merging dev
Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <Atom/RPI.Reflect/Material/MaterialAsset.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialPropertiesLayout.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialFunctor.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialVersionUpdate.h>
|
||||
#include <Atom/RPI.Reflect/Asset/AssetHandler.h>
|
||||
#include <Atom/RPI.Public/Shader/ShaderReloadDebugTracker.h>
|
||||
|
||||
@@ -32,8 +33,9 @@ namespace AZ
|
||||
if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<MaterialAsset, AZ::Data::AssetData>()
|
||||
->Version(10)
|
||||
->Version(11) // Material version update
|
||||
->Field("materialTypeAsset", &MaterialAsset::m_materialTypeAsset)
|
||||
->Field("materialTypeVersion", &MaterialAsset::m_materialTypeVersion)
|
||||
->Field("propertyValues", &MaterialAsset::m_propertyValues)
|
||||
->Field("propertyNames", &MaterialAsset::m_propertyNames)
|
||||
;
|
||||
@@ -103,9 +105,25 @@ namespace AZ
|
||||
|
||||
AZStd::array_view<MaterialPropertyValue> MaterialAsset::GetPropertyValues() const
|
||||
{
|
||||
if (!m_propertyNames.empty() && m_isDirty)
|
||||
// If property names are included, they are used to re-arrange the property value list to align with the
|
||||
// MaterialPropertiesLayout. This realignment would be necessary if the material type is updated with
|
||||
// a new property layout, and a corresponding material is not reprocessed by the AP and continues using the
|
||||
// old property layout.
|
||||
if (!m_propertyNames.empty())
|
||||
{
|
||||
const_cast<MaterialAsset*>(this)->RealignPropertyValuesAndNames();
|
||||
const uint32_t materialTypeVersion = m_materialTypeAsset->GetVersion();
|
||||
if (m_materialTypeVersion < materialTypeVersion)
|
||||
{
|
||||
// It is possible that the material type has had some properties renamed. If that's the case, and this material
|
||||
// is still referencing the old property layout, we need to apply any auto updates to rename those properties
|
||||
// before using them to realign the property values.
|
||||
const_cast<MaterialAsset*>(this)->ApplyVersionUpdates();
|
||||
}
|
||||
|
||||
if (m_isDirty)
|
||||
{
|
||||
const_cast<MaterialAsset*>(this)->RealignPropertyValuesAndNames();
|
||||
}
|
||||
}
|
||||
|
||||
return m_propertyValues;
|
||||
@@ -183,6 +201,40 @@ namespace AZ
|
||||
m_isDirty = false;
|
||||
}
|
||||
|
||||
void MaterialAsset::ApplyVersionUpdates()
|
||||
{
|
||||
if (m_materialTypeVersion == m_materialTypeAsset->GetVersion())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const uint32_t originalVersion = m_materialTypeVersion;
|
||||
|
||||
bool changesWereApplied = false;
|
||||
|
||||
for (const MaterialVersionUpdate& versionUpdate : m_materialTypeAsset->GetMaterialVersionUpdateList())
|
||||
{
|
||||
if (m_materialTypeVersion < versionUpdate.GetVersion())
|
||||
{
|
||||
if (versionUpdate.ApplyVersionUpdates(*this))
|
||||
{
|
||||
changesWereApplied = true;
|
||||
m_materialTypeVersion = versionUpdate.GetVersion();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (changesWereApplied)
|
||||
{
|
||||
AZ_Warning("MaterialAsset", false,
|
||||
"This material is based on version '%u' of %s, but the material type is now at version '%u'. "
|
||||
"Automatic updates are available. Consider updating the .material source file.",
|
||||
originalVersion, m_materialTypeAsset.ToString<AZStd::string>().c_str(), m_materialTypeAsset->GetVersion());
|
||||
}
|
||||
|
||||
m_materialTypeVersion = m_materialTypeAsset->GetVersion();
|
||||
}
|
||||
|
||||
void MaterialAsset::ReinitializeMaterialTypeAsset(Data::Asset<Data::AssetData> asset)
|
||||
{
|
||||
Data::Asset<MaterialTypeAsset> newMaterialTypeAsset = { asset.GetAs<MaterialTypeAsset>(), AZ::Data::AssetLoadBehavior::PreLoad };
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace AZ
|
||||
if (ValidateIsReady())
|
||||
{
|
||||
m_asset->m_materialTypeAsset = parentMaterial.m_materialTypeAsset;
|
||||
m_asset->m_materialTypeVersion = m_asset->m_materialTypeAsset->GetVersion();
|
||||
|
||||
if (!m_asset->m_materialTypeAsset)
|
||||
{
|
||||
@@ -69,6 +70,7 @@ namespace AZ
|
||||
ReportError("MaterialTypeAsset is null");
|
||||
return;
|
||||
}
|
||||
m_asset->m_materialTypeVersion = m_asset->m_materialTypeAsset->GetVersion();
|
||||
|
||||
m_materialPropertiesLayout = m_asset->GetMaterialPropertiesLayout();
|
||||
if (includeMaterialPropertyNames)
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace AZ
|
||||
|
||||
void MaterialTypeAsset::Reflect(ReflectContext* context)
|
||||
{
|
||||
MaterialVersionUpdate::Reflect(context);
|
||||
UvNamePair::Reflect(context);
|
||||
|
||||
if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
|
||||
@@ -44,7 +45,9 @@ namespace AZ
|
||||
serializeContext->RegisterGenericType<MaterialUvNameMap>();
|
||||
|
||||
serializeContext->Class<MaterialTypeAsset, AZ::Data::AssetData>()
|
||||
->Version(4) // ATOM-15472
|
||||
->Version(5) // Material version update
|
||||
->Field("Version", &MaterialTypeAsset::m_version)
|
||||
->Field("VersionUpdates", &MaterialTypeAsset::m_materialVersionUpdates)
|
||||
->Field("ShaderCollection", &MaterialTypeAsset::m_shaderCollection)
|
||||
->Field("MaterialFunctors", &MaterialTypeAsset::m_materialFunctors)
|
||||
->Field("MaterialSrgShaderIndex", &MaterialTypeAsset::m_materialSrgShaderIndex)
|
||||
@@ -161,6 +164,11 @@ namespace AZ
|
||||
return m_uvNameMap;
|
||||
}
|
||||
|
||||
uint32_t MaterialTypeAsset::GetVersion() const
|
||||
{
|
||||
return m_version;
|
||||
}
|
||||
|
||||
void MaterialTypeAsset::SetReady()
|
||||
{
|
||||
m_status = AssetStatus::Ready;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace AZ
|
||||
|
||||
bool MaterialTypeAssetCreator::End(Data::Asset<MaterialTypeAsset>& result)
|
||||
{
|
||||
if (!ValidateIsReady() || !ValidateEndMaterialProperty())
|
||||
if (!ValidateIsReady() || !ValidateEndMaterialProperty() || !ValidateMaterialVersion())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -100,6 +100,48 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
bool MaterialTypeAssetCreator::ValidateMaterialVersion()
|
||||
{
|
||||
if (m_asset->m_materialVersionUpdates.empty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t prevVersion = 0;
|
||||
for(const MaterialVersionUpdate& versionUpdate : m_asset->m_materialVersionUpdates)
|
||||
{
|
||||
if (versionUpdate.GetVersion() <= prevVersion)
|
||||
{
|
||||
ReportError("Version updates are not sequential. See version update '%u'.", versionUpdate.GetVersion());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (versionUpdate.GetVersion() > m_asset->m_version)
|
||||
{
|
||||
ReportError("Version updates go beyond the current material type version. See version update '%u'.", versionUpdate.GetVersion());
|
||||
return false;
|
||||
}
|
||||
|
||||
prevVersion = versionUpdate.GetVersion();
|
||||
}
|
||||
|
||||
const auto& lastMaterialVersionUpdate = m_asset->m_materialVersionUpdates.back();
|
||||
for (const auto& action : lastMaterialVersionUpdate.GetActions())
|
||||
{
|
||||
const auto propertyIndex = m_asset->m_materialPropertiesLayout->FindPropertyIndex(AZ::Name{ action.m_toPropertyId });
|
||||
if (!propertyIndex.IsValid())
|
||||
{
|
||||
ReportError("Renamed property '%s' not found in material property layout. Check that the property name has been "
|
||||
"upgraded to the correct version",
|
||||
action.m_toPropertyId.GetCStr());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MaterialTypeAssetCreator::AddShader(const AZ::Data::Asset<ShaderAsset>& shaderAsset, const ShaderVariantId& shaderVaraintId, const AZ::Name& shaderTag)
|
||||
{
|
||||
if (ValidateIsReady() && ValidateNotNull(shaderAsset, "ShaderAsset"))
|
||||
@@ -123,6 +165,16 @@ namespace AZ
|
||||
AddShader(shaderAsset, ShaderVariantId{}, shaderTag);
|
||||
}
|
||||
|
||||
void MaterialTypeAssetCreator::SetVersion(uint32_t version)
|
||||
{
|
||||
m_asset->m_version = version;
|
||||
}
|
||||
|
||||
void MaterialTypeAssetCreator::AddVersionUpdate(const MaterialVersionUpdate& materialVersionUpdate)
|
||||
{
|
||||
m_asset->m_materialVersionUpdates.push_back(materialVersionUpdate);
|
||||
}
|
||||
|
||||
void MaterialTypeAssetCreator::ClaimShaderOptionOwnership(const Name& shaderOptionName)
|
||||
{
|
||||
bool optionFound = false;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Atom/RPI.Reflect/Material/MaterialVersionUpdate.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialAsset.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
namespace RPI
|
||||
{
|
||||
void MaterialVersionUpdate::RenamePropertyAction::Reflect(ReflectContext* context)
|
||||
{
|
||||
if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<RenamePropertyAction>()
|
||||
->Version(1)
|
||||
->Field("From", &RenamePropertyAction::m_fromPropertyId)
|
||||
->Field("To", &RenamePropertyAction::m_toPropertyId)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialVersionUpdate::Reflect(ReflectContext* context)
|
||||
{
|
||||
MaterialVersionUpdate::RenamePropertyAction::Reflect(context);
|
||||
|
||||
if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->RegisterGenericType<MaterialVersionUpdate::Actions>();
|
||||
|
||||
serializeContext->Class<MaterialVersionUpdate>()
|
||||
->Version(1)
|
||||
->Field("ToVersion", &MaterialVersionUpdate::m_toVersion)
|
||||
->Field("Actions", &MaterialVersionUpdate::m_actions)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
MaterialVersionUpdate::MaterialVersionUpdate(uint32_t toVersion)
|
||||
: m_toVersion(toVersion)
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t MaterialVersionUpdate::GetVersion() const
|
||||
{
|
||||
return m_toVersion;
|
||||
}
|
||||
|
||||
void MaterialVersionUpdate::SetVersion(uint32_t toVersion)
|
||||
{
|
||||
m_toVersion = toVersion;
|
||||
}
|
||||
|
||||
bool MaterialVersionUpdate::ApplyVersionUpdates(MaterialAsset& materialAsset) const
|
||||
{
|
||||
bool changesWereApplied = false;
|
||||
|
||||
for (auto& propertyName : materialAsset.m_propertyNames)
|
||||
{
|
||||
for (const auto& action : m_actions)
|
||||
{
|
||||
if (propertyName == action.m_fromPropertyId)
|
||||
{
|
||||
propertyName = action.m_toPropertyId;
|
||||
changesWereApplied = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return changesWereApplied;
|
||||
}
|
||||
|
||||
const AZ::RPI::MaterialVersionUpdate::Actions& MaterialVersionUpdate::GetActions() const
|
||||
{
|
||||
return m_actions;
|
||||
}
|
||||
|
||||
void MaterialVersionUpdate::AddAction(const RenamePropertyAction& action)
|
||||
{
|
||||
m_actions.push_back(action);
|
||||
}
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
Reference in New Issue
Block a user