fix(agc): store a storage image whose last block row runs past its allocation #5030
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5030"
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 johnmaia on 2026-10-13T08:55:17Z.
What
StorageTexture::writeBackLayersdrops a CPU-path write-back as "memory no longer registered" when no single registered readable range contains[base, base + guestBytes). A title can size the allocation of a single-level tiled surface as pitch × height, with the next allocation starting right after it. A tiled mip's 64 KiB blocks are stored row-major (TextureTiling.hpp), so that allocation ends inside the last block row. The bytes after it are the tail of that row: they hold texels with y < height, which the GPU's own store writes into the next allocation. In that case the whole write-back was dropped.With this change, the whole surface is stored as the GPU does when all of these hold:
tiledSize − pitch × height);Padding slots keep their bytes, since the store writes only bytes that changed. Everything else is dropped with the report and the
unregisteredDroppedcount, as before.Seen in Epic Mickey: Rebrushed (PPSA15657, UE 4.27):
Tested
agc_driver_storage_write_back_overhang:mainfeddf7f4c:Texture.cppfrommain: fails at byte 0x5 (the whole write-back is dropped);cteston the RTX 4080: 1110 of 1110.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-13T09:19:30Z.
In game, Dark Beauty Castle before (left) and after (right) this change, from the same spawn point:
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T09:41:32Z.
Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main
2a2a3dc65together with nine other open GPU PRs (their own commits applied, no merge commits; one further PR, #5024, conflicted with them and was left out), so only the tests that belong to this PR say something about it:tests/execution/StorageWriteBackOverhang.cpp, whichctestruns asagc_driver_storage_write_back_overhang: 3 of 3 runs passed.Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-13T10:55:55Z.
Rebased onto
main075169f7bas one commit (e6afbc95a). #5024 replacedoriginalValidwith the per-unitlayerOriginal, so a store over the overhang now leaves the stored units' saved bytes invalid:layerOriginal[layer] = !skippedLayer[layer] && !overhang.Windows 11, WinLibs GCC 15.2.0 r7, Release, RTX 4080:
agc_driver_storage_write_back_overhangpassed 3 of 3 runs (--repeat until-fail:3), and the full suite passed 1060 of 1060.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-13T16:04:55Z.
The clipped bytes are not padding rows. They hold texels with y < height. With this change they are left unstored, without the "memory no longer registered" report and without the
unregisteredDroppedcount.padding(Texture.cpp:4294 on e6afbc95a) is the byte count of the padding rows, (alignedRows − rows) × pitch. It does not say which bytes those are. In this driver's tiled layout, a mip's 64 KiB blocks are stored row-major,blocksPerRowper row (TextureTiling.hpp:34-36, TextureDetile.comp:243-244). So[pitch × height, tiledSize)is the tail of the last block row, not its padding rows. AMD's addrlib places blocks the same way:blkIdx = yb * pb + xb, thenaddr = ... + (blkIdx << blkSizeLog2) + (blkOffset ^ pipeBankXor)(gfx10addrlib.cpp L4838-L4850).standard64Extrafor 8-byte elements (TextureDetile.comp:117-119) makes byte-offset bits 13, 14 and 15 of a block x5, y5 and x6. So the last 8 KiB of block 1 hold elements x 96-127, y 96-127.What I ran (WSL2 Ubuntu, GCC 15.2, CI CMake configuration, Release, lavapipe): this PR merged onto main
fdefd7660, plus one extra execution test. The test uses the same compute store asStorageWriteBackOverhangon two surfaces, one registered whole and one registered as pitch × height plus a neighbouring allocation. It then checks every element with y < height at its tiled offset:[gpu] ... droppedline is printed.agc_driver_storage_write_back_overhangpasses.With
Texture.cppfrom main, both split surfaces are dropped whole, with the report.A clip bounded only by the padding byte count cannot tell padding from lost data. One of these is needed:
unregisteredDroppedcount whenever texels are dropped.The test would catch this if it checked every element with y < height, instead of only the bytes before pitch × height.
AI-assisted: written with Claude Code; I checked the code paths and ran the test described above.
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-14T00:24:20Z.
@nikowolf123 you're right, thanks for the careful check. The blocks are row-major, so
[pitch × height, tiledSize)is the tail of the last block row, not padding rows, and the clip dropped real texels without a report. I took your first option: when the allocation ends inside the last block row and registered memory continues to the surface's end, the whole surface is stored, as the GPU's own store does. Everything else drops with the report and the count, as before.The test now checks every element: the split surface must match the fully registered one over the whole tiled size, with texels past pitch × height (768 here) and the padding slots keeping their sentinel. Windows, RTX 4080 and UHD 770,
mainfeddf7f4c:Texture.cppagc_driver_storage_write_back_overhang6ad9372fd)mainFull ctest on the RTX 4080: 1110 of 1110. The description is updated; the in-game check with this version is still to do.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-14T00:43:18Z.
In-game run of the new head
6ad9372fd: Epic Mickey: Rebrushed, Dark Beauty Castle. Linux, RX 7600 (RADV, Mesa 25.2.8), built onmainfeddf7f4ctogether with #5232.memory no longer registeredline for it. The only four such lines are for 0x100000 and 0x400000 surfaces, and every earlier build prints the same four.APS5_PROFILE_DRAW=1), in the range of earlier runs on this machine.I also checked the test on the RX 7600. A variant that checks every 8-byte slot (whole / split / short registration) fails on the previous clip at slot 0x1e000 (768 texels past the allocation) and passes with this logic. Full ctest: 1035/1035.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:32:55Z.
Checked the new overhang path in
StorageTexture::writeBackLayers(single level/layer, no mip tail, allocation ends inside the last block row, registered memory continues to the surface end) and its execution testagc_driver_storage_write_back_overhang: it passes here and fails without theTexture.cppchange. The layout point from @nikowolf123 is addressed in this head. Merging once the full Build is green.