Loop limits of their own for named shaders (grid march 39f0e9: 12.3 -> 0.4 ms) #108
No reviewers
Labels
No labels
accessibility
already-solved
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
merged
needs-decision
needs-game-run
needs-rebase
not-merged
nvidia
obsolete
question
security
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/avatarmanz--VIctory-7900XTX!108
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-108"
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?
@SousaTrashBin on GitHub · 2026-11-26 03:32 UTC · original
SousaTrashBin:rdna4/shader-loop-limits→main· +144 −3 · 5 files · 1 commits · openLoop limits of their own for named shaders (
VICTORY_SHADER_LOOP_LIMITS)The case
In a timing run on an RX 9070 XT, the title's compute shader
39f0e9aeb156a61c(oneDispatch(3600, 1, 1)a frame, a march through a 3D grid: per step a typed load of a cell and a test of bit 29) took 12.3 ms of the card a frame in a street, with one dispatch at 70 ms. With every loop stopped at 64 (VICTORY_SHADER_LOOP_LIMIT=64) it took 0.4 ms. So its time is iterations past 64.The compute limit is 4,096 per loop entry (
lower.rscount_iteration), and the comment there names the case: a loop whose exit is in data the host does not have yet runs to the limit in every lane. A rough count of ~3,400 dependent steps per ray from the timings puts its rays at that limit: they march past where they leave any grid, and what they compute there is wrong anyway.The change
victory_shader::emit::with_loop_limit(Some(n), || translate(..))runs one translation with every loop stopped afterniterations, on its thread only (count_iterationreadsloop_limit_here()).shader_cache::host_shadertakes the limit for the container's hash (16 hex digits of its BLAKE3, as the runtime names shaders) fromVICTORY_SHADER_LOOP_LIMITS(hash:iterations,...). Unset, it defaults to39f0e9aeb156a61c:512; empty, there are none. Only that shader's cache key changes, so no other shader is translated again.Checked on the title's container: its 11 loop limits go from 4,096 to 512, and nothing else in the translation changes size. Measured in the title: 0.3–0.5 ms a frame instead of 12.3 ms.
This is a shortcut, as the other limits are: what the march reads that keeps it from its exit is not found yet. With it found, the default can go. It may change what that pass draws where rays used to reach the limit; I have not compared the picture.
Also
Two examples in
victory-shaderthat helped here:disasm: prints the GFX10 code of a saved container (VICTORY_SHADER_SAVEwrites them).translate_limit: writes a container's DXIL with the stage limits and with a named limit.Tests
VICTORY_SHADER_LOOP_LIMITSparsing, and naming a shader by its container's BLAKE3.cargo test -p victory-shader --libpasses exceptsize_tests::the_record_count_of_a_structured_buffer_read_by_index, which crashes (access violation) the same way onmain.cargo test -p victory-gpu --libpasses apart fromtimeline::report::tests::real_waits_are_recorded_with_who_ended_them, which also fails onmain.🤖 Generated with Claude Code
@Yoshi-233 on GitHub · 2026-11-26 03:58 UTC · original
I reproduced a scope-restoration bug in
with_loop_limitat66e0034. With an outer limit of 7, I entered a limit of 64, raised a synthetic panic and caught it inside the outer callback. On that same thread,loop_limit_here()then returned 64, where the still-active outer callback expected 7. The existing normal-return and separate-thread tests pass; it's the unwind path that skips the restore.I tried saving the previous value in a small
Dropguard for the duration of the callback. The new regression and the full Linuxvictory-shader --libsuite then passed (204 passed, 2 ignored). A minimal regression inside the module is:One separate hardware data point for the shader you identified: on my earlier RTX 4070 Ti SUPER run, this exact hash (
39f0e9aeb156a61c) passed DXIL validation, but standaloneCreateComputePipelineStatereturned0x8007000Ebefore any dispatch. That was a different fork/build, driver 32.0.16.1742. I haven't measured the 512-limit translation on that GPU. Original test and controls@avatarmanz on GitHub · 2026-11-26 07:33 UTC · original
Left open: conflicts with main's shader_cache.rs (the cache is keyed by translator version now), and the loop limit changes the grid march on every card by default; needs a rebase and an in-game check.
@HAL9000RELOADED on GitHub · 2026-11-26 16:32 UTC · original
RDNA3 data point for the shader this PR caps: in a
VICTORY_GPU_TIMING=1run on maina9400a6+ #165 (RX 7900 XTX (RDNA3), driver 32.0.32015.7029, i7-13700KF, Windows 10 22H2 (19045), 4K output, Series X,VICTORY_RENDER_SCALE=0.5), the timing group that contains39f0e9aeb156a61ctakes about 1.2 ms of card time a frame, against 12.3 ms on the RX 9070 XT in the description.So the grid march looks expensive mainly on RDNA4; on this card the cap would save at most about a millisecond. This is main, not the current head
66e0034of this PR: the PR itself was not run here (it conflicts with main).AI-assisted (Claude Code): tests run on my machine, text drafted with Claude.
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.