db63dcbcd9
* Implement sync interval and refresh rate API for RenderViewportWidget Signed-off-by: nvsickle <nvsickle@amazon.com> * Measure actual frame timings in the viewport info overlay. Takes the median of the sum of (frame end - frame begin) to provide more a more representative view of when frames begin and end. Note: Until VSync is internally supported by the event loop, this will produce nearly identical frame timings as the frame will spend as much time as needed synchronously waiting on a vblank. Signed-off-by: nvsickle <nvsickle@amazon.com> * Make frame timing per-pipeline, wire up refresh rate info to ViewportContext Signed-off-by: nvsickle <nvsickle@amazon.com> * POC: Frame limit pipeline rendering Signed-off-by: nvsickle <nvsickle@amazon.com> * Switch Editor tick to every 0ms to allow better tick accumulation behavior Signed-off-by: nvsickle <nvsickle@amazon.com> * Move RPISystemComponent to the tick bus, remove tick accumulation logic Signed-off-by: nvsickle <nvsickle@amazon.com> * Add `AddToRenderTickAtInterval` to RenderPipeline API This allows a pipeline to update at a set cadence, instead of rendering every frame or being directly told when to tick. Signed-off-by: nvsickle <nvsickle@amazon.com> * Make ViewportContext enforce a target framerate -Adds GetFpsLimit/SetFpsLimit for actively limiting FPS -Calculates a render tick interval based on vsync and the vps limit and updates the current pipeline Signed-off-by: nvsickle <nvsickle@amazon.com> * Add r_fps_limit and ed_inactive_viewport_fps_limit cvars Signed-off-by: nvsickle <nvsickle@amazon.com> * Quick null check from a crash I bumped into Signed-off-by: nvsickle <nvsickle@amazon.com> * Fix off-by-one on FPS calculation (shouldn't include the not-yet-rendered frame) Signed-off-by: nvsickle <nvsickle@amazon.com> * Clarify frame time begin initialization Signed-off-by: nvsickle <nvsickle@amazon.com> * Fix TrackView export. Signed-off-by: nvsickle <nvsickle@amazon.com> * Address some reviewer feedback, revert RPISystem API change, fix CPU profiler. Signed-off-by: nvsickle <nvsickle@amazon.com> * Add g_simulation_tick_rate Signed-off-by: nvsickle <nvsickle@amazon.com> * Address review feedback, make frame limit updates event driven Signed-off-by: nvsickle <nvsickle@amazon.com> * Remove timestamp update from ComponentApplication::Tick Signed-off-by: nvsickle <nvsickle@amazon.com>
90 lines
3.4 KiB
C++
90 lines
3.4 KiB
C++
/*
|
|
* 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.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
#pragma once
|
|
|
|
#include <AzCore/Component/Component.h>
|
|
|
|
#include <CryCommon/CrySystemBus.h>
|
|
#include <AzCore/Script/ScriptTimePoint.h>
|
|
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
|
|
#include <AzFramework/Font/FontInterface.h>
|
|
#include <Atom/RPI.Public/Base.h>
|
|
#include <Atom/RPI.Public/ViewportContextBus.h>
|
|
#include <AtomLyIntegration/AtomViewportDisplayInfo/AtomViewportInfoDisplayBus.h>
|
|
|
|
namespace AZ
|
|
{
|
|
class TickRequests;
|
|
|
|
namespace Render
|
|
{
|
|
class AtomViewportDisplayInfoSystemComponent
|
|
: public AZ::Component
|
|
, public AZ::RPI::ViewportContextNotificationBus::Handler
|
|
, public AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Handler
|
|
{
|
|
public:
|
|
AZ_COMPONENT(AtomViewportDisplayInfoSystemComponent, "{AC32F173-E7E2-4943-8E6C-7C3091978221}");
|
|
|
|
static void Reflect(AZ::ReflectContext* context);
|
|
|
|
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
|
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
|
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
|
|
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
|
|
|
|
protected:
|
|
// AZ::Component overrides...
|
|
void Activate() override;
|
|
void Deactivate() override;
|
|
|
|
// AZ::RPI::ViewportContextNotificationBus::Handler overrides...
|
|
void OnRenderTick() override;
|
|
void OnFrameEnd() override;
|
|
|
|
// AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Handler overrides...
|
|
AtomBridge::ViewportInfoDisplayState GetDisplayState() const override;
|
|
void SetDisplayState(AtomBridge::ViewportInfoDisplayState state) override;
|
|
|
|
private:
|
|
AZ::RPI::ViewportContextPtr GetViewportContext() const;
|
|
void DrawLine(AZStd::string_view line, AZ::Color color = AZ::Colors::White);
|
|
|
|
void UpdateFramerate();
|
|
|
|
void DrawRendererInfo();
|
|
void DrawCameraInfo();
|
|
void DrawPassInfo();
|
|
void DrawFramerate();
|
|
|
|
void UpdateScene(AZ::RPI::ScenePtr scene);
|
|
|
|
static constexpr float BaseFontSize = 0.7f;
|
|
|
|
AZStd::string m_rendererDescription;
|
|
AzFramework::TextDrawParameters m_drawParams;
|
|
AzFramework::FontDrawInterface* m_fontDrawInterface = nullptr;
|
|
float m_lineSpacing;
|
|
AZStd::chrono::duration<double> m_fpsInterval = AZStd::chrono::seconds(1);
|
|
struct FrameTimingInfo
|
|
{
|
|
AZStd::chrono::system_clock::time_point m_beginFrameTime;
|
|
AZStd::optional<AZStd::chrono::system_clock::time_point> m_endFrameTime;
|
|
|
|
explicit FrameTimingInfo(AZStd::chrono::system_clock::time_point beginFrameTime)
|
|
: m_beginFrameTime(beginFrameTime)
|
|
{
|
|
}
|
|
};
|
|
AZStd::deque<FrameTimingInfo> m_fpsHistory;
|
|
AZStd::optional<AZStd::chrono::system_clock::time_point> m_lastMemoryUpdate;
|
|
bool m_updateRootPassQuery = true;
|
|
};
|
|
} // namespace Render
|
|
} // namespace AZ
|