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

+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.