feat(shader): accept every SDWA selector on v_mov_b32 #751
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/751"
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 Celegans12 on 2026-10-05T20:39:46Z.
What
v_mov_b32_sdwathrewVOP1 SDWA destination selector 1 (unused 2, source selector 0) ... is not supportedwhen a byte source (src0_selBYTE_0..3) met a partial destination (dst_selBYTE_0..3, WORD_0/1): the VMovB32 rule allowed only WORD and DWORD sources there.src0_sel,sext,dst_selanddst_unusedcombination is now accepted. Translation already implements them (applyBitSourceModifiers,writeRawU32): the selected field is zero- or sign-extended, and the result's low bits go to thedst_selfield with the other bits zeroed (UNUSED_PAD), sign-extended above and zeroed below (UNUSED_SEXT) or kept (UNUSED_PRESERVE).dst_unused3, and neg/abs on sub-dword sources.v_mov_b32_sdwa v3, v3 dst_sel:BYTE_1/2/3 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_0(0x7e0602f9 + 0x00001103/0x00001203/0x00001303 at 0x4b64/0x4b6c/0x4b7c). These three are the only byte-source partial-destination moves among the game's 5,859 shaders that usev_mov_b32_sdwa.RdnaVectorOpDecoder.cpp; they merge cleanly with this branch.Tested
main9cafa33f: configure-DBUILD_TESTING=ON, full build,--target libs,ctest:ctest --output-on-failure)agc_driver_sdwa_move_selectorsruns all 294 combinations as wave32, wave64 and wave64 on 32-lane subgroups, plus the game's three in-place words under a partial exec mask, on the GPU (RTX 3080 Laptop and Intel UHD); expected values come from an ISA model. Newagc_vop1_sdwa_move_decodechecks the decoded operands for all 294 and that the reserved encodings throw. Onmainthe GPU test fails at its first byte-source move with the message above, and the decode test reports the 144 byte-source partial-destination combinations.agc_driver_image_sample_derivatives: therethreadBitreads an EXEC written withs_mov_b32from EXEC_LO at the subgroup invocation id, onmaintoo.mainit fails at decode; with this change it decodes and translates (3,340 instructions) and stops at an unrelated gap, a loop-indexed image descriptor (s_load_dwordx8at 0x131c). 352 other game shaders that usev_mov_b32_sdwagive identical results with and without this change.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 (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T23:37:37Z.
The Linux CI re-run now gets through ctest and fails in this PR's own test (run 37383475649, attempt 2, llvmpipe with 8-wide subgroups):
What the log narrows down:
wave64dispatch (device->Target()). Thewave64 splitrun isn't reached.EXEC_HI = 0x3c3c3c3c, set bys_mov_b32 exec_hi. The lower half underEXEC_LOpassed.Here, on NVIDIA, the test passes 20 times in a row and Windows CI is green. Because of that, this may be how a partial
EXEC_HIwritten withs_mov_b32is handled when a wave64 spans several 8-lane subgroups, rather than the SDWA change itself. As far as I can see, no execution test onmainwrites a partialEXEC_HIthat way. Could you check, for example by adding a plainv_mov_b32under the same EXEC to see whether it also skips the upper lanes on llvmpipe? If it's amainissue, a separate fix (or a skip on small subgroups, with a note) would let this land.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T00:49:19Z.
Thanks. As you suspected, it is on
main, and it is not specific to SDWA or to EXEC_HI. On subgroups narrower than 32 lanes, when EXEC is written as a value (s_mov_b32/s_mov_b64), each lane reads its bit from EXEC_LO at its subgroup invocation id. So lanes 32..63 follow EXEC_LO's pattern rather than all keeping their old value; lane 36 is active and kept its source, as you read it.Mechanism. On a host subgroup narrower than 32 lanes, a wave64 runs one guest lane per invocation (
laneCountis 1 inSpirvEmitter::Emit).LaneIdlowers togl_SubgroupInvocationID(EmitLaneIdin SpirvAluEmitterMath.cpp, viaEmitSubgroupLocalInvocationIdin SpirvSubgroup.cpp).TranslationContext::threadBit(ExecMask.cpp) picks the lane's bit withlane < 32 ? exec_lo : exec_hiandlane & 31, so on llvmpipe (id 0..7) every lane takes bitidof EXEC_LO.Plain
v_mov_b32. Probe onmaincb33f858, no SDWA:s_mov_b32 exec_lo/exec_hi, thenv_mov_b32andv_add_nc_u32, every lane checked. It ran on the Intel UHD iGPU with compute subgroups forced to 8 and to 16 lanes (a local VulkanDevice change that sets the required subgroup size; not pushed). Both instructions wrote the same lanes:Why it is not fixed on
mainhere. EXEC from a compare is consistent on 8 lanes:v_cmp_gt_u32+s_and_saveexec_b64gives the expected 0x00000fff_ffffffff, because the ballot is subgroup-local too. Taking onlyLaneIdfrom the wave lane (LocalInvocationIndexmodulo the wave size) fixed the literal masks but broke that compare case: only lanes 0..7 stayed active. A fix would needLaneIdfrom the wave lane and each subgroup's ballot placed at its wave offset, plus matching changes in readfirstlane, mbcnt and the cross-lane ops (shuffles, DPP, permlane), and wave-wide ballots for whole-mask scalar uses. That is a larger change than this PR, andmainalready skips EXEC-masked cases below 32 lanes (agc_driver_image_sample_derivatives).Change. Rebased on current
main. The broadcast check now follows that precedent: whenTarget().subgroupSize < 32, it printsEXEC-masked broadcast skipped, subgroup size N cannot hold a wave32and skips the check. The 294 full-EXEC combinations still run on every device.One side note: in that run Windows CI reports this test as Skipped, like the other GPU tests, so llvmpipe is the only CI job that actually executes it.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T03:27:19Z.
Thanks for tracking that down. The skip follows the existing DPP/swizzle precedent (
Target().subgroupSize < 32), it only drops the masked broadcast check, and the 294 full-EXEC combinations still run in all three passes, so this looks good to me.The literal-EXEC behaviour you found on narrow subgroups is a
mainlimitation rather than something for this PR. It might be worth a TechnicalDebt line at some point (EXEC written as a value is read per subgroup invocation from EXEC_LO when the host subgroup is narrower than 32), since it isn't written down anywhere yet.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T03:34:36Z.
Thanks. The TechnicalDebt line is up as #800 (documentation only).