From 4d618ea619e8bb2b6e4c930f77bd97411ae4d50a Mon Sep 17 00:00:00 2001 From: Jacob Hilliard Date: Tue, 20 Jul 2021 16:03:22 -0700 Subject: [PATCH] Profiling: Add more instrumentation Adds new instrumentation macros throughout the codebase, using the visualizer to find where current instrumentation is lacking using the shadowed sponza sample + editor. Some notes from exploring: - We spend ~5ms in CullingScene: BeginCulling - PipelineStateCache: Compact usually 1ms - CompileImageBarriers takes most of the time in CompileResourceBarriers Signed-off-by: Jacob Hilliard --- Gems/Atom/RHI/Code/Source/RHI/FrameGraph.cpp | 1 + Gems/Atom/RHI/Code/Source/RHI/FrameGraphExecuter.cpp | 1 + Gems/Atom/RHI/Code/Source/RHI/PipelineStateCache.cpp | 2 ++ Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp | 2 +- Gems/Atom/RHI/DX12/Code/Source/RHI/FrameGraphCompiler.cpp | 2 ++ Gems/Atom/RPI/Code/Source/RPI.Public/Culling.cpp | 1 + Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp | 7 ++++++- Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp | 4 +++- 8 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Gems/Atom/RHI/Code/Source/RHI/FrameGraph.cpp b/Gems/Atom/RHI/Code/Source/RHI/FrameGraph.cpp index b670dc1234..d2298cda3f 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/FrameGraph.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/FrameGraph.cpp @@ -126,6 +126,7 @@ namespace AZ ResultCode FrameGraph::End() { + AZ_ATOM_PROFILE_FUNCTION("RHI", "FrameGraph: End"); ResultCode resultCode = ValidateEnd(); if (resultCode != ResultCode::Success) { diff --git a/Gems/Atom/RHI/Code/Source/RHI/FrameGraphExecuter.cpp b/Gems/Atom/RHI/Code/Source/RHI/FrameGraphExecuter.cpp index 3189acab49..342e537993 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/FrameGraphExecuter.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/FrameGraphExecuter.cpp @@ -72,6 +72,7 @@ namespace AZ void FrameGraphExecuter::Begin(const FrameGraph& frameGraph) { AZ_TRACE_METHOD(); + AZ_ATOM_PROFILE_FUNCTION("RHI", "FrameGraphExecuter: Begin"); BeginInternal(frameGraph); } diff --git a/Gems/Atom/RHI/Code/Source/RHI/PipelineStateCache.cpp b/Gems/Atom/RHI/Code/Source/RHI/PipelineStateCache.cpp index 1170b82d78..0210d941dc 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/PipelineStateCache.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/PipelineStateCache.cpp @@ -6,6 +6,7 @@ * */ +#include #include #include #include @@ -205,6 +206,7 @@ namespace AZ void PipelineStateCache::Compact() { + AZ_ATOM_PROFILE_FUNCTION("RHI", "PipelineStateCache: Compact"); AZStd::unique_lock lock(m_mutex); // Merge the pending cache into the read-only cache. diff --git a/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp b/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp index 083fb87b93..49244f776f 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp @@ -223,7 +223,7 @@ namespace AZ * own RHI scopes to the frame scheduler. This happens prior to the RPI pass graph registration. */ { - AZ_ATOM_PROFILE_TIME_GROUP_REGION("RHI", "RHISystem :FrameUpdate: OnFramePrepare"); + AZ_ATOM_PROFILE_TIME_GROUP_REGION("RHI", "RHISystem: FrameUpdate: OnFramePrepare"); RHISystemNotificationBus::Broadcast(&RHISystemNotificationBus::Events::OnFramePrepare, m_frameScheduler); } diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI/FrameGraphCompiler.cpp b/Gems/Atom/RHI/DX12/Code/Source/RHI/FrameGraphCompiler.cpp index c98fd51fbb..ba4aa76a60 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI/FrameGraphCompiler.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI/FrameGraphCompiler.cpp @@ -469,6 +469,8 @@ namespace AZ ResourceTransitionLoggerNull logger(imageFrameAttachment.GetId()); #endif + AZ_ATOM_PROFILE_FUNCTION("RHI", "FrameGraphCompiler: CompileImageBarriers (DX12)"); + Image& image = static_cast(*imageFrameAttachment.GetImage()); RHI::ImageScopeAttachment* scopeAttachment = imageFrameAttachment.GetFirstScopeAttachment(); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Culling.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Culling.cpp index e192e71fc4..c630fe0e5d 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Culling.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Culling.cpp @@ -720,6 +720,7 @@ namespace AZ void CullingScene::BeginCulling(const AZStd::vector& views) { + AZ_ATOM_PROFILE_FUNCTION("RPI", "CullingScene: BeginCulling"); m_cullDataConcurrencyCheck.soft_lock(); m_debugCtx.ResetCullStats(); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp index f62dfa1d70..27e3612a4c 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassSystem.cpp @@ -298,6 +298,7 @@ namespace AZ void PassSystem::ProcessQueuedChanges() { + AZ_ATOM_PROFILE_FUNCTION("RPI", "PassSystem: ProcessQueuedChanges"); RemovePasses(); BuildPasses(); InitializePasses(); @@ -313,7 +314,11 @@ namespace AZ m_state = PassSystemState::Rendering; Pass::FramePrepareParams params{ &frameGraphBuilder }; - m_rootPass->FrameBegin(params); + + { + AZ_ATOM_PROFILE_TIME_GROUP_REGION("RPI", "Pass: FrameBegin"); + m_rootPass->FrameBegin(params); + } } void PassSystem::FrameEnd() diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp index bc700dd24f..071a07ecda 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp @@ -408,6 +408,7 @@ namespace AZ { AZ_PROFILE_SCOPE(Debug::ProfileCategory::AzRender, "m_srgCallback"); + AZ_ATOM_PROFILE_TIME_GROUP_REGION("RPI", "ShaderResourceGroupCallback: SrgCallback"); // Set values for scene srg if (m_srg && m_srgCallback) { @@ -418,7 +419,7 @@ namespace AZ // Get active pipelines which need to be rendered and notify them frame started AZStd::vector activePipelines; { - AZ_ATOM_PROFILE_TIME_GROUP_REGION("RPI", "OnStartFrame"); + AZ_ATOM_PROFILE_TIME_GROUP_REGION("RPI", "Scene: OnStartFrame"); for (auto& pipeline : m_pipelines) { if (pipeline->NeedsRender()) @@ -483,6 +484,7 @@ namespace AZ { AZ_PROFILE_SCOPE(Debug::ProfileCategory::AzRender, "CollectDrawPackets"); + AZ_ATOM_PROFILE_TIME_GROUP_REGION("RPI", "CollectDrawPackets"); AZ::JobCompletion* collectDrawPacketsCompletion = aznew AZ::JobCompletion(); // Launch FeatureProcessor::Render() jobs