feat(agc): materialize single-sample and one-fragment PS4 color target fast clears #18177
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18177"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by puridanish284 on 2026-11-10T18:24:28Z.
What
A single-sample PS4 (GCN) color target with
CB_COLOR_INFOFAST_CLEARstopped the run when it was decoded:AGC graphics: PS4 color target fast clear (CMASK) is not implemented. Only multisampled GCN targets took their CMASK (#9892). A fast clear is how GCN titles usually clear a render target: the CMASK is filled with the fast clear code andCB_COLOR_CLEAR_WORD0/1hold the color, which a later draw or fast clear eliminate expands.Update, 2026-11-11: this PR now depends on #18176, merged in (
65dfabca21), and also materializes the fast clears of one-fragment targets. adam25136 ran #18176 on Grand Theft Auto V (CUSA00419) (comment): its EQAA stop is gone, and the title stops on the same target atPS4 color target fast clear (CMASK) is not implemented, a 4-sample, 1-fragment target withFAST_CLEARandCOMPRESSION(CB_COLOR_INFO0x0002e828,CB_COLOR_ATTRIB0x000021ce, 1920x1088). #18176 draws such a target as one stored sample, so its fast clear is the single-sample one this PR materializes: with both, its CMASK is taken instead of that refusal, and the CMASK codes of a one-fragment target are read as below.Update, 2026-11-12, later array slices (
79fee62a8d, with #18176's update merged in asa799188cdf): a fast-cleared target viewed at slice n read and expanded the CMASK of slice 0. With #18176's slice strides, the CMASK of slice n starts nCB_COLOR_CMASK_SLICEsizes pastCB_COLOR_CMASK, and a one-fragment target's FMASK n FMASK slices past its base. A CMASK slice is a multiple of 128 bytes (128 for a 64x64 target), so the GCN CMASK is now read and expanded at 128-byte alignment instead of 256.FAST_CLEARnow takes its CMASK as multisampled ones do (CB_COLOR_CMASK,CMASK_SLICEtile max + 1 times 128 bytes) and is a CMASK fast clear.COMPRESSIONalone still takes no CMASK on a single-sample target.materializeCmaskClear, which runs before a draw and in a CB fast clear eliminate, reads the CMASK with the AGC path'sCmaskLayout, whose size and tile order are the RDNA ones; for a GCN target it threwCMASK size differs from the color target's CMASK layout. For a GCN tile mode it now reads thecmaskBytesthe registers give, through the same recorder and shadow synchronization (readCmask's read moved intoreadCmaskBytes, unchanged for the AGC path), at 128-byte alignment, the unit of a CMASK slice:readCmaskrequires, or it throwsCMASK code 0x… of a one-fragment GCN color target is not implemented;a GCN CMASK that fast clears only some tiles of its color target is not implemented (the GCN CMASK tile order is not modeled).Each tile's code is read as
readCmaskreads it on the AGC path: 0 for a fast-cleared tile, any other code for one whose texels are in memory (0xf when expanded, 0xc to 0xf for a one-fragment target).Debt: the "PS4 (GCN) multisampled color targets" entry no longer lists the single-sample or one-fragment fast clear among what throws, and a new "PS4 (GCN) single-sample and one-fragment fast clears" entry says what is modeled and what throws.
Overlap:
tools/pr_overlap.py --branch claude/ps4-single-sample-fast-clearreported no overlap with the open pull requests it could compare and failed closed on 69 that already conflict withmainand shareDraw.cpp,State.cppordocs/dev/debt/libSceAgcDriver.mdwith this branch. Merged intomainand into this branch, each of them 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 two entries this branch changes; a merge keeps both. None of the 69 changesDecodeGcnColorBuffer's CMASK,materializeCmaskClear,readCmaskorstoreCmaskClearTexels. Since then #11825 (fast clears of array and layered color targets) renamesmaterializeCmaskCleartomaterializeCmaskClearOfnext to this branch's GCN branch; a merge keeps the GCN branch in the renamed function.Depends on #18176, merged in: until it merges, its commits
b278e7d8deandf348629c5cshow in this diff, and the merge resolves the two files both change,GcnColorTarget.cppand the PS4 multisampled debt entry.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 newSingleSampleFastClearDecodechecks the CMASK address, size and fast clear of a single-sample target withFAST_CLEAR, no CMASK withCOMPRESSIONalone, and the refusal without a CMASK address.New
agc_driver_gcn_fast_clear_color_target(PS4 shader mode, hand-encoded GFX7 shaders, guest memory below 2^40, a 64x64 RGBA8 thin-1D target with a red clear color):It passes 3 of 3 runs. Built against
main'sState.cppandDraw.cpp, it stops atAGC graphics: PS4 color target fast clear (CMASK) is not implemented.Mutation checks: without the GCN branch the draw throws
CMASK size differs from the color target's CMASK layout; without the CMASK write-back the test fails atthe CMASK of the materialized GCN fast clear was not expanded.AGC protocol, on
main9e3265259eand on this branch, same machine, withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationin 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 onmain(without the new test) and 29 of 29 on this branch. The Khronos validation layer is Ubuntu's 1.3.275, loaded throughVK_LAYER_PATH; the loader logsInsert instance layer "VK_LAYER_KHRONOS_validation", and neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS. The only VUID in either log isVUID-VkDeviceCreateInfo-pNext-pNextat 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.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.cppdoes.2026-11-11, head
1b91fc8eaemerged withmain62bd7dd61e(a temporary merge, same machine and options): the focused set above passes 30 of 30, and 28 of 28 onmainwithout the two new tests. The VUIDs per test are the same:VUID-VkDeviceCreateInfo-pNext-pNextat device creation, and 114VUID-vkCmdDraw-None-07629inagc_driver_native_multisample_depthandagc_driver_sample_mask_multisampleon both, plus one device-creation message for each new test.agc_driver_gcn_fast_clear_color_targetnow also draws over a 4-sample 1-fragment target withFAST_CLEARandCOMPRESSION, as GTA V's: under code 0 it leaves the clear color around the same 1653 drawn texels and expands the CMASK, under code 0xc on every tile it keeps its blue texels, and code 0x5 is refused by name.agc_gcn_color_targetchecks that such a target takes its CMASK and its FMASK.Mutation checks of the one-fragment codes: without their check, code 0x5 is not refused; with the earlier all-0-or-all-0xff rule, code 0xc throws
fast clears only some tiles.JJenkx ran
agc_driver_gcn_fast_clear_color_targetandagc_gcn_color_targetof the earlier head359965bfa0on Windows with an AMD RX 6700 XT: 3 of 3 runs pass (comment).Not run on a title here; the GTA V stop above is adam25136's run of #18176.
2026-11-12, head
79fee62a8d:agc_driver_gcn_fast_clear_color_targetalso draws into slice 1 of two-slice single-sample and one-fragment arrays whose slice 0 CMASK is expanded and slice 1 CMASK holds code 0. Slice 1 gets the clear color around the same 1653 drawn texels, slice 0 keeps its blue texels, slice 1's CMASK is expanded, and the one-fragment array's FMASK guard covers slice 1's FMASK and not slice 0's.agc_gcn_color_targetchecks the CMASK of slice 2 of a fast-cleared single-sample array and the CMASK and FMASK of slice 1 of a one-fragment one. With the 256-byte alignment the draw fails atnull or misaligned address; without the CMASK slice offset, atthe fast-cleared GCN target did not decode with the CMASK of its slice.Same head, the focused set with the validation layer: 30 of 30 pass, and 28 of 28 on
mainc85dcfd005without the two new tests, with the sameVUID-ids and counts per test on both, plus one device-creation message for each new test.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T16:21:29Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the available evidence supports merging, with no blocking defects found in the changed implementation.
What I ran
Reviewed head
79fee62a8d5b6c02d643813c74cc3177e64d0893using the prepared diff andrepo_read.pyfor targeted source context. No build or test commands were run; reported test results below are author-supplied.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Read changed files:
Draw.cpp,State.cpp,GcnColorTarget.cpp,GcnFastClearColorTarget.cpp, andlibSceAgcDriver.md. All changed files listed in the manifest were included and their relevant changed sections were read. Did not run tests or independently verify the author-reported results, platform builds, or console behavior.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:33:23Z.
Review: COMMENTED
The trial merge onto
c1601e56d5was clean. I also verified that this exact head is an ancestor of #22140, which adds tile-ordered partial CMASK materialization. Please keep full-clear and all-expanded controls in this PR, and preserve the explicit mixed-clear refusal here so #22140 remains the change that replaces it. The one-fragment and single-sample tests cover different metadata paths. Paired lavapipe validation is pending.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.