feat(agc): emulate undithered alpha-to-coverage #3228

Merged
GustavoGamarra95 merged 3 commits from upstream-pr/3228 into main 2026-10-11 07:22:24 +00:00
GustavoGamarra95 commented 2026-10-11 02:08:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-11T02:08:28Z.


What

God of War Sons of Sparta (PPSA28997) stopped a few minutes into play with alpha-to-coverage is unsupported (register 0x2dc = 0x0000aa01).

  • Decode. DB_ALPHA_TO_MASK = 0xaa01 is accepted: the enable bit with the four quad offsets at 2 and no OFFSET_ROUND, the undithered setting radeonsi programs. The following still throw:
    • any other offsets, or OFFSET_ROUND;
    • an MRT0 that is missing, swizzled, packed or exported without a floating-point alpha;
    • a pixel shader that exports a sample mask.
  • Shader. Draws are single-sampled, so the pixel stage gets an alphaToCoverage flag. Such a variant declares SampleMask and starts with every sample covered. At its MRT0 export it writes 0 when the alpha is below one half or NaN, and all ones otherwise. It runs with late fragment tests. The shader keeps running after the export, so later stores still happen, as they do with a zero coverage mask on the GPU.
  • Shader identity. The flag is part of the static shader identity (CacheKey) and of the request serialization, now version 16.
  • Vulkan's alphaToCoverageEnable is not used: the NVIDIA driver 615.78.08 dithers single-sample coverage. An alpha of 0.25 writes half the pixels of an RTX 3050 Laptop target.

Tested

  • The rule was measured on a Radeon 660M (gfx1035) with RADV and RADV_DEBUG=noatocdithering, which programs DB_ALPHA_TO_MASK = 0xaa01. I compared the GPU's own Vulkan alpha-to-coverage with this emulation for 16 alpha values: 0, -0, 0.25, the two floats below one half, one half, the two floats above it, 0.75, 1, 2, -1, both infinities and both NaNs. All 16 matched on the 660M, and the emulation gave the same result on the RTX 3050. The rows are pinned in tests/execution/AlphaToCoverage.cpp. They are not measured on gfx1013, as TechnicalDebt.md says.
  • Arch Linux, kernel 7.2.9, GCC 16.2.1, Release, on main d31b57a4: ctest 752/753 passed on the RTX 3050. The failure is agc_driver_dcc_keys_first_write, which fails on main on this GPU too. Each commit builds and passes the tests it touches (agc_shader_memory, agc_driver_graphics, agc_driver_dual_source_blend).
  • PPSA28997 now plays past that point, through several levels, with #1482 and #1431 applied for Linux.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4815942761 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3228). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-11T02:08:28Z. --- ### What God of War Sons of Sparta (PPSA28997) stopped a few minutes into play with `alpha-to-coverage is unsupported (register 0x2dc = 0x0000aa01)`. - **Decode.** `DB_ALPHA_TO_MASK = 0xaa01` is accepted: the enable bit with the four quad offsets at 2 and no `OFFSET_ROUND`, the undithered setting [radeonsi programs](https://gitlab.freedesktop.org/mesa/mesa/-/blob/bffd91947efc1932da99aca69fc540d6d4201b0c/src/gallium/drivers/radeonsi/si_state.c#L371-L381). The following still throw: - any other offsets, or `OFFSET_ROUND`; - an MRT0 that is missing, swizzled, packed or exported without a floating-point alpha; - a pixel shader that exports a sample mask. - **Shader.** Draws are single-sampled, so the pixel stage gets an `alphaToCoverage` flag. Such a variant declares `SampleMask` and starts with every sample covered. At its MRT0 export it writes 0 when the alpha is below one half or NaN, and all ones otherwise. It runs with late fragment tests. The shader keeps running after the export, so later stores still happen, as they do with a zero coverage mask on the GPU. - **Shader identity.** The flag is part of the static shader identity (`CacheKey`) and of the request serialization, now version 16. - Vulkan's `alphaToCoverageEnable` is not used: the NVIDIA driver 615.78.08 dithers single-sample coverage. An alpha of 0.25 writes half the pixels of an RTX 3050 Laptop target. ### Tested - The rule was measured on a Radeon 660M (gfx1035) with RADV and `RADV_DEBUG=noatocdithering`, which programs `DB_ALPHA_TO_MASK = 0xaa01`. I compared the GPU's own Vulkan alpha-to-coverage with this emulation for 16 alpha values: 0, -0, 0.25, the two floats below one half, one half, the two floats above it, 0.75, 1, 2, -1, both infinities and both NaNs. All 16 matched on the 660M, and the emulation gave the same result on the RTX 3050. The rows are pinned in `tests/execution/AlphaToCoverage.cpp`. They are not measured on gfx1013, as `TechnicalDebt.md` says. - Arch Linux, kernel 7.2.9, GCC 16.2.1, Release, on `main` d31b57a4: `ctest` 752/753 passed on the RTX 3050. The failure is `agc_driver_dcc_keys_first_write`, which fails on `main` on this GPU too. Each commit builds and passes the tests it touches (`agc_shader_memory`, `agc_driver_graphics`, `agc_driver_dual_source_blend`). - PPSA28997 now plays past that point, through several levels, with #1482 and #1431 applied for Linux. ### 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 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-11 02:08:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T02:08:43Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104482135 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3228#issuecomment-6104482135). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T02:08:43Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
github-actions[bot] commented 2026-10-11 05:30:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T05:30:23Z.


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
#2169 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp L600-602, L989-991
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105847517 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3228#issuecomment-6105847517). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T05:30:23Z. --- <!-- 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 | |---|---|---|---| | #2169 | `core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp` [L600-602](https://github.com/boykopovar/AnyPS5/blob/47c8e19eb7b7edf389428e9e385cd2a8444bb36b/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp#L600-L602), [L989-991](https://github.com/boykopovar/AnyPS5/blob/47c8e19eb7b7edf389428e9e385cd2a8444bb36b/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp#L989-L991) | | |
reyani-dev commented 2026-10-11 06:28:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T06:28:41Z.


Windows run, since the PR has only Linux results. Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release, NVIDIA RTX 4070 Laptop GPU (driver 616.92), head 50e84c7c merged onto current main, with VK_LOADER_DRIVERS_DISABLE=*dzn* (this machine's Dozen ICD crashes on its own, #3255).

  • It builds cleanly. The only two warnings are nodiscard ones in AttributeInstructions.cpp and tests/Graphics.cpp that main already has; the header changes just cause those files to recompile.
  • agc_driver_alpha_to_coverage (the pinned 16-value rows), agc_shader_memory, agc_driver_graphics and agc_driver_dual_source_blend pass.
  • ctest -R "^agc_|video_out|^shader|recompiler": 358/358 pass. agc_driver_dcc_keys_first_write, which fails on your RTX 3050, passes on this GPU both with and without the change.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106248281 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3228#issuecomment-6106248281). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T06:28:41Z. --- Windows run, since the PR has only Linux results. Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release, NVIDIA RTX 4070 Laptop GPU (driver 616.92), head `50e84c7c` merged onto current `main`, with `VK_LOADER_DRIVERS_DISABLE=*dzn*` (this machine's Dozen ICD crashes on its own, #3255). - It builds cleanly. The only two warnings are `nodiscard` ones in `AttributeInstructions.cpp` and `tests/Graphics.cpp` that `main` already has; the header changes just cause those files to recompile. - `agc_driver_alpha_to_coverage` (the pinned 16-value rows), `agc_shader_memory`, `agc_driver_graphics` and `agc_driver_dual_source_blend` pass. - `ctest -R "^agc_|video_out|^shader|recompiler"`: 358/358 pass. `agc_driver_dcc_keys_first_write`, which fails on your RTX 3050, passes on this GPU both with and without the change.
adriadam10 commented 2026-10-11 07:22:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:22:19Z.


Checked on current main: scoped build and ctest (agc_driver_graphics, agc_shader_memory, agc_driver_prepared_graphics, agc_driver_alpha_to_coverage) pass. I also swapped the emulation for Vulkan's alphaToCoverageEnable on RADV (Radeon 660M, RADV_DEBUG=noatocdithering) and the new test passes all rows, so the 0.5/NaN rule matches the hardware path; with dithering on it differs, as the description says.

Notes, not blocking:

  • #2977 also bumps the request serialization to version 16 with a different layout. Whichever lands second has to move to 17.
  • MRT0 export formats 5 and 6 (UNORM16/SNORM16) are accepted but not covered by the test.

Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106633069 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3228#issuecomment-6106633069). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:22:19Z. --- Checked on current main: scoped build and ctest (`agc_driver_graphics`, `agc_shader_memory`, `agc_driver_prepared_graphics`, `agc_driver_alpha_to_coverage`) pass. I also swapped the emulation for Vulkan's `alphaToCoverageEnable` on RADV (Radeon 660M, `RADV_DEBUG=noatocdithering`) and the new test passes all rows, so the 0.5/NaN rule matches the hardware path; with dithering on it differs, as the description says. Notes, not blocking: - #2977 also bumps the request serialization to version 16 with a different layout. Whichever lands second has to move to 17. - MRT0 export formats 5 and 6 (UNORM16/SNORM16) are accepted but not covered by the test. Merging.
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!3228
No description provided.