microsoft/compiler: Use image formats to determine texture types
authorJesse Natalie <jenatali@microsoft.com>
Fri, 26 May 2023 17:41:27 +0000 (10:41 -0700)
committerMarge Bot <emma+marge@anholt.net>
Tue, 30 May 2023 17:54:18 +0000 (17:54 +0000)
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: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23266>

src/microsoft/compiler/dxil_module.c
src/microsoft/compiler/nir_to_dxil.c

index 0f05b0d..e3814db 100644 (file)
@@ -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]),
index ad671e8..b06438c 100644 (file)
@@ -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);