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++
latency-min B3: explicit VSync keeps a one-deep display queue
Veyra Goal Agentada49ff01ec2
diff --git a/docs/LATENCY_MIN_PLAN_2026-10-13.md b/docs/LATENCY_MIN_PLAN_2026-10-13.mdindex c9dc9839..d18b62d2 100644--- a/docs/LATENCY_MIN_PLAN_2026-10-13.md+++ b/docs/LATENCY_MIN_PLAN_2026-10-13.md@@ -27,7 +27,7 @@| **A2 诊断**(随 A1) | 每秒记录 presentsAhead(GetLastPresentCount−已显示 PresentCount);“自动”模式也统计送显→上屏(只按确认上屏的那一帧) | 以后的日志能直接看出是否排队 | 日志字段存在且数值合理 || **B1 XeSS“提交即送显”** | XeSS 时读帧→处理→立即打标签并 Present,不再由调度器等 GPU 完成后才送;一个 XeLL 周期内完成 睡眠→读输入→提交→送显,修正周期错位 | 去掉 CPU 等 GPU 的约 7ms 和轮询抖动;XeLL 的队列控制按设计生效 | 320Hz/60Hz 下 XeSS 回调→送显、真帧率、XeLL 睡眠时长;画面校验无错帧 || **B2 补帧输出预算**(已实施) | 内容帧率×倍数 > 1.02×刷新率时:DLSS/FSR/VFG 自动降到能放下的最大合法倍数;放不下但源比屏幕慢(60fps@100Hz)保留 2X(仍多出画面);源已占满屏幕(≥0.97×刷新,如 60Hz 屏 + 60fps 源)旁路补帧,真帧直接显示、不等插帧;XeSS 只做 SetEnabled(false) 旁路;新决定持续 1.5 秒才生效,状态栏说明原因 | 不浪费 GPU、动作均匀;60Hz+60fps 时延迟等于仅 NR | 实测:DLSS 6X@320Hz→4X,送显→上屏 6.2/8.0→5.0/6.9ms,垂直同步 12.2/18.4→5.7/8.5ms;模拟 60Hz 旁路回调→送显 8.8ms=仅 NR;30fps+2X@60Hz 保持 2X |-| **B3 “垂直同步”也不排队** | 用户显式选垂直同步时,在读采集帧之前等待可等待对象(≤1 个刷新),不在送显前等;XeSS 代理最大延迟设 1;“低延迟队列”改成这个语义 | 垂直同步模式下的排队上限 1 帧 | DLSS 6X@320Hz 垂直同步模式送显→上屏≈1 个刷新;回调→送显不升 |+| **B3 “垂直同步”也不排队**(已实施) | 只有显式垂直同步节流:启用时清掉可等待对象积累的计数并放行一帧;直播未补帧时在读采集帧之前取得屏幕容量,每次送显前也取得容量(插帧最多等 ≤2ms 否则让给下一帧);自动/撕裂永不等待;“低延迟队列”=只保留一帧在处理 + 未补帧时 Reflex;XeSS 代理不设最大延迟(Intel:XeLL 以外的延迟手段不受支持) | 垂直同步模式下的排队上限 1 帧 | 回放 6X 超刷新:送显→上屏 18.4→5.8ms;探针源快 5%:7.3→2.5 个刷新;常规配置无回退;采集卡实测待设备上线 || **C1 VRR 研究** | 用户在驱动开启 G-SYNC/FreeSync 后,实测“自动”是否触发可变刷新;若不触发,评估“垂直同步 + B2 输出预算(输出始终低于最高刷新)”的 VRR 模式(不会撕裂) | 少等 0–1 个刷新(60Hz 平均约 8ms) | 需用户开启 VRR;对比送显→上屏 || **C2 独立翻转确认** | 用 PresentMon(需管理员)确认全屏/窗口的呈现模式;窗口合成会多 1 个刷新 | 明确“全屏更低”的条件或修掉窗口合成 | PresentMon PresentMode 列 || **C3 采集拷贝** | 4K NV12 回调拷贝约 1.5ms,研究直接以驱动缓冲上传 | ≤1.5ms | 回调耗时日志 |diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex b221042e..c7650989 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -9367,3 +9367,11 @@ v2.0.7 ID 410800361,published_at 2026-10-12T16:24:59Z,latest/非草稿/非构建:build.py 新增目标 veyra_realtime_preview_tests,并对包含改动头文件的 Qt moc 生成源重编(快照结构变化,不能混用旧布局);回执 logs/claude-latency-min-20261013/build-20261013-213309,check_rebuilt 所有链接对象已重编。测试:veyra_realtime_preview_tests 0 失败(新增预算 19 项、防抖 7 项)、veyra_repair_contract_tests、veyra_ui_contract_tests 通过。实卡(T911 2K60 NV12 → NR,320Hz,logs/claude-latency-min-20261013/b2-*):DLSS 6X 自动→4X:送显 360→240/s,补帧 GPU P95 7.4→5.7ms,送显→上屏 P50/P95 6.2/8.0→5.0/6.9ms(等于原生 4X);同 EXE 关预算对照 6X 为 5.6/9.5ms、回调→送显 P95 28.6 vs 26.5ms。显式垂直同步 6X:12.2/18.4→5.7/8.5ms,插帧过期 46→0/s,邮箱等待 10.7→0.3ms。模拟 60Hz(测试开关)DLSS 2X 旁路:回调→送显 P95 8.8ms,与仅 NR 8.9ms 相同(补帧时约 26ms);XeSS 2X 旁路:SDK 提交 120→60/s、enabled=0、Present 调用 0.64→0.20ms;60→30(30fps 内容)+2X@60Hz 保持 2X(60/s)。仅 NR 不变(8.9ms)。真实 60Hz 屏幕的光学复测仍需用户。++## 2026-10-14 极限低延迟 B3 垂直同步也不排队(Claude)++问题:垂直同步时设了最大延迟 1,但只有“低延迟队列”或输出上限开着才等可等待对象,所以队列不受限;“自动/撕裂”配“低延迟队列”时反而也在送显前等这个对象,等于把送显卡到刷新率上。新探针 `tmp/claude-latency-min-20261013/dxgi_semaphore_probe.cpp` 还证明:没人等待时这个对象会积累计数,之后切到垂直同步再“每帧等一次”也完全不拦(排 7 帧、等待 0ms),必须先清掉旧计数。++改动:只有显式“垂直同步”启用 DXGI 节流(最大延迟 1),启用时先让已排的帧显示完(≤100ms)、清掉积累的计数、再放行一帧(空队列不会卡死);直播且未补帧时在读采集帧之前取得屏幕容量(读帧门,无事可等时直接等这个对象而不是 1ms 轮询);每次送显前都取得容量,插帧最多等半个子帧间隔(≤2ms)否则让给下一帧,真帧继续等。“自动/撕裂”永不等待这个对象;“低延迟队列”改为“只保留一帧在处理 + 未补帧时 Reflex”,提示文字与状态栏改写并追加翻译。B2 在垂直同步下放不下时直接旁路(多出的帧会排队而不是被替换),XeSS 放不下也旁路。XeSS 代理不设最大延迟:Intel 文档写明 XeLL 以外的延迟手段不受支持、可能异常。运行中等待失败只停节流并提示,不再反复重配。测试开关 `VEYRA_TEST_LEGACY_VSYNC_QUEUE=1` 恢复旧的不等待队列。++验证:veyra_realtime_preview_tests(新增垂直同步规则 5 项)、repair/ui contract 通过;latency-min-tests display-sync 12/12、lifecycle 通过(日志 staleLatencyCounts=3)。采集卡本时段离线(PnP 状态 Unknown,几小时前可用),改用同一条直播链路的回放与探针:回放垂直同步 DLSS 6X(关预算强制超刷新)送显→上屏 18.4→5.8ms、排队 7→2、Present 阻塞 3.3→0.4ms;开预算的常规配置 B3 与旧行为完全一致(无回退);自动+低延迟队列 6X 不再被卡到刷新率(361 次/s);Reflex 与生命周期场景 13/13 通过。读帧门探针(采集式邮箱,320Hz):源比刷新快 5% 时旧行为显示帧年龄 22.9ms(7.3 个刷新)→ B3 7.7ms(2.5 个刷新),自动模式 4.8ms;源比刷新慢时三者相同。60Hz 下对应约 122→41ms。回放的连续时间线本身让真帧等一个源间隔,故回放的读→送显不代表采集卡延迟;采集卡实测待设备重新上线。diff --git a/i18n/catalog.json b/i18n/catalog.jsonindex 703d70e7..9c252d53 100644--- a/i18n/catalog.json+++ b/i18n/catalog.json@@ -15744,6 +15744,90 @@"zh-TW": "螢幕 %1 Hz 只顯示得下 %2X:已從 %3X 降到 %2X","en": "A %1 Hz display can only show %2X: lowered from %3X to %2X","ja": "%1 Hz の画面で表示できるのは %2X まで:%3X から %2X に下げました"+ },+ {+ "zh": "只保留一帧在处理,未补帧时加 NVIDIA Reflex;垂直同步本身已不排队",+ "src": "qml/ProPage.qml",+ "zh-TW": "只保留一幀在處理,未補幀時加 NVIDIA Reflex;垂直同步本身已不排隊",+ "en": "Keeps one frame in flight and adds NVIDIA Reflex without frame generation; VSync itself no longer queues",+ "ja": "処理中のフレームを 1 枚に保ち、フレーム生成なしでは NVIDIA Reflex を追加;垂直同期自体はもうキューを溜めない"+ },+ {+ "zh": "只保留一帧在处理,未补帧时加 Reflex",+ "src": "qml/NodePage.qml",+ "zh-TW": "只保留一幀在處理,未補幀時加 Reflex",+ "en": "One frame in flight; adds Reflex without frame generation",+ "ja": "処理中は 1 フレームのみ、フレーム生成なしでは Reflex を追加"+ },+ {+ "zh": "垂直同步:屏幕队列 1 帧,读帧前等待刷新",+ "src": "src/engine/VideoPresenter.cpp",+ "zh-TW": "垂直同步:螢幕佇列 1 幀,讀幀前等待更新",+ "en": "VSync: one-frame display queue, waits for the refresh before reading a frame",+ "ja": "垂直同期:画面キュー 1 フレーム、フレーム読み込み前にリフレッシュを待機"+ },+ {+ "zh": "垂直同步:屏幕队列控制不可用",+ "src": "src/engine/VideoPresenter.cpp",+ "zh-TW": "垂直同步:螢幕佇列控制不可用",+ "en": "VSync: display queue control unavailable",+ "ja": "垂直同期:画面キューの制御は使用不可"+ },+ {+ "zh": "显示队列恢复失败",+ "src": "src/engine/VideoPresenter.cpp",+ "zh-TW": "顯示佇列恢復失敗",+ "en": "Display queue restore failed",+ "ja": "表示キューの復元に失敗"+ },+ {+ "zh": "低延迟队列:只保留一帧在处理",+ "src": "src/engine/VideoPresenter.cpp",+ "zh-TW": "低延遲佇列:只保留一幀在處理",+ "en": "Low-latency queue: one frame in flight",+ "ja": "低遅延キュー:処理中は 1 フレームのみ"+ },+ {+ "zh": "显示队列等待失败,垂直同步屏幕队列不再限制;详见日志",+ "src": "src/engine/EngineController.cpp",+ "zh-TW": "顯示佇列等待失敗,垂直同步螢幕佇列不再限制;詳見日誌",+ "en": "Display queue wait failed; the VSync display queue is no longer limited; see the log",+ "ja": "表示キューの待機に失敗。垂直同期の画面キューは制限されなくなりました。ログを参照"+ },+ {+ "zh": "不撕裂,也不等待垂直同步(延迟最低)",+ "src": "src/engine/VideoPresenter.cpp",+ "zh-TW": "不撕裂,也不等待垂直同步(延遲最低)",+ "en": "no tearing and no VSync wait (lowest latency)",+ "ja": "ティアリングなし、垂直同期を待たない(最小遅延)"+ },+ {+ "zh": "低延迟队列:只保留一帧在处理(补帧运行,Reflex 不启用)",+ "src": "src/engine/VideoPresenter.cpp",+ "zh-TW": "低延遲佇列:只保留一幀在處理(補幀運行,Reflex 不啟用)",+ "en": "Low-latency queue: one frame in flight (frame generation running, Reflex off)",+ "ja": "低遅延キュー:処理中は 1 フレームのみ(フレーム生成中のため Reflex は無効)"+ },+ {+ "zh": "低延迟队列:只保留一帧在处理 + NVIDIA Reflex(实验)",+ "src": "src/engine/VideoPresenter.cpp",+ "zh-TW": "低延遲佇列:只保留一幀在處理 + NVIDIA Reflex(實驗)",+ "en": "Low-latency queue: one frame in flight + NVIDIA Reflex (experimental)",+ "ja": "低遅延キュー:処理中は 1 フレームのみ + NVIDIA Reflex(実験的)"+ },+ {+ "zh": "低延迟队列:只保留一帧在处理(Reflex 初始化失败)",+ "src": "src/engine/VideoPresenter.cpp",+ "zh-TW": "低延遲佇列:只保留一幀在處理(Reflex 初始化失敗)",+ "en": "Low-latency queue: one frame in flight (Reflex initialization failed)",+ "ja": "低遅延キュー:処理中は 1 フレームのみ(Reflex の初期化に失敗)"+ },+ {+ "zh": "显示同步:自动",+ "src": "src/engine/VideoPresenter.cpp",+ "zh-TW": "顯示同步:自動",+ "en": "Display sync: auto",+ "ja": "表示の同期:自動"}]}diff --git a/include/veyra/engine/DisplayFgBudget.h b/include/veyra/engine/DisplayFgBudget.hindex 18538162..e45b94a2 100644--- a/include/veyra/engine/DisplayFgBudget.h+++ b/include/veyra/engine/DisplayFgBudget.h@@ -15,14 +15,17 @@ namespace veyra::engine {// 1. the output fits the refresh (content x M <= 1.02 x refresh): unchanged;// 2. otherwise the largest supported multiplier whose output fits;// 3. if none fits but the source is slower than the panel (60 fps on a-// 100 Hz panel), 2X: it still shows more distinct pictures per refresh;+// 100 Hz panel), 2X: Automatic replaces the surplus at each refresh and+// still shows more distinct pictures per refresh. Under VSync (queued)+// the surplus would wait in the display queue instead, so bypass;// 4. if the source alone already fills the panel (>= 0.97 x refresh, e.g.// 60 fps on 60 Hz), bypass generation: no generated picture can add a// refresh, and real frames present as soon as they are enhanced instead// of waiting half an interval behind a generated one.// XeSS changes its interpolation count only through a model switch Intel// documents as expensive (shader compilation), so XeSS keeps the requested-// multiplier and only rule 4 applies (xefgSwapChainSetEnabled).+// multiplier and only bypasses (xefgSwapChainSetEnabled): under rule 4, and+// under VSync whenever its output does not fit.inline constexpr double kDisplayFgFitTolerance=1.02;inline constexpr double kDisplayFgFillRatio=0.97;@@ -38,14 +41,16 @@ constexpr bool displayFgMultiplierSupported(FrameGenerationBackend backend,unsig}// 0 = bypass generation, otherwise a multiplier in [2, requested].-// Unknown rates keep the request.-inline unsigned displayFgMultiplier(FrameGenerationBackend backend,unsigned requested,double contentFps,double refreshHz){+// queued: presents above the refresh wait in the display queue (VSync)+// instead of being replaced (Automatic). Unknown rates keep the request.+inline unsigned displayFgMultiplier(FrameGenerationBackend backend,unsigned requested,double contentFps,double refreshHz,bool queued=false){if(requested<2||!std::isfinite(contentFps)||!std::isfinite(refreshHz)||contentFps<=0||refreshHz<=0)return requested;if(contentFps>=refreshHz*kDisplayFgFillRatio)return 0;- if(contentFps*requested<=refreshHz*kDisplayFgFitTolerance||backend==FrameGenerationBackend::XeSS)return requested;+ if(contentFps*requested<=refreshHz*kDisplayFgFitTolerance)return requested;+ if(backend==FrameGenerationBackend::XeSS)return queued?0:requested;for(unsigned m=requested-1;m>=2;--m)if(displayFgMultiplierSupported(backend,m)&&contentFps*m<=refreshHz*kDisplayFgFitTolerance)return m;- return 2;+ return queued?0:2;}// A changed decision applies only after it held for the whole hold time, so adiff --git a/include/veyra/engine/VideoPresenter.h b/include/veyra/engine/VideoPresenter.hindex 7fbeaf01..6231c545 100644--- a/include/veyra/engine/VideoPresenter.h+++ b/include/veyra/engine/VideoPresenter.h@@ -39,6 +39,7 @@ public:void sourceProcessed(pipeline::FrameIdentity);PresentationSettings configurePresentation(gfx::D3D12DeviceContext&,PresentationSettings,bool fg,std::wstring& status);bool presentationReady(){return sink_.presentationReady();}+ bool waitPresentationReady(unsigned ms){return sink_.waitPresentationReady(ms);}uint64_t beginReflex(){return reflex_.begin();}void reflexFrame(uint64_t id){reflexFrame_=id;}// True while XeSS owns Present: the low-latency queue and the outputdiff --git a/include/veyra/gfx/PresentSink.h b/include/veyra/gfx/PresentSink.hindex 6ccded50..d5dc6575 100644--- a/include/veyra/gfx/PresentSink.h+++ b/include/veyra/gfx/PresentSink.h@@ -134,7 +134,11 @@ public:// The owner re-reads the monitor after a move or mode change.void setDisplayRefreshHz(double hz){if(hz>=1.0)displayRefreshHz_=hz;}bool configurePacing(bool enabled,bool vsync,bool tearing);- bool presentationReady();+ // Acquires one present of display-queue capacity (the frame latency+ // object) while pacing; the next Present consumes it. Never blocks with+ // ms=0. True when not pacing.+ bool waitPresentationReady(unsigned ms);+ bool presentationReady(){return waitPresentationReady(0);}bool pacingActive()const{return pacing_;}void resize(uint32_t width, uint32_t height);diff --git a/qml/Veyra/NodePage.qml b/qml/Veyra/NodePage.qmlindex 9db73aaf..c31599a6 100644--- a/qml/Veyra/NodePage.qml+++ b/qml/Veyra/NodePage.qml@@ -1565,7 +1565,7 @@ VPage {}VRow {label: qsTr("低延迟队列")- hint: qsTr("减少排队;不宣称延迟下降")+ hint: qsTr("只保留一帧在处理,未补帧时加 Reflex")VSwitch { checked: veyra.fgLowQueue; onToggled: checked => veyra.fgLowQueue = checked }}}diff --git a/qml/Veyra/ProPage.qml b/qml/Veyra/ProPage.qmlindex a6b5046d..0a924d30 100644--- a/qml/Veyra/ProPage.qml+++ b/qml/Veyra/ProPage.qml@@ -1815,7 +1815,7 @@ VPage {}VRow {label: qsTr("低延迟队列")- hint: qsTr("减少软件排队;屏幕延迟需要实测")+ hint: qsTr("只保留一帧在处理,未补帧时加 NVIDIA Reflex;垂直同步本身已不排队")VSwitch {objectName: "list-low-queue"checked: veyra.fgLowQueuediff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cppindex 749ec71d..9a620f80 100644--- a/src/engine/EngineController.cpp+++ b/src/engine/EngineController.cpp@@ -1130,6 +1130,12 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sif(!isImage){liveScheduler=std::make_unique<LiveGpuScheduler>();veyra::log::info("scheduler",std::format("single GPU owner thread={} capacity=2 source={} (bounded enhanced lookahead)",GetCurrentThreadId(),isCapture?"live":"file"));}PresentationCadence cadence;PresentationSettings presentationEffective;+ // presentationPaced: VSync keeps a one-deep display queue (latency+ // object). A failed wait turns pacing off for this configuration.+ // VEYRA_TEST_LEGACY_VSYNC_QUEUE=1 restores the unwaited VSync queue+ // (no read gate, waits only with the toggle/cap) for A/B runs.+ bool presentationPaced=false;+ static const bool legacyVsyncQueue=GetEnvironmentVariableW(L"VEYRA_TEST_LEGACY_VSYNC_QUEUE",nullptr,0)>0;uint64_t pacingRevision=0,presenterGeneration=0;auto applyPresentation=[&]{PresentationSettings requested;uint64_t revision;@@ -1140,21 +1146,20 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sif(presentationEffective.enabled&&!presenter.reflexActive()&&presenter.reflexDisablePending()){std::lock_guard lock(mutex_);snapshot_.presentationEffective=presentationEffective;snapshot_.presentationStatus=presenter.reflexDisablePending()?L"Reflex 调用及驱动撤销失败;请关闭视频后重试":L"Reflex 调用失败,当前使用低排队;详见日志";}- if(presentationEffective.enabled&&!presenter.pacingActive()){- presentationEffective.enabled=false;- std::wstring message;- presentationEffective=presenter.configurePresentation(ctx,presentationEffective,options.fg,message);- cadence.reset();- std::lock_guard lock(mutex_);snapshot_.presentationEffective=presentationEffective;snapshot_.presentationStatus=L"显示队列等待失败;"+message;+ if(presentationPaced&&!presenter.pacingActive()){+ // The sink already stopped waiting; reconfiguring would arm it again.+ presentationPaced=false;cadence.reset();+ std::lock_guard lock(mutex_);snapshot_.presentationStatus=L"显示队列等待失败,垂直同步屏幕队列不再限制;详见日志";}return;}if(isImage)requested.enabled=false;std::wstring message;presentationEffective=presenter.configurePresentation(ctx,requested,options.fg,message);+ presentationPaced=presenter.pacingActive()&&!legacyVsyncQueue;pacingRevision=revision;presenterGeneration=presenter.generation();cadence.reset();{std::lock_guard lock(mutex_);snapshot_.presentationEffective=presentationEffective;snapshot_.presentationRevision=revision;snapshot_.presentationStatus=message;snapshot_.presentationProviderOwned=presenter.providerOwnedPresentation();}- veyra::log::info("pacing",std::format("revision={} requested={}/{}/{} effective={}/{}/{}",revision,requested.enabled,unsigned(requested.mode),unsigned(requested.display),presentationEffective.enabled,unsigned(presentationEffective.mode),unsigned(presentationEffective.display)));+ veyra::log::info("pacing",std::format("revision={} requested={}/{}/{} effective={}/{}/{} displayQueuePaced={}",revision,requested.enabled,unsigned(requested.mode),unsigned(requested.display),presentationEffective.enabled,unsigned(presentationEffective.mode),unsigned(presentationEffective.display),presentationPaced));};auto drainLivePresentation=[&]{cadence.reset();if(liveScheduler){++presentationDrains;liveScheduler->cancel();pollCompletions();pendingCompletions.clear();}pairLatency.reset();};auto advanceLive=[&]{applyPresentation();if(liveScheduler){pollCompletions();if(stop_||(paused_&&!seekPreviewPending)||seekSeconds_>=0){liveScheduler->cancel();cadence.reset();}else liveScheduler->advance(host100ns());}};@@ -1542,6 +1547,11 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sconst auto enhancementPending=[&]{const bool fgRunning=options.fg&&!fgBypassed;if(presentationEffective.enabled&&!fgRunning&&(isCapture||!fileAwaitingVideo)&&liveScheduler->occupancy()>=1)return true;+ // Explicit VSync, live, no generation: throttle only before the+ // read. A frame read while the display queue is full would wait+ // there a refresh; waiting first lets the mailbox hand over a+ // newer frame instead (latency-min B3).+ if(isCapture&&presentationPaced&&!fgRunning&&(liveScheduler->occupancy()>=1||!presenter.presentationReady()))return true;// Live sources: never stack a second frame behind one the GPU// is still enhancing. When NR/SR cost more than one source// interval, a second queued frame doubled capture-to-present@@ -1554,7 +1564,12 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,swhile((liveScheduler->occupancy()>=2||!graph->nextFrameSlotAvailable()||enhancementPending())&&!stop_&&(!paused_||seekPreviewPending)&&!liveScheduler->failed()){advanceLive();if(seekSeconds_>=0)break;if(liveScheduler->occupancy()==0&&!graph->nextFrameSlotAvailable()&&elapsedMs(leaseWaitStart)>2000){status(L"等待输出纹理释放超时",true);stop_=true;break;}- if(liveScheduler->occupancy()>=2||!graph->nextFrameSlotAvailable()||enhancementPending())waitLive();+ if(liveScheduler->occupancy()>=2||!graph->nextFrameSlotAvailable()||enhancementPending()){+ // Only the display queue is outstanding: wake on its latency object+ // (acquiring it) instead of a 1 ms poll.+ if(isCapture&&presentationPaced&&liveScheduler->occupancy()==0&&pendingCompletions.empty()&&graph->nextFrameSlotAvailable())presenter.waitPresentationReady(1);+ else waitLive();+ }std::lock_guard lock(mutex_);if(desired_.revision!=options.settings.revision)break;}if(stop_||seekSeconds_>=0||(paused_&&!seekPreviewPending)||liveScheduler->failed()||liveScheduler->occupancy()>=2||!graph->nextFrameSlotAvailable()||enhancementPending())continue;@@ -1904,7 +1919,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s// measured cadence and decides nothing until it has one.contentFps=dedupActive?contentDedup.contentFps():activeSource->info().averageFps*(halfRate?.5:1.0);refreshHz=displayFgTestHz>0?displayFgTestHz:presenter.displayRefreshHz();- if(contentFps>0&&refreshHz>0&&displayFgGate.update(displayFgMultiplier(options.settings.frameGenerationBackend,options.fgMultiplier,contentFps,refreshHz),host100ns())){+ if(contentFps>0&&refreshHz>0&&displayFgGate.update(displayFgMultiplier(options.settings.frameGenerationBackend,options.fgMultiplier,contentFps,refreshHz,presentationVsync(presentationEffective)),host100ns())){const auto applied=displayFgGate.applied();veyra::log::info("display-fg-budget",std::format("revision={} backend={} requested={}X applied={} contentFps={:.3f} refreshHz={:.3f}{} dedup={} halfRate={} display={} (output above the refresh is never shown: lower multiplier, or bypass when the source already fills the panel)",options.settings.revision,frameGenerationBackendName(options.settings.frameGenerationBackend),options.fgMultiplier,applied?std::format("{}X",applied):std::string("bypass"),contentFps,refreshHz,displayFgTestHz>0?" (test override)":"",dedupActive,halfRate,unsigned(presentationEffective.display)));@@ -2196,7 +2211,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s}struct LiveStepState {unsigned next=0,handled=0,remaining=0;bool readyReported=false;- Clock::time_point readyStart=Clock::now();std::optional<Clock::time_point> deadlineStart;+ Clock::time_point readyStart=Clock::now();std::optional<Clock::time_point> deadlineStart,capacityStart;double readyMs=0,waitMs=0,presentMs=0,ageMs=0;uint64_t count=0,dropped=0;diagnostics::GpuSample blit;};@@ -2294,8 +2309,21 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s// instead of accumulating latency.if(capInterval>0&&cadence.rateSkipsCandidate(optionalNow,mediaDeadline,interval,capInterval)){++s.dropped;++s.handled;++s.next;s.deadlineStart.reset();continue;}if(optionalNow<due)return {State::Pending,due};- if(!presenter.presentationReady())return {State::Pending,optionalNow+2000};}+ // Explicit VSync: one present of display capacity per present, so a+ // frame never waits in DXGI's queue (true when not paced). A generated+ // frame waits at most half its interval (<= 2 ms) and is otherwise+ // replaced by the next one: waiting longer only moved the queue into+ // this scheduler and held the real frame behind it (DLSS 6X replay+ // on 320 Hz: callback->present P95 18.4 -> 34.2 ms). The real frame waits.+ if((!legacyVsyncQueue||presentationEffective.enabled||presentationEffective.outputRate==OutputRateMode::Custom)&&!presenter.presentationReady()){+ if(generated&&!legacyVsyncQueue){+ if(!s.capacityStart)s.capacityStart=Clock::now();+ if(elapsedMs(*s.capacityStart)>std::min(2.0,sourceIntervalMs/std::max(1u,batch.batch.count)/2)){++s.dropped;++s.handled;++s.next;s.deadlineStart.reset();s.capacityStart.reset();continue;}+ }+ return {State::Pending,optionalNow+2000};+ }+ s.capacityStart.reset();const auto waited=elapsedMs(*s.deadlineStart);s.deadlineStart.reset();s.waitMs+=waited;flow->cpu(diagnostics::CpuStage::DeadlineWait,waited,host100ns());const bool deviationValid=!isCapture&&!isImage&&!fileAwaitingVideo&&!paused_;const double entryDeviation=deviationValid?nowMs()-itemPtsMs:0;diff --git a/src/engine/VideoPresenter.cpp b/src/engine/VideoPresenter.cppindex 9ec4f46f..697fc869 100644--- a/src/engine/VideoPresenter.cpp+++ b/src/engine/VideoPresenter.cpp@@ -489,26 +489,32 @@ PresentationSettings VideoPresenter::configurePresentation(gfx::D3D12DeviceContereturn effective;}providerOwnedPresentation_=false;- if(!requested.enabled){- // Vertical sync with the default 3-frame queue lets presents pile up behind the- // refresh: on a 60 Hz panel that is up to ~50 ms, and a capture user measured- // "twice 1.4.4's latency" with 2.0 on vsync against 1.4.4 on tearing (field logs- // 2026-10-01). Under vsync the queue stays one deep even without 低延迟队列.- const bool shallow=vsync&&sink_.configurePacing(true,vsync,tearing);- const bool restored=shallow||sink_.configurePacing(false,vsync,tearing);- status=(shallow?L"垂直同步 · 队列深度 1 · ":restored?L"低延迟队列已关闭 · ":L"低延迟队列恢复失败 · ")+sync;if(effective.outputRate==OutputRateMode::Custom)status+=std::format(L" · 输出上限 {:.3f} FPS",effective.customFps);status+=capNotice;return effective;}- if(!sink_.configurePacing(true,vsync,tearing)){effective.enabled=false;status=L"显示队列控制不可用 · "+sync;return effective;}- // Low latency = queue depth 1, plus Reflex when frame generation is off- // (generated outputs would need separately validated out-of-band markers).- std::wstring latency=L"低延迟队列:队列深度 1";- if(fg)latency+=L"(补帧运行,Reflex 不启用)";- else if(reflex_.enable(ctx.device()))latency=L"低延迟队列:队列深度 1 + NVIDIA Reflex(实验)";- else latency+=L"(Reflex 初始化失败)";+ // Only explicit VSync can queue presents behind the display, so only VSync+ // keeps a one-deep display queue, and the engine really waits for it: it+ // acquires the latency object before reading the next capture frame+ // (without frame generation) and before every present, so no frame sits+ // in DXGI's queue. Before latency-min B3 VSync set latency 1 without+ // anyone waiting, which does not limit the queue (7 frames in the DXGI+ // probe; DLSS 6X on 320 Hz 12.2/18.4 ms present->scanout, field: "twice+ // 1.4.4's latency" on a 60 Hz panel, 2026-10-01). Automatic replaces an+ // unshown frame and Tearing never waits: acquiring the latency object+ // there would throttle presents to the refresh, the wait they avoid.+ const bool paced=vsync&&sink_.configurePacing(true,vsync,tearing);+ const bool restored=paced||sink_.configurePacing(false,vsync,tearing);+ const std::wstring queue=paced?L"垂直同步:屏幕队列 1 帧,读帧前等待刷新 · ":vsync?L"垂直同步:屏幕队列控制不可用 · ":restored?L"":L"显示队列恢复失败 · ";std::wstring cap;if(followDisplay)cap=std::format(L"输出上限:跟随显示器 {:.0f} Hz",requested.customFps);else if(requested.outputRate==OutputRateMode::Custom)cap=std::format(L"输出上限:{:.3f} FPS",requested.customFps);else cap=L"输出上限:关闭";- status=latency+L" · "+cap+L" · "+sync;+ if(!requested.enabled){status=queue+sync;if(effective.outputRate==OutputRateMode::Custom)status+=L" · "+cap;status+=capNotice;return effective;}+ // Low-latency queue: one source frame in flight (the next input is read+ // after the previous one was presented), plus Reflex when frame generation+ // is off (generated outputs would need separately validated markers).+ std::wstring latency=L"低延迟队列:只保留一帧在处理";+ if(fg)latency+=L"(补帧运行,Reflex 不启用)";+ else if(reflex_.enable(ctx.device()))latency+=L" + NVIDIA Reflex(实验)";+ else latency+=L"(Reflex 初始化失败)";+ status=latency+L" · "+cap+L" · "+queue+sync;return effective;}Microsoft::WRL::ComPtr<ID3D12Resource> VideoPresenter::presentedResourceForTest() {diff --git a/src/gfx/PresentSink.cpp b/src/gfx/PresentSink.cppindex a49aa973..c409fa4f 100644--- a/src/gfx/PresentSink.cpp+++ b/src/gfx/PresentSink.cpp@@ -544,13 +544,33 @@ bool PresentSink::configurePacing(bool enabled,bool vsync,bool tearing){// Do not install another latency waiter on the provider swap chain.if(xess_){pacing_=false;capacityAcquired_=false;desc_.vsync=xess_&&vsync;desc_.tearing=tearing;log::info("pacing",std::format("provider={} applicationWait=0 vsync={} tearing={}","XeSS",desc_.vsync,desc_.tearing));return !enabled;}const HRESULT hr=latencyHandle_?swapChain_->SetMaximumFrameLatency(enabled?1:3):enabled?E_NOTIMPL:S_OK;- log::info("pacing",std::format("DXGI enabled={} maximumLatency={} vsync={} tearing={} hr=0x{:X}",enabled,enabled?1:3,vsync,tearing,unsigned(hr)));pacing_=enabled&&SUCCEEDED(hr);desc_.vsync=vsync;desc_.tearing=tearing;capacityAcquired_=false;+ unsigned stale=0;+ if(pacing_){+ // Re-arm. The latency object keeps the counts released while nobody+ // waited (latency 3 outside VSync), and one wait per present only holds+ // whatever queue depth existed at the switch. Probe 2026-10-14+ // (tmp/claude-latency-min-20261013/dxgi_semaphore_probe.cpp, 320 Hz):+ // after 600 unwaited Automatic presents the waits never blocked and+ // 7 presents stayed queued; with the stale counts dropped the depth+ // matched a fresh chain. Let queued presents retire (bounded), drop the+ // counts, then allow exactly one present before the first wait, so an+ // empty queue (paused, first frame) cannot stall on a count that never comes.+ const auto until=GetTickCount64()+100;+ for(;;){+ UINT last=0;DXGI_FRAME_STATISTICS stats{};+ if(FAILED(swapChain_->GetLastPresentCount(&last))||FAILED(swapChain_->GetFrameStatistics(&stats))||last==stats.PresentCount||GetTickCount64()>until)break;+ Sleep(1);+ }+ while(stale<4096&&WaitForSingleObject(latencyHandle_,0)==WAIT_OBJECT_0)++stale;+ capacityAcquired_=true;+ }+ log::info("pacing",std::format("DXGI enabled={} maximumLatency={} vsync={} tearing={} hr=0x{:X} staleLatencyCounts={}",enabled,enabled?1:3,vsync,tearing,unsigned(hr),stale));return SUCCEEDED(hr);}-bool PresentSink::presentationReady(){+bool PresentSink::waitPresentationReady(unsigned ms){if(!pacing_||!latencyHandle_||capacityAcquired_)return true;- const auto result=WaitForSingleObject(latencyHandle_,0);+ const auto result=WaitForSingleObject(latencyHandle_,ms);if(result==WAIT_OBJECT_0)capacityAcquired_=true;if(result==WAIT_FAILED){log::warn("pacing",std::format("DXGI capacity wait failed error={}",GetLastError()));configurePacing(false,desc_.vsync,desc_.tearing);return true;}return capacityAcquired_;diff --git a/tests/unit/RealtimePreviewSchedulingTests.cpp b/tests/unit/RealtimePreviewSchedulingTests.cppindex f70ee4e7..2795b517 100644--- a/tests/unit/RealtimePreviewSchedulingTests.cpp+++ b/tests/unit/RealtimePreviewSchedulingTests.cpp@@ -155,6 +155,11 @@ int main() {check(displayFgMultiplier(B::XeSS, 4, 60, 144) == 4, "XeSS keeps its multiplier unless bypassed");check(displayFgMultiplier(B::Dlss, 6, 0, 60) == 6 && displayFgMultiplier(B::Dlss, 6, 60, 0) == 6, "unknown rates keep the request");check(displayFgMultiplier(B::Dlss, 1, 60, 60) == 1, "no generation requested stays unchanged");+ check(displayFgMultiplier(B::Dlss, 6, 60, 100, true) == 0, "under VSync 60 fps on 100 Hz bypasses: the surplus would queue");+ check(displayFgMultiplier(B::Dlss, 6, 60, 320, true) == 4, "under VSync a fitting lower multiplier is still used");+ check(displayFgMultiplier(B::Dlss, 2, 30, 60, true) == 2, "under VSync a fitting request is unchanged");+ check(displayFgMultiplier(B::XeSS, 4, 60, 144, true) == 0, "under VSync XeSS bypasses when its output does not fit");+ check(displayFgMultiplier(B::XeSS, 2, 60, 144, true) == 2, "under VSync a fitting XeSS request is unchanged");DisplayFgBudgetGate gate(15000000);check(gate.update(4, 0) && gate.applied() == 4, "first budget decision applies at once");