2
0
Эх сурвалжийг харах

More accurate FrameTime stats (#454)

* More accurate FrameTime stats

Signed-off-by: rgba16f <[email protected]>

* ASV More Accurate Frame Time Stats, make the count of frames to average time over command line configurable

Signed-off-by: rgba16f <[email protected]>

* More Accurate Frame Time Stats, update PR with @moudgils & @gadams3's feedback

Signed-off-by: rgba16f <[email protected]>
rgba16f 3 жил өмнө
parent
commit
770fbfba22

+ 18 - 4
Gem/Code/Source/SampleComponentManager.cpp

@@ -330,8 +330,9 @@ namespace AtomSampleViewer
 
 
     SampleComponentManager::SampleComponentManager()
     SampleComponentManager::SampleComponentManager()
         : m_imguiFrameCaptureSaver("@user@/frame_capture.xml")
         : m_imguiFrameCaptureSaver("@user@/frame_capture.xml")
-        , m_imGuiFrameTimer(FrameTimeLogSize, FrameTimeLogSize, 250.0f)
     {
     {
+        m_imGuiFrameTimer = AZStd::make_unique<ImGuiHistogramQueue>(FrameTimeDefaultLogSize, FrameTimeDefaultLogSize, 250.0f);
+
         m_exampleEntity = aznew AZ::Entity();
         m_exampleEntity = aznew AZ::Entity();
 
 
         m_entityContextId = AzFramework::EntityContextId::CreateNull();
         m_entityContextId = AzFramework::EntityContextId::CreateNull();
@@ -486,6 +487,16 @@ namespace AtomSampleViewer
             }
             }
             AZ_Warning("SampleComponentManager", targetSampleFound, "Failed find target sample %s", targetSampleName.c_str());
             AZ_Warning("SampleComponentManager", targetSampleFound, "Failed find target sample %s", targetSampleName.c_str());
         }
         }
+        if (commandLine->HasSwitch("timingSamples"))
+        {
+                AZStd::string timingSamplesStr = commandLine->GetSwitchValue("timingSamples", 0);
+                int timingSamplesCount = 0;
+                if (AZ::StringFunc::LooksLikeInt(timingSamplesStr.c_str(), &timingSamplesCount))
+                {
+                    timingSamplesCount = AZStd::clamp<int>(timingSamplesCount, FrameTimeMinLogSize, FrameTimeMaxLogSize);
+                    m_imGuiFrameTimer = AZStd::make_unique<ImGuiHistogramQueue>(timingSamplesCount, timingSamplesCount, 250.0f);
+                }
+        }
 
 
         // Set default screenshot folder to relative path 'Screenshots'
         // Set default screenshot folder to relative path 'Screenshots'
         AZ::IO::Path screenshotFolder = "Screenshots";
         AZ::IO::Path screenshotFolder = "Screenshots";
@@ -543,7 +554,10 @@ namespace AtomSampleViewer
 
 
     void SampleComponentManager::OnTick(float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
     void SampleComponentManager::OnTick(float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
     {
     {
-        m_imGuiFrameTimer.PushValue(deltaTime * 1000.0f);
+        if (m_imGuiFrameTimer)
+        {
+            m_imGuiFrameTimer->PushValue(deltaTime * 1000.0f);
+        }
 
 
         bool screenshotRequest = false;
         bool screenshotRequest = false;
 
 
@@ -1191,12 +1205,12 @@ namespace AtomSampleViewer
 
 
     void SampleComponentManager::ShowFramerateHistogram(float deltaTime)
     void SampleComponentManager::ShowFramerateHistogram(float deltaTime)
     {
     {
-        if (ImGui::Begin("Frame Time Histogram", &m_showFramerateHistogram, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings))
+        if (m_imGuiFrameTimer && ImGui::Begin("Frame Time Histogram", &m_showFramerateHistogram, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings))
         {
         {
             ImGuiHistogramQueue::WidgetSettings settings;
             ImGuiHistogramQueue::WidgetSettings settings;
             settings.m_reportInverse = false;
             settings.m_reportInverse = false;
             settings.m_units = "ms";
             settings.m_units = "ms";
-            m_imGuiFrameTimer.Tick(deltaTime * 1000.0f, settings);
+            m_imGuiFrameTimer->Tick(deltaTime * 1000.0f, settings);
         }
         }
         ImGui::End();
         ImGui::End();
     }
     }

+ 5 - 2
Gem/Code/Source/SampleComponentManager.h

@@ -33,6 +33,7 @@
 #include <AzCore/std/containers/vector.h>
 #include <AzCore/std/containers/vector.h>
 #include <AzCore/std/containers/map.h>
 #include <AzCore/std/containers/map.h>
 #include <AzCore/std/smart_ptr/shared_ptr.h>
 #include <AzCore/std/smart_ptr/shared_ptr.h>
+#include <AzCore/std/smart_ptr/unique_ptr.h>
 
 
 #include <AzFramework/Input/Events/InputChannelEventListener.h>
 #include <AzFramework/Input/Events/InputChannelEventListener.h>
 #include <AzFramework/Entity/EntityContextBus.h>
 #include <AzFramework/Entity/EntityContextBus.h>
@@ -200,8 +201,10 @@ namespace AtomSampleViewer
 
 
         int32_t m_selectedSampleIndex = -1;
         int32_t m_selectedSampleIndex = -1;
 
 
-        static constexpr uint32_t FrameTimeLogSize = 30;
-        ImGuiHistogramQueue m_imGuiFrameTimer;
+        static constexpr uint32_t FrameTimeDefaultLogSize = 100;
+        static constexpr uint32_t FrameTimeMinLogSize = FrameTimeDefaultLogSize;
+        static constexpr uint32_t FrameTimeMaxLogSize = 1000000; // 1M
+        AZStd::unique_ptr<ImGuiHistogramQueue> m_imGuiFrameTimer;
 
 
         ImGuiMessageBox m_contentWarningDialog;
         ImGuiMessageBox m_contentWarningDialog;
 
 

+ 1 - 1
Gem/Code/Source/Utils/ImGuiHistogramQueue.cpp

@@ -69,7 +69,7 @@ namespace AtomSampleViewer
         // Calculate average for numeric display
         // Calculate average for numeric display
         if (m_timeSinceLastDisplayUpdate >= m_numericDisplayDelay || m_samplesSinceLastDisplayUpdate >= m_maxSamples)
         if (m_timeSinceLastDisplayUpdate >= m_numericDisplayDelay || m_samplesSinceLastDisplayUpdate >= m_maxSamples)
         {
         {
-            m_displayedAverage = UpdateDisplayedValues(m_samplesSinceLastDisplayUpdate, m_displayedMinimum, m_displayedMaximum);
+            m_displayedAverage = UpdateDisplayedValues(m_maxSamples, m_displayedMinimum, m_displayedMaximum);
 
 
             m_timeSinceLastDisplayUpdate = 0.0f;
             m_timeSinceLastDisplayUpdate = 0.0f;
             m_samplesSinceLastDisplayUpdate = 0;
             m_samplesSinceLastDisplayUpdate = 0;