Merge pull request #1314 from aws-lumberyard-dev/santorac/stabilization/2106/HotReloadFixes

Updated the usage of ShaderReloadDebugTracker to include the address of the object. This is necessary for debugging where multiple assets may be reloading at the same time. Also added a Printf function for generic messages at the current indent level.

This is specifically in support of:
ATOM-14613 Baseviewer MatertialHotReloadTest fails to change the color after turning blending on and off
ATOM-15728 Shader Hot Reload Fails in Debug Build
main
Chris Santora 5 years ago committed by GitHub
commit 0d45ec806c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -57,6 +57,20 @@ namespace AZ
} }
#endif #endif
} }
//! Prints a generic message at the appropriate indent level.
template<typename ... Args>
static void Printf([[maybe_unused]] const char* format, [[maybe_unused]] Args... args)
{
#ifdef AZ_ENABLE_SHADER_RELOAD_DEBUG_TRACKER
if (IsEnabled())
{
const AZStd::string message = AZStd::string::format(format, args...);
AZ_TracePrintf("ShaderReloadDebug", "%*s %s \n", s_indent, "", message.c_str());
}
#endif
}
//! Use this utility to call BeginSection(), and automatically call EndSection() when the object goes out of scope. //! Use this utility to call BeginSection(), and automatically call EndSection() when the object goes out of scope.
class ScopedSection final class ScopedSection final

@ -97,6 +97,7 @@ namespace AZ
ShaderReloadNotificationBus::MultiHandler::BusDisconnect(); ShaderReloadNotificationBus::MultiHandler::BusDisconnect();
for (auto& shaderItem : m_shaderCollection) for (auto& shaderItem : m_shaderCollection)
{ {
ShaderReloadDebugTracker::Printf("(Material has ShaderAsset %p)", shaderItem.GetShaderAsset().Get());
ShaderReloadNotificationBus::MultiHandler::BusConnect(shaderItem.GetShaderAsset().GetId()); ShaderReloadNotificationBus::MultiHandler::BusConnect(shaderItem.GetShaderAsset().GetId());
} }
@ -226,7 +227,7 @@ namespace AZ
// AssetBus overrides... // AssetBus overrides...
void Material::OnAssetReloaded(Data::Asset<Data::AssetData> asset) void Material::OnAssetReloaded(Data::Asset<Data::AssetData> asset)
{ {
ShaderReloadDebugTracker::ScopedSection reloadSection("Material::OnAssetReloaded %s", asset.GetHint().c_str()); ShaderReloadDebugTracker::ScopedSection reloadSection("{%p}->Material::OnAssetReloaded %s", this, asset.GetHint().c_str());
Data::Asset<MaterialAsset> newMaterialAsset = { asset.GetAs<MaterialAsset>(), AZ::Data::AssetLoadBehavior::PreLoad }; Data::Asset<MaterialAsset> newMaterialAsset = { asset.GetAs<MaterialAsset>(), AZ::Data::AssetLoadBehavior::PreLoad };
@ -241,7 +242,7 @@ namespace AZ
// MaterialReloadNotificationBus overrides... // MaterialReloadNotificationBus overrides...
void Material::OnMaterialAssetReinitialized(const Data::Asset<MaterialAsset>& materialAsset) void Material::OnMaterialAssetReinitialized(const Data::Asset<MaterialAsset>& materialAsset)
{ {
ShaderReloadDebugTracker::ScopedSection reloadSection("Material::OnMaterialAssetReinitialized %s", materialAsset.GetHint().c_str()); ShaderReloadDebugTracker::ScopedSection reloadSection("{%p}->Material::OnMaterialAssetReinitialized %s", this, materialAsset.GetHint().c_str());
OnAssetReloaded(materialAsset); OnAssetReloaded(materialAsset);
} }
@ -249,7 +250,7 @@ namespace AZ
// ShaderReloadNotificationBus overrides... // ShaderReloadNotificationBus overrides...
void Material::OnShaderReinitialized([[maybe_unused]] const Shader& shader) void Material::OnShaderReinitialized([[maybe_unused]] const Shader& shader)
{ {
ShaderReloadDebugTracker::ScopedSection reloadSection("Material::OnShaderReinitialized %s", shader.GetAsset().GetHint().c_str()); ShaderReloadDebugTracker::ScopedSection reloadSection("{%p}->Material::OnShaderReinitialized %s", this, shader.GetAsset().GetHint().c_str());
// Note that it might not be strictly necessary to reinitialize the entire material, we might be able to get away with // Note that it might not be strictly necessary to reinitialize the entire material, we might be able to get away with
// just bumping the m_currentChangeId or some other minor updates. But it's pretty hard to know what exactly needs to be // just bumping the m_currentChangeId or some other minor updates. But it's pretty hard to know what exactly needs to be
// updated to correctly handle the reload, so it's safer to just reinitialize the whole material. // updated to correctly handle the reload, so it's safer to just reinitialize the whole material.
@ -260,7 +261,7 @@ namespace AZ
{ {
// TODO: I think we should make Shader handle OnShaderAssetReinitialized and treat it just like the shader reloaded. // TODO: I think we should make Shader handle OnShaderAssetReinitialized and treat it just like the shader reloaded.
ShaderReloadDebugTracker::ScopedSection reloadSection("Material::OnShaderAssetReinitialized %s", shaderAsset.GetHint().c_str()); ShaderReloadDebugTracker::ScopedSection reloadSection("{%p}->Material::OnShaderAssetReinitialized %s", this, shaderAsset.GetHint().c_str());
// Note that it might not be strictly necessary to reinitialize the entire material, we might be able to get away with // Note that it might not be strictly necessary to reinitialize the entire material, we might be able to get away with
// just bumping the m_currentChangeId or some other minor updates. But it's pretty hard to know what exactly needs to be // just bumping the m_currentChangeId or some other minor updates. But it's pretty hard to know what exactly needs to be
// updated to correctly handle the reload, so it's safer to just reinitialize the whole material. // updated to correctly handle the reload, so it's safer to just reinitialize the whole material.
@ -269,7 +270,7 @@ namespace AZ
void Material::OnShaderVariantReinitialized(const Shader& shader, const ShaderVariantId& /*shaderVariantId*/, ShaderVariantStableId shaderVariantStableId) void Material::OnShaderVariantReinitialized(const Shader& shader, const ShaderVariantId& /*shaderVariantId*/, ShaderVariantStableId shaderVariantStableId)
{ {
ShaderReloadDebugTracker::ScopedSection reloadSection("Material::OnShaderVariantReinitialized %s variant %u", shader.GetAsset().GetHint().c_str(), shaderVariantStableId.GetIndex()); ShaderReloadDebugTracker::ScopedSection reloadSection("{%p}->Material::OnShaderVariantReinitialized %s variant %u", this, shader.GetAsset().GetHint().c_str(), shaderVariantStableId.GetIndex());
// Note that it would be better to check the shaderVariantId to see if that variant is relevant to this particular material before reinitializing it. // Note that it would be better to check the shaderVariantId to see if that variant is relevant to this particular material before reinitializing it.
// There could be hundreds or even thousands of variants for a shader, but only one of those variants will be used by any given material. So we could // There could be hundreds or even thousands of variants for a shader, but only one of those variants will be used by any given material. So we could

@ -132,7 +132,7 @@ namespace AZ
// AssetBus overrides // AssetBus overrides
void Shader::OnAssetReloaded(Data::Asset<Data::AssetData> asset) void Shader::OnAssetReloaded(Data::Asset<Data::AssetData> asset)
{ {
ShaderReloadDebugTracker::ScopedSection reloadSection("Shader::OnAssetReloaded %s", asset.GetHint().c_str()); ShaderReloadDebugTracker::ScopedSection reloadSection("{%p}->Shader::OnAssetReloaded %s", this, asset.GetHint().c_str());
if (asset->GetId() == m_asset->GetId()) if (asset->GetId() == m_asset->GetId())
{ {

@ -119,7 +119,7 @@ namespace AZ
void MaterialAsset::OnAssetReloaded(Data::Asset<Data::AssetData> asset) void MaterialAsset::OnAssetReloaded(Data::Asset<Data::AssetData> asset)
{ {
ShaderReloadDebugTracker::ScopedSection reloadSection("MaterialAsset::OnAssetReloaded %s", asset.GetHint().c_str()); ShaderReloadDebugTracker::ScopedSection reloadSection("{%p}->MaterialAsset::OnAssetReloaded %s", this, asset.GetHint().c_str());
Data::Asset<MaterialTypeAsset> newMaterialTypeAsset = { asset.GetAs<MaterialTypeAsset>(), AZ::Data::AssetLoadBehavior::PreLoad }; Data::Asset<MaterialTypeAsset> newMaterialTypeAsset = { asset.GetAs<MaterialTypeAsset>(), AZ::Data::AssetLoadBehavior::PreLoad };

@ -130,7 +130,7 @@ namespace AZ
void MaterialTypeAsset::OnAssetReloaded(Data::Asset<Data::AssetData> asset) void MaterialTypeAsset::OnAssetReloaded(Data::Asset<Data::AssetData> asset)
{ {
ShaderReloadDebugTracker::ScopedSection reloadSection("MaterialTypeAsset::OnAssetReloaded %s", asset.GetHint().c_str()); ShaderReloadDebugTracker::ScopedSection reloadSection("{%p}->MaterialTypeAsset::OnAssetReloaded %s", this, asset.GetHint().c_str());
// The order of asset reloads is non-deterministic. If the MaterialTypeAsset reloads before these // The order of asset reloads is non-deterministic. If the MaterialTypeAsset reloads before these
// dependency assets, this will make sure the MaterialTypeAsset gets the latest ones when they reload. // dependency assets, this will make sure the MaterialTypeAsset gets the latest ones when they reload.

@ -381,7 +381,7 @@ namespace AZ
// AssetBus overrides... // AssetBus overrides...
void ShaderAsset::OnAssetReloaded(Data::Asset<Data::AssetData> asset) void ShaderAsset::OnAssetReloaded(Data::Asset<Data::AssetData> asset)
{ {
ShaderReloadDebugTracker::ScopedSection reloadSection("ShaderAsset::OnAssetReloaded %s", asset.GetHint().c_str()); ShaderReloadDebugTracker::ScopedSection reloadSection("{%p}->ShaderAsset::OnAssetReloaded %s", this, asset.GetHint().c_str());
Data::Asset<ShaderVariantAsset> shaderVariantAsset = { asset.GetAs<ShaderVariantAsset>(), AZ::Data::AssetLoadBehavior::PreLoad }; Data::Asset<ShaderVariantAsset> shaderVariantAsset = { asset.GetAs<ShaderVariantAsset>(), AZ::Data::AssetLoadBehavior::PreLoad };
AZ_Assert(shaderVariantAsset->GetStableId() == RootShaderVariantStableId, AZ_Assert(shaderVariantAsset->GetStableId() == RootShaderVariantStableId,
@ -396,7 +396,7 @@ namespace AZ
/// ShaderVariantFinderNotificationBus overrides /// ShaderVariantFinderNotificationBus overrides
void ShaderAsset::OnShaderVariantTreeAssetReady(Data::Asset<ShaderVariantTreeAsset> shaderVariantTreeAsset, bool isError) void ShaderAsset::OnShaderVariantTreeAssetReady(Data::Asset<ShaderVariantTreeAsset> shaderVariantTreeAsset, bool isError)
{ {
ShaderReloadDebugTracker::ScopedSection reloadSection("ShaderAsset::OnShaderVariantTreeAssetReady %s", shaderVariantTreeAsset.GetHint().c_str()); ShaderReloadDebugTracker::ScopedSection reloadSection("{%p}->ShaderAsset::OnShaderVariantTreeAssetReady %s", this, shaderVariantTreeAsset.GetHint().c_str());
AZStd::unique_lock<decltype(m_variantTreeMutex)> lock(m_variantTreeMutex); AZStd::unique_lock<decltype(m_variantTreeMutex)> lock(m_variantTreeMutex);
if (isError) if (isError)

Loading…
Cancel
Save