From: Józef Kucia <jkucia(a)codeweavers.com>
Signed-off-by: Józef Kucia <jkucia(a)codeweavers.com>
---
tests/d3d12.c | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 223 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c
index c82778594129..aa35315f3e7a 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -11739,6 +11739,228 @@ static void test_cube_maps(void)
destroy_test_context(&context);
}
+static void test_multisample_array_texture(void)
+{
+ D3D12_ROOT_SIGNATURE_DESC root_signature_desc;
+ D3D12_ROOT_PARAMETER root_parameters[3];
+ D3D12_DESCRIPTOR_RANGE descriptor_range;
+ ID3D12GraphicsCommandList *command_list;
+ D3D12_RENDER_TARGET_VIEW_DESC rtv_desc;
+ D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle;
+ D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle;
+ D3D12_HEAP_PROPERTIES heap_properties;
+ D3D12_RESOURCE_DESC resource_desc;
+ struct test_context_desc desc;
+ struct resource_readback rb;
+ struct test_context context;
+ ID3D12DescriptorHeap *heap;
+ ID3D12Resource *uav_buffer;
+ ID3D12CommandQueue *queue;
+ ID3D12Resource *texture;
+ ID3D12Device *device;
+ unsigned int i;
+ HRESULT hr;
+
+ static const DWORD ps_code[] =
+ {
+#if 0
+ Texture2DMSArray<float4> t;
+
+ RWByteAddressBuffer u;
+
+ uint layer;
+ uint sample_index;
+
+ uint offset;
+
+ float4 main() : SV_Target
+ {
+ uint width, height, elements, samples;
+ t.GetDimensions(width, height, elements, samples);
+ u.Store4(offset, uint4(width, height, elements, samples));
+ return t.Load(int3(0, 0, layer), sample_index);
+ }
+#endif
+ 0x43425844, 0xb1457478, 0xd475e3dd, 0xda1eb41d, 0x66075d2b, 0x00000001, 0x0000017c, 0x00000003,
+ 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
+ 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000104, 0x00000050, 0x00000041,
+ 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004858, 0x00107000, 0x00000000,
+ 0x00005555, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
+ 0x00000001, 0x8900103d, 0x80000242, 0x00155543, 0x00100072, 0x00000000, 0x00004001, 0x00000000,
+ 0x00107e46, 0x00000000, 0x0500086f, 0x00100082, 0x00000000, 0x0010700a, 0x00000000, 0x080000a6,
+ 0x0011e0f2, 0x00000001, 0x0020802a, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x05000036,
+ 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x06000036, 0x00100042, 0x00000000, 0x0020800a,
+ 0x00000000, 0x00000000, 0x8c00002e, 0x80000242, 0x00155543, 0x001020f2, 0x00000000, 0x00100206,
+ 0x00000000, 0x00107e46, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
+ };
+ static const D3D12_SHADER_BYTECODE ps = {ps_code, sizeof(ps_code)};
+ static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
+ static const struct vec4 colors[] =
+ {
+ {1.0f, 0.0f, 0.0f, 1.0f},
+ {0.0f, 1.0f, 0.0f, 1.0f},
+ {0.0f, 0.0f, 1.0f, 1.0f},
+
+ {0.0f, 1.0f, 1.0f, 1.0f},
+ {1.0f, 0.0f, 1.0f, 1.0f},
+ {1.0f, 1.0f, 0.0f, 1.0f},
+
+ {0.5f, 0.5f, 0.5f, 1.0f},
+ {0.5f, 0.5f, 0.5f, 0.5f},
+ };
+ static const struct
+ {
+ struct
+ {
+ unsigned int layer;
+ unsigned int sample_index;
+ unsigned int offset;
+ } constants;
+ unsigned int expected_color;
+ }
+ tests[] =
+ {
+ {{0, 0, 0}, 0xff0000ff},
+ {{0, 1, 0}, 0xff0000ff},
+ {{0, 2, 0}, 0xff0000ff},
+ {{0, 3, 0}, 0xff0000ff},
+
+ {{1, 0, 16}, 0xff00ff00},
+ {{2, 1, 32}, 0xffff0000},
+ {{3, 2, 32}, 0xffffff00},
+ {{4, 3, 32}, 0xffff00ff},
+ {{5, 0, 32}, 0xff00ffff},
+ {{6, 0, 32}, 0xff7f7f7f},
+ {{7, 0, 32}, 0x7f7f7f7f},
+ };
+
+ memset(&desc, 0, sizeof(desc));
+ desc.rt_descriptor_count = 2;
+ desc.no_root_signature = true;
+ if (!init_test_context(&context, &desc))
+ return;
+ device = context.device;
+ command_list = context.list;
+ queue = context.queue;
+
+ descriptor_range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
+ descriptor_range.NumDescriptors = 1;
+ descriptor_range.BaseShaderRegister = 0;
+ descriptor_range.RegisterSpace = 0;
+ descriptor_range.OffsetInDescriptorsFromTableStart = 0;
+ root_parameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
+ root_parameters[0].DescriptorTable.NumDescriptorRanges = 1;
+ root_parameters[0].DescriptorTable.pDescriptorRanges = &descriptor_range;
+ root_parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
+ root_parameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
+ root_parameters[1].Constants.ShaderRegister = 0;
+ root_parameters[1].Constants.RegisterSpace = 0;
+ root_parameters[1].Constants.Num32BitValues = 3;
+ root_parameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
+ root_parameters[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
+ root_parameters[2].Descriptor.ShaderRegister = 1;
+ root_parameters[2].Descriptor.RegisterSpace = 0;
+ root_parameters[2].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
+
+ memset(&root_signature_desc, 0, sizeof(root_signature_desc));
+ root_signature_desc.NumParameters = ARRAY_SIZE(root_parameters);
+ root_signature_desc.pParameters = root_parameters;
+ root_signature_desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_NONE;
+ hr = create_root_signature(device, &root_signature_desc, &context.root_signature);
+ ok(hr == S_OK, "Failed to create root signature, hr %#x.\n", hr);
+
+ context.pipeline_state = create_pipeline_state(context.device,
+ context.root_signature, context.render_target_desc.Format, NULL, &ps, NULL);
+
+ heap = create_gpu_descriptor_heap(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1);
+
+ memset(&heap_properties, 0, sizeof(heap_properties));
+ heap_properties.Type = D3D12_HEAP_TYPE_DEFAULT;
+
+ memset(&resource_desc, 0, sizeof(resource_desc));
+ resource_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
+ resource_desc.Width = 32;
+ resource_desc.Height = 32;
+ resource_desc.DepthOrArraySize = ARRAY_SIZE(colors);
+ resource_desc.MipLevels = 1;
+ resource_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ resource_desc.SampleDesc.Count = 4;
+ resource_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
+ hr = ID3D12Device_CreateCommittedResource(device, &heap_properties, D3D12_HEAP_FLAG_NONE,
+ &resource_desc, D3D12_RESOURCE_STATE_RENDER_TARGET, NULL, &IID_ID3D12Resource, (void **)&texture);
+ ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
+
+ cpu_handle = get_cpu_rtv_handle(&context, context.rtv_heap, 1);
+
+ for (i = 0; i < ARRAY_SIZE(colors); ++i)
+ {
+ memset(&rtv_desc, 0, sizeof(rtv_desc));
+ rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY;
+ rtv_desc.Format = resource_desc.Format;
+ rtv_desc.Texture2DMSArray.FirstArraySlice = i;
+ rtv_desc.Texture2DMSArray.ArraySize = 1;
+ ID3D12Device_CreateRenderTargetView(device, texture, &rtv_desc, cpu_handle);
+
+ ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, cpu_handle, &colors[i].x, 0, NULL);
+ }
+
+ transition_resource_state(command_list, texture,
+ D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
+
+ cpu_handle = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap);
+ gpu_handle = ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap);
+
+ ID3D12Device_CreateShaderResourceView(device, texture, NULL, cpu_handle);
+
+ uav_buffer = create_default_buffer(device, 4096,
+ D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+
+ for (i = 0; i < ARRAY_SIZE(tests); ++i)
+ {
+ ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL);
+ ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, FALSE, NULL);
+ ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature);
+ ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state);
+ ID3D12GraphicsCommandList_SetDescriptorHeaps(command_list, 1, &heap);
+ ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, 0, gpu_handle);
+ ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(command_list, 1, 3, &tests[i].constants.layer, 0);
+ ID3D12GraphicsCommandList_SetGraphicsRootUnorderedAccessView(command_list,
+ 2, ID3D12Resource_GetGPUVirtualAddress(uav_buffer));
+ ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+ ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport);
+ ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect);
+ ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0);
+
+ transition_resource_state(command_list, context.render_target,
+ D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
+ check_sub_resource_uint(context.render_target, 0, queue, command_list, tests[i].expected_color, 1);
+
+ reset_command_list(command_list, context.allocator);
+ transition_resource_state(command_list, context.render_target,
+ D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET);
+ }
+
+ transition_resource_state(command_list, uav_buffer,
+ D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
+
+ get_buffer_readback_with_command_list(uav_buffer, DXGI_FORMAT_R32G32B32A32_UINT, &rb, queue, command_list);
+ for (i = 0; i < 2; ++i)
+ {
+ const struct uvec4 *v = get_readback_uvec4(&rb, i, 0);
+ ok(v->x == resource_desc.Width, "Got unexpected width %u.\n", v->x);
+ ok(v->y == resource_desc.Height, "Got unexpected height %u.\n", v->y);
+ ok(v->z == resource_desc.DepthOrArraySize, "Got unexpected array size %u.\n", v->z);
+ ok(v->w == resource_desc.SampleDesc.Count, "Got unexpected sample count %u.\n", v->w);
+ }
+ release_resource_readback(&rb);
+
+ ID3D12Resource_Release(texture);
+ ID3D12Resource_Release(uav_buffer);
+ ID3D12DescriptorHeap_Release(heap);
+ destroy_test_context(&context);
+}
+
static void test_descriptor_tables(void)
{
ID3D12DescriptorHeap *heap, *sampler_heap, *heaps[2];
@@ -21659,6 +21881,7 @@ START_TEST(d3d12)
run_test(test_gather);
run_test(test_gather_c);
run_test(test_cube_maps);
+ run_test(test_multisample_array_texture);
run_test(test_descriptor_tables);
run_test(test_descriptor_tables_overlapping_bindings);
run_test(test_update_root_descriptors);
--
2.18.1