Added new shader reinitialization signaling.

This was done while working on "ATOM-15728 Shader Hot Reload Fails in Debug Build", but it turned out these changes did not actually fix the issue (or any other known hot-reload issue). Still, these improvements are appropriate as they correct logical oversights.

ShaderVariant was not listening to asset reloads. It needs to know when the ShaderVariantAsset reload happens so it can reinitialize it's members as well as propagate reinitialization messages. I added a member for the ShaderAsset as the class needs this to reinitialize itself. So now the class listens for reloads of both the ShaderVariantAsset and the ShaderAsset.

Shader was not listening for ShaderAsset reinitialization events.

Updated the API for ShaderReloadNotificationBus's OnShaderVariantReinitialized to include the ShaderVariant which is the most relevant information (the other information wasn't really being used anyway).
This commit is contained in:
Chris Santora
2021-06-15 19:26:11 -07:00
parent 7bfc6dd7cb
commit c158ca178f
20 changed files with 103 additions and 50 deletions
@@ -145,7 +145,7 @@ namespace AZ
// ShaderReloadNotificationBus overrides...
void OnShaderReinitialized(const Shader& shader) override;
void OnShaderAssetReinitialized(const Data::Asset<ShaderAsset>& shaderAsset) override;
void OnShaderVariantReinitialized(const Shader& shader, const ShaderVariantId& shaderVariantId, ShaderVariantStableId shaderVariantStableId) override;
void OnShaderVariantReinitialized(const ShaderVariant& shaderVariant) override;
///////////////////////////////////////////////////////////////////
template<typename Type>
@@ -78,7 +78,7 @@ namespace AZ
// ShaderReloadNotificationBus::Handler overrides...
void OnShaderReinitialized(const Shader& shader) override;
void OnShaderAssetReinitialized(const Data::Asset<ShaderAsset>& shaderAsset) override;
void OnShaderVariantReinitialized(const Shader& shader, const ShaderVariantId& shaderVariantId, ShaderVariantStableId shaderVariantStableId) override;
void OnShaderVariantReinitialized(const ShaderVariant& shaderVariant) override;
void LoadShader();
PassDescriptor m_passDescriptor;
@@ -78,7 +78,7 @@ namespace AZ
// ShaderReloadNotificationBus overrides...
void OnShaderReinitialized(const Shader& shader) override;
void OnShaderAssetReinitialized(const Data::Asset<ShaderAsset>& shaderAsset) override;
void OnShaderVariantReinitialized(const Shader& shader, const ShaderVariantId& shaderVariantId, ShaderVariantStableId shaderVariantStableId) override;
void OnShaderVariantReinitialized(const ShaderVariant& shaderVariant) override;
///////////////////////////////////////////////////////////////////
void LoadShader();
@@ -88,7 +88,7 @@ namespace AZ
// ShaderReloadNotificationBus overrides...
void OnShaderReinitialized(const AZ::RPI::Shader& shader) override;
void OnShaderAssetReinitialized(const Data::Asset<ShaderAsset>& shaderAsset) override;
void OnShaderVariantReinitialized(const Shader& shader, const ShaderVariantId& shaderVariantId, ShaderVariantStableId shaderVariantStableId) override;
void OnShaderVariantReinitialized(const ShaderVariant& shaderVariant) override;
///////////////////////////////////////////////////////////////////
// Update shader variant from m_shader. It's called whenever shader, shader asset or shader variant were changed.
@@ -22,10 +22,11 @@ namespace AZ
{
class Shader;
class ShaderAsset;
class ShaderVariant;
/**
* Connect to this EBus to get notifications whenever a Data::Instance<Shader> reloads its ShaderAsset.
* The bus address is the AssetId of the ShaderAsset.
* Connect to this EBus to get notifications whenever a shader system class reinitializes itself.
* The bus address is the AssetId of the ShaderAsset, even when the thing being reinitialized is a ShaderVariant or other shader related class.
*/
class ShaderReloadNotifications
: public EBusTraits
@@ -35,7 +36,7 @@ namespace AZ
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
typedef Data::AssetId BusIdType;
typedef Data::AssetId BusIdType;
//////////////////////////////////////////////////////////////////////////
virtual ~ShaderReloadNotifications() {}
@@ -47,7 +48,7 @@ namespace AZ
virtual void OnShaderReinitialized(const Shader& shader) { AZ_UNUSED(shader); }
//! Called when a particular shader variant is reinitialized.
virtual void OnShaderVariantReinitialized(const Shader& shader, const ShaderVariantId& shaderVariantId, ShaderVariantStableId shaderVariantStableId) { AZ_UNUSED(shader); AZ_UNUSED(shaderVariantId); AZ_UNUSED(shaderVariantStableId); }
virtual void OnShaderVariantReinitialized(const ShaderVariant& shaderVariant) { AZ_UNUSED(shaderVariant); }
};
typedef EBus<ShaderReloadNotifications> ShaderReloadNotificationBus;
@@ -23,10 +23,12 @@ namespace AZ
//! the RHI::PipelineStateType of the parent Shader instance. For shaders on the raster
//! pipeline, the RHI::DrawFilterTag is also provided.
class ShaderVariant final
: public Data::AssetBus::MultiHandler
{
friend class Shader;
public:
ShaderVariant() = default;
virtual ~ShaderVariant();
AZ_DEFAULT_COPY_MOVE(ShaderVariant);
//! Fills a pipeline state descriptor with settings provided by the ShaderVariant. (Note that
@@ -54,12 +56,21 @@ namespace AZ
bool IsRootVariant() const { return m_shaderVariantAsset->IsRootVariant(); }
ShaderVariantStableId GetStableId() const { return m_shaderVariantAsset->GetStableId(); }
const Data::Asset<ShaderAsset>& GetShaderAsset() const { return m_shaderAsset; }
const Data::Asset<ShaderVariantAsset>& GetShaderVariantAsset() const { return m_shaderVariantAsset; }
private:
// Called by Shader. Initializes runtime data from asset data. Returns whether the call succeeded.
bool Init(
const ShaderAsset& shaderAsset,
Data::Asset<ShaderVariantAsset> shaderVariantAsset);
const Data::Asset<ShaderAsset>& shaderAsset,
const Data::Asset<ShaderVariantAsset>& shaderVariantAsset);
// AssetBus overrides...
void OnAssetReloaded(Data::Asset<Data::AssetData> asset) override;
//! A reference to the shader asset that this is a variant of.
Data::Asset<ShaderAsset> m_shaderAsset;
// Cached state from the asset to avoid an indirection.
RHI::PipelineStateType m_pipelineStateType = RHI::PipelineStateType::Count;