fix(agc): apply CMASK fast clears per tile #2470
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2470"
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 oneandonlydean on 2026-10-09T22:25:30Z.
What
materializeCmaskCleardecodes the CMASK tile by tile instead of requiring it to be all fast-cleared or all expanded:CmaskLayout), addressed with the pipe-aligned SW_64KB_Z_X CMASK equation for 16 pipes from AMD addrlib (GFX10_CMASK_SW_PATTERN,Gfx10Lib::HwlComputeCmaskAddrFromCoord). The sizes match addrlib and the existingCmaskBytes, which now uses the layout.CB_COLOR_CLEAR_WORDinto the tile's texels, edge tiles included; 0xF keeps them (Mesaac_descriptors.hCMASK_NOAA_COLOR_CLEAR_REG/CMASK_NOAA_COLOR_EXPANDED). Any other code, a cleared tile of a DCC target, and another CMASK swizzle mode throw. The CMASK is then stored as expanded.CmaskClear.comp,TextureDetiler::DispatchCmaskClear) recorded in stream order. It reads the nibbles from the import, stores the clear into the cleared tiles through a UINT view of the image (StorageTexture::ElementView) and fills the CMASK with 0xFF, so it never waits for pending GPU writes to the CMASK. An invalid code it reads sets a bit in a host-visible word, and the next materialization throws on it.CollectWrites+StoredOver).CB_COLOR_ATTRIB3FMASK_SW_MODE SW_64KB_Z_X with CMASK_PIPE_ALIGNED, a 4 KiB aligned writable CMASK and texels of at most 64 bits.CMASK_BASE_EXTis now part of the draw key (the decode already read it).Call sites and the return value of
materializeCmaskClearare unchanged. TechnicalDebt's CMASK entry is updated.Why
A title fast-clears a target and then draws over part of it before the eliminate. With the all-or-nothing check, any CMASK with both cleared and expanded tiles threw ("not all fast-cleared or all expanded"). Reading the whole CMASK on the CPU at every draw into a fast-cleared target also waited for the GPU work that writes it.
Independent of #1337: it changes
metadataPassResidentandFillClear, which this PR does not touch. With both, an all-cleared CMASK on a target without a host import also stays on the GPU.This and #2469 both add a test target in
core/libs/prx/libSceAgcDriver/CMakeLists.txt, so whichever lands second needs a small rebase of that file; nothing else overlaps.Tested
Linux (CachyOS, GCC 16.2, RTX 4090, NVIDIA 610.57.04), on
main6a2b99b82d: ctest 507/507.tools/check_conventions.pypasses.New
agc_driver_cmask_fast_clear(Vulkan, in ctest): linear and SW_64KB_R_X targets that are fast-cleared and then partly drawn, drawn again and read back; partial, edge and checkerboard eliminates through the compute pass; a fast-cleared bottom edge row under a draw of the top rows; an invalid code read by the compute pass throws. Fails onmain("CMASK whose tiles are not all fast-cleared or all expanded is not modeled").agc_driver_graphics: CMASK sizes and nibble addresses against addrlib for 11 surfaces up to 4096x4096; decode rejections (swizzle mode, pipe alignment, misaligned CMASK); draw key coverage of the decode; CPU eliminate of a partial CMASK, of a DCC decompress pass and of a CMASK whose nibbles past the target are expanded; invalid codes and a cleared tile of a DCC target throw. Fails onmainwith the same error.A heavier title, frames per second, warm caches. It does not reach its menus on
mainalone, so both builds carry the fixes it needs (boot fixes, #425, #1059, #1274, #1745 and two pending perf changes); "base" is that build. Gate run with presses at 200/210 s (two runs each after a warm-up run), and one level loaded directly (level start +30 to +150 s):* the second base run's presses landed 30 s earlier on the frame clock, which moves its menu window; the menu change uses the first base run. No CMASK code was rejected in any run.
A lighter title that runs at 60 fps, on
main+ this: all screen checks pass, 59.9 fps menu and gameplay, no skipped draws, no single-frame flashes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T22:49:58Z.
Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at
f44b3cbd:/tmp/anyps5_build) with zero warnings/errors.python3 tools/check_conventions.py --base origin/main --head HEAD-> PASS (0 errors).libSceAgcDriver. Correctly calculates tile clear strides and eliminates full surface clears when only dirty tiles require clearing.LGTM!
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T22:52:35Z.
Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head
f44b3cbd, merged ontomain09a3462ewith #2473, which currentmainneeds to build on Windows, and #2451.agc_driver_cmask_fast_clearandagc_driver_bda_span_readspass, as doagc_driver_graphicsandagc_shader_memory.libSceAgcDriver/CMakeLists.txt) and with #2449 and #2450, so it can't be merged together with any of those three as they stand.No title was run.
🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T05:28:27Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/CMakeLists.txtL748core/libs/prx/libSceAgcDriver/Graphics/shaders/CmaskClear.compcore/libs/prx/libSceAgcDriver/tests/CmaskFastClear.cpp