Prevents a crash in RADV due to an assertion failure when such inputs are present.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d-shader/spirv.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 6f948c31..d607bc70 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -4548,6 +4548,8 @@ static uint32_t vkd3d_dxbc_compiler_emit_input(struct vkd3d_dxbc_compiler *compi if (builtin) { input_id = vkd3d_dxbc_compiler_emit_builtin_variable(compiler, builtin, storage_class, array_size); + if (reg->type == VKD3DSPR_PATCHCONST) + vkd3d_spirv_build_op_decorate(builder, input_id, SpvDecorationPatch, NULL, 0); } else {
Prevents a crash in RADV when such inputs are present.
From a vkd3d-proton patch by Hans-Kristian Arntzen.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d-shader/spirv.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index d607bc70..005e803d 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -4610,6 +4610,16 @@ static uint32_t vkd3d_dxbc_compiler_emit_input(struct vkd3d_dxbc_compiler *compi val_id = vkd3d_spirv_build_op_in_bounds_access_chain1(builder, ptr_type_id, input_id, index); dst_reg.idx[0].offset = i; } + else if (builtin && builtin->spirv_array_size >= 1) + { + /* The DXBC builtin is not an array, but the SPIR-V builtin is an array, so + * we'll need to index into the builtin when we try to load it. + * This happens when we try to read TessLevel in domain shader. */ + ptr_type_id = vkd3d_spirv_get_op_type_pointer(builder, SpvStorageClassInput, type_id); + index = vkd3d_dxbc_compiler_get_constant_uint(compiler, builtin->member_idx); + val_id = vkd3d_spirv_build_op_in_bounds_access_chain1(builder, ptr_type_id, input_id, index); + dst_reg.idx[0].offset = reg_idx + i; + } val_id = vkd3d_spirv_build_op_load(builder, type_id, val_id, SpvMemoryAccessMaskNone);
if (builtin && builtin->fixup_pfn)
Based on a vkd3d-proton patch by Hans-Kristian Arntzen.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- 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<data, 1> 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<data, 1> 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<data, 1> 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);
Based on a vkd3d-proton patch by Hans-Kristian Arntzen.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d-shader/spirv.c | 4 ++-- tests/d3d12.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 005e803d..379746b7 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -4064,8 +4064,8 @@ vkd3d_system_value_builtins[] = {VKD3D_SIV_TRIANGLE_W_TESS_FACTOR, {VKD3D_SHADER_COMPONENT_FLOAT, 1, SpvBuiltInTessLevelOuter, NULL, 4, 2}}, {VKD3D_SIV_TRIANGLE_INNER_TESS_FACTOR, {VKD3D_SHADER_COMPONENT_FLOAT, 1, SpvBuiltInTessLevelInner, NULL, 2, 0}},
- {VKD3D_SIV_LINE_DETAIL_TESS_FACTOR, {VKD3D_SHADER_COMPONENT_FLOAT, 1, SpvBuiltInTessLevelOuter, NULL, 4, 0}}, - {VKD3D_SIV_LINE_DENSITY_TESS_FACTOR, {VKD3D_SHADER_COMPONENT_FLOAT, 1, SpvBuiltInTessLevelOuter, NULL, 4, 1}}, + {VKD3D_SIV_LINE_DENSITY_TESS_FACTOR, {VKD3D_SHADER_COMPONENT_FLOAT, 1, SpvBuiltInTessLevelOuter, NULL, 4, 0}}, + {VKD3D_SIV_LINE_DETAIL_TESS_FACTOR, {VKD3D_SHADER_COMPONENT_FLOAT, 1, SpvBuiltInTessLevelOuter, NULL, 4, 1}}, }; static const struct vkd3d_spirv_builtin vkd3d_pixel_shader_position_builtin = { diff --git a/tests/d3d12.c b/tests/d3d12.c index ed85f4a1..3202c10b 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -29135,9 +29135,9 @@ static void test_tessellation_ds_inputs(void) 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}, + {false, false, false, false, true, true, false, false}, + {false, false, false, false, true, true, false, false}, + {false, false, false, false, true, true, false, false}, }; static const unsigned int stride = sizeof(reference[0]);
Otherwise if the input is located above position 0 in the private array it will be swizzled incorrectly, e.g. a.yz instead of a.xy in test_tessellation_ds_inputs().
Based on a vkd3d-proton patch by Hans-Kristian Arntzen.
Signed-off-by: Conor McCarthy cmccarthy@codeweaver.com --- libs/vkd3d-shader/spirv.c | 4 ++-- tests/d3d12.c | 8 -------- 2 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 379746b7..6680551b 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -4632,8 +4632,8 @@ static uint32_t vkd3d_dxbc_compiler_emit_input(struct vkd3d_dxbc_compiler *compi }
val_id = vkd3d_dxbc_compiler_emit_swizzle(compiler, val_id, - vkd3d_write_mask_from_component_count(input_component_count) << component_idx, - VKD3D_SHADER_COMPONENT_FLOAT, VKD3D_SHADER_NO_SWIZZLE, dst->write_mask); + vkd3d_write_mask_from_component_count(input_component_count), + VKD3D_SHADER_COMPONENT_FLOAT, VKD3D_SHADER_NO_SWIZZLE, dst->write_mask >> component_idx);
vkd3d_dxbc_compiler_emit_store_reg(compiler, &dst_reg, dst->write_mask, val_id); } diff --git a/tests/d3d12.c b/tests/d3d12.c index 3202c10b..be9017f5 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -29132,13 +29132,6 @@ static void test_tessellation_ds_inputs(void) {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, false, false, true, true, false, false}, - {false, false, false, false, true, true, false, false}, - {false, false, false, false, true, true, false, false}, - }; static const unsigned int stride = sizeof(reference[0]);
memset(&desc, 0, sizeof(desc)); @@ -29188,7 +29181,6 @@ static void test_tessellation_ds_inputs(void) 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]); }