Skip to content

fix(agc): keep a surface's results in the 64 KiB block it shares with its neighbour - #441

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
oneandonlydean:fix/agc-partial-block-write-coverage
Oct 3, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
oneandonlydean:fix/agc-partial-block-write-coverage

Conversation

@oneandonlydean

Copy link
Copy Markdown
Collaborator

What

Write stamps are kept per 64 KiB block, so a write-back of one surface stamps the whole block it shares with a surface packed right after it. A pending storage image of that neighbour read the stamp as a store over its own bytes: its write-back kept the guest bytes of the shared block in place of its results, and its next refresh re-uploaded those stale bytes.

PPSA21564's half-resolution fog texture (960x540 RGBA16F, linear) starts 0xb800 bytes before a block end, right after another 960x540 surface. It lost its first 6 rows that way, and the fog composite upsampled them into an orange band across the top 12 rows of the scene in one of its cinematics. It depended on when the deferred write-backs ran, so some runs showed it every frame and others rarely.

  • The write tracker now remembers the byte ranges of the driver's own stores (MarkWritten) in the blocks they cover only in part: up to four ranges per block. When a range is overwritten, the block keeps its generation, so a forgotten range still counts as a store.
  • New GuestMemory::StoredOver(address, bytes, generation) says whether a store reached that range since a generation. A CPU store, a whole-block driver store, a dropped range or an unwatched range still counts for the whole block, so the answer is never "not stored" when a store may have landed.
  • The write-back keep rule (writeBackLayers) and the refresh drop rule (Refresh) ask it only for the blocks a surface covers in part; whole blocks behave as before.

Tested

  • Linux (CachyOS, x86-64): full build with BUILD_TESTING=ON and ctest pass (127/127).
  • New agc_write_tracking (ctest, CPU only; skipped with code 77 when write watching is unavailable): two surfaces sharing a block at the same 0xb800 offset; a store of the first surface's bytes does not count over the second surface's part of the shared block but does over its own; a store into the second part, a whole-block store, more partial stores than the tracker keeps, and a CPU store in the block all count; a store older than the generation does not; a range the tracker does not cover always counts (checked on Linux; on Windows the tracker covers the whole guest arena range, so the test has no such range there). StoredOver is new, so the test does not build without this change.
  • PPSA21564: the cinematic showed the band in 252 frames of a run before and in none after, and the change has been on my integration branch through repeated passes of my visual regression check (checkpoint frames, flicker, shimmer, video tearing, FPS).

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

… its neighbour

Write stamps are per 64 KiB block, so a write-back of one surface stamps the
whole block it shares with the surface packed right after it. A pending
image of that neighbour read the stamp as a store over its own bytes: its
write-back kept the guest bytes of the shared block in place of its results
and its next refresh re-uploaded them, stale. PPSA21564's half-resolution
fog texture (960x540 RGBA16F, linear, starting 0xb800 bytes before a block
end right after another 960x540 surface) lost its first 6 rows that way,
which the fog composite upsampled into an orange band across the top 12
rows of the scene in one of its cinematics.

The tracker now remembers the byte ranges of the driver's own stores
(MarkWritten) in the blocks they cover only in part, and StoredOver says
whether a store reached a given range since a generation (a CPU store still
counts for its whole block). The write-back keep rule and the refresh drop
rule ask it for the blocks a surface covers only in part.
@oneandonlydean
oneandonlydean force-pushed the fix/agc-partial-block-write-coverage branch from b03393f to 01bcab3 Compare October 3, 2026 07:43
@oneandonlydean

Copy link
Copy Markdown
Collaborator Author

The Linux failure in the first CI run is agc_driver_vopc_compare (thread 1 compare 39 is 0, expected 1), the intermittent llvmpipe failure I described in #399 (comment). This PR doesn't touch the shader path; Windows passed in the same run. I rebased onto current main to start a fresh run.

@github-actions github-actions Bot added build agc libSceAgc* labels Oct 3, 2026
@oneandonlydean
oneandonlydean merged commit be7d33b into boykopovar:main Oct 3, 2026
3 checks passed
@oneandonlydean
oneandonlydean deleted the fix/agc-partial-block-write-coverage branch October 3, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant