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

Closed
TheoGegout wants to merge 3 commits from upstream-pr/935 into main
TheoGegout commented 2026-11-25 13:11:40 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by TheoGegout on 2026-11-25T13:11:40Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6605264764 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/935). Originally posted by [TheoGegout](https://github.com/TheoGegout) on 2026-11-25T13:11:40Z. --- ## 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)
TheoGegout commented 2026-11-25 14:10:54 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by TheoGegout on 2026-11-25T14:07:44Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7164800275 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/935#issuecomment-7164800275). Originally posted by [TheoGegout](https://github.com/TheoGegout) on 2026-11-25T14:07:44Z. --- 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 commented 2026-11-25 16:12:55 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by TheoGegout on 2026-11-25T16:12:34Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7167688045 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/935#issuecomment-7167688045). Originally posted by [TheoGegout](https://github.com/TheoGegout) on 2026-11-25T16:12:34Z. --- 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.
upstream-sync closed this pull request 2026-11-25 17:07:46 +00:00

Pull request closed

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!934
No description provided.