fix(shader): prove masked lanes unread across exec phis, loops and image operations #3279
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3279"
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-11T05:02:23Z.
Carried from @AlxcBTW's fork (AlxcBTW/AnyPS5#37, commits 1-5; @xXPBSXx's commit kept under his name); the intake pause closes PRs opened from that account.
What
Refs #2548. Pixel shaders that read the packed ancillary VGPR once and then reuse the register are refused with
The later writes become
SelectU32(mask, new, ancillary), so the raw word stays in the lanes the mask excludes.MaskedSelectEliminatordrops such a select when it can prove those lanes are never read. This PR lets it prove that in more programs. It removes a select only when the proof holds; a select it cannot prove is kept and refused as before, so no ancillary bit is produced and the gfx1013 layout question does not come up here.Commits, cherry-picked unchanged onto
main961b25fe:c2a48416follow exec phis and long kill chains. Kill paths save and restore exec, so later execs are phis at block merges, and the kills' AND chains go past the eight-level limit. To check that a later exec implies the write's exec, the pass now accepts a phi outside loops whose incoming values all imply it, pairs low and high exec words merged in one block predecessor by predecessor, memoises results per select and follows up to 64 levels. A cycle counts as not implied.cd4eaacfscale the walk limit with the program. The limit is max(4096, 2 x instructions) steps, linear per walk, and the walk uses id-indexed tables instead of hash sets.98f99d38loops. A loop phi implies the write's exec if every incoming value does. The phi is assumed to imply it while its back-edge values are checked, and results that relied on a failed assumption are discarded. The write's exec must be computed outside any loop.83f8c193image reads (@xXPBSXx, his6f9f48d7unchanged).ImageReadcarries the exec as its last operand like the buffer loads and fetches only where it is true, so it joinsreadsOnlyWhereActive.fda4aa90image writes, explicit-LOD gathers and size queries.ImageWritestores inside an if on its exec operand, so it joins the exec-guarded list.ImageGatherRawwith its own LOD, or outside pixel shaders, andImageQueryDimensionsare lane-local.ImageQueryLod, implicit-LOD samples and gathers,ImageBvhIntersectRayand the atomics are left out.Not included: the rest of AlxcBTW/AnyPS5#37 (a whole ancillary word for reads the walk keeps, and the trace switch). A read the walk cannot drop is still refused; Returnal and Minecraft Dungeons II need that part.
#2654 changes the visited storage of the same walk and conflicts with commit 2.
Tested
Linux (CachyOS, GCC 16.2.1, Release, CI's configure flags without ccache), RTX 4090 (NVIDIA 610.57.04),
main961b25feplus the five commits:agc_masked_selectandpixel_ancillarypass. WithMaskedSelectEliminator.cppput back tomain, both fail:agc_masked_selecton the kill-chain, loop, image read, image write, gather and size-query cases, andpixel_ancillarywith the refusal above.ctest -R "agc|shader": 349/350. Fullctest: 758 tests, 1 failure, 5 video-out tests skipped. The failure in both isagc_driver_dcc_keys_first_write, which fails the same way onmain(#3179).tools/check_conventions.pypasses.From #2548, on earlier states of the same commits:
0x2026c60000recompiles inagc_shader_replay. Two shaders stay refused and the title still aborts on one.Runs of the whole fork branch (these commits plus the whole-word part):
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 adriadam10 on 2026-10-11T07:19:38Z.
Checked on Linux (Release, partial build of libs + AGC):
agc_masked_selectandpixel_ancillarypass, and both fail withMaskedSelectEliminator.cppreverted tomain.ImageRead/ImageWritetake their exec as the last operand and the SPIR-V emitter guards them with it, so listing them as read-only-where-active is exact. Loop revival and wider-exec cases keep the select. Merging.Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:19:51Z.
Additional platform validation of standalone PR head
fda4aa90c9f81fa3b5160150b3bee926b6923955(2026-10-11):Windows: passed — Windows 11, WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja; Release,
BUILD_TESTING=ON.2 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.
Checks:
agc_masked_select,pixel_ancillary.Command after building:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^(agc_masked_select|pixel_ancillary)$".This scope checks CPU-side behavior; no GPU execution result is claimed.
No title/gameplay validation. These results cover the standalone head, not a merge with current main.