intel/compiler: Use switch for DERIVATIVE_GROUP logic
authorFelix DeGrood <felix.j.degrood@intel.com>
Wed, 19 May 2021 16:32:16 +0000 (09:32 -0700)
committerMarge Bot <eric+marge@anholt.net>
Sat, 22 May 2021 00:15:25 +0000 (00:15 +0000)
Switch statement is more readable.

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10733>

src/intel/compiler/brw_nir_lower_cs_intrinsics.c

index f9330b6..b642035 100644 (file)
@@ -107,18 +107,29 @@ lower_cs_intrinsics_convert_block(struct lower_intrinsics_state *state,
              * large so it can safely be omitted.
              */
 
-            if (state->nir->info.cs.derivative_group != DERIVATIVE_GROUP_QUADS) {
-               /* If we are not grouping in quads, just set the local invocatio
+            nir_ssa_def *id_x, *id_y, *id_z;
+            switch (state->nir->info.cs.derivative_group) {
+            case DERIVATIVE_GROUP_NONE:
+               /* If not using derivatives, just set the local invocation
                 * index linearly, and calculate local invocation ID from that.
                 */
                local_index = linear;
-
-               nir_ssa_def *id_x, *id_y, *id_z;
                id_x = nir_umod(b, local_index, size_x);
                id_y = nir_umod(b, nir_udiv(b, local_index, size_x), size_y);
                id_z = nir_udiv(b, local_index, nir_imul(b, size_x, size_y));
                local_id = nir_vec3(b, id_x, id_y, id_z);
-            } else {
+               break;
+            case DERIVATIVE_GROUP_LINEAR:
+               /* For linear, just set the local invocation index linearly,
+                * and calculate local invocation ID from that.
+                */
+               local_index = linear;
+               id_x = nir_umod(b, local_index, size_x);
+               id_y = nir_umod(b, nir_udiv(b, local_index, size_x), size_y);
+               id_z = nir_udiv(b, local_index, nir_imul(b, size_x, size_y));
+               local_id = nir_vec3(b, id_x, id_y, id_z);
+               break;
+            case DERIVATIVE_GROUP_QUADS: {
                /* For quads, first we figure out the 2x2 grid the invocation
                 * belongs to -- treating extra Z layers as just more rows.
                 * Then map that into local invocation ID (trivial) and local
@@ -146,6 +157,10 @@ lower_cs_intrinsics_convert_block(struct lower_intrinsics_state *state,
                                    nir_umod(b, y, size_y),
                                    nir_udiv(b, y, size_y));
                local_index = nir_iadd(b, x, nir_imul(b, y, size_x));
+               break;
+            }
+            default:
+               unreachable("invalid derivative group");
             }
          }