a95c609bd8
This change is a preparation for moving the CPU profiler/visualization system from Atom into its own Gem by removing the dependency on local time tracking object AZ::RHI::CpuTimingStatistics Full changes include: - Removed all usage of AZ::RHI::CpuTimingStatistics -- Replaced with pushing to AZ::Statistics::StatisticalProfilerProxy global instance - Promoted VariableTimer from AZ::RHI to AZ::Debug - Removed now unused CpuTimingStatistics.h Signed-off-by: AMZN-ScottR 24445312+AMZN-ScottR@users.noreply.github.com
133 lines
4.8 KiB
C++
133 lines
4.8 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
|
|
*
|
|
*/
|
|
|
|
#include <AtomImGuiToolsSystemComponent.h>
|
|
|
|
#include <AzCore/Serialization/SerializeContext.h>
|
|
#include <AzCore/Serialization/EditContext.h>
|
|
#include <AzCore/Serialization/EditContextConstants.inl>
|
|
#include <Atom/RPI.Public/Pass/PassSystemInterface.h>
|
|
#include <AzFramework/Components/ConsoleBus.h>
|
|
|
|
namespace AtomImGuiTools
|
|
{
|
|
void AtomImGuiToolsSystemComponent::Reflect(AZ::ReflectContext* context)
|
|
{
|
|
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
|
|
{
|
|
serialize->Class<AtomImGuiToolsSystemComponent, AZ::Component>()
|
|
->Version(0)
|
|
;
|
|
|
|
if (AZ::EditContext* ec = serialize->GetEditContext())
|
|
{
|
|
ec->Class<AtomImGuiToolsSystemComponent>("AtomImGuiTools", "[Manager of various Atom ImGui tools.]")
|
|
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
|
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
|
|
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
|
;
|
|
}
|
|
}
|
|
}
|
|
|
|
void AtomImGuiToolsSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
|
|
{
|
|
provided.push_back(AZ_CRC("AtomImGuiToolsService"));
|
|
}
|
|
|
|
void AtomImGuiToolsSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
|
{
|
|
incompatible.push_back(AZ_CRC("AtomImGuiToolsService"));
|
|
}
|
|
|
|
void AtomImGuiToolsSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
|
|
{
|
|
AZ_UNUSED(required);
|
|
}
|
|
|
|
void AtomImGuiToolsSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
|
|
{
|
|
AZ_UNUSED(dependent);
|
|
}
|
|
|
|
void AtomImGuiToolsSystemComponent::Activate()
|
|
{
|
|
#if defined(IMGUI_ENABLED)
|
|
ImGui::ImGuiUpdateListenerBus::Handler::BusConnect();
|
|
#endif
|
|
CrySystemEventBus::Handler::BusConnect();
|
|
}
|
|
|
|
void AtomImGuiToolsSystemComponent::Deactivate()
|
|
{
|
|
#if defined(IMGUI_ENABLED)
|
|
m_imguiPassTree.Reset();
|
|
ImGui::ImGuiUpdateListenerBus::Handler::BusDisconnect();
|
|
#endif
|
|
|
|
CrySystemEventBus::Handler::BusDisconnect();
|
|
}
|
|
|
|
#if defined(IMGUI_ENABLED)
|
|
void AtomImGuiToolsSystemComponent::OnImGuiUpdate()
|
|
{
|
|
if (m_showPassTree)
|
|
{
|
|
m_imguiPassTree.Draw(m_showPassTree, AZ::RPI::PassSystemInterface::Get()->GetRootPass().get());
|
|
}
|
|
if (m_showGpuProfiler)
|
|
{
|
|
m_imguiGpuProfiler.Draw(m_showGpuProfiler, AZ::RPI::PassSystemInterface::Get()->GetRootPass().get());
|
|
}
|
|
if (m_showCpuProfiler)
|
|
{
|
|
m_imguiCpuProfiler.Draw(m_showCpuProfiler);
|
|
}
|
|
if (m_showTransientAttachmentProfiler)
|
|
{
|
|
auto* transientStats = AZ::RHI::RHISystemInterface::Get()->GetTransientAttachmentStatistics();
|
|
if (transientStats)
|
|
{
|
|
m_showTransientAttachmentProfiler = m_imguiTransientAttachmentProfiler.Draw(*transientStats);
|
|
}
|
|
}
|
|
if (m_showShaderMetrics)
|
|
{
|
|
m_imguiShaderMetrics.Draw(m_showShaderMetrics, AZ::RPI::ShaderMetricsSystemInterface::Get()->GetMetrics());
|
|
}
|
|
}
|
|
|
|
void AtomImGuiToolsSystemComponent::OnImGuiMainMenuUpdate()
|
|
{
|
|
if (ImGui::BeginMenu("Atom Tools"))
|
|
{
|
|
ImGui::MenuItem("Pass Viewer", "", &m_showPassTree);
|
|
ImGui::MenuItem("Gpu Profiler", "", &m_showGpuProfiler);
|
|
if (ImGui::MenuItem("Cpu Profiler", "", &m_showCpuProfiler))
|
|
{
|
|
AZ::RHI::RHISystemInterface::Get()->ModifyFrameSchedulerStatisticsFlags(
|
|
AZ::RHI::FrameSchedulerStatisticsFlags::GatherCpuTimingStatistics, m_showCpuProfiler);
|
|
AZ::RHI::CpuProfiler::Get()->SetProfilerEnabled(m_showCpuProfiler);
|
|
}
|
|
if (ImGui::MenuItem("Transient Attachment Profiler", "", &m_showTransientAttachmentProfiler))
|
|
{
|
|
AZ::RHI::RHISystemInterface::Get()->ModifyFrameSchedulerStatisticsFlags(
|
|
AZ::RHI::FrameSchedulerStatisticsFlags::GatherTransientAttachmentStatistics, m_showTransientAttachmentProfiler);
|
|
}
|
|
ImGui::MenuItem("Shader Metrics", "", &m_showShaderMetrics);
|
|
ImGui::EndMenu();
|
|
}
|
|
}
|
|
#endif
|
|
|
|
void AtomImGuiToolsSystemComponent::OnCryEditorInitialized()
|
|
{
|
|
AzFramework::ConsoleRequestBus::Broadcast(&AzFramework::ConsoleRequestBus::Events::ExecuteConsoleCommand, "imgui_DiscreteInputMode 1");
|
|
}
|
|
} // namespace AtomImGuiTools
|