Shaders: stop ray traversal sooner (512) in programs with the node test #305
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/TaynanGT--Vice-Tay!305
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-305"
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?
@urielbeaupre on GitHub · 2026-11-27 15:08 UTC · original
urielbeaupre:nvidia-trace-loop-limit→main· +447 −14 · 7 files · 6 commits · openSummary
With
-RayTracingon an NVIDIA RTX 4070 Ti (12 GB), most of the ray-tracing cost was lanes that never finish traversal. This stops traversal loops sooner, in the programs that walk structures only.image_bvh*_intersect_raynow stop at 512 iterations (VICTORY_SHADER_TRACE_LOOP_LIMIT; part of the translation). Every other compute loop keeps 4,096; pixel/mesh limits are unchanged.-Machine 4070 -RayTracing, same unattended opening, warm caches, run twice):No difference in lighting seen between the two in the same scenes; the existing patches are there at both limits.
How it was found
VICTORY_GPU_TIMING=1withVICTORY_D3D12_DRED=1(per-command times need full DRED, notlight):CS_ScreenProbes_TraceRays_RayBinning_BVH_Mixed(f22a76fcb967ee59) took 41 ms a frame, single dispatches up to 157 ms;RaytraceVBuffer(6d7fe7745ab9c6d8) 8.8 ms; everything else under 1 ms.VICTORY_SHADER_CENSUS).s_cmp_le_u32 s32, s43,s32from the constant buffer at user data 5, table byte0x1c0, dword0x78) reads 65,535 at run time (VICTORY_PROBE_ROOT, added here): the title counts on sound structures.VICTORY_MEMORY_DUMPwalked offline: PC-built structures (0x8000,0x8004) have thousands of nodes reached twice and children outside them; a few static ones are still packed on the card (byte for byte title memory) though a builder dispatch named them.VICTORY_BVH_TRACE);The root cause of the broken PC-built structures is still open (notes added to
docs/fork-ray-tracing.mdunder Known gaps). This limits the cost of the lanes that walk them.Diagnostics added (diagnostics builds only)
VICTORY_SHADER_COMPUTE_LOOP_LIMIT=<n>: the loop limit for every compute program.VICTORY_PROBE_ROOT=<hash>,<user data>[,<table byte>]: logs a program's constant buffer at its dispatches.VICTORY_BVH_TRACE=1: also counts copies recorded while the size slot still held its old value, and whether the size was too small.VICTORY_MEMORY_DUMP: also writes title memory laid out like the arenas (title-<n>.bin).Tests
cargo test -p victory-shader --lib: 321 passed, 0 failed, 4 ignored (before rebasing ontob67e8d8).cargo test -p victory-gpu --features diagnostics --lib memory: 25 passed.cargo clippy -p victory-shader -p victory-gpu --features victory-gpu/diagnostics: no warnings.🤖 Generated with Claude Code
@TaynanGT on GitHub · 2026-11-27 15:26 UTC · original
@urielbeaupre The 4070 Ti runs show the cost of the long traversal on that route. I updated
81bd48dto keep 4,096 as the default and key the disk cache on both loop limits. This letsVICTORY_SHADER_TRACE_LOOP_LIMIT=512use its own translations in the same-scene comparison. The dorm artefacts are still part of the image check.@urielbeaupre on GitHub · 2026-11-27 15:44 UTC · original
Thanks for
81bd48d. Keeping 4,096 as the default fits what I found next. I've added8137f71on top of it with the cause of the long traversal:VICTORY_MEMORY_CLOSED_NOTES=1(diagnostics) logs them: about 1,000 pages across 10 title buffers (1.5 to 12 MiB) in two minutes of ray tracing.VICTORY_BVH_OPEN_ALL=0restores the old behaviour), at the default 4,096 limit, RTX 4070 Ti, Series S,-RayTracing:CS_ScreenProbes_TraceRays_RayBinning_BVH_Mixed, ms/frame (median,VICTORY_GPU_TIMING)RaytraceVBuffer, ms/frameThere was no crash or device removal in four runs. The stores still go to the copies on the card, not to title memory.
The orange light patches in the dorm look the same with the buffers open or closed, and at 512 or 4,096, so I think they're a separate issue. Still open, also in the notes: non-compacted built structures (
0x8000; my offline walk may misread their layout) and an occasional static structure left packed on the card.Tests:
victory-shaderlib 327 passed;victory-gpu(diagnostics) memory tests 25 passed; clippy clean on both crates.@TaynanGT on GitHub · 2026-11-27 15:54 UTC · original
@urielbeaupre The drop from 41.8 to 6.0 ms at the full 4,096 limit is the result to follow. It ties the slow traversal to builder stores that were being dropped. I’d compare the same route with the buffer change alone and track VRAM and copy-back alongside the timings. The orange patches still have their own repro.
@urielbeaupre on GitHub · 2026-11-27 16:16 UTC · original
Same route (the unattended opening),
-RayTracing, trace limit 4,096. The only difference between the two runs is the buffer change. Medians over the run come from the frame lines; VRAM is the "card's own: in use" line (43 and 46 samples):VICTORY_BVH_OPEN_ALL=0VRAM is up about 130 MB at the median, and copy-back and copies are within noise.
One thing to check before you merge. In a non-RT run with the buffers open, I saw multicoloured garbage on a character's face and neck in the bar cutscene. The same moment rendered cleanly in an earlier run with the buffers closed. It may be intermittent and unrelated, but opening every title buffer also lets non-builder shaders that store by address reach those buffers. I'm running the closed/open pair on that cutscene now. I'm also preparing a narrower version that opens a buffer only when a builder dispatch names an address inside it (root views or 64-bit constants), so other shaders keep the old behaviour. I'll post both.
@urielbeaupre on GitHub · 2026-11-27 16:19 UTC · original
Follow-up on the face artefact: it isn't from this change. The same multicoloured garbage on the bar cutscene character's face and neck showed up in a run with
VICTORY_BVH_OPEN_ALL=0(buffers closed, otherwise identical, ray tracing off). It's intermittent and happens with or without the buffer change, so it has its own repro like the orange patches.I'll still post the narrower variant (open only the title buffers a builder dispatch names) with its own timings, in case you'd rather keep other programs' stores by address closed.
@TaynanGT on GitHub · 2026-11-27 16:20 UTC · original
@urielbeaupre The closed-buffer run confirms the face mosaic has its own repro. At 4,096, the full-buffer change adds about 130 MB of median local VRAM and takes copy-back from 23.9 to 20.9 ms in this pair. The builder-targeted variant is the next one I’d measure on that same route, including builders that pass addresses through constants.
@urielbeaupre on GitHub · 2026-11-27 17:05 UTC · original
e7de67fis the builder-targeted variant, now the default. A title buffer is opened when a builder dispatch names an address inside it: root views, 64-bit addresses in two constants, and 256-byte-unit constants. Other programs keep the old rule.VICTORY_BVH_OPEN_NAMED=0restores closed buffers, andVICTORY_BVH_OPEN_ALL=1keeps the open-everything variant as a test.With
VICTORY_MEMORY_CLOSED_NOTES=1, two minutes of ray tracing dropped no store by address. Before, about 1,000 pages across 10 buffers were dropped. 34 buffers were opened for the builder.A correction to my earlier 41.8 → 6.0 ms. Those two numbers came from different stretches: the 41.8 is the dorm, played by hand; the 6.0 is the unattended opening. Measured side by side with the same method (unattended opening, warm-up run first, 0 pipelines being made, 100 s,
VICTORY_GPU_TIMING=1,VICTORY_D3D12_DRED=1, 4,096):CS_ScreenProbes_TraceRays_RayBinning_BVH_Mixed, ms/frameOPEN_NAMED=0)OPEN_ALL=1)In this window, mostly cutscenes, run-to-run variation is about as large as the differences, so it doesn't show the large effect. The dump result stands (compacted structures: 2,972 → 140 children outside them, 2,884 → 77 wrong parent links). The dorm still needs a side-by-side; I'll run the three variants for long enough to reach it and post the numbers.
Separately, on the CPU side, same method with ray tracing off: PR #284 + PR #294 merged on this branch gave a median of 20.0 fps (slowest quarter 16.2), against 16.5 and 16.9 (12.5 and 13.7) for two baseline runs. I'll post that on those PRs too.
@TaynanGT on GitHub · 2026-11-27 17:08 UTC · original
@urielbeaupre The 41.8 and 6.0 ms came from different scenes, and I treated them as a pair earlier. I’ll use 14.6, 11.2 and 12.3 ms for closed, named and all-open in the matched opening at 4,096. For the dorm, keep the three modes on the same save and camera. The 34 opened buffers and zero dropped stores give us a concrete result to check again alongside local VRAM and copy-back time.
@urielbeaupre on GitHub · 2026-11-27 17:22 UTC · original
These are dorm dumps for the builder-named default (
e7de67f) andVICTORY_BVH_OPEN_NAMED=0, on the same save and camera: the unattended opening, idle in the dorm,VICTORY_MEMORY_DUMPtaken 190 s after input starts,-RayTracing, limit 4,096. The structures the trace walks were checked offline (children walked from the 4 top levels and their instances, parent links checked against the tree):0x8004)With the builder's stores reaching their buffers, roughly twice as many compacted structures exist, which suggests many builds never got that far when closed. Per structure, children outside them drop by 81% and wrong parent links by 94%. Nodes reached twice only drop by 22%, and a third of the structures still have some defect, so a second, smaller cause remains. Static structures left packed on the card are unchanged: 3 in each dump.
The dorm timing for the three modes on this save/camera is queued for the next window, alongside VRAM and copy-back.
@TaynanGT on GitHub · 2026-11-27 17:29 UTC · original
@urielbeaupre The per-structure counts make the dorm comparison clear even though 354 structures were available with the named buffers and 166 with them closed. I’ll record 27.8 to 5.3 for out-of-range children and 28.3 to 1.6 for parent links. About a third still show a defect. Keep the timings and memory measurements tied to this same save and camera.
@urielbeaupre on GitHub · 2026-11-27 18:06 UTC · original
14c6a05fixes the static structures left packed on the card.Memory::placetook a page into an arena at submission but leftheld.takenat 0. The nextbring()of that page treated it as never taken and sent all of title memory's bytes up again. Title memory still holds the packed bytes, because nothing the builder stores comes back, so an unpacked structure reverted to0x8102and stayed that way.The page now gets the write-watch number from before the copy, the same as
bring().VICTORY_PLACE_TAKEN=0restores the old behaviour.Dorm dumps, same save and camera, builder-named default:
VICTORY_PLACE_TAKEN=0(4 dumps)It does not measurably change the share of broken compacted built structures: 11 to 43% from dump to dump either way, so that has another cause. For those, a BVH-trace pairing of compacted structures with their copy sources found that 11 of the 16 broken ones with a source still in the dump were copied from a sound source, so the damage happens at or after the copy. I don't expect a measurable frame-time change from this one and haven't timed it.
@TaynanGT on GitHub · 2026-11-27 18:12 UTC · original
@urielbeaupre All three captures with the stamp enabled had zero static structures left packed. I pulled the page-stamp change into #342 on current main. The isolated test reproduced the overwrite, preserved the GPU update, and still copied a later CPU write. The compacted structures remain a separate copy-path question.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.