r600/sfn: Sort uniforms by binding and offset
authorGert Wollny <gert.wollny@collabora.com>
Tue, 21 Jul 2020 09:43:08 +0000 (11:43 +0200)
committerGert Wollny <gw.fossdev@gmail.com>
Sun, 9 Aug 2020 13:45:33 +0000 (13:45 +0000)
This is required to get atomics right.

v2: rebase to use global variable lists

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6025>

src/gallium/drivers/r600/sfn/sfn_nir.cpp

index d65a1c9..50edec1 100644 (file)
@@ -484,6 +484,32 @@ bool r600_lower_ubo_to_align16(nir_shader *shader)
                                         nullptr);
 }
 
+static void
+insert_uniform_sorted(struct exec_list *var_list, nir_variable *new_var)
+{
+   nir_foreach_variable_in_list(var, var_list) {
+      if (var->data.binding > new_var->data.binding ||
+          (var->data.binding == new_var->data.binding &&
+           var->data.offset > new_var->data.offset)) {
+         exec_node_insert_node_before(&var->node, &new_var->node);
+         return;
+      }
+   }
+   exec_list_push_tail(var_list, &new_var->node);
+}
+
+void sort_uniforms(nir_shader *shader)
+{
+   struct exec_list new_list;
+   exec_list_make_empty(&new_list);
+
+   nir_foreach_uniform_variable_safe(var, shader) {
+      exec_node_remove(&var->node);
+      insert_uniform_sorted(&new_list, var);
+   }
+   exec_list_append(&shader->variables, &new_list);
+}
+
 }
 
 using r600::r600_nir_lower_int_tg4;
@@ -661,6 +687,8 @@ int r600_shader_from_nir(struct r600_context *rctx,
       fprintf(stderr, "END PRE-OPT-NIR--------------------------------------\n\n");
    }
 
+   r600::sort_uniforms(sel->nir);
+
    NIR_PASS_V(sel->nir, nir_lower_vars_to_ssa);
    NIR_PASS_V(sel->nir, nir_lower_regs_to_ssa);
    NIR_PASS_V(sel->nir, nir_lower_phis_to_scalar);