d3d12: Reduce gs variant key init cost; unnecessary validate gs calls
authorGiancarlo Devich <gdevich@microsoft.com>
Tue, 14 Mar 2023 18:52:16 +0000 (11:52 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 17 Mar 2023 07:43:08 +0000 (07:43 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21909>

src/gallium/drivers/d3d12/d3d12_compiler.cpp
src/gallium/drivers/d3d12/d3d12_compiler.h

index f6bcd0c..339b4fc 100644 (file)
@@ -714,9 +714,9 @@ validate_geometry_shader_variant(struct d3d12_selection_context *sel_ctx)
    d3d12_shader_selector* vs = ctx->gfx_stages[PIPE_SHADER_VERTEX];
    d3d12_shader_selector* fs = ctx->gfx_stages[PIPE_SHADER_FRAGMENT];
 
-   struct d3d12_gs_variant_key key{0};
-
-   bool variant_needed = false;
+   struct d3d12_gs_variant_key key;
+   key.all = 0;
+   key.flat_varyings = 0;
 
    /* Fill the geometry shader variant key */
    if (sel_ctx->fill_mode_lowered != PIPE_POLYGON_MODE_FILL) {
@@ -729,27 +729,20 @@ validate_geometry_shader_variant(struct d3d12_selection_context *sel_ctx)
       fill_flat_varyings(&key, fs);
       if (key.flat_varyings != 0)
          key.flatshade_first = ctx->gfx_pipeline_state.rast->base.flatshade_first;
-      variant_needed = true;
    } else if (sel_ctx->needs_point_sprite_lowering) {
       key.passthrough = true;
-      variant_needed = true;
    } else if (sel_ctx->needs_vertex_reordering) {
       /* TODO support cases where flat shading (pv != 0) and xfb are enabled */
       key.provoking_vertex = sel_ctx->provoking_vertex;
       key.alternate_tri = sel_ctx->alternate_tri;
-      variant_needed = true;
    }
 
-   if (variant_needed) {
-      if (vs->initial_output_vars == nullptr) {
-         vs->initial_output_vars = fill_varyings(sel_ctx->ctx, vs->initial, nir_var_shader_out,
-                                                 vs->initial->info.outputs_written, false);
-      }
-      key.varyings = vs->initial_output_vars;
+   if (vs->initial_output_vars == nullptr) {
+      vs->initial_output_vars = fill_varyings(sel_ctx->ctx, vs->initial, nir_var_shader_out,
+                                                vs->initial->info.outputs_written, false);
    }
-
-   /* Find/create the proper variant and bind it */
-   gs = variant_needed ? d3d12_get_gs_variant(ctx, &key) : NULL;
+   key.varyings = vs->initial_output_vars;
+   gs = d3d12_get_gs_variant(ctx, &key);
    ctx->gfx_stages[PIPE_SHADER_GEOMETRY] = gs;
 }
 
@@ -1639,7 +1632,15 @@ d3d12_select_shader_variants(struct d3d12_context *ctx, const struct pipe_draw_i
    sel_ctx.frag_result_color_lowering = frag_result_color_lowering(ctx);
    sel_ctx.manual_depth_range = ctx->manual_depth_range;
 
-   validate_geometry_shader_variant(&sel_ctx);
+   d3d12_shader_selector* gs = ctx->gfx_stages[PIPE_SHADER_GEOMETRY];
+   if (gs == nullptr || gs->is_variant) {
+      if (sel_ctx.fill_mode_lowered != PIPE_POLYGON_MODE_FILL || sel_ctx.needs_point_sprite_lowering || sel_ctx.needs_vertex_reordering)
+         validate_geometry_shader_variant(&sel_ctx);
+      else if (gs != nullptr) {
+         ctx->gfx_stages[PIPE_SHADER_GEOMETRY] = NULL;
+      }
+   }
+
    validate_tess_ctrl_shader_variant(&sel_ctx);
 
    for (unsigned i = 0; i < ARRAY_SIZE(order); ++i) {
index aebe7a9..7b51ef7 100644 (file)
@@ -238,15 +238,20 @@ struct d3d12_shader {
 
 struct d3d12_gs_variant_key
 {
-   unsigned passthrough:1;
-   unsigned provoking_vertex:3;
-   unsigned alternate_tri:1;
-   unsigned fill_mode:2;
-   unsigned cull_mode:2;
-   unsigned has_front_face:1;
-   unsigned front_ccw:1;
-   unsigned edge_flag_fix:1;
-   unsigned flatshade_first:1;
+   union {
+      struct {
+         unsigned passthrough:1;
+         unsigned provoking_vertex:3;
+         unsigned alternate_tri:1;
+         unsigned fill_mode:2;
+         unsigned cull_mode:2;
+         unsigned has_front_face:1;
+         unsigned front_ccw:1;
+         unsigned edge_flag_fix:1;
+         unsigned flatshade_first:1;
+      };
+      uint64_t all;
+   };
    uint64_t flat_varyings;
    struct d3d12_varying_info *varyings;
 };