diff --git a/Source/Engine/Graphics/GPUDevice.cpp b/Source/Engine/Graphics/GPUDevice.cpp index 1e79d5a58..02c2765d0 100644 --- a/Source/Engine/Graphics/GPUDevice.cpp +++ b/Source/Engine/Graphics/GPUDevice.cpp @@ -753,6 +753,8 @@ void GPUDevice::DrawEnd() } #if COMPILE_WITH_PROFILER const double presentEnd = Platform::GetTimeSeconds(); + extern double LastInputLatency, LastInputReadTime; + LastInputLatency = (float)(presentEnd - LastInputReadTime); ProfilerGPU::OnPresentTime((float)((presentEnd - presentStart) * 1000.0)); #endif GetMainContext()->OnPresent(); diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index 2dd80f923..13136a0a3 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -50,6 +50,8 @@ namespace InputDevice::EventQueue InputEvents; } +double LastInputReadTime = 0; + class InputService : public EngineService { public: @@ -860,6 +862,7 @@ void InputService::Update() const auto frame = Time::Update.TicksCount; const auto dt = Time::Update.UnscaledDeltaTime.GetTotalSeconds(); InputEvents.Clear(); + LastInputReadTime = Platform::GetTimeSeconds(); // If application has no user focus then simply clear the state if (!Engine::HasFocus) diff --git a/Source/Engine/Profiler/ProfilingTools.cpp b/Source/Engine/Profiler/ProfilingTools.cpp index 0e7ac1566..6e2a0afe8 100644 --- a/Source/Engine/Profiler/ProfilingTools.cpp +++ b/Source/Engine/Profiler/ProfilingTools.cpp @@ -29,6 +29,7 @@ public: }; ProfilingToolsService ProfilingToolsServiceInstance; +double LastInputLatency = 0; void ProfilingToolsService::Update() { @@ -52,6 +53,8 @@ void ProfilingToolsService::Update() float presentTime; ProfilerGPU::GetLastFrameData(stats.DrawGPUTimeMs, presentTime, stats.DrawStats); stats.DrawCPUTimeMs = Math::Max(stats.DrawCPUTimeMs - presentTime, 0.0f); // Remove swapchain present wait time to exclude from drawing on CPU + + stats.InputLatencyMs = (float)(LastInputLatency * 1000.0); } // Extract CPU profiler events diff --git a/Source/Engine/Profiler/ProfilingTools.h b/Source/Engine/Profiler/ProfilingTools.h index 34be06e5d..223894866 100644 --- a/Source/Engine/Profiler/ProfilingTools.h +++ b/Source/Engine/Profiler/ProfilingTools.h @@ -81,6 +81,11 @@ public: /// API_FIELD() float DrawGPUTimeMs; + /// + /// The time between player inputs reading and frame presentation to display (in milliseconds). + /// + API_FIELD() float InputLatencyMs; + /// /// The last rendered frame stats. ///