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++
phase-2 work: P2.2-P2.5 parity shaders + compare mode + phase2 gate 35/35 (encode 1 code, decode 1 ulp)
Veyra Goal Agent67b0fa08b4c2
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 27fdb1bb..72a55381 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -89,17 +89,22 @@ target_link_libraries(veyra_runtime_probe PRIVATE veyra_gfx)if(VEYRA_ENABLE_EXPERIMENTAL_DLSSNR)veyra_add_compute_shader(veyra_shader_test_pattern GenerateTestPattern)+ veyra_add_compute_shader(veyra_shader_parity_encode ParityEncode)+ veyra_add_compute_shader(veyra_shader_parity_decode ParityDecode)add_executable(veyra_nr_harnesstools/nr_harness/main.cpptools/nr_harness/frame_loop.cpp+ tools/nr_harness/harness_util.cpp+ tools/nr_harness/parity_compare.cpp)veyra_apply_warnings(veyra_nr_harness)target_compile_features(veyra_nr_harness PRIVATE cxx_std_20)target_compile_definitions(veyra_nr_harness PRIVATEUNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAXVEYRA_SHADER_DIR="${CMAKE_BINARY_DIR}/shaders")- target_link_libraries(veyra_nr_harness PRIVATE veyra_gfx veyra_ngx)- add_dependencies(veyra_nr_harness veyra_shader_test_pattern)+ target_link_libraries(veyra_nr_harness PRIVATE veyra_gfx veyra_ngx veyra_parity)+ add_dependencies(veyra_nr_harness veyra_shader_test_pattern+ veyra_shader_parity_encode veyra_shader_parity_decode)endif()# ---------------------------------------------------------------------------diff --git a/loop/BACKLOG.md b/loop/BACKLOG.mdindex 5617537c..f1f43e4b 100644--- a/loop/BACKLOG.md+++ b/loop/BACKLOG.md@@ -31,10 +31,10 @@ Phase 0 gate:以 Playbook 第 16 节 Phase 0 为准。未完成 P0.9 禁止开## Phase 2 — RenoDX-equivalent parity codec(锁定)- [x] P2.1 为 transfer/range/matrix/proxy encode/decode 建 CPU golden tests 和 phase2 gate。(2026-09-02:12/12 双配置 0 failures;gate fail-closed 验证 exit 1;亮度保持误差 0.000000。)-- [ ] P2.2 实现 Original→Parity Encode shader,显式定义输入/输出色域、transfer、range 和资源格式。-- [ ] P2.3 实现 Parity Decode 与 Raw/bypass 对照;记录三个 1.0 中性 codec baseline、来源说明、addon hash 和 capture hash。当前没有 preset;不得加载 addon 取值。-- [ ] P2.4 CPU/GPU golden、identity/bypass、灰阶/色卡/高光测试达到 Playbook 容差。-- [ ] P2.5 完整 Original→Encode→Feature18→Decode capture;不得以主观好看作为 gate。+- [x] P2.2 实现 Original→Parity Encode shader,显式定义输入/输出色域、transfer、range 和资源格式。(2026-09-02:ParityEncode.hlsl,GPU vs CPU ≤1 code。)+- [x] P2.3 实现 Parity Decode 与 Raw/bypass 对照;记录三个 1.0 中性 codec baseline、来源说明、addon hash 和 capture hash。当前没有 preset;不得加载 addon 取值。(2026-09-02:ParityDecode.hlsl;JSON 记录 1.0/1.0/1.0+addon 实测 hash+raw/final hash;addon 从未加载。)+- [x] P2.4 CPU/GPU golden、identity/bypass、灰阶/色卡/高光测试达到 Playbook 容差。(2026-09-02:encode≤1 code、decode≤0.002、CPU 12/12。)+- [x] P2.5 完整 Original→Encode→Feature18→Decode capture;不得以主观好看作为 gate。(2026-09-02:四阶段七文件捕获,raw≠final hash,量化统计非主观。)- [ ] P2.6 gate、只读 Reviewer、P0/P1 修复、checkpoint。## Phase 3 — Minimal video pipeline(锁定)diff --git a/loop/EVIDENCE.md b/loop/EVIDENCE.mdindex 59b07741..12992f9c 100644--- a/loop/EVIDENCE.md+++ b/loop/EVIDENCE.md@@ -2,6 +2,21 @@这里只登记真实存在的门禁证据。格式固定:+## Phase 2 / phase2 / 2026-09-02T23:05:00+08:00++- Commit: 验证内容 checkpoint 待 Reviewer 后登记;gate 运行于 220d6ba+f477948 之后的工作树+- Command: `powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\scripts\loop-gate.ps1 -Gate phase2`+- Exit code: 0(外层 70;内部 phase2.ps1 35/35,run-id 32fb351bb11b49d2b718027bbfdb33f4,5.0s)+- Build configuration: x64-debug + x64-release 均真实构建;CPU 黄金测试双配置 12/12 0 failures;Release parity run 真实执行 16 帧 Evaluate+- Hardware/runtime identity: RTX 5070 / Feature 18 via signed snippet(Init_Ext/Create 0x1);debug run 附带 ID3D12InfoQueue 零错误+- Logs/captures: logs/phase2/32fb351bb11b49d2b718027bbfdb33f4/;captures/phase2/32fb351bb11b49d2b718027bbfdb33f4/(七文件:00_original.rgba16f.bin+json、01_proxy.png、02_raw_dlssnr.png、03_final.rgba16f.bin+preview.png+json)+- Quantitative result: **GPU vs CPU encode maxCodeDelta=1(≤1)**;**GPU vs CPU decode maxAbsError=0.001953125(≤0.002,恰为 FP16 在 4.0 的 1 ulp,期望已先量化 FP16)、nanInf=0**;中性 baseline paperWhiteScale/transferStrength/colorStrength=1.0/1.0/1.0 且 addon SHA-256 实测匹配(addon 从未被加载);rawDlssnr=6EE7EDEE… ≠ final=D2588673…;画面抽验 meanLuma proxy 0.543 / raw 0.546 / final 0.567(无系统性洗白/压黑)+- Reviewer: not run yet(gate 首次通过后立即安排)+- Open P0/P1: none known+- Conclusion: Playbook §16 Phase 2 全部门槛(CPU golden、≤1 code、≤0.002、四阶段真实捕获、中性 baseline+addon hash 记录、raw/final 可区分)机器验证通过++调试记录:5 个缺陷由 debug layer infoQueue 定位——SRV MipLevels=0 触发 RemoveDevice;UAV range 双重偏移越界;NGX 后共享资源 DATA_STATIC bind 冲突(DESCRIPTORS_VOLATILE+前置 barrier);decode 容差含 FP16 量化(期望量化后比较)。CPU 黄金数学零改动。+## Phase 1 / phase1 / 2026-09-02T22:20:00+08:00- Commit: 验证内容 checkpoint 在 Reviewer 通过后登记于 STATE.phases[1].commit;gate 运行时工作树为 a8feb21 + 用户安装 Graphics Tools 的环境变化diff --git a/loop/JOURNAL.md b/loop/JOURNAL.mdindex afbf25f3..93bfed2f 100644--- a/loop/JOURNAL.md+++ b/loop/JOURNAL.md@@ -505,6 +505,31 @@ Result:---+## Cycle 019 — P2.2–P2.5 parity 全链与 phase2 gate++### Before++- Phase: 2+- 唯一任务: 实现 shaders/Parity{Encode,Decode}.hlsl(DXC 构建期编译)+ harness --parity-compare(Original FP16 上传→Encode→16 帧 Evaluate→Decode→Final;GPU/CPU 对比统计;四阶段捕获;中性 baseline/addon hash 记录);跑 phase2 gate 全绿。+- 可证伪假设: GPU/CPU encode 差 >1 code 或 decode 差 >0.002 则 FAIL;debug layer 报错则 FAIL。+- 预计修改文件: shaders/Parity{Encode,Decode}.hlsl、tools/nr_harness/{parity_compare.h,parity_compare.cpp,harness_util.h,harness_util.cpp}、frame_loop.cpp(改用共享 util)、main.cpp、CMakeLists。+- 快速检查命令: `--parity-compare --frames 16` → 0;`loop-gate -Gate phase2` → 0。+- 预期新增证据: maxCodeDelta≤1、maxAbsError≤0.002、四阶段捕获、raw≠final hash。++### After++- 实际命令与 exit code:+ - 调试历程(debug layer + infoQueue 实战立功):①HLSL `linear` 是保留字+向量三目需 select();②SRV desc `Texture2D.MipLevels=0` 非法→debug layer 直接 RemoveDevice(id=31/232);③UAV range `OffsetInDescriptorsFromTableStart=4` 与绑定时 +4 堆偏移双重叠加越过 8 槽堆尾(id=646/1023);④NGX Evaluate 后共享资源状态与 DATA_STATIC bind 校验冲突(id=538/527)→ DESCRIPTORS_VOLATILE + decode 前置 barrier 小提交;⑤decode 差异主成分是 FP16 在 ≥4.0 区间的存储量化(1 ulp=0.0039)→ CPU 期望先量化 FP16 再比较(测得 0.001953125=恰 1 ulp)。+ - Debug --parity-compare → **P2_EXIT=0:encode maxCodeDelta=1、decode maxAbsError=0.001953125、nanInf=0、infoQueue 0 错误、四阶段捕获 written=true、parity: PASS**。+ - `loop-gate -Gate phase2` → **exit 0:35/35 checks**(run-id 32fb351bb11b49d2b718027bbfdb33f4,5.0s)。+- 新证据/日志路径: logs/phase2/32fb351bb11b49d2b718027bbfdb33f4/;captures/phase2/<runId>/ 七文件(00_original.rgba16f.bin 16588800B+json、01_proxy.png、02_raw_dlssnr.png、03_final.rgba16f.bin+preview+json);raw=6EE7EDEE… ≠ final=D2588673…;画面抽验 meanLuma:proxy 0.543→raw 0.546→final 0.567(高光恢复,无洗白/压黑)。+- 失败 fingerprint: 无遗留(5 个缺陷全部由 debug layer 证据定位修复)。+- 是否有进展,依据: 是——Playbook §16 Phase 2 全部门槛机器验证通过。+- STATE/BACKLOG 更新: cycle.completed=19;P2.2–P2.5 → DONE;STATE gate_passed 待 Reviewer。+- 下一唯一动作: P2.6 只读 Reviewer(BASE_COMMIT=1dcf834…)→ PASS 则 checkpoint 解锁 Phase 3。++---+复制下面模板开始每个新 cycle。必须先填 Before,再改代码;完成后填 After。## Cycle NNN — 简短任务名diff --git a/loop/STATE.json b/loop/STATE.jsonindex f7eb97f0..8dd16711 100644--- a/loop/STATE.json+++ b/loop/STATE.json@@ -6,7 +6,7 @@"phase": {"id": 2,"name": "RenoDX-equivalent parity codec",- "state": "not_started",+ "state": "gate_passed","gate": "phase2"},"phases": [@@ -29,8 +29,8 @@{"id": 2,"name": "RenoDX-equivalent parity codec",- "status": "not_started",- "gateEvidence": null,+ "status": "gate_passed",+ "gateEvidence": "loop/EVIDENCE.md#phase-2--phase2--2026-09-02t230500-0800","reviewEvidence": null,"commit": null},@@ -76,19 +76,19 @@}],"cycle": {- "completed": 18,+ "completed": 19,"maximum": 80,"sameFailureAttempts": 0,"maximumSameFailureAttempts": 3,"noProgressCycles": 0,"maximumNoProgressCycles": 5},- "currentTask": "P2.2/P2.3: implement shaders/ParityEncode.hlsl + ParityDecode.hlsl (16x16 groups, out-of-bounds return, Original FP16 -> Proxy RGBA8 -> Final FP16) and the harness --parity-compare mode with four-stage captures, GPU-vs-CPU statistics, and the neutral-baseline/addon-hash record.",+ "currentTask": "P2.6: run the read-only Phase 2 Reviewer (BASE_COMMIT=1dcf834f56986d334a2a6256b196fa1d878ad9b1, phase 1 checkpoint), fix any P0/P1, then checkpoint and unlock Phase 3.","lastGate": {"name": "phase2",- "status": "not_run",- "exitCode": null,- "evidence": null+ "status": "passed",+ "exitCode": 0,+ "evidence": "loop/EVIDENCE.md#phase-2--phase2--2026-09-02t230500-0800"},"lastFailureFingerprint": null,"failureLedger": [],@@ -96,6 +96,6 @@"lastGoodCommit": "1dcf834f56986d334a2a6256b196fa1d878ad9b1","openP0P1Findings": [],"blockers": [],- "nextAction": "Write ParityEncode/ParityDecode shaders + harness --parity-compare (P2.2/P2.3), then P2.4 tolerances and P2.5 captures.",- "updatedAt": "2026-09-02T23:20:00+08:00"+ "nextAction": "Spawn read-only Phase 2 Reviewer; after PASS do checkpoint and unlock Phase 3 (FFmpeg pipeline).",+ "updatedAt": "2026-09-02T23:10:00+08:00"}diff --git a/shaders/ParityDecode.hlsl b/shaders/ParityDecode.hlslnew file mode 100644index 00000000..84a3c0d3--- /dev/null+++ b/shaders/ParityDecode.hlsl@@ -0,0 +1,143 @@+// RenoDX-equivalent parity decode (Playbook section 9.3).+// Reads Original (linear FP16), Proxy and Neural (sRGB-encoded UNORM) and+// reconstructs Final (linear FP16) with luminance restoration, OkLab hue+// correction and the AP1 gamut clamp. Must stay identical to+// src/parity/RenoDxParityCodec.cpp.++cbuffer ParityParams : register(b0)+{+ float4 paritySettings; // x=paperWhiteScale y=transferStrength z=colorStrength w=unused+ uint4 parityDimensions; // x=width y=height+};++Texture2D<float4> originalTex : register(t0);+Texture2D<float4> proxyTex : register(t1);+Texture2D<float4> neuralTex : register(t2);+RWTexture2D<float4> finalTex : register(u0);++float SrgbDecode1(float c)+{+ return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4);+}++float3 SrgbDecode(float3 c)+{+ return float3(SrgbDecode1(c.r), SrgbDecode1(c.g), SrgbDecode1(c.b));+}++float Luminance(float3 rgb)+{+ return dot(rgb, float3(0.212639, 0.715169, 0.072192));+}++float SignedCbrt(float x)+{+ return sign(x) * pow(abs(x), 1.0 / 3.0);+}++float3 Mul3(float3x3 m, float3 v)+{+ return mul(m, v);+}++static const float3x3 kRgbToLms = {+ 0.4122214708, 0.5363325363, 0.0514459929,+ 0.2119034982, 0.6806995451, 0.1073969566,+ 0.0883024619, 0.2817188376, 0.6299787005+};++static const float3x3 kLabFromLmsCbrt = {+ 0.2104542553, 0.7936177850, -0.0040720468,+ 1.9779984951, -2.4285922050, 0.4505937099,+ 0.0259040371, 0.7827717662, -0.8086757660+};++static const float3x3 kLmsFromLabCubed = {+ 1.0, 0.3963377774, 0.2158037573,+ 1.0, -0.1055613458, -0.0638541728,+ 1.0, -0.0894841775, -1.2914855480+};++static const float3x3 kRgbFromLms = {+ 4.0767416621, -3.3077115913, 0.2309699292,+ -1.2684380046, 2.6097574011, -0.3413193965,+ -0.0041960863, -0.7034186147, 1.7076147010+};++static const float3x3 kBt709ToAp1 = {+ 0.613097, 0.339523, 0.047379,+ 0.070194, 0.916354, 0.013452,+ 0.020616, 0.109570, 0.869815+};++static const float3x3 kAp1ToBt709 = {+ 1.705051, -0.621792, -0.083259,+ -0.130256, 1.140805, -0.010548,+ -0.024003, -0.128969, 1.152972+};++float3 ToOkLab(float3 rgb)+{+ float3 lms = Mul3(kRgbToLms, rgb);+ float3 cbrt = float3(SignedCbrt(lms.r), SignedCbrt(lms.g), SignedCbrt(lms.b));+ return Mul3(kLabFromLmsCbrt, cbrt);+}++float3 FromOkLab(float3 lab)+{+ float3 lmsPrime = Mul3(kLmsFromLabCubed, lab);+ float3 lmsCubed = lmsPrime * lmsPrime * lmsPrime;+ return Mul3(kRgbFromLms, lmsCubed);+}++float3 ClampAp1(float3 rgb)+{+ float3 ap1 = Mul3(kBt709ToAp1, rgb);+ return Mul3(kAp1ToBt709, max(ap1, 0.0));+}++float3 HueOkLab(float3 incorrect, float3 correct)+{+ float3 incorrectLab = ToOkLab(incorrect);+ float3 correctLab = ToOkLab(correct);+ float incorrectChroma = length(incorrectLab.gb);+ float correctChroma = length(correctLab.gb);+ incorrectLab.gb = correctLab.gb * (correctChroma == 0.0 ? 1.0 : incorrectChroma / correctChroma);+ return ClampAp1(FromOkLab(incorrectLab));+}++[numthreads(16, 16, 1)]+void main(uint3 dispatchThreadId : SV_DispatchThreadID)+{+ if (dispatchThreadId.x >= parityDimensions.x || dispatchThreadId.y >= parityDimensions.y) {+ return;+ }++ const float4 originalSample = originalTex[dispatchThreadId.xy];+ const float3 original = max(originalSample.rgb, 0.0) / paritySettings.x;+ const float3 proxy = SrgbDecode(proxyTex[dispatchThreadId.xy].rgb);+ const float3 neural = SrgbDecode(neuralTex[dispatchThreadId.xy].rgb);++ const float originalY = Luminance(original);+ const float proxyY = Luminance(proxy);+ const float neuralY = Luminance(neural);++ float ratio;+ if (originalY < proxyY) {+ ratio = originalY / proxyY;+ }+ else {+ const float newY = neuralY + max(0.0, originalY - proxyY);+ ratio = neuralY > 0.0 ? newY / neuralY : 0.0;+ }++ const float3 scaled = HueOkLab(neural * ratio, neural);+ const float3 upgraded = lerp(original, scaled, paritySettings.y);++ const float upgradedY = Luminance(upgraded);+ const float finalRatio = originalY == 0.0 ? 1.0 : upgradedY / originalY;+ const float3 luminanceOnly = original * finalRatio;+ const float3 result = lerp(luminanceOnly, upgraded, paritySettings.z);++ finalTex[dispatchThreadId.xy] = float4(result * paritySettings.x, originalSample.a);+}diff --git a/shaders/ParityEncode.hlsl b/shaders/ParityEncode.hlslnew file mode 100644index 00000000..5397bc3f--- /dev/null+++ b/shaders/ParityEncode.hlsl@@ -0,0 +1,44 @@+// RenoDX-equivalent proxy encode (Playbook section 9.2).+// Original = linear BT.709 working RGB (R16G16B16A16_FLOAT, may exceed 1.0)+// Proxy = sRGB-encoded soft-clipped value in R8G8B8A8_UNORM.+// The math must stay identical to src/parity/RenoDxParityCodec.cpp.++cbuffer ParityParams : register(b0)+{+ float4 paritySettings; // x=paperWhiteScale y=transferStrength z=colorStrength w=unused+ uint4 parityDimensions; // x=width y=height+};++Texture2D<float4> originalTex : register(t0);+RWTexture2D<unorm float4> proxyTex : register(u0);++float SrgbEncode1(float c)+{+ c = max(c, 0.0);+ return c <= 0.0031308 ? 12.92 * c : 1.055 * pow(c, 1.0 / 2.4) - 0.055;+}++float3 SrgbEncode(float3 c)+{+ return float3(SrgbEncode1(c.r), SrgbEncode1(c.g), SrgbEncode1(c.b));+}++float Shoulder(float x)+{+ return 0.75 + 0.25 * (1.0 - exp(-5.7780 * (x - 0.75)));+}++[numthreads(16, 16, 1)]+void main(uint3 dispatchThreadId : SV_DispatchThreadID)+{+ if (dispatchThreadId.x >= parityDimensions.x || dispatchThreadId.y >= parityDimensions.y) {+ return;+ }++ const float4 original = originalTex[dispatchThreadId.xy];+ const float3 linearRgb = max(original.rgb, 0.0) / paritySettings.x;+ // shoulder(x) = 0.75 + 0.25 * (1 - exp(-5.7780 * (x - 0.75))); component-wise.+ const float3 shouldered = 0.75 + 0.25 * (1.0 - exp(-5.7780 * (linearRgb - 0.75)));+ const float3 mapped = select(linearRgb <= 0.75, linearRgb, shouldered);+ proxyTex[dispatchThreadId.xy] = float4(SrgbEncode(mapped), original.a);+}diff --git a/tools/nr_harness/frame_loop.cpp b/tools/nr_harness/frame_loop.cppindex 7bf47d85..489d8d37 100644--- a/tools/nr_harness/frame_loop.cpp+++ b/tools/nr_harness/frame_loop.cpp@@ -24,23 +24,20 @@#include "veyra/ngx/NgxCoreHost.h"#include "veyra/ngx/NgxParameters.h"+#include "harness_util.h"+namespace veyra::harness {namespace {-std::string narrowText(const std::wstring& text)-{- if (text.empty()) {- return {};- }- const int length = WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), nullptr, 0, nullptr, nullptr);- if (length <= 0) {- return {};- }- std::string converted(static_cast<size_t>(length), '\0');- WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), converted.data(), length, nullptr, nullptr);- return converted;-}+using util::RgbaStats;+using util::analyzeRgba;+using util::jsonEscape;+using util::narrowText;+using util::osBuildString;+using util::ownExePath;+using util::writeRgbaPng;+using util::writeTextFileUtf8;std::string scanJsonStringField(const std::string& text, const char* key){@@ -83,225 +80,6 @@ bool loadLocalIdentity(const std::wstring& runtimeDir, LocalIdentity& identity)return !identity.projectId.empty() && !identity.engineVersion.empty();}-// ----------------------------------------------------------------------------// Minimal PNG writer (uncompressed deflate stored blocks): a real PNG any-// viewer opens, without linking a compression library (harness-only).-// ----------------------------------------------------------------------------uint32_t crc32Of(const uint8_t* data, size_t size)-{- static uint32_t table[256];- static bool initialized = false;- if (!initialized) {- for (uint32_t n = 0; n < 256; ++n) {- uint32_t c = n;- for (int k = 0; k < 8; ++k) {- c = (c & 1) != 0 ? 0xEDB88320u ^ (c >> 1) : c >> 1;- }- table[n] = c;- }- initialized = true;- }- uint32_t crc = 0xFFFFFFFFu;- for (size_t i = 0; i < size; ++i) {- crc = table[(crc ^ data[i]) & 0xFF] ^ (crc >> 8);- }- return crc ^ 0xFFFFFFFFu;-}--uint32_t adler32Of(const uint8_t* data, size_t size)-{- uint32_t a = 1;- uint32_t b = 0;- for (size_t i = 0; i < size; ++i) {- a = (a + data[i]) % 65521u;- b = (b + a) % 65521u;- }- return (b << 16) | a;-}--bool writeRgbaPng(const std::wstring& path, const uint8_t* pixels, uint32_t width, uint32_t height, size_t sourceRowPitch)-{- const size_t rowBytes = static_cast<size_t>(width) * 4;- std::vector<uint8_t> raw((rowBytes + 1) * height);- for (uint32_t y = 0; y < height; ++y) {- raw[y * (rowBytes + 1)] = 0; // filter: none- memcpy(raw.data() + y * (rowBytes + 1) + 1, pixels + y * sourceRowPitch, rowBytes);- }-- std::vector<uint8_t> zlibStream;- zlibStream.push_back(0x78);- zlibStream.push_back(0x01);- size_t offset = 0;- while (offset < raw.size()) {- const size_t chunk = std::min<size_t>(raw.size() - offset, 65535);- const bool finalBlock = offset + chunk >= raw.size();- zlibStream.push_back(finalBlock ? 1 : 0);- zlibStream.push_back(static_cast<uint8_t>(chunk & 0xFF));- zlibStream.push_back(static_cast<uint8_t>((chunk >> 8) & 0xFF));- zlibStream.push_back(static_cast<uint8_t>(~chunk & 0xFF));- zlibStream.push_back(static_cast<uint8_t>((~chunk >> 8) & 0xFF));- zlibStream.insert(zlibStream.end(), raw.begin() + static_cast<ptrdiff_t>(offset),- raw.begin() + static_cast<ptrdiff_t>(offset + chunk));- offset += chunk;- }- const uint32_t adler = adler32Of(raw.data(), raw.size());- zlibStream.push_back(static_cast<uint8_t>((adler >> 24) & 0xFF));- zlibStream.push_back(static_cast<uint8_t>((adler >> 16) & 0xFF));- zlibStream.push_back(static_cast<uint8_t>((adler >> 8) & 0xFF));- zlibStream.push_back(static_cast<uint8_t>(adler & 0xFF));-- std::vector<uint8_t> png{ 0x89, 'P', 'N', 'G', '\r', '\n', 0x1A, '\n' };- const auto appendChunk = [&png](const char type[5], const std::vector<uint8_t>& payload) {- const uint32_t length = static_cast<uint32_t>(payload.size());- png.push_back(static_cast<uint8_t>((length >> 24) & 0xFF));- png.push_back(static_cast<uint8_t>((length >> 16) & 0xFF));- png.push_back(static_cast<uint8_t>((length >> 8) & 0xFF));- png.push_back(static_cast<uint8_t>(length & 0xFF));- std::vector<uint8_t> body(type, type + 4);- body.insert(body.end(), payload.begin(), payload.end());- png.insert(png.end(), body.begin(), body.end());- const uint32_t crc = crc32Of(body.data(), body.size());- png.push_back(static_cast<uint8_t>((crc >> 24) & 0xFF));- png.push_back(static_cast<uint8_t>((crc >> 16) & 0xFF));- png.push_back(static_cast<uint8_t>((crc >> 8) & 0xFF));- png.push_back(static_cast<uint8_t>(crc & 0xFF));- };- std::vector<uint8_t> ihdr(13);- ihdr[0] = static_cast<uint8_t>((width >> 24) & 0xFF);- ihdr[1] = static_cast<uint8_t>((width >> 16) & 0xFF);- ihdr[2] = static_cast<uint8_t>((width >> 8) & 0xFF);- ihdr[3] = static_cast<uint8_t>(width & 0xFF);- ihdr[4] = static_cast<uint8_t>((height >> 24) & 0xFF);- ihdr[5] = static_cast<uint8_t>((height >> 16) & 0xFF);- ihdr[6] = static_cast<uint8_t>((height >> 8) & 0xFF);- ihdr[7] = static_cast<uint8_t>(height & 0xFF);- ihdr[8] = 8; // bit depth- ihdr[9] = 6; // RGBA- appendChunk("IHDR", ihdr);- appendChunk("IDAT", zlibStream);- appendChunk("IEND", {});-- HANDLE file = CreateFileW(path.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);- if (file == INVALID_HANDLE_VALUE) {- return false;- }- DWORD written = 0;- const BOOL ok = WriteFile(file, png.data(), static_cast<DWORD>(png.size()), &written, nullptr);- CloseHandle(file);- return ok != FALSE && written == png.size();-}--struct RgbaStats {- double meanLuma = 0.0;- double minLuma = 1.0;- double maxLuma = 0.0;- double stddev = 0.0;- bool allZero = true;- bool constant = true;- std::string sha256;-};--std::string jsonEscape(const std::string& text)-{- std::string escaped;- escaped.reserve(text.size() + 8);- for (const char c : text) {- switch (c) {- case '"': escaped += "\\\""; break;- case '\\': escaped += "\\\\"; break;- case '\n': escaped += "\\n"; break;- case '\r': escaped += "\\r"; break;- case '\t': escaped += "\\t"; break;- default:- if (static_cast<unsigned char>(c) < 0x20) {- escaped += std::format("\\u{:04x}", static_cast<unsigned char>(c));- }- else {- escaped.push_back(c);- }- break;- }- }- return escaped;-}--bool writeTextFileUtf8(const std::wstring& path, const std::string& content)-{- HANDLE file = CreateFileW(path.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);- if (file == INVALID_HANDLE_VALUE) {- return false;- }- DWORD written = 0;- const BOOL ok = WriteFile(file, content.data(), static_cast<DWORD>(content.size()), &written, nullptr);- CloseHandle(file);- return ok != FALSE && written == content.size();-}--std::wstring ownExePath()-{- wchar_t buffer[MAX_PATH * 2]{};- const DWORD length = GetModuleFileNameW(nullptr, buffer, static_cast<DWORD>(std::size(buffer)));- if (length == 0 || length >= std::size(buffer)) {- return {};- }- return std::wstring(buffer, length);-}--std::string osBuildString()-{- const HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");- if (ntdll == nullptr) {- return {};- }- using RtlGetVersionFn = LONG(WINAPI*)(PRTL_OSVERSIONINFOW);- const auto rtlGetVersion = reinterpret_cast<RtlGetVersionFn>(reinterpret_cast<void*>(GetProcAddress(ntdll, "RtlGetVersion")));- if (rtlGetVersion == nullptr) {- return {};- }- RTL_OSVERSIONINFOW info{};- info.dwOSVersionInfoSize = sizeof(info);- if (rtlGetVersion(&info) != 0) {- return {};- }- return std::format("{}.{}.{}", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber);-}--RgbaStats analyzeRgba(const uint8_t* pixels, uint32_t width, uint32_t height, size_t rowPitch)-{- RgbaStats stats;- double sum = 0.0;- double sumSquares = 0.0;- uint64_t count = 0;- for (uint32_t y = 0; y < height; ++y) {- const uint8_t* row = pixels + y * rowPitch;- for (uint32_t x = 0; x < width; ++x) {- const double r = row[x * 4 + 0] / 255.0;- const double g = row[x * 4 + 1] / 255.0;- const double b = row[x * 4 + 2] / 255.0;- const double luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;- sum += luma;- sumSquares += luma * luma;- stats.minLuma = std::min(stats.minLuma, luma);- stats.maxLuma = std::max(stats.maxLuma, luma);- if (row[x * 4] != 0 || row[x * 4 + 1] != 0 || row[x * 4 + 2] != 0) {- stats.allZero = false;- }- ++count;- }- }- const double mean = count > 0 ? sum / static_cast<double>(count) : 0.0;- const double variance = count > 0 ? std::max(0.0, sumSquares / static_cast<double>(count) - mean * mean) : 0.0;- stats.meanLuma = mean;- stats.stddev = std::sqrt(variance);- stats.constant = stats.maxLuma == stats.minLuma;- std::vector<uint8_t> packed(static_cast<size_t>(width) * height * 4);- for (uint32_t y = 0; y < height; ++y) {- memcpy(packed.data() + static_cast<size_t>(y) * width * 4, pixels + y * rowPitch, static_cast<size_t>(width) * 4);- }- stats.sha256 = sha256Hex(packed.data(), packed.size());- return stats;-}-} // namespaceint runFrameLoop(const FrameLoopArgs& args)diff --git a/tools/nr_harness/harness_util.cpp b/tools/nr_harness/harness_util.cppnew file mode 100644index 00000000..ec5b4e9a--- /dev/null+++ b/tools/nr_harness/harness_util.cpp@@ -0,0 +1,238 @@+#include "harness_util.h"++#include <windows.h>++#include <algorithm>+#include <cstring>+#include <format>+#include <fstream>+#include <vector>++#include "veyra/FileIdentity.h"++namespace veyra::harness::util {++std::string narrowText(const std::wstring& text)+{+ if (text.empty()) {+ return {};+ }+ const int length = WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), nullptr, 0, nullptr, nullptr);+ if (length <= 0) {+ return {};+ }+ std::string converted(static_cast<size_t>(length), '\0');+ WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), converted.data(), length, nullptr, nullptr);+ return converted;+}++std::string jsonEscape(const std::string& text)+{+ std::string escaped;+ escaped.reserve(text.size() + 8);+ for (const char c : text) {+ switch (c) {+ case '"': escaped += "\\\""; break;+ case '\\': escaped += "\\\\"; break;+ case '\n': escaped += "\\n"; break;+ case '\r': escaped += "\\r"; break;+ case '\t': escaped += "\\t"; break;+ default:+ if (static_cast<unsigned char>(c) < 0x20) {+ escaped += std::format("\\u{:04x}", static_cast<unsigned char>(c));+ }+ else {+ escaped.push_back(c);+ }+ break;+ }+ }+ return escaped;+}++bool writeTextFileUtf8(const std::wstring& path, const std::string& content)+{+ HANDLE file = CreateFileW(path.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);+ if (file == INVALID_HANDLE_VALUE) {+ return false;+ }+ DWORD written = 0;+ const BOOL ok = WriteFile(file, content.data(), static_cast<DWORD>(content.size()), &written, nullptr);+ CloseHandle(file);+ return ok != FALSE && written == content.size();+}++namespace {++uint32_t crc32Of(const uint8_t* data, size_t size)+{+ static uint32_t table[256];+ static bool initialized = false;+ if (!initialized) {+ for (uint32_t n = 0; n < 256; ++n) {+ uint32_t c = n;+ for (int k = 0; k < 8; ++k) {+ c = (c & 1) != 0 ? 0xEDB88320u ^ (c >> 1) : c >> 1;+ }+ table[n] = c;+ }+ initialized = true;+ }+ uint32_t crc = 0xFFFFFFFFu;+ for (size_t i = 0; i < size; ++i) {+ crc = table[(crc ^ data[i]) & 0xFF] ^ (crc >> 8);+ }+ return crc ^ 0xFFFFFFFFu;+}++uint32_t adler32Of(const uint8_t* data, size_t size)+{+ uint32_t a = 1;+ uint32_t b = 0;+ for (size_t i = 0; i < size; ++i) {+ a = (a + data[i]) % 65521u;+ b = (b + a) % 65521u;+ }+ return (b << 16) | a;+}++} // namespace++bool writeRgbaPng(const std::wstring& path, const uint8_t* pixels, uint32_t width, uint32_t height, size_t sourceRowPitch)+{+ const size_t rowBytes = static_cast<size_t>(width) * 4;+ std::vector<uint8_t> raw((rowBytes + 1) * height);+ for (uint32_t y = 0; y < height; ++y) {+ raw[y * (rowBytes + 1)] = 0; // filter: none+ memcpy(raw.data() + y * (rowBytes + 1) + 1, pixels + y * sourceRowPitch, rowBytes);+ }++ std::vector<uint8_t> zlibStream;+ zlibStream.push_back(0x78);+ zlibStream.push_back(0x01);+ size_t offset = 0;+ while (offset < raw.size()) {+ const size_t chunk = std::min<size_t>(raw.size() - offset, 65535);+ const bool finalBlock = offset + chunk >= raw.size();+ zlibStream.push_back(finalBlock ? 1 : 0);+ zlibStream.push_back(static_cast<uint8_t>(chunk & 0xFF));+ zlibStream.push_back(static_cast<uint8_t>((chunk >> 8) & 0xFF));+ zlibStream.push_back(static_cast<uint8_t>(~chunk & 0xFF));+ zlibStream.push_back(static_cast<uint8_t>((~chunk >> 8) & 0xFF));+ zlibStream.insert(zlibStream.end(), raw.begin() + static_cast<ptrdiff_t>(offset),+ raw.begin() + static_cast<ptrdiff_t>(offset + chunk));+ offset += chunk;+ }+ const uint32_t adler = adler32Of(raw.data(), raw.size());+ zlibStream.push_back(static_cast<uint8_t>((adler >> 24) & 0xFF));+ zlibStream.push_back(static_cast<uint8_t>((adler >> 16) & 0xFF));+ zlibStream.push_back(static_cast<uint8_t>((adler >> 8) & 0xFF));+ zlibStream.push_back(static_cast<uint8_t>(adler & 0xFF));++ std::vector<uint8_t> png{ 0x89, 'P', 'N', 'G', '\r', '\n', 0x1A, '\n' };+ const auto appendChunk = [&png](const char type[5], const std::vector<uint8_t>& payload) {+ const uint32_t length = static_cast<uint32_t>(payload.size());+ png.push_back(static_cast<uint8_t>((length >> 24) & 0xFF));+ png.push_back(static_cast<uint8_t>((length >> 16) & 0xFF));+ png.push_back(static_cast<uint8_t>((length >> 8) & 0xFF));+ png.push_back(static_cast<uint8_t>(length & 0xFF));+ std::vector<uint8_t> body(type, type + 4);+ body.insert(body.end(), payload.begin(), payload.end());+ png.insert(png.end(), body.begin(), body.end());+ const uint32_t crc = crc32Of(body.data(), body.size());+ png.push_back(static_cast<uint8_t>((crc >> 24) & 0xFF));+ png.push_back(static_cast<uint8_t>((crc >> 16) & 0xFF));+ png.push_back(static_cast<uint8_t>((crc >> 8) & 0xFF));+ png.push_back(static_cast<uint8_t>(crc & 0xFF));+ };+ std::vector<uint8_t> ihdr(13);+ ihdr[0] = static_cast<uint8_t>((width >> 24) & 0xFF);+ ihdr[1] = static_cast<uint8_t>((width >> 16) & 0xFF);+ ihdr[2] = static_cast<uint8_t>((width >> 8) & 0xFF);+ ihdr[3] = static_cast<uint8_t>(width & 0xFF);+ ihdr[4] = static_cast<uint8_t>((height >> 24) & 0xFF);+ ihdr[5] = static_cast<uint8_t>((height >> 16) & 0xFF);+ ihdr[6] = static_cast<uint8_t>((height >> 8) & 0xFF);+ ihdr[7] = static_cast<uint8_t>(height & 0xFF);+ ihdr[8] = 8; // bit depth+ ihdr[9] = 6; // RGBA+ appendChunk("IHDR", ihdr);+ appendChunk("IDAT", zlibStream);+ appendChunk("IEND", {});++ HANDLE file = CreateFileW(path.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);+ if (file == INVALID_HANDLE_VALUE) {+ return false;+ }+ DWORD written = 0;+ const BOOL ok = WriteFile(file, png.data(), static_cast<DWORD>(png.size()), &written, nullptr);+ CloseHandle(file);+ return ok != FALSE && written == png.size();+}++std::wstring ownExePath()+{+ wchar_t buffer[MAX_PATH * 2]{};+ const DWORD length = GetModuleFileNameW(nullptr, buffer, static_cast<DWORD>(std::size(buffer)));+ if (length == 0 || length >= std::size(buffer)) {+ return {};+ }+ return std::wstring(buffer, length);+}++std::string osBuildString()+{+ const HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");+ if (ntdll == nullptr) {+ return {};+ }+ using RtlGetVersionFn = LONG(WINAPI*)(PRTL_OSVERSIONINFOW);+ const auto rtlGetVersion = reinterpret_cast<RtlGetVersionFn>(reinterpret_cast<void*>(GetProcAddress(ntdll, "RtlGetVersion")));+ if (rtlGetVersion == nullptr) {+ return {};+ }+ RTL_OSVERSIONINFOW info{};+ info.dwOSVersionInfoSize = sizeof(info);+ if (rtlGetVersion(&info) != 0) {+ return {};+ }+ return std::format("{}.{}.{}", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber);+}++RgbaStats analyzeRgba(const uint8_t* pixels, uint32_t width, uint32_t height, size_t rowPitch)+{+ RgbaStats stats;+ double sum = 0.0;+ double sumSquares = 0.0;+ uint64_t count = 0;+ for (uint32_t y = 0; y < height; ++y) {+ const uint8_t* row = pixels + y * rowPitch;+ for (uint32_t x = 0; x < width; ++x) {+ const double r = row[x * 4 + 0] / 255.0;+ const double g = row[x * 4 + 1] / 255.0;+ const double b = row[x * 4 + 2] / 255.0;+ const double luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;+ sum += luma;+ sumSquares += luma * luma;+ stats.minLuma = std::min(stats.minLuma, luma);+ stats.maxLuma = std::max(stats.maxLuma, luma);+ if (row[x * 4] != 0 || row[x * 4 + 1] != 0 || row[x * 4 + 2] != 0) {+ stats.allZero = false;+ }+ ++count;+ }+ }+ const double mean = count > 0 ? sum / static_cast<double>(count) : 0.0;+ const double variance = count > 0 ? std::max(0.0, sumSquares / static_cast<double>(count) - mean * mean) : 0.0;+ stats.meanLuma = mean;+ stats.stddev = std::sqrt(variance);+ stats.constant = stats.maxLuma == stats.minLuma;+ std::vector<uint8_t> packed(static_cast<size_t>(width) * height * 4);+ for (uint32_t y = 0; y < height; ++y) {+ memcpy(packed.data() + static_cast<size_t>(y) * width * 4, pixels + y * rowPitch, static_cast<size_t>(width) * 4);+ }+ stats.sha256 = sha256Hex(packed.data(), packed.size());+ return stats;+}++} // namespace veyra::harness::utildiff --git a/tools/nr_harness/harness_util.h b/tools/nr_harness/harness_util.hnew file mode 100644index 00000000..3901b0a5--- /dev/null+++ b/tools/nr_harness/harness_util.h@@ -0,0 +1,30 @@+#pragma once++// Shared harness helpers: path/text conversion, JSON escaping, the minimal+// stored-deflate PNG writer, and RGBA statistics.++#include <cstdint>+#include <string>++namespace veyra::harness::util {++std::string narrowText(const std::wstring& text);+std::string jsonEscape(const std::string& text);+bool writeTextFileUtf8(const std::wstring& path, const std::string& content);+bool writeRgbaPng(const std::wstring& path, const uint8_t* pixels, uint32_t width, uint32_t height, size_t sourceRowPitch);+std::wstring ownExePath();+std::string osBuildString();++struct RgbaStats {+ double meanLuma = 0.0;+ double minLuma = 1.0;+ double maxLuma = 0.0;+ double stddev = 0.0;+ bool allZero = true;+ bool constant = true;+ std::string sha256;+};++RgbaStats analyzeRgba(const uint8_t* pixels, uint32_t width, uint32_t height, size_t rowPitch);++} // namespace veyra::harness::utildiff --git a/tools/nr_harness/main.cpp b/tools/nr_harness/main.cppindex 4a41a476..5d6a0ccb 100644--- a/tools/nr_harness/main.cpp+++ b/tools/nr_harness/main.cpp@@ -23,6 +23,7 @@#include "veyra/ngx/NgxParameters.h"#include "frame_loop.h"+#include "parity_compare.h"namespace {@@ -460,6 +461,7 @@ int wmain(int argc, wchar_t** argv)bool shimTest = false;bool createTest = false;bool frameLoop = false;+ bool parityCompare = false;for (int i = 1; i < argc; ++i) {const std::wstring arg = argv[i];if (arg == L"--load-only") {@@ -471,6 +473,9 @@ int wmain(int argc, wchar_t** argv)else if (arg == L"--create-test") {createTest = true;}+ else if (arg == L"--parity-compare") {+ parityCompare = true;+ }else if (arg == L"--frames" && i + 1 < argc) {frames = static_cast<uint32_t>(wcstoul(argv[++i], nullptr, 10));frameLoop = true;@@ -521,6 +526,17 @@ int wmain(int argc, wchar_t** argv)if (shimTest && !runtimeDir.empty()) {exitCode = runShimTest(runtimeDir);}+ else if (parityCompare && !runtimeDir.empty()) {+ veyra::harness::FrameLoopArgs loopArgs{};+ loopArgs.runtimeDir = runtimeDir;+ loopArgs.width = width;+ loopArgs.height = height;+ loopArgs.frames = frames;+ loopArgs.runId = runId;+ loopArgs.jsonFile = jsonFile;+ loopArgs.captureDir = captureDir;+ exitCode = veyra::harness::runParityCompare(loopArgs);+ }else if (createTest && !runtimeDir.empty()) {exitCode = runCreateTest(runtimeDir, width, height);}diff --git a/tools/nr_harness/parity_compare.cpp b/tools/nr_harness/parity_compare.cppnew file mode 100644index 00000000..466de71b--- /dev/null+++ b/tools/nr_harness/parity_compare.cpp@@ -0,0 +1,1040 @@+#include "parity_compare.h"++#include <windows.h>+#include <d3d12.h>+#include <dxgi1_6.h>+#include <nvsdk_ngx.h>++#include <algorithm>+#include <cmath>+#include <cstdint>+#include <cstring>+#include <filesystem>+#include <format>+#include <fstream>+#include <vector>++#include "harness_util.h"+#include "veyra/FileIdentity.h"+#include "veyra/Log.h"+#include "veyra/NgxResult.h"+#include "veyra/Result.h"+#include "veyra/gfx/CommandSlotRing.h"+#include "veyra/gfx/D3D12DeviceContext.h"+#include "veyra/ngx/DlssNrParameters.h"+#include "veyra/ngx/DlssNrRuntimeAdapter.h"+#include "veyra/ngx/NgxCoreHost.h"+#include "veyra/ngx/NgxParameters.h"+#include "veyra/parity/RenoDxParityCodec.h"++namespace veyra::harness {++namespace {++using util::RgbaStats;+using util::analyzeRgba;+using util::jsonEscape;+using util::narrowText;+using util::osBuildString;+using util::ownExePath;+using util::writeRgbaPng;+using util::writeTextFileUtf8;++// float -> half conversion used for BOTH the upload buffer and the CPU+// reference so the comparison runs on identical inputs.+uint16_t floatToHalf(float value)+{+ const uint32_t bits = *reinterpret_cast<const uint32_t*>(&value);+ const uint16_t sign = static_cast<uint16_t>((bits >> 16) & 0x8000);+ const int32_t exponent = static_cast<int32_t>((bits >> 23) & 0xFF) - 127 + 15;+ uint32_t mantissa = bits & 0x007FFFFF;+ if (((bits >> 23) & 0xFF) == 0xFF) {+ return static_cast<uint16_t>(sign | 0x7C00); // Inf/NaN+ }+ if (((bits >> 23) & 0xFF) == 0) {+ return sign; // zero / denormal -> zero (inputs are normal test values)+ }+ if (exponent >= 0x1F) {+ return static_cast<uint16_t>(sign | 0x7BFF); // saturate+ }+ if (exponent <= 0) {+ return sign; // underflow to zero+ }+ return static_cast<uint16_t>(sign | (static_cast<uint32_t>(exponent) << 10) | (mantissa >> 13));+}++float halfToFloat(uint16_t value)+{+ const uint32_t sign = static_cast<uint32_t>(value & 0x8000) << 16;+ const uint32_t exponent = (value >> 10) & 0x1F;+ const uint32_t mantissa = value & 0x3FF;+ if (exponent == 0) {+ return *reinterpret_cast<const float*>(&sign);+ }+ if (exponent == 0x1F) {+ const uint32_t inf = sign | 0x7F800000;+ return *reinterpret_cast<const float*>(&inf);+ }+ const uint32_t result = sign | ((exponent + 112) << 23) | (mantissa << 13);+ return *reinterpret_cast<const float*>(&result);+}++// Deterministic linear test content (Playbook 9.5 scenarios as full-frame+// zones): gray steps incl. 18% gray, gradients with highlights up to 4.0,+// color patches, skin tone and hard edges.+void fillOriginalPixel(uint32_t x, uint32_t y, uint32_t width, uint32_t height, float out[4])+{+ const double u = static_cast<double>(x) / width;+ const double v = static_cast<double>(y) / height;+ if (y < height / 4) {+ // Gray steps incl. 18% gray and shoulder entries 1/2/4.+ const double steps[] = { 0.0, 0.18, 0.5, 0.75, 1.0, 2.0, 4.0, 0.05 };+ const int index = static_cast<int>(u * 8) % 8;+ out[0] = out[1] = out[2] = static_cast<float>(steps[index]);+ }+ else if (y < height / 2) {+ // Gradient with superwhite sweep in red.+ out[0] = static_cast<float>(u * 4.0);+ out[1] = static_cast<float>(0.1 * (1.0 - u));+ out[2] = static_cast<float>(v * 0.2);+ }+ else if (y < 3 * height / 4) {+ // Color patches: primaries + skin tone + checker.+ const int cell = static_cast<int>(u * 8) % 8;+ switch (cell) {+ case 0: out[0] = 1; out[1] = 0; out[2] = 0; break;+ case 1: out[0] = 0; out[1] = 1; out[2] = 0; break;+ case 2: out[0] = 0; out[1] = 0; out[2] = 1; break;+ case 3: out[0] = 0.847f; out[1] = 0.682f; out[2] = 0.552f; break;+ case 4: case 6: out[0] = 0.2f; out[1] = 0.4f; out[2] = 0.6f; break;+ default: out[0] = 0.05f; out[1] = 0.05f; out[2] = 0.05f; break;+ }+ }+ else {+ // Hard edge columns on a mid gray field.+ out[0] = out[1] = out[2] = (x == width / 2 || x == width / 2 + 1) ? 0.9f : 0.3f;+ if (x % 64 == 0) {+ out[0] = 2.0f;+ out[1] = 1.0f;+ out[2] = 0.5f;+ }+ }+ out[3] = 1.0f;+}++struct ParityGpu {+ gfx::ComPtr<ID3D12Resource> original; // R16G16B16A16_FLOAT+ gfx::ComPtr<ID3D12Resource> proxy; // R8G8B8A8_UNORM (UAV)+ gfx::ComPtr<ID3D12Resource> neural; // R8G8B8A8_UNORM (UAV)+ gfx::ComPtr<ID3D12Resource> final; // R16G16B16A16_FLOAT (UAV)+};++bool createParityTextures(const gfx::D3D12DeviceContext& context, uint32_t width, uint32_t height, ParityGpu& out)+{+ const auto makeTexture = [&](DXGI_FORMAT format, D3D12_RESOURCE_FLAGS flags, const wchar_t* name) {+ D3D12_HEAP_PROPERTIES heapProps{};+ heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;+ D3D12_RESOURCE_DESC desc{};+ desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;+ desc.Width = width;+ desc.Height = height;+ desc.DepthOrArraySize = 1;+ desc.MipLevels = 1;+ desc.Format = format;+ desc.SampleDesc.Count = 1;+ desc.Flags = flags;+ gfx::ComPtr<ID3D12Resource> resource;+ if (FAILED(context.device()->CreateCommittedResource(&heapProps, D3D12_HEAP_FLAG_NONE,+ &desc, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&resource)))) {+ log::error("harness", std::format("parity: create texture {} failed", narrowText(name)));+ return gfx::ComPtr<ID3D12Resource>{};+ }+ return resource;+ };+ out.original = makeTexture(DXGI_FORMAT_R16G16B16A16_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"Original");+ out.proxy = makeTexture(DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"Proxy");+ out.neural = makeTexture(DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"Neural");+ out.final = makeTexture(DXGI_FORMAT_R16G16B16A16_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"Final");+ return out.original != nullptr && out.proxy != nullptr && out.neural != nullptr && out.final != nullptr;+}++std::vector<uint8_t> loadShaderBytes(const std::string& name)+{+ const std::string path = std::string(VEYRA_SHADER_DIR "/") + name;+ HANDLE file = CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr,+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);+ if (file == INVALID_HANDLE_VALUE) {+ log::error("harness", std::format("parity: shader missing path={}", path));+ return {};+ }+ LARGE_INTEGER size{};+ GetFileSizeEx(file, &size);+ std::vector<uint8_t> bytes(static_cast<size_t>(size.QuadPart));+ DWORD read = 0;+ ReadFile(file, bytes.data(), static_cast<DWORD>(bytes.size()), &read, nullptr);+ CloseHandle(file);+ return bytes;+}++} // namespace++int runParityCompare(const FrameLoopArgs& args)+{+ const uint32_t width = args.width;+ const uint32_t height = args.height;+ const uint32_t evaluateFrames = std::max<uint32_t>(args.frames, 8);++#if defined(VEYRA_D3D12_DEBUG)+ constexpr bool kDebugLayerByBuild = true;+#else+ constexpr bool kDebugLayerByBuild = false;+#endif+ gfx::D3D12DeviceContext context;+ gfx::DeviceContextDesc contextDesc{};+ contextDesc.enableDebugLayer = kDebugLayerByBuild;+ contextDesc.commandSlotCount = 4;+ Status status = Status::Ok;+ if (!context.initialize(contextDesc, status)) {+ return 6;+ }+ gfx::CommandSlotRing ring;+ if (!ring.initialize(context.device(), context.directQueue(), context.fence(), context.fenceEvent(), 4, status)) {+ context.shutdown();+ return 7;+ }++ // Debug-layer observability (same rationale as the frame loop).+ gfx::ComPtr<ID3D12InfoQueue> parityInfoQueue;+#if defined(VEYRA_D3D12_DEBUG)+ if (SUCCEEDED(context.device()->QueryInterface(IID_PPV_ARGS(&parityInfoQueue)))) {+ parityInfoQueue->SetMuteDebugOutput(false);+ }+#endif+ const auto drainInfoQueue = [&]() {+ if (parityInfoQueue == nullptr) {+ return;+ }+ const uint64_t stored = parityInfoQueue->GetNumStoredMessages();+ uint64_t reported = 0;+ for (uint64_t i = 0; i < stored && reported < 50; ++i) {+ SIZE_T length = 0;+ if (FAILED(parityInfoQueue->GetMessage(i, nullptr, &length)) || length == 0) {+ continue;+ }+ std::vector<uint8_t> buffer(length);+ auto* message = reinterpret_cast<D3D12_MESSAGE*>(buffer.data());+ if (FAILED(parityInfoQueue->GetMessage(i, message, &length))) {+ continue;+ }+ ++reported;+ log::error("harness", std::format("parity infoqueue id={} desc={}",+ static_cast<unsigned>(message->ID), message->pDescription));+ }+ };++ // Local identity + core + snippet (Playbook 8.4 order).+ const std::wstring runtimeDir = args.runtimeDir;+ std::ifstream identityStream(runtimeDir + L"\\..\\config\\ngx-local.json", std::ios::binary);+ std::string identityText((std::istreambuf_iterator<char>(identityStream)), std::istreambuf_iterator<char>());+ const std::string projectId = [&identityText] {+ const std::string needle = "\"ngxProjectId\"";+ size_t position = identityText.find(needle);+ if (position == std::string::npos) return std::string();+ position = identityText.find('"', identityText.find(':', position + needle.size()));+ const size_t start = position + 1;+ const size_t end = identityText.find('"', start);+ return identityText.substr(start, end - start);+ }();+ if (projectId.empty()) {+ ring.shutdown();+ context.shutdown();+ return 7;+ }+ ngx::NgxCoreHost coreHost;+ if (!coreHost.initialize(context.device(), runtimeDir, projectId.c_str(), "Veyra-Experimental-0.1.0", status)) {+ ring.shutdown();+ context.shutdown();+ return 8;+ }+ ngx::DlssNrRuntimeAdapter adapter;+ if (!adapter.load(runtimeDir, status) || !adapter.installCallerCompatibility(status)) {+ adapter.unload();+ coreHost.shutdown();+ ring.shutdown();+ context.shutdown();+ return 9;+ }+ uint64_t result = 0;+ uint32_t sehCode = 0;+ if (!adapter.snippetInitExt(context.device(), runtimeDir, result, sehCode) ||+ result != static_cast<uint64_t>(NVSDK_NGX_Result_Success)) {+ adapter.restoreCallerCompatibility();+ adapter.unload();+ coreHost.shutdown();+ ring.shutdown();+ context.shutdown();+ return 10;+ }++ NVSDK_NGX_Parameter* params = coreHost.allocateParameters(status);+ NVSDK_NGX_Handle* handle = nullptr;+ ParityGpu gpu{};+ if (params == nullptr) {+ goto parity_teardown;+ }+ {+ namespace p = ngx::dlssnr;+ ngx::ParameterBlock pb(params);+ pb.setU32(p::kWidth, width);+ pb.setU32(p::kHeight, height);+ pb.setU32(p::kInputWidth, width);+ pb.setU32(p::kInputHeight, height);+ pb.setU32(p::kOutputWidth, width);+ pb.setU32(p::kOutputHeight, height);+ pb.setU32(p::kOutputDotWidth, width);+ pb.setU32(p::kOutputDotHeight, height);+ pb.setU32(p::kUpscaling, 0);+ pb.setF32(p::kScale, 1.0f);+ pb.setF32(p::kScalingRatio, 1.0f);+ pb.setVoid(p::kComputeScalingRatioCallback,+ reinterpret_cast<void*>(&ngx::DlssNrRuntimeAdapter::scalingRatioCallback));+ pb.setI32(p::kHintRenderPreset, 0);+ pb.setU32(p::kStdWidth, width);+ pb.setU32(p::kStdHeight, height);+ pb.setI32(p::kPerfQualityValue, 1);+ pb.setU32(p::kCreationNodeMask, 1);+ pb.setU32(p::kVisibilityNodeMask, 1);++ ID3D12GraphicsCommandList* list = ring.acquire(0, status);+ if (list == nullptr) {+ goto parity_teardown;+ }+ if (!adapter.snippetCreateFeature(list, params, &handle, result, sehCode) ||+ result != static_cast<uint64_t>(NVSDK_NGX_Result_Success) || handle == nullptr) {+ goto parity_teardown;+ }+ if (!ring.submitAndSignal(0) || !ring.waitIdle()) {+ goto parity_teardown;+ }+ }+ log::info("harness", "parity: [stage] before textures");+ if (!createParityTextures(context, width, height, gpu)) {+ goto parity_teardown;+ }++ {+ // --- Zero guidance textures (R16G16F / R32F) via upload copies.+ const auto makeZero = [&](DXGI_FORMAT format, uint32_t bytesPerPixel) -> gfx::ComPtr<ID3D12Resource> {+ const size_t row = (static_cast<size_t>(width) * bytesPerPixel + 255) & ~size_t(255);+ const size_t sizeBytes = row * height;+ D3D12_HEAP_PROPERTIES uploadProps{};+ uploadProps.Type = D3D12_HEAP_TYPE_UPLOAD;+ D3D12_RESOURCE_DESC uploadDesc{};+ uploadDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;+ uploadDesc.Width = sizeBytes;+ uploadDesc.Height = 1;+ uploadDesc.DepthOrArraySize = 1;+ uploadDesc.MipLevels = 1;+ uploadDesc.SampleDesc.Count = 1;+ uploadDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;+ gfx::ComPtr<ID3D12Resource> upload;+ gfx::ComPtr<ID3D12Resource> texture;+ D3D12_HEAP_PROPERTIES defaultProps{};+ defaultProps.Type = D3D12_HEAP_TYPE_DEFAULT;+ D3D12_RESOURCE_DESC texDesc{};+ texDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;+ texDesc.Width = width;+ texDesc.Height = height;+ texDesc.DepthOrArraySize = 1;+ texDesc.MipLevels = 1;+ texDesc.Format = format;+ texDesc.SampleDesc.Count = 1;+ texDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;+ if (FAILED(context.device()->CreateCommittedResource(&uploadProps, D3D12_HEAP_FLAG_NONE, &uploadDesc,+ D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&upload))) ||+ FAILED(context.device()->CreateCommittedResource(&defaultProps, D3D12_HEAP_FLAG_NONE, &texDesc,+ D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&texture)))) {+ return nullptr;+ }+ void* mapped = nullptr;+ if (FAILED(upload->Map(0, nullptr, &mapped))) {+ return nullptr;+ }+ memset(mapped, 0, sizeBytes);+ upload->Unmap(0, nullptr);++ ID3D12GraphicsCommandList* list = ring.acquire(1, status);+ if (list == nullptr) {+ return nullptr;+ }+ D3D12_RESOURCE_BARRIER b[2]{};+ b[0].Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;+ b[0].Transition.pResource = texture.Get();+ b[0].Transition.StateBefore = D3D12_RESOURCE_STATE_COMMON;+ b[0].Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;+ b[0].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;+ list->ResourceBarrier(1, b);+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint{};+ footprint.Footprint.Format = format;+ footprint.Footprint.Width = width;+ footprint.Footprint.Height = height;+ footprint.Footprint.Depth = 1;+ footprint.Footprint.RowPitch = static_cast<UINT>(row);+ D3D12_TEXTURE_COPY_LOCATION dst{};+ dst.pResource = texture.Get();+ dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;+ dst.SubresourceIndex = 0;+ D3D12_TEXTURE_COPY_LOCATION src{};+ src.pResource = upload.Get();+ src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;+ src.PlacedFootprint = footprint;+ list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);+ b[1].Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;+ b[1].Transition.pResource = texture.Get();+ b[1].Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;+ b[1].Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;+ b[1].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;+ list->ResourceBarrier(1, &b[1]);+ if (!ring.submitAndSignal(1) || !ring.waitIdle()) {+ return nullptr;+ }+ return texture;+ };+ auto motion = makeZero(DXGI_FORMAT_R16G16_FLOAT, 4);+ auto depth = makeZero(DXGI_FORMAT_R32_FLOAT, 4);+ if (motion == nullptr || depth == nullptr) {+ goto parity_teardown;+ }++ // --- Host Original (fp32 -> fp16) + upload to GPU.+ const size_t originalRow = (static_cast<size_t>(width) * 8 + 255) & ~size_t(255);+ const size_t originalBytes = originalRow * height;+ std::vector<uint16_t> originalHalf(static_cast<size_t>(width) * height * 4);+ for (uint32_t y = 0; y < height; ++y) {+ for (uint32_t x = 0; x < width; ++x) {+ float pixel[4]{};+ fillOriginalPixel(x, y, width, height, pixel);+ const size_t index = (static_cast<size_t>(y) * width + x) * 4;+ originalHalf[index + 0] = floatToHalf(pixel[0]);+ originalHalf[index + 1] = floatToHalf(pixel[1]);+ originalHalf[index + 2] = floatToHalf(pixel[2]);+ originalHalf[index + 3] = floatToHalf(pixel[3]);+ }+ }+ {+ D3D12_HEAP_PROPERTIES uploadProps{};+ uploadProps.Type = D3D12_HEAP_TYPE_UPLOAD;+ D3D12_RESOURCE_DESC uploadDesc{};+ uploadDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;+ uploadDesc.Width = originalBytes;+ uploadDesc.Height = 1;+ uploadDesc.DepthOrArraySize = 1;+ uploadDesc.MipLevels = 1;+ uploadDesc.SampleDesc.Count = 1;+ uploadDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;+ gfx::ComPtr<ID3D12Resource> upload;+ if (FAILED(context.device()->CreateCommittedResource(&uploadProps, D3D12_HEAP_FLAG_NONE, &uploadDesc,+ D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&upload)))) {+ goto parity_teardown;+ }+ void* mapped = nullptr;+ if (FAILED(upload->Map(0, nullptr, &mapped))) {+ goto parity_teardown;+ }+ for (uint32_t y = 0; y < height; ++y) {+ memcpy(static_cast<uint8_t*>(mapped) + y * originalRow,+ originalHalf.data() + static_cast<size_t>(y) * width * 4,+ static_cast<size_t>(width) * 8);+ }+ upload->Unmap(0, nullptr);++ ID3D12GraphicsCommandList* list = ring.acquire(0, status);+ if (list == nullptr) {+ goto parity_teardown;+ }+ D3D12_RESOURCE_BARRIER b[2]{};+ b[0].Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;+ b[0].Transition.pResource = gpu.original.Get();+ b[0].Transition.StateBefore = D3D12_RESOURCE_STATE_COMMON;+ b[0].Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;+ b[0].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;+ list->ResourceBarrier(1, b);+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint{};+ footprint.Footprint.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;+ footprint.Footprint.Width = width;+ footprint.Footprint.Height = height;+ footprint.Footprint.Depth = 1;+ footprint.Footprint.RowPitch = static_cast<UINT>(originalRow);+ D3D12_TEXTURE_COPY_LOCATION dst{};+ dst.pResource = gpu.original.Get();+ dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;+ dst.SubresourceIndex = 0;+ D3D12_TEXTURE_COPY_LOCATION src{};+ src.pResource = upload.Get();+ src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;+ src.PlacedFootprint = footprint;+ list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);+ b[1].Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;+ b[1].Transition.pResource = gpu.original.Get();+ b[1].Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;+ b[1].Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;+ b[1].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;+ list->ResourceBarrier(1, &b[1]);+ if (!ring.submitAndSignal(0) || !ring.waitIdle()) {+ goto parity_teardown;+ }+ }++ // --- Descriptor heap + parity pipelines.+ log::info("harness", "parity: [stage] original uploaded");+ D3D12_DESCRIPTOR_HEAP_DESC heapDesc{};+ heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;+ heapDesc.NumDescriptors = 8;+ heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;+ gfx::ComPtr<ID3D12DescriptorHeap> heap;+ if (FAILED(context.device()->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&heap)))) {+ goto parity_teardown;+ }+ log::info("harness", "parity: [stage] heap created");+ const UINT increment = context.device()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);+ D3D12_CPU_DESCRIPTOR_HANDLE cpu = heap->GetCPUDescriptorHandleForHeapStart();+ D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = heap->GetGPUDescriptorHandleForHeapStart();++ D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc{};+ srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;+ srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;+ srvDesc.Texture2D.MostDetailedMip = 0;+ srvDesc.Texture2D.MipLevels = 1; // 0 is invalid; the debug layer removes the device+ srvDesc.Texture2D.PlaneSlice = 0;+ srvDesc.Texture2D.ResourceMinLODClamp = 0.0f;+ srvDesc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;+ context.device()->CreateShaderResourceView(gpu.original.Get(), &srvDesc, cpu);+ srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;+ context.device()->CreateShaderResourceView(gpu.proxy.Get(), &srvDesc, { cpu.ptr + increment });+ context.device()->CreateShaderResourceView(gpu.neural.Get(), &srvDesc, { cpu.ptr + 2ull * increment });++ D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc{};+ uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;+ uavDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;+ context.device()->CreateUnorderedAccessView(gpu.proxy.Get(), nullptr, &uavDesc, { cpu.ptr + 4ull * increment });+ uavDesc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;+ context.device()->CreateUnorderedAccessView(gpu.final.Get(), nullptr, &uavDesc, { cpu.ptr + 5ull * increment });++ D3D12_DESCRIPTOR_RANGE1 ranges[3]{};+ ranges[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;+ ranges[0].NumDescriptors = 3;+ ranges[0].BaseShaderRegister = 0;+ ranges[0].RegisterSpace = 0;+ ranges[0].OffsetInDescriptorsFromTableStart = 0;+ // NGX's EvaluateFeature records its own barriers on shared resources;+ // volatile descriptors keep bind-time state validation honest there.+ ranges[0].Flags = D3D12_DESCRIPTOR_RANGE_FLAG_DESCRIPTORS_VOLATILE;+ ranges[1].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;+ ranges[1].NumDescriptors = 1;+ ranges[1].BaseShaderRegister = 0;+ ranges[1].RegisterSpace = 0;+ // Table base IS the UAV descriptor: bind-time handles already point+ // at heap slot 4 (encode: proxy) or slot 5 (decode: final).+ ranges[1].OffsetInDescriptorsFromTableStart = 0;+ ranges[1].Flags = D3D12_DESCRIPTOR_RANGE_FLAG_DESCRIPTORS_VOLATILE;+ D3D12_ROOT_PARAMETER1 rootParameters[3]{};+ rootParameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;+ rootParameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;+ rootParameters[0].Constants.ShaderRegister = 0;+ rootParameters[0].Constants.RegisterSpace = 0;+ rootParameters[0].Constants.Num32BitValues = 8;+ rootParameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;+ rootParameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;+ rootParameters[1].DescriptorTable.NumDescriptorRanges = 1;+ rootParameters[1].DescriptorTable.pDescriptorRanges = &ranges[0];+ rootParameters[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;+ rootParameters[2].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;+ rootParameters[2].DescriptorTable.NumDescriptorRanges = 1;+ rootParameters[2].DescriptorTable.pDescriptorRanges = &ranges[1];+ D3D12_VERSIONED_ROOT_SIGNATURE_DESC rootDesc{};+ rootDesc.Version = D3D_ROOT_SIGNATURE_VERSION_1_1;+ rootDesc.Desc_1_1.NumParameters = 3;+ rootDesc.Desc_1_1.pParameters = rootParameters;+ gfx::ComPtr<ID3DBlob> signature;+ gfx::ComPtr<ID3DBlob> signatureError;+ const HRESULT serializeResult = D3D12SerializeVersionedRootSignature(&rootDesc, &signature, &signatureError);+ if (FAILED(serializeResult)) {+ log::error("harness", std::format("parity: root signature serialize failed hr={} detail={}",+ hresultString(serializeResult),+ signatureError != nullptr ? std::string(static_cast<const char*>(signatureError->GetBufferPointer())) : std::string("<none>")));+ goto parity_teardown;+ }+ gfx::ComPtr<ID3D12RootSignature> rootSignature;+ const HRESULT rootResult = context.device()->CreateRootSignature(0, signature->GetBufferPointer(),+ signature->GetBufferSize(), IID_PPV_ARGS(&rootSignature));+ if (FAILED(rootResult)) {+ log::error("harness", std::format("parity: CreateRootSignature failed hr={}", hresultString(rootResult)));+ uint32_t removedReason = 0;+ (void)context.checkDeviceAlive(removedReason);+ log::error("harness", std::format("parity: deviceRemovedReason=0x{:08X}", removedReason));+ drainInfoQueue();+ goto parity_teardown;+ }++ log::info("harness", "parity: [stage] root signature created");+ const auto makePso = [&](const char* file) -> gfx::ComPtr<ID3D12PipelineState> {+ const std::vector<uint8_t> bytes = loadShaderBytes(file);+ if (bytes.empty()) {+ return nullptr;+ }+ D3D12_COMPUTE_PIPELINE_STATE_DESC psoDesc{};+ psoDesc.pRootSignature = rootSignature.Get();+ psoDesc.CS.pShaderBytecode = bytes.data();+ psoDesc.CS.BytecodeLength = bytes.size();+ gfx::ComPtr<ID3D12PipelineState> pso;+ if (FAILED(context.device()->CreateComputePipelineState(&psoDesc, IID_PPV_ARGS(&pso)))) {+ log::error("harness", std::format("parity: PSO {} failed", file));+ return nullptr;+ }+ return pso;+ };+ auto encodePso = makePso("ParityEncode.dxil");+ auto decodePso = makePso("ParityDecode.dxil");+ if (encodePso == nullptr || decodePso == nullptr) {+ goto parity_teardown;+ }++ const parity::ParitySettings neutral{};+ const float settingsConstants[8] = {+ static_cast<float>(neutral.paperWhiteScale),+ static_cast<float>(neutral.transferStrength),+ static_cast<float>(neutral.colorStrength),+ 0.0f,+ static_cast<float>(width),+ static_cast<float>(height),+ 0.0f,+ 0.0f+ };+ ID3D12DescriptorHeap* heaps[] = { heap.Get() };++ const auto transition = [](ID3D12GraphicsCommandList* list, ID3D12Resource* resource,+ D3D12_RESOURCE_STATES before, D3D12_RESOURCE_STATES after) {+ D3D12_RESOURCE_BARRIER barrier{};+ barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;+ barrier.Transition.pResource = resource;+ barrier.Transition.StateBefore = before;+ barrier.Transition.StateAfter = after;+ barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;+ list->ResourceBarrier(1, &barrier);+ };++ log::info("harness", "parity: [stage] PSOs created");+ // --- ParityEncode dispatch.+ {+ ID3D12GraphicsCommandList* list = ring.acquire(2, status);+ if (list == nullptr) {+ goto parity_teardown;+ }+ transition(list, gpu.proxy.Get(), D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);+ list->SetDescriptorHeaps(1, heaps);+ list->SetPipelineState(encodePso.Get());+ list->SetComputeRootSignature(rootSignature.Get());+ list->SetComputeRoot32BitConstants(0, 8, settingsConstants, 0);+ list->SetComputeRootDescriptorTable(1, { gpuHandle.ptr }); // SRV: original at offset 0+ list->SetComputeRootDescriptorTable(2, { gpuHandle.ptr + 4ull * increment }); // UAV: proxy at offset 4+ list->Dispatch((width + 15) / 16, (height + 15) / 16, 1);+ transition(list, gpu.proxy.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ transition(list, gpu.neural.Get(), D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);+ if (!ring.submitAndSignal(2) || !ring.waitIdle()) {+ goto parity_teardown;+ }+ }++ // --- Readback staging.+ const size_t rgba8Row = (static_cast<size_t>(width) * 4 + 255) & ~size_t(255);+ const size_t rgba8Bytes = rgba8Row * height;+ D3D12_HEAP_PROPERTIES readbackProps{};+ readbackProps.Type = D3D12_HEAP_TYPE_READBACK;+ D3D12_RESOURCE_DESC readbackDesc{};+ readbackDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;+ readbackDesc.Height = 1;+ readbackDesc.DepthOrArraySize = 1;+ readbackDesc.MipLevels = 1;+ readbackDesc.SampleDesc.Count = 1;+ readbackDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;+ readbackDesc.Width = rgba8Bytes > originalBytes ? rgba8Bytes : originalBytes;+ gfx::ComPtr<ID3D12Resource> readback;+ if (FAILED(context.device()->CreateCommittedResource(&readbackProps, D3D12_HEAP_FLAG_NONE,+ &readbackDesc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&readback)))) {+ goto parity_teardown;+ }++ const auto copyOut = [&](ID3D12Resource* texture, DXGI_FORMAT format,+ size_t rowPitch, D3D12_RESOURCE_STATES before, std::vector<uint8_t>& outBytes) -> bool {+ (void)format; // footprint format documented at call sites+ ID3D12GraphicsCommandList* list = ring.acquire(3, status);+ if (list == nullptr) {+ return false;+ }+ transition(list, texture, before, D3D12_RESOURCE_STATE_COPY_SOURCE);+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint{};+ footprint.Footprint.Format = format;+ footprint.Footprint.Width = width;+ footprint.Footprint.Height = height;+ footprint.Footprint.Depth = 1;+ footprint.Footprint.RowPitch = static_cast<UINT>(rowPitch);+ D3D12_TEXTURE_COPY_LOCATION dst{};+ dst.pResource = readback.Get();+ dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;+ dst.PlacedFootprint = footprint;+ D3D12_TEXTURE_COPY_LOCATION src{};+ src.pResource = texture;+ src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;+ src.SubresourceIndex = 0;+ list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);+ transition(list, texture, D3D12_RESOURCE_STATE_COPY_SOURCE, before);+ if (!ring.submitAndSignal(3) || !ring.waitIdle()) {+ return false;+ }+ void* mapped = nullptr;+ D3D12_RANGE range{ 0, rowPitch * height };+ if (FAILED(readback->Map(0, &range, &mapped))) {+ return false;+ }+ outBytes.assign(static_cast<const uint8_t*>(mapped), static_cast<const uint8_t*>(mapped) + rowPitch * height);+ readback->Unmap(0, nullptr);+ return true;+ };++ std::vector<uint8_t> proxyBytes;+ if (!copyOut(gpu.proxy.Get(), DXGI_FORMAT_R8G8B8A8_UNORM, rgba8Row,+ D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, proxyBytes)) {+ goto parity_teardown;+ }++ // GPU vs CPU encode comparison (Playbook 9.5, <= 1 code value).+ double maxCodeDelta = 0.0;+ for (uint32_t y = 0; y < height; ++y) {+ for (uint32_t x = 0; x < width; ++x) {+ const size_t halfIndex = (static_cast<size_t>(y) * width + x) * 4;+ const parity::RgbF original{+ halfToFloat(originalHalf[halfIndex + 0]),+ halfToFloat(originalHalf[halfIndex + 1]),+ halfToFloat(originalHalf[halfIndex + 2]),+ };+ const parity::Rgba8 expected = parity::encodeProxy(original, 1.0, neutral);+ const uint8_t* row = proxyBytes.data() + y * rgba8Row;+ maxCodeDelta = std::max(maxCodeDelta, std::abs(static_cast<double>(row[x * 4 + 0]) - expected.r));+ maxCodeDelta = std::max(maxCodeDelta, std::abs(static_cast<double>(row[x * 4 + 1]) - expected.g));+ maxCodeDelta = std::max(maxCodeDelta, std::abs(static_cast<double>(row[x * 4 + 2]) - expected.b));+ }+ }+ log::info("harness", std::format("parity: gpu-vs-cpu encode maxCodeDelta={}", maxCodeDelta));++ // --- Feature 18 evaluates on the fixed proxy.+ uint64_t evaluateSucceeded = 0;+ for (uint32_t frame = 0; frame < evaluateFrames; ++frame) {+ ID3D12GraphicsCommandList* list = ring.acquire(frame % 4, status);+ if (list == nullptr) {+ goto parity_teardown;+ }+ namespace p = ngx::dlssnr;+ ngx::ParameterBlock pb(params);+ pb.setD3D12Resource(p::kColor, gpu.proxy.Get());+ pb.setD3D12Resource(p::kOutput, gpu.neural.Get());+ pb.setD3D12Resource(p::kMVec, motion.Get());+ pb.setD3D12Resource(p::kDepth, depth.Get());+ pb.setU32(p::kColorSubrectBaseX, 0);+ pb.setU32(p::kColorSubrectBaseY, 0);+ pb.setU32(p::kColorSubrectWidth, width);+ pb.setU32(p::kColorSubrectHeight, height);+ pb.setU32(p::kOutputSubrectBaseX, 0);+ pb.setU32(p::kOutputSubrectBaseY, 0);+ pb.setU32(p::kOutputSubrectWidth, width);+ pb.setU32(p::kOutputSubrectHeight, height);+ pb.setU32(p::kMVecSubrectBaseX, 0);+ pb.setU32(p::kMVecSubrectBaseY, 0);+ pb.setU32(p::kMVecSubrectWidth, width);+ pb.setU32(p::kMVecSubrectHeight, height);+ pb.setU32(p::kDepthSubrectBaseX, 0);+ pb.setU32(p::kDepthSubrectBaseY, 0);+ pb.setU32(p::kDepthSubrectWidth, width);+ pb.setU32(p::kDepthSubrectHeight, height);+ pb.setF32(p::kMVecScaleX, 1.0f);+ pb.setF32(p::kMVecScaleY, 1.0f);+ pb.setI32(p::kDepthInverted, 1);+ pb.setI32(p::kIndicatorInvertX, 0);+ pb.setI32(p::kIndicatorInvertY, 0);+ pb.setI32(p::kEnabled, 1);+ pb.setI32(p::kReset, frame == 0 ? 1 : 0);+ pb.setI32(p::kStyle, 0);+ pb.setF32(p::kIntensity, 1.0f);+ pb.setF32(p::kLocalToneStrength, 1.0f);+ pb.setF32(p::kLocalStructureStrength, 1.0f);+ pb.setF32(p::kSkinStructureStrength, -1.0f);+ pb.setI32(p::kUseAutoMask, 0);+ pb.setI32(p::kUICorrection, 0);++ uint64_t evalResult = 0;+ uint32_t evalSeh = 0;+ if (!adapter.snippetEvaluateFeature(list, handle, params, evalResult, evalSeh) ||+ evalResult != static_cast<uint64_t>(NVSDK_NGX_Result_Success)) {+ log::error("harness", std::format("parity: Evaluate frame={} failed result={}",+ frame, ngxResultString(evalResult)));+ goto parity_teardown;+ }+ ++evaluateSucceeded;+ D3D12_RESOURCE_BARRIER uavBarrier{};+ uavBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;+ uavBarrier.UAV.pResource = gpu.neural.Get();+ list->ResourceBarrier(1, &uavBarrier);+ if (!ring.submitAndSignal(frame % 4)) {+ goto parity_teardown;+ }+ }+ if (!ring.waitIdle()) {+ goto parity_teardown;+ }++ // --- ParityDecode: pre-pass transitions, then the dispatch list.+ {+ ID3D12GraphicsCommandList* list = ring.acquire(2, status);+ if (list == nullptr) {+ goto parity_teardown;+ }+ transition(list, gpu.neural.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ transition(list, gpu.final.Get(), D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);+ if (!ring.submitAndSignal(2) || !ring.waitIdle()) {+ goto parity_teardown;+ }+ }+ {+ ID3D12GraphicsCommandList* list = ring.acquire(2, status);+ if (list == nullptr) {+ goto parity_teardown;+ }+ list->SetDescriptorHeaps(1, heaps);+ list->SetPipelineState(decodePso.Get());+ list->SetComputeRootSignature(rootSignature.Get());+ list->SetComputeRoot32BitConstants(0, 8, settingsConstants, 0);+ list->SetComputeRootDescriptorTable(1, { gpuHandle.ptr }); // SRVs: original, proxy, neural+ list->SetComputeRootDescriptorTable(2, { gpuHandle.ptr + 5ull * increment }); // UAV: final at offset 5+ list->Dispatch((width + 15) / 16, (height + 15) / 16, 1);+ transition(list, gpu.final.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);+ if (!ring.submitAndSignal(2) || !ring.waitIdle()) {+ goto parity_teardown;+ }+ }++ // --- Readbacks: neural (rgba8) and final (fp16).+ std::vector<uint8_t> neuralBytes;+ std::vector<uint8_t> finalBytes;+ if (!copyOut(gpu.neural.Get(), DXGI_FORMAT_R8G8B8A8_UNORM, rgba8Row,+ D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, neuralBytes)) {+ goto parity_teardown;+ }+ {+ // final currently COPY_SOURCE after the decode transition above.+ ID3D12GraphicsCommandList* list = ring.acquire(3, status);+ if (list != nullptr) {+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint{};+ footprint.Footprint.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;+ footprint.Footprint.Width = width;+ footprint.Footprint.Height = height;+ footprint.Footprint.Depth = 1;+ footprint.Footprint.RowPitch = static_cast<UINT>(originalRow);+ D3D12_TEXTURE_COPY_LOCATION dst{};+ dst.pResource = readback.Get();+ dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;+ dst.PlacedFootprint = footprint;+ D3D12_TEXTURE_COPY_LOCATION src{};+ src.pResource = gpu.final.Get();+ src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;+ src.SubresourceIndex = 0;+ list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);+ transition(list, gpu.final.Get(), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);+ if (ring.submitAndSignal(3) && ring.waitIdle()) {+ void* mapped = nullptr;+ D3D12_RANGE range{ 0, originalRow * height };+ if (SUCCEEDED(readback->Map(0, &range, &mapped))) {+ finalBytes.assign(static_cast<const uint8_t*>(mapped),+ static_cast<const uint8_t*>(mapped) + originalRow * height);+ readback->Unmap(0, nullptr);+ }+ }+ }+ }+ if (neuralBytes.empty() || finalBytes.empty()) {+ goto parity_teardown;+ }++ // --- GPU vs CPU decode comparison (Playbook 9.5, <= 0.002 abs, no NaN/Inf).+ double maxAbsError = 0.0;+ uint64_t nanInfCount = 0;+ for (uint32_t y = 0; y < height; ++y) {+ for (uint32_t x = 0; x < width; ++x) {+ const size_t index = (static_cast<size_t>(y) * width + x) * 4;+ const parity::RgbF original{+ halfToFloat(originalHalf[index + 0]),+ halfToFloat(originalHalf[index + 1]),+ halfToFloat(originalHalf[index + 2]),+ };+ const uint8_t* proxyRow = proxyBytes.data() + y * rgba8Row;+ const uint8_t* neuralRow = neuralBytes.data() + y * rgba8Row;+ const parity::RgbF proxyLinear{+ parity::srgbDecode(proxyRow[x * 4 + 0] / 255.0),+ parity::srgbDecode(proxyRow[x * 4 + 1] / 255.0),+ parity::srgbDecode(proxyRow[x * 4 + 2] / 255.0),+ };+ const parity::RgbF neuralLinear{+ parity::srgbDecode(neuralRow[x * 4 + 0] / 255.0),+ parity::srgbDecode(neuralRow[x * 4 + 1] / 255.0),+ parity::srgbDecode(neuralRow[x * 4 + 2] / 255.0),+ };+ const parity::RgbF expected = parity::parityDecode(original, proxyLinear, neuralLinear, neutral);+ // The Final texture is FP16: quantize the CPU expectation to+ // FP16 first so the tolerance measures shader math error, not+ // storage quantization (1 ulp at [4,8) is 0.0039 by design).+ const float expectedFp16[3] = {+ halfToFloat(floatToHalf(static_cast<float>(expected.r))),+ halfToFloat(floatToHalf(static_cast<float>(expected.g))),+ halfToFloat(floatToHalf(static_cast<float>(expected.b))),+ };+ const uint16_t* finalRow = reinterpret_cast<const uint16_t*>(finalBytes.data() + y * originalRow);+ const float actual[3] = {+ halfToFloat(finalRow[x * 4 + 0]),+ halfToFloat(finalRow[x * 4 + 1]),+ halfToFloat(finalRow[x * 4 + 2]),+ };+ for (int channel = 0; channel < 3; ++channel) {+ if (!std::isfinite(actual[channel])) {+ ++nanInfCount;+ }+ maxAbsError = std::max(maxAbsError, std::abs(static_cast<double>(actual[channel]) -+ expectedFp16[channel]));+ }+ }+ }+ log::info("harness", std::format("parity: gpu-vs-cpu decode maxAbsError={} nanInf={}", maxAbsError, nanInfCount));++ // --- Four-stage captures (Playbook 9.1 / 17.2).+ const std::wstring captureDir = args.captureDir.empty() ? std::wstring(L"captures\\phase2") : args.captureDir;+ std::error_code mkdirError;+ std::filesystem::create_directories(captureDir, mkdirError);+ const bool capturesOk = [&] {+ const std::wstring originalBin = captureDir + L"\\00_original.rgba16f.bin";+ const std::wstring proxyPng = captureDir + L"\\01_proxy.png";+ const std::wstring rawPng = captureDir + L"\\02_raw_dlssnr.png";+ const std::wstring finalBin = captureDir + L"\\03_final.rgba16f.bin";+ const std::wstring previewPng = captureDir + L"\\03_final-preview.png";+ bool ok = writeTextFileUtf8(originalBin,+ std::string(reinterpret_cast<const char*>(originalHalf.data()), originalHalf.size() * 2));+ ok = writeRgbaPng(proxyPng, proxyBytes.data(), width, height, rgba8Row) && ok;+ ok = writeRgbaPng(rawPng, neuralBytes.data(), width, height, rgba8Row) && ok;+ ok = writeTextFileUtf8(finalBin,+ std::string(reinterpret_cast<const char*>(finalBytes.data()), finalBytes.size())) && ok;++ // sRGB preview of the FP16 final (preview only; the .bin is raw).+ std::vector<uint8_t> preview(static_cast<size_t>(width) * height * 4);+ for (uint32_t y = 0; y < height; ++y) {+ const uint16_t* finalRow = reinterpret_cast<const uint16_t*>(finalBytes.data() + y * originalRow);+ for (uint32_t x = 0; x < width; ++x) {+ for (int channel = 0; channel < 3; ++channel) {+ const double linear = halfToFloat(finalRow[x * 4 + channel]);+ const double encoded = parity::srgbEncode(std::min(std::max(linear, 0.0), 1.0));+ preview[(static_cast<size_t>(y) * width + x) * 4 + channel] =+ static_cast<uint8_t>(std::lround(encoded * 255.0));+ }+ preview[(static_cast<size_t>(y) * width + x) * 4 + 3] = 255;+ }+ }+ ok = writeRgbaPng(previewPng, preview.data(), width, height, static_cast<size_t>(width) * 4) && ok;++ const std::string stageJson = std::format(+ "{{\n \"schema\": 1,\n \"width\": {},\n \"height\": {},\n"+ " \"formats\": {{\"original\": \"R16G16B16A16_FLOAT\", \"proxy\": \"R8G8B8A8_UNORM\","+ " \"raw\": \"R8G8B8A8_UNORM\", \"final\": \"R16G16B16A16_FLOAT\"}},\n"+ " \"colorSpace\": \"linear BT.709 working RGB\",\n"+ " \"profile\": {{\"paperWhiteScale\": 1.0, \"transferStrength\": 1.0, \"colorStrength\": 1.0}},\n"+ " \"frameId\": {},\n \"runId\": \"{}\"\n}}\n",+ width, height, evaluateFrames - 1, jsonEscape(narrowText(args.runId)));+ ok = writeTextFileUtf8(captureDir + L"\\00_original.json", stageJson) && ok;+ ok = writeTextFileUtf8(captureDir + L"\\03_final.json", stageJson) && ok;+ return ok;+ }();+ log::info("harness", std::format("parity: four-stage captures written={}", capturesOk));++ const RgbaStats rawStats = analyzeRgba(neuralBytes.data(), width, height, rgba8Row);+ const std::string finalSha = sha256Hex(reinterpret_cast<const uint8_t*>(finalBytes.data()), finalBytes.size());++ // --- Reverse teardown (Playbook 8.8).+ uint64_t releaseResultValue = 0;+ uint32_t releaseSeh = 0;+ const bool releaseOk = adapter.snippetReleaseFeature(handle, releaseResultValue, releaseSeh) &&+ releaseResultValue == static_cast<uint64_t>(NVSDK_NGX_Result_Success);+ coreHost.destroyParameters(params);+ params = nullptr;+ uint64_t snippetShutdownValue = 0;+ uint32_t snippetShutdownSeh = 0;+ (void)adapter.snippetShutdown1(context.device(), snippetShutdownValue, snippetShutdownSeh);+ adapter.restoreCallerCompatibility();+ adapter.unload();+ ring.shutdown();+ coreHost.shutdown();+ context.shutdown();++ const bool allOk = evaluateSucceeded == evaluateFrames && capturesOk &&+ maxCodeDelta <= 1.0 && maxAbsError <= 0.002 && nanInfCount == 0 && releaseOk;++ // --- JSON summary (phase2 gate contract).+ std::string exeSha;+ {+ FileIdentity exeIdentity{};+ IdentityError exeError = IdentityError::None;+ if (computeFileIdentity(ownExePath(), exeIdentity, exeError)) {+ exeSha = exeIdentity.sha256Upper;+ }+ }+ std::string addonSha;+ {+ FileIdentity addonIdentity{};+ IdentityError addonError = IdentityError::None;+ if (computeFileIdentity(L"renodx-dlss5-1.addon64", addonIdentity, addonError)) {+ addonSha = addonIdentity.sha256Upper;+ }+ }+ std::string json;+ json += "{\n";+ json += " \"probe\": \"veyra_nr_harness_parity\",\n";+ json += std::format(" \"runId\": \"{}\",\n", jsonEscape(narrowText(args.runId)));+ json += std::format(" \"exeSha256\": \"{}\",\n", jsonEscape(exeSha));+ json += std::format(" \"osBuild\": \"{}\",\n", jsonEscape(osBuildString()));+ json += std::format(" \"frames\": {},\n", evaluateSucceeded);+ json += std::format(" \"encode\": {{\"maxCodeDelta\": {:.4}}},\n", maxCodeDelta);+ json += std::format(" \"decode\": {{\"maxAbsError\": {:.6}, \"nanInfCount\": {}}},\n", maxAbsError, nanInfCount);+ json += std::format(" \"baseline\": {{\"paperWhiteScale\": 1.0, \"transferStrength\": 1.0, \"colorStrength\": 1.0, \"addonSha256\": \"{}\", \"source\": \"V1 neutral engineering baseline (no ReShade preset exists in this workspace; addon never loaded)\"}},\n",+ jsonEscape(addonSha));+ json += std::format(" \"captureHashes\": {{\"rawDlssnr\": \"{}\", \"final\": \"{}\"}}\n",+ jsonEscape(rawStats.sha256), jsonEscape(finalSha));+ json += "}\n";+ if (!args.jsonFile.empty()) {+ const bool jsonOk = writeTextFileUtf8(args.jsonFile, json);+ log::info("harness", std::format("parity: json written={} path={}", jsonOk, narrowText(args.jsonFile)));+ }++ log::info("harness", allOk ? "parity: PASS" : "parity: FAIL");+ if (!allOk) {+ drainInfoQueue();+ }+ return allOk ? 0 : 12;+ }++parity_teardown:+ if (params != nullptr) {+ coreHost.destroyParameters(params);+ }+ adapter.restoreCallerCompatibility();+ adapter.unload();+ ring.shutdown();+ coreHost.shutdown();+ context.shutdown();+ log::error("harness", "parity: FAIL (setup or execution error)");+ return 11;+}++} // namespace veyra::harnessdiff --git a/tools/nr_harness/parity_compare.h b/tools/nr_harness/parity_compare.hnew file mode 100644index 00000000..fcba21e7--- /dev/null+++ b/tools/nr_harness/parity_compare.h@@ -0,0 +1,16 @@+#pragma once++// Phase 2 parity comparison: Original (linear FP16) -> ParityEncode ->+// Feature 18 Evaluate -> ParityDecode -> Final, with GPU-vs-CPU deltas,+// four-stage captures and the neutral-baseline record (Playbook sections+// 9.1-9.5).+#include <cstdint>+#include <string>++#include "frame_loop.h"++namespace veyra::harness {++int runParityCompare(const FrameLoopArgs& args);++} // namespace veyra::harness