Repository navigation
rdna2spirv: intra-block %vgpr/%sgpr value forwarding - #4518
SweatierKey wants to merge 5 commits into
Conversation
Kam471
left a comment
There was a problem hiding this comment.
Ran this at c31262e3 on Windows 11: tests/semantic/test_reg_load_forwarding.py -> 6 tests, OK; compileall and git diff --check clean.
The translator forwards %vgpr/%sgpr values within a block (updating the tests that depended on the old repeated loads), and the new forwarding cases plus the affected suites pass. No blocking issue.
|
Replying to @SweatierKey. Register forwarding preserved the full GPU readback in two cases on Linux, RTX 5090 (driver 595.99.02, subgroup 32), at
For each fixture the eight expected words matched, and the entire output buffer was byte-identical with forwarding on and off. AI-assisted. |
|
I ran In the head disassembly, both lane shuffles immediately following The fixture and official runner were byte-identical across revisions. Both runs used the same |
|
Tested
This PR and #4473 don't merge cleanly with each other (conflict in Tested and written by Claude (Claude Code), posting from @theswiss24's account. |
whattheflop
left a comment
There was a problem hiding this comment.
AI-assisted independent Windows CPU check at c31262e3, base 03b09a08, with a disposable integration of #4473 aa813789 and #4510 7ea906d5. uv CPython 3.12.13, synthetic shaders only.
- Five defined probes were bit-exact across main, the PR and the combined tree. The diamond/backedge case matched all 32 lanes, and a masked-lane case exercised all four dynamic VGPR writers while preserving lane 7. All 15 modules passed
spirv-val --target-env vulkan1.2. - The same float chain assembled to 12,836 bytes on main, 9,660 on this PR and 7,420 combined. The combined tree removed 38 cross-instruction bitcast round trips attributable to forwarding. Disabling forwarding in the combined tree removed that opportunity and raised size to 10,692 bytes with identical outputs.
- #4510 applied cleanly. #4473 required reconciling ten hunks in
tools/rdna2spirv.py: constructor signature and fields,emit,x_split,translatesetup and five reset sites. Keeping both caches' initialization and resets passed the six forwarding, six EXEC-cache and two bitcast tests. - The combined
v_mad_i16and D16 SINT-store probes both exercised signed inputs totou()and neither reached a signed inversion throughtof().
There was a problem hiding this comment.
I tested c31262e3 against its parent 03b09a08 on Linux with Mesa 26.1.6 RADV (GFX1201 via Mesa's DRM shim). These measurements cover cold pipeline creation and use synthetic RDNA2 only. I used the same native vk_pipeline_check executable for every run, a fresh process per sample, one worker, and MESA_SHADER_CACHE_DISABLE=true.
| Synthetic compute workload | Translator | SPIR-V bytes | Pipeline creation, median (range) |
|---|---|---|---|
1,024 chained v_fma_f32 |
Main | 305,040 | 31 ms (30–40 ms) |
1,024 chained v_fma_f32 |
#4518 | 177,992 | 24 ms (19–42 ms) |
128 dynamic buffer_load_format_x loads |
Main | 521,036 | 7.05 s (6.98–7.77 s) |
128 dynamic buffer_load_format_x loads |
#4518 | 514,344 | 7.45 s (7.06–7.98 s) |
128 dynamic buffer_load_format_x loads |
Single-component decoder prototype | 491,336 | 0.41 s (0.40–0.46 s) |
128 dynamic buffer_load_format_x loads |
#4518 plus prototype | 484,644 | 0.44 s (0.39–0.45 s) |
Five samples per FMA variant and three per typed-load variant. Each module passed spirv-val and created its pipeline successfully. Register forwarding reduced the FMA binary by 41.7%. The small, overlapping timing ranges make the FMA result inconclusive for compile time. On this typed-load fixture, the decoder change accounts for the large speedup. It applies cleanly on top of #4518 and keeps the compile time in the same range.
On #4518 alone the six forwarding tests and 156 buffer semantic tests pass with SPIRV-Tools required. With the decoder patch applied, the six forwarding tests and 157 buffer tests pass. The decoder differential also matches all 5,120 reference words bit-for-bit on that combined tree.
AI-assisted. No game files or physical GPU required for this check.
Larger synthetic cases
- 512 dynamic single-result typed loads. Main and #4518 both hit a 100-second timeout. The decoder prototype compiled in 3.40 s and the combined tree compiled in 4.27 s. One run per build with an 8 GiB address-space limit, otherwise the same compiler and cache settings. All four modules passed
spirv-val. - 2,048 integer multiply/add pairs under a partial EXEC mask. The observable value depends on a push-constant multiplier and the lane ID. #4518 reduces the binary from 744,744 to 384,296 bytes. Cold RADV pipeline creation went from a median 119 ms (119–138 ms) to 98 ms (93–101 ms), three samples per build. For synthetic chains of 128, 512 and 2,048 pairs, all 64 output words per dispatch matched a CPU reference on llvmpipe with both builds, including the 35 inactive lanes that retained their original values.
|
Tested What is fine:
What breaks: the 28 pytest-marked files as CI's
All 17 new failures are in one file, so the forwarding now leaves an Also fine on their own: RTX 5080 not run (186 MiB free, another job holds it). Machine: Linux Mint 22 (Ubuntu 24.04 base), |
|
Tested
AI-assisted (Devin). |
|
Apple M2 no-regression check at head c31262e (macOS 26.4, MoltenVK 1.4.2 direct, subgroup 4..32, llvm-mc 23.1.6, clean full build exit 0).
AI-assisted. |
|
Thanks @chpeu for catching the
|
|
Independent check of the current head
AI-assisted. |
|
Tested Ran the complete synthetic GPU suite with AI-assisted verification with synthetic inputs. |
|
Tested c5e6daf (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.
No game files. AI-assisted. |
|
Heads-up from a scratch merge (not a review): merged alone onto current That test came to
|
|
Tested c5e6daf on Intel UHD 630 (CFL GT2), Mesa 25.2.8 ANV, Ubuntu 24.04: pass. |
|
Thanks @mrp1no for the scratch-merge heads-up! Rebased onto
|
c5e6daf to
d78290b
Compare
|
Tested
|
|
Re-tested the fixed head
So from this machine the |
|
Merged cleanly with current main and green across the board: the four changed semantic suites (36 + 9 + 6 + 22), the translator battery (596 passed), image_load_typed 23, rcp_iflag_mods 5, design_rows 4, and 29 more across five related suites. Fixtures generated, the new text write pins UTF-8/LF, and spirv-as/val genuinely executed for the forwarding tests. This optimizes existing lowering rather than adding an opcode rule, so no new contract row expected; #2956 shares the translator file in different hunks. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
d78290b to
5643985
Compare
|
Re-tested the newest head The cube problem I reported is still fixed at this head: Whole pytest translator set, measured in the same session on both sides:
The totals differ because your branch carries two extra marked test files of its own, not because of a difference in Machine: Linux Mint 22 (Ubuntu 24.04 base), |
|
Tested 5643985 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.
This head appears test-only (per git show); no runtime/translator code changes in the checked commit. GPU suite not re-run. AI-assisted (OpenCode). |
|
Tested 5643985 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 forwarding itself held up in every check below, but three semantic tests that reached main after the 03b09a0 runs reported above now fail.
AI-assisted. |
|
Thanks @sovljanskii for the thorough shadow-audit, probes, and mutation analysis! Pushed
Verified locally (Linux, Python 3.13.5,
|
|
Re-tested the current head Everything green here:
I did not re-run the GPU battery or the full 6,245-case semantic suite for this head: your diff is translator and test |
a15b082 to
312debf
Compare
|
Rebased onto With both optimizations active together, forwarding a constant input whose value equals the Verified locally on
|
|
Re-checked head
The single failure is not yours: Not re-run for this head: the GPU battery and the ~6,245-case semantic suite — your diff is translator and test files |
…_offset_gathers_preserve_offset_and_unpack_uv_lod
… forwarding tests
312debf to
ef9104e
Compare
|
Tested New failure. git fetch origin pull/4518/head
git checkout --detach 8575d36ed
git merge --no-edit FETCH_HEAD
python -I scripts/run_semantic_tests.py tests/semanticThe translated shaders look correct. The test's GPU. I ran
The one failure is Not covered: no game files or retail shader corpus, and no fixture reaches AI-assisted (Claude Code). |
Claim: #4421 (comment).
What changes
%vgpr/%sgprvalue forwarding (Gen._reg_val, default-on intranslate()):load_reg(kind, r)returns the cached SSA value for(kind, r)when already loaded or stored earlier in the current basic block (eliminating both theOpAccessChainandOpLoad).store_reg,dst, andv_writelane_b32continue emittingOpStoreto%vgpr/%sgpr(so cross-block readers and dynamics_movrels/v_movrelsreads always see exact memory) and update_reg_val[(kind, r)]to the stored SSA value;dstandv_writelane_b32also reuse_reg_valforold.v_swaprel_b32,v_movreld_b32,v_movrelsd_b32,v_movrelsd_2_b32) invalidate all"vgpr"entries in_reg_val._reg_valclears on everyOpLabel,x_split, and block boundary intranslate().Gen()unit-test callers default tocache_regs=False, keeping inline loads insideg.body.tests/test_translate.py,tests/test_image_load_typed.py,tests/test_rcp_iflag_mods.py,tests/semantic/test_buffer_oob_select.py,tests/semantic/test_buffer_swizzle.py) to also recognize forwarded VGPR/SGPR values (OpStore %vgpr[r] <val>and constant-foldedOpBitFieldUExtract), and addstests/semantic/test_reg_load_forwarding.py.SHADER-789), rdna2spirv: cache per-block %active loads and fast-path no-EXEC dst() writes #4473 (SHADER-796), spirv_opt: sound dominator-tree SPIR-V optimizer (#884) #2298 (--opt), rdna2spirv: f32 constants are module-scope OpConstants, not a bitcast at each use (-2.4% SPIR-V) #4391 (Gen.fconst), andtof/touround-trip folding (and synergizes withtof/touby exposing cross-instruction bitcast chains).Measured impact (
spirv-as+spirv-val --target-env vulkan1.2)03b09a08)s_cbranch_execzblocks).spv/ ~7,800 reg loads.spv/ 925 uint loads.spvbytes,spirv-val34→24 msv_fma_f32).spv/ ~4,000 reg loads.spv/ 48 uint loads.spvbytes,spirv-val14→8 ms.asmfixtures (runtime/test/shaders/*.asm)Verification (Linux CPU, Python 3.13.5, LLVM 18.1.8, SPIRV-Tools, no game files)
tests/semantic/test_reg_load_forwarding.py: 6/6 OK (32-lane divergentrun_wavewiths_and_saveexec_b32/v_writelane_b32/self-aliasing, divergent loops,v_movreld_b32+v_swaprel_b32invalidation,v_movrels_b32/s_movrels_b32coexistence,--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.