Module: Mesa
Branch: main
Commit: cdf0ed8960eed92e98778a0f1a11aaf839f54507
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=cdf0ed8960eed92e98778a0f1a11aaf839f54507

Author: Timothy Arceri <[email protected]>
Date:   Fri Oct  6 12:53:22 2023 +1100

glsl: use the nir based lower_named_interface_blocks()

Because we are now doing the lowering in NIR we need to move the code
that sets the compact flag on some builtin vars out of the glsl to nir
pass.

Acked-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26001>

---

 src/compiler/glsl/gl_nir_linker.c                  | 21 +++++++++++++
 .../glsl/gl_nir_lower_named_interface_blocks.c     | 36 +++++++++++++++++++++-
 src/compiler/glsl/glsl_to_nir.cpp                  | 36 ----------------------
 src/compiler/glsl/linker.cpp                       |  5 ---
 4 files changed, 56 insertions(+), 42 deletions(-)

diff --git a/src/compiler/glsl/gl_nir_linker.c 
b/src/compiler/glsl/gl_nir_linker.c
index 33e3258d433..fa342a53f7b 100644
--- a/src/compiler/glsl/gl_nir_linker.c
+++ b/src/compiler/glsl/gl_nir_linker.c
@@ -1344,6 +1344,8 @@ gl_nir_link_glsl(const struct gl_constants *consts,
       last = i;
    }
 
+   gl_nir_lower_named_interface_blocks(prog);
+
    /* Validate the inputs of each stage with the output of the preceding
     * stage.
     */
@@ -1454,9 +1456,28 @@ gl_nir_link_glsl(const struct gl_constants *consts,
                                    nir_var_mem_ubo | nir_var_mem_ssbo |
                                    nir_var_system_value,
                                    &opts);
+
+         if (shader->Program->info.stage == MESA_SHADER_FRAGMENT) {
+            nir_shader *nir = shader->Program->nir;
+            nir_foreach_variable_in_shader(var, nir) {
+               if (var->data.mode == nir_var_system_value &&
+                   (var->data.location == SYSTEM_VALUE_SAMPLE_ID ||
+                    var->data.location == SYSTEM_VALUE_SAMPLE_POS))
+                  nir->info.fs.uses_sample_shading = true;
+
+               if (var->data.mode == nir_var_shader_in && var->data.sample)
+                  nir->info.fs.uses_sample_shading = true;
+
+               if (var->data.mode == nir_var_shader_out &&
+                   var->data.fb_fetch_output)
+                  nir->info.fs.uses_sample_shading = true;
+            }
+         }
       }
    }
 
+
+
    if (!gl_nir_link_uniforms(consts, prog, true))
       return false;
 
diff --git a/src/compiler/glsl/gl_nir_lower_named_interface_blocks.c 
b/src/compiler/glsl/gl_nir_lower_named_interface_blocks.c
index 18bac021a16..6249b4c1186 100644
--- a/src/compiler/glsl/gl_nir_lower_named_interface_blocks.c
+++ b/src/compiler/glsl/gl_nir_lower_named_interface_blocks.c
@@ -309,10 +309,44 @@ lower_named_interface_blocks(struct gl_linked_shader *sh)
                               nir_metadata_dominance, &state);
 
    /* Third pass: Mark now lowered blks as ordinary globals to be dead code
-    * eliminated.
+    * eliminated. Also use this oppotunity to set the compact flag where
+    * needed now that the default interface block has been lowered away.
     */
    nir_foreach_variable_with_modes(var, sh->Program->nir,
                                    nir_var_shader_in | nir_var_shader_out) {
+
+      if (var->data.mode == nir_var_shader_in) {
+         if (sh->Program->nir->info.stage == MESA_SHADER_TESS_EVAL &&
+             (var->data.location == VARYING_SLOT_TESS_LEVEL_INNER ||
+              var->data.location == VARYING_SLOT_TESS_LEVEL_OUTER)) {
+            var->data.compact =
+               glsl_type_is_scalar(glsl_without_array(var->type));
+         }
+
+         if (sh->Program->nir->info.stage > MESA_SHADER_VERTEX &&
+             var->data.location >= VARYING_SLOT_CLIP_DIST0 &&
+             var->data.location <= VARYING_SLOT_CULL_DIST1) {
+            var->data.compact =
+               glsl_type_is_scalar(glsl_without_array(var->type));
+         }
+      } else {
+         assert(var->data.mode == nir_var_shader_out);
+
+         if (sh->Program->nir->info.stage == MESA_SHADER_TESS_CTRL &&
+             (var->data.location == VARYING_SLOT_TESS_LEVEL_INNER ||
+              var->data.location == VARYING_SLOT_TESS_LEVEL_OUTER)) {
+            var->data.compact =
+               glsl_type_is_scalar(glsl_without_array(var->type));
+         }
+
+         if (sh->Program->nir->info.stage <= MESA_SHADER_GEOMETRY &&
+             var->data.location >= VARYING_SLOT_CLIP_DIST0 &&
+             var->data.location <= VARYING_SLOT_CULL_DIST1) {
+            var->data.compact =
+               glsl_type_is_scalar(glsl_without_array(var->type));
+         }
+      }
+
       const struct glsl_type * iface_t = glsl_without_array(var->type);
       if (!(iface_t == var->interface_type))
          continue;
diff --git a/src/compiler/glsl/glsl_to_nir.cpp 
b/src/compiler/glsl/glsl_to_nir.cpp
index f509a9e1942..961fe6bb658 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -303,19 +303,6 @@ glsl_to_nir(const struct gl_constants *consts,
       shader->info.fs.pixel_center_integer = 
sh->Program->info.fs.pixel_center_integer;
       shader->info.fs.origin_upper_left = 
sh->Program->info.fs.origin_upper_left;
       shader->info.fs.advanced_blend_modes = 
sh->Program->info.fs.advanced_blend_modes;
-
-      nir_foreach_variable_in_shader(var, shader) {
-         if (var->data.mode == nir_var_system_value &&
-             (var->data.location == SYSTEM_VALUE_SAMPLE_ID ||
-              var->data.location == SYSTEM_VALUE_SAMPLE_POS))
-            shader->info.fs.uses_sample_shading = true;
-
-         if (var->data.mode == nir_var_shader_in && var->data.sample)
-            shader->info.fs.uses_sample_shading = true;
-
-         if (var->data.mode == nir_var_shader_out && var->data.fb_fetch_output)
-            shader->info.fs.uses_sample_shading = true;
-      }
    }
 
    return shader;
@@ -585,34 +572,11 @@ nir_visitor::visit(ir_variable *ir)
          var->data.mode = nir_var_system_value;
       } else {
          var->data.mode = nir_var_shader_in;
-
-         if (shader->info.stage == MESA_SHADER_TESS_EVAL &&
-             (ir->data.location == VARYING_SLOT_TESS_LEVEL_INNER ||
-              ir->data.location == VARYING_SLOT_TESS_LEVEL_OUTER)) {
-            var->data.compact = ir->type->without_array()->is_scalar();
-         }
-
-         if (shader->info.stage > MESA_SHADER_VERTEX &&
-             ir->data.location >= VARYING_SLOT_CLIP_DIST0 &&
-             ir->data.location <= VARYING_SLOT_CULL_DIST1) {
-            var->data.compact = ir->type->without_array()->is_scalar();
-         }
       }
       break;
 
    case ir_var_shader_out:
       var->data.mode = nir_var_shader_out;
-      if (shader->info.stage == MESA_SHADER_TESS_CTRL &&
-          (ir->data.location == VARYING_SLOT_TESS_LEVEL_INNER ||
-           ir->data.location == VARYING_SLOT_TESS_LEVEL_OUTER)) {
-         var->data.compact = ir->type->without_array()->is_scalar();
-      }
-
-      if (shader->info.stage <= MESA_SHADER_GEOMETRY &&
-          ir->data.location >= VARYING_SLOT_CLIP_DIST0 &&
-          ir->data.location <= VARYING_SLOT_CULL_DIST1) {
-         var->data.compact = ir->type->without_array()->is_scalar();
-      }
       break;
 
    case ir_var_uniform:
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 262a53ea181..a0a7336613c 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -3116,11 +3116,6 @@ link_shaders(struct gl_context *ctx, struct 
gl_shader_program *prog)
    if (!prog->data->LinkStatus)
       goto done;
 
-   for (unsigned int i = 0; i < MESA_SHADER_STAGES; i++) {
-      if (prog->_LinkedShaders[i] != NULL)
-         lower_named_interface_blocks(mem_ctx, prog->_LinkedShaders[i]);
-   }
-
    if (prog->IsES && prog->GLSL_Version == 100)
       if (!validate_invariant_builtins(prog,
             prog->_LinkedShaders[MESA_SHADER_VERTEX],

Reply via email to