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
Contributor

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

@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

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Verdict: merge candidate (kept). Head af8b9ad is unchanged and still merges cleanly into main. The gate in pipeline::builder::runs (crates/victory-gpu/src/pipeline/builder.rs) and the two drop sites in draw.rs are as reviewed before.

On the latest reply: noted. The Windows Ampere run with #2703 is a new data point. Without this PR the device was removed at 133 s and 81 s. With it, both runs lasted 10 minutes with the builder held back. If #2703 lands, this PR should land with it or before it. The host_wave32() condition still belongs to whichever of this PR and #2176 lands second.

CI: passing (check). Recommending a look, not approving.


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
Contributor

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.

@moe-miau

Copy link
Copy Markdown

Data point from an RTX 4070 SUPER: with #2176 (wave64 programs as two 32-lane halves), once its cross-half refusals are lifted, all 53 builder pipelines get made, and the builder then hangs the GPU within 2 minutes (0x887A0006; the hung submission held 14394a32 and 28918b71). With this PR and one more condition, holding the builder back when the host runs 64-lane programs as halves (all_made(&states) && !victory_shader::emit::host_wave32()), a 6-minute run had no removal, and the log showed BVH builder held back ... pipelines=53 made=53 refused=0 as intended. So this PR's gate is what keeps those hosts alive once their pipelines all get made. Details and the stack used are on #2176.

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

Thanks for the runs. @r4tedx, the comparison with the root-signature rule (53 pipelines against about 518 dispatches a frame) is the argument for recognising the builder by where its code lies. @desplmfao, the fp16 ±∞ pointer tracing back to Box16Rehydration is a very clear way to show what a half-run builder does.

@moe-miau, host_wave32() only exists with #2176, so that extra condition belongs in #2176. When it lands, a host that runs 64-lane programs as halves should hold the builder back even with all 53 made, which is what your run shows. If #2176 lands first I'll add it here, or it can go in #2176 itself.

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.
@0xkn0wh3r3
0xkn0wh3r3 force-pushed the gpu/bvh-builder-all-or-none branch from 60632d3 to af8b9ad Compare November 25, 2026 22:12
moe-miau added a commit to moe-miau/VIctory that referenced this pull request Nov 25, 2026
…uilder waits

With wave64 programs run as two 32-lane host waves (Marvisak#2176), 118 of the
title's programs were still refused here: 80 read a wave mask as data,
32 exchange lanes, a few scan across the wave. Each host wave already
stands for one half (its ballot's high dword is 0, `host_lane` keeps
lanes in the half), so those now translate with that meaning: exact
for programs whose waves work within themselves (compaction, reductions,
one atomic per wave), approximate where the console exchanged across
the halves.

The BVH builder's programs do exchange across them, and run that way
they hung the GPU within two minutes on an RTX 4070 SUPER. So on such
hosts the builder stays held back (Marvisak#2118), as it is today where its
programs are refused.

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

Copy link
Copy Markdown
Contributor

Code review and RTX 5090 + WARP verification at head af8b9ada41c4 merged cleanly onto main (63bcca43c6a0):

  • Code review: pipeline/builder.rs records the title acceleration-structure builder DLL range from both initial mapping and LateDlls in apps/victory/src/run.rs, tags compute pipelines created from that range (via bytecode pointer or RtlCaptureStackBackTrace), eagerly schedules compilation via make::begin, and gates both compute dispatch sites in draw.rs (State::dispatch line 1105 and execute_indirect line 1743) via pipeline::held_back until every live builder pipeline in PIPELINES reports Some(true). Graphics/stream pipelines pass &[] and remain unaffected.
  • Minor edge note (non-blocking): DECIDED caches (frame, open) for the rest of the frame. If runs() already cached true earlier in a frame and the title creates a brand-new uncompiled builder pipeline later in the same frame, the new pipeline itself is still held by host_pipeline while existing builder pipelines keep running for the remainder of that frame; gating catches the full set starting on the next frame (minimal practical impact since builder pipelines are typically created ahead of dispatch).
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 192 files ok; cargo clippy --locked -p victory-gpu -p victory --tests -- -D warnings (default + --features diagnostics): 0 warnings
    • victory-gpu (pipeline:: draw::tests): 46/46 passed default on RTX 5090; 49/49 passed (--features diagnostics) on both RTX 5090 and WARP (including all 3 new builder tests)
    • victory crate tests: 18/18 passed (14 unit + 4 integration).

Clean and well-scoped; LGTM.

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

@fuzeofficlal thanks for the review and the 5090 + WARP runs. On the DECIDED note: right, the decision is made once a frame, so a builder pipeline created after the frame's first dispatch only gates the set from the next frame. The new pipeline itself is held anyway, because it has no host pipeline until it's made. So for the rest of that frame, the builder runs without that one stage, which is what this PR prevents. The title creates its builder pipelines at load, long before the first dispatch, so I've left it per-frame rather than re-checking on every dispatch. I can tighten it if the maintainer prefers.

@neonbyte1

Copy link
Copy Markdown

Tested af8b9ada on an RTX 5090 (driver 620.73.04) under Linux: Wine 11.22, vkd3d-proton 3.1-83 (GE-Proton11-14), DXVK dxgi, diagnostics build. The base is main 219878a plus #2723, #1129, #1548, #233, #320, #439 and a one-back-edge-per-block workaround for HansKristian-Work/dxil-spirv#380.

On that base, #439 makes 28918b7150a7aad5 (the builder program at XboxBvhBuilder.dll+0x25c40) translate, while its sibling 14394a322f6dd5c2 stays refused ("console wave64 lanes in a group of more than 64 threads"). So the builder ran half its stages:

Build Runs Result
base, no #2118 2 (cold, warm) title crash at +0x23cf683 (write to 0) during loading, frames 626 and 1211
base, 28918b7150a7aad5 skipped 2 (7 and 12 min) no crash
base + #2118 1 (10 min) no crash, reached gameplay (frame 1744), no Xid

A bisect over the 72 shaders #439 newly translates narrowed the crash to that one program. With #2118, the refused sibling holds the set as intended, and nothing in the log points at the builder afterwards.

AI-assisted (Claude); measured on my machine, no game data shared.

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

@neonbyte1 thanks, that's a clean demonstration. Bisecting #439's 72 newly translated programs down to 28918b7150a7aad5, then showing the crash gone either by skipping it or by holding the builder back while its sibling 14394a322f6dd5c2 is refused, is exactly the case this gate is for: a builder running only some of its stages corrupts memory. It's good to have it on Linux/vkd3d-proton too.

desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
GPU: the BVH builder runs whole or not at all

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
Upstream main merged Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906 and Marvisak#1152 and took up what
Marvisak#1769 (LDS bounds, Marvisak#1949) and Marvisak#1763 (typed UAV formats, Marvisak#2462) did; main's
code is kept for those.
- emit/lower.rs: ds_bpermute within each half (main's Marvisak#573, same as
  Marvisak#439's); LDS bounds as main's Marvisak#1949 (Marvisak#1769's test-only counter kept, its
  and_guard dropped); title-memory marks: main's straddling-write lookup
  (Marvisak#2484) with Marvisak#2167's current head (3cb308d, rebased on 63bcca4): guarded
  dirty atomics, raw_dword2, memory_null, synthetic_mark_dxil in
  lower/mark_tests.rs; the old Marvisak#2167 head taken out first.
- emit/host.rs: main's shared WARP device and lock (Marvisak#244) with Marvisak#439's
  adapter list and Host::on (create_device takes an optional adapter).
- descriptor/host.rs: main's Marvisak#2462 format checks; Marvisak#1763's tests kept.
- gpu host.rs: main's multi-plane present with Marvisak#2310's crumbed copy.
- pipeline.rs: Marvisak#2118/Marvisak#2311's builder and BVH checks with main's skip
  hashes (Marvisak#1320); draw.rs, shadow.rs, main.rs: both sides.
- Tests main added since get Marvisak#439's Parts fields and emit's Target.
- README: base 63bcca4; rows of PRs merged upstream, superseded or closed
  taken out, with a note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
The previous renderer (old upstream base 940d32f) is the first parent and
is also kept as the branch renderer-2026-11-25-oldbase; the second parent
is the rebuild: fork main (upstream main 63bcca4 + our pull requests) with
the renderer stack merged on it: Marvisak#439 (on main: update/439-main's
resolution), Marvisak#2309, Marvisak#2167, Marvisak#2118, Marvisak#2311, Marvisak#1722, Marvisak#1751, Marvisak#688, Marvisak#1872, Marvisak#2292,
Marvisak#2310, Marvisak#2112 (opt-in), Marvisak#2230 (latch on by default), Marvisak#2389, Marvisak#2088 (small
windows opt-in), Marvisak#2099's new head, and tonight's Marvisak#491 journal fixes.
Merged upstream since: Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906, Marvisak#1152; superseded by
main: Marvisak#1769, Marvisak#1763, Marvisak#2366.

The picture on this base still shows the overlay that plain upstream main
shows too; that is being looked into.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davesousa

Copy link
Copy Markdown

Windows NVIDIA in-game result for this PR together with #2703, which lets most of the builder's dispatches through: RTX 3070 Ti 8 GB (Ampere, 32-lane waves), driver 621.40, Windows 11 26200, TDR delay 8 s. 63bcca4 + #2319 + #2178 + #2634 + #2703, diag build, warm caches, scripted walking from 150 s. This PR at af8b9ad merges cleanly on that stack, and its three tests pass here.

+ #2703 + #2703 + this PR
runs 2 2 (one with DRED)
end 0x887A0006 at 133 s and 81 s no removal, both stopped by me at 10 min
longest host submission 14.9 s, 15.5 s 1.3 s, 0.64 s
world frame, median (2 samples, 2.5-4 s) 809 ms, 702 ms

At the first world frame: BVH builder held back: not all its pipelines are made pipelines=53 made=44 refused=9, and it never opened. So on Windows Ampere this PR is what lets #2703 land without a GPU reset. Details, and a comparison with #2841 (which does not stop the reset on its own), are on #2703.

AI-assisted (Claude Code); the runs are on my machine.

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

@davesousa thanks, that's the Windows confirmation. With #2703 letting most of the builder through, the device reset at 133 s and 81 s, with 15 s submissions, without this PR. With it, both runs went 10 minutes with the longest submission at 1.3 s, because the builder was held back with 9 of its 53 pipelines refused. So whichever of #2703 and this PR lands, the other should go with it.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 26, 2026
…hing

Run C1 (cool/play-1 6201516, RTX 5070, VICTORY_BVH_BUILDER=1): the
32-lane guard held the builder back (one "held back: the host has no
64-lane waves pipelines=53", no device removal), but the title crashed in
loading, writing through a null pointer at the address the Marvisak#2118 thread
reported for a half-run builder; without the switch it runs on. Held
back is not off: the switch also stopped make::left_out from leaving out
the programs that walk the builder's structures (CS_RaytracingResolve,
CS_ScreenProbes_ActivateRays), which then ran over structures the
held-back builder never built. That this caused the crash is a reading
of the code, not reproduced; this change makes the narrow host's run the
same as one without the switch, whichever difference it was.

builder_allowed(): the switch on a host with 64-lane waves. builder_runs()
and both of make::left_out's rules ask it, so on a host without them
everything is as without the switch. It warns once, when the switch is
set: "the ray-tracing structure builder held back: the host has no
64-lane waves; VICTORY_BVH_BUILDER=1 is ignored, and the builder and the
programs that walk its structures stay off as without it". The host is
asked only with the switch on.

Test: the_switch_is_ignored_on_hosts_without_64_lane_waves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
crashbashash added a commit to crashbashash/VIctory-proton that referenced this pull request Nov 26, 2026
…IDIA device removals

The table row for upstream Marvisak#2999 (lane quads and the f16 bias of compute samples); the NVIDIA note names Marvisak#2118, with which lhnizdo saw no reset on an RTX 2080.
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.

10 participants