fix(agc): route compacted color exports to the slots CB_SHADER_MASK enables #505

Merged
oneandonlydean merged 1 commit from upstream-pr/505 into main 2026-10-05 08:23:18 +00:00
oneandonlydean commented 2026-10-04 10:45:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T10:45:26Z.


Title: fix(agc): route compacted color exports to the slots CB_SHADER_MASK enables

What

The follow-up to #294 that Michon asked for (comment). #294 is merged; this is one commit on current main.

Pixel shader color exports are compacted: export MRTi goes to the i-th MRT slot with a non-zero CB_SHADER_MASK nibble, and field i of SPI_SHADER_COL_FORMAT is the format of export i. main still maps export i to slot i and reads slot i's format field. A shader with CB_SHADER_MASK 0xf000f and SPI_SHADER_COL_FORMAT 0x44 (color to slot 0, velocity to slot 4) is therefore refused with "color export format 0": slot 4's field is 0. That is PPSA21564's glass material (60 shader variants); with those draws skipped, the glass floor and windows show the interior behind them.

  • ColorTarget gets exportIndex next to #294's slot. The attachment references, blend states, export mappings, ValidateShaders locations (through blends.size()), and the pipeline and pass keys now use the export index. The color buffer, CB_BLEND control and target mask still come from the slot.
  • An unwritten export below the highest written one stays a VK_ATTACHMENT_UNUSED reference with a disabled blend, as #294 does for gaps.
  • The recompiler already takes field i of SPI_SHADER_COL_FORMAT as the format of export MRTi (DecodePixelStageInfo, targetOutputMode[exp.index]). The decode now checks that same field.
  • Without holes in CB_SHADER_MASK, export i is slot i and nothing changes. With holes it does: for CB_SHADER_MASK 0xf0f, export 1 now goes to slot 2, not slot 1.

AMD's RDNA2 ISA guide lists the export targets (MRT0 to MRT7) but not how they map to CB slots. The mapping comes from Mesa (e5f06878):

Tested

  • Linux (CachyOS, x86-64, GCC): full build with BUILD_TESTING=ON and cmake --build build --target libs; ctest passes (183/183).
  • New CompactedExportTests in agc_driver_graphics_tests:
    • the glass state (CB_SHADER_MASK 0xf000f, CB_TARGET_MASK 0x3000f, SPI_SHADER_COL_FORMAT 0x44) decodes to two attachments: export 1 is slot 4's color buffer, with slot 4's blend control, target mask (R and G) and component mapping in ExportMappings()[1];
    • SPI_SHADER_COL_FORMAT 0x90009 (field 1 zero, slot 4's field set) is refused with "color export format 0";
    • CB_SHADER_MASK 0xf0f0f with slot 2 write-masked gives three blend states: export 1 is unused, and export 2 is slot 4.
  • On main (with only the new field added, so the test compiles), the test fails with "AGC graphics: color export format 0 is unsupported".
  • PPSA21564: the same mapping, on my integration branch's older MRT code, has been there since 2026-10-02; with it, the glass floor and windows render. This branch was not run in the title, only the tests above. Michon offered to check it on GTA V.
  • Fork CI (Linux and Windows) passes.

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 (#294 is merged)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4733732666 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/505). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T10:45:26Z. --- Title: fix(agc): route compacted color exports to the slots CB_SHADER_MASK enables ### What The follow-up to #294 that Michon asked for ([comment](https://github.com/boykopovar/AnyPS5/pull/294#issuecomment-5967289140)). #294 is merged; this is one commit on current `main`. Pixel shader color exports are compacted: export MRTi goes to the i-th MRT slot with a non-zero `CB_SHADER_MASK` nibble, and field i of `SPI_SHADER_COL_FORMAT` is the format of export i. `main` still maps export i to slot i and reads slot i's format field. A shader with `CB_SHADER_MASK` 0xf000f and `SPI_SHADER_COL_FORMAT` 0x44 (color to slot 0, velocity to slot 4) is therefore refused with "color export format 0": slot 4's field is 0. That is PPSA21564's glass material (60 shader variants); with those draws skipped, the glass floor and windows show the interior behind them. - `ColorTarget` gets `exportIndex` next to #294's `slot`. The attachment references, blend states, export mappings, `ValidateShaders` locations (through `blends.size()`), and the pipeline and pass keys now use the export index. The color buffer, `CB_BLEND` control and target mask still come from the slot. - An unwritten export below the highest written one stays a `VK_ATTACHMENT_UNUSED` reference with a disabled blend, as #294 does for gaps. - The recompiler already takes field i of `SPI_SHADER_COL_FORMAT` as the format of export MRTi (`DecodePixelStageInfo`, `targetOutputMode[exp.index]`). The decode now checks that same field. - Without holes in `CB_SHADER_MASK`, export i is slot i and nothing changes. With holes it does: for `CB_SHADER_MASK` 0xf0f, export 1 now goes to slot 2, not slot 1. AMD's RDNA2 ISA guide lists the export targets (MRT0 to MRT7) but not how they map to CB slots. The mapping comes from Mesa (e5f06878): - radv writes `CB_SHADER_MASK` uncompacted, built from the per-attachment formats ([ac_shader_util.c:43](https://gitlab.freedesktop.org/mesa/mesa/-/blob/e5f0687867f5c5e88619175d9b0442f8560e8d53/src/amd/common/ac_shader_util.c#L43), [radv_shader_info.c:898](https://gitlab.freedesktop.org/mesa/mesa/-/blob/e5f0687867f5c5e88619175d9b0442f8560e8d53/src/amd/vulkan/radv_shader_info.c#L898)). - It writes `SPI_SHADER_COL_FORMAT` with the holes removed ([radv_cmd_buffer.c:13202](https://gitlab.freedesktop.org/mesa/mesa/-/blob/e5f0687867f5c5e88619175d9b0442f8560e8d53/src/amd/vulkan/radv_cmd_buffer.c#L13202), written at [13229 to 13247](https://gitlab.freedesktop.org/mesa/mesa/-/blob/e5f0687867f5c5e88619175d9b0442f8560e8d53/src/amd/vulkan/radv_cmd_buffer.c#L13229-13247)). - The shader exports color k to MRT0 plus its compacted index ([ac_nir_lower_ps_late.c:264](https://gitlab.freedesktop.org/mesa/mesa/-/blob/e5f0687867f5c5e88619175d9b0442f8560e8d53/src/amd/common/nir/ac_nir_lower_ps_late.c#L264-274); radeonsi does the same in [si_shader_llvm_ps.c:177](https://gitlab.freedesktop.org/mesa/mesa/-/blob/e5f0687867f5c5e88619175d9b0442f8560e8d53/src/gallium/drivers/radeonsi/gfx/si_shader_llvm_ps.c#L177)). ### Tested - Linux (CachyOS, x86-64, GCC): full build with `BUILD_TESTING=ON` and `cmake --build build --target libs`; `ctest` passes (183/183). - New `CompactedExportTests` in `agc_driver_graphics_tests`: - the glass state (`CB_SHADER_MASK` 0xf000f, `CB_TARGET_MASK` 0x3000f, `SPI_SHADER_COL_FORMAT` 0x44) decodes to two attachments: export 1 is slot 4's color buffer, with slot 4's blend control, target mask (R and G) and component mapping in `ExportMappings()[1]`; - `SPI_SHADER_COL_FORMAT` 0x90009 (field 1 zero, slot 4's field set) is refused with "color export format 0"; - `CB_SHADER_MASK` 0xf0f0f with slot 2 write-masked gives three blend states: export 1 is unused, and export 2 is slot 4. - On `main` (with only the new field added, so the test compiles), the test fails with "AGC graphics: color export format 0 is unsupported". - PPSA21564: the same mapping, on my integration branch's older MRT code, has been there since 2026-10-02; with it, the glass floor and windows render. This branch was not run in the title, only the tests above. Michon offered to check it on GTA V. - Fork CI (Linux and Windows) passes. ### 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 (#294 is merged) - [x] AI-assisted: yes
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!505
No description provided.