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:
@@ -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