Shaders, GPU: VICTORY_LOOP_CUTS=1 counts the lanes translated loops leave at the loop limit #2733
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2733
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2733"
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?
@Exopus-0x65f7ad0 on GitHub · 2026-11-25 19:20 UTC · original
Exopus-0x65f7ad0:pr/loop-cuts-counter→main· +380 −14 · 11 files · 1 commits · openFollow-up to #1819, as promised there and asked for by the triage: a way to count how often translated loops are cut at the loop limit, so the default can be decided on evidence instead of argued.
What it adds
VICTORY_LOOP_CUTS=1(diagnostics builds only, likeVICTORY_SHADER_LOOP_LIMIT; off by default, nothing changes without it):victory-shader): a lane that leaves a loop because ofLOOP_LIMITdoes oneInterlockedAdd(1)on the first dword of a new raw root UAV,u2in the memory space (LOOP_CUTS): on a conditional back edge, guarded by "the branch wanted to go round again and the limit turned it" (built withselect, noxorof compares); on an unconditional back edge, in the block it leaves through (abort_block). Module notes: "Loop cuts".victory-gpu): while the switch is on, every root signature declares that root UAV and every draw and dispatch binds a 256-byte counter of ours (loop_cuts.rs). The frame line gets one more line every 5 s:translated loops left at the limit (VICTORY_LOOP_CUTS): N lanes since the last line, M since the start(with the limit in force). The counter is never reset while shaders may add to it; its 32-bit wraps are followed.emit/host.rs,victory translate --pipelines) declares the counter too.Why every pipeline and not only those with loops: the switch is a run-wide diagnostic, and a root signature may declare more than its shaders use. It costs one root descriptor (2 DWORDs) per pipeline, only while it is on.
How to use it for the #1819 question
Run a scene twice with a diagnostics build and
VICTORY_LOOP_CUTS=1, once atVICTORY_SHADER_LOOP_LIMIT=16384and once at the default 2^20 (or any lower limit you want to rule out). A loop that ends on its own never reaches the counter; any non-zero count at 2^14 that is not also there at 2^20 is a loop the lower limit would change.Tests
emit::tests::the_loop_cuts_switch_is_on_only_for_1: parsing of the switch.synthetic_tests::a_loop_left_at_the_limit_counts_its_lanes_only_when_asked: a GFX10 loop whose scalar counter only ends on wrap-around; off, the DXIL has no atomic; on, exactly one (guarded by the cut on the back edge), and it passesdxil.dllvalidation when present.shader_cache::tests::the_key_covers_translator_encoding_and_settings: the switch changes the key.Ran here on Windows 11, RTX 5060 Ti: the three tests above pass. The rest of
victory-shader --libandvictory-gpu --libbehave as onmain(13f91ca) on this machine: the same twovictory-gputests fail there too (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views), and thevictory-shadertest process ends with the same access violation in a GPU test on both. In-game counts from a run will follow in a comment.Writing the test showed something worth knowing for the #1819 discussion: on a conditional back edge (the usual loop shape) a lane at the limit does not go through the "killed" exit block at all; the limit is ANDed into the branch, so the lane simply leaves by the loop's normal exit and runs the code after the loop with whatever it had. Only unconditional back edges use the exit block that returns (and discards in pixel programs). The counter covers both.
No title data in this PR (no hashes, addresses, captures or logs from the game).
🤖 Generated with Claude Code
@kotekompotek on GitHub · 2026-11-25 20:07 UTC · original
Useful diagnostic: the UAV is only bound when the pipeline actually carries the loop_cuts param and the counter exists, so pipelines built before the knob existed are untouched. Counter read via volatile loads on the shared buffer is right for a root UAV write. Frame-line integration keeps it zero-cost with the knob off.
@fuzeofficlal on GitHub · 2026-11-25 20:10 UTC · original
Reviewed and verified
6b213e18on Windows 11 (RTX 5090 + WARP + Windows SDK10.0.26100.0dxil.dll) againstmain(13f91ca).Code review
diagnosticsis off orVICTORY_LOOP_CUTS!=1, nou2UAV,atomicBinOp, extra root-signature parameter, or D3D12 buffer is emitted/allocated, andshader_cache::keystays identical to existing caches.u2(MEMORY_SPACE) addsUAVS_EVERY_STAGEonly when needed for non-pixel/compute stages; conditional back-edges useselect(orig, stop, false)and updateself.tail[b]/ counter phis properly;loop_cuts::Counterholds a persistent 256-byte shared buffer withDATA_VOLATILEand handles 32-bit wraparound intotal(), while cache keys and root blobs separate enabled/disabled pipelines cleanly. (Minor note: enablingVICTORY_LOOP_CUTS=1adds 2 DWORDs to root signatures if a pipeline is already right at the 64-DWORD limit.)Verification (Windows 11, RTX 5090 + WARP +
dxil.dll)victory-shader:the_loop_cuts_switch_is_on_only_for_1passed;a_loop_left_at_the_limit_counts_its_lanes_only_when_askedpassed (withdxil.dll).victory-gpuWARP (VICTORY_D3D12_WARP=1,--features diagnostics --lib -- --test-threads=1): 198 passed, 0 failed, 1 ignored.victory-gpuRTX 5090 (--features diagnostics):shader_cache::3/3,pipeline::16/16 — both withVICTORY_LOOP_CUTSunset and withVICTORY_LOOP_CUTS=1.cargo clippy --locked(victory-shader+victory-gpu, default & extra features): 0 warnings;cargo xtask policy: 185 files ok.git merge-treeagainst13f91ca,#2668, and#2755.@Exopus-0x65f7ad0 on GitHub · 2026-11-25 21:42 UTC · original
Thanks @fuzeofficlal and @kotekompotek for the review and the RTX 5090 / WARP runs.
In-game counts, as asked on #1819. RTX 5060 Ti 8 GB, Windows 11, Series S. I ported the counter to the tree I run the game on (fxceless/victory-fork main plus PRs); same lowering, with the fork's root-slot binding instead of
u2.VICTORY_LOOP_CUTS=1, the same limit for every stage (VICTORY_SHADER_LOOP_LIMIT=16383, so the fork's per-stage limits are out of the way):So the counter does count, and in these scenes, which render correctly, no translated loop reaches 2^14. That is one machine and one route through the game; other scenes and the ray-tracing builder (off here) are not covered.
🤖 Generated with Claude Code
@Marvisak on GitHub · 2026-11-25 23:21 UTC · original
Automated triage for the maintainers. This branch conflicts with
mainin crates/victory-gpu/src/draw.rs and crates/victory-shader/src/emit/synthetic_tests.rs, so it cannot be merged as is. It will be reviewed once it is rebased.Generated by Claude Code
6b213e1880toc7a0a6a08d@Exopus-0x65f7ad0 on GitHub · 2026-11-26 13:33 UTC · original
Rebased onto
main(63bcca4); the head is nowc7a0a6a.draw.rs: the marks block is now alet … = if … else { None };expression onmain. The loop-cut counter's root UAV binding now comes right after it, unchanged.synthetic_tests.rs: I keptmain'sbuild/build_wave/run_permute_csas they are. The test only adds two small helpers next tolowered,nativeandhost_shader, plusa_loop_left_at_the_limit_counts_its_lanes_only_when_asked.Results on an RTX 5060 Ti:
cargo test -p victory-shader --lib synthetic: the loop-cuts test passes.gathers_at_a_level_match_the_hardwarefails, but it fails the same way onmainitself on this card, so it is unrelated.cargo check -p victory-gpupasses.🤖 Generated with Claude Code
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.