AtomSampleViewerSystemComponent.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <AzCore/Component/Component.h>
  10. #include <AzCore/Component/TickBus.h>
  11. #include <AzCore/RTTI/RTTI.h>
  12. #include <AzCore/Component/EntityBus.h>
  13. #include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
  14. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  15. #include <CrySystemBus.h>
  16. namespace AtomSampleViewer
  17. {
  18. using HighResTimer = AZStd::chrono::high_resolution_clock;
  19. class AtomSampleViewerSystemComponent final
  20. : public AZ::Component
  21. , public AZ::TickBus::Handler
  22. , public AZ::EntitySystemBus::Handler
  23. , protected CrySystemEventBus::Handler
  24. {
  25. public:
  26. AZ_COMPONENT(AtomSampleViewerSystemComponent, "{714873AD-70FC-47A8-A609-46103CB8DABA}");
  27. static void Reflect(AZ::ReflectContext* context);
  28. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  29. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  30. AtomSampleViewerSystemComponent();
  31. ~AtomSampleViewerSystemComponent() override;
  32. void Activate() override;
  33. void Deactivate() override;
  34. // AZ::EntitySystemBus::Handler
  35. void OnEntityDestroyed(const AZ::EntityId& entityId) override;
  36. // AZ::TickBus::Handler
  37. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  38. // CrySystemEventBus::Handler
  39. void OnCrySystemInitialized(ISystem& system, const SSystemInitParams&) override;
  40. private:
  41. void TrackPerfMetrics(const float deltaTime);
  42. void LogPerfMetrics() const;
  43. struct PerfMetrics
  44. {
  45. AZ_CLASS_ALLOCATOR(PerfMetrics, AZ::SystemAllocator, 0);
  46. AZ_TYPE_INFO(PerfMetrics, "{D333FB60-DC06-42CF-9124-B1EF90690A16}");
  47. static void Reflect(AZ::ReflectContext* context);
  48. virtual ~PerfMetrics() = default;
  49. float m_averageDeltaSeconds = 0.0f;
  50. float m_timeToFirstRenderSeconds = 0.0f;
  51. float m_timingTargetSeconds = 10.0f;
  52. };
  53. AZStd::chrono::time_point<HighResTimer> m_timestamp;
  54. float m_accumulatedDeltaSeconds = 0.0f;
  55. uint32_t m_frameCount = 0;
  56. bool m_testsLogged = false;
  57. PerfMetrics m_perfMetrics;
  58. AZ::Entity* m_atomSampleViewerEntity = nullptr;
  59. AZStd::vector<AZ::Name> m_passesToRemove;
  60. void ReadTimeoutShutdown();
  61. void TickTimeoutShutdown(float deltaTimeInSeconds);
  62. float m_secondsBeforeShutdown = 0.f; // >0.f If timeout shutdown is enabled, this will count down the time until quit() is called.
  63. };
  64. } // namespace AtomSampleViewer