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

Open
sil-kong wants to merge 2 commits from upstream-pr/69 into main
sil-kong commented 2026-11-25 13:18:02 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by sil-kong on 2026-11-25T13:18:02Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:6605381235 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/69). Originally posted by [sil-kong](https://github.com/sil-kong) on 2026-11-25T13:18:02Z. --- 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.
gut0to commented 2026-11-25 15:08:49 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-25T15:08:49Z.

Review: COMMENTED


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

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6060182196 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/69#pullrequestreview-6060182196). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-25T15:08:49Z. **Review:** COMMENTED --- AI-assisted review: I checked the changed behavior and the associated test coverage.
gut0to commented 2026-11-25 15:08:50 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-25T15:08:50Z.

Code review location: crates/victory-gpu/src/shadow.rs; line 1789

@@ -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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4696895537 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/69#discussion_r4696895537). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-25T15:08:50Z. **Code review location:** `crates/victory-gpu/src/shadow.rs`; line 1789 ~~~~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.
sil-kong commented 2026-11-25 15:11:34 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by sil-kong on 2026-11-25T15:11:34Z.


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).

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7166449425 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/69#issuecomment-7166449425). Originally posted by [sil-kong](https://github.com/sil-kong) on 2026-11-25T15:11:34Z. --- 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).
TobiasFornell commented 2026-11-25 21:35:58 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by TobiasFornell on 2026-11-25T21:35:58Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7175290791 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/69#issuecomment-7175290791). Originally posted by [TobiasFornell](https://github.com/TobiasFornell) on 2026-11-25T21:35:58Z. --- 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/69:upstream-pr/69'
git switch 'upstream-pr/69'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/69'
git switch 'upstream-pr/69'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/69'
git switch 'upstream-pr/69'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/69'
git switch 'main'
git merge --squash 'upstream-pr/69'
git switch 'main'
git merge --ff-only 'upstream-pr/69'
git switch 'main'
git merge 'upstream-pr/69'
git push origin 'main'
Sign in to join this conversation.
No reviewers
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
Belobug/VIctory-Belobug-AMD!69
No description provided.