GPU: the BVH builder runs whole or not at all #2118
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2118
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2118"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@0xkn0wh3r3 on GitHub · 2026-11-25 05:24 UTC · original
0xkn0wh3r3:gpu/bvh-builder-all-or-none→main· +466 −10 · 6 files · 2 commits · openThe 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: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.runregisters the DLL's range when it maps it (note_title_dll, at start and when the title loads it later).execute_indirect) of a held-back builder pipeline are dropped.State::bindfails, e.g. a root view's offset it cannot place; or an indirect dispatch's arguments, count or signature are missing) also holds the builder back: at once for the rest of the frame, then for as long as the title keeps that pipeline. It is not retried on a timer, since the drops seen recur every frame and each retry would be another partial frame. A builder pipeline created after the frame's decision and not yet made holds only the rest of that frame; the next frame's check sees it as missing. Skipped pipelines (VICTORY_SKIP_PIPELINES, diagnostics) were already covered: they count as refused.dropped=counts pipelines held for a dropped dispatch). The first dropped dispatch is logged with its reason.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
Four 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 throughcreate_compute, a refused builder pipeline holds back builder dispatches, while other pipelines are unaffected.pipeline::tests::a_dropped_builder_dispatch_holds_the_builder: a made builder pipeline runs; once a dispatch of it is dropped, the builder is held back in that frame and later ones, and runs again once the pipeline is released. It fails without the change.Runs (rebased on
main63bcca4, NVIDIA):cargo test -p victory-gpu --lib: all pass exceptdescriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views, which already fail onmainfrom the NVIDIA heap cap (#1835), and the flakyframe::tests::waits_end_on_ticks_and_count_frames. Same with--features diagnostics.cargo test -p victory: pass.cargo clippy --workspace --all-targets -- -D warnings, with and without--all-features: clean.cargo xtask policy: ok.Not covered
Not run with a game (no game data here).
@r4tedx on GitHub · 2026-11-25 09:59 UTC · original
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:
main940d32fplus 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=909312BVH 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 onmain940d32f+ #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 on GitHub · 2026-11-25 10:45 UTC · original · edited 2026-11-26 03:19 UTC
Automated triage for the maintainers.
Verdict: merge candidate (kept). Head
af8b9adis unchanged and still merges cleanly intomain. The gate inpipeline::builder::runs(crates/victory-gpu/src/pipeline/builder.rs) and the two drop sites indraw.rsare 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 on GitHub · 2026-11-25 11:45 UTC · original
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.RadixCount14394a322f6dd5c2andRadixAlloce63d22c4def9ba6adon'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:0x7c007c00fc00fc00.That pointer is the fp16 −∞/+∞ empty-child constant
Box16Rehydrationwrites 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 fromXboxBvhBuilder.dllfound 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 on GitHub · 2026-11-25 18:30 UTC · original
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 showedBVH builder held back ... pipelines=53 made=53 refused=0as 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 on GitHub · 2026-11-25 18:37 UTC · original
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
Box16Rehydrationis 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.@fuzeofficlal on GitHub · 2026-11-26 00:41 UTC · original
Code review and RTX 5090 + WARP verification at head
af8b9ada41c4merged cleanly ontomain(63bcca43c6a0):pipeline/builder.rsrecords the title acceleration-structure builder DLL range from both initial mapping andLateDllsinapps/victory/src/run.rs, tags compute pipelines created from that range (via bytecode pointer orRtlCaptureStackBackTrace), eagerly schedules compilation viamake::begin, and gates both compute dispatch sites indraw.rs(State::dispatchline 1105 andexecute_indirectline 1743) viapipeline::held_backuntil every live builder pipeline inPIPELINESreportsSome(true). Graphics/stream pipelines pass&[]and remain unaffected.DECIDEDcaches(frame, open)for the rest of the frame. Ifruns()already cachedtrueearlier 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 byhost_pipelinewhile 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).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 warningsvictory-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)victorycrate tests: 18/18 passed (14 unit + 4 integration).Clean and well-scoped; LGTM.
@0xkn0wh3r3 on GitHub · 2026-11-26 01:05 UTC · original
@fuzeofficlal thanks for the review and the 5090 + WARP runs. On the
DECIDEDnote: 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 on GitHub · 2026-11-26 01:27 UTC · original
Tested
af8b9adaon an RTX 5090 (driver 620.73.04) under Linux: Wine 11.22, vkd3d-proton 3.1-83 (GE-Proton11-14), DXVKdxgi, diagnostics build. The base ismain219878aplus #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 atXboxBvhBuilder.dll+0x25c40) translate, while its sibling14394a322f6dd5c2stays refused ("console wave64 lanes in a group of more than 64 threads"). So the builder ran half its stages:+0x23cf683(write to 0) during loading, frames 626 and 121128918b7150a7aad5skippedA 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 on GitHub · 2026-11-26 01:29 UTC · original
@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 sibling14394a322f6dd5c2is 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.@davesousa on GitHub · 2026-11-26 02:35 UTC · original
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,diagbuild, warm caches, scripted walking from 150 s. This PR ataf8b9admerges cleanly on that stack, and its three tests pass here.0x887A0006at 133 s and 81 sAt 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 on GitHub · 2026-11-26 02:36 UTC · original
@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.
@DenRakEiw on GitHub · 2026-11-25 05:36 UTC · original · approved these changes
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 (includingbuilder_dispatches_wait_for_every_builder_pipeline)cargo clippy -p victory-gpu -p victory --all-targets— 0 warningscargo 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).
@catminou4 on GitHub · 2026-11-25 05:48 UTC · original · reviewed
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.
@fuzeofficlal on GitHub · 2026-11-26 15:37 UTC · original · approved these changes
Reviewed
af8b9ada41c47fc2748e72cf119e09a8185a0cfc(merged cleanly onto63bcca43c6a00a758510398fa43096ce7e4f7df0) and verified on Windows 11 with an NVIDIA GeForce RTX 5090, WARP, and D3D12 Debug Layer.Audit
apps/victory/src/run.rs:122,:390;crates/victory-gpu/src/pipeline/builder.rs:31,:45,:85;crates/victory-gpu/src/pipeline/make.rs:209,:217): both initial and late-loaded title DLL ranges are registered under the existing#[cfg(windows)]loader paths,created_by_builderchecks both bytecode ranges and caller frames (RtlCaptureStackBackTrace) againstXboxBvhBuilder.dll(case-insensitively), andbuilder::notekicks off compilation viamake::beginwithout being throttled by the per-frame wait budget.crates/victory-gpu/src/pipeline/builder.rs:98,:139;crates/victory-gpu/src/pipeline.rs:267,:794;crates/victory-gpu/src/draw.rs:1084,:1722):all_madeprunes droppedWeak<Pending>entries, caches the per-frame decision inDECIDED, and holds back builder dispatches in bothdispatchandexecute_indirectuntil every live builder pipeline is ready while leaving non-builder and graphics pipelines untouched.Verification
63bcca43c6a00a758510398fa43096ce7e4f7df0+cargo run -p xtask -- policy(192 files ok)cargo clippy -p victory-gpu -p victory --all-targets -- -D warnings(default &--all-features)cargo test -p victory: 18/18 passed (14 unit +census+census_unreadable+translate)victory-gpupipeline::+draw::withVICTORY_D3D12_DEBUG=1: 46/46 passed on RTX 5090; 49/49 passed (--features diagnostics) on WARP (including all three new builder tests).@latentdev on GitHub · 2026-11-26 17:09 UTC · original
When every builder pipeline exists: the gate opens, and two things follow (RTX 4090)
This is a case the gate doesn't see yet. The tree is #439 without e2d3cfd's limit plus #180-style quad gradients, so for the first time here all 53 builder pipelines translate and are made. Also in the tree: the title-memory and views' page bitmaps moved to video memory (#2175/#2465's approach), #2118 at
af8b9ad, and #3102.1. Without #2703, the gate opens and the builder runs only partly. The log says
BVH builder runs frame=1017 pipelines=53 made=53 refused=0, but 11 builder programs are still dropped at dispatch with "a root view's offset: no root view, or outside title buffers" (the dword-4 bug, #2699):190fbf0e,35e51bb2,3b90165a,5062bc7a,5e687674,6f6a359d,c42a3195,c85822de,f6e47efa,f94e5d8b,ffd93c8a, all inXboxBvhBuilder.dll. The gate only counts pipelines that are missing, not dispatches dropped for other reasons. The run went 9.5 minutes without a hang, but it is the partial build this PR exists to prevent.2. With #2703, the whole builder runs and hangs. It hung 7 frames into the world:
0x887A0006with nvlddmkm event 153. The list stopped atdispatch 1075x1x1 [compute 5552dac6a2b7a1fd], also a builder program. So once nothing is refused, the next blocker on this card is that program, not the gate.Suggestions:
runs()hold the builder while any builder dispatch is dropped at dispatch time, not only while a pipeline is missing. Root-view checks and skips are two such cases.5552dac6runs, it may be worth treating it as a held builder pipeline on 32-lane hosts.The combination you described stays the safe one on this card: with
e2d3cfd, 7 builder stages are refused, so the gate holds the whole builder.af8b9ada41to999a8f6712@0xkn0wh3r3 on GitHub · 2026-11-26 18:18 UTC · original
@latentdev thanks, that's a real hole: the gate only looked at missing pipelines, so with all 53 made it opened even though 11 builder dispatches were still dropped at bind time.
Fixed in
999a8f67(branch rebased onmain63bcca4). A builder dispatch dropped at dispatch time now holds the builder back. That covers aState::bindfailure (the root-view offset case you hit, no dynamic slots, no view heap, ...) and an indirect dispatch whose arguments, count or signature are missing. The hold starts at once, for the rest of that frame, and stays while the title keeps the dropped pipeline. A title usually keeps its pipelines, so in practice one dropped builder dispatch holds the builder for the rest of the run. It isn't retried on a timer, because these drops recur every frame and each retry would be another partial frame. The first drop is logged with its reason, and theBVH builder held backline now has adropped=count. Skips were already covered: a skipped pipeline counts as refused, so the old gate held it.New test:
pipeline::tests::a_dropped_builder_dispatch_holds_the_builder. A made builder pipeline runs. Once one of its dispatches is dropped, the builder is held in that frame and in later ones, and it runs again once the pipeline is released. The test fails without the change.On the hang with #2703 at
5552dac6on the 4090: I'd keep that out of the gate. It's a device hang in one program that should be looked into on its own (in #2703, or in its own issue). Hard-coding a title shader hash here isn't an option, and a per-program rule would hide the bug rather than fix it. The gate should only encode "all of the builder or none of it".maincan take merges more often #3347@latentdev on GitHub · 2026-11-26 19:31 UTC · original
Checked
999a8f6in the title on the RTX 4090, in the case I reported: all 53 builder pipelines made (#439 without e2d3cfd's limit) and #2703 not applied, so the dword-4 stages are dropped at bind time. The builder is no longer forced off.It stayed held for the rest of an 8-minute run, which ended at the time limit with no hang or device removal. The cutscene frames I captured look as they do with the builder off. Its own test passes here too, with the other three builder tests.
One small thing: the first hold also logs draw.rs's
once!warning, which still reads "a dispatch of the BVH builder held back: not all its pipelines are made". In this case every pipeline was made, so that text may want to name the reason, or point to the builder's own line.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.