fix(agc): render 8_8_8_8 and 16_16_16_16 color targets with reversed component orders #1425

Merged
gjonn merged 2 commits from upstream-pr/1425 into main 2026-10-08 13:18:27 +00:00
gjonn commented 2026-10-08 04:24:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-08T04:24:16Z.


What

A color target of format 8_8_8_8 with CB_COLOR_INFO.COMP_SWAP 2 or 3 was refused ("unsupported color format 10 number type 0 component swap 2"). For four components these swaps are the reversed orders: SWAP_STD_REV stores the export as A, B, G, R from the lowest bits, and SWAP_ALT_REV as A, R, G, B. A title renders thousands of draws per minute into such targets. The same orders on 16_16_16_16 targets (format 12) were refused too.

  • DecodeColorFormat returns RGBA8 (unorm, snorm or sRGB) for those targets, with component mapping 0x1b (STD_REV) or 0x93 (ALT_REV). The pixel shader's exports are permuted through the same mapping the one-component swaps already use: memory component c takes export component (mapping >> 2c) & 3. #1349 uses the same encoding for the alternate order of 16-bit targets (0xc6).
  • 16_16_16_16 targets with COMP_SWAP 2 or 3 (unorm, snorm, float or uint) decode to RGBA16 with the same mappings, 0x1b and 0x93. SWAP_ALT on 16_16_16_16 stays refused here; that order is #1349's.
  • Blending into a reversed target throws ("blending into a color target with a reversed component order is not implemented"). After the permutation, Vulkan would blend the shader's alpha with the color equation and read alpha factors from the wrong component. Write masks follow the mapping.
  • SWAP_STD and SWAP_ALT are unchanged.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0: agc_driver_graphics passes with a new case. An 8_8_8_8 unorm target with COMP_SWAP 2 and 3 decodes to RGBA8 with mapping 0x1b and 0x93, ExportMappings carries the mapping, all four channels are written, and enabling blending on it is refused.
  • The same case checks that a 16_16_16_16 float target with COMP_SWAP 2 and 3 decodes to RGBA16 float with mapping 0x1b and 0x93 and writes all four channels, and that COMP_SWAP 1 on 16_16_16_16 is still refused.
  • In a title that renders into such targets, the draws no longer skip: about 6 900 skipped draws in 120 s went to 0, and no blended reversed target appeared.
  • In a title that renders into reversed 16_16_16_16 float targets, about 355 skipped draws per 60 s went to 0.

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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4781749612 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1425). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-08T04:24:16Z. --- ### What A color target of format 8_8_8_8 with `CB_COLOR_INFO.COMP_SWAP` 2 or 3 was refused ("unsupported color format 10 number type 0 component swap 2"). For four components these swaps are the reversed orders: SWAP_STD_REV stores the export as A, B, G, R from the lowest bits, and SWAP_ALT_REV as A, R, G, B. A title renders thousands of draws per minute into such targets. The same orders on 16_16_16_16 targets (format 12) were refused too. - `DecodeColorFormat` returns RGBA8 (unorm, snorm or sRGB) for those targets, with component mapping 0x1b (STD_REV) or 0x93 (ALT_REV). The pixel shader's exports are permuted through the same mapping the one-component swaps already use: memory component `c` takes export component `(mapping >> 2c) & 3`. #1349 uses the same encoding for the alternate order of 16-bit targets (0xc6). - 16_16_16_16 targets with COMP_SWAP 2 or 3 (unorm, snorm, float or uint) decode to RGBA16 with the same mappings, 0x1b and 0x93. SWAP_ALT on 16_16_16_16 stays refused here; that order is #1349's. - Blending into a reversed target throws ("blending into a color target with a reversed component order is not implemented"). After the permutation, Vulkan would blend the shader's alpha with the color equation and read alpha factors from the wrong component. Write masks follow the mapping. - SWAP_STD and SWAP_ALT are unchanged. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0: `agc_driver_graphics` passes with a new case. An 8_8_8_8 unorm target with COMP_SWAP 2 and 3 decodes to RGBA8 with mapping 0x1b and 0x93, `ExportMappings` carries the mapping, all four channels are written, and enabling blending on it is refused. - The same case checks that a 16_16_16_16 float target with COMP_SWAP 2 and 3 decodes to RGBA16 float with mapping 0x1b and 0x93 and writes all four channels, and that COMP_SWAP 1 on 16_16_16_16 is still refused. - In a title that renders into such targets, the draws no longer skip: about 6 900 skipped draws in 120 s went to 0, and no blended reversed target appeared. - In a title that renders into reversed 16_16_16_16 float targets, about 355 skipped draws per 60 s went to 0. ### 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 - [x] AI-assisted: yes
adriadam10 commented 2026-10-08 13:18:23 +00:00 (Migrated from github.com)

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


Checked on Linux: build + ctest 457/457, and agc_driver_graphics fails without the State.cpp change. The mappings (0x1b = A,B,G,R and 0x93 = A,R,G,B from the lowest bits) match ac_translate_colorswap in Mesa. Blending into a reversed target throws and SWAP_ALT on 16_16_16_16 stays refused, so nothing wrong is silently accepted. CI is green; merging.

Heads-up: #1349 and #1073 touch the same lines of DecodeColorFormat and will need a rebase after this lands. Could you add the title ID of the game that hits these targets? Nobody has been able to reproduce that part here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6060750406 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1425#issuecomment-6060750406). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T13:18:23Z. --- Checked on Linux: build + ctest 457/457, and `agc_driver_graphics` fails without the `State.cpp` change. The mappings (0x1b = A,B,G,R and 0x93 = A,R,G,B from the lowest bits) match `ac_translate_colorswap` in Mesa. Blending into a reversed target throws and SWAP_ALT on 16_16_16_16 stays refused, so nothing wrong is silently accepted. CI is green; merging. Heads-up: #1349 and #1073 touch the same lines of `DecodeColorFormat` and will need a rebase after this lands. Could you add the title ID of the game that hits these targets? Nobody has been able to reproduce that part here.
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!1425
No description provided.