Skip to content

rdna2spirv: cache per-block %active loads and fast-path no-EXEC dst() writes - #4473

Merged
shayderrr merged 3 commits into
ItsNotRexed:mainfrom
SweatierKey:feat/cache-active-exec
Nov 23, 2026
Merged

shayderrr merged 3 commits into
ItsNotRexed:mainfrom
SweatierKey:feat/cache-active-exec

Conversation

@SweatierKey

Copy link
Copy Markdown
Contributor

Claim: #4421 (comment).

What changes

Measured impact (spirv-as + spirv-val --target-env vulkan1.2)

Benchmark Before (03b09a08) After Delta
Divergent loop (2.5k RDNA2 insns, 40 s_cbranch_execz blocks) 35,738 lines / 631,184 B .spv / 2,566 OpLoad %active 33,256 lines / 591,472 B .spv / 84 OpLoad %active −6.9% lines, −6.3% .spv bytes, −96.7% %active loads
Straight-line ALU (1k v_fma_f32, no EXEC writes) 16,264 lines / 296,540 B .spv / 1,005 OpLoad %active 13,251 lines / 240,300 B .spv / 0 OpLoad %active −18.5% lines, −19.0% .spv bytes, −100% %active loads
234 real GPU-harness .asm fixtures (runtime/test/shaders/*.asm) 362,312 lines (234/234 valid) 349,510 lines (234/234 valid) −12,802 lines (−3.5% incl. fixed headers/prologues)

Verification (Linux CPU, Python 3.13.5, LLVM 18.1.8, SPIRV-Tools, no game files)

  • tests/semantic/test_active_cache.py: 6/6 OK (mid-block s_and_saveexec_b32/s_or_b32 cache updates on 32-lane run_wave, divergent loop caching, no-EXEC fast path, DPP row_mask preservation under exec_static_true, --wave64-emulate validation, direct Gen() default).
  • tests/test_translate.py: 343/343 passed (1 skipped, 0 failed) + 234/234 GPU .asm fixtures validated with spirv-val --target-env vulkan1.2 (1 pre-existing LLVM 18 operand error on ps_sdwa_f16_const, identical to 03b09a08).
  • Full tests/semantic suite (7,456 tests): zero new failures vs 03b09a08; tests/test_semantic_translator_use.py: 3/3 OK; all 74 non-pytest translator/SPIR-V tests/test_*.py: 74/74 passed.
  • git diff --check clean.

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 aa813789 on Windows 11: test_active_cache.py 6 OK, test_carry_exec_mask.py 9 OK, test_valu_permlane16.py 16 OK, test_f64_transcendentals.py 2 OK; git diff --check clean.

The per-block %active loads are cached and no-EXEC dst() writes take the fast path; the updated tests (including the carry/EXEC mask and permlane cases) pass. No blocking issue.

@whattheflop whattheflop 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 Windows CPU verification at aa813789, uv CPython 3.12.13, SPIRV-Tools v2026.4 and LLVM 21.1.8 through WSL. Two fresh 32-lane pixel shaders passed Vulkan 1.2 validation, matched hand-calculated outputs and agreed with exact parent 03b09a08 on every lane.

  • A shader using save-EXEC, EXECZ branches, a restore and a second mask change reduced active loads from 25 to 6 (489 to 470 SPIR-V lines). Masked lanes 5 and 20 retained the expected words through both regions.
  • A straight-line no-EXEC shader reduced active loads from 7 to zero and uint selects from 6 to zero (290 to 271 lines).

The selected touched tests passed, including 7 bpermute cases with AMDGPU LLVM. Synthetic interpreter and offline validation only.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested aa813789 on Linux (Ubuntu), CPython 3.10.12, pytest 9.2.0, CPU only, synthetic .asm fixtures, no game files: pass.

  • python -I: tests/semantic/test_active_cache.py 6/6 OK, test_carry_exec_mask.py 9/9 OK, test_valu_permlane16.py 16/16 OK, test_f64_transcendentals.py 2/2 OK, test_rcp_iflag_mods.py 5/5 OK.
  • Negative control: with main's tools/rdna2spirv.py, test_active_cache.py fails 4/6 — %active is re-loaded before every OpSelect instead of being cached per block.
  • tests/test_translate.py runs 585 skipped here — SPIRV-Tools isn't installed, so the spirv-as/spirv-val validation paths didn't run. Worth a maintainer/reviewer run with the toolchain present.
  • git diff --check clean; compileall clean.

AI-assisted (Devin).

@mrbean56

Copy link
Copy Markdown

Tested aa81378929 on Linux (Debian 13), Python 3.13.5, SPIRV-Tools v2026.4: pass, no output change observed.

  • pytest tests/semantic/test_active_cache.py tests/semantic/test_carry_exec_mask.py tests/semantic/test_valu_permlane16.py tests/test_f64_transcendentals.py tests/test_rcp_iflag_mods.py tests/test_translate.py -q: 619 passed, 4 skipped, 144 subtests passed.
  • Semantic differential against main: translated all 40 PS fixtures that translate here with this branch and with 03b09a08, ran each through the mini interpreter with the same (empty) inputs, and compared every output word: 40 / 40 identical.
  • exec_static_true safety: writes_exec catches every EXEC writer I can name — v_cmpx* by prefix (covers _e32/_e64/_sdwa/_dpp), any saveexec/wrexec opcode (including s_andn2_saveexec, s_xor_saveexec), and any SALU op whose first operand is an exec* destination (s_mov_b64 exec, s_wqm_b64 exec, s_cselect_b64 exec, …). The s_cmp*/s_bitcmp* exclusions are right because their first operand is a source. Every OpStore %active in the file goes through emit() with that exact prefix, so the assert covers the model's only way to change %active; dst()'s fast path keeps the dpp_guard check, and a DPP write therefore still builds the OpLoad/OpSelect guard.
  • Spot check: a synthetic PS with no EXEC write emits 0 OpLoad %bool %active and direct OpStores; the same PS with v_cmpx_gt_f32 or s_and_saveexec_b64 emits the %active load/store machinery (2 loads, 1 store each), so the fast path is off exactly where it must be.

One process note: the assert is the safety net, and it disappears under python -O. The repo runs -I, so this is only a caution for anyone running the translator with optimizations on.

No GPU, no game data. AI-assisted.

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

Reviewed aa81378: %active values are cached only within a block and updated when stored, while labels and split regions clear the cache. The no-EXEC fast path retains DPP guards and is enabled only after the translator finds no EXEC-writing instruction. Independent semantic, SPIR-V validation, and differential reports pass.

@paratustra

Copy link
Copy Markdown
Contributor

Checked aa81378 against main 03b09a0 (macOS, Python 3.15.2, tests/semantic/support.translate_lines). A shader that writes EXEC through a VALU carry-out now fails to translate. writes_exec() (tools/rdna2spirv.py:12983-12991) only looks at the first operand. In VOP3b ops, though, the carry-out SGPR is the second operand, and it can be EXEC. So exec_static_true is set for a shader that does write EXEC.

v_mov_b32 v0, 5
v_mov_b32 v1, -1
v_add_co_u32 v2, exec_lo, v1, v0
exp mrt0 v0, v2, v2, v2 done vm
s_endpgm
result
main translates (the carry-out is stored to %active)
this PR AssertionError: OpStore %active emitted with exec_static_true: OpStore %active %t18

It fails loudly only because of the assert in emit(). Under python -O it translates while exec_static_true is still set, so the no-EXEC fast path is chosen for a shader that writes EXEC. Checking every destination operand would close this. That means the VOP3b carry-out (v_add_co/v_sub_co/v_subrev_co/*_co_ci, v_mad_u64_u32/v_mad_i64_i32, v_div_scale), or any operand the op writes, not only a[0]. A one-line test with this listing would pin it.

I found no EXEC writer that the per-block %active cache misses: every store goes through emit(), which resets on OpLabel. The full semantic suite gives the same failures on this head and on main, apart from the PR's new tests.

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

@bobcatchris

Copy link
Copy Markdown
Contributor

Apple M2 no-regression check at head aa81378 (macOS 26.4, MoltenVK 1.4.2 direct, subgroup 4..32, llvm-mc 23.1.6, clean full build exit 0).

python -I scripts/run_gpu_tests.py --build runtime/build/linux: 213 shaders translated, 213 pass spirv-val; 127/210 passed, 76 skipped, 7 failed — identical to upstream/main aa2988c on this M2 (same seven known MoltenVK expected failures, no new failure or skip). Head fetched read-only, no rebase/edit/push. Synthetic shaders and counts only; no game files.

AI-assisted.

@theswiss24

Copy link
Copy Markdown

Tested aa813789 (contains main 03b09a08) on NVIDIA GeForce RTX 2060 SUPER (Turing), driver 580.178.04, Ubuntu 24.04.5, llvm-mc 20.1.2, test programs built from main 03b09a08 (this PR changes no C++): pass.

LEONIDA_W64_EMULATE=1 python3 -I scripts/run_gpu_tests.py --build <main build>: 195/210 passed, 15 skipped, 0 failed, the same result on every test as main 03b09a08. I'm also measuring this PR on the corpus's largest modules for SHADER-774 and will post that in the coordination issue.

No game files.

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

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

Tested aa81378 on AMD Radeon RX 9070 XT (RADV GFX1201) 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): 196/210 passed, 14 skipped, 0 failed on both GPUs, with every test's result the same as at the merge base 03b09a0. Every GPU fixture goes through the changed dst()/%active paths.
  • Corpus slice (my own 1.0.2.1 work folder, python -I tools/rdna2spirv.py <work>/shaders/dxbc/disasm --limit 2000), this PR against 03b09a0:
    • Translated: 2,000 against 2,000. spirv-val: 2,000 against 2,000. No regression in either count.
    • All 2,000 modules change, and the slice's SPIR-V goes from 1,110.1 MB to 1,080.1 MB (−2.7%). That is smaller than your fixture figure (−3.5% lines), which fits real shaders writing EXEC more often.
    • The two runs were concurrent, so I don't report a time difference.
  • tests/test_translate.py: 581 passed, 4 skipped. tests/test_f64_transcendentals.py: 2 OK. tests/test_rcp_iflag_mods.py: 5 OK.
  • python -m unittest discover -s tests/semantic: 7462 run, 7 failures and 2 errors. That is exactly main's set at 03b09a0, compared by test name, so test_active_cache.py and the relaxed tests pass.

No game files or shader names; counts and sizes only. AI-assisted.

@SandimL

SandimL commented Nov 23, 2026

Copy link
Copy Markdown

Tested aa813789 on AMD Radeon RX 6750 XT (gfx1031, Navi 22, RDNA2, subgroup 32..64), AMD proprietary driver 26.11.2 (Vulkan 2.0.353 / API 1.4.315), Windows 11 Pro build 26300.

Translation (runtime/test/shaders/build.py, llvm-mc 21.1.8 + SPIRV-Tools 2025.1 via WSL): 234/234 translated, 234/234 pass spirv-val — identical with and without this PR's rdna2spirv.py change.

GPU (check.py, test programs from the runtime-windows CI artifact of main 4eb6155d): 178/184 pass, 4 skipped, 2 unrunnable with these binaries, and the exact same split appears on the parent commit aa813789~1, so this PR changes nothing on RDNA2 here.

  • Skipped (expected): ms_w64x_ballot, ms_wave_info_s3, ms_v5_workgroup (mesh fixtures build.py does not build) and ps_w64x_readlane (this device cannot require a 64-wide fragment subgroup).
  • The 2 that don't run are a stale-binary mismatch, not a regression: the 4eb6155d artifact predates VKC_HEAP_INIT (61a9adc2), so cs_heap_init reads the untouched 0xEEEEEEEE fill; ps_array_resinfo (4096/4096 pixels differ) is also newer than that artifact. Both fail identically with and without this PR — I A/B'd by swapping only tools/rdna2spirv.py to its parent. I could not build the test programs at this commit locally (no MSVC/Vulkan SDK on this machine).

Net: no RDNA2 regression from this change, and the whole corpus translates and validates clean. AI-assisted (Claude Code).

@SandimL

SandimL commented Nov 23, 2026

Copy link
Copy Markdown

Scope note on my check above: I reproduced @paratustra's regression on this setup too. Their listing fails to translate on aa813789 with AssertionError: OpStore %active emitted with exec_static_true: OpStore %active %t18, while the parent aa813789~1 translates it fine (Python 3.11.9, Windows; swapping only tools/rdna2spirv.py).

So my "no regression / corpus clean" result above is scoped to the 234 runtime/test/shaders fixtures build.py builds — none of them write EXEC through a VOP3b carry-out, so that run does not clear this PR. The writes_exec() fix @paratustra describes (consider every destination operand, e.g. the VOP3b carry-out SGPR, not just a[0]) is needed first. AI-assisted (Claude Code).

@SweatierKey

Copy link
Copy Markdown
Contributor Author

Thanks @paratustra, @SandimL, and @mrbean56 for catching this! Pushed fix in 453fec25:

  • writes_exec() now checks base_op(op) in VOP3_TWO_DESTS for a[1] targeting exec* (covering v_add_co_u32, v_sub_co_u32, v_subrev_co_u32, *_co_ci_u32, v_mad_u64_u32, v_mad_i64_i32, v_div_scale_f32/f64), while still returning False when exec* is only read as a source operand (e.g. s_mov_b32 s0, exec_lo). Audited every OpStore %active, set_exec(), exec_half_write(), put_mask(), and mask_dst() callsite in tools/rdna2spirv.py to confirm no other operand position can write EXEC.
  • Replaced assert not self.exec_static_true in Gen.emit() with an explicit RuntimeError so the safety net remains active even under python -O.
  • Added test_vop3b_carry_out_to_exec_disables_static_true in tests/semantic/test_active_cache.py covering @paratustra's exact listing + writes_exec() checks.
  • Verified: test_active_cache.py (7/7), test_carry_exec_mask.py, test_valu_permlane16.py, test_f64_transcendentals.py, test_rcp_iflag_mods.py (39/39 OK), test_cube_sample.py (18/18 OK), python3 -O guard check OK, spirv-val --target-env vulkan1.2 OK.

@paratustra

Copy link
Copy Markdown
Contributor

Re-checked 453fec2 on macOS, Python 3.15.2. This resolves my note:

  • v_add_co_u32 v2, exec_lo, v1, v0 and v_sub_co_u32 v2, exec_lo, … now translate and store the carry-out to %active, with and without python -O;
  • a plain read (s_mov_b32 s0, exec_lo) still takes the no-EXEC path;
  • tests/semantic/test_active_cache.py passes.

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

@Kev-Ball

Copy link
Copy Markdown

Tested 453fec25 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.

Ran the complete scripts/run_gpu_tests.py --build runtime/build/linux --require-pass suite with LEONIDA_W64_EMULATE=1: 195/210 passed, 15 skipped, 0 failures. Also ran the seven semantic tests selected by unittest discover -s tests/semantic -p "*active*.py"; all passed.

AI-assisted verification with synthetic inputs.

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

Tested 453fec2 (a re-test at the new head) on AMD Radeon RX 9070 XT (RADV GFX1201) 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): 196/210 passed, 14 skipped, 0 failed on both GPUs, with every test's result the same as at the merge base 03b09a0.
  • tests/test_translate.py: 581 passed, 4 skipped. tests/test_f64_transcendentals.py: 2 OK. tests/test_rcp_iflag_mods.py: 5 OK.
  • python -m unittest discover -s tests/semantic: 7463 run, 7 failures and 2 errors. That is main's known set at 03b09a0 (test_cmp_class_f64, test_mutations, test_loop_ballot_barrier). The PR adds none.
  • Note: main has moved 914 commits past that merge base, so this doesn't cover the branch merged onto current main.

No game files. AI-assisted.

@lunarminus

Copy link
Copy Markdown

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

  • This PR changes no C++, so the test programs are the d0835dd9 build.
  • python -I scripts/run_gpu_tests.py, native: 214/214 translated, 214/214 pass spirv-val. 196/210 passed, 14 skipped, 0 failed.
  • Same run with LEONIDA_W64_EMULATE=1: 214/214 translated and valid. 196/210 passed, 14 skipped, 0 failed.
  • Compared per test with d0835dd9 without the PR, in both modes: every one of the 210 results (PASS/FAIL/SKIP and test name) is the same, with 0 differences.
  • The generated SPIR-V did change. Over the 214 fixture modules, OpLoad %bool %active drops from 9,191 to 1,878 (native) and from 9,181 to 2,051 (emulate). Lines drop from 351,288 to 339,178 and from 359,099 to 347,172.
  • The other GPU run on 453fec25 in the thread is on NVIDIA (32-lane subgroups, emulate mode). This one adds AMD/RADV in both modes.
  • PR tests, python -I -m unittest: test_active_cache 7/7 OK, test_carry_exec_mask 9/9, test_valu_permlane16 16/16, test_f64_transcendentals 2/2, test_rcp_iflag_mods 5/5.
  • pytest tests/test_translate.py tests/test_f64_transcendentals.py tests/test_rcp_iflag_mods.py, with spirv-as/spirv-val and AMDGPU clang/llvm-mc 23.1.5: 588 passed, 4 skipped, 29 subtests passed. The 4 skips are test_translate GS/MS fixtures that have no synthetic DXBC.
  • Full tests/semantic: 7,463 tests with the PR and 7,456 without. Both give 7 failures and 2 errors, and the FAIL/ERROR set is identical by test name.
  • CPU translation check with hand-written listings, PR vs d0835dd9:
    • @paratustra's v_add_co_u32 v2, exec_lo, v1, v0 listing translates and stores the carry-out to %active.
    • A plain s_mov_b32 s0, exec_lo read takes the no-EXEC path (0 %active loads).
    • v_cmpx_gt_f32 keeps the %active load/store.
  • Nobody in the thread asked for a command specific to AMD or 32-wide GPUs, so I ran nothing beyond this.

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

@sebashord

Copy link
Copy Markdown

Tested 453fec2535682ef814fc81fe9f1d5440051694bd on Windows 11 Pro build 26300.9974 with two GPUs: Radeon iGPU of a Ryzen 7 9800X3D (gfx1036, 0x1002:0x13c0, AMD proprietary driver 25.10.36, subgroup 32..64) and RTX 5070 Ti (driver 621.01, subgroup 32..32): pass, every GPU result is identical to the base 03b09a08. The GPU runs I can see on this head are Linux; this adds the AMD Windows driver and an RTX 50 card.

GPU suite (python -I scripts\run_gpu_tests.py --build runtime\build --require-pass, one GPU at a time)

Device Base 03b09a08 This head
Radeon iGPU, 25.10.36, native wave64 195/210 passed, 15 skipped, 0 failed 195/210 passed, 15 skipped, 0 failed
RTX 5070 Ti, 621.01, native 164/210, 46 skipped, 0 failed 164/210, 46 skipped, 0 failed
RTX 5070 Ti, LEONIDA_W64_EMULATE=1 195/210, 15 skipped, 0 failed 195/210, 15 skipped, 0 failed

In each of the three configurations all 210 result lines (status and output words) are the same for base and head, and the 83 raw\*.raw files the suite leaves in its work folder are byte-identical (SHA-256).

Fuzzer on the Radeon: python -I tools\valu_fuzz.py --family f16 --seed 1 --programs 300 --wave 32 --build runtime\build gives 300/300 match, 0 mismatched, 0 skipped. I stopped at 300 because on this driver seed 1 reaches the known SHADER-777 mismatch at program 534 on this base.

CPU tests (LEONIDA_REQUIRE_SPIRV_TOOLS=1, python -I <file>, all OK): tests/semantic/test_active_cache.py (7, also 7 with python -I -O), tests/semantic/test_carry_exec_mask.py (9), tests/semantic/test_valu_permlane16.py (16), tests/test_f64_transcendentals.py (2), tests/test_rcp_iflag_mods.py (5).

This PR changes no C++, so I did not rebuild: the test programs are an MSVC 14.44 build of 72cda1f2 (#1976, same base 03b09a08), whose compiled sources differ from this head only in runtime/shims/dxgi_com.cpp, runtime/test/dxgi_swapchain_test.cpp and runtime/CMakeLists.txt. Base and head rows used the same programs.

Not run: tests/test_translate.py and the other pytest-only files (no pytest on this machine), and I did not measure the SPIR-V size or pipeline-time numbers.

Tools: llvm-mc 23.1.6 (conda-forge), Vulkan SDK 1.4.363.0, Python 3.11.9, VK_LOADER_LAYERS_DISABLE=~implicit~.

AI-assisted. Synthetic test programs and counts only, no game files.

Created with Perplexity

@kapitche

Copy link
Copy Markdown
Contributor

Tested 453fec25 merged with main 98fa503f on Windows 11, RTX 4080 SUPER + Intel UHD 770 (MSVC 14.51): pass, no GPU result changes.

  • scripts/run_gpu_tests.py --build runtime/build (217 cases, llvm-mc 23.1.6, test programs from a runtime build of main 7b7d73f8, the PR's tools/ and scripts/): RTX 4080 SUPER 170 passed, 47 skipped, 0 failed; Intel UHD 770 150 passed, 67 skipped, 0 failed.
  • Control: main 7b7d73f8 with the same test programs on the same machine gives 170/47/0 and 150/67/0, and the per-case PASS/SKIP lists are identical to the PR's on both GPUs.
  • tests/semantic/test_active_cache.py (7 tests), tests/test_rcp_iflag_mods.py (5) OK; tests/test_translate.py ran clean (no output).
  • Negative control (tools/rdna2spirv.py from main, everything else from the PR): test_active_cache.py gives 5 failures in 7 tests.

@memorypressure

Copy link
Copy Markdown

Checked at 453fec2 merged with main 3faac55: merges clean; the new test_active_cache.py is 7/7 with all classes correctly above unittest.main(), both changed semantic suites and both changed tools/ tests pass, tests/test_translate.py is 596/596 in the venv (re-run), and test_spirv_opt, test_desc_cache and test_control_flow_exec stay green. The cache-invalidation audit is the part worth reviewing: every OpStore active emission matches the emit-hook invalidation, the four extra reset sites cover segment/label transitions, and the VOP3_TWO_DESTS carry-out hole is closed with genuine negative controls (s_mov reading exec_lo must not count). One honest caveat: exec_static_true is a program-wide dataflow claim — a corpus GPU sweep is the natural confirmation. Pairwise with #4477 and #4479 (same translator file) is clean both ways. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@javdc

javdc commented Nov 23, 2026

Copy link
Copy Markdown

Tested a82ea10 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.

  • pytest tests/semantic/test_active_cache.py -q: 7 passed.
  • Full GPU suite (PR worktree vs existing runtime build): 212 passed / 232 total, 16 skipped, 0 failed (expected skips; no failures).

Translator optimization only (tools/rdna2spirv.py) plus semantic test; no runtime C++ changes.

AI-assisted (OpenCode).

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested a82ea10 on Intel UHD Graphics 630 (CFL GT2), Mesa ANV, subgroup 8..32: the full run_gpu_tests.py suite prints "167/232 passed, 63 skipped" with FAIL cs_fmt_int_narrow ("word 34: expected 0xffffffff, got 0x00000000") and FAIL cs_signed_zero_nan. Running those two fixtures on 561b65a gives the same two FAIL lines, so they are not introduced by this PR. test_active_cache runs 7 tests OK (the description says 6), test_carry_exec_mask and test_valu_permlane16 25 tests OK, and tests/test_translate.py, test_f64_transcendentals.py and test_rcp_iflag_mods.py give 640 passed under pytest. I did not run a full suite on 561b65a for a test-by-test comparison.

AI-assisted.

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested a82ea10 merged onto main 561b65a (the branch is already based on it) on Apple M4, macOS 27.2.1, MoltenVK 1.4.2, Python 3.15.2 and 3.12.16: needs changes. The cache and the no-EXEC fast path held up in every check below, but two semantic tests that reached main after the 03b09a0 runs reported above now fail.

  • Semantic suite (python3.15 -I -m unittest discover -s tests/semantic): 6157 run, 1 failure and 2 errors, 1 skipped, 1 expected failure. Main gives 6150 run, OK. The new failures also fail on 3.12:

    • test_int32_to_f64.Int32ToFloat64.test_signed_and_unsigned_conversion_reach_both_destination_words, both subtests: ValueError at tests/semantic/test_int32_to_f64.py:56. The test expects an OpSelect in front of each destination word. The fixture never writes EXEC, so the word is now stored directly. If the test falls back to the word itself when there is no select (selected, = sel or [word]), it passes.
    • test_ds_swizzle_b32.NegativeControls.test_sabotage_quad_base_mask_shuffle_and_exec_guard: n3 is 0 at tests/semantic/test_ds_swizzle_b32.py:892. The sabotage regex (lines 883-889) needs OpLoad %bool %active directly before the eager mask OpSelect. That select now uses the id cached from the earlier s_mov_b32 exec_lo. Matching the mask select by the OpNot that follows it ((%\w+) = OpSelect %uint %\w+ %cffffffff %c0\n(\s*)(%\w+) = OpNot %uint \1) makes the negative control bite again: 20/20 on main, on this PR, and on this PR merged with rdna2spirv: intra-block %vgpr/%sgpr value forwarding #4518.
  • PR tests, on both Pythons: test_active_cache 7 (the description says 6), test_carry_exec_mask 9, test_f64_transcendentals 2 and test_rcp_iflag_mods 5, all OK. test_translate.py plus test_cube_sample.py under pytest (3.15 only): 651 passed, the same as main. compileall and git diff --check are clean.

  • Corpus slice (--shard 0/64): 415 translated and 415 pass spirv-val, the same as main, with unchanged index fields. All 415 modules differ. Total size goes from 63,879,501 to 63,283,843 words (−0.93%); no module grew.

  • Audit: every write to %active is an emit("OpStore %active …") line, which the hook in emit() turns into the cached id; labels, block starts, x_split and folded regions drop it. writes_exec() (tools/rdna2spirv.py:15029) covers operand 0, the VOP3b carry-out, v_cmpx, saveexec and wrexec. Later passes over insns only remove instructions, so exec_static_true stays conservative. If writes_exec() missed a writer, the shader would fail loudly with the RuntimeError at line 396 instead of being miscompiled; I checked that, with the v_cmpx or saveexec clause removed, a shader whose only EXEC writer is v_cmpx (or saveexec) raises it.

  • I wrote 38 pixel-shader probes by hand and ran them on the CPU wave interpreter. They cover v_cmpx mid-block (e32, e64, class, u64), s_mov/s_andn2/s_xor/s_or on exec_lo, v_readfirstlane into exec_lo, a VOP3b carry-out into exec_lo, s_wqm, saveexec at the end of a block, wave64 writes of exec_hi alone and of 64-bit pairs, v_cmpx followed by DPP, and EXEC read as data (s_mov, s_bcnt1, s_ff1, v_cndmask, s_and) or by s_cbranch_execz in shaders that never write it. Per-lane output is identical to main, and every module passes spirv-val. v_cmp_*_e64 exec_lo, … is Unsupported on main and here alike.

  • Mutations: the PR's own tests catch 5 of 11 (the cache not taking the stored id, exec_static_true always on, no VOP3b clause, no operand-0 clause (caught only by test_carry_exec_mask), no reset at block start). The other 6 survive:

    • exec_value() returning 0 under exec_static_true: no test reads EXEC as data in a shader that never writes it; my probe does;
    • writes_exec() without v_cmpx, or without saveexec: every test also restores EXEC with s_or/s_mov; the guard catches these at translate time, but no test pins it;
    • dropping the label reset, the x_split reset or the folded-region resets: none of the tests, probes or corpus checks I ran tell these apart.

    Possible test additions: EXEC read as data (s_mov_b32 s4, exec_lo, v_cndmask … exec_lo) in a no-EXEC-write shader, and one shader each whose only EXEC writer is v_cmpx or saveexec.

  • GPU (scripts/run_gpu_tests.py, one runtime built from main; this PR changes nothing under runtime/ or scripts/): 165/232 passed and 59 skipped. Every row is identical to main, which I ran twice, including the same 8 FAIL rows this M4 also has on main. 237 of the 255 test modules change.

  • Together with rdna2spirv: intra-block %vgpr/%sgpr value forwarding #4518: merging both gives 9 conflict hunks in tools/rdna2spirv.py (Gen.__init__, the emit() hook, x_split, the Gen(...) call and five reset sites), each resolved by keeping both sides. After that, tests/test_translate.py::test_a16_sample_gradients_use_full_vgprs from rdna2spirv: intra-block %vgpr/%sgpr value forwarding #4518 fails. Its stored_to reverse map is keyed by the stored id, and the fast path here stores the same constant to v8 and v11, so the lookup finds the wrong VGPR. The fix belongs to whichever PR lands second (details on rdna2spirv: intra-block %vgpr/%sgpr value forwarding #4518). On the merge, the semantic suite runs 6163 tests with 4 failures and 2 errors, exactly the failures of the two PRs added together. The probes, the corpus slice (415/415, −5.68% words) and the GPU rows all match main.

AI-assisted.

@SweatierKey

Copy link
Copy Markdown
Contributor Author

Thanks @sovljanskii for the detailed audit, probes, and mutation checks! Pushed da0b0b181:

  • Fixed the 2 newly-merged semantic tests:
    • tests/semantic/test_int32_to_f64.py: falls back to the extracted word directly when the no-EXEC fast path omits OpSelect (selected, = sel or [word]).
    • tests/semantic/test_ds_swizzle_b32.py: matches the eager mask OpSelect by the following OpNot %uint \1 so the negative control fires regardless of whether %active came from a fresh OpLoad or the per-block cache.
  • Hardened tests/semantic/test_active_cache.py (now 9 tests): added test_no_exec_write_reads_exec_as_data (s_mov_b32 s4, exec_lo and v_cndmask_b32_e64 ... exec_lo in a no-EXEC-write shader) and test_vcmpx_only_and_saveexec_only_disable_static_true (shaders whose only EXEC writer is v_cmpx or s_*_saveexec).
  • Also updated stored_to in #4518 (a15b08221) so merging #4473 + #4518 keeps test_a16_sample_gradients_use_full_vgprs green.

Verified locally (Linux, Python 3.13.5, spirv-as + spirv-val, LEONIDA_REQUIRE_SPIRV_TOOLS=1):

  • Full python3 -I -m unittest discover -s tests/semantic: 6159 tests OK (skipped=1, expected failures=1, 0 failures/errors).
  • test_active_cache.py (9/9), test_int32_to_f64.py (3 ran / 1 skipped without spirv-opt, OK), test_ds_swizzle_b32.py (20/20), test_f64_transcendentals.py + test_rcp_iflag_mods.py (7/7).

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review

Reviewed change in PR #4473: rdna2spirv: cache per-block %active loads and fast-path no-EXEC dst() writes.

Scope: tests/semantic/test_active_cache.py, tests/semantic/test_carry_exec_mask.py, tests/test_f64_transcendentals.py, +3 more
Diff: +355 / -22 across 6 file(s).

The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.

Reviewed by shayderrr via automated batch review.

@shayderrr

Copy link
Copy Markdown
Collaborator

Thanks @SweatierKey - I went through rdna2spirv: cache per-block %active loads and fast-path no-EXEC dst() writes and the diff around tests/semantic/test_active_cache.py. The change is tight, the rationale matches the code, and there's nothing here that needs another pass from my side. Approved and squash-merging it into main now. Nice work.

@shayderrr
shayderrr merged commit 92417d5 into ItsNotRexed:main Nov 23, 2026
0 of 5 checks passed
SweatierKey added a commit to SweatierKey/Leonida that referenced this pull request Nov 23, 2026
SweatierKey added a commit to SweatierKey/Leonida that referenced this pull request Nov 23, 2026
kett1m added a commit to kett1m/Leonida that referenced this pull request Nov 23, 2026
…can be inactive

main is red in this suite: 3 files, 51 failures. 47 are here. ItsNotRexed#4473 folds `if (%active)` to `if (%true)` when the
shader writes no EXEC, which is what the model says then (no lane is inactive), but find_guarded_texel_block only
accepted a branch on an OpLoad of %active.

The walker now accepts the constant, and only the constant: a module with an OpStore to %active still has to branch
on the load, so a shader that can deactivate lanes keeps the real guard.

test_image_atomics_guard: OK (3 tests). Whole suite after: 2 files failed (test_float_nan_fract,
test_image_store_d16), both separate.
SweatierKey added a commit to SweatierKey/Leonida that referenced this pull request Nov 23, 2026
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.