feat(shader): add GDS ordered counts and ordered-append dispatches #5176
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5176"
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 n-delic on 2026-10-13T13:56:26Z.
What
ds_ordered_count(DS opcode 0x3f) now translates instead of throwing. Each wave adds its first active lane's value to a GDS counter with one device-scope atomic, and every active lane gets the counter's previous value, the same wayds_appendhands out ranges.DISPATCH_DIRECTandDISPATCH_INDIRECTacceptORDERED_APPEND_ENBL(initiator bit 3), the modifier such dispatches set.Compute shaders of MXGP 26 (PPSA30839, Unreal Engine 5) use both. On
mainthat title stops at the first such shader withds_ordered_count at pc ...: GDS counters updated in wave launch order are not modeled.Source of the operand fields: LLVM's lowering of
llvm.amdgcn.ds.ordered.add(SIISelLowering.cpp L8844-L8894, llvmorg-19.1.0):offset0is the counter index times 4, and the whole GDS address.M0holds the ordered wave ID, not a GDS address (radeonsisi_compute_prim_discard.cin Mesa 20.3 andgfx10_shader_ngg.cin Mesa 21.3, ACOordered_xfb_counter_add_amd: "The GDS address is always 0 with ordered append"). It only orders the waves, which is not modeled, so it is ignored.offset1bit 0 releases the wave and bit 1 marks it done; bits 2-3 are the shader type.offset1bit 4 selects swap instead of add.offset1bits 6-7 are the dword count less one.Not modeled, and recorded in
docs/dev/debt/shader.md:Swap, counts of more than one dword, and non-GDS forms still throw.
Tested
Linux (Pop!_OS, kernel 7.1.5), GCC, Release, RTX 3060 (NVIDIA 595.104.02).
agc_driver_gds_append_consume: a new pass runsds_ordered_count(release and done set) for wave32 and wave64 workgroups of 32 and 64 threads, once with M0 = 0 and once with M0 = 7 (a wave ID). Each wave adds its first lane id + 3. The test checks that:Changing the expected amount makes it fail (
GDS counter 0 is 1003, expected 1004). With M0 read as a GDS address, as in the first head, the M0 = 0 pass fails (wave 0 returned 0, expected 1000).agc_wave_control_decode,agc_driver_pm4: an add is translated, while swap and multi-dword counts are refused with their own messages.ORDERED_APPEND_ENBLis accepted, and other unknown modifiers are still refused.ctest -R 'agc|shader': 484 of 484 pass (one Vulkan test skipped as onmain).MXGP 26: with this change (on a branch with other local fixes), the shaders that used it run and the title reaches its main menu.
tools/check_conventions.py --base upstream/mainpasses.Windows (RTX 4080, UHD 770) and macOS (M2 Max, MoltenVK) runs by reviewers are in the comments, on the first head.
Not tested: AMD hardware, the hardware oracle.
Checklist
main; no other open PR implements the same functions (#980 decoded the opcode only and was closed)NotImplemented_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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-13T14:49:33Z.
Windows run, since the description says Windows is untested. Setup: Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,ctest -j4 --timeout 300. Head merged intomain69b4ca5d9. Two GPUs: RTX 4080 (NVIDIA 617.42) and Intel UHD 770 (101.6129).agc_driver_gds_append_consumeruns on both GPUs and printsgds append consume tests passed; it is not skipped.agc_driver_pm4andagc_wave_control_decodealso pass on both.Not tested: AMD hardware, the hardware oracle, a title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-13T17:54:55Z.
A second title for this: Silent Hill: Townfall (PPSA33286, Unreal Engine). Windows 11, RTX 3070, GCC 15.2.0, Release.
61b8742b6the title presents frames at 3840x2160, then stops atAGC driver: DISPATCH_DIRECT at DWORD 2309: dispatch modifiers 0x49 are not implemented(ORDERED_APPEND_ENBL | ORDER_MODE).8cf6a0bc3+ this head (bb17e6110) that dispatch is accepted. The title then stops at the next compile, in the same compute shader, before itsds_ordered_countis reached, so I cannot confirm the ordered count itself in the title yet.The shader (
0x16402d6e00, wave64;0x1640286900and0x16402b0500have the same code) uses the form this PR covers: a DPP prefix sum over the wave,v_readlane_b32of lanes 31 and 63 for the wave total, thenand appends to a buffer at the returned base, so only the order of the appended ranges differs from hardware, as the debt entry says.
What stops it now is the call just before that (
computed/data-dependent s_swappc_b64 call target at program counter 0x00000134): the target pair is read through a descriptor loaded from the constant address0xF_E0040000, not from user data. I left a note on #4706, which links table-loaded call targets from user-data descriptors.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:31:35Z.
Review: CHANGES_REQUESTED
Thanks. Build, the touched agc tests and a negative check are fine here (
agc_driver_gds_append_consume,agc_driver_pm4andagc_wave_control_decodefail without the change). One problem blocks the merge:M0 is read as a GDS address, but on
ds_ordered_countit holds the ordered wave ID.SharedMemoryInstructions.cpp:304passes M0 to theds_appendpath, which takes the base from M0[31:16] and skips the add when M0[15:0] is 0 (SpirvMemoryInstructions.cpp:1187-1193). Every user of the instruction I could find puts the ordered wave ID in M0, and the counter address is onlyoffset0:si_compute_prim_discard.c(Mesa 20.3):ordered_wave_id = (TG_SIZE >> 6) & 0xfffis passed as thellvm.amdgcn.ds.ordered.*pointer, with the comment "The GDS address is always 0 with ordered append";gfx10_shader_ngg.c(Mesa 21.3):ngg_get_ordered_id()(gs_tg_info[11:0]) is the pointer;nir_intrinsic_ordered_xfb_counter_add_amd:m0 = ordered_id, address VGPR 0.The LLVM lowering cited in the description only copies the pointer operand into M0, so it does not support "M0 is the GDS address". Our compute entry fills TG_SIZE's wave-ID bits with 0 (
InstructionTranslator.cpp:229-236), so a shader that builds M0 the way these do gets M0 = 0: the counter is never updated and every wave receives 0, which means they all append at the same base. The test setsm0 = 0xffff(GdsAppendConsume.cpp:50), theds_appendform, so it can't see this.Suggested direction: address the counter by
offset0alone and leave M0 out of the address and the bounds check. Add a pass with M0 = 0 and one with a small wave ID in M0, and correct the M0 sentence in the description and indocs/dev/debt/shader.md.The rest looks right to me: the
offset1decoding matches LLVM/ACO'sds_ordered_count_offsets, swap and multi-dword counts throw, the lane-varying result is inLaneSource, and the debt entry records the launch order that isn't modeled. We couldn't run this on the hardware oracle (no GDS ordered append through HSA).Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-14T17:18:39Z.
Run on an Apple GPU, next to the RTX 3060 and the RTX 4080 and UHD 770 runs above.
GPUs tested: Apple M2 Max, MoltenVK 1.4.2 (Vulkan 1.4.357), macOS 27.2, x86-64 under Rosetta
maindoes not run the GPU tests on macOS yet, so I tested onmacos-portatb7eb6b6b(mugurc/AnyPS5) with this PR's diff applied, not onmain. Release build, LunarG Vulkan SDK 1.4.363.0. The suite isctest -R agc -E 'flip|display|lds_atomics64' -j1 --timeout 30. Without the PR, 22 tests fail on this branch, all of them known macOS failures listed in #1. Headbb17e6110. The diff applies cleanly, exceptdocs/.agc_driver_gds_append_consumepasses, and is not skipped. With only the test files applied to the unchanged branch, it fails withds_ordered_count at pc 16: GDS counters updated in wave launch order are not modeled, so the new pass runs here.agc_driver_pm4andagc_wave_control_decodepass.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-14T18:23:59Z.
Silent Hill: Townfall (PPSA33286) runs into what @adriadam10 describes. The compute shader at
0x16402d6e00(wave64) builds M0 for itsds_ordered_countfrom an ordered wave ID and a high half, not from a GDS address:Windows 11, RTX 3070,
maine34c47921+ this PR at bb17e6110. The shader also makes a computeds_swappc_b64at 0x134 thatmaincan't link yet (separate from this PR), so all three runs used a local stub that skips that call. One 900 s run each:GameThread timed out waiting for RenderThread after 120.00 secsoffset0alone (M0 left out, as suggested above)So the suggested direction also fixes the hang this title hits. Runs of this title are somewhat flaky, so treat one run per row as an indication, not proof. I can test a new head on it.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by n-delic on 2026-10-14T19:03:51Z.
@adriadam10 Thanks, you're right. Fixed in 8b25a9486:
offset0alone. M0 is no longer part of the address or the bounds check, and the translation doesn't read it.GdsAppendConsume.cppruns the ordered pass with M0 = 0 and with M0 = 7. With the first head's M0 addressing, the M0 = 0 pass fails (wave 0 returned 0, expected 1000).docs/dev/debt/shader.md(citing the radeonsi sources you listed) and in the description.ctest -R 'agc|shader': 484 of 484 pass, andcheck_conventions.pypasses (Linux, RTX 3060).@tv7 Thanks for the Townfall runs. The new head should behave like your "offset0 alone" row.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T19:27:55Z.
Review: APPROVED
Re-checked 8b25a9486: the counter is addressed by
offset0alone, the M0 = 0 and M0 = 7 passes inGdsAppendConsume.cppfail on the first head's M0 addressing, and the debt entry now describes M0 correctly.agc_driver_gds_append_consume,agc_driver_pm4andagc_wave_control_decodefail without the change.The branch conflicted with main in
docs/dev/debt/shader.md(adjacent line from thes_swappc_b64entry); I rebased it, keeping both lines. Build and the touched agc tests pass on the rebased tree. Merging once the full Build is green.