mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:30:53 +01:00
[PR #1101] [CLOSED] rdna2spirv: bound loop visits at the structured exit (SHADER-LOOP-GUARD) #1136
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1136
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1101
Author: @Moriz82
Created: 11/24/2026
Status: ❌ Closed
Base:
main← Head:split/shader-loop-guard📝 Commits (1)
30baacfrdna2spirv: bound loop visits at the structured exit (SHADER-LOOP-GUARD)📊 Changes
2 files changed (+7 additions, -1 deletions)
View changed files
📝
docs/design.md(+1 -1)📝
tests/test_make_game_translator_flags.py(+6 -0)📄 Description
Rebased onto
bfef489cat30baacf9. Main already includes the loop guard. This diff tests the build flag forwarding and documents the native and emulated forced-exit behavior reported below. The three focused suites passed 71 tests.Claimed in the coordination issue as: SHADER-LOOP-GUARD (claim).
Part of the split of #984 into small pull requests.
Depends on: none
Overlaps: #984 is the parent integration. This child merges cleanly beside #1068 and #1073. Either can land first.
What and why
A compute invocation can keep taking a loop back edge when its input makes the exit condition unreachable. On Linux, a synthetic shader that added two on each visit could never reach its odd target. With the guard disabled, both the 32-lane and 64-lane cases exceeded the interpreter's 10,000-step limit in structured and dispatch modes.
The translator now counts visits to each structured loop header per invocation. Entering the loop starts a fresh counter. At the configured limit, a back edge goes to the loop's merge block. A dispatch-loop visit counts one dispatch iteration. Both the translator and the shader build accept
--loop-limit N. The default is 65,536. Set it to zero to restore the unbounded output.This also truncates finite loops that need more visits. With a budget of 16, every lane reached a target of 6 normally. For targets of 1 and 34, every lane reported 32 in structured mode and 30 in dispatch mode. For nested loops with three visits to each header per entry, every lane reported all nine inner iterations. A merge phi with no value on a newly forced exit receives an undefined value on that edge.
The structured-branch test interpreter now reads header phis from the entering edge, as the new counters require. The build digest, fixture build dependencies and runtime workflow path filters include the new translator module.
Tested
Applied only the new tests and their synthetic fixture to pristine main
3aa975421for the regression comparison. The child has one commit on that base.LoopGuardTests.test_finite_and_nonterminatingLoopGuardTests.test_dispatch_loop_also_stopsLoopGuardTests.test_inner_budget_resets_on_each_entryMainWiringTest.test_explicit_loop_limit_reaches_the_shaders_stagepython3 -I scripts/run_semantic_tests.py tests/semantic -p test_loop_iteration_guard.py -j 2python3 -I scripts/run_semantic_tests.py tests/semantic -p test_control_flow_branches.py -j 2python3 -I tests/test_make_game_translator_flags.pypython3 -I tests/test_cmake_translator_deps.pyandpython3 -I tests/test_runtime_paths.pypython3 -I -m compileall -q make_game.py tools testspython3 -I <file>orpython3 -I -m pytest -q <file>tests/test_imhex_patterns.py. The same 6 of its 9 cases failed. Zero new failing files.python3 -I scripts/run_semantic_tests.py tests/semantic -j 2python3 -I scripts/check_no_game_data.pycmake -S runtime -B runtime/build/bootandcmake --build runtime/build/boot --target gta6rt -j6For the synthetic loop,
spirv-valaccepted all 24 combinations of lane width, structured or dispatch lowering, peephole optimization on or off, and limits 0, 16 or 65,536. Nine additional modules with exit phis validated at limits 0, 1 and 4,294,967,295. A loop-free control was byte-identical. On the translator CLI, limit zero reproduced main's 7,116-byte binary and shader index. The default and explicit 65,536 produced the same 7,220-byte binary and index.The following repository fixtures were also built on main and the child:
All 11 synthetic modules translated and validated on each tree. Nine contained loops. Main had zero guard counters across 41 loop headers, and the default child had 41 across the same 41 headers.
GPUs tested: none. Validation used CPU interpreters and SPIRV-Tools on Linux. Native Windows, Wine, NVIDIA GPU, AMD GPU, Intel GPU and game boots were not run.
AI-assisted: yes
Checklist
docs/design.md.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.