fix(agc): rotate the bank of PS4 array layers like addrlib #12998

Merged
xXPBSXx merged 2 commits from upstream-pr/12998 into main 2026-10-30 09:55:55 +00:00
xXPBSXx commented 2026-10-29 20:03:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-29T20:03:01Z.


What

The layers of a PS4 macro-tiled array were placed by a plain offset, with the same bank bits in every layer. For the non-PRT modes the AMD address library also rotates the bank by (banks / 2 - 1) times the layer index, and applies it to the bank as one XOR of the sum with the bank swizzle (egbaddrlib.cpp L3002-L3049). That is the XOR form shadPS4 uses; fpPS4 adds the rotation after the XOR instead.

This adds GcnLayerBankXor, the rotation of one layer as a constant in the bank bits of the address (shift taken from the tile geometry, bit 11 for the 8-pipe modes modelled here), and the detiler passes it with its existing bank/pipe XOR, so the shader is unchanged. The product (banks / 2 - 1) * layer is taken modulo the bank count; it is not a bitwise function of the layer index, so it cannot be folded into the swizzle equation. It applies to the non-PRT modes (Display2D, Thin2D, Depth2D*) from layer 1 and only to mips that are macro-tiled; PRT modes and the micro-tiled small mips are unchanged. The bank swizzle of the surface is taken as 0, as before.

Only surfaces with a gcnPitch (PS4 GCN) are affected; PS5 modes are not. A PS4 color target view of an array slice is rejected on main (DecodeGcnColorBuffer throws for a slice other than 0), so no color-target path addresses PS4 array layers yet; a change that allows such a view with a plain slice offset would need this rotation as well. The rotation rests on the address library and the two emulators; it is not measured on a console, and no title that reaches it has been run.

Commits: the test commit comes first and fails on main for the non-PRT modes from layer 1; the fix commit makes it pass.

Overlap

Open PRs that change TextureTiling.hpp, TextureTiling.cpp, TextureDetiler.cpp, TextureDetile.comp or the two tests tests/TextureTiling.cpp and tests/execution/GcnDetile.cpp (file sets from git diff --name-only against each PR head's merge base, all 1470 open pull requests as of 2026-10-29 19:20, main bb04a4f1ea): 26 touch these files or are ours. git merge-tree of this branch against each of them gives the same result with and without these commits, so none of them gets a new conflict from this PR. #9674 (tile mode 19) edits the same files and merges without a text conflict; a trial merge of both builds, and the tests below pass on it. The 16 pull requests opened since then (#12979 to #12994, checked 2026-10-29 20:25 against main 58b2753d74, which did not change these files) touch none of them. No open PR adds a bank rotation for array layers. Re-checked when opening against the 14 pull requests opened since 19:20 and main 420b6a064e (which has not changed these files): none of them touches them.

Tested

Windows 10 Pro 10.0.19045. agc_driver_gcn_detile_tests (GPU) and agc_driver_graphics_tests (the CPU tiling tests among them), with 1 and 2 mip levels and array layers 0 to 5:

  • Test commit a12f933bb8 alone, on top of main bb04a4f1ea: the GPU test fails on an NVIDIA GeForce RTX 4080 SUPER and on an AMD Radeon RX 6400 at array layer 1 (detiled as 204, expected 0), and the tiling test fails with is at 524288, addrlib places it at 538624.
  • With the fix commit c7a3fff544: all three pass, the GPU test on both GPUs (RTX 4080 SUPER, driver package 32.0.16.1074; RX 6400, 32.0.21033.3005, as reported by Windows).
  • Trial merge of this branch with #9674 (head 356cb639ef): the same three runs pass.
    tools/check_conventions.py --base upstream/main passes. No title was run.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4080 SUPER (32.0.16.1074) and AMD Radeon RX 6400 (32.0.21033.3005), Windows 10 Pro 10.0.19045
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5074731900 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12998). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-29T20:03:01Z. --- ### What The layers of a PS4 macro-tiled array were placed by a plain offset, with the same bank bits in every layer. For the non-PRT modes the AMD address library also rotates the bank by `(banks / 2 - 1)` times the layer index, and applies it to the bank as one XOR of the sum with the bank swizzle ([`egbaddrlib.cpp` L3002-L3049](https://gitlab.freedesktop.org/mesa/mesa/-/blob/393bf0d1467c4a7e208fd0d36b05b99438926079/src/amd/addrlib/src/r800/egbaddrlib.cpp#L3002-L3049)). That is the XOR form shadPS4 uses; fpPS4 adds the rotation after the XOR instead. This adds `GcnLayerBankXor`, the rotation of one layer as a constant in the bank bits of the address (shift taken from the tile geometry, bit 11 for the 8-pipe modes modelled here), and the detiler passes it with its existing bank/pipe XOR, so the shader is unchanged. The product `(banks / 2 - 1) * layer` is taken modulo the bank count; it is not a bitwise function of the layer index, so it cannot be folded into the swizzle equation. It applies to the non-PRT modes (`Display2D`, `Thin2D`, `Depth2D*`) from layer 1 and only to mips that are macro-tiled; PRT modes and the micro-tiled small mips are unchanged. The bank swizzle of the surface is taken as 0, as before. Only surfaces with a `gcnPitch` (PS4 GCN) are affected; PS5 modes are not. A PS4 color target view of an array slice is rejected on `main` (`DecodeGcnColorBuffer` throws for a slice other than 0), so no color-target path addresses PS4 array layers yet; a change that allows such a view with a plain slice offset would need this rotation as well. The rotation rests on the address library and the two emulators; it is not measured on a console, and no title that reaches it has been run. Commits: the test commit comes first and fails on `main` for the non-PRT modes from layer 1; the fix commit makes it pass. ### Overlap Open PRs that change `TextureTiling.hpp`, `TextureTiling.cpp`, `TextureDetiler.cpp`, `TextureDetile.comp` or the two tests `tests/TextureTiling.cpp` and `tests/execution/GcnDetile.cpp` (file sets from `git diff --name-only` against each PR head's merge base, all 1470 open pull requests as of 2026-10-29 19:20, main `bb04a4f1ea`): 26 touch these files or are ours. `git merge-tree` of this branch against each of them gives the same result with and without these commits, so none of them gets a new conflict from this PR. #9674 (tile mode 19) edits the same files and merges without a text conflict; a trial merge of both builds, and the tests below pass on it. The 16 pull requests opened since then (#12979 to #12994, checked 2026-10-29 20:25 against main `58b2753d74`, which did not change these files) touch none of them. No open PR adds a bank rotation for array layers. Re-checked when opening against the 14 pull requests opened since 19:20 and main `420b6a064e` (which has not changed these files): none of them touches them. ### Tested Windows 10 Pro 10.0.19045. `agc_driver_gcn_detile_tests` (GPU) and `agc_driver_graphics_tests` (the CPU tiling tests among them), with 1 and 2 mip levels and array layers 0 to 5: - Test commit `a12f933bb8` alone, on top of main `bb04a4f1ea`: the GPU test fails on an NVIDIA GeForce RTX 4080 SUPER and on an AMD Radeon RX 6400 at array layer 1 (`detiled as 204, expected 0`), and the tiling test fails with `is at 524288, addrlib places it at 538624`. - With the fix commit `c7a3fff544`: all three pass, the GPU test on both GPUs (RTX 4080 SUPER, driver package 32.0.16.1074; RX 6400, 32.0.21033.3005, as reported by Windows). - Trial merge of this branch with #9674 (head `356cb639ef`): the same three runs pass. `tools/check_conventions.py --base upstream/main` passes. No title was run. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4080 SUPER (32.0.16.1074) and AMD Radeon RX 6400 (32.0.21033.3005), Windows 10 Pro 10.0.19045 - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-29 21:57:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T21:57:25Z.

Review: APPROVED


Reviewed — looks good

The array-layer bank rotation matches the cited address-library rule and is covered by tiling and GPU detile tests; I found no blocking issue in the exact head reviewed.

What I ran

  • PR head: c7a3fff5445fae8de8497a87fdabc25c30b0677f.
  • Base: upstream/main at d820fef1827f27247cd28da7b4eec7891904bae5; current-main merge preview was clean (3056b89e4d4bd99822a2c30c5dd18cd415163ca6). The changed tiling, detiler, shader, and test paths have not changed on current main since the PR's reported bb04a4f1ea comparison base.
  • Environment: Linux x86_64; no local build or GPU tests run.
git diff --check upstream/main...refs/review/pr-12998-head
git merge-tree --write-tree upstream/main refs/review/pr-12998-head
python tools/check_conventions.py --base upstream/main --head refs/review/pr-12998-head
git diff --name-only bb04a4f1ea...upstream/main -- core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp core/libs/prx/libSceAgcDriver/Graphics/shaders/TextureDetile.comp core/libs/prx/libSceAgcDriver/tests/TextureTiling.cpp core/libs/prx/libSceAgcDriver/tests/execution/GcnDetile.cpp

Results

Check Result
Patch whitespace Pass; command exited 0 with no output.
Current-main merge preview Pass; clean tree 3056b89e4d4bd99822a2c30c5dd18cd415163ca6.
Repository conventions Pass.
Source review Pass; the layer contribution is rotated in the bank bits for non-PRT macro-tiled modes, while layer 0, PRT, and micro-tiled mips remain unchanged.
Hosted CI Windows product, eligibility, conventions, intake, labels, and report checks passed; Linux and specialized jobs were skipped.
GPU tests The PR reports Windows tests on RTX 4080 SUPER and RX 6400, including failing controls on the test-only commit and passing results with the fix. An external report also records a GPU run on RTX 2000 Ada with no new failures or validation IDs. These were not run locally.
Unedited local command output

python tools/check_conventions.py --base upstream/main --head refs/review/pr-12998-head

All conventions checks passed.

git merge-tree --write-tree upstream/main refs/review/pr-12998-head

3056b89e4d4bd99822a2c30c5dd18cd415163ca6

git diff --check upstream/main...refs/review/pr-12998-head exited 0 with no output. The current-main changed-path comparison also produced no output.

Sources

Not verified

  • I did not build or run GPU tests locally. Linux product CI was skipped, and no title or physical console was tested.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5705512364 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12998#pullrequestreview-5705512364). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T21:57:25Z. **Review:** APPROVED --- # Reviewed — looks good The array-layer bank rotation matches the cited address-library rule and is covered by tiling and GPU detile tests; I found no blocking issue in the exact head reviewed. ## What I ran - PR head: `c7a3fff5445fae8de8497a87fdabc25c30b0677f`. - Base: `upstream/main` at `d820fef1827f27247cd28da7b4eec7891904bae5`; current-main merge preview was clean (`3056b89e4d4bd99822a2c30c5dd18cd415163ca6`). The changed tiling, detiler, shader, and test paths have not changed on current `main` since the PR's reported `bb04a4f1ea` comparison base. - Environment: Linux x86_64; no local build or GPU tests run. ```sh git diff --check upstream/main...refs/review/pr-12998-head git merge-tree --write-tree upstream/main refs/review/pr-12998-head python tools/check_conventions.py --base upstream/main --head refs/review/pr-12998-head git diff --name-only bb04a4f1ea...upstream/main -- core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp core/libs/prx/libSceAgcDriver/Graphics/shaders/TextureDetile.comp core/libs/prx/libSceAgcDriver/tests/TextureTiling.cpp core/libs/prx/libSceAgcDriver/tests/execution/GcnDetile.cpp ``` ## Results | Check | Result | |---|---| | Patch whitespace | Pass; command exited 0 with no output. | | Current-main merge preview | Pass; clean tree `3056b89e4d4bd99822a2c30c5dd18cd415163ca6`. | | Repository conventions | Pass. | | Source review | Pass; the layer contribution is rotated in the bank bits for non-PRT macro-tiled modes, while layer 0, PRT, and micro-tiled mips remain unchanged. | | Hosted CI | Windows product, eligibility, conventions, intake, labels, and report checks passed; Linux and specialized jobs were skipped. | | GPU tests | The PR reports Windows tests on RTX 4080 SUPER and RX 6400, including failing controls on the test-only commit and passing results with the fix. An external report also records a GPU run on RTX 2000 Ada with no new failures or validation IDs. These were not run locally. | <details> <summary>Unedited local command output</summary> `python tools/check_conventions.py --base upstream/main --head refs/review/pr-12998-head` ```text All conventions checks passed. ``` `git merge-tree --write-tree upstream/main refs/review/pr-12998-head` ```text 3056b89e4d4bd99822a2c30c5dd18cd415163ca6 ``` `git diff --check upstream/main...refs/review/pr-12998-head` exited 0 with no output. The current-main changed-path comparison also produced no output. </details> ## Sources - [PR-pinned texture tiling implementation](https://github.com/boykopovar/AnyPS5/blob/c7a3fff5445fae8de8497a87fdabc25c30b0677f/core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp) - [AMD addrlib reference pinned to commit `393bf0d1467c4a7e208fd0d36b05b99438926079`](https://gitlab.freedesktop.org/mesa/mesa/-/blob/393bf0d1467c4a7e208fd0d36b05b99438926079/src/amd/addrlib/src/r800/egbaddrlib.cpp#L3002-L3049) ## Not verified - I did not build or run GPU tests locally. Linux product CI was skipped, and no title or physical console was tested.
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!12998
No description provided.