From 9a4094e9972e2d774ab064b525e76dece266ba19 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 22 Dec 2023 04:11:38 +1000 Subject: [PATCH] GS/Vulkan: Fix incorrect layout in depth feedback loops Was setting the incorrect texture slot as dirty. --- pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp | 43 +++++++++++++++--------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp index 198461f925..ebc193adae 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp +++ b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp @@ -3462,27 +3462,40 @@ void GSDeviceVK::OMSetRenderTargets( { if (vkRt) { - // NVIDIA drivers appear to return random garbage when sampling the RT via a feedback loop, if the load op for - // the render pass is CLEAR. Using vkCmdClearAttachments() doesn't work, so we have to clear the image instead. - if (feedback_loop & FeedbackLoopFlag_ReadAndWriteRT && vkRt->GetState() == GSTexture::State::Cleared && - IsDeviceNVIDIA()) + if (feedback_loop & FeedbackLoopFlag_ReadAndWriteRT) { - vkRt->CommitClear(); - } + // NVIDIA drivers appear to return random garbage when sampling the RT via a feedback loop, if the load op for + // the render pass is CLEAR. Using vkCmdClearAttachments() doesn't work, so we have to clear the image instead. + if (vkRt->GetState() == GSTexture::State::Cleared && IsDeviceNVIDIA()) + vkRt->CommitClear(); - vkRt->TransitionToLayout((feedback_loop & FeedbackLoopFlag_ReadAndWriteRT) ? - GSTextureVK::Layout::FeedbackLoop : - GSTextureVK::Layout::ColorAttachment); + if (vkRt->GetLayout() != GSTextureVK::Layout::FeedbackLoop) + { + // need to update descriptors to reflect the new layout + m_dirty_flags |= (DIRTY_FLAG_TFX_TEXTURE_0 << TFX_TEXTURE_RT); + vkRt->TransitionToLayout(GSTextureVK::Layout::FeedbackLoop); + } + } + else + { + vkRt->TransitionToLayout(GSTextureVK::Layout::ColorAttachment); + } } if (vkDs) { // need to update descriptors to reflect the new layout - if ((feedback_loop & FeedbackLoopFlag_ReadDS) && vkDs->GetLayout() != GSTextureVK::Layout::FeedbackLoop) - m_dirty_flags |= (DIRTY_FLAG_TFX_TEXTURE_0 << TFX_TEXTURE_RT); - - vkDs->TransitionToLayout((feedback_loop & FeedbackLoopFlag_ReadDS) ? - GSTextureVK::Layout::FeedbackLoop : - GSTextureVK::Layout::DepthStencilAttachment); + if (feedback_loop & FeedbackLoopFlag_ReadDS) + { + if (vkDs->GetLayout() != GSTextureVK::Layout::FeedbackLoop) + { + m_dirty_flags |= (DIRTY_FLAG_TFX_TEXTURE_0 << TFX_TEXTURE_TEXTURE); + vkDs->TransitionToLayout(GSTextureVK::Layout::FeedbackLoop); + } + } + else + { + vkDs->TransitionToLayout(GSTextureVK::Layout::DepthStencilAttachment); + } } }