AtomSampleViewerSystemComponent.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #pragma once
  13. #include <AzCore/Component/Component.h>
  14. #include <AzCore/Component/TickBus.h>
  15. #include <AzCore/RTTI/RTTI.h>
  16. #include <AzCore/Component/EntityBus.h>
  17. #include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
  18. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  19. #include <CrySystemBus.h>
  20. namespace AtomSampleViewer
  21. {
  22. using HighResTimer = AZStd::chrono::high_resolution_clock;
  23. class AtomSampleViewerSystemComponent final
  24. : public AZ::Component
  25. , public AZ::TickBus::Handler
  26. , public AZ::EntitySystemBus::Handler
  27. , protected CrySystemEventBus::Handler
  28. {
  29. public:
  30. AZ_COMPONENT(AtomSampleViewerSystemComponent, "{714873AD-70FC-47A8-A609-46103CB8DABA}");
  31. static void Reflect(AZ::ReflectContext* context);
  32. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  33. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  34. AtomSampleViewerSystemComponent();
  35. ~AtomSampleViewerSystemComponent() override;
  36. void Activate() override;
  37. void Deactivate() override;
  38. // AZ::EntitySystemBus::Handler
  39. void OnEntityDestroyed(const AZ::EntityId& entityId) override;
  40. // AZ::TickBus::Handler
  41. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  42. // CrySystemEventBus::Handler
  43. void OnCrySystemInitialized(ISystem& system, const SSystemInitParams&) override;
  44. private:
  45. void TrackPerfMetrics(const float deltaTime);
  46. void LogPerfMetrics() const;
  47. struct PerfMetrics
  48. {
  49. AZ_CLASS_ALLOCATOR(PerfMetrics, AZ::SystemAllocator, 0);
  50. AZ_TYPE_INFO(PerfMetrics, "{D333FB60-DC06-42CF-9124-B1EF90690A16}");
  51. static void Reflect(AZ::ReflectContext* context);
  52. virtual ~PerfMetrics() = default;
  53. float m_averageDeltaSeconds = 0.0f;
  54. float m_timeToFirstRenderSeconds = 0.0f;
  55. float m_timingTargetSeconds = 10.0f;
  56. };
  57. AZStd::chrono::time_point<HighResTimer> m_timestamp;
  58. float m_accumulatedDeltaSeconds = 0.0f;
  59. uint32_t m_frameCount = 0;
  60. bool m_testsLogged = false;
  61. PerfMetrics m_perfMetrics;
  62. AZ::Entity* m_atomSampleViewerEntity = nullptr;
  63. AZStd::vector<AZ::Name> m_passesToRemove;
  64. void ReadTimeoutShutdown();
  65. void TickTimeoutShutdown(float deltaTimeInSeconds);
  66. float m_secondsBeforeShutdown = 0.f; // >0.f If timeout shutdown is enabled, this will count down the time until quit() is called.
  67. };
  68. } // namespace AtomSampleViewer