diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c index 85f9441f3cc..5aa9d8ec32d 100644 --- a/src/amd/vulkan/radv_pipeline_cache.c +++ b/src/amd/vulkan/radv_pipeline_cache.c @@ -15,6 +15,8 @@ #include "radv_debug.h" #include "radv_descriptor_set.h" #include "radv_pipeline.h" +#include "radv_pipeline_compute.h" +#include "radv_pipeline_graphics.h" #include "radv_pipeline_rt.h" #include "radv_shader.h" #include "vk_pipeline.h" @@ -310,9 +312,9 @@ const struct vk_pipeline_cache_object_ops radv_pipeline_ops = { .destroy = radv_pipeline_cache_object_destroy, }; -bool -radv_pipeline_cache_search(struct radv_device *device, struct vk_pipeline_cache *cache, struct radv_pipeline *pipeline, - bool *found_in_application_cache) +static struct radv_pipeline_cache_object * +radv_pipeline_cache_object_search(struct radv_device *device, struct vk_pipeline_cache *cache, + const unsigned char *sha1, bool *found_in_application_cache) { *found_in_application_cache = false; @@ -326,25 +328,53 @@ radv_pipeline_cache_search(struct radv_device *device, struct vk_pipeline_cache } struct vk_pipeline_cache_object *object = - vk_pipeline_cache_lookup_object(cache, pipeline->sha1, SHA1_DIGEST_LENGTH, &radv_pipeline_ops, found); + vk_pipeline_cache_lookup_object(cache, sha1, SHA1_DIGEST_LENGTH, &radv_pipeline_ops, found); if (!object) return false; - struct radv_pipeline_cache_object *pipeline_obj = container_of(object, struct radv_pipeline_cache_object, base); + return container_of(object, struct radv_pipeline_cache_object, base); +} + +bool +radv_graphics_pipeline_cache_search(struct radv_device *device, struct vk_pipeline_cache *cache, + struct radv_graphics_pipeline *pipeline, bool *found_in_application_cache) +{ + struct radv_pipeline_cache_object *pipeline_obj; + + pipeline_obj = radv_pipeline_cache_object_search(device, cache, pipeline->base.sha1, found_in_application_cache); + if (!pipeline_obj) + return false; for (unsigned i = 0; i < pipeline_obj->num_shaders; i++) { gl_shader_stage s = pipeline_obj->shaders[i]->info.stage; if (s == MESA_SHADER_VERTEX && i > 0) { /* The GS copy-shader is a VS placed after all other stages */ - assert(i == pipeline_obj->num_shaders - 1 && pipeline->shaders[MESA_SHADER_GEOMETRY]); - pipeline->gs_copy_shader = radv_shader_ref(pipeline_obj->shaders[i]); + assert(i == pipeline_obj->num_shaders - 1 && pipeline->base.shaders[MESA_SHADER_GEOMETRY]); + pipeline->base.gs_copy_shader = radv_shader_ref(pipeline_obj->shaders[i]); } else { - pipeline->shaders[s] = radv_shader_ref(pipeline_obj->shaders[i]); + pipeline->base.shaders[s] = radv_shader_ref(pipeline_obj->shaders[i]); } } - pipeline->cache_object = object; + pipeline->base.cache_object = &pipeline_obj->base; + return true; +} + +bool +radv_compute_pipeline_cache_search(struct radv_device *device, struct vk_pipeline_cache *cache, + struct radv_compute_pipeline *pipeline, bool *found_in_application_cache) +{ + struct radv_pipeline_cache_object *pipeline_obj; + + pipeline_obj = radv_pipeline_cache_object_search(device, cache, pipeline->base.sha1, found_in_application_cache); + if (!pipeline_obj) + return false; + + assert(pipeline_obj->num_shaders == 1); + pipeline->base.shaders[MESA_SHADER_COMPUTE] = radv_shader_ref(pipeline_obj->shaders[0]); + + pipeline->base.cache_object = &pipeline_obj->base; return true; } @@ -400,24 +430,13 @@ radv_ray_tracing_pipeline_cache_search(struct radv_device *device, struct vk_pip struct radv_ray_tracing_pipeline *pipeline, bool *found_in_application_cache) { - *found_in_application_cache = false; + struct radv_pipeline_cache_object *pipeline_obj; - if (device->cache_disabled) + pipeline_obj = + radv_pipeline_cache_object_search(device, cache, pipeline->base.base.sha1, found_in_application_cache); + if (!pipeline_obj) return false; - bool *found = found_in_application_cache; - if (!cache) { - cache = device->mem_cache; - found = NULL; - } - - struct vk_pipeline_cache_object *object = - vk_pipeline_cache_lookup_object(cache, pipeline->base.base.sha1, SHA1_DIGEST_LENGTH, &radv_pipeline_ops, found); - - if (!object) - return false; - - struct radv_pipeline_cache_object *pipeline_obj = container_of(object, struct radv_pipeline_cache_object, base); struct radv_ray_tracing_pipeline_cache_data *data = pipeline_obj->data; bool is_library = pipeline->base.base.create_flags & VK_PIPELINE_CREATE_2_LIBRARY_BIT_KHR; @@ -442,7 +461,7 @@ radv_ray_tracing_pipeline_cache_search(struct radv_device *device, struct vk_pip assert(idx == pipeline_obj->num_shaders); - pipeline->base.base.cache_object = object; + pipeline->base.base.cache_object = &pipeline_obj->base; return complete; } diff --git a/src/amd/vulkan/radv_pipeline_cache.h b/src/amd/vulkan/radv_pipeline_cache.h index 87682bdbbad..5aecc2a5de9 100644 --- a/src/amd/vulkan/radv_pipeline_cache.h +++ b/src/amd/vulkan/radv_pipeline_cache.h @@ -23,6 +23,8 @@ struct radv_pipeline; struct radv_pipeline_layout; struct radv_ray_tracing_group; struct radv_ray_tracing_pipeline; +struct radv_graphics_pipeline; +struct radv_compute_pipeline; struct radv_ray_tracing_stage; struct radv_shader_binary; struct radv_shader_stage; @@ -43,8 +45,11 @@ void radv_hash_rt_shaders(const struct radv_device *device, unsigned char *hash, struct radv_shader *radv_shader_create(struct radv_device *device, struct vk_pipeline_cache *cache, const struct radv_shader_binary *binary, bool skip_cache); -bool radv_pipeline_cache_search(struct radv_device *device, struct vk_pipeline_cache *cache, - struct radv_pipeline *pipeline, bool *found_in_application_cache); +bool radv_graphics_pipeline_cache_search(struct radv_device *device, struct vk_pipeline_cache *cache, + struct radv_graphics_pipeline *pipeline, bool *found_in_application_cache); + +bool radv_compute_pipeline_cache_search(struct radv_device *device, struct vk_pipeline_cache *cache, + struct radv_compute_pipeline *pipeline, bool *found_in_application_cache); void radv_pipeline_cache_insert(struct radv_device *device, struct vk_pipeline_cache *cache, struct radv_pipeline *pipeline); diff --git a/src/amd/vulkan/radv_pipeline_compute.c b/src/amd/vulkan/radv_pipeline_compute.c index a8b90686c65..9647aeebfd7 100644 --- a/src/amd/vulkan/radv_pipeline_compute.c +++ b/src/amd/vulkan/radv_pipeline_compute.c @@ -243,7 +243,8 @@ radv_compute_pipeline_compile(const VkComputePipelineCreateInfo *pCreateInfo, st } bool found_in_application_cache = true; - if (!skip_shaders_cache && radv_pipeline_cache_search(device, cache, &pipeline->base, &found_in_application_cache)) { + if (!skip_shaders_cache && + radv_compute_pipeline_cache_search(device, cache, pipeline, &found_in_application_cache)) { if (found_in_application_cache) pipeline_feedback.flags |= VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT; result = VK_SUCCESS; diff --git a/src/amd/vulkan/radv_pipeline_graphics.c b/src/amd/vulkan/radv_pipeline_graphics.c index d19b7bde736..033bc913e8a 100644 --- a/src/amd/vulkan/radv_pipeline_graphics.c +++ b/src/amd/vulkan/radv_pipeline_graphics.c @@ -2674,7 +2674,8 @@ radv_graphics_pipeline_compile(struct radv_graphics_pipeline *pipeline, const Vk } bool found_in_application_cache = true; - if (!skip_shaders_cache && radv_pipeline_cache_search(device, cache, &pipeline->base, &found_in_application_cache)) { + if (!skip_shaders_cache && + radv_graphics_pipeline_cache_search(device, cache, pipeline, &found_in_application_cache)) { if (found_in_application_cache) pipeline_feedback.flags |= VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT;