Ray tracing: the builder's quarantine holds (split out of #935) #1013

Open
github-bot wants to merge 1 commit from github-bot/gh-1013 into main AGit
Owner

@⁠TheoGegout on GitHub · 2026-11-25 16:12 UTC · original
TheoGegout:bvh-quarantine-holds → main · +27 −5 · 2 files · 1 commits · open

Split out of #935, as suggested there: the quarantine fix alone, on top of main.

The bug

VICTORY_BVH_QUARANTINE=1 is meant to keep the structure builder's stores out of title memory. It leaked. Copy-backs into title memory (Step::GpuWrite) are declared per list, not per dispatch. A builder stage skipped its own declaration, but any other shader in the same list that declared a write carried the builder's stores back with it.

The fix

  • Deferred gets a quarantined flag, reset with the rest of the recording.
  • HostList::quarantine() sets it and drops the GpuWrite steps already declared in the list.
  • defer_gpu_write declares nothing once the list is quarantined.
  • draw.rs calls list.quarantine() when it records a quarantined builder stage.

A list with a quarantined builder stage therefore copies nothing back, before or after that stage.

Effect

On #935's base, with the builder on, the title crashed within seconds; with this fix and VICTORY_BVH_QUARANTINE=1 it ran 74 s with no such crash. The crash itself came from the overrun of dispatches by thread counts, which #994 fixes; this only makes the quarantine do what it says, for testing the builder without its results.

Checked

  • cargo check -p victory with and without --features diagnostics: pass.
  • cargo xtask policy: pass.
  • cargo clippy -p victory-gpu -- -D warnings reports four lints on main (in resource.rs, draw.rs:2524, queue.rs, shadow.rs), none in the lines changed here.

🤖 Generated with Claude Code

**@⁠TheoGegout** on GitHub · 2026-11-25 16:12 UTC · [original](https://github.com/fxceless/victory-fork/pull/1013) `TheoGegout:bvh-quarantine-holds` → `main` · +27 −5 · 2 files · 1 commits · open Split out of #935, as suggested there: the quarantine fix alone, on top of `main`. ## The bug `VICTORY_BVH_QUARANTINE=1` is meant to keep the structure builder's stores out of title memory. It leaked. Copy-backs into title memory (`Step::GpuWrite`) are declared per list, not per dispatch. A builder stage skipped its own declaration, but any other shader in the same list that declared a write carried the builder's stores back with it. ## The fix - `Deferred` gets a `quarantined` flag, reset with the rest of the recording. - `HostList::quarantine()` sets it and drops the `GpuWrite` steps already declared in the list. - `defer_gpu_write` declares nothing once the list is quarantined. - `draw.rs` calls `list.quarantine()` when it records a quarantined builder stage. A list with a quarantined builder stage therefore copies nothing back, before or after that stage. ## Effect On #935's base, with the builder on, the title crashed within seconds; with this fix and `VICTORY_BVH_QUARANTINE=1` it ran 74 s with no such crash. The crash itself came from the overrun of dispatches by thread counts, which #994 fixes; this only makes the quarantine do what it says, for testing the builder without its results. ## Checked - `cargo check -p victory` with and without `--features diagnostics`: pass. - `cargo xtask policy`: pass. - `cargo clippy -p victory-gpu -- -D warnings` reports four lints on `main` (in `resource.rs`, `draw.rs:2524`, `queue.rs`, `shadow.rs`), none in the lines changed here. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
VICTORY_BVH_QUARANTINE=1 leaked: copy-backs into title memory are declared
per list, so another shader's declaration in the same list carried the
structure builder's stores back too. A list that records a quarantined
builder stage now copies nothing back (HostList::quarantine), including what
was declared before it.

Split out of #935 at PiloteCode's request: it is independent of the overrun
of dispatches by thread counts fixed in #994.

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

@⁠drchef420 on GitHub · 2026-11-26 05:06 UTC · original

AI-assisted (Claude Code). Numbers and log lines only, no game data.

An independent sighting of the leak this fixes, and what holding every shared copy back costs.

Setup. RTX 5070 12 GB (driver 610.88) beside an RTX 3060 (the game on the 5070 by Windows' per-app GPU preference), Core Ultra 7 270K Plus, 32 GB, Windows 11 26300, Series X profile. Tree: fork main at a183ea2 (ee3475e here, main merged into a test branch), a new start with no save. Switches: VICTORY_BVH_BUILDER=1 VICTORY_FIRSTLANE_OWN=1 VICTORY_BVH_QUARANTINE=1.

Without the fix. The title crashed in the opening cutscene about 8 s after the builder started: one fault at +0x52eca06, a read reported at 0xffffffffffffffff, rdx = all ones. Four earlier runs from a save crashed the same way within seconds (9 and 13 faults, registers holding pairs of float infinities, 0x7f8000007f800000). The no-switch run from the same start went past that point and 5 minutes more.

With a whole quarantine. Not this PR's form but the same idea, carried further: a host copy that a quarantined builder stage is given to write (a view in its tables, a root view, or any copy numbered for title memory by address) is marked, and from then on none of it is copied back, on any of the four paths (PC copies, relay, card copies, card relay), whichever list or shader declared the write. With that, the title ran past the cutscene and 8 min 37 s more (to frame 3,400) and did not crash there. That agrees with your diagnosis: the builder's stores reached title memory through copy-backs other shaders declared.

What it cost. 2,048 copies marked in the first 83 s (8,590 MB, nearly all 4 MiB windows by address, with COPIES raised to 8191), over 16,384 copy-backs left out. Shared video memory went from 1.5 to 10.5 GB in the 35 s after the builder started and to 15.7 GB; frames went from ~4/s to one per 23-25 s; at 8.5 min shared and upload buffers failed with 0x8007000E and the title crashed on a null write (+0x23cf683). So a quarantine that holds is a way to test, not to play, as you say; #994 is the fix.

We did not run this PR's own form; if useful, we can.

**@⁠drchef420** on GitHub · 2026-11-26 05:06 UTC · [original](https://github.com/fxceless/victory-fork/pull/1013#issuecomment-7183180066) *AI-assisted (Claude Code). Numbers and log lines only, no game data.* **An independent sighting of the leak this fixes, and what holding every shared copy back costs.** **Setup.** RTX 5070 12 GB (driver 610.88) beside an RTX 3060 (the game on the 5070 by Windows' per-app GPU preference), Core Ultra 7 270K Plus, 32 GB, Windows 11 26300, Series X profile. Tree: fork `main` at `a183ea2` (`ee3475e` here, main merged into a test branch), a new start with no save. Switches: `VICTORY_BVH_BUILDER=1 VICTORY_FIRSTLANE_OWN=1 VICTORY_BVH_QUARANTINE=1`. **Without the fix.** The title crashed in the opening cutscene about 8 s after the builder started: one fault at `+0x52eca06`, a read reported at `0xffffffffffffffff`, `rdx` = all ones. Four earlier runs from a save crashed the same way within seconds (9 and 13 faults, registers holding pairs of float infinities, `0x7f8000007f800000`). The no-switch run from the same start went past that point and 5 minutes more. **With a whole quarantine.** Not this PR's form but the same idea, carried further: a host copy that a quarantined builder stage is given to write (a view in its tables, a root view, or any copy numbered for title memory by address) is marked, and from then on none of it is copied back, on any of the four paths (PC copies, relay, card copies, card relay), whichever list or shader declared the write. With that, the title ran **past the cutscene and 8 min 37 s more** (to frame 3,400) and did not crash there. That agrees with your diagnosis: the builder's stores reached title memory through copy-backs other shaders declared. **What it cost.** 2,048 copies marked in the first 83 s (8,590 MB, nearly all 4 MiB windows by address, with `COPIES` raised to 8191), over 16,384 copy-backs left out. Shared video memory went from 1.5 to 10.5 GB in the 35 s after the builder started and to 15.7 GB; frames went from ~4/s to one per 23-25 s; at 8.5 min shared and upload buffers failed with `0x8007000E` and the title crashed on a null write (`+0x23cf683`). So a quarantine that holds is a way to test, not to play, as you say; #994 is the fix. We did not run this PR's own form; if useful, we can.
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/1013/head:github-bot/gh-1013'
git switch 'github-bot/gh-1013'

Merge

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