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

Author: Marek Olšák <[email protected]>
Date:   Thu Apr  6 23:34:47 2023 -0400

nir: handle nir_var_mem_ubo in nir_clone_uniform_variable

for UBOs

Reviewed-By: Mike Blumenkrantz <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25394>

---

 src/compiler/nir/nir.h                 |  2 +-
 src/compiler/nir/nir_linking_helpers.c | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 406748ebb09..42776b5607d 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4966,7 +4966,7 @@ void nir_link_xfb_varyings(nir_shader *producer, 
nir_shader *consumer);
 bool nir_link_opt_varyings(nir_shader *producer, nir_shader *consumer);
 void nir_link_varying_precision(nir_shader *producer, nir_shader *consumer);
 nir_variable *nir_clone_uniform_variable(nir_shader *nir,
-                                         nir_variable *uniform);
+                                         nir_variable *uniform, bool spirv);
 nir_deref_instr *nir_clone_deref_instr(struct nir_builder *b,
                                        nir_variable *var,
                                        nir_deref_instr *deref);
diff --git a/src/compiler/nir/nir_linking_helpers.c 
b/src/compiler/nir/nir_linking_helpers.c
index 364623359fc..f3be6b1c6f6 100644
--- a/src/compiler/nir/nir_linking_helpers.c
+++ b/src/compiler/nir/nir_linking_helpers.c
@@ -1173,12 +1173,14 @@ is_direct_uniform_load(nir_def *def, nir_scalar *s)
  * \param uniform The uniform that's declared in another shader.
  */
 nir_variable *
-nir_clone_uniform_variable(nir_shader *nir, nir_variable *uniform)
+nir_clone_uniform_variable(nir_shader *nir, nir_variable *uniform, bool spirv)
 {
    /* Find if uniform already exists in consumer. */
    nir_variable *new_var = NULL;
-   nir_foreach_uniform_variable(v, nir) {
-      if (!strcmp(uniform->name, v->name)) {
+   nir_foreach_variable_with_modes(v, nir, uniform->data.mode) {
+      if ((spirv && uniform->data.mode & nir_var_mem_ubo &&
+           v->data.binding == uniform->data.binding) ||
+          (!spirv && !strcmp(uniform->name, v->name))) {
          new_var = v;
          break;
       }
@@ -1241,7 +1243,7 @@ replace_varying_input_by_uniform_load(nir_shader *shader,
    nir_intrinsic_instr *load = 
nir_instr_as_intrinsic(scalar->def->parent_instr);
    nir_deref_instr *deref = nir_src_as_deref(load->src[0]);
    nir_variable *uni_var = nir_deref_instr_get_variable(deref);
-   uni_var = nir_clone_uniform_variable(shader, uni_var);
+   uni_var = nir_clone_uniform_variable(shader, uni_var, false);
 
    bool progress = false;
    nir_foreach_block(block, impl) {

Reply via email to