fix(agc): read comp-to-single DCC keys of sampled textures and storage images #4700
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4700"
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 Nesyth on 2026-10-12T19:13:43Z.
What
DCC key 0x10 (comp-to-single,
GFX9_DCC_CLEAR_SINGLEin Mesa) marks a 256-byte block whose texels all equal its first texel. #2939 (b89b7f953) expands such keys in a CB DCC decompress pass. Sampled textures and storage images still read them as stored ([gpu] texture ... has single DCC keys ...; its texels are read as stored), so every texel but the first of each block came from whatever memory held before.TextureClearKeysanswersClearSinglefor uniform 0x10 keys when the format's element size divides 256 bytes. Other formats, and 0x10 mixed with other keys, still read as stored.ReadTextureSurfacereads the stored bytes and copies each block's first element over the rest of the block (ExpandSingleBlocks).MarkDirty).keyFlipand thestoredrule inStorageTexture::Refresh).cachedTexturechanges in two ways under single keys:RunSingleKeysOverPendingImagebelow), when only the keys were written, the lookup can find the surface unchanged and skip the image's refresh; without this line it then views the image and samples its own texels.mainreads such keys as stored, so there an unchanged surface matches its snapshot and the snapshot is reused.fastTextureapplies that memory check under single keys too.mainreads 0x10 keys as uncompressed, so it checks them today. Without this line, the newClearSingleanswer would skip the check, and a re-clear that kept the 0x10 keys but changed the first texels would reuse the old snapshot.docs/dev/debt/libSceAgcDriver.mdnow describes the reads above and says so.singleDccKeysTests(TextureFormat):ClearSingle, and a read gives every block its first element;DccKeysFirstWrite:RunSingleKeys: a storage image's first write stores the keys uncompressed, and the write-back gives every texel the kernel did not write its block's first texel;RunSingleKeysSampled: samples texel (1, 0) of a single-key texture (it must be its block's first texel), then samples again after the CPU changed that first texel under the same keys (it must be the new value). It runs from unwatched and from write-watched memory. Its output buffer is a separate allocation, and the write-watched run requires the texels to stay write-watched after the first sampling;RunSingleKeysOverPendingImage: a kernel writes the first 32 texels of row 1 under uncompressed keys, so a storage image has results pending; the CPU then stores 0x10 keys, and texel (1, 0) must sample as its block's first texel, not as the image's unexpanded texel. It runs in write-watched memory whose host import keeps the watch: a shared mapping on Windows; on Linux the test sets the import watch toWatchfor this case and restores it after (on lavapipe, imported ranges are otherwise compared).ShaderResources.cpplines above reverted,agc_driver_dcc_keys_first_writefails, on Linux and on Windows (see Tested).Overlaps with open PRs; whichever merges second rebases:
textureClearKeysaround the line this one changes, and adds its test next to these intests/execution/DccKeysFirstWrite.cpp, where both declarestd::optional<GuestBlock> sampledinmain().singleDccKeysTestsintests/TextureFormat.cpp.Tested
Windows 11 Pro 10.0.22631, AMD Ryzen 7 7800X3D, AMD Radeon RX 7900 XTX, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, onmaind53960612:ctest: no failures out of 995 with2fb6dccd7, and again with83959f315, includingagc_driver_graphics(singleDccKeysTests) andagc_driver_dcc_keys_first_write. Withc809601df,agc_driver_dcc_keys_first_writepasses; the full suite was not run again.2fb6dccd7andDccMetadata.cpp,ShaderResources.cppandTexture.cppas onmain, both fail:agc_driver_graphicswith "comp-to-single keys of format 1 must read as single", andagc_driver_dcc_keys_first_writewith "a pending comp-to-single fill of the keys: the keys read uncompressed (expected single) and the read did not wait".c809601dfand one of the threeShaderResources.cpplines reverted at a time,agc_driver_dcc_keys_first_writefails with the same messages as on Linux below.tools/check_conventions.py --base d53960612passes on this head.Linux, in my fork's Actions: ubuntu-24.04, GCC 13.3.0, lavapipe (Mesa 25.2.8), Release,
ANYPS5_REQUIRE_VULKAN=1, with the upstreamlinuxjob's packages and configure options (without ccache);maind53960612with this head (c809601df) merged in; onlyagc_driver_dcc_keys_first_writewas built and run: https://github.com/Nesyth/AnyPS5/actions/runs/38320553715ShaderResources.cppline reverted at a time, it fails:fastTexturecheck: "comp-to-single keys sampled after the first texel of the block changed from write-watched memory: component 0 of thread 0 is 0x3f800000, expected 0x00000000";cachedTexture: "comp-to-single keys sampled after the first texel of the block changed from unwatched memory: component 0 of thread 0 is 0x3f800000, expected 0x00000000";cachedTexture: "comp-to-single keys stored over a pending storage image: component 0 of thread 0 is 0x00000000, expected 0x3f800000".Vampire Survivors (PPSA21703) on
main42496c5e5without this change, plus only a localclose()guard the title needs (#3295 is open for the same problem; see #3745):[gpu] texture ... (format 56) has single DCC keys ...; its texels are read as storedreports.Vampire Survivors with this change, in an earlier session on
mainffa198407plus three local changes that are not pull requests (vertex input copies, AudioOut pacing and theclose()guard), about 54 minutes of play:has single DCC keysorhas mixed DCC keysreports.2fb6dccd7; the base differs.has single DCC keys ...; its texels are read as storedreports per run, in five runs; with it there were none, in any run. No visible change in the scenes checked.fastTextureline. The build was an earlier state of the bring-up build:mainbab7b3285plus #4021, #4057, #1077, #425, #454, #4031, #2254 and local changes.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 github-actions[bot] on 2026-10-12T19:29:14Z.
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/tests/TextureFormat.cppL98, L147core/libs/prx/libSceAgcDriver/Graphics/src/DccMetadata.cppL451-452core/libs/prx/libSceAgcDriver/tests/execution/DccKeysFirstWrite.cppL371, L512core/libs/prx/libSceAgcDriver/tests/execution/DccKeysFirstWrite.cppL503Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:38:19Z.
Code review location:
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp; line 3237The Windows run does not exercise this added branch because that path compares host imports rather than using write-watched memory, as the PR description notes. This check is what rejects a cached snapshot after guest memory changes while the
ClearSinglekeys remain unchanged. Couldagc_driver_dcc_keys_first_writebe run on Linux for this head and the result added? My local CMake configure could not reach the test: the PR worktree's SDL2 submodule is uninitialized, and the environment lacks the PipeWire/PulseAudio/ALSA development files required by the project configuration.Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-12T22:35:17Z.
The two runs the description lists as not done yet, on NVIDIA and Intel.
Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The rebased head
2fb6dccd7merged intomain584cc4c57.agc_driver_graphics,agc_driver_dcc_keys_first_writeandagc_driver_texture_formatpass on both GPUs with--repeat until-fail:3. The full suite (ctest --timeout 120 --parallel 4) passes 1018 of 1018 on both.DccMetadata.cpp,ShaderResources.cppandTexture.cppas onmain, the new tests fail on both GPUs:agc_driver_graphics:comp-to-single keys of format 1 must read as singleagc_driver_dcc_keys_first_write:a pending comp-to-single fill of the keys: the keys read uncompressed (expected single) and the read did not waitWritten with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Nesyth on 2026-10-13T00:32:38Z.
Code review location:
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp; line 3237Thanks. I ran it on Linux in my fork's Actions.
Two test commits are now on this branch:
83959f315moves the sampled output into a separate allocation, so the texels stay write-watched and the write-watched run depends on thefastTexturecheck, on Windows as well.c809601dfadds a case for thecachedTexturesource reset, with a storage image whose results are still pending.With them (ubuntu-24.04, GCC 13.3.0, lavapipe, Release,
ANYPS5_REQUIRE_VULKAN=1,maind53960612with this branch merged in), the test passes, and with any one of the threeShaderResources.cpplines reverted it fails with its own message (the run's three negative-check steps): https://github.com/Nesyth/AnyPS5/actions/runs/38320553715On Windows each of the three reverts fails with the same message as on Linux. The description now has the Linux result and the messages.