feat(libSceAgcDriver): back the global data share with driver-owned guest memory #285
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/285"
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 SP4C3B4R-8 on 2026-10-01T21:57:11Z.
What
Implements the
Gdsdescriptor role. The 64 KiB global data share is allocated once as driver-owned guest memory (an anonymousmmapin the guest address range). Shader GDS bindings bind that range as a writable, atomic guest buffer, and DMA_DATA packets with a GDS source or destination read and write the same range, so both go through the existing CPU/GPU coherence tracking. The test that expectedunsupported descriptor role Gdsnow checks that a GDS binding with a guest descriptor is rejected. The new execution testagc_driver_gds_append_consumesets GDS counters with DMA_DATA, runsds_append/ds_consumeon the GDS (wave32, wave64, full and partial EXEC, two waves per group) and reads the counters back with DMA_DATA.Tested
Windows 11, MinGW-w64 GCC 15.2.0 (winlibs, ucrt posix seh). Rebased on
main4764e59c. Full build andctest: 396/396 passed on this branch alone. Also checked with a retail title.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🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T00:51:01Z.
Some context first: PPSA21564 runs its light lists through GDS, with ds_append in a pixel shader and in compute kernels, and the CP reads the counters back through DMA_DATA. On my integration branch I had that working another way, with a device-owned 64 KiB Vulkan buffer. From reading the diff, this PR covers everything that title needed from mine: draws and dispatches can bind the GDS, and a DMA_DATA from GDS sees the shaders' results through the existing write tracking. So I don't plan to send mine.
One thing this PR changes:
GdsAddress()takes the 64 KiB from the title's flexible memory budget.sceKernelMapFlexibleMemoryis checked againstFLEXIBLE_MEMORY_SIZEin libkernel, but the hardware GDS is not part of that budget. Two effects:ENOMEM, andGdsAddress()throws "cannot allocate the global data share". This also covers a CP-only DMA_DATA into GDS (clearing append counters, for example), which works on main today without any shader.sceKernelAvailableFlexibleMemorySizereports 64 KiB less after the first GDS access than before it.Allocating the GDS outside the flexible accounting would avoid both.
If they're useful, I also have GPU tests for this on my branch: ds_append and ds_consume from compute in wave32 and wave64, a pixel shader appending per pixel, and the CP reading the counters back through DMA_DATA. I can port them onto the execution test harness from #251 as a follow-up once this lands.
Imported from boykopovar/AnyPS5. Originally posted by SP4C3B4R-8 on 2026-10-02T09:41:05Z.
Thanks, both points are right. c7eac17 maps the GDS through the anonymous mapping path instead of
sceKernelMapFlexibleMemory, so it is no longer charged toFLEXIBLE_MEMORY_SIZE: a title that has used its whole flexible budget can still touch the GDS (including a CP-only DMA_DATA into it), andsceKernelAvailableFlexibleMemorySizereports the same value before and after the first GDS access. The PM4 test now checks that, and it fails on the previous commit.Porting your ds_append/ds_consume and per-pixel append tests onto the #251 harness as a follow-up would be great, they cover far more of the shader side than this PR does.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T10:01:58Z.
Thanks, c7eac17 looks right to me: the GDS now goes through the anonymous mapping path, so it stays out of the flexible accounting, and the new Pm4 check covers the reported size. I'll port the ds_append/ds_consume and per-pixel append tests onto the #251 harness once this lands.
Imported from boykopovar/AnyPS5. Originally posted by SP4C3B4R-8 on 2026-10-02T10:06:46Z.
Thanks for checking it, and for taking the tests on.
Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-03T20:00:23Z.
Tested on Linux (GCC 16.2), PPSA21567, with this PR's two commits applied onto
maind3ec1f15. It clearsunsupported descriptor role Gds. The shader that hit it uses onlyds_appendon GDS (6 sites, M0 base 0xc60, size 0x20).ds_consumeand plain GDS reads and writes were not exercised, and I did not check whether the title uses the DMA_DATA GDS path. The title then stops at an unrelated error in a later compute shader.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-05T20:29:15Z.
Tested c7eac179 on Windows 11, MinGW-w64 GCC 15.2.0, RTX 3080 Laptop (NVIDIA 610.62).
681f83e5(clean):-DBUILD_TESTING=ON, full build, ctest 316/316, GPU execution tests included.agc_driver_graphicsfails withunsupported descriptor role Gds.agc_driver_pm4passes there: main keeps the GDS in a static array, so the new flexible-memory check has nothing to catch on main.agc_driver_flip, which crashes intermittently here (heap corruption or segfault) on its base709d7fe0as well.ds_append(full and partial EXEC) andds_consumeon GDS with M0 = 0x01000020, two dispatches back to back, counters set by DMA_DATA immediate→GDS and read by DMA_DATA GDS→memory throughPm4::Execute. For wave64 (64- and 32-lane subgroups) and wave32 the final counters and per-wave returned values are exact, and a GDS read issued beforeWaitIdlealready sees both dispatches. On main it fails withunsupported descriptor role Gds.unsupported descriptor role Gdsis gone; the run now stops at an unrelatedcompute shader 0x800040a500: guest sampler descriptor uses unnormalized coordinates. These two shaders use onlyds_appendon GDS (1 and 9 sites); the title'sds_add_rtn_u32GDS sites were not reached.Nit: the description still says the GDS is allocated with
sceKernelMapFlexibleMemory; since c7eac17 it is an anonymousmmap.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T13:11:47Z.
Performance data from PPSA26344 v1.008 with c7eac179, for after this lands. Not a regression: the drain is in
main's packet path.Build: our integration branch (
main5895ea72+ c7eac179 + other open PRs and local fixes) with a local per-packet timer (wall time in the packet loop), same machine as above.46104000 00000000 00000000 00000d28 00000000 40000024(+0xd28, 0x24 bytes), the 0x80003a1d00 range from the comment above;c6104000 00000000 00000000 00000d50 00000000 00000018(+0xd50, 0x18 bytes), then a 240×135-group dispatch (0x0d500018).Pm4::ResolveStorereturns nullopt for a GDS destination (Execution/src/Pm4.cpp:505at c7eac179), sopreparePacketMemorydrains the device before each fill.APS5_PROFILE_GPUand different debug options, q38 +328 averaged 582 / 644 ms against 605 / 646 ms per 0x800036e100 dispatch.[sync] 680 device drains by packet: DMA_DATA=680at about 285 s, the number of GDS fills started by then (four per frame plus 7 on q30, GDS +0xd18 (0x10 bytes)). In that run q20's and q30's fills went over 15 ms 31 times. The 4-byte GDS→memory copies are not drains; the first on q0 (+3186) takes about 22 ms per frame.That exclusion (on
mainas well) is what makes these fills drain. Not measured: the frame time without it.Imported from boykopovar/AnyPS5. Originally posted by SP4C3B4R-8 on 2026-10-06T21:15:35Z.
@Celegans12 thanks for testing on Windows and for the GPU check of
ds_append/ds_consume. Fixed the description: since c7eac17 the GDS is an anonymousmmap, notsceKernelMapFlexibleMemory.Written with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-06T23:40:51Z.
Tested on PPSA21567 (Linux, RTX 3070 8 GB, default build, virtual display) on
main5895ea72+ #732 (for the loader) + this PR, merged locally (c748c384).main+ #732 ended 6 to 11 s in withAGC graphics: unsupported descriptor role Gds.compute shader 0x5005f7800: AGC driver: guest memory is not readable at 0x30 (range 0x30+0x4), which looks like the #479 class (null SRT pointer reads, #759).One run with this PR, so I can't say more about how far it gets.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T13:29:19Z.
Review: CHANGES_REQUESTED
Checked on Linux (RADV): build and full ctest green merged onto current main, the GDS ranges are still validated before use (
Pm4.cpp:433-434), and the mapping stays out of the flexible budget. One thing missing before merge:tests/Graphics.cpp:1284, and the new check intests/Pm4.cpp:330passes onmaintoo (main has no mapping to charge). Nothing exercises a shader binding the GDS, which is what this PR adds;tests/execution/DsAppendConsume.cppcovers LDS only. Please add an execution test along the lines of the one @Celegans12 described: set counters with DMA_DATA immediate→GDS, runds_append/ds_consumeon GDS from compute in wave32 and wave64 (full and partial EXEC), and read them back with DMA_DATA GDS→memory, pinning the final counters and the per-wave return values. If @oneandonlydean's tests from his branch are ready to port, including them here works just as well.Not blocking, for a follow-up: with the GDS now in guest memory,
Pm4::ResolveStoreno longer needs to returnnulloptfor a GDS destination (Pm4.cpp:556); that exclusion is what makes the per-frame GDS clears drain the device in @Celegans12's measurements.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T13:55:19Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppL456core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppL456core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppL456core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppL456mmap_nid_postfixImported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-07T15:37:37Z.
Tested with Astro's Playroom (PPSA01325) on Windows 11, RTX 3060 Laptop, MinGW-w64 GCC 15.2.0, with this PR (c7eac179) merged onto main
3c054008(the merge is clean).compute shader 0x5002a8500: AGC graphics: unsupported descriptor role Gds.0x5001c6a00: AGC driver: guest memory is not readable at 0x28(the SRT walk reads through a null user-data pointer), so I can't tell yet whether the GDS shader's output is correct.Other blockers for this title were bypassed locally to get this far (a missing
libSceJobManagerand three undeclared imports); they are unrelated to this PR. Tested with AI assistance (Claude Code).Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T15:42:15Z.
@orbz22 the stop you hit next (
guest memory is not readable at 0x28, an SRT walk through a null user-data pointer in a compute shader) looks like what #759 covers. It turns descriptor reads through a null SRT pointer into deferred faults, so the dispatch only faults if a lane actually executes the read. Ghost of Yōtei has several shaders like that behind branches the GPU never takes. #759 is being rebased onto current main right now; once it's up, it might be worth a try with Astro's Playroom on top of this PR.Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-07T16:06:24Z.
@Celegans12 thanks, that was it. With #759 (a3de45b1) and this PR (c7eac179) both merged onto main
3c054008, theguest memory is not readable at 0x28stop in compute shader0x5001c6a00is gone. The only conflict was the role list inShaderValidation.cpp, resolved by accepting bothGdsandImageTableMap.Astro's Playroom now opens its window and presents one frame (black), then hangs:
Nothing writes 1 to that label before the timeout. Before it, some draws are skipped (
color compression, DCC ... is unsupported,vertex fetch exceeds descriptor record count,missing register at DWORD 0x1b3). I'll look into where that label should come from. Tested with AI assistance (Claude Code).Imported from boykopovar/AnyPS5. Originally posted by SP4C3B4R-8 on 2026-10-07T20:14:36Z.
@adriadam10 thanks, test added in
faa1cc59; the branch is rebased onto currentmain(4764e59c, no conflicts).tests/execution/GdsAppendConsume.cpp(agc_driver_gds_append_consume):DMA_DATAimmediate → GDS and reads them back withDMA_DATAGDS → memory before the first dispatch;ds_append/ds_consumeon the GDS (M0 base 0, size 0xffff), at full EXEC and then withv_cmpxleaving only part of the lanes; inactive lanes must keep their sentinel;On
mainwithout this PR it fails withunsupported descriptor role Gds. Fullctestpasses on Windows (396/396). I leftResolveStorealone, as you suggested, for a follow-up.Written with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T21:00:29Z.
Review: APPROVED
Thanks for the test. Checked on Linux (RADV) merged onto current main: full ctest green, and
agc_driver_gds_append_consumeandagc_driver_graphicsboth fail with the driver changes reverted, so the shader GDS binding and the DMA_DATA GDS path are now covered. Merging once CI is green.