fix(agc): fold GPU-side indirect dispatches over the workgroup count limit #25010
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25010"
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 mariushub on 2026-11-21T14:49:49Z.
What
A
DISPATCH_INDIRECTwhose group counts stay on the GPU ran no workgroup at all when a count exceededmaxComputeWorkGroupCount:DispatchArguments.comp(#6360) writes 0x0x0 for such counts. The console takes 32-bit counts, and Y and Z are limited to 65535 on AMD and NVIDIA, so a title that dispatches more than 65535 groups along Y lost the whole dispatch. Direct dispatches over the limit already run in chunks (#7445); GPU-side indirect ones did not.PS2 Classics hit this: the PS2HD emulator's GS rasterizer (
gsKernelRenderTiles) is an indirect dispatch of one column of tiles, and with its default up-rendering a 3D scene needs more tiles than 65535. On Tomb Raider: Legend (PPSA22453) the menu dispatches it with 1x79988x1 and 1x169464x1 groups, so the rasterizer never ran and the menu stayed black (#23908). It does not happen with--gs-uprender=none, which needs four times fewer tiles. WALL-E's black menu (#19548) is also a PS2HD title; I have not tested it.With this change such a dispatch runs as one linear dispatch:
DispatchArguments.comp: when a count exceeds the limit and the program was compiled for an indirect dispatch, the kernel writesT x 1 x 1(T = x * y * z) and the original X and Y counts (words 6 and 7). It still writes 0x0x0 when T exceedsmaxComputeWorkGroupCount[0]or 2^31 - 1, or the dispatch has 2^32 invocations or more, so the garbage count #6360 guards against (0xffffffff groups) still runs nothing.VulkanDevice::recordDispatch: a program that reads the counts gets them copied into its ShaderData before the dispatch's leading barrier, as the thread-dimension limit already is, and zeros when the counts were read on the CPU. Split table call parts keep the old behaviour.ShaderComputeStageInfo::groupFold, set for aDISPATCH_INDIRECTof a program that reads its workgroup ids, makes the entry prologue rebuild those ids (and the global ids of a partial-group dispatch) from the linear id and a newDispatchGroupCountShaderData input; counts of 0 leave the ids as they are. Such a program keeps its ShaderData in a buffer, not in push constants, since the GPU writes the counts. A program that reads no workgroup id is folded without a separate variant. The flag is part of the recompile cache key, the dispatch cache key and the request serialization (version 64); the disk cache format moves to 96.ShaderResources::shaderDataAllocationto find the binding of a program with an image table, which #24871 fixes (and #20067 too); without it such a program's folded dispatch throws, as its thread-dimension limit already does.Tested
Windows 11 Pro 26100, WinLibs GCC 15.2.0, Release, on an NVIDIA GeForce RTX 5080 and the AMD Radeon iGPU of a Ryzen 7 9800X3D (gfx1036).
agc_driver_indirect_dispatch_limit, extended: 2 x (maxComputeWorkGroupCount[1]+ 1) groups each store(Y << 16) | Xat their linear index (131072 groups checked), once with group counts and once with thread counts and a partial last group; 1 x 0xffffffff x 1 runs no thread; 1x1x1 still runs. Two negative controls fail: without the fold in the argument kernel at group 0, and without the ShaderData copy at group 2 (stored 2, expected 65536).mainand on this PR, on both GPUs, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(SDK 1.4.335) andVK_LOADER_DEBUG=layer: everyagc_driver_*indirect*test,agc_driver_prepared_shaders*,agc_driver_oversized_dispatch,agc_driver_cross_workgroup_flag,agc_driver_wave_id_in_workgroup,agc_shader_disk_cache*,agc_spirv_*,agc_shader_cache_housekeeping*,agc_shader_memory*andrequest_serializer(76 tests). All pass in the four runs, onmain(e60b2f74ad) and on this PR; every log shows the loader inserting the layer, none containswas not found but was requested by env var VK_INSTANCE_LAYERS, and none contains aVUID-line.request_serializerandshader_*tests (2079) on the iGPU: 23 failures, all among 26 I ran one at a time onmainand on this PR before rebasing: 24 fail on both,agc_storage_write_back_host_retilepasses on both, andagc_driver_store_over_untrackedis flaky onmaintoo (3 of 8 runs fail there).APS5_FRAME_CAPTURE, 10 frames) replayed withagc_frame_replay --frames.main: every frame black. This PR: the menu renders, at the up-rendered resolution, on both GPUs (screenshot below). In game on the RTX 5080, with this change built on the earlier basedbd4eb7377and each title's default configuration: the Tomb Raider: Legend menu and the Jak and Daxter: The Precursor Legacy (PPSA20928, 4x4 up-render) title screen now render. Both run slowly because the rasterizer now does its work: in the replay it costs about 37 ms per dispatch on the iGPU and 180 to 230 ms on the RTX 5080, the same as when the counts are read on the CPU (APS5_NO_GPU_INDIRECT=1), and an iGPU frame takes 65 ms here against 99 ms with the counts read on the CPU. The PS2 logo of both titles pauses for 1 to 2 s on the RTX 5080, and for less time onmain. A frame capture of the logo replayed on this PR shows why: its first five frames run the rasterizer with 252552, 262088, 200232, 212196 and 149440 groups, whichmainskips, and each now takes 140 to 255 ms on the RTX 5080 and 105 to 170 ms on the iGPU. The movie that follows is not affected (35712 groups per dispatch, within the limit).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 JJenkx on 2026-11-22T08:41:43Z.
Review: COMMENTED
Tested on Linux with an AMD Radeon RX 6650 XT (RADV NAVI23) with and without the Khronos validation layer, and reviewed the diff. The focused GPU + VVL suite and negative control pass on Linux RADV, and code reading turned up one concrete bug on the indirect split-table-call path.
Code finding: uninitialized
ShaderDatagroup counts on GPU-side indirect split table callscore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp:413setscompute.groupFold = indirectArguments != 0 && (...)onrequestbeforeSplitTableCallPartsFor(request, ...)/dispatchSplitTableCall(..., request, ...)(Dispatch.cpp:428-430).SplitTableCallPartInvocation(ShaderRegistry.cpp:1487) copiesrequestverbatim without clearingcompute.groupFold, so an indirect split-table-call entry part that reads workgroup IDs or partial groups compiles withdispatchGroupCount == true.VulkanDevice::recordDispatch(core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:6115-6145):foldThreadsis forced to0uwhensplitis true, whilereadsCountsis stilltrue.argumentImport != nullptr && argumentImport->address != 0,copiedis a newly allocated uninitialized 32-byte buffer, andRecordDispatchArgumentsinvokesDispatchArguments.compwithparameters.foldThreads == 0u.DispatchArguments.comp:63-66skips writingwords[6]andwords[7]whenparameters.foldThreads == 0u.VulkanDevice.cpp:6136-6137then unconditionally copies bytes24..31(words[6..7]) fromcopiedintoShaderDataand setscountsCopied = true, bypassing the{0, 0}vkCmdUpdateBufferfallback at line 6143.copied[24..27]is nonzero, the split part's entry prologue seesunfolded == falseand corrupts its workgroup IDs.Suggested fix: Clear
compute.groupFold = falsewhen compiling split table call parts (so they keep the old behaviour without movingShaderDataout of push constants or emitting prologue divides), and inVulkanDevice::recordDispatchguard thecountscopy withif (readsCounts && foldThreads != 0u)(settingcountsCopied = readsCounts && foldThreads != 0u) so{0, 0}is always written wheneverfoldThreads == 0u.Linux AMD RADV hardware verification
Setup
ANYPS5_ENABLE_SPIRV_TOOLS=OFF).main10a9c248ffc(includes merged #24871c603d5d41133). Candidate: clean merge of PR headb0ebf5b48425onto10a9c248ffc.AMD Radeon RX 6650 XT (RADV NAVI23)(vendor=0x1002 device=0x73ef subgroup=64, Mesa RADV 26.3.1).ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1; layer runs addVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(1.4.363) andVK_LOADER_DEBUG=layer.agc_driver_.*indirect|agc_driver_prepared_shaders|agc_driver_oversized_dispatch|agc_driver_cross_workgroup_flag|agc_driver_wave_id_in_workgroup|agc_shader_disk_cache|agc_spirv_|agc_shader_cache_housekeeping|agc_shader_memory|request_serializer|agc_indexed_indirect_patches):VUID-/SYNC-HAZARD-/UNASSIGNED-10a9c248ffcb0ebf5b48425merged on10a9c248ffcDispatchArguments.compreverted to10a9c248ffc,agc_driver_indirect_dispatch_limit)AGC graphics: indirect dispatch fold: group 0 of 2x65536x1 stored 3735928559, expected 0was not found but was requested by env var VK_INSTANCE_LAYERSlines across all runs.AI-assisted: yes (code review and scripted test runs on the Linux RADV machine above).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T09:02:22Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the inspected code supports the documented indirect-dispatch fold, and no verified defect warrants blocking merge.
What I ran
Reviewed head
b0ebf5b484257a18f5ee0eeb51f74225ed61cc43. Read the prepared description, commit list, manifest, and full diff; inspected relevant source ranges throughrepo_read.py. No tests or builds were run by me.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Full text of
VulkanDevice.cppandShaderMemory.cppwas excluded from the prepared folder; I inspected only the relevant changed ranges via the reader. Other changed files whose full text was included in the manifest were not all read. Build, test results, hardware behavior, performance, and the author-reported negative controls were not independently verified.review/files.jsonwas not available through the reader; exclusion details came frommanifest.json.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-23T10:41:45Z.
Review: COMMENTED
Windows check of head
b0ebf5b484with GCC 16 on an NVIDIA and an AMD GPU, merged ontomainf5b7e1d1ac(which has #24871; clean merge), and a read of the split-table-call path JJenkx raised.Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release full build, run from PowerShell withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. GPUs, each picked withANYPS5_GPU: NVIDIA GeForce RTX 5070 Ti (621.01) and the Ryzen 7 7700X's integrated AMD Radeon (1002:164e, Adrenalin 26.10.2). This was built together with #21745, which touches other files apart fromShaderMemory.cpp.agc_driver_*indirect*test, the split table call tests,agc_driver_oversized_dispatch,agc_driver_cross_workgroup_flag,agc_driver_wave_id_in_workgroup,agc_driver_prepared_shaders*,agc_shader_disk_cache*andrequest_serializer(66 tests here): 66 of 66 onmain, and with this PR in 3 of 3 runs, on both GPUs. NoVUID-lines.JJenkx's split-table-call finding holds, as far as I can trace it.
Driver::dispatchsetscompute.groupFoldbeforeSplitTableCallPartsFor.SplitTableCallPartInvocationcopiesrequestas it is, andShaderInputInfoBuilder.cpp:101passes the flag on, so a split part that reads its workgroup ids is compiled withDispatchGroupCount. InrecordDispatch,foldThreadsis 0 for it, soDispatchArguments.compleaves words 6 and 7 alone, butreadsCountsis still set, so they are copied into ShaderData and the zero fallback is skipped.One detail makes non-zero words there likely, not only possible:
Graphics::Buffertakes its memory fromBufferPool, which clears a reused tail only on Apple. The 32-byte argument buffers of folded dispatches, which do write the real X and Y counts into words 6 and 7, go back to that pool. A split part that gets one of them later rebuilds its workgroup ids from those counts.SplitTableCallRun's indirect cases compile withoutgroupFold, so the tests don't reach this path.Version numbers: the request serializer's 64 is also taken by #24906, #23818 and #22251, so whichever lands later needs the next number. (I first listed the disk cache's 97 here too. That doesn't matter: the cache is also keyed on a hash of the recompiler sources.)
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:41:26Z.
Review: COMMENTED
This head conflicts with
mainf3c2cd73abin seven files, includingRecorder.hpp,BindingAllocator.cpp, and both request serialization files. Please reconcile the folded-dispatch shader-data words, serializer and cache version together. The fixture checks both group-count and thread-count paths, and its assertion that the arguments stay on the GPU is essential. The paired Vulkan run is pending the merge resolution.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.