fix(agc): store and read DCC keys over the console's metadata extent #788
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/788"
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 Celegans12 on 2026-10-06T00:19:51Z.
What
@merwie's PPSA12544 report on #648 (1920x1080: 33552
0xff, 10080x00of 34560 keys, first differing 32784) comes from the extent of the driver's key stores, not from key order or padding (my row-major reading here was wrong).ceil(W/512) * ceil(H/512) * 4096bytes (addrlib; PPSA26344's 0x161d760; GTA V's 0x6000 at 1280x720), 49152 at 1920x1080.MarkDccUncompressedstored 34560.cs_dcc_retile_32bppcopy of its render DCC; that retile (addrlib patterns 25 to 2) of a 34560-key store gives merwie's numbers.DccKeyCountgives the extent for single-level, single-layer 4-byte SW_64KB_R_X surfaces. Color target and storage image key stores cover it for pipe-aligned DCC (CB_COLOR_ATTRIB3bit 30, T# word 6 bit 19; libSceAgc's size query returns it, and at 128x128, 1920x1080 and 3840x2160 its CB keys end within 240 bytes of it), throwing where it is not writable; unaligned DCC keepsbytes/256.DisplayBufferKeysreads the extent and presents only uniform keys.bytes/256differ or are unreadable now throws; pipe-aligned driver stores leave no differing tail, unaligned ones can. Texture and CB key reads keepbytes/256(TechnicalDebt).DecodeColorBufferandRunColorMetadataPassnext to code changed here and refuses multisampled DCC.Tested
mainc73ee448: configure-DBUILD_TESTING=ON, full build,--target libs,ctest:ctest --output-on-failure)VK_DRIVER_FILES): 402/402 pass;agc_driver_flat_storeis left out there because it takes several minutes on Windows llvmpipeagc_display_buffer_dccandagc_driver_graphics(do not build onmain): merwie's keys reproduce, the driver's store, retiled, presents, and the flip reads keys past 34560; pipe-aligned stores cover the extent (or throw if not writable), unaligned onesbytes/256. Pipe-aligned rows fail on the old extent, unaligned ones without the gate.agc_driver_recorder_tests,video_out_flip_tests dcc.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 oneandonlydean on 2026-10-06T01:12:41Z.
Thanks. The 8x8-block mapping checks out: the low byte of
tileOffsetdepends only onx & 7andy & 7, so each block fills exactly one 256-byte key block. Cross-checking the runs againstDecodeDisplayBuffer's per-pixel keys is a good oracle. Two questions:0000key in the first 32400 keys, and 32400 is exactly the number of presented 8x8 blocks. That suggests the console orders keys differently from the driver's linear model. Is the plan to model that order next, and does this PR still help once it's modelled?VulkanDevice.cpp:1845-1850), the whole-surfaceProvedClearKeysis compared with keys read only over the presented runs. So a surface with mixed padding still throws there, and a case that presented under #648 can now throw. Could the comparison use the same runs?Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T01:36:26Z.
Thanks, both points are right.
merwie's numbers fit a row-major order of 8x8 blocks exactly.
0000key, 32784, is block row 136 and column 144 (y 1088..1095, x 1152..1159), inside the padding rows. The zeros end near block row 140.The plan is to model that order next. I'd derive it from the gfx10 DCC meta addressing for this swizzle, rather than assume row-major from one title's histogram. I'll also check which writers produce the display keys: the driver's own key stores use its model, so both orders cannot meet on the same buffer unchecked.
The point of this PR survives that change. In a row-major order the padding blocks are still there: 240 x 9 blocks below row 135, plus any columns past
width. They still have to be ignored. Only the key-to-pixel mapping changes. I'll rework #788 on that basis rather than have the tile-order mapping land.Yes. The pending-image comparison will use the same presented runs as the classification. A surface with mixed padding then presents there too, and no case that presented under #648 throws.
I'll convert this to a draft until the reworked version is up.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T02:35:41Z.
Correction to my earlier reply: the row-major reading was wrong, and neither order nor padding is the cause.
tileOffsetmatches addrlib'sGFX10_SW_64K_R_X_1xaapattern), addrlib places keys in 4 KiB meta blocks of 512x512 pixels. The blocks run row-major with a pitch ofceil(W/512), and keys are swizzled inside each block. So the metadata isceil(W/512) * ceil(H/512) * 4096bytes: 49152 for 1920x1080, against the 34560 the driver models. The title's own libSceAgc DCC info function (PPSA26344 eboot 0x161d760) computes the same size.[rt+0xa8]is the metadata passed tosceVideoOutRegisterBuffers2at 0xcd004a.MarkDccUncompressedstores 0xff only over bytes/256 keys of the render DCC, so the rest of the 49152 bytes stays 0.So the fix is to store and read keys over the console's metadata size for these surfaces, and to classify all of them. Nothing about padding is needed. I'll rework this PR that way, with a test that reproduces the three numbers, and the pending-image comparison will use the same range. The DCC addressing derivation goes in the PR text.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T04:12:04Z.
Reworked as described above, and ready for review again. The new title is "store and read DCC keys over the console's metadata extent". It is one commit on
main109a3281, and the padding runs are gone.DccKeyCountisceil(W/512) * ceil(H/512) * 4096bytes. Color target and storage image key stores cover that extent, and the flip classifies all of it.main.agc_display_buffer_dccreproduces merwie's numbers with a test-side copy of addrlib's patterns 25 and 2 and a retile: 33552 / 1008 / first differing key 32784 over 34560 keys. The driver's store over the extent, retiled, presents; with the old extent the same test fails with exactly those numbers.@merwie, if you can run PPSA12544 on this version, it should present without the padding experiment. If it still throws, the message now names the first differing key and its pixels in the displayable order, and
APS5_TRACE_DCC_KEYS=1prints the run lengths.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T05:33:56Z.
Thanks for the rework. Both earlier points are covered: the padding runs are gone, and the pending-image check now reads the display keys over the same extent as the flip. Reproducing merwie's 33552 / 1008 / 32784 numbers from a retile in
agc_display_buffer_dccis a convincing test.One question about the store side.
DccKeyCountapplies the 512x512-per-4 KiB extent to every single-level, single-layer 4-byte SW_64KB_R_X color target and storage image, not only to display buffers. SoMarkDccUncompressednow writes past one key per 256 bytes on render targets as well:metadataPassTestscase): 4096 instead of 256.StoredKeyCountonly checks that the larger range is writable, so if a title's render DCC is smaller than that, the extra bytes land in whatever follows it rather than throwing. The 49152 figure comes from the displayable copy and the PPSA26344 DCC info function at 1080p. Does the same size hold for the pipe-aligned render metadata and for small targets? If it's only confirmed for the displayable case, could the larger store be limited to surfaces whose metadata is known to have that size (or throw when it can't be confirmed), with the rest kept at one key per 256 bytes?I'll run this through PPSA21564 before it lands, since its color target and storage image write-backs take the new store path.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T06:54:15Z.
Good question. I checked the render (pipe-aligned) metadata and small targets. The size holds for them too, and one key per 256 bytes does not describe that metadata.
What the CB addresses. For the render DCC (16 pipes, non-RB+,
GFX10_DCC_64K_R_X_SW_PATTERN[25]), the pipe bits sit at key-address bits 8..11. So at the sizes below, even a 128x128 target's keys are spread over its whole 4 KiB meta block. These are the keys of the surface's own 8x8 blocks (x < W, y < H):How libSceAgc sizes it (PPSA26344 eboot):
ceil(W/512)*ceil(H/512)*4096per slice and alignment 4096. The meta block is 4096 bytes for swizzle 27 on both branches (0x161d7ca, 0x161d98d), so the minimum is 4096, also for 128x128.DCC_PIPE_ALIGNED(or 0x44000000, 0x1611c0e).[rt+0xa8]the same way (0xfe4353), then memsets both to 0 over that size (0xfe4289-0xfe42ba).slices * sliceSize;Why not store only the CB's keys. I simulated the retile at 1920x1080 with the padding left at the allocation's 0x00:
main's prefix check throws too (3392 zeros). The texture readers'bytes/256prefix of the render DCC also turns mixed (3644 padding keys).Proposal.
CB_COLOR_ATTRIB3.DCC_PIPE_ALIGNED(bit 30) for color targets, andMETA_PIPE_ALIGNED(T# word 6 bit 19) for storage images. That is where the hardware's own addressing confirms the size for most sizes; libSceAgc's query covers the rest. merwie's numbers reproduce only with a pipe-aligned render DCC, so PPSA12544 stays covered.bytes/256as they were (at 1920x1080 its CB writes keys up to 46205), so its flip throws if they differ. libSceAgc's render-target initializer always sets the bit, so that takes title-built CB registers or an unaligned T#.Driver::fillBufferdoes not match, so the store would stay atbytes/256, and merwie's case would come back.What changed in the PR. I amended the commit that way (now on
main481c85e7):ColorTargetandGuestTextureResourcekeep the bit asdccPipeAligned. The color target and storage image key stores cover the extent only when it is set, and one key per 256 bytes otherwise.DisplayBufferKeysis unchanged.DccKeyCountof descriptors from 128x128 to 3840x2160, a 128x128 fast clear eliminate, and a decoded 1920x1080 T# store (49152 or 34560 keys). An unaligned store over metadata smaller than the extent stores 34560 keys and does not throw.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T20:12:48Z.
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/tests/GuestTextureResource.cppL6docs/dev/TechnicalDebt.mdL245-246docs/dev/TechnicalDebt.mdL245-246core/libs/prx/libSceAgcDriver/Graphics/include/State.hppL43core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppL97-102docs/dev/TechnicalDebt.mdL245-246docs/dev/TechnicalDebt.mdL245-246core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppL43-66docs/dev/TechnicalDebt.mdL245-246docs/dev/TechnicalDebt.mdL246Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T16:09:35Z.
@oneandonlydean ready from our side; you said you'd run it through PPSA21564 before it lands, so the merge is yours once that's done.
main: build + ctest 397/397 on Linux (RADV).bytes/256failsagc_display_buffer_dccandagc_driver_graphics; dropping the pipe-aligned gate fails both as well. So the tests pin both the extent and the gate.Gfx10Lib::GetMetaBlkSize: a 4 KiB meta block of a 4-byte SW_64KB_R_X surface covers 512x512 pixels.TechnicalDebt.md) and #935 (tests/GuestTextureResource.cpp) are adjacency only.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-07T20:47:31Z.
Thanks for the negative checks and for matching the extent against addrlib. The regression run for #788 hasn't happened yet. I'll post the result here, and merge if it passes.
Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-07T21:48:49Z.
A PPSA12544 data point for this head (
8710433f), since the description starts from merwie's Silksong numbers.Windows 11, Intel i9-10850K, NVIDIA RTX 3080. PPSA12544 v1.0.30021 on
0d3c1eecplus this PR and merwie's Silksong stack (#760, #846, #842, #844, #839, #904), #903 and a few export PRs. Two runs without any local workaround for Mixed display keys (40 s and 90 s) reach the main menu at 60 FPS with noreads Mixed DCC keysstop. The presents come from the resident image ([flip] ... from the resident image, through guest memory: 0), so the display-buffer key read inDisplayBufferKeysis not reached in these runs.AI-assisted (Claude Code) testing and write-up.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T22:13:44Z.
Rebased onto
main(f6d6675d6) after #935 and #903. The #935 conflict was only the test includes. There's one line beyond the rebase, so you know before the regression run: #903 added a key store at the first write inStorageTexture::MarkDirty, and it still wrote one key per 256 bytes. On a pipe-aligned 1920x1080 surface that would cover only 34,560 of the 49,152 keys and leave the stale tail this PR removes, so that call now usesDccKeyCount(descriptor, guestBytes)like the other three storage-image stores. #903's own test uses DCC that isn't pipe-aligned, so it's unaffected, and no test pins that particular line yet. CI here: 403/403, lavapipe 402/402.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T22:18:05Z.
The windows failure is
guest_raise_exception(libkernel) hitting its 30 s timeout, the same flaky timeout #1267 got; it passes standalone in about 7 s here. A re-run of the windows job should clear it.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T11:40:11Z.
Tested 016507040 on main
73ac9ef7f: ctest 433/433, and the full game check passes the same with and without this (no new skipped draws, no visual differences). I couldn't do the second, heavier title on main yet: it stops before the intro on a separate issue unrelated to this PR. From our side this is good to merge. It now conflicts with main indocs/dev/TechnicalDebt.mdonly, so it needs one more rebase first.