Skip to content

wave64_halves: a buffer access without idxen through a literal V# with ADD_TID_ENABLE reads by lane (SHADER-833) - #4655

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
tedin7:shader-833
Nov 23, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
tedin7:shader-833

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-833 (#4571 (comment))

What and why

Finding by @shdann (#4571): tools/wave64_halves.py gave tier A to a buffer_load without idxen through a V# with ADD_TID_ENABLE. Without idxen that bit adds the wave lane to the index (idxen ignores it, docs/design.md "Swizzled buffer addressing"), so the loaded value depends on how the wave is cut: lane 40 reads index 40 in a wave64 and index 8 in a half.

  • tools/wave64_halves.py: a MUBUF/MTBUF access with no idxen whose V# word3 is a literal (written earlier in the block by the same scalar folds rdna2spirv records in sgpr_imm: s_mov_b32/s_mov_b64 (word3 as the high half of a pair), s_movk_i32, s_pack_*, s_bfm_b32, s_not_b32, s_and/lshl/lshr_b32, s_mul_i32; mirrored in Analysis.literal_sgpr because the analysis runs before the translator emits a block, so its sgpr_imm cannot be imported or read) with bit 23 set gets the raw lane-id taint: the load result, a store's address and an atomic's address. Reason is the existing lane-id, so no new reason code. A literal with the bit clear, and every access with idxen, are unchanged.
  • docs/design.md, SHADER-10 row: the run-time V# assumption (tiers A and B take ADD_TID_ENABLE as 0 without idxen through a run-time V#), credit to @shdann, and the follow-up (count bound V#s with bit 23 at run time, needs the game).

Tested with numbers

RunPod pod only. test_wave64_halves.py, test_wave64_halves_soundness.py, test_wave64_halves_fixtures.py, test_wave64_graphics_scan.py together:

  • before (origin/main + the new tests): 160 passed, 3 failed (the ones that must fail). First fix commit with the new tests: the s_mov_b64 case fails.
  • after (this commit): 165 passed, 18 subtests passed, 0 failed.

New class AddTidBuffer (8 tests, incl. s_mov_b64 / s_pack / s_bfm word3 and offen, tbuffer load, buffer_store_format with bit set -> C, clear -> A): literal with bit set is tier C lane-id (buffer_load_dword, buffer_load_format_x); bit clear is tier A; idxen with the bit set is tier A; literal copied through another SGPR; store and atomic with bit set are C, with bit clear A; a run-time V# stays A (the documented assumption).

Not covered

  • Classification only: the wave interpreter on main cannot load from a physical-storage-buffer pointer (OpLoad of a "psb" access chain is unhandled), so there is no 64 against 2x32 run of a buffer load. wave64_halves: a buffer_load with idxen at a wave-uniform address gives a wave-uniform VGPR (new SHADER item) #4630 (read-only memory in spirv_wave_interp.py) would allow that test as a follow-up.

  • Run-time V# with the bit set: undecidable from the code, documented as an assumption.

  • Folds rdna2spirv has that are not mirrored (s_abs, s_sext, s_min/max, s_add/sub, s_xor/andn2 family, s_bfe, s_absdiff, s_lshlN_add): such a word3 counts as run-time. The bit counts even with SWIZZLE_ENABLE clear (conservative).

  • Corpus census not re-measured with this rule (needs the game); the census numbers in design.md predate it and may change.

  • Reviewed by an independent model (DeepSeek) before opening: it found that word3 literals built with s_mov_b64, s_pack_* or s_bfm_* were missed; fixed and pinned.

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

…dxen through a literal V# with ADD_TID_ENABLE (SHADER-833)
…s_pack, s_bfm, ...), pin offen/tbuffer/store_format (SHADER-833)
@Kev-Ball

Copy link
Copy Markdown

Tested f502d1fc on an NVIDIA GeForce RTX 3080 Ti (32-lane subgroups), driver 620.73.04, CachyOS Linux 7.3.5-2-cachyos. I rebuilt the Vulkan harnesses from this revision and selected the NVIDIA device explicitly.

The 8 AddTidBuffer classification tests passed. On the GPU, scripts/run_gpu_tests.py --filter cs_buf_swizzle --require-pass validated and passed: the no-idxen literal ADD_TID store left out[6:8] = [0xbeef0000, 0xbeef0001], as expected for lanes 0 and 1. The graphics regression run (build.py, then w64_graphics.py) validated 242/242 modules and reported 15 tier-A/B fixtures OK, 12 tier-C skips. This covers the 32-lane side; no native wave64 reference was available on this card.

AI-assisted verification with synthetic inputs.

@theswiss24

Copy link
Copy Markdown

Tested f502d1fc merged onto main 3eb4410b (clean) on two GPUs in a Dell Latitude 5501 (Linux Mint 22.3), test programs built from main 3eb4410b (this PR changes no C++), llvm-mc 20.1.2, LEONIDA_W64_EMULATE=1: pass. Every test has the same result as main on each device:

GPU driver run_gpu_tests.py
NVIDIA MX150 (Pascal) 580.178.04 191/217 passed, 26 skipped, 0 failed
Intel UHD 630 (Gen9.5) Mesa ANV 25.2.8 184/217 passed, 31 skipped, 2 failed, the same 2 as main (cs_fmt_int_narrow = TEST-1000, and cs_signed_zero_nan, the known Mesa 25.2 NIR issue)

No game files.

Tested and written by Claude (Claude Code), posting from @theswiss24's account.

@kapitche

Copy link
Copy Markdown
Contributor

Tested f502d1f merged with main 2d3369a on WSL2 Ubuntu (Python 3.12.16) and, merged with main 3eb4410, on native Windows 11 (Python 3.13.1): pass.

  • tests/semantic/test_wave64_halves.py: 109 tests OK on both.
  • Negative control (tools/wave64_halves.py and docs/design.md from main, PR test kept): 5 failures on both ((A, False) != (C, True) and A != C: a V# whose word3 has ADD_TID_ENABLE read without idxen was tier A).
  • Read: I checked the scalar folds the new literal_sgpr mirrors against the ISA definitions: s_pack_ll/lh/hh_b32_b16 (low half from S0[15:0] or S0[31:16]; high half from S1[15:0] or S1[31:16]), s_bfm_b32 (((1 << S0[4:0]) - 1) << S1[4:0]), s_movk_i32 (16-bit sign extension), s_not_b32 and the s_mov_b64 half selection all match. No issue found. wave64_halves: a lane mask accumulated by lane-local defs is not stale (SHADER-821) #4656 edits the same test file and is itself conflicting with main right now.

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

Tested f502d1f on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

  • Full python -I scripts/run_gpu_tests.py (Linux build of this branch's runtime/, LEONIDA_VK_DEVICE per GPU): 202/217 passed, 15 skipped, 0 failed on both GPUs, with every test's result the same as at the merge base 7b7d73f.
  • python -m unittest discover -s tests/semantic: 6253 run, 3 failures and 2 errors. That is exactly the set at the merge base 7b7d73f, compared by test name: all in test_loop_ballot_barrier (the two errors and test_divergent_loop_wave64_emulate_and_native_cs, fix open in tests: test_loop_ballot_barrier follows #2089's structured wave64 emulation (main red since 1cc7497b) #3995). The PR adds none.

No game files. AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ran this at f502d1fc5 on Windows 11: tests/semantic/test_wave64_halves.py -> 109 tests, OK; tests/semantic/test_wave64_halves_soundness.py -> 30 tests, OK; git diff --check clean.

The analysis now tracks 64-bit literal words through s_mov_b64/s_pack/s_bfm folds for the wave64 halves rule (SHADER-833) and pins the offen/tbuffer/store_format forms it must not treat as lane-uniform. The docs row is updated, and the added cases cover the tracked and rejected forms.

Merge checks: clean with #4624; conflicts with #4619 (tools/wave64_halves.py), #4620 (docs/design.md) and #4630 (docs/design.md, tests/semantic/spirv_wave_interp.py, test_spirv_wave_interp.py). No blocking issue in the change itself.

@Kev-Ball

Copy link
Copy Markdown

The SHADER-833 change leaves the retail 1.0.2.1 tier census unchanged. I checked all 26,503 shaders and compared all 13,405 wave64 VS/PS/GS classifications at 7b7d73f8 and f502d1fc. Both classifiers received the same translator blocks, successors and lane masks.

Stage Tier A Tier B Tier C
VS 1,455 79 702
PS 3,404 27 7,543
GS 195 0 0

Zero shaders changed tier, reason list or idiom list. The new literal ADD_TID_ENABLE rule marked zero instruction sites, including in shaders already classified C. As a control, the same counter marked one site in the synthetic bit-set load without idxen (A → C) and zero in both the bit-clear and idxen controls (A → A).

This closes the static census question for this package. The separate question about bit 23 in descriptors bound at run time still requires a runtime measurement. AI-assisted.

@memorypressure

Copy link
Copy Markdown

Verified at the head: test_wave64_halves passes 109/109 under python -I, translator-use and design-row guards are clean, and the ADD_TID_ENABLE rule ships with its contract-table row as required. Merges cleanly with current main; same-family sequencing note as #4656 (same tool + same semantic test file). The census note honestly says corpus counts were not re-measured. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@epzlo

epzlo commented Nov 23, 2026

Copy link
Copy Markdown

Tested f502d1fc on AMD Radeon RX 7600 (RADV NAVI33, gfx1102), Mesa 26.3.1, CachyOS Linux 7.3.5, Python 3.14.10: pass.

AI-assisted (Claude Code).

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