From 1ea7edd009e7f0b4e529cce5e1677b1aa863112f Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 26 Dec 2023 01:42:54 +0100 Subject: [PATCH] NVIDIA: move markers to actual IDXGISwapChain::Present runtime call Testing revealed better latency reduction when moved directly here as we also take into account the additional buffy copy's the game does in SpinPresent, our new render thread frame limiter and and ImGui. The difference is very large when the render thread frame limiter is used. The code still passes NVIDIA's reflex testing utility after this patch. --- src/materialsystem/cmaterialsystem.cpp | 13 ------------- src/windows/id3dx.cpp | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/materialsystem/cmaterialsystem.cpp b/src/materialsystem/cmaterialsystem.cpp index 0f466392..5ec2da93 100644 --- a/src/materialsystem/cmaterialsystem.cpp +++ b/src/materialsystem/cmaterialsystem.cpp @@ -115,20 +115,7 @@ void* __fastcall DispatchDrawCall(int64_t a1, uint64_t a2, int a3, int a4, int64 //--------------------------------------------------------------------------------- ssize_t SpinPresent(void) { - // NOTE: -1 since we need to sync this with its corresponding frame, g_FrameNum - // gets incremented in CMaterialSystem::SwapBuffers, which is after the markers - // for simulation start/end and render submit start. The render thread (here) - // continues after to finish the frame. - const NvU64 frameID = (NvU64)MaterialSystem()->GetCurrentFrameCount() -1; - - GFX_SetLatencyMarker(D3D11Device(), RENDERSUBMIT_END, frameID); - - // TODO[ AMOS ]: move to actual Present runtime call? SpinPresent calls some - // other DX buffer copy API's before the actual Present calls is being made. - GFX_SetLatencyMarker(D3D11Device(), PRESENT_START, frameID); const ssize_t val = v_SpinPresent(); - GFX_SetLatencyMarker(D3D11Device(), PRESENT_END, frameID); - return val; } diff --git a/src/windows/id3dx.cpp b/src/windows/id3dx.cpp index 5a12fa96..49f64115 100644 --- a/src/windows/id3dx.cpp +++ b/src/windows/id3dx.cpp @@ -13,6 +13,7 @@ #include "engine/sys_engine.h" #include "engine/sys_mainwind.h" #include "inputsystem/inputsystem.h" +#include "materialsystem/cmaterialsystem.h" #include "public/bitmap/stb_image.h" #include "public/rendersystem/schema/texture.g.h" @@ -146,9 +147,19 @@ HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT nSyncInterval, UINT n if (g_pEngine->GetQuitting() == IEngine::QUIT_NOTQUITTING) DrawImGui(); - /////////////////////////////////////////////////////////////////////////////// - HRESULT result = s_fnSwapChainPresent(pSwapChain, nSyncInterval, nFlags); + /////////////////////////////////////////////////////////////////////////////// + // NOTE: -1 since we need to sync this with its corresponding frame, g_FrameNum + // gets incremented in CMaterialSystem::SwapBuffers, which is after the markers + // for simulation start/end and render submit start. The render thread (here) + // continues after to finish the frame. + const NvU64 frameID = (NvU64)MaterialSystem()->GetCurrentFrameCount() - 1; + GFX_SetLatencyMarker(D3D11Device(), RENDERSUBMIT_END, frameID); + + GFX_SetLatencyMarker(D3D11Device(), PRESENT_START, frameID); + const HRESULT result = s_fnSwapChainPresent(pSwapChain, nSyncInterval, nFlags); + GFX_SetLatencyMarker(D3D11Device(), PRESENT_END, frameID); + return result; }