[Mesa-dev] [PATCH 07/21] anv/pipline: Add a helper struct for per-stage info

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


---
 src/intel/vulkan/anv_pipeline.c | 170 +++++++++++++++++-----------------------
 src/intel/vulkan/anv_private.h  |   2 +-
 2 files changed, 74 insertions(+), 98 deletions(-)

diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index 8318dea..311bd91 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -98,7 +98,7 @@ static const uint64_t stage_to_debug[] = {
 static nir_shader *
 anv_shader_compile_to_nir(struct anv_pipeline *pipeline,
                           void *mem_ctx,
-                          struct anv_shader_module *module,
+                          const struct anv_shader_module *module,
                           const char *entrypoint_name,
                           gl_shader_stage stage,
                           const VkSpecializationInfo *spec_info)
@@ -359,19 +359,24 @@ populate_cs_prog_key(const struct gen_device_info *devinfo,
    populate_sampler_prog_key(devinfo, &key->tex);
 }
 
+struct anv_pipeline_stage {
+   gl_shader_stage stage;
+
+   const struct anv_shader_module *module;
+   const char *entrypoint;
+   const VkSpecializationInfo *spec_info;
+};
+
 static void
 anv_pipeline_hash_shader(struct anv_pipeline *pipeline,
-                         struct anv_shader_module *module,
-                         const char *entrypoint,
-                         gl_shader_stage stage,
-                         const VkSpecializationInfo *spec_info,
+                         struct anv_pipeline_stage *stage,
                          const void *key, size_t key_size,
                          unsigned char *sha1_out)
 {
    struct mesa_sha1 ctx;
 
    _mesa_sha1_init(&ctx);
-   if (stage != MESA_SHADER_COMPUTE) {
+   if (stage->stage != MESA_SHADER_COMPUTE) {
       _mesa_sha1_update(&ctx, &pipeline->subpass->view_mask,
                         sizeof(pipeline->subpass->view_mask));
    }
@@ -379,13 +384,15 @@ anv_pipeline_hash_shader(struct anv_pipeline *pipeline,
       _mesa_sha1_update(&ctx, pipeline->layout->sha1,
                         sizeof(pipeline->layout->sha1));
    }
-   _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
-   _mesa_sha1_update(&ctx, entrypoint, strlen(entrypoint));
-   _mesa_sha1_update(&ctx, &stage, sizeof(stage));
-   if (spec_info) {
-      _mesa_sha1_update(&ctx, spec_info->pMapEntries,
-                        spec_info->mapEntryCount * sizeof(*spec_info->pMapEntries));
-      _mesa_sha1_update(&ctx, spec_info->pData, spec_info->dataSize);
+   _mesa_sha1_update(&ctx, stage->module->sha1, sizeof(stage->module->sha1));
+   _mesa_sha1_update(&ctx, stage->entrypoint, strlen(stage->entrypoint));
+   _mesa_sha1_update(&ctx, &stage->stage, sizeof(stage->stage));
+   if (stage->spec_info) {
+      _mesa_sha1_update(&ctx, stage->spec_info->pMapEntries,
+                        stage->spec_info->mapEntryCount *
+                        sizeof(*stage->spec_info->pMapEntries));
+      _mesa_sha1_update(&ctx, stage->spec_info->pData,
+                        stage->spec_info->dataSize);
    }
    _mesa_sha1_update(&ctx, key, key_size);
    _mesa_sha1_final(&ctx, sha1_out);
@@ -394,16 +401,15 @@ anv_pipeline_hash_shader(struct anv_pipeline *pipeline,
 static nir_shader *
 anv_pipeline_compile(struct anv_pipeline *pipeline,
                      void *mem_ctx,
-                     struct anv_shader_module *module,
-                     const char *entrypoint,
-                     gl_shader_stage stage,
-                     const VkSpecializationInfo *spec_info,
+                     struct anv_pipeline_stage *stage,
                      struct brw_stage_prog_data *prog_data,
                      struct anv_pipeline_bind_map *map)
 {
    nir_shader *nir = anv_shader_compile_to_nir(pipeline, mem_ctx,
-                                               module, entrypoint, stage,
-                                               spec_info);
+                                               stage->module,
+                                               stage->entrypoint,
+                                               stage->stage,
+                                               stage->spec_info);
    if (nir == NULL)
       return NULL;
 
@@ -411,10 +417,10 @@ anv_pipeline_compile(struct anv_pipeline *pipeline,
 
    NIR_PASS_V(nir, anv_nir_lower_push_constants);
 
-   if (stage != MESA_SHADER_COMPUTE)
+   if (nir->info.stage != MESA_SHADER_COMPUTE)
       NIR_PASS_V(nir, anv_nir_lower_multiview, pipeline->subpass->view_mask);
 
-   if (stage == MESA_SHADER_COMPUTE) {
+   if (nir->info.stage == MESA_SHADER_COMPUTE) {
       NIR_PASS_V(nir, brw_nir_lower_cs_shared);
       prog_data->total_shared = nir->num_shared;
    }
@@ -503,10 +509,7 @@ anv_pipeline_add_compiled_stage(struct anv_pipeline *pipeline,
 static VkResult
 anv_pipeline_compile_vs(struct anv_pipeline *pipeline,
                         struct anv_pipeline_cache *cache,
-                        const VkGraphicsPipelineCreateInfo *info,
-                        struct anv_shader_module *module,
-                        const char *entrypoint,
-                        const VkSpecializationInfo *spec_info)
+                        struct anv_pipeline_stage *stage)
 {
    const struct brw_compiler *compiler =
       pipeline->device->instance->physicalDevice.compiler;
@@ -517,9 +520,7 @@ anv_pipeline_compile_vs(struct anv_pipeline *pipeline,
    populate_vs_prog_key(&pipeline->device->info, &key);
 
    if (cache) {
-      anv_pipeline_hash_shader(pipeline, module, entrypoint,
-                               MESA_SHADER_VERTEX, spec_info,
-                               &key, sizeof(key), sha1);
+      anv_pipeline_hash_shader(pipeline, stage, &key, sizeof(key), sha1);
       bin = anv_pipeline_cache_search(cache, sha1, 20);
    }
 
@@ -535,9 +536,7 @@ anv_pipeline_compile_vs(struct anv_pipeline *pipeline,
 
       void *mem_ctx = ralloc_context(NULL);
 
-      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx,
-                                             module, entrypoint,
-                                             MESA_SHADER_VERTEX, spec_info,
+      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, stage,
                                              &prog_data.base.base, &map);
       if (nir == NULL) {
          ralloc_free(mem_ctx);
@@ -620,12 +619,8 @@ static VkResult
 anv_pipeline_compile_tcs_tes(struct anv_pipeline *pipeline,
                              struct anv_pipeline_cache *cache,
                              const VkGraphicsPipelineCreateInfo *info,
-                             struct anv_shader_module *tcs_module,
-                             const char *tcs_entrypoint,
-                             const VkSpecializationInfo *tcs_spec_info,
-                             struct anv_shader_module *tes_module,
-                             const char *tes_entrypoint,
-                             const VkSpecializationInfo *tes_spec_info)
+                             struct anv_pipeline_stage *tcs_stage,
+                             struct anv_pipeline_stage *tes_stage)
 {
    const struct gen_device_info *devinfo = &pipeline->device->info;
    const struct brw_compiler *compiler =
@@ -643,11 +638,9 @@ anv_pipeline_compile_tcs_tes(struct anv_pipeline *pipeline,
    populate_tes_prog_key(&pipeline->device->info, &tes_key);
 
    if (cache) {
-      anv_pipeline_hash_shader(pipeline, tcs_module, tcs_entrypoint,
-                               MESA_SHADER_TESS_CTRL, tcs_spec_info,
+      anv_pipeline_hash_shader(pipeline, tcs_stage,
                                &tcs_key, sizeof(tcs_key), tcs_sha1);
-      anv_pipeline_hash_shader(pipeline, tes_module, tes_entrypoint,
-                               MESA_SHADER_TESS_EVAL, tes_spec_info,
+      anv_pipeline_hash_shader(pipeline, tes_stage,
                                &tes_key, sizeof(tes_key), tes_sha1);
       memcpy(&tcs_sha1[20], tes_sha1, 20);
       memcpy(&tes_sha1[20], tcs_sha1, 20);
@@ -675,12 +668,10 @@ anv_pipeline_compile_tcs_tes(struct anv_pipeline *pipeline,
       void *mem_ctx = ralloc_context(NULL);
 
       nir_shader *tcs_nir =
-         anv_pipeline_compile(pipeline, mem_ctx, tcs_module, tcs_entrypoint,
-                              MESA_SHADER_TESS_CTRL, tcs_spec_info,
+         anv_pipeline_compile(pipeline, mem_ctx, tcs_stage,
                               &tcs_prog_data.base.base, &tcs_map);
       nir_shader *tes_nir =
-         anv_pipeline_compile(pipeline, mem_ctx, tes_module, tes_entrypoint,
-                              MESA_SHADER_TESS_EVAL, tes_spec_info,
+         anv_pipeline_compile(pipeline, mem_ctx, tes_stage,
                               &tes_prog_data.base.base, &tes_map);
       if (tcs_nir == NULL || tes_nir == NULL) {
          ralloc_free(mem_ctx);
@@ -767,10 +758,7 @@ anv_pipeline_compile_tcs_tes(struct anv_pipeline *pipeline,
 static VkResult
 anv_pipeline_compile_gs(struct anv_pipeline *pipeline,
                         struct anv_pipeline_cache *cache,
-                        const VkGraphicsPipelineCreateInfo *info,
-                        struct anv_shader_module *module,
-                        const char *entrypoint,
-                        const VkSpecializationInfo *spec_info)
+                        struct anv_pipeline_stage *stage)
 {
    const struct brw_compiler *compiler =
       pipeline->device->instance->physicalDevice.compiler;
@@ -781,9 +769,7 @@ anv_pipeline_compile_gs(struct anv_pipeline *pipeline,
    populate_gs_prog_key(&pipeline->device->info, &key);
 
    if (cache) {
-      anv_pipeline_hash_shader(pipeline, module, entrypoint,
-                               MESA_SHADER_GEOMETRY, spec_info,
-                               &key, sizeof(key), sha1);
+      anv_pipeline_hash_shader(pipeline, stage, &key, sizeof(key), sha1);
       bin = anv_pipeline_cache_search(cache, sha1, 20);
    }
 
@@ -799,9 +785,7 @@ anv_pipeline_compile_gs(struct anv_pipeline *pipeline,
 
       void *mem_ctx = ralloc_context(NULL);
 
-      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx,
-                                             module, entrypoint,
-                                             MESA_SHADER_GEOMETRY, spec_info,
+      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, stage,
                                              &prog_data.base.base, &map);
       if (nir == NULL) {
          ralloc_free(mem_ctx);
@@ -846,9 +830,7 @@ static VkResult
 anv_pipeline_compile_fs(struct anv_pipeline *pipeline,
                         struct anv_pipeline_cache *cache,
                         const VkGraphicsPipelineCreateInfo *info,
-                        struct anv_shader_module *module,
-                        const char *entrypoint,
-                        const VkSpecializationInfo *spec_info)
+                        struct anv_pipeline_stage *stage)
 {
    const struct brw_compiler *compiler =
       pipeline->device->instance->physicalDevice.compiler;
@@ -868,9 +850,7 @@ anv_pipeline_compile_fs(struct anv_pipeline *pipeline,
    key.input_slots_valid = vue_map->slots_valid;
 
    if (cache) {
-      anv_pipeline_hash_shader(pipeline, module, entrypoint,
-                               MESA_SHADER_FRAGMENT, spec_info,
-                               &key, sizeof(key), sha1);
+      anv_pipeline_hash_shader(pipeline, stage, &key, sizeof(key), sha1);
       bin = anv_pipeline_cache_search(cache, sha1, 20);
    }
 
@@ -886,9 +866,7 @@ anv_pipeline_compile_fs(struct anv_pipeline *pipeline,
 
       void *mem_ctx = ralloc_context(NULL);
 
-      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx,
-                                             module, entrypoint,
-                                             MESA_SHADER_FRAGMENT, spec_info,
+      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, stage,
                                              &prog_data.base, &map);
       if (nir == NULL) {
          ralloc_free(mem_ctx);
@@ -978,12 +956,20 @@ VkResult
 anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
                         struct anv_pipeline_cache *cache,
                         const VkComputePipelineCreateInfo *info,
-                        struct anv_shader_module *module,
+                        const struct anv_shader_module *module,
                         const char *entrypoint,
                         const VkSpecializationInfo *spec_info)
 {
    const struct brw_compiler *compiler =
       pipeline->device->instance->physicalDevice.compiler;
+
+   struct anv_pipeline_stage stage = {
+      .stage = MESA_SHADER_COMPUTE,
+      .module = module,
+      .entrypoint = entrypoint,
+      .spec_info = spec_info,
+   };
+
    struct brw_cs_prog_key key;
    struct anv_shader_bin *bin = NULL;
    unsigned char sha1[20];
@@ -991,9 +977,7 @@ anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
    populate_cs_prog_key(&pipeline->device->info, &key);
 
    if (cache) {
-      anv_pipeline_hash_shader(pipeline, module, entrypoint,
-                               MESA_SHADER_COMPUTE, spec_info,
-                               &key, sizeof(key), sha1);
+      anv_pipeline_hash_shader(pipeline, &stage, &key, sizeof(key), sha1);
       bin = anv_pipeline_cache_search(cache, sha1, 20);
    }
 
@@ -1009,9 +993,7 @@ anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
 
       void *mem_ctx = ralloc_context(NULL);
 
-      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx,
-                                             module, entrypoint,
-                                             MESA_SHADER_COMPUTE, spec_info,
+      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, &stage,
                                              &prog_data.base, &map);
       if (nir == NULL) {
          ralloc_free(mem_ctx);
@@ -1300,47 +1282,41 @@ anv_pipeline_init(struct anv_pipeline *pipeline,
 
    pipeline->active_stages = 0;
 
-   const VkPipelineShaderStageCreateInfo *pStages[MESA_SHADER_STAGES] = {};
-   struct anv_shader_module *modules[MESA_SHADER_STAGES] = {};
+   struct anv_pipeline_stage stages[MESA_SHADER_STAGES] = {};
    for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
-      gl_shader_stage stage = ffs(pCreateInfo->pStages[i].stage) - 1;
-      pStages[stage] = &pCreateInfo->pStages[i];
-      modules[stage] = anv_shader_module_from_handle(pStages[stage]->module);
+      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;
    }
 
-   if (modules[MESA_SHADER_VERTEX]) {
-      result = anv_pipeline_compile_vs(pipeline, cache, pCreateInfo,
-                                       modules[MESA_SHADER_VERTEX],
-                                       pStages[MESA_SHADER_VERTEX]->pName,
-                                       pStages[MESA_SHADER_VERTEX]->pSpecializationInfo);
+   if (stages[MESA_SHADER_VERTEX].entrypoint) {
+      result = anv_pipeline_compile_vs(pipeline, cache,
+                                       &stages[MESA_SHADER_VERTEX]);
       if (result != VK_SUCCESS)
          goto compile_fail;
    }
 
-   if (modules[MESA_SHADER_TESS_EVAL]) {
+   if (stages[MESA_SHADER_TESS_EVAL].entrypoint) {
       anv_pipeline_compile_tcs_tes(pipeline, cache, pCreateInfo,
-                                   modules[MESA_SHADER_TESS_CTRL],
-                                   pStages[MESA_SHADER_TESS_CTRL]->pName,
-                                   pStages[MESA_SHADER_TESS_CTRL]->pSpecializationInfo,
-                                   modules[MESA_SHADER_TESS_EVAL],
-                                   pStages[MESA_SHADER_TESS_EVAL]->pName,
-                                   pStages[MESA_SHADER_TESS_EVAL]->pSpecializationInfo);
+                                   &stages[MESA_SHADER_TESS_CTRL],
+                                   &stages[MESA_SHADER_TESS_EVAL]);
    }
 
-   if (modules[MESA_SHADER_GEOMETRY]) {
-      result = anv_pipeline_compile_gs(pipeline, cache, pCreateInfo,
-                                       modules[MESA_SHADER_GEOMETRY],
-                                       pStages[MESA_SHADER_GEOMETRY]->pName,
-                                       pStages[MESA_SHADER_GEOMETRY]->pSpecializationInfo);
+   if (stages[MESA_SHADER_GEOMETRY].entrypoint) {
+      result = anv_pipeline_compile_gs(pipeline, cache,
+                                       &stages[MESA_SHADER_GEOMETRY]);
       if (result != VK_SUCCESS)
          goto compile_fail;
    }
 
-   if (modules[MESA_SHADER_FRAGMENT]) {
+   if (stages[MESA_SHADER_FRAGMENT].entrypoint) {
       result = anv_pipeline_compile_fs(pipeline, cache, pCreateInfo,
-                                       modules[MESA_SHADER_FRAGMENT],
-                                       pStages[MESA_SHADER_FRAGMENT]->pName,
-                                       pStages[MESA_SHADER_FRAGMENT]->pSpecializationInfo);
+                                       &stages[MESA_SHADER_FRAGMENT]);
       if (result != VK_SUCCESS)
          goto compile_fail;
    }
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 8de5103..b1f95c1 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -2183,7 +2183,7 @@ VkResult
 anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
                         struct anv_pipeline_cache *cache,
                         const VkComputePipelineCreateInfo *info,
-                        struct anv_shader_module *module,
+                        const struct anv_shader_module *module,
                         const char *entrypoint,
                         const VkSpecializationInfo *spec_info);
 
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list