From 118173ecd7a2159c3ef7ae682af1e2d01b04f926 Mon Sep 17 00:00:00 2001 From: ayo <93222141+countervolts@users.noreply.github.com> Date: Sun, 27 Sep 2026 15:26:56 -0400 Subject: [PATCH] d4r: official NVIDIA DLSS on AMD GPUs under Linux and Proton --- .gitignore | 34 + LICENSE | 73 + NOTICE | 31 + README.md | 104 + config/d4r.ini.default | 126 + docs/architecture.md | 90 + docs/building.md | 106 + docs/native-kernels.md | 94 + docs/performance.md | 59 + kernels/build.sh | 61 + kernels/k/dltss_pwin_dec0_layer.hip | 3 + kernels/k/dltss_pwin_dec1_layer.hip | 3 + kernels/k/dltss_pwin_dec2_layer.hip | 3 + kernels/k/dltss_pwin_dec3_layer.hip | 2 + kernels/k/dltss_pwin_dec4_layer.hip | 2 + kernels/k/dltss_pwin_dec5_layer.hip | 2 + kernels/k/dltss_pwin_enc0_layer.hip | 3 + kernels/k/dltss_pwin_enc1_layer.hip | 3 + kernels/k/dltss_pwin_enc2_layer.hip | 3 + kernels/k/dltss_pwin_enc3_layer.hip | 2 + kernels/k/dltss_pwin_enc4_layer.hip | 2 + kernels/k/pwin_common.h | 188 + kernels/k/pwin_layer.h | 837 +++ kernels/k/pwin_pos.h | 433 ++ kernels/k/pwin_wide.h | 455 ++ kernels/m/rrlite_dec1_4x4.hip | 7 + kernels/m/rrlite_dec2_4x4.hip | 7 + kernels/m/rrlite_enc1_4x4.hip | 7 + kernels/m/rrlite_enc2_4x4.hip | 7 + kernels/m/rrlite_enc3_tube_4x4.hip | 7 + kernels/m/swin_block.h | 768 +++ kernels/m/swin_common.h | 330 ++ kernels/tex/build_tex.sh | 26 + kernels/tex/dec0_head.hip | 112 + kernels/tex/enc0_tail.hip | 124 + kernels/tex/make_ptx.py | 253 + kernels/tex/sust_only.hip | 2 + kernels/tex/tex_common.h | 375 ++ kernels/tools/dump_runner.cpp | 167 + kernels/tools/extract_dlss_ptx.py | 94 + kernels/tools/kernel_manifest.py | 69 + kernels/tools/kprof.py | 13 + kernels/tools/psnr.py | 15 + kernels/tools/ptxload.c | 20 + kernels/tools/ptxsim.py | 877 ++++ kernels/tools/pwin_model.py | 408 ++ kernels/tools/swin_model.py | 168 + packaging/D4R_README.txt | 119 + packaging/RELEASE_NOTES.md | 63 + packaging/SOURCES.txt | 36 + packaging/VERSION | 1 + packaging/d4r-check.sh | 52 + packaging/d4r.ini | 53 + packaging/optiscaler.settings | 16 + ...split-command-list-for-external-wait.patch | 304 ++ .../zluda/0002-dlss-runtime-cumulative.patch | 2768 ++++++++++ .../0003-perf-implicit-bound-gfx11-wmma.patch | 772 +++ ...04-native-overrides-and-gpu-handoffs.patch | 1672 ++++++ scripts/build_bench_dlss_kernel.sh | 11 + scripts/build_d3d12_dlss_harness.sh | 11 + scripts/build_d3d12_hip_interop_probe.sh | 15 + scripts/build_d4r_nvapi_identity.sh | 9 + scripts/build_d4r_nvngx_shim.sh | 23 + scripts/build_hip_vk_interop_probe.sh | 20 + scripts/build_ngx_cuda_probe.sh | 21 + scripts/build_ngx_d3d12_probe.sh | 17 + scripts/build_ngx_load_probe.sh | 11 + scripts/build_ngx_vulkan_probe.sh | 23 + scripts/build_replay_dlss_fp8_ops.sh | 11 + scripts/build_replay_dlss_histogram.sh | 18 + scripts/build_replay_dlss_kernel.sh | 11 + scripts/build_replay_dlss_layer.sh | 11 + .../build_replay_dlss_surface_half_store.sh | 11 + scripts/build_replay_dlss_surface_store.sh | 11 + scripts/build_replay_dlss_texture_sample.sh | 11 + scripts/build_vkd3d_proton_d4r.sh | 30 + scripts/build_wine_nvcuda_bridge.sh | 15 + scripts/build_zluda_ptx_helpers.sh | 57 + scripts/check_environment.sh | 59 + scripts/d4r_config.py | 200 + scripts/d4r_play.sh | 9 + scripts/d4r_proton_env.sh | 40 + scripts/install_d4r_runtime.sh | 29 + scripts/package_release.sh | 151 + scripts/run_bench_dlss_kernel.sh | 20 + scripts/run_d3d12_dlss_harness.sh | 48 + ...un_d3d12_dlss_harness_optiscaler_proton.sh | 149 + scripts/run_d3d12_dlss_harness_proton.sh | 36 + scripts/run_d3d12_hip_interop_probe.sh | 22 + scripts/run_game_d4r_optiscaler_proton.sh | 170 + scripts/run_hip_vk_interop_probe.sh | 9 + scripts/run_ngx_cuda_probe.sh | 71 + scripts/run_ngx_d3d12_probe.sh | 22 + scripts/run_ngx_load_probe.sh | 18 + scripts/run_ngx_vulkan_probe.sh | 22 + scripts/run_replay_dlss_fp8_ops.sh | 14 + scripts/run_replay_dlss_histogram.sh | 19 + scripts/run_replay_dlss_kernel.sh | 19 + scripts/run_replay_dlss_surface_half_store.sh | 14 + scripts/run_replay_dlss_surface_store.sh | 14 + scripts/run_replay_dlss_texture_sample.sh | 14 + tools/bench_cuda_copies.cpp | 222 + tools/bench_dlss_kernel.cpp | 222 + tools/compare_ngx_dlls.py | 79 + tools/d3d12_dlss_harness.cpp | 814 +++ tools/d3d12_hip_interop_probe.cpp | 446 ++ tools/d4r_ngx_param_host.cpp | 18 + tools/d4r_ngx_param_msvc.cpp | 191 + tools/d4r_nvapi_identity.c | 81 + tools/d4r_nvngx_shim.cpp | 4622 +++++++++++++++++ tools/hip_vk_interop_probe.cpp | 319 ++ tools/inspect_ngx_dll.py | 505 ++ tools/instrument_ptx_nonfinite.py | 210 + tools/ngx_cuda_probe.cpp | 1107 ++++ tools/ngx_d3d12_probe.cpp | 363 ++ tools/ngx_load_probe.cpp | 60 + tools/ngx_param_abi_probe_msvc.cpp | 269 + tools/ngx_param_abi_probe_shared.h | 12 + tools/ngx_vulkan_probe.cpp | 411 ++ tools/replay_dlss_fp8_ops.cpp | 1874 +++++++ tools/replay_dlss_histogram.cpp | 508 ++ tools/replay_dlss_kernel.cpp | 233 + tools/replay_dlss_layer.cpp | 194 + tools/replay_dlss_surface_half_store.cpp | 355 ++ tools/replay_dlss_surface_store.cpp | 859 +++ tools/replay_dlss_texture_sample.cpp | 472 ++ tools/wine_nvcuda_bridge.c | 2839 ++++++++++ tools/wine_nvcuda_bridge.spec | 101 + 128 files changed, 31333 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 README.md create mode 100644 config/d4r.ini.default create mode 100644 docs/architecture.md create mode 100644 docs/building.md create mode 100644 docs/native-kernels.md create mode 100644 docs/performance.md create mode 100755 kernels/build.sh create mode 100644 kernels/k/dltss_pwin_dec0_layer.hip create mode 100644 kernels/k/dltss_pwin_dec1_layer.hip create mode 100644 kernels/k/dltss_pwin_dec2_layer.hip create mode 100644 kernels/k/dltss_pwin_dec3_layer.hip create mode 100644 kernels/k/dltss_pwin_dec4_layer.hip create mode 100644 kernels/k/dltss_pwin_dec5_layer.hip create mode 100644 kernels/k/dltss_pwin_enc0_layer.hip create mode 100644 kernels/k/dltss_pwin_enc1_layer.hip create mode 100644 kernels/k/dltss_pwin_enc2_layer.hip create mode 100644 kernels/k/dltss_pwin_enc3_layer.hip create mode 100644 kernels/k/dltss_pwin_enc4_layer.hip create mode 100644 kernels/k/pwin_common.h create mode 100644 kernels/k/pwin_layer.h create mode 100644 kernels/k/pwin_pos.h create mode 100644 kernels/k/pwin_wide.h create mode 100644 kernels/m/rrlite_dec1_4x4.hip create mode 100644 kernels/m/rrlite_dec2_4x4.hip create mode 100644 kernels/m/rrlite_enc1_4x4.hip create mode 100644 kernels/m/rrlite_enc2_4x4.hip create mode 100644 kernels/m/rrlite_enc3_tube_4x4.hip create mode 100644 kernels/m/swin_block.h create mode 100644 kernels/m/swin_common.h create mode 100755 kernels/tex/build_tex.sh create mode 100644 kernels/tex/dec0_head.hip create mode 100644 kernels/tex/enc0_tail.hip create mode 100755 kernels/tex/make_ptx.py create mode 100644 kernels/tex/sust_only.hip create mode 100644 kernels/tex/tex_common.h create mode 100644 kernels/tools/dump_runner.cpp create mode 100644 kernels/tools/extract_dlss_ptx.py create mode 100644 kernels/tools/kernel_manifest.py create mode 100644 kernels/tools/kprof.py create mode 100644 kernels/tools/psnr.py create mode 100644 kernels/tools/ptxload.c create mode 100644 kernels/tools/ptxsim.py create mode 100644 kernels/tools/pwin_model.py create mode 100644 kernels/tools/swin_model.py create mode 100644 packaging/D4R_README.txt create mode 100644 packaging/RELEASE_NOTES.md create mode 100644 packaging/SOURCES.txt create mode 100644 packaging/VERSION create mode 100755 packaging/d4r-check.sh create mode 100644 packaging/d4r.ini create mode 100644 packaging/optiscaler.settings create mode 100644 patches/vkd3d-proton/0001-split-command-list-for-external-wait.patch create mode 100644 patches/zluda/0002-dlss-runtime-cumulative.patch create mode 100644 patches/zluda/0003-perf-implicit-bound-gfx11-wmma.patch create mode 100644 patches/zluda/0004-native-overrides-and-gpu-handoffs.patch create mode 100755 scripts/build_bench_dlss_kernel.sh create mode 100755 scripts/build_d3d12_dlss_harness.sh create mode 100755 scripts/build_d3d12_hip_interop_probe.sh create mode 100755 scripts/build_d4r_nvapi_identity.sh create mode 100755 scripts/build_d4r_nvngx_shim.sh create mode 100755 scripts/build_hip_vk_interop_probe.sh create mode 100755 scripts/build_ngx_cuda_probe.sh create mode 100755 scripts/build_ngx_d3d12_probe.sh create mode 100755 scripts/build_ngx_load_probe.sh create mode 100755 scripts/build_ngx_vulkan_probe.sh create mode 100755 scripts/build_replay_dlss_fp8_ops.sh create mode 100755 scripts/build_replay_dlss_histogram.sh create mode 100755 scripts/build_replay_dlss_kernel.sh create mode 100755 scripts/build_replay_dlss_layer.sh create mode 100755 scripts/build_replay_dlss_surface_half_store.sh create mode 100755 scripts/build_replay_dlss_surface_store.sh create mode 100755 scripts/build_replay_dlss_texture_sample.sh create mode 100755 scripts/build_vkd3d_proton_d4r.sh create mode 100755 scripts/build_wine_nvcuda_bridge.sh create mode 100755 scripts/build_zluda_ptx_helpers.sh create mode 100755 scripts/check_environment.sh create mode 100755 scripts/d4r_config.py create mode 100755 scripts/d4r_play.sh create mode 100644 scripts/d4r_proton_env.sh create mode 100755 scripts/install_d4r_runtime.sh create mode 100755 scripts/package_release.sh create mode 100755 scripts/run_bench_dlss_kernel.sh create mode 100755 scripts/run_d3d12_dlss_harness.sh create mode 100755 scripts/run_d3d12_dlss_harness_optiscaler_proton.sh create mode 100755 scripts/run_d3d12_dlss_harness_proton.sh create mode 100755 scripts/run_d3d12_hip_interop_probe.sh create mode 100755 scripts/run_game_d4r_optiscaler_proton.sh create mode 100755 scripts/run_hip_vk_interop_probe.sh create mode 100755 scripts/run_ngx_cuda_probe.sh create mode 100755 scripts/run_ngx_d3d12_probe.sh create mode 100755 scripts/run_ngx_load_probe.sh create mode 100755 scripts/run_ngx_vulkan_probe.sh create mode 100755 scripts/run_replay_dlss_fp8_ops.sh create mode 100755 scripts/run_replay_dlss_histogram.sh create mode 100755 scripts/run_replay_dlss_kernel.sh create mode 100755 scripts/run_replay_dlss_surface_half_store.sh create mode 100755 scripts/run_replay_dlss_surface_store.sh create mode 100755 scripts/run_replay_dlss_texture_sample.sh create mode 100644 tools/bench_cuda_copies.cpp create mode 100644 tools/bench_dlss_kernel.cpp create mode 100644 tools/compare_ngx_dlls.py create mode 100644 tools/d3d12_dlss_harness.cpp create mode 100644 tools/d3d12_hip_interop_probe.cpp create mode 100644 tools/d4r_ngx_param_host.cpp create mode 100644 tools/d4r_ngx_param_msvc.cpp create mode 100644 tools/d4r_nvapi_identity.c create mode 100644 tools/d4r_nvngx_shim.cpp create mode 100644 tools/hip_vk_interop_probe.cpp create mode 100755 tools/inspect_ngx_dll.py create mode 100644 tools/instrument_ptx_nonfinite.py create mode 100644 tools/ngx_cuda_probe.cpp create mode 100644 tools/ngx_d3d12_probe.cpp create mode 100644 tools/ngx_load_probe.cpp create mode 100644 tools/ngx_param_abi_probe_msvc.cpp create mode 100644 tools/ngx_param_abi_probe_shared.h create mode 100644 tools/ngx_vulkan_probe.cpp create mode 100644 tools/replay_dlss_fp8_ops.cpp create mode 100644 tools/replay_dlss_histogram.cpp create mode 100644 tools/replay_dlss_kernel.cpp create mode 100644 tools/replay_dlss_layer.cpp create mode 100644 tools/replay_dlss_surface_half_store.cpp create mode 100644 tools/replay_dlss_surface_store.cpp create mode 100644 tools/replay_dlss_texture_sample.cpp create mode 100644 tools/wine_nvcuda_bridge.c create mode 100644 tools/wine_nvcuda_bridge.spec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62dc6c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +# Local proprietary/runtime inputs and outputs +*.dll +*.exe +*.asi +*.pth +*.safetensors +*.onnx +*.cubin +*.fatbin +*.nvngx + +# Local captures, dumps, traces, and build products +/captures/ +/dumps/ +/traces/ +/build/ +/dist/ +*.trace +*.dump +*.log +__pycache__/ +.venv/ +/Archive.zip +/vkd3d-proton.cache + +# Machine-specific notes, CI runner setup, local experiments, benchmark automation (kept locally, never published) +/private/ +# Claude Code local settings +/.claude/ +# Native kernel build products and inputs extracted from NVIDIA's DLL at build time +/kernels/out/ +*.hsaco +*.ptx +/kernels/extracted/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..137069b --- /dev/null +++ b/LICENSE @@ -0,0 +1,73 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + + You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + +To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..13ca203 --- /dev/null +++ b/NOTICE @@ -0,0 +1,31 @@ +d4r +Copyright 2026 countervolts + +This product is licensed under the Apache License, Version 2.0 (see LICENSE), except for the files +listed below. + +patches/zluda/*.patch + Changes to ZLUDA (https://github.com/vosen/ZLUDA). ZLUDA is dual-licensed under the Apache + License, Version 2.0 and the MIT license; these patches are offered under the same terms. + +patches/vkd3d-proton/*.patch + Changes to vkd3d-proton (https://github.com/HansKristian-Work/vkd3d-proton), which is licensed + under the GNU Lesser General Public License, version 2.1. These patches are offered under the + same license. + +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 +texts in d4r/licenses and says where every file comes from in d4r/source/SOURCES.txt. +Release zips also contain NVIDIA's nvngx_dlss.dll and _nvngx.dll and DLSS kernels compiled from +NVIDIA's PTX. Those are NVIDIA's property, are not covered by this repository's license, and are +included by whoever publishes the zip. + +This repository contains no NVIDIA software. The NVIDIA DLSS feature library (nvngx_dlss.dll) and +the NGX core (_nvngx.dll) are NVIDIA's; you supply your own copies, and their use is governed by +NVIDIA's license terms. At build time, kernels/tools/extract_dlss_ptx.py reads PTX from your copy +of nvngx_dlss.dll into kernels/extracted/, which is not part of the repository and must not be +redistributed. + +NVIDIA and DLSS are trademarks of NVIDIA Corporation. AMD, Radeon and FSR are trademarks of +Advanced Micro Devices, Inc. This project is not affiliated with or endorsed by either company. diff --git a/README.md b/README.md new file mode 100644 index 0000000..14b68bc --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ +# d4r + +d4r runs NVIDIA's official DLSS Super Resolution library (`nvngx_dlss.dll`) in Windows games on AMD Radeon GPUs under Linux and Proton. The game asks for DLSS as usual; the DLSS network runs on the AMD GPU through [ZLUDA](https://github.com/vosen/ZLUDA) (CUDA on ROCm/HIP), with the heaviest DLSS kernels replaced by hand-written RDNA3 code. + +It is an experiment. It has been tested on one GPU and one game, it depends on unreleased patches to ZLUDA and vkd3d-proton, and it needs NVIDIA files that are not part of this repository. + +> **Not affiliated with NVIDIA or AMD.** This repository contains no NVIDIA software. You supply your own `nvngx_dlss.dll` and NGX core (`_nvngx.dll`), and you are responsible for complying with NVIDIA's license terms for them. + +## Results + +Radeon RX 7700 XT (RDNA3, gfx1101), SILENT HILL Townfall at 2560×1440, the same 62-second street walk for every run, frame rates from MangoHud frametime logs. Every DLSS result is presented in the frame it belongs to (no added latency). + +| Mode | DLSS 3 CNN (preset E) | DLSS 4 (preset K) | DLSS 4.5 (preset M) | FSR 4 | +|---|---|---|---|---| +| Quality (1705×960) | **72.4** fps | 69.4 | 51.5 | 76.0 | +| Balanced (1488×837) | **80.5** | 76.6 | 59.6 | 84.5 | +| Performance (1280×720) | **87.8** | 84.0 | 69.9 | 94.0 | +| Ultra Performance (853×480) | 88.9 | **94.5** | 90.3 | 107.3 | + +DLSS Ultra Performance demo: + + + +For reference, native 2560×1440 without upscaling (the game's TSR at 100%) runs at 49.1 fps on the same walk. + +On the same GPU DLSS starts at a disadvantage: its networks were designed for NVIDIA's tensor cores, and parts of them still run as translated NVIDIA code. How the numbers were measured, and what each optimisation contributed, is in [docs/performance.md](docs/performance.md). + +## Known issues + +- Native upscaling can show visible artifacting. + +## How it works + +``` +game (D3D12) ──► OptiScaler (DLSS inputs) ──► d4r_nvngx.dll (NGX D3D12 API, tools/d4r_nvngx_shim.cpp) + │ inputs/output stay in VRAM (vkd3d-proton Vulkan interop, + │ command list split around DLSS for same-frame results) + ▼ + official NGX core + nvngx_dlss.dll (their CUDA path) + ▼ + nvcuda.dll (Wine CUDA bridge, tools/wine_nvcuda_bridge.c) + ▼ + ZLUDA (patches/zluda: PTX → AMDGPU, WMMA, native kernel overrides) + ▼ + native RDNA3 kernels (kernels/: DLSS 4 and 4.5 network layers) +``` + +- **The shim** (`d4r_nvngx.dll`) implements the D3D12 NGX entry points OptiScaler calls, copies the game's colour, depth and motion vectors into buffers shared with HIP, evaluates DLSS through the CUDA version of NGX, and writes the result back into the game's output texture. +- **The bridge** is a Wine builtin `nvcuda.dll` that forwards the CUDA driver API to ZLUDA on the Linux side, plus a few helpers the shim needs (Vulkan memory import, asynchronous array copies, GPU-side waits). +- **ZLUDA** compiles NVIDIA's PTX for the AMD GPU. The patches add what DLSS needs (textures, surfaces, FP8 and tensor-core MMA on RDNA3 WMMA) and a hook that serves hand-written kernels in place of selected PTX kernels. +- **Native kernels** reimplement the DLSS 4 and 4.5 network layers for RDNA3 and replace parts of a few texture-heavy kernels. They are 2–3× faster than the translated versions and are checked against numpy reference models of the layers. + +Details: [docs/architecture.md](docs/architecture.md) and [docs/native-kernels.md](docs/native-kernels.md). + +## Install the release + +The release zip works like an OptiScaler release: its contents go into the folder that holds the game's main `.exe`. + +1. Extract `d4r-.zip` there. It contains: + - OptiScaler 0.9.4 as `dxgi.dll`, with an `OptiScaler.ini` set up for d4r; + - the d4r-patched vkd3d-proton (`d3d12.dll`, `d3d12core.dll`); + - an `d4r` folder with the shim, the CUDA bridge, ZLUDA, the native kernels, this game's `d4r.ini`, and NVIDIA's `nvngx_dlss.dll` (310.7) and `_nvngx.dll`. +2. In Steam, select GE-Proton 11 for the game and set these launch options: `PROTON_FORCE_NVAPI=1 DXVK_NVAPI_GPU_ARCH=AD100 %command%`. + +The only other requirement is ROCm's HIP runtime 7.x, installed from your distribution. The zip's NVIDIA files and the kernels built from NVIDIA's code are not covered by this repository's license (see [NOTICE](NOTICE)). The Proton prefix and the system are not changed. [packaging/D4R_README.txt](packaging/D4R_README.txt) is the full guide that ships in the zip; `scripts/package_release.sh` builds the zip (see [docs/building.md](docs/building.md#7-package-a-release)). + +## Requirements (building from source) + +- Linux with an AMD RDNA3 GPU. The native kernels use gfx11 WMMA; they are built for gfx1101 by default (`D4R_GPU_ARCH` for other RDNA3 chips, untested). Without them DLSS still runs through ZLUDA, much more slowly. +- ROCm with HIP and its clang (tested with ROCm 7.2). +- GE-Proton with OptiScaler integration (tested with GE-Proton11-3). +- Build tools: a Rust toolchain and git-lfs (ZLUDA), meson and ninja (vkd3d-proton), `winegcc`/`winebuild` (bridge), `x86_64-w64-mingw32-g++` and `clang-cl` (shim), Python 3. +- NVIDIA's `nvngx_dlss.dll` 310.7 and a matching NGX core `_nvngx.dll`. + +## Build and run + +The full sequence is in [docs/building.md](docs/building.md). In short: + +1. Build ZLUDA `ee2f25a` with `patches/zluda/0002`–`0004` applied. +2. Build the patched vkd3d-proton: `scripts/build_vkd3d_proton_d4r.sh OUT_DIR`. +3. Build the shim and bridge: `scripts/build_d4r_nvngx_shim.sh`, `scripts/build_wine_nvcuda_bridge.sh`. +4. Stage the runtime with your NVIDIA files: `scripts/install_d4r_runtime.sh _nvngx.dll nvngx_dlss.dll`. +5. Build the native kernels: `D4R_ROCM_DIR=… D4R_DLSS_DLL=… D4R_ZLUDA_BUILD=… kernels/build.sh`. +6. Fill in `~/.config/d4r/d4r.ini` (created from `config/d4r.ini.default` on first launch) and start the game with `scripts/d4r_play.sh`. + +The launcher backs up and restores everything it touches in the Proton prefix: OptiScaler.ini, the prefix's `d3d12.dll`/`d3d12core.dll`, and the game's Engine.ini when cvars are set. + +## Repository layout + +| Path | Contents | +|---|---| +| `tools/` | the NGX shim, the Wine CUDA bridge, a D3D12 DLSS harness, probes and kernel replay tools | +| `kernels/` | native RDNA3 kernels (`k/` DLSS 4, `m/` DLSS 4.5, `tex/` texture-kernel parts), their build script, validation tools and numpy reference models | +| `patches/` | ZLUDA and vkd3d-proton patches | +| `scripts/` | build, install, launch and probe scripts | +| `config/` | the default `d4r.ini` for the developer launcher | +| `packaging/` | the release's `d4r.ini`, OptiScaler settings, user guide and install check | +| `docs/` | architecture, build, native kernel and performance notes | + +## License + +Apache License 2.0 (see [LICENSE](LICENSE)). The patches in `patches/` are offered under the licenses of the projects they modify: ZLUDA (Apache-2.0 or MIT) and vkd3d-proton (LGPL-2.1). See [NOTICE](NOTICE). diff --git a/config/d4r.ini.default b/config/d4r.ini.default new file mode 100644 index 0000000..468c8c8 --- /dev/null +++ b/config/d4r.ini.default @@ -0,0 +1,126 @@ +; d4r configuration: official NVIDIA DLSS on AMD (ZLUDA + Wine CUDA bridge + NGX shim) +; +; Read by scripts/run_game_d4r_optiscaler_proton.sh at every game launch. The first launch copies +; this file to ~/.config/d4r/d4r.ini (or D4R_CONFIG); edit that copy. Changes apply at the next launch. +; +; Every value can be left as "auto" (or empty) to keep the built-in default. An environment variable +; set before launching (e.g. D4R_DLSS_PRESET=11) always wins over this file. +; Paths may use ~ for your home directory. + +[Launch] +; Used by scripts/d4r_play.sh (one-command launch). Examples: +; ProtonDir = ~/.local/share/Steam/compatibilitytools.d/GE-Proton11-3 +; CompatDataDir = ~/.local/share/Steam/steamapps/compatdata/ +; GameExe = ~/Games/MyGame/Binaries/Win64/MyGame-Win64-Shipping.exe +ProtonDir = +CompatDataDir = +GameExe = + +[DLSS] +; Which DLSS network ("preset") to run. fps measured on an RX 7700 XT, Townfall 2560x1440, same street +; walk, for Quality / Balanced / Performance / Ultra Performance (FSR 4: 76 / 85 / 94 / 107): +; E (or CNN) = DLSS 3 CNN, the fastest at Quality..Performance 72 / 81 / 88 / 89 +; K (or DLSS4) = DLSS 4 transformer, sharper; best at Ultra Perf 69 / 77 / 84 / 95 +; M (or DLSS4.5) = DLSS 4.5 transformer, best image, slowest 52 / 60 / 70 / 90 +; F = the other CNN (same speed as E); A, B, C, D, G, J run the K network in this DLSS version; +; L (DLSS 4.5 Ultra Performance model) is not accelerated here and runs very slowly. +; auto = whatever the game/OptiScaler asks for +Model = K +[Latency] +; How many frames old the upscaled image the game presents may be. +; 0 = same frame (no added latency, no trailing artefacts; needs VkD3DDir below) +; 1 = at most 1 frame old +; 2 = 2 frames old (roughly +20% fps with DLSS 4.5, adds ~2 frames of input latency, +; fast motion can trail) +; 3 = 2-3 frames old (about the same fps as 2 in practice) +FrameAge = 0 + +[Kernels] +; Native RDNA3 kernels for the DLSS 4 and 4.5 network layers (replace ZLUDA's translated code). +; fast = native kernels with relaxed numerics (visually identical to exact, ~15% faster) +; exact = native kernels that reproduce NVIDIA's FP8/f16 rounding bit for bit +; off = ZLUDA-translated kernels only +; fast/exact need the code objects built by the native-kernel tools ([Paths] NativeKernelDir*). +NativeKernels = off +; FP8 tensor-core emulation on RDNA3 WMMA (much faster than the scalar path). +Fp8Wmma = true +; Drop per-instruction flush-to-zero mode switches in ZLUDA-compiled kernels +; (only values below ~1e-38 differ; a little faster). +IgnoreDenormals = true +; Thread-block bound assumed for kernels without launch bounds (256 avoids register spills). +ImplicitMaxBlock = 256 + +[Interop] +; 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 +; Wait for the input copies before DLSS runs (prevents beaded thin lines in motion). Keep on. +InputSync = true +; Faster hand-offs between the game and DLSS (same frame, same result). Need FrameAge = 0 and VRAM +; interop, and a runtime built from this checkout (scripts/install_d4r_runtime.sh). +; GpuWait: DLSS is queued ahead and starts on the GPU the moment the game's inputs are ready +; LinearInputs: DLSS reads the game's inputs in place (no input copies; needs GpuWait) +; DirectOutput: the result is written straight into the game-side buffer (preset K, and only while +; NGX runs the native output kernel; drops NVIDIA's "DLSS SDK" watermark) +; ElideNgxSync: removes NGX's internal CPU waits between its GPU stages +; EvalSync = false: no CPU wait between DLSS and the output copy +; MarkerPollUs: how often (microseconds) the CPU checks for the game's inputs without GpuWait +GpuWait = true +LinearInputs = true +DirectOutput = true +ElideNgxSync = true +EvalSync = false +MarkerPollUs = 20 + +[Paths] +; auto = defaults of scripts/d4r_proton_env.sh +RuntimeDir = auto +; ZLUDA build (directory with libcuda.so / libnvcuda.so) +ZludaDir = auto +RocmDir = auto +; d4r-patched vkd3d-proton (d3d12.dll + d3d12core.dll); required for FrameAge = 0 +VkD3DDir = auto +; JIT cache directory (XDG_CACHE_HOME): auto = the default ~/.cache; per-zluda = one per ZLUDA build, +; ~/.cache/d4r-perf-game-jit- (a new ZLUDA build compiles every kernel once on first use) +JitCacheDir = auto +; Native kernel code objects, one directory per NativeKernels mode +NativeKernelDirFast = auto +NativeKernelDirExact = auto + +[Game] +; Unreal Engine games: extra console variables applied for this launch only (the game's Engine.ini is +; backed up and restored on exit). Example for sharper thin lines in SILENT HILL Townfall: +; EngineIni = ~/.local/share/Steam/steamapps/compatdata//pfx/drive_c/users/steamuser/AppData/Local/Townfall/Saved/Config/Windows/Engine.ini +; Cvars = r.Tonemapper.Sharpen=0;r.SceneColorFringeQuality=0 +EngineIni = +Cvars = + +[OptiScaler] +; OptiScaler's own FPS overlay (top left) +FpsOverlay = true +; 0 = simple ... 3 = detailed with frame-time graph +FpsOverlayType = 3 +LogLevel = 2 +; Override the render resolution OptiScaler requests per quality mode, e.g. 2.0 turns the game's +; "Quality" into Performance-level input (1280x720 for 1440p). auto = the game's choice. +QualityRatioQuality = auto +QualityRatioBalanced = auto +QualityRatioPerformance = auto +QualityRatioUltraPerformance = auto +; Any other OptiScaler.ini settings for this launch, "Section.Key=value;Section.Key=value" +Extra = + +[Overlay] +; MangoHud FPS counter (top right) +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) +Profile = false +; Log directory (auto = ~/.cache/d4r-dlss-captures/game--