Repository navigation
OLD-7450: restore old upstream PR 7450 - wave64 emulate: a cross-lane read of a missing lane in a partial wave gives 0 - #833
Conversation
… gives 0 Restores old upstream PR 7450, ported onto main. With --wave64-emulate, every read of another lane's exchange slot (ds_swizzle, ds_bpermute, ds_permute, readlane, ...) now selects 0 when the source lane does not exist in a partial last wave (Gen.x_lane_word), instead of relying on the prologue's zeroed slot. RADV (Mesa 26.3.1) turned the store, barrier and load of an exchange behind a branch into masked_swizzle_amd with fetch_inactive, so in a 40-thread group lanes 32-39 of a SWAP 8 swizzle read the missing lanes' registers. Full waves emit the same module as before. scripts/run_gpu_tests.py now runs the partial-wave fixtures emulated at subgroup 32, as check.py's partial_wave_test does. It left the subgroup size to the driver, and RADV picks 64 for compute, where the new fixture passed even without the fix. GPU test cs_w64x_partial_swizzle (words measured on gfx1036 through tools/hw_oracle), semantic test test_w64x_partial_swizzle with a hand-written fixture, and a contract-table row in docs/design.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Clean-Room Peer Review for PR #833 (d3d12: support x_lane_word boundary checks for cross-lane exchanges on partial waves)
Brilliant driver-level workaround and ISA conformance fix:
- RADV Subgroup Swizzle Optimization Guard:
- Addresses Mesa RADV optimization behavior where a workgroup store/barrier/load exchange sequence is lowered directly to a subgroup swizzle instruction. On partial waves, reading a non-existent invocation fetched undefined register data instead of the zeroed workgroup buffer slot.
- Implements x_lane_word(idx, lane) which emits an OpSelect %uint (lane_index < total_threads) val 0.
- Zero Overhead for Full Waves:
- if threads >= self.x_lanes: return v guarantees that full 64-lane waves emit zero extra instructions or comparisons.
- Unit Test Coverage:
-
ests/semantic/test_partial_wave_swizzle.py validates partial waves (40 threads, 104 threads) and verifies bit-for-bit identity for full waves (64 threads).
-
- Clean-room verification: Standard library only, LF line endings, documentation updated in docs/design.md.
LGTM! Highly valuable RDNA2 shader lowering fix. Approved.
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Audited and verified. Restores upstream PR 7450: under --wave64-emulate, Gen.x_lane_word selects 0 when a source lane does not exist in a partial workgroup, preventing RADV's masked_swizzle_amd optimization from reading uninitialized inactive registers. Contract table updated in docs/design.md with hardware measurements on gfx1036. Clean-room compliant. Approved.
|
Tested 5668f16 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32, mesh shaders), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows: pass Built at this head with
|
|
Thanks @Sangonapou for the 3080 Ti run: The red checks are
AI-assisted (Claude Code, Claude Opus 5.5). |
Conflict in scripts/run_gpu_tests.py: the dump-test name list gained cs_w64x_cmp_sdst on main and cs_w64x_partial_swizzle here; both are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main now resets the missing lanes' exchange slots with OpAtomicStore (19e42d6) instead of OpStore, so the test's poison substitution matched nothing and both partial-wave cases failed on their own guard. Match the atomic store's value operand instead. Without x_lane_word the 40-thread case still fails, so the test keeps covering the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scripts/run_gpu_tests.py: main added cs_w32_wrxchg2_ext and cs_w32_wrxchg2st64 to the same name list; keep main's list and add cs_w64x_partial_swizzle to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged: wave64 emulate: a cross-lane read of a missing lane in a partial wave gives 0.
AI-assisted (Claude Code, Claude Opus 5.5). |
Claimed in the coordination issue as: OLD-7450 #14 (comment)
Restoration of my original pull request, old upstream PR 7450 in
ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Ported onto main at d0da7da; the translator change applied unchanged, and the port adds the subgroup-32 pin inscripts/run_gpu_tests.py(below) and the RX 7900 XTX measurements to the contract row.Depends on: #793 (line-level, docs/design.md), #364, #366, #373 (line-level, scripts/run_gpu_tests.py)
What and why
--wave64-emulate, a cross-lane read of another lane's exchange slot gives 0 when the source lane doesn't exist in a partial last wave. This coversds_swizzle_b32,ds_bpermute_b32,ds_permute_b32,v_readlane_b32,v_readfirstlane_b32, DPP and the other reads behindGen.x_round. A source lane that isn't running reads 0 on the hardware.Gen.x_lane_word:x_wbase + lane < threads, else 0. It is used by the five slot reads inx_round.masked_swizzle_amdwithfetch_inactive. In a 40-thread group, lanes 32-39 ofds_swizzle_b32 offset:swizzle(SWAP,8)then read the missing lanes' registers: garbage that changes between runs.cs_w64x_partial_swizzle(40 threads: SWAP 8, BROADCAST 16,15 andds_bpermute_b32from lanes 40-47). Its 8 words were measured natively on gfx1036 throughtools/hw_oracle.tests/semantic/test_w64x_partial_swizzle.pywith a hand-written fixture. It covers 40 and 104 threads, with the prologue's zero stores replaced by a poison word in the workgroup interpreter.scripts/run_gpu_tests.pynow runs the partial-wave fixtures emulated at subgroup 32, ascheck.py'spartial_wave_testalready does.check.pyshows it wrong.docs/design.mdcontract table: "Wave64 emulation: cross-lane reads of missing lanes", with how it was confirmed.Tested
Mesa 26.3.1 RADV on Linux. "Before" is main d0da7da with only this PR's tests and runner change added.
test_w64x_partial_swizzle.py: before 2 fail and 1 error; after 3/3 OK.run_semantic_tests.py): before 465 files and 6,108 tests, after 466 files and 6,111 tests; 0 files fail on either.cs_w64x_partial_swizzle, emulated at subgroup 32, 20 runs ofvk_compute_testper device:run_gpu_tests.py --filter cs_w64x_partial:cs_w64x_partial_swizzlefails);check.py, emulated:cs_w64x_partial_swizzlefails on both GPUs before and isokafter.run_gpu_tests.py, the same on both GPUs, native andLEONIDA_W64_EMULATE=1:cs_imgload_tfeandcs_imgload_d16_tfe. They fail on main too and this change doesn't touch them.crosslane_fuzz.py --wave 64 --ext --dpp --no-maskdata --programs 1000 --seed 48315 --modes emulate:--limit 2000slice, native and--wave64-emulate: 2000 translated and 2000 passspirv-val, before and after, with identical modules. That slice has no compute shaders.--wave64-emulate: 40 translated and 40 passspirv-val, before and after. 25 of the 40 modules change (the ones that read across lanes).python -m compileall -q tools tests scriptsis clean;git diff --checkis clean;check_no_game_data.pypasses on every changed file;tests/test_shader_checks.py,tests/test_partial_wave_subgroup.py,tests/test_run_gpu_*.pyandtests/test_text_write_line_endings.pypass.GPUs tested: AMD Radeon RX 7900 XTX (RDNA3, RADV, Mesa 26.3.1, Linux); AMD Radeon Graphics iGPU of the Ryzen 9 7950X3D (gfx1036, RDNA2, RADV, Mesa 26.3.1, Linux)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.AI-assisted (Claude Code, Claude Opus 5.5).