Merge remote-tracking branch 'upstream/stabilization/2110' into Atom/santorac/MaterialEditorHandlesMissingTextures
This commit is contained in:
@@ -160,6 +160,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS)
|
||||
Gem::Atom_RPI.Public
|
||||
Gem::Atom_RHI.Public
|
||||
Gem::Atom_RPI.Edit
|
||||
Gem::Atom_Utils.TestUtils.Static
|
||||
)
|
||||
ly_add_googletest(
|
||||
NAME Gem::Atom_RPI.Tests
|
||||
|
||||
@@ -209,10 +209,6 @@ namespace AZ
|
||||
//! Traversal will stop once all properties have been enumerated or the callback function returns false
|
||||
void EnumeratePropertiesInDisplayOrder(const EnumeratePropertiesCallback& callback) const;
|
||||
|
||||
//! Convert the property value into the format that will be stored in the source data
|
||||
//! This is primarily needed to support conversions of special types like enums and images
|
||||
bool ConvertPropertyValueToSourceDataFormat(const AZ::Name& propertyId, 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.
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace AZ
|
||||
//! Set the timestamp value when the ProcessJob() started.
|
||||
//! This is needed to synchronize between the ShaderAsset and ShaderVariantAsset when hot-reloading shaders.
|
||||
//! The idea is that this timestamp must be greater or equal than the ShaderAsset.
|
||||
void SetBuildTimestamp(AZStd::sys_time_t buildTimestamp);
|
||||
void SetBuildTimestamp(AZ::u64 buildTimestamp);
|
||||
|
||||
//! Assigns a shaderStageFunction, which contains the byte code, to the slot dictated by the shader stage.
|
||||
void SetShaderFunction(RHI::ShaderStage shaderStage, RHI::Ptr<RHI::ShaderStageFunction> shaderStageFunction);
|
||||
|
||||
@@ -294,7 +294,7 @@ namespace AZ
|
||||
Name m_drawListName;
|
||||
|
||||
//! Use to synchronize versions of the ShaderAsset and ShaderVariantTreeAsset, especially during hot-reload.
|
||||
AZStd::sys_time_t m_shaderAssetBuildTimestamp = 0;
|
||||
AZ::u64 m_shaderAssetBuildTimestamp = 0;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace AZ
|
||||
|
||||
//! Return the timestamp when this asset was built, and it must be >= than the timestamp of the main ShaderAsset.
|
||||
//! This is used to synchronize versions of the ShaderAsset and ShaderVariantAsset, especially during hot-reload.
|
||||
AZStd::sys_time_t GetBuildTimestamp() const;
|
||||
AZ::u64 GetBuildTimestamp() const;
|
||||
|
||||
bool IsRootVariant() const { return m_stableId == RPI::RootShaderVariantStableId; }
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace AZ
|
||||
AZStd::array<RHI::Ptr<RHI::ShaderStageFunction>, RHI::ShaderStageCount> m_functionsByStage;
|
||||
|
||||
//! Used to synchronize versions of the ShaderAsset and ShaderVariantAsset, especially during hot-reload.
|
||||
AZStd::sys_time_t m_buildTimestamp = 0;
|
||||
AZ::u64 m_buildTimestamp = 0;
|
||||
};
|
||||
|
||||
class ShaderVariantAssetHandler final
|
||||
|
||||
@@ -300,48 +300,6 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
bool MaterialTypeSourceData::ConvertPropertyValueToSourceDataFormat([[maybe_unused]] const AZ::Name& propertyId, const PropertyDefinition& propertyDefinition, MaterialPropertyValue& propertyValue) const
|
||||
{
|
||||
if (propertyDefinition.m_dataType == AZ::RPI::MaterialPropertyDataType::Enum && propertyValue.Is<uint32_t>())
|
||||
{
|
||||
const uint32_t index = propertyValue.GetValue<uint32_t>();
|
||||
if (index >= propertyDefinition.m_enumValues.size())
|
||||
{
|
||||
AZ_Error("Material source data", false, "Invalid value for material enum property: '%s'.", propertyId.GetCStr());
|
||||
return false;
|
||||
}
|
||||
|
||||
propertyValue = propertyDefinition.m_enumValues[index];
|
||||
return true;
|
||||
}
|
||||
|
||||
// Image asset references must be converted from asset IDs to a relative source file path
|
||||
if (propertyDefinition.m_dataType == AZ::RPI::MaterialPropertyDataType::Image && propertyValue.Is<Data::Asset<ImageAsset>>())
|
||||
{
|
||||
const Data::Asset<ImageAsset>& imageAsset = propertyValue.GetValue<Data::Asset<ImageAsset>>();
|
||||
|
||||
Data::AssetInfo imageAssetInfo;
|
||||
if (imageAsset.GetId().IsValid())
|
||||
{
|
||||
bool result = false;
|
||||
AZStd::string rootFilePath;
|
||||
const AZStd::string platformName = ""; // Empty for default
|
||||
AzToolsFramework::AssetSystemRequestBus::BroadcastResult(result, &AzToolsFramework::AssetSystem::AssetSystemRequest::GetAssetInfoById,
|
||||
imageAsset.GetId(), imageAsset.GetType(), platformName, imageAssetInfo, rootFilePath);
|
||||
if (!result)
|
||||
{
|
||||
AZ_Error("Material source data", false, "Image asset could not be found for property: '%s'.", propertyId.GetCStr());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
propertyValue = imageAssetInfo.m_relativePath;
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Outcome<Data::Asset<MaterialTypeAsset>> MaterialTypeSourceData::CreateMaterialTypeAsset(Data::AssetId assetId, AZStd::string_view materialTypeSourceFilePath, bool elevateWarnings) const
|
||||
{
|
||||
MaterialTypeAssetCreator materialTypeAssetCreator;
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace AZ
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Methods for all shader variant types
|
||||
|
||||
void ShaderVariantAssetCreator::SetBuildTimestamp(AZStd::sys_time_t buildTimestamp)
|
||||
void ShaderVariantAssetCreator::SetBuildTimestamp(AZ::u64 buildTimestamp)
|
||||
{
|
||||
if (ValidateIsReady())
|
||||
{
|
||||
|
||||
@@ -202,17 +202,17 @@ namespace AZ
|
||||
return;
|
||||
}
|
||||
AZ_Assert(m_asset->m_shaderAssetBuildTimestamp == m_reloadedRootShaderVariantAsset->GetBuildTimestamp(),
|
||||
"shaderAsset timeStamp=%lld, but Root ShaderVariantAsset timeStamp=%lld",
|
||||
"shaderAsset '%s' timeStamp=%lld, but Root ShaderVariantAsset timeStamp=%lld", m_asset.GetHint().c_str(),
|
||||
m_asset->m_shaderAssetBuildTimestamp, m_reloadedRootShaderVariantAsset->GetBuildTimestamp());
|
||||
m_asset->UpdateRootShaderVariantAsset(m_supervariantIndex, m_reloadedRootShaderVariantAsset);
|
||||
m_reloadedRootShaderVariantAsset = {}; // Clear the temporary reference.
|
||||
|
||||
if (ShaderReloadDebugTracker::IsEnabled())
|
||||
{
|
||||
auto makeTimeString = [](AZStd::sys_time_t timestamp, AZStd::sys_time_t now)
|
||||
auto makeTimeString = [](AZ::u64 timestamp, AZ::u64 now)
|
||||
{
|
||||
AZStd::sys_time_t elapsedMicroseconds = now - timestamp;
|
||||
double elapsedSeconds = aznumeric_cast<double>(elapsedMicroseconds / 1'000'000);
|
||||
AZ::u64 elapsedMillis = now - timestamp;
|
||||
double elapsedSeconds = aznumeric_cast<double>(elapsedMillis / 1'000);
|
||||
AZStd::string timeString = AZStd::string::format("%lld (%f seconds ago)", timestamp, elapsedSeconds);
|
||||
return timeString;
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
AZStd::sys_time_t ShaderVariantAsset::GetBuildTimestamp() const
|
||||
AZ::u64 ShaderVariantAsset::GetBuildTimestamp() const
|
||||
{
|
||||
return m_buildTimestamp;
|
||||
}
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* 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 <Common/AssetSystemStub.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
void AssetSystemStub::Activate()
|
||||
{
|
||||
m_sourceInfoMap.clear();
|
||||
BusConnect();
|
||||
}
|
||||
|
||||
void AssetSystemStub::Deactivate()
|
||||
{
|
||||
m_sourceInfoMap.clear();
|
||||
BusDisconnect();
|
||||
}
|
||||
|
||||
void AssetSystemStub::RegisterSourceInfo(const char* sourcePath, const AZ::Data::AssetId& assetId)
|
||||
{
|
||||
AZ::Data::AssetInfo assetInfo;
|
||||
assetInfo.m_assetId = assetId;
|
||||
RegisterSourceInfo(sourcePath, assetInfo, "");
|
||||
}
|
||||
|
||||
void AssetSystemStub::RegisterSourceInfo(const char* sourcePath, const AZ::Data::AssetInfo& assetInfo, const AZStd::string& watchFolder)
|
||||
{
|
||||
SourceInfo sourceInfo{ assetInfo , watchFolder };
|
||||
|
||||
// Because GetSourceInfoBySourcePath should always return 0 for the sub-id, since it's about the source file not product file.
|
||||
sourceInfo.m_assetInfo.m_assetId.m_subId = 0;
|
||||
|
||||
AZStd::string normalizedSourcePath = sourcePath;
|
||||
AzFramework::StringFunc::Path::Normalize(normalizedSourcePath);
|
||||
m_sourceInfoMap.emplace(normalizedSourcePath, sourceInfo);
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetSourceInfoBySourcePath(const char* sourcePath, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder)
|
||||
{
|
||||
AZStd::string normalizedSourcePath = sourcePath;
|
||||
AzFramework::StringFunc::Path::Normalize(normalizedSourcePath);
|
||||
|
||||
auto iter = m_sourceInfoMap.find(normalizedSourcePath);
|
||||
|
||||
if (iter != m_sourceInfoMap.end())
|
||||
{
|
||||
assetInfo = iter->second.m_assetInfo;
|
||||
watchFolder = iter->second.m_watchFolder;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetRelativeProductPathFromFullSourceOrProductPath([[maybe_unused]] const AZStd::string& fullPath, [[maybe_unused]] AZStd::string& relativeProductPath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GenerateRelativeSourcePath(
|
||||
[[maybe_unused]] const AZStd::string& sourcePath, [[maybe_unused]] AZStd::string& relativePath,
|
||||
[[maybe_unused]] AZStd::string& watchFolder)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetFullSourcePathFromRelativeProductPath(
|
||||
[[maybe_unused]] const AZStd::string& relPath, [[maybe_unused]] AZStd::string& fullSourcePath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetAssetInfoById([[maybe_unused]] const AZ::Data::AssetId& assetId, [[maybe_unused]] const AZ::Data::AssetType& assetType, [[maybe_unused]] const AZStd::string& platformName, [[maybe_unused]] AZ::Data::AssetInfo& assetInfo, [[maybe_unused]] AZStd::string& rootFilePath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetSourceInfoBySourceUUID([[maybe_unused]] const AZ::Uuid& sourceUuid, [[maybe_unused]] AZ::Data::AssetInfo& assetInfo, [[maybe_unused]] AZStd::string& watchFolder)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetScanFolders([[maybe_unused]] AZStd::vector<AZStd::string>& scanFolders)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetAssetSafeFolders([[maybe_unused]] AZStd::vector<AZStd::string>& assetSafeFolders)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::IsAssetPlatformEnabled(const char* /*platform*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int AssetSystemStub::GetPendingAssetsForPlatform(const char* /*platform*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetAssetsProducedBySourceUUID(const AZ::Uuid& sourceUuid, AZStd::vector<AZ::Data::AssetInfo>& productsAssetInfo)
|
||||
{
|
||||
productsAssetInfo.clear();
|
||||
for (AZStd::pair<AZStd::string, SourceInfo> element : m_sourceInfoMap)
|
||||
{
|
||||
if (element.second.m_assetInfo.m_assetId.m_guid == sourceUuid)
|
||||
{
|
||||
productsAssetInfo.push_back(element.second.m_assetInfo);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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 <AzToolsFramework/API/EditorAssetSystemAPI.h>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
/**
|
||||
* This class can stub out the asset system to enable the RPI's AssetUtils class to look up test assets.
|
||||
* This is included in the RPITestFixture class. To use it, first create a test asset using AssetManager::Create()
|
||||
* or one of the RPI's AssetCreators. This will register the asset with the asset database. Example:
|
||||
*
|
||||
* Data::Asset<MaterialAsset> myTestMaterialAsset1;
|
||||
* MaterialAssetCreator creator;
|
||||
* creator.Begin(...);
|
||||
* // set some stuff
|
||||
* creator.End(myTestMaterialAsset1);
|
||||
*
|
||||
* Then call RegisterSourceInfo for whatever test assets you want to be able to access via AssetUtils.
|
||||
* This associates an AssetInfo object with some dummy source file name. No source file is actually created;
|
||||
* it just allows AssetUtils to find the desired AssetInfo when looking up a source file name that your unit
|
||||
* test provides. Example:
|
||||
*
|
||||
* m_assetSystemStub.RegisterSourceInfo("MyTestMaterial1.material", Data::AssetInfo{ myTestMaterialAsset1.GetId() }, "");
|
||||
* m_assetSystemStub.RegisterSourceInfo("MyTestMaterial2.material", Data::AssetInfo{ myTestMaterialAsset2.GetId() }, "");
|
||||
*
|
||||
* Now the RPI should be able to use AssetUtils like normal to access your test assets. Example:
|
||||
*
|
||||
* RPI::AssetUtils::LoadAsset("MyTestMaterial1.material"); // Returns myTestMaterialAsset1
|
||||
*/
|
||||
class AssetSystemStub : public AzToolsFramework::AssetSystemRequestBus::Handler
|
||||
{
|
||||
public:
|
||||
|
||||
void Activate();
|
||||
void Deactivate();
|
||||
|
||||
void RegisterSourceInfo(const char* sourcePath, const AZ::Data::AssetId& assetId);
|
||||
void RegisterSourceInfo(const char* sourcePath, const AZ::Data::AssetInfo& assetInfo, const AZStd::string& watchFolder);
|
||||
|
||||
private:
|
||||
struct SourceInfo
|
||||
{
|
||||
AZ::Data::AssetInfo m_assetInfo;
|
||||
AZStd::string m_watchFolder;
|
||||
};
|
||||
|
||||
AZStd::unordered_map<AZStd::string, SourceInfo> m_sourceInfoMap;
|
||||
|
||||
bool GetSourceInfoBySourcePath(const char* sourcePath, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder) override;
|
||||
bool GetRelativeProductPathFromFullSourceOrProductPath(const AZStd::string& fullPath, AZStd::string& relativeProductPath) override;
|
||||
bool GenerateRelativeSourcePath(
|
||||
const AZStd::string& sourcePath, AZStd::string& relativePath, AZStd::string& watchFolder) override;
|
||||
bool GetFullSourcePathFromRelativeProductPath(const AZStd::string& relPath, AZStd::string& fullSourcePath) override;
|
||||
bool GetAssetInfoById(const AZ::Data::AssetId& assetId, const AZ::Data::AssetType& assetType, const AZStd::string& platformName, AZ::Data::AssetInfo& assetInfo, AZStd::string& rootFilePath) override;
|
||||
bool GetSourceInfoBySourceUUID(const AZ::Uuid& sourceUuid, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder) override;
|
||||
bool GetScanFolders(AZStd::vector<AZStd::string>& scanFolders) override;
|
||||
bool GetAssetSafeFolders(AZStd::vector<AZStd::string>& assetSafeFolders) override;
|
||||
bool IsAssetPlatformEnabled(const char* platform) override;
|
||||
int GetPendingAssetsForPlatform(const char* platform) override;
|
||||
bool GetAssetsProducedBySourceUUID(const AZ::Uuid& sourceUuid, AZStd::vector<AZ::Data::AssetInfo>& productsAssetInfo) override;
|
||||
};
|
||||
} // namespace UnitTest
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <Common/AssetManagerTestFixture.h>
|
||||
#include <Common/RHI/Stubs.h>
|
||||
#include <Common/RHI/Factory.h>
|
||||
#include <Common/AssetSystemStub.h>
|
||||
#include <Atom/Utils/TestUtils/AssetSystemStub.h>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
|
||||
@@ -10,8 +10,6 @@ set(FILES
|
||||
Tests/Buffer/BufferTests.cpp
|
||||
Tests/Common/AssetManagerTestFixture.cpp
|
||||
Tests/Common/AssetManagerTestFixture.h
|
||||
Tests/Common/AssetSystemStub.cpp
|
||||
Tests/Common/AssetSystemStub.h
|
||||
Tests/Common/ErrorMessageFinder.cpp
|
||||
Tests/Common/ErrorMessageFinder.h
|
||||
Tests/Common/ErrorMessageFinderTests.cpp
|
||||
|
||||
Reference in New Issue
Block a user