Skip to content

GPU fixture ps_w64_a_break: a break loop's lane mask in an SGPR pair is tier A (SHADER-821) - #4870

Open
CuteBooty wants to merge 4 commits into
ItsNotRexed:mainfrom
CuteBooty:test/ps-w64-a-break
Open

CuteBooty wants to merge 4 commits into
ItsNotRexed:mainfrom
CuteBooty:test/ps-w64-a-break

Conversation

@CuteBooty

Copy link
Copy Markdown

Claim: #4683 (comment)

Depends on: #4656 (the branch carries its commits; the fixture is the last commit, 05ee55e6; please land #4656 first)

What and why

#4656 (SHADER-821) makes a lane mask that a compiler's break loop collects in an SGPR pair partition invariant, which moves such shaders from tier C to tier A. Its coverage is CPU only, and none of the existing GPU fixtures reaches the rule (check on #4656).

ps_w64_a_break is a wave64 pixel shader with two such loops, run by w64_graphics.py as tier A:

  • a break loop on x (1..4 trips, lanes of one quad leave at different trips), with a counter behind the break;
  • a break loop on y (1..8 trips), so a half can close it in fewer trips than the wave;
  • no saved copy of EXEC: the export runs with the EXEC the two pairs rebuilt, so a lost bit leaves the pixel cleared and a bit set early shortens that lane's loop.

Every expected word is a function of the pixel's (x, y): (x % 4 + 1, 1000 + x, 2000 + 5 * (y % 8 + 1), x % 4).

Tested

NVIDIA GeForce RTX 3070 (32-wide only), driver 617.14, Windows 11 25H2, llvm-mc 23.1.5, on top of #4656 649260f0:

  • build.py: 243/243 translated and valid; ps_w64_a_break is tier A with no reasons. With tools/wave64_halves.py from main (98fa503f) it is tier C, tainted-exec, so the fixture needs the rule.
  • w64_graphics.py: ps_w64_a_break A ok (all 4096 pixels give the derived words); the other 15 tier A/B fixtures still ok, tier C skipped (32-only device).
  • check.py: 153/188 pass, 35 skipped, as before.
  • python -m pytest tests/test_wave64_halves_fixtures.py: 9 passed (the fixture's tier is pinned in EXPECT).

Not tested: a 64-lane run. This device can only require 32, so the 64-against-32 comparison needs an AMD GPU (or W64G_SAVE_REF / W64G_REF).

AI-assisted (Claude Code; an independent read-through of the branch offsets and derived words by Codex).

🤖 Generated with Claude Code

Jacob and others added 4 commits November 23, 2026 18:02
…e (SHADER-821)

A compiler's break loop ORs a v_cmp result into an SGPR pair and narrows EXEC
with it. stale_uses() treated the pair as a scalar, so the loop was tier C
tainted-exec although each bit belongs to one lane. A def that ORs (or
AND-NOTs) a same-block v_cmp result into the pair leaves the off lanes' bits
alone; a read that only uses the pair as a lane mask (an EXEC write, or the next
such def) is no longer stale. Scalar uses (s_bcnt1, s_cmp) still are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…DER-821)

After the rebase onto main, the kill-exit test from cc4231d that expected a
conservative tier C for an exit whose live mask two kills define now gets A:
both definitions are `s_andn2_b64 D, D, vcc` after a v_cmp, so the mask is
lane-local. Run it on the emulator (64 lanes against two halves of 32, with
the halves leaving at different votes) and the words match. Keep a C control
where the second definition ORs in a scalar register.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…is tier A (SHADER-821)

A wave64 pixel shader with two compiler-style break loops: the lanes that
left are collected by s_or_b64 D, vcc, D after a v_cmp, the pair narrows
EXEC inside the loop and widens it again behind it. w64_graphics.py runs it
as tier A; every word is a function of the pixel's (x, y).

With tools/wave64_halves.py from main the fixture is tier C (tainted-exec);
with ItsNotRexed#4656 it is tier A. On an RTX 3070 (32-wide only, driver 617.14) all
4096 pixels give the derived words.

Depends on: ItsNotRexed#4656

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 05ee55e6 on Windows 11. All 4,096 pixels match the expected four words on the NVIDIA GeForce RTX 4090 (32.0.16.2101) and AMD Radeon(TM) Graphics (32.0.21043.5001). The 65,536-byte readbacks have the same SHA-256: b422c1ea1a21d647c2d8f2334ed60f070e37a5e12222ac6e2d5f52c2a3b3a063.

I ran vk_harness.exe vs_ids.spv ps_w64_a_break.spv out.raw with LEONIDA_VK_DEVICE=4090 and VKH_SUBGROUP_SIZE=32. I repeated the draw with LEONIDA_VK_DEVICE=Radeon and sizes 32 and 64. The harness confirms the 32 request on NVIDIA. It reports the range 32–64 on AMD but does not confirm either request there.

To check the execution width, I repeated each draw with a diagnostic fragment module. It writes the SPIR-V SubgroupSize built-in into the fourth output word. Every pixel reports 32 on NVIDIA. Every pixel reports 64 on AMD for both requests. I used the original four output words for the image comparison above.

I translated the checked-in fixture instructions with the PR translator. I supplied synthetic instruction lengths for the branch offsets and assembled the SPIR-V with the in-tree assembler. The PR classifies the break fixture as tier A. The merge-base translator at 98fa503f classifies the same listing as tier C (tainted-exec). The fixture pytest file reports eight passes and one skip. The standard llvm-mc build and external SPIR-V validation remain untested here.

AI-assisted.

@Rainmaker33

Copy link
Copy Markdown

Tested 05ee55e on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass.

The PR's diff applied cleanly to main d974c88. VS 2022, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8; harness programs from a CMake build of that main; overlay layers off.

  • build.py: 243 translated, all pass spirv-val.
  • runtime/test/shaders/w64_graphics.py, at 32 lanes only on NVIDIA: ps_w64_a_break (tier A) is ok. Overall 16 ok and 12 SKIP (tier C needs 64 and 32), with no failures.
  • scripts/run_gpu_tests.py: 170/217, 0 failures, the same as main.
  • tests/semantic/test_wave64_halves.py: OK. I didn't run tests/test_wave64_halves_fixtures.py (it needs pytest, which isn't installed here).

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 05ee55e on AMD Radeon 610M (RADV RAPHAEL_MENDOCINO, subgroup 32..64, Mesa 26.2.6), CachyOS Linux: pass.

  • runtime/test/shaders/build.py: 243 translated, 243 pass spirv-val.
  • w64_graphics.py with LEONIDA_VK_DEVICE=RADV: all 28 wave64 fixtures ok, including ps_w64_a_break (tier A). RADV runs both 32 and 64 lanes, so the 32/64 comparison is native here.
  • pytest tests/test_wave64_halves_fixtures.py tests/semantic/test_wave64_halves.py: 116 passed, 19 subtests passed.

Not checked: the claim that main classifies this fixture as tier C.

AI-assisted.

@memorypressure

Copy link
Copy Markdown

Verified merge with main 3faac55 (clean): test_wave64_halves.py (semantic) and test_wave64_halves_fixtures.py (9 under pytest, re-run) pass, as does the test_semantic_translator_use.py guard. The new fixture is a hand-written asm listing with the expected-words derivation in comments, and the detector extension is confined to lane-local SGPR-pair defs with a clear contract (only the s_or_b64/s_andn2_b32 shapes fed by a same-block v_cmp with no EXEC write since) — well-scoped. The GPU-side w64_graphics run needs hardware and was not executed here. Note: no CI checks reported on this branch. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@bunbeans2-arch

Copy link
Copy Markdown

The 64-against-32 run you asked for, on an AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), Windows 11 23H2, AMD's
Windows Vulkan driver, head 05ee55e.
build.py made 31 wave64 fixtures, and w64_graphics.py gives 24 ok and 4 skipped, rc 0. The line in question:
ps_w64_a_break A ok.
The comparison really ran at both sizes: all 8 ps_w64_c_* tier C fixtures pass, and those need the 64 and 32 images
to differ. The 4 skips are the VS/GS tier C fixtures (no RADV gewave32 on Windows).
tests/test_wave64_halves_fixtures.py: 9 passed.
This adds AMD's own Windows driver on RDNA4 to the RADV run above.
AI-assisted (Claude Code). No game files.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 05ee55e on Windows Server 2022, CPython 3.13.12: pass

  • pytest tests/test_wave64_halves_fixtures.py -> 8 passed, 1 skipped; python -I -m unittest discover -s tests/semantic -p "test_wave64_halves.py" -> OK

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

sperm pushed a commit to sperm/Leonida that referenced this pull request Nov 23, 2026
… loop keeps the rule (SHADER-821)

b3933dc made any non-narrowing EXEC write after the first vote turn the lane-local rule off for the rest of the
shader. A break loop's restore (`s_or_b64 exec, exec, <left lanes>`) at its exit block is such a write, so every
later loop's v_cmp stopped counting (two loops in a row: @CuteBooty, ItsNotRexed#4870, tier A before, C after).

Track the open votes instead: a vote opens leaving its block and closes on entering a block that post-dominates
it, where the halves are together again; only a widening while a vote is open counts against that vote.

@shdann's counterexample (a restore inside the vote's region) stays tier C; a widening behind a later vote after
a closed loop is tier C too. Two loops are tier A and run the same in the wave and in halves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

7 participants