From f9b133d1532eac996ed59770ca61aa0193374ad0 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 14 Apr 2023 15:03:21 +0100 Subject: [PATCH] Fix depth readback with custom depth image in vulkan pixel history --- renderdoc/driver/vulkan/vk_pixelhistory.cpp | 32 ++++++++++----------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/renderdoc/driver/vulkan/vk_pixelhistory.cpp b/renderdoc/driver/vulkan/vk_pixelhistory.cpp index e062139bb..38d7b84c3 100644 --- a/renderdoc/driver/vulkan/vk_pixelhistory.cpp +++ b/renderdoc/driver/vulkan/vk_pixelhistory.cpp @@ -884,16 +884,13 @@ protected: dyn.depth.resolveMode = VK_RESOLVE_MODE_NONE; dyn.depth.resolveImageView = VK_NULL_HANDLE; - if(dyn.depth.loadOp != VK_ATTACHMENT_LOAD_OP_NONE_EXT) - dyn.depth.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; - if(dyn.depth.storeOp != VK_ATTACHMENT_STORE_OP_NONE) - dyn.depth.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + dyn.depth.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + dyn.depth.storeOp = VK_ATTACHMENT_STORE_OP_STORE; dyn.stencil.resolveMode = VK_RESOLVE_MODE_NONE; dyn.stencil.resolveImageView = VK_NULL_HANDLE; - dyn.stencil.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; - if(dyn.stencil.storeOp != VK_ATTACHMENT_STORE_OP_NONE) - dyn.stencil.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + dyn.stencil.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + dyn.stencil.storeOp = VK_ATTACHMENT_STORE_OP_STORE; // we'll be using our own depth/stencil attachment but it will be updated in PatchFramebuffer. // Just set the image layout here @@ -985,9 +982,9 @@ protected: VkAttachmentDescription dsAtt = {}; dsAtt.format = m_CallbackInfo.dsFormat; dsAtt.samples = m_CallbackInfo.samples; - dsAtt.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - dsAtt.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; - dsAtt.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + dsAtt.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + dsAtt.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + dsAtt.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; dsAtt.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; dsAtt.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; dsAtt.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; @@ -2921,9 +2918,9 @@ struct VulkanPixelHistoryPerFragmentCallback : VulkanPixelHistoryCallback if(depthImage != VK_NULL_HANDLE) { CopyPixelParams depthCopyParams = colourCopyParams; - depthCopyParams.srcImage = depthImage; - depthCopyParams.srcImageLayout = depthLayout; - depthCopyParams.srcImageFormat = depthFormat; + depthCopyParams.srcImage = m_CallbackInfo.dsImage; + depthCopyParams.srcImageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + depthCopyParams.srcImageFormat = m_CallbackInfo.dsFormat; CopyImagePixel(cmd, depthCopyParams, (fragsProcessed + f) * sizeof(PerFragmentInfo) + offsetof(struct PerFragmentInfo, postMod) + offsetof(struct PixelHistoryValue, depth)); @@ -3182,11 +3179,11 @@ private: struct VulkanPixelHistoryDiscardedFragmentsCallback : VulkanPixelHistoryCallback { // Key is event ID and value is a list of primitive IDs - std::map > m_Events; + std::map> m_Events; VulkanPixelHistoryDiscardedFragmentsCallback(WrappedVulkan *vk, PixelHistoryShaderCache *shaderCache, const PixelHistoryCallbackInfo &callbackInfo, - std::map > events, + std::map> events, VkQueryPool occlusionPool) : VulkanPixelHistoryCallback(vk, shaderCache, callbackInfo, occlusionPool), m_Events(events) { @@ -4004,7 +4001,7 @@ rdcarray VulkanReplay::PixelHistory(rdcarray even // Retrieve primitive ID values where fragment shader discarded some // fragments. For these primitives we are going to perform an occlusion // query to see if a primitive was discarded. - std::map > discardedPrimsEvents; + std::map> discardedPrimsEvents; uint32_t primitivesToCheck = 0; for(size_t h = 0; h < history.size(); h++) { @@ -4084,7 +4081,8 @@ rdcarray VulkanReplay::PixelHistory(rdcarray even if((uint32_t)callbackInfo.samples > 1) history[h].postMod.depth = bp[offset].postMod.depth.fdepth; else - history[h].postMod.depth = GetDepthValue(cb.GetDepthFormat(eid), bp[offset].postMod); + history[h].postMod.depth = + GetDepthValue(VK_FORMAT_D32_SFLOAT_S8_UINT, bp[offset].postMod); history[h].postMod.stencil = -2; } // If it is not the first fragment for the event, set the preMod to the