Skip to content

Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.

C++

feat(ada-mfg): complete the RTX 40 multi-frame port from dashdogy v1.3.3

Veyra Goal Agentaa168abd5075
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
index 2cc16ff4..b31f58de 100644
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@ -153,26 +153,59 @@ before its dispatch), so that validation mode is skipped for the FSR SR
configuration with an explicit log line. See
[AMD FSR frame generation integration record](docs/FSR_FRAMEGEN_INTEGRATION_2026-09-16.md).
-## MFGAdaUnlock-RenoDx (RTX 40 series DLSS multi-frame unlock — ported)
-
-[ImDreamt/MFGAdaUnlock-RenoDx](https://github.com/ImDreamt/MFGAdaUnlock-RenoDx)
-(MIT) is the source of Veyra's RTX 40 series multi-frame unlock. Ported into
-`include/veyra/ngx/AdaMfgUnlock.h` / `src/ngx/AdaMfgUnlock.cpp` and adapted:
-
-- the two architecture compares (`0x1b0` → `0x190`), the kernel PTX midpoint
- correction (inject the temporal parameter, replace the 104 compiled-in `0.5`
- multiplies, truncate the fatbin so the driver JITs the corrected code) and the
- `dlfg_kernel` descriptor redirect are the upstream technique;
-- Veyra adds hard architecture gating (never applied on Blackwell, so RTX 50
- keeps its native path), audited build identity, structural verification of the
- PTX before any write, read-back verification and full rollback when the
- session ends;
-- the upstream Streamline-side hardware flip-metering workaround is **not
- applicable**: Veyra calls NGX directly and does not load Streamline or any
- ReShade/RenoDX add-on. That risk is documented as unverified for Ada.
+## RTX 40 series DLSS multi-frame unlock (ported)
+
+Two upstream projects are ported into `include/veyra/ngx/AdaMfgUnlock.h` /
+`src/ngx/AdaMfgUnlock.cpp`; both are MIT-licensed and are attributed separately.
+
+### ImDreamt/MFGAdaUnlock-RenoDx (initial port)
+
+https://github.com/ImDreamt/MFGAdaUnlock-RenoDx , commit
+`a8aa0d9289471facc1e32013d17fd9c1195bc2cd` (MIT). The initial port brought:
+
+- the two architecture compares (`0x1b0` → `0x190`);
+- the kernel PTX midpoint correction (inject the temporal parameter, replace the
+ 104 compiled-in `0.5` multiplies, truncate the fatbin so the driver JITs the
+ corrected code instead of loading the precompiled cubin);
+- the `dlfg_kernel` descriptor redirect, all process-memory only.
+
+### dashdogy/RTX40MFG-Unlock v1.3.3 (completion port, 2026-09-16)
+
+https://github.com/dashdogy/RTX40MFG-Unlock , commit
+`33b41835dc39c5d8ab1ef93efb2449be31139c09` (v1.3.3, MIT; source tree studied in
+the gitignored `third_party_local/community/RTX40MFG-Unlock`). Ported pieces:
+
+- the provider count/index validator patch from `source/native/ngx_mfg_gate.h`
+ (pattern `84 d2 0f 84 03 01 00 00 be 05 00 00 00`, near-jz head `0f 84` →
+ `eb 04`, whose entry condition gates the accepted generated-frame ceiling on
+ the runtime-detected architecture). This is the documented mechanism behind
+ upstream's v1.3.3 fix for "MFG getting stuck at 2x"; every count, index and
+ profile-limit check after the branch is retained;
+- the three-stage SHA-256 identity chain from `source/native/midpoint_fix.cpp`
+ legacy profile: source fatbin (98408 B) `5A8E0284…`, decompressed PTX
+ (99362 B) `46C05996…`, rebuilt fatbin (127200 B) `19FB3CD5…`, plus the
+ sm_120/sm_89 entry field checks (28024/28017/90490 and 30384/30379/99362).
+ Veyra reproduced the rebuilt-fatbin digest byte-for-byte from its own
+ `runtime_local/nvidia/nvngx_dlssg.dll` 310.7 before porting; the digest is now
+ a publication gate, so a build that does not reproduce the upstream-verified
+ byte stream is refused and fully rolled back.
+
+Veyra adaptations and additions: hard architecture gating (never applied on
+Blackwell, so RTX 50 keeps its native path); the count/index site must match
+uniquely, sit at an even address and branch to the audited `cmp r8d, 1` target
+before any write; all edits happen in the mapped image only (disk file is never
+touched, re-signed or renamed); read-back verification and full rollback when
+the session ends. The rollback path re-opens page protection before restoring
+bytes — negative testing during this port caught that the original Veyra
+rollback path wrote into read-only pages and would have crashed the process on
+a refused kernel fix. The upstream Streamline-side hardware flip-metering /
+pacing workaround and per-title `nvidia_mfg_policy` ceilings are **not
+applicable**: Veyra calls NGX directly and does not load Streamline, ReShade or
+any RenoDX add-on.
Evidence on this machine (RTX 5070, structure and patch mechanics only):
-`logs/fsr/dlssg-unlock-scan.log`, `logs/fsr/dlssg-unlock-applytest.log`.
+`logs/fsr/dlssg-unlock-scan.log`, `logs/fsr/dlssg-unlock-applytest.log`;
+delivery gate `logs/delivery/d0a266a1e549402ca26c2c8ec8d27022/result.json`.
Ada behaviour still has to be verified on RTX 40 hardware.
## dav1d (1.3.0 AV1 playback)
diff --git a/docs/DLSSG_30SERIES_DECISION_2026-09-16.md b/docs/DLSSG_30SERIES_DECISION_2026-09-16.md
index e2f76406..20abaaf5 100644
--- a/docs/DLSSG_30SERIES_DECISION_2026-09-16.md
+++ b/docs/DLSSG_30SERIES_DECISION_2026-09-16.md
@@ -1,16 +1,35 @@
# 30 系(RTX 30)补帧决策(D 工作流,2026-09-16)
+> 2026-09-16 复查更新:用户复核了 `sdli1995/dlssg_for_sm86` 的许可证显示,要求重新核查。
+> 核查结果(`git ls-files` + 仓库目录实测,不是 GitHub 侧栏):该仓库**没有任何 `.c/.cpp/.h`
+> 源码文件,也没有 LICENSE 文件**;`README` 自述 GPLv3、GitHub 由此推断出 GPL-3.0 标签,
+> 但仓库本体只有 18 个 DLL(`version.dll`、`dxgi.dll` 等命名)+ ini + 文档。它是**伪装成
+> 系统 DLL 的代理加载器**:导出表只有 `GetFileVersionInfoW` 一类转发函数加一个
+> `DlssgProxy_Name` 标记,运行时把 DLSSG 调用重定向到 FSR3 补帧。没有源码就没有可搬运对象,
+> 随包分发二进制则等于分发无许可证文本的第三方 DLL——两条都不成立。
+
## 结论
-**不移植 `sdli1995/dlssg_for_sm86`**,也不随包分发它的 DLL。理由不是"做不到",是两条硬约束:
+**不移植 `sdli1995/dlssg_for_sm86`,也不随包分发它的 DLL。** 理由不是"做不到",是两条硬约束:
+
+1. 该仓库**没有源码、没有 LICENSE 文件**(README 自述 GPLv3 但没有随附许可证文本)。
+ 项目规则对无许可证材料的原话是"不得复制代码";二进制同样不作为可搬运对象。
+2. 它的形态是**替换式代理**,本质是把 DLSSG 调用转成 FSR3 帧生成。也就是说:它提供的能力
+ 我们自己**已经有了一个更干净的等价物**——见下。
+
+## dashdogy/RTX40MFG-Unlock 的 30 系实验路径(2026-09-16 评估)
-1. 该仓库 **没有许可证**(GitHub API `license` 为空)。项目规则里对无许可证仓库的原话是
- "不得复制代码",Veyra 又是 GPLv3 发布,不能装看不见。
-2. 它的形态是**替换式 `nvngx_dlssg.dll`**(SM86 专用代理),本质是把 DLSSG 调用转成
- FSR3 帧生成。也就是说:它提供的能力我们自己**已经有了一个合法且更干净的等价物**——见下。
+dashdogy v1.3.3 源码中含有 30 系实验后端(`ampere_backend.cpp`、`ampere_gpu.cpp`、
+`ampere_cuda_program.cpp`、`ampere_native_cache.cpp` 等,MIT)。但 `BUILD.md` 明确写明:
+它需要**单独准备的 "validated SM86 kernel cache"**(`native-cache/`、`native-cache-3109/`、
+`all-provider-layouts/` 三套 fatbin 缓存 + manifest),并原话标注 *"Kernel caches are
+separately prepared build inputs and are not included in this source tree. A source checkout
+alone cannot reproduce the DLL without them."* README 同时标注 30 系支持 *"very early and
+experimental"*、可能完全不工作。这些 kernel cache 是构建输入的二进制 blob,不在公开源码里,
+我们既不伪造也不向第三方索取未公开材料——所以**维持搁置**:30 系不接原生 DLSS MFG 路径。
-同类里唯一许可证明确的是 `Nukem9/dlssg-to-fsr3`(GPL-3.0)。如果将来要做"代理式"方案,
-应当以它为上游(GPL-3.0 与 Veyra 兼容),而不是用无许可证的 sm86 包。
+同类里许可证明确的是 `Nukem9/dlssg-to-fsr3`(GPL-3.0)。如果将来要做"代理式"方案,
+应当以它为上游(GPL-3.0 与 Veyra 兼容),而不是用无源码的 sm86 包。
## 30 系用户现在的 2X 路径
diff --git a/docs/FRAMEGEN_FSR_DOLBY_STATUS_2026-09-16.md b/docs/FRAMEGEN_FSR_DOLBY_STATUS_2026-09-16.md
index 884e3a34..a5e9a77a 100644
--- a/docs/FRAMEGEN_FSR_DOLBY_STATUS_2026-09-16.md
+++ b/docs/FRAMEGEN_FSR_DOLBY_STATUS_2026-09-16.md
@@ -83,8 +83,8 @@ $env:VEYRA_TEST_FG_FORCE_MULTIPLIER='1'
| 项 | 状态 | 说明 / 下一步 |
| --- | --- | --- |
| XeSS 节奏 hook(A-2) | **已移植并实测(`9dd…`:见提交记录)** | present thunk `0x25C0` 接管 + 提供方调度器 `0x21EE30`,只在 >2X 安装、退出回滚。4K/30fps 素材 4X 实测:`refused=0`、同 burst 内间距 mean≈**8.303ms**(目标 33.33/4=8.33ms)、min≈8.14ms、max≈8.42ms,339 真实 / 1005 生成、exit 0;关掉 hook 的对照里 4X 完全没有调度发生。**未移植**:上游时间戳/截止时间层与墙钟回退。顺带修掉 XeSS 2X 静默退回原生呈现的 bug(现在 280 真实 / 276 生成) |
-| 40 系 DLSS MFG 解锁(C-2) | **已实现并提交(`9179449`)** | 移植 `ImDreamt/MFGAdaUnlock-RenoDx`(MIT):两处 `0x1b0` 架构比较改写、PTX 中点修正(注入 temporal 参数 + 104 处 0.5 替换 + fatbin 截断逼 JIT)、8 个 `dlfg_kernel` 槽位重定向,全程进程内、可回滚。本机结构扫描与 `--apply-test` 全部通过(gates=2/descriptors=8/ptx=99362/midpoints=104;`applied=1 readBack=1 restored=1`),50 系 6X 完全不受影响。**行为未验证**:3X/4X 是否真出运动帧、Ada 缺硬件 flip metering 是否冻结,需要 40 系实机 |
-| 30 系原生 2X(D) | **决策:不移植无许可证的上游,改用 FSR 补帧** | `dlssg_for_sm86` 无许可证 → 项目规则禁止复制;它本质是把 DLSSG 代理成 FSR3 补帧,而 Veyra 自己的 FSR 帧生成(E)已经能提供同样的 2X 且厂商无关。详见 [30 系补帧决策](DLSSG_30SERIES_DECISION_2026-09-16.md)。**未验证**:FSR 补帧在 RTX 30 实机上能否运行 |
+| 40 系 DLSS MFG 解锁(C-2 完整版) | **已实现(`9179449` 初版 + 2026-09-16 补齐)** | 两个 MIT 上游合并移植:`ImDreamt/MFGAdaUnlock-RenoDx` 的两处 `0x1b0` 架构比较改写、PTX 中点修正(104 处 0.5 替换 + fatbin 截断逼 JIT)、8 个 `dlfg_kernel` 槽位重定向;`dashdogy/RTX40MFG-Unlock` v1.3.3 的 count/index validator 补丁(v1.3.3 修复"卡 2x"的机制)+ 三段 SHA-256 身份链(source fatbin `5A8E0284…` → PTX `46C05996…` → **重建 fatbin `19FB3CD5…` 与上游逐位一致**)+ sm120/sm89 字段校验。重建 fatbin 哈希作为发布闸:不一致即拒绝并回滚。本机三个场景全过:原版 apply/readBack/restored=1/1/1;篡改 fatbin 1 字节 → 干净拒绝+完整回滚(同时修复了原版回滚路径写只读页的崩溃 bug);篡改 gate 模式 → 预检拒绝。50 系 6X 路径不受影响(Ada 专属门控)。**行为未验证**:3X/4X/6X 是否真出运动帧、Ada 缺硬件 flip metering 是否冻结,需要 40 系实机 |
+| 30 系原生 2X(D) | **决策:搁置(2026-09-16 复查后维持)** | `sdli1995/dlssg_for_sm86` 实测无源码、无 LICENSE 文件(README 自述 GPLv3,GitHub 侧栏标签由此推断),本体是伪装 DLL 的代理加载器;dashdogy v1.3.3 的 30 系实验路径依赖**不在公开源码树里的 SM86 kernel cache**(BUILD.md 原话"source checkout alone cannot reproduce the DLL"),无法合法复现。30 系用户走 Veyra 自带 FSR 帧生成(E)。详见 [30 系补帧决策](DLSSG_30SERIES_DECISION_2026-09-16.md)。**未验证**:FSR 补帧在 RTX 30 实机上能否运行 |
| FSR 帧生成(E) | **已完成并实测(2X)** | 见上文 §一.5 与 [接入记录](FSR_FRAMEGEN_INTEGRATION_2026-09-16.md);4.0.1 ML 需 AMD 卡复测 |
| FSR 超分(F) | **已接入并实测(3.1.x)** | 图内 SR 阶段新分支 + `videoSrQuality=5` 档位;播放器 205–226 次 dispatch 0 失败,AMD 光流形状 exit 0,同帧对照平均绝对差 0.31/255;**相对画质略软(梯度能量比 0.888)如实记录**;4.x ML 需 AMD 实机。见 [FSR 超分接入记录](FSR_UPSCALING_PLAN_2026-09-16.md) |
| 杜比直通 / 解码(G-2) | **解码兜底已实现并本地验证(`56bb0f6`)** | FFmpeg 解码 AC-3/E-AC-3(含 DD+ Atmos 载体)/DTS/DTS-HD,IEC 61937 解框;采集端在无 PCM 可用时按优先级走位流直通并解码进既有 5.1 管线。本地用真实 AC-3/E-AC-3 位流验证了 6 声道与幅度映射。**未验证**:真实位流采集卡协商(本机设备不提供位流)、TrueHD/DTS-HD 无真实素材 |
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index d3c06c00..7e14b1bf 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -13,6 +13,20 @@
未完成(如实记录):XeSS 节奏 hook(`XeFGPacing`)未移植、>2X 生成帧间距未测量;40 系 DLSS MFG 解锁(RenoDX 的架构比较 + PTX 中点修正 + flip metering)未实现;30 系原生 2X 未开始;AMD FSR(帧生成 4.0.x / 超分)未开始(SDK 2.3.0 未下载);杜比直通/解码未实现。完整状态、验收清单与边界见 [隔离分支施工状态](FRAMEGEN_FSR_DOLBY_STATUS_2026-09-16.md)。未合并 main、未推送、未发布。
+### 2026-09-16 40 系 6X 完整移植(用户要求"能加一起加了")
+
+用户指出上一轮对 40 系上游的审计过粗,要求重新研究并把 dashdogy 项目里能加的实现合并进产品。复核与施工记录:
+
+- **重新审计(逐仓库打开原文,不看 GitHub 侧栏)**:`sdli1995/dlssg_for_sm86` 实测**无任何 `.c/.cpp/.h` 源码、无 LICENSE 文件**(`git ls-files` 只有 18 个 DLL + ini + 文档;README 自述 GPLv3 但无许可证文本),本体是伪装系统 DLL 的代理加载器。真正含源码的 40 系上游是 `dashdogy/RTX40MFG-Unlock`(MIT,v1.3.3,commit `33b41835dc39c5d8ab1ef93efb2449be31139c09`,143 个源文件),我们此前的 C-2 只搬了其中一部分。
+- **缺口一:`ngx_mfg_gate` count/index validator 补丁**(`source/native/ngx_mfg_gate.h`)。pattern `84 d2 0f 84 03 01 00 00 be 05 00 00 00`(`test dl,dl / jz / mov esi,5`),近跳头 `0f 84` → `eb 04` 强制走 `mov esi,5`。这是上游 v1.3.3 changelog "Fixed MFG getting stuck at 2x and related freezing, flickering and black screens" 的直接机制之一。Veyra 的 310.7 构建里该 pattern **唯一匹配**(文件偏移 0x64b42 / RVA 0x65742),jz 目标 `41 83 f8 01` 校验通过,但此前完全没有打这个补丁。
+- **缺口二:三段 SHA-256 身份链 + 结构字段校验**(`source/native/midpoint_fix.cpp` legacy profile)。source fatbin(98408 B)`5A8E0284…`、解压 PTX(99362 B)`46C05996…`、重建 fatbin(127200 B)`19FB3CD5…`,外加 sm120/sm89 条目字段(28024/28017/90490、30384/30379/99362/0x2041)。我们此前的校验只有 PE 时间戳 + PTX 长度。
+- **哈希复现(决定性证据)**:用 `out/build/ptx_patch_digest.py` 从本地 `runtime_local/nvidia/nvngx_dlssg.dll` 复现重建流程,输出完整 fatbin SHA256 = `19FB3CD5500BFD1FC88F96C36B381E096D6AB1DFC7B1DB02A04D40A00849104B`,与上游 profile 记录**逐位一致**。上一轮报告"输出哈希不一致"是拿补丁后 PTX 的哈希(`44FEF743…`)去比全 fatbin 哈希(`19FB3CD5…`)——比错了对象,本次更正。
+- **实现**(`include/veyra/ngx/AdaMfgUnlock.h` / `src/ngx/AdaMfgUnlock.cpp`):新增 mfg gate 补丁点(唯一匹配 + 偶地址 + 分支目标 `cmp r8d,1` 三重校验,VirtualProtect 写 + FlushInstructionCache,失败整体回滚);三段 BCrypt SHA-256 闸(source fatbin → PTX → 重建 fatbin;**重建哈希作为发布闸,与上游字节流不一致即拒绝并回滚**);sm120/sm89 字段校验;`distinctFatbins` 统计(本机=1,8 个 descriptor 指向同一 fatbin)。`scan/State` 字段、探针、`EnhanceGraph` 预检与日志同步更新;UI 侧保留现有 1/3/5 能力驱动逻辑(`nvidia_mfg_policy` 语义一致)。
+- **负向测试抓出一个既有崩溃 bug**:kernel fix 被拒绝时的回滚路径直接向只读页写回原字节(无 VirtualProtect),触发即 ACCESS_VIOLATION(0xC0000005)。修复为 VirtualProtect→写→恢复保护。该路径此前从未被执行过(原 probe 只测成功路径),修复后三场景全部干净。
+- **本机证据(RTX 5070,结构 + 补丁机制,非 40 系行为)**:原版 `--apply-test` → `applied=1 readBack=1 restored=1`,gates=2 / mfgGate=1(1) / descriptors=8;篡改 fatbin 1 字节 → `kernel fix refused: source fatbin SHA-256 does not match` + 完整回滚,无崩溃,exit 1;篡改 gate pattern → 预检拒绝 exit 1。delivery 短测 PASS(`logs/delivery/d0a266a1e549402ca26c2c8ec8d27022/result.json`)。
+- **30 系**:复查后维持搁置。dashdogy v1.3.3 有 30 系实验路径,但 `BUILD.md` 原文写明依赖**不在源码树的 validated SM86 kernel cache**("A source checkout alone cannot reproduce the DLL without them");`sdli1995` 无源码不可搬。决策文档与 notices 已更新。
+- **未验证**:40 系实机行为(6X 真实插帧质量、Ada 缺硬件 flip metering 的冻结风险)仍需用户实机验收;XeSS/FSR/杜比各项边界与上一段一致。
+
## 2026-09-15 采集卡直播窗口标题修复(第三方工具“识别不到 Veyra”)
用户反馈除 OBS 外各平台直播工具无法识别“正在采集中的 Veyra”,且顺序敏感:先抓到窗口再开采集卡正常,先开采集卡再抓就抓不到。实机取证确认根因是 Veyra 自己:采集卡来源 `capture:`/`capture2:` 连接串被当文件名写进主窗口标题,实测标题长 776 字符(`Veyra — capture2:<十六进制设备路径>:...`),空闲/播放文件时为正常短名;直播伴侣日志把该标题截断到 259 字符后参与来源命名,其包内前端以 `${exe} ${title}` 命名来源。同场会话的 mediasdk_server 日志显示“采集卡已运行再添加 game 来源”的 hook 通路实际成功(`Load Shared Texture Success, size: 842 x 494`、`OnAutoSwitchMode from Window to Game`、GameSource 连续 60 秒以上有数据),因此本轮不做换链/画面的猜测性改动。
diff --git a/include/veyra/ngx/AdaMfgUnlock.h b/include/veyra/ngx/AdaMfgUnlock.h
index 2eeb673b..2295a675 100644
--- a/include/veyra/ngx/AdaMfgUnlock.h
+++ b/include/veyra/ngx/AdaMfgUnlock.h
@@ -29,6 +29,17 @@ namespace veyra::ngx {
// kernel's own temporal parameter, and the fatbin is truncated after that
// PTX entry so the driver JITs the corrected code instead of loading the
// precompiled cubin.
+// 4. the DLSS-G provider's count/index validator (ported from
+// dashdogy/RTX40MFG-Unlock v1.3.3 ngx_mfg_gate) gates the accepted
+// numFramesToGenerate on the runtime-detected arch; without it Ada can
+// advertise multi-frame and still refuse to generate more than one frame.
+//
+// Identity is verified in three SHA-256 steps against the audited 310.7 build,
+// mirroring the upstream midpoint_fix profiles:
+// source fatbin (98408 B) -> decompressed PTX (99362 B) -> rebuilt fatbin
+// (127200 B). The rebuilt-form digest is the publication gate: the patched
+// image must match the upstream-verified byte stream exactly before the
+// descriptor is redirected, otherwise everything rolls back.
//
// Safety rules baked in:
// - never applied on Blackwell (50 series keeps its native path untouched);
@@ -50,12 +61,28 @@ public:
static constexpr size_t kMaxArchGateSites = 4;
static constexpr uint32_t kAdaArchId = 0x190u; // NVAPI arch id, Ada
static constexpr uint32_t kBlackwellArchId = 0x1B0u;
+ // Audited fatbin identity (dashdogy/RTX40MFG-Unlock v1.3.3 legacy profile,
+ // MIT; hashes reproduced byte-for-byte against runtime_local 310.7).
+ static constexpr uint64_t kExpectedSourceFatbinBytes = 98408ull;
+ static constexpr uint64_t kExpectedRebuiltFatbinBytes = 127200ull;
+ static constexpr const char* kExpectedSourceFatbinSha256 =
+ "5A8E0284AAB8AC14FC82B0504BBEEF25D2FCE1D13A1C11D8BDB3F91FEE8145FC";
+ static constexpr const char* kExpectedSourcePtxSha256 =
+ "46C05996A2EF199BBE39378681734ED5EE757655DE70410D9900D85BA91222F1";
+ static constexpr const char* kExpectedRebuiltFatbinSha256 =
+ "19FB3CD5500BFD1FC88F96C36B381E096D6AB1DFC7B1DB02A04D40A00849104B";
+ // The count/index validator pattern is expected exactly once in the
+ // audited build; a different count is a refusal, not a guess.
+ static constexpr size_t kExpectedMfgGateSites = 1;
struct Scan {
bool moduleValid = false;
bool identityMatched = false;
size_t archGateSites = 0;
+ size_t mfgGateSites = 0;
+ bool mfgGateValid = false;
size_t descriptorSlots = 0;
+ size_t distinctFatbins = 0;
uint64_t ptxBytes = 0;
size_t midpointCount = 0;
bool joinLabelUnique = false;
@@ -68,7 +95,9 @@ public:
bool applied = false;
bool archGatesPatched = false;
bool kernelPatched = false;
+ bool mfgGatePatched = false;
size_t archGateSites = 0;
+ size_t mfgGateSites = 0;
size_t descriptorSlots = 0;
std::wstring detail;
};
diff --git a/src/ngx/AdaMfgUnlock.cpp b/src/ngx/AdaMfgUnlock.cpp
index 802047f6..1ae9d1c6 100644
--- a/src/ngx/AdaMfgUnlock.cpp
+++ b/src/ngx/AdaMfgUnlock.cpp
@@ -2,6 +2,10 @@
#include "veyra/Log.h"
+#include <bcrypt.h>
+
+#include <algorithm>
+#include <array>
#include <cstring>
#include <filesystem>
#include <mutex>
@@ -19,6 +23,19 @@ constexpr size_t kEntryNameOffset = 0x10;
constexpr size_t kDescriptorNameOffset = 0x28;
constexpr char kDescriptorName[] = "dlfg_kernel";
constexpr char kEntryName[] = "main_kernel";
+// Audited fatbin layout of nvngx_dlssg.dll 310.7 (dashdogy legacy profile):
+// outer header (16) + sm_120 entry (hdr 104 + payload 28024 = 28128), then the
+// sm_89 PTX entry at offset 28144 whose payload is 30384 bytes (30379
+// compressed) and decompresses to the 99362-byte audited PTX.
+constexpr size_t kSm120EntryOffset = kOuterHeader;
+constexpr uint32_t kEntryHeaderBytes = 104;
+constexpr uint64_t kSm120PayloadBytes = 28024ull;
+constexpr uint32_t kSm120CompressedBytes = 28017u;
+constexpr uint64_t kSm120RawBytes = 90490ull;
+constexpr uint64_t kSm89PayloadBytes = 30384ull;
+constexpr uint32_t kSm89CompressedBytes = 30379u;
+constexpr uint64_t kCompressedFlags = 0x2041ull;
+constexpr size_t kSm89EntryOffset = kSm120EntryOffset + kEntryHeaderBytes + kSm120PayloadBytes;
constexpr char kJoinLabel[] = "$L__BB0_3:";
constexpr char kMidpointBits[] = "0f3F000000";
constexpr char kMulPrefix[] = "mul.ftz.f32 ";
@@ -31,11 +48,57 @@ constexpr char kTemporalInput[] =
"ld.param.f32 %f134, [main_kernel_param_0+32];\r\n"
"mov.f32 %f135, 0f3F800000;\r\n"
"sub.ftz.f32 %f136, %f135, %f134;\r\n";
+// dashdogy/RTX40MFG-Unlock v1.3.3 ngx_mfg_gate (MIT), byte-for-byte pattern of
+// the provider's count/index validator in the audited 310.7 build:
+// test dl, dl ; jz <cmp r8d,1 path> ; mov esi, 5
+// Patching the near-jz head to "jmp +4" skips the remaining displacement bytes
+// and falls into mov esi,5 unconditionally, restoring on Ada the multi-frame
+// count ceiling the provider only applies on Blackwell. Every count, index and
+// profile-limit check after this branch is retained.
+constexpr uint8_t kMfgGatePattern[] = {
+ 0x84, 0xd2, 0x0f, 0x84, 0x03, 0x01, 0x00, 0x00, 0xbe, 0x05, 0x00, 0x00, 0x00};
+constexpr size_t kMfgGatePatternSize = sizeof(kMfgGatePattern);
+constexpr size_t kMfgGateJumpOffset = 2;
+constexpr uint8_t kMfgGateOriginal[2] = {0x0f, 0x84};
+constexpr uint8_t kMfgGateReplacement[2] = {0xeb, 0x04};
+constexpr uint8_t kMfgGateTargetCheck[4] = {0x41, 0x83, 0xf8, 0x01}; // cmp r8d, 1
uint16_t readU16(const uint8_t* p) { uint16_t v; std::memcpy(&v, p, 2); return v; }
uint32_t readU32(const uint8_t* p) { uint32_t v; std::memcpy(&v, p, 4); return v; }
uint64_t readU64(const uint8_t* p) { uint64_t v; std::memcpy(&v, p, 8); return v; }
+// Uppercase SHA-256 comparison via the platform BCrypt (no new dependency;
+// veyra_base already links bcrypt). Used for the three identity gates ported
+// from the upstream midpoint_fix profiles.
+bool sha256Equals(const uint8_t* bytes, size_t count, const char* expected) {
+ if (bytes == nullptr || count == 0 || count > ULONG_MAX || expected == nullptr ||
+ std::strlen(expected) != 64) {
+ return false;
+ }
+ BCRYPT_ALG_HANDLE algorithm = nullptr;
+ std::array<uint8_t, 32> digest{};
+ NTSTATUS status = BCryptOpenAlgorithmProvider(&algorithm, BCRYPT_SHA256_ALGORITHM, nullptr, 0);
+ if (status >= 0) {
+ status = BCryptHash(algorithm, nullptr, 0, const_cast<PUCHAR>(bytes),
+ static_cast<ULONG>(count), digest.data(),
+ static_cast<ULONG>(digest.size()));
+ }
+ if (algorithm != nullptr) {
+ BCryptCloseAlgorithmProvider(algorithm, 0);
+ }
+ if (status < 0) {
+ return false;
+ }
+ static constexpr char kDigits[] = "0123456789ABCDEF";
+ for (size_t index = 0; index < digest.size(); ++index) {
+ if (expected[index * 2] != kDigits[digest[index] >> 4] ||
+ expected[index * 2 + 1] != kDigits[digest[index] & 0x0F]) {
+ return false;
+ }
+ }
+ return true;
+}
+
// Plain LZ4 block format, as emitted by the CUDA fatbin packer.
bool lz4BlockDecompress(const uint8_t* src, size_t srcSize, uint8_t* dst, size_t dstSize) {
size_t in = 0, out = 0;
@@ -183,21 +246,46 @@ PtxFacts inspectPtx(const uint8_t* fat, size_t entry, std::vector<uint8_t>& ptx)
// Rebuild the fatbin with the temporal fix applied. Returns false with a reason
// whenever the structure is not exactly what the audited build has.
bool buildTemporalFatbin(const uint8_t* fat, size_t fatSize, std::vector<uint8_t>& out, std::string& why) {
+ // Structural identity first: the audited 310.7 fatbin has a fixed layout
+ // and byte-exact hashes (mirrors the upstream TemporalProviderProfile).
+ if (fatSize != AdaMfgUnlock::kExpectedSourceFatbinBytes ||
+ readU32(fat) != kFatbinMagic || readU16(fat + 6) != kOuterHeader ||
+ readU64(fat + 8) + kOuterHeader != fatSize) {
+ why = "fatbin outer header does not match the audited layout";
+ return false;
+ }
+ const uint8_t* sm120 = fat + kSm120EntryOffset;
+ if (readU16(sm120) != kPtxKind || readU32(sm120 + 4) != kEntryHeaderBytes ||
+ readU64(sm120 + 8) != kSm120PayloadBytes ||
+ readU32(sm120 + 16) != kSm120CompressedBytes ||
+ readU32(sm120 + 28) != 120u || readU64(sm120 + 40) != kCompressedFlags ||
+ readU64(sm120 + 56) != kSm120RawBytes) {
+ why = "sm_120 entry does not match the audited fatbin layout";
+ return false;
+ }
size_t entry = 0;
if (!findSm89PtxEntry(fat, fatSize, entry)) {
why = "no sm_89 PTX entry in the fatbin";
return false;
}
+ if (entry != kSm89EntryOffset) {
+ why = "sm_89 entry is at offset " + std::to_string(entry) + ", expected " +
+ std::to_string(kSm89EntryOffset);
+ return false;
+ }
const uint32_t hdr = readU32(fat + entry + 4);
const uint32_t compressed = readU32(fat + entry + 16);
const uint64_t raw = readU64(fat + entry + 56);
- if (compressed == 0 || raw == 0 || raw > (8u << 20)) {
- why = "PTX entry is not compressed as expected";
+ if (readU16(fat + entry) != kPtxKind || hdr != kEntryHeaderBytes ||
+ readU64(fat + entry + 8) != kSm89PayloadBytes ||
+ compressed != kSm89CompressedBytes || readU32(fat + entry + 28) != kSm89Arch ||
+ readU64(fat + entry + 40) != kCompressedFlags ||
+ raw != AdaMfgUnlock::kExpectedPtxBytes) {
+ why = "sm_89 entry does not match the audited fatbin layout";
return false;
}
- if (raw != AdaMfgUnlock::kExpectedPtxBytes) {
- why = "PTX is " + std::to_string(raw) + " bytes, expected " +
- std::to_string(AdaMfgUnlock::kExpectedPtxBytes);
+ if (!sha256Equals(fat, fatSize, AdaMfgUnlock::kExpectedSourceFatbinSha256)) {
+ why = "source fatbin SHA-256 does not match the audited runtime";
return false;
}
// static_cast, not size_t(raw): "T x(U(y))" is a function declaration.
@@ -206,6 +294,10 @@ bool buildTemporalFatbin(const uint8_t* fat, size_t fatSize, std::vector<uint8_t
why = "LZ4 decompression failed";
return false;
}
+ if (!sha256Equals(ptx.data(), ptx.size(), AdaMfgUnlock::kExpectedSourcePtxSha256)) {
+ why = "decompressed PTX SHA-256 does not match the audited runtime";
+ return false;
+ }
const char* begin = reinterpret_cast<const char*>(ptx.data());
const size_t n = ptx.size();
const size_t labelLen = sizeof(kJoinLabel) - 1;
@@ -273,6 +365,13 @@ bool buildTemporalFatbin(const uint8_t* fat, size_t fatSize, std::vector<uint8_t
std::memcpy(out.data() + entry + 56, &zero64, 8);
const uint64_t outer = finalSize - kOuterHeader;
std::memcpy(out.data() + 8, &outer, 8);
+ // Publication gate: the rebuilt image must equal the upstream-verified
+ // byte stream exactly, or nothing is published and the caller rolls back.
+ if (out.size() != AdaMfgUnlock::kExpectedRebuiltFatbinBytes ||
+ !sha256Equals(out.data(), out.size(), AdaMfgUnlock::kExpectedRebuiltFatbinSha256)) {
+ why = "rebuilt fatbin does not match the upstream-verified byte stream";
+ return false;
+ }
return true;
}
@@ -282,6 +381,11 @@ struct GlobalState {
bool installed = false;
std::vector<std::pair<unsigned char*, unsigned char>> gateSites;
std::vector<std::pair<uint64_t*, uint64_t>> descriptorSlots;
+ struct MfgGateRecord {
+ uint8_t* jump = nullptr;
+ std::array<uint8_t, 2> original{};
+ };
+ std::vector<MfgGateRecord> mfgGateWrites;
void* kernelAllocation = nullptr;
};
@@ -290,6 +394,54 @@ GlobalState& global() {
return instance;
}
+// Count/index validator site (see kMfgGatePattern). Ambiguity is a refusal.
+struct MfgGateSite {
+ uint8_t* match = nullptr;
+ uint8_t* jump = nullptr;
+};
+
+bool mfgGateMatches(const uint8_t* p) {
+ return std::memcmp(p, kMfgGatePattern, 2) == 0 &&
+ (std::memcmp(p + kMfgGateJumpOffset, kMfgGateOriginal, 2) == 0 ||
+ std::memcmp(p + kMfgGateJumpOffset, kMfgGateReplacement, 2) == 0) &&
+ std::memcmp(p + 4, kMfgGatePattern + 4, kMfgGatePatternSize - 4) == 0;
+}
+
+bool findMfgGateSite(uint8_t* base, const IMAGE_NT_HEADERS64* nt, MfgGateSite& site,
+ size_t& matchCount) {
+ matchCount = 0;
+ uint8_t* found = nullptr;
+ const auto* section = IMAGE_FIRST_SECTION(nt);
+ for (WORD i = 0; i < nt->FileHeader.NumberOfSections; ++i, ++section) {
+ if ((section->Characteristics & IMAGE_SCN_MEM_EXECUTE) == 0) continue;
+ uint8_t* begin = base + section->VirtualAddress;
+ const size_t size = section->Misc.VirtualSize;
+ if (size < kMfgGatePatternSize) continue;
+ for (size_t off = 0; off + kMfgGatePatternSize <= size; ++off) {
+ if (!mfgGateMatches(begin + off)) continue;
+ ++matchCount;
+ found = begin + off;
+ }
+ }
+ if (matchCount != 1 || found == nullptr) return false;
+ // Upstream requires the patched pair at an even address (atomic publication
+ // precondition) and the branch target to be the audited "cmp r8d, 1" path.
+ if ((reinterpret_cast<uintptr_t>(found + kMfgGateJumpOffset) & 1u) != 0) return false;
+ int32_t displacement = 0;
+ std::memcpy(&displacement, found + 4, 4);
+ const auto imageStart = reinterpret_cast<uintptr_t>(base);
+ const size_t imageSize = nt->OptionalHeader.SizeOfImage;
+ const uintptr_t target = reinterpret_cast<uintptr_t>(found) + 8 + static_cast<intptr_t>(displacement);
+ if (target < imageStart || target + sizeof(kMfgGateTargetCheck) > imageStart + imageSize) return false;
+ if (std::memcmp(reinterpret_cast<const void*>(target), kMfgGateTargetCheck,
+ sizeof(kMfgGateTargetCheck)) != 0) {
+ return false;
+ }
+ site.match = found;
+ site.jump = found + kMfgGateJumpOffset;
+ return true;
+}
+
void patchGateSites(uint8_t* base, const IMAGE_NT_HEADERS64* nt,
std::vector<std::pair<unsigned char*, unsigned char>>& sites) {
const auto* section = IMAGE_FIRST_SECTION(nt);
@@ -361,6 +513,15 @@ AdaMfgUnlock::Scan AdaMfgUnlock::scan(HMODULE module) {
const auto hits = findDescriptors(base, nt);
result.descriptorSlots = hits.size();
+ {
+ std::vector<const uint8_t*> fatbins;
+ for (const auto& hit : hits) {
+ if (std::find(fatbins.begin(), fatbins.end(), hit.fatbin) == fatbins.end()) {
+ fatbins.push_back(hit.fatbin);
+ }
+ }
+ result.distinctFatbins = fatbins.size();
+ }
if (!hits.empty()) {
size_t entry = 0;
if (findSm89PtxEntry(hits.front().fatbin, hits.front().fatbinSize, entry)) {
@@ -371,8 +532,13 @@ AdaMfgUnlock::Scan AdaMfgUnlock::scan(HMODULE module) {
result.joinLabelUnique = facts.joinLabelCount == 1;
}
}
- result.detail = "gates=" + std::to_string(result.archGateSites) + " slots=" +
- std::to_string(result.descriptorSlots) + " ptx=" + std::to_string(result.ptxBytes) +
+ MfgGateSite mfgGate{};
+ result.mfgGateValid = findMfgGateSite(base, nt, mfgGate, result.mfgGateSites);
+ result.detail = "gates=" + std::to_string(result.archGateSites) + " mfgGate=" +
+ std::to_string(result.mfgGateSites) + " mfgGateValid=" +
+ (result.mfgGateValid ? "1" : "0") + " slots=" +
+ std::to_string(result.descriptorSlots) + " fatbins=" +
+ std::to_string(result.distinctFatbins) + " ptx=" + std::to_string(result.ptxBytes) +
" midpoints=" + std::to_string(result.midpointCount) +
" joinLabelUnique=" + (result.joinLabelUnique ? "1" : "0");
return result;
@@ -410,6 +576,26 @@ AdaMfgUnlock::State AdaMfgUnlock::apply(HMODULE module, bool includeKernelFix) {
state.identityVerified = nt->OptionalHeader.SizeOfImage == kKnownSizeOfImage &&
nt->FileHeader.TimeDateStamp == kKnownTimeDateStamp;
+ auto rollbackGates = [&]() {
+ for (const auto& site : g.gateSites) {
+ DWORD oldProtect = 0;
+ if (VirtualProtect(site.first, 1, PAGE_EXECUTE_READWRITE, &oldProtect) == 0) continue;
+ *site.first = site.second;
+ DWORD ignored = 0;
+ VirtualProtect(site.first, 1, oldProtect, &ignored);
+ }
+ g.gateSites.clear();
+ for (const auto& write : g.mfgGateWrites) {
+ DWORD oldProtect = 0;
+ if (VirtualProtect(write.jump, 2, PAGE_EXECUTE_READWRITE, &oldProtect) == 0) continue;
+ std::memcpy(write.jump, write.original.data(), 2);
+ FlushInstructionCache(GetCurrentProcess(), write.jump, 2);
+ DWORD ignored = 0;
+ VirtualProtect(write.jump, 2, oldProtect, &ignored);
+ }
+ g.mfgGateWrites.clear();
+ };
+
// Architecture gates first: without both of them the runtime advertises
// multi-frame and then renders black.
patchGateSites(base, nt, g.gateSites);
@@ -417,23 +603,62 @@ AdaMfgUnlock::State AdaMfgUnlock::apply(HMODULE module, bool includeKernelFix) {
state.archGatesPatched = state.archGateSites >= kMinArchGateSites &&
state.archGateSites <= kMaxArchGateSites;
if (!state.archGatesPatched) {
- for (const auto& site : g.gateSites) *site.first = site.second;
- g.gateSites.clear();
+ rollbackGates();
state.detail = std::format(L"arch-gate site count {} outside the audited range {}-{}; runtime left untouched",
state.archGateSites, kMinArchGateSites, kMaxArchGateSites);
g.state = state;
return state;
}
+ // Provider count/index validator (dashdogy v1.3.3 ngx_mfg_gate): without
+ // this, Ada can advertise 6X and still refuse to generate beyond one frame.
+ MfgGateSite mfgGate{};
+ size_t mfgGateMatches = 0;
+ const bool mfgGateFound = findMfgGateSite(base, nt, mfgGate, mfgGateMatches);
+ state.mfgGateSites = mfgGateMatches;
+ if (!mfgGateFound || mfgGateMatches != kExpectedMfgGateSites) {
+ rollbackGates();
+ state.archGatesPatched = false;
+ state.detail = std::format(L"count/index validator: {} site(s) found, valid={}; exactly {} expected; runtime left untouched",
+ mfgGateMatches, mfgGateFound ? 1 : 0, kExpectedMfgGateSites);
+ g.state = state;
+ return state;
+ }
+ std::array<uint8_t, 2> mfgGateOriginal{};
+ std::memcpy(mfgGateOriginal.data(), mfgGate.jump, 2);
+ if (std::memcmp(mfgGateOriginal.data(), kMfgGateOriginal, 2) != 0) {
+ rollbackGates();
+ state.archGatesPatched = false;
+ state.detail = L"count/index validator carries foreign bytes; runtime left untouched";
+ g.state = state;
+ return state;
+ }
+ {
+ DWORD oldProtect = 0;
+ if (VirtualProtect(mfgGate.jump, 2, PAGE_EXECUTE_READWRITE, &oldProtect) == 0) {
+ rollbackGates();
+ state.archGatesPatched = false;
+ state.detail = L"count/index validator page is not writable; runtime left untouched";
+ g.state = state;
+ return state;
+ }
+ std::memcpy(mfgGate.jump, kMfgGateReplacement, 2);
+ FlushInstructionCache(GetCurrentProcess(), mfgGate.jump, 2);
+ DWORD ignored = 0;
+ VirtualProtect(mfgGate.jump, 2, oldProtect, &ignored);
+ }
+ g.mfgGateWrites.push_back({mfgGate.jump, mfgGateOriginal});
+ state.mfgGatePatched = true;
+
if (includeKernelFix) {
const auto hits = findDescriptors(base, nt);
state.descriptorSlots = hits.size();
std::vector<uint8_t> rebuilt;
std::string why;
if (hits.empty() || !buildTemporalFatbin(hits.front().fatbin, hits.front().fatbinSize, rebuilt, why)) {
- for (const auto& site : g.gateSites) *site.first = site.second;
- g.gateSites.clear();
+ rollbackGates();
state.archGatesPatched = false;
+ state.mfgGatePatched = false;
state.detail = std::format(L"kernel fix refused: {}; arch gates rolled back, runtime left untouched",
std::wstring(why.begin(), why.end()));
g.state = state;
@@ -441,9 +666,9 @@ AdaMfgUnlock::State AdaMfgUnlock::apply(HMODULE module, bool includeKernelFix) {
}
void* mem = VirtualAlloc(nullptr, rebuilt.size(), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (mem == nullptr) {
- for (const auto& site : g.gateSites) *site.first = site.second;
- g.gateSites.clear();
+ rollbackGates();
state.archGatesPatched = false;
+ state.mfgGatePatched = false;
state.detail = L"kernel allocation failed; arch gates rolled back";
g.state = state;
return state;
@@ -459,9 +684,9 @@ AdaMfgUnlock::State AdaMfgUnlock::apply(HMODULE module, bool includeKernelFix) {
}
if (g.descriptorSlots.empty()) {
VirtualFree(mem, 0, MEM_RELEASE);
- for (const auto& site : g.gateSites) *site.first = site.second;
- g.gateSites.clear();
+ rollbackGates();
state.archGatesPatched = false;
+ state.mfgGatePatched = false;
state.detail = L"no dlfg_kernel descriptor slot was writable; arch gates rolled back";
g.state = state;
return state;
@@ -471,13 +696,15 @@ AdaMfgUnlock::State AdaMfgUnlock::apply(HMODULE module, bool includeKernelFix) {
}
g.installed = true;
- state.applied = state.archGatesPatched && state.kernelPatched;
- state.detail = std::format(L"gates={} descriptors={} kernel={} (in-memory only)",
- state.archGateSites, state.descriptorSlots,
+ state.applied = state.archGatesPatched && state.mfgGatePatched && state.kernelPatched;
+ state.detail = std::format(L"gates={} mfgGate={} descriptors={} kernel={} (in-memory only)",
+ state.archGateSites, state.mfgGatePatched ? 1 : 0,
+ state.descriptorSlots,
state.kernelPatched ? L"temporal-fixed" : L"untouched");
g.state = state;
- veyra::log::info("ada-mfg", std::format("Ada multi-frame unlock: {} gate(s), {} descriptor slot(s), kernel={}, identityVerified={}",
- state.archGateSites, state.descriptorSlots,
+ veyra::log::info("ada-mfg", std::format("Ada multi-frame unlock: {} gate(s), count/index gate={}, {} descriptor slot(s), kernel={}, identityVerified={}",
+ state.archGateSites, state.mfgGatePatched ? 1 : 0,
+ state.descriptorSlots,
state.kernelPatched ? 1 : 0, state.identityVerified ? 1 : 0));
return state;
}
@@ -485,7 +712,9 @@ AdaMfgUnlock::State AdaMfgUnlock::apply(HMODULE module, bool includeKernelFix) {
void AdaMfgUnlock::release() {
auto& g = global();
std::lock_guard lock(g.mutex);
- if (!g.installed && g.gateSites.empty() && g.descriptorSlots.empty()) return;
+ if (!g.installed && g.gateSites.empty() && g.descriptorSlots.empty() && g.mfgGateWrites.empty()) {
+ return;
+ }
for (const auto& slot : g.descriptorSlots) {
DWORD oldProtect = 0;
if (VirtualProtect(slot.first, 8, PAGE_READWRITE, &oldProtect) == 0) continue;
@@ -506,6 +735,15 @@ void AdaMfgUnlock::release() {
VirtualProtect(site.first, 1, oldProtect, &ignored);
}
g.gateSites.clear();
+ for (const auto& write : g.mfgGateWrites) {
+ DWORD oldProtect = 0;
+ if (VirtualProtect(write.jump, 2, PAGE_EXECUTE_READWRITE, &oldProtect) == 0) continue;
+ std::memcpy(write.jump, write.original.data(), 2);
+ FlushInstructionCache(GetCurrentProcess(), write.jump, 2);
+ DWORD ignored = 0;
+ VirtualProtect(write.jump, 2, oldProtect, &ignored);
+ }
+ g.mfgGateWrites.clear();
g.installed = false;
g.state = State{};
veyra::log::info("ada-mfg", "Ada multi-frame unlock rolled back (runtime image restored)");
diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cpp
index 81baa37f..221c806a 100644
--- a/src/pipeline/EnhanceGraph.cpp
+++ b/src/pipeline/EnhanceGraph.cpp
@@ -422,7 +422,9 @@ void EnhanceGraph::applyAdaMfgUnlock()
}
const auto scan = ngx::AdaMfgUnlock::scan(module);
if (!scan.moduleValid || scan.archGateSites < ngx::AdaMfgUnlock::kMinArchGateSites ||
- scan.archGateSites > ngx::AdaMfgUnlock::kMaxArchGateSites || scan.descriptorSlots == 0 ||
+ scan.archGateSites > ngx::AdaMfgUnlock::kMaxArchGateSites ||
+ scan.mfgGateSites != ngx::AdaMfgUnlock::kExpectedMfgGateSites || !scan.mfgGateValid ||
+ scan.descriptorSlots == 0 ||
scan.ptxBytes != ngx::AdaMfgUnlock::kExpectedPtxBytes ||
scan.midpointCount != ngx::AdaMfgUnlock::kExpectedMidpoints || !scan.joinLabelUnique) {
veyra::log::warn("ada-mfg", std::format("unlock refused: runtime build does not match the audited structure ({})",
@@ -430,9 +432,10 @@ void EnhanceGraph::applyAdaMfgUnlock()
return;
}
const auto state = ngx::AdaMfgUnlock::apply(module, true);
- veyra::log::info("ada-mfg", std::format("adapter deviceId=0x{:04X} unlock applied={} gates={} descriptors={} kernel={} ({})",
+ veyra::log::info("ada-mfg", std::format("adapter deviceId=0x{:04X} unlock applied={} gates={} mfgGate={} descriptors={} kernel={} ({})",
adapter.deviceId, state.applied ? 1 : 0, state.archGateSites,
- state.descriptorSlots, state.kernelPatched ? 1 : 0,
+ state.mfgGatePatched ? 1 : 0, state.descriptorSlots,
+ state.kernelPatched ? 1 : 0,
std::string(state.detail.begin(), state.detail.end())));
}
diff --git a/tools/dlssg_unlock_probe/main.cpp b/tools/dlssg_unlock_probe/main.cpp
index 96e4a1b2..fffb19f8 100644
--- a/tools/dlssg_unlock_probe/main.cpp
+++ b/tools/dlssg_unlock_probe/main.cpp
@@ -61,10 +61,13 @@ int wmain(int argc, wchar_t** argv) {
veyra::ngx::AdaMfgUnlock::kKnownTimeDateStamp, veyra::ngx::AdaMfgUnlock::kKnownSizeOfImage);
const auto scan = veyra::ngx::AdaMfgUnlock::scan(module);
- std::printf("[dlssg-unlock] scan: valid=%d identity=%d gateSites=%llu descriptors=%llu ptx=%llu midpoints=%llu joinLabelUnique=%d\n",
+ std::printf("[dlssg-unlock] scan: valid=%d identity=%d gateSites=%llu mfgGateSites=%llu mfgGateValid=%d descriptors=%llu distinctFatbins=%llu ptx=%llu midpoints=%llu joinLabelUnique=%d\n",
scan.moduleValid ? 1 : 0, scan.identityMatched ? 1 : 0,
static_cast<unsigned long long>(scan.archGateSites),
+ static_cast<unsigned long long>(scan.mfgGateSites),
+ scan.mfgGateValid ? 1 : 0,
static_cast<unsigned long long>(scan.descriptorSlots),
+ static_cast<unsigned long long>(scan.distinctFatbins),
static_cast<unsigned long long>(scan.ptxBytes),
static_cast<unsigned long long>(scan.midpointCount),
scan.joinLabelUnique ? 1 : 0);
@@ -72,6 +75,8 @@ int wmain(int argc, wchar_t** argv) {
const bool structureOk = scan.moduleValid && scan.archGateSites >= veyra::ngx::AdaMfgUnlock::kMinArchGateSites &&
scan.archGateSites <= veyra::ngx::AdaMfgUnlock::kMaxArchGateSites &&
+ scan.mfgGateSites == veyra::ngx::AdaMfgUnlock::kExpectedMfgGateSites &&
+ scan.mfgGateValid &&
scan.descriptorSlots > 0 && scan.ptxBytes == veyra::ngx::AdaMfgUnlock::kExpectedPtxBytes &&
scan.midpointCount == veyra::ngx::AdaMfgUnlock::kExpectedMidpoints &&
scan.joinLabelUnique;
@@ -88,29 +93,40 @@ int wmain(int argc, wchar_t** argv) {
}
const auto applied = veyra::ngx::AdaMfgUnlock::apply(module, true);
- std::printf("[dlssg-unlock] apply: applied=%d gates=%d(%llu) kernel=%d descriptors=%llu detail=%s\n",
+ std::printf("[dlssg-unlock] apply: applied=%d gates=%d(%llu) mfgGate=%d(%llu) kernel=%d descriptors=%llu detail=%s\n",
applied.applied ? 1 : 0, applied.archGatesPatched ? 1 : 0,
- static_cast<unsigned long long>(applied.archGateSites), applied.kernelPatched ? 1 : 0,
+ static_cast<unsigned long long>(applied.archGateSites),
+ applied.mfgGatePatched ? 1 : 0,
+ static_cast<unsigned long long>(applied.mfgGateSites), applied.kernelPatched ? 1 : 0,
static_cast<unsigned long long>(applied.descriptorSlots), toUtf8(applied.detail).c_str());
// Read-back: the gate bytes must now read 0x90 and the descriptors must point
// at the rebuilt fatbin, so a second scan sees zero gates and no matching
- // descriptor any more (the rebuilt one is uncompressed).
+ // descriptor any more (the rebuilt one is uncompressed). The count/index
+ // validator scan must still find its unique site, now carrying the patched
+ // jump, and report it as valid.
const auto afterApply = veyra::ngx::AdaMfgUnlock::scan(module);
- std::printf("[dlssg-unlock] post-apply scan: gateSites=%llu descriptors=%llu ptx=%llu detail=%s\n",
+ std::printf("[dlssg-unlock] post-apply scan: gateSites=%llu mfgGateSites=%llu mfgGateValid=%d descriptors=%llu ptx=%llu detail=%s\n",
static_cast<unsigned long long>(afterApply.archGateSites),
+ static_cast<unsigned long long>(afterApply.mfgGateSites),
+ afterApply.mfgGateValid ? 1 : 0,
static_cast<unsigned long long>(afterApply.descriptorSlots),
static_cast<unsigned long long>(afterApply.ptxBytes), afterApply.detail.c_str());
- const bool readBack = applied.applied && afterApply.archGateSites == 0;
+ const bool readBack = applied.applied && afterApply.archGateSites == 0 &&
+ afterApply.mfgGateSites == 1 && afterApply.mfgGateValid;
veyra::ngx::AdaMfgUnlock::release();
const auto afterRelease = veyra::ngx::AdaMfgUnlock::scan(module);
- std::printf("[dlssg-unlock] post-release scan: gateSites=%llu descriptors=%llu ptx=%llu midpoints=%llu\n",
+ std::printf("[dlssg-unlock] post-release scan: gateSites=%llu mfgGateSites=%llu mfgGateValid=%d descriptors=%llu ptx=%llu midpoints=%llu\n",
static_cast<unsigned long long>(afterRelease.archGateSites),
+ static_cast<unsigned long long>(afterRelease.mfgGateSites),
+ afterRelease.mfgGateValid ? 1 : 0,
static_cast<unsigned long long>(afterRelease.descriptorSlots),
static_cast<unsigned long long>(afterRelease.ptxBytes),
static_cast<unsigned long long>(afterRelease.midpointCount));
const bool restored = afterRelease.archGateSites == scan.archGateSites &&
+ afterRelease.mfgGateSites == scan.mfgGateSites &&
+ afterRelease.mfgGateValid == scan.mfgGateValid &&
afterRelease.descriptorSlots == scan.descriptorSlots &&
afterRelease.ptxBytes == scan.ptxBytes;
std::printf("[dlssg-unlock] applied=%d readBack=%d restored=%d\n", applied.applied ? 1 : 0, readBack ? 1 : 0,