Mesa (main): zink: clear current gfx/compute program upon unbinding its shaders

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 18 21:10:06 UTC 2021


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Tue Jun  8 16:48:15 2021 -0400

zink: clear current gfx/compute program upon unbinding its shaders

this simplifies a lot of code

Reviewed-by: Hoe Hao Cheng <haochengho12907 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12428>

---

 src/gallium/drivers/zink/zink_batch.c    |  8 ++------
 src/gallium/drivers/zink/zink_compiler.c | 14 ++------------
 src/gallium/drivers/zink/zink_program.c  |  7 +++++--
 3 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c
index 3ff705b48ea..17aecc73eed 100644
--- a/src/gallium/drivers/zink/zink_batch.c
+++ b/src/gallium/drivers/zink/zink_batch.c
@@ -69,14 +69,10 @@ zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs)
       zink_batch_usage_unset(&pg->batch_uses, bs);
       if (pg->is_compute) {
          struct zink_compute_program *comp = (struct zink_compute_program*)pg;
-         bool in_use = comp == ctx->curr_compute;
-         if (zink_compute_program_reference(screen, &comp, NULL) && in_use)
-            ctx->curr_compute = NULL;
+         zink_compute_program_reference(screen, &comp, NULL);
       } else {
          struct zink_gfx_program *prog = (struct zink_gfx_program*)pg;
-         bool in_use = prog == ctx->curr_program;
-         if (zink_gfx_program_reference(screen, &prog, NULL) && in_use)
-            ctx->curr_program = NULL;
+         zink_gfx_program_reference(screen, &prog, NULL);
       }
    }
 
diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c
index 461943803b2..c4ac0081572 100644
--- a/src/gallium/drivers/zink/zink_compiler.c
+++ b/src/gallium/drivers/zink/zink_compiler.c
@@ -1073,28 +1073,18 @@ zink_shader_free(struct zink_context *ctx, struct zink_shader *shader)
          struct zink_compute_program *comp = (void*)entry->key;
          _mesa_hash_table_remove_key(ctx->compute_program_cache, comp->shader);
          comp->shader = NULL;
-         bool in_use = comp == ctx->curr_compute;
-         if (in_use)
-            ctx->compute_stage = NULL;
-         if (zink_compute_program_reference(screen, &comp, NULL) && in_use)
-            ctx->curr_compute = NULL;
+         zink_compute_program_reference(screen, &comp, NULL);
       } else {
          struct zink_gfx_program *prog = (void*)entry->key;
          enum pipe_shader_type pstage = pipe_shader_type_from_mesa(shader->nir->info.stage);
          assert(pstage < ZINK_SHADER_COUNT);
-         bool in_use = prog == ctx->curr_program;
          if (shader->nir->info.stage != MESA_SHADER_TESS_CTRL || !shader->is_generated)
             _mesa_hash_table_remove_key(ctx->program_cache, prog->shaders);
          prog->shaders[pstage] = NULL;
          if (shader->nir->info.stage == MESA_SHADER_TESS_EVAL && shader->generated)
             /* automatically destroy generated tcs shaders when tes is destroyed */
             zink_shader_free(ctx, shader->generated);
-         if (in_use) {
-            ctx->gfx_pipeline_state.modules[pstage] = VK_NULL_HANDLE;
-            ctx->gfx_stages[pstage] = NULL;
-         }
-         if (zink_gfx_program_reference(screen, &prog, NULL) && in_use)
-            ctx->curr_program = NULL;
+         zink_gfx_program_reference(screen, &prog, NULL);
       }
    }
    _mesa_set_destroy(shader->programs, NULL);
diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c
index 592e18f45d4..f0e12314b68 100644
--- a/src/gallium/drivers/zink/zink_program.c
+++ b/src/gallium/drivers/zink/zink_program.c
@@ -885,14 +885,17 @@ bind_stage(struct zink_context *ctx, enum pipe_shader_type stage,
             ctx->curr_compute = entry->data;
          } else
             ctx->dirty_shader_stages |= 1 << stage;
-      }
+      } else if (!shader)
+         ctx->curr_compute = NULL;
       ctx->compute_stage = shader;
       zink_select_launch_grid(ctx);
    } else {
       ctx->gfx_stages[stage] = shader;
       ctx->gfx_pipeline_state.combined_dirty = true;
-      if (!shader)
+      if (!shader) {
          ctx->gfx_pipeline_state.modules[stage] = VK_NULL_HANDLE;
+         ctx->curr_program = NULL;
+      }
       ctx->dirty_shader_stages |= 1 << stage;
    }
    if (shader && shader->nir->info.num_inlinable_uniforms)



More information about the mesa-commit mailing list