feat(shader): implement s_subvector_loop_begin and s_subvector_loop_end #3750
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3750"
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 fma-rc on 2026-10-11T16:26:40Z.
What
s_subvector_loop_beginands_subvector_loop_end(SOPK 0x1b / 0x1c) threwGNM subvector loop instructions are not supported by this translator. Astro's Playroom (PPSA01325) stops on that: a wave64 mesh shader of the title has one such pair around a 32-lane stream compaction.Both are now translated for wave64 shaders, with
D0the SGPR operand:That is the pseudo-code of AMD's RDNA 2 instruction set reference, with the
S0it tests in the end instruction read asD0. I measured it on a Radeon 610M (gfx1036, wave64; ieee 0, dx10_clamp 1, denorm32 0, denorm16 3, round32 0, round16 0, fp16_overflow 0): two loop bodies, one that leaves EXEC alone and one that ends withs_mov_b64 exec, -1as the title's does, each with seven initial masks. Every row matches the pseudo-code. Script and raw output: https://github.com/fma-rc/AnyPS5/tree/evidence/subvector-loop-oracle/oracle-subvector-loopTwo smaller changes come with it:
SpirvSpecialization.cpp: when the loop body ends withs_mov_b64 exec, -1the back-edge condition is a constant false, and the pass folded that branch away, leaving anOpLoopMergeheader with no back edge. NVIDIA 615.78.08 segfaults compiling that. A constant-condition branch whose untaken target is a loop header is now kept.EmbeddedVertexFetch.cpp: both opcodes are listed as exec writers.Not covered: a wave32 shader and a destination that is not an SGPR throw (not measured). Only a compute shader is tested. A loop whose back-edge block becomes unreachable some other way can still lose its back edge. PS5 hardware was not measured.
Tested
Arch Linux, GCC 16.2.1, Release,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1,maina11c8f7f(the "this branch" row was run again after the rebase ontomain0a8b1d32b, same results). New testagc_driver_subvector_loopruns the measured kernel and checks all 14 cases, every lane and output.SpirvSpecialization.cppchangeSo upstream's Linux CI will skip the 14 cases. Full ctest on this branch: 833 of 833 on RADV; on the RTX 5080 one failure,
agc_driver_emulated_color_compare, which is also red inmain'slinuxCI job.tools/check_conventions.py --base origin/mainpasses.Astro's Playroom on the RTX 5080 with this branch, #3669 and #425 merged onto
maina11c8f7f: one 300 s run ends at the timeout without the error, where the same build without this branch stops on it afterLoadLevelResources: cpuplaza_mini_04. What the title shows on screen was not checked.Not tested on Windows.
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-11T21:58:28Z.
Measured both instructions on RDNA2 (gfx1035, wave64): the two loop bodies of the test (EXEC kept /
s_mov_b64 exec, -1) over 64 initial masks (the 7 of the test plus edge and random ones), all 9 outputs per lane, match this translation bit for bit. Test passes on RADV with the validation layer clean, and fails without the change.One correction to the description: on current
maintheSpirvSpecialization.cppchange is needed on every driver, not just NVIDIA. Without it the recompiler's own SPIR-V validation rejects the module (Loop header ... is targeted by 0 back-edge blocks but the standard requires exactly one), RADV included. I rebased ontomainand added one commit that names that rule in the TechnicalDebt line. Merging.