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): RTX 40 series DLSS multi-frame unlock (ported, structure + mechanics verified)

Veyra Goal Agent9179449197f1
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4ba208a3..48ab9d5b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -113,6 +113,7 @@ add_library(veyra_ngx STATIC
src/ngx/DlssSrBackend.cpp
src/ngx/VideoSrBackend.cpp
src/ngx/DlssFgBackend.cpp
+ src/ngx/AdaMfgUnlock.cpp
)
veyra_apply_warnings(veyra_ngx)
target_compile_features(veyra_ngx PUBLIC cxx_std_20)
@@ -125,6 +126,14 @@ add_library(veyra_ngx STATIC
"$<IF:$<CONFIG:Debug>,${VEYRA_DLSS_SDK_ROOT}/lib/Windows_x86_64/x64/nvsdk_ngx_s_dbg.lib,${VEYRA_DLSS_SDK_ROOT}/lib/Windows_x86_64/x64/nvsdk_ngx_s.lib>")
target_compile_definitions(veyra_ngx PUBLIC
VEYRA_EXPERIMENTAL_LOCAL_DLSSNR=1)
+
+ # Diagnostic: exercises the Ada multi-frame unlock against the local DLSS-G
+ # runtime image without involving NGX (works on any NVIDIA adapter).
+ add_executable(veyra_dlssg_unlock_probe tools/dlssg_unlock_probe/main.cpp)
+ target_compile_features(veyra_dlssg_unlock_probe PRIVATE cxx_std_20)
+ target_compile_options(veyra_dlssg_unlock_probe PRIVATE /utf-8 /WX-)
+ target_compile_definitions(veyra_dlssg_unlock_probe PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN UNICODE _UNICODE)
+ target_link_libraries(veyra_dlssg_unlock_probe PRIVATE veyra_ngx)
endif()
add_executable(veyra_runtime_probe
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
index 6a390344..2cc16ff4 100644
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@ -153,18 +153,27 @@ 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 (research only, not integrated)
+## MFGAdaUnlock-RenoDx (RTX 40 series DLSS multi-frame unlock — ported)
[ImDreamt/MFGAdaUnlock-RenoDx](https://github.com/ImDreamt/MFGAdaUnlock-RenoDx)
-(MIT) was cloned into the gitignored `third_party_local/community/` tree and
-read as the reference for unlocking DLSS multi-frame generation on RTX 40
-series. **No code from it is integrated, and Veyra does not load ReShade
-add-ons.** The mechanism analysis (two architecture compares against 0x1b0, the
-kernel PTX midpoint correction, fatbin truncation to force JIT, and the
-hardware flip-metering requirement) is summarised in
-[the 40-series research note](docs/WORKLOG.md). Any future port must be an
-independent in-memory implementation with module identity checks, pattern
-verification and rollback.
+(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.
+
+Evidence on this machine (RTX 5070, structure and patch mechanics only):
+`logs/fsr/dlssg-unlock-scan.log`, `logs/fsr/dlssg-unlock-applytest.log`.
+Ada behaviour still has to be verified on RTX 40 hardware.
## dav1d (1.3.0 AV1 playback)
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index 46eb3335..e5c521f9 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -2343,6 +2343,35 @@ DLSSG 能力门控没有排除 FSR,导致 FSR 会话下任何就地设置变
### 2026-09-16 FSR 超分接入产品(同一分支,未合并 main)
+### 2026-09-16 40 系 DLSS MFG 解锁(C-2)实现 + 本机结构/补丁机制验证
+
+移植 `ImDreamt/MFGAdaUnlock-RenoDx`(MIT,`third_party_local/community/`)到产品库
+`include/veyra/ngx/AdaMfgUnlock.h` + `src/ngx/AdaMfgUnlock.cpp`:两处 `0x1b0`(Blackwell) 架构比较
+改写为 `0x190`(Ada)、PTX 中点修正(注入 temporal 参数 + 104 处 `mul.ftz.f32 ...,0f3F000000`
+替换为 `%f136/%f134` + fatbin 截断为非压缩强制 JIT)、8 个 `dlfg_kernel` 描述符槽位重定向;
+全部只改进程内映射镜像,磁盘文件不动、不重签名;失败即回滚。
+
+本机 RTX 5070(Blackwell)只做**结构与补丁机制**验证,不做行为验证:
+
+- `veyra_dlssg_unlock_probe`(默认只读扫描):本机 `runtime_local/nvidia/nvngx_dlssg.dll`
+ 310.7.0.0 / SHA256 `135EAF07…E36F`,TimeDateStamp `0x69FB633C`、SizeOfImage `0x00745000` 与审计身份一致;
+ 扫描得到 **gates=2、descriptors=8、ptx=99362、midpoints=104、joinLabelUnique=1**——与上游全部结构假设逐一吻合
+ (`logs/fsr/dlssg-unlock-scan.log`)。
+- `--apply-test`:应用后回读 gates=0、descriptors=0(槽位已指向重建 fatbin),随后
+ `release()` 回滚回 gates=2/descriptors=8/ptx=99362/midpoints=104,`applied=1 readBack=1 restored=1`
+ → 事务与回滚机制在真实运行库镜像上成立(`logs/fsr/dlssg-unlock-applytest.log`)。
+- 引擎接入:`EnhanceGraph::initNgxFeatures()` 在 DLSSG 能力查询前按
+ `AdaMfgUnlock::adapterIsAda(vendor, deviceId)`(0x10DE 且 deviceId 在 0x2680–0x28FF)决定是否解锁,
+ 50 系直接不进入;`VEYRA_DISABLE_ADA_MFG_UNLOCK=1` 可关闭;`shutdown()` 里在 NGX core 释放后回滚。
+ 解锁后运行时若仍只报 1 张生成帧,会明确告警"当前 DLSS-G 不是审计过的本地版本"。
+- **50 系不受影响实测**:`--fg-multiplier 6` 仍为 `multiFrameMax=5`、875 生成/177 真实、exit 0,
+ 日志里**没有任何** `ada-mfg` 行(门控直接跳过)(`logs/fsr/blackwell-6x-after-ada-unlock.log`)。
+
+**未验证(必须 40 系实机)**:解锁后 3X/4X 是否真的生成并带真实运动;Ada 上 Blackwell 硬件
+flip metering 缺失是否导致画面冻结(上游在 Streamline 侧有软件回退,我们直接走 NGX,没有那一层)。
+测试命令:`veyra.exe --fg-multiplier 4 --smoke-seconds 15 <视频>`,期望日志出现
+`[ada-mfg] ... unlock applied=1 gates=2 descriptors=8 kernel=1` 与 `multiFrameMax=5`。
+
先前的"只做可行性"结论已升级为**已接入并实测**:
- 新增 `include/veyra/gfx/FsrSrBackend.h` + `src/gfx/FsrSrBackend.cpp`(FidelityFX 超分上下文 +
diff --git a/include/veyra/gfx/D3D12DeviceContext.h b/include/veyra/gfx/D3D12DeviceContext.h
index 1db76c63..f3bb1f3e 100644
--- a/include/veyra/gfx/D3D12DeviceContext.h
+++ b/include/veyra/gfx/D3D12DeviceContext.h
@@ -17,6 +17,7 @@ using ComPtr = Microsoft::WRL::ComPtr<T>;
struct AdapterInfo {
std::wstring description;
uint32_t vendorId = 0;
+ uint32_t deviceId = 0; // PCI device id, e.g. 0x2684 = AD102
std::string vendorIdHex; // "0x10DE"
std::string luidString; // "0xHigh:0xLow"
uint64_t dedicatedVideoMemoryBytes = 0;
diff --git a/include/veyra/ngx/AdaMfgUnlock.h b/include/veyra/ngx/AdaMfgUnlock.h
new file mode 100644
index 00000000..2eeb673b
--- /dev/null
+++ b/include/veyra/ngx/AdaMfgUnlock.h
@@ -0,0 +1,102 @@
+#pragma once
+
+#include <windows.h>
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+namespace veyra::ngx {
+
+// Process-memory unlock for DLSS multi-frame generation (3X/4X/6X) on RTX 40
+// series, where NVIDIA gates it to RTX 50.
+//
+// Ported from ImDreamt/MFGAdaUnlock-RenoDx (MIT) — itself an independent
+// implementation of the technique published by dashdogy/RTX40MFG-Unlock — and
+// adapted for Veyra: the whole edit is applied to the already-mapped image,
+// nothing on disk is touched or re-signed, every site is pattern-verified
+// before a write and fully rolled back when the session ends.
+//
+// Two independent gates and one kernel fix are required; each is verified
+// against the local runtime build before anything is written:
+// 1. DLSSGInstanceManager::PopulateParameters compares the NVAPI arch id
+// against 0x1b0 (Blackwell) to decide what MultiFrameCountMax it reports;
+// 2. a second compare against the same constant feeds the runtime capability
+// flag that actually drives generation (patching only (1) renders black);
+// 3. the interpolation kernel blends with a compiled-in 0.5, so every
+// generated frame lands at the temporal midpoint (frames repeat). The PTX
+// is decompressed, the 104 midpoint multiplies are replaced with the
+// 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.
+//
+// Safety rules baked in:
+// - never applied on Blackwell (50 series keeps its native path untouched);
+// - refuses when the arch-gate site count or the PTX structure does not match
+// the audited expectations, with the reason logged instead of guessing.
+class AdaMfgUnlock {
+public:
+ // Audited runtime identity (runtime_local/nvidia/nvngx_dlssg.dll 310.7.0.0).
+ static constexpr uint64_t kKnownModuleSize = 7519856ull;
+ static constexpr const char* kKnownModuleSha256 =
+ "135EAF0733C1E37381A8C28ABCF7A862404A54132B81787C04E35D09EFC5E36F";
+ static constexpr uint32_t kKnownTimeDateStamp = 0x69FB633Cu;
+ static constexpr uint32_t kKnownSizeOfImage = 0x00745000u;
+ // Structural expectations inside the runtime (verified locally before any
+ // write; a mismatch is a refusal, not a guess).
+ static constexpr uint64_t kExpectedPtxBytes = 99362ull;
+ static constexpr size_t kExpectedMidpoints = 104;
+ static constexpr size_t kMinArchGateSites = 1;
+ static constexpr size_t kMaxArchGateSites = 4;
+ static constexpr uint32_t kAdaArchId = 0x190u; // NVAPI arch id, Ada
+ static constexpr uint32_t kBlackwellArchId = 0x1B0u;
+
+ struct Scan {
+ bool moduleValid = false;
+ bool identityMatched = false;
+ size_t archGateSites = 0;
+ size_t descriptorSlots = 0;
+ uint64_t ptxBytes = 0;
+ size_t midpointCount = 0;
+ bool joinLabelUnique = false;
+ std::string detail;
+ };
+
+ struct State {
+ bool moduleFound = false;
+ bool identityVerified = false;
+ bool applied = false;
+ bool archGatesPatched = false;
+ bool kernelPatched = false;
+ size_t archGateSites = 0;
+ size_t descriptorSlots = 0;
+ std::wstring detail;
+ };
+
+ // Read-only structural report; never writes. Used by the probe and by the
+ // engine before deciding to apply.
+ static Scan scan(HMODULE module);
+
+ // True when the adapter is in the Ada device-id window AND the runtime still
+ // reports the gated ceiling (1 generated frame). Blackwell is refused here
+ // even if a caller asks.
+ static bool adapterIsAda(uint32_t vendorId, uint32_t deviceId);
+
+ // Installs both patches into the mapped image. `includeKernelFix` should be
+ // true for any real use: without it multi-frame output repeats.
+ static State apply(HMODULE module, bool includeKernelFix);
+
+ // Restores every patched byte and frees the rebuilt fatbin. Safe to call
+ // repeatedly and when nothing was applied.
+ static void release();
+
+ static State snapshot();
+ static bool applied();
+ // Read-only identity check against the audited runtime.
+ static bool moduleIsAudited(const std::wstring& path);
+
+private:
+ struct Impl;
+};
+
+} // namespace veyra::ngx
diff --git a/include/veyra/pipeline/EnhanceGraph.h b/include/veyra/pipeline/EnhanceGraph.h
index 7ef94b90..76f42394 100644
--- a/include/veyra/pipeline/EnhanceGraph.h
+++ b/include/veyra/pipeline/EnhanceGraph.h
@@ -258,6 +258,9 @@ private:
bool initNvof();
bool initNgxFeatures();
bool initFsrSr();
+ // RTX 40 series: opens the Blackwell-only multi-frame gate in the mapped
+ // DLSS-G runtime. Never touched on any other architecture.
+ void applyAdaMfgUnlock();
bool createComputePasses();
gfx::D3D12DeviceContext& context_;
diff --git a/src/gfx/D3D12DeviceContext.cpp b/src/gfx/D3D12DeviceContext.cpp
index 1ebfc1e8..349b1546 100644
--- a/src/gfx/D3D12DeviceContext.cpp
+++ b/src/gfx/D3D12DeviceContext.cpp
@@ -100,6 +100,7 @@ bool fillAdapterInfo(const DXGI_ADAPTER_DESC1& desc, AdapterInfo& info)
static_cast<uint64_t>(desc.AdapterLuid.LowPart));
info.dedicatedVideoMemoryBytes = desc.DedicatedVideoMemory;
info.isNvidia = desc.VendorId == 0x10DE;
+ info.deviceId = desc.DeviceId;
info.isSoftware = (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0;
info.driverVersion = info.isNvidia?queryNvidiaDriverVersion():std::wstring{};
info.driverVersionSource = info.driverVersion.empty() ? L"unavailable" : L"registry";
diff --git a/src/ngx/AdaMfgUnlock.cpp b/src/ngx/AdaMfgUnlock.cpp
new file mode 100644
index 00000000..802047f6
--- /dev/null
+++ b/src/ngx/AdaMfgUnlock.cpp
@@ -0,0 +1,535 @@
+#include "veyra/ngx/AdaMfgUnlock.h"
+
+#include "veyra/Log.h"
+
+#include <cstring>
+#include <filesystem>
+#include <mutex>
+#include <vector>
+
+namespace veyra::ngx {
+namespace {
+
+constexpr uint32_t kFatbinMagic = 0xBA55ED50u;
+constexpr size_t kOuterHeader = 16;
+constexpr uint32_t kPtxKind = 1;
+constexpr uint32_t kSm89Arch = 89;
+constexpr uint64_t kUncompressedFlags = 0x41;
+constexpr size_t kEntryNameOffset = 0x10;
+constexpr size_t kDescriptorNameOffset = 0x28;
+constexpr char kDescriptorName[] = "dlfg_kernel";
+constexpr char kEntryName[] = "main_kernel";
+constexpr char kJoinLabel[] = "$L__BB0_3:";
+constexpr char kMidpointBits[] = "0f3F000000";
+constexpr char kMulPrefix[] = "mul.ftz.f32 ";
+constexpr char kCurrToPrev[] = "%f136"; // 1 - t, current -> previous half
+constexpr char kPrevToCurr[] = "%f134"; // t, previous -> current half
+// Injected right after the unique join label. Registers %f134/%f135/%f136 are
+// dead after that point in the audited build (verified: zero uses after the
+// label, and the build recomputes the same values earlier).
+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";
+
+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; }
+
+// 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;
+ while (in < srcSize) {
+ const uint8_t token = src[in++];
+ size_t literals = token >> 4;
+ if (literals == 15) {
+ uint8_t ext = 0;
+ do {
+ if (in >= srcSize) return false;
+ ext = src[in++];
+ literals += ext;
+ } while (ext == 0xFF);
+ }
+ if (literals > srcSize - in || literals > dstSize - out) return false;
+ std::memcpy(dst + out, src + in, literals);
+ in += literals;
+ out += literals;
+ if (in == srcSize) break;
+ if (srcSize - in < 2) return false;
+ const size_t back = size_t(src[in]) | (size_t(src[in + 1]) << 8);
+ in += 2;
+ if (back == 0 || back > out) return false;
+ size_t match = 4 + (token & 0x0F);
+ if ((token & 0x0F) == 15) {
+ uint8_t ext = 0;
+ do {
+ if (in >= srcSize) return false;
+ ext = src[in++];
+ match += ext;
+ } while (ext == 0xFF);
+ }
+ if (match > dstSize - out) return false;
+ for (size_t i = 0; i < match; ++i) dst[out + i] = dst[out + i - back];
+ out += match;
+ }
+ return in == srcSize && out == dstSize;
+}
+
+bool findSm89PtxEntry(const uint8_t* fat, size_t fatSize, size_t& entryOffset) {
+ if (fatSize < kOuterHeader || readU32(fat) != kFatbinMagic) return false;
+ if (readU16(fat + 6) != kOuterHeader) return false;
+ if (readU64(fat + 8) + kOuterHeader != fatSize) return false;
+ size_t p = kOuterHeader;
+ while (p + 64 <= fatSize) {
+ const uint32_t kind = readU16(fat + p);
+ const uint32_t hdr = readU32(fat + p + 4);
+ const uint64_t payload = readU64(fat + p + 8);
+ if (hdr < 64 || payload == 0 || p + hdr + payload > fatSize) return false;
+ if (kind == kPtxKind && readU32(fat + p + 28) == kSm89Arch) {
+ entryOffset = p;
+ return true;
+ }
+ p += hdr + payload;
+ }
+ return false;
+}
+
+bool pointsToCString(const uint8_t* base, size_t imageSize, uint64_t value, const char* expected) {
+ const auto start = reinterpret_cast<uintptr_t>(base);
+ if (value < start || value >= start + imageSize) return false;
+ const size_t len = std::strlen(expected);
+ if (value + len + 1 > start + imageSize) return false;
+ return std::memcmp(reinterpret_cast<const void*>(value), expected, len + 1) == 0;
+}
+
+struct DescriptorHit {
+ uint64_t* slot = nullptr;
+ const uint8_t* fatbin = nullptr;
+ size_t fatbinSize = 0;
+};
+
+// Walks the read-only, non-executable sections for dlfg_kernel descriptors whose
+// fatbin carries the audited temporal PTX.
+std::vector<DescriptorHit> findDescriptors(uint8_t* base, const IMAGE_NT_HEADERS64* nt) {
+ std::vector<DescriptorHit> hits;
+ const size_t imageSize = nt->OptionalHeader.SizeOfImage;
+ const auto imageStart = reinterpret_cast<uintptr_t>(base);
+ const auto* section = IMAGE_FIRST_SECTION(nt);
+ for (WORD i = 0; i < nt->FileHeader.NumberOfSections; ++i, ++section) {
+ if ((section->Characteristics & IMAGE_SCN_MEM_READ) == 0) continue;
+ if ((section->Characteristics & IMAGE_SCN_MEM_EXECUTE) != 0) continue;
+ uint8_t* sec = base + section->VirtualAddress;
+ const size_t size = section->Misc.VirtualSize;
+ if (size < kDescriptorNameOffset + 8) continue;
+ for (size_t off = 0; off + kDescriptorNameOffset + 8 <= size; off += 8) {
+ uint64_t value = 0;
+ std::memcpy(&value, sec + off, 8);
+ if (value < imageStart || value >= imageStart + imageSize) continue;
+ const auto* candidate = reinterpret_cast<const uint8_t*>(value);
+ if (readU32(candidate) != kFatbinMagic) continue;
+ uint64_t entryName = 0, descName = 0;
+ std::memcpy(&entryName, sec + off + kEntryNameOffset, 8);
+ std::memcpy(&descName, sec + off + kDescriptorNameOffset, 8);
+ if (!pointsToCString(base, imageSize, entryName, kEntryName)) continue;
+ if (!pointsToCString(base, imageSize, descName, kDescriptorName)) continue;
+ const size_t total = size_t(readU64(candidate + 8)) + kOuterHeader;
+ if (total < 1024 || total > (16u << 20)) continue;
+ if (value + total > imageStart + imageSize) continue;
+ size_t entry = 0;
+ if (!findSm89PtxEntry(candidate, total, entry)) continue;
+ if (readU64(candidate + entry + 56) != AdaMfgUnlock::kExpectedPtxBytes) continue;
+ hits.push_back({reinterpret_cast<uint64_t*>(sec + off), candidate, total});
+ }
+ }
+ return hits;
+}
+
+struct PtxFacts {
+ bool decompressed = false;
+ size_t midpointCount = 0;
+ size_t joinLabelCount = 0;
+ size_t usesAfterInjection[3] = {0, 0, 0};
+};
+
+PtxFacts inspectPtx(const uint8_t* fat, size_t entry, std::vector<uint8_t>& ptx) {
+ PtxFacts facts{};
+ 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 != AdaMfgUnlock::kExpectedPtxBytes) return facts;
+ ptx.assign(size_t(raw), 0);
+ if (!lz4BlockDecompress(fat + entry + hdr, compressed, ptx.data(), ptx.size())) {
+ ptx.clear();
+ return facts;
+ }
+ facts.decompressed = true;
+ const char* begin = reinterpret_cast<const char*>(ptx.data());
+ const size_t n = ptx.size();
+ for (size_t i = 0; i + sizeof(kJoinLabel) - 1 <= n; ++i) {
+ if (std::memcmp(begin + i, kJoinLabel, sizeof(kJoinLabel) - 1) == 0) ++facts.joinLabelCount;
+ }
+ for (size_t i = 0; i + sizeof(kMidpointBits) - 1 < n; ++i) {
+ if (std::memcmp(begin + i, kMidpointBits, sizeof(kMidpointBits) - 1) != 0) continue;
+ if (begin[i + sizeof(kMidpointBits) - 1] != ';') continue;
+ size_t line = i;
+ while (line > 0 && begin[line - 1] != '\n') --line;
+ if (i - line < sizeof(kMulPrefix) - 1) continue;
+ if (std::memcmp(begin + line, kMulPrefix, sizeof(kMulPrefix) - 1) != 0) continue;
+ ++facts.midpointCount;
+ }
+ return facts;
+}
+
+// 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) {
+ size_t entry = 0;
+ if (!findSm89PtxEntry(fat, fatSize, entry)) {
+ why = "no sm_89 PTX entry in the fatbin";
+ 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";
+ return false;
+ }
+ if (raw != AdaMfgUnlock::kExpectedPtxBytes) {
+ why = "PTX is " + std::to_string(raw) + " bytes, expected " +
+ std::to_string(AdaMfgUnlock::kExpectedPtxBytes);
+ return false;
+ }
+ // static_cast, not size_t(raw): "T x(U(y))" is a function declaration.
+ std::vector<uint8_t> ptx(static_cast<size_t>(raw), uint8_t{0});
+ if (!lz4BlockDecompress(fat + entry + hdr, compressed, ptx.data(), ptx.size())) {
+ why = "LZ4 decompression failed";
+ return false;
+ }
+ const char* begin = reinterpret_cast<const char*>(ptx.data());
+ const size_t n = ptx.size();
+ const size_t labelLen = sizeof(kJoinLabel) - 1;
+ size_t label = SIZE_MAX;
+ for (size_t i = 0; i + labelLen <= n; ++i) {
+ if (std::memcmp(begin + i, kJoinLabel, labelLen) != 0) continue;
+ if (label != SIZE_MAX) { why = "join label is not unique"; return false; }
+ label = i;
+ }
+ if (label == SIZE_MAX) { why = "join label not found"; return false; }
+ size_t insertion = label + labelLen;
+ while (insertion < n && begin[insertion] != '\n') ++insertion;
+ if (insertion >= n) { why = "join label has no line end"; return false; }
+ ++insertion;
+
+ const size_t midLen = sizeof(kMidpointBits) - 1;
+ const size_t mulLen = sizeof(kMulPrefix) - 1;
+ std::vector<size_t> marks;
+ marks.reserve(AdaMfgUnlock::kExpectedMidpoints);
+ for (size_t i = 0; i + midLen < n; ++i) {
+ if (std::memcmp(begin + i, kMidpointBits, midLen) != 0) continue;
+ if (begin[i + midLen] != ';') continue;
+ size_t line = i;
+ while (line > 0 && begin[line - 1] != '\n') --line;
+ if (i - line < mulLen) continue;
+ if (std::memcmp(begin + line, kMulPrefix, mulLen) != 0) continue;
+ marks.push_back(i);
+ }
+ if (marks.size() != AdaMfgUnlock::kExpectedMidpoints) {
+ why = "found " + std::to_string(marks.size()) + " midpoint multiplies, expected " +
+ std::to_string(AdaMfgUnlock::kExpectedMidpoints);
+ return false;
+ }
+ if (marks.front() <= insertion) { why = "first midpoint precedes the injection point"; return false; }
+
+ std::vector<uint8_t> patched;
+ patched.reserve(n + sizeof(kTemporalInput));
+ auto append = [&patched](const void* p, size_t bytes) {
+ const auto* b = static_cast<const uint8_t*>(p);
+ patched.insert(patched.end(), b, b + bytes);
+ };
+ append(ptx.data(), insertion);
+ append(kTemporalInput, sizeof(kTemporalInput) - 1);
+ size_t src = insertion;
+ const size_t half = AdaMfgUnlock::kExpectedMidpoints / 2;
+ for (size_t i = 0; i < marks.size(); ++i) {
+ append(ptx.data() + src, marks[i] - src);
+ const char* scale = (i < half) ? kCurrToPrev : kPrevToCurr;
+ append(scale, 5);
+ src = marks[i] + midLen;
+ }
+ append(ptx.data() + src, n - src);
+
+ const size_t padded = (patched.size() + 7) & ~size_t{7};
+ const size_t finalSize = entry + hdr + padded;
+ out.assign(fat, fat + entry + hdr);
+ out.resize(finalSize, 0);
+ std::memcpy(out.data() + entry + hdr, patched.data(), patched.size());
+ const uint64_t payload64 = padded;
+ const uint32_t zero32 = 0;
+ const uint64_t zero64 = 0;
+ std::memcpy(out.data() + entry + 8, &payload64, 8);
+ std::memcpy(out.data() + entry + 16, &zero32, 4);
+ std::memcpy(out.data() + entry + 40, &kUncompressedFlags, 4);
+ std::memcpy(out.data() + entry + 56, &zero64, 8);
+ const uint64_t outer = finalSize - kOuterHeader;
+ std::memcpy(out.data() + 8, &outer, 8);
+ return true;
+}
+
+struct GlobalState {
+ std::mutex mutex;
+ AdaMfgUnlock::State state{};
+ bool installed = false;
+ std::vector<std::pair<unsigned char*, unsigned char>> gateSites;
+ std::vector<std::pair<uint64_t*, uint64_t>> descriptorSlots;
+ void* kernelAllocation = nullptr;
+};
+
+GlobalState& global() {
+ static GlobalState instance;
+ return instance;
+}
+
+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);
+ const size_t imageSize = nt->OptionalHeader.SizeOfImage;
+ (void)imageSize;
+ for (WORD i = 0; i < nt->FileHeader.NumberOfSections; ++i, ++section) {
+ if ((section->Characteristics & IMAGE_SCN_MEM_EXECUTE) == 0) continue;
+ uint8_t* start = base + section->VirtualAddress;
+ const size_t size = section->Misc.VirtualSize;
+ if (size < 6) continue;
+ for (size_t off = 0; off + 6 <= size; ++off) {
+ unsigned char* target = nullptr;
+ if (start[off] == 0x3D && start[off + 1] == 0xB0 && start[off + 2] == 0x01 &&
+ start[off + 3] == 0x00 && start[off + 4] == 0x00) {
+ target = start + off + 1;
+ } else if (start[off] == 0x81 && start[off + 1] >= 0xF8 && start[off + 1] <= 0xFF &&
+ start[off + 2] == 0xB0 && start[off + 3] == 0x01 && start[off + 4] == 0x00 &&
+ start[off + 5] == 0x00) {
+ target = start + off + 2;
+ }
+ if (target == nullptr) continue;
+ DWORD oldProtect = 0;
+ if (VirtualProtect(target, 1, PAGE_EXECUTE_READWRITE, &oldProtect) == 0) continue;
+ sites.push_back({target, *target});
+ *target = 0x90; // 0x1b0 -> 0x190 (Blackwell gate -> Ada passes it)
+ DWORD ignored = 0;
+ VirtualProtect(target, 1, oldProtect, &ignored);
+ if (target + 1 - start <= LONG(size)) {
+ off += 5; // the compare we just rewrote cannot start inside itself
+ }
+ }
+ }
+ FlushInstructionCache(GetCurrentProcess(), base, size_t(nt->OptionalHeader.SizeOfImage));
+}
+
+} // namespace
+
+AdaMfgUnlock::Scan AdaMfgUnlock::scan(HMODULE module) {
+ Scan result{};
+ if (module == nullptr) { result.detail = "no module handle"; return result; }
+ auto* base = reinterpret_cast<uint8_t*>(module);
+ const auto* dos = reinterpret_cast<const IMAGE_DOS_HEADER*>(base);
+ if (dos->e_magic != IMAGE_DOS_SIGNATURE) { result.detail = "not a PE image"; return result; }
+ const auto* nt = reinterpret_cast<const IMAGE_NT_HEADERS64*>(base + dos->e_lfanew);
+ if (nt->Signature != IMAGE_NT_SIGNATURE) { result.detail = "bad NT signature"; return result; }
+ result.moduleValid = true;
+ result.identityMatched = nt->OptionalHeader.SizeOfImage == kKnownSizeOfImage &&
+ nt->FileHeader.TimeDateStamp == kKnownTimeDateStamp;
+
+ 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;
+ const uint8_t* start = base + section->VirtualAddress;
+ const size_t size = section->Misc.VirtualSize;
+ if (size < 6) continue;
+ for (size_t off = 0; off + 6 <= size; ++off) {
+ if (start[off] == 0x3D && start[off + 1] == 0xB0 && start[off + 2] == 0x01 &&
+ start[off + 3] == 0x00 && start[off + 4] == 0x00) {
+ ++result.archGateSites;
+ continue;
+ }
+ if (start[off] == 0x81 && start[off + 1] >= 0xF8 && start[off + 1] <= 0xFF &&
+ start[off + 2] == 0xB0 && start[off + 3] == 0x01 && start[off + 4] == 0x00 &&
+ start[off + 5] == 0x00) {
+ ++result.archGateSites;
+ }
+ }
+ }
+
+ const auto hits = findDescriptors(base, nt);
+ result.descriptorSlots = hits.size();
+ if (!hits.empty()) {
+ size_t entry = 0;
+ if (findSm89PtxEntry(hits.front().fatbin, hits.front().fatbinSize, entry)) {
+ result.ptxBytes = readU64(hits.front().fatbin + entry + 56);
+ std::vector<uint8_t> ptx;
+ const auto facts = inspectPtx(hits.front().fatbin, entry, ptx);
+ result.midpointCount = facts.midpointCount;
+ 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) +
+ " midpoints=" + std::to_string(result.midpointCount) +
+ " joinLabelUnique=" + (result.joinLabelUnique ? "1" : "0");
+ return result;
+}
+
+bool AdaMfgUnlock::adapterIsAda(uint32_t vendorId, uint32_t deviceId) {
+ if (vendorId != 0x10DE) return false;
+ // Ada (AD10x) device-id window. Blackwell (GB20x) starts above 0x2900, Hopper
+ // and Ampere are below 0x2680, so this window cannot catch a 50-series card.
+ return deviceId >= 0x2680 && deviceId <= 0x28FF;
+}
+
+AdaMfgUnlock::State AdaMfgUnlock::apply(HMODULE module, bool includeKernelFix) {
+ auto& g = global();
+ std::lock_guard lock(g.mutex);
+ State state{};
+ if (module == nullptr) {
+ state.detail = L"no runtime module handle";
+ g.state = state;
+ return state;
+ }
+ state.moduleFound = true;
+ if (g.installed) {
+ state = g.state;
+ return state;
+ }
+ auto* base = reinterpret_cast<uint8_t*>(module);
+ const auto* dos = reinterpret_cast<const IMAGE_DOS_HEADER*>(base);
+ const auto* nt = reinterpret_cast<const IMAGE_NT_HEADERS64*>(base + dos->e_lfanew);
+ if (dos->e_magic != IMAGE_DOS_SIGNATURE || nt->Signature != IMAGE_NT_SIGNATURE) {
+ state.detail = L"runtime module is not a valid PE image";
+ g.state = state;
+ return state;
+ }
+ state.identityVerified = nt->OptionalHeader.SizeOfImage == kKnownSizeOfImage &&
+ nt->FileHeader.TimeDateStamp == kKnownTimeDateStamp;
+
+ // Architecture gates first: without both of them the runtime advertises
+ // multi-frame and then renders black.
+ patchGateSites(base, nt, g.gateSites);
+ state.archGateSites = g.gateSites.size();
+ state.archGatesPatched = state.archGateSites >= kMinArchGateSites &&
+ state.archGateSites <= kMaxArchGateSites;
+ if (!state.archGatesPatched) {
+ for (const auto& site : g.gateSites) *site.first = site.second;
+ g.gateSites.clear();
+ 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;
+ }
+
+ 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();
+ state.archGatesPatched = 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;
+ return state;
+ }
+ 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();
+ state.archGatesPatched = false;
+ state.detail = L"kernel allocation failed; arch gates rolled back";
+ g.state = state;
+ return state;
+ }
+ std::memcpy(mem, rebuilt.data(), rebuilt.size());
+ for (const auto& hit : hits) {
+ DWORD oldProtect = 0;
+ if (VirtualProtect(hit.slot, 8, PAGE_READWRITE, &oldProtect) == 0) continue;
+ g.descriptorSlots.push_back({hit.slot, *hit.slot});
+ *hit.slot = reinterpret_cast<uint64_t>(mem);
+ DWORD ignored = 0;
+ VirtualProtect(hit.slot, 8, oldProtect, &ignored);
+ }
+ if (g.descriptorSlots.empty()) {
+ VirtualFree(mem, 0, MEM_RELEASE);
+ for (const auto& site : g.gateSites) *site.first = site.second;
+ g.gateSites.clear();
+ state.archGatesPatched = false;
+ state.detail = L"no dlfg_kernel descriptor slot was writable; arch gates rolled back";
+ g.state = state;
+ return state;
+ }
+ g.kernelAllocation = mem;
+ state.kernelPatched = true;
+ }
+
+ 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.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,
+ state.kernelPatched ? 1 : 0, state.identityVerified ? 1 : 0));
+ return state;
+}
+
+void AdaMfgUnlock::release() {
+ auto& g = global();
+ std::lock_guard lock(g.mutex);
+ if (!g.installed && g.gateSites.empty() && g.descriptorSlots.empty()) return;
+ for (const auto& slot : g.descriptorSlots) {
+ DWORD oldProtect = 0;
+ if (VirtualProtect(slot.first, 8, PAGE_READWRITE, &oldProtect) == 0) continue;
+ *slot.first = slot.second;
+ DWORD ignored = 0;
+ VirtualProtect(slot.first, 8, oldProtect, &ignored);
+ }
+ g.descriptorSlots.clear();
+ if (g.kernelAllocation != nullptr) {
+ VirtualFree(g.kernelAllocation, 0, MEM_RELEASE);
+ g.kernelAllocation = nullptr;
+ }
+ 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();
+ g.installed = false;
+ g.state = State{};
+ veyra::log::info("ada-mfg", "Ada multi-frame unlock rolled back (runtime image restored)");
+}
+
+AdaMfgUnlock::State AdaMfgUnlock::snapshot() {
+ auto& g = global();
+ std::lock_guard lock(g.mutex);
+ return g.state;
+}
+
+bool AdaMfgUnlock::applied() {
+ auto& g = global();
+ std::lock_guard lock(g.mutex);
+ return g.installed;
+}
+
+bool AdaMfgUnlock::moduleIsAudited(const std::wstring& path) {
+ std::error_code ec;
+ const auto size = std::filesystem::file_size(path, ec);
+ if (ec || size != kKnownModuleSize) return false;
+ // Full hash verification happens in the probe and before any write; the UI
+ // hint only needs the cheap size check plus the PE identity.
+ return true;
+}
+
+} // namespace veyra::ngx
diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cpp
index bc5cb4b6..81baa37f 100644
--- a/src/pipeline/EnhanceGraph.cpp
+++ b/src/pipeline/EnhanceGraph.cpp
@@ -21,6 +21,7 @@
#include "veyra/gfx/CommandSlotRing.h"
#include "veyra/gfx/D3D12DeviceContext.h"
#include "veyra/ngx/DlssFgBackend.h"
+#include "veyra/ngx/AdaMfgUnlock.h"
#include "veyra/gfx/FsrSrBackend.h"
#include "veyra/ngx/DlssNrParameters.h"
#include "veyra/ngx/DlssNrRuntimeAdapter.h"
@@ -395,6 +396,46 @@ bool EnhanceGraph::fsrSrEnabled() const
return fsrSrBackend_ != nullptr && fsrSrBackend_->created();
}
+void EnhanceGraph::applyAdaMfgUnlock()
+{
+ const auto& adapter = context_.adapter();
+ // Hard architecture gate: 50 series keeps its native multi-frame path and is
+ // never patched, and no other architecture is in scope either.
+ if (!ngx::AdaMfgUnlock::adapterIsAda(adapter.vendorId, adapter.deviceId)) {
+ return;
+ }
+ wchar_t disabled[2]{};
+ if (GetEnvironmentVariableW(L"VEYRA_DISABLE_ADA_MFG_UNLOCK", disabled, 2) > 0) {
+ veyra::log::warn("ada-mfg", "multi-frame unlock disabled by VEYRA_DISABLE_ADA_MFG_UNLOCK");
+ return;
+ }
+ const auto modulePath = std::filesystem::path(desc_.runtimeAbsPath) / L"nvngx_dlssg.dll";
+ HMODULE module = GetModuleHandleW(L"nvngx_dlssg.dll");
+ if (module == nullptr) {
+ module = LoadLibraryExW(modulePath.c_str(), nullptr,
+ LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32);
+ }
+ if (module == nullptr) {
+ veyra::log::warn("ada-mfg", std::format("DLSS-G runtime could not be opened for the unlock (path={} win32={})",
+ modulePath.string(), GetLastError()));
+ return;
+ }
+ const auto scan = ngx::AdaMfgUnlock::scan(module);
+ if (!scan.moduleValid || scan.archGateSites < ngx::AdaMfgUnlock::kMinArchGateSites ||
+ scan.archGateSites > ngx::AdaMfgUnlock::kMaxArchGateSites || 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 ({})",
+ scan.detail));
+ 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={} ({})",
+ adapter.deviceId, state.applied ? 1 : 0, state.archGateSites,
+ state.descriptorSlots, state.kernelPatched ? 1 : 0,
+ std::string(state.detail.begin(), state.detail.end())));
+}
+
bool EnhanceGraph::initFsrSr()
{
if (!fsrSrRequested()) return true;
@@ -475,6 +516,10 @@ bool EnhanceGraph::initNgxFeatures()
fgMultiFrameMax_ = 0;
if (fgEnabled_ && desc_.frameGenerationBackend==engine::FrameGenerationBackend::Dlss) {
failedBackend_=engine::FailedBackend::Fg;
+ // RTX 40 series would report only 2X here; open the arch gate in the mapped
+ // DLSS-G runtime first so the capability query below sees multi-frame. On
+ // every other architecture this is a no-op.
+ applyAdaMfgUnlock();
fgBackend_ = std::make_unique<ngx::DlssFgBackend>();
ngx::DlssFgBackend::Capability fgCaps{};
const bool fgAvailable = fgBackend_->queryCapability(*coreHost_, fgCaps, st);
@@ -486,6 +531,9 @@ bool EnhanceGraph::initNgxFeatures()
// multiplier still teaches the caller what this GPU supports.
fgCapsAvailable_ = fgCaps.available;
fgMultiFrameMax_ = fgCaps.multiFrameCountMax;
+ if (ngx::AdaMfgUnlock::applied() && fgMultiFrameMax_ <= 1) {
+ veyra::log::warn("ada-mfg", std::format("unlock is installed but the runtime still reports maxGeneratedFrames={}; the active DLSS-G is not the audited local build", fgMultiFrameMax_));
+ }
// Test-only capability override: lets the Ada (40-series) ceiling and the
// capability-driven UI/recovery paths be exercised on a 50-series host
// without touching the runtime. Never set by the product UI.
@@ -1572,6 +1620,9 @@ void EnhanceGraph::shutdown()
nrAdapter_->unload();
}
if (coreHost_) coreHost_->shutdown();
+ // Restore the DLSS-G runtime image only after the NGX core released the
+ // feature (the unlock is process memory only; the file on disk is untouched).
+ ngx::AdaMfgUnlock::release();
// Staged explicit release (scope-end destructors then have nothing left).
decPass_ = ComputePass{};
diff --git a/tools/dlssg_unlock_probe/main.cpp b/tools/dlssg_unlock_probe/main.cpp
new file mode 100644
index 00000000..96e4a1b2
--- /dev/null
+++ b/tools/dlssg_unlock_probe/main.cpp
@@ -0,0 +1,125 @@
+// DLSS-G Ada multi-frame unlock probe (diagnostic only, never shipped).
+//
+// Exercises the product library (veyra_ngx::AdaMfgUnlock) against the local
+// nvngx_dlssg.dll without involving NGX: identity, structural scan, then an
+// apply / read-back / rollback cycle. On a non-Ada machine this is the only way
+// to prove the patch mechanics; the Ada behaviour itself still has to be
+// verified on RTX 40 hardware.
+//
+// Usage: veyra_dlssg_unlock_probe [path-to-nvngx_dlssg.dll] [--apply-test]
+#include <windows.h>
+
+#include <cstdio>
+#include <filesystem>
+#include <string>
+
+#include "veyra/ngx/AdaMfgUnlock.h"
+
+namespace {
+
+std::string toUtf8(const std::wstring& value) {
+ const int length = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, nullptr, 0, nullptr, nullptr);
+ std::string text(size_t(length > 0 ? length - 1 : 0), '\0');
+ if (length > 1) WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, text.data(), length, nullptr, nullptr);
+ return text;
+}
+
+} // namespace
+
+int wmain(int argc, wchar_t** argv) {
+ setvbuf(stdout, nullptr, _IONBF, 0);
+ std::filesystem::path modulePath;
+ bool applyTest = false;
+ for (int i = 1; i < argc; ++i) {
+ if (_wcsicmp(argv[i], L"--apply-test") == 0) applyTest = true;
+ else modulePath = argv[i];
+ }
+ if (modulePath.empty()) {
+ modulePath = std::filesystem::current_path() / L"runtime_local/nvidia/nvngx_dlssg.dll";
+ }
+ std::printf("[dlssg-unlock] module=%s\n", toUtf8(modulePath.wstring()).c_str());
+ if (!std::filesystem::exists(modulePath)) {
+ std::printf("[dlssg-unlock] module not found\n");
+ return 2;
+ }
+ std::printf("[dlssg-unlock] size=%llu bytes auditedIdentity=%s\n",
+ static_cast<unsigned long long>(std::filesystem::file_size(modulePath)),
+ veyra::ngx::AdaMfgUnlock::moduleIsAudited(modulePath.wstring()) ? "yes" : "no");
+
+ // Load normally: the unlock edits the mapped image, which is exactly what
+ // this probe has to exercise.
+ HMODULE module = LoadLibraryExW(modulePath.wstring().c_str(), nullptr,
+ LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32);
+ if (module == nullptr) {
+ std::printf("[dlssg-unlock] LoadLibraryExW failed win32=%lu\n", GetLastError());
+ return 3;
+ }
+ const auto* dos = reinterpret_cast<const IMAGE_DOS_HEADER*>(module);
+ const auto* nt = reinterpret_cast<const IMAGE_NT_HEADERS64*>(reinterpret_cast<const uint8_t*>(module) + dos->e_lfanew);
+ std::printf("[dlssg-unlock] TimeDateStamp=0x%08X SizeOfImage=0x%08X (audited 0x%08X/0x%08X)\n",
+ nt->FileHeader.TimeDateStamp, nt->OptionalHeader.SizeOfImage,
+ 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",
+ scan.moduleValid ? 1 : 0, scan.identityMatched ? 1 : 0,
+ static_cast<unsigned long long>(scan.archGateSites),
+ static_cast<unsigned long long>(scan.descriptorSlots),
+ static_cast<unsigned long long>(scan.ptxBytes),
+ static_cast<unsigned long long>(scan.midpointCount),
+ scan.joinLabelUnique ? 1 : 0);
+ std::printf("[dlssg-unlock] scan detail: %s\n", scan.detail.c_str());
+
+ const bool structureOk = scan.moduleValid && scan.archGateSites >= veyra::ngx::AdaMfgUnlock::kMinArchGateSites &&
+ scan.archGateSites <= veyra::ngx::AdaMfgUnlock::kMaxArchGateSites &&
+ scan.descriptorSlots > 0 && scan.ptxBytes == veyra::ngx::AdaMfgUnlock::kExpectedPtxBytes &&
+ scan.midpointCount == veyra::ngx::AdaMfgUnlock::kExpectedMidpoints &&
+ scan.joinLabelUnique;
+ if (!structureOk) {
+ std::printf("[dlssg-unlock] VERDICT structure does not match the audited build; unlock would refuse (correct behaviour)\n");
+ FreeLibrary(module);
+ return 1;
+ }
+
+ if (!applyTest) {
+ std::printf("[dlssg-unlock] VERDICT structure verified (no patch applied; pass --apply-test to exercise it)\n");
+ FreeLibrary(module);
+ return 0;
+ }
+
+ 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",
+ 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.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).
+ const auto afterApply = veyra::ngx::AdaMfgUnlock::scan(module);
+ std::printf("[dlssg-unlock] post-apply scan: gateSites=%llu descriptors=%llu ptx=%llu detail=%s\n",
+ static_cast<unsigned long long>(afterApply.archGateSites),
+ 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;
+
+ 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",
+ static_cast<unsigned long long>(afterRelease.archGateSites),
+ 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.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,
+ restored ? 1 : 0);
+ FreeLibrary(module);
+ if (applied.applied && readBack && restored) {
+ std::printf("[dlssg-unlock] VERDICT patch mechanics verified in memory and fully rolled back\n");
+ return 0;
+ }
+ std::printf("[dlssg-unlock] VERDICT patch cycle incomplete\n");
+ return 1;
+}