mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
merge: upscale bridge DLLs (tools/upscale/bridges, add-on pack 'upscale') from wip/upscale-bridges
This commit is contained in:
commit
f2309c8a09
27 files changed
+5992
-6
No files matched your search
@@ -322,6 +322,9 @@ jobs:
|
||||
- name: Build the DiRT 3 / DiRT Showdown ws2_32 stand-in
|
||||
run: python3 tools/components/prepare.py dirt-ws2
|
||||
|
||||
- name: Build the DLSS / FSR / XeSS upscale bridges
|
||||
run: python3 tools/components/prepare.py upscale-bridges
|
||||
|
||||
- name: Cache graphics driver inputs
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
|
||||
@@ -55,7 +55,7 @@ jobs:
|
||||
jq -r --arg n "$2" '.assets // [] | .[] | select(.name == $n) | .digest // empty'
|
||||
}
|
||||
commit=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$BUILD_RUN" --jq .head_sha 2>/dev/null || echo "$GITHUB_SHA")
|
||||
for name in proot directaudio tracking xbox comet butler powervr ubisoft rockstar dirt epic; do
|
||||
for name in proot directaudio tracking xbox comet butler powervr ubisoft rockstar dirt epic upscale; do
|
||||
file="packs/$name.tar.zst"
|
||||
[ -f "$file" ] || { echo "::error::$name.tar.zst is missing from Build APK run $BUILD_RUN"; exit 1; }
|
||||
sha=$(sha256sum "$file" | cut -d' ' -f1)
|
||||
|
||||
+2
-2
@@ -93,7 +93,7 @@ def trackingPack = rootProject.file('tools/packs/tracking/release.env').readLine
|
||||
def prootPackPin = rootProject.file('tools/packs/proot/release.env').readLines()
|
||||
.findAll { it.contains('=') && !it.startsWith('#') }
|
||||
.collectEntries { def kv = it.split('=', 2); [(kv[0].trim()): kv[1].trim()] }
|
||||
def addonPacks = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'butler', 'powervr', 'ubisoft', 'rockstar', 'dirt', 'epic'].collectEntries { name ->
|
||||
def addonPacks = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'butler', 'powervr', 'ubisoft', 'rockstar', 'dirt', 'epic', 'upscale'].collectEntries { name ->
|
||||
def pack = file("build/packs/${name}.tar.zst")
|
||||
if (!pack.isFile()) {
|
||||
if (ciBuild) throw new GradleException("Add-on pack ${pack} is missing: run tools/packs/build.sh app/build/packs")
|
||||
@@ -203,7 +203,7 @@ android {
|
||||
}
|
||||
|
||||
androidResources {
|
||||
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~:<dir>droiddeck-xbox:<dir>droiddeck-comet:<dir>droiddeck-ubisoft:<dir>droiddeck-rockstar:<dir>droiddeck-dirt:<dir>droiddeck-epic:<dir>directaudio:<dir>hybris'
|
||||
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~:<dir>droiddeck-xbox:<dir>droiddeck-comet:<dir>droiddeck-ubisoft:<dir>droiddeck-rockstar:<dir>droiddeck-dirt:<dir>droiddeck-epic:<dir>droiddeck-upscale:<dir>directaudio:<dir>hybris'
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
|
||||
@@ -269,5 +269,41 @@
|
||||
"lld",
|
||||
"llvm"
|
||||
]
|
||||
},
|
||||
"upscale-bridges": {
|
||||
"script": "tools/components/recipes/upscale-bridges.sh",
|
||||
"inputs": [
|
||||
"tools/upscale/bridges",
|
||||
"tools/components/recipes/upscale-bridges.sh"
|
||||
],
|
||||
"outputs": [
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/_nvngx.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/amd_fidelityfx_dx12.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/amd_fidelityfx_loader_dx12.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/amd_fidelityfx_upscaler_dx12.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/amd_fidelityfx_upscaler_vk.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/amd_fidelityfx_vk.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/ffx_fsr2_api_x64.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/ffx_fsr3upscaler_x64.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/libxess.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/nvapi64.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/nvngx.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/x86_64-windows/nvngx_dlss.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/_nvngx.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/amd_fidelityfx_dx12.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/amd_fidelityfx_loader_dx12.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/amd_fidelityfx_upscaler_dx12.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/amd_fidelityfx_upscaler_vk.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/amd_fidelityfx_vk.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/ffx_fsr2_api_x64.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/ffx_fsr3upscaler_x64.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/libxess.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/nvapi64.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/nvngx.dll",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/aarch64-windows/nvngx_dlss.dll"
|
||||
],
|
||||
"packages": [
|
||||
"gcc-mingw-w64-x86-64"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
bash tools/upscale/bridges/build.sh app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges
|
||||
@@ -98,6 +98,11 @@ pack powervr "$repo/app/src/main/assets/hybris" runtime.tzst version.txt
|
||||
[ ! -f "$linuxfs/droiddeck-ubisoft/droiddeck-upc.exe" ] || pack ubisoft "$linuxfs/droiddeck-ubisoft" droiddeck-upc.exe
|
||||
[ ! -f "$linuxfs/droiddeck-rockstar/Launcher64.exe" ] || pack rockstar "$linuxfs/droiddeck-rockstar" Launcher32.exe Launcher64.exe
|
||||
[ ! -f "$linuxfs/droiddeck-dirt/ws2_32.dll" ] || pack dirt "$linuxfs/droiddeck-dirt" ws2_32.dll
|
||||
upscale=(_nvngx.dll amd_fidelityfx_dx12.dll amd_fidelityfx_loader_dx12.dll amd_fidelityfx_upscaler_dx12.dll
|
||||
amd_fidelityfx_upscaler_vk.dll amd_fidelityfx_vk.dll ffx_fsr2_api_x64.dll ffx_fsr3upscaler_x64.dll
|
||||
libxess.dll nvapi64.dll nvngx.dll nvngx_dlss.dll)
|
||||
[ ! -f "$linuxfs/droiddeck-upscale/bridges/x86_64-windows/nvngx.dll" ] || pack upscale "$linuxfs/droiddeck-upscale" \
|
||||
"${upscale[@]/#/bridges/x86_64-windows/}" "${upscale[@]/#/bridges/aarch64-windows/}"
|
||||
[ ! -f "$linuxfs/droiddeck-epic/EpicGamesLauncher.exe" ] || pack epic "$linuxfs/droiddeck-epic" EpicGamesLauncher.exe
|
||||
|
||||
mkdir "$work/butler"
|
||||
|
||||
@@ -16,17 +16,19 @@ PACKS = Path('app/build/packs')
|
||||
PACKED = {'assets/linuxfs/usr/local/lib/droiddeck-xbox/': 'xbox', 'assets/linuxfs/usr/local/lib/droiddeck-comet/': 'comet',
|
||||
'assets/linuxfs/usr/local/lib/droiddeck-ubisoft/': 'ubisoft', 'assets/linuxfs/usr/local/lib/droiddeck-rockstar/': 'rockstar',
|
||||
'assets/linuxfs/usr/local/lib/droiddeck-dirt/': 'dirt', 'assets/linuxfs/usr/local/lib/droiddeck-epic/': 'epic',
|
||||
'assets/linuxfs/usr/local/lib/droiddeck-upscale/': 'upscale',
|
||||
'assets/directaudio/': 'directaudio', 'assets/hybris/': 'powervr'}
|
||||
# DrWeb flags proot itself as Tool.Linux.Proot; the app runs the pack's copy through Android's linker.
|
||||
PACKED_FILES = {'lib/arm64-v8a/libproot.so': ('proot', 'libproot.so')}
|
||||
# The loader is execve'd, which targetSdk 29+ allows only from the APK's native library directory.
|
||||
PROOT_LOADER = {'lib/arm64-v8a/libproot-loader.so': 'libproot-loader.so'}
|
||||
PACKED_LIBRARIES = ['lib/arm64-v8a/libopencv_java4.so', 'lib/arm64-v8a/libmediapipe_tasks_jni.so']
|
||||
PACK_NAMES = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'butler', 'powervr', 'ubisoft', 'rockstar', 'dirt', 'epic']
|
||||
PACK_NAMES = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'butler', 'powervr', 'ubisoft', 'rockstar', 'dirt', 'epic',
|
||||
'upscale']
|
||||
SOURCE_PATHS = ['app/build.gradle', 'app/src/main/cpp/fakeinput_steam.cpp', 'app/src/main/assets/pulseaudio.tzst',
|
||||
'tools/linuxfs', 'tools/proot', 'tools/aaudio-sink', 'tools/directaudio', 'tools/packs',
|
||||
'tools/gamescope/release.env', 'tools/droiddeck-esync/release.env',
|
||||
'tools/mangoapp', 'tools/msitools', 'tools/pipewire', 'tools/comet', 'tools/xbox', 'tools/dirt-ws2', 'tools/ubisoft-launcher', 'tools/rockstar-launcher', 'tools/epic-launcher', 'tools/components', 'tools/ci', 'tools/build_local.sh',
|
||||
'tools/mangoapp', 'tools/msitools', 'tools/pipewire', 'tools/comet', 'tools/xbox', 'tools/dirt-ws2', 'tools/upscale', 'tools/ubisoft-launcher', 'tools/rockstar-launcher', 'tools/epic-launcher', 'tools/components', 'tools/ci', 'tools/build_local.sh',
|
||||
'tools/powervr', 'tools/hybris', 'tools/dxvk', 'tools/vulkan-wsi',
|
||||
'tools/release/runtime_inputs.py', 'app/src/main/assets/desktop-removal',
|
||||
'tools/quest', 'tools/vr/src', 'tools/vr/driver_droiddeck', 'tools/vr/layer', 'tools/vr/build.sh',
|
||||
@@ -253,7 +255,7 @@ def windows_binaries(package):
|
||||
def check_apk(apk, root=ROOT):
|
||||
data = verify(root)
|
||||
packs = {name: pack_digests(root, name) for name in PACK_NAMES
|
||||
if name not in ('ubisoft', 'rockstar', 'dirt', 'epic') or (root / PACKS / (name + '.tar.zst')).is_file()}
|
||||
if name not in ('ubisoft', 'rockstar', 'dirt', 'epic', 'upscale') or (root / PACKS / (name + '.tar.zst')).is_file()}
|
||||
for name, rel in PROOT_LOADER.items():
|
||||
if packs['proot'].get(rel) != data['outputs'][name]['sha256']:
|
||||
raise ValueError('Add-on pack proot is missing or has a stale ' + rel)
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
# Upscale bridge DLLs
|
||||
|
||||
Windows x86-64 DLLs that stand in for a game's DLSS, FidelityFX (FSR 2, FSR 3, FidelityFX API) and
|
||||
XeSS libraries inside Wine. They do not upscale anything themselves: each frame's colour, depth,
|
||||
motion-vector and output images are written into a host-visible Vulkan mailbox buffer, and a
|
||||
`vkCmdUpdateBuffer` "doorbell" on a marker buffer tells the Android Vulkan layer to record the
|
||||
upscaler into the game's command buffer. The layer finds both buffers by their sizes and magic
|
||||
numbers. `fsr4_seam_proto.h` is that contract and is a verbatim copy of the fork's
|
||||
`app/src/main/cpp/fsr4npu/fsr4_seam_proto.h` (sha256 `a9f614c53ae9209edf0fa9c5acb0a27fdf923c08026362b23f60e1bcb39acd15`).
|
||||
It must stay byte-identical to the layer's copy. If the layer does not acknowledge a frame,
|
||||
the bridge blits the render-resolution image to the output (bilinear) so the game never shows
|
||||
stale memory. D3D12 games reach Vulkan through vkd3d-proton's `ID3D12DXVKInteropDevice1`.
|
||||
|
||||
| DLL | Source | Export list | Replaces |
|
||||
| --- | --- | --- | --- |
|
||||
| `amd_fidelityfx_vk.dll` | `wl_ffx_bridge.c` | `wl_ffx_bridge.def` | FidelityFX API (`ffxCreateContext`, `ffxDispatch`, ...) |
|
||||
| `amd_fidelityfx_dx12.dll`, `amd_fidelityfx_upscaler_vk.dll`, `amd_fidelityfx_upscaler_dx12.dll`, `amd_fidelityfx_loader_dx12.dll` | copies of `amd_fidelityfx_vk.dll` | | the same API under the other SDK file names |
|
||||
| `ffx_fsr3upscaler_x64.dll` | `wl_fsr23_bridge.c` | `ffx_fsr3upscaler_x64.def` | FSR 3.0 / 3.1 upscaler |
|
||||
| `ffx_fsr2_api_x64.dll` | `wl_fsr23_bridge.c` | `ffx_fsr2_api_x64.def` | FSR 2.0 / 2.1 / 2.2 |
|
||||
| `libxess.dll` | `wl_xess_bridge.c` | `libxess.def` | Intel XeSS 1.3 / 2.0 (D3D12 + Vulkan) |
|
||||
| `nvngx.dll` | `wl_ngx_bridge.c` | `nvngx.def` | NVIDIA NGX / DLSS Super Resolution (Vulkan + D3D12) |
|
||||
| `_nvngx.dll`, `nvngx_dlss.dll` | copies of `nvngx.dll` | | the names games and Streamline load NGX by |
|
||||
| `nvapi64.dll` | `wl_nvapi_shim.c` (+ `wl_ngx_hooks.h`) | `nvapi64.def` | NVAPI, reporting an RTX 2060 so games offer DLSS |
|
||||
|
||||
`wl_fsr23_bridge.c` exports both the FSR 2 and FSR 3 entry points, so both DLLs carry all 21.
|
||||
`nvngx.dll` exports the 88 `.def` names plus 9 that only its source marks `__declspec(dllexport)`. `build.sh`
|
||||
fails when a DLL's exports (from `x86_64-w64-mingw32-objdump -p`) differ from its `.def` plus
|
||||
its source's `dllexport` names.
|
||||
|
||||
When the XeSS 3.0 backend is selected, `wl_xess3_direct.h` loads Intel's XeSS SDK runtime as
|
||||
`wl_xess_official.dll` (from the DLL search path, then `C:\windows\system32`). When it is missing or
|
||||
fails, the frame goes to the layer flagged `WLFSR4_FLAG_XESS_FALLBACK` (FSR 3.1 on the GPU). That DLL is Intel's prebuilt binary and is not built here.
|
||||
|
||||
## Build
|
||||
|
||||
```sh
|
||||
bash tools/upscale/bridges/build.sh OUT
|
||||
```
|
||||
|
||||
Needs `x86_64-w64-mingw32-gcc` (Ubuntu `gcc-mingw-w64-x86-64`) and `python3`. The output is
|
||||
deterministic (`-s`, `-Wl,--no-insert-timestamp`, linked under the bare DLL name because `ld`
|
||||
derives the image base from the output path). Every DLL is stamped as a Wine builtin the way
|
||||
`winebuild --builtin` does it: the 32-byte `"Wine builtin DLL"` signature, zero-padded, at file
|
||||
offset 0x40 (`pe.py stamp`). Wine then loads them from `WINEDLLPATH` when the override is
|
||||
`builtin`. The same x86-64 files are installed to `OUT/x86_64-windows/` and
|
||||
`OUT/aarch64-windows/`, because the ARM64EC Wine loads x86-64 builtins from the latter.
|
||||
|
||||
CI builds them with the `upscale-bridges` component recipe into
|
||||
`app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale/bridges/`. The APK may not carry
|
||||
Windows executables (`tools/release/runtime_inputs.py`), so they ship in the `upscale` add-on
|
||||
pack (`tools/packs/build.sh`), whose entries are `bridges/{x86_64,aarch64}-windows/<dll>`.
|
||||
|
||||
## Environment
|
||||
|
||||
| Variable | Default | Effect |
|
||||
| --- | --- | --- |
|
||||
| `DROIDDECK_UPSCALE_BACKEND` (then `DROIDDECK_UPSCALE_ENGINE`, `WINLATOR_FSR4_BACKEND`, `WINLATOR_FSR4_ENGINE`) | `fsr4_0_npu` | Backend the bridges assume until the layer writes its live control word: `fsr3_gpu`, `xess3_gpu`, `fsr4_0_npu`, `fsr4_1_lite_npu`, `fsr4_1_full_npu`, `fsr4_1_lite_gpu`, `fsr4_1_full_gpu` |
|
||||
| `DROIDDECK_UPSCALE_VRAM_MB` (then `WINLATOR_FSR4_VRAM_MB`, `WRAPPER_VMEM_MAX_SIZE`) | DXGI adapter 0, else 12 GB | VRAM `nvapi64.dll` reports (512-65536 MB) |
|
||||
| `DROIDDECK_UPSCALE_SIGFIX=1` | off | `nvapi64.dll` patches the import tables of loaded modules (LoadLibrary*, GetProcAddress, GetFileAttributes*, CreateFileW, Reg*), redirects `nvngx`/`_nvngx` loads to `C:\windows\system32\_nvngx.dll`, fakes the NVIDIA signature-override registry keys, forces `WinVerifyTrust` success and redirects `CryptQueryObject` for `nvngx`/`amd_fidelityfx*`, so games that signature-check NGX load the bridge. Never applied to rdr2.exe, playrdr2.exe or gta5.exe |
|
||||
| `DROIDDECK_UPSCALE_LOG=1` | off | Hook messages appended to `C:\windows\temp\wl_fsr4_bridge.log` |
|
||||
|
||||
## Changes from the fork
|
||||
|
||||
- D3D11 NGX reports DLSS unavailable (`SuperSampling.Available` 0, feature requirements
|
||||
`AdapterUnsupported`, `CreateFeature`/`EvaluateFeature` return
|
||||
`NVSDK_NGX_Result_FAIL_FeatureNotSupported`). The fork returned success and rendered nothing,
|
||||
because D3D11 has no route to the Vulkan layer.
|
||||
- The `nvapi64.dll` hooks are off unless `DROIDDECK_UPSCALE_SIGFIX=1`; the fork always installed them.
|
||||
- Logging is off unless `DROIDDECK_UPSCALE_LOG=1`; the fork always wrote the log.
|
||||
- `DROIDDECK_UPSCALE_*` variables are read first, the fork's names after them (`dd_env.h`).
|
||||
- `fsr4_seam_proto.h` is included from this folder instead of `../fsr4npu/`.
|
||||
- Built with Ubuntu's MinGW-w64 GCC (msvcrt) instead of the fork's PowerShell script; flags as in
|
||||
its `build_win_dlls.ps1` plus `-s` and `-Wl,--no-insert-timestamp`. The fork stamped the
|
||||
signature at install time; here it is stamped at build time.
|
||||
|
||||
Seam protocol, struct layouts, magics and backend IDs are unchanged.
|
||||
|
||||
## Credits and licence
|
||||
|
||||
Ported from [michaelisomer-cyber/Winlator-NeuralScale](https://github.com/michaelisomer-cyber/Winlator-NeuralScale)
|
||||
at `a0ab6b0f770e1a6786b4e68def46b4edb8baafd0` (`app/src/main/cpp/fsr4npu_win/`), GPL-3.0. That fork
|
||||
builds on [StevenMXZ/Winlator-Ludashi](https://github.com/StevenMXZ/Winlator-Ludashi). The NGX
|
||||
and NVAPI shims follow OptiScaler's approach (and fakenvapi's NVAPI interface). These files stay
|
||||
under the GPL-3.0, the licence of this repository (`LICENSE`); modified files say so in their
|
||||
first line.
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
mkdir -p "${1:?usage: build.sh <out-dir>}"
|
||||
out=$(cd "$1" && pwd)
|
||||
work=$(mktemp -d)
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
|
||||
cc=x86_64-w64-mingw32-gcc
|
||||
objdump=x86_64-w64-mingw32-objdump
|
||||
for tool in "$cc" "$objdump"; do
|
||||
command -v "$tool" >/dev/null || { echo "upscale-bridges: $tool not found (apt install gcc-mingw-w64-x86-64)" >&2; exit 1; }
|
||||
done
|
||||
cflags=(-O2 -shared -s -Wall -Wextra -Wno-unused-function -static-libgcc -I"$here"
|
||||
-ffile-prefix-map="$here"=. -Wl,--no-insert-timestamp)
|
||||
|
||||
build() {
|
||||
local name=$1 source=$2 definition=$3
|
||||
shift 3
|
||||
# ld derives the DLL's image base from the -o path, so link in $work under the bare name.
|
||||
(cd "$work" && "$cc" "${cflags[@]}" "$here/$source" "$here/$definition" "$@" -o "$name")
|
||||
python3 -I "$here/pe.py" verify "$work/$name" "$here/$definition" "$here/$source" "$objdump"
|
||||
python3 -I "$here/pe.py" stamp "$work/$name"
|
||||
}
|
||||
|
||||
build amd_fidelityfx_vk.dll wl_ffx_bridge.c wl_ffx_bridge.def -lm
|
||||
for name in amd_fidelityfx_dx12.dll amd_fidelityfx_upscaler_vk.dll amd_fidelityfx_upscaler_dx12.dll amd_fidelityfx_loader_dx12.dll; do
|
||||
cp "$work/amd_fidelityfx_vk.dll" "$work/$name"
|
||||
done
|
||||
build libxess.dll wl_xess_bridge.c libxess.def -lm
|
||||
build ffx_fsr3upscaler_x64.dll wl_fsr23_bridge.c ffx_fsr3upscaler_x64.def -lm
|
||||
build ffx_fsr2_api_x64.dll wl_fsr23_bridge.c ffx_fsr2_api_x64.def -lm
|
||||
build nvngx.dll wl_ngx_bridge.c nvngx.def -lm
|
||||
for name in _nvngx.dll nvngx_dlss.dll; do
|
||||
cp "$work/nvngx.dll" "$work/$name"
|
||||
done
|
||||
build nvapi64.dll wl_nvapi_shim.c nvapi64.def
|
||||
|
||||
names=(_nvngx.dll amd_fidelityfx_dx12.dll amd_fidelityfx_loader_dx12.dll amd_fidelityfx_upscaler_dx12.dll
|
||||
amd_fidelityfx_upscaler_vk.dll amd_fidelityfx_vk.dll ffx_fsr2_api_x64.dll ffx_fsr3upscaler_x64.dll
|
||||
libxess.dll nvapi64.dll nvngx.dll nvngx_dlss.dll)
|
||||
[ "$(ls "$work" | sort)" = "$(printf '%s\n' "${names[@]}" | sort)" ] || { echo "upscale-bridges: unexpected outputs" >&2; exit 1; }
|
||||
# The ARM64EC Wine loads x86-64 builtins from aarch64-windows as well.
|
||||
for arch in x86_64-windows aarch64-windows; do
|
||||
rm -rf "${out:?}/$arch"
|
||||
mkdir -p "$out/$arch"
|
||||
for name in "${names[@]}"; do
|
||||
install -m 644 "$work/$name" "$out/$arch/$name"
|
||||
done
|
||||
done
|
||||
@@ -0,0 +1,20 @@
|
||||
// DroidDeck: environment lookups shared by the upscale bridges.
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
// Copies the first variable in the NULL-terminated list that is set and fits into buf.
|
||||
static DWORD dd_env_first(const char *const *names, char *buf, DWORD size) {
|
||||
for (; *names; names++) {
|
||||
DWORD n = GetEnvironmentVariableA(*names, buf, size);
|
||||
if (n > 0 && n < size) return n;
|
||||
}
|
||||
if (size) buf[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dd_env_is_on(const char *name) {
|
||||
char buf[8];
|
||||
DWORD n = GetEnvironmentVariableA(name, buf, sizeof buf);
|
||||
return n == 1 && buf[0] == '1';
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
LIBRARY ffx_fsr2_api_x64.dll
|
||||
EXPORTS
|
||||
ffxFsr2ContextCreate
|
||||
ffxFsr2ContextDispatch
|
||||
ffxFsr2ContextGenerateReactiveMask
|
||||
ffxFsr2ContextDestroy
|
||||
ffxFsr2GetUpscaleRatioFromQualityMode
|
||||
ffxFsr2GetRenderResolutionFromQualityMode
|
||||
ffxFsr2GetJitterPhaseCount
|
||||
ffxFsr2GetJitterOffset
|
||||
ffxFsr2ResourceIsNull
|
||||
@@ -0,0 +1,14 @@
|
||||
LIBRARY ffx_fsr3upscaler_x64.dll
|
||||
EXPORTS
|
||||
ffxFsr3UpscalerContextCreate
|
||||
ffxFsr3UpscalerGetSharedResourceDescriptions
|
||||
ffxFsr3UpscalerContextDispatch
|
||||
ffxFsr3UpscalerContextGenerateReactiveMask
|
||||
ffxFsr3UpscalerContextDestroy
|
||||
ffxFsr3UpscalerGetUpscaleRatioFromQualityMode
|
||||
ffxFsr3UpscalerGetRenderResolutionFromQualityMode
|
||||
ffxFsr3UpscalerGetJitterPhaseCount
|
||||
ffxFsr3UpscalerGetJitterOffset
|
||||
ffxFsr3UpscalerResourceIsNull
|
||||
ffxFsr3UpscalerSetConstant
|
||||
ffxFsr3UpscalerGetEffectVersion
|
||||
@@ -0,0 +1,162 @@
|
||||
// Shared in-process zero-copy Wine <-> Android Vulkan Layer mailbox/doorbell protocol
|
||||
// for Winlator Ludashi FSR 4.1.1 on Qualcomm Hexagon HTP v81 NPU.
|
||||
//
|
||||
// Used identically by:
|
||||
// - Android ARM64 Vulkan Layer: libVkLayer_winlator_fsr4_npu.so
|
||||
// - Windows x86_64 Bridge DLLs: amd_fidelityfx_vk.dll, amd_fidelityfx_dx12.dll, nvngx.dll
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Exact buffer creation signatures recognized by libVkLayer_winlator_fsr4_npu.so
|
||||
// via vkCreateBuffer / vkBindBufferMemory / vkMapMemory / vkCmdUpdateBuffer.
|
||||
#define WLFSR4_MAILBOX_BYTES 0x2000u /* 8192 bytes: header + 4 ring slots */
|
||||
#define WLFSR4_MARKER_BYTES 0x02D0u /* 720 bytes: doorbell target buffer */
|
||||
#define WLFSR4_MAILBOX_MAGIC 0x345253464E4C5755ULL /* "UWLNFSR4" */
|
||||
#define WLFSR4_DOORBELL_MAGIC 0x444246535234574CULL /* "LWR4SFBD" */
|
||||
#define WLFSR4_HELLO_MAGIC 0x48454C4F46535234ULL /* "4RSFOLEH" */
|
||||
#define WLFSR4_TELEMETRY_MAGIC 0x54454C4D46535234ULL /* "4RSFMLET" (XeSS 3.0 direct telemetry ping) */
|
||||
#define WLFSR4_PROTO_VERSION 2u
|
||||
#define WLFSR4_SLOTS 4u
|
||||
|
||||
// Multi-backend IDs shared across Android Vulkan layer, Windows bridge DLLs, and Java/Kotlin UI
|
||||
enum {
|
||||
WL_FSR_BACKEND_FSR3_GPU = 0, /* FSR 3.1 (GPU) */
|
||||
WL_FSR_BACKEND_XESS3_GPU = 1, /* XeSS 3.0 DP4a (GPU, official libxess.dll) */
|
||||
WL_FSR_BACKEND_FSR4_0_NPU = 2, /* FSR 4.0.2 INT8 (Hexagon HTP NPU) */
|
||||
WL_FSR_BACKEND_FSR4_1_LITE_NPU = 3, /* FSR 4.1.2 Lite INT8 (Hexagon HTP NPU) */
|
||||
WL_FSR_BACKEND_FSR4_1_FULL_NPU = 4, /* FSR 4.1.1 Full INT8 (Hexagon HTP NPU) */
|
||||
WL_FSR_BACKEND_FSR4_1_LITE_GPU = 5, /* FSR 4.1.2 Lite INT8 (Adreno Vulkan DP4a GPU) */
|
||||
WL_FSR_BACKEND_FSR4_1_FULL_GPU = 6, /* FSR 4.1.1 Full INT8 (Adreno Vulkan DP4a GPU) */
|
||||
};
|
||||
|
||||
// Packed live control bits written by the Vulkan layer into mailbox->live_ctrl
|
||||
#define WLFSR4_CTRL_BACKEND_MASK 0xFFULL
|
||||
#define WLFSR4_CTRL_ENABLED_BIT (1ULL << 8)
|
||||
#define WLFSR4_CTRL_SYNC_BIT (1ULL << 9)
|
||||
#define WLFSR4_CTRL_SHARP_SHIFT 16u
|
||||
#define WLFSR4_CTRL_SHARP_MASK 0xFFFFULL /* sharpness * 1000 */
|
||||
|
||||
// Ack flags written by the Vulkan layer into mailbox->ack
|
||||
#define WLFSR4_ACK_WORK_BIT 0x8000000000000000ULL /* real GPU/NPU work recorded */
|
||||
#define WLFSR4_ACK_NPU_ACTIVE_BIT 0x4000000000000000ULL /* Hexagon HTP NPU path active */
|
||||
#define WLFSR4_ACK_SEQ_MASK 0x0000FFFFFFFFFFFFULL
|
||||
|
||||
// Frame flags
|
||||
#define WLFSR4_FLAG_RESET (1u << 0)
|
||||
#define WLFSR4_FLAG_HDR (1u << 1)
|
||||
#define WLFSR4_FLAG_SRGB_OUT (1u << 2)
|
||||
#define WLFSR4_FLAG_DEPTH_INVERTED (1u << 3)
|
||||
#define WLFSR4_FLAG_DISPLAY_RES_MV (1u << 4)
|
||||
#define WLFSR4_FLAG_SHARPEN (1u << 5)
|
||||
#define WLFSR4_FLAG_MV_JITTERED (1u << 6)
|
||||
#define WLFSR4_FLAG_AUTO_EXPOSURE (1u << 7)
|
||||
#define WLFSR4_FLAG_XESS_FALLBACK (1u << 8) /* Bridge fell back from XeSS 3.0 -> request FSR 3.1 GPU */
|
||||
|
||||
// Source API tag (for logging & heuristics)
|
||||
enum {
|
||||
WLFSR4_API_UNKNOWN = 0,
|
||||
WLFSR4_API_FFX_VK = 1,
|
||||
WLFSR4_API_FFX_DX12 = 2,
|
||||
WLFSR4_API_NGX_VK = 3,
|
||||
WLFSR4_API_NGX_DX12 = 4,
|
||||
WLFSR4_API_XESS_VK = 5,
|
||||
WLFSR4_API_XESS_DX12 = 6,
|
||||
WLFSR4_API_FSR3_VK = 7,
|
||||
WLFSR4_API_FSR3_DX12 = 8,
|
||||
WLFSR4_API_FSR2_VK = 9,
|
||||
WLFSR4_API_FSR2_DX12 = 10,
|
||||
};
|
||||
|
||||
// Preset hint
|
||||
enum {
|
||||
WLFSR4_PRESET_AUTO = 0,
|
||||
WLFSR4_PRESET_PERF = 1,
|
||||
WLFSR4_PRESET_ULTRAPERF = 2,
|
||||
};
|
||||
|
||||
// In-game quality mode reported by DLSS / FidelityFX bridge -> Vulkan layer -> Left Sidebar
|
||||
enum {
|
||||
WLFSR4_QUALITY_AUTO = 0,
|
||||
WLFSR4_QUALITY_NATIVE_AA = 1, /* DLAA / Native AA (1.0x) */
|
||||
WLFSR4_QUALITY_QUALITY = 2, /* Quality (1.5x) */
|
||||
WLFSR4_QUALITY_BALANCED = 3, /* Balanced (1.7x) */
|
||||
WLFSR4_QUALITY_PERF = 4, /* Performance (2.0x) */
|
||||
WLFSR4_QUALITY_ULTRA_PERF = 5, /* Ultra Performance (3.0x) */
|
||||
WLFSR4_QUALITY_ULTRA_QUAL = 6, /* Ultra Quality (1.3x) */
|
||||
};
|
||||
|
||||
typedef struct WlFsr4ImageRef {
|
||||
uint64_t vk_image; /* non-dispatchable VkImage handle (guest == host under winevulkan) */
|
||||
uint64_t vk_view; /* optional VkImageView handle (0 = layer creates its own view) */
|
||||
uint32_t vk_format; /* VkFormat */
|
||||
uint32_t vk_layout; /* VkImageLayout at dispatch entry & expected at exit */
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t aspect; /* VkImageAspectFlags (0 = auto color/depth) */
|
||||
uint32_t reserved;
|
||||
} WlFsr4ImageRef; /* 40 bytes */
|
||||
|
||||
typedef struct WlFsr4FrameDesc {
|
||||
uint64_t seq;
|
||||
uint64_t reserved_handle;
|
||||
WlFsr4ImageRef color;
|
||||
WlFsr4ImageRef depth;
|
||||
WlFsr4ImageRef motion;
|
||||
WlFsr4ImageRef output;
|
||||
uint32_t render_w;
|
||||
uint32_t render_h;
|
||||
uint32_t output_w;
|
||||
uint32_t output_h;
|
||||
float jitter_x;
|
||||
float jitter_y;
|
||||
float mv_scale_x;
|
||||
float mv_scale_y;
|
||||
float pre_exposure;
|
||||
float sharpness;
|
||||
float frame_time_ms;
|
||||
float camera_near;
|
||||
float camera_far;
|
||||
float camera_fov_y;
|
||||
uint32_t flags;
|
||||
uint32_t api_source;
|
||||
uint32_t preset_hint;
|
||||
uint32_t quality_mode; /* WLFSR4_QUALITY_* */
|
||||
uint32_t pad[2];
|
||||
} WlFsr4FrameDesc; /* 256 bytes */
|
||||
|
||||
typedef struct WlFsr4Mailbox {
|
||||
volatile uint64_t magic;
|
||||
volatile uint64_t version;
|
||||
volatile uint64_t ack; /* layer writes seq | flags synchronously inside vkCmdUpdateBuffer */
|
||||
volatile uint64_t ack_count;
|
||||
volatile uint64_t layer_caps; /* bit 0: layer alive, bit 1: HTP NPU ready, bit 2: 1080p shaders ready */
|
||||
volatile uint64_t npu_dispatches;
|
||||
volatile uint32_t last_htp_us; /* last Hexagon HTP execution time in microseconds */
|
||||
volatile uint32_t last_status; /* 0=ok, 1=fallback-blit, 2=error */
|
||||
volatile uint64_t live_ctrl; /* WLFSR4_CTRL_* packed live control synced from Android UI */
|
||||
volatile uint32_t last_gpu_us; /* last GPU upscaler execution time in microseconds */
|
||||
volatile uint32_t tele_gpu_us; /* bridge-reported XeSS 3.0 GPU/CPU time (us) on TELEMETRY ping */
|
||||
uint64_t reserved[6];
|
||||
WlFsr4FrameDesc slots[WLFSR4_SLOTS];
|
||||
} WlFsr4Mailbox;
|
||||
|
||||
typedef struct WlFsr4DoorbellPayload {
|
||||
uint64_t magic;
|
||||
uint64_t seq;
|
||||
} WlFsr4DoorbellPayload;
|
||||
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||
_Static_assert(sizeof(WlFsr4ImageRef) == 40, "WlFsr4ImageRef size");
|
||||
_Static_assert(sizeof(WlFsr4FrameDesc) == 256, "WlFsr4FrameDesc size");
|
||||
_Static_assert(sizeof(WlFsr4Mailbox) <= WLFSR4_MAILBOX_BYTES, "WlFsr4Mailbox fits in 8KB");
|
||||
_Static_assert(sizeof(WlFsr4DoorbellPayload) == 16, "WlFsr4DoorbellPayload size");
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
LIBRARY libxess.dll
|
||||
EXPORTS
|
||||
xessGetVersion
|
||||
xessGetIntelXeFXVersion
|
||||
xessIsOptimalDriver
|
||||
xessSetLoggingCallback
|
||||
xessGetProperties
|
||||
xessGetInputResolution
|
||||
xessGetOptimalInputResolution
|
||||
xessGetJitterScale
|
||||
xessSetJitterScale
|
||||
xessGetVelocityScale
|
||||
xessSetVelocityScale
|
||||
xessSetExposureMultiplier
|
||||
xessGetExposureMultiplier
|
||||
xessSetMaxResponsiveMaskValue
|
||||
xessGetMaxResponsiveMaskValue
|
||||
xessForceLegacyScaleFactors
|
||||
xessGetPipelineBuildStatus
|
||||
xessDestroyContext
|
||||
xessSelectNetworkModel
|
||||
xessStartDump
|
||||
xessGetProfilingData
|
||||
xessSetContextParameterF
|
||||
xessD3D12CreateContext
|
||||
xessD3D12BuildPipelines
|
||||
xessD3D12Init
|
||||
xessD3D12GetInitParams
|
||||
xessD3D12Execute
|
||||
xessD3D12GetProfilingData
|
||||
xessD3D12GetResourcesToDump
|
||||
xessVKGetRequiredInstanceExtensions
|
||||
xessVKGetRequiredDeviceExtensions
|
||||
xessVKGetRequiredDeviceFeatures
|
||||
xessVKCreateContext
|
||||
xessVKBuildPipelines
|
||||
xessVKInit
|
||||
xessVKGetInitParams
|
||||
xessVKExecute
|
||||
xessVKGetResourcesToDump
|
||||
@@ -0,0 +1,3 @@
|
||||
LIBRARY nvapi64
|
||||
EXPORTS
|
||||
nvapi_QueryInterface
|
||||
@@ -0,0 +1,90 @@
|
||||
LIBRARY nvngx
|
||||
EXPORTS
|
||||
GetNGXResultAsString
|
||||
NVSDK_NGX_CUDA_AllocateParameters
|
||||
NVSDK_NGX_CUDA_CreateFeature
|
||||
NVSDK_NGX_CUDA_DestroyParameters
|
||||
NVSDK_NGX_CUDA_EvaluateFeature
|
||||
NVSDK_NGX_CUDA_GetCapabilityParameters
|
||||
NVSDK_NGX_CUDA_GetParameters
|
||||
NVSDK_NGX_CUDA_GetScratchBufferSize
|
||||
NVSDK_NGX_CUDA_Init
|
||||
NVSDK_NGX_CUDA_Init_with_ProjectID
|
||||
NVSDK_NGX_CUDA_ReleaseFeature
|
||||
NVSDK_NGX_CUDA_Shutdown
|
||||
NVSDK_NGX_D3D11_AllocateParameters
|
||||
NVSDK_NGX_D3D11_CreateFeature
|
||||
NVSDK_NGX_D3D11_DestroyParameters
|
||||
NVSDK_NGX_D3D11_EvaluateFeature
|
||||
NVSDK_NGX_D3D11_EvaluateFeature_C
|
||||
NVSDK_NGX_D3D11_GetCapabilityParameters
|
||||
NVSDK_NGX_D3D11_GetFeatureRequirements
|
||||
NVSDK_NGX_D3D11_GetParameters
|
||||
NVSDK_NGX_D3D11_GetScratchBufferSize
|
||||
NVSDK_NGX_D3D11_Init
|
||||
NVSDK_NGX_D3D11_Init_Ext
|
||||
NVSDK_NGX_D3D11_Init_ProjectID
|
||||
NVSDK_NGX_D3D11_Init_with_ProjectID
|
||||
NVSDK_NGX_D3D11_PopulateParameters_Impl
|
||||
NVSDK_NGX_D3D11_ReleaseFeature
|
||||
NVSDK_NGX_D3D11_Shutdown
|
||||
NVSDK_NGX_D3D11_Shutdown1
|
||||
NVSDK_NGX_D3D12_AllocateParameters
|
||||
NVSDK_NGX_D3D12_CreateFeature
|
||||
NVSDK_NGX_D3D12_DestroyParameters
|
||||
NVSDK_NGX_D3D12_EvaluateFeature
|
||||
NVSDK_NGX_D3D12_GetCapabilityParameters
|
||||
NVSDK_NGX_D3D12_GetFeatureRequirements
|
||||
NVSDK_NGX_D3D12_GetParameters
|
||||
NVSDK_NGX_D3D12_GetScratchBufferSize
|
||||
NVSDK_NGX_D3D12_Init
|
||||
NVSDK_NGX_D3D12_Init_Ext
|
||||
NVSDK_NGX_D3D12_Init_ProjectID
|
||||
NVSDK_NGX_D3D12_Init_with_ProjectID
|
||||
NVSDK_NGX_D3D12_PopulateParameters_Impl
|
||||
NVSDK_NGX_D3D12_ReleaseFeature
|
||||
NVSDK_NGX_D3D12_Shutdown
|
||||
NVSDK_NGX_D3D12_Shutdown1
|
||||
NVSDK_NGX_GetSnippetVersion
|
||||
NVSDK_NGX_Parameter_GetD
|
||||
NVSDK_NGX_Parameter_GetD3d11Resource
|
||||
NVSDK_NGX_Parameter_GetD3d12Resource
|
||||
NVSDK_NGX_Parameter_GetF
|
||||
NVSDK_NGX_Parameter_GetI
|
||||
NVSDK_NGX_Parameter_GetUI
|
||||
NVSDK_NGX_Parameter_GetULL
|
||||
NVSDK_NGX_Parameter_GetVoidPointer
|
||||
NVSDK_NGX_Parameter_SetD
|
||||
NVSDK_NGX_Parameter_SetD3d11Resource
|
||||
NVSDK_NGX_Parameter_SetD3d12Resource
|
||||
NVSDK_NGX_Parameter_SetF
|
||||
NVSDK_NGX_Parameter_SetI
|
||||
NVSDK_NGX_Parameter_SetUI
|
||||
NVSDK_NGX_Parameter_SetULL
|
||||
NVSDK_NGX_Parameter_SetVoidPointer
|
||||
NVSDK_NGX_UpdateFeature
|
||||
NVSDK_NGX_VULKAN_AllocateParameters
|
||||
NVSDK_NGX_VULKAN_CreateFeature
|
||||
NVSDK_NGX_VULKAN_CreateFeature1
|
||||
NVSDK_NGX_VULKAN_DestroyParameters
|
||||
NVSDK_NGX_VULKAN_EvaluateFeature
|
||||
NVSDK_NGX_VULKAN_EvaluateFeature_C
|
||||
NVSDK_NGX_VULKAN_GetCapabilityParameters
|
||||
NVSDK_NGX_VULKAN_GetFeatureDeviceExtensionRequirements
|
||||
NVSDK_NGX_VULKAN_GetFeatureExtensionRequirements
|
||||
NVSDK_NGX_VULKAN_GetFeatureInstanceExtensionRequirements
|
||||
NVSDK_NGX_VULKAN_GetFeatureRequirements
|
||||
NVSDK_NGX_VULKAN_GetParameter
|
||||
NVSDK_NGX_VULKAN_GetParameters
|
||||
NVSDK_NGX_VULKAN_GetScratchBufferSize
|
||||
NVSDK_NGX_VULKAN_Init
|
||||
NVSDK_NGX_VULKAN_Init_Ext
|
||||
NVSDK_NGX_VULKAN_Init_Ext2
|
||||
NVSDK_NGX_VULKAN_Init_ProjectID_Ext
|
||||
NVSDK_NGX_VULKAN_Init_with_ProjectID
|
||||
NVSDK_NGX_VULKAN_PopulateParameters_Impl
|
||||
NVSDK_NGX_VULKAN_ReleaseFeature
|
||||
NVSDK_NGX_VULKAN_RequiredExtensions
|
||||
NVSDK_NGX_VULKAN_SetParameter
|
||||
NVSDK_NGX_VULKAN_Shutdown
|
||||
NVSDK_NGX_VULKAN_Shutdown1
|
||||
@@ -0,0 +1,79 @@
|
||||
"""Stamp and check the upscale bridge DLLs.
|
||||
|
||||
stamp DLL write Wine's builtin signature at 0x40, as winebuild --builtin does
|
||||
verify DLL DEF SRC OBJDUMP the exports `OBJDUMP -p` reports must be the .def names plus SRC's dllexports
|
||||
"""
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# tools/winebuild/spec32.c: static const char builtin_signature[32] = "Wine builtin DLL";
|
||||
SIGNATURE = b'Wine builtin DLL'.ljust(32, b'\0')
|
||||
OFFSET = 0x40
|
||||
|
||||
|
||||
def stamp(dll):
|
||||
data = bytearray(Path(dll).read_bytes())
|
||||
if data[:2] != b'MZ':
|
||||
sys.exit(f'{dll}: not a PE file')
|
||||
lfanew = int.from_bytes(data[0x3c:0x40], 'little')
|
||||
if lfanew < OFFSET + len(SIGNATURE):
|
||||
sys.exit(f'{dll}: not enough space ({lfanew:#x}) for the Wine signature')
|
||||
data[OFFSET:OFFSET + len(SIGNATURE)] = SIGNATURE
|
||||
Path(dll).write_bytes(data)
|
||||
if Path(dll).read_bytes()[OFFSET:OFFSET + len(SIGNATURE)] != SIGNATURE:
|
||||
sys.exit(f'{dll}: Wine signature did not stick')
|
||||
|
||||
|
||||
def def_names(path):
|
||||
names, exports = set(), False
|
||||
for line in Path(path).read_text().splitlines():
|
||||
line = line.split(';', 1)[0].strip()
|
||||
if not line:
|
||||
continue
|
||||
if line.upper() == 'EXPORTS':
|
||||
exports = True
|
||||
elif exports:
|
||||
names.add(line.split()[0].split('=', 1)[0])
|
||||
return names
|
||||
|
||||
|
||||
def source_names(path):
|
||||
text = Path(path).read_text()
|
||||
return {re.findall(r'\w+', head)[-1] for head in re.findall(r'__declspec\(dllexport\)([^(;{]*)\(', text)}
|
||||
|
||||
|
||||
def exports(dll, objdump):
|
||||
report = subprocess.run([objdump, '-p', dll], check=True, capture_output=True, text=True).stdout
|
||||
if 'file format pei-x86-64' not in report:
|
||||
sys.exit(f'{dll}: not an x86-64 PE image')
|
||||
table = report.split('[Ordinal/Name Pointer] Table', 1)
|
||||
if len(table) != 2:
|
||||
sys.exit(f'{dll}: no export table')
|
||||
names = []
|
||||
for line in table[1].splitlines()[2:]:
|
||||
if not line.strip():
|
||||
break
|
||||
names.append(line.split()[-1])
|
||||
if len(names) != len(set(names)):
|
||||
sys.exit(f'{dll}: duplicate exports')
|
||||
return set(names)
|
||||
|
||||
|
||||
def verify(dll, definition, source, objdump):
|
||||
found = exports(dll, objdump)
|
||||
expected = def_names(definition) | source_names(source)
|
||||
missing, extra = sorted(expected - found), sorted(found - expected)
|
||||
if missing or extra:
|
||||
sys.exit(f'{dll}: exports do not match {Path(definition).name}: missing {missing}, unexpected {extra}')
|
||||
print(f'{Path(dll).name}: {len(found)} exports match {Path(definition).name}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[1:2] == ['stamp'] and len(sys.argv) == 3:
|
||||
stamp(sys.argv[2])
|
||||
elif sys.argv[1:2] == ['verify'] and len(sys.argv) == 6:
|
||||
verify(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
|
||||
else:
|
||||
sys.exit(__doc__)
|
||||
@@ -0,0 +1,570 @@
|
||||
// Winlator Ludashi Native AMD FidelityFX API 2.0 (FSR 4.1.1) Bridge DLL
|
||||
// Works for BOTH Vulkan (amd_fidelityfx_vk.dll / amd_fidelityfx_upscaler_vk.dll)
|
||||
// AND DirectX 12 via vkd3d-proton interop (amd_fidelityfx_dx12.dll / amd_fidelityfx_upscaler_dx12.dll).
|
||||
//
|
||||
// Exposes AMD FSR 4.1.1 (and 3.1.4 compat) via ffxQuery(GET_VERSIONS) and forwards every
|
||||
// ffxDispatch(UPSCALE) zero-copy to libVkLayer_winlator_fsr4_npu.so on the Hexagon HTP v81 NPU.
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "wl_seam_client.h"
|
||||
#include "wl_vkd3d_interop.h"
|
||||
#include "wl_xess3_direct.h"
|
||||
|
||||
// ---- Official AMD FidelityFX API 2.0 ABI (verified from GPUOpen FidelityFX-SDK) ----
|
||||
typedef void *ffxContext;
|
||||
typedef uint32_t ffxReturnCode_t;
|
||||
typedef uint64_t ffxStructType_t;
|
||||
|
||||
enum {
|
||||
FFX_API_RETURN_OK = 0,
|
||||
FFX_API_RETURN_ERROR = 1,
|
||||
FFX_API_RETURN_ERROR_UNKNOWN_DESCTYPE = 2,
|
||||
FFX_API_RETURN_ERROR_RUNTIME_ERROR = 3,
|
||||
FFX_API_RETURN_NO_PROVIDER = 4,
|
||||
FFX_API_RETURN_ERROR_MEMORY = 5,
|
||||
FFX_API_RETURN_ERROR_PARAMETER = 6,
|
||||
};
|
||||
|
||||
typedef struct ffxApiHeader {
|
||||
ffxStructType_t type;
|
||||
struct ffxApiHeader *pNext;
|
||||
} ffxApiHeader;
|
||||
|
||||
typedef void *(*ffxAlloc)(void *pUserData, uint64_t size);
|
||||
typedef void (*ffxDealloc)(void *pUserData, void *pMem);
|
||||
typedef struct ffxAllocationCallbacks {
|
||||
void *pUserData;
|
||||
ffxAlloc alloc;
|
||||
ffxDealloc dealloc;
|
||||
} ffxAllocationCallbacks;
|
||||
|
||||
typedef void (*ffxApiMessage)(uint32_t type, const wchar_t *message);
|
||||
|
||||
typedef struct FfxApiDimensions2D { uint32_t width, height; } FfxApiDimensions2D;
|
||||
typedef struct FfxApiFloatCoords2D { float x, y; } FfxApiFloatCoords2D;
|
||||
|
||||
typedef struct FfxApiResourceDescription {
|
||||
uint32_t type;
|
||||
uint32_t format;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t depth;
|
||||
uint32_t mipCount;
|
||||
uint32_t flags;
|
||||
uint32_t usage;
|
||||
} FfxApiResourceDescription;
|
||||
|
||||
typedef struct FfxApiResource {
|
||||
void *resource;
|
||||
FfxApiResourceDescription description;
|
||||
uint32_t state;
|
||||
} FfxApiResource;
|
||||
|
||||
typedef struct FfxApiEffectMemoryUsage {
|
||||
uint64_t totalUsageInBytes;
|
||||
uint64_t aliasableUsageInBytes;
|
||||
} FfxApiEffectMemoryUsage;
|
||||
|
||||
#define FFX_API_QUERY_DESC_TYPE_GET_VERSIONS 4u
|
||||
#define FFX_API_DESC_TYPE_OVERRIDE_VERSION 5u
|
||||
#define FFX_API_QUERY_DESC_TYPE_GET_PROVIDER_VERSION 6u
|
||||
#define FFX_API_CONFIGURE_DESC_TYPE_GLOBALDEBUG 7u
|
||||
|
||||
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_DX12 0x00000002u
|
||||
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_VK_DEPRECATED 0x00000003u
|
||||
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_VK 0x01000003u
|
||||
|
||||
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE 0x00010000u
|
||||
#define FFX_API_DISPATCH_DESC_TYPE_UPSCALE 0x00010001u
|
||||
#define FFX_API_QUERY_DESC_TYPE_UPSCALE_GETUPSCALERATIO 0x00010002u
|
||||
#define FFX_API_QUERY_DESC_TYPE_UPSCALE_GETRENDERRES 0x00010003u
|
||||
#define FFX_API_QUERY_DESC_TYPE_UPSCALE_GETJITTERPHASECOUNT 0x00010004u
|
||||
#define FFX_API_QUERY_DESC_TYPE_UPSCALE_GETJITTEROFFSET 0x00010005u
|
||||
#define FFX_API_DISPATCH_DESC_TYPE_UPSCALE_GENREACTIVEMASK 0x00010006u
|
||||
#define FFX_API_CONFIGURE_DESC_TYPE_UPSCALE_KEYVALUE 0x00010007u
|
||||
#define FFX_API_QUERY_DESC_TYPE_UPSCALE_GPU_MEMORY_USAGE 0x00010008u
|
||||
#define FFX_API_QUERY_DESC_TYPE_UPSCALE_GPU_MEMORY_USAGE_V2 0x00010009u
|
||||
#define FFX_API_QUERY_DESC_TYPE_UPSCALE_GET_RESOURCE_REQS 0x0001000au
|
||||
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE_VERSION 0x0001000bu
|
||||
|
||||
enum {
|
||||
FFX_UPSCALE_QUALITY_MODE_NATIVEAA = 0,
|
||||
FFX_UPSCALE_QUALITY_MODE_QUALITY = 1,
|
||||
FFX_UPSCALE_QUALITY_MODE_BALANCED = 2,
|
||||
FFX_UPSCALE_QUALITY_MODE_PERFORMANCE = 3,
|
||||
FFX_UPSCALE_QUALITY_MODE_ULTRA_PERFORMANCE = 4,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
uint64_t createDescType;
|
||||
void *device;
|
||||
uint64_t *outputCount;
|
||||
uint64_t *versionIds;
|
||||
const char **versionNames;
|
||||
} ffxQueryDescGetVersions;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
uint64_t versionId;
|
||||
const char *versionName;
|
||||
} ffxQueryGetProviderVersion;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
uint32_t flags;
|
||||
FfxApiDimensions2D maxRenderSize;
|
||||
FfxApiDimensions2D maxUpscaleSize;
|
||||
ffxApiMessage fpMessage;
|
||||
} ffxCreateContextDescUpscale;
|
||||
|
||||
typedef struct {
|
||||
VkDevice vkDevice;
|
||||
VkPhysicalDevice vkPhysicalDevice;
|
||||
PFN_wlVkGetDeviceProcAddr vkDeviceProcAddr;
|
||||
} FfxVkDeviceContext;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
FfxVkDeviceContext deviceContext;
|
||||
} ffxCreateBackendVKDesc;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
void *device; // ID3D12Device*
|
||||
} ffxCreateBackendDX12Desc;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
void *commandList;
|
||||
FfxApiResource color;
|
||||
FfxApiResource depth;
|
||||
FfxApiResource motionVectors;
|
||||
FfxApiResource exposure;
|
||||
FfxApiResource reactive;
|
||||
FfxApiResource transparencyAndComposition;
|
||||
FfxApiResource output;
|
||||
FfxApiFloatCoords2D jitterOffset;
|
||||
FfxApiFloatCoords2D motionVectorScale;
|
||||
FfxApiDimensions2D renderSize;
|
||||
FfxApiDimensions2D upscaleSize;
|
||||
bool enableSharpening;
|
||||
float sharpness;
|
||||
float frameTimeDelta;
|
||||
float preExposure;
|
||||
bool reset;
|
||||
float cameraNear;
|
||||
float cameraFar;
|
||||
float cameraFovAngleVertical;
|
||||
float viewSpaceToMetersFactor;
|
||||
uint32_t flags;
|
||||
} ffxDispatchDescUpscale;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
uint32_t qualityMode;
|
||||
float *pOutUpscaleRatio;
|
||||
} ffxQueryDescUpscaleGetUpscaleRatio;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
uint32_t displayWidth, displayHeight, qualityMode;
|
||||
uint32_t *pOutRenderWidth, *pOutRenderHeight;
|
||||
} ffxQueryDescUpscaleGetRenderRes;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
uint32_t renderWidth, displayWidth;
|
||||
int32_t *pOutPhaseCount;
|
||||
} ffxQueryDescUpscaleGetJitterPhaseCount;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
int32_t index, phaseCount;
|
||||
float *pOutX, *pOutY;
|
||||
} ffxQueryDescUpscaleGetJitterOffset;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
FfxApiEffectMemoryUsage *gpuMemoryUsageUpscaler;
|
||||
} ffxQueryDescUpscaleGetGPUMem;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
void *device;
|
||||
FfxApiDimensions2D maxRenderSize, maxUpscaleSize;
|
||||
uint32_t flags;
|
||||
FfxApiEffectMemoryUsage *gpuMemoryUsageUpscaler;
|
||||
} ffxQueryDescUpscaleGetGPUMemV2;
|
||||
|
||||
typedef struct {
|
||||
ffxApiHeader header;
|
||||
uint64_t required_resources;
|
||||
uint64_t optional_resources;
|
||||
} ffxQueryDescUpscaleGetResourceReqs;
|
||||
|
||||
// ---- Version IDs exposed to games ----
|
||||
// Bit packing matches AMD FidelityFX SDK 2.0 (major<<22 | minor<<12 | patch) + provider tag
|
||||
#define WL_FSR4_VER_ID_4_1_1 ((4ULL << 22) | (1ULL << 12) | 1ULL)
|
||||
#define WL_FSR4_VER_ID_3_1_4 ((3ULL << 22) | (1ULL << 12) | 4ULL)
|
||||
|
||||
static const uint64_t k_ver_ids[2] = { WL_FSR4_VER_ID_4_1_1, WL_FSR4_VER_ID_3_1_4 };
|
||||
static const char *k_ver_names[2] = { "4.1.1", "3.1.4" };
|
||||
|
||||
typedef struct WlFfxUpscaleCtx {
|
||||
int is_dx12;
|
||||
int needs_reset;
|
||||
uint32_t create_flags;
|
||||
uint32_t max_rw, max_rh, max_ow, max_oh;
|
||||
void *d3d12_dev;
|
||||
WlSeamClient seam;
|
||||
WlXess3State xess3;
|
||||
WlID3D12DXVKInteropDevice1 *dx12_interop;
|
||||
} WlFfxUpscaleCtx;
|
||||
|
||||
static volatile uint32_t g_last_ffx_quality = WLFSR4_QUALITY_AUTO;
|
||||
|
||||
static uint32_t ffx_mode_to_wl_quality(uint32_t mode) {
|
||||
switch (mode) {
|
||||
case FFX_UPSCALE_QUALITY_MODE_NATIVEAA: return WLFSR4_QUALITY_NATIVE_AA;
|
||||
case FFX_UPSCALE_QUALITY_MODE_QUALITY: return WLFSR4_QUALITY_QUALITY;
|
||||
case FFX_UPSCALE_QUALITY_MODE_BALANCED: return WLFSR4_QUALITY_BALANCED;
|
||||
case FFX_UPSCALE_QUALITY_MODE_PERFORMANCE: return WLFSR4_QUALITY_PERF;
|
||||
case FFX_UPSCALE_QUALITY_MODE_ULTRA_PERFORMANCE: return WLFSR4_QUALITY_ULTRA_PERF;
|
||||
default: return WLFSR4_QUALITY_AUTO;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t ffx_infer_quality(uint32_t rw, uint32_t ow) {
|
||||
if (rw == 0u || ow == 0u) return WLFSR4_QUALITY_AUTO;
|
||||
float r = (float)ow / (float)rw;
|
||||
if (r < 1.15f) return WLFSR4_QUALITY_NATIVE_AA;
|
||||
if (r < 1.38f) return WLFSR4_QUALITY_ULTRA_QUAL;
|
||||
if (r < 1.60f) return WLFSR4_QUALITY_QUALITY;
|
||||
if (r < 1.85f) return WLFSR4_QUALITY_BALANCED;
|
||||
if (r < 2.45f) return WLFSR4_QUALITY_PERF;
|
||||
return WLFSR4_QUALITY_ULTRA_PERF;
|
||||
}
|
||||
|
||||
static float halton(int32_t index, int32_t base) {
|
||||
float f = 1.0f, r = 0.0f;
|
||||
int32_t cur = index;
|
||||
while (cur > 0) {
|
||||
f /= (float)base;
|
||||
r += f * (float)(cur % base);
|
||||
cur /= base;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static uint32_t ffx_fmt_to_vk(uint32_t f) {
|
||||
switch (f) {
|
||||
case 3: return 109; /* R32G32B32A32_SFLOAT */
|
||||
case 4: return 97; /* R16G16B16A16_SFLOAT */
|
||||
case 6: return 103; /* R32G32_SFLOAT */
|
||||
case 10: return 37; /* R8G8B8A8_UNORM */
|
||||
case 12: return 43; /* R8G8B8A8_SRGB */
|
||||
case 14: return 44; /* B8G8R8A8_UNORM */
|
||||
case 15: return 50; /* B8G8R8A8_SRGB */
|
||||
case 16: return 122; /* B10G11R11_UFLOAT_PACK32 */
|
||||
case 17: return 64; /* A2B10G10R10_UNORM_PACK32 */
|
||||
case 18: return 83; /* R16G16_SFLOAT */
|
||||
case 28: return 100; /* R32_SFLOAT */
|
||||
default: return 0; /* let Vulkan layer look up from vkCreateImage table */
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t ffx_state_to_vk_layout(uint32_t st, int is_depth) {
|
||||
if (st & (1u << 1)) return 1; /* UNORDERED_ACCESS -> GENERAL */
|
||||
if (st & ((1u << 2) | (1u << 3))) return is_depth ? 4 : 5; /* DEPTH_STENCIL_READ_ONLY / SHADER_READ_ONLY */
|
||||
if (st & (1u << 4)) return 6; /* TRANSFER_SRC */
|
||||
if (st & (1u << 5)) return 7; /* TRANSFER_DST */
|
||||
if (st & (1u << 8)) return 2; /* COLOR_ATTACHMENT_OPTIMAL */
|
||||
if (st & (1u << 9)) return 3; /* DEPTH_STENCIL_ATTACHMENT_OPTIMAL */
|
||||
return 1; /* GENERAL */
|
||||
}
|
||||
|
||||
static float quality_ratio(uint32_t mode) {
|
||||
switch (mode) {
|
||||
case FFX_UPSCALE_QUALITY_MODE_NATIVEAA: return 1.0f;
|
||||
case FFX_UPSCALE_QUALITY_MODE_QUALITY: return 1.5f;
|
||||
case FFX_UPSCALE_QUALITY_MODE_BALANCED: return 1.7f;
|
||||
case FFX_UPSCALE_QUALITY_MODE_PERFORMANCE: return 2.0f;
|
||||
case FFX_UPSCALE_QUALITY_MODE_ULTRA_PERFORMANCE: return 3.0f;
|
||||
default: return 2.0f;
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(dllexport) ffxReturnCode_t ffxCreateContext(ffxContext *context, ffxApiHeader *desc, const ffxAllocationCallbacks *memCb) {
|
||||
(void)memCb;
|
||||
if (!context || !desc) return FFX_API_RETURN_ERROR_PARAMETER;
|
||||
|
||||
const ffxCreateContextDescUpscale *up = NULL;
|
||||
const ffxCreateBackendVKDesc *bvk = NULL;
|
||||
const ffxCreateBackendDX12Desc *bdx = NULL;
|
||||
|
||||
for (const ffxApiHeader *h = desc; h; h = h->pNext) {
|
||||
if (h->type == FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE) up = (const ffxCreateContextDescUpscale *)h;
|
||||
else if (h->type == FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_VK ||
|
||||
h->type == FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_VK_DEPRECATED) bvk = (const ffxCreateBackendVKDesc *)h;
|
||||
else if (h->type == FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_DX12) bdx = (const ffxCreateBackendDX12Desc *)h;
|
||||
}
|
||||
if (!up) return FFX_API_RETURN_NO_PROVIDER;
|
||||
|
||||
WlFfxUpscaleCtx *ctx = (WlFfxUpscaleCtx *)calloc(1, sizeof *ctx);
|
||||
if (!ctx) return FFX_API_RETURN_ERROR_MEMORY;
|
||||
|
||||
ctx->create_flags = up->flags;
|
||||
ctx->needs_reset = 1;
|
||||
ctx->max_rw = up->maxRenderSize.width;
|
||||
ctx->max_rh = up->maxRenderSize.height;
|
||||
ctx->max_ow = up->maxUpscaleSize.width;
|
||||
ctx->max_oh = up->maxUpscaleSize.height;
|
||||
|
||||
if (bvk && bvk->deviceContext.vkDevice) {
|
||||
ctx->is_dx12 = 0;
|
||||
wl_seam_init(&ctx->seam, NULL, bvk->deviceContext.vkPhysicalDevice,
|
||||
bvk->deviceContext.vkDevice, bvk->deviceContext.vkDeviceProcAddr);
|
||||
} else if (bdx && bdx->device) {
|
||||
ctx->is_dx12 = 1;
|
||||
ctx->d3d12_dev = bdx->device;
|
||||
ctx->dx12_interop = wl_query_vkd3d_interop(bdx->device);
|
||||
if (ctx->dx12_interop) {
|
||||
void *vk_inst = NULL, *vk_phys = NULL, *vk_dev = NULL;
|
||||
if (ctx->dx12_interop->lpVtbl->GetVulkanHandles(ctx->dx12_interop, &vk_inst, &vk_phys, &vk_dev) == S_OK && vk_dev) {
|
||||
wl_seam_init(&ctx->seam, vk_inst, vk_phys, vk_dev, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*context = ctx;
|
||||
return FFX_API_RETURN_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) ffxReturnCode_t ffxDestroyContext(ffxContext *context, const ffxAllocationCallbacks *memCb) {
|
||||
(void)memCb;
|
||||
if (!context || !*context) return FFX_API_RETURN_OK;
|
||||
WlFfxUpscaleCtx *ctx = (WlFfxUpscaleCtx *)(*context);
|
||||
wl_xess3_destroy(&ctx->xess3);
|
||||
wl_seam_destroy(&ctx->seam);
|
||||
if (ctx->dx12_interop) {
|
||||
ctx->dx12_interop->lpVtbl->Release(ctx->dx12_interop);
|
||||
ctx->dx12_interop = NULL;
|
||||
}
|
||||
free(ctx);
|
||||
*context = NULL;
|
||||
return FFX_API_RETURN_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) ffxReturnCode_t ffxConfigure(ffxContext *context, const ffxApiHeader *desc) {
|
||||
(void)context; (void)desc;
|
||||
return FFX_API_RETURN_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) ffxReturnCode_t ffxQuery(ffxContext *context, ffxApiHeader *desc) {
|
||||
(void)context;
|
||||
if (!desc) return FFX_API_RETURN_ERROR_PARAMETER;
|
||||
|
||||
for (ffxApiHeader *h = desc; h; h = h->pNext) {
|
||||
switch (h->type) {
|
||||
case FFX_API_QUERY_DESC_TYPE_GET_VERSIONS: {
|
||||
ffxQueryDescGetVersions *q = (ffxQueryDescGetVersions *)h;
|
||||
if (!q->outputCount) return FFX_API_RETURN_ERROR_PARAMETER;
|
||||
uint64_t cap = *q->outputCount;
|
||||
if (cap == 0 || (!q->versionIds && !q->versionNames)) {
|
||||
*q->outputCount = 2;
|
||||
break;
|
||||
}
|
||||
uint64_t n = cap < 2 ? cap : 2;
|
||||
for (uint64_t i = 0; i < n; i++) {
|
||||
if (q->versionIds) q->versionIds[i] = k_ver_ids[i];
|
||||
if (q->versionNames) q->versionNames[i] = k_ver_names[i];
|
||||
}
|
||||
*q->outputCount = n;
|
||||
break;
|
||||
}
|
||||
case FFX_API_QUERY_DESC_TYPE_GET_PROVIDER_VERSION: {
|
||||
ffxQueryGetProviderVersion *q = (ffxQueryGetProviderVersion *)h;
|
||||
q->versionId = WL_FSR4_VER_ID_4_1_1;
|
||||
q->versionName = "4.1.1";
|
||||
break;
|
||||
}
|
||||
case FFX_API_QUERY_DESC_TYPE_UPSCALE_GETUPSCALERATIO: {
|
||||
ffxQueryDescUpscaleGetUpscaleRatio *q = (ffxQueryDescUpscaleGetUpscaleRatio *)h;
|
||||
g_last_ffx_quality = ffx_mode_to_wl_quality(q->qualityMode);
|
||||
if (q->pOutUpscaleRatio) *q->pOutUpscaleRatio = quality_ratio(q->qualityMode);
|
||||
break;
|
||||
}
|
||||
case FFX_API_QUERY_DESC_TYPE_UPSCALE_GETRENDERRES: {
|
||||
ffxQueryDescUpscaleGetRenderRes *q = (ffxQueryDescUpscaleGetRenderRes *)h;
|
||||
g_last_ffx_quality = ffx_mode_to_wl_quality(q->qualityMode);
|
||||
float r = quality_ratio(q->qualityMode);
|
||||
if (q->pOutRenderWidth) *q->pOutRenderWidth = (uint32_t)((float)q->displayWidth / r);
|
||||
if (q->pOutRenderHeight) *q->pOutRenderHeight = (uint32_t)((float)q->displayHeight / r);
|
||||
break;
|
||||
}
|
||||
case FFX_API_QUERY_DESC_TYPE_UPSCALE_GETJITTERPHASECOUNT: {
|
||||
ffxQueryDescUpscaleGetJitterPhaseCount *q = (ffxQueryDescUpscaleGetJitterPhaseCount *)h;
|
||||
if (q->pOutPhaseCount && q->renderWidth > 0) {
|
||||
float ratio = (float)q->displayWidth / (float)q->renderWidth;
|
||||
int32_t pc = (int32_t)ceilf(8.0f * ratio * ratio);
|
||||
if (pc < 8) pc = 8;
|
||||
*q->pOutPhaseCount = pc;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FFX_API_QUERY_DESC_TYPE_UPSCALE_GETJITTEROFFSET: {
|
||||
ffxQueryDescUpscaleGetJitterOffset *q = (ffxQueryDescUpscaleGetJitterOffset *)h;
|
||||
int32_t pc = q->phaseCount > 0 ? q->phaseCount : 8;
|
||||
int32_t idx = (q->index % pc) + 1;
|
||||
if (idx <= 0) idx += pc;
|
||||
if (q->pOutX) *q->pOutX = halton(idx, 2) - 0.5f;
|
||||
if (q->pOutY) *q->pOutY = halton(idx, 3) - 0.5f;
|
||||
break;
|
||||
}
|
||||
case FFX_API_QUERY_DESC_TYPE_UPSCALE_GPU_MEMORY_USAGE: {
|
||||
ffxQueryDescUpscaleGetGPUMem *q = (ffxQueryDescUpscaleGetGPUMem *)h;
|
||||
if (q->gpuMemoryUsageUpscaler) {
|
||||
q->gpuMemoryUsageUpscaler->totalUsageInBytes = 64ULL * 1024ULL * 1024ULL;
|
||||
q->gpuMemoryUsageUpscaler->aliasableUsageInBytes = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FFX_API_QUERY_DESC_TYPE_UPSCALE_GPU_MEMORY_USAGE_V2: {
|
||||
ffxQueryDescUpscaleGetGPUMemV2 *q = (ffxQueryDescUpscaleGetGPUMemV2 *)h;
|
||||
if (q->gpuMemoryUsageUpscaler) {
|
||||
q->gpuMemoryUsageUpscaler->totalUsageInBytes = 64ULL * 1024ULL * 1024ULL;
|
||||
q->gpuMemoryUsageUpscaler->aliasableUsageInBytes = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FFX_API_QUERY_DESC_TYPE_UPSCALE_GET_RESOURCE_REQS: {
|
||||
ffxQueryDescUpscaleGetResourceReqs *q = (ffxQueryDescUpscaleGetResourceReqs *)h;
|
||||
q->required_resources = (1ULL << 0) | (1ULL << 1) | (1ULL << 2); /* COLOR | DEPTH | MV */
|
||||
q->optional_resources = (1ULL << 3) | (1ULL << 4) | (1ULL << 5);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return FFX_API_RETURN_OK;
|
||||
}
|
||||
|
||||
static void fill_vk_img_ref(WlFsr4ImageRef *dst, const FfxApiResource *src, int is_depth) {
|
||||
memset(dst, 0, sizeof *dst);
|
||||
if (!src || !src->resource) return;
|
||||
dst->vk_image = (uint64_t)(uintptr_t)src->resource;
|
||||
dst->vk_format = ffx_fmt_to_vk(src->description.format);
|
||||
dst->vk_layout = ffx_state_to_vk_layout(src->state, is_depth);
|
||||
dst->width = src->description.width;
|
||||
dst->height = src->description.height;
|
||||
dst->aspect = is_depth ? 2u : 1u;
|
||||
}
|
||||
|
||||
static void fill_dx12_img_ref(WlID3D12DXVKInteropDevice1 *interop, WlFsr4ImageRef *dst, const FfxApiResource *src, int is_depth) {
|
||||
memset(dst, 0, sizeof *dst);
|
||||
if (!interop || !src || !src->resource) return;
|
||||
UINT64 vk_img = 0, off = 0;
|
||||
UINT32 vk_fmt = 0;
|
||||
if (interop->lpVtbl->GetVulkanResourceInfo1(interop, src->resource, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
||||
dst->vk_image = vk_img;
|
||||
dst->vk_format = vk_fmt ? vk_fmt : ffx_fmt_to_vk(src->description.format);
|
||||
dst->vk_layout = ffx_state_to_vk_layout(src->state, is_depth);
|
||||
dst->width = src->description.width;
|
||||
dst->height = src->description.height;
|
||||
dst->aspect = is_depth ? 2u : 1u;
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(dllexport) ffxReturnCode_t ffxDispatch(ffxContext *context, const ffxApiHeader *desc) {
|
||||
if (!context || !*context || !desc) return FFX_API_RETURN_ERROR_PARAMETER;
|
||||
WlFfxUpscaleCtx *ctx = (WlFfxUpscaleCtx *)(*context);
|
||||
|
||||
for (const ffxApiHeader *h = desc; h; h = h->pNext) {
|
||||
if (h->type != FFX_API_DISPATCH_DESC_TYPE_UPSCALE) continue;
|
||||
const ffxDispatchDescUpscale *d = (const ffxDispatchDescUpscale *)h;
|
||||
if (!d->commandList || !ctx->seam.ready) return FFX_API_RETURN_ERROR_RUNTIME_ERROR;
|
||||
|
||||
WlFsr4FrameDesc f;
|
||||
memset(&f, 0, sizeof f);
|
||||
f.render_w = d->renderSize.width ? d->renderSize.width : ctx->max_rw;
|
||||
f.render_h = d->renderSize.height ? d->renderSize.height : ctx->max_rh;
|
||||
f.output_w = d->upscaleSize.width ? d->upscaleSize.width : ctx->max_ow;
|
||||
f.output_h = d->upscaleSize.height ? d->upscaleSize.height : ctx->max_oh;
|
||||
f.jitter_x = d->jitterOffset.x;
|
||||
f.jitter_y = d->jitterOffset.y;
|
||||
f.mv_scale_x = d->motionVectorScale.x != 0.f ? d->motionVectorScale.x : 1.f;
|
||||
f.mv_scale_y = d->motionVectorScale.y != 0.f ? d->motionVectorScale.y : 1.f;
|
||||
f.pre_exposure = d->preExposure > 0.f ? d->preExposure : 1.f;
|
||||
f.sharpness = d->sharpness;
|
||||
f.frame_time_ms = d->frameTimeDelta;
|
||||
f.camera_near = d->cameraNear;
|
||||
f.camera_far = d->cameraFar;
|
||||
f.camera_fov_y = d->cameraFovAngleVertical;
|
||||
if (d->reset || ctx->needs_reset) {
|
||||
f.flags |= WLFSR4_FLAG_RESET;
|
||||
ctx->needs_reset = 0;
|
||||
}
|
||||
if (ctx->create_flags & (1u << 0)) f.flags |= WLFSR4_FLAG_HDR;
|
||||
if (ctx->create_flags & (1u << 1)) f.flags |= WLFSR4_FLAG_DISPLAY_RES_MV;
|
||||
if (ctx->create_flags & (1u << 2)) f.flags |= WLFSR4_FLAG_MV_JITTERED;
|
||||
if (ctx->create_flags & (1u << 3)) f.flags |= WLFSR4_FLAG_DEPTH_INVERTED;
|
||||
if (ctx->create_flags & (1u << 5)) f.flags |= WLFSR4_FLAG_AUTO_EXPOSURE;
|
||||
if (d->enableSharpening) f.flags |= WLFSR4_FLAG_SHARPEN;
|
||||
f.quality_mode = (g_last_ffx_quality != WLFSR4_QUALITY_AUTO)
|
||||
? g_last_ffx_quality
|
||||
: ffx_infer_quality(f.render_w, f.output_w);
|
||||
if (f.quality_mode == WLFSR4_QUALITY_ULTRA_PERF) f.preset_hint = WLFSR4_PRESET_ULTRAPERF;
|
||||
|
||||
if (!ctx->is_dx12) {
|
||||
f.api_source = WLFSR4_API_FFX_VK;
|
||||
fill_vk_img_ref(&f.color, &d->color, 0);
|
||||
fill_vk_img_ref(&f.depth, &d->depth, 1);
|
||||
fill_vk_img_ref(&f.motion, &d->motionVectors, 0);
|
||||
fill_vk_img_ref(&f.output, &d->output, 0);
|
||||
if (!wl_seam_dispatch_or_blit(&ctx->seam, (VkCommandBuffer)d->commandList, &f))
|
||||
return FFX_API_RETURN_ERROR_RUNTIME_ERROR;
|
||||
} else if (ctx->dx12_interop) {
|
||||
f.api_source = WLFSR4_API_FFX_DX12;
|
||||
fill_dx12_img_ref(ctx->dx12_interop, &f.color, &d->color, 0);
|
||||
fill_dx12_img_ref(ctx->dx12_interop, &f.depth, &d->depth, 1);
|
||||
fill_dx12_img_ref(ctx->dx12_interop, &f.motion, &d->motionVectors, 0);
|
||||
fill_dx12_img_ref(ctx->dx12_interop, &f.output, &d->output, 0);
|
||||
|
||||
int live_en = 1;
|
||||
int live_backend = wl_seam_live_backend(&ctx->seam, &live_en);
|
||||
if (live_en && live_backend == WL_FSR_BACKEND_XESS3_GPU && ctx->d3d12_dev) {
|
||||
if (wl_xess3_eval_d3d12(&ctx->xess3, &ctx->seam, ctx->dx12_interop,
|
||||
ctx->d3d12_dev, d->commandList, &f,
|
||||
d->color.resource, d->depth.resource,
|
||||
d->motionVectors.resource, d->output.resource)) {
|
||||
continue;
|
||||
}
|
||||
wl_xess3_tag_fallback(&ctx->xess3, &f);
|
||||
} else {
|
||||
wl_xess3_on_inactive(&ctx->xess3);
|
||||
}
|
||||
|
||||
void *vk_cb = NULL;
|
||||
int ok = 0;
|
||||
if (ctx->dx12_interop->lpVtbl->BeginVkCommandBufferInterop(ctx->dx12_interop, d->commandList, &vk_cb) == S_OK && vk_cb) {
|
||||
ok = wl_seam_dispatch_or_blit(&ctx->seam, (VkCommandBuffer)vk_cb, &f);
|
||||
ctx->dx12_interop->lpVtbl->EndVkCommandBufferInterop(ctx->dx12_interop, d->commandList);
|
||||
}
|
||||
if (!ok) return FFX_API_RETURN_ERROR_RUNTIME_ERROR;
|
||||
}
|
||||
}
|
||||
return FFX_API_RETURN_OK;
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
|
||||
(void)hinst; (void)reason; (void)reserved;
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
EXPORTS
|
||||
ffxCreateContext
|
||||
ffxDestroyContext
|
||||
ffxConfigure
|
||||
ffxQuery
|
||||
ffxDispatch
|
||||
@@ -0,0 +1,886 @@
|
||||
// Winlator Ludashi AMD FSR 3 (ffx_fsr3upscaler_x64.dll) & External FSR 2 (ffx_fsr2_api_x64.dll)
|
||||
// -> AMD FSR 4 INT8 Hexagon HTP NPU Bridge
|
||||
//
|
||||
// Supports BOTH DirectX 12 (via vkd3d-proton zero-copy interop) and Vulkan,
|
||||
// auto-detecting FSR 3.0 vs FSR 3.1 and FSR 2.0 vs FSR 2.1/2.2 struct layouts.
|
||||
// Requires ZERO GPU spoofing — runs cleanly on Adreno/Turnip in No-GPU-Spoof mode.
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "wl_seam_client.h"
|
||||
#include "wl_vkd3d_interop.h"
|
||||
#include "wl_xess3_direct.h"
|
||||
|
||||
// ---- Common FFX error & basic types ----
|
||||
typedef int32_t FfxErrorCode;
|
||||
#define FFX_OK 0
|
||||
#define FFX_ERROR_INVALID_POINTER (-2147483647 - 1)
|
||||
#define FFX_ERROR_INVALID_ALIGNMENT (-2147483647)
|
||||
#define FFX_ERROR_INVALID_SIZE (-2147483646)
|
||||
#define FFX_ERROR_EOF (-2147483645)
|
||||
#define FFX_ERROR_INVALID_PATH (-2147483644)
|
||||
#define FFX_ERROR_EOF_EX (-2147483643)
|
||||
#define FFX_ERROR_MALFORMED_DATA (-2147483642)
|
||||
#define FFX_ERROR_OUT_OF_MEMORY (-2147483641)
|
||||
#define FFX_ERROR_INCOMPLETE_INTERFACE (-2147483640)
|
||||
#define FFX_ERROR_INVALID_ENUM (-2147483639)
|
||||
#define FFX_ERROR_INVALID_ARGUMENT (-2147483638)
|
||||
#define FFX_ERROR_OUT_OF_RANGE (-2147483637)
|
||||
#define FFX_ERROR_NULL_DEVICE (-2147483636)
|
||||
|
||||
typedef struct { uint32_t width, height; } WlFfxDim2D;
|
||||
typedef struct { float x, y; } WlFfxFloat2D;
|
||||
|
||||
// ---- FSR 3 ABI structs (verified from FidelityFX SDK 1.0/1.1 fsr3 & fsr31) ----
|
||||
typedef struct {
|
||||
uint32_t type;
|
||||
uint32_t format;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t depth;
|
||||
uint32_t mipCount;
|
||||
uint32_t flags;
|
||||
uint32_t usage;
|
||||
} WlFfxResDesc3;
|
||||
|
||||
typedef struct {
|
||||
void *resource;
|
||||
WlFfxResDesc3 description;
|
||||
uint32_t state;
|
||||
uint16_t name[64];
|
||||
} WlFfxResource3;
|
||||
|
||||
typedef struct {
|
||||
uint32_t heapType;
|
||||
WlFfxResDesc3 resourceDescription;
|
||||
uint32_t initialState;
|
||||
uint32_t initDataSize;
|
||||
void *initData;
|
||||
const uint16_t *name;
|
||||
uint32_t id;
|
||||
} WlFfxCreateResDesc3;
|
||||
|
||||
typedef struct {
|
||||
WlFfxCreateResDesc3 reconstructedPrevNearestDepth;
|
||||
WlFfxCreateResDesc3 dilatedDepth;
|
||||
WlFfxCreateResDesc3 dilatedMotionVectors;
|
||||
} WlFfxFsr3SharedResDescs;
|
||||
|
||||
typedef struct {
|
||||
void *callbacks[16];
|
||||
void *scratchBuffer;
|
||||
size_t scratchBufferSize;
|
||||
void *device;
|
||||
} WlFfxInterface3;
|
||||
|
||||
typedef struct {
|
||||
uint32_t flags;
|
||||
WlFfxDim2D maxRenderSize;
|
||||
WlFfxDim2D displaySize;
|
||||
WlFfxInterface3 backendInterface;
|
||||
void *fpMessage;
|
||||
} WlFfxFsr30CtxDesc;
|
||||
|
||||
typedef struct {
|
||||
uint32_t flags;
|
||||
WlFfxDim2D maxRenderSize;
|
||||
WlFfxDim2D maxUpscaleSize;
|
||||
void *fpMessage;
|
||||
WlFfxInterface3 backendInterface;
|
||||
} WlFfxFsr31CtxDesc;
|
||||
|
||||
typedef struct {
|
||||
void *commandList;
|
||||
WlFfxResource3 color;
|
||||
WlFfxResource3 depth;
|
||||
WlFfxResource3 motionVectors;
|
||||
WlFfxResource3 exposure;
|
||||
WlFfxResource3 reactive;
|
||||
WlFfxResource3 transparencyAndComposition;
|
||||
WlFfxResource3 dilatedDepth;
|
||||
WlFfxResource3 dilatedMotionVectors;
|
||||
WlFfxResource3 reconstructedPrevNearestDepth;
|
||||
WlFfxResource3 output;
|
||||
WlFfxFloat2D jitterOffset;
|
||||
WlFfxFloat2D motionVectorScale;
|
||||
WlFfxDim2D renderSize;
|
||||
bool enableSharpening;
|
||||
float sharpness;
|
||||
float frameTimeDelta;
|
||||
float preExposure;
|
||||
bool reset;
|
||||
float cameraNear;
|
||||
float cameraFar;
|
||||
float cameraFovAngleVertical;
|
||||
float viewSpaceToMetersFactor;
|
||||
} WlFfxFsr30DispatchDesc;
|
||||
|
||||
typedef struct {
|
||||
void *commandList;
|
||||
WlFfxResource3 color;
|
||||
WlFfxResource3 depth;
|
||||
WlFfxResource3 motionVectors;
|
||||
WlFfxResource3 exposure;
|
||||
WlFfxResource3 reactive;
|
||||
WlFfxResource3 transparencyAndComposition;
|
||||
WlFfxResource3 dilatedDepth;
|
||||
WlFfxResource3 dilatedMotionVectors;
|
||||
WlFfxResource3 reconstructedPrevNearestDepth;
|
||||
WlFfxResource3 output;
|
||||
WlFfxFloat2D jitterOffset;
|
||||
WlFfxFloat2D motionVectorScale;
|
||||
WlFfxDim2D renderSize;
|
||||
WlFfxDim2D upscaleSize;
|
||||
bool enableSharpening;
|
||||
float sharpness;
|
||||
float frameTimeDelta;
|
||||
float preExposure;
|
||||
bool reset;
|
||||
float cameraNear;
|
||||
float cameraFar;
|
||||
float cameraFovAngleVertical;
|
||||
float viewSpaceToMetersFactor;
|
||||
uint32_t flags;
|
||||
} WlFfxFsr31DispatchDesc;
|
||||
|
||||
// ---- FSR 2 ABI structs (verified from FidelityFX FSR 2.0 / 2.1.2 / 2.2.1) ----
|
||||
typedef struct {
|
||||
uint32_t type;
|
||||
uint32_t format;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t depth;
|
||||
uint32_t mipCount;
|
||||
uint32_t flags;
|
||||
} WlFfxResDesc2;
|
||||
|
||||
typedef struct {
|
||||
void *resource;
|
||||
uint16_t name[64];
|
||||
WlFfxResDesc2 description;
|
||||
uint32_t state;
|
||||
bool isDepth;
|
||||
uint64_t descriptorData;
|
||||
} WlFfxResource21;
|
||||
|
||||
typedef struct {
|
||||
void *resource;
|
||||
WlFfxResDesc2 description;
|
||||
uint32_t state;
|
||||
bool isDepth;
|
||||
uint64_t descriptorData;
|
||||
} WlFfxResource20;
|
||||
|
||||
typedef struct {
|
||||
void *callbacks[12];
|
||||
void *scratchBuffer;
|
||||
size_t scratchBufferSize;
|
||||
} WlFfxInterface2;
|
||||
|
||||
typedef struct {
|
||||
uint32_t flags;
|
||||
WlFfxDim2D maxRenderSize;
|
||||
WlFfxDim2D displaySize;
|
||||
WlFfxInterface2 callbacks;
|
||||
void *device;
|
||||
} WlFfxFsr2CtxDesc;
|
||||
|
||||
typedef struct {
|
||||
void *commandList;
|
||||
WlFfxResource21 color;
|
||||
WlFfxResource21 depth;
|
||||
WlFfxResource21 motionVectors;
|
||||
WlFfxResource21 exposure;
|
||||
WlFfxResource21 reactive;
|
||||
WlFfxResource21 transparencyAndComposition;
|
||||
WlFfxResource21 output;
|
||||
WlFfxFloat2D jitterOffset;
|
||||
WlFfxFloat2D motionVectorScale;
|
||||
WlFfxDim2D renderSize;
|
||||
bool enableSharpening;
|
||||
float sharpness;
|
||||
float frameTimeDelta;
|
||||
float preExposure;
|
||||
bool reset;
|
||||
float cameraNear;
|
||||
float cameraFar;
|
||||
float cameraFovAngleVertical;
|
||||
} WlFfxFsr21DispatchDesc;
|
||||
|
||||
typedef struct {
|
||||
void *commandList;
|
||||
WlFfxResource20 color;
|
||||
WlFfxResource20 depth;
|
||||
WlFfxResource20 motionVectors;
|
||||
WlFfxResource20 exposure;
|
||||
WlFfxResource20 reactive;
|
||||
WlFfxResource20 transparencyAndComposition;
|
||||
WlFfxResource20 output;
|
||||
WlFfxFloat2D jitterOffset;
|
||||
WlFfxFloat2D motionVectorScale;
|
||||
WlFfxDim2D renderSize;
|
||||
bool enableSharpening;
|
||||
float sharpness;
|
||||
float frameTimeDelta;
|
||||
float preExposure;
|
||||
bool reset;
|
||||
float cameraNear;
|
||||
float cameraFar;
|
||||
float cameraFovAngleVertical;
|
||||
} WlFfxFsr20DispatchDesc;
|
||||
|
||||
typedef struct {
|
||||
VkDevice vkDevice;
|
||||
VkPhysicalDevice vkPhysicalDevice;
|
||||
PFN_wlVkGetDeviceProcAddr vkDeviceProcAddr;
|
||||
} WlFfxVkDevCtx3;
|
||||
|
||||
// ---- Shared Helpers ----
|
||||
#define WL_FSR23_MAGIC 0x574C4632u /* "WLF2" */
|
||||
|
||||
typedef struct WlFsr23Ctx {
|
||||
uint32_t magic;
|
||||
int is_fsr3;
|
||||
int is_fsr31;
|
||||
int is_dx12;
|
||||
int needs_reset;
|
||||
uint32_t flags;
|
||||
uint32_t max_rw, max_rh;
|
||||
uint32_t disp_w, disp_h;
|
||||
void *d3d12_dev;
|
||||
WlSeamClient seam;
|
||||
WlXess3State xess3;
|
||||
WlID3D12DXVKInteropDevice1 *dx12_interop;
|
||||
} WlFsr23Ctx;
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t pad;
|
||||
WlFsr23Ctx *ctx;
|
||||
} WlFsrContextHeader;
|
||||
|
||||
static volatile uint32_t g_last_quality_mode = WLFSR4_QUALITY_AUTO;
|
||||
|
||||
static float fsr_halton(int32_t index, int32_t base) {
|
||||
float f = 1.0f, r = 0.0f;
|
||||
int32_t cur = index;
|
||||
while (cur > 0) {
|
||||
f /= (float)base;
|
||||
r += f * (float)(cur % base);
|
||||
cur /= base;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static float fsr_quality_ratio(uint32_t mode) {
|
||||
switch (mode) {
|
||||
case 0: return 1.0f; /* Native AA */
|
||||
case 1: return 1.5f; /* Quality */
|
||||
case 2: return 1.7f; /* Balanced */
|
||||
case 3: return 2.0f; /* Performance */
|
||||
case 4: return 3.0f; /* Ultra Performance */
|
||||
default: return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t fsr_mode_to_wl(uint32_t mode) {
|
||||
switch (mode) {
|
||||
case 0: return WLFSR4_QUALITY_NATIVE_AA;
|
||||
case 1: return WLFSR4_QUALITY_QUALITY;
|
||||
case 2: return WLFSR4_QUALITY_BALANCED;
|
||||
case 3: return WLFSR4_QUALITY_PERF;
|
||||
case 4: return WLFSR4_QUALITY_ULTRA_PERF;
|
||||
default: return WLFSR4_QUALITY_AUTO;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t fsr_infer_quality(uint32_t rw, uint32_t ow) {
|
||||
if (rw == 0u || ow == 0u) return WLFSR4_QUALITY_AUTO;
|
||||
float r = (float)ow / (float)rw;
|
||||
if (r < 1.15f) return WLFSR4_QUALITY_NATIVE_AA;
|
||||
if (r < 1.38f) return WLFSR4_QUALITY_ULTRA_QUAL;
|
||||
if (r < 1.60f) return WLFSR4_QUALITY_QUALITY;
|
||||
if (r < 1.85f) return WLFSR4_QUALITY_BALANCED;
|
||||
if (r < 2.45f) return WLFSR4_QUALITY_PERF;
|
||||
return WLFSR4_QUALITY_ULTRA_PERF;
|
||||
}
|
||||
|
||||
static uint32_t fsr_fmt_to_vk(uint32_t f) {
|
||||
switch (f) {
|
||||
case 3: return 109; /* R32G32B32A32_SFLOAT */
|
||||
case 4: return 97; /* R16G16B16A16_SFLOAT */
|
||||
case 5: return 103; /* R32G32_SFLOAT */
|
||||
case 8: return 64; /* A2B10G10R10_UNORM_PACK32 */
|
||||
case 10: return 37; /* R8G8B8A8_UNORM */
|
||||
case 12: return 43; /* R8G8B8A8_SRGB */
|
||||
case 13: return 122; /* B10G11R11_UFLOAT_PACK32 */
|
||||
case 14: return 83; /* R16G16_SFLOAT */
|
||||
case 24: return 100; /* R32_SFLOAT */
|
||||
default: return 0; /* layer resolves from vkCreateImage table */
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t fsr_state_to_vk_layout(uint32_t st, int is_depth) {
|
||||
if (st & (1u << 1)) return 1u; /* UNORDERED_ACCESS -> GENERAL */
|
||||
if (st & ((1u << 2) | (1u << 3))) return is_depth ? 4u : 5u; /* COMPUTE/PIXEL_READ */
|
||||
if (st & (1u << 4)) return 6u; /* COPY_SRC */
|
||||
if (st & (1u << 5)) return 7u; /* COPY_DEST */
|
||||
if (st & (1u << 8)) return 2u; /* RENDER_TARGET */
|
||||
return 1u;
|
||||
}
|
||||
|
||||
static uint32_t fsr_state_to_d3d12(uint32_t st) {
|
||||
if (st & (1u << 1)) return 0x8u; /* UNORDERED_ACCESS */
|
||||
if (st & (1u << 2)) return 0x40u; /* NON_PIXEL_SHADER_RESOURCE */
|
||||
if (st & (1u << 3)) return 0x80u; /* PIXEL_SHADER_RESOURCE */
|
||||
if (st & (1u << 4)) return 0x800u; /* COPY_SOURCE */
|
||||
if (st & (1u << 5)) return 0x400u; /* COPY_DEST */
|
||||
if (st & (1u << 8)) return 0x4u; /* RENDER_TARGET */
|
||||
return 0x40u;
|
||||
}
|
||||
|
||||
static uint32_t fsr_flags_to_wl(uint32_t flags) {
|
||||
uint32_t out = 0;
|
||||
if (flags & (1u << 0)) out |= WLFSR4_FLAG_HDR;
|
||||
if (flags & (1u << 1)) out |= WLFSR4_FLAG_DISPLAY_RES_MV;
|
||||
if (flags & (1u << 2)) out |= WLFSR4_FLAG_MV_JITTERED;
|
||||
if (flags & (1u << 3)) out |= WLFSR4_FLAG_DEPTH_INVERTED;
|
||||
if (flags & (1u << 5)) out |= WLFSR4_FLAG_AUTO_EXPOSURE;
|
||||
return out;
|
||||
}
|
||||
|
||||
static int ptr_belongs_to_vk_backend(void *fn_ptr) {
|
||||
if (!fn_ptr) return 0;
|
||||
HMODULE hm = NULL;
|
||||
if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
||||
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
(LPCSTR)fn_ptr, &hm) || !hm) {
|
||||
return 0;
|
||||
}
|
||||
char path[MAX_PATH];
|
||||
DWORD len = GetModuleFileNameA(hm, path, MAX_PATH);
|
||||
if (!len) return 0;
|
||||
for (DWORD i = 0; i < len; i++) {
|
||||
if (path[i] >= 'A' && path[i] <= 'Z') path[i] = (char)(path[i] - 'A' + 'a');
|
||||
}
|
||||
if (strstr(path, "_vk") || strstr(path, "vulkan")) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ptr_belongs_to_dx12_backend(void *fn_ptr) {
|
||||
if (!fn_ptr) return 0;
|
||||
HMODULE hm = NULL;
|
||||
if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
||||
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
(LPCSTR)fn_ptr, &hm) || !hm) {
|
||||
return 0;
|
||||
}
|
||||
char path[MAX_PATH];
|
||||
DWORD len = GetModuleFileNameA(hm, path, MAX_PATH);
|
||||
if (!len) return 0;
|
||||
for (DWORD i = 0; i < len; i++) {
|
||||
if (path[i] >= 'A' && path[i] <= 'Z') path[i] = (char)(path[i] - 'A' + 'a');
|
||||
}
|
||||
if (strstr(path, "dx12") || strstr(path, "d3d12")) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fsr_init_backend(WlFsr23Ctx *ctx, void *ffx_device, void *cb_probe, int is_fsr3) {
|
||||
if (!ffx_device) return;
|
||||
int is_vk = ptr_belongs_to_vk_backend(cb_probe);
|
||||
int is_dx = ptr_belongs_to_dx12_backend(cb_probe);
|
||||
|
||||
if (!is_vk && !is_dx) {
|
||||
// Fallback heuristic: if d3d12.dll is loaded, prefer DX12 unless vk backend module is present
|
||||
if (GetModuleHandleA("ffx_backend_vk_x64.dll") || GetModuleHandleA("ffx_fsr2_api_vk_x64.dll")) {
|
||||
is_vk = 1;
|
||||
} else if (GetModuleHandleA("d3d12.dll")) {
|
||||
is_dx = 1;
|
||||
} else if (GetModuleHandleA("vulkan-1.dll")) {
|
||||
is_vk = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_vk) {
|
||||
ctx->is_dx12 = 0;
|
||||
if (is_fsr3) {
|
||||
// FSR 3 VK passes FfxVkDeviceContext* as FfxDevice
|
||||
const WlFfxVkDevCtx3 *vkc = (const WlFfxVkDevCtx3 *)ffx_device;
|
||||
if (vkc->vkDevice) {
|
||||
wl_seam_init(&ctx->seam, NULL, vkc->vkPhysicalDevice, vkc->vkDevice, vkc->vkDeviceProcAddr);
|
||||
}
|
||||
} else {
|
||||
// FSR 2 VK passes VkDevice directly as FfxDevice
|
||||
wl_seam_init(&ctx->seam, NULL, NULL, (VkDevice)ffx_device, NULL);
|
||||
}
|
||||
} else {
|
||||
ctx->is_dx12 = 1;
|
||||
ctx->d3d12_dev = ffx_device;
|
||||
ctx->dx12_interop = wl_query_vkd3d_interop(ffx_device);
|
||||
if (ctx->dx12_interop) {
|
||||
void *vk_inst = NULL, *vk_phys = NULL, *vk_dev = NULL;
|
||||
if (ctx->dx12_interop->lpVtbl->GetVulkanHandles(ctx->dx12_interop, &vk_inst, &vk_phys, &vk_dev) == S_OK && vk_dev) {
|
||||
wl_seam_init(&ctx->seam, vk_inst, vk_phys, vk_dev, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void fsr_fill_ref(WlFsr23Ctx *ctx, WlFsr4ImageRef *dst, void *res,
|
||||
uint32_t ffx_fmt, uint32_t ffx_state, uint32_t w, uint32_t h, int is_depth) {
|
||||
memset(dst, 0, sizeof *dst);
|
||||
if (!res) return;
|
||||
if (!ctx->is_dx12) {
|
||||
dst->vk_image = (uint64_t)(uintptr_t)res;
|
||||
dst->vk_format = fsr_fmt_to_vk(ffx_fmt);
|
||||
dst->vk_layout = fsr_state_to_vk_layout(ffx_state, is_depth);
|
||||
dst->width = w;
|
||||
dst->height = h;
|
||||
dst->aspect = is_depth ? 2u : 1u;
|
||||
} else if (ctx->dx12_interop) {
|
||||
UINT64 vk_img = 0, off = 0;
|
||||
UINT32 vk_fmt = 0;
|
||||
if (ctx->dx12_interop->lpVtbl->GetVulkanResourceInfo1(ctx->dx12_interop, res, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
||||
UINT32 layout = fsr_state_to_vk_layout(ffx_state, is_depth);
|
||||
if (ctx->dx12_interop->lpVtbl->GetVulkanImageLayout) {
|
||||
UINT32 queried = 0;
|
||||
ctx->dx12_interop->lpVtbl->GetVulkanImageLayout(ctx->dx12_interop, res, fsr_state_to_d3d12(ffx_state), &queried);
|
||||
if (queried != 0) layout = queried;
|
||||
}
|
||||
dst->vk_image = vk_img;
|
||||
dst->vk_format = vk_fmt ? vk_fmt : fsr_fmt_to_vk(ffx_fmt);
|
||||
dst->vk_layout = layout;
|
||||
dst->width = w;
|
||||
dst->height = h;
|
||||
dst->aspect = is_depth ? 2u : 1u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int fsr_submit_frame_ex(WlFsr23Ctx *ctx, void *cmd_list, WlFsr4FrameDesc *f,
|
||||
void *res_col, void *res_dep, void *res_mv, void *res_out) {
|
||||
if (!ctx || !cmd_list || !ctx->seam.ready) return 0;
|
||||
if (!ctx->is_dx12) {
|
||||
return wl_seam_dispatch_or_blit(&ctx->seam, (VkCommandBuffer)cmd_list, f);
|
||||
} else if (ctx->dx12_interop) {
|
||||
int live_en = 1;
|
||||
int live_backend = wl_seam_live_backend(&ctx->seam, &live_en);
|
||||
if (live_en && live_backend == WL_FSR_BACKEND_XESS3_GPU && ctx->d3d12_dev) {
|
||||
if (wl_xess3_eval_d3d12(&ctx->xess3, &ctx->seam, ctx->dx12_interop,
|
||||
ctx->d3d12_dev, cmd_list, f,
|
||||
res_col, res_dep, res_mv, res_out)) {
|
||||
return 1;
|
||||
}
|
||||
wl_xess3_tag_fallback(&ctx->xess3, f);
|
||||
} else {
|
||||
wl_xess3_on_inactive(&ctx->xess3);
|
||||
}
|
||||
void *vk_cb = NULL;
|
||||
int ok = 0;
|
||||
if (ctx->dx12_interop->lpVtbl->BeginVkCommandBufferInterop(ctx->dx12_interop, cmd_list, &vk_cb) == S_OK && vk_cb) {
|
||||
ok = wl_seam_dispatch_or_blit(&ctx->seam, (VkCommandBuffer)vk_cb, f);
|
||||
ctx->dx12_interop->lpVtbl->EndVkCommandBufferInterop(ctx->dx12_interop, cmd_list);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static WlFsr23Ctx *unwrap_ctx(void *opaque_ctx) {
|
||||
if (!opaque_ctx) return NULL;
|
||||
WlFsrContextHeader *hdr = (WlFsrContextHeader *)opaque_ctx;
|
||||
if (hdr->magic != WL_FSR23_MAGIC || !hdr->ctx || hdr->ctx->magic != WL_FSR23_MAGIC) return NULL;
|
||||
return hdr->ctx;
|
||||
}
|
||||
|
||||
static void destroy_ctx_common(void *opaque_ctx) {
|
||||
WlFsr23Ctx *ctx = unwrap_ctx(opaque_ctx);
|
||||
if (!ctx) return;
|
||||
wl_xess3_destroy(&ctx->xess3);
|
||||
wl_seam_destroy(&ctx->seam);
|
||||
if (ctx->dx12_interop) {
|
||||
ctx->dx12_interop->lpVtbl->Release(ctx->dx12_interop);
|
||||
ctx->dx12_interop = NULL;
|
||||
}
|
||||
ctx->magic = 0;
|
||||
free(ctx);
|
||||
memset(opaque_ctx, 0, sizeof(WlFsrContextHeader));
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// AMD FSR 3 Upscaler Exports (ffx_fsr3upscaler_x64.dll)
|
||||
// ============================================================================
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr3UpscalerContextCreate(void *pContext, const void *pContextDescription) {
|
||||
if (!pContext || !pContextDescription) return FFX_ERROR_INVALID_POINTER;
|
||||
|
||||
const WlFfxFsr30CtxDesc *d30 = (const WlFfxFsr30CtxDesc *)pContextDescription;
|
||||
const WlFfxFsr31CtxDesc *d31 = (const WlFfxFsr31CtxDesc *)pContextDescription;
|
||||
|
||||
// Auto-detect FSR 3.0 vs FSR 3.1 layout:
|
||||
// In FSR 3.0, backendInterface.scratchBufferSize is at offset 160 and device is at 168.
|
||||
// In FSR 3.1, fpMessage precedes backendInterface so scratchBufferSize is at 168 and device is at 176.
|
||||
int is_31 = 0;
|
||||
size_t sz30 = d30->backendInterface.scratchBufferSize;
|
||||
size_t sz31 = d31->backendInterface.scratchBufferSize;
|
||||
int sz30_ok = (sz30 > 0 && sz30 < (64u * 1024u * 1024u) && d30->backendInterface.device != NULL);
|
||||
int sz31_ok = (sz31 > 0 && sz31 < (64u * 1024u * 1024u) && d31->backendInterface.device != NULL);
|
||||
if (sz31_ok && !sz30_ok) {
|
||||
is_31 = 1;
|
||||
} else if (!sz30_ok && d31->backendInterface.device != NULL && d30->backendInterface.callbacks[0] == NULL) {
|
||||
is_31 = 1;
|
||||
}
|
||||
|
||||
WlFsr23Ctx *ctx = (WlFsr23Ctx *)calloc(1, sizeof *ctx);
|
||||
if (!ctx) return FFX_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
ctx->magic = WL_FSR23_MAGIC;
|
||||
ctx->is_fsr3 = 1;
|
||||
ctx->is_fsr31 = is_31;
|
||||
ctx->needs_reset = 1;
|
||||
ctx->flags = d30->flags;
|
||||
ctx->max_rw = d30->maxRenderSize.width;
|
||||
ctx->max_rh = d30->maxRenderSize.height;
|
||||
ctx->disp_w = d30->displaySize.width;
|
||||
ctx->disp_h = d30->displaySize.height;
|
||||
|
||||
void *dev = is_31 ? d31->backendInterface.device : d30->backendInterface.device;
|
||||
void *cb_probe = is_31 ? d31->backendInterface.callbacks[1] : d30->backendInterface.callbacks[1];
|
||||
fsr_init_backend(ctx, dev, cb_probe, 1);
|
||||
|
||||
WlFsrContextHeader *hdr = (WlFsrContextHeader *)pContext;
|
||||
hdr->magic = WL_FSR23_MAGIC;
|
||||
hdr->pad = 0;
|
||||
hdr->ctx = ctx;
|
||||
return FFX_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr3UpscalerGetSharedResourceDescriptions(void *pContext, void *pSharedResources) {
|
||||
WlFsr23Ctx *ctx = unwrap_ctx(pContext);
|
||||
if (!ctx || !pSharedResources) return FFX_ERROR_INVALID_POINTER;
|
||||
|
||||
WlFfxFsr3SharedResDescs *sr = (WlFfxFsr3SharedResDescs *)pSharedResources;
|
||||
memset(sr, 0, sizeof *sr);
|
||||
uint32_t w = ctx->max_rw ? ctx->max_rw : 1280;
|
||||
uint32_t h = ctx->max_rh ? ctx->max_rh : 720;
|
||||
|
||||
// reconstructedPrevNearestDepth: R32_UINT, UAV
|
||||
sr->reconstructedPrevNearestDepth.resourceDescription.type = 2; /* TEXTURE2D */
|
||||
sr->reconstructedPrevNearestDepth.resourceDescription.format = 7; /* R32_UINT */
|
||||
sr->reconstructedPrevNearestDepth.resourceDescription.width = w;
|
||||
sr->reconstructedPrevNearestDepth.resourceDescription.height = h;
|
||||
sr->reconstructedPrevNearestDepth.resourceDescription.depth = 1;
|
||||
sr->reconstructedPrevNearestDepth.resourceDescription.mipCount = 1;
|
||||
sr->reconstructedPrevNearestDepth.resourceDescription.usage = 2; /* UAV */
|
||||
sr->reconstructedPrevNearestDepth.initialState = 2; /* UNORDERED_ACCESS */
|
||||
|
||||
// dilatedDepth: R32_FLOAT, UAV
|
||||
sr->dilatedDepth = sr->reconstructedPrevNearestDepth;
|
||||
sr->dilatedDepth.resourceDescription.format = 24; /* R32_FLOAT */
|
||||
|
||||
// dilatedMotionVectors: R16G16_FLOAT, UAV
|
||||
sr->dilatedMotionVectors = sr->reconstructedPrevNearestDepth;
|
||||
sr->dilatedMotionVectors.resourceDescription.format = 14; /* R16G16_FLOAT */
|
||||
return FFX_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr3UpscalerContextDispatch(void *pContext, const void *pDispatchDescription) {
|
||||
WlFsr23Ctx *ctx = unwrap_ctx(pContext);
|
||||
if (!ctx || !pDispatchDescription) return FFX_ERROR_INVALID_POINTER;
|
||||
|
||||
const WlFfxFsr30DispatchDesc *d30 = (const WlFfxFsr30DispatchDesc *)pDispatchDescription;
|
||||
const WlFfxFsr31DispatchDesc *d31 = (const WlFfxFsr31DispatchDesc *)pDispatchDescription;
|
||||
|
||||
WlFsr4FrameDesc f;
|
||||
memset(&f, 0, sizeof f);
|
||||
|
||||
uint32_t rw = d30->renderSize.width ? d30->renderSize.width : ctx->max_rw;
|
||||
uint32_t rh = d30->renderSize.height ? d30->renderSize.height : ctx->max_rh;
|
||||
uint32_t ow = ctx->disp_w;
|
||||
uint32_t oh = ctx->disp_h;
|
||||
if (ctx->is_fsr31 && d31->upscaleSize.width >= 64 && d31->upscaleSize.height >= 64) {
|
||||
ow = d31->upscaleSize.width;
|
||||
oh = d31->upscaleSize.height;
|
||||
}
|
||||
if (!ow && d30->output.description.width) ow = d30->output.description.width;
|
||||
if (!oh && d30->output.description.height) oh = d30->output.description.height;
|
||||
|
||||
f.render_w = rw;
|
||||
f.render_h = rh;
|
||||
f.output_w = ow;
|
||||
f.output_h = oh;
|
||||
f.jitter_x = d30->jitterOffset.x;
|
||||
f.jitter_y = d30->jitterOffset.y;
|
||||
f.mv_scale_x = d30->motionVectorScale.x != 0.0f ? d30->motionVectorScale.x : 1.0f;
|
||||
f.mv_scale_y = d30->motionVectorScale.y != 0.0f ? d30->motionVectorScale.y : 1.0f;
|
||||
|
||||
bool en_sharp = ctx->is_fsr31 ? d31->enableSharpening : d30->enableSharpening;
|
||||
float sharp = ctx->is_fsr31 ? d31->sharpness : d30->sharpness;
|
||||
float dt = ctx->is_fsr31 ? d31->frameTimeDelta : d30->frameTimeDelta;
|
||||
float pre_exp = ctx->is_fsr31 ? d31->preExposure : d30->preExposure;
|
||||
bool reset = ctx->is_fsr31 ? d31->reset : d30->reset;
|
||||
float c_near = ctx->is_fsr31 ? d31->cameraNear : d30->cameraNear;
|
||||
float c_far = ctx->is_fsr31 ? d31->cameraFar : d30->cameraFar;
|
||||
float c_fov = ctx->is_fsr31 ? d31->cameraFovAngleVertical : d30->cameraFovAngleVertical;
|
||||
|
||||
f.pre_exposure = pre_exp > 0.0f ? pre_exp : 1.0f;
|
||||
f.sharpness = sharp;
|
||||
f.frame_time_ms = dt;
|
||||
f.camera_near = c_near;
|
||||
f.camera_far = c_far;
|
||||
f.camera_fov_y = c_fov;
|
||||
f.flags = fsr_flags_to_wl(ctx->flags);
|
||||
if (en_sharp) f.flags |= WLFSR4_FLAG_SHARPEN;
|
||||
if (reset || ctx->needs_reset) {
|
||||
f.flags |= WLFSR4_FLAG_RESET;
|
||||
ctx->needs_reset = 0;
|
||||
}
|
||||
|
||||
f.api_source = ctx->is_dx12 ? WLFSR4_API_FSR3_DX12 : WLFSR4_API_FSR3_VK;
|
||||
f.quality_mode = (g_last_quality_mode != WLFSR4_QUALITY_AUTO)
|
||||
? g_last_quality_mode
|
||||
: fsr_infer_quality(rw, ow);
|
||||
if (f.quality_mode == WLFSR4_QUALITY_ULTRA_PERF) f.preset_hint = WLFSR4_PRESET_ULTRAPERF;
|
||||
|
||||
int high_res_mv = (ctx->flags & (1u << 1)) ? 1 : 0;
|
||||
fsr_fill_ref(ctx, &f.color, d30->color.resource, d30->color.description.format, d30->color.state,
|
||||
d30->color.description.width ? d30->color.description.width : rw,
|
||||
d30->color.description.height ? d30->color.description.height : rh, 0);
|
||||
fsr_fill_ref(ctx, &f.depth, d30->depth.resource, d30->depth.description.format, d30->depth.state,
|
||||
d30->depth.description.width ? d30->depth.description.width : rw,
|
||||
d30->depth.description.height ? d30->depth.description.height : rh, 1);
|
||||
fsr_fill_ref(ctx, &f.motion, d30->motionVectors.resource, d30->motionVectors.description.format, d30->motionVectors.state,
|
||||
d30->motionVectors.description.width ? d30->motionVectors.description.width : (high_res_mv ? ow : rw),
|
||||
d30->motionVectors.description.height ? d30->motionVectors.description.height : (high_res_mv ? oh : rh), 0);
|
||||
fsr_fill_ref(ctx, &f.output, d30->output.resource, d30->output.description.format, d30->output.state,
|
||||
d30->output.description.width ? d30->output.description.width : ow,
|
||||
d30->output.description.height ? d30->output.description.height : oh, 0);
|
||||
|
||||
int ok = fsr_submit_frame_ex(ctx, d30->commandList, &f,
|
||||
d30->color.resource, d30->depth.resource,
|
||||
d30->motionVectors.resource, d30->output.resource);
|
||||
return ok ? FFX_OK : FFX_ERROR_NULL_DEVICE;
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr3UpscalerContextGenerateReactiveMask(void *pContext, const void *pParams) {
|
||||
(void)pContext; (void)pParams;
|
||||
return FFX_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr3UpscalerContextDestroy(void *pContext) {
|
||||
if (!pContext) return FFX_ERROR_INVALID_POINTER;
|
||||
destroy_ctx_common(pContext);
|
||||
return FFX_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) float ffxFsr3UpscalerGetUpscaleRatioFromQualityMode(uint32_t qualityMode) {
|
||||
g_last_quality_mode = fsr_mode_to_wl(qualityMode);
|
||||
return fsr_quality_ratio(qualityMode);
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr3UpscalerGetRenderResolutionFromQualityMode(
|
||||
uint32_t *pRenderWidth, uint32_t *pRenderHeight,
|
||||
uint32_t displayWidth, uint32_t displayHeight, uint32_t qualityMode) {
|
||||
if (!pRenderWidth || !pRenderHeight) return FFX_ERROR_INVALID_POINTER;
|
||||
float r = fsr_quality_ratio(qualityMode);
|
||||
if (r <= 0.0f) return FFX_ERROR_INVALID_ENUM;
|
||||
g_last_quality_mode = fsr_mode_to_wl(qualityMode);
|
||||
*pRenderWidth = (uint32_t)((float)displayWidth / r);
|
||||
*pRenderHeight = (uint32_t)((float)displayHeight / r);
|
||||
return FFX_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) int32_t ffxFsr3UpscalerGetJitterPhaseCount(int32_t renderWidth, int32_t displayWidth) {
|
||||
if (renderWidth <= 0) return 8;
|
||||
float ratio = (float)displayWidth / (float)renderWidth;
|
||||
int32_t pc = (int32_t)ceilf(8.0f * ratio * ratio);
|
||||
return pc < 8 ? 8 : pc;
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr3UpscalerGetJitterOffset(float *pOutX, float *pOutY,
|
||||
int32_t index, int32_t phaseCount) {
|
||||
if (!pOutX || !pOutY) return FFX_ERROR_INVALID_POINTER;
|
||||
if (phaseCount <= 0) return FFX_ERROR_INVALID_ARGUMENT;
|
||||
int32_t idx = (index % phaseCount) + 1;
|
||||
if (idx <= 0) idx += phaseCount;
|
||||
*pOutX = fsr_halton(idx, 2) - 0.5f;
|
||||
*pOutY = fsr_halton(idx, 3) - 0.5f;
|
||||
return FFX_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) bool ffxFsr3UpscalerResourceIsNull(WlFfxResource3 resource) {
|
||||
return resource.resource == NULL;
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr3UpscalerSetConstant(void *pContext, uint32_t key, void *valuePtr) {
|
||||
(void)pContext; (void)key; (void)valuePtr;
|
||||
return FFX_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) uint32_t ffxFsr3UpscalerGetEffectVersion(void) {
|
||||
return (3u << 22) | (1u << 12) | 0u;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// AMD FSR 2 Core Exports (ffx_fsr2_api_x64.dll)
|
||||
// ============================================================================
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr2ContextCreate(void *pContext, const void *pContextDescription) {
|
||||
if (!pContext || !pContextDescription) return FFX_ERROR_INVALID_POINTER;
|
||||
|
||||
const WlFfxFsr2CtxDesc *d = (const WlFfxFsr2CtxDesc *)pContextDescription;
|
||||
WlFsr23Ctx *ctx = (WlFsr23Ctx *)calloc(1, sizeof *ctx);
|
||||
if (!ctx) return FFX_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
ctx->magic = WL_FSR23_MAGIC;
|
||||
ctx->is_fsr3 = 0;
|
||||
ctx->is_fsr31 = 0;
|
||||
ctx->needs_reset = 1;
|
||||
ctx->flags = d->flags;
|
||||
ctx->max_rw = d->maxRenderSize.width;
|
||||
ctx->max_rh = d->maxRenderSize.height;
|
||||
ctx->disp_w = d->displaySize.width;
|
||||
ctx->disp_h = d->displaySize.height;
|
||||
|
||||
fsr_init_backend(ctx, d->device, d->callbacks.callbacks[0], 0);
|
||||
|
||||
WlFsrContextHeader *hdr = (WlFsrContextHeader *)pContext;
|
||||
hdr->magic = WL_FSR23_MAGIC;
|
||||
hdr->pad = 0;
|
||||
hdr->ctx = ctx;
|
||||
return FFX_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr2ContextDispatch(void *pContext, const void *pDispatchDescription) {
|
||||
WlFsr23Ctx *ctx = unwrap_ctx(pContext);
|
||||
if (!ctx || !pDispatchDescription) return FFX_ERROR_INVALID_POINTER;
|
||||
|
||||
const WlFfxFsr21DispatchDesc *d21 = (const WlFfxFsr21DispatchDesc *)pDispatchDescription;
|
||||
const WlFfxFsr20DispatchDesc *d20 = (const WlFfxFsr20DispatchDesc *)pDispatchDescription;
|
||||
|
||||
// Auto-detect FSR 2.1/2.2 (184-byte FfxResource with wchar_t name[64]) vs FSR 2.0 (56-byte FfxResource)
|
||||
int use_21 = (d21->renderSize.width >= 64 && d21->renderSize.width <= 16384 &&
|
||||
d21->renderSize.height >= 64 && d21->renderSize.height <= 16384 &&
|
||||
d21->output.resource != NULL);
|
||||
|
||||
WlFsr4FrameDesc f;
|
||||
memset(&f, 0, sizeof f);
|
||||
|
||||
uint32_t rw = use_21 ? d21->renderSize.width : d20->renderSize.width;
|
||||
uint32_t rh = use_21 ? d21->renderSize.height : d20->renderSize.height;
|
||||
if (!rw) rw = ctx->max_rw;
|
||||
if (!rh) rh = ctx->max_rh;
|
||||
uint32_t ow = ctx->disp_w;
|
||||
uint32_t oh = ctx->disp_h;
|
||||
int high_res_mv = (ctx->flags & (1u << 1)) ? 1 : 0;
|
||||
|
||||
f.render_w = rw;
|
||||
f.render_h = rh;
|
||||
f.output_w = ow;
|
||||
f.output_h = oh;
|
||||
f.jitter_x = use_21 ? d21->jitterOffset.x : d20->jitterOffset.x;
|
||||
f.jitter_y = use_21 ? d21->jitterOffset.y : d20->jitterOffset.y;
|
||||
float mvx = use_21 ? d21->motionVectorScale.x : d20->motionVectorScale.x;
|
||||
float mvy = use_21 ? d21->motionVectorScale.y : d20->motionVectorScale.y;
|
||||
f.mv_scale_x = mvx != 0.0f ? mvx : 1.0f;
|
||||
f.mv_scale_y = mvy != 0.0f ? mvy : 1.0f;
|
||||
float pre_exp = use_21 ? d21->preExposure : d20->preExposure;
|
||||
f.pre_exposure = pre_exp > 0.0f ? pre_exp : 1.0f;
|
||||
f.sharpness = use_21 ? d21->sharpness : d20->sharpness;
|
||||
f.frame_time_ms = use_21 ? d21->frameTimeDelta : d20->frameTimeDelta;
|
||||
f.camera_near = use_21 ? d21->cameraNear : d20->cameraNear;
|
||||
f.camera_far = use_21 ? d21->cameraFar : d20->cameraFar;
|
||||
f.camera_fov_y = use_21 ? d21->cameraFovAngleVertical : d20->cameraFovAngleVertical;
|
||||
f.flags = fsr_flags_to_wl(ctx->flags);
|
||||
if (use_21 ? d21->enableSharpening : d20->enableSharpening) f.flags |= WLFSR4_FLAG_SHARPEN;
|
||||
if ((use_21 ? d21->reset : d20->reset) || ctx->needs_reset) {
|
||||
f.flags |= WLFSR4_FLAG_RESET;
|
||||
ctx->needs_reset = 0;
|
||||
}
|
||||
|
||||
f.api_source = ctx->is_dx12 ? WLFSR4_API_FSR2_DX12 : WLFSR4_API_FSR2_VK;
|
||||
f.quality_mode = (g_last_quality_mode != WLFSR4_QUALITY_AUTO)
|
||||
? g_last_quality_mode
|
||||
: fsr_infer_quality(rw, ow);
|
||||
if (f.quality_mode == WLFSR4_QUALITY_ULTRA_PERF) f.preset_hint = WLFSR4_PRESET_ULTRAPERF;
|
||||
|
||||
if (use_21) {
|
||||
fsr_fill_ref(ctx, &f.color, d21->color.resource, d21->color.description.format, d21->color.state,
|
||||
d21->color.description.width ? d21->color.description.width : rw,
|
||||
d21->color.description.height ? d21->color.description.height : rh, 0);
|
||||
fsr_fill_ref(ctx, &f.depth, d21->depth.resource, d21->depth.description.format, d21->depth.state,
|
||||
d21->depth.description.width ? d21->depth.description.width : rw,
|
||||
d21->depth.description.height ? d21->depth.description.height : rh, 1);
|
||||
fsr_fill_ref(ctx, &f.motion, d21->motionVectors.resource, d21->motionVectors.description.format, d21->motionVectors.state,
|
||||
d21->motionVectors.description.width ? d21->motionVectors.description.width : (high_res_mv ? ow : rw),
|
||||
d21->motionVectors.description.height ? d21->motionVectors.description.height : (high_res_mv ? oh : rh), 0);
|
||||
fsr_fill_ref(ctx, &f.output, d21->output.resource, d21->output.description.format, d21->output.state,
|
||||
d21->output.description.width ? d21->output.description.width : ow,
|
||||
d21->output.description.height ? d21->output.description.height : oh, 0);
|
||||
} else {
|
||||
fsr_fill_ref(ctx, &f.color, d20->color.resource, d20->color.description.format, d20->color.state,
|
||||
d20->color.description.width ? d20->color.description.width : rw,
|
||||
d20->color.description.height ? d20->color.description.height : rh, 0);
|
||||
fsr_fill_ref(ctx, &f.depth, d20->depth.resource, d20->depth.description.format, d20->depth.state,
|
||||
d20->depth.description.width ? d20->depth.description.width : rw,
|
||||
d20->depth.description.height ? d20->depth.description.height : rh, 1);
|
||||
fsr_fill_ref(ctx, &f.motion, d20->motionVectors.resource, d20->motionVectors.description.format, d20->motionVectors.state,
|
||||
d20->motionVectors.description.width ? d20->motionVectors.description.width : (high_res_mv ? ow : rw),
|
||||
d20->motionVectors.description.height ? d20->motionVectors.description.height : (high_res_mv ? oh : rh), 0);
|
||||
fsr_fill_ref(ctx, &f.output, d20->output.resource, d20->output.description.format, d20->output.state,
|
||||
d20->output.description.width ? d20->output.description.width : ow,
|
||||
d20->output.description.height ? d20->output.description.height : oh, 0);
|
||||
}
|
||||
|
||||
int ok = fsr_submit_frame_ex(ctx, d21->commandList, &f,
|
||||
use_21 ? d21->color.resource : d20->color.resource,
|
||||
use_21 ? d21->depth.resource : d20->depth.resource,
|
||||
use_21 ? d21->motionVectors.resource : d20->motionVectors.resource,
|
||||
use_21 ? d21->output.resource : d20->output.resource);
|
||||
return ok ? FFX_OK : FFX_ERROR_NULL_DEVICE;
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr2ContextGenerateReactiveMask(void *pContext, const void *pParams) {
|
||||
(void)pContext; (void)pParams;
|
||||
return FFX_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr2ContextDestroy(void *pContext) {
|
||||
if (!pContext) return FFX_ERROR_INVALID_POINTER;
|
||||
destroy_ctx_common(pContext);
|
||||
return FFX_OK;
|
||||
}
|
||||
|
||||
__declspec(dllexport) float ffxFsr2GetUpscaleRatioFromQualityMode(uint32_t qualityMode) {
|
||||
g_last_quality_mode = fsr_mode_to_wl(qualityMode);
|
||||
return fsr_quality_ratio(qualityMode);
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr2GetRenderResolutionFromQualityMode(
|
||||
uint32_t *renderWidth, uint32_t *renderHeight,
|
||||
uint32_t displayWidth, uint32_t displayHeight, uint32_t qualityMode) {
|
||||
return ffxFsr3UpscalerGetRenderResolutionFromQualityMode(
|
||||
renderWidth, renderHeight, displayWidth, displayHeight, qualityMode);
|
||||
}
|
||||
|
||||
__declspec(dllexport) int32_t ffxFsr2GetJitterPhaseCount(int32_t renderWidth, int32_t displayWidth) {
|
||||
return ffxFsr3UpscalerGetJitterPhaseCount(renderWidth, displayWidth);
|
||||
}
|
||||
|
||||
__declspec(dllexport) FfxErrorCode ffxFsr2GetJitterOffset(float *outX, float *outY,
|
||||
int32_t index, int32_t phaseCount) {
|
||||
return ffxFsr3UpscalerGetJitterOffset(outX, outY, index, phaseCount);
|
||||
}
|
||||
|
||||
__declspec(dllexport) bool ffxFsr2ResourceIsNull(WlFfxResource21 resource) {
|
||||
return resource.resource == NULL;
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
|
||||
(void)hinst; (void)reason; (void)reserved;
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,949 @@
|
||||
// DroidDeck: modified from michaelisomer-cyber/Winlator-NeuralScale a0ab6b0f (see README.md).
|
||||
// Winlator Ludashi OptiScaler-style NVIDIA NGX (DLSS) -> AMD FSR 4.1.1 Hexagon HTP NPU Bridge
|
||||
//
|
||||
// Exports the full 89-symbol NVIDIA NGX ABI (Vulkan + D3D12 + D3D11) so DLSS-capable Windows
|
||||
// games (such as Red Dead Redemption 2 on Vulkan, Rise of the Tomb Raider / Cyberpunk on DX12)
|
||||
// unlock DLSS in-game and route every EvaluateFeature call zero-copy into our native Android
|
||||
// Vulkan Layer (libVkLayer_winlator_fsr4_npu.so) running FSR 4.1.1 on the Hexagon HTP v81 NPU.
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "wl_seam_client.h"
|
||||
#include "wl_vkd3d_interop.h"
|
||||
#include "wl_xess3_direct.h"
|
||||
|
||||
typedef uint32_t NVSDK_NGX_Result;
|
||||
#define NVSDK_NGX_Result_Success 0x00000001u
|
||||
#define NVSDK_NGX_Result_Fail 0xBAD00000u
|
||||
#define NVSDK_NGX_Result_FAIL_FeatureNotSupported 0xBAD00001u
|
||||
#define NVSDK_NGX_Result_FAIL_InvalidParameter 0xBAD00005u
|
||||
#define NVSDK_NGX_Result_FAIL_NotInitialized 0xBAD00007u
|
||||
|
||||
typedef struct { uint32_t Id; } NVSDK_NGX_Handle;
|
||||
|
||||
typedef struct {
|
||||
uint32_t FeatureSupported; /* 0 = NVSDK_NGX_FeatureSupportResult_Supported */
|
||||
uint32_t MinHWArchitecture; /* 0 */
|
||||
char MinOSVersion[255];
|
||||
} NVSDK_NGX_FeatureRequirement;
|
||||
|
||||
typedef struct {
|
||||
uint32_t SDKVersion;
|
||||
uint32_t FeatureID; /* 1=SuperSampling, 11=FrameGeneration, 13=RayReconstruction */
|
||||
} NVSDK_NGX_FeatureDiscoveryInfoHead;
|
||||
|
||||
// Exact NVIDIA nvsdk_ngx_defs_vk.h layout (verified against NVIDIA/DLSS)
|
||||
typedef struct {
|
||||
uint32_t aspectMask;
|
||||
uint32_t baseMipLevel;
|
||||
uint32_t levelCount;
|
||||
uint32_t baseArrayLayer;
|
||||
uint32_t layerCount;
|
||||
} WlVkImageSubresourceRange;
|
||||
|
||||
typedef struct {
|
||||
uint64_t ImageView;
|
||||
uint64_t Image;
|
||||
WlVkImageSubresourceRange SubresourceRange;
|
||||
uint32_t Format;
|
||||
uint32_t Width;
|
||||
uint32_t Height;
|
||||
} NVSDK_NGX_ImageViewInfo_VK;
|
||||
|
||||
typedef struct {
|
||||
uint64_t Buffer;
|
||||
uint32_t SizeInBytes;
|
||||
} NVSDK_NGX_BufferInfo_VK;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
NVSDK_NGX_ImageViewInfo_VK ImageViewInfo;
|
||||
NVSDK_NGX_BufferInfo_VK BufferInfo;
|
||||
} Resource;
|
||||
uint32_t Type; /* 0 = VK_IMAGEVIEW, 1 = VK_BUFFER */
|
||||
bool ReadWrite;
|
||||
} NVSDK_NGX_Resource_VK;
|
||||
|
||||
// ---- Parameter bag with exact 17-slot MSVC x64 C++ vtable ----
|
||||
#define MAX_PARAMS 160
|
||||
|
||||
typedef struct {
|
||||
char key[96];
|
||||
int type; /* 0=ull/i/ui, 1=f, 2=d, 3=ptr */
|
||||
uint64_t u;
|
||||
float f;
|
||||
double d;
|
||||
void *p;
|
||||
} WlNgxKv;
|
||||
|
||||
typedef struct WlNgxParam {
|
||||
void **vtbl;
|
||||
int owned;
|
||||
int count;
|
||||
WlNgxKv kv[MAX_PARAMS];
|
||||
} WlNgxParam;
|
||||
|
||||
static WlNgxKv *kv_find(WlNgxParam *s, const char *k) {
|
||||
if (!s || !k) return NULL;
|
||||
for (int i = 0; i < s->count; i++) {
|
||||
if (_stricmp(s->kv[i].key, k) == 0) return &s->kv[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void kv_set(WlNgxParam *s, const char *k, int type, uint64_t u, float f, double d, void *p) {
|
||||
if (!s || !k) return;
|
||||
WlNgxKv *e = kv_find(s, k);
|
||||
if (!e) {
|
||||
if (s->count >= MAX_PARAMS) return;
|
||||
e = &s->kv[s->count++];
|
||||
memset(e, 0, sizeof *e);
|
||||
strncpy(e->key, k, sizeof(e->key) - 1);
|
||||
}
|
||||
e->type = type; e->u = u; e->f = f; e->d = d; e->p = p;
|
||||
}
|
||||
|
||||
static int kv_get_u(WlNgxParam *s, const char *k, uint64_t *out) {
|
||||
WlNgxKv *e = kv_find(s, k);
|
||||
if (!e) return 0;
|
||||
if (out) {
|
||||
if (e->type == 0) *out = e->u;
|
||||
else if (e->type == 1) *out = (uint64_t)(int64_t)e->f;
|
||||
else if (e->type == 2) *out = (uint64_t)(int64_t)e->d;
|
||||
else *out = (uint64_t)(uintptr_t)e->p;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int kv_get_f(WlNgxParam *s, const char *k, float *out) {
|
||||
WlNgxKv *e = kv_find(s, k);
|
||||
if (!e) return 0;
|
||||
if (out) {
|
||||
if (e->type == 1) *out = e->f;
|
||||
else if (e->type == 2) *out = (float)e->d;
|
||||
else *out = (float)(int64_t)e->u;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int kv_get_d(WlNgxParam *s, const char *k, double *out) {
|
||||
WlNgxKv *e = kv_find(s, k);
|
||||
if (!e) return 0;
|
||||
if (out) {
|
||||
if (e->type == 2) *out = e->d;
|
||||
else if (e->type == 1) *out = (double)e->f;
|
||||
else *out = (double)(int64_t)e->u;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int kv_get_p(WlNgxParam *s, const char *k, void **out) {
|
||||
WlNgxKv *e = kv_find(s, k);
|
||||
if (!e) return 0;
|
||||
if (out) *out = (e->type == 3) ? e->p : (void *)(uintptr_t)e->u;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// MSVC x64 C++ overloaded virtual function layout (reverse declaration order within Set/Get groups)
|
||||
static void __cdecl P_SetVP(WlNgxParam *s, const char *k, void *v) { kv_set(s, k, 3, (uint64_t)(uintptr_t)v, 0, 0, v); }
|
||||
static void __cdecl P_SetD12(WlNgxParam *s, const char *k, void *v) { kv_set(s, k, 3, (uint64_t)(uintptr_t)v, 0, 0, v); }
|
||||
static void __cdecl P_SetD11(WlNgxParam *s, const char *k, void *v) { kv_set(s, k, 3, (uint64_t)(uintptr_t)v, 0, 0, v); }
|
||||
static void __cdecl P_SetI(WlNgxParam *s, const char *k, int v) { kv_set(s, k, 0, (uint64_t)(int64_t)v, (float)v, (double)v, NULL); }
|
||||
static void __cdecl P_SetUI(WlNgxParam *s, const char *k, uint32_t v) { kv_set(s, k, 0, (uint64_t)v, (float)v, (double)v, NULL); }
|
||||
static void __cdecl P_SetD(WlNgxParam *s, const char *k, double v) { kv_set(s, k, 2, (uint64_t)(int64_t)v, (float)v, v, NULL); }
|
||||
static void __cdecl P_SetF(WlNgxParam *s, const char *k, float v) { kv_set(s, k, 1, (uint64_t)(int64_t)v, v, (double)v, NULL); }
|
||||
static void __cdecl P_SetULL(WlNgxParam *s, const char *k, uint64_t v) { kv_set(s, k, 0, v, (float)v, (double)v, (void *)(uintptr_t)v); }
|
||||
|
||||
static NVSDK_NGX_Result __cdecl P_GetVP(WlNgxParam *s, const char *k, void **v) { return kv_get_p(s, k, v) ? NVSDK_NGX_Result_Success : NVSDK_NGX_Result_FAIL_InvalidParameter; }
|
||||
static NVSDK_NGX_Result __cdecl P_GetD12(WlNgxParam *s, const char *k, void **v) { return kv_get_p(s, k, v) ? NVSDK_NGX_Result_Success : NVSDK_NGX_Result_FAIL_InvalidParameter; }
|
||||
static NVSDK_NGX_Result __cdecl P_GetD11(WlNgxParam *s, const char *k, void **v) { return kv_get_p(s, k, v) ? NVSDK_NGX_Result_Success : NVSDK_NGX_Result_FAIL_InvalidParameter; }
|
||||
static NVSDK_NGX_Result __cdecl P_GetI(WlNgxParam *s, const char *k, int *v) { uint64_t t = 0; if (!kv_get_u(s, k, &t)) return NVSDK_NGX_Result_FAIL_InvalidParameter; if (v) *v = (int)(int64_t)t; return NVSDK_NGX_Result_Success; }
|
||||
static NVSDK_NGX_Result __cdecl P_GetUI(WlNgxParam *s, const char *k, uint32_t *v) { uint64_t t = 0; if (!kv_get_u(s, k, &t)) return NVSDK_NGX_Result_FAIL_InvalidParameter; if (v) *v = (uint32_t)t; return NVSDK_NGX_Result_Success; }
|
||||
static NVSDK_NGX_Result __cdecl P_GetD(WlNgxParam *s, const char *k, double *v) { return kv_get_d(s, k, v) ? NVSDK_NGX_Result_Success : NVSDK_NGX_Result_FAIL_InvalidParameter; }
|
||||
static NVSDK_NGX_Result __cdecl P_GetF(WlNgxParam *s, const char *k, float *v) { return kv_get_f(s, k, v) ? NVSDK_NGX_Result_Success : NVSDK_NGX_Result_FAIL_InvalidParameter; }
|
||||
static NVSDK_NGX_Result __cdecl P_GetULL(WlNgxParam *s, const char *k, uint64_t *v) { return kv_get_u(s, k, v) ? NVSDK_NGX_Result_Success : NVSDK_NGX_Result_FAIL_InvalidParameter; }
|
||||
static void __cdecl P_Reset(WlNgxParam *s) { if (s) s->count = 0; }
|
||||
|
||||
static void *g_param_vtbl[17] = {
|
||||
(void *)P_SetVP, (void *)P_SetD12, (void *)P_SetD11, (void *)P_SetI,
|
||||
(void *)P_SetUI, (void *)P_SetD, (void *)P_SetF, (void *)P_SetULL,
|
||||
(void *)P_GetVP, (void *)P_GetD12, (void *)P_GetD11, (void *)P_GetI,
|
||||
(void *)P_GetUI, (void *)P_GetD, (void *)P_GetF, (void *)P_GetULL,
|
||||
(void *)P_Reset,
|
||||
};
|
||||
|
||||
static volatile uint32_t g_last_perf_quality = 0xFFFFFFFFu;
|
||||
|
||||
static uint32_t ngx_pq_to_wl_quality(uint32_t pq) {
|
||||
switch (pq) {
|
||||
case 0u: return WLFSR4_QUALITY_PERF;
|
||||
case 1u: return WLFSR4_QUALITY_BALANCED;
|
||||
case 2u: return WLFSR4_QUALITY_QUALITY;
|
||||
case 3u: return WLFSR4_QUALITY_ULTRA_PERF;
|
||||
case 4u: return WLFSR4_QUALITY_ULTRA_QUAL;
|
||||
case 5u: return WLFSR4_QUALITY_NATIVE_AA;
|
||||
default: return WLFSR4_QUALITY_AUTO;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t infer_quality_from_res(uint32_t rw, uint32_t ow) {
|
||||
if (rw == 0u || ow == 0u) return WLFSR4_QUALITY_AUTO;
|
||||
float r = (float)ow / (float)rw;
|
||||
if (r < 1.15f) return WLFSR4_QUALITY_NATIVE_AA;
|
||||
if (r < 1.38f) return WLFSR4_QUALITY_ULTRA_QUAL;
|
||||
if (r < 1.60f) return WLFSR4_QUALITY_QUALITY;
|
||||
if (r < 1.85f) return WLFSR4_QUALITY_BALANCED;
|
||||
if (r < 2.45f) return WLFSR4_QUALITY_PERF;
|
||||
return WLFSR4_QUALITY_ULTRA_PERF;
|
||||
}
|
||||
|
||||
static NVSDK_NGX_Result __cdecl dlss_optimal_settings_cb(WlNgxParam *p) {
|
||||
if (!p) return NVSDK_NGX_Result_FAIL_InvalidParameter;
|
||||
uint64_t ow = 1920, oh = 1080, pq = 0;
|
||||
if (!kv_get_u(p, "Width", &ow)) kv_get_u(p, "#\x10", &ow);
|
||||
if (!kv_get_u(p, "Height", &oh)) kv_get_u(p, "#\x11", &oh);
|
||||
if (kv_get_u(p, "PerfQualityValue", &pq) || kv_get_u(p, "#\x3f", &pq)) {
|
||||
g_last_perf_quality = (uint32_t)pq;
|
||||
}
|
||||
|
||||
// Map DLSS quality values to exact FSR 4.1.1 scale ratios
|
||||
float scale = 2.0f; /* MaxPerf = 2.0x -> 960x540 for 1080p */
|
||||
if (pq == 1) scale = 1.7f; /* Balanced */
|
||||
else if (pq == 2) scale = 1.5f; /* MaxQuality */
|
||||
else if (pq == 3) scale = 3.0f; /* UltraPerformance */
|
||||
else if (pq == 4) scale = 1.3f; /* UltraQuality */
|
||||
else if (pq == 5) scale = 1.0f; /* DLAA */
|
||||
|
||||
uint32_t rw = ((uint32_t)((float)ow / scale)) & ~1u;
|
||||
uint32_t rh = ((uint32_t)((float)oh / scale)) & ~1u;
|
||||
if (rw < 320u) rw = 320u;
|
||||
if (rh < 180u) rh = 180u;
|
||||
uint32_t minw = ((uint32_t)((float)ow * 0.5f)) & ~1u;
|
||||
uint32_t minh = ((uint32_t)((float)oh * 0.5f)) & ~1u;
|
||||
if (rw < minw || rh < minh) { minw = rw; minh = rh; }
|
||||
if (pq == 5) { minw = rw; minh = rh; }
|
||||
float scale_ratio = (ow > 0) ? ((float)rw / (float)ow) : (1.0f / scale);
|
||||
uint64_t scratch_bytes = (uint64_t)ow * (uint64_t)oh * 31ULL;
|
||||
|
||||
P_SetF(p, "Scale", scale_ratio);
|
||||
P_SetF(p, "SuperSampling.ScaleFactor", scale_ratio);
|
||||
P_SetUI(p, "OutWidth", rw);
|
||||
P_SetUI(p, "OutHeight", rh);
|
||||
P_SetUI(p, "DLSS.Get.Dynamic.Max.Render.Width", (uint32_t)ow);
|
||||
P_SetUI(p, "DLSS.Get.Dynamic.Max.Render.Height", (uint32_t)oh);
|
||||
P_SetUI(p, "DLSS.Get.Dynamic.Min.Render.Width", minw);
|
||||
P_SetUI(p, "DLSS.Get.Dynamic.Min.Render.Height", minh);
|
||||
P_SetF(p, "Sharpness", 0.0f);
|
||||
P_SetULL(p, "SizeInBytes", scratch_bytes);
|
||||
P_SetI(p, "DLSSMode", 1); /* NVSDK_NGX_DLSS_Mode_DLSS_DLISP */
|
||||
|
||||
// Legacy EParameter aliases used by older NGX SDK titles (e.g. RDR2)
|
||||
P_SetF(p, "#\x0f", scale_ratio);
|
||||
P_SetUI(p, "#\x12", rw);
|
||||
P_SetUI(p, "#\x13", rh);
|
||||
P_SetULL(p, "#\x30", scratch_bytes);
|
||||
P_SetI(p, "#\x41", 1);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
|
||||
static NVSDK_NGX_Result __cdecl dlss_get_stats_cb(WlNgxParam *p) {
|
||||
if (p) {
|
||||
uint64_t w = 1920, h = 1080;
|
||||
kv_get_u(p, "Width", &w);
|
||||
kv_get_u(p, "Height", &h);
|
||||
P_SetULL(p, "SizeInBytes", w * h * 31ULL);
|
||||
}
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
|
||||
static void populate_cap_params(WlNgxParam *p) {
|
||||
if (!p) return;
|
||||
P_SetI(p, "SuperSampling.Available", 1);
|
||||
P_SetI(p, "SuperSampling.NeedsUpdatedDriver", 0);
|
||||
P_SetUI(p, "SuperSampling.MinDriverVersionMajor", 0);
|
||||
P_SetUI(p, "SuperSampling.MinDriverVersionMinor", 0);
|
||||
P_SetUI(p, "SuperSampling.FeatureInitResult", NVSDK_NGX_Result_Success);
|
||||
P_SetI(p, "SuperSampling.Allow", 1);
|
||||
P_SetI(p, "DLSS.Available", 1);
|
||||
P_SetI(p, "Snippet.OptIn", 1);
|
||||
P_SetI(p, "Snippet.OptLevel", 0);
|
||||
P_SetI(p, "Snippet.IsDevBranch", 0);
|
||||
P_SetI(p, "FreeMemOnReleaseFeature", 0);
|
||||
P_SetI(p, "CreationNodeMask", 1);
|
||||
P_SetI(p, "VisibilityNodeMask", 1);
|
||||
P_SetI(p, "DLSS.Enable.Output.Subrects", 1);
|
||||
P_SetI(p, "RTXValue", 0);
|
||||
P_SetF(p, "Sharpness", 0.0f);
|
||||
P_SetF(p, "MV.Scale.X", 1.0f);
|
||||
P_SetF(p, "MV.Scale.Y", 1.0f);
|
||||
P_SetF(p, "MV.Offset.X", 0.0f);
|
||||
P_SetF(p, "MV.Offset.Y", 0.0f);
|
||||
P_SetF(p, "DLSS.Exposure.Scale", 1.0f);
|
||||
P_SetI(p, "PerfQualityValue", 0);
|
||||
P_SetULL(p, "SizeInBytes", 1920ULL * 1080ULL * 31ULL);
|
||||
P_SetVP(p, "DLSSOptimalSettingsCallback", (void *)dlss_optimal_settings_cb);
|
||||
P_SetVP(p, "DLSSDOptimalSettingsCallback", (void *)dlss_optimal_settings_cb);
|
||||
P_SetVP(p, "DLSSGetStatsCallback", (void *)dlss_get_stats_cb);
|
||||
|
||||
// Render preset hints (DLSS 3.1+ / Streamline / Cyberpunk 2077)
|
||||
P_SetUI(p, "DLSS.Hint.Render.Preset.DLAA", 0u);
|
||||
P_SetUI(p, "DLSS.Hint.Render.Preset.UltraQuality", 0u);
|
||||
P_SetUI(p, "DLSS.Hint.Render.Preset.Quality", 0u);
|
||||
P_SetUI(p, "DLSS.Hint.Render.Preset.Balanced", 0u);
|
||||
P_SetUI(p, "DLSS.Hint.Render.Preset.Performance", 0u);
|
||||
P_SetUI(p, "DLSS.Hint.Render.Preset.UltraPerformance", 0u);
|
||||
|
||||
// Report Ray Reconstruction & Frame Generation unavailable so games stick to DLSS Super Resolution
|
||||
P_SetI(p, "SuperSamplingDenoising.Available", 0);
|
||||
P_SetI(p, "SuperSamplingDenoising.NeedsUpdatedDriver", 0);
|
||||
P_SetUI(p, "SuperSamplingDenoising.MinDriverVersionMajor", 0);
|
||||
P_SetUI(p, "SuperSamplingDenoising.MinDriverVersionMinor", 0);
|
||||
P_SetI(p, "SuperSamplingDenoising.FeatureInitResult", 0);
|
||||
P_SetI(p, "FrameGeneration.Available", 0);
|
||||
P_SetI(p, "FrameInterpolation.Available", 0);
|
||||
|
||||
// Legacy EParameter aliases (CRITICAL for RDR2 / DLSS 2.x games)
|
||||
P_SetI(p, "#\x01", 1); /* SuperSampling_Available */
|
||||
P_SetI(p, "#\x44", 0); /* OptLevel */
|
||||
P_SetI(p, "#\x45", 0); /* IsDevSnippetBranch */
|
||||
P_SetVP(p, "#\x3e", (void *)dlss_optimal_settings_cb); /* DLSSOptimalSettingsCallback */
|
||||
P_SetF(p, "#\x14", 0.0f); /* Sharpness */
|
||||
P_SetF(p, "#\x2c", 1.0f); /* MV_Scale_X */
|
||||
P_SetF(p, "#\x2d", 1.0f); /* MV_Scale_Y */
|
||||
P_SetF(p, "#\x38", 0.0f); /* MV_Offset_X */
|
||||
P_SetF(p, "#\x39", 0.0f); /* MV_Offset_Y */
|
||||
}
|
||||
|
||||
static WlNgxParam *alloc_param(int owned, int caps) {
|
||||
WlNgxParam *p = (WlNgxParam *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WlNgxParam));
|
||||
if (!p) return NULL;
|
||||
p->vtbl = g_param_vtbl;
|
||||
p->owned = owned;
|
||||
if (caps) populate_cap_params(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
// ---- Global Vulkan & DX12 runtime state ----
|
||||
static CRITICAL_SECTION g_cs;
|
||||
static int g_cs_ready = 0;
|
||||
static WlSeamClient g_vk_seam;
|
||||
static WlSeamClient g_dx12_seam;
|
||||
static WlID3D12DXVKInteropDevice1 *g_dx12_interop = NULL;
|
||||
static void *g_d3d12_dev = NULL;
|
||||
static WlXess3State g_vk_xess3;
|
||||
static WlXess3State g_dx12_xess3;
|
||||
static WlNgxParam *g_cap_param = NULL;
|
||||
static uint32_t g_next_handle_id = 1u;
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
int is_dx12;
|
||||
int has_perf_quality;
|
||||
int needs_reset;
|
||||
uint32_t rw, rh, ow, oh;
|
||||
uint32_t create_flags;
|
||||
uint32_t perf_quality;
|
||||
} WlNgxFeature;
|
||||
|
||||
#define MAX_FEATURES 16
|
||||
static WlNgxFeature g_feats[MAX_FEATURES];
|
||||
|
||||
static void ensure_cs(void) {
|
||||
if (!g_cs_ready) { InitializeCriticalSection(&g_cs); g_cs_ready = 1; }
|
||||
}
|
||||
|
||||
static WlNgxFeature *find_feat(const NVSDK_NGX_Handle *h) {
|
||||
if (!h) return NULL;
|
||||
for (int i = 0; i < MAX_FEATURES; i++) {
|
||||
if (g_feats[i].id == h->Id) return &g_feats[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static WlNgxFeature *create_feat(int is_dx12, WlNgxParam *params, NVSDK_NGX_Handle **out_h) {
|
||||
for (int i = 0; i < MAX_FEATURES; i++) {
|
||||
if (g_feats[i].id == 0) {
|
||||
WlNgxFeature *f = &g_feats[i];
|
||||
memset(f, 0, sizeof *f);
|
||||
f->id = g_next_handle_id++;
|
||||
f->is_dx12 = is_dx12;
|
||||
f->needs_reset = 1;
|
||||
uint64_t v = 0;
|
||||
if (kv_get_u(params, "Width", &v) || kv_get_u(params, "#\x10", &v)) f->rw = (uint32_t)v;
|
||||
if (kv_get_u(params, "Height", &v) || kv_get_u(params, "#\x11", &v)) f->rh = (uint32_t)v;
|
||||
if (kv_get_u(params, "OutWidth", &v) || kv_get_u(params, "#\x12", &v)) f->ow = (uint32_t)v;
|
||||
if (kv_get_u(params, "OutHeight", &v) || kv_get_u(params, "#\x13", &v)) f->oh = (uint32_t)v;
|
||||
if (kv_get_u(params, "DLSS.Feature.Create.Flags", &v)) f->create_flags = (uint32_t)v;
|
||||
if (kv_get_u(params, "PerfQualityValue", &v) || kv_get_u(params, "#\x3f", &v)) {
|
||||
f->perf_quality = (uint32_t)v;
|
||||
f->has_perf_quality = 1;
|
||||
g_last_perf_quality = (uint32_t)v;
|
||||
} else if (g_last_perf_quality != 0xFFFFFFFFu) {
|
||||
f->perf_quality = g_last_perf_quality;
|
||||
f->has_perf_quality = 1;
|
||||
}
|
||||
NVSDK_NGX_Handle *nh = (NVSDK_NGX_Handle *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(NVSDK_NGX_Handle));
|
||||
nh->Id = f->id;
|
||||
if (out_h) *out_h = nh;
|
||||
return f;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void apply_ngx_create_flags(WlFsr4FrameDesc *dst, uint32_t cf) {
|
||||
if (cf & (1u << 0)) dst->flags |= WLFSR4_FLAG_HDR;
|
||||
if (!(cf & (1u << 1)) && cf != 0u) dst->flags |= WLFSR4_FLAG_DISPLAY_RES_MV;
|
||||
if (cf & (1u << 2)) dst->flags |= WLFSR4_FLAG_MV_JITTERED;
|
||||
if (cf & (1u << 3)) dst->flags |= WLFSR4_FLAG_DEPTH_INVERTED;
|
||||
if (cf & (1u << 5)) dst->flags |= WLFSR4_FLAG_SHARPEN;
|
||||
if (cf & (1u << 6)) dst->flags |= WLFSR4_FLAG_AUTO_EXPOSURE;
|
||||
}
|
||||
|
||||
static uint64_t g_app_id = 0x24480451ULL;
|
||||
|
||||
// ---- Generic C parameter helpers & NGX metadata exports ----
|
||||
__declspec(dllexport) const wchar_t *GetNGXResultAsString(NVSDK_NGX_Result r) {
|
||||
return (r == NVSDK_NGX_Result_Success) ? L"NVSDK_NGX_Result_Success" : L"NVSDK_NGX_Result_Fail";
|
||||
}
|
||||
__declspec(dllexport) uint32_t NVSDK_NGX_GetAPIVersion(void) { return 19u; }
|
||||
__declspec(dllexport) uint32_t NVSDK_NGX_GetApplicationId(void) { return (uint32_t)g_app_id; }
|
||||
__declspec(dllexport) uint32_t NVSDK_NGX_GetDriverVersion(void) { return 0x023A0000u; /* 570.00 */ }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_GetDriverVersionEx(uint32_t *versions, uint32_t inCnt, uint32_t *outCnt) {
|
||||
if (!versions && !outCnt) return NVSDK_NGX_Result_FAIL_InvalidParameter;
|
||||
if (outCnt) *outCnt = 2u;
|
||||
if (versions && inCnt >= 1u) {
|
||||
versions[0] = 570u;
|
||||
if (inCnt >= 2u) versions[1] = 0u;
|
||||
}
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) uint32_t NVSDK_NGX_GetGPUArchitecture(void) { return 0x0190u; /* Ada */ }
|
||||
__declspec(dllexport) uint32_t NVSDK_NGX_GetSnippetVersion(void) { return 0x00030700u; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_ProcessCommand(const char *cmd, const char *val, void *unk) { (void)cmd; (void)val; (void)unk; return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_SetInfoCallback(void *cb) { (void)cb; return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_SetTelemetryEvaluateCallback(void *cb) { (void)cb; return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_UpdateFeature(const void *a, uint32_t b) { (void)a; (void)b; return NVSDK_NGX_Result_Success; }
|
||||
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_SetULL(WlNgxParam *p, const char *k, uint64_t v) { P_SetULL(p, k, v); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_SetF(WlNgxParam *p, const char *k, float v) { P_SetF(p, k, v); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_SetD(WlNgxParam *p, const char *k, double v) { P_SetD(p, k, v); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_SetUI(WlNgxParam *p, const char *k, uint32_t v) { P_SetUI(p, k, v); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_SetI(WlNgxParam *p, const char *k, int v) { P_SetI(p, k, v); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_SetD3d11Resource(WlNgxParam *p, const char *k, void *v) { P_SetD11(p, k, v); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_SetD3d12Resource(WlNgxParam *p, const char *k, void *v) { P_SetD12(p, k, v); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_SetVoidPointer(WlNgxParam *p, const char *k, void *v) { P_SetVP(p, k, v); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_GetULL(WlNgxParam *p, const char *k, uint64_t *v) { return P_GetULL(p, k, v); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_GetF(WlNgxParam *p, const char *k, float *v) { return P_GetF(p, k, v); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_GetD(WlNgxParam *p, const char *k, double *v) { return P_GetD(p, k, v); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_GetUI(WlNgxParam *p, const char *k, uint32_t *v) { return P_GetUI(p, k, v); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_GetI(WlNgxParam *p, const char *k, int *v) { return P_GetI(p, k, v); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_GetD3d11Resource(WlNgxParam *p, const char *k, void **v) { return P_GetD11(p, k, v); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_GetD3d12Resource(WlNgxParam *p, const char *k, void **v) { return P_GetD12(p, k, v); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_Parameter_GetVoidPointer(WlNgxParam *p, const char *k, void **v) { return P_GetVP(p, k, v); }
|
||||
|
||||
// ---- VULKAN NGX API (RDR2, DOOM Eternal, etc.) ----
|
||||
static void vk_ngx_attach(VkInstance inst, VkPhysicalDevice phys, VkDevice dev, PFN_wlVkGetDeviceProcAddr gdpa) {
|
||||
ensure_cs();
|
||||
EnterCriticalSection(&g_cs);
|
||||
if (dev && (!g_vk_seam.ready || g_vk_seam.dev != dev)) {
|
||||
if (g_vk_seam.ready) wl_seam_destroy(&g_vk_seam);
|
||||
wl_seam_init(&g_vk_seam, inst, phys, dev, gdpa);
|
||||
}
|
||||
LeaveCriticalSection(&g_cs);
|
||||
}
|
||||
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init(uint64_t appId, const wchar_t *path, VkInstance inst, VkPhysicalDevice phys, VkDevice dev, void *gipa, void *gdpa, void *info, uint32_t ver) {
|
||||
(void)appId; (void)path; (void)gipa; (void)info; (void)ver;
|
||||
vk_ngx_attach(inst, phys, dev, (PFN_wlVkGetDeviceProcAddr)gdpa);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_Ext(uint64_t appId, const wchar_t *path, VkInstance inst, VkPhysicalDevice phys, VkDevice dev, uint32_t ver, void *info) {
|
||||
(void)appId; (void)path; (void)ver; (void)info;
|
||||
vk_ngx_attach(inst, phys, dev, NULL);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_Ext2(uint64_t appId, const wchar_t *path, VkInstance inst, VkPhysicalDevice phys, VkDevice dev, void *gipa, void *gdpa, uint32_t ver, void *info) {
|
||||
(void)appId; (void)path; (void)gipa; (void)ver; (void)info;
|
||||
vk_ngx_attach(inst, phys, dev, (PFN_wlVkGetDeviceProcAddr)gdpa);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_ProjectID(const char *proj, uint32_t eng, const char *engv, const wchar_t *path, VkInstance inst, VkPhysicalDevice phys, VkDevice dev, void *gipa, void *gdpa, uint32_t ver, void *info) {
|
||||
(void)proj; (void)eng; (void)engv; (void)path; (void)gipa; (void)ver; (void)info;
|
||||
vk_ngx_attach(inst, phys, dev, (PFN_wlVkGetDeviceProcAddr)gdpa);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_with_ProjectID(const char *proj, uint32_t eng, const char *engv, const wchar_t *path, VkInstance inst, VkPhysicalDevice phys, VkDevice dev, void *gipa, void *gdpa, void *info, uint32_t ver) {
|
||||
(void)proj; (void)eng; (void)engv; (void)path; (void)gipa; (void)info; (void)ver;
|
||||
vk_ngx_attach(inst, phys, dev, (PFN_wlVkGetDeviceProcAddr)gdpa);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_ProjectID_Ext(const char *proj, uint32_t eng, const char *engv, const wchar_t *path, VkInstance inst, VkPhysicalDevice phys, VkDevice dev, void *gipa, void *gdpa, uint32_t ver, void *info) {
|
||||
(void)proj; (void)eng; (void)engv; (void)path; (void)gipa; (void)ver; (void)info;
|
||||
vk_ngx_attach(inst, phys, dev, (PFN_wlVkGetDeviceProcAddr)gdpa);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_Shutdown(void) {
|
||||
ensure_cs(); EnterCriticalSection(&g_cs);
|
||||
wl_xess3_destroy(&g_vk_xess3);
|
||||
wl_seam_destroy(&g_vk_seam);
|
||||
LeaveCriticalSection(&g_cs);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_Shutdown1(VkDevice dev) {
|
||||
(void)dev;
|
||||
return NVSDK_NGX_VULKAN_Shutdown();
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_RequiredExtensions(uint32_t *instCnt, const char ***instExts, uint32_t *devCnt, const char ***devExts) {
|
||||
// OptiScaler pattern: return 0 required extensions so the game never fails VkDevice creation
|
||||
// if an intermediate Wine/wrapper layer filters NVX names; our Vulkan layer still advertises
|
||||
// VK_NVX_binary_import / VK_NVX_image_view_handle for games that explicitly probe them.
|
||||
if (instCnt) *instCnt = 0;
|
||||
if (instExts) *instExts = NULL;
|
||||
if (devCnt) *devCnt = 0;
|
||||
if (devExts) *devExts = NULL;
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_GetFeatureInstanceExtensionRequirements(const void *info, uint32_t *outCnt, void **outExts) {
|
||||
(void)info;
|
||||
if (outCnt) *outCnt = 0;
|
||||
if (outExts) *outExts = NULL;
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_GetFeatureDeviceExtensionRequirements(VkInstance inst, VkPhysicalDevice pd, const void *info, uint32_t *outCnt, void **outExts) {
|
||||
(void)inst; (void)pd; (void)info;
|
||||
if (outCnt) *outCnt = 0;
|
||||
if (outExts) *outExts = NULL;
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_GetFeatureExtensionRequirements(const void *info, uint32_t *instCnt, void **instExts, uint32_t *devCnt, void **devExts) {
|
||||
(void)info;
|
||||
if (instCnt) *instCnt = 0;
|
||||
if (instExts) *instExts = NULL;
|
||||
if (devCnt) *devCnt = 0;
|
||||
if (devExts) *devExts = NULL;
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
static NVSDK_NGX_Result fill_feature_requirements(const void *info, NVSDK_NGX_FeatureRequirement *outReq) {
|
||||
if (!outReq) return NVSDK_NGX_Result_FAIL_InvalidParameter;
|
||||
memset(outReq, 0, sizeof *outReq);
|
||||
strcpy(outReq->MinOSVersion, "10.0.10240.16384");
|
||||
uint32_t fid = 1u; /* Default SuperSampling */
|
||||
if (info) fid = ((const NVSDK_NGX_FeatureDiscoveryInfoHead *)info)->FeatureID;
|
||||
if (fid == 1u || fid == 3u) {
|
||||
outReq->FeatureSupported = 0u; /* NVSDK_NGX_FeatureSupportResult_Supported */
|
||||
outReq->MinHWArchitecture = 0u;
|
||||
} else {
|
||||
outReq->FeatureSupported = 4u; /* AdapterUnsupported for FG / RayReconstruction */
|
||||
outReq->MinHWArchitecture = 0x0190u;
|
||||
}
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_GetFeatureRequirements(VkInstance inst, VkPhysicalDevice pd, const void *info, NVSDK_NGX_FeatureRequirement *outReq) {
|
||||
(void)inst; (void)pd;
|
||||
return fill_feature_requirements(info, outReq);
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_GetCapabilityParameters(WlNgxParam **outP) {
|
||||
ensure_cs(); EnterCriticalSection(&g_cs);
|
||||
if (!g_cap_param) g_cap_param = alloc_param(0, 1);
|
||||
if (outP) *outP = g_cap_param;
|
||||
LeaveCriticalSection(&g_cs);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_GetParameters(WlNgxParam **outP) { return NVSDK_NGX_VULKAN_GetCapabilityParameters(outP); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_AllocateParameters(WlNgxParam **outP) {
|
||||
if (outP) *outP = alloc_param(1, 0);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_DestroyParameters(WlNgxParam *p) {
|
||||
if (p && p->owned) HeapFree(GetProcessHeap(), 0, p);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_PopulateParameters_Impl(WlNgxParam *p) { populate_cap_params(p); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_GetScratchBufferSize(uint32_t feat, WlNgxParam *p, size_t *sz) { (void)feat; (void)p; if (sz) *sz = 1024 * 1024; return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_SetParameter(const char *k, void *v) { ensure_cs(); if (!g_cap_param) g_cap_param = alloc_param(0, 1); P_SetVP(g_cap_param, k, v); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_GetParameter(const char *k, void **v) { ensure_cs(); if (!g_cap_param) g_cap_param = alloc_param(0, 1); return P_GetVP(g_cap_param, k, v); }
|
||||
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_CreateFeature(VkCommandBuffer cb, uint32_t feat, WlNgxParam *p, NVSDK_NGX_Handle **outH) {
|
||||
(void)cb; (void)feat;
|
||||
ensure_cs(); EnterCriticalSection(&g_cs);
|
||||
create_feat(0, p, outH);
|
||||
LeaveCriticalSection(&g_cs);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_CreateFeature1(VkDevice dev, VkCommandBuffer cb, uint32_t feat, WlNgxParam *p, NVSDK_NGX_Handle **outH) {
|
||||
vk_ngx_attach(NULL, NULL, dev, NULL);
|
||||
return NVSDK_NGX_VULKAN_CreateFeature(cb, feat, p, outH);
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_ReleaseFeature(NVSDK_NGX_Handle *h) {
|
||||
ensure_cs(); EnterCriticalSection(&g_cs);
|
||||
WlNgxFeature *f = find_feat(h);
|
||||
if (f) memset(f, 0, sizeof *f);
|
||||
LeaveCriticalSection(&g_cs);
|
||||
if (h) HeapFree(GetProcessHeap(), 0, h);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
|
||||
static void extract_ngx_vk_res(WlFsr4ImageRef *dst, wl_xess_vk_img_t *ximg, WlNgxParam *p, const char *k1, const char *k2, int is_depth) {
|
||||
memset(dst, 0, sizeof *dst);
|
||||
if (ximg) memset(ximg, 0, sizeof *ximg);
|
||||
void *rp = NULL;
|
||||
if (!kv_get_p(p, k1, &rp) && k2) kv_get_p(p, k2, &rp);
|
||||
if (!rp) return;
|
||||
const NVSDK_NGX_Resource_VK *r = (const NVSDK_NGX_Resource_VK *)rp;
|
||||
if (r->Type == 0) {
|
||||
dst->vk_image = r->Resource.ImageViewInfo.Image;
|
||||
dst->vk_view = r->Resource.ImageViewInfo.ImageView;
|
||||
dst->vk_format = r->Resource.ImageViewInfo.Format;
|
||||
dst->width = r->Resource.ImageViewInfo.Width;
|
||||
dst->height = r->Resource.ImageViewInfo.Height;
|
||||
dst->vk_layout = r->ReadWrite ? 1u : (is_depth ? 4u : 5u); /* GENERAL or SHADER_READ_ONLY */
|
||||
dst->aspect = is_depth ? 2u : 1u;
|
||||
if (ximg) {
|
||||
ximg->imageView = r->Resource.ImageViewInfo.ImageView;
|
||||
ximg->image = r->Resource.ImageViewInfo.Image;
|
||||
ximg->subresourceRange.aspectMask = r->Resource.ImageViewInfo.SubresourceRange.aspectMask ? r->Resource.ImageViewInfo.SubresourceRange.aspectMask : (is_depth ? 2u : 1u);
|
||||
ximg->subresourceRange.baseMipLevel = r->Resource.ImageViewInfo.SubresourceRange.baseMipLevel;
|
||||
ximg->subresourceRange.levelCount = r->Resource.ImageViewInfo.SubresourceRange.levelCount ? r->Resource.ImageViewInfo.SubresourceRange.levelCount : 1u;
|
||||
ximg->subresourceRange.baseArrayLayer = r->Resource.ImageViewInfo.SubresourceRange.baseArrayLayer;
|
||||
ximg->subresourceRange.layerCount = r->Resource.ImageViewInfo.SubresourceRange.layerCount ? r->Resource.ImageViewInfo.SubresourceRange.layerCount : 1u;
|
||||
ximg->format = r->Resource.ImageViewInfo.Format;
|
||||
ximg->width = r->Resource.ImageViewInfo.Width;
|
||||
ximg->height = r->Resource.ImageViewInfo.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_EvaluateFeature(VkCommandBuffer cb, const NVSDK_NGX_Handle *h, WlNgxParam *p, void *cbk) {
|
||||
(void)cbk;
|
||||
if (!cb || !p) return NVSDK_NGX_Result_FAIL_InvalidParameter;
|
||||
ensure_cs();
|
||||
EnterCriticalSection(&g_cs);
|
||||
WlNgxFeature *feat = find_feat(h);
|
||||
int ready = g_vk_seam.ready;
|
||||
int do_reset = 0;
|
||||
uint32_t feat_cf = 0, feat_pq = 0;
|
||||
int feat_has_pq = 0;
|
||||
uint32_t feat_rw = 0, feat_rh = 0, feat_ow = 0, feat_oh = 0;
|
||||
if (feat) {
|
||||
if (feat->needs_reset) { do_reset = 1; feat->needs_reset = 0; }
|
||||
feat_cf = feat->create_flags;
|
||||
feat_pq = feat->perf_quality;
|
||||
feat_has_pq = feat->has_perf_quality;
|
||||
feat_rw = feat->rw; feat_rh = feat->rh; feat_ow = feat->ow; feat_oh = feat->oh;
|
||||
}
|
||||
LeaveCriticalSection(&g_cs);
|
||||
if (!ready) return NVSDK_NGX_Result_Fail;
|
||||
|
||||
WlFsr4FrameDesc f;
|
||||
memset(&f, 0, sizeof f);
|
||||
wl_xess_vk_img_t x_col, x_dep, x_mv, x_out;
|
||||
f.api_source = WLFSR4_API_NGX_VK;
|
||||
extract_ngx_vk_res(&f.color, &x_col, p, "Color", "#\x1e", 0);
|
||||
if (!f.color.vk_image) extract_ngx_vk_res(&f.color, &x_col, p, "__ColorInput", NULL, 0);
|
||||
extract_ngx_vk_res(&f.depth, &x_dep, p, "Depth", "#\x3d", 1);
|
||||
extract_ngx_vk_res(&f.motion, &x_mv, p, "MotionVectors", "#\x27", 0);
|
||||
if (!f.motion.vk_image) extract_ngx_vk_res(&f.motion, &x_mv, p, "__MVecInput", NULL, 0);
|
||||
extract_ngx_vk_res(&f.output, &x_out, p, "Output", "#\x22", 0);
|
||||
if (!f.output.vk_image) extract_ngx_vk_res(&f.output, &x_out, p, "__Output", NULL, 0);
|
||||
|
||||
uint64_t u = 0;
|
||||
f.render_w = kv_get_u(p, "DLSS.Render.Subrect.Dimensions.Width", &u) ? (uint32_t)u
|
||||
: (kv_get_u(p, "#\x2a", &u) ? (uint32_t)u : (f.color.width ? f.color.width : feat_rw));
|
||||
f.render_h = kv_get_u(p, "DLSS.Render.Subrect.Dimensions.Height", &u) ? (uint32_t)u
|
||||
: (kv_get_u(p, "#\x2b", &u) ? (uint32_t)u : (f.color.height ? f.color.height : feat_rh));
|
||||
f.output_w = f.output.width ? f.output.width : (feat_ow ? feat_ow : 1920u);
|
||||
f.output_h = f.output.height ? f.output.height : (feat_oh ? feat_oh : 1080u);
|
||||
|
||||
kv_get_f(p, "Jitter.Offset.X", &f.jitter_x);
|
||||
kv_get_f(p, "Jitter.Offset.Y", &f.jitter_y);
|
||||
f.mv_scale_x = 1.0f; f.mv_scale_y = 1.0f;
|
||||
if (!kv_get_f(p, "MV.Scale.X", &f.mv_scale_x)) kv_get_f(p, "#\x2c", &f.mv_scale_x);
|
||||
if (!kv_get_f(p, "MV.Scale.Y", &f.mv_scale_y)) kv_get_f(p, "#\x2d", &f.mv_scale_y);
|
||||
f.pre_exposure = 1.0f;
|
||||
kv_get_f(p, "DLSS.Pre.Exposure", &f.pre_exposure);
|
||||
if (!kv_get_f(p, "Sharpness", &f.sharpness)) kv_get_f(p, "#\x14", &f.sharpness);
|
||||
if (f.sharpness > 0.01f) f.flags |= WLFSR4_FLAG_SHARPEN;
|
||||
if ((kv_get_u(p, "Reset", &u) && u) || (kv_get_u(p, "#\x25", &u) && u) || do_reset) f.flags |= WLFSR4_FLAG_RESET;
|
||||
apply_ngx_create_flags(&f, feat_cf);
|
||||
|
||||
uint32_t qm = WLFSR4_QUALITY_AUTO;
|
||||
if (kv_get_u(p, "PerfQualityValue", &u)) {
|
||||
g_last_perf_quality = (uint32_t)u;
|
||||
qm = ngx_pq_to_wl_quality((uint32_t)u);
|
||||
} else if (feat_has_pq) {
|
||||
qm = ngx_pq_to_wl_quality(feat_pq);
|
||||
} else if (g_last_perf_quality != 0xFFFFFFFFu) {
|
||||
qm = ngx_pq_to_wl_quality(g_last_perf_quality);
|
||||
} else {
|
||||
qm = infer_quality_from_res(f.render_w, f.output_w);
|
||||
}
|
||||
f.quality_mode = qm;
|
||||
if (qm == WLFSR4_QUALITY_ULTRA_PERF) f.preset_hint = WLFSR4_PRESET_ULTRAPERF;
|
||||
|
||||
int live_en = 1;
|
||||
int live_backend = wl_seam_live_backend(&g_vk_seam, &live_en);
|
||||
if (live_en && live_backend == WL_FSR_BACKEND_XESS3_GPU) {
|
||||
if (wl_xess3_eval_vk(&g_vk_xess3, &g_vk_seam, cb, &f, &x_col, &x_dep, &x_mv, &x_out)) {
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
wl_xess3_tag_fallback(&g_vk_xess3, &f);
|
||||
} else {
|
||||
wl_xess3_on_inactive(&g_vk_xess3);
|
||||
}
|
||||
|
||||
int ok = wl_seam_dispatch_or_blit(&g_vk_seam, cb, &f);
|
||||
return ok ? NVSDK_NGX_Result_Success : NVSDK_NGX_Result_Fail;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_EvaluateFeature_C(VkCommandBuffer cb, const NVSDK_NGX_Handle *h, WlNgxParam *p, void *cbk) {
|
||||
return NVSDK_NGX_VULKAN_EvaluateFeature(cb, h, p, cbk);
|
||||
}
|
||||
|
||||
// ---- D3D12 NGX API (via vkd3d-proton ID3D12DXVKInteropDevice1 -> same Hexagon NPU Vulkan layer!) ----
|
||||
static void dx12_ngx_attach(void *d3d12_dev) {
|
||||
ensure_cs();
|
||||
EnterCriticalSection(&g_cs);
|
||||
if (d3d12_dev) g_d3d12_dev = d3d12_dev;
|
||||
if (!g_dx12_seam.ready && d3d12_dev) {
|
||||
if (!g_dx12_interop) g_dx12_interop = wl_query_vkd3d_interop(d3d12_dev);
|
||||
if (g_dx12_interop) {
|
||||
void *vk_inst = NULL, *vk_phys = NULL, *vk_dev = NULL;
|
||||
if (g_dx12_interop->lpVtbl->GetVulkanHandles(g_dx12_interop, &vk_inst, &vk_phys, &vk_dev) == S_OK && vk_dev) {
|
||||
wl_seam_init(&g_dx12_seam, vk_inst, vk_phys, vk_dev, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&g_cs);
|
||||
}
|
||||
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_Init(uint64_t appId, const wchar_t *path, void *dev, void *info, uint32_t ver) {
|
||||
(void)appId; (void)path; (void)info; (void)ver;
|
||||
dx12_ngx_attach(dev);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_Ext(uint64_t appId, const wchar_t *path, void *dev, uint32_t ver, void *info) {
|
||||
(void)appId; (void)path; (void)ver; (void)info;
|
||||
dx12_ngx_attach(dev);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_ProjectID(const char *proj, uint32_t eng, const char *engv, const wchar_t *path, void *dev, void *info, uint32_t ver) {
|
||||
(void)proj; (void)eng; (void)engv; (void)path; (void)info; (void)ver;
|
||||
dx12_ngx_attach(dev);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_with_ProjectID(const char *proj, uint32_t eng, const char *engv, const wchar_t *path, void *dev, void *info, uint32_t ver) {
|
||||
(void)proj; (void)eng; (void)engv; (void)path; (void)info; (void)ver;
|
||||
dx12_ngx_attach(dev);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_Shutdown(void) {
|
||||
ensure_cs(); EnterCriticalSection(&g_cs);
|
||||
wl_xess3_destroy(&g_dx12_xess3);
|
||||
wl_seam_destroy(&g_dx12_seam);
|
||||
if (g_dx12_interop) { g_dx12_interop->lpVtbl->Release(g_dx12_interop); g_dx12_interop = NULL; }
|
||||
g_d3d12_dev = NULL;
|
||||
LeaveCriticalSection(&g_cs);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_Shutdown1(void *dev) { (void)dev; return NVSDK_NGX_D3D12_Shutdown(); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_GetFeatureRequirements(void *adapter, const void *info, NVSDK_NGX_FeatureRequirement *outReq) {
|
||||
(void)adapter;
|
||||
return fill_feature_requirements(info, outReq);
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_GetCapabilityParameters(WlNgxParam **outP) { return NVSDK_NGX_VULKAN_GetCapabilityParameters(outP); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_GetParameters(WlNgxParam **outP) { return NVSDK_NGX_VULKAN_GetCapabilityParameters(outP); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_AllocateParameters(WlNgxParam **outP) { return NVSDK_NGX_VULKAN_AllocateParameters(outP); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_DestroyParameters(WlNgxParam *p) { return NVSDK_NGX_VULKAN_DestroyParameters(p); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_PopulateParameters_Impl(WlNgxParam *p) { populate_cap_params(p); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_GetScratchBufferSize(uint32_t feat, WlNgxParam *p, size_t *sz) { (void)feat; (void)p; if (sz) *sz = 1024 * 1024; return NVSDK_NGX_Result_Success; }
|
||||
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_CreateFeature(void *cmdList, uint32_t feat, WlNgxParam *p, NVSDK_NGX_Handle **outH) {
|
||||
(void)cmdList; (void)feat;
|
||||
ensure_cs(); EnterCriticalSection(&g_cs);
|
||||
create_feat(1, p, outH);
|
||||
LeaveCriticalSection(&g_cs);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_ReleaseFeature(NVSDK_NGX_Handle *h) { return NVSDK_NGX_VULKAN_ReleaseFeature(h); }
|
||||
|
||||
static void *extract_ngx_dx12_res(WlID3D12DXVKInteropDevice1 *interop, WlFsr4ImageRef *dst, WlNgxParam *p, const char *k1, const char *k2, int is_depth) {
|
||||
memset(dst, 0, sizeof *dst);
|
||||
void *res = NULL;
|
||||
if (!kv_get_p(p, k1, &res) && k2) kv_get_p(p, k2, &res);
|
||||
if (!res || !interop) return res;
|
||||
UINT64 vk_img = 0, off = 0;
|
||||
UINT32 vk_fmt = 0;
|
||||
if (interop->lpVtbl->GetVulkanResourceInfo1(interop, res, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
||||
dst->vk_image = vk_img;
|
||||
dst->vk_format = vk_fmt;
|
||||
dst->vk_layout = is_depth ? 4u : 1u; /* DEPTH_STENCIL_READ_ONLY or GENERAL */
|
||||
dst->aspect = is_depth ? 2u : 1u;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(void *cmdList, const NVSDK_NGX_Handle *h, WlNgxParam *p, void *cbk) {
|
||||
(void)cbk;
|
||||
if (!cmdList || !p) return NVSDK_NGX_Result_FAIL_InvalidParameter;
|
||||
ensure_cs();
|
||||
EnterCriticalSection(&g_cs);
|
||||
WlNgxFeature *feat = find_feat(h);
|
||||
WlID3D12DXVKInteropDevice1 *interop = g_dx12_interop;
|
||||
void *d3d12_dev = g_d3d12_dev;
|
||||
int ready = g_dx12_seam.ready;
|
||||
int do_reset = 0;
|
||||
uint32_t feat_cf = 0, feat_pq = 0;
|
||||
int feat_has_pq = 0;
|
||||
uint32_t feat_rw = 0, feat_rh = 0, feat_ow = 0, feat_oh = 0;
|
||||
if (feat) {
|
||||
if (feat->needs_reset) { do_reset = 1; feat->needs_reset = 0; }
|
||||
feat_cf = feat->create_flags;
|
||||
feat_pq = feat->perf_quality;
|
||||
feat_has_pq = feat->has_perf_quality;
|
||||
feat_rw = feat->rw; feat_rh = feat->rh; feat_ow = feat->ow; feat_oh = feat->oh;
|
||||
}
|
||||
LeaveCriticalSection(&g_cs);
|
||||
if (!ready || !interop) return NVSDK_NGX_Result_Fail;
|
||||
|
||||
WlFsr4FrameDesc f;
|
||||
memset(&f, 0, sizeof f);
|
||||
f.api_source = WLFSR4_API_NGX_DX12;
|
||||
void *res_col = extract_ngx_dx12_res(interop, &f.color, p, "Color", "#\x1e", 0);
|
||||
if (!f.color.vk_image) res_col = extract_ngx_dx12_res(interop, &f.color, p, "__ColorInput", NULL, 0);
|
||||
void *res_dep = extract_ngx_dx12_res(interop, &f.depth, p, "Depth", "#\x3d", 1);
|
||||
void *res_mv = extract_ngx_dx12_res(interop, &f.motion, p, "MotionVectors", "#\x27", 0);
|
||||
if (!f.motion.vk_image) res_mv = extract_ngx_dx12_res(interop, &f.motion, p, "__MVecInput", NULL, 0);
|
||||
void *res_out = extract_ngx_dx12_res(interop, &f.output, p, "Output", "#\x22", 0);
|
||||
if (!f.output.vk_image) res_out = extract_ngx_dx12_res(interop, &f.output, p, "__Output", NULL, 0);
|
||||
|
||||
uint64_t u = 0;
|
||||
f.render_w = kv_get_u(p, "DLSS.Render.Subrect.Dimensions.Width", &u) ? (uint32_t)u
|
||||
: (kv_get_u(p, "#\x2a", &u) ? (uint32_t)u : (feat_rw ? feat_rw : 960u));
|
||||
f.render_h = kv_get_u(p, "DLSS.Render.Subrect.Dimensions.Height", &u) ? (uint32_t)u
|
||||
: (kv_get_u(p, "#\x2b", &u) ? (uint32_t)u : (feat_rh ? feat_rh : 540u));
|
||||
f.output_w = feat_ow ? feat_ow : 1920u;
|
||||
f.output_h = feat_oh ? feat_oh : 1080u;
|
||||
kv_get_f(p, "Jitter.Offset.X", &f.jitter_x);
|
||||
kv_get_f(p, "Jitter.Offset.Y", &f.jitter_y);
|
||||
f.mv_scale_x = 1.0f; f.mv_scale_y = 1.0f;
|
||||
if (!kv_get_f(p, "MV.Scale.X", &f.mv_scale_x)) kv_get_f(p, "#\x2c", &f.mv_scale_x);
|
||||
if (!kv_get_f(p, "MV.Scale.Y", &f.mv_scale_y)) kv_get_f(p, "#\x2d", &f.mv_scale_y);
|
||||
f.pre_exposure = 1.0f;
|
||||
kv_get_f(p, "DLSS.Pre.Exposure", &f.pre_exposure);
|
||||
if (!kv_get_f(p, "Sharpness", &f.sharpness)) kv_get_f(p, "#\x14", &f.sharpness);
|
||||
if (f.sharpness > 0.01f) f.flags |= WLFSR4_FLAG_SHARPEN;
|
||||
if ((kv_get_u(p, "Reset", &u) && u) || (kv_get_u(p, "#\x25", &u) && u) || do_reset) f.flags |= WLFSR4_FLAG_RESET;
|
||||
apply_ngx_create_flags(&f, feat_cf);
|
||||
|
||||
uint32_t qm = WLFSR4_QUALITY_AUTO;
|
||||
if (kv_get_u(p, "PerfQualityValue", &u)) {
|
||||
g_last_perf_quality = (uint32_t)u;
|
||||
qm = ngx_pq_to_wl_quality((uint32_t)u);
|
||||
} else if (feat_has_pq) {
|
||||
qm = ngx_pq_to_wl_quality(feat_pq);
|
||||
} else if (g_last_perf_quality != 0xFFFFFFFFu) {
|
||||
qm = ngx_pq_to_wl_quality(g_last_perf_quality);
|
||||
} else {
|
||||
qm = infer_quality_from_res(f.render_w, f.output_w);
|
||||
}
|
||||
f.quality_mode = qm;
|
||||
if (qm == WLFSR4_QUALITY_ULTRA_PERF) f.preset_hint = WLFSR4_PRESET_ULTRAPERF;
|
||||
|
||||
int live_en = 1;
|
||||
int live_backend = wl_seam_live_backend(&g_dx12_seam, &live_en);
|
||||
if (live_en && live_backend == WL_FSR_BACKEND_XESS3_GPU && d3d12_dev) {
|
||||
if (wl_xess3_eval_d3d12(&g_dx12_xess3, &g_dx12_seam, interop, d3d12_dev, cmdList,
|
||||
&f, res_col, res_dep, res_mv, res_out)) {
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
wl_xess3_tag_fallback(&g_dx12_xess3, &f);
|
||||
} else {
|
||||
wl_xess3_on_inactive(&g_dx12_xess3);
|
||||
}
|
||||
|
||||
void *vk_cb = NULL;
|
||||
int ok = 0;
|
||||
if (interop->lpVtbl->BeginVkCommandBufferInterop(interop, cmdList, &vk_cb) == S_OK && vk_cb) {
|
||||
ok = wl_seam_dispatch_or_blit(&g_dx12_seam, (VkCommandBuffer)vk_cb, &f);
|
||||
interop->lpVtbl->EndVkCommandBufferInterop(interop, cmdList);
|
||||
}
|
||||
return ok ? NVSDK_NGX_Result_Success : NVSDK_NGX_Result_Fail;
|
||||
}
|
||||
|
||||
// ---- D3D11 & CUDA stubs (prevent unresolved symbol crashes on multi-API games) ----
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_Init(uint64_t a, const wchar_t *b, void *c, void *d, uint32_t e) { (void)a;(void)b;(void)c;(void)d;(void)e; return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_Init_Ext(uint64_t a, const wchar_t *b, void *c, uint32_t d, void *e) { (void)a;(void)b;(void)c;(void)d;(void)e; return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_Init_ProjectID(const char *a, uint32_t b, const char *c, const wchar_t *d, void *e, void *f, uint32_t g) { (void)a;(void)b;(void)c;(void)d;(void)e;(void)f;(void)g; return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_Init_with_ProjectID(const char *a, uint32_t b, const char *c, const wchar_t *d, void *e, void *f, uint32_t g) { (void)a;(void)b;(void)c;(void)d;(void)e;(void)f;(void)g; return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_Shutdown(void) { return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_Shutdown1(void *a) { (void)a; return NVSDK_NGX_Result_Success; }
|
||||
// DroidDeck: D3D11 has no path to the Vulkan layer, so it reports DLSS unavailable and games hide it.
|
||||
static void populate_d3d11_cap_params(WlNgxParam *p) {
|
||||
if (!p) return;
|
||||
populate_cap_params(p);
|
||||
P_SetI(p, "SuperSampling.Available", 0);
|
||||
P_SetUI(p, "SuperSampling.FeatureInitResult", NVSDK_NGX_Result_FAIL_FeatureNotSupported);
|
||||
P_SetI(p, "DLSS.Available", 0);
|
||||
P_SetI(p, "#\x01", 0); /* SuperSampling_Available */
|
||||
}
|
||||
static WlNgxParam *g_d3d11_cap_param = NULL;
|
||||
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_GetFeatureRequirements(void *a, const void *b, NVSDK_NGX_FeatureRequirement *c) {
|
||||
(void)a; (void)b;
|
||||
if (!c) return NVSDK_NGX_Result_FAIL_InvalidParameter;
|
||||
memset(c, 0, sizeof *c);
|
||||
strcpy(c->MinOSVersion, "10.0.10240.16384");
|
||||
c->FeatureSupported = 4u; /* NVSDK_NGX_FeatureSupportResult_AdapterUnsupported */
|
||||
c->MinHWArchitecture = 0x0190u;
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_GetCapabilityParameters(WlNgxParam **p) {
|
||||
ensure_cs(); EnterCriticalSection(&g_cs);
|
||||
if (!g_d3d11_cap_param) {
|
||||
g_d3d11_cap_param = alloc_param(0, 0);
|
||||
populate_d3d11_cap_params(g_d3d11_cap_param);
|
||||
}
|
||||
if (p) *p = g_d3d11_cap_param;
|
||||
LeaveCriticalSection(&g_cs);
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_GetParameters(WlNgxParam **p) { return NVSDK_NGX_D3D11_GetCapabilityParameters(p); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_AllocateParameters(WlNgxParam **p) { return NVSDK_NGX_VULKAN_AllocateParameters(p); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_DestroyParameters(WlNgxParam *p) { return NVSDK_NGX_VULKAN_DestroyParameters(p); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_PopulateParameters_Impl(WlNgxParam *p) { populate_d3d11_cap_params(p); return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_GetScratchBufferSize(uint32_t a, WlNgxParam *b, size_t *c) { return NVSDK_NGX_VULKAN_GetScratchBufferSize(a, b, c); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_CreateFeature(void *a, uint32_t b, WlNgxParam *c, NVSDK_NGX_Handle **d) {
|
||||
(void)a; (void)b; (void)c;
|
||||
if (d) *d = NULL;
|
||||
return NVSDK_NGX_Result_FAIL_FeatureNotSupported;
|
||||
}
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_ReleaseFeature(NVSDK_NGX_Handle *h) { return NVSDK_NGX_VULKAN_ReleaseFeature(h); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_EvaluateFeature(void *a, const NVSDK_NGX_Handle *b, WlNgxParam *c, void *d) { (void)a;(void)b;(void)c;(void)d; return NVSDK_NGX_Result_FAIL_FeatureNotSupported; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D11_EvaluateFeature_C(void *a, const NVSDK_NGX_Handle *b, WlNgxParam *c, void *d) { (void)a;(void)b;(void)c;(void)d; return NVSDK_NGX_Result_FAIL_FeatureNotSupported; }
|
||||
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_CUDA_Init(uint64_t a, const wchar_t *b, void *c, uint32_t d) { (void)a;(void)b;(void)c;(void)d; return NVSDK_NGX_Result_FAIL_FeatureNotSupported; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_CUDA_Init_with_ProjectID(const char *a, uint32_t b, const char *c, const wchar_t *d, void *e, uint32_t f) { (void)a;(void)b;(void)c;(void)d;(void)e;(void)f; return NVSDK_NGX_Result_FAIL_FeatureNotSupported; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_CUDA_Shutdown(void) { return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_CUDA_GetCapabilityParameters(WlNgxParam **p) { return NVSDK_NGX_VULKAN_GetCapabilityParameters(p); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_CUDA_GetParameters(WlNgxParam **p) { return NVSDK_NGX_VULKAN_GetCapabilityParameters(p); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_CUDA_AllocateParameters(WlNgxParam **p) { return NVSDK_NGX_VULKAN_AllocateParameters(p); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_CUDA_DestroyParameters(WlNgxParam *p) { return NVSDK_NGX_VULKAN_DestroyParameters(p); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_CUDA_GetScratchBufferSize(uint32_t a, WlNgxParam *b, size_t *c) { return NVSDK_NGX_VULKAN_GetScratchBufferSize(a, b, c); }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_CUDA_CreateFeature(uint32_t a, WlNgxParam *b, NVSDK_NGX_Handle **c) { (void)a;(void)b;(void)c; return NVSDK_NGX_Result_FAIL_FeatureNotSupported; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_CUDA_ReleaseFeature(NVSDK_NGX_Handle *h) { (void)h; return NVSDK_NGX_Result_Success; }
|
||||
__declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_CUDA_EvaluateFeature(const NVSDK_NGX_Handle *a, WlNgxParam *b, void *c) { (void)a;(void)b;(void)c; return NVSDK_NGX_Result_FAIL_FeatureNotSupported; }
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
|
||||
(void)hinst; (void)reserved;
|
||||
if (reason == DLL_PROCESS_ATTACH) {
|
||||
DisableThreadLibraryCalls(hinst);
|
||||
ensure_cs();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,585 @@
|
||||
// DroidDeck: modified from michaelisomer-cyber/Winlator-NeuralScale a0ab6b0f (see README.md).
|
||||
// ARM64EC / FEXCore / Box64 / Wine-safe IAT + GetProcAddress NGX hook engine.
|
||||
// Installed inside nvapi64.dll so that when nvsdk_ngx.lib (inside Cyberpunk 2077's
|
||||
// sl.common.dll, RDR2.exe, etc.) tries to locate, signature-verify, and load
|
||||
// nvngx.dll / _nvngx.dll, it cleanly passes WinVerifyTrust + CryptQueryObject
|
||||
// and loads our C:\windows\system32\_nvngx.dll bridge without touching game folders
|
||||
// or patching executable machine code (100% safe on ARM64EC thunks).
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <stdio.h>
|
||||
#include "dd_env.h"
|
||||
|
||||
#ifndef FILE_ATTRIBUTE_ARCHIVE
|
||||
#define FILE_ATTRIBUTE_ARCHIVE 0x20
|
||||
#endif
|
||||
|
||||
// Minimal WinTrust & Crypt32 definitions (avoid linking wintrust.lib / crypt32.lib)
|
||||
typedef struct WlWintrustFileInfo {
|
||||
DWORD cbStruct;
|
||||
LPCWSTR pcwszFilePath;
|
||||
HANDLE hFile;
|
||||
GUID *pgKnownSubject;
|
||||
} WlWintrustFileInfo;
|
||||
|
||||
typedef struct WlWintrustData {
|
||||
DWORD cbStruct;
|
||||
LPVOID pPolicyCallbackData;
|
||||
LPVOID pSIPClientData;
|
||||
DWORD dwUIChoice;
|
||||
DWORD fdwRevocationChecks;
|
||||
DWORD dwUnionChoice; /* 1 = WTD_CHOICE_FILE */
|
||||
union {
|
||||
WlWintrustFileInfo *pFile;
|
||||
void *pOther;
|
||||
} u;
|
||||
DWORD dwStateAction; /* 1 = VERIFY, 2 = CLOSE */
|
||||
HANDLE hWVTStateData;
|
||||
WCHAR *pwszURLReference;
|
||||
DWORD dwProvFlags;
|
||||
DWORD dwUIContext;
|
||||
void *pSignatureSettings;
|
||||
} WlWintrustData;
|
||||
|
||||
typedef HMODULE (WINAPI *PFN_LoadLibraryW)(LPCWSTR);
|
||||
typedef HMODULE (WINAPI *PFN_LoadLibraryA)(LPCSTR);
|
||||
typedef HMODULE (WINAPI *PFN_LoadLibraryExW)(LPCWSTR, HANDLE, DWORD);
|
||||
typedef HMODULE (WINAPI *PFN_LoadLibraryExA)(LPCSTR, HANDLE, DWORD);
|
||||
typedef FARPROC (WINAPI *PFN_GetProcAddress)(HMODULE, LPCSTR);
|
||||
typedef DWORD (WINAPI *PFN_GetFileAttributesW)(LPCWSTR);
|
||||
typedef BOOL (WINAPI *PFN_GetFileAttributesExW)(LPCWSTR, GET_FILEEX_INFO_LEVELS, LPVOID);
|
||||
typedef HANDLE (WINAPI *PFN_CreateFileW)(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
|
||||
typedef LONG (WINAPI *PFN_WinVerifyTrust)(HWND, GUID *, LPVOID);
|
||||
typedef BOOL (WINAPI *PFN_CryptQueryObject)(DWORD, const void *, DWORD, DWORD, DWORD, DWORD *, DWORD *, DWORD *, void *, void *, const void **);
|
||||
typedef LSTATUS (WINAPI *PFN_RegOpenKeyExW)(HKEY, LPCWSTR, DWORD, REGSAM, PHKEY);
|
||||
typedef LSTATUS (WINAPI *PFN_RegEnumValueW)(HKEY, DWORD, LPWSTR, LPDWORD, LPDWORD, LPDWORD, LPBYTE, LPDWORD);
|
||||
typedef LSTATUS (WINAPI *PFN_RegQueryValueExW)(HKEY, LPCWSTR, LPDWORD, LPDWORD, LPBYTE, LPDWORD);
|
||||
typedef LSTATUS (WINAPI *PFN_RegCloseKey)(HKEY);
|
||||
|
||||
static HMODULE g_wl_self_mod = NULL;
|
||||
static HMODULE g_wl_our_nvngx = NULL;
|
||||
static DWORD g_wl_tls_reent = TLS_OUT_OF_INDEXES;
|
||||
static volatile LONG g_wl_hooks_installed = 0;
|
||||
static CRITICAL_SECTION g_wl_hook_cs;
|
||||
static int g_wl_hook_cs_ready = 0;
|
||||
static WCHAR g_wl_signed_nv_dll[MAX_PATH] = {0};
|
||||
|
||||
static const HKEY k_wl_sig_hkey = (HKEY)(uintptr_t)0xFFFFFFFF13372137ULL;
|
||||
|
||||
static PFN_LoadLibraryW o_LoadLibraryW = NULL;
|
||||
static PFN_LoadLibraryA o_LoadLibraryA = NULL;
|
||||
static PFN_LoadLibraryExW o_LoadLibraryExW = NULL;
|
||||
static PFN_LoadLibraryExA o_LoadLibraryExA = NULL;
|
||||
static PFN_GetProcAddress o_GetProcAddress = NULL;
|
||||
static PFN_GetFileAttributesW o_GetFileAttributesW = NULL;
|
||||
static PFN_GetFileAttributesExW o_GetFileAttributesExW = NULL;
|
||||
static PFN_CreateFileW o_CreateFileW = NULL;
|
||||
static PFN_WinVerifyTrust o_WinVerifyTrust = NULL;
|
||||
static PFN_CryptQueryObject o_CryptQueryObject = NULL;
|
||||
static PFN_RegOpenKeyExW o_RegOpenKeyExW = NULL;
|
||||
static PFN_RegEnumValueW o_RegEnumValueW = NULL;
|
||||
static PFN_RegQueryValueExW o_RegQueryValueExW = NULL;
|
||||
static PFN_RegCloseKey o_RegCloseKey = NULL;
|
||||
|
||||
static int g_wl_log_on = -1;
|
||||
|
||||
static void wl_hook_log(const char *msg) {
|
||||
if (g_wl_log_on < 0) g_wl_log_on = dd_env_is_on("DROIDDECK_UPSCALE_LOG");
|
||||
if (!msg || !g_wl_log_on) return;
|
||||
HANDLE hf = CreateFileA("C:\\windows\\temp\\wl_fsr4_bridge.log",
|
||||
FILE_APPEND_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hf != INVALID_HANDLE_VALUE) {
|
||||
DWORD wr = 0;
|
||||
WriteFile(hf, msg, (DWORD)strlen(msg), &wr, NULL);
|
||||
WriteFile(hf, "\r\n", 2, &wr, NULL);
|
||||
CloseHandle(hf);
|
||||
}
|
||||
}
|
||||
|
||||
static int wl_in_hook(void) {
|
||||
return (g_wl_tls_reent != TLS_OUT_OF_INDEXES) && (TlsGetValue(g_wl_tls_reent) != NULL);
|
||||
}
|
||||
static void wl_enter_hook(void) {
|
||||
if (g_wl_tls_reent != TLS_OUT_OF_INDEXES) TlsSetValue(g_wl_tls_reent, (LPVOID)1);
|
||||
}
|
||||
static void wl_leave_hook(void) {
|
||||
if (g_wl_tls_reent != TLS_OUT_OF_INDEXES) TlsSetValue(g_wl_tls_reent, NULL);
|
||||
}
|
||||
|
||||
static const WCHAR *wl_basename_w(const WCHAR *path) {
|
||||
if (!path) return L"";
|
||||
const WCHAR *last = path;
|
||||
for (const WCHAR *p = path; *p; p++) {
|
||||
if (*p == L'\\' || *p == L'/') last = p + 1;
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
static const char *wl_basename_a(const char *path) {
|
||||
if (!path) return "";
|
||||
const char *last = path;
|
||||
for (const char *p = path; *p; p++) {
|
||||
if (*p == '\\' || *p == '/') last = p + 1;
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
// Matches nvngx.dll or _nvngx.dll (and NOT nvngx_dlss.dll / nvngx_dlssg.dll / nvngx_dlssd.dll)
|
||||
static int wl_is_nvngx_core_w(const WCHAR *path) {
|
||||
const WCHAR *base = wl_basename_w(path);
|
||||
return _wcsicmp(base, L"nvngx.dll") == 0 ||
|
||||
_wcsicmp(base, L"_nvngx.dll") == 0 ||
|
||||
_wcsicmp(base, L"nvngx") == 0 ||
|
||||
_wcsicmp(base, L"_nvngx") == 0;
|
||||
}
|
||||
|
||||
static int wl_is_nvngx_core_a(const char *path) {
|
||||
const char *base = wl_basename_a(path);
|
||||
return _stricmp(base, "nvngx.dll") == 0 ||
|
||||
_stricmp(base, "_nvngx.dll") == 0 ||
|
||||
_stricmp(base, "nvngx") == 0 ||
|
||||
_stricmp(base, "_nvngx") == 0;
|
||||
}
|
||||
|
||||
static int wl_is_sig_target_w(const WCHAR *path) {
|
||||
if (!path) return 0;
|
||||
const WCHAR *base = wl_basename_w(path);
|
||||
if (wl_is_nvngx_core_w(base)) return 1;
|
||||
if (_wcsnicmp(base, L"amd_fidelityfx", 14) == 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HMODULE wl_load_our_nvngx(void) {
|
||||
if (g_wl_our_nvngx) return g_wl_our_nvngx;
|
||||
if (!o_LoadLibraryW) return NULL;
|
||||
wl_enter_hook();
|
||||
HMODULE h = o_LoadLibraryW(L"C:\\windows\\system32\\_nvngx.dll");
|
||||
if (!h) h = o_LoadLibraryW(L"C:\\windows\\system32\\nvngx.dll");
|
||||
wl_leave_hook();
|
||||
if (h) g_wl_our_nvngx = h;
|
||||
return h;
|
||||
}
|
||||
|
||||
static void wl_find_signed_nv_dll(void) {
|
||||
if (g_wl_signed_nv_dll[0]) return;
|
||||
WCHAR exe_dir[MAX_PATH] = {0};
|
||||
DWORD n = GetModuleFileNameW(NULL, exe_dir, MAX_PATH);
|
||||
if (n == 0 || n >= MAX_PATH) return;
|
||||
for (int i = (int)n - 1; i >= 0; i--) {
|
||||
if (exe_dir[i] == L'\\' || exe_dir[i] == L'/') {
|
||||
exe_dir[i + 1] = L'\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
static const WCHAR *const k_candidates[] = {
|
||||
L"nvngx_dlss.dll",
|
||||
L"sl.interposer.dll",
|
||||
L"sl.common.dll",
|
||||
L"sl.dlss.dll",
|
||||
L"nvngx_dlssg.dll",
|
||||
};
|
||||
PFN_GetFileAttributesW fnAttr = o_GetFileAttributesW ? o_GetFileAttributesW : GetFileAttributesW;
|
||||
for (size_t i = 0; i < sizeof(k_candidates) / sizeof(k_candidates[0]); i++) {
|
||||
WCHAR cand[MAX_PATH] = {0};
|
||||
_snwprintf(cand, MAX_PATH - 1, L"%ls%ls", exe_dir, k_candidates[i]);
|
||||
DWORD attr = fnAttr(cand);
|
||||
if (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||
wcsncpy(g_wl_signed_nv_dll, cand, MAX_PATH - 1);
|
||||
char logbuf[320];
|
||||
snprintf(logbuf, sizeof logbuf, "[nvapi] Found genuine NVIDIA-signed cert donor: %ls", k_candidates[i]);
|
||||
wl_hook_log(logbuf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void wl_patch_module_iat(HMODULE mod);
|
||||
|
||||
// ---- Hook implementations ----
|
||||
static HMODULE WINAPI hk_LoadLibraryW(LPCWSTR lpName) {
|
||||
if (!wl_in_hook() && lpName && wl_is_nvngx_core_w(lpName)) {
|
||||
wl_hook_log("[nvapi] hk_LoadLibraryW intercepted nvngx -> _nvngx.dll");
|
||||
return wl_load_our_nvngx();
|
||||
}
|
||||
HMODULE h = o_LoadLibraryW ? o_LoadLibraryW(lpName) : NULL;
|
||||
if (h && !wl_in_hook()) {
|
||||
wl_enter_hook();
|
||||
wl_patch_module_iat(h);
|
||||
wl_leave_hook();
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
static HMODULE WINAPI hk_LoadLibraryA(LPCSTR lpName) {
|
||||
if (!wl_in_hook() && lpName && wl_is_nvngx_core_a(lpName)) {
|
||||
wl_hook_log("[nvapi] hk_LoadLibraryA intercepted nvngx -> _nvngx.dll");
|
||||
return wl_load_our_nvngx();
|
||||
}
|
||||
HMODULE h = o_LoadLibraryA ? o_LoadLibraryA(lpName) : NULL;
|
||||
if (h && !wl_in_hook()) {
|
||||
wl_enter_hook();
|
||||
wl_patch_module_iat(h);
|
||||
wl_leave_hook();
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
static HMODULE WINAPI hk_LoadLibraryExW(LPCWSTR lpName, HANDLE hFile, DWORD dwFlags) {
|
||||
if (!wl_in_hook() && lpName && wl_is_nvngx_core_w(lpName) &&
|
||||
!(dwFlags & (LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))) {
|
||||
wl_hook_log("[nvapi] hk_LoadLibraryExW intercepted nvngx -> _nvngx.dll");
|
||||
return wl_load_our_nvngx();
|
||||
}
|
||||
HMODULE h = o_LoadLibraryExW ? o_LoadLibraryExW(lpName, hFile, dwFlags) : NULL;
|
||||
if (h && !wl_in_hook() &&
|
||||
!(dwFlags & (LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))) {
|
||||
wl_enter_hook();
|
||||
wl_patch_module_iat(h);
|
||||
wl_leave_hook();
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
static HMODULE WINAPI hk_LoadLibraryExA(LPCSTR lpName, HANDLE hFile, DWORD dwFlags) {
|
||||
if (!wl_in_hook() && lpName && wl_is_nvngx_core_a(lpName) &&
|
||||
!(dwFlags & (LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))) {
|
||||
wl_hook_log("[nvapi] hk_LoadLibraryExA intercepted nvngx -> _nvngx.dll");
|
||||
return wl_load_our_nvngx();
|
||||
}
|
||||
HMODULE h = o_LoadLibraryExA ? o_LoadLibraryExA(lpName, hFile, dwFlags) : NULL;
|
||||
if (h && !wl_in_hook() &&
|
||||
!(dwFlags & (LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))) {
|
||||
wl_enter_hook();
|
||||
wl_patch_module_iat(h);
|
||||
wl_leave_hook();
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
static DWORD WINAPI hk_GetFileAttributesW(LPCWSTR lpFileName) {
|
||||
if (!wl_in_hook() && lpFileName && wl_is_nvngx_core_w(lpFileName)) {
|
||||
return FILE_ATTRIBUTE_ARCHIVE;
|
||||
}
|
||||
return o_GetFileAttributesW ? o_GetFileAttributesW(lpFileName) : INVALID_FILE_ATTRIBUTES;
|
||||
}
|
||||
|
||||
static BOOL WINAPI hk_GetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInfo) {
|
||||
if (!wl_in_hook() && lpFileName && wl_is_nvngx_core_w(lpFileName)) {
|
||||
const WCHAR *target = g_wl_signed_nv_dll[0] ? g_wl_signed_nv_dll : L"C:\\windows\\system32\\_nvngx.dll";
|
||||
if (o_GetFileAttributesExW) return o_GetFileAttributesExW(target, fInfoLevelId, lpFileInfo);
|
||||
}
|
||||
return o_GetFileAttributesExW ? o_GetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInfo) : FALSE;
|
||||
}
|
||||
|
||||
static HANDLE WINAPI hk_CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
|
||||
LPSECURITY_ATTRIBUTES lpSec, DWORD dwCreation, DWORD dwFlags, HANDLE hTmpl) {
|
||||
if (!wl_in_hook() && lpFileName && wl_is_nvngx_core_w(lpFileName) &&
|
||||
!(dwDesiredAccess & GENERIC_WRITE)) {
|
||||
const WCHAR *target = g_wl_signed_nv_dll[0] ? g_wl_signed_nv_dll : L"C:\\windows\\system32\\_nvngx.dll";
|
||||
return o_CreateFileW(target, dwDesiredAccess, dwShareMode, lpSec, dwCreation, dwFlags, hTmpl);
|
||||
}
|
||||
return o_CreateFileW ? o_CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSec, dwCreation, dwFlags, hTmpl)
|
||||
: INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
static LONG WINAPI hk_WinVerifyTrust(HWND hwnd, GUID *pgActionID, LPVOID pWVTData) {
|
||||
if (!wl_in_hook() && pWVTData) {
|
||||
WlWintrustData *data = (WlWintrustData *)pWVTData;
|
||||
if (data->dwUnionChoice == 1u && data->u.pFile && data->u.pFile->pcwszFilePath &&
|
||||
wl_is_sig_target_w(data->u.pFile->pcwszFilePath)) {
|
||||
wl_hook_log("[nvapi] hk_WinVerifyTrust -> ERROR_SUCCESS for nvngx");
|
||||
if (data->dwStateAction == 1u && g_wl_signed_nv_dll[0] && o_WinVerifyTrust) {
|
||||
WlWintrustData copy = *data;
|
||||
WlWintrustFileInfo fcopy = *data->u.pFile;
|
||||
fcopy.pcwszFilePath = g_wl_signed_nv_dll;
|
||||
copy.u.pFile = &fcopy;
|
||||
wl_enter_hook();
|
||||
LONG r = o_WinVerifyTrust(hwnd, pgActionID, ©);
|
||||
wl_leave_hook();
|
||||
data->hWVTStateData = copy.hWVTStateData;
|
||||
if (r == ERROR_SUCCESS) return ERROR_SUCCESS;
|
||||
}
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
if (!o_WinVerifyTrust) {
|
||||
HMODULE hw = o_LoadLibraryW ? o_LoadLibraryW(L"wintrust.dll") : NULL;
|
||||
if (hw && o_GetProcAddress) o_WinVerifyTrust = (PFN_WinVerifyTrust)(void *)o_GetProcAddress(hw, "WinVerifyTrust");
|
||||
}
|
||||
return o_WinVerifyTrust ? o_WinVerifyTrust(hwnd, pgActionID, pWVTData) : ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static BOOL WINAPI hk_CryptQueryObject(DWORD dwObjectType, const void *pvObject, DWORD dwExpectedContent,
|
||||
DWORD dwExpectedFormat, DWORD dwFlags, DWORD *pdwEncoding,
|
||||
DWORD *pdwContent, DWORD *pdwFormat, void *phCertStore,
|
||||
void *phMsg, const void **ppvContext) {
|
||||
if (!o_CryptQueryObject) {
|
||||
HMODULE hc = o_LoadLibraryW ? o_LoadLibraryW(L"crypt32.dll") : NULL;
|
||||
if (hc && o_GetProcAddress) o_CryptQueryObject = (PFN_CryptQueryObject)(void *)o_GetProcAddress(hc, "CryptQueryObject");
|
||||
}
|
||||
if (!o_CryptQueryObject) return FALSE;
|
||||
if (!wl_in_hook() && dwObjectType == 1u /* CERT_QUERY_OBJECT_FILE */ && pvObject) {
|
||||
const WCHAR *wpath = (const WCHAR *)pvObject;
|
||||
if (wl_is_sig_target_w(wpath) && g_wl_signed_nv_dll[0]) {
|
||||
wl_hook_log("[nvapi] hk_CryptQueryObject redirected nvngx -> signed NVIDIA donor");
|
||||
return o_CryptQueryObject(dwObjectType, g_wl_signed_nv_dll, dwExpectedContent, dwExpectedFormat,
|
||||
dwFlags, pdwEncoding, pdwContent, pdwFormat, phCertStore, phMsg, ppvContext);
|
||||
}
|
||||
}
|
||||
return o_CryptQueryObject(dwObjectType, pvObject, dwExpectedContent, dwExpectedFormat,
|
||||
dwFlags, pdwEncoding, pdwContent, pdwFormat, phCertStore, phMsg, ppvContext);
|
||||
}
|
||||
|
||||
static LSTATUS WINAPI hk_RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult) {
|
||||
if (!wl_in_hook() && hKey == k_wl_sig_hkey && lpSubKey && phkResult) {
|
||||
// Child subkey opened relative to our synthetic signature-override key (e.g. NGXCore):
|
||||
// resolve against real HKLM\SOFTWARE\NVIDIA Corporation\Global\<subkey>
|
||||
WCHAR full[256];
|
||||
_snwprintf(full, 255, L"SOFTWARE\\NVIDIA Corporation\\Global\\%ls", lpSubKey);
|
||||
full[255] = L'\0';
|
||||
return o_RegOpenKeyExW ? o_RegOpenKeyExW(HKEY_LOCAL_MACHINE, full, ulOptions, samDesired, phkResult)
|
||||
: ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
if (!wl_in_hook() && lpSubKey && phkResult &&
|
||||
(_wcsicmp(lpSubKey, L"SOFTWARE\\NVIDIA Corporation\\Global") == 0 ||
|
||||
_wcsicmp(lpSubKey, L"SYSTEM\\ControlSet001\\Services\\nvlddmkm") == 0 ||
|
||||
_wcsicmp(lpSubKey, L"SYSTEM\\CurrentControlSet\\Services\\nvlddmkm") == 0)) {
|
||||
*phkResult = k_wl_sig_hkey;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
return o_RegOpenKeyExW ? o_RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult) : ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
static LSTATUS WINAPI hk_RegEnumValueW(HKEY hKey, DWORD dwIndex, LPWSTR lpValueName, LPDWORD lpcchValueName,
|
||||
LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) {
|
||||
if (hKey == k_wl_sig_hkey) {
|
||||
if (dwIndex != 0) return ERROR_NO_MORE_ITEMS;
|
||||
static const WCHAR k_guid[] = L"{41FCC608-8496-4DEF-B43E-7D9BD675A6FF}";
|
||||
DWORD len = (DWORD)wcslen(k_guid);
|
||||
if (!lpValueName || !lpcchValueName || !lpData || !lpcbData) return ERROR_INVALID_PARAMETER;
|
||||
if (*lpcchValueName <= len) { *lpcchValueName = len + 1; return ERROR_MORE_DATA; }
|
||||
memcpy(lpValueName, k_guid, (len + 1) * sizeof(WCHAR));
|
||||
*lpcchValueName = len;
|
||||
if (lpType) *lpType = REG_BINARY;
|
||||
if (*lpcbData < 1) { *lpcbData = 1; return ERROR_MORE_DATA; }
|
||||
lpData[0] = 0x01;
|
||||
*lpcbData = 1;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
return o_RegEnumValueW ? o_RegEnumValueW(hKey, dwIndex, lpValueName, lpcchValueName, lpReserved, lpType, lpData, lpcbData)
|
||||
: ERROR_NO_MORE_ITEMS;
|
||||
}
|
||||
|
||||
static LSTATUS WINAPI hk_RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved,
|
||||
LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) {
|
||||
if (hKey == k_wl_sig_hkey) {
|
||||
if (lpValueName && _wcsicmp(lpValueName, L"{41FCC608-8496-4DEF-B43E-7D9BD675A6FF}") == 0) {
|
||||
if (lpType) *lpType = REG_BINARY;
|
||||
if (!lpcbData) return ERROR_SUCCESS;
|
||||
if (!lpData) { *lpcbData = 1; return ERROR_SUCCESS; }
|
||||
if (*lpcbData < 1) { *lpcbData = 1; return ERROR_MORE_DATA; }
|
||||
lpData[0] = 0x01;
|
||||
*lpcbData = 1;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
return ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
return o_RegQueryValueExW ? o_RegQueryValueExW(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData)
|
||||
: ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
static LSTATUS WINAPI hk_RegCloseKey(HKEY hKey) {
|
||||
if (hKey == k_wl_sig_hkey) return ERROR_SUCCESS;
|
||||
return o_RegCloseKey ? o_RegCloseKey(hKey) : ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static FARPROC WINAPI hk_GetProcAddress(HMODULE hMod, LPCSTR lpProcName) {
|
||||
FARPROC orig = o_GetProcAddress ? o_GetProcAddress(hMod, lpProcName) : NULL;
|
||||
if (!orig || wl_in_hook() || !lpProcName || ((uintptr_t)lpProcName < 0x10000u)) return orig;
|
||||
|
||||
if (strcmp(lpProcName, "WinVerifyTrust") == 0) {
|
||||
if (!o_WinVerifyTrust) o_WinVerifyTrust = (PFN_WinVerifyTrust)(void *)orig;
|
||||
return (FARPROC)(void *)hk_WinVerifyTrust;
|
||||
}
|
||||
if (strcmp(lpProcName, "CryptQueryObject") == 0) {
|
||||
if (!o_CryptQueryObject) o_CryptQueryObject = (PFN_CryptQueryObject)(void *)orig;
|
||||
return (FARPROC)(void *)hk_CryptQueryObject;
|
||||
}
|
||||
if (strcmp(lpProcName, "LoadLibraryW") == 0) return (FARPROC)(void *)hk_LoadLibraryW;
|
||||
if (strcmp(lpProcName, "LoadLibraryA") == 0) return (FARPROC)(void *)hk_LoadLibraryA;
|
||||
if (strcmp(lpProcName, "LoadLibraryExW") == 0) return (FARPROC)(void *)hk_LoadLibraryExW;
|
||||
if (strcmp(lpProcName, "LoadLibraryExA") == 0) return (FARPROC)(void *)hk_LoadLibraryExA;
|
||||
if (strcmp(lpProcName, "GetFileAttributesW") == 0) return (FARPROC)(void *)hk_GetFileAttributesW;
|
||||
if (strcmp(lpProcName, "GetFileAttributesExW") == 0) return (FARPROC)(void *)hk_GetFileAttributesExW;
|
||||
if (strcmp(lpProcName, "CreateFileW") == 0) return (FARPROC)(void *)hk_CreateFileW;
|
||||
if (strcmp(lpProcName, "RegOpenKeyExW") == 0) return (FARPROC)(void *)hk_RegOpenKeyExW;
|
||||
if (strcmp(lpProcName, "RegEnumValueW") == 0) return (FARPROC)(void *)hk_RegEnumValueW;
|
||||
if (strcmp(lpProcName, "RegQueryValueExW") == 0) return (FARPROC)(void *)hk_RegQueryValueExW;
|
||||
if (strcmp(lpProcName, "RegCloseKey") == 0) return (FARPROC)(void *)hk_RegCloseKey;
|
||||
return orig;
|
||||
}
|
||||
|
||||
static int wl_should_skip_module(HMODULE mod) {
|
||||
if (!mod || mod == g_wl_self_mod || mod == g_wl_our_nvngx) return 1;
|
||||
WCHAR path[MAX_PATH] = {0};
|
||||
DWORD n = GetModuleFileNameW(mod, path, MAX_PATH);
|
||||
if (n == 0) return 1;
|
||||
const WCHAR *base = wl_basename_w(path);
|
||||
// Never patch core OS / Wine system DLLs to prevent recursion or loader side-effects
|
||||
if (_wcsicmp(base, L"ntdll.dll") == 0 ||
|
||||
_wcsicmp(base, L"kernel32.dll") == 0 ||
|
||||
_wcsicmp(base, L"kernelbase.dll") == 0 ||
|
||||
_wcsicmp(base, L"advapi32.dll") == 0 ||
|
||||
_wcsicmp(base, L"sechost.dll") == 0 ||
|
||||
_wcsicmp(base, L"wintrust.dll") == 0 ||
|
||||
_wcsicmp(base, L"crypt32.dll") == 0 ||
|
||||
_wcsicmp(base, L"ucrtbase.dll") == 0 ||
|
||||
_wcsicmp(base, L"msvcrt.dll") == 0 ||
|
||||
_wcsicmp(base, L"nvapi64.dll") == 0 ||
|
||||
_wcsicmp(base, L"_nvngx.dll") == 0 ||
|
||||
_wcsicmp(base, L"nvngx.dll") == 0 ||
|
||||
_wcsicmp(base, L"dxgi.dll") == 0 ||
|
||||
_wcsicmp(base, L"d3d12.dll") == 0 ||
|
||||
_wcsicmp(base, L"d3d12core.dll") == 0 ||
|
||||
_wcsicmp(base, L"d3d11.dll") == 0 ||
|
||||
_wcsicmp(base, L"vulkan-1.dll") == 0 ||
|
||||
_wcsicmp(base, L"winevulkan.dll") == 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *wl_hook_for_import(const char *funcName) {
|
||||
if (!funcName) return NULL;
|
||||
if (strcmp(funcName, "LoadLibraryW") == 0) return (void *)hk_LoadLibraryW;
|
||||
if (strcmp(funcName, "LoadLibraryA") == 0) return (void *)hk_LoadLibraryA;
|
||||
if (strcmp(funcName, "LoadLibraryExW") == 0) return (void *)hk_LoadLibraryExW;
|
||||
if (strcmp(funcName, "LoadLibraryExA") == 0) return (void *)hk_LoadLibraryExA;
|
||||
if (strcmp(funcName, "GetProcAddress") == 0) return (void *)hk_GetProcAddress;
|
||||
if (strcmp(funcName, "GetFileAttributesW") == 0) return (void *)hk_GetFileAttributesW;
|
||||
if (strcmp(funcName, "GetFileAttributesExW") == 0) return (void *)hk_GetFileAttributesExW;
|
||||
if (strcmp(funcName, "CreateFileW") == 0) return (void *)hk_CreateFileW;
|
||||
if (strcmp(funcName, "WinVerifyTrust") == 0) return (void *)hk_WinVerifyTrust;
|
||||
if (strcmp(funcName, "CryptQueryObject") == 0) return (void *)hk_CryptQueryObject;
|
||||
if (strcmp(funcName, "RegOpenKeyExW") == 0) return (void *)hk_RegOpenKeyExW;
|
||||
if (strcmp(funcName, "RegEnumValueW") == 0) return (void *)hk_RegEnumValueW;
|
||||
if (strcmp(funcName, "RegQueryValueExW") == 0) return (void *)hk_RegQueryValueExW;
|
||||
if (strcmp(funcName, "RegCloseKey") == 0) return (void *)hk_RegCloseKey;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void wl_patch_module_iat(HMODULE mod) {
|
||||
if (wl_should_skip_module(mod)) return;
|
||||
uint8_t *base = (uint8_t *)mod;
|
||||
IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *)base;
|
||||
if (IsBadReadPtr(dos, sizeof *dos) || dos->e_magic != IMAGE_DOS_SIGNATURE) return;
|
||||
IMAGE_NT_HEADERS *nt = (IMAGE_NT_HEADERS *)(base + dos->e_lfanew);
|
||||
if (IsBadReadPtr(nt, sizeof *nt) || nt->Signature != IMAGE_NT_SIGNATURE) return;
|
||||
|
||||
IMAGE_DATA_DIRECTORY impDir = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
|
||||
if (!impDir.VirtualAddress || !impDir.Size) return;
|
||||
IMAGE_IMPORT_DESCRIPTOR *desc = (IMAGE_IMPORT_DESCRIPTOR *)(base + impDir.VirtualAddress);
|
||||
|
||||
for (; !IsBadReadPtr(desc, sizeof *desc) && desc->Name != 0; desc++) {
|
||||
if (!desc->OriginalFirstThunk || !desc->FirstThunk) continue;
|
||||
IMAGE_THUNK_DATA *origThunk = (IMAGE_THUNK_DATA *)(base + desc->OriginalFirstThunk);
|
||||
IMAGE_THUNK_DATA *iatThunk = (IMAGE_THUNK_DATA *)(base + desc->FirstThunk);
|
||||
for (; origThunk->u1.AddressOfData != 0; origThunk++, iatThunk++) {
|
||||
if (IMAGE_SNAP_BY_ORDINAL(origThunk->u1.Ordinal)) continue;
|
||||
IMAGE_IMPORT_BY_NAME *ibn = (IMAGE_IMPORT_BY_NAME *)(base + origThunk->u1.AddressOfData);
|
||||
void *hookFn = wl_hook_for_import((const char *)ibn->Name);
|
||||
if (!hookFn) continue;
|
||||
void **slot = (void **)&iatThunk->u1.Function;
|
||||
if (*slot == hookFn) continue;
|
||||
DWORD oldProt = 0;
|
||||
if (VirtualProtect(slot, sizeof(void *), PAGE_READWRITE, &oldProt)) {
|
||||
*slot = hookFn;
|
||||
VirtualProtect(slot, sizeof(void *), oldProt, &oldProt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int wl_is_arxan_protected_exe(void) {
|
||||
WCHAR exePath[MAX_PATH] = {0};
|
||||
if (!GetModuleFileNameW(NULL, exePath, MAX_PATH)) return 0;
|
||||
const WCHAR *base = wl_basename_w(exePath);
|
||||
return _wcsicmp(base, L"rdr2.exe") == 0 ||
|
||||
_wcsicmp(base, L"playrdr2.exe") == 0 ||
|
||||
_wcsicmp(base, L"gta5.exe") == 0;
|
||||
}
|
||||
|
||||
static void wl_install_ngx_hooks_once(void) {
|
||||
if (InterlockedCompareExchange(&g_wl_hooks_installed, 1, 0) != 0) return;
|
||||
if (!dd_env_is_on("DROIDDECK_UPSCALE_SIGFIX")) return;
|
||||
if (!g_wl_hook_cs_ready) { InitializeCriticalSection(&g_wl_hook_cs); g_wl_hook_cs_ready = 1; }
|
||||
g_wl_tls_reent = TlsAlloc();
|
||||
|
||||
// RDR2 uses Arxan anti-tamper which terminates the game right after the loading screen
|
||||
// if its executable .text or IAT is modified. Rely cleanly on NGXCore registry keys +
|
||||
// EnableSignatureOverride ({41FCC608-...}=01) without touching RDR2.exe memory!
|
||||
if (wl_is_arxan_protected_exe()) {
|
||||
wl_hook_log("[nvapi] Arxan-protected game detected (RDR2) — skipping IAT/.text patching");
|
||||
return;
|
||||
}
|
||||
|
||||
HMODULE hK32 = GetModuleHandleA("kernel32.dll");
|
||||
HMODULE hAdv = GetModuleHandleA("advapi32.dll");
|
||||
if (!hAdv) hAdv = LoadLibraryA("advapi32.dll");
|
||||
HMODULE hWt = GetModuleHandleA("wintrust.dll");
|
||||
HMODULE hCr = GetModuleHandleA("crypt32.dll");
|
||||
|
||||
if (hK32) {
|
||||
o_LoadLibraryW = (PFN_LoadLibraryW)(void *)GetProcAddress(hK32, "LoadLibraryW");
|
||||
o_LoadLibraryA = (PFN_LoadLibraryA)(void *)GetProcAddress(hK32, "LoadLibraryA");
|
||||
o_LoadLibraryExW = (PFN_LoadLibraryExW)(void *)GetProcAddress(hK32, "LoadLibraryExW");
|
||||
o_LoadLibraryExA = (PFN_LoadLibraryExA)(void *)GetProcAddress(hK32, "LoadLibraryExA");
|
||||
o_GetProcAddress = (PFN_GetProcAddress)(void *)GetProcAddress(hK32, "GetProcAddress");
|
||||
o_GetFileAttributesW = (PFN_GetFileAttributesW)(void *)GetProcAddress(hK32, "GetFileAttributesW");
|
||||
o_GetFileAttributesExW = (PFN_GetFileAttributesExW)(void *)GetProcAddress(hK32, "GetFileAttributesExW");
|
||||
o_CreateFileW = (PFN_CreateFileW)(void *)GetProcAddress(hK32, "CreateFileW");
|
||||
}
|
||||
if (hAdv) {
|
||||
o_RegOpenKeyExW = (PFN_RegOpenKeyExW)(void *)GetProcAddress(hAdv, "RegOpenKeyExW");
|
||||
o_RegEnumValueW = (PFN_RegEnumValueW)(void *)GetProcAddress(hAdv, "RegEnumValueW");
|
||||
o_RegQueryValueExW = (PFN_RegQueryValueExW)(void *)GetProcAddress(hAdv, "RegQueryValueExW");
|
||||
o_RegCloseKey = (PFN_RegCloseKey)(void *)GetProcAddress(hAdv, "RegCloseKey");
|
||||
}
|
||||
if (hWt) o_WinVerifyTrust = (PFN_WinVerifyTrust)(void *)GetProcAddress(hWt, "WinVerifyTrust");
|
||||
if (hCr) o_CryptQueryObject = (PFN_CryptQueryObject)(void *)GetProcAddress(hCr, "CryptQueryObject");
|
||||
|
||||
wl_enter_hook();
|
||||
wl_find_signed_nv_dll();
|
||||
|
||||
int patched = 0;
|
||||
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
|
||||
if (snap != INVALID_HANDLE_VALUE) {
|
||||
MODULEENTRY32W me;
|
||||
memset(&me, 0, sizeof me);
|
||||
me.dwSize = sizeof me;
|
||||
if (Module32FirstW(snap, &me)) {
|
||||
do {
|
||||
if (!wl_should_skip_module(me.hModule)) {
|
||||
wl_patch_module_iat(me.hModule);
|
||||
patched++;
|
||||
}
|
||||
} while (Module32NextW(snap, &me));
|
||||
}
|
||||
CloseHandle(snap);
|
||||
} else {
|
||||
wl_patch_module_iat(GetModuleHandleW(NULL));
|
||||
patched = 1;
|
||||
}
|
||||
wl_leave_hook();
|
||||
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof buf, "[nvapi] Installed ARM64EC-safe NGX IAT hooks on %d modules", patched);
|
||||
wl_hook_log(buf);
|
||||
}
|
||||
@@ -0,0 +1,576 @@
|
||||
// DroidDeck: modified from michaelisomer-cyber/Winlator-NeuralScale a0ab6b0f (see README.md).
|
||||
// Full OptiScaler/fakenvapi-parity nvapi64.dll shim for Winlator Ludashi FSR 4 NPU.
|
||||
// - Dynamically queries DXGI Adapter 0 LUID so NVIDIA Streamline (Cyberpunk 2077, etc.)
|
||||
// matches the DXGI adapter to our spoofed NVIDIA GeForce RTX 2060 (Turing TU106).
|
||||
// - Implements all core NVAPI interfaces required by RDR2 (Vulkan/DX12), Cyberpunk 2077
|
||||
// (Streamline sl.common / sl.dlss), Unreal Engine, and DX11/DX12/Vulkan DLSS titles.
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "wl_ngx_hooks.h"
|
||||
|
||||
typedef int32_t NvAPI_Status;
|
||||
#define NVAPI_OK 0
|
||||
#define NVAPI_ERROR -1
|
||||
#define NVAPI_INVALID_ARGUMENT -5
|
||||
#define NVAPI_NO_IMPLEMENTATION -7
|
||||
#define NVAPI_END_ENUMERATION -7
|
||||
#define NVAPI_INVALID_POINTER -14
|
||||
#define NVAPI_NOT_SUPPORTED -104
|
||||
#define NVAPI_INCOMPATIBLE_STRUCT_VERSION -105
|
||||
|
||||
#define NVAPI_SHORT_STRING_MAX 64
|
||||
#define NVAPI_MAX_PHYSICAL_GPUS 64
|
||||
|
||||
// NVIDIA Driver 570.00 (satisfies all DLSS 2/3/3.5/4 & Streamline 2.x checks)
|
||||
#define WL_NV_DRIVER_VERSION 57000u
|
||||
#define WL_NV_BUILD_BRANCH "r570_00"
|
||||
#define WL_NV_GPU_NAME "NVIDIA GeForce RTX 2060"
|
||||
|
||||
static void *const k_fake_gpu = (void *)(uintptr_t)0x000010DE00001F08ULL;
|
||||
static void *const k_fake_lgpu = (void *)(uintptr_t)0x000010DE00001F09ULL;
|
||||
static void *const k_fake_disp = (void *)(uintptr_t)0x000010DE00000001ULL;
|
||||
static void *const k_drs_sess = (void *)(uintptr_t)0x000010DE0000D001ULL;
|
||||
static void *const k_drs_prof = (void *)(uintptr_t)0x000010DE0000D002ULL;
|
||||
|
||||
// Minimal COM vtable definitions for IDXGIFactory1 / IDXGIAdapter1 (no dxgi.lib link required)
|
||||
typedef struct WlDxgiAdapterDesc1 {
|
||||
WCHAR Description[128];
|
||||
UINT VendorId;
|
||||
UINT DeviceId;
|
||||
UINT SubSysId;
|
||||
UINT Revision;
|
||||
SIZE_T DedicatedVideoMemory;
|
||||
SIZE_T DedicatedSystemMemory;
|
||||
SIZE_T SharedSystemMemory;
|
||||
LUID AdapterLuid;
|
||||
UINT Flags;
|
||||
} WlDxgiAdapterDesc1;
|
||||
|
||||
typedef struct WlIDXGIAdapter1Vtbl {
|
||||
HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *, const GUID *, void **);
|
||||
ULONG (STDMETHODCALLTYPE *AddRef)(void *);
|
||||
ULONG (STDMETHODCALLTYPE *Release)(void *);
|
||||
HRESULT (STDMETHODCALLTYPE *SetPrivateData)(void *, const GUID *, UINT, const void *);
|
||||
HRESULT (STDMETHODCALLTYPE *SetPrivateDataInterface)(void *, const GUID *, const void *);
|
||||
HRESULT (STDMETHODCALLTYPE *GetPrivateData)(void *, const GUID *, UINT *, void *);
|
||||
HRESULT (STDMETHODCALLTYPE *GetParent)(void *, const GUID *, void **);
|
||||
HRESULT (STDMETHODCALLTYPE *EnumOutputs)(void *, UINT, void **);
|
||||
HRESULT (STDMETHODCALLTYPE *GetDesc)(void *, void *);
|
||||
HRESULT (STDMETHODCALLTYPE *CheckInterfaceSupport)(void *, const GUID *, LARGE_INTEGER *);
|
||||
HRESULT (STDMETHODCALLTYPE *GetDesc1)(void *, WlDxgiAdapterDesc1 *);
|
||||
} WlIDXGIAdapter1Vtbl;
|
||||
|
||||
typedef struct { WlIDXGIAdapter1Vtbl *lpVtbl; } WlIDXGIAdapter1;
|
||||
|
||||
typedef struct WlIDXGIFactory1Vtbl {
|
||||
HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *, const GUID *, void **);
|
||||
ULONG (STDMETHODCALLTYPE *AddRef)(void *);
|
||||
ULONG (STDMETHODCALLTYPE *Release)(void *);
|
||||
HRESULT (STDMETHODCALLTYPE *SetPrivateData)(void *, const GUID *, UINT, const void *);
|
||||
HRESULT (STDMETHODCALLTYPE *SetPrivateDataInterface)(void *, const GUID *, const void *);
|
||||
HRESULT (STDMETHODCALLTYPE *GetPrivateData)(void *, const GUID *, UINT *, void *);
|
||||
HRESULT (STDMETHODCALLTYPE *GetParent)(void *, const GUID *, void **);
|
||||
HRESULT (STDMETHODCALLTYPE *EnumAdapters)(void *, UINT, void **);
|
||||
HRESULT (STDMETHODCALLTYPE *MakeWindowAssociation)(void *, HWND, UINT);
|
||||
HRESULT (STDMETHODCALLTYPE *GetWindowAssociation)(void *, HWND *);
|
||||
HRESULT (STDMETHODCALLTYPE *CreateSwapChain)(void *, void *, void *, void **);
|
||||
HRESULT (STDMETHODCALLTYPE *CreateSoftwareAdapter)(void *, HMODULE, void **);
|
||||
HRESULT (STDMETHODCALLTYPE *EnumAdapters1)(void *, UINT, WlIDXGIAdapter1 **);
|
||||
} WlIDXGIFactory1Vtbl;
|
||||
|
||||
typedef struct { WlIDXGIFactory1Vtbl *lpVtbl; } WlIDXGIFactory1;
|
||||
|
||||
typedef HRESULT (WINAPI *PFN_CreateDXGIFactory1)(const GUID *riid, void **ppFactory);
|
||||
static const GUID k_IID_IDXGIFactory1 = {
|
||||
0x770aae78u, 0xf26fu, 0x4dbau, { 0xa8, 0x29, 0x25, 0x3c, 0x83, 0xd1, 0xb3, 0x87 }
|
||||
};
|
||||
|
||||
static CRITICAL_SECTION g_cs;
|
||||
static int g_cs_ready = 0;
|
||||
static int g_dxgi_probed = 0;
|
||||
static LUID g_luid = { 0x10DE1F08u, 0 };
|
||||
static uint32_t g_vendor_id = 0x10DEu;
|
||||
static uint32_t g_device_id = 0x1F08u;
|
||||
static uint32_t g_subsys_id = 0x10DE1F08u;
|
||||
static uint32_t g_rev_id = 0xA1u;
|
||||
static uint64_t g_dxgi_vram_bytes = 0ULL;
|
||||
|
||||
static void ensure_cs(void) {
|
||||
if (!g_cs_ready) { InitializeCriticalSection(&g_cs); g_cs_ready = 1; }
|
||||
}
|
||||
|
||||
static void probe_dxgi_adapter_once(void) {
|
||||
ensure_cs();
|
||||
EnterCriticalSection(&g_cs);
|
||||
if (!g_dxgi_probed) {
|
||||
g_dxgi_probed = 1;
|
||||
HMODULE hDxgi = GetModuleHandleA("dxgi.dll");
|
||||
if (!hDxgi) hDxgi = LoadLibraryA("dxgi.dll");
|
||||
if (hDxgi) {
|
||||
PFN_CreateDXGIFactory1 fnCreate = (PFN_CreateDXGIFactory1)(void *)GetProcAddress(hDxgi, "CreateDXGIFactory1");
|
||||
if (fnCreate) {
|
||||
WlIDXGIFactory1 *factory = NULL;
|
||||
if (SUCCEEDED(fnCreate(&k_IID_IDXGIFactory1, (void **)&factory)) && factory) {
|
||||
WlIDXGIAdapter1 *adapter = NULL;
|
||||
if (SUCCEEDED(factory->lpVtbl->EnumAdapters1(factory, 0, &adapter)) && adapter) {
|
||||
WlDxgiAdapterDesc1 desc;
|
||||
memset(&desc, 0, sizeof desc);
|
||||
if (SUCCEEDED(adapter->lpVtbl->GetDesc1(adapter, &desc))) {
|
||||
g_luid = desc.AdapterLuid;
|
||||
if (desc.DedicatedVideoMemory > 0) {
|
||||
g_dxgi_vram_bytes = (uint64_t)desc.DedicatedVideoMemory;
|
||||
}
|
||||
if (desc.VendorId == 0x10DEu && desc.DeviceId != 0) {
|
||||
g_vendor_id = desc.VendorId;
|
||||
g_device_id = desc.DeviceId;
|
||||
if (desc.SubSysId) g_subsys_id = desc.SubSysId;
|
||||
if (desc.Revision) g_rev_id = desc.Revision;
|
||||
}
|
||||
}
|
||||
adapter->lpVtbl->Release(adapter);
|
||||
}
|
||||
factory->lpVtbl->Release(factory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&g_cs);
|
||||
}
|
||||
|
||||
static uint64_t wl_nv_vram_bytes(void) {
|
||||
static const char *const names[] = { "DROIDDECK_UPSCALE_VRAM_MB", "WINLATOR_FSR4_VRAM_MB", "WRAPPER_VMEM_MAX_SIZE" };
|
||||
char buf[64];
|
||||
for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
|
||||
DWORD n = GetEnvironmentVariableA(names[i], buf, sizeof(buf));
|
||||
if (n > 0 && n < sizeof(buf)) {
|
||||
unsigned long long mb = strtoull(buf, NULL, 10);
|
||||
if (mb >= 512ULL && mb <= 65536ULL) return mb * 1024ULL * 1024ULL;
|
||||
}
|
||||
}
|
||||
probe_dxgi_adapter_once();
|
||||
if (g_dxgi_vram_bytes >= 512ULL * 1024ULL * 1024ULL) return g_dxgi_vram_bytes;
|
||||
return 12ULL * 1024ULL * 1024ULL * 1024ULL;
|
||||
}
|
||||
|
||||
static void copy_short_str(char *dst, const char *src) {
|
||||
if (!dst) return;
|
||||
strncpy(dst, src ? src : "", NVAPI_SHORT_STRING_MAX - 1);
|
||||
dst[NVAPI_SHORT_STRING_MAX - 1] = '\0';
|
||||
}
|
||||
|
||||
// ---- Exact NVAPI structs (verified against NVIDIA NVAPI SDK / fakenvapi) ----
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
uint32_t drvVersion;
|
||||
uint32_t bldChangeListNum;
|
||||
char szBuildBranchString[NVAPI_SHORT_STRING_MAX];
|
||||
char szAdapterString[NVAPI_SHORT_STRING_MAX];
|
||||
} WlNvDisplayDriverVersion;
|
||||
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
uint32_t driverVersion;
|
||||
char szBuildBranch[NVAPI_SHORT_STRING_MAX];
|
||||
uint32_t flags; /* bit0=DCH, bit1=Studio, bit2=GameReady, bit3=RTXProd, bit4=RTXNFB */
|
||||
char szBuildBaseBranch[NVAPI_SHORT_STRING_MAX];
|
||||
uint32_t reservedEx;
|
||||
} WlNvDisplayDriverInfoV2;
|
||||
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
void *pOSAdapterId;
|
||||
uint32_t physicalGpuCount;
|
||||
void *physicalGpuHandles[NVAPI_MAX_PHYSICAL_GPUS];
|
||||
uint32_t reserved[8];
|
||||
} WlNvLogicalGpuDataV1;
|
||||
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
uint32_t gpuCount;
|
||||
struct {
|
||||
void *hPhysicalGpu;
|
||||
uint32_t flags;
|
||||
} computeGpus[NVAPI_MAX_PHYSICAL_GPUS];
|
||||
} WlNvComputeGpuTopologyV1;
|
||||
|
||||
typedef struct {
|
||||
uint32_t bIsPresent;
|
||||
uint32_t frequency;
|
||||
} WlNvClockDomain;
|
||||
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
uint32_t clockType;
|
||||
WlNvClockDomain domain[32];
|
||||
} WlNvGpuClockFrequencies;
|
||||
|
||||
// ---- Core NVAPI implementations ----
|
||||
static NvAPI_Status __cdecl impl_Initialize(void) {
|
||||
wl_install_ngx_hooks_once();
|
||||
probe_dxgi_adapter_once();
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_Unload(void) { return NVAPI_OK; }
|
||||
static NvAPI_Status __cdecl impl_GetInterfaceVersionString(char *out) {
|
||||
copy_short_str(out, "NVAPI Open Source Interface (Winlator FSR4 NPU)");
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GetErrorMessage(NvAPI_Status nr, char *out) {
|
||||
copy_short_str(out, nr == NVAPI_OK ? "NVAPI_OK" : "NVAPI_ERROR");
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GetDisplayDriverVersion(void *disp, WlNvDisplayDriverVersion *ver) {
|
||||
(void)disp;
|
||||
if (!ver) return NVAPI_INVALID_ARGUMENT;
|
||||
ver->drvVersion = WL_NV_DRIVER_VERSION;
|
||||
ver->bldChangeListNum = 35000000u;
|
||||
copy_short_str(ver->szBuildBranchString, WL_NV_BUILD_BRANCH);
|
||||
copy_short_str(ver->szAdapterString, WL_NV_GPU_NAME);
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_SYS_GetDriverAndBranchVersion(uint32_t *ver, char *branch) {
|
||||
if (ver) *ver = WL_NV_DRIVER_VERSION;
|
||||
if (branch) copy_short_str(branch, WL_NV_BUILD_BRANCH);
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_SYS_GetDisplayDriverInfo(WlNvDisplayDriverInfoV2 *info) {
|
||||
if (!info) return NVAPI_INVALID_ARGUMENT;
|
||||
info->driverVersion = WL_NV_DRIVER_VERSION;
|
||||
copy_short_str(info->szBuildBranch, WL_NV_BUILD_BRANCH);
|
||||
info->flags = (1u << 0) | (1u << 1) | (1u << 2) | (1u << 3) | (1u << 4);
|
||||
uint32_t struct_ver = (info->version >> 16) & 0xFFFFu;
|
||||
if (struct_ver >= 2u || info->version == 2u) {
|
||||
copy_short_str(info->szBuildBaseBranch, WL_NV_BUILD_BRANCH);
|
||||
info->reservedEx = 0;
|
||||
}
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_EnumPhysicalGPUs(void **handles, uint32_t *count) {
|
||||
probe_dxgi_adapter_once();
|
||||
if (handles) handles[0] = k_fake_gpu;
|
||||
if (count) *count = 1u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_EnumLogicalGPUs(void **handles, uint32_t *count) {
|
||||
probe_dxgi_adapter_once();
|
||||
if (handles) handles[0] = k_fake_lgpu;
|
||||
if (count) *count = 1u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_EnumNvidiaDisplayHandle(uint32_t idx, void **handle) {
|
||||
if (idx > 0) return NVAPI_END_ENUMERATION;
|
||||
if (handle) *handle = k_fake_disp;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_EnumUnattached(uint32_t idx, void **handle) {
|
||||
(void)idx; (void)handle;
|
||||
return NVAPI_END_ENUMERATION;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GetLogicalGPUFromPhysicalGPU(void *phys, void **logical) {
|
||||
(void)phys;
|
||||
if (logical) *logical = k_fake_lgpu;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GetPhysicalGPUsFromLogicalGPU(void *logical, void **phys, uint32_t *count) {
|
||||
(void)logical;
|
||||
if (phys) phys[0] = k_fake_gpu;
|
||||
if (count) *count = 1u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GetPhysicalGPUsFromDisplay(void *disp, void **phys, uint32_t *count) {
|
||||
(void)disp;
|
||||
if (phys) phys[0] = k_fake_gpu;
|
||||
if (count) *count = 1u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GetGPUIDfromPhysicalGPU(void *phys, uint32_t *gpuId) {
|
||||
(void)phys;
|
||||
if (gpuId) *gpuId = 0x100u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GetPhysicalGPUFromGPUID(uint32_t gpuId, void **phys) {
|
||||
(void)gpuId;
|
||||
if (phys) *phys = k_fake_gpu;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetAdapterIdFromPhysicalGpu(void *gpu, void *pOSAdapterId) {
|
||||
(void)gpu;
|
||||
if (!pOSAdapterId) return NVAPI_INVALID_ARGUMENT;
|
||||
probe_dxgi_adapter_once();
|
||||
memcpy(pOSAdapterId, &g_luid, sizeof(g_luid));
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetLogicalGpuInfo(void *logical, WlNvLogicalGpuDataV1 *data) {
|
||||
(void)logical;
|
||||
if (!data) return NVAPI_INVALID_ARGUMENT;
|
||||
probe_dxgi_adapter_once();
|
||||
if (data->pOSAdapterId) memcpy(data->pOSAdapterId, &g_luid, sizeof(g_luid));
|
||||
data->physicalGpuCount = 1u;
|
||||
data->physicalGpuHandles[0] = k_fake_gpu;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetFullName(void *gpu, char *name) {
|
||||
(void)gpu;
|
||||
copy_short_str(name, WL_NV_GPU_NAME);
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetPCIIdentifiers(void *gpu, uint32_t *devId, uint32_t *subSysId, uint32_t *revId, uint32_t *extDevId) {
|
||||
(void)gpu;
|
||||
probe_dxgi_adapter_once();
|
||||
if (devId) *devId = (g_device_id << 16) | (g_vendor_id & 0xFFFFu);
|
||||
if (subSysId) *subSysId = g_subsys_id;
|
||||
if (revId) *revId = g_rev_id;
|
||||
if (extDevId) *extDevId = g_device_id;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetArchInfo(void *gpu, void *info) {
|
||||
(void)gpu;
|
||||
if (!info) return NVAPI_INVALID_ARGUMENT;
|
||||
uint32_t *u = (uint32_t *)info;
|
||||
// NV_GPU_ARCH_INFO_V2: [0]=version, [1]=architecture (TU100=0x160), [2]=implementation (TU106=0x06), [3]=revision (0xA1)
|
||||
u[1] = 0x00000160u;
|
||||
u[2] = 0x00000006u;
|
||||
u[3] = 0x000000A1u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetGPUType(void *gpu, uint32_t *type) {
|
||||
(void)gpu;
|
||||
if (type) *type = 2u; /* NV_SYSTEM_TYPE_DISCRETE */
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetMemoryInfo(void *gpu, uint32_t *info) {
|
||||
(void)gpu;
|
||||
if (info) {
|
||||
uint64_t vram_kb64 = wl_nv_vram_bytes() / 1024ULL;
|
||||
uint32_t vram_kb = (vram_kb64 > 0xFFFFFFFFULL) ? 0xFFFFFFFFu : (uint32_t)vram_kb64;
|
||||
info[1] = vram_kb;
|
||||
info[2] = vram_kb;
|
||||
info[3] = 0u;
|
||||
info[4] = vram_kb / 2u;
|
||||
info[5] = (vram_kb / 8u) * 7u;
|
||||
}
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetMemoryInfoEx(void *gpu, uint64_t *info) {
|
||||
(void)gpu;
|
||||
if (info) {
|
||||
uint64_t vram_b = wl_nv_vram_bytes();
|
||||
info[1] = vram_b;
|
||||
info[2] = vram_b;
|
||||
info[3] = 0ULL;
|
||||
info[4] = vram_b / 2ULL;
|
||||
info[5] = (vram_b / 8ULL) * 7ULL;
|
||||
}
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetVbiosVersionString(void *gpu, char *out) {
|
||||
(void)gpu;
|
||||
copy_short_str(out, "90.06.2E.00.01");
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetPhysicalFrameBufferSize(void *gpu, uint32_t *kb) {
|
||||
(void)gpu;
|
||||
if (kb) {
|
||||
uint64_t vram_kb64 = wl_nv_vram_bytes() / 1024ULL;
|
||||
*kb = (vram_kb64 > 0xFFFFFFFFULL) ? 0xFFFFFFFFu : (uint32_t)vram_kb64;
|
||||
}
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetGpuCoreCount(void *gpu, uint32_t *cnt) {
|
||||
(void)gpu;
|
||||
if (cnt) *cnt = 1920u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetConnectedDisplayIds(void *gpu, void *ids, uint32_t *cnt, uint32_t flags) {
|
||||
(void)gpu; (void)ids; (void)flags;
|
||||
if (cnt) *cnt = 0u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_CudaEnumComputeCapableGpus(WlNvComputeGpuTopologyV1 *topo) {
|
||||
if (!topo) return NVAPI_INVALID_ARGUMENT;
|
||||
topo->gpuCount = 1u;
|
||||
topo->computeGpus[0].hPhysicalGpu = k_fake_gpu;
|
||||
topo->computeGpus[0].flags = 0x7u; /* CAPABLE | ENABLE | RECOMMENDED */
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_GPU_GetAllClockFrequencies(void *gpu, WlNvGpuClockFrequencies *clk) {
|
||||
(void)gpu;
|
||||
if (!clk) return NVAPI_INVALID_ARGUMENT;
|
||||
memset(clk->domain, 0, sizeof clk->domain);
|
||||
clk->domain[0].bIsPresent = 1; clk->domain[0].frequency = 1680000u; /* Graphics */
|
||||
clk->domain[4].bIsPresent = 1; clk->domain[4].frequency = 7000000u; /* Memory */
|
||||
clk->domain[7].bIsPresent = 1; clk->domain[7].frequency = 1400000u; /* Video */
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_Disp_GetDisplayIdByDisplayName(const char *name, uint32_t *id) {
|
||||
(void)name;
|
||||
if (id) *id = 0u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_Disp_GetGDIPrimaryDisplayId(uint32_t *id) {
|
||||
if (id) *id = 0u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_Disp_OutputMode(uint32_t dispId, uint32_t *mode) {
|
||||
(void)dispId;
|
||||
if (mode) *mode = 0u; /* SDR */
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_SYS_GetDisplayIdFromGpuAndOutputId(void *gpu, uint32_t outId, uint32_t *dispId) {
|
||||
(void)gpu; (void)outId;
|
||||
if (dispId) *dispId = 0u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_SYS_GetGpuAndOutputIdFromDisplayId(uint32_t dispId, void **gpu, uint32_t *outId) {
|
||||
(void)dispId;
|
||||
if (gpu) *gpu = k_fake_gpu;
|
||||
if (outId) *outId = 0u;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_D3D_GetCurrentSLIState(void *dev, uint32_t *state) {
|
||||
(void)dev;
|
||||
if (state) {
|
||||
state[1] = 1; state[2] = 1; state[3] = 0;
|
||||
state[4] = 0; state[5] = 0; state[6] = 0;
|
||||
}
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_D3D_GetObjectHandleForResource(void *dev, void *res, void **outH) {
|
||||
(void)dev;
|
||||
if (outH) *outH = res;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_D3D12_IsNvShaderExtnOpCodeSupported(void *dev, uint32_t op, uint8_t *supported) {
|
||||
(void)dev; (void)op;
|
||||
if (supported) *supported = 0;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_D3D12_GetRaytracingCaps(void *dev, uint32_t type, void *pData, size_t dataSize) {
|
||||
(void)dev; (void)type;
|
||||
if (!pData) return NVAPI_INVALID_POINTER;
|
||||
memset(pData, 0, dataSize);
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_DRS_CreateSession(void **sess) {
|
||||
if (sess) *sess = k_drs_sess;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_DRS_GetBaseProfile(void *sess, void **prof) {
|
||||
(void)sess;
|
||||
if (prof) *prof = k_drs_prof;
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_D3D_GetSleepStatus(void *dev, uint32_t *params) {
|
||||
(void)dev;
|
||||
if (params) {
|
||||
params[1] = 0u; /* bLowLatencyMode */
|
||||
params[2] = 0u; /* bFsVrr */
|
||||
params[3] = 0u; /* bCplVsyncOn */
|
||||
}
|
||||
return NVAPI_OK;
|
||||
}
|
||||
static NvAPI_Status __cdecl impl_NoOpOk(void) { return NVAPI_OK; }
|
||||
static NvAPI_Status __cdecl impl_NotSupported(void) { return NVAPI_NO_IMPLEMENTATION; }
|
||||
|
||||
__declspec(dllexport) void *__cdecl nvapi_QueryInterface(uint32_t id) {
|
||||
wl_install_ngx_hooks_once();
|
||||
switch (id) {
|
||||
// Core & driver info
|
||||
case 0x0150E828u: return (void *)impl_Initialize; // NvAPI_Initialize
|
||||
case 0xD22BDD7Eu: return (void *)impl_Unload; // NvAPI_Unload
|
||||
case 0x01053FA5u: return (void *)impl_GetInterfaceVersionString; // NvAPI_GetInterfaceVersionString
|
||||
case 0x6C2D048Cu: return (void *)impl_GetErrorMessage; // NvAPI_GetErrorMessage
|
||||
case 0xF951A4D1u: return (void *)impl_GetDisplayDriverVersion; // NvAPI_GetDisplayDriverVersion
|
||||
case 0x2926AAADu: return (void *)impl_SYS_GetDriverAndBranchVersion; // NvAPI_SYS_GetDriverAndBranchVersion
|
||||
case 0x721FACEBu: return (void *)impl_SYS_GetDisplayDriverInfo; // NvAPI_SYS_GetDisplayDriverInfo
|
||||
case 0x08F2BAB4u: return (void *)impl_SYS_GetDisplayIdFromGpuAndOutputId;// NvAPI_SYS_GetDisplayIdFromGpuAndOutputId
|
||||
case 0x112BA1A5u: return (void *)impl_SYS_GetGpuAndOutputIdFromDisplayId;// NvAPI_SYS_GetGpuAndOutputIdFromDisplayId
|
||||
|
||||
// Physical / logical GPU enumeration & LUID matching (CRITICAL for Streamline / Cyberpunk 2077)
|
||||
case 0xE5AC921Fu: return (void *)impl_EnumPhysicalGPUs; // NvAPI_EnumPhysicalGPUs
|
||||
case 0x48B3EA59u: return (void *)impl_EnumLogicalGPUs; // NvAPI_EnumLogicalGPUs
|
||||
case 0x9ABDD40Du: return (void *)impl_EnumNvidiaDisplayHandle; // NvAPI_EnumNvidiaDisplayHandle
|
||||
case 0x20DE9260u: return (void *)impl_EnumUnattached; // NvAPI_EnumNvidiaUnAttachedDisplayHandle
|
||||
case 0xADD604D1u: return (void *)impl_GetLogicalGPUFromPhysicalGPU; // NvAPI_GetLogicalGPUFromPhysicalGPU
|
||||
case 0xAEA3FA32u: return (void *)impl_GetPhysicalGPUsFromLogicalGPU; // NvAPI_GetPhysicalGPUsFromLogicalGPU
|
||||
case 0x34EF9506u: return (void *)impl_GetPhysicalGPUsFromDisplay; // NvAPI_GetPhysicalGPUsFromDisplay
|
||||
case 0x6533EA3Eu: return (void *)impl_GetGPUIDfromPhysicalGPU; // NvAPI_GetGPUIDfromPhysicalGPU
|
||||
case 0x5380AD1Au: return (void *)impl_GetPhysicalGPUFromGPUID; // NvAPI_GetPhysicalGPUFromGPUID
|
||||
case 0x0FF07FDEu: return (void *)impl_GPU_GetAdapterIdFromPhysicalGpu; // NvAPI_GPU_GetAdapterIdFromPhysicalGpu
|
||||
case 0x842B066Eu: return (void *)impl_GPU_GetLogicalGpuInfo; // NvAPI_GPU_GetLogicalGpuInfo
|
||||
|
||||
// GPU capabilities & identity
|
||||
case 0xCEEE8E9Fu: return (void *)impl_GPU_GetFullName; // NvAPI_GPU_GetFullName
|
||||
case 0x2DDFB66Eu: return (void *)impl_GPU_GetPCIIdentifiers; // NvAPI_GPU_GetPCIIdentifiers
|
||||
case 0xD8265D24u: return (void *)impl_GPU_GetArchInfo; // NvAPI_GPU_GetArchInfo
|
||||
case 0xC33BAEB1u: return (void *)impl_GPU_GetGPUType; // NvAPI_GPU_GetGPUType
|
||||
case 0x07F9B368u: return (void *)impl_GPU_GetMemoryInfo; // NvAPI_GPU_GetMemoryInfo
|
||||
case 0xC0599498u: return (void *)impl_GPU_GetMemoryInfoEx; // NvAPI_GPU_GetMemoryInfoEx
|
||||
case 0xA561FD7Du: return (void *)impl_GPU_GetVbiosVersionString; // NvAPI_GPU_GetVbiosVersionString
|
||||
case 0x46FBEB03u: return (void *)impl_GPU_GetPhysicalFrameBufferSize; // NvAPI_GPU_GetPhysicalFrameBufferSize
|
||||
case 0x5A04B644u: return (void *)impl_GPU_GetPhysicalFrameBufferSize; // NvAPI_GPU_GetVirtualFrameBufferSize
|
||||
case 0xC7026A87u: return (void *)impl_GPU_GetGpuCoreCount; // NvAPI_GPU_GetGpuCoreCount
|
||||
case 0x0078DBA2u: return (void *)impl_GPU_GetConnectedDisplayIds; // NvAPI_GPU_GetConnectedDisplayIds
|
||||
case 0x5786CC6Eu: return (void *)impl_GPU_CudaEnumComputeCapableGpus; // NvAPI_GPU_CudaEnumComputeCapableGpus
|
||||
case 0xDCB616C3u: return (void *)impl_GPU_GetAllClockFrequencies; // NvAPI_GPU_GetAllClockFrequencies
|
||||
|
||||
// Display
|
||||
case 0xAE457190u: return (void *)impl_Disp_GetDisplayIdByDisplayName; // NvAPI_DISP_GetDisplayIdByDisplayName
|
||||
case 0x1E9D8A31u: return (void *)impl_Disp_GetGDIPrimaryDisplayId; // NvAPI_DISP_GetGDIPrimaryDisplayId
|
||||
case 0x98E7661Au: return (void *)impl_Disp_OutputMode; // NvAPI_Disp_SetOutputMode
|
||||
case 0x81FED88Du: return (void *)impl_Disp_OutputMode; // NvAPI_Disp_GetOutputMode
|
||||
case 0x84F2A8DFu: return (void *)impl_NoOpOk; // NvAPI_Disp_GetHdrCapabilities
|
||||
case 0x351DA224u: return (void *)impl_NoOpOk; // NvAPI_Disp_HdrColorControl
|
||||
|
||||
// D3D / D3D12 / Reflex
|
||||
case 0x4B708B54u: return (void *)impl_D3D_GetCurrentSLIState; // NvAPI_D3D_GetCurrentSLIState
|
||||
case 0xFCEAC864u: return (void *)impl_D3D_GetObjectHandleForResource; // NvAPI_D3D_GetObjectHandleForResource
|
||||
case 0x8C02C4D0u: return (void *)impl_NoOpOk; // NvAPI_D3D_RegisterDevice
|
||||
case 0x3DFACEC8u: return (void *)impl_D3D12_IsNvShaderExtnOpCodeSupported;// NvAPI_D3D12_IsNvShaderExtnOpCodeSupported
|
||||
case 0x43D867C0u: return (void *)impl_NoOpOk; // NvAPI_D3D12_SetNvShaderExtnSlotSpaceLocalThread
|
||||
case 0x85A6C2A0u: return (void *)impl_D3D12_GetRaytracingCaps; // NvAPI_D3D12_GetRaytracingCaps
|
||||
case 0x03D6E8CBu: return (void *)impl_NoOpOk; // NvAPI_D3D12_NotifyOutOfBandCommandQueue
|
||||
case 0x13C98F73u: return (void *)impl_NoOpOk; // NvAPI_D3D12_SetAsyncFrameMarker
|
||||
case 0xAEF96CA1u: return (void *)impl_D3D_GetSleepStatus; // NvAPI_D3D_GetSleepStatus
|
||||
case 0xAC1CA9E0u: return (void *)impl_NoOpOk; // NvAPI_D3D_SetSleepMode
|
||||
case 0x852CD1D2u: return (void *)impl_NoOpOk; // NvAPI_D3D_Sleep
|
||||
case 0xB9F6FAFFu: return (void *)impl_NoOpOk; // NvAPI_D3D_SetReflexSync
|
||||
case 0x1A587F9Cu: return (void *)impl_NoOpOk; // NvAPI_D3D_GetLatency
|
||||
case 0xD9984C05u: return (void *)impl_NoOpOk; // NvAPI_D3D_SetLatencyMarker
|
||||
|
||||
// Vulkan Reflex (graceful unsupported so Vulkan games don't expect a timeline semaphore we didn't create)
|
||||
case 0x5C1696B6u: return (void *)impl_NotSupported; // NvAPI_Vulkan_InitLowLatencyDevice
|
||||
case 0x11A5932Bu: return (void *)impl_NoOpOk; // NvAPI_Vulkan_DestroyLowLatencyDevice
|
||||
case 0xADF966AFu: return (void *)impl_NotSupported; // NvAPI_Vulkan_GetSleepStatus
|
||||
case 0x2ACFD162u: return (void *)impl_NotSupported; // NvAPI_Vulkan_SetSleepMode
|
||||
case 0x36732B1Eu: return (void *)impl_NotSupported; // NvAPI_Vulkan_Sleep
|
||||
case 0x3233D44Au: return (void *)impl_NotSupported; // NvAPI_Vulkan_GetLatency
|
||||
case 0xA17D13D6u: return (void *)impl_NotSupported; // NvAPI_Vulkan_SetLatencyMarker
|
||||
case 0x5D6D3840u: return (void *)impl_NoOpOk; // NvAPI_Vulkan_NotifyOutOfBandVkQueue
|
||||
|
||||
// DRS (Driver Settings)
|
||||
case 0x0694D52Eu: return (void *)impl_DRS_CreateSession; // NvAPI_DRS_CreateSession
|
||||
case 0xDAD9CFF8u: return (void *)impl_NoOpOk; // NvAPI_DRS_DestroySession
|
||||
case 0x375DBD6Bu: return (void *)impl_NoOpOk; // NvAPI_DRS_LoadSettings
|
||||
case 0xFCBC7E14u: return (void *)impl_NoOpOk; // NvAPI_DRS_SaveSettings
|
||||
case 0xDA8466A0u: return (void *)impl_DRS_GetBaseProfile; // NvAPI_DRS_GetBaseProfile
|
||||
case 0x73BF8338u: return (void *)impl_NotSupported; // NvAPI_DRS_GetSetting
|
||||
case 0x577DD202u: return (void *)impl_NoOpOk; // NvAPI_DRS_SetSetting
|
||||
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
|
||||
(void)reserved;
|
||||
if (reason == DLL_PROCESS_ATTACH) {
|
||||
g_wl_self_mod = hinst;
|
||||
DisableThreadLibraryCalls(hinst);
|
||||
ensure_cs();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,443 @@
|
||||
// DroidDeck: modified from michaelisomer-cyber/Winlator-NeuralScale a0ab6b0f (see README.md).
|
||||
// Windows-side in-process Vulkan Seam Client for Winlator Ludashi FSR 4.1.1 HTP NPU Layer.
|
||||
// Allocates the host-coherent WlFsr4Mailbox + marker buffer on the game's VkDevice and
|
||||
// rings the vkCmdUpdateBuffer doorbell so libVkLayer_winlator_fsr4_npu.so records the
|
||||
// zero-copy Hexagon HTP v81 pipeline directly into the game's VkCommandBuffer.
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "fsr4_seam_proto.h"
|
||||
#include "dd_env.h"
|
||||
|
||||
// Minimal Vulkan types for MinGW x86_64 (zero external Vulkan SDK dependency)
|
||||
typedef uint32_t VkFlags;
|
||||
typedef uint32_t VkBool32;
|
||||
typedef uint64_t VkDeviceSize;
|
||||
typedef int32_t VkResult;
|
||||
typedef void *VkInstance;
|
||||
typedef void *VkPhysicalDevice;
|
||||
typedef void *VkDevice;
|
||||
typedef void *VkCommandBuffer;
|
||||
typedef uint64_t VkBuffer;
|
||||
typedef uint64_t VkDeviceMemory;
|
||||
typedef uint64_t VkImage;
|
||||
typedef uint64_t VkImageView;
|
||||
|
||||
#define VK_SUCCESS 0
|
||||
#define VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO 12
|
||||
#define VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO 5
|
||||
#define VK_BUFFER_USAGE_TRANSFER_DST_BIT 0x00000002u
|
||||
#define VK_BUFFER_USAGE_STORAGE_BUFFER_BIT 0x00000020u
|
||||
#define VK_SHARING_MODE_EXCLUSIVE 0
|
||||
#define VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT 0x00000002u
|
||||
#define VK_MEMORY_PROPERTY_HOST_COHERENT_BIT 0x00000004u
|
||||
|
||||
typedef struct {
|
||||
uint32_t sType;
|
||||
const void *pNext;
|
||||
VkFlags flags;
|
||||
VkDeviceSize size;
|
||||
VkFlags usage;
|
||||
uint32_t sharingMode;
|
||||
uint32_t queueFamilyIndexCount;
|
||||
const uint32_t *pQueueFamilyIndices;
|
||||
} WlVkBufferCreateInfo;
|
||||
|
||||
typedef struct {
|
||||
VkDeviceSize size;
|
||||
VkDeviceSize alignment;
|
||||
uint32_t memoryTypeBits;
|
||||
} WlVkMemoryRequirements;
|
||||
|
||||
typedef struct {
|
||||
uint32_t sType;
|
||||
const void *pNext;
|
||||
VkDeviceSize allocationSize;
|
||||
uint32_t memoryTypeIndex;
|
||||
} WlVkMemoryAllocateInfo;
|
||||
|
||||
typedef struct {
|
||||
VkFlags propertyFlags;
|
||||
uint32_t heapIndex;
|
||||
} WlVkMemoryType;
|
||||
|
||||
typedef struct {
|
||||
VkDeviceSize size;
|
||||
VkFlags flags;
|
||||
} WlVkMemoryHeap;
|
||||
|
||||
typedef struct {
|
||||
uint32_t memoryTypeCount;
|
||||
WlVkMemoryType memoryTypes[32];
|
||||
uint32_t memoryHeapCount;
|
||||
WlVkMemoryHeap memoryHeaps[16];
|
||||
} WlVkPhysicalDeviceMemoryProperties;
|
||||
|
||||
typedef struct {
|
||||
uint32_t sType;
|
||||
const void *pNext;
|
||||
uint32_t srcAccessMask;
|
||||
uint32_t dstAccessMask;
|
||||
uint32_t oldLayout;
|
||||
uint32_t newLayout;
|
||||
uint32_t srcQueueFamilyIndex;
|
||||
uint32_t dstQueueFamilyIndex;
|
||||
VkImage image;
|
||||
struct {
|
||||
uint32_t aspectMask;
|
||||
uint32_t baseMipLevel;
|
||||
uint32_t levelCount;
|
||||
uint32_t baseArrayLayer;
|
||||
uint32_t layerCount;
|
||||
} subresourceRange;
|
||||
} WlVkImageMemoryBarrier;
|
||||
|
||||
typedef struct {
|
||||
struct {
|
||||
uint32_t aspectMask;
|
||||
uint32_t mipLevel;
|
||||
uint32_t baseArrayLayer;
|
||||
uint32_t layerCount;
|
||||
} srcSubresource;
|
||||
struct { int32_t x, y, z; } srcOffsets[2];
|
||||
struct {
|
||||
uint32_t aspectMask;
|
||||
uint32_t mipLevel;
|
||||
uint32_t baseArrayLayer;
|
||||
uint32_t layerCount;
|
||||
} dstSubresource;
|
||||
struct { int32_t x, y, z; } dstOffsets[2];
|
||||
} WlVkImageBlit;
|
||||
|
||||
typedef void *(__stdcall *PFN_wlVkGetDeviceProcAddr)(VkDevice, const char *);
|
||||
typedef void *(__stdcall *PFN_wlVkGetInstanceProcAddr)(VkInstance, const char *);
|
||||
typedef VkResult (__stdcall *PFN_wlVkCreateBuffer)(VkDevice, const WlVkBufferCreateInfo *, const void *, VkBuffer *);
|
||||
typedef void (__stdcall *PFN_wlVkDestroyBuffer)(VkDevice, VkBuffer, const void *);
|
||||
typedef void (__stdcall *PFN_wlVkGetBufferMemoryRequirements)(VkDevice, VkBuffer, WlVkMemoryRequirements *);
|
||||
typedef VkResult (__stdcall *PFN_wlVkAllocateMemory)(VkDevice, const WlVkMemoryAllocateInfo *, const void *, VkDeviceMemory *);
|
||||
typedef void (__stdcall *PFN_wlVkFreeMemory)(VkDevice, VkDeviceMemory, const void *);
|
||||
typedef VkResult (__stdcall *PFN_wlVkBindBufferMemory)(VkDevice, VkBuffer, VkDeviceMemory, VkDeviceSize);
|
||||
typedef VkResult (__stdcall *PFN_wlVkMapMemory)(VkDevice, VkDeviceMemory, VkDeviceSize, VkDeviceSize, VkFlags, void **);
|
||||
typedef void (__stdcall *PFN_wlVkUnmapMemory)(VkDevice, VkDeviceMemory);
|
||||
typedef void (__stdcall *PFN_wlVkCmdUpdateBuffer)(VkCommandBuffer, VkBuffer, VkDeviceSize, VkDeviceSize, const void *);
|
||||
typedef void (__stdcall *PFN_wlVkCmdPipelineBarrier)(VkCommandBuffer, uint32_t, uint32_t, uint32_t, uint32_t, const void *, uint32_t, const void *, uint32_t, const WlVkImageMemoryBarrier *);
|
||||
typedef void (__stdcall *PFN_wlVkCmdBlitImage)(VkCommandBuffer, VkImage, uint32_t, VkImage, uint32_t, uint32_t, const WlVkImageBlit *, uint32_t);
|
||||
typedef void (__stdcall *PFN_wlVkGetPhysicalDeviceMemoryProperties)(VkPhysicalDevice, WlVkPhysicalDeviceMemoryProperties *);
|
||||
|
||||
typedef struct WlSeamClient {
|
||||
int ready;
|
||||
VkInstance inst;
|
||||
VkDevice dev;
|
||||
VkPhysicalDevice phys;
|
||||
VkBuffer mbox_buf;
|
||||
VkDeviceMemory mbox_mem;
|
||||
WlFsr4Mailbox *mbox;
|
||||
VkBuffer marker_buf;
|
||||
VkDeviceMemory marker_mem;
|
||||
uint64_t next_seq;
|
||||
PFN_wlVkDestroyBuffer DestroyBuffer;
|
||||
PFN_wlVkFreeMemory FreeMemory;
|
||||
PFN_wlVkUnmapMemory UnmapMemory;
|
||||
PFN_wlVkCmdUpdateBuffer CmdUpdateBuffer;
|
||||
PFN_wlVkCmdPipelineBarrier CmdPipelineBarrier;
|
||||
PFN_wlVkCmdBlitImage CmdBlitImage;
|
||||
} WlSeamClient;
|
||||
|
||||
static uint32_t wl_seam_pick_mem(const WlVkPhysicalDeviceMemoryProperties *mp, uint32_t bits, uint32_t want) {
|
||||
if (mp) {
|
||||
for (uint32_t i = 0; i < mp->memoryTypeCount; i++) {
|
||||
if ((bits & (1u << i)) && (mp->memoryTypes[i].propertyFlags & want) == want) return i;
|
||||
}
|
||||
}
|
||||
for (uint32_t i = 0; i < 32; i++) {
|
||||
if (bits & (1u << i)) return i;
|
||||
}
|
||||
return 0xFFFFFFFFu;
|
||||
}
|
||||
|
||||
static int wl_seam_init(WlSeamClient *c, VkInstance inst, VkPhysicalDevice phys, VkDevice dev,
|
||||
PFN_wlVkGetDeviceProcAddr gdpa) {
|
||||
memset(c, 0, sizeof *c);
|
||||
if (!dev) return 0;
|
||||
|
||||
HMODULE vkmod = GetModuleHandleA("vulkan-1.dll");
|
||||
if (!vkmod) vkmod = LoadLibraryA("vulkan-1.dll");
|
||||
if (!gdpa && vkmod) gdpa = (PFN_wlVkGetDeviceProcAddr)(void *)GetProcAddress(vkmod, "vkGetDeviceProcAddr");
|
||||
if (!gdpa) return 0;
|
||||
|
||||
PFN_wlVkCreateBuffer CreateBuffer = (PFN_wlVkCreateBuffer)gdpa(dev, "vkCreateBuffer");
|
||||
PFN_wlVkGetBufferMemoryRequirements GetBufReqs = (PFN_wlVkGetBufferMemoryRequirements)gdpa(dev, "vkGetBufferMemoryRequirements");
|
||||
PFN_wlVkAllocateMemory AllocateMemory = (PFN_wlVkAllocateMemory)gdpa(dev, "vkAllocateMemory");
|
||||
PFN_wlVkBindBufferMemory BindBufferMemory = (PFN_wlVkBindBufferMemory)gdpa(dev, "vkBindBufferMemory");
|
||||
PFN_wlVkMapMemory MapMemory = (PFN_wlVkMapMemory)gdpa(dev, "vkMapMemory");
|
||||
c->DestroyBuffer = (PFN_wlVkDestroyBuffer)gdpa(dev, "vkDestroyBuffer");
|
||||
c->FreeMemory = (PFN_wlVkFreeMemory)gdpa(dev, "vkFreeMemory");
|
||||
c->UnmapMemory = (PFN_wlVkUnmapMemory)gdpa(dev, "vkUnmapMemory");
|
||||
c->CmdUpdateBuffer = (PFN_wlVkCmdUpdateBuffer)gdpa(dev, "vkCmdUpdateBuffer");
|
||||
c->CmdPipelineBarrier = (PFN_wlVkCmdPipelineBarrier)gdpa(dev, "vkCmdPipelineBarrier");
|
||||
c->CmdBlitImage = (PFN_wlVkCmdBlitImage)gdpa(dev, "vkCmdBlitImage");
|
||||
|
||||
if (!CreateBuffer || !GetBufReqs || !AllocateMemory || !BindBufferMemory || !MapMemory || !c->CmdUpdateBuffer)
|
||||
return 0;
|
||||
|
||||
WlVkPhysicalDeviceMemoryProperties mp;
|
||||
memset(&mp, 0, sizeof mp);
|
||||
int has_mp = 0;
|
||||
if (phys && vkmod) {
|
||||
PFN_wlVkGetPhysicalDeviceMemoryProperties get_mp = NULL;
|
||||
if (inst) {
|
||||
PFN_wlVkGetInstanceProcAddr gipa = (PFN_wlVkGetInstanceProcAddr)(void *)GetProcAddress(vkmod, "vkGetInstanceProcAddr");
|
||||
if (gipa) get_mp = (PFN_wlVkGetPhysicalDeviceMemoryProperties)gipa(inst, "vkGetPhysicalDeviceMemoryProperties");
|
||||
}
|
||||
if (!get_mp) get_mp = (PFN_wlVkGetPhysicalDeviceMemoryProperties)(void *)GetProcAddress(vkmod, "vkGetPhysicalDeviceMemoryProperties");
|
||||
if (get_mp) { get_mp(phys, &mp); has_mp = 1; }
|
||||
}
|
||||
|
||||
// 1. Allocate MAILBOX buffer (exact signature WLFSR4_MAILBOX_BYTES + STORAGE_BUFFER | TRANSFER_DST)
|
||||
WlVkBufferCreateInfo bci;
|
||||
memset(&bci, 0, sizeof bci);
|
||||
bci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
bci.size = WLFSR4_MAILBOX_BYTES;
|
||||
bci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
bci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
if (CreateBuffer(dev, &bci, NULL, &c->mbox_buf) != VK_SUCCESS) return 0;
|
||||
|
||||
WlVkMemoryRequirements mr;
|
||||
memset(&mr, 0, sizeof mr);
|
||||
GetBufReqs(dev, c->mbox_buf, &mr);
|
||||
|
||||
WlVkMemoryAllocateInfo mai;
|
||||
memset(&mai, 0, sizeof mai);
|
||||
mai.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
mai.allocationSize = mr.size;
|
||||
|
||||
void *mapped = NULL;
|
||||
if (has_mp) {
|
||||
uint32_t mt = wl_seam_pick_mem(&mp, mr.memoryTypeBits,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
if (mt == 0xFFFFFFFFu) { if (c->DestroyBuffer) c->DestroyBuffer(dev, c->mbox_buf, NULL); return 0; }
|
||||
mai.memoryTypeIndex = mt;
|
||||
if (AllocateMemory(dev, &mai, NULL, &c->mbox_mem) != VK_SUCCESS ||
|
||||
BindBufferMemory(dev, c->mbox_buf, c->mbox_mem, 0) != VK_SUCCESS ||
|
||||
MapMemory(dev, c->mbox_mem, 0, WLFSR4_MAILBOX_BYTES, 0, &mapped) != VK_SUCCESS || !mapped) {
|
||||
if (c->mbox_mem && c->FreeMemory) c->FreeMemory(dev, c->mbox_mem, NULL);
|
||||
if (c->DestroyBuffer) c->DestroyBuffer(dev, c->mbox_buf, NULL);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
// VkPhysicalDevice unavailable (e.g. FSR 2 VK): probe compatible memory types until vkMapMemory succeeds
|
||||
int ok = 0;
|
||||
for (uint32_t i = 0; i < 32; i++) {
|
||||
if (!(mr.memoryTypeBits & (1u << i))) continue;
|
||||
VkDeviceMemory cand = 0;
|
||||
mai.memoryTypeIndex = i;
|
||||
if (AllocateMemory(dev, &mai, NULL, &cand) != VK_SUCCESS) continue;
|
||||
if (MapMemory(dev, cand, 0, WLFSR4_MAILBOX_BYTES, 0, &mapped) == VK_SUCCESS && mapped) {
|
||||
if (BindBufferMemory(dev, c->mbox_buf, cand, 0) == VK_SUCCESS) {
|
||||
c->mbox_mem = cand;
|
||||
ok = 1;
|
||||
break;
|
||||
}
|
||||
if (c->UnmapMemory) c->UnmapMemory(dev, cand);
|
||||
}
|
||||
if (c->FreeMemory) c->FreeMemory(dev, cand, NULL);
|
||||
mapped = NULL;
|
||||
}
|
||||
if (!ok) {
|
||||
if (c->DestroyBuffer) c->DestroyBuffer(dev, c->mbox_buf, NULL);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
memset(mapped, 0, WLFSR4_MAILBOX_BYTES);
|
||||
c->mbox = (WlFsr4Mailbox *)mapped;
|
||||
c->mbox->magic = WLFSR4_MAILBOX_MAGIC;
|
||||
c->mbox->version = WLFSR4_PROTO_VERSION;
|
||||
|
||||
// 2. Allocate MARKER buffer (exact signature WLFSR4_MARKER_BYTES + TRANSFER_DST)
|
||||
bci.size = WLFSR4_MARKER_BYTES;
|
||||
bci.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
if (CreateBuffer(dev, &bci, NULL, &c->marker_buf) != VK_SUCCESS) {
|
||||
if (c->UnmapMemory) c->UnmapMemory(dev, c->mbox_mem);
|
||||
if (c->FreeMemory) c->FreeMemory(dev, c->mbox_mem, NULL);
|
||||
if (c->DestroyBuffer) c->DestroyBuffer(dev, c->mbox_buf, NULL);
|
||||
return 0;
|
||||
}
|
||||
GetBufReqs(dev, c->marker_buf, &mr);
|
||||
mai.allocationSize = mr.size;
|
||||
mai.memoryTypeIndex = wl_seam_pick_mem(has_mp ? &mp : NULL, mr.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
|
||||
if (AllocateMemory(dev, &mai, NULL, &c->marker_mem) != VK_SUCCESS ||
|
||||
BindBufferMemory(dev, c->marker_buf, c->marker_mem, 0) != VK_SUCCESS) {
|
||||
if (c->marker_mem && c->FreeMemory) c->FreeMemory(dev, c->marker_mem, NULL);
|
||||
if (c->DestroyBuffer) c->DestroyBuffer(dev, c->marker_buf, NULL);
|
||||
if (c->UnmapMemory) c->UnmapMemory(dev, c->mbox_mem);
|
||||
if (c->FreeMemory) c->FreeMemory(dev, c->mbox_mem, NULL);
|
||||
if (c->DestroyBuffer) c->DestroyBuffer(dev, c->mbox_buf, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
c->inst = inst;
|
||||
c->dev = dev;
|
||||
c->phys = phys;
|
||||
c->next_seq = 1u;
|
||||
c->ready = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void wl_seam_destroy(WlSeamClient *c) {
|
||||
if (!c || !c->ready) return;
|
||||
if (c->marker_buf && c->DestroyBuffer) c->DestroyBuffer(c->dev, c->marker_buf, NULL);
|
||||
if (c->marker_mem && c->FreeMemory) c->FreeMemory(c->dev, c->marker_mem, NULL);
|
||||
if (c->mbox_mem && c->UnmapMemory) c->UnmapMemory(c->dev, c->mbox_mem);
|
||||
if (c->mbox_buf && c->DestroyBuffer) c->DestroyBuffer(c->dev, c->mbox_buf, NULL);
|
||||
if (c->mbox_mem && c->FreeMemory) c->FreeMemory(c->dev, c->mbox_mem, NULL);
|
||||
memset(c, 0, sizeof *c);
|
||||
}
|
||||
|
||||
static int wl_seam_dispatch(WlSeamClient *c, VkCommandBuffer cb, const WlFsr4FrameDesc *in_frame) {
|
||||
if (!c || !c->ready || !cb || !in_frame || !c->mbox) return 0;
|
||||
uint64_t seq = c->next_seq++;
|
||||
WlFsr4FrameDesc *slot = &c->mbox->slots[seq % WLFSR4_SLOTS];
|
||||
*slot = *in_frame;
|
||||
slot->seq = seq;
|
||||
MemoryBarrier();
|
||||
|
||||
WlFsr4DoorbellPayload pay;
|
||||
pay.magic = WLFSR4_DOORBELL_MAGIC;
|
||||
pay.seq = seq;
|
||||
c->CmdUpdateBuffer(cb, c->marker_buf, 0, sizeof pay, &pay);
|
||||
MemoryBarrier();
|
||||
|
||||
uint64_t ack = c->mbox->ack;
|
||||
return ((ack & WLFSR4_ACK_SEQ_MASK) == seq && (ack & WLFSR4_ACK_WORK_BIT)) ? 1 : 0;
|
||||
}
|
||||
|
||||
// Fail-closed guest-side bilinear blit fallback if the Vulkan layer did not ack a frame.
|
||||
// Ensures the game's output image is NEVER left unwritten / corrupted with stale VRAM.
|
||||
static int wl_seam_fallback_blit(WlSeamClient *c, VkCommandBuffer cb, const WlFsr4FrameDesc *f) {
|
||||
if (!c || !cb || !f || !c->CmdPipelineBarrier || !c->CmdBlitImage) return 0;
|
||||
if (!f->color.vk_image || !f->output.vk_image || f->color.vk_image == f->output.vk_image) return 0;
|
||||
uint32_t rw = f->render_w ? f->render_w : f->color.width;
|
||||
uint32_t rh = f->render_h ? f->render_h : f->color.height;
|
||||
uint32_t ow = f->output_w ? f->output_w : f->output.width;
|
||||
uint32_t oh = f->output_h ? f->output_h : f->output.height;
|
||||
if (!rw || !rh || !ow || !oh) return 0;
|
||||
|
||||
uint32_t src_lay = f->color.vk_layout ? f->color.vk_layout : 1u; /* GENERAL */
|
||||
uint32_t dst_lay = f->output.vk_layout ? f->output.vk_layout : 1u;
|
||||
|
||||
WlVkImageMemoryBarrier pre[2];
|
||||
memset(pre, 0, sizeof pre);
|
||||
pre[0].sType = 45u; /* VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER */
|
||||
pre[0].srcAccessMask = 0x00010000u; /* MEMORY_WRITE */
|
||||
pre[0].dstAccessMask = 0x00000800u; /* TRANSFER_READ */
|
||||
pre[0].oldLayout = src_lay;
|
||||
pre[0].newLayout = 6u; /* TRANSFER_SRC_OPTIMAL */
|
||||
pre[0].srcQueueFamilyIndex = 0xFFFFFFFFu;
|
||||
pre[0].dstQueueFamilyIndex = 0xFFFFFFFFu;
|
||||
pre[0].image = f->color.vk_image;
|
||||
pre[0].subresourceRange.aspectMask = 1u;
|
||||
pre[0].subresourceRange.levelCount = 1u;
|
||||
pre[0].subresourceRange.layerCount = 1u;
|
||||
|
||||
pre[1] = pre[0];
|
||||
pre[1].srcAccessMask = 0x00018000u; /* MEMORY_READ | MEMORY_WRITE */
|
||||
pre[1].dstAccessMask = 0x00001000u; /* TRANSFER_WRITE */
|
||||
pre[1].oldLayout = dst_lay;
|
||||
pre[1].newLayout = 7u; /* TRANSFER_DST_OPTIMAL */
|
||||
pre[1].image = f->output.vk_image;
|
||||
|
||||
c->CmdPipelineBarrier(cb, 0x00010000u /* ALL_COMMANDS */, 0x00001000u /* TRANSFER */, 0, 0, NULL, 0, NULL, 2, pre);
|
||||
|
||||
WlVkImageBlit reg;
|
||||
memset(®, 0, sizeof reg);
|
||||
reg.srcSubresource.aspectMask = 1u;
|
||||
reg.srcSubresource.layerCount = 1u;
|
||||
reg.srcOffsets[1].x = (int32_t)rw;
|
||||
reg.srcOffsets[1].y = (int32_t)rh;
|
||||
reg.srcOffsets[1].z = 1;
|
||||
reg.dstSubresource.aspectMask = 1u;
|
||||
reg.dstSubresource.layerCount = 1u;
|
||||
reg.dstOffsets[1].x = (int32_t)ow;
|
||||
reg.dstOffsets[1].y = (int32_t)oh;
|
||||
reg.dstOffsets[1].z = 1;
|
||||
c->CmdBlitImage(cb, f->color.vk_image, 6u, f->output.vk_image, 7u, 1u, ®, 1u /* LINEAR */);
|
||||
|
||||
WlVkImageMemoryBarrier post[2];
|
||||
post[0] = pre[0];
|
||||
post[0].srcAccessMask = 0x00000800u;
|
||||
post[0].dstAccessMask = 0x00018000u;
|
||||
post[0].oldLayout = 6u;
|
||||
post[0].newLayout = src_lay;
|
||||
|
||||
post[1] = pre[1];
|
||||
post[1].srcAccessMask = 0x00001000u;
|
||||
post[1].dstAccessMask = 0x00018000u;
|
||||
post[1].oldLayout = 7u;
|
||||
post[1].newLayout = dst_lay;
|
||||
|
||||
c->CmdPipelineBarrier(cb, 0x00001000u /* TRANSFER */, 0x00010000u /* ALL_COMMANDS */, 0, 0, NULL, 0, NULL, 2, post);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int wl_seam_dispatch_or_blit(WlSeamClient *c, VkCommandBuffer cb, const WlFsr4FrameDesc *f) {
|
||||
if (wl_seam_dispatch(c, cb, f)) return 1;
|
||||
return wl_seam_fallback_blit(c, cb, f);
|
||||
}
|
||||
|
||||
static int wl_seam_parse_backend_env(void) {
|
||||
static const char *const names[] = {
|
||||
"DROIDDECK_UPSCALE_BACKEND", "DROIDDECK_UPSCALE_ENGINE",
|
||||
"WINLATOR_FSR4_BACKEND", "WINLATOR_FSR4_ENGINE", NULL,
|
||||
};
|
||||
char buf[64];
|
||||
if (dd_env_first(names, buf, sizeof buf)) {
|
||||
if (_stricmp(buf, "fsr3_gpu") == 0 || _stricmp(buf, "fsr3") == 0) return WL_FSR_BACKEND_FSR3_GPU;
|
||||
if (_stricmp(buf, "xess3_gpu") == 0 || _stricmp(buf, "xess3") == 0 || _stricmp(buf, "xess") == 0) return WL_FSR_BACKEND_XESS3_GPU;
|
||||
if (_stricmp(buf, "fsr4_1_lite_npu") == 0 || _stricmp(buf, "fsr412_lite_npu") == 0) return WL_FSR_BACKEND_FSR4_1_LITE_NPU;
|
||||
if (_stricmp(buf, "fsr4_1_full_npu") == 0 || _stricmp(buf, "fsr411_full_npu") == 0) return WL_FSR_BACKEND_FSR4_1_FULL_NPU;
|
||||
if (_stricmp(buf, "fsr4_1_lite_gpu") == 0 || _stricmp(buf, "fsr412_lite_gpu") == 0) return WL_FSR_BACKEND_FSR4_1_LITE_GPU;
|
||||
if (_stricmp(buf, "fsr4_1_full_gpu") == 0 || _stricmp(buf, "fsr411_full_gpu") == 0) return WL_FSR_BACKEND_FSR4_1_FULL_GPU;
|
||||
if (_stricmp(buf, "fsr4_0_npu") == 0 || _stricmp(buf, "fsr4_npu") == 0 || _stricmp(buf, "fsr4") == 0) return WL_FSR_BACKEND_FSR4_0_NPU;
|
||||
}
|
||||
return WL_FSR_BACKEND_FSR4_0_NPU;
|
||||
}
|
||||
|
||||
static int wl_seam_live_backend(const WlSeamClient *c, int *out_enabled) {
|
||||
if (out_enabled) *out_enabled = 1;
|
||||
if (c && c->ready && c->mbox) {
|
||||
uint64_t ctrl = c->mbox->live_ctrl;
|
||||
if (ctrl != 0ULL) {
|
||||
if (out_enabled) *out_enabled = (ctrl & WLFSR4_CTRL_ENABLED_BIT) ? 1 : 0;
|
||||
return (int)(ctrl & WLFSR4_CTRL_BACKEND_MASK);
|
||||
}
|
||||
}
|
||||
return wl_seam_parse_backend_env();
|
||||
}
|
||||
|
||||
static void wl_seam_telemetry_begin(WlSeamClient *c, VkCommandBuffer cb) {
|
||||
if (!c || !c->ready || !cb || !c->CmdUpdateBuffer) return;
|
||||
WlFsr4DoorbellPayload pay;
|
||||
pay.magic = WLFSR4_TELEMETRY_MAGIC;
|
||||
pay.seq = 0u;
|
||||
c->CmdUpdateBuffer(cb, c->marker_buf, 0, sizeof pay, &pay);
|
||||
}
|
||||
|
||||
static void wl_seam_telemetry_end(WlSeamClient *c, VkCommandBuffer cb, const WlFsr4FrameDesc *in_frame, uint32_t cpu_us) {
|
||||
if (!c || !c->ready || !cb || !in_frame || !c->mbox || !c->CmdUpdateBuffer) return;
|
||||
uint64_t seq = c->next_seq++;
|
||||
if (seq == 0u) seq = c->next_seq++;
|
||||
WlFsr4FrameDesc *slot = &c->mbox->slots[seq % WLFSR4_SLOTS];
|
||||
*slot = *in_frame;
|
||||
slot->seq = seq;
|
||||
c->mbox->tele_gpu_us = cpu_us;
|
||||
MemoryBarrier();
|
||||
|
||||
WlFsr4DoorbellPayload pay;
|
||||
pay.magic = WLFSR4_TELEMETRY_MAGIC;
|
||||
pay.seq = seq;
|
||||
c->CmdUpdateBuffer(cb, c->marker_buf, 0, sizeof pay, &pay);
|
||||
MemoryBarrier();
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Exact vkd3d-proton ID3D12DXVKInteropDevice / ID3D12DXVKInteropDevice1 C COM vtable
|
||||
// Verified against HansKristian-Work/vkd3d-proton include/vkd3d_device_vkd3d_ext.idl.
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// {39da4e09-bd1c-4198-9fae-86bbe3be41fd}
|
||||
static const GUID WL_IID_ID3D12DXVKInteropDevice = {
|
||||
0x39da4e09, 0xbd1c, 0x4198, {0x9f, 0xae, 0x86, 0xbb, 0xe3, 0xbe, 0x41, 0xfd}
|
||||
};
|
||||
|
||||
// {902d8115-59eb-4406-9518-fe00f991ee65}
|
||||
static const GUID WL_IID_ID3D12DXVKInteropDevice1 = {
|
||||
0x902d8115, 0x59eb, 0x4406, {0x95, 0x18, 0xfe, 0x00, 0xf9, 0x91, 0xee, 0x65}
|
||||
};
|
||||
|
||||
typedef struct WlID3D12DXVKInteropDevice1 WlID3D12DXVKInteropDevice1;
|
||||
|
||||
typedef struct WlID3D12DXVKInteropDevice1Vtbl {
|
||||
// IUnknown
|
||||
HRESULT (__stdcall *QueryInterface)(WlID3D12DXVKInteropDevice1 *This, const GUID *riid, void **ppv);
|
||||
ULONG (__stdcall *AddRef)(WlID3D12DXVKInteropDevice1 *This);
|
||||
ULONG (__stdcall *Release)(WlID3D12DXVKInteropDevice1 *This);
|
||||
// ID3D12DXVKInteropDevice
|
||||
HRESULT (__stdcall *GetDXGIAdapter)(WlID3D12DXVKInteropDevice1 *This, const GUID *iid, void **object);
|
||||
HRESULT (__stdcall *GetInstanceExtensions)(WlID3D12DXVKInteropDevice1 *This, UINT *count, const char **exts);
|
||||
HRESULT (__stdcall *GetDeviceExtensions)(WlID3D12DXVKInteropDevice1 *This, UINT *count, const char **exts);
|
||||
HRESULT (__stdcall *GetDeviceFeatures)(WlID3D12DXVKInteropDevice1 *This, const void **features);
|
||||
HRESULT (__stdcall *GetVulkanHandles)(WlID3D12DXVKInteropDevice1 *This, void **vk_inst, void **vk_phys, void **vk_dev);
|
||||
HRESULT (__stdcall *GetVulkanQueueInfo)(WlID3D12DXVKInteropDevice1 *This, void *queue, void **vk_queue, UINT32 *vk_qf);
|
||||
void (__stdcall *GetVulkanImageLayout)(WlID3D12DXVKInteropDevice1 *This, void *resource, UINT32 d3d12_state, UINT32 *vk_layout);
|
||||
HRESULT (__stdcall *GetVulkanResourceInfo)(WlID3D12DXVKInteropDevice1 *This, void *resource, UINT64 *vk_handle, UINT64 *buf_offset);
|
||||
HRESULT (__stdcall *LockCommandQueue)(WlID3D12DXVKInteropDevice1 *This, void *queue);
|
||||
HRESULT (__stdcall *UnlockCommandQueue)(WlID3D12DXVKInteropDevice1 *This, void *queue);
|
||||
// ID3D12DXVKInteropDevice1
|
||||
HRESULT (__stdcall *GetVulkanResourceInfo1)(WlID3D12DXVKInteropDevice1 *This, void *resource, UINT64 *vk_handle, UINT64 *buf_offset, UINT32 *vk_format);
|
||||
HRESULT (__stdcall *CreateInteropCommandQueue)(WlID3D12DXVKInteropDevice1 *This, const void *desc, UINT32 qf, void **ppQueue);
|
||||
HRESULT (__stdcall *CreateInteropCommandAllocator)(WlID3D12DXVKInteropDevice1 *This, UINT32 type, UINT32 qf, void **ppAlloc);
|
||||
HRESULT (__stdcall *BeginVkCommandBufferInterop)(WlID3D12DXVKInteropDevice1 *This, void *cmdList, void **pVkCmdBuf);
|
||||
HRESULT (__stdcall *EndVkCommandBufferInterop)(WlID3D12DXVKInteropDevice1 *This, void *cmdList);
|
||||
} WlID3D12DXVKInteropDevice1Vtbl;
|
||||
|
||||
struct WlID3D12DXVKInteropDevice1 {
|
||||
const WlID3D12DXVKInteropDevice1Vtbl *lpVtbl;
|
||||
};
|
||||
|
||||
static inline WlID3D12DXVKInteropDevice1 *wl_query_vkd3d_interop(void *d3d12_device) {
|
||||
if (!d3d12_device) return NULL;
|
||||
typedef struct {
|
||||
HRESULT (__stdcall *QueryInterface)(void *This, const GUID *riid, void **ppv);
|
||||
} IUnkVtbl;
|
||||
typedef struct { const IUnkVtbl *lpVtbl; } IUnkObj;
|
||||
IUnkObj *obj = (IUnkObj *)d3d12_device;
|
||||
WlID3D12DXVKInteropDevice1 *out = NULL;
|
||||
if (obj->lpVtbl && obj->lpVtbl->QueryInterface(d3d12_device, &WL_IID_ID3D12DXVKInteropDevice1, (void **)&out) == S_OK && out) {
|
||||
return out;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,484 @@
|
||||
// Winlator Ludashi Direct Intel XeSS 3.0 DP4a Execution Helper (Vulkan + DX12)
|
||||
//
|
||||
// Dynamically loads Intel's official XeSS 3.0 SDK runtime (wl_xess_official.dll) and
|
||||
// executes genuine XeSS 3.0 DP4a upscaling on Adreno 840 when the user selects
|
||||
// "XeSS 3.0 DP4a (GPU)" in Winlator settings or the in-game live sidebar.
|
||||
//
|
||||
// On ANY initialization or execution failure (driver mismatch, missing extension, OOM),
|
||||
// cleanly destroys the XeSS context and returns 0 so the caller falls back seamlessly
|
||||
// to Winlator's FSR 3.1 GPU upscaler — never crashing or showing a black screen.
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "wl_seam_client.h"
|
||||
#include "wl_vkd3d_interop.h"
|
||||
|
||||
#pragma pack(push, 8)
|
||||
typedef struct _wl_xess_ctx_t *wl_xess_ctx_t;
|
||||
|
||||
typedef struct { uint32_t x; uint32_t y; } wl_xess_2d_t;
|
||||
typedef wl_xess_2d_t wl_xess_coord_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t aspectMask;
|
||||
uint32_t baseMipLevel;
|
||||
uint32_t levelCount;
|
||||
uint32_t baseArrayLayer;
|
||||
uint32_t layerCount;
|
||||
} wl_xess_vk_subres_t;
|
||||
|
||||
typedef struct {
|
||||
VkImageView imageView;
|
||||
VkImage image;
|
||||
wl_xess_vk_subres_t subresourceRange;
|
||||
uint32_t format;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
} wl_xess_vk_img_t;
|
||||
|
||||
typedef struct {
|
||||
wl_xess_vk_img_t colorTexture;
|
||||
wl_xess_vk_img_t velocityTexture;
|
||||
wl_xess_vk_img_t depthTexture;
|
||||
wl_xess_vk_img_t exposureScaleTexture;
|
||||
wl_xess_vk_img_t responsivePixelMaskTexture;
|
||||
wl_xess_vk_img_t outputTexture;
|
||||
float jitterOffsetX;
|
||||
float jitterOffsetY;
|
||||
float exposureScale;
|
||||
uint32_t resetHistory;
|
||||
uint32_t inputWidth;
|
||||
uint32_t inputHeight;
|
||||
wl_xess_coord_t inputColorBase;
|
||||
wl_xess_coord_t inputMotionVectorBase;
|
||||
wl_xess_coord_t inputDepthBase;
|
||||
wl_xess_coord_t inputResponsiveMaskBase;
|
||||
wl_xess_coord_t reserved0;
|
||||
wl_xess_coord_t outputColorBase;
|
||||
} wl_xess_vk_exec_t;
|
||||
|
||||
typedef struct {
|
||||
wl_xess_2d_t outputResolution;
|
||||
uint32_t qualitySetting;
|
||||
uint32_t initFlags;
|
||||
uint32_t creationNodeMask;
|
||||
uint32_t visibleNodeMask;
|
||||
VkDeviceMemory tempBufferHeap;
|
||||
uint64_t bufferHeapOffset;
|
||||
VkDeviceMemory tempTextureHeap;
|
||||
uint64_t textureHeapOffset;
|
||||
uint64_t pipelineCache;
|
||||
} wl_xess_vk_init_t;
|
||||
|
||||
typedef struct {
|
||||
void *pColorTexture;
|
||||
void *pVelocityTexture;
|
||||
void *pDepthTexture;
|
||||
void *pExposureScaleTexture;
|
||||
void *pResponsivePixelMaskTexture;
|
||||
void *pOutputTexture;
|
||||
float jitterOffsetX;
|
||||
float jitterOffsetY;
|
||||
float exposureScale;
|
||||
uint32_t resetHistory;
|
||||
uint32_t inputWidth;
|
||||
uint32_t inputHeight;
|
||||
wl_xess_coord_t inputColorBase;
|
||||
wl_xess_coord_t inputMotionVectorBase;
|
||||
wl_xess_coord_t inputDepthBase;
|
||||
wl_xess_coord_t inputResponsiveMaskBase;
|
||||
wl_xess_coord_t reserved0;
|
||||
wl_xess_coord_t outputColorBase;
|
||||
void *pDescriptorHeap;
|
||||
uint32_t descriptorHeapOffset;
|
||||
} wl_xess_d3d12_exec_t;
|
||||
|
||||
typedef struct {
|
||||
wl_xess_2d_t outputResolution;
|
||||
uint32_t qualitySetting;
|
||||
uint32_t initFlags;
|
||||
uint32_t creationNodeMask;
|
||||
uint32_t visibleNodeMask;
|
||||
void *pTempBufferHeap;
|
||||
uint64_t bufferHeapOffset;
|
||||
void *pTempTextureHeap;
|
||||
uint64_t textureHeapOffset;
|
||||
void *pPipelineLibrary;
|
||||
} wl_xess_d3d12_init_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
_Static_assert(sizeof(wl_xess_vk_img_t) == 48, "wl_xess_vk_img_t ABI mismatch");
|
||||
_Static_assert(sizeof(wl_xess_vk_init_t) == 64, "wl_xess_vk_init_t ABI mismatch");
|
||||
_Static_assert(sizeof(wl_xess_d3d12_init_t) == 64, "wl_xess_d3d12_init_t ABI mismatch");
|
||||
|
||||
typedef int32_t (__cdecl *PFN_xessVKCreateContext)(VkInstance, VkPhysicalDevice, VkDevice, wl_xess_ctx_t *);
|
||||
typedef int32_t (__cdecl *PFN_xessVKInit)(wl_xess_ctx_t, const wl_xess_vk_init_t *);
|
||||
typedef int32_t (__cdecl *PFN_xessVKExecute)(wl_xess_ctx_t, VkCommandBuffer, const wl_xess_vk_exec_t *);
|
||||
typedef int32_t (__cdecl *PFN_xessD3D12CreateContext)(void *, wl_xess_ctx_t *);
|
||||
typedef int32_t (__cdecl *PFN_xessD3D12Init)(wl_xess_ctx_t, const wl_xess_d3d12_init_t *);
|
||||
typedef int32_t (__cdecl *PFN_xessD3D12Execute)(wl_xess_ctx_t, void *, const wl_xess_d3d12_exec_t *);
|
||||
typedef int32_t (__cdecl *PFN_xessSetVelocityScale)(wl_xess_ctx_t, float, float);
|
||||
typedef int32_t (__cdecl *PFN_xessSetJitterScale)(wl_xess_ctx_t, float, float);
|
||||
typedef int32_t (__cdecl *PFN_xessDestroyContext)(wl_xess_ctx_t);
|
||||
|
||||
typedef struct WlXess3Api {
|
||||
int loaded;
|
||||
int available;
|
||||
DWORD load_err;
|
||||
HMODULE mod;
|
||||
PFN_xessVKCreateContext VKCreateContext;
|
||||
PFN_xessVKInit VKInit;
|
||||
PFN_xessVKExecute VKExecute;
|
||||
PFN_xessD3D12CreateContext D3D12CreateContext;
|
||||
PFN_xessD3D12Init D3D12Init;
|
||||
PFN_xessD3D12Execute D3D12Execute;
|
||||
PFN_xessSetVelocityScale SetVelocityScale;
|
||||
PFN_xessSetJitterScale SetJitterScale;
|
||||
PFN_xessDestroyContext DestroyContext;
|
||||
} WlXess3Api;
|
||||
|
||||
static WlXess3Api g_wl_xess3_api;
|
||||
|
||||
static int wl_xess3_load_api(void) {
|
||||
if (g_wl_xess3_api.loaded) return g_wl_xess3_api.available;
|
||||
g_wl_xess3_api.loaded = 1;
|
||||
SetLastError(0);
|
||||
HMODULE m = LoadLibraryA("wl_xess_official.dll");
|
||||
if (!m) m = LoadLibraryA("C:\\windows\\system32\\wl_xess_official.dll");
|
||||
if (!m) {
|
||||
g_wl_xess3_api.load_err = GetLastError();
|
||||
return 0;
|
||||
}
|
||||
g_wl_xess3_api.mod = m;
|
||||
g_wl_xess3_api.VKCreateContext = (PFN_xessVKCreateContext)(void *)GetProcAddress(m, "xessVKCreateContext");
|
||||
g_wl_xess3_api.VKInit = (PFN_xessVKInit)(void *)GetProcAddress(m, "xessVKInit");
|
||||
g_wl_xess3_api.VKExecute = (PFN_xessVKExecute)(void *)GetProcAddress(m, "xessVKExecute");
|
||||
g_wl_xess3_api.D3D12CreateContext = (PFN_xessD3D12CreateContext)(void *)GetProcAddress(m, "xessD3D12CreateContext");
|
||||
g_wl_xess3_api.D3D12Init = (PFN_xessD3D12Init)(void *)GetProcAddress(m, "xessD3D12Init");
|
||||
g_wl_xess3_api.D3D12Execute = (PFN_xessD3D12Execute)(void *)GetProcAddress(m, "xessD3D12Execute");
|
||||
g_wl_xess3_api.SetVelocityScale = (PFN_xessSetVelocityScale)(void *)GetProcAddress(m, "xessSetVelocityScale");
|
||||
g_wl_xess3_api.SetJitterScale = (PFN_xessSetJitterScale)(void *)GetProcAddress(m, "xessSetJitterScale");
|
||||
g_wl_xess3_api.DestroyContext = (PFN_xessDestroyContext)(void *)GetProcAddress(m, "xessDestroyContext");
|
||||
if ((g_wl_xess3_api.VKCreateContext && g_wl_xess3_api.VKInit && g_wl_xess3_api.VKExecute) ||
|
||||
(g_wl_xess3_api.D3D12CreateContext && g_wl_xess3_api.D3D12Init && g_wl_xess3_api.D3D12Execute)) {
|
||||
g_wl_xess3_api.available = 1;
|
||||
}
|
||||
return g_wl_xess3_api.available;
|
||||
}
|
||||
|
||||
typedef struct WlXess3State {
|
||||
wl_xess_ctx_t ctx;
|
||||
int is_vk;
|
||||
int initialized;
|
||||
int failed;
|
||||
uint32_t fail_stage; /* 1=load_dll, 2=proc, 3=create_ctx, 4=init, 5=exec, 6=missing_handles */
|
||||
int32_t fail_rc;
|
||||
uint32_t out_w, out_h;
|
||||
uint32_t quality;
|
||||
uint32_t init_flags;
|
||||
float last_mv_sx, last_mv_sy;
|
||||
} WlXess3State;
|
||||
|
||||
static void wl_xess3_destroy(WlXess3State *st) {
|
||||
if (!st) return;
|
||||
if (st->ctx && g_wl_xess3_api.DestroyContext) {
|
||||
g_wl_xess3_api.DestroyContext(st->ctx);
|
||||
}
|
||||
memset(st, 0, sizeof *st);
|
||||
}
|
||||
|
||||
static void wl_xess3_mark_fail(WlXess3State *st, uint32_t stage, int32_t rc) {
|
||||
if (!st) return;
|
||||
st->failed = 1;
|
||||
st->fail_stage = stage;
|
||||
st->fail_rc = rc;
|
||||
}
|
||||
|
||||
static void wl_xess3_tag_fallback(const WlXess3State *st, WlFsr4FrameDesc *f) {
|
||||
if (!f) return;
|
||||
f->flags |= WLFSR4_FLAG_XESS_FALLBACK;
|
||||
f->pad[0] = st ? st->fail_stage : 6u;
|
||||
f->pad[1] = st ? (uint32_t)st->fail_rc : 0u;
|
||||
}
|
||||
|
||||
static void wl_xess3_on_inactive(WlXess3State *st) {
|
||||
if (!st) return;
|
||||
// Allow clean retry when user toggles away from XeSS 3 and back
|
||||
st->failed = 0;
|
||||
}
|
||||
|
||||
static uint32_t wl_xess3_map_quality(uint32_t wl_q) {
|
||||
switch (wl_q) {
|
||||
case WLFSR4_QUALITY_ULTRA_PERF: return 100u; /* XESS_QUALITY_SETTING_ULTRA_PERFORMANCE */
|
||||
case WLFSR4_QUALITY_PERF: return 101u; /* XESS_QUALITY_SETTING_PERFORMANCE */
|
||||
case WLFSR4_QUALITY_BALANCED: return 102u; /* XESS_QUALITY_SETTING_BALANCED */
|
||||
case WLFSR4_QUALITY_QUALITY: return 103u; /* XESS_QUALITY_SETTING_QUALITY */
|
||||
case WLFSR4_QUALITY_ULTRA_QUAL: return 104u; /* XESS_QUALITY_SETTING_ULTRA_QUALITY */
|
||||
case WLFSR4_QUALITY_NATIVE_AA: return 106u; /* XESS_QUALITY_SETTING_AA */
|
||||
default: return 103u;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t wl_xess3_map_init_flags(uint32_t wl_flags) {
|
||||
uint32_t xf = 0u;
|
||||
if (wl_flags & WLFSR4_FLAG_DISPLAY_RES_MV) xf |= (1u << 0); /* HIGH_RES_MV */
|
||||
if (wl_flags & WLFSR4_FLAG_DEPTH_INVERTED) xf |= (1u << 1); /* INVERTED_DEPTH */
|
||||
if (!(wl_flags & WLFSR4_FLAG_HDR)) xf |= (1u << 6); /* LDR_INPUT_COLOR */
|
||||
if (wl_flags & WLFSR4_FLAG_MV_JITTERED) xf |= (1u << 7); /* JITTERED_MV */
|
||||
if (wl_flags & WLFSR4_FLAG_AUTO_EXPOSURE) xf |= (1u << 8); /* ENABLE_AUTOEXPOSURE */
|
||||
return xf;
|
||||
}
|
||||
|
||||
static void wl_xess3_vk_barrier(WlSeamClient *seam, VkCommandBuffer cb,
|
||||
VkImage img, uint32_t aspect,
|
||||
uint32_t old_lay, uint32_t new_lay) {
|
||||
if (!seam || !seam->CmdPipelineBarrier || !img || old_lay == new_lay) return;
|
||||
WlVkImageMemoryBarrier b;
|
||||
memset(&b, 0, sizeof b);
|
||||
b.sType = 45u; /* VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER */
|
||||
b.srcAccessMask = 0x00018000u; /* MEMORY_READ | MEMORY_WRITE */
|
||||
b.dstAccessMask = 0x00018000u;
|
||||
b.oldLayout = old_lay;
|
||||
b.newLayout = new_lay;
|
||||
b.srcQueueFamilyIndex = 0xFFFFFFFFu;
|
||||
b.dstQueueFamilyIndex = 0xFFFFFFFFu;
|
||||
b.image = img;
|
||||
b.subresourceRange.aspectMask = aspect ? aspect : 1u;
|
||||
b.subresourceRange.levelCount = 1u;
|
||||
b.subresourceRange.layerCount = 1u;
|
||||
seam->CmdPipelineBarrier(cb, 0x00010000u, 0x00010000u, 0, 0, NULL, 0, NULL, 1, &b);
|
||||
}
|
||||
|
||||
static int wl_xess3_eval_vk(WlXess3State *st, WlSeamClient *seam,
|
||||
VkCommandBuffer cb, const WlFsr4FrameDesc *f,
|
||||
const wl_xess_vk_img_t *col,
|
||||
const wl_xess_vk_img_t *dep,
|
||||
const wl_xess_vk_img_t *mv,
|
||||
const wl_xess_vk_img_t *out) {
|
||||
if (!st || st->failed || !seam || !seam->ready || !cb || !f || !col || !mv || !out) {
|
||||
if (st && !st->failed) wl_xess3_mark_fail(st, 6u, 1);
|
||||
return 0;
|
||||
}
|
||||
if (!col->image || !col->imageView || !mv->image || !mv->imageView || !out->image || !out->imageView) {
|
||||
wl_xess3_mark_fail(st, 6u, 2);
|
||||
return 0;
|
||||
}
|
||||
if (!wl_xess3_load_api()) {
|
||||
wl_xess3_mark_fail(st, 1u, (int32_t)g_wl_xess3_api.load_err);
|
||||
return 0;
|
||||
}
|
||||
if (!g_wl_xess3_api.VKCreateContext || !g_wl_xess3_api.VKInit || !g_wl_xess3_api.VKExecute) {
|
||||
wl_xess3_mark_fail(st, 2u, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t quality = wl_xess3_map_quality(f->quality_mode);
|
||||
uint32_t init_flags = wl_xess3_map_init_flags(f->flags);
|
||||
if (!dep || !dep->image || !dep->imageView) init_flags |= (1u << 0); /* HIGH_RES_MV if no depth */
|
||||
|
||||
if (!st->ctx) {
|
||||
if (!seam->inst || !seam->phys || !seam->dev) {
|
||||
wl_xess3_mark_fail(st, 6u, 3);
|
||||
return 0;
|
||||
}
|
||||
int32_t rc = g_wl_xess3_api.VKCreateContext(seam->inst, seam->phys, seam->dev, &st->ctx);
|
||||
if (rc < 0 || !st->ctx) {
|
||||
wl_xess3_mark_fail(st, 3u, rc);
|
||||
return 0;
|
||||
}
|
||||
st->is_vk = 1;
|
||||
}
|
||||
|
||||
if (!st->initialized || st->out_w != f->output_w || st->out_h != f->output_h ||
|
||||
st->quality != quality || st->init_flags != init_flags) {
|
||||
wl_xess_vk_init_t ip;
|
||||
memset(&ip, 0, sizeof ip);
|
||||
ip.outputResolution.x = f->output_w;
|
||||
ip.outputResolution.y = f->output_h;
|
||||
ip.qualitySetting = quality;
|
||||
ip.initFlags = init_flags;
|
||||
ip.creationNodeMask = 1u;
|
||||
ip.visibleNodeMask = 1u;
|
||||
int32_t rc = g_wl_xess3_api.VKInit(st->ctx, &ip);
|
||||
if (rc < 0) {
|
||||
wl_xess3_destroy(st);
|
||||
wl_xess3_mark_fail(st, 4u, rc);
|
||||
return 0;
|
||||
}
|
||||
st->initialized = 1;
|
||||
st->out_w = f->output_w;
|
||||
st->out_h = f->output_h;
|
||||
st->quality = quality;
|
||||
st->init_flags = init_flags;
|
||||
st->last_mv_sx = 1e9f;
|
||||
st->last_mv_sy = 1e9f;
|
||||
}
|
||||
|
||||
if (g_wl_xess3_api.SetVelocityScale && (st->last_mv_sx != f->mv_scale_x || st->last_mv_sy != f->mv_scale_y)) {
|
||||
g_wl_xess3_api.SetVelocityScale(st->ctx, f->mv_scale_x, f->mv_scale_y);
|
||||
st->last_mv_sx = f->mv_scale_x;
|
||||
st->last_mv_sy = f->mv_scale_y;
|
||||
}
|
||||
|
||||
// Ensure XeSS VK layout contract: inputs = SHADER_READ_ONLY_OPTIMAL (5), output = GENERAL (1)
|
||||
uint32_t col_lay = f->color.vk_layout ? f->color.vk_layout : 5u;
|
||||
uint32_t dep_lay = f->depth.vk_layout ? f->depth.vk_layout : 5u;
|
||||
uint32_t mv_lay = f->motion.vk_layout ? f->motion.vk_layout : 5u;
|
||||
uint32_t out_lay = f->output.vk_layout ? f->output.vk_layout : 1u;
|
||||
|
||||
wl_xess3_vk_barrier(seam, cb, col->image, 1u, col_lay, 5u);
|
||||
if (dep && dep->image) wl_xess3_vk_barrier(seam, cb, dep->image, dep->subresourceRange.aspectMask ? dep->subresourceRange.aspectMask : 2u, dep_lay, 5u);
|
||||
wl_xess3_vk_barrier(seam, cb, mv->image, 1u, mv_lay, 5u);
|
||||
wl_xess3_vk_barrier(seam, cb, out->image, 1u, out_lay, 1u);
|
||||
|
||||
wl_xess_vk_exec_t ep;
|
||||
memset(&ep, 0, sizeof ep);
|
||||
ep.colorTexture = *col;
|
||||
ep.velocityTexture = *mv;
|
||||
if (dep && dep->image && dep->imageView) ep.depthTexture = *dep;
|
||||
ep.outputTexture = *out;
|
||||
ep.jitterOffsetX = f->jitter_x;
|
||||
ep.jitterOffsetY = f->jitter_y;
|
||||
ep.exposureScale = (f->pre_exposure > 0.0f) ? f->pre_exposure : 1.0f;
|
||||
ep.resetHistory = (f->flags & WLFSR4_FLAG_RESET) ? 1u : 0u;
|
||||
ep.inputWidth = f->render_w;
|
||||
ep.inputHeight = f->render_h;
|
||||
|
||||
LARGE_INTEGER t0, t1, freq;
|
||||
QueryPerformanceFrequency(&freq);
|
||||
QueryPerformanceCounter(&t0);
|
||||
|
||||
wl_seam_telemetry_begin(seam, cb);
|
||||
int32_t rc = g_wl_xess3_api.VKExecute(st->ctx, cb, &ep);
|
||||
|
||||
// Restore caller layouts
|
||||
wl_xess3_vk_barrier(seam, cb, col->image, 1u, 5u, col_lay);
|
||||
if (dep && dep->image) wl_xess3_vk_barrier(seam, cb, dep->image, dep->subresourceRange.aspectMask ? dep->subresourceRange.aspectMask : 2u, 5u, dep_lay);
|
||||
wl_xess3_vk_barrier(seam, cb, mv->image, 1u, 5u, mv_lay);
|
||||
wl_xess3_vk_barrier(seam, cb, out->image, 1u, 1u, out_lay);
|
||||
|
||||
QueryPerformanceCounter(&t1);
|
||||
uint32_t cpu_us = (freq.QuadPart > 0) ? (uint32_t)(((t1.QuadPart - t0.QuadPart) * 1000000ULL) / (uint64_t)freq.QuadPart) : 0u;
|
||||
|
||||
if (rc < 0) {
|
||||
wl_xess3_destroy(st);
|
||||
wl_xess3_mark_fail(st, 5u, rc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
wl_seam_telemetry_end(seam, cb, f, cpu_us);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int wl_xess3_eval_d3d12(WlXess3State *st, WlSeamClient *seam,
|
||||
WlID3D12DXVKInteropDevice1 *interop,
|
||||
void *d3d12_dev, void *d3d12_cmdlist,
|
||||
const WlFsr4FrameDesc *f,
|
||||
void *res_col, void *res_dep,
|
||||
void *res_mv, void *res_out) {
|
||||
if (!st || st->failed || !d3d12_dev || !d3d12_cmdlist || !f || !res_col || !res_mv || !res_out) {
|
||||
if (st && !st->failed) wl_xess3_mark_fail(st, 6u, 4);
|
||||
return 0;
|
||||
}
|
||||
if (!wl_xess3_load_api()) {
|
||||
wl_xess3_mark_fail(st, 1u, (int32_t)g_wl_xess3_api.load_err);
|
||||
return 0;
|
||||
}
|
||||
if (!g_wl_xess3_api.D3D12CreateContext || !g_wl_xess3_api.D3D12Init || !g_wl_xess3_api.D3D12Execute) {
|
||||
wl_xess3_mark_fail(st, 2u, 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t quality = wl_xess3_map_quality(f->quality_mode);
|
||||
uint32_t init_flags = wl_xess3_map_init_flags(f->flags);
|
||||
if (!res_dep) init_flags |= (1u << 0); /* HIGH_RES_MV if no depth */
|
||||
|
||||
if (!st->ctx) {
|
||||
int32_t rc = g_wl_xess3_api.D3D12CreateContext(d3d12_dev, &st->ctx);
|
||||
if (rc < 0 || !st->ctx) {
|
||||
wl_xess3_mark_fail(st, 3u, rc);
|
||||
return 0;
|
||||
}
|
||||
st->is_vk = 0;
|
||||
}
|
||||
|
||||
if (!st->initialized || st->out_w != f->output_w || st->out_h != f->output_h ||
|
||||
st->quality != quality || st->init_flags != init_flags) {
|
||||
wl_xess_d3d12_init_t ip;
|
||||
memset(&ip, 0, sizeof ip);
|
||||
ip.outputResolution.x = f->output_w;
|
||||
ip.outputResolution.y = f->output_h;
|
||||
ip.qualitySetting = quality;
|
||||
ip.initFlags = init_flags;
|
||||
ip.creationNodeMask = 1u;
|
||||
ip.visibleNodeMask = 1u;
|
||||
int32_t rc = g_wl_xess3_api.D3D12Init(st->ctx, &ip);
|
||||
if (rc < 0) {
|
||||
wl_xess3_destroy(st);
|
||||
wl_xess3_mark_fail(st, 4u, rc);
|
||||
return 0;
|
||||
}
|
||||
st->initialized = 1;
|
||||
st->out_w = f->output_w;
|
||||
st->out_h = f->output_h;
|
||||
st->quality = quality;
|
||||
st->init_flags = init_flags;
|
||||
st->last_mv_sx = 1e9f;
|
||||
st->last_mv_sy = 1e9f;
|
||||
}
|
||||
|
||||
if (g_wl_xess3_api.SetVelocityScale && (st->last_mv_sx != f->mv_scale_x || st->last_mv_sy != f->mv_scale_y)) {
|
||||
g_wl_xess3_api.SetVelocityScale(st->ctx, f->mv_scale_x, f->mv_scale_y);
|
||||
st->last_mv_sx = f->mv_scale_x;
|
||||
st->last_mv_sy = f->mv_scale_y;
|
||||
}
|
||||
|
||||
wl_xess_d3d12_exec_t ep;
|
||||
memset(&ep, 0, sizeof ep);
|
||||
ep.pColorTexture = res_col;
|
||||
ep.pVelocityTexture = res_mv;
|
||||
ep.pDepthTexture = res_dep;
|
||||
ep.pOutputTexture = res_out;
|
||||
ep.jitterOffsetX = f->jitter_x;
|
||||
ep.jitterOffsetY = f->jitter_y;
|
||||
ep.exposureScale = (f->pre_exposure > 0.0f) ? f->pre_exposure : 1.0f;
|
||||
ep.resetHistory = (f->flags & WLFSR4_FLAG_RESET) ? 1u : 0u;
|
||||
ep.inputWidth = f->render_w;
|
||||
ep.inputHeight = f->render_h;
|
||||
|
||||
// Bracket with Vulkan timestamp telemetry if interop is available
|
||||
if (seam && seam->ready && interop) {
|
||||
void *vk_cb = NULL;
|
||||
if (interop->lpVtbl->BeginVkCommandBufferInterop(interop, d3d12_cmdlist, &vk_cb) == S_OK && vk_cb) {
|
||||
wl_seam_telemetry_begin(seam, (VkCommandBuffer)vk_cb);
|
||||
interop->lpVtbl->EndVkCommandBufferInterop(interop, d3d12_cmdlist);
|
||||
}
|
||||
}
|
||||
|
||||
LARGE_INTEGER t0, t1, freq;
|
||||
QueryPerformanceFrequency(&freq);
|
||||
QueryPerformanceCounter(&t0);
|
||||
|
||||
int32_t rc = g_wl_xess3_api.D3D12Execute(st->ctx, d3d12_cmdlist, &ep);
|
||||
|
||||
QueryPerformanceCounter(&t1);
|
||||
uint32_t cpu_us = (freq.QuadPart > 0) ? (uint32_t)(((t1.QuadPart - t0.QuadPart) * 1000000ULL) / (uint64_t)freq.QuadPart) : 0u;
|
||||
|
||||
if (rc < 0) {
|
||||
wl_xess3_destroy(st);
|
||||
wl_xess3_mark_fail(st, 5u, rc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (seam && seam->ready && interop) {
|
||||
void *vk_cb = NULL;
|
||||
if (interop->lpVtbl->BeginVkCommandBufferInterop(interop, d3d12_cmdlist, &vk_cb) == S_OK && vk_cb) {
|
||||
wl_seam_telemetry_end(seam, (VkCommandBuffer)vk_cb, f, cpu_us);
|
||||
interop->lpVtbl->EndVkCommandBufferInterop(interop, d3d12_cmdlist);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,824 @@
|
||||
// Winlator Ludashi Intel XeSS (libxess.dll) -> AMD FSR 4 INT8 Hexagon HTP NPU Bridge
|
||||
//
|
||||
// Implements the full Intel XeSS 1.3 / 2.0 C ABI for BOTH:
|
||||
// - DirectX 12 (via vkd3d-proton ID3D12DXVKInteropDevice1 zero-copy interop)
|
||||
// - Vulkan (direct VkImage / VkCommandBuffer)
|
||||
//
|
||||
// Requires ZERO GPU spoofing and ZERO driver signature checks — works cleanly on
|
||||
// Adreno / Turnip in No-GPU-Spoof mode as well as RTX/RDNA4 spoof modes.
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "wl_seam_client.h"
|
||||
#include "wl_vkd3d_interop.h"
|
||||
#include "wl_xess3_direct.h"
|
||||
|
||||
// ---- Official Intel XeSS C ABI (verified from intel/xess xess.h, xess_d3d12.h, xess_vk.h) ----
|
||||
#pragma pack(push, 8)
|
||||
|
||||
typedef struct _xess_context_handle_t *xess_context_handle_t;
|
||||
|
||||
typedef struct _xess_version_t {
|
||||
uint16_t major;
|
||||
uint16_t minor;
|
||||
uint16_t patch;
|
||||
uint16_t reserved;
|
||||
} xess_version_t;
|
||||
|
||||
typedef struct _xess_2d_t {
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
} xess_2d_t;
|
||||
|
||||
typedef xess_2d_t xess_coord_t;
|
||||
|
||||
typedef enum _xess_quality_settings_t {
|
||||
XESS_QUALITY_SETTING_ULTRA_PERFORMANCE = 100,
|
||||
XESS_QUALITY_SETTING_PERFORMANCE = 101,
|
||||
XESS_QUALITY_SETTING_BALANCED = 102,
|
||||
XESS_QUALITY_SETTING_QUALITY = 103,
|
||||
XESS_QUALITY_SETTING_ULTRA_QUALITY = 104,
|
||||
XESS_QUALITY_SETTING_ULTRA_QUALITY_PLUS = 105,
|
||||
XESS_QUALITY_SETTING_AA = 106,
|
||||
} xess_quality_settings_t;
|
||||
|
||||
typedef enum _xess_init_flags_t {
|
||||
XESS_INIT_FLAG_NONE = 0,
|
||||
XESS_INIT_FLAG_HIGH_RES_MV = 1 << 0,
|
||||
XESS_INIT_FLAG_INVERTED_DEPTH = 1 << 1,
|
||||
XESS_INIT_FLAG_EXPOSURE_SCALE_TEXTURE = 1 << 2,
|
||||
XESS_INIT_FLAG_RESPONSIVE_PIXEL_MASK = 1 << 3,
|
||||
XESS_INIT_FLAG_USE_NDC_VELOCITY = 1 << 4,
|
||||
XESS_INIT_FLAG_EXTERNAL_DESCRIPTOR_HEAP = 1 << 5,
|
||||
XESS_INIT_FLAG_LDR_INPUT_COLOR = 1 << 6,
|
||||
XESS_INIT_FLAG_JITTERED_MV = 1 << 7,
|
||||
XESS_INIT_FLAG_ENABLE_AUTOEXPOSURE = 1 << 8,
|
||||
} xess_init_flags_t;
|
||||
|
||||
typedef struct _xess_properties_t {
|
||||
uint32_t requiredDescriptorCount;
|
||||
uint64_t tempBufferHeapSize;
|
||||
uint64_t tempTextureHeapSize;
|
||||
} xess_properties_t;
|
||||
|
||||
typedef enum _xess_result_t {
|
||||
XESS_RESULT_WARNING_NONEXISTING_FOLDER = 1,
|
||||
XESS_RESULT_WARNING_OLD_DRIVER = 2,
|
||||
XESS_RESULT_SUCCESS = 0,
|
||||
XESS_RESULT_ERROR_UNSUPPORTED_DEVICE = -1,
|
||||
XESS_RESULT_ERROR_UNSUPPORTED_DRIVER = -2,
|
||||
XESS_RESULT_ERROR_UNINITIALIZED = -3,
|
||||
XESS_RESULT_ERROR_INVALID_ARGUMENT = -4,
|
||||
XESS_RESULT_ERROR_DEVICE_OUT_OF_MEMORY = -5,
|
||||
XESS_RESULT_ERROR_DEVICE = -6,
|
||||
XESS_RESULT_ERROR_NOT_IMPLEMENTED = -7,
|
||||
XESS_RESULT_ERROR_INVALID_CONTEXT = -8,
|
||||
XESS_RESULT_ERROR_OPERATION_IN_PROGRESS = -9,
|
||||
XESS_RESULT_ERROR_UNSUPPORTED = -10,
|
||||
XESS_RESULT_ERROR_CANT_LOAD_LIBRARY = -11,
|
||||
XESS_RESULT_ERROR_WRONG_CALL_ORDER = -12,
|
||||
XESS_RESULT_ERROR_UNKNOWN = -1000,
|
||||
} xess_result_t;
|
||||
|
||||
typedef enum _xess_logging_level_t {
|
||||
XESS_LOGGING_LEVEL_DEBUG = 0,
|
||||
XESS_LOGGING_LEVEL_INFO = 1,
|
||||
XESS_LOGGING_LEVEL_WARNING = 2,
|
||||
XESS_LOGGING_LEVEL_ERROR = 3,
|
||||
} xess_logging_level_t;
|
||||
|
||||
typedef void (*xess_app_log_callback_t)(const char *message, xess_logging_level_t loggingLevel);
|
||||
|
||||
typedef struct _xess_d3d12_execute_params_t {
|
||||
void *pColorTexture;
|
||||
void *pVelocityTexture;
|
||||
void *pDepthTexture;
|
||||
void *pExposureScaleTexture;
|
||||
void *pResponsivePixelMaskTexture;
|
||||
void *pOutputTexture;
|
||||
float jitterOffsetX;
|
||||
float jitterOffsetY;
|
||||
float exposureScale;
|
||||
uint32_t resetHistory;
|
||||
uint32_t inputWidth;
|
||||
uint32_t inputHeight;
|
||||
xess_coord_t inputColorBase;
|
||||
xess_coord_t inputMotionVectorBase;
|
||||
xess_coord_t inputDepthBase;
|
||||
xess_coord_t inputResponsiveMaskBase;
|
||||
xess_coord_t reserved0;
|
||||
xess_coord_t outputColorBase;
|
||||
void *pDescriptorHeap;
|
||||
uint32_t descriptorHeapOffset;
|
||||
} xess_d3d12_execute_params_t;
|
||||
|
||||
typedef struct _xess_d3d12_init_params_t {
|
||||
xess_2d_t outputResolution;
|
||||
xess_quality_settings_t qualitySetting;
|
||||
uint32_t initFlags;
|
||||
uint32_t creationNodeMask;
|
||||
uint32_t visibleNodeMask;
|
||||
void *pTempBufferHeap;
|
||||
uint64_t bufferHeapOffset;
|
||||
void *pTempTextureHeap;
|
||||
uint64_t textureHeapOffset;
|
||||
void *pPipelineLibrary;
|
||||
} xess_d3d12_init_params_t;
|
||||
|
||||
typedef struct _wl_vk_subresource_range {
|
||||
uint32_t aspectMask;
|
||||
uint32_t baseMipLevel;
|
||||
uint32_t levelCount;
|
||||
uint32_t baseArrayLayer;
|
||||
uint32_t layerCount;
|
||||
} WlVkSubresourceRange;
|
||||
|
||||
typedef struct _xess_vk_image_view_info {
|
||||
VkImageView imageView;
|
||||
VkImage image;
|
||||
WlVkSubresourceRange subresourceRange;
|
||||
uint32_t format;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
} xess_vk_image_view_info;
|
||||
|
||||
typedef struct _xess_vk_execute_params_t {
|
||||
xess_vk_image_view_info colorTexture;
|
||||
xess_vk_image_view_info velocityTexture;
|
||||
xess_vk_image_view_info depthTexture;
|
||||
xess_vk_image_view_info exposureScaleTexture;
|
||||
xess_vk_image_view_info responsivePixelMaskTexture;
|
||||
xess_vk_image_view_info outputTexture;
|
||||
float jitterOffsetX;
|
||||
float jitterOffsetY;
|
||||
float exposureScale;
|
||||
uint32_t resetHistory;
|
||||
uint32_t inputWidth;
|
||||
uint32_t inputHeight;
|
||||
xess_coord_t inputColorBase;
|
||||
xess_coord_t inputMotionVectorBase;
|
||||
xess_coord_t inputDepthBase;
|
||||
xess_coord_t inputResponsiveMaskBase;
|
||||
xess_coord_t reserved0;
|
||||
xess_coord_t outputColorBase;
|
||||
} xess_vk_execute_params_t;
|
||||
|
||||
typedef struct _xess_vk_init_params_t {
|
||||
xess_2d_t outputResolution;
|
||||
xess_quality_settings_t qualitySetting;
|
||||
uint32_t initFlags;
|
||||
uint32_t creationNodeMask;
|
||||
uint32_t visibleNodeMask;
|
||||
VkDeviceMemory tempBufferHeap;
|
||||
uint64_t bufferHeapOffset;
|
||||
VkDeviceMemory tempTextureHeap;
|
||||
uint64_t textureHeapOffset;
|
||||
uint64_t pipelineCache;
|
||||
} xess_vk_init_params_t;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
// Compile-time ABI sanity checks
|
||||
_Static_assert(sizeof(xess_quality_settings_t) == 4, "xess_quality_settings_t size");
|
||||
_Static_assert(sizeof(xess_init_flags_t) == 4, "xess_init_flags_t size");
|
||||
_Static_assert(sizeof(xess_result_t) == 4, "xess_result_t size");
|
||||
_Static_assert(sizeof(xess_properties_t) == 24, "xess_properties_t size");
|
||||
_Static_assert(sizeof(xess_vk_image_view_info) == 48, "xess_vk_image_view_info size");
|
||||
|
||||
// ---- Internal context ----
|
||||
#define WL_XESS_MAGIC 0x58455353u /* "XESS" */
|
||||
|
||||
typedef struct WlXessCtx {
|
||||
uint32_t magic;
|
||||
int is_vk;
|
||||
int initialized;
|
||||
int pipelines_built;
|
||||
int needs_reset;
|
||||
int force_legacy_scales;
|
||||
|
||||
xess_2d_t out_res;
|
||||
xess_quality_settings_t quality;
|
||||
uint32_t init_flags;
|
||||
xess_d3d12_init_params_t d3d12_init;
|
||||
xess_vk_init_params_t vk_init;
|
||||
|
||||
float jitter_scale_x;
|
||||
float jitter_scale_y;
|
||||
float vel_scale_x;
|
||||
float vel_scale_y;
|
||||
float exposure_mult;
|
||||
float max_responsive_mask;
|
||||
|
||||
WlSeamClient seam;
|
||||
WlID3D12DXVKInteropDevice1 *dx12_interop;
|
||||
void *d3d12_dev;
|
||||
WlXess3State xess3;
|
||||
} WlXessCtx;
|
||||
|
||||
static WlXessCtx *xess_unwrap(xess_context_handle_t h) {
|
||||
if (!h) return NULL;
|
||||
WlXessCtx *c = (WlXessCtx *)h;
|
||||
return (c->magic == WL_XESS_MAGIC) ? c : NULL;
|
||||
}
|
||||
|
||||
static float xess_quality_ratio(xess_quality_settings_t q, int legacy) {
|
||||
(void)legacy;
|
||||
switch (q) {
|
||||
case XESS_QUALITY_SETTING_ULTRA_PERFORMANCE: return 3.0f;
|
||||
case XESS_QUALITY_SETTING_PERFORMANCE: return 2.0f;
|
||||
case XESS_QUALITY_SETTING_BALANCED: return 1.7f;
|
||||
case XESS_QUALITY_SETTING_QUALITY: return 1.5f;
|
||||
case XESS_QUALITY_SETTING_ULTRA_QUALITY: return 1.3f;
|
||||
case XESS_QUALITY_SETTING_ULTRA_QUALITY_PLUS: return 1.3f;
|
||||
case XESS_QUALITY_SETTING_AA: return 1.0f;
|
||||
default: return 1.7f;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t xess_quality_to_wl(xess_quality_settings_t q) {
|
||||
switch (q) {
|
||||
case XESS_QUALITY_SETTING_ULTRA_PERFORMANCE: return WLFSR4_QUALITY_ULTRA_PERF;
|
||||
case XESS_QUALITY_SETTING_PERFORMANCE: return WLFSR4_QUALITY_PERF;
|
||||
case XESS_QUALITY_SETTING_BALANCED: return WLFSR4_QUALITY_BALANCED;
|
||||
case XESS_QUALITY_SETTING_QUALITY: return WLFSR4_QUALITY_QUALITY;
|
||||
case XESS_QUALITY_SETTING_ULTRA_QUALITY:
|
||||
case XESS_QUALITY_SETTING_ULTRA_QUALITY_PLUS: return WLFSR4_QUALITY_ULTRA_QUAL;
|
||||
case XESS_QUALITY_SETTING_AA: return WLFSR4_QUALITY_NATIVE_AA;
|
||||
default: return WLFSR4_QUALITY_AUTO;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t xess_flags_to_wl(uint32_t xflags) {
|
||||
uint32_t f = 0;
|
||||
if (!(xflags & XESS_INIT_FLAG_LDR_INPUT_COLOR)) f |= WLFSR4_FLAG_HDR;
|
||||
if (xflags & XESS_INIT_FLAG_INVERTED_DEPTH) f |= WLFSR4_FLAG_DEPTH_INVERTED;
|
||||
if (xflags & XESS_INIT_FLAG_HIGH_RES_MV) f |= WLFSR4_FLAG_DISPLAY_RES_MV;
|
||||
if (xflags & XESS_INIT_FLAG_JITTERED_MV) f |= WLFSR4_FLAG_MV_JITTERED;
|
||||
if (xflags & XESS_INIT_FLAG_ENABLE_AUTOEXPOSURE) f |= WLFSR4_FLAG_AUTO_EXPOSURE;
|
||||
return f;
|
||||
}
|
||||
|
||||
static void xess_fill_dx12_ref(WlID3D12DXVKInteropDevice1 *interop, WlFsr4ImageRef *dst,
|
||||
void *d3d12_res, uint32_t d3d12_state, uint32_t w, uint32_t h, int is_depth) {
|
||||
memset(dst, 0, sizeof *dst);
|
||||
if (!interop || !d3d12_res) return;
|
||||
UINT64 vk_img = 0, off = 0;
|
||||
UINT32 vk_fmt = 0;
|
||||
if (interop->lpVtbl->GetVulkanResourceInfo1(interop, d3d12_res, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
||||
UINT32 layout = (d3d12_state == 0x8u) ? 1u : (is_depth ? 4u : 5u);
|
||||
if (interop->lpVtbl->GetVulkanImageLayout) {
|
||||
UINT32 queried = 0;
|
||||
interop->lpVtbl->GetVulkanImageLayout(interop, d3d12_res, d3d12_state, &queried);
|
||||
if (queried != 0) layout = queried;
|
||||
}
|
||||
dst->vk_image = vk_img;
|
||||
dst->vk_format = vk_fmt;
|
||||
dst->vk_layout = layout;
|
||||
dst->width = w;
|
||||
dst->height = h;
|
||||
dst->aspect = is_depth ? 2u : 1u;
|
||||
}
|
||||
}
|
||||
|
||||
static void xess_fill_vk_ref(WlFsr4ImageRef *dst, const xess_vk_image_view_info *src,
|
||||
uint32_t layout, uint32_t fallback_w, uint32_t fallback_h, int is_depth) {
|
||||
memset(dst, 0, sizeof *dst);
|
||||
if (!src || !src->image) return;
|
||||
dst->vk_image = src->image;
|
||||
dst->vk_view = src->imageView;
|
||||
dst->vk_format = src->format;
|
||||
dst->vk_layout = layout;
|
||||
dst->width = src->width ? src->width : fallback_w;
|
||||
dst->height = src->height ? src->height : fallback_h;
|
||||
dst->aspect = src->subresourceRange.aspectMask ? src->subresourceRange.aspectMask : (is_depth ? 2u : 1u);
|
||||
}
|
||||
|
||||
// ---- Core XeSS Exports ----
|
||||
|
||||
__declspec(dllexport) xess_result_t xessGetVersion(xess_version_t *pVersion) {
|
||||
if (!pVersion) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
pVersion->major = 1;
|
||||
pVersion->minor = 3;
|
||||
pVersion->patch = 1;
|
||||
pVersion->reserved = 0;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessGetIntelXeFXVersion(xess_context_handle_t hContext, xess_version_t *pVersion) {
|
||||
(void)hContext;
|
||||
if (!pVersion) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
pVersion->major = 0;
|
||||
pVersion->minor = 0;
|
||||
pVersion->patch = 0;
|
||||
pVersion->reserved = 0;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessIsOptimalDriver(xess_context_handle_t hContext) {
|
||||
(void)hContext;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessSetLoggingCallback(xess_context_handle_t hContext,
|
||||
xess_logging_level_t loggingLevel,
|
||||
xess_app_log_callback_t loggingCallback) {
|
||||
(void)hContext; (void)loggingLevel; (void)loggingCallback;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessGetProperties(xess_context_handle_t hContext,
|
||||
const xess_2d_t *pOutputResolution,
|
||||
xess_properties_t *pBindingProperties) {
|
||||
(void)hContext; (void)pOutputResolution;
|
||||
if (!pBindingProperties) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
pBindingProperties->requiredDescriptorCount = 1;
|
||||
pBindingProperties->tempBufferHeapSize = 65536;
|
||||
pBindingProperties->tempTextureHeapSize = 65536;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessGetInputResolution(xess_context_handle_t hContext,
|
||||
const xess_2d_t *pOutputResolution,
|
||||
xess_quality_settings_t qualitySettings,
|
||||
xess_2d_t *pInputResolution) {
|
||||
if (!pOutputResolution || !pInputResolution) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
float r = xess_quality_ratio(qualitySettings, c ? c->force_legacy_scales : 0);
|
||||
uint32_t w = (uint32_t)((float)pOutputResolution->x / r);
|
||||
uint32_t h = (uint32_t)((float)pOutputResolution->y / r);
|
||||
if (w < 16) w = 16;
|
||||
if (h < 16) h = 16;
|
||||
pInputResolution->x = w;
|
||||
pInputResolution->y = h;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessGetOptimalInputResolution(xess_context_handle_t hContext,
|
||||
const xess_2d_t *pOutputResolution,
|
||||
xess_quality_settings_t qualitySettings,
|
||||
xess_2d_t *pInputResolutionOptimal,
|
||||
xess_2d_t *pInputResolutionMin,
|
||||
xess_2d_t *pInputResolutionMax) {
|
||||
if (!pOutputResolution || !pInputResolutionOptimal) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
float r = xess_quality_ratio(qualitySettings, c ? c->force_legacy_scales : 0);
|
||||
uint32_t w = (uint32_t)((float)pOutputResolution->x / r);
|
||||
uint32_t h = (uint32_t)((float)pOutputResolution->y / r);
|
||||
if (w < 16) w = 16;
|
||||
if (h < 16) h = 16;
|
||||
pInputResolutionOptimal->x = w;
|
||||
pInputResolutionOptimal->y = h;
|
||||
if (pInputResolutionMin) {
|
||||
pInputResolutionMin->x = (uint32_t)((float)pOutputResolution->x / 3.0f);
|
||||
pInputResolutionMin->y = (uint32_t)((float)pOutputResolution->y / 3.0f);
|
||||
}
|
||||
if (pInputResolutionMax) {
|
||||
pInputResolutionMax->x = pOutputResolution->x;
|
||||
pInputResolutionMax->y = pOutputResolution->y;
|
||||
}
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessGetJitterScale(xess_context_handle_t hContext, float *pX, float *pY) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
if (!pX || !pY) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
*pX = c->jitter_scale_x;
|
||||
*pY = c->jitter_scale_y;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessSetJitterScale(xess_context_handle_t hContext, float x, float y) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
c->jitter_scale_x = x;
|
||||
c->jitter_scale_y = y;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessGetVelocityScale(xess_context_handle_t hContext, float *pX, float *pY) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
if (!pX || !pY) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
*pX = c->vel_scale_x;
|
||||
*pY = c->vel_scale_y;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessSetVelocityScale(xess_context_handle_t hContext, float x, float y) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
c->vel_scale_x = x;
|
||||
c->vel_scale_y = y;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessSetExposureMultiplier(xess_context_handle_t hContext, float scale) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
c->exposure_mult = scale > 0.0f ? scale : 1.0f;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessGetExposureMultiplier(xess_context_handle_t hContext, float *pScale) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
if (!pScale) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
*pScale = c->exposure_mult;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessSetMaxResponsiveMaskValue(xess_context_handle_t hContext, float value) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
if (value < 0.0f || value > 1.0f) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
c->max_responsive_mask = value;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessGetMaxResponsiveMaskValue(xess_context_handle_t hContext, float *pValue) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
if (!pValue) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
*pValue = c->max_responsive_mask;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessForceLegacyScaleFactors(xess_context_handle_t hContext, bool force) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
c->force_legacy_scales = force ? 1 : 0;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessGetPipelineBuildStatus(xess_context_handle_t hContext) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessDestroyContext(xess_context_handle_t hContext) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
wl_xess3_destroy(&c->xess3);
|
||||
wl_seam_destroy(&c->seam);
|
||||
if (c->dx12_interop) {
|
||||
c->dx12_interop->lpVtbl->Release(c->dx12_interop);
|
||||
c->dx12_interop = NULL;
|
||||
}
|
||||
c->magic = 0;
|
||||
free(c);
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
// Debug / optional exports
|
||||
__declspec(dllexport) xess_result_t xessSelectNetworkModel(xess_context_handle_t hContext, uint32_t network) {
|
||||
(void)hContext; (void)network;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessStartDump(xess_context_handle_t hContext, const void *dumpParams) {
|
||||
(void)hContext; (void)dumpParams;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessGetProfilingData(xess_context_handle_t hContext, void **pProfilingData) {
|
||||
(void)hContext;
|
||||
if (pProfilingData) *pProfilingData = NULL;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessD3D12GetProfilingData(xess_context_handle_t hContext, void **pProfilingData) {
|
||||
(void)hContext;
|
||||
if (pProfilingData) *pProfilingData = NULL;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessD3D12GetResourcesToDump(xess_context_handle_t hContext, void **pResourcesToDump) {
|
||||
(void)hContext;
|
||||
if (pResourcesToDump) *pResourcesToDump = NULL;
|
||||
return XESS_RESULT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessVKGetResourcesToDump(xess_context_handle_t hContext, void **pResourcesToDump) {
|
||||
(void)hContext;
|
||||
if (pResourcesToDump) *pResourcesToDump = NULL;
|
||||
return XESS_RESULT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessSetContextParameterF(xess_context_handle_t hContext, const char *name, float val) {
|
||||
(void)hContext; (void)name; (void)val;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
// ---- DirectX 12 XeSS Exports ----
|
||||
|
||||
__declspec(dllexport) xess_result_t xessD3D12CreateContext(void *pDevice, xess_context_handle_t *phContext) {
|
||||
if (!pDevice || !phContext) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
WlXessCtx *c = (WlXessCtx *)calloc(1, sizeof *c);
|
||||
if (!c) return XESS_RESULT_ERROR_UNKNOWN;
|
||||
|
||||
c->magic = WL_XESS_MAGIC;
|
||||
c->is_vk = 0;
|
||||
c->needs_reset = 1;
|
||||
c->jitter_scale_x = 1.0f;
|
||||
c->jitter_scale_y = 1.0f;
|
||||
c->vel_scale_x = 1.0f;
|
||||
c->vel_scale_y = 1.0f;
|
||||
c->exposure_mult = 1.0f;
|
||||
c->max_responsive_mask = 1.0f;
|
||||
|
||||
c->d3d12_dev = pDevice;
|
||||
c->dx12_interop = wl_query_vkd3d_interop(pDevice);
|
||||
if (c->dx12_interop) {
|
||||
void *vk_inst = NULL, *vk_phys = NULL, *vk_dev = NULL;
|
||||
if (c->dx12_interop->lpVtbl->GetVulkanHandles(c->dx12_interop, &vk_inst, &vk_phys, &vk_dev) == S_OK && vk_dev) {
|
||||
wl_seam_init(&c->seam, vk_inst, vk_phys, vk_dev, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
*phContext = (xess_context_handle_t)c;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessD3D12BuildPipelines(xess_context_handle_t hContext,
|
||||
void *pPipelineLibrary,
|
||||
bool blocking,
|
||||
uint32_t initFlags) {
|
||||
(void)pPipelineLibrary; (void)blocking;
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
c->init_flags = initFlags;
|
||||
c->pipelines_built = 1;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessD3D12Init(xess_context_handle_t hContext,
|
||||
const xess_d3d12_init_params_t *pInitParams) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
if (!pInitParams) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
c->d3d12_init = *pInitParams;
|
||||
c->out_res = pInitParams->outputResolution;
|
||||
c->quality = pInitParams->qualitySetting;
|
||||
c->init_flags = pInitParams->initFlags;
|
||||
c->initialized = 1;
|
||||
c->needs_reset = 1;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessD3D12GetInitParams(xess_context_handle_t hContext,
|
||||
xess_d3d12_init_params_t *pInitParams) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
if (!c->initialized) return XESS_RESULT_ERROR_UNINITIALIZED;
|
||||
if (!pInitParams) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
*pInitParams = c->d3d12_init;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessD3D12Execute(xess_context_handle_t hContext,
|
||||
void *pCommandList,
|
||||
const xess_d3d12_execute_params_t *pExecParams) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
if (!c->initialized) return XESS_RESULT_ERROR_UNINITIALIZED;
|
||||
if (!pCommandList || !pExecParams) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
if (!c->seam.ready || !c->dx12_interop) return XESS_RESULT_ERROR_UNINITIALIZED;
|
||||
|
||||
uint32_t out_w = c->out_res.x;
|
||||
uint32_t out_h = c->out_res.y;
|
||||
uint32_t in_w = pExecParams->inputWidth ? pExecParams->inputWidth : out_w;
|
||||
uint32_t in_h = pExecParams->inputHeight ? pExecParams->inputHeight : out_h;
|
||||
int high_res_mv = (c->init_flags & XESS_INIT_FLAG_HIGH_RES_MV) ? 1 : 0;
|
||||
|
||||
WlFsr4FrameDesc f;
|
||||
memset(&f, 0, sizeof f);
|
||||
f.render_w = in_w;
|
||||
f.render_h = in_h;
|
||||
f.output_w = out_w;
|
||||
f.output_h = out_h;
|
||||
f.jitter_x = pExecParams->jitterOffsetX * c->jitter_scale_x;
|
||||
f.jitter_y = pExecParams->jitterOffsetY * c->jitter_scale_y;
|
||||
|
||||
if (c->init_flags & XESS_INIT_FLAG_USE_NDC_VELOCITY) {
|
||||
float mv_w = high_res_mv ? (float)out_w : (float)in_w;
|
||||
float mv_h = high_res_mv ? (float)out_h : (float)in_h;
|
||||
f.mv_scale_x = mv_w * 0.5f * c->vel_scale_x;
|
||||
f.mv_scale_y = mv_h * -0.5f * c->vel_scale_y;
|
||||
} else {
|
||||
f.mv_scale_x = c->vel_scale_x;
|
||||
f.mv_scale_y = c->vel_scale_y;
|
||||
}
|
||||
|
||||
float exp_s = pExecParams->exposureScale > 0.0f ? pExecParams->exposureScale : 1.0f;
|
||||
f.pre_exposure = exp_s * c->exposure_mult;
|
||||
f.flags = xess_flags_to_wl(c->init_flags);
|
||||
if (pExecParams->resetHistory || c->needs_reset) {
|
||||
f.flags |= WLFSR4_FLAG_RESET;
|
||||
c->needs_reset = 0;
|
||||
}
|
||||
f.api_source = WLFSR4_API_XESS_DX12;
|
||||
f.quality_mode = xess_quality_to_wl(c->quality);
|
||||
if (f.quality_mode == WLFSR4_QUALITY_ULTRA_PERF) f.preset_hint = WLFSR4_PRESET_ULTRAPERF;
|
||||
|
||||
// XeSS DX12 contract: inputs are NON_PIXEL_SHADER_RESOURCE (0x40), output is UNORDERED_ACCESS (0x8)
|
||||
xess_fill_dx12_ref(c->dx12_interop, &f.color, pExecParams->pColorTexture, 0x40u, in_w, in_h, 0);
|
||||
xess_fill_dx12_ref(c->dx12_interop, &f.depth, pExecParams->pDepthTexture, 0x40u, in_w, in_h, 1);
|
||||
xess_fill_dx12_ref(c->dx12_interop, &f.motion, pExecParams->pVelocityTexture, 0x40u,
|
||||
high_res_mv ? out_w : in_w, high_res_mv ? out_h : in_h, 0);
|
||||
xess_fill_dx12_ref(c->dx12_interop, &f.output, pExecParams->pOutputTexture, 0x8u, out_w, out_h, 0);
|
||||
|
||||
int live_en = 1;
|
||||
int live_backend = wl_seam_live_backend(&c->seam, &live_en);
|
||||
if (live_en && live_backend == WL_FSR_BACKEND_XESS3_GPU && c->d3d12_dev) {
|
||||
if (wl_xess3_eval_d3d12(&c->xess3, &c->seam, c->dx12_interop, c->d3d12_dev, pCommandList,
|
||||
&f, pExecParams->pColorTexture, pExecParams->pDepthTexture,
|
||||
pExecParams->pVelocityTexture, pExecParams->pOutputTexture)) {
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
wl_xess3_tag_fallback(&c->xess3, &f);
|
||||
} else {
|
||||
wl_xess3_on_inactive(&c->xess3);
|
||||
}
|
||||
|
||||
void *vk_cb = NULL;
|
||||
int ok = 0;
|
||||
if (c->dx12_interop->lpVtbl->BeginVkCommandBufferInterop(c->dx12_interop, pCommandList, &vk_cb) == S_OK && vk_cb) {
|
||||
ok = wl_seam_dispatch_or_blit(&c->seam, (VkCommandBuffer)vk_cb, &f);
|
||||
c->dx12_interop->lpVtbl->EndVkCommandBufferInterop(c->dx12_interop, pCommandList);
|
||||
}
|
||||
|
||||
return ok ? XESS_RESULT_SUCCESS : XESS_RESULT_ERROR_DEVICE;
|
||||
}
|
||||
|
||||
// ---- Vulkan XeSS Exports ----
|
||||
|
||||
__declspec(dllexport) xess_result_t xessVKGetRequiredInstanceExtensions(uint32_t *instanceExtensionsCount,
|
||||
const char *const **instanceExtensions,
|
||||
uint32_t *minVkApiVersion) {
|
||||
if (instanceExtensionsCount) *instanceExtensionsCount = 0;
|
||||
if (instanceExtensions) *instanceExtensions = NULL;
|
||||
if (minVkApiVersion) *minVkApiVersion = (1u << 22) | (1u << 12); /* VK_API_VERSION_1_1 */
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessVKGetRequiredDeviceExtensions(VkInstance instance,
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t *deviceExtensionsCount,
|
||||
const char *const **deviceExtensions) {
|
||||
(void)instance; (void)physicalDevice;
|
||||
if (deviceExtensionsCount) *deviceExtensionsCount = 0;
|
||||
if (deviceExtensions) *deviceExtensions = NULL;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessVKGetRequiredDeviceFeatures(VkInstance instance,
|
||||
VkPhysicalDevice physicalDevice,
|
||||
void **features) {
|
||||
(void)instance; (void)physicalDevice; (void)features;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessVKCreateContext(VkInstance instance,
|
||||
VkPhysicalDevice physicalDevice,
|
||||
VkDevice device,
|
||||
xess_context_handle_t *phContext) {
|
||||
if (!device || !phContext) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
WlXessCtx *c = (WlXessCtx *)calloc(1, sizeof *c);
|
||||
if (!c) return XESS_RESULT_ERROR_UNKNOWN;
|
||||
|
||||
c->magic = WL_XESS_MAGIC;
|
||||
c->is_vk = 1;
|
||||
c->needs_reset = 1;
|
||||
c->jitter_scale_x = 1.0f;
|
||||
c->jitter_scale_y = 1.0f;
|
||||
c->vel_scale_x = 1.0f;
|
||||
c->vel_scale_y = 1.0f;
|
||||
c->exposure_mult = 1.0f;
|
||||
c->max_responsive_mask = 1.0f;
|
||||
|
||||
wl_seam_init(&c->seam, instance, physicalDevice, device, NULL);
|
||||
|
||||
*phContext = (xess_context_handle_t)c;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessVKBuildPipelines(xess_context_handle_t hContext,
|
||||
uint64_t pipelineCache,
|
||||
bool blocking,
|
||||
uint32_t initFlags) {
|
||||
(void)pipelineCache; (void)blocking;
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
c->init_flags = initFlags;
|
||||
c->pipelines_built = 1;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessVKInit(xess_context_handle_t hContext,
|
||||
const xess_vk_init_params_t *pInitParams) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
if (!pInitParams) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
c->vk_init = *pInitParams;
|
||||
c->out_res = pInitParams->outputResolution;
|
||||
c->quality = pInitParams->qualitySetting;
|
||||
c->init_flags = pInitParams->initFlags;
|
||||
c->initialized = 1;
|
||||
c->needs_reset = 1;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessVKGetInitParams(xess_context_handle_t hContext,
|
||||
xess_vk_init_params_t *pInitParams) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
if (!c->initialized) return XESS_RESULT_ERROR_UNINITIALIZED;
|
||||
if (!pInitParams) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
*pInitParams = c->vk_init;
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
__declspec(dllexport) xess_result_t xessVKExecute(xess_context_handle_t hContext,
|
||||
VkCommandBuffer commandBuffer,
|
||||
const xess_vk_execute_params_t *pExecParams) {
|
||||
WlXessCtx *c = xess_unwrap(hContext);
|
||||
if (!c) return XESS_RESULT_ERROR_INVALID_CONTEXT;
|
||||
if (!c->initialized) return XESS_RESULT_ERROR_UNINITIALIZED;
|
||||
if (!commandBuffer || !pExecParams) return XESS_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
if (!c->seam.ready) return XESS_RESULT_ERROR_UNINITIALIZED;
|
||||
|
||||
uint32_t out_w = c->out_res.x;
|
||||
uint32_t out_h = c->out_res.y;
|
||||
uint32_t in_w = pExecParams->inputWidth ? pExecParams->inputWidth : out_w;
|
||||
uint32_t in_h = pExecParams->inputHeight ? pExecParams->inputHeight : out_h;
|
||||
int high_res_mv = (c->init_flags & XESS_INIT_FLAG_HIGH_RES_MV) ? 1 : 0;
|
||||
|
||||
WlFsr4FrameDesc f;
|
||||
memset(&f, 0, sizeof f);
|
||||
f.render_w = in_w;
|
||||
f.render_h = in_h;
|
||||
f.output_w = out_w;
|
||||
f.output_h = out_h;
|
||||
f.jitter_x = pExecParams->jitterOffsetX * c->jitter_scale_x;
|
||||
f.jitter_y = pExecParams->jitterOffsetY * c->jitter_scale_y;
|
||||
|
||||
if (c->init_flags & XESS_INIT_FLAG_USE_NDC_VELOCITY) {
|
||||
float mv_w = high_res_mv ? (float)out_w : (float)in_w;
|
||||
float mv_h = high_res_mv ? (float)out_h : (float)in_h;
|
||||
f.mv_scale_x = mv_w * 0.5f * c->vel_scale_x;
|
||||
f.mv_scale_y = mv_h * -0.5f * c->vel_scale_y;
|
||||
} else {
|
||||
f.mv_scale_x = c->vel_scale_x;
|
||||
f.mv_scale_y = c->vel_scale_y;
|
||||
}
|
||||
|
||||
float exp_s = pExecParams->exposureScale > 0.0f ? pExecParams->exposureScale : 1.0f;
|
||||
f.pre_exposure = exp_s * c->exposure_mult;
|
||||
f.flags = xess_flags_to_wl(c->init_flags);
|
||||
if (pExecParams->resetHistory || c->needs_reset) {
|
||||
f.flags |= WLFSR4_FLAG_RESET;
|
||||
c->needs_reset = 0;
|
||||
}
|
||||
f.api_source = WLFSR4_API_XESS_VK;
|
||||
f.quality_mode = xess_quality_to_wl(c->quality);
|
||||
if (f.quality_mode == WLFSR4_QUALITY_ULTRA_PERF) f.preset_hint = WLFSR4_PRESET_ULTRAPERF;
|
||||
|
||||
// XeSS VK contract: inputs in SHADER_READ_ONLY_OPTIMAL (5), output in GENERAL (1)
|
||||
xess_fill_vk_ref(&f.color, &pExecParams->colorTexture, 5u, in_w, in_h, 0);
|
||||
xess_fill_vk_ref(&f.depth, &pExecParams->depthTexture, 5u, in_w, in_h, 1);
|
||||
xess_fill_vk_ref(&f.motion, &pExecParams->velocityTexture, 5u,
|
||||
high_res_mv ? out_w : in_w, high_res_mv ? out_h : in_h, 0);
|
||||
xess_fill_vk_ref(&f.output, &pExecParams->outputTexture, 1u, out_w, out_h, 0);
|
||||
|
||||
int live_en = 1;
|
||||
int live_backend = wl_seam_live_backend(&c->seam, &live_en);
|
||||
if (live_en && live_backend == WL_FSR_BACKEND_XESS3_GPU) {
|
||||
wl_xess_vk_img_t x_col, x_dep, x_mv, x_out;
|
||||
memcpy(&x_col, &pExecParams->colorTexture, sizeof x_col);
|
||||
memcpy(&x_dep, &pExecParams->depthTexture, sizeof x_dep);
|
||||
memcpy(&x_mv, &pExecParams->velocityTexture, sizeof x_mv);
|
||||
memcpy(&x_out, &pExecParams->outputTexture, sizeof x_out);
|
||||
if (wl_xess3_eval_vk(&c->xess3, &c->seam, commandBuffer, &f, &x_col, &x_dep, &x_mv, &x_out)) {
|
||||
return XESS_RESULT_SUCCESS;
|
||||
}
|
||||
wl_xess3_tag_fallback(&c->xess3, &f);
|
||||
} else {
|
||||
wl_xess3_on_inactive(&c->xess3);
|
||||
}
|
||||
|
||||
int ok = wl_seam_dispatch_or_blit(&c->seam, commandBuffer, &f);
|
||||
return ok ? XESS_RESULT_SUCCESS : XESS_RESULT_ERROR_DEVICE;
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
|
||||
(void)hinst; (void)reason; (void)reserved;
|
||||
return TRUE;
|
||||
}
|
||||
Reference in new issue
Block a user