[PR #808] [MERGED] cfg_structure / rdna2spirv: unwrap tautological %pc guards in structured CFGs (ms_wave_info_s3 AMD crash, SHADER-STRUCTURED-PC-UNWRAP) #846

Closed
opened 2026-11-26 20:19:14 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/808
Author: @whoalin1
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: shader-structured-pc-unwrap


📝 Commits (4)

  • 0681b9d cfg_structure / rdna2spirv: unwrap tautological %pc guards in structured CFGs (ms_wave_info_s3 AMD LLPC crash)
  • 53ef382 cfg_structure: document why loop entry keeps cur_pc | {h} in unwrap_known_pc_guards
  • 8e5cf5a fix(rdna2spirv): include END in out_pcs for trailing conditional branches
  • 33431d6 fix(wave64_emulate_opt): refuse exec-fold regions containing a trailing conditional branch

📊 Changes

7 files changed (+337 additions, -79 deletions)

View changed files

📝 docs/design.md (+1 -1)
➕ tests/semantic/test_structured_pc_unwrap.py (+186 -0)
📝 tests/test_cfg_structure.py (+39 -0)
📝 tests/test_translate.py (+5 -0)
📝 tools/cfg_structure.py (+66 -2)
📝 tools/rdna2spirv.py (+26 -4)
📝 tools/wave64_emulate_opt.py (+14 -72)

📄 Description

Claim: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133575269 (SHADER-STRUCTURED-PC-UNWRAP)

Problem

On AMD's proprietary Windows Vulkan driver (24.10.24, LLPC, AMD Ryzen 5 7600 RDNA2 iGPU, native wave64), ms_wave_info_s3 segfaults (0xC0000005) during vkCreateGraphicsPipelines.

In ms_wave_info_s3.asm, blk0 conditionally skips blk1 (MSG_GS_ALLOC_REQ), and both blk0 and blk1 converge at blk2 (s_barrier). cfg_structure.structure() wraps blk2 in ("guard", 2, [("block", 2)]), emitting OpBranchConditional around %blk2's OpControlBarrier even though %pc == 2 is tautologically true on every incoming path.

  • Under --wave64-emulate (e.g., 32-wide NVIDIA GPUs), wave64_emulate_opt._unwrap_known_pc_guards already unwrapped that guard, so ms_wave_info_s3 passed there.
  • On native wave64 (AMD RDNA2), rdna2spirv.capped_tree() used cfg_structure.structure() directly without unwrapping tautological %pc guards, leaving OpControlBarrier inside conditional control flow and crashing AMD Windows LLPC (0xC0000005).

Fix

  • tools/cfg_structure.py: add unwrap_known_pc_guards(tree, out_pcs, entry_pc=0) (moved from tools/wave64_emulate_opt.py, keeping cfg_structure.structure() unchanged for callers like _drop_sink_block).
  • tools/wave64_emulate_opt.py: delegate _unwrap_known_pc_guards directly to cfg_structure.unwrap_known_pc_guards.
  • tools/rdna2spirv.py (capped_tree): apply cfg_structure.unwrap_known_pc_guards to structured trees before computing nesting depth, so both assemble() and needs_barrier_rounds() see post-dominating merge/barrier blocks at top level.
  • tests/test_cfg_structure.py: add test_unwrap_known_pc_guards (single-arm if-then, diamond, loop exit, early-exit guard preservation) and differentially check unwrap_known_pc_guards across all 18,228 random reducible graphs × 6 seeds.
  • tests/test_translate.py: assert %blk2 in ms_wave_info_s3 is emitted without a conditional %pc guard before its OpControlBarrier.
  • docs/design.md: document the pass in the Control flow contract row.

Verification (before/after on main 47c651174, LEONIDA_VK_VALIDATION=1)

  • AMD Radeon(TM) Graphics (Ryzen 5 7600 RDNA2 iGPU, Windows 11, driver 24.10.24, 128B push constants, LEONIDA_PC_TAIL_UBO=1):
    • Before (main): ms_wave_info_s3 FAIL (vk_harness crash 0xC0000005)
    • After: ms_wave_info_s3 PASS (4096/4096 pixels exact, 0 validation errors); cs_barrier_divergent, cs_barrier_early_end, cs_barrier_loop 3/3 PASS
  • NVIDIA GeForce RTX 4070 SUPER (Windows 11, driver 610.88):
    • ms_wave_info_s3 PASS (4096/4096 pixels exact, 0 validation errors); cs_barrier_* 3/3 PASS
  • CPU / unit tests:
    • python -I tests/test_cfg_structure.py — 18,228 random reducible graphs × 6 seeds (both structured and unwrapped trees match walk()), plus shape & deep-chain tests
    • python -I tests/test_runner_calls_all_tests.py — 3/3 OK
    • python -I tests/test_cfg_run_limit.py — 4/4 OK
    • pytest tests/test_translate.py — 669 passed
    • unittest discover -s tests/semantic -p test_wave64_emulate_opt.py — 31/31 OK
    • unittest discover -s tests/semantic -p "test_*barrier*.py" — 53/53 OK
    • unittest discover -s tests/semantic -p "test_exec*.py" — 2/2 OK
    • unittest discover -s tests/semantic -p "test_ms_*.py" — 6/6 OK
    • python -I tests/test_text_write_line_endings.py — 3/3 OK
    • python -I scripts/check_no_game_data.py ... — clean (rc=0)

AI-assisted (Gemini 4 Neon).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/808 **Author:** [@whoalin1](https://github.com/whoalin1) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `shader-structured-pc-unwrap` --- ### 📝 Commits (4) - [`0681b9d`](https://github.com/ubiquitarianism/leonida/commit/0681b9d280ee1adac2d123fb47265da4d9e35444) cfg_structure / rdna2spirv: unwrap tautological %pc guards in structured CFGs (ms_wave_info_s3 AMD LLPC crash) - [`53ef382`](https://github.com/ubiquitarianism/leonida/commit/53ef382d7097290ecb1387f2400eaa7d134585b6) cfg_structure: document why loop entry keeps cur_pc | {h} in unwrap_known_pc_guards - [`8e5cf5a`](https://github.com/ubiquitarianism/leonida/commit/8e5cf5aef1942811bc6e377077b8dc8f388ff8fc) fix(rdna2spirv): include END in out_pcs for trailing conditional branches - [`33431d6`](https://github.com/ubiquitarianism/leonida/commit/33431d6fe5482fdc87edb212f325f37386b4937a) fix(wave64_emulate_opt): refuse exec-fold regions containing a trailing conditional branch ### 📊 Changes **7 files changed** (+337 additions, -79 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) ➕ `tests/semantic/test_structured_pc_unwrap.py` (+186 -0) 📝 `tests/test_cfg_structure.py` (+39 -0) 📝 `tests/test_translate.py` (+5 -0) 📝 `tools/cfg_structure.py` (+66 -2) 📝 `tools/rdna2spirv.py` (+26 -4) 📝 `tools/wave64_emulate_opt.py` (+14 -72) </details> ### 📄 Description Claim: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133575269 (`SHADER-STRUCTURED-PC-UNWRAP`) ### Problem On AMD's proprietary Windows Vulkan driver (`24.10.24`, LLPC, AMD Ryzen 5 7600 RDNA2 iGPU, native wave64), `ms_wave_info_s3` segfaults (`0xC0000005`) during `vkCreateGraphicsPipelines`. In `ms_wave_info_s3.asm`, `blk0` conditionally skips `blk1` (`MSG_GS_ALLOC_REQ`), and both `blk0` and `blk1` converge at `blk2` (`s_barrier`). `cfg_structure.structure()` wraps `blk2` in `("guard", 2, [("block", 2)])`, emitting `OpBranchConditional` around `%blk2`'s `OpControlBarrier` even though `%pc == 2` is tautologically true on every incoming path. - Under `--wave64-emulate` (e.g., 32-wide NVIDIA GPUs), `wave64_emulate_opt._unwrap_known_pc_guards` already unwrapped that guard, so `ms_wave_info_s3` passed there. - On native wave64 (AMD RDNA2), `rdna2spirv.capped_tree()` used `cfg_structure.structure()` directly without unwrapping tautological `%pc` guards, leaving `OpControlBarrier` inside conditional control flow and crashing AMD Windows LLPC (`0xC0000005`). ### Fix - `tools/cfg_structure.py`: add `unwrap_known_pc_guards(tree, out_pcs, entry_pc=0)` (moved from `tools/wave64_emulate_opt.py`, keeping `cfg_structure.structure()` unchanged for callers like `_drop_sink_block`). - `tools/wave64_emulate_opt.py`: delegate `_unwrap_known_pc_guards` directly to `cfg_structure.unwrap_known_pc_guards`. - `tools/rdna2spirv.py` (`capped_tree`): apply `cfg_structure.unwrap_known_pc_guards` to structured trees before computing nesting depth, so both `assemble()` and `needs_barrier_rounds()` see post-dominating merge/barrier blocks at top level. - `tests/test_cfg_structure.py`: add `test_unwrap_known_pc_guards` (single-arm if-then, diamond, loop exit, early-exit guard preservation) and differentially check `unwrap_known_pc_guards` across all 18,228 random reducible graphs × 6 seeds. - `tests/test_translate.py`: assert `%blk2` in `ms_wave_info_s3` is emitted without a conditional `%pc` guard before its `OpControlBarrier`. - `docs/design.md`: document the pass in the Control flow contract row. ### Verification (before/after on `main` `47c651174`, `LEONIDA_VK_VALIDATION=1`) - **AMD Radeon(TM) Graphics (Ryzen 5 7600 RDNA2 iGPU, Windows 11, driver 24.10.24, 128B push constants, `LEONIDA_PC_TAIL_UBO=1`)**: - Before (`main`): `ms_wave_info_s3` **FAIL** (`vk_harness` crash `0xC0000005`) - After: `ms_wave_info_s3` **PASS** (`4096/4096 pixels exact`, 0 validation errors); `cs_barrier_divergent`, `cs_barrier_early_end`, `cs_barrier_loop` **3/3 PASS** - **NVIDIA GeForce RTX 4070 SUPER (Windows 11, driver 610.88)**: - `ms_wave_info_s3` **PASS** (`4096/4096 pixels exact`, 0 validation errors); `cs_barrier_*` **3/3 PASS** - **CPU / unit tests**: - `python -I tests/test_cfg_structure.py` — **18,228 random reducible graphs × 6 seeds** (both structured and unwrapped trees match `walk()`), plus shape & deep-chain tests - `python -I tests/test_runner_calls_all_tests.py` — **3/3 OK** - `python -I tests/test_cfg_run_limit.py` — **4/4 OK** - `pytest tests/test_translate.py` — **669 passed** - `unittest discover -s tests/semantic -p test_wave64_emulate_opt.py` — **31/31 OK** - `unittest discover -s tests/semantic -p "test_*barrier*.py"` — **53/53 OK** - `unittest discover -s tests/semantic -p "test_exec*.py"` — **2/2 OK** - `unittest discover -s tests/semantic -p "test_ms_*.py"` — **6/6 OK** - `python -I tests/test_text_write_line_endings.py` — **3/3 OK** - `python -I scripts/check_no_game_data.py ...` — clean (`rc=0`) AI-assisted (Gemini 4 Neon). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:14 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#846
No description provided.