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:
Doug McDiarmid
2021-06-18 16:39:32 -07:00
parent e22d21f4b6
commit dc1d34c83f
29 changed files with 282 additions and 45 deletions
@@ -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