Skip to content

fix(agc): store a storage image whose last block row runs past its allocation - #5030

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
johnmaia:fix/storage-writeback-overhang
Oct 14, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
johnmaia:fix/storage-writeback-overhang

Conversation

@johnmaia

@johnmaia johnmaia commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

StorageTexture::writeBackLayers drops 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:

  • one level, one layer, no mip tail;
  • the range holding the surface's start ends inside its last block row (the overhang is at most tiledSize − pitch × height);
  • registered readable memory continues from there to the surface's end.

Padding slots keep their bytes, since the store writes only bytes that changed. Everything else is dropped with the report and the unregisteredDropped count, as before.

Seen in Epic Mickey: Rebrushed (PPSA15657, UE 4.27):

  • Its virtual-texture lightmaps live in an 8160x8160 BC3 pool: SW_64KB_S, 2040x2040 blocks, with an AnyPS5 footprint of 2048 rows (0x4000000 bytes).
  • The game registers 0x3fc0000 bytes (pitch × 2040 rows), so the next allocation starts 0x40000 before the surface's end. Those 0x40000 bytes are the last 4 blocks of the last block row and hold texels x 7168-8159, y 7936-8159 of the pool.
  • New tiles reach the pool through a compute copy into a 2040x2040 RGBA32UI alias. Every write-back of that alias was dropped, so the BC3 view that the base pass samples kept an old render target's bytes. Walls and floors showed speckled multicolour noise.

Tested

  • New execution test agc_driver_storage_write_back_overhang:
    • It writes a 128x120 RGBA16F SW_64KB_S image with a compute store, once with the surface registered whole and once registered as pitch × height plus a neighbouring allocation. Both start with the same bytes: zero, then a sentinel past pitch × height.
    • The split surface must match the fully registered one over the whole tiled size. The test also checks that texels lie past pitch × height (768 of them here) and that the padding slots keep the sentinel.
    • Windows 11, WinLibs GCC 15.2.0 r7, Release, RTX 4080 and Intel UHD 770, main feddf7f:
      • this change: passes, 3 of 3 runs on each GPU;
      • Texture.cpp from main: fails at byte 0x5 (the whole write-back is dropped);
      • the first version of this PR, which clipped at the allocation end: fails at byte 0x1e000, where the clip started.
  • Full ctest on the RTX 4080: 1110 of 1110.
  • In game, Dark Beauty Castle, Linux, RX 7600 (RADV), with the first version of this PR: the walls and floors rendered clean instead of speckled, and level FPS was unchanged (4.2 before, 4.75 after, within noise). A run with this version is pending.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA15657 Disney Epic Mickey: Rebrushed (PPSA15657) on Linux #2255
  • AI-assisted: yes

🤖 Generated with Claude Code

@johnmaia

Copy link
Copy Markdown
Contributor Author

In game, Dark Beauty Castle before (left) and after (right) this change, from the same spawn point:

Before (left) and after (right), same spawn point

@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main 2a2a3dc65 together 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, which ctest runs as agc_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).

@github-actions github-actions Bot added agc libSceAgc* needs rebase Conflicts with main, rebase needed labels Oct 13, 2026
@johnmaia
johnmaia force-pushed the fix/storage-writeback-overhang branch from 8a15b2b to e6afbc9 Compare October 13, 2026 10:55
@johnmaia

Copy link
Copy Markdown
Contributor Author

Rebased onto main 075169f as one commit (e6afbc9). #5024 replaced originalValid with the per-unit layerOriginal, 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_overhang passed 3 of 3 runs (--repeat until-fail:3), and the full suite passed 1060 of 1060.

AI-assisted: yes (Claude Code)

@nikowolf123

Copy link
Copy Markdown
Contributor

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 unregisteredDropped count.

padding (Texture.cpp:4294 on e6afbc9) 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, blocksPerRow per 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, then addr = ... + (blkIdx << blkSizeLog2) + (blkOffset ^ pipeBankXor) (gfx10addrlib.cpp L4838-L4850).

  • Title case (2040x2040 elements, 16 bytes each, 64x64-element blocks, 32 blocks per row, allocation 0x3fc0000 of 0x4000000):
    • The clipped 0x40000 bytes are blocks 1020-1023, the last 4 blocks of the last block row. They cover element columns 1792-2047 and rows 1984-2047.
    • 13888 of their 16384 slots hold real elements: columns 1792-2039, rows 1984-2039. That is texels x 7168-8159, y 7936-8159 of the 8160x8160 pool, or 0x36400 of the 0x40000 bytes. Element (2000, 2000), for example, is at +0x3ff3000.
    • After this change those guest bytes, which the BC3 view samples, keep their old contents, and nothing is logged.
  • The new test's surface (128x120, 8 bytes each, 128x64-element blocks, allocation 0x1e000 of 0x20000):
    • standard64Extra for 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.
    • 768 of those 1024 elements are real (y 96-119). For example, (100, 100) is at 0x1e180.
    • The test shader writes (x, y, 7, 1) to every element. StorageWriteBackOverhang.cpp:155 then asserts that these bytes still hold the neighbour's 0xa5 sentinel, so the test requires that these texels are not stored.

What I ran (WSL2 Ubuntu, GCC 15.2, CI CMake configuration, Release, lavapipe): this PR merged onto main fdefd76, plus one extra execution test. The test uses the same compute store as StorageWriteBackOverhang on 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:

  • 128x120: 768 elements (x 96-127, y 96-119) have their bytes past the allocation end. All 768 are written in the fully registered surface. In the split surface none of them is stored, all still hold the 0xa5 sentinel, and no [gpu] ... dropped line is printed.
  • 1024x120 (8 blocks per row): 7168 elements (x 896-1023, y 64-119) are past the allocation end, with the same result.
  • agc_driver_storage_write_back_overhang passes.

With Texture.cpp from 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:

  • store those bytes, which is where the GPU's own store puts these texels; or
  • keep the report and the unregisteredDropped count 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.

…location

A storage image whose surface runs past the end of its registered
allocation had every write-back dropped as "memory no longer
registered". Titles can size a single-level surface's allocation as
pitch x height. A tiled mip's 64 KiB blocks are stored row-major, so
that size ends inside the last block row, and 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. When the allocation ends
inside the last block row and registered readable memory continues to
the surface's end, the write-back now stores the whole surface, as the
GPU does. Padding slots keep their bytes, since the store writes only
bytes that changed.

Epic Mickey: Rebrushed streams its lightmaps into an 8160x8160 BC3 pool
(SW_64KB_S, 2048 block rows) through a 2040x2040 RGBA32UI alias written
by compute. The game allocates 2040 rows, so all its write-backs were
dropped and the walls sampled leftover memory as speckled noise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@johnmaia
johnmaia force-pushed the fix/storage-writeback-overhang branch from e6afbc9 to 6ad9372 Compare October 14, 2026 00:23
@johnmaia johnmaia changed the title fix(agc): store a storage image's results inside an allocation sized pitch x height fix(agc): store a storage image whose last block row runs past its allocation Oct 14, 2026
@johnmaia

Copy link
Copy Markdown
Contributor Author

@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, main feddf7f:

Texture.cpp agc_driver_storage_write_back_overhang
this PR (6ad9372) passes, 3 of 3 on each GPU
main fails at byte 0x5 (whole write-back dropped)
the first version (clip at the allocation end) fails at byte 0x1e000

Full 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)

@johnmaia

Copy link
Copy Markdown
Contributor Author

In-game run of the new head 6ad9372: Epic Mickey: Rebrushed, Dark Beauty Castle. Linux, RX 7600 (RADV, Mesa 25.2.8), built on main feddf7f together with #5232.

  • The title's virtual-texture lightmap pool is the 2040x2040 RGBA32UI surface (tiled 0x4000000, registered 0x3fc0000). Its tail is covered by the next registered allocation, so it takes the new path: the whole surface is stored. No memory no longer registered line for it. The only four such lines are for 0x100000 and 0x400000 surfaces, and every earlier build prints the same four.
  • Walls and floors are clean, with no lightmap speckle. Four in-level frames show no new corruption from the bytes that now go into the neighbouring allocation.
  • In-level FPS: 4.81 mean over 66 samples (30-300 s after Continue, 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).

@adriadam10

Copy link
Copy Markdown
Collaborator

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 test agc_driver_storage_write_back_overhang: it passes here and fails without the Texture.cpp change. The layout point from @nikowolf123 is addressed in this head. Merging once the full Build is green.

@adriadam10
adriadam10 merged commit ee6addf into boykopovar:main Oct 14, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants