[Linux] 30–60 FPS with Series X + DLSS Frame Generation on a 12 GB RTX, under plain Wine (one setting kills the FG stutter) #3370

Open
opened 2026-12-03 17:29:00 +00:00 by janvitos · 0 comments
janvitos commented 2026-12-03 17:29:00 +00:00 (Migrated from github.com)
Contributor

Imported from ubiquitarianism/leonida. Originally posted by janvitos on 2026-12-03T17:29:00Z.


Series X profile, DLSS Quality to 1440p and DLSS Frame Generation 2x now run well on my 12 GB card under upstream Wine. Two things made the difference:

  • LEONIDA_FG_RESET_STALE=0 fixed the stutter. Before, the game felt like 10–15 fps even with the FG counter showing 35.
  • LEONIDA_TEXTURE_BUDGET_MB=2048 stops the card filling up and the driver crashing.

Below: evidence, then a setup guide.

System

RTX 4070 SUPER 12 GB · Ryzen 7 9700X · 48 GB RAM · CachyOS (kernel 7.3.7) · NVIDIA 620.73.04 (open modules, patched with open-gpu-kernel-modules PR #1542) · Wine 11.23 (upstream, not Proton) · 2560x1440 · Mandy d227aa73e

Evidence

1. Frame-generation stutter. By default, Mandy tells DLSS-G "reset" (skip the in-between frame) on any present without a fresh upscale, and on the present after it (fg.rs, present_start). Under Wine, 15–33% of gameplay presents were like that.

FG_RESET_STALE on (default) LEONIDA_FG_RESET_STALE=0
Frames on screen per real frame 1.4–1.76 (MangoHud, every shown frame logged) 2 (Streamline reports presented=2, 0 resets)
Real frames taking >1.5× the usual time 9.0% 2.8%
How it felt Jerky, worst when turning the camera or with lights on screen Smooth

The skipped frames left irregular double-length gaps. That's why a frame cap (LEONIDA_FG_LIMIT_FPS=30) didn't help. A possible side effect of turning resets off is warping on a generated frame at a camera cut.

2. VRAM. On Series X, texture storage grew to 4.0 GB. Frame generation needs about 1 GB more that DXGI's budget doesn't count. The card filled up and the kernel logged nvidia-drm: Failed to allocate NVKMS video memory, then Xid 109 / Xid 31 and a device-removed crash (0x887A0005). Windows spills over-budget VRAM into system RAM (see #2821); here the driver failed allocations instead. With LEONIDA_TEXTURE_BUDGET_MB=2048, after about 10 minutes:

  • the game used 10.2 GB (11.4 of 12.3 GB on the whole card);
  • Mandy used 8.5 GB of an 8.9 GB budget;
  • the kernel logged no Xid or NVKMS errors.

3. Frame rates (Mandy's log; FG doubles each):

Scene Real fps Shown fps with FG
Intro 20–30 40–60
Dense city at night 13–16 26–32

Setup

Needs:

  • Upstream Wine 11.x. Proton-based Wine (Proton Experimental, Proton-CachyOS, wine-cachyos) ran at 3–7 fps for me: Mandy's write-watch queries were 8–15x slower there.
  • Steam's Proton - Experimental installed. It's only used for its VKD3D-Proton, DXVK dxgi and dxvk-nvapi; the bundled VKD3D-Proton 3.1 crashed NVIDIA's shader compiler.
  • The NVIDIA driver's nvngx.dll / _nvngx.dll (in /usr/lib/nvidia/wine/ on Arch-based systems).
  • rust and cargo-xwin.
  • Microsoft's d3dcompiler_47.dll (x64, the one winetricks ships). Wine's builtin compiler can't compile Mandy's helper shaders, which leaves the world black.
  • Recommended: NVIDIA's open kernel modules with PR #1542 (NVIDIA/open-gpu-kernel-modules) applied. Stock 620.x (including 620.85.02) can hard-freeze the desktop when a memory-mapping insert fails while VRAM is full. I had a hard reset during play that came right after 24 Failed to insert new mapping node lines. With the texture cap, VRAM shouldn't fill, but the patch is a safety net.

1. Clone Mandy and get NVIDIA's SDK files. Use the layout of d3d12/scripts/get-nvidia-sdks.ps1: DLSS v310.9.16 from github.com/NVIDIA/DLSS and Streamline v2.14.16 from github.com/NVIDIA-RTX/Streamline.

d3d12/nvidia-sdk/DLSS/lib/Windows_x86_64/{rel,x64}/   # nvngx_dlss.dll, nvngx_dlssg.dll, nvsdk_ngx_d.lib
d3d12/nvidia-sdk/Streamline/bin/x64/                   # sl.interposer.dll, sl.dlss_g.dll, sl.reflex.dll, ...

2. Apply the Wine frame-generation patch (below). Streamline only enables DLSS-G when hardware GPU scheduling is on. Wine 11.23 doesn't report it, so you get eErrorOSDisabledHWS; Proton's Wine has a patch for this. This patch answers that one query as "on" under Wine and passes every other query through unchanged (LEONIDA_FG_WINE_HWS=0 turns it off).

git apply fg-wine-scheduling.patch

3. Build:

cd d3d12
LEONIDA_DLSS_SDK=$PWD/nvidia-sdk/DLSS cargo xwin build --locked --profile play -p leonida \
  --features diagnostics,dlss,mimalloc --target x86_64-pc-windows-msvc

--profile play with diagnostics is needed: most of the settings below are diagnostics switches.

4. Launch with the script below. Set GAME to your dump's path. The first start translates shaders, which takes a while.

Why each setting

Setting Why
LEONIDA_FG_RESET_STALE=0 The stutter fix above
LEONIDA_TEXTURE_BUDGET_MB=2048 Keeps Series X + FG within 12 GB. Without it, texture storage filled the card
LEONIDA_FRAME_GEN=2, UPSCALE=dlss, RENDER_SCALE=0.6667, OUTPUT=2560x1440 DLSS Quality to 1440p with 2x FG. 4K output filled the card
LEONIDA_FG_LIMIT_FPS=0 auto measured the loading screen and locked the intro at 12 fps
LEONIDA_WINDOWS_BAR_MB=0 play-nvidia.ps1 puts up to 3 GB here on PCs with <48 GB RAM, and that comes out of VRAM
LEONIDA_TITLE_RANGE=0 The title range fails under Wine 11.23 (XMemVirtualAlloc ... miss=Refused, thousands per run) and the picture looked washed out
LEONIDA_PIPELINE_WAIT_MS=250 play-linux.sh's 10000 froze the game for seconds when a new pipeline was built
DXVK dxgi + hideNvidiaGpu = False Wine's own dxgi crashed at startup. DXVK reports NVIDIA cards as AMD by default
dxvk-nvapi + nvngx + NGXCore registry key What Proton does for DLSS (PROTON_ENABLE_NVAPI)
WINEDEBUG=fixme-all Wine prints a fixme about 400 times a second for a query Mandy makes (70% of the log)
The remaining LEONIDA_* play-nvidia.ps1's play set as of b41763227, copied as is (it halved the per-frame refresh time). The only change is BAR 0

Reflex stays on: without it, DLSS-G turns itself off after a few seconds (eFailReflexNotDetectedAtRuntime).

Launcher script
#!/bin/bash
# GTA VI with Mandy under upstream Wine: Series X, DLSS Quality -> 1440p, DLSS-G 2x. `script VAR=value` overrides.
GAME=/path/to/game_scarlett_master.exe
dir=$HOME/Games/mandy                     # your Mandy checkout
data=$HOME/Games/mandy-data               # cache, saves, d3dcompiler_47.dll
proton="$HOME/.local/share/Steam/steamapps/common/Proton - Experimental/files/lib/wine"
export LEONIDA_RUNTIME=$dir/d3d12/target/x86_64-pc-windows-msvc/play/leonida.exe
export LEONIDA_VKD3D=$proton/vkd3d-proton/x86_64-windows
export LEONIDA_WINEPREFIX=$HOME/Games/mandy-prefix LEONIDA_CACHE_DIR=$data/cache LEONIDA_DATA_DIR=$data/data
export LEONIDA_PIPELINE_WAIT_MS=250 LEONIDA_TITLE_RANGE=0

if [ ! -d "$LEONIDA_WINEPREFIX/drive_c/windows/system32" ]; then
  mkdir -p "$LEONIDA_WINEPREFIX"
  WINEPREFIX=$LEONIDA_WINEPREFIX WINEARCH=win64 WINEDLLOVERRIDES="mscoree,mshtml=" wineboot -u
fi
sys32=$LEONIDA_WINEPREFIX/drive_c/windows/system32
for f in "$proton/dxvk/x86_64-windows/dxgi.dll" "$data/dlls/d3dcompiler_47.dll" \
         "$proton/nvapi/x86_64-windows/nvapi64.dll" "$proton/nvapi/x86_64-windows/nvofapi64.dll" \
         /usr/lib/nvidia/wine/nvngx.dll /usr/lib/nvidia/wine/_nvngx.dll; do
  cmp -s "$f" "$sys32/${f##*/}" || install -m 644 "$f" "$sys32/${f##*/}"
done
chmod u+w "$sys32/d3d12.dll" "$sys32/d3d12core.dll" 2>/dev/null   # Steam's copies are read-only
grep -q NGXCore "$LEONIDA_WINEPREFIX/system.reg" || WINEPREFIX=$LEONIDA_WINEPREFIX wine reg add \
  'HKLM\SOFTWARE\NVIDIA Corporation\Global\NGXCore' /v FullPath /t REG_SZ /d 'C:\Windows\System32' /f
export WINEDLLOVERRIDES="nvapi64,nvofapi64,dxgi,d3dcompiler_47=n" DXVK_ENABLE_NVAPI=1
export DXVK_CONFIG="dxgi.hideNvidiaGpu = False" WINEDEBUG=fixme-all

sdk=$dir/d3d12/nvidia-sdk; win=Z:${sdk//\//\\}
export LEONIDA_DLSS_DIR=$win\\DLSS\\lib\\Windows_x86_64\\rel LEONIDA_STREAMLINE_DIR=$win\\Streamline\\bin\\x64
export LEONIDA_UPSCALE=dlss LEONIDA_FSR_UPSCALER=1 LEONIDA_OWN_UPSCALER=0 LEONIDA_RENDER_SCALE=0.6667
export LEONIDA_OUTPUT=2560x1440 LEONIDA_FRAME_GEN=2 LEONIDA_FG_LIMIT_FPS=0
export LEONIDA_FG_RESET_STALE=0 LEONIDA_TEXTURE_BUDGET_MB=2048

# play-nvidia.ps1's play set (b41763227), BAR 0
export LEONIDA_TEXTURE_NO_WAIT=0 LEONIDA_RELAY=2 LEONIDA_CARD_STEPS=2 LEONIDA_WIDE_BACK=1 LEONIDA_CARD_REHASH_RUNS=1 \
  LEONIDA_JOIN_COPIES=1 LEONIDA_INDIRECT_WINDOW=1 LEONIDA_RELAY_COPY=1 LEONIDA_FETCH_CHECK=1 LEONIDA_SUBMIT_SENDER=1 \
  LEONIDA_INDIRECT_BATCH=4 LEONIDA_MAP_THREADS=1 LEONIDA_TITLE_PRIORITIES=0 LEONIDA_PORT_GUARD=1 LEONIDA_PORT_JOURNAL=1 \
  LEONIDA_CARD_AWAKE=0 LEONIDA_STORE_BESIDE=1 LEONIDA_ALIAS_DIRECT=1 LEONIDA_QUICK_FIND_WINDOWS=1 \
  LEONIDA_PORT_DESCRIPTORS=1 LEONIDA_COPY_SCOPED=1 LEONIDA_INDEX_HEAP_SPANS=1 LEONIDA_AHEAD_SPLIT=1 LEONIDA_SHOW_AFTER=1 \
  LEONIDA_AMBIENT=0.8 LEONIDA_AMBIENT_MOST=2 LEONIDA_AMBIENT_AIR=1.5 LEONIDA_AMBIENT_ALPHA=4 LEONIDA_REFLECT_MOST=0.5 \
  LEONIDA_D3D12_DRED=faults LEONIDA_THIN=1 LEONIDA_THIN_THREADS=6 LEONIDA_JOIN_PARTS=8 LEONIDA_UPLOAD_AHEAD=1 \
  LEONIDA_TEXTURE_HASH_BACKOFF=1 LEONIDA_NAN_SCRUB=1 LEONIDA_STATIC_SAMPLERS_LINEAR=PS_Composite LEONIDA_EARLY_DEPTH=1 \
  LEONIDA_PLACED_TITLE=1 LEONIDA_DYNAMIC_SLOTS=524288 LEONIDA_CARD_BUFFERS_MB=1536 LEONIDA_CARD_BUFFERS_MIN_MB=1 \
  LEONIDA_CARD_BUFFERS_MIN_KB=64 LEONIDA_FILL_TITLE=1 LEONIDA_WC_NO_BACK=1 LEONIDA_MEMORY_MAP=0 LEONIDA_SECTION_MB=16 \
  LEONIDA_WINDOWS_BAR_MB=0 \
  LEONIDA_SKIP_PIPELINES=51e19585b4753814,aaabcd7a8ec90db8,9f3ecb8d133084bf,2a00e6082220d9a5 \
  LEONIDA_PAIRED_FOR=ae0deeafe219c15c,407eca669212d400,18d957e62926ed3e,5e3dd99e0f067aee,57f1b81de55c2842,02384a60fda6f2d0,339d476c267c03c7,39998898c90889b2,c042a10ed3428758,c85cb6bc1cd8e2ad,c80d02ddc38ef279,be6ce5d849d51127,922e1d0ee1e19a85,1f1fbd86759b3da2,0ffd3b911e35e7d0,71883e40620a567a,3c9d23fa83d63d43,4031c6c05fa7ec48,bc76c37f9fa3672b,0a5ecfee6b79e13b,d3e5b737ea7cc150,55d2bce91ec9abcc,f8f712930c606707,40bc5fd052acfdf4,294e7cdd91ebd1f1,b7953a05b189dfc1,a53a7977fe762268,be14e72d86362031,0a5d4f9047b3dce4,8dd8d739047fe557,12b0005a30bc18a9,2620618869072a85,eb9a057a81d18c42,89ed0b981f99573c,b2711644ca5566cc,0903802745985664,ce2378e5e8711aad,136986812880cead,3c196d81eca7ff15,acf14a70f37fb012,f79824724d8e2daf,f0aa2b1e79275592,c4183d3cbee28e8e,2e92491c2ae5472b

for kv in "$@"; do case "$kv" in *=*) export "$kv";; esac; done
exec "$dir/scripts/play-linux.sh" "$GAME" --series-x
fg-wine-scheduling.patch
diff --git a/d3d12/crates/leonida-gpu/src/fg.rs b/d3d12/crates/leonida-gpu/src/fg.rs
index 15a04c58d..dfcc66be7 100644
--- a/d3d12/crates/leonida-gpu/src/fg.rs
+++ b/d3d12/crates/leonida-gpu/src/fg.rs
@@ -844,6 +844,8 @@ fn log_reflex_report(fg: &Fg) {
 fn init(device: &ID3D12Device) -> anyhow::Result<Fg> {
     let dir = std::env::var_os("LEONIDA_STREAMLINE_DIR")
         .ok_or_else(|| anyhow::anyhow!("LEONIDA_STREAMLINE_DIR is not set"))?;
+    // Local patch (mandy): under Wine, hardware GPU scheduling reported on, as Proton's Wine does.
+    crate::wine_hws::report_scheduling_on();
     // SAFETY: NVIDIA's signed interposer from the SDK folder the launcher names.
     let mut s = unsafe { sl::Sl::load(std::path::Path::new(&dir)) }?;
     let features = sl::FG_FEATURES;
diff --git a/d3d12/crates/leonida-gpu/src/lib.rs b/d3d12/crates/leonida-gpu/src/lib.rs
index 12a697870..e14b6a375 100644
--- a/d3d12/crates/leonida-gpu/src/lib.rs
+++ b/d3d12/crates/leonida-gpu/src/lib.rs
@@ -64,6 +64,8 @@ pub mod aspect;
 pub mod streamline;
 #[cfg(windows)]
 mod fg;
+#[cfg(windows)]
+mod wine_hws;
 /// Leonida: AMD FSR 3 frame generation where DLSS Frame Generation does not run (`LEONIDA_FSR_FRAMEGEN`).
 #[cfg(windows)]
 mod fsr;
diff --git a/d3d12/crates/leonida-gpu/src/wine_hws.rs b/d3d12/crates/leonida-gpu/src/wine_hws.rs
new file mode 100644
index 000000000..deb6a0eab
--- /dev/null
+++ b/d3d12/crates/leonida-gpu/src/wine_hws.rs
@@ -0,0 +1,147 @@
+//! Local patch (mandy, 2026-12-02; ~/Games/mandy-data/patches/fg-wine-scheduling.patch): DLSS frame
+//! generation under upstream Wine.
+//!
+//! Streamline gives DLSS-G only where hardware-accelerated GPU scheduling is on. It asks through
+//! `D3DKMTQueryAdapterInfo` with `KMTQAITYPE_WDDM_2_7_CAPS` (gdi32; Wine forwards it to win32u's
+//! `NtGdiDdDDIQueryAdapterInfo`). Wine 11.23 does not say "on", so `slIsFeatureSupported` gave
+//! `eErrorOSDisabledHWS`. Proton's Wine says "on" (a win32u patch, WINE_DISABLE_HARDWARE_SCHEDULING),
+//! and frame generation started there, but asking which memory this title wrote took 8 to 15 times
+//! as long under it. So under Wine, before Streamline loads, win32u's system call stub for the call
+//! jumps to [`query`]: that one question is answered "supported and on", every other one goes to a
+//! copy of the stub, which makes the same system call. Not on Windows, where the system answers.
+//! LEONIDA_FG_WINE_HWS=0 leaves it out.
+
+use std::sync::Once;
+use std::sync::atomic::{AtomicUsize, Ordering};
+
+use windows_sys::Win32::System::Diagnostics::Debug::FlushInstructionCache;
+use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress, LoadLibraryA};
+use windows_sys::Win32::System::Memory::{
+    MEM_COMMIT, MEM_RESERVE, PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, PAGE_PROTECTION_FLAGS, PAGE_READWRITE,
+    VirtualAlloc, VirtualProtect,
+};
+use windows_sys::Win32::System::Threading::GetCurrentProcess;
+
+/// `KMTQAITYPE_WDDM_2_7_CAPS` (Wine's d3dkmthk.h: the one before `KMTQAITYPE_DISPLAY_UMDRIVERNAME`, 71).
+const WDDM_2_7_CAPS: u32 = 70;
+/// `D3DKMT_WDDM_2_7_CAPS`: HwSchSupported (bit 0), HwSchEnabled (bit 1).
+const SCHEDULING_ON: u32 = 0b11;
+/// Wine's x86-64 system call stub (win32u.dll of Wine 11.23): `mov r10, rcx; mov eax, <number>;
+/// test byte [0x7ffe0308], 1; jne 1f; syscall; ret; 1: jmp 2f; ret; 2: call [0x7ffe1000]; ret`.
+/// Bytes 4..8 are the number. Its addresses are absolute or inside it, so a copy anywhere makes
+/// the same call.
+const STUB: [u8; 32] = [
+    0x4c, 0x8b, 0xd1, 0xb8, 0, 0, 0, 0, 0xf6, 0x04, 0x25, 0x08, 0x03, 0xfe, 0x7f, 0x01, //
+    0x75, 0x03, 0x0f, 0x05, 0xc3, 0xeb, 0x01, 0xc3, 0xff, 0x14, 0x25, 0x00, 0x10, 0xfe, 0x7f, 0xc3,
+];
+
+/// `D3DKMT_QUERYADAPTERINFO`.
+#[repr(C)]
+struct QueryAdapterInfo {
+    adapter: u32,
+    kind: u32,
+    data: *mut u32,
+    size: u32,
+}
+
+type Query = unsafe extern "system" fn(*const QueryAdapterInfo) -> i32;
+
+/// The copy of the stub (0 until [`install`] made it).
+static ORIGINAL: AtomicUsize = AtomicUsize::new(0);
+
+/// What the stub jumps to: `NtGdiDdDDIQueryAdapterInfo`'s own signature.
+unsafe extern "system" fn query(info: *const QueryAdapterInfo) -> i32 {
+    // SAFETY: the caller's argument, null or a D3DKMT_QUERYADAPTERINFO, as for the system call.
+    if let Some(i) = unsafe { info.as_ref() }
+        && i.kind == WDDM_2_7_CAPS
+        && !i.data.is_null()
+        && i.size >= 4
+    {
+        // SAFETY: the caller's buffer, `size` bytes.
+        unsafe { i.data.write_unaligned(SCHEDULING_ON) };
+        return 0; // STATUS_SUCCESS
+    }
+    // SAFETY: stored before the stub was sent here; a copy of the stub, the same signature.
+    let original = unsafe { std::mem::transmute::<usize, Query>(ORIGINAL.load(Ordering::Acquire)) };
+    // SAFETY: the caller's argument, passed on.
+    unsafe { original(info) }
+}
+
+/// Under Wine, once (from `fg::init`, before Streamline loads): [`install`], and says what it did.
+pub(crate) fn report_scheduling_on() {
+    static ONCE: Once = Once::new();
+    ONCE.call_once(|| {
+        if std::env::var_os("LEONIDA_FG_WINE_HWS").is_some_and(|v| v == "0") {
+            return;
+        }
+        // SAFETY: see `install`.
+        match unsafe { install() } {
+            Ok(false) => {}
+            Ok(true) => tracing::info!(
+                "frame generation: Wine's answer about hardware GPU scheduling is \"on\" in this process, as Proton's (LEONIDA_FG_WINE_HWS=0 leaves it)"
+            ),
+            Err(e) => tracing::warn!(error = e, "frame generation: Wine's answer about hardware GPU scheduling left as it is"),
+        }
+    });
+}
+
+/// Sends win32u's `NtGdiDdDDIQueryAdapterInfo` to [`query`]: `Ok(false)` when this is not Wine, an
+/// error when its stub is not the one this knows (another Wine), and nothing is changed.
+///
+/// # Safety
+/// Once per process. The stub's first 12 bytes are rewritten in place: a thread inside them at
+/// that moment would run a mix of both (it is called at a device's start, not per frame).
+pub(crate) unsafe fn install() -> Result<bool, &'static str> {
+    // SAFETY: plain lookups in loaded system DLLs (gdi32 loaded if it was not).
+    let target = unsafe {
+        let ntdll = GetModuleHandleA(c"ntdll.dll".as_ptr().cast());
+        if ntdll.is_null() || GetProcAddress(ntdll, c"wine_get_version".as_ptr().cast()).is_none() {
+            return Ok(false);
+        }
+        let gdi32 = LoadLibraryA(c"gdi32.dll".as_ptr().cast());
+        if gdi32.is_null() {
+            return Err("gdi32.dll did not load");
+        }
+        // Through gdi32, as Streamline imports it: the address Wine's forward resolves to.
+        match GetProcAddress(gdi32, c"D3DKMTQueryAdapterInfo".as_ptr().cast()) {
+            Some(f) => f as usize as *mut u8,
+            None => return Err("gdi32.dll has no D3DKMTQueryAdapterInfo"),
+        }
+    };
+    // SAFETY: the start of an exported function's code; the rest is read only if that matches.
+    let known = unsafe {
+        std::slice::from_raw_parts(target, 4) == &STUB[..4]
+            && std::slice::from_raw_parts(target.add(8), STUB.len() - 8) == &STUB[8..]
+    };
+    if !known {
+        return Err("D3DKMTQueryAdapterInfo is not the system call stub this patch knows (another Wine)");
+    }
+    // SAFETY: a new private page, the stub copied into it, then made executable.
+    let copy = unsafe { VirtualAlloc(std::ptr::null(), 4096, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) }.cast::<u8>();
+    if copy.is_null() {
+        return Err("no memory for the copy of the stub");
+    }
+    let mut old: PAGE_PROTECTION_FLAGS = 0;
+    // SAFETY: as above.
+    unsafe {
+        std::ptr::copy_nonoverlapping(target, copy, STUB.len());
+        if VirtualProtect(copy.cast(), 4096, PAGE_EXECUTE_READ, &mut old) == 0 {
+            return Err("the copy of the stub could not be made executable");
+        }
+    }
+    ORIGINAL.store(copy as usize, Ordering::Release);
+    // mov rax, query; jmp rax (rax is the stub's scratch: it puts the number there).
+    let mut jump = [0x48, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xe0];
+    jump[2..10].copy_from_slice(&(query as Query as usize as u64).to_le_bytes());
+    // SAFETY: the stub's own bytes, made writable for the write and given their protection back.
+    unsafe {
+        if VirtualProtect(target.cast(), jump.len(), PAGE_EXECUTE_READWRITE, &mut old) == 0 {
+            return Err("the stub could not be made writable");
+        }
+        std::ptr::copy_nonoverlapping(jump.as_ptr(), target, jump.len());
+        let mut was: PAGE_PROTECTION_FLAGS = 0;
+        let _ = VirtualProtect(target.cast(), jump.len(), old, &mut was);
+        let _ = FlushInstructionCache(GetCurrentProcess(), target.cast(), jump.len());
+    }
+    Ok(true)
+}

For the devs

  • FG_RESET_STALE: under Wine, a large share of gameplay presents (15–33%) arrive without a fresh upscale. I don't know why, but resetting DLSS-G on all of them (and on the present after) costs a third of the generated frames and makes the pacing uneven. Maybe default it off on Linux, or only reset on real cuts?
  • Texture pool: it frees only completely empty 64 MB blocks, but the room and keep rules count empty space inside blocks as free (resource.rs room() / keep policy). On Series X + FG, blocks reached 4.0 GB while only 1.4–1.6 GB of textures were in them. An absolute cap works around it.
  • FG under upstream Wine: without something like the patch above, upstream Wine can't run DLSS-G at all. Happy to open a PR.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:6774474943 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/issues/3370). Originally posted by [janvitos](https://github.com/janvitos) on 2026-12-03T17:29:00Z. --- Series X profile, DLSS Quality to 1440p and DLSS Frame Generation 2x now run well on my 12 GB card under upstream Wine. Two things made the difference: - **`LEONIDA_FG_RESET_STALE=0`** fixed the stutter. Before, the game felt like 10–15 fps even with the FG counter showing 35. - **`LEONIDA_TEXTURE_BUDGET_MB=2048`** stops the card filling up and the driver crashing. Below: evidence, then a setup guide. ### System RTX 4070 SUPER 12 GB · Ryzen 7 9700X · 48 GB RAM · CachyOS (kernel 7.3.7) · NVIDIA 620.73.04 (open modules, patched with open-gpu-kernel-modules PR #1542) · **Wine 11.23 (upstream, not Proton)** · 2560x1440 · Mandy `d227aa73e` ### Evidence **1. Frame-generation stutter.** By default, Mandy tells DLSS-G "reset" (skip the in-between frame) on any present without a fresh upscale, and on the present after it (`fg.rs`, `present_start`). Under Wine, 15–33% of gameplay presents were like that. | | `FG_RESET_STALE` on (default) | `LEONIDA_FG_RESET_STALE=0` | |---|---|---| | Frames on screen per real frame | 1.4–1.76 (MangoHud, every shown frame logged) | 2 (Streamline reports `presented=2`, 0 resets) | | Real frames taking >1.5× the usual time | 9.0% | 2.8% | | How it felt | Jerky, worst when turning the camera or with lights on screen | Smooth | The skipped frames left irregular double-length gaps. That's why a frame cap (`LEONIDA_FG_LIMIT_FPS=30`) didn't help. A possible side effect of turning resets off is warping on a generated frame at a camera cut. **2. VRAM.** On Series X, texture storage grew to 4.0 GB. Frame generation needs about 1 GB more that DXGI's budget doesn't count. The card filled up and the kernel logged `nvidia-drm: Failed to allocate NVKMS video memory`, then Xid 109 / Xid 31 and a device-removed crash (`0x887A0005`). Windows spills over-budget VRAM into system RAM (see #2821); here the driver failed allocations instead. With `LEONIDA_TEXTURE_BUDGET_MB=2048`, after about 10 minutes: - the game used 10.2 GB (11.4 of 12.3 GB on the whole card); - Mandy used 8.5 GB of an 8.9 GB budget; - the kernel logged no Xid or NVKMS errors. **3. Frame rates** (Mandy's log; FG doubles each): | Scene | Real fps | Shown fps with FG | |---|---|---| | Intro | 20–30 | 40–60 | | Dense city at night | 13–16 | 26–32 | ### Setup **Needs:** - Upstream Wine 11.x. Proton-based Wine (Proton Experimental, Proton-CachyOS, wine-cachyos) ran at 3–7 fps for me: Mandy's write-watch queries were 8–15x slower there. - Steam's *Proton - Experimental* installed. It's only used for its VKD3D-Proton, DXVK `dxgi` and `dxvk-nvapi`; the bundled VKD3D-Proton 3.1 crashed NVIDIA's shader compiler. - The NVIDIA driver's `nvngx.dll` / `_nvngx.dll` (in `/usr/lib/nvidia/wine/` on Arch-based systems). - `rust` and `cargo-xwin`. - Microsoft's `d3dcompiler_47.dll` (x64, the one winetricks ships). Wine's builtin compiler can't compile Mandy's helper shaders, which leaves the world black. - **Recommended: NVIDIA's open kernel modules with PR #1542** (NVIDIA/open-gpu-kernel-modules) applied. Stock 620.x (including 620.85.02) can hard-freeze the desktop when a memory-mapping insert fails while VRAM is full. I had a hard reset during play that came right after 24 `Failed to insert new mapping node` lines. With the texture cap, VRAM shouldn't fill, but the patch is a safety net. **1. Clone Mandy and get NVIDIA's SDK files.** Use the layout of `d3d12/scripts/get-nvidia-sdks.ps1`: DLSS `v310.9.16` from github.com/NVIDIA/DLSS and Streamline `v2.14.16` from github.com/NVIDIA-RTX/Streamline. ``` d3d12/nvidia-sdk/DLSS/lib/Windows_x86_64/{rel,x64}/ # nvngx_dlss.dll, nvngx_dlssg.dll, nvsdk_ngx_d.lib d3d12/nvidia-sdk/Streamline/bin/x64/ # sl.interposer.dll, sl.dlss_g.dll, sl.reflex.dll, ... ``` **2. Apply the Wine frame-generation patch (below).** Streamline only enables DLSS-G when hardware GPU scheduling is on. Wine 11.23 doesn't report it, so you get `eErrorOSDisabledHWS`; Proton's Wine has a patch for this. This patch answers that one query as "on" under Wine and passes every other query through unchanged (`LEONIDA_FG_WINE_HWS=0` turns it off). ```sh git apply fg-wine-scheduling.patch ``` **3. Build:** ```sh cd d3d12 LEONIDA_DLSS_SDK=$PWD/nvidia-sdk/DLSS cargo xwin build --locked --profile play -p leonida \ --features diagnostics,dlss,mimalloc --target x86_64-pc-windows-msvc ``` `--profile play` with `diagnostics` is needed: most of the settings below are diagnostics switches. **4. Launch with the script below.** Set `GAME` to your dump's path. The first start translates shaders, which takes a while. ### Why each setting | Setting | Why | |---|---| | `LEONIDA_FG_RESET_STALE=0` | The stutter fix above | | `LEONIDA_TEXTURE_BUDGET_MB=2048` | Keeps Series X + FG within 12 GB. Without it, texture storage filled the card | | `LEONIDA_FRAME_GEN=2`, `UPSCALE=dlss`, `RENDER_SCALE=0.6667`, `OUTPUT=2560x1440` | DLSS Quality to 1440p with 2x FG. 4K output filled the card | | `LEONIDA_FG_LIMIT_FPS=0` | `auto` measured the loading screen and locked the intro at 12 fps | | `LEONIDA_WINDOWS_BAR_MB=0` | `play-nvidia.ps1` puts up to 3 GB here on PCs with <48 GB RAM, and that comes out of VRAM | | `LEONIDA_TITLE_RANGE=0` | The title range fails under Wine 11.23 (`XMemVirtualAlloc ... miss=Refused`, thousands per run) and the picture looked washed out | | `LEONIDA_PIPELINE_WAIT_MS=250` | `play-linux.sh`'s 10000 froze the game for seconds when a new pipeline was built | | DXVK `dxgi` + `hideNvidiaGpu = False` | Wine's own `dxgi` crashed at startup. DXVK reports NVIDIA cards as AMD by default | | `dxvk-nvapi` + `nvngx` + `NGXCore` registry key | What Proton does for DLSS (`PROTON_ENABLE_NVAPI`) | | `WINEDEBUG=fixme-all` | Wine prints a fixme about 400 times a second for a query Mandy makes (70% of the log) | | The remaining `LEONIDA_*` | `play-nvidia.ps1`'s play set as of `b41763227`, copied as is (it halved the per-frame refresh time). The only change is BAR 0 | Reflex stays on: without it, DLSS-G turns itself off after a few seconds (`eFailReflexNotDetectedAtRuntime`). <details><summary>Launcher script</summary> ```bash #!/bin/bash # GTA VI with Mandy under upstream Wine: Series X, DLSS Quality -> 1440p, DLSS-G 2x. `script VAR=value` overrides. GAME=/path/to/game_scarlett_master.exe dir=$HOME/Games/mandy # your Mandy checkout data=$HOME/Games/mandy-data # cache, saves, d3dcompiler_47.dll proton="$HOME/.local/share/Steam/steamapps/common/Proton - Experimental/files/lib/wine" export LEONIDA_RUNTIME=$dir/d3d12/target/x86_64-pc-windows-msvc/play/leonida.exe export LEONIDA_VKD3D=$proton/vkd3d-proton/x86_64-windows export LEONIDA_WINEPREFIX=$HOME/Games/mandy-prefix LEONIDA_CACHE_DIR=$data/cache LEONIDA_DATA_DIR=$data/data export LEONIDA_PIPELINE_WAIT_MS=250 LEONIDA_TITLE_RANGE=0 if [ ! -d "$LEONIDA_WINEPREFIX/drive_c/windows/system32" ]; then mkdir -p "$LEONIDA_WINEPREFIX" WINEPREFIX=$LEONIDA_WINEPREFIX WINEARCH=win64 WINEDLLOVERRIDES="mscoree,mshtml=" wineboot -u fi sys32=$LEONIDA_WINEPREFIX/drive_c/windows/system32 for f in "$proton/dxvk/x86_64-windows/dxgi.dll" "$data/dlls/d3dcompiler_47.dll" \ "$proton/nvapi/x86_64-windows/nvapi64.dll" "$proton/nvapi/x86_64-windows/nvofapi64.dll" \ /usr/lib/nvidia/wine/nvngx.dll /usr/lib/nvidia/wine/_nvngx.dll; do cmp -s "$f" "$sys32/${f##*/}" || install -m 644 "$f" "$sys32/${f##*/}" done chmod u+w "$sys32/d3d12.dll" "$sys32/d3d12core.dll" 2>/dev/null # Steam's copies are read-only grep -q NGXCore "$LEONIDA_WINEPREFIX/system.reg" || WINEPREFIX=$LEONIDA_WINEPREFIX wine reg add \ 'HKLM\SOFTWARE\NVIDIA Corporation\Global\NGXCore' /v FullPath /t REG_SZ /d 'C:\Windows\System32' /f export WINEDLLOVERRIDES="nvapi64,nvofapi64,dxgi,d3dcompiler_47=n" DXVK_ENABLE_NVAPI=1 export DXVK_CONFIG="dxgi.hideNvidiaGpu = False" WINEDEBUG=fixme-all sdk=$dir/d3d12/nvidia-sdk; win=Z:${sdk//\//\\} export LEONIDA_DLSS_DIR=$win\\DLSS\\lib\\Windows_x86_64\\rel LEONIDA_STREAMLINE_DIR=$win\\Streamline\\bin\\x64 export LEONIDA_UPSCALE=dlss LEONIDA_FSR_UPSCALER=1 LEONIDA_OWN_UPSCALER=0 LEONIDA_RENDER_SCALE=0.6667 export LEONIDA_OUTPUT=2560x1440 LEONIDA_FRAME_GEN=2 LEONIDA_FG_LIMIT_FPS=0 export LEONIDA_FG_RESET_STALE=0 LEONIDA_TEXTURE_BUDGET_MB=2048 # play-nvidia.ps1's play set (b41763227), BAR 0 export LEONIDA_TEXTURE_NO_WAIT=0 LEONIDA_RELAY=2 LEONIDA_CARD_STEPS=2 LEONIDA_WIDE_BACK=1 LEONIDA_CARD_REHASH_RUNS=1 \ LEONIDA_JOIN_COPIES=1 LEONIDA_INDIRECT_WINDOW=1 LEONIDA_RELAY_COPY=1 LEONIDA_FETCH_CHECK=1 LEONIDA_SUBMIT_SENDER=1 \ LEONIDA_INDIRECT_BATCH=4 LEONIDA_MAP_THREADS=1 LEONIDA_TITLE_PRIORITIES=0 LEONIDA_PORT_GUARD=1 LEONIDA_PORT_JOURNAL=1 \ LEONIDA_CARD_AWAKE=0 LEONIDA_STORE_BESIDE=1 LEONIDA_ALIAS_DIRECT=1 LEONIDA_QUICK_FIND_WINDOWS=1 \ LEONIDA_PORT_DESCRIPTORS=1 LEONIDA_COPY_SCOPED=1 LEONIDA_INDEX_HEAP_SPANS=1 LEONIDA_AHEAD_SPLIT=1 LEONIDA_SHOW_AFTER=1 \ LEONIDA_AMBIENT=0.8 LEONIDA_AMBIENT_MOST=2 LEONIDA_AMBIENT_AIR=1.5 LEONIDA_AMBIENT_ALPHA=4 LEONIDA_REFLECT_MOST=0.5 \ LEONIDA_D3D12_DRED=faults LEONIDA_THIN=1 LEONIDA_THIN_THREADS=6 LEONIDA_JOIN_PARTS=8 LEONIDA_UPLOAD_AHEAD=1 \ LEONIDA_TEXTURE_HASH_BACKOFF=1 LEONIDA_NAN_SCRUB=1 LEONIDA_STATIC_SAMPLERS_LINEAR=PS_Composite LEONIDA_EARLY_DEPTH=1 \ LEONIDA_PLACED_TITLE=1 LEONIDA_DYNAMIC_SLOTS=524288 LEONIDA_CARD_BUFFERS_MB=1536 LEONIDA_CARD_BUFFERS_MIN_MB=1 \ LEONIDA_CARD_BUFFERS_MIN_KB=64 LEONIDA_FILL_TITLE=1 LEONIDA_WC_NO_BACK=1 LEONIDA_MEMORY_MAP=0 LEONIDA_SECTION_MB=16 \ LEONIDA_WINDOWS_BAR_MB=0 \ LEONIDA_SKIP_PIPELINES=51e19585b4753814,aaabcd7a8ec90db8,9f3ecb8d133084bf,2a00e6082220d9a5 \ LEONIDA_PAIRED_FOR=ae0deeafe219c15c,407eca669212d400,18d957e62926ed3e,5e3dd99e0f067aee,57f1b81de55c2842,02384a60fda6f2d0,339d476c267c03c7,39998898c90889b2,c042a10ed3428758,c85cb6bc1cd8e2ad,c80d02ddc38ef279,be6ce5d849d51127,922e1d0ee1e19a85,1f1fbd86759b3da2,0ffd3b911e35e7d0,71883e40620a567a,3c9d23fa83d63d43,4031c6c05fa7ec48,bc76c37f9fa3672b,0a5ecfee6b79e13b,d3e5b737ea7cc150,55d2bce91ec9abcc,f8f712930c606707,40bc5fd052acfdf4,294e7cdd91ebd1f1,b7953a05b189dfc1,a53a7977fe762268,be14e72d86362031,0a5d4f9047b3dce4,8dd8d739047fe557,12b0005a30bc18a9,2620618869072a85,eb9a057a81d18c42,89ed0b981f99573c,b2711644ca5566cc,0903802745985664,ce2378e5e8711aad,136986812880cead,3c196d81eca7ff15,acf14a70f37fb012,f79824724d8e2daf,f0aa2b1e79275592,c4183d3cbee28e8e,2e92491c2ae5472b for kv in "$@"; do case "$kv" in *=*) export "$kv";; esac; done exec "$dir/scripts/play-linux.sh" "$GAME" --series-x ``` </details> <details><summary>fg-wine-scheduling.patch</summary> ```diff diff --git a/d3d12/crates/leonida-gpu/src/fg.rs b/d3d12/crates/leonida-gpu/src/fg.rs index 15a04c58d..dfcc66be7 100644 --- a/d3d12/crates/leonida-gpu/src/fg.rs +++ b/d3d12/crates/leonida-gpu/src/fg.rs @@ -844,6 +844,8 @@ fn log_reflex_report(fg: &Fg) { fn init(device: &ID3D12Device) -> anyhow::Result<Fg> { let dir = std::env::var_os("LEONIDA_STREAMLINE_DIR") .ok_or_else(|| anyhow::anyhow!("LEONIDA_STREAMLINE_DIR is not set"))?; + // Local patch (mandy): under Wine, hardware GPU scheduling reported on, as Proton's Wine does. + crate::wine_hws::report_scheduling_on(); // SAFETY: NVIDIA's signed interposer from the SDK folder the launcher names. let mut s = unsafe { sl::Sl::load(std::path::Path::new(&dir)) }?; let features = sl::FG_FEATURES; diff --git a/d3d12/crates/leonida-gpu/src/lib.rs b/d3d12/crates/leonida-gpu/src/lib.rs index 12a697870..e14b6a375 100644 --- a/d3d12/crates/leonida-gpu/src/lib.rs +++ b/d3d12/crates/leonida-gpu/src/lib.rs @@ -64,6 +64,8 @@ pub mod aspect; pub mod streamline; #[cfg(windows)] mod fg; +#[cfg(windows)] +mod wine_hws; /// Leonida: AMD FSR 3 frame generation where DLSS Frame Generation does not run (`LEONIDA_FSR_FRAMEGEN`). #[cfg(windows)] mod fsr; diff --git a/d3d12/crates/leonida-gpu/src/wine_hws.rs b/d3d12/crates/leonida-gpu/src/wine_hws.rs new file mode 100644 index 000000000..deb6a0eab --- /dev/null +++ b/d3d12/crates/leonida-gpu/src/wine_hws.rs @@ -0,0 +1,147 @@ +//! Local patch (mandy, 2026-12-02; ~/Games/mandy-data/patches/fg-wine-scheduling.patch): DLSS frame +//! generation under upstream Wine. +//! +//! Streamline gives DLSS-G only where hardware-accelerated GPU scheduling is on. It asks through +//! `D3DKMTQueryAdapterInfo` with `KMTQAITYPE_WDDM_2_7_CAPS` (gdi32; Wine forwards it to win32u's +//! `NtGdiDdDDIQueryAdapterInfo`). Wine 11.23 does not say "on", so `slIsFeatureSupported` gave +//! `eErrorOSDisabledHWS`. Proton's Wine says "on" (a win32u patch, WINE_DISABLE_HARDWARE_SCHEDULING), +//! and frame generation started there, but asking which memory this title wrote took 8 to 15 times +//! as long under it. So under Wine, before Streamline loads, win32u's system call stub for the call +//! jumps to [`query`]: that one question is answered "supported and on", every other one goes to a +//! copy of the stub, which makes the same system call. Not on Windows, where the system answers. +//! LEONIDA_FG_WINE_HWS=0 leaves it out. + +use std::sync::Once; +use std::sync::atomic::{AtomicUsize, Ordering}; + +use windows_sys::Win32::System::Diagnostics::Debug::FlushInstructionCache; +use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress, LoadLibraryA}; +use windows_sys::Win32::System::Memory::{ + MEM_COMMIT, MEM_RESERVE, PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, PAGE_PROTECTION_FLAGS, PAGE_READWRITE, + VirtualAlloc, VirtualProtect, +}; +use windows_sys::Win32::System::Threading::GetCurrentProcess; + +/// `KMTQAITYPE_WDDM_2_7_CAPS` (Wine's d3dkmthk.h: the one before `KMTQAITYPE_DISPLAY_UMDRIVERNAME`, 71). +const WDDM_2_7_CAPS: u32 = 70; +/// `D3DKMT_WDDM_2_7_CAPS`: HwSchSupported (bit 0), HwSchEnabled (bit 1). +const SCHEDULING_ON: u32 = 0b11; +/// Wine's x86-64 system call stub (win32u.dll of Wine 11.23): `mov r10, rcx; mov eax, <number>; +/// test byte [0x7ffe0308], 1; jne 1f; syscall; ret; 1: jmp 2f; ret; 2: call [0x7ffe1000]; ret`. +/// Bytes 4..8 are the number. Its addresses are absolute or inside it, so a copy anywhere makes +/// the same call. +const STUB: [u8; 32] = [ + 0x4c, 0x8b, 0xd1, 0xb8, 0, 0, 0, 0, 0xf6, 0x04, 0x25, 0x08, 0x03, 0xfe, 0x7f, 0x01, // + 0x75, 0x03, 0x0f, 0x05, 0xc3, 0xeb, 0x01, 0xc3, 0xff, 0x14, 0x25, 0x00, 0x10, 0xfe, 0x7f, 0xc3, +]; + +/// `D3DKMT_QUERYADAPTERINFO`. +#[repr(C)] +struct QueryAdapterInfo { + adapter: u32, + kind: u32, + data: *mut u32, + size: u32, +} + +type Query = unsafe extern "system" fn(*const QueryAdapterInfo) -> i32; + +/// The copy of the stub (0 until [`install`] made it). +static ORIGINAL: AtomicUsize = AtomicUsize::new(0); + +/// What the stub jumps to: `NtGdiDdDDIQueryAdapterInfo`'s own signature. +unsafe extern "system" fn query(info: *const QueryAdapterInfo) -> i32 { + // SAFETY: the caller's argument, null or a D3DKMT_QUERYADAPTERINFO, as for the system call. + if let Some(i) = unsafe { info.as_ref() } + && i.kind == WDDM_2_7_CAPS + && !i.data.is_null() + && i.size >= 4 + { + // SAFETY: the caller's buffer, `size` bytes. + unsafe { i.data.write_unaligned(SCHEDULING_ON) }; + return 0; // STATUS_SUCCESS + } + // SAFETY: stored before the stub was sent here; a copy of the stub, the same signature. + let original = unsafe { std::mem::transmute::<usize, Query>(ORIGINAL.load(Ordering::Acquire)) }; + // SAFETY: the caller's argument, passed on. + unsafe { original(info) } +} + +/// Under Wine, once (from `fg::init`, before Streamline loads): [`install`], and says what it did. +pub(crate) fn report_scheduling_on() { + static ONCE: Once = Once::new(); + ONCE.call_once(|| { + if std::env::var_os("LEONIDA_FG_WINE_HWS").is_some_and(|v| v == "0") { + return; + } + // SAFETY: see `install`. + match unsafe { install() } { + Ok(false) => {} + Ok(true) => tracing::info!( + "frame generation: Wine's answer about hardware GPU scheduling is \"on\" in this process, as Proton's (LEONIDA_FG_WINE_HWS=0 leaves it)" + ), + Err(e) => tracing::warn!(error = e, "frame generation: Wine's answer about hardware GPU scheduling left as it is"), + } + }); +} + +/// Sends win32u's `NtGdiDdDDIQueryAdapterInfo` to [`query`]: `Ok(false)` when this is not Wine, an +/// error when its stub is not the one this knows (another Wine), and nothing is changed. +/// +/// # Safety +/// Once per process. The stub's first 12 bytes are rewritten in place: a thread inside them at +/// that moment would run a mix of both (it is called at a device's start, not per frame). +pub(crate) unsafe fn install() -> Result<bool, &'static str> { + // SAFETY: plain lookups in loaded system DLLs (gdi32 loaded if it was not). + let target = unsafe { + let ntdll = GetModuleHandleA(c"ntdll.dll".as_ptr().cast()); + if ntdll.is_null() || GetProcAddress(ntdll, c"wine_get_version".as_ptr().cast()).is_none() { + return Ok(false); + } + let gdi32 = LoadLibraryA(c"gdi32.dll".as_ptr().cast()); + if gdi32.is_null() { + return Err("gdi32.dll did not load"); + } + // Through gdi32, as Streamline imports it: the address Wine's forward resolves to. + match GetProcAddress(gdi32, c"D3DKMTQueryAdapterInfo".as_ptr().cast()) { + Some(f) => f as usize as *mut u8, + None => return Err("gdi32.dll has no D3DKMTQueryAdapterInfo"), + } + }; + // SAFETY: the start of an exported function's code; the rest is read only if that matches. + let known = unsafe { + std::slice::from_raw_parts(target, 4) == &STUB[..4] + && std::slice::from_raw_parts(target.add(8), STUB.len() - 8) == &STUB[8..] + }; + if !known { + return Err("D3DKMTQueryAdapterInfo is not the system call stub this patch knows (another Wine)"); + } + // SAFETY: a new private page, the stub copied into it, then made executable. + let copy = unsafe { VirtualAlloc(std::ptr::null(), 4096, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) }.cast::<u8>(); + if copy.is_null() { + return Err("no memory for the copy of the stub"); + } + let mut old: PAGE_PROTECTION_FLAGS = 0; + // SAFETY: as above. + unsafe { + std::ptr::copy_nonoverlapping(target, copy, STUB.len()); + if VirtualProtect(copy.cast(), 4096, PAGE_EXECUTE_READ, &mut old) == 0 { + return Err("the copy of the stub could not be made executable"); + } + } + ORIGINAL.store(copy as usize, Ordering::Release); + // mov rax, query; jmp rax (rax is the stub's scratch: it puts the number there). + let mut jump = [0x48, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xe0]; + jump[2..10].copy_from_slice(&(query as Query as usize as u64).to_le_bytes()); + // SAFETY: the stub's own bytes, made writable for the write and given their protection back. + unsafe { + if VirtualProtect(target.cast(), jump.len(), PAGE_EXECUTE_READWRITE, &mut old) == 0 { + return Err("the stub could not be made writable"); + } + std::ptr::copy_nonoverlapping(jump.as_ptr(), target, jump.len()); + let mut was: PAGE_PROTECTION_FLAGS = 0; + let _ = VirtualProtect(target.cast(), jump.len(), old, &mut was); + let _ = FlushInstructionCache(GetCurrentProcess(), target.cast(), jump.len()); + } + Ok(true) +} ``` </details> ### For the devs - **`FG_RESET_STALE`:** under Wine, a large share of gameplay presents (15–33%) arrive without a fresh upscale. I don't know why, but resetting DLSS-G on all of them (and on the present after) costs a third of the generated frames and makes the pacing uneven. Maybe default it off on Linux, or only reset on real cuts? - **Texture pool:** it frees only completely empty 64 MB blocks, but the room and keep rules count empty space inside blocks as free (`resource.rs` `room()` / keep policy). On Series X + FG, blocks reached 4.0 GB while only 1.4–1.6 GB of textures were in them. An absolute cap works around it. - **FG under upstream Wine:** without something like the patch above, upstream Wine can't run DLSS-G at all. Happy to open a PR.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy#3370
No description provided.