Skip to content

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++

Start E0 + #53 anti-aliasing: authorization, plan, slot regression harness

Veyra Goal Agentdf8028af15d6
diff --git a/AGENTS.md b/AGENTS.md
index 32213dda..4d57ecab 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -1,5 +1,7 @@
# Veyra 项目 Agent 执行规则
+> **2026-10-17 效果器扩展基础 E0 与 #53 空间抗锯齿(Claude 子会话)**:用户“抗锯齿和美颜好好做,开工吧”(并要求开子会话用 Sonnet5.5 Extra 开工),#53 要求加入 FXAA、SMAA 之类的空间抗锯齿并与 VSR 超分搭配(DLSS 类超分会破坏 UI、VSR 抗锯齿不稳定),参考 SAOG0721/Magpie 的各种抗锯齿方案,以新效果器方式加入:列表模式是“画质”页下的新效果,节点模式是新的节点项。按 docs/EFFECTS_INFRA_AA_53_PLAN_2026-10-17.md 与 reports/claude-plan-48-53-beauty-20261017/PLAN_48_53_BEAUTY_2026-10-17.md 第 3、4 节,从 main 26c0d61 在 E盘 claude/aa-53-20261017(worktrees/aa-53-20261017)隔离实施 E0(EffectType 追加 AntiAliasing/Beauty、链容量 16→32 及满载明确拒绝、导出协议 9→10/预设库 v14/链会话 v9、GpuTimer 64 位掩码、调色专用四类插入槽通用化为每槽 pass 列表并新增源分辨率槽与 NR 组之后槽)与抗锯齿(FXAA/SMAA/MLAA、实验时域 SMAA;EnhanceGraph 接点、新 AntiAliasPass、着色器、bridge/QML/翻译/预设/会话/导出/许可),这些具体接点覆盖旧冻结。E0 提交并回归后建 claude/effects-infra-20261017 指向该提交,供美颜会话合入且不再移动。先存档 archives/claude-aa-53-20261017(start.json:88 工作树/100 分支/主检出 64 脏文件逐文件 SHA256;source-before.bundle verify 通过,76,295,892 字节,SHA256 f22a36f9…1095)。调色输出须与改动前逐字节一致;UI33ms/250ms、GPU 默认优先级、运行库/模型/驱动/真实配置不动,不派 Agent,不 merge/push/Release/打包,不评论或关闭 issue;测试≤300秒、构建≤900秒;产物全 E:/项目/Veyra/{build,tests,logs,tmp,reports,archives}/claude-aa-53-20261017。AMD/Intel 实卡与用户 Switch 素材未验须明示,不用本机 RTX 结果外推。
+
> **2026-10-17 PR57本机接入授权**:用户要求合入其云端Agent的PR57并做好测试。按docs/PR57_INTEGRATION_PLAN_2026-10-17.md,从main d68d6be在codex/pr57-capture-window-20261017保留原head09ac54b/1295d6b整合;允许窗口捕获游戏输入/缩放/resize及采集能力/精确格式/旧版选择入口的必要适配、源/引擎快照/bridge/QML/CMake/翻译/回归接点,覆盖这些范围历史冻结。本机Windows构建/实测通过后允许本地main正常合并与普通GitHub同步以完成PR57;不发布新版本、不改已发2.0.9资产/标签、不代发评论/关闭无关issue/派Agent/关机。84旧树/96旧分支/509脏文件与PR/源码bundle先存档;全E盘,测试≤300秒/构建≤900秒,UI33ms/250ms、既有低延迟/运行组件/模型/驱动/真实配置保持。云端测试待办不扩展当前授权,实卡未覆盖项须明示。
> **2026-10-17 2.0.9 正式发布授权**:用户明确“发布吧,老样子发好给我群公告”。按docs/RELEASE_2.0.9_PLAN_2026-10-17.md从已验bfce70b建立codex/release-2.0.9-20261017,允许已验代码main正常快进/普通push nrvideo/main、新v2.0.9与v2.0.9-sources标签、正式Release及对应源码上传。NVIDIA/AMD沿用已交付2.0.9-test ZIP,外部正式命名,包内字节/test标识保持,不重编译重封包。中英README和完整更新报告覆盖全部2.0.8后改动,保留六群/赞助width220、Discord/Ko-fi/知识库;主仅两包,源归档上传应用源与新增去隔行源,旧FFmpeg/依赖源保留固定链接。83旧树/95旧分支/509脏文件/六原归档与旧Release保护,全E盘,无子Agent/代发/关闭issue/关机。最新授权覆盖此前本轮no-main/no-push/no-Release,不扩展为修改专有二进制、驱动或用户配置。
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3d73abd9..724f4eba 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1350,6 +1350,14 @@ target_link_options(veyra_hdr_tuning_tests PRIVATE /STACK:33554432)
target_compile_definitions(veyra_color_grade_gpu_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
target_include_directories(veyra_color_grade_gpu_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${FFMPEG_INCLUDE_DIRS})
target_link_libraries(veyra_color_grade_gpu_tests PRIVATE veyra_pipeline veyra_sinks)
+ # Byte-exact regression for the effect insertion slots (colour today, more
+ # effects later): one frame per configuration through the real graph, printed
+ # as SHA-256 so a build from before a change can be compared with one after it.
+ add_executable(veyra_effect_slot_regression_tests tests/integration/EffectSlotRegressionTests.cpp)
+ target_compile_features(veyra_effect_slot_regression_tests PRIVATE cxx_std_20)
+ target_compile_options(veyra_effect_slot_regression_tests PRIVATE /utf-8)
+ target_compile_definitions(veyra_effect_slot_regression_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
+ target_link_libraries(veyra_effect_slot_regression_tests PRIVATE veyra_engine)
# Adobe .cube parsing + the runtime LUT store (CPU only).
add_executable(veyra_color_lut_tests tests/unit/ColorLutTests.cpp src/engine/ColorLut.cpp)
target_compile_features(veyra_color_lut_tests PRIVATE cxx_std_20)
diff --git a/docs/EFFECTS_INFRA_AA_53_PLAN_2026-10-17.md b/docs/EFFECTS_INFRA_AA_53_PLAN_2026-10-17.md
new file mode 100644
index 00000000..c71693b4
--- /dev/null
+++ b/docs/EFFECTS_INFRA_AA_53_PLAN_2026-10-17.md
@@ -0,0 +1,64 @@
+# 效果器扩展基础 E0 与 #53 空间抗锯齿:施工方案(2026-10-17)
+
+分支 `claude/aa-53-20261017`(worktree `E:/项目/Veyra/worktrees/aa-53-20261017`),基线 main `26c0d61`。上位计划:`E:/项目/Veyra/reports/claude-plan-48-53-beauty-20261017/PLAN_48_53_BEAUTY_2026-10-17.md` 第 3、4 节。授权与用户原话见 `AGENTS.md` 顶部同日条目。
+
+存档:`E:/项目/Veyra/archives/claude-aa-53-20261017/`(`start.json`:88 工作树 / 100 分支 / 主检出 64 个脏文件逐文件 SHA256;`source-before.bundle` verify 通过,76,295,892 字节,SHA256 `f22a36f998b4d0b7eaa181537fc68b2c32fb2a75229a508f0af65d4803041095`)。产物目录:`{build,tests,logs,tmp,reports,archives}/claude-aa-53-20261017`。
+
+## 1. 范围
+
+两件事,按顺序,分开提交:
+
+1. **E0 效果器扩展基础**(抗锯齿与美颜共用,只在本会话做一次;美颜会话合入 `claude/effects-infra-20261017`)。
+2. **#53 空间抗锯齿**:FXAA 中/高/极高、SMAA 低/中/高/极高、MLAA(阈值/强度)、实验“时域 SMAA”(T2x/4x NoJitter,默认关)。
+
+不做:带抖动的 SMAA T2x/4x、会改分辨率的 Anime4K 3D AA 放大与 SGSR、整套 MagpieFX 通用运行时。
+
+## 2. 现状(main `26c0d61`)要点
+
+- 调色在图里有三类位置:①列表/节点首个调色融合进输入转换,列表额外调色在 `srcRgba_` 上逐个原位执行(`additionalColorInstances_`);②节点模式的“槽”调色(SR 前/NR 前/NR 层间/链尾),由 `EnhanceGraphDesc::preSrColor/preNrColor/interNrColorTarget/tailColor` 按**调色参数序号**判定,`EnhanceGraph` 里各有一份维护计数、输出指针、视图和派发代码;③这些判定同时驱动 `validateFixedExecutionPlan` 的次序校验。
+- `kMaxChainNodes=16`,`toChain()` 满载静默覆盖最后一格;`EffectType` 6 项;`GpuStage` 25 项,`GpuTimer` 用 32 位掩码;导出共享协议 9、预设库最高 13、链会话最高 8。
+
+## 3. E0 设计
+
+### 3.1 数据与格式
+- `EffectType` 末尾追加 `AntiAliasing`(6)、`Beauty`(7),既有数值不变;`effectTypeCount` 与所有定长数组(目录、计划资源计数、列表顺序表)随之 8 项。目录项新增 `hidden`:`Beauty` 在 E0 起即隐藏;`AntiAliasing` 在 E0 提交内隐藏,抗锯齿提交中放开。
+- `kMaxChainNodes` 16→32;`toChain()` 满载不再覆盖,返回明确失败(`EffectChain::overflow` 标记,`validateChain` 拒绝);`NodeGraphLayout` 等相关数组随常量增长。
+- `AntiAliasSettings`(方式、质量档、MLAA 阈值/强度、时域实验与历史权重)进入 `ChainNode`/`EnhancementSettings`(实例 0 为 `antiAlias`,第 2 实例为 `additionalAntiAlias`,与调色同构),含校验、`activeVideoSettings`、`sameVideoConfiguration`、`requiresGraphRebuild`。
+- 导出共享协议 9→10(`bytes=sizeof(Shared)` 校验保留);预设库最高 v14(只有含新类型/超过 16 节点的内容写 v14,旧内容仍写最低够用版本);链会话最高 v9。旧版读到更高版本明确拒绝并保留原文件;导出 worker 版本/字节不符拒绝。
+- `GpuStage` 增加 `AaNode0-1`、`BeautyNode0-5`、`BeautyDetect`(共 34 项),`GpuTimer` 掩码 64 位;`enhancementProcessingMs` 把抗锯齿区间并入增强链耗时;旧 Win32 遥测名表同步。
+
+### 3.2 插入槽通用化(图内)
+- 新接口 `SlotPass`(`createViews/dispatch/reset`,同尺寸输入→输出的简单 pass);`ColorGradeInstance` 实现它,`AntiAliasPass`、以后的美颜 pass 也实现它。
+- `EnhanceGraphDesc` 用**按计划步骤**的 `placementOfStep(step)` 取代四个按调色序号的判定:返回 `Ingress / SourcePost / PreSr / PreNr / InterNr(target) / Tail`。判定条件逐字沿用旧四个函数,仅把“邻接的调色”推广为“邻接的简单 pass”(调色、抗锯齿、美颜);旧函数保留为薄封装,`EffectChainTests` 里的既有断言继续成立。
+- 列表模式(无 `runtimeNodeOrder`)按类型固定:调色=Ingress,抗锯齿=SourcePost,美颜=Tail。节点模式头部区域(第一个 SR/NR/保护之前)的前导调色仍走输入转换融合;其后的简单 pass 进 SourcePost,其间的调色(含参数 0)作为槽内节点调色,保证“按链顺序执行”。
+- 图内每个槽一张 `SlotList`(按计划顺序的 `{pass, output, 计划步骤, 尺寸, 计时阶段}`),统一做资源创建、视图绑定、派发与计时;原调色四类派发/视图/计数/日志代码改为遍历槽列表,调色输出逐字节不变。
+- 新槽:`SourcePost`(输入转换与列表额外调色之后、任何放大之前,源分辨率)供抗锯齿;`Tail` 在列表模式预留给美颜(NR 组含保护收尾之后、RTX HDR 之前,NR 先行时在 SR 之后)。
+- 对比视图“原画”仍取抗锯齿之前的 `srcRgba_`;`workRgba_` 与 SR/NR 的“阶段输入”改走 `stageInput` 访问器。
+
+### 3.3 界面接点
+- `effectCatalog/effectAvailability` 新 id `aa`、`beauty`(隐藏项不进入菜单);节点页编辑器分发、色标;列表处理顺序条;`nodeTimings`/`stageTimings`;四语言翻译。
+
+## 4. 抗锯齿设计(E0 之后)
+
+- 着色器:`shaders/MagpieCompat.hlsli`(`GetInputPt/GetInputSize/GetOutputSize/Rmp8x8/GetFrameCount` 与 PS 风格 pass→CS 包装)、`shaders/Fxaa.hlsli`、`shaders/Smaa.hlsli`、`shaders/Mlaa.hlsli`;CMake 增 `veyra_add_compute_shader_variant`(同源多预设,`-D` 宏)。`ComputePass::create` 增可选静态采样器。
+- 颜色域:线性 FP16 工作纹理;先用一个小 pass 把线性颜色转成感知亮度纹理(SDR sRGB 曲线,HDR=PQ 归一化亮度,负值/超范围夹到 0 后编码);边缘检测只读它;混合与邻域重采样仍作用在线性纹理,HDR 高光与负分量保留。
+- `AntiAliasPass`:持有各变体 PSO、`edges/blend` 中间纹理、SMAA 查找纹理、时域历史;seek/切镜/断点/尺寸变化/重建重置历史。
+- 位置:列表 `调色→抗锯齿→SR→NR→保护→(美颜)→RTX HDR→补帧`,NR 先行 `调色→抗锯齿→NR→保护→SR→…`;节点模式最多 2 个实例,RTX HDR 之后禁止。
+- 界面:“画质”页最上方(超分辨率之上)新卡片“抗锯齿”;节点“添加节点”新增“抗锯齿”;预设/会话/继续上次/导出带参数。
+- 许可:补回 FXAA 的 NVIDIA 2011 声明,保留 SMAA/MLAA MIT 声明与 Magpie GPLv3;`THIRD_PARTY_NOTICES.md` 逐文件记录来源提交、改动与 SHA256;SMAA 查找表 `AreaTex.dds`/`SearchTex.dds` 取自 Magpie 同一提交,随构建复制到 shaders 目录。
+
+## 5. 测试与回归门槛
+
+- **调色逐字节回归(E0 门槛)**:`veyra_effect_slot_regression_tests` 每配置一个进程渲染一帧,输出 8 位结果、FP16 线性输入、对比参考的 SHA-256。配置:列表默认(SR+NR+3 调色)、NR 先行、6 调色、双 NR+保护、节点 SR 前/NR 前/NR 层间/链尾各一组、混合(SR 先行与 NR 先行)、仅 SR 链尾、拆分 NR。在**未改产品代码**的基线上先录制,E0 后逐项对比必须全部相同;基线先自比对两次确认确定性。
+- 单元:`veyra_effect_chain_tests`(链校验与上限、满载拒绝、计划与槽判定、会话/预设往返、旧版拒绝)、预设库/会话/导出协议测试、GpuTimer 掩码测试、UI 契约/翻译检查。
+- 抗锯齿:合成锯齿图(多角度细线、文字/UI)边缘阶梯指标、平坦区几乎不变、HDR 无 NaN/截断/负值丢失;时域实验的重置与拖影;1080p/1440p/4K 各档 GPU 耗时实测。
+- 约束:单测试 ≤300 秒、构建 ≤900 秒、每类配置只测一次、不做压力测试;GPU 计时前确认无他人 Veyra 进程。
+
+## 6. 提交计划
+
+1. `tests:` 切片回归 harness + 本方案 + AGENTS 授权(未改产品代码,用于录制基线)。
+2. `E0:` 效果器扩展基础(回归通过后建 `claude/effects-infra-20261017` 指向它,不再移动;后续修正用 `[E0-fix]` 前缀单独提交并记入 WORKLOG)。
+3. `AA:` 抗锯齿(着色器、AntiAliasPass、图接入、桥接/QML/翻译、预设/会话/导出、许可、测试与报告)。
+
+## 7. 未验证项(预先声明)
+AMD/Intel 实卡、用户 Switch 素材、长时间运行、光学延迟均不在本轮验证范围;本机 RTX 结果不外推其它硬件。
diff --git a/tests/integration/EffectSlotRegressionTests.cpp b/tests/integration/EffectSlotRegressionTests.cpp
new file mode 100644
index 00000000..50655a83
--- /dev/null
+++ b/tests/integration/EffectSlotRegressionTests.cpp
@@ -0,0 +1,257 @@
+// Byte-exact regression for the effect insertion slots.
+//
+// The graph runs colour grades in several places (fused into input conversion,
+// extra list instances, and node-mode slots before SR, before NR, between NR
+// layers and after everything). This executable renders one deterministic
+// frame per configuration through the real EnhanceGraph and prints SHA-256 of
+// the 8-bit output and of the FP16 intermediates. A build from before a change
+// and a build after it must print identical lines; a runner script compares
+// them against a recorded baseline. One case per process keeps the NGX core
+// lifetime out of the comparison.
+//
+// veyra_effect_slot_regression_tests.exe --list
+// veyra_effect_slot_regression_tests.exe --case <name>
+#include "veyra/engine/PreviewGpuSession.h"
+#include "veyra/engine/GraphDescription.h"
+#include "veyra/engine/EffectChain.h"
+#include "veyra/sink/ImageExportSink.h"
+#include "veyra/FileIdentity.h"
+#include "veyra/RuntimePaths.h"
+#include <d3d12sdklayers.h>
+#include <algorithm>
+#include <array>
+#include <cstdint>
+#include <cstdio>
+#include <cstring>
+#include <functional>
+#include <iostream>
+#include <memory>
+#include <optional>
+#include <string>
+#include <string_view>
+#include <vector>
+extern "C" {
+#include <libavutil/frame.h>
+#include <libavutil/pixfmt.h>
+}
+
+namespace {
+using namespace veyra;
+using engine::ChainNode;
+using engine::EffectChain;
+using engine::EffectType;
+
+constexpr unsigned kWidth = 640, kHeight = 360;
+
+// A deterministic picture with smooth ramps, hard edges, thin diagonal lines
+// and mild texture, so every colour variant and the NR model have something to
+// act on.
+bool paint(AVFrame* f) {
+ f->format = AV_PIX_FMT_BGR0;
+ f->width = kWidth;
+ f->height = kHeight;
+ f->color_range = AVCOL_RANGE_UNSPECIFIED;
+ f->color_trc = AVCOL_TRC_IEC61966_2_1;
+ f->colorspace = AVCOL_SPC_RGB;
+ if (av_frame_get_buffer(f, 32) < 0) return false;
+ for (unsigned y = 0; y < kHeight; ++y)
+ for (unsigned x = 0; x < kWidth; ++x) {
+ const float u = float(x) / float(kWidth - 1), v = float(y) / float(kHeight - 1);
+ float r = 50 + 160 * u, g = 40 + 130 * v, b = 130 + 90 * (1 - u) * (0.4f + v);
+ const int dx = int(x) - 170, dy = int(y) - 190;
+ if (dx * dx + dy * dy < 85 * 85) { r = 225; g = 78; b = 52; }
+ if (x > 330 && x < 540 && y > 70 && y < 270) { r = 44; g = 164; b = 214; }
+ if (((x * 3 + y * 2) % 41) < 2) { r = 238; g = 236; b = 228; }
+ if (x > 40 && x < 120 && y > 40 && y < 120) { const bool cell = ((x / 8) + (y / 8)) & 1; r = g = b = cell ? 232 : 24; }
+ uint32_t h = x * 2654435761u ^ (y * 40503u + 0x9E3779B9u);
+ h ^= h >> 13; h *= 0x5bd1e995u; h ^= h >> 15;
+ const int noise = int(h % 7u) - 3;
+ auto q = [&](float c) { return uint8_t(std::clamp(int(c + 0.5f) + noise, 0, 255)); };
+ auto* p = f->data[0] + size_t(y) * f->linesize[0] + size_t(x) * 4;
+ p[0] = q(b); p[1] = q(g); p[2] = q(r); p[3] = 255;
+ }
+ return true;
+}
+
+engine::ColorSettings gradeVariant(int variant) {
+ engine::ColorSettings c;
+ c.enabled = true;
+ switch (variant) {
+ case 0: c.exposure = 0.7f; break;
+ case 1: c.contrast = 45; c.saturation = -20; break;
+ case 2: c.temperature = 35; c.tint = -10; c.vibrance = 30; break;
+ case 3: c.highlights = -40; c.shadows = 30; c.blacks = 10; break;
+ case 4: c.saturation = 55; c.whites = -12; break;
+ default: c.exposure = -0.4f; c.contrast = 18; c.temperature = -22; break;
+ }
+ return c;
+}
+ChainNode colorNode(int variant) {
+ ChainNode n; n.type = EffectType::Color; n.enabled = true; n.color = gradeVariant(variant); return n;
+}
+ChainNode srNode() { ChainNode n; n.type = EffectType::SuperResolution; n.enabled = true; return n; }
+ChainNode nrNode(bool nrFirst) {
+ ChainNode n; n.type = EffectType::NrEnhance; n.enabled = true;
+ n.nr.sizePolicy = pipeline::NrSizePolicy::Realtime; n.nr.temporal = false; n.nr.lowLatencyPairing = nrFirst;
+ return n;
+}
+
+struct Case {
+ std::string name;
+ engine::EnhancementSettings settings;
+ std::optional<engine::ChainRuntimeOrder> order;
+ bool nr = false, sr = false;
+ unsigned expectedNr = 0;
+};
+
+Case nodeCase(std::string name, std::initializer_list<ChainNode> nodes) {
+ Case c; c.name = std::move(name);
+ auto chain = std::make_unique<EffectChain>();
+ chain->mode = engine::ChainMode::Node;
+ for (const auto& n : nodes) {
+ chain->nodes[chain->nodeCount++] = n;
+ c.nr = c.nr || (n.type == EffectType::NrEnhance && n.enabled);
+ c.sr = c.sr || (n.type == EffectType::SuperResolution && n.enabled);
+ if (n.type == EffectType::NrEnhance && n.enabled) ++c.expectedNr;
+ }
+ engine::fromChain(*chain, c.settings);
+ c.settings.multiplier = 1;
+ c.settings.nrMotion = engine::MotionSource::Zero;
+ c.settings.srTarget = pipeline::SrTarget::Qhd;
+ c.order = engine::runtimeOrder(*chain);
+ return c;
+}
+Case listCase(std::string name, bool nr, bool sr, bool nrFirst, unsigned colors, unsigned nrLayers = 1, bool protection = false) {
+ Case c; c.name = std::move(name); c.nr = nr; c.sr = sr; c.expectedNr = nr ? nrLayers : 0;
+ auto& s = c.settings;
+ s.nr = nr; s.sr = sr; s.lowLatency = nrFirst; s.multiplier = 1;
+ s.nrMotion = engine::MotionSource::Zero; s.srTarget = pipeline::SrTarget::Qhd;
+ if (colors > 0) s.color = gradeVariant(0);
+ s.additionalColorCount = colors > 1 ? colors - 1 : 0;
+ for (unsigned i = 0; i + 1 < colors && i < s.additionalColors.size(); ++i) s.additionalColors[i] = gradeVariant(int(i) + 1);
+ if (nr && nrLayers > 1) {
+ s.nrLayerCount = nrLayers;
+ for (unsigned i = 0; i < nrLayers; ++i) {
+ s.nrLayers[i].enabled = true; s.nrLayers[i].lowLatencyPairing = nrFirst;
+ s.nrLayers[i].sizePolicy = pipeline::NrSizePolicy::Realtime;
+ }
+ }
+ if (protection) { s.protection.enabled = true; s.protection.featherPixels = 4; s.protection.regions[0] = {0.1f, 0.1f, 0.45f, 0.5f, false}; }
+ return c;
+}
+
+std::vector<Case> allCases() {
+ std::vector<Case> cases;
+ cases.push_back(listCase("list-default-colors", true, true, false, 3));
+ cases.push_back(listCase("list-nrfirst-colors", true, true, true, 2));
+ cases.push_back(listCase("list-six-colors-sr", false, true, false, 6));
+ cases.push_back(listCase("list-nr2-protection-colors", true, true, false, 2, 2, true));
+ cases.push_back(nodeCase("node-prenr", {srNode(), colorNode(1), nrNode(false)}));
+ cases.push_back(nodeCase("node-presr", {nrNode(true), colorNode(2), srNode()}));
+ cases.push_back(nodeCase("node-internr", {srNode(), nrNode(false), colorNode(3), nrNode(false)}));
+ cases.push_back(nodeCase("node-tail", {srNode(), nrNode(false), colorNode(4)}));
+ cases.push_back(nodeCase("node-tail-sr-only", {srNode(), colorNode(1), colorNode(2)}));
+ cases.push_back(nodeCase("node-mixed-sr-first", {colorNode(0), srNode(), colorNode(1), nrNode(false), colorNode(2), nrNode(false), colorNode(3)}));
+ cases.push_back(nodeCase("node-mixed-nr-first", {colorNode(0), nrNode(true), colorNode(1), nrNode(true), colorNode(2), srNode(), colorNode(3)}));
+ cases.push_back(nodeCase("node-split", {nrNode(true), colorNode(2), srNode(), colorNode(3), nrNode(true), colorNode(4)}));
+ return cases;
+}
+
+// Diagnostic readback of an FP16 RGBA texture (never used by the product).
+bool readRaw(engine::PreviewGpuSession& session, ID3D12Resource* texture, std::vector<uint8_t>& pixels,
+ D3D12_RESOURCE_STATES initial) {
+ if (!texture) return false;
+ const auto desc = texture->GetDesc();
+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{}; UINT64 bytes = 0;
+ session.context.device()->GetCopyableFootprints(&desc, 0, 1, 0, &fp, nullptr, nullptr, &bytes);
+ D3D12_HEAP_PROPERTIES heap{}; heap.Type = D3D12_HEAP_TYPE_READBACK;
+ D3D12_RESOURCE_DESC buffer{}; buffer.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; buffer.Width = bytes;
+ buffer.Height = 1; buffer.DepthOrArraySize = 1; buffer.MipLevels = 1; buffer.SampleDesc.Count = 1;
+ buffer.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
+ Microsoft::WRL::ComPtr<ID3D12Resource> readback;
+ if (FAILED(session.context.device()->CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &buffer,
+ D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&readback)))) return false;
+ Status status; uint32_t slot;
+ auto* list = session.ring.acquireNext(slot, status);
+ if (!list) return false;
+ D3D12_RESOURCE_BARRIER barrier{}; barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+ barrier.Transition = {texture, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, initial, D3D12_RESOURCE_STATE_COPY_SOURCE};
+ list->ResourceBarrier(1, &barrier);
+ D3D12_TEXTURE_COPY_LOCATION src{}, dst{};
+ src.pResource = texture; src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
+ dst.pResource = readback.Get(); dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; dst.PlacedFootprint = fp;
+ list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
+ std::swap(barrier.Transition.StateBefore, barrier.Transition.StateAfter);
+ list->ResourceBarrier(1, &barrier);
+ if (!session.ring.submitAndSignal(slot) || !session.ring.waitIdle()) return false;
+ void* data = nullptr; D3D12_RANGE range{0, SIZE_T(bytes)};
+ if (FAILED(readback->Map(0, &range, &data))) return false;
+ pixels.resize(size_t(desc.Width) * desc.Height * 8);
+ for (unsigned y = 0; y < desc.Height; ++y)
+ std::memcpy(pixels.data() + size_t(y) * desc.Width * 8,
+ static_cast<uint8_t*>(data) + fp.Offset + size_t(y) * fp.Footprint.RowPitch, size_t(desc.Width) * 8);
+ D3D12_RANGE empty{}; readback->Unmap(0, &empty);
+ return true;
+}
+
+int runCase(const Case& test) {
+ HRESULT com = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
+ (void)com;
+ engine::EnhancementSettings settings = test.settings;
+ if (const auto error = settings.validate(); !error.empty()) { std::cout << "CASE_FAIL name=" << test.name << " invalid-settings=" << error << std::endl; return 2; }
+ engine::StageRequest request; request.width = kWidth; request.height = kHeight; request.nr = test.nr; request.sr = test.sr;
+ if (test.order) request.nodeOrder = &*test.order;
+ pipeline::EnhanceGraphDesc desc;
+ engine::describeStages(request, settings, desc);
+ if (!desc.fixedExecutionPlanError.empty()) { std::cout << "CASE_FAIL name=" << test.name << " plan=" << desc.fixedExecutionPlanError << std::endl; return 2; }
+ desc.rgbInput = true; desc.runtimeAbsPath = runtime::localRuntimeDirectory().wstring();
+ engine::PreviewGpuSession session;
+ if (!session.initialize()) { std::cout << "CASE_FAIL name=" << test.name << " device" << std::endl; return 2; }
+ if (!session.graph->initialize(desc) || !session.graph->createViews()) { std::cout << "CASE_FAIL name=" << test.name << " graph-init" << std::endl; return 2; }
+ AVFrame* frame = av_frame_alloc();
+ if (!frame || !paint(frame)) return 2;
+ pipeline::EnhanceGraph::FrameOutputs out;
+ bool ok = session.graph->process(frame, 0.0, true, out, 1) && session.ring.waitIdle();
+ sink::RgbaImage image;
+ std::vector<uint8_t> raw, sourceRef, baseRef;
+ ok = ok && sink::readRgba8(session.context, session.ring, session.graph->videoFrameResource(out.videoSlot), image);
+ ok = ok && readRaw(session, session.graph->diagnosticLinearInput(), raw, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ ok = ok && readRaw(session, session.graph->sourceReference(out.videoSlot), sourceRef, D3D12_RESOURCE_STATE_COMMON);
+ ok = ok && readRaw(session, session.graph->baseReference(out.videoSlot), baseRef, D3D12_RESOURCE_STATE_COMMON);
+ const auto nrEvaluations = session.graph->metrics().nrEvaluateCount;
+ const auto srEvaluations = session.graph->metrics().srEvaluateCount;
+ ok = ok && nrEvaluations == test.expectedNr && (!test.sr || session.graph->srEnabled());
+ if (ok)
+ std::cout << "CASE_RESULT name=" << test.name << " out=" << sha256Hex(image.pixels.data(), image.pixels.size())
+ << " linear=" << sha256Hex(raw.data(), raw.size())
+ << " sourceRef=" << sha256Hex(sourceRef.data(), sourceRef.size())
+ << " baseRef=" << sha256Hex(baseRef.data(), baseRef.size())
+ << " size=" << image.width << 'x' << image.height << " nrEval=" << nrEvaluations << " srEval=" << srEvaluations
+ << " nrBeforeSr=" << desc.nrBeforeSr << " node=" << desc.runtimeNodeOrder << std::endl;
+ else
+ std::cout << "CASE_FAIL name=" << test.name << " process-or-readback nrEval=" << nrEvaluations << std::endl;
+ out = {};
+ session.ring.drainQueue();
+ session.graph->shutdown();
+ av_frame_free(&frame);
+ session.shutdown();
+ return ok ? 0 : 1;
+}
+} // namespace
+
+int wmain(int argc, wchar_t** argv) {
+ const auto cases = allCases();
+ if (argc == 2 && std::wstring_view(argv[1]) == L"--list") {
+ for (const auto& c : cases) std::cout << c.name << '\n';
+ return 0;
+ }
+ if (argc == 3 && std::wstring_view(argv[1]) == L"--case") {
+ const std::wstring wanted = argv[2];
+ for (const auto& c : cases) {
+ if (std::wstring(c.name.begin(), c.name.end()) == wanted) return runCase(c);
+ }
+ std::cout << "unknown case" << std::endl;
+ return 2;
+ }
+ return 2;
+}