fix(shader): take the 32_AR export alpha from channel 1 as GFX10 does #5110

Closed
nikowolf123 wants to merge 1 commit from upstream-pr/5110 into main
nikowolf123 commented 2026-10-13 11:56:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-13T11:56:15Z.


What

A pixel export to an MRT whose SPI_SHADER_COL_FORMAT is 32_AR (3) took its alpha from export channel 3 (EN mask 0x9). That is the layout before GFX10, and 8e6614500 added it without a source. On GFX10 the alpha is export channel 1, and the PS5's gfx1013 is GFX10. Every AMD compiler for GFX10 puts it there:

The RDNA 2 ISA guide documents the EXP EN mask but not how the SPI packs each color format, so it does not settle this case.

Because of this, a console shader's exp mrt0 v0, v1, off, off lost its alpha, which stayed at the 1.0 default. Mesa picks 32_AR for two kinds of COLOR_32 target (ac_shader_util.c#L744-L752):

  • an alpha-only COMP_SWAP ALT_REV target, which stored 1.0;
  • a COMP_SWAP STD target whose blend reads the source alpha, which blended as if the alpha were 1.

When channel 3 was also enabled, its value was used as the alpha.

  • SpirvModuleEmitter.cpp, ExportVector: a 32_AR export now reads channels 0 and 1, and channel 1 becomes the alpha component. Channels 2 and 3 are ignored, just as 32_R and 32_GR already ignore the channels they don't carry. Green and blue stay 0, and an export without channel 1 keeps the 1.0 alpha default, as the other formats do.
  • docs/dev/debt/shader.md: records the layout and those defaults as not measured on hardware.
  • tests/execution/Pixel32ArExport.cpp (agc_driver_pixel32_ar_export): draws 32_AR exports with EN 0x3, 0xb and 0xf, as wave32 and wave64. The registers are decoded by DecodeColorBuffer and DecodePixelStageInfo. There are two linear targets: COLOR_32 FLOAT ALT_REV (R32_SFLOAT, mapping 0xe7), and COLOR_32 FLOAT blended with SRC_ALPHA / ONE_MINUS_SRC_ALPHA over 0.75. Every stored value is compared bit for bit: exporting (0.5, 0.25) stores 0.25 in the first target and blends to 0.6875 in the second. On main, every row fails. The ALT_REV target stores 1.0 for EN 0x3 and channel 3 (0.0625) for EN 0xb and 0xf. The blended target stores 0.5 instead of 0.6875 for EN 0x3, and blends with the channel 3 alpha for EN 0xb and 0xf.

Tested

Ubuntu 26.04 under WSL2, GCC 15.2.0, configured like CI (Release, Ninja, -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON, ccache), lavapipe from Mesa 26.0.8 with VK_ICD_FILENAMES=<lvp_icd json> ANYPS5_REQUIRE_VULKAN=1 GALLIUM_OVERRIDE_CPU_CAPS=avx, on main c8eb1f52d:

  • ctest -R '^agc_driver_pixel32_ar_export$' fails on main with the emitter unchanged: wave32 the 32_AR export with EN 0x3 of (0.5, 0.25, 2, 0.0625) into the COLOR_32 FLOAT ALT_REV (alpha only) target stored 0x3f800000 at pixel (0, 0), expected 0x3e800000. With the comparison changed locally to report every mismatching row instead of stopping at the first, all 16 rows (4 exports, 2 targets, wave32 and wave64) fail on main. With the fix the unchanged test passes in under 0.5 s, also with --repeat until-fail:3.
  • ctest -R 'agc_shader|agc_driver|shader' -j6: on main with only the new test added, 381 of 382 pass and the new test fails. With the fix, 382 of 382 pass.
  • Full ctest -j6 --timeout 120 on the commit: 1044 of 1044 pass. The skips are the existing lavapipe subgroup skips.
  • tools/check_test_registration.py and main's tools/check_conventions.py pass, including --title/--body.
  • Rebased onto main 84e2a8c0b (no conflicts): the new test passes 3 of 3 runs, and ctest -R 'agc_shader|agc_driver|shader' passes 382 of 382.

Native Windows 11, WinLibs GCC 15.2.0, NVIDIA GeForce RTX 5080 (driver 616.92), on the same commit: the new test passes 3 of 3 runs, and ctest -R 'agc_shader|agc_driver|shader|recompiler' passes 381 of 381.

Not measured on AMD hardware, neither gfx1013 nor any PC RDNA 2 GPU. The sources above are compilers, not measurements. tools/hw-oracle runs compute kernels only and cannot reach the SPI color export path (HW_ORACLE.md). A reviewer with a gfx103x GPU could confirm it with a RADV draw into an R32_SFLOAT target blended with SRC_ALPHA, or into an alpha-only target. RADV_DEBUG=shaders should show an exp mrt0 with the alpha in the second channel and the last two channels off, and the image should follow that alpha.

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: none
  • Unblocks: none
  • GPUs tested: lavapipe (Mesa 26.0.8, llvmpipe) on WSL2 Ubuntu 26.04; NVIDIA GeForce RTX 5080, driver 616.92, Windows 11
  • AI-assisted: yes. Written with Claude Code; I reviewed every line and ran the tests above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4842833232 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5110). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-13T11:56:15Z. --- ### What A pixel export to an MRT whose `SPI_SHADER_COL_FORMAT` is 32_AR (3) took its alpha from export channel 3 (EN mask `0x9`). That is the layout before GFX10, and 8e6614500 added it without a source. On GFX10 the alpha is export channel 1, and the PS5's gfx1013 is GFX10. Every AMD compiler for GFX10 puts it there: - Mesa, `emit_ps_color_export` in [ac_nir_lower_ps_late.c#L400-L411](https://gitlab.freedesktop.org/mesa/mesa/-/blob/3e32b0e1f132231b7a972c1b0b5b06c7e16cf8b9/src/amd/common/nir/ac_nir_lower_ps_late.c#L400-L411): `unsigned index = s->options->gfx_level >= GFX10 ? 1 : 3;`. The MRTZ path ([L246-L252](https://gitlab.freedesktop.org/mesa/mesa/-/blob/3e32b0e1f132231b7a972c1b0b5b06c7e16cf8b9/src/amd/common/nir/ac_nir_lower_ps_late.c#L246-L252)) follows the same rule, and that file is already the project's source for the MRTZ layout. - Mesa 22.0 ACO, [aco_instruction_selection.cpp#L11087-L11096](https://gitlab.freedesktop.org/mesa/mesa/-/blob/a82920af6efa4a7a66919885c6477fbd8fdc7b9d/src/amd/compiler/aco_instruction_selection.cpp#L11087-L11096): on GFX10 `enabled_channels = 0x3; values[1] = values[3];`, and `0x9` before GFX10. - Mesa 22.0 radeonsi, [si_shader_llvm_ps.c#L323-L333](https://gitlab.freedesktop.org/mesa/mesa/-/blob/a82920af6efa4a7a66919885c6477fbd8fdc7b9d/src/gallium/drivers/radeonsi/si_shader_llvm_ps.c#L323-L333): the same rule. - AMD LLPC, [FragmentColorExport.cpp#L157-L168](https://github.com/GPUOpen-Drivers/llpc/blob/40cb8d95ad8d6f7f1652e3fd47d39667594cce08/lgc/lowering/FragmentColorExport.cpp#L157-L168): `EXP_FORMAT_32_AR` puts the alpha in `exports[1]` with mask `0x2`. The RDNA 2 ISA guide documents the EXP EN mask but not how the SPI packs each color format, so it does not settle this case. Because of this, a console shader's `exp mrt0 v0, v1, off, off` lost its alpha, which stayed at the 1.0 default. Mesa picks 32_AR for two kinds of COLOR_32 target ([ac_shader_util.c#L744-L752](https://gitlab.freedesktop.org/mesa/mesa/-/blob/3e32b0e1f132231b7a972c1b0b5b06c7e16cf8b9/src/amd/common/ac_shader_util.c#L744-L752)): - an alpha-only COMP_SWAP ALT_REV target, which stored 1.0; - a COMP_SWAP STD target whose blend reads the source alpha, which blended as if the alpha were 1. When channel 3 was also enabled, its value was used as the alpha. - `SpirvModuleEmitter.cpp`, `ExportVector`: a 32_AR export now reads channels 0 and 1, and channel 1 becomes the alpha component. Channels 2 and 3 are ignored, just as 32_R and 32_GR already ignore the channels they don't carry. Green and blue stay 0, and an export without channel 1 keeps the 1.0 alpha default, as the other formats do. - `docs/dev/debt/shader.md`: records the layout and those defaults as not measured on hardware. - `tests/execution/Pixel32ArExport.cpp` (`agc_driver_pixel32_ar_export`): draws 32_AR exports with EN `0x3`, `0xb` and `0xf`, as wave32 and wave64. The registers are decoded by `DecodeColorBuffer` and `DecodePixelStageInfo`. There are two linear targets: COLOR_32 FLOAT ALT_REV (R32_SFLOAT, mapping `0xe7`), and COLOR_32 FLOAT blended with SRC_ALPHA / ONE_MINUS_SRC_ALPHA over 0.75. Every stored value is compared bit for bit: exporting (0.5, 0.25) stores 0.25 in the first target and blends to 0.6875 in the second. On `main`, every row fails. The ALT_REV target stores 1.0 for EN `0x3` and channel 3 (0.0625) for EN `0xb` and `0xf`. The blended target stores 0.5 instead of 0.6875 for EN `0x3`, and blends with the channel 3 alpha for EN `0xb` and `0xf`. ### Tested Ubuntu 26.04 under WSL2, GCC 15.2.0, configured like CI (Release, Ninja, `-DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON`, ccache), lavapipe from Mesa 26.0.8 with `VK_ICD_FILENAMES=<lvp_icd json> ANYPS5_REQUIRE_VULKAN=1 GALLIUM_OVERRIDE_CPU_CAPS=avx`, on `main` c8eb1f52d: - `ctest -R '^agc_driver_pixel32_ar_export$'` fails on `main` with the emitter unchanged: `wave32 the 32_AR export with EN 0x3 of (0.5, 0.25, 2, 0.0625) into the COLOR_32 FLOAT ALT_REV (alpha only) target stored 0x3f800000 at pixel (0, 0), expected 0x3e800000`. With the comparison changed locally to report every mismatching row instead of stopping at the first, all 16 rows (4 exports, 2 targets, wave32 and wave64) fail on `main`. With the fix the unchanged test passes in under 0.5 s, also with `--repeat until-fail:3`. - `ctest -R 'agc_shader|agc_driver|shader' -j6`: on `main` with only the new test added, 381 of 382 pass and the new test fails. With the fix, 382 of 382 pass. - Full `ctest -j6 --timeout 120` on the commit: 1044 of 1044 pass. The skips are the existing lavapipe subgroup skips. - `tools/check_test_registration.py` and `main`'s `tools/check_conventions.py` pass, including `--title`/`--body`. - Rebased onto `main` 84e2a8c0b (no conflicts): the new test passes 3 of 3 runs, and `ctest -R 'agc_shader|agc_driver|shader'` passes 382 of 382. Native Windows 11, WinLibs GCC 15.2.0, NVIDIA GeForce RTX 5080 (driver 616.92), on the same commit: the new test passes 3 of 3 runs, and `ctest -R 'agc_shader|agc_driver|shader|recompiler'` passes 381 of 381. Not measured on AMD hardware, neither gfx1013 nor any PC RDNA 2 GPU. The sources above are compilers, not measurements. `tools/hw-oracle` runs compute kernels only and cannot reach the SPI color export path ([HW_ORACLE.md](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/HW_ORACLE.md)). A reviewer with a gfx103x GPU could confirm it with a RADV draw into an R32_SFLOAT target blended with SRC_ALPHA, or into an alpha-only target. `RADV_DEBUG=shaders` should show an `exp mrt0` with the alpha in the second channel and the last two channels `off`, and the image should follow that alpha. ### 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 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: none - [x] Unblocks: none - [x] GPUs tested: lavapipe (Mesa 26.0.8, llvmpipe) on WSL2 Ubuntu 26.04; NVIDIA GeForce RTX 5080, driver 616.92, Windows 11 - [x] AI-assisted: yes. Written with Claude Code; I reviewed every line and ran the tests above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-14 02:33:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:33:25Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159593138 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5110#issuecomment-6159593138). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:33:25Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Pull request closed

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!5110
No description provided.