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

Author: Mike Blumenkrantz <[email protected]>
Date:   Mon Apr  3 15:45:20 2023 -0400

zink: avoid accessing zink_gfx_program::modules during pipeline compile

this allows a different array of modules to be passed in

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22725>

---

 src/gallium/drivers/zink/zink_pipeline.c        | 7 ++++---
 src/gallium/drivers/zink/zink_pipeline.h        | 1 +
 src/gallium/drivers/zink/zink_program.c         | 6 ++++--
 src/gallium/drivers/zink/zink_program_state.hpp | 4 ++--
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_pipeline.c 
b/src/gallium/drivers/zink/zink_pipeline.c
index 0021ff99850..44888a00a8f 100644
--- a/src/gallium/drivers/zink/zink_pipeline.c
+++ b/src/gallium/drivers/zink/zink_pipeline.c
@@ -38,6 +38,7 @@
 VkPipeline
 zink_create_gfx_pipeline(struct zink_screen *screen,
                          struct zink_gfx_program *prog,
+                         VkShaderModule *modules,
                          struct zink_gfx_pipeline_state *state,
                          const uint8_t *binding_map,
                          VkPrimitiveTopology primitive_topology,
@@ -364,7 +365,7 @@ zink_create_gfx_pipeline(struct zink_screen *screen,
 
    VkPipelineTessellationStateCreateInfo tci = {0};
    VkPipelineTessellationDomainOriginStateCreateInfo tdci = {0};
-   if (prog->modules[MESA_SHADER_TESS_CTRL] && 
prog->modules[MESA_SHADER_TESS_EVAL]) {
+   if (prog->shaders[MESA_SHADER_TESS_CTRL] && 
prog->shaders[MESA_SHADER_TESS_EVAL]) {
       tci.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
       tci.patchControlPoints = state->dyn_state2.vertices_per_patch;
       pci.pTessellationState = &tci;
@@ -376,13 +377,13 @@ zink_create_gfx_pipeline(struct zink_screen *screen,
    VkPipelineShaderStageCreateInfo shader_stages[ZINK_GFX_SHADER_COUNT];
    uint32_t num_stages = 0;
    for (int i = 0; i < ZINK_GFX_SHADER_COUNT; ++i) {
-      if (!prog->modules[i])
+      if (!prog->shaders[i])
          continue;
 
       VkPipelineShaderStageCreateInfo stage = {0};
       stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
       stage.stage = mesa_to_vk_shader_stage(i);
-      stage.module = prog->modules[i];
+      stage.module = modules[i];
       stage.pName = "main";
       shader_stages[num_stages++] = stage;
    }
diff --git a/src/gallium/drivers/zink/zink_pipeline.h 
b/src/gallium/drivers/zink/zink_pipeline.h
index c6d5001c074..72397de90c3 100644
--- a/src/gallium/drivers/zink/zink_pipeline.h
+++ b/src/gallium/drivers/zink/zink_pipeline.h
@@ -43,6 +43,7 @@ zink_find_or_create_input_dynamic(struct zink_context *ctx, 
VkPrimitiveTopology
 VkPipeline
 zink_create_gfx_pipeline(struct zink_screen *screen,
                          struct zink_gfx_program *prog,
+                         VkShaderModule *modules,
                          struct zink_gfx_pipeline_state *state,
                          const uint8_t *binding_map,
                          VkPrimitiveTopology primitive_topology,
diff --git a/src/gallium/drivers/zink/zink_program.c 
b/src/gallium/drivers/zink/zink_program.c
index be798cd3098..ca7dad896e3 100644
--- a/src/gallium/drivers/zink/zink_program.c
+++ b/src/gallium/drivers/zink/zink_program.c
@@ -781,7 +781,7 @@ optimized_compile_job(void *data, void *gdata, int 
thread_index)
    if (pc_entry->gkey)
       pipeline = zink_create_gfx_pipeline_combined(screen, pc_entry->prog, 
pc_entry->ikey->pipeline, &pc_entry->gkey->pipeline, 1, 
pc_entry->okey->pipeline, true);
    else
-      pipeline = zink_create_gfx_pipeline(screen, pc_entry->prog, 
&pc_entry->state, pc_entry->state.element_state->binding_map, 
zink_primitive_topology(pc_entry->state.gfx_prim_mode), true);
+      pipeline = zink_create_gfx_pipeline(screen, pc_entry->prog, 
pc_entry->prog->modules, &pc_entry->state, 
pc_entry->state.element_state->binding_map, 
zink_primitive_topology(pc_entry->state.gfx_prim_mode), true);
    if (pipeline) {
       pc_entry->unoptimized_pipeline = pc_entry->pipeline;
       pc_entry->pipeline = pipeline;
@@ -2099,7 +2099,9 @@ zink_link_gfx_shader(struct pipe_context *pctx, void 
**shaders)
          generate_gfx_program_modules_optimal(ctx, screen,  prog, 
&ctx->gfx_pipeline_state);
       else
          generate_gfx_program_modules(ctx, screen,  prog, 
&ctx->gfx_pipeline_state);
-      VkPipeline pipeline = zink_create_gfx_pipeline(screen, prog, 
&ctx->gfx_pipeline_state, ctx->gfx_pipeline_state.element_state->binding_map,  
shaders[MESA_SHADER_TESS_EVAL] ? VK_PRIMITIVE_TOPOLOGY_PATCH_LIST : 
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, true);
+      VkPipeline pipeline = zink_create_gfx_pipeline(screen, prog, 
prog->modules, &ctx->gfx_pipeline_state,
+                                                     
ctx->gfx_pipeline_state.element_state->binding_map,
+                                                     
shaders[MESA_SHADER_TESS_EVAL] ? VK_PRIMITIVE_TOPOLOGY_PATCH_LIST : 
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, true);
       print_pipeline_stats(screen, pipeline);
    } else {
       util_queue_add_job(&zink_screen(pctx->screen)->cache_get_thread, prog, 
&prog->base.cache_fence, precompile_job, NULL, 0);
diff --git a/src/gallium/drivers/zink/zink_program_state.hpp 
b/src/gallium/drivers/zink/zink_program_state.hpp
index 7b57856ae3a..8cbb7ca449f 100644
--- a/src/gallium/drivers/zink/zink_program_state.hpp
+++ b/src/gallium/drivers/zink/zink_program_state.hpp
@@ -213,9 +213,9 @@ zink_get_gfx_pipeline(struct zink_context *ctx,
       } else {
          /* optimize by default only when expecting precompiles in order to 
reduce stuttering */
          if (DYNAMIC_STATE != ZINK_DYNAMIC_VERTEX_INPUT2 && DYNAMIC_STATE != 
ZINK_DYNAMIC_VERTEX_INPUT)
-            pipeline = zink_create_gfx_pipeline(screen, prog, state, 
state->element_state->binding_map, vkmode, !HAVE_LIB);
+            pipeline = zink_create_gfx_pipeline(screen, prog, prog->modules, 
state, state->element_state->binding_map, vkmode, !HAVE_LIB);
          else
-            pipeline = zink_create_gfx_pipeline(screen, prog, state, NULL, 
vkmode, !HAVE_LIB);
+            pipeline = zink_create_gfx_pipeline(screen, prog, prog->modules, 
state, NULL, vkmode, !HAVE_LIB);
       }
       if (pipeline == VK_NULL_HANDLE)
          return VK_NULL_HANDLE;

Reply via email to