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(ampere-mfg): wire the RTX 30 unlock into the FG path with a CUDA preflight

Veyra Goal Agent3dd5addbdd9e
diff --git a/include/veyra/pipeline/EnhanceGraph.h b/include/veyra/pipeline/EnhanceGraph.h
index 76f42394..e4caba38 100644
--- a/include/veyra/pipeline/EnhanceGraph.h
+++ b/include/veyra/pipeline/EnhanceGraph.h
@@ -261,6 +261,7 @@ private:
// RTX 40 series: opens the Blackwell-only multi-frame gate in the mapped
// DLSS-G runtime. Never touched on any other architecture.
void applyAdaMfgUnlock();
+ void applyAmpereMfgUnlock();
bool createComputePasses();
gfx::D3D12DeviceContext& context_;
diff --git a/src/ngx/AmpereMfgUnlock.cpp b/src/ngx/AmpereMfgUnlock.cpp
index a5570888..30b16ea9 100644
--- a/src/ngx/AmpereMfgUnlock.cpp
+++ b/src/ngx/AmpereMfgUnlock.cpp
@@ -551,6 +551,69 @@ void* allocateReachable(size_t bytes, const uint8_t* moduleBase) {
return VirtualAlloc(nullptr, bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
}
+// CUDA driver preflight (the intent of dashdogy's ampere_cuda_program
+// validation): in a private context on the active GPU, the driver must accept
+// every rebuilt fatbin before any pointer is published. On an RTX 30 host this
+// compiles the sm_86 programs on the real Ampere device; on other hosts it at
+// least proves the PTX/JIT path is legal.
+bool preflightPrograms(const std::vector<std::pair<const uint8_t*, size_t>>& programs,
+ std::string& why, size_t& loaded) {
+ loaded = 0;
+ HMODULE cuda = LoadLibraryExW(L"nvcuda.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
+ if (cuda == nullptr) {
+ why = "nvcuda.dll is not available";
+ return false;
+ }
+ // nvcuda.dll is intentionally never unloaded: the CUDA driver does not
+ // support being freed while the process lives.
+ const auto init = reinterpret_cast<int (*)(unsigned)>(
+ reinterpret_cast<void*>(GetProcAddress(cuda, "cuInit")));
+ const auto deviceGet = reinterpret_cast<int (*)(int*, int)>(
+ reinterpret_cast<void*>(GetProcAddress(cuda, "cuDeviceGet")));
+ const auto ctxCreate = reinterpret_cast<int (*)(void**, unsigned, int)>(
+ reinterpret_cast<void*>(GetProcAddress(cuda, "cuCtxCreate_v2")));
+ const auto ctxDestroy = reinterpret_cast<int (*)(void*)>(
+ reinterpret_cast<void*>(GetProcAddress(cuda, "cuCtxDestroy_v2")));
+ const auto moduleLoad = reinterpret_cast<int (*)(void**, const void*, unsigned, void*, void*)>(
+ reinterpret_cast<void*>(GetProcAddress(cuda, "cuModuleLoadDataEx")));
+ const auto moduleUnload = reinterpret_cast<int (*)(void*)>(
+ reinterpret_cast<void*>(GetProcAddress(cuda, "cuModuleUnload")));
+ if (init == nullptr || deviceGet == nullptr || ctxCreate == nullptr ||
+ ctxDestroy == nullptr || moduleLoad == nullptr || moduleUnload == nullptr) {
+ why = "nvcuda.dll does not export the required driver API";
+ return false;
+ }
+ if (init(0) != 0) {
+ why = "cuInit failed";
+ return false;
+ }
+ int device = 0;
+ if (deviceGet(&device, 0) != 0) {
+ why = "cuDeviceGet failed";
+ return false;
+ }
+ void* context = nullptr;
+ if (ctxCreate(&context, 0, device) != 0) {
+ why = "cuCtxCreate failed";
+ return false;
+ }
+ bool ok = true;
+ for (size_t index = 0; index < programs.size(); ++index) {
+ void* module = nullptr;
+ const int result = moduleLoad(&module, programs[index].first, 0, nullptr, nullptr);
+ if (result != 0) {
+ why = std::format("the CUDA driver rejected rebuilt program {} (cuModuleLoadDataEx={})",
+ index, result);
+ ok = false;
+ break;
+ }
+ if (module != nullptr) moduleUnload(module);
+ ++loaded;
+ }
+ ctxDestroy(context);
+ return ok;
+}
+
} // namespace
AmpereMfgUnlock::Scan AmpereMfgUnlock::scan(HMODULE module) {
@@ -881,6 +944,24 @@ AmpereMfgUnlock::State AmpereMfgUnlock::apply(HMODULE module) {
replacements.push_back({fb.address, std::move(data)});
}
+ // The driver must accept the whole rebuilt program set before anything is
+ // published; a rejected program is a refusal, never a half-installed set.
+ size_t preflightLoaded = 0;
+ {
+ std::vector<std::pair<const uint8_t*, size_t>> programData;
+ programData.reserve(replacements.size());
+ for (const auto& replacement : replacements) {
+ programData.push_back({replacement.data.data(), replacement.data.size()});
+ }
+ std::string preflightWhy;
+ if (!preflightPrograms(programData, preflightWhy, preflightLoaded)) {
+ state.detail = std::format(L"CUDA preflight refused the rebuilt program set: {}",
+ std::wstring(preflightWhy.begin(), preflightWhy.end()));
+ g.state = state;
+ return state;
+ }
+ }
+
size_t total = 0;
std::vector<size_t> offsets;
offsets.reserve(replacements.size());
@@ -1020,8 +1101,9 @@ AmpereMfgUnlock::State AmpereMfgUnlock::apply(HMODULE module) {
state.fatbinsRedirected = true;
state.applied = state.archGatesPatched && state.fatbinsRedirected;
state.detail = std::format(
- L"runs={} slots={} fatbins={} lea={} gates={} (in-memory only)",
- slotRuns, hits.size(), replacements.size(), g.leaWrites.size(), state.archGateSites);
+ L"runs={} slots={} fatbins={} lea={} gates={} preflight={}/{} (in-memory only)",
+ slotRuns, hits.size(), replacements.size(), g.leaWrites.size(), state.archGateSites,
+ preflightLoaded, replacements.size());
g.state = state;
veyra::log::info("ampere-mfg",
std::format("RTX 30 sm_86 unlock: {} runs / {} slot pointers, {} fatbins redirected, "
diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cpp
index 221c806a..d94f71ed 100644
--- a/src/pipeline/EnhanceGraph.cpp
+++ b/src/pipeline/EnhanceGraph.cpp
@@ -22,6 +22,7 @@
#include "veyra/gfx/D3D12DeviceContext.h"
#include "veyra/ngx/DlssFgBackend.h"
#include "veyra/ngx/AdaMfgUnlock.h"
+#include "veyra/ngx/AmpereMfgUnlock.h"
#include "veyra/gfx/FsrSrBackend.h"
#include "veyra/ngx/DlssNrParameters.h"
#include "veyra/ngx/DlssNrRuntimeAdapter.h"
@@ -439,6 +440,55 @@ void EnhanceGraph::applyAdaMfgUnlock()
std::string(state.detail.begin(), state.detail.end())));
}
+void EnhanceGraph::applyAmpereMfgUnlock()
+{
+ const auto& adapter = context_.adapter();
+ // Hard architecture gate: only RTX 30 (Ampere GA10x) takes this path. Ada
+ // keeps its own unlock and Blackwell keeps its native multi-frame path.
+ if (!ngx::AmpereMfgUnlock::adapterIsAmpere(adapter.vendorId, adapter.deviceId)) {
+ return;
+ }
+ wchar_t disabled[2]{};
+ if (GetEnvironmentVariableW(L"VEYRA_DISABLE_AMPERE_MFG_UNLOCK", disabled, 2) > 0) {
+ veyra::log::warn("ampere-mfg", "RTX 30 sm_86 unlock disabled by VEYRA_DISABLE_AMPERE_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("ampere-mfg", std::format("DLSS-G runtime could not be opened for the RTX 30 unlock (path={} win32={})",
+ modulePath.string(), GetLastError()));
+ return;
+ }
+ const auto scan = ngx::AmpereMfgUnlock::scan(module);
+ if (!scan.moduleValid || !scan.identityMatched ||
+ scan.slotRuns != ngx::AmpereMfgUnlock::kExpectedSlotRuns ||
+ scan.slotPointers != ngx::AmpereMfgUnlock::kExpectedSlotRuns *
+ ngx::AmpereMfgUnlock::kExpectedSlotsPerRun ||
+ scan.programFatbins != ngx::AmpereMfgUnlock::kExpectedProgramFatbins ||
+ scan.networkFatbins != ngx::AmpereMfgUnlock::kExpectedRdataNetworkFatbins ||
+ scan.auxFatbins != ngx::AmpereMfgUnlock::kExpectedAuxFatbins ||
+ scan.leaSites != ngx::AmpereMfgUnlock::kExpectedLeaSites ||
+ scan.archGateSites < ngx::AmpereMfgUnlock::kMinArchGateSites ||
+ scan.archGateSites > ngx::AmpereMfgUnlock::kMaxArchGateSites ||
+ !scan.temporalSlotUnique) {
+ veyra::log::warn("ampere-mfg", std::format("unlock refused: runtime build does not match the audited structure ({})",
+ scan.detail));
+ return;
+ }
+ const auto state = ngx::AmpereMfgUnlock::apply(module);
+ veyra::log::info("ampere-mfg", std::format("adapter deviceId=0x{:04X} unlock applied={} runs={} slots={} fatbins={} lea={} gates={} ({})",
+ adapter.deviceId, state.applied ? 1 : 0, state.slotRuns,
+ state.slotPointers,
+ state.programFatbins + state.networkFatbins + state.auxFatbins,
+ state.leaSites, state.archGateSites,
+ std::string(state.detail.begin(), state.detail.end())));
+}
+
bool EnhanceGraph::initFsrSr()
{
if (!fsrSrRequested()) return true;
@@ -523,12 +573,29 @@ bool EnhanceGraph::initNgxFeatures()
// DLSS-G runtime first so the capability query below sees multi-frame. On
// every other architecture this is a no-op.
applyAdaMfgUnlock();
+ // RTX 30 has no sm_86 program in the provider at all; the Ampere unlock
+ // rebuilds every fatbin and re-targets the arch gates before the query.
+ applyAmpereMfgUnlock();
fgBackend_ = std::make_unique<ngx::DlssFgBackend>();
ngx::DlssFgBackend::Capability fgCaps{};
const bool fgAvailable = fgBackend_->queryCapability(*coreHost_, fgCaps, st);
if (!fgAvailable) {
- veyra::log::error("graph", "FG unavailable; fail closed");
- return false;
+ if (ngx::AmpereMfgUnlock::applied()) {
+ // The provider's own report stays Ada/Blackwell-gated; the audited
+ // sm_86 unlock replaced every program and the audited build's
+ // compiled ceiling is five generated frames. Only a completely
+ // absent report is overridden; an explicit smaller value is kept.
+ if (fgCaps.multiFrameCountMax == 0) {
+ fgCaps.multiFrameCountMax = 5;
+ }
+ fgCaps.available = true;
+ veyra::log::warn("ampere-mfg", std::format(
+ "runtime reported FG unavailable; continuing on the audited sm_86 unlock (multiFrameMax={})",
+ fgCaps.multiFrameCountMax));
+ } else {
+ veyra::log::error("graph", "FG unavailable; fail closed");
+ return false;
+ }
}
// Publish the capability before validating the request so a rejected
// multiplier still teaches the caller what this GPU supports.
@@ -1626,6 +1693,7 @@ void EnhanceGraph::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();
+ ngx::AmpereMfgUnlock::release();
// Staged explicit release (scope-end destructors then have nothing left).
decPass_ = ComputePass{};