fix(agc): alpha-to-coverage from a 32_AR MRT0 export without a color target #5521

Merged
codingreapermaps merged 2 commits from upstream-pr/5521 into main 2026-10-14 09:37:55 +00:00
codingreapermaps commented 2026-10-13 22:17:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by codingreapermaps on 2026-10-13T22:17:02Z.


What

Undithered alpha-to-coverage (DB_ALPHA_TO_MASK = 0xaa01) was refused on draws without a color target on MRT0, and on 32_AR MRT0 exports. Those are the draws radeonsi produces for alpha-to-coverage without a color buffer: the color format of MRT0 becomes SPI_SHADER_32_AR so that the alpha still reaches the DB. PPSA12361 (Transport Fever 2: Console Edition) issues them when the camera zooms in on a map and stopped with alpha-to-coverage without a written MRT0 color target is unsupported.

  • DecodeState accepts alpha-to-coverage when no color target is written on MRT0, and accepts the 32_AR export format.
  • The MRT0 export format is read from SPI_SHADER_COL_FORMAT. The decoder masked the export formats to 0 for draws without a color target, so such a draw was refused as format 0 even with a 32_AR export.
  • A draw that enables alpha-to-coverage with no MRT0 export at all still throws, as does a component-swapped or packed MRT0 target. The debt entry for alpha-to-coverage records the radeonsi source.

Which channel of a 32_AR export carries the alpha is #5110's change, which this PR depends on: its first commit here is #5110 unchanged. Before #5110 the recompiler took the alpha from channel 3 and the coverage of these draws ignored it. Dithered alpha-to-coverage (#4451) is unrelated: this PR does not change which DB_ALPHA_TO_MASK values are accepted.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce MX450 (driver 581.83).

  • agc_driver_alpha_to_coverage_tests: new DepthOnlyCoverage draws a depth-only triangle with alpha-to-coverage and a 32_AR export over a cleared depth surface, then counts the pixels a depth test still passes. With export mask 0x3, alpha 0.75 writes the depth everywhere and alpha 0.25 writes none. With export mask 0xF, alpha 0.25 in channel 1 and 0.75 in channel 3, it writes none: the coverage follows channel 1 and channel 3 is ignored. All alpha-to-coverage tests pass.
  • agc_driver_graphics_tests: 32_AR is accepted with a color target; with CB_TARGET_MASK 0 and a 32_AR export the state decodes with alpha-to-coverage and no target and passes the precheck; formats 1 and 2, and no MRT0 export without a target, are refused. All graphics tests pass.
  • agc_driver_pixel32_ar_export_tests from #5110 passes on this branch.
  • PPSA12361: with the other local changes the title still needs, zooming in on a map no longer stops the title.
  • Built and tested on main at 30f961266 with #5110.

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: #5110
  • Unblocks: PPSA12361 (no Game bring-up discussion yet)
  • GPUs tested: NVIDIA GeForce MX450, driver 581.83, Windows 11
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4850189834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5521). Originally posted by [codingreapermaps](https://github.com/codingreapermaps) on 2026-10-13T22:17:02Z. --- ### What Undithered alpha-to-coverage (`DB_ALPHA_TO_MASK = 0xaa01`) was refused on draws without a color target on MRT0, and on `32_AR` MRT0 exports. Those are the draws [radeonsi produces for alpha-to-coverage without a color buffer](https://gitlab.freedesktop.org/mesa/mesa/-/blob/mesa-24.0.0/src/gallium/drivers/radeonsi/si_state_shaders.cpp#L2425-L2431): the color format of MRT0 becomes `SPI_SHADER_32_AR` so that the alpha still reaches the DB. PPSA12361 (Transport Fever 2: Console Edition) issues them when the camera zooms in on a map and stopped with `alpha-to-coverage without a written MRT0 color target is unsupported`. - `DecodeState` accepts alpha-to-coverage when no color target is written on MRT0, and accepts the `32_AR` export format. - The MRT0 export format is read from `SPI_SHADER_COL_FORMAT`. The decoder masked the export formats to 0 for draws without a color target, so such a draw was refused as `format 0` even with a `32_AR` export. - A draw that enables alpha-to-coverage with no MRT0 export at all still throws, as does a component-swapped or packed MRT0 target. The debt entry for alpha-to-coverage records the radeonsi source. Which channel of a `32_AR` export carries the alpha is #5110's change, which this PR depends on: its first commit here is #5110 unchanged. Before #5110 the recompiler took the alpha from channel 3 and the coverage of these draws ignored it. Dithered alpha-to-coverage (#4451) is unrelated: this PR does not change which `DB_ALPHA_TO_MASK` values are accepted. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce MX450 (driver 581.83). - `agc_driver_alpha_to_coverage_tests`: new `DepthOnlyCoverage` draws a depth-only triangle with alpha-to-coverage and a `32_AR` export over a cleared depth surface, then counts the pixels a depth test still passes. With export mask `0x3`, alpha 0.75 writes the depth everywhere and alpha 0.25 writes none. With export mask `0xF`, alpha 0.25 in channel 1 and 0.75 in channel 3, it writes none: the coverage follows channel 1 and channel 3 is ignored. All alpha-to-coverage tests pass. - `agc_driver_graphics_tests`: `32_AR` is accepted with a color target; with `CB_TARGET_MASK` 0 and a `32_AR` export the state decodes with alpha-to-coverage and no target and passes the precheck; formats 1 and 2, and no MRT0 export without a target, are refused. All graphics tests pass. - `agc_driver_pixel32_ar_export_tests` from #5110 passes on this branch. - PPSA12361: with the other local changes the title still needs, zooming in on a map no longer stops the title. - Built and tested on `main` at `30f961266` with #5110. ### 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: #5110 - [x] Unblocks: PPSA12361 (no Game bring-up discussion yet) - [x] GPUs tested: NVIDIA GeForce MX450, driver 581.83, Windows 11 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-13 22:24:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T22:24:50Z.

Review: COMMENTED


The mode == 3u branch remaps only source components 0 and 1 to raw R and A, but the revised exported mask now permits exp.en bits 2 and 3 too. For a valid 32_AR export with EXP_EN=0xF (or 0xC), those source components are never copied into raw; after the export mapping the corresponding channels become zero/default, and in particular an alpha supplied in source component 3 is lost because A is taken from component 1. The new depth-only fixture appears to use only EXP_EN=0x3, so it would not catch this. Could you add a focused mask 0xF regression and either preserve the enabled channels consistently with the 32_AR semantics or reject unsupported enable masks?

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5510780154 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5521#pullrequestreview-5510780154). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T22:24:50Z. **Review:** COMMENTED --- The `mode == 3u` branch remaps only source components 0 and 1 to raw R and A, but the revised `exported` mask now permits `exp.en` bits 2 and 3 too. For a valid 32_AR export with `EXP_EN=0xF` (or `0xC`), those source components are never copied into `raw`; after the export mapping the corresponding channels become zero/default, and in particular an alpha supplied in source component 3 is lost because A is taken from component 1. The new depth-only fixture appears to use only `EXP_EN=0x3`, so it would not catch this. Could you add a focused mask `0xF` regression and either preserve the enabled channels consistently with the 32_AR semantics or reject unsupported enable masks?
codingreapermaps commented 2026-10-13 22:59:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by codingreapermaps on 2026-10-13T22:59:04Z.


Thanks, you're right, and the overlap bot points at the same line: #5110 already fixes the 32_AR channel layout, with more sources, and its mask handling answers this. I've rebased onto main with #5110 as the first commit and dropped my own ExportVector change, so the mode == 3u branch here is #5110's: the enabled channels are masked to 0x3 and channel 1 goes to alpha, so with EXP_EN=0xF channels 2 and 3 are ignored, as GFX10 does (ac_nir_lower_ps_late.c).

I added the 0xF regression you asked for to DepthOnlyCoverage: alpha 0.25 in channel 1 and 0.75 in channel 3 with EXP_EN=0xF writes no depth, so the coverage follows channel 1. This PR is now only the decoder side (alpha-to-coverage without an MRT0 color target, 32_AR accepted, the MRT0 export format read from SPI_SHADER_COL_FORMAT), with Depends on: #5110.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156991085 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5521#issuecomment-6156991085). Originally posted by [codingreapermaps](https://github.com/codingreapermaps) on 2026-10-13T22:59:04Z. --- Thanks, you're right, and the overlap bot points at the same line: #5110 already fixes the `32_AR` channel layout, with more sources, and its mask handling answers this. I've rebased onto `main` with #5110 as the first commit and dropped my own `ExportVector` change, so the `mode == 3u` branch here is #5110's: the enabled channels are masked to `0x3` and channel 1 goes to alpha, so with `EXP_EN=0xF` channels 2 and 3 are ignored, as GFX10 does ([ac_nir_lower_ps_late.c](https://gitlab.freedesktop.org/mesa/mesa/-/blob/3e32b0e1f132231b7a972c1b0b5b06c7e16cf8b9/src/amd/common/nir/ac_nir_lower_ps_late.c#L400-L411)). I added the `0xF` regression you asked for to `DepthOnlyCoverage`: alpha 0.25 in channel 1 and 0.75 in channel 3 with `EXP_EN=0xF` writes no depth, so the coverage follows channel 1. This PR is now only the decoder side (alpha-to-coverage without an MRT0 color target, `32_AR` accepted, the MRT0 export format read from `SPI_SHADER_COL_FORMAT`), with **Depends on: #5110**.
MarcZX10 commented 2026-10-13 23:12:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T23:12:25Z.


Thanks, that addresses my specific concern. The new EXP_EN=0xF depth-only case checks that the alpha in channel 1 drives coverage while channel 3 is ignored for 32_AR, and the PR now records its dependency on #5110. The latest convention check passes; the full Linux/Windows jobs are path-skipped for this diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157167207 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5521#issuecomment-6157167207). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T23:12:25Z. --- Thanks, that addresses my specific concern. The new `EXP_EN=0xF` depth-only case checks that the alpha in channel 1 drives coverage while channel 3 is ignored for `32_AR`, and the PR now records its dependency on #5110. The latest convention check passes; the full Linux/Windows jobs are path-skipped for this diff.
xXPBSXx commented 2026-10-14 03:23:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T03:23:31Z.


Windows test of #5521: Windows 10 (19045), MinGW-w64 GCC 15.2, Release, ninja -j 4, ctest called directly; ctest ran without -V, so the logs of the passing runs do not show which GPU, if any, the tests used (not verified). Tree: main 54c2e14dc + merge of PR head 269d806f532c748e4dbfe5a608ae5c3267f71778 (local merge 30ce9121a, no conflict). Logs: rtx5521_*_N.log, rtx5521_result.txt.
3 ctest targets, 3 runs each, exit code 0 in 9 of 9 runs: agc_driver_alpha_to_coverage, agc_driver_graphics, agc_driver_pixel32_ar_export.
Not tested: that the new or changed tests fail without the change (no baseline run), other ctest targets, the AMD GPU unless named above, Linux, a title run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6160163419 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5521#issuecomment-6160163419). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-14T03:23:31Z. --- Windows test of #5521: Windows 10 (19045), MinGW-w64 GCC 15.2, Release, `ninja -j 4`, ctest called directly; ctest ran without `-V`, so the logs of the passing runs do not show which GPU, if any, the tests used (not verified). Tree: `main` `54c2e14dc` + merge of PR head `269d806f532c748e4dbfe5a608ae5c3267f71778` (local merge `30ce9121a`, no conflict). Logs: `rtx5521_*_N.log`, `rtx5521_result.txt`. 3 ctest targets, 3 runs each, exit code 0 in 9 of 9 runs: `agc_driver_alpha_to_coverage`, `agc_driver_graphics`, `agc_driver_pixel32_ar_export`. Not tested: that the new or changed tests fail without the change (no baseline run), other ctest targets, the AMD GPU unless named above, Linux, a title run. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-14 04:57:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T04:57:14Z.


Rebased on current main; only docs/dev/debt/libSceAgcDriver.md conflicted (kept both entries). #5110 is closed, so this PR now carries its commit itself.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161231023 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5521#issuecomment-6161231023). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T04:57:14Z. --- Rebased on current `main`; only `docs/dev/debt/libSceAgcDriver.md` conflicted (kept both entries). #5110 is closed, so this PR now carries its commit itself.
github-actions[bot] commented 2026-10-14 09:03:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T09:03:42Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4451 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp L989-992
docs/dev/debt/libSceAgcDriver.md L10
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6164798418 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5521#issuecomment-6164798418). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T09:03:42Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4451 | `core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp` [L989-992](https://github.com/boykopovar/AnyPS5/blob/bf8e69d581f6e10b725718b0941ad55b7fcc4fdb/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp#L989-L992)<br>`docs/dev/debt/libSceAgcDriver.md` [L10](https://github.com/boykopovar/AnyPS5/blob/bf8e69d581f6e10b725718b0941ad55b7fcc4fdb/docs/dev/debt/libSceAgcDriver.md#L10) | | |
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!5521
No description provided.