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 capture cadence resets after short driver timestamps
Veyra Goal Agent34f479e6f952
diff --git a/AGENTS.md b/AGENTS.mdindex c4c05164..dc321019 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -1,5 +1,7 @@# Veyra 项目 Agent 执行规则+> **2026-10-12 日志50补帧修复授权**:用户在完成 RTX5070Ti/Elgato 日志诊断后明确“尝试修复”。按 docs/FG_CAPTURE_RECOVERY_PLAN_2026-10-12.md 从 main a167831 在 codex/fg-capture-recovery-20261012 隔离修复异常短 PTS 污染节奏基线及有证据的必要接点,覆盖这些具体范围旧冻结。独立 start/bundle 保护64旧树/515脏文件;已有交换链复用先验证,不重复改写。保持真实 PTS、VRR、真正断点重置、容量上限、UI33ms/250ms、GPU默认优先级与用户配置,不派Agent、不改驱动/运行库/模型。全产物E盘,测试每进程≤300秒/构建≤900秒;无main合并/push/打包/Release/关机。本机回放不能冒充Elgato实卡或物理屏幕性能验收。+> **2026-10-12 PR34 合并与采集设置授权**:用户明确合并 PR34、补齐当前卡全部设备格式及采集页自动保存/继续上次/启动自动恢复。按 docs/PR34_CAPTURE_SETTINGS_PLAN_2026-10-12.md 从 main76f41b3 在 codex/pr34-capture-settings-20261012 隔离适配必要 source/bridge/QML/preferences/测试接点,覆盖这些范围旧冻结。构建及定向验收后允许 main 合并与普通推送以完成 GitHub PR 合并。62 旧树/509 脏文件保持,main仅按授权更新;其它尚未合并分支不混入。保持 UI33ms/250ms、默认优先级与正常采集缓冲,不派Agent、不改驱动/运行库/真实配置。全产物E盘,测试≤300秒/构建≤900秒,无打包/Release/关机。> **2026-10-11 当前修复已合入本地main**:Codex4557ab6(含e8300d9)与Claude1d4c33f经隔离整合、42依赖闭包/13EXE构建、完整CMake、16组回归、12真实GUI状态/6布局及SR+VFG组合持久化/重启通过;实测产品4904b73、记录tip adcf509通过功能merge d2e1396进入main,完整Git树相同。VFG默认中档、DLSS K、33ms统计/250ms状态及负优化撤回保持。59开工树中唯main按授权更新,其余58树/504脏文件、来源分支及原包1626文件保持;final.json见reports/merge-current-fixes-20261011。首次组合GUI夹具漏FG节点失败,修夹具后通过,原证据保留;没有新的性能A/B或全硬件/长期显存通过声明。无push/打包/Release/关机。diff --git a/CMakeLists.txt b/CMakeLists.txtindex b6334d74..c2df873a 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -820,6 +820,9 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avformadd_executable(veyra_settings_transaction_tests tests/integration/SettingsTransactionTests.cpp)target_compile_features(veyra_settings_transaction_tests PRIVATE cxx_std_20)target_link_libraries(veyra_settings_transaction_tests PRIVATE veyra_engine)+ add_executable(veyra_capture_cadence_fg_tests tests/integration/CaptureCadenceFgTests.cpp)+ target_compile_features(veyra_capture_cadence_fg_tests PRIVATE cxx_std_20)+ target_link_libraries(veyra_capture_cadence_fg_tests PRIVATE veyra_engine)add_executable(veyra_sr_quality_tests tests/integration/SrQualityTests.cpp)target_compile_features(veyra_sr_quality_tests PRIVATE cxx_std_20)target_link_libraries(veyra_sr_quality_tests PRIVATE veyra_engine)diff --git a/docs/FG_CAPTURE_RECOVERY_PLAN_2026-10-12.md b/docs/FG_CAPTURE_RECOVERY_PLAN_2026-10-12.mdnew file mode 100644index 00000000..6ac5be2e--- /dev/null+++ b/docs/FG_CAPTURE_RECOVERY_PLAN_2026-10-12.md@@ -0,0 +1,20 @@+# 日志50:采集补帧误重置修复++2026-10-12。当前用户授权“尝试修复”,起点 main a167831,隔离分支 codex/fg-capture-recovery-20261012。main/既有树不改,不推送或制作发布包。++## 证据与边界++原日志 SHA256 cf2ea29a124385e62bf65858c89ff6b449303aebe4f17d01087988dfca706e55;诊断与最小生产代码复现在 E:/项目/Veyra/reports/log50-fg-diagnosis-20261012。Elgato4KPro 协商60Hz、回调约59.94,常见样本 PTS/时长20.833ms,周期性出现1ms短增量。SceneCadenceAnalyzer 将这个单帧增量作为下一帧的基线,下一正常间隔被误判为断点。733条场景边界中726条 cadenceBreak=true。这是已证实的软件缺陷;导致驱动时钟变化的外部条件未确定。++日志另有负补帧截止时间和 Present CPU 阻塞,以及切换后 CreateSwapChainForHwnd/ResizeBuffers 失败。当前 main 已包含108cbaa交换链复用、失败resize保留旧缓冲;先做真实对象/像素回归,不凭模块名字归咎某个叠加层,不重复引入未经验证的窗口替换。++## 实施++1. 存档64旧工作树/515未提交文件的状态和SHA、main增量Git bundle,建立独立工作树。原日志、所有已有包/运行库保持原样。+2. 将单个上一间隔基线改为固定小窗口的稳健基线,短异常不能污染下一帧;不改源PTS/样本时长、不删真正画面、不硬锁60Hz。保留 sourceStep 跳帧归一化、真实大间隔、重复帧、切镜、显式reset语义。先在旧代码上确认新回归失败,再修复。+3. 同一生产库做连续时序回放与实际GPU补帧验证;补充DLSS/VFG切换持有外部COM引用、resize失败后继续出画的真实回归。若发现新的根因,只加有证据的最小接点,不提高优先级、放宽补帧截止时间或增加排队掩盖问题。+4. 构建当前依赖闭包和应用,运行场景/采集时序/呈现回归以及用户GTA视频定向回归;原件校验,写REPORT/WORKLOG,封存已验源码。现场Elgato/5070Ti/120Hz仍需用户重测,不能承诺恢复固定120fps。++## 输出与验证++产物统一 E:/项目/Veyra/{archives,build,tests,logs,tmp,reports}/fg-capture-recovery-20261012。构建复用不可变缓存,明确记录实际重编对象,不能冒称clean全量。测试每进程≤300秒,构建≤900秒;GUI不增加Timer、不改33ms统计/250ms状态节奏。无 proprietary runtime/SDK/模型进入Git,不修改真实配置。失败回执保留,收益仅按本轮实际对照报告。diff --git a/docs/FG_CAPTURE_RECOVERY_REPORT_2026-10-12.md b/docs/FG_CAPTURE_RECOVERY_REPORT_2026-10-12.mdnew file mode 100644index 00000000..955a6b69--- /dev/null+++ b/docs/FG_CAPTURE_RECOVERY_REPORT_2026-10-12.md@@ -0,0 +1,43 @@+# 日志50补帧:短时间戳误重置修复++2026-10-12。分支 codex/fg-capture-recovery-20261012,基线 main a167831b。已完成可复现缺陷修复、构建和定向回归;没有合并main、推送或制作发布包。实卡性能仍待原用户复测。++## 改了什么++SceneCadenceAnalyzer 原来将上一帧间隔直接当作下一帧基线。Elgato4KPro 日志里的 1ms 正增量恰好不属于 `<1ms` 的重复帧,紧接着的16.683/20.833ms正常增量就超过 `3×1ms+5ms`,导致误重置NR/光流/补帧历史。现改为最近5个非重复、按sourceStep归一化的正间隔中位数;只保存5个数字,没有增加5帧缓存或等待。窗口随显式reset清空。源PTS、帧号、样本时长、VRR、真正大断点及切镜检测保留。++生产修改只有 include/veyra/core/SceneCadenceAnalyzer.h 和 src/core/SceneCadenceAnalyzer.cpp。CMake仅登记新增永久GPU回归;新增/扩充测试在 tests/integration/CaptureCadenceFgTests.cpp、tests/unit/SceneCadenceTests.cpp。UI、EngineController、呈现策略、补帧预算/截止时间、队列容量、GPU默认优先级、驱动/运行库/模型原件均未修改。保留33ms统计/250ms状态节奏。++日志里的切换失败另有交换链占用问题。main已经有108cbaa的持久交换链复用及失败resize保留旧缓冲;本轮验证它们覆盖DLSS↔VFG相同格式切换,不重复修改。测试保留真实外部COM引用,并强制ResizeBuffers返回0x887A0001:继续用旧缓冲出画,外部引用释放后恢复800×450。++## 本轮实测++| 检查 | 结果 |+| --- | --- |+| 单测先复现再修 | 修复前30检查/5失败;修复后30/0,包括周期1ms、连续短异常、sourceStep、48-120Hz模拟VRR、200/400ms真断点、切镜/闪光/重复帧/reset |+| 同一GPU回归负对照 | 修复前main的实际库,224帧中误重置2次、生成221帧;预期exit1,D3D12错误0 |+| 修复后GPU回放 | RTX5070;P010输入、640×360,DLSS/VFG × 20.833/16.683ms四组;每组224帧、223有效生成、误重置0,异常前后四对均可生成;原PTS和中间PTS顺序保持,200ms真断点正确reset,D3D12错误0 |+| 交换链/尺寸恢复 | 上述四组跨后端保留同一链;真实持有backbuffer使resize失败一次,释放后成功;原有16轮SDR/HDR设置/外部引用像素回归及关闭/失效窗口/重新打开通过 |+| 共享时间/预算契约 | timing及259条contracts通过;未修改准入阈值 |+| 用户GTA原4K视频 | 8轮NR/FG/SR热切换、seek/慢放事务确认及故障回滚/停止全部通过,单项最长43.9秒;非现场采集FPS对照 |+| 生产QML应用 | GPU与软件UI两条实际GTA播放、私有profile、自动正常退出均通过;没有QML错误;这是启动回归,不是新UI性能A/B |++构建命令:`python -X utf8 -B -I E:/项目/Veyra/tmp/fg-capture-recovery-20261012/build.py`。复用不可变已验缓存,重编22个依赖闭包对象并重新链接10个EXE,耗时55.4秒;不是从零全量重编。完整CMake配置验证新目标和既有PS5/Moonlight/Xbox/DeckLink支持。既有未改代码/SDK的编译警告保留;新节奏实现没有编译警告。++主要回归命令:`tests/fg-capture-recovery-20261012/harness/regress.py scene timing contracts capture-cadence`、`presenter lifecycle video rollback`、`capture-cadence-before`,都在同一个任务私有运行目录;最后一项为预期失败负对照。`tmp/fg-capture-recovery-20261012/gui-smoke.py`验证两种生产UI。每测试进程≤300秒,构建≤900秒。++## 证据、保护与失败记录++产物根目录 E:/项目/Veyra;本任务archives/build/tests/logs/tmp/reports均同名。构建回执 logs/fg-capture-recovery-20261012/build-20261012-152556/receipt.json;GPU回放 fg-recovery/tests-20261012-152709;GTA/交换链回归152749;负对照153016;GUI gui-20261012-153428。validation.json核对598源码/配置、329构建输入、10EXE、QML与原包1626文件,原用户日志SHA保持。++严格旧树保护检查如实失败:开工64旧工作树中63树仍完全一致,claude/xess-flow-tune-20261012在本轮期间有并行未提交编辑;该树由另一任务使用,本轮未写入、未回滚或合入它。全部原分支tip与main保持。没有修改旧start/guard来制造通过;差异见worktree-audit.json。++工具夹具出现过失败:独立单测编译器PATH/Windows环境键解析、复制构建脚本时反斜杠转义、旧Ninja图没有settings_transaction目标、负对照的目录断言误包含其自身输出目录,以及GUI日志实际在app/logs而非data-dir。均只修E盘夹具后重新验证;原测试单测5失败和旧GPU2误重置是预期缺陷证据,未冒称通过。另一次归档旧GUI日志因目录名写错未复制,初次console仍在153322,未将该次夹具计为通过。严格旧树差异保留,不恢复并行任务。没有通过改产品迎合夹具。++## 还不能声称什么++上述224帧是同步GPU回归,不能算实时吞吐或物理屏幕帧率;不把221→223说成普遍性能百分比。本机没有反馈者的Elgato4KPro/5070Ti/120Hz组合,尚未验证它的实际提交FPS、VSync阻塞及长时间行为。驱动给出的48fps时间尺度与60fps回调不一致仍保留原始时间戳,本轮没有强行重定时。真正GPU欠速、截止时间耗尽或外部模块持续持有资源仍可出现预算告警。下一步只需该用户用此构建、原设置重测并提供新日志,确认误重置消失后再判断剩余准入损失。++收尾仅删除本任务tmp下7个已解析核对的临时子目录,792文件/70,852,248逻辑字节;不把逻辑字节冒充精确物理释放量。任务脚本、实际构建、私有可用运行目录、profile和必要证据保留,详见cleanup.json。++可用本地测试程序:E:/项目/Veyra/tests/fg-capture-recovery-20261012/app/veyra_qml_ui.exe。无新发布包、用户配置未改,Git提交/存档和存储整理见reports/fg-capture-recovery-20261012/final.json。diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex b19ff764..1f2c548d 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -9169,3 +9169,14 @@ harness/final-ui.py最终9组通过:四语言布局、跨列表/节点全局全部源码以外产物在E:/项目/Veyra本轮build/tests/logs/tmp/reports/archives目录,私有profile和子进程缓存。源/二进制及原包1626文件、旧树保持校验见validation.json,Git收尾见final.json。BMD/美乐威没有实卡,真实出画和全制式待持卡用户确认;不宣称性能提升、全硬件或长期稳定通过。详细记录docs/PR34_CAPTURE_SETTINGS_REPORT_2026-10-12.md。验证后合入并普通推送main完成PR34,无打包/Release/关机。2026-10-12 PR34合并收尾:seal.py validate通过834源码/配置、334构建输入、12EXE、11回归、9最终GUI及两个草稿保存场景;旧62树/509脏文件、原包1626文件完整。适配提交b60830c及tested标签封存,GitHub固定head f1f53ace合并成功(7b9332513257363ec3474c7232bf2bc448296f17),隔离候选49eb6bd吸收远端记录,只多同步远端既有star-history.svg。main merge6570f5672ce3496c4b9bfd27750cb59c1917cc4d完整树等于候选907bad1dd0e077647ff632213fde77b8084e00d6,产品源码与实测一致;后续仅本段及报告收尾文档。普通推送/PR状态/61旧树保持/增量最终bundle的实际结果见reports/pr34-capture-settings-20261012/final.json。修正一次PowerShell未引用HEAD^{tree}导致的只读查询错误后,用带引号参数成功取得树SHA;没有执行其失败结果作为合并依据。+++## 2026-10-12 日志50采集补帧误重置修复++按用户“尝试修复”,main a167831起点,隔离codex/fg-capture-recovery-20261012;archives/fg-capture-recovery-20261012/start.json与增量bundle存档64旧树/515脏文件。最小生产修改仅SceneCadenceAnalyzer两文件:上一间隔改为固定5值中位基线,不缓存帧、不改真实PTS/VRR/预算/队列/UI33ms/250ms/默认GPU优先级。补永久CPU/GPU回归和CMake测试登记。++命令python -X utf8 -B -I tmp/fg-capture-recovery-20261012/scene-test.py before/after:30检查从5失败到0;build.py依赖闭包22项/10EXE,55.4秒,非clean全量;configure.py完整CMake通过。harness/regress.py scene timing contracts capture-cadence、presenter lifecycle video rollback全部通过;capture-cadence-before预期exit1,原生产库224帧2误重置/221生成,修复四组各0/223。真实P010/DLSS/VFG、外部COM链/缓冲引用、resize故障恢复及200ms真断点/D3D12错误0;GTA八轮设置、事务seek、回滚通过。gui-smoke.py GPU/软件生产UI实际GTA播放和正常退出通过。同步图回归不是FPS/显示延迟证据,无实卡或普遍性能收益声明。++工具夹具PATH/环境键、路径转义、旧Ninja缺目标、负对照输出目录断言和GUI日志路径失败已修,未以失败批次冒称通过;详细失败记录见REPORT。严格旧树核对失败于并行claude/xess-flow-tune树的新增修改:63原树完全保持,差异原样记录worktree-audit.json,没有写入/回滚/合入该树。main及原分支tip保持。validation.json核对源码/输入/10EXE/原包1626文件和原日志SHA;runtime/SDK/模型无新增入Git。++全产物E:/项目/Veyra本轮archives/build/tests/logs/tmp/reports;实际命令、原回执与边界见docs/FG_CAPTURE_RECOVERY_REPORT_2026-10-12.md。可用程序tests/fg-capture-recovery-20261012/app/veyra_qml_ui.exe,未合并main/push/打包/Release/关机。最后源码commit/tag/bundle、保护及存储核对见reports/fg-capture-recovery-20261012/final.json。反馈者Elgato/5070Ti/120Hz仍需同设置复测;不强改设备时钟或延长deadline掩盖剩余问题。diff --git a/include/veyra/core/SceneCadenceAnalyzer.h b/include/veyra/core/SceneCadenceAnalyzer.hindex a28ccc98..a18c4962 100644--- a/include/veyra/core/SceneCadenceAnalyzer.h+++ b/include/veyra/core/SceneCadenceAnalyzer.h@@ -4,6 +4,7 @@// and cadence changes using histogram + SAD + PTS sequence analysis.// Feeds ResetCoordinator with the appropriate ResetReason.#include <cstdint>+#include <array>#include <vector>#include "veyra/core/ResetCoordinator.h"@@ -55,7 +56,7 @@ public:uint64_t sourceStep = 1);// Reset baseline (called on seek/source switch/etc).- void reset() { hasBaseline_ = false; prevHistogram_.clear(); lastCadenceDeltaUs_ = 0; }+ void reset() { hasBaseline_ = false; prevHistogram_.clear(); cadenceCount_ = cadencePosition_ = 0; }const SceneAnalysisResult& lastResult() const { return lastResult_; }uint64_t sceneCutCount() const { return sceneCutCount_; }@@ -71,7 +72,10 @@ private:uint64_t flashCount_ = 0;uint64_t duplicateCount_ = 0;SceneAnalysisResult lastResult_;- double lastCadenceDeltaUs_ = 0; // per-source-frame PTS interval of the previous frame+ // A single short driver timestamp must not establish the next frame's+ // expected cadence. Fixed storage, no buffering or source retiming.+ std::array<double, 5> cadenceIntervals_{};+ unsigned cadenceCount_ = 0, cadencePosition_ = 0;double histogramDistance(const std::vector<double>& a, const std::vector<double>& b) const;};diff --git a/src/core/SceneCadenceAnalyzer.cpp b/src/core/SceneCadenceAnalyzer.cppindex 97e593a5..e16b29df 100644--- a/src/core/SceneCadenceAnalyzer.cpp+++ b/src/core/SceneCadenceAnalyzer.cpp@@ -69,11 +69,16 @@ SceneAnalysisResult SceneCadenceAnalyzer::analyze(uint64_t frameId,double cadenceDeltaUs = 0;if (result.ptsDeltaUs > 0 && result.ptsDeltaUs < 1e15) {cadenceDeltaUs = result.ptsDeltaUs / double(sourceStep ? sourceStep : 1);- // Check against expected cadence (simplified: if delta is 3x the- // previous delta, consider it a break)- if (lastCadenceDeltaUs_ > 0 &&- cadenceDeltaUs > lastCadenceDeltaUs_ * 3.0 + config_.cadenceBreakPtsJitterUs) {- result.isCadenceBreak = true;+ if (cadenceCount_) {+ auto intervals = cadenceIntervals_;+ auto middle = intervals.begin() + cadenceCount_ / 2;+ std::nth_element(intervals.begin(), middle, intervals.begin() + cadenceCount_);+ // Log50: ordinary 16.683/20.833ms frames surrounding an isolated+ // positive 1ms increment used to reset all temporal history. The+ // median tolerates two outliers, yet adapts to sustained changes.+ // Use the upper median during startup so one short sample cannot+ // lower an already observed ordinary interval.+ result.isCadenceBreak = cadenceDeltaUs > *middle * 3.0 + config_.cadenceBreakPtsJitterUs;}}@@ -83,7 +88,11 @@ SceneAnalysisResult SceneCadenceAnalyzer::analyze(uint64_t frameId,prevPtsUs_ = ptsUs;}- if (cadenceDeltaUs > 0 && !result.isDuplicate) lastCadenceDeltaUs_ = cadenceDeltaUs;+ if (cadenceDeltaUs > 0 && !result.isDuplicate) {+ cadenceIntervals_[cadencePosition_] = cadenceDeltaUs;+ cadencePosition_ = (cadencePosition_ + 1) % cadenceIntervals_.size();+ if (cadenceCount_ < cadenceIntervals_.size()) ++cadenceCount_;+ }lastResult_ = result;return result;}diff --git a/tests/integration/CaptureCadenceFgTests.cpp b/tests/integration/CaptureCadenceFgTests.cppnew file mode 100644index 00000000..17fa1e0c--- /dev/null+++ b/tests/integration/CaptureCadenceFgTests.cpp@@ -0,0 +1,147 @@+// Log50 timestamps replayed through the actual graph and native presenter.+// Test-only synchronous GPU waits/readback are not playback code or FPS data.+#include "veyra/engine/VideoPresenter.h"+#include "veyra/pipeline/EnhanceGraph.h"+#include "veyra/gfx/D3D12DeviceContext.h"+#include "veyra/gfx/CommandSlotRing.h"+#include "veyra/sink/ImageExportSink.h"+#include "veyra/RuntimePaths.h"+#include "veyra/Log.h"+#include <d3d12sdklayers.h>+#include <filesystem>+#include <iostream>+#include <thread>+#include <vector>+extern "C" {+#include <libavutil/frame.h>+#include <libavutil/pixfmt.h>+}++int wmain(int argc, wchar_t** argv) {+ using namespace veyra;+ if (argc != 2 || FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED))) return 2;+ const std::filesystem::path output = argv[1];+ std::filesystem::create_directories(output);+ Logger::instance().openFile((output / L"engine.log").wstring());+ Logger::instance().setConsoleEnabled(false);+ gfx::D3D12DeviceContext ctx;+ gfx::CommandSlotRing ring;+ gfx::DeviceContextDesc device;+ device.enableDebugLayer = true;+ Status status;+ if (!ctx.initialize(device, status) ||+ !ring.initialize(ctx.device(), ctx.directQueue(), ctx.fence(), ctx.fenceEvent(), 6, status)) return 2;+ gfx::ComPtr<ID3D12InfoQueue> messages;+ ctx.device()->QueryInterface(IID_PPV_ARGS(&messages));+ if (!messages) return 2;+ messages->ClearStoredMessages();+ HWND window = CreateWindowExW(WS_EX_NOACTIVATE, L"STATIC", L"Capture cadence replay",+ WS_POPUP, 30, 30, 640, 360, nullptr, nullptr, GetModuleHandleW(nullptr), nullptr);+ if (!window) return 2;+ engine::VideoPresenter presenter;+ gfx::ComPtr<IDXGISwapChain3> held;+ AVFrame* frame = av_frame_alloc();+ frame->format = AV_PIX_FMT_P010LE;+ frame->width = 640; frame->height = 360;+ frame->color_range = AVCOL_RANGE_MPEG;+ frame->colorspace = AVCOL_SPC_BT709;+ frame->color_primaries = AVCOL_PRI_BT709;+ frame->color_trc = AVCOL_TRC_BT709;+ bool ok = av_frame_get_buffer(frame, 32) >= 0;+ for (unsigned round = 0; round < 4 && ok; ++round) {+ ok = presenter.prepareGraphChange() && ring.drainQueue();+ pipeline::EnhanceGraph graph(ctx, ring);+ pipeline::EnhanceGraphDesc desc;+ desc.sourceWidth = desc.workWidth = 640;+ desc.sourceHeight = desc.workHeight = 360;+ desc.enableNr = desc.enableSr = false; desc.enableFg = true;+ desc.captureBitDepth = 10; desc.fgMultiplier = 2;+ desc.frameGenerationBackend = round % 2 ? engine::FrameGenerationBackend::Vfg : engine::FrameGenerationBackend::Dlss;+ desc.runtimeAbsPath = runtime::localRuntimeDirectory().wstring();+ ok = ok && graph.initialize(desc) && graph.createViews() && presenter.open(ctx, window, graph);+ if (!held) held = presenter.swapChainForTest();+ const bool retained = held && held.Get() == presenter.swapChainForTest().Get();+ ok = ok && retained;+ const uint64_t intervalUs = round < 2 ? 20833 : 16683;+ uint64_t ptsUs = 0;+ unsigned cadenceBreaks = 0, generated = 0, anomalyPairs = 0;+ bool originalPts = true, orderedSubframes = true;+ unsigned lastSlot = 0; pipeline::FrameIdentity lastIdentity;+ for (unsigned i = 0; i < 224 && ok; ++i) {+ if (i) ptsUs += i % 101 == 0 ? 1000 : intervalUs;+ for (int y = 0; y < 360; ++y) for (int x = 0; x < 640; ++x) {+ const auto luma = 40 + (((unsigned(x) + i * 2) / 8 * 7 + unsigned(y) / 8 * 11) % 160);+ reinterpret_cast<uint16_t*>(frame->data[0] + size_t(y) * frame->linesize[0])[x] = uint16_t((64 + luma * 3) << 6);+ }+ for (int y = 0; y < 180; ++y) for (int x = 0; x < 640; ++x)+ reinterpret_cast<uint16_t*>(frame->data[1] + size_t(y) * frame->linesize[1])[x] = 512 << 6;+ pipeline::EnhanceGraph::FrameOutputs out;+ ok = graph.process(frame, double(ptsUs) / 1000, i == 0, out, i + 1) &&+ ring.waitIdle() && graph.resolveGeneration(out);+ cadenceBreaks += out.detectedReset == pipeline::ResetReason::CadenceBreak;+ originalPts &= out.batch.b100ns == int64_t(ptsUs * 10);+ if (out.hasGenerated) {+ ++generated;+ if (i > 1 && (i % 101 == 0 || i % 101 == 1)) ++anomalyPairs;+ }+ for (unsigned n = 0; n < out.batch.count; ++n) {+ const auto& item = out.batch.frames[n];+ if (item.kind == pipeline::FrameKind::Generated && item.validity == pipeline::GenerationValidity::Valid)+ orderedSubframes &= item.pts100ns > out.batch.a100ns && item.pts100ns < out.batch.b100ns;+ }+ ok = ok && presenter.present(ctx, ring, graph, out.videoSlot, false, false, 0, false, .5f, out.batch.identity);+ lastSlot = out.videoSlot; lastIdentity = out.batch.identity;+ }+ sink::RgbaImage image;+ ok = ok && presenter.readPresentedFrameForTest(ctx, ring, image);+ bool visible = false;+ if (ok) for (size_t p = 0; p < image.pixels.size(); p += 4) visible |= image.pixels[p] > 30;+ if (round == 0 && ok) {+ // Force the field ResizeBuffers ownership error using an actual+ // external backbuffer reference, then release it and recover.+ gfx::ComPtr<ID3D12Resource> externalBuffer;+ ok = SUCCEEDED(held->GetBuffer(0, IID_PPV_ARGS(&externalBuffer)));+ SetWindowPos(window, nullptr, 0, 0, 800, 450, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);+ ok = ok && presenter.present(ctx, ring, graph, lastSlot, false, false, 0, false, .5f, lastIdentity);+ DXGI_SWAP_CHAIN_DESC1 size{}; held->GetDesc1(&size);+ const bool keptOldBuffers = size.Width == 640 && size.Height == 360;+ externalBuffer.Reset();+ std::this_thread::sleep_for(std::chrono::milliseconds(250));+ ok = ok && presenter.present(ctx, ring, graph, lastSlot, false, false, 0, false, .5f, lastIdentity);+ held->GetDesc1(&size);+ const bool resized = size.Width == 800 && size.Height == 450;+ ok = ok && keptOldBuffers && resized && presenter.readPresentedFrameForTest(ctx, ring, image);+ std::cout << "CAPTURE_RESIZE keptOldBuffers=" << keptOldBuffers << " recovered=" << resized+ << " passed=" << ok << std::endl;+ }+ // A real 200ms gap must still reset even after the anomaly pattern.+ pipeline::EnhanceGraph::FrameOutputs gap;+ ok = ok && graph.process(frame, double(ptsUs + 200000) / 1000, false, gap, 225) && ring.waitIdle();+ const bool realGap = gap.detectedReset == pipeline::ResetReason::CadenceBreak && gap.historyReset;+ gap = {};+ ok = ok && cadenceBreaks == 0 && generated >= 218 && anomalyPairs == 4 &&+ originalPts && orderedSubframes && visible && realGap;+ std::cout << "CAPTURE_CADENCE backend=" << (round % 2 ? "VFG" : "DLSS")+ << " intervalUs=" << intervalUs << " frames=224 cadenceBreaks=" << cadenceBreaks+ << " generated=" << generated << " anomalyPairs=" << anomalyPairs+ << " originalPts=" << originalPts << " orderedSubframes=" << orderedSubframes+ << " retainedExternalChain=" << retained << " visible=" << visible+ << " realGap=" << realGap << " passed=" << ok << std::endl;+ ok = presenter.prepareGraphChange() && ring.drainQueue() && ok;+ graph.shutdown();+ }+ held.Reset(); presenter.close(); av_frame_free(&frame);+ unsigned errors = 0;+ for (UINT64 i = 0; i < messages->GetNumStoredMessagesAllowedByRetrievalFilter(); ++i) {+ SIZE_T size = 0; messages->GetMessage(i, nullptr, &size);+ std::vector<char> buffer(size);+ auto* message = reinterpret_cast<D3D12_MESSAGE*>(buffer.data());+ messages->GetMessage(i, message, &size);+ if (message->Severity <= D3D12_MESSAGE_SEVERITY_ERROR) { ++errors; std::cerr << message->pDescription << std::endl; }+ }+ ok = ok && errors == 0 && SUCCEEDED(ctx.device()->GetDeviceRemovedReason());+ messages.Reset(); ring.shutdown(); ctx.shutdown(); DestroyWindow(window); CoUninitialize();+ std::cout << "CAPTURE_CADENCE_RESULT passed=" << ok << " debugErrors=" << errors+ << " physicalCapture=unmeasured displayFps=unmeasured" << std::endl;+ return ok ? 0 : 1;+}diff --git a/tests/unit/SceneCadenceTests.cpp b/tests/unit/SceneCadenceTests.cppindex 57b57dbc..0e2ca304 100644--- a/tests/unit/SceneCadenceTests.cpp+++ b/tests/unit/SceneCadenceTests.cpp@@ -139,6 +139,68 @@ int main() {check("scene:duplicate-no-false-break", !r.isCadenceBreak, "interval after a duplicate compares with the last real interval");}+ // Log50: Elgato4KPro delivers a positive 1ms PTS increment periodically,+ // surrounded by ordinary 20.833ms (or 16.683ms) intervals. It is not a+ // duplicate at the 1ms boundary, even for a static picture. Returning to+ // normal must not reset the entire temporal graph.+ for (uint64_t interval : {20833u, 16683u}) {+ for (double sad : {0.0, 0.01}) {+ SceneCadenceAnalyzer a;+ const auto histogram = makeHistogram(0.5);+ uint64_t pts = 0;+ unsigned breaks = 0;+ (void)a.analyze(0, histogram, sad, pts);+ for (uint64_t frame = 1; frame <= 6060; ++frame) {+ pts += frame % 101 == 0 ? 1000 : interval;+ const auto r = a.analyze(frame, histogram, sad, pts);+ breaks += r.isCadenceBreak;+ }+ check("scene:log50-short-pts-no-reset", breaks == 0,+ "periodic 1ms timestamp cannot poison the next normal interval");+ const auto gap = a.analyze(6061, histogram, sad, pts + 200000);+ check("scene:log50-real-stall-still-breaks", gap.isCadenceBreak,+ "robust baseline still detects a real 200ms source stall");+ }+ }+ {+ SceneCadenceAnalyzer a;+ const auto histogram = makeHistogram(0.5);+ uint64_t pts = 0;+ (void)a.analyze(0, histogram, 0.01, pts);+ for (uint64_t frame = 1; frame <= 8; ++frame)+ (void)a.analyze(frame, histogram, 0.01, pts += 16683);+ (void)a.analyze(9, histogram, 0.01, pts += 1000);+ (void)a.analyze(10, histogram, 0.01, pts += 2000);+ check("scene:short-pts-burst-no-reset",+ !a.analyze(11, histogram, 0.01, pts += 16683).isCadenceBreak,+ "two timestamp outliers still cannot establish a new cadence");+ check("scene:short-pts-mailbox-skip",+ !a.analyze(12, histogram, 0.01, pts += 16683 * 6, 6).isCadenceBreak,+ "sourceStep normalization remains effective after timestamp jitter");+ }+ {+ SceneCadenceAnalyzer a;+ const auto histogram = makeHistogram(0.5);+ uint64_t pts = 0;+ bool continuous = true;+ (void)a.analyze(0, histogram, 0.01, pts);+ for (uint64_t frame = 1; frame <= 2400; ++frame) {+ // 48/120/60/90Hz VRR is a real variable cadence, not a 60Hz stream.+ const uint64_t interval[] = {20833, 8333, 16667, 11111};+ continuous &= !a.analyze(frame, histogram, 0.01,+ pts += interval[frame % 4]).isCadenceBreak;+ }+ check("scene:vrr-cadence-preserved", continuous,+ "variable 48-120Hz input remains continuous");+ a.reset();+ (void)a.analyze(0, histogram, 0.01, 0);+ // Establish a genuinely faster source after reconnect, then stall.+ (void)a.analyze(1, histogram, 0.01, 2000);+ check("scene:reset-clears-robust-cadence",+ a.analyze(2, histogram, 0.01, 22000).isCadenceBreak,+ "no old slow cadence can mask a break in a fresh fast stream");+ }+// Reset clears baseline.{SceneCadenceAnalyzer a;