[PATCH vkd3d 5/5] vkd3d-shader: Create descriptor array symbols for resources.
Conor McCarthy
cmccarthy at codeweavers.com
Fri Jul 9 00:46:53 CDT 2021
Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
---
include/vkd3d_shader.h | 6 ++--
libs/vkd3d-shader/spirv.c | 64 +++++++++++++++++++++++++++++++++------
2 files changed, 58 insertions(+), 12 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h
index 77758a2b..4593fcec 100644
--- a/include/vkd3d_shader.h
+++ b/include/vkd3d_shader.h
@@ -208,8 +208,10 @@ struct vkd3d_shader_descriptor_binding
/** The binding index of the descriptor. */
unsigned int binding;
/**
- * The size of this descriptor array. Descriptor arrays are not supported in
- * this version of vkd3d-shader, and therefore this value must be 1.
+ * The size of this descriptor array. Descriptor arrays are supported in
+ * this version of vkd3d-shader for all descriptor types except UAV
+ * counters and combined resource/sampler descriptors. For such bindings
+ * this value must be 1. Dynamic array indexing is not supported.
*/
unsigned int count;
};
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c
index 31c9eb1e..ade9916f 100644
--- a/libs/vkd3d-shader/spirv.c
+++ b/libs/vkd3d-shader/spirv.c
@@ -5703,8 +5703,13 @@ 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;
+ struct vkd3d_symbol_descriptor_array_data array_data;
+ struct vkd3d_shader_descriptor_binding binding;
enum vkd3d_shader_component_type sampled_type;
+ const struct vkd3d_symbol *array_symbol;
struct vkd3d_symbol resource_symbol;
+ uint32_t contained_type_id = 0;
+ unsigned int binding_base_idx;
bool is_uav;
is_uav = reg->type == VKD3DSPR_UAV;
@@ -5724,6 +5729,9 @@ static void vkd3d_dxbc_compiler_emit_resource_declaration(struct vkd3d_dxbc_comp
return;
}
+ binding = vkd3d_dxbc_compiler_get_descriptor_binding(compiler, reg, &resource->range,
+ resource_type, false, &binding_base_idx);
+
if (compiler->ssbo_uavs && is_uav && resource_type == VKD3D_SHADER_RESOURCE_BUFFER)
{
uint32_t array_type_id, struct_id;
@@ -5744,16 +5752,22 @@ static void vkd3d_dxbc_compiler_emit_resource_declaration(struct vkd3d_dxbc_comp
{
type_id = vkd3d_dxbc_compiler_get_image_type_id(compiler, reg, &resource->range,
resource_type_info, sampled_type, structure_stride || raw, 0);
+
+ if (binding.count != 1 || resource->range.last == ~0u)
+ {
+ contained_type_id = type_id;
+ type_id = vkd3d_spirv_get_op_type_array(builder, type_id,
+ vkd3d_dxbc_compiler_get_constant_uint(compiler, binding.count));
+ }
}
ptr_type_id = vkd3d_spirv_get_op_type_pointer(builder, storage_class, type_id);
- var_id = vkd3d_spirv_build_op_variable(builder, &builder->global_stream,
- ptr_type_id, storage_class, 0);
- vkd3d_dxbc_compiler_emit_descriptor_binding_for_reg(compiler, var_id, reg,
- &resource->range, resource_type, false);
-
- vkd3d_dxbc_compiler_emit_register_debug_name(builder, var_id, reg);
+ array_data.contained_type_id = contained_type_id;
+ array_data.binding_base_idx = binding_base_idx;
+ array_data.storage_class = storage_class;
+ var_id = vkd3d_dxbc_compiler_get_resource_variable(compiler, &array_data, ptr_type_id, reg, &binding,
+ &array_symbol);
if (is_uav)
{
@@ -5791,6 +5805,11 @@ static void vkd3d_dxbc_compiler_emit_resource_declaration(struct vkd3d_dxbc_comp
storage_class = SpvStorageClassUniform;
ptr_type_id = vkd3d_spirv_get_op_type_pointer(builder, storage_class, struct_id);
}
+ else if (contained_type_id)
+ {
+ /* TODO: UAV counter arrays. */
+ ptr_type_id = vkd3d_spirv_get_op_type_pointer(builder, storage_class, contained_type_id);
+ }
counter_var_id = vkd3d_spirv_build_op_variable(builder, &builder->global_stream,
ptr_type_id, storage_class, 0);
@@ -5804,6 +5823,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.descriptor_array = array_symbol;
resource_symbol.info.resource.range = resource->range;
resource_symbol.info.resource.sampled_type = sampled_type;
resource_symbol.info.resource.type_id = type_id;
@@ -7798,9 +7818,26 @@ static void vkd3d_dxbc_compiler_prepare_image(struct vkd3d_dxbc_compiler *compil
if (!symbol)
symbol = vkd3d_dxbc_compiler_find_resource(compiler, resource_reg);
- image->id = symbol->id;
+ if (symbol->descriptor_array)
+ {
+ const struct vkd3d_symbol_descriptor_array_data *array_data = &symbol->descriptor_array->info.descriptor_array;
+ uint32_t ptr_type_id, index_id;
+
+ index_id = vkd3d_dxbc_compiler_get_resource_index(compiler, resource_reg,
+ array_data->binding_base_idx, symbol->info.resource.resource_type_info->resource_type);
+
+ ptr_type_id = vkd3d_spirv_get_op_type_pointer(builder, array_data->storage_class,
+ array_data->contained_type_id);
+ image->image_type_id = array_data->contained_type_id;
+
+ image->id = vkd3d_spirv_build_op_access_chain(builder, ptr_type_id, symbol->id, &index_id, 1);
+ }
+ else
+ {
+ image->id = symbol->id;
+ image->image_type_id = symbol->info.resource.type_id;
+ }
image->sampled_type = symbol->info.resource.sampled_type;
- image->image_type_id = symbol->info.resource.type_id;
image->resource_type_info = symbol->info.resource.resource_type_info;
image->structure_stride = symbol->info.resource.structure_stride;
image->raw = symbol->info.resource.raw;
@@ -7815,8 +7852,15 @@ static void vkd3d_dxbc_compiler_prepare_image(struct vkd3d_dxbc_compiler *compil
return;
}
- image->image_id = load ? vkd3d_spirv_build_op_load(builder,
- image->image_type_id, image->id, SpvMemoryAccessMaskNone) : 0;
+ if (load)
+ {
+ image->image_id = vkd3d_spirv_build_op_load(builder,
+ image->image_type_id, image->id, SpvMemoryAccessMaskNone);
+ }
+ else
+ {
+ image->image_id = 0;
+ }
image->image_type_id = vkd3d_dxbc_compiler_get_image_type_id(compiler, resource_reg,
&symbol->info.resource.range, image->resource_type_info,
--
2.31.1
More information about the wine-devel
mailing list