launcher: give each -O0 loop one block that returns to its header #535

Merged
NickStallman merged 1 commit from upstream-pr/535 into main 2026-12-01 14:00:55 +00:00
NickStallman commented 2026-11-29 20:33:58 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T20:33:58Z.


Problem. The DXC helper runs -simplifycfg after -O0 code generation (#479). On a block-dispatcher program it can leave several blocks branching back to one loop header. dxil-spirv assumes one (cfg_structurizer.cpp, visit); with more its dominator walk recurses without end, the pipeline thread overflows its stack and dies, and the provider waits for it forever ("still running"). ProjectScarlett's CS_ScreenProbes_ActivateRays (8ae931bd, request feb4cf08…) hit this in every run of ours I checked that has that DXIL (19), each with one Wine "stack overflow" line. The same program without -simplifycfg finished compiling on an RTX 5090 in 174 and 161 s (two runs on builds without #479).

Change. Run -loop-simplify after it.

Tested

  • New synthetic test in tests/test_dxc_worker.py: four back edges before, one after. Removing the pass fails it.
  • On that program: five before, one after; dxv accepts it; native dxil-spirv (34f0ff8) overflows before and converts in 11 s after; DXIL 3.455 to 3.454 MB.
  • Compiling 090cf6ce's translation through the helper gives a file byte-identical to the game's.
  • python tuxbox.py check --no-gpu: passed.
  • Full python tuxbox.py check of e6adb185 (rebased onto e5d2e913; no change to the patch): RTX 5090 (10de:2b85, 620.70.10) 200 pass, 0 fail; AMD iGPU (1002:13c0, RADV) 199 pass, 0 fail. GE-Proton11-14.
  • Of the 242 largest stored DXIL files examined, only this program has the fault.

On main (2d6dc338) this program takes #489's structured form, which has one back edge per loop, so it should compile there as it is (no GPU run). Other block-dispatcher programs that fall to -O0 can still hit this.

Cost. The helper is part of the cache identity, so recorded shaders are compiled again once.

Game (RTX 5090 10de:2b85, 620.70.10, GE-Proton11-14; an integration build of 007b982d with this and other open PRs): the program's pipeline finished compiling in 146 s with a cold driver cache and 89 s in a second run that started from the first one's, with no stack overflow in either. That build also has the newer structured form, so the runs don't show which of the two fixed it. The second run reached the story and then ended in a crash that is still being looked into (a refused ray scene); neither shows the program being dispatched.

Not run: an output comparison of the two DXIL forms (-loop-simplify is a stock LLVM pass).

Evidence: TuxBox check of e6adb18527, no uncommitted changes, GPU 10de:2b85: 16 passed, 0 failed, 0 not run
Evidence: TuxBox check of e6adb18527, no uncommitted changes, GPU 1002:13c0: 16 passed, 0 failed, 0 not run

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5554835280 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/535). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T20:33:58Z. --- **Problem.** The DXC helper runs `-simplifycfg` after `-O0` code generation (#479). On a block-dispatcher program it can leave several blocks branching back to one loop header. dxil-spirv assumes one (`cfg_structurizer.cpp`, `visit`); with more its dominator walk recurses without end, the pipeline thread overflows its stack and dies, and the provider waits for it forever ("still running"). ProjectScarlett's `CS_ScreenProbes_ActivateRays` (`8ae931bd`, request `feb4cf08…`) hit this in every run of ours I checked that has that DXIL (19), each with one Wine "stack overflow" line. The same program without `-simplifycfg` finished compiling on an RTX 5090 in 174 and 161 s (two runs on builds without #479). **Change.** Run `-loop-simplify` after it. ## Tested - New synthetic test in `tests/test_dxc_worker.py`: four back edges before, one after. Removing the pass fails it. - On that program: five before, one after; dxv accepts it; native dxil-spirv (34f0ff8) overflows before and converts in 11 s after; DXIL 3.455 to 3.454 MB. - Compiling 090cf6ce's translation through the helper gives a file byte-identical to the game's. - `python tuxbox.py check --no-gpu`: passed. - Full `python tuxbox.py check` of e6adb185 (rebased onto e5d2e913; no change to the patch): RTX 5090 (`10de:2b85`, 620.70.10) 200 pass, 0 fail; AMD iGPU (`1002:13c0`, RADV) 199 pass, 0 fail. GE-Proton11-14. - Of the 242 largest stored DXIL files examined, only this program has the fault. On main (2d6dc338) this program takes #489's structured form, which has one back edge per loop, so it should compile there as it is (no GPU run). Other block-dispatcher programs that fall to `-O0` can still hit this. **Cost.** The helper is part of the cache identity, so recorded shaders are compiled again once. **Game** (RTX 5090 `10de:2b85`, 620.70.10, GE-Proton11-14; an integration build of 007b982d with this and other open PRs): the program's pipeline finished compiling in 146 s with a cold driver cache and 89 s in a second run that started from the first one's, with no stack overflow in either. That build also has the newer structured form, so the runs don't show which of the two fixed it. The second run reached the story and then ended in a crash that is still being looked into (a refused ray scene); neither shows the program being dispatched. **Not run:** an output comparison of the two DXIL forms (`-loop-simplify` is a stock LLVM pass). Evidence: TuxBox check of e6adb1852782, no uncommitted changes, GPU 10de:2b85: 16 passed, 0 failed, 0 not run Evidence: TuxBox check of e6adb1852782, no uncommitted changes, GPU 1002:13c0: 16 passed, 0 failed, 0 not run 🤖 Generated with [Claude Code](https://claude.com/claude-code)
brcly commented 2026-11-30 09:17:13 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T09:17:13Z.


Thanks, the analysis is clear and the fix looks right: -loop-simplify is the stock way to restore one back edge per loop, and the synthetic test pins it down.

I'm holding it rather than merging now, for one reason: cost against a benefit we can't measure on main today. The helper is part of the DXC cache identity, so merging this recompiles every player's shaders once. By your own numbers, though, nothing on current main hits the fault: 8ae931bd now takes #489's structured form, and none of the other 241 large DXIL files you checked has it.

Either of these would get it merged:

  1. A program that falls to -O0 on current main and hits the multiple-back-edge recursion (a request hash plus the stack-overflow line is enough).
  2. The next PR that changes tools/dxc_worker.cpp for another reason. We'd fold this in so players recompile once, not twice.

Leaving it open in the meantime.

<!-- greyfinch-sync:brcly/TuxBox:comment:7273993767 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/535#issuecomment-7273993767). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T09:17:13Z. --- Thanks, the analysis is clear and the fix looks right: `-loop-simplify` is the stock way to restore one back edge per loop, and the synthetic test pins it down. I'm holding it rather than merging now, for one reason: cost against a benefit we can't measure on main today. The helper is part of the DXC cache identity, so merging this recompiles every player's shaders once. By your own numbers, though, nothing on current main hits the fault: `8ae931bd` now takes #489's structured form, and none of the other 241 large DXIL files you checked has it. Either of these would get it merged: 1. A program that falls to `-O0` on current main and hits the multiple-back-edge recursion (a request hash plus the stack-overflow line is enough). 2. The next PR that changes `tools/dxc_worker.cpp` for another reason. We'd fold this in so players recompile once, not twice. Leaving it open in the meantime.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!535
No description provided.