From 2e1c278e3d2e379a6d566d5aa75d7c1739886430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Briano?= Date: Fri, 20 Sep 2024 19:18:58 -0700 Subject: [PATCH] anv: skip rt pipeline compile if we found all shaders When no pipeline cache is provided by the application and we rely on the internal one, cache hits are not counted as such. This was causing us to return COMPILE_REQUIRED on some cases where all shaders had been found in the cache, as well as some unnecessary extra processing in the case that we did have to compile the pipeline. Fixes: 1dacea10f35 ("anv: implement caching for ray tracing pipelines") Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_pipeline.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 061ddd13464..26ad7bfa390 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -3621,9 +3621,10 @@ static bool anv_ray_tracing_pipeline_load_cached_shaders(struct anv_ray_tracing_pipeline *pipeline, struct vk_pipeline_cache *cache, const VkRayTracingPipelineCreateInfoKHR *info, - struct anv_pipeline_stage *stages) + struct anv_pipeline_stage *stages, + VkPipelineCreationFeedback *pipeline_feedback) { - uint32_t shaders = 0, cache_hits = 0; + uint32_t shaders = 0, found = 0, cache_hits = 0; for (uint32_t i = 0; i < info->stageCount; i++) { if (stages[i].info == NULL) continue; @@ -3643,13 +3644,20 @@ anv_ray_tracing_pipeline_load_cached_shaders(struct anv_ray_tracing_pipeline *pi VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT; } - if (stages[i].bin != NULL) + if (stages[i].bin != NULL) { + found++; anv_pipeline_add_executables(&pipeline->base, &stages[i]); + } stages[i].feedback.duration += os_time_get_nano() - stage_start; } - return cache_hits == shaders; + if (cache_hits == shaders) { + pipeline_feedback->flags |= + VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT; + } + + return found == shaders; } static VkResult @@ -3671,9 +3679,8 @@ anv_pipeline_compile_ray_tracing(struct anv_ray_tracing_pipeline *pipeline, (pipeline->base.flags & VK_PIPELINE_CREATE_CAPTURE_INTERNAL_REPRESENTATIONS_BIT_KHR); if (!skip_cache_lookup && - anv_ray_tracing_pipeline_load_cached_shaders(pipeline, cache, info, stages)) { - pipeline_feedback.flags |= - VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT; + anv_ray_tracing_pipeline_load_cached_shaders(pipeline, cache, info, stages, + &pipeline_feedback)) { goto done; } @@ -3684,6 +3691,15 @@ anv_pipeline_compile_ray_tracing(struct anv_ray_tracing_pipeline *pipeline, if (stages[i].info == NULL) continue; + /* Intersection and any-hit need to fetch the nir always, + * so that they can be handled correctly below in the group section. + * For the other stages, if we found them in the cache, skip this part. + */ + if (!(stages[i].stage == MESA_SHADER_INTERSECTION || + stages[i].stage == MESA_SHADER_ANY_HIT) && + stages[i].bin != NULL) + continue; + int64_t stage_start = os_time_get_nano(); VkResult result = anv_pipeline_stage_get_nir(&pipeline->base, cache,