Under Wine, copies of title memory are not sparse buffers by default (GPU reset once the world loads) #69

Open
github-bot wants to merge 2 commits from github-bot/gh-69 into main AGit
Owner

@⁠sil-kong on GitHub · 2026-11-25 13:18 UTC · original
sil-kong:wine-no-sparse → main · +52 −1 · 1 files · 2 commits · open

Under Wine, once the world loads, sparse copies of title memory hang the GPU until the driver resets it. This turns them off by default under Wine only.

What happens

Linux, RX 7900 XT (RDNA3), RADV / Mesa 26.2.7, GE-Proton10-34's Wine with vkd3d-proton from Proton Experimental, x86_64-pc-windows-gnu release of 71652a2, with title memory copied (VICTORY_COPY_MEMORY=1, which #53 makes the default under Wine).

The intro and loading pass. When the world loads, the GPU time per frame goes from tens of ms to seconds:

0.1 fps, 6983 ms/frame (... 6106 ms on the GPU ...), 284 draws/frame, dropped 1544 (365 being made)
0.1 fps, 8676 ms/frame (... 6350 ms on the GPU ...)
slow host submission ms=17356 lists=36 ...

A minute later the card was reset and the desktop (Hyprland, same GPU) went down with it; the machine had to be restarted. The kernel journal of that boot was not flushed, so I have no reset line to quote, only the log above and the crash.

Each tile mapping of a sparse copy becomes a sparse bind on the queue in vkd3d-proton (UpdateTileMappings), which on RADV is costly, and the world maps many tiles a frame.

Change

One function, sparse() in crates/victory-gpu/src/shadow.rs. Under Wine (ntdll exports wine_get_version, as xmem::on_wine tells) copies of title memory are made per title buffer or window, as before cc4d18d. Windows is unchanged.

VICTORY_SPARSE Windows Wine
not set sparse (as before) not sparse
0 not sparse not sparse
any other value sparse sparse

The log line says which: copies of title memory in sparse buffers on=false wine=true.

Tested

Same machine, same build plus this change, same save, first room of the prison. Nothing else changed between the two runs.

sparse (as now) not sparse (this branch)
GPU time per frame in the world 6.1 to 6.4 s, then a GPU reset about 90 ms
Frame rate 0.1 1.5 to 2.0
Draws per frame 284, 1544 dropped about 6,870, about 320 dropped
Run ended by the reset (desktop down) over 20 minutes, no fault

The cost: without sparse copies the CPU copies more per frame (about 640 MB in about 100 ms here), so this trades the GPU hang for CPU time. Some of #18's work might make the sparse path usable under Wine later; VICTORY_SPARSE=1 is there to try it.

#6 (Linux, RADV, the desktop froze once the world was black) might be the same; I can't tell from here.

Builds with cargo build --release -p victory --target x86_64-pc-windows-gnu; no new warnings.

**@⁠sil-kong** on GitHub · 2026-11-25 13:18 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/69) `sil-kong:wine-no-sparse` → `main` · +52 −1 · 1 files · 2 commits · open Under Wine, once the world loads, sparse copies of title memory hang the GPU until the driver resets it. This turns them off by default under Wine only. ## What happens Linux, RX 7900 XT (RDNA3), RADV / Mesa 26.2.7, GE-Proton10-34's Wine with vkd3d-proton from Proton Experimental, `x86_64-pc-windows-gnu` release of `71652a2`, with title memory copied (`VICTORY_COPY_MEMORY=1`, which #53 makes the default under Wine). The intro and loading pass. When the world loads, the GPU time per frame goes from tens of ms to seconds: ``` 0.1 fps, 6983 ms/frame (... 6106 ms on the GPU ...), 284 draws/frame, dropped 1544 (365 being made) 0.1 fps, 8676 ms/frame (... 6350 ms on the GPU ...) slow host submission ms=17356 lists=36 ... ``` A minute later the card was reset and the desktop (Hyprland, same GPU) went down with it; the machine had to be restarted. The kernel journal of that boot was not flushed, so I have no reset line to quote, only the log above and the crash. Each tile mapping of a sparse copy becomes a sparse bind on the queue in vkd3d-proton (`UpdateTileMappings`), which on RADV is costly, and the world maps many tiles a frame. ## Change One function, `sparse()` in `crates/victory-gpu/src/shadow.rs`. Under Wine (ntdll exports `wine_get_version`, as `xmem::on_wine` tells) copies of title memory are made per title buffer or window, as before `cc4d18d`. Windows is unchanged. | `VICTORY_SPARSE` | Windows | Wine | |---|---|---| | not set | sparse (as before) | **not sparse** | | `0` | not sparse | not sparse | | any other value | sparse | sparse | The log line says which: `copies of title memory in sparse buffers on=false wine=true`. ## Tested Same machine, same build plus this change, same save, first room of the prison. Nothing else changed between the two runs. | | sparse (as now) | not sparse (this branch) | |---|---|---| | GPU time per frame in the world | 6.1 to 6.4 s, then a GPU reset | about 90 ms | | Frame rate | 0.1 | 1.5 to 2.0 | | Draws per frame | 284, 1544 dropped | about 6,870, about 320 dropped | | Run | ended by the reset (desktop down) | over 20 minutes, no fault | The cost: without sparse copies the CPU copies more per frame (about 640 MB in about 100 ms here), so this trades the GPU hang for CPU time. Some of #18's work might make the sparse path usable under Wine later; `VICTORY_SPARSE=1` is there to try it. #6 (Linux, RADV, the desktop froze once the world was black) might be the same; I can't tell from here. Builds with `cargo build --release -p victory --target x86_64-pc-windows-gnu`; no new warnings.
vkd3d-proton turns each tile mapping into a sparse bind on the queue. On
RADV, once the world loads, frames took 6 to 9 s on the GPU and
submissions up to 17 s, until the driver reset the card and the desktop
went down with it. Without sparse copies (one copy per title buffer or
window, as before cc4d18d) the same scene runs at about 90 ms of GPU time
a frame.

VICTORY_SPARSE=1 keeps them under Wine; VICTORY_SPARSE=0 turns them off
everywhere. Windows is unchanged.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:34:57 +00:00
Author
Owner

@⁠sil-kong on GitHub · 2026-11-25 15:11 UTC · original

Done: the choice is now sparse_policy(switch, wine), a pure function sparse_on calls once, and sparse_copies_are_off_under_wine_unless_asked_for covers unset (on natively, off under Wine) and VICTORY_SPARSE=0/1 on both hosts. The test passes (cargo test -p victory-gpu --lib, run under Wine). Also rebased on current main (01aadd1).

**@⁠sil-kong** on GitHub · 2026-11-25 15:11 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/69#issuecomment-7166449425) Done: the choice is now `sparse_policy(switch, wine)`, a pure function `sparse_on` calls once, and `sparse_copies_are_off_under_wine_unless_asked_for` covers unset (on natively, off under Wine) and `VICTORY_SPARSE=0`/`1` on both hosts. The test passes (`cargo test -p victory-gpu --lib`, run under Wine). Also rebased on current main (01aadd1).
Author
Owner

@⁠TobiasFornell on GitHub · 2026-11-25 21:35 UTC · original

Adding an RDNA4 data point here: on CachyOS Linux, RX 9070 XT (RDNA4, RADV), Proton Experimental (Belobug-based local branch with #53's copy mode, #100's 4 KiB tile-base fix, and local CPU-prep patches), sparse copies of title memory do not trigger the ~6 s GPU hang or device reset seen on RDNA3 / Mesa 26.2.7.

In a 600 s prison-cell run (measured after world entry: 461 ms/frame median — 292 ms prep, 88 ms copy-back, 81 ms GPU), sparse copies ran cleanly with 0 kernel GPU page faults. Keeping VICTORY_SPARSE=1 available as an opt-in override when defaulting it off under Wine looks like the right call.

**@⁠TobiasFornell** on GitHub · 2026-11-25 21:35 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/69#issuecomment-7175290791) Adding an RDNA4 data point here: on **CachyOS Linux, RX 9070 XT (RDNA4, RADV), Proton Experimental** (Belobug-based local branch with #53's copy mode, #100's 4 KiB tile-base fix, and local CPU-prep patches), sparse copies of title memory do **not** trigger the ~6 s GPU hang or device reset seen on RDNA3 / Mesa 26.2.7. In a 600 s prison-cell run (measured after world entry: `461 ms/frame` median — 292 ms prep, 88 ms copy-back, **81 ms GPU**), sparse copies ran cleanly with **0 kernel GPU page faults**. Keeping `VICTORY_SPARSE=1` available as an opt-in override when defaulting it off under Wine looks like the right call.
Author
Owner

@⁠gut0to on GitHub · 2026-11-25 15:08 UTC · original
On crates/victory-gpu/src/shadow.rs line 1789 (outdated):

@@ -1775,9 +1775,40 @@ fn sparse_buffer(start: u64, len: u64, of: Option<Arc<Shadow>>) -> Option<Shadow
     })
 }
 
+/// Whether copies of title memory go in sparse buffers. Under Wine they do
+/// not by default: vkd3d-proton turns each tile mapping into a sparse bind
+/// on the queue, and with the world loading, frames took 6 to 9 s on the
+/// GPU, submissions up to 17 s, until the driver reset the card (on RADV
+/// the desktop went down with it). Without them, as before `cc4d18d`, each
+/// title buffer or window gets its own copy. `VICTORY_SPARSE=1` keeps them
+/// under Wine, `VICTORY_SPARSE=0` turns them off everywhere.
+fn sparse_on() -> bool {
+    static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
+    *ON.get_or_init(|| {
+        let wine = on_wine_host();
+        let on = match std::env::var_os("VICTORY_SPARSE") {

Could the default/override policy be extracted into a small pure helper and tested for both Wine defaults and explicit VICTORY_SPARSE=0/1? This toggle changes a GPU-reset-prone path, and OnceLock currently leaves the environment-selection cases untested. AI-assisted review; I checked the selection logic and test coverage.

**@⁠gut0to** on GitHub · 2026-11-25 15:08 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/69#discussion_r4696895537) On `crates/victory-gpu/src/shadow.rs` line 1789 (outdated): ```diff @@ -1775,9 +1775,40 @@ fn sparse_buffer(start: u64, len: u64, of: Option<Arc<Shadow>>) -> Option<Shadow }) } +/// Whether copies of title memory go in sparse buffers. Under Wine they do +/// not by default: vkd3d-proton turns each tile mapping into a sparse bind +/// on the queue, and with the world loading, frames took 6 to 9 s on the +/// GPU, submissions up to 17 s, until the driver reset the card (on RADV +/// the desktop went down with it). Without them, as before `cc4d18d`, each +/// title buffer or window gets its own copy. `VICTORY_SPARSE=1` keeps them +/// under Wine, `VICTORY_SPARSE=0` turns them off everywhere. +fn sparse_on() -> bool { + static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new(); + *ON.get_or_init(|| { + let wine = on_wine_host(); + let on = match std::env::var_os("VICTORY_SPARSE") { ``` Could the default/override policy be extracted into a small pure helper and tested for both Wine defaults and explicit VICTORY_SPARSE=0/1? This toggle changes a GPU-reset-prone path, and OnceLock currently leaves the environment-selection cases untested. AI-assisted review; I checked the selection logic and test coverage.
Author
Owner

@⁠gut0to on GitHub · 2026-11-25 15:08 UTC · original · reviewed

AI-assisted review: I checked the changed behavior and the associated test coverage.

**@⁠gut0to** on GitHub · 2026-11-25 15:08 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/69#pullrequestreview-6060182196) · **reviewed** AI-assisted review: I checked the changed behavior and the associated test coverage.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/69/head:github-bot/gh-69'
git switch 'github-bot/gh-69'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-69'
git switch 'github-bot/gh-69'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-69'
git switch 'github-bot/gh-69'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-69'
git switch 'main'
git merge --squash 'github-bot/gh-69'
git switch 'main'
git merge --ff-only 'github-bot/gh-69'
git switch 'main'
git merge 'github-bot/gh-69'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.