Repository navigation
rdna2spirv: cache per-block %active loads and fast-path no-EXEC dst() writes - #4473
SweatierKey wants to merge 2 commits into
Conversation
Kam471
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
Tested
AI-assisted (Devin). |
|
Tested
One process note: the assert is the safety net, and it disappears under No GPU, no game data. AI-assisted. |
Flyander
left a comment
There was a problem hiding this comment.
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.
|
Checked aa81378 against main 03b09a0 (macOS, Python 3.15.2,
It fails loudly only because of the assert in I found no EXEC writer that the per-block No game files. AI-assisted (Claude Code). |
|
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).
AI-assisted. |
|
Tested
No game files. Tested and written by Claude (Claude Code), posting from @theswiss24's account. |
|
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.
No game files or shader names; counts and sizes only. AI-assisted. |
|
Tested Translation ( GPU (
Net: no RDNA2 regression from this change, and the whole corpus translates and validates clean. AI-assisted (Claude Code). |
|
Scope note on my check above: I reproduced @paratustra's regression on this setup too. Their listing fails to translate on So my "no regression / corpus clean" result above is scoped to the 234 |
|
Thanks @paratustra, @SandimL, and @mrbean56 for catching this! Pushed fix in
|
|
Re-checked 453fec2 on macOS, Python 3.15.2. This resolves my note:
No game files. AI-assisted (Claude Code). |
Claim: #4421 (comment).
What changes
%activecaching (Gen.active_b()): tracks the current basic block's%activeSSA bool inGen._active_ssa, updating on everyOpStore %active <val>and invalidating on everyOpLabel,x_split, and block boundary intranslate(). Eliminates redundantOpLoad %bool %activeinstructions inside each basic block.Gen.exec_static_true): whennot any(writes_exec(i) for i in insns),%activeis statically%truefor the entire shader (guarded by anassert not self.exec_static_trueinsideemit()on anyOpStore %activeso a missed instruction can never silently miscompile).active_b()returns%true,exec_value()returns0xFFFFFFFF, anddst()emits a directOpStorewhendpp_guard is Noneinstead ofOpLoad old+OpLoad %active+OpSelect+OpStore.Gen()unit-test callers default tocache_active=Falseandexec_static_true=False, preserving existingg.body-inspecting tests.tests/test_translate.py,tests/test_f64_transcendentals.py,tests/test_rcp_iflag_mods.py,tests/semantic/test_carry_exec_mask.py,tests/semantic/test_valu_permlane16.py) that previously required a freshOpLoad %bool %activeorOpSelecteven after a same-blockOpStore %activeor in a shader with no EXEC writes, and addstests/semantic/test_active_cache.py.SHADER-789), spirv_opt: sound dominator-tree SPIR-V optimizer (#884) #2298 (--opt), rdna2spirv: the legacy multiply tests |x|, |y| < FLT_MIN instead of flushing both operands, 11% smaller modules (SHADER-771) #4345 (SHADER-771), rdna2spirv: f32 constants are module-scope OpConstants, not a bitcast at each use (-2.4% SPIR-V) #4391 (Gen.fconst), andSHADER-774(%fmt_decode_fn).Measured impact (
spirv-as+spirv-val --target-env vulkan1.2)03b09a08)s_cbranch_execzblocks).spv/ 2,566OpLoad %active.spv/ 84OpLoad %active.spvbytes, −96.7%%activeloadsv_fma_f32, no EXEC writes).spv/ 1,005OpLoad %active.spv/ 0OpLoad %active.spvbytes, −100%%activeloads.asmfixtures (runtime/test/shaders/*.asm)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-blocks_and_saveexec_b32/s_or_b32cache updates on 32-lanerun_wave, divergent loop caching, no-EXEC fast path, DPProw_maskpreservation underexec_static_true,--wave64-emulatevalidation, directGen()default).tests/test_translate.py: 343/343 passed (1 skipped, 0 failed) + 234/234 GPU.asmfixtures validated withspirv-val --target-env vulkan1.2(1 pre-existing LLVM 18 operand error onps_sdwa_f16_const, identical to03b09a08).tests/semanticsuite (7,456 tests): zero new failures vs03b09a08;tests/test_semantic_translator_use.py: 3/3 OK; all 74 non-pytest translator/SPIR-Vtests/test_*.py: 74/74 passed.git diff --checkclean.AI-assisted.