fix(agc): apply the pending CMASK clear in a fast-clear eliminate of a multisampled target #24993

Merged
birdmarty merged 1 commit from upstream-pr/24993 into main 2026-11-21 21:05:34 +00:00
birdmarty commented 2026-11-21 14:24:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by birdmarty on 2026-11-21T14:24:11Z.


What

Apply a pending CMASK fast clear to the host image when a CB fast-clear eliminate (CB_COLOR_CONTROL mode 2) targets a multisampled color target, instead of refusing the pass.

Previously, DecodeColorMetadataPass accepted only a CB resolve (mode 3) or an FMASK decompress (mode 5) over a multisampled color target and threw CB metadata pass over a multisampled color target, whose texels are on the host, is unsupported for mode 2. On the console, a fast-clear eliminate writes the fast-clear colour into tiles whose CMASK marks them as fast-cleared; in AnyPS5, an FMASK decompress already handles this for multisampled targets by calling MaterializeMultisampleTargetClear. A fast-clear eliminate now takes the same path when the target has a CMASK address. A fast-clear eliminate without a CMASK address and a CB DCC decompress (mode 6) over a multisampled target still throw.

Changes

  • core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp: allow ColorMetadataPass::Mode::EliminateFastClear over multisampled targets when target.cmaskAddress != 0; throw "fast-clear eliminate of a multisampled target without a CMASK address" when absent, and keep refusing DccDecompress over multisampled targets.
  • core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp: in RunColorMetadataPass, route multisampled targets (color.samples != 1u) to MaterializeMultisampleTargetClear(context, color) and continue, matching FmaskDecompress.
  • core/libs/prx/libSceAgcDriver/tests/Graphics.cpp: update the no-CMASK eliminate rejection test, add a decode test for a 4x multisampled SW_64KB_R_X target with CMASK and DCC (CB_COLOR_CONTROL=0x00cc0020), and check that DCC decompress (0x00cc0060) over the same target still throws.
  • core/libs/prx/libSceAgcDriver/tests/Recorder.cpp: generalize fmaskDecompressMsaaTests into msaaClearPassTests and run it for both FmaskDecompress and EliminateFastClear, verifying that a seeded CMASK fast clear materializes to the host 4x image, resolves to the clear colour, and does not re-clear on a second eliminate.
  • docs/dev/debt/changes/fix-agc-msaa-fast-clear-eliminate.md: update Multisampled targets in CB passes to document fast-clear eliminate alongside FMASK decompress, including that guest CMASK is left untouched (console rewrite to expanded is not modeled) and DCC decompress still throws.

Note: this PR and #24994 both edit the same loop in RunColorMetadataPass (Draw.cpp). Whichever merges second will need a rebase so ClaimMultisampleTargetMemory runs only for single-sample targets (after the if (color.samples != 1u) branch).

Tested

Windows 11 Pro (build 26300), Intel Core i9-9900K, MinGW-w64 GCC 15.3.0, Release build with tests, AMD Radeon RX 6800 (vendor 0x1002, device 0x73bf, AMD proprietary driver 26.10.1 / Windows driver 32.0.21045.16010, Vulkan 1.4.315), based on origin/main e60b2f74ad.

Focused AGC tests on main e60b2f74ad and on this branch (e2a5008fd0), same machine and GPU, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Vulkan SDK 1.4.363.0) and VK_LOADER_DEBUG=layer. The set has 29 tests in 11 programs (agc_driver_graphics, agc_driver_recorder, agc_driver_cmask_fast_clear, agc_driver_pipelined_metadata_pass*, agc_driver_cached_image_multisample_guard, agc_driver_multisample_{retirement,srgb_twin,fill_host_only}, agc_driver_multisampled_pass_order, agc_driver_msaa_dcc_*, agc_driver_color_memo_{msaa,metadata,untracked-cmask}_*):

  • main (e60b2f74ad): 28 passed, 1 failed (agc_driver_recorder, pre-existing Windows address-reuse failure: AGC graphics: 64 KiB R_X 512x512, 3 mips, no DCC, an access to the first unit: an earlier case's image is still in the live registry over the reused memory, so this image would store whole). Insert instance layer "VK_LAYER_KHRONOS_validation" logged 31 times, 0 missing-layer errors, 0 VUID- lines.
  • This change (e2a5008fd0): the same 28 passed, 1 failed (agc_driver_recorder, identical pre-existing failure). Insert instance layer "VK_LAYER_KHRONOS_validation" logged 31 times, 0 missing-layer errors, 0 VUID- lines.
  • agc_driver_recorder_tests --multisample-only under the same validation layer env: passed (fast-clear eliminate MSAA clear and resolve tests passed, VK_LAYER_KHRONOS_validation inserted, 0 VUID- lines).
  • Without the fix (origin/main e60b2f74ad State.cpp and Draw.cpp built with this branch's tests): agc_driver_graphics_tests fails with AGC graphics: unexpected failure: AGC graphics: CB metadata pass over a multisampled color target, whose texels are on the host, is unsupported (only a CB resolve is modeled), and agc_driver_recorder_tests --multisample-only fails with AGC graphics: fast-clear eliminate did not materialize the seeded clear to the host multisampled image.
  • py -3 tools/check_conventions.py --base origin/main and py -3 tools/debt_fold.py --check: both passed.
  • py -3 tools/pr_overlap.py --branch fix/agc-msaa-fast-clear-eliminate (2,185 open PRs): 0 overlaps among mergeable PRs; 64 PRs that conflict with main could not be compared automatically and were checked manually (along with #6808, #6989/#6995/#7002, #13963, #13147, #23252, #24049, #24572, #24735); none implements this change (#13963 is a complementary text neighbour in Draw.cpp).

Title test: Forza Horizon 5 (PPSA22327 v01.685.672, single run each on this machine):

  • Without this change (main 291739adca + #23688, runs 6–7): aborted on a fast-clear eliminate (CB_COLOR_CONTROL=0x00cc0020, CB_COLOR_INFO=0x18046718) over a 4x MSAA 3840x2160 B10G11R11 target with CMASK fast clear on, DCC and FMASK set.
  • With this change (local stack on main 089d2df72e + #23688 + this fix's State.cpp/Draw.cpp change, run 8): passed that eliminate cleanly and progressed to the next unrelated stop.

Not tested: other GPUs, Linux/macOS host builds, console hardware measurement of guest CMASK after an eliminate, or a standalone re-run of the title on e2a5008fd0 (the State.cpp and Draw.cpp diff is unchanged from the tested commit).

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
  • Fixes: none
  • Unblocks: PPSA22327 #25152
  • GPUs tested: AMD Radeon RX 6800 (vendor=0x1002, device=0x73bf), AMD proprietary driver 26.10.1 (Windows driver 32.0.21045.16010, Vulkan 1.4.315), Windows 11 Pro (build 26300); Khronos validation layer 1.4.363.0 on main and this change, 0 VUIDs
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5428843099 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24993). Originally posted by [birdmarty](https://github.com/birdmarty) on 2026-11-21T14:24:11Z. --- ### What Apply a pending CMASK fast clear to the host image when a CB fast-clear eliminate (`CB_COLOR_CONTROL` mode 2) targets a multisampled color target, instead of refusing the pass. Previously, `DecodeColorMetadataPass` accepted only a CB resolve (mode 3) or an FMASK decompress (mode 5) over a multisampled color target and threw `CB metadata pass over a multisampled color target, whose texels are on the host, is unsupported` for mode 2. On the console, a fast-clear eliminate writes the fast-clear colour into tiles whose CMASK marks them as fast-cleared; in AnyPS5, an FMASK decompress already handles this for multisampled targets by calling `MaterializeMultisampleTargetClear`. A fast-clear eliminate now takes the same path when the target has a CMASK address. A fast-clear eliminate without a CMASK address and a CB DCC decompress (mode 6) over a multisampled target still throw. #### Changes - `core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp`: allow `ColorMetadataPass::Mode::EliminateFastClear` over multisampled targets when `target.cmaskAddress != 0`; throw `"fast-clear eliminate of a multisampled target without a CMASK address"` when absent, and keep refusing `DccDecompress` over multisampled targets. - `core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp`: in `RunColorMetadataPass`, route multisampled targets (`color.samples != 1u`) to `MaterializeMultisampleTargetClear(context, color)` and `continue`, matching `FmaskDecompress`. - `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`: update the no-CMASK eliminate rejection test, add a decode test for a 4x multisampled `SW_64KB_R_X` target with CMASK and DCC (`CB_COLOR_CONTROL=0x00cc0020`), and check that DCC decompress (`0x00cc0060`) over the same target still throws. - `core/libs/prx/libSceAgcDriver/tests/Recorder.cpp`: generalize `fmaskDecompressMsaaTests` into `msaaClearPassTests` and run it for both `FmaskDecompress` and `EliminateFastClear`, verifying that a seeded CMASK fast clear materializes to the host 4x image, resolves to the clear colour, and does not re-clear on a second eliminate. - `docs/dev/debt/changes/fix-agc-msaa-fast-clear-eliminate.md`: update `Multisampled targets in CB passes` to document fast-clear eliminate alongside FMASK decompress, including that guest CMASK is left untouched (console rewrite to expanded is not modeled) and DCC decompress still throws. Note: this PR and #24994 both edit the same loop in `RunColorMetadataPass` (`Draw.cpp`). Whichever merges second will need a rebase so `ClaimMultisampleTargetMemory` runs only for single-sample targets (after the `if (color.samples != 1u)` branch). ### Tested Windows 11 Pro (build 26300), Intel Core i9-9900K, MinGW-w64 GCC 15.3.0, Release build with tests, AMD Radeon RX 6800 (vendor `0x1002`, device `0x73bf`, AMD proprietary driver 26.10.1 / Windows driver 32.0.21045.16010, Vulkan 1.4.315), based on `origin/main` e60b2f74ad. Focused AGC tests on `main` e60b2f74ad and on this branch (e2a5008fd0), same machine and GPU, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (Vulkan SDK 1.4.363.0) and `VK_LOADER_DEBUG=layer`. The set has 29 tests in 11 programs (`agc_driver_graphics`, `agc_driver_recorder`, `agc_driver_cmask_fast_clear`, `agc_driver_pipelined_metadata_pass*`, `agc_driver_cached_image_multisample_guard`, `agc_driver_multisample_{retirement,srgb_twin,fill_host_only}`, `agc_driver_multisampled_pass_order`, `agc_driver_msaa_dcc_*`, `agc_driver_color_memo_{msaa,metadata,untracked-cmask}_*`): - `main` (e60b2f74ad): 28 passed, 1 failed (`agc_driver_recorder`, pre-existing Windows address-reuse failure: `AGC graphics: 64 KiB R_X 512x512, 3 mips, no DCC, an access to the first unit: an earlier case's image is still in the live registry over the reused memory, so this image would store whole`). `Insert instance layer "VK_LAYER_KHRONOS_validation"` logged 31 times, 0 missing-layer errors, 0 `VUID-` lines. - This change (e2a5008fd0): the same 28 passed, 1 failed (`agc_driver_recorder`, identical pre-existing failure). `Insert instance layer "VK_LAYER_KHRONOS_validation"` logged 31 times, 0 missing-layer errors, 0 `VUID-` lines. - `agc_driver_recorder_tests --multisample-only` under the same validation layer env: passed (`fast-clear eliminate MSAA clear and resolve tests passed`, `VK_LAYER_KHRONOS_validation` inserted, 0 `VUID-` lines). - Without the fix (`origin/main` e60b2f74ad `State.cpp` and `Draw.cpp` built with this branch's tests): `agc_driver_graphics_tests` fails with `AGC graphics: unexpected failure: AGC graphics: CB metadata pass over a multisampled color target, whose texels are on the host, is unsupported (only a CB resolve is modeled)`, and `agc_driver_recorder_tests --multisample-only` fails with `AGC graphics: fast-clear eliminate did not materialize the seeded clear to the host multisampled image`. - `py -3 tools/check_conventions.py --base origin/main` and `py -3 tools/debt_fold.py --check`: both passed. - `py -3 tools/pr_overlap.py --branch fix/agc-msaa-fast-clear-eliminate` (2,185 open PRs): 0 overlaps among mergeable PRs; 64 PRs that conflict with `main` could not be compared automatically and were checked manually (along with #6808, #6989/#6995/#7002, #13963, #13147, #23252, #24049, #24572, #24735); none implements this change (#13963 is a complementary text neighbour in `Draw.cpp`). Title test: Forza Horizon 5 (`PPSA22327` v01.685.672, single run each on this machine): - Without this change (`main` 291739adca + #23688, runs 6–7): aborted on a fast-clear eliminate (`CB_COLOR_CONTROL=0x00cc0020`, `CB_COLOR_INFO=0x18046718`) over a 4x MSAA 3840x2160 `B10G11R11` target with CMASK fast clear on, DCC and FMASK set. - With this change (local stack on `main` 089d2df72e + #23688 + this fix's `State.cpp`/`Draw.cpp` change, run 8): passed that eliminate cleanly and progressed to the next unrelated stop. Not tested: other GPUs, Linux/macOS host builds, console hardware measurement of guest CMASK after an eliminate, or a standalone re-run of the title on e2a5008fd0 (the `State.cpp` and `Draw.cpp` diff is unchanged from the tested commit). ### 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) and the licence notice of code adapted from upstream (see AGENTS.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] Fixes: none - [x] Unblocks: PPSA22327 #25152 - [x] GPUs tested: AMD Radeon RX 6800 (vendor=0x1002, device=0x73bf), AMD proprietary driver 26.10.1 (Windows driver 32.0.21045.16010, Vulkan 1.4.315), Windows 11 Pro (build 26300); Khronos validation layer 1.4.363.0 on `main` and this change, 0 VUIDs - [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!24993
No description provided.