From 5e55ced8b26651d231254da66c8d914b72b2b5ac Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 21 Feb 2021 14:51:11 +0100 Subject: [PATCH] [dxvk] Fix deferred clear logic for overlapping image views If we clear the same image subresources twice with different views and then start rendering to one view, we may end up clearing to the wrong clear value. --- src/dxvk/dxvk_context.cpp | 6 ++++-- src/dxvk/dxvk_image.h | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 4e18ef65..2ace2a32 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -1868,7 +1868,8 @@ namespace dxvk { entry.clearValue.depthStencil.stencil = clearValue.depthStencil.stencil; return; - } + } else if (entry.imageView->checkSubresourceOverlap(imageView)) + this->flushClears(false); } m_deferredClears.push_back({ imageView, 0, clearAspects, clearValue }); @@ -1883,7 +1884,8 @@ namespace dxvk { entry.discardAspects |= discardAspects; entry.clearAspects &= ~discardAspects; return; - } + } else if (entry.imageView->checkSubresourceOverlap(imageView)) + this->flushClears(false); } m_deferredClears.push_back({ imageView, discardAspects }); diff --git a/src/dxvk/dxvk_image.h b/src/dxvk/dxvk_image.h index 3852c6e6..b04fd602 100644 --- a/src/dxvk/dxvk_image.h +++ b/src/dxvk/dxvk_image.h @@ -469,6 +469,23 @@ namespace dxvk { return result; } + /** + * \brief Checks whether this view overlaps with another one + * + * Two views overlap if they were created for the same + * image and have at least one subresource in common. + * \param [in] view The other view to check + * \returns \c true if the two views overlap + */ + bool checkSubresourceOverlap(const Rc& view) const { + if (likely(m_image != view->m_image)) + return false; + + return vk::checkSubresourceRangeOverlap( + this->imageSubresources(), + view->imageSubresources()); + } + private: Rc m_vkd;