Commit Graph
84 Commits
Author SHA1 Message Date
woutermans dbef6f794e docs: pair the output-kernel numbers from the same run 2026-10-12 12:47:53 +02:00
woutermans 0dc2397e2b shim/harness: capture and replay a frame's Ray Reconstruction guides exactly
A replay only means something if the denoiser gets the bytes the game gave it.
The capture now records, for every bound guide, the caller's own DXGI format and
texel size next to the plane (they differ from the CUDA array's for every
converted format, and B8G8R8A8_UNORM is four bytes to D3D12 and sixteen to the
float array), the names the caller registered each surface under as well as the
names the denoiser reads it as, the exposure texture's own geometry, and the
feature's creation state - dimensions, quality, create flags, output-subrect
setting and the effective render preset. A frame whose staging is not readable
aborts its whole capture instead of writing a descriptor without its plane.

The harness reads all of it back: it sizes and creates the feature from the
capture, creates each guide in the recorded format at the recorded size, uploads
the recorded bytes, applies the recorded scalars, subrect origins, inversion
flags and camera matrices, binds the exact source names and clears the ones the
frame stopped registering. A missing guide descriptor, a missing or mis-sized
plane, a truncated parameter line, a claimed exposure with no geometry, or a
capture taken before the creation state was recorded is refused rather than
filled in with a default, because a replay that invents any of it still renders
a plausible image that matches nothing the game produced.
2026-10-12 12:47:53 +02:00
woutermans 74ce9d8f9a kernels: build the denoiser's output kernel natively, authorized separately
Ray Reconstruction's eleven DLSS-D Swin layers still run ZLUDA's compile of
NVIDIA's PTX; at 1280x720 -> 3840x2160 on gfx1201 they are 30.2 of a 31.6 ms
frame. The denoiser's high-fidelity output kernel is the first one with a native
replacement: make_ptx.py replaces its whole-texel RGBA16F store
(sust.b.2d.v4.b16.zero) through d4r_sust_v4b16, kernels/build.sh builds the pair
as the `rr` family, and packaging builds it into every target folder including
the RDNA4 FP8 ones.

Both libraries define modules named cuda_dldn_engine_*, with different text, so
one manifest cannot take the union of their hashes: kernel_manifest.py now takes
the denoiser DLL as --rr-dll and lets only its hashes authorize a
cuda_dldn_engine_* binary, and package_release.sh passes it when the denoiser is
bundled.

Verified in the D3D12 harness with Ray Reconstruction at 1280x720 -> 3840x2160:
the output kernel drops from 1.44 to 1.00 ms/frame and the 66 MB raw output is
byte-identical to the run with every kernel translated.

docs/native-kernels.md gains the denoiser family, the per-kernel cost table and
the instruction counts that show why the Swin layers are the remaining work.
2026-10-12 12:47:53 +02:00
woutermans 56e1b76622 Restore behavioral render preset override coverage 2026-10-12 12:47:53 +02:00
woutermans bd343a7be1 Drop brittle shim source-text checks after rebase 2026-10-12 12:47:53 +02:00
woutermans 5461c161f3 Keep RR guides and separate alpha in VRAM 2026-10-12 12:47:53 +02:00
woutermans 7117c38674 Add CUDA NGX Ray Reconstruction support
Run the signed CUDA-capable denoiser through feature 13 with independent D/E presets, pre-Init discovery, per-frame guide and camera snapshots, normalized integer guide staging, paired alpha output, and recorded-resource retirement.

Add the required ZLUDA/LLVM patch, behavioral configuration tests, GPU harness coverage, optional denoiser installation and packaging, and tested support limitations. Preserve upstream attribution and distinguish LLVM licensing from the ZLUDA portions of the patch.
2026-10-12 12:47:53 +02:00
ayo 503061d568 x4r 2026-10-12 05:37:36 -04:00
woutermans 37d1055228 Engine: support dynamic input resolution for presets K, L and M 2026-10-11 20:45:26 +02:00
woutermans 653460f7b2 Engine: native preset L (rrlite unfolded input, expansion and reconstruction stages) 2026-10-10 23:58:18 +02:00
Woutermans de37ca5869 Merge pull request #33 from woutermans/engine-native-pr
Native engine for presets K and M in the shim, wider game coverage, redistribution guard
2026-10-10 21:27:41 +02:00
woutermans 2088422682 Add redistribution guard
scripts/check_redistributable.py refuses NVIDIA binaries (by name and
version resource), NGX SDK headers, PTX and code objects, PTX translations
(marked by ptx2glsl.py/condense.py) and the engine's model data in the
repository, and in each release variant (clean/installer/full) whatever
that variant does not contain. package_release.sh runs it before zipping;
scripts/git-hooks/pre-commit runs it locally.

Signed-off-by: woutermans <[email protected]>
2026-10-10 20:54:31 +02:00
woutermans e0d1549a21 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]>
2026-10-10 20:54:01 +02:00
ayo 16cfc1f063 mt 2026-10-09 04:32:45 -04:00
ayo 694a7a0126 Add experimental native Vulkan DLSS frontend
Implement NGX's Vulkan API over the existing CUDA backend. Compute shaders
pack the game's sampled images into buffers shared with CUDA (device-local
memory exported through the Wine bridge), and a device event in the game's
command buffer holds its queue until the result is written back, keeping
frame age at zero. DLSS reads inputs through pitch-linear textures and its
native output kernel writes the shared buffer directly; input and
completion waits are adaptive.

Make it work across engines: shared buffers are concurrent over every
compute-capable queue family (Indiana Jones records DLSS on async compute),
depth kept in an R32F colour image is accepted under a depth aspect, and the
extension-requirement query allows a null list. Spare buffer sets are
imported on the first frame and never while a frame is pending, since an
import can block on GPU work that is waiting for us; host staging covers any
shortfall.

Fix two exit hazards. A game quitting without NGX shutdown left the GPU
waiting on an event that only a killed thread would set, resetting the ring
10 s later: the bridge now runs a shim hook before teardown and skips all
CUDA destroy/sync calls once Wine is shutting the process down. The shim's
own entry point skips CRT static destructors at process termination, where
locks held by killed threads made the exit spin forever.

Add a Vulkan DLSS harness (dynamic, recreate, discard, invalid, exit,
compute-queue and in-flight modes), staging/depth probes, ABI/config tests,
and an OptiScaler settings overlay for Vulkan games.
2026-10-09 02:57:23 -04:00
ayo 18c694eecb Change d4r license to GPL-3.0-only 2026-10-08 17:17:44 -04:00
ayo fb244c1ef9 i love gitignore 2026-10-08 16:04:26 -04:00
ayo 4d5952bdb4 no idea how that got there 👀 2026-10-08 16:04:08 -04:00
ayo 12782b3ff6 Merge pull request #31 from lunar-me/fix-docs/issue-012
docs: fix wrong article before `d4r.ini
2026-10-08 20:26:31 +01:00
ayo c276548dab Merge pull request #32 from lunar-me/fix-docs/issue-013
docs: fix wrong article before d4r folder in the packaging readme
2026-10-08 20:26:24 +01:00
ayo e86131d396 Merge pull request #30 from lunar-me/fix-docs/issue-011
docs: fix wrong article before `d4r` folder
2026-10-08 20:26:10 +01:00
pi ce7d0ec34a docs: fix documentation (grammar-minor-003) 2026-10-09 05:11:57 +13:00
pi 77886fd07a docs: fix documentation (grammar-minor-002) 2026-10-09 05:11:48 +13:00
pi 9060d3c076 docs: fix documentation (grammar-minor-001) 2026-10-09 05:11:38 +13:00
woutermans 934fb486c7 Clamp the patch merge to ±2π in the native Swin encoders
NVIDIA's enc1 and enc2 clamp the patch merge's result to ±2π (as f16) before
its e4m3 encoding (max.f16x2 / min.f16x2 with 0fC0C90FDB / 0f40C90FDB after the
merge's last MMA). The native layers did not, in either template or set:
merge_clamp (swin_common.h) now does, at the three sites that encode the merged
tokens (swin_block.h's e4m3-activation and f16 paths, swin_tok.h), and
swin_check.py's model clamps the same way.

Measured on an RX 9070 XT against a run with no native kernels (preset L,
accuracy set, the flags of Ghost of Tsushima, 1280x720 -> 3840x2160, one
frame): native enc1 alone 34 dB and enc2 alone 31 dB from the translated
kernels before, byte-identical after; the whole native set 28 -> 80 dB (the
rest is dec1, 0.09% of the output values). Preset M's fast set against
translated M: 30.8 -> 35.1 dB after 30 frames. The gfx11 path has the same
change and was not run on hardware.

The repo's tests pass (36, 3 skipped).
2026-10-08 02:21:41 +02:00
Woutermans 62738a01cc Merge pull request #29 from woutermans/sr-native-layout
Preset L: native token-lane enc0 and dec0 on RDNA4 native FP8
2026-10-08 02:08:06 +02:00
woutermans 8813ea723c kernels/tex: native token-lane parts for preset L's enc0 and dec0
L's unfolded enc0 and dec0 are still ZLUDA's compile of NVIDIA's PTX and cost
2.95 ms of the preset's 5.86 ms per frame (RX 9070 XT, 1280x720 -> 4K). The
embedding, the patch expand, the Swin block (32 channels, 2 heads, at pixel
resolution) and the patch merge are now native token-lane code; the texture
work around them stays ZLUDA's compile.

enc0l_tail.hip cuts in at the barrier after the feature staging and dec0l_block.hip
before the output code that reads the block's f16 result out of the last MMAs; make_ptx.py
splices either in when D4R_TEX_SRC names it and build.sh selects both for the gfx12
native-FP8 builds. swin_tex.h carries the indexing the two tails share; swin_tok.h gains
the pixel-order token layout (SWIN_TOK_NATURAL), ZLUDA's attention key order
(SWIN_PV_ZLUDA_ORDER) and swin_tok_core, which the encoded tests reuse. swin_common.h
takes the block weight layout (moved out of swin_block.h) and the exact and approximate
reciprocal / mix forms the tails need without the HIP headers (D4R_NO_HIP_RUNTIME).

The f32 sums stay in ZLUDA's order (K slots of the FP8 WMMAs, key order of the f16
attention product) and rsqrt/rcp use the hardware approximations ZLUDA lowers to, so the
harness's final frame is byte-identical to the translated kernels: all four enc0 flag
variants, 720p and 1080p render, 1440p and 4K output, static and moving scenes, 100
frames, and the accuracy set. With M's own sum order about one token in 20,000 differed.
M's layers compile to the same instructions and its frame is byte-identical.

enc0 1.69 -> 0.63 ms and dec0 1.26 -> 0.54 ms at 720p->4K, 2.73 -> 1.16 and 2.28 -> 1.01
at 1080p->4K; the preset 5.83 -> 4.06 and 8.63 -> 5.69 ms. -DD4R_SWIN_K32_MIX rounds the
f16 products earlier for 0.56 and 0.49 ms and is not byte-identical, so it is not built by
default. The repo's tests pass (36, 3 skipped).
2026-10-08 01:08:34 +02:00
ayo 0a12b6ce16 Add NVIDIA DLL downloader and bundle install.sh in release ZIPs 2026-10-07 16:43:38 -04:00
woutermans 6ec70b3ee9 Preserve upstream accuracy-package adjustment during PR integration 2026-10-07 22:39:37 +02:00
woutermans 69b284b8b7 Fix PR integration: token prep slots, input ordering and output lifetime 2026-10-07 22:39:37 +02:00
ayo e3d32a62a3 small package change 2026-10-07 16:33:29 -04:00
woutermans 84e6048066 Merge PR #27: experimental packed and in-place DLSS output 2026-10-07 22:26:30 +02:00
woutermans 607035aa98 Merge PR #26: RDNA4 token-lane Swin and hardware FP8 texture tails
# Conflicts:
#	kernels/m/rrlite_enc3_tube_4x4.hip
2026-10-07 22:26:30 +02:00
Woutermans e5a8a4afb1 Merge pull request #28 from Tk-Glitch/R16_FLOAT_depth
Add R16_FLOAT depth input support
2026-10-07 22:13:38 +02:00
ayo a627439025 Add MicroCUDA backend, adaptive output wait, wider native K coverage (improve perf)
Shim
- Adaptive output-event wait: sleep to ~120 us before the predicted
  completion (smoothed per wait site), spin near it, back off when late.
  D4R_SHIM_OUTPUT_POLL_US restores a fixed interval.

- Defer the input-marker wait into the worker thread with VRAM interop
  (D4R_SHIM_DEFER_MARKER, default on), taking the host setup off the
  critical path.

MicroCUDA
- Experimental ZLUDA-free backend in wine_nvcuda_bridge, plus
  tools/microcuda and scripts/build_microcuda.sh. Serves accuracy, fast
  and native kernels; unregistered modules fall back to the reference
  path. Unclassified writes invalidate prepared weights.

M kernels
- SWIN_PREP_IDENTITY_AT: key weight prep by allocation identity
  (MicroCUDA); enc3 tube uses it with 8 slots. ZLUDA ignores it.

- dec2 (gfx1101): SWIN_PACKED_RESIDUAL, byte-identical, ~1.6% faster.

- Opt-in gfx12 hardware fp8 conversion (SWIN_FP8_HWCVT), unverified
  on hardware.

Native K translators
- ctile: handle variants that re-materialize the parameter base (mvlo).

- rewrite_output: check live-in registers, not just outputs.

- build.sh: native input covers all 8 flag variants, output the 4 HDR
  "max" variants; depth-tile skip stays mvhi-only.

Tools
- dump_runner and bench_dlss_kernel harness additions.
2026-10-07 15:54:38 -04:00
Tk-Glitch 40e0094c19 Add R16_FLOAT depth input support
Alan Wake 2 uses the format for depth when enabling Ray Reconstruction.
The CPU path converts half to float in convert_row_in.
The VRAM interop path blits R16F/R16UNORM depth to an R32F conversion image before copying into the canonical buffer.

Signed-off-by: Tk-Glitch <[email protected]>
2026-10-07 13:12:28 +02:00
woutermans 283738d626 Document the linear-texture input investigation
- Add docs/in-place-inputs.md: reading the DLSS inputs in place does not work,
  because a hardware texture fetch on a HIP texture object over memory imported
  from vkd3d-proton returns stale data while plain loads and cuMemcpy2D are
  correct; records the measurements, the rule-outs and the reworked-fetch
  workaround that turned out not to pay for itself.
- Add tools/hip_vk_texture_stale_repro.cpp and its build script, the native
  Vulkan + HIP reproducer that rules out a general ROCm or RADV bug.
2026-10-07 11:00:26 +02:00
woutermans 87365077e0 Add experimental packed and in-place DLSS output
- Tag redirected surfaces as R10G10B10A2 ('R3') as well as RGBA16F ('R2'), and
  let the native output kernel store the game's R10G10B10A2 texels itself.
- Import linear, exportable game textures (vkd3d-proton patch 0003) into HIP
  so the output kernel writes the game's output texture with no game-side copy.
- Add ID3D12DXVKInteropDeviceD4R3 with GetVulkanLinearImageInfo.
- Gate both paths behind D4R_SHIM_OUTPUT_PACKED and D4R_SHIM_INPLACE, and use
  them only for split frames of preset M whose output kernel honours the redirect.
- Convert on the host when a recorded packed frame finds the wrong kernel.
- Give the harness an R10G10B10A2 output, and add D4R_SHIM_SPIN_POLL so
  frame timing is not quantised to the poll sleep.
- Document the measured removal of the output copies in performance.md.
2026-10-07 11:00:26 +02:00
woutermans 1038825225 Hardware e4m3 decode in dec0's tail on the native-FP8 build
make_ptx.py turns the 32 cvt.rn.f16x2.e4m3x2 of rrlite_dec0_4x4_folded into calls of d4r_dec_e4m3x2 (tex_common.h) when D4R_TEX_FP8=1: v_cvt_pk_f32_fp8 and two conversions to f16 instead of ZLUDA's integer lowering (about 25 instructions each; the kernel goes from 4058 to 3418 instructions). The conversion equals ZLUDA's e4m3_to_f16_bits for every code except the NaN codes 0x7f / 0xff, checked over all 65536 code pairs on an RX 9070 XT, and the head never stages those codes (it clamps to +-448 before encoding). Harness frames are byte-identical in the accuracy and the fast set, over a 16-frame moving sequence in the accuracy set. dec0 at 2227x1253 render: 0.43 -> 0.38 ms (accuracy), 0.36 -> 0.30 ms (fast). -DD4R_TEX_SOFT_E4M3 gives ZLUDA's lowering; builds without D4R_TEX_FP8 keep the PTX instruction.
2026-10-07 01:15:36 +02:00
woutermans 5198fd38b3 Hardware e4m3 in the texture tails: enc0 tail and dec0 head
On the gfx12 native-FP8 path the enc0 tail and the dec0 head encode their results with v_cvt_pk_fp8_f32 on the f32 copies of the f16 values (e4m3x4_f32 in tex_common.h) instead of ZLUDA's integer e4m3x2. The clamps keep the conversion in range: +-2pi for enc0 (the f16 bound hi[0], same in f32) and +-448 for dec0, both as a median of three, where a NaN gives the lower bound. The codes equal e4m3x2 for every non-NaN f16, checked over all 65536 patterns on an RX 9070 XT; a NaN in dec0 now encodes as -448 instead of the NaN code. Harness frames are byte-identical in both sets (LDR and HDR, motion vectors at render and display resolution). dec0: 0.21 -> 0.15 ms at 1280x720 render and 0.74 -> 0.53 ms at 2560x1440; enc0 changes by 1-2% (its time is ZLUDA's compile of the feature code). -DD4R_TEX_SOFT_E4M3 (D4R_TEX_CFLAGS) keeps e4m3x2.
2026-10-06 23:25:14 +02:00
woutermans 3490023668 Token lanes for enc2 and dec2 too
The remaining two layers (96 channels, four heads) use the same swin_tok.h template: byte-identical on the same recorded launches and harness sequences, enc2 0.22 -> 0.14 ms and dec2 0.20 -> 0.14 ms at 1280x720 render, 0.75 -> 0.47 and 0.69 -> 0.47 ms at 2560x1440. Skipping windows that lie entirely outside the image is also exact but below the measurement noise (at most 2.4% of the windows of every other tube launch), so it is not kept; true16 code generation remains not tried.
2026-10-06 23:00:03 +02:00
woutermans a7d565d1cd Token-lane block for the RDNA4 native-FP8 layers: enc1, dec1 and the enc3 tube
swin_tok.h passes the weights as the first WMMA operand and the activations as the second, so each GEMM's encoded result is already the next one's operand and stays in registers (swin_block.h transposes every result through LDS). One wave owns one 4x4 window for the whole block: norms, attention and the MLP need no LDS and no barriers; only the patch expand and the patch merge go through an e4m3 image in LDS. Outputs are bit-identical to swin_block.h (swapped WMMA operand roles, verified on an RX 9070 XT and on recorded launches). mix2 rounds in place (accumulator is addend and destination, no copy per pair). -DSWIN_NO_TOKEN_LANES builds these layers from swin_block.h again; enc2 and dec2 are unchanged. RX 9070 XT accuracy set, 2560x1440 render: whole evaluation 8.56 -> 7.18 ms.
2026-10-06 22:10:41 +02:00
Woutermans 7c60d53cd0 Merge pull request #25 from woutermans/rdna4-fp8-byte-activations
Speed up preset M on RDNA4 native FP8 (byte activations, cheaper accuracy set)
2026-10-06 19:27:30 +02:00
Woutermans 8537c3132f Merge pull request #23 from dhaern/fix/launcher-config-and-packaging
fix(launcher): harden config parsing and release packaging
2026-10-06 19:20:35 +02:00
Woutermans 17012ea588 Merge pull request #21 from dhaern/fix/native-kernel-hardening
fix(native-kernels): harden kernel loading in the bridge and ZLUDA patch
2026-10-06 19:20:31 +02:00
Woutermans 9f96c3e57e Merge pull request #20 from dhaern/fix/ngx-feature-cleanup
fix(shim): release NGX state when feature creation or recreation fails
2026-10-06 19:20:27 +02:00
Woutermans 1db8df252f Merge pull request #22 from dhaern/fix/shim-log-path-and-ranges
fix(shim): fix log path overflow, negative numeric settings and RGB9E5 range
2026-10-06 19:20:23 +02:00
Woutermans 3381127259 Merge pull request #24 from Tk-Glitch/R8G8B8A8_UNORM_motion
Add R8G8B8A8_UNORM motion vector format
2026-10-06 19:20:20 +02:00
woutermans cf741c2e3d docs: RDNA4 fast and accuracy sets, FP8 and 16-bit, before and after 2026-10-06 15:18:11 +02:00
woutermans 11c84193e6 docs: compare the RDNA4 FP8 set with the 16-bit path
The 2x figure is against the previous native-FP8 layers. With NativeFp8 off
the RX 9070 XT was already at 3.37 ms for 1280x720 -> 3840x2160; the FP8 set
is 2.88 ms there.
2026-10-06 15:03:00 +02:00