From: Henri Verbeet hverbeet@codeweavers.com Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- tests/d3d12.c | 199 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 198 insertions(+), 1 deletion(-)
diff --git a/tests/d3d12.c b/tests/d3d12.c index ce6d6b36..4397c063 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -740,7 +740,7 @@ static ID3D12PipelineState *create_compute_pipeline_state_(unsigned int line, ID ID3D12RootSignature *root_signature, const D3D12_SHADER_BYTECODE cs) { D3D12_COMPUTE_PIPELINE_STATE_DESC pipeline_state_desc; - ID3D12PipelineState *pipeline_state; + ID3D12PipelineState *pipeline_state = NULL; HRESULT hr;
memset(&pipeline_state_desc, 0, sizeof(pipeline_state_desc)); @@ -33837,6 +33837,202 @@ static void test_hull_shader_patch_constant_inputs(void) destroy_test_context(&context); }
+static void test_resource_arrays(void) +{ + ID3D12Resource *input_buffers[8], *output_buffers[6]; + D3D12_ROOT_SIGNATURE_DESC root_signature_desc; + D3D12_UNORDERED_ACCESS_VIEW_DESC uav_desc; + D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc; + ID3D12GraphicsCommandList *command_list; + unsigned int descriptor_count; + struct resource_readback rb; + struct test_context context; + ID3D12DescriptorHeap *heap; + ID3D12CommandQueue *queue; + ID3D12Device *device; + unsigned int i; + HRESULT hr; + + static const D3D12_DESCRIPTOR_RANGE descriptor_ranges[] = + { + {D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 8, 2, 2, 0}, + {D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 6, 1, 3, D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND}, + }; + + static const struct uvec4 cb_data[] = + { + {0, 0}, + {1, 1}, + {0, 5}, + {1, 4}, + {2, 0}, + {3, 1}, + }; + + static const D3D12_ROOT_PARAMETER root_parameters[] = + { + {D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE, + .DescriptorTable = {ARRAY_SIZE(descriptor_ranges), descriptor_ranges}}, + {D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS, .Constants = {2, 1, ARRAY_SIZE(cb_data) * 4}}, + }; + + static const DWORD cs_code[] = + { +#if 0 + cbuffer cb : register(b2, space1) + { + uint2 c[6]; + } + + Buffer<uint> t1[2] : register(t2, space2); + Buffer<uint> t2[] : register(t4, space2); + + RWBuffer<uint> u1[2] : register(u1, space3); + RWBuffer<uint> u2[] : register(u3, space3); + + [numthreads(1, 1, 1)] + void main() + { + u1[c[0].x][0] = t1[c[0].y][0]; + u1[c[1].x][0] = t1[c[1].y][0]; + u2[c[2].x][0] = t2[c[2].y][0]; + u2[c[3].x][0] = t2[c[3].y][0]; + u2[c[4].x][0] = t2[c[4].y][0]; + u2[c[5].x][0] = t2[c[5].y][0]; + } +#endif + 0x43425844, 0xef615fd3, 0x708c1d93, 0xdb9908b4, 0xb1853d57, 0x00000001, 0x000004c8, 0x00000003, + 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000474, 0x00050051, 0x0000011d, 0x0100086a, + 0x07000059, 0x00308e46, 0x00000000, 0x00000002, 0x00000002, 0x00000006, 0x00000001, 0x07000858, + 0x00307e46, 0x00000000, 0x00000002, 0x00000003, 0x00004444, 0x00000002, 0x07000858, 0x00307e46, + 0x00000001, 0x00000004, 0xffffffff, 0x00004444, 0x00000002, 0x0700089c, 0x0031ee46, 0x00000000, + 0x00000001, 0x00000002, 0x00004444, 0x00000003, 0x0700089c, 0x0031ee46, 0x00000001, 0x00000003, + 0xffffffff, 0x00004444, 0x00000003, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, + 0x00000001, 0x07000036, 0x00100012, 0x00000000, 0x0030801a, 0x00000000, 0x00000002, 0x00000000, + 0x0d00002d, 0x00100012, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x06207e46, 0x00000000, 0x00000002, 0x0010000a, 0x00000000, 0x07000036, 0x00100022, 0x00000000, + 0x0030800a, 0x00000000, 0x00000002, 0x00000000, 0x0d0000a4, 0x0621e0f2, 0x00000000, 0x00000001, + 0x0010001a, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00100006, + 0x00000000, 0x07000036, 0x00100012, 0x00000000, 0x0030801a, 0x00000000, 0x00000002, 0x00000001, + 0x0d00002d, 0x00100012, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x06207e46, 0x00000000, 0x00000002, 0x0010000a, 0x00000000, 0x07000036, 0x00100022, 0x00000000, + 0x0030800a, 0x00000000, 0x00000002, 0x00000001, 0x0d0000a4, 0x0621e0f2, 0x00000000, 0x00000001, + 0x0010001a, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00100006, + 0x00000000, 0x07000036, 0x00100012, 0x00000000, 0x0030801a, 0x00000000, 0x00000002, 0x00000002, + 0x0d00002d, 0x00100012, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x06207e46, 0x00000001, 0x00000004, 0x0010000a, 0x00000000, 0x07000036, 0x00100022, 0x00000000, + 0x0030800a, 0x00000000, 0x00000002, 0x00000002, 0x0d0000a4, 0x0621e0f2, 0x00000001, 0x00000003, + 0x0010001a, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00100006, + 0x00000000, 0x07000036, 0x00100012, 0x00000000, 0x0030801a, 0x00000000, 0x00000002, 0x00000003, + 0x0d00002d, 0x00100012, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x06207e46, 0x00000001, 0x00000004, 0x0010000a, 0x00000000, 0x07000036, 0x00100022, 0x00000000, + 0x0030800a, 0x00000000, 0x00000002, 0x00000003, 0x0d0000a4, 0x0621e0f2, 0x00000001, 0x00000003, + 0x0010001a, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00100006, + 0x00000000, 0x07000036, 0x00100012, 0x00000000, 0x0030801a, 0x00000000, 0x00000002, 0x00000004, + 0x0d00002d, 0x00100012, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x06207e46, 0x00000001, 0x00000004, 0x0010000a, 0x00000000, 0x07000036, 0x00100022, 0x00000000, + 0x0030800a, 0x00000000, 0x00000002, 0x00000004, 0x0d0000a4, 0x0621e0f2, 0x00000001, 0x00000003, + 0x0010001a, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00100006, + 0x00000000, 0x07000036, 0x00100012, 0x00000000, 0x0030801a, 0x00000000, 0x00000002, 0x00000005, + 0x0d00002d, 0x00100012, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x06207e46, 0x00000001, 0x00000004, 0x0010000a, 0x00000000, 0x07000036, 0x00100022, 0x00000000, + 0x0030800a, 0x00000000, 0x00000002, 0x00000005, 0x0d0000a4, 0x0621e0f2, 0x00000001, 0x00000003, + 0x0010001a, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00100006, + 0x00000000, 0x0100003e, + }; + + static const uint32_t srv_data[] = {0x1, 0x4, 0x9, 0x10, 0x19, 0x24, 0x31, 0x40}; + static const uint32_t uav_data[] = {0x1, 0x4, 0x40, 0x31, 0x9, 0x10}; + + if (!init_compute_test_context(&context)) + return; + device = context.device; + command_list = context.list; + queue = context.queue; + + memset(&root_signature_desc, 0, sizeof(root_signature_desc)); + root_signature_desc.NumParameters = ARRAY_SIZE(root_parameters); + root_signature_desc.pParameters = root_parameters; + hr = create_root_signature(device, &root_signature_desc, &context.root_signature); + ok(hr == S_OK, "Failed to create root signature, hr %#x.\n", hr); + + for (i = 0, descriptor_count = 0; i < ARRAY_SIZE(descriptor_ranges); ++i) + { + descriptor_count += descriptor_ranges[i].NumDescriptors; + } + heap = create_gpu_descriptor_heap(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, descriptor_count); + + for (i = 0; i < ARRAY_SIZE(input_buffers); ++i) + { + input_buffers[i] = create_default_buffer(device, sizeof(uint32_t), + D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COPY_DEST); + upload_buffer_data(input_buffers[i], 0, sizeof(srv_data[i]), &srv_data[i], queue, command_list); + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, input_buffers[i], + D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); + + memset(&srv_desc, 0, sizeof(srv_desc)); + srv_desc.Format = DXGI_FORMAT_R32_UINT; + srv_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; + srv_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + srv_desc.Buffer.FirstElement = 0; + srv_desc.Buffer.NumElements = 1; + ID3D12Device_CreateShaderResourceView(device, input_buffers[i], &srv_desc, + get_cpu_descriptor_handle(&context, heap, i)); + } + + for (i = 0; i < ARRAY_SIZE(output_buffers); ++i) + { + output_buffers[i] = create_default_buffer(device, sizeof(uint32_t), + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + + memset(&uav_desc, 0, sizeof(uav_desc)); + uav_desc.Format = DXGI_FORMAT_R32_UINT; + uav_desc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER; + uav_desc.Buffer.FirstElement = 0; + uav_desc.Buffer.NumElements = 1; + ID3D12Device_CreateUnorderedAccessView(device, output_buffers[i], NULL, &uav_desc, + get_cpu_descriptor_handle(&context, heap, ARRAY_SIZE(input_buffers) + i)); + } + + context.pipeline_state = create_compute_pipeline_state(device, context.root_signature, + shader_bytecode(cs_code, sizeof(cs_code))); + if (!context.pipeline_state) + { + skip("Shader descriptor arrays are not supported.\n"); + goto done; + } + + ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state); + ID3D12GraphicsCommandList_SetComputeRootSignature(command_list, context.root_signature); + ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(command_list, + 0, get_gpu_descriptor_handle(&context, heap, 0)); + ID3D12GraphicsCommandList_SetComputeRoot32BitConstants(command_list, 1, ARRAY_SIZE(cb_data) * 4, cb_data, 0); + + ID3D12GraphicsCommandList_Dispatch(command_list, 1, 1, 1); + + for (i = 0; i < ARRAY_SIZE(output_buffers); ++i) + { + vkd3d_test_set_context("buffer %u", i); + transition_sub_resource_state(command_list, output_buffers[i], 0, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); + get_buffer_readback_with_command_list(output_buffers[i], DXGI_FORMAT_R32_UINT, &rb, queue, command_list); + todo_if(i) + check_readback_data_uint(&rb, NULL, uav_data[i], 0); + release_resource_readback(&rb); + reset_command_list(command_list, context.allocator); + } + +done: + for (i = 0; i < ARRAY_SIZE(output_buffers); ++i) + ID3D12Resource_Release(output_buffers[i]); + for (i = 0; i < ARRAY_SIZE(input_buffers); ++i) + ID3D12Resource_Release(input_buffers[i]); + ID3D12DescriptorHeap_Release(heap); + destroy_test_context(&context); +} + START_TEST(d3d12) { parse_args(argc, argv); @@ -34005,4 +34201,5 @@ START_TEST(d3d12) run_test(test_sampler_register_space); run_test(test_hull_shader_relative_addressing); run_test(test_hull_shader_patch_constant_inputs); + run_test(test_resource_arrays); }
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d-shader/dxbc.c | 28 +++++++++++++----- libs/vkd3d-shader/trace.c | 60 +++++++++++++++++++++------------------ 2 files changed, 54 insertions(+), 34 deletions(-)
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c index 4bc62014..b81ac976 100644 --- a/libs/vkd3d-shader/dxbc.c +++ b/libs/vkd3d-shader/dxbc.c @@ -637,8 +637,8 @@ static void shader_sm4_read_shader_data(struct vkd3d_shader_instruction *ins, static void shader_sm4_set_descriptor_register_range(struct vkd3d_sm4_data *priv, struct vkd3d_shader_register *reg, struct vkd3d_shader_register_range *range) { - range->first = reg->idx[shader_is_sm_5_1(priv) ? 1 : 0].offset; - range->last = reg->idx[shader_is_sm_5_1(priv) ? 2 : 0].offset; + range->first = reg->idx[1].offset; + range->last = reg->idx[shader_is_sm_5_1(priv) ? 2 : 1].offset; if (range->last < range->first) { FIXME("Invalid register range [%u:%u].\n", range->first, range->last); @@ -1516,6 +1516,21 @@ static bool shader_sm4_read_reg_idx(struct vkd3d_sm4_data *priv, const DWORD **p return true; }
+static bool sm4_register_is_descriptor(enum vkd3d_sm4_register_type register_type) +{ + switch (register_type) + { + case VKD3D_SM4_RT_SAMPLER: + case VKD3D_SM4_RT_RESOURCE: + case VKD3D_SM4_RT_CONSTBUFFER: + case VKD3D_SM5_RT_UAV: + return true; + + default: + return false; + } +} + static bool shader_sm4_read_param(struct vkd3d_sm4_data *priv, const DWORD **ptr, const DWORD *end, enum vkd3d_data_type data_type, struct vkd3d_shader_register *param, enum vkd3d_shader_src_modifier *modifier) @@ -1667,13 +1682,12 @@ static bool shader_sm4_read_param(struct vkd3d_sm4_data *priv, const DWORD **ptr break; } } - else if (register_type == VKD3D_SM4_RT_CONSTBUFFER && order == 2) + else if (!shader_is_sm_5_1(priv) && sm4_register_is_descriptor(register_type)) { - /* SM5.1 places the buffer offset in idx[2]; earlier versions place it - * in idx[1]. Normalize to SM5.1. */ + /* SM5.1 places a symbol identifier in idx[0] and moves + * other values up one slot. Normalize to SM5.1. */ param->idx[2] = param->idx[1]; - param->idx[1].rel_addr = NULL; - param->idx[1].offset = 0; + param->idx[1] = param->idx[0]; }
map_register(priv, param); diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c index 2d16714b..8da877b4 100644 --- a/libs/vkd3d-shader/trace.c +++ b/libs/vkd3d-shader/trace.c @@ -762,7 +762,8 @@ static void shader_print_subscript(struct vkd3d_d3d_asm_compiler *compiler, shader_print_uint_literal(compiler, "", offset, "]"); }
-static void shader_dump_register(struct vkd3d_d3d_asm_compiler *compiler, const struct vkd3d_shader_register *reg) +static void shader_dump_register(struct vkd3d_d3d_asm_compiler *compiler, const struct vkd3d_shader_register *reg, + bool is_descriptor_declaration) { struct vkd3d_string_buffer *buffer = &compiler->buffer; unsigned int offset = reg->idx[0].offset; @@ -1057,15 +1058,20 @@ static void shader_dump_register(struct vkd3d_d3d_asm_compiler *compiler, const vkd3d_string_buffer_printf(buffer, "%u%s", offset, compiler->colours.reset); }
- /* For CBs in sm < 5.1 we move the buffer offset from idx[1] to idx[2] - * to normalise it with 5.1. - * Here we should ignore it if it's a CB in sm < 5.1. */ - if (reg->idx[1].offset != ~0u && - (reg->type != VKD3DSPR_CONSTBUFFER || shader_ver_ge(&compiler->shader_version, 5, 1))) - shader_print_subscript(compiler, reg->idx[1].offset, reg->idx[1].rel_addr); + /* For descriptors in sm < 5.1 we move the reg->idx values up one slot + * to normalise with 5.1. */ + if (shader_ver_ge(&compiler->shader_version, 5, 1) && is_descriptor_declaration) + { + shader_print_subscript(compiler, reg->idx[1].offset, NULL); + } + else + { + if (reg->idx[1].offset != ~0u) + shader_print_subscript(compiler, reg->idx[1].offset, reg->idx[1].rel_addr);
- if (reg->idx[2].offset != ~0u) - shader_print_subscript(compiler, reg->idx[2].offset, reg->idx[2].rel_addr); + if (reg->idx[2].offset != ~0u) + shader_print_subscript(compiler, reg->idx[2].offset, reg->idx[2].rel_addr); + } } else { @@ -1082,12 +1088,12 @@ static void shader_dump_register(struct vkd3d_d3d_asm_compiler *compiler, const }
static void shader_dump_dst_param(struct vkd3d_d3d_asm_compiler *compiler, - const struct vkd3d_shader_dst_param *param) + const struct vkd3d_shader_dst_param *param, bool is_descriptor_declaration) { struct vkd3d_string_buffer *buffer = &compiler->buffer; uint32_t write_mask = param->write_mask;
- shader_dump_register(compiler, ¶m->reg); + shader_dump_register(compiler, ¶m->reg, is_descriptor_declaration);
if (write_mask) { @@ -1127,7 +1133,7 @@ static void shader_dump_src_param(struct vkd3d_d3d_asm_compiler *compiler, if (src_modifier == VKD3DSPSM_ABS || src_modifier == VKD3DSPSM_ABSNEG) shader_addline(buffer, "|");
- shader_dump_register(compiler, ¶m->reg); + shader_dump_register(compiler, ¶m->reg, false);
switch (src_modifier) { @@ -1427,13 +1433,13 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, shader_dump_decl_usage(compiler, &ins->declaration.semantic, ins->flags); shader_dump_ins_modifiers(compiler, &ins->declaration.semantic.resource.reg); vkd3d_string_buffer_printf(buffer, "%s ", compiler->colours.reset); - shader_dump_register(compiler, &ins->declaration.semantic.resource.reg.reg); + shader_dump_register(compiler, &ins->declaration.semantic.resource.reg.reg, true); shader_dump_register_space(compiler, ins->declaration.semantic.resource.range.space); break;
case VKD3DSIH_DCL_CONSTANT_BUFFER: vkd3d_string_buffer_printf(buffer, " "); - shader_dump_register(compiler, &ins->declaration.cb.src.reg); + shader_dump_register(compiler, &ins->declaration.cb.src.reg, true); if (shader_ver_ge(&compiler->shader_version, 5, 1)) shader_print_subscript(compiler, ins->declaration.cb.size, NULL); shader_addline(buffer, ", %s", @@ -1472,7 +1478,7 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler,
case VKD3DSIH_DCL_INDEX_RANGE: vkd3d_string_buffer_printf(buffer, " "); - shader_dump_dst_param(compiler, &ins->declaration.index_range.dst); + shader_dump_dst_param(compiler, &ins->declaration.index_range.dst, false); shader_print_uint_literal(compiler, " ", ins->declaration.index_range.register_count, ""); break;
@@ -1487,7 +1493,7 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, vkd3d_string_buffer_printf(buffer, " "); shader_dump_interpolation_mode(compiler, ins->flags); shader_addline(buffer, " "); - shader_dump_dst_param(compiler, &ins->declaration.dst); + shader_dump_dst_param(compiler, &ins->declaration.dst, false); break;
case VKD3DSIH_DCL_INPUT_PS_SGV: @@ -1495,7 +1501,7 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, case VKD3DSIH_DCL_INPUT_SIV: case VKD3DSIH_DCL_OUTPUT_SIV: vkd3d_string_buffer_printf(buffer, " "); - shader_dump_dst_param(compiler, &ins->declaration.register_semantic.reg); + shader_dump_dst_param(compiler, &ins->declaration.register_semantic.reg, false); shader_addline(buffer, ", "); shader_dump_shader_input_sysval_semantic(compiler, ins->declaration.register_semantic.sysval_semantic); break; @@ -1504,7 +1510,7 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, vkd3d_string_buffer_printf(buffer, " "); shader_dump_interpolation_mode(compiler, ins->flags); shader_addline(buffer, " "); - shader_dump_dst_param(compiler, &ins->declaration.register_semantic.reg); + shader_dump_dst_param(compiler, &ins->declaration.register_semantic.reg, false); shader_addline(buffer, ", "); shader_dump_shader_input_sysval_semantic(compiler, ins->declaration.register_semantic.sysval_semantic); break; @@ -1512,7 +1518,7 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, case VKD3DSIH_DCL_INPUT: case VKD3DSIH_DCL_OUTPUT: vkd3d_string_buffer_printf(buffer, " "); - shader_dump_dst_param(compiler, &ins->declaration.dst); + shader_dump_dst_param(compiler, &ins->declaration.dst, false); break;
case VKD3DSIH_DCL_INPUT_PRIMITIVE: @@ -1530,20 +1536,20 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler,
case VKD3DSIH_DCL_RESOURCE_RAW: vkd3d_string_buffer_printf(buffer, " "); - shader_dump_dst_param(compiler, &ins->declaration.raw_resource.resource.reg); + shader_dump_dst_param(compiler, &ins->declaration.raw_resource.resource.reg, true); shader_dump_register_space(compiler, ins->declaration.raw_resource.resource.range.space); break;
case VKD3DSIH_DCL_RESOURCE_STRUCTURED: vkd3d_string_buffer_printf(buffer, " "); - shader_dump_dst_param(compiler, &ins->declaration.structured_resource.resource.reg); + shader_dump_dst_param(compiler, &ins->declaration.structured_resource.resource.reg, true); shader_print_uint_literal(compiler, ", ", ins->declaration.structured_resource.byte_stride, ""); shader_dump_register_space(compiler, ins->declaration.structured_resource.resource.range.space); break;
case VKD3DSIH_DCL_SAMPLER: vkd3d_string_buffer_printf(buffer, " "); - shader_dump_register(compiler, &ins->declaration.sampler.src.reg); + shader_dump_register(compiler, &ins->declaration.sampler.src.reg, true); if (ins->flags == VKD3DSI_SAMPLER_COMPARISON_MODE) shader_addline(buffer, ", comparisonMode"); shader_dump_register_space(compiler, ins->declaration.sampler.range.space); @@ -1576,13 +1582,13 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler,
case VKD3DSIH_DCL_TGSM_RAW: vkd3d_string_buffer_printf(buffer, " "); - shader_dump_dst_param(compiler, &ins->declaration.tgsm_raw.reg); + shader_dump_dst_param(compiler, &ins->declaration.tgsm_raw.reg, false); shader_print_uint_literal(compiler, ", ", ins->declaration.tgsm_raw.byte_count, ""); break;
case VKD3DSIH_DCL_TGSM_STRUCTURED: vkd3d_string_buffer_printf(buffer, " "); - shader_dump_dst_param(compiler, &ins->declaration.tgsm_structured.reg); + shader_dump_dst_param(compiler, &ins->declaration.tgsm_structured.reg, false); shader_print_uint_literal(compiler, ", ", ins->declaration.tgsm_structured.byte_stride, ""); shader_print_uint_literal(compiler, ", ", ins->declaration.tgsm_structured.structure_count, ""); break; @@ -1596,14 +1602,14 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, case VKD3DSIH_DCL_UAV_RAW: shader_dump_uav_flags(compiler, ins->flags); shader_addline(buffer, " "); - shader_dump_dst_param(compiler, &ins->declaration.raw_resource.resource.reg); + shader_dump_dst_param(compiler, &ins->declaration.raw_resource.resource.reg, true); shader_dump_register_space(compiler, ins->declaration.raw_resource.resource.range.space); break;
case VKD3DSIH_DCL_UAV_STRUCTURED: shader_dump_uav_flags(compiler, ins->flags); shader_addline(buffer, " "); - shader_dump_dst_param(compiler, &ins->declaration.structured_resource.resource.reg); + shader_dump_dst_param(compiler, &ins->declaration.structured_resource.resource.reg, true); shader_print_uint_literal(compiler, ", ", ins->declaration.structured_resource.byte_stride, ""); shader_dump_register_space(compiler, ins->declaration.structured_resource.resource.range.space); break; @@ -1666,7 +1672,7 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, { shader_dump_ins_modifiers(compiler, &ins->dst[i]); shader_addline(buffer, !i ? " " : ", "); - shader_dump_dst_param(compiler, &ins->dst[i]); + shader_dump_dst_param(compiler, &ins->dst[i], false); }
/* Other source tokens */
On Wed, 7 Jul 2021 at 03:20, Conor McCarthy cmccarthy@codeweavers.com wrote:
-static void shader_dump_register(struct vkd3d_d3d_asm_compiler *compiler, const struct vkd3d_shader_register *reg) +static void shader_dump_register(struct vkd3d_d3d_asm_compiler *compiler, const struct vkd3d_shader_register *reg,
bool is_descriptor_declaration)
{
I think technically we would only need to know whether the register is part of a declaration; shader_dump_register() should be able to figure out whether something is a descriptor on its own.
@@ -1057,15 +1058,20 @@ static void shader_dump_register(struct vkd3d_d3d_asm_compiler *compiler, const vkd3d_string_buffer_printf(buffer, "%u%s", offset, compiler->colours.reset); }
/* For CBs in sm < 5.1 we move the buffer offset from idx[1] to idx[2]
* to normalise it with 5.1.
* Here we should ignore it if it's a CB in sm < 5.1. */
if (reg->idx[1].offset != ~0u &&
(reg->type != VKD3DSPR_CONSTBUFFER || shader_ver_ge(&compiler->shader_version, 5, 1)))
shader_print_subscript(compiler, reg->idx[1].offset, reg->idx[1].rel_addr);
/* For descriptors in sm < 5.1 we move the reg->idx values up one slot
* to normalise with 5.1. */
if (shader_ver_ge(&compiler->shader_version, 5, 1) && is_descriptor_declaration)
{
shader_print_subscript(compiler, reg->idx[1].offset, NULL);
}
else
{
if (reg->idx[1].offset != ~0u)
shader_print_subscript(compiler, reg->idx[1].offset, reg->idx[1].rel_addr);
if (reg->idx[2].offset != ~0u)
shader_print_subscript(compiler, reg->idx[2].offset, reg->idx[2].rel_addr);
if (reg->idx[2].offset != ~0u)
shader_print_subscript(compiler, reg->idx[2].offset, reg->idx[2].rel_addr);
} }
That doesn't do the right thing. For example:
before this patch: ps_5_0 dcl_globalFlags refactoringAllowed dcl_constantBuffer cb0[1], immediateIndexed dcl_sampler s0 dcl_resource_texturecube(float,float,float,float) t0 ... switch cb0[0].x ... after: ps_5_0 dcl_globalFlags refactoringAllowed dcl_constantBuffer cb0[0][1], immediateIndexed dcl_sampler s0[0] dcl_resource_texturecube(float,float,float,float) t0[0] ... switch cb0[0][0].x ...
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d-shader/trace.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c index 8da877b4..e55ef3a2 100644 --- a/libs/vkd3d-shader/trace.c +++ b/libs/vkd3d-shader/trace.c @@ -762,6 +762,16 @@ static void shader_print_subscript(struct vkd3d_d3d_asm_compiler *compiler, shader_print_uint_literal(compiler, "", offset, "]"); }
+static void shader_print_subscript_range(struct vkd3d_d3d_asm_compiler *compiler, + unsigned int offset_first, unsigned int offset_last) +{ + shader_print_uint_literal(compiler, "[", offset_first, ":"); + if (offset_last != ~0u) + shader_print_uint_literal(compiler, "", offset_last, "]"); + else + vkd3d_string_buffer_printf(&compiler->buffer, "*]"); +} + static void shader_dump_register(struct vkd3d_d3d_asm_compiler *compiler, const struct vkd3d_shader_register *reg, bool is_descriptor_declaration) { @@ -1059,10 +1069,11 @@ static void shader_dump_register(struct vkd3d_d3d_asm_compiler *compiler, const }
/* For descriptors in sm < 5.1 we move the reg->idx values up one slot - * to normalise with 5.1. */ + * to normalise with 5.1. For 5.1 descriptor declarations we need to + * trace the register range instead of a single register index. */ if (shader_ver_ge(&compiler->shader_version, 5, 1) && is_descriptor_declaration) { - shader_print_subscript(compiler, reg->idx[1].offset, NULL); + shader_print_subscript_range(compiler, reg->idx[1].offset, reg->idx[2].offset); } else {