fix(shader): wrap the v_readlane_b32 lane select at the wave size #322
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/322"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T05:45:04Z.
What
Follow-up to #254, as discussed there: #254 masks the
v_writelane_b32lane select, and adriadam10 leftv_readlane_b32/Shufflefor this PR ("I leftv_readlane_b32/Shufflefor your follow-up, as you offered.").The hardware reads the
v_readlane_b32lane select modulo the wave size: S1[4:0] in wave32, S1[5:0] in wave64.ReadLaneEliminatoralready assumes this for constant lanes (selector % waveSize), and the two-lane wave64 path inSpirvValueEmitContext::Shufflealready wraps (it masks with 31 and picks the half from bit 5). The single-subgroup path did not:EmitReadLanepassed the raw select straight toOpGroupNonUniformShuffle, which is undefined for an id at or above the subgroup size. A wave32v_readlane_b32 s8, v4, 37emittedOpGroupNonUniformShuffle %uint %uint_3 %v4 %uint_37.Changes:
EmitReadLanemasks the lane select withWaveSize() - 1beforeShuffle, the same expressionEmitWriteLaneuses after #254. On the two-lane path the extra AND is redundant and folds away.ReadLaneEliminatordoes not cover this: it only rewrites a read it can resolve to av_writelanechain or a unique lane value, so other constant lanes (and every SGPR-selected lane) still reach the emitter.v_readfirstlane_b32is not changed here. Its lane comes fromOpGroupNonUniformBallotFindLSB(orFirstLaneon the two-lane path), which is in range whenever a lane is active. With an empty EXEC it is undefined on the single-subgroup path and lane 31 on the two-lane path, while the hardware reads lane 0. That is a separate fix, which I'll send after this one.Test
agc_driver_read_lane, in the style of #254'sagc_driver_write_lane(words fromllvm-mc -mcpu=gfx1013): a 32-thread wave32 dispatch where every lane readsv_readlane_b32with an inline lane of 37, then with an SGPR lane of 69 taken fromv_readfirstlane_b32of a loaded value. Both must return lane 5's value, and the third result checks thev_readfirstlane_b32value. Like the write-lane test, it is skipped when the subgroup cannot hold a wave32 (lavapipe: 8).Tested
ctest: 100/100 pass, including the new test.OpGroupNonUniformShufflewith lane 37 (and the dynamic lane 69), so NVIDIA happens to wrap the out-of-range id itself; the result is still undefined by the spec. On a device that runs a wave32 program on a 64-wide subgroup (RADV without #316), lane 37 is an invocation outside the 32-thread dispatch, so I expect the old code to fail there, but I have no AMD GPU to check it.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository