From 918224e2d53ff7c8f0c02acb01331551c3c05110 Mon Sep 17 00:00:00 2001 From: dmcdiar Date: Fri, 16 Jul 2021 18:21:50 -0700 Subject: [PATCH] Moved render checks to a ShouldRender() helper function. Skipped attachment readback on RealTime DiffuseProbeGrids if raytracing is not supported by the hardware. Signed-off-by: dmcdiar --- .../DiffuseProbeGridRenderPass.cpp | 55 +++++++++++++------ .../DiffuseProbeGridRenderPass.h | 5 ++ 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridRenderPass.cpp b/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridRenderPass.cpp index 29e7d42da8..55d8ca5cba 100644 --- a/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridRenderPass.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridRenderPass.cpp @@ -6,6 +6,7 @@ * */ +#include #include #include #include @@ -44,6 +45,7 @@ namespace AZ void DiffuseProbeGridRenderPass::FrameBeginInternal(FramePrepareParams params) { + RHI::Ptr device = RHI::RHISystemInterface::Get()->GetDevice(); RPI::Scene* scene = m_pipeline->GetScene(); DiffuseProbeGridFeatureProcessor* diffuseProbeGridFeatureProcessor = scene->GetFeatureProcessor(); @@ -67,10 +69,13 @@ namespace AZ Base::FrameBeginInternal(params); - for (auto& diffuseProbeGrid : diffuseProbeGridFeatureProcessor->GetRealTimeProbeGrids()) + // process attachment readback for RealTime grids, if raytracing is supported on this device + if (device->GetFeatures().m_rayTracing) { - // process attachment readback - diffuseProbeGrid->GetTextureReadback().FrameBegin(params); + for (auto& diffuseProbeGrid : diffuseProbeGridFeatureProcessor->GetRealTimeProbeGrids()) + { + diffuseProbeGrid->GetTextureReadback().FrameBegin(params); + } } } @@ -81,13 +86,7 @@ namespace AZ for (auto& diffuseProbeGrid : diffuseProbeGridFeatureProcessor->GetProbeGrids()) { - if (diffuseProbeGrid->GetMode() == DiffuseProbeGridMode::Baked && - !diffuseProbeGrid->HasValidBakedTextures()) - { - continue; - } - - if (!diffuseProbeGrid->GetIsVisible()) + if (!ShouldRender(diffuseProbeGrid)) { continue; } @@ -173,13 +172,7 @@ namespace AZ for (auto& diffuseProbeGrid : diffuseProbeGridFeatureProcessor->GetProbeGrids()) { - if (diffuseProbeGrid->GetMode() == DiffuseProbeGridMode::Baked && - !diffuseProbeGrid->HasValidBakedTextures()) - { - continue; - } - - if (!diffuseProbeGrid->GetIsVisible()) + if (!ShouldRender(diffuseProbeGrid)) { continue; } @@ -193,5 +186,33 @@ namespace AZ Base::CompileResources(context); } + + bool DiffuseProbeGridRenderPass::ShouldRender(const AZStd::shared_ptr& diffuseProbeGrid) + { + RHI::Ptr device = RHI::RHISystemInterface::Get()->GetDevice(); + + // check for baked mode with no valid textures + if (diffuseProbeGrid->GetMode() == DiffuseProbeGridMode::Baked && + !diffuseProbeGrid->HasValidBakedTextures()) + { + return false; + } + + // check for RealTime mode without ray tracing + if (diffuseProbeGrid->GetMode() == DiffuseProbeGridMode::RealTime && + !device->GetFeatures().m_rayTracing) + { + return false; + } + + // check if culled out + if (!diffuseProbeGrid->GetIsVisible()) + { + return false; + } + + // DiffuseProbeGrid should be rendered + return true; + } } // namespace Render } // namespace AZ diff --git a/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridRenderPass.h b/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridRenderPass.h index 5531364b2d..6f4a91d9c6 100644 --- a/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridRenderPass.h +++ b/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridRenderPass.h @@ -14,6 +14,8 @@ namespace AZ { namespace Render { + class DiffuseProbeGrid; + //! This pass renders the diffuse global illumination in the area covered by //! each DiffuseProbeGrid. class DiffuseProbeGridRenderPass final @@ -40,6 +42,9 @@ namespace AZ void SetupFrameGraphDependencies(RHI::FrameGraphInterface frameGraph) override; void CompileResources(const RHI::FrameGraphCompileContext& context) override; + // helper function to determine if a DiffuseProbeGrid should be rendered based on its state + bool ShouldRender(const AZStd::shared_ptr& diffuseProbeGrid); + Data::Instance m_shader; RHI::Ptr m_srgLayout; };