fix(agc): prefer the pending image of exactly a sampled surface over an aliasing mip chain #1494

Merged
TideOPL merged 3 commits from upstream-pr/1494 into main 2026-10-10 05:25:25 +00:00
TideOPL commented 2026-10-08 09:15:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-08T09:15:15Z.


What

StorageTexture::FindPending returned the first pending storage image at a texture's address that is at least as long as the surface. When transient surfaces alias, that can be the wrong image.

Unreal's depth of field does this: the reduce pass writes a 2-mip 1424x800 RGBA16F chain, and right after, the post-filter and bokeh scatter write a 1-mip 1424x800 surface at the same address, each with its own DCC keys. When the recombine sampled the newer single-mip surface, the lookup could pick the older chain. The chain's view was then refreshed under its own keys, which the title had already re-filled with a fast-clear code, so whole blocks read as the clear value (0, 0, 0, 1) instead of what the GPU had just written. On screen these were large black rectangles at 8x8-workgroup granularity, at the same positions every frame.

Now an image whose length equals the surface's wins. A longer chain still serves a descriptor of its first mips when no exact image is pending, so the containment case it was written for is unchanged.

Tested

Windows 11, NVIDIA RTX 5070 (driver 610.88).

  • PPSA16064 (Minecraft Dungeons II): the title screen's DOF recombine output had fixed black rectangles covering most of the screen. With this change the whole frame renders. I located the cause by probing the recombine's registers per pixel: in the holes, the foreground-layer sample came back as (0, 0, 0, 1) while the GPU-side image held the real data.
  • ctest: 426 of 426 pass on current main with this PR and #1495 (unrelated files) applied.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4784528924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1494). Originally posted by [TideOPL](https://github.com/TideOPL) on 2026-10-08T09:15:15Z. --- ### What `StorageTexture::FindPending` returned the first pending storage image at a texture's address that is at least as long as the surface. When transient surfaces alias, that can be the wrong image. Unreal's depth of field does this: the reduce pass writes a 2-mip 1424x800 RGBA16F chain, and right after, the post-filter and bokeh scatter write a 1-mip 1424x800 surface at the same address, each with its own DCC keys. When the recombine sampled the newer single-mip surface, the lookup could pick the older chain. The chain's view was then refreshed under its own keys, which the title had already re-filled with a fast-clear code, so whole blocks read as the clear value (0, 0, 0, 1) instead of what the GPU had just written. On screen these were large black rectangles at 8x8-workgroup granularity, at the same positions every frame. Now an image whose length equals the surface's wins. A longer chain still serves a descriptor of its first mips when no exact image is pending, so the containment case it was written for is unchanged. ### Tested Windows 11, NVIDIA RTX 5070 (driver 610.88). - PPSA16064 (Minecraft Dungeons II): the title screen's DOF recombine output had fixed black rectangles covering most of the screen. With this change the whole frame renders. I located the cause by probing the recombine's registers per pixel: in the holes, the foreground-layer sample came back as (0, 0, 0, 1) while the GPU-side image held the real data. - `ctest`: 426 of 426 pass on current `main` with this PR and #1495 (unrelated files) applied. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
klosixgaming-arch commented 2026-10-08 11:31:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:31:20Z.

Review: APPROVED


Good fix for storage texture pending lookup. This properly handles cases where multiple textures overlap at the same address by preferring exact matches over containment matches, preventing incorrect texture reuse.

Strengths:

  • Clean fix for a subtle bug in texture lookup logic
  • Proper handling of both exact matches and containment cases
  • Good use of weak_from_this() for thread-safe shared pointer management
  • Clear comments explaining the containment vs equality distinction

This will improve rendering correctness by ensuring the right texture is found during pending lookups. Ready to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5455877196 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1494#pullrequestreview-5455877196). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T11:31:20Z. **Review:** APPROVED --- Good fix for storage texture pending lookup. This properly handles cases where multiple textures overlap at the same address by preferring exact matches over containment matches, preventing incorrect texture reuse. **Strengths:** - Clean fix for a subtle bug in texture lookup logic - Proper handling of both exact matches and containment cases - Good use of weak_from_this() for thread-safe shared pointer management - Clear comments explaining the containment vs equality distinction This will improve rendering correctness by ensuring the right texture is found during pending lookups. Ready to merge.
adriadam10 commented 2026-10-09 23:36:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:36:17Z.

Review: DISMISSED


The change itself reads right: preferring the image whose guestBytes equals the sampled surface's, and keeping the first containing image as a fallback, leaves the chain-prefix case untouched.

One thing is missing before this can merge:

  • There is no test. A fix reported on a title needs a Linux test that reproduces it (CONTRIBUTING). Two pending storage images at the same address, a 2-mip chain and a 1-mip surface of the same extent, with FindPending asked for the 1-mip size, should return the single-mip image, and for the first-mips-of-a-chain case still return the chain. The execution tests in core/libs/prx/libSceAgcDriver/tests/execution/ (e.g. DccKeysFirstWrite.cpp) already drive pending images and can be extended. The test should fail on current main and pass with this change, and be registered in ctest.

Build and the libSceAgcDriver ctest scope pass locally with the change applied; the Minecraft Dungeons II result on Windows/NVIDIA could not be verified here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5476357087 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1494#pullrequestreview-5476357087). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T23:36:17Z. **Review:** DISMISSED --- The change itself reads right: preferring the image whose `guestBytes` equals the sampled surface's, and keeping the first containing image as a fallback, leaves the chain-prefix case untouched. One thing is missing before this can merge: - There is no test. A fix reported on a title needs a Linux test that reproduces it (CONTRIBUTING). Two pending storage images at the same address, a 2-mip chain and a 1-mip surface of the same extent, with `FindPending` asked for the 1-mip size, should return the single-mip image, and for the first-mips-of-a-chain case still return the chain. The execution tests in `core/libs/prx/libSceAgcDriver/tests/execution/` (e.g. `DccKeysFirstWrite.cpp`) already drive pending images and can be extended. The test should fail on current `main` and pass with this change, and be registered in ctest. Build and the libSceAgcDriver ctest scope pass locally with the change applied; the Minecraft Dungeons II result on Windows/NVIDIA could not be verified here.
TideOPL commented 2026-10-10 00:21:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-10T00:21:13Z.


Thanks. I added the execution test agc_driver_pending_exact_surface (tests/execution/PendingExactSurface.cpp, picked up by the existing glob, so it's in ctest). It writes mip 0 of a 2-mip 256x256 R32 surface, then a 1-mip surface at the same address. The chain's mip 0 lies past the 1-mip surface's bytes, so both stay pending, with the chain first.

  • Only the chain pending: a lookup of the 1-mip size returns the chain (first-mips case unchanged).
  • Both pending: it returns the 1-mip image.

On current main the second lookup returns the 327680-byte 2-mip chain. Full ctest passes on Linux and Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6091540039 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1494#issuecomment-6091540039). Originally posted by [TideOPL](https://github.com/TideOPL) on 2026-10-10T00:21:13Z. --- Thanks. I added the execution test `agc_driver_pending_exact_surface` (`tests/execution/PendingExactSurface.cpp`, picked up by the existing glob, so it's in ctest). It writes mip 0 of a 2-mip 256x256 R32 surface, then a 1-mip surface at the same address. The chain's mip 0 lies past the 1-mip surface's bytes, so both stay pending, with the chain first. - Only the chain pending: a lookup of the 1-mip size returns the chain (first-mips case unchanged). - Both pending: it returns the 1-mip image. On current `main` the second lookup returns the 327680-byte 2-mip chain. Full ctest passes on Linux and Windows.
oneandonlydean commented 2026-10-10 05:25:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:25:22Z.


The test that was asked for is in 3fba616bb5 (a pending surface aliased by a pending mip chain), and this head passed the full Linux and Windows build in the merge-train run 38023415505, so the change request is resolved. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094190652 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1494#issuecomment-6094190652). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T05:25:22Z. --- The test that was asked for is in 3fba616bb5 (a pending surface aliased by a pending mip chain), and this head passed the full Linux and Windows build in the merge-train run 38023415505, so the change request is resolved. Merging.
Sign in to join this conversation.
No reviewers
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!1494
No description provided.