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] 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