compiler/nir: make lowering global-id to local-id optional
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Mon, 13 Jan 2020 09:35:40 +0000 (10:35 +0100)
committerMarge Bot <eric+marge@anholt.net>
Fri, 21 Aug 2020 22:07:05 +0000 (22:07 +0000)
For D3D12, we don't want to lower this, as there's a dedicated global-id
system-value that might be faster to use, depending on the hardware.

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5891>

src/compiler/nir/nir.h
src/compiler/nir/nir_lower_system_values.c

index 25176a95e57cad242621cf6fcab513b7ce92051e..bb43ab18a9de157e7c18597ba6e69a2413124931 100644 (file)
@@ -3124,6 +3124,9 @@ typedef struct nir_shader_compiler_options {
    bool lower_cs_local_index_from_id;
    bool lower_cs_local_id_from_index;
 
+   /* Prevents lowering global_invocation_id to be in terms of work_group_id */
+   bool has_cs_global_id;
+
    bool lower_device_index_to_zero;
 
    /* Set if nir_lower_wpos_ytransform() should also invert gl_PointCoord. */
index 92723a5bffbb096097135a1e4c079955e91e43dc..bc6a39317674083ee91540ec8f967373a73bb528 100644 (file)
@@ -188,13 +188,17 @@ lower_system_value_instr(nir_builder *b, nir_instr *instr, void *_state)
       }
 
    case nir_intrinsic_load_global_invocation_id: {
-      nir_ssa_def *group_size = nir_load_local_group_size(b);
-      nir_ssa_def *group_id = nir_load_work_group_id(b, bit_size);
-      nir_ssa_def *local_id = nir_load_local_invocation_id(b);
+      if (!b->shader->options->has_cs_global_id) {
+         nir_ssa_def *group_size = nir_load_local_group_size(b);
+         nir_ssa_def *group_id = nir_load_work_group_id(b, bit_size);
+         nir_ssa_def *local_id = nir_load_local_invocation_id(b);
 
-      return nir_iadd(b, nir_imul(b, group_id,
-                                     nir_u2u(b, group_size, bit_size)),
-                         nir_u2u(b, local_id, bit_size));
+         return nir_iadd(b, nir_imul(b, group_id,
+                                        nir_u2u(b, group_size, bit_size)),
+                            nir_u2u(b, local_id, bit_size));
+      } else {
+         return NULL;
+      }
    }
 
    case nir_intrinsic_load_global_invocation_index: {