feat(agc): fast clear the CMASK of array and layered color targets #11825
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11825"
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-27T08:55:34Z.
What
Carried from #8065 by @ArielWolle (closed by the open PR limit, not on its merits).
Fast clears the CMASK of array and layered color targets instead of throwing
CMASK fast clears of a 3D or array color target are unsupported. Each layer is cleared through its own CMASK slice: the color address, the CMASK address and the pipe-bank XOR are offset per slice, the CMASK range check covers every layer, and the written-buffer ranges cover all layers. A 3D color target and a slice or array of a mipmapped target still throw, as recorded in the technical debt entry. The per-slice CMASK stride follows Addrlib's slice size and has not been measured on hardware.The branch is the author's three commits on current
main. The layered-draw commits it was stacked on (#7254) are already inmain. It still contains the two commits of #7668 (CMASK offset of a color target slice), which is open: if #7668 merges first they apply as empty, and if this merges first #7668 has nothing left to add.Two commits of ours: a merge of
main, and one that moves the pipeline journal'ssizeof(State)guard from 912 to 928 bytes, becauseColorTargetgainedcmaskSliceandcmaskSliceBytes. Both only address a draw's CMASK data; the recipe codec andCanonicalPipelineStatecopy just the pipeline-relevant color target fields, so no recipe format changes.Tested
main12686b52de:agc_driver_graphics,agc_driver_cmask_fast_clear,agc_driver_layered_array_color_draw,agc_recorder_cmaskandagc_driver_graphics_maps_fallbackpass.tools/check_conventions.pywith this title and body passed. A full local CI run (cilocal.py ci: configure, build,libs,select_tests.py ctest) on the head ran 2517 tests with 0 failures and 0 errors; 29 were skipped, among thempad_sdl, which skips because this host has a joystick attached (its own message: "SDL sees 1 host joysticks"), so the run's skip check flags it. Not run: Windows, macOS.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 (none added).mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T09:24:23Z.
Review: CHANGES_REQUESTED
I reviewed the per-slice CMASK address path, the CPU materialization loop, and the added layout/graphics tests. The Windows product job passes, as do conventions, eligibility, intake, labels, and the progress report. The author reports focused GPU runs and a 2,517-test Linux suite; I could not run those locally because this environment has no usable GPU runtime.
Before approval, the required AGC validation from CONTRIBUTING is still missing from the report: run the same focused tests on
mainand this change, on the same GPU/machine, withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1, andANYPS5_REQUIRE_VULKAN=1underctest -V; confirm the requested layer was found and compare anyVUID-errors. The current PR body reports results on the change but does not include that paired validation-layer run.The branch is also based on
5bc84038c490a0427ff272e39e2a1cdf6fdc3c0e, while current upstreammainis801d5b9bc11049e6274daca09d70690bd5b8d0a9. Please update and retest against currentmain. Finally, the body says this branch includes two commits from still-open #7668 and that either PR could land first; please get the overlapping authors' agreement on landing order and record the dependency accordingly, as CONTRIBUTING requires. I request changes for these validation/readiness gaps, not because I found a confirmed CMASK calculation defect.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T06:11:18Z.
Review: DISMISSED
Reviewed — changes requested
The decode, stride and per-layer split work and the focused tests pass on a clean merge, but the CPU fast-clear path writes the cleared tiles of every slice except slice 0 to the wrong texels, because it drops the slice's pipe-bank XOR.
What I ran
6e05e5763ebeaab817ad3baca00de8d3c44ac8a6main:2960e9a6e7e1fc99c4ed180c71495b5eb83464c7main+ head,--no-ff, no conflicts):7b90366b84d107024ba9429f2cbfc408630b2dd7Results
maingit diff --checkcheck_conventions.py[debt-length]on the CMASK fast clears entry (2586 characters; it was 1554 onmain)main, validation layer onVUID-lines (merged /main)was not found but was requested by env var VK_INSTANCE_LAYERSVK_LAYER_KHRONOS_validationin bothMerged tree ctest
main ctest
This is the paired validation-layer run that the earlier review asked for (that review was on
45e34f8cd6). It shows noVUID-lines on either side. That review's base-branch point is also settled: the head merges cleanly onto the currentmain.Negative control
Restoring every production file from
maindoesn't compile, because the tests useNibble's third argument andColorTarget::cmaskSliceBytes. ycbuzi's Windows run reported the same. Instead, I reverted one production behaviour at a time and kept the tests:materializeCmaskClearalways callsmaterializeCmaskClearOfonce (no per-layer split)agc_driver_layered_array_color_draw_testsCmaskLayout::Nibbleignoressliceagc_driver_graphics_testscmaskSliceOffsetforced to 0 inDecodeColorBufferagc_driver_graphics_testsNone of these tests catches the bug below.
Findings
Blocking
1. A partial CMASK clear of slice ≥ 1 writes the clear value into the wrong 8x8 tiles.
storeCmaskClearTexels(core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp:443) builds its layout asColorTargetLayout(width, height, tileMode, elementBytes), sopipeBankXorfalls back to its default of 0. The change computes each slice's XOR, inmaterializeCmaskClear(one.pipeBankXor ^= ColorSliceXor(...), Draw.cpp:526) and for a plain slice inDecodeColorBuffer. The CPU path never reads that value.storeSingleTexelsdoes passcolor.pipeBankXor(Draw.cpp:319).An array resident has more than one layer, so
StorageTexture::ElementView()returnsVK_NULL_HANDLEfor it and the GPUrecordCmaskClearpath is never taken. Every array or layered fast clear therefore goes through this CPU path. When the CMASK is fully cleared the error doesn't show, because the whole slice is filled. When it is partly cleared, the clear lands on other texels of the slice than the cleared tiles.The new
RunCmaskCleartest can't see this. It compares the two-layer view with the single-slice view of the same slice (LayeredArrayColorDraw.cpp L280-L288), and both go through the same CPU path. It also checks only the number of cleared texels, not where they are.Evidence: I added a probe to the test locally. For each slice of the four-slice SW_64KB_R_X array, it (a) draws through a single-slice view with the scissor limited to one 8x8 tile and records which 32-bit words of the slice change, then (b) marks only that tile cleared in the slice's CMASK, runs the fast-clear materialization through the same single-slice view, and records which words change.
With the one-line fix below, every row prints
same=1. The PR'sagc_driver_layered_array_color_drawandagc_driver_cmask_fast_cleartests still pass with that fix.Suggested fix: pass
color.pipeBankXoras above. Also extendRunCmaskClear(oragc_driver_cmask_fast_clearwith a real slice XOR) to compare the cleared texels against where a draw writes the same tile, or againstColorTargetLayout(..., pipeBankXor).Offset(x, y), so that the test fails without the fix. The fix also covers the CPU fallback for a plain slice (arrayLastSlice == 0, slice ≠ 0), which this PR (with #7668's commits) newly lets through, and a non-zero base XOR taken from the surface address.Probe added to LayeredArrayColorDraw.cpp (local only)
Non-blocking
2. The one-fragment CMASK code check still reads the slice-0 nibbles. In
readCmask, thecoverageSamples > samplesloop (core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp:417, permalink) still callslayout.Nibble(tileX, tileY), while the loop below it now passescolor.cmaskSlice. For slice ≥ 1 of a single-sample, multi-coverage target, it checks the codes at the slice-0 positions. On a small target those can be padding nibbles, so it can throw on leftover values or miss a real code. Passcolor.cmaskSlicethere too.3. Debt entry length.
check_conventions.pywarns that the CMASK fast clears entry indocs/dev/debt/libSceAgcDriver.mdis 2586 characters, over the 1000-character guideline; it was already 1554 onmain. The new text could be shortened to the gap: the per-slice stride and Z-bit XOR follow Addrlib and are not verified on hardware, and a 3D target or a slice or array of a mipmapped target throws.4. Landing order with #7668. The body lists #7668 under Depends on, and that PR is still open. The fix for finding 1 also applies to the plain-slice CPU path that #7668's commits enable, so whichever PR lands first should carry it.
Not verified
libstarget. I built and ran only the AGC targets the change touches.To get this to a good state
color.pipeBankXorto theColorTargetLayoutinstoreCmaskClearTexels.ColorTargetLayout(..., pipeBankXor).Offset.color.cmaskSlicein the one-fragment code check and shorten the debt entry.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T19:52:08Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
This pull request does not merge cleanly into
main(128b5c49ba): head86a4136de4conflicts incore/libs/prx/libSceAgcDriver/Graphics/src/PipelineJournal.cppcore/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cppPlease rebase it onto current
main. I will review the change once it merges cleanly.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-04T00:07:03Z.
Review: APPROVED
Re-checked — approved
Since my last review,
storeCmaskClearTexelsbuilds its layout with the slice's pipe-bank XOR, the one-fragment CMASK check reads the slice's own nibbles, and a new tile-against-draw test fails without the fix. The debt entry is also shorter, and theStatesize guard is updated for the merge ofmain.What changed since my last review
I last reviewed
6e05e5763e. The branch was rebased onmainsince then: the layered-draw commits of #7254 were dropped and the six CMASK commits were replayed. The new commits are:a01df997c0passescolor.pipeBankXorto theColorTargetLayoutinstoreCmaskClearTexels, andcolor.cmaskSlicetoNibblein the one-fragment loop ofreadCmask.c5b40a544cshortens the CMASK fast clears debt entry.86a4136de4addsRunTileClearMatchesDrawtoLayeredArrayColorDraw.cpp. It checks slices 0 to 3 at tiles (5,3) and (0,0), and compares the words that a scissored 8x8 draw writes with the words that a fast clear of the same tile writes.55f2963f98mergesmain. It keeps the eighth push constant (slice) inDispatchCmaskClearwith theResolveddispatch calls frommain.c32f9d09d9moves thesizeof(State)guard from 936 to 952.mainalready had 936, and the two newColorTargetfields add 16 bytes.What I ran
c32f9d09d9ccecbee8dc9fba06dbe8bf8973614cmain:1c8c0efc8c41314402e6966da5bef6ea3d639d100c625f6e8d16df8d9ab1994e89deb8c6597d5cb2git diff --checkcheck_conventions.py[debt-length]warning is gonelibs(script)mainVUID-lines are inagc_driver_image_gather_volume, a test that did not run on the baselinemain. This PR does not touch samplers, so I do not count them against it.VUID-lines, nowas not found but was requestedRunTileClearMatchesDrawtile clear against draw: 8 cases, 0 differgit status --porcelainemptyFocused run, merged tree
Negative control
I removed only the
color.pipeBankXorargument fromstoreCmaskClearTexels(core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp:570) and kept the new test.agc_driver_layered_array_color_drawthen fails. Every case of slices 1 to 3 differs, and slice 0, which has no XOR, still passes. This matches the probe in my previous review and the author's RTX 4090 result.Output with the fix reverted
After restoring
Draw.cppfrom the merged tree and rebuilding, the test passes again.Previous findings
storeCmaskClearTexelsnow passescolor.pipeBankXor. The newRunTileClearMatchesDrawchecks where the cleared words land, not only how many there are, and it fails without the fix (control above).readCmasknow callsNibble(tileX, tileY, color.cmaskSlice). No test exercises this loop with slice ≥ 1, but the change is the same one-argument change the second loop already had.check_conventions.pyno longer warns. The entry now starts with the gap: what is unverified on hardware and what throws.Depends on: #7668 (open)and that either PR can land first. The XOR fix now lives in this PR, so if #7668 lands alone, its plain-slice CPU path would lack the fix until this PR lands. The discussion records no agreement with that PR's author.New findings
Blocking
None.
Non-blocking
None. On this lavapipe machine,
agc_driver_graphics(34.2 s) andagc_driver_graphics_maps_fallback(36.1 s) run over 30 s even without the validation layer. This PR only adds a few CPU-sideDecodeColorBuffercalls toGraphics.cpp, and the NVIDIA CI comment on86a4136already flaggedagc_driver_graphics_maps_fallbackat 35.5 s. I therefore count the duration asmain's, although I did not timemainhere. The PR's test changes do not compile againstmain's production files, so I could not time them in isolation.Not verified
agc_driver_graphics*tests onmainon this machine, so the 30 s overrun is attributed tomainby inference only.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T08:56:05Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review covered the changed implementation and tests, and no verified blocking defect was found.
What I ran
Reviewed head
ca2b7cc278ea7c1cae3737a5799e1da182f21393usingrepo_read.pyagainst the prepared diff and repository files. No commands or tests were run during this review; test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
core/libs/prx/libSceAgcDriver/tests/Graphics.cppwas excluded from the review folder due to size; I read the changed test region throughrepo_read.py. No tests were run. Windows, macOS, and physical-console behavior were not verified in this review. Other excluded files listed inreview/manifest.jsonwere not present; the manifest lists onlyGraphics.cppas excluded by size.Files read:
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/WrittenBuffers.cpp,core/libs/prx/libSceAgcDriver/Graphics/include/ColorTargetLayout.hpp,core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp,core/libs/prx/libSceAgcDriver/Graphics/include/TextureDetiler.hpp,core/libs/prx/libSceAgcDriver/Graphics/shaders/CmaskClear.comp,core/libs/prx/libSceAgcDriver/Graphics/src/ColorTargetLayout.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/PipelineJournal.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp,core/libs/prx/libSceAgcDriver/tests/CmaskFastClear.cpp,core/libs/prx/libSceAgcDriver/tests/ColorTargetLayout.cpp, the changed region ofcore/libs/prx/libSceAgcDriver/tests/Graphics.cpp,core/libs/prx/libSceAgcDriver/tests/execution/LayeredArrayColorDraw.cpp, anddocs/dev/debt/libSceAgcDriver.md.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:56:38Z.
Review: COMMENTED
The trial merge conflicts in draw/state tracking, the pipeline journal and layered-array test code. The slice-relative color offset and CMASK nibble/XOR selection need the same nonzero base-layer test. Please retain a view starting after slice zero and check that both neighboring slices keep their original color and metadata after eliminate. Please put the direct AGC debt edit in a fragment. I have no paired Vulkan result for this conflicted head.
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.