SponzaBenchmarkComponent.h 5.4 KB

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