From 436820d2331e6f15411b89e93a467c1c86bfedfb Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 11 Feb 2021 02:10:32 +0100 Subject: [PATCH] [dxvk] Add method to query color attachment index from attachment index --- src/dxvk/dxvk_framebuffer.cpp | 6 +++--- src/dxvk/dxvk_framebuffer.h | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/dxvk/dxvk_framebuffer.cpp b/src/dxvk/dxvk_framebuffer.cpp index 2da9fa867..ca2ac0c7d 100644 --- a/src/dxvk/dxvk_framebuffer.cpp +++ b/src/dxvk/dxvk_framebuffer.cpp @@ -16,14 +16,14 @@ namespace dxvk { for (uint32_t i = 0; i < MaxNumRenderTargets; i++) { if (m_renderTargets.color[i].view != nullptr) { views[m_attachmentCount] = m_renderTargets.color[i].view->handle(); - m_attachments[m_attachmentCount] = &m_renderTargets.color[i]; + m_attachments[m_attachmentCount] = i; m_attachmentCount += 1; } } if (m_renderTargets.depth.view != nullptr) { views[m_attachmentCount] = m_renderTargets.depth.view->handle(); - m_attachments[m_attachmentCount] = &m_renderTargets.depth; + m_attachments[m_attachmentCount] = -1; m_attachmentCount += 1; } @@ -50,7 +50,7 @@ namespace dxvk { int32_t DxvkFramebuffer::findAttachment(const Rc& view) const { for (uint32_t i = 0; i < m_attachmentCount; i++) { - if (m_attachments[i]->view == view) + if (getAttachment(i).view == view) return int32_t(i); } diff --git a/src/dxvk/dxvk_framebuffer.h b/src/dxvk/dxvk_framebuffer.h index 995051e83..08c311851 100644 --- a/src/dxvk/dxvk_framebuffer.h +++ b/src/dxvk/dxvk_framebuffer.h @@ -159,6 +159,14 @@ namespace dxvk { return m_attachmentCount; } + /** + * \brief Queries color attachment index of a given attachment + * \returns The index, or -1 if the given attachment is the depth attachment + */ + const int32_t getColorAttachmentIndex(uint32_t id) const { + return m_attachments[id]; + } + /** * \brief Retrieves attachment by index * @@ -166,9 +174,10 @@ namespace dxvk { * \returns The framebuffer attachment */ const DxvkAttachment& getAttachment(uint32_t id) const { - return *m_attachments[id]; + int32_t idx = getColorAttachmentIndex(id); + return idx < 0 ? m_renderTargets.depth : m_renderTargets.color[idx]; } - + /** * \brief Finds attachment index by view * @@ -217,8 +226,8 @@ namespace dxvk { const DxvkRenderTargets m_renderTargets; const DxvkFramebufferSize m_renderSize; - uint32_t m_attachmentCount = 0; - std::array m_attachments; + uint32_t m_attachmentCount = 0; + std::array m_attachments; VkFramebuffer m_handle = VK_NULL_HANDLE;