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
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!3063
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3063"
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?
@HQasper on GitHub · 2026-11-29 19:52 UTC · original
HQasper:pr/bvh-rehydration-hitches→main· +208 −7 · 7 files · 18 commits · openRelated 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 (
caa78b8ca62bc3d6Box16Rehydration,28918b7150a7aad5Box32Rehydration) 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 inemit/lower/tests.rs, and the cache key invictory-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 translatetoo). 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, inapps/victory/src/play.rsandscripts/play-foxhound.ps1.How it was tested
GPU and profile: RTX 5090 (driver 621.24), Ryzen 9 9950X3D, Series X, 1440p (
VICTORY_NATIVE_SIZE=2560x1440because of #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 as55d06914): 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.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, based4b5d51, 1,627 one-group dispatches):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 main55d06914itself gives 2,165 passed, 4 failed, 78 ignored. Its 4 failures are threebcpack::tests::oracle_parity_*tests andxtask'srepository_passes_policy, which flags upstream's ownvictory-loader/src/heap_sites/frame_users.rs.Checked for overlap
play.rsandplay-foxhound.ps1as its guard expects.Written with Claude Code (Claude Opus 5.5); measured on my PC; reviewed by me.
🤖 Generated with Claude Code
github-bot referenced this pull request2026-11-30 00:28:41 +00:00
@DoubleD17 on GitHub · 2026-11-30 12:03 UTC · original
We ran a test of this PR with ray tracing on (
VICTORY_BVH_BUILDER=1), on a 12 GB card, on current main (41adb551with this PR merged, head0fb92720). 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):
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:
41adb551, against41adb551itself, each with a preload made with these settings;AI Assisted
c71899d9) into the merge of upstream84bd61e212436d5592@HQasper on GitHub · 2026-11-30 16:53 UTC · original
Thanks for the thorough test, and for running the extra rounds after the first two looked too good.
Speed. I agree with your reading. The gain measured here (RTX 5090) is in the loading frames. With ray tracing on, a 12 GB card that is GPU-bound at 4–6 fps and spilling into system memory won't show it, and main's own spread (75–184 ms) is larger than the mean difference you measured (−3.4 ms). So "no difference we can measure on this card" is a fair result and doesn't contradict ours.
The dark ladder. This is the part we can't rule out, so thank you for flagging it. What the cap does: the two rehydration programs (caa78b8ca62bc3d6, 28918b7150a7aad5) go round a node's children as many times as the top byte of its header says. A real node has at most 4 children, and those programs' other loops run at most 24 rounds. The lanes past a structure's last node read that byte from whatever lies after it, which is why they ran up to 255 rounds. Capping at 32 therefore should only cut rounds that read junk. That is a reading of the code, not a proof, and I haven't read the shaders' loop bounds to confirm that nothing needs more than 32. One dark picture in seven runs, and none in 11 other runs, is also not enough to pin it on the cap. The other change in this PR, VICTORY_BVH_COHERENT_GLC=1, is a second possible cause.
If you still have the setup, the check that would settle it is the 120 s scene with VICTORY_SHADER_LOOP_LIMIT_OF unset against the same scene with it set. If you can see it again, tell us whether it comes with the cap, with VICTORY_BVH_COHERENT_GLC, or with neither. Both switches can be turned off separately in the launcher defaults.
@KruIN689 on GitHub · 2026-11-30 20:37 UTC · original
Test of #3063 and #3067 together on a 16 GB card, as a third datapoint beside the RTX 5090 and the 12 GB card above.
Setup. RTX 5080 16 GB (driver 621.40), Ryzen 9 9950X3D, 47 GB, Windows 11. Series X, 1440p, DLSS Quality, software ray tracing (
VICTORY_BVH_BUILDER=1), withVICTORY_BVH_INVERTED_MISS=1,VICTORY_BVH_COHERENT_GLC=1andVICTORY_SHADER_LOOP_LIMIT_OF=caa78b8ca62bc3d6:32,28918b7150a7aad5:32. Both PRs were cherry-picked onto our fork of main829188e9+ fixes. Same save, standing still, alternating runs of 3.5 min.We have carried both PRs in our fork since 2026-11-30 with these defaults, with no problems reported.
(Measured and written with Claude Code, for KruIN689.)
@upipibi on GitHub · 2026-12-01 04:55 UTC · original
On the dark ladder: one possible way in for
VICTORY_BVH_COHERENT_GLC=1.past_wave_cachedoesn't count two ways a GFX10 program asks to see what other groups wrote. Code and synthetic tests only, heada5a8c1ef; I can't look at the title's programs, so this needs a recount on your side.The two ways.
s_waitcnt …; buffer_gl1_inv; buffer_gl0_inv. The loads after it are plain: noglc, nodlc. A refit where the last child to arrive builds the parent is that shape: an atomic, the invalidates, then plain loads of the children's boxes.past_wave_cacheleaves atomics out on purpose and doesn't look at the invalidates, so such a program gets a plain view under the switch. The invalidates are then dropped in lowering ("The host has no console buffer cache to invalidate",lower.rs:13564onmain), so nothing makes the other groups' writes visible on the card.glc.s_load_dword*from title memory goes throughmemory()andmemory_view(lower.rs:4041), so it shares the program's view.Fields::Smemcarriescache.glc/dlc, butpast_wave_cacheonly looks atBufferandFlat.Shown with your test's pattern. I encoded
buffer_atomic_add … glc,buffer_gl1_inv,buffer_gl0_inv,buffer_load_dword, and separatelys_load_dword s4, s[2:3], 0x0 glc.ir::builddecodes them as those instructions, withglc=trueon the atomic and on the scalar load, andpast_wave_cachereturnsfalsefor both programs.A widening that counts them. With it,
emit::lower::testsgives 32 passed, 0 failed, yours included:The test
What it would settle. You counted 3 of the builder's 52 programs with
glc/dlc. If a count with the widened check still gives 3, this isn't the way in, and the loop limit is the one left to look at for the ladder. If it gives more, those programs read other groups' writes through a plain view now. Keeping them coherent would cost part of the gain but keep the picture.Tested with the help of Claude Code (Claude Opus 5.5).
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.