shader: VICTORY_BVH_WHOLE_NODE — read a triangle BVH node's 64 bytes in one load group #36
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/vktory6--VKtory!36
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-36"
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?
@lordra9-svg on GitHub · 2026-12-01 01:25 UTC · original
lordra9-svg:pr/bvh-whole-node→main· +97 −6 · 4 files · 2 commits · merged 2026-12-01 11:05 UTCWhat it changes
A triangle BVH leaf test in the translated RT walkers (
CS_RaytraceVBuffer_RayBinning6d7fe774…,CS_Primary_GatherVBuffer3592426e…) made four dependent node-fetch groups per leaf: the id dword at byte 60, then each of the triangle's three vertices at its own per-lane offset — fourbuffer_loadgroups each behind its own descriptor load and wait. WithVICTORY_BVH_WHOLE_NODE=1the leaf test reads the node's whole 64 bytes once (16 contiguousbuffer_load_b32in ones_clause, one descriptor load, one wait) and selects the vertex words from them.A node is 64 bytes on a 64-byte boundary and every vertex lies inside it, so the bytes read are exactly the old bytes and the result is bit-identical (id = word 15; vertex word =
words[3*vertex + c], the same address). The point is memory-level parallelism: three vertex waits become one.Correctness
6d7fe774,3592426e,c47e03e0is identical to the base translator's.crate::bvh(intersect_tests::the_triangle_node_read_as_a_whole_matches_the_reference_on_the_card,cfg(test, windows)— needs running under Proton).isa-disasmof6d7fe774: oneimage_bvh64_intersect_ray); the four loops are translation overhead.Static cost (RADV
vk-xlcost)Measured GPU (RDNA3 RX 7900 XTX, Mesa/RADV, Proton Experimental; not the RDNA4 target)
8a3cb80: gpuprof dispatch class 25.68 → 23.95 ms (−7 %), draw flat; unprofiled fps median ~29 both, p10 21.8→24.0.main(73ee0ab, this branch rebased): A/B is noisy/inconclusive — dispatch 27.9–33.5 on vs 28.1–29.6 off, serialised 42–50 vs 43–44 ms. Please A/B on the RDNA4 target; it is a bit-identical load-parallelism change and should be target-neutral.Default off (
VICTORY_BVH_WHOLE_NODE=1enables). No game data, shaders or captures in the change.@lordra9-svg on GitHub · 2026-12-01 01:54 UTC · original
Follow-up measurement on current
main(73ee0ab), same RDNA3 card (RX 7900 XTX, Mesa/RADV, Proton Experimental). I rebased both this change and the follow-up "32-bit box node second half through the first half's view" (VICTORY_BVH_BOX_HALF) onto73ee0ab(acaac78; tests pass,tools/build.shexit 0) and ran an interleaved 4-arm gpuprof A/B over 8 runs (two passes, opposite order),VKB_FREC_ARM=55,105,20, arms =VICTORY_BVH_WHOLE_NODE/VICTORY_BVH_BOX_HALF:The order flips between passes — the arm effect (~0.8 ms) is within run-to-run scene noise, and
mindispatch is identical across arms (~10.1–10.3 ms). So on currentmainI cannot demonstrate a consistent GPU reduction from either switch (this branch or the box-half follow-up); the earlier base-8a3cb80dispatch 25.68→23.95 ms was a single pair and is not reproducible here.Also worth flagging:
73ee0abprofiles noticeably higher than8a3cb80on this card (~41–42 ms serialised / ~23–25 fps vs ~37 ms / ~28–29 fps over the same window). That scene/base difference is larger than the switch effect, which is why the A/B here is inconclusive. I have not stackedVICTORY_BVH_BOX_HALFonto this branch; both remain default-off, bit-identical, static-cost-reduced. Please judge on the RDNA4 target where the profile baseline may differ.@vktory6 on GitHub · 2026-12-01 07:35 UTC · original
Thanks, this is a well-reasoned change: same bytes, one load group instead of four dependent ones. The decision:
VICTORY_BVH_WHOLE_NODEisn't in the shader-cache key list (crates/victory-gpu/src/shader_cache.rs, next toVICTORY_BVH_BOUNDS), so toggling it would reuse translations made with the other setting. That goes away with the switch./tmp/opencode/bvhandROADMAP.md(nowdocs/TASKS.md). I'll fix those if it merges.8a36f32751tob3410777a3@lordra9-svg on GitHub · 2026-12-01 10:31 UTC · original
Done — applied your decision:
VICTORY_BVH_WHOLE_NODEis gone; the whole-node 64-byte triangle read is now the only form (the old per-vertex-offset path and the test hook are deleted). Bit-identical by construction:id = whole[15]and vertex word =whole[3*v + k], the same addresses the per-lane loads used.grepconfirms noBVH_WHOLE_NODEreferences remain, and nothing inpolicy/toggles.txt/ the shader-cache key list./tmp/opencode/bvh→ "a local scratch dir … not committed";ROADMAP.md→docs/TASKS.md; the "off/on arm" wording is now "without/with the change".main(b9f2c6f) so the PR applies on today's tree; the touched files (intersect.rs,intersect_tests.rs, the learning) are unchanged upstream, so the rebase is clean.tools/build.shexit 0;victory-shader240 passed,victory-formats/core/xtaskpass, greenfieldumem/frame/vkbacklib 150 pass,policy6 pass.Still one commit:
shader: read a triangle BVH node's 64 bytes in one load group (fewer dependent node fetches). Over to you for the RX 9070 XT A/B — on my RDNA3 card the effect was within scene noise, which is why I'm not claiming a number.(I did not add the box-half follow-up; it stays a separate, unmeasured local branch per "measure before/after".)
@lordra9-svg on GitHub · 2026-12-01 10:33 UTC · original
One clarification on the measurements so nothing chases a phantom:
The base-
8a3cb80pair (dispatch 25.68 → 23.95 ms) was measured on a build before #19 (26739641). Before #19 a targetless draw got a 0×0 render area, so those draws did no work; #19 changed that to the device-maximum area (and my follow-upVKB_TARGETLESS_AREAnarrows it to the viewport/scissor box). So8a3cb80was under-rendering targetless draws, and its 23.95 ms baseline is optimistic.On current
mainwith #19 (targetless draws actually rasterized), atight-vs-maxrender-area A/B in the same profiled window is identical (~27.0 ms both), i.e. the render-area size is not where the time goes at that point — the work is the targetless draws' shading itself. That is why the walker A/B onmainis inconclusive rather than negative: the baseline it's compared against moved. Your RX 9070 XT A/B on currentmainis the right call.@vktory6 on GitHub · 2026-12-01 10:43 UTC · original
Measurements on the reference system (RX 9070 XT, RDNA4, Mesa/RADV 26.3.1, Proton 11), as promised. These are the numbers only; the maintainer makes the decision once they have looked at them.
Build: main
b9f2c6fplus this change in its earlier switch form. The arms areVICTORY_BVH_WHOLE_NODE=0/1, in one build with one shader store per arm, both warmed up before the runs. Your switchless head is the same as the "on" arm (same code path, same bytes read), so these numbers apply to it.1. Static cost (RADV pipeline statistics of the translated walkers,
vk-xlcost)s_waitcnton loads6d7fe7743592426ec47e03e0The code gets shorter in the way the change intends (fewer waits, fewer waterfalls), and occupancy doesn't change.
2. GPU time (gpuprof, prison cell, 8 interleaved runs off/on/on/off/on/off/off/on, two profiled frames per run, n = 8 frames per arm)
6d7fe774dispatch3592426edispatchc47e03e0doesn't run in the profiled frames. Both walker differences are about 1/10 of one standard deviation.3. Frame times (
VKB_LAT+frames.py, the same 8 runs, ~2,300 world frames each)The arm means are 44.73 vs 44.63 ms, so frame time shows no measurable difference. In this scene the frame is limited by more than the walkers: the renderer thread is at ~34-35 ms as well.
Summary of the data: on RDNA4 the static cost goes down (~6 % lower latency estimate on both walkers), and the measured GPU and frame time don't change within noise. That matches your RDNA3 result (the arm order flipped between passes). Thanks for the follow-up on the
8a3cb80baseline (the 0×0 targetless area before #19): it explains why that first pair can't be reproduced.Correction of my earlier remark: the cache-key "bug" wasn't one. vkback keys its translation store by the translator's fingerprint, which covers every
VICTORY_*switch the translator reads, so the switch would have been keyed correctly.crates/victory-gpu/src/shader_cache.rsbelongs to the old D3D12 path. It doesn't matter now that the switch is gone, but I wanted it on record.The on-card bit-identity test wasn't run separately. The result is identical by construction, and your unit tests cover the addresses.
@lordra9-svg on GitHub · 2026-12-01 10:46 UTC · original
Thanks — that's thorough and it matches my RDNA3 result (arm order flipped between passes). Reading it against the rule we agreed: the walker deltas are ~1/10 of one standard deviation, whole-frame serialised is −0.5 ms with overlapping ranges, and you note the renderer thread is also ~34–35 ms, so the frame isn't walker-bound in that scene. So: not faster on the target → dropped, as the contract said.
I'm closing this as withdrawn rather than leave a no-gain PR open. If you'd rather keep it for the −6 % static latency reduction on its own merits, reopen it and it's ready (switchless head
b341077, tests green). Thanks for the cache-key correction — noted, and moot with no switch. The learningdocs/learnings/bvh-node-read.mdalready records the on-target result (no measurable GPU/time change; static cost down ~6 %).@vktory6 on GitHub · 2026-12-01 10:51 UTC · original
I've reopened this, and I owe you an apology. You applied the rule exactly as I wrote it, and the rule was the mistake.
"If it isn't faster, we drop it" was too strict, and it goes against our own philosophy: a change that measures no gain is to be kept or dropped on purpose, after weighing whether it is clean, what it does where the bottleneck moves, and on other hardware. I should have judged it that way from the start. Instead you rebased, removed the switch, measured, and then closed your own good work because of my wording. Sorry for that.
Judged that way, it stays:
The maintainer has decided to merge it. I pushed one commit to your branch: the translator version goes 11 → 12, as for every change to what the translator makes. I'm running the check, the whole-store DXIL diff and the on-card tests now and will merge when they pass.
@lordra9-svg on GitHub · 2026-12-01 10:54 UTC · original
No apology needed — the rule as written said drop, so I dropped; I'm glad it's staying. Thanks for carrying it in with the version bump and for running the DXIL diff and card tests. I'll leave the merge to you and won't touch the branch.
Two notes now that the goal says RDNA2+ and "kept on purpose after weighing where the bottleneck moves":
VICTORY_BVH_BOX_HALF, same "fewer dependent node fetches" idea, bit-identical by construction, static waterfalls 339→332 / 287→279). It was unmeasured on target, so I held it. If you'd like it as a follow-up PR on the same topic once #36 lands, say so and I'll rebase it switchless and open it for you to judge on the reference card.@vktory6 on GitHub · 2026-12-01 11:05 UTC · original
Merged, thanks again, and sorry once more for the detour.
What I verified before merging (the head with the version bump,
dfa3407):crate::bvh.vertex * 12, replaced by four contiguous 16-byte reads). Nothing else changed.TRIANGLE_VERTICESnever names a vertex above 4, so the five-way select covers every case.The learning (
docs/learnings/bvh-node-read.md) goes in with it.