GPU: the guards make only views read-only, never committed private memory or free memory (the world froze with the structure builder on) #1144

Open
tippythetaidum wants to merge 2 commits from upstream-pr/1147 into main
tippythetaidum commented 2026-11-25 21:39:04 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by tippythetaidum on 2026-11-25T21:39:04Z.


Problem

With VICTORY_BVH_BUILDER=1 (the #994 stack merged into a tree based on 0b0074e), the title froze 3, 18 and 4 seconds after the log's "the ray-tracing structure builder runs" line, in 3 runs of 3 on an RTX 5080. CPU time stopped advancing, the card sat at 7-10 % with no device loss and no driver event, and the process stayed alive. That is the same picture as #942 (all threads waiting, GPU idle).

Thread dumps of the freezes, read with WinDbg against the builds' own PDBs:

  • In watch::install::on_write, waiting for the guard lock in Mutex::lock_contended: the submission thread, the title's main thread, a pipeline worker, and a D3D12 background thread inside the driver's shader compiler (nvgpucomp64, reached through RtlDispatchException → RtlpCallVectoredHandlers).
  • Waiting for the process heap's lock in RtlAllocateHeap: the audio thread (apu::process) and the XInput poll.
  • The exception record on one of the threads in on_write is a write fault at 0x5a2e30. That is inside the process heap, whose handle (0x590000) is on the audio thread's RtlAllocateHeap frame.

So a page of the process heap had been made read-only by the guards. The heap's own code then faulted while holding the heap lock, the fault waited in on_write for the guard lock, and the guard lock's holder was waiting for the heap lock.

Cause

Two ways in watch.rs let committed memory that is not the title's be made read-only:

  1. A range that begins in mapped memory and runs into other memory. is_view answers yes as soon as the first region is MEM_MAPPED. protect_here then tries the whole range, and when that fails (it spans allocations) it protects it block by block, so every committed block in the range is made read-only, private memory included. In the third freeze's dump, which carries the memory map, the 4 MiB window 0x400000-0x800000 (beginning in a read-only mapped region at 0x400000) had every committed private block in it read-only: the process heap's blocks 0x590000-0x660000 (allocation base 0x570000, allocated read-write), plus 0x430000-0x440000 and 0x6c0000-0x800000. That last one stops exactly at the window's end while the same allocation goes on read-write above it. The write faults there were at 0x5e90dc and 0x5b3920 (audio freeing an Opus decoder, the XInput poll, a thread-pool memset).
  2. Free memory. Before this change, is_view also took a range with free memory in it for a view ("a hole (a placeholder, or free)"). uncommitted_end then noted the blocks absent, to be guarded once mapped, so whatever the process allocated there later would have been guarded with it. Marvisak/VIctory#1849 found this under Wine (a null address's window over the process heap).

Marvisak/VIctory's main has since moved to deciding region by region (280b150: anything but committed private memory and images). This change does the same here.

Change (crates/victory-gpu/src/watch.rs)

  • protect_here walks the range region by region. It guards only memory that is not committed private memory and not an image: views, and placeholders, which are noted absent when their protection fails, as before.
  • is_view: a free region ends the walk with "not a view".
  • uncommitted_end: only placeholders (MEM_RESERVE) are uncommitted blocks to note absent, not free memory.
  • New tests, each failing without its change:
    • committed_private_memory_beside_a_view_is_not_guarded: a view and committed private memory side by side in one split placeholder. The view is guarded and the private block stays writable. Without the change the private block ends up read-only.
    • free_memory_is_not_tracked: a released reservation is not tracked. It is checked only while the memory is still free, since other tests allocate meanwhile.

Tested

  • On this branch (main 9c184b3 plus the two commits): cargo test -p victory-gpu --lib -- watch:: gives 16 passed, 0 failed, 1 ignored (an event-log test). cargo clippy -p victory-gpu --all-targets -- -D warnings reports 7 errors, all in other files and already on main (resource.rs, fpsbox.rs, draw.rs, pipeline/library.rs, queue.rs, shadow.rs, indirect.rs), none in watch.rs.
  • In the title, in my tree with both changes and the builder on: the builder ran 2 min 34 s from its first frame until I stopped the run, with no freeze and 0 errors. Before, 3 runs of 3 froze 3 to 18 s after it started. I haven't run it longer than that yet.

Possibly the same freeze as #942 (same base commit, same signature), not verified on that machine.

AI-assisted (Claude Code, Claude Opus 5.5): dump reading, the change and this text. Runs on my machine; no game data attached.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6614280292 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1147). Originally posted by [tippythetaidum](https://github.com/tippythetaidum) on 2026-11-25T21:39:04Z. --- ## Problem With `VICTORY_BVH_BUILDER=1` (the #994 stack merged into a tree based on `0b0074e`), the title froze 3, 18 and 4 seconds after the log's "the ray-tracing structure builder runs" line, in 3 runs of 3 on an RTX 5080. CPU time stopped advancing, the card sat at 7-10 % with no device loss and no driver event, and the process stayed alive. That is the same picture as #942 (all threads waiting, GPU idle). Thread dumps of the freezes, read with WinDbg against the builds' own PDBs: - In `watch::install::on_write`, waiting for the guard lock in `Mutex::lock_contended`: the submission thread, the title's main thread, a pipeline worker, and a D3D12 background thread inside the driver's shader compiler (`nvgpucomp64`, reached through `RtlDispatchException` → `RtlpCallVectoredHandlers`). - Waiting for the process heap's lock in `RtlAllocateHeap`: the audio thread (`apu::process`) and the XInput poll. - The exception record on one of the threads in `on_write` is a write fault at `0x5a2e30`. That is inside the process heap, whose handle (`0x590000`) is on the audio thread's `RtlAllocateHeap` frame. So a page of the process heap had been made read-only by the guards. The heap's own code then faulted while holding the heap lock, the fault waited in `on_write` for the guard lock, and the guard lock's holder was waiting for the heap lock. ## Cause Two ways in `watch.rs` let committed memory that is not the title's be made read-only: 1. **A range that begins in mapped memory and runs into other memory.** `is_view` answers yes as soon as the first region is `MEM_MAPPED`. `protect_here` then tries the whole range, and when that fails (it spans allocations) it protects it block by block, so every committed block in the range is made read-only, private memory included. In the third freeze's dump, which carries the memory map, the 4 MiB window `0x400000`-`0x800000` (beginning in a read-only mapped region at `0x400000`) had **every committed private block in it read-only**: the process heap's blocks `0x590000`-`0x660000` (allocation base `0x570000`, allocated read-write), plus `0x430000`-`0x440000` and `0x6c0000`-`0x800000`. That last one stops exactly at the window's end while the same allocation goes on read-write above it. The write faults there were at `0x5e90dc` and `0x5b3920` (audio freeing an Opus decoder, the XInput poll, a thread-pool `memset`). 2. **Free memory.** Before this change, `is_view` also took a range with *free* memory in it for a view ("a hole (a placeholder, or free)"). `uncommitted_end` then noted the blocks absent, to be guarded once mapped, so whatever the process allocated there later would have been guarded with it. Marvisak/VIctory#1849 found this under Wine (a null address's window over the process heap). Marvisak/VIctory's main has since moved to deciding region by region (280b150: anything but committed private memory and images). This change does the same here. ## Change (`crates/victory-gpu/src/watch.rs`) - `protect_here` walks the range region by region. It guards only memory that is not committed private memory and not an image: views, and placeholders, which are noted absent when their protection fails, as before. - `is_view`: a free region ends the walk with "not a view". - `uncommitted_end`: only placeholders (`MEM_RESERVE`) are uncommitted blocks to note absent, not free memory. - New tests, each failing without its change: - `committed_private_memory_beside_a_view_is_not_guarded`: a view and committed private memory side by side in one split placeholder. The view is guarded and the private block stays writable. Without the change the private block ends up read-only. - `free_memory_is_not_tracked`: a released reservation is not tracked. It is checked only while the memory is still free, since other tests allocate meanwhile. ## Tested - On this branch (`main` `9c184b3` plus the two commits): `cargo test -p victory-gpu --lib -- watch::` gives 16 passed, 0 failed, 1 ignored (an event-log test). `cargo clippy -p victory-gpu --all-targets -- -D warnings` reports 7 errors, all in other files and already on `main` (`resource.rs`, `fpsbox.rs`, `draw.rs`, `pipeline/library.rs`, `queue.rs`, `shadow.rs`, `indirect.rs`), none in `watch.rs`. - In the title, in my tree with both changes and the builder on: the builder ran 2 min 34 s from its first frame until I stopped the run, with no freeze and 0 errors. Before, 3 runs of 3 froze 3 to 18 s after it started. I haven't run it longer than that yet. Possibly the same freeze as #942 (same base commit, same signature), not verified on that machine. AI-assisted (Claude Code, Claude Opus 5.5): dump reading, the change and this text. Runs on my machine; no game data attached. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tippythetaidum commented 2026-11-25 23:09:57 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by tippythetaidum on 2026-11-25T22:33:22Z.


Related, and earlier: #804 (AscilCH) fixes one route to the same fault. A block noted absent that later becomes private memory is no longer treated as a known view (known_view and guard check protected only, and is_view before a block leaves absent).

How they relate:

  • #804's route, absent then reallocated as private, is also closed here as a consequence: protect_here never makes committed private memory read-only, whatever the guard state says.
  • The route in this PR's dump isn't that one. The 4 MiB window 0x400000-0x800000 began in mapped memory, so is_view answered yes at its first region, and the heap's blocks were protected block by block without ever being absent. #804 alone wouldn't stop that; the region check in protect_here does.

Both touch watch.rs's guard/known_view neighbourhood, so whichever lands second needs a rebase. I'm happy to rebase this onto #804 if it goes first. The two tests check different things (absent_block_reallocated_as_private_memory_is_not_guarded there, committed_private_memory_beside_a_view_is_not_guarded here) and can both stay.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7176508899 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1147#issuecomment-7176508899). Originally posted by [tippythetaidum](https://github.com/tippythetaidum) on 2026-11-25T22:33:22Z. --- Related, and earlier: #804 (AscilCH) fixes one route to the same fault. A block noted `absent` that later becomes private memory is no longer treated as a known view (`known_view` and `guard` check `protected` only, and `is_view` before a block leaves `absent`). How they relate: - **#804's route**, absent then reallocated as private, is also closed here as a consequence: `protect_here` never makes committed private memory read-only, whatever the guard state says. - **The route in this PR's dump isn't that one.** The 4 MiB window `0x400000`-`0x800000` began in mapped memory, so `is_view` answered yes at its first region, and the heap's blocks were protected block by block without ever being `absent`. #804 alone wouldn't stop that; the region check in `protect_here` does. Both touch `watch.rs`'s `guard`/`known_view` neighbourhood, so whichever lands second needs a rebase. I'm happy to rebase this onto #804 if it goes first. The two tests check different things (`absent_block_reallocated_as_private_memory_is_not_guarded` there, `committed_private_memory_beside_a_view_is_not_guarded` here) and can both stay. AI-assisted (Claude Code, Claude Opus 5.5).
Proudnoob4 commented 2026-11-26 00:06:09 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Proudnoob4 on 2026-11-25T23:17:51Z.


AI-assisted (Claude Opus 5.5 in OpenCode), measured on my own machine. This replaces two overlapping AI-written reports I posted here earlier; on re-auditing the logs, some of their numbers were single samples or misattributed, and one said there were no visual artifacts, which was wrong.

Setup: RTX 4080 16 GB, Windows 10 22H2, Series X build, diagnostics release, prison-cell scene (~4,800 draws/frame). Three single 360 s runs, so this is a bundle comparison, not an isolated A/B:

  • A fxceless stack, f32 path
  • B = A + a local port of Marvisak/VIctory#2825 native f16
  • C = B + #1168 + #1147 + #1164 (VICTORY_CARD_PIECE_KB=16) + #1171 + #1172 + a local commit (skip clean card_dirty copies; chunk wide compare dispatches to ≤ 65,535 groups)
In-world, from the logs A B C
FPS, 2nd-half median (max) 8.8 (9.3) 8.8 (9.7) 8.9 (9.4)
Usual frame, median 112 ms 111 ms 113 ms
GPU title lists (all other lists), 2nd-half median 40.0 ms 38.1 ms 31.8 ms
cardmeter, 256-frame mean, steady 40.8 ms 40.9 ms 31.6–33.7 ms
Copy-back (last usual-frame summary) 23.2 ms / 62.5 MB 22.4 ms / 60.9 MB 28.4 ms / 49.4 MB
Pieces fetched on the copy queue / frame ~1,370 ~1,388 ~4,138
Writes back in place / frame 1,386 1,390 4,150
Card idle per frame 62.5 ms 68.7 ms 68.8 ms
  • GPU: title-list time fell by ~8 ms between B and C. Native f16 alone (A→B) changed it by ~2 ms at most (cardmeter unchanged). Which of C's additions gave the 8 ms is not isolated.
  • No FPS change: the frame is CPU-bound on the submit thread (copies ~63 ms + copy-back 22–28 ms of a ~110 ms frame), so the GPU saving does not reach the screen.
  • Artifacts in C: a frame grabbed at 330 s shows blocky corrupted tiles along the bottom of the screen and a stair-stepped edge on the character's shoulder. Which change causes it is not isolated. B's earlier frame looked clean.
  • Stability: no panic, device-removed or ERROR lines in C's log, no crash in 360 s.

For this PR: ran in C with no crash. The last summary shows 396 guard faults and 291 page faults per frame, against 372 / 198 in B. I can't tell whether that rise comes from this PR or from the other changes in C.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7177374642 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1147#issuecomment-7177374642). Originally posted by [Proudnoob4](https://github.com/Proudnoob4) on 2026-11-25T23:17:51Z. --- *AI-assisted (Claude Opus 5.5 in OpenCode), measured on my own machine. **This replaces two overlapping AI-written reports I posted here earlier; on re-auditing the logs, some of their numbers were single samples or misattributed, and one said there were no visual artifacts, which was wrong.*** **Setup:** RTX 4080 16 GB, Windows 10 22H2, Series X build, diagnostics release, prison-cell scene (~4,800 draws/frame). Three single 360 s runs, so this is a bundle comparison, not an isolated A/B: - **A** fxceless stack, f32 path - **B** = A + a local port of `Marvisak/VIctory#2825` native f16 - **C** = B + `#1168` + `#1147` + `#1164` (`VICTORY_CARD_PIECE_KB=16`) + `#1171` + `#1172` + a local commit (skip clean `card_dirty` copies; chunk wide compare dispatches to ≤ 65,535 groups) | In-world, from the logs | A | B | C | |---|---:|---:|---:| | FPS, 2nd-half median (max) | 8.8 (9.3) | 8.8 (9.7) | 8.9 (9.4) | | Usual frame, median | 112 ms | 111 ms | 113 ms | | GPU title lists (`all other lists`), 2nd-half median | 40.0 ms | 38.1 ms | **31.8 ms** | | `cardmeter`, 256-frame mean, steady | 40.8 ms | 40.9 ms | **31.6–33.7 ms** | | Copy-back (last usual-frame summary) | 23.2 ms / 62.5 MB | 22.4 ms / 60.9 MB | **28.4 ms** / 49.4 MB | | Pieces fetched on the copy queue / frame | ~1,370 | ~1,388 | **~4,138** | | Writes back in place / frame | 1,386 | 1,390 | 4,150 | | Card idle per frame | 62.5 ms | 68.7 ms | 68.8 ms | - **GPU:** title-list time fell by ~8 ms between B and C. Native f16 alone (A→B) changed it by ~2 ms at most (`cardmeter` unchanged). Which of C's additions gave the 8 ms is **not isolated**. - **No FPS change:** the frame is CPU-bound on the submit thread (copies ~63 ms + copy-back 22–28 ms of a ~110 ms frame), so the GPU saving does not reach the screen. - **Artifacts in C:** a frame grabbed at 330 s shows blocky corrupted tiles along the bottom of the screen and a stair-stepped edge on the character's shoulder. Which change causes it is **not isolated**. B's earlier frame looked clean. - **Stability:** no panic, device-removed or ERROR lines in C's log, no crash in 360 s. **For this PR:** ran in C with no crash. The last summary shows 396 guard faults and 291 page faults per frame, against 372 / 198 in B. I can't tell whether that rise comes from this PR or from the other changes in C.
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/1147:upstream-pr/1147'
git switch 'upstream-pr/1147'

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/1147'
git switch 'upstream-pr/1147'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1147'
git switch 'upstream-pr/1147'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1147'
git switch 'main'
git merge --squash 'upstream-pr/1147'
git switch 'main'
git merge --ff-only 'upstream-pr/1147'
git switch 'main'
git merge 'upstream-pr/1147'
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
fxceless/victory-fork!1144
No description provided.