AGC: CPU SW_64KB_R_X color layout drops cross-block XOR coordinate bits at 64/128 bpp #3475

Closed
opened 2026-10-11 11:12:03 +00:00 by Amoenus · 1 comment
Amoenus commented 2026-10-11 11:12:03 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-11T11:12:03Z.


Summary

ColorTargetLayout evaluates XOR equations using coordinates modulo the block dimensions. For SW_64KB_R_X at64/128bpp, the existing equations also use higher coordinate bits in their in-block pipe XOR. Dropping those bits makes CPU color offsets disagree with compiled AMD addrlib and with full-coordinate evaluation of AnyPS5's own existing equations, even when pipeBankXor=0. CPU color Tile/Detile and transfers share this offset routine, so a roundtrip with the same routine can pass without validating memory placement.

This is a source-model consistency defect; PS5 hardware/render equivalence and a title hitting these particular cases have not been measured. It was discovered while strengthening the independent validation for #2970 using our PPSA99902 dump as a broader compatibility target; that title's confirmed missing mode is D_X, not evidence that it executes these R_X cases. The separate arbitrary column-bit XOR discrepancy is reported on PR1735.

Revision / environment

  • Unmodified main 74981fabe1 production ColorTargetLayout.cpp/header, Git blobs b4deb5dda8 /8c492a1a02. These files and TextureSwizzleEquations.hpp are unchanged through fetched main0f863c102207dae4b77b1a2bad16c3aedec34691.
  • Windows11, Winlibs MinGW-w64 GCC15.2.0r7; standalone CPU executable links production ColorTargetLayout.cpp and independently compiled, unmodified AMD PAL addrlib c5e800072a32f68b6ccc4422936d96167c6e0728. No AnyPS5 GPU equation used as the AMD oracle.
  • Synthetic GFX10.1 non-RB+ family0x8f/revision0x82, GB_ADDR_CONFIG0x00100044,16pipes/256-byte interleave. This is a source configuration, not console-register measurement. Surface API:2D,color/texture,noMetadata,1slice/1mip/1sample/1fragment.

Minimal reproduction / expected offsets

Using AgcDriver::Graphics and the unchanged production source:

const ColorTargetLayout a(33, 65, ColorTileMode::RenderTarget, 8, 0);
const ColorTargetLayout b(129, 67, ColorTileMode::RenderTarget, 16, 0);
const auto first = a.Offset(0, 64);
const auto second = b.Offset(64, 0);
Surface / coordinate Current AnyPS5 AMD-source expected
33x65,64bpp,(0,64),zero XOR 65536 (0x10000) 67584 (0x10800)
129x67,128bpp,(64,0),zero XOR 65536 (0x10000) 66560 (0x10400)

The independent API calls are Addr2ComputeSurfaceInfo followed by Addr2ComputeSurfaceAddrFromCoord, SW_64KB_R_X, the geometry above, bpp=64/128, pipeBankXor=0. Supply unalignedWidth/Height, numSlices/numMipLevels/numSamples/numFrags=1 and x/y as shown; compare output.addr and bitPosition=0.

Cause and controlled correction

ColorTargetLayout::offset on the pinned revision uses xOffsets[x%blockWidth] and yOffsets[y%blockHeight]. Existing R_X equations at8-byte elements include y-bit6 in address-bit11 while blockHeight=64; at16-byte elements they also include x-bit6 in address-bit10 while blockWidth=64. AMD HwlComputeSurfaceAddrFromCoordTiled evaluates its equation on full x/y, then adds the block index.

Controlled external correction: retained the exact main header, equations, geometry, allocation and XOR handling; changed only the R_X offset path to evaluate the existing equation with full x/y. This is a proposed correction, not a committed/runtime-tested implementation. The equivalent calculation is:

std::uint32_t inBlock = 0;
for (std::uint32_t bit = 0; bit < 16u; ++bit) {
    const auto coordinates = (x & equation->bits[bit] & 0xfffu)
        ^ ((y << 12u) & equation->bits[bit] & 0xfff000u);
    inBlock |= (std::popcount(coordinates) & 1u) << bit;
}
return block * Alignment() + (inBlock ^ pipeBankXor);

An implementation can preserve the cached fast path and add the higher-coordinate XOR contributions instead. It should keep legal-value semantics separate from the reserved raw-bit question on PR1735.

**Independent before/after:**5element sizes (1/2/4/8/16bytes),7extents (1x1,5x3,33x65,129x67,257x129,1025x513,3840x2160),4legal codes (0,0x0f,0x40,0xcf), boundary/dense-small/sampled-large coordinates: 140 configurations,536,940 address comparisons per run.

  • Unmodified main: 95,156 mismatches, identical5/5 runs; all differing configurations are8/16-byte R_X elements spanning blocks. The same origin/within-block cases do not expose this defect.
  • Only full-coordinate correction: zero mismatches,5/5 runs, same source/configuration/inputs. No column-bit masking change involved.
  • No array/mip-tail, console, GPU draw or game-runtime validation of this correction yet. No claim that it fixes our title or is ready for upstream merge.

Follow-up / duplicate check

Add independently expected64/128bpp offsets across block boundaries (including zero XOR), implement the missing coordinate contribution generally, then exercise color transfers and GPU/CPU interoperability. Main's existing same-layout roundtrips alone are insufficient. All experiments are local/fork-only; no PR created.

Checked existing issues for ColorTargetLayout/SW_64KB_R_X/color block/color coordinate and open PRs mentioning ColorTargetLayout; reviewed related #1734/#1735/#2970. No matching tracked cross-block CPU coordinate defect found. This issue separates it from #2970's missing D64 mode and PR1735's reserved-XOR input question. AI-assisted investigation/validation/report: Codex.

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:issue:5800523315 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3475). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-11T11:12:03Z. --- ### Summary ColorTargetLayout evaluates XOR equations using coordinates modulo the block dimensions. For SW_64KB_R_X at64/128bpp, the existing equations also use higher coordinate bits in their in-block pipe XOR. Dropping those bits makes CPU color offsets disagree with compiled AMD addrlib and with full-coordinate evaluation of **AnyPS5's own existing equations**, even when pipeBankXor=0. CPU color Tile/Detile and transfers share this offset routine, so a roundtrip with the same routine can pass without validating memory placement. This is a source-model consistency defect; **PS5 hardware/render equivalence and a title hitting these particular cases have not been measured**. It was discovered while strengthening the independent validation for #2970 using our PPSA99902 dump as a broader compatibility target; that title's confirmed missing mode is D_X, not evidence that it executes these R_X cases. The separate arbitrary column-bit XOR discrepancy is reported on [PR1735](https://github.com/boykopovar/AnyPS5/pull/1735#issuecomment-6108358021). ### Revision / environment - Unmodified main **74981fabe1c0fc56b561914beb027ddc9b07d358** production ColorTargetLayout.cpp/header, Git blobs b4deb5dda8d41c567a98aacbb7769061433937b7 /8c492a1a0269ac5aec03a9d41a4d9b30dfb38b9c. These files and TextureSwizzleEquations.hpp are unchanged through fetched main0f863c102207dae4b77b1a2bad16c3aedec34691. - Windows11, Winlibs MinGW-w64 GCC15.2.0r7; standalone CPU executable links production ColorTargetLayout.cpp and independently compiled, unmodified AMD PAL addrlib **c5e800072a32f68b6ccc4422936d96167c6e0728**. No AnyPS5 GPU equation used as the AMD oracle. - Synthetic GFX10.1 non-RB+ family0x8f/revision0x82, GB_ADDR_CONFIG0x00100044,16pipes/256-byte interleave. This is a source configuration, not console-register measurement. Surface API:2D,color/texture,noMetadata,1slice/1mip/1sample/1fragment. ### Minimal reproduction / expected offsets Using AgcDriver::Graphics and the unchanged production source: ```cpp const ColorTargetLayout a(33, 65, ColorTileMode::RenderTarget, 8, 0); const ColorTargetLayout b(129, 67, ColorTileMode::RenderTarget, 16, 0); const auto first = a.Offset(0, 64); const auto second = b.Offset(64, 0); ``` | Surface / coordinate | Current AnyPS5 | AMD-source expected | |---|---:|---:| |33x65,64bpp,(0,64),zero XOR|65536 (0x10000)|67584 (0x10800)| |129x67,128bpp,(64,0),zero XOR|65536 (0x10000)|66560 (0x10400)| The independent API calls are Addr2ComputeSurfaceInfo followed by Addr2ComputeSurfaceAddrFromCoord, SW_64KB_R_X, the geometry above, bpp=64/128, pipeBankXor=0. Supply unalignedWidth/Height, numSlices/numMipLevels/numSamples/numFrags=1 and x/y as shown; compare output.addr and bitPosition=0. ### Cause and controlled correction [ColorTargetLayout::offset on the pinned revision](https://github.com/boykopovar/AnyPS5/blob/74981fabe1c0fc56b561914beb027ddc9b07d358/core/libs/prx/libSceAgcDriver/Graphics/src/ColorTargetLayout.cpp) uses xOffsets[x%blockWidth] and yOffsets[y%blockHeight]. [Existing R_X equations](https://github.com/boykopovar/AnyPS5/blob/74981fabe1c0fc56b561914beb027ddc9b07d358/core/libs/prx/libSceAgcDriver/Graphics/include/TextureSwizzleEquations.hpp) at8-byte elements include y-bit6 in address-bit11 while blockHeight=64; at16-byte elements they also include x-bit6 in address-bit10 while blockWidth=64. AMD [HwlComputeSurfaceAddrFromCoordTiled](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/imported/addrlib/src/gfx10/gfx10addrlib.cpp) evaluates its equation on full x/y, then adds the block index. **Controlled external correction:** retained the exact main header, equations, geometry, allocation and XOR handling; changed only the R_X offset path to evaluate the existing equation with full x/y. This is a proposed correction, **not a committed/runtime-tested implementation**. The equivalent calculation is: ```cpp std::uint32_t inBlock = 0; for (std::uint32_t bit = 0; bit < 16u; ++bit) { const auto coordinates = (x & equation->bits[bit] & 0xfffu) ^ ((y << 12u) & equation->bits[bit] & 0xfff000u); inBlock |= (std::popcount(coordinates) & 1u) << bit; } return block * Alignment() + (inBlock ^ pipeBankXor); ``` An implementation can preserve the cached fast path and add the higher-coordinate XOR contributions instead. It should keep legal-value semantics separate from the reserved raw-bit question on PR1735. **Independent before/after:**5element sizes (1/2/4/8/16bytes),7extents (1x1,5x3,33x65,129x67,257x129,1025x513,3840x2160),4legal codes (0,0x0f,0x40,0xcf), boundary/dense-small/sampled-large coordinates: **140 configurations,536,940 address comparisons per run**. - Unmodified main: **95,156 mismatches, identical5/5 runs**; all differing configurations are8/16-byte R_X elements spanning blocks. The same origin/within-block cases do not expose this defect. - Only full-coordinate correction: **zero mismatches,5/5 runs**, same source/configuration/inputs. No column-bit masking change involved. - No array/mip-tail, console, GPU draw or game-runtime validation of this correction yet. No claim that it fixes our title or is ready for upstream merge. ### Follow-up / duplicate check Add independently expected64/128bpp offsets across block boundaries (including zero XOR), implement the missing coordinate contribution generally, then exercise color transfers and GPU/CPU interoperability. Main's existing same-layout roundtrips alone are insufficient. All experiments are local/fork-only; **no PR created**. Checked existing issues for ColorTargetLayout/SW_64KB_R_X/color block/color coordinate and open PRs mentioning ColorTargetLayout; reviewed related #1734/#1735/#2970. No matching tracked cross-block CPU coordinate defect found. This issue separates it from #2970's missing D64 mode and PR1735's reserved-XOR input question. AI-assisted investigation/validation/report: Codex. ### 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.
adriadam10 commented 2026-10-11 12:02:05 +00:00 (Migrated from github.com)
Author
Contributor

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


Fixed by #3482: R_X color offsets now include the high x/y coordinate contributions, covered by agc_driver_graphics.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108807643 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3475#issuecomment-6108807643). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T12:02:05Z. --- Fixed by #3482: R_X color offsets now include the high x/y coordinate contributions, covered by `agc_driver_graphics`.
Sign in to join this conversation.
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#3475
No description provided.