fix(agc): drop image stores to a view that starts past the surface's last mip level #483

Closed
ThisIsAkill wants to merge 1 commit from upstream-pr/483 into main
ThisIsAkill commented 2026-10-03 22:47:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-03T22:47:56Z.


What

A T# whose BASE_LEVEL is past its own MAX_MIP names a mip level the resource does not have. DecodeTextureResource threw guest texture descriptor starts past the surface's last mip level.

PPSA21567 (Astro Bot) hits this in a per-level compute chain. For a 1920x1080 surface with 6 levels it creates views of levels 0..6, and every one of them carries MAX_MIP = 5. It then runs one pass of the chain (same shader, same 60x34 grid as the valid levels) that stores into the level-6 view.

There are two ways to handle it; maintainers may prefer the other one:

  • Grow the image (KytyPS5): Kyty allocates max(MAX_MIP + 1, BASE_LEVEL + view levels) host levels, so the level-6 view gets a seventh, host-only level. The title runs there.
  • Drop the stores (this PR): treat the view as covering no level. Stores to it are discarded, and reads still fail.

I chose to drop because growing invents a level that the title's own descriptors say does not exist. Writing that level back could address memory the title never allocated for this surface, and sizing a cached surface from a view rather than from MAX_MIP would change it for every other view of that surface. This also extends a precedent already in DecodeTextureResource: a LAST_LEVEL past MAX_MIP is clamped, because "the hardware never addresses them".

Changes:

  • Recompiler: the image specialization gets an empty flag (non-null T#, not dynamic-mip, BASE_LEVEL > MAX_MIP), part of the variant and disk-cache keys (static_assert sizes updated). The backend compiles image_store to an empty image away. Loads, samples, size queries and atomics on it fail compilation. The T# level fields are read through small named helpers, also used by the two existing sites in ResourceMaterializer.cpp.
  • Driver: DecodeTextureResource returns such a view marked empty and clamped to MAX_MIP. The storage binding uses that existing level as a placeholder that is never written back. Sampled bindings of an empty view still throw (RequireLevelsPresent). Dynamic-mip storage writes to an empty view throw.
  • The discard is logged once per surface and level: [gpu] storage image view of surface 0x... starts at mip 6, past its last mip 5: the shader's stores to it are dropped.
  • TechnicalDebt entry.

Hardware behaviour: I found no AMD documentation for stores through a view whose BASE_LEVEL is past MAX_MIP (dropped or clamped). The RDNA2 ISA reference was not retrievable (its published URLs now redirect to the docs.amd.com portal), and searching turned up only emulator code. So this is a conservative choice, not a documented one. For comparison, stores past a view's extent are already left to the GPU here (image stores carry no bounds check and no robustness feature is enabled), and the title's valid passes at levels 3..5 rely on that.

Tested

  • Linux (CachyOS, GCC 16.2, RTX 3070): ctest 151/151 on current main + this branch.
  • New execution test agc_driver_empty_mip_view (2-level 8x8 R32_UINT surface): a store through the last real level reaches memory (positive control), a store through a level-2 view leaves memory untouched and logs once, and a load through the level-2 view fails to compile. New decode cases in GuestTextureResource.
  • PPSA21567 on Linux, on main with other open PRs and local changes (not clean main): the level-6 views of two surfaces log their dropped stores once each, and the title runs on (about 4 more minutes of rendering) to an unrelated texture error.

Overlap with #425 / #426: this PR is independent of both. The pr-overlap check flags ShaderResources.cpp because the edits touch neighbouring lines (textual overlap only, no shared behaviour). I'll rebase after either one merges.

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 (the dropped store is logged, not silent)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude). I reviewed it and take responsibility for every line.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4730299367 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/483). Originally posted by [ThisIsAkill](https://github.com/ThisIsAkill) on 2026-10-03T22:47:56Z. --- ### What A T# whose `BASE_LEVEL` is past its own `MAX_MIP` names a mip level the resource does not have. `DecodeTextureResource` threw `guest texture descriptor starts past the surface's last mip level`. PPSA21567 (Astro Bot) hits this in a per-level compute chain. For a 1920x1080 surface with 6 levels it creates views of levels 0..6, and every one of them carries `MAX_MIP = 5`. It then runs one pass of the chain (same shader, same 60x34 grid as the valid levels) that stores into the level-6 view. There are two ways to handle it; maintainers may prefer the other one: - **Grow the image (KytyPS5):** Kyty allocates `max(MAX_MIP + 1, BASE_LEVEL + view levels)` host levels, so the level-6 view gets a seventh, host-only level. The title runs there. - **Drop the stores (this PR):** treat the view as covering no level. Stores to it are discarded, and reads still fail. I chose to drop because growing invents a level that the title's own descriptors say does not exist. Writing that level back could address memory the title never allocated for this surface, and sizing a cached surface from a view rather than from `MAX_MIP` would change it for every other view of that surface. This also extends a precedent already in `DecodeTextureResource`: a `LAST_LEVEL` past `MAX_MIP` is clamped, because "the hardware never addresses them". Changes: - Recompiler: the image specialization gets an `empty` flag (non-null T#, not dynamic-mip, `BASE_LEVEL > MAX_MIP`), part of the variant and disk-cache keys (`static_assert` sizes updated). The backend compiles `image_store` to an empty image away. Loads, samples, size queries and atomics on it fail compilation. The T# level fields are read through small named helpers, also used by the two existing sites in `ResourceMaterializer.cpp`. - Driver: `DecodeTextureResource` returns such a view marked empty and clamped to `MAX_MIP`. The storage binding uses that existing level as a placeholder that is never written back. Sampled bindings of an empty view still throw (`RequireLevelsPresent`). Dynamic-mip storage writes to an empty view throw. - The discard is logged once per surface and level: `[gpu] storage image view of surface 0x... starts at mip 6, past its last mip 5: the shader's stores to it are dropped`. - TechnicalDebt entry. Hardware behaviour: I found no AMD documentation for stores through a view whose `BASE_LEVEL` is past `MAX_MIP` (dropped or clamped). The RDNA2 ISA reference was not retrievable (its published URLs now redirect to the docs.amd.com portal), and searching turned up only emulator code. So this is a conservative choice, not a documented one. For comparison, stores past a view's extent are already left to the GPU here (image stores carry no bounds check and no robustness feature is enabled), and the title's valid passes at levels 3..5 rely on that. ### Tested - Linux (CachyOS, GCC 16.2, RTX 3070): `ctest` 151/151 on current `main` + this branch. - New execution test `agc_driver_empty_mip_view` (2-level 8x8 R32_UINT surface): a store through the last real level reaches memory (positive control), a store through a level-2 view leaves memory untouched and logs once, and a load through the level-2 view fails to compile. New decode cases in `GuestTextureResource`. - PPSA21567 on Linux, on `main` with other open PRs and local changes (not clean `main`): the level-6 views of two surfaces log their dropped stores once each, and the title runs on (about 4 more minutes of rendering) to an unrelated texture error. **Overlap with #425 / #426:** this PR is independent of both. The pr-overlap check flags `ShaderResources.cpp` because the edits touch neighbouring lines (textual overlap only, no shared behaviour). I'll rebase after either one merges. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt (the dropped store is logged, not silent) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude). I reviewed it and take responsibility for every line. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-03 23:05:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-03T23:05:41Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#293 core/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hpp L68
#426 core/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hpp L68
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L513-514, L1641-1642, L2464-2465
#490 core/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hpp L63
core/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cpp L132, L166-167
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L513-516
core/libs/prx/libSceAgcDriver/tests/GuestTextureResource.cpp L271
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5974432519 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/483#issuecomment-5974432519). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-03T23:05:41Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #293 | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hpp` [L68](https://github.com/boykopovar/AnyPS5/blob/2cf901bcffef9ee1e12fe272e63a9978ceefed0d/core/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hpp#L68) | | | | #426 | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hpp` [L68](https://github.com/boykopovar/AnyPS5/blob/2cf901bcffef9ee1e12fe272e63a9978ceefed0d/core/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hpp#L68)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` [L513-514](https://github.com/boykopovar/AnyPS5/blob/2cf901bcffef9ee1e12fe272e63a9978ceefed0d/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L513-L514), [L1641-1642](https://github.com/boykopovar/AnyPS5/blob/2cf901bcffef9ee1e12fe272e63a9978ceefed0d/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L1641-L1642), [L2464-2465](https://github.com/boykopovar/AnyPS5/blob/2cf901bcffef9ee1e12fe272e63a9978ceefed0d/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L2464-L2465) | | | | #490 | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hpp` [L63](https://github.com/boykopovar/AnyPS5/blob/2cf901bcffef9ee1e12fe272e63a9978ceefed0d/core/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hpp#L63)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cpp` [L132](https://github.com/boykopovar/AnyPS5/blob/2cf901bcffef9ee1e12fe272e63a9978ceefed0d/core/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cpp#L132), [L166-167](https://github.com/boykopovar/AnyPS5/blob/2cf901bcffef9ee1e12fe272e63a9978ceefed0d/core/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cpp#L166-L167)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` [L513-516](https://github.com/boykopovar/AnyPS5/blob/2cf901bcffef9ee1e12fe272e63a9978ceefed0d/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L513-L516)<br>`core/libs/prx/libSceAgcDriver/tests/GuestTextureResource.cpp` [L271](https://github.com/boykopovar/AnyPS5/blob/2cf901bcffef9ee1e12fe272e63a9978ceefed0d/core/libs/prx/libSceAgcDriver/tests/GuestTextureResource.cpp#L271) | | |
oneandonlydean commented 2026-10-04 05:46:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:46:16Z.


Thanks for writing up both options so clearly. I hit the same chain in PPSA21564 (two 1920x1080 RGBA16F bloom chains, MAX_MIP 5, level 6 stored every frame) and went the other way on my integration branch, because I think the hardware does write that level. On GFX10, MAX_MIP only decides where the levels are placed: a level's address comes from the levels below it, and a level in the mip tail is a fixed slot of the tail block. For this surface addrlib gives the same layout for 6 and 7 levels, with level 6 in tail slot 1, so the store lands inside the surface's own allocation and levels 0 to 5 do not move. Dropping the stores then loses texels the console writes. My version addresses such a view only when extending the chain to the view's last level keeps the allocated levels and the surface size unchanged, keeps one storage image for the surface, and still throws otherwise (linear chains, chains without a tail). It is waiting on #394 because it touches the same tiling files. I can open it so the maintainer can compare the two; what do you think?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977043344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/483#issuecomment-5977043344). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T05:46:16Z. --- Thanks for writing up both options so clearly. I hit the same chain in PPSA21564 (two 1920x1080 RGBA16F bloom chains, MAX_MIP 5, level 6 stored every frame) and went the other way on my integration branch, because I think the hardware does write that level. On GFX10, MAX_MIP only decides where the levels are placed: a level's address comes from the levels below it, and a level in the mip tail is a fixed slot of the tail block. For this surface addrlib gives the same layout for 6 and 7 levels, with level 6 in tail slot 1, so the store lands inside the surface's own allocation and levels 0 to 5 do not move. Dropping the stores then loses texels the console writes. My version addresses such a view only when extending the chain to the view's last level keeps the allocated levels and the surface size unchanged, keeps one storage image for the surface, and still throws otherwise (linear chains, chains without a tail). It is waiting on #394 because it touches the same tiling files. I can open it so the maintainer can compare the two; what do you think?
ThisIsAkill commented 2026-10-04 06:15:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-04T06:15:45Z.


You're right, and thanks for explaining it. I checked with Mesa's addrlib (GFX10 path, Addr2ComputeSurfaceInfo; 1920x1080, 64 bpp, SW_64KB_R_X, 2D) for 6 and for 7 levels, under five GB_ADDR_CONFIG settings (Navi10 with 4, 8 and 16 pipes, Navi21, Navi22). They all agree:

  • Levels 0 to 5 have the same offsets either way, and the total size is the same (0x1640000).
  • The mip tail starts at level 5 (64x64) in both layouts.
  • Level 6 (32x32) is a slot in that same tail block (tail offset 0x4000, against 0x8000 for level 5), inside the allocation.

So the title's level-6 stores land in memory the surface already owns, and dropping them loses texels the console writes. Please open your version. I'll close #483 in favour of it once it's up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977232686 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/483#issuecomment-5977232686). Originally posted by [ThisIsAkill](https://github.com/ThisIsAkill) on 2026-10-04T06:15:45Z. --- You're right, and thanks for explaining it. I checked with Mesa's addrlib (GFX10 path, `Addr2ComputeSurfaceInfo`; 1920x1080, 64 bpp, `SW_64KB_R_X`, 2D) for 6 and for 7 levels, under five GB_ADDR_CONFIG settings (Navi10 with 4, 8 and 16 pipes, Navi21, Navi22). They all agree: - Levels 0 to 5 have the same offsets either way, and the total size is the same (0x1640000). - The mip tail starts at level 5 (64x64) in both layouts. - Level 6 (32x32) is a slot in that same tail block (tail offset 0x4000, against 0x8000 for level 5), inside the allocation. So the title's level-6 stores land in memory the surface already owns, and dropping them loses texels the console writes. Please open your version. I'll close #483 in favour of it once it's up.
ThisIsAkill commented 2026-10-04 12:41:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-04T12:41:59Z.


Closing in favour of #490, which writes the level-6 view into the mip tail the way the hardware does (verified with addrlib above). Thanks @oneandonlydean for the explanation and for opening it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5980033739 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/483#issuecomment-5980033739). Originally posted by [ThisIsAkill](https://github.com/ThisIsAkill) on 2026-10-04T12:41:59Z. --- Closing in favour of #490, which writes the level-6 view into the mip tail the way the hardware does (verified with addrlib above). Thanks @oneandonlydean for the explanation and for opening it.

Pull request closed

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!483
No description provided.