Merge pull request #1450 from aws-lumberyard-dev/Atom/dmcdiar/ATOM-5702

[ATOM-5702] MSAA sample is missing lighting when viewing the non-MSAA mode
This commit is contained in:
dmcdiarmid-ly
2021-06-21 21:08:17 -07:00
committed by GitHub
35 changed files with 389 additions and 46 deletions
@@ -50,6 +50,13 @@
"Attachment": "ResolvedOutput"
}
}
],
"FallbackConnections": [
// used in non-MSAA pipelines when the resolve is disabled
{
"Input" : "Input",
"Output" : "Output"
}
]
}
}
@@ -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": {
@@ -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": {
@@ -52,5 +52,14 @@
"type": "Fragment"
}
]
}
},
"Supervariants":
[
{
"Name": "NoMSAA",
"PlusArguments": "--no-ms",
"MinusArguments": ""
}
]
}
@@ -52,5 +52,14 @@
"type": "Fragment"
}
]
}
},
"Supervariants":
[
{
"Name": "NoMSAA",
"PlusArguments": "--no-ms",
"MinusArguments": ""
}
]
}
@@ -30,5 +30,14 @@
"type": "Fragment"
}
]
}
},
"Supervariants":
[
{
"Name": "NoMSAA",
"PlusArguments": "--no-ms",
"MinusArguments": ""
}
]
}
@@ -15,5 +15,14 @@
"type" : "Compute"
}
]
}
},
"Supervariants":
[
{
"Name": "NoMSAA",
"PlusArguments": "--no-ms",
"MinusArguments": ""
}
]
}
@@ -49,5 +49,14 @@
"type": "Fragment"
}
]
}
},
"Supervariants":
[
{
"Name": "NoMSAA",
"PlusArguments": "--no-ms",
"MinusArguments": ""
}
]
}
@@ -40,5 +40,14 @@
"type": "Fragment"
}
]
}
},
"Supervariants":
[
{
"Name": "NoMSAA",
"PlusArguments": "--no-ms",
"MinusArguments": ""
}
]
}
@@ -49,5 +49,14 @@
"type": "Fragment"
}
]
}
},
"Supervariants":
[
{
"Name": "NoMSAA",
"PlusArguments": "--no-ms",
"MinusArguments": ""
}
]
}
@@ -42,5 +42,14 @@
"type": "Fragment"
}
]
}
},
"Supervariants":
[
{
"Name": "NoMSAA",
"PlusArguments": "--no-ms",
"MinusArguments": ""
}
]
}
@@ -49,5 +49,14 @@
"type": "Fragment"
}
]
}
},
"Supervariants":
[
{
"Name": "NoMSAA",
"PlusArguments": "--no-ms",
"MinusArguments": ""
}
]
}
@@ -47,5 +47,14 @@
"type": "Vertex"
}
]
}
},
"Supervariants":
[
{
"Name": "NoMSAA",
"PlusArguments": "--no-ms",
"MinusArguments": ""
}
]
}
@@ -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.");
@@ -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");
}
@@ -42,6 +42,7 @@ namespace AZ
// Pass behavior overrides...
void BuildInternal() override;
void FrameBeginInternal(FramePrepareParams params) override;
bool IsEnabled() const override;
private:
@@ -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 <Atom/RPI.Public/Pass/Pass.h>
#include <Atom/RPI.Public/Pass/FullscreenTrianglePass.h>
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<MSAAResolveFullScreenPass> Create(const RPI::PassDescriptor& descriptor);
private:
explicit MSAAResolveFullScreenPass(const RPI::PassDescriptor& descriptor);
// Pass Overrides...
bool IsEnabled() const override;
};
} // namespace RPI
} // namespace AZ
@@ -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;
@@ -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<ShaderResourceGroup> Create(
const Data::Asset<ShaderAsset>& 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<ShaderResourceGroup> Create(
const Data::Asset<ShaderAsset>& shaderAsset, const SupervariantIndex& supervariantIndex, const AZ::Name& srgName);
@@ -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<Name, ShaderOptionValue> 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
@@ -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
@@ -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<ShaderVariantAsset> 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<RHI::ShaderResourceGroupLayout>& FindShaderResourceGroupLayout(
const Name& shaderResourceGroupName, SupervariantIndex supervariantIndex) const;
const RHI::Ptr<RHI::ShaderResourceGroupLayout>& FindShaderResourceGroupLayout(const Name& shaderResourceGroupName) const
{
return FindShaderResourceGroupLayout(shaderResourceGroupName, DefaultSupervariantIndex);
}
const RHI::Ptr<RHI::ShaderResourceGroupLayout>& 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<RHI::ShaderResourceGroupLayout>& FindShaderResourceGroupLayout(
uint32_t bindingSlot, SupervariantIndex supervariantIndex) const;
const RHI::Ptr<RHI::ShaderResourceGroupLayout>& FindShaderResourceGroupLayout(uint32_t bindingSlot) const
{
return FindShaderResourceGroupLayout(bindingSlot, DefaultSupervariantIndex);
}
const RHI::Ptr<RHI::ShaderResourceGroupLayout>& FindShaderResourceGroupLayout(uint32_t bindingSlot) const;
//! Finds and returns the shader resource group layout designated as a ShaderVariantKey fallback.
const RHI::Ptr<RHI::ShaderResourceGroupLayout>& 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 <name>.shader file.
Name m_name;
@@ -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
@@ -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)
{
@@ -11,6 +11,7 @@
*/
#include <Atom/RPI.Public/Pass/MSAAResolvePass.h>
#include <Atom/RPI.Public/RenderPipeline.h>
#include <Atom/RPI.Reflect/Pass/PassTemplate.h>
#include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
@@ -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
@@ -23,6 +23,7 @@
#include <Atom/RPI.Public/Pass/PassFilter.h>
#include <Atom/RPI.Public/Pass/RasterPass.h>
#include <Atom/RPI.Public/Pass/MSAAResolvePass.h>
#include <Atom/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.h>
#include <Atom/RPI.Public/Pass/Specific/EnvironmentCubeMapPass.h>
#include <Atom/RPI.Public/Pass/Specific/RenderToTexturePass.h>
#include <Atom/RPI.Public/Pass/Specific/SelectorPass.h>
@@ -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);
@@ -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(),
@@ -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 <Atom/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.h>
#include <Atom/RPI.Public/Pass/Pass.h>
#include <Atom/RPI.Public/RenderPipeline.h>
namespace AZ
{
namespace RPI
{
RPI::Ptr<MSAAResolveFullScreenPass> MSAAResolveFullScreenPass::Create(const RPI::PassDescriptor& descriptor)
{
RPI::Ptr<MSAAResolveFullScreenPass> 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
@@ -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);
@@ -21,6 +21,7 @@
#include <AtomCore/Instance/InstanceDatabase.h>
#include <AzCore/Interface/Interface.h>
#include <Atom/RPI.Public/Shader/ShaderSystemInterface.h>
#include <Atom/RPI.Public/Shader/ShaderReloadDebugTracker.h>
namespace AZ
@@ -32,6 +33,19 @@ namespace AZ
auto anySupervariantName = AZStd::any(supervariantName);
Data::Instance<Shader> shaderInstance = Data::InstanceDatabase<Shader>::Instance().FindOrCreate(
Data::InstanceId::CreateFromAssetId(shaderAsset.GetId()), shaderAsset, &anySupervariantName);
if (shaderInstance)
{
// [GFX TODO][ATOM-15813] Change InstanceDatabase<Shader> 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
@@ -40,6 +40,19 @@ namespace AZ
return Data::InstanceId::CreateData(idString.data(), idString.size());
}
Data::Instance<ShaderResourceGroup> ShaderResourceGroup::Create(
const Data::Asset<ShaderAsset>& 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<ShaderResourceGroup>::Instance().FindOrCreate(
Data::InstanceId::CreateRandom(), shaderAsset, &anyInitParams);
}
Data::Instance<ShaderResourceGroup> ShaderResourceGroup::Create(
const Data::Asset<ShaderAsset>& shaderAsset, const SupervariantIndex& supervariantIndex, const AZ::Name& srgName)
{
@@ -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
@@ -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();
@@ -20,6 +20,7 @@
#include <AzCore/Interface/Interface.h>
#include <Atom/RPI.Reflect/Shader/IShaderVariantFinder.h>
#include <Atom/RPI.Public/Shader/ShaderSystem.h>
#include <Atom/RPI.Public/Shader/ShaderReloadDebugTracker.h>
#include <Atom/RPI.Public/Shader/ShaderReloadNotificationBus.h>
@@ -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<ShaderVariantAsset> ShaderAsset::GetVariant(
const ShaderVariantId& shaderVariantId, SupervariantIndex supervariantIndex)
@@ -297,6 +308,25 @@ namespace AZ
return RHI::NullSrgLayout;
}
const RHI::Ptr<RHI::ShaderResourceGroupLayout>& 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<RHI::ShaderResourceGroupLayout>& ShaderAsset::FindShaderResourceGroupLayout(
uint32_t bindingSlot, SupervariantIndex supervariantIndex) const
{
@@ -320,6 +350,25 @@ namespace AZ
return RHI::NullSrgLayout;
}
const RHI::Ptr<RHI::ShaderResourceGroupLayout>& 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<RHI::ShaderResourceGroupLayout>& 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.
@@ -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