r600/sfn: Sort the outputs of the FS according to data index
authorGert Wollny <gert.wollny@collabora.com>
Tue, 22 Sep 2020 07:15:31 +0000 (09:15 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 22 Sep 2020 14:32:45 +0000 (14:32 +0000)
Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6814>

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

index 6150c93..c30e82d 100644 (file)
@@ -416,6 +416,39 @@ void sort_uniforms(nir_shader *shader)
    exec_list_append(&shader->variables, &new_list);
 }
 
+static void
+insert_fsoutput_sorted(struct exec_list *var_list, nir_variable *new_var)
+{
+
+   nir_foreach_variable_in_list(var, var_list) {
+      if (var->data.location > new_var->data.location ||
+          (var->data.location == new_var->data.location &&
+           var->data.index > new_var->data.index)) {
+         exec_node_insert_node_before(&var->node, &new_var->node);
+         return;
+      }
+   }
+
+   exec_list_push_tail(var_list, &new_var->node);
+}
+
+void sort_fsoutput(nir_shader *shader)
+{
+   struct exec_list new_list;
+   exec_list_make_empty(&new_list);
+
+   nir_foreach_shader_out_variable_safe(var, shader) {
+      exec_node_remove(&var->node);
+      insert_fsoutput_sorted(&new_list, var);
+   }
+
+   unsigned driver_location = 0;
+   nir_foreach_variable_in_list(var, &new_list)
+      var->data.driver_location = driver_location++;
+
+   exec_list_append(&shader->variables, &new_list);
+}
+
 }
 
 static nir_intrinsic_op
@@ -801,9 +834,11 @@ int r600_shader_from_nir(struct r600_context *rctx,
    while (optimize_once(sel->nir));
 
    auto sh = nir_shader_clone(sel->nir, sel->nir);
-
    NIR_PASS_V(sh, nir_opt_algebraic_late);
 
+   if (sel->nir->info.stage == MESA_SHADER_FRAGMENT)
+      r600::sort_fsoutput(sh);
+
    NIR_PASS_V(sh, nir_lower_locals_to_regs);
 
    //NIR_PASS_V(sel->nir, nir_opt_algebraic);