From: Stefan Dösinger stefan@codeweavers.com
This doesn't do all too much, renderpass creation is fast. It is a nice demonstration though. We might want to skip this patch when committing the cache upstream. --- libs/vkd3d/device.c | 26 ++++++++++++++++++++++++++ libs/vkd3d/state.c | 5 +++++ libs/vkd3d/vkd3d_private.h | 23 ++++++++++++----------- 3 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 46803c35c..82212a33e 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -4360,6 +4360,30 @@ static void *device_worker_main(void *arg) return NULL; }
+static bool d3d12_device_load_cache(const void *key, uint32_t key_size, + const void *value, uint32_t value_size, void *context) +{ + const struct vkd3d_shader_cache_entry *e = value; + struct d3d12_device *device = context; + VkRenderPass rp; + + TRACE("device %p got entry type (%c%c%c%c)\n", device, + e->type & 0xff, e->type >> 8 & 0xff, e->type >> 16 & 0xff, + e->type >> 24 & 0xff); + + switch (e->type) + { + case SHADER_CACHE_ENTRY_RENDER_PASS: + vkd3d_render_pass_cache_find(device->render_pass_cache, device, key, &rp); + break; + + case SHADER_CACHE_ENTRY_VULKAN_BLOB: + break; + } + + return true; +} + static HRESULT d3d12_device_init(struct d3d12_device *device, struct vkd3d_instance *instance, const struct vkd3d_device_create_info *create_info) { @@ -4451,6 +4475,8 @@ static HRESULT d3d12_device_init(struct d3d12_device *device,
device_init_descriptor_pool_sizes(device);
+ vkd3d_shader_cache_enumerate(device->persistent_cache, d3d12_device_load_cache, device); + if ((device->parent = create_info->parent)) IUnknown_AddRef(device->parent);
diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index b812ea9f7..5fa4da3e4 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -1560,6 +1560,7 @@ static HRESULT vkd3d_render_pass_cache_create_pass_locked(struct vkd3d_shader_ca VkAttachmentReference attachment_references[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT + 1]; VkAttachmentDescription attachments[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT + 1]; const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; + struct vkd3d_shader_cache_entry rp_data; unsigned int index, attachment_index; VkSubpassDescription sub_pass_desc; VkRenderPassCreateInfo pass_info; @@ -1668,6 +1669,10 @@ static HRESULT vkd3d_render_pass_cache_create_pass_locked(struct vkd3d_shader_ca *vk_render_pass = VK_NULL_HANDLE; }
+ rp_data.type = SHADER_CACHE_ENTRY_RENDER_PASS; + rp_data.vkd3d_revision = VKD3D_SHADER_CACHE_VKD3D_VERSION; + vkd3d_shader_cache_put(device->persistent_cache, key, sizeof(*key), &rp_data, sizeof(rp_data)); + return hresult_from_vk_result(vr); }
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 8a8099400..5144fa2b1 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -55,8 +55,20 @@ #define VKD3D_SHADER_CACHE_OBJ_VERSION 1ull #define VKD3D_SHADER_CACHE_VKD3D_VERSION 1u
+struct vkd3d_render_pass_key +{ + unsigned int attachment_count; + bool depth_enable; + bool stencil_enable; + bool depth_stencil_write; + bool padding; + unsigned int sample_count; + VkFormat vk_formats[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT + 1]; +}; + enum vkd3d_shader_cache_entry_type { + SHADER_CACHE_ENTRY_RENDER_PASS = VKD3D_MAKE_TAG('R', 'P', 'A', 'S'), SHADER_CACHE_ENTRY_VULKAN_BLOB = VKD3D_MAKE_TAG('V', 'K', 'P', 'C'), };
@@ -562,17 +574,6 @@ D3D12_GPU_VIRTUAL_ADDRESS vkd3d_gpu_va_allocator_allocate(struct vkd3d_gpu_va_al void *vkd3d_gpu_va_allocator_dereference(struct vkd3d_gpu_va_allocator *allocator, D3D12_GPU_VIRTUAL_ADDRESS address); void vkd3d_gpu_va_allocator_free(struct vkd3d_gpu_va_allocator *allocator, D3D12_GPU_VIRTUAL_ADDRESS address);
-struct vkd3d_render_pass_key -{ - unsigned int attachment_count; - bool depth_enable; - bool stencil_enable; - bool depth_stencil_write; - bool padding; - unsigned int sample_count; - VkFormat vk_formats[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT + 1]; -}; - struct vkd3d_render_pass_entry;
struct vkd3d_shader_cache *vkd3d_render_pass_cache_init(struct d3d12_device *device);