fix(shader): keep s_cselect_b64 of two masks as a lane bit and fold constant masks #1640
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1640"
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 morten-holm on 2026-10-08T15:25:08Z.
What
s_cselect_b64 sd, exec, 0(and the same form with vcc or all ones) gives a mask that is the same for every lane. The translation stored it as a plain register pair, so a later read of the pair went throughLaneId. Metal has no lane number in a vertex shader, and MoltenVK rejects such a shader ("subgroup capability 61 is unsupported for shader stage 1"), so the draw is skipped.s_cselect_b64with two mask sources now stores the lane bitscc ? source1 : source2and marks the pair as a mask, the same wayv_cmpresults are kept. The sources are read before the destination is written.((W >> (x & 31)) & 1) != 0to a constant whenWis all zero or all one. Some masks only become constant after folding.The translation is exact. Nothing changes when the lanes differ.
Tested
agc_constant_bit_test: fails without the fold (all-zero and all-one cases) and passes with it.link.h), so I ran the test and the existing masked-select, control-flow, shader-disk-cache and DPP-write tests on a macOS port tree that carries the same shader code: all pass. The four changed shader files compile on this branch.scalarSelectMask64translation by a unit test; it was only checked end to end on the title above.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T15:31:50Z.
Review: APPROVED
LGTM. Well-structured fix for the s_cselect_b64 mask handling issue on Metal/MoltenVK. The three-part approach is clean: (1) scalarSelectMask64 properly stores lane bits and marks pairs as masks, (2) foldConstantBitTest eliminates LaneId usage for constant all-zero/all-one masks, and (3) threadBit recognizes constant masks upfront. The test specifically validates the folding cases that were failing before. Good end-to-end testing on a retail title showing the MoltenVK error is resolved.
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T19:43:06Z.
Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head
8dc1a828, merged ontomain8b393b6ein one build with 31 other PRs that had no Windows run.agc_constant_bit_test.guest_offline_imports, broken by #2359 (reported there).No title was run.
🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:03:00Z.
Review: CHANGES_REQUESTED
Checked: build + ctest on Linux are green, and
agc_constant_bit_testfails when the non-test changes are reverted, so the folder part is covered. The translation looks right to me (sources read before the destination is written, same mask-tag pattern asv_cmp).One thing needed before merging:
scalarSelectMask64(ControlFlowInstructions.cpp:247) and the constant paths inreadMask/threadBit(ExecMask.cpp:21,:41) are not covered by any test; the PR description says so too. Please add a test (execution, or IR-level next toagc_masked_select_tests) that pins values:scc= 0 and 1, a non-constant source (lanes differ), destination equal to one of the sources, and a wave64 case where the two halves differ.Imported from boykopovar/AnyPS5. Originally posted by morten-holm on 2026-10-10T06:56:20Z.
The requested test is in:
agc_scalar_select_mask(tests/ScalarSelectMask.cpp, registered next toagc_constant_bit_test). It translates small wave64 vertex programs, runs the IR over every lane and pins the lane values, withsccset and clear, for:vccandexec, in both orders),vccholds the lanes below 40),s[4:5], andvcc),exec, zero, -1) and literal sources, including an all-ones literal in wave32 and in wave64.The constant cases also check that the select keeps both sources as IR constants, which is how
threadBit's constant path is covered.I removed the two constant returns in
readMaskin the same commit. With them gone the results are identical, becausethreadBitfolds the same constants, so no test can tell them apart and they only added code.To check that the test can fail, I changed the fix four ways: with
s_cselect_b64reverted it fails (the pair is not marked as a mask), with the two sources swapped it fails on lane values, with thethreadBitconstant fold disabled it fails on the wave32 case, and without thereadMaskreturns it still passes.I ran the test on macOS by linking the recompiler objects without libc (
main's libc does not build there), so the CI run is its first one through CMake.@adriadam10 could you take another look?
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:51:33Z.
Review: APPROVED
Checked on Linux (build + ctest):
agc_constant_bit_testandagc_scalar_select_maskpass, and both fail with the non-test changes reverted. Measureds_cselect_b64on hardware (gfx1035) with vcc/exec/0/-1/literal/SGPR-pair sources and scc set and clear: the result isscc ? source1 : source2and a literal is zero-extended, which matches what the tests pin. Thanks for adding the translation test; merging.