From 4f8327188bd9ce16ce9282aaffcbecdb1dc8d605 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Wed, 22 Oct 2025 17:06:03 -0400 Subject: [PATCH] panvk: Add an in-memory shader cache This one just hangs out and prevents unnecessary duplicate compilation. We set .weak_ref = true so it doesn't actually hold references forever. It just hangs onto any shaders that exist in some VkPipeline or VkShader somewhere. But if an app compiles a pipeline it already has, it will let us avoid a duplicate compile, even if the app doesn't provide a pipeline cache. Acked-by: Eric R. Smith Reviewed-by: Lars-Ivar Hesselberg Simonsen Part-of: --- src/panfrost/vulkan/panvk_vX_device.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/panfrost/vulkan/panvk_vX_device.c b/src/panfrost/vulkan/panvk_vX_device.c index 2706b42bc28..c2809256a3a 100644 --- a/src/panfrost/vulkan/panvk_vX_device.c +++ b/src/panfrost/vulkan/panvk_vX_device.c @@ -510,10 +510,19 @@ panvk_per_arch(create_device)(struct panvk_physical_device *physical_device, if (result != VK_SUCCESS) goto err_free_priv_bos; + struct vk_pipeline_cache_create_info cache_info = { + .weak_ref = true, + }; + device->vk.mem_cache = vk_pipeline_cache_create(&device->vk, &cache_info, NULL); + if (device->vk.mem_cache == NULL) { + result = VK_ERROR_OUT_OF_HOST_MEMORY; + goto err_free_precomp; + } + #if PAN_ARCH >= 10 result = panvk_per_arch(device_draw_context_init)(device); if (result != VK_SUCCESS) - goto err_free_precomp; + goto err_free_mem_cache; #endif result = panvk_meta_init(device); @@ -578,8 +587,10 @@ err_finish_queues: err_free_draw_ctx: #if PAN_ARCH >= 10 panvk_per_arch(device_draw_context_cleanup)(device); -err_free_precomp: +err_free_mem_cache: #endif + vk_pipeline_cache_destroy(device->vk.mem_cache, NULL); +err_free_precomp: panvk_precomp_cleanup(device); err_free_priv_bos: if (device->printf.bo) @@ -630,6 +641,7 @@ panvk_per_arch(destroy_device)(struct panvk_device *device, panvk_per_arch(device_draw_context_cleanup)(device); #endif panvk_meta_cleanup(device); + vk_pipeline_cache_destroy(device->vk.mem_cache, NULL); pan_kmod_bo_put(device->sparse_mem.blackhole); u_printf_destroy(&device->printf.ctx); panvk_priv_bo_unref(device->printf.bo);