Skip to content

[pr-performance] Ray tracing: the BVH rehydration programs stop at 32 rounds and the builder's memory is coherent only where it asks (+15 % fps in play with ray tracing) - #1

Open
HQasper wants to merge 536 commits into
mainfrom
pr/bvh-rehydration-hitches
Open

HQasper wants to merge 536 commits into
mainfrom
pr/bvh-rehydration-hitches

Conversation

@HQasper

@HQasper HQasper commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Fixes #

What it changes

With ray tracing on, the title's BVH rehydration programs take a large share of the card's frame on NVIDIA, in play and not only while loading (trustno1-coder#1370 measures these two programs as over half of it). Two causes, each behind a switch, and the launcher turns both on.

The rehydration programs' loops. The rehydration programs (caa78b8ca62bc3d6 Box16Rehydration, 28918b7150a7aad5 Box32Rehydration) go round a node's children as many times as the top byte of its header says. A group is 64 nodes of one structure, and most structures are smaller. The lanes past the last node read that byte from whatever lies after the hierarchy, and go round up to 255 times. What they write lands in unused node slots of the group's page and in LDS above their own; the lanes before them never read it. A real node has at most 4 children, and the programs' other loops go round at most 24 times, so a limit of 32 cuts only those lanes. On the console a round costs a few instructions; translated it is about 3,000 IR instructions with two memory lookups per access.

The builder's coherence. The builder's views of title memory were all globally coherent (87eb9f2: a refit climbs from children to parents), and a coherent view is not kept in the card's first-level cache. Of the builder's 52 programs only 3 load or store with glc or dlc (93be497e, 5552dac6, ffd93c8a). The console's compiler sets those bits where other groups write what a program reads, so the other 49 can have plain views.

What is in it:

  • Shaders: VICTORY_BVH_COHERENT_GLC=1 …: emit/lower.rs, emit/mod.rs, a unit test in emit/lower/tests.rs, and the cache key in victory-gpu/src/shader_cache.rs.
  • Shaders: VICTORY_SHADER_LOOP_LIMIT_OF=<hash>:<limit>,…: named programs get a loop limit of their own (any build, victory translate too). Each such program has its own cache entry (the variant's key plus the limit), and every other program keeps its entry.
  • Launcher: …: both switches on by default, in apps/victory/src/play.rs and scripts/play-foxhound.ps1.

How it was tested

  • GPU and profile: RTX 5090 (driver 621.24), Ryzen 9 9950X3D, Series X, 1440p (VICTORY_NATIVE_SIZE=2560x1440 because of v2026.11.29.01 is unable to start trustno1-coder/VIctory-NVIDIA#2141), DLSS Quality, ray tracing on with the launcher's other ray-tracing defaults (inverted-box miss, walk loops at 512), frame generation off.

  • In game, on 829188e (the same code as 55d0691): eight runs of 6 minutes from the same save, in the order b r i t t i r b (b: the launcher's ray-tracing defaults all on; r, i, t: PR 1, 2 or 3 off), with shaders and pipelines made beforehand for each variant. The world is reached about 45 s after the first frame. "Way in" is its first 60 s, "play" the next 180 s. Each cell is the mean of two runs, with the two runs' values in brackets. 0 GPU removals and 0 crashes in all eight runs.

    Before (both switches off) After (both on)
    fps in play 27.4 (26.4 / 28.4) 31.4 (29.9 / 32.8)
    1 % low in play 9.9 (12.3 / 7.6) fps 14.6 (13.1 / 16.1) fps
    Frames over 50 ms in play 498 (572 / 423) 96 (139 / 53)
    Frames over 100 ms in play 46 (3 / 88) 4 (6 / 1)
    fps on the way in 23.1 (21.1 / 25.2) 23.5 (22.9 / 24.1)
    Frames over 100 ms on the way in 30 (42 / 19) 36 (28 / 45)
    Longest frame on the way in 637 (512 / 761) ms 230 (244 / 216) ms

    On the first base this was measured on (d4b5d51), the gain was in loading: 60-120 s after the first frame, frames over 100 ms went from 47 / 28 to 10 / 9, and play was unchanged. On this base that window shows no difference (16 frames over 100 ms either way), and the gain is in play instead. The card is busy 91-95 % of the time without the switches and 88 % with them. The two switches were not measured apart here.

  • Recorded loading frame (victory replay, base d4b5d51, 1,627 one-group dispatches):

    • the two rehydration programs: 200 ms → 32 ms with the limit → 25.5 ms with both switches
    • the frame: 221 ms → 51.5 ms, the same picture
    • a limit of 256 changed nothing, and 64 left 59 ms
  • Pictures (base d4b5d51): captures of the opening cutscene and the first 75 s in the world, aligned on the cutscene's flash, show the same pictures with and without the switches.

  • Wave sizes: 32-lane host (the rehydration programs are wave64 programs lowered for it).

  • cargo test (cargo test --workspace --locked --no-fail-fast -- --test-threads=4, 2026-11-29): 4 failed, the same 4 as upstream (below). victory-hle's test binary stopped once with an access violation in its media tests, so the run counted 1,744 passed and 73 ignored. Run alone three times, that binary passed in full each time (423 passed, 5 ignored), as it did three times on upstream. Upstream main 55d0691 itself gives 2,165 passed, 4 failed, 78 ignored. Its 4 failures are three bcpack::tests::oracle_parity_* tests and xtask's repository_passes_policy, which flags upstream's own victory-loader/src/heap_sites/frame_users.rs.

Checked for overlap


Written with Claude Code (Claude Opus 5.5); measured on my PC; reviewed by me.

🤖 Generated with Claude Code

@HQasper

HQasper commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner Author

Review notes (fork copy for review; not opened on the upstream repository yet)

  • Base: 55d06914, upstream main of 2026-11-29. The branch merges cleanly there (checked with git merge-tree).
  • The issue and PR numbers in the description (#…) are the upstream repository's. They are written plain on purpose, so this copy does not show up on those threads.

Still to do before it goes upstream:

@HQasper HQasper changed the title [pr-performance] Ray tracing: the BVH rehydration programs stop at 32 rounds and the builder's memory is coherent only where it asks (loading hitches) [pr-performance] Ray tracing: the BVH rehydration programs stop at 32 rounds and the builder's memory is coherent only where it asks (+15 % fps in play with ray tracing) Nov 29, 2026
…T_WRITTEN behind a RwLock — asked of every texture read on every recording thread (3–5× cheaper under contention)
… the gap ranges asked ahead are joined over (default unchanged)
…re wave64 folding and cap eager fold at 255 host regs
…ITY is no longer also the helpers' on/off switch
…hares writing and deleting, not reading alone
…ng when the host list or its epoch changed
…e CPU maps on 16 GB cards too, not only on small hosts (VICTORY_WINDOWS_BAR_MB=4096 when unset)
…ending status entry waits a little for it to be written (VICTORY_DSTORAGE_POLL_WAIT_US)
…oo big for staging lets the next lane start (VICTORY_DSTORAGE_STAGING_NEXT=1)
… the processors make pipelines, at most 24
…RGET lets go of a learned page found the same after 8 waits
…d bitwise, associative mul, and complement ops in DXIL opt
…barriers to source, count, and budget buffers
… and v_cndmask_b32 abs/neg modifiers bitwise
…tion: whole 16-digit hashes only, and with_program restores the thread state (follow-up to trustno1-coder#938)
CowboyBingus and others added 30 commits November 30, 2026 01:07
…mpares, a counter set again; find_trips returns early without loops

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A folded wave64 compute program asks which half holds the first lane
wherever the console reads one (`s_cmp_lg_u32 E.lo, 0`), so it reads its
EXEC pair as a number. Where that pair came through a join that only a
loop header's join reads, the join was not marked as read and its
incoming masks became zero without a word (the shortcut
VICTORY_STRICT_JOINS names). From the second iteration on the read then
said "no lane in the lower half", took the upper half's first lane, and
with no lane there a stale value.

In `ptfx_CS_lightAtlas_Sprite` (2561af9577c47289) the counter of the
loop over the light mask's words is read that way: in every wave of 32
sprites or fewer it never moved, the loop ran to the iteration limit
(4,096) with a light's whole body in each round, 60-80 ms of the card a
dispatch, and its lanes left without their store, so the title asked
for the same sprites again in every frame.

In folded programs the joins of lane masks are now read too, whatever
the switch: a mask has a DXIL form, the ballot of its lanes. Other
joins keep the shortcut.

Of the title's 26,084 programs 18 come out otherwise, all folded: the
particles' light atlas (2), the shadow masks (6), the water's volume
light (4), the scattering gather (2) and the particle updates (4). All
26,084 still translate.

RTX 5090, Series X profile, 2560x1440, DLSS Quality, 32-lane waves, on
a deck at night facing a house: the card's time in the title's lists
40-77 ms a frame before, 22.5 ms after; the frame 78-112 ms before,
65-75 ms after (diagnostics build).
Tests for the folded form's joins of lane masks, written by SergDi in
the pull request's discussion (trustno1-coder#2853): a loop whose header joins EXEC
from a join of EXEC that nothing else reads, and reads it as a number.

- CPU: the lowered module takes no 32-bit zero over the back edge.
  Without the fix it does ([(32, 0)]).
- Host: the first active lane's count reaches its limit for five masks,
  in both folded forms.

No title data. victory-shader's library tests: 465 passed, 9 ignored.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o1-coder#3829)

The texture queue counted what is kept for card copies of title buffers
and for render targets as used; slot eviction did not. With trustno1-coder#3829's
figures (8 GB card) the queue said "no room, new textures wait" at
5,365 MB against 5,272 MB while eviction saw 4,621 MB against 5,251 MB
and never started, so the waiting textures were never given room and
flickered black.

Both now count through queue_use. VICTORY_SLOT_EVICT_KEPT=0 goes back to
the count without the reserves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, chunks with DRED markers (trustno1-coder#3706)

matching 14,763 builds + 2,319 rehydrates (11.3 s CPU preparation); a 4070
Ti SUPER lost the device within 120 s. Thousands of builds in one
submission can pass Windows' 2 s TDR.

- Per frame at most 256 builds+rehydrates / 64 MB of inputs (one always
  goes, whatever its size) and 2,048 refits; the rest waits for the next
  frames in order of first request (a newer request for the same structure
  replaces it in place; builds and refits each never pass an older one).
  CPU decoding (quant24, meshlet) is deferred with it. Requests with
  postbuild info are never deferred; a copy from a waiting structure gives
  its build first; freed memory drops what waits there.
- Instances naming a BLAS that waits get InstanceMask 0 (remap table entry
  with host address 0), never the old structure; counted on the card.
- BLAS work given in chunks (64 builds / 16 MB), each behind a DRED marker
  with its counts; waiting work goes before every TLAS build.
- 5 s line 'hardware RT budget': deferred builds/rehydrates/refits, most
  given/deferred per frame, most waiting, frames with a backlog, chunks,
  instances masked for a BLAS not built yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PVi6XmTj4ohPL7QwUeFgV4
…ked again with the slots alone on nearly every look, taking the watch's locks a second time)
… of 256; size and view-alignment diagnostics (trustno1-coder#3706)

The hardware path copied the host's own compacted and current sizes into
the title's slots. Those are another card's layout, with no promise of
being a multiple of 256, and the title places what follows a compacted
structure after it. They are now the size told at prebuild (host size,
at least 256, a multiple of 256), as the title's own builder path answers
them with VICTORY_BVH_SIZE_ANSWER (on by default). Written with
WriteBufferImmediate; serialization info is still emitted by the host.

Diagnostics builds: 'BVH size answer' once per distinct (builder, kind,
input shape, sizes) under both builders, with the size % 256; 'a buffer
view off 16 bytes' once per distinct (kind, residue, element, inside the
0x28960000 buffer) and counts by first byte % 16 at each power of two.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PVi6XmTj4ohPL7QwUeFgV4
… switches to leave GPU writes the title does not read on the card


# Conflicts:
#	crates/victory-gpu/src/shadow.rs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The index divided by the mip count includes both array and plane slices.
Count the host format's planes when validating the mapped subresource,
so a legal stencil copy reaches the twin. Test both stencil slices of a
depth-stencil array and reject the index past the last plane.

(cherry picked from commit 95f9b2a)
…ard's use as the texture queue does (trustno1-coder#3829)


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ocks taken once a call (VICTORY_MAP_ONCE, opt-in): worst frame while the world streams 170-210 ms where it was 300-555 ms


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o the uploaded descriptor


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… they took whole: a page part asked for again is not read again unless written


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After the texture floor is reached, bound the counted eviction start by
the automatic queue's exact line. The 50% minimum of the rounded policy
can put eviction above that line once face headroom is subtracted.

Keep separate start and stop thresholds and retain the percentage plan
for the legacy switch and explicit texture budgets. Test the equality
boundary, the capped pass, and the lower stop line.

(cherry picked from commit 267a5f6)
…lded

ptfx_CS_lightAtlas_Sprite and _Trail are clustered-lighting loops whose wave
operations (min/max of the lanes' light-grid cells, OR of their light masks,
walking the set bits) are unions: each 32-lane half doing them alone gives
every lane the same lights, so local waves are exact for them (no LDS, no
barrier). Folded they need 2 x 129 VGPRs a host lane, past the 255 an NVIDIA
thread has, and cost 13-135 ms a frame of card time indoors on an RTX 5070.

VICTORY_WAVE_FOLDED_SKIP now defaults to ["lightAtlas"]; set it empty to fold
them again.
…tlas lane-mask joins (24/7 interior stall, trustno1-coder#3835)


# Conflicts:
#	crates/victory-shader/src/emit/folded_tests.rs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ip count the program fixes runs every iteration, past the stage's loop cap (PS_IntegrateEnvBRDF)


# Conflicts:
#	crates/victory-shader/src/emit/lower.rs
#	crates/victory-shader/src/emit/lower/tests.rs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ures are occluded, not lit: no grid of white dots in the shade


# Conflicts:
#	crates/victory-gpu/src/shader_cache.rs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng when write watch is kept


# Conflicts:
#	crates/victory-gpu/src/host.rs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ght atlas programs as local waves, not folded (indoor 4-8 fps -> 26-31 fps on NVIDIA)


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…buffer addresses ignore their two low bits, as the hardware does (misaligned access under Aftermath)


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…no1-coder#3706)

BLASes went only when the title freed their memory: on an RTX 4090 AS
memory went from 370 MB at 3 min to 1,583 MB at 20 min (10.2k live); on a
16 GB RTX 5070 Ti the card's memory passed its budget within 4 min, then a
device loss.

- The instance remap marks each table slot it finds with the TLAS build's
  stamp (g_used, a word per slot), copied to a readback buffer; read when
  the list is reset after its last execution (Feedback, HostList::hold).
- Past the budget (10% of the DXGI local budget, 256 MB..1.5 GB), the
  BLASes no instance named for 120 frames before the horizon (the oldest
  TLAS whose marks are still in flight) go from the lookup table, oldest
  first, down to 90% of it, at most 512 a frame; never one waiting, nor
  one without a request of the title's to build it from.
- Evicted BLASes stay in the remap table with host address 0 (instances
  masked); one named again is built again from the title's last request
  (no update, no postbuild) through the per-frame build budget.
- BLAS bytes are counted by a BlasMemory held by the lookup table and by
  every TLAS/table snapshot (BlasRefs); retired with the buffer, counted
  freed only when the last holder is dropped past its fence.
- Line every 5 s 'hardware RT BLAS memory': budget, live, pinned, evicted,
  named again, rebuilt after eviction, bytes freed past their fence.

No switch (a leak fix); the numbers are constants. CPU tests: never judged
on a TLAS in flight, LRU order, freed only past the last fence, rebuilt
after eviction (and copies).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PVi6XmTj4ohPL7QwUeFgV4
…g: DXR 1.1 structures for XboxBvhBuilder and traversal loops lifted to RayQuery (VICTORY_HW_RT, off)


# Conflicts:
#	crates/victory-gpu/src/descriptor.rs
#	crates/victory-gpu/src/host/menu.rs
#	crates/victory-gpu/src/lib.rs
#	crates/victory-gpu/src/shader_cache.rs
#	crates/victory-shader/src/emit/lower.rs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rge)


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arrange log lines


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e 3965)


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts, lazy compare, trustno1-coder#3838 copy-back classes)


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts in emit/mod.rs (translate: keep note_program and the per-program
loop limit), emit/lower.rs (loop_cap: upstream's own-trip-count floor, then
the per-program override) and shader_cache.rs (both sets of keyed switches).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.