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: 1dacea10f3 ("anv: implement caching for ray tracing pipelines")

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31298>
This commit is contained in:
Iván Briano 2024-09-20 19:18:58 -07:00 committed by Marge Bot
parent 1a45c8827b
commit 2e1c278e3d

View file

@ -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,