diff --git a/src/intel/vulkan/anv_genX.h b/src/intel/vulkan/anv_genX.h index 95b9eda7a90..88e7258651f 100644 --- a/src/intel/vulkan/anv_genX.h +++ b/src/intel/vulkan/anv_genX.h @@ -38,6 +38,8 @@ struct intel_sample_positions; +typedef struct VkRenderingSelfDependencyInfoMESA VkRenderingSelfDependencyInfoMESA; + extern const uint32_t genX(vk_to_intel_cullmode)[]; extern const uint32_t genX(vk_to_intel_front_face)[]; @@ -166,3 +168,9 @@ genX(ms_rasterization_mode)(struct anv_graphics_pipeline *pipeline, VkPolygonMode genX(raster_polygon_mode)(struct anv_graphics_pipeline *pipeline, VkPrimitiveTopology primitive_topology); + +void +genX(graphics_pipeline_emit)(struct anv_graphics_pipeline *pipeline, + const VkGraphicsPipelineCreateInfo *pCreateInfo, + const VkPipelineRenderingCreateInfo *rendering_info, + const VkRenderingSelfDependencyInfoMESA *rsd_info); diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 30bdae58cd4..cc5d4d98dc1 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -2320,7 +2320,7 @@ vk_line_rasterization_mode(const VkPipelineRasterizationLineStateCreateInfoEXT * return line_mode; } -VkResult +static VkResult anv_graphics_pipeline_init(struct anv_graphics_pipeline *pipeline, struct anv_device *device, struct vk_pipeline_cache *cache, @@ -2493,6 +2493,105 @@ anv_graphics_pipeline_init(struct anv_graphics_pipeline *pipeline, return VK_SUCCESS; } +static VkResult +anv_graphics_pipeline_create(struct anv_device *device, + struct vk_pipeline_cache *cache, + const VkGraphicsPipelineCreateInfo *pCreateInfo, + const VkAllocationCallbacks *pAllocator, + VkPipeline *pPipeline) +{ + struct anv_graphics_pipeline *pipeline; + VkResult result; + + assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO); + + pipeline = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*pipeline), 8, + VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + if (pipeline == NULL) + return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); + + /* We'll use these as defaults if we don't have pipeline rendering or + * self-dependency structs. Saves us some NULL checks. + */ + VkRenderingSelfDependencyInfoMESA rsd_info_tmp = { + .sType = VK_STRUCTURE_TYPE_RENDERING_SELF_DEPENDENCY_INFO_MESA, + }; + VkPipelineRenderingCreateInfo rendering_info_tmp = { + .sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO, + .pNext = &rsd_info_tmp, + }; + + const VkPipelineRenderingCreateInfo *rendering_info = + vk_get_pipeline_rendering_create_info(pCreateInfo); + if (rendering_info == NULL) + rendering_info = &rendering_info_tmp; + + const VkRenderingSelfDependencyInfoMESA *rsd_info = + vk_find_struct_const(rendering_info->pNext, + RENDERING_SELF_DEPENDENCY_INFO_MESA); + if (rsd_info == NULL) + rsd_info = &rsd_info_tmp; + + result = anv_graphics_pipeline_init(pipeline, device, cache, + pCreateInfo, rendering_info, + pAllocator); + if (result != VK_SUCCESS) { + vk_free2(&device->vk.alloc, pAllocator, pipeline); + return result; + } + + anv_genX(&device->info, graphics_pipeline_emit)(pipeline, + pCreateInfo, + rendering_info, + rsd_info); + + *pPipeline = anv_pipeline_to_handle(&pipeline->base); + + return pipeline->base.batch.status; +} + +VkResult anv_CreateGraphicsPipelines( + VkDevice _device, + VkPipelineCache pipelineCache, + uint32_t count, + const VkGraphicsPipelineCreateInfo* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkPipeline* pPipelines) +{ + ANV_FROM_HANDLE(anv_device, device, _device); + ANV_FROM_HANDLE(vk_pipeline_cache, pipeline_cache, pipelineCache); + + VkResult result = VK_SUCCESS; + + unsigned i; + for (i = 0; i < count; i++) { + VkResult res = anv_graphics_pipeline_create(device, + pipeline_cache, + &pCreateInfos[i], + pAllocator, &pPipelines[i]); + + if (res == VK_SUCCESS) + continue; + + /* Bail out on the first error != VK_PIPELINE_COMPILE_REQUIRED as it + * is not obvious what error should be report upon 2 different failures. + * */ + result = res; + if (res != VK_PIPELINE_COMPILE_REQUIRED) + break; + + pPipelines[i] = VK_NULL_HANDLE; + + if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT) + break; + } + + for (; i < count; i++) + pPipelines[i] = VK_NULL_HANDLE; + + return result; +} + static VkResult compile_upload_rt_shader(struct anv_ray_tracing_pipeline *pipeline, struct vk_pipeline_cache *cache, diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 3b5eb704340..7202799d66b 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -3542,13 +3542,6 @@ 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 vk_pipeline_cache *cache, - const VkGraphicsPipelineCreateInfo *pCreateInfo, - const VkPipelineRenderingCreateInfo *rendering_info, - const VkAllocationCallbacks *alloc); - VkResult anv_pipeline_compile_cs(struct anv_compute_pipeline *pipeline, struct vk_pipeline_cache *cache, diff --git a/src/intel/vulkan/genX_pipeline.c b/src/intel/vulkan/genX_pipeline.c index acdddfebf38..9ec9f329188 100644 --- a/src/intel/vulkan/genX_pipeline.c +++ b/src/intel/vulkan/genX_pipeline.c @@ -2654,57 +2654,12 @@ emit_mesh_state(struct anv_graphics_pipeline *pipeline) } #endif -static VkResult -genX(graphics_pipeline_create)( - VkDevice _device, - struct vk_pipeline_cache * cache, - const VkGraphicsPipelineCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkPipeline* pPipeline) +void +genX(graphics_pipeline_emit)(struct anv_graphics_pipeline *pipeline, + const VkGraphicsPipelineCreateInfo *pCreateInfo, + const VkPipelineRenderingCreateInfo *rendering_info, + const VkRenderingSelfDependencyInfoMESA *rsd_info) { - ANV_FROM_HANDLE(anv_device, device, _device); - struct anv_graphics_pipeline *pipeline; - VkResult result; - - assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO); - - pipeline = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*pipeline), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); - if (pipeline == NULL) - return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); - - /* We'll use these as defaults if we don't have pipeline rendering or - * self-dependency structs. Saves us some NULL checks. - */ - VkRenderingSelfDependencyInfoMESA rsd_info_tmp = { - .sType = VK_STRUCTURE_TYPE_RENDERING_SELF_DEPENDENCY_INFO_MESA, - }; - VkPipelineRenderingCreateInfo rendering_info_tmp = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO, - .pNext = &rsd_info_tmp, - }; - - const VkPipelineRenderingCreateInfo *rendering_info = - vk_get_pipeline_rendering_create_info(pCreateInfo); - if (rendering_info == NULL) - rendering_info = &rendering_info_tmp; - - const VkRenderingSelfDependencyInfoMESA *rsd_info = - vk_find_struct_const(rendering_info->pNext, - RENDERING_SELF_DEPENDENCY_INFO_MESA); - if (rsd_info == NULL) - rsd_info = &rsd_info_tmp; - - result = anv_graphics_pipeline_init(pipeline, device, cache, - pCreateInfo, rendering_info, - pAllocator); - if (result != VK_SUCCESS) { - vk_free2(&device->vk.alloc, pAllocator, pipeline); - if (result == VK_PIPELINE_COMPILE_REQUIRED) - *pPipeline = VK_NULL_HANDLE; - return result; - } - /* If rasterization is not enabled, various CreateInfo structs must be * ignored. */ @@ -2780,7 +2735,9 @@ genX(graphics_pipeline_create)( emit_3dstate_vf_statistics(pipeline); emit_3dstate_streamout(pipeline, pCreateInfo->pRasterizationState); + #if GFX_VERx10 >= 125 + const struct anv_device *device = pipeline->base.device; /* Disable Mesh. */ if (device->physical->vk.supported_extensions.NV_mesh_shader) { anv_batch_emit(&pipeline->base.batch, GENX(3DSTATE_MESH_CONTROL), zero); @@ -2810,10 +2767,6 @@ genX(graphics_pipeline_create)( #if GFX_VER >= 8 emit_3dstate_ps_extra(pipeline, pCreateInfo->pRasterizationState, rsd_info); #endif - - *pPipeline = anv_pipeline_to_handle(&pipeline->base); - - return pipeline->base.batch.status; } #if GFX_VERx10 >= 125 @@ -2989,45 +2942,6 @@ compute_pipeline_create( return pipeline->base.batch.status; } -VkResult genX(CreateGraphicsPipelines)( - VkDevice _device, - VkPipelineCache pipelineCache, - uint32_t count, - const VkGraphicsPipelineCreateInfo* pCreateInfos, - const VkAllocationCallbacks* pAllocator, - VkPipeline* pPipelines) -{ - VK_FROM_HANDLE(vk_pipeline_cache, pipeline_cache, pipelineCache); - - VkResult result = VK_SUCCESS; - - unsigned i; - for (i = 0; i < count; i++) { - VkResult res = genX(graphics_pipeline_create)(_device, - pipeline_cache, - &pCreateInfos[i], - pAllocator, &pPipelines[i]); - - if (res == VK_SUCCESS) - continue; - - /* Bail out on the first error != VK_PIPELINE_COMPILE_REQUIRED_EX as it - * is not obvious what error should be report upon 2 different failures. - * */ - result = res; - if (res != VK_PIPELINE_COMPILE_REQUIRED) - break; - - if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT) - break; - } - - for (; i < count; i++) - pPipelines[i] = VK_NULL_HANDLE; - - return result; -} - VkResult genX(CreateComputePipelines)( VkDevice _device, VkPipelineCache pipelineCache,