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(xess): refine optical-flow motion boundaries without changing NR guidance
Veyra Goal Agentf468dfbd3b00
diff --git a/AGENTS.md b/AGENTS.mdindex 148ea42a..cefd5e12 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -1,5 +1,7 @@# Veyra 项目 Agent 执行规则+> **2026-10-12 XeSS 修复接手**:用户要求接手 Claude 额度耗尽的 XeSS 修复。按 docs/XESS_HANDOFF_PLAN_2026-10-12.md 在 codex/xess-handoff-20261012 从 7fe3ea6 继承独立封存的五文件未完成修改,只完成 XeSS 开启光流时的运动边界精修及必要生命周期/构建/真实画质和耗时验证。61 旧工作树/509 脏文件由 archives/xess-handoff-20261012/start.json 保护,Claude 原树不改;此具体范围覆盖历史冻结。不派 Agent、不修改运行库/模型/驱动/真实配置;33ms 统计和默认 GPU 优先级保持。全部产物 E 盘、每测试≤300秒/构建≤900秒;无 main 合并/push/Release/关机。未获益的精修撤回,合成画面结果不冒充真实游戏或其他硬件通过。+> **2026-10-12 补帧人物边缘果冻 J0(Claude)**:用户要求先排查果冻(延迟暂缓),按 reports/jelly-latency-20261012/方案选项.md 先做 J0 判定,先测 DLSS/FSR,随后按用户“主要是XESS”补测 XeSS(SDK 只显示插值帧加桌面复制抓屏)。存档 `checkpoint/pre-claude-jelly-20261012`(main 76f41b3)与 E 盘 `archives/claude-jelly-20261012`;分支 `claude/jelly-20261012` 新增诊断测试 `veyra_fg_motion_boundary_tests`、`veyra_fg_xess_boundary_tests` 及文档;产品代码只加默认不生效的测试开关(XeSS 只显示插值帧、fgMotionProbe 进 XeSS 链路、NVOF 网格),不改默认行为、运行库/模型/驱动/用户配置;无 merge/push/Release。结论见 docs/JELLY_J0_2026-10-12.md。> **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 814d3d05..3d19d2fd 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -297,6 +297,8 @@ veyra_add_compute_shader(veyra_shader_nr_temporal NrTemporal)# Stage-5 output stabiliser (anti-flicker, default off).veyra_add_compute_shader(veyra_shader_nr_hold NrHold)veyra_add_compute_shader(veyra_shader_flow_adapt FlowAdapt)+veyra_add_compute_shader(veyra_shader_flow_refine FlowRefine)+veyra_add_compute_shader(veyra_shader_flow_fill FlowFill)# VfgShotChange: per-pair shot-change test for VFG (replaces the SDK's automatic one).veyra_add_compute_shader(veyra_shader_vfg_shot_change VfgShotChange)veyra_add_compute_shader(veyra_shader_rgb_nv12 RgbToNv12)@@ -556,7 +558,7 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avform# veyra_sources: product input sources (Playbook R3/R7). MediaFileSource# composes veyra_media; no second decode implementation exists.- add_dependencies(veyra_pipeline veyra_shader_nr_downsample veyra_shader_nr_residual veyra_shader_nr_temporal veyra_shader_nr_hold veyra_shader_flow_adapt veyra_shader_vfg_shot_change)+ add_dependencies(veyra_pipeline veyra_shader_nr_downsample veyra_shader_nr_residual veyra_shader_nr_temporal veyra_shader_nr_hold veyra_shader_flow_adapt veyra_shader_flow_refine veyra_shader_flow_fill veyra_shader_vfg_shot_change)add_library(veyra_sources STATICsrc/source/NativeCaptureSink.cppsrc/source/MediaFileSource.cpp@@ -922,6 +924,11 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avformtarget_include_directories(veyra_fg_xess_boundary_tests PRIVATE ${FFMPEG_INCLUDE_DIRS})target_compile_definitions(veyra_fg_xess_boundary_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN VEYRA_PROJECT_ROOT="${CMAKE_CURRENT_SOURCE_DIR}")target_link_libraries(veyra_fg_xess_boundary_tests PRIVATE veyra_engine d3d11 dxgi)+ add_executable(veyra_xess_motion_contract_tests tests/integration/XessMotionContractTests.cpp)+ target_compile_features(veyra_xess_motion_contract_tests PRIVATE cxx_std_20)+ target_include_directories(veyra_xess_motion_contract_tests PRIVATE ${FFMPEG_INCLUDE_DIRS})+ target_compile_definitions(veyra_xess_motion_contract_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN VEYRA_PROJECT_ROOT="${CMAKE_CURRENT_SOURCE_DIR}")+ target_link_libraries(veyra_xess_motion_contract_tests PRIVATE veyra_engine)# Qt 6.8.3 is staged under deps/ (the user allowed the latest Qt). The probe is# opt-in so a normal product build never depends on Qt being present.option(VEYRA_BUILD_QT_PROBE "Build the Qt + D3D12 host probe" OFF)diff --git a/docs/JELLY_FIX_PLAN_2026-10-12.md b/docs/JELLY_FIX_PLAN_2026-10-12.mdnew file mode 100644index 00000000..cf99083b--- /dev/null+++ b/docs/JELLY_FIX_PLAN_2026-10-12.md@@ -0,0 +1,65 @@+# XeSS 开启光流时的人物边缘果冻:修复计划(2026-10-12,Claude)++## 授权与范围++- 用户看完 J0(`docs/JELLY_J0_2026-10-12.md`)后回复“可以,写计划开工”。随后纠正:“应该是xess模型的问题,用户反馈关闭光流就会好很多,所以不要管那个,你就修开启光流的情况下就行了”。+- **只修运动来源选“光流”时**交给补帧的运动矢量:+ - XeSS 送显端补帧(主要目标);+ - 顺带修“只开 FSR 补帧时光流根本不创建”的缺陷,这同属“开了光流却没用上”。+- **不改**:+ - XeSS“自动”仍给零矢量;+ - 栏杆竖纹问题,按用户判断属 XeSS 模型本身,不处理;+ - DLSS(它不读矢量)、VFG;+ - NR / 超分使用的光流仍保留原校验(项目规则:交给 NGX 的低置信矢量必须衰减);+ - 运行库、模型、驱动、默认设置、用户配置。+- 规则沿用:+ - 存档:`checkpoint/pre-claude-jelly-20261012`(main)、`checkpoint/pre-claude-jelly-fix-20261012`(分支头 7fe3ea6),以及 `archives/claude-jelly-20261012/`(含 `branch-before-fix.bundle`);+ - 在 `claude/jelly-20261012` 上实施;+ - 同一 EXE 用测试开关做 A/B,负优化当场撤回;+ - 每种测试只跑一次;+ - 不 merge、不 push、不 Release。++## 依据(J0 实测,XeSS 侧跑场景,轮廓带误差)++| 运动输入 | 中速 27 px/帧 | 高速 80 px/帧 |+| --- | --- | --- |+| 产品光流(现状“光流”) | 6.88 | 8.21 |+| 产品光流,关闭逐像素清零 | 6.43 | 7.56 |+| 理想矢量(上限参考) | 5.47 | 6.01 |++剩余差距来自运动边界:+- 8×8 方块矢量跨在人物和背景之间;+- 新露出的背景被清零,或拿到错误的矢量。++更细的 NVOF 网格、全分辨率光流、质量档都无效,所以要加新的处理步骤。++## 设计++在 NVOF 之后、交给 XeSS 之前,增加一条只给补帧用的分支。++1. **逐像素选矢量**(新着色器 `FlowRefine.hlsl`,光流分辨率):+ - 每个光流像素从自己和周围 3×3 个 NVOF 网格的矢量里选一个:用 3×3 亮度块比较当前帧与上一帧对应位置,取差最小的;+ - 平局时偏向自己格子的矢量;+ - 不清零,并记下最小代价。+2. **遮挡填充**(新着色器 `FlowFill.hlsl`):+ - 最小代价仍超过阈值的像素,说明哪个候选都对不上,通常是人物移开后露出的背景;+ - 在 8 个方向、2–48 像素距离上找“能对上且当前颜色最接近”的像素,借它的矢量,代替错误矢量或 0。+3. 用现有 `FlowAdapt` 放大到补帧分辨率,作为 XeSS 送显端的运动输入。NR、超分、DLSS 仍用原来的 `baseFlow`。+4. 只在以下条件同时满足时启用:XeSS 补帧 + 运动来源“光流” + NVIDIA 光流后端。AMD 光流和 GPU DIS 保持原路径。测试开关 `VEYRA_TEST_FLOW_REFINE=0` 恢复旧行为,用于同一 EXE 的 A/B。+5. FSR:`EnhanceGraph::initNvof` 的创建条件补上 FSR 补帧。FSR 是否也改用精修后的矢量,按实测决定。++## 验收++- XeSS 侧跑中速、高速(`veyra_fg_xess_boundary_tests`,每种只跑一次):+ - 新路径的轮廓带误差必须低于旧光流,目标是明显逼近理想矢量;+ - 远处背景误差不能变差。+- 栏杆场景(密集竖条横移)做一次对照:新路径不差于旧光流。+- GPU 开销:同一 EXE、4K 播放、XeSS 加光流,记录开关前后的 GPU 就绪时间。目标在 RTX 5070 上增加约 1 ms 以内。+- FSR:只开 FSR 补帧并选“光流”时,日志显示 NVOF 实际执行。+- 回归:沿用合并构建的相关回归(链路、呈现、契约等),D3D12 调试层零错误。+- 交付:本地测试版,供用户在真实游戏里看侧跑和高速镜头;同时写 WORKLOG 和 AGENTS 记录。++## 风险++- 精修依赖光流输入图的亮度匹配。暗部、强噪声、重复纹理上可能选错;有平局偏向和代价阈值兜底。+- 合成场景的提升不等于真实游戏也有同样幅度,最终以用户的实机观感为准。diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex 9ed5cc7c..8b0f7a0c 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -9157,3 +9157,24 @@ seal.py validate逐项核对源码/输入/EXE/QML/原包1626文件及旧树;- 结果(4K 合成场景,30fps 位移,FG 2X,光流 1080p):DLSS 补帧对零、产品光流、理想、取反、全屏 +120 px 的矢量结果相同(轮廓带误差 2.77/2.58),即不读矢量。FSR 依赖矢量:零 6.59/10.52(镜头转动时背景整体 16.26),产品光流 1.54/2.04,与理想 1.71/2.05 相当。开 NR 后轮廓带偏离原图更多(NR 光流 13.00 对 NR 零 10.77),但静止人物内侧抖动没有增加。判定:光流精修(J1)没有收益,不实施。附带发现 initNvof 只给 DLSS 补帧建光流,只开 FSR 补帧时“光流”实际为 0。- 证据:logs/claude-jelly-20261012/j0/(j0-results.json、每组日志、裁切图/误差图/sheet)。详细结论与边界见 docs/JELLY_J0_2026-10-12.md。合成场景没有复现明显果冻,XeSS 未测;不 merge/push/Release。- XeSS 补测(用户:“主要是XESS……人物侧向奔跑……画面高速运动的时候”):新增 veyra_fg_xess_boundary_tests。2560×1440 全屏,产品图 + VideoPresenter 的 XeSS 送显链路,SDK 调试功能“只显示插值帧”,用 DXGI 桌面复制抓屏(HDR 桌面按 SDR 白电平 4.75 还原)。侧跑场景每帧 27/80 px:零矢量(XeSS“自动”默认)7.68/9.65,产品光流 6.88/8.21,关闭清零校验 6.43/7.56,理想 5.47/6.01,取反 8.05/10.12。加分层深度只改善 2–4%;NVOF 网格 1/2、全分辨率光流、质量档无效,GPU DIS 更差。判定:XeSS 依赖我们的矢量,默认零矢量最差,逐像素精修(J1)对 XeSS 有收益。产品代码只加测试开关(VEYRA_TEST_XESS_ONLY_INTERPOLATED、fgMotionProbe 送入 XeSS 链路、VEYRA_TEST_NVOF_GRID),默认路径不变。证据 logs/claude-jelly-20261012/xess/。+++## 2026-10-12 接手 Claude XeSS 光流修复++用户要求“claude又跑空额度了,继续接手他,完成xess修复”。读取其最新 d6689aca 会话,沿用最后授权:只修开启光流的人物/背景运动边界,Automatic 不改,延迟暂缓。独立 archives/xess-handoff-20261012/start.json、source-before.bundle(verify)和五文件 patch/副本保护 61 旧工作树/509 脏文件;在 E:/项目/Veyra/worktrees/xess-handoff-20261012 / codex/xess-handoff-20261012 从 7fe3ea6 接手,Claude 原树、桌面和 main76f41b3 不改,不派 Agent。++继承两个诊断提交和 FlowRefine/FlowFill 半成品,完成 NVOF→逐像素邻格亮度匹配→相似颜色补洞→XeSS 工作尺寸运动的 GPU 分支;补资源/预算、pass shader/descriptor 顺序、barrier、首帧/reset零运动、失败/释放及 CMake 接线。仅 XeSS+显式光流+NVIDIA 生效,NR/SR 保留原校验光流,Automatic/其他光流后端/其他补帧不改;还原 Claude 半成品里的 FSR 初始化条件扩大。新增工作纳入已有光流计时,未改 33ms统计/约250ms状态/GPU默认优先级,无正常路径像素回读或逐帧等待。++命令前缀为 Python3.11 -X utf8 -B -I,脚本与产物均 E:/项目/Veyra/{用途}/xess-handoff-20261012:++- tmp/.../build.py 最终 logs/.../build-20261012-111040/receipt.json,22.2秒,17依赖闭包对象核对/重编、16EXE链接成功;不是clean全工程重编。GUI SHA256 43a5fea655a3b2840e5f5f25befac70c8ad6cd2de2f78c79385d8f83ea658edc。tmp/.../configure.py → configure-20261012-111144完整配置成功,新shader及test targets登记,无QuickPrivate。+- tests/.../harness/regress.py xess-motion chain contracts hdr video rollback → logs/.../xess/tests-20261012-111135/receipt.json 六组通过;160真实GPU检查、6运动帧对改变、D3D12错误0。首帧/reset/Automatic零运动,原校验光流和未增强实帧像素相同,设置重建、失败回退、HDR颜色回归通过。+- tests/.../harness/ui.py perf-old perf-new lifecycle → logs/.../xess-ui-20261012-111651/receipt.json,40.3/40.0/50.1秒通过;真实GUI seek/暂停恢复/2X→4X/零运动/AMD光流→NVOF/关闭开启,SDK framesPresented=4。AMD provider在RTX5070实际Dispatch成功,非AMD显卡验收。探针删除、Main.qml恢复。+- tests/.../harness/quality.py → logs/.../quality-20261012-112023/results.json,6组每组11/11有效插值帧、debug/capture错误0。1440p XeSS2X、720p flow,中速27px/高速80px侧跑、80px横移轮廓带MAE8:6.8755→6.3781(-7.23%)、8.2148→7.4180(-9.70%)、3.7651→3.0332(-19.44%);远处背景误差均降。不是实际果冻减少百分比,仍有弯曲残留。SDK只显示插值调试模式generated计数为0,不冒称计数证明;全部目标帧由像素匹配确认,matchedReal0,正常GUI另验2X/4X提交。+- GTA6原4K30/原版NR一层1080/NVOF1080/XeSS2X,测试私有配置在打开源前固定普通class2(产品原有默认实时class5保持)。相同源帧300–840共541帧,Color.begin→Residual.end中位8.4835→8.8310ms(+0.348ms/+4.10%)、P95 8.6534→9.0396,双方约60fps提交;显存1980→2037MiB(+57)。不能把XeSS异步FgBatch时间戳或UI统计直接当全部处理/显示延迟。光流统计覆盖新增工作后约+0.57ms含旧漏记densify/adapt,实际成本看同边界处理图。汇总reports/.../validation.json。++失败保留:110508性能夹具实际Native4K+默认class5,作废,修正sizePolicy0和普通优先级后110652/111651重测;111634抓屏重复帧耗尽容量仅4/11而失败,测试改像素去重+有界128张、加强为11/11且无采集错误,单独重建诊断测试boundary-build-20261012-112011(4秒),产品及其他EXE保持,最终六组与早期完整结果一致。单独重链首次LNK1181因工作目录错误,修复后通过。新保护核对器最初漏处理2棵detached HEAD,修正与开工None比较后61树/509文件全同,保留guard-detached-mismatch.json。++本地构建 tests/.../app、Start-XeSS-Test.cmd 和独立 user-test-profile,未打新压缩包。1626母包文件哈希不变,SDK/DLL/模型/媒体未入Git。运行组件原件保持,默认UI/GPU行为保持,无main合并/push/Release/关机。真实用户游戏、AMD/Intel显卡、长期显存和屏幕端到端延迟未验,不宣称根治。详见 docs/XESS_HANDOFF_REPORT_2026-10-12.md;最终本地commit、source-after.bundle、全部保护/构建回执哈希见 reports/xess-handoff-20261012/final.json。++启动入口最终实测:tmp/.../check-launcher.py,reports/.../launcher.json,9.6秒。初次检查误在继承管道关闭后查询已退出进程,日志实际正常;种子配置补齐field-render迁移旁文件,真实GUI断言XeSS2X/光流/NVOF/原版NR1080p成功,按时退出,检查探针已删除。diff --git a/docs/XESS_HANDOFF_PLAN_2026-10-12.md b/docs/XESS_HANDOFF_PLAN_2026-10-12.mdnew file mode 100644index 00000000..976dcb4b--- /dev/null+++ b/docs/XESS_HANDOFF_PLAN_2026-10-12.md@@ -0,0 +1,23 @@+# XeSS 光流修复接手(2026-10-12)++用户要求接手 Claude 未完成的 XeSS 修复。已读取最新本地会话 d6689aca:最后要求只修开启光流的情况,自动模式不改,延迟研究暂缓。原分支 7fe3ea6 的五文件修改已独立封存,原工作树保留;新分支 codex/xess-handoff-20261012。++## 工作与完成门槛++1. 审查 FlowRefine/FlowFill 及 EnhanceGraph 的半成品:初始化顺序、NVOF 后端实际创建、资源状态、reset、缩放、创建失败与释放。+2. 只给 XeSS 的 NVIDIA 光流分支做精修,NR/SR 继续消费原有校验结果。默认自动模式、其他补帧、UI 统计节奏与 GPU 优先级保持。Claude 半成品中的 FSR 创建条件修改不属于本轮,接手时还原,精修不扩到 FSR。+3. 完成 CMake 着色器登记、依赖闭包重编译与真实 GUI 构建。所有构建/测试/缓存写 E:/项目/Veyra/<用途>/xess-handoff-20261012。+4. 同一 EXE 的旧路径/新路径跑 XeSS 中速、高速侧跑及背景横移,实际插值帧抓屏评分;检查远处背景和调试层错误。新路径无收益或负收益即撤回,不以理想矢量的上限冒充已实现收益。+5. 测真实 GTA VI 4K30、1080 光流/NR 下的图 GPU 时间及资源占用;新增开销有实测证据。相关呈现/链路/设置测试、光流首帧/seek/reset/后端切换及 GUI 启停通过。+6. 在 WORKLOG 和本文件补全实际命令、结果、失败、限制;保全旧工作树和运行组件。只提交本地分支;不合并 main、不推送、不发布、不关机。++## 起点++- main:76f41b3813972cf36b52fa0b1446f79713a1ba3e。+- Claude:7fe3ea652b24db16c04557c7b58624f7efebbd53,2 已提交诊断改动,5 未完成文件。+- 独立不可变快照:E:/项目/Veyra/archives/xess-handoff-20261012/start.json,61 工作树/509 脏文件;source-before.bundle 已 verify。+- 开工时尚未构建或测试新的修复,不把 Claude J0 的历史结果当本轮通过。++## 完成记录++已完成资源/描述符/初始化顺序、定向派发与释放、CMake、160 项 GPU 检查、六组完整插值帧画质对照、GTA6 普通优先级性能对照、实际 GUI 2X/4X 与生命周期回归。完整命令、回执、失败夹具修正及未验证范围见 docs/XESS_HANDOFF_REPORT_2026-10-12.md。本地构建为 2.0.6-xess-fix-test-20261012;未合入 main、推送或发布。diff --git a/docs/XESS_HANDOFF_REPORT_2026-10-12.md b/docs/XESS_HANDOFF_REPORT_2026-10-12.mdnew file mode 100644index 00000000..5ba6d478--- /dev/null+++ b/docs/XESS_HANDOFF_REPORT_2026-10-12.md@@ -0,0 +1,71 @@+# XeSS 开启光流时的运动边界修复(2026-10-12)++本轮接手 Claude 最新本地会话 d6689aca-8401-42b5-8005-40a5adb7fb7f。其最后的用户要求是修开启光流后的果冻,自动模式保持,延迟研究暂缓。来自 claude/jelly-20261012 的两个诊断提交 66e2407、7fe3ea6 与五个未完成文件已继承到 codex/xess-handoff-20261012;原树、桌面树和 main 保留。独立 start.json 与 source-before.bundle 在 E:/项目/Veyra/archives/xess-handoff-20261012。++## 已确认的问题与修复++NVOF 的网格矢量可能跨越人物和背景边界,原有校验还会把低置信度区域清零。Claude 的 XeSS 诊断显示更准确的运动输入有改善空间;这证明运动边界是可改善因素,尚不能断言用户所有果冻均由这一项造成。++保留 Claude 的两个 shader 算法,完成其遗漏的产品接线:++- FlowRefine 在每个光流像素选择邻近网格中与前帧亮度块更匹配的 current→previous 矢量;FlowFill 对匹配差的区域借用附近相似颜色、低代价的矢量。这是有界启发式处理,没有修改 XeSS 模型。+- 只在 XeSS + 显式光流 + NVIDIA NVOF 时建立这条分支。Automatic/Zero、AMD FidelityFX/GPU DIS 光流和其他补帧沿用原路径;NR/SR 仍用原有校验后的光流。Claude 半成品中扩大 FSR 光流初始化条件的改动已还原。+- 修正创建顺序、3 个 compute pass 的 shader/descriptor 对应关系、SRV/UAV 转换与屏障、尺寸缩放、资源预算和释放。首帧、reset 和没有有效帧对时仍送零运动并保持无历史标识。+- 将新增工作纳入现有 GPU 光流计时,避免性能面板漏算。没有增加 UI Timer,没有提高 33ms 统计或约 250ms 状态更新频率,没有改变 GPU 优先级默认值。测试显式选择普通 class 2;当前产品原有默认是实时 class 5,不能把两者混为一谈。++正常播放未增加 GPU→CPU 像素回读、逐帧 CPU fence 等待或无界队列。读回只存在于诊断测试。++## 构建与可复验命令++命令前缀为本机 Python 3.11 -X utf8 -B -I。以下相对产物路径均基于 E:/项目/Veyra,各 subprocess 测试最多 290 秒,构建设总上限 890 秒。++1. tmp/xess-handoff-20261012/build.py:最终产品回执 logs/xess-handoff-20261012/build-20261012-111040/receipt.json,22.2 秒,17 个依赖闭包对象核对/重编、16 个 EXE 链接成功。使用已验 main 构建对象和固定依赖,不是 clean 全工程重编。EnhanceGraph.h 的所有使用者按传递 include 重编。+2. tmp/xess-handoff-20261012/configure.py:configure-20261012-111144/receipt.json,完整产品功能配置和新 shader/test target 登记成功;没有引入 Qt Quick 私有重绘接口。+3. tests/xess-handoff-20261012/harness/regress.py xess-motion chain contracts hdr video rollback:logs/xess-handoff-20261012/xess/tests-20261012-111135/receipt.json,六组 exit 0。160 项真实 NVOF/GPU 检查、6 个实际改变的运动帧对、D3D12 错误 0;首帧/reset/Automatic 为零,原有校验光流与未增强的实帧逐字节一致,重建/释放正常。真实 GTA6 设置事务、失败回退与 HDR 颜色回归同时通过。+4. tests/xess-handoff-20261012/harness/ui.py perf-old perf-new lifecycle:logs/xess-handoff-20261012/xess-ui-20261012-111651/receipt.json,40.3/40.0/50.1 秒,三组 exit 0。实际 GUI seek、暂停恢复、2X→4X、零运动、AMD FidelityFX 光流→NVOF、补帧关闭/开启通过。日志确认 4X 的 SDK framesPresented=4;AMD 光流也在本机 RTX 上实际 Dispatch result=0,不代表 AMD 显卡验收。临时 QML 探针已删除,Main.qml 恢复源文件字节。+5. tmp/xess-handoff-20261012/rebuild-boundary.py 仅重建抓屏诊断测试:logs/xess-handoff-20261012/boundary-build-20261012-112011/receipt.json,4.0 秒;产品及其他 EXE 哈希保持。+6. tests/xess-handoff-20261012/harness/quality.py:logs/xess-handoff-20261012/quality-20261012-112023/results.json,六组 exit 0,每组 11/11 个暖机后的中间帧、调试层和采集错误均 0。+7. tmp/xess-handoff-20261012/check-launcher.py:reports/xess-handoff-20261012/launcher.json,9.6 秒,实际启动测试入口并核对 XeSS2X/光流/NVOF/原版NR1080p配置,再按时退出;检查探针也已删除。++## 画质对照++同一 EXE、同一场景用 VEYRA_TEST_FLOW_REFINE=0/1 切换旧/新路径,2560×1440、XeSS 2X、光流 1280×720。SDK 测试开关只显示插值帧,再用桌面复制抓取实际显示像素;HDR 桌面的 SDR 白电平按 4.75 还原。27/80 是每个 30fps 源帧的位移像素,不是播放帧率。++| 场景 | 旧轮廓带 MAE8 | 新轮廓带 MAE8 | 误差降低 |+| --- | ---: | ---: | ---: |+| 人物中速侧跑 27px | 6.8755 | 6.3781 | 7.23% |+| 人物高速侧跑 80px | 8.2148 | 7.4180 | 9.70% |+| 背景横移 80px | 3.7651 | 3.0332 | 19.44% |++远处背景 MAE8 分别 1.3340→1.2589、0.4784→0.3884、0.5131→0.3873,没有本组对照中的背景负收益。腿部截图人工核对可见网格边缘改善,也仍有细条弯曲等残留。误差下降不是“果冻减少多少”的用户体验百分比。++SDK 在“只显示插值”诊断模式中的 generated counter 为 0;不拿该计数当生成成功证明。每个目标中间帧均通过像素匹配找到,matchedReal=0;正常 GUI 测试另有实际 SDK 2X/4X 提交记录。++## 性能对照与成本++本机 RTX 5070、616.56,用户指定的 GTA VI 原 4K30 视频、原版 NR 一层/内部 1080p、NVOF 1080p、SR/HDR/调色关闭、XeSS 2X。两组均在打开视频前设定普通 GPU class 2,不改真实用户配置。预热后取相同源帧 300–840,共 541 帧;20 个独立 GUI 秒样本。++| 指标 | 旧路径 | 新路径 |+| --- | ---: | ---: |+| GPU 处理图中位数 | 8.4835ms | 8.8310ms |+| GPU 处理图 P95 | 8.6534ms | 9.0396ms |+| 提交 FPS 中位数 | 60.0 | 60.0 |+| 暖机后显存读数中位数 | 1980MiB | 2037MiB |++新增 GPU 成本约 0.348ms(本组 +4.10%),固定纹理预算约 56MiB,实测显存读数 +57MiB。GPU 图按同一帧 Color.begin→Residual.end 计算,不能把 XeSS presenter 的异步 FgBatch 时间戳混进去,也不是全部 XeSS 生成耗时或屏幕端到端延迟。现有“光流”统计新增约 0.57ms,还包含过去未计入该区间的 densify/adapt;真实新增成本应看上述同边界处理图,不能用两版 UI 阶段之差替代。++分析脚本 tmp/xess-handoff-20261012/analyze.py,汇总 reports/xess-handoff-20261012/validation.json。先前 110652 对照约 +0.340ms/+57MiB,与最终复测一致。++## 失败记录与限制++- 第一轮性能夹具误把 sizePolicy=1 当实时 1080p,实际为 Native 4K,且没有显式固定普通优先级。xess-ui-20261012-110508 保留,已作废;110652 和最终 111651 确认资源尺寸与 class 2 后重测。+- quality-20261012-111634 的第二组只抓到 4/11 个有效目标中间帧:桌面重复更新耗尽 64 张容量,并非产品报错。诊断测试改为仅保留像素不同的相邻截图、容量有界 128,完成条件加强为 11/11 且无采集错误。六组完整重测与此前 110221 的 11/11 结果一致,没有降低验收门槛。+- 单独重链测试最初漏设缓存库工作目录,LNK1181;修正后 exit 0。保护核对器起初没处理两棵 detached HEAD,误报失败;修正为空引用与开工值 None 比较后 61 树/509 脏文件一致。失败输出保留,不计入成功。+- 首次启动器检查在等待继承管道关闭后才查询进程,错过已正常退出的 GUI;日志显示启动与按时退出均正常。也发现种子配置需要一起复制 chain-session.v1.field-render 迁移旁文件;补齐后直接在真实 GUI 读取配置断言通过,未修改产品持久化逻辑。+- 本轮没有用户所述真实游戏片源的逐帧真值、AMD/Intel 显卡、长期显存、屏幕延迟和所有 HDR+XeSS 组合实机验收。不能宣称果冻根治或所有设备变快;本轮是用小幅 GPU/显存成本换取已测运动边界改善。++## 本地交付与保护++本地运行目录 E:/项目/Veyra/tests/xess-handoff-20261012/app,版本 2.0.6-xess-fix-test-20261012。入口 Start-XeSS-Test.cmd 使用独立配置目录;选择 XeSS 的“光流”运动来源才能测试新增分支。产品 EXE SHA256 43a5fea655a3b2840e5f5f25befac70c8ad6cd2de2f78c79385d8f83ea658edc。++运行组件沿用原件:libxess_fg.dll 1.3.1.78 / SHA256 EC5E0C65E075570C6EDE72618BB666D0BE0C2E10B2EA9762C0FE8CB8E375AB27;原版 NR E16BCF15E16E13F527491CDF7845B2FE6521A738D8F7C9C721866A8496E1FC8E。1626 母包文件 SHA 核对不变;DLL、SDK、模型、测试媒体均未入 Git。保护、最终 commit、source-after.bundle 与回执哈希见 reports/xess-handoff-20261012/final.json。本轮不 main 合并、不 push、不发布、不关机。diff --git a/include/veyra/pipeline/EnhanceGraph.h b/include/veyra/pipeline/EnhanceGraph.hindex 63e44a05..d2e4ce0f 100644--- a/include/veyra/pipeline/EnhanceGraph.h+++ b/include/veyra/pipeline/EnhanceGraph.h@@ -702,6 +702,11 @@ private:uint32_t nrLayerCount_=1;ComPtr<ID3D12Resource> presentMotion_[2];bool presentMotionValid_[2]={};+ // XeSS present-path motion with the optical-flow source: per-pixel refined NVOF+ // vectors with disocclusion fill (FlowRefine/FlowFill), never zeroed. NR/SR keep+ // the validated baseFlow_. VEYRA_TEST_FLOW_REFINE=0 restores the previous input.+ bool flowRefine_=false;+ ComPtr<ID3D12Resource> fgFlowRefined_,fgFlowFilled_,fgBaseFlow_;uint64_t motionPreviousSource_[2]={},previousSource_=0;ComPtr<ID3D12Resource> proxyTex_;ComPtr<ID3D12Resource> neuralTex_;@@ -727,6 +732,7 @@ private:float toneMapPeakNits_=0; // latched per graph/source; never varies with frame brightnessComputePass rgbPass_,hdrVideoSrPass_;ComputePass downsamplePass_,residualPass_,stackProtectionPass_,flowAdaptPass_;+ ComputePass flowRefinePass_,flowFillPass_,fgFlowAdaptPass_;// Stage-5 output stabiliser (anti-flicker). Constructed only when the// setting is non-zero; a default (0) session never allocates it and the// dispatch is skipped, so the disabled path is unchanged.diff --git a/shaders/FlowFill.hlsl b/shaders/FlowFill.hlslnew file mode 100644index 00000000..760115ec--- /dev/null+++ b/shaders/FlowFill.hlsl@@ -0,0 +1,48 @@+// Disocclusion fill for frame-generation motion (after FlowRefine). A pixel whose best+// candidate still does not match the previous frame has no correspondence there: usually+// background that a moving object has just uncovered. Zero or a wrong vector makes the+// interpolator drag that background with the object (the "jelly" around characters).+// Take the vector of the most similar-coloured confident pixel nearby instead; uncovered+// background resembles the background beside it, which moves with the background.+Texture2D<float4> refined : register(t0); // xy vector, z best cost (FlowRefine)+Texture2D<float4> currentColor : register(t1); // flow extent+RWTexture2D<float2> output : register(u0); // flow extent, current->previous pixels++cbuffer FlowFillConstants : register(b0)+{+ uint flowW;+ uint flowH;+ float threshold; // best cost above this has no correspondence+ float distanceWeight; // colour distance added per pixel of search distance+ uint unused0;+ uint unused1;+ uint unused2;+ uint unused3;+};++static const int2 kDirections[8] = { int2(1, 0), int2(-1, 0), int2(0, 1), int2(0, -1), int2(1, 1), int2(-1, 1), int2(1, -1), int2(-1, -1) };+static const int kRadii[9] = { 2, 4, 8, 12, 16, 24, 32, 48, 64 };++[numthreads(16, 16, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ if (id.x >= flowW || id.y >= flowH) return;+ const int2 p = int2(id.xy);+ const float4 own = refined[p];+ if (own.z <= threshold) { output[p] = own.xy; return; }+ const float3 colour = currentColor[p].rgb;+ float bestScore = 1e9;+ float2 vector = own.xy;+ [loop] for (int r = 0; r < 9; ++r) {+ [unroll] for (int d = 0; d < 8; ++d) {+ const int2 q = p + kDirections[d] * kRadii[r];+ if (any(q < 0) || q.x >= int(flowW) || q.y >= int(flowH)) continue;+ const float4 candidate = refined[q];+ if (candidate.z > threshold) continue;+ const float3 delta = currentColor[q].rgb - colour;+ const float score = dot(abs(delta), float3(1, 1, 1)) + distanceWeight * kRadii[r];+ if (score < bestScore) { bestScore = score; vector = candidate.xy; }+ }+ }+ output[p] = vector;+}diff --git a/shaders/FlowRefine.hlsl b/shaders/FlowRefine.hlslnew file mode 100644index 00000000..aa3bd84a--- /dev/null+++ b/shaders/FlowRefine.hlsl@@ -0,0 +1,52 @@+// Frame-generation motion refinement (XeSS, motion source "optical flow").+// NVOF returns one current->previous vector per grid cell, so a cell that straddles a+// moving character and the background moves both with one vector. Per flow pixel, pick+// the vector of the 3x3 neighbouring cells whose 3x3 luma patch matches the previous+// frame best: motion boundaries follow the picture instead of the grid. Unlike+// NvofDensify nothing is zeroed; the best cost is kept for FlowFill to find pixels that+// have no correspondence at all (background uncovered by a moving object).+Texture2D<int2> rawFlow : register(t0); // grid extent, S10.5 flow pixels+Texture2D<float4> previousColor : register(t1); // flow extent+Texture2D<float4> currentColor : register(t2); // flow extent+RWTexture2D<float4> refined : register(u0); // xy vector, z best cost, w own-cell cost++cbuffer FlowRefineConstants : register(b0)+{+ uint gridW;+ uint gridH;+ uint flowW;+ uint flowH;+ uint gridSize;+ float tieBias; // added to every neighbour cell's cost: the own cell wins ties+ uint unused0;+ uint unused1;+};++float luma(float3 c) { return dot(c, float3(.2126, .7152, .0722)); }++[numthreads(16, 16, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ if (id.x >= flowW || id.y >= flowH) return;+ const int2 p = int2(id.xy);+ const int2 limit = int2(flowW - 1, flowH - 1);+ float current[9];+ [unroll] for (int j = 0; j < 9; ++j)+ current[j] = luma(currentColor[clamp(p + int2(j % 3 - 1, j / 3 - 1), int2(0, 0), limit)].rgb);+ const int2 cell = p / int(gridSize);+ const int2 cellLimit = int2(gridW - 1, gridH - 1);+ float bestCost = 1e9, ownCost = 0;+ float2 best = 0;+ [unroll] for (int k = 0; k < 9; ++k) {+ const int2 offset = int2(k % 3 - 1, k / 3 - 1);+ const float2 v = float2(rawFlow[clamp(cell + offset, int2(0, 0), cellLimit)]) / 32.0;+ const int2 q = p + int2(round(v));+ float cost = 0;+ [unroll] for (int j = 0; j < 9; ++j)+ cost += abs(current[j] - luma(previousColor[clamp(q + int2(j % 3 - 1, j / 3 - 1), int2(0, 0), limit)].rgb));+ cost /= 9;+ if (k == 4) ownCost = cost; else cost += tieBias;+ if (cost < bestCost) { bestCost = cost; best = v; }+ }+ refined[p] = float4(best, bestCost, ownCost);+}diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cppindex 9bf1581a..c9f66e14 100644--- a/src/pipeline/EnhanceGraph.cpp+++ b/src/pipeline/EnhanceGraph.cpp@@ -455,6 +455,10 @@ bool EnhanceGraph::initialize(const EnhanceGraphDesc& desc)(!desc.noNgx || engine::fsrFrameGeneration(desc.frameGenerationBackend)||desc.frameGenerationBackend==engine::FrameGenerationBackend::Vfg);nvofStandalone_ = desc.enableNvofStandalone && !desc.noFeatures;if(desc_.opticalFlowBackend==engine::OpticalFlowBackend::AmdFidelityFx&&desc.amdFlowHalfResolution){nvofW_=std::max(1u,nvofW_/2);nvofH_=std::max(1u,nvofH_/2);}+ wchar_t refine[4]{};+ const bool refineDisabled=GetEnvironmentVariableW(L"VEYRA_TEST_FLOW_REFINE",refine,4)&&refine[0]==L'0';+ flowRefine_=presentSinkFg()&&desc_.fgUsesFlow()&&+ desc_.opticalFlowBackend==engine::OpticalFlowBackend::Nvidia&&!refineDisabled;uint64_t budget=0,usage=0;// Every NR layer allocates its own full set of textures, and a stabilised// layer adds two history/guide pairs on top. The stack is bounded (16 nodes),@@ -480,7 +484,8 @@ bool EnhanceGraph::initialize(const EnhanceGraphDesc& desc)const unsigned generatedTextures=fgEnabled_?(fsrEnabled()?2u:vfg?2u*(desc_.fgMultiplier-1u):10u):0;const uint64_t estimate=uint64_t(workW_)*workH_*(76u+4u*generatedTextures)+vfgSharedBytes+nrTextureBytes+fullLayerBytes- +uint64_t(srcW_)*srcH_*(32u+(desc_.protectionBeforeSr()?8u:0u))+temporalBytes+tailColorBytes+interProtectionBytes;+ +uint64_t(srcW_)*srcH_*(32u+(desc_.protectionBeforeSr()?8u:0u))+temporalBytes+tailColorBytes+interProtectionBytes+ +(flowRefine_?uint64_t(nvofW_)*nvofH_*12u+uint64_t(workW_)*workH_*4u:0);if(context_.videoMemoryInfo(budget,usage)){veyra::log::info("memory",std::format("graph lower-bound={}MiB budget={}MiB usage={}MiB; SDK allocations additional",estimate>>20,budget>>20,usage>>20));if(usage>=budget||estimate>budget-usage){veyra::log::error("memory","insufficient adapter budget for requested graph textures");return false;}@@ -602,6 +607,15 @@ bool EnhanceGraph::createResources()baseFlow_=makeTexture(context_.device(),workW_,workH_,DXGI_FORMAT_R16G16_FLOAT,true);if(presentSinkFg())for(auto& motion:presentMotion_){motion=makeTexture(context_.device(),workW_,workH_,DXGI_FORMAT_R16G16_FLOAT,false);if(!motion)return false;}if(!residualRgba_||!nrFlow_||!baseFlow_)return false;+ // XeSS with the optical-flow source: refined NVOF vectors (FlowRefine/FlowFill).+ // NVOF only - the refinement reads NVOF's grid vectors.+ if(flowRefine_){+ fgFlowRefined_=makeTexture(context_.device(),nvofW_,nvofH_,DXGI_FORMAT_R16G16B16A16_FLOAT,true);+ fgFlowFilled_=makeTexture(context_.device(),nvofW_,nvofH_,DXGI_FORMAT_R16G16_FLOAT,true);+ fgBaseFlow_=makeTexture(context_.device(),workW_,workH_,DXGI_FORMAT_R16G16_FLOAT,true);+ if(!fgFlowRefined_||!fgFlowFilled_||!fgBaseFlow_)return false;+ }+ if(presentSinkFg())veyra::log::info("graph",std::format("present-sink FG motion: {}",!desc_.fgUsesFlow()?"zero":flowRefine_?"refined NVOF (FlowRefine+FlowFill)":"validated flow"));// Colour grade tables (v4): only allocated when the stage is enabled.colorActive_=desc_.color.enabled&&!desc_.nodeColor(0);if(colorActive_){@@ -1513,6 +1527,11 @@ bool EnhanceGraph::createComputePasses()if(nrInstances_.size()>1&&!stackProtectionPass_.create(context_.device(),cs,4,3,1,40))return false;}if(!flowAdaptPass_.loadShader("FlowAdapt.dxil",cs)||!flowAdaptPass_.create(context_.device(),cs,3+UINT(nrInstances_.size()),1,1))return false;+ if(flowRefine_){+ if(!fgFlowAdaptPass_.create(context_.device(),cs,2,1,1))return false;+ if(!flowRefinePass_.loadShader("FlowRefine.dxil",cs)||!flowRefinePass_.create(context_.device(),cs,4,3,1))return false;+ if(!flowFillPass_.loadShader("FlowFill.dxil",cs)||!flowFillPass_.create(context_.device(),cs,3,2,1))return false;+ }// Stage-5 output stabiliser. Only allocated when the setting is non-zero:// a default session never pays for it and the dispatch is skipped below, so// the disabled path stays byte-identical to a build without this pass.@@ -1709,6 +1728,19 @@ bool EnhanceGraph::createViews()makeUav(context_.device(),baseFlow_.Get(),DXGI_FORMAT_R16G16_FLOAT,cpu(flowAdaptPass_,2));for(size_t i=0;i<nrInstances_.size();++i)makeUav(context_.device(),nrInstances_[i]->motion(),DXGI_FORMAT_R16G16_FLOAT,cpu(flowAdaptPass_,3+UINT(i)));+ if(flowRefine_){+ // FlowRefine: 0 raw grid vectors, 1 previous, 2 current; 3 refined. FlowFill: 0 refined,+ // 1 current; 2 filled. Adapt: 0 filled; 1 work-extent XeSS motion.+ D3D12_SHADER_RESOURCE_VIEW_DESC raw{};raw.Format=DXGI_FORMAT_R16G16_SINT;raw.ViewDimension=D3D12_SRV_DIMENSION_TEXTURE2D;+ raw.Shader4ComponentMapping=D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;raw.Texture2D.MipLevels=1;+ stager_.stageSrv(nvofRawTex_.Get(),&raw,flowRefinePass_.heap.Get(),0);+ stagedSrv(nvofInA_.Get(),DXGI_FORMAT_B8G8R8A8_UNORM,flowRefinePass_,1);stagedSrv(nvofInB_.Get(),DXGI_FORMAT_B8G8R8A8_UNORM,flowRefinePass_,2);+ makeUav(context_.device(),fgFlowRefined_.Get(),DXGI_FORMAT_R16G16B16A16_FLOAT,cpu(flowRefinePass_,3));+ stagedSrv(fgFlowRefined_.Get(),DXGI_FORMAT_R16G16B16A16_FLOAT,flowFillPass_,0);stagedSrv(nvofInB_.Get(),DXGI_FORMAT_B8G8R8A8_UNORM,flowFillPass_,1);+ makeUav(context_.device(),fgFlowFilled_.Get(),DXGI_FORMAT_R16G16_FLOAT,cpu(flowFillPass_,2));+ stagedSrv(fgFlowFilled_.Get(),DXGI_FORMAT_R16G16_FLOAT,fgFlowAdaptPass_,0);+ makeUav(context_.device(),fgBaseFlow_.Get(),DXGI_FORMAT_R16G16_FLOAT,cpu(fgFlowAdaptPass_,1));+ }if(desc_.hdrWorking()&&videoSrInput_){stagedSrv(srcRgba_.Get(),DXGI_FORMAT_R16G16B16A16_FLOAT,hdrVideoSrPass_,0);stagedSrv(videoSrInput_.Get(),DXGI_FORMAT_R8G8B8A8_UNORM,hdrVideoSrPass_,1);@@ -2347,7 +2379,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frameif(!waitForFlow())return false;}list=ring_.acquireNext(slot,st);if(!list)return false;- gpuTimer_.mark(list,GpuStage::Flow,true);+ if(!flowRefine_||!haveFlow)gpuTimer_.mark(list,GpuStage::Flow,true);}if(haveFlow) {if(amdOf_)tracker_.transition(list,amdOf_->sceneChanges(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);@@ -2362,6 +2394,21 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, FramedensifyPass_.bind(list,dc,gpuHandleOf(densifyPass_,0).ptr,gpuHandleOf(densifyPass_,5).ptr);list->Dispatch((nvofW_+15)/16,(nvofH_+15)/16,1);tracker_.uavBarrier(list,flowTex_.Get());tracker_.uavBarrier(list,confTex_.Get());+ if(flowRefine_){+ // XeSS motion: per-pixel candidate choice, then disocclusion fill.+ tracker_.transition(list,fgFlowRefined_.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS);+ const float rc[8]={uintBits(rawW_),uintBits(rawH_),uintBits(nvofW_),uintBits(nvofH_),uintBits(selectedGrid_),.004f,0,0};+ flowRefinePass_.bind(list,rc,gpuHandleOf(flowRefinePass_,0).ptr,gpuHandleOf(flowRefinePass_,3).ptr);+ list->Dispatch((nvofW_+15)/16,(nvofH_+15)/16,1);+ tracker_.uavBarrier(list,fgFlowRefined_.Get());+ tracker_.transition(list,fgFlowRefined_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ tracker_.transition(list,fgFlowFilled_.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS);+ const float fc[8]={uintBits(nvofW_),uintBits(nvofH_),.06f,.002f,0,0,0,0};+ flowFillPass_.bind(list,fc,gpuHandleOf(flowFillPass_,0).ptr,gpuHandleOf(flowFillPass_,2).ptr);+ list->Dispatch((nvofW_+15)/16,(nvofH_+15)/16,1);+ tracker_.uavBarrier(list,fgFlowFilled_.Get());+ tracker_.transition(list,fgFlowFilled_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ }tracker_.transition(list,nvofInA_.Get(),D3D12_RESOURCE_STATE_COMMON);tracker_.transition(list,nvofInB_.Get(),D3D12_RESOURCE_STATE_COMMON);tracker_.transition(list,nvofRawTex_.Get(),D3D12_RESOURCE_STATE_COMMON);@@ -2383,6 +2430,16 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Framelist->Dispatch((w+15)/16,(h+15)/16,1);tracker_.uavBarrier(list,output);tracker_.transition(list,output,D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);};adapt(nrFlow_.Get(),nrW_,nrH_,1);adapt(baseFlow_.Get(),workW_,workH_,2);+ if(flowRefine_){+ tracker_.transition(list,fgBaseFlow_.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS);+ const float c[8]={uintBits(nvofW_),uintBits(nvofH_),uintBits(workW_),uintBits(workH_),0,0,0,0};+ fgFlowAdaptPass_.bind(list,c,gpuHandleOf(fgFlowAdaptPass_,0).ptr,gpuHandleOf(fgFlowAdaptPass_,1).ptr);+ list->Dispatch((workW_+15)/16,(workH_+15)/16,1);tracker_.uavBarrier(list,fgBaseFlow_.Get());+ tracker_.transition(list,fgBaseFlow_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ // Include refinement/fill/adaptation in the existing optical-flow+ // timing. Otherwise the performance panel silently omits this work.+ gpuTimer_.mark(list,GpuStage::Flow,true);+ }for(size_t i=0;i<nrInstances_.size();++i){const auto* layer=nrInstances_[i].get();if(layer->motion()!=nrFlow_.Get())adapt(layer->motion(),layer->width(),layer->height(),3+UINT(i));}@@ -2823,7 +2880,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frameif(presentSinkFg()){// Test-only: fgMotionProbe (never set by the product) also feeds the XeSS// present path, held in COMMON, same current->previous pixel convention.- auto* input=desc_.fgMotionProbe&&!reset?desc_.fgMotionProbe:desc_.fgUsesFlow()&&haveFlow&&!reset?baseFlow_.Get():nrZeroMotion_.Get();+ auto* input=desc_.fgMotionProbe&&!reset?desc_.fgMotionProbe:desc_.fgUsesFlow()&&haveFlow&&!reset?(flowRefine_?fgBaseFlow_.Get():baseFlow_.Get()):nrZeroMotion_.Get();tracker_.transition(list,input,D3D12_RESOURCE_STATE_COPY_SOURCE);tracker_.transition(list,presentMotion_[parity].Get(),D3D12_RESOURCE_STATE_COPY_DEST);list->CopyResource(presentMotion_[parity].Get(),input);@@ -3380,6 +3437,7 @@ void EnhanceGraph::shutdown()nrInstances_.clear();for(auto& layer:nrAutoPool_)layer.reset();nrAutoLevel_=0;nrAutoPoolReady_=nrAutoResetPending_=false;residualRgba_.Reset();preSrProtectionRgba_.Reset();interNrProtectionRgba_.Reset();nrFlow_.Reset();baseFlow_.Reset();+ fgFlowRefined_.Reset();fgFlowFilled_.Reset();fgBaseFlow_.Reset();flowRefinePass_={};flowFillPass_={};fgFlowAdaptPass_={};flowRefine_=false;for(unsigned i=0;i<kGeneratedPoolSlots;++i){if(fgDisableMapped_[i]&&fgDisableReadback_[i]){D3D12_RANGE written{0,0};fgDisableReadback_[i]->Unmap(0,&written);}fgDisableMapped_[i]=nullptr;fgDisable_[i].Reset();fgDisableReadback_[i].Reset();generatedLeases_[i].reset();genFrame_[i].Reset();}for(auto& lease:realLeases_)lease.reset();fgDisableInit_.Reset();encPass_ = ComputePass{};blitPass_ = ComputePass{};hdrVideoSrPass_={};diff --git a/tests/integration/FgXessBoundaryTests.cpp b/tests/integration/FgXessBoundaryTests.cppindex 68108d8c..84ed1b42 100644--- a/tests/integration/FgXessBoundaryTests.cpp+++ b/tests/integration/FgXessBoundaryTests.cpp@@ -235,13 +235,14 @@ int wmain(int argc,wchar_t** argv){D3D11_TEXTURE2D_DESC sd{};sd.Width=CW;sd.Height=H;sd.MipLevels=1;sd.ArraySize=1;sd.Format=captureFormat;sd.SampleDesc.Count=1;sd.Usage=D3D11_USAGE_STAGING;sd.CPUAccessFlags=D3D11_CPU_ACCESS_READ;ComPtr<ID3D11Texture2D> staging;if(FAILED(device11->CreateTexture2D(&sd,nullptr,&staging)))return 2;std::vector<Image> captures;std::mutex captureLock;std::atomic<bool> stop=false;std::atomic<unsigned> captureErrors=0;+ unsigned duplicateCaptures=0;std::jthread capture([&]{while(!stop){DXGI_OUTDUPL_FRAME_INFO fi{};ComPtr<IDXGIResource> resource;const HRESULT hr=duplication->AcquireNextFrame(20,&fi,&resource);if(hr==DXGI_ERROR_WAIT_TIMEOUT)continue;if(FAILED(hr)){++captureErrors;break;}- if(fi.LastPresentTime.QuadPart&&captures.size()<64){+ if(fi.LastPresentTime.QuadPart&&captures.size()<128){ComPtr<ID3D11Texture2D> texture;if(SUCCEEDED(resource.As(&texture))){D3D11_BOX box{UINT(X0),0,0,UINT(X0+CW),UINT(H),1};context11->CopySubresourceRegion(staging.Get(),0,0,0,0,texture.Get(),0,&box);@@ -252,7 +253,13 @@ int wmain(int argc,wchar_t** argv){if(hdrDesktop){const auto* h=reinterpret_cast<const uint16_t*>(row);for(int x=0;x<CW;++x)im.rgb[size_t(y)*CW+x]={decode[h[x*4]],decode[h[x*4+1]],decode[h[x*4+2]]};}else for(int x=0;x<CW;++x)im.rgb[size_t(y)*CW+x]={row[x*4+2],row[x*4+1],row[x*4]};}- context11->Unmap(staging.Get(),0);std::lock_guard lock(captureLock);captures.push_back(std::move(im));+ context11->Unmap(staging.Get(),0);std::lock_guard lock(captureLock);+ // DWM can report multiple desktop updates for an unchanged+ // interpolated image (including the previous test window).+ // Keep distinct pixels so those updates cannot consume the+ // bounded capture budget before the later pairs are shown.+ if(!captures.empty()&&im.rgb==captures.back().rgb)++duplicateCaptures;+ else captures.push_back(std::move(im));}}}@@ -348,10 +355,10 @@ int wmain(int argc,wchar_t** argv){if(SUCCEEDED(ctx.device()->QueryInterface(IID_PPV_ARGS(&iq))))for(UINT64 i=0;i<iq->GetNumStoredMessages();++i){SIZE_T bytes=0;if(FAILED(iq->GetMessage(i,nullptr,&bytes)))continue;std::vector<uint8_t>b(bytes);auto* msg=reinterpret_cast<D3D12_MESSAGE*>(b.data());if(SUCCEEDED(iq->GetMessage(i,msg,&bytes))&&msg->Severity<=D3D12_MESSAGE_SEVERITY_ERROR){++errors;std::cerr<<msg->pDescription<<std::endl;}}- const bool complete=evaluated>=unsigned(N-Warmup-1)*2/3;- std::cout<<std::format("FG_XESS_BOUNDARY {{\"label\":\"{}\",\"captures\":{},\"matchedReal\":{},\"unmatched\":{},\"evaluated\":{},\"sdkGenerated\":{},\"bandMae\":{:.4f},\"bandBadPct\":{:.4f},"+ const bool complete=evaluated==unsigned(N-Warmup-1)&&!captureErrors;+ std::cout<<std::format("FG_XESS_BOUNDARY {{\"label\":\"{}\",\"captures\":{},\"duplicatesSkipped\":{},\"matchedReal\":{},\"unmatched\":{},\"evaluated\":{},\"sdkGenerated\":{},\"bandMae\":{:.4f},\"bandBadPct\":{:.4f},""\"outsideMae\":{:.4f},\"outsideBadPct\":{:.4f},\"innerMae\":{:.4f},\"pairDistances\":[{}],\"captureMatches\":[{}],\"hdrDesktop\":{},\"sdrWhite\":{:.3f},\"captureErrors\":{},\"errors\":{},\"pass\":{}}}",- label,captures.size(),matchedReal,unmatched,evaluated,generatedBySdk,band.mae(),band.badPercent(),outside.mae(),outside.badPercent(),inner.mae(),distances,matches,+ label,captures.size(),duplicateCaptures,matchedReal,unmatched,evaluated,generatedBySdk,band.mae(),band.badPercent(),outside.mae(),outside.badPercent(),inner.mae(),distances,matches,hdrDesktop,white,captureErrors.load(),errors,ok&&complete&&!errors?"true":"false")<<std::endl;ring.shutdown();ctx.shutdown();DestroyWindow(window);CoUninitialize();return ok&&complete&&!errors?0:1;diff --git a/tests/integration/XessMotionContractTests.cpp b/tests/integration/XessMotionContractTests.cppnew file mode 100644index 00000000..5edb9a39--- /dev/null+++ b/tests/integration/XessMotionContractTests.cpp@@ -0,0 +1,129 @@+// Real GPU checks for the XeSS-only motion branch. Pixel readback and waits are+// confined to this test; the product keeps its asynchronous GPU path.+#include "veyra/pipeline/EnhanceGraph.h"+#include "veyra/pipeline/GpuPassUtils.h"+#include "veyra/gfx/D3D12DeviceContext.h"+#include "veyra/gfx/CommandSlotRing.h"+#include "veyra/Log.h"+#include <DirectXPackedVector.h>+#include <d3d12sdklayers.h>+#include <cmath>+#include <cstring>+#include <filesystem>+#include <iostream>+#include <vector>+extern "C" {+#include <libavutil/frame.h>+#include <libavutil/pixfmt.h>+}+using namespace veyra;+using Microsoft::WRL::ComPtr;+namespace {+unsigned checks=0, failures=0;+void check(bool ok,const char* why) { ++checks;if(!ok){++failures;std::cerr<<"FAIL "<<why<<'\n';} }++std::vector<uint8_t> readTexture(gfx::D3D12DeviceContext& ctx,gfx::CommandSlotRing& ring,+ pipeline::EnhanceGraph& graph,ID3D12Resource* texture) {+ if(!texture)return {};+ const auto desc=texture->GetDesc();+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint{};UINT rows=0;UINT64 rowBytes=0,total=0;+ ctx.device()->GetCopyableFootprints(&desc,0,1,0,&footprint,&rows,&rowBytes,&total);+ D3D12_HEAP_PROPERTIES heap{};heap.Type=D3D12_HEAP_TYPE_READBACK;+ D3D12_RESOURCE_DESC buffer{};buffer.Dimension=D3D12_RESOURCE_DIMENSION_BUFFER;+ buffer.Width=total;buffer.Height=1;buffer.DepthOrArraySize=buffer.MipLevels=1;+ buffer.SampleDesc.Count=1;buffer.Layout=D3D12_TEXTURE_LAYOUT_ROW_MAJOR;+ ComPtr<ID3D12Resource> readback;+ if(FAILED(ctx.device()->CreateCommittedResource(&heap,D3D12_HEAP_FLAG_NONE,&buffer,+ D3D12_RESOURCE_STATE_COPY_DEST,nullptr,IID_PPV_ARGS(&readback))))return {};+ Status status=Status::Ok;unsigned slot=0;auto* list=ring.acquireNext(slot,status);if(!list)return {};+ const auto state=graph.diagnosticResourceState(texture);+ D3D12_RESOURCE_BARRIER barrier{};barrier.Type=D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;+ barrier.Transition={texture,D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,state,D3D12_RESOURCE_STATE_COPY_SOURCE};+ if(state!=D3D12_RESOURCE_STATE_COPY_SOURCE)list->ResourceBarrier(1,&barrier);+ D3D12_TEXTURE_COPY_LOCATION dst{},src{};+ dst.pResource=readback.Get();dst.Type=D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;dst.PlacedFootprint=footprint;+ src.pResource=texture;src.Type=D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;+ list->CopyTextureRegion(&dst,0,0,0,&src,nullptr);+ if(state!=D3D12_RESOURCE_STATE_COPY_SOURCE){std::swap(barrier.Transition.StateBefore,barrier.Transition.StateAfter);list->ResourceBarrier(1,&barrier);}+ if(!ring.submitAndSignal(slot)||!ring.waitIdle())return {};+ void* data=nullptr;D3D12_RANGE range{0,SIZE_T(total)};if(FAILED(readback->Map(0,&range,&data)))return {};+ std::vector<uint8_t> result(size_t(rowBytes)*rows);+ for(UINT y=0;y<rows;++y)std::memcpy(result.data()+size_t(y)*rowBytes,+ static_cast<uint8_t*>(data)+footprint.Offset+size_t(y)*footprint.Footprint.RowPitch,size_t(rowBytes));+ D3D12_RANGE written{0,0};readback->Unmap(0,&written);return result;+}+bool zero(const std::vector<uint8_t>& bytes) {+ if(bytes.empty()||bytes.size()%2)return false;+ for(size_t i=0;i<bytes.size();i+=2){uint16_t h;std::memcpy(&h,bytes.data()+i,2);if((h&0x7fff)!=0)return false;}+ return true;+}+bool finite(const std::vector<uint8_t>& bytes) {+ if(bytes.empty()||bytes.size()%2)return false;+ for(size_t i=0;i<bytes.size();i+=2){uint16_t h;std::memcpy(&h,bytes.data()+i,2);if(!std::isfinite(DirectX::PackedVector::XMConvertHalfToFloat(h)))return false;}+ return true;+}+struct Frame {std::vector<uint8_t> motion,flow,video;};+}+int wmain(int argc,wchar_t** argv) {+ if(argc!=2)return 2;+ const std::filesystem::path out=argv[1];std::filesystem::create_directories(out);+ Logger::instance().openFile((out/L"engine.log").wstring());+ gfx::D3D12DeviceContext ctx;gfx::CommandSlotRing ring;Status status=Status::Ok;+ gfx::DeviceContextDesc dd;dd.enableDebugLayer=true;+ if(!ctx.initialize(dd,status)||!ring.initialize(ctx.device(),ctx.directQueue(),ctx.fence(),ctx.fenceEvent(),6,status))return 2;+ ComPtr<ID3D12InfoQueue> iq;ctx.device()->QueryInterface(IID_PPV_ARGS(&iq));if(!iq)return 2;+ AVFrame* frame=av_frame_alloc();if(!frame)return 2;+ frame->format=AV_PIX_FMT_RGBA;frame->width=640;frame->height=360;+ frame->color_range=AVCOL_RANGE_JPEG;frame->colorspace=AVCOL_SPC_RGB;frame->color_trc=AVCOL_TRC_IEC61966_2_1;+ if(av_frame_get_buffer(frame,32)<0)return 2;+ std::vector<Frame> legacy;unsigned changed=0;+ for(unsigned mode=0;mode<3;++mode) {+ SetEnvironmentVariableW(L"VEYRA_TEST_FLOW_REFINE",mode==0?L"0":L"1");+ pipeline::EnhanceGraph graph(ctx,ring);pipeline::EnhanceGraphDesc desc;+ desc.sourceWidth=640;desc.sourceHeight=360;desc.workWidth=1280;desc.workHeight=720;+ desc.flowWidth=320;desc.flowHeight=180;desc.rgbInput=true;+ desc.enableNr=desc.enableSr=false;desc.enableFg=true;desc.noNgx=true;+ desc.enableNvofStandalone=true;desc.fgMultiplier=2;+ desc.frameGenerationBackend=engine::FrameGenerationBackend::XeSS;+ desc.fgMotion=mode==2?engine::MotionSource::Automatic:engine::MotionSource::OpticalFlow;+ const bool initialized=graph.initialize(desc)&&graph.createViews();check(initialized,"graph initializes");if(!initialized)break;+ for(unsigned k=0;k<8;++k) {+ for(int y=0;y<frame->height;++y)for(int x=0;x<frame->width;++x) {+ auto* p=frame->data[0]+size_t(y)*frame->linesize[0]+x*4;+ const bool body=x>245&&x<385&&y>70&&y<300;+ const int moving=x+int(k)*12;+ p[0]=uint8_t(body?180:35+(moving/7+y/5)%90);+ p[1]=uint8_t(body?60:50+(moving/11+y/9)%100);+ p[2]=uint8_t(body?45:30+(moving/17+y/7)%80);p[3]=255;+ }+ const bool reset=k==0||k==4;pipeline::EnhanceGraph::FrameOutputs output;+ const bool processed=graph.process(frame,k*(1000.0/30),reset,output,k+1)&&ring.waitIdle();+ check(processed,"frame processes");if(!processed)break;+ Frame got;+ got.motion=readTexture(ctx,ring,graph,graph.presentMotion(output.videoSlot));+ got.flow=readTexture(ctx,ring,graph,graph.flowResource());+ got.video=readTexture(ctx,ring,graph,graph.videoFrameResource(output.videoSlot));+ check(finite(got.motion),"XeSS motion is finite");+ check(!got.video.empty(),"real output exists");+ check(graph.presentMotionValid(output.videoSlot)==!reset,"history validity resets together");+ if(reset||mode==2)check(zero(got.motion),"first/reset/automatic frame receives zero motion");+ else check(!zero(got.motion),"optical-flow frame receives actual motion");+ if(mode==0)legacy.push_back(std::move(got));+ else if(k<legacy.size()) {+ check(got.video==legacy[k].video,"XeSS motion repair never changes source/real output");+ if(!reset)check(got.flow==legacy[k].flow,"original validated NR/SR guidance stays identical");+ if(mode==1&&!reset&&got.motion!=legacy[k].motion)++changed;+ }+ }+ check(graph.metrics().nvofExecuteCount==6,"NVOF executes six valid frame pairs around reset");+ check(ring.drainQueue(),"bounded teardown drains");graph.shutdown();+ }+ check(changed>0,"refinement changes actual XeSS motion");+ unsigned errors=0;+ for(UINT64 i=0;i<iq->GetNumStoredMessages();++i){SIZE_T n=0;iq->GetMessage(i,nullptr,&n);std::vector<uint8_t> bytes(n);auto* message=reinterpret_cast<D3D12_MESSAGE*>(bytes.data());+ if(SUCCEEDED(iq->GetMessage(i,message,&n))&&message->Severity<=D3D12_MESSAGE_SEVERITY_ERROR){++errors;std::cerr<<message->pDescription<<'\n';}}+ check(errors==0,"D3D12 debug errors zero");check(SUCCEEDED(ctx.device()->GetDeviceRemovedReason()),"device remains healthy");+ av_frame_free(&frame);iq.Reset();ring.shutdown();ctx.shutdown();+ std::cout<<"XESS_MOTION_CONTRACT checks="<<checks<<" failures="<<failures<<" changedPairs="<<changed<<" debugErrors="<<errors<<std::endl;+ return failures?1:0;+}