d3d12: Compare shader keys with a switch, instead of cascading if's
authorGiancarlo Devich <gdevich@microsoft.com>
Tue, 28 Feb 2023 23:44:43 +0000 (15:44 -0800)
committerMarge Bot <emma+marge@anholt.net>
Wed, 1 Mar 2023 19:40:06 +0000 (19:40 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21610>

src/gallium/drivers/d3d12/d3d12_compiler.cpp

index eff3ef5..fe2a524 100644 (file)
@@ -765,7 +765,18 @@ d3d12_compare_shader_keys(struct d3d12_selection_context* sel_ctx, const d3d12_s
    if (expect->hash != have->hash)
       return false;
 
-   if (expect->stage == PIPE_SHADER_GEOMETRY) {
+   switch (expect->stage) {
+   case PIPE_SHADER_VERTEX:
+      if (expect->vs.needs_format_emulation != have->vs.needs_format_emulation)
+         return false;
+
+      if (expect->vs.needs_format_emulation) {
+         if (memcmp(expect->vs.format_conversion, have->vs.format_conversion,
+            sel_ctx->ctx->gfx_pipeline_state.ves->num_elements * sizeof(enum pipe_format)))
+            return false;
+      }
+      break;
+   case PIPE_SHADER_GEOMETRY:
       if (expect->gs.writes_psize) {
          if (!have->gs.writes_psize ||
              expect->gs.point_pos_stream_out != have->gs.point_pos_stream_out ||
@@ -773,27 +784,14 @@ d3d12_compare_shader_keys(struct d3d12_selection_context* sel_ctx, const d3d12_s
              expect->gs.sprite_origin_upper_left != have->gs.sprite_origin_upper_left ||
              expect->gs.point_size_per_vertex != have->gs.point_size_per_vertex)
             return false;
-      } else if (have->gs.writes_psize) {
+      } else if (have->gs.writes_psize)
          return false;
-      }
+      
       if (expect->gs.primitive_id != have->gs.primitive_id ||
           expect->gs.triangle_strip != have->gs.triangle_strip)
          return false;
-   } else if (expect->stage == PIPE_SHADER_FRAGMENT) {
-      if (expect->fs.frag_result_color_lowering != have->fs.frag_result_color_lowering ||
-          expect->fs.manual_depth_range != have->fs.manual_depth_range ||
-          expect->fs.polygon_stipple != have->fs.polygon_stipple ||
-          expect->fs.cast_to_uint != have->fs.cast_to_uint ||
-          expect->fs.cast_to_int != have->fs.cast_to_int ||
-          expect->fs.remap_front_facing != have->fs.remap_front_facing ||
-          expect->fs.missing_dual_src_outputs != have->fs.missing_dual_src_outputs ||
-          expect->fs.multisample_disabled != have->fs.multisample_disabled)
-         return false;
-   } else if (expect->stage == PIPE_SHADER_COMPUTE) {
-      if (memcmp(expect->cs.workgroup_size, have->cs.workgroup_size,
-                 sizeof(have->cs.workgroup_size)))
-         return false;
-   } else if (expect->stage == PIPE_SHADER_TESS_CTRL) {
+      break;
+   case PIPE_SHADER_TESS_CTRL:
       if (expect->hs.primitive_mode != have->hs.primitive_mode ||
           expect->hs.ccw != have->hs.ccw ||
           expect->hs.point_mode != have->hs.point_mode ||
@@ -802,11 +800,33 @@ d3d12_compare_shader_keys(struct d3d12_selection_context* sel_ctx, const d3d12_s
           !d3d12_compare_varying_info(expect->hs.required_patch_outputs, have->hs.required_patch_outputs) ||
           expect->hs.next_patch_inputs != have->hs.next_patch_inputs)
          return false;
-   } else if (expect->stage == PIPE_SHADER_TESS_EVAL) {
+      break;
+   case PIPE_SHADER_TESS_EVAL:
       if (expect->ds.tcs_vertices_out != have->ds.tcs_vertices_out ||
           !d3d12_compare_varying_info(expect->ds.required_patch_inputs, have->ds.required_patch_inputs) ||
           expect->ds.prev_patch_outputs != have ->ds.prev_patch_outputs)
          return false;
+      break;
+   case PIPE_SHADER_FRAGMENT:
+      if (expect->fs.frag_result_color_lowering != have->fs.frag_result_color_lowering ||
+          expect->fs.manual_depth_range != have->fs.manual_depth_range ||
+          expect->fs.polygon_stipple != have->fs.polygon_stipple ||
+          expect->fs.cast_to_uint != have->fs.cast_to_uint ||
+          expect->fs.cast_to_int != have->fs.cast_to_int ||
+          expect->fs.remap_front_facing != have->fs.remap_front_facing ||
+          expect->fs.missing_dual_src_outputs != have->fs.missing_dual_src_outputs ||
+          expect->fs.multisample_disabled != have->fs.multisample_disabled)
+         return false;
+      if (expect->fs.provoking_vertex != have->fs.provoking_vertex)
+         return false;
+      break;
+   case PIPE_SHADER_COMPUTE:
+      if (memcmp(expect->cs.workgroup_size, have->cs.workgroup_size,
+                 sizeof(have->cs.workgroup_size)))
+         return false;
+      break;
+   default:
+      unreachable("invalid stage");
    }
 
    if (expect->input_clip_size != have->input_clip_size)
@@ -846,20 +866,6 @@ d3d12_compare_shader_keys(struct d3d12_selection_context* sel_ctx, const d3d12_s
        expect->halfz != have->halfz)
       return false;
 
-   if (expect->stage == PIPE_SHADER_VERTEX) {
-      if (expect->vs.needs_format_emulation != have->vs.needs_format_emulation)
-         return false;
-
-      if (expect->vs.needs_format_emulation) {
-         if (memcmp(expect->vs.format_conversion, have->vs.format_conversion,
-                    sel_ctx->ctx->gfx_pipeline_state.ves->num_elements * sizeof (enum pipe_format)))
-            return false;
-      }
-   }
-
-   if (expect->stage == PIPE_SHADER_FRAGMENT && expect->fs.provoking_vertex != have->fs.provoking_vertex)
-      return false;
-
    /* Because we only add varyings we check that a shader has at least the expected in-
     * and outputs. */