From 8f9b8af78250fe7644622580c53559caa81d155e Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Sat, 13 Jun 2020 13:57:32 -0500 Subject: [PATCH] anv: Add anv_pipeline_init/finish helpers This cleans up pipline create/destroy a bit after the compute/gfx split. Reviewed-by: Lionel Landwerlin Reviewed-by: Caio Marcelo de Oliveira Filho Part-of: --- src/intel/vulkan/anv_pipeline.c | 94 +++++++++++++++++++++----------- src/intel/vulkan/anv_private.h | 20 +++++-- src/intel/vulkan/genX_pipeline.c | 26 +++------ 3 files changed, 84 insertions(+), 56 deletions(-) diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index b3469518884..4d4898ec4af 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -299,6 +299,54 @@ anv_shader_compile_to_nir(struct anv_device *device, return nir; } +VkResult +anv_pipeline_init(struct anv_pipeline *pipeline, + struct anv_device *device, + enum anv_pipeline_type type, + VkPipelineCreateFlags flags, + const VkAllocationCallbacks *pAllocator) +{ + VkResult result; + + memset(pipeline, 0, sizeof(*pipeline)); + + vk_object_base_init(&device->vk, &pipeline->base, + VK_OBJECT_TYPE_PIPELINE); + pipeline->device = device; + + /* It's the job of the child class to provide actual backing storage for + * the batch by setting batch.start, batch.next, and batch.end. + */ + pipeline->batch.alloc = pAllocator ? pAllocator : &device->vk.alloc; + pipeline->batch.relocs = &pipeline->batch_relocs; + pipeline->batch.status = VK_SUCCESS; + + result = anv_reloc_list_init(&pipeline->batch_relocs, + pipeline->batch.alloc); + if (result != VK_SUCCESS) + return result; + + pipeline->mem_ctx = ralloc_context(NULL); + + pipeline->type = type; + pipeline->flags = flags; + + util_dynarray_init(&pipeline->executables, pipeline->mem_ctx); + + return VK_SUCCESS; +} + +void +anv_pipeline_finish(struct anv_pipeline *pipeline, + struct anv_device *device, + const VkAllocationCallbacks *pAllocator) +{ + anv_reloc_list_finish(&pipeline->batch_relocs, + pAllocator ? pAllocator : &device->vk.alloc); + ralloc_free(pipeline->mem_ctx); + vk_object_base_finish(&pipeline->base); +} + void anv_DestroyPipeline( VkDevice _device, VkPipeline _pipeline, @@ -310,11 +358,6 @@ void anv_DestroyPipeline( if (!pipeline) return; - anv_reloc_list_finish(&pipeline->batch_relocs, - pAllocator ? pAllocator : &device->vk.alloc); - - ralloc_free(pipeline->mem_ctx); - switch (pipeline->type) { case ANV_PIPELINE_GRAPHICS: { struct anv_graphics_pipeline *gfx_pipeline = @@ -344,7 +387,7 @@ void anv_DestroyPipeline( unreachable("invalid pipeline type"); } - vk_object_base_finish(&pipeline->base); + anv_pipeline_finish(pipeline, device, pAllocator); vk_free2(&device->vk.alloc, pAllocator, pipeline); } @@ -1974,40 +2017,28 @@ anv_pipeline_setup_l3_config(struct anv_pipeline *pipeline, bool needs_slm) } VkResult -anv_pipeline_init(struct anv_graphics_pipeline *pipeline, - struct anv_device *device, - struct anv_pipeline_cache *cache, - const VkGraphicsPipelineCreateInfo *pCreateInfo, - const VkAllocationCallbacks *alloc) +anv_graphics_pipeline_init(struct anv_graphics_pipeline *pipeline, + struct anv_device *device, + struct anv_pipeline_cache *cache, + const VkGraphicsPipelineCreateInfo *pCreateInfo, + const VkAllocationCallbacks *alloc) { VkResult result; anv_pipeline_validate_create_info(pCreateInfo); - if (alloc == NULL) - alloc = &device->vk.alloc; - - vk_object_base_init(&device->vk, &pipeline->base.base, - VK_OBJECT_TYPE_PIPELINE); - pipeline->base.device = device; - pipeline->base.type = ANV_PIPELINE_GRAPHICS; - - ANV_FROM_HANDLE(anv_render_pass, render_pass, pCreateInfo->renderPass); - assert(pCreateInfo->subpass < render_pass->subpass_count); - pipeline->subpass = &render_pass->subpasses[pCreateInfo->subpass]; - - result = anv_reloc_list_init(&pipeline->base.batch_relocs, alloc); + result = anv_pipeline_init(&pipeline->base, device, + ANV_PIPELINE_GRAPHICS, pCreateInfo->flags, + alloc); if (result != VK_SUCCESS) return result; - pipeline->base.batch.alloc = alloc; - pipeline->base.batch.relocs = &pipeline->base.batch_relocs; - pipeline->base.batch.status = VK_SUCCESS; anv_batch_set_storage(&pipeline->base.batch, ANV_NULL_ADDRESS, pipeline->batch_data, sizeof(pipeline->batch_data)); - pipeline->base.mem_ctx = ralloc_context(NULL); - pipeline->base.flags = pCreateInfo->flags; + ANV_FROM_HANDLE(anv_render_pass, render_pass, pCreateInfo->renderPass); + assert(pCreateInfo->subpass < render_pass->subpass_count); + pipeline->subpass = &render_pass->subpasses[pCreateInfo->subpass]; assert(pCreateInfo->pRasterizationState); @@ -2034,12 +2065,9 @@ anv_pipeline_init(struct anv_graphics_pipeline *pipeline, */ memset(pipeline->shaders, 0, sizeof(pipeline->shaders)); - util_dynarray_init(&pipeline->base.executables, pipeline->base.mem_ctx); - result = anv_pipeline_compile_graphics(pipeline, cache, pCreateInfo); if (result != VK_SUCCESS) { - ralloc_free(pipeline->base.mem_ctx); - anv_reloc_list_finish(&pipeline->base.batch_relocs, alloc); + anv_pipeline_finish(&pipeline->base, device, alloc); return result; } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index be0cc9bc59e..5f9bff5d5aa 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -3409,10 +3409,22 @@ anv_pipeline_get_last_vue_prog_data(const struct anv_graphics_pipeline *pipeline } VkResult -anv_pipeline_init(struct anv_graphics_pipeline *pipeline, struct anv_device *device, - struct anv_pipeline_cache *cache, - const VkGraphicsPipelineCreateInfo *pCreateInfo, - const VkAllocationCallbacks *alloc); +anv_pipeline_init(struct anv_pipeline *pipeline, + struct anv_device *device, + enum anv_pipeline_type type, + VkPipelineCreateFlags flags, + const VkAllocationCallbacks *pAllocator); + +void +anv_pipeline_finish(struct anv_pipeline *pipeline, + struct anv_device *device, + const VkAllocationCallbacks *pAllocator); + +VkResult +anv_graphics_pipeline_init(struct anv_graphics_pipeline *pipeline, struct anv_device *device, + struct anv_pipeline_cache *cache, + const VkGraphicsPipelineCreateInfo *pCreateInfo, + const VkAllocationCallbacks *alloc); VkResult anv_pipeline_compile_cs(struct anv_compute_pipeline *pipeline, diff --git a/src/intel/vulkan/genX_pipeline.c b/src/intel/vulkan/genX_pipeline.c index d83716bfedf..cfb9fedb201 100644 --- a/src/intel/vulkan/genX_pipeline.c +++ b/src/intel/vulkan/genX_pipeline.c @@ -2168,8 +2168,8 @@ genX(graphics_pipeline_create)( if (pipeline == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); - result = anv_pipeline_init(pipeline, device, cache, - pCreateInfo, pAllocator); + result = anv_graphics_pipeline_init(pipeline, device, cache, + pCreateInfo, pAllocator); if (result != VK_SUCCESS) { vk_free2(&device->vk.alloc, pAllocator, pipeline); return result; @@ -2285,38 +2285,26 @@ compute_pipeline_create( if (pipeline == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); - vk_object_base_init(&device->vk, &pipeline->base.base, - VK_OBJECT_TYPE_PIPELINE); - pipeline->base.device = device; - pipeline->base.type = ANV_PIPELINE_COMPUTE; - - const VkAllocationCallbacks *alloc = - pAllocator ? pAllocator : &device->vk.alloc; - - result = anv_reloc_list_init(&pipeline->base.batch_relocs, alloc); + result = anv_pipeline_init(&pipeline->base, device, + ANV_PIPELINE_COMPUTE, pCreateInfo->flags, + pAllocator); if (result != VK_SUCCESS) { vk_free2(&device->vk.alloc, pAllocator, pipeline); return result; } - pipeline->base.batch.alloc = alloc; - pipeline->base.batch.relocs = &pipeline->base.batch_relocs; - pipeline->base.batch.status = VK_SUCCESS; + anv_batch_set_storage(&pipeline->base.batch, ANV_NULL_ADDRESS, pipeline->batch_data, sizeof(pipeline->batch_data)); - pipeline->base.mem_ctx = ralloc_context(NULL); - pipeline->base.flags = pCreateInfo->flags; pipeline->cs = NULL; - util_dynarray_init(&pipeline->base.executables, pipeline->base.mem_ctx); - assert(pCreateInfo->stage.stage == VK_SHADER_STAGE_COMPUTE_BIT); ANV_FROM_HANDLE(anv_shader_module, module, pCreateInfo->stage.module); result = anv_pipeline_compile_cs(pipeline, cache, pCreateInfo, module, pCreateInfo->stage.pName, pCreateInfo->stage.pSpecializationInfo); if (result != VK_SUCCESS) { - ralloc_free(pipeline->base.mem_ctx); + anv_pipeline_finish(&pipeline->base, device, pAllocator); vk_free2(&device->vk.alloc, pAllocator, pipeline); return result; } -- 2.30.2