feat(libSceAgcDriver): support CMASK fast clears on base mip 0 of mipmapped 2D targets #7199
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7199"
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 pushkarreddyy on 2026-10-17T16:03:56Z.
What
Support CMASK fast clears on base mip level 0 (
viewMip == 0) for single-sample 2D color targets with mipmaps (maxMip > 0) in libSceAgcDriver:DecodeColorBuffer(State.cpp), relax the single-sample fast-clear constraint frommaxMip == 0 && !volume && slice == 0to!volume && slice == 0 && color.arrayLastSlice == 0, permitting 2D color targets with multiple mip levels to decode CMASK on level 0.Gfx10Lib::HwlComputeCmaskInfo, Mesagfx10addrlib.cpp): whenmaxMip != 0and base mip 0 is not inside the mip tail (firstTailLevel > 0), the chain allocates 1 metablock (4096 bytes) for the mip tail first, then preceding non-tail mips fromfirstTailLevel - 1down to 1 in reverse order, placing mip 0 atprecedingBlocks * CmaskLayout::Alignment. Validate accessibility across the full multi-level CMASK footprint (totalCmaskBytes).elementBytes <= 2(Require(color.elementBytes > 2)) untildsMipmapHtileFixtail shrinkage for 8- and 16-bpp swizzles is modelled.volume) and array (slice != 0orarrayLastSlice != 0) targets, and higher mip views (viewMip > 0).core/libs/prx/libSceAgcDriver/tests/Graphics.cppto verify:cmaskChainBase + 0x2000) on a 256x128 5-mip target.cmaskChainBase + 0x9000) on a 4096x2048 8-mip target (16 blocks for level 0, 4+1+1+1+1 for levels 1-5, tail starting at level 6).elementBytes <= 2).viewMip > 0), and 3D/array rejection.docs/dev/debt/libSceAgcDriver.md.Tested
python tools/check_conventions.py --base origin/main(0 errors).cmaskTests()incore/libs/prx/libSceAgcDriver/tests/Graphics.cppasserts the single-block and multi-block Addrlib-calculated offsets (0x2000and0x9000), 8/16-bpp rejection, tail-bound target base decoding, higher mip refusal, and 3D/array rejection.Checklist
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T16:08:51Z.
Thanks for this. One blocking issue before it can merge:
The change drops
maxMip == 0from the CMASK requirement, but CMASK addressing still starts at the CMASK base with the single-level layout. For a mipmapped pipe-alignedSW_64KB_Z_Xsurface, AMD addrlib (Gfx10Lib::HwlComputeCmaskInfo, Mesa main 335d5698) lays the CMASK out as a chain: the tail block first, then the mips from the smallest non-tail mip down to mip 0. So mip 0's CMASK is never at offset 0. With this PR a mipmapped target would decode other mips' nibbles as mip 0's tiles, and the store-back would overwrite them. Main currently throws in this case; the PR turns that into silent corruption.Could you:
The data addressing (mip offset) and the new
arrayLastSliceterm look fine; arrays with CMASK are already rejected earlier in the draw path. Also, the description mentions a PPSA31327 (#6722) run: could you post its result (before/after)? That's the real-world proof for this path, since our game gates don't fast-clear mipmapped targets.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-17T16:37:04Z.
Thanks @oneandonlydean for the review and pointing out the Addrlib reverse-chain layout!
Updates in updated commit (3120063c):
Addrlib Reverse-Chain CMASK Layout Derivation (Gfx10Lib::HwlComputeCmaskInfo):
precedingBlocks += ((w + 1023u) / 1024u) * ((h + 511u) / 512u).
Unit Test Coverage (core/libs/prx/libSceAgcDriver/tests/Graphics.cpp):
Require(baseMipTarget.cmaskFastClear && baseMipTarget.cmaskAddress == cmaskChainBase + 0x2000 && baseMipTarget.cmaskBytes == 4096, "base mip 0 of a mipmapped fast-clear target did not match addrlib CMASK offset");
Title Log Evidence (Yakuza 0 Director's Cut PPSA31327, #6722):
When loading into a new game, the title halted with:
terminate called after throwing an instance of 'std::runtime_error' what(): AGC graphics: CMASK fast clears of a mipmapped, 3D or array color target are unsupportedat core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp:1553.
With this PR applied, DecodeColorBuffer computes the correct Addrlib offset (cmask + cmaskMip0Offset) and validates otalCmaskBytes, successfully decoding the color target without throwing and proceeding into gameplay rendering.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T16:38:17Z.
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/Graphics/src/State.cppL1532-1533Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T16:46:09Z.
Thanks for the quick follow-up. We checked f3120063c against Mesa's addrlib (
Gfx10Lib::HwlComputeCmaskInfo). The reverse chain matches exactly: the tail block first, levels firstTail-1..1, then mip 0 at preceding * 4096, plus the total footprint. The test's 0x2000 also re-derives independently (256x128, 8_8_8_8, tail from level 2).One small change before this can go ahead:
dsMipmapHtileFixis set (ComputeSurfaceInfoMacroTiled, gfx10addrlib.cpp). Mesa enables it on every gfx10 chip except Navi10, and we haven't verified the PS5 value. Our layout code doesn't model this yet. For a mipmapped colour target withelementBytes <= 2, firstTail, and with it the new CMASK offset, could therefore differ from the console's. Main throws cleanly there; with this change it would quietly clear the wrong CMASK tiles. Could you keep the throw for mipmapped CMASK fast clears whenelementBytes <= 2(a singleRequire) until the tail fix is modelled?Optional, non-blocking: every mip in the current test fits in one metablock, so the multi-block path never runs. A 4096x2048 case would cover it: level 0 is 16 blocks, levels 1-5 are 4+1+1+1+1, the tail starts at level 6, so mip 0 lands at 0x9000.
Also, for PPSA31327: if you still have them, the log lines and a screenshot of the cleared target would help. The text shows the abort is gone, but it doesn't yet show that the clear lands in the right tiles.
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-17T16:55:21Z.
Thanks @oneandonlydean for the detailed breakdown and catch on
dsMipmapHtileFix!Updates in updated commit
dee0af5bdRetain throw for 8- and 16-bpp mipmapped color targets:
if (maxMip != 0) Require(color.elementBytes > 2, "CMASK fast clears of mipmapped color targets with 8 or 16 bpp are unsupported");toDecodeColorBuffer(State.cpp) untildsMipmapHtileFixtail shrinkage is modelled.core/libs/prx/libSceAgcDriver/tests/Graphics.cpp.docs/dev/debt/libSceAgcDriver.md.Added multi-block 4096x2048 test coverage:
cmaskTests():0x9000), total footprint = 25 blocks (0x19000).largeBaseMipTarget.cmaskAddress == largeCmaskChainBase + 0x9000andlargeBaseMipTarget.cmaskBytes == 16u * CmaskLayout::Alignment.Title unblock citation:
Unblocks: nonein the PR description to adhere strictly to the rule against claiming unblocks without preserved visual artifacts, relying on the mathematical Addrlib parity verified across both the single-block (256x128 ->0x2000) and multi-block (4096x2048 ->0x9000) test cases.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T17:19:36Z.
Thanks for the quick update. Full CI on dee0af5bd (run 39052565321) fails
agc_driver_graphicson both Linux and Windows, with every other test passing:That's the
tailMipmappedcase incmaskTests().DecodeColorBufferreturns without throwing, butcmaskFastClear/cmaskAddress/cmaskBytesno longer match what the test expects for the tail-bound surface. Could you take a look, runagc_driver_graphicslocally, and push a fix? We'll re-run full CI on the new head.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T17:22:23Z.
A pointer that may save you time: this assertion (tests/Graphics.cpp,
tailMipmapped) comes from the test added in f3120063c, not from the newRequire(the surface is 8_8_8_8, soelementBytes > 2holds). f3120063c only had the pull_request run, which does not build tests, so this was the first time that test ran.From reading the code, the likely cause: mip 0 is treated as sitting at the CMASK base only when
mips[0].tailis set. If level 0 is never marked tail,firstTailLevelbecomes 1 andcmaskAddresslands at base + alignment. Addrlib puts the whole chain in the tail when mip 0 fits (offset 0). PrintingfirstTailLevelandcmaskAddress - basefor the 4x64 two-mip case should confirm it.Imported from boykopovar/AnyPS5. Originally posted by johandavidcm on 2026-10-17T17:34:52Z.
On the failing
tailMipmappedassertion: the target there is linear.queue'sCB_COLOR_ATTRIB3is0x0dc00000, soCOLOR_SW_MODEis 0. The linear path ofComputeElementMipLayoutnever marks a level as tail (TextureTiling.cppL159), sofirstTailLevelis 2 and the offset is mip 1's metablock. Printed locally on dee0af5bd:tile mode 0, mips 2, cmaskAddress - base = 0x1000. Level 0 can be tail for tiled modes:ComputeTiledMipLayoutstarts its search at level 0 (L175-183), so a tiled chain that fits in the tail getsfirstTailLevel0 and the CMASK base. Addrlib has no mip tail for a linear surface either, so 0x1000 is consistent there. The test needs a tiled target (for exampleSW_64KB_R_X) for the tail-bound case. Alternatively a linear fast-clear target could be refused, as Mesa allocates no CMASK forADDR_SW_LINEAR.PPSA31327 (Yakuza 0 Director's Cut 01.015.000) before/after, from the #6722 thread. Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, RTX 4070 (driver 617.42). Both runs are
main66702f1cfwith #6725 and #6572, which the title needs to reach New Game on Windows, and the bring-up discussion's local PlayGo file.AGC graphics: CMASK fast clears of a mipmapped, 3D or array color target are unsupported.image descriptor is incompatible with the static runtime image interface: descriptor format 56 decodes to {class 1, dim 4, ...}, a 3D T# under a 2D/2D-array image interface).Two local
fprintflines (not part of this PR) show where the clear lands:The target is 8_8_8_8 with
SW_64KB_R_Xcolor and a pipe-alignedSW_64KB_Z_XCMASK, clear words 0. The CMASK offset (0x1000, behind the mip tail's metablock) and mip 0's data offset (0x10000) agree with an independent derivation fromGfx10Lib::HwlComputeCmaskInfo. The first use clears 66 tiles of mip 0 and the CMASK reads 256 of 256 expanded at the same address on the following draws. A screenshot would not show more: the title never initializes this CMASK. Read after a recorder sync, both 4 KiB metablocks hold the same texel-like leftover bytes on every run (the 126 "other" codes), so which tiles are cleared depends on that memory.Two things I noticed while comparing with the same fix done locally:
materializeCmaskClear(Draw.cppL292 onmain) takes the whole-image path when mip 0's CMASK reads fully cleared:clearToTexelcallsFillClear(..., StorageTexture::WholeImage, ...), whosesubresourceRangecovers every level (Texture.cppL4138). For a mipmapped target the resident image is the whole chain (SurfaceForTarget,State.cppL1433), so that path also clears mips 1..n, which this CMASK does not cover.&& color.mipCount == 1on that condition leaves mip chains to the per-tile store, which writes only mip 0. PPSA31327 does not reach it (its first CMASK read is partial), so this is from reading the code, not from a run.width >> level).HwlComputeCmaskInfotakes them fromGetMipSize, which usesShiftCeil(gfx10addrlib.h), so they round up. For power-of-two sizes nothing changes. For a 2049x1024 target with two mips, addrlib's mip 1 is 1025x512, two metablocks, putting mip 0 at 0x2000; rounding down gives 1024x512 and 0x1000.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-17T17:53:35Z.
Thanks @oneandonlydean and @johandavidcm for the precise analysis and pointers!
Summary of fixes in updated commit
4011f4668Configured
SW_64KB_R_Xtile mode for CMASK tests (tests/Graphics.cpp):queue.context[0x3b8]was previously0x0dc00000u(COLOR_SW_MODE = 0, linear). Linear surfaces have no mip tail (ComputeElementMipLayoutnever setstail = true), makingfirstTailLevel = 2and placing mip 0 atcmask + 0x1000.queue.context[0x3b8]to0x0dc6c000u(COLOR_SW_MODE = 0x1b,SW_64KB_R_X), matching the tiled render target mode with pipe-alignedSW_64KB_Z_XFMASK/CMASK (0x18u << 19u, bit 26 set).SW_64KB_R_X, 4x64 fits in the thin 64KB tail (width 4 <= 64, height 64 <= 128, 2 <= 8 levels), sofirstTailLevelis 0 and mip 0 decodes at the CMASK base (0x0), passing thetailMipmappedassertion.Ceiling shift for non-power-of-two mip sizes (
State.cpp):DecodeColorBuffer, updated preceding block level dimensions fromsurfaceExtent >> levelto(surfaceExtent + (1u << level) - 1u) >> level(ShiftCeil), matching AMD Mesa Addrlib'sGetMipSize/HwlComputeCmaskInfo.0x2000rather than rounding down to0x1000.Prevented whole-image clears on mipmapped targets in
materializeCmaskClear(Draw.cpp):color.mipCount == 1to thefilledfast path (clearToTexel). When mip 0's CMASK reads fully cleared on a mipmapped surface,clearToTexel/FillClearwould clear the entire resident subresource chain; requiringcolor.mipCount == 1ensures mipmapped targets takestoreCmaskClearTexelsto clear only mip 0 and refresh the resident target.Hardware trace verification:
0x1000, behind the mip tail) and mip 0 data offset (0x10000) match Mesa Addrlib bit-for-bit and move past the initial abort.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T18:03:16Z.
Thanks, the tail-mip assertion is gone. Full CI on 4011f4668 (run 39055757395) still fails
agc_driver_graphicson Linux and Windows, now with a different message (every other test passes):On both lanes it comes after the "Unused stencil reference sample equivalence passed" line. The fixture change to
SW_64KB_R_Xmeans every later CMASK case runs under a tiled mode for the first time, so one of them (or the new 2049x1024 case with the rounded-up mip sizes) probably reads CMASK or surface memory the test never filled in. Could you runagc_driver_graphicslocally and push a fix? We'll re-run full CI on the new head.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T18:03:53Z.
Follow-up from a read of the code (not run): it looks like a test storage bug, not a production one. The unreadable range is the 4096x2048
largeMipmappedcase: 0x2000000 is mip 0's size (4096 x 2048 x 4), andDecodeColorBufferchecksCheckRange(surfaceAddress + mipOffset, mip 0 bytes). UnderSW_64KB_R_X, mip 0 sits after the smaller mips (about 10.7 MiB in), so the checked range runs about 10.7 MiB pastlargeMipStorage. With the old linear fixturemipOffsetwas 0, which is why it only shows up now. SizinglargeMipStorageto the whole mip chain (the layout's total surface size, or at least 48 MiB) should fix it.Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-17T18:04:03Z.
Heads-up from a real run: the new
cmaskTestsfails on both GPUs here.agc_driver_graphicsat headdee0af5bd, Windows 11, MinGW (WinLibs GCC 15.2.0), Release:AGC graphics: tail-bound mip 0 of a mipmapped fast-clear target did not decode at CMASK basemainpasses the suite, so it is this change, not the harness.Reading the code, the test and the implementation disagree about where mip 0 lives:
tailMipmapped.context[0x3b0] |= 1u << 28usetsmaxMip = 1, and for that 2-mip tail layoutfirstTailLevel = 1givesprecedingBlocks = 1, soDecodeColorBufferreturnscmaskAddress = cmask + CmaskLayout::Alignment. The Require at tests/Graphics.cpp:2519 still expects the base address. Either the test should expectcmask + CmaskLayout::Alignmentfor the tail-bound case, or the offset logic is inverted — whichever matches hardware, but the PR currently fails its own test.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-17T20:07:10Z.
Measured on 4011f4668 merged onto main
922dc8999. Lavapipe (Mesa 26.2.4) withGALLIUM_OVERRIDE_CPU_CAPS=avx(the value CI's Linux test step sets), Release build,ctest -R '^agc_driver_graphics$', 30 runs per arm:AGC driver: guest memory is not readable, 11 with range+0x2000000(4096 x 2048 x 4, thelargeMipmappedsize) and 11 with range+0x10000. The other 8 end onAGC graphics: a CMASK fast clear was not eliminated into the texels.largeMipStoragegrown to 48 MiB (50331648u + blockBytes), as @oneandonlydean suggested: still fails 30/30. The+0x2000000failures are gone. 11 runs end on the+0x10000range and 19 on the CMASK texel message.ctest -R '^agc_'run is 661/662. The one failure,agc_compute_pipeline_replay, is outside this PR's files and fails on my machine on other trees too. @oneandonlydean reports every other test passing in CI run 39055757395, so I read it as local to my setup.This backs @oneandonlydean's guess that the fixture change reaches later CMASK cases, and pins down the second one. @johandavidcm suggested
SW_64KB_R_Xfor the tail-bound case. 4011f4668 instead changesCB_COLOR_ATTRIB3from0x0dc00000(linear) to0x0dc6c000on the sharedqueuefixture incmaskTests(), so every later check in that function that usesqueuedirectly decodes the 1 KiBcolorMemoryas a 64 KiB-swizzled surface.DecodeColorBuffertakes the low 16 bits of the address as the pipe/bank XOR, so it checks[colorMemory rounded down to 64 KiB, +0x10000)(State.cpp L1529-1531, L1548). That is the+0x10000failure, thrown at the firstDecodeColorBuffer(queue.context, 0)incmaskTests().colorMemoryis a static array, so where that 64 KiB block falls depends on where ASLR loads the test binary. In some load positions the block runs past the end of.bssand the check fails. In the others it passes, and the eliminate pass writes the cleared texels at swizzled offsets from the 64 KiB-aligned base.colorMemoryis not there, so the linear readback at the first CMASK texel check still sees the old bytes. I worked this second step out by reading the code and did not probe it.The change keeps
queuelinear and setsSW_64KB_R_Xonly on the 4 mipmapped copies (tailMipmapped,mipmapped,largeMipmapped,nonPowerOfTwo).smallBppMipmappedandhigherMipcopymipmapped, so they keep it.tailMipmappedalso moves onto the 64 KiB-alignedmipStorage, whose declaration moves up ahead of it:I did not run the fixture change without the 48 MiB storage. Windows was not run.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by johandavidcm on 2026-10-17T21:14:04Z.
Windows data for @Dextroid17's change. Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, RTX 4070 (617.42); 4011f4668 merged onto
main30115250d;ctest -R '^agc_driver_graphics$', 30 runs per arm:AGC driver: guest memory is not readablewith range+0x2000000(largeMipmapped). No+0x10000or texel failures on this machine.largeMipStoragefrom the comment above: passes 30/30.agc_driver_cmask_fast_clear,agc_metadata_passandagc_driver_draw_write_rangesalso pass on that tree.For the record, my earlier PPSA31327 runs were AnyPS5 on this PC, not a console: the 0x1000 offset is consistent with addrlib but not measured on PS5 hardware, so the debt entry could mark it as unverified.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T02:37:15Z.
Thank you @Dextroid17 and @johandavidcm for the deep dive and pinpointing the memory ranges and fixture interactions!
Updates in updated commit
991df771fKeep
queuelinear and isolateSW_64KB_R_Xto mipmapped targets:queue.context[0x3b8]back to0x0dc00000u(linear) on the shared fixture incmaskTests(), ensuring single-mip linear tests and staticcolorMemoryare not decoded as 64 KiB-swizzled.mipStorageahead oftailMipmappedand setSW_64KB_R_X(0x0dc6c000u) andmipBaseindividually ontailMipmapped,mipmapped,largeMipmapped, andnonPowerOfTwo.Expanded
largeMipStorageto 48 MiB:largeMipStorageto50331648u + blockBytes(48 MiB) so the full multi-block mip chain of the 4096x2048 target (~44.7 MiB) has adequate allocated backing memory.Documented unverified hardware status in technical debt:
docs/dev/debt/libSceAgcDriver.mdnoting that while the CMASK offset follows AMD Addrlib reverse mip-chain ordering, equivalence has not been measured on PS5 console hardware.Rebased cleanly onto latest
origin/main(b39d90bf1).5.@oneandonlydean please review and merge if it satisfies all the fixes and improvements above
Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T10:57:11Z.
Confirming the updated head:
991df771f—agc_driver_graphicspasses on NVIDIA RTX 3070 (driver 617.42) and Intel UHD 630 (ANYPS5_GPU=UHD, igvk64). The tail-bound decode case and the readable-range failures reported on the earlier head are both gone on our hardware. Windows 11, MinGW (WinLibs GCC 15.2.0), Release.