Repository navigation
GPU: the BVH builder runs whole or not at all - #2118
0xkn0wh3r3 wants to merge 1 commit into
Conversation
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
left a comment
There was a problem hiding this comment.
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).
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.
|
In-game run of this PR (head Build: What this PR did:
Against the same tree without it: without this PR, 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 |
|
Automated triage for the maintainers. This holds back every BVH builder dispatch, direct and Generated by Claude Code |
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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 (
That pointer is the fp16 −∞/+∞ empty-child constant With this PR: 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 |
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: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.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 throughcreate_compute, a refused builder pipeline holds back builder dispatches, while other pipelines are unaffected.Runs:
cargo test -p victory-gpu --libon an RTX 5070 Ti: all pass except the two tests that already fail onmainfrom the NVIDIA heap cap (NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #1835).cargo test -p victory: pass.cargo clippyforvictory-gpu(with and without--features diagnostics) andvictory: clean.Not covered
Not run with a game (no game data here).