Skip to content

wave64: scalar side effects in a voted branch refuse tier A (SHADER-742) - #4156

Open
olegmkrv wants to merge 1 commit into
ItsNotRexed:mainfrom
olegmkrv:shader-742-scalar-side-effect
Open

olegmkrv wants to merge 1 commit into
ItsNotRexed:mainfrom
olegmkrv:shader-742-scalar-side-effect

Conversation

@olegmkrv

Copy link
Copy Markdown

Claimed as SHADER-742 in #4084.

tools/wave64_halves.py treated s_store_*/s_buffer_store_*, scalar atomics and non-GS s_sendmsg inside a voted branch's run side as tier A. They run once per wave, not under EXEC, so two 32-lane halves would run them twice when both take the branch. They now yield tier C scalar-side-effect (GS emit/cut/done stays tier A as stage output). Contract table in docs/design.md updated.

Tested: python3 -I -B tests/semantic/test_wave64_halves.py -> 79 pass (73 existing + 6 new); git diff --check clean. Python only, no game files or GPU. AI-assisted.

@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Code read of acd24ad3. run_side_has_scalar_effect walks the blocks reachable from the run side without crossing the join and reports scalar-side-effect at the effect's own pc for s_store_*, s_buffer_store_*, s_atomic_*, s_buffer_atomic_* and non-GS s_sendmsg; GS emit/cut/done stays tier A.
Ran on Windows 11, Python 3.14: tests/semantic/test_wave64_halves.py 79 OK; with only tools/wave64_halves.py restored to main four of the new tests fail; test_wave64_halves_soundness (30) and test_wave64_halves_fixtures (9) pass; compileall and git diff --check clean.
Mutation check: dropping s_atomic_ or s_buffer_store_ from the prefix list, or flipping the GS test of s_sendmsg either way, is caught. Removing the stop at the join (if b == join or b in seen to if b in seen) is not caught by any test, and it changes behaviour: with an s_store_dword in the join block after the branch the PR gives tier A and the mutant gives tier C. A test with a scalar store after the join (expecting tier A) would pin the scan boundary.
Question, not a blocker: a scalar store or atomic outside any voted branch still gets no reason, although "runs once per wave, not under EXEC, so each half repeats it" would apply there too; is that covered elsewhere or left for another item?
AI-assisted code read (Claude).

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested acd24ad on Windows 11 (Python 3.12.10), AMD Radeon iGPU gfx1036 (driver 26.10.1) and RTX 5080 (driver 616.92), translator and runtime from this head (MSVC, RelWithDebInfo):

  • tests/semantic/test_wave64_halves.py 79/79 OK, test_wave64_halves_soundness.py 30/30 OK, tests/test_wave64_halves_fixtures.py 9 passed.
  • runtime/test/shaders/w64_graphics.py on each GPU (LEONIDA_VK_DEVICE set per run, VK_LOADER_LAYERS_DISABLE=~implicit~, no validation layer installed): 14 ok, 12 SKIP (tier C, which needs a device that can require both fragment sizes), 0 failures on both. So the tier A/B fixtures still give their derived words after the reclassification.

No negative control run.

AI-assisted.

@KkelebekK

Copy link
Copy Markdown

Tested 13eb929c (clean merge into main 3faac557, which is also its merge-base; Python-only change) on AMD Radeon 780M (RADV PHOENIX, gfx1103 / RDNA3, Mesa 26.2.6, subgroup 32..64) and NVIDIA RTX 4070 Laptop (620.70.06, subgroup 32..32), CachyOS, Linux 7.3.4, llvm-mc 23.1.4, Python 3.14.10: pass. The rule has no GPU-visible effect on the existing fixtures, and this machine cannot exercise it on a GPU (see below).

CPU tests (each run in a 4 GB scope):

  • python -I -m unittest discover -s tests/semantic -p test_wave64_halves.py: 105 OK (includes the 4 new ScalarSideEffect tests).
  • With test_wave64_halves_soundness, tests/test_wave64_halves_fixtures, test_wave64_graphics_scan, test_wave64_pipeline_audit, the docs tests, test_text_encoding, test_wave64_cross_half, test_wave64_emulate_opt: 222 passed, 73 subtests. compileall and git diff --check clean. I did not run the whole tests/semantic suite for this PR.
  • Negative control, this head with tools/wave64_halves.py restored to 3faac557: the 5 effect cases of test_scalar_effects_in_the_run_side_are_tier_c (s_store_dword, s_buffer_store_dword, s_atomic_add, s_buffer_atomic_add, s_sendmsg) fail; the other tests pass.
  • Mutant, the scan allowed to cross the join (if b == join or b in seen -> if b in seen): test_scalar_store_in_the_join_is_not_part_of_the_voted_region fails, so the boundary an earlier review found unpinned is now pinned.

GPU, no regression:

  • run_gpu_tests.py full suite, 780M native 202/217 (15 skipped), 4070 native 170/217 (47 skipped), 4070 LEONIDA_W64_EMULATE=1 201/217 (16 skipped), 0 failed. These are the same numbers and the same per-fixture verdicts as my run of main 3faac557.
  • runtime/test/shaders/w64_graphics.py on shaders built by build.py from this head: 780M 27 ok, 0 SKIP, 0 failed (the VS/GS fixtures use RADV_PERFTEST=gewave32 set by the script; the PS fixtures 64 vs 32 by required subgroup size). 4070: 27 ok, 0 SKIP, with the 780M's 64-lane images as the reference (W64G_SAVE_REF on the 780M, W64G_REF on the 4070). The same commands on main also give 27 ok on each.
  • All 242 translated .spv files and the whole index.json (tier, reasons, idioms) are byte/field-identical between main and this head for every build.py shader, so no existing fixture changes tier.

What the tests do and do not show:

  • The new rule is checked only on hand-built blocks (the test says the translator does not lower these scalar writes), so no GPU fixture can reach tier C scalar-side-effect, and the GPU runs above only show that the existing tiers are unchanged. The unit tests and the translator's analysis agree by construction; I did not find an independent hardware check of "runs once per wave, twice for two halves".
  • Scope: the scan runs only for the non-EXEC votes (vccz/vccnz, SCC). With the same blocks run through wave64_halves.analyse, an s_store_dword on the run side of s_cbranch_vccnz is tier C scalar-side-effect, while the same store on the run side of s_cbranch_execnz, or in straight-line code, stays tier A. The design row says the rule does not prove scalar effects elsewhere are partition-invariant, so this is documented, not a defect; I mention it because the earlier review asked the same.
  • No hardware claim in this PR; the 780M being RDNA3 does not matter here.

Synthetic inputs only, no game data. AI-assisted.

@cxchhh

cxchhh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 13eb929 on Tesla V100 (Volta) + RTX 4090 (Ada), Linux: pass

Machines: Tesla V100-SXM2-32GB (Volta, 32-wide, NVIDIA 580.95.05, Ubuntu 24.04) and RTX 4090 (Ada, 32-wide, NVIDIA 570.153.02 user-space Vulkan driver in a Linux container, Vulkan 1.4.303). The 4090 has mesh shaders and fragment barycentrics, so it runs the mesh/barycentric tests the V100 skips. Each run is the PR diff applied to main 3faac557 (clean apply) and compared with unchanged main on the same machine. GPU suite: scripts/run_gpu_tests.py native, and with LEONIDA_W64_EMULATE=1 (V100 also LEONIDA_BARY_FALLBACK=1). Baseline main: V100 161/217 native, 194/217 emulated; 4090 167/217 native, 198/217 emulated; 0 failures anywhere. tests/semantic full suite: main has 6245 tests with the 5 known test_loop_ballot_barrier emulated cases failing (plus one test_vcmp16_opsel spirv-val error from my PATH, identical on every tree).

  • test_wave64_halves.py: 105 OK (main has 101). The PR's test file run against main's tools/wave64_halves.py gives 5 failures.
  • tests/semantic: 6249 tests; the failure list is identical to main's.
  • GPU suite: same as main on both GPUs (V100 161/194, 4090 167/198, 0 failures). The PR is Python-only, so this just confirms nothing else moved.

The 32-wide half only; the AMD half still needs someone else.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested ec86cd0 merged with main 561b65a on Linux (WSL2), CPython 3.12.16, CPU only: pass.

  • tests/semantic/test_wave64_halves.py: 129/129.
  • Negative control: with main's tools/wave64_halves.py the same file fails (failures=5).

@AwkGrep256

Copy link
Copy Markdown
Contributor

Tested ec86cd0 against main 561b65a8 on CachyOS, Python 3.14, LLVM 23.1.5: pass.

  • CPU: tests/semantic/test_wave64_halves*.py OK. Negative control: test_wave64_halves.py with main's tools/wave64_halves.py has 5 failures.
  • Corpus (my own 1.0.2.1 copy, all 26,503 shaders, --wave64-emulate, counts only): 26,503 translated and 26,503 pass spirv-val, as on main. The wave64 tiers are identical (A 5,059 / B 101 / C 8,245; 13,098 not wave64), no first reason changes, and every SPIR-V module is byte-identical to main's. So no shader in 1.0.2.1 has the scalar-side-effect-in-a-voted-branch shape this refuses; the rule is a guard with no cost on the corpus.

AI-assisted.

tools/wave64_halves.py treats s_store_*/s_buffer_store_*, scalar
atomics and non-GS s_sendmsg in the run side as visible effects:
two 32-lane halves would run them twice when both take the branch.
New tier C reason scalar-side-effect; GS emit/cut/done stays output.

AI-assisted.
@JRamos1993

Copy link
Copy Markdown
Contributor

Tested f25949a6 merged onto main 1cc6e3c1 on Windows 11, CPython 3.14.3, CPU only: pass.

  • python -I -m unittest discover -s tests/semantic -p test_wave64_halves.py: 129 tests OK.
  • Negative control (tools/wave64_halves.py from main, the PR's tests kept): tests/semantic/test_wave64_halves.py 129 tests FAILED (failures=5).
  • py_compile on the 2 changed Python files: OK; git diff --check: clean.

No game files. AI-assisted (Claude Code).

@MuratK20

Copy link
Copy Markdown

Tested f25949a merged on main 1cc6e3c, Windows 11, Python 3.13.5: pass.

  • tests/semantic/test_wave64_halves.py: 129 OK (main: 125). With main's tools/wave64_halves.py, the new test_scalar_effects_in_the_run_side_are_tier_c fails for all 5 ops (s_store_dword, s_buffer_store_dword, s_atomic_add, s_buffer_atomic_add, s_sendmsg), so it tests the fix.
  • Merges cleanly with wave64_halves: an SGPR-pair mask with one half overwritten is mask-half #4624 (same two files); together 130 OK. Full unittest discover -s tests/semantic with both: 5826 tests, 3 failures, 6 skipped; main alone: 5821 tests, the same 3 failures (pre-existing on Windows), 6 skipped.
  • scripts/run_gpu_tests.py on an RDNA2 iGPU (gfx1036, 1002:13c0, AMD 32.0.13036.4): 214/235 pass, identical to main.

AI-assisted (Claude Code).

@TG0000

TG0000 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested f25949a on AMD Radeon RX 6800 (RDNA2 gfx1030, AMD 26.11.2, Windows 11): pass

I trial-merged it onto main 924b1465 (clean merge). It changes only Python and docs, so the runtime was not rebuilt.

python -I scripts/run_gpu_tests.py --build build --work <scratch> --llvm-mc <llvm-mc.exe>
python -m pytest -q tests/semantic/test_wave64_halves.py
  • compileall on make_game.py, tools, tests and scripts: ok
  • GPU suite: 221/239 passed, 17 skipped, 1 failed (ms_wave_info_s3, which also fails on main, see below). The device line reports AMD Radeon RX 6800 (subgroup 32..64), and the 32-wide wave64 VS/PS/GS line reports tier A: 1, tier C: 1.
  • tests/semantic/test_wave64_halves.py: 129 passed, 25 subtests passed, 0 failed (11.2 s)

Setup: Vulkan test targets built once from main 924b1465 with llvm-mingw 20261117 (clang++), Ninja, -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF. llvm-mc and spirv-val from MSYS2 ucrt64, Python 3.12.10. No Vulkan validation layer was loaded. Repo tests only, no game files.

Pre-existing on main, not from this PR: ms_wave_info_s3 fails on this card with at (0,0): got (-1.0000,-1.0000,-1.0000,-1.0000), want (0.0078,0.0078,0.5,1.0). It failed 3 out of 3 times on bare main 924b1465 (--filter ms_wave_info). host_adapter_test also does not compile on main with this toolchain (d3d12_com.h:395: unknown type name 'ID3D12GraphicsCommandList8'), and the GPU runner does not use it.

AI-assisted (Claude Code).

@lunarminus

Copy link
Copy Markdown

Tested f25949a6 merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • Tree: d0835dd9 is an ancestor of this head, so the merge was a fast-forward. The tree tested is f25949a6 itself (main 1cc6e3c1 plus this commit). The PR changes nothing under runtime/, so I used the test programs built at d0835dd9.
  • CPU:
    • python -I -m unittest discover -s tests/semantic -p 'test_wave64_halves*.py': 164 OK.
    • tests/semantic/test_wave64_halves.py on its own: 129 OK.
    • Negative control with 1cc6e3c1's tools/wave64_halves.py and the PR's tests: failures=5, all subtests of test_scalar_effects_in_the_run_side_are_tier_c (s_store_dword, s_buffer_store_dword, s_atomic_add, s_buffer_atomic_add, s_sendmsg).
    • compileall and git diff --check are clean.
  • scripts/run_gpu_tests.py, native and LEONIDA_W64_EMULATE=1: 214/235 passed, 16 skipped, 5 failed in each mode. The failures are cs_bvh, cs_bvh32, ps_sample_c, ps_sample_c_b and ps_sample_implicit_uint; in the ps_sample_* ones vk_texture_test prints its usage text and exits 2.
    • Compared per test with d0835dd9 without the PR (234 names, since cs_fmt_d16_xyz is listed twice): 207 tests keep their verdict. cs_bvh and cs_bvh32 go from PASS to FAIL. 25 tests were added on main after d0835dd9 (none by this PR): 20 PASS, 2 SKIP, 3 FAIL (the ps_sample_* ones).
    • Control, main 1cc6e3c1 without the PR, same d0835dd9 test programs: 214/235 in both modes, with the same verdict as this head for every test, the 5 failures included. So the failures come from the old test programs running newer fixtures, not from this PR.
    • With a runtime build whose runtime/ (outside runtime/test/shaders) matches this head, the five pass in both modes (--filter cs_bvh 2/2, --filter ps_sample_ 6/6).
  • runtime/test/shaders/build.py: 264/264 translated and spirv-val clean. Wave64 graphics tiers are A 11 / B 8 / C 13. The output, including index.json, is identical to 1cc6e3c1's.
  • runtime/test/shaders/w64_graphics.py: 29 ok, 0 SKIP, 0 failed on this head, and the same on 1cc6e3c1.
  • As earlier testers noted, no GPU fixture reaches the new tier C scalar-side-effect. The GPU runs only show that existing tiers and results are unchanged.

Synthetic inputs only, no game files.

AI-assisted (Claude Code).

@Spggety

Spggety commented Nov 23, 2026

Copy link
Copy Markdown

Tested f25949a6 on AMD Radeon RX 6600 XT (Navi 23, gfx1032, RDNA2, discrete), AMD proprietary driver 24.10.1 (32.0.12019.1028, Vulkan 1.3.292), subgroup 32..64, Windows 11 (build 22631). Toolchain: MSVC 14.44, Vulkan SDK 1.4.363.1, llvm-mc from rocm-sdk-core 10.0.0, Python 3.11.9. Pass.

  • tests/semantic/test_wave64_halves.py: 129 tests, OK.
  • scripts/run_gpu_tests.py (native wave64, PR merged onto main 1cc6e3c1, the runtime build's commit): 213/235 passed, 20 skipped, the same results as main itself (213/235, 20 skipped). The two failures, ms_clip and ms_wave_info_s3, are the same on main 1cc6e3c1 without this PR (3/3 reruns): on this driver vk_harness exits with 0xC0000005 before any readback, so the FAIL line has only the device line. They are not from this PR.

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

@wavehs

wavehs commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested f25949a6f on Apple M3 Pro (macOS arm64, CPython 3.15.2, CPU only, hand-built blocks): pass.

  • python3 -I -B tests/semantic/test_wave64_halves.py -> 129 tests, OK (origin/main has 125 in that file, so the PR adds 4). All test_wave64*.py -> 238, OK; tests/test_lane_masks.py OK.
  • Negative control on origin/main dde82f27e (main's tools/wave64_halves.py, this PR's test kept): FAILED (failures=5) — the five effect subcases report tier A instead of C (the output diff is the -/+ A/C pair), so the new test does exercise the new scan. test_plain_skip_is_tier_a, test_gs_sendmsg_is_tier_a and the join-boundary case stay green on main, as they must.
  • Full suite A/B (python -I scripts/run_semantic_tests.py tests/semantic), because wave64_halves.analyse is on the translator's path for wave64 VS/PS/GS (tools/rdna2spirv.py:15215): this head alone 433 files / 5,825 tests with test_float_nan_fract failing 3; origin/main dde82f27e 447 files / 5,956 tests with the two pre-existing macOS failures (test_image_atomics_guard 47, test_image_store_d16 1); head merged into origin/main 447 files / 5,960 tests, only those two pre-existing failures and test_float_nan_fract green. The head-alone test_float_nan_fract failure is not this PR: the same 3 failures reproduce at its merge-base 1cc6e3c12, and main fixed it in between.
  • Merges cleanly onto origin/main dde82f27e (only tools/wave64_halves.py auto-merges). compileall, python -I scripts/check_no_game_data.py on the three changed files, git diff --check and test_docs_design_rows.py/test_docs_table_rows.py are clean; the new test imports wave64_halves so tests/test_semantic_translator_use.py stays green.

Code read: folding self.past_jumps(skip) into join is behaviour-preserving (skip is not None already guarded the old call and reaches(run, None, n) could not be true), and run_side_scalar_effect stops exactly at join, guards loops with seen, and cannot affect the earlier tier-A path because it only runs after ok is decided. Two notes, neither blocking:

  1. s_sendmsghalt is not covered. Only op == "s_sendmsg" is special-cased, but llvm-mc 23.1.5 assembles s_sendmsghalt 1 for gfx1030 (0x01,0x00,0x91,0xbf) and tools/rdna2_decode.py:761 already knows the pair, so a halt-sendmsg inside a voted run region would still be tier A while its message is per-wave. If you consider it a side effect, op.startswith("s_sendmsg") covers both and keeps the GS exemption.
  2. The sites entry names whichever effect the DFS pops first, not the lowest-pc one in the region (work.extend(self.succ[b]) with pop()), so with two effects in one run region the reported pc/op depends on block order rather than on program order. Deterministic per input, just not ordered; sorting self.succ[b] or keeping the minimum pc would make the report canonical if you want it to read like the other tier-C sites.

AI-assisted.

Raxstreams added a commit to Raxstreams/Leonida that referenced this pull request Nov 23, 2026
wave64: scalar side effects in a voted branch refuse tier A (SHADER-742)

Independent review: ItsNotRexed#4156 (comment)

Fork integration. AI-assisted (Codex).
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.