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++
Preflight AMD HIP initialization in a child before in-process NR creation
Veyra Goal Agentb15152be5258
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 460eca38..e6770545 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -381,6 +381,7 @@ add_library(veyra_pipeline STATICsrc/pipeline/AntiAliasPass.cppsrc/pipeline/SmaaLookupTables.cppsrc/pipeline/NrInstance.cpp+ src/pipeline/AmdHipPreflight.cppsrc/pipeline/LmxxfNrBackend.cppsrc/pipeline/Rdna3NrBackend.cppsrc/pipeline/VfgBackend.cpp@@ -449,6 +450,10 @@ add_executable(veyra_lmxxf_nr_tests tests/unit/LmxxfNrTests.cpp)target_compile_features(veyra_lmxxf_nr_tests PRIVATE cxx_std_20)target_link_libraries(veyra_lmxxf_nr_tests PRIVATE veyra_pipeline)add_dependencies(veyra_lmxxf_nr_tests veyra_lmxxf_fake_runtime veyra_lmxxf_fake_original_runtime)+# Issue 88: the AMD HIP self-test child, its class ladder and its result lines.+add_executable(veyra_amd_hip_preflight_tests tests/unit/AmdHipPreflightTests.cpp)+target_compile_features(veyra_amd_hip_preflight_tests PRIVATE cxx_std_20)+target_link_libraries(veyra_amd_hip_preflight_tests PRIVATE veyra_pipeline)add_executable(veyra_lmxxf_runtime_metadata_tests tests/integration/LmxxfNrRuntimeMetadataTests.cpp)target_compile_features(veyra_lmxxf_runtime_metadata_tests PRIVATE cxx_std_20)target_link_libraries(veyra_lmxxf_runtime_metadata_tests PRIVATE veyra_pipeline)diff --git a/apps/veyra-qml/main.cpp b/apps/veyra-qml/main.cppindex 77999258..8f23d3dc 100644--- a/apps/veyra-qml/main.cpp+++ b/apps/veyra-qml/main.cpp@@ -53,6 +53,7 @@#include "veyra/engine/ExportJobManager.h"#include "veyra/engine/PresentationGeometry.h"#include "veyra/gfx/PresentationHooks.h"+#include "veyra/pipeline/AmdHipPreflight.h"#include "veyra/ui/InterfaceRenderer.h"#include "veyra/ui/QmlDataDirectory.h"#include "veyra/ui/QmlPlayerBridge.h"@@ -1104,6 +1105,20 @@ static int runApplication(int argc, char** argv, QString& restartProgram, QStrin}int main(int argc, char** argv) {+ // A child for the AMD HIP self-test (AmdHipPreflight.h): no Qt, no window and+ // no player state, only the HIP calls and their result lines on the pipe.+ if (argc >= 2 && std::strcmp(argv[1], "--amd-hip-preflight") == 0) {+ int count = 0;+ wchar_t** wide = CommandLineToArgvW(GetCommandLineW(), &count);+ const int code = wide ? veyra::pipeline::amdhip::preflightMain(count, wide) : 2;+ if (wide) LocalFree(wide);+ return code;+ }+ {+ std::wstring self(32768, L'\0');+ self.resize(GetModuleFileNameW(nullptr, self.data(), DWORD(self.size())));+ veyra::pipeline::amdhip::setPreflightExecutable(self);+ }QString program;QStringList arguments;const int result = runApplication(argc, argv, program, arguments);diff --git a/docs/ISSUE88_AMD_HIP_PREFLIGHT_2026-11-06.md b/docs/ISSUE88_AMD_HIP_PREFLIGHT_2026-11-06.mdnew file mode 100644index 00000000..ccf6b357--- /dev/null+++ b/docs/ISSUE88_AMD_HIP_PREFLIGHT_2026-11-06.md@@ -0,0 +1,124 @@+# Issue #88:RX 9060 XT 开 AMD NR 第一帧崩溃——HIP 子进程自检(2026-11-06,Claude)++- **分支**:`claude/issue88-hip-preflight-20261106`,工作树 `E:/项目/Veyra/worktrees/claude-issue88-20261106`。+- **基线**:main `edd901e`。与 2.1.3 产品 `7a2d15d` 相比,代码没有差异,只多了文档。+- **状态**:未提交,未合并,未 push/Release,也没有在 issue 上回复。+- **用户要求**:“看一下 issues88 给他修复”,并附上了报告人的 `veyra-nr-crash-evidence.zip`。++## 现场证据++**报告人环境**:++- RX 9060 XT(gfx1200,Navi 44,8 GB,1002:7590);+- 驱动 32.0.32015.12012(Adrenalin 26.10.2),System32 中的 `amdhip64_7.dll` 为 10.0.3683.0,`amd_comgr_3.dll` 为 3.0.0.0(两者时间戳相差约 6 分钟,同一个驱动包);+- Windows 11 26200。++**崩溃情况**:++- 2.1.2 和 2.1.3 共崩溃 14 次,全部是 `amdhip64_7.dll+0x4A40A0` 的访问违例(读地址 0x390)。+- Small 和 Original 两个模型都会崩,每次都在第一帧 NR 约 200 ms 后。++**minidump 解析**(用自写的 minidump 读取脚本,见 `E:/项目/Veyra/reports/claude-issue88-20261106/`):++- **崩溃线程**是一个 HIP 内部线程:栈上只有 `amdhip64_7.dll`,没有 Veyra 或 lmxxf 的帧。+ - 崩溃指令 `mov rcx,[rcx+390h]` 是一个函数的第一条指令,当时 `rcx=0`,即传入了空对象。+- **同一时刻的播放线程**正在 lmxxf 里调用 HIP 并等待:+ - 用 call-return 核对后,最上层的 lmxxf 帧是 `LmxxfNrRuntime.dll+0xA4A2E`;+ - 该处是 `call [rsi+1C8h]`,前后引用的操作名依次是 `"hipInit"`、`"device"`、`"stream"`,后面紧接加载 `c32_prefix_reference.hsaco`;+ - 也就是说,它正卡在网络初始化的 `hipStreamCreate(&stream)` 里,还没有加载任何 gfx1200 内核。+- **模块来源**:HIP 和 COMGR 都来自驱动(System32),不是 Veyra 打包进去的副本。++## 对照++- **上游 lmxxf issue 18**:另一台 RX 9060 XT(gfx1200),驱动 26.10.1,在 Magpie 里运行 0.45 的同一套内核,能正确出画面,只是慢。所以 gfx1200 并不是根本不能创建 HIP 流。+- **Veyra 进程的特殊之处**:默认把整个进程的 GPU 调度等级设为 Realtime(日志 `gpu-priority requested=5 actual=5`,报告人每一次都是这样)。RX 9000 上的 lmxxf 在主进程里运行 HIP;RX 7000 走的是独立 worker 进程。+- **本机探针**(`E:/项目/Veyra/tmp/claude-issue88-20261106/probe`):用 AMD 核显和 HIP 6.4,分别在普通、先建 D3D12 设备、再设为 Realtime、设为 High 四种状态下创建流,全部正常。本机没有 RDNA4 和 HIP 7,这个结果不能代表报告人的环境。+- **结论**:根因在 AMD HIP 运行库内部,本机无法复现。“Realtime 调度等级触发”是最可疑的 Veyra 侧差异,但没有证实。++## 改动++**`include/veyra/pipeline/AmdHipPreflight.h` 和 `src/pipeline/AmdHipPreflight.cpp`(新增)**:++- **子进程模式**:`<exe> --amd-hip-preflight <HIP DLL> <适配器 LUID> <调度等级>`。依次执行以下步骤,每步之前先把步骤名写到管道:+ 1. 用 LUID 在同一块卡上创建 D3D12 设备;+ 2. 设为父进程当前的调度等级;+ 3. 从 System32 加载 `amdhip64_7.dll`(与 lmxxf 相同);+ 4. `hipInit`;+ 5. 用 `hipGetDevicePropertiesR0600` 按 LUID 找设备(与 lmxxf 一样,只有一个且没有 LUID 时用它);+ 6. `hipSetDevice`;+ 7. `hipStreamCreate`;+ 8. 分配 1 MB 显存,在流上清零、同步后释放;+ 9. 销毁流。+- **崩溃记录**:未处理异常过滤器记录异常码、`模块+偏移` 和当时所在的步骤。+- **退出方式**:成功后直接结束子进程,避免 HIP 卸载时出错把“通过”误报成崩溃。+- **父进程的降级顺序**:先用当前等级。不通过时,Realtime 依次试 High、Normal;High 试 Normal。+ - 加载、建设备这类失败与调度等级无关,不再往下试。+ - 每块卡在每个进程里只测一次,结果缓存。+ - 每次尝试写一行日志 `[amd-hip-preflight]`。++**`LmxxfNrBackend::open`**:在模块、ABI、资源和环境检查都通过之后、`Create` 之前执行自检,且只在宿主登记了自检程序时执行。++- **当前等级通过**:行为与原来相同。+- **当前等级失败、较低等级通过**:用 `setGpuPriorityComputeCap` 把本进程的 GPU 调度等级限制到通过的那一档,并记录警告。+ - 默认值不变,只有自检证明当前等级下 HIP 起不来时才降。+- **全部失败**:AMD NR 打开失败,走现有的 NR 后端失败路径,播放继续。错误信息包含每一档的结果,并提示更新驱动、发送日志。++**`GpuSchedulingPriority`**:新增独立的“计算运行库上限”`setGpuPriorityComputeCap`。它与原来的抖音直播伴侣上限取较低者,不改变原来的上限语义。++**`apps/veyra-qml/main.cpp`**:++- `main()` 最前面处理 `--amd-hip-preflight`,在 Qt、窗口、播放器状态、崩溃转储之前。+- 随后把自身 exe 路径登记为自检程序。+- 不新增可执行文件,发布包清单不需要改。++**`tests/unit/AmdHipPreflightTests.cpp` 和 CMake 目标 `veyra_amd_hip_preflight_tests`**:++- **纯逻辑**:降级顺序、输出解析、汇总文字。+- **真实 GPU 调度等级**:Realtime → 计算上限 High → 与 Normal 上限叠加 → 解除。+- **真实子进程**:需要 AMD 适配器,并设置 `VEYRA_TEST_AMD_HIP_DLL`。+- **仅测试用的钩子**:`VEYRA_TEST_AMD_HIP_PREFLIGHT_CRASH=<步骤>:<等级|all>`,它在另一个线程读地址 0x390,模拟现场的崩溃方式。++## 验证++**构建**:用 `scripts/acceptance/build-recording-handoff.py`,任务名 `claude-issue88-20261106`,标签 `2.1.3-issue88-test`,并发 2。++- 构建目标:`veyra_qml_ui`、`veyra_amd_hip_preflight_tests`、`veyra_lmxxf_nr_tests`、`veyra_amd_nr_graph_tests`。+- 首次新建目录 295.5 秒通过;补充子进程信息行后增量构建 9.6 秒通过。+- 新文件没有编译警告。日志里的 `getenv` C4996 警告来自 `LmxxfNrBackend.cpp` 原有的第 59–63 行。++**`veyra_amd_hip_preflight_tests`**:本机 AMD 核显(gfx1036,HIP 6.4.50101),设置 `VEYRA_TEST_AMD_HIP_DLL=amdhip64_6.dll`,全部通过,用时约 4 秒:++- **纯逻辑**:降级顺序、输出解析(含 info 行)、汇总文字。+- **真实调度等级**:Realtime 为 5 → 加计算上限后为 4 → 再叠加 Normal 上限为 2 → 解除后回到 5。+- **真实子进程,正常 HIP**:在等级 5 下全部步骤走到 release,通过。+- **只在等级 5 的 stream 步骤崩溃**:子进程以 0xC0000005 退出并报告偏移和步骤,父进程不受影响,等级 4 通过并被选用。+- **每一档都崩溃**:试了 3 次,HIP 被拒绝。+- **缓存**:同一块卡在同一进程里只测一次。+- **HIP 库不存在**:在 load 步骤失败(code 126),只试一次。++**原有 AMD NR 回归**(准备方式同 `menu-amd-hdr-fix.py` 的 gpu 模式,使用假的 lmxxf 运行库):++- 两轮都通过:AMD 合成图 128 个用例 0 失败(HDR 108 项全部通过,D3D12 调试层 0 错误);lmxxf ABI 66 项 0 失败。+- 这两组测试没有登记自检程序,走的是原来的路径。++**真实 `veyra_qml_ui.exe`**:++- **子进程模式**:放进 2.1.3 文件目录,用临时副本,结束后删除。+ - 不加钩子:在等级 5 下走完全部步骤,输出 `done status=ok`,退出码 0。+ - 加崩溃钩子:退出码为 0xC0000005,输出 `crash ... step=stream`。+ - 没有写日志,也没有写转储。+ - 打进补丁的那一份程序又按同样两种情况复测了一遍,结果相同。+- **普通启动冒烟**:私有配置,Pro 页,8 秒后自动退出。退出码 0,日志里没有 ERROR 或 WARN。++**测试补丁**:`E:/项目/Veyra/test-packages/claude-issue88-20261106/Veyra-2.1.3-issue88-test.zip`(8,650,216 字节,SHA256 `9155e585…`)。++- 内含主程序 `063635483e3e…`、双语 README 和 SHA256SUMS。+- 用法是替换 2.1.3 AMD 包里的 `veyra_qml_ui.exe`;两个显卡包的主程序本来就是同一个文件。++## 没有验证的部分++- **RDNA4 实卡**:本机没有 RDNA4 和 `amdhip64_7.dll`。真实的 gfx1200 和 HIP 7 在 Realtime、High、Normal 下的结果,要等报告人运行测试版后从日志里看。+- **报告人机器上的结果**:“降到 High 后 NR 就能用”只是一种可能。也可能三档都失败;那样 AMD NR 会被关闭但不再崩溃,根因仍要等 AMD 驱动修复,或者再做进一步定位。+- **自检只覆盖到创建流和清零显存**:如果真实运行时之后的步骤(加载内核、导入 D3D12 共享资源)在主进程里崩溃,自检拦不住。+- **本机无法走到 lmxxf 那条路径**:核显名称不含 RX 90,所以真实程序没有完整走过“自检 → 降级 → lmxxf 建网络”;这一段由单元测试和代码审读覆盖。+- **启动耗时**:第一次打开 AMD NR 时,多出子进程初始化 HIP 的时间。本机核显每次约 0.1–0.5 秒,现场没有测。diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex 49e8a7cb..f8466385 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -722,3 +722,30 @@ Veyra-2.1.3-AMD-win64-portable.zip:717577602 bytes,SHA256 `dc1223f0aff0feb39首个QtTest夹具when:windowShown在独立应用中未触发,已停止唯一私有路径测试进程并改Timer显式调用测试方法;两次有效检查均exit0,无engine/QML错误。未碰用户运行进程、配置和原日志。仅作为受控对照把旧处理器放入私有QML,已恢复原字节。本轮删除SHA白名单隔离测试副本的命令被自动审批以blocked by policy拒绝,未执行;保留tests/sr-menu-investigation-20261106/app,不改shell/工具绕过,配置和日志保留。证据CLEANUP.json。产品代码和已发布包均未修改。++## 2026-11-06 Issue #88:RX 9060 XT 开 AMD NR 第一帧崩溃,改为 HIP 子进程自检(Claude)++**状态**:分支 `claude/issue88-hip-preflight-20261106`,基线 main `edd901e`(代码与 2.1.3 `7a2d15d` 相同),未提交,未在 issue 上回复。++**证据**(报告人 zip):14 次崩溃都在 `amdhip64_7.dll+0x4A40A0`,都是读地址 0x390。+- 自写 minidump 读取脚本显示,崩溃线程是 HIP 内部线程;同一时刻,播放线程停在 lmxxf 网络初始化的 `hipStreamCreate`(`LmxxfNrRuntime.dll+0xA4A2E`,前后操作名 hipInit/device/stream)。+- HIP 和 COMGR 都来自驱动的 System32。+- 上游 lmxxf issue 18:另一台 RX 9060 XT 在 Magpie 里能正常跑同一套内核。Veyra 进程默认处于 Realtime GPU 调度等级,是最可疑的差异,未证实。+- 本机核显 + HIP 6 在四种进程状态下创建流都正常,不能代表 RDNA4。++**修复**:新增 `AmdHipPreflight`。+- `LmxxfNrBackend::open` 在 Create 之前,让本程序以 `--amd-hip-preflight` 子进程模式先在同一块卡上执行 D3D12、调度等级、hipInit、按 LUID 选卡、hipSetDevice、hipStreamCreate、显存清零。+- 当前等级失败时依次试 High、Normal,第一个通过的等级通过新的 `setGpuPriorityComputeCap` 应用到本进程。+- 全部失败则拒绝 AMD NR,播放继续。++**验证**:+- 构建 295.5 秒,增量 9.6 秒。+- 新单测在本机核显上全部通过:真实调度等级 5→4→2→5;正常、只在 Realtime 崩溃、每档都崩溃、缓存、缺库。+- 原 AMD 合成图 128/0、lmxxf ABI 66/0。+- 真实 exe 子进程模式无钩子退出码 0,加钩子 0xC0000005;普通启动冒烟正常。++**交付**:测试补丁 `test-packages/claude-issue88-20261106/Veyra-2.1.3-issue88-test.zip`。++**记录**:`docs/ISSUE88_AMD_HIP_PREFLIGHT_2026-11-06.md`,报告 `E:/项目/Veyra/reports/claude-issue88-20261106/`。++**未验证**:RDNA4/HIP 7 实卡结果要等报告人运行;本机走不到 lmxxf 真实路径。diff --git a/include/veyra/gfx/GpuSchedulingPriority.h b/include/veyra/gfx/GpuSchedulingPriority.hindex 3b38aa94..e53f1ed3 100644--- a/include/veyra/gfx/GpuSchedulingPriority.h+++ b/include/veyra/gfx/GpuSchedulingPriority.h@@ -20,4 +20,7 @@ GpuPriorityStatus gpuPriorityStatus();// Highest class to use while another program shares the GPU (Realtime = no cap). The// class applied is the lower of the request and the cap; `requested` keeps the request.void setGpuPriorityCap(GpuPriority cap);+// Highest class an in-process compute runtime survives here (AMD HIP self-test,+// AmdHipPreflight.h). Independent of the cap above; the lowest of the three applies.+void setGpuPriorityComputeCap(GpuPriority cap);}diff --git a/include/veyra/pipeline/AmdHipPreflight.h b/include/veyra/pipeline/AmdHipPreflight.hnew file mode 100644index 00000000..f5aafe67--- /dev/null+++ b/include/veyra/pipeline/AmdHipPreflight.h@@ -0,0 +1,59 @@+// SPDX-License-Identifier: GPL-3.0-only+#pragma once+// HIP self-test for the in-process RX 9000 NR runtime (lmxxf).+//+// GitHub issue 88 (RX 9060 XT gfx1200, driver 32.0.32015.12012, amdhip64_7.dll+// 10.0.3683.0): the first hipStreamCreate the runtime makes on the first NR+// frame let a HIP-internal thread read through a null object+// (amdhip64_7.dll+0x4A40A0, read of 0x390) and the whole player went down,+// 14 times on 2.1.2 and 2.1.3. The same gfx1200 card runs these kernels in+// Magpie (upstream lmxxf issue 18), whose process does not hold the Realtime+// GPU scheduling class this player requests by default.+//+// HIP therefore meets this process only after a child (this executable,+// --amd-hip-preflight) has made the same first calls on the same adapter: a+// D3D12 device, the parent's GPU scheduling class, hipInit, the device with the+// adapter's LUID, hipSetDevice, hipStreamCreate and a small allocation cleared on+// that stream. A crash ends the child, not the player. When the current class+// fails, High and then Normal are tried; the first class that passes caps this+// process while AMD NR is in use. When none passes AMD NR is refused with the+// failing step, instead of crashing.+#include <cstdint>+#include <string>+#include <vector>++namespace veyra::pipeline::amdhip {+struct PreflightAttempt {+ int priority=0; // D3DKMT scheduling class the child used; 0 = left unchanged+ bool ok=false;+ std::string step; // the last step the child started+ std::string detail; // failure, crash or timeout text+ std::string info; // the child's info lines (class granted, HIP runtime, devices), " | " joined+ uint32_t exitCode=0;+};+struct PreflightOutcome {+ bool ok=false;+ int priority=0; // class of the passing attempt+ std::vector<PreflightAttempt> attempts;+ std::string summary; // one line for the log and the refusal+};++// Child mode: argv = exe --amd-hip-preflight <hip dll> <adapter LUID hex> <priority class>.+int preflightMain(int argc, wchar_t** argv);++// The classes to try: the current one, then High and Normal below it. An unknown+// current class (-1) runs once without changing the child's class.+std::vector<int> ladder(int current);+// Reads one child's output; a missing final line means it did not finish.+PreflightAttempt parseOutput(const std::string& output, uint32_t exitCode, int priority);+std::string summarize(const std::vector<PreflightAttempt>& attempts);++// The executable that implements --amd-hip-preflight. Empty (the default, e.g.+// in tests that do not opt in): no self-test, HIP is loaded as before.+void setPreflightExecutable(const std::wstring& path);+std::wstring preflightExecutable();+// Runs the ladder (no cache). VEYRA_TEST_AMD_HIP_DLL replaces amdhip64_7.dll in tests.+PreflightOutcome runLadder(uint64_t adapterLuid, int currentPriority);+// runLadder once per adapter per process; later calls return the first outcome.+PreflightOutcome preflightOnce(uint64_t adapterLuid, int currentPriority);+} // namespace veyra::pipeline::amdhipdiff --git a/src/gfx/GpuSchedulingPriority.cpp b/src/gfx/GpuSchedulingPriority.cppindex 0dc277c6..d85f7cb3 100644--- a/src/gfx/GpuSchedulingPriority.cpp+++ b/src/gfx/GpuSchedulingPriority.cpp@@ -18,7 +18,11 @@ struct Api {std::mutex mutex;GpuPriorityStatus current;GpuPriority cap=GpuPriority::Realtime;-GpuPriority effective(){return int(current.requested)<=int(cap)?current.requested:cap;}+GpuPriority computeCap=GpuPriority::Realtime;+GpuPriority effective(){+ const GpuPriority limit=int(cap)<=int(computeCap)?cap:computeCap;+ return int(current.requested)<=int(limit)?current.requested:limit;+}void publish(GpuPriorityState state,int actual,uint32_t status){const bool capped=effective()!=current.requested;if(current.state==state&¤t.actual==actual&¤t.status==status&¤t.capped==capped)return;@@ -71,5 +75,12 @@ void setGpuPriorityCap(GpuPriority value){cap=value;++current.revision;applyLocked();}+void setGpuPriorityComputeCap(GpuPriority value){+ if(value!=GpuPriority::Normal&&value!=GpuPriority::High&&value!=GpuPriority::Realtime)return;+ std::lock_guard lock(mutex);+ if(computeCap==value)return;+ computeCap=value;++current.revision;+ applyLocked();+}GpuPriorityStatus gpuPriorityStatus(){std::lock_guard lock(mutex);return current;}}diff --git a/src/pipeline/AmdHipPreflight.cpp b/src/pipeline/AmdHipPreflight.cppnew file mode 100644index 00000000..5f64f15e--- /dev/null+++ b/src/pipeline/AmdHipPreflight.cpp@@ -0,0 +1,323 @@+// SPDX-License-Identifier: GPL-3.0-only+#include "veyra/pipeline/AmdHipPreflight.h"++#include "veyra/Log.h"+#include "veyra/pipeline/Rdna3HipDevices.h"++#include <windows.h>+#include <d3d12.h>+#include <dxgi1_4.h>++#include <algorithm>+#include <cstdio>+#include <cstring>+#include <format>+#include <map>+#include <mutex>+#include <string_view>+#include <thread>+#include <vector>++namespace veyra::pipeline::amdhip {+namespace {+constexpr DWORD kChildTimeoutMs = 30000;+const char* g_step = "start";++// Child side: one line per event on the inherited pipe, unbuffered, no allocation+// on the crash path.+void emit(const char* text) {+ const HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);+ if (!out || out == INVALID_HANDLE_VALUE) return;+ char line[600];+ const int n = _snprintf_s(line, sizeof(line), _TRUNCATE, "amd-hip-preflight %s\n", text);+ DWORD written = 0;+ if (n > 0) WriteFile(out, line, DWORD(n), &written, nullptr);+}+void step(const char* name) {+ g_step = name;+ char text[96];+ _snprintf_s(text, sizeof(text), _TRUNCATE, "step=%s", name);+ emit(text);+}+LONG WINAPI crashFilter(EXCEPTION_POINTERS* info) {+ const auto* record = info ? info->ExceptionRecord : nullptr;+ const DWORD code = record ? record->ExceptionCode : 0;+ const void* address = record ? record->ExceptionAddress : nullptr;+ char where[320] = "unknown";+ HMODULE module = nullptr;+ if (address && GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,+ static_cast<LPCWSTR>(address), &module)) {+ wchar_t path[MAX_PATH]{};+ GetModuleFileNameW(module, path, MAX_PATH);+ const wchar_t* name = wcsrchr(path, L'\\');+ char narrow[MAX_PATH]{};+ WideCharToMultiByte(CP_UTF8, 0, name ? name + 1 : path, -1, narrow, MAX_PATH, nullptr, nullptr);+ _snprintf_s(where, sizeof(where), _TRUNCATE, "%s+0x%llX", narrow,+ static_cast<unsigned long long>(reinterpret_cast<uintptr_t>(address) - reinterpret_cast<uintptr_t>(module)));+ }+ char text[480];+ _snprintf_s(text, sizeof(text), _TRUNCATE, "crash code=0x%08lX at=%s step=%s", code, where, g_step);+ emit(text);+ return EXCEPTION_EXECUTE_HANDLER; // the child ends with the exception code+}+// Test hook: VEYRA_TEST_AMD_HIP_PREFLIGHT_CRASH=<step>:<class|all> reads address+// 0x390 on another thread at that step, as the field crash did.+void maybeCrash(const char* name, int priority) {+ char value[64]{};+ if (!GetEnvironmentVariableA("VEYRA_TEST_AMD_HIP_PREFLIGHT_CRASH", value, sizeof(value))) return;+ const char* colon = strchr(value, ':');+ if (!colon || size_t(colon - value) != strlen(name) || strncmp(value, name, strlen(name)) != 0) return;+ if (strcmp(colon + 1, "all") != 0 && atoi(colon + 1) != priority) return;+ std::thread([] { (void)*reinterpret_cast<volatile int*>(static_cast<uintptr_t>(0x390)); }).join();+}+int fail(const char* failedStep, long long code, int exitCode) {+ char text[160];+ _snprintf_s(text, sizeof(text), _TRUNCATE, "failed step=%s code=%lld", failedStep, code);+ emit(text);+ return exitCode;+}++template<class F> F resolve(HMODULE module, const char* name) { return reinterpret_cast<F>(GetProcAddress(module, name)); }++// Parent side: run one child with only its own output pipe inherited.+bool runChild(const std::wstring& executable, const std::wstring& command, std::string& output, DWORD& exitCode, bool& timedOut) {+ SECURITY_ATTRIBUTES sa{sizeof(sa), nullptr, TRUE};+ HANDLE read = nullptr, write = nullptr;+ if (!CreatePipe(&read, &write, &sa, 65536)) return false;+ SetHandleInformation(read, HANDLE_FLAG_INHERIT, 0);+ SIZE_T bytes = 0;+ InitializeProcThreadAttributeList(nullptr, 1, 0, &bytes);+ std::vector<unsigned char> storage(bytes);+ STARTUPINFOEXW startup{};+ startup.StartupInfo.cb = sizeof(startup);+ startup.StartupInfo.dwFlags = STARTF_USESTDHANDLES;+ startup.StartupInfo.hStdOutput = write;+ startup.StartupInfo.hStdError = write;+ startup.lpAttributeList = reinterpret_cast<LPPROC_THREAD_ATTRIBUTE_LIST>(storage.data());+ if (!InitializeProcThreadAttributeList(startup.lpAttributeList, 1, 0, &bytes) ||+ !UpdateProcThreadAttribute(startup.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_HANDLE_LIST, &write, sizeof(write), nullptr, nullptr)) {+ CloseHandle(read); CloseHandle(write); return false;+ }+ std::wstring line = command;+ PROCESS_INFORMATION process{};+ const bool created = CreateProcessW(executable.c_str(), line.data(), nullptr, nullptr, TRUE,+ CREATE_NO_WINDOW | EXTENDED_STARTUPINFO_PRESENT, nullptr, nullptr, &startup.StartupInfo, &process) != FALSE;+ DeleteProcThreadAttributeList(startup.lpAttributeList);+ CloseHandle(write);+ if (!created) { CloseHandle(read); return false; }+ // A few hundred bytes: they fit the pipe, so waiting first cannot block the child.+ const DWORD waited = WaitForSingleObject(process.hProcess, kChildTimeoutMs);+ timedOut = waited != WAIT_OBJECT_0;+ if (timedOut) { TerminateProcess(process.hProcess, 1); WaitForSingleObject(process.hProcess, 5000); }+ GetExitCodeProcess(process.hProcess, &exitCode);+ char buffer[4096];+ DWORD n = 0;+ while (ReadFile(read, buffer, sizeof(buffer), &n, nullptr) && n) output.append(buffer, n);+ CloseHandle(read); CloseHandle(process.hThread); CloseHandle(process.hProcess);+ return true;+}++std::mutex g_mutex;+std::wstring g_executable;+std::map<uint64_t, PreflightOutcome> g_outcomes;+} // namespace++int preflightMain(int argc, wchar_t** argv) {+ SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);+ SetUnhandledExceptionFilter(crashFilter);+ if (argc < 5) return fail("args", argc, 2);+ const std::wstring hipDll = argv[2];+ const uint64_t luid = wcstoull(argv[3], nullptr, 16);+ const int priority = _wtoi(argv[4]);+ char text[256];+ _snprintf_s(text, sizeof(text), _TRUNCATE, "start luid=0x%016llX class=%d", static_cast<unsigned long long>(luid), priority);+ emit(text);++ // The same adapter as the player's device, through its LUID.+ step("d3d12");+ IDXGIFactory4* factory = nullptr;+ HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&factory));+ if (FAILED(hr)) return fail("d3d12", hr, 10);+ const LUID wanted{DWORD(luid & 0xFFFFFFFFull), LONG(luid >> 32)};+ IDXGIAdapter1* adapter = nullptr;+ hr = factory->EnumAdapterByLuid(wanted, IID_PPV_ARGS(&adapter));+ factory->Release();+ if (FAILED(hr)) return fail("d3d12", hr, 10);+ ID3D12Device* device = nullptr;+ hr = D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device));+ adapter->Release();+ if (FAILED(hr)) return fail("d3d12", hr, 10);++ // The parent's scheduling class; WDDM keeps none before the device above exists.+ if (priority > 0) {+ step("priority");+ const HMODULE gdi = LoadLibraryExW(L"gdi32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);+ const auto set = gdi ? resolve<LONG(WINAPI*)(HANDLE, int)>(gdi, "D3DKMTSetProcessSchedulingPriorityClass") : nullptr;+ const auto get = gdi ? resolve<LONG(WINAPI*)(HANDLE, int*)>(gdi, "D3DKMTGetProcessSchedulingPriorityClass") : nullptr;+ if (!set || !get) return fail("priority", -1, 11);+ const LONG status = set(GetCurrentProcess(), priority);+ int actual = -1;+ get(GetCurrentProcess(), &actual);+ _snprintf_s(text, sizeof(text), _TRUNCATE, "info class=%d status=0x%08lX", actual, static_cast<unsigned long>(status));+ emit(text);+ if (actual != priority) return fail("priority", actual, 11);+ }++ step("load");+ const HMODULE hip = LoadLibraryExW(hipDll.c_str(), nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);+ if (!hip) return fail("load", GetLastError(), 12);+ using Int = int (*)(int*);+ const auto init = resolve<int (*)(unsigned)>(hip, "hipInit");+ const auto version = resolve<Int>(hip, "hipRuntimeGetVersion");+ const auto count = resolve<Int>(hip, "hipGetDeviceCount");+ const auto properties = resolve<int (*)(void*, int)>(hip, "hipGetDevicePropertiesR0600");+ const auto select = resolve<int (*)(int)>(hip, "hipSetDevice");+ const auto createStream = resolve<int (*)(void**)>(hip, "hipStreamCreate");+ const auto allocate = resolve<int (*)(void**, size_t)>(hip, "hipMalloc");+ const auto clear = resolve<int (*)(void*, int, size_t, void*)>(hip, "hipMemsetAsync");+ const auto wait = resolve<int (*)(void*)>(hip, "hipStreamSynchronize");+ const auto release = resolve<int (*)(void*)>(hip, "hipFree");+ const auto destroyStream = resolve<int (*)(void*)>(hip, "hipStreamDestroy");+ if (!init || !version || !count || !properties || !select || !createStream || !allocate || !clear || !wait || !release || !destroyStream)+ return fail("load", -2, 12);++ step("init");+ maybeCrash("init", priority);+ if (const int e = init(0)) return fail("init", e, 13);+ int runtime = 0;+ version(&runtime);++ step("devices");+ maybeCrash("devices", priority);+ int devices = 0;+ if (const int e = count(&devices)) return fail("devices", e, 14);+ std::vector<rdna3::hip::Device> list;+ std::vector<char> props(rdna3::hip::kPropertiesBytes);+ for (int i = 0; i < devices; ++i) {+ std::fill(props.begin(), props.end(), char(0));+ if (const int e = properties(props.data(), i)) return fail("devices", e, 14);+ list.push_back(rdna3::hip::parseProperties(i, props.data(), props.size()));+ _snprintf_s(text, sizeof(text), _TRUNCATE, "info runtime=%d device=%d luid=0x%016llX arch=%s name=%s", runtime, i,+ static_cast<unsigned long long>(list.back().luid), list.back().arch.c_str(), list.back().name.c_str());+ emit(text);+ }+ // As the runtime does: the LUID decides; a lone device without one is the fallback.+ auto index = rdna3::hip::indexForLuid(list, luid);+ if (!index && list.size() == 1 && list[0].luid == 0) index = 0;+ if (!index) return fail("devices", devices, 14);++ step("select");+ maybeCrash("select", priority);+ if (const int e = select(*index)) return fail("select", e, 15);++ step("stream"); // the call that crashed in issue 88+ maybeCrash("stream", priority);+ void* stream = nullptr;+ if (const int e = createStream(&stream)) return fail("stream", e, 16);++ step("memory");+ maybeCrash("memory", priority);+ void* memory = nullptr;+ if (const int e = allocate(&memory, size_t(1) << 20)) return fail("memory", e, 17);+ if (const int e = clear(memory, 0, size_t(1) << 20, stream)) return fail("memory", e, 17);+ if (const int e = wait(stream)) return fail("memory", e, 17);+ release(memory);++ step("release");+ if (const int e = destroyStream(stream)) return fail("release", e, 18);+ emit("done status=ok");+ // HIP and the device are left to the system: some HIP builds fault in their+ // own unload, which would turn a pass into a crash report.+ TerminateProcess(GetCurrentProcess(), 0);+ return 0;+}++std::vector<int> ladder(int current) {+ if (current < 0) return {0};+ std::vector<int> classes{current};+ if (current > 4) classes.push_back(4);+ if (current > 2) classes.push_back(2);+ return classes;+}++PreflightAttempt parseOutput(const std::string& output, uint32_t exitCode, int priority) {+ PreflightAttempt attempt;+ attempt.priority = priority;+ attempt.exitCode = exitCode;+ bool done = false;+ size_t start = 0;+ while (start < output.size()) {+ const size_t end = std::min(output.find('\n', start), output.size());+ std::string line = output.substr(start, end - start);+ start = end + 1;+ while (!line.empty() && (line.back() == '\r' || line.back() == ' ')) line.pop_back();+ constexpr std::string_view prefix = "amd-hip-preflight ";+ if (line.rfind(prefix, 0) != 0) continue;+ const std::string rest = line.substr(prefix.size());+ if (rest.rfind("step=", 0) == 0) attempt.step = rest.substr(5);+ else if (rest.rfind("info ", 0) == 0) attempt.info += (attempt.info.empty() ? "" : " | ") + rest.substr(5);+ else if (rest == "done status=ok") done = true;+ else if (rest.rfind("crash ", 0) == 0 || rest.rfind("failed ", 0) == 0) attempt.detail = rest;+ }+ attempt.ok = done && exitCode == 0 && attempt.detail.empty();+ if (!attempt.ok && attempt.detail.empty())+ attempt.detail = std::format("ended without a result exit=0x{:08X}", exitCode);+ return attempt;+}++std::string summarize(const std::vector<PreflightAttempt>& attempts) {+ std::string text;+ for (const auto& a : attempts) {+ if (!text.empty()) text += "; ";+ text += a.priority > 0 ? std::format("class {}: ", a.priority) : std::string("default class: ");+ text += a.ok ? std::string("ok") : a.detail + (a.detail.find("step=") == std::string::npos ? " step=" + a.step : std::string());+ }+ return text.empty() ? std::string("not run") : text;+}++void setPreflightExecutable(const std::wstring& path) { std::lock_guard lock(g_mutex); g_executable = path; }+std::wstring preflightExecutable() { std::lock_guard lock(g_mutex); return g_executable; }++PreflightOutcome runLadder(uint64_t adapterLuid, int currentPriority) {+ PreflightOutcome outcome;+ const std::wstring executable = preflightExecutable();+ wchar_t dll[MAX_PATH]{};+ const std::wstring hipDll = GetEnvironmentVariableW(L"VEYRA_TEST_AMD_HIP_DLL", dll, MAX_PATH) ? std::wstring(dll) : std::wstring(L"amdhip64_7.dll");+ for (const int priority : ladder(currentPriority)) {+ const std::wstring command = std::format(L"\"{}\" --amd-hip-preflight \"{}\" {:016X} {}", executable, hipDll, adapterLuid, priority);+ std::string output;+ DWORD exitCode = 0;+ bool timedOut = false;+ PreflightAttempt attempt;+ if (!runChild(executable, command, output, exitCode, timedOut)) {+ attempt.priority = priority;+ attempt.detail = std::format("launch failed win32={}", GetLastError());+ } else {+ attempt = parseOutput(output, exitCode, priority);+ if (timedOut) { attempt.ok = false; attempt.detail = std::format("no result within {} ms", kChildTimeoutMs); }+ }+ veyra::log::info("amd-hip-preflight", std::format("adapter=0x{:016X} class={} result={} step={} exit=0x{:08X} {}{}{}",+ adapterLuid, priority, attempt.ok ? "ok" : "failed", attempt.step.empty() ? "none" : attempt.step, attempt.exitCode, attempt.detail,+ attempt.info.empty() ? "" : " info: ", attempt.info));+ outcome.attempts.push_back(attempt);+ if (attempt.ok) { outcome.ok = true; outcome.priority = priority; break; }+ // A lower class cannot help before HIP is reached (launch, adapter, library).+ if (attempt.step.empty() || attempt.step == "start" || attempt.step == "d3d12" || attempt.step == "load") break;+ }+ outcome.summary = summarize(outcome.attempts);+ return outcome;+}++PreflightOutcome preflightOnce(uint64_t adapterLuid, int currentPriority) {+ static std::mutex runMutex;+ std::lock_guard lock(runMutex);+ {+ std::lock_guard cache(g_mutex);+ if (const auto it = g_outcomes.find(adapterLuid); it != g_outcomes.end()) return it->second;+ }+ auto outcome = runLadder(adapterLuid, currentPriority);+ std::lock_guard cache(g_mutex);+ g_outcomes[adapterLuid] = outcome;+ return outcome;+}+} // namespace veyra::pipeline::amdhipdiff --git a/src/pipeline/LmxxfNrBackend.cpp b/src/pipeline/LmxxfNrBackend.cppindex 870aab31..1fc7abe0 100644--- a/src/pipeline/LmxxfNrBackend.cpp+++ b/src/pipeline/LmxxfNrBackend.cpp@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-3.0-only#include "veyra/pipeline/LmxxfNrBackend.h"#include "veyra/Log.h"+#include "veyra/gfx/GpuSchedulingPriority.h"+#include "veyra/pipeline/AmdHipPreflight.h"#include <atomic>#include <format>#include <algorithm>@@ -68,6 +70,27 @@ bool LmxxfNrBackend::open(const std::filesystem::path& directory, ID3D12Device*log::error("amd-nr",error_);close();return false;};if(!compatibleEnvironment()||!controlsCompatible())return rejectEnvironment();+ // HIP reaches this process only after a child made its first calls on this+ // adapter (AmdHipPreflight.h, issue 88). The class that passed caps this+ // process from here on; when none passed AMD NR stays off instead of crashing.+ if (!amdhip::preflightExecutable().empty()) {+ const LUID adapter = device->GetAdapterLuid();+ const uint64_t luid = (uint64_t(uint32_t(adapter.HighPart)) << 32) | adapter.LowPart;+ const int current = gfx::gpuPriorityStatus().actual;+ const auto outcome = amdhip::preflightOnce(luid, current);+ if (!outcome.ok) {+ error_ = "AMD HIP self-test failed, AMD NR stays off so playback continues (" + outcome.summary ++ "). Update the AMD driver and send this log";+ log::error("amd-nr", error_); close(); return false;+ }+ if (outcome.priority > 0 && current > outcome.priority) {+ gfx::setGpuPriorityComputeCap(gfx::GpuPriority(outcome.priority));+ log::warn("amd-nr", std::format("HIP failed at GPU scheduling class {} and passed at {}; this process stays at {} ({})",+ current, outcome.priority, gfx::gpuPriorityStatus().actual, outcome.summary));+ } else {+ log::info("amd-nr", std::format("HIP self-test passed at GPU scheduling class {} ({})", outcome.priority, outcome.summary));+ }+ }LmxxfNrCreateInfo info{}; info.struct_size = sizeof(info); info.device = device; info.queue = queue;info.assets_directory = assets.c_str(); // flags=0: a failed network is never passed off as NRif (!result(api_.Create(&info, &context_), "Create") || !context_) { close(); return false; }diff --git a/tests/unit/AmdHipPreflightTests.cpp b/tests/unit/AmdHipPreflightTests.cppnew file mode 100644index 00000000..aba5ba86--- /dev/null+++ b/tests/unit/AmdHipPreflightTests.cpp@@ -0,0 +1,134 @@+// Issue 88: the AMD HIP self-test runs in a child, so a HIP fault ends the child+// and not the player, and a class that HIP survives is found before HIP is loaded.+// The child part needs an AMD adapter and VEYRA_TEST_AMD_HIP_DLL (e.g. amdhip64_6.dll).+#include "veyra/gfx/GpuSchedulingPriority.h"+#include "veyra/pipeline/AmdHipPreflight.h"++#include <windows.h>+#include <d3d12.h>+#include <dxgi1_4.h>++#include <iostream>+#include <string>+#include <vector>++using namespace veyra::pipeline::amdhip;++namespace {+bool check(bool condition, const char* message) {+ if (!condition) std::cerr << "FAIL: " << message << '\n';+ return condition;+}+uint64_t firstAmdAdapter() {+ IDXGIFactory1* factory = nullptr;+ if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return 0;+ uint64_t luid = 0;+ IDXGIAdapter1* adapter = nullptr;+ for (UINT i = 0; !luid && factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; ++i) {+ DXGI_ADAPTER_DESC1 desc{};+ adapter->GetDesc1(&desc);+ if (desc.VendorId == 0x1002 && !(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE))+ luid = (uint64_t(uint32_t(desc.AdapterLuid.HighPart)) << 32) | desc.AdapterLuid.LowPart;+ adapter->Release();+ }+ factory->Release();+ return luid;+}+void crashAt(const wchar_t* value) { SetEnvironmentVariableW(L"VEYRA_TEST_AMD_HIP_PREFLIGHT_CRASH", value); }+} // namespace++int wmain(int argc, wchar_t** argv) {+ if (argc >= 2 && wcscmp(argv[1], L"--amd-hip-preflight") == 0) return preflightMain(argc, argv);+ bool ok = true;++ ok &= check(ladder(5) == std::vector<int>{5, 4, 2}, "Realtime tries High, then Normal");+ ok &= check(ladder(4) == std::vector<int>{4, 2}, "High tries Normal");+ ok &= check(ladder(2) == std::vector<int>{2}, "Normal has nothing lower");+ ok &= check(ladder(-1) == std::vector<int>{0}, "an unknown class runs once and leaves the child's class alone");++ auto attempt = parseOutput("amd-hip-preflight start luid=0x1 class=5\namd-hip-preflight info class=5 status=0x00000000\n"+ "amd-hip-preflight step=stream\namd-hip-preflight info runtime=70253211 device=0 arch=gfx1200\namd-hip-preflight step=memory\n"+ "amd-hip-preflight step=release\namd-hip-preflight done status=ok\n", 0, 5);+ ok &= check(attempt.ok && attempt.step == "release" && attempt.detail.empty(), "a finished child passes");+ ok &= check(attempt.info == "class=5 status=0x00000000 | runtime=70253211 device=0 arch=gfx1200", "the child's info lines reach the log");+ attempt = parseOutput("amd-hip-preflight step=stream\r\namd-hip-preflight crash code=0xC0000005 at=amdhip64_7.dll+0x4A40A0 step=stream\r\n", 0xC0000005, 5);+ ok &= check(!attempt.ok && attempt.step == "stream" && attempt.detail.find("amdhip64_7.dll+0x4A40A0") != std::string::npos,+ "a crash keeps the module offset and the step");+ attempt = parseOutput("amd-hip-preflight step=init\namd-hip-preflight failed step=init code=100\n", 13, 4);+ ok &= check(!attempt.ok && attempt.detail == "failed step=init code=100", "a HIP error is reported as it came");+ attempt = parseOutput("amd-hip-preflight step=stream\n", 1, 5);+ ok &= check(!attempt.ok && attempt.detail.rfind("ended without a result", 0) == 0, "a child that never finished fails");+ attempt = parseOutput("amd-hip-preflight done status=ok\n", 0xC0000005, 5);+ ok &= check(!attempt.ok, "a fault after the last line still fails");+ const std::string summary = summarize({parseOutput("amd-hip-preflight step=stream\namd-hip-preflight crash code=0xC0000005 at=x+0x1 step=stream\n", 0xC0000005, 5),+ parseOutput("amd-hip-preflight done status=ok\n", 0, 4)});+ ok &= check(summary == "class 5: crash code=0xC0000005 at=x+0x1 step=stream; class 4: ok", "the summary lists every class tried");++ // The class the self-test chose is what this process really runs at.+ ID3D12Device* device = nullptr; // WDDM schedules a process only once it has a GPU context+ if (SUCCEEDED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device)))) {+ using veyra::gfx::GpuPriority;+ veyra::gfx::requestGpuPriority(GpuPriority::Realtime);+ const int realtime = veyra::gfx::gpuPriorityStatus().actual;+ veyra::gfx::setGpuPriorityComputeCap(GpuPriority::High);+ const auto computeCapped = veyra::gfx::gpuPriorityStatus();+ veyra::gfx::setGpuPriorityCap(GpuPriority::Normal);+ const int bothCaps = veyra::gfx::gpuPriorityStatus().actual;+ veyra::gfx::setGpuPriorityCap(GpuPriority::Realtime);+ veyra::gfx::setGpuPriorityComputeCap(GpuPriority::Realtime);+ const auto lifted = veyra::gfx::gpuPriorityStatus();+ std::cout << "gpu class realtime=" << realtime << " compute-capped=" << computeCapped.actual+ << " both-caps=" << bothCaps << " lifted=" << lifted.actual << '\n';+ ok &= check(realtime == 5 && computeCapped.actual == 4 && computeCapped.capped && computeCapped.requested == GpuPriority::Realtime,+ "the compute cap applies High under a Realtime request");+ ok &= check(bothCaps == 2, "the lower of the overlay cap and the compute cap applies");+ ok &= check(lifted.actual == 5 && !lifted.capped, "lifting both caps restores Realtime");+ device->Release();+ } else {+ std::cout << "SKIP gpu class: no D3D12 device\n";+ }++ const uint64_t luid = firstAmdAdapter();+ wchar_t dll[MAX_PATH]{};+ if (!luid || !GetEnvironmentVariableW(L"VEYRA_TEST_AMD_HIP_DLL", dll, MAX_PATH)) {+ std::cout << "SKIP children: no AMD adapter or VEYRA_TEST_AMD_HIP_DLL\n";+ } else {+ wchar_t self[MAX_PATH]{};+ GetModuleFileNameW(nullptr, self, MAX_PATH);+ ok &= check(preflightExecutable().empty(), "no self-test until a host opts in");+ setPreflightExecutable(self);++ crashAt(nullptr);+ auto outcome = runLadder(luid, 5);+ std::cout << "working HIP: " << outcome.summary << '\n';+ ok &= check(outcome.ok && outcome.priority == 5 && outcome.attempts.size() == 1, "a working HIP passes at the current class");++ crashAt(L"stream:5");+ outcome = runLadder(luid, 5);+ std::cout << "crash at Realtime only: " << outcome.summary << '\n';+ ok &= check(outcome.ok && outcome.priority == 4 && outcome.attempts.size() == 2 &&+ outcome.attempts[0].exitCode == 0xC0000005 && outcome.attempts[0].step == "stream",+ "a stream crash at Realtime is survived and High is chosen");++ crashAt(L"stream:all");+ outcome = runLadder(luid, 5);+ std::cout << "crash at every class: " << outcome.summary << '\n';+ ok &= check(!outcome.ok && outcome.attempts.size() == 3, "a crash at every class refuses HIP");++ crashAt(nullptr);+ const auto first = preflightOnce(luid, 5);+ crashAt(L"stream:all");+ const auto second = preflightOnce(luid, 5);+ ok &= check(first.ok && second.ok && second.summary == first.summary, "one self-test per adapter per process");+ crashAt(nullptr);++ SetEnvironmentVariableW(L"VEYRA_TEST_AMD_HIP_DLL", L"veyra-no-such-hip.dll");+ outcome = runLadder(luid, 5);+ std::cout << "missing library: " << outcome.summary << '\n';+ ok &= check(!outcome.ok && outcome.attempts.size() == 1 && outcome.attempts[0].step == "load",+ "a missing HIP library is not retried at lower classes");+ SetEnvironmentVariableW(L"VEYRA_TEST_AMD_HIP_DLL", dll);+ }+ std::cout << (ok ? "PASS" : "FAIL") << " amd hip preflight\n";+ return ok ? 0 : 1;+}