feat(agc): draw PS4 EQAA and one-fragment color targets #18176

Merged
puridanish284 merged 3 commits from upstream-pr/18176 into main 2026-11-14 17:41:02 +00:00
puridanish284 commented 2026-11-10 18:24:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by puridanish284 on 2026-11-10T18:24:11Z.


What

A PS4 (GCN) color target with fewer fragments than samples (CB_COLOR_ATTRIB NUM_FRAGMENTS below NUM_SAMPLES) stopped the run with AGC graphics: GCN color targets with fewer fragments than samples (EQAA) are not implemented. It is the current stop of Grand Theft Auto V (CUSA00419) after 34.5 s, blocker 7 in #18084, which no issue or pull request tracked.

DecodeGcnColorBuffer now reads these targets as the AGC path's decoder has since #9700 and #9450:

  • 2 or 4 fragments of 4 or 8 samples (EQAA): samples is the coverage sample count and eqaaFragments the fragment count, so the target is drawn at its coverage samples as a host-resident target (#9892), with its color memory guarded over the fragments it stores. It needs CB_COLOR_INFO COMPRESSION and a CB_COLOR_FMASK base, as on the AGC path, and throws without them.
  • 1 fragment of 2, 4 or 8 samples: one stored sample with coverageSamples set, drawn by the AGC path's one-fragment code. With COMPRESSION its FMASK base is recorded, and that code guards it.
  • More fragments than samples throws.

The AGC path sizes both FMASK guards (fmaskBytes and GuardOneFragmentFmask) with the SW_64KB_Z_X layout, which does not hold for GCN tiling: for a 64x64 target they guard 64 KiB where the PS4 FMASK is 4 KiB, so later guest data in that range would be refused. A GCN target now records the size CB_COLOR_FMASK_SLICE gives in ColorTarget::gcnFmaskBytes, and both guards use it for GCN tile modes: (tile max + 1) × 64 pixels of

Fragments FMASK bits per pixel addrlib SiLib::HwlComputeFmaskBits
1 8, whatever the coverage sample count bpp = 1, numSamples = 8
2 2 × samples bpp = 2
4 4 × samples bpp = 4

A slice is pitch × height × bpp × samples bits in addrlib's macro-tiled layout, and Mesa programs TILE_MAX as pitch × height / 64 − 1 of the FMASK surface (ac_surface.c). The register fields are GFX7's from Mesa's gfx7.json. gcnFmaskBytes is 32 bits (at most 2^22 tiles × 64 pixels × 32 bits = 1 GiB) and fills padding after fmaskPipeBankXor, so sizeof(State) stays 952 and the pipeline journal, which records no FMASK field, is unchanged.

Update, 2026-11-12, later array slices (f348629c5c, with main c85dcfd005 merged in as b58d7b1f4d): a CB_COLOR_VIEW of slice n of a target storing 2 or more fragments started n single-sample slices past CB_COLOR_BASE, as on main, and its CMASK and FMASK at their bases. A slice holds all stored fragments, as addrlib sizes it with its samples (egbaddrlib.cpp), and Mesa programs the color, CMASK and FMASK bases for slice 0 and the layer only in CB_COLOR_VIEW (ac_descriptors.c, L1177), so the CB steps all three per slice. Slice n of a multisampled, EQAA or one-fragment target now starts n slices of its stored fragments past the base, and its CMASK and FMASK n CB_COLOR_CMASK_SLICE and CB_COLOR_FMASK_SLICE sizes past theirs; a single-sample target keeps its stride. A later slice of the 2D-tiled modes still throws here; #18721 places single-sample ones.

Unchanged: FMASK contents are not modeled (the plane is guarded, never written); a one-fragment target with FAST_CLEAR still throws as a single-sample fast clear; and a PS4 multisampled target, EQAA or not, still throws when it is first drawn without a fast clear (initial multisample color contents with CMASK require a modeled metadata import, or initial multisample color footprint is not implemented without CMASK). The new test introduces its targets with a fast clear.

Debt: the "PS4 (GCN) multisampled color targets" entry now covers EQAA and one-fragment targets, the FMASK size and what still throws, and a new "PS4 (GCN) color array slice strides" entry says where a later slice, its CMASK and its FMASK start.

Overlap: tools/pr_overlap.py --branch claude/zealous-brown-h1u67r against main 9e3265259e and the 2011 open pull requests reported no overlap with those it could compare and failed closed on 39 that already conflict with main and share docs/dev/debt/libSceAgcDriver.md, State.hpp, State.cpp or MultisampleTarget.cpp with this branch. Merged into main and into this branch, each of the 39 conflicts in the same files with the same number of hunks, except #14212, which puts a blank line between all debt entries and gets one more hunk on the entry this branch rewrites; a merge keeps both. Of them, #9748, #9895, #10249 and #11551 edit State.cpp, none in the GCN color target decode or its FMASK fields, and #9895 and #11551 keep the EQAA refusal.

GTA V's target is a 4-sample, 1-fragment target with FAST_CLEAR and COMPRESSION (adam25136's run in the comments): this PR draws it as one stored sample and still refuses its fast clear, at PS4 color target fast clear (CMASK) is not implemented. #18177 materializes the fast clears of single-sample and one-fragment PS4 targets on top of this branch and depends on it; until this PR merges, #18177's diff includes it.

Tested

Windows 11 (10.0.26200.9711) with WSL2 Ubuntu 24.04.5 LTS (kernel 6.18.54.1-microsoft-standard-WSL2), gcc 13.3.0, -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON, test targets only. Vulkan device: lavapipe (llvmpipe (LLVM 20.1.2, 256 bits), Mesa 25.2.8, Vulkan 1.4.318); the machine's GeForce RTX 3080 has no Vulkan driver inside WSL2. No title or console.

  • agc_gcn_color_target (CPU): the new FewerFragmentsDecode checks 4/2, 8/2, 8/4 and 4/1 targets (samples, coverage samples, fragments, FMASK base and size, no FMASK or CMASK on an uncompressed one-fragment target) and the four refusals.
  • New agc_driver_gcn_eqaa_color_target (PS4 shader mode, hand-encoded GFX7 shaders, guest memory below 2^40): fast-clears and draws a 4-sample 2-fragment target and a 4x target with the same two triangles. Their CB resolves are identical and hold 102 quarter- or three-quarter-coverage channels; the EQAA FMASK guard ends at the 4 KiB CB_COLOR_FMASK_SLICE gives, as does that of a compressed one-fragment target, and the color guard covers the two stored fragments only. It passes 3 of 3 runs.
  • On main 946133f92f, the same test (without its two gcnFmaskBytes checks, as the field does not exist there) stops at the title's message: AGC graphics: GCN color targets with fewer fragments than samples (EQAA) are not implemented.
  • Mutation check: sizing either FMASK guard as on the AGC path fails the new test (a test read of 0x800051000+0x100 overlaps the FMASK of EQAA color target 0x800050000+0x10000, and the same for the one-fragment target).
  • AGC protocol, on main 946133f92f and on this branch, same machine, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation in the build directory: ctest -R '^(agc_gcn_color_target|agc_driver_eqaa_color_target|agc_driver_graphics|agc_driver_gcn_.*|agc_driver_.*multisample.*|agc_driver_cached_image_multisample_guard|agc_driver_sample_multisample_target)$' -E sampled_cache_budget -j 8 --timeout 300 -V: 28 of 28 pass on main, 29 of 29 on this branch. The Khronos validation layer is Ubuntu's 1.3.275, loaded through VK_LAYER_PATH; the loader logs Insert instance layer "VK_LAYER_KHRONOS_validation", and neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS. The only VUID in either log is VUID-VkDeviceCreateInfo-pNext-pNext at device creation (#17693: the layer is older than the repository's headers), with the same count in every test of both runs, plus one for the new test's device.
  • python3 tools/check_conventions.py --base upstream/main: all conventions checks passed. The branch merges cleanly with main 9e3265259e, which changed none of its files.
  • Not built for Windows or macOS here (no MinGW toolchain on this machine); the new test allocates its guest block there through the guest arena, as GcnColorTarget.cpp does.
  • Not run on GTA V or any other title (I have no dump), nor on a hardware GPU.
  • 2026-11-12, head b58d7b1f4d: agc_gcn_color_target's new MultisampledSlicesDecode decodes slice 1 of a 4x array 4 single-sample slices past the base with its CMASK one CMASK slice past its base; slice 2 of a 4-sample 2-fragment array 2 × 2 slices past, with its FMASK and CMASK two of their slices past; slice 3 of a compressed one-fragment array 3 single-fragment slices past, with its FMASK three FMASK slices past; and slice 0 at the three bases. Removing the fragment factor, the CMASK offset or the FMASK offset each fails it.
  • Same head, the focused set above with the validation layer: 29 of 29 pass, and 28 of 28 on main c85dcfd005. Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS, and every test logs the same VUID- ids and counts on both (VUID-VkDeviceCreateInfo-pNext-pNext at device creation, and 2 and 36 VUID-vkCmdDraw-None-07629 in agc_driver_native_multisample_depth and agc_driver_sample_mask_multisample), plus the new test's device-creation message.
  • The branch merges cleanly with #18177 and #18721; the three merged together pass agc_gcn_color_target, agc_driver_graphics, agc_driver_gcn_eqaa_color_target, agc_driver_gcn_fast_clear_color_target and agc_driver_gcn_color_array_slices.

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
  • Fixes: none
  • Unblocks: CUSA00419 #18084, blocker 7 with #18177: adam25136's run shows this PR ends the EQAA stop and the title then stops on the same target's fast clear, which #18177 materializes
  • GPUs tested: llvmpipe (lavapipe), Mesa 25.2.8, LLVM 20.1.2, Vulkan 1.4.318, Ubuntu 24.04.5 on WSL2 (Windows 11); no hardware GPU
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5246621267 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18176). Originally posted by [puridanish284](https://github.com/puridanish284) on 2026-11-10T18:24:11Z. --- ### What A PS4 (GCN) color target with fewer fragments than samples (`CB_COLOR_ATTRIB` `NUM_FRAGMENTS` below `NUM_SAMPLES`) stopped the run with `AGC graphics: GCN color targets with fewer fragments than samples (EQAA) are not implemented`. It is the current stop of Grand Theft Auto V (CUSA00419) after 34.5 s, blocker 7 in #18084, which no issue or pull request tracked. `DecodeGcnColorBuffer` now reads these targets as the AGC path's decoder has since #9700 and #9450: - 2 or 4 fragments of 4 or 8 samples (EQAA): `samples` is the coverage sample count and `eqaaFragments` the fragment count, so the target is drawn at its coverage samples as a host-resident target (#9892), with its color memory guarded over the fragments it stores. It needs `CB_COLOR_INFO` `COMPRESSION` and a `CB_COLOR_FMASK` base, as on the AGC path, and throws without them. - 1 fragment of 2, 4 or 8 samples: one stored sample with `coverageSamples` set, drawn by the AGC path's one-fragment code. With `COMPRESSION` its FMASK base is recorded, and that code guards it. - More fragments than samples throws. The AGC path sizes both FMASK guards (`fmaskBytes` and `GuardOneFragmentFmask`) with the `SW_64KB_Z_X` layout, which does not hold for GCN tiling: for a 64x64 target they guard 64 KiB where the PS4 FMASK is 4 KiB, so later guest data in that range would be refused. A GCN target now records the size `CB_COLOR_FMASK_SLICE` gives in `ColorTarget::gcnFmaskBytes`, and both guards use it for GCN tile modes: (tile max + 1) × 64 pixels of | Fragments | FMASK bits per pixel | [addrlib `SiLib::HwlComputeFmaskBits`](https://gitlab.freedesktop.org/mesa/mesa/-/blob/mesa-25.2.8/src/amd/addrlib/src/r800/siaddrlib.cpp#L3211-3301) | |---|---|---| | 1 | 8, whatever the coverage sample count | `bpp = 1`, `numSamples = 8` | | 2 | 2 × samples | `bpp = 2` | | 4 | 4 × samples | `bpp = 4` | A slice is pitch × height × bpp × samples bits in addrlib's [macro-tiled layout](https://gitlab.freedesktop.org/mesa/mesa/-/blob/mesa-25.2.8/src/amd/addrlib/src/r800/egbaddrlib.cpp#L619-620), and Mesa programs `TILE_MAX` as pitch × height / 64 − 1 of the FMASK surface ([`ac_surface.c`](https://gitlab.freedesktop.org/mesa/mesa/-/blob/mesa-25.2.8/src/amd/common/ac_surface.c#L1690-1692)). The register fields are GFX7's from Mesa's `gfx7.json`. `gcnFmaskBytes` is 32 bits (at most 2^22 tiles × 64 pixels × 32 bits = 1 GiB) and fills padding after `fmaskPipeBankXor`, so `sizeof(State)` stays 952 and the pipeline journal, which records no FMASK field, is unchanged. **Update, 2026-11-12, later array slices** (`f348629c5c`, with `main` `c85dcfd005` merged in as `b58d7b1f4d`): a `CB_COLOR_VIEW` of slice n of a target storing 2 or more fragments started n single-sample slices past `CB_COLOR_BASE`, as on `main`, and its CMASK and FMASK at their bases. A slice holds all stored fragments, as addrlib sizes it with its samples ([`egbaddrlib.cpp`](https://github.com/openbsd/xenocara/blob/1b39033df8d928ec247ca64448c4a63c72302db7/lib/mesa/src/amd/addrlib/src/r800/egbaddrlib.cpp#L1878-L1897)), and Mesa programs the color, CMASK and FMASK bases for slice 0 and the layer only in `CB_COLOR_VIEW` ([`ac_descriptors.c`](https://github.com/openbsd/xenocara/blob/1b39033df8d928ec247ca64448c4a63c72302db7/lib/mesa/src/amd/common/ac_descriptors.c#L1391-L1492), [L1177](https://github.com/openbsd/xenocara/blob/1b39033df8d928ec247ca64448c4a63c72302db7/lib/mesa/src/amd/common/ac_descriptors.c#L1177-L1178)), so the CB steps all three per slice. Slice n of a multisampled, EQAA or one-fragment target now starts n slices of its stored fragments past the base, and its CMASK and FMASK n `CB_COLOR_CMASK_SLICE` and `CB_COLOR_FMASK_SLICE` sizes past theirs; a single-sample target keeps its stride. A later slice of the 2D-tiled modes still throws here; #18721 places single-sample ones. Unchanged: FMASK contents are not modeled (the plane is guarded, never written); a one-fragment target with `FAST_CLEAR` still throws as a single-sample fast clear; and a PS4 multisampled target, EQAA or not, still throws when it is first drawn without a fast clear (`initial multisample color contents with CMASK require a modeled metadata import`, or `initial multisample color footprint is not implemented` without CMASK). The new test introduces its targets with a fast clear. Debt: the "PS4 (GCN) multisampled color targets" entry now covers EQAA and one-fragment targets, the FMASK size and what still throws, and a new "PS4 (GCN) color array slice strides" entry says where a later slice, its CMASK and its FMASK start. Overlap: `tools/pr_overlap.py --branch claude/zealous-brown-h1u67r` against `main` `9e3265259e` and the 2011 open pull requests reported no overlap with those it could compare and failed closed on 39 that already conflict with `main` and share `docs/dev/debt/libSceAgcDriver.md`, `State.hpp`, `State.cpp` or `MultisampleTarget.cpp` with this branch. Merged into `main` and into this branch, each of the 39 conflicts in the same files with the same number of hunks, except #14212, which puts a blank line between all debt entries and gets one more hunk on the entry this branch rewrites; a merge keeps both. Of them, #9748, #9895, #10249 and #11551 edit `State.cpp`, none in the GCN color target decode or its FMASK fields, and #9895 and #11551 keep the EQAA refusal. GTA V's target is a 4-sample, 1-fragment target with `FAST_CLEAR` and `COMPRESSION` (adam25136's run in the comments): this PR draws it as one stored sample and still refuses its fast clear, at `PS4 color target fast clear (CMASK) is not implemented`. #18177 materializes the fast clears of single-sample and one-fragment PS4 targets on top of this branch and depends on it; until this PR merges, #18177's diff includes it. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 (10.0.26200.9711) with WSL2 Ubuntu 24.04.5 LTS (kernel 6.18.54.1-microsoft-standard-WSL2), gcc 13.3.0, `-DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON`, test targets only. Vulkan device: lavapipe (`llvmpipe (LLVM 20.1.2, 256 bits)`, Mesa 25.2.8, Vulkan 1.4.318); the machine's GeForce RTX 3080 has no Vulkan driver inside WSL2. No title or console. - `agc_gcn_color_target` (CPU): the new `FewerFragmentsDecode` checks 4/2, 8/2, 8/4 and 4/1 targets (samples, coverage samples, fragments, FMASK base and size, no FMASK or CMASK on an uncompressed one-fragment target) and the four refusals. - New `agc_driver_gcn_eqaa_color_target` (PS4 shader mode, hand-encoded GFX7 shaders, guest memory below 2^40): fast-clears and draws a 4-sample 2-fragment target and a 4x target with the same two triangles. Their CB resolves are identical and hold 102 quarter- or three-quarter-coverage channels; the EQAA FMASK guard ends at the 4 KiB `CB_COLOR_FMASK_SLICE` gives, as does that of a compressed one-fragment target, and the color guard covers the two stored fragments only. It passes 3 of 3 runs. - On `main` `946133f92f`, the same test (without its two `gcnFmaskBytes` checks, as the field does not exist there) stops at the title's message: `AGC graphics: GCN color targets with fewer fragments than samples (EQAA) are not implemented`. - Mutation check: sizing either FMASK guard as on the AGC path fails the new test (`a test read of 0x800051000+0x100 overlaps the FMASK of EQAA color target 0x800050000+0x10000`, and the same for the one-fragment target). - AGC protocol, on `main` `946133f92f` and on this branch, same machine, with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` in the build directory: `ctest -R '^(agc_gcn_color_target|agc_driver_eqaa_color_target|agc_driver_graphics|agc_driver_gcn_.*|agc_driver_.*multisample.*|agc_driver_cached_image_multisample_guard|agc_driver_sample_multisample_target)$' -E sampled_cache_budget -j 8 --timeout 300 -V`: 28 of 28 pass on `main`, 29 of 29 on this branch. The Khronos validation layer is Ubuntu's 1.3.275, loaded through `VK_LAYER_PATH`; the loader logs `Insert instance layer "VK_LAYER_KHRONOS_validation"`, and neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`. The only VUID in either log is `VUID-VkDeviceCreateInfo-pNext-pNext` at device creation (#17693: the layer is older than the repository's headers), with the same count in every test of both runs, plus one for the new test's device. - `python3 tools/check_conventions.py --base upstream/main`: all conventions checks passed. The branch merges cleanly with `main` `9e3265259e`, which changed none of its files. - Not built for Windows or macOS here (no MinGW toolchain on this machine); the new test allocates its guest block there through the guest arena, as `GcnColorTarget.cpp` does. - Not run on GTA V or any other title (I have no dump), nor on a hardware GPU. - 2026-11-12, head `b58d7b1f4d`: `agc_gcn_color_target`'s new `MultisampledSlicesDecode` decodes slice 1 of a 4x array 4 single-sample slices past the base with its CMASK one CMASK slice past its base; slice 2 of a 4-sample 2-fragment array 2 × 2 slices past, with its FMASK and CMASK two of their slices past; slice 3 of a compressed one-fragment array 3 single-fragment slices past, with its FMASK three FMASK slices past; and slice 0 at the three bases. Removing the fragment factor, the CMASK offset or the FMASK offset each fails it. - Same head, the focused set above with the validation layer: 29 of 29 pass, and 28 of 28 on `main` `c85dcfd005`. Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`, and every test logs the same `VUID-` ids and counts on both (`VUID-VkDeviceCreateInfo-pNext-pNext` at device creation, and 2 and 36 `VUID-vkCmdDraw-None-07629` in `agc_driver_native_multisample_depth` and `agc_driver_sample_mask_multisample`), plus the new test's device-creation message. - The branch merges cleanly with #18177 and #18721; the three merged together pass `agc_gcn_color_target`, `agc_driver_graphics`, `agc_driver_gcn_eqaa_color_target`, `agc_driver_gcn_fast_clear_color_target` and `agc_driver_gcn_color_array_slices`. ### 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] Fixes: none - [x] Unblocks: CUSA00419 #18084, blocker 7 with #18177: adam25136's run shows this PR ends the EQAA stop and the title then stops on the same target's fast clear, which #18177 materializes - [x] GPUs tested: llvmpipe (lavapipe), Mesa 25.2.8, LLVM 20.1.2, Vulkan 1.4.318, Ubuntu 24.04.5 on WSL2 (Windows 11); no hardware GPU - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!18176
No description provided.