Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.
C++
Fix PS5 H264 hardware slice truncation and frame descriptor reuse
Veyra Goal Agentc68b4b0d3303
diff --git a/.gitattributes b/.gitattributesindex acca1e84..bcf7cf51 100644--- a/.gitattributes+++ b/.gitattributes@@ -1,3 +1,5 @@# Unified dependency patches must remain applicable after a Windows checkout.scripts/remoteplay/patches/*.patch text eol=lf+# A single space is a required empty context line in unified diff syntax.+scripts/ffmpeg/*.patch text eol=lf whitespace=-blank-at-eoldiff --git a/AGENTS.md b/AGENTS.mdindex 7f9f4b2e..b11beb4c 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -1,5 +1,7 @@# Veyra 项目 Agent 执行规则+> 2026-09-13 PS5 H.264 硬解细条修复:本机 FFmpeg n9.0.1 增加 `scripts/ffmpeg/ps5-h264-slices.patch`(32→256 slices),同一真实 PS5 AU 软/硬解已全图比较一致;另修正硬解 SRV 双帧覆盖。后续构建/发布不得无意退回未打补丁的 FFmpeg。对应源码应使用实际 patched tree,并携带 `veyra-local-build.json` 及补丁/重编译说明;原 vcpkg SPDX 仅代表底包。详见 `docs/PS5_HARDWARE_STRIP_REPAIR_2026-09-13.md`。本次只做本地修复,未授权新发布;NVIDIA 运行组件不变。+> 2026-09-12 用户授权合并 PS5 开发版并发布 0.0.5 至 Likely7/Veyra-NRVideo,更新双语 README 和完整便携包。沿用七个已批准增强运行文件,串流开源依赖附对应源码、固定版本、补丁及许可证。SDK、凭据、个人配置、测试媒体不进入源码或便携包。实验功能边界如实说明。> 2026-09-12 用户授权实施 PS5 HDR、PSN 登录与主机保留方案(docs/PS5_HDR_PSN_HOST_PLAN_2026-09-12.md)。仅对本次经过显式HDR输入/输出契约的PS5路径扩展旧SDR限制;文件/采集/导出不得全局放开HDR防错检查。原生HDR旁路显示与“HDR转SDR后增强”必须区分,不能将实验NR的SDR结果冒充原生HDR增强。PSN凭据及主机密钥只在用户数据目录DPAPI加密保存,不提交Git。当前状态按对应施工记录,不由本授权推断测试通过。diff --git a/CMakeLists.txt b/CMakeLists.txtindex 354a96d3..98d0869d 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -573,11 +573,19 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avformtarget_compile_definitions(veyra_popup_selector_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN UNICODE _UNICODE)target_link_libraries(veyra_popup_selector_tests PRIVATE veyra_base comctl32)add_executable(veyra_hdr_color_tests tests/integration/HdrColorTests.cpp)+ add_executable(veyra_hw_import_image_tests tests/integration/HardwareImportImageTests.cpp)+ target_compile_features(veyra_hw_import_image_tests PRIVATE cxx_std_20)+ target_compile_definitions(veyra_hw_import_image_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)+ target_link_libraries(veyra_hw_import_image_tests PRIVATE veyra_engine)target_compile_features(veyra_hdr_color_tests PRIVATE cxx_std_20)target_compile_definitions(veyra_hdr_color_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)target_link_libraries(veyra_hdr_color_tests PRIVATE veyra_engine)add_executable(veyra WIN32 apps/veyra/main.cpp apps/veyra/ui/AppShell.cpp apps/veyra/ui/CapturePanel.cpp apps/veyra/ui/SubtitleOverlay.cpp apps/veyra/SettingsWindow.cpp apps/veyra/TelemetryWindow.cpp)if(VEYRA_ENABLE_REMOTEPLAY)+ add_executable(veyra_ps5_hw_image_tests tests/integration/Ps5HardwareImageTests.cpp)+ target_compile_features(veyra_ps5_hw_image_tests PRIVATE cxx_std_20)+ target_compile_definitions(veyra_ps5_hw_image_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)+ target_link_libraries(veyra_ps5_hw_image_tests PRIVATE veyra_engine)find_package(SDL3 3.4.14 EXACT CONFIG REQUIRED)target_sources(veyra PRIVATE apps/veyra/ui/RemotePlayPanel.cpp src/remoteplay/ControllerInput.cpp)target_link_libraries(veyra PRIVATE SDL3::SDL3)diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.mdindex 3d6e9e03..eb81ebda 100644--- a/THIRD_PARTY_NOTICES.md+++ b/THIRD_PARTY_NOTICES.md@@ -10,6 +10,8 @@ The nvEncodeAPI.h header itself has NVIDIA's permissive MIT-style notice (CopyriFFmpeg: dynamically linked 9.0.1#1 vcpkg build. The portable package carries five FFmpeg DLLs, the complete copyright/license notices and SPDX provenance. Corresponding upstream source and the vcpkg patch/build recipe are listed in `docs/BUILD.md`. No FFmpeg command-line executable or test-media toolchain is shipped.+The PS5 H.264 repair build additionally applies `scripts/ffmpeg/ps5-h264-slices.patch` to FFmpeg's LGPL `libavcodec/h264dec.h`, increasing the bounded slice capacity from 32 to 256. This is a Veyra modification, not an upstream release claim. Its corresponding source, patch, configuration and DLL identity record must accompany any future binary release; the previously published 0.0.5 package is unchanged by this local repair.+## Intel XeSS / XeLLOfficial XeSS SDK 3.0.2. Veyra loads `libxess_fg.dll` and `libxell.dll` for experimental preview frame generation. Unmodified binaries may be redistributed under the Intel Simplified Software License; the complete license and `third-party-programs.txt` accompany the package. User DLL replacement is allowed by Veyra without fixed identity locks; compatibility is not guaranteed.diff --git a/docs/BUILD.md b/docs/BUILD.mdindex d44f3309..b9441136 100644--- a/docs/BUILD.md+++ b/docs/BUILD.md@@ -6,6 +6,7 @@- Windows 11 x64, Visual Studio 2022 C++ tools, Windows SDK, CMake 3.24+, Ninja.- Local FFmpeg development libraries matching avcodec63 / avformat63 / avutil61 / swresample7 / swscale10. Release 0.0.5 uses the vcpkg FFmpeg 9.0.1#1 build (LGPL configuration).+- The subsequent PS5 H.264 repair requires the additional [slice-capacity patch and matching rebuild](../scripts/ffmpeg/README.md). Stock 9.0.1 D3D12 H.264 has a 32-slice limit; the tested PS5 stream uses 68. Preserve `veyra-local-build.json` alongside the original vcpkg provenance when preparing future corresponding-source packages. Existing 0.0.5 assets have not been replaced by this local repair.- NVIDIA DLSS SDK 310.7.0, Optical Flow SDK 5.0.7, RTX Video SDK 1.1.0, and nv-codec-headers. Prepare these under their respective licenses in ignored local directories.- Intel XeSS SDK 3.0.2 for the XeSS presenter; AMD FidelityFX SDK 1.1.4 optical-flow/backend static libraries for the AMD flow option.- Local NR runtime and NGX project configuration for experimental NR. The source repository intentionally does not contain them.diff --git a/docs/PS5_HARDWARE_STRIP_REPAIR_2026-09-13.md b/docs/PS5_HARDWARE_STRIP_REPAIR_2026-09-13.mdnew file mode 100644index 00000000..574247da--- /dev/null+++ b/docs/PS5_HARDWARE_STRIP_REPAIR_2026-09-13.md@@ -0,0 +1,43 @@+# PS5 硬解细条画面修复记录++## 问题与定位++用户报告 PS5 H.264 SDR 硬解只有顶部细条,切换软件解码恢复。基线 83f90ba,施工分支 `codex/ps5-decoded-frame-strip`。本次不发布。++1. 原始日志帧尺寸/图尺寸/显示窗口均完整,不能据“解码成功、60 fps”判断画面正确。+2. 普通 1080p 文件软硬解全图逐像素比较误差 0,实际窗口显示完整;不能代表 PS5 多切片码流通过。+3. 实际已配对 PS5 诊断:硬解资源 1920×1080、NV12、单层、无裁剪、flags=0。硬解帧经 FFmpeg 回读再转色仍为细条;GPU 导入与该回读误差 0。该检查只排除导入改变画面,**不能证明解码正确**。+4. 将同一个真实 PS5 压缩 AU 分别交给产品的软/硬解:软件完整,硬解细条,全图平均通道误差 167.459/255。日志逐条报 32..68 个切片超出 `MAX_SLICES=32`。FFmpeg n9.0.1 的 `d3d12va_h264.c` 直接使用 `h264dec.h` 的 32 长度数组,超限返回 ERANGE;最终收到 AVFrame 仍不能证明所有 slice 被解码。+5. 独立发现硬解 SRV 槽位被下一帧覆盖。两张黑/白图在 GPU gate 后连续排队,旧实现第一张全图 6144 个 RGB 通道错误,单层/三层纹理均复现;按现有两槽 fence 生命周期轮转描述符后错误归零。该修复不是 PS5 多切片问题的替代。++## 修改++- `EnhanceGraph.cpp`:保留软件上传 SRV 槽 0/1;硬解使用 3/4、5/6 两组,与已有 `uploadFences_`/`hardwareInputFrames_` 同生命周期;通过既有 CPU descriptor staging 写入,不新增逐帧等待或 GPU→CPU 回读。+- `RemotePlaySource.cpp`:首张真实硬解输出记录可见尺寸、资源尺寸/格式、层数、slice、crop 和 fence,不记录凭据。+- `scripts/ffmpeg/ps5-h264-slices.patch`:H.264 `MAX_SLICES` 从 32 扩为 256(保持内部按位环索引所需的二次幂)。仅修改外置开源 FFmpeg 源码并重编译,不修改 NVIDIA 二进制。新构建必须沿用原 DLL 编译配置。+- 新诊断 `HardwareImportImageTests` / `HardwareImportFixtures` 检查全图及两帧并发 SRV;`Ps5HardwareImageTests --last-paired-ps5 <输出前缀>` 显式使用最后一个本机 DPAPI 配对,只做短时连接和同码流软硬解图像比较。不会改配对或让主机休眠。诊断图和日志只在忽略目录。++## 已执行证据++- `cmd /c out\remoteplay\build-hw-import.cmd`,普通软/硬解四帧全图误差 0。初次测试程序缺 AVFrame include 编译失败,补齐后成功。+- `veyra_hw_import_image_tests.exe logs/ps5-p1-1080p30-long.mp4 logs/hw-import-after`:4 帧误差 0,单层/三层两帧排队均错误通道 0,退出 0。旧代码的失败保留于 `logs/hw-import-fixture-before.log`。+- `cmd /c out\remoteplay\build-ps5-image.cmd`:初次缺完整设备/命令环类型 include 失败,补齐成功。+- 实际 PS5:`logs/ps5-live-import.log` 为 GPU 导入/回读一致但画面错误;`logs/ps5-live-decode.log` 为同码流软件正确/硬解错误,诊断退出 12。**这两项不记为 PS5 修复通过。**+- FFmpeg 独立源码 `C:\veyra-deps\ffmpeg-ps5-slices-source`,构建 `C:\veyra-deps\ffmpeg-ps5-slices-build`,安装目标 `C:\veyra-deps\ffmpeg-ps5-slices-installed`。原始 vcpkg 源码/构建不覆盖。原 DLL 配置见 `logs/ps5-ffmpeg-original-configuration.txt`。+- FFmpeg 首次 configure 因 MSYS link.exe 抢先于 MSVC link.exe 失败(`logs/ps5-ffmpeg-build.log`)。修正 PATH 后重试,结果待追加。++## 最终验证与交付++- 外置 FFmpeg `configure + make -j8 + make install` 成功,`logs/ps5-ffmpeg-build-retry.log`。功能选项取自原 DLL(LGPL、无额外编解码库),仅安装/归档工具路径改变。没有覆盖原 vcpkg 构建树。+- 同码流实机复测:`veyra_ps5_hw_image_tests.exe --last-paired-ps5 logs/ps5-live-patched`,`logs/ps5-live-patched.log`:D3D12VA、1920×1080、fallback=false;软件/硬件全图误差 **0**,退出 0。已查看硬解输出 PNG:完整《羊蹄山之魂》装备页,细条消失;无旧的超切片警告。+- `cmd /c out\remoteplay\build-extra-delay.cmd` 产品构建成功,`logs/ps5-strip-product-build.log`。新 5 个 FFmpeg DLL 已放入 `out/remoteplay/product-repair` 及默认开发依赖前缀 `C:\veyra-deps\installed\x64-windows\bin`,避免下次构建复制回旧版。原 DLL 保留在 `out/remoteplay/ffmpeg-baseline-backup`;原始 `.lib`/公开头文件 ABI 不变。+- 新 avcodec-63.dll SHA256:`0710F0D87A7FFCC9F998F1A35D0500345F6C66EB9A5A39C51D60D293142BD84F`。完整 5 文件身份/源码头文件/补丁哈希与原配置在 `logs/ps5-ffmpeg-local-build.json`、依赖前缀 `share/ffmpeg/veyra-local-build.json`。NVIDIA DLL 未变。+- 最终普通文件全图/并发纹理回归:`logs/hw-import-final.log`,4 帧误差 0,4 个并发黑白图错误通道 0。+- `veyra_hdr_color_tests.exe`:8 组 P010/planar、limited/full、HDR 原生/转SDR GPU色值及呈现全部通过(`logs/ps5-strip-hdr.log`)。+- `veyra_hdr_color_tests.exe logs/ps5-main10-fixture.mp4`:Main10 软/硬解 × NR单独/标准 SR→NR→FG/低延迟 NR→SR→FG,共6组,每组12帧真实NR,组合模式含12次SR及11张生成帧;退出0,`logs/ps5-strip-main10-combo.log`。+- 更新后主程序硬解文件 NR 连续40秒:`VEYRA_TEST_FILE_HW_DECODE=1`, `veyra.exe --smoke-seconds 40 --smoke-view professional logs/ps5-p1-1080p30-long.mp4`;`logs/ps5-strip-final-nr-fg.log`:1135 源帧、1135次NR、1134次NVOF、failed=false。该次FG未开启(文件名不代表测试功能);NR CreateFeature18=0x1、SEH=0。未在当前修复后主UI做持续PS5手柄/音频验收,实机证据为共享产品Source/Graph的同AU全图比较。+- `veyra_ui_contract_tests.exe` 通过(模式/旁路、384 DPI布局组合、PCM音量及设置存储),`logs/ps5-strip-contract.log`。+- `git apply --reverse --check <ps5-h264-slices.patch>` 对外置已补丁源码通过。最初零上下文补丁的普通 apply 检查失败,已补上下文;最终补丁源码内容不变。原本的中间源码ZIP不作为最终交付。+- 对应源码打包验证成功:`scripts/package-ffmpeg-source.py --prefix C:/veyra-deps/installed/x64-windows --vcpkg C:/veyra-deps/vcpkg --source C:/veyra-deps/ffmpeg-ps5-slices-source --output out/remoteplay/ffmpeg-slices-corresponding-source-final.zip --version 0.0.5`。10442源码记录、LGPL,SHA256 `694E19F42CBC7C210619532B3E101E184522E7CC084491C615918C6DA205B339`;仅本地验证,未上传或替换已发布资产。++结论:本次 H.264 硬解细条故障已通过真实PS5同码流对照修复。用户可重开桌面“Veyra PS5 测试版”,选“自动·优先硬解”或“D3D12VA 硬件解码”重新连接;保留软件解码选项。未发布;实际 PS5 HDR 主机输出、长时串流/手柄/音频仍由用户继续验收,不以文件Main10回归冒充实机HDR。diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex 4cd3818c..97bd264f 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -1754,3 +1754,8 @@ apps/veyra/SettingsWindow.cpp调整布局;apps/veyra/ui/AppShell.cpp新增音## 2026-09-12 增强处理耗时主面板与应用图标用户确认后开工存档7a30b66,分支codex/processing-metrics-and-app-icon。主曲线与大数字改为同帧光流/NR/SR/残差/FG批次GPU区间去重后的处理耗时,排除呈现等待与音频;原有额外显示延迟移到小三角详情第一项。XeSS内部FG缺计时继续明确排除。用户Logo转换为七尺寸ICO,嵌入EXE大/小窗口图标与专业模式品牌位。没有修改音频/跳帧/呈现调度,不能将本次显示修正称为过载迟到已修复。构建两次成功,命令cmd /c out/remoteplay/build-extra-delay.cmd;98合同检查通过。180秒4K文件NR+DLSSG短测5275帧、5251生成帧、failed=false;最终构建另用1080色条文件到4K测试视频SR+NR+DLSSG,Create result=0x1/SEH=0、FG warm-up Evaluate=0x1,实际GUI主数字约12.1ms、详情首项迟到约0.5ms,曲线/详情切换及Logo可见。ExtractIconExW确认EXE一组图标;具体命令、文件、范围与日志见docs/PROCESSING_METRICS_ICON_2026-09-12.md。未测试实卡、PS5实机及XeSS内部计时,未发布。下一步由用户体验新版面板;过载调度方案仍单独待实施。++## 2026-09-13 PS5 H.264 硬解细条修复+基线83f90ba,分支codex/ps5-decoded-frame-strip。用户软件解码正常;同真实PS5 AU软/硬解比较定位到FFmpeg n9.0.1 H.264 MAX_SLICES=32,而PS5输入68 slices,硬解在进入增强前已经损坏。外置开源源码容量改256并按原LGPL功能配置重编译;同码流全图误差由167.459变为0,已查看完整装备页,日志ps5-live-decode/ps5-live-patched。另用两张黑白图并发GPU排队复现并修复共享硬解SRV槽覆盖,按已有两槽fence轮转并使用staging,修复后4组错误通道归零。+产品构建cmd /c out/remoteplay/build-extra-delay.cmd成功(最后ps5-strip-final-build.log);普通视频软硬解全图、8组HDR颜色/呈现、6组Main10软硬解NR/SR/FG组合、40秒主程序硬解NR(1135次NR,1134次NVOF,failed=false)、UI合同回归通过。NR CreateFeature18=0x1,SEH=0。未将共享Source/Graph实机同AU验证冒充主UI长时PS5/HDR/手柄/音频验收。+新FFmpeg五DLL更新本机测试目录与默认开发前缀,原件忽略目录备份;新增源码补丁、重编译脚本、双层provenance打包校验及真实全图诊断。对应源码ZIP本地验证通过,未发布;SDK/NVIDIA运行时/依赖DLL/媒体/凭据均未入Git。失败记录包括:诊断缺include、MSYS link遮蔽MSVC、零上下文补丁apply失败,均已修正;最初GPU回读一致但画面仍坏的检查不作通过证明。详情、命令、哈希、日志与后续验收见docs/PS5_HARDWARE_STRIP_REPAIR_2026-09-13.md。用户下一步重开桌面PS5测试版,选自动优先硬解或D3D12VA重连体验。diff --git a/scripts/ffmpeg/README.md b/scripts/ffmpeg/README.mdnew file mode 100644index 00000000..a858b2d3--- /dev/null+++ b/scripts/ffmpeg/README.md@@ -0,0 +1,14 @@+# PS5 H.264 slice capacity repair++Base: FFmpeg n9.0.1 with the original vcpkg 9.0.1#1 patches. FFmpeg remains LGPL-2.1-or-later in the recorded configuration; this patch does not enable GPL/nonfree/external codec features.++The H.264 D3D12 backend uses `MAX_SLICES` from `libavcodec/h264dec.h` for its fixed slice-control array. PS5 1080p H.264 supplied 68 slices per picture during the regression, exceeding the original 32. `ps5-h264-slices.patch` increases capacity to 256, a power of two required by the internal ring indexing. This does not re-encode the stream or change bitrate, resolution or GPU decoding.++1. Copy the matching vcpkg-patched source tree to a new external directory; do not mix it with another vcpkg build currently in progress.+2. Apply `git apply /path/to/ps5-h264-slices.patch` from that source directory. Verify `h264dec.h` has `MAX_SLICES 256`.+3. Run `prepare-slice-build.py` with explicit `--reference-bin`, `--source`, `--build`, `--prefix`, `--msys`, `--msvc-bin`, `--nasm` and `--output` paths. Reference-bin is the existing compatible FFmpeg DLL directory. MSYS is its installation root; MSVC-bin is the VS x64 compiler directory; nasm is the assembler directory. The helper queries the existing DLL's LGPL configuration and only changes installation/archive-tool paths.+4. In a VS x64 developer environment run MSYS `bash.exe <output-script>`. The script puts MSVC first in PATH so MSYS `link.exe` cannot replace the MSVC linker. It performs configure, `make -j8`, and `make install` into the separate prefix.+5. Test the rebuilt DLLs before replacing local development dependencies. Preserve the baseline DLLs and record all five rebuilt DLL SHA-256 values, the patched header SHA-256, patch SHA-256 and unchanged configuration in `share/ffmpeg/veyra-local-build.json`. Publisher scripts include/validate this additional provenance; it is not a player runtime DLL lock.+6. Build and run `veyra_hw_import_image_tests <1080p H.264 file> <image-prefix>`, HDR color tests, and the opt-in `veyra_ps5_hw_image_tests --last-paired-ps5 <image-prefix>`. The latter briefly connects the last DPAPI-saved PS5 and compares software/hardware decoding of the **same** compressed AU; never package its images or private logs.++For a later release, pass the actual Veyra-patched source directory to `scripts/package-ffmpeg-source.py`; the stock vcpkg source directory must be rejected when the local-build record is present. Include the resulting corresponding-source archive, original licenses, original vcpkg SPDX (baseline provenance), and the extra Veyra build record. No FFmpeg DLL or copied dependency source is committed to Veyra Git.diff --git a/scripts/ffmpeg/prepare-slice-build.py b/scripts/ffmpeg/prepare-slice-build.pynew file mode 100644index 00000000..59a5061d--- /dev/null+++ b/scripts/ffmpeg/prepare-slice-build.py@@ -0,0 +1,41 @@+"""Generate a matching FFmpeg rebuild script; does not install/replace DLLs.++Run in a VS x64 developer environment, then invoke the emitted script with+the supplied MSYS bash. The source must already have ps5-h264-slices.patch.+"""+import argparse+import ctypes+import os+from pathlib import Path+import shlex++p = argparse.ArgumentParser()+for name in ('reference-bin', 'source', 'build', 'prefix', 'msys', 'msvc-bin', 'nasm', 'output'):+ p.add_argument('--' + name, type=Path, required=True)+a = p.parse_args()+if '#define MAX_SLICES 256' not in (a.source / 'libavcodec/h264dec.h').read_text():+ raise SystemExit('Apply ps5-h264-slices.patch to a separate n9.0.1 source tree first')+with os.add_dll_directory(str(a.reference_bin.resolve())):+ lib = ctypes.CDLL(str((a.reference_bin / 'avcodec-63.dll').resolve()))+ lib.avcodec_configuration.restype = ctypes.c_char_p+ lib.avcodec_license.restype = ctypes.c_char_p+ if lib.avcodec_license().decode() != 'LGPL version 2.1 or later':+ raise SystemExit('Unexpected reference license')+ config = lib.avcodec_configuration().decode()+def posix(path):+ value = path.resolve().as_posix()+ return '/' + value[0].lower() + value[2:] if len(value) > 2 and value[1] == ':' else value+args = shlex.split(config)+ar = a.msys / 'usr/share/automake-1.18/ar-lib'+args = [('--prefix=' + a.prefix.resolve().as_posix() if x.startswith('--prefix=') else+ '--ar=' + shlex.quote(posix(ar)) + ' lib.exe' if x.startswith('--ar=') else x) for x in args]+a.build.mkdir(parents=True, exist_ok=True)+a.output.parent.mkdir(parents=True, exist_ok=True)+search = ':'.join(posix(x) for x in (a.msvc_bin, a.msys / 'usr/bin', a.nasm))+script = ('#!/bin/bash\nset -eu\nexport PATH=' + shlex.quote(search) + ':"$PATH"\n'+ + 'cd ' + shlex.quote(posix(a.build)) + '\n'+ + shlex.quote(posix(a.source / 'configure')) + ' ' + shlex.join(args)+ + '\nmake -j8\nmake install\n')+a.output.write_text(script, encoding='utf-8', newline='\n')+a.output.with_suffix('.reference-config.txt').write_text(config, encoding='utf-8')+print(a.output)diff --git a/scripts/ffmpeg/ps5-h264-slices.patch b/scripts/ffmpeg/ps5-h264-slices.patchnew file mode 100644index 00000000..806686e2--- /dev/null+++ b/scripts/ffmpeg/ps5-h264-slices.patch@@ -0,0 +1,10 @@+--- a/libavcodec/h264dec.h++++ b/libavcodec/h264dec.h+@@ -56,6 +56,6 @@+ * The maximum number of slices supported by the decoder.+ * must be a power of 2+ */+-#define MAX_SLICES 32++#define MAX_SLICES 256++ #ifdef ALLOW_INTERLACEdiff --git a/scripts/package-ffmpeg-source.py b/scripts/package-ffmpeg-source.pyindex 4883354a..25164579 100644--- a/scripts/package-ffmpeg-source.py+++ b/scripts/package-ffmpeg-source.py@@ -27,6 +27,19 @@ for item in spdx['files']:if hashlib.sha256(path.read_bytes()).hexdigest() != expected.lower():raise SystemExit(f'Port provenance mismatch: {path.name}')records = []+local_build_path = args.prefix / 'share/ffmpeg/veyra-local-build.json'+local_build = json.loads(local_build_path.read_text(encoding='utf-8-sig')) if local_build_path.exists() else None+patches = Path(__file__).resolve().parent / 'ffmpeg'+if local_build:+ for item in local_build['files']:+ if Path(item['name']).name != item['name']:+ raise SystemExit('Invalid FFmpeg build manifest path')+ if hashlib.sha256((args.prefix / 'bin' / item['name']).read_bytes()).hexdigest() != item['sha256'].lower():+ raise SystemExit('FFmpeg binary does not match the local build record')+ if hashlib.sha256((args.source / 'libavcodec/h264dec.h').read_bytes()).hexdigest() != local_build['h264HeaderSha256'].lower():+ raise SystemExit('Select the matching Veyra-patched FFmpeg source tree')+ if hashlib.sha256((patches / 'ps5-h264-slices.patch').read_bytes()).hexdigest() != local_build['patchSha256'].lower():+ raise SystemExit('FFmpeg patch identity mismatch')with os.add_dll_directory(str((args.prefix / 'bin').resolve())):lib = ctypes.CDLL(str((args.prefix / 'bin/avcodec-63.dll').resolve()))lib.avcodec_configuration.restype = ctypes.c_char_p@@ -47,13 +60,20 @@ with zipfile.ZipFile(args.output, 'x', compression=zipfile.ZIP_DEFLATED, compresarchive.write(path, name)records.append({'path': name, 'sha256': hashlib.sha256(path.read_bytes()).hexdigest()})archive.write(spdx_path, 'FFMPEG-SPDX.json')+ if local_build:+ archive.write(local_build_path, 'FFMPEG-VEYRA-BUILD.json')+ for path in sorted(patches.iterdir()):+ if path.is_file():+ archive.write(path, 'veyra-patches/' + path.name)archive.write(args.vcpkg / 'LICENSE.txt', 'VCPKG-LICENSE.txt')archive.writestr('binary-configuration.txt', license_name + '\n\n' + configuration + '\n')archive.writestr('source-manifest.json', json.dumps(records, indent=2))archive.writestr('README.txt',f'FFmpeg 9.0.1#1 corresponding-source material for Veyra {args.version}.\n''Not needed to run the application. No NVIDIA SDK or runtime is included.\n'- 'ffmpeg-patched is the local vcpkg patched n9.0.1 source tree.\n'+ 'ffmpeg-patched is the matching patched n9.0.1 source tree.\n'+ 'When FFMPEG-VEYRA-BUILD.json exists, also apply the recorded Veyra patch\n'+ 'after the vcpkg port patches; see veyra-patches/README.md for rebuild instructions.\n''vcpkg-port contains the build recipe and patches, verified against the shipped SPDX.\n''binary-configuration.txt is queried from the actual distributed avcodec DLL,\n''not copied from a potentially newer build cache.\n'diff --git a/scripts/package-portable.ps1 b/scripts/package-portable.ps1index 69412abc..ca439046 100644--- a/scripts/package-portable.ps1+++ b/scripts/package-portable.ps1@@ -72,6 +72,15 @@ foreach ($shader in Get-ChildItem -LiteralPath (Join-Path $bin 'shaders') -FileCopy-Payload (Join-Path $resolvedRoot 'runtime_local/config/ngx-local.json') 'runtime/config/ngx-local.json'Copy-Payload 'C:/veyra-deps/installed/x64-windows/share/ffmpeg/copyright' 'licenses/FFMPEG-COPYRIGHT.txt'Copy-Payload 'C:/veyra-deps/installed/x64-windows/share/ffmpeg/vcpkg.spdx.json' 'licenses/FFMPEG-SPDX.json'+$ffmpegLocalBuild = 'C:/veyra-deps/installed/x64-windows/share/ffmpeg/veyra-local-build.json'+if (Test-Path -LiteralPath $ffmpegLocalBuild) {+ $ffmpegBuild = Get-Content -LiteralPath $ffmpegLocalBuild -Raw | ConvertFrom-Json+ foreach ($file in $ffmpegBuild.files) {+ if ($file.name -notin $applicationFiles) { throw 'Unexpected FFmpeg build manifest entry' }+ if ((Get-FileHash -LiteralPath (Join-Path $bin $file.name) -Algorithm SHA256).Hash -ne $file.sha256) { throw "FFmpeg publisher provenance mismatch: $($file.name)" }+ }+ Copy-Payload $ffmpegLocalBuild 'licenses/FFMPEG-VEYRA-BUILD.json'+}Copy-Payload (Join-Path $resolvedRoot 'assets/icons/lucide/LICENSE') 'licenses/LUCIDE-LICENSE.txt'Copy-Payload (Join-Path $resolvedRoot 'third_party_local/nvidia/DLSS_repo/LICENSE.txt') 'licenses/NVIDIA_RTX_SDK_LICENSE.txt'Copy-Payload (Join-Path $resolvedRoot 'third_party_local/nvidia/RTX_Video_SDK_1.1.0/NVIDIA_RTX_Video_SDK_License.pdf') 'licenses/NVIDIA_RTX_VIDEO_SDK_LICENSE.pdf'diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cppindex 960f0087..84a7428c 100644--- a/src/pipeline/EnhanceGraph.cpp+++ b/src/pipeline/EnhanceGraph.cpp@@ -792,7 +792,9 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, FramelumaSrv.Texture2D.MipLevels = 1;lumaSrv.Texture2D.PlaneSlice = 0;}- context_.device()->CreateShaderResourceView(nv12Texture, &lumaSrv, cpuHandleOf(yuvPass_, 0));+ // Slots 0/1 remain the CPU-upload views. Hardware views rotate with+ // hardwareInputFrames_/uploadFences_; never overwrite an in-flight SRV.+ stager_.stageSrv(nv12Texture, &lumaSrv, yuvPass_.heap.Get(), 3 + parity * 2);D3D12_SHADER_RESOURCE_VIEW_DESC chromaSrv{};chromaSrv.Format = nv12Texture->GetDesc().Format==DXGI_FORMAT_P010?DXGI_FORMAT_R16G16_UNORM:DXGI_FORMAT_R8G8_UNORM;chromaSrv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;@@ -812,7 +814,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, FramechromaSrv.Texture2D.MipLevels = 1;chromaSrv.Texture2D.PlaneSlice = 1;}- context_.device()->CreateShaderResourceView(nv12Texture, &chromaSrv, cpuHandleOf(yuvPass_, 1));+ stager_.stageSrv(nv12Texture, &chromaSrv, yuvPass_.heap.Get(), 4 + parity * 2);tracker_.transition(list, nv12Texture, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);} else {nv12Ctx_ = sws_getCachedContext(nv12Ctx_, frame->width, frame->height,@@ -870,7 +872,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frameresolved.matrix==YuvMatrix::BT2020NCL?2.0f:resolved.matrix==YuvMatrix::BT601?0.0f:1.0f,resolved.transfer==TransferFunction::PQ?4.0f:float(workingTransferCode(resolved)), (nv12Texture?nv12Texture->GetDesc().Format==DXGI_FORMAT_P010:desc_.hdrInput)?1.0f:0.0f,uintBits(srcW_), uintBits(srcH_), uintBits(desc_.hdrOutput?1u:0u), 0.0f };- yuvPass_.bind(list, constants, gpuHandleOf(yuvPass_, 0).ptr, gpuHandleOf(yuvPass_, 2).ptr);+ yuvPass_.bind(list, constants, gpuHandleOf(yuvPass_, nv12Texture ? 3 + parity * 2 : 0).ptr, gpuHandleOf(yuvPass_, 2).ptr);list->Dispatch((srcW_ + 15) / 16, (srcH_ + 15) / 16, 1);}tracker_.uavBarrier(list, srcRgba_.Get());diff --git a/src/source/RemotePlaySource.cpp b/src/source/RemotePlaySource.cppindex ac639329..99956f8a 100644--- a/src/source/RemotePlaySource.cpp+++ b/src/source/RemotePlaySource.cpp@@ -306,6 +306,14 @@ bool RemotePlaySource::drainDecoder(std::uint64_t sourceIndex, const pipeline::Fconst bool hardware=decoderFrame_->format==AV_PIX_FMT_D3D12;if(sequence_==1||info_.hardwareDecodeActive!=hardware)veyra::log::info("remoteplay-decode",std::format("actual={} pixelFormat={} {}x{} fallback={}",hardware?"D3D12VA":"software",decoderFrame_->format,decoderFrame_->width,decoderFrame_->height,hardwareFallback_));info_.hardwareDecodeActive=hardware;+#ifdef _WIN32+ if(sequence_==1&&hardware){+ auto* native=reinterpret_cast<AVD3D12VAFrame*>(decoderFrame_->data[0]);+ if(native&&native->texture){const auto d=native->texture->GetDesc();+ veyra::log::info("remoteplay-texture",std::format("visible={}x{} resource={}x{} array={} mip={} slice={} format={} flags=0x{:X} crop={}/{}/{}/{} fence={}",decoderFrame_->width,decoderFrame_->height,d.Width,d.Height,d.DepthOrArraySize,d.MipLevels,native->subresource_index,unsigned(d.Format),unsigned(d.Flags),decoderFrame_->crop_left,decoderFrame_->crop_top,decoderFrame_->crop_right,decoderFrame_->crop_bottom,native->sync_ctx.fence_value));+ }+ }+#endifinbox_->decoderBackend(hardware,hardwareFallback_);packet.color.resource = nullptr;// The AU contract is one picture per input. Unknown/reused timestampsdiff --git a/tests/integration/HardwareImportFixtures.h b/tests/integration/HardwareImportFixtures.hnew file mode 100644index 00000000..7535aeeb--- /dev/null+++ b/tests/integration/HardwareImportFixtures.h@@ -0,0 +1,63 @@+#pragma once+#include <cstring>+#include <thread>+#include <chrono>+#include <libavutil/buffer.h>++// Diagnostic-only readback and queue gate: keep two different input images+// pending at once so descriptor overwrites cannot hide behind a CPU wait.+inline bool hardwareImportFixtures(veyra::gfx::D3D12DeviceContext& ctx,+ veyra::gfx::CommandSlotRing& ring) {+ using namespace veyra;+ bool passed=true;+ for(unsigned slices:{1u,3u}) {+ pipeline::EnhanceGraph graph(ctx,ring);pipeline::EnhanceGraphDesc gd;+ gd.sourceWidth=gd.workWidth=64;gd.sourceHeight=gd.workHeight=32;+ gd.enableNr=gd.enableSr=gd.enableFg=false;+ if(!graph.initialize(gd)||!graph.createViews())return false;+ gfx::ComPtr<ID3D12Resource> textures[2],uploads[2];+ AVFrame* frames[2]{};+ for(unsigned i=0;i<2;++i) {+ D3D12_RESOURCE_DESC d{};d.Dimension=D3D12_RESOURCE_DIMENSION_TEXTURE2D;+ d.Width=64;d.Height=32;d.DepthOrArraySize=UINT16(slices);d.MipLevels=1;+ d.Format=DXGI_FORMAT_NV12;d.SampleDesc.Count=1;+ D3D12_HEAP_PROPERTIES hp{};hp.Type=D3D12_HEAP_TYPE_DEFAULT;+ if(FAILED(ctx.device()->CreateCommittedResource(&hp,D3D12_HEAP_FLAG_NONE,&d,D3D12_RESOURCE_STATE_COPY_DEST,nullptr,IID_PPV_ARGS(&textures[i]))))return false;+ const UINT slice=slices-1;+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp[2];UINT rows[2];UINT64 rowBytes[2],size[2];+ ctx.device()->GetCopyableFootprints(&d,slice,1,0,&fp[0],&rows[0],&rowBytes[0],&size[0]);+ ctx.device()->GetCopyableFootprints(&d,slice+slices,1,(size[0]+511)&~UINT64(511),&fp[1],&rows[1],&rowBytes[1],&size[1]);+ D3D12_RESOURCE_DESC b{};b.Dimension=D3D12_RESOURCE_DIMENSION_BUFFER;b.Width=fp[1].Offset+fp[1].Footprint.RowPitch*rows[1];b.Height=1;b.DepthOrArraySize=1;b.MipLevels=1;b.SampleDesc.Count=1;b.Layout=D3D12_TEXTURE_LAYOUT_ROW_MAJOR;+ hp.Type=D3D12_HEAP_TYPE_UPLOAD;+ if(FAILED(ctx.device()->CreateCommittedResource(&hp,D3D12_HEAP_FLAG_NONE,&b,D3D12_RESOURCE_STATE_GENERIC_READ,nullptr,IID_PPV_ARGS(&uploads[i]))))return false;+ void* mapped=nullptr;D3D12_RANGE empty{};if(FAILED(uploads[i]->Map(0,&empty,&mapped)))return false;+ std::memset(mapped,0,size_t(b.Width));+ for(unsigned p=0;p<2;++p)for(unsigned y=0;y<rows[p];++y)+ std::memset(static_cast<uint8_t*>(mapped)+fp[p].Offset+y*fp[p].Footprint.RowPitch,p?128:(i?235:16),size_t(rowBytes[p]));+ uploads[i]->Unmap(0,nullptr);+ Status st;uint32_t slot;auto* list=ring.acquireNext(slot,st);if(!list)return false;+ for(unsigned p=0;p<2;++p){D3D12_TEXTURE_COPY_LOCATION dst{},src{};dst.pResource=textures[i].Get();dst.Type=D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;dst.SubresourceIndex=slice+p*slices;src.pResource=uploads[i].Get();src.Type=D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;src.PlacedFootprint=fp[p];list->CopyTextureRegion(&dst,0,0,0,&src,nullptr);}+ pipeline::StateTracker states;states.set(textures[i].Get(),D3D12_RESOURCE_STATE_COPY_DEST);states.transition(list,textures[i].Get(),D3D12_RESOURCE_STATE_COMMON);+ if(!ring.submitAndSignal(slot))return false;+ frames[i]=av_frame_alloc();frames[i]->format=AV_PIX_FMT_D3D12;frames[i]->width=64;frames[i]->height=32;+ frames[i]->color_range=AVCOL_RANGE_MPEG;frames[i]->colorspace=AVCOL_SPC_BT709;frames[i]->color_trc=AVCOL_TRC_BT709;+ frames[i]->buf[0]=av_buffer_allocz(sizeof(AVD3D12VAFrame));if(!frames[i]->buf[0])return false;+ frames[i]->data[0]=frames[i]->buf[0]->data;+ auto* native=reinterpret_cast<AVD3D12VAFrame*>(frames[i]->data[0]);native->texture=textures[i].Get();native->subresource_index=slice;+ }+ ring.drainQueue();+ gfx::ComPtr<ID3D12Fence> gate;if(FAILED(ctx.device()->CreateFence(0,D3D12_FENCE_FLAG_NONE,IID_PPV_ARGS(&gate))))return false;+ if(FAILED(ctx.directQueue()->Wait(gate.Get(),1)))return false;+ // Watchdog releases the gate even on failure; no unbounded test hang.+ std::jthread watchdog([gate]{std::this_thread::sleep_for(std::chrono::seconds(2));gate->Signal(1);});+ pipeline::EnhanceGraph::FrameOutputs out[2];bool ok=true;+ for(unsigned i=0;i<2;++i)ok=graph.process(frames[i],i*33.333,i==0,out[i],i+1)&&ok;+ gate->Signal(1);+ for(unsigned i=0;i<2&&ok;++i){sink::RgbaImage image;if(!sink::readRgba8(ctx,ring,graph.videoFrameResource(out[i].videoSlot),image))return false;+ unsigned bad=0;for(size_t p=0;p<image.pixels.size();++p)if(p%4!=3&&std::abs(int(image.pixels[p])-(i?255:0))>2)++bad;+ std::cout<<"QUEUED_IMPORT array="<<slices<<" frame="<<i<<" wrongChannels="<<bad<<std::endl;passed=passed&&bad==0;+ }+ passed=passed&&ok;ring.drainQueue();out[0]={};out[1]={};graph.shutdown();for(auto*& f:frames)av_frame_free(&f);+ }+ return passed;+}diff --git a/tests/integration/HardwareImportImageTests.cpp b/tests/integration/HardwareImportImageTests.cppnew file mode 100644index 00000000..b4eee051--- /dev/null+++ b/tests/integration/HardwareImportImageTests.cpp@@ -0,0 +1,52 @@+#include "veyra/pipeline/EnhanceGraph.h"+#include "veyra/gfx/D3D12DeviceContext.h"+#include "veyra/gfx/CommandSlotRing.h"+#include "veyra/source/MediaFileSource.h"+#include "veyra/sink/ImageExportSink.h"+#include <iostream>+#include <cmath>+extern "C" {+#include <libavutil/frame.h>+#include <libavutil/hwcontext_d3d12va.h>+}+using namespace veyra;+#include "HardwareImportFixtures.h"+// Explicit diagnostic readback. Compare the entire GPU-converted image, not+// merely successful decode/evaluate return codes or one non-black pixel.+int wmain(int argc,wchar_t** argv){+ if(argc!=3)return 2;+ CoInitializeEx(nullptr,COINIT_MULTITHREADED);+ gfx::D3D12DeviceContext ctx;gfx::CommandSlotRing ring;Status st;+ if(!ctx.initialize({},st)||!ring.initialize(ctx.device(),ctx.directQueue(),ctx.fence(),ctx.fenceEvent(),6,st))return 3;+ std::vector<sink::RgbaImage> reference;double worst=0;+ for(bool hardware:{false,true}){+ source::MediaFileSource source;source::SourceOpenDesc sd;sd.path=argv[1];sd.preferHardwareDecode=hardware;sd.d3d12Device=ctx.device();sd.d3d12Queue=ctx.directQueue();+ if(!source.open(sd))return 4;+ pipeline::EnhanceGraph graph(ctx,ring);pipeline::EnhanceGraphDesc gd;+ gd.sourceWidth=gd.workWidth=source.info().width;gd.sourceHeight=gd.workHeight=source.info().height;gd.enableNr=false;gd.enableSr=false;gd.enableFg=false;+ if(!graph.initialize(gd)||!graph.createViews())return 5;+ for(unsigned i=0;i<4;++i){+ pipeline::FramePacket packet;const AVFrame* frame=nullptr;source::SourceReadStatus result;+ do{result=source.read(packet,&frame);}while(result==source::SourceReadStatus::Waiting);+ if(result!=source::SourceReadStatus::Frame||(frame->format==AV_PIX_FMT_D3D12)!=hardware)return 6;+ if(hardware){auto* native=reinterpret_cast<AVD3D12VAFrame*>(frame->data[0]);auto d=native->texture->GetDesc();std::cout<<"GPU_IMPORT frame="<<i<<" visible="<<frame->width<<"x"<<frame->height<<" resource="<<d.Width<<"x"<<d.Height<<" array="<<d.DepthOrArraySize<<" slice="<<native->subresource_index<<" format="<<d.Format<<std::endl;}+ pipeline::EnhanceGraph::FrameOutputs out;+ if(!graph.process(frame,i*1000.0/30,i==0,out,i+1,&packet.colorInfo))return 7;+ sink::RgbaImage image;if(!sink::readRgba8(ctx,ring,graph.videoFrameResource(out.videoSlot),image))return 8;+ if(i==0&&!sink::saveImage(std::wstring(argv[2])+(hardware?L"-hardware.png":L"-software.png"),image))return 9;+ if(!hardware)reference.push_back(std::move(image));+ else{+ auto& ref=reference[i];if(ref.width!=image.width||ref.height!=image.height)return 10;+ double sum=0;for(size_t p=0;p<ref.pixels.size();++p)if(p%4!=3)sum+=std::abs(int(ref.pixels[p])-int(image.pixels[p]));+ double error=sum/(image.width*image.height*3.0);worst=std::max(worst,error);+ std::cout<<"PIXEL_COMPARE frame="<<i<<" meanAbsoluteError="<<error<<std::endl;+ }+ out={};+ }+ ring.drainQueue();graph.shutdown();source.close();+ }+ const bool fixtures=hardwareImportFixtures(ctx,ring);+ ring.shutdown();ctx.shutdown();CoUninitialize();+ std::cout<<"FULL_IMAGE_PASS="<<(worst<2.0)<<" worst="<<worst<<std::endl;+ return worst<2&&fixtures?0:11;+}diff --git a/tests/integration/Ps5HardwareImageTests.cpp b/tests/integration/Ps5HardwareImageTests.cppnew file mode 100644index 00000000..2862ec9d--- /dev/null+++ b/tests/integration/Ps5HardwareImageTests.cpp@@ -0,0 +1,69 @@+#include "veyra/remoteplay/ProfileStore.h"+#include "veyra/source/RemotePlaySource.h"+#include "veyra/pipeline/EnhanceGraph.h"+#include "veyra/sink/ImageExportSink.h"+#include "veyra/gfx/D3D12DeviceContext.h"+#include "veyra/gfx/CommandSlotRing.h"+#include <chrono>+#include <thread>+#include <iostream>+extern "C" {+#include <libavutil/frame.h>+#include <libavutil/hwcontext.h>+}+using namespace veyra;+namespace veyra::source {+struct RemotePlaySourceTestAccess {+ static std::vector<uint8_t> takeFirstAu(RemotePlaySource& source){+ auto sample=source.inbox_->tryVideo(remoteplay::monotonic100ns());if(!sample)return {};+ if(!sample->configBefore)return {};+ std::vector<uint8_t> bytes;auto config=sample->configBefore->payload.bytes(),au=sample->sample.payload.bytes();+ bytes.insert(bytes.end(),config.begin(),config.end());bytes.insert(bytes.end(),au.begin(),au.end());return bytes;+ }+ static AVFrame* decode(RemotePlaySource& source,const std::vector<uint8_t>& bytes,bool software){+ if(software)source.decodeMode_=RemotePlayConnectDesc::DecodeMode::Software;+ if(!source.openDecoder(remoteplay::Codec::H264,1920,1080))return nullptr;+ pipeline::FramePacket packet;+ if(!source.submitPacket(bytes,1,packet)||source.ready_.empty())return nullptr;+ return av_frame_clone(source.ready_.front().frame.get());+ }+};+}+// Explicit opt-in live diagnostic. Reuses the last local DPAPI profile only;+// never prints keys, changes pairing, or sends a power command to the console.+int wmain(int argc,wchar_t** argv){+ if(argc!=3||std::wstring_view(argv[1])!=L"--last-paired-ps5")return 2;+ const auto dir=remoteplay::profileDirectory();wchar_t name[80]{};+ GetPrivateProfileStringW(L"RemotePlay",L"LastProfile",L"",name,80,(dir/L"settings.ini").c_str());+ std::wstring profile=name;if(profile.empty()||profile.find_first_of(L"/\\:")!=profile.npos)return 3;+ auto saved=remoteplay::loadProfile(dir/profile);if(!saved)return 4;+ CoInitializeEx(nullptr,COINIT_MULTITHREADED);gfx::D3D12DeviceContext ctx;gfx::CommandSlotRing ring;Status st;+ if(!ctx.initialize({},st)||!ring.initialize(ctx.device(),ctx.directQueue(),ctx.fence(),ctx.fenceEvent(),6,st))return 5;+ source::RemotePlaySource source;source::RemotePlayConnectDesc desc;desc.request=std::move(*saved);+ desc.request.video={1920,1080,60,80000,remoteplay::Codec::H264};desc.decodeMode=source::RemotePlayConnectDesc::DecodeMode::Hardware;+ ctx.device()->AddRef();desc.decodeDevice={ctx.device(),[](ID3D12Device* d){d->Release();}};+ if(!source.connect(desc))return 6;+ AVFrame* frame=nullptr;pipeline::FramePacket packet;auto deadline=std::chrono::steady_clock::now()+std::chrono::seconds(20);+ std::vector<uint8_t> encoded;+ while(std::chrono::steady_clock::now()<deadline){encoded=source::RemotePlaySourceTestAccess::takeFirstAu(source);+ if(!encoded.empty()){frame=source::RemotePlaySourceTestAccess::decode(source,encoded,false);break;}+ std::this_thread::sleep_for(std::chrono::milliseconds(1));+ }+ if(!frame){source.close();return 7;}+ // Decode the identical compressed AU in software, not a transfer of an+ // already corrupted GPU image: the oracle must include decoder correctness.+ source::RemotePlaySource cpuSource;+ AVFrame* cpu=source::RemotePlaySourceTestAccess::decode(cpuSource,encoded,true);if(!cpu)return 8;+ sink::RgbaImage images[2];unsigned i=0;+ for(auto* input:{frame,cpu}){pipeline::EnhanceGraph graph(ctx,ring);pipeline::EnhanceGraphDesc gd;+ gd.sourceWidth=gd.workWidth=input->width;gd.sourceHeight=gd.workHeight=input->height;gd.enableNr=gd.enableSr=gd.enableFg=false;+ if(!graph.initialize(gd)||!graph.createViews())return 9;pipeline::EnhanceGraph::FrameOutputs out;+ if(!graph.process(input,0,true,out,1)||!sink::readRgba8(ctx,ring,graph.videoFrameResource(out.videoSlot),images[i]))return 10;+ if(!sink::saveImage(std::wstring(argv[2])+(i?L"-reference.png":L"-hardware.png"),images[i]))return 11;+ ++i;out={};ring.drainQueue();graph.shutdown();+ }+ double error=0;for(size_t p=0;p<images[0].pixels.size();++p)if(p%4!=3)error+=std::abs(int(images[0].pixels[p])-int(images[1].pixels[p]));+ error/=images[0].width*images[0].height*3.0;+ std::cout<<"PS5_HARDWARE_IMPORT width="<<frame->width<<" height="<<frame->height<<" meanError="<<error<<std::endl;+ av_frame_free(&cpu);av_frame_free(&frame);source.close();ring.shutdown();ctx.shutdown();CoUninitialize();return error<2?0:12;+}