From: Zebediah Figura zfigura@codeweavers.com
These functions do not really share any code in common. --- libs/vkd3d-shader/spirv.c | 43 ++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index fa605f18..a6c4833b 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -2599,8 +2599,8 @@ static struct vkd3d_push_constant_buffer_binding *spirv_compiler_find_push_const return NULL; }
-static bool spirv_compiler_has_combined_sampler(const struct spirv_compiler *compiler, - const struct vkd3d_shader_resource *resource, const struct vkd3d_shader_sampler *sampler) +static bool spirv_compiler_has_combined_sampler_for_resource(const struct spirv_compiler *compiler, + const struct vkd3d_shader_resource *resource) { const struct vkd3d_shader_interface_info *shader_interface = &compiler->shader_interface; const struct vkd3d_shader_combined_resource_sampler *combined_sampler; @@ -2609,10 +2609,35 @@ static bool spirv_compiler_has_combined_sampler(const struct spirv_compiler *com if (!shader_interface->combined_sampler_count) return false;
- if (resource && (resource->reg.reg.type == VKD3DSPR_UAV || resource->range.last != resource->range.first)) + if (resource->reg.reg.type == VKD3DSPR_UAV || resource->range.last != resource->range.first) return false;
- if (sampler && sampler->range.first != sampler->range.last) + for (i = 0; i < shader_interface->combined_sampler_count; ++i) + { + combined_sampler = &shader_interface->combined_samplers[i]; + + if (!spirv_compiler_check_shader_visibility(compiler, combined_sampler->shader_visibility)) + continue; + + if ((combined_sampler->resource_space == resource->range.space + && combined_sampler->resource_index == resource->range.first)) + return true; + } + + return false; +} + +static bool spirv_compiler_has_combined_sampler_for_sampler(const struct spirv_compiler *compiler, + const struct vkd3d_shader_sampler *sampler) +{ + const struct vkd3d_shader_interface_info *shader_interface = &compiler->shader_interface; + const struct vkd3d_shader_combined_resource_sampler *combined_sampler; + unsigned int i; + + if (!shader_interface->combined_sampler_count) + return false; + + if (sampler->range.last != sampler->range.first) return false;
for (i = 0; i < shader_interface->combined_sampler_count; ++i) @@ -2622,10 +2647,8 @@ static bool spirv_compiler_has_combined_sampler(const struct spirv_compiler *com if (!spirv_compiler_check_shader_visibility(compiler, combined_sampler->shader_visibility)) continue;
- if ((!resource || (combined_sampler->resource_space == resource->range.space - && combined_sampler->resource_index == resource->range.first)) - && (!sampler || (combined_sampler->sampler_space == sampler->range.space - && combined_sampler->sampler_index == sampler->range.first))) + if (combined_sampler->sampler_space == sampler->range.space + && combined_sampler->sampler_index == sampler->range.first) return true; }
@@ -5643,7 +5666,7 @@ static void spirv_compiler_emit_dcl_sampler(struct spirv_compiler *compiler, reg_symbol.info.sampler.range = sampler->range; spirv_compiler_put_symbol(compiler, ®_symbol);
- if (spirv_compiler_has_combined_sampler(compiler, NULL, sampler)) + if (spirv_compiler_has_combined_sampler_for_sampler(compiler, sampler)) return;
type_id = vkd3d_spirv_get_op_type_sampler(builder); @@ -5855,7 +5878,7 @@ static void spirv_compiler_emit_resource_declaration(struct spirv_compiler *comp
sampled_type = vkd3d_component_type_from_data_type(resource_data_type);
- if (spirv_compiler_has_combined_sampler(compiler, resource, NULL)) + if (spirv_compiler_has_combined_sampler_for_resource(compiler, resource)) { spirv_compiler_emit_combined_sampler_declarations(compiler, reg, &resource->range, resource_type, sampled_type, structure_stride, raw, resource_type_info);
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/spirv.c | 72 ++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 17 deletions(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index a6c4833b..ea6357a4 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -2628,7 +2628,7 @@ static bool spirv_compiler_has_combined_sampler_for_resource(const struct spirv_ }
static bool spirv_compiler_has_combined_sampler_for_sampler(const struct spirv_compiler *compiler, - const struct vkd3d_shader_sampler *sampler) + const struct vkd3d_shader_register_range *range) { const struct vkd3d_shader_interface_info *shader_interface = &compiler->shader_interface; const struct vkd3d_shader_combined_resource_sampler *combined_sampler; @@ -2637,7 +2637,7 @@ static bool spirv_compiler_has_combined_sampler_for_sampler(const struct spirv_c if (!shader_interface->combined_sampler_count) return false;
- if (sampler->range.last != sampler->range.first) + if (range->last != range->first) return false;
for (i = 0; i < shader_interface->combined_sampler_count; ++i) @@ -2647,8 +2647,8 @@ static bool spirv_compiler_has_combined_sampler_for_sampler(const struct spirv_c if (!spirv_compiler_check_shader_visibility(compiler, combined_sampler->shader_visibility)) continue;
- if (combined_sampler->sampler_space == sampler->range.space - && combined_sampler->sampler_index == sampler->range.first) + if (combined_sampler->sampler_space == range->space + && combined_sampler->sampler_index == range->first) return true; }
@@ -5651,29 +5651,34 @@ static void spirv_compiler_emit_dcl_immediate_constant_buffer(struct spirv_compi spirv_compiler_put_symbol(compiler, ®_symbol); }
-static void spirv_compiler_emit_dcl_sampler(struct spirv_compiler *compiler, - const struct vkd3d_shader_instruction *instruction) +static void spirv_compiler_emit_sampler_declaration(struct spirv_compiler *compiler, + const struct vkd3d_shader_register_range *range, unsigned int register_id) { - const struct vkd3d_shader_sampler *sampler = &instruction->declaration.sampler; const SpvStorageClass storage_class = SpvStorageClassUniformConstant; struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; - const struct vkd3d_shader_register *reg = &sampler->src.reg; struct vkd3d_descriptor_variable_info var_info; struct vkd3d_symbol reg_symbol; uint32_t type_id, var_id;
- vkd3d_symbol_make_sampler(®_symbol, reg); - reg_symbol.info.sampler.range = sampler->range; + const struct vkd3d_shader_register reg = + { + .type = VKD3DSPR_SAMPLER, + .idx[0].offset = register_id, + .idx_count = 1, + }; + + vkd3d_symbol_make_sampler(®_symbol, ®); + reg_symbol.info.sampler.range = *range; spirv_compiler_put_symbol(compiler, ®_symbol);
- if (spirv_compiler_has_combined_sampler_for_sampler(compiler, sampler)) + if (spirv_compiler_has_combined_sampler_for_sampler(compiler, range)) return;
type_id = vkd3d_spirv_get_op_type_sampler(builder); - var_id = spirv_compiler_build_descriptor_variable(compiler, storage_class, type_id, reg, - &sampler->range, VKD3D_SHADER_RESOURCE_NONE, false, &var_info); + var_id = spirv_compiler_build_descriptor_variable(compiler, storage_class, type_id, ®, + range, VKD3D_SHADER_RESOURCE_NONE, false, &var_info);
- vkd3d_symbol_make_register(®_symbol, reg); + vkd3d_symbol_make_register(®_symbol, ®); vkd3d_symbol_set_register_info(®_symbol, var_id, storage_class, VKD3D_SHADER_COMPONENT_FLOAT, VKD3DSP_WRITEMASK_ALL); reg_symbol.descriptor_array = var_info.array_symbol; @@ -9203,9 +9208,6 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler, case VKD3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER: spirv_compiler_emit_dcl_immediate_constant_buffer(compiler, instruction); break; - case VKD3DSIH_DCL_SAMPLER: - spirv_compiler_emit_dcl_sampler(compiler, instruction); - break; case VKD3DSIH_DCL: case VKD3DSIH_DCL_UAV_TYPED: spirv_compiler_emit_dcl_resource(compiler, instruction); @@ -9514,6 +9516,7 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler, spirv_compiler_emit_cut_stream(compiler, instruction); break; case VKD3DSIH_DCL_HS_MAX_TESSFACTOR: + case VKD3DSIH_DCL_SAMPLER: case VKD3DSIH_DCL_TEMPS: case VKD3DSIH_HS_DECLS: case VKD3DSIH_NOP: @@ -9526,6 +9529,39 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler, return ret; }
+static void spirv_compiler_emit_descriptor_declarations(struct spirv_compiler *compiler) +{ + unsigned int i; + + for (i = 0; i < compiler->scan_descriptor_info->descriptor_count; ++i) + { + const struct vkd3d_shader_descriptor_info1 *descriptor = &compiler->scan_descriptor_info->descriptors[i]; + struct vkd3d_shader_register_range range; + + range.first = descriptor->register_index; + if (descriptor->count == ~0u) + range.last = ~0u; + else + range.last = descriptor->register_index + descriptor->count - 1; + range.space = descriptor->register_space; + + switch (descriptor->type) + { + case VKD3D_SHADER_DESCRIPTOR_TYPE_SAMPLER: + spirv_compiler_emit_sampler_declaration(compiler, &range, descriptor->register_id); + break; + + case VKD3D_SHADER_DESCRIPTOR_TYPE_CBV: + case VKD3D_SHADER_DESCRIPTOR_TYPE_SRV: + case VKD3D_SHADER_DESCRIPTOR_TYPE_UAV: + break; + + default: + vkd3d_unreachable(); + } + } +} + static void spirv_compiler_emit_sm1_constant_buffer(struct spirv_compiler *compiler, const struct vkd3d_shader_desc *desc, enum vkd3d_shader_d3dbc_constant_register set, enum vkd3d_data_type data_type) @@ -9561,6 +9597,8 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler, if (parser->shader_desc.temp_count) spirv_compiler_emit_temps(compiler, parser->shader_desc.temp_count);
+ spirv_compiler_emit_descriptor_declarations(compiler); + spirv_compiler_emit_sm1_constant_buffer(compiler, &parser->shader_desc, VKD3D_SHADER_D3DBC_FLOAT_CONSTANT_REGISTER, VKD3D_DATA_FLOAT); spirv_compiler_emit_sm1_constant_buffer(compiler, &parser->shader_desc,
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/spirv.c | 61 ++++++++++----------------------------- 1 file changed, 16 insertions(+), 45 deletions(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index ea6357a4..8a446ae2 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -5561,8 +5561,8 @@ static uint32_t spirv_compiler_build_descriptor_variable(struct spirv_compiler * return var_id; }
-static void spirv_compiler_emit_constant_buffer(struct spirv_compiler *compiler, unsigned int size, - const struct vkd3d_shader_register_range *range, const struct vkd3d_shader_register *reg) +static void spirv_compiler_emit_cbv_declaration(struct spirv_compiler *compiler, + const struct vkd3d_shader_register_range *range, unsigned int register_id, unsigned int size) { struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; uint32_t vec4_id, array_type_id, length_id, struct_id, var_id; @@ -5571,13 +5571,20 @@ static void spirv_compiler_emit_constant_buffer(struct spirv_compiler *compiler, struct vkd3d_descriptor_variable_info var_info; struct vkd3d_symbol reg_symbol;
+ struct vkd3d_shader_register reg = + { + .type = VKD3DSPR_CONSTBUFFER, + .idx[0].offset = register_id, + .idx_count = 1, + }; + if ((push_cb = spirv_compiler_find_push_constant_buffer(compiler, range))) { /* Push constant buffers are handled in * spirv_compiler_emit_push_constant_buffers(). */ unsigned int cb_size_in_bytes = size * VKD3D_VEC4_SIZE * sizeof(uint32_t); - push_cb->reg = *reg; + push_cb->reg = reg; push_cb->size = size; if (cb_size_in_bytes > push_cb->pc.size) { @@ -5598,9 +5605,9 @@ static void spirv_compiler_emit_constant_buffer(struct spirv_compiler *compiler, vkd3d_spirv_build_op_name(builder, struct_id, "cb%u_struct", size);
var_id = spirv_compiler_build_descriptor_variable(compiler, storage_class, struct_id, - reg, range, VKD3D_SHADER_RESOURCE_BUFFER, false, &var_info); + ®, range, VKD3D_SHADER_RESOURCE_BUFFER, false, &var_info);
- vkd3d_symbol_make_register(®_symbol, reg); + vkd3d_symbol_make_register(®_symbol, ®); vkd3d_symbol_set_register_info(®_symbol, var_id, storage_class, VKD3D_SHADER_COMPONENT_FLOAT, VKD3DSP_WRITEMASK_ALL); reg_symbol.descriptor_array = var_info.array_symbol; @@ -5608,16 +5615,6 @@ static void spirv_compiler_emit_constant_buffer(struct spirv_compiler *compiler, spirv_compiler_put_symbol(compiler, ®_symbol); }
-static void spirv_compiler_emit_dcl_constant_buffer(struct spirv_compiler *compiler, - const struct vkd3d_shader_instruction *instruction) -{ - const struct vkd3d_shader_constant_buffer *cb = &instruction->declaration.cb; - - assert(!(instruction->flags & ~VKD3DSI_INDEXED_DYNAMIC)); - - spirv_compiler_emit_constant_buffer(compiler, cb->size, &cb->range, &cb->src.reg); -} - static void spirv_compiler_emit_dcl_immediate_constant_buffer(struct spirv_compiler *compiler, const struct vkd3d_shader_instruction *instruction) { @@ -9202,9 +9199,6 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler, case VKD3DSIH_DCL_INDEXABLE_TEMP: spirv_compiler_emit_dcl_indexable_temp(compiler, instruction); break; - case VKD3DSIH_DCL_CONSTANT_BUFFER: - spirv_compiler_emit_dcl_constant_buffer(compiler, instruction); - break; case VKD3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER: spirv_compiler_emit_dcl_immediate_constant_buffer(compiler, instruction); break; @@ -9515,6 +9509,7 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler, case VKD3DSIH_CUT_STREAM: spirv_compiler_emit_cut_stream(compiler, instruction); break; + case VKD3DSIH_DCL_CONSTANT_BUFFER: case VKD3DSIH_DCL_HS_MAX_TESSFACTOR: case VKD3DSIH_DCL_SAMPLER: case VKD3DSIH_DCL_TEMPS: @@ -9552,6 +9547,9 @@ static void spirv_compiler_emit_descriptor_declarations(struct spirv_compiler *c break;
case VKD3D_SHADER_DESCRIPTOR_TYPE_CBV: + spirv_compiler_emit_cbv_declaration(compiler, &range, descriptor->register_id, descriptor->buffer_size); + break; + case VKD3D_SHADER_DESCRIPTOR_TYPE_SRV: case VKD3D_SHADER_DESCRIPTOR_TYPE_UAV: break; @@ -9562,26 +9560,6 @@ static void spirv_compiler_emit_descriptor_declarations(struct spirv_compiler *c } }
-static void spirv_compiler_emit_sm1_constant_buffer(struct spirv_compiler *compiler, - const struct vkd3d_shader_desc *desc, enum vkd3d_shader_d3dbc_constant_register set, - enum vkd3d_data_type data_type) -{ - struct vkd3d_shader_register_range range = {.space = 0, .first = set, .last = set}; - uint32_t count = desc->flat_constant_count[set].external; - struct vkd3d_shader_register reg = - { - .type = VKD3DSPR_CONSTBUFFER, - .idx[0].offset = set, /* register ID */ - .idx[1].offset = set, /* register index */ - .idx[2].offset = count, /* size */ - .idx_count = 3, - .data_type = data_type, - }; - - if (count) - spirv_compiler_emit_constant_buffer(compiler, count, &range, ®); -} - static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler, const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_parser *parser, struct vkd3d_shader_code *spirv) @@ -9599,13 +9577,6 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler,
spirv_compiler_emit_descriptor_declarations(compiler);
- spirv_compiler_emit_sm1_constant_buffer(compiler, &parser->shader_desc, - VKD3D_SHADER_D3DBC_FLOAT_CONSTANT_REGISTER, VKD3D_DATA_FLOAT); - spirv_compiler_emit_sm1_constant_buffer(compiler, &parser->shader_desc, - VKD3D_SHADER_D3DBC_INT_CONSTANT_REGISTER, VKD3D_DATA_INT); - spirv_compiler_emit_sm1_constant_buffer(compiler, &parser->shader_desc, - VKD3D_SHADER_D3DBC_BOOL_CONSTANT_REGISTER, VKD3D_DATA_UINT); - compiler->location.column = 0; compiler->location.line = 1;
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/spirv.c | 129 ++++++++--------------- libs/vkd3d-shader/vkd3d_shader_private.h | 24 +++++ 2 files changed, 68 insertions(+), 85 deletions(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 8a446ae2..53156f79 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -2600,7 +2600,7 @@ static struct vkd3d_push_constant_buffer_binding *spirv_compiler_find_push_const }
static bool spirv_compiler_has_combined_sampler_for_resource(const struct spirv_compiler *compiler, - const struct vkd3d_shader_resource *resource) + const struct vkd3d_shader_register_range *range) { const struct vkd3d_shader_interface_info *shader_interface = &compiler->shader_interface; const struct vkd3d_shader_combined_resource_sampler *combined_sampler; @@ -2609,7 +2609,7 @@ static bool spirv_compiler_has_combined_sampler_for_resource(const struct spirv_ if (!shader_interface->combined_sampler_count) return false;
- if (resource->reg.reg.type == VKD3DSPR_UAV || resource->range.last != resource->range.first) + if (range->last != range->first) return false;
for (i = 0; i < shader_interface->combined_sampler_count; ++i) @@ -2619,8 +2619,8 @@ static bool spirv_compiler_has_combined_sampler_for_resource(const struct spirv_ if (!spirv_compiler_check_shader_visibility(compiler, combined_sampler->shader_visibility)) continue;
- if ((combined_sampler->resource_space == resource->range.space - && combined_sampler->resource_index == resource->range.first)) + if ((combined_sampler->resource_space == range->space + && combined_sampler->resource_index == range->first)) return true; }
@@ -5857,20 +5857,30 @@ static void spirv_compiler_emit_combined_sampler_declarations(struct spirv_compi }
static void spirv_compiler_emit_resource_declaration(struct spirv_compiler *compiler, - const struct vkd3d_shader_resource *resource, enum vkd3d_shader_resource_type resource_type, - enum vkd3d_data_type resource_data_type, unsigned int structure_stride, bool raw) + const struct vkd3d_shader_register_range *range, unsigned int register_id, + unsigned int sample_count, bool is_uav, enum vkd3d_shader_resource_type resource_type, + enum vkd3d_shader_resource_data_type resource_data_type, unsigned int structure_stride, bool raw) { struct vkd3d_descriptor_variable_info var_info, counter_var_info = {0}; struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; SpvStorageClass storage_class = SpvStorageClassUniformConstant; uint32_t counter_type_id, type_id, var_id, counter_var_id = 0; - const struct vkd3d_shader_register *reg = &resource->reg.reg; const struct vkd3d_spirv_resource_type *resource_type_info; enum vkd3d_shader_component_type sampled_type; struct vkd3d_symbol resource_symbol; - bool is_uav;
- is_uav = reg->type == VKD3DSPR_UAV; + struct vkd3d_shader_register reg = + { + .type = is_uav ? VKD3DSPR_UAV : VKD3DSPR_RESOURCE, + .idx[0].offset = register_id, + .idx_count = 1, + }; + + if (resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_2DMS && sample_count == 1) + resource_type = VKD3D_SHADER_RESOURCE_TEXTURE_2D; + else if (resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY && sample_count == 1) + resource_type = VKD3D_SHADER_RESOURCE_TEXTURE_2DARRAY; + if (!(resource_type_info = spirv_compiler_enable_resource_type(compiler, resource_type, is_uav))) { @@ -5878,11 +5888,11 @@ static void spirv_compiler_emit_resource_declaration(struct spirv_compiler *comp return; }
- sampled_type = vkd3d_component_type_from_data_type(resource_data_type); + sampled_type = vkd3d_component_type_from_resource_data_type(resource_data_type);
- if (spirv_compiler_has_combined_sampler_for_resource(compiler, resource)) + if (!is_uav && spirv_compiler_has_combined_sampler_for_resource(compiler, range)) { - spirv_compiler_emit_combined_sampler_declarations(compiler, reg, &resource->range, + spirv_compiler_emit_combined_sampler_declarations(compiler, ®, range, resource_type, sampled_type, structure_stride, raw, resource_type_info); return; } @@ -5905,19 +5915,18 @@ static void spirv_compiler_emit_resource_declaration(struct spirv_compiler *comp } else { - type_id = spirv_compiler_get_image_type_id(compiler, reg, &resource->range, + type_id = spirv_compiler_get_image_type_id(compiler, ®, range, resource_type_info, sampled_type, structure_stride || raw, 0); }
- var_id = spirv_compiler_build_descriptor_variable(compiler, storage_class, type_id, reg, - &resource->range, resource_type, false, &var_info); + var_id = spirv_compiler_build_descriptor_variable(compiler, storage_class, type_id, ®, + range, resource_type, false, &var_info);
if (is_uav) { const struct vkd3d_shader_descriptor_info1 *d;
- d = spirv_compiler_get_descriptor_info(compiler, - VKD3D_SHADER_DESCRIPTOR_TYPE_UAV, &resource->range); + d = spirv_compiler_get_descriptor_info(compiler, VKD3D_SHADER_DESCRIPTOR_TYPE_UAV, range);
if (!(d->flags & VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_READ)) vkd3d_spirv_build_op_decorate(builder, var_id, SpvDecorationNonReadable, NULL, 0); @@ -5949,15 +5958,15 @@ static void spirv_compiler_emit_resource_declaration(struct spirv_compiler *comp type_id = struct_id; }
- counter_var_id = spirv_compiler_build_descriptor_variable(compiler, storage_class, type_id, reg, - &resource->range, resource_type, true, &counter_var_info); + counter_var_id = spirv_compiler_build_descriptor_variable(compiler, storage_class, + type_id, ®, range, resource_type, true, &counter_var_info); } }
- vkd3d_symbol_make_resource(&resource_symbol, reg); + vkd3d_symbol_make_resource(&resource_symbol, ®); resource_symbol.id = var_id; resource_symbol.descriptor_array = var_info.array_symbol; - resource_symbol.info.resource.range = resource->range; + resource_symbol.info.resource.range = *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; @@ -5970,58 +5979,6 @@ static void spirv_compiler_emit_resource_declaration(struct spirv_compiler *comp spirv_compiler_put_symbol(compiler, &resource_symbol); }
-static void spirv_compiler_emit_dcl_resource(struct spirv_compiler *compiler, - const struct vkd3d_shader_instruction *instruction) -{ - const struct vkd3d_shader_semantic *semantic = &instruction->declaration.semantic; - enum vkd3d_shader_resource_type resource_type = semantic->resource_type; - uint32_t flags = instruction->flags; - - /* We don't distinguish between APPEND and COUNTER UAVs. */ - flags &= ~VKD3DSUF_ORDER_PRESERVING_COUNTER; - if (flags) - FIXME("Unhandled UAV flags %#x.\n", flags); - - if (resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_2DMS && semantic->sample_count == 1) - resource_type = VKD3D_SHADER_RESOURCE_TEXTURE_2D; - else if (resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY && semantic->sample_count == 1) - resource_type = VKD3D_SHADER_RESOURCE_TEXTURE_2DARRAY; - - spirv_compiler_emit_resource_declaration(compiler, &semantic->resource, - resource_type, semantic->resource_data_type[0], 0, false); -} - -static void spirv_compiler_emit_dcl_resource_raw(struct spirv_compiler *compiler, - const struct vkd3d_shader_instruction *instruction) -{ - const struct vkd3d_shader_raw_resource *resource = &instruction->declaration.raw_resource; - uint32_t flags = instruction->flags; - - /* We don't distinguish between APPEND and COUNTER UAVs. */ - flags &= ~VKD3DSUF_ORDER_PRESERVING_COUNTER; - if (flags) - FIXME("Unhandled UAV flags %#x.\n", flags); - - spirv_compiler_emit_resource_declaration(compiler, &resource->resource, - VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_DATA_UINT, 0, true); -} - -static void spirv_compiler_emit_dcl_resource_structured(struct spirv_compiler *compiler, - const struct vkd3d_shader_instruction *instruction) -{ - const struct vkd3d_shader_structured_resource *resource = &instruction->declaration.structured_resource; - unsigned int stride = resource->byte_stride; - uint32_t flags = instruction->flags; - - /* We don't distinguish between APPEND and COUNTER UAVs. */ - flags &= ~VKD3DSUF_ORDER_PRESERVING_COUNTER; - if (flags) - FIXME("Unhandled UAV flags %#x.\n", flags); - - spirv_compiler_emit_resource_declaration(compiler, &resource->resource, - VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_DATA_UINT, stride / 4, false); -} - static void spirv_compiler_emit_workgroup_memory(struct spirv_compiler *compiler, const struct vkd3d_shader_register *reg, unsigned int size, unsigned int structure_stride) { @@ -9202,18 +9159,6 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler, case VKD3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER: spirv_compiler_emit_dcl_immediate_constant_buffer(compiler, instruction); break; - case VKD3DSIH_DCL: - case VKD3DSIH_DCL_UAV_TYPED: - spirv_compiler_emit_dcl_resource(compiler, instruction); - break; - case VKD3DSIH_DCL_RESOURCE_RAW: - case VKD3DSIH_DCL_UAV_RAW: - spirv_compiler_emit_dcl_resource_raw(compiler, instruction); - break; - case VKD3DSIH_DCL_RESOURCE_STRUCTURED: - case VKD3DSIH_DCL_UAV_STRUCTURED: - spirv_compiler_emit_dcl_resource_structured(compiler, instruction); - break; case VKD3DSIH_DCL_TGSM_RAW: spirv_compiler_emit_dcl_tgsm_raw(compiler, instruction); break; @@ -9509,10 +9454,16 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler, case VKD3DSIH_CUT_STREAM: spirv_compiler_emit_cut_stream(compiler, instruction); break; + case VKD3DSIH_DCL: case VKD3DSIH_DCL_CONSTANT_BUFFER: case VKD3DSIH_DCL_HS_MAX_TESSFACTOR: + case VKD3DSIH_DCL_RESOURCE_RAW: + case VKD3DSIH_DCL_RESOURCE_STRUCTURED: case VKD3DSIH_DCL_SAMPLER: case VKD3DSIH_DCL_TEMPS: + case VKD3DSIH_DCL_UAV_RAW: + case VKD3DSIH_DCL_UAV_STRUCTURED: + case VKD3DSIH_DCL_UAV_TYPED: case VKD3DSIH_HS_DECLS: case VKD3DSIH_NOP: /* nothing to do */ @@ -9551,7 +9502,15 @@ static void spirv_compiler_emit_descriptor_declarations(struct spirv_compiler *c break;
case VKD3D_SHADER_DESCRIPTOR_TYPE_SRV: + spirv_compiler_emit_resource_declaration(compiler, &range, descriptor->register_id, + descriptor->sample_count, false, descriptor->resource_type, descriptor->resource_data_type, + descriptor->structure_stride / 4, descriptor->flags & VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_RAW_BUFFER); + break; + case VKD3D_SHADER_DESCRIPTOR_TYPE_UAV: + spirv_compiler_emit_resource_declaration(compiler, &range, descriptor->register_id, + descriptor->sample_count, true, descriptor->resource_type, descriptor->resource_data_type, + descriptor->structure_stride / 4, descriptor->flags & VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_RAW_BUFFER); break;
default: diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index bf925a44..8d9ae9a0 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -1310,6 +1310,30 @@ static inline enum vkd3d_data_type vkd3d_data_type_from_component_type( } }
+static inline enum vkd3d_shader_component_type vkd3d_component_type_from_resource_data_type( + enum vkd3d_shader_resource_data_type data_type) +{ + switch (data_type) + { + case VKD3D_SHADER_RESOURCE_DATA_FLOAT: + case VKD3D_SHADER_RESOURCE_DATA_UNORM: + case VKD3D_SHADER_RESOURCE_DATA_SNORM: + return VKD3D_SHADER_COMPONENT_FLOAT; + case VKD3D_SHADER_RESOURCE_DATA_UINT: + return VKD3D_SHADER_COMPONENT_UINT; + case VKD3D_SHADER_RESOURCE_DATA_INT: + return VKD3D_SHADER_COMPONENT_INT; + case VKD3D_SHADER_RESOURCE_DATA_DOUBLE: + case VKD3D_SHADER_RESOURCE_DATA_CONTINUED: + return VKD3D_SHADER_COMPONENT_DOUBLE; + default: + FIXME("Unhandled data type %#x.\n", data_type); + /* fall-through */ + case VKD3D_SHADER_RESOURCE_DATA_MIXED: + return VKD3D_SHADER_COMPONENT_UINT; + } +} + enum vkd3d_shader_input_sysval_semantic vkd3d_siv_from_sysval_indexed(enum vkd3d_shader_sysval_semantic sysval, unsigned int index);
+ const struct vkd3d_shader_register reg = + { + .type = VKD3DSPR_SAMPLER, + .idx[0].offset = register_id, + .idx_count = 1, + };
This is hardly the only place that does something like this, but could we please start using shader_register_init() or helpers built on top of that? Mainly to make life slightly easier for people touching struct vkd3d_shader_register in the future, of course.
This merge request was approved by Henri Verbeet.