dzn: Add a generic cached blob wrapper
Basically what vk_pipeline_cache's raw_data_object abstraction provides, but I'm not sure it makes sense to make it generic so I copied it here. Might be more appropriate to make raw_data_object public. Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17140>
This commit is contained in:

committed by
Marge Bot

parent
06f37025f1
commit
d4630b703d
@@ -281,6 +281,11 @@ dzn_physical_device_init_uuids(struct dzn_physical_device *pdev)
|
||||
memcpy(pdev->device_uuid, sha1, VK_UUID_SIZE);
|
||||
}
|
||||
|
||||
const struct vk_pipeline_cache_object_ops *const dzn_pipeline_cache_import_ops[] = {
|
||||
&dzn_cached_blob_ops,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static VkResult
|
||||
dzn_physical_device_create(struct dzn_instance *instance,
|
||||
IDXGIAdapter1 *adapter,
|
||||
@@ -326,6 +331,8 @@ dzn_physical_device_create(struct dzn_instance *instance,
|
||||
assert(num_sync_types <= MAX_SYNC_TYPES);
|
||||
pdev->vk.supported_sync_types = pdev->sync_types;
|
||||
|
||||
pdev->vk.pipeline_cache_import_ops = dzn_pipeline_cache_import_ops;
|
||||
|
||||
/* TODO: something something queue families */
|
||||
|
||||
result = dzn_wsi_init(pdev);
|
||||
|
@@ -36,6 +36,7 @@
|
||||
#include "vk_util.h"
|
||||
#include "vk_format.h"
|
||||
#include "vk_pipeline.h"
|
||||
#include "vk_pipeline_cache.h"
|
||||
|
||||
#include "util/u_debug.h"
|
||||
|
||||
@@ -73,6 +74,88 @@ gfx_pipeline_variant_key_hash(const void *key)
|
||||
return _mesa_hash_data(key, sizeof(struct dzn_graphics_pipeline_variant_key));
|
||||
}
|
||||
|
||||
struct dzn_cached_blob {
|
||||
struct vk_pipeline_cache_object base;
|
||||
uint8_t hash[SHA1_DIGEST_LENGTH];
|
||||
const void *data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
static bool
|
||||
dzn_cached_blob_serialize(struct vk_pipeline_cache_object *object,
|
||||
struct blob *blob)
|
||||
{
|
||||
struct dzn_cached_blob *cached_blob =
|
||||
container_of(object, struct dzn_cached_blob, base);
|
||||
|
||||
blob_write_bytes(blob, cached_blob->data, cached_blob->size);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
dzn_cached_blob_destroy(struct vk_pipeline_cache_object *object)
|
||||
{
|
||||
struct dzn_cached_blob *shader =
|
||||
container_of(object, struct dzn_cached_blob, base);
|
||||
|
||||
vk_free(&shader->base.device->alloc, shader);
|
||||
}
|
||||
|
||||
static struct vk_pipeline_cache_object *
|
||||
dzn_cached_blob_create(struct vk_device *device,
|
||||
const void *hash,
|
||||
const void *data,
|
||||
size_t data_size);
|
||||
|
||||
static struct vk_pipeline_cache_object *
|
||||
dzn_cached_blob_deserialize(struct vk_device *device,
|
||||
const void *key_data,
|
||||
size_t key_size,
|
||||
struct blob_reader *blob)
|
||||
{
|
||||
size_t data_size = blob->end - blob->current;
|
||||
assert(key_size == SHA1_DIGEST_LENGTH);
|
||||
|
||||
return dzn_cached_blob_create(device, key_data,
|
||||
blob_read_bytes(blob, data_size),
|
||||
data_size);
|
||||
}
|
||||
|
||||
const struct vk_pipeline_cache_object_ops dzn_cached_blob_ops = {
|
||||
.serialize = dzn_cached_blob_serialize,
|
||||
.deserialize = dzn_cached_blob_deserialize,
|
||||
.destroy = dzn_cached_blob_destroy,
|
||||
};
|
||||
|
||||
|
||||
static struct vk_pipeline_cache_object *
|
||||
dzn_cached_blob_create(struct vk_device *device,
|
||||
const void *hash,
|
||||
const void *data,
|
||||
size_t data_size)
|
||||
{
|
||||
VK_MULTIALLOC(ma);
|
||||
VK_MULTIALLOC_DECL(&ma, struct dzn_cached_blob, blob, 1);
|
||||
VK_MULTIALLOC_DECL(&ma, uint8_t, copy, data_size);
|
||||
|
||||
if (!vk_multialloc_alloc(&ma, &device->alloc,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE))
|
||||
return NULL;
|
||||
|
||||
memcpy(blob->hash, hash, sizeof(blob->hash));
|
||||
|
||||
vk_pipeline_cache_object_init(device, &blob->base,
|
||||
&dzn_cached_blob_ops,
|
||||
blob->hash, sizeof(blob->hash));
|
||||
|
||||
if (data)
|
||||
memcpy(copy, data, data_size);
|
||||
blob->data = copy;
|
||||
blob->size = data_size;
|
||||
|
||||
return &blob->base;
|
||||
}
|
||||
|
||||
static VkResult
|
||||
dzn_graphics_pipeline_prepare_for_variants(struct dzn_device *device,
|
||||
struct dzn_graphics_pipeline *pipeline)
|
||||
|
@@ -756,6 +756,8 @@ struct dzn_pipeline {
|
||||
ID3D12PipelineState *state;
|
||||
};
|
||||
|
||||
extern const struct vk_pipeline_cache_object_ops dzn_cached_blob_ops;
|
||||
|
||||
enum dzn_indirect_draw_cmd_sig_type {
|
||||
DZN_INDIRECT_DRAW_CMD_SIG,
|
||||
DZN_INDIRECT_INDEXED_DRAW_CMD_SIG,
|
||||
|
Reference in New Issue
Block a user