zink: improve generated gs unbinding
authorantonino <antonino.maniscalco@collabora.com>
Wed, 8 Mar 2023 16:30:10 +0000 (17:30 +0100)
committerMarge Bot <emma+marge@anholt.net>
Wed, 29 Mar 2023 19:18:40 +0000 (19:18 +0000)
Avoid looping by using the new `parent` field to check if a generaetd gs
is bound and use `bind_gs_state` insted of `bind_gfx_stage` so that
`bind_last_vertex_stage` is automatically called

Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21238>

src/gallium/drivers/zink/zink_compiler.c
src/gallium/drivers/zink/zink_program.c

index e15967f..4bc175a 100644 (file)
@@ -4746,11 +4746,11 @@ zink_shader_free(struct zink_screen *screen, struct zink_shader *shader)
       /* only remove generated tcs during parent tes destruction */
       if (stage == MESA_SHADER_TESS_EVAL && shader->non_fs.generated_tcs)
          prog->shaders[MESA_SHADER_TESS_CTRL] = NULL;
-      for (unsigned int i = 0; i < ARRAY_SIZE(shader->non_fs.generated_gs); i++) {
-         for (int j = 0; j < ARRAY_SIZE(shader->non_fs.generated_gs[0]); j++) {
-            if (stage != MESA_SHADER_FRAGMENT && shader->non_fs.generated_gs[i][j])
-               prog->shaders[MESA_SHADER_GEOMETRY] = NULL;
-         }
+      if (stage != MESA_SHADER_FRAGMENT &&
+          prog->shaders[MESA_SHADER_GEOMETRY] &&
+          prog->shaders[MESA_SHADER_GEOMETRY]->non_fs.parent ==
+          shader) {
+         prog->shaders[MESA_SHADER_GEOMETRY] = NULL;
       }
       zink_gfx_program_reference(screen, &prog, NULL);
    }
index 1b138ae..f6f6f8f 100644 (file)
@@ -1579,17 +1579,12 @@ unbind_generated_gs(struct zink_context *ctx, gl_shader_stage stage, struct zink
    if (ctx->gfx_stages[stage]->non_fs.is_generated)
       ctx->inlinable_uniforms_valid_mask &= ~BITFIELD_BIT(MESA_SHADER_GEOMETRY);
 
-   for (int i = 0; i < ARRAY_SIZE(shader->non_fs.generated_gs); i++) {
-      for (int j = 0; j < ARRAY_SIZE(shader->non_fs.generated_gs[0]); j++) {
-         if (ctx->gfx_stages[stage]->non_fs.generated_gs[i][j] &&
-             ctx->gfx_stages[MESA_SHADER_GEOMETRY] ==
-             ctx->gfx_stages[stage]->non_fs.generated_gs[i][j]) {
-            assert(stage != MESA_SHADER_GEOMETRY); /* let's not keep recursing! */
-            bind_gfx_stage(ctx, MESA_SHADER_GEOMETRY, NULL);
-            ctx->is_generated_gs_bound = false;
-            ctx->inlinable_uniforms_valid_mask &= ~BITFIELD_BIT(MESA_SHADER_GEOMETRY);
-         }
-      }
+   if (ctx->gfx_stages[MESA_SHADER_GEOMETRY] &&
+       ctx->gfx_stages[MESA_SHADER_GEOMETRY]->non_fs.parent ==
+       ctx->gfx_stages[stage]) {
+      ctx->base.bind_gs_state(&ctx->base, NULL);
+      ctx->is_generated_gs_bound = false;
+      ctx->inlinable_uniforms_valid_mask &= ~BITFIELD_BIT(MESA_SHADER_GEOMETRY);
    }
 }
 
@@ -2335,8 +2330,8 @@ zink_set_primitive_emulation_keys(struct zink_context *ctx)
             shader->sinfo.so_info = ctx->gfx_stages[prev_vertex_stage]->sinfo.so_info;
          }
 
-         bind_gfx_stage(ctx, MESA_SHADER_GEOMETRY,
-                        ctx->gfx_stages[prev_vertex_stage]->non_fs.generated_gs[ctx->gfx_pipeline_state.gfx_prim_mode][zink_prim_type]);
+         ctx->base.bind_gs_state(&ctx->base,
+                                 ctx->gfx_stages[prev_vertex_stage]->non_fs.generated_gs[ctx->gfx_pipeline_state.gfx_prim_mode][zink_prim_type]);
          ctx->is_generated_gs_bound = true;
       }
 
@@ -2345,5 +2340,5 @@ zink_set_primitive_emulation_keys(struct zink_context *ctx)
                                                       ctx->gfx_pipeline_state.dyn_state3.pv_last});
    } else if (ctx->gfx_stages[MESA_SHADER_GEOMETRY] &&
               ctx->gfx_stages[MESA_SHADER_GEOMETRY]->non_fs.is_generated)
-         bind_gfx_stage(ctx, MESA_SHADER_GEOMETRY, NULL);
+         ctx->base.bind_gs_state(&ctx->base, NULL);
 }