diff --git a/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveColor.pass b/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveColor.pass index 94e42f9202..baffbef6f3 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveColor.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveColor.pass @@ -50,6 +50,13 @@ "Attachment": "ResolvedOutput" } } + ], + "FallbackConnections": [ + // used in non-MSAA pipelines when the resolve is disabled + { + "Input" : "Input", + "Output" : "Output" + } ] } } diff --git a/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveCustom.pass b/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveCustom.pass index c9f93b433d..5fee65640f 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveCustom.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveCustom.pass @@ -5,7 +5,7 @@ "ClassData": { "PassTemplate": { "Name": "MSAAResolveCustomTemplate", - "PassClass": "FullScreenTriangle", + "PassClass": "MSAAResolveFullScreenPass", "Slots": [ { "Name": "Input", @@ -48,6 +48,13 @@ } } ], + "FallbackConnections": [ + // used in non-MSAA pipelines when the resolve is disabled + { + "Input" : "Input", + "Output" : "Output" + } + ], "PassData": { "$type": "FullscreenTrianglePassData", "ShaderAsset": { diff --git a/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveDepth.pass b/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveDepth.pass index 738f83c168..9edcf17cf6 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveDepth.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/MSAAResolveDepth.pass @@ -5,7 +5,7 @@ "ClassData": { "PassTemplate": { "Name": "MSAAResolveDepthTemplate", - "PassClass": "FullScreenTriangle", + "PassClass": "MSAAResolveFullScreenPass", "Slots": [ { "Name": "Input", @@ -54,6 +54,13 @@ } } ], + "FallbackConnections": [ + // used in non-MSAA pipelines when the resolve is disabled + { + "Input" : "Input", + "Output" : "Output" + } + ], "PassData": { "$type": "FullscreenTrianglePassData", "ShaderAsset": { diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseComposite.shader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseComposite.shader index f074dcb0dd..1593f0bb66 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseComposite.shader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseComposite.shader @@ -52,5 +52,14 @@ "type": "Fragment" } ] - } + }, + + "Supervariants": + [ + { + "Name": "NoMSAA", + "PlusArguments": "--no-ms", + "MinusArguments": "" + } + ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseGlobalFullscreen.shader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseGlobalFullscreen.shader index 06967548bb..3d4b711f63 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseGlobalFullscreen.shader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseGlobalFullscreen.shader @@ -52,5 +52,14 @@ "type": "Fragment" } ] - } + }, + + "Supervariants": + [ + { + "Name": "NoMSAA", + "PlusArguments": "--no-ms", + "MinusArguments": "" + } + ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridDownsample.shader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridDownsample.shader index 372ba59637..dff0f755d0 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridDownsample.shader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridDownsample.shader @@ -30,5 +30,14 @@ "type": "Fragment" } ] - } + }, + + "Supervariants": + [ + { + "Name": "NoMSAA", + "PlusArguments": "--no-ms", + "MinusArguments": "" + } + ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/LightCulling/LightCullingTilePrepare.shader b/Gems/Atom/Feature/Common/Assets/Shaders/LightCulling/LightCullingTilePrepare.shader index d101424e65..070bc8e2bc 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/LightCulling/LightCullingTilePrepare.shader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/LightCulling/LightCullingTilePrepare.shader @@ -15,5 +15,14 @@ "type" : "Compute" } ] - } + }, + + "Supervariants": + [ + { + "Name": "NoMSAA", + "PlusArguments": "--no-ms", + "MinusArguments": "" + } + ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionComposite.shader b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionComposite.shader index c1d272e857..847bf5e300 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionComposite.shader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionComposite.shader @@ -49,5 +49,14 @@ "type": "Fragment" } ] - } + }, + + "Supervariants": + [ + { + "Name": "NoMSAA", + "PlusArguments": "--no-ms", + "MinusArguments": "" + } + ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionGlobalFullscreen.shader b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionGlobalFullscreen.shader index 069700191a..445a29c74f 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionGlobalFullscreen.shader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionGlobalFullscreen.shader @@ -40,5 +40,14 @@ "type": "Fragment" } ] - } + }, + + "Supervariants": + [ + { + "Name": "NoMSAA", + "PlusArguments": "--no-ms", + "MinusArguments": "" + } + ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeBlendWeight.shader b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeBlendWeight.shader index 645f635743..1da653f1e7 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeBlendWeight.shader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeBlendWeight.shader @@ -49,5 +49,14 @@ "type": "Fragment" } ] - } + }, + + "Supervariants": + [ + { + "Name": "NoMSAA", + "PlusArguments": "--no-ms", + "MinusArguments": "" + } + ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeRenderInner.shader b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeRenderInner.shader index 24ba5c250b..76cab60b3c 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeRenderInner.shader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeRenderInner.shader @@ -42,5 +42,14 @@ "type": "Fragment" } ] - } + }, + + "Supervariants": + [ + { + "Name": "NoMSAA", + "PlusArguments": "--no-ms", + "MinusArguments": "" + } + ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeRenderOuter.shader b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeRenderOuter.shader index 68a2344fb5..9e60a5faf9 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeRenderOuter.shader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeRenderOuter.shader @@ -49,5 +49,14 @@ "type": "Fragment" } ] - } + }, + + "Supervariants": + [ + { + "Name": "NoMSAA", + "PlusArguments": "--no-ms", + "MinusArguments": "" + } + ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeStencil.shader b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeStencil.shader index c4a0bb3c8b..538d746fba 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeStencil.shader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionProbeStencil.shader @@ -47,5 +47,14 @@ "type": "Vertex" } ] - } + }, + + "Supervariants": + [ + { + "Name": "NoMSAA", + "PlusArguments": "--no-ms", + "MinusArguments": "" + } + ] } diff --git a/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp index 6fe6cf1f88..b9b4699ec7 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp @@ -684,7 +684,7 @@ namespace AZ if (!m_shaderResourceGroup) { auto& shaderAsset = material->GetAsset()->GetMaterialTypeAsset()->GetShaderAssetForObjectSrg(); - m_shaderResourceGroup = RPI::ShaderResourceGroup::Create(shaderAsset, RPI::DefaultSupervariantIndex, objectSrgLayout->GetName()); + m_shaderResourceGroup = RPI::ShaderResourceGroup::Create(shaderAsset, objectSrgLayout->GetName()); if (!m_shaderResourceGroup) { AZ_Warning("MeshFeatureProcessor", false, "Failed to create a new shader resource group, skipping."); diff --git a/Gems/Atom/Feature/Common/Code/Source/RayTracing/RayTracingFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/RayTracing/RayTracingFeatureProcessor.cpp index 3023e06b50..f27c9d4e0d 100644 --- a/Gems/Atom/Feature/Common/Code/Source/RayTracing/RayTracingFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/RayTracing/RayTracingFeatureProcessor.cpp @@ -74,12 +74,12 @@ namespace AZ } // create the RayTracingSceneSrg - m_rayTracingSceneSrg = RPI::ShaderResourceGroup::Create(m_rayTracingSrgAsset, RPI::DefaultSupervariantIndex, Name("RayTracingSceneSrg")); + m_rayTracingSceneSrg = RPI::ShaderResourceGroup::Create(m_rayTracingSrgAsset, Name("RayTracingSceneSrg")); AZ_Assert(m_rayTracingSceneSrg, "Failed to create RayTracingSceneSrg"); // create the RayTracingMaterialSrg const AZ::Name rayTracingMaterialSrgName("RayTracingMaterialSrg"); - m_rayTracingMaterialSrg = RPI::ShaderResourceGroup::Create(m_rayTracingSrgAsset, RPI::DefaultSupervariantIndex, Name("RayTracingMaterialSrg")); + m_rayTracingMaterialSrg = RPI::ShaderResourceGroup::Create(m_rayTracingSrgAsset, Name("RayTracingMaterialSrg")); AZ_Assert(m_rayTracingMaterialSrg, "Failed to create RayTracingMaterialSrg"); } diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/MSAAResolvePass.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/MSAAResolvePass.h index 71776982b3..d70bb6e134 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/MSAAResolvePass.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/MSAAResolvePass.h @@ -42,6 +42,7 @@ namespace AZ // Pass behavior overrides... void BuildInternal() override; void FrameBeginInternal(FramePrepareParams params) override; + bool IsEnabled() const override; private: diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.h new file mode 100644 index 0000000000..e9337962b1 --- /dev/null +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.h @@ -0,0 +1,41 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ +#pragma once + +#include +#include + +namespace AZ +{ + namespace RPI + { + //! This pass allows the use of a custom fullscreen MSAA resolve pass shader. + class MSAAResolveFullScreenPass + : public RPI::FullscreenTrianglePass + { + AZ_RPI_PASS(MSAAResolveFullScreenPass); + + public: + AZ_RTTI(RPI::MSAAResolveFullScreenPass, "{998FCF6D-5441-4C59-89EC-795CFB803912}", FullscreenTrianglePass); + AZ_CLASS_ALLOCATOR(RPI::MSAAResolveFullScreenPass, SystemAllocator, 0); + + //! Creates a new pass without a PassTemplate + static RPI::Ptr Create(const RPI::PassDescriptor& descriptor); + + private: + explicit MSAAResolveFullScreenPass(const RPI::PassDescriptor& descriptor); + + // Pass Overrides... + bool IsEnabled() const override; + }; + } // namespace RPI +} // namespace AZ diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/Shader.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/Shader.h index c31f6b41b0..d6f105e323 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/Shader.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/Shader.h @@ -141,6 +141,11 @@ namespace AZ //! This tag corresponds to the ShaderAsset object's DrawListName. RHI::DrawListTag GetDrawListTag() const; + //! Changes the supervariant of the shader to the specified supervariantIndex. + //! [GFX TODO][ATOM-15813]: this can be removed when the shader InstanceDatabase can support multiple shader + //! instances with different supervariants. + void ChangeSupervariant(SupervariantIndex supervariantIndex); + private: explicit Shader(const SupervariantIndex& supervariantIndex) : m_supervariantIndex(supervariantIndex){}; Shader() = delete; diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderResourceGroup.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderResourceGroup.h index fb2b443ca5..ec5e4c2735 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderResourceGroup.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderResourceGroup.h @@ -61,6 +61,12 @@ namespace AZ AZ_CLASS_ALLOCATOR(ShaderResourceGroup, AZ::SystemAllocator, 0); /// Instantiates a unique shader resource group instance using its paired asset but with a random InstanceId. + /// This version uses the system-wide supervariant (if available) specified by the ShaderSystem or the Default supervariant. + static Data::Instance Create( + const Data::Asset& shaderAsset, const AZ::Name& srgName); + + /// Instantiates a unique shader resource group instance using its paired asset but with a random InstanceId. + /// This version uses the supervariant specified by the caller. static Data::Instance Create( const Data::Asset& shaderAsset, const SupervariantIndex& supervariantIndex, const AZ::Name& srgName); diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderSystem.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderSystem.h index 362e5fec72..51c776212d 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderSystem.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderSystem.h @@ -45,15 +45,19 @@ namespace AZ ShaderOptionValue GetGlobalShaderOption(const AZ::Name& shaderOptionName) override; const GlobalShaderOptionMap& GetGlobalShaderOptions() const override; void Connect(GlobalShaderOptionUpdatedEvent::Handler& handler) override; + void SetSupervariantName(const AZ::Name& supervariantName) override; + const AZ::Name& GetSupervariantName() const override; /////////////////////////////////////////////////////////////////// private: AZStd::unordered_map m_globalShaderOptionValues; GlobalShaderOptionUpdatedEvent m_globalShaderOptionUpdatedEvent; ShaderVariantAsyncLoader m_shaderVariantAsyncLoader; + + //! The ShaderSystem supervariantName is used by the ShaderAsset to search for an additional supervariant permutation. + //! This is done by appending the supervariantName set here to the user-specified supervariant name. + //! Currently this is used for NoMSAA supervariant support. + AZ::Name m_supervariantName; }; - - - } // namespace RPI } // namespace AZ diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderSystemInterface.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderSystemInterface.h index 5d2bf97578..9b0cce85bf 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderSystemInterface.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/ShaderSystemInterface.h @@ -47,6 +47,12 @@ namespace AZ //! Connect a handler for GlobalShaderOptionUpdatedEvent's virtual void Connect(GlobalShaderOptionUpdatedEvent::Handler& handler) = 0; + + //! The ShaderSystem supervariantName is used by the ShaderAsset to search for an additional supervariant permutation. + //! This is done by appending the supervariantName set here to the user-specified supervariant name. + //! Currently this is used for NoMSAA supervariant support. + virtual void SetSupervariantName(const AZ::Name& supervariantName) = 0; + virtual const AZ::Name& GetSupervariantName() const = 0; }; } // namespace RPI diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAsset.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAsset.h index 569358e642..699151d96c 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAsset.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAsset.h @@ -105,6 +105,8 @@ namespace AZ //! Returns the shader option group layout. const ShaderOptionGroupLayout* GetShaderOptionGroupLayout() const; + //! Returns the supervariant index from the specified name. + //! Note that this will append the system supervariant name from RPI::ShaderSystem when searching. SupervariantIndex GetSupervariantIndex(const AZ::Name& supervariantName) const; //! This function should be your one stop shop to get a ShaderVariantAsset. @@ -141,22 +143,15 @@ namespace AZ Data::Asset GetRootVariant() const { return GetRootVariant(DefaultSupervariantIndex); } - //! Finds and returns the shader resource group asset with the requested name. Returns an empty handle if no matching group was - //! found. + //! Finds and returns the shader resource group asset with the requested name. Returns an empty handle if no matching group was found. const RHI::Ptr& FindShaderResourceGroupLayout( const Name& shaderResourceGroupName, SupervariantIndex supervariantIndex) const; - const RHI::Ptr& FindShaderResourceGroupLayout(const Name& shaderResourceGroupName) const - { - return FindShaderResourceGroupLayout(shaderResourceGroupName, DefaultSupervariantIndex); - } + const RHI::Ptr& FindShaderResourceGroupLayout(const Name& shaderResourceGroupName) const; //! Finds and returns the shader resource group layout associated with the requested binding slot. Returns an empty handle if no matching srg was found. const RHI::Ptr& FindShaderResourceGroupLayout( uint32_t bindingSlot, SupervariantIndex supervariantIndex) const; - const RHI::Ptr& FindShaderResourceGroupLayout(uint32_t bindingSlot) const - { - return FindShaderResourceGroupLayout(bindingSlot, DefaultSupervariantIndex); - } + const RHI::Ptr& FindShaderResourceGroupLayout(uint32_t bindingSlot) const; //! Finds and returns the shader resource group layout designated as a ShaderVariantKey fallback. const RHI::Ptr& FindFallbackShaderResourceGroupLayout( SupervariantIndex supervariantIndex) const; @@ -287,6 +282,8 @@ namespace AZ Supervariant* GetSupervariant(SupervariantIndex supervariantIndex); const Supervariant* GetSupervariant(SupervariantIndex supervariantIndex) const; + //! Search for a supervariant index by name. + SupervariantIndex GetSupervariantIndexInternal(AZ::Name supervariantName) const; //! The name is the stem of the source .shader file. Name m_name; diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderCommonTypes.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderCommonTypes.h index 6d42ac386e..d5d1d0bddc 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderCommonTypes.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderCommonTypes.h @@ -37,6 +37,9 @@ namespace AZ //! in the list of supervariants owned by the ShaderAsset. static const SupervariantIndex DefaultSupervariantIndex(0); + //! The NoMSAA supervariant is auto-generated by AZSLc. + static const char* NoMsaaSupervariantName = "NoMSAA"; + static const SupervariantIndex InvalidSupervariantIndex; enum class ShaderStageType : uint32_t diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Material/Material.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Material/Material.cpp index 4d134257e5..ca1ff8b13e 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Material/Material.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Material/Material.cpp @@ -69,7 +69,7 @@ namespace AZ if (srgLayout) { auto shaderAsset = m_materialAsset->GetMaterialTypeAsset()->GetShaderAssetForMaterialSrg(); - m_shaderResourceGroup = ShaderResourceGroup::Create(shaderAsset, DefaultSupervariantIndex, srgLayout->GetName()); + m_shaderResourceGroup = ShaderResourceGroup::Create(shaderAsset, srgLayout->GetName()); if (m_shaderResourceGroup) { diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/MSAAResolvePass.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/MSAAResolvePass.cpp index e457cb4992..03e5be4ee6 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/MSAAResolvePass.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/MSAAResolvePass.cpp @@ -11,6 +11,7 @@ */ #include +#include #include #include @@ -76,5 +77,17 @@ namespace AZ void MSAAResolvePass::BuildCommandListInternal([[maybe_unused]] const RHI::FrameGraphExecuteContext& context) { } + + bool MSAAResolvePass::IsEnabled() const + { + // check Pass base class first to see if the Pass is explicitly disabled + if (!Pass::IsEnabled()) + { + return false; + } + + // check render pipeline MSAA sample count + return (m_pipeline->GetRenderSettings().m_multisampleState.m_samples > 1); + } } // namespace RPI } // namespace AZ 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 90df206a3d..e96ce25844 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,7 @@ namespace AZ AddPassCreator(Name("FullScreenTriangle"), &FullscreenTrianglePass::Create); AddPassCreator(Name("ComputePass"), &ComputePass::Create); AddPassCreator(Name("MSAAResolvePass"), &MSAAResolvePass::Create); + AddPassCreator(Name("MSAAResolveFullScreenPass"), &MSAAResolveFullScreenPass::Create); AddPassCreator(Name("DownsampleMipChainPass"), &DownsampleMipChainPass::Create); AddPassCreator(Name("EnvironmentCubeMapPass"), &EnvironmentCubeMapPass::Create); AddPassCreator(Name("RenderToTexturePass"), &RenderToTexturePass::Create); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/RasterPass.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/RasterPass.cpp index 13f2784a2d..59e7db427a 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/RasterPass.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/RasterPass.cpp @@ -64,11 +64,10 @@ namespace AZ if (shaderAsset) { - auto supervariantIndex = DefaultSupervariantIndex; - const auto srgLayout = shaderAsset->FindShaderResourceGroupLayout(SrgBindingSlot::Pass, supervariantIndex); + const auto srgLayout = shaderAsset->FindShaderResourceGroupLayout(SrgBindingSlot::Pass); if (srgLayout) { - m_shaderResourceGroup = ShaderResourceGroup::Create(shaderAsset, supervariantIndex, srgLayout->GetName()); + m_shaderResourceGroup = ShaderResourceGroup::Create(shaderAsset, srgLayout->GetName()); AZ_Assert( m_shaderResourceGroup, "[RasterPass '%s']: Failed to create SRG from shader asset '%s'", GetPathName().GetCStr(), diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.cpp new file mode 100644 index 0000000000..bb2d8d6a21 --- /dev/null +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.cpp @@ -0,0 +1,44 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include +#include + +namespace AZ +{ + namespace RPI + { + RPI::Ptr MSAAResolveFullScreenPass::Create(const RPI::PassDescriptor& descriptor) + { + RPI::Ptr pass = aznew MSAAResolveFullScreenPass(descriptor); + return AZStd::move(pass); + } + + MSAAResolveFullScreenPass::MSAAResolveFullScreenPass(const RPI::PassDescriptor& descriptor) + : RPI::FullscreenTrianglePass(descriptor) + { + } + + bool MSAAResolveFullScreenPass::IsEnabled() const + { + // check Pass base class first to see if the Pass is explicitly disabled + if (!Pass::IsEnabled()) + { + return false; + } + + // check render pipeline MSAA sample count + return (m_pipeline->GetRenderSettings().m_multisampleState.m_samples > 1); + } + } // namespace RPI +} // namespace AZ diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp index c6457e2c2e..53ae52f129 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp @@ -46,7 +46,7 @@ namespace AZ if (sceneSrgLayout) { auto shaderAsset = RPISystemInterface::Get()->GetCommonShaderAssetForSrgs(); - scene->m_srg = ShaderResourceGroup::Create(shaderAsset, DefaultSupervariantIndex, sceneSrgLayout->GetName()); + scene->m_srg = ShaderResourceGroup::Create(shaderAsset, sceneSrgLayout->GetName()); } return ScenePtr(scene); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/Shader.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/Shader.cpp index 41661fe0dc..13405a3ae9 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/Shader.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/Shader.cpp @@ -21,6 +21,7 @@ #include #include +#include #include namespace AZ @@ -32,6 +33,19 @@ namespace AZ auto anySupervariantName = AZStd::any(supervariantName); Data::Instance shaderInstance = Data::InstanceDatabase::Instance().FindOrCreate( Data::InstanceId::CreateFromAssetId(shaderAsset.GetId()), shaderAsset, &anySupervariantName); + + if (shaderInstance) + { + // [GFX TODO][ATOM-15813] Change InstanceDatabase to support multiple instances with different supervariants. + // At this time we do not support multiple supervariants loaded for a shader asset simultaneously, so if this shader + // is referring to the wrong supervariant we need to change it to the correct one. + SupervariantIndex supervariantIndex = shaderAsset->GetSupervariantIndex(supervariantName); + if (supervariantIndex.IsValid() && shaderInstance->GetSupervariantIndex() != supervariantIndex) + { + shaderInstance->ChangeSupervariant(supervariantIndex); + } + } + return shaderInstance; } @@ -67,7 +81,6 @@ namespace AZ RHI::ResultCode Shader::Init(ShaderAsset& shaderAsset) { - AZ_Assert(m_supervariantIndex != InvalidSupervariantIndex, "Invalid supervariant index"); Data::AssetBus::Handler::BusDisconnect(); ShaderReloadNotificationBus::Handler::BusDisconnect(); ShaderVariantFinderNotificationBus::Handler::BusDisconnect(); @@ -424,5 +437,15 @@ namespace AZ { return m_drawListTag; } + + void Shader::ChangeSupervariant(SupervariantIndex supervariantIndex) + { + if (supervariantIndex != m_supervariantIndex) + { + m_supervariantIndex = supervariantIndex; + Init(*m_asset); + } + } + } // namespace RPI } // namespace AZ diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderResourceGroup.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderResourceGroup.cpp index f63165495f..b52fffbdb0 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderResourceGroup.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderResourceGroup.cpp @@ -40,6 +40,19 @@ namespace AZ return Data::InstanceId::CreateData(idString.data(), idString.size()); } + Data::Instance ShaderResourceGroup::Create( + const Data::Asset& shaderAsset, const AZ::Name& srgName) + { + // retrieve the supervariantIndex by searching for the default supervariant name, this will + // allow the shader asset to properly handle the RPI::ShaderSystem supervariant + SupervariantIndex supervariantIndex = shaderAsset->GetSupervariantIndex(AZ::Name("")); + + SrgInitParams initParams{ supervariantIndex, srgName }; + auto anyInitParams = AZStd::any(initParams); + return Data::InstanceDatabase::Instance().FindOrCreate( + Data::InstanceId::CreateRandom(), shaderAsset, &anyInitParams); + } + Data::Instance ShaderResourceGroup::Create( const Data::Asset& shaderAsset, const SupervariantIndex& supervariantIndex, const AZ::Name& srgName) { diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderSystem.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderSystem.cpp index d94760d243..1058a7efc2 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderSystem.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderSystem.cpp @@ -148,6 +148,16 @@ namespace AZ { handler.Connect(m_globalShaderOptionUpdatedEvent); } + + void ShaderSystem::SetSupervariantName(const AZ::Name& supervariantName) + { + m_supervariantName = supervariantName; + } + + const AZ::Name& ShaderSystem::GetSupervariantName() const + { + return m_supervariantName; + } /////////////////////////////////////////////////////////////////// } // namespace RPI diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/View.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/View.cpp index f86a51124b..fcc46565fa 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/View.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/View.cpp @@ -59,7 +59,7 @@ namespace AZ if (viewSrgShaderAsset.IsReady()) { - m_shaderResourceGroup = ShaderResourceGroup::Create(viewSrgShaderAsset, DefaultSupervariantIndex, RPISystemInterface::Get()->GetViewSrgLayout()->GetName()); + m_shaderResourceGroup = ShaderResourceGroup::Create(viewSrgShaderAsset, RPISystemInterface::Get()->GetViewSrgLayout()->GetName()); } #if AZ_TRAIT_MASKED_OCCLUSION_CULLING_SUPPORTED m_maskedOcclusionCulling = MaskedOcclusionCulling::Create(); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAsset.cpp b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAsset.cpp index 8ecfbe3036..3e3f3faad8 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAsset.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAsset.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -149,18 +150,28 @@ namespace AZ SupervariantIndex ShaderAsset::GetSupervariantIndex(const AZ::Name& supervariantName) const { - const auto& supervariants = GetCurrentShaderApiData().m_supervariants; - const uint32_t supervariantCount = supervariants.size(); - for (uint32_t index = 0; index < supervariantCount; ++index) - { - if (supervariants[index].m_name == supervariantName) - { - return SupervariantIndex{index}; - } - } - return InvalidSupervariantIndex; - } + SupervariantIndex supervariantIndex = InvalidSupervariantIndex; + // check for an RPI ShaderSystem supervariant + RPI::ShaderSystemInterface* shaderSystemInterface = ShaderSystemInterface::Get(); + if (shaderSystemInterface && !shaderSystemInterface->GetSupervariantName().IsEmpty()) + { + // search for the combined requested name and system supervariant name + // Note: the shader may not support this supervariant, if it doesn't we will + // fallback to the requested name below + AZStd::string combinedName = supervariantName.GetCStr(); + combinedName.append(shaderSystemInterface->GetSupervariantName().GetCStr()); + supervariantIndex = GetSupervariantIndexInternal(AZ::Name(combinedName)); + } + + if (supervariantIndex == InvalidSupervariantIndex) + { + // search for the requested name + supervariantIndex = GetSupervariantIndexInternal(supervariantName); + } + + return supervariantIndex; + } Data::Asset ShaderAsset::GetVariant( const ShaderVariantId& shaderVariantId, SupervariantIndex supervariantIndex) @@ -297,6 +308,25 @@ namespace AZ return RHI::NullSrgLayout; } + const RHI::Ptr& ShaderAsset::FindShaderResourceGroupLayout(const Name& shaderResourceGroupName) const + { + SupervariantIndex supervariantIndex = DefaultSupervariantIndex; + + // check for an RPI ShaderSystem specified supervariant + // Note: we can just search for the system supervariant name, since the default supervariant is "", so no need to append + RPI::ShaderSystemInterface* shaderSystemInterface = ShaderSystemInterface::Get(); + if (shaderSystemInterface && !shaderSystemInterface->GetSupervariantName().IsEmpty()) + { + SupervariantIndex systemSupervariantIndex = GetSupervariantIndexInternal(shaderSystemInterface->GetSupervariantName()); + if (systemSupervariantIndex.IsValid()) + { + supervariantIndex = systemSupervariantIndex; + } + } + + return FindShaderResourceGroupLayout(shaderResourceGroupName, supervariantIndex); + } + const RHI::Ptr& ShaderAsset::FindShaderResourceGroupLayout( uint32_t bindingSlot, SupervariantIndex supervariantIndex) const { @@ -320,6 +350,25 @@ namespace AZ return RHI::NullSrgLayout; } + const RHI::Ptr& ShaderAsset::FindShaderResourceGroupLayout(uint32_t bindingSlot) const + { + SupervariantIndex supervariantIndex = DefaultSupervariantIndex; + + // check for an RPI ShaderSystem specified supervariant + // Note: we can just search for the system supervariant name, since the default supervariant is "", so no need to append + RPI::ShaderSystemInterface* shaderSystemInterface = ShaderSystemInterface::Get(); + if (shaderSystemInterface && !shaderSystemInterface->GetSupervariantName().IsEmpty()) + { + SupervariantIndex systemSupervariantIndex = GetSupervariantIndexInternal(shaderSystemInterface->GetSupervariantName()); + if (systemSupervariantIndex.IsValid()) + { + supervariantIndex = systemSupervariantIndex; + } + } + + return FindShaderResourceGroupLayout(bindingSlot, supervariantIndex); + } + const RHI::Ptr& ShaderAsset::FindFallbackShaderResourceGroupLayout( SupervariantIndex supervariantIndex) const { @@ -468,6 +517,20 @@ namespace AZ return &supervariants[index]; } + SupervariantIndex ShaderAsset::GetSupervariantIndexInternal(AZ::Name supervariantName) const + { + const auto& supervariants = GetCurrentShaderApiData().m_supervariants; + const uint32_t supervariantCount = supervariants.size(); + for (uint32_t index = 0; index < supervariantCount; ++index) + { + if (supervariants[index].m_name == supervariantName) + { + return SupervariantIndex{ index }; + } + } + return InvalidSupervariantIndex; + } + bool ShaderAsset::SelectShaderApiData() { // Use the current RHI that is active to select which shader data to use. diff --git a/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake b/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake index 8f6e5dbeeb..933fd66dbd 100644 --- a/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake +++ b/Gems/Atom/RPI/Code/atom_rpi_public_files.cmake @@ -79,6 +79,7 @@ set(FILES Include/Atom/RPI.Public/Pass/Specific/DownsampleMipChainPass.h Include/Atom/RPI.Public/Pass/Specific/ImageAttachmentPreviewPass.h Include/Atom/RPI.Public/Pass/Specific/EnvironmentCubeMapPass.h + Include/Atom/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.h Include/Atom/RPI.Public/Pass/Specific/RenderToTexturePass.h Include/Atom/RPI.Public/Pass/Specific/SelectorPass.h Include/Atom/RPI.Public/Pass/Specific/SwapChainPass.h @@ -154,6 +155,7 @@ set(FILES Source/RPI.Public/Pass/Specific/DownsampleMipChainPass.cpp Source/RPI.Public/Pass/Specific/ImageAttachmentPreviewPass.cpp Source/RPI.Public/Pass/Specific/EnvironmentCubeMapPass.cpp + Source/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.cpp Source/RPI.Public/Pass/Specific/RenderToTexturePass.cpp Source/RPI.Public/Pass/Specific/SelectorPass.cpp Source/RPI.Public/Pass/Specific/SwapChainPass.cpp