[PR #1133] rdna2spirv: use subgroup ballot in quad_any for non-PS stages to avoid partial-quad UB (OLD-9833) #1165

Open
opened 2026-11-26 20:20:18 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1133
Author: @ambroseautomation
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: carry/old-9833-quad-any-ballot


📝 Commits (1)

  • ed4a77c rdna2spirv: use subgroup ballot in quad_any for non-PS stages to avoid partial-quad UB

📊 Changes

2 files changed (+183 additions, -17 deletions)

View changed files

➕ tests/semantic/test_quad_any_partial_quad.py (+154 -0)
📝 tools/rdna2spirv.py (+29 -17)

📄 Description

Claimed in the coordination issue as: OLD-9833 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7141272211)

What and why

Carries forward old-pr/9833 (draft #101, original commit author Lewandox preserved; indexed in #17), rebased cleanly onto current main.

Fixes partial-quad undefined behavior in Gen.quad_any (tools/rdna2spirv.py):

  • For fragment shaders (ps), keeps OpGroupNonUniformQuadSwap (2x2 fragment quads always have 4 invocations).
  • For compute, vertex, geometry, and mesh shaders (cs, vs, gs, ms), replaces OpGroupNonUniformQuadSwap / OpGroupNonUniformShuffle with OpGroupNonUniformBallot + OpGroupNonUniformBallotBitExtract across the quad's four lanes (combined with bitwise OR to avoid short-circuiting in MSL), so absent invocations in partial quads (workgroups or draws whose size is not a multiple of 4) read as 0 instead of triggering undefined behavior.
  • Adds tests/semantic/test_quad_any_partial_quad.py verifying compute partial quads, vertex partial quads, and fragment quad-swap preservation.

Tested

  • python -m unittest discover -s tests/semantic -p test_quad_any_partial_quad.py -v: 3 tests, OK.
  • python -I scripts/run_semantic_tests.py tests/semantic: 471 files, 6,171 tests, 0 files failed.
  • python -m compileall -q make_game.py tools tests: exit 0.
  • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_quad_any_partial_quad.py: exit 0 (no game data).

GPUs tested: n/a (CPU SPIR-V interpreter semantic suite on Windows 11 Pro 64-bit, Python 3.12.10)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • 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. (n/a — partial-quad UB fix for existing quad_any lowering)

🔄 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/1133 **Author:** [@ambroseautomation](https://github.com/ambroseautomation) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `carry/old-9833-quad-any-ballot` --- ### 📝 Commits (1) - [`ed4a77c`](https://github.com/ubiquitarianism/leonida/commit/ed4a77cb4b4b11ae04095c0953a62b26a1a1c22e) rdna2spirv: use subgroup ballot in quad_any for non-PS stages to avoid partial-quad UB ### 📊 Changes **2 files changed** (+183 additions, -17 deletions) <details> <summary>View changed files</summary> ➕ `tests/semantic/test_quad_any_partial_quad.py` (+154 -0) 📝 `tools/rdna2spirv.py` (+29 -17) </details> ### 📄 Description Claimed in the coordination issue as: OLD-9833 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7141272211) ### What and why Carries forward `old-pr/9833` (draft #101, original commit author `Lewandox` preserved; indexed in #17), rebased cleanly onto current `main`. Fixes partial-quad undefined behavior in `Gen.quad_any` (`tools/rdna2spirv.py`): - For fragment shaders (`ps`), keeps `OpGroupNonUniformQuadSwap` (2x2 fragment quads always have 4 invocations). - For compute, vertex, geometry, and mesh shaders (`cs`, `vs`, `gs`, `ms`), replaces `OpGroupNonUniformQuadSwap` / `OpGroupNonUniformShuffle` with `OpGroupNonUniformBallot` + `OpGroupNonUniformBallotBitExtract` across the quad's four lanes (combined with bitwise OR to avoid short-circuiting in MSL), so absent invocations in partial quads (workgroups or draws whose size is not a multiple of 4) read as 0 instead of triggering undefined behavior. - Adds `tests/semantic/test_quad_any_partial_quad.py` verifying compute partial quads, vertex partial quads, and fragment quad-swap preservation. ### Tested - `python -m unittest discover -s tests/semantic -p test_quad_any_partial_quad.py -v`: 3 tests, OK. - `python -I scripts/run_semantic_tests.py tests/semantic`: 471 files, 6,171 tests, 0 files failed. - `python -m compileall -q make_game.py tools tests`: exit 0. - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_quad_any_partial_quad.py`: exit 0 (no game data). GPUs tested: n/a (CPU SPIR-V interpreter semantic suite on Windows 11 Pro 64-bit, Python 3.12.10) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — partial-quad UB fix for existing `quad_any` lowering) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#1165
No description provided.