From ebd925e79ce5dc4d4ee940d213806e2fcab1a78b Mon Sep 17 00:00:00 2001 From: Giancarlo Devich Date: Tue, 28 Feb 2023 15:44:43 -0800 Subject: [PATCH] d3d12: Compare shader keys with a switch, instead of cascading if's Part-of: --- 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,13 +784,30 @@ 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) { + 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 || + expect->hs.spacing != have->hs.spacing || + expect->hs.patch_vertices_in != have->hs.patch_vertices_in || + !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; + 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 || @@ -789,24 +817,16 @@ d3d12_compare_shader_keys(struct d3d12_selection_context* sel_ctx, const d3d12_s 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 (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; - } else if (expect->stage == 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 || - expect->hs.spacing != have->hs.spacing || - expect->hs.patch_vertices_in != have->hs.patch_vertices_in || - !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) { - 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; + 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. */