Skip to content

rdna2spirv: quad_any's docstring says partial quads are exact (DOC-QUAD-ANY-PARTIAL) - #2799

Merged
MoonEyes merged 3 commits into
ProjectLeonida:mainfrom
aznohonza:docs/quad-any-partial
Dec 1, 2026
Merged

MoonEyes merged 3 commits into
ProjectLeonida:mainfrom
aznohonza:docs/quad-any-partial

Conversation

@aznohonza

@aznohonza aznohonza commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: DOC-QUAD-ANY-PARTIAL

What and why

The quad_any docstring said an absent invocation in a partial quad gives an undefined value natively. That is stale: the non-fragment branch already answers partial quads exactly by reading each lane's activity with OpGroupNonUniformBallot, and tests/semantic/test_absent_lane_ub.py::test_quad_any_partial_quad_in_vs_and_cs covers partial VS and CS quads (it asserts the module uses ballot, not QuadSwap or an unguarded shuffle). This changes comments only; no translation output changes.

After review, three more stale lines in the same docstring/comment and one in a test header: the docstring no longer says the vertex, geometry and mesh shaders shuffle (they ballot); a partial quad is described as fewer than 4 of the quad's lanes running (a partial wave such as 2 active lanes of a 32-lane subgroup, not only a size that is not a multiple of 4); the exactness claim is limited to the non-emulated path; and the tests/semantic/test_salu_wqm32.py header now says the vertex path uses ballot, not a shuffle.

Tested

CPU only, no game files or GPU:

  • python -I tests/semantic/test_absent_lane_ub.py — 18 tests pass.
  • python -I tests/semantic/test_salu_wqm32.py — 10 tests pass.
  • python -m compileall -q tools/rdna2spirv.py and scripts/check_no_game_data.py on the changed files.

GPUs tested: n/a

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: wording only, no new rule)

The comment still claimed an absent invocation in a partial non-fragment
quad gave an undefined value natively, while the non-fragment branch
reads every lane's activity with OpGroupNonUniformBallot. Wording only.

DOC-QUAD-ANY-PARTIAL.
@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12, head 3587499f4, main 9dffbe721. CPU only.

READ IN CODE

  • The new docstring matches the code. quad_any has three branches: emulated (exchange buffer), ps (OpGroupNonUniformQuadSwap; fragment quads are always complete), and every other stage, which uses OpGroupNonUniformBallot and takes this lane's 4-bit quad nibble. With ballot, an absent lane is simply 0, so partial quads are exact, as the new text says. The old line ("undefined value natively") described the code before the ballot branch.
  • The diff only touches the docstring (3+/2−), so translator output can't change.

MEASURED

  • python -I tests/semantic/test_absent_lane_ub.py: 18 tests OK on main 9dffbe721. That file includes test_quad_any_partial_quad_in_vs_and_cs (line 341), the test your description cites.

AI-assisted: Claude Code

@aegish-zagi

Copy link
Copy Markdown
Contributor

Verification — VERIFY-2799

Verdict: PASS

  • PR: rdna2spirv: quad_any's docstring says partial quads are exact (DOC-QUAD-ANY-PARTIAL) #2799 | head sha: 3587499f4f01375d114887caaaca9069fff0748b | merge state vs main: clean merge with current main 5dd6d444f in a scratch worktree (merge commit eb268b04d), no conflicts. Diff: docstring only in tools/rdna2spirv.py (+3/−2), no code change.
  • Tests run: python -m unittest discover -s tests/semantic -p test_absent_lane_ub.py
    • On PR (merged with main): 18 tests, OK
    • On plain main: 18 tests, OK — identical, as expected for a documentation-only change.
  • Audit (READ IN CODE): the new docstring text matches the implementation it describes. In Gen.quad_any, the non-fragment branch (CS/VS/GS/MS) sets uses_ballot and emits OpGroupNonUniformBallot, then extracts this lane's 4-bit quad nibble from the ballot word; the in-code comment at that branch states ballot bit l is set iff lane l is running with v != 0, so the result is exact on partial subgroups — which is precisely what the corrected docstring now says, replacing the stale 'undefined value natively' claim. The covering test named in the PR (test_quad_any_partial_quad_in_vs_and_cs) exists in tests/semantic/test_absent_lane_ub.py and passes. No game data.
  • Platform: Linux, Python 3.12.3, no GPU.

AI-assisted: yes (Muse Wonder, Muse by Meta)

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new sentence matches the code: the non-fragment branch ballots v != 0 (tools/rdna2spirv.py:7211), ORs the selected word and masks the quad nibble (:7223-7225), so absent lanes contribute 0 and the result is exact for the running lanes — which is also what docs/design.md:551 and :575 already say. test_absent_lane_ub.py (18/18), test_translate.py -k wqm (13/13) and test_salu_wqm32.py (10/10) pass, and test_quad_any_partial_quad_in_vs_and_cs does exercise a partial quad (VS with lanes 5 and 6 of 32, CS with a two-lane workgroup, both in the strict interpreter).

But the change leaves the docstring contradicting itself two lines above:

  • :7173-7174 still says "vertex, geometry and mesh shaders shuffle". That is stale from before 9e085fa6c replaced the shuffle path with ballot for CS/VS/GS/MS, and it now reads as two different mechanisms in one paragraph. Fix that clause here ("the fragment stage uses the 2x2 quad; the other stages ballot"), or the next editor will follow the wrong one.
  • The parenthetical is narrower than the code and than your own test: :7206 says "subgroup size or thread count not a multiple of 4", while the new text says "a group whose size is not a multiple of 4" — your VS case is 2 active lanes of a 32-lane subgroup, i.e. a partial wave, not an odd group size.
  • "is exact too" lost the qualifier the old sentence had: the ballot reason holds only without emulation — the if self.emulate branch above reads %x_buf, not Ballot.

Minor, outside the diff but about the same rule: tests/semantic/test_salu_wqm32.py:7-8 still claims the vertex path uses OpGroupNonUniformShuffle for quad_any, while the test itself asserts QuadSwap for PS and Ballot at :312-313 — its header is stale. No contract-table change is needed; docs/design.md:551 already records this.

@aznohonza

Copy link
Copy Markdown
Contributor Author

Addressed in d696c86:

  • the stale shuffle clause is gone: the fragment stage uses the 2x2 quad, every other stage ballots;
  • both the docstring and the inline comment now say a partial quad has fewer than 4 of its lanes running, with your case (2 active lanes of a 32-lane subgroup) as the example, not an odd group size;
  • the exactness claim is back inside "without emulation"; the emulated path is stated separately as the exchange-buffer read;
  • tests/semantic/test_salu_wqm32.py's header now says OpGroupNonUniformBallot for quad_any and OpGroupNonUniformQuadSwap only for the fragment stage.

docs/design.md:551 already describes the code, so no contract row changes. Checks: python -I tests/semantic/test_absent_lane_ub.py (18 pass), python -I tests/semantic/test_salu_wqm32.py (10 pass), python -m compileall -q tools/rdna2spirv.py, and scripts/check_no_game_data.py on the changed files. Comment-only, no output change.

@MoonEyes

MoonEyes commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Verified by MoonEyes (another person than the author) on head d696c8650 merged with main 501b3e6c5: Windows 11, Python 3.14. The diff changes a docstring and comments in tools/rdna2spirv.py and one line of a test's docstring, no code: tests/semantic/test_salu_wqm32.py 10 OK on both sides, so there is no red. I read quad_any next to it: the fragment stage uses QuadSwap and the others ballot, as the new text says.

AI-assisted (Claude Code).

@aznohonza

Copy link
Copy Markdown
Contributor Author

Thanks — tests/semantic/test_salu_wqm32.py is 10 tests OK here too, and the change is comments and one test docstring only. Nothing further from our side.

AI-assisted.

@MoonEyes

MoonEyes commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Merging. Head d696c8650 merges cleanly with main 9f27ba2e1 and does not force a rebase of #2566. CI green on this head and on main. Comments and a docstring only, no code: the test passes on both sides; I read quad_any against the new text. Merged by MoonEyes.

AI-assisted (Claude Code).

@MoonEyes
MoonEyes merged commit 3e7b34a into ProjectLeonida:main Dec 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants