From 191db77e4de274ce812ea261b84c321527567b9d Mon Sep 17 00:00:00 2001 From: Guthrie Adams Date: Mon, 24 Jan 2022 22:17:01 -0600 Subject: [PATCH] Atom Tools: Moved performance monitor system component from ME to ATF Moved the performance monitor system component and metrics gathering from the material editor into atom tools framework so it can be reused and extended by other applications. Replaced the custom performance monitor docked window in the material editor with status bar widgets that are always visible and take up no screen real estate. This could possibly be moved to the base application class or rendered on top of the viewport. Signed-off-by: Guthrie Adams --- .../PerformanceMonitor}/PerformanceMetrics.h | 7 +- .../PerformanceMonitorRequestBus.h | 13 +- .../Code/Source/AtomToolsFrameworkModule.cpp | 3 + .../PerformanceMonitorSystemComponent.cpp} | 99 +++++++------ .../PerformanceMonitorSystemComponent.h} | 29 ++-- .../Code/atomtoolsframework_files.cmake | 4 + .../Viewport/MaterialViewportModule.cpp | 11 +- .../Viewport/MaterialViewportWidget.cpp | 3 - .../Source/Window/MaterialEditorWindow.cpp | 46 +++++- .../Code/Source/Window/MaterialEditorWindow.h | 10 +- .../PerformanceMonitorWidget.cpp | 57 -------- .../PerformanceMonitorWidget.h | 44 ------ .../PerformanceMonitorWidget.ui | 133 ------------------ .../Code/materialeditor_files.cmake | 7 - 14 files changed, 136 insertions(+), 330 deletions(-) rename Gems/Atom/Tools/{MaterialEditor/Code/Source/Viewport => AtomToolsFramework/Code/Include/AtomToolsFramework/PerformanceMonitor}/PerformanceMetrics.h (82%) rename Gems/Atom/Tools/{MaterialEditor/Code/Source/Viewport => AtomToolsFramework/Code/Include/AtomToolsFramework/PerformanceMonitor}/PerformanceMonitorRequestBus.h (76%) rename Gems/Atom/Tools/{MaterialEditor/Code/Source/Viewport/PerformanceMonitorComponent.cpp => AtomToolsFramework/Code/Source/PerformanceMonitor/PerformanceMonitorSystemComponent.cpp} (66%) rename Gems/Atom/Tools/{MaterialEditor/Code/Source/Viewport/PerformanceMonitorComponent.h => AtomToolsFramework/Code/Source/PerformanceMonitor/PerformanceMonitorSystemComponent.h} (64%) delete mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.cpp delete mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.h delete mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.ui diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMetrics.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/PerformanceMonitor/PerformanceMetrics.h similarity index 82% rename from Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMetrics.h rename to Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/PerformanceMonitor/PerformanceMetrics.h index 12c5bc01d6..57d02d991c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMetrics.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/PerformanceMonitor/PerformanceMetrics.h @@ -5,6 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 OR MIT * */ + #pragma once #include @@ -12,9 +13,9 @@ #include #include -namespace MaterialEditor +namespace AtomToolsFramework { - //! Data structure containing performance metrics for Material Editor + //! Data structure containing performance metrics struct PerformanceMetrics final { AZ_CLASS_ALLOCATOR(PerformanceMetrics, AZ::SystemAllocator, 0); @@ -22,4 +23,4 @@ namespace MaterialEditor double m_cpuFrameTimeMs = 0; double m_gpuFrameTimeMs = 0; }; -} // namespace MaterialEditor +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMonitorRequestBus.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/PerformanceMonitor/PerformanceMonitorRequestBus.h similarity index 76% rename from Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMonitorRequestBus.h rename to Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/PerformanceMonitor/PerformanceMonitorRequestBus.h index 6001787d99..80cdf37a73 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMonitorRequestBus.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/PerformanceMonitor/PerformanceMonitorRequestBus.h @@ -5,16 +5,16 @@ * SPDX-License-Identifier: Apache-2.0 OR MIT * */ + #pragma once #include -#include +#include -namespace MaterialEditor +namespace AtomToolsFramework { //! Provides communication with Performance Monitor - class PerformanceMonitorRequests - : public AZ::EBusTraits + class PerformanceMonitorRequests : public AZ::EBusTraits { public: static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; @@ -23,11 +23,10 @@ namespace MaterialEditor //! Enable or disable CPU and GPU monitoring //! @param enabled whether performance monitoring should be enabled virtual void SetProfilerEnabled(bool enabled) = 0; - //! Gather performance metrics for the current frame - virtual void GatherMetrics() = 0; + //! Get current metrics virtual const PerformanceMetrics& GetMetrics() = 0; }; using PerformanceMonitorRequestBus = AZ::EBus; -} // namespace MaterialEditor +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AtomToolsFrameworkModule.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AtomToolsFrameworkModule.cpp index 865f12d904..978ac52cca 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AtomToolsFrameworkModule.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AtomToolsFrameworkModule.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace AtomToolsFramework @@ -20,6 +21,7 @@ namespace AtomToolsFramework AtomToolsFrameworkSystemComponent::CreateDescriptor(), AtomToolsDocumentSystemComponent::CreateDescriptor(), AtomToolsMainWindowSystemComponent::CreateDescriptor(), + PerformanceMonitorSystemComponent::CreateDescriptor(), PreviewRendererSystemComponent::CreateDescriptor(), }); } @@ -30,6 +32,7 @@ namespace AtomToolsFramework azrtti_typeid(), azrtti_typeid(), azrtti_typeid(), + azrtti_typeid(), azrtti_typeid(), }; } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMonitorComponent.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/PerformanceMonitor/PerformanceMonitorSystemComponent.cpp similarity index 66% rename from Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMonitorComponent.cpp rename to Gems/Atom/Tools/AtomToolsFramework/Code/Source/PerformanceMonitor/PerformanceMonitorSystemComponent.cpp index c8f12480b5..b1cca6c1ab 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMonitorComponent.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/PerformanceMonitor/PerformanceMonitorSystemComponent.cpp @@ -6,74 +6,44 @@ * */ -#include - #include #include #include +#include +#include -#include - -namespace MaterialEditor +namespace AtomToolsFramework { - void PerformanceMonitorComponent::Reflect(AZ::ReflectContext* context) - { - if (AZ::SerializeContext* serialize = azrtti_cast(context)) - { - serialize->Class() - ->Version(0); - } - } - - PerformanceMonitorComponent::PerformanceMonitorComponent() - { - } - - void PerformanceMonitorComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) + void PerformanceMonitorSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC_CE("PerformanceMonitorService")); } - void PerformanceMonitorComponent::Init() + void PerformanceMonitorSystemComponent::Reflect(AZ::ReflectContext* context) + { + if (AZ::SerializeContext* serialize = azrtti_cast(context)) + { + serialize->Class()->Version(0); + } + } + + void PerformanceMonitorSystemComponent::Init() { } - void PerformanceMonitorComponent::Activate() + void PerformanceMonitorSystemComponent::Activate() { + AZ::TickBus::Handler::BusConnect(); PerformanceMonitorRequestBus::Handler::BusConnect(); } - void PerformanceMonitorComponent::Deactivate() + void PerformanceMonitorSystemComponent::Deactivate() { PerformanceMonitorRequestBus::Handler::BusDisconnect(); + AZ::TickBus::Handler::BusDisconnect(); } - void PerformanceMonitorComponent::SetProfilerEnabled(bool enabled) - { - if (m_profilingEnabled == enabled) - { - return; - } - - AZ::RHI::Ptr rootPass = AZ::RPI::PassSystemInterface::Get()->GetRootPass(); - if (rootPass) - { - rootPass->SetTimestampQueryEnabled(enabled); - } - else - { - AZ_Error("PerformanceMonitorComponent", false, "Failed to find root pass."); - } - - if (enabled) - { - ResetStats(); - } - - m_profilingEnabled = enabled; - } - - void PerformanceMonitorComponent::GatherMetrics() + void PerformanceMonitorSystemComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time) { if (!m_profilingEnabled) { @@ -103,21 +73,46 @@ namespace MaterialEditor } } - const PerformanceMetrics& PerformanceMonitorComponent::GetMetrics() + void PerformanceMonitorSystemComponent::SetProfilerEnabled(bool enabled) + { + if (m_profilingEnabled == enabled) + { + return; + } + + AZ::RHI::Ptr rootPass = AZ::RPI::PassSystemInterface::Get()->GetRootPass(); + if (rootPass) + { + rootPass->SetTimestampQueryEnabled(enabled); + } + else + { + AZ_Error("PerformanceMonitorSystemComponent", false, "Failed to find root pass."); + } + + if (enabled) + { + ResetStats(); + } + + m_profilingEnabled = enabled; + } + + const PerformanceMetrics& PerformanceMonitorSystemComponent::GetMetrics() { UpdateMetrics(); return m_metrics; } - void PerformanceMonitorComponent::UpdateMetrics() + void PerformanceMonitorSystemComponent::UpdateMetrics() { m_metrics.m_cpuFrameTimeMs = m_cpuFrameTimeMs.GetAverage(); m_metrics.m_gpuFrameTimeMs = m_gpuFrameTimeMs.GetAverage(); } - void PerformanceMonitorComponent::ResetStats() + void PerformanceMonitorSystemComponent::ResetStats() { m_cpuFrameTimeMs.Reset(); m_gpuFrameTimeMs.Reset(); } -} +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMonitorComponent.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/PerformanceMonitor/PerformanceMonitorSystemComponent.h similarity index 64% rename from Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMonitorComponent.h rename to Gems/Atom/Tools/AtomToolsFramework/Code/Source/PerformanceMonitor/PerformanceMonitorSystemComponent.h index 3045bf9533..2cc336f07c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/PerformanceMonitorComponent.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/PerformanceMonitor/PerformanceMonitorSystemComponent.h @@ -10,25 +10,26 @@ #include #include +#include #include -#include +#include -namespace MaterialEditor +namespace AtomToolsFramework { - //! PerformanceMonitorComponent monitors performance within Material Editor - class PerformanceMonitorComponent + //! PerformanceMonitorSystemComponent monitors performance + class PerformanceMonitorSystemComponent : public AZ::Component , private PerformanceMonitorRequestBus::Handler + , private AZ::TickBus::Handler { public: - AZ_COMPONENT(PerformanceMonitorComponent, "{C2F54D1B-A106-4922-82BE-ACB7A168D4AF}"); - - static void Reflect(AZ::ReflectContext* context); - - PerformanceMonitorComponent(); - ~PerformanceMonitorComponent() = default; + AZ_COMPONENT(PerformanceMonitorSystemComponent, "{C2F54D1B-A106-4922-82BE-ACB7A168D4AF}"); static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided); + static void Reflect(AZ::ReflectContext* context); + + PerformanceMonitorSystemComponent() = default; + ~PerformanceMonitorSystemComponent() = default; private: // AZ::Component overrides... @@ -36,9 +37,11 @@ namespace MaterialEditor void Activate() override; void Deactivate() override; - // PerformanceMonitorRequestBus::Handler interface overrides... + // AZ::TickBus::Handler overrides... + void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; + + // PerformanceMonitorRequestBus::Handler overrides... void SetProfilerEnabled(bool enabled) override; - void GatherMetrics() override; const PerformanceMetrics& GetMetrics() override; void UpdateMetrics(); @@ -55,4 +58,4 @@ namespace MaterialEditor static constexpr int SampleCount = 10; int m_sample = 0; }; -} +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake index db20452036..1dbfb7b686 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake @@ -28,6 +28,8 @@ set(FILES Include/AtomToolsFramework/Inspector/InspectorGroupWidget.h Include/AtomToolsFramework/Inspector/InspectorGroupHeaderWidget.h Include/AtomToolsFramework/Inspector/InspectorPropertyGroupWidget.h + Include/AtomToolsFramework/PerformanceMonitor/PerformanceMetrics.h + Include/AtomToolsFramework/PerformanceMonitor/PerformanceMonitorRequestBus.h Include/AtomToolsFramework/Util/MaterialPropertyUtil.h Include/AtomToolsFramework/Util/Util.h Include/AtomToolsFramework/Viewport/RenderViewportWidget.h @@ -61,6 +63,8 @@ set(FILES Source/Inspector/InspectorGroupWidget.cpp Source/Inspector/InspectorGroupHeaderWidget.cpp Source/Inspector/InspectorPropertyGroupWidget.cpp + Source/PerformanceMonitor/PerformanceMonitorSystemComponent.cpp + Source/PerformanceMonitor/PerformanceMonitorSystemComponent.h Source/Util/MaterialPropertyUtil.cpp Source/Util/Util.cpp Source/Viewport/RenderViewportWidget.cpp diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportModule.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportModule.cpp index 01a13519fb..5467a2607c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportModule.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportModule.cpp @@ -8,16 +8,16 @@ #include #include -#include namespace MaterialEditor { MaterialViewportModule::MaterialViewportModule() { // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here. - m_descriptors.insert(m_descriptors.end(), { - MaterialViewportComponent::CreateDescriptor(), - PerformanceMonitorComponent::CreateDescriptor(), + m_descriptors.insert( + m_descriptors.end(), + { + MaterialViewportComponent::CreateDescriptor(), }); } @@ -25,7 +25,6 @@ namespace MaterialEditor { return AZ::ComponentTypeList{ azrtti_typeid(), - azrtti_typeid(), }; } -} +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportWidget.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportWidget.cpp index dd157c59ac..21b01b5dab 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportWidget.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportWidget.cpp @@ -50,7 +50,6 @@ #include #include #include -#include #include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT @@ -462,8 +461,6 @@ namespace MaterialEditor m_renderPipeline->AddToRenderTickOnce(); - PerformanceMonitorRequestBus::Broadcast(&PerformanceMonitorRequestBus::Handler::GatherMetrics); - if (m_shadowCatcherMaterial) { // Compile the m_shadowCatcherMaterial in OnTick because changes can only be compiled once per frame. diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp index d538f62e15..49356e6735 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -19,7 +20,6 @@ #include #include #include -#include #include #include @@ -30,6 +30,7 @@ AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnin #include #include #include +#include #include #include AZ_POP_DISABLE_WARNING @@ -95,10 +96,7 @@ namespace MaterialEditor AddDockWidget("Inspector", new MaterialInspector, Qt::RightDockWidgetArea, Qt::Vertical); AddDockWidget("Viewport Settings", new ViewportSettingsInspector, Qt::LeftDockWidgetArea, Qt::Vertical); - AddDockWidget("Performance Monitor", new PerformanceMonitorWidget, Qt::BottomDockWidgetArea, Qt::Horizontal); - SetDockWidgetVisible("Viewport Settings", false); - SetDockWidgetVisible("Performance Monitor", false); // Restore geometry and show the window mainWindowWrapper->showFromSettings(); @@ -114,6 +112,14 @@ namespace MaterialEditor } OnDocumentOpened(AZ::Uuid::CreateNull()); + + SetupMetrics(); + } + + MaterialEditorWindow::~MaterialEditorWindow() + { + AtomToolsFramework::PerformanceMonitorRequestBus::Broadcast( + &AtomToolsFramework::PerformanceMonitorRequestBus::Handler::SetProfilerEnabled, false); } void MaterialEditorWindow::ResizeViewportRenderTarget(uint32_t width, uint32_t height) @@ -207,6 +213,38 @@ namespace MaterialEditor Base::closeEvent(closeEvent); } + + void MaterialEditorWindow::SetupMetrics() + { + m_statusBarCpuTime = new QLabel(this); + statusBar()->addPermanentWidget(m_statusBarCpuTime); + m_statusBarGpuTime = new QLabel(this); + statusBar()->addPermanentWidget(m_statusBarGpuTime); + m_statusBarFps = new QLabel(this); + statusBar()->addPermanentWidget(m_statusBarFps); + + static constexpr int UpdateIntervalMs = 1000; + m_metricsTimer.setInterval(UpdateIntervalMs); + m_metricsTimer.start(); + connect(&m_metricsTimer, &QTimer::timeout, this, &MaterialEditorWindow::UpdateMetrics); + + AtomToolsFramework::PerformanceMonitorRequestBus::Broadcast( + &AtomToolsFramework::PerformanceMonitorRequestBus::Handler::SetProfilerEnabled, true); + + UpdateMetrics(); + } + + void MaterialEditorWindow::UpdateMetrics() + { + AtomToolsFramework::PerformanceMetrics metrics = {}; + AtomToolsFramework::PerformanceMonitorRequestBus::BroadcastResult( + metrics, &AtomToolsFramework::PerformanceMonitorRequestBus::Handler::GetMetrics); + + m_statusBarCpuTime->setText(tr("CPU Time %1 ms").arg(QString::number(metrics.m_cpuFrameTimeMs, 'f', 2))); + m_statusBarGpuTime->setText(tr("GPU Time %1 ms").arg(QString::number(metrics.m_gpuFrameTimeMs, 'f', 2))); + int frameRate = metrics.m_cpuFrameTimeMs > 0 ? aznumeric_cast(1000 / metrics.m_cpuFrameTimeMs) : 0; + m_statusBarFps->setText(tr("FPS %1").arg(QString::number(frameRate))); + } } // namespace MaterialEditor #include diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h index 8317382d6d..3cf08e0374 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h @@ -14,6 +14,7 @@ AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT #include #include +#include AZ_POP_DISABLE_WARNING #endif @@ -33,7 +34,7 @@ namespace MaterialEditor using Base = AtomToolsFramework::AtomToolsDocumentMainWindow; MaterialEditorWindow(QWidget* parent = 0); - ~MaterialEditorWindow() = default; + ~MaterialEditorWindow(); protected: void ResizeViewportRenderTarget(uint32_t width, uint32_t height) override; @@ -48,7 +49,14 @@ namespace MaterialEditor void closeEvent(QCloseEvent* closeEvent) override; + void SetupMetrics(); + void UpdateMetrics(); + MaterialViewportWidget* m_materialViewport = {}; MaterialEditorToolBar* m_toolBar = {}; + QLabel* m_statusBarFps = {}; + QLabel* m_statusBarCpuTime = {}; + QLabel* m_statusBarGpuTime = {}; + QTimer m_metricsTimer; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.cpp deleted file mode 100644 index 8492ce5f1f..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 - * - */ - -#include -#include -#include - -#include - -namespace MaterialEditor -{ - PerformanceMonitorWidget::PerformanceMonitorWidget(QWidget* parent) - : QWidget(parent) - , m_ui(new Ui::PerformanceMonitorWidget) - { - m_ui->setupUi(this); - - - m_updateTimer.setInterval(UpdateIntervalMs); - connect(&m_updateTimer, &QTimer::timeout, this, &PerformanceMonitorWidget::UpdateMetrics); - } - - PerformanceMonitorWidget::~PerformanceMonitorWidget() = default; - - void PerformanceMonitorWidget::showEvent(QShowEvent* event) - { - QWidget::showEvent(event); - - m_updateTimer.start(); - PerformanceMonitorRequestBus::Broadcast(&PerformanceMonitorRequestBus::Handler::SetProfilerEnabled, true); - } - - void PerformanceMonitorWidget::hideEvent(QHideEvent* event) - { - QWidget::hideEvent(event); - - m_updateTimer.stop(); - PerformanceMonitorRequestBus::Broadcast(&PerformanceMonitorRequestBus::Handler::SetProfilerEnabled, false); - } - - void PerformanceMonitorWidget::UpdateMetrics() - { - PerformanceMetrics metrics; - PerformanceMonitorRequestBus::BroadcastResult(metrics, &PerformanceMonitorRequestBus::Handler::GetMetrics); - m_ui->m_cpuFrameTimeValue->setText(QString("%1 ms").arg(QString::number(metrics.m_cpuFrameTimeMs, 'f', 2))); - m_ui->m_gpuFrameTimeValue->setText(QString("%1 ms").arg(QString::number(metrics.m_gpuFrameTimeMs, 'f', 2))); - int frameRate = metrics.m_cpuFrameTimeMs > 0 ? aznumeric_cast(1000 / metrics.m_cpuFrameTimeMs) : 0; - m_ui->m_frameRateValue->setText(QString::number(frameRate)); - } -} // namespace MaterialEditor - -#include diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.h deleted file mode 100644 index 1570d61aa3..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 -#include - -namespace Ui -{ - class PerformanceMonitorWidget; -} - -namespace MaterialEditor -{ - //! Displays performance metrics for Material Editor - class PerformanceMonitorWidget - : public QWidget - { - Q_OBJECT - public: - PerformanceMonitorWidget(QWidget* parent = nullptr); - ~PerformanceMonitorWidget(); - - private slots: - void UpdateMetrics(); - - private: - void showEvent(QShowEvent* event) override; - void hideEvent(QHideEvent* event) override; - - QScopedPointer m_ui; - QTimer m_updateTimer; - - - //! interval to request performance metrics - static constexpr int UpdateIntervalMs = 1000; - }; -} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.ui b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.ui deleted file mode 100644 index 776ce79a87..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/PerformanceMonitor/PerformanceMonitorWidget.ui +++ /dev/null @@ -1,133 +0,0 @@ - - - PerformanceMonitorWidget - - - - 0 - 0 - 237 - 200 - - - - - 200 - 200 - - - - Performance Monitor - - - - - - - - Frame Rate: - - - - - - - 0 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - CPU Frame Time: - - - - - - - 0 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - GPU Frame Time: - - - - - - - 0 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 67 - - - - - - - - - diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake index f062246413..4e270460a6 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake @@ -23,8 +23,6 @@ set(FILES Source/Viewport/MaterialViewportSettings.h Source/Viewport/MaterialViewportRequestBus.h Source/Viewport/MaterialViewportNotificationBus.h - Source/Viewport/PerformanceMetrics.h - Source/Viewport/PerformanceMonitorRequestBus.h Source/Viewport/InputController/MaterialEditorViewportInputController.cpp Source/Viewport/InputController/MaterialEditorViewportInputController.h Source/Viewport/InputController/Behavior.cpp @@ -49,8 +47,6 @@ set(FILES Source/Viewport/MaterialViewportWidget.cpp Source/Viewport/MaterialViewportWidget.h Source/Viewport/MaterialViewportWidget.ui - Source/Viewport/PerformanceMonitorComponent.cpp - Source/Viewport/PerformanceMonitorComponent.h Source/Window/MaterialEditorWindowSettings.h Source/Window/MaterialEditorBrowserInteractions.h @@ -67,9 +63,6 @@ set(FILES Source/Window/CreateMaterialDialog/CreateMaterialDialog.cpp Source/Window/CreateMaterialDialog/CreateMaterialDialog.h Source/Window/CreateMaterialDialog/CreateMaterialDialog.ui - Source/Window/PerformanceMonitor/PerformanceMonitorWidget.cpp - Source/Window/PerformanceMonitor/PerformanceMonitorWidget.h - Source/Window/PerformanceMonitor/PerformanceMonitorWidget.ui Source/Window/ToolBar/MaterialEditorToolBar.h Source/Window/ToolBar/MaterialEditorToolBar.cpp Source/Window/ToolBar/ModelPresetComboBox.h