From 0f46e279ba1c74924d81ea7dcf77d94e159820d3 Mon Sep 17 00:00:00 2001 From: Echo J Date: Mon, 22 Apr 2024 10:38:08 +0300 Subject: [PATCH] vulkan: Add implicit pipeline caching support This mirrors RADV's pipeline behavior (which is more performant when programs like DXVK don't use the pipeline cache functionality) Drivers need to set the implicit cache variable to use this though (the next patch will enable this for NVK) Reviewed-by: Faith Ekstrand Part-of: --- src/vulkan/runtime/vk_device.c | 1 + src/vulkan/runtime/vk_device.h | 3 +++ src/vulkan/runtime/vk_pipeline.c | 12 ++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/vulkan/runtime/vk_device.c b/src/vulkan/runtime/vk_device.c index d4aca6803b5..31cb331e9ab 100644 --- a/src/vulkan/runtime/vk_device.c +++ b/src/vulkan/runtime/vk_device.c @@ -150,6 +150,7 @@ vk_device_init(struct vk_device *device, list_inithead(&device->queues); device->drm_fd = -1; + device->mem_cache = NULL; device->timeline_mode = get_timeline_mode(physical_device); diff --git a/src/vulkan/runtime/vk_device.h b/src/vulkan/runtime/vk_device.h index 5bdd3a3ddd8..37e56771062 100644 --- a/src/vulkan/runtime/vk_device.h +++ b/src/vulkan/runtime/vk_device.h @@ -195,6 +195,9 @@ struct vk_device { /* Set by vk_device_set_drm_fd() */ int drm_fd; + /** Implicit pipeline cache, or NULL */ + struct vk_pipeline_cache *mem_cache; + /** An enum describing how timeline semaphores work */ enum vk_device_timeline_mode { /** Timeline semaphores are not supported */ diff --git a/src/vulkan/runtime/vk_pipeline.c b/src/vulkan/runtime/vk_pipeline.c index 421afc2ca89..a22f682ecb9 100644 --- a/src/vulkan/runtime/vk_pipeline.c +++ b/src/vulkan/runtime/vk_pipeline.c @@ -1267,7 +1267,7 @@ vk_graphics_pipeline_compile_shaders(struct vk_device *device, all_cache_hits = false; } - if (all_cache_hits) { + if (all_cache_hits && cache != device->mem_cache) { /* The pipeline cache only really helps if we hit for everything * in the partition. Otherwise, we have to go re-compile it all * anyway. @@ -1798,6 +1798,10 @@ vk_common_CreateGraphicsPipelines(VkDevice _device, VK_FROM_HANDLE(vk_pipeline_cache, cache, pipelineCache); VkResult first_error_or_success = VK_SUCCESS; + /* Use implicit pipeline cache if there's no cache set */ + if (!cache && device->mem_cache) + cache = device->mem_cache; + /* From the Vulkan 1.3.274 spec: * * "When attempting to create many pipelines in a single command, it is @@ -2092,7 +2096,7 @@ vk_create_compute_pipeline(struct vk_device *device, .flags = VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT, .duration = pipeline_end - pipeline_start, }; - if (cache_hit) { + if (cache_hit && cache != device->mem_cache) { pipeline_feedback.flags |= VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT; } @@ -2128,6 +2132,10 @@ vk_common_CreateComputePipelines(VkDevice _device, VK_FROM_HANDLE(vk_pipeline_cache, cache, pipelineCache); VkResult first_error_or_success = VK_SUCCESS; + /* Use implicit pipeline cache if there's no cache set */ + if (!cache && device->mem_cache) + cache = device->mem_cache; + /* From the Vulkan 1.3.274 spec: * * "When attempting to create many pipelines in a single command, it is