feat(agc): accept the dispatch and indirect packet forms vkQuake's RADV emits #2756
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2756"
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 TheAggie on 2026-10-10T13:07:18Z.
What
Split out of #1917 at review's request. These six commits came from running vkQuake (PPSA99010, the homebrew Vulkan port) through RADV on the PS5 (mihawk-99/PS5_Mesa). They change how many threads a dispatch runs and how indirect draws and dispatches are decoded, so they get their own review here. #1917, with the ccleste packet forms, is merged.
PARTIAL_TG_ENin the initiator and puts each axis's last-group size in the upper half ofCOMPUTE_NUM_THREAD_X/Y/Z. The dispatch now runs(groups - 1) * full + lastthreads per axis through the dispatch-size limitUSE_THREAD_DIMENSIONSalready uses, or plain groups when every last group is complete. A zero or oversized last group throws (Pm4::PartialGroupThreads).DecodeComputeStageInforeads onlyNUM_THREAD_FULL(bits 15:0); it read the whole register, so a partial size would have widened the workgroup.COPY_DATAfrom memory to context registers. Where it doesn't useLOAD_CONTEXT_REG_INDEX, RADV loads clear values intoDB_STENCIL_CLEAR/DB_DEPTH_CLEARandCB_COLORn_CLEAR_WORD0/1withCOPY_DATAto a register (DST_SEL0, one or two dwords). It isn't a memory store, so the packet drains like otherCOPY_DATAthe driver can't record on the GPU, and executing it reads the source then and writes the registers. Register, GDS, immediate and clock sources, and destinations outside the context registers, are still rejected.COPY_DATAto memory throughDST_SEL5 (COPY_DATA_DST_MEMin Mesa'ssid.h), the current form of the deprecated GRBM-synchronizedDST_SEL1 already accepted. RADV uses it for every memory destination; vkQuake's timestamp writes hit it.ORDER_MODEfor a dispatch that needs in-order wave launch. That is the stricter guarantee and the driver doesn't reorder waves, so a direct or indirect dispatch now needs onlyCOMPUTE_SHADER_EN.DRAW_INDIRECTandDRAW_INDEX_INDIRECTwhen the vertex shader doesn't read the base instance, and as the draw-index location of the multi forms when draw IDs are off. The validator accepted only0x280as "no register"; 0 is now accepted and decoded as0x280.SET_BASEto the argument buffer address plus the command's offset, which Vulkan only requires to be a multiple of 4 (vkQuake's ends in0x14). The validator required 8-byte alignment; the records are read as 32-bit words, so a 4-byte-aligned base is now accepted and a 2-byte-aligned one still rejected.Tests (
agc_driver_pm4,agc_driver_graphics):PartialGroupThreadsfor complete, partial, empty and invalid last groups;DecodeComputeStageInfoignoring the partial half;COPY_DATAwriting one and two context registers, not resolving as a store, and rejecting an immediate source, a non-context register, an overflowing range and a misaligned source;DST_SEL5 with an immediate and a 64-bit timestamp; initiators0x2047,0x2007and indirect0x2005accepted and0x40rejected. Each new check fails with its change reverted.Tests for these two (
agc_driver_pm4): location 0 inDRAW_INDIRECTand in the multi form resolves to0x280, and an out-of-range location (0x200) is still rejected; aSET_BASEending in0x14is accepted and one ending in0x12rejected. Each fails with its change reverted.Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti.
maincf8b129e2. Full suite: 551 of 554 pass, 1 skipped. The two failures,agc_driver_prepared_shaders_debug_failureandguest_memory, fail the same way on cleanmaincf8b129e2on this machine. It was run from the generatedCTestTestfile.cmakecommands because antivirus blocksctest.exeon this machine.tools/check_conventions.pypasses.mainalone yet: it stops atFAIL: unresolved ELF import 1nTKA7pN1jw from libSceLibcInternal.prx(utime, #2024), and 13 more imports are missing after that. I have not rerun it since this rebase.Not tested on AMD, Intel, Linux or macOS on this head.
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 fma-rc on 2026-10-10T14:08:15Z.
Tested merged onto
main78aedb40with a temporary test (Linux; NVIDIA RTX 5080 and RADV on a Radeon 610M, same results on both).1. The fill fast path ignores
PARTIAL_TG_EN.fillBuffer/copyBufferreturn inDispatch.cppbeforePartialGroupThreadsis called, andDecodePatternFillRangeonly knows initiator bit0x20. WithPatternFillKernel,0x207..0x209 = {0x00100040, 0x00010001, 0x00010001},DISPATCH_DIRECT {2, 1, 1, 0x43}, control count and records 256:0x410x43(groups - 1) * full + lastgives 80)0x207 = 0x00000040), initiator0x43mainrejects initiator0x43, so this path is new with this PR.2.
PartialGroupThreadsreturns instead of throwing in two cases.({0x10002, 1, 1}, {0x0001ffff, 0x00010001, 0x00010001})returns{0, 1, 1}: the 32-bit product wraps. Only reachable with absurd sizes, but it is a silent wrong limit.({1, 0, 1}, {0x00100040, 0x00010001, 0x00000001})returns{0, 0, 0}, while({1, 1, 1}, …)with the same registers throws: the early return on a zero group count skips validating the remaining axes.3. Question:
Validatenow accepts initiator0x63(PARTIAL_TG_ENwithUSE_THREAD_DIMENSIONS).Dispatch.cppthen setspartialThreadsfrom the packet words as thread counts and overwrites it treating the same words as group counts. Is that combination meant to be accepted?The new tests in
tests/Pm4.cppcallValidateandPartialGroupThreadsdirectly; none of them drives a dispatch with bit0x2, which is why 1 isn't caught.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T19:17:56Z.
Points 1 and 2 from fma-rc need fixing first: the fill/copy fast path in
Dispatch.cppreturns beforePartialGroupThreads, so initiator0x43fills whole groups and a zero last group doesn't throw; andPartialGroupThreadswraps its product and stops validating after a zero group count, where both should throw. For 3, either reject0x63inValidateor decode it once. A test that runs a dispatch with bit0x2through the driver would have caught 1.Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-10T19:43:01Z.
Thanks @fma-rc and @oneandonlydean. Fixed in 7c72f048 (a new commit on top, so the change is easy to review):
Dispatch.cppnow decodes the partial sizes beforefillBuffer/copyBuffer. When the last group is partial, it skips both fast paths and runs the shader withpartialThreadsset. A zero or oversized last group now throws there, before either fast path.PartialGroupThreads.({1, 0, 1}, {0x00100040, 0x00010001, 0x00000001})now throws.(groups - 1) * full + lastin 64 bits and throws when that doesn't fit in 32, so({0x10002, 1, 1}, {0x0001ffff, …})throws instead of wrapping.0x63.Validatenow rejectsPARTIAL_TG_ENtogether withUSE_THREAD_DIMENSIONS.Tests:
agc_driver_pattern_buffer_fillnow runs the fill kernel through the driver with0x207..0x209 = {0x00100040, 0x00010001, 0x00010001}andDISPATCH_DIRECT {2, 1, 1, 0x43}(control count and records 256), in wave32 and wave64. It checks that exactly 80 dwords are written. With theDispatch.cppchange reverted, it fails at index 80.tests/Pm4.cppgains the two throwingPartialGroupThreadscases and the0x63rejection.agc|shader|recompiler|pm4|dispatchpasses: 322 of 322 on Windows 11, RTX 5070 Ti, MinGW-w64 GCC 15.2.0.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T20:01:32Z.
Re-tested at 7c72f048 merged onto
main9206c3e6(Linux; RTX 5080 and RADV on a Radeon 610M, same results on both). The three points are fixed here, and I have two new ones.Fixed, by run through the driver (
PatternFillKernel, 64-thread groups):0x430x430x430x00400040),0x430x20070x43COMPUTE_NUM_THREAD partial group size is zero or exceeds the full groupagc_driver_pm4,agc_driver_pm4_failure,agc_driver_graphicsandagc_driver_pattern_buffer_fillpass on both devices, andagc_driver_pattern_buffer_fillfails withDispatch.cppreverted tomain.1. The
ResolveStoreassertion does not test its guard.tests/Pm4.cpp:387uses register0xa00a. With|| copyDataToRegister(packet)removed fromPm4.cpp:597the test still passes, because0xa00a % 4 != 0andfits()already returnsnullopt:Pm4.cpp:597agc_driver_pm40xa00a0xa00a0xa00cCOPY_DATA to a register resolved as a memory store0xa00cA register number that is a multiple of 4 makes the assertion cover the guard.
2. A dispatch with a start offset is run from 0, and the partial arithmetic now applies to it. With
COMPUTE_START_X(0x204) = 1 andFORCE_START_AT_000clear:0x410x45(FORCE_START_AT_000set)0x43RADV emits this form when a dispatch has a base offset, and then the packet words are end values, not counts (
radv_cmd_buffer.c:15212):Read that way, the first row is group 1 only and the third is groups 1 and 2 with a 16-thread last group;
Dispatch.cpp:75passes the packet words toPartialGroupThreadsas counts. Accepting0x41with a start offset is probably older than this PR (I did not run the probe onmain); the0x43row is new with it. Throwing when bit0x4is clear and a start register is non-zero would keep it from running wrong.Not checked: vkQuake itself, the copy kernel with a partial last group, partial last groups on Y and Z through a shader,
COPY_DATAto a register through a full submission.Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-10T20:18:48Z.
Independent local validation of 7c72f048
Tested your current head
7c72f0487cf838feabb180c8fedd4357fe008d81as seven cherry-picked commits onto main43d2a7c4c00dd532076af30d2b75243ac10ad6c7. Windows 11 Enterprise 26200, RTX 5080, WinLibs r7 GCC 15.2.0, Release, BUILD_TESTING=ON. Full system libraries built.agc_driver_pm4,agc_driver_pm4_failure,agc_driver_graphicsandagc_driver_pattern_buffer_fillall passed five repetitions, no skips, each below 30 seconds. Full suite, Linux and console hardware were not tested.I reproduced the two points in fma-rc's latest comment independently:
agc_driver_pm4withCOPY_DATA to a register resolved as a memory store. This confirms the alignment issue with the original assertion.For local diagnostic use I added an explicit refusal of known nonzero COMPUTE_START_X/Y/Z when FORCE_START_AT_000 is clear, before fast paths/preparation. Separate driver cases cover X/Y/Z for direct, partial and indirect dispatches, verifying refusal and unchanged output. FORCE_START_AT_000 controls execute all three axes and verify the written/untouched range. The 12 new groups plus the four above passed five repetitions. Removing the start guard makes its direct-X case fail. Both mutation sources were restored byte-for-byte, full libraries rebuilt, and all 16 groups passed five repetitions again. The guard and stronger COPY_DATA assertion are separate unpublished local topic commits (
6b8f9a4d,9e7fb76f), not new PRs.PPSA99902 (Sonic Unleashed Recompiled) also reaches your exact dispatch form on a conditional local startup stack: captured
DISPATCH_DIRECT {0x50,1,1,0x2047}, with COMPUTE_START_X/Y/Z all zero and NUM_THREAD_X/Y/Z{0x00400040,0x00010001,0x00010001}. The last groups are complete and FORCE_START_AT_000 is set. Five prior-stack runs refuse that initiator. Title comparison is now complete on the same pinned main43d2a7c4: before stack d25142cb, proposal/adapters stack60d016a7. Profiles differ only in libSceAgcDriver.prx. Five controlled strict-filter runs pass this initiator and stop later atDescriptorBindingBuilder::Populate multisampled image resources have no descriptor image shape(29.048, 29.090, 29.520, 28.871, 28.632s), with the BDA write-back warningmore than 4096 pages stored to through the BDA table in one use are not implementedbeforehand in all five. Before/after restored controls reproduce the0x2047refusal (28.566/28.805s). No run timed out; baseline libraries/guest libc/original executable were restored/hash checked. The refreshed integrated selection passed 46 groups five times, no skips, maximum 4.21 s. An initial full-profile pilot also changed two dependent wrapper binaries and was excluded from the single-driver comparison. Default filtering still misses pathconf. The actual multisampled resource and BDA page count remain under investigation. This is not a gameplay or console-semantics claim.One source question remains outside these tests: the PR accepts ORDER_MODE=0 because the driver does not reorder waves. AMD's register reference describes ordered wave launch, while Vulkan shader execution leaves relative invocation execution order undefined. These are different guarantees; the tests above do not establish that the host honors ordered wave launch. Is there a source or measurement establishing that this bit can be ignored without changing observable behavior? This title's captured 0x2047 has ORDER_MODE=1.
Logs, captured private title data, exact patches and hashes retained outside the repository. No branch push or new PR. AI-assisted validation/local changes: Codex.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:19Z.
The
ResolveStoreassertion attests/Pm4.cpp:387uses register0xa00a, whichfits()already rejects, so it passes with thecopyDataToRegisterguard removed; please use0xa00cas fma-rc showed. The nonzeroCOMPUTE_START_*case is older than this PR and can go in a separate one.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:15:28Z.
Checked at 7c72f048 merged onto main: build and the libSceAgcDriver ctest (354 tests) are green, and the new
agc_driver_pm4checks fail without their change.ORDER_MODEmatches Mesa (radv_device.csets it to allow out-of-order launch,radv_cmd_buffer.cclears it for ordered dispatches).Added one commit on top for @oneandonlydean's last point: the
ResolveStoreassertion intests/Pm4.cppnow uses0xa00c, so it fails if thecopyDataToRegisterguard is removed (verified). The nonzeroCOMPUTE_START_*case stays out of this PR.Merging once CI is green.