From f524f91d6fabf77f46f92f4ae3fb5a5ac57b20d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 16 Mar 2023 20:05:36 +0100 Subject: [PATCH] vulkan/pipeline_cache: implement vk_pipeline_cache_create_and_insert_object() This function directly inserts the serialized data into the disk cache before calling deserialize() and inserting into the pipeline cache. Part-of: --- src/vulkan/runtime/vk_pipeline_cache.c | 25 +++++++++++++++++++++++++ src/vulkan/runtime/vk_pipeline_cache.h | 17 +++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/vulkan/runtime/vk_pipeline_cache.c b/src/vulkan/runtime/vk_pipeline_cache.c index 44b954c8f5f..7e8c8c8c786 100644 --- a/src/vulkan/runtime/vk_pipeline_cache.c +++ b/src/vulkan/runtime/vk_pipeline_cache.c @@ -452,6 +452,31 @@ vk_pipeline_cache_add_object(struct vk_pipeline_cache *cache, return inserted; } +struct vk_pipeline_cache_object * +vk_pipeline_cache_create_and_insert_object(struct vk_pipeline_cache *cache, + const void *key_data, uint32_t key_size, + const void *data, size_t data_size, + const struct vk_pipeline_cache_object_ops *ops) +{ +#ifdef ENABLE_SHADER_CACHE + struct disk_cache *disk_cache = cache->base.device->physical->disk_cache; + if (disk_cache) { + cache_key cache_key; + disk_cache_compute_key(disk_cache, key_data, key_size, cache_key); + disk_cache_put(disk_cache, cache_key, data, data_size, NULL); + } +#endif + + struct vk_pipeline_cache_object *object = + vk_pipeline_cache_object_deserialize(cache, key_data, key_size, data, + data_size, ops); + + if (object) + object = vk_pipeline_cache_insert_object(cache, object); + + return object; +} + nir_shader * vk_pipeline_cache_lookup_nir(struct vk_pipeline_cache *cache, const void *key_data, size_t key_size, diff --git a/src/vulkan/runtime/vk_pipeline_cache.h b/src/vulkan/runtime/vk_pipeline_cache.h index d0caba37fbb..99e2b1d186a 100644 --- a/src/vulkan/runtime/vk_pipeline_cache.h +++ b/src/vulkan/runtime/vk_pipeline_cache.h @@ -241,6 +241,23 @@ struct vk_pipeline_cache_object * MUST_CHECK vk_pipeline_cache_add_object(struct vk_pipeline_cache *cache, struct vk_pipeline_cache_object *object); +/** Creates and inserts an object into the pipeline cache + * + * This function takes serialized data and emplaces the deserialized object + * into the pipeline cache. It is the responsibility of the caller to + * specify a deserialize() function that properly initializes the object. + * + * This function can be used to avoid an extra serialize() step for + * disk-cache insertion. For the intended usage pattern, see + * vk_pipeline_cache_add_object(). + * + */ +struct vk_pipeline_cache_object * +vk_pipeline_cache_create_and_insert_object(struct vk_pipeline_cache *cache, + const void *key_data, uint32_t key_size, + const void *data, size_t data_size, + const struct vk_pipeline_cache_object_ops *ops); + struct nir_shader * vk_pipeline_cache_lookup_nir(struct vk_pipeline_cache *cache, const void *key_data, size_t key_size,