From: Józef Kucia jkucia@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- tests/d3d12.c | 283 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c index 38e757a28748..34b4fdf101fb 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -18921,6 +18921,288 @@ static void test_clip_distance(void) destroy_test_context(&context); }
+static void test_combined_clip_and_cull_distances(void) +{ + D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc; + ID3D12GraphicsCommandList *command_list; + D3D12_INPUT_LAYOUT_DESC input_layout; + D3D12_VERTEX_BUFFER_VIEW vbv[2]; + struct test_context_desc desc; + struct test_context context; + struct resource_readback rb; + ID3D12CommandQueue *queue; + ID3D12Resource *vb[2]; + ID3D12Device *device; + unsigned int i, j, k; + HRESULT hr; + + static const DWORD vs_code[] = + { +#if 0 + struct input + { + float4 position : POSITION; + float clip0 : CLIP_DISTANCE0; + float clip1 : CLIP_DISTANCE1; + float clip2 : CLIP_DISTANCE2; + float clip3 : CLIP_DISTANCE3; + float cull0 : CULL_DISTANCE0; + float cull1 : CULL_DISTANCE1; + float cull2 : CULL_DISTANCE2; + float cull3 : CULL_DISTANCE3; + }; + + struct vertex + { + float4 position : SV_Position; + float3 clip0 : SV_ClipDistance1; + float3 cull0 : SV_CullDistance1; + float clip1 : SV_ClipDistance2; + float cull1 : SV_CullDistance2; + }; + + void main(input vin, out vertex vertex) + { + vertex.position = vin.position; + vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2); + vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2); + vertex.clip1 = vin.clip3; + vertex.cull1 = vin.cull3; + } +#endif + 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003, + 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0, + 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000, + 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002, + 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9, + 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000, + 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006, + 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7, + 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, + 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f, + 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, + 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c, + 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003, + 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002, + 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e, + 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f, + 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012, + 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f, + 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007, + 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067, + 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067, + 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036, + 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, + 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042, + 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004, + 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002, + 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036, + 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e, + }; + static const D3D12_SHADER_BYTECODE vs = {vs_code, sizeof(vs_code)}; + static const D3D12_INPUT_ELEMENT_DESC layout_desc[] = + { + {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, + {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, + {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, + {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, + {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, + {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, + {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, + {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, + {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, + }; + static const struct vec4 quad[] = + { + {-1.0f, -1.0f}, + {-1.0f, 1.0f}, + { 1.0f, -1.0f}, + { 1.0f, 1.0f}, + }; + struct + { + float clip_distance[4]; + float cull_distance[4]; + } + vertices[4] = + { + {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + }; + static const struct test + { + float vertices[4]; + BOOL triangle_visible[2]; + } + cull_distance_tests[] = + { + {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}}, + {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}}, + {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}}, + {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}}, + {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}}, + {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}}, + {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}}, + {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}}, + {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}}, + + {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}}, + {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}}, + {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}}, + {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}}, + {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}}, + + {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}}, + }; + static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + + memset(&desc, 0, sizeof(desc)); + desc.rt_width = 640; + desc.rt_height = 480; + desc.root_signature_flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT; + desc.no_pipeline = true; + if (!init_test_context(&context, &desc)) + return; + device = context.device; + command_list = context.list; + queue = context.queue; + + input_layout.pInputElementDescs = layout_desc; + input_layout.NumElements = ARRAY_SIZE(layout_desc); + + init_pipeline_state_desc(&pso_desc, context.root_signature, + context.render_target_desc.Format, &vs, NULL, &input_layout); + hr = ID3D12Device_CreateGraphicsPipelineState(device, &pso_desc, + &IID_ID3D12PipelineState, (void **)&context.pipeline_state); + ok(hr == S_OK, "Failed to create pipeline state, hr %#x.\n", hr); + + vb[0] = create_upload_buffer(device, sizeof(quad), quad); + vbv[0].BufferLocation = ID3D12Resource_GetGPUVirtualAddress(vb[0]); + vbv[0].StrideInBytes = sizeof(*quad); + vbv[0].SizeInBytes = sizeof(quad); + + vb[1] = create_upload_buffer(device, sizeof(vertices), vertices); + vbv[1].BufferLocation = ID3D12Resource_GetGPUVirtualAddress(vb[1]); + vbv[1].StrideInBytes = sizeof(*vertices); + vbv[1].SizeInBytes = sizeof(vertices); + + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, FALSE, NULL); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature); + ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); + ID3D12GraphicsCommandList_IASetVertexBuffers(command_list, 0, ARRAY_SIZE(vbv), vbv); + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 4, 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, 0xff00ff00, 0); + + 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); + + for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i) + { + for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j) + { + const struct test *test = &cull_distance_tests[j]; + unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)]; + unsigned int color; + + for (k = 0; k < ARRAY_SIZE(vertices); ++k) + vertices[k].cull_distance[i] = test->vertices[k]; + update_buffer_data(vb[1], 0, sizeof(vertices), vertices); + + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, FALSE, NULL); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature); + ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); + ID3D12GraphicsCommandList_IASetVertexBuffers(command_list, 0, ARRAY_SIZE(vbv), vbv); + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 4, 1, 0, 0); + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + + for (k = 0; k < ARRAY_SIZE(expected_color); ++k) + expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff; + + if (expected_color[0] == expected_color[1]) + { + check_sub_resource_uint(context.render_target, 0, queue, command_list, expected_color[0], 0); + } + else + { + get_texture_readback_with_command_list(context.render_target, 0, &rb, queue, command_list); + color = get_readback_uint(&rb, 160, 240, 0); + ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color); + color = get_readback_uint(&rb, 480, 240, 0); + ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color); + release_resource_readback(&rb); + } + + 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); + } + + for (j = 0; j < ARRAY_SIZE(vertices); ++j) + vertices[j].cull_distance[i] = 1.0f; + } + + for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i) + { + for (j = 0; j < ARRAY_SIZE(vertices); ++j) + vertices[j].clip_distance[i] = -1.0f; + update_buffer_data(vb[1], 0, sizeof(vertices), vertices); + + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, FALSE, NULL); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature); + ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); + ID3D12GraphicsCommandList_IASetVertexBuffers(command_list, 0, ARRAY_SIZE(vbv), vbv); + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 4, 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, 0xffffffff, 0); + + 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); + + for (j = 0; j < ARRAY_SIZE(vertices); ++j) + vertices[j].clip_distance[i] = 1.0f; + } + + memset(vertices, 0, sizeof(vertices)); + update_buffer_data(vb[1], 0, sizeof(vertices), vertices); + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, FALSE, NULL); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature); + ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); + ID3D12GraphicsCommandList_IASetVertexBuffers(command_list, 0, ARRAY_SIZE(vbv), vbv); + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 4, 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, 0xff00ff00, 0); + + for (i = 0; i < ARRAY_SIZE(vb); ++i) + ID3D12Resource_Release(vb[i]); + destroy_test_context(&context); +} + START_TEST(d3d12) { bool enable_debug_layer = false; @@ -19036,4 +19318,5 @@ START_TEST(d3d12) run_test(test_render_a8); run_test(test_cpu_descriptors_lifetime); run_test(test_clip_distance); + run_test(test_combined_clip_and_cull_distances); }