Skip to content

GPU: the BVH builder runs whole or not at all - #2118

Open
0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:gpu/bvh-builder-all-or-none
Open

0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:gpu/bvh-builder-all-or-none

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 25, 2026 •

Copy link
Copy Markdown

The problem

A frame can run only part of the title's ray-tracing structure builder. The stages that run then write wrong results into title memory. In fxceless/victory-fork this wrote garbage bounds and crashed the title.

The title's BVH builder (XboxBvhBuilder.dll) builds and refits its ray-tracing structures in title memory through about fifty compute dispatches a frame. A dispatch without a host pipeline is dropped on its own while the rest of the list runs (State::dispatch). Some builder pipelines lack one:

  • refused on NVIDIA (they ask for 64-lane waves);
  • not translated;
  • still being made.

So the stages that do run work on data the missing stages never produced.

The fix

Builder dispatches run only in frames where every builder pipeline has its host pipeline. Otherwise none run, and the structures keep what they held. The decision is made once per frame (pipeline::builder::runs), so no frame runs part of the builder.

  • Builder pipelines are recognised by origin: their bytecode lies in the builder DLL's image, or the builder's code is among the callers when the pipeline is created. run registers the DLL's range when it maps it (note_title_dll, at start and when the title loads it later).
  • They start compiling as soon as they are created, so the per-frame wait budget does not hold the builder back.
  • Both direct dispatches and indirect dispatches (execute_indirect) of a held-back builder pipeline are dropped.
  • The log says when the builder starts or stops running.

On NVIDIA this keeps the builder off until 64-lane programs run there, instead of running it partly. Pipelines from other code are not affected. The rule comes from fxceless/victory-fork's notes; the code is new.

Testing

Three new tests (no game data):

  • pipeline::builder::tests::the_builder_runs_only_with_every_pipeline_made: the all-or-none decision. One pipeline refused or still being made holds all back.
  • pipeline::builder::tests::builder_pipelines_are_known_by_their_origin: recognising builder pipelines by bytecode and by caller.
  • pipeline::tests::builder_dispatches_wait_for_every_builder_pipeline: end to end through create_compute, a refused builder pipeline holds back builder dispatches, while other pipelines are unaffected.

Runs:

Not covered

Not run with a game (no game data here).

The title's acceleration-structure builder (`XboxBvhBuilder.dll`) builds
and refits the ray-tracing structures in title memory every frame through
some fifty compute dispatches. A dispatch without a host pipeline is
dropped on its own (`State::dispatch`, `execute_indirect`), and some of
the builder's lack one for a long time or for good: refused on hosts of
32-lane waves (they ask for 64-lane waves), not translated, or still being
made. The stages that do run then work on data the missing ones never
wrote, and write the result into title memory. On fxceless/victory-fork,
where this happened, the builder wrote garbage bounds that crashed the
title; that fork's rule is the one taken here.

Its dispatches now run only in frames where every pipeline the builder
has created has its host pipeline; otherwise none run, and the structures
keep what they held. The decision is made once per frame, so a frame
never runs part of the builder. Its pipelines are known by origin: bytecode
in the builder's image, or a return address in it on the stack when the
pipeline is created (`run` passes the DLL's range as it maps it, at start
and when the title loads it). They are started at once, so no frame's
wait budget holds the builder back.

New tests (no game data):
- `pipeline::builder::tests::the_builder_runs_only_with_every_pipeline_made`
- `pipeline::builder::tests::builder_pipelines_are_known_by_their_origin`
- `pipeline::tests::builder_dispatches_wait_for_every_builder_pipeline`:
  a compute pipeline created from bytecode in the registered image is the
  builder's, is started at once, is refused (no shader container), and
  holds back builder dispatches; another pipeline is not held back.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib pipeline:: — 18 passed, 0 failed (including builder_dispatches_wait_for_every_builder_pipeline)
  • cargo clippy -p victory-gpu -p victory --all-targets — 0 warnings
  • cargo xtask policy — ok (184 files ok)

Clean gating ensuring BVH builder dispatches wait for all builder pipelines before running. Looks good.

AI-assisted (Gemini 4 Neon).

RecompLive added a commit to RecompLive/victory-fork that referenced this pull request Nov 25, 2026
Ported from Marvisak/VIctory#2118 (GPL-3.0-or-later), fixes fxceless#880's crash
path: a builder dispatch whose host pipeline is missing was dropped on
its own, so the rest of the builder ran on data the missing stages never
wrote and put garbage bounds into title memory.

- Builder pipelines are known by origin: bytecode in XboxBvhBuilder.dll's
  image, or its code among the callers. `run` notes the DLL's range when
  it maps it (start and late loads).
- They start compiling when created (no frame wait budget), and a frame
  holds all builder dispatches back unless every builder pipeline is made;
  the decision is taken once per frame.
- Three tests, including one through create_compute with a refused
  pipeline.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

BVH builder all-or-nothing — build atomicity fix; relates to #2040's 64-bit BVH pointers and #1794's BVH a16 work.

@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

In-game run of this PR (head 60632d3f) on an RTX 5070 (driver 616.92, Windows 11). This used my local copy of the title (1.0.2.1); only the log lines, counts and timings below are reported.

Build: main 940d32f plus a stack of open PRs, with this one merged in: r4tedx/VIctory@gpu-run/layer1-2118 (2fde53b3). The stack includes #1763, #2136, #2147, #1819 (loop limit 2^14) and #2168. Diagnostics build, VICTORY_D3D12_DRED=1, 10 minutes, about 8 minutes of it in the world.

What this PR did:

  • BVH builder mapped base=0x7ffdfc610000 size=909312
  • At the world's first frame (1503): BVH builder held back: not all its pipelines are made pipelines=53 made=48 refused=5. The builder stayed off for the rest of the run.

Against the same tree without it: without this PR, CS_IrradianceCache_ShadowTrace_WithFar (f607780aa8e502d0, a ray-traced probe shadow trace) removed the device about 70 s after world entry. DRED put the stop at its indirect dispatch, and the System log had nvlddmkm event 153. That run was on main 940d32f + #1763. With this PR: no hang in 10 minutes, no device removal, and no System log events. The trace program itself still runs (it was not skipped).

For comparison: a cruder gate. The fxceless fork / ztrx recognise builder programs by their root signature not fitting the user SGPRs (parameters read from a table at user data 16). I tried a gate built on that rule on the same tree. It also kept the hang away, but it dropped a mean of 518 dispatches a frame (up to 950), against this PR's 53 builder pipelines. So that rule takes more than the builder. Recognising the builder by where its code lies, as here, is the sharper rule. I am not opening that gate as a PR.

Not this PR's doing: the GPU time fell from 4.4-6.2 s a frame to 320-410 ms (frames 0.85-1.07 s, 2,200-4,300 draws a frame). But #1819 is in the same build, and the 4.1 s submissions that made most of the old frame time are gone with it. The scenes also differ. I am not claiming that drop for #2118.

Not checked: an AMD host, where the builder's 64-lane programs are not refused, so the builder could run whole. In this run sky, fog and atmosphere are lit, but surfaces stay dark. I have not looked at whether this PR plays any part in that.

AI-assisted

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This holds back every BVH builder dispatch, direct and execute_indirect, in any frame where one of the builder's pipelines is refused or still being made (pipeline::builder::runs, checked in State::dispatch and the indirect path in crates/victory-gpu/src/draw.rs). Builder pipelines are recognised by bytecode or a caller inside the builder DLL's image. run.rs registers that image through note_title_dll. I checked that the decision is made once per frame (DECIDED), that make::state only reads without waiting, and that RtlCaptureStackBackTrace is already in the crate's windows-sys features (it is also used in object.rs). One independent in-game run on an RTX 5070 reports that the device-removal hang seen without this PR is gone (5 of 53 builder pipelines refused). Trade-off for the maintainer: on 32-lane hosts the builder never runs until 64-lane programs run there. CI has not run on this head.


Generated by Claude Code

desplmfao pushed a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
The world's ray-traced pass (f607780aa8e502d0) walks the acceleration
structures with image_bvh64_intersect_ray, in a loop the title bounds at
65,535 steps per wave. When the builder has not built them, it walks
whatever lies in that memory and outlasts the host's GPU timeout: the
device is lost (DXGI_ERROR_DEVICE_HUNG). On a host of 32-lane waves some
builder programs are refused, the builder is held back for good (Marvisak#2118),
and every run ended that way at world entry (RTX 5090).

A pipeline with an image_bvh*_intersect_ray program now waits, like the
builder's own dispatches, until the builder has run whole once. Titles
without XboxBvhBuilder.dll are not held. held_back says why, and the
dispatch and indirect paths log it once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@desplmfao

Copy link
Copy Markdown

A data point from the title on NVIDIA under Linux, where this fixed real corruption for us. RTX 5080, Proton with vkd3d-proton 3.2.0, our stack with #439, #2167 and #2311.

Without this PR: #2167 makes the rehydration passes (Box32Rehydration, Box16Rehydration, DecompressHeader) fast enough to run, but on our stack five builder pipelines are missing. RadixCount 14394a322f6dd5c2 and RadixAlloc e63d22c4def9ba6a don't translate (wave64 in groups of more than 64 threads), and the same goes for PrefixSum1024 and up. So the builder ran half its stages, and the title broke:

  • the player character lost her head;
  • triangles stretched across the whole screen;
  • after about 140 s the title crashed reading a pointer 0x7c007c00fc00fc00.

That pointer is the fp16 −∞/+∞ empty-child constant Box16Rehydration writes into its nodes, so a box node had been written over a live CPU object.

With this PR: BVH builder held back: not all its pipelines are made … pipelines=53 made=48 refused=5. The head is back, the stretched triangles are gone, and the run had no crash.

How it was found: the title's crash log gave the faulting read. Disassembling the title at that address showed the load, and the loaded value matched the constant in Box16Rehydration's GCN. An agent translating all 52 builder containers from XboxBvhBuilder.dll found the ones that don't translate. Before that, the GPU breadcrumbs from #2310 had shown the rehydration list itself timing out, which #2167 fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants