fix(agc): materialize GCN CMASK fast clears of only some tiles #22140
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22140"
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 B-Howell on 2026-11-17T06:21:11Z.
What
Follow-up to #18177. With #18177, Bloodborne (CUSA00900 01.09) stops on character creation at
a GCN CMASK that fast clears only some tiles of its color target is not implemented (the GCN CMASK tile order is not modeled). Its CMASK (896x832 RGBA8, tile index 14,CB_COLOR_CMASK_SLICE0x3f = 8192 bytes, contents in this comment) holds only codes 0 and 1. This PR does two things inmaterializeGcnCmaskClear:gfx6MaskRam.hL261-L263): "Bits 3:2 should be 2'b11 to indicate 'not fast cleared' and bits 1:0 being 2'b00 to mean all FMask pointers are zero". A single-sample target has no FMASK, so codes 0 to 3 are fast cleared there and 0xc to 0xf are not. A one-fragment target keeps #18177's rule (code 0, or 0xc to 0xf). Codes 4 to 0xb throwCMASK code 0x… of a single-sample GCN color target is not implemented. Bloodborne's CMASK is therefore a whole-surface fast clear.storeCmaskClearTexelspath the AGC partial CMASK uses (itsCmaskLayoutparameter became the surface layout and tile counts). The newGcnCmaskLayoutfollows addrlib's tiled CMASK addressing for the P8_32x32_16x16 pipe configuration thatGcnTilinguses for these modes, with 8 pipes and 256-byte pipe interleaves (Mesamesa-25.2.8,siaddrlib.cpp):TileCoordToMaskElementIndex,ADDR_PIPECFG_P8_32x32_16x16:*macroShift = 1; *elemIdxBits =2; elemIdx0 = tx1^ty0; elemIdx1 = tx1;ComputePipeFromCoord, same case:pipeBit0 = x3 ^ y3 ^ x4; pipeBit1 = x4 ^ y4; pipeBit2 = x5 ^ y5;HwlComputeXmaskAddrFromCoord, tiled branch:microNumber = static_cast<UINT_64>(microX + microY * (macroWidth / MicroTileWidth / 4)) << microShift;,macroOffset = macroNumber * tileNumPerPipe * elemBits;withtileNumPerPipe = 256, thenaddrInBits = totalOffset % (m_pipeInterleaveBytes * 8) + pipe * (m_pipeInterleaveBytes * 8) + totalOffset / (m_pipeInterleaveBytes * 8) * (m_pipeInterleaveBytes * 8) * numPipes;and*pBitPosition = static_cast<UINT_32>(addrInBits) % 8;Lib::ComputeTileDataWidthAndHeightwithCmaskCacheBits = 1024,CmaskElemBits = 4, 8 pipes), andLib::ComputeCmaskInfoadds macro rows until the slice is a multiple ofm_pipeInterleaveBytes * HwlGetPipes(pTileInfo)(2048 bytes). This gives Bloodborne's 8192 bytes for 896x832, matching itsCMASK_SLICE.HwlComputeXmaskAddrFromCoordpasses it, so the CMASK order does not depend on the target's bank or pipe XOR.Still throws, with debt: a partial fast clear of a 1D-tiled or linear target, one through a linear CMASK (
CB_COLOR_INFOCMASK_IS_LINEAR, bit 19, now decoded intoColorTarget::cmaskLinear), and one whoseCMASK_SLICEis smaller than addrlib's padded size. The last case happens for an odd count of 512x256 macro tiles: Mesa'sac_compute_cmaskgives a 128x128 targetcmask_slice_tile_max7 (1024 bytes) but a 2048-bytecmask_slice_size, and addrlib addresses pipes 4 to 7 of its one macro tile past the first 1024 bytes. Reading pastCMASK_SLICEwould overlap the next slice under this branch's slice stride, so it is refused instead. Whole-surface clears of such targets still work as in #18177. @puridanish284: a slice stride ofCMASK_SLICEbytes may be shorter than addrlib's for those targets. Mesa steps slices bycmask_slice_size. It does not matter for Bloodborne.Debt: the fragment changes #18177's "PS4 (GCN) single-sample and one-fragment fast clears" entry.
Overlap:
tools/pr_overlap.py --branch claude/gcn-partial-cmask-clearfound no overlap among the PRs it could compare. It failed closed on 80 that conflict withmainand shareDraw.cpp,State.cpp,State.hppor the AGC debt file. None of them adds a GCN CMASK tile order.materializeGcnCmaskClearexists only in #18177. #11825 also passespipeBankXorto the surface layout insidestoreCmaskClearTexels, which this PR moves to the caller. A merge keeps the AGC caller oncolor.pipeBankXoronce #11825 lands.Tested
Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON; NVIDIA GeForce RTX 4080 SUPER, driver 621.14.agc_gcn_color_target(GcnCmaskTileOrder), with expectations worked out by hand from the addrlib lines above:CMASK_IS_LINEARdecodes.agc_driver_gcn_fast_clear_color_target(512x512 Thin2D RGBA8,CMASK_SLICE15, fast clear eliminate):CMASK_SLICE7.main(3ca7e584c9f), the new execution test fails at the partial case with #18177's own refusal. The CPU test does not build there, sinceGcnCmaskLayoutdoes not exist.AGENTS.md validation:
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, with LunarG layer 1.4.363.1 throughVK_ADD_LAYER_PATH.ctest -R '^(agc_gcn_color_target|agc_driver_cmask_fast_clear|agc_driver_gcn_fast_clear_color_target|agc_driver_gcn_eqaa_color_target|agc_driver_gcn_color_array_slices)$' -V, on #18177's head merged withmain(3ca7e584c9f) and on this branch.Insert instance layer "VK_LAYER_KHRONOS_validation", nowas not found but was requested by env var VK_INSTANCE_LAYERS, nofailed to loadand 0VUID-lines.Bloodborne (CUSA00900 01.09, my own copy) on the machine above. The tree is
mainf2a25e5b42a+ #17105 + #17711 + #20156 + #18177 + #21944 + #21969 + #21977 + #22033 + #22060 + #22076 + this PR. I ran 3 runs of about 4 minutes each with injected pad input:AGC graphics: nonstandard pixel center or vertex quantization is unsupported(PA_SU_VTX_CNTLother than 0x2d,State.cpp). That is a separate issue.2c7b3fc4:agc_driver_gcn_fast_clear_color_targetandagc_gcn_color_targetpass on Vega (gfx900, GCN5), an RDNA2 GPU (gfx1036), an RDNA3 GPU (NAVI31) and lavapipe, with the Khronos layer 1.4.363,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1and 0VUID-, including the partial-tile case (comment).2c7b3fc46bmerged onto maind89f26516c: Linux 7.3.4, GCC 16.2.1, Mesa 26.2.6 RADV, RX 7900 XT (gfx1100) and 7800X3D iGPU (gfx1036), Khronos layer 1.4.363.1. Full suite and-R '^agc'with the layer: no new failures against main on either GPU, the layer loads in every run, and there are 0VUID-and 0SYNC-HAZARDlines.2c7b3fc46bmerged onto mainfbaae8a79d: Arch Linux, GCC 16.2.1, RTX 4090 (Ada), NVIDIA 620.70.06, Khronos layer 1.4.363.1. The five focused tests pass 5 of 5 (main 4 of 4; the new test is not on main), the layer loads, and no log has awas not foundorVUID-line. With main'sDraw.cppthe new test fails withCMASK size differs from the color target's CMASK layout.2c7b3fc46band on #18177's head79fee62a8d, each merged onto main223cc23237: Arch Linux 7.2.15, GCC 16.2.1, Intel UHD Graphics (Raptor Lake-S, Mesa 26.2.5 ANV) and RTX 3050 Laptop (Ampere GA107, NVIDIA 615.78.08), Khronos layer 1.4.363. The five focused tests pass 5/5 in 3 runs per GPU on both arms, the layer loads, no log has awas not foundorVUID-line, and the partial-tile case runs on both GPUs.2c7b3fc46bmerged onto mained1def4dd4: Windows 11 23H2 (22631), Ryzen 7 5700X, RTX 4060 (driver 616.56), WinLibs GCC 15.2.0 r7, Release.agc_driver_gcn_fast_clear_color_targetpasses; of the 1282 tests the change reaches, the only failures are ones main also has on this GPU (#23232, #23711). No validation layer was installed, so this run does not coverVUID-errors.ca70c588503(main859a238b8c, 2026-11-29):State.hppconflicted with main's newfmaskCompressionfield; both fields kept. The debt-file edit moved into this PR's fragment (debt_fold.py --checkpasses). Windows 11, WinLibs GCC 15.2.0 r7, RTX 4080 SUPER:agc_driver_gcn_fast_clear_color_targetandagc_gcn_color_targetpass withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1and the Khronos layer, 0VUID-lines, nowas not foundline.b6511ed728c(CodeRabbit,Draw.cppL721): a 2D thin target with no cleared tile of its own now records a proof that names its extent, so a larger target over the same unchanged CMASK still clears its own tiles. New execution case: a 128x128 target over a 2048-byte CMASK whose only cleared nibble is tile (32,0) of a 512x512 target, then that 512x512 target. Windows 11, WinLibs GCC 15.2.0 r7, RTX 4080 SUPER,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1and the Khronos layer:agc_driver_gcn_fast_clear_color_targetandagc_gcn_color_targetpass, 0VUID-lines, nowas not foundline. Withca70c588503'sDraw.cppthe new case fails:did not store the clear color in tile (32,0) alone: 64 texels differ.6be2244aa83(CodeRabbit,Draw.cppL733): materializing a fast clear of a 2D thin target now expands only the CMASK nibbles of the tiles it cleared, and the proof and the draw-time CMASK checks use the target's extent, so a tile outside a smaller target keeps its clear for a larger one. New execution case: a 2048-byte CMASK clearing tiles (0,0) and (32,0), a 128x128 target, then a 512x512 target. Windows 11, WinLibs GCC 15.2.0 r7, RTX 4080 SUPER,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1and the Khronos layer:agc_driver_gcn_fast_clear_color_targetandagc_gcn_color_targetpass, 0VUID-lines, nowas not foundline. Withb6511ed728c'sDraw.cppthe new case fails:did not store the clear color in tile (32,0) alone: 64 texels differ.6be2244aa8merged into main: full ctest suite on GitHub-hosted Windows Server 2022 and Windows Server 2025, WinLibs GCC 15.2.0 (run). No failure that main does not also have on the same runner. The runners have no GPU, so this does not cover the changed GPU paths orVUID-errors.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T02:12:11Z.
Review: COMMENTED
Reviewed — comments
Materialization of a whole-surface GCN fast clear may use the wrong pixel layout when it falls back to writing guest memory for a 2D-tiled target.
What I ran
Inspected the prepared diff and targeted source at head
2c7b3fc46b0ad05198fd0c062b6b5e17ccc23ec1usingrepo_read.py; no commands or tests were run.Results
Findings
Blocking
None verified.
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp:736constructs the fallback surface layout withoutcolor.pipeBankXor, unlike the partial-clear path at line 725. For 2D-tiled GCN targets,DecodeGcnColorBufferderives a pipe bank XOR for the slice. IfclearToTexelcannot fill a resident texture, the fallback writes texels using an un-swizzled layout, which may place the clear color in incorrect guest-memory locations. Consider passingcolor.pipeBankXorhere as well.Not verified
No tests or build were run. The description's reported test results were not independently verified. Reviewed the supplied description, commits, manifest and diff, plus targeted portions of
State.cppandDraw.cpp. The manifest indicates full text was included for changed files; the excluded-file list was not available in the prepared bundle.To get this to a good state
Nothing is required. Optional: use the same pipe bank XOR in the whole-surface fallback and add a regression case that exercises it when resident filling is unavailable.
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-22T11:54:49Z.
Review: APPROVED
Windows check of head
2c7b3fc46b(with #18177's commits it carries) on an AMD and an NVIDIA GPU, with GCC 16 and the validation layer, merged ontomain7eb79b0c48(clean merge). The Windows runs so far were an RTX 4080 SUPER and an RTX 4060 without the layer, so this adds an AMD GPU on Windows.Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release full build, run from PowerShell withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. GPUs, each picked withANYPS5_GPU: NVIDIA GeForce RTX 5070 Ti (621.01) and the Ryzen 7 7700X's integrated AMD Radeon (1002:164e, Adrenalin 26.10.2). This was built together with #24960, which touches other files.ctest -R '^(agc_gcn_color_target|agc_driver_cmask_fast_clear|agc_driver_gcn_fast_clear_color_target|agc_driver_gcn_eqaa_color_target|agc_driver_gcn_color_array_slices)$':mainThe fifth test is
agc_driver_gcn_fast_clear_color_target, which runs on both GPUs, none skipped. NoVUID-lines on either side, and no "was not found but was requested" layer lines.Red check: with the first pipe bit of
GcnCmaskLayout::Nibbletaken without thex1term (x0 ^ y0 ^ x1→x0 ^ y0, so the CMASK nibbles land on other tiles), bothagc_gcn_color_targetandagc_driver_gcn_fast_clear_color_targetfail on the Radeon. The latter fails with "the fast clear eliminate of a 2D thin GCN target whose CMASK clears nibbles 0, 1, 2, 512 and 2048 did not store the clear color in tiles (0,0), (1,1), (2,3), (1,0) and (4,0) alone". So the execution case pins the tile order, not just the CPU expectations.Not run: Linux, Intel, and Bloodborne itself (I don't have it).
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T06:17:10Z.
Review: COMMENTED
Actionable comments posted: 1
1d238acb-23dc-4cf0-ae6b-621830f0e3c0Reviewing files that changed from the base of the PR and between
859a238b8candca70c58850.core/libs/prx/libSceAgcDriver/Graphics/include/ColorTargetLayout.hppcore/libs/prx/libSceAgcDriver/Graphics/include/State.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ColorTargetLayout.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/GcnColorTarget.cppcore/libs/prx/libSceAgcDriver/tests/execution/GcnFastClearColorTarget.cppdocs/dev/debt/changes/claude-gcn-partial-cmask-clear.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T06:23:48Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected changes shows a concrete defect, and the available evidence supports the targeted GCN CMASK behavior.
What I ran
ca70c588503ce14e1977dc53bfdb818799116a4ausingrepo_read.pyto read the prepared diff, manifest, and targeted sources.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
reviewedin the manifest were read. The review bundle did not exposefiles.json; the manifest lists these eight changed files as included. Relevant portions of the diff and targeted implementation and test ranges were inspected; unrelated portions of the large new execution test were not read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T07:16:04Z.
Review: COMMENTED
Actionable comments posted: 1
178558c0-2537-4ba5-badb-eec22260f4d8Reviewing files that changed from the base of the PR and between
ca70c58850andb6511ed728.core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/execution/GcnFastClearColorTarget.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T07:17:52Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and inspected test coverage support merging.
What I ran
Reviewed head
b6511ed728ca437a59ade99c354cf19115e40033usingrepo_read.pyagainst the prepared review bundle and repository files at that pinned head. No commands or tests were run in this review environment. The description reports focused Vulkan checks on this head; those results are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
Read
ColorTargetLayout.hpp,State.hpp,ColorTargetLayout.cpp,Draw.cpp,State.cpp,GcnColorTarget.cpp,GcnFastClearColorTarget.cpp, andclaude-gcn-partial-cmask-clear.md. The diff and manifest were also read. The changed production code decodes the linear CMASK flag, models the documented GCN tile order, handles partial materialization only for supported 2D layouts, and refuses unsupported cases. The execution tests cover partial tiles, code interpretation, undersized slices, array slices, and the proof-scope regression described in the PR.Not verified
No tests were run during this review. Console behavior and changes excluded from the prepared bundle were not verified; the manifest lists no excluded changed files.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T08:27:16Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
6be2244aa832ad017c52d5cd83e51b6928967b6b. No commands or tests were run in this review; test outcomes below are reported in the PR description. I read all eight changed files listed in the manifest:ColorTargetLayout.hpp,State.hpp,ColorTargetLayout.cpp,Draw.cpp,State.cpp,GcnColorTarget.cpp,GcnFastClearColorTarget.cpp, andclaude-gcn-partial-cmask-clear.md. The manifest shows all eight are included; no changed files were excluded. The review folder’sfiles.jsonwas unavailable through the reader.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not independently run the build, tests, GPU validation, or Bloodborne. The reported test runs and outcomes in the description were not independently confirmed. The description reports these supported limitations: partial fast clears for 1D or linear targets, linear CMASKs, and undersized CMASK slices remain unsupported.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-29T10:08:00Z.
Review: APPROVED
Follow-up on Windows for head
6be2244aa8, covering themainmerge and both CMASK fixes made after my approval of2c7b3fc46b.Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release full build, run from PowerShell. Merged ontomain1c99516e94(clean merge). NVIDIA RTX 5070 Ti and the Ryzen 7700X integrated Radeon (1002:164e, AMD driver 32.0.21045.29003).ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(1.4.363),VK_LOADER_DEBUG=layer.tools/check_conventions.py --base upstream/mainandtools/debt_fold.py --checkpass.^(agc.*gcn.*|agc.*cmask.*|agc_driver_graphics)$(27 tests, includingagc_driver_gcn_fast_clear_color_target,agc_gcn_color_target,agc_driver_cmask_fast_clearandagc_driver_graphics): 27 of 27 in 3 of 3 runs on each GPU. Every Vulkan test's log shows the layer inserted, and there are noVUID-lines.6be2244aa8: reversing itsDraw.cpphunks failsagc_driver_gcn_fast_clear_color_targeton both GPUs withthe fast clear eliminate of a 512x512 2D thin GCN target, after a 128x128 target materialized tile (0,0) of the same CMASK, did not store the clear color in tile (32,0) alone: 64 texels differ.b6511ed728: also reversing itsDraw.cpphunks fails the same test on both GPUs at the earlier case,over a CMASK whose only cleared tile (32,0) lies outside a 128x128 target that used it first.The
State.hppmerge keeps bothcmaskLinearandmain'sfmaskCompression, andoperator==compares both. Proof matching stays conservative: a proof scoped to one target extent satisfies only a query with the same extent, and a query without an extent (thematerializepath atDraw.cpp:773) accepts only a whole-range proof.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:13:31Z.
Review: COMMENTED
The trial merge onto
a1b75b0947was clean. I checked how the mixed-CMASK path gates tile materialization on the GCN tile layout. The fixture checks selected interleave nibbles and includes the case where a small aliased target must leave an out-of-extent clear available to a larger target. Please keep that case when reconciling other fast-clear changes. Paired graphics and color-target 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.