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.
This commit is contained in:
ayo committed 2026-10-09 02:57:23 -04:00
1 parent 18c694eecb
commit 694a7a0126
24 files changed
+2215 -20

No files matched your search

+4 -3
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
# Builds build/d4r_nvngx.dll, the D3D12-to-CUDA NGX core shim loaded by
# Builds build/d4r_nvngx.dll, the D3D12/Vulkan-to-CUDA NGX core shim loaded by
# OptiScaler through its NvngxPath setting.
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
MINGW_CXX="${MINGW_CXX:-x86_64-w64-mingw32-g++}"
@@ -10,6 +10,7 @@ CLANG_CL="${CLANG_CL:-clang-cl}"
VULKAN_INCLUDE="${VULKAN_INCLUDE:-/usr/include}"
mkdir -p "$ROOT/build"
bash "$ROOT/scripts/build_vulkan_staging.sh"
# Only the Vulkan headers from the host include tree, not its libc headers.
mkdir -p "$ROOT/build/vulkan-include"
ln -sfn "$VULKAN_INCLUDE/vulkan" "$ROOT/build/vulkan-include/vulkan"
@@ -17,7 +18,7 @@ ln -sfn "$VULKAN_INCLUDE/vk_video" "$ROOT/build/vulkan-include/vk_video"
PARAM_OBJECT="$ROOT/build/d4r_ngx_param_msvc.obj"
"$CLANG_CL" --target=x86_64-pc-windows-msvc /nologo /std:c++20 /O2 /c /GS- /GR- /EHs-c- /Zl \
"/Fo$PARAM_OBJECT" -- "$ROOT/tools/d4r_ngx_param_msvc.cpp"
"$MINGW_CXX" -std=c++20 -O2 -Wall -Wextra -Wno-missing-field-initializers -I"$ROOT/build/vulkan-include" -shared -static -static-libgcc -static-libstdc++ \
"$MINGW_CXX" -std=c++20 -O2 -Wall -Wextra -Wno-missing-field-initializers -I"$ROOT/build/vulkan-include" -I"$ROOT/build/vulkan-staging" -shared -static -static-libgcc -static-libstdc++ \
"$ROOT/tools/d4r_nvngx_shim.cpp" "$ROOT/tools/d4r_ngx_param_host.cpp" "$PARAM_OBJECT" \
-o "$ROOT/build/d4r_nvngx.dll"
-Wl,--entry,d4r_dll_entry -o "$ROOT/build/d4r_nvngx.dll"
printf 'Built %s\n' "$ROOT/build/d4r_nvngx.dll"
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
"$ROOT/scripts/build_d4r_nvngx_shim.sh"
"${MINGW_CXX:-x86_64-w64-mingw32-g++}" -std=c++20 -O2 -Wall -Wextra -Wno-missing-field-initializers \
-I"$ROOT/build/vulkan-include" -static -static-libgcc -static-libstdc++ \
"$ROOT/tools/vulkan_dlss_harness.cpp" "$ROOT/tools/d4r_ngx_param_host.cpp" "$ROOT/build/d4r_ngx_param_msvc.obj" \
-o "$ROOT/build/vulkan_dlss_harness.exe"
printf 'Built %s\n' "$ROOT/build/vulkan_dlss_harness.exe"
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUT="${1:-$ROOT/build/vulkan-staging}"
mkdir -p "$OUT"
glslangValidator -V --target-env vulkan1.0 -o "$OUT/read.spv" "$ROOT/kernels/support/vulkan_read.comp" >/dev/null
for format in rgba16f rgba32f r11f_g11f_b10f rgb10_a2 rgba8; do
glslangValidator -V --target-env vulkan1.0 -DOUTPUT_FORMAT="$format" \
-o "$OUT/write_$format.spv" "$ROOT/kernels/support/vulkan_write.comp" >/dev/null
done
python3 - "$OUT" <<'PY'
from pathlib import Path
import struct, sys
root = Path(sys.argv[1]); lines = ['#pragma once', '#include <cstdint>']
for path in sorted(root.glob('*.spv')):
data = path.read_bytes()
words = struct.unpack('<' + 'I' * (len(data)//4), data)
lines.append(f'static const uint32_t d4r_vk_{path.stem}[] = {{')
lines.extend(','.join(f'0x{w:08x}' for w in words[i:i+8])+',' for i in range(0,len(words),8))
lines.append('};')
(root/'d4r_vulkan_staging_spv.h').write_text('\n'.join(lines)+'\n')
PY
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -euo pipefail
# Uses an isolated Proton prefix and an existing portable d4r runtime.
# usage: run_vulkan_dlss_harness_proton.sh PROTON_DIR D4R_DIR OUTPUT_RAW [FRAMES [discard|invalid]]
if [[ $# -lt 3 ]]; then
printf 'usage: %s PROTON_DIR D4R_DIR OUTPUT_RAW [FRAMES [discard|invalid]]\n' "$0" >&2
exit 2
fi
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PROTON_DIR="$(realpath "$1")"
RUNTIME="$(realpath "$2")"
OUTPUT="$(realpath -m "$3")"
shift 3
for file in ngx/_nvngx.dll nvngx_dlss.dll nvcuda.dll zluda/libcuda.so; do
[[ -f "$RUNTIME/$file" ]] || { printf 'Missing runtime file: %s\n' "$RUNTIME/$file" >&2; exit 2; }
done
"$ROOT/scripts/build_vulkan_dlss_harness.sh"
APP_DIR="$(mktemp -d "$ROOT/build/vulkan-harness-app-XXXXXX")"
cp "$ROOT/build/vulkan_dlss_harness.exe" "$ROOT/build/d4r_nvngx.dll" "$APP_DIR/"
ln -s "$RUNTIME/nvngx_dlss.dll" "$APP_DIR/nvngx_dlss.dll"
winpath() { printf 'Z:%s' "${1//\//\\}"; }
export STEAM_COMPAT_CLIENT_INSTALL_PATH="${STEAM_COMPAT_CLIENT_INSTALL_PATH:-$HOME/.local/share/Steam}"
export STEAM_COMPAT_DATA_PATH="${D4R_PROTON_COMPAT_DATA:-${TMPDIR:-/tmp}/d4r-vulkan-harness-compat}"
mkdir -p "$STEAM_COMPAT_DATA_PATH" "$(dirname "$OUTPUT")"
export D4R_NGX_CORE="$(winpath "$RUNTIME/ngx/_nvngx.dll")"
export D4R_NGX_FEATURE_DIR="$(winpath "$RUNTIME")"
export D4R_NVCUDA_BRIDGE="$(winpath "$RUNTIME/nvcuda.dll")"
export D4R_ZLUDA_LIBCUDA="$RUNTIME/zluda/libcuda.so"
export D4R_ZLUDA_NATIVE_DIR="${D4R_ZLUDA_NATIVE_DIR:-$RUNTIME/kernels}"
export D4R_ROCM_DIR="${D4R_ROCM_DIR:-$RUNTIME/rocm}"
export LD_LIBRARY_PATH="$RUNTIME/zluda:$D4R_ROCM_DIR/lib:$D4R_ROCM_DIR/lib/llvm/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export PROTON_ENABLE_NVAPI=1 DXVK_NVAPI_ALLOW_OTHER_DRIVERS=1 DXVK_NVAPI_GPU_ARCH=AD100
export D4R_CUDA_CAPTURE=0 D4R_ZLUDA_IMPLICIT_MAX_BLOCK=256 D4R_ZLUDA_WMMA=1
export D4R_SHIM_LOG="$(winpath "$ROOT/build/vulkan-harness.log")"
export WINEDEBUG="${WINEDEBUG:--all}"
"$PROTON_DIR/proton" run "$APP_DIR/vulkan_dlss_harness.exe" \
"$(winpath "$APP_DIR/d4r_nvngx.dll")" "$(winpath "$OUTPUT")" "$@"