Mesa (main): vulkan/pipeline_cache: Implement deserialize for raw objects
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed May 18 05:06:08 UTC 2022
Module: Mesa
Branch: main
Commit: d35e78bb853634da3ac6ea306797e770a875df94
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=d35e78bb853634da3ac6ea306797e770a875df94
Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date: Mon May 2 11:43:17 2022 -0500
vulkan/pipeline_cache: Implement deserialize for raw objects
When caching NIR, it's cached as a raw object because we cache the
serialized NIR. When it's then loaded from the disk cache later, we
fail to deserialize it because raw objects are a special case. There
are two callers of vk_pipeline_cache_object_deserialize(), one of which
has a special case for raw objects and the other is called only when
we've checked that it isn't a raw object. The special cases are
pointless; raw objects should deserialize themselves.
Fixes: 591da9877900 ("vulkan: Add a common VkPipelineCache implementation")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16281>
---
src/vulkan/runtime/vk_pipeline_cache.c | 43 ++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 12 deletions(-)
diff --git a/src/vulkan/runtime/vk_pipeline_cache.c b/src/vulkan/runtime/vk_pipeline_cache.c
index 6ed7a397203..b9a3c4c0e6c 100644
--- a/src/vulkan/runtime/vk_pipeline_cache.c
+++ b/src/vulkan/runtime/vk_pipeline_cache.c
@@ -44,6 +44,11 @@ struct raw_data_object {
size_t data_size;
};
+static struct raw_data_object *
+raw_data_object_create(struct vk_device *device,
+ const void *key_data, size_t key_size,
+ const void *data, size_t data_size);
+
static bool
raw_data_object_serialize(struct vk_pipeline_cache_object *object,
struct blob *blob)
@@ -56,6 +61,27 @@ raw_data_object_serialize(struct vk_pipeline_cache_object *object,
return true;
}
+static struct vk_pipeline_cache_object *
+raw_data_object_deserialize(struct vk_device *device,
+ const void *key_data,
+ size_t key_size,
+ struct blob_reader *blob)
+{
+ /* We consume the entire blob_reader. Each call to ops->deserialize()
+ * happens with a brand new blob reader for error checking anyway so we
+ * can assume the blob consumes the entire reader and we don't need to
+ * serialize the data size separately.
+ */
+ assert(blob->current < blob->end);
+ size_t data_size = blob->end - blob->current;
+ const void *data = blob_read_bytes(blob, data_size);
+
+ struct raw_data_object *data_obj =
+ raw_data_object_create(device, key_data, key_size, data, data_size);
+
+ return data_obj ? &data_obj->base : NULL;
+}
+
static void
raw_data_object_destroy(struct vk_pipeline_cache_object *object)
{
@@ -67,6 +93,7 @@ raw_data_object_destroy(struct vk_pipeline_cache_object *object)
static const struct vk_pipeline_cache_object_ops raw_data_object_ops = {
.serialize = raw_data_object_serialize,
+ .deserialize = raw_data_object_deserialize,
.destroy = raw_data_object_destroy,
};
@@ -527,18 +554,10 @@ vk_pipeline_cache_load(struct vk_pipeline_cache *cache,
const struct vk_pipeline_cache_object_ops *ops =
find_ops_for_type(cache->base.device->physical, type);
- struct vk_pipeline_cache_object *object;
- if (ops != NULL) {
- object = vk_pipeline_cache_object_deserialize(cache,
- key_data, key_size,
- data, data_size, ops);
- } else {
- struct raw_data_object *data_obj =
- raw_data_object_create(cache->base.device,
- key_data, key_size,
- data, data_size);
- object = data_obj != NULL ? &data_obj->base : NULL;
- }
+ struct vk_pipeline_cache_object *object =
+ vk_pipeline_cache_object_deserialize(cache,
+ key_data, key_size,
+ data, data_size, ops);
if (object == NULL)
continue;
More information about the mesa-commit
mailing list