diff --git a/Code/Framework/AzCore/AzCore/Debug/Profiler.h b/Code/Framework/AzCore/AzCore/Debug/Profiler.h index 6e86de2e93..6b27b35f53 100644 --- a/Code/Framework/AzCore/AzCore/Debug/Profiler.h +++ b/Code/Framework/AzCore/AzCore/Debug/Profiler.h @@ -10,11 +10,6 @@ #include #include -#ifdef USE_PIX -#include -#include -#endif - #if defined(AZ_PROFILER_MACRO_DISABLE) // by default we never disable the profiler registers as their overhead should be minimal, you can // still do that for your code though. #define AZ_PROFILE_SCOPE(...) diff --git a/Code/Framework/AzCore/AzCore/Debug/Profiler.inl b/Code/Framework/AzCore/AzCore/Debug/Profiler.inl index 74c0f553c4..c820639b09 100644 --- a/Code/Framework/AzCore/AzCore/Debug/Profiler.inl +++ b/Code/Framework/AzCore/AzCore/Debug/Profiler.inl @@ -10,44 +10,48 @@ namespace AZ::Debug { + namespace Platform + { + template + void BeginProfileRegion(Budget* budget, const char* eventName, T const&... args); + void BeginProfileRegion(Budget* budget, const char* eventName); + void EndProfileRegion(Budget* budget); + } // namespace Platform + template void ProfileScope::BeginRegion( [[maybe_unused]] Budget* budget, [[maybe_unused]] const char* eventName, [[maybe_unused]] T const&... args) { - if (!budget) + #if !defined(_RELEASE) + if (budget) { - return; - } -#if !defined(_RELEASE) - // TODO: Verification that the supplied system name corresponds to a known budget -#if defined(USE_PIX) - PIXBeginEvent(PIX_COLOR_INDEX(budget->Crc() & 0xff), eventName, args...); -#endif - budget->BeginProfileRegion(); + Platform::BeginProfileRegion(budget, eventName, args...); - if (auto profiler = AZ::Interface::Get(); profiler) - { - profiler->BeginRegion(budget, eventName); + budget->BeginProfileRegion(); + + if (auto profiler = AZ::Interface::Get(); profiler) + { + profiler->BeginRegion(budget, eventName); + } } -#endif + #endif // #if !defined(_RELEASE) } inline void ProfileScope::EndRegion([[maybe_unused]] Budget* budget) { - if (!budget) + #if !defined(_RELEASE) + if (budget) { - return; + budget->EndProfileRegion(); + + if (auto profiler = AZ::Interface::Get(); profiler) + { + profiler->EndRegion(budget); + } + + Platform::EndProfileRegion(budget); } -#if !defined(_RELEASE) - budget->EndProfileRegion(); -#if defined(USE_PIX) - PIXEndEvent(); -#endif - if (auto profiler = AZ::Interface::Get(); profiler) - { - profiler->EndRegion(budget); - } -#endif + #endif // !defined(_RELEASE) } template @@ -63,3 +67,5 @@ namespace AZ::Debug } } // namespace AZ::Debug + +#include diff --git a/Code/Framework/AzCore/Platform/Android/AzCore/Debug/Profiler_Android.inl b/Code/Framework/AzCore/Platform/Android/AzCore/Debug/Profiler_Android.inl new file mode 100644 index 0000000000..30f18fca6b --- /dev/null +++ b/Code/Framework/AzCore/Platform/Android/AzCore/Debug/Profiler_Android.inl @@ -0,0 +1,37 @@ +/* + * 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 AZ::Debug::Platform +{ + template + void BeginProfileRegion([[maybe_unused]] Budget* budget, const char* eventName, T const&... args) + { + // ideally this would be smaller but AZ_PROFILE_FUNCTION produces some long event names + using EventNameString = AZStd::fixed_string<512>; + + AZ_PUSH_DISABLE_WARNING(, "-Wformat-security") + EventNameString fullEventName = EventNameString::format(eventName, args...); + AZ_POP_DISABLE_WARNING + + ATrace_beginSection(fullEventName.c_str()); + } + + inline void BeginProfileRegion([[maybe_unused]] Budget* budget, const char* eventName) + { + ATrace_beginSection(eventName); + } + + inline void EndProfileRegion([[maybe_unused]] Budget* budget) + { + ATrace_endSection(); + } +} // namespace AZ::Debug::Platform diff --git a/Code/Framework/AzCore/Platform/AppleTV/AzCore/IO/Streamer/StreamerContext_Platform.h b/Code/Framework/AzCore/Platform/Android/AzCore/Debug/Profiler_Platform.inl similarity index 71% rename from Code/Framework/AzCore/Platform/AppleTV/AzCore/IO/Streamer/StreamerContext_Platform.h rename to Code/Framework/AzCore/Platform/Android/AzCore/Debug/Profiler_Platform.inl index 51d3f54553..5499a0c573 100644 --- a/Code/Framework/AzCore/Platform/AppleTV/AzCore/IO/Streamer/StreamerContext_Platform.h +++ b/Code/Framework/AzCore/Platform/Android/AzCore/Debug/Profiler_Platform.inl @@ -5,6 +5,5 @@ * SPDX-License-Identifier: Apache-2.0 OR MIT * */ -#pragma once -#include <../Common/Default/AzCore/IO/Streamer/StreamerContext_Default.h> +#include diff --git a/Code/Framework/AzCore/Platform/Android/platform_android_files.cmake b/Code/Framework/AzCore/Platform/Android/platform_android_files.cmake index 15326a4435..2ac4967b04 100644 --- a/Code/Framework/AzCore/Platform/Android/platform_android_files.cmake +++ b/Code/Framework/AzCore/Platform/Android/platform_android_files.cmake @@ -81,6 +81,8 @@ set(FILES ../../AzCore/Android/JNI/Internal/JStringUtils_impl.h ../../AzCore/Android/JNI/Internal/Object_impl.h ../../AzCore/Android/JNI/Internal/Signature_impl.h + AzCore/Debug/Profiler_Platform.inl + AzCore/Debug/Profiler_Android.inl ) if (LY_TEST_PROJECT) ly_add_source_properties( diff --git a/Code/Framework/AzCore/Platform/Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl b/Code/Framework/AzCore/Platform/Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl new file mode 100644 index 0000000000..aa796312d7 --- /dev/null +++ b/Code/Framework/AzCore/Platform/Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl @@ -0,0 +1,23 @@ +/* + * 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 + * + */ + +namespace AZ::Debug::Platform +{ + template + void BeginProfileRegion([[maybe_unused]] Budget* budget, [[maybe_unused]] const char* eventName, [[maybe_unused]] T const&... args) + { + } + + inline void BeginProfileRegion([[maybe_unused]] Budget* budget, [[maybe_unused]] const char* eventName) + { + } + + inline void EndProfileRegion([[maybe_unused]] Budget* budget) + { + } +} // namespace AZ::Debug::Platform diff --git a/Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/Debug/Profiler_WinAPI.inl b/Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/Debug/Profiler_WinAPI.inl new file mode 100644 index 0000000000..848460837d --- /dev/null +++ b/Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/Debug/Profiler_WinAPI.inl @@ -0,0 +1,37 @@ +/* + * 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 USE_PIX + #include + #include +#endif + +namespace AZ::Debug::Platform +{ + template + void BeginProfileRegion([[maybe_unused]] Budget* budget, [[maybe_unused]] const char* eventName, [[maybe_unused]] T const&... args) + { + #ifdef USE_PIX + PIXBeginEvent(PIX_COLOR_INDEX(budget->Crc() & 0xff), eventName, args...); + #endif + } + + inline void BeginProfileRegion([[maybe_unused]] Budget* budget, [[maybe_unused]] const char* eventName) + { + #ifdef USE_PIX + PIXBeginEvent(PIX_COLOR_INDEX(budget->Crc() & 0xff), eventName); + #endif + } + + inline void EndProfileRegion([[maybe_unused]] Budget* budget) + { + #ifdef USE_PIX + PIXEndEvent(); + #endif + } +} // namespace AZ::Debug::Platform diff --git a/Code/Framework/AzCore/Platform/Linux/AzCore/Debug/Profiler_Platform.inl b/Code/Framework/AzCore/Platform/Linux/AzCore/Debug/Profiler_Platform.inl new file mode 100644 index 0000000000..d453d1f645 --- /dev/null +++ b/Code/Framework/AzCore/Platform/Linux/AzCore/Debug/Profiler_Platform.inl @@ -0,0 +1,9 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include <../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl> diff --git a/Code/Framework/AzCore/Platform/Linux/platform_linux_files.cmake b/Code/Framework/AzCore/Platform/Linux/platform_linux_files.cmake index b54e38032b..ca0ec0d281 100644 --- a/Code/Framework/AzCore/Platform/Linux/platform_linux_files.cmake +++ b/Code/Framework/AzCore/Platform/Linux/platform_linux_files.cmake @@ -66,4 +66,6 @@ set(FILES ../Common/UnixLike/AzCore/std/time_UnixLike.cpp AzCore/Utils/Utils_Linux.cpp ../Common/UnixLike/AzCore/Utils/Utils_UnixLike.cpp + AzCore/Debug/Profiler_Platform.inl + ../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl ) diff --git a/Code/Framework/AzCore/Platform/Mac/AzCore/Debug/Profiler_Platform.inl b/Code/Framework/AzCore/Platform/Mac/AzCore/Debug/Profiler_Platform.inl new file mode 100644 index 0000000000..d453d1f645 --- /dev/null +++ b/Code/Framework/AzCore/Platform/Mac/AzCore/Debug/Profiler_Platform.inl @@ -0,0 +1,9 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include <../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl> diff --git a/Code/Framework/AzCore/Platform/Mac/platform_mac_files.cmake b/Code/Framework/AzCore/Platform/Mac/platform_mac_files.cmake index dfb76b6db0..65453ee2a5 100644 --- a/Code/Framework/AzCore/Platform/Mac/platform_mac_files.cmake +++ b/Code/Framework/AzCore/Platform/Mac/platform_mac_files.cmake @@ -69,4 +69,6 @@ set(FILES AzCore/Utils/Utils_Mac.cpp ../Common/Apple/AzCore/Utils/Utils_Apple.cpp ../Common/UnixLike/AzCore/Utils/Utils_UnixLike.cpp + AzCore/Debug/Profiler_Platform.inl + ../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl ) diff --git a/Code/Framework/AzCore/Platform/Windows/AzCore/Debug/Profiler_Platform.inl b/Code/Framework/AzCore/Platform/Windows/AzCore/Debug/Profiler_Platform.inl new file mode 100644 index 0000000000..4f6460a2a6 --- /dev/null +++ b/Code/Framework/AzCore/Platform/Windows/AzCore/Debug/Profiler_Platform.inl @@ -0,0 +1,9 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include <../Common/WinAPI/AzCore/Debug/Profiler_WinAPI.inl> diff --git a/Code/Framework/AzCore/Platform/Windows/platform_windows_files.cmake b/Code/Framework/AzCore/Platform/Windows/platform_windows_files.cmake index 6386377fcb..55bbebe917 100644 --- a/Code/Framework/AzCore/Platform/Windows/platform_windows_files.cmake +++ b/Code/Framework/AzCore/Platform/Windows/platform_windows_files.cmake @@ -72,4 +72,6 @@ set(FILES AzCore/std/time_Windows.cpp ../Common/WinAPI/AzCore/Utils/Utils_WinAPI.cpp AzCore/Utils/Utils_Windows.cpp + AzCore/Debug/Profiler_Platform.inl + ../Common/WinAPI/AzCore/Debug/Profiler_WinAPI.inl ) diff --git a/Code/Framework/AzCore/Platform/iOS/AzCore/Debug/Profiler_Platform.inl b/Code/Framework/AzCore/Platform/iOS/AzCore/Debug/Profiler_Platform.inl new file mode 100644 index 0000000000..d453d1f645 --- /dev/null +++ b/Code/Framework/AzCore/Platform/iOS/AzCore/Debug/Profiler_Platform.inl @@ -0,0 +1,9 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include <../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl> diff --git a/Code/Framework/AzCore/Platform/iOS/platform_ios_files.cmake b/Code/Framework/AzCore/Platform/iOS/platform_ios_files.cmake index 81ee9bd09f..6d50d65160 100644 --- a/Code/Framework/AzCore/Platform/iOS/platform_ios_files.cmake +++ b/Code/Framework/AzCore/Platform/iOS/platform_ios_files.cmake @@ -67,4 +67,6 @@ set(FILES AzCore/Utils/Utils_iOS.mm ../Common/Apple/AzCore/Utils/Utils_Apple.cpp ../Common/UnixLike/AzCore/Utils/Utils_UnixLike.cpp + AzCore/Debug/Profiler_Platform.inl + ../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl )