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);