From ee043f4fed7d3db8d1c559675e8e0d04711abdc0 Mon Sep 17 00:00:00 2001 From: moudgils <47460854+moudgils@users.noreply.github.com> Date: Fri, 22 Oct 2021 12:10:15 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20RHI/Subpass=20sample=20for=20Vulkan.=20Th?= =?UTF-8?q?e=20issue=20was=20that=20we=20were=20exectui=E2=80=A6=20(#4904)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix RHI/Subpass sample for Vulkan. The issue was that we were exectuing the sub-pass groups more than once when parallel encoding was used. Signed-off-by: moudgils * Added a minor comment Signed-off-by: moudgils * Minor perf improvement Signed-off-by: moudgils --- .../Code/Source/RHI/FrameGraphExecuteGroupHandlerBase.cpp | 6 ++++++ .../Code/Source/RHI/FrameGraphExecuteGroupHandlerBase.h | 2 ++ Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuter.cpp | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuteGroupHandlerBase.cpp b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuteGroupHandlerBase.cpp index e85c86f3f4..9c1bb896f9 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuteGroupHandlerBase.cpp +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuteGroupHandlerBase.cpp @@ -27,6 +27,7 @@ namespace AZ { EndInternal(); m_device->GetCommandQueueContext().GetCommandQueue(m_hardwareQueueClass).ExecuteWork(AZStd::move(m_workRequest)); + m_isExecuted = true; } bool FrameGraphExecuteGroupHandlerBase::IsComplete() const @@ -42,6 +43,11 @@ namespace AZ return true; } + bool FrameGraphExecuteGroupHandlerBase::IsExecuted() const + { + return m_isExecuted; + } + template void InsertWorkRequestElements(T& destination, const T& source) { diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuteGroupHandlerBase.h b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuteGroupHandlerBase.h index a0aa6d465a..1aad409667 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuteGroupHandlerBase.h +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuteGroupHandlerBase.h @@ -41,6 +41,7 @@ namespace AZ void End(); bool IsComplete() const; + bool IsExecuted() const; protected: virtual RHI::ResultCode InitInternal(Device& device, const AZStd::vector& executeGroups) = 0; @@ -52,6 +53,7 @@ namespace AZ ExecuteWorkRequest m_workRequest; RHI::HardwareQueueClass m_hardwareQueueClass = RHI::HardwareQueueClass::Graphics; AZStd::vector m_executeGroups; + bool m_isExecuted = false; }; } } diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuter.cpp b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuter.cpp index 7165b5c305..45fe9344a9 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuter.cpp +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/FrameGraphExecuter.cpp @@ -177,8 +177,8 @@ namespace AZ auto findIter = m_groupHandlers.find(group.GetGroupId()); AZ_Assert(findIter != m_groupHandlers.end(), "Could not find group handler for groupId %d", group.GetGroupId().GetIndex()); FrameGraphExecuteGroupHandlerBase* handler = findIter->second.get(); - // Wait until all execute groups of the handler has finished. - if (handler->IsComplete()) + // Wait until all execute groups of the handler has finished and also make sure that the handler itself hasn't executed already (which is possible for parallel encoding). + if (!handler->IsExecuted() && handler->IsComplete()) { // This will execute the recorded work into the queue. handler->End();