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

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

@⁠tippythetaidum on GitHub · 2026-11-25 21:39 UTC · original
tippythetaidum:gpu/watch-free-memory → main · +185 −21 · 1 files · 2 commits · open

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

**@⁠tippythetaidum** on GitHub · 2026-11-25 21:39 UTC · [original](https://github.com/fxceless/victory-fork/pull/1147) `tippythetaidum:gpu/watch-free-memory` → `main` · +185 −21 · 1 files · 2 commits · open ## 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)
Two runs with VICTORY_BVH_BUILDER=1 froze 3 and 18 s after the builder
started: CPU time stopped, the card idle, no device loss. Thread dumps:
threads waiting in watch::install::on_write for the guard lock (the
submission thread, the title's main thread, a pipeline worker, and a
D3D12 background thread inside the driver's shader compiler), and others
waiting for the process heap's lock (audio, XInput). The faulting write
on one of them was at 0x5a2e30, inside the process heap (0x590000).

is_view took a range with free memory in it for a view and noted its
blocks absent, to be guarded once mapped; whatever the process allocated
there later was guarded with it, the heap too. The heap's own code then
faulted while holding its lock, the fault waited for the guard lock, and
the guard lock's holder for the heap. Free memory now is no view and is
not noted absent (placeholders still are), as Marvisak/VIctory#1849 found
under Wine. New test free_memory_is_not_tracked fails without the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
R12 (with f60e726) froze 4 s after the structure builder started, as
before. Its dump, taken with the memory map: the process heap's committed
blocks 0x590000-0x660000 read-only (allocated read-write, base 0x570000),
and with them 0x430000-0x440000 and 0x6c0000-0x800000: every committed
private block of the 4 MiB 0x400000-0x800000, ending exactly at its end
while the same allocation goes on read-write above it. Write faults at
0x5e90dc and 0x5b3920 (audio freeing an Opus decoder, XInput, a thread
pool memset), each waiting in on_write for the guard lock.

That window begins in mapped memory, so is_view says it is a view, and
protect_here, after the whole range failed, made it read-only block by
block, committed private blocks included. protect_here now walks the
range region by region and guards only memory that is not committed
private memory or an image (views; placeholders are noted absent as
before), as Marvisak/VIctory's 280b150 decides.

New test committed_private_memory_beside_a_view_is_not_guarded: a view
and committed private memory side by side; the view is guarded, the
private block stays writable. It fails without the change (the private
block read-only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:25 +00:00
Author
Owner

@⁠tippythetaidum on GitHub · 2026-11-25 22:33 UTC · original

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

**@⁠tippythetaidum** on GitHub · 2026-11-25 22:33 UTC · [original](https://github.com/fxceless/victory-fork/pull/1147#issuecomment-7176508899) 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).
Author
Owner

@⁠Proudnoob4 on GitHub · 2026-11-25 23:17 UTC · original · edited 2026-11-25 23:26 UTC

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.

**@⁠Proudnoob4** on GitHub · 2026-11-25 23:17 UTC · [original](https://github.com/fxceless/victory-fork/pull/1147#issuecomment-7177374642) · edited 2026-11-25 23:26 UTC *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 has changes conflicting with the target branch.
  • crates/victory-gpu/src/watch.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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