From: Conor McCarthy Subject: [PATCH vkd3d 3/5] tests: Add tests for domain shader patch constant inputs. Message-Id: <20210914020039.10807-3-cmccarthy@codeweavers.com> Date: Tue, 14 Sep 2021 12:00:37 +1000 In-Reply-To: <20210914020039.10807-1-cmccarthy@codeweavers.com> References: <20210914020039.10807-1-cmccarthy@codeweavers.com> Based on a vkd3d-proton patch by Hans-Kristian Arntzen. Signed-off-by: Conor McCarthy --- tests/d3d12.c | 214 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) diff --git a/tests/d3d12.c b/tests/d3d12.c index 89b1f000..ed85f4a1 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -28986,6 +28986,219 @@ static void test_tessellation_primitive_id(void) destroy_test_context(&context); } +static void test_tessellation_ds_inputs(void) +{ + D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc; + ID3D12GraphicsCommandList *command_list; + D3D12_STREAM_OUTPUT_BUFFER_VIEW sobv; + D3D12_INPUT_LAYOUT_DESC input_layout; + struct test_context_desc desc; + struct resource_readback rb; + struct test_context context; + ID3D12Resource *so_buffer; + ID3D12CommandQueue *queue; + unsigned int x, y; + HRESULT hr; + +#if 0 + struct data + { + float4 position : SV_Position; + }; + data vs_main() + { + data d; + d.position = float4(1.0f, 2.0f, 3.0f, 4.0f); + return d; + } + + struct patch_constant_data + { + float tess_factor[2] : SV_TessFactor; + float3 a : A; + float3 b : B; + }; + + void patch_constant(OutputPatch control_points, + uint prim_id : SV_PrimitiveID, + out patch_constant_data output) + { + output.tess_factor[0] = 2.0f; + output.tess_factor[1] = 1.0f; + output.a = float3(2.0f, 4.0f, 10.0f); + output.b = float3(3.0f, 3.0f, 12.0f); + } + + [domain("isoline")] + [outputcontrolpoints(1)] + [partitioning("integer")] + [outputtopology("line")] + [patchconstantfunc("patch_constant")] + data hs_main(InputPatch input) + { + return input[0]; + } + + [domain("isoline")] + void ds_main(patch_constant_data input, + float tess_factor[2] : SV_TessFactor, + float2 tess_coord : SV_DomainLocation, + float3 a : A, + float3 b : B, + const OutputPatch patch, + out float4 position : SV_Position, + out float4 out_color : COLOR) + { + position = float4(patch[0].position.xy, tess_coord); + out_color = float4(0.5f * (a.xy + b.yz), tess_factor[0], tess_factor[1]); + } +#endif + static const DWORD vs_code[] = + { + 0x43425844, 0xcb24c840, 0x8a22891b, 0xcf0dbe1d, 0x7b0a4fdb, 0x00000001, 0x000000b8, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, + 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x00000040, 0x00010050, 0x00000010, + 0x0100086a, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, + 0x00004002, 0x3f800000, 0x40000000, 0x40400000, 0x40800000, 0x0100003e, + }; + static const D3D12_SHADER_BYTECODE vs = {vs_code, sizeof(vs_code)}; + static const DWORD hs_code[] = + { + 0x43425844, 0x67db9c59, 0xff2c4d5e, 0xc2a4d15b, 0x0f71495f, 0x00000001, 0x00000384, 0x00000004, + 0x00000030, 0x00000064, 0x00000098, 0x0000011c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, + 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, + 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, + 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000007c, + 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000010, 0x00000003, 0x00000000, 0x00000e01, + 0x00000076, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000010e, 0x00000068, 0x00000001, + 0x0000000f, 0x00000003, 0x00000001, 0x00000e01, 0x00000078, 0x00000000, 0x00000000, 0x00000003, + 0x00000001, 0x0000010e, 0x545f5653, 0x46737365, 0x6f746361, 0x00410072, 0xabab0042, 0x58454853, + 0x00000260, 0x00030050, 0x00000098, 0x01000071, 0x01000893, 0x01000894, 0x01000895, 0x01000896, + 0x01001097, 0x0100086a, 0x00001835, 0x0000000a, 0x41200000, 0x40800000, 0x40000000, 0x40000000, + 0x41400000, 0x40400000, 0x40400000, 0x3f800000, 0x01000072, 0x0400005f, 0x002010f2, 0x00000001, + 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, + 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002, 0x0200005f, 0x00017000, + 0x04000067, 0x00102012, 0x00000000, 0x00000016, 0x04000067, 0x00102012, 0x00000001, 0x00000015, + 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000002, 0x04000036, 0x00100012, + 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a, 0x00000000, 0x0090903a, 0x0010000a, + 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002, 0x0200005f, 0x00017000, 0x03000065, + 0x00102022, 0x00000000, 0x03000065, 0x00102022, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, + 0x00102022, 0x00000000, 0x00000002, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, + 0x00902022, 0x0010000a, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000, 0x0100003e, 0x01000073, + 0x02000099, 0x00000002, 0x0200005f, 0x00017000, 0x03000065, 0x00102042, 0x00000000, 0x03000065, + 0x00102042, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x00102042, 0x00000000, 0x00000002, + 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902042, 0x0010000a, 0x00000000, + 0x0090901a, 0x0010000a, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002, 0x0200005f, + 0x00017000, 0x03000065, 0x00102082, 0x00000000, 0x03000065, 0x00102082, 0x00000001, 0x02000068, + 0x00000001, 0x0400005b, 0x00102082, 0x00000000, 0x00000002, 0x04000036, 0x00100012, 0x00000000, + 0x0001700a, 0x07000036, 0x00902082, 0x0010000a, 0x00000000, 0x0090900a, 0x0010000a, 0x00000000, + 0x0100003e, + }; + static const D3D12_SHADER_BYTECODE hs = {hs_code, sizeof(hs_code)}; + static const DWORD ds_code[] = + { + 0x43425844, 0xef67f8be, 0x1be137b6, 0x0e4a6b01, 0xf0cd92d8, 0x00000001, 0x00000264, 0x00000004, + 0x00000030, 0x00000064, 0x000000e8, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, + 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, + 0x006e6f69, 0x47534350, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000010, + 0x00000003, 0x00000000, 0x00000101, 0x00000076, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000060e, 0x00000068, 0x00000001, 0x0000000f, 0x00000003, 0x00000001, 0x00000101, 0x00000078, + 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c0e, 0x545f5653, 0x46737365, 0x6f746361, + 0x00410072, 0xabab0042, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, + 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, + 0x00000001, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x58454853, + 0x00000120, 0x00040050, 0x00000048, 0x01000893, 0x01000895, 0x0100086a, 0x04000061, 0x0011b012, + 0x00000000, 0x00000016, 0x0300005f, 0x0011b062, 0x00000000, 0x04000061, 0x0011b012, 0x00000001, + 0x00000015, 0x0300005f, 0x0011b0c2, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x00219032, + 0x00000001, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, + 0x00000001, 0x02000068, 0x00000001, 0x06000036, 0x00102032, 0x00000000, 0x00219046, 0x00000000, + 0x00000000, 0x04000036, 0x001020c2, 0x00000000, 0x0001c406, 0x07000000, 0x00100032, 0x00000000, + 0x0011b596, 0x00000000, 0x0011bae6, 0x00000001, 0x0a000038, 0x00102032, 0x00000001, 0x00100046, + 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x05000036, 0x00102042, + 0x00000001, 0x0011b00a, 0x00000000, 0x05000036, 0x00102082, 0x00000001, 0x0011b00a, 0x00000001, + 0x0100003e, + }; + static const D3D12_SHADER_BYTECODE ds = {ds_code, sizeof(ds_code)}; + static const D3D12_SO_DECLARATION_ENTRY so_declaration[] = + { + {0, "SV_POSITION", 0, 0, 4, 0}, + {0, "COLOR", 0, 0, 4, 0}, + }; + static const float reference[4][8] = + { + {1.0f, 2.0f, 0.0f, 0.0f, 2.5f, 8.0f, 2.0f, 1.0f}, + {1.0f, 2.0f, 1.0f, 0.0f, 2.5f, 8.0f, 2.0f, 1.0f}, + {1.0f, 2.0f, 0.0f, 0.5f, 2.5f, 8.0f, 2.0f, 1.0f}, + {1.0f, 2.0f, 1.0f, 0.5f, 2.5f, 8.0f, 2.0f, 1.0f}, + }; + static const bool is_todo[4][8] = + { + {false, false, false, false, true, true, false, false}, + {false, false, true, false, true, true, false, false}, + {false, false, true, true, true, true, false, false}, + {false, false, false, true, true, true, false, false}, + }; + static const unsigned int stride = sizeof(reference[0]); + + memset(&desc, 0, sizeof(desc)); + desc.root_signature_flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT + | D3D12_ROOT_SIGNATURE_FLAG_ALLOW_STREAM_OUTPUT; + desc.no_pipeline = true; + if (!init_test_context(&context, &desc)) + return; + command_list = context.list; + queue = context.queue; + + memset(&input_layout, 0, sizeof(input_layout)); + + init_pipeline_state_desc(&pso_desc, context.root_signature, DXGI_FORMAT_UNKNOWN, &vs, NULL, &input_layout); + pso_desc.HS = hs; + pso_desc.DS = ds; + memset(&pso_desc.PS, 0, sizeof(pso_desc.PS)); + pso_desc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH; + pso_desc.StreamOutput.NumEntries = ARRAY_SIZE(so_declaration); + pso_desc.StreamOutput.pSODeclaration = so_declaration; + pso_desc.StreamOutput.pBufferStrides = &stride; + pso_desc.StreamOutput.NumStrides = 1; + pso_desc.StreamOutput.RasterizedStream = D3D12_SO_NO_RASTERIZED_STREAM; + hr = ID3D12Device_CreateGraphicsPipelineState(context.device, &pso_desc, + &IID_ID3D12PipelineState, (void **)&context.pipeline_state); + ok(hr == S_OK, "Failed to create state, hr %#x.\n", hr); + + so_buffer = create_default_buffer(context.device, 4096, + D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_STREAM_OUT); + sobv.BufferLocation = ID3D12Resource_GetGPUVirtualAddress(so_buffer); + sobv.SizeInBytes = 1024; + sobv.BufferFilledSizeLocation = sobv.BufferLocation + sobv.SizeInBytes; + + ID3D12GraphicsCommandList_SOSetTargets(command_list, 0, 1, &sobv); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature); + ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 4, 1, 0, 0); + + transition_resource_state(command_list, so_buffer, + D3D12_RESOURCE_STATE_STREAM_OUT, D3D12_RESOURCE_STATE_COPY_SOURCE); + get_buffer_readback_with_command_list(so_buffer, DXGI_FORMAT_UNKNOWN, &rb, queue, command_list); + for (y = 0; y < 4; ++y) + { + float *elems = get_readback_data(&rb, y, 0, 0, stride); + for (x = 0; x < 8; ++x) + { + todo_if(is_todo[y][x]) + ok(compare_float(reference[y][x], elems[x], 0), + "Got unexpected value %f for [%u][%u], expected %f.\n", elems[x], y, x, reference[y][x]); + } + } + release_resource_readback(&rb); + + ID3D12Resource_Release(so_buffer); + destroy_test_context(&context); +} + static void test_render_a8(void) { static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f}; @@ -35263,6 +35476,7 @@ START_TEST(d3d12) run_test(test_hull_shader_fork_phase); run_test(test_line_tessellation); run_test(test_tessellation_primitive_id); + run_test(test_tessellation_ds_inputs); run_test(test_render_a8); run_test(test_cpu_descriptors_lifetime); run_test(test_clip_distance); -- 2.32.0