Shaders: stop ray traversal sooner (512) in programs with the node test #305
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from TaynanGT/Vice-Tay. Originally posted by urielbeaupre on 2026-11-27T15:08:59Z.
Summary
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
Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T15:26:22Z.
@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.Imported from TaynanGT/Vice-Tay. Originally posted by urielbeaupre on 2026-11-27T15:44:01Z.
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.Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T15:54:04Z.
@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.
Imported from TaynanGT/Vice-Tay. Originally posted by urielbeaupre on 2026-11-27T16:16:34Z.
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.
Imported from TaynanGT/Vice-Tay. Originally posted by urielbeaupre on 2026-11-27T16:19:02Z.
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.
Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T16:20:57Z.
@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.
Imported from TaynanGT/Vice-Tay. Originally posted by urielbeaupre on 2026-11-27T17:05:49Z.
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.
Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T17:08:52Z.
@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.
Imported from TaynanGT/Vice-Tay. Originally posted by urielbeaupre on 2026-11-27T17:22:22Z.
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.
Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T17:29:24Z.
@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.
Imported from TaynanGT/Vice-Tay. Originally posted by urielbeaupre on 2026-11-27T18:06:32Z.
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.
Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T18:12:17Z.
@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.
Imported from TaynanGT/Vice-Tay. Originally posted by Aniseto on 2026-11-28T09:21:59Z.
Ran the victory-shader library suite at
14c6a05on an NVIDIA Blackwell desktop part:Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by
rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build;VICTORY_D3D12_ADAPTER=NVIDIA.All 336 tests pass with 18 ignored and no skips. This is the first datapoint from an RTX 5070 Ti in the thread; the reports there are on RTX 4070 Ti and other cards. The trace-loop limit change is opt-in and I did not run a title with it enabled, so the 12.1 -> 13.9 fps comparison was not reproduced here.
Not tested: a
-RayTracingtitle session, the memory-by-address tests (separate crate), a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T11:23:56Z.
Thanks for the full shader suite result. The 336 passing tests add useful coverage on the 5070 Ti, but don't reproduce the earlier FPS result. I'd keep the traversal cap opt-in pending a matched visual and frame-time comparison.
Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:12:14Z.
mainhas moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the currentmainand open a new PR; I'll review it there.Pull request closed