fix(agc): offset the CMASK of a plain color target slice by its slice #7668
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7668"
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 ArielWolle on 2026-10-18T21:24:55Z.
What
A color view that selects slice N of a single-sample, single-mip 2D color target (
CB_COLOR_VIEWslice start N, the surface itself without an array depth) with CMASK fast clear enabled threwCMASK fast clears of a 3D or array color target are unsupported. The decode moves the color address by N slices (ComputeSurfaceSizeper slice) but kept the CMASK register's address.The CMASK of slice N is now read N whole-slice CMASKs after the CMASK register (
slice * totalBlocks * CmaskLayout::Alignment, the same block count the base mip 0 path already computes). The color address, the CMASK range check and the clear itself then follow the slice. The slice also goes into the in-block swizzle: AMD Addrlib'sHwlComputeCmaskAddrFromCoord(Mesamesa-25.2.0) passes it as the pattern's Z coordinate, and the pipe-aligned 16-pipe pattern puts Z0..Z3 into nibble bits 12, 11, 10 and 9.CmaskLayout::Nibbletakes the slice and XORs it in, on the CPU path and in the clear shader (CmaskClear.comp, push constantslice). A uniform CMASK reads the same at every slice. Still throwing: a 3D target, a target with an array depth (CB_COLOR_ATTRIB3MIP0_DEPTH), and a slice of a mipmapped target. Multisampled targets keep their own CMASK per slice.Why this layout: PPSA34063 (NHL 27) binds one base register and one CMASK register for all six slices of a 512x512, 8-byte-texel target and selects the slice in
CB_COLOR_VIEW. The color of slice 1 lies 2 MiB after the base (one slice of that surface). The CMASK memory behind the register holds six consecutive 4 KiB blocks, all expanded (0xF), then zeros. That is one 4 KiB block per slice, which is the stride used here. The stride and the swizzle come from Addrlib and the register values and memory, not checked on a console; the debt file says so.Tested
Windows 11 (build 26200), MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 3070, driver 617.42.
cmake --build build-nhl --target agc_driver_graphics_tests, thenagc_driver_graphics_tests.exewithbuild-nhl/core/libs/libs/unpatchedfirst onPATH: ends withGraphics validation tests passed. New cases incmaskTests: slice 0 keeps the CMASK register address; slice 2 of a 64x4 target decodes at register + 2 blocks; slice 1 of a 1024x1024 target (two blocks per slice) decodes at register + 2 blocks with a two-blockcmaskBytes; a slice of a mipmapped target still fails withslice of a mipmapped. The existing array and volume rejections still pass. Run on48d61f53b;State.cppis identical on currentmain(0d1c299a9), and the patch applies to it without changes.agc_driver_graphics_testspasses, andagc_driver_cmask_fast_clear_tests(withANYPS5_REQUIRE_VULKAN=1) passes with new runs that clear partial CMASKs of slices 1, 2, 3 and 8 through the draw and eliminate paths.ColorTargetLayout.cpppins 14 nibbles for slices 1-15, evaluated from the Mesa pattern text, not from this code; the slice 0 values reproduce the existing references. With the shader's XOR removed the CMASK test fails at slice 1.python tools/check_conventions.py --base origin/main: all checks passed.layered draws into a color view of several array slices are unsupported), which this PR does not touch. The title was run with a local video output switch that is not part of this change.agc_driver_cmask_fast_clear_tests, not by the title.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)Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T22:33:49Z.
AMD run, since the description covers an RTX 3070. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. Build:main8a456334fwith #7677, #7673, #7671, #7666, #7676, #7675, #7672, #7668, #7664 and #7658 merged together (each merge clean, built once).The build is clean and
agc_driver_graphics, which holds this PR's new checks, passes 3 runs of 3.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T01:24:00Z.
The per-slice stride matches AMD Addrlib: Mesa
mesa-25.2.0src/amd/addrlib/src/gfx10/gfx10addrlib.cpp:355and:610(addr = sliceSize * slice + ...).But Addrlib also passes the slice into the in-block swizzle (
:598-603). The pipe-aligned 16-pipe CMASK pattern (gfx10SwizzlePattern.h:5484→ pattern 4 at:5986) hasX3^Y3^Z3, Z2^X4^Y4, Z1^Y5^X6, Z0^X5^Y6in nibble bits 9-12.CmaskLayout::Nibbleis that pattern with Z=0, and this PR keeps it for slice N.Evaluating the pattern:
Could slice > 0 either XOR the slice's Z bits into bits 9-12, or require the slice's CMASK block to be uniform until that is checked?
The tests pass for me on Windows (RTX 5070 Ti and AMD RDNA2 iGPU) and on Linux (gcc 13.3). On
maina373e85e5they fail withCMASK fast clears of a 3D or array color target are unsupported.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T06:35:40Z.
Intel and AMD Windows data:
agc_driver_graphicsfails onmainand passes with this PR, on an Intel UHD 770 and an AMD RX 9070 XT.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. This headc075d28f2merged intomain07377573f. "Without" means this PR's test files onmain07377573f, with none of its other changes.tests/Graphics.cppagc_driver_graphicsfails:CMASK fast clears of a 3D or array color target are unsupportedI also ran full CTest with this PR and the 13 other open AGC and shader PRs I tested in the same batch merged together (#7659, #7504, #7432, #7426, #7413, #7480, #7465, #7466, #7464, #7449, #7489, #7673, #7560). Neither GPU showed a failure beyond
main's own: the five image-table tests (#6647) andagc_driver_sample_multisample_target(#6957) on the UHD 770, andagc_driver_layered_volume_vertex_no_gpl(#4768) on the RX 9070 XT.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ArielWolle on 2026-10-19T13:28:51Z.
Thanks, you're right. I checked it against the Mesa source before changing anything:
Gfx10Lib::HwlComputeCmaskAddrFromCoord(mesa-25.2.0,gfx10addrlib.cpp) passespIn->sliceas the Z argument ofComputeOffsetFromSwizzlePatternand also addssliceSize * slice.GFX10_CMASK_SW_PATTERN(the 16-pipe, pipe-aligned entry) has nibble bits 9-12 =X3^Y3^Z3,Z2^X4^Y4,Z1^Y5^X6,Z0^X5^Y6.CmaskLayout::Nibblewas that pattern with Z fixed at 0.Pushed 355e85a99:
CmaskLayout::Nibble(tileX, tileY, slice)XORs the slice's low four bits into nibble bits 12, 11, 10 and 9. Slice 1 moves every tile by 0x1000, slice 2 by 0x800, as you computed.ColorTarget::cmaskSlicecarries the slice fromDecodeColorBufferto the CPU path (readCmask).CmaskClear.comp) had its own copy of the equation, so the slice is now a push constant there too. The two paths agree.Tests:
ColorTargetLayout.cpppins 14 nibbles for slices 1-15. I evaluated them from the pattern text in Mesa, not from our code. The slice 0 column reproduces the existing references, so the evaluation matches what we had. It also checks that tiles still don't alias for several slices.CmaskFastClear.cppnow clears partial CMASKs of slices 1, 2, 3 and 8 through the draw and eliminate paths. With the shader's XOR removed, it fails at slice 1.agc_driver_graphics_testsandagc_driver_cmask_fast_clear_testspass on Windows (RTX 3070, GCC 15.2). I haven't run Linux or AMD.Still unverified on a console: what the PS5 writes for a slice above 0. The stride and the swizzle both come from Addrlib, and the debt entry says so.
Why my tests missed it:
ColorTargetLayout.cppand the GPU test inCmaskFastClear.cpponly ever used slice 0, becauseNibblehad no slice input. They were correct for Z = 0 and said nothing about other slices.cmaskAddress,cmaskBytes). None of them read a mixed CMASK of a slice above 0, which is the only case where the swizzle matters.HwlComputeCmaskInfo). I never readHwlComputeCmaskAddrFromCoord, where the slice also goes into the pattern.AI-assisted: yes (GitHub Copilot).
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-19T13:40:07Z.
Rechecked 355e85a99 (the slice XOR) on AMD's Windows driver. Radeon 860M (RDNA 3.5,
1002:1114), driver 32.0.13058.8001, Windows 11, WinLibs GCC 15.2.0, Release,ANYPS5_NO_SHADER_CACHE=1. Head merged intomain5eba12d6b(clean merge).main'sCmaskClear.compagc_driver_cmask_fast_clearSW_64KB_R_X slice 1 partly fast-cleared target drawn over its left part: texel (32, 0) holds 287454020agc_driver_graphicsSo the new slice cases cover the GPU clear's XOR on this driver as well. A full revert to
main's sources doesn't build, since the tests usecmaskSliceand the three-argumentNibble.Separately, with
APS5_NO_GPL=1agc_driver_cmask_fast_clearstill fails here at the existingSW_64KB_R_Xcase (texel (0, 0) holds 1515870810), as onmain. That's #7875's open entry and doesn't come from this change.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T23:11:30Z.
I rechecked the slice XOR from 355e85a99 (head
5fd2541ce). The point I raised is fixed.Against Mesa. I evaluated
GFX10_CMASK_SW_PATTERNrow 4 directly from the text ofmesa-25.2.0src/amd/addrlib/src/gfx10/gfx10SwizzlePattern.h:5986:X3, Y4, X6, Y6, X7, Y7, X8, Y8, X9, X3^Y3^Z3, Z2^X4^Y4, Z1^Y5^X6, Z0^X5^Y6, with Z =pIn->sliceasgfx10addrlib.cpp:598-603passes it, and 8192 nibbles per 4 KiB block.cmaskSliceReferencesand the 5 existing slice 0 references, 19 of 19.CmaskLayout::NibbleandCmaskClear.compapply.Tests. Windows 11 Home 26300, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON,main9127ea36dwith this head merged. GPUs: RTX 5070 Ti (NVIDIA 617.42) and the AMD Radeon iGPU (RDNA2,1002:13c0, AMD proprietary driver 2026.04.17,ANYPS5_GPU=AMD). Run withANYPS5_REQUIRE_VULKAN=1. On both GPUs, 12 tests pass:agc_driver_graphicsandagc_driver_cmask_fast_clear;uint8x4color target tests.Negative controls:
offset ^= ...slice...line removed fromColorTargetLayout.cpp,agc_driver_graphicsfails withCMASK nibble of a slice differs from addrlib's, which passes the slice into the swizzle pattern.CmaskClear.comp,agc_driver_cmask_fast_clearfails on both GPUs withSW_64KB_R_X slice 1 partly fast-cleared target drawn over its left part: texel (32, 0) holds 287454020. This is the same failure @LeandroLP23 got on RDNA 3.5.Linux. WSL Ubuntu 24.04, GCC 13.3, llvmpipe (Mesa 25.2.8), with this head and six other open AGC and shader PRs merged into
main9127ea36d.agc_driver_graphicsandagc_driver_cmask_fast_clearpass.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T08:56:59Z.
Taking this over so it can merge ahead of the layered CMASK work that builds on it (#8065). We'll do the rebase onto current main and review it under the normal process; your commits and credit stay as they are.
Imported from boykopovar/AnyPS5. Originally posted by ArielWolle on 2026-10-20T17:57:42Z.
Rebased onto the latest
mainand pushed. @oneandonlydean, could you take another look when convenient?Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T23:04:59Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The per-slice CMASK offset and the slice XOR into the swizzle work and are covered by tests. Both new tests fail when the production code is restored from
main. One call site inreadCmaskstill reads slice 0 nibbles.What I ran
Head
a40a71c16f9f4ab5b5a2171b2385a9e105f3e0a2merged intomain1c8c0efc8c41314402e6966da5bef6ea3d639d10(merged treeb1e2afab4047edfea25a40224086169fa3436ac1). Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6, LLVM 19).Results
git diff --checkcheck_conventions.py[debt-length]ondocs/dev/debt/libSceAgcDriver.md:249(2486 characters)libsOKmainagc_driver_graphicsagc_driver_cmask_fast_clearCMASK fast clear draw and eliminate tests passedagc_driver_image_gather_volumeagc_driver_image_gather_volume(see below)git status --porcelainempty; both tests pass againThe script's
new_vuidentries are allVUID-VkSamplerCreateInfo-addressMode*, and all are marked "test not run on main": the validation baseline is1e658521a0, which is older thanmain1c8c0efc8c. This PR changes no sampler code, and that test does not touch CMASK. So I don't count them against the PR, but I did not confirm them on amainbuild.Negative control
The tests use
cmaskSliceand the three-argumentNibble, so restoring every production file frommaindoes not build, as LeandroLP23 noted. Instead I restored onlyGraphics/src/State.cpp(the slice decode) andGraphics/shaders/CmaskClear.comp(the GPU XOR) frommainand rebuilt both test executables:Output
On lavapipe this gives the same
CmaskClear.compfailure that LeandroLP23 and wachi35676 reported on RDNA 3.5 and NVIDIA. I did not repeat the control for the CPUNibbleXOR, which wachi35676 already covered. After restoring the merged files the tree is clean and both tests pass.Findings
Blocking
readCmaskstill reads slice 0 nibbles (core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp:544).color.coverageSamples > color.samples(a one-fragment EQAA target), each tile's code is checked withlayout.Nibble(tileX, tileY), so slice 0 is used. The cleared-tile loop atDraw.cpp:558and the GPU clear now usecolor.cmaskSlice.DecodeColorBuffersetscoverageSamplesfromCB_COLOR_ATTRIBNUM_SAMPLES for any target (State.cpp:2168), and this PR now accepts slice > 0 whensamples == 1, so this path is reachable for a sliced EQAA target.color.cmaskSliceat line 544 as well. Ideally add aoneFragmentrun at a slice above 0 intests/CmaskFastClear.cpp.Non-blocking
docs/dev/debt/libSceAgcDriver.md:249). The checker warns at 2486 characters. The entry was already over the 1000-character limit onmain, and the PR adds about 750 characters, much of it describing the implemented behaviour and PPSA34063's memory contents. CONTRIBUTING asks for the gap first and the behaviour only as far as the gap needs it. Suggest cutting the addition to the open gap: the stride and the Z swizzle come from AddrlibHwlComputeCmaskAddrFromCoord(mesa-25.2.0) and are unverified on PS5 hardware; 3D, array-depth and mipmapped-slice targets throw. Put the PPSA34063 evidence in the PR description.agc_driver_graphicstakes 35.9 s alone on lavapipe, over the 30 s rule. The PR adds only four CPU-sideDecodeColorBuffercalls to it, so this is almost certainly the case onmaintoo. It is not counted against this PR (I did not timemain).Not verified
gfx10addrlib.cpporgfx10SwizzlePattern.hmyself (no network). The stride and Z-bit placement match wachi35676's independent evaluation, which reproduced all 19 references.agc_driver_image_gather_volumeVUIDs on amainbuild at1c8c0efc8c.To get this to a good state
color.cmaskSlicetolayout.NibbleatDraw.cpp:544, and ideally cover a sliced one-fragment target inCmaskFastClear.cpp.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:38:36Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation consistently carries the slice through CMASK addressing and nibble selection; the reported test runs were not independently reproduced, and one changed test file was not read.
What I ran
Reviewed head
cd4b5811a70506e524c7c782c270aa179b8b082cusing the prepared diff andrepo_read.pysource reads. No build or test commands were run. No merged-preview check was performed.Results
Findings
Blocking
None identified in the code inspected.
Non-blocking
None.
Not verified
Read:
ColorTargetLayout.hpp,State.hpp,TextureDetiler.hpp,CmaskClear.comp,ColorTargetLayout.cpp,Draw.cpp,State.cpp,TextureDetiler.cpp,CmaskFastClear.cpp,ColorTargetLayout.cpptests, anddocs/dev/debt/libSceAgcDriver.md.Not read:
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp(excluded from the review bundle because it was too large). Build and test results in the PR description were author-reported; they were not run during this review. Console hardware behavior was not independently verified.To get this to a good state
Nothing is required. Optional: include a focused excerpt or split out the changed
Graphics.cpptest case so it can be reviewed.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.