fix(agc): retain cross-block R_X coordinate XORs #3482

Merged
MarcZX10 merged 2 commits from upstream-pr/3482 into main 2026-10-11 12:02:03 +00:00
MarcZX10 commented 2026-10-11 11:24:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T11:24:23Z.


What

Issue #3475 reports incorrect CPU offsets for SW_64KB_R_X color surfaces at 64 and 128 bits per element. On current main, core/libs/prx/libSceAgcDriver/Graphics/src/ColorTargetLayout.cpp:152 computes the in-block address from only the precomputed low coordinate bits:

return block * Alignment() + (xOffsets[x % blockWidth] ^ yOffsets[y % blockHeight] ^ pipeBankXor);

The R_X equations also XOR higher x/y coordinate bits into the in-block address. The current expression drops those terms when a surface crosses the nominal block width or height.

This change keeps the existing lookup tables for the low bits, then adds the high-coordinate equation contributions for R_X before applying the pipe/bank XOR. It adds fixed-address regressions for both reported cases:

  • 33x65, 64 bpp, (0, 64): offset 0x10800 (67584)
  • 129x67, 128 bpp, (64, 0): offset 0x10400 (66560)

The issue report attributes these expected values to an independent AMD addrlib comparison. I have not validated these layouts on PS5 hardware.

Tested

Linux, GCC 12.2 Release: built agc_driver_graphics_tests; ctest --test-dir build-check -R '^agc_driver_graphics$' --output-on-failure passed. Rebuilding and running the test with current main's ColorTargetLayout.cpp failed on the new 64 bpp assertion. python3 tools/check_conventions.py --base upstream/main and git diff --check passed. Windows and PS5 hardware not tested.

Checklist

  • Based on current main (0f863c102207dae4b77b1a2bad16c3aedec34691); no other open PR implements this coordinate correction
  • 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
  • New third-party code is a submodule built from source
  • Generic behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818696219 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3482). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T11:24:23Z. --- ### What Issue #3475 reports incorrect CPU offsets for SW_64KB_R_X color surfaces at 64 and 128 bits per element. On current `main`, `core/libs/prx/libSceAgcDriver/Graphics/src/ColorTargetLayout.cpp:152` computes the in-block address from only the precomputed low coordinate bits: ```cpp return block * Alignment() + (xOffsets[x % blockWidth] ^ yOffsets[y % blockHeight] ^ pipeBankXor); ``` The R_X equations also XOR higher x/y coordinate bits into the in-block address. The current expression drops those terms when a surface crosses the nominal block width or height. This change keeps the existing lookup tables for the low bits, then adds the high-coordinate equation contributions for R_X before applying the pipe/bank XOR. It adds fixed-address regressions for both reported cases: - 33x65, 64 bpp, (0, 64): offset `0x10800` (67584) - 129x67, 128 bpp, (64, 0): offset `0x10400` (66560) The issue report attributes these expected values to an independent AMD addrlib comparison. I have not validated these layouts on PS5 hardware. ### Tested Linux, GCC 12.2 Release: built `agc_driver_graphics_tests`; `ctest --test-dir build-check -R '^agc_driver_graphics$' --output-on-failure` passed. Rebuilding and running the test with current `main`'s `ColorTargetLayout.cpp` failed on the new 64 bpp assertion. `python3 tools/check_conventions.py --base upstream/main` and `git diff --check` passed. Windows and PS5 hardware not tested. ### Checklist - [x] Based on current `main` (`0f863c102207dae4b77b1a2bad16c3aedec34691`); no other open PR implements this coordinate correction - [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 - [x] New third-party code is a submodule built from source - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
adriadam10 commented 2026-10-11 11:41:16 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Thanks for the fix. One bug remains:

  • ColorTargetLayout.cpp:159: inBlock |= (parity(coordinates) << bit) must be ^=. inBlock already holds the low-coordinate contribution to that bit (from xOffsets/yOffsets), and the high-coordinate parity has to be XORed into it, not ORed. Evaluating the existing kTextureSwizzleEquations entry on full x/y as a reference, the PR disagrees on 12288 of 73728 coordinates in a 3x3-block 8-byte surface and 11264 on a 16-byte one. For example, 8 bytes at (32, 64): the PR returns 0x800, the full equation gives 0x0 (same at 16 bytes, (32, 64)).
  • tests/ColorTargetLayout.cpp:56-57: both new cases pass with |= because the low part of the affected bit is 0 there. Please add cases where the low and high contributions are both 1 (e.g. (32, 64) at 8 bytes and 16 bytes) with expected values from addrlib, or at least from the full-coordinate evaluation of the equation.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5483163319 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3482#pullrequestreview-5483163319). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T11:41:16Z. **Review:** CHANGES_REQUESTED --- Thanks for the fix. One bug remains: - `ColorTargetLayout.cpp:159`: `inBlock |= (parity(coordinates) << bit)` must be `^=`. `inBlock` already holds the low-coordinate contribution to that bit (from `xOffsets`/`yOffsets`), and the high-coordinate parity has to be XORed into it, not ORed. Evaluating the existing `kTextureSwizzleEquations` entry on full x/y as a reference, the PR disagrees on 12288 of 73728 coordinates in a 3x3-block 8-byte surface and 11264 on a 16-byte one. For example, 8 bytes at (32, 64): the PR returns `0x800`, the full equation gives `0x0` (same at 16 bytes, (32, 64)). - `tests/ColorTargetLayout.cpp:56-57`: both new cases pass with `|=` because the low part of the affected bit is 0 there. Please add cases where the low and high contributions are both 1 (e.g. (32, 64) at 8 bytes and 16 bytes) with expected values from addrlib, or at least from the full-coordinate evaluation of the equation.
MarcZX10 commented 2026-10-11 11:49:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T11:49:38Z.


Correction: my previous comment was mangled by shell interpolation. The code and tests are correct; the new (32, 64) regression cases assert full Offset() values, including their row-block bases: 0x10000 (8-byte elements) and 0x30000 (16-byte elements). The in-block equation result for both overlap cases is 0.

Commit 8a390b06d changes the high-coordinate combination to XOR and adds these cases. Rebuilt and ran agc_driver_graphics_tests, the convention checker, and git diff --check; all pass. The negative control with |= fails on the new assertion.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108709538 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3482#issuecomment-6108709538). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T11:49:38Z. --- Correction: my previous comment was mangled by shell interpolation. The code and tests are correct; the new `(32, 64)` regression cases assert full `Offset()` values, including their row-block bases: `0x10000` (8-byte elements) and `0x30000` (16-byte elements). The in-block equation result for both overlap cases is `0`. Commit `8a390b06d` changes the high-coordinate combination to XOR and adds these cases. Rebuilt and ran `agc_driver_graphics_tests`, the convention checker, and `git diff --check`; all pass. The negative control with `|=` fails on the new assertion.
adriadam10 commented 2026-10-11 12:01:59 +00:00 (Migrated from github.com)

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

Review: APPROVED


Checked the XOR fix against the full-coordinate evaluation of the existing {27,8}/{27,16} equations: the (0,64), (64,0) and overlapping (32,64) cases match the new assertions. agc_driver_graphics passes on the PR merged onto main and fails without the change. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5483220341 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3482#pullrequestreview-5483220341). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T12:01:59Z. **Review:** APPROVED --- Checked the XOR fix against the full-coordinate evaluation of the existing `{27,8}`/`{27,16}` equations: the (0,64), (64,0) and overlapping (32,64) cases match the new assertions. `agc_driver_graphics` passes on the PR merged onto main and fails without the change. Merging.
Amoenus commented 2026-10-11 12:06:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-11T12:06:14Z.


Independent source-reference verification of merged #3482 (2026-10-11)

Rebuilt the unchanged merged production ColorTargetLayout.cpp/.hpp and TextureSwizzleEquations.hpp from main2220effbe42c850d7f8df56dbac52e3cdea54009 (PR head8a390b06df02bf576a15d9c66d9b64949b7abdb1), using our existing independent AMD PAL AddrLib reference pinned atc5e800072a32f68b6ccc4422936d96167c6e0728. Rechecked all42 reference source files' SHA256/Git blobs before running. No substitute implementation or patch to the merged production code.

5/5 runs:140 configurations,536,940 byte-address checks per run, zero differences, including geometry. Five element sizes1/2/4/8/16bytes; seven extents1x1,5x3,33x65,129x67,257x129,1025x513,3840x2160; four legal16pipe XOR codes0/0x0f/0x40/0xcf. This covers both minimal8/16byte cross-block witnesses and overlapping coordinate contributions. The prior unchanged-main audit differed in95,156 of these536,940 checks; this merged version now matches the source reference throughout that same matrix.

Configuration is syntheticGFX10.1 non-RB+ family0x8f/revision0x82,GB_ADDR_CONFIG0x00100044,16pipes/256B; single mip/slice. This is CPU source-consistency validation, not PS5 hardware measurement, full repository-suite validation, native GPU interoperability or evidence that this particular title reaches the affected coordinates. Those broader claims are not made.

As a separation control, the independent1x1 arbitrary-XOR origin audit still has25/45differences, exactly as before: reserved column-bit handling remains a distinct unsettled input-contract question discussed on #1735. No XOR-mask change was needed to fix #3475. Pinned AMD source. Our game/integration remains pinned atforkd8fd7c7/main0f863 for the completed MSAA capture; it has not yet been rebased onto this merge. The upstream fix will be retained during that refresh rather than duplicated. AI-assisted verification/report: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108841648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3482#issuecomment-6108841648). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-11T12:06:14Z. --- ### Independent source-reference verification of merged #3482 (2026-10-11) Rebuilt the **unchanged merged production ColorTargetLayout.cpp/.hpp and TextureSwizzleEquations.hpp** from main2220effbe42c850d7f8df56dbac52e3cdea54009 (PR head8a390b06df02bf576a15d9c66d9b64949b7abdb1), using our existing independent AMD PAL AddrLib reference pinned atc5e800072a32f68b6ccc4422936d96167c6e0728. Rechecked all42 reference source files' SHA256/Git blobs before running. No substitute implementation or patch to the merged production code. **5/5 runs:140 configurations,536,940 byte-address checks per run, zero differences**, including geometry. Five element sizes1/2/4/8/16bytes; seven extents1x1,5x3,33x65,129x67,257x129,1025x513,3840x2160; four legal16pipe XOR codes0/0x0f/0x40/0xcf. This covers both minimal8/16byte cross-block witnesses and overlapping coordinate contributions. The prior unchanged-main audit differed in95,156 of these536,940 checks; this merged version now matches the source reference throughout that same matrix. Configuration is syntheticGFX10.1 non-RB+ family0x8f/revision0x82,GB_ADDR_CONFIG0x00100044,16pipes/256B; single mip/slice. This is **CPU source-consistency validation**, not PS5 hardware measurement, full repository-suite validation, native GPU interoperability or evidence that this particular title reaches the affected coordinates. Those broader claims are not made. As a separation control, the independent1x1 arbitrary-XOR origin audit still has25/45differences, exactly as before: reserved column-bit handling remains a distinct unsettled input-contract question discussed on #1735. No XOR-mask change was needed to fix #3475. [Pinned AMD source](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/imported/addrlib/src/gfx10/gfx10addrlib.cpp). Our game/integration remains pinned atforkd8fd7c7/main0f863 for the completed MSAA capture; it has not yet been rebased onto this merge. The upstream fix will be retained during that refresh rather than duplicated. AI-assisted verification/report: Codex.
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!3482
No description provided.