BistroBenchmarkComponent.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * 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.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <CommonSampleComponentBase.h>
  9. #include <AtomCore/Instance/InstanceId.h>
  10. #include <AzCore/Component/TickBus.h>
  11. #include <AzCore/Math/Vector3.h>
  12. #include <AzCore/std/string/string_view.h>
  13. #include <Atom/Feature/CoreLights/DirectionalLightFeatureProcessorInterface.h>
  14. #include <Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h>
  15. #include <Utils/Utils.h>
  16. struct ImGuiContext;
  17. namespace AtomSampleViewer
  18. {
  19. class BistroBenchmarkComponent final
  20. : public CommonSampleComponentBase
  21. , public AZ::TickBus::Handler
  22. , public AZ::Data::AssetBus::MultiHandler
  23. {
  24. public:
  25. AZ_COMPONENT(BistroBenchmarkComponent, "{2AFFAA6B-1795-4635-AFAD-C2A98163832F}", CommonSampleComponentBase);
  26. static void Reflect(AZ::ReflectContext* context);
  27. BistroBenchmarkComponent() = default;
  28. ~BistroBenchmarkComponent() override = default;
  29. //AZ::Component
  30. void Activate() override;
  31. void Deactivate() override;
  32. private:
  33. // AZ::TickBus::Handler
  34. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  35. // AZ::Data::AssetBus::Handler
  36. void OnAssetReady(AZ::Data::Asset<AZ::Data::AssetData> asset);
  37. void BenchmarkLoadStart();
  38. void FinalizeLoadBenchmarkData();
  39. void BenchmarkLoadEnd();
  40. void BenchmarkRunStart();
  41. void CollectRunBenchmarkData(float deltaTime, AZ::ScriptTimePoint timePoint);
  42. void FinalizeRunBenchmarkData();
  43. void BenchmarkRunEnd();
  44. void DisplayLoadingDialog();
  45. void DisplayResults();
  46. struct LoadBenchmarkData
  47. {
  48. AZ_TYPE_INFO(LoadBenchmarkData, "{8677FEAB-EBA6-468A-97CB-AAF1B16F5FE2}");
  49. static void Reflect(AZ::ReflectContext* context);
  50. struct FileLoadedData
  51. {
  52. AZ_TYPE_INFO(FileLoadedData, "{F4E5728D-C526-4C28-83BA-D4B07DC894E8}");
  53. static void Reflect(AZ::ReflectContext* context);
  54. AZStd::string m_relativePath;
  55. AZ::u64 m_bytesLoaded = 0;
  56. };
  57. AZStd::string m_name = "";
  58. double m_timeInSeconds = 0.0;
  59. double m_totalMBLoaded = 0.0;
  60. double m_mbPerSec = 0.0;
  61. AZ::u64 m_numFilesLoaded = 0;
  62. AZStd::vector<FileLoadedData> m_filesLoaded;
  63. };
  64. AZStd::vector<AZ::Data::AssetId> m_trackedAssets;
  65. struct RunBenchmarkData
  66. {
  67. AZ_TYPE_INFO(RunBenchmarkData, "{45FFA85B-1224-4558-B833-3D8A4404041C}");
  68. static void Reflect(AZ::ReflectContext* context);
  69. AZStd::string m_name;
  70. AZStd::vector<float> m_frameTimes; // not serialized
  71. AZStd::vector<float> m_frameRates; // not serialized
  72. AZ::u64 m_frameCount;
  73. double m_timeInSeconds = 0.0;
  74. double m_timeToFirstFrame = 0.0;
  75. double m_averageFrameTime = 0.0;
  76. float m_50pFramesUnder = 0.0f;
  77. float m_90pFramesUnder = 0.0f;
  78. float m_minFrameTime = FLT_MAX;
  79. float m_maxFrameTime = FLT_MIN;
  80. float m_averageFrameRate = 0.0;
  81. float m_minFrameRate = FLT_MAX;
  82. float m_maxFrameRate = FLT_MIN;
  83. };
  84. double m_currentTimePointInSeconds = 0.0;
  85. double m_benchmarkStartTimePoint = 0.0;
  86. double m_timeToFirstFrame = 0.0;
  87. LoadBenchmarkData m_currentLoadBenchmarkData;
  88. RunBenchmarkData m_currentRunBenchmarkData;
  89. struct CameraPathPoint
  90. {
  91. AZ::u64 m_framePoint;
  92. AZ::Vector3 m_position;
  93. AZ::Vector3 m_target;
  94. AZ::Vector3 m_up;
  95. };
  96. using CameraPath = AZStd::vector<CameraPathPoint>;
  97. const CameraPath m_exteriorPath = {
  98. {0, AZ::Vector3(8.0f, 0.0, 3.0f), AZ::Vector3(-100.0f, 0.0f, 10.0f), AZ::Vector3(0.0f, 0.0f, 1.0f)},
  99. {10000, AZ::Vector3(-8.0f, 0.0, 3.0f), AZ::Vector3(-100.0f, 0.0f, 10.0f), AZ::Vector3(0.0f, 0.0f, 1.0f)},
  100. };
  101. bool m_firstResultsDisplay = true;
  102. bool m_startBenchmarkCapture = true;
  103. bool m_endBenchmarkCapture = true;
  104. AZ::u64 m_frameCount = 0;
  105. CameraPathPoint m_currentCameraPoint;
  106. CameraPathPoint m_lastCameraPoint;
  107. AZ::Data::Asset<AZ::RPI::ModelAsset> m_sponzaExteriorAsset;
  108. AZ::Data::Asset<AZ::RPI::ModelAsset> m_sponzaInteriorAsset;
  109. using MeshHandle = AZ::Render::MeshFeatureProcessorInterface::MeshHandle;
  110. MeshHandle m_sponzaExteriorMeshHandle;
  111. MeshHandle m_sponzaInteriorMeshHandle;
  112. Utils::DefaultIBL m_defaultIbl;
  113. bool m_sponzaExteriorLoaded = false;
  114. bool m_sponzaInteriorLoaded = false;
  115. AZ::Component* m_cameraControlComponent = nullptr;
  116. AZStd::vector<uint64_t> m_framesToCapture;
  117. AZStd::string m_screenshotFolder;
  118. // Lights
  119. AZ::Render::DirectionalLightFeatureProcessorInterface* m_directionalLightFeatureProcessor = nullptr;
  120. AZ::Render::DirectionalLightFeatureProcessorInterface::LightHandle m_directionalLightHandle;
  121. AZ::Render::SkyBoxFeatureProcessorInterface* m_skyboxFeatureProcessor = nullptr;
  122. };
  123. } // namespace AtomSampleViewer