From 84691dfc460b651b94bc42f102fadde1cd6952f3 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Fri, 26 May 2023 10:41:27 -0700 Subject: [PATCH] microsoft/compiler: Use image formats to determine texture types Fixes some tests when bindless is disabled, where the image format is R32, we do atomics on it, but we didn't set the "typed UAV load with additional formats" feature bit because when we loaded from it, we only loaded one component. Since the image format on the DXIL side was declared as U32x4, the DXIL validator said that we should have. Part-of: --- src/microsoft/compiler/dxil_module.c | 9 +++++++-- src/microsoft/compiler/nir_to_dxil.c | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/microsoft/compiler/dxil_module.c b/src/microsoft/compiler/dxil_module.c index 0f05b0d5efe..e3814dbaedd 100644 --- a/src/microsoft/compiler/dxil_module.c +++ b/src/microsoft/compiler/dxil_module.c @@ -2122,9 +2122,14 @@ dxil_module_get_uav_res_props_const(struct dxil_module *m, dwords[0] = get_basic_srv_uav_res_props_dword(true, false, false /*TODO*/, false, dxil_sampler_dim_to_resource_kind(nir_intrinsic_image_dim(intr), nir_intrinsic_image_array(intr))); + unsigned num_comps = intr->num_components ? intr->num_components : 1; + if (nir_intrinsic_has_format(intr)) { + enum pipe_format format = nir_intrinsic_format(intr); + if (format != PIPE_FORMAT_NONE) + num_comps = util_format_get_nr_components(format); + } dwords[1] = get_typed_srv_uav_res_props_dword(comp_type_from_alu_type(alu_type_from_image_intr(intr)), - intr->num_components ? intr->num_components : 1, - 0); + num_comps, 0); const struct dxil_value *values[2] = { dxil_module_get_int32_const(m, dwords[0]), diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c index ad671e8eeb0..b06438c31fa 100644 --- a/src/microsoft/compiler/nir_to_dxil.c +++ b/src/microsoft/compiler/nir_to_dxil.c @@ -1400,7 +1400,9 @@ 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, 4, res_kind, name); + return emit_uav(ctx, binding, space, count, comp_type, + util_format_get_nr_components(var->data.image.format), + res_kind, name); } static void @@ -4268,7 +4270,7 @@ emit_image_load(struct ntd_context *ctx, nir_intrinsic_instr *intr) store_dest(ctx, &intr->dest, i, component); } - if (num_components > 1) + if (util_format_get_nr_components(nir_intrinsic_format(intr)) > 1) ctx->mod.feats.typed_uav_load_additional_formats = true; return true; @@ -6727,6 +6729,8 @@ nir_to_dxil(struct nir_shader *s, const struct nir_to_dxil_options *opts, NIR_PASS_V(s, dxil_nir_move_consts); NIR_PASS_V(s, nir_opt_dce); + NIR_PASS_V(s, dxil_nir_guess_image_formats); + if (debug_dxil & DXIL_DEBUG_VERBOSE) nir_print_shader(s, stderr);