Skip to content

fix(agc): store a storage image's DCC keys at write-back only when not stored yet - #3458

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
alfalfa-star:fix/agc-dcc-writeback-keys-reused
Oct 11, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
alfalfa-star:fix/agc-dcc-writeback-keys-reused

Conversation

@alfalfa-star

Copy link
Copy Markdown
Contributor

What

A storage image's write-back stores uncompressed DCC keys over its metadata again, even when the image's first write already stored them (b8d3060). The write-back is deferred until something flushes it. By then the title may have reused the metadata memory, and the store overwrites the title's data with 0xff.

Title: RIDE 4 (PPSA01599, Unreal Engine 4) on Linux, main 8ec0e13. With #3435 and #3440 for its earlier stops, it shows the logo and legal screen. Then, about 150 s in, it crashes in game code (app.elf+0x260884e, SIGSEGV): UE4's small-block allocator pops a per-thread free list whose head is 0xffffffffffffffff.

What happens, from a gdb run (breakpoint on MarkDccUncompressed, hardware watchpoint on the corrupted word):

  1. The title renders into four 1920x1088 RGBA8 targets. Each one's 64 KiB DCC key block sits right after it; for example the target at 0x2020800000 has keys at 0x2021800000.
  2. At the first write, StorageTexture::MarkDirty stores 0xc000 uncompressed keys there (uploadedKeys becomes Uncompressed).
  3. After the legal screen the title frees the targets. UE4's allocator takes the key block: game code (app+0x25f9ea8, app+0x26086dc, ...) writes heap pointers (0x1020e5....) to 0x2021800020.
  4. A later dispatch's AcquireRegistered → FlushForAccess → writeBack → writeBackLayers runs the targets' pending write-backs. Each calls MarkDccUncompressed again. Its AlreadyUncompressed check sees the allocator's bytes, not 0xff, so it stores 0xc000 bytes of 0xff over them.
  5. The next free-list pop dereferences 0xff...ff.

The address changes from run to run (0x2021800020, 0x2021a00020, 0x2021e00020), but it is always a key block that a write-back stores after the reuse.

Fix

The three write-back paths in writeBackLayers (GPU-direct, retile and CPU round trip) store the keys only when the image's uploaded keys are not Uncompressed already. In that case the first write, or an earlier write-back, already stored them, and nothing the driver saw has changed them since.

  • A title's key fill (filledKeys) still skips the store, as before.
  • A refresh that reads clear keys again (uploaded keys Clear*) still gets them stored at the next write-back.

Tested

Linux (Arch), GCC, Release, RADV, on main 99c1c26.

  • agc_driver_dcc_keys_first_write gets RunReusedKeys:
    • a first write stores 0xff keys;
    • the CPU then overwrites the key bytes with 0x5a, standing in for the title reusing the memory;
    • after FlushPending, the keys must still be 0x5a and the texels must hold the image's results.
  • On main it fails with 0 of 256 key bytes are 0x5a (key 0 is 0xff); with the fix it passes. The existing first-write, fill and refresh cases pass unchanged.
  • Full ctest: 825/825 (4 video-out flip tests skipped as usual).
  • RIDE 4 with the fix runs past the crash. It reaches its title screen at about 118 s and runs to about 290 s, where it stops at sceAjmBatchJobSetResampleParametersEx: a ratio change per sample is unsupported.
  • tools/check_conventions.py passes.

@Celegans12, this changes when the keys from your first-write store are written again at write-back. Does it miss a case you had in mind?

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

alfalfa-star and others added 2 commits October 11, 2026 12:51
…t stored yet

MarkDirty stores uncompressed keys at an image's first write and marks
its uploaded keys uncompressed. The write-back stored them again,
whenever the key bytes did not read uncompressed. By then the title may
have reused the metadata memory: RIDE 4 (PPSA01599) frees its 1920x1088
render targets after the legal screen and Unreal Engine's small-block
allocator takes the 64 KiB key block that followed one of them. The
deferred write-back then filled the allocator's free lists with 0xff
and the title crashed popping one.

The write-back now stores keys only when the image's uploaded keys are
not uncompressed already, that is when no store at the first write or
an earlier write-back made them so since the keys were last read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e-back

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked build and ctest (libSceAgcDriver scope, 382/382) on the PR merged onto main. agc_driver_dcc_keys_first_write passes with the change and RunReusedKeys fails without it. The three write-back paths now skip the key store only when the first write or an earlier write-back already stored Uncompressed; the fill and Clear* refresh cases are unchanged. Merging.

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.

2 participants