vulkan/pipeline_cache: implement vk_pipeline_cache_create_and_insert_object()
authorDaniel Schürmann <daniel@schuermann.dev>
Thu, 16 Mar 2023 19:05:36 +0000 (20:05 +0100)
committerMarge Bot <emma+marge@anholt.net>
Mon, 10 Apr 2023 09:14:30 +0000 (09:14 +0000)
This function directly inserts the serialized data into the disk cache
before calling deserialize() and inserting into the pipeline cache.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21967>

src/vulkan/runtime/vk_pipeline_cache.c
src/vulkan/runtime/vk_pipeline_cache.h

index 44b954c..7e8c8c8 100644 (file)
@@ -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,
index d0caba3..99e2b1d 100644 (file)
@@ -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,