Engine: native presets K and M in the D3D12 shim, wider game coverage

A standalone Vulkan inference engine (engine/) for DLSS presets K and M that
runs from weights extracted from the user's own nvngx_dlss.dll, with d4r's
own input, network and reconstruction shaders or the native HIP network
layers, recorded into the game's command list by the shim. Opt-in
([Engine] Enabled / D4R_ENGINE=1); anything uncovered falls back to the
CUDA/ZLUDA path with the reason logged.

Byte-identical to NGX's CUDA backend under the phase-capable reference
(1706x960 -> 2560x1440, native HIP network, eleven frames, RX 9070 XT):
- K render- and display-resolution motion vectors, HDR and LDR
- K game-supplied exposure and automatic exposure with any pre-exposure
  and exposure scale (one residual: effective exposure exactly 2 or 4)
- K and M with the DLSS indicator's inverted-axis parameters
- M with any exposure settings (NGX ignores them for M)
K packages need the current compile_k.py (marker D4RO0003).

Also: HIP shared buffers are pooled across feature recreation (ROCm leaks
destroyed imports), hipnet.bin must match the preset, M-only games do not
load the K model, install_d4r_runtime.sh stages k, k-ldr, m, m-ldr with
hip/, the activation table has a generator (gen_activation_m.py), and
package_release.sh can bundle the engine's shaders (never its weights).

Signed-off-by: woutermans <[email protected]>
This commit is contained in:
woutermans committed 2026-10-10 20:54:01 +02:00
1 parent 16cfc1f063
commit e0d1549a21
82 files changed
+13335 -96

No files matched your search

+11 -1
View File
@@ -86,6 +86,15 @@ Settings
PreferAccuracy = true. This uses original translated enc1/enc2 layers while retaining other
native acceleration. It reduced trails in a captured Townfall sequence on RX 7700 XT and costs
some GPU time. Restart after changing it; other scenes and RDNA4 hardware still need testing.
- [Engine] Enabled = true (experimental, off by default) runs DLSS 4 (K) and 4.5 (M) on d4r's own Vulkan
inference engine: the upscale is recorded into the game's own frame instead of going through CUDA
emulation. It needs Mesa RADV with VK_KHR_cooperative_matrix and the models in d4r/engine/k (K),
d4r/engine/k-ldr (K in games without HDR), d4r/engine/m and d4r/engine/m-ldr (M). Games and settings
it does not cover (other models, display-resolution motion vectors with M) keep using the normal path,
and d4r/d4r_nvngx.log says which one ran and why. Tested in one game so far.
This zip has only the engine's shaders in d4r/engine/k. The weights (weights.bin, offsets.bin,
lut.bin) are read from your own nvngx_dlss.dll with the tools in d4r's source repository
(engine/README.md); until they are there, d4r uses the normal path.
- OptiScaler.ini: OptiScaler's settings, such as its fps overlay and the render resolution of each
quality mode. Press Insert in game for OptiScaler's menu.
[Libraries] NvngxPath=d4r\nvngx.dll explicitly selects d4r's shim; OptiDllPath=d4r is also
@@ -152,7 +161,8 @@ Licenses
d4r is GNU General Public License, version 3 only (GPL-3.0-only). The release also contains ZLUDA (Apache 2.0 or MIT), vkd3d-proton
(LGPL 2.1, patched) and OptiScaler 0.9.4 (GPL 3.0, unmodified). d4r/source/SOURCES.txt says where
each file comes from, and d4r/licenses has the license texts. d4r is not affiliated with NVIDIA,
AMD or the OptiScaler project.
AMD or the OptiScaler project, and is provided "as is", without warranty of any kind (GPL-3.0,
sections 15 and 16).
@clean NVIDIA's files are yours to supply, under NVIDIA's terms.
@full NVIDIA's files in this zip (d4r/nvngx_dlss.dll, d4r/ngx/_nvngx.dll) and the kernels built from
@full NVIDIA's code (listed in d4r/source/SOURCES.txt) are NVIDIA's property, are not covered by
+7
View File
@@ -1,5 +1,12 @@
# Unreleased
- `scripts/check_redistributable.py` refuses NVIDIA's binaries, NGX SDK headers, PTX and code objects, d4r's PTX translations and the engine's model data. `scripts/package_release.sh` runs it on every release before zipping, CI runs it on every push and pull request, and `git config core.hooksPath scripts/git-hooks` runs it before each commit. `LEGAL.md` describes what d4r publishes; `CONTRIBUTING.md` requires signed-off commits.
- Native engine fixes: the K adapter now passes the game's exposure scale to the exposure shader (it was silently ignored); the HIP network's shared buffers are reused across feature recreation instead of leaking their ROCm mapping (21 → 6 imports over seven K features in the harness); `hipnet.bin` must belong to the preset being created; an M-only game no longer loads the K model; `scripts/install_d4r_runtime.sh` stages `engine/k-ldr` and each model's `hip/` folder.
- Native engine, preset K: output is now byte-identical to the CUDA reference over an eleven-frame sequence at Quality (1706×960 → 2560×1440, native HIP network, RX 9070 XT), where later frames previously fell to 47–51 dB. The engine now selects NGX's reconstruction table by upscaling ratio instead of using one table for every ratio, and two rounding-order differences in the input and output stages are gone. K models must be rebuilt (`prepare_k.py`, `compile_k.py`); older packages still load and behave as before.
- Native engine, wider game coverage (K packages must be rebuilt with the current `compile_k.py`, marker `D4RO0003`; older packages keep refusing the new cases with a logged reason):
- Preset K accepts display-resolution motion vectors (MVLowRes clear; output-sized, in output pixels). Byte-identical to the phase-capable CUDA reference over eleven frames at 1706×960 → 2560×1440 (HDR, create flags 0x49) and 1712×960 → 2560×1440 (LDR, 0x68), and over three frames at 1280×720 → 2560×1440. The reference must use a ZLUDA with patch 0008; the old bundled library omits K's bottleneck post phases and is itself off by ~33 dB. Preset M still uses the CUDA backend for display-resolution vectors.
- Preset K accepts a game-supplied exposure texture (AutoExposure off) and any positive exposure scale and pre-exposure in both the automatic and the game path. With the native HIP network at 1706×960 → 2560×1440, HDR K is byte-identical to the CUDA backend over eleven frames for automatic exposure with scale and pre-exposure 1/0.5/0.7/2/3 (and combinations) and for game textures 0.4–32, except an effective exposure of exactly 2 or 4 (first differing frame 104.7 dB / 112.8 dB, then ≈49–63 dB); LDR ignores the exposure and is byte-identical for any value. Preset M accepts the AutoExposure flag, an exposure texture, pre-exposure and exposure scale, which NGX ignores for M (CUDA and engine output identical for each).
- Presets K and M accept the DLSS indicator's inverted-axis parameters, which only place NGX's debug indicator (NGX and engine output byte-identical with and without them), regular (non-inverted) depth (K), and output subrectangles (not yet run in the harness).
- Merge the RDNA4 token-lane Swin and hardware-FP8 texture-tail optimizations, preserving MicroCUDA's allocation-identity tube weight cache.
- Add opt-in packed R10G10B10A2 and in-place DLSS output, with vkd3d-proton patches `0001`–`0003`. In-place mappings retain their source textures until process exit; output recreation can increase retained VRAM.
- Fix deferred input-marker ordering: wait for the game's GPU copies before CUDA uploads or diagnostic readbacks, not just before NGX evaluation.
+9 -7
View File
@@ -37,17 +37,19 @@ Third-party software, unmodified or patched by d4r:
@clean Not included: NVIDIA's DLSS library (nvngx_dlss.dll) and NGX runtime (_nvngx.dll). You supply them
@clean and are responsible for complying with NVIDIA's license terms.
@full NVIDIA's software, not covered by any license in d4r/licenses and included by whoever distributes
@full this zip, not by NVIDIA:
@full NVIDIA's software, not covered by any license in d4r/licenses and included by whoever built this
@full zip, not by NVIDIA. NVIDIA's license does not permit redistributing it; do not share this zip:
@full d4r/nvngx_dlss.dll NVIDIA DLSS Super Resolution library @DLSS_VERSION@
@full d4r/ngx/_nvngx.dll NVIDIA NGX runtime from NVIDIA's Windows display driver, @NGX_VERSION@
@installer NVIDIA DLLs are not bundled. install.sh downloads DLSS 310.7.0 from NVIDIA/DLSS
@installer commit a291cc7d2cc642a51566f3dfd5376f635cd1b284 and _nvngx.dll from NVIDIA driver 596.36.
@installer URLs and SHA-256 hashes are pinned in install.sh. NVIDIA license terms apply.
@installer Included NVIDIA PTX-derived kernels (not covered by d4r licenses):
@installer d4r/kernels/*/hiluma_engine_output_*, rrlite_enc0_*, rrlite_dec0_*, rrlite_post_*, rrlite_downsample_*
@installer compiled from DLSS PTX by ZLUDA (kernels/tex in this repository).
@full d4r/kernels/*/hiluma_engine_output_*, rrlite_enc0_*, rrlite_dec0_*, rrlite_post_*, rrlite_downsample_*
@full DLSS kernels: NVIDIA's PTX from nvngx_dlss.dll with parts replaced by d4r code
@full (kernels/tex in the d4r repository), compiled by ZLUDA
@installer d4r/kernels/*/hiluma_engine_*, rrlite_enc0_*, rrlite_dec0_*, rrlite_post_*, rrlite_downsample_*
@installer NVIDIA's PTX with parts replaced by d4r code (kernels/tex) or translated to
@installer HIP (kernels/native), compiled by ZLUDA or ROCm's clang.
@full d4r/kernels/*/hiluma_engine_*, rrlite_enc0_*, rrlite_dec0_*, rrlite_post_*, rrlite_downsample_*
@full DLSS kernels: NVIDIA's PTX from nvngx_dlss.dll, with parts replaced by d4r code
@full (kernels/tex in the d4r repository) or translated to HIP (kernels/native),
@full compiled by ZLUDA or ROCm's clang
d4r is not affiliated with NVIDIA, AMD or the OptiScaler project.
+13
View File
@@ -60,6 +60,19 @@ ElideNgxSync = true
; effect only while d4r's own output kernel runs, which it does when the DLSS library matches.
DirectOutput = auto
[Engine]
; Experimental. Runs DLSS 4 and 4.5 (models K and M) on d4r's own Vulkan inference engine instead of NVIDIA's
; kernels: the game shows the result of the frame it just rendered and [Latency] / [Interop] do not apply.
; Needs Mesa RADV with VK_KHR_cooperative_matrix and the models in d4r\engine\k, k-ldr, m and m-ldr
; (see D4R_README.txt). Games or settings it does not cover use the normal path; d4r_nvngx.log says why.
Enabled = false
; Another model K folder for games with the HDR flag (a path relative to the d4r folder, or a Windows path
; such as Z:\home\me\k)
ModelDir = auto
; auto / hip = the network on d4r's native HIP layer kernels when the model folder has them (faster),
; vulkan = on the engine's shader
Network = auto
[Paths]
; Linux paths.
; ROCm installation (default: the ROCm runtime in d4r\rocm, else /opt/rocm)