Module: Mesa
Branch: main
Commit: ebd925e79ce5dc4d4ee940d213806e2fcab1a78b
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=ebd925e79ce5dc4d4ee940d213806e2fcab1a78b

Author: Giancarlo Devich <[email protected]>
Date:   Tue Feb 28 15:44:43 2023 -0800

d3d12: Compare shader keys with a switch, instead of cascading if's

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21610>

---

 src/gallium/drivers/d3d12/d3d12_compiler.cpp | 72 +++++++++++++++-------------
 1 file changed, 39 insertions(+), 33 deletions(-)

diff --git a/src/gallium/drivers/d3d12/d3d12_compiler.cpp 
b/src/gallium/drivers/d3d12/d3d12_compiler.cpp
index eff3ef567a8..fe2a5245d74 100644
--- a/src/gallium/drivers/d3d12/d3d12_compiler.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_compiler.cpp
@@ -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. */
 

Reply via email to