Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
gjonn:fix/agc-reversed-rgba8-color-targets
Oct 8, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
gjonn:fix/agc-reversed-rgba8-color-targets

Conversation

@gjonn

@gjonn gjonn commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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. fix(agc): support alternate channel order in 16-bit color targets #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 fix(agc): support alternate channel order in 16-bit color targets #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

COMP_SWAP 2 and 3 store a four-component export as ABGR and ARGB from the
lowest bits. Render such targets as RGBA8 and permute the pixel shader's
exports through the existing component mapping (0x1b and 0x93), as the
one-component swaps already do. Blending into them throws: the alpha
factors would read the wrong export component.
…ders

Accept COMP_SWAP STD_REV and ALT_REV on 16_16_16_16 color targets and
map them onto RGBA16 with the same export component mappings used for
8_8_8_8. ALT on 16_16_16_16 is still refused.
@gjonn gjonn changed the title fix(agc): render 8_8_8_8 color targets with reversed component orders fix(agc): render 8_8_8_8 and 16_16_16_16 color targets with reversed component orders Oct 8, 2026
@github-actions github-actions Bot added the agc libSceAgc* label Oct 8, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 merged commit fd5342b into boykopovar:main Oct 8, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants