[PR #2102] [MERGED] wave64_emulate_opt: a guarded s_barrier keeps only the tail in the round scheduler (SHADER-W64-STRUCTURED-SBARRIER-TAIL) #2107

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2102
Author: @DadaCap
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: mesh-epilogue-tail


📝 Commits (1)

  • 8481605 wave64_emulate_opt: a guarded s_barrier keeps only the tail in the round scheduler (SHADER-W64-STRUCTURED-SBARRIER-TAIL)

📊 Changes

4 files changed (+52 additions, -18 deletions)

View changed files

📝 docs/design.md (+1 -1)
📝 tests/semantic/test_loop_ballot_barrier.py (+2 -2)
📝 tests/semantic/test_wave64_emulate_opt.py (+45 -7)
📝 tools/wave64_emulate_opt.py (+4 -8)

📄 Description

Claimed in the coordination issue as: SHADER-W64-STRUCTURED-SBARRIER-TAIL (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7174042486)

Depends on: nothing

What and why

Under --wave64-emulate, plan_structured_emulation gives no plan for a multi-wave program (more than 64 threads) as soon as one s_barrier sits under a guard or in a loop. The NGG mesh epilogue has one (s_cbranch_vccnz over an s_barrier), so every mesh program of 1.0.2.1 runs whole in the round scheduler.

The planner already has a step for a tail that must stay in rounds (tail_scheduler, used from an early s_endpgm on). This change uses it from the first guarded s_barrier on as well, and emits what comes before in the structured form.

Why it is sound:

  • The tail starts at the first top-level item that holds a guarded or looped s_barrier and runs to the end of the program, so every such s_barrier, and every one after it, stays in the rounds. Waves on different paths still meet at different sites there (cs_barrier_divergent).
  • What runs before the tail can only hold s_barriers in top-level blocks, which the whole workgroup reaches, and no s_endpgm.
  • The tail step itself, and the barrier in front of it when memory is dirty, are unchanged.

Counts over 1.0.2.1 (translator only)

Programs Emulated rounds before Structured after spirv-val failures
Mesh 9,282 9,282 0
Compute, executable archives, still in rounds on main 222 40 0
Compute, pipeline library, still in rounds on main 262 34 0

All of them translate before and after. The compute programs were run through main's translator again for the "before" column (none is structured). For mesh, main's translator gives the same bytes as the old folder for three programs I checked. Other stages cannot reach this code.

Measured in the game

Two runs of the same executable (a local tree of db1a22d29 with other open work, GPU timer on), the only difference being the mesh modules. Median GPU time of the sampled indirect draws, for the 17 mesh programs sampled at the same group count in both; the sample counts are small for some:

Mesh program Before, ms (n) After, ms (n) Ratio
MS_VS_TransformD_c5fd36bb 2.94 (96) 0.40 (19) 0.14
MS_VS_OctaSLOD_5fd19871 3.60 (24) 0.76 (42) 0.21
MSNC_VS_TransformSkinD_9e3a1555 3.73 (81) 1.27 (75) 0.34
MS_VS_TransformD_c5fd36bb~153 18.61 (27) 11.12 (14) 0.60
MSNC_VS_PropFoliageSkinDeferred_4352f5e1~8 28.14 (22) 17.60 (4) 0.63
MSNC_VS_TransformSkinD_9e3a1555~50 25.20 (17) 19.68 (21) 0.78

The other 11 are between 0.13 and 0.64.

Not shown by these runs:

  • Pictures. The two runs' exposure differs a lot, as it does between runs of one build here, so I could not compare them by pixels. Correctness rests on the CPU workgroup interpreter.
  • Stability. The run with the old modules lost the device at 700 s, in a different scene, and the run with the new ones did not in 15 minutes. One event says nothing about this change.
  • The new compute modules were not run in the game.

Tested

  • tests/semantic/test_wave64_emulate_opt.py: test_multiwave_divergent_sbarrier_falls_back_to_rounds asserted the old fallback; it now asserts that both s_barrier arms are in the tail, and the same memory result in both invocation orders. New: a mesh-epilogue shape (guarded s_barrier, skipped and taken, 128 threads, both orders).
  • tests/semantic/test_loop_ballot_barrier.py: two tests asserted the rounds form for an s_barrier in a loop; they now expect the structured form, and their memory results (including the wave that ends early) are unchanged.
  • Whole translator suite: 491 files, 6,313 tests, 0 files failed (24 jobs)
  • tests/test_translate.py: 706 pass, 2 fail (cs_dpp_cmp.asm: my older llvm-mc refuses the DPP form of v_cmp); both fail the same way on plain main here.
  • python -I -m compileall -q tools tests, tests/test_docs_*.py, scripts/check_no_game_data.py on the changed files.

GPUs tested: NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 (the game runs above; the hand-written GPU tests were not run)

AI-assisted: yes (Claude Code, Claude Opus 5.5 wrote the change, the tests and this text)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🤖 Generated with Claude Code


🔄 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/2102 **Author:** [@DadaCap](https://github.com/DadaCap) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `mesh-epilogue-tail` --- ### 📝 Commits (1) - [`8481605`](https://github.com/ubiquitarianism/leonida/commit/84816055d526062d6c61da6076fc31c92aee2b66) wave64_emulate_opt: a guarded s_barrier keeps only the tail in the round scheduler (SHADER-W64-STRUCTURED-SBARRIER-TAIL) ### 📊 Changes **4 files changed** (+52 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) 📝 `tests/semantic/test_loop_ballot_barrier.py` (+2 -2) 📝 `tests/semantic/test_wave64_emulate_opt.py` (+45 -7) 📝 `tools/wave64_emulate_opt.py` (+4 -8) </details> ### 📄 Description Claimed in the coordination issue as: SHADER-W64-STRUCTURED-SBARRIER-TAIL (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7174042486) Depends on: nothing ### What and why Under `--wave64-emulate`, `plan_structured_emulation` gives no plan for a multi-wave program (more than 64 threads) as soon as one `s_barrier` sits under a guard or in a loop. The NGG mesh epilogue has one (`s_cbranch_vccnz` over an `s_barrier`), so every mesh program of 1.0.2.1 runs whole in the round scheduler. The planner already has a step for a tail that must stay in rounds (`tail_scheduler`, used from an early `s_endpgm` on). This change uses it from the first guarded `s_barrier` on as well, and emits what comes before in the structured form. Why it is sound: - The tail starts at the first top-level item that holds a guarded or looped `s_barrier` and runs to the end of the program, so every such `s_barrier`, and every one after it, stays in the rounds. Waves on different paths still meet at different sites there (`cs_barrier_divergent`). - What runs before the tail can only hold `s_barrier`s in top-level blocks, which the whole workgroup reaches, and no `s_endpgm`. - The tail step itself, and the barrier in front of it when memory is dirty, are unchanged. ### Counts over 1.0.2.1 (translator only) | Programs | Emulated rounds before | Structured after | `spirv-val` failures | |---|---|---|---| | Mesh | 9,282 | 9,282 | 0 | | Compute, executable archives, still in rounds on main | 222 | 40 | 0 | | Compute, pipeline library, still in rounds on main | 262 | 34 | 0 | All of them translate before and after. The compute programs were run through main's translator again for the "before" column (none is structured). For mesh, main's translator gives the same bytes as the old folder for three programs I checked. Other stages cannot reach this code. ### Measured in the game Two runs of the same executable (a local tree of `db1a22d29` with other open work, GPU timer on), the only difference being the mesh modules. Median GPU time of the sampled indirect draws, for the 17 mesh programs sampled at the same group count in both; the sample counts are small for some: | Mesh program | Before, ms (n) | After, ms (n) | Ratio | |---|---|---|---| | `MS_VS_TransformD_c5fd36bb` | 2.94 (96) | 0.40 (19) | 0.14 | | `MS_VS_OctaSLOD_5fd19871` | 3.60 (24) | 0.76 (42) | 0.21 | | `MSNC_VS_TransformSkinD_9e3a1555` | 3.73 (81) | 1.27 (75) | 0.34 | | `MS_VS_TransformD_c5fd36bb~153` | 18.61 (27) | 11.12 (14) | 0.60 | | `MSNC_VS_PropFoliageSkinDeferred_4352f5e1~8` | 28.14 (22) | 17.60 (4) | 0.63 | | `MSNC_VS_TransformSkinD_9e3a1555~50` | 25.20 (17) | 19.68 (21) | 0.78 | The other 11 are between 0.13 and 0.64. Not shown by these runs: - **Pictures.** The two runs' exposure differs a lot, as it does between runs of one build here, so I could not compare them by pixels. Correctness rests on the CPU workgroup interpreter. - **Stability.** The run with the old modules lost the device at 700 s, in a different scene, and the run with the new ones did not in 15 minutes. One event says nothing about this change. - The new compute modules were not run in the game. ### Tested - `tests/semantic/test_wave64_emulate_opt.py`: `test_multiwave_divergent_sbarrier_falls_back_to_rounds` asserted the old fallback; it now asserts that both `s_barrier` arms are in the tail, and the same memory result in both invocation orders. New: a mesh-epilogue shape (guarded `s_barrier`, skipped and taken, 128 threads, both orders). - `tests/semantic/test_loop_ballot_barrier.py`: two tests asserted the rounds form for an `s_barrier` in a loop; they now expect the structured form, and their memory results (including the wave that ends early) are unchanged. - Whole translator suite: 491 files, 6,313 tests, 0 files failed (24 jobs) - `tests/test_translate.py`: 706 pass, 2 fail (`cs_dpp_cmp.asm`: my older `llvm-mc` refuses the DPP form of `v_cmp`); both fail the same way on plain `main` here. - `python -I -m compileall -q tools tests`, `tests/test_docs_*.py`, `scripts/check_no_game_data.py` on the changed files. GPUs tested: NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 (the game runs above; the hand-written GPU tests were not run) AI-assisted: yes (Claude Code, Claude Opus 5.5 wrote the change, the tests and this text) ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 changed title from [PR #2102] wave64_emulate_opt: a guarded s_barrier keeps only the tail in the round scheduler (SHADER-W64-STRUCTURED-SBARRIER-TAIL) to [PR #2102] [MERGED] wave64_emulate_opt: a guarded s_barrier keeps only the tail in the round scheduler (SHADER-W64-STRUCTURED-SBARRIER-TAIL) 2026-11-26 22:46:09 +01:00
4ld0 closed this issue 2026-11-26 22:46:09 +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#2107
No description provided.