From 0c8c77b1b01ce6401c2f1b7ad69177beb3805da5 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Fri, 26 May 2023 10:37:04 -0700 Subject: [PATCH] microsoft/compiler: Enable emitting type info for textures with <4 comps Part-of: --- src/microsoft/compiler/dxil_module.c | 17 ++++++++++++----- src/microsoft/compiler/dxil_module.h | 3 ++- src/microsoft/compiler/nir_to_dxil.c | 17 +++++++++-------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/microsoft/compiler/dxil_module.c b/src/microsoft/compiler/dxil_module.c index 2fba8b0ee0e..0f05b0d5efe 100644 --- a/src/microsoft/compiler/dxil_module.c +++ b/src/microsoft/compiler/dxil_module.c @@ -799,12 +799,13 @@ get_res_ms_postfix(enum dxil_resource_kind kind) return ", 0"; default: - return " "; + return ""; } } const struct dxil_type * dxil_module_get_res_type(struct dxil_module *m, enum dxil_resource_kind kind, - enum dxil_component_type comp_type, bool readwrite) + enum dxil_component_type comp_type, unsigned num_comps, + bool readwrite) { switch (kind) { case DXIL_RESOURCE_KIND_TYPED_BUFFER: @@ -819,12 +820,18 @@ dxil_module_get_res_type(struct dxil_module *m, enum dxil_resource_kind kind, case DXIL_RESOURCE_KIND_TEXTURECUBE_ARRAY: { const struct dxil_type *component_type = dxil_module_get_type_from_comp_type(m, comp_type); - const struct dxil_type *vec_type = dxil_module_get_vector_type(m, component_type, 4); + const struct dxil_type *vec_type = num_comps == 1 ? component_type : + dxil_module_get_vector_type(m, component_type, num_comps); + char vector_name[64] = { 0 }; + if (num_comps == 1) + snprintf(vector_name, 64, "%s", get_res_comp_type_name(comp_type)); + else + snprintf(vector_name, 64, "vector<%s, %d>", get_res_comp_type_name(comp_type), num_comps); char class_name[64] = { 0 }; - snprintf(class_name, 64, "class.%s%s%s>", + snprintf(class_name, 64, "class.%s%s<%s%s>", readwrite ? "RW" : "", get_res_dimension_type_name(kind), - get_res_comp_type_name(comp_type), + vector_name, get_res_ms_postfix(kind)); return dxil_module_get_struct_type(m, class_name, &vec_type, 1); } diff --git a/src/microsoft/compiler/dxil_module.h b/src/microsoft/compiler/dxil_module.h index f427e6e44c3..f668c9f19a0 100644 --- a/src/microsoft/compiler/dxil_module.h +++ b/src/microsoft/compiler/dxil_module.h @@ -324,7 +324,8 @@ dxil_module_get_split_double_ret_type(struct dxil_module *mod); const struct dxil_type * dxil_module_get_res_type(struct dxil_module *m, enum dxil_resource_kind kind, - enum dxil_component_type comp_type, bool readwrite); + enum dxil_component_type comp_type, unsigned num_comps, + bool readwrite); const struct dxil_type * dxil_module_get_resret_type(struct dxil_module *m, enum overload_type overload); diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c index 320479db388..ad671e8eeb0 100644 --- a/src/microsoft/compiler/nir_to_dxil.c +++ b/src/microsoft/compiler/nir_to_dxil.c @@ -1292,7 +1292,7 @@ emit_srv(struct ntd_context *ctx, nir_variable *var, unsigned count) res_kind = dxil_get_resource_kind(var->type); res_type = DXIL_RES_SRV_TYPED; } - const struct dxil_type *res_type_as_type = dxil_module_get_res_type(&ctx->mod, res_kind, comp_type, false /* readwrite */); + const struct dxil_type *res_type_as_type = dxil_module_get_res_type(&ctx->mod, res_kind, comp_type, 4, false /* readwrite */); if (glsl_type_is_array(var->type)) res_type_as_type = dxil_module_get_array_type(&ctx->mod, res_type_as_type, count); @@ -1321,7 +1321,7 @@ emit_globals(struct ntd_context *ctx, unsigned size) return true; const struct dxil_type *struct_type = dxil_module_get_res_type(&ctx->mod, - DXIL_RESOURCE_KIND_RAW_BUFFER, DXIL_COMP_TYPE_INVALID, true /* readwrite */); + DXIL_RESOURCE_KIND_RAW_BUFFER, DXIL_COMP_TYPE_INVALID, 1, true /* readwrite */); if (!struct_type) return false; @@ -1351,12 +1351,13 @@ emit_globals(struct ntd_context *ctx, unsigned size) static bool emit_uav(struct ntd_context *ctx, unsigned binding, unsigned space, unsigned count, - enum dxil_component_type comp_type, enum dxil_resource_kind res_kind, const char *name) + enum dxil_component_type comp_type, unsigned num_comps, enum dxil_resource_kind res_kind, + const char *name) { unsigned id = util_dynarray_num_elements(&ctx->uav_metadata_nodes, const struct dxil_mdnode *); resource_array_layout layout = { id, binding, count, space }; - const struct dxil_type *res_type = dxil_module_get_res_type(&ctx->mod, res_kind, comp_type, true /* readwrite */); + const struct dxil_type *res_type = dxil_module_get_res_type(&ctx->mod, res_kind, comp_type, num_comps, true /* readwrite */); res_type = dxil_module_get_array_type(&ctx->mod, res_type, count); const struct dxil_mdnode *uav_meta = emit_uav_metadata(&ctx->mod, res_type, name, &layout, comp_type, res_kind); @@ -1399,7 +1400,7 @@ emit_uav_var(struct ntd_context *ctx, nir_variable *var, unsigned count) enum dxil_resource_kind res_kind = dxil_get_resource_kind(var->type); const char *name = var->name; - return emit_uav(ctx, binding, space, count, comp_type, res_kind, name); + return emit_uav(ctx, binding, space, count, comp_type, 4, res_kind, name); } static void @@ -6250,7 +6251,7 @@ emit_module(struct ntd_context *ctx, const struct nir_to_dxil_options *opts) if (glsl_type_is_array(var->type)) count = glsl_get_length(var->type); if (!emit_uav(ctx, var->data.binding, var->data.descriptor_set, - count, DXIL_COMP_TYPE_INVALID, + count, DXIL_COMP_TYPE_INVALID, 1, DXIL_RESOURCE_KIND_RAW_BUFFER, var->name)) return false; @@ -6260,7 +6261,7 @@ emit_module(struct ntd_context *ctx, const struct nir_to_dxil_options *opts) for (unsigned i = 0; i < ctx->shader->info.num_ssbos; ++i) { char name[64]; snprintf(name, sizeof(name), "__ssbo%d", i); - if (!emit_uav(ctx, i, 0, 1, DXIL_COMP_TYPE_INVALID, + if (!emit_uav(ctx, i, 0, 1, DXIL_COMP_TYPE_INVALID, 1, DXIL_RESOURCE_KIND_RAW_BUFFER, name)) return false; } @@ -6270,7 +6271,7 @@ emit_module(struct ntd_context *ctx, const struct nir_to_dxil_options *opts) * space 2 will be a single array. */ if (ctx->shader->info.num_ssbos && - !emit_uav(ctx, 0, 2, ctx->shader->info.num_ssbos, DXIL_COMP_TYPE_INVALID, + !emit_uav(ctx, 0, 2, ctx->shader->info.num_ssbos, DXIL_COMP_TYPE_INVALID, 1, DXIL_RESOURCE_KIND_RAW_BUFFER, "__ssbo_dynamic")) return false; }