fix(agc): lower hull exec masks restored through phis to own lane bits #4172
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4172"
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-12T00:34:17Z.
What
In a hull, each host invocation is one guest lane, so a lane mask can only be kept if every use reads the invocation's own bit. Tessellation lowering recognised that for a ballot-derived saved exec, but a wave64 hull that narrows EXEC with
s_and_saveexec_b64and restores it through phis (also inside a scalar loop) was refused as "uses a lane mask other than its own lane's bit".SelectU32and phis boolean selects and phis (loops included), all-zero or all-one words constants. Both halves must have the same shape and ballot the same predicate; wave32 uses the low word only.s_mov_b64 vcc,s_cbranch_vccnz) otherwise kept its block condition on the replaced word and failed SPIR-V emission. Fix and test by @EagleBearerYS.PPSA26344's first terrain hull (0x80002fc700) restores its exec this way; with this change its replayed request gets past the lane-mask refusal.
#5457 builds on this stack and edits the same lowering and test file.
Tested
Based on
mainf265cd55. Windows 11 (MinGW-w64 GCC 15.2.0) and Linux: configure -DBUILD_TESTING=ON, targeted test builds, ctest:agc_driver_tessellation,agc_shader_memory,agc_driver_graphicsandagc_tessellation_factor_ringpass (4/4); on #4222's head, withagc_driver_bda_device, 5/5main: the same 5 tests pass (5/5)log_macros, which fails onmaintoo; Linux (upstream's job in WSL) merged withmain5a81f608: 1089/1091,agc_driver_bc_block_copyandagc_driver_depth_compare_copyfail on thatmainas wellIn
agc_driver_tessellation,HullAndSaveexecis now a rendered check,HullSaveexecLoop(exec restored through loop phis, with a dead mask accumulator) is new and rendered,HullLaneCount(s_bcnt1_i32_b64 execas data) is still refused, andRequireCompareBranchescompiles a hull and a domain that branch on a compare copied to VCC.agc_shader_memorychecks that domain wave reductions unders_orn2_saveexec_b64still reduce on 32 and 64 lanes. They fail onmainwith the lane-mask refusal; without the identity replacement the compare-branch hull fails with "branch condition ... was not emitted before the branch".Not tested: console behaviour.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-12T02:56:47Z.
I force-pushed this (and restacked #4201 and #4222 on it) after a Yōtei run found a problem the first version caused. The own-lane-bit rewrite also ran in domain and local programs, and there it turned
s_orn2_saveexec_b64 vcc, execinto plain booleans before the half-wave reduction matcher could see the exec words. The terrain domain program's two wave reductions then failed with "v_readlane_b32 of lane 63 is outside the 32-lane host subgroup".The rewrite now runs in hull programs only, which are the only ones that need it. The terrain hull's SPIR-V is byte-identical, and
agc_shader_memorygained three domain checks (UMin on 32 lanes, OR on 64, divergent keys) that fail on the previous head with the game's message.Checks after the change
main34a16b7f: 924/925 pass;agc_driver_depth_compare_copyalso fails onmain.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T12:54:27Z.
Rebase handoff — rebased on top of the rebased chain (
rebase/4114→rebase/4163→ this), all on currentmain. Authorship unchanged.One test-file conflict with main's newer
ShaderMemory.cpptests: both sides added independent tests at the same spot — kept main'sv_movreld_b32window tests and this PR's domain-stage reduction test together.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesTo pick it up (pull the chain in order):
Heads:
rebase/4114=d0ea5f4d1,rebase/4163=652f2763d,rebase/4172=65ad9582b. #4201 on top of this is next.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T13:41:08Z.
lowerOwnLaneBitsreplaces lane-bit words withReplaceAllUsesWith(bit), butBlockInfo::conditionis a plain pointer, not a use. Take a hull that branches on a compare copied to VCC (v_cmp_* s[n:n+1],s_mov_b64 vcc, s[n:n+1],s_cbranch_vccnz):branch condition Unreachable of block 0 (defined in no block) was not emitted before the branch.Resident Evil Village (PPSA01556) hit this in a domain program through the old
SavedLaneBitloop, which has the same pattern. With your chain that program no longer goes through it, but a hull test with such a branch still fails on #4222's head (3a72fa3fa). The front end avoids this by replacing through an identity. Doing the same here fixes it:Fix and test, on #4222's head
Village also needs two tessellation changes your chain doesn't have:
All three are rebased on #4222 with tests, red/green on Windows, and passing on Linux. With them, 19 of Village's 21 dumped tessellation programs compile on your chain. The other 2 only miss #4114's patch bound, because the dumped requests carry no NUM_PATCHES; at 128 or 170 patches all 21 compile.
How would you like them? I could open them as PRs that depend on #4222, you could take the
lowerOwnLaneBitsfix into #4172, or they could go tomainfirst. They conflict with your chain inTessellationLowering.cpp,ShaderInputInfoBuilder.cppand the tests, so I'd rather follow your order.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:25:41Z.
Review: DISMISSED
Thanks, the approach looks right. One blocker:
lowerOwnLaneBits(TessellationLowering.cpp:584) usesReplaceAllUsesWith(bit), butBlockInfo::condition(set inExecMask.cpp:206) is a plain pointer that the replacement doesn't touch. A hull that branches on a compare copied to VCC (v_cmp_* s[n:n+1],s_mov_b64 vcc, s[n:n+1],s_cbranch_vccnz) keeps its block condition on the replaced value, so after dead-code elimination SPIR-V emission fails withbranch condition ... was not emitted before the branch. @EagleBearerYS reported this above with a hull test and a fix that replaces through an identity, as the front end does. Please take that fix and itsHullCompareBranchtest (adjusted to this head), and check that the test fails without the change.Everything else I read looks consistent with the description: the half-wave matcher is untouched for local/domain programs and
HullLaneCountis still refused.agc_shader_memory,agc_driver_graphicsandagc_tessellation_factor_ringpass here;agc_driver_tessellationpasses on CI's lavapipe.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-14T01:56:39Z.
@adriadam10 @EagleBearerYS I've folded the block-condition fix into this PR's commit.
lowerOwnLaneBitsnow replaces the mask words through identities and resolves the block conditions afterwards, the same way the front end does, so a hull that branches on a compare copied to VCC keeps its condition through dead-code elimination. Thanks, @EagleBearerYS, for tracking this down and sending the fix with a ready test; you're credited in the commit message.The
HullCompareBranchtest is in as you wrote it, along with itsDomainCompareBranchhalf, moved onto this head asRequireCompareBranches. With the oldReplaceAllUsesWithit fails with the same "branch condition ... was not emitted before the branch" error on the hull (the domain half compiles either way), and with the fix it passes together with the other tessellation and shader tests on Windows and on Linux.I also rebased onto current
mainand restacked #4201 and #4222 on the new head. While doing that I moved #4201's request version to 24, becausemainnow uses 23 for the pixel layer export flag. #5457 is stacked on the old heads, so it'll need a rebase onto these. On your question about the other two fixes, keeping #5457 as its own PR on top of #4222 seems right to me, since they're separate cases from what this chain handles. I'm happy to run it against Yōtei's hulls once it's rebased. Could you take another look when you have a moment?Details
New heads: #4172
8cbf91d5d2, #4201f823bf932f, #4222f33872bec3(based onmainee9037d8; all three still merge cleanly with currentmain).Without the fix (this head with only the
lowerOwnLaneBitschange reverted):With the fix, Windows 11 on an RTX 3080 Laptop GPU (driver 610.62):
agc_driver_tessellation,agc_shader_memory,agc_driver_graphics,agc_tessellation_factor_ring: 4/4 passagc_driver_bda_device: 5/5 passLinux (upstream's job in WSL, GCC 13.3, llvmpipe), #4222's head merged with
main: the same 5 tests pass (5/5).Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-14T02:54:06Z.
Thanks for folding the block-condition fix and its test into this commit, and for the credit.
I've rebased #5457 onto #4222's new head (f33872bec). Its two commits are unchanged apart from one test-array conflict, and its head is now 5589f924e. On my fork's full Build, with that branch merged into
main,agc_driver_tessellationpasses on Linux (lavapipe) with bothRequireCompareBranchesand #5457'sRequireSingleControlPointHullsin it, and the rest of the suite passes on Linux and Windows (run).Yes please on Yōtei's hulls, and thanks for offering.