From 7f409f446a8d961856bf6c76a9d6f7d39c2d59cc Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 7 Feb 2018 16:46:39 +0100 Subject: [PATCH] [dxvk] Improve internal framebuffer APIs Removes an unnecessary dynamic memory allocation in favour of a stack-allocated array. --- src/dxvk/dxvk_framebuffer.cpp | 15 ++++++++------- src/dxvk/dxvk_framebuffer.h | 6 ++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/dxvk/dxvk_framebuffer.cpp b/src/dxvk/dxvk_framebuffer.cpp index c06584b1..9972f9b2 100644 --- a/src/dxvk/dxvk_framebuffer.cpp +++ b/src/dxvk/dxvk_framebuffer.cpp @@ -33,18 +33,18 @@ namespace dxvk { } - std::vector DxvkRenderTargets::getAttachments() const { - std::vector result; + uint32_t DxvkRenderTargets::getAttachments(VkImageView* viewHandles) const { + uint32_t numViews = 0; if (m_depthTarget.view != nullptr) - result.push_back(m_depthTarget.view->handle()); + viewHandles[numViews++] = m_depthTarget.view->handle(); for (uint32_t i = 0; i < MaxNumRenderTargets; i++) { if (m_colorTargets.at(i).view != nullptr) - result.push_back(m_colorTargets.at(i).view->handle()); + viewHandles[numViews++] = m_colorTargets.at(i).view->handle(); } - return result; + return numViews; } @@ -87,14 +87,15 @@ namespace dxvk { m_renderPass (renderPass), m_renderTargets (renderTargets), m_framebufferSize (renderTargets.getImageSize()) { - auto views = renderTargets.getAttachments(); + std::array views; + uint32_t viewCount = renderTargets.getAttachments(views.data()); VkFramebufferCreateInfo info; info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; info.pNext = nullptr; info.flags = 0; info.renderPass = renderPass->handle(); - info.attachmentCount = views.size(); + info.attachmentCount = viewCount; info.pAttachments = views.data(); info.width = m_framebufferSize.width; info.height = m_framebufferSize.height; diff --git a/src/dxvk/dxvk_framebuffer.h b/src/dxvk/dxvk_framebuffer.h index c7f5e60e..b91c7c80 100644 --- a/src/dxvk/dxvk_framebuffer.h +++ b/src/dxvk/dxvk_framebuffer.h @@ -95,9 +95,11 @@ namespace dxvk { /** * \brief Creates attachment list - * \returns Framebuffer attachment list + * + * \param [out] viewHandles Attachment handles + * \returns Framebuffer attachment count */ - std::vector getAttachments() const; + uint32_t getAttachments(VkImageView* viewHandles) const; /** * \brief Framebuffer size