Skip to content

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) - #3063

Open
HQasper wants to merge 4 commits into
trustno1-coder:mainfrom
HQasper:pr/bvh-rehydration-hitches
Open

HQasper wants to merge 4 commits into
trustno1-coder:mainfrom
HQasper:pr/bvh-rehydration-hitches

Conversation

@HQasper

@HQasper HQasper commented Nov 29, 2026

Copy link
Copy Markdown

Related to #1370.

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 (#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 #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 and others added 3 commits November 29, 2026 19:38
…re asked

The structure 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: 26-48 such
loads each); the console's compiler sets them where other groups write what
a program reads. With the switch, the other 49 get plain views.

Measured on a recorded loading frame (victory replay, RTX, ray tracing on):
the two BVH rehydration programs, 1,627 one-group dispatches, went from
200 to 151 ms, the frame from 221 to 163 ms, the same picture.
Off unless set; on, the shader cache keys on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VICTORY_SHADER_LOOP_LIMIT_OF=<hash>:<limit>,... (any build): the programs
named by the 16 hex digits a run's log names a shader by (the start of the
BLAKE3 hash of the container) have that loop limit in place of their
stage's. The shader cache keys those programs apart; the others keep their
entries. `victory translate` applies it too.

Root cause of the loading hitches with ray tracing on NVIDIA: the BVH
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; most structures
are smaller, and the lanes past the last node read that byte from whatever
lies after the hierarchy, up to 255 rounds. What those lanes write goes to
unused node slots of the group's page and to LDS above their own; the lanes
before them do not read it. A real node has at most 4 children (the title's
loop indexes a 4-entry array) 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 is a few instructions; translated it is about 3,000 IR instructions
with two memory lookups per access.

Recorded loading frame (victory replay, RTX, ray tracing on), 1,627
one-group dispatches: at 32 the two programs took 32 ms instead of 200;
with VICTORY_BVH_COHERENT_GLC=1 too, 25.5 ms, the frame 51.5 ms instead of
221, the same picture. A limit of 256 changed nothing, 64 left 59 ms;
VICTORY_SHADER_OPT=0, no barriers and the other wave64 switches changed
nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ut by default

VICTORY_BVH_COHERENT_GLC=1 and VICTORY_SHADER_LOOP_LIMIT_OF=
caa78b8ca62bc3d6:32,28918b7150a7aad5:32 by default (launcher and
play-foxhound.ps1).

ABBA on an RTX with ray tracing, DLSS Quality (release 9975300, warmed for
both), 60-120 s after the first frame (the opening cutscene and the way
into the world): frames over 100 ms 47 / 28 -> 10 / 9, over 50 ms 326 / 217
-> 167 / 167, longest 571 / 270 -> 184 / 172 ms, 20.3 / 23.8 -> 24.6 /
24.7 fps. Start-up and steady play alike (30.0 / 31.5 vs 29.7 / 30.8 fps),
0 crashes. Captures of the cutscene and the first 75 s in the world, aligned
on the cutscene's flash: the same pictures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the pr-performance Pull request: makes it faster or use less memory label Nov 29, 2026
@github-actions github-actions Bot 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 (+15 % fps in play with ray tracing) 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
Alxspb added a commit to Alxspb/VIctory-NVIDIA that referenced this pull request Nov 29, 2026
Carried ahead of upstream, each behind its own switch or strictly local:
- trustno1-coder#3379 the commit floor scales to the PC's RAM, so a 16 GB PC still admits
  driver compiles (without it every PSO compile is put off, and the scene
  draws nothing);
- trustno1-coder#3398 a draw's wait ends when the memory guard puts the compile off, so a
  drawing thread does not sit 500 ms at the commit limit;
- trustno1-coder#3065 the ambient depth table is bound by the resolve only, and frame
  generation is asked again once DLSS-G allows more frames;
- trustno1-coder#3067 the ray test misses inverted boxes, as the console's does
  (VICTORY_BVH_MISS; the authors measure +57 % with ray tracing);
- trustno1-coder#3063 the BVH rehydration stops at 32 rounds and the builder's memory is
  coherent only where it asks (VICTORY_BVH_REHYDRATE_MAX,
  VICTORY_BVH_COHERENT_GLC; the authors measure +15 %);
- trustno1-coder#3406 VRAM is checked before the first streamed textures are allocated;
- trustno1-coder#3128 sampled texture eviction is on by default through 10 GB of VRAM;
- trustno1-coder#3413 the relay fence context survives a GPU device loss.

Left for a hand rebase, because they sit in the paths our parallel submit
and DLSS work rewrote: trustno1-coder#1978 (keep the DLSS frame generation inputs through
presentation) and trustno1-coder#3411 (the RTX 5060 Ti bundle).
Alxspb added a commit to Alxspb/VIctory-NVIDIA that referenced this pull request Nov 29, 2026
Carried ahead of upstream, each behind its own switch or strictly local:
- trustno1-coder#3379 the commit floor scales to the PC's RAM, so a 16 GB PC still admits
  driver compiles (without it every PSO compile is put off, and the scene
  draws nothing);
- trustno1-coder#3398 a draw's wait ends when the memory guard puts the compile off, so a
  drawing thread does not sit 500 ms at the commit limit;
- trustno1-coder#3065 the ambient depth table is bound by the resolve only, and frame
  generation is asked again once DLSS-G allows more frames;
- trustno1-coder#3067 the ray test misses inverted boxes, as the console's does
  (VICTORY_BVH_MISS; the authors measure +57 % with ray tracing);
- trustno1-coder#3063 the BVH rehydration stops at 32 rounds and the builder's memory is
  coherent only where it asks (VICTORY_BVH_REHYDRATE_MAX,
  VICTORY_BVH_COHERENT_GLC; the authors measure +15 %);
- trustno1-coder#3406 VRAM is checked before the first streamed textures are allocated;
- trustno1-coder#3128 sampled texture eviction is on by default through 10 GB of VRAM;
- trustno1-coder#3413 the relay fence context survives a GPU device loss.

Left for a hand rebase, because they sit in the paths our parallel submit
and DLSS work rewrote: trustno1-coder#1978 (keep the DLSS frame generation inputs through
presentation) and trustno1-coder#3411 (the RTX 5060 Ti bundle).
moritz-eckhard-nickel added a commit to moritz-eckhard-nickel/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
…oop limit, coherent builder memory), conflicts resolved by keeping both sides

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

Copy link
Copy Markdown
Contributor

We ran a test of this PR with ray tracing on (VICTORY_BVH_BUILDER=1), on a 12 GB card, on current main (41adb55 with this PR merged, head 0fb9272). The log confirmed the switch: "VICTORY_BVH_COHERENT_GLC: the structure builder's memory views are coherent only where it asks".

No difference we can measure on this card. With ray tracing on, the card is the limit here: about 4 to 6 fps, the GPU busy 98 to 100 % of the time, and the host's "on the GPU" time is 75 to 185 ms a frame on main, against 4 to 8 ms with ray tracing off. Our first two runs looked like a big gain, so we ran four more:

Light-view seconds only (the idle camera's lighter views, about 7,500 draws a frame):

on the GPU (ms/frame) main at that point fps main at that point
round 1, run 1 82.6 148.4 5.6 4.3
round 1, run 2 96.7 164.5 4.7 3.8
round 2, run 1 85.2 101.9 5.5 4.8
round 2, run 2 177.3 109.5 3.8 4.8
round 2, run 3 79.7 102.9 5.7 5.1
round 2, run 4 178.4 93.2 3.6 5.5
mean difference −3.4 ms +4.1 %

Four of the six runs had less GPU time than main and two had much more, and main's own seven runs ranged from 75.5 to 184.3 ms on the GPU. Shared memory was 10.4 to 11.3 GB in the last 100 s of every run, with this PR or without it (8.5 to 9.0 GB with ray tracing off), so on a 12 GB card part of the ray-tracing data probably lives in system memory. That may explain the spread, and why the gain you measured on an RTX 5090 does not show here.

Picture, one case to look at: in this PR's warm-up run (its first run after the preload), from about 120 s to the end, a metal ladder and the character next to it went dark, as if in shadow, where every other run shows them lit. A glass door behind them showed a sharp, bright reflection with a black vertical band, where it shows a faint one otherwise. We did not see it again in this PR's six other runs, nor in eight main runs or three runs of #3067 with ray tracing on. So it happened once in seven runs of this PR. We do not know whether it came from this PR or from that run being the first after the preload. Since the rehydration programs now stop at 32 rounds, could a structure that needs more rounds keep stale geometry and cast a wrong shadow?

Setup:

  • Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (driver 621.40, DXGI budget 11,175 MB), 64 GB RAM, Windows 11;
  • Series X, 1440p with DLAA (DLSS at native resolution), frame generation off, ray tracing on;
  • the PR merged locally onto main 41adb55, against 41adb55 itself, each with a preload made with these settings;
  • a warm-up run per build, then two rounds (2 PR runs among 3 main runs, then 4 among 4, ABBA), 150 s each, every run from the same save, restored before each run;
  • medians of the 5 s host lines on the light-view seconds after the first 20 s, each run compared with main's runs of its round interpolated in time;
  • picture check: a burst of 80 frames at the end of each run plus a capture at 120 s, looked at frame by frame.

AI Assisted

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

pr-performance Pull request: makes it faster or use less memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants