From 0a8ba357382fc87040444278910b80c32fb668a8 Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Wed, 15 Dec 2021 18:32:59 -0800 Subject: [PATCH 1/4] Added ClearPass and automatic instantiation from ParentPass for slots specifying a clear action Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Feature/Common/Assets/Passes/Clear.pass | 30 ++++++++++ .../Assets/Passes/PassTemplates.azasset | 4 ++ .../Passes/SMAA1xApplyLinearHDRColor.pass | 5 +- .../Passes/SMAA1xApplyPerceptualColor.pass | 5 +- .../atom_feature_common_asset_files.cmake | 4 ++ .../PostProcessing/EyeAdaptationPass.cpp | 2 - .../Include/Atom/RPI.Public/Pass/ClearPass.h | 45 +++++++++++++++ .../Include/Atom/RPI.Public/Pass/ParentPass.h | 4 ++ .../Atom/RPI.Reflect/Pass/ClearPassData.h | 43 ++++++++++++++ .../Code/Source/RPI.Public/Pass/ClearPass.cpp | 57 +++++++++++++++++++ .../Source/RPI.Public/Pass/ParentPass.cpp | 50 +++++++++++++++- .../Source/RPI.Public/Pass/PassFactory.cpp | 2 + .../Source/RPI.Public/Pass/PassSystem.cpp | 2 + .../Atom/RPI/Code/atom_rpi_public_files.cmake | 2 + .../RPI/Code/atom_rpi_reflect_files.cmake | 1 + 15 files changed, 245 insertions(+), 11 deletions(-) create mode 100644 Gems/Atom/Feature/Common/Assets/Passes/Clear.pass create mode 100644 Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h create mode 100644 Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/ClearPassData.h create mode 100644 Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp diff --git a/Gems/Atom/Feature/Common/Assets/Passes/Clear.pass b/Gems/Atom/Feature/Common/Assets/Passes/Clear.pass new file mode 100644 index 0000000000..a36c2ef03d --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Passes/Clear.pass @@ -0,0 +1,30 @@ +{ + "Type": "JsonSerialization", + "Version": 1, + "ClassName": "PassAsset", + "ClassData": { + "PassTemplate": { + "Name": "ClearPassTemplate", + "PassClass": "ClearPass", + "Slots": [ + { + "Name": "ClearInputOutput", + "SlotType": "InputOutput", + "ScopeAttachmentUsage": "RenderTarget", + "LoadStoreAction": { + "ClearValue": { + "Value": [ + 0.0, + 0.0, + 0.0, + 0.0 + ] + }, + "LoadAction": "Clear", + "LoadActionStencil": "Clear" + } + } + ] + } + } +} diff --git a/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset b/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset index eba745fb3c..b16536b276 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset +++ b/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset @@ -64,6 +64,10 @@ "Name": "CascadedShadowmapsTemplate", "Path": "Passes/CascadedShadowmaps.pass" }, + { + "Name": "ClearPassTemplate", + "Path": "Passes/Clear.pass" + }, { "Name": "FullscreenCopyTemplate", "Path": "Passes/FullscreenCopy.pass" diff --git a/Gems/Atom/Feature/Common/Assets/Passes/SMAA1xApplyLinearHDRColor.pass b/Gems/Atom/Feature/Common/Assets/Passes/SMAA1xApplyLinearHDRColor.pass index 70604fba25..9ae0f62bc7 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/SMAA1xApplyLinearHDRColor.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/SMAA1xApplyLinearHDRColor.pass @@ -25,10 +25,7 @@ { "Name": "OutputColor", "SlotType": "Output", - "ScopeAttachmentUsage": "RenderTarget", - "LoadStoreAction": { - "LoadAction": "DontCare" - } + "ScopeAttachmentUsage": "RenderTarget" } ], "Connections": [ diff --git a/Gems/Atom/Feature/Common/Assets/Passes/SMAA1xApplyPerceptualColor.pass b/Gems/Atom/Feature/Common/Assets/Passes/SMAA1xApplyPerceptualColor.pass index 27fcff21cf..04484e1f17 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/SMAA1xApplyPerceptualColor.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/SMAA1xApplyPerceptualColor.pass @@ -25,10 +25,7 @@ { "Name": "OutputColor", "SlotType": "Output", - "ScopeAttachmentUsage": "RenderTarget", - "LoadStoreAction": { - "LoadAction": "DontCare" - } + "ScopeAttachmentUsage": "RenderTarget" } ], "Connections": [ diff --git a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake index c4d198fef9..a684b4b299 100644 --- a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake +++ b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake @@ -53,6 +53,7 @@ set(FILES Materials/Types/StandardPBR_LowEndForward.azsl Materials/Types/StandardPBR_LowEndForward.shader Materials/Types/StandardPBR_LowEndForward_EDS.shader + Materials/Types/StandardPBR_Metallic.lua Materials/Types/StandardPBR_ParallaxState.lua Materials/Types/StandardPBR_Roughness.lua Materials/Types/StandardPBR_ShaderEnable.lua @@ -85,6 +86,7 @@ set(FILES Passes/CascadedShadowmaps.pass Passes/CheckerboardResolveColor.pass Passes/CheckerboardResolveDepth.pass + Passes/Clear.pass Passes/ContrastAdaptiveSharpening.pass Passes/ConvertToAcescg.pass Passes/DebugOverlayParent.pass @@ -129,6 +131,7 @@ set(FILES Passes/DownsampleMipChain.pass Passes/EnvironmentCubeMapDepthMSAA.pass Passes/EnvironmentCubeMapForwardMSAA.pass + Passes/EnvironmentCubeMapForwardSubsurfaceMSAA.pass Passes/EnvironmentCubeMapPipeline.pass Passes/EnvironmentCubeMapSkyBox.pass Passes/EsmShadowmaps.pass @@ -303,6 +306,7 @@ set(FILES ShaderLib/Atom/Features/ScreenSpace/ScreenSpaceUtil.azsli ShaderLib/Atom/Features/Shadow/BicubicPcfFilters.azsli ShaderLib/Atom/Features/Shadow/DirectionalLightShadow.azsli + ShaderLib/Atom/Features/Shadow/ESM.azsli ShaderLib/Atom/Features/Shadow/NormalOffsetShadows.azsli ShaderLib/Atom/Features/Shadow/ProjectedShadow.azsli ShaderLib/Atom/Features/Shadow/ReceiverPlaneDepthBias.azsli diff --git a/Gems/Atom/Feature/Common/Code/Source/PostProcessing/EyeAdaptationPass.cpp b/Gems/Atom/Feature/Common/Code/Source/PostProcessing/EyeAdaptationPass.cpp index 5683241693..20254690f9 100644 --- a/Gems/Atom/Feature/Common/Code/Source/PostProcessing/EyeAdaptationPass.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/PostProcessing/EyeAdaptationPass.cpp @@ -73,8 +73,6 @@ namespace AZ return false; } - AZ_Assert(m_pipeline->GetScene(), "EyeAdaptationPass's Pipeline does not have a valid scene pointer"); - AZ::RPI::Scene* scene = GetScene(); bool enabled = false; diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h new file mode 100644 index 0000000000..e917584fca --- /dev/null +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ +#pragma once + +#include + +#include +#include +#include + +#include + +namespace AZ +{ + namespace RPI + { + //! A simple pass to clear a render target + class ClearPass + : public RenderPass + { + AZ_RPI_PASS(ClearPass); + + public: + AZ_RTTI(ClearPass, "{31CBAD6C-108F-4F3F-B498-ED968DFCFCE2}", RenderPass); + AZ_CLASS_ALLOCATOR(ClearPass, SystemAllocator, 0); + virtual ~ClearPass() = default; + + //! Creates a ClearPass + static Ptr Create(const PassDescriptor& descriptor); + + protected: + ClearPass(const PassDescriptor& descriptor); + void InitializeInternal() override; + + private: + + RHI::ClearValue m_clearValue; + }; + } // namespace RPI +} // namespace AZ diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ParentPass.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ParentPass.h index 6523f0a6d8..6ee0b43ce5 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ParentPass.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ParentPass.h @@ -131,6 +131,10 @@ namespace AZ // Generates child passes from source PassTemplate void CreatePassesFromTemplate(); + + // Generates child clear passes to clear input and input/output attachments + void CreateClearPassFromBinding(PassAttachmentBinding& binding, PassRequest& clearRequest); + void CreateClearPassesFromBindings(); }; template diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/ClearPassData.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/ClearPassData.h new file mode 100644 index 0000000000..5eed6d54fa --- /dev/null +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/ClearPassData.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ +#pragma once + +#include + +#include + +namespace AZ +{ + namespace RPI + { + //! Custom data for the ClearPass. Should be specified in the PassRequest. + struct ClearPassData + : public RenderPassData + { + AZ_RTTI(ClearPassData, "{5F2C24A4-62D0-4E60-91EC-C207C10D15C6}", RenderPassData); + AZ_CLASS_ALLOCATOR(ClearPassData, SystemAllocator, 0); + + ClearPassData() = default; + virtual ~ClearPassData() = default; + + static void Reflect(ReflectContext* context) + { + if (auto* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(0) + ->Field("ClearValue", &ClearPassData::m_clearValue) + ; + } + } + + RHI::ClearValue m_clearValue; + }; + } // namespace RPI +} // namespace AZ + diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp new file mode 100644 index 0000000000..1ba16f4b5a --- /dev/null +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +namespace AZ +{ + namespace RPI + { + Ptr ClearPass::Create(const PassDescriptor& descriptor) + { + Ptr pass = aznew ClearPass(descriptor); + return pass; + } + + ClearPass::ClearPass(const PassDescriptor& descriptor) + : RenderPass(descriptor) + { + const ClearPassData* passData = PassUtils::GetPassData(descriptor); + if (passData != nullptr) + { + m_clearValue = passData->m_clearValue; + } + } + + void ClearPass::InitializeInternal() + { + RenderPass::InitializeInternal(); + + // Set clear value + AZ_Assert(GetInputOutputCount() > 0, "ClearPass: Missing InputOutput binding!"); + RPI::PassAttachmentBinding& binding = GetInputOutputBinding(0); + binding.m_unifiedScopeDesc.m_loadStoreAction.m_clearValue = m_clearValue; + } + + } // namespace RPI +} // namespace AZ diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp index dccf5dbc2e..f0154b371a 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp @@ -9,11 +9,15 @@ #include #include +#include #include +#include #include #include #include +#include +#include #include namespace AZ @@ -196,7 +200,7 @@ namespace AZ } } - // --- PassTemplate related functions --- + // --- Child creation --- void ParentPass::CreatePassesFromTemplate() { @@ -217,6 +221,49 @@ namespace AZ } } + void ParentPass::CreateClearPassFromBinding(PassAttachmentBinding& binding, PassRequest& clearRequest) + { + if (binding.m_unifiedScopeDesc.m_loadStoreAction.m_loadAction == RHI::AttachmentLoadAction::Clear || + binding.m_unifiedScopeDesc.m_loadStoreAction.m_loadActionStencil == RHI::AttachmentLoadAction::Clear) + { + // Set the name of the child clear pass as well as the binding it's connected to + clearRequest.m_passName = ConcatPassName(Name("Clear"), binding.m_name); + clearRequest.m_connections[0].m_attachmentRef.m_attachment = binding.m_name; + + // Set the pass clear value to the clear value of the attachment binding + ClearPassData* clearData = static_cast(clearRequest.m_passData.get()); + clearData->m_clearValue = binding.m_unifiedScopeDesc.m_loadStoreAction.m_clearValue; + + // Create and add the pass + Ptr clearPass = PassSystemInterface::Get()->CreatePassFromRequest(&clearRequest); + if (clearPass) + { + AddChild(clearPass); + } + } + + } + + void ParentPass::CreateClearPassesFromBindings() + { + PassRequest clearRequest; + clearRequest.m_templateName = Name("ClearPassTemplate"); + clearRequest.m_passData = AZStd::make_shared(); + clearRequest.m_connections.push_back(); + clearRequest.m_connections[0].m_localSlot = Name("ClearInputOutput"); + clearRequest.m_connections[0].m_attachmentRef.m_pass = Name("Parent"); + + for (uint32_t idx = 0; idx < GetInputCount(); ++idx) + { + CreateClearPassFromBinding(GetInputBinding(idx), clearRequest); + } + + for (uint32_t idx = 0; idx < GetInputOutputCount(); ++idx) + { + CreateClearPassFromBinding(GetInputOutputBinding(idx), clearRequest); + } + } + // --- Pass behavior functions --- void ParentPass::CreateChildPasses() @@ -229,6 +276,7 @@ namespace AZ m_flags.m_alreadyCreatedChildren = true; RemoveChildren(); + CreateClearPassesFromBindings(); CreatePassesFromTemplate(); CreateChildPassesInternal(); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp index ef8d7a3fae..7443c51bff 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp @@ -8,6 +8,7 @@ #include +#include #include #include #include @@ -60,6 +61,7 @@ namespace AZ { AddPassCreator(Name("ParentPass"), &ParentPass::Create); AddPassCreator(Name("RasterPass"), &RasterPass::Create); + AddPassCreator(Name("ClearPass"), &ClearPass::Create); AddPassCreator(Name("CopyPass"), &CopyPass::Create); AddPassCreator(Name("FullScreenTriangle"), &FullscreenTrianglePass::Create); AddPassCreator(Name("ComputePass"), &ComputePass::Create); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp index cd64010680..f45d28518f 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -67,6 +68,7 @@ namespace AZ PassSlot::Reflect(context); PassData::Reflect(context); + ClearPassData::Reflect(context); CopyPassData::Reflect(context); RenderPassData::Reflect(context); ComputePassData::Reflect(context); diff --git a/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake b/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake index 93b85375f0..91dcf479e9 100644 --- a/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake +++ b/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake @@ -57,6 +57,7 @@ set(FILES Include/Atom/RPI.Public/Model/ModelSystem.h Include/Atom/RPI.Public/Model/UvStreamTangentBitmask.h Include/Atom/RPI.Public/Pass/AttachmentReadback.h + Include/Atom/RPI.Public/Pass/ClearPass.h Include/Atom/RPI.Public/Pass/ComputePass.h Include/Atom/RPI.Public/Pass/CopyPass.h Include/Atom/RPI.Public/Pass/FullscreenTrianglePass.h @@ -135,6 +136,7 @@ set(FILES Source/RPI.Public/Model/ModelSystem.cpp Source/RPI.Public/Model/UvStreamTangentBitmask.cpp Source/RPI.Public/Pass/AttachmentReadback.cpp + Source/RPI.Public/Pass/ClearPass.cpp Source/RPI.Public/Pass/ComputePass.cpp Source/RPI.Public/Pass/CopyPass.cpp Source/RPI.Public/Pass/FullscreenTrianglePass.cpp diff --git a/Gems/Atom/RPI/Code/atom_rpi_reflect_files.cmake b/Gems/Atom/RPI/Code/atom_rpi_reflect_files.cmake index 4f0e432511..921d5a8e46 100644 --- a/Gems/Atom/RPI/Code/atom_rpi_reflect_files.cmake +++ b/Gems/Atom/RPI/Code/atom_rpi_reflect_files.cmake @@ -62,6 +62,7 @@ set(FILES Include/Atom/RPI.Reflect/Material/ShaderCollection.h Include/Atom/RPI.Reflect/Material/MaterialFunctor.h Include/Atom/RPI.Reflect/Material/MaterialVersionUpdate.h + Include/Atom/RPI.Reflect/Pass/ClearPassData.h Include/Atom/RPI.Reflect/Pass/ComputePassData.h Include/Atom/RPI.Reflect/Pass/CopyPassData.h Include/Atom/RPI.Reflect/Pass/DownsampleMipChainPassData.h From 18bb69a5cbecf53ce9388300090391bbc5aba071 Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Wed, 15 Dec 2021 18:37:48 -0800 Subject: [PATCH 2/4] removed unnecessary lines Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Code/Include/Atom/RPI.Public/Pass/ClearPass.h | 7 +------ .../Include/Atom/RPI.Reflect/Pass/ClearPassData.h | 2 +- .../RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp | 12 ------------ 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h index e917584fca..3599e6de44 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h @@ -8,11 +8,6 @@ #pragma once #include - -#include -#include -#include - #include namespace AZ @@ -38,8 +33,8 @@ namespace AZ void InitializeInternal() override; private: - RHI::ClearValue m_clearValue; }; + } // namespace RPI } // namespace AZ diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/ClearPassData.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/ClearPassData.h index 5eed6d54fa..9c03f5ccd6 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/ClearPassData.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/ClearPassData.h @@ -8,7 +8,6 @@ #pragma once #include - #include namespace AZ @@ -38,6 +37,7 @@ namespace AZ RHI::ClearValue m_clearValue; }; + } // namespace RPI } // namespace AZ diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp index 1ba16f4b5a..0e3ea76728 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp @@ -8,20 +8,8 @@ #include #include -#include -#include #include -#include -#include - -#include -#include -#include - -#include -#include -#include namespace AZ { From 2bc381811d0a5d5fd508d7c4443371e8a04f8f36 Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Thu, 16 Dec 2021 10:42:53 -0800 Subject: [PATCH 3/4] addressed PR feedback Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Feature/Common/Assets/Passes/PassTemplates.azasset | 4 ++-- .../Common/Assets/Passes/{Clear.pass => SlowClear.pass} | 6 +++++- .../Common/Assets/atom_feature_common_asset_files.cmake | 2 +- .../RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h | 4 +++- .../RPI/Code/Include/Atom/RPI.Public/Pass/ParentPass.h | 9 +++++++++ Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp | 2 +- 6 files changed, 21 insertions(+), 6 deletions(-) rename Gems/Atom/Feature/Common/Assets/Passes/{Clear.pass => SlowClear.pass} (79%) diff --git a/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset b/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset index b16536b276..96cf769690 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset +++ b/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset @@ -65,8 +65,8 @@ "Path": "Passes/CascadedShadowmaps.pass" }, { - "Name": "ClearPassTemplate", - "Path": "Passes/Clear.pass" + "Name": "SlowClearPassTemplate", + "Path": "Passes/SlowClear.pass" }, { "Name": "FullscreenCopyTemplate", diff --git a/Gems/Atom/Feature/Common/Assets/Passes/Clear.pass b/Gems/Atom/Feature/Common/Assets/Passes/SlowClear.pass similarity index 79% rename from Gems/Atom/Feature/Common/Assets/Passes/Clear.pass rename to Gems/Atom/Feature/Common/Assets/Passes/SlowClear.pass index a36c2ef03d..417cf94eac 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/Clear.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/SlowClear.pass @@ -4,7 +4,11 @@ "ClassName": "PassAsset", "ClassData": { "PassTemplate": { - "Name": "ClearPassTemplate", + + // This is for debug purposes and edge cases only + // If you want to clear an attachment you should + // use the LoadStoreAction on your pass slot. + "Name": "SlowClearPassTemplate", "PassClass": "ClearPass", "Slots": [ { diff --git a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake index a684b4b299..a03058e2bf 100644 --- a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake +++ b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake @@ -86,7 +86,6 @@ set(FILES Passes/CascadedShadowmaps.pass Passes/CheckerboardResolveColor.pass Passes/CheckerboardResolveDepth.pass - Passes/Clear.pass Passes/ContrastAdaptiveSharpening.pass Passes/ConvertToAcescg.pass Passes/DebugOverlayParent.pass @@ -201,6 +200,7 @@ set(FILES Passes/Skinning.pass Passes/SkyBox.pass Passes/SkyBox_TwoOutputs.pass + Passes/SlowClear.pass Passes/SMAA1xApplyLinearHDRColor.pass Passes/SMAA1xApplyPerceptualColor.pass Passes/SMAABlendingWeightCalculation.pass diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h index 3599e6de44..96252ca82c 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h @@ -14,7 +14,9 @@ namespace AZ { namespace RPI { - //! A simple pass to clear a render target + //! Only use this for debug purposes and edge cases + //! The correct and efficient way to clear a pass is through the LoadStoreAction on the pass slot + //! This will clear a given image attachment to the specified clear value. class ClearPass : public RenderPass { diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ParentPass.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ParentPass.h index 6ee0b43ce5..00b7a76f77 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ParentPass.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ParentPass.h @@ -133,6 +133,15 @@ namespace AZ void CreatePassesFromTemplate(); // Generates child clear passes to clear input and input/output attachments + // TODO: These two functions are a workaround for a complicated edge case: + // Let Parent Pass P1 have two children, C1 and C2. C1 writes to an attachment that C2 reads, + // but C1 can be disabled, in which case we just want C2 to read the cleared texture. + // Because of this, the attachment is owned by the parent pass, that way it is always available for C2 + // to read even when C1 is disabled. However we still want to clear the attachment before C2 reads it. + // We tried overriding the LoadStoreAction to clear on C2's slot when C1 is disabled, but the RHI + // doesn't allow for clears on Input only slots. Changing the slot to InputOutput was in conflict with + // the texture definition in the SRG, and it couldn't be changed to RW because it was an MSAA texture. + // So now we detect clear actions on parent slots and generate a clear pass for them. void CreateClearPassFromBinding(PassAttachmentBinding& binding, PassRequest& clearRequest); void CreateClearPassesFromBindings(); }; diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp index f0154b371a..fff6fae0a3 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp @@ -247,7 +247,7 @@ namespace AZ void ParentPass::CreateClearPassesFromBindings() { PassRequest clearRequest; - clearRequest.m_templateName = Name("ClearPassTemplate"); + clearRequest.m_templateName = Name("SlowClearPassTemplate"); clearRequest.m_passData = AZStd::make_shared(); clearRequest.m_connections.push_back(); clearRequest.m_connections[0].m_localSlot = Name("ClearInputOutput"); From 53cf7b462bf58385d39cf4714642e1c4e33b6761 Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Thu, 16 Dec 2021 11:03:20 -0800 Subject: [PATCH 4/4] Changing all ClearPass to SlowClearPass Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Feature/Common/Assets/Passes/SlowClear.pass | 2 +- .../Pass/{ClearPass.h => SlowClearPass.h} | 16 ++++++++-------- .../{ClearPassData.h => SlowClearPassData.h} | 16 ++++++++-------- .../Code/Source/RPI.Public/Pass/ParentPass.cpp | 8 ++++---- .../Code/Source/RPI.Public/Pass/PassFactory.cpp | 4 ++-- .../Code/Source/RPI.Public/Pass/PassSystem.cpp | 4 ++-- .../Pass/{ClearPass.cpp => SlowClearPass.cpp} | 16 ++++++++-------- Gems/Atom/RPI/Code/atom_rpi_public_files.cmake | 4 ++-- Gems/Atom/RPI/Code/atom_rpi_reflect_files.cmake | 2 +- 9 files changed, 36 insertions(+), 36 deletions(-) rename Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/{ClearPass.h => SlowClearPass.h} (65%) rename Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/{ClearPassData.h => SlowClearPassData.h} (58%) rename Gems/Atom/RPI/Code/Source/RPI.Public/Pass/{ClearPass.cpp => SlowClearPass.cpp} (59%) diff --git a/Gems/Atom/Feature/Common/Assets/Passes/SlowClear.pass b/Gems/Atom/Feature/Common/Assets/Passes/SlowClear.pass index 417cf94eac..97b486191a 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/SlowClear.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/SlowClear.pass @@ -9,7 +9,7 @@ // If you want to clear an attachment you should // use the LoadStoreAction on your pass slot. "Name": "SlowClearPassTemplate", - "PassClass": "ClearPass", + "PassClass": "SlowClearPass", "Slots": [ { "Name": "ClearInputOutput", diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/SlowClearPass.h similarity index 65% rename from Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h rename to Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/SlowClearPass.h index 96252ca82c..6fcb7abd17 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ClearPass.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/SlowClearPass.h @@ -17,21 +17,21 @@ namespace AZ //! Only use this for debug purposes and edge cases //! The correct and efficient way to clear a pass is through the LoadStoreAction on the pass slot //! This will clear a given image attachment to the specified clear value. - class ClearPass + class SlowClearPass : public RenderPass { - AZ_RPI_PASS(ClearPass); + AZ_RPI_PASS(SlowClearPass); public: - AZ_RTTI(ClearPass, "{31CBAD6C-108F-4F3F-B498-ED968DFCFCE2}", RenderPass); - AZ_CLASS_ALLOCATOR(ClearPass, SystemAllocator, 0); - virtual ~ClearPass() = default; + AZ_RTTI(SlowClearPass, "{31CBAD6C-108F-4F3F-B498-ED968DFCFCE2}", RenderPass); + AZ_CLASS_ALLOCATOR(SlowClearPass, SystemAllocator, 0); + virtual ~SlowClearPass() = default; - //! Creates a ClearPass - static Ptr Create(const PassDescriptor& descriptor); + //! Creates a SlowClearPass + static Ptr Create(const PassDescriptor& descriptor); protected: - ClearPass(const PassDescriptor& descriptor); + SlowClearPass(const PassDescriptor& descriptor); void InitializeInternal() override; private: diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/ClearPassData.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/SlowClearPassData.h similarity index 58% rename from Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/ClearPassData.h rename to Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/SlowClearPassData.h index 9c03f5ccd6..7607bca285 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/ClearPassData.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Pass/SlowClearPassData.h @@ -14,23 +14,23 @@ namespace AZ { namespace RPI { - //! Custom data for the ClearPass. Should be specified in the PassRequest. - struct ClearPassData + //! Custom data for the SlowClearPass. Should be specified in the PassRequest. + struct SlowClearPassData : public RenderPassData { - AZ_RTTI(ClearPassData, "{5F2C24A4-62D0-4E60-91EC-C207C10D15C6}", RenderPassData); - AZ_CLASS_ALLOCATOR(ClearPassData, SystemAllocator, 0); + AZ_RTTI(SlowClearPassData, "{5F2C24A4-62D0-4E60-91EC-C207C10D15C6}", RenderPassData); + AZ_CLASS_ALLOCATOR(SlowClearPassData, SystemAllocator, 0); - ClearPassData() = default; - virtual ~ClearPassData() = default; + SlowClearPassData() = default; + virtual ~SlowClearPassData() = default; static void Reflect(ReflectContext* context) { if (auto* serializeContext = azrtti_cast(context)) { - serializeContext->Class() + serializeContext->Class() ->Version(0) - ->Field("ClearValue", &ClearPassData::m_clearValue) + ->Field("ClearValue", &SlowClearPassData::m_clearValue) ; } } diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp index fff6fae0a3..55f3e44173 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ParentPass.cpp @@ -9,14 +9,14 @@ #include #include -#include +#include #include #include #include #include #include -#include +#include #include #include @@ -231,7 +231,7 @@ namespace AZ clearRequest.m_connections[0].m_attachmentRef.m_attachment = binding.m_name; // Set the pass clear value to the clear value of the attachment binding - ClearPassData* clearData = static_cast(clearRequest.m_passData.get()); + SlowClearPassData* clearData = static_cast(clearRequest.m_passData.get()); clearData->m_clearValue = binding.m_unifiedScopeDesc.m_loadStoreAction.m_clearValue; // Create and add the pass @@ -248,7 +248,7 @@ namespace AZ { PassRequest clearRequest; clearRequest.m_templateName = Name("SlowClearPassTemplate"); - clearRequest.m_passData = AZStd::make_shared(); + clearRequest.m_passData = AZStd::make_shared(); clearRequest.m_connections.push_back(); clearRequest.m_connections[0].m_localSlot = Name("ClearInputOutput"); clearRequest.m_connections[0].m_attachmentRef.m_pass = Name("Parent"); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp index 7443c51bff..cc79df144d 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp @@ -8,7 +8,6 @@ #include -#include #include #include #include @@ -20,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -61,7 +61,7 @@ namespace AZ { AddPassCreator(Name("ParentPass"), &ParentPass::Create); AddPassCreator(Name("RasterPass"), &RasterPass::Create); - AddPassCreator(Name("ClearPass"), &ClearPass::Create); + AddPassCreator(Name("SlowClearPass"), &SlowClearPass::Create); AddPassCreator(Name("CopyPass"), &CopyPass::Create); AddPassCreator(Name("FullScreenTriangle"), &FullscreenTrianglePass::Create); AddPassCreator(Name("ComputePass"), &ComputePass::Create); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp index f45d28518f..9e1333b7ab 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -40,6 +39,7 @@ #include #include #include +#include namespace AZ { @@ -68,7 +68,7 @@ namespace AZ PassSlot::Reflect(context); PassData::Reflect(context); - ClearPassData::Reflect(context); + SlowClearPassData::Reflect(context); CopyPassData::Reflect(context); RenderPassData::Reflect(context); ComputePassData::Reflect(context); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/SlowClearPass.cpp similarity index 59% rename from Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp rename to Gems/Atom/RPI/Code/Source/RPI.Public/Pass/SlowClearPass.cpp index 0e3ea76728..62a8241242 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ClearPass.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/SlowClearPass.cpp @@ -6,37 +6,37 @@ * */ -#include +#include #include -#include +#include namespace AZ { namespace RPI { - Ptr ClearPass::Create(const PassDescriptor& descriptor) + Ptr SlowClearPass::Create(const PassDescriptor& descriptor) { - Ptr pass = aznew ClearPass(descriptor); + Ptr pass = aznew SlowClearPass(descriptor); return pass; } - ClearPass::ClearPass(const PassDescriptor& descriptor) + SlowClearPass::SlowClearPass(const PassDescriptor& descriptor) : RenderPass(descriptor) { - const ClearPassData* passData = PassUtils::GetPassData(descriptor); + const SlowClearPassData* passData = PassUtils::GetPassData(descriptor); if (passData != nullptr) { m_clearValue = passData->m_clearValue; } } - void ClearPass::InitializeInternal() + void SlowClearPass::InitializeInternal() { RenderPass::InitializeInternal(); // Set clear value - AZ_Assert(GetInputOutputCount() > 0, "ClearPass: Missing InputOutput binding!"); + AZ_Assert(GetInputOutputCount() > 0, "SlowClearPass: Missing InputOutput binding!"); RPI::PassAttachmentBinding& binding = GetInputOutputBinding(0); binding.m_unifiedScopeDesc.m_loadStoreAction.m_clearValue = m_clearValue; } diff --git a/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake b/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake index 91dcf479e9..36df56cdab 100644 --- a/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake +++ b/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake @@ -57,7 +57,6 @@ set(FILES Include/Atom/RPI.Public/Model/ModelSystem.h Include/Atom/RPI.Public/Model/UvStreamTangentBitmask.h Include/Atom/RPI.Public/Pass/AttachmentReadback.h - Include/Atom/RPI.Public/Pass/ClearPass.h Include/Atom/RPI.Public/Pass/ComputePass.h Include/Atom/RPI.Public/Pass/CopyPass.h Include/Atom/RPI.Public/Pass/FullscreenTrianglePass.h @@ -74,6 +73,7 @@ set(FILES Include/Atom/RPI.Public/Pass/RasterPass.h Include/Atom/RPI.Public/Pass/RenderPass.h Include/Atom/RPI.Public/Pass/MSAAResolvePass.h + Include/Atom/RPI.Public/Pass/SlowClearPass.h Include/Atom/RPI.Public/Pass/Specific/DownsampleMipChainPass.h Include/Atom/RPI.Public/Pass/Specific/ImageAttachmentPreviewPass.h Include/Atom/RPI.Public/Pass/Specific/EnvironmentCubeMapPass.h @@ -136,7 +136,6 @@ set(FILES Source/RPI.Public/Model/ModelSystem.cpp Source/RPI.Public/Model/UvStreamTangentBitmask.cpp Source/RPI.Public/Pass/AttachmentReadback.cpp - Source/RPI.Public/Pass/ClearPass.cpp Source/RPI.Public/Pass/ComputePass.cpp Source/RPI.Public/Pass/CopyPass.cpp Source/RPI.Public/Pass/FullscreenTrianglePass.cpp @@ -151,6 +150,7 @@ set(FILES Source/RPI.Public/Pass/RasterPass.cpp Source/RPI.Public/Pass/RenderPass.cpp Source/RPI.Public/Pass/MSAAResolvePass.cpp + Source/RPI.Public/Pass/SlowClearPass.cpp Source/RPI.Public/Pass/Specific/DownsampleMipChainPass.cpp Source/RPI.Public/Pass/Specific/ImageAttachmentPreviewPass.cpp Source/RPI.Public/Pass/Specific/EnvironmentCubeMapPass.cpp diff --git a/Gems/Atom/RPI/Code/atom_rpi_reflect_files.cmake b/Gems/Atom/RPI/Code/atom_rpi_reflect_files.cmake index 921d5a8e46..df8f389c37 100644 --- a/Gems/Atom/RPI/Code/atom_rpi_reflect_files.cmake +++ b/Gems/Atom/RPI/Code/atom_rpi_reflect_files.cmake @@ -62,7 +62,6 @@ set(FILES Include/Atom/RPI.Reflect/Material/ShaderCollection.h Include/Atom/RPI.Reflect/Material/MaterialFunctor.h Include/Atom/RPI.Reflect/Material/MaterialVersionUpdate.h - Include/Atom/RPI.Reflect/Pass/ClearPassData.h Include/Atom/RPI.Reflect/Pass/ComputePassData.h Include/Atom/RPI.Reflect/Pass/CopyPassData.h Include/Atom/RPI.Reflect/Pass/DownsampleMipChainPassData.h @@ -76,6 +75,7 @@ set(FILES Include/Atom/RPI.Reflect/Pass/PassTemplate.h Include/Atom/RPI.Reflect/Pass/RasterPassData.h Include/Atom/RPI.Reflect/Pass/RenderPassData.h + Include/Atom/RPI.Reflect/Pass/SlowClearPassData.h Include/Atom/RPI.Reflect/Shader/ShaderCommonTypes.h Include/Atom/RPI.Reflect/Shader/ShaderAsset.h Include/Atom/RPI.Reflect/Shader/ShaderAssetCreator.h