Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d-shader/dxbc.c | 32 ++++++++++++++++-------- libs/vkd3d-shader/spirv.c | 21 ++++++++-------- libs/vkd3d-shader/trace.c | 10 ++++---- libs/vkd3d-shader/vkd3d_shader_main.c | 4 +-- libs/vkd3d-shader/vkd3d_shader_private.h | 9 +++++-- 5 files changed, 46 insertions(+), 30 deletions(-)
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c index d2cf87e3..89971477 100644 --- a/libs/vkd3d-shader/dxbc.c +++ b/libs/vkd3d-shader/dxbc.c @@ -630,6 +630,18 @@ static unsigned int shader_sm4_map_resource_idx(struct vkd3d_shader_register *re return reg->idx[0].offset; }
+static void shader_sm4_read_descriptor_register_range(struct vkd3d_sm4_data *priv, const DWORD **ptr, + const DWORD *end, struct vkd3d_shader_register *reg, struct vkd3d_descriptor_register_range *range) +{ + shader_sm4_read_register_space(priv, ptr, end, &range->space); + 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; + if (range->last < range->first) + { + FIXME("Invalid register range [%u:%u].\n", range->first, range->last); + } +} + static void shader_sm4_read_dcl_resource(struct vkd3d_shader_instruction *ins, DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count, struct vkd3d_sm4_data *priv) @@ -654,7 +666,6 @@ static void shader_sm4_read_dcl_resource(struct vkd3d_shader_instruction *ins, } reg_data_type = opcode == VKD3D_SM4_OP_DCL_RESOURCE ? VKD3D_DATA_RESOURCE : VKD3D_DATA_UAV; shader_sm4_read_dst_param(priv, &tokens, end, reg_data_type, &semantic->resource.reg); - semantic->resource.register_index = shader_sm4_map_resource_idx(&semantic->resource.reg.reg, priv);
components = *tokens++; for (i = 0; i < VKD3D_VEC4_SIZE; i++) @@ -675,7 +686,8 @@ static void shader_sm4_read_dcl_resource(struct vkd3d_shader_instruction *ins, if (reg_data_type == VKD3D_DATA_UAV) ins->flags = (opcode_token & VKD3D_SM5_UAV_FLAGS_MASK) >> VKD3D_SM5_UAV_FLAGS_SHIFT;
- shader_sm4_read_register_space(priv, &tokens, end, &semantic->resource.register_space); + shader_sm4_read_descriptor_register_range(priv, &tokens, end, &semantic->resource.reg.reg, + &semantic->resource.range); }
static void shader_sm4_read_dcl_constant_buffer(struct vkd3d_shader_instruction *ins, @@ -916,9 +928,9 @@ static void shader_sm5_read_dcl_uav_raw(struct vkd3d_shader_instruction *ins, const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_UAV, &resource->resource.reg); - resource->resource.register_index = shader_sm4_map_resource_idx(&resource->resource.reg.reg, priv); ins->flags = (opcode_token & VKD3D_SM5_UAV_FLAGS_MASK) >> VKD3D_SM5_UAV_FLAGS_SHIFT; - shader_sm4_read_register_space(priv, &tokens, end, &resource->resource.register_space); + shader_sm4_read_descriptor_register_range(priv, &tokens, end, + &resource->resource.reg.reg, &resource->resource.range); }
static void shader_sm5_read_dcl_uav_structured(struct vkd3d_shader_instruction *ins, @@ -929,12 +941,12 @@ static void shader_sm5_read_dcl_uav_structured(struct vkd3d_shader_instruction * const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_UAV, &resource->resource.reg); - resource->resource.register_index = shader_sm4_map_resource_idx(&resource->resource.reg.reg, priv); ins->flags = (opcode_token & VKD3D_SM5_UAV_FLAGS_MASK) >> VKD3D_SM5_UAV_FLAGS_SHIFT; resource->byte_stride = *tokens++; if (resource->byte_stride % 4) FIXME("Byte stride %u is not multiple of 4.\n", resource->byte_stride); - shader_sm4_read_register_space(priv, &tokens, end, &resource->resource.register_space); + shader_sm4_read_descriptor_register_range(priv, &tokens, end, + &resource->resource.reg.reg, &resource->resource.range); }
static void shader_sm5_read_dcl_tgsm_raw(struct vkd3d_shader_instruction *ins, @@ -967,11 +979,11 @@ static void shader_sm5_read_dcl_resource_structured(struct vkd3d_shader_instruct const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_RESOURCE, &resource->resource.reg); - resource->resource.register_index = shader_sm4_map_resource_idx(&resource->resource.reg.reg, priv); resource->byte_stride = *tokens++; if (resource->byte_stride % 4) FIXME("Byte stride %u is not multiple of 4.\n", resource->byte_stride); - shader_sm4_read_register_space(priv, &tokens, end, &resource->resource.register_space); + shader_sm4_read_descriptor_register_range(priv, &tokens, end, + &resource->resource.reg.reg, &resource->resource.range); }
static void shader_sm5_read_dcl_resource_raw(struct vkd3d_shader_instruction *ins, @@ -982,8 +994,8 @@ static void shader_sm5_read_dcl_resource_raw(struct vkd3d_shader_instruction *in const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_RESOURCE, &resource->resource.reg); - resource->resource.register_index = shader_sm4_map_resource_idx(&resource->resource.reg.reg, priv); - shader_sm4_read_register_space(priv, &tokens, end, &resource->resource.register_space); + shader_sm4_read_descriptor_register_range(priv, &tokens, end, + &resource->resource.reg.reg, &resource->resource.range); }
static void shader_sm5_read_sync(struct vkd3d_shader_instruction *ins, diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 0e75b0ae..f34a6a1d 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -1932,8 +1932,7 @@ struct vkd3d_symbol_register_data
struct vkd3d_symbol_resource_data { - unsigned int register_space; - unsigned int register_index; + struct vkd3d_descriptor_register_range range; enum vkd3d_shader_component_type sampled_type; uint32_t type_id; const struct vkd3d_spirv_resource_type *resource_type_info; @@ -2441,8 +2440,8 @@ static bool vkd3d_dxbc_compiler_has_combined_sampler(const struct vkd3d_dxbc_com if (!vkd3d_dxbc_compiler_check_shader_visibility(compiler, combined_sampler->shader_visibility)) continue;
- if ((!resource || (combined_sampler->resource_space == resource->register_space - && combined_sampler->resource_index == resource->register_index)) + if ((!resource || (combined_sampler->resource_space == resource->range.space + && combined_sampler->resource_index == resource->range.first)) && (!sampler || (combined_sampler->sampler_space == sampler->register_space && combined_sampler->sampler_index == sampler->register_index))) return true; @@ -5533,8 +5532,9 @@ static void vkd3d_dxbc_compiler_emit_combined_sampler_declarations(struct vkd3d_ current->sampler_index == VKD3D_SHADER_DUMMY_SAMPLER_INDEX ? 0 : current->sampler_space, current->sampler_index); symbol.id = var_id; - symbol.info.resource.register_space = resource_space; - symbol.info.resource.register_index = resource_index; + symbol.info.resource.range.space = resource_space; + symbol.info.resource.range.first = resource_index; + symbol.info.resource.range.last = resource_index; symbol.info.resource.sampled_type = sampled_type; symbol.info.resource.type_id = image_type_id; symbol.info.resource.resource_type_info = resource_type_info; @@ -5554,8 +5554,8 @@ static void vkd3d_dxbc_compiler_emit_resource_declaration(struct vkd3d_dxbc_comp SpvStorageClass storage_class = SpvStorageClassUniformConstant; const struct vkd3d_shader_register *reg = &resource->reg.reg; const struct vkd3d_spirv_resource_type *resource_type_info; - unsigned int register_space = resource->register_space; - unsigned int register_index = resource->register_index; + unsigned int register_space = resource->range.space; + unsigned int register_index = resource->range.first; enum vkd3d_shader_component_type sampled_type; struct vkd3d_symbol resource_symbol; bool is_uav; @@ -5657,8 +5657,7 @@ static void vkd3d_dxbc_compiler_emit_resource_declaration(struct vkd3d_dxbc_comp
vkd3d_symbol_make_resource(&resource_symbol, reg); resource_symbol.id = var_id; - resource_symbol.info.resource.register_space = register_space; - resource_symbol.info.resource.register_index = register_index; + resource_symbol.info.resource.range = resource->range; resource_symbol.info.resource.sampled_type = sampled_type; resource_symbol.info.resource.type_id = type_id; resource_symbol.info.resource.resource_type_info = resource_type_info; @@ -7673,7 +7672,7 @@ static void vkd3d_dxbc_compiler_prepare_image(struct vkd3d_dxbc_compiler *compil image->image_type_id, image->id, SpvMemoryAccessMaskNone) : 0;
image->image_type_id = vkd3d_dxbc_compiler_get_image_type_id(compiler, resource_reg, - symbol->info.resource.register_space, symbol->info.resource.register_index, image->resource_type_info, + symbol->info.resource.range.space, symbol->info.resource.range.first, image->resource_type_info, image->sampled_type, image->structure_stride || image->raw, depth_comparison);
if (sampled) diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c index 4e355118..c35179a8 100644 --- a/libs/vkd3d-shader/trace.c +++ b/libs/vkd3d-shader/trace.c @@ -1428,7 +1428,7 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, 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_space(compiler, ins->declaration.semantic.resource.register_space); + shader_dump_register_space(compiler, ins->declaration.semantic.resource.range.space); break;
case VKD3DSIH_DCL_CONSTANT_BUFFER: @@ -1531,14 +1531,14 @@ 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_register_space(compiler, ins->declaration.raw_resource.resource.register_space); + 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_print_uint_literal(compiler, ", ", ins->declaration.structured_resource.byte_stride, ""); - shader_dump_register_space(compiler, ins->declaration.structured_resource.resource.register_space); + shader_dump_register_space(compiler, ins->declaration.structured_resource.resource.range.space); break;
case VKD3DSIH_DCL_SAMPLER: @@ -1597,7 +1597,7 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, shader_dump_uav_flags(compiler, ins->flags); shader_addline(buffer, " "); shader_dump_dst_param(compiler, &ins->declaration.raw_resource.resource.reg); - shader_dump_register_space(compiler, ins->declaration.raw_resource.resource.register_space); + shader_dump_register_space(compiler, ins->declaration.raw_resource.resource.range.space); break;
case VKD3DSIH_DCL_UAV_STRUCTURED: @@ -1605,7 +1605,7 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, shader_addline(buffer, " "); shader_dump_dst_param(compiler, &ins->declaration.structured_resource.resource.reg); shader_print_uint_literal(compiler, ", ", ins->declaration.structured_resource.byte_stride, ""); - shader_dump_register_space(compiler, ins->declaration.structured_resource.resource.register_space); + shader_dump_register_space(compiler, ins->declaration.structured_resource.resource.range.space); break;
case VKD3DSIH_DEF: diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 2308b894..df811d37 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -666,8 +666,8 @@ static void vkd3d_shader_scan_resource_declaration(struct vkd3d_shader_scan_cont type = VKD3D_SHADER_DESCRIPTOR_TYPE_UAV; else type = VKD3D_SHADER_DESCRIPTOR_TYPE_SRV; - vkd3d_shader_scan_add_descriptor(context, type, resource->register_space, - resource->register_index, resource_type, resource_data_type, 0); + vkd3d_shader_scan_add_descriptor(context, type, resource->range.space, + resource->range.first, resource_type, resource_data_type, 0); if (type == VKD3D_SHADER_DESCRIPTOR_TYPE_UAV) vkd3d_shader_scan_add_uav_range(context, resource->reg.reg.idx[0].offset, context->scan_descriptor_info->descriptor_count - 1); diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 6d756e40..e4beef15 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -636,11 +636,16 @@ struct vkd3d_shader_index_range unsigned int register_count; };
+struct vkd3d_descriptor_register_range +{ + unsigned int space; + unsigned int first, last; +}; + struct vkd3d_shader_resource { struct vkd3d_shader_dst_param reg; - unsigned int register_space; - unsigned int register_index; + struct vkd3d_descriptor_register_range range; };
enum vkd3d_decl_usage