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

feat(engine): describe the processing chain as data

Veyra Goal Agent37101071c653
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7cefad6e..14869720 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -752,7 +752,7 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avform
target_link_libraries(veyra_repair_fg_tests PRIVATE veyra_pipeline veyra_sinks veyra_nvof)
# Headless quality-core runner (Playbook R3.3): the phase5 gate's quality
- add_library(veyra_engine STATIC src/engine/EngineController.cpp src/engine/EngineControllerImage.cpp src/engine/PosterFrame.cpp src/engine/TiledImageProcessor.cpp src/engine/PresetStore.cpp src/engine/VideoPresenter.cpp src/engine/VideoExportJob.cpp src/engine/ExportJobManager.cpp src/engine/Subtitles.cpp src/engine/FgCompatibilityProbe.cpp)
+ add_library(veyra_engine STATIC src/engine/EngineController.cpp src/engine/EngineControllerImage.cpp src/engine/PosterFrame.cpp src/engine/EffectChain.cpp src/engine/TiledImageProcessor.cpp src/engine/PresetStore.cpp src/engine/VideoPresenter.cpp src/engine/VideoExportJob.cpp src/engine/ExportJobManager.cpp src/engine/Subtitles.cpp src/engine/FgCompatibilityProbe.cpp)
target_sources(veyra_pipeline PRIVATE src/guidance/AmdOpticalFlow.cpp
src/guidance/GpuDisOpticalFlow.cpp third_party/gpu-dis/src/gpu/native_strict_dis_provider.cpp)
target_include_directories(veyra_pipeline PRIVATE third_party/gpu-dis/src/gpu)
@@ -771,6 +771,11 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avform
target_compile_options(veyra_engine PRIVATE /utf-8)
target_compile_definitions(veyra_engine PUBLIC VEYRA_PROJECT_ROOT="${CMAKE_CURRENT_SOURCE_DIR}" VEYRA_SHADER_DIR="${CMAKE_BINARY_DIR}/shaders")
target_link_libraries(veyra_engine PUBLIC veyra_pipeline veyra_sources veyra_sinks veyra_ngx veyra_nvof)
+ add_executable(veyra_effect_chain_tests tests/unit/EffectChainTests.cpp src/engine/EffectChain.cpp)
+ target_compile_features(veyra_effect_chain_tests PRIVATE cxx_std_20)
+ target_include_directories(veyra_effect_chain_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
+ target_link_libraries(veyra_effect_chain_tests PRIVATE veyra_base)
+
add_executable(veyra_repair_preset_tests tests/unit/RepairPresetTests.cpp src/engine/PresetStore.cpp)
# CPU bake of the colour grade: no GPU, no engine link - the tables the ingest
# shader reads are pure maths and must be verifiable without a device.
diff --git a/docs/UI_MIGRATION_EXECUTION_2026-09-25.md b/docs/UI_MIGRATION_EXECUTION_2026-09-25.md
index 6d063c8d..bab2ed4a 100644
--- a/docs/UI_MIGRATION_EXECUTION_2026-09-25.md
+++ b/docs/UI_MIGRATION_EXECUTION_2026-09-25.md
@@ -18,6 +18,7 @@
| S0.4 | 性能 / 延迟基线 | 完成 | `checkpoint/ui-mig-s0` | 4 种播放场景 |
| S1.1 | 合并图描述构建 | 完成 | `checkpoint/ui-mig-s1.1` | 6 处合并为 `describeStages()`;13 项哈希一致 |
| S1.7 | 快照补字段(宽高比 / 时长 / 封面) | 完成 | `checkpoint/ui-mig-s1.7` | 宽高比与时长实测正确;关键哈希一致 |
+| S1.2+S1.3 | 效果链模型与效果注册表 | 完成 | `checkpoint/ui-mig-s1.2` | 34 项单元检查全过;引擎尚未改用它 |
## 发现并修复的 bug
@@ -30,6 +31,18 @@
## 日志
+### S1.2 + S1.3(2026-09-25)效果链模型与效果注册表
+- 新增 `include/veyra/engine/EffectChain.h` + `src/engine/EffectChain.cpp`:
+ - `EffectType` 六种(调色、超分辨率、NR、保护区域、RTX Video HDR、补帧),每种在 `effectCatalog()` 里登记名称、实例上限(调色 6、NR 4、其余 1)、是否可重复、是否必须最后、是否改变分辨率、是否实验;
+ - `ChainNode` 每节点带自己的载荷(NR 的参数与运行版本、保护区域、调色、Video HDR),NR 的每层参数独立;
+ - `EffectChain` 固定容量 16 节点 + `nodeCount` + 模式(列表 / 节点)+ 补帧倍率,整体可平凡复制(导出共享内存要求的静态断言仍然成立);
+ - `validateChain()`:数量上限、补帧只能最后、RTX Video HDR 之后只能接补帧;
+ - `toChain()` / `fromChain()`:与 `EnhancementSettings` 双向转换,转换不会碰采集、音频、导出等非阶段字段;
+ - `requiresGraphRebuild()`:把“哪些变化要重建管线”从 `EngineController` 里 25 个字段的手写“或”判断收进一处。
+- 这一步只是把结构立起来,**引擎仍然使用 `EnhancementSettings`**,行为一字未改;`applySettings` 里原本的拒绝规则继续生效。
+- 新增 `veyra_effect_chain_tests`(34 项检查):往返转换保真、禁用阶段保持禁用、非阶段字段不被改动、列表顺序、补帧必须在最后(含“后面只有禁用节点时允许”)、HDR 之后只能接补帧、NR 层数上限、以及重建判断的正反例。
+- 下一步 S1.4 会让引擎改用 `requiresGraphRebuild()`,并先与旧判断并行比对后再切换。
+
### S1.7(2026-09-25)快照补字段
- `SourceInfo` 新增 `displayAspect`(应用容器 SAR 与旋转后的显示宽高比)与 `rotationDegrees`;`FFmpegDemuxer` 增加 `sampleAspect()` / `rotationDegrees()`(读 `sample_aspect_ratio`、`rotate` 元数据和 `AV_PKT_DATA_DISPLAYMATRIX`,用 FFmpeg 6+ 的 `codecpar->coded_side_data` 接口)。
- 四种源都填了这个字段:文件按 SAR+旋转计算;采集卡与屏幕捕获按格式尺寸;PS5 按请求尺寸或实际解码尺寸。原先完全没有宽高比信息,变形宽银幕片源会算错窗口大小。
diff --git a/include/veyra/engine/EffectChain.h b/include/veyra/engine/EffectChain.h
new file mode 100644
index 00000000..1675d522
--- /dev/null
+++ b/include/veyra/engine/EffectChain.h
@@ -0,0 +1,151 @@
+#pragma once
+#include "veyra/engine/ColorSettings.h"
+#include "veyra/engine/EnhancementSettings.h"
+#include "veyra/engine/VideoHdrSettings.h"
+#include <array>
+#include <cstdint>
+#include <string_view>
+
+namespace veyra::engine {
+// The processing chain as data, instead of a fixed set of fields.
+//
+// Why: the UI has to show, reorder (node mode) and stack (NR layers) the
+// stages, and both the preview and the export worker need to carry that
+// description across a process boundary. A fixed-capacity array keeps the
+// structure trivially copyable, which the export shared memory header asserts.
+//
+// The structure is additive for now: EnhancementSettings remains the runtime
+// input, and toChain()/fromChain() convert between the two. Later engine work
+// (multi-NR, ordered executor, node mode) consumes the chain directly.
+inline constexpr uint32_t kMaxChainNodes = 16;
+inline constexpr uint32_t kMaxNrInstances = 4;
+inline constexpr uint32_t kMaxColorInstances = 6;
+
+enum class EffectType : uint8_t {
+ Color = 0, // tone/LUT grade
+ SuperResolution, // DLSS SR / RTX Video SR / AMD FSR
+ NrEnhance, // one NR instance; repeatable
+ Protection, // keeps NR out of chosen rectangles
+ VideoHdr, // SDR -> HDR conversion
+ FrameGeneration, // must be the last node
+ Count
+};
+constexpr uint32_t effectTypeCount = uint32_t(EffectType::Count);
+constexpr std::string_view effectTypeName(EffectType type) {
+ switch (type) {
+ case EffectType::Color: return "color";
+ case EffectType::SuperResolution: return "sr";
+ case EffectType::NrEnhance: return "nr";
+ case EffectType::Protection: return "protection";
+ case EffectType::VideoHdr: return "video-hdr";
+ case EffectType::FrameGeneration: return "frame-generation";
+ case EffectType::Count: break;
+ }
+ return "unknown";
+}
+
+// One NR instance. Every field is per-instance on purpose: stacking only makes
+// sense when each layer can be tuned on its own.
+struct ChainNrParams {
+ NrSettings model{};
+ ResidualSettings residual{};
+ NrRuntime runtime = NrRuntime::Original;
+ bool temporal = false; // motion-reprojected residual stabilization
+ bool lowLatencyPairing = false; // this layer may run before SR (preview only)
+ bool operator==(const ChainNrParams&) const = default;
+};
+
+struct ChainNode {
+ EffectType type = EffectType::NrEnhance;
+ bool enabled = false;
+ uint8_t reserved = 0;
+ // Frame coordinates in node mode; ignored in list mode. Node mode keeps its
+ // own layout, so they never affect the picture.
+ float viewX = 0, viewY = 0;
+ // Per-type payload; only the fields that belong to `type` are meaningful.
+ ChainNrParams nr{};
+ ProtectionSettings protection{};
+ ColorSettings color{};
+ VideoHdrSettings videoHdr{};
+ bool operator==(const ChainNode&) const = default;
+};
+
+enum class ChainMode : uint8_t { List = 0, Node = 1 };
+
+// Description of the whole chain plus the settings that are not stages.
+// Trivially copyable: no pointers, no containers, no std::string.
+struct EffectChain {
+ std::array<ChainNode, kMaxChainNodes> nodes{};
+ uint32_t nodeCount = 0;
+ ChainMode mode = ChainMode::List;
+ // Frame-generation detail: the node says whether it runs, this says how many
+ // frames it produces. Only meaningful when a frame-generation node is on.
+ uint32_t fgMultiplier = 2;
+ // Non-stage settings that still belong to a job description (they were in
+ // EnhancementSettings before and stay there; copied here for completeness).
+ bool fgStrictAdmission = false;
+ bool operator==(const EffectChain&) const = default;
+
+ // Counts nodes of one type, regardless of enabled state.
+ uint32_t countOf(EffectType type) const {
+ uint32_t n = 0;
+ for (uint32_t i = 0; i < nodeCount; ++i) if (nodes[i].type == type) ++n;
+ return n;
+ }
+ const ChainNode* firstOf(EffectType type) const {
+ for (uint32_t i = 0; i < nodeCount; ++i) if (nodes[i].type == type) return &nodes[i];
+ return nullptr;
+ }
+ ChainNode* firstOf(EffectType type) {
+ for (uint32_t i = 0; i < nodeCount; ++i) if (nodes[i].type == type) return &nodes[i];
+ return nullptr;
+ }
+};
+
+// Result of a chain edit. The UI shows `message`; the engine refuses
+// `!accepted` edits instead of silently dropping a stage.
+struct ChainValidation {
+ bool accepted = true;
+ const char* message = "";
+};
+
+// Rules that apply to both editing modes. Node mode can order stages freely,
+// but the physics of the pipeline does not change with the UI.
+ChainValidation validateChain(const EffectChain& chain);
+
+// Converts between the chain description and the settings struct the engine
+// consumes today. `fromChain` keeps every non-stage field of `base`, so a
+// round trip through the chain never loses capture/audio/export settings.
+EffectChain toChain(const EnhancementSettings& settings);
+void fromChain(const EffectChain& chain, EnhancementSettings& settings);
+
+// Rebuild requirement: true when the difference between two settings structs
+// changes the shape of the graph (features, sizes, order, master switches)
+// rather than a live uniform. This is the single rule the controller and the
+// export job use; it replaces the hand-written field list.
+bool requiresGraphRebuild(const EnhancementSettings& previous, const EnhancementSettings& next);
+
+// Effect metadata the UI generates its controls from. Adding an effect means
+// registering it here; no UI code changes.
+struct EffectParameterInfo {
+ const char* id = "";
+ const char* label = "";
+ enum class Kind : uint8_t { Toggle, Slider, Choice, Text } kind = Kind::Toggle;
+ float minimum = 0, maximum = 1, step = 0.01f, defaultValue = 0;
+ uint8_t group = 0; // 0 = common, >0 = collapsible advanced group
+ bool rebuild = false; // changing it needs a graph rebuild, not a live update
+ bool experimental = false;
+};
+struct EffectInfo {
+ EffectType type = EffectType::NrEnhance;
+ std::string_view id;
+ std::string_view label;
+ uint32_t maxInstances = 1;
+ bool repeatable = false;
+ bool mustBeLast = false;
+ bool changesResolution = false;
+ bool experimental = false;
+};
+const EffectInfo& effectInfo(EffectType type);
+const std::array<EffectInfo, effectTypeCount>& effectCatalog();
+}
diff --git a/src/engine/EffectChain.cpp b/src/engine/EffectChain.cpp
new file mode 100644
index 00000000..64bc3a3f
--- /dev/null
+++ b/src/engine/EffectChain.cpp
@@ -0,0 +1,181 @@
+#include "veyra/engine/EffectChain.h"
+
+#include <algorithm>
+
+namespace veyra::engine {
+namespace {
+constexpr std::array<EffectInfo, effectTypeCount> kCatalog{{
+ {EffectType::Color, effectTypeName(EffectType::Color), "调色", kMaxColorInstances, true, false, false, false},
+ {EffectType::SuperResolution, effectTypeName(EffectType::SuperResolution), "超分辨率", 1, false, false, true, false},
+ {EffectType::NrEnhance, effectTypeName(EffectType::NrEnhance), "NR 画面增强", kMaxNrInstances, true, false, false, true},
+ {EffectType::Protection, effectTypeName(EffectType::Protection), "NR 保护区域", 1, false, false, false, false},
+ {EffectType::VideoHdr, effectTypeName(EffectType::VideoHdr), "RTX Video HDR", 1, false, false, false, false},
+ {EffectType::FrameGeneration, effectTypeName(EffectType::FrameGeneration), "补帧", 1, false, true, false, false},
+}};
+} // namespace
+
+const EffectInfo& effectInfo(EffectType type) {
+ const auto index = size_t(type);
+ return kCatalog[index < kCatalog.size() ? index : 0];
+}
+const std::array<EffectInfo, effectTypeCount>& effectCatalog() { return kCatalog; }
+
+ChainValidation validateChain(const EffectChain& chain) {
+ if (chain.nodeCount > kMaxChainNodes) return {false, "链路节点过多"};
+ std::array<uint32_t, effectTypeCount> seen{};
+ uint32_t lastEnabled = kMaxChainNodes; // index of the last enabled node
+ for (uint32_t i = 0; i < chain.nodeCount; ++i) {
+ const auto& node = chain.nodes[i];
+ const auto index = size_t(node.type);
+ if (index >= effectTypeCount) return {false, "未知效果类型"};
+ ++seen[index];
+ if (node.enabled) lastEnabled = i;
+ }
+ for (uint32_t t = 0; t < effectTypeCount; ++t) {
+ const auto& info = kCatalog[t];
+ if (seen[t] > info.maxInstances) return {false, "该效果数量超出上限"};
+ }
+ // Frame generation always runs on the chain's final output: the present
+ // sink owns the swapchain and the OSD/subtitles are composited after it.
+ // The UI refuses to move it, and this is the engine-side guard.
+ for (uint32_t i = 0; i < chain.nodeCount; ++i) {
+ if (chain.nodes[i].type == EffectType::FrameGeneration && chain.nodes[i].enabled &&
+ i != lastEnabled) {
+ return {false, "补帧只能放在链路最后"};
+ }
+ }
+ // Video HDR turns an SDR frame into an HDR one; the stages after it must be
+ // able to consume HDR. Only frame generation is allowed to follow.
+ for (uint32_t i = 0; i < chain.nodeCount; ++i) {
+ if (chain.nodes[i].type != EffectType::VideoHdr || !chain.nodes[i].enabled) continue;
+ for (uint32_t j = i + 1; j < chain.nodeCount; ++j) {
+ const auto type = chain.nodes[j].type;
+ if (!chain.nodes[j].enabled) continue;
+ if (type != EffectType::FrameGeneration) return {false, "RTX Video HDR 之后只能接补帧"};
+ }
+ }
+ return {};
+}
+
+EffectChain toChain(const EnhancementSettings& settings) {
+ EffectChain chain;
+ chain.mode = ChainMode::List;
+ chain.fgStrictAdmission = settings.fgStrictAdmission;
+ chain.fgMultiplier = std::max(2u, settings.multiplier);
+ auto append = [&chain](EffectType type, bool enabled) -> ChainNode& {
+ ChainNode& node = chain.nodes[chain.nodeCount < kMaxChainNodes ? chain.nodeCount : kMaxChainNodes - 1];
+ if (chain.nodeCount < kMaxChainNodes) ++chain.nodeCount;
+ node = ChainNode{};
+ node.type = type;
+ node.enabled = enabled;
+ return node;
+ };
+ // List order is the product order: colour (fused into the ingest shader),
+ // SR, NR layers, protection, Video HDR, frame generation.
+ append(EffectType::Color, settings.color.enabled).color = settings.color;
+ {
+ ChainNode& sr = append(EffectType::SuperResolution, settings.sr);
+ // SR has no payload of its own yet: its inputs live in the settings
+ // fields videoSrQuality / srTarget, which fromChain() fills back.
+ (void)sr;
+ }
+ {
+ ChainNode& nr = append(EffectType::NrEnhance, settings.nr);
+ nr.nr.model = settings.model;
+ nr.nr.residual = settings.residual;
+ nr.nr.runtime = settings.nrRuntime;
+ nr.nr.temporal = settings.nrTemporal;
+ nr.nr.lowLatencyPairing = settings.lowLatency;
+ }
+ append(EffectType::Protection, settings.protection.enabled).protection = settings.protection;
+ append(EffectType::VideoHdr, settings.videoHdr.enabled).videoHdr = settings.videoHdr;
+ append(EffectType::FrameGeneration, settings.multiplier > 1);
+ return chain;
+}
+
+void fromChain(const EffectChain& chain, EnhancementSettings& settings) {
+ // Start from the values the chain does not carry, so callers can pass a
+ // settings struct that already has capture/audio/export fields filled in.
+ settings.color = {};
+ settings.sr = false;
+ settings.nr = false;
+ settings.model = NrSettings{};
+ settings.residual = ResidualSettings{};
+ settings.nrRuntime = NrRuntime::Original;
+ settings.nrTemporal = false;
+ settings.lowLatency = false;
+ settings.protection = ProtectionSettings{};
+ settings.videoHdr = VideoHdrSettings{};
+ settings.multiplier = 1;
+ settings.fgStrictAdmission = chain.fgStrictAdmission;
+ for (uint32_t i = 0; i < chain.nodeCount; ++i) {
+ const auto& node = chain.nodes[i];
+ switch (node.type) {
+ case EffectType::Color:
+ settings.color = node.color;
+ settings.color.enabled = node.enabled;
+ break;
+ case EffectType::SuperResolution:
+ settings.sr = node.enabled;
+ break;
+ case EffectType::NrEnhance:
+ // Only the first NR instance maps back into today's single-NR
+ // settings; extra layers need the multi-instance engine work.
+ if (!settings.nr) {
+ settings.model = node.nr.model;
+ settings.residual = node.nr.residual;
+ settings.nrRuntime = node.nr.runtime;
+ settings.nrTemporal = node.nr.temporal;
+ settings.lowLatency = node.nr.lowLatencyPairing;
+ }
+ settings.nr = settings.nr || node.enabled;
+ break;
+ case EffectType::Protection:
+ settings.protection = node.protection;
+ settings.protection.enabled = node.enabled;
+ break;
+ case EffectType::VideoHdr:
+ settings.videoHdr = node.videoHdr;
+ settings.videoHdr.enabled = node.enabled;
+ break;
+ case EffectType::FrameGeneration:
+ settings.multiplier = node.enabled ? std::max(2u, chain.fgMultiplier) : 1;
+ break;
+ case EffectType::Count:
+ break;
+ }
+ }
+}
+
+bool requiresGraphRebuild(const EnhancementSettings& previous, const EnhancementSettings& next) {
+ // Everything the graph allocates or branches on. Live uniform parameters
+ // (NR model/residual sliders, colour values, protection rectangles, audio,
+ // export bitrate) are deliberately absent: applySettings() handles them.
+ const auto planOf = [](const EnhancementSettings& s) {
+ // The real sizes come from ResolutionPlan, which needs the source
+ // extent; the caller compares those separately. Here we compare the
+ // inputs that decide them.
+ return std::array<uint64_t, 8>{
+ uint64_t(s.sr), uint64_t(s.nr), uint64_t(s.multiplier),
+ uint64_t(s.nrRuntime), uint64_t(s.nrTemporal), uint64_t(s.videoHdr.enabled),
+ uint64_t(s.color.enabled), uint64_t(s.videoSrQuality)};
+ };
+ if (planOf(previous) != planOf(next)) return true;
+ if (previous.lowLatency != next.lowLatency) return true;
+ if (previous.nrPolicy != next.nrPolicy) return true;
+ if (previous.srTarget != next.srTarget) return true;
+ if (previous.frameGenerationBackend != next.frameGenerationBackend) return true;
+ if (previous.opticalFlowBackend != next.opticalFlowBackend) return true;
+ if (previous.amdFlowHalfResolution != next.amdFlowHalfResolution) return true;
+ if (previous.flow != next.flow) return true;
+ if (previous.captureCompatible != next.captureCompatible) return true;
+ if (previous.forceSdrPreview != next.forceSdrPreview) return true;
+ if (previous.color.lutNameString() != next.color.lutNameString()) return true;
+ // The LUT's input space changes which table the colour stage binds.
+ if (previous.color.lutInputSpace != next.color.lutInputSpace) return true;
+ // Deeper chain edits (an extra NR layer, a reordered node) need the engine
+ // work that lands with the ordered executor; until then the chain's shape
+ // is fully determined by the fields above.
+ return false;
+}
+}
diff --git a/tests/unit/EffectChainTests.cpp b/tests/unit/EffectChainTests.cpp
new file mode 100644
index 00000000..6ce8a677
--- /dev/null
+++ b/tests/unit/EffectChainTests.cpp
@@ -0,0 +1,189 @@
+// EffectChain: conversion fidelity and the ordering rules that both editing
+// modes must obey. These are the guards for the multi-NR and node-mode work.
+#include "veyra/engine/EffectChain.h"
+
+#include <cstdio>
+#include <string>
+
+using namespace veyra::engine;
+
+namespace {
+int failures = 0;
+void check(bool ok, const char* label) {
+ std::printf("%s %s\n", ok ? "PASS" : "FAIL", label);
+ if (!ok) ++failures;
+}
+
+EnhancementSettings populated() {
+ EnhancementSettings s;
+ s.revision = 7;
+ s.nr = true; s.sr = true; s.lowLatency = true;
+ s.model = NrSettings{0.8f, 0.7f, 0.6f, 0.2f, 1, 1, 0};
+ s.residual = ResidualSettings{1.4f, 0.8f, 1.1f, 0.9f, 1.2f};
+ s.nrRuntime = NrRuntime::Community;
+ s.nrTemporal = true;
+ s.protection.enabled = true;
+ s.protection.featherPixels = 12;
+ s.protection.regions[1] = {0.1f, 0.2f, 0.3f, 0.4f};
+ s.color.enabled = true;
+ s.color.exposure = 0.25f;
+ s.color.setLutName(L"Kodak.cube");
+ s.videoHdr.enabled = true;
+ s.videoHdr.peakNits = 1200;
+ s.multiplier = 4;
+ s.frameGenerationBackend = FrameGenerationBackend::Dlss;
+ s.videoSrQuality = 3;
+ s.srTarget = veyra::pipeline::SrTarget::Uhd4K;
+ // Fields that are not stages: the chain must not disturb them.
+ s.audioOffsetMs = 40;
+ s.audioSync = AudioSyncMode::Manual;
+ s.captureCompatible = true;
+ s.exportBitrateMbps = 90;
+ s.flow = FlowQuality::Quality;
+ return s;
+}
+} // namespace
+
+int main() {
+ // 1. Round trip through the chain preserves every stage field.
+ {
+ const auto before = populated();
+ auto after = before;
+ fromChain(toChain(before), after);
+ check(after.nr == before.nr && after.sr == before.sr, "round trip keeps the stage switches");
+ check(after.model == before.model, "round trip keeps the NR model parameters");
+ check(after.residual == before.residual, "round trip keeps the residual parameters");
+ check(after.nrRuntime == before.nrRuntime, "round trip keeps the NR runtime");
+ check(after.nrTemporal == before.nrTemporal, "round trip keeps temporal anti-flicker");
+ check(after.lowLatency == before.lowLatency, "round trip keeps the NR-first order");
+ check(after.protection.enabled && after.protection.featherPixels == 12 &&
+ after.protection.regions[1].right == 0.3f && after.protection.regions[1].bottom == 0.4f, "round trip keeps the protection regions");
+ check(after.color.enabled && after.color.lutNameString() == before.color.lutNameString() &&
+ after.color.exposure == before.color.exposure, "round trip keeps the colour grade");
+ check(after.videoHdr.enabled && after.videoHdr.peakNits == 1200, "round trip keeps Video HDR");
+ check(after.multiplier == 4, "round trip keeps the frame-generation multiplier");
+ check(after.videoSrQuality == 3, "round trip keeps the SR quality");
+ // Non-stage fields are the caller's: fromChain must leave them alone.
+ check(after.audioOffsetMs == 40 && after.audioSync == AudioSyncMode::Manual,
+ "round trip does not touch audio settings");
+ check(after.captureCompatible && after.exportBitrateMbps == 90,
+ "round trip does not touch capture or export settings");
+ check(after.flow == FlowQuality::Quality, "round trip does not touch the flow quality");
+ }
+
+ // 2. A disabled stage stays disabled through the round trip.
+ {
+ auto before = populated();
+ before.nr = false; before.sr = false; before.multiplier = 1;
+ before.videoHdr.enabled = false; before.protection.enabled = false;
+ auto after = before;
+ fromChain(toChain(before), after);
+ check(!after.nr && !after.sr && after.multiplier == 1 && !after.videoHdr.enabled &&
+ !after.protection.enabled, "round trip keeps disabled stages disabled");
+ }
+
+ // 3. List order is the product order and NR defaults to exactly one layer.
+ {
+ const auto chain = toChain(populated());
+ check(chain.nodeCount == 6, "list chain has one node per stage");
+ check(chain.nodes[0].type == EffectType::Color &&
+ chain.nodes[1].type == EffectType::SuperResolution &&
+ chain.nodes[2].type == EffectType::NrEnhance &&
+ chain.nodes[3].type == EffectType::Protection &&
+ chain.nodes[4].type == EffectType::VideoHdr &&
+ chain.nodes[5].type == EffectType::FrameGeneration,
+ "list chain is colour, SR, NR, protection, HDR, frame generation");
+ check(chain.countOf(EffectType::NrEnhance) == 1, "list chain has a single NR layer");
+ }
+
+ // 4. Frame generation must be last. This is what stops the UI from moving it.
+ {
+ EffectChain chain;
+ chain.nodeCount = 2;
+ chain.nodes[0] = ChainNode{}; chain.nodes[0].type = EffectType::FrameGeneration; chain.nodes[0].enabled = true;
+ chain.nodes[1] = ChainNode{}; chain.nodes[1].type = EffectType::NrEnhance; chain.nodes[1].enabled = true;
+ const auto verdict = validateChain(chain);
+ check(!verdict.accepted && std::string(verdict.message).find("补帧") != std::string::npos,
+ "frame generation before another enabled stage is rejected");
+
+ EffectChain ok;
+ ok.nodeCount = 2;
+ ok.nodes[0] = ChainNode{}; ok.nodes[0].type = EffectType::NrEnhance; ok.nodes[0].enabled = true;
+ ok.nodes[1] = ChainNode{}; ok.nodes[1].type = EffectType::FrameGeneration; ok.nodes[1].enabled = true;
+ check(validateChain(ok).accepted, "frame generation last is accepted");
+
+ // A disabled trailing node does not push FG out of last place.
+ EffectChain trailing;
+ trailing.nodeCount = 3;
+ trailing.nodes[0] = ChainNode{}; trailing.nodes[0].type = EffectType::NrEnhance; trailing.nodes[0].enabled = true;
+ trailing.nodes[1] = ChainNode{}; trailing.nodes[1].type = EffectType::FrameGeneration; trailing.nodes[1].enabled = true;
+ trailing.nodes[2] = ChainNode{}; trailing.nodes[2].type = EffectType::VideoHdr; trailing.nodes[2].enabled = false;
+ check(validateChain(trailing).accepted, "a disabled node after frame generation is allowed");
+ }
+
+ // 5. Video HDR may only be followed by frame generation.
+ {
+ EffectChain chain;
+ chain.nodeCount = 2;
+ chain.nodes[0] = ChainNode{}; chain.nodes[0].type = EffectType::VideoHdr; chain.nodes[0].enabled = true;
+ chain.nodes[1] = ChainNode{}; chain.nodes[1].type = EffectType::NrEnhance; chain.nodes[1].enabled = true;
+ const auto verdict = validateChain(chain);
+ check(!verdict.accepted && std::string(verdict.message).find("HDR") != std::string::npos,
+ "a stage after Video HDR is rejected");
+
+ EffectChain ok;
+ ok.nodeCount = 3;
+ ok.nodes[0] = ChainNode{}; ok.nodes[0].type = EffectType::VideoHdr; ok.nodes[0].enabled = true;
+ ok.nodes[1] = ChainNode{}; ok.nodes[1].type = EffectType::FrameGeneration; ok.nodes[1].enabled = true;
+ ok.nodes[2] = ChainNode{}; ok.nodes[2].type = EffectType::NrEnhance; ok.nodes[2].enabled = false;
+ check(validateChain(ok).accepted, "a disabled stage after Video HDR is allowed");
+ }
+
+ // 6. Instance limits come from the catalog.
+ {
+ EffectChain chain;
+ chain.nodeCount = kMaxNrInstances + 1;
+ for (uint32_t i = 0; i < chain.nodeCount; ++i) {
+ chain.nodes[i] = ChainNode{};
+ chain.nodes[i].type = EffectType::NrEnhance;
+ chain.nodes[i].enabled = true;
+ }
+ check(!validateChain(chain).accepted, "more NR layers than the catalog allows is rejected");
+ chain.nodeCount = kMaxNrInstances;
+ check(validateChain(chain).accepted, "the NR layer ceiling itself is allowed");
+ check(effectInfo(EffectType::NrEnhance).repeatable &&
+ effectInfo(EffectType::NrEnhance).maxInstances == kMaxNrInstances,
+ "the catalog marks NR as repeatable up to the ceiling");
+ check(effectInfo(EffectType::FrameGeneration).mustBeLast, "the catalog marks frame generation as last");
+ }
+
+ // 7. Rebuild rules: shape changes rebuild, live parameters do not.
+ {
+ const auto base = populated();
+ { auto next = base; next.model.intensity = 0.42f;
+ check(!requiresGraphRebuild(base, next), "an NR slider does not rebuild"); }
+ { auto next = base; next.color.exposure = -0.5f; next.color.saturation = 30;
+ check(!requiresGraphRebuild(base, next), "colour values do not rebuild"); }
+ { auto next = base; next.protection.regions[0] = {0.2f, 0.2f, 0.5f, 0.5f};
+ check(!requiresGraphRebuild(base, next), "protection rectangles do not rebuild"); }
+ { auto next = base; next.audioOffsetMs = -30; next.exportBitrateMbps = 12;
+ check(!requiresGraphRebuild(base, next), "audio and export fields do not rebuild"); }
+ { auto next = base; next.nr = false;
+ check(requiresGraphRebuild(base, next), "turning NR off rebuilds"); }
+ { auto next = base; next.multiplier = 2;
+ check(requiresGraphRebuild(base, next), "changing the multiplier rebuilds"); }
+ { auto next = base; next.nrTemporal = false;
+ check(requiresGraphRebuild(base, next), "toggling temporal anti-flicker rebuilds"); }
+ { auto next = base; next.videoHdr.enabled = false;
+ check(requiresGraphRebuild(base, next), "toggling Video HDR rebuilds"); }
+ { auto next = base; next.lowLatency = false;
+ check(requiresGraphRebuild(base, next), "changing the NR/SR order rebuilds"); }
+ { auto next = base; next.color.setLutName(L"Other.cube");
+ check(requiresGraphRebuild(base, next), "switching the LUT rebuilds"); }
+ { auto next = base; next.nrPolicy = veyra::pipeline::NrSizePolicy::Native;
+ check(requiresGraphRebuild(base, next), "changing the NR size policy rebuilds"); }
+ }
+
+ std::printf(failures ? "effect chain: %d FAILURES\n" : "effect chain: all checks passed\n", failures);
+ return failures ? 1 : 0;
+}