NoMSAA supervariant support
Added a ShaderSystem supervariant to provide a system-wide supervariant name. Changed ShaderAsset to append the system-wide supervariant name when searching for supervariants. Added the NoMSAA supervariant to several shaders.
This commit is contained in:
@@ -50,6 +50,13 @@
|
||||
"Attachment": "ResolvedOutput"
|
||||
}
|
||||
}
|
||||
],
|
||||
"FallbackConnections": [
|
||||
// used in non-MSAA pipelines when the resolve is disabled
|
||||
{
|
||||
"Input" : "Input",
|
||||
"Output" : "Output"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,13 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
"FallbackConnections": [
|
||||
// used in non-MSAA pipelines when the resolve is disabled
|
||||
{
|
||||
"Input" : "Input",
|
||||
"Output" : "Output"
|
||||
}
|
||||
],
|
||||
"PassData": {
|
||||
"$type": "FullscreenTrianglePassData",
|
||||
"ShaderAsset": {
|
||||
|
||||
@@ -54,6 +54,13 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
"FallbackConnections": [
|
||||
// used in non-MSAA pipelines when the resolve is disabled
|
||||
{
|
||||
"Input" : "Input",
|
||||
"Output" : "Output"
|
||||
}
|
||||
],
|
||||
"PassData": {
|
||||
"$type": "FullscreenTrianglePassData",
|
||||
"ShaderAsset": {
|
||||
|
||||
+10
-1
@@ -52,5 +52,14 @@
|
||||
"type": "Fragment"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"Supervariants":
|
||||
[
|
||||
{
|
||||
"Name": "NoMSAA",
|
||||
"PlusArguments": "--no-ms",
|
||||
"MinusArguments": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+10
-1
@@ -52,5 +52,14 @@
|
||||
"type": "Fragment"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"Supervariants":
|
||||
[
|
||||
{
|
||||
"Name": "NoMSAA",
|
||||
"PlusArguments": "--no-ms",
|
||||
"MinusArguments": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+10
-1
@@ -30,5 +30,14 @@
|
||||
"type": "Fragment"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"Supervariants":
|
||||
[
|
||||
{
|
||||
"Name": "NoMSAA",
|
||||
"PlusArguments": "--no-ms",
|
||||
"MinusArguments": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+10
-1
@@ -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": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+10
-1
@@ -40,5 +40,14 @@
|
||||
"type": "Fragment"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"Supervariants":
|
||||
[
|
||||
{
|
||||
"Name": "NoMSAA",
|
||||
"PlusArguments": "--no-ms",
|
||||
"MinusArguments": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+10
-1
@@ -49,5 +49,14 @@
|
||||
"type": "Fragment"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"Supervariants":
|
||||
[
|
||||
{
|
||||
"Name": "NoMSAA",
|
||||
"PlusArguments": "--no-ms",
|
||||
"MinusArguments": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+10
-1
@@ -42,5 +42,14 @@
|
||||
"type": "Fragment"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"Supervariants":
|
||||
[
|
||||
{
|
||||
"Name": "NoMSAA",
|
||||
"PlusArguments": "--no-ms",
|
||||
"MinusArguments": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+10
-1
@@ -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": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -658,7 +658,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");
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,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 appropriate 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
|
||||
|
||||
@@ -103,6 +103,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.
|
||||
@@ -139,22 +141,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;
|
||||
@@ -277,6 +272,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)
|
||||
{
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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/ShaderReloadNotificationBus.h>
|
||||
#include <Atom/RPI.Public/Shader/ShaderReloadDebugTracker.h>
|
||||
|
||||
@@ -33,6 +34,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;
|
||||
}
|
||||
|
||||
@@ -68,8 +82,6 @@ namespace AZ
|
||||
|
||||
RHI::ResultCode Shader::Init(ShaderAsset& shaderAsset)
|
||||
{
|
||||
AZ_Assert(m_supervariantIndex != InvalidSupervariantIndex, "Invalid supervariant index");
|
||||
|
||||
ShaderVariantFinderNotificationBus::Handler::BusDisconnect();
|
||||
ShaderVariantFinderNotificationBus::Handler::BusConnect(shaderAsset.GetId());
|
||||
|
||||
@@ -395,5 +407,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>
|
||||
|
||||
@@ -148,18 +149,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)
|
||||
@@ -296,6 +307,24 @@ 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
|
||||
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
|
||||
{
|
||||
@@ -319,6 +348,24 @@ 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
|
||||
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
|
||||
{
|
||||
@@ -467,6 +514,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::FinalizeAfterLoad()
|
||||
{
|
||||
// Use the current RHI that is active to select which shader data to use.
|
||||
|
||||
Reference in New Issue
Block a user