zink: move find_sampler_var from zink to nir core
authorIllia Polishchuk <illia.a.polishchuk@globallogic.com>
Mon, 11 Sep 2023 13:08:31 +0000 (16:08 +0300)
committerMarge Bot <emma+marge@anholt.net>
Tue, 12 Sep 2023 15:44:52 +0000 (15:44 +0000)
Avoid code duplication because it need to be used in following commits

Fixes: 1a8dd84ec61 ("nir: Propagate the type sampler type change to the used variable.")

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Signed-off-by: Illia Polishchuk <illia.a.polishchuk@globallogic.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25145>

src/compiler/nir/nir.c
src/compiler/nir/nir.h
src/gallium/drivers/zink/zink_compiler.c

index 9748f9e..8b8aeaf 100644 (file)
@@ -423,6 +423,22 @@ nir_find_state_variable(nir_shader *s,
    return NULL;
 }
 
+nir_variable *nir_find_sampler_variable_with_tex_index(nir_shader *shader,
+                                                       unsigned texture_index)
+{
+   nir_foreach_variable_with_modes(var, shader, nir_var_uniform) {
+      unsigned size =
+          glsl_type_is_array(var->type) ? glsl_array_size(var->type) : 1;
+      if ((glsl_type_is_texture(glsl_without_array(var->type)) ||
+           glsl_type_is_sampler(glsl_without_array(var->type))) &&
+          (var->data.binding == texture_index ||
+           (var->data.binding < texture_index &&
+            var->data.binding + size > texture_index)))
+         return var;
+   }
+   return NULL;
+}
+
 /* Annoyingly, qsort_r is not in the C standard library and, in particular, we
  * can't count on it on MSV and Android.  So we stuff the CMP function into
  * each array element.  It's a bit messy and burns more memory but the list of
index d9ec891..7d919a8 100644 (file)
@@ -4060,6 +4060,9 @@ nir_variable *nir_find_variable_with_driver_location(nir_shader *shader,
 nir_variable *nir_find_state_variable(nir_shader *s,
                                       gl_state_index16 tokens[STATE_LENGTH]);
 
+nir_variable *nir_find_sampler_variable_with_tex_index(nir_shader *shader,
+                                                       unsigned texture_index);
+
 void nir_sort_variables_with_modes(nir_shader *shader,
                                    int (*compar)(const nir_variable *,
                                                  const nir_variable *),
index 5b220ff..d714dd7 100644 (file)
@@ -4827,18 +4827,6 @@ type_image(nir_shader *nir, nir_variable *var)
    var->data.mode = nir_var_shader_temp;
 }
 
-static nir_variable *
-find_sampler_var(nir_shader *nir, unsigned texture_index)
-{
-   nir_foreach_variable_with_modes(var, nir, nir_var_uniform) {
-      unsigned size = glsl_type_is_array(var->type) ? glsl_array_size(var->type) : 1;
-      if ((glsl_type_is_texture(glsl_without_array(var->type)) || glsl_type_is_sampler(glsl_without_array(var->type))) &&
-          (var->data.binding == texture_index || (var->data.binding < texture_index && var->data.binding + size > texture_index)))
-         return var;
-   }
-   return NULL;
-}
-
 static bool
 type_sampler_vars(nir_shader *nir, unsigned *sampler_mask)
 {
@@ -4860,7 +4848,7 @@ type_sampler_vars(nir_shader *nir, unsigned *sampler_mask)
                break;
             }
             *sampler_mask |= BITFIELD_BIT(tex->sampler_index);
-            nir_variable *var = find_sampler_var(nir, tex->texture_index);
+            nir_variable *var = nir_find_sampler_variable_with_tex_index(nir, tex->texture_index);
             assert(var);
             if (glsl_get_sampler_result_type(glsl_without_array(var->type)) != GLSL_TYPE_VOID)
                continue;
@@ -4890,7 +4878,7 @@ type_sampler_vars(nir_shader *nir, unsigned *sampler_mask)
                continue;
             }
             *sampler_mask |= BITFIELD_BIT(tex->sampler_index);
-            nir_variable *var = find_sampler_var(nir, tex->texture_index);
+            nir_variable *var = nir_find_sampler_variable_with_tex_index(nir, tex->texture_index);
             assert(var);
             if (glsl_get_sampler_result_type(glsl_without_array(var->type)) != GLSL_TYPE_VOID)
                continue;