[PATCH vkd3d 5/5] tests: Add tests for loading stencil values from textures.
Józef Kucia
joseph.kucia at gmail.com
Fri Jun 7 07:38:05 CDT 2019
From: Józef Kucia <jkucia at codeweavers.com>
With plane slice and component mapping.
Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
tests/d3d12.c | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 182 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c
index 04ee7be99fff..3c1eec59857e 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -18858,6 +18858,187 @@ static void test_depth_read_only_view(void)
destroy_test_context(&context);
}
+static void test_stencil_load(void)
+{
+ D3D12_ROOT_SIGNATURE_DESC root_signature_desc;
+ D3D12_DESCRIPTOR_RANGE descriptor_ranges[2];
+ D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc;
+ D3D12_ROOT_PARAMETER root_parameters[1];
+ ID3D12GraphicsCommandList *command_list;
+ ID3D12PipelineState *pipeline_state;
+ struct depth_stencil_resource ds;
+ struct test_context_desc desc;
+ struct test_context context;
+ ID3D12DescriptorHeap *heap;
+ ID3D12CommandQueue *queue;
+ struct uvec4 uvec4 = {0};
+ ID3D12Resource *texture;
+ ID3D12Device *device;
+ unsigned int i;
+ HRESULT hr;
+
+ static const DWORD cs_code[] =
+ {
+#if 0
+ Texture2D<uint4> t;
+ RWTexture2D<uint4> u;
+
+ [numthreads(1, 1, 1)]
+ void main(uint2 id : SV_GroupID)
+ {
+ u[id] = t[id];
+ }
+#endif
+ 0x43425844, 0x0b41fa64, 0xd64df766, 0xc4c98283, 0xb810dc2b, 0x00000001, 0x00000110, 0x00000003,
+ 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
+ 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000bc, 0x00050050, 0x0000002f, 0x0100086a,
+ 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x0400189c, 0x0011e000, 0x00000000, 0x00004444,
+ 0x0200005f, 0x00021032, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
+ 0x04000036, 0x00100032, 0x00000000, 0x00021046, 0x08000036, 0x001000c2, 0x00000000, 0x00004002,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8900002d, 0x800000c2, 0x00111103, 0x001000f2,
+ 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000000,
+ 0x00021546, 0x00100e46, 0x00000000, 0x0100003e,
+ };
+ static const DWORD ps_code[] =
+ {
+#if 0
+ Texture2D<uint4> t;
+
+ uint4 main(float4 position : SV_Position) : SV_Target
+ {
+ return t[int2(position.x, position.y)];
+ }
+#endif
+ 0x43425844, 0x9ad18dbc, 0x98de0e54, 0xe3c15d5b, 0xac8b580a, 0x00000001, 0x00000138, 0x00000003,
+ 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
+ 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
+ 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000009c, 0x00000050,
+ 0x00000027, 0x0100086a, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032,
+ 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0500001b,
+ 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8900002d, 0x800000c2, 0x00111103, 0x001020f2,
+ 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 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 unsigned int tests[] = {0, 50, 75, 100, 150, 200, 255};
+
+ memset(&desc, 0, sizeof(desc));
+ desc.rt_format = DXGI_FORMAT_R32G32B32A32_UINT;
+ desc.no_root_signature = true;
+ if (!init_test_context(&context, &desc))
+ return;
+ device = context.device;
+ command_list = context.list;
+ queue = context.queue;
+
+ descriptor_ranges[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
+ descriptor_ranges[0].NumDescriptors = 1;
+ descriptor_ranges[0].BaseShaderRegister = 0;
+ descriptor_ranges[0].RegisterSpace = 0;
+ descriptor_ranges[0].OffsetInDescriptorsFromTableStart = 0;
+ descriptor_ranges[1].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
+ descriptor_ranges[1].NumDescriptors = 1;
+ descriptor_ranges[1].BaseShaderRegister = 0;
+ descriptor_ranges[1].RegisterSpace = 0;
+ descriptor_ranges[1].OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
+ root_parameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
+ root_parameters[0].DescriptorTable.NumDescriptorRanges = 2;
+ root_parameters[0].DescriptorTable.pDescriptorRanges = descriptor_ranges;
+ root_parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
+ root_signature_desc.NumParameters = 1;
+ root_signature_desc.pParameters = root_parameters;
+ root_signature_desc.NumStaticSamplers = 0;
+ root_signature_desc.pStaticSamplers = NULL;
+ 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);
+
+ pipeline_state = create_compute_pipeline_state(device, context.root_signature,
+ shader_bytecode(cs_code, sizeof(cs_code)));
+ 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, 2);
+
+ init_depth_stencil(&ds, device, context.render_target_desc.Width,
+ context.render_target_desc.Height, 1, 1, DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, NULL);
+ memset(&srv_desc, 0, sizeof(srv_desc));
+ srv_desc.Format = DXGI_FORMAT_X24_TYPELESS_G8_UINT;
+ srv_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
+ srv_desc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(
+ D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1,
+ D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1,
+ D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1,
+ D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1);
+ srv_desc.Texture2D.MipLevels = 1;
+ srv_desc.Texture2D.PlaneSlice = 1;
+ ID3D12Device_CreateShaderResourceView(device, ds.texture, &srv_desc,
+ get_cpu_descriptor_handle(&context, heap, 0));
+
+ texture = create_default_texture(device, 32, 32, DXGI_FORMAT_R32G32B32A32_UINT,
+ D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ ID3D12Device_CreateUnorderedAccessView(device, texture, NULL, NULL,
+ get_cpu_descriptor_handle(&context, heap, 1));
+
+ for (i = 0; i < ARRAY_SIZE(tests); ++i)
+ {
+ vkd3d_test_set_context("Test %u", i);
+
+ uvec4.x = uvec4.y = uvec4.z = uvec4.w = tests[i];
+
+ ID3D12GraphicsCommandList_ClearDepthStencilView(command_list, ds.dsv_handle,
+ D3D12_CLEAR_FLAG_STENCIL, 0.0f, tests[i], 0, NULL);
+ transition_sub_resource_state(command_list, ds.texture, 0,
+ D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
+
+ ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL);
+ ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, FALSE, NULL);
+ ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport);
+ ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect);
+
+ ID3D12GraphicsCommandList_SetDescriptorHeaps(command_list, 1, &heap);
+
+ ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state);
+ ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature);
+ ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, 0,
+ ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap));
+ ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+ ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0);
+
+ ID3D12GraphicsCommandList_SetPipelineState(command_list, pipeline_state);
+ ID3D12GraphicsCommandList_SetComputeRootSignature(command_list, context.root_signature);
+ ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(command_list, 0,
+ ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap));
+ ID3D12GraphicsCommandList_Dispatch(command_list, 32, 32, 1);
+
+ transition_sub_resource_state(command_list, context.render_target, 0,
+ D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
+ check_sub_resource_uvec4(context.render_target, 0, queue, command_list, &uvec4);
+
+ reset_command_list(command_list, context.allocator);
+ transition_sub_resource_state(command_list, texture, 0,
+ D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
+ check_sub_resource_uvec4(texture, 0, queue, command_list, &uvec4);
+
+ reset_command_list(command_list, context.allocator);
+ transition_sub_resource_state(command_list, context.render_target, 0,
+ D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET);
+ transition_sub_resource_state(command_list, texture, 0,
+ D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ transition_sub_resource_state(command_list, ds.texture, 0,
+ D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_DEPTH_WRITE);
+ }
+ vkd3d_test_set_context(NULL);
+
+ destroy_depth_stencil(&ds);
+ ID3D12Resource_Release(texture);
+ ID3D12DescriptorHeap_Release(heap);
+ ID3D12PipelineState_Release(pipeline_state);
+ destroy_test_context(&context);
+}
+
static void test_typed_buffer_uav(void)
{
D3D12_CPU_DESCRIPTOR_HANDLE cpu_descriptor_handle;
@@ -29843,6 +30024,7 @@ START_TEST(d3d12)
run_test(test_depth_stencil_sampling);
run_test(test_depth_load);
run_test(test_depth_read_only_view);
+ run_test(test_stencil_load);
run_test(test_typed_buffer_uav);
run_test(test_typed_uav_store);
run_test(test_compute_shader_registers);
--
2.21.0
More information about the wine-devel
mailing list