[Mesa-dev] [PATCH 11/21] anv/pipeline: Pull shader compilation out into a helper.

Jason Ekstrand jason at jlekstrand.net
Sat Oct 28 18:36:19 UTC 2017


---
 src/intel/vulkan/anv_pipeline.c | 209 +++++++++++++++++++++-------------------
 1 file changed, 111 insertions(+), 98 deletions(-)

diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index ba0ffd7..ec14c73 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -947,6 +947,113 @@ anv_pipeline_compile_fs(struct anv_pipeline *pipeline,
    return VK_SUCCESS;
 }
 
+static VkResult
+anv_pipeline_compile_graphics(struct anv_pipeline *pipeline,
+                              struct anv_pipeline_cache *cache,
+                              const VkGraphicsPipelineCreateInfo *info)
+{
+   struct anv_pipeline_stage stages[MESA_SHADER_STAGES] = {};
+
+   VkResult result;
+   for (uint32_t i = 0; i < info->stageCount; i++) {
+      gl_shader_stage stage = vk_to_mesa_shader_stage(info->pStages[i].stage);
+      const VkPipelineShaderStageCreateInfo *sinfo = &info->pStages[i];
+
+      stages[stage].stage = stage;
+      stages[stage].module = anv_shader_module_from_handle(sinfo->module);
+      stages[stage].entrypoint = sinfo->pName;
+      stages[stage].spec_info = sinfo->pSpecializationInfo;
+
+      const struct gen_device_info *devinfo = &pipeline->device->info;
+      switch (stage) {
+      case MESA_SHADER_VERTEX:
+         populate_vs_prog_key(devinfo, &stages[stage].key.vs);
+         break;
+      case MESA_SHADER_TESS_CTRL:
+         populate_tcs_prog_key(devinfo,
+                               info->pTessellationState->patchControlPoints,
+                               &stages[stage].key.tcs);
+         break;
+      case MESA_SHADER_TESS_EVAL:
+         populate_tes_prog_key(devinfo, &stages[stage].key.tes);
+         break;
+      case MESA_SHADER_GEOMETRY:
+         populate_gs_prog_key(devinfo, &stages[stage].key.gs);
+         break;
+      case MESA_SHADER_FRAGMENT:
+         populate_wm_prog_key(devinfo, info->pMultisampleState,
+                              pipeline->subpass->color_count,
+                              &stages[stage].key.wm);
+         break;
+      default:
+         unreachable("Invalid graphics shader stage");
+      }
+   }
+
+   if (cache) {
+      unsigned char sha1[20];
+      anv_pipeline_hash_graphics(pipeline, stages, sha1);
+
+      for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
+         if (!stages[s].entrypoint)
+            continue;
+
+         stages[s].cache_key.stage = s;
+         memcpy(stages[s].cache_key.sha1, sha1, sizeof(sha1));
+
+         struct anv_shader_bin *bin =
+            anv_pipeline_cache_search(cache, &stages[s].cache_key,
+                                      sizeof(stages[s].cache_key));
+         if (bin)
+            anv_pipeline_add_compiled_stage(pipeline, s, bin);
+      }
+   }
+
+   for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
+      if (!stages[s].entrypoint)
+         continue;
+
+      assert(stages[s].stage == s);
+
+      if (pipeline->shaders[s])
+         continue;
+
+      switch (s) {
+      case MESA_SHADER_VERTEX:
+         result = anv_pipeline_compile_vs(pipeline, cache, &stages[s]);
+         break;
+      case MESA_SHADER_TESS_CTRL:
+         /* Handled with TESS_EVAL */
+         break;
+      case MESA_SHADER_TESS_EVAL:
+         result = anv_pipeline_compile_tcs_tes(pipeline, cache,
+                                               &stages[MESA_SHADER_TESS_CTRL],
+                                               &stages[MESA_SHADER_TESS_EVAL]);
+         break;
+      case MESA_SHADER_GEOMETRY:
+         result = anv_pipeline_compile_gs(pipeline, cache, &stages[s]);
+         break;
+      case MESA_SHADER_FRAGMENT:
+         result = anv_pipeline_compile_fs(pipeline, cache, &stages[s]);
+         break;
+      default:
+         unreachable("Invalid graphics shader stage");
+      }
+      if (result != VK_SUCCESS)
+         goto fail;
+   }
+
+   return VK_SUCCESS;
+
+fail:
+   for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
+      if (pipeline->shaders[s])
+         anv_shader_bin_unref(pipeline->device, pipeline->shaders[s]);
+   }
+
+   return result;
+}
+
 VkResult
 anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
                         struct anv_pipeline_cache *cache,
@@ -1276,94 +1383,10 @@ anv_pipeline_init(struct anv_pipeline *pipeline,
 
    pipeline->active_stages = 0;
 
-   struct anv_pipeline_stage stages[MESA_SHADER_STAGES] = {};
-   for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
-      gl_shader_stage stage =
-         vk_to_mesa_shader_stage(pCreateInfo->pStages[i].stage);
-      const VkPipelineShaderStageCreateInfo *sinfo = &pCreateInfo->pStages[i];
-
-      stages[stage].stage = stage;
-      stages[stage].module = anv_shader_module_from_handle(sinfo->module);
-      stages[stage].entrypoint = sinfo->pName;
-      stages[stage].spec_info = sinfo->pSpecializationInfo;
-
-      const struct gen_device_info *devinfo = &device->info;
-      switch (stage) {
-      case MESA_SHADER_VERTEX:
-         populate_vs_prog_key(devinfo, &stages[stage].key.vs);
-         break;
-      case MESA_SHADER_TESS_CTRL:
-         populate_tcs_prog_key(devinfo,
-                               pCreateInfo->pTessellationState->patchControlPoints,
-                               &stages[stage].key.tcs);
-         break;
-      case MESA_SHADER_TESS_EVAL:
-         populate_tes_prog_key(devinfo, &stages[stage].key.tes);
-         break;
-      case MESA_SHADER_GEOMETRY:
-         populate_gs_prog_key(devinfo, &stages[stage].key.gs);
-         break;
-      case MESA_SHADER_FRAGMENT:
-         populate_wm_prog_key(devinfo, pCreateInfo->pMultisampleState,
-                              pipeline->subpass->color_count,
-                              &stages[stage].key.wm);
-         break;
-      default:
-         unreachable("Invalid graphics shader stage");
-      }
-   }
-
-   if (cache) {
-      unsigned char sha1[20];
-      anv_pipeline_hash_graphics(pipeline, stages, sha1);
-
-      for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
-         if (!stages[s].entrypoint)
-            continue;
-
-         stages[s].cache_key.stage = s;
-         memcpy(stages[s].cache_key.sha1, sha1, sizeof(sha1));
-
-         struct anv_shader_bin *bin =
-            anv_pipeline_cache_search(cache, &stages[s].cache_key,
-                                      sizeof(stages[s].cache_key));
-         if (bin)
-            anv_pipeline_add_compiled_stage(pipeline, s, bin);
-      }
-   }
-
-   for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
-      if (!stages[s].entrypoint)
-         continue;
-
-      assert(stages[s].stage == s);
-
-      if (pipeline->shaders[s])
-         continue;
-
-      switch (s) {
-      case MESA_SHADER_VERTEX:
-         result = anv_pipeline_compile_vs(pipeline, cache, &stages[s]);
-         break;
-      case MESA_SHADER_TESS_CTRL:
-         /* Handled with TESS_EVAL */
-         break;
-      case MESA_SHADER_TESS_EVAL:
-         result = anv_pipeline_compile_tcs_tes(pipeline, cache,
-                                               &stages[MESA_SHADER_TESS_CTRL],
-                                               &stages[MESA_SHADER_TESS_EVAL]);
-         break;
-      case MESA_SHADER_GEOMETRY:
-         result = anv_pipeline_compile_gs(pipeline, cache, &stages[s]);
-         break;
-      case MESA_SHADER_FRAGMENT:
-         result = anv_pipeline_compile_fs(pipeline, cache, &stages[s]);
-         break;
-      default:
-         unreachable("Invalid graphics shader stage");
-      }
-      if (result != VK_SUCCESS)
-         goto compile_fail;
+   result = anv_pipeline_compile_graphics(pipeline, cache, pCreateInfo);
+   if (result != VK_SUCCESS) {
+      anv_reloc_list_finish(&pipeline->batch_relocs, alloc);
+      return result;
    }
 
    assert(pipeline->active_stages & VK_SHADER_STAGE_VERTEX_BIT);
@@ -1416,14 +1439,4 @@ anv_pipeline_init(struct anv_pipeline *pipeline,
       pipeline->topology = vk_to_gen_primitive_type[ia_info->topology];
 
    return VK_SUCCESS;
-
-compile_fail:
-   for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
-      if (pipeline->shaders[s])
-         anv_shader_bin_unref(device, pipeline->shaders[s]);
-   }
-
-   anv_reloc_list_finish(&pipeline->batch_relocs, alloc);
-
-   return result;
 }
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list