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++
fix: reanchor live frame-generation deadlines
Veyra Goal Agentebba6f1f686f
diff --git a/apps/veyra/ui/LiveStatusDashboard.h b/apps/veyra/ui/LiveStatusDashboard.hindex 0ac0a8d4..d360388f 100644--- a/apps/veyra/ui/LiveStatusDashboard.h+++ b/apps/veyra/ui/LiveStatusDashboard.h@@ -66,7 +66,7 @@ inline void paintDashboard(HWND h,HDC dc,int w,int height,const engine::PlayerSnstd::wstring status=L"待机";COLORREF color=RGB(145,151,149);if(s.failed){status=L"错误";color=RGB(245,86,86);}else if(s.remoteRecovering){status=L"恢复中";color=RGB(242,185,65);}- else if(active&&!s.applying&&f.rateWindowReady){status=history.overloaded?L"过载":L"正常";color=history.overloaded?RGB(242,185,65):RGB(111,211,127);}+ else if(active&&!s.applying&&f.rateWindowReady){status=history.overloaded?L"补帧受限":L"正常";color=history.overloaded?RGB(242,185,65):RGB(111,211,127);}else if(s.applying&&s.running)status=L"调整中";else if(active)status=L"采样中";else if(s.transport==engine::TransportState::Paused)status=L"已暂停";text(L"当前状态",26+bw,bottom+6,bw-20,18,10,secondary);{AlphaGraphics draw(dc);Gdiplus::SolidBrush dot(Gdiplus::Color(255,GetRValue(color),GetGValue(color),GetBValue(color)));draw.get().FillEllipse(&dot,dip(h,27+bw),dip(h,bottom+35),dip(h,8),dip(h,8));}diff --git a/docs/CAPTURE_FG_CLOCK_REPAIR_2026-09-14.md b/docs/CAPTURE_FG_CLOCK_REPAIR_2026-09-14.mdnew file mode 100644index 00000000..15fd71cc--- /dev/null+++ b/docs/CAPTURE_FG_CLOCK_REPAIR_2026-09-14.md@@ -0,0 +1,43 @@+# 采集卡内部 FG 时间线修复(2026-09-14)++## 基线与范围++- 修复分支:`codex/capture-fg-clock-repair-20260914`+- 修复前回退 checkpoint:`d9a94eb`(`chore: checkpoint before capture FG clock repair`)+- 本轮只修实时采集/测试回放的 FG 时间锚定、诊断和状态文案;不修改 NVIDIA runtime、SDK、FFmpeg 或用户已有的采集音频设备选择改动。++## 根因++物理采集开启内部 FG 时,旧路径把源 PTS 在会话开始时一次性映射到主机时间。采集卡实际回调约 59.94fps,而协商/名义节奏约 60fps,约 0.1% 的差异会在几分钟内累积为数百毫秒的截止时间误差。程序随后把已经来不及的 FG 候选全部拒绝,UI 将持续低于目标输出误报为“过载”。++反馈日志中同时出现 `callbackFps=59.94`、`gpuReadyP95Ms` 约 2.9ms、`gpuFgBatchP95Ms` 约 5.7ms,但 `remainingDeadlineMs` 已为约 -289ms;这不是 NR/SR 或 GPU OOM。++## 修复内容++1. `PresentationScheduler` 增加 `resetPair()`,明确区分连续文件时间线和 live 输入对时间线。+2. 物理采集、PS5 和 file-backed live replay 在 FG 路径中按每个新 A/B 对重新锚定到输入到达时间。源 PTS 仍用于历史、运动和 FG 插值;当前 A/B 对内部仍按 PTS 间隔保持生成帧与真实帧的节奏。+3. DLSS FG 在 `Evaluate` 前重新锚定,准入预算不会因为旧时间线漂移而被伪造放宽;XeSS/live FG 在呈现前也使用同一对帧锚点。+4. 实时状态从“过载”改为“补帧受限”,避免把软件截止时间不足冒充物理 GPU 过载。+5. 合同测试新增 59.94/60Hz 五分钟漂移模拟:单一锚点会落后约 300ms,逐对锚定的 FG 截止时间保持在当前输入对内。++## 实际验证++构建命令:++```powershell+powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\scripts\build.ps1 -Root 'C:\Users\123\Desktop\Veyra DLSS Video Player' -Preset x64-release -BuildDirectory 'C:\Users\123\Desktop\Veyra DLSS Video Player\out\build\capture-fg-clock-repair' -FfmpegRoot 'C:\veyra-deps\ffmpeg-ps5-dav1d-installed'+```++- 首次完整构建:216/216,exit 0。+- 最终增量重建:20/20,exit 0。+- `veyra_repair_contract_tests.exe`:109 checks,0 failures。+- `veyra_live_timing_tests.exe`:全部 PASS。+- `veyra_presentation_worker_tests.exe`:全部 PASS。+- `veyra_fg_admission_tests.exe dlss 2/3/4 ...`:三种倍率均 exit 0;DLSS Create/Evaluate、40 原帧、NR 40 次、D3D12 debug errors=0。+- `veyra_live_presentation_tests.exe ... --overload`:资源边界、准入统计、关闭释放均 PASS;日志记录 `timeline=capture-pair`。+- `veyra_live_presentation_tests.exe ... --source-gap`:源等待、恢复、EOF 排空、跨 epoch 全部 PASS,`EOS frames=3600 ready=3600 presented=3600 cancelled=0`。+- `git diff --check`:通过。++## 未完成的实卡边界++本轮没有占用用户采集卡,也没有在用户的 RTX 4070 Ti 与 RTX 5070 上做同素材 A/B;没有测量显示器 scanout、温度、功耗或实际物理屏幕延迟。因此不能把自动化回放通过写成用户实卡已经验收。下一步应使用修复后的程序,在原始采集格式、NR/SR 关闭、内部 DLSS FG 开启的相同条件下重新采集 30–60 秒日志,确认 `timeline=capture-pair` 且截止时间不再单调跌入数百毫秒负值。diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex 09f815ae..354194c2 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -1,5 +1,11 @@# 2026-09-11 继续修复目标模式执行中+## 2026-09-14 采集卡内部 FG 时间线修复++用户反馈 RTX 4070 Ti 开启内部 FG、NR/SR 关闭后很快显示过载。排查确认物理采集的源 PTS 与主机回调时钟存在 59.94/60Hz 长期漂移;旧代码只在会话开始锚定一次,导致补帧截止时间累积落后数百毫秒,软件准入连续拒绝 FG,并非已证实的 GPU OOM 或 NR/SR 负载。已在 `codex/capture-fg-clock-repair-20260914` 分支修复:物理采集/PS5/live replay 按每个 A/B 对重新锚定,保留对内 FG 节奏;新增 `timeline=capture-pair` 诊断,UI 将“过载”改为“补帧受限”。++修复前 checkpoint 为 `d9a94eb`。完整构建 216/216、最终增量构建 20/20;合同测试 109/109、实时计时、呈现 worker、DLSS 2/3/4 准入及 live overload/source-gap 回归通过。详细命令、日志和未完成的 RTX 4070 Ti 实卡验收边界见 [采集卡内部 FG 时间线修复](CAPTURE_FG_CLOCK_REPAIR_2026-09-14.md)。未 push/发布。+## 2026-09-14 采集卡音频设备选择修复用户反馈“采集卡对应音频在 Veyra 中选不到、OBS 可以选择”。静态排查确认原实现只枚举全局独立 DirectShow 音频 filter,未使用选中视频 filter 的内置音频 pin,也用易变整数序号重新绑定设备。本轮已修复内置音频路径、独立音频 DevicePath 绑定、`capture2:` 连接串和音频 pin/media type 诊断;旧 `capture:` 路径兼容。详细范围、命令、结果和未测边界见 [采集卡音频设备选择修复](CAPTURE_AUDIO_DEVICE_SELECTION_REPAIR_2026-09-14.md)。diff --git a/include/veyra/engine/PresentationScheduler.h b/include/veyra/engine/PresentationScheduler.hindex f084655c..571c48e4 100644--- a/include/veyra/engine/PresentationScheduler.h+++ b/include/veyra/engine/PresentationScheduler.h@@ -1,15 +1,19 @@#pragma once#include <cstdint>namespace veyra::engine {-// Maps a continuous source epoch to one monotonic host timeline. Processing-// completion must never re-anchor individual pairs. PS5 may explicitly reset-// per newly decoded input pair (before enhancement) because its PTS is locally-// estimated and decoder delivery jitter is not playback lateness. Units: 100 ns.+// Maps source timestamps to a monotonic host timeline. File playback keeps a+// continuous source anchor; live sources may explicitly re-anchor each input+// pair before enhancement because their device/source clock is not guaranteed+// to match the host clock. Processing completion must never re-anchor a pair.+// Units: 100 ns.class PresentationScheduler {public:void reset(uint64_t epoch,int64_t source,int64_t host,int64_t lookahead,bool paceSourcePts=true) {epoch_=epoch;source_=source;host_=host;delay_=lookahead;anchored_=true;paced_=paceSourcePts;}+ void resetPair(uint64_t epoch,int64_t source,int64_t host,int64_t lookahead,bool paceSourcePts=true) {+ reset(epoch,source,host,lookahead,paceSourcePts);+ }bool anchored(uint64_t epoch)const{return anchored_&&epoch==epoch_;}// Unbuffered capture is ready-driven. A late first callback or clock drift// must not turn its source timestamps into a persistent presentation hold.diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cppindex 5a2afcad..51239c2a 100644--- a/src/engine/EngineController.cpp+++ b/src/engine/EngineController.cpp@@ -127,6 +127,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s(void)remoteRequest;const bool isRemote=false;#endifconst bool isCapture=physicalCapture||options.captureReplayForTest||isRemote;+ const bool pairAnchoredLive=physicalCapture||options.captureReplayForTest||isRemote;const bool useLiveFgAdmission=!(options.captureReplayForTest&&options.captureReplayDisableFgAdmissionForTest);source::IFrameSource* activeSource=physicalCapture?static_cast<source::IFrameSource*>(&captureSource):&source;#ifdef VEYRA_ENABLE_REMOTEPLAY@@ -631,18 +632,20 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sif(isCapture&&!rereadCached&&useLiveFgAdmission&&options.settings.frameGenerationBackend!=FrameGenerationBackend::XeSS){const auto presentP95=livePresent.p95();admitFg=[&,presentP95](const pipeline::FrameBatch& batch){- // PS5 decode/network delivery jitters independently of- // its estimated PTS. Give each newly decoded pair its- // one-input-interval budget, anchored BEFORE enhancement.+ // Physical capture and PS5 delivery clocks are not+ // guaranteed to match the host clock. Anchor each new+ // input pair before enhancement, so a 59.94-vs-60Hz+ // mismatch cannot accumulate into a stale deadline.// Never extend it based on processing/ready completion.- if(isRemote||!liveTimeline.anchored(batch.identity.epoch))liveTimeline.reset(batch.identity.epoch,batch.b100ns,liveInputReady,liveSourceInterval100ns(pkt.duration,activeSource->info().averageFps));+ if(pairAnchoredLive)liveTimeline.resetPair(batch.identity.epoch,batch.b100ns,liveInputReady,liveSourceInterval100ns(pkt.duration,activeSource->info().averageFps));+ else if(!liveTimeline.anchored(batch.identity.epoch))liveTimeline.reset(batch.identity.epoch,batch.b100ns,liveInputReady,liveSourceInterval100ns(pkt.duration,activeSource->info().averageFps));const auto interval=liveSourceInterval100ns(pkt.duration,activeSource->info().averageFps);const auto a=(historyReset||batch.b100ns<=batch.a100ns||batch.b100ns-batch.a100ns>10000000)?batch.b100ns-interval:batch.a100ns;const auto lastGenerated=pipeline::FrameBatch::interpolate(a,batch.b100ns,options.fgMultiplier-1,options.fgMultiplier);const auto now=host100ns(),deadline=liveTimeline.deadline(lastGenerated);const double elapsed=elapsedMs(processStart);const bool admitted=fgBudget.admit(now,deadline,elapsed,presentP95);- if(now>=nextFgAdmissionLog){nextFgAdmissionLog=now+10000000;veyra::log::info("live-fg-admission",std::format("admitted={} remainingDeadlineMs={:.3f} predictedMs={:.3f} elapsedMs={:.3f} decodedAgeMs={:.3f} callbackAgeMs={:.3f} presentP95Ms={:.3f}",admitted,double(deadline-now)/10000,fgBudget.predicted(now).value_or(-1),elapsed,double(now-liveInputReady)/10000,double(now-captureArrival)/10000,presentP95));}+ if(now>=nextFgAdmissionLog){nextFgAdmissionLog=now+10000000;veyra::log::info("live-fg-admission",std::format("timeline={} admitted={} remainingDeadlineMs={:.3f} predictedMs={:.3f} elapsedMs={:.3f} decodedAgeMs={:.3f} callbackAgeMs={:.3f} presentP95Ms={:.3f}",pairAnchoredLive?(isRemote?"decoded-pair":"capture-pair"):"continuous",admitted,double(deadline-now)/10000,fgBudget.predicted(now).value_or(-1),elapsed,double(now-liveInputReady)/10000,double(now-captureArrival)/10000,presentP95));}return admitted;};}@@ -735,13 +738,15 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sstd::lock_guard lock(mutex_);snapshot_.captureHalfRate=halfRate;veyra::log::info("capture-rate",std::format("revision={} requested60To30={} active={} transportFps={} originalPtsPreserved=true",options.settings.revision,options.settings.content==ContentRate::Capture60To30,halfRate,isCapture?activeSource->info().averageFps:0));}- if(isCapture&&!rereadCached&&(isRemote||!liveTimeline.anchored(out.batch.identity.epoch))){+ const bool pairPacing=pairAnchoredLive&&options.fg;+ if(isCapture&&!rereadCached&&(isRemote||pairPacing||!liveTimeline.anchored(out.batch.identity.epoch))){const auto duration100ns=liveSourceInterval100ns(pkt.duration,activeSource->info().averageFps);// File replay has no device pacing and still needs its PTS// clock. Physical capture without FG presents as soon as ready.const bool paceSourcePts=options.fg||!physicalCapture;- if(!liveTimeline.anchored(out.batch.identity.epoch))veyra::log::info("capture-timeline",std::format("interval100ns={} packetDurationKnown={} packetDurationPositive={} nominalFps={} FG={} pacing={}",duration100ns,!pkt.duration.isUnknown(),pkt.duration.num>0,activeSource->info().averageFps,options.fg,isRemote?"decoded-pair":paceSourcePts?"source-pts":"capture-ready"));- liveTimeline.reset(out.batch.identity.epoch,out.batch.b100ns,liveInputReady,options.fg?duration100ns:0,paceSourcePts);+ if(!liveTimeline.anchored(out.batch.identity.epoch)||(pairPacing&&frames==0))veyra::log::info("capture-timeline",std::format("interval100ns={} packetDurationKnown={} packetDurationPositive={} nominalFps={} FG={} pacing={}",duration100ns,!pkt.duration.isUnknown(),pkt.duration.num>0,activeSource->info().averageFps,options.fg,pairAnchoredLive?(isRemote?"decoded-pair":"capture-pair"):paceSourcePts?"source-pts":"capture-ready"));+ if(pairPacing||isRemote)liveTimeline.resetPair(out.batch.identity.epoch,out.batch.b100ns,liveInputReady,options.fg?duration100ns:0,paceSourcePts);+ else if(!liveTimeline.anchored(out.batch.identity.epoch))liveTimeline.reset(out.batch.identity.epoch,out.batch.b100ns,liveInputReady,options.fg?duration100ns:0,paceSourcePts);}if(!isImage&&!isCapture&&frames==0){anchor=Clock::now();anchorMs=lastAudioClockMs=pts;}double frameWaitMs=0,framePresentMs=0;diff --git a/tests/unit/RepairContractTests.cpp b/tests/unit/RepairContractTests.cppindex 0fa18bec..2633c999 100644--- a/tests/unit/RepairContractTests.cpp+++ b/tests/unit/RepairContractTests.cpp@@ -120,6 +120,25 @@ int main(){check(captureTimeline.deadline(6000600000LL)<=6001030000LL,"unbuffered capture cannot accumulate source-clock drift");captureTimeline.reset(2,0,2000000,166667,true);check(captureTimeline.deadline(166667)==2333334,"switch to FG restores continuous source-PTS pacing and lookahead");+ // A physical capture device may report 59.94fps while its negotiated+ // duration is treated as 60fps. A single source/host anchor accumulates+ // roughly 300ms of error in five minutes; pair anchoring keeps the FG+ // deadline within the current input pair instead.+ constexpr int64_t nominal60=166667,actual5994=166834;+ engine::PresentationScheduler continuousCapture;+ continuousCapture.reset(7,0,0,nominal60,true);+ constexpr int64_t samples=18000;+ const int64_t lastSource=samples*nominal60,lastArrival=samples*actual5994;+ const int64_t lastGenerated=lastSource-nominal60/2;+ check(continuousCapture.deadline(lastGenerated)<lastArrival-2500000,"single capture source anchor exposes long-run 59.94/60 drift");+ engine::PresentationScheduler pairCapture;bool pairDeadlineBounded=true;+ for(int64_t i=1;i<=samples;++i){+ const int64_t source=i*nominal60,arrival=i*actual5994;+ pairCapture.resetPair(7,source,arrival,nominal60,true);+ const int64_t generated=source-nominal60/2,deadline=pairCapture.deadline(generated);+ pairDeadlineBounded&=deadline>=arrival&&deadline<=arrival+nominal60;+ }+ check(pairDeadlineBounded,"pair-anchored capture FG deadline does not accumulate source-clock drift");engine::PresentationScheduler ps5Timeline;bool decodedPairFits=true;for(int64_t i=1;i<120;++i){const int64_t b=i*166667,decoded=1000000+b+(i%2?150000:20000);