From 4245bf7ac97b01a97f43806cb4f68873bbd677ed Mon Sep 17 00:00:00 2001 From: Tobias Alexander Franke Date: Tue, 7 Dec 2021 17:00:52 +0800 Subject: [PATCH 01/17] Notify relative component to acquire wind information when the tag of global wind and local wind in PhysX configuration changes. Signed-off-by: T.J. McGrath-Daly --- Gems/PhysX/Code/Source/WindProvider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gems/PhysX/Code/Source/WindProvider.cpp b/Gems/PhysX/Code/Source/WindProvider.cpp index 3090cea062..c7d5d0863b 100644 --- a/Gems/PhysX/Code/Source/WindProvider.cpp +++ b/Gems/PhysX/Code/Source/WindProvider.cpp @@ -177,7 +177,7 @@ namespace PhysX AZStd::vector m_entityTransformHandlers; AZStd::vector m_pendingAabbUpdates; ChangeCallback m_changeCallback; - bool m_changed = false; + bool m_changed = true; }; WindProvider::WindProvider() From a6feef3563a6731c15ecb4090855027a0aae26b8 Mon Sep 17 00:00:00 2001 From: Guthrie Adams Date: Fri, 14 Jan 2022 16:51:46 -0600 Subject: [PATCH 02/17] Atom Tools: Created base class for document-based applications Moving some duplicated code to a common base class Signed-off-by: Guthrie Adams --- .../Document/AtomToolsDocumentApplication.h | 28 ++++++++++++++++ .../Document/AtomToolsDocumentApplication.cpp | 33 +++++++++++++++++++ .../Code/atomtoolsframework_files.cmake | 2 ++ .../Code/Source/MaterialEditorApplication.cpp | 18 +--------- .../Code/Source/MaterialEditorApplication.h | 13 +++----- .../ShaderManagementConsoleApplication.cpp | 19 +---------- .../ShaderManagementConsoleApplication.h | 13 +++----- 7 files changed, 75 insertions(+), 51 deletions(-) create mode 100644 Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Document/AtomToolsDocumentApplication.h create mode 100644 Gems/Atom/Tools/AtomToolsFramework/Code/Source/Document/AtomToolsDocumentApplication.cpp diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Document/AtomToolsDocumentApplication.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Document/AtomToolsDocumentApplication.h new file mode 100644 index 0000000000..7b9327337c --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Document/AtomToolsDocumentApplication.h @@ -0,0 +1,28 @@ +/* + * 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 + +namespace AtomToolsFramework +{ + class AtomToolsDocumentApplication + : public AtomToolsApplication + { + public: + AZ_TYPE_INFO(AtomToolsDocumentApplication, "{F4B43677-EB95-4CBB-8B8E-9EF4247E6F0D}"); + + using Base = AtomToolsApplication; + + AtomToolsDocumentApplication(int* argc, char*** argv); + + // AtomToolsApplication overrides... + void ProcessCommandLine(const AZ::CommandLine& commandLine) override; + }; +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Document/AtomToolsDocumentApplication.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Document/AtomToolsDocumentApplication.cpp new file mode 100644 index 0000000000..beb414bb6c --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Document/AtomToolsDocumentApplication.cpp @@ -0,0 +1,33 @@ +/* + * 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 +#include + +namespace AtomToolsFramework +{ + AtomToolsDocumentApplication::AtomToolsDocumentApplication(int* argc, char*** argv) + : Base(argc, argv) + { + } + + void AtomToolsDocumentApplication::ProcessCommandLine(const AZ::CommandLine& commandLine) + { + // Process command line options for opening documents on startup + size_t openDocumentCount = commandLine.GetNumMiscValues(); + for (size_t openDocumentIndex = 0; openDocumentIndex < openDocumentCount; ++openDocumentIndex) + { + const AZStd::string openDocumentPath = commandLine.GetMiscValue(openDocumentIndex); + + AZ_Printf(GetBuildTargetName().c_str(), "Opening document: %s", openDocumentPath.c_str()); + AtomToolsDocumentSystemRequestBus::Broadcast(&AtomToolsDocumentSystemRequestBus::Events::OpenDocument, openDocumentPath); + } + + Base::ProcessCommandLine(commandLine); + } +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake index 3ddcc05245..4f0e0d34e7 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake @@ -12,6 +12,7 @@ set(FILES Include/AtomToolsFramework/Communication/LocalSocket.h Include/AtomToolsFramework/Debug/TraceRecorder.h Include/AtomToolsFramework/Document/AtomToolsDocument.h + Include/AtomToolsFramework/Document/AtomToolsDocumentApplication.h Include/AtomToolsFramework/Document/AtomToolsDocumentMainWindow.h Include/AtomToolsFramework/Document/AtomToolsDocumentSystemSettings.h Include/AtomToolsFramework/Document/AtomToolsDocumentSystemRequestBus.h @@ -40,6 +41,7 @@ set(FILES Source/Communication/LocalSocket.cpp Source/Debug/TraceRecorder.cpp Source/Document/AtomToolsDocument.cpp + Source/Document/AtomToolsDocumentApplication.cpp Source/Document/AtomToolsDocumentMainWindow.cpp Source/Document/AtomToolsDocumentSystemSettings.cpp Source/Document/AtomToolsDocumentSystemComponent.cpp diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp index cec882cabb..15a5ff1715 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -37,7 +36,7 @@ namespace MaterialEditor } MaterialEditorApplication::MaterialEditorApplication(int* argc, char*** argv) - : AtomToolsApplication(argc, argv) + : Base(argc, argv) { QApplication::setApplicationName("O3DE Material Editor"); @@ -58,19 +57,4 @@ namespace MaterialEditor { return AZStd::vector({ "passes/", "config/", "MaterialEditor/" }); } - - void MaterialEditorApplication::ProcessCommandLine(const AZ::CommandLine& commandLine) - { - // Process command line options for opening one or more material documents on startup - size_t openDocumentCount = commandLine.GetNumMiscValues(); - for (size_t openDocumentIndex = 0; openDocumentIndex < openDocumentCount; ++openDocumentIndex) - { - const AZStd::string openDocumentPath = commandLine.GetMiscValue(openDocumentIndex); - - AZ_Printf(GetBuildTargetName().c_str(), "Opening document: %s", openDocumentPath.c_str()); - AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast(&AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument, openDocumentPath); - } - - Base::ProcessCommandLine(commandLine); - } } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h index e91bce48f0..bf2e6f6ca1 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h @@ -8,30 +8,27 @@ #pragma once -#include -#include +#include namespace MaterialEditor { class MaterialThumbnailRenderer; class MaterialEditorApplication - : public AtomToolsFramework::AtomToolsApplication + : public AtomToolsFramework::AtomToolsDocumentApplication { public: AZ_TYPE_INFO(MaterialEditor::MaterialEditorApplication, "{30F90CA5-1253-49B5-8143-19CEE37E22BB}"); - using Base = AtomToolsFramework::AtomToolsApplication; + using Base = AtomToolsFramework::AtomToolsDocumentApplication; MaterialEditorApplication(int* argc, char*** argv); - ////////////////////////////////////////////////////////////////////////// - // AzFramework::Application + // AzFramework::Application overrides... void CreateStaticModules(AZStd::vector& outModules) override; const char* GetCurrentConfigurationName() const override; - private: - void ProcessCommandLine(const AZ::CommandLine& commandLine) override; + // AtomToolsFramework::AtomToolsApplication overrides... AZStd::string GetBuildTargetName() const override; AZStd::vector GetCriticalAssetFilters() const override; }; diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp index 3d07a0de15..a242716b52 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -36,7 +35,7 @@ namespace ShaderManagementConsole } ShaderManagementConsoleApplication::ShaderManagementConsoleApplication(int* argc, char*** argv) - : AtomToolsApplication(argc, argv) + : Base(argc, argv) { QApplication::setApplicationName("O3DE Shader Management Console"); @@ -56,20 +55,4 @@ namespace ShaderManagementConsole { return AZStd::vector({ "passes/", "config/" }); } - - void ShaderManagementConsoleApplication::ProcessCommandLine(const AZ::CommandLine& commandLine) - { - // Process command line options for opening one or more documents on startup - size_t openDocumentCount = commandLine.GetNumMiscValues(); - for (size_t openDocumentIndex = 0; openDocumentIndex < openDocumentCount; ++openDocumentIndex) - { - const AZStd::string openDocumentPath = commandLine.GetMiscValue(openDocumentIndex); - - AZ_Printf(GetBuildTargetName().c_str(), "Opening document: %s", openDocumentPath.c_str()); - AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast( - &AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument, openDocumentPath); - } - - Base::ProcessCommandLine(commandLine); - } } // namespace ShaderManagementConsole diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h index 6596429577..6b0365e6bd 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h @@ -8,28 +8,25 @@ #pragma once -#include -#include +#include namespace ShaderManagementConsole { class ShaderManagementConsoleApplication - : public AtomToolsFramework::AtomToolsApplication + : public AtomToolsFramework::AtomToolsDocumentApplication { public: AZ_TYPE_INFO(ShaderManagementConsole::ShaderManagementConsoleApplication, "{A31B1AEB-4DA3-49CD-884A-CC998FF7546F}"); - using Base = AtomToolsFramework::AtomToolsApplication; + using Base = AtomToolsFramework::AtomToolsDocumentApplication; ShaderManagementConsoleApplication(int* argc, char*** argv); - ////////////////////////////////////////////////////////////////////////// - // AzFramework::Application + // AzFramework::Application overrides... void CreateStaticModules(AZStd::vector& outModules) override; const char* GetCurrentConfigurationName() const override; - private: - void ProcessCommandLine(const AZ::CommandLine& commandLine); + // AtomToolsFramework::AtomToolsApplication overrides... AZStd::string GetBuildTargetName() const override; AZStd::vector GetCriticalAssetFilters() const override; }; From aac28f73aaf9ff72232aafeaa589fcb0437a7cc8 Mon Sep 17 00:00:00 2001 From: Bindless-Chicken <1039134+Bindless-Chicken@users.noreply.github.com> Date: Mon, 17 Jan 2022 14:25:50 +0000 Subject: [PATCH 03/17] Fix missing ImGui::End in multiplayer windows Signed-off-by: Bindless-Chicken <1039134+Bindless-Chicken@users.noreply.github.com> --- .../Code/Source/Debug/MultiplayerDebugSystemComponent.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp index 4ff78d3815..4266072d20 100644 --- a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp +++ b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp @@ -386,7 +386,6 @@ namespace Multiplayer } ImGui::NewLine(); } - ImGui::End(); } void DrawMultiplayerStats() @@ -437,7 +436,6 @@ namespace Multiplayer ImGui::EndTable(); ImGui::NewLine(); } - ImGui::End(); } void MultiplayerDebugSystemComponent::OnImGuiUpdate() @@ -448,6 +446,7 @@ namespace Multiplayer { DrawNetworkingStats(); } + ImGui::End(); } if (m_displayMultiplayerStats) @@ -456,6 +455,7 @@ namespace Multiplayer { DrawMultiplayerStats(); } + ImGui::End(); } if (m_displayPerEntityStats) @@ -473,6 +473,7 @@ namespace Multiplayer m_reporter->OnImGuiUpdate(); } } + ImGui::End(); } if (m_displayHierarchyDebugger) @@ -489,6 +490,7 @@ namespace Multiplayer m_hierarchyDebugger->OnImGuiUpdate(); } } + ImGui::End(); } else { From 2b103ce445fb09ad955af4a44128132d58e5a48b Mon Sep 17 00:00:00 2001 From: dmcdiarmid-ly <63674186+dmcdiarmid-ly@users.noreply.github.com> Date: Mon, 17 Jan 2022 16:52:30 -0700 Subject: [PATCH 04/17] Added support for supervariants to the PrecompiledShaderBuilder Signed-off-by: dmcdiarmid-ly <63674186+dmcdiarmid-ly@users.noreply.github.com> --- .../AzslShaderBuilderSystemComponent.cpp | 2 +- .../Editor/PrecompiledShaderBuilder.cpp | 67 ++++++++++-------- ...seProbeGridBlendDistance.precompiledshader | 31 +++++---- ...ProbeGridBlendIrradiance.precompiledshader | 31 +++++---- ...beGridBorderUpdateColumn.precompiledshader | 33 +++++---- ...ProbeGridBorderUpdateRow.precompiledshader | 37 +++++----- ...eProbeGridClassification.precompiledshader | 31 +++++---- ...ffuseProbeGridRayTracing.precompiledshader | 38 ++++++----- ...GridRayTracingClosestHit.precompiledshader | 35 ++++++---- ...eProbeGridRayTracingMiss.precompiledshader | 33 +++++---- ...ffuseProbeGridRelocation.precompiledshader | 35 ++++++---- .../DiffuseProbeGridRender.precompiledshader | 35 ++++++---- .../Shader/PrecompiledShaderAssetSourceData.h | 27 ++++++-- .../RPI.Reflect/Shader/ShaderAssetCreator.h | 15 +++- .../PrecompiledShaderAssetSourceData.cpp | 28 ++++++-- .../RPI.Reflect/Shader/ShaderAssetCreator.cpp | 68 ++++++++++++------- 16 files changed, 340 insertions(+), 206 deletions(-) diff --git a/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp b/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp index cc80b38b85..eae4e804e0 100644 --- a/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp +++ b/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp @@ -120,7 +120,7 @@ namespace AZ // Register Precompiled Shader Builder AssetBuilderSDK::AssetBuilderDesc precompiledShaderBuilderDescriptor; precompiledShaderBuilderDescriptor.m_name = "Precompiled Shader Builder"; - precompiledShaderBuilderDescriptor.m_version = 10; // ATOM-15472 + precompiledShaderBuilderDescriptor.m_version = 11; // ATOM-15740 precompiledShaderBuilderDescriptor.m_patterns.push_back(AssetBuilderSDK::AssetBuilderPattern(AZStd::string::format("*.%s", AZ::PrecompiledShaderBuilder::Extension), AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard)); precompiledShaderBuilderDescriptor.m_busId = azrtti_typeid(); precompiledShaderBuilderDescriptor.m_createJobFunction = AZStd::bind(&PrecompiledShaderBuilder::CreateJobs, &m_precompiledShaderBuilder, AZStd::placeholders::_1, AZStd::placeholders::_2); diff --git a/Gems/Atom/Asset/Shader/Code/Source/Editor/PrecompiledShaderBuilder.cpp b/Gems/Atom/Asset/Shader/Code/Source/Editor/PrecompiledShaderBuilder.cpp index 2abee4d297..05b4ff309b 100644 --- a/Gems/Atom/Asset/Shader/Code/Source/Editor/PrecompiledShaderBuilder.cpp +++ b/Gems/Atom/Asset/Shader/Code/Source/Editor/PrecompiledShaderBuilder.cpp @@ -68,20 +68,23 @@ namespace AZ { AZStd::vector jobDependencyList; - // setup dependencies on the root azshadervariant asset file names - for (const auto& rootShaderVariantAsset : precompiledShaderAsset.m_rootShaderVariantAssets) + // setup dependencies on the root azshadervariant asset file names, for each supervariant + for (const auto& supervariant : precompiledShaderAsset.m_supervariants) { - AZStd::string rootShaderVariantAssetPath = RPI::AssetUtils::ResolvePathReference(request.m_sourceFile.c_str(), rootShaderVariantAsset->m_rootShaderVariantAssetFileName); - AssetBuilderSDK::SourceFileDependency sourceDependency; - sourceDependency.m_sourceFileDependencyPath = rootShaderVariantAssetPath; - response.m_sourceFileDependencyList.push_back(sourceDependency); - - AssetBuilderSDK::JobDependency jobDependency; - jobDependency.m_jobKey = "azshadervariant"; - jobDependency.m_platformIdentifier = platformInfo.m_identifier; - jobDependency.m_type = AssetBuilderSDK::JobDependencyType::Order; - jobDependency.m_sourceFile = sourceDependency; - jobDependencyList.push_back(jobDependency); + for (const auto& rootShaderVariantAsset : supervariant->m_rootShaderVariantAssets) + { + AZStd::string rootShaderVariantAssetPath = RPI::AssetUtils::ResolvePathReference(request.m_sourceFile.c_str(), rootShaderVariantAsset->m_rootShaderVariantAssetFileName); + AssetBuilderSDK::SourceFileDependency sourceDependency; + sourceDependency.m_sourceFileDependencyPath = rootShaderVariantAssetPath; + response.m_sourceFileDependencyList.push_back(sourceDependency); + + AssetBuilderSDK::JobDependency jobDependency; + jobDependency.m_jobKey = "azshadervariant"; + jobDependency.m_platformIdentifier = platformInfo.m_identifier; + jobDependency.m_type = AssetBuilderSDK::JobDependencyType::Order; + jobDependency.m_sourceFile = sourceDependency; + jobDependencyList.push_back(jobDependency); + } } AssetBuilderSDK::JobDescriptor job; @@ -137,33 +140,37 @@ namespace AZ AssetBuilderSDK::JobProduct jobProduct; - // load the variant product assets + // load the variant product assets, for each supervariant // these are the dependency root variant asset products that were processed prior to running this job - RPI::ShaderAssetCreator::ShaderRootVariantAssets rootVariantProductAssets; - for (AZStd::unique_ptr& rootShaderVariantAsset : precompiledShaderAsset.m_rootShaderVariantAssets) + RPI::ShaderAssetCreator::ShaderSupervariants supervariants; + for (const auto& supervariant : precompiledShaderAsset.m_supervariants) { - // retrieve the variant asset - auto assetOutcome = RPI::AssetUtils::LoadAsset(request.m_fullPath, rootShaderVariantAsset->m_rootShaderVariantAssetFileName, 0); - if (!assetOutcome) + RPI::ShaderAssetCreator::ShaderRootVariantAssets rootVariantProductAssets; + for (const auto& rootShaderVariantAsset : supervariant->m_rootShaderVariantAssets) { - AZ_Error(PrecompiledShaderBuilderName, false, "Failed to retrieve Variant asset for file [%s]", rootShaderVariantAsset->m_rootShaderVariantAssetFileName.c_str()); - return; - } + // retrieve the variant asset + auto assetOutcome = RPI::AssetUtils::LoadAsset(request.m_fullPath, rootShaderVariantAsset->m_rootShaderVariantAssetFileName, 0); + if (!assetOutcome) + { + AZ_Error(PrecompiledShaderBuilderName, false, "Failed to retrieve Variant asset for file [%s]", rootShaderVariantAsset->m_rootShaderVariantAssetFileName.c_str()); + return; + } - rootVariantProductAssets.push_back(AZStd::make_pair(RHI::APIType{ rootShaderVariantAsset->m_apiName.GetCStr() }, assetOutcome.GetValue())); + rootVariantProductAssets.push_back(AZStd::make_pair(RHI::APIType{ rootShaderVariantAsset->m_apiName.GetCStr() }, assetOutcome.GetValue())); + + AssetBuilderSDK::ProductDependency productDependency; + productDependency.m_dependencyId = assetOutcome.GetValue().GetId(); + productDependency.m_flags = AZ::Data::ProductDependencyInfo::CreateFlags(AZ::Data::AssetLoadBehavior::PreLoad); + jobProduct.m_dependencies.push_back(productDependency); + } - AssetBuilderSDK::ProductDependency productDependency; - productDependency.m_dependencyId = assetOutcome.GetValue().GetId(); - productDependency.m_flags = AZ::Data::ProductDependencyInfo::CreateFlags(AZ::Data::AssetLoadBehavior::PreLoad); - jobProduct.m_dependencies.push_back(productDependency); + supervariants.push_back({ supervariant->m_name, rootVariantProductAssets }); } // use the ShaderAssetCreator to clone the shader asset, which will update the embedded Srg and Variant asset UUIDs // Note that the Srg and Variant assets do not have embedded asset references and are processed with the RC Copy functionality RPI::ShaderAssetCreator shaderAssetCreator; - shaderAssetCreator.Clone(Uuid::CreateRandom(), - *shaderAsset, - rootVariantProductAssets); + shaderAssetCreator.Clone(Uuid::CreateRandom(), *shaderAsset, supervariants); Data::Asset outputShaderAsset; if (!shaderAssetCreator.End(outputShaderAsset)) diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendDistance.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendDistance.precompiledshader index be1d87ff3e..81d6bde5f0 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendDistance.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendDistance.precompiledshader @@ -7,21 +7,28 @@ "ShaderAssetFileName": "diffuseprobegridblenddistance.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendIrradiance.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendIrradiance.precompiledshader index 92fb12d5cc..9fa8e27461 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendIrradiance.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendIrradiance.precompiledshader @@ -7,21 +7,28 @@ "ShaderAssetFileName": "diffuseprobegridblendirradiance.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateColumn.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateColumn.precompiledshader index 8de77320f0..f2363bd5ee 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateColumn.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateColumn.precompiledshader @@ -5,23 +5,30 @@ "ClassData": { "ShaderAssetFileName": "diffuseprobegridborderupdatecolumn.azshader", - "PlatformIdentifiers": + "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateRow.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateRow.precompiledshader index 274dae91af..d87cc47a38 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateRow.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateRow.precompiledshader @@ -2,26 +2,31 @@ "Type": "JsonSerialization", "Version": 1, "ClassName": "PrecompiledShaderAssetSourceData", - "ClassData": - { + "ClassData": { "ShaderAssetFileName": "diffuseprobegridborderupdaterow.azshader", - "PlatformIdentifiers": - [ - "pc", "linux" + "PlatformIdentifiers": [ + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridClassification.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridClassification.precompiledshader index 85f75e6364..66671fd7bc 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridClassification.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridClassification.precompiledshader @@ -7,21 +7,28 @@ "ShaderAssetFileName": "diffuseprobegridclassification.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridclassification_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridclassification_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridclassification_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridclassification_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridclassification_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridclassification_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracing.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracing.precompiledshader index 88aa115b63..7b156ca7e5 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracing.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracing.precompiledshader @@ -2,27 +2,33 @@ "Type": "JsonSerialization", "Version": 1, "ClassName": "PrecompiledShaderAssetSourceData", - "ClassData": + "ClassData": { "ShaderAssetFileName": "diffuseprobegridraytracing.azshader", - "PlatformIdentifiers": - [ - "pc", "linux" + "PlatformIdentifiers": [ + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_null_0.azshadervariant" + } + ] } ] } -} +} \ No newline at end of file diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingClosestHit.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingClosestHit.precompiledshader index 948fc793ab..d19eb4baf1 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingClosestHit.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingClosestHit.precompiledshader @@ -2,27 +2,34 @@ "Type": "JsonSerialization", "Version": 1, "ClassName": "PrecompiledShaderAssetSourceData", - "ClassData": + "ClassData": { "ShaderAssetFileName": "diffuseprobegridraytracingclosesthit.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_null_0.azshadervariant" + } + ] } ] } -} +} \ No newline at end of file diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingMiss.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingMiss.precompiledshader index dec0e244b1..d30783db14 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingMiss.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingMiss.precompiledshader @@ -2,26 +2,33 @@ "Type": "JsonSerialization", "Version": 1, "ClassName": "PrecompiledShaderAssetSourceData", - "ClassData": + "ClassData": { "ShaderAssetFileName": "diffuseprobegridraytracingmiss.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRelocation.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRelocation.precompiledshader index e09a29a7e8..56b487ceb6 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRelocation.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRelocation.precompiledshader @@ -2,27 +2,34 @@ "Type": "JsonSerialization", "Version": 1, "ClassName": "PrecompiledShaderAssetSourceData", - "ClassData": + "ClassData": { "ShaderAssetFileName": "diffuseprobegridrelocation.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_null_0.azshadervariant" + } + ] } ] } -} +} \ No newline at end of file diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRender.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRender.precompiledshader index 279deaaa29..97c58091a2 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRender.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRender.precompiledshader @@ -7,22 +7,29 @@ "ShaderAssetFileName": "diffuseprobegridrender.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridrender_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridrender_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridrender_null_0.azshadervariant" - } + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridrender_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridrender_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridrender_null_0.azshadervariant" + } + ] + } ] } -} +} \ No newline at end of file diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.h index ce5a4c8a7a..956367c126 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.h @@ -17,14 +17,14 @@ namespace AZ namespace RPI { - //! This asset contains is loaded from a Json file and contains information about + //! This asset is loaded from a Json file and contains information about //! precompiled shader variants and their associated API name. - struct RootShaderVariantAssetSourceData final + struct PrecompiledRootShaderVariantAssetSourceData final : public Data::AssetData { public: - AZ_RTTI(RootShaderVariantAssetSourceData, "{661EF8A7-7BAC-41B6-AD5C-C7249B2390AD}"); - AZ_CLASS_ALLOCATOR(RootShaderVariantAssetSourceData, SystemAllocator, 0); + AZ_RTTI(PrecompiledRootShaderVariantAssetSourceData, "{661EF8A7-7BAC-41B6-AD5C-C7249B2390AD}"); + AZ_CLASS_ALLOCATOR(PrecompiledRootShaderVariantAssetSourceData, SystemAllocator, 0); static void Reflect(ReflectContext* context); @@ -32,7 +32,22 @@ namespace AZ AZStd::string m_rootShaderVariantAssetFileName; }; - //! This asset contains is loaded from a Json file and contains information about + //! This asset is loaded from a Json file and contains information about + //! precompiled shader supervariants + struct PrecompiledSupervariantSourceData final + : public Data::AssetData + { + public: + AZ_RTTI(PrecompiledSupervariantSourceData, "{630BDF15-CE7C-4E2C-882E-4F7AF09C8BB6}"); + AZ_CLASS_ALLOCATOR(PrecompiledSupervariantSourceData, SystemAllocator, 0); + + static void Reflect(ReflectContext* context); + + AZ::Name m_name; + AZStd::vector> m_rootShaderVariantAssets; + }; + + //! This asset is loaded from a Json file and contains information about //! precompiled shader assets. struct PrecompiledShaderAssetSourceData final : public Data::AssetData @@ -45,7 +60,7 @@ namespace AZ AZStd::string m_shaderAssetFileName; AZStd::vector m_platformIdentifiers; - AZStd::vector> m_rootShaderVariantAssets; + AZStd::vector> m_supervariants; }; } // namespace RPI } // namespace AZ diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAssetCreator.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAssetCreator.h index 22854a4559..d0c9729948 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAssetCreator.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAssetCreator.h @@ -75,11 +75,20 @@ namespace AZ bool End(Data::Asset& shaderAsset); - //! Clones an existing ShaderAsset nd replaces the referenced Srg and Variant assets - using ShaderRootVariantAssets = AZStd::vector>>; + //! Clones an existing ShaderAsset and replaces the ShaderVariant assets + using ShaderRootVariantAssetPair = AZStd::pair>; + using ShaderRootVariantAssets = AZStd::vector; + + struct ShaderSupervariant + { + AZ::Name m_name; + ShaderRootVariantAssets m_rootVariantAssets; + }; + using ShaderSupervariants = AZStd::vector; + void Clone(const Data::AssetId& assetId, const ShaderAsset& sourceShaderAsset, - const ShaderRootVariantAssets& rootVariantAssets); + const ShaderSupervariants& supervariants); private: diff --git a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.cpp b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.cpp index a7a9344d6e..62fb904b37 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.cpp @@ -14,29 +14,43 @@ namespace AZ { namespace RPI { - void RootShaderVariantAssetSourceData::Reflect(ReflectContext* context) + void PrecompiledRootShaderVariantAssetSourceData::Reflect(ReflectContext* context) { if (auto* serializeContext = azrtti_cast(context)) { - serializeContext->Class() + serializeContext->Class() ->Version(0) - ->Field("APIName", &RootShaderVariantAssetSourceData::m_apiName) - ->Field("RootShaderVariantAssetFileName", &RootShaderVariantAssetSourceData::m_rootShaderVariantAssetFileName) + ->Field("APIName", &PrecompiledRootShaderVariantAssetSourceData::m_apiName) + ->Field("RootShaderVariantAssetFileName", &PrecompiledRootShaderVariantAssetSourceData::m_rootShaderVariantAssetFileName) + ; + } + } + + void PrecompiledSupervariantSourceData::Reflect(ReflectContext* context) + { + PrecompiledRootShaderVariantAssetSourceData::Reflect(context); + + if (auto* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(0) + ->Field("Name", &PrecompiledSupervariantSourceData::m_name) + ->Field("RootShaderVariantAssets", &PrecompiledSupervariantSourceData::m_rootShaderVariantAssets) ; } } void PrecompiledShaderAssetSourceData::Reflect(ReflectContext* context) { - RootShaderVariantAssetSourceData::Reflect(context); + PrecompiledSupervariantSourceData::Reflect(context); if (auto* serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(1) // ATOM-15472 + ->Version(2) // ATOM-15740 ->Field("ShaderAssetFileName", &PrecompiledShaderAssetSourceData::m_shaderAssetFileName) ->Field("PlatformIdentifiers", &PrecompiledShaderAssetSourceData::m_platformIdentifiers) - ->Field("RootShaderVariantAssets", &PrecompiledShaderAssetSourceData::m_rootShaderVariantAssets) + ->Field("Supervariants", &PrecompiledShaderAssetSourceData::m_supervariants) ; } } diff --git a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAssetCreator.cpp b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAssetCreator.cpp index 5df37aa211..e56561b400 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAssetCreator.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAssetCreator.cpp @@ -382,7 +382,7 @@ namespace AZ return EndCommon(shaderAsset); } - void ShaderAssetCreator::Clone(const Data::AssetId& assetId, const ShaderAsset& sourceShaderAsset, [[maybe_unused]] const ShaderRootVariantAssets& rootVariantAssets) + void ShaderAssetCreator::Clone(const Data::AssetId& assetId, const ShaderAsset& sourceShaderAsset, [[maybe_unused]] const ShaderSupervariants& supervariants) { BeginCommon(assetId); @@ -392,38 +392,60 @@ namespace AZ m_asset->m_shaderOptionGroupLayout = sourceShaderAsset.m_shaderOptionGroupLayout; m_asset->m_buildTimestamp = sourceShaderAsset.m_buildTimestamp; - // copy root variant assets + // copy the perAPIShaderData for (auto& perAPIShaderData : sourceShaderAsset.m_perAPIShaderData) { - // find the matching ShaderVariantAsset - AZ::Data::Asset foundVariantAsset; - for (const auto& variantAsset : rootVariantAssets) + if (perAPIShaderData.m_supervariants.empty()) { - if (variantAsset.first == perAPIShaderData.m_APIType) - { - foundVariantAsset = variantAsset.second; - break; - } + ReportWarning("Attempting to clone a shader asset that has no supervariants for API [%d]", perAPIShaderData.m_APIType); + continue; } - - if (!foundVariantAsset) + + if (perAPIShaderData.m_supervariants.size() != supervariants.size()) { - ReportWarning("Failed to find variant asset for API [%d]", perAPIShaderData.m_APIType); + ReportError("Incorrect number of supervariants provided to ShaderAssetCreator::Clone"); + return; } - + m_asset->m_perAPIShaderData.push_back(perAPIShaderData); - if (m_asset->m_perAPIShaderData.back().m_supervariants.empty()) - { - ReportWarning("Attempting to clone a shader asset that has no supervariants for API [%d]", perAPIShaderData.m_APIType); - } - else + + // set the supervariants for this API + for (auto& supervariant : m_asset->m_perAPIShaderData.back().m_supervariants) { - // currently we only support one supervariant when cloning - // [GFX TODO][ATOM-15740] Support multiple supervariants in ShaderAssetCreator::Clone - m_asset->m_perAPIShaderData.back().m_supervariants[0].m_rootShaderVariantAsset = foundVariantAsset; + // find the matching Supervariant by name from the incoming list + ShaderSupervariants::const_iterator itFoundSuperVariant = AZStd::find_if( + supervariants.begin(), + supervariants.end(), + [&supervariant](const ShaderSupervariant& shaderSupervariant) + { + return supervariant.m_name == shaderSupervariant.m_name; + }); + + if (itFoundSuperVariant == supervariants.end()) + { + ReportError("Failed to find supervariant [%s]", supervariant.m_name.GetCStr()); + return; + } + + // find the matching ShaderVariantAsset for this API + ShaderRootVariantAssets::const_iterator itFoundRootShaderVariantAsset = AZStd::find_if( + itFoundSuperVariant->m_rootVariantAssets.begin(), + itFoundSuperVariant->m_rootVariantAssets.end(), + [&perAPIShaderData](const ShaderRootVariantAssetPair& rootShaderVariantAsset) + { + return perAPIShaderData.m_APIType == rootShaderVariantAsset.first; + }); + + if (itFoundRootShaderVariantAsset == itFoundSuperVariant->m_rootVariantAssets.end()) + { + ReportWarning("Failed to find root shader variant asset for API [%d] Supervariant [%s]", perAPIShaderData.m_APIType, supervariant.m_name.GetCStr()); + } + else + { + supervariant.m_rootShaderVariantAsset = itFoundRootShaderVariantAsset->second; + } } } - } } // namespace RPI } // namespace AZ From 626b16dbaeeb40594303fa49ad473d37684eb9b1 Mon Sep 17 00:00:00 2001 From: Gene Walters Date: Tue, 18 Jan 2022 10:27:10 -0800 Subject: [PATCH 05/17] Updating NetworkingSpawnableLibrary to only store network spawnables, instead of all spawnables Signed-off-by: Gene Walters --- .../Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp | 4 ++-- .../Code/Source/NetworkEntity/NetworkSpawnableLibrary.h | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp index f60778dbb4..7fb7bfdc39 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include namespace Multiplayer @@ -42,7 +41,8 @@ namespace Multiplayer auto enumerateCallback = [this](const AZ::Data::AssetId id, const AZ::Data::AssetInfo& info) { - if (info.m_assetType == AZ::AzTypeInfo::Uuid()) + if (info.m_assetType == AZ::AzTypeInfo::Uuid() && + info.m_relativePath.ends_with(".network.spawnable")) { ProcessSpawnableAsset(info.m_relativePath, id); } diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h index 0fc3ae07cc..469086f4cb 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h @@ -23,12 +23,15 @@ namespace Multiplayer NetworkSpawnableLibrary(); ~NetworkSpawnableLibrary(); - /// INetworkSpawnableLibrary overrides. + //! INetworkSpawnableLibrary overrides. + //! @{ + // Iterates over all assets (on-disk and in-memory) and stores any spawnables that are "network.spawnables" + // This allows us to look up network spawnable assets by name or id for later use void BuildSpawnablesList() override; void ProcessSpawnableAsset(const AZStd::string& relativePath, AZ::Data::AssetId id) override; AZ::Name GetSpawnableNameFromAssetId(AZ::Data::AssetId assetId) override; AZ::Data::AssetId GetAssetIdByName(AZ::Name name) override; - + //! @} private: AZStd::unordered_map m_spawnables; From b09caa5e7576af98b060f339308f779c9af1b6d5 Mon Sep 17 00:00:00 2001 From: Guthrie Adams Date: Tue, 18 Jan 2022 17:14:49 -0600 Subject: [PATCH 06/17] Atom Tools: disabling auto load of unused gems in some atom tools Atom tools are set up to inherit and automatically load all of the gems used by the game project. This is a great simplification that saves us from having to manually update cmake settings for every game project to push dependencies to every tool. The tradeoff is that some dependencies will be added to certain tools that have no relevance whatsoever, potentially wasting initialization time, memory utilization, and some processing. This change follows an existing example to update a couple of tools to forego initializing unused gems. They can easily be reenabled as needed. Signed-off-by: Guthrie Adams --- .../Include/AtomToolsFramework/Util/Util.h | 2 +- .../Code/Source/Util/Util.cpp | 6 +- .../EditorMaterialSystemComponent.cpp | 2 +- Registry/gem_autoload.materialeditor.setreg | 69 +++++++++++++++++++ ...em_autoload.shadermanagementconsole.setreg | 69 +++++++++++++++++++ 5 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 Registry/gem_autoload.materialeditor.setreg create mode 100644 Registry/gem_autoload.shadermanagementconsole.setreg diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Util/Util.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Util/Util.h index ab2b8b46c0..57355e4f56 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Util/Util.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Util/Util.h @@ -38,5 +38,5 @@ namespace AtomToolsFramework QFileInfo GetOpenFileInfo(const AZStd::vector& assetTypes); QFileInfo GetUniqueFileInfo(const QString& initialPath); QFileInfo GetDuplicationFileInfo(const QString& initialPath); - bool LaunchTool(const QString& baseName, const QString& extension, const QStringList& arguments); + bool LaunchTool(const QString& baseName, const QStringList& arguments); } // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/Util.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/Util.cpp index b45ff3c12f..89a5407260 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/Util.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/Util.cpp @@ -168,13 +168,13 @@ namespace AtomToolsFramework return duplicateFileInfo; } - bool LaunchTool(const QString& baseName, const QString& extension, const QStringList& arguments) + bool LaunchTool(const QString& baseName, const QStringList& arguments) { AZ::IO::FixedMaxPath engineRoot = AZ::Utils::GetEnginePath(); AZ_Assert(!engineRoot.empty(), "Cannot query Engine Path"); - AZ::IO::FixedMaxPath launchPath = AZ::IO::FixedMaxPath(AZ::Utils::GetExecutableDirectory()) - / (baseName + extension).toUtf8().constData(); + AZ::IO::FixedMaxPath launchPath = + AZ::IO::FixedMaxPath(AZ::Utils::GetExecutableDirectory()) / (baseName + AZ_TRAIT_OS_EXECUTABLE_EXTENSION).toUtf8().constData(); return QProcess::startDetached(launchPath.c_str(), arguments, engineRoot.c_str()); } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp index adaebfb889..e216606401 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp @@ -143,7 +143,7 @@ namespace AZ arguments.append(QString("--project-path=%1").arg(projectPath.c_str())); } - AtomToolsFramework::LaunchTool("MaterialEditor", AZ_TRAIT_OS_EXECUTABLE_EXTENSION, arguments); + AtomToolsFramework::LaunchTool("MaterialEditor", arguments); } void EditorMaterialSystemComponent::OpenMaterialInspector( diff --git a/Registry/gem_autoload.materialeditor.setreg b/Registry/gem_autoload.materialeditor.setreg new file mode 100644 index 0000000000..fd00ff05c7 --- /dev/null +++ b/Registry/gem_autoload.materialeditor.setreg @@ -0,0 +1,69 @@ +{ + "Amazon": { + "Gems": { + "ImGui.Editor": { + "AutoLoad": false + }, + "Gestures.Editor": { + "AutoLoad": false + }, + "GraphCanvas.Editor": { + "AutoLoad": false + }, + "GraphModel.Editor": { + "AutoLoad": false + }, + "PhysX.Editor": { + "AutoLoad": false + }, + "PhysXDebug.Editor": { + "AutoLoad": false + }, + "Blast.Editor": { + "AutoLoad": false + }, + "NVCloth.Editor": { + "AutoLoad": false + }, + "ScriptCanvas.Editor": { + "AutoLoad": false + }, + "ScriptCanvasPhysics": { + "AutoLoad": false + }, + "ScriptCanvasTesting.Editor": { + "AutoLoad": false + }, + "LandscapeCanvas.Editor": { + "AutoLoad": false + }, + "HttpRequestor.Editor": { + "AutoLoad": false + }, + "WhiteBox.Editor": { + "AutoLoad": false + }, + "PythonAssetBuilder.Editor": { + "AutoLoad": false + }, + "AWSCore": { + "AutoLoad": false + }, + "AWSCore.Editor": { + "AutoLoad": false + }, + "AWSClientAuth": { + "AutoLoad": false + }, + "AWSClientAuth.Editor": { + "AutoLoad": false + }, + "AWSMetrics": { + "AutoLoad": false + }, + "AWSMetrics.Editor": { + "AutoLoad": false + } + } + } +} diff --git a/Registry/gem_autoload.shadermanagementconsole.setreg b/Registry/gem_autoload.shadermanagementconsole.setreg new file mode 100644 index 0000000000..fd00ff05c7 --- /dev/null +++ b/Registry/gem_autoload.shadermanagementconsole.setreg @@ -0,0 +1,69 @@ +{ + "Amazon": { + "Gems": { + "ImGui.Editor": { + "AutoLoad": false + }, + "Gestures.Editor": { + "AutoLoad": false + }, + "GraphCanvas.Editor": { + "AutoLoad": false + }, + "GraphModel.Editor": { + "AutoLoad": false + }, + "PhysX.Editor": { + "AutoLoad": false + }, + "PhysXDebug.Editor": { + "AutoLoad": false + }, + "Blast.Editor": { + "AutoLoad": false + }, + "NVCloth.Editor": { + "AutoLoad": false + }, + "ScriptCanvas.Editor": { + "AutoLoad": false + }, + "ScriptCanvasPhysics": { + "AutoLoad": false + }, + "ScriptCanvasTesting.Editor": { + "AutoLoad": false + }, + "LandscapeCanvas.Editor": { + "AutoLoad": false + }, + "HttpRequestor.Editor": { + "AutoLoad": false + }, + "WhiteBox.Editor": { + "AutoLoad": false + }, + "PythonAssetBuilder.Editor": { + "AutoLoad": false + }, + "AWSCore": { + "AutoLoad": false + }, + "AWSCore.Editor": { + "AutoLoad": false + }, + "AWSClientAuth": { + "AutoLoad": false + }, + "AWSClientAuth.Editor": { + "AutoLoad": false + }, + "AWSMetrics": { + "AutoLoad": false + }, + "AWSMetrics.Editor": { + "AutoLoad": false + } + } + } +} From eb51cd4c06670380314c1a54a5b10a858749b354 Mon Sep 17 00:00:00 2001 From: Guthrie Adams Date: Tue, 18 Jan 2022 01:50:05 -0600 Subject: [PATCH 07/17] Atom Tools: moving custom asset browser code to common location Consolidated duplicate asset browser code from multiple tools into single class in atom tools framework Moved creation of asset browser and Python terminal windows into base main window class Fixed docked window orientations Added checks to asset browser to prevent crashes if tree state saver was null Signed-off-by: Guthrie Adams --- .../Views/AssetBrowserTreeView.cpp | 11 +- .../AssetBrowser/AtomToolsAssetBrowser.h} | 48 ++-- .../Window/AtomToolsMainWindow.h | 3 + .../AssetBrowser/AtomToolsAssetBrowser.cpp} | 211 +++++++++--------- .../AssetBrowser/AtomToolsAssetBrowser.qrc | 5 + .../AssetBrowser/AtomToolsAssetBrowser.ui} | 4 +- .../Code/Source/AssetBrowser/Icons/view.svg} | 0 .../Document/AtomToolsDocumentMainWindow.cpp | 2 + .../Source/Window/AtomToolsMainWindow.cpp | 6 + .../Code/atomtoolsframework_files.cmake | 4 + .../Code/Source/Window/MaterialEditor.qrc | 1 - .../Source/Window/MaterialEditorWindow.cpp | 36 ++- .../Code/Source/Window/MaterialEditorWindow.h | 5 +- .../Window/MaterialEditorWindowModule.cpp | 1 + .../Code/materialeditorwindow_files.cmake | 3 - .../Code/CMakeLists.txt | 1 - .../ShaderManagementConsoleBrowserWidget.h | 69 ------ .../ShaderManagementConsoleBrowserWidget.ui | 168 -------------- .../Window/ShaderManagementConsoleWindow.cpp | 19 +- .../Window/ShaderManagementConsoleWindow.h | 4 +- .../ShaderManagementConsoleWindowModule.cpp | 12 +- .../shadermanagementconsolewindow_files.cmake | 3 - 22 files changed, 210 insertions(+), 406 deletions(-) rename Gems/Atom/Tools/{MaterialEditor/Code/Source/Window/MaterialBrowserWidget.h => AtomToolsFramework/Code/Include/AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowser.h} (54%) rename Gems/Atom/Tools/{MaterialEditor/Code/Source/Window/MaterialBrowserWidget.cpp => AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.cpp} (56%) create mode 100644 Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.qrc rename Gems/Atom/Tools/{MaterialEditor/Code/Source/Window/MaterialBrowserWidget.ui => AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.ui} (98%) rename Gems/Atom/Tools/{MaterialEditor/Code/Source/Window/Icons/View.svg => AtomToolsFramework/Code/Source/AssetBrowser/Icons/view.svg} (100%) delete mode 100644 Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserWidget.h delete mode 100644 Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserWidget.ui diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/AssetBrowserTreeView.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/AssetBrowserTreeView.cpp index 146eab9073..93a153cc16 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/AssetBrowserTreeView.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/AssetBrowserTreeView.cpp @@ -230,7 +230,10 @@ namespace AzToolsFramework { QModelIndex curIndex = selectedIndexes[0]; m_expandToEntriesByDefault = true; - m_treeStateSaver->ApplySnapshot(); + if (m_treeStateSaver) + { + m_treeStateSaver->ApplySnapshot(); + } setCurrentIndex(curIndex); scrollTo(curIndex); @@ -240,8 +243,12 @@ namespace AzToolsFramework // Flag our default expansion state so that we expand down to source entries after filtering m_expandToEntriesByDefault = hasFilter; + // Then ask our state saver to apply its current snapshot again, falling back on asking us if entries should be expanded or not - m_treeStateSaver->ApplySnapshot(); + if (m_treeStateSaver) + { + m_treeStateSaver->ApplySnapshot(); + } // If we're filtering for a valid entry, select the first valid entry if (hasFilter && selectFirstValidEntry) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialBrowserWidget.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowser.h similarity index 54% rename from Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialBrowserWidget.h rename to Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowser.h index 24a244bc3c..915387d7b1 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialBrowserWidget.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowser.h @@ -9,17 +9,14 @@ #pragma once #if !defined(Q_MOC_RUN) -#include #include #include -#include #include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT #include #include AZ_POP_DISABLE_WARNING - #endif namespace AzToolsFramework @@ -27,49 +24,50 @@ namespace AzToolsFramework namespace AssetBrowser { class AssetBrowserFilterModel; - class CompositeFilter; - class AssetBrowserEntry; - class ProductAssetBrowserEntry; - class SourceAssetBrowserEntry; } -} +} // namespace AzToolsFramework namespace Ui { - class MaterialBrowserWidget; + class AtomToolsAssetBrowser; } -namespace MaterialEditor +namespace AtomToolsFramework { - //! Provides a tree view of all available materials and other assets exposed by the MaterialEditor. - class MaterialBrowserWidget + //! Extends the standard asset browser with custom filters and multiselect behavior + class AtomToolsAssetBrowser : public QWidget , protected AZ::TickBus::Handler - , protected AtomToolsFramework::AtomToolsDocumentNotificationBus::Handler { Q_OBJECT public: - MaterialBrowserWidget(QWidget* parent = nullptr); - ~MaterialBrowserWidget(); + AtomToolsAssetBrowser(QWidget* parent = nullptr); + ~AtomToolsAssetBrowser(); - private: - AzToolsFramework::AssetBrowser::FilterConstType CreateFilter() const; + void SetFilterState(const AZStd::string& category, const AZStd::string& displayName, bool enabled); + void SetOpenHandler(AZStd::function openHandler); + + void SelectEntries(const AZStd::string& absolutePath); void OpenSelectedEntries(); + void OpenOptionsMenu(); - // AtomToolsDocumentNotificationBus::Handler implementation - void OnDocumentOpened(const AZ::Uuid& documentId) override; + protected: + AzToolsFramework::AssetBrowser::FilterConstType CreateFilter() const; + void UpdateFilter(); + void UpdatePreview(); + void TogglePreview(); // AZ::TickBus::Handler void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; - void OpenOptionsMenu(); - - QScopedPointer m_ui; + QScopedPointer m_ui; AzToolsFramework::AssetBrowser::AssetBrowserFilterModel* m_filterModel = nullptr; - //! if new asset is being created with this path it will automatically be selected + //! If an asset is opened with this path it will automatically be selected AZStd::string m_pathToSelect; - QByteArray m_materialBrowserState; + QByteArray m_browserState; + + AZStd::function m_openHandler; }; -} // namespace MaterialEditor +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Window/AtomToolsMainWindow.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Window/AtomToolsMainWindow.h index fab6e2fb01..92218d2542 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Window/AtomToolsMainWindow.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Window/AtomToolsMainWindow.h @@ -8,6 +8,7 @@ #pragma once +#include #include #include #include @@ -53,6 +54,8 @@ namespace AtomToolsFramework QMenu* m_menuView = {}; QMenu* m_menuHelp = {}; + AtomToolsFramework::AtomToolsAssetBrowser* m_assetBrowser = {}; + AZStd::unordered_map m_dockWidgets; AZStd::unordered_map m_dockActions; }; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialBrowserWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.cpp similarity index 56% rename from Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialBrowserWidget.cpp rename to Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.cpp index 4df76b4dac..4270cb87fe 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialBrowserWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.cpp @@ -6,13 +6,9 @@ * */ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include #include #include @@ -21,41 +17,32 @@ #include #include #include -#include -#include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT #include -#include #include -#include -#include #include #include #include -#include AZ_POP_DISABLE_WARNING -namespace MaterialEditor +namespace AtomToolsFramework { - MaterialBrowserWidget::MaterialBrowserWidget(QWidget* parent) + AtomToolsAssetBrowser::AtomToolsAssetBrowser(QWidget* parent) : QWidget(parent) - , m_ui(new Ui::MaterialBrowserWidget) + , m_ui(new Ui::AtomToolsAssetBrowser) { using namespace AzToolsFramework::AssetBrowser; m_ui->setupUi(this); m_ui->m_searchWidget->Setup(true, true); - m_ui->m_searchWidget->SetFilterState("", AZ::RPI::StreamingImageAsset::Group, true); - m_ui->m_searchWidget->SetFilterState("", AZ::RPI::MaterialAsset::Group, true); m_ui->m_searchWidget->setMinimumSize(QSize(150, 0)); - m_ui->m_viewOptionButton->setIcon(QIcon(":/Icons/View.svg")); + + m_ui->m_viewOptionButton->setIcon(QIcon(":/Icons/view.svg")); m_ui->m_splitter->setSizes(QList() << 400 << 200); m_ui->m_splitter->setStretchFactor(0, 1); - connect(m_ui->m_viewOptionButton, &QPushButton::clicked, this, &MaterialBrowserWidget::OpenOptionsMenu); - // Get the asset browser model AssetBrowserModel* assetBrowserModel = nullptr; AssetBrowserComponentRequestBus::BroadcastResult(assetBrowserModel, &AssetBrowserComponentRequests::GetAssetBrowserModel); @@ -73,38 +60,82 @@ namespace MaterialEditor // Maintains the tree expansion state between runs m_ui->m_assetBrowserTreeViewWidget->SetName("AssetBrowserTreeView_main"); - connect(m_ui->m_searchWidget->GetFilter().data(), &AssetBrowserEntryFilter::updatedSignal, m_filterModel, &AssetBrowserFilterModel::filterUpdatedSlot); - connect(m_filterModel, &AssetBrowserFilterModel::filterChanged, this, [this]() + connect(m_filterModel, &AssetBrowserFilterModel::filterChanged, this, &AtomToolsAssetBrowser::UpdateFilter); + connect(m_ui->m_assetBrowserTreeViewWidget, &AssetBrowserTreeView::activated, this, &AtomToolsAssetBrowser::OpenSelectedEntries); + connect(m_ui->m_assetBrowserTreeViewWidget, &AssetBrowserTreeView::selectionChangedSignal, this, &AtomToolsAssetBrowser::UpdatePreview); + connect(m_ui->m_viewOptionButton, &QPushButton::clicked, this, &AtomToolsAssetBrowser::OpenOptionsMenu); + connect( + m_ui->m_searchWidget->GetFilter().data(), &AssetBrowserEntryFilter::updatedSignal, m_filterModel, + &AssetBrowserFilterModel::filterUpdatedSlot); + } + + AtomToolsAssetBrowser::~AtomToolsAssetBrowser() + { + // Maintains the tree expansion state between runs + m_ui->m_assetBrowserTreeViewWidget->SaveState(); + AZ::TickBus::Handler::BusDisconnect(); + } + + void AtomToolsAssetBrowser::SetFilterState(const AZStd::string& category, const AZStd::string& displayName, bool enabled) + { + m_ui->m_searchWidget->SetFilterState(category.c_str(), displayName.c_str(), enabled); + } + + void AtomToolsAssetBrowser::SetOpenHandler(AZStd::function openHandler) + { + m_openHandler = openHandler; + } + + void AtomToolsAssetBrowser::SelectEntries(const AZStd::string& absolutePath) + { + if (!absolutePath.empty()) { - const bool hasFilter = !m_ui->m_searchWidget->GetFilterString().isEmpty(); - constexpr bool selectFirstFilteredIndex = true; - m_ui->m_assetBrowserTreeViewWidget->UpdateAfterFilter(hasFilter, selectFirstFilteredIndex); - }); - connect(m_ui->m_assetBrowserTreeViewWidget, &AssetBrowserTreeView::activated, this, &MaterialBrowserWidget::OpenSelectedEntries); - connect(m_ui->m_assetBrowserTreeViewWidget, &AssetBrowserTreeView::selectionChangedSignal, [this]() { - const auto& selectedAssets = m_ui->m_assetBrowserTreeViewWidget->GetSelectedAssets(); - if (!selectedAssets.empty()) + // Selecting a new asset in the browser is not guaranteed to happen immediately. + // The asset browser model notifications are sent before the model is updated. + // Instead of relying on the notifications, queue the selection and process it on tick until this change occurs. + m_pathToSelect = absolutePath; + AzFramework::StringFunc::Path::Normalize(m_pathToSelect); + AZ::TickBus::Handler::BusConnect(); + } + } + + void AtomToolsAssetBrowser::OpenSelectedEntries() + { + const AZStd::vector entries = m_ui->m_assetBrowserTreeViewWidget->GetSelectedAssets(); + + const int multiSelectPromptThreshold = 10; + if (entries.size() >= multiSelectPromptThreshold) + { + QMessageBox::StandardButton result = QMessageBox::question( + QApplication::activeWindow(), + tr("Attemptng to open %1 files").arg(entries.size()), + tr("Would you like to open anyway?"), + QMessageBox::Yes | QMessageBox::No); + if (result == QMessageBox::No) { - m_ui->m_previewerFrame->Display(selectedAssets.front()); + return; } - else + } + + for (const AssetBrowserEntry* entry : entries) + { + if (entry && entry->GetEntryType() != AssetBrowserEntry::AssetEntryType::Folder && m_openHandler) { - m_ui->m_previewerFrame->Clear(); + m_openHandler(entry->GetFullPath().c_str()); } - }); - - AtomToolsFramework::AtomToolsDocumentNotificationBus::Handler::BusConnect(); + } } - MaterialBrowserWidget::~MaterialBrowserWidget() + void AtomToolsAssetBrowser::OpenOptionsMenu() { - // Maintains the tree expansion state between runs - m_ui->m_assetBrowserTreeViewWidget->SaveState(); - AtomToolsFramework::AtomToolsDocumentNotificationBus::Handler::BusDisconnect(); - AZ::TickBus::Handler::BusDisconnect(); + QMenu menu; + QAction* action = menu.addAction(tr("Show Asset Preview"), this, &AtomToolsAssetBrowser::TogglePreview); + action->setCheckable(true); + action->setChecked(m_ui->m_previewerFrame->isVisible()); + menu.exec(QCursor::pos()); } - AzToolsFramework::AssetBrowser::FilterConstType MaterialBrowserWidget::CreateFilter() const + AzToolsFramework::AssetBrowser::FilterConstType AtomToolsAssetBrowser::CreateFilter() const { using namespace AzToolsFramework::AssetBrowser; @@ -125,59 +156,42 @@ namespace MaterialEditor return finalFilter; } - void MaterialBrowserWidget::OpenSelectedEntries() + void AtomToolsAssetBrowser::UpdateFilter() { - const AZStd::vector entries = m_ui->m_assetBrowserTreeViewWidget->GetSelectedAssets(); + const bool hasFilter = !m_ui->m_searchWidget->GetFilterString().isEmpty(); + constexpr bool selectFirstFilteredIndex = true; + m_ui->m_assetBrowserTreeViewWidget->UpdateAfterFilter(hasFilter, selectFirstFilteredIndex); + } - const int multiSelectPromptThreshold = 10; - if (entries.size() >= multiSelectPromptThreshold) + void AtomToolsAssetBrowser::UpdatePreview() + { + const auto& selectedAssets = m_ui->m_assetBrowserTreeViewWidget->GetSelectedAssets(); + if (!selectedAssets.empty()) { - if (QMessageBox::question( - QApplication::activeWindow(), - QString("Attemptng to open %1 files").arg(entries.size()), - "Would you like to open anyway?", - QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) - { - return; - } + m_ui->m_previewerFrame->Display(selectedAssets.front()); } - - for (const AssetBrowserEntry* entry : entries) + else { - if (entry) - { - if (AzFramework::StringFunc::Path::IsExtension(entry->GetFullPath().c_str(), AZ::RPI::MaterialSourceData::Extension)) - { - AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast(&AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument, entry->GetFullPath()); - } - else if (AzFramework::StringFunc::Path::IsExtension(entry->GetFullPath().c_str(), AZ::RPI::MaterialTypeSourceData::Extension)) - { - //ignore AZ::RPI::MaterialTypeSourceData::Extension - } - else - { - QDesktopServices::openUrl(QUrl::fromLocalFile(entry->GetFullPath().c_str())); - } - } + m_ui->m_previewerFrame->Clear(); } } - void MaterialBrowserWidget::OnDocumentOpened(const AZ::Uuid& documentId) + void AtomToolsAssetBrowser::TogglePreview() { - AZStd::string absolutePath; - AtomToolsFramework::AtomToolsDocumentRequestBus::EventResult(absolutePath, documentId, &AtomToolsFramework::AtomToolsDocumentRequestBus::Events::GetAbsolutePath); - if (!absolutePath.empty()) + const bool isPreviewFrameVisible = m_ui->m_previewerFrame->isVisible(); + m_ui->m_previewerFrame->setVisible(!isPreviewFrameVisible); + if (isPreviewFrameVisible) { - // Selecting a new asset in the browser is not guaranteed to happen immediately. - // The asset browser model notifications are sent before the model is updated. - // Instead of relying on the notifications, queue the selection and process it on tick until this change occurs. - m_pathToSelect = absolutePath; - AzFramework::StringFunc::Path::Normalize(m_pathToSelect); - AZ::TickBus::Handler::BusConnect(); + m_browserState = m_ui->m_splitter->saveState(); + m_ui->m_splitter->setSizes(QList({ 1, 0 })); + } + else + { + m_ui->m_splitter->restoreState(m_browserState); } } - void MaterialBrowserWidget::OnTick(float deltaTime, AZ::ScriptTimePoint time) + void AtomToolsAssetBrowser::OnTick(float deltaTime, AZ::ScriptTimePoint time) { AZ_UNUSED(time); AZ_UNUSED(deltaTime); @@ -188,7 +202,7 @@ namespace MaterialEditor AzToolsFramework::AssetBrowser::AssetBrowserViewRequestBus::Broadcast( &AzToolsFramework::AssetBrowser::AssetBrowserViewRequestBus::Events::SelectFileAtPath, m_pathToSelect); - // Iterate over the selected entries to verify if the selection was made + // Iterate over the selected entries to verify if the selection was made for (const AssetBrowserEntry* entry : m_ui->m_assetBrowserTreeViewWidget->GetSelectedAssets()) { if (entry) @@ -205,31 +219,6 @@ namespace MaterialEditor } } } +} // namespace AtomToolsFramework - void MaterialBrowserWidget::OpenOptionsMenu() - { - QMenu menu; - - QAction* action = new QAction("Show Asset Preview", this); - action->setCheckable(true); - action->setChecked(m_ui->m_previewerFrame->isVisible()); - connect(action, &QAction::triggered, [this]() { - bool isPreviewFrameVisible = m_ui->m_previewerFrame->isVisible(); - m_ui->m_previewerFrame->setVisible(!isPreviewFrameVisible); - if (isPreviewFrameVisible) - { - m_materialBrowserState = m_ui->m_splitter->saveState(); - m_ui->m_splitter->setSizes(QList({ 1, 0 })); - } - else - { - m_ui->m_splitter->restoreState(m_materialBrowserState); - } - }); - menu.addAction(action); - menu.exec(QCursor::pos()); - } - -} // namespace MaterialEditor - -#include +#include diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.qrc b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.qrc new file mode 100644 index 0000000000..c24968e78a --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.qrc @@ -0,0 +1,5 @@ + + + Icons/view.svg + + diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialBrowserWidget.ui b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.ui similarity index 98% rename from Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialBrowserWidget.ui rename to Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.ui index 9e5344bea2..9b68b3edc9 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialBrowserWidget.ui +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowser.ui @@ -1,7 +1,7 @@ - MaterialBrowserWidget - + AtomToolsAssetBrowser + 0 diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/Icons/View.svg b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/Icons/view.svg similarity index 100% rename from Gems/Atom/Tools/MaterialEditor/Code/Source/Window/Icons/View.svg rename to Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/Icons/view.svg diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Document/AtomToolsDocumentMainWindow.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Document/AtomToolsDocumentMainWindow.cpp index 0d62adc9ee..e8be20097f 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Document/AtomToolsDocumentMainWindow.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Document/AtomToolsDocumentMainWindow.cpp @@ -414,6 +414,8 @@ namespace AtomToolsFramework m_actionPreviousTab->setEnabled(m_tabWidget->count() > 1); m_actionNextTab->setEnabled(m_tabWidget->count() > 1); + m_assetBrowser->SelectEntries(absolutePath); + activateWindow(); raise(); diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Window/AtomToolsMainWindow.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Window/AtomToolsMainWindow.cpp index f07fd9c536..6a30ffc421 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Window/AtomToolsMainWindow.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Window/AtomToolsMainWindow.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -40,6 +41,11 @@ namespace AtomToolsFramework centralWidget->setLayout(centralWidgetLayout); setCentralWidget(centralWidget); + m_assetBrowser = new AtomToolsFramework::AtomToolsAssetBrowser(this); + AddDockWidget("Asset Browser", m_assetBrowser, Qt::BottomDockWidgetArea, Qt::Horizontal); + AddDockWidget("Python Terminal", new AzToolsFramework::CScriptTermDialog, Qt::BottomDockWidgetArea, Qt::Horizontal); + SetDockWidgetVisible("Python Terminal", false); + AtomToolsMainWindowRequestBus::Handler::BusConnect(); } diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake index 3ddcc05245..3de1bb65e2 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake @@ -8,6 +8,7 @@ set(FILES Include/AtomToolsFramework/Application/AtomToolsApplication.h + Include/AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowser.h Include/AtomToolsFramework/Communication/LocalServer.h Include/AtomToolsFramework/Communication/LocalSocket.h Include/AtomToolsFramework/Debug/TraceRecorder.h @@ -36,6 +37,9 @@ set(FILES Include/AtomToolsFramework/Window/AtomToolsMainWindowFactoryRequestBus.h Include/AtomToolsFramework/Window/AtomToolsMainWindowNotificationBus.h Source/Application/AtomToolsApplication.cpp + Source/AssetBrowser/AtomToolsAssetBrowser.cpp + Source/AssetBrowser/AtomToolsAssetBrowser.qrc + Source/AssetBrowser/AtomToolsAssetBrowser.ui Source/Communication/LocalServer.cpp Source/Communication/LocalSocket.cpp Source/Debug/TraceRecorder.cpp diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditor.qrc b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditor.qrc index 902201e792..73b55f2f39 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditor.qrc +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditor.qrc @@ -21,6 +21,5 @@ Icons/shadow.svg Icons/skybox.svg Icons/toneMapping.svg - Icons/View.svg diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp index 0388af0134..44adda432d 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp @@ -8,15 +8,16 @@ #include #include +#include +#include #include +#include #include #include #include -#include #include #include #include -#include #include #include #include @@ -27,14 +28,16 @@ AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnin #include #include #include +#include #include +#include #include AZ_POP_DISABLE_WARNING namespace MaterialEditor { MaterialEditorWindow::MaterialEditorWindow(QWidget* parent /* = 0 */) - : AtomToolsFramework::AtomToolsDocumentMainWindow(parent) + : Base(parent) { resize(1280, 1024); @@ -72,15 +75,30 @@ namespace MaterialEditor m_materialViewport->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); centralWidget()->layout()->addWidget(m_materialViewport); - AddDockWidget("Asset Browser", new MaterialBrowserWidget, Qt::BottomDockWidgetArea, Qt::Vertical); - AddDockWidget("Inspector", new MaterialInspector, Qt::RightDockWidgetArea, Qt::Horizontal); - AddDockWidget("Viewport Settings", new ViewportSettingsInspector, Qt::LeftDockWidgetArea, Qt::Horizontal); - AddDockWidget("Performance Monitor", new PerformanceMonitorWidget, Qt::RightDockWidgetArea, Qt::Horizontal); - AddDockWidget("Python Terminal", new AzToolsFramework::CScriptTermDialog, Qt::BottomDockWidgetArea, Qt::Horizontal); + m_assetBrowser->SetFilterState("", AZ::RPI::StreamingImageAsset::Group, true); + m_assetBrowser->SetFilterState("", AZ::RPI::MaterialAsset::Group, true); + m_assetBrowser->SetOpenHandler([](const AZStd::string& absolutePath) { + if (AzFramework::StringFunc::Path::IsExtension(absolutePath.c_str(), AZ::RPI::MaterialSourceData::Extension)) + { + AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast( + &AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument, absolutePath); + return; + } + + if (AzFramework::StringFunc::Path::IsExtension(absolutePath.c_str(), AZ::RPI::MaterialTypeSourceData::Extension)) + { + return; + } + + QDesktopServices::openUrl(QUrl::fromLocalFile(absolutePath.c_str())); + }); + + AddDockWidget("Inspector", new MaterialInspector, Qt::RightDockWidgetArea, Qt::Vertical); + AddDockWidget("Viewport Settings", new ViewportSettingsInspector, Qt::LeftDockWidgetArea, Qt::Vertical); + AddDockWidget("Performance Monitor", new PerformanceMonitorWidget, Qt::BottomDockWidgetArea, Qt::Horizontal); SetDockWidgetVisible("Viewport Settings", false); SetDockWidgetVisible("Performance Monitor", false); - SetDockWidgetVisible("Python Terminal", false); // Restore geometry and show the window mainWindowWrapper->showFromSettings(); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h index bed2aa34e4..8ad294c529 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h @@ -21,7 +21,6 @@ namespace MaterialEditor { //! MaterialEditorWindow is the main class. Its responsibility is limited to initializing and connecting //! its panels, managing selection of assets, and performing high-level actions like saving. It contains... - //! 1) MaterialBrowser - The user browses for Material (.material) assets. //! 2) MaterialViewport - The user can see the selected Material applied to a model. //! 3) MaterialPropertyInspector - The user edits the properties of the selected Material. class MaterialEditorWindow @@ -48,7 +47,7 @@ namespace MaterialEditor void closeEvent(QCloseEvent* closeEvent) override; - MaterialViewportWidget* m_materialViewport = nullptr; - MaterialEditorToolBar* m_toolBar = nullptr; + MaterialViewportWidget* m_materialViewport = {}; + MaterialEditorToolBar* m_toolBar = {}; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowModule.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowModule.cpp index c761c85556..1562d11647 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowModule.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowModule.cpp @@ -14,6 +14,7 @@ void InitMaterialEditorResources() //Must register qt resources from other modules Q_INIT_RESOURCE(MaterialEditor); Q_INIT_RESOURCE(InspectorWidget); + Q_INIT_RESOURCE(AtomToolsAssetBrowser); } namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake index b814ad3f47..3d21e71294 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake @@ -15,9 +15,6 @@ set(FILES Source/Window/MaterialEditorWindow.cpp Source/Window/MaterialEditorWindowModule.cpp Source/Window/MaterialEditorWindowSettings.cpp - Source/Window/MaterialBrowserWidget.h - Source/Window/MaterialBrowserWidget.cpp - Source/Window/MaterialBrowserWidget.ui Source/Window/MaterialEditor.qrc Source/Window/MaterialEditor.qss Source/Window/MaterialEditorWindowComponent.h diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/CMakeLists.txt b/Gems/Atom/Tools/ShaderManagementConsole/Code/CMakeLists.txt index 3f7788418a..c5ceab5360 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/CMakeLists.txt +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/CMakeLists.txt @@ -42,7 +42,6 @@ ly_add_target( NAME ShaderManagementConsole.Window STATIC NAMESPACE Gem AUTOMOC - AUTOUIC AUTORCC FILES_CMAKE shadermanagementconsolewindow_files.cmake diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserWidget.h b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserWidget.h deleted file mode 100644 index 73a2a24aa9..0000000000 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserWidget.h +++ /dev/null @@ -1,69 +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 - -#if !defined(Q_MOC_RUN) -#include -#include -#include -#include - -AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT -#include -AZ_POP_DISABLE_WARNING - -#endif - -namespace AzToolsFramework -{ - namespace AssetBrowser - { - class AssetBrowserFilterModel; - class CompositeFilter; - class AssetBrowserEntry; - class ProductAssetBrowserEntry; - class SourceAssetBrowserEntry; - } -} - -namespace Ui -{ - class ShaderManagementConsoleBrowserWidget; -} - -namespace ShaderManagementConsole -{ - //! Provides a tree view of all available assets - class ShaderManagementConsoleBrowserWidget - : public QWidget - , public AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationBus::Handler - , public AtomToolsFramework::AtomToolsDocumentNotificationBus::Handler - { - Q_OBJECT - public: - ShaderManagementConsoleBrowserWidget(QWidget* parent = nullptr); - ~ShaderManagementConsoleBrowserWidget(); - - private: - AzToolsFramework::AssetBrowser::FilterConstType CreateFilter() const; - void OpenSelectedEntries(); - - QScopedPointer m_ui; - AzToolsFramework::AssetBrowser::AssetBrowserFilterModel* m_filterModel = nullptr; - - //! if new asset is being created with this path it will automatically be selected - AZStd::string m_pathToSelect; - - // AssetBrowserModelNotificationBus::Handler implementation - void EntryAdded(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) override; - - // AtomToolsFramework::AtomToolsDocumentNotificationBus::Handler implementation - void OnDocumentOpened(const AZ::Uuid& documentId) override; - }; -} // namespace ShaderManagementConsole diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserWidget.ui b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserWidget.ui deleted file mode 100644 index cf8a714273..0000000000 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserWidget.ui +++ /dev/null @@ -1,168 +0,0 @@ - - - ShaderManagementConsoleBrowserWidget - - - - 0 - 0 - 691 - 554 - - - - Asset Browser - - - - 0 - - - - - - 1 - 1 - - - - true - - - - - 0 - 0 - 671 - 534 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - 0 - 0 - - - - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - false - - - - - 0 - 0 - - - - vertical-align: top - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 1 - 0 - - - - QAbstractItemView::DragOnly - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - - - - - - - - - AzToolsFramework::AssetBrowser::SearchWidget - QWidget -
AzToolsFramework/AssetBrowser/Search/SearchWidget.h
- 1 -
- - AzToolsFramework::AssetBrowser::AssetBrowserTreeView - QTreeView -
AzToolsFramework/AssetBrowser/Views/AssetBrowserTreeView.h
-
- - AzToolsFramework::AssetBrowser::PreviewerFrame - QFrame -
AzToolsFramework/AssetBrowser/Previewer/PreviewerFrame.h
- 1 -
-
- - -
diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.cpp index 29dafe99fe..8e8e047e83 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.cpp +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.cpp @@ -7,23 +7,25 @@ */ #include +#include #include #include #include -#include #include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT +#include #include #include #include +#include #include AZ_POP_DISABLE_WARNING namespace ShaderManagementConsole { ShaderManagementConsoleWindow::ShaderManagementConsoleWindow(QWidget* parent /* = 0 */) - : AtomToolsFramework::AtomToolsDocumentMainWindow(parent) + : Base(parent) { resize(1280, 1024); @@ -41,10 +43,17 @@ namespace ShaderManagementConsole m_toolBar->setObjectName("ToolBar"); addToolBar(m_toolBar); - AddDockWidget("Asset Browser", new ShaderManagementConsoleBrowserWidget, Qt::BottomDockWidgetArea, Qt::Vertical); - AddDockWidget("Python Terminal", new AzToolsFramework::CScriptTermDialog, Qt::BottomDockWidgetArea, Qt::Horizontal); + m_assetBrowser->SetFilterState("", AZ::RPI::ShaderAsset::Group, true); + m_assetBrowser->SetOpenHandler([](const AZStd::string& absolutePath) { + if (AzFramework::StringFunc::Path::IsExtension(absolutePath.c_str(), AZ::RPI::ShaderVariantListSourceData::Extension)) + { + AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast( + &AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument, absolutePath); + return; + } - SetDockWidgetVisible("Python Terminal", false); + QDesktopServices::openUrl(QUrl::fromLocalFile(absolutePath.c_str())); + }); // Restore geometry and show the window mainWindowWrapper->showFromSettings(); diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.h b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.h index 3ba122674a..1c7479e526 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.h +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.h @@ -14,9 +14,7 @@ #include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT -#include #include - #include AZ_POP_DISABLE_WARNING #endif @@ -40,6 +38,6 @@ namespace ShaderManagementConsole protected: QWidget* CreateDocumentTabView(const AZ::Uuid& documentId) override; - ShaderManagementConsoleToolBar* m_toolBar = nullptr; + ShaderManagementConsoleToolBar* m_toolBar = {}; }; } // namespace ShaderManagementConsole diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindowModule.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindowModule.cpp index 3db5b236d6..a13b873aee 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindowModule.cpp +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindowModule.cpp @@ -9,10 +9,20 @@ #include #include +void InitShaderManagementConsoleResources() +{ + // Must register qt resources from other modules + Q_INIT_RESOURCE(ShaderManagementConsole); + Q_INIT_RESOURCE(InspectorWidget); + Q_INIT_RESOURCE(AtomToolsAssetBrowser); +} + namespace ShaderManagementConsole { ShaderManagementConsoleWindowModule::ShaderManagementConsoleWindowModule() { + InitShaderManagementConsoleResources(); + // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here. m_descriptors.insert(m_descriptors.end(), { ShaderManagementConsoleWindowComponent::CreateDescriptor(), @@ -25,4 +35,4 @@ namespace ShaderManagementConsole azrtti_typeid(), }; } -} +} // namespace ShaderManagementConsole diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/shadermanagementconsolewindow_files.cmake b/Gems/Atom/Tools/ShaderManagementConsole/Code/shadermanagementconsolewindow_files.cmake index 0d33d990a4..fb5cc0dad6 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/shadermanagementconsolewindow_files.cmake +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/shadermanagementconsolewindow_files.cmake @@ -14,9 +14,6 @@ set(FILES Source/Window/ShaderManagementConsoleWindow.h Source/Window/ShaderManagementConsoleWindow.cpp Source/Window/ShaderManagementConsoleWindowModule.cpp - Source/Window/ShaderManagementConsoleBrowserWidget.h - Source/Window/ShaderManagementConsoleBrowserWidget.cpp - Source/Window/ShaderManagementConsoleBrowserWidget.ui Source/Window/ShaderManagementConsole.qrc Source/Window/ShaderManagementConsoleWindowComponent.h Source/Window/ShaderManagementConsoleWindowComponent.cpp From 54de15b0ecd555a481c24f569e382d8a1e514ad0 Mon Sep 17 00:00:00 2001 From: Gene Walters Date: Tue, 18 Jan 2022 16:34:58 -0800 Subject: [PATCH 08/17] Adding '.network.spawnable' as a network constant Signed-off-by: Gene Walters --- .../Code/Include/Multiplayer/MultiplayerConstants.h | 1 + .../Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp | 3 ++- .../Code/Source/Pipeline/NetworkPrefabProcessor.cpp | 3 ++- Gems/Multiplayer/Code/Tests/PrefabProcessingTests.cpp | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerConstants.h b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerConstants.h index 4471aa0c2b..3a4a9b1f58 100644 --- a/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerConstants.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerConstants.h @@ -20,6 +20,7 @@ namespace Multiplayer constexpr AZStd::string_view MpNetworkInterfaceName("MultiplayerNetworkInterface"); constexpr AZStd::string_view MpEditorInterfaceName("MultiplayerEditorNetworkInterface"); constexpr AZStd::string_view LocalHost("127.0.0.1"); + constexpr AZStd::string_view NetworkSpawnableFileExtension(".network.spawnable"); constexpr uint16_t DefaultServerPort = 33450; constexpr uint16_t DefaultServerEditorPort = 33451; diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp index 7fb7bfdc39..e668d43267 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace Multiplayer { @@ -42,7 +43,7 @@ namespace Multiplayer auto enumerateCallback = [this](const AZ::Data::AssetId id, const AZ::Data::AssetInfo& info) { if (info.m_assetType == AZ::AzTypeInfo::Uuid() && - info.m_relativePath.ends_with(".network.spawnable")) + info.m_relativePath.ends_with(NetworkSpawnableFileExtension)) { ProcessSpawnableAsset(info.m_relativePath, id); } diff --git a/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp b/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp index a797523bc0..9d6c47bb00 100644 --- a/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp +++ b/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -95,7 +96,7 @@ namespace Multiplayer using namespace AzToolsFramework::Prefab; AZStd::string uniqueName = prefab.GetName(); - uniqueName += ".network.spawnable"; + uniqueName += NetworkSpawnableFileExtension; auto serializer = [serializationFormat](AZStd::vector& output, const ProcessedObjectStore& object) -> bool { AZ::IO::ByteContainerStream stream(&output); diff --git a/Gems/Multiplayer/Code/Tests/PrefabProcessingTests.cpp b/Gems/Multiplayer/Code/Tests/PrefabProcessingTests.cpp index aef13fbfe2..32be828686 100644 --- a/Gems/Multiplayer/Code/Tests/PrefabProcessingTests.cpp +++ b/Gems/Multiplayer/Code/Tests/PrefabProcessingTests.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace UnitTest @@ -92,7 +93,7 @@ namespace UnitTest // Verify the name and the type of the spawnable asset const AZ::Data::AssetData& spawnableAsset = processedObjects[0].GetAsset(); - EXPECT_EQ(prefabName + ".network.spawnable", processedObjects[0].GetId()); + EXPECT_EQ(prefabName + Multiplayer::NetworkSpawnableFileExtension.data(), processedObjects[0].GetId()); EXPECT_EQ(spawnableAsset.GetType(), azrtti_typeid()); // Verify we have only the networked entity in the network spawnable and not the static one From fbfea49b68dbd0fb5c139087a6acbfe4a2f0c6be Mon Sep 17 00:00:00 2001 From: Gene Walters Date: Tue, 18 Jan 2022 23:55:40 -0800 Subject: [PATCH 09/17] small comment tweak based on feedback Signed-off-by: Gene Walters --- .../Code/Source/NetworkEntity/NetworkSpawnableLibrary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h index 469086f4cb..ab6211f522 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h @@ -26,7 +26,7 @@ namespace Multiplayer //! INetworkSpawnableLibrary overrides. //! @{ // Iterates over all assets (on-disk and in-memory) and stores any spawnables that are "network.spawnables" - // This allows us to look up network spawnable assets by name or id for later use + // This allows users to look up network spawnable assets by name or id if needed later void BuildSpawnablesList() override; void ProcessSpawnableAsset(const AZStd::string& relativePath, AZ::Data::AssetId id) override; AZ::Name GetSpawnableNameFromAssetId(AZ::Data::AssetId assetId) override; From 667a9df34231b2215cda2877b8f2ae0c70e2b243 Mon Sep 17 00:00:00 2001 From: Benjamin Jillich <43751992+amzn-jillich@users.noreply.github.com> Date: Wed, 19 Jan 2022 17:20:27 +0100 Subject: [PATCH 10/17] ImGui: Added new histogram group helper (#6998) * Added a helper class for a group containing several histograms. * The group is shown using collapsible header. Signed-off-by: Benjamin Jillich --- .../Include/LYImGuiUtils/HistogramGroup.h | 54 ++++++++++++ .../Source/LYImGuiUtils/HistogramGroup.cpp | 82 +++++++++++++++++++ .../Code/imgui_lyutils_static_files.cmake | 2 + 3 files changed, 138 insertions(+) create mode 100644 Gems/ImGui/Code/Include/LYImGuiUtils/HistogramGroup.h create mode 100644 Gems/ImGui/Code/Source/LYImGuiUtils/HistogramGroup.cpp diff --git a/Gems/ImGui/Code/Include/LYImGuiUtils/HistogramGroup.h b/Gems/ImGui/Code/Include/LYImGuiUtils/HistogramGroup.h new file mode 100644 index 0000000000..b3c7e0e7d8 --- /dev/null +++ b/Gems/ImGui/Code/Include/LYImGuiUtils/HistogramGroup.h @@ -0,0 +1,54 @@ +/* + * 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 + +#ifdef IMGUI_ENABLED + +#include +#include +#include + +#include +#include + +namespace ImGui::LYImGuiUtils +{ + //! Helper for a group containing several histograms. + //! The group is shown using collapsible header. + class HistogramGroup + { + public: + HistogramGroup() = default; + HistogramGroup(const char* name, int histogramBinCount); + + void OnImGuiUpdate(); + void PushHistogramValue(const char* valueName, float value, const AZ::Color& color); + + const char* GetName() const { return m_name.c_str(); } + const AZStd::string& GetNameString() const { return m_name; } + void SetName(AZStd::string name) { m_name = name; } + + void SetHistogramBinCount(int count) { m_histogramBinCount = count; } + + //! Needs to be public for l-value access for ImGui::MenuItem() + bool m_show = true; + + private: + AZStd::string m_name; //< The name shown in the collapsible header. + int m_histogramBinCount = 100; //< The number of bins in the histogram. + + using HistogramIndexByNames = AZStd::unordered_map; + HistogramIndexByNames m_histogramIndexByName; //< Look-up table for the histogram index by name. + AZStd::vector m_histograms; //< Owns the histogram containers. + + static constexpr float s_histogramHeight = 85.0f; + }; +} // namespace ImGui::LYImGuiUtils + +#endif // IMGUI_ENABLED diff --git a/Gems/ImGui/Code/Source/LYImGuiUtils/HistogramGroup.cpp b/Gems/ImGui/Code/Source/LYImGuiUtils/HistogramGroup.cpp new file mode 100644 index 0000000000..62e8eb7b33 --- /dev/null +++ b/Gems/ImGui/Code/Source/LYImGuiUtils/HistogramGroup.cpp @@ -0,0 +1,82 @@ +/* + * 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 + * + */ + +#ifdef IMGUI_ENABLED +#include "LYImGuiUtils/HistogramGroup.h" + +namespace ImGui::LYImGuiUtils +{ + HistogramGroup::HistogramGroup(const char* name, int histogramBinCount) + : m_name(name) + , m_histogramBinCount(histogramBinCount) + { + } + + void HistogramGroup::PushHistogramValue(const char* valueName, float value, const AZ::Color& color) + { + auto iterator = m_histogramIndexByName.find(valueName); + if (iterator != m_histogramIndexByName.end()) + { + ImGui::LYImGuiUtils::HistogramContainer& histogramContiner = m_histograms[iterator->second]; + histogramContiner.PushValue(value); + histogramContiner.SetBarLineColor(ImColor(color.GetR(), color.GetG(), color.GetB(), color.GetA())); + } + else + { + ImGui::LYImGuiUtils::HistogramContainer newHistogram; + newHistogram.Init(/*histogramName=*/valueName, + /*containerCount=*/m_histogramBinCount, + /*viewType=*/ImGui::LYImGuiUtils::HistogramContainer::ViewType::Histogram, + /*displayOverlays=*/true, + /*min=*/0.0f, + /*max=*/0.0f); + + newHistogram.SetMoveDirection(ImGui::LYImGuiUtils::HistogramContainer::PushRightMoveLeft); + newHistogram.PushValue(value); + + m_histogramIndexByName[valueName] = m_histograms.size(); + m_histograms.push_back(newHistogram); + } + } + + void HistogramGroup::OnImGuiUpdate() + { + if (!m_show) + { + return; + } + + if (ImGui::CollapsingHeader(m_name.c_str(), ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed)) + { + for (auto& histogram : m_histograms) + { + ImGui::BeginGroup(); + { + histogram.Draw(ImGui::GetColumnWidth() - 70, s_histogramHeight); + + ImGui::SameLine(); + + ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0,0,0,255)); + { + const ImColor color = histogram.GetBarLineColor(); + ImGui::PushStyleColor(ImGuiCol_Button, color.Value); + { + const AZStd::string valueString = AZStd::string::format("%.2f", histogram.GetLastValue()); + ImGui::Button(valueString.c_str()); + } + ImGui::PopStyleColor(); + } + ImGui::PopStyleColor(); + } + ImGui::EndGroup(); + } + } + } +} // namespace ImGui::LYImGuiUtils + +#endif // IMGUI_ENABLED diff --git a/Gems/ImGui/Code/imgui_lyutils_static_files.cmake b/Gems/ImGui/Code/imgui_lyutils_static_files.cmake index d63730e6cb..9807cfe29d 100644 --- a/Gems/ImGui/Code/imgui_lyutils_static_files.cmake +++ b/Gems/ImGui/Code/imgui_lyutils_static_files.cmake @@ -8,7 +8,9 @@ set(FILES Include/LYImGuiUtils/HistogramContainer.h + Include/LYImGuiUtils/HistogramGroup.h Include/LYImGuiUtils/ImGuiDrawHelpers.h Source/LYImGuiUtils/HistogramContainer.cpp + Source/LYImGuiUtils/HistogramGroup.cpp Source/LYImGuiUtils/ImGuiDrawHelpers.cpp ) From 65a749494e01453f542ddbdfe143894608bc1be2 Mon Sep 17 00:00:00 2001 From: Ignacio Martinez <82394219+AMZN-Igarri@users.noreply.github.com> Date: Wed, 19 Jan 2022 17:45:52 +0100 Subject: [PATCH 11/17] Fix: Entity Outliner: Outliner is unusable with the Editor in slice mode (#6983) * Fixed vertical offset Signed-off-by: AMZN-Igarri <82394219+AMZN-Igarri@users.noreply.github.com> * Fixed QPoint Signed-off-by: AMZN-Igarri <82394219+AMZN-Igarri@users.noreply.github.com> * Fixed Entry delegate Signed-off-by: AMZN-Igarri <82394219+AMZN-Igarri@users.noreply.github.com> * SetRenderHint in Entry delegate Signed-off-by: AMZN-Igarri <82394219+AMZN-Igarri@users.noreply.github.com> * Save and restore painter inside the highlighter Signed-off-by: AMZN-Igarri <82394219+AMZN-Igarri@users.noreply.github.com> * Restoring Painter Signed-off-by: AMZN-Igarri <82394219+AMZN-Igarri@users.noreply.github.com> * Removed comment Signed-off-by: AMZN-Igarri <82394219+AMZN-Igarri@users.noreply.github.com> --- .../UI/Outliner/OutlinerListModel.cpp | 7 ++++--- .../AzToolsFramework/AssetBrowser/Views/EntryDelegate.cpp | 1 + .../AzToolsFramework/Editor/RichTextHighlighter.cpp | 8 +++----- .../AzToolsFramework/Editor/RichTextHighlighter.h | 3 ++- .../UI/Outliner/EntityOutlinerListModel.cpp | 2 ++ 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerListModel.cpp b/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerListModel.cpp index 1c361b050d..39be4839e6 100644 --- a/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerListModel.cpp +++ b/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerListModel.cpp @@ -2599,11 +2599,12 @@ void OutlinerItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optionV4.text.clear(); optionV4.widget->style()->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter); - // Now we setup a Text Document so it can draw the rich text int verticalOffset = GetEntityNameVerticalOffset(entityId); - painter->translate(textRect.topLeft() + QPoint(0, verticalOffset)); - AzToolsFramework::RichTextHighlighter::PaintHighlightedRichText(entityNameRichText, painter, optionV4, textRect); + AzToolsFramework::RichTextHighlighter::PaintHighlightedRichText( + entityNameRichText, painter, optionV4, textRect, QPoint(0, verticalOffset)); + + painter->restore(); OutlinerListModel::s_paintingName = false; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/EntryDelegate.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/EntryDelegate.cpp index 8e69d5f788..5711ca2608 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/EntryDelegate.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/EntryDelegate.cpp @@ -290,6 +290,7 @@ namespace AzToolsFramework { displayString = RichTextHighlighter::HighlightText(displayString, m_assetBrowserFilerModel->GetStringFilter()->GetFilterString()); } + RichTextHighlighter::PaintHighlightedRichText(displayString, painter, optionV4, remainingRect); } } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Editor/RichTextHighlighter.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Editor/RichTextHighlighter.cpp index 8b28298c3d..f22fdd16b4 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Editor/RichTextHighlighter.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Editor/RichTextHighlighter.cpp @@ -29,12 +29,11 @@ namespace AzToolsFramework return highlightedString; } - void RichTextHighlighter::PaintHighlightedRichText(const QString& highlightedString,QPainter* painter, QStyleOptionViewItem option, QRect availableRect) + void RichTextHighlighter::PaintHighlightedRichText(const QString& highlightedString,QPainter* painter, QStyleOptionViewItem option, QRect availableRect, QPoint offset /* = QPoint()*/) { + // Now we setup a Text Document so it can draw the rich text painter->save(); painter->setRenderHint(QPainter::Antialiasing); - - // Now we setup a Text Document so it can draw the rich text QTextDocument textDoc; textDoc.setDefaultFont(option.font); if (option.state & QStyle::State_Enabled) @@ -46,10 +45,9 @@ namespace AzToolsFramework textDoc.setDefaultStyleSheet("body {color: #7C7C7C}"); } textDoc.setHtml("" + highlightedString + ""); - painter->translate(availableRect.topLeft()); + painter->translate(availableRect.topLeft() + offset); textDoc.setTextWidth(availableRect.width()); textDoc.drawContents(painter, QRectF(0, 0, availableRect.width(), availableRect.height())); - painter->restore(); } } // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Editor/RichTextHighlighter.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Editor/RichTextHighlighter.h index b5c1859497..cdcb0b14b3 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Editor/RichTextHighlighter.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Editor/RichTextHighlighter.h @@ -30,7 +30,8 @@ namespace AzToolsFramework RichTextHighlighter() = delete; static QString HighlightText(const QString& displayString, const QString& matchingSubstring); - static void PaintHighlightedRichText(const QString& highlightedString,QPainter* painter, QStyleOptionViewItem option, QRect availableRect); + static void PaintHighlightedRichText(const QString& highlightedString,QPainter* painter, QStyleOptionViewItem option, + QRect availableRect, QPoint offset = QPoint()); }; } // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerListModel.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerListModel.cpp index e0060e2b42..93e4ffd3da 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerListModel.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerListModel.cpp @@ -2368,6 +2368,8 @@ namespace AzToolsFramework AzToolsFramework::RichTextHighlighter::PaintHighlightedRichText(entityNameRichText, painter, optionV4, textRect); + painter->restore(); + EntityOutlinerListModel::s_paintingName = false; } From 9d3f8e0b7dfd81bfc091b072505e615f2f21e8ba Mon Sep 17 00:00:00 2001 From: Scott Romero <24445312+AMZN-ScottR@users.noreply.github.com> Date: Wed, 19 Jan 2022 09:09:32 -0800 Subject: [PATCH 12/17] [development] minor Android toolchain updates (#6931) Fixed issue with Android NDK r23 native only builds where the platform version was ignored Bumped the default ANDROID_NATIVE_API_LEVEL to 24 so it matches the Android project generator scripts Removed some unnecessary information from message strings Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> --- cmake/Platform/Android/Toolchain_android.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/Platform/Android/Toolchain_android.cmake b/cmake/Platform/Android/Toolchain_android.cmake index 75ff4554fd..974eb33681 100644 --- a/cmake/Platform/Android/Toolchain_android.cmake +++ b/cmake/Platform/Android/Toolchain_android.cmake @@ -37,9 +37,9 @@ if(NOT ANDROID_ABI MATCHES "^arm64-") message(FATAL_ERROR "Only the 64-bit ANDROID_ABI's are supported. arm64-v8a can be used if not set") endif() if(NOT ANDROID_NATIVE_API_LEVEL) - set(ANDROID_NATIVE_API_LEVEL 21) + set(ANDROID_NATIVE_API_LEVEL 24) endif() - +set(ANDROID_PLATFORM android-${ANDROID_NATIVE_API_LEVEL}) # Make a backup of the CMAKE_FIND_ROOT_PATH since it will be altered by the NDK toolchain file and needs to be restored after the input set(BACKUP_CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH}) @@ -64,9 +64,9 @@ set(LY_TOOLCHAIN_NDK_API_LEVEL ${ANDROID_PLATFORM_LEVEL}) set(MIN_NDK_VERSION 21) if(${LY_TOOLCHAIN_NDK_PKG_MAJOR} VERSION_LESS ${MIN_NDK_VERSION}) - message(FATAL_ERROR "Unsupported NDK Version ${LY_TOOLCHAIN_NDK_PKG_MAJOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}.${LY_TOOLCHAIN_NDK_API_LEVEL}. Must be version ${MIN_NDK_VERSION} or above") + message(FATAL_ERROR "Unsupported NDK Version ${LY_TOOLCHAIN_NDK_PKG_MAJOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}. Must be version ${MIN_NDK_VERSION} or above") else() - message(STATUS "Detected NDK Version ${LY_TOOLCHAIN_NDK_PKG_MAJOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}") + message(STATUS "Detected NDK Version ${LY_TOOLCHAIN_NDK_PKG_MAJOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}") endif() list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES LY_NDK_DIR) From a63ea12a1f6a47ba6ea27ce2ad847526023b1180 Mon Sep 17 00:00:00 2001 From: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> Date: Wed, 19 Jan 2022 09:52:27 -0800 Subject: [PATCH 13/17] System shortcuts crash the Editor when Global Preferences are open (#6994) * Changes to the keyPressEvent override of the Editor Preferences Dialog to prevent infinite loops on focus switches. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Renaming function to clarify its purpose. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> --- Code/Editor/EditorPreferencesDialog.cpp | 22 ++++++++++++---------- Code/Editor/EditorPreferencesDialog.h | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Code/Editor/EditorPreferencesDialog.cpp b/Code/Editor/EditorPreferencesDialog.cpp index 665daf52a8..42f7446716 100644 --- a/Code/Editor/EditorPreferencesDialog.cpp +++ b/Code/Editor/EditorPreferencesDialog.cpp @@ -112,29 +112,31 @@ void EditorPreferencesDialog::showEvent(QShowEvent* event) QDialog::showEvent(event); } -void WidgetHandleKeyPressEvent(QWidget* widget, QKeyEvent* event) +bool WidgetConsumesKeyPressEvent(QKeyEvent* event) { // If the enter key is pressed during any text input, the dialog box will close // making it inconvenient to do multiple edits. This routine captures the // Key_Enter or Key_Return and clears the focus to give a visible cue that - // editing of that field has finished and then doesn't propogate it. + // editing of that field has finished and then doesn't propagate it. if (event->key() != Qt::Key::Key_Enter && event->key() != Qt::Key::Key_Return) { - QApplication::sendEvent(widget, event); + return false; } - else + + if (QWidget* editWidget = QApplication::focusWidget()) { - if (QWidget* editWidget = QApplication::focusWidget()) - { - editWidget->clearFocus(); - } + editWidget->clearFocus(); } -} + return true; +} void EditorPreferencesDialog::keyPressEvent(QKeyEvent* event) { - WidgetHandleKeyPressEvent(this, event); + if (!WidgetConsumesKeyPressEvent(event)) + { + QDialog::keyPressEvent(event); + } } void EditorPreferencesDialog::OnTreeCurrentItemChanged() diff --git a/Code/Editor/EditorPreferencesDialog.h b/Code/Editor/EditorPreferencesDialog.h index a3f05ad00d..70a186375b 100644 --- a/Code/Editor/EditorPreferencesDialog.h +++ b/Code/Editor/EditorPreferencesDialog.h @@ -19,7 +19,7 @@ namespace Ui class EditorPreferencesTreeWidgetItem; -void WidgetHandleKeyPressEvent(QWidget* widget, QKeyEvent* event); +bool WidgetConsumesKeyPressEvent(QKeyEvent* event); class EditorPreferencesDialog : public QDialog From ca56770655b0f79b7d3e1f6322def650549feb05 Mon Sep 17 00:00:00 2001 From: Junbo Liang <68558268+junbo75@users.noreply.github.com> Date: Wed, 19 Jan 2022 10:50:56 -0800 Subject: [PATCH 14/17] [AWSMetrics] Update the auto-generated code to follow O3DE coding standard (#6910) * [AWSMetrics] Update the auto-generated code to follow O3DE coding standard Signed-off-by: Junbo Liang <68558268+junbo75@users.noreply.github.com> --- .../Code/Source/AWSMetricsConstant.h | 18 ++--- .../Code/Source/AWSMetricsServiceApi.cpp | 65 ++++++++++++------- .../Code/Source/AWSMetricsServiceApi.h | 44 +++++++------ .../AWSMetrics/Code/Source/MetricsManager.cpp | 26 ++++---- Gems/AWSMetrics/Code/Source/MetricsManager.h | 5 +- .../Code/Tests/AWSMetricsServiceApiTest.cpp | 48 +++++++------- .../Code/Tests/MetricsManagerTest.cpp | 16 ++--- Gems/AWSMetrics/cdk/api_spec.json | 26 ++++---- 8 files changed, 136 insertions(+), 112 deletions(-) diff --git a/Gems/AWSMetrics/Code/Source/AWSMetricsConstant.h b/Gems/AWSMetrics/Code/Source/AWSMetricsConstant.h index ecb2b5dcfa..8779b66355 100644 --- a/Gems/AWSMetrics/Code/Source/AWSMetricsConstant.h +++ b/Gems/AWSMetrics/Code/Source/AWSMetricsConstant.h @@ -21,16 +21,16 @@ namespace AWSMetrics static constexpr char AwsMetricsAttributeKeyEventData[] = "event_data"; //! Service API request and response object keys - static constexpr char AwsMetricsSuccessResponseRecordKeyErrorCode[] = "error_code"; - static constexpr char AwsMetricsSuccessResponseRecordKeyResult[] = "result"; - static constexpr char AwsMetricsSuccessResponseKeyFailedRecordCount[] = "failed_record_count"; - static constexpr char AwsMetricsSuccessResponseKeyEvents[] = "events"; - static constexpr char AwsMetricsSuccessResponseKeyTotal[] = "total"; - static constexpr char AwsMetricsErrorKeyMessage[] = "message"; - static constexpr char AwsMetricsErrorKeyType[] = "type"; - static constexpr char AwsMetricsRequestParameterKeyEvents[] = "events"; + static constexpr char AwsMetricsPostMetricsEventsResponseEntryKeyErrorCode[] = "error_code"; + static constexpr char AwsMetricsPostMetricsEventsResponseEntryKeyResult[] = "result"; + static constexpr char AwsMetricsPostMetricsEventsResponseKeyFailedRecordCount[] = "failed_record_count"; + static constexpr char AwsMetricsPostMetricsEventsResponseKeyEvents[] = "events"; + static constexpr char AwsMetricsPostMetricsEventsResponseKeyTotal[] = "total"; + static constexpr char AwsMetricsPostMetricsEventsErrorKeyMessage[] = "message"; + static constexpr char AwsMetricsPostMetricsEventsErrorKeyType[] = "type"; + static constexpr char AwsMetricsPostMetricsEventsRequestParameterKeyEvents[] = "events"; - static constexpr char AwsMetricsSuccessResponseRecordResult[] = "Ok"; + static constexpr char AwsMetricsPostMetricsEventsResponseEntrySuccessResult[] = "Ok"; //! Service API limits //! https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html diff --git a/Gems/AWSMetrics/Code/Source/AWSMetricsServiceApi.cpp b/Gems/AWSMetrics/Code/Source/AWSMetricsServiceApi.cpp index 7e568e0c40..b7e9d7a1a9 100644 --- a/Gems/AWSMetrics/Code/Source/AWSMetricsServiceApi.cpp +++ b/Gems/AWSMetrics/Code/Source/AWSMetricsServiceApi.cpp @@ -15,56 +15,77 @@ namespace AWSMetrics { namespace ServiceAPI { - bool MetricsEventSuccessResponseRecord::OnJsonKey(const char* key, AWSCore::JsonReader& reader) + bool PostMetricsEventsResponseEntry::OnJsonKey(const char* key, AWSCore::JsonReader& reader) { - if (strcmp(key, AwsMetricsSuccessResponseRecordKeyErrorCode) == 0) return reader.Accept(errorCode); + if (strcmp(key, AwsMetricsPostMetricsEventsResponseEntryKeyErrorCode) == 0) + { + return reader.Accept(m_errorCode); + } - if (strcmp(key, AwsMetricsSuccessResponseRecordKeyResult) == 0) return reader.Accept(result); + if (strcmp(key, AwsMetricsPostMetricsEventsResponseEntryKeyResult) == 0) + { + return reader.Accept(m_result); + } return reader.Ignore(); } - bool MetricsEventSuccessResponse::OnJsonKey(const char* key, AWSCore::JsonReader& reader) + bool PostMetricsEventsResponse::OnJsonKey(const char* key, AWSCore::JsonReader& reader) { - if (strcmp(key, AwsMetricsSuccessResponseKeyFailedRecordCount) == 0) return reader.Accept(failedRecordCount); + if (strcmp(key, AwsMetricsPostMetricsEventsResponseKeyFailedRecordCount) == 0) + { + return reader.Accept(m_failedRecordCount); + } - if (strcmp(key, AwsMetricsSuccessResponseKeyEvents) == 0) return reader.Accept(events); + if (strcmp(key, AwsMetricsPostMetricsEventsResponseKeyEvents) == 0) + { + return reader.Accept(m_responseEntries); + } - if (strcmp(key, AwsMetricsSuccessResponseKeyTotal) == 0) return reader.Accept(total); + if (strcmp(key, AwsMetricsPostMetricsEventsResponseKeyTotal) == 0) + { + return reader.Accept(m_total); + } return reader.Ignore(); } - bool Error::OnJsonKey(const char* key, AWSCore::JsonReader& reader) + bool PostMetricsEventsError::OnJsonKey(const char* key, AWSCore::JsonReader& reader) { - if (strcmp(key, AwsMetricsErrorKeyMessage) == 0) return reader.Accept(message); + if (strcmp(key, AwsMetricsPostMetricsEventsErrorKeyMessage) == 0) + { + return reader.Accept(message); + } - if (strcmp(key, AwsMetricsErrorKeyType) == 0) return reader.Accept(type); + if (strcmp(key, AwsMetricsPostMetricsEventsErrorKeyType) == 0) + { + return reader.Accept(type); + } return reader.Ignore(); } - // Generated Function Parameters - bool PostProducerEventsRequest::Parameters::BuildRequest(AWSCore::RequestBuilder& request) + // Generated request parameters + bool PostMetricsEventsRequest::Parameters::BuildRequest(AWSCore::RequestBuilder& request) { - bool ok = true; + bool buildResult = true; + buildResult = buildResult && request.WriteJsonBodyParameter(*this); - ok = ok && request.WriteJsonBodyParameter(*this); - return ok; + return buildResult; } - bool PostProducerEventsRequest::Parameters::WriteJson(AWSCore::JsonWriter& writer) const + bool PostMetricsEventsRequest::Parameters::WriteJson(AWSCore::JsonWriter& writer) const { - bool ok = true; + bool writeResult = true; - ok = ok && writer.StartObject(); + writeResult = writeResult && writer.StartObject(); - ok = ok && writer.Key(AwsMetricsRequestParameterKeyEvents); - ok = ok && data.SerializeToJson(writer); + writeResult = writeResult && writer.Key(AwsMetricsPostMetricsEventsRequestParameterKeyEvents); + writeResult = writeResult && m_metricsQueue.SerializeToJson(writer); - ok = ok && writer.EndObject(); + writeResult = writeResult && writer.EndObject(); - return ok; + return writeResult; } } } diff --git a/Gems/AWSMetrics/Code/Source/AWSMetricsServiceApi.h b/Gems/AWSMetrics/Code/Source/AWSMetricsServiceApi.h index a64c9f8a53..dde36fc04a 100644 --- a/Gems/AWSMetrics/Code/Source/AWSMetricsServiceApi.h +++ b/Gems/AWSMetrics/Code/Source/AWSMetricsServiceApi.h @@ -16,41 +16,44 @@ namespace AWSMetrics { namespace ServiceAPI { - //! Struct for storing event record from the response. - struct MetricsEventSuccessResponseRecord + //! Response for an individual metrics event from a PostMetricsEvents request. + //! If the event is successfully sent to the backend, it receives an "Ok" result. + //! If the event fails to be sent to the backend, the result includes an error code and an "Error" result. + struct PostMetricsEventsResponseEntry { - //! Identify the expected property type and provide a location where the property value can be stored. + //! Identify the expected property type in the response entry for each individual metrics event and provide a location where the property value can be stored. //! @param key Name of the property. //! @param reader JSON reader to read the property. bool OnJsonKey(const char* key, AWSCore::JsonReader& reader); - AZStd::string errorCode; //!< Error code if the event is not sent successfully. - AZStd::string result; //!< Processing result for the input record. + AZStd::string m_errorCode; //!< Error code if the individual metrics event failed to be sent. + AZStd::string m_result; //!< Result for the processed individual metrics event. Expected value: "Error" or "Ok". }; - using MetricsEventSuccessResponsePropertyEvents = AZStd::vector; + using PostMetricsEventsResponseEntries = AZStd::vector; - //! Struct for storing the success response. - struct MetricsEventSuccessResponse + //! Response for all the processed metrics events from a PostMetricsEvents request. + struct PostMetricsEventsResponse { - //! Identify the expected property type and provide a location where the property value can be stored. + //! Identify the expected property type in the response and provide a location where the property value can be stored. //! @param key Name of the property. //! @param reader JSON reader to read the property. bool OnJsonKey(const char* key, AWSCore::JsonReader& reader); - int failedRecordCount{ 0 }; //!< Number of events that failed to be saved to metrics events stream. - MetricsEventSuccessResponsePropertyEvents events; //! List of input event records. - int total{ 0 }; //!< Total number of events that were processed in the request + int m_failedRecordCount{ 0 }; //!< Number of events that failed to be sent to the backend. + PostMetricsEventsResponseEntries m_responseEntries; //! Response list for all the processed metrics events. + int m_total{ 0 }; //!< Total number of events that were processed in the request. }; - //! Struct for storing the failure response. - struct Error + //! Failure response for sending the PostMetricsEvents request. + struct PostMetricsEventsError { - //! Identify the expected property type and provide a location where the property value can be stored. + //! Identify the expected property type in the failure response and provide a location where the property value can be stored. //! @param key Name of the property. //! @param reader JSON reader to read the property. bool OnJsonKey(const char* key, AWSCore::JsonReader& reader); + //! Do not rename the following members since they are expected by the AWSCore dependency. AZStd::string message; //!< Error message. AZStd::string type; //!< Error type. }; @@ -60,7 +63,7 @@ namespace AWSMetrics //! POST request defined by api_spec.json to send metrics to the backend. //! The path for this service API is "/producer/events". - class PostProducerEventsRequest + class PostMetricsEventsRequest : public AWSCore::ServiceRequest { public: @@ -79,14 +82,15 @@ namespace AWSMetrics //! @return Whether the serialization is successful. bool WriteJson(AWSCore::JsonWriter& writer) const; - MetricsQueue data; //!< Data to send via the service API request. + MetricsQueue m_metricsQueue; //!< Metrics events to send via the service API request. }; - MetricsEventSuccessResponse result; //! Success response. - Error error; //! Failure response. + //! Do not rename the following members since they are expected by the AWSCore dependency. + PostMetricsEventsResponse result; //! Success response. + PostMetricsEventsError error; //! Failure response. Parameters parameters; //! Request parameter. }; - using PostProducerEventsRequestJob = AWSCore::ServiceRequestJob; + using PostMetricsEventsRequestJob = AWSCore::ServiceRequestJob; } // ServiceAPI } // AWSMetrics diff --git a/Gems/AWSMetrics/Code/Source/MetricsManager.cpp b/Gems/AWSMetrics/Code/Source/MetricsManager.cpp index 03e31770ee..d484b8c169 100644 --- a/Gems/AWSMetrics/Code/Source/MetricsManager.cpp +++ b/Gems/AWSMetrics/Code/Source/MetricsManager.cpp @@ -172,17 +172,17 @@ namespace AWSMetrics if (outcome.IsSuccess()) { // Generate response records for success call to keep consistency with the Service API response - ServiceAPI::MetricsEventSuccessResponsePropertyEvents responseRecords; + ServiceAPI::PostMetricsEventsResponseEntries responseEntries; int numMetricsEventsInRequest = metricsQueue->GetNumMetrics(); for (int index = 0; index < numMetricsEventsInRequest; ++index) { - ServiceAPI::MetricsEventSuccessResponseRecord responseRecord; - responseRecord.result = AwsMetricsSuccessResponseRecordResult; + ServiceAPI::PostMetricsEventsResponseEntry responseEntry; + responseEntry.m_result = AwsMetricsPostMetricsEventsResponseEntrySuccessResult; - responseRecords.emplace_back(responseRecord); + responseEntries.emplace_back(responseEntry); } - OnResponseReceived(*metricsQueue, responseRecords); + OnResponseReceived(*metricsQueue, responseEntries); AZ::TickBus::QueueFunction([requestId]() { @@ -209,19 +209,19 @@ namespace AWSMetrics { int requestId = ++m_sendMetricsId; - ServiceAPI::PostProducerEventsRequestJob* requestJob = ServiceAPI::PostProducerEventsRequestJob::Create( - [this, requestId](ServiceAPI::PostProducerEventsRequestJob* successJob) + ServiceAPI::PostMetricsEventsRequestJob* requestJob = ServiceAPI::PostMetricsEventsRequestJob::Create( + [this, requestId](ServiceAPI::PostMetricsEventsRequestJob* successJob) { - OnResponseReceived(successJob->parameters.data, successJob->result.events); + OnResponseReceived(successJob->parameters.m_metricsQueue, successJob->result.m_responseEntries); AZ::TickBus::QueueFunction([requestId]() { AWSMetricsNotificationBus::Broadcast(&AWSMetricsNotifications::OnSendMetricsSuccess, requestId); }); }, - [this, requestId](ServiceAPI::PostProducerEventsRequestJob* failedJob) + [this, requestId](ServiceAPI::PostMetricsEventsRequestJob* failedJob) { - OnResponseReceived(failedJob->parameters.data); + OnResponseReceived(failedJob->parameters.m_metricsQueue); AZStd::string errorMessage = failedJob->error.message; AZ::TickBus::QueueFunction([requestId, errorMessage]() @@ -230,11 +230,11 @@ namespace AWSMetrics }); }); - requestJob->parameters.data = AZStd::move(metricsQueue); + requestJob->parameters.m_metricsQueue = AZStd::move(metricsQueue); requestJob->Start(); } - void MetricsManager::OnResponseReceived(const MetricsQueue& metricsEventsInRequest, const ServiceAPI::MetricsEventSuccessResponsePropertyEvents& responseRecords) + void MetricsManager::OnResponseReceived(const MetricsQueue& metricsEventsInRequest, const ServiceAPI::PostMetricsEventsResponseEntries& responseEntries) { MetricsQueue metricsEventsForRetry; int numMetricsEventsInRequest = metricsEventsInRequest.GetNumMetrics(); @@ -242,7 +242,7 @@ namespace AWSMetrics { MetricsEvent metricsEvent = metricsEventsInRequest[index]; - if (responseRecords.size() > 0 && responseRecords[index].result == AwsMetricsSuccessResponseRecordResult) + if (responseEntries.size() > 0 && responseEntries[index].m_result == AwsMetricsPostMetricsEventsResponseEntrySuccessResult) { // The metrics event is sent to the backend successfully. if (metricsEvent.GetNumFailures() == 0) diff --git a/Gems/AWSMetrics/Code/Source/MetricsManager.h b/Gems/AWSMetrics/Code/Source/MetricsManager.h index 3bb06acd75..63a614ae67 100644 --- a/Gems/AWSMetrics/Code/Source/MetricsManager.h +++ b/Gems/AWSMetrics/Code/Source/MetricsManager.h @@ -60,9 +60,8 @@ namespace AWSMetrics //! Update the global stats and add qualified failed metrics events back to the buffer for retry. //! @param metricsEventsInRequest Metrics events in the original request. - //! @param responseRecords Response records from the call. Each record in the list contains the result for sending the corresponding metrics event. - void OnResponseReceived(const MetricsQueue& metricsEventsInRequest, const ServiceAPI::MetricsEventSuccessResponsePropertyEvents& responseRecords = - ServiceAPI::MetricsEventSuccessResponsePropertyEvents()); + //! @param responseEntries Response list for all the processed metrics events. + void OnResponseReceived(const MetricsQueue& metricsEventsInRequest, const ServiceAPI::PostMetricsEventsResponseEntries& responseEntries = ServiceAPI::PostMetricsEventsResponseEntries()); //! Implementation for flush all metrics buffered in memory. void FlushMetricsAsync(); diff --git a/Gems/AWSMetrics/Code/Tests/AWSMetricsServiceApiTest.cpp b/Gems/AWSMetrics/Code/Tests/AWSMetricsServiceApiTest.cpp index b7e7527b20..2b7f92601b 100644 --- a/Gems/AWSMetrics/Code/Tests/AWSMetricsServiceApiTest.cpp +++ b/Gems/AWSMetrics/Code/Tests/AWSMetricsServiceApiTest.cpp @@ -42,43 +42,43 @@ namespace AWSMetrics TEST_F(AWSMetricsServiceApiTest, OnJsonKey_MetricsEventSuccessResponseRecord_AcceptValidKeys) { - ServiceAPI::MetricsEventSuccessResponseRecord responseRecord; - responseRecord.result = "ok"; + ServiceAPI::PostMetricsEventsResponseEntry responseRecord; + responseRecord.m_result = "ok"; - EXPECT_CALL(JsonReader, Accept(responseRecord.result)).Times(1); - EXPECT_CALL(JsonReader, Accept(responseRecord.errorCode)).Times(1); + EXPECT_CALL(JsonReader, Accept(responseRecord.m_result)).Times(1); + EXPECT_CALL(JsonReader, Accept(responseRecord.m_errorCode)).Times(1); EXPECT_CALL(JsonReader, Ignore()).Times(1); - responseRecord.OnJsonKey(AwsMetricsSuccessResponseRecordKeyResult, JsonReader); - responseRecord.OnJsonKey(AwsMetricsSuccessResponseRecordKeyErrorCode, JsonReader); + responseRecord.OnJsonKey(AwsMetricsPostMetricsEventsResponseEntryKeyResult, JsonReader); + responseRecord.OnJsonKey(AwsMetricsPostMetricsEventsResponseEntryKeyErrorCode, JsonReader); responseRecord.OnJsonKey("other", JsonReader); } TEST_F(AWSMetricsServiceApiTest, OnJsonKeyWithEvents_MetricsEventSuccessResponseRecord_AcceptValidKeys) { // Verifiy that JsonReader accepts valid JSON keys in each event record from a success reponse - ServiceAPI::MetricsEventSuccessResponseRecord responseRecord; - responseRecord.result = "ok"; + ServiceAPI::PostMetricsEventsResponseEntry responseRecord; + responseRecord.m_result = "Ok"; - ServiceAPI::MetricsEventSuccessResponse response; - response.events.emplace_back(responseRecord); - response.failedRecordCount = 0; - response.total = 1; + ServiceAPI::PostMetricsEventsResponse response; + response.m_responseEntries.emplace_back(responseRecord); + response.m_failedRecordCount = 0; + response.m_total = 1; - EXPECT_CALL(JsonReader, Accept(response.failedRecordCount)).Times(1); - EXPECT_CALL(JsonReader, Accept(response.total)).Times(1); + EXPECT_CALL(JsonReader, Accept(response.m_failedRecordCount)).Times(1); + EXPECT_CALL(JsonReader, Accept(response.m_total)).Times(1); EXPECT_CALL(JsonReader, Accept(::testing::An())).Times(1); EXPECT_CALL(JsonReader, Ignore()).Times(1); - response.OnJsonKey(AwsMetricsSuccessResponseKeyFailedRecordCount, JsonReader); - response.OnJsonKey(AwsMetricsSuccessResponseKeyTotal, JsonReader); - response.OnJsonKey(AwsMetricsSuccessResponseKeyEvents, JsonReader); + response.OnJsonKey(AwsMetricsPostMetricsEventsResponseKeyFailedRecordCount, JsonReader); + response.OnJsonKey(AwsMetricsPostMetricsEventsResponseKeyTotal, JsonReader); + response.OnJsonKey(AwsMetricsPostMetricsEventsResponseKeyEvents, JsonReader); response.OnJsonKey("other", JsonReader); } TEST_F(AWSMetricsServiceApiTest, OnJsonKey_Error_AcceptValidKeys) { - ServiceAPI::Error error; + ServiceAPI::PostMetricsEventsError error; error.message = "error message"; error.type = "404"; @@ -86,16 +86,16 @@ namespace AWSMetrics EXPECT_CALL(JsonReader, Accept(error.type)).Times(1); EXPECT_CALL(JsonReader, Ignore()).Times(1); - error.OnJsonKey(AwsMetricsErrorKeyMessage, JsonReader); - error.OnJsonKey(AwsMetricsErrorKeyType, JsonReader); + error.OnJsonKey(AwsMetricsPostMetricsEventsErrorKeyMessage, JsonReader); + error.OnJsonKey(AwsMetricsPostMetricsEventsErrorKeyType, JsonReader); error.OnJsonKey("other", JsonReader); } TEST_F(AWSMetricsServiceApiTest, BuildRequestBody_PostProducerEventsRequest_SerializedMetricsQueue) { - ServiceAPI::PostProducerEventsRequest request; - request.parameters.data = MetricsQueue(); - request.parameters.data.AddMetrics(MetricsEventBuilder().Build()); + ServiceAPI::PostMetricsEventsRequest request; + request.parameters.m_metricsQueue = MetricsQueue(); + request.parameters.m_metricsQueue.AddMetrics(MetricsEventBuilder().Build()); AWSCore::RequestBuilder requestBuilder{}; EXPECT_TRUE(request.parameters.BuildRequest(requestBuilder)); @@ -104,6 +104,6 @@ namespace AWSMetrics std::istreambuf_iterator eos; AZStd::string bodyString{ std::istreambuf_iterator(*bodyContent), eos }; - EXPECT_TRUE(bodyString.contains(AZStd::string::format("{\"%s\":[{\"event_timestamp\":", AwsMetricsRequestParameterKeyEvents))); + EXPECT_TRUE(bodyString.contains(AZStd::string::format("{\"%s\":[{\"event_timestamp\":", AwsMetricsPostMetricsEventsRequestParameterKeyEvents))); } } diff --git a/Gems/AWSMetrics/Code/Tests/MetricsManagerTest.cpp b/Gems/AWSMetrics/Code/Tests/MetricsManagerTest.cpp index 9fcebec524..154e88f90e 100644 --- a/Gems/AWSMetrics/Code/Tests/MetricsManagerTest.cpp +++ b/Gems/AWSMetrics/Code/Tests/MetricsManagerTest.cpp @@ -430,14 +430,14 @@ namespace AWSMetrics ReplaceLocalFileIOWithMockIO(); } - TEST_F(MetricsManagerTest, OnResponseReceived_WithResponseRecords_RetryFailedMetrics) + TEST_F(MetricsManagerTest, OnResponseReceived_WithResponseEntries_RetryFailedMetrics) { // Reset the config file to change the max queue size setting. ResetClientConfig(false, (double)TestMetricsEventSizeInBytes * (MaxNumMetricsEvents + 1) / MbToBytes, DefaultFlushPeriodInSeconds, 1); MetricsQueue metricsEvents; - ServiceAPI::MetricsEventSuccessResponsePropertyEvents responseRecords; + ServiceAPI::PostMetricsEventsResponseEntries responseEntries; for (int index = 0; index < MaxNumMetricsEvents; ++index) { MetricsEvent newEvent; @@ -445,19 +445,19 @@ namespace AWSMetrics metricsEvents.AddMetrics(newEvent); - ServiceAPI::MetricsEventSuccessResponseRecord responseRecord; + ServiceAPI::PostMetricsEventsResponseEntry responseEntry; if (index % 2 == 0) { - responseRecord.errorCode = "Error"; + responseEntry.m_errorCode = "Error"; } else { - responseRecord.result = "Ok"; + responseEntry.m_result = "Ok"; } - responseRecords.emplace_back(responseRecord); + responseEntries.emplace_back(responseEntry); } - m_metricsManager->OnResponseReceived(metricsEvents, responseRecords); + m_metricsManager->OnResponseReceived(metricsEvents, responseEntries); const GlobalStatistics& stats = m_metricsManager->GetGlobalStatistics(); EXPECT_EQ(stats.m_numEvents, MaxNumMetricsEvents); @@ -471,7 +471,7 @@ namespace AWSMetrics ASSERT_EQ(m_metricsManager->GetNumBufferedMetrics(), MaxNumMetricsEvents / 2); } - TEST_F(MetricsManagerTest, OnResponseReceived_NoResponseRecords_RetryAllMetrics) + TEST_F(MetricsManagerTest, OnResponseReceived_NoResponseEntries_RetryAllMetrics) { // Reset the config file to change the max queue size setting. ResetClientConfig(false, (double)TestMetricsEventSizeInBytes * (MaxNumMetricsEvents + 1) / MbToBytes, diff --git a/Gems/AWSMetrics/cdk/api_spec.json b/Gems/AWSMetrics/cdk/api_spec.json index 74a19ba460..0daf629516 100644 --- a/Gems/AWSMetrics/cdk/api_spec.json +++ b/Gems/AWSMetrics/cdk/api_spec.json @@ -3,7 +3,7 @@ "info": { "title": "AWSMetricsServiceApi", "description": "Service API for the data analytics pipeline defined by the AWS Metrics Gem", - "version": "1.0.0" + "version": "1.0.1" }, "x-amazon-apigateway-request-validators": { "all": { @@ -68,7 +68,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/MetricsEventSuccessResponse" + "$ref": "#/components/schemas/PostMetricsEventsResponse" } } } @@ -78,7 +78,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Error" + "$ref": "#/components/schemas/PostMetricsEventsError" } } } @@ -88,17 +88,17 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Error" + "$ref": "#/components/schemas/PostMetricsEventsError" } } } }, "500": { - "description": "Internal Server Error", + "description": "Internal Server PostMetricsEventsError", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Error" + "$ref": "#/components/schemas/PostMetricsEventsError" } } } @@ -109,7 +109,7 @@ }, "components": { "schemas": { - "Error": { + "PostMetricsEventsError": { "type": "object", "properties": { "message": { @@ -184,18 +184,18 @@ } } }, - "MetricsEventSuccessResponse": { + "PostMetricsEventsResponse": { "title": "Metrics Event Success Response Schema", "type": "object", "properties": { "failed_record_count": { "type": "number", - "description": "Number of events that failed to be saved to metrics events stream" + "description": "Number of events that failed to be sent to the backend" }, "events": { "type": "array", "items": { - "$ref": "#/components/schemas/MetricsEventSuccessResponseRecord" + "$ref": "#/components/schemas/PostMetricsEventsResponseEntry" } }, "total": { @@ -204,16 +204,16 @@ } } }, - "MetricsEventSuccessResponseRecord": { + "PostMetricsEventsResponseEntry": { "type": "object", "properties": { "error_code": { "type": "string", - "description": "The error code from the metrics events stream. Value set if Result is Error" + "description": "Error code if the individual metrics event failed to be sent" }, "result": { "type": "string", - "description": "Processing result for the input record" + "description": "Result for the processed individual metrics event. Expected value: \"Error\" or \"Ok\"" } } } From 83878e63775ccb3bdad0cad49a9ae973e1d48596 Mon Sep 17 00:00:00 2001 From: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> Date: Wed, 19 Jan 2022 12:57:52 -0600 Subject: [PATCH 15/17] Change GetValues() to take in const positions. (#6987) * Change GetValues() to take in const positions. To support this, span needed some template deductions to correctly convert from non-const containers to const ones. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * Removed the most problematic template deduction rules. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * Remove duplicate validate_iterator methods. iterator type is a pointer, not a value, so "const iterator" and "const const_iterator" produce the same function signature. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * Fixed the span types. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> --- .../AzCore/AzCore/std/containers/span.h | 36 +++++++----------- .../AzCore/AzCore/std/containers/span.inl | 38 +++---------------- .../AzCore/AzCore/std/containers/vector.h | 20 ---------- .../Components/ConstantGradientComponent.h | 2 +- .../Components/DitherGradientComponent.h | 2 +- .../Components/ImageGradientComponent.h | 2 +- .../Components/InvertGradientComponent.h | 2 +- .../Components/LevelsGradientComponent.h | 2 +- .../Components/MixedGradientComponent.h | 2 +- .../Components/PerlinGradientComponent.h | 2 +- .../Components/PosterizeGradientComponent.h | 2 +- .../Components/RandomGradientComponent.h | 2 +- .../Components/ReferenceGradientComponent.h | 2 +- .../ShapeAreaFalloffGradientComponent.h | 2 +- .../Components/SmoothStepGradientComponent.h | 2 +- .../SurfaceAltitudeGradientComponent.h | 2 +- .../Components/SurfaceMaskGradientComponent.h | 2 +- .../SurfaceSlopeGradientComponent.h | 2 +- .../Components/ThresholdGradientComponent.h | 2 +- .../Ebuses/GradientRequestBus.h | 2 +- .../Include/GradientSignal/GradientSampler.h | 4 +- .../Components/ConstantGradientComponent.cpp | 2 +- .../Components/DitherGradientComponent.cpp | 2 +- .../Components/ImageGradientComponent.cpp | 2 +- .../Components/InvertGradientComponent.cpp | 2 +- .../Components/LevelsGradientComponent.cpp | 2 +- .../Components/MixedGradientComponent.cpp | 2 +- .../Components/PerlinGradientComponent.cpp | 2 +- .../Components/PosterizeGradientComponent.cpp | 2 +- .../Components/RandomGradientComponent.cpp | 2 +- .../Components/ReferenceGradientComponent.cpp | 2 +- .../ShapeAreaFalloffGradientComponent.cpp | 2 +- .../SmoothStepGradientComponent.cpp | 2 +- .../SurfaceAltitudeGradientComponent.cpp | 2 +- .../SurfaceMaskGradientComponent.cpp | 2 +- .../SurfaceSlopeGradientComponent.cpp | 2 +- .../Components/ThresholdGradientComponent.cpp | 2 +- 37 files changed, 55 insertions(+), 109 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/std/containers/span.h b/Code/Framework/AzCore/AzCore/std/containers/span.h index 5bb51bf481..fbf5f56870 100644 --- a/Code/Framework/AzCore/AzCore/std/containers/span.h +++ b/Code/Framework/AzCore/AzCore/std/containers/span.h @@ -33,23 +33,24 @@ namespace AZStd * * Since the span does not copy and store any data, it is only valid as long as the data used to create it is valid. */ - template + template class span final { public: - using value_type = Element; + using element_type = T; + using value_type = AZStd::remove_cv_t; - using pointer = value_type*; - using const_pointer = const value_type*; + using pointer = T*; + using const_pointer = const T*; - using reference = value_type&; - using const_reference = const value_type&; + using reference = T&; + using const_reference = const T&; using size_type = AZStd::size_t; using difference_type = AZStd::ptrdiff_t; - using iterator = value_type*; - using const_iterator = const value_type*; + using iterator = T*; + using const_iterator = const T*; using reverse_iterator = AZStd::reverse_iterator; using const_reverse_iterator = AZStd::reverse_iterator; @@ -65,21 +66,11 @@ namespace AZStd // create a span to just the first element instead of an entire array. constexpr span(const_pointer s) = delete; - template - constexpr span(AZStd::array& data); + template + constexpr span(Container& data); - constexpr span(AZStd::vector& data); - - template - constexpr span(AZStd::fixed_vector& data); - - template - constexpr span(const AZStd::array& data); - - constexpr span(const AZStd::vector& data); - - template - constexpr span(const AZStd::fixed_vector& data); + template + constexpr span(const Container& data); constexpr span(const span&) = default; @@ -132,6 +123,7 @@ namespace AZStd pointer m_begin; pointer m_end; }; + } // namespace AZStd #include diff --git a/Code/Framework/AzCore/AzCore/std/containers/span.inl b/Code/Framework/AzCore/AzCore/std/containers/span.inl index 01bab9a5a4..2b24a11fc3 100644 --- a/Code/Framework/AzCore/AzCore/std/containers/span.inl +++ b/Code/Framework/AzCore/AzCore/std/containers/span.inl @@ -29,42 +29,16 @@ namespace AZStd , m_end(last) { } - template - template - inline constexpr span::span(AZStd::array& data) - : m_begin(data.data()) - , m_end(m_begin + data.size()) - { } - - template - inline constexpr span::span(AZStd::vector& data) - : m_begin(data.data()) - , m_end(m_begin + data.size()) - { } - - template - template - inline constexpr span::span(AZStd::fixed_vector& data) + template + template + inline constexpr span::span(Container& data) : m_begin(data.data()) , m_end(m_begin + data.size()) { } - template - template - inline constexpr span::span(const AZStd::array& data) - : m_begin(data.data()) - , m_end(m_begin + data.size()) - { } - - template - inline constexpr span::span(const AZStd::vector& data) - : m_begin(data.data()) - , m_end(m_begin + data.size()) - { } - - template - template - inline constexpr span::span(const AZStd::fixed_vector& data) + template + template + inline constexpr span::span(const Container& data) : m_begin(data.data()) , m_end(m_begin + data.size()) { } diff --git a/Code/Framework/AzCore/AzCore/std/containers/vector.h b/Code/Framework/AzCore/AzCore/std/containers/vector.h index 255e1c4de4..cd25450777 100644 --- a/Code/Framework/AzCore/AzCore/std/containers/vector.h +++ b/Code/Framework/AzCore/AzCore/std/containers/vector.h @@ -954,25 +954,6 @@ namespace AZStd return true; } /// Validates an iter iterator. Returns a combination of \ref iterator_status_flag. - AZ_FORCE_INLINE int validate_iterator(const iterator& iter) const - { -#ifdef AZSTD_HAS_CHECKED_ITERATORS - AZ_Assert(iter.m_container == this, "Iterator doesn't belong to this container"); - pointer iterPtr = iter.m_iter; -#else - pointer iterPtr = iter; -#endif - if (iterPtr < m_start || iterPtr > m_last) - { - return isf_none; - } - else if (iterPtr == m_last) - { - return isf_valid; - } - - return isf_valid | isf_can_dereference; - } AZ_FORCE_INLINE int validate_iterator(const const_iterator& iter) const { #ifdef AZSTD_HAS_CHECKED_ITERATORS @@ -992,7 +973,6 @@ namespace AZStd return isf_valid | isf_can_dereference; } - AZ_FORCE_INLINE int validate_iterator(const reverse_iterator& iter) const { return validate_iterator(iter.base()); } AZ_FORCE_INLINE int validate_iterator(const const_reverse_iterator& iter) const { return validate_iterator(iter.base()); } /** diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/ConstantGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/ConstantGradientComponent.h index 1ed06a976a..ff81206225 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/ConstantGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/ConstantGradientComponent.h @@ -62,7 +62,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; protected: ////////////////////////////////////////////////////////////////////////// diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/DitherGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/DitherGradientComponent.h index add6de06cf..ff863115af 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/DitherGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/DitherGradientComponent.h @@ -77,7 +77,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; bool IsEntityInHierarchy(const AZ::EntityId& entityId) const override; ////////////////////////////////////////////////////////////////////////// diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/ImageGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/ImageGradientComponent.h index 79d42ec478..044e9d91b1 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/ImageGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/ImageGradientComponent.h @@ -69,7 +69,7 @@ namespace GradientSignal // GradientRequestBus overrides... float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; // AZ::Data::AssetBus overrides... void OnAssetReady(AZ::Data::Asset asset) override; diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/InvertGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/InvertGradientComponent.h index a370286b0b..e4c1faa5d0 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/InvertGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/InvertGradientComponent.h @@ -64,7 +64,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; bool IsEntityInHierarchy(const AZ::EntityId& entityId) const override; protected: diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/LevelsGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/LevelsGradientComponent.h index 093f84ef3a..eee777045f 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/LevelsGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/LevelsGradientComponent.h @@ -69,7 +69,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; bool IsEntityInHierarchy(const AZ::EntityId& entityId) const override; protected: diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/MixedGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/MixedGradientComponent.h index 658118fca4..27e7d238a7 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/MixedGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/MixedGradientComponent.h @@ -99,7 +99,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; bool IsEntityInHierarchy(const AZ::EntityId& entityId) const override; protected: diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/PerlinGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/PerlinGradientComponent.h index 19f3fe7294..d1f35220ed 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/PerlinGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/PerlinGradientComponent.h @@ -70,7 +70,7 @@ namespace GradientSignal // GradientRequestBus overrides... float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; private: PerlinGradientConfig m_configuration; diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/PosterizeGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/PosterizeGradientComponent.h index bff49ac619..55ea37868b 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/PosterizeGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/PosterizeGradientComponent.h @@ -73,7 +73,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; bool IsEntityInHierarchy(const AZ::EntityId& entityId) const override; protected: diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/RandomGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/RandomGradientComponent.h index 328fed5118..ffd532e024 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/RandomGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/RandomGradientComponent.h @@ -61,7 +61,7 @@ namespace GradientSignal // GradientRequestBus overrides... float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; private: RandomGradientConfig m_configuration; diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/ReferenceGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/ReferenceGradientComponent.h index 17c40865b3..82d2de1725 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/ReferenceGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/ReferenceGradientComponent.h @@ -64,7 +64,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; bool IsEntityInHierarchy(const AZ::EntityId& entityId) const override; protected: diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/ShapeAreaFalloffGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/ShapeAreaFalloffGradientComponent.h index 27b2da58a3..4169f31a89 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/ShapeAreaFalloffGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/ShapeAreaFalloffGradientComponent.h @@ -69,7 +69,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; protected: ////////////////////////////////////////////////////////////////////////// diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/SmoothStepGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/SmoothStepGradientComponent.h index 03f629ab1e..282ad65a0c 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/SmoothStepGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/SmoothStepGradientComponent.h @@ -71,7 +71,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; bool IsEntityInHierarchy(const AZ::EntityId& entityId) const override; protected: diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceAltitudeGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceAltitudeGradientComponent.h index eb76fac292..6843be8a0e 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceAltitudeGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceAltitudeGradientComponent.h @@ -90,7 +90,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; protected: ////////////////////////////////////////////////////////////////////////// diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceMaskGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceMaskGradientComponent.h index 3eafb8c115..2580da10a0 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceMaskGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceMaskGradientComponent.h @@ -70,7 +70,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; protected: ////////////////////////////////////////////////////////////////////////// diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceSlopeGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceSlopeGradientComponent.h index b464b6fb0f..bdfbcd2b7f 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceSlopeGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/SurfaceSlopeGradientComponent.h @@ -92,7 +92,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; protected: ////////////////////////////////////////////////////////////////////////// diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Components/ThresholdGradientComponent.h b/Gems/GradientSignal/Code/Include/GradientSignal/Components/ThresholdGradientComponent.h index 96bc235ea8..06369cbe0a 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Components/ThresholdGradientComponent.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Components/ThresholdGradientComponent.h @@ -65,7 +65,7 @@ namespace GradientSignal ////////////////////////////////////////////////////////////////////////// // GradientRequestBus float GetValue(const GradientSampleParams& sampleParams) const override; - void GetValues(AZStd::span positions, AZStd::span outValues) const override; + void GetValues(AZStd::span positions, AZStd::span outValues) const override; bool IsEntityInHierarchy(const AZ::EntityId& entityId) const override; protected: diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/Ebuses/GradientRequestBus.h b/Gems/GradientSignal/Code/Include/GradientSignal/Ebuses/GradientRequestBus.h index 45b5a173a3..a2e5912f82 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/Ebuses/GradientRequestBus.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/Ebuses/GradientRequestBus.h @@ -56,7 +56,7 @@ namespace GradientSignal * \param positions The input list of positions to query. * \param outValues The output list of values. This list is expected to be the same size as the positions list. */ - virtual void GetValues(AZStd::span positions, AZStd::span outValues) const + virtual void GetValues(AZStd::span positions, AZStd::span outValues) const { // Reference implementation of GetValues for any gradients that don't have their own optimized implementations. // This is 10%-60% faster than calling GetValue via EBus many times due to the per-call EBus overhead. diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/GradientSampler.h b/Gems/GradientSignal/Code/Include/GradientSignal/GradientSampler.h index bf5c8d1ea0..113693e928 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/GradientSampler.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/GradientSampler.h @@ -33,7 +33,7 @@ namespace GradientSignal static void Reflect(AZ::ReflectContext* context); inline float GetValue(const GradientSampleParams& sampleParams) const; - inline void GetValues(AZStd::span positions, AZStd::span outValues) const; + inline void GetValues(AZStd::span positions, AZStd::span outValues) const; bool IsEntityInHierarchy(const AZ::EntityId& entityId) const; @@ -147,7 +147,7 @@ namespace GradientSignal return output * m_opacity; } - inline void GradientSampler::GetValues(AZStd::span positions, AZStd::span outValues) const + inline void GradientSampler::GetValues(AZStd::span positions, AZStd::span outValues) const { auto ClearOutputValues = [](AZStd::span outValues) { diff --git a/Gems/GradientSignal/Code/Source/Components/ConstantGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/ConstantGradientComponent.cpp index ac81f616c6..bf94429a63 100644 --- a/Gems/GradientSignal/Code/Source/Components/ConstantGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/ConstantGradientComponent.cpp @@ -135,7 +135,7 @@ namespace GradientSignal } void ConstantGradientComponent::GetValues( - [[maybe_unused]] AZStd::span positions, AZStd::span outValues) const + [[maybe_unused]] AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/DitherGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/DitherGradientComponent.cpp index 1b320afeb9..eaed069292 100644 --- a/Gems/GradientSignal/Code/Source/Components/DitherGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/DitherGradientComponent.cpp @@ -264,7 +264,7 @@ namespace GradientSignal return GetDitherValue(scaledCoordinate, value); } - void DitherGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void DitherGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/ImageGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/ImageGradientComponent.cpp index d948f6269e..3639d5c6df 100644 --- a/Gems/GradientSignal/Code/Source/Components/ImageGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/ImageGradientComponent.cpp @@ -219,7 +219,7 @@ namespace GradientSignal return 0.0f; } - void ImageGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void ImageGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/InvertGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/InvertGradientComponent.cpp index aef5cc7a52..c9d8451104 100644 --- a/Gems/GradientSignal/Code/Source/Components/InvertGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/InvertGradientComponent.cpp @@ -137,7 +137,7 @@ namespace GradientSignal return output; } - void InvertGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void InvertGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/LevelsGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/LevelsGradientComponent.cpp index 25f6a34614..85797ef4fe 100644 --- a/Gems/GradientSignal/Code/Source/Components/LevelsGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/LevelsGradientComponent.cpp @@ -185,7 +185,7 @@ namespace GradientSignal return output; } - void LevelsGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void LevelsGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/MixedGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/MixedGradientComponent.cpp index 23bdd379fe..d3cc1a5f24 100644 --- a/Gems/GradientSignal/Code/Source/Components/MixedGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/MixedGradientComponent.cpp @@ -284,7 +284,7 @@ namespace GradientSignal return AZ::GetClamp(result, 0.0f, 1.0f); } - void MixedGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void MixedGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/PerlinGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/PerlinGradientComponent.cpp index e3dfaf2161..17d389559b 100644 --- a/Gems/GradientSignal/Code/Source/Components/PerlinGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/PerlinGradientComponent.cpp @@ -203,7 +203,7 @@ namespace GradientSignal return 0.0f; } - void PerlinGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void PerlinGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/PosterizeGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/PosterizeGradientComponent.cpp index 4616e080f1..b46c9891ed 100644 --- a/Gems/GradientSignal/Code/Source/Components/PosterizeGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/PosterizeGradientComponent.cpp @@ -155,7 +155,7 @@ namespace GradientSignal return PosterizeValue(input, bands, m_configuration.m_mode); } - void PosterizeGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void PosterizeGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/RandomGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/RandomGradientComponent.cpp index 0f4ece38a1..245801e3b8 100644 --- a/Gems/GradientSignal/Code/Source/Components/RandomGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/RandomGradientComponent.cpp @@ -183,7 +183,7 @@ namespace GradientSignal return 0.0f; } - void RandomGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void RandomGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/ReferenceGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/ReferenceGradientComponent.cpp index e135401ff5..a3d67e6f8a 100644 --- a/Gems/GradientSignal/Code/Source/Components/ReferenceGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/ReferenceGradientComponent.cpp @@ -134,7 +134,7 @@ namespace GradientSignal return m_configuration.m_gradientSampler.GetValue(sampleParams); } - void ReferenceGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void ReferenceGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/ShapeAreaFalloffGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/ShapeAreaFalloffGradientComponent.cpp index 77b7f1a428..62b4834f47 100644 --- a/Gems/GradientSignal/Code/Source/Components/ShapeAreaFalloffGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/ShapeAreaFalloffGradientComponent.cpp @@ -168,7 +168,7 @@ namespace GradientSignal return (distance <= 0.0f) ? 1.0f : AZ::GetMax(1.0f - (distance / m_configuration.m_falloffWidth), 0.0f); } - void ShapeAreaFalloffGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void ShapeAreaFalloffGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/SmoothStepGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/SmoothStepGradientComponent.cpp index 683f0a37fa..9d1a601fe8 100644 --- a/Gems/GradientSignal/Code/Source/Components/SmoothStepGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/SmoothStepGradientComponent.cpp @@ -172,7 +172,7 @@ namespace GradientSignal return m_configuration.m_smoothStep.GetSmoothedValue(value); } - void SmoothStepGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void SmoothStepGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/SurfaceAltitudeGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/SurfaceAltitudeGradientComponent.cpp index ee6c272e40..1670483131 100644 --- a/Gems/GradientSignal/Code/Source/Components/SurfaceAltitudeGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/SurfaceAltitudeGradientComponent.cpp @@ -211,7 +211,7 @@ namespace GradientSignal return CalculateAltitudeRatio(points, m_configuration.m_altitudeMin, m_configuration.m_altitudeMax); } - void SurfaceAltitudeGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void SurfaceAltitudeGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/SurfaceMaskGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/SurfaceMaskGradientComponent.cpp index f697050f56..ea72971818 100644 --- a/Gems/GradientSignal/Code/Source/Components/SurfaceMaskGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/SurfaceMaskGradientComponent.cpp @@ -175,7 +175,7 @@ namespace GradientSignal return result; } - void SurfaceMaskGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void SurfaceMaskGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/SurfaceSlopeGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/SurfaceSlopeGradientComponent.cpp index 50105a862f..e557785509 100644 --- a/Gems/GradientSignal/Code/Source/Components/SurfaceSlopeGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/SurfaceSlopeGradientComponent.cpp @@ -215,7 +215,7 @@ namespace GradientSignal return GetSlopeRatio(points, angleMin, angleMax); } - void SurfaceSlopeGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void SurfaceSlopeGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { diff --git a/Gems/GradientSignal/Code/Source/Components/ThresholdGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/ThresholdGradientComponent.cpp index 5df579576d..25e956be38 100644 --- a/Gems/GradientSignal/Code/Source/Components/ThresholdGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/ThresholdGradientComponent.cpp @@ -141,7 +141,7 @@ namespace GradientSignal return (m_configuration.m_gradientSampler.GetValue(sampleParams) <= m_configuration.m_threshold) ? 0.0f : 1.0f; } - void ThresholdGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const + void ThresholdGradientComponent::GetValues(AZStd::span positions, AZStd::span outValues) const { if (positions.size() != outValues.size()) { From cfd721bce16de707574219fd46fc7456d0d21ca4 Mon Sep 17 00:00:00 2001 From: Nicholas Van Sickle Date: Wed, 19 Jan 2022 11:52:57 -0800 Subject: [PATCH 16/17] A bit of Generic DOM tidying/fixup (#6914) * A bit of Generic DOM tidying/fixup - Refactor out a test fixture for all DOM tests / benchmarks - Optimize `GetType` implementation to not use `AZStd::variant::visit` (benchmark included to A/B the implementations) - Tag a few more mutating Value functions with "Mutable" to avoid astonishing copy-on-writes Benchmark results for GetType implementation: ``` DomValueBenchmark/AzDomValueGetType_UsingVariantIndex 18.2 ns 18.0 ns 40727273 items_per_second=443.667M/s DomValueBenchmark/AzDomValueGetType_UsingVariantVisit 32.2 ns 32.2 ns 21333333 items_per_second=248.242M/s ``` Signed-off-by: Nicholas Van Sickle --- Code/Framework/AzCore/AzCore/DOM/DomUtils.cpp | 8 +- Code/Framework/AzCore/AzCore/DOM/DomValue.cpp | 105 +++------ Code/Framework/AzCore/AzCore/DOM/DomValue.h | 16 +- .../AzCore/Tests/DOM/DomFixtures.cpp | 189 +++++++++++++++ Code/Framework/AzCore/Tests/DOM/DomFixtures.h | 66 ++++++ .../AzCore/Tests/DOM/DomJsonBenchmarks.cpp | 146 ++---------- .../AzCore/Tests/DOM/DomJsonTests.cpp | 9 +- .../AzCore/Tests/DOM/DomValueBenchmarks.cpp | 223 +++++++++--------- .../AzCore/Tests/DOM/DomValueTests.cpp | 14 +- .../AzCore/Tests/azcoretests_files.cmake | 2 + 10 files changed, 443 insertions(+), 335 deletions(-) create mode 100644 Code/Framework/AzCore/Tests/DOM/DomFixtures.cpp create mode 100644 Code/Framework/AzCore/Tests/DOM/DomFixtures.h diff --git a/Code/Framework/AzCore/AzCore/DOM/DomUtils.cpp b/Code/Framework/AzCore/AzCore/DOM/DomUtils.cpp index c604373296..bc5c2b28cf 100644 --- a/Code/Framework/AzCore/AzCore/DOM/DomUtils.cpp +++ b/Code/Framework/AzCore/AzCore/DOM/DomUtils.cpp @@ -77,8 +77,8 @@ namespace AZ::Dom::Utils for (size_t i = 0; i < ourValues.size(); ++i) { const Object::EntryType& lhsChild = ourValues[i]; - const Object::EntryType& rhsChild = theirValues[i]; - if (lhsChild.first != rhsChild.first || !DeepCompareIsEqual(lhsChild.second, rhsChild.second)) + auto rhsIt = rhs.FindMember(lhsChild.first); + if (rhsIt == rhs.MemberEnd() || !DeepCompareIsEqual(lhsChild.second, rhsIt->second)) { return false; } @@ -144,8 +144,8 @@ namespace AZ::Dom::Utils for (size_t i = 0; i < ourProperties.size(); ++i) { const Object::EntryType& lhsChild = ourProperties[i]; - const Object::EntryType& rhsChild = theirProperties[i]; - if (lhsChild.first != rhsChild.first || !DeepCompareIsEqual(lhsChild.second, rhsChild.second)) + auto rhsIt = rhs.FindMember(lhsChild.first); + if (rhsIt == rhs.MemberEnd() || !DeepCompareIsEqual(lhsChild.second, rhsIt->second)) { return false; } diff --git a/Code/Framework/AzCore/AzCore/DOM/DomValue.cpp b/Code/Framework/AzCore/AzCore/DOM/DomValue.cpp index 6d944c9f45..10c8e33715 100644 --- a/Code/Framework/AzCore/AzCore/DOM/DomValue.cpp +++ b/Code/Framework/AzCore/AzCore/DOM/DomValue.cpp @@ -283,64 +283,33 @@ namespace AZ::Dom Type Dom::Value::GetType() const { - return AZStd::visit( - [](auto&& value) -> Type - { - using CurrentType = AZStd::decay_t; - if constexpr (AZStd::is_same_v) - { - return Type::Null; - } - else if constexpr (AZStd::is_same_v) - { - return Type::Int64; - } - else if constexpr (AZStd::is_same_v) - { - return Type::Uint64; - } - else if constexpr (AZStd::is_same_v) - { - return Type::Double; - } - else if constexpr (AZStd::is_same_v) - { - return Type::Bool; - } - else if constexpr (AZStd::is_same_v) - { - return Type::String; - } - else if constexpr (AZStd::is_same_v) - { - return Type::String; - } - else if constexpr (AZStd::is_same_v) - { - return Type::String; - } - else if constexpr (AZStd::is_same_v) - { - return Type::Object; - } - else if constexpr (AZStd::is_same_v) - { - return Type::Array; - } - else if constexpr (AZStd::is_same_v) - { - return Type::Node; - } - else if constexpr (AZStd::is_same_v) - { - return Type::Opaque; - } - else - { - AZ_Assert(false, "AZ::Dom::Value::GetType: m_value has an unexpected type"); - } - }, - m_value); + switch (m_value.index()) + { + case GetTypeIndex(): + return Type::Null; + case GetTypeIndex(): + return Type::Int64; + case GetTypeIndex(): + return Type::Uint64; + case GetTypeIndex(): + return Type::Double; + case GetTypeIndex(): + return Type::Bool; + case GetTypeIndex(): + case GetTypeIndex(): + case GetTypeIndex(): + return Type::String; + case GetTypeIndex(): + return Type::Object; + case GetTypeIndex(): + return Type::Array; + case GetTypeIndex(): + return Type::Node; + case GetTypeIndex>(): + return Type::Opaque; + } + AZ_Assert(false, "AZ::Dom::Value::GetType: m_value has an unexpected type"); + return Type::Null; } bool Value::IsNull() const @@ -594,12 +563,12 @@ namespace AZ::Dom return GetObjectInternal().end(); } - Object::Iterator Value::MemberBegin() + Object::Iterator Value::MutableMemberBegin() { return GetObjectInternal().begin(); } - Object::Iterator Value::MemberEnd() + Object::Iterator Value::MutableMemberEnd() { return GetObjectInternal().end(); } @@ -725,12 +694,12 @@ namespace AZ::Dom return object.end(); } - Object::Iterator Value::EraseMember(Object::ConstIterator pos) + Object::Iterator Value::EraseMember(Object::Iterator pos) { return GetObjectInternal().erase(pos); } - Object::Iterator Value::EraseMember(Object::ConstIterator first, Object::ConstIterator last) + Object::Iterator Value::EraseMember(Object::Iterator first, Object::Iterator last) { return GetObjectInternal().erase(first, last); } @@ -811,12 +780,12 @@ namespace AZ::Dom return GetArrayInternal().end(); } - Array::Iterator Value::ArrayBegin() + Array::Iterator Value::MutableArrayBegin() { return GetArrayInternal().begin(); } - Array::Iterator Value::ArrayEnd() + Array::Iterator Value::MutableArrayEnd() { return GetArrayInternal().end(); } @@ -843,12 +812,12 @@ namespace AZ::Dom return *this; } - Array::Iterator Value::ArrayErase(Array::ConstIterator pos) + Array::Iterator Value::ArrayErase(Array::Iterator pos) { return GetArrayInternal().erase(pos); } - Array::Iterator Value::ArrayErase(Array::ConstIterator first, Array::ConstIterator last) + Array::Iterator Value::ArrayErase(Array::Iterator first, Array::Iterator last) { return GetArrayInternal().erase(first, last); } @@ -1113,6 +1082,10 @@ namespace AZ::Dom { result = visitor.RefCountedString(arg, copyStrings ? Lifetime::Temporary : Lifetime::Persistent); } + else if constexpr (AZStd::is_same_v) + { + result = visitor.String(arg, copyStrings ? Lifetime::Temporary : Lifetime::Persistent); + } else if constexpr (AZStd::is_same_v) { result = visitor.StartObject(); diff --git a/Code/Framework/AzCore/AzCore/DOM/DomValue.h b/Code/Framework/AzCore/AzCore/DOM/DomValue.h index ecf8326525..d1d3c1745d 100644 --- a/Code/Framework/AzCore/AzCore/DOM/DomValue.h +++ b/Code/Framework/AzCore/AzCore/DOM/DomValue.h @@ -268,8 +268,8 @@ namespace AZ::Dom Object::ConstIterator MemberBegin() const; Object::ConstIterator MemberEnd() const; - Object::Iterator MemberBegin(); - Object::Iterator MemberEnd(); + Object::Iterator MutableMemberBegin(); + Object::Iterator MutableMemberEnd(); Object::Iterator FindMutableMember(KeyType name); Object::Iterator FindMutableMember(AZStd::string_view name); @@ -289,8 +289,8 @@ namespace AZ::Dom void RemoveMember(KeyType name); void RemoveMember(AZStd::string_view name); Object::Iterator RemoveMember(Object::Iterator pos); - Object::Iterator EraseMember(Object::ConstIterator pos); - Object::Iterator EraseMember(Object::ConstIterator first, Object::ConstIterator last); + Object::Iterator EraseMember(Object::Iterator pos); + Object::Iterator EraseMember(Object::Iterator first, Object::Iterator last); Object::Iterator EraseMember(KeyType name); Object::Iterator EraseMember(AZStd::string_view name); @@ -313,15 +313,15 @@ namespace AZ::Dom Array::ConstIterator ArrayBegin() const; Array::ConstIterator ArrayEnd() const; - Array::Iterator ArrayBegin(); - Array::Iterator ArrayEnd(); + Array::Iterator MutableArrayBegin(); + Array::Iterator MutableArrayEnd(); Value& ArrayReserve(size_t newCapacity); Value& ArrayPushBack(Value value); Value& ArrayPopBack(); - Array::Iterator ArrayErase(Array::ConstIterator pos); - Array::Iterator ArrayErase(Array::ConstIterator first, Array::ConstIterator last); + Array::Iterator ArrayErase(Array::Iterator pos); + Array::Iterator ArrayErase(Array::Iterator first, Array::Iterator last); Array::ContainerType& GetMutableArray(); const Array::ContainerType& GetArray() const; diff --git a/Code/Framework/AzCore/Tests/DOM/DomFixtures.cpp b/Code/Framework/AzCore/Tests/DOM/DomFixtures.cpp new file mode 100644 index 0000000000..236c1f6d74 --- /dev/null +++ b/Code/Framework/AzCore/Tests/DOM/DomFixtures.cpp @@ -0,0 +1,189 @@ +/* + * 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 +#include +#include +#include + +namespace AZ::Dom::Tests +{ + void DomTestHarness::SetUpHarness() + { + NameDictionary::Create(); + AZ::AllocatorInstance::Create(); + } + + void DomTestHarness::TearDownHarness() + { + AZ::AllocatorInstance::Destroy(); + NameDictionary::Destroy(); + } + + void DomBenchmarkFixture::SetUp(const ::benchmark::State& st) + { + UnitTest::AllocatorsBenchmarkFixture::SetUp(st); + SetUpHarness(); + } + + void DomBenchmarkFixture::SetUp(::benchmark::State& st) + { + UnitTest::AllocatorsBenchmarkFixture::SetUp(st); + SetUpHarness(); + } + + void DomBenchmarkFixture::TearDown(::benchmark::State& st) + { + TearDownHarness(); + UnitTest::AllocatorsBenchmarkFixture::TearDown(st); + } + + void DomBenchmarkFixture::TearDown(const ::benchmark::State& st) + { + TearDownHarness(); + UnitTest::AllocatorsBenchmarkFixture::TearDown(st); + } + + rapidjson::Document DomBenchmarkFixture::GenerateDomJsonBenchmarkDocument(int64_t entryCount, int64_t stringTemplateLength) + { + rapidjson::Document document; + document.SetObject(); + + AZStd::string entryTemplate; + while (entryTemplate.size() < aznumeric_cast(stringTemplateLength)) + { + entryTemplate += "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor "; + } + entryTemplate.resize(stringTemplateLength); + AZStd::string buffer; + + auto createString = [&](int n) -> rapidjson::Value + { + buffer = AZStd::string::format("#%i %s", n, entryTemplate.c_str()); + return rapidjson::Value(buffer.data(), aznumeric_cast(buffer.size()), document.GetAllocator()); + }; + + auto createEntry = [&](int n) -> rapidjson::Value + { + rapidjson::Value entry(rapidjson::kObjectType); + entry.AddMember("string", createString(n), document.GetAllocator()); + entry.AddMember("int", rapidjson::Value(n), document.GetAllocator()); + entry.AddMember("double", rapidjson::Value(aznumeric_cast(n) * 0.5), document.GetAllocator()); + entry.AddMember("bool", rapidjson::Value(n % 2 == 0), document.GetAllocator()); + entry.AddMember("null", rapidjson::Value(rapidjson::kNullType), document.GetAllocator()); + return entry; + }; + + auto createArray = [&]() -> rapidjson::Value + { + rapidjson::Value array; + array.SetArray(); + for (int i = 0; i < entryCount; ++i) + { + array.PushBack(createEntry(i), document.GetAllocator()); + } + return array; + }; + + auto createObject = [&]() -> rapidjson::Value + { + rapidjson::Value object; + object.SetObject(); + for (int i = 0; i < entryCount; ++i) + { + buffer = AZStd::string::format("Key%i", i); + rapidjson::Value key; + key.SetString(buffer.data(), aznumeric_cast(buffer.length()), document.GetAllocator()); + object.AddMember(key.Move(), createArray(), document.GetAllocator()); + } + return object; + }; + + document.SetObject(); + document.AddMember("entries", createObject(), document.GetAllocator()); + + return document; + } + + AZStd::string DomBenchmarkFixture::GenerateDomJsonBenchmarkPayload(int64_t entryCount, int64_t stringTemplateLength) + { + rapidjson::Document document = GenerateDomJsonBenchmarkDocument(entryCount, stringTemplateLength); + + AZStd::string serializedJson; + auto result = AZ::JsonSerializationUtils::WriteJsonString(document, serializedJson); + AZ_Assert(result.IsSuccess(), "Failed to serialize generated JSON"); + return serializedJson; + } + + Value DomBenchmarkFixture::GenerateDomBenchmarkPayload(int64_t entryCount, int64_t stringTemplateLength) + { + Value root(Type::Object); + + AZStd::string entryTemplate; + while (entryTemplate.size() < aznumeric_cast(stringTemplateLength)) + { + entryTemplate += "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor "; + } + entryTemplate.resize(stringTemplateLength); + AZStd::string buffer; + + auto createString = [&](int n) -> Value + { + return Value(AZStd::string::format("#%i %s", n, entryTemplate.c_str()), true); + }; + + auto createEntry = [&](int n) -> Value + { + Value entry(Type::Object); + entry.AddMember("string", createString(n)); + entry.AddMember("int", Value(n)); + entry.AddMember("double", Value(aznumeric_cast(n) * 0.5)); + entry.AddMember("bool", Value(n % 2 == 0)); + entry.AddMember("null", Value(Type::Null)); + return entry; + }; + + auto createArray = [&]() -> Value + { + Value array(Type::Array); + for (int i = 0; i < entryCount; ++i) + { + array.ArrayPushBack(createEntry(i)); + } + return array; + }; + + auto createObject = [&]() -> Value + { + Value object; + object.SetObject(); + for (int i = 0; i < entryCount; ++i) + { + buffer = AZStd::string::format("Key%i", i); + object.AddMember(AZ::Name(buffer), createArray()); + } + return object; + }; + + root["entries"] = createObject(); + + return root; + } + + void DomTestFixture::SetUp() + { + UnitTest::AllocatorsFixture::SetUp(); + SetUpHarness(); + } + + void DomTestFixture::TearDown() + { + TearDownHarness(); + UnitTest::AllocatorsFixture::TearDown(); + } +} // namespace AZ::Dom::Tests diff --git a/Code/Framework/AzCore/Tests/DOM/DomFixtures.h b/Code/Framework/AzCore/Tests/DOM/DomFixtures.h new file mode 100644 index 0000000000..381eff6b98 --- /dev/null +++ b/Code/Framework/AzCore/Tests/DOM/DomFixtures.h @@ -0,0 +1,66 @@ +/* + * 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 +#include +#include + +#define DOM_REGISTER_SERIALIZATION_BENCHMARK(BaseClass, Method) \ + BENCHMARK_REGISTER_F(BaseClass, Method)->Args({ 10, 5 })->Args({ 10, 500 })->Args({ 100, 5 })->Args({ 100, 500 }) +#define DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(BaseClass, Method) \ + DOM_REGISTER_SERIALIZATION_BENCHMARK(BaseClass, Method)->Unit(benchmark::kMillisecond); +#define DOM_REGISTER_SERIALIZATION_BENCHMARK_NS(BaseClass, Method) \ + DOM_REGISTER_SERIALIZATION_BENCHMARK(BaseClass, Method)->Unit(benchmark::kNanosecond); + +namespace AZ::Dom::Tests +{ + class DomTestHarness + { + public: + virtual ~DomTestHarness() = default; + + virtual void SetUpHarness(); + virtual void TearDownHarness(); + }; + + class DomBenchmarkFixture + : public DomTestHarness + , public UnitTest::AllocatorsBenchmarkFixture + { + public: + void SetUp(const ::benchmark::State& st) override; + void SetUp(::benchmark::State& st) override; + void TearDown(::benchmark::State& st) override; + void TearDown(const ::benchmark::State& st) override; + + rapidjson::Document GenerateDomJsonBenchmarkDocument(int64_t entryCount, int64_t stringTemplateLength); + AZStd::string GenerateDomJsonBenchmarkPayload(int64_t entryCount, int64_t stringTemplateLength); + Value GenerateDomBenchmarkPayload(int64_t entryCount, int64_t stringTemplateLength); + + template + static void TakeAndDiscardWithoutTimingDtor(T&& value, benchmark::State& state) + { + { + T instance = AZStd::move(value); + state.PauseTiming(); + } + state.ResumeTiming(); + } + }; + + class DomTestFixture + : public DomTestHarness + , public UnitTest::AllocatorsFixture + { + public: + void SetUp() override; + void TearDown() override; + }; +} // namespace AZ::Dom::Tests diff --git a/Code/Framework/AzCore/Tests/DOM/DomJsonBenchmarks.cpp b/Code/Framework/AzCore/Tests/DOM/DomJsonBenchmarks.cpp index 8eda110e7b..f84b60af07 100644 --- a/Code/Framework/AzCore/Tests/DOM/DomJsonBenchmarks.cpp +++ b/Code/Framework/AzCore/Tests/DOM/DomJsonBenchmarks.cpp @@ -16,131 +16,14 @@ #include #include #include +#include -namespace Benchmark +namespace AZ::Dom::Benchmark { - class DomJsonBenchmark : public UnitTest::AllocatorsBenchmarkFixture + class DomJsonBenchmark : public Tests::DomBenchmarkFixture { - public: - void SetUp(const ::benchmark::State& st) override - { - UnitTest::AllocatorsBenchmarkFixture::SetUp(st); - AZ::NameDictionary::Create(); - AZ::AllocatorInstance::Create(); - } - - void SetUp(::benchmark::State& st) override - { - UnitTest::AllocatorsBenchmarkFixture::SetUp(st); - AZ::NameDictionary::Create(); - AZ::AllocatorInstance::Create(); - } - - void TearDown(::benchmark::State& st) override - { - AZ::AllocatorInstance::Destroy(); - AZ::NameDictionary::Destroy(); - UnitTest::AllocatorsBenchmarkFixture::TearDown(st); - } - - void TearDown(const ::benchmark::State& st) override - { - AZ::AllocatorInstance::Destroy(); - AZ::NameDictionary::Destroy(); - UnitTest::AllocatorsBenchmarkFixture::TearDown(st); - } - - rapidjson::Document GenerateDomJsonBenchmarkDocument(int64_t entryCount, int64_t stringTemplateLength) - { - rapidjson::Document document; - document.SetObject(); - - AZStd::string entryTemplate; - while (entryTemplate.size() < static_cast(stringTemplateLength)) - { - entryTemplate += "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor "; - } - entryTemplate.resize(stringTemplateLength); - AZStd::string buffer; - - auto createString = [&](int n) -> rapidjson::Value - { - buffer = AZStd::string::format("#%i %s", n, entryTemplate.c_str()); - return rapidjson::Value(buffer.data(), static_cast(buffer.size()), document.GetAllocator()); - }; - - auto createEntry = [&](int n) -> rapidjson::Value - { - rapidjson::Value entry(rapidjson::kObjectType); - entry.AddMember("string", createString(n), document.GetAllocator()); - entry.AddMember("int", rapidjson::Value(n), document.GetAllocator()); - entry.AddMember("double", rapidjson::Value(static_cast(n) * 0.5), document.GetAllocator()); - entry.AddMember("bool", rapidjson::Value(n % 2 == 0), document.GetAllocator()); - entry.AddMember("null", rapidjson::Value(rapidjson::kNullType), document.GetAllocator()); - return entry; - }; - - auto createArray = [&]() -> rapidjson::Value - { - rapidjson::Value array; - array.SetArray(); - for (int i = 0; i < entryCount; ++i) - { - array.PushBack(createEntry(i), document.GetAllocator()); - } - return array; - }; - - auto createObject = [&]() -> rapidjson::Value - { - rapidjson::Value object; - object.SetObject(); - for (int i = 0; i < entryCount; ++i) - { - buffer = AZStd::string::format("Key%i", i); - rapidjson::Value key; - key.SetString(buffer.data(), static_cast(buffer.length()), document.GetAllocator()); - object.AddMember(key.Move(), createArray(), document.GetAllocator()); - } - return object; - }; - - document.SetObject(); - document.AddMember("entries", createObject(), document.GetAllocator()); - - return document; - } - - AZStd::string GenerateDomJsonBenchmarkPayload(int64_t entryCount, int64_t stringTemplateLength) - { - rapidjson::Document document = GenerateDomJsonBenchmarkDocument(entryCount, stringTemplateLength); - - AZStd::string serializedJson; - auto result = AZ::JsonSerializationUtils::WriteJsonString(document, serializedJson); - AZ_Assert(result.IsSuccess(), "Failed to serialize generated JSON"); - return serializedJson; - } - - template - void TakeAndDiscardWithoutTimingDtor(T&& value, benchmark::State& state) - { - { - T instance = AZStd::move(value); - state.PauseTiming(); - } - state.ResumeTiming(); - } }; -// Helper macro for registering JSON benchmarks -#define BENCHMARK_REGISTER_JSON(BaseClass, Method) \ - BENCHMARK_REGISTER_F(BaseClass, Method) \ - ->Args({ 10, 5 }) \ - ->Args({ 10, 500 }) \ - ->Args({ 100, 5 }) \ - ->Args({ 100, 500 }) \ - ->Unit(benchmark::kMillisecond); - BENCHMARK_DEFINE_F(DomJsonBenchmark, AzDomDeserializeToRapidjsonInPlace)(benchmark::State& state) { AZ::Dom::JsonBackend backend; @@ -163,7 +46,7 @@ namespace Benchmark state.SetBytesProcessed(serializedPayload.size() * state.iterations()); } - BENCHMARK_REGISTER_JSON(DomJsonBenchmark, AzDomDeserializeToRapidjsonInPlace) + DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(DomJsonBenchmark, AzDomDeserializeToRapidjsonInPlace) BENCHMARK_DEFINE_F(DomJsonBenchmark, AzDomDeserializeToAzDomValueInPlace)(benchmark::State& state) { @@ -187,7 +70,7 @@ namespace Benchmark state.SetBytesProcessed(serializedPayload.size() * state.iterations()); } - BENCHMARK_REGISTER_JSON(DomJsonBenchmark, AzDomDeserializeToAzDomValueInPlace) + DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(DomJsonBenchmark, AzDomDeserializeToAzDomValueInPlace) BENCHMARK_DEFINE_F(DomJsonBenchmark, AzDomDeserializeToRapidjson)(benchmark::State& state) { @@ -207,7 +90,7 @@ namespace Benchmark state.SetBytesProcessed(serializedPayload.size() * state.iterations()); } - BENCHMARK_REGISTER_JSON(DomJsonBenchmark, AzDomDeserializeToRapidjson) + DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(DomJsonBenchmark, AzDomDeserializeToRapidjson) BENCHMARK_DEFINE_F(DomJsonBenchmark, AzDomDeserializeToAzDomValue)(benchmark::State& state) { @@ -227,7 +110,7 @@ namespace Benchmark state.SetBytesProcessed(serializedPayload.size() * state.iterations()); } - BENCHMARK_REGISTER_JSON(DomJsonBenchmark, AzDomDeserializeToAzDomValue) + DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(DomJsonBenchmark, AzDomDeserializeToAzDomValue) BENCHMARK_DEFINE_F(DomJsonBenchmark, RapidjsonDeserializeToRapidjson)(benchmark::State& state) { @@ -243,7 +126,7 @@ namespace Benchmark state.SetBytesProcessed(serializedPayload.size() * state.iterations()); } - BENCHMARK_REGISTER_JSON(DomJsonBenchmark, RapidjsonDeserializeToRapidjson) + DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(DomJsonBenchmark, RapidjsonDeserializeToRapidjson) BENCHMARK_DEFINE_F(DomJsonBenchmark, RapidjsonMakeComplexObject)(benchmark::State& state) { @@ -254,7 +137,7 @@ namespace Benchmark state.SetItemsProcessed(state.range(0) * state.range(0) * state.iterations()); } - BENCHMARK_REGISTER_JSON(DomJsonBenchmark, RapidjsonMakeComplexObject) + DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(DomJsonBenchmark, RapidjsonMakeComplexObject) BENCHMARK_DEFINE_F(DomJsonBenchmark, RapidjsonLookupMemberByString)(benchmark::State& state) { @@ -264,7 +147,9 @@ namespace Benchmark { AZStd::string key(AZStd::string::format("key%" PRId64, i)); keys.push_back(key); - document.AddMember(rapidjson::Value(key.data(), static_cast(key.size()), document.GetAllocator()), rapidjson::Value(i), document.GetAllocator()); + document.AddMember( + rapidjson::Value(key.data(), static_cast(key.size()), document.GetAllocator()), rapidjson::Value(i), + document.GetAllocator()); } for (auto _ : state) @@ -293,7 +178,7 @@ namespace Benchmark state.SetItemsProcessed(state.iterations()); } - BENCHMARK_REGISTER_JSON(DomJsonBenchmark, RapidjsonDeepCopy) + DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(DomJsonBenchmark, RapidjsonDeepCopy) BENCHMARK_DEFINE_F(DomJsonBenchmark, RapidjsonCopyAndMutate)(benchmark::State& state) { @@ -309,9 +194,8 @@ namespace Benchmark state.SetItemsProcessed(state.iterations()); } - BENCHMARK_REGISTER_JSON(DomJsonBenchmark, RapidjsonCopyAndMutate) + DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(DomJsonBenchmark, RapidjsonCopyAndMutate) -#undef BENCHMARK_REGISTER_JSON -} // namespace Benchmark +} // namespace AZ::Dom::Benchmark #endif // defined(HAVE_BENCHMARK) diff --git a/Code/Framework/AzCore/Tests/DOM/DomJsonTests.cpp b/Code/Framework/AzCore/Tests/DOM/DomJsonTests.cpp index c7af6438cf..ff9e378134 100644 --- a/Code/Framework/AzCore/Tests/DOM/DomJsonTests.cpp +++ b/Code/Framework/AzCore/Tests/DOM/DomJsonTests.cpp @@ -13,24 +13,23 @@ #include #include #include +#include namespace AZ::Dom::Tests { - class DomJsonTests : public UnitTest::AllocatorsFixture + class DomJsonTests : public DomTestFixture { public: void SetUp() override { - UnitTest::AllocatorsFixture::SetUp(); - NameDictionary::Create(); + DomTestFixture::SetUp(); m_document = AZStd::make_unique(); } void TearDown() override { m_document.reset(); - NameDictionary::Destroy(); - UnitTest::AllocatorsFixture::TearDown(); + DomTestFixture::TearDown(); } rapidjson::Value CreateString(const AZStd::string& text) diff --git a/Code/Framework/AzCore/Tests/DOM/DomValueBenchmarks.cpp b/Code/Framework/AzCore/Tests/DOM/DomValueBenchmarks.cpp index 40b96e148b..69d99eb12b 100644 --- a/Code/Framework/AzCore/Tests/DOM/DomValueBenchmarks.cpp +++ b/Code/Framework/AzCore/Tests/DOM/DomValueBenchmarks.cpp @@ -6,110 +6,133 @@ * */ -#include #include +#include #include #include -#include +#include namespace AZ::Dom::Benchmark { - class DomValueBenchmark : public UnitTest::AllocatorsBenchmarkFixture + class DomValueBenchmark : public Tests::DomBenchmarkFixture { - public: - void SetUp(const ::benchmark::State& st) override - { - UnitTest::AllocatorsBenchmarkFixture::SetUp(st); - AZ::NameDictionary::Create(); - AZ::AllocatorInstance::Create(); - } + }; - void SetUp(::benchmark::State& st) override - { - UnitTest::AllocatorsBenchmarkFixture::SetUp(st); - AZ::NameDictionary::Create(); - AZ::AllocatorInstance::Create(); - } + BENCHMARK_DEFINE_F(DomValueBenchmark, AzDomValueGetType_UsingVariantIndex)(benchmark::State& state) + { + Value intValue(5); + Value boolValue(true); + Value objValue(Type::Object); + Value nodeValue(Type::Node); + Value arrValue(Type::Array); + Value uintValue(5u); + Value doubleValue(4.0); + Value stringValue("foo", true); - void TearDown(::benchmark::State& st) override + for (auto _ : state) { - AZ::AllocatorInstance::Destroy(); - AZ::NameDictionary::Destroy(); - UnitTest::AllocatorsBenchmarkFixture::TearDown(st); + (intValue.GetType()); + (boolValue.GetType()); + (objValue.GetType()); + (nodeValue.GetType()); + (arrValue.GetType()); + (uintValue.GetType()); + (doubleValue.GetType()); + (stringValue.GetType()); } - void TearDown(const ::benchmark::State& st) override - { - AZ::AllocatorInstance::Destroy(); - AZ::NameDictionary::Destroy(); - UnitTest::AllocatorsBenchmarkFixture::TearDown(st); - } + state.SetItemsProcessed(8 * state.iterations()); + } + BENCHMARK_REGISTER_F(DomValueBenchmark, AzDomValueGetType_UsingVariantIndex); - Value GenerateDomBenchmarkPayload(int64_t entryCount, int64_t stringTemplateLength) + BENCHMARK_DEFINE_F(DomValueBenchmark, AzDomValueGetType_UsingVariantVisit)(benchmark::State& state) + { + Value intValue(5); + Value boolValue(true); + Value objValue(Type::Object); + Value nodeValue(Type::Node); + Value arrValue(Type::Array); + Value uintValue(5u); + Value doubleValue(4.0); + Value stringValue("foo", true); + + auto getTypeViaVisit = [](const Value& value) { - Value root(Type::Object); - - AZStd::string entryTemplate; - while (entryTemplate.size() < static_cast(stringTemplateLength)) - { - entryTemplate += "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor "; - } - entryTemplate.resize(stringTemplateLength); - AZStd::string buffer; - - auto createString = [&](int n) -> Value - { - return Value(AZStd::string::format("#%i %s", n, entryTemplate.c_str()), true); - }; - - auto createEntry = [&](int n) -> Value - { - Value entry(Type::Object); - entry.AddMember("string", createString(n)); - entry.AddMember("int", Value(n)); - entry.AddMember("double", Value(static_cast(n) * 0.5)); - entry.AddMember("bool", Value(n % 2 == 0)); - entry.AddMember("null", Value(Type::Null)); - return entry; - }; - - auto createArray = [&]() -> Value - { - Value array(Type::Array); - for (int i = 0; i < entryCount; ++i) + return AZStd::visit( + [](auto&& value) constexpr -> Type { - array.ArrayPushBack(createEntry(i)); - } - return array; - }; - - auto createObject = [&]() -> Value - { - Value object; - object.SetObject(); - for (int i = 0; i < entryCount; ++i) - { - buffer = AZStd::string::format("Key%i", i); - object.AddMember(AZ::Name(buffer), createArray()); - } - return object; - }; - - root["entries"] = createObject(); - - return root; - } + using CurrentType = AZStd::decay_t; + if constexpr (AZStd::is_same_v) + { + return Type::Null; + } + else if constexpr (AZStd::is_same_v) + { + return Type::Int64; + } + else if constexpr (AZStd::is_same_v) + { + return Type::Uint64; + } + else if constexpr (AZStd::is_same_v) + { + return Type::Double; + } + else if constexpr (AZStd::is_same_v) + { + return Type::Bool; + } + else if constexpr (AZStd::is_same_v) + { + return Type::String; + } + else if constexpr (AZStd::is_same_v) + { + return Type::String; + } + else if constexpr (AZStd::is_same_v) + { + return Type::String; + } + else if constexpr (AZStd::is_same_v) + { + return Type::Object; + } + else if constexpr (AZStd::is_same_v) + { + return Type::Array; + } + else if constexpr (AZStd::is_same_v) + { + return Type::Node; + } + else if constexpr (AZStd::is_same_v) + { + return Type::Opaque; + } + else + { + AZ_Assert(false, "AZ::Dom::Value::GetType: m_value has an unexpected type"); + } + }, + value.GetInternalValue()); + }; - template - void TakeAndDiscardWithoutTimingDtor(T&& value, benchmark::State& state) + for (auto _ : state) { - { - T instance = AZStd::move(value); - state.PauseTiming(); - } - state.ResumeTiming(); + (getTypeViaVisit(intValue)); + (getTypeViaVisit(boolValue)); + (getTypeViaVisit(objValue)); + (getTypeViaVisit(nodeValue)); + (getTypeViaVisit(arrValue)); + (getTypeViaVisit(uintValue)); + (getTypeViaVisit(doubleValue)); + (getTypeViaVisit(stringValue)); } - }; + + state.SetItemsProcessed(8 * state.iterations()); + } + BENCHMARK_REGISTER_F(DomValueBenchmark, AzDomValueGetType_UsingVariantVisit); BENCHMARK_DEFINE_F(DomValueBenchmark, AzDomValueMakeComplexObject)(benchmark::State& state) { @@ -120,12 +143,7 @@ namespace AZ::Dom::Benchmark state.SetItemsProcessed(state.range(0) * state.range(0) * state.iterations()); } - BENCHMARK_REGISTER_F(DomValueBenchmark, AzDomValueMakeComplexObject) - ->Args({ 10, 5 }) - ->Args({ 10, 500 }) - ->Args({ 100, 5 }) - ->Args({ 100, 500 }) - ->Unit(benchmark::kMillisecond); + DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(DomValueBenchmark, AzDomValueMakeComplexObject) BENCHMARK_DEFINE_F(DomValueBenchmark, AzDomValueShallowCopy)(benchmark::State& state) { @@ -139,12 +157,7 @@ namespace AZ::Dom::Benchmark state.SetItemsProcessed(state.iterations()); } - BENCHMARK_REGISTER_F(DomValueBenchmark, AzDomValueShallowCopy) - ->Args({ 10, 5 }) - ->Args({ 10, 500 }) - ->Args({ 100, 5 }) - ->Args({ 100, 500 }) - ->Unit(benchmark::kNanosecond); + DOM_REGISTER_SERIALIZATION_BENCHMARK_NS(DomValueBenchmark, AzDomValueShallowCopy) BENCHMARK_DEFINE_F(DomValueBenchmark, AzDomValueCopyAndMutate)(benchmark::State& state) { @@ -159,12 +172,7 @@ namespace AZ::Dom::Benchmark state.SetItemsProcessed(state.iterations()); } - BENCHMARK_REGISTER_F(DomValueBenchmark, AzDomValueCopyAndMutate) - ->Args({ 10, 5 }) - ->Args({ 10, 500 }) - ->Args({ 100, 5 }) - ->Args({ 100, 500 }) - ->Unit(benchmark::kNanosecond); + DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(DomValueBenchmark, AzDomValueCopyAndMutate) BENCHMARK_DEFINE_F(DomValueBenchmark, AzDomValueDeepCopy)(benchmark::State& state) { @@ -178,12 +186,7 @@ namespace AZ::Dom::Benchmark state.SetItemsProcessed(state.iterations()); } - BENCHMARK_REGISTER_F(DomValueBenchmark, AzDomValueDeepCopy) - ->Args({ 10, 5 }) - ->Args({ 10, 500 }) - ->Args({ 100, 5 }) - ->Args({ 100, 500 }) - ->Unit(benchmark::kMillisecond); + DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(DomValueBenchmark, AzDomValueDeepCopy) BENCHMARK_DEFINE_F(DomValueBenchmark, LookupMemberByName)(benchmark::State& state) { diff --git a/Code/Framework/AzCore/Tests/DOM/DomValueTests.cpp b/Code/Framework/AzCore/Tests/DOM/DomValueTests.cpp index 10e9f29a44..f39ca4818a 100644 --- a/Code/Framework/AzCore/Tests/DOM/DomValueTests.cpp +++ b/Code/Framework/AzCore/Tests/DOM/DomValueTests.cpp @@ -15,26 +15,18 @@ #include #include #include +#include namespace AZ::Dom::Tests { - class DomValueTests : public UnitTest::AllocatorsFixture + class DomValueTests : public DomTestFixture { public: - void SetUp() override - { - UnitTest::AllocatorsFixture::SetUp(); - NameDictionary::Create(); - AZ::AllocatorInstance::Create(); - } - void TearDown() override { m_value = Value(); - AZ::AllocatorInstance::Destroy(); - NameDictionary::Destroy(); - UnitTest::AllocatorsFixture::TearDown(); + DomTestFixture::TearDown(); } void PerformValueChecks() diff --git a/Code/Framework/AzCore/Tests/azcoretests_files.cmake b/Code/Framework/AzCore/Tests/azcoretests_files.cmake index 7be3afb4a9..aee6828b76 100644 --- a/Code/Framework/AzCore/Tests/azcoretests_files.cmake +++ b/Code/Framework/AzCore/Tests/azcoretests_files.cmake @@ -215,6 +215,8 @@ set(FILES AZStd/Variant.cpp AZStd/VariantSerialization.cpp AZStd/VectorAndArray.cpp + DOM/DomFixtures.cpp + DOM/DomFixtures.h DOM/DomJsonTests.cpp DOM/DomJsonBenchmarks.cpp DOM/DomValueTests.cpp From 5cac67bfaddd9fc568e35ad2c1f8a75a03f0b765 Mon Sep 17 00:00:00 2001 From: Vincent Liu <5900509+onecent1101@users.noreply.github.com> Date: Wed, 19 Jan 2022 12:11:39 -0800 Subject: [PATCH 17/17] Silence aws logging for unit test and have a new AWSNativeSDK as entry point for test env (#6865) * Silence aws logging for unit test * Create a new AWSNativeSDK entry point for test environment only * Update naming for target and file --- Code/Tools/AWSNativeSDKInit/CMakeLists.txt | 18 ++++++++ .../aws_native_sdk_test_files.cmake | 12 +++++ .../source/AWSNativeSDKInit.cpp | 1 - .../tests/libs/AWSNativeSDKTestManager.cpp | 45 +++++++++++++++++++ .../tests/libs/AWSNativeSDKTestManager.h | 39 ++++++++++++++++ Gems/AWSClientAuth/Code/CMakeLists.txt | 3 +- .../Code/Tests/AWSClientAuthGemMock.h | 7 ++- Gems/AWSCore/Code/CMakeLists.txt | 4 +- .../Code/Tests/AWSCoreSystemComponentTest.cpp | 4 +- .../Code/Tests/TestFramework/AWSCoreFixture.h | 6 +-- .../Code/AWSGameLiftClient/CMakeLists.txt | 2 +- .../Tests/AWSGameLiftClientFixture.h | 7 +-- 12 files changed, 130 insertions(+), 18 deletions(-) create mode 100644 Code/Tools/AWSNativeSDKInit/aws_native_sdk_test_files.cmake create mode 100644 Code/Tools/AWSNativeSDKInit/tests/libs/AWSNativeSDKTestManager.cpp create mode 100644 Code/Tools/AWSNativeSDKInit/tests/libs/AWSNativeSDKTestManager.h diff --git a/Code/Tools/AWSNativeSDKInit/CMakeLists.txt b/Code/Tools/AWSNativeSDKInit/CMakeLists.txt index 04f61eb924..de3e0008c2 100644 --- a/Code/Tools/AWSNativeSDKInit/CMakeLists.txt +++ b/Code/Tools/AWSNativeSDKInit/CMakeLists.txt @@ -25,6 +25,24 @@ ly_add_target( AZ::AzCore ) +ly_add_target( + NAME AWSNativeSDKTestLibs STATIC + NAMESPACE AZ + FILES_CMAKE + aws_native_sdk_test_files.cmake + INCLUDE_DIRECTORIES + PUBLIC + include + tests/libs + PRIVATE + source + BUILD_DEPENDENCIES + PRIVATE + 3rdParty::AWSNativeSDK::Core + AZ::AzCore + AZ::AzTest +) + ################################################################################ # Tests ################################################################################ diff --git a/Code/Tools/AWSNativeSDKInit/aws_native_sdk_test_files.cmake b/Code/Tools/AWSNativeSDKInit/aws_native_sdk_test_files.cmake new file mode 100644 index 0000000000..17f4b3f6e9 --- /dev/null +++ b/Code/Tools/AWSNativeSDKInit/aws_native_sdk_test_files.cmake @@ -0,0 +1,12 @@ +# +# 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 +# +# + +set(FILES + tests/libs/AWSNativeSDKTestManager.cpp + tests/libs/AWSNativeSDKTestManager.h +) diff --git a/Code/Tools/AWSNativeSDKInit/source/AWSNativeSDKInit.cpp b/Code/Tools/AWSNativeSDKInit/source/AWSNativeSDKInit.cpp index ca63859945..ca02b4f223 100644 --- a/Code/Tools/AWSNativeSDKInit/source/AWSNativeSDKInit.cpp +++ b/Code/Tools/AWSNativeSDKInit/source/AWSNativeSDKInit.cpp @@ -89,5 +89,4 @@ namespace AWSNativeSDKInit Platform::CustomizeShutdown(); #endif // #if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK) } - } diff --git a/Code/Tools/AWSNativeSDKInit/tests/libs/AWSNativeSDKTestManager.cpp b/Code/Tools/AWSNativeSDKInit/tests/libs/AWSNativeSDKTestManager.cpp new file mode 100644 index 0000000000..29300857c1 --- /dev/null +++ b/Code/Tools/AWSNativeSDKInit/tests/libs/AWSNativeSDKTestManager.cpp @@ -0,0 +1,45 @@ +/* + * 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 + +#include +#include + +#include +#include +#include + +namespace AWSNativeSDKTestLibs +{ + AZ::EnvironmentVariable AWSNativeSDKTestManager::s_sdkManager = nullptr; + + AWSNativeSDKTestManager::AWSNativeSDKTestManager() + { + AZ::Test::SetEnv("AWS_DEFAULT_REGION", "us-east-1", 1); + m_awsSDKOptions.memoryManagementOptions.memoryManager = &m_memoryManager; + Aws::InitAPI(m_awsSDKOptions); + } + + AWSNativeSDKTestManager::~AWSNativeSDKTestManager() + { + Aws::ShutdownAPI(m_awsSDKOptions); + AZ::Test::UnsetEnv("AWS_DEFAULT_REGION"); + } + + void AWSNativeSDKTestManager::Init() + { + s_sdkManager = AZ::Environment::CreateVariable(AWSNativeSDKTestManager::SdkManagerTag); + } + + void AWSNativeSDKTestManager::Shutdown() + { + s_sdkManager = nullptr; + } +} diff --git a/Code/Tools/AWSNativeSDKInit/tests/libs/AWSNativeSDKTestManager.h b/Code/Tools/AWSNativeSDKInit/tests/libs/AWSNativeSDKTestManager.h new file mode 100644 index 0000000000..48e97bb6f8 --- /dev/null +++ b/Code/Tools/AWSNativeSDKInit/tests/libs/AWSNativeSDKTestManager.h @@ -0,0 +1,39 @@ +/* + * 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 +#include + +#include + +#include + +namespace AWSNativeSDKTestLibs +{ + // Entry point for AWSNativeSDK's initialization and shutdown for test environment + // Use an AZ::Environment variable to enforce only one init and shutdown + class AWSNativeSDKTestManager + { + public: + static constexpr const char SdkManagerTag[] = "TestAWSSDKManager"; + + AWSNativeSDKTestManager(); + ~AWSNativeSDKTestManager(); + + static void Init(); + static void Shutdown(); + + private: + static AZ::EnvironmentVariable s_sdkManager; + + AWSNativeSDKInit::MemoryManager m_memoryManager; + Aws::SDKOptions m_awsSDKOptions; + }; +} diff --git a/Gems/AWSClientAuth/Code/CMakeLists.txt b/Gems/AWSClientAuth/Code/CMakeLists.txt index ac9d221f07..e34dd702dd 100644 --- a/Gems/AWSClientAuth/Code/CMakeLists.txt +++ b/Gems/AWSClientAuth/Code/CMakeLists.txt @@ -106,13 +106,12 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) 3rdParty::AWSNativeSDK::AWSClientAuth AZ::AzCore AZ::AzFramework - AZ::AWSNativeSDKInit + AZ::AWSNativeSDKTestLibs Gem::AWSClientAuth.Static Gem::AWSCore Gem::HttpRequestor RUNTIME_DEPENDENCIES Gem::AWSCore - AZ::AWSNativeSDKInit Gem::HttpRequestor ) ly_add_googletest( diff --git a/Gems/AWSClientAuth/Code/Tests/AWSClientAuthGemMock.h b/Gems/AWSClientAuth/Code/Tests/AWSClientAuthGemMock.h index 19314035c4..3bfde09492 100644 --- a/Gems/AWSClientAuth/Code/Tests/AWSClientAuthGemMock.h +++ b/Gems/AWSClientAuth/Code/Tests/AWSClientAuthGemMock.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include @@ -542,7 +542,7 @@ namespace AWSClientAuthUnitTest m_jobContext.reset(aznew AZ::JobContext(*m_jobManager, *m_jobCancelGroup)); AZ::JobContext::SetGlobalContext(m_jobContext.get()); - AWSNativeSDKInit::InitializationManager::InitAwsApi(); + AWSNativeSDKTestLibs::AWSNativeSDKTestManager::Init(); m_cognitoIdentityProviderClientMock = std::make_shared(); m_cognitoIdentityClientMock = std::make_shared(); } @@ -557,8 +557,7 @@ namespace AWSClientAuthUnitTest m_cognitoIdentityProviderClientMock.reset(); m_cognitoIdentityClientMock.reset(); - AWSNativeSDKInit::InitializationManager::Shutdown(); - + AWSNativeSDKTestLibs::AWSNativeSDKTestManager::Shutdown(); AZ::AllocatorInstance::Destroy(); diff --git a/Gems/AWSCore/Code/CMakeLists.txt b/Gems/AWSCore/Code/CMakeLists.txt index 3911aefce6..bb836b57bd 100644 --- a/Gems/AWSCore/Code/CMakeLists.txt +++ b/Gems/AWSCore/Code/CMakeLists.txt @@ -163,7 +163,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) PRIVATE AZ::AzTest AZ::AzFramework - AZ::AWSNativeSDKInit + AZ::AWSNativeSDKTestLibs Gem::AWSCore.Static ) @@ -202,7 +202,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) 3rdParty::Qt::Gui 3rdParty::Qt::Widgets AZ::AzTest - AZ::AWSNativeSDKInit + AZ::AWSNativeSDKTestLibs Gem::AWSCore.Static Gem::AWSCore.Editor.Static ) diff --git a/Gems/AWSCore/Code/Tests/AWSCoreSystemComponentTest.cpp b/Gems/AWSCore/Code/Tests/AWSCoreSystemComponentTest.cpp index b66b43f735..74a1588895 100644 --- a/Gems/AWSCore/Code/Tests/AWSCoreSystemComponentTest.cpp +++ b/Gems/AWSCore/Code/Tests/AWSCoreSystemComponentTest.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include @@ -105,7 +105,7 @@ public: TEST_F(AWSCoreSystemComponentTest, ComponentActivateTest) { // Shutdown SDK which is init in fixture setup step - AWSNativeSDKInit::InitializationManager::Shutdown(); + AWSNativeSDKTestLibs::AWSNativeSDKTestManager::Shutdown(); EXPECT_FALSE(m_coreSystemsComponent->IsAWSApiInitialized()); diff --git a/Gems/AWSCore/Code/Tests/TestFramework/AWSCoreFixture.h b/Gems/AWSCore/Code/Tests/TestFramework/AWSCoreFixture.h index 6ea5593d0e..4daf5bb679 100644 --- a/Gems/AWSCore/Code/Tests/TestFramework/AWSCoreFixture.h +++ b/Gems/AWSCore/Code/Tests/TestFramework/AWSCoreFixture.h @@ -17,7 +17,7 @@ #include #include -#include +#include namespace AWSCoreTestingUtils { @@ -138,7 +138,7 @@ public: m_app = AZStd::make_unique(); } - AWSNativeSDKInit::InitializationManager::InitAwsApi(); + AWSNativeSDKTestLibs::AWSNativeSDKTestManager::Init(); } void TearDown() override @@ -148,7 +148,7 @@ public: void TearDownFixture(bool mockSettingsRegistry = true) { - AWSNativeSDKInit::InitializationManager::Shutdown(); + AWSNativeSDKTestLibs::AWSNativeSDKTestManager::Shutdown(); if (mockSettingsRegistry) { diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/CMakeLists.txt b/Gems/AWSGameLift/Code/AWSGameLiftClient/CMakeLists.txt index ab85e89f75..bdc831c439 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/CMakeLists.txt +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/CMakeLists.txt @@ -90,7 +90,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) Gem::AWSCore Gem::AWSGameLift.Client.Static 3rdParty::AWSNativeSDK::GameLiftClient - AZ::AWSNativeSDKInit + AZ::AWSNativeSDKTestLibs ) # Add AWSGameLift.Client.Tests to googletest ly_add_googletest( diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/AWSGameLiftClientFixture.h b/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/AWSGameLiftClientFixture.h index 88ddb92531..b1c689baec 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/AWSGameLiftClientFixture.h +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/AWSGameLiftClientFixture.h @@ -8,12 +8,13 @@ #pragma once -#include +#include #include #include #include #include #include +#include class AWSGameLiftClientFixture : public UnitTest::ScopedAllocatorSetupFixture @@ -38,12 +39,12 @@ public: m_jobContext.reset(aznew AZ::JobContext(*m_jobManager, *m_jobCancelGroup)); AZ::JobContext::SetGlobalContext(m_jobContext.get()); - AWSNativeSDKInit::InitializationManager::InitAwsApi(); + AWSNativeSDKTestLibs::AWSNativeSDKTestManager::Init(); } void TearDown() override { - AWSNativeSDKInit::InitializationManager::Shutdown(); + AWSNativeSDKTestLibs::AWSNativeSDKTestManager::Shutdown(); AZ::JobContext::SetGlobalContext(nullptr); m_jobContext.reset();