Skip to content

rdna2spirv: exec_half_write extracts per-lane bit for computed scalar values (SHADER-1264) - #8424

Open
Tortoche wants to merge 2 commits into
ItsNotRexed:mainfrom
Tortoche:fix/shader-1264-exec-half-computed-scalar
Open

Tortoche wants to merge 2 commits into
ItsNotRexed:mainfrom
Tortoche:fix/shader-1264-exec-half-computed-scalar

Conversation

@Tortoche

@Tortoche Tortoche commented Nov 23, 2026 •

Copy link
Copy Markdown

What this does

When a computed non-mask scalar value was written to exec_lo or exec_hi (such as via s_add_u32, s_lshl_b32, or scalar memory loads through Gen.dst), exec_half_write tested (val != 0) which evaluated to true across all lanes of that wave half, turning on lanes that should have remained inactive.

Extract each lane's corresponding bit (val >> (rel & 31)) & 1, unifying it with the immediate constant path.

Testing

  • Adds regression test tests/semantic/test_wave64_exec_half_computed.py covering computed scalar writes to exec_lo and exec_hi in wave64 mode.
  • Verified negative control: fails on previous implementation (AssertionError: 4294967295 != 5), passes cleanly with this fix.
  • All 76 exec tests in tests/semantic/ pass.
  • scripts/check_no_game_data.py: pass.
  • Synthetic inputs only, no game data.
  • AI-assisted.

… values (SHADER-1264)

When a computed non-mask scalar value was written to exec_lo or exec_hi
(such as via s_add_u32, s_lshl_b32, or scalar loads through Gen.dst),
exec_half_write tested (val != 0) which evaluated to true across all lanes
of that wave half, turning on lanes that should have remained inactive.

Extract each lane's corresponding bit (val >> (rel & 31)) & 1, matching
the immediate constant path. Add regression test covering computed scalar
writes to exec_lo and exec_hi in wave64 mode.

@leoleahy leoleahy 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.

AI-assisted.

Independently verified on Windows 11 (Python 3.14.8, CPU-only) at 5fcb226f:

  • Merge cleanliness against upstream/main (dde82f27): git merge-tree --write-tree clean, git diff --check clean, python -I -m compileall -q clean.
  • Added semantic suite (python -I -m unittest discover -s tests/semantic -p test_wave64_exec_half_computed.py): 3/3 OK on HEAD; negative control on dde82f27 fails all 3/3 (producing 4294967295 instead of 5, 10, and 0x10).
  • Adjacent wave64 semantic suites on HEAD: test_wave64_vcc_half_write.py 7/7 OK, test_wave64_subgroup_ops.py 6/6 OK.
  • Audited all 5 exec_half_write call sites in tools/rdna2spirv.py: per-lane mask callers pass 0 / 0xFFFFFFFF (where (val >> (rel & 31)) & 1 != 0 matches val != 0 identically), while computed scalar bitmask callers now extract each lane's own bit properly.

Looks solid and ready to merge.

@morodirule

Copy link
Copy Markdown

Tested 5fcb226 on Arch Linux, Python 3.14.10, CPU only: pass — new tests/semantic/test_wave64_exec_half_computed.py 3/3 OK. Negative control: base translator → all 3 fail; restored, green again. No game files, no GPU. AI-assisted.

@nonverifiedperson

Copy link
Copy Markdown
Contributor

GPU and silicon check of 5fcb226 (up to date with main): with this PR the translated shader matches gfx1036 hardware. On main it doesn't.

I used a wave64 compute shader (group 64,1,1, --require-wave64). It does four computed SALU writes to one EXEC half and marks each lane that runs a following v_mov_b32. Each lane then stores its marks, and the table shows them as lo/hi bitmaps:

setup gfx1036 silicon (hw_oracle, wave64) main translator, Radeon this PR, Radeon
exec_hi = 0x12345678, s_add_u32 exec_lo, s4(=5), 0 lo 0x00000005 hi 0x12345678 lo 0xffffffff hi 0x12345678 lo 0x00000005 hi 0x12345678
exec_lo = 0x87654321, s_add_u32 exec_hi, s4(=10), 0 lo 0x87654321 hi 0x0000000a lo 0x87654321 hi 0xffffffff lo 0x87654321 hi 0x0000000a
exec_hi = 0, s_lshl_b32 exec_lo, s4(=1), 4 lo 0x00000010 hi 0 lo 0xffffffff hi 0 lo 0x00000010 hi 0
exec_hi = 0, s_add_u32 exec_lo, s4(=0xfffffffe), 1 lo 0xffffffff hi 0 lo 0xffffffff hi 0 lo 0xffffffff hi 0

The CPU interpreter gives the same words as the Radeon GPU for both translators. The other three writes to a mask still go through exec_half_write: s_mov_b32 from a mask SGPR, put_mask, and the _wrexec_b32 halves. They pass the all-ones/zero per-lane form, so (val >> (rel & 31)) & 1 gives the same lanes as the old val != 0.

Tests:

  • python -I scripts/run_semantic_tests.py tests/semantic: 448 files, 5959 tests. 3 files fail: test_image_atomics_guard, test_image_cube_store_glc and test_image_store_d16. These are the same 3 that fail on main, and tests/semantic: three image test files red on main (stale after #4473 and #6805; LLVM_MC on Windows) #7284 fixes them.
  • python -m unittest discover -s tests/semantic -p test_wave64_exec_half_computed.py: 3 pass.
  • scripts/run_gpu_tests.py --filter exec with this PR's translator: 6/6 pass on the Radeon, including cs_w64x_andn2_exec and cs_w64x_saveexec_b64. On the RTX 5070 Ti, 4/6 pass and the 2 wave64 fixtures skip because the card has no 64-wide subgroup.

A pitfall in case anyone turns this into a GPU fixture: read the marks back per lane, or through s_bcnt1/s_ff1. A v_mov_b32 v1, s20 of a v_cmp result reads lane 0's per-lane copy of the mask (all-ones or zero), not the 32-bit ballot. My first readback did that and looked like a failure of this PR.

Windows 10 22H2, AMD Radeon iGPU (gfx1036, driver 32.0.13036.4), NVIDIA RTX 5070 Ti (driver 621.35), Vulkan SDK 1.4.363. Synthetic values only, no game files. AI-assisted (Claude Code).

@tupacfan04 tupacfan04 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.

The new wave64 bit extraction is correct: exec_half_write() takes (word >> (rel & 31)) & 1, half 0/1 preserves the other 32 lanes, the register-mask representation still works, the constant path keeps the Intel workaround, and the wave64 tests cover s_add_u32 into both halves and s_lshl_b32 into exec_lo (they fail on the old val != 0). The wave32 path is still broken:

tools/rdna2spirv.py:1548-1552 only sends wave64 EXEC writes to exec_half_write():

if self.wave64 and a["k"] == "special" and a["t"] in ("exec_lo", "exec_hi"):
    self.exec_half_write(1 if a["t"] == "exec_hi" else 0, val)
    return
if a["k"] == "special" and a["t"] in ("exec_lo", "exec"):
    self.set_exec(val)
    return

In wave32, a computed scalar from s_add_u32, s_lshl_b32, etc. goes to set_exec(), whose tmp_bool_nz() is OpINotEqual %bool val 0 (:5578-5581), so a uniform value 5 activates every lane instead of lanes 0 and 2. The paths hit this (s_add_u32 → dst() at :9485; s_lshl_b32 → _store_b32_mask_dst/dst() at :11372/:5642). A wave32 shader with s_mov_b32 exec_lo, 0, s_mov_b32 s4, 5, s_add_u32 exec_lo, s4, 0 should leave exec_lo = 5, but still leaves 0xFFFFFFFF; s_lshl_b32 exec_lo, s4, 4 is the same.

Test gap: tests/semantic/test_wave64_exec_half_computed.py is wave64-only (FSSM_64, run_workgroup(..., 64, 64), all cases use wave64 halves); there is no wave32 FSSM_32/32-thread case for s_add_u32 exec_lo/s_lshl_b32 exec_lo, so the wave32 path is unpinned. The body's “scalar memory loads through Gen.dst” is not in the committed test, and the values 5/10/0x10 only exercise bits 0-4 (no bit 31).

Fix: use the bit extraction for wave32 exec_lo too (shared helper with exec_half_write), and add wave32 s_add/s_lshl cases plus a bit-31 case. Synthetic only; no game files. AI-assisted (OpenCode).

@KoertLichtendonk

Copy link
Copy Markdown
Contributor

Coordinator note: SHADER-1264 already has an open PR, #8353 by @HDFreitas (opened 18:32 UTC), so this looks like a duplicate. Please compare the two and either close this one or say here what it adds. The maintainer decides which one is merged.

@rojasruiz

Copy link
Copy Markdown

Tested 5fcb226 merged onto main bf69af7 (clean merge) on NVIDIA GeForce RTX 3080 (32-wide subgroups), driver 615.78.08, Linux 7.2.15; llvm-mc 23.1.3, SPIRV-Tools v2026.4: pass, no regression.

  • run_gpu_tests.py with LEONIDA_W64_EMULATE=1 (every wave64 module through the emulated exec_half_write path): 223/241 passed, 17 skipped. main gives the same, with the same single failure (the known ms_wave_info_s3).
  • Default flags: 192/241, 48 skipped, identical to main.
  • tests/semantic/test_wave64_exec_half_computed.py: 3 OK. scripts/run_semantic_tests.py tests/semantic: 448 files / 5,960 tests, with only the 2 files already red on main failing (test_image_atomics_guard, test_image_store_d16), at the same counts.
  • check_no_game_data.py on both files: clean.

No GPU fixture writes a computed (non-mask) scalar to exec_lo/exec_hi yet, so on hardware this shows no side effects rather than the fix itself. The CPU test is what covers the new path.

AI-assisted (Claude Code).

@Tortoche

Copy link
Copy Markdown
Author

Thanks for the review @tupacfan04 and @leoleahy!

I have updated the PR to address your suggestion:

  • Unified the exec_lo, exec_hi, and wave32 exec handling in Gen.dst() to route through exec_half_write(0, val) for wave32 as well.
  • Added wave32 test coverage (Wave32ExecComputedScalarTests) covering s_add_u32 to exec_lo, s_add_u32 directly to exec, and shift bit 31 (s_lshl_b32 with shift 31).
  • Added wave64 bit 31 shift coverage to Wave64ExecHalfComputedScalarTests.

All 7 test cases pass cleanly.

@jacob-rowlands

Copy link
Copy Markdown

Tested 1d93673c5 merged onto main 867d922f0, Linux (CachyOS, Python 3.14.10), no game files: one existing test now fails, introduced by the latest commit.

python3 -I tests/semantic/test_active_cache.py:

Tree Result
main 867d922f0 OK (3 runs out of 3)
this PR at 5fcb226ff (the head the earlier checks used), merged onto the same main OK
this PR at 1d93673c5, merged onto the same main FAILED (3 runs out of 3): test_divergent_loop_loads_active_once_per_block, AssertionError: 7 not less than or equal to 6 : expected cached %active loads, got 7

The PR is based on dde82f27e, older than this main, so the merge brings in nothing but the PR's own two files.

The cause looks like 1d93673c5's change to Gen.dst. Wave32 writes to exec_lo/exec used to go through set_exec and now go through exec_half_write. The test's loop ends each iteration with s_or_b32 exec_lo, exec_lo, s6, and on this path the per-block %active cache costs one extra load. The results are still exact: with only the load-count assertion removed, the rest of the test passes on all 32 lanes. So this is a codegen regression caught by the existing guard, not a wrong value. Either keeping wave32 exec_lo/exec writes on set_exec when the value is a lane mask, or having exec_half_write reuse set_exec's cache handling, would likely restore it.

Everything else matches main: test_wave64_exec_half_computed.py passes, the semantic suite otherwise has the same 2 files failing as main, and run_gpu_tests.py gives the same results as main on a Ryzen 5 7600X iGPU (RADV, Mesa 26.3.1) and an RTX 3080 (NVIDIA 620.73.04), with and without LEONIDA_W64_EMULATE=1.

AI-assisted (Claude Code).

@trigger337

Copy link
Copy Markdown

Tested 1d93673 on AMD Radeon RX 6900 XT (RADV Navi 21, Mesa 26.2.5, Linux 7.3.1 CachyOS): pass

  • python -I tests/semantic/test_wave64_exec_half_computed.py: 7/7 passed.
  • python scripts/run_gpu_tests.py --build runtime/build/linux: 224/241 passed, 16 skipped, 0 failures.
  • scripts/check_no_game_data.py: clean.

AI-assisted: yes
agent: yes

@N4use4tic

Copy link
Copy Markdown

Tested 1d93673 on Windows 11, Python 3.14.4, no GPU or LLVM: pass.
From tests/semantic: test_wave64_exec_half_computed (7 tests), test_wave32_bfm64_data (6) and test_wave64_subgroup_ops (6) OK; tests/test_lane_masks.py ok.
test_image_atomics_guard and test_image_store_d16 are still red, as on main (#7284).
No merge conflicts with #8448, #8409 or #8264.
Code not reviewed beyond the test run.

@CourtyardGames

Copy link
Copy Markdown

Tested 1d93673 on AMD Radeon Graphics (Ryzen 5 7600X iGPU, RDNA2), AMD 32.0.21042.62 / AMDVLK 2.0.353, Vulkan 1.4.315, Windows 11, MSVC 14.51: pass

PR head is on main dde82f2; the PR does not touch runtime/, so the runtime was the existing main build.

  • tests/semantic/test_wave64_exec_half_computed.py: 7/7 OK.
  • Control: the same test with main's tools/rdna2spirv.py swapped in: 7/7 fail (all 4 wave64 and 3 wave32 cases), so the PR changes the outcome.
  • scripts/run_gpu_tests.py on the iGPU (device reported "AMD Radeon(TM) Graphics, subgroup 32..64"): native 218/241 passed, 23 skipped, 0 failed; LEONIDA_W64_EMULATE=1: 218/241 passed, 23 skipped, 0 failed.
  • Other tests/semantic/test_wave64_*.py (11 files): all OK.

Note: this head (1d93673) is newer than the one the earlier GPU checks covered (5fcb226). AI-assisted.

@matheusfermiano-source

Copy link
Copy Markdown

Tested 1d93673c5 (the PR's diff applied on main 867d922f0), full python -I scripts/run_gpu_tests.py on both GPUs of one laptop, each compared with main on the same machine and binaries, CachyOS Linux: pass.

GPU Driver main this PR Difference
AMD Radeon 660M (RDNA2 iGPU, gfx1035, Ryzen 5 7535HS), subgroup 32..64 RADV, Mesa 26.3.1 225/241 passed, 16 skipped 225/241 passed, 16 skipped same results as main
NVIDIA GeForce RTX 3050 Laptop (Ampere), subgroup 32 NVIDIA 620.73.04 192/241 passed, 48 skipped 192/241 passed, 48 skipped fails on main too: ms_wave_info_s3 (#6172)
  • Radeon 660M wave64 checks: LEONIDA_W64_EMULATE=1 run_gpu_tests.py 225/241 passed, 16 skipped (main: 225/241 passed, 16 skipped); runtime/test/shaders/w64_graphics.py 29 ok, 0 SKIP, 0 other.

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

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 1d93673c on Windows Server 2022, CPython 3.13.12: pass

  • python -I -m unittest discover -s tests/semantic -p "test_wave64_exec_half_computed.py" -> OK

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

@IxMxAMAR

Copy link
Copy Markdown

Checked 1d93673c on Windows 11 Pro 26200, CPython 3.12.10, with an RX 9070 XT (RDNA4, AMD 26.11.2) and Intel Graphics (Core Ultra 5 225, Xe-LPG, 101.8860).

  • tests/semantic/test_wave64_exec_half_computed.py: OK at the head. With the base's tools/rdna2spirv.py (dde82f27), 7 of its tests fail, so it catches what it describes.
  • scripts/run_gpu_tests.py, full suite, with this PR's translator and with the base's (runner binaries from a main 867d922f build):
GPU, LEONIDA_W64_EMULATE base this PR
RX 9070 XT, 0 (native wave64) 225 PASS, 16 SKIP the same
RX 9070 XT, 1 225 PASS, 16 SKIP the same
Intel Graphics, 1 206 PASS, 1 FAIL, 34 SKIP the same

Every fixture has the same result with and without the change. The one Intel failure is ms_wave_info_s3, which fails the same way on the base (#6172). cs_exec_const and cs_exec64 pass on both GPUs, so the shift-and-mask path still holds on Xe-LPG now that computed values go through it too.

No game files. AI-assisted.

@lordra9-svg

Copy link
Copy Markdown

Independent confirmation of the regression @jacob-rowlands reported, on the PR head as filed (no merge onto newer main), Linux (Bazzite 45), Python 3.15.2, standard library only, no GPU, no game files:

python3 -I tests/semantic/test_active_cache.py

tree result
1d93673c5 (this head) FAILED, 3 runs out of 3
5fcb226ff (previous head) OK, 3 runs out of 3
main 867d922f0 OK, 3 runs out of 3

The failure is deterministic:

FAIL: test_divergent_loop_loads_active_once_per_block
  File "tests/semantic/test_active_cache.py", line 166, in test_divergent_loop_loads_active_once_per_block
    self.assertLessEqual(total_loads, 6, f"expected cached %active loads, got {total_loads}")
AssertionError: 7 not less than or equal to 6 : expected cached %active loads, got 7

So the regression is between 5fcb226ff and 1d93673c5, i.e. from the wave32 unification commit (Gen.dst() routing wave32 exec through exec_half_write(0, val)), not from main or the test environment.

AI-assisted (OpenCode).

@slint6614-dev

Copy link
Copy Markdown
Contributor

AMD RDNA2 GPU-suite check of 1d93673c5 (AI-assisted): full scripts/run_gpu_tests.py with this branch's translator, against the same run on main 867d922f. Ryzen 5 9600X iGPU "AMD Radeon(TM) Graphics" (gfx1036, the console's RDNA2 family), native wave32/wave64, AMD Adrenalin 26.11.2 (Vulkan driver 2.0.353), Windows 11 26300, Python 3.12; test programs from a RelWithDebInfo build of 561b65a (LEONIDA_GPU_TEST_TIMEOUT=60).

Same per-fixture results as main: every fixture all translated and pass spirv-val; main: 222/241 passed, 17 skipped, 2 FAIL (ps_sample_implicit_uint, ps_table_fetch: vk_texture_test usage errors from the older test-program build, identical on both sides). No fixture changes status.

@TheoGegout

Copy link
Copy Markdown

Tested 1d93673c5 merged onto main 867d922f0 (merge d008edfaf) on AMD Radeon RX 6800 XT (RDNA2, Navi 21), AMD proprietary driver 26.10.1 (Vulkan 1.4.315), Windows 11 Pro 26300: pass, no change against main.

Standalone tools built with llvm-mingw 20261117 (clang, Ninja, Release, -DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF, so the MSVC-only runtime targets are not built), llvm-mc 23.1.6 (conda-forge), Vulkan SDK 1.4.341.1. Baseline: the same steps on main 867d922f0.

  • GPU: scripts/run_gpu_tests.py, full suite: 223/241 passed, 17 skipped, 1 failed (ms_wave_info_s3), identical to main, result words included.
  • ctest: 66/67, vk_queue_query_sync failed (see below).
  • tests/semantic/test_wave64_exec_half_computed.py: OK. Negative control: against main's translator it fails (7 failures).

Both non-passing results are on main too, not caused by this PR: ms_wave_info_s3 fails intermittently on this GPU (#6172, SHADER-766), and vk_queue_query_sync failed 13 of 20 standalone reruns on main (progress counter device loss NOT propagated, as in #8426; #6149).

AI-assisted (Claude Code).

@zsigisti

Copy link
Copy Markdown

GPU test for this fix: #8995 adds cs_w32_exec_computed and cs_w64_exec_computed (computed s_lshl/s_add/s_bfm/s_not/s_mov/s_and writes into exec_lo / exec_hi), plus a CPU run of the same words in tests/semantic/test_exec_computed.py. Merged with this PR, both pass on an RTX 5070 (wave64 emulated). On main the computed half turns fully on (8192 8192 8192 … / 8224 8192 16384 16384 …). #8353 and #8424 give identical words on every case, so the fixture doesn't decide between them. If your docs/design.md row needs a GPU check, it can name these tests. 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.