Mesa (main): zink: inline program cache structs

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 25 22:38:31 UTC 2021


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Wed Jun  9 18:42:26 2021 -0400

zink: inline program cache structs

derefs--

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

---

 src/gallium/drivers/zink/zink_compiler.c |  4 ++--
 src/gallium/drivers/zink/zink_context.c  | 14 +++++---------
 src/gallium/drivers/zink/zink_context.h  |  4 ++--
 src/gallium/drivers/zink/zink_draw.cpp   |  6 +++---
 src/gallium/drivers/zink/zink_program.c  |  2 +-
 src/gallium/drivers/zink/zink_program.h  |  2 ++
 6 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c
index c4ac0081572..b2026f31f6e 100644
--- a/src/gallium/drivers/zink/zink_compiler.c
+++ b/src/gallium/drivers/zink/zink_compiler.c
@@ -1071,7 +1071,7 @@ zink_shader_free(struct zink_context *ctx, struct zink_shader *shader)
    set_foreach(shader->programs, entry) {
       if (shader->nir->info.stage == MESA_SHADER_COMPUTE) {
          struct zink_compute_program *comp = (void*)entry->key;
-         _mesa_hash_table_remove_key(ctx->compute_program_cache, comp->shader);
+         _mesa_hash_table_remove_key(&ctx->compute_program_cache, comp->shader);
          comp->shader = NULL;
          zink_compute_program_reference(screen, &comp, NULL);
       } else {
@@ -1079,7 +1079,7 @@ zink_shader_free(struct zink_context *ctx, struct zink_shader *shader)
          enum pipe_shader_type pstage = pipe_shader_type_from_mesa(shader->nir->info.stage);
          assert(pstage < ZINK_SHADER_COUNT);
          if (shader->nir->info.stage != MESA_SHADER_TESS_CTRL || !shader->is_generated)
-            _mesa_hash_table_remove_key(ctx->program_cache, prog->shaders);
+            _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 */
diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index f5808219abe..1b8859a694f 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -125,8 +125,8 @@ zink_context_destroy(struct pipe_context *pctx)
    u_upload_destroy(pctx->stream_uploader);
    u_upload_destroy(pctx->const_uploader);
    slab_destroy_child(&ctx->transfer_pool);
-   _mesa_hash_table_destroy(ctx->program_cache, NULL);
-   _mesa_hash_table_destroy(ctx->compute_program_cache, NULL);
+   _mesa_hash_table_clear(&ctx->program_cache, NULL);
+   _mesa_hash_table_clear(&ctx->compute_program_cache, NULL);
    _mesa_hash_table_destroy(ctx->render_pass_cache, NULL);
    slab_destroy_child(&ctx->transfer_pool_unsync);
 
@@ -3526,16 +3526,12 @@ zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
    if (!ctx->blitter)
       goto fail;
 
-   ctx->program_cache = _mesa_hash_table_create(NULL,
-                                                hash_gfx_program,
-                                                equals_gfx_program);
-   ctx->compute_program_cache = _mesa_hash_table_create(NULL,
-                                                _mesa_hash_pointer,
-                                                _mesa_key_pointer_equal);
+   _mesa_hash_table_init(&ctx->program_cache, ctx, hash_gfx_program, equals_gfx_program);
+   _mesa_hash_table_init(&ctx->compute_program_cache, ctx, _mesa_hash_pointer, _mesa_key_pointer_equal);
    ctx->render_pass_cache = _mesa_hash_table_create(NULL,
                                                     hash_render_pass_state,
                                                     equals_render_pass_state);
-   if (!ctx->program_cache || !ctx->compute_program_cache || !ctx->render_pass_cache)
+   if (!ctx->render_pass_cache)
       goto fail;
 
    const uint8_t data[] = {0};
diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h
index be60c21567e..7667092e4bd 100644
--- a/src/gallium/drivers/zink/zink_context.h
+++ b/src/gallium/drivers/zink/zink_context.h
@@ -203,14 +203,14 @@ struct zink_context {
    bool shader_reads_basevertex;
    struct zink_gfx_pipeline_state gfx_pipeline_state;
    enum pipe_prim_type gfx_prim_mode;
-   struct hash_table *program_cache;
+   struct hash_table program_cache;
    struct zink_gfx_program *curr_program;
 
    struct zink_descriptor_data *dd;
 
    struct zink_shader *compute_stage;
    struct zink_compute_pipeline_state compute_pipeline_state;
-   struct hash_table *compute_program_cache;
+   struct hash_table compute_program_cache;
    struct zink_compute_program *curr_compute;
 
    unsigned dirty_shader_stages : 6; /* mask of changed shader stages */
diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp
index 4a5f52ff112..dca3f39b7a5 100644
--- a/src/gallium/drivers/zink/zink_draw.cpp
+++ b/src/gallium/drivers/zink/zink_draw.cpp
@@ -180,7 +180,7 @@ update_compute_program(struct zink_context *ctx)
    const unsigned bits = 1 << PIPE_SHADER_COMPUTE;
    if (ctx->dirty_shader_stages & bits) {
       struct zink_compute_program *comp = zink_create_compute_program(ctx, ctx->compute_stage);
-      _mesa_hash_table_insert(ctx->compute_program_cache, comp->shader, comp);
+      _mesa_hash_table_insert(&ctx->compute_program_cache, comp->shader, comp);
       ctx->compute_pipeline_state.dirty = true;
       ctx->curr_compute = comp;
       ctx->dirty_shader_stages &= bits;
@@ -203,13 +203,13 @@ update_gfx_program(struct zink_context *ctx)
    unsigned bits = u_bit_consecutive(PIPE_SHADER_VERTEX, 5);
    if (ctx->dirty_shader_stages & bits) {
       struct zink_gfx_program *prog = NULL;
-      struct hash_entry *entry = _mesa_hash_table_search(ctx->program_cache,
+      struct hash_entry *entry = _mesa_hash_table_search(&ctx->program_cache,
                                                          ctx->gfx_stages);
       if (entry)
          zink_update_gfx_program(ctx, (struct zink_gfx_program*)entry->data);
       else {
          prog = zink_create_gfx_program(ctx, ctx->gfx_stages);
-         entry = _mesa_hash_table_insert(ctx->program_cache, prog->shaders, prog);
+         entry = _mesa_hash_table_insert(&ctx->program_cache, prog->shaders, prog);
       }
       prog = (struct zink_gfx_program*)(entry ? entry->data : NULL);
       if (prog && prog != ctx->curr_program) {
diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c
index 12777d21d37..91db9cf0eea 100644
--- a/src/gallium/drivers/zink/zink_program.c
+++ b/src/gallium/drivers/zink/zink_program.c
@@ -879,7 +879,7 @@ bind_stage(struct zink_context *ctx, enum pipe_shader_type stage,
 {
    if (stage == PIPE_SHADER_COMPUTE) {
       if (shader && shader != ctx->compute_stage) {
-         struct hash_entry *entry = _mesa_hash_table_search(ctx->compute_program_cache, shader);
+         struct hash_entry *entry = _mesa_hash_table_search(&ctx->compute_program_cache, shader);
          if (entry) {
             ctx->compute_pipeline_state.dirty = true;
             ctx->curr_compute = entry->data;
diff --git a/src/gallium/drivers/zink/zink_program.h b/src/gallium/drivers/zink/zink_program.h
index eb77c828ec3..fc66f8d767e 100644
--- a/src/gallium/drivers/zink/zink_program.h
+++ b/src/gallium/drivers/zink/zink_program.h
@@ -85,6 +85,8 @@ struct zink_program {
 
    /* the shader cache stores a mapping of zink_shader_key::VkShaderModule */
    struct hash_table shader_cache[ZINK_SHADER_COUNT];
+
+   bool removed;
 };
 
 struct zink_gfx_program {



More information about the mesa-commit mailing list