fix(agc): render a slice of a 2D array color target into that layer of the array #3524

Merged
XairRrR merged 1 commit from upstream-pr/3524 into main 2026-10-11 21:30:08 +00:00
XairRrR commented 2026-10-11 12:18:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-11T12:18:24Z.


What

A color view of slice N of a 2D array (CB_COLOR_VIEW SLICE_START, with CB_COLOR_ATTRIB3 MIP0_DEPTH as the last slice) was rendered as a plain 2D surface at the slice's address (#2626 moves the address by the slice size). The swizzle equations of the XOR tile modes take the slice index: the detiler feeds it to the equation's slice bits (TextureDetile.comp), so the driver samples slice N of an array in that layout. So the texels of slice N of an array are not where a 2D surface at that address puts them. A title that renders into array slices and then samples the array reads them scrambled.

Measured with the new test: in slice 1 of a 128x128 R32 SW_64KB_R_X array, texel (0, 0) sits at dword 0x200 of the slice, where the 2D layout puts texel (0, 0) at dword 0.

Changes:

  • DecodeColorBuffer keeps the array's address, its last slice and the view's slice in the ColorTarget. The slice address is unchanged.
  • A resident target that is a slice of an array attaches that layer of the array's storage image, so its texels follow the array's layout. Storage images of 2D arrays are color attachments for this, and AttachmentView takes a layer.
  • A slice that has no resident array image (DCC, CMASK, an attachment proxy, or a linear array) now throws when the array is XOR-tiled, instead of being written in the 2D layout. Otherwise it keeps the 2D path, where the layouts agree.

Test tests/execution/ArrayLayerTarget.cpp:

  • draws a 16-pixel-wide scissor into slice 1 of a 4-slice array color view;
  • checks the draw rendered into the array's image;
  • reads slice 1 through the array: the drawn texels inside the scissor, the old ones outside;
  • checks slices 0, 2 and 3 unchanged;
  • after the write-back, uploads the array again from guest memory and reads the same slice 1.

On main it fails at the first read ("slice 1 read through the array after the draw: texel (0, 0) reads 0x5a5a5a5a, expected 0x3e800000").

The titles of #2626 (VITA5 PPSA39410, Homebrew UI Lab PPSA99050) render through such slice views of an XOR-tiled array (CB_COLOR_ATTRIB3 0x4dc6c001, MIP0_DEPTH 1); I have not run them. PPSA05684 does not take this path: its layer targets are plain 2D views at the layers' addresses, so the change has no effect there (checked in its menu, no draw through a slice view).

Tested

  • Arch Linux (kernel 7.2.6), GCC 16.2.1, NVIDIA RTX 4070 Ti SUPER (driver 615.71.09), Release with BUILD_TESTING=ON.
  • Branch built alone on main a11c8f7f. Full ctest: 832/833. The one failure, agc_driver_emulated_color_compare, fails the same way on plain main. Conventions check passed.
  • Title: Uncharted: Legacy of Thieves Collection (PPSA05684), on its own bring-up branch.

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
    • Overlaps #1077 on AttachmentView (see comment)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818990483 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3524). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-11T12:18:24Z. --- ### What A color view of slice N of a 2D array (`CB_COLOR_VIEW` `SLICE_START`, with `CB_COLOR_ATTRIB3` `MIP0_DEPTH` as the last slice) was rendered as a plain 2D surface at the slice's address (#2626 moves the address by the slice size). The swizzle equations of the XOR tile modes take the slice index: the detiler feeds it to the equation's slice bits (`TextureDetile.comp`), so the driver samples slice N of an array in that layout. So the texels of slice N of an array are not where a 2D surface at that address puts them. A title that renders into array slices and then samples the array reads them scrambled. Measured with the new test: in slice 1 of a 128x128 R32 `SW_64KB_R_X` array, texel (0, 0) sits at dword 0x200 of the slice, where the 2D layout puts texel (0, 0) at dword 0. Changes: - `DecodeColorBuffer` keeps the array's address, its last slice and the view's slice in the `ColorTarget`. The slice address is unchanged. - A resident target that is a slice of an array attaches that layer of the array's storage image, so its texels follow the array's layout. Storage images of 2D arrays are color attachments for this, and `AttachmentView` takes a layer. - A slice that has no resident array image (DCC, CMASK, an attachment proxy, or a linear array) now throws when the array is XOR-tiled, instead of being written in the 2D layout. Otherwise it keeps the 2D path, where the layouts agree. Test `tests/execution/ArrayLayerTarget.cpp`: - draws a 16-pixel-wide scissor into slice 1 of a 4-slice array color view; - checks the draw rendered into the array's image; - reads slice 1 through the array: the drawn texels inside the scissor, the old ones outside; - checks slices 0, 2 and 3 unchanged; - after the write-back, uploads the array again from guest memory and reads the same slice 1. On `main` it fails at the first read ("slice 1 read through the array after the draw: texel (0, 0) reads 0x5a5a5a5a, expected 0x3e800000"). The titles of #2626 (VITA5 PPSA39410, Homebrew UI Lab PPSA99050) render through such slice views of an XOR-tiled array (`CB_COLOR_ATTRIB3` `0x4dc6c001`, `MIP0_DEPTH` 1); I have not run them. PPSA05684 does not take this path: its layer targets are plain 2D views at the layers' addresses, so the change has no effect there (checked in its menu, no draw through a slice view). ### Tested - Arch Linux (kernel 7.2.6), GCC 16.2.1, NVIDIA RTX 4070 Ti SUPER (driver 615.71.09), Release with `BUILD_TESTING=ON`. - Branch built alone on main a11c8f7f. Full ctest: 832/833. The one failure, `agc_driver_emulated_color_compare`, fails the same way on plain main. Conventions check passed. - Title: Uncharted: Legacy of Thieves Collection (PPSA05684), on its own bring-up branch. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 - Overlaps #1077 on `AttachmentView` (see comment) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 12:38:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T12:38:35Z.


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
#1077 core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp L56
core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp L162, L532
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp L58-93, L1894
core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp L873-874
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L1320, L1324-1325, L1335, L1338
#3633 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp L874
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109105007 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3524#issuecomment-6109105007). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T12:38:35Z. --- <!-- 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 | |---|---|---|---| | #1077 | `core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp` [L56](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp#L56)<br>`core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp` [L162](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp#L162), [L532](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp#L532)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp` [L58-93](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp#L58-L93), [L1894](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp#L1894)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp` [L873-874](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp#L873-L874)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` [L1320](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L1320), [L1324-1325](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L1324-L1325), [L1335](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L1335), [L1338](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L1338) | | | | #3633 | `core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp` [L874](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp#L874) | | |
adriadam10 commented 2026-10-11 13:10:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T13:10:10Z.

Review: CHANGES_REQUESTED


Thanks, the approach (sharing the array's image per layer instead of a separate 2D image) makes sense. Local scoped build and ctest for libSceAgcDriver are green and agc_layer_alias passes. A few things before it can land:

  • Perf PRs need before/after numbers (CONTRIBUTING). Please post the frame time or the readback/upload count on PPSA05684 with and without the change.
  • agc_layer_alias only covers alias resolution and the attachment view. Nothing exercises the Draw.cpp:1886-1899 path: a 2D target attaching a layer, the former 2D image being flushed and evicted, and the result being visible when sampling the array. Please add a test that draws into a layer and samples the array.
  • When the standalone 2D layout differs from the array's layer (ShaderResources.cpp:848) the alias is silently skipped and the old path stays. Please list that in TechnicalDebt.md.

The red conventions/relinker jobs are the imgui gitlink on main (fixed in #3511), unrelated to this PR; they pass after a rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5483419025 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3524#pullrequestreview-5483419025). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T13:10:10Z. **Review:** CHANGES_REQUESTED --- Thanks, the approach (sharing the array's image per layer instead of a separate 2D image) makes sense. Local scoped build and ctest for libSceAgcDriver are green and `agc_layer_alias` passes. A few things before it can land: - Perf PRs need before/after numbers (CONTRIBUTING). Please post the frame time or the readback/upload count on PPSA05684 with and without the change. - `agc_layer_alias` only covers alias resolution and the attachment view. Nothing exercises the `Draw.cpp:1886-1899` path: a 2D target attaching a layer, the former 2D image being flushed and evicted, and the result being visible when sampling the array. Please add a test that draws into a layer and samples the array. - When the standalone 2D layout differs from the array's layer (`ShaderResources.cpp:848`) the alias is silently skipped and the old path stays. Please list that in TechnicalDebt.md. The red `conventions`/`relinker` jobs are the imgui gitlink on main (fixed in #3511), unrelated to this PR; they pass after a rebase.
XairRrR commented 2026-10-11 13:13:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-11T13:13:34Z.


On the overlap table above:

  • #1077 adds a layers count to StorageTexture::AttachmentView and its view cache key, to render layered draws into 3D color targets. This PR adds a layer index there, to attach one layer of a 2D array. Same lines, different features. Whichever lands second needs a rebase that keeps both arguments (layer selects the first layer, layers the count).
  • #2904 changes the depth-surface check at the top of cachedStorageTexture. This PR changes the same function further down (the layer alias lookup), so that one should only be a textual conflict.

Neither implements the same thing, so Depends on stays none. I'll rebase whichever way they land.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109396347 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3524#issuecomment-6109396347). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-11T13:13:34Z. --- On the overlap table above: - **#1077** adds a `layers` count to `StorageTexture::AttachmentView` and its view cache key, to render layered draws into 3D color targets. This PR adds a `layer` index there, to attach one layer of a 2D array. Same lines, different features. Whichever lands second needs a rebase that keeps both arguments (`layer` selects the first layer, `layers` the count). - **#2904** changes the depth-surface check at the top of `cachedStorageTexture`. This PR changes the same function further down (the layer alias lookup), so that one should only be a textual conflict. Neither implements the same thing, so Depends on stays none. I'll rebase whichever way they land.
XairRrR commented 2026-10-11 14:11:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-11T14:11:49Z.


Thanks for the review. Writing the test you asked for turned up a bug on main, so I've rewritten the PR around it (force-pushed, new title and description).

The test showed that slice N of an XOR-tiled 2D array does not have the layout of a 2D surface at the slice's address: the swizzle equation, as the detiler applies it, takes the slice index. In slice 1 of a 128x128 R32 SW_64KB_R_X array, texel (0, 0) sits at dword 0x200 of the slice. Since #2626 turns a view of slice N into a 2D target at the slice's address, a draw into slice N wrote the 2D layout and the array read it back scrambled. My first version only covered this when the array happened to be cached first.

On your three points:

  • Numbers: this is now a correctness fix rather than a perf change. The perf case I started from turned out to be different: PPSA05684 renders its layers through plain 2D views at the layer addresses, not through slice views, so this version does not touch it. I dropped the perf claim.
  • Test: tests/execution/ArrayLayerTarget.cpp draws into slice 1 of an array color view with a partial scissor and reads the slices back through the array, before and after a write-back. It fails on main.
  • TechnicalDebt: the address-based alias is gone, so nothing is skipped silently anymore. A slice that cannot use the array's image (DCC, CMASK, attachment proxy) throws when the array is XOR-tiled, and keeps the 2D path otherwise, where the layouts agree.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109906158 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3524#issuecomment-6109906158). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-11T14:11:49Z. --- Thanks for the review. Writing the test you asked for turned up a bug on `main`, so I've rewritten the PR around it (force-pushed, new title and description). The test showed that slice N of an XOR-tiled 2D array does not have the layout of a 2D surface at the slice's address: the swizzle equation, as the detiler applies it, takes the slice index. In slice 1 of a 128x128 R32 `SW_64KB_R_X` array, texel (0, 0) sits at dword 0x200 of the slice. Since #2626 turns a view of slice N into a 2D target at the slice's address, a draw into slice N wrote the 2D layout and the array read it back scrambled. My first version only covered this when the array happened to be cached first. On your three points: - **Numbers:** this is now a correctness fix rather than a perf change. The perf case I started from turned out to be different: PPSA05684 renders its layers through plain 2D views at the layer addresses, not through slice views, so this version does not touch it. I dropped the perf claim. - **Test:** `tests/execution/ArrayLayerTarget.cpp` draws into slice 1 of an array color view with a partial scissor and reads the slices back through the array, before and after a write-back. It fails on `main`. - **TechnicalDebt:** the address-based alias is gone, so nothing is skipped silently anymore. A slice that cannot use the array's image (DCC, CMASK, attachment proxy) throws when the array is XOR-tiled, and keeps the 2D path otherwise, where the layouts agree.
adriadam10 commented 2026-10-11 21:30:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:30:04Z.

Review: APPROVED


Checked on the PR merged onto current main: libSceAgcDriver build + ctest green, agc_driver_array_layer_target passes and fails with the array-layer branch in Draw.cpp disabled. CI green on this head. Merging.

Note for whoever lands second between this and #1077: both change StorageTexture::AttachmentView (layer here, layers there); the rebase keeps both.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5485046883 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3524#pullrequestreview-5485046883). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:30:04Z. **Review:** APPROVED --- Checked on the PR merged onto current `main`: libSceAgcDriver build + ctest green, `agc_driver_array_layer_target` passes and fails with the array-layer branch in `Draw.cpp` disabled. CI green on this head. Merging. Note for whoever lands second between this and #1077: both change `StorageTexture::AttachmentView` (`layer` here, `layers` there); the rebase keeps both.
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!3524
No description provided.