diff --git a/docs/README.md b/docs/README.md index 904f36f58..8cba5cc3e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -97,6 +97,7 @@ method, scope and caveats. No game data is included. | [coder.md](coder.md) | The compressed mass in `story000_script.rpf`: entry framing (`align16(entry+8)` payload), the 32-value tag alphabet, deflate-shaped but proprietary, variable-length 7/8-bit LSB-first codes with no stored table, and the `n7 = 116..127` search that finishes it. | | [mission_logic.md](mission_logic.md) | Mission state tables: 0x20 record layout (band counter, byte offsets), the 64-byte pool element with world transforms, case-folding joaat keys, 53.5 % of states named, 113 state-set clusters covering 82.4 % of files. | | [gbuffer.md](gbuffer.md) | Deferred G-buffer targets (`PS_DeferredTextured` and all 2,989 `*Deferred*` pixel shaders, `PROC-146`): 5- and 6-target `OSG1`/`PSV0` signatures (`float32` + `exp ... compr` on all outputs), the 24-bit octahedral normal split across `mrt1.gba` (`2047.5` scale, `1/255` byte packing), sqrt-encoded `mrt2`, byte IDs in `mrt3.zw`, float motion in `mrt4`, and why binding `f16` targets mangles the normal bytes. | +| [upscaler_backends.md](upscaler_backends.md) | The upscaler landscape the runtime can drive: which components the package ships (FSR4 on Xbox ABI), which it could reach on PC (DLSS), what each license permits, and where the integration's ABI declarations live (`runtime/test/ffx_api_min.h`, `runtime/test/nvngx_api_min.h`). | ## Other languages diff --git a/docs/upscaler_backends.md b/docs/upscaler_backends.md new file mode 100644 index 000000000..34607a05a --- /dev/null +++ b/docs/upscaler_backends.md @@ -0,0 +1,81 @@ +# Upscaler backends behind the FFX front + +The game drives its upscaler through the FidelityFX API five functions (`ffxConfigure`, `ffxQuery`, +`ffxCreateContext`, `ffxDestroyContext`, `ffxDispatch`, measured on 1.0.2.1 in fsr_dispatch_test). That five-function +front is the one integration surface Leonida owns: what sits behind it is a provider choice, not a code change. This +note records the license status and the interface facts for each provider, so the follow-up PRs do not re-survey; +nothing speculative ships here — the only backend code in the tree is the DLSS one (PR: runtime/src/dlss_backend, +behind `LEONIDA_DLSS=1`). + +``` +game → ffxConfigure/ffxQuery/ffxCreateContext/ffxDispatch (the front, untouched) + ├─ default: the package's amd_fidelityfx_upscaler_xbox.dll (FSR4 scarlett), the measured path + ├─ LEONIDA_DLSS=1: runtime/src/dlss_backend → driver NGX Core (nvngx.dll) + nvngx_dlss.dll + ├─ (reserved) FSR3.1: a PC FSR3.1 context behind the same five functions — same API, no translation + └─ (reserved) XeSS: an XeSS 2.x context — either through its FFX front or a thin bridge +``` + +## 1. What ships today + +**FSR4 (the game's own) — zero code.** `amd_fidelityfx_upscaler_xbox.dll` runs on the Xbox-ABI device proxy and +fsr_dispatch_test drives it step by step (docs/d3d12_vulkan.md Appendix A.3 records the backend descriptor 0x01000002 +and the slots it calls). The runtime dll stays next to the package as shipped; nothing from it is redistributed. This +is the default path and it works. + +**DLSS — runtime/src/dlss_backend (this PR).** The FFX five functions stay untouched; when `LEONIDA_DLSS=1` the +shim's upscale dispatch reaches the DLSS backend, which translates the FFX description to NGX (isomorphic ML-upscaler +inputs; the field mapping is in dlss_backend.h) and runs it through the driver's NGX Core loaded by name. The +nvngx_api_min.h header is written from the export table and the 310.6 programming guide — no SDK file is in the tree, +and the runtime dlls (nvngx_dlss.dll etc.) are provided by the user's driver installation next to the exe, exactly +like the game's own upscaler dll. Quality mapping and the per-slot DLSS.Hint.Render.Preset hint are the pure +functions in dlss_backend.cpp, covered by dlss_backend_unit_test (CPU-only, no device). + +## 2. FSR3.1 — by construction, almost nothing to ship + +FSR 3.1 exposes the same five functions: the game's front is already FSR 3.1-shaped (the API is versioned at the +context; fsr_dispatch_test measures 4.1/4.1.1 version descriptors on the FSR4 dll). A PC FSR3.1 provider is therefore +the same shape as the FSR4 provider — context creation, version descriptor, a D3D12 backend interface — with no +translation layer at all. The integration work is plumbing, not mapping: + +- provider choice in the shim (the game dll is FSR4; a PC FSR3.1 runtime is opt-in via env, same pattern as + `LEONIDA_NGX_DLL`), +- the pre-existing hard prerequisite: the descriptor model must land first (#335) — color/depth/mv need real + render outputs to feed either provider. + +**License map (measured on the upstream repos, 2026-11-23):** the `GPUOpen-Effects/FidelityFX-FSR` repo is MIT +(license.txt, the standard grant), but it ships only the FSR1-era headers (`ffx_a.h`, `ffx_fsr1.h`). The FFX API and +FSR3.x sources live in the `GPUOpen-LibrariesAndSDKs/FidelityFX-SDK` repo under `Kits/FidelityFX`, whose license.md +is **not MIT** — it is AMD's redistribution license ("binary form only", "no reverse engineering, decompilation, or +disassembly"). So, same rule as DLSS: no SDK header is copied into this GPL tree. The front's ABI is already written +from the export table and the measured structs (fsr_dispatch_test's own ffx types); the provider dll is +user-provided as shipped. + +## 3. XeSS — reserved, same pattern + +Intel XeSS 2.x accepts both shapes: a D3D12-native API (`xess.h`: `xessD3D12CreateContext`/`Init`/Execute…, which +needs an FFX→XeSS bridge of ~a dozen setters — jitter, mv scale, exposure, reset all have named equivalents) and a +FFX-API front (`libxess_fx.dll`, which answers the same five functions and would need no bridge at all). The +non-Intel path exists (DP4a / SM6.4 dot-product kernels run on any vendor), so XeSS is the natural third provider +rather than an Intel-only one — but it is not current work. + +**License (intel/xess LICENSE.txt, read 2026-11-23):** Intel Simplified Software License — binary form only, +explicitly no reverse engineering or modification. Same conclusion as above: nothing from the XeSS SDK enters the +tree; an xess_api_min.h-style header would be written from the export table at integration time, and the runtime +libs are user-provided. + +## 4. The complete license map + +| Component | License | In this tree? | User-side artifact | +|---|---|---|---| +| game's `amd_fidelityfx_upscaler_xbox.dll` (FSR4) | game EULA | no — measured, never redistributed | as shipped | +| driver NGX Core (`nvngx.dll`) | NVIDIA driver distribution | no — loaded by name LEONIDA_NGX_DLL | driver install | +| `nvngx_dlss.dll` / `dlssg` / `dlssd` | NVIDIA driver / RTX EULA | no | driver install (exe-adjacent) | +| NVIDIA DLSS SDK (headers, libs, docs) | RTX proprietary (no OSS relicensing) | no — ABI written from export table + 310.6 guide | not needed | +| AMD FFX API + FSR3.x (`FidelityFX-SDK` Kits) | AMD redistribution (binary-only, no RE) | no — front ABI already written from the export table | user-provided FSR3.1 runtime (reserved) | +| `GPUOpen-Effects/FidelityFX-FSR` repo (FSR1 headers) | MIT | usable, but FSR1 has no role here | — | +| Intel XeSS SDK (`xess.h`, `libxess*`) | Intel Simplified (binary-only, no RE) | no — reserved; ABI from export table at integration time | user-provided runtime (reserved) | + +The pattern is uniform: Leonida writes its own minimal ABI headers from export tables and public specifications, +never ships a vendor SDK file, and every runtime dll is user-provided at the location its installer manages. The +providers differ only in what their translation layer contains: FSR4/FSR3.1 none, DLSS the NGX parameter bag with +its quality/preset mapping (shipped), XeSS a small bridge (reserved). diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index f317958f1..5949b5a61 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -312,6 +312,19 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME) target_compile_options(bcrypt_rng_test PRIVATE /W4 /permissive- /utf-8) target_link_options(bcrypt_rng_test PRIVATE /OPT:NOREF) + # DLSS (nvngx) backend: translation surface and unit test. The .cpp pulls in the NGX declarations from + # test/nvngx_api_min.h (written-out ABI subset, no NVIDIA SDK source); the test drives the pure functions + # and the parameter-bag assembly through a recording mock, so it needs no DXGI/D3D12 and no NGX Core. + add_executable(dlss_backend_test + test/dlss_backend_unit_test.cpp + src/dlss_backend.cpp + ) + target_include_directories(dlss_backend_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) + target_compile_definitions(dlss_backend_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) + target_compile_options(dlss_backend_test PRIVATE /W4 /permissive- /utf-8) + target_link_options(dlss_backend_test PRIVATE /OPT:NOREF) + add_test(NAME dlss_backend COMMAND dlss_backend_test) + # Synthetic tests for the atomic API reference lifecycle. add_executable(api_ref_state_test test/api_ref_state_test.cpp) target_include_directories(api_ref_state_test PRIVATE diff --git a/runtime/src/dlss_backend.cpp b/runtime/src/dlss_backend.cpp new file mode 100644 index 000000000..8baa84b6e --- /dev/null +++ b/runtime/src/dlss_backend.cpp @@ -0,0 +1,255 @@ +// DLSS backend: the NVIDIA NGX path behind the DLSS provider face the runtime exposes. The FFX-facing +// description (the game's ffx::DispatchDescUpscale or the plain FfxDescription) is translated to NGX — the two +// are ML upscalers with isomorphic inputs: color, depth, motion vectors, jitter, exposure; the DLSS side is +// documented in the DLSS Programming Guide 310.6 sections 5.2-5.4 — and run through the driver's NGX Core, +// which is loaded by name and never shipped with Leonida: nvngx.dll from the NVIDIA driver distribution, +// nvngx_dlss.dll next to the exe. +// +// Backend contract (src-level): +// init(device) once, before any create; also queries capability (SuperSampling.Available) +// create(...) once per (in, out) size pair on quality/flag change; releases the old handle +// eval_from_ffx(...) per dispatch: fills the parameter bag from the FFX description and records +// shutdown(device) releases the feature, parameters and the NGX instance +// The caller owns state preservation: NGX rewrites the command list state (guide 5.4 IMPORTANT), so the shim +// wraps the game's list and restores the game's state after the records. +#include "dlss_backend.h" + +#include + +#include + +#include +#include +#include + +#include "../test/nvngx_api_min.h" + +namespace leonida::dlss { + +namespace { + +struct Core { + nvngx::PfnInitWithProjectId init_project_id = nullptr; + nvngx::PfnAllocateParameters allocate = nullptr; + nvngx::PfnGetCapabilityParameters capability = nullptr; + nvngx::PfnCreateFeature create_feature = nullptr; + nvngx::PfnEvaluateFeature evaluate = nullptr; + nvngx::PfnReleaseFeature release_feature = nullptr; + nvngx::PfnDestroyParameters destroy = nullptr; + nvngx::PfnShutdown1 shutdown1 = nullptr; + bool enabled = false; +}; + +Core& core() { + static Core c; + return c; +} + +bool g_initiated = false; + +void* find_export(HMODULE module, const char* name) { + return reinterpret_cast(GetProcAddress(module, name)); +} + +// Loads the NGX Core and binds exports. Env LEONIDA_NGX_DLL names a full nvngx.dll path; without it, the +// loader search finds nvngx.dll the way NGX itself does (application folder, then the driver distribution). +bool load_core() { + if (core().enabled) return true; + HMODULE module = nullptr; + if (const char* path = std::getenv("LEONIDA_NGX_DLL"); path && *path) { + module = LoadLibraryA(path); + } else { + module = GetModuleHandleA("nvngx.dll"); // already in the process (the game loads it), else below + if (!module) module = LoadLibraryA("nvngx.dll"); + } + if (!module) { + std::printf("dlss: no NGX Core (set LEONIDA_NGX_DLL=, or install the NVIDIA driver)\n"); + return false; + } + Core& c = core(); + c.init_project_id = reinterpret_cast(find_export(module, "NVSDK_NGX_D3D12_Init_ProjectID")); + c.allocate = reinterpret_cast(find_export(module, "NVSDK_NGX_D3D12_AllocateParameters")); + c.capability = reinterpret_cast(find_export(module, "NVSDK_NGX_D3D12_GetCapabilityParameters")); + c.create_feature = reinterpret_cast(find_export(module, "NVSDK_NGX_D3D12_CreateFeature")); + c.evaluate = reinterpret_cast(find_export(module, "NVSDK_NGX_D3D12_EvaluateFeature")); + c.release_feature = reinterpret_cast(find_export(module, "NVSDK_NGX_D3D12_ReleaseFeature")); + c.destroy = reinterpret_cast(find_export(module, "NVSDK_NGX_D3D12_DestroyParameters")); + c.shutdown1 = reinterpret_cast(find_export(module, "NVSDK_NGX_D3D12_Shutdown1")); + if (!(c.init_project_id && c.allocate && c.capability && c.create_feature && c.evaluate && c.release_feature && + c.destroy && c.shutdown1)) { + std::printf("dlss: NGX Core exports incomplete\n"); + return false; + } + c.enabled = true; + return true; +} + +} // namespace + +bool init(ID3D12Device* device, const wchar_t* data_path) { + if (!load_core()) return false; + if (g_initiated) return true; + // The NGX Core dereferences the info record unconditionally: a null here ends the process (observed), + // a zeroed one is what the SDK's own init path passes. + nvngx::FeatureCommonInfo info{}; + const nvngx::Result rc = core().init_project_id( + "7c2f18e5-3bda-41e6-9f0d-2a4b8c6e5d17", nvngx::ENGINE_CUSTOM, "leonida 0.1", data_path, device, &info, + nvngx::SDK_VERSION); + if (rc != nvngx::RESULT_SUCCESS) { + std::printf("dlss: init_project_id -> 0x%x\n", static_cast(rc)); + return false; + } + // capability: SuperSampling.Available + driver gate, as guide 5.2.6 prescribes + nvngx::Parameter* caps = nullptr; + if (core().capability(&caps) == nvngx::RESULT_SUCCESS && caps) { + int available = 0, needs_newer = 0; + caps->Get(nvngx::SUPER_AVAILABLE, &available); + caps->Get(nvngx::SUPER_NEEDS_UPDATED_DRIVER, &needs_newer); + core().destroy(caps); + g_initiated = available != 0 && needs_newer == 0; + return g_initiated; + } + return false; +} + +bool initiated() { + return g_initiated; +} + +void shutdown(ID3D12Device* device) { + if (core().enabled) core().shutdown1(device); +} + +nvngx::PerfQualityValue pick_quality(float upscale_ratio) { + // The FFX mode's ratio names the DLSS slot (the game's own ffxQuery feeds desc.upscale_ratio). The slot + // ratios anchored by the guide's Optimal Settings table are MaxQuality=1.5, UltraQuality=1.7, + // Balanced=1.7237, MaxPerf=3.0: distances fold 2.0-3.0 into UltraQuality and the 1.7237 collision keeps + // Balanced in the 1.71..2.0 band. + if (upscale_ratio >= 3.0f) return nvngx::PERF_VALUE_MAX_PERF; + if (upscale_ratio >= 2.0f) return nvngx::PERF_VALUE_ULTRA_QUALITY; + if (upscale_ratio > 1.71f) return nvngx::PERF_VALUE_BALANCED; // 1.7237x + if (upscale_ratio > 1.6f) return nvngx::PERF_VALUE_ULTRA_QUALITY; // 1.7x + if (upscale_ratio > 1.05f) return nvngx::PERF_VALUE_MAX_QUALITY; // 1.5x + return nvngx::PERF_VALUE_DLAA; +} + +int create_flags(const Description& desc) { + return (desc.hdr ? nvngx::DLSS_FLAG_IS_HDR : 0) | (desc.mv_low_res ? nvngx::DLSS_FLAG_MV_LOW_RES : 0) | + (desc.mv_jittered ? nvngx::DLSS_FLAG_MV_JITTERED : 0) | + (desc.depth_inverted ? nvngx::DLSS_FLAG_DEPTH_INVERTED : 0) | + (desc.auto_exposure ? nvngx::DLSS_FLAG_AUTO_EXPOSURE : 0); +} + +float effective_mv_scale(float mv_scale) { + return mv_scale == 0.0f ? 1.0f : mv_scale; // the shipped helper's 0-means-1.0 rule +} + +const char* preset_key(nvngx::PerfQualityValue quality) { + switch (quality) { + case nvngx::PERF_VALUE_DLAA: return nvngx::PRESET_KEY_DLAA; + case nvngx::PERF_VALUE_ULTRA_QUALITY: return nvngx::PRESET_KEY_ULTRA_QUALITY; + case nvngx::PERF_VALUE_MAX_QUALITY: return nvngx::PRESET_KEY_QUALITY; + case nvngx::PERF_VALUE_BALANCED: return nvngx::PRESET_KEY_BALANCED; + case nvngx::PERF_VALUE_MAX_PERF: return nvngx::PRESET_KEY_PERFORMANCE; + case nvngx::PERF_VALUE_ULTRA_PERFORMANCE: return nvngx::PRESET_KEY_ULTRA_PERFORMANCE; + } + return nvngx::PRESET_KEY_QUALITY; +} + +// The create parameter bag, in the shipped helper's exact key and type order (NGX_D3D12_CREATE_DLSS_EXT): +// node masks as unsigned, sizes as unsigned, quality and flags as int. The preset hint rides the same bag +// so it is on it before CreateFeature — the guide's 3.12 example Sets it on the create parameters, and the +// slot pick is read at creation when the network preset is baked into the feature. PRESET_DEFAULT (0) +// leaves the key unset, which keeps the driver's OTA default in place. +void fill_create_params(nvngx::Parameter* params, const Description& desc, unsigned int creation_node_mask, + nvngx::PerfQualityValue quality, int flags) { + params->Set(nvngx::CREATION_NODE_MASK, creation_node_mask); + params->Set(nvngx::VISIBILITY_NODE_MASK, creation_node_mask); + params->Set(nvngx::WIDTH, desc.render_width); + params->Set(nvngx::HEIGHT, desc.render_height); + params->Set(nvngx::OUT_WIDTH, desc.upscale_width); + params->Set(nvngx::OUT_HEIGHT, desc.upscale_height); + params->Set(nvngx::PERF_QUALITY_VALUE, static_cast(quality)); + params->Set(nvngx::DLSS_CREATE_FLAGS, flags); + params->Set(nvngx::DLSS_ENABLE_OUTPUT_SUBRECTS, 0); + if (desc.preset != nvngx::PRESET_DEFAULT) + params->Set(preset_key(quality), desc.preset); +} + +// The eval parameter bag, in the shipped helper's exact key and type order (NGX_D3D12_EVALUATE_DLSS_EXT): +// resources, jitter floats, the deprecated sharpness (set 0), reset as int, the MV scale with the helper's +// 0-means-1.0 rule, then the optional resources. The preset hint is refreshed identically, so a bag reused +// across frames keeps describing the selected slot whatever the NGX side reads at which call. +void fill_eval_params(nvngx::Parameter* params, const FfxDescription& fx, int preset, + nvngx::PerfQualityValue quality) { + params->Set(nvngx::COLOR, fx.color); + params->Set(nvngx::OUTPUT, fx.output); + if (fx.depth) params->Set(nvngx::DEPTH, fx.depth); + if (fx.motion_vectors) params->Set(nvngx::MOTION_VECTORS, fx.motion_vectors); + params->Set(nvngx::JITTER_OFFSET_X, fx.jitter_x); + params->Set(nvngx::JITTER_OFFSET_Y, fx.jitter_y); + params->Set(nvngx::SHARPNESS, fx.sharpness); + params->Set(nvngx::RESET, fx.reset ? 1 : 0); + params->Set(nvngx::MV_SCALE_X, effective_mv_scale(fx.mv_scale_x)); + params->Set(nvngx::MV_SCALE_Y, effective_mv_scale(fx.mv_scale_y)); + if (preset != nvngx::PRESET_DEFAULT) + params->Set(preset_key(quality), preset); + if (fx.exposure) params->Set(nvngx::EXPOSURE_TEXTURE, fx.exposure); + if (fx.transparency_mask) params->Set(nvngx::TRANSPARENCY_MASK, fx.transparency_mask); +} + +FfxDescription ffx_to_native(ID3D12GraphicsCommandList* list, const ffx::DispatchDescUpscale& fx) { + (void)list; + FfxDescription out{}; + out.color = static_cast(fx.color.resource); + out.output = static_cast(fx.output.resource); + out.depth = static_cast(fx.depth.resource); + out.motion_vectors = static_cast(fx.motionVectors.resource); + out.exposure = static_cast(fx.exposure.resource); + out.transparency_mask = static_cast(fx.transparencyAndComposition.resource); + // FFX's jitterOffset is the negative of what NGX wants (the shipped helper negates the game's half-pixel + // jitter; the game passes the NGX-convention values already, so they pass through unchanged). + out.jitter_x = fx.jitterOffset.x; + out.jitter_y = fx.jitterOffset.y; + // FFX's motionVectorScale is applied identically by NGX; only the 0-means-1.0 shipped rule rides on top. + out.mv_scale_x = fx.motionVectorScale.x; + out.mv_scale_y = fx.motionVectorScale.y; + out.sharpness = fx.enableSharpening ? fx.sharpness : 0.0f; + out.reset = fx.reset; + return out; +} + +Feature create(ID3D12GraphicsCommandList* list, const Description& desc, ID3D12Device* device, + unsigned int creation_node_mask) { + (void)device; + if (!core().enabled) return Feature{}; + nvngx::Parameter* params = nullptr; + if (core().allocate(¶ms) != nvngx::RESULT_SUCCESS || !params) return Feature{}; + const nvngx::PerfQualityValue quality = pick_quality(desc.upscale_ratio); + const int flags = create_flags(desc); + fill_create_params(params, desc, creation_node_mask, quality, flags); + Feature f; + f.params = params; + nvngx::Handle* handle = nullptr; + f.rc_create = core().create_feature(list, nvngx::FEATURE_SUPERSAMPLING, params, &handle); + f.ngx = handle; + f.quality = quality; + f.flags = flags; + f.preset = desc.preset; + return f; +} + +bool eval_from_ffx(Feature& f, ID3D12GraphicsCommandList* list, const FfxDescription& fx) { + if (!f.ngx || !f.params) return false; + fill_eval_params(f.params, fx, f.preset, f.quality); + return core().evaluate(list, f.ngx, f.params, nullptr) == nvngx::RESULT_SUCCESS; +} + +void destroy(Feature& f) { + if (f.ngx && core().enabled) core().release_feature(f.ngx); + f.ngx = nullptr; + if (f.params && core().enabled) core().destroy(f.params); + f.params = nullptr; +} + +} // namespace leonida::dlss diff --git a/runtime/src/dlss_backend.h b/runtime/src/dlss_backend.h new file mode 100644 index 000000000..62e34917c --- /dev/null +++ b/runtime/src/dlss_backend.h @@ -0,0 +1,105 @@ +// DLSS backend: the NVIDIA NGX path that the FFX-facing DLSS provider exposes. This is what a DLSS-enabled +// runtime builds on when the user's rig has the NGX Core (nvngx.dll from the driver, nvngx_dlss.dll next to the +// exe): the pure translation surface (pick_quality, create_flags, preset_key, the create/eval parameter-bag +// assembly) is exposed on its own so the unit tests can drive it without NGX, and the process-level bits +// (Core load, init, capability query, feature create/evaluate/release) wrap the driver's NGX D3D12 exports. +// The NGX declarations live in runtime/test/nvngx_api_min.h next to ffx_api_min.h; nothing of NVIDIA's SDK is +// vendored (their license forbids it) — only written-out declarations from the ABI and the public 310.6 guide. +#pragma once + +#include + +#include + +#include "../test/nvngx_api_min.h" +#include "../test/ffx_api_min.h" // declaration subset; ffx_to_native bridges its DispatchDescUpscale + +namespace leonida::dlss { + +// What the FFX create asks for, in DLSS terms. The flags are the FFX upscale context flags (the game passes +// HDR + low-res MVs + inverted depth + auto exposure on 1.0.2.1); `preset` is a DLSS.Hint.Render.Preset value +// (nvngx::PresetValue); the default 0 leaves the driver's OTA choice in place. +struct Description { + unsigned int render_width = 0; + unsigned int render_height = 0; + unsigned int upscale_width = 0; + unsigned int upscale_height = 0; + float upscale_ratio = 1.0f; // from the game's own ffxQuery(GETUPSCALERATIOFROMQUALITYMODE) + bool hdr = false; + bool mv_low_res = true; + bool mv_jittered = false; + bool depth_inverted = false; + bool auto_exposure = false; + int preset = nvngx::PRESET_DEFAULT; +}; + +// One dispatch's inputs. The plain ID3D12Resource* form is the native one the parameter bag wants; the FFX +// form (the game's ffx::DispatchDescUpscale carries ffx::Resource wrappers) is handled by the bridge below. +struct FfxDescription { + ID3D12Resource* color = nullptr; + ID3D12Resource* output = nullptr; + ID3D12Resource* depth = nullptr; + ID3D12Resource* motion_vectors = nullptr; + ID3D12Resource* exposure = nullptr; + ID3D12Resource* transparency_mask = nullptr; + float jitter_x = 0.0f; + float jitter_y = 0.0f; + float mv_scale_x = 0.0f; // 0 means 1.0 at eval, per the shipped helper + float mv_scale_y = 0.0f; + float sharpness = 0.0f; // deprecated upstream; stays 0 + bool reset = false; // scene transitions +}; + +struct Feature { + nvngx::Handle* ngx = nullptr; + nvngx::Parameter* params = nullptr; + nvngx::Result rc_create = 0; + nvngx::PerfQualityValue quality = nvngx::PERF_VALUE_MAX_QUALITY; + int flags = 0; + int preset = nvngx::PRESET_DEFAULT; // per-slot hint set at eval; 0 stays the OTA default +}; + +// The translation pieces, exposed on their own because the tests drive them without NGX (they are the +// game-measured mapping rules, not just implementation details): +// pick_quality — the FFX mode's ratio names the DLSS slot; the shipped-enum collisions resolve +// conservatively (3.0x keeps MaxPerf, 1.7237x keeps Balanced; 2.0-3.0 folds into +// UltraQuality, and the 1.71 cut is where the shipped values stop differing). +// create_flags — the bitmap the measured 1.0.2.1 FSR4 context translates to. +// effective_mv_scale — the shipped helper's 0-means-1.0 rule. +nvngx::PerfQualityValue pick_quality(float upscale_ratio); +int create_flags(const Description& desc); +float effective_mv_scale(float mv_scale); + +// The per-slot preset key for a quality mode (DLSS.Hint.Render.Preset.*), and whether the feature's preset +// hint should be set at all: the driver's OTA default stays untouched for PRESET_DEFAULT. +const char* preset_key(nvngx::PerfQualityValue quality); + +// The parameter-bag assembly, also driven by the tests (a mock nvngx::Parameter records the calls): the +// guide's create sequence (5.3, via the shipped NGX_D3D12_CREATE_DLSS_EXT helper) and the eval sequence +// (5.4, via NGX_D3D12_EVALUATE_DLSS_EXT). The preset hint goes into the bag before CreateFeature (guide +// 3.12: presets are selected per scaling-ratio slot on the create parameters) and is refreshed per eval. +void fill_create_params(nvngx::Parameter* params, const Description& desc, unsigned int creation_node_mask, + nvngx::PerfQualityValue quality, int flags); +void fill_eval_params(nvngx::Parameter* params, const FfxDescription& fx, int preset, + nvngx::PerfQualityValue quality); + +// The FFX-face bridge: pulls the game's ffx::DispatchDescUpscale into the native FfxDescription so the shim +// can feed one dispatch straight from the FFX front's upscale desc. Null ffx resources stay null on the NGX +// side; sharpness rides ffx's own enableSharpening flag (0 when unset, per the deprecated-key story). +FfxDescription ffx_to_native(ID3D12GraphicsCommandList* list, const ffx::DispatchDescUpscale& fx); + +// Process-level: loads the NGX Core by name (LEONIDA_NGX_DLL overrides), inits on device, checks capability. +bool init(ID3D12Device* device, const wchar_t* data_path); +bool initiated(); +void shutdown(ID3D12Device* device); + +// One DLSS feature per (description); destroying the previous one is the caller's business — NGX caches it +// internally, and the guide's release-then-create on state change keeps that cache warm. +Feature create(ID3D12GraphicsCommandList* list, const Description& desc, ID3D12Device* device, + unsigned int creation_node_mask); + +bool eval_from_ffx(Feature& f, ID3D12GraphicsCommandList* list, const FfxDescription& fx); + +void destroy(Feature& f); + +} // namespace leonida::dlss diff --git a/runtime/test/dlss_backend_unit_test.cpp b/runtime/test/dlss_backend_unit_test.cpp new file mode 100644 index 000000000..1bfa847eb --- /dev/null +++ b/runtime/test/dlss_backend_unit_test.cpp @@ -0,0 +1,209 @@ +// CPU-only unit test for the DLSS backend's translation rules: it drives the pure functions +// (pick_quality / create_flags / effective_mv_scale / preset_key) and, through a recording mock of the +// nvngx::Parameter ABI, the create/eval parameter-bag assembly (fill_create_params / fill_eval_params) — +// no D3D12 device and no NGX, so it runs everywhere and guards the game-measured mapping and the guide's +// 310.6 key order that the .cpp must not drift from. +#include +#include +#include + +#include "../src/dlss_backend.h" + +namespace { + +int g_failures = 0; + +void check(bool ok, const char* what) { + std::printf("%s %s\n", ok ? "PASS" : "FAIL", what); + if (!ok) ++g_failures; +} + +// A recording Parameter: every Set lands in a list of "name=value" words; Get answers are irrelevant here. +struct MockParameter final : nvngx::Parameter { + std::vector puts; + + std::string dump() const { + std::string out; + for (const std::string& w : puts) out += w + " "; + return out; + } + + void Set(const char* name, unsigned long long) override { puts.push_back(std::string(name) + "=ull"); } + void Set(const char* name, float) override { puts.push_back(std::string(name) + "=f"); } + void Set(const char* name, double) override { puts.push_back(std::string(name) + "=d"); } + void Set(const char* name, unsigned int) override { puts.push_back(std::string(name) + "=ui"); } + void Set(const char* name, int) override { puts.push_back(std::string(name) + "=i"); } + void Set(const char* name, ID3D11Resource*) override { puts.push_back(std::string(name) + "=r11"); } + void Set(const char* name, ID3D12Resource*) override { puts.push_back(std::string(name) + "=r12"); } + void Set(const char* name, void*) override { puts.push_back(std::string(name) + "=p"); } + nvngx::Result Get(const char*, unsigned long long*) const override { return nvngx::RESULT_FAIL; } + nvngx::Result Get(const char*, float*) const override { return nvngx::RESULT_FAIL; } + nvngx::Result Get(const char*, double*) const override { return nvngx::RESULT_FAIL; } + nvngx::Result Get(const char*, unsigned int*) const override { return nvngx::RESULT_FAIL; } + nvngx::Result Get(const char*, int*) const override { return nvngx::RESULT_FAIL; } + nvngx::Result Get(const char*, ID3D11Resource**) const override { return nvngx::RESULT_FAIL; } + nvngx::Result Get(const char*, ID3D12Resource**) const override { return nvngx::RESULT_FAIL; } + nvngx::Result Get(const char*, void**) const override { return nvngx::RESULT_FAIL; } + void Reset() override {} +}; + +void contains(const MockParameter& m, const char* word, const char* what) { + check(m.dump().find(word) != std::string::npos, what); +} + +} // namespace + +int main() { + std::setvbuf(stdout, nullptr, _IONBF, 0); + using leonida::dlss::pick_quality; + using leonida::dlss::create_flags; + using leonida::dlss::effective_mv_scale; + using leonida::dlss::preset_key; + using nvngx::PerfQualityValue; + + // pick_quality: the measured FFX slots of 1.0.2.1 — 1280x720 -> 1920x1080 is 1.5x. + check(pick_quality(1.5f) == nvngx::PERF_VALUE_MAX_QUALITY, "1.5x -> MaxQuality (the game's FSR Quality slot)"); + check(pick_quality(2.0f) == nvngx::PERF_VALUE_ULTRA_QUALITY, "2.0x -> UltraQuality"); + check(pick_quality(1.7f) == nvngx::PERF_VALUE_ULTRA_QUALITY, "1.7x -> UltraQuality"); + // The shipped-enum collisions: 1.7237x is Balanced's own ratio and UltraQuality does not win it. + check(pick_quality(1.7237f) == nvngx::PERF_VALUE_BALANCED, "1.7237x -> Balanced (shipped collision)"); + check(pick_quality(1.72f) == nvngx::PERF_VALUE_BALANCED, "1.72x -> Balanced"); + check(pick_quality(1.705f) == nvngx::PERF_VALUE_ULTRA_QUALITY, "1.705x -> UltraQuality (under the 1.71 cut)"); + check(pick_quality(3.0f) == nvngx::PERF_VALUE_MAX_PERF, "3.0x -> MaxPerf (shipped collision with UltraPerf)"); + check(pick_quality(2.99f) == nvngx::PERF_VALUE_ULTRA_QUALITY, "2.99x -> UltraQuality"); + check(pick_quality(4.0f) == nvngx::PERF_VALUE_MAX_PERF, "4.0x -> MaxPerf (UltraPerformance lives above 3.0)"); + check(pick_quality(1.06f) == nvngx::PERF_VALUE_MAX_QUALITY, "1.06x -> MaxQuality band"); + check(pick_quality(1.05f) == nvngx::PERF_VALUE_DLAA, "1.05x -> DLAA (boundary)"); + check(pick_quality(1.0f) == nvngx::PERF_VALUE_DLAA, "1.0x -> DLAA"); + + // create_flags: the measured 1.0.2.1 FSR4 context is HDR + low-res MVs + inverted depth + auto exposure + // (the game renders motion vectors at render resolution, so MV_LOW_RES rides the default). + leonida::dlss::Description game{}; + game.upscale_ratio = 1.5f; + game.hdr = true; + game.depth_inverted = true; + game.auto_exposure = true; + const int expect_game = nvngx::DLSS_FLAG_IS_HDR | nvngx::DLSS_FLAG_MV_LOW_RES | + nvngx::DLSS_FLAG_DEPTH_INVERTED | nvngx::DLSS_FLAG_AUTO_EXPOSURE; + check(create_flags(game) == expect_game, "game-measured context -> HDR|MVLowRes|DepthInverted|AutoExposure"); + leonida::dlss::Description all{}; + all.hdr = all.mv_low_res = all.mv_jittered = all.depth_inverted = all.auto_exposure = true; + const int expect_all = nvngx::DLSS_FLAG_IS_HDR | nvngx::DLSS_FLAG_MV_LOW_RES | nvngx::DLSS_FLAG_MV_JITTERED | + nvngx::DLSS_FLAG_DEPTH_INVERTED | nvngx::DLSS_FLAG_AUTO_EXPOSURE; + check(create_flags(all) == expect_all, "all set -> all bits"); + leonida::dlss::Description none{}; + check(none.mv_low_res == true, "mv_low_res defaults to true (the game renders MVs at render resolution)"); + check(create_flags(none) == nvngx::DLSS_FLAG_MV_LOW_RES, "defaults -> MV_LOW_RES only"); + + // effective_mv_scale: the shipped helper's 0-means-1.0 rule. + check(effective_mv_scale(0.0f) == 1.0f, "mv scale 0 -> 1.0"); + check(effective_mv_scale(0.5f) == 0.5f, "mv scale passes through"); + check(effective_mv_scale(-0.0f) == 1.0f, "negative zero -> 1.0 as well"); + + // preset_key: one key per quality slot. + check(preset_key(nvngx::PERF_VALUE_MAX_QUALITY) == nvngx::PRESET_KEY_QUALITY, "MaxQuality -> Quality preset key"); + check(preset_key(nvngx::PERF_VALUE_BALANCED) == nvngx::PRESET_KEY_BALANCED, "Balanced -> Balanced key"); + check(preset_key(nvngx::PERF_VALUE_MAX_PERF) == nvngx::PRESET_KEY_PERFORMANCE, "MaxPerf -> Performance key"); + check(preset_key(nvngx::PERF_VALUE_ULTRA_PERFORMANCE) == nvngx::PRESET_KEY_ULTRA_PERFORMANCE, + "UltraPerformance -> UltraPerformance key"); + check(preset_key(nvngx::PERF_VALUE_ULTRA_QUALITY) == nvngx::PRESET_KEY_ULTRA_QUALITY, + "UltraQuality -> UltraQuality key"); + check(preset_key(nvngx::PERF_VALUE_DLAA) == nvngx::PRESET_KEY_DLAA, "DLAA -> DLAA key"); + + // PresetValue enum: the shipped J/K/L/M numbering must not drift (K=11 transformer, L=12, M=13). + check(nvngx::PRESET_J == 10 && nvngx::PRESET_K == 11 && nvngx::PRESET_L == 12 && nvngx::PRESET_M == 13, + "preset enum keeps shipped numbering"); + + // Result codes: the guide's AllocateParameters fallback story (5.3) lives on FAIL_OutOfDate = |12. + check(nvngx::RESULT_SUCCESS == 1, "RESULT_SUCCESS = 1 (shipped enum)"); + check(static_cast(nvngx::RESULT_FAIL) == 0xBAD00000u, "FAIL base = 0xBAD00000"); + check(static_cast(nvngx::RESULT_FAIL_OUT_OF_DATE) == 0xBAD0000Cu, "FAIL_OutOfDate = base|12"); + check(static_cast(nvngx::RESULT_FAIL_NOT_INITIALIZED) == 0xBAD00007u, "FAIL_NotInitialized = base|7"); + + // create bag: the shipped helper's exact key and type order (NGX_D3D12_CREATE_DLSS_EXT), and the preset + // hint rides the bag before CreateFeature whenever a preset is named. + { + MockParameter m; + leonida::dlss::Description d{}; + d.render_width = 1280; + d.render_height = 720; + d.upscale_width = 1920; + d.upscale_height = 1080; + d.upscale_ratio = 1.5f; // the game's Quality slot + d.hdr = true; + d.preset = nvngx::PRESET_K; + leonida::dlss::fill_create_params(&m, d, 1, leonida::dlss::pick_quality(d.upscale_ratio), + leonida::dlss::create_flags(d)); + const char* expect = + "CreationNodeMask=ui VisibilityNodeMask=ui Width=ui Height=ui OutWidth=ui OutHeight=ui " + "PerfQualityValue=i DLSS.Feature.Create.Flags=i DLSS.Enable.Output.Subrects=i " + "DLSS.Hint.Render.Preset.Quality=i "; + check(m.dump() == expect, "create bag: helper key/type order + preset hint on the create bag"); + } + { + MockParameter m; + leonida::dlss::Description d{}; + d.render_width = 1280; + d.render_height = 720; + d.upscale_width = 1920; + d.upscale_height = 1080; + d.upscale_ratio = 1.5f; + leonida::dlss::fill_create_params(&m, d, 1, leonida::dlss::pick_quality(d.upscale_ratio), + leonida::dlss::create_flags(d)); + check(m.dump().find("Preset") == std::string::npos, + "create bag: PRESET_DEFAULT sets no preset key (OTA default stays)"); + } + + // eval bag: the shipped helper's exact key and type order (NGX_D3D12_EVALUATE_DLSS_EXT), optional + // resources skipped when null; the preset refresh lands with the reset/mv-scale group. + { + MockParameter m; + ID3D12Resource *color = reinterpret_cast(0x11), *out = reinterpret_cast(0x22); + leonida::dlss::FfxDescription fx{}; + fx.color = color; + fx.output = out; + fx.jitter_x = 0.25f; + fx.jitter_y = -0.125f; + fx.mv_scale_x = 0.0f; // the shipped 0-means-1.0 + fx.mv_scale_y = 0.5f; + fx.reset = true; + fx.exposure = reinterpret_cast(0x33); + leonida::dlss::fill_eval_params(&m, fx, nvngx::PRESET_J, nvngx::PERF_VALUE_MAX_QUALITY); + const char* expect = + "Color=r12 Output=r12 Jitter.Offset.X=f Jitter.Offset.Y=f Sharpness=f Reset=i " + "MV.Scale.X=f MV.Scale.Y=f DLSS.Hint.Render.Preset.Quality=i ExposureTexture=r12 "; + check(m.dump() == expect, "eval bag: helper key/type order, null depth/mv skipped, preset refreshed"); + } + + // sweep: across the plausible FFX ratio range, the bucket agrees with an independent, table-driven + // reference at every step — the .005-band edges (1.05/1.6/1.71/2.0/3.0), the 1.7237 collision band, + // and the 2.0-3.0 UltraQuality fold are each pinned at thousands of points, not just the edges. + { + auto reference = [](float r) { + // The table, written straight from the guide's Optimal Settings ratios (MaxQuality 1.5, + // UltraQuality 1.7, Balanced 1.7237, MaxPerf 3.0) and the shipped-enum conservatism. + if (r >= 3.0f) return nvngx::PERF_VALUE_MAX_PERF; + if (r >= 2.0f) return nvngx::PERF_VALUE_ULTRA_QUALITY; + if (r > 1.71f) return nvngx::PERF_VALUE_BALANCED; // 1.7237x, the Balanced band up to 2.0 + if (r > 1.6f) return nvngx::PERF_VALUE_ULTRA_QUALITY; + if (r > 1.05f) return nvngx::PERF_VALUE_MAX_QUALITY; + return nvngx::PERF_VALUE_DLAA; + }; + bool ok = true; + float first_bad = 0.0f; + for (int step = 0; step <= 3500; ++step) { + const float r = 1.0f + step * 0.001f; + if (leonida::dlss::pick_quality(r) != reference(r)) { + ok = false; + first_bad = r; + break; + } + } + check(ok, "sweep 1.0..4.5 @0.001: pick_quality matches the ratio table at every step"); + if (!ok) std::printf(" first mismatch at %.3f\n", first_bad); + } + + std::printf("dlss_backend_unit: %s (%d failure%s)\n", g_failures ? "FAILED" : "OK", g_failures, + g_failures == 1 ? "" : "s"); + return g_failures ? 1 : 0; +} diff --git a/runtime/test/nvngx_api_min.h b/runtime/test/nvngx_api_min.h new file mode 100644 index 000000000..2b58813c8 --- /dev/null +++ b/runtime/test/nvngx_api_min.h @@ -0,0 +1,173 @@ +// The subset of the NVIDIA NGX interface that dlss_backend_unit_test.cpp and src/dlss_backend.cpp call, written out +// from the ABI as shipped: +// - the export names, from a PE export-table dump of the driver's NGX Core (nvngx.dll, 310.x line, D3D12 section +// read here: NVSDK_NGX_D3D12_{Init_ProjectID, Init_Ext, Init, AllocateParameters, GetCapabilityParameters, +// GetParameters, CreateFeature, EvaluateFeature, ReleaseFeature, DestroyParameters, GetScratchBufferSize, +// Shutdown, Shutdown1}); +// - the 17-virtual-slot parameter object, as the SDK ships it (single-inheritance MSVC vtable; the order below +// exercised end to end by a probe that runs Init/Capability/Create/Evaluate on real hardware); +// - the semantics of the create/evaluate parameters, documented in the public DLSS Programming Guide (310.6, +// sections 5.2 to 5.4, key strings and flag bits included). +// Nothing from the NVIDIA DLSS SDK is copied here: those files carry the NVIDIA RTX SDK license, which forbids +// making them subject to an open-source license; nvngx_dlss.dll itself is a user-side component (the driver's +// NGX Core loads it, and the game-side copy lives next to the executable per the guide's distribution section). +#pragma once + +#include + +typedef struct ID3D11Resource ID3D11Resource; +typedef struct ID3D12Resource ID3D12Resource; + +namespace nvngx { + +using Result = int; +using Version = int; +using EngineType = int; +using Feature = int; // NVSDK_NGX_Feature_SuperSampling = 1 + +constexpr Result RESULT_SUCCESS = 0x1; +constexpr Result RESULT_FAIL = static_cast(0xBAD00000u); +constexpr Result RESULT_FAIL_FEATURE_NOT_SUPPORTED = RESULT_FAIL | 1; +constexpr Result RESULT_FAIL_PLATFORM_ERROR = RESULT_FAIL | 2; +constexpr Result RESULT_FAIL_FEATURE_ALREADY_EXISTS = RESULT_FAIL | 3; +constexpr Result RESULT_FAIL_FEATURE_NOT_FOUND = RESULT_FAIL | 4; +constexpr Result RESULT_FAIL_INVALID_PARAMETER = RESULT_FAIL | 5; +constexpr Result RESULT_FAIL_NOT_INITIALIZED = RESULT_FAIL | 7; +constexpr Result RESULT_FAIL_OUT_OF_DATE = RESULT_FAIL | 12; // an older driver: the deprecated GetParameters fallback + +constexpr Version SDK_VERSION = 0x15; // NVSDK_NGX_Version_API of the 310.6 release (NVNGX version 1.5.0) +constexpr EngineType ENGINE_CUSTOM = 0; +constexpr Feature FEATURE_SUPERSAMPLING = 1; + +// DLSS create flags, as the guide documents them (section 5.3) and the runtime checks them. +constexpr int DLSS_FLAG_IS_HDR = 1 << 0; +constexpr int DLSS_FLAG_MV_LOW_RES = 1 << 1; +constexpr int DLSS_FLAG_MV_JITTERED = 1 << 2; +constexpr int DLSS_FLAG_DEPTH_INVERTED = 1 << 3; +constexpr int DLSS_FLAG_AUTO_EXPOSURE = 1 << 6; + +// PerfQualityValue, the shipped enum order (guide section 5.2.8.1): MaxPerf=MaxPerformance, MaxQuality=Quality. +enum PerfQualityValue { + PERF_VALUE_MAX_PERF = 0, // 3.0x + PERF_VALUE_BALANCED = 1, // 1.7237x + PERF_VALUE_MAX_QUALITY = 2, // 1.5x + PERF_VALUE_ULTRA_PERFORMANCE = 3, // 3.0x, extended slot + PERF_VALUE_ULTRA_QUALITY = 4, // 1.7x, extended slot + PERF_VALUE_DLAA = 5, // 1.0x +}; + +// DLSS.Hint.Render.Preset values (guide 5.2.8.2, the 310.6 enum). Default keeps whatever the OTA brings; the +// live presets are J/K/L/M (K is the transformer one recommended for DLAA/Balanced/Quality, L is Ultra Perf's, +// M is Perf's); the rest are deprecated or reserved. +enum PresetValue { + PRESET_DEFAULT = 0, + PRESET_E = 5, + PRESET_F = 6, + PRESET_J = 10, + PRESET_K = 11, + PRESET_L = 12, + PRESET_M = 13, +}; + +// The opaque object Allocate/Get(Capability)Parameters hands out: 17 virtual slots, single-inheritance vtable, +// declared in this exact order (verified at runtime; changing the order changes the ABI). +struct Parameter { + virtual void Set(const char* name, unsigned long long value) = 0; + virtual void Set(const char* name, float value) = 0; + virtual void Set(const char* name, double value) = 0; + virtual void Set(const char* name, unsigned int value) = 0; + virtual void Set(const char* name, int value) = 0; + virtual void Set(const char* name, ID3D11Resource* value) = 0; + virtual void Set(const char* name, ID3D12Resource* value) = 0; + virtual void Set(const char* name, void* value) = 0; + virtual Result Get(const char* name, unsigned long long* out) const = 0; + virtual Result Get(const char* name, float* out) const = 0; + virtual Result Get(const char* name, double* out) const = 0; + virtual Result Get(const char* name, unsigned int* out) const = 0; + virtual Result Get(const char* name, int* out) const = 0; + virtual Result Get(const char* name, ID3D11Resource** out) const = 0; + virtual Result Get(const char* name, ID3D12Resource** out) const = 0; + virtual Result Get(const char* name, void** out) const = 0; + virtual void Reset() = 0; +}; + +// Where the NGX Core looks for feature dlls beyond the application folder (guide section 5.1), plus the +// logging block the Core reads whenever the caller declares an SDK version that knows it (0x14+; 0x15 is +// passed). The layout matches the shipped struct exactly: 16-byte path list (pointer + length + pad), +// the opaque internal slot, and the inline 16-byte logging record. A shorter record ends the process at +// init with 0xc0000005 (the Core dereferences/reads past the shorter object — observed), which is why the +// logging record is inlined bytes, not a pointer the zeroing would hide behind. +struct PathListInfo { + const wchar_t* const* path; + unsigned int length; +}; +typedef void(__cdecl* AppLogCallback)(const char* message, int logging_level, Feature source); +struct LoggingInfo { + AppLogCallback callback; // app-side sink; null keeps the Core's defaults + int minimum_level; // 0 off / 1 on / 2 verbose + bool disable_other_sinks; // true requires a non-null callback +}; +struct FeatureCommonInfo { + PathListInfo pathList; + void* internal; // engine-managed + LoggingInfo logging; +}; + +// The Core reads these records by the shipped layout; a mismatch is a silent ABI break, so pin the sizes. +static_assert(sizeof(PathListInfo) == 16, "PathListInfo must match the shipped 16-byte record"); +static_assert(sizeof(LoggingInfo) == 16, "LoggingInfo must match the shipped 16-byte record"); +static_assert(sizeof(FeatureCommonInfo) == 40, "FeatureCommonInfo must total the shipped 40-byte record"); + +typedef struct Handle Handle; // opaque, from CreateFeature, consumed by Evaluate/Release + +// Function signatures exactly as the NGX Core exports them (the short Init name; the SDK's longer +// NVSDK_NGX_D3D12_Init_with_ProjectID is a wrapper around it). +using PfnInitWithProjectId = Result (*)(const char* project_id, EngineType engine, const char* engine_version, + const wchar_t* data_path, ID3D12Device* device, + const FeatureCommonInfo* info, Version version); +using PfnAllocateParameters = Result (*)(Parameter**); +using PfnGetCapabilityParameters = Result (*)(Parameter**); +using PfnCreateFeature = Result (*)(ID3D12GraphicsCommandList*, Feature, Parameter*, Handle**); +using PfnEvaluateFeature = Result (*)(ID3D12GraphicsCommandList*, const Handle*, Parameter*, void* callback); +using PfnReleaseFeature = Result (*)(Handle*); +using PfnDestroyParameters = Result (*)(Parameter*); +using PfnShutdown1 = Result (*)(void* device); + +// The parameter keys this integration reads or writes (string values documented in the guide 5.2-5.5 and +// exercised by the runtime). +constexpr const char* CREATION_NODE_MASK = "CreationNodeMask"; +constexpr const char* VISIBILITY_NODE_MASK = "VisibilityNodeMask"; +constexpr const char* WIDTH = "Width"; +constexpr const char* HEIGHT = "Height"; +constexpr const char* OUT_WIDTH = "OutWidth"; +constexpr const char* OUT_HEIGHT = "OutHeight"; +constexpr const char* PERF_QUALITY_VALUE = "PerfQualityValue"; +constexpr const char* DLSS_CREATE_FLAGS = "DLSS.Feature.Create.Flags"; +constexpr const char* DLSS_ENABLE_OUTPUT_SUBRECTS = "DLSS.Enable.Output.Subrects"; +constexpr const char* COLOR = "Color"; +constexpr const char* OUTPUT = "Output"; +constexpr const char* DEPTH = "Depth"; +constexpr const char* MOTION_VECTORS = "MotionVectors"; +constexpr const char* JITTER_OFFSET_X = "Jitter.Offset.X"; +constexpr const char* JITTER_OFFSET_Y = "Jitter.Offset.Y"; +constexpr const char* MV_SCALE_X = "MV.Scale.X"; +constexpr const char* MV_SCALE_Y = "MV.Scale.Y"; +constexpr const char* RESET = "Reset"; +constexpr const char* SHARPNESS = "Sharpness"; +constexpr const char* EXPOSURE_TEXTURE = "ExposureTexture"; +constexpr const char* TRANSPARENCY_MASK = "TransparencyMask"; +constexpr const char* SUPER_AVAILABLE = "SuperSampling.Available"; +constexpr const char* SUPER_NEEDS_UPDATED_DRIVER = "SuperSampling.NeedsUpdatedDriver"; +constexpr const char* SUPER_MIN_DRIVER_VERSION_MAJOR = "SuperSampling.MinDriverVersionMajor"; +constexpr const char* SUPER_MIN_DRIVER_VERSION_MINOR = "SuperSampling.MinDriverVersionMinor"; +constexpr const char* SUPER_FEATURE_INIT_RESULT = "SuperSampling.FeatureInitResult"; +// Per-slot render preset hints (310.6): the int value is a member of PresetValue; setting the slot that +// matches the feature's quality mode overrides which network preset runs. +constexpr const char* PRESET_KEY_DLAA = "DLSS.Hint.Render.Preset.DLAA"; +constexpr const char* PRESET_KEY_ULTRA_QUALITY = "DLSS.Hint.Render.Preset.UltraQuality"; +constexpr const char* PRESET_KEY_QUALITY = "DLSS.Hint.Render.Preset.Quality"; +constexpr const char* PRESET_KEY_BALANCED = "DLSS.Hint.Render.Preset.Balanced"; +constexpr const char* PRESET_KEY_PERFORMANCE = "DLSS.Hint.Render.Preset.Performance"; +constexpr const char* PRESET_KEY_ULTRA_PERFORMANCE = "DLSS.Hint.Render.Preset.UltraPerformance"; + +} // namespace nvngx