anv: Use a dynamic array for storing executables in pipeline
[mesa.git] / src / intel / vulkan / anv_pipeline.c
index 0fcbe745f4b95f395d20f785889b5464bcf8c1e8..9f14fb88f821d7b2727cd0e570f13af41ab743ee 100644 (file)
@@ -663,7 +663,7 @@ anv_pipeline_lower_nir(struct anv_pipeline *pipeline,
 
    NIR_PASS_V(nir, anv_nir_lower_ycbcr_textures, layout);
 
-   if (nir->info.stage != MESA_SHADER_COMPUTE)
+   if (pipeline->type == ANV_PIPELINE_GRAPHICS)
       NIR_PASS_V(nir, anv_nir_lower_multiview, pipeline->subpass->view_mask);
 
    nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
@@ -1051,13 +1051,14 @@ anv_pipeline_add_executable(struct anv_pipeline *pipeline,
       free(stream_data);
    }
 
-   pipeline->executables[pipeline->num_executables++] =
-      (struct anv_pipeline_executable) {
-         .stage = stage->stage,
-         .stats = *stats,
-         .nir = nir,
-         .disasm = disasm,
-      };
+   const struct anv_pipeline_executable exe = {
+      .stage = stage->stage,
+      .stats = *stats,
+      .nir = nir,
+      .disasm = disasm,
+   };
+   util_dynarray_append(&pipeline->executables,
+                        struct anv_pipeline_executable, exe);
 }
 
 static void
@@ -1830,6 +1831,7 @@ anv_pipeline_init(struct anv_pipeline *pipeline,
       alloc = &device->alloc;
 
    pipeline->device = device;
+   pipeline->type = ANV_PIPELINE_GRAPHICS;
 
    ANV_FROM_HANDLE(anv_render_pass, render_pass, pCreateInfo->renderPass);
    assert(pCreateInfo->subpass < render_pass->subpass_count);
@@ -1872,7 +1874,8 @@ anv_pipeline_init(struct anv_pipeline *pipeline,
     * of various prog_data pointers.  Make them NULL by default.
     */
    memset(pipeline->shaders, 0, sizeof(pipeline->shaders));
-   pipeline->num_executables = 0;
+
+   util_dynarray_init(&pipeline->executables, pipeline->mem_ctx);
 
    result = anv_pipeline_compile_graphics(pipeline, cache, pCreateInfo);
    if (result != VK_SUCCESS) {
@@ -1975,12 +1978,12 @@ VkResult anv_GetPipelineExecutablePropertiesKHR(
    ANV_FROM_HANDLE(anv_pipeline, pipeline, pPipelineInfo->pipeline);
    VK_OUTARRAY_MAKE(out, pProperties, pExecutableCount);
 
-   for (uint32_t i = 0; i < pipeline->num_executables; i++) {
+   util_dynarray_foreach (&pipeline->executables, struct anv_pipeline_executable, exe) {
       vk_outarray_append(&out, props) {
-         gl_shader_stage stage = pipeline->executables[i].stage;
+         gl_shader_stage stage = exe->stage;
          props->stages = mesa_to_vk_shader_stage(stage);
 
-         unsigned simd_width = pipeline->executables[i].stats.dispatch_width;
+         unsigned simd_width = exe->stats.dispatch_width;
          if (stage == MESA_SHADER_FRAGMENT) {
             WRITE_STR(props->name, "%s%d %s",
                       simd_width ? "SIMD" : "vec",
@@ -2004,6 +2007,15 @@ VkResult anv_GetPipelineExecutablePropertiesKHR(
    return vk_outarray_status(&out);
 }
 
+static const struct anv_pipeline_executable *
+anv_pipeline_get_executable(struct anv_pipeline *pipeline, uint32_t index)
+{
+   assert(index < util_dynarray_num_elements(&pipeline->executables,
+                                             struct anv_pipeline_executable));
+   return util_dynarray_element(
+      &pipeline->executables, struct anv_pipeline_executable, index);
+}
+
 VkResult anv_GetPipelineExecutableStatisticsKHR(
     VkDevice                                    device,
     const VkPipelineExecutableInfoKHR*          pExecutableInfo,
@@ -2013,9 +2025,8 @@ VkResult anv_GetPipelineExecutableStatisticsKHR(
    ANV_FROM_HANDLE(anv_pipeline, pipeline, pExecutableInfo->pipeline);
    VK_OUTARRAY_MAKE(out, pStatistics, pStatisticCount);
 
-   assert(pExecutableInfo->executableIndex < pipeline->num_executables);
    const struct anv_pipeline_executable *exe =
-      &pipeline->executables[pExecutableInfo->executableIndex];
+      anv_pipeline_get_executable(pipeline, pExecutableInfo->executableIndex);
    const struct brw_stage_prog_data *prog_data =
       pipeline->shaders[exe->stage]->prog_data;
 
@@ -2126,9 +2137,8 @@ VkResult anv_GetPipelineExecutableInternalRepresentationsKHR(
                     pInternalRepresentationCount);
    bool incomplete_text = false;
 
-   assert(pExecutableInfo->executableIndex < pipeline->num_executables);
    const struct anv_pipeline_executable *exe =
-      &pipeline->executables[pExecutableInfo->executableIndex];
+      anv_pipeline_get_executable(pipeline, pExecutableInfo->executableIndex);
 
    if (exe->nir) {
       vk_outarray_append(&out, ir) {