From 03dc59ef399f92f5b89ae493868561d9bfa8d60e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 26 Oct 2019 23:59:11 +0200 Subject: [PATCH] [dxvk] Write correct depth-stencil attachment layout to state cache Fixes a dumb issue where we'd compress layouts with high enum values to a single byte and incorrectly interpret the result as PREINITIALIZED. --- src/dxvk/dxvk_state_cache.cpp | 28 ++++++++++++++++++++++++---- src/dxvk/dxvk_state_cache.h | 6 ++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/dxvk/dxvk_state_cache.cpp b/src/dxvk/dxvk_state_cache.cpp index 9972f53a..e2b5a8ad 100644 --- a/src/dxvk/dxvk_state_cache.cpp +++ b/src/dxvk/dxvk_state_cache.cpp @@ -542,7 +542,7 @@ namespace dxvk { entry.format.sampleCount = VkSampleCountFlagBits(sampleCount); entry.format.depth.format = VkFormat(imageFormat); - entry.format.depth.layout = VkImageLayout(imageLayout); + entry.format.depth.layout = unpackImageLayout(imageLayout); for (uint32_t i = 0; i < MaxNumRenderTargets; i++) { if (!data.read(imageFormat) @@ -550,7 +550,7 @@ namespace dxvk { return false; entry.format.color[i].format = VkFormat(imageFormat); - entry.format.color[i].layout = VkImageLayout(imageLayout); + entry.format.color[i].layout = unpackImageLayout(imageLayout); } // Read common pipeline state @@ -638,11 +638,11 @@ namespace dxvk { // Pack render pass format data.write(uint8_t(entry.format.sampleCount)); data.write(uint8_t(entry.format.depth.format)); - data.write(uint8_t(entry.format.depth.layout)); + data.write(packImageLayout(entry.format.depth.layout)); for (uint32_t i = 0; i < MaxNumRenderTargets; i++) { data.write(uint8_t(entry.format.color[i].format)); - data.write(uint8_t(entry.format.color[i].layout)); + data.write(packImageLayout(entry.format.color[i].layout)); } // Write out common pipeline state @@ -965,4 +965,24 @@ namespace dxvk { return env::getEnvVar("DXVK_STATE_CACHE_PATH"); } + + uint8_t DxvkStateCache::packImageLayout( + VkImageLayout layout) { + switch (layout) { + case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: return 0x80; + case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: return 0x81; + default: return uint8_t(layout); + } + } + + + VkImageLayout DxvkStateCache::unpackImageLayout( + uint8_t layout) { + switch (layout) { + case 0x80: return VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL; + case 0x81: return VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL; + default: return VkImageLayout(layout); + } + } + } diff --git a/src/dxvk/dxvk_state_cache.h b/src/dxvk/dxvk_state_cache.h index f938efdd..80fab912 100644 --- a/src/dxvk/dxvk_state_cache.h +++ b/src/dxvk/dxvk_state_cache.h @@ -180,6 +180,12 @@ namespace dxvk { std::string getCacheDir() const; + static uint8_t packImageLayout( + VkImageLayout layout); + + static VkImageLayout unpackImageLayout( + uint8_t layout); + }; } \ No newline at end of file