Skip to content

Commit

Permalink
Improved the logic in the vulkan graphics system in regards to render…
Browse files Browse the repository at this point in the history
…pass reuse.
  • Loading branch information
pboechat committed Nov 20, 2023
1 parent 076ff73 commit 5866e0d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ namespace FastCG
std::vector<PipelineCommand> mPipelineCommands;
std::vector<CopyCommand> mCopyCommands;
std::vector<DrawCommand> mDrawCommands;
VkRenderPass mPrevRenderPass{VK_NULL_HANDLE};
std::vector<VulkanClearRequest> mClearRequests;
bool mEnded{true};
#if _DEBUG
Expand Down
41 changes: 29 additions & 12 deletions FastCG/src/Graphics/Vulkan/VulkanGraphicsContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,26 +559,42 @@ namespace FastCG
continue;
}

auto it = std::find_if(mClearRequests.begin(), mClearRequests.end(), [pRenderTarget](const auto &rClearRequest)
{ return rClearRequest.pTexture == pRenderTarget; });
if (it != mClearRequests.end())
{
mClearRequests.erase(it);
}

renderTargetCount++;
}

if (actualRenderPassDescription.pDepthStencilBuffer != nullptr)
if (mPrevRenderPass != VK_NULL_HANDLE && mPrevRenderPass != renderPass)
{
auto it = std::find_if(mClearRequests.begin(), mClearRequests.end(), [&actualRenderPassDescription](const auto &rClearRequest)
{ return rClearRequest.pTexture == actualRenderPassDescription.pDepthStencilBuffer; });
if (it != mClearRequests.end())
// erase clear requests only if switching renderpasses for reasons other
// than indirect attachments clears. this avoids the unnecessary creation/starting
// of renderpasses due to those clears.
for (const auto *pRenderTarget : actualRenderPassDescription.renderTargets)
{
mClearRequests.erase(it);
if (pRenderTarget == nullptr)
{
continue;
}

auto it = std::find_if(mClearRequests.begin(), mClearRequests.end(), [pRenderTarget](const auto &rClearRequest)
{ return rClearRequest.pTexture == pRenderTarget; });
if (it != mClearRequests.end())
{
mClearRequests.erase(it);
}
}

if (actualRenderPassDescription.pDepthStencilBuffer != nullptr)
{
auto it = std::find_if(mClearRequests.begin(), mClearRequests.end(), [&actualRenderPassDescription](const auto &rClearRequest)
{ return rClearRequest.pTexture == actualRenderPassDescription.pDepthStencilBuffer; });
if (it != mClearRequests.end())
{
mClearRequests.erase(it);
}
}
}

mPrevRenderPass = renderPass;

auto pipeline = VulkanGraphicsSystem::GetInstance()->GetOrCreatePipeline(mPipelineDescription, renderPass, renderTargetCount, mVertexBuffers).second;
assert(pipeline.pipeline != VK_NULL_HANDLE);

Expand Down Expand Up @@ -1202,6 +1218,7 @@ namespace FastCG
mDrawCommands.resize(0);
mCopyCommands.resize(0);
mClearRequests.resize(0);
mPrevRenderPass = VK_NULL_HANDLE;
#if _DEBUG
mMarkerCommands.resize(0);
#endif
Expand Down

0 comments on commit 5866e0d

Please sign in to comment.