Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.
C++
diag(present): log Present-to-scanout latency and composition mode
Veyra Goal Agentd49b14571b97
diff --git a/include/veyra/gfx/PresentSink.h b/include/veyra/gfx/PresentSink.hindex 5061be23..ac8b957a 100644--- a/include/veyra/gfx/PresentSink.h+++ b/include/veyra/gfx/PresentSink.h@@ -11,9 +11,11 @@#include <dxgi1_6.h>#include <wrl/client.h>+#include <array>#include <cstdint>#include <string>#include <optional>+#include <vector>#include "veyra/Result.h"#include "veyra/gfx/XessPresenter.h"@@ -111,6 +113,19 @@ public:HRESULT result=S_OK;};FrameStatisticsDelta sampleFrameStatistics();+ // Present call -> the vblank that showed it, for VSync DXGI presents.+ // Flip-model frame statistics name the last displayed present+ // (PresentCount, same numbering as GetLastPresentCount) and its vblank+ // (PresentRefreshCount); SyncQPCTime/SyncRefreshCount date that vblank.+ // Sampled before every Present, summarised and cleared by the caller.+ // compositionMode: DXGI_FRAME_PRESENTATION_MODE (0 composed, 1 overlay,+ // 2 none, 3 composition failure), -1 when the query is unavailable.+ struct DisplayLatencySummary {+ uint64_t samples=0;+ double p50Ms=-1,p95Ms=-1,maxMs=-1;+ int compositionMode=-1;+ };+ DisplayLatencySummary takeDisplayLatency();double displayRefreshHz()const{return displayRefreshHz_;}bool configurePacing(bool enabled,bool vsync,bool tearing);bool presentationReady();@@ -186,6 +201,15 @@ private:bool frameStatisticsBaseValid_=false;uint64_t frameStatisticsBasePresents_=0;UINT frameStatisticsBasePresentRefresh_=0,frameStatisticsBaseSyncRefresh_=0,frameStatisticsBaseDisplayed_=0;+ void sampleDisplayLatency();+ struct PendingPresent { UINT id=0; int64_t qpc=0; };+ std::array<PendingPresent,16> pendingPresents_{};+ unsigned pendingPresentNext_=0;+ UINT lastDisplayedPresent_=0,lastSyncRefresh_=0;+ int64_t lastSyncQpc_=0;+ double refreshQpc_=0;+ bool displayLatencyEnabled_=true;+ std::vector<double> displayLatencyMs_;};} // namespace veyra::gfxdiff --git a/src/engine/VideoPresenter.cpp b/src/engine/VideoPresenter.cppindex 25bf511b..dc3c8f3e 100644--- a/src/engine/VideoPresenter.cpp+++ b/src/engine/VideoPresenter.cpp@@ -393,6 +393,8 @@ bool VideoPresenter::present(gfx::D3D12DeviceContext& ctx,gfx::CommandSlotRing&const auto stats=displayStats?sink_.sampleFrameStatistics():gfx::PresentSink::FrameStatisticsDelta{};if(stats.supported)veyra::log::info("display-stats",std::format("refreshHz={:.3f} presentCalls={} dxgiPresentCount={} refreshes={} presentRefreshDelta={} backend={} (DXGI GetFrameStatistics delta over ~1s. These counters CANNOT tell how many frames the panel actually showed: with vsync off and tearing allowed, dxgiPresentCount tracks completed Present calls, and both refresh counters just advance with the monitor. Measuring scanout needs PresentMon. XeSS generated presents are provider-internal.)",sink_.displayRefreshHz(),stats.presents,stats.displayed,stats.refreshes,stats.displayedRefresh,sink_.xess()?"XeSS":"DXGI"));else if(FAILED(stats.result))veyra::log::info("display-stats",std::format("unavailable hr=0x{:X} backend={}",unsigned(stats.result),sink_.xess()?"XeSS":"DXGI"));+ const auto scanout=displayStats?sink_.takeDisplayLatency():gfx::PresentSink::DisplayLatencySummary{};+ if(scanout.samples||scanout.compositionMode>=0)veyra::log::info("display-latency",std::format("presentToScanoutP50Ms={:.3f} presentToScanoutP95Ms={:.3f} presentToScanoutMaxMs={:.3f} samples={} compositionMode={} refreshHz={:.3f} (DXGI frame statistics: Present call to the vblank that showed it, VSync DXGI presents only; compositionMode 0 composed 1 overlay 2 none 3 failure -1 unknown; not a photon measurement)",scanout.p50Ms,scanout.p95Ms,scanout.maxMs,scanout.samples,scanout.compositionMode,sink_.displayRefreshHz()));const auto& timing=sink_.lastPresentTiming();veyra::log::info("present-cost",std::format("generated={} totalMs={:.3f} recordSubmitMs={:.3f} slotWaitMs={:.3f} dxgiMs={:.3f} slow={} source={} epoch={} backend={} resized={} resizeMs={:.3f} beginMs={:.3f} commandsMs={:.3f} beforeMs={:.3f} presentCallMs={:.3f} bufferMs={:.3f} afterMs={:.3f} hr=0x{:X}",generated,std::chrono::duration<double,std::milli>(presentEnd-presentStart).count(),diff --git a/src/gfx/PresentSink.cpp b/src/gfx/PresentSink.cppindex f25c5299..dc9742ca 100644--- a/src/gfx/PresentSink.cpp+++ b/src/gfx/PresentSink.cpp@@ -5,6 +5,7 @@#include <d3d12sdklayers.h>#include <dxgi1_6.h>+#include <algorithm>#include <format>#include <chrono>#include <vector>@@ -324,6 +325,9 @@ bool PresentSink::initialize(ID3D12Device* device, ID3D12CommandQueue* queue,tearingSupported_=tearingSupported_&&(actual.Flags&DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING)!=0;displayRefreshHz_=displayRefreshFps(hwnd_);frameStatisticsBaseValid_=false;+ // New swap chain: present ids restart; VEYRA_TEST_NO_DISPLAY_STATS=1 disables the samples.+ displayLatencyEnabled_=GetEnvironmentVariableW(L"VEYRA_TEST_NO_DISPLAY_STATS",nullptr,0)==0;+ pendingPresents_={};lastDisplayedPresent_=0;lastSyncRefresh_=0;lastSyncQpc_=0;refreshQpc_=0;displayLatencyMs_.clear();log::info("display-refresh",std::format("monitor refresh={:.3f} Hz at swapchain creation (0 = unknown); submissions above this rate cannot all be scanned out",displayRefreshHz_));log::info("present", std::format("present-sink: window {}x{} swapEffect={} buffers=3 vsync={} tearing={} captureCompatible={} (capture not verified)",width_, height_, actual.SwapEffect==DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL?"flip-sequential":"flip-discard", desc_.vsync ? 1 : 0, (desc_.tearing && tearingSupported_) ? 1 : 0, desc.captureCompatible));@@ -397,8 +401,14 @@ bool PresentSink::present(Status& status)const bool beforeOk=!xess_||xess_->beforePresent();presentTiming_.beforeMs=split();if(!beforeOk){xessFailed_=true;status=Status::WindowFailure;return false;}+ const bool trackScanout=displayLatencyEnabled_&&!xess_&&syncInterval==1;+ if(trackScanout)sampleDisplayLatency();+ LARGE_INTEGER presentQpc{};QueryPerformanceCounter(&presentQpc);const HRESULT hr = swapChain_->Present(syncInterval, flags);presentTiming_.callMs=split();presentTiming_.result=hr;+ UINT presentId=0;+ if(SUCCEEDED(hr)&&trackScanout&&SUCCEEDED(swapChain_->GetLastPresentCount(&presentId)))+ pendingPresents_[pendingPresentNext_++%pendingPresents_.size()]={presentId,presentQpc.QuadPart};if(presentContractDirty_||attemptedPresentCount_<=3||attemptedPresentCount_%120==0){log::info("present-contract",std::format("backend={} sync={} flags=0x{:X} hr=0x{:X}",xess_?"XeSS":"DXGI",syncInterval,flags,unsigned(hr)));presentContractDirty_=false;@@ -482,6 +492,42 @@ PresentSink::FrameStatisticsDelta PresentSink::sampleFrameStatistics(){return delta;}+void PresentSink::sampleDisplayLatency(){+ static const double frequency=[]{LARGE_INTEGER f{};QueryPerformanceFrequency(&f);return double(f.QuadPart);}();+ DXGI_FRAME_STATISTICS stats{};+ if(!swapChain_||FAILED(swapChain_->GetFrameStatistics(&stats))||!stats.SyncQPCTime.QuadPart)return;+ // Measured vblank period from successive statistics, else the monitor rate.+ if(lastSyncQpc_&&stats.SyncRefreshCount>lastSyncRefresh_&&stats.SyncQPCTime.QuadPart>lastSyncQpc_)+ refreshQpc_=double(stats.SyncQPCTime.QuadPart-lastSyncQpc_)/double(stats.SyncRefreshCount-lastSyncRefresh_);+ lastSyncQpc_=stats.SyncQPCTime.QuadPart;lastSyncRefresh_=stats.SyncRefreshCount;+ if(stats.PresentCount==lastDisplayedPresent_)return;+ lastDisplayedPresent_=stats.PresentCount;+ const double period=refreshQpc_>0?refreshQpc_:displayRefreshHz_>=1?frequency/displayRefreshHz_:0;+ if(period<=0||stats.SyncRefreshCount<stats.PresentRefreshCount||stats.SyncRefreshCount-stats.PresentRefreshCount>16)return;+ const double scanout=double(stats.SyncQPCTime.QuadPart)-double(stats.SyncRefreshCount-stats.PresentRefreshCount)*period;+ for(const auto& pending:pendingPresents_){+ if(pending.id!=stats.PresentCount||!pending.qpc)continue;+ const double ms=(scanout-double(pending.qpc))*1000.0/frequency;+ if(ms>=0&&ms<1000&&displayLatencyMs_.size()<4096)displayLatencyMs_.push_back(ms);+ break;+ }+}+PresentSink::DisplayLatencySummary PresentSink::takeDisplayLatency(){+ DisplayLatencySummary summary;+ auto& values=displayLatencyMs_;+ if(!values.empty()){+ std::sort(values.begin(),values.end());+ summary.samples=values.size();summary.p50Ms=values[(values.size()-1)/2];+ summary.p95Ms=values[std::min(values.size()-1,(values.size()*95+99)/100-1)];summary.maxMs=values.back();+ values.clear();+ }+ ComPtr<IDXGISwapChainMedia> media;+ DXGI_FRAME_STATISTICS_MEDIA statistics{};+ if(displayLatencyEnabled_&&!xess_&&swapChain_&&SUCCEEDED(swapChain_.As(&media))&&SUCCEEDED(media->GetFrameStatisticsMedia(&statistics)))+ summary.compositionMode=int(statistics.CompositionMode);+ return summary;+}+bool PresentSink::configurePacing(bool enabled,bool vsync,bool tearing){if(desc_.vsync!=vsync||desc_.tearing!=tearing)presentContractDirty_=true;// XeSS owns pacing, but its proxy accepts DXGI VSync independently.