From 34e6b0fe71d770729000a553f79b784e9b2dc279 Mon Sep 17 00:00:00 2001 From: ayo <93222141+countervolts@users.noreply.github.com> Date: Fri, 16 Oct 2026 04:55:25 -0400 Subject: [PATCH] rr: add FSR Ray Regeneration, exact RDNA3 inference and motion experiments Add an experimental FSR Ray Regeneration backend for D3D12 RR requests: - Convert depth, motion, normals and albedos into AMD denoiser inputs. - Split and recompose diffuse/specular signals, then run Super Sampling. - Add stability/detail controls, demodulation guards and halo limiting. - Handle AMD provider discovery under NVIDIA GPU spoofing. - Add runtime probes, synthetic reference scenes and per-dispatch profiling. Add exact gfx11 DLSS-RR inference using f16 cooperative matrices: - Reproduce FP8 conversions, accumulation and camera reprojection arithmetic. - Widen model weights and avoid requiring VK_EXT_shader_float8. - Extend model building, replay tools and descriptor metadata. Expand motion preprocessing and experimental AW2 native-motion support: - Add tiled LDS dilation, padded allocation handling and thin-only sky fill. - Order dilation with input waits and NGX on the selected stream. - Add jitter-aligned native composition, hybrid routing and wire history repair. - Add prepared masks, sparse repair and independent motion/repair controls. Add optional fused R11G11B10 input/output conversion, sampled stage timings and profile summarization. Extend configuration, packaging, documentation, FidelityFX headers and CPU/GPU regression coverage. --- NOTICE | 9 + README.md | 1 + config/d4r.ini.default | 27 +- docs/architecture.md | 2 +- docs/fsr-ray-regeneration.md | 103 ++ docs/native-kernels.md | 174 +- engine/compile_rr.py | 6 +- engine/evk.cpp | 14 +- engine/replay_rr.cpp | 25 +- engine/rr/README.md | 31 + engine/rr/build_native_model.sh | 39 +- engine/rr/dec0_m.comp | 52 +- engine/rr/enc0_m_decl.glsl | 10 + engine/rr/enc0_m_tail.glsl | 68 +- engine/rr/ptx2rr.py | 94 +- engine/rr/rr_attn.glsl | 33 +- engine/rr/rr_exact.glsl | 33 +- engine/rr/rr_gfx11.glsl | 95 + engine/rr/rr_gfx11_k32.glsl | 29 + engine/rr/swin_m.comp | 72 +- engine/rr/widen_weights.py | 33 + engine/rr_camera.h | 63 + engine/runtime.cpp | 1 + engine/runtime_rr.inc | 21 + kernels/support/fsr_rr_compose.comp | 55 + kernels/support/fsr_rr_prepare.comp | 194 ++ kernels/support/motion_dilate.hip | 8 + kernels/support/motion_dilate_lds.hip | 164 ++ kernels/support/native_motion_compose.hip | 232 +++ kernels/support/native_motion_prepared.hip | 133 ++ kernels/support/wire_history.hip | 248 +++ packaging/d4r.ini | 21 +- scripts/build_d4r_nvngx_shim.sh | 2 +- scripts/build_fsr_rr_probe.sh | 15 + scripts/build_rr_backend_check.sh | 14 + scripts/build_vkd3d_proton_d4r.sh | 19 +- scripts/build_vulkan_staging.sh | 3 + scripts/d4r_config.py | 34 + scripts/package_release.sh | 5 + scripts/run_fsr_rr_probe_proton.sh | 53 + scripts/run_rr_backend_check_proton.sh | 47 + scripts/summarize_d4r_profile.py | 72 + tests/test_accuracy.py | 11 + tests/test_asi_setup.py | 4 +- tests/test_fused_vram_output.py | 110 ++ tests/test_motion_geometry.py | 13 + tests/test_motion_kernel_gpu.py | 149 ++ tests/test_motion_submission.py | 75 + tests/test_native_aligned_gpu.py | 87 + tests/test_native_motion.py | 65 + tests/test_native_motion_routing.py | 81 + tests/test_optiscaler_packaging.py | 39 +- tests/test_output_conversion_gpu.py | 21 + tests/test_prepared_wire_gpu.py | 83 + tests/test_profile_summary.py | 48 + tests/test_ray_reconstruction.py | 62 +- tests/test_rr_camera.py | 46 + tests/test_shim_config.py | 38 +- tests/test_vram_profile_timing.py | 42 + tests/test_wire_background_gpu.py | 64 + tests/test_wire_history.py | 54 + tests/test_wire_history_gpu.py | 88 + third_party/fidelityfx/LICENSE.txt | 20 + third_party/fidelityfx/api/include/ffx_api.h | 213 +++ .../fidelityfx/api/include/ffx_api_types.h | 257 +++ .../denoisers/include/ffx_denoiser.h | 584 ++++++ tools/d4r_fsr_rr.h | 279 +++ tools/d4r_fsr_rr_backend.inl | 1156 ++++++++++++ tools/d4r_fsr_rr_dispatch_profile.h | 777 ++++++++ tools/d4r_fsr_rr_identity.h | 172 ++ tools/d4r_fsr_rr_passes.h | 239 +++ tools/d4r_motion_dilation.h | 7 + tools/d4r_native_motion.h | 94 + tools/d4r_nvngx_shim.cpp | 1600 +++++++++++++++-- tools/d4r_vulkan_frontend.inl | 6 +- tools/d4r_wire_history.h | 109 ++ tools/fsr_rr_probe.cpp | 695 +++++++ tools/fsr_rr_scene.h | 515 ++++++ tools/rr_backend_check.cpp | 733 ++++++++ tools/vulkan_output_conversion_probe.cpp | 133 ++ tools/wine_nvcuda_bridge.c | 349 +++- tools/wine_nvcuda_bridge.spec | 16 + vulkan/kvk.cpp | 7 + 83 files changed, 11300 insertions(+), 195 deletions(-) create mode 100644 docs/fsr-ray-regeneration.md create mode 100644 engine/rr/rr_gfx11.glsl create mode 100644 engine/rr/rr_gfx11_k32.glsl create mode 100644 engine/rr/widen_weights.py create mode 100644 engine/rr_camera.h create mode 100644 kernels/support/fsr_rr_compose.comp create mode 100644 kernels/support/fsr_rr_prepare.comp create mode 100644 kernels/support/motion_dilate_lds.hip create mode 100644 kernels/support/native_motion_compose.hip create mode 100644 kernels/support/native_motion_prepared.hip create mode 100644 kernels/support/wire_history.hip create mode 100755 scripts/build_fsr_rr_probe.sh create mode 100755 scripts/build_rr_backend_check.sh create mode 100755 scripts/run_fsr_rr_probe_proton.sh create mode 100755 scripts/run_rr_backend_check_proton.sh create mode 100644 scripts/summarize_d4r_profile.py create mode 100644 tests/test_fused_vram_output.py create mode 100644 tests/test_motion_submission.py create mode 100644 tests/test_native_aligned_gpu.py create mode 100644 tests/test_native_motion.py create mode 100644 tests/test_native_motion_routing.py create mode 100644 tests/test_output_conversion_gpu.py create mode 100644 tests/test_prepared_wire_gpu.py create mode 100644 tests/test_profile_summary.py create mode 100644 tests/test_rr_camera.py create mode 100644 tests/test_vram_profile_timing.py create mode 100644 tests/test_wire_background_gpu.py create mode 100644 tests/test_wire_history.py create mode 100644 tests/test_wire_history_gpu.py create mode 100644 third_party/fidelityfx/LICENSE.txt create mode 100644 third_party/fidelityfx/api/include/ffx_api.h create mode 100644 third_party/fidelityfx/api/include/ffx_api_types.h create mode 100644 third_party/fidelityfx/denoisers/include/ffx_denoiser.h create mode 100644 tools/d4r_fsr_rr.h create mode 100644 tools/d4r_fsr_rr_backend.inl create mode 100644 tools/d4r_fsr_rr_dispatch_profile.h create mode 100644 tools/d4r_fsr_rr_identity.h create mode 100644 tools/d4r_fsr_rr_passes.h create mode 100644 tools/d4r_native_motion.h create mode 100644 tools/d4r_wire_history.h create mode 100644 tools/fsr_rr_probe.cpp create mode 100644 tools/fsr_rr_scene.h create mode 100644 tools/rr_backend_check.cpp create mode 100644 tools/vulkan_output_conversion_probe.cpp diff --git a/NOTICE b/NOTICE index 2a3cebb..afd8f21 100644 --- a/NOTICE +++ b/NOTICE @@ -17,6 +17,15 @@ patches/vkd3d-proton/*.patch under the GNU Lesser General Public License, version 2.1. These patches are offered under the same license. +third_party/fidelityfx/ + AMD FidelityFX SDK 2.3.0 API headers (ffx_api.h, ffx_api_types.h, ffx_denoiser.h), copied + unmodified; the SDK license lists them under the MIT license (third_party/fidelityfx/LICENSE.txt). + AMD's runtime DLLs are not included and remain under AMD's binary terms. + +kernels/support/fsr_rr_prepare.comp + Its diffuse/specular split follows the DLSS-RR to FSR-RR adapter in Zach Hembree's OptiScaler + branch ffx-denoise-experimental and burak113's continuation (GPL-3.0). + Release zips (scripts/package_release.sh) also bundle binaries of ZLUDA (Apache-2.0 or MIT, with LLVM under Apache-2.0 with LLVM exceptions), the patched vkd3d-proton (LGPL-2.1) and OptiScaler (https://github.com/optiscaler/OptiScaler, GPL-3.0, unmodified). Each zip carries their license diff --git a/README.md b/README.md index 65e9f1c..cb7b954 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ PreferAccuracy = true NativeSwinEncoders = false MotionVectorDilation = 2 +MotionDilationThinSky = false ; opt-in thin-only sky fill; keep false for current behavior ``` ## Known issues diff --git a/config/d4r.ini.default b/config/d4r.ini.default index 578c5ac..e0eba6d 100644 --- a/config/d4r.ini.default +++ b/config/d4r.ini.default @@ -44,6 +44,24 @@ Enable = auto ; auto preserves the game's choice; default = NVIDIA's default, D/E = transformer models. ; These presets are independent of [DLSS] Model. E requires a DLL that contains that model. Model = auto +; Which denoiser answers a game's Ray Reconstruction request (D4R_RR_BACKEND): +; dlss = NVIDIA's DLSS Ray Reconstruction (Model above), the default. +; fsr = experimental: AMD's FSR Ray Regeneration 1.2 (amd_fidelityfx_denoiser_dx12.dll, unmodified) +; denoises at render resolution, then Super Sampling ([DLSS] Model) upscales to the game's +; output size. D3D12 only. The game's combined colour is split into diffuse and specular +; by its albedos, which is an approximation; see docs/fsr-ray-regeneration.md. +; Changing it needs a game restart (or the game recreating its Ray Reconstruction feature). +Backend = dlss +; The AMD denoiser DLL for Backend = fsr (D4R_FSR_RR_DLL). auto: amd_fidelityfx_denoiser_dx12.dll in +; the d4r folder. +FsrDenoiser = auto +; Backend = fsr tuning. FsrStabilityBias: the AMD denoiser's temporal stability bias; auto = AMD's +; default (1), which blurs reflections and fine detail; 0 measured sharper and closer to the noise-free +; truth, moving or still (D4R_FSR_RR_STABILITY_BIAS). FsrDetail: the share (0-1) of the colour that goes +; around the denoiser, keeping detail it removes as noise (hair, water ripples, foliage) at the cost of some +; grain; 0 = off (D4R_FSR_RR_DETAIL). +FsrStabilityBias = auto +FsrDetail = 0 [Latency] ; How many frames old the upscaled image the game presents may be. @@ -90,6 +108,10 @@ ImplicitMaxBlock = 256 ; and same-frame linear VRAM inputs; unsupported features retain original vectors. ; Default off. May affect disocclusion edges. (D4R_MOTION_DILATION) MotionVectorDilation = 0 +; Opt-in sky-fill experiment for equal render/motion grids: borrow only from foreground +; runs <=3 pixels along either axis. Opaque dilation is unchanged. Restart to change. +; Unsupported routes retain nearest-foreground fill. (D4R_MOTION_THIN_SKY) +MotionDilationThinSky = false ; Keep DLSS inputs and output in VRAM (vkd3d-proton Vulkan interop) instead of copying through ; system memory. Falls back automatically when the game's resources do not qualify. VramInterop = true @@ -177,8 +199,11 @@ MangoHud = false MangoHudConfig = fps,frametime,frame_timing=0,gpu_stats=0,cpu_stats=0,position=top-right,font_size=36 [Debug] -; Per-frame timing lines in the shim log (d4r_nvngx.log) +; Measure stage timings and write sampled timing lines in the shim log (d4r_nvngx.log) Profile = false +; Log the first 5 frames, then every Nth frame. 1 = every frame. Restart after changing. +; FSR RR stage summaries average N completed GPU samples. Env: D4R_PROFILE_LOG_EVERY +ProfileLogEvery = 60 ; Log directory (auto = ~/.cache/d4r-dlss-captures/game--