Skip to content

w64_graphics: gs_w64_a_bpermute, a geometry-stage ds_bpermute fixture (tier A, GPU-checked on RADV) - #7338

Open
sskver wants to merge 3 commits into
ItsNotRexed:mainfrom
sskver:gs-w64-bpermute-fixture
Open

sskver wants to merge 3 commits into
ItsNotRexed:mainfrom
sskver:gs-w64-bpermute-fixture

Conversation

@sskver

@sskver sskver commented Nov 23, 2026

Copy link
Copy Markdown

Claim: #7231 (comment). Companion to #7311 (the vertex-stage fixture); independent of it, so either can merge first. Both add one line to the same FIXTURES and EXPECT tables, so the second to land needs a trivial rebase.

Adds gs_w64_a_bpermute, a geometry-stage ds_bpermute_b32 fixture for SHADER-10 tier A. The geometry stage had only gs_w64_a_ring and the lane-id probe.

It is gs_w64_a_ring plus four lane ^ 1 reads. Triangle p (from TEXCOORD0.x of input vertex 0, as in gs_w64_a_ring) stores four words to its heap record, all a function of p alone: p ^ 1, 3 * (p ^ 1) + 7, p (a round trip through lane ^ 1), and p >> 1.

Changes: the .asm, a FIXTURES entry (_gs_a_bpermute) in w64_graphics.py, and an EXPECT entry in tests/test_wave64_halves_fixtures.py. No translator change.

Tested (no game files):

  • GPU: AMD Ryzen 7 7800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.3.1, Linux, pinned with LEONIDA_VK_DEVICE=raphael. Scripts from this branch (main e0816d6af); vk_harness built from main 09b9ba8 (no runtime/ file the harness uses changed in between).
  • w64_graphics.py over all fixtures: 30 of 30 ok (the 29 existing plus this one), exit 0, tiers A 12 / B 8 / C 13 (this branch does not contain w64_graphics: vs_w64_a_bpermute, a vertex-stage ds_bpermute fixture (tier A, GPU-checked on RADV) #7311's fixture).
  • The translator classifies it tier A with no reasons or idioms.
  • python -m pytest tests/test_wave64_halves_fixtures.py: 10 passed. llvm-mc 21.1.8, SPIRV-Tools 1.4.363.0.

How RADV packed the geometry invocations on this GPU (measured with gs_w64_c_lane_id, 320 triangles; one GPU only, so the header says so): at wave64 the waves hold 42 invocations (first triangles 0, 42, 84, 126, ...); at wave32 each of those waves is split into 32 and 10 (0, 32, 42, 74, 84, ...). Every wave32 wave is one half of a wave64 wave, as for vertices. A wave starts at triangle 42 * w, so odd waves start 2 mod 4 and only lane ^ 1 is guaranteed to hold triangle p ^ 1; that is why the fixture reads only lane ^ 1.

AI-assisted (Claude Code, Claude Sonnet 5.5).

🤖 Generated with Claude Code

@tikD1337

Copy link
Copy Markdown
Contributor

I've checked the fixture's lane pairing and found one gap in the test coverage. Here is the review:

Review: gs_w64_a_bpermute, a geometry-stage ds_bpermute fixture (tier A)

What changed

  • runtime/test/shaders/gs_w64_a_bpermute.asm (new): a wave64 legacy (LDS-ring) GS. It starts the same way as gs_w64_a_ring: exec from s3[15:8], ds_read_b32 of TEXCOORD0.x from the input ring, and p = (x - 0x101) / 3 computed as a v_mul_hi_u32 by 0xaaaaaaab followed by a shift right by 1. It then builds a lane-id address ((mbcnt_hi(mbcnt_lo(-1)) ^ 1) << 2) and issues four ds_bpermute_b32. The fourth one (v8) reads back the result of the first (v6), with an s_waitcnt lgkmcnt(0) between them. It stores v[6:9] to 0x1000 + 16·p through the V# in s[4:7]. Like gs_w64_a_ring, it emits one vertex through the lane-based ring address, which makes no primitive.
  • w64_graphics.py: _gs_a_bpermute(i) = (i^1, 3(i^1)+7, i, i>>1), registered as tier A with GS_ENV.
  • tests/test_wave64_halves_fixtures.py: EXPECT["gs_w64_a_bpermute"] = ("A", [], []). This keeps test_every_fixture_has_a_tier_and_a_gpu_check (asm set == EXPECT == FIXTURES) consistent.

Soundness of the expected words

I checked the derivation against the wave layout in the header, measured with gs_w64_c_lane_id on gfx1036 / RADV 26.3.1:

  • At wave64, waves hold 42 invocations and start at 42·w. At wave32, waves start at 0, 32, 42, 74, … and hold 32 or 10. Every start is even and every wave size is even, including the tail: 320 − 7·42 = 26 lanes, one wave at either size. So lane L and lane L^1 always hold triangles p and p^1, both active, and no read lands on an inactive lane (an inactive lane would return 0). The header is right that lane ^ 2 / ^ 3 would not be safe here, because odd waves start at 2 mod 4. Restricting the fixture to ^ 1 is the correct choice.
  • r0 = p^1 and r1 = 3(p^1)+7 are direct. r2 reads v6 from the partner, which is (p^1)^1 = p. r3 = (p^1)>>1 = p>>1. All four match _gs_a_bpermute.
  • v_mad_u32_u24 v17, v21, 3, 7: p ≤ 319, so the 24-bit operand is exact.
  • The "address bits 2..6 only" wording follows ps_w64_a_bpermute.asm:3, i.e. the address counted within a 32-lane half. At wave64, lanes 32..41 do set bit 7. Under the ISA 10.4.4 two-halves model the second half reads the same lane either way, so the claim holds in the sense the PS fixture defines it.
  • The words depend only on p, never on the lane, so the result does not depend on how the triangles are split into waves. That is what tier A requires.

Issues

  1. tests/test_translate.py will silently skip this fixture (please fix). tests/test_translate.py:60-61 skips every gs_* / ms_* sample whose stem is not in conftest.SAMPLE_DXBC. tests/conftest.py:144 lists gs_w64_a_ring and gs_w64_c_lane_id but not the new fixture. As a result, the generic translate + spirv-val pass over runtime/test/shaders never translates gs_w64_a_bpermute and reports a SKIP instead. The fix is one line:
    "gs_w64_a_ring": GS_TRI_DXBC, "gs_w64_a_bpermute": GS_TRI_DXBC, "gs_w64_c_lane_id": GS_TRI_DXBC,
    test_fixtures_are_classified_as_their_headers_say still goes through build.py, which gives every gs_* the gs_tri signatures. That covers the tier classification, but not the test_translate validation pass.
  2. The header points to a fixture that does not exist (nit). Line 2 calls this "the geometry counterpart of vs_w64_a_bpermute and ps_w64_a_bpermute". There is no vs_w64_a_bpermute.asm in the tree or in FIXTURES. If it lives in another open PR, add Depends on: #N. Otherwise drop the reference.
  3. The test module's docstring is now incomplete (nit). The docstring of tests/test_wave64_halves_fixtures.py lists the GPUs each fixture group was checked on, and it does not mention the gs fixtures or gfx1036. One clause recording this run (RADV 26.3.1, gfx1036, with and without gewave32) would keep that record complete. The header also says the wave layout was measured on one GPU only. A second RADV GPU, for example the RX 9070 XT already used for the VS fixtures, would back the tier A claim more strongly. That is optional, because the result does not depend on how triangles are split into waves, as long as every wave starts on an even triangle.
  4. No _gs_a_bpermute spot check (optional). test_expected_words_of_the_gpu_fixtures checks the other reference functions but not this one. A line such as assert w64_graphics._gs_a_bpermute(43) == (42, 133, 43, 21) would pin it.

Test results (Windows 11, CPython 3.13, no game files)

  • git diff --check: PASS
  • python -m compileall -q make_game.py tools tests: PASS
  • python -I scripts/check_no_game_data.py on the changed files: PASS
  • python -I make_game.py --help: PASS
  • Targeted tests: none run. tests/test_wave64_halves_fixtures.py needs llvm-mc (AMDGPU) and spirv-as / spirv-val, so it did not run on this machine. The GPU check (vk_harness on RADV with and without RADV_PERFTEST=gewave32) is the author's report and was not reproduced here.

Adherence

  • No game data: the .asm is hand-written and its input comes from vs_ids / GS_TRI_DXBC. There is no carved shader, disassembly or log.
  • No keys or decryption, nothing online: nothing here touches either.
  • Fix, don't disable: this is a test fixture, not a translator rule, so no docs/design.md contract-table row is required. The missing SAMPLE_DXBC entry (issue 1) does, however, produce an automatic skip, and it should be added so the fixture is validated rather than skipped.

Approve once item 1 is fixed. Items 2–4 are nits.

AI-assisted.

@sskver

sskver commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks for the review. Pushed a follow-up commit:

  1. tests/conftest.py: gs_w64_a_bpermute is now in SAMPLE_DXBC, so test_translate.py translates and validates it instead of skipping it. pytest tests/test_translate.py -k gs_w64 now gives 3 passed (ring, bpermute, lane_id), 0 skipped.
  2. The .asm header now names the vertex fixture as the separate pull request w64_graphics: vs_w64_a_bpermute, a vertex-stage ds_bpermute fixture (tier A, GPU-checked on RADV) #7311 and says this file does not depend on it.
  3. Added the suggested spot check _gs_a_bpermute(43) == (42, 133, 43, 21) to test_expected_words_of_the_gpu_fixtures.

tests/test_wave64_halves_fixtures.py still gives 10 passed. I left item 3 (the docstring clause and a second RADV GPU) alone: I only have the one gfx1036 iGPU, so I cannot add another GPU's run.

AI-assisted (Claude Code, Claude Sonnet 5.5).

@sskver

sskver commented Nov 23, 2026

Copy link
Copy Markdown
Author

Second vendor, same fixture: gs_w64_a_bpermute also passes on NVIDIA GeForce RTX 5080 (driver 615.78.08, Linux, LEONIDA_VK_DEVICE=5080), with the follow-up commit. w64_graphics.py over all fixtures with this branch: 18 ok, 12 SKIP (the tier C fixtures, "needs a device that can require both 64 and 32"), 0 failures; the existing ps_w64_a_bpermute, vs_w64_a_skip and gs_w64_a_ring pass as well. This is a default-size check only (NVIDIA cannot be held to 64 lanes), so it confirms the expected words on a second vendor but is not a wave64-vs-wave32 comparison; that comparison is still the gfx1036 / RADV run in the description.

AI-assisted (Claude Code, Claude Sonnet 5.5).

@nullmarsh

Copy link
Copy Markdown

Tested 794a199f on RX 9060 XT (RDNA4, gfx1200), AMD Windows driver 26.11.2, Windows 11: gs_w64_a_bpermute fails here. w64_graphics.py reports 64: 88 of 320 pixels differ from the derived words, first (20,1): got (0, 0, 0, 0), want (85, 262, 84, 42). The other 25 fixtures are ok, and 6 tier C skip (no required VS/GS size on this driver). pytest tests/test_wave64_halves_fixtures.py: 10 passed.

It's the packing, not the translator. Measured with gs_w64_c_lane_id on the same draw, this driver packs the 320 GS invocations into waves of 64, 21, 64, 21, 64, 21, 1, 64 (first triangles 0, 64, 85, 149, 170, 234, 255, 256), not RADV's 42. A 21-invocation wave makes the next wave start at an odd triangle (85, 149, 255), so in those waves lane ^ 1 holds the wrong triangle (84 records wrong). The last lane of each odd wave has no partner and reads 0 (4 all-zero records: 84, 169, 254, 255). So "only lane ^ 1 is guaranteed to hold triangle p ^ 1" doesn't hold on the AMD Windows driver; the header's "other GPUs may pack differently" is the case here.

For comparison, #7311's vs_w64_a_bpermute passes on this driver.

AI-assisted (Claude Code), no game files.

@InCaseOf

Copy link
Copy Markdown

Tested 794a199 on AMD Radeon RX 5700 XT (RDNA1, gfx1010, RADV NAVI10), Mesa 26.3.1, Linux 6.18 (Arch container): fail (the new fixture only; nothing else regresses)

  • w64_graphics.py over all fixtures: 29 of 30 ok; gs_w64_a_bpermute fails: 64: 160 of 320 pixels differ from the derived words, first (40,0): got (0, 0, 0, 0), want (41, 130, 40, 20). The wave32 run gives the same records, wrong at the same 160 triangles: 40-81, 122-163, 204-245, 286-319. Same cause as vs_w64_a_bpermute in w64_graphics: vs_w64_a_bpermute, a vertex-stage ds_bpermute fixture (tier A, GPU-checked on RADV) #7311 (I've commented the same measurement there).
  • scripts/run_gpu_tests.py: 211/239 passed, 28 skipped, 0 failed (main e36d4c4: 212/240, 0 failed).
  • python -m pytest tests/test_wave64_halves_fixtures.py: 10 passed.

RDNA1 packs the waves differently from gfx1036, measured with the probe fixtures (max lane and the vertex at which lane 0 appears):

probe wave64 wave32
vs_w64_c_lane_id (960 vertices) 64, 59, 64, 59, ... (starts 0, 64, 123, 187, 246, ...; period 123) 32, 32, 32, 27, ... (0, 32, 64, 96, 123, ...)
gs_w64_c_lane_id (320 triangles) 41 per wave (starts 0, 41, 82, 123, ...) 32, 9, ... (0, 32, 41, 73, 82, ...)

So half the waves start at an odd vertex (8 of 16 VS waves, 4 of 8 GS waves at wave64), and the fixture's assumption that lane ^ 1 holds v ^ 1 (true on gfx1036, where every wave starts at an even vertex) does not hold here: in those waves lane ^ 1 holds v + 1 / v - 1 the other way round, and the last lane of a 59- or 41-lane wave reads an inactive lane and stores zeros.

Two things that may help:

  • Every wave32 wave is exactly one half of a wave64 wave on RDNA1 too (64 = 32 + 32, 59 = 32 + 27, 41 = 32 + 9), so the "repacking, not the two halves" docstring point from w64_graphics: vs_w64_a_bpermute, a vertex-stage ds_bpermute fixture (tier A, GPU-checked on RADV) #7311 also fails on gfx1010, not only gfx1036.
  • The records are identical at wave64 and wave32, so the tier A property itself (same words at both sizes) holds; only the derived words are packing-dependent. Expected words that do not assume an even wave start (for example only the round-trip word, or a partner computed from the measured packing) would make the fixture pass on both GPUs.

LLVM llvm-mc 23.1.5, SPIRV-Tools v2026.4, Python 3.14. Test programs built from main e36d4c4 (no runtime change in this PR). No game files.

AI-assisted (Claude Code).

@senyurah

Copy link
Copy Markdown

Tested 794a199f4 on Windows 11 build 26200, RTX 4060 Ti, NVIDIA 621.24, Vulkan 1.4.357, subgroup 32. With LLVM 23.1.5 and SPIRV-Tools v2026.4, all five targeted shaders passed spirv-val. w64_graphics.py reported gs_w64_a_bpermute and gs_w64_a_ring both OK. pytest tests/test_translate.py -k gs_w64 gave 3 passes.

The default-size gs_w64_c_lane_id readback had 320 valid records in 32 consecutive spans of 10 triangles each, with lane IDs 0–9 in each span. Every span began at an even triangle index, so this draw satisfies the lane-pairing assumption. It adds a Windows NVIDIA result and does not contradict the odd-start failure on the AMD Windows driver. No game files. AI-assisted (Codex).

@sskver

sskver commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks to @InCaseOf, @nullmarsh and @senyurah for testing. The failures on the RX 9060 XT (AMD Windows driver, waves of 64, 21, 64, 21, ...) and the RX 5700 XT (waves of 41) were the fixture's, not the translator's: I had assumed every wave starts at an even triangle, which holds on RADV gfx1036 but not there, so lane ^ 1 was not always p ^ 1. Pushed afab304: w64_graphics.py now measures the wave layout with the stage's lane-id probe at the same size and derives each record's expected words from it (the partner is the triangle at lane ^ 1 in the same wave; the last lane of an odd-sized wave has no partner and reads 0), and the 64-vs-32 equality check applies only when the wave32 draw is the wave64 draw cut into halves, as in every layout reported so far. Six new CPU tests use the reported layouts and reproduce the zero records the testers saw (84, 169, 254 and 255 on the 9060 XT); w64_graphics.py is 30/30 ok on RADV gfx1036 and 18 ok / 12 SKIP on an RTX 5080; pytest 16 passed, and test_translate.py -k gs_w64 gives 3. I can't rerun on the 5700 XT or 9060 XT: could you?

AI-assisted (Claude Code, Claude Sonnet 5.5).

@javdc

javdc commented Nov 23, 2026

Copy link
Copy Markdown

Tested 794a199 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: inconclusive (pre-existing w64_graphics 64-lane exit -11 on this Deck)

  • pytest tests/test_wave64_halves_fixtures.py -q — 10 passed
  • python3 -I runtime/test/shaders/w64_graphics.py <work> /home/deck/opencode/Leonida/runtime/build gs_w64_a_bpermute — 64-lane run: exit -11; same direct invocation also exits -11 on main for vs_w64_a_skip, so not treated as a PR regression

AI-assisted (OpenCode).

@InCaseOf

Copy link
Copy Markdown

Tested afab304 on RX 5700 XT (RDNA1, gfx1010, RADV NAVI10), Mesa 26.3.1, Linux 6.18: pass

  • w64_graphics.py over all fixtures: 30/30 ok, gs_w64_a_bpermute included (and the vs/gs/ps lane-id probes).
  • python -m pytest tests/test_wave64_halves_fixtures.py: 16 passed.
  • scripts/run_gpu_tests.py: 211/239 passed, 28 skipped, 0 failed.

Same setup as my first run (test programs from main e36d4c4, LLVM 23.1.5, SPIRV-Tools v2026.4, no game files). Thanks for the quick fix.

AI-assisted (Claude Code).

@nullmarsh

Copy link
Copy Markdown

Re-tested afab304d on the RX 9060 XT (gfx1200, AMD Windows driver 26.11.2): pass. gs_w64_a_bpermute is now ok against the measured 64/21 layout. w64_graphics.py: 26 ok, 6 tier C skipped (no required VS/GS size on this driver), 0 differ. pytest tests/test_wave64_halves_fixtures.py: 16 passed.

AI-assisted (Claude Code), no game files.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 794a199f4 merged onto main 9ce9a7923 (clean merge) on a second RDNA2 GPU: pass.

AMD Radeon RX 6700 XT (gfx1031, discrete RDNA2), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5; llvm-mc 23.1.5, SPIRV-Tools v2026.4, Python 3.14.10.

Geometry packing (gs_w64_c_lane_id, 320 triangles) matches your gfx1036 numbers: at wave64, 8 waves of 42 invocations (last 26), first triangles 0, 42, 84, 126, ...; at wave32 each of those is split into 32 + 10 (first triangles 0, 32, 42, 74, 84, ...).

AI-assisted (Claude Code).

@carlos-seiffert

Copy link
Copy Markdown

Tested afab304 (merged onto main 976b3ec) on NVIDIA GeForce RTX 2060 (Turing), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 (10.0.26300), subgroup size 32: pass

What I ran: python -I scripts/run_gpu_tests.py with the Vulkan tools built from 976b3ec (llvm-mingw + Ninja, -DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF, Vulkan-Headers 6802bb47), llvm-mc 23.1.6 and SPIRV-Tools from conda-forge.

main 976b3ec this PR on main
full GPU suite 192/241 passed, 48 skipped, 1 fail 192/241 passed, 48 skipped, 1 fail (same as main)

No GPU test changed status against main. runtime/test/shaders/w64_graphics.py (after build.py), main 976b3ec: 17 ok, 12 SKIP. On NVIDIA the vertex and geometry subgroup size cannot be required, so only the default-size checks run and every tier C line is a SKIP; this does not compare a wave64 run with a wave32 one.

With this PR: 18 ok, 12 SKIP — the new gs_w64_a_bpermute (tier A) is ok, and gs_w64_a_ring is still ok; nothing else changed.

tests/test_wave64_halves_fixtures.py: needs pytest, not run.

The one failure on both sides is ms_wave_info_s3, which fails on main on this GPU (10/10 runs) and is fixed by #7136 / #5741 / #5855; it is unrelated to this PR.

AI-assisted run (Claude Code); the numbers are from my machine.

@la-bagu3tte

Copy link
Copy Markdown

Same check on the geometry fixture: gfx1013 passes on afab304, and its reference matches on a 32-wide NVIDIA card.

Environment. AMD BC-250 (RDNA2 APU, gfx1013), RADV, Mesa 26.2.7, Vulkan 1.4.354, Bazzite 45 (Fedora 45), Python 3.15.2. Shaders from this head: 269 translated, 269 pass spirv-val. Test programs from main e0816d6.

Before and after on gfx1013:

head result
794a199 29 of 30 ok, gs_w64_a_bpermute fails: 160 of 320 records differ, first (40,0): got (0,0,0,0), want (41,130,40,20)
afab304 30 of 30 ok, exit 0

What gfx1013 packs, measured with gs_w64_c_lane_id over 320 triangles: at wave64 the waves hold 41 invocations (not 42 as on gfx1036), first triangles 0, 41, 82, 123, 164, 205, 246, 287; at wave32 the waves hold 32 and 9, first triangles 0, 32, 41, 73, 82, 114, 123, 155. p == wave first + lane holds for all 320, but the odd starts make lane ^ 1 hold p ^ 1 for only 160 of them — which is exactly the 160 records that failed before your fix, and it is the mirror of @nullmarsh's 64/21 layout on the RX 9060 XT.

Cross-device. The gfx1013 reference used as W64G_REF on an NVIDIA GeForce RTX 5080 (subgroup 32..32, driver 621.14, Windows 11 26200): 30 of 30 ok, exit 0, gs_w64_a_bpermute A ok.

No game files. AI-assisted (Claude).

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.

9 participants