/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #pragma once #include #include #include namespace AZ { namespace RPI { class Pass; } namespace Render { //! Helper class that executes a function when a certain amount of frames have passed. class DelayedQueryCaptureHelper { using CaptureCallback = AZStd::function; enum DelayedCaptureState { Idle, Pending }; // Wait 6 frames before calling the callback. const uint32_t FrameThreshold = 6u; public: //! Starts a delayed capture. bool StartCapture(CaptureCallback&& saveCallback); //! Decrements the threshold value, and executes the functor when the threshold reaches 0. void UpdateCapture(); //! Returns whether the state is idle. bool IsIdle() const; private: uint32_t m_frameThreshold = 0u; DelayedCaptureState m_state = DelayedCaptureState::Idle; CaptureCallback m_captureCallback; }; //! System component to handle ProfilingCaptureSystemComponent. class ProfilingCaptureSystemComponent final : public AZ::Component , public ProfilingCaptureRequestBus::Handler , public AZ::TickBus::Handler { public: AZ_COMPONENT(ProfilingCaptureSystemComponent, "{B715C113-E697-41D3-87BF-27D0ED1055BA}"); static void Reflect(AZ::ReflectContext* context); void Activate() override; void Deactivate() override; // ProfilingCaptureRequestBus overrides... bool CapturePassTimestamp(const AZStd::string& outputFilePath) override; bool CapturePassPipelineStatistics(const AZStd::string& outputFilePath) override; bool CaptureCpuProfilingStatistics(const AZStd::string& outputFilePath) override; private: void OnTick(float deltaTime, ScriptTimePoint time) override; // Recursively collect all the passes from the root pass. AZStd::vector CollectPassesRecursively(const RPI::Pass* root) const; AZStd::vector FindPasses(AZStd::vector&& passHierarchy) const; DelayedQueryCaptureHelper m_timestampCapture; DelayedQueryCaptureHelper m_pipelineStatisticsCapture; DelayedQueryCaptureHelper m_cpuProfilingStatisticsCapture; }; } }