nir_to_tgsi: Fix image declarations.
authorEmma Anholt <emma@anholt.net>
Tue, 12 Jan 2021 00:21:20 +0000 (16:21 -0800)
committerMarge Bot <eric+marge@anholt.net>
Fri, 16 Jul 2021 21:35:31 +0000 (21:35 +0000)
We failed to translate the target type, which virgl needs for translation.
Also the read_only flag is for consts, shader inputs, and uniforms.  The
access flag gives you the readonly qualifier.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11916>

src/gallium/auxiliary/nir/nir_to_tgsi.c

index fbeadd9..38d2db7 100644 (file)
@@ -384,6 +384,27 @@ ntt_setup_inputs(struct ntt_compile *c)
    }
 }
 
+static enum tgsi_texture_type
+tgsi_target_from_sampler_dim(enum glsl_sampler_dim dim, bool is_array)
+{
+   switch (dim) {
+   case GLSL_SAMPLER_DIM_1D:
+      return is_array ? TGSI_TEXTURE_1D_ARRAY : TGSI_TEXTURE_1D;
+   case GLSL_SAMPLER_DIM_2D:
+      return is_array ? TGSI_TEXTURE_2D_ARRAY : TGSI_TEXTURE_2D;
+   case GLSL_SAMPLER_DIM_3D:
+      return TGSI_TEXTURE_3D;
+   case GLSL_SAMPLER_DIM_CUBE:
+      return is_array ? TGSI_TEXTURE_CUBE_ARRAY : TGSI_TEXTURE_CUBE;
+   case GLSL_SAMPLER_DIM_RECT:
+      return TGSI_TEXTURE_RECT;
+   case GLSL_SAMPLER_DIM_BUF:
+      return TGSI_TEXTURE_BUFFER;
+   default:
+      unreachable("unknown sampler dim");
+   }
+}
+
 static void
 ntt_setup_uniforms(struct ntt_compile *c)
 {
@@ -392,11 +413,15 @@ ntt_setup_uniforms(struct ntt_compile *c)
 
    nir_foreach_uniform_variable(var, c->s) {
       if (glsl_type_is_image(var->type)) {
+         enum tgsi_texture_type tex_type =
+             tgsi_target_from_sampler_dim(glsl_get_sampler_dim(var->type),
+                                          glsl_sampler_type_is_array(var->type));
+
          c->images[var->data.binding] = ureg_DECL_image(c->ureg,
                                                         var->data.binding,
-                                                        TGSI_TEXTURE_2D,
+                                                        tex_type,
                                                         var->data.image.format,
-                                                        !var->data.read_only,
+                                                        !(var->data.access & ACCESS_NON_WRITEABLE),
                                                         false);
       } else {
          unsigned size;
@@ -1381,27 +1406,6 @@ ntt_emit_mem(struct ntt_compile *c, nir_intrinsic_instr *instr,
                     0 /* format: unused */);
 }
 
-static enum tgsi_texture_type
-tgsi_target_from_sampler_dim(enum glsl_sampler_dim dim, bool is_array)
-{
-   switch (dim) {
-   case GLSL_SAMPLER_DIM_1D:
-      return is_array ? TGSI_TEXTURE_1D_ARRAY : TGSI_TEXTURE_1D;
-   case GLSL_SAMPLER_DIM_2D:
-      return is_array ? TGSI_TEXTURE_2D_ARRAY : TGSI_TEXTURE_2D;
-   case GLSL_SAMPLER_DIM_3D:
-      return TGSI_TEXTURE_3D;
-   case GLSL_SAMPLER_DIM_CUBE:
-      return is_array ? TGSI_TEXTURE_CUBE_ARRAY : TGSI_TEXTURE_CUBE;
-   case GLSL_SAMPLER_DIM_RECT:
-      return TGSI_TEXTURE_RECT;
-   case GLSL_SAMPLER_DIM_BUF:
-      return TGSI_TEXTURE_BUFFER;
-   default:
-      unreachable("unknown sampler dim");
-   }
-}
-
 static void
 ntt_emit_image_load_store(struct ntt_compile *c, nir_intrinsic_instr *instr)
 {