Builder quarantine that holds; tracing where the builder's results land #935

Closed
github-bot wants to merge 3 commits from gh-pr/935/head into gh-pr/935/base
Owner

@⁠TheoGegout on GitHub · 2026-11-25 13:11 UTC · original
TheoGegout:rt-builder-quarantine-and-trace → main · +716 −27 · 19 files · 3 commits · closed without merging

Builder quarantine that holds; tracing where the builder's results land

The fix

VICTORY_BVH_QUARANTINE=1 leaked. Copy-backs into title memory are declared
per list, not per dispatch: memory::ready declares every numbered copy
written once per list, and draws through descriptor tables declare theirs. So
another shader's declaration in the same list carried the structure builder's
stores back into title memory too.

A list that records a quarantined builder stage now copies nothing back
(HostList::quarantine), including what was declared before it.

Measured on an AMD Radeon RX 6800 XT (Series X profile, prologue):

  • VICTORY_BVH_BUILDER=1: the title crashes 3 to 12 s after the builder's
    first frame.
  • VICTORY_BVH_BUILDER=1 VICTORY_BVH_QUARANTINE=1 before this change: same
    crash, about 12 s in.
  • With this change: the title ran 74 s with the builder on and no such crash.
    The card was then lost (0x887A0006), with about 1.1 s of GPU time per frame
    once the builder runs.

Diagnostics (behind diagnostics, all off by default)

  • VICTORY_BVH_TRACE=1 (bvhtrace.rs): infinities (0x7f800000,
    0xff800000) written into title memory by shader copy-backs, title buffer
    copies and texture read-backs, counted per 4 MiB block before and after the
    builder's first dispatch; the root arguments of builder dispatches; the
    copies reachable by raw address.
  • Lost raw-address accesses now record the address's low dword, the
    instruction's byte offset and the program's number (program_id, FNV-1a of
    its code) beside the page, in records of FAULT_DWORDS. The record layout
    changes, the buffer size does not (1024 records of 4 dwords).
  • VICTORY_BVH_WARMUP=<frames>: the builder runs quarantined for its first
    frames.

What the runs showed (also in docs/fork-ray-tracing.md)

  • All 52 builder programs translate and get host pipelines, and the builder
    runs.
  • The crash is on several title threads at once, each following a pointer
    field of one of the title's own objects that holds +inf, -inf or a pair
    like 0xff8000007f800000.
  • No path of ours writes those infinities into those objects. Copy-backs carry
    none before the builder runs and many after (36 to 66 blocks of 4 MiB), none
    in the corrupted objects' blocks; buffer copies and read-backs carry none. So
    the title's own code writes them, presumably from builder results it reads
    (bounds, sizes) that are wrong.
  • Not the first frames alone: VICTORY_BVH_WARMUP=10 crashes as soon as the
    results are let through.
  • Not the float atomics: the compare-exchange loop the translator emits for
    global_atomic_fmin/fmax (258 of them in the builder) gives exact results
    with 65,536 threads on one address, in a custom write-back L0 buffer (as the
    4 MiB windows are made) and in a default buffer.
  • In a quarantined frame, the lost raw-address accesses came from three title
    programs that walk the structures (not from the builder), through real title
    addresses whose pages had no copy yet.

Checks

  • cargo build --release -p victory and --profile diag --features diagnostics
  • cargo test --release -p victory-shader: 215 passed
  • cargo xtask policy: ok

🤖 Generated with Claude Code

**@⁠TheoGegout** on GitHub · 2026-11-25 13:11 UTC · [original](https://github.com/fxceless/victory-fork/pull/935) `TheoGegout:rt-builder-quarantine-and-trace` → `main` · +716 −27 · 19 files · 3 commits · closed without merging ## Builder quarantine that holds; tracing where the builder's results land ### The fix `VICTORY_BVH_QUARANTINE=1` leaked. Copy-backs into title memory are declared per list, not per dispatch: `memory::ready` declares every numbered copy written once per list, and draws through descriptor tables declare theirs. So another shader's declaration in the same list carried the structure builder's stores back into title memory too. A list that records a quarantined builder stage now copies nothing back (`HostList::quarantine`), including what was declared before it. Measured on an AMD Radeon RX 6800 XT (Series X profile, prologue): - `VICTORY_BVH_BUILDER=1`: the title crashes 3 to 12 s after the builder's first frame. - `VICTORY_BVH_BUILDER=1 VICTORY_BVH_QUARANTINE=1` before this change: same crash, about 12 s in. - With this change: the title ran 74 s with the builder on and no such crash. The card was then lost (`0x887A0006`), with about 1.1 s of GPU time per frame once the builder runs. ### Diagnostics (behind `diagnostics`, all off by default) - `VICTORY_BVH_TRACE=1` (`bvhtrace.rs`): infinities (`0x7f800000`, `0xff800000`) written into title memory by shader copy-backs, title buffer copies and texture read-backs, counted per 4 MiB block before and after the builder's first dispatch; the root arguments of builder dispatches; the copies reachable by raw address. - Lost raw-address accesses now record the address's low dword, the instruction's byte offset and the program's number (`program_id`, FNV-1a of its code) beside the page, in records of `FAULT_DWORDS`. The record layout changes, the buffer size does not (1024 records of 4 dwords). - `VICTORY_BVH_WARMUP=<frames>`: the builder runs quarantined for its first frames. ### What the runs showed (also in `docs/fork-ray-tracing.md`) - All 52 builder programs translate and get host pipelines, and the builder runs. - The crash is on several title threads at once, each following a pointer field of one of the title's own objects that holds `+inf`, `-inf` or a pair like `0xff8000007f800000`. - No path of ours writes those infinities into those objects. Copy-backs carry none before the builder runs and many after (36 to 66 blocks of 4 MiB), none in the corrupted objects' blocks; buffer copies and read-backs carry none. So the title's own code writes them, presumably from builder results it reads (bounds, sizes) that are wrong. - Not the first frames alone: `VICTORY_BVH_WARMUP=10` crashes as soon as the results are let through. - Not the float atomics: the compare-exchange loop the translator emits for `global_atomic_fmin/fmax` (258 of them in the builder) gives exact results with 65,536 threads on one address, in a custom write-back L0 buffer (as the 4 MiB windows are made) and in a default buffer. - In a quarantined frame, the lost raw-address accesses came from three title programs that walk the structures (not from the builder), through real title addresses whose pages had no copy yet. ### Checks - `cargo build --release -p victory` and `--profile diag --features diagnostics` - `cargo test --release -p victory-shader`: 215 passed - `cargo xtask policy`: ok 🤖 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. With it the title ran 74 s with the builder
on, where it crashed within seconds before.

Diagnostics, all behind the diagnostics feature and off by default:
- VICTORY_BVH_TRACE=1 (bvhtrace.rs): infinities written into title memory
  by shader copy-backs, title buffer copies and texture read-backs, counted
  per 4 MiB block before and after the builder's first dispatch; the root
  arguments of builder dispatches; the copies reachable by raw address.
- Lost raw-address accesses now record the address's low dword, the
  instruction's byte offset and the program's number (program_id, FNV-1a of
  its code) beside the page, in records of FAULT_DWORDS.
- VICTORY_BVH_WARMUP=<frames>: the builder runs quarantined for its first
  frames.

docs/fork-ray-tracing.md: what runs with the builder on showed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the builder on, the title follows pointers into memory holding
128-byte box nodes (child words 0xffffffff, boxes real or +inf/-inf empty)
where it keeps tables of its own inside the structures. The structures are
the dehydrated bottom-level ones the title ships, rehydrated in place
through the builder DLL's rehydrate entry point, which writes nothing
itself and records builder stages. Dropping only those stages removes the
crash with the other stages running and nothing quarantined; one of the
four programs they record loses its reads to pages with no copy yet.

Diagnostics, behind the diagnostics feature and off by default:
- VICTORY_BVH_SKIP_REHYDRATE=1: the rehydrate entry point is marked
  (victory_core::bvh, loader shim) and the builder stages it records are
  dropped (pipeline::rehydrate_skipped), each program logged once.
- VICTORY_CRASH_REGMEM=1: the crash report adds the memory around each
  register holding an address, and around the pointers in its first dwords.
- VICTORY_BVH_WATCH=<start>,<len>: every write of ours into a title range.
- VICTORY_BVH_TRACE: summaries past the line limit, every reachable copy.

docs/fork-ray-tracing.md: the findings, with an earlier wrong reading
corrected (the infinities land at the structures' GPU addresses; the crash
reads them through the other view).

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

@⁠TheoGegout on GitHub · 2026-11-25 14:07 UTC · original

Follow-up: I tried to fix the rehydrate stages' lost reads, and both attempts run into the raw-address copy limit. Notes for whoever picks this up.

What the rehydrate program reads. 5e68767498c57eb6 (the big rehydrate stage, 36 KB of native code) reaches its data through two levels of pointers that nothing names before it runs:

  1. a table of arguments, whose address comes in root constants; at +0x5c it holds the address of an array;
  2. that array is 48-byte records, one per geometry, with the index format at +8 (42 = R32_UINT, 57 = R16_UINT) and the address of the index data at +24;
  3. the index data itself.

Only the first level is made ready, so the other reads give zeros. The lost accesses of a frame include addresses like 0x3ae1a and 0xf0020: offsets from a pointer read as 0.

Attempt 1: name what the rehydrate call's descriptions name. The loader shim read the call's build descriptions and geometry descriptions (D3D12's public layouts) and handed the structures, sources, index and vertex buffers to memory::ready for the stages recorded during the call. Still crashed. With the quarantine fixed in this PR it now crashed too, where it ran 74 s before. The rehydrate program still lost about 500 reads in two frames, through the deeper pointers.

Attempt 2: chase pointers before every builder stage. Read 4 KiB behind each address a stage's arguments name, name every dword pair that looks like a 40-bit title address, and go one level deeper. Every copy number was taken within 1.7 s of the builder starting:

WARN victory_gpu::memory: title memory by address: no number left for another copy; its pages read zeros COPIES=1023

Why this is a wall. Memory by address goes through host copies of 4 MiB windows, 1023 at most (about 4 GB of system memory). The title rehydrates hundreds of batches of up to 16 structures each, spread over several GB of addresses, and many structures land in a window of their own. Making everything the rehydrate stages read ready does not fit in 1023 windows. Raising the limit costs the same again in system memory. I believe the way through is shaders reading title memory in place instead of through copies (VICTORY_INPLACE), extended to the mapped views the structures live in. Those views are turned down today.

Until then, VICTORY_BVH_SKIP_REHYDRATE=1 keeps the title running with the builder's other stages on. The two attempts are not in this PR.

**@⁠TheoGegout** on GitHub · 2026-11-25 14:07 UTC · [original](https://github.com/fxceless/victory-fork/pull/935#issuecomment-7164800275) Follow-up: I tried to fix the rehydrate stages' lost reads, and both attempts run into the raw-address copy limit. Notes for whoever picks this up. **What the rehydrate program reads.** `5e68767498c57eb6` (the big rehydrate stage, 36 KB of native code) reaches its data through two levels of pointers that nothing names before it runs: 1. a table of arguments, whose address comes in root constants; at `+0x5c` it holds the address of an array; 2. that array is 48-byte records, one per geometry, with the index format at `+8` (42 = `R32_UINT`, 57 = `R16_UINT`) and the address of the index data at `+24`; 3. the index data itself. Only the first level is made ready, so the other reads give zeros. The lost accesses of a frame include addresses like `0x3ae1a` and `0xf0020`: offsets from a pointer read as 0. **Attempt 1: name what the rehydrate call's descriptions name.** The loader shim read the call's build descriptions and geometry descriptions (D3D12's public layouts) and handed the structures, sources, index and vertex buffers to `memory::ready` for the stages recorded during the call. Still crashed. With the quarantine fixed in this PR it now crashed too, where it ran 74 s before. The rehydrate program still lost about 500 reads in two frames, through the deeper pointers. **Attempt 2: chase pointers before every builder stage.** Read 4 KiB behind each address a stage's arguments name, name every dword pair that looks like a 40-bit title address, and go one level deeper. Every copy number was taken within 1.7 s of the builder starting: ``` WARN victory_gpu::memory: title memory by address: no number left for another copy; its pages read zeros COPIES=1023 ``` **Why this is a wall.** Memory by address goes through host copies of 4 MiB windows, 1023 at most (about 4 GB of system memory). The title rehydrates hundreds of batches of up to 16 structures each, spread over several GB of addresses, and many structures land in a window of their own. Making everything the rehydrate stages read ready does not fit in 1023 windows. Raising the limit costs the same again in system memory. I believe the way through is shaders reading title memory in place instead of through copies (`VICTORY_INPLACE`), extended to the mapped views the structures live in. Those views are turned down today. Until then, `VICTORY_BVH_SKIP_REHYDRATE=1` keeps the title running with the builder's other stages on. The two attempts are not in this PR.
Author
Owner

@⁠TheoGegout on GitHub · 2026-11-25 16:12 UTC · original

Closing in favour of two PRs, as discussed on #994:

  • #994 fixes the cause of the crash this PR chased: dispatches by thread counts were run as group counts, and the box stages wrote empty nodes over the title's objects. I ran #994's head in the title on a Radeon RX 6800 XT, more than 5 minutes with the builder on and no crash (report on #994). Its bvhtrace.rs and crash-memory dump replace the ones here.
  • #1013 carries the one piece of this PR that stands on its own: the builder's quarantine no longer leaks through other shaders' copy-backs in the same list.

VICTORY_BVH_SKIP_REHYDRATE and the rehydrate diagnosis in docs/fork-ray-tracing.md described the overrun's effects, so they are not carried over.

**@⁠TheoGegout** on GitHub · 2026-11-25 16:12 UTC · [original](https://github.com/fxceless/victory-fork/pull/935#issuecomment-7167688045) Closing in favour of two PRs, as discussed on #994: - **#994** fixes the cause of the crash this PR chased: dispatches by thread counts were run as group counts, and the box stages wrote empty nodes over the title's objects. I ran #994's head in the title on a Radeon RX 6800 XT, more than 5 minutes with the builder on and no crash (report on #994). Its `bvhtrace.rs` and crash-memory dump replace the ones here. - **#1013** carries the one piece of this PR that stands on its own: the builder's quarantine no longer leaks through other shaders' copy-backs in the same list. `VICTORY_BVH_SKIP_REHYDRATE` and the rehydrate diagnosis in `docs/fork-ray-tracing.md` described the overrun's effects, so they are not carried over.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.