zink: require optimal_keys for GPL
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Fri, 23 Sep 2022 02:24:25 +0000 (22:24 -0400)
committerMarge Bot <emma+marge@anholt.net>
Sat, 1 Oct 2022 02:18:39 +0000 (02:18 +0000)
this is pointless otherwise

Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18911>

src/gallium/drivers/zink/zink_program.c
src/gallium/drivers/zink/zink_program.h
src/gallium/drivers/zink/zink_program_state.hpp
src/gallium/drivers/zink/zink_screen.c
src/gallium/drivers/zink/zink_types.h

index aeef892..881a6af 100644 (file)
@@ -457,12 +457,6 @@ hash_pipeline_lib(const void *key)
 }
 
 static bool
-equals_pipeline_lib(const void *a, const void *b)
-{
-   return !memcmp(a, b, offsetof(struct zink_gfx_library_key, pipeline));
-}
-
-static bool
 equals_pipeline_lib_optimal(const void *a, const void *b)
 {
    return !memcmp(a, b, sizeof(uint32_t));
@@ -894,7 +888,7 @@ zink_create_gfx_program(struct zink_context *ctx,
       }
    }
 
-   _mesa_set_init(&prog->libs, prog, hash_pipeline_lib, screen->optimal_keys ? equals_pipeline_lib_optimal : equals_pipeline_lib);
+   _mesa_set_init(&prog->libs, prog, hash_pipeline_lib, equals_pipeline_lib_optimal);
 
    struct mesa_sha1 sctx;
    _mesa_sha1_init(&sctx);
@@ -1530,13 +1524,15 @@ zink_create_cached_shader_state(struct pipe_context *pctx, const struct pipe_sha
    return util_live_shader_cache_get(pctx, &screen->shaders, shader, &cache_hit);
 }
 
-void
+struct zink_gfx_library_key *
 zink_create_pipeline_lib(struct zink_screen *screen, struct zink_gfx_program *prog, struct zink_gfx_pipeline_state *state)
 {
    struct zink_gfx_library_key *gkey = rzalloc(prog, struct zink_gfx_library_key);
-   memcpy(gkey->modules, state->modules, sizeof(gkey->modules));
+   gkey->optimal_key = state->optimal_key;
+   memcpy(gkey->modules, prog->modules, sizeof(gkey->modules));
    gkey->pipeline = zink_create_gfx_pipeline_library(screen, prog);
    _mesa_set_add(&prog->libs, gkey);
+   return gkey;
 }
 
 void
index f4e054f..335f1bb 100644 (file)
@@ -33,6 +33,10 @@ extern "C" {
 struct gfx_pipeline_cache_entry {
    struct zink_gfx_pipeline_state state;
    VkPipeline pipeline;
+   /* GPL only */
+   struct zink_gfx_input_key *ikey;
+   struct zink_gfx_library_key *gkey;
+   struct zink_gfx_output_key *okey;
 };
 
 struct compute_pipeline_cache_entry {
@@ -124,7 +128,7 @@ void
 zink_gfx_program_update_optimal(struct zink_context *ctx);
 
 
-void
+struct zink_gfx_library_key *
 zink_create_pipeline_lib(struct zink_screen *screen, struct zink_gfx_program *prog, struct zink_gfx_pipeline_state *state);
 uint32_t hash_gfx_output(const void *key);
 uint32_t hash_gfx_output_ds3(const void *key);
index 83ebd58..311c26c 100644 (file)
@@ -217,6 +217,11 @@ zink_get_gfx_pipeline(struct zink_context *ctx,
    if (!entry) {
       util_queue_fence_wait(&prog->base.cache_fence);
       VkPipeline pipeline = VK_NULL_HANDLE;
+      struct gfx_pipeline_cache_entry *pc_entry = CALLOC_STRUCT(gfx_pipeline_cache_entry);
+      if (!pc_entry)
+         return VK_NULL_HANDLE;
+      memcpy(&pc_entry->state, state, sizeof(*state));
+      entry = _mesa_hash_table_insert_pre_hashed(&prog->pipelines[rp_idx][idx], state->final_hash, pc_entry, pc_entry);
       if (HAVE_LIB &&
           /* TODO: if there's ever a dynamic render extension with input attachments */
           !ctx->gfx_pipeline_state.render_pass &&
@@ -225,41 +230,30 @@ zink_get_gfx_pipeline(struct zink_context *ctx,
           !zink_get_fs_key(ctx)->fbfetch_ms &&
           !ctx->gfx_pipeline_state.force_persample_interp &&
           !ctx->gfx_pipeline_state.min_samples) {
-         struct set_entry *he = _mesa_set_search(&prog->libs, ctx->gfx_pipeline_state.modules);
-         if (!he && (zink_debug & ZINK_DEBUG_GPL)) {
-            zink_create_pipeline_lib(screen, prog, &ctx->gfx_pipeline_state);
-            he = _mesa_set_search(&prog->libs, ctx->gfx_pipeline_state.modules);
-            assert(he);
-         }
-         if (he) {
-            struct zink_gfx_library_key *gkey = (struct zink_gfx_library_key *)he->key;
-            struct zink_gfx_input_key *ikey = DYNAMIC_STATE == ZINK_DYNAMIC_VERTEX_INPUT || DYNAMIC_STATE == ZINK_DYNAMIC_VERTEX_INPUT2 ?
-                                              find_or_create_input_dynamic(ctx, vkmode) :
-                                              find_or_create_input(ctx, vkmode);
-            struct zink_gfx_output_key *okey = DYNAMIC_STATE >= ZINK_DYNAMIC_STATE3 && screen->have_full_ds3 ?
-                                               find_or_create_output_ds3(ctx) :
-                                               find_or_create_output(ctx);
-            pipeline = zink_create_gfx_pipeline_combined(screen, prog, ikey->pipeline, gkey->pipeline, okey->pipeline);
-         }
-      }
-      if (!pipeline) {
-         pipeline = zink_create_gfx_pipeline(screen, prog, state,
-                                             ctx->element_state->binding_map,
-                                             vkmode);
+         struct set_entry *he = _mesa_set_search(&prog->libs, &ctx->gfx_pipeline_state.optimal_key);
+         struct zink_gfx_library_key *gkey;
+         if (he)
+            gkey = (struct zink_gfx_library_key *)he->key;
+         else
+            gkey = zink_create_pipeline_lib(screen, prog, &ctx->gfx_pipeline_state);
+         struct zink_gfx_input_key *ikey = DYNAMIC_STATE == ZINK_DYNAMIC_VERTEX_INPUT ?
+                                             find_or_create_input_dynamic(ctx, vkmode) :
+                                             find_or_create_input(ctx, vkmode);
+         struct zink_gfx_output_key *okey = DYNAMIC_STATE >= ZINK_DYNAMIC_STATE3 && screen->have_full_ds3 ?
+                                             find_or_create_output_ds3(ctx) :
+                                             find_or_create_output(ctx);
+         pc_entry->ikey = ikey;
+         pc_entry->gkey = gkey;
+         pc_entry->okey = okey;
+         pipeline = zink_create_gfx_pipeline_combined(screen, prog, ikey->pipeline, gkey->pipeline, okey->pipeline);
+      } else {
+         pipeline = zink_create_gfx_pipeline(screen, prog, state, ctx->element_state->binding_map, vkmode);
       }
       if (pipeline == VK_NULL_HANDLE)
          return VK_NULL_HANDLE;
 
       zink_screen_update_pipeline_cache(screen, &prog->base, false);
-      struct gfx_pipeline_cache_entry *pc_entry = CALLOC_STRUCT(gfx_pipeline_cache_entry);
-      if (!pc_entry)
-         return VK_NULL_HANDLE;
-
-      memcpy(&pc_entry->state, state, sizeof(*state));
       pc_entry->pipeline = pipeline;
-
-      entry = _mesa_hash_table_insert_pre_hashed(&prog->pipelines[rp_idx][idx], state->final_hash, pc_entry, pc_entry);
-      assert(entry);
    }
 
    struct gfx_pipeline_cache_entry *cache_entry = (struct gfx_pipeline_cache_entry *)entry->data;
index 25ef765..948f704 100644 (file)
@@ -2592,9 +2592,8 @@ zink_internal_create_screen(const struct pipe_screen_config *config)
    /* temporarily disabled */
    screen->info.have_EXT_graphics_pipeline_library = false;
 
-   if (!(zink_debug & ZINK_DEBUG_GPL))
-      screen->optimal_keys = !screen->need_decompose_attrs && screen->info.have_EXT_non_seamless_cube_map && !screen->driconf.inline_uniforms;
-   if (screen->optimal_keys)
+   screen->optimal_keys = !screen->need_decompose_attrs && screen->info.have_EXT_non_seamless_cube_map && !screen->driconf.inline_uniforms;
+   if (!screen->optimal_keys)
       screen->info.have_EXT_graphics_pipeline_library = false;
 
    return screen;
index 3f7288c..7283c4e 100644 (file)
@@ -791,10 +791,8 @@ struct zink_program {
 typedef bool (*equals_gfx_pipeline_state_func)(const void *a, const void *b);
 
 struct zink_gfx_library_key {
-   union {
-      VkShaderModule modules[ZINK_GFX_SHADER_COUNT];
-      uint32_t optimal_key; //equals_pipeline_lib_optimal
-   };
+   uint32_t optimal_key; //equals_pipeline_lib_optimal
+   VkShaderModule modules[ZINK_GFX_SHADER_COUNT];
    VkPipeline pipeline;
 };