iris: Properly move edgeflag_out from output list to global list
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 14 Nov 2019 18:10:27 +0000 (10:10 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 14 Nov 2019 22:50:09 +0000 (14:50 -0800)
When demoting it from an output to a global, we need to actually move
it to the correct list.  While here, we also refactor so it's clear
we aren't mutating the list while iterating.

Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/2106
Fixes: f9fd04aca15 ("nir: Fix non-determinism in lower_global_vars_to_local")
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/gallium/drivers/iris/iris_program.c

index 505ededbb5990058d42d66dbaaaf227cdf992ce3..04f28a7dd8efdda5ca06577aa7640ab2ee1357d3 100644 (file)
@@ -194,17 +194,25 @@ iris_fix_edge_flags(nir_shader *nir)
    if (nir->info.stage != MESA_SHADER_VERTEX)
       return false;
 
-   nir_foreach_variable(var, &nir->outputs) {
-      if (var->data.location == VARYING_SLOT_EDGE) {
-         var->data.mode = nir_var_shader_temp;
-         nir->info.outputs_written &= ~VARYING_BIT_EDGE;
-         nir->info.inputs_read &= ~VERT_BIT_EDGEFLAG;
-         nir_fixup_deref_modes(nir);
-         return true;
+   nir_variable *var = NULL;
+   nir_foreach_variable(v, &nir->outputs) {
+      if (v->data.location == VARYING_SLOT_EDGE) {
+         var = v;
+         break;
       }
    }
 
-   return false;
+   if (!var)
+      return false;
+
+   exec_node_remove(&var->node);
+   var->data.mode = nir_var_shader_temp;
+   exec_list_push_tail(&nir->globals, &var->node);
+   nir->info.outputs_written &= ~VARYING_BIT_EDGE;
+   nir->info.inputs_read &= ~VERT_BIT_EDGEFLAG;
+   nir_fixup_deref_modes(nir);
+
+   return true;
 }
 
 /**