Merge branch 'development' of https://github.com/o3de/o3de into bitset_serialization_includes

This commit is contained in:
puvvadar
2021-10-22 09:52:27 -07:00
476 changed files with 10659 additions and 4988 deletions
@@ -24,6 +24,13 @@ namespace AZ
AZ_RTTI(AZ::RPI::JsonMaterialPropertyValueSerializer, "{A52B1ED8-C849-4269-9AA7-9D0814D2EC59}", BaseJsonSerializer);
AZ_CLASS_ALLOCATOR_DECL;
//! A LoadContext object must be passed down to the serializer via JsonDeserializerContext::GetMetadata().Add(...)
struct LoadContext
{
AZ_TYPE_INFO(JsonMaterialPropertyValueSerializer::LoadContext, "{5E0A891A-27F6-4AD7-88A5-B9EA50F88B45}");
uint32_t m_materialTypeVersion; //!< The version number from the .materialtype file
};
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
JsonDeserializerContext& context) override;
@@ -50,7 +50,7 @@ namespace AZ
AZStd::string m_parentMaterial; //!< The immediate parent of this material
uint32_t m_propertyLayoutVersion = 0; //!< The version of the property layout, defined in the material type, which was used to configure this material
uint32_t m_materialTypeVersion = 0; //!< The version of the material type that was used to configure this material
struct Property
{
@@ -64,6 +64,18 @@ namespace AZ
PropertyGroupMap m_properties;
enum class ApplyVersionUpdatesResult
{
Failed,
NoUpdates,
UpdatesApplied
};
//! Checks the material type version and potentially applies a series of property changes (most common are simple property renames)
//! based on the MaterialTypeAsset's version update procedure.
//! @param materialSourceFilePath Indicates the path of the .material file that the MaterialSourceData represents. Used for resolving file-relative paths.
ApplyVersionUpdatesResult ApplyVersionUpdates(AZStd::string_view materialSourceFilePath = "");
//! Creates a MaterialAsset from the MaterialSourceData content.
//! @param assetId ID for the MaterialAsset
//! @param materialSourceFilePath Indicates the path of the .material file that the MaterialSourceData represents. Used for resolving file-relative paths.
@@ -13,6 +13,7 @@
#include <Atom/RPI.Reflect/Base.h>
#include <Atom/RPI.Reflect/Material/MaterialPropertyDescriptor.h>
#include <Atom/RPI.Edit/Material/MaterialFunctorSourceData.h>
#include <Atom/RPI.Edit/Material/MaterialPropertyId.h>
namespace AZ
{
@@ -119,12 +120,36 @@ namespace AZ
using PropertyList = AZStd::vector<PropertyDefinition>;
struct VersionUpdatesRenameOperationDefinition
{
AZ_TYPE_INFO(AZ::RPI::MaterialTypeSourceData::VersionUpdatesRenameOperationDefinition, "{F2295489-E15A-46CC-929F-8D42DEDBCF14}");
AZStd::string m_operation;
AZStd::string m_renameFrom;
AZStd::string m_renameTo;
};
// TODO: Support script operations--At that point, we'll likely need to replace VersionUpdatesRenameOperationDefinition with a more generic
// data structure that has a custom JSON serialize. We will only be supporting rename for now.
using VersionUpdateActions = AZStd::vector<VersionUpdatesRenameOperationDefinition>;
struct VersionUpdateDefinition
{
AZ_TYPE_INFO(AZ::RPI::MaterialTypeSourceData::VersionUpdateDefinition, "{2C9D3B91-0585-4BC9-91D2-4CF0C71BC4B7}");
uint32_t m_toVersion;
VersionUpdateActions m_actions;
};
using VersionUpdates = AZStd::vector<VersionUpdateDefinition>;
struct PropertyLayout
{
AZ_TYPE_INFO(AZ::RPI::MaterialTypeSourceData::PropertyLayout, "{AE53CF3F-5C3B-44F5-B2FB-306F0EB06393}");
//! Indicates the version of the set of available properties. Can be used to detect materials that might need to be updated.
uint32_t m_version = 0;
//! This field is unused, and has been replaced by MaterialTypeSourceData::m_version below. It is kept for legacy file compatibility to suppress warnings and errors.
uint32_t m_versionOld = 0;
//! List of groups that will contain the available properties
AZStd::vector<GroupDefinition> m_groups;
@@ -135,6 +160,11 @@ namespace AZ
AZStd::string m_description;
//! Version 1 is the default and should not contain any version update.
uint32_t m_version = 1;
VersionUpdates m_versionUpdates;
PropertyLayout m_propertyLayout;
//! A list of shader variants that are always used at runtime; they cannot be turned off
@@ -153,7 +183,12 @@ namespace AZ
const GroupDefinition* FindGroup(AZStd::string_view groupName) const;
const PropertyDefinition* FindProperty(AZStd::string_view groupName, AZStd::string_view propertyName) const;
//! Searches for a specific property.
//! Note this function can find properties using old versions of the property name; in that case,
//! the name in the returned PropertyDefinition* will not match the @propertyName that was searched for.
//! @param materialTypeVersion indicates the version number of the property name being passed in. Only renames above this version number will be applied.
//! @return the requested property, or null if it could not be found
const PropertyDefinition* FindProperty(AZStd::string_view groupName, AZStd::string_view propertyName, uint32_t materialTypeVersion = 0) const;
//! Construct a complete list of group definitions, including implicit groups, arranged in the same order as the source data
//! Groups with the same name will be consolidated into a single entry
@@ -179,6 +214,11 @@ namespace AZ
bool ConvertPropertyValueToSourceDataFormat(const PropertyDefinition& propertyDefinition, MaterialPropertyValue& propertyValue) const;
Outcome<Data::Asset<MaterialTypeAsset>> CreateMaterialTypeAsset(Data::AssetId assetId, AZStd::string_view materialTypeSourceFilePath = "", bool elevateWarnings = true) const;
//! Possibly renames @propertyId based on the material version update steps.
//! @param materialTypeVersion indicates the version number of the property name being passed in. Only renames above this version number will be applied.
//! @return true if the property was renamed
bool ApplyPropertyRenames(MaterialPropertyId& propertyId, uint32_t materialTypeVersion = 0) const;
};
//! The wrapper class for derived material functors.
@@ -22,6 +22,7 @@
namespace UnitTest
{
class MaterialTests;
class MaterialAssetTests;
}
namespace AZ
@@ -42,10 +43,12 @@ namespace AZ
, public MaterialReloadNotificationBus::Handler
, public AssetInitBus::Handler
{
friend class MaterialVersionUpdate;
friend class MaterialAssetCreator;
friend class MaterialAssetHandler;
friend class MaterialAssetCreatorCommon;
friend class UnitTest::MaterialTests;
friend class UnitTest::MaterialAssetTests;
public:
AZ_RTTI(MaterialAsset, "{522C7BE0-501D-463E-92C6-15184A2B7AD8}", AZ::Data::AssetData);
@@ -119,6 +122,10 @@ namespace AZ
//! from m_materialTypeAsset.
void RealignPropertyValuesAndNames();
//! Checks the material type version and potentially applies a series of property changes (most common are simple property renames)
//! based on the MaterialTypeAsset's version update procedure.
void ApplyVersionUpdates();
//! Called by asset creators to assign the asset to a ready state.
void SetReady();
@@ -143,6 +150,10 @@ namespace AZ
//! If empty, this implies that m_propertyValues is aligned with the entries in m_materialPropertiesLayout.
AZStd::vector<AZ::Name> m_propertyNames;
//! The materialTypeVersion this materialAsset was based of. If the versions do not match at runtime when a
//! materialTypeAsset is loaded, an update will be performed on m_propertyNames if populated.
uint32_t m_materialTypeVersion = 1;
//! A flag to determine if m_propertyValues needs to be aligned with MaterialPropertiesLayout. Set to true whenever
//! m_materialTypeAsset is reinitializing.
bool m_isDirty = true;
@@ -18,6 +18,7 @@
#include <Atom/RPI.Reflect/Material/ShaderCollection.h>
#include <Atom/RPI.Reflect/Material/MaterialPropertiesLayout.h>
#include <Atom/RPI.Reflect/Material/MaterialFunctor.h>
#include <Atom/RPI.Reflect/Material/MaterialVersionUpdate.h>
namespace AZ
{
@@ -123,6 +124,11 @@ namespace AZ
//! Returns a map from the UV shader inputs to a custom name.
MaterialUvNameMap GetUvNameMap() const;
//! Returns the version of the MaterialTypeAsset.
uint32_t GetVersion() const;
const AZStd::vector<MaterialVersionUpdate>& GetMaterialVersionUpdateList() const { return m_materialVersionUpdates; }
private:
bool PostLoadInit() override;
@@ -162,6 +168,12 @@ namespace AZ
//! Index in @m_shaderCollection of the shader asset that contains the ObjectSrg.
uint32_t m_objectSrgShaderIndex = InvalidShaderIndex;
//! The version of this MaterialTypeAsset. If the version is greater than 1, actions performed
//! to update this MaterialTypeAsset will be in m_materialVersionUpdateMap
uint32_t m_version = 1;
//! Contains actions to perform for each material update version.
AZStd::vector<MaterialVersionUpdate> m_materialVersionUpdates;
};
class MaterialTypeAssetHandler : public AssetHandler<MaterialTypeAsset>
@@ -38,6 +38,11 @@ namespace AZ
void AddShader(const AZ::Data::Asset<ShaderAsset>& shaderAsset, const ShaderVariantId& shaderVaraintId = ShaderVariantId{}, const AZ::Name& shaderTag = Uuid::CreateRandom().ToString<AZ::Name>());
void AddShader(const AZ::Data::Asset<ShaderAsset>& shaderAsset, const AZ::Name& shaderTag);
//! Sets the version of the MaterialTypeAsset
void SetVersion(uint32_t version);
//! Adds a version update object into the MaterialTypeAsset
void AddVersionUpdate(const MaterialVersionUpdate& materialVersionUpdate);
//! Indicates that this MaterialType will own the specified shader option.
//! Material-owned shader options can be connected to material properties (either directly or through functors).
//! They cannot be accessed externally (for example, through the Material::SetSystemShaderOption() function).
@@ -112,6 +117,7 @@ namespace AZ
//! Saves the per-material SRG layout in m_shaderResourceGroupLayout for easier access
void CacheMaterialSrgLayout();
bool ValidateMaterialVersion();
bool ValidateBeginMaterialProperty();
bool ValidateEndMaterialProperty();
@@ -0,0 +1,62 @@
/*
* 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
*
*/
#pragma once
#include <AzCore/RTTI/ReflectContext.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/containers/map.h>
#include <AzCore/std/string/string.h>
#include <AzCore/Name/Name.h>
namespace AZ
{
namespace RPI
{
class MaterialAsset;
// This class contains a toVersion and a list of actions to specify what operations were performed to upgrade a materialType.
class MaterialVersionUpdate
{
public:
AZ_TYPE_INFO(AZ::RPI::MaterialVersionUpdate, "{B36E7712-AED8-46AA-AFE0-01F8F884C44A}");
static void Reflect(ReflectContext* context);
// At this time, the only supported operation is rename. If/when we add more actions in the future,
// we'll need to improve this, possibly with some virtual interface or union data.
struct RenamePropertyAction
{
AZ_TYPE_INFO(AZ::RPI::MaterialVersionUpdate::RenameAction, "{A1FBEB19-EA05-40F0-9700-57D048DF572B}");
static void Reflect(ReflectContext* context);
AZ::Name m_fromPropertyId;
AZ::Name m_toPropertyId;
};
explicit MaterialVersionUpdate() = default;
explicit MaterialVersionUpdate(uint32_t toVersion);
uint32_t GetVersion() const;
void SetVersion(uint32_t toVersion);
//! Apply version updates to the given material asset.
//! @return true if any changes were made
bool ApplyVersionUpdates(MaterialAsset& materialAsset) const;
using Actions = AZStd::vector<RenamePropertyAction>;
const Actions& GetActions() const;
void AddAction(const RenamePropertyAction& action);
private:
uint32_t m_toVersion;
Actions m_actions;
};
} // namespace RPI
} // namespace AZ