AGC: multisampled targets whose memory a title reuses throw on the next access (SONIC SUPERSTARS PPSA06888) #5933

Open
opened 2026-10-14 16:18:49 +00:00 by billythemenace2 · 1 comment
billythemenace2 commented 2026-10-14 16:18:49 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-14T16:18:49Z.


SONIC SUPERSTARS (PPSA06888) reuses the memory of 4x multisampled color targets it no longer draws to: for textures, a storage image and CPU-read data. Every such access throws, because a multisampled target's guard stays until its memory is unmapped. The title plays, but it stops a few minutes in: on entering or leaving a bonus stage, and in the main stage.

Observed (one per run):

a texture read of 0x284a10000+0x8000 overlaps multisampled color target 0x284a10000+0x10000 (4 samples)
a texture read of 0x25378f000+0x56000 overlaps multisampled color target 0x2537e0000+0x10000 (4 samples)
a texture read of 0x29e802000+0x40000 overlaps multisampled color target 0x29e830000+0x10000 (4 samples)
a texture read of 0x29e201000+0x80000 overlaps multisampled color target 0x29e230000+0x10000 (4 samples)
a CPU read of 0x28459fd00+0x4 overlaps multisampled color target 0x284590000+0x10000 (4 samples)
a storage image access of 0x293bb0000+0x1 overlaps multisampled color target 0x293bb0000+0x10000 (4 samples)

The second one is an ordinary texture: T# 025378f0 cad00000 007fc07f 90590fac 00000000 00700090 00000000 00000000, 512x512, format 173, 10 mips, tile mode 2, 0x56000 bytes, starting 0x51000 below the target. Every target in these errors is a 64 KiB 4x surface.

What did not work, so a fix needs another signal for "the target is dead":

  1. Retire on a CPU store (record the write-tracking generation at guard time, retire when UnchangedSinceCollected fails). It never fires here: a log at guard time shows GuestMemory::Watched false for every multisampled target in these runs (both the 4x and the 2x ones), so CPU stores into that memory are not seen.
  2. Retire when the driver writes guest memory over the target (a hook in Write, WriteChanged, StoreOwnBytes, MarkWritten). This is wrong. A log of those writes shows the same MarkWritten ranges over targets every frame, for example 0x26dcbfe30+0x14c70 over the target at 0x26dcc0000 and 0x286d0fd30+0x13fb0 over 0x286d10000. With the hook most of the scene disappeared, which points to targets still in use being retired.

Open question for the multisample code (#4474, #4820, #5445): what tells AnyPS5 that the guest has moved on from a target whose memory is not write-watched? Candidates I have not tried: a draw or dispatch binding the range as something other than this target (as in the storage image case above), or the guest allocator's free, if one is visible.

Setup: Windows 11, MinGW-w64 GCC 15, Release, AMD Radeon RX 5700 XT. main 5a6ad0ed3 plus #5865, #5375, #5456, #5882, #4820 and #5445 (the title's earlier stops), and a local footprint for the Z64KBX layout (#5445 comment).

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5851391432 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5933). Originally posted by [billythemenace2](https://github.com/billythemenace2) on 2026-10-14T16:18:49Z. --- SONIC SUPERSTARS (PPSA06888) reuses the memory of 4x multisampled color targets it no longer draws to: for textures, a storage image and CPU-read data. Every such access throws, because a multisampled target's guard stays until its memory is unmapped. The title plays, but it stops a few minutes in: on entering or leaving a bonus stage, and in the main stage. Observed (one per run): ``` a texture read of 0x284a10000+0x8000 overlaps multisampled color target 0x284a10000+0x10000 (4 samples) a texture read of 0x25378f000+0x56000 overlaps multisampled color target 0x2537e0000+0x10000 (4 samples) a texture read of 0x29e802000+0x40000 overlaps multisampled color target 0x29e830000+0x10000 (4 samples) a texture read of 0x29e201000+0x80000 overlaps multisampled color target 0x29e230000+0x10000 (4 samples) a CPU read of 0x28459fd00+0x4 overlaps multisampled color target 0x284590000+0x10000 (4 samples) a storage image access of 0x293bb0000+0x1 overlaps multisampled color target 0x293bb0000+0x10000 (4 samples) ``` The second one is an ordinary texture: T# `025378f0 cad00000 007fc07f 90590fac 00000000 00700090 00000000 00000000`, 512x512, format 173, 10 mips, tile mode 2, 0x56000 bytes, starting 0x51000 below the target. Every target in these errors is a 64 KiB 4x surface. **What did not work**, so a fix needs another signal for "the target is dead": 1. *Retire on a CPU store* (record the write-tracking generation at guard time, retire when `UnchangedSinceCollected` fails). It never fires here: a log at guard time shows `GuestMemory::Watched` false for every multisampled target in these runs (both the 4x and the 2x ones), so CPU stores into that memory are not seen. 2. *Retire when the driver writes guest memory over the target* (a hook in `Write`, `WriteChanged`, `StoreOwnBytes`, `MarkWritten`). This is wrong. A log of those writes shows the same `MarkWritten` ranges over targets every frame, for example `0x26dcbfe30+0x14c70` over the target at `0x26dcc0000` and `0x286d0fd30+0x13fb0` over `0x286d10000`. With the hook most of the scene disappeared, which points to targets still in use being retired. Open question for the multisample code (#4474, #4820, #5445): what tells AnyPS5 that the guest has moved on from a target whose memory is not write-watched? Candidates I have not tried: a draw or dispatch binding the range as something other than this target (as in the storage image case above), or the guest allocator's free, if one is visible. Setup: Windows 11, MinGW-w64 GCC 15, Release, AMD Radeon RX 5700 XT. `main` `5a6ad0ed3` plus #5865, #5375, #5456, #5882, #4820 and #5445 (the title's earlier stops), and a local footprint for the Z64KBX layout (#5445 comment). AI-assisted (Claude Code).
KingDarkHN commented 2026-10-16 13:40:45 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by KingDarkHN on 2026-10-16T13:40:45Z.


Addressed by #6808.

The signal you are looking for is the read site that reuses the range. Instead of keying retirement off a CPU store or a driver write to the target (your two attempts that did not work), this keys it off the guest-memory access that reuses the target's memory:

  • RequireNoMultisampleTarget drops the reused color guard instead of throwing, so the a texture read, a storage image access and a CPU read accesses in the log above retire the target they overlap.
  • RequireNoResidentDepthRead takes allowStaleOwnerRetirement; a read tagged Registers, TextureRead or VertexBuffer retires a stale depth owner whose range is no longer attached, while a read that still overlaps an attached target keeps refusing. The native depth lookup is moved ahead of the guard, so sampling a live depth target still goes through the depth path.

A guest read of a target's memory as something else (a texture, a vertex buffer, registers) is therefore the proof that the guest has moved on. A write to that memory is not needed, which is why it does not matter that GuestMemory::Watched is false for these targets.

Measured with #6808: SONIC SUPERSTARS got past the bonus stages and the main stage in a ~6 minute run (Linux, Omarchy/Arch, kernel 7.2.3, RTX 5060 Ti, driver 610.57.04) without this throw, and the full agc_driver suite stays at its pre-existing pass rate.

One caveat on the depth half: retiring a written depth owner drops its host image without publishing it back to guest memory, so it is a compatibility workaround rather than a full fix. That is recorded as a debt entry in the PR (docs/dev/debt/libSceAgcDriver.md) and discussed with #6727. The color-target half, which is this issue, has no such caveat.

The change is documented in detail on the pull request.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6216777037 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5933#issuecomment-6216777037). Originally posted by [KingDarkHN](https://github.com/KingDarkHN) on 2026-10-16T13:40:45Z. --- Addressed by #6808. The signal you are looking for is the **read site that reuses the range**. Instead of keying retirement off a CPU store or a driver write to the target (your two attempts that did not work), this keys it off the guest-memory access that reuses the target's memory: - `RequireNoMultisampleTarget` drops the reused color guard instead of throwing, so the `a texture read`, `a storage image access` and `a CPU read` accesses in the log above retire the target they overlap. - `RequireNoResidentDepthRead` takes `allowStaleOwnerRetirement`; a read tagged `Registers`, `TextureRead` or `VertexBuffer` retires a stale depth owner whose range is no longer attached, while a read that still overlaps an attached target keeps refusing. The native depth lookup is moved ahead of the guard, so sampling a live depth target still goes through the depth path. A guest read of a target's memory as something else (a texture, a vertex buffer, registers) is therefore the proof that the guest has moved on. A write to that memory is not needed, which is why it does not matter that `GuestMemory::Watched` is false for these targets. Measured with #6808: SONIC SUPERSTARS got past the bonus stages and the main stage in a ~6 minute run (Linux, Omarchy/Arch, kernel 7.2.3, RTX 5060 Ti, driver 610.57.04) without this throw, and the full `agc_driver` suite stays at its pre-existing pass rate. One caveat on the depth half: retiring a **written** depth owner drops its host image without publishing it back to guest memory, so it is a compatibility workaround rather than a full fix. That is recorded as a debt entry in the PR (`docs/dev/debt/libSceAgcDriver.md`) and discussed with #6727. The color-target half, which is this issue, has no such caveat. The change is documented in detail on the pull request.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#5933
No description provided.