nir: convert unused mesh outputs to shared memory
authorMarcin Ślusarz <marcin.slusarz@intel.com>
Wed, 13 Jul 2022 11:55:32 +0000 (13:55 +0200)
committerMarge Bot <emma+marge@anholt.net>
Wed, 20 Jul 2022 09:22:06 +0000 (09:22 +0000)
Otherwise reads from output in one subgroup may not see
writes from other subgroups. Temp variables are later converted
to scratch, so even within one subgroup we may not see correct values.

Test case in https://gitlab.freedesktop.org/mesa/crucible/-/merge_requests/115

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17517>

src/compiler/nir/nir_linking_helpers.c

index 613b424..8304e82 100644 (file)
@@ -161,8 +161,12 @@ nir_remove_unused_io_vars(nir_shader *shader,
 
       if (!(other_stage & get_variable_io_mask(var, shader->info.stage))) {
          /* This one is invalid, make it a global variable instead */
+         if (shader->info.stage == MESA_SHADER_MESH &&
+               (shader->info.outputs_read & BITFIELD64_BIT(var->data.location)))
+            var->data.mode = nir_var_mem_shared;
+         else
+            var->data.mode = nir_var_shader_temp;
          var->data.location = 0;
-         var->data.mode = nir_var_shader_temp;
 
          progress = true;
       }