fix(agc): store uncompressed DCC keys at the first write of a fast-cleared image #903
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/903"
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 Celegans12 on 2026-10-06T14:55:48Z.
What
A storage image uploaded under fast-clear DCC keys kept the clear code in memory until its write-back, so a kernel reading the keys after a write to the image still read it.
StorageTexture::MarkDirty) stores its keys uncompressed (MarkDccUncompressed, as at the write-back) and marks its uploaded keys uncompressed, unless the title filled them with a clear code since (#163).StorageTexture::ProvedKeys(Refresh, fast revalidation) reads them as the pending work leaves them: fills and our key stores note their byte (Recorder::NotePendingFill), and it waits only while those bytes still allow a clear code.DccKeyCountthey read 0xff.MarkDirty) get it too.fastRevalidate; whichever lands second keeps both.Details
The splash draw (queue 0 +6617) writes a 3840x2160 image at 0x5005160000; the retile kernel (+6693) copies its keys (0x5007140000), still 0x00. The store covers 0x1fe00 of its 0x28000 keys.
Tested
mainee391a56: configure-DBUILD_TESTING=ON, full build,--target libs,ctest:ctest --output-on-failure)VK_DRIVER_FILES): 368/368 pass;agc_driver_flat_storeis left out there because it takes several minutes on Windows llvmpipeagc_driver_dcc_keys_first_write(plain and write-watched memory): a key copy after a first write reads 0xff; a pending 0x10 fill skips the wait, 0000 fills take it and the refresh clears the image; a write marked after a 0001 key fill, before a refresh, keeps 0x40. Fails without the store or the fill check; does not build on main.agc_driver_recorder_tests(not in ctest) passes on NVIDIA; its key fills now write the keys.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 NahuelGenchi on 2026-10-06T23:58:46Z.
Tested c99a7bed on an R9 380 (Tonga, GFX8, RADV, Mesa 26.0.8, subgroup 64), Ubuntu 26.04, GCC 15.2, Release build.
The new agc_driver_dcc_keys_first_write test fails here every time (5 out of 5 runs, also with ANYPS5_NO_SHADER_CACHE=1). The kernel rejects the command stream ("radv/amdgpu: The CS has been rejected, see dmesg for more information (-14)"), vkQueueSubmit then returns -4 (device lost) and the test ends with "the refresh after the one that cleared the image uploaded it again". Right before that it logs "has mixed DCC keys ... its texels are read as stored" for the 128x128 format 56 storage image.
The same binary passes on llvmpipe on this machine, so it looks specific to RADV on GCN. The rest of the suite passes (367 of 368, lod_clamp skipped since the card has no shaderResourceMinLod). I also ran all agc_driver_* binaries under the Khronos validation layer with sync validation on and got no errors or hazards, the same as main. I couldn't read dmesg on this box, so I don't have the kernel side of the rejection. Happy to run anything else on this card if it helps.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T00:33:56Z.
Thanks for running this on the 380. Your log was enough to find it, and I'm fairly confident it's a bug in my test, not in GCN or DCC. When the device starts on Linux, the driver checks whether the kernel driver writes to imported pages, and amdgpu does: it re-faults userptr pages for write on every submission. So on any amdgpu card, host imports are taken off the write watch. My test decided its second block was write-watched before that block got imported, so its last check expected a second refresh to skip the upload, which only holds while the watch is on. I get your exact message on NVIDIA when I run that check on unwatched memory.
I'm less sure about the CS rejection, but it looks like a side effect. The failed check skipped the final wait, and the test had already freed its memory when the device was torn down. The teardown then submitted the leftover work with userptr BOs whose pages were gone, which amdgpu rejects with -EFAULT.
a8ba1c53 fixes the test. It checks the watch again once its block is imported, as the storage refresh test in
Recorder.cppdoes, and it frees its memory after the device. On amdgpu, the second pass now runs as unwatched. Could you run it once on that head?I'd expect three lines:
There shouldn't be a teardown line.
Details
DccKeysFirstWrite.cpp, theif (watched)block after the 0000 fills). The plain pass had already finished.decideImportWatchinGuestBufferMemory.cpp) runs at device creation. After a "yes", every import callsGuestMemory::Unwatchfirst. An unwatched block can't prove it is unchanged, soStorageTexture::Refreshuploads again.[gpu] unit shadow teardown: AGC graphics: vkQueueSubmit recorder: Vulkan result -4.~VulkanDevicerunsPublishAllShadowsandrecorder->Sync(), and imports are only retired lazily, so both BOs were still in that submission. dmesg probably won't show anything: as far as I know, amdgpu logs this failure only at debug level.APS5_WRITE_WATCH_IMPORTS=unwatch VK_DRIVER_FILES=/usr/share/vulkan/icd.d/lvp_icd.x86_64.json, llvmpipe should fail the same way, without the CS rejection;APS5_NO_WRITE_WATCH=1, the test should pass on RADV.main, not part of this PR.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T19:38:08Z.
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/ShaderResources.cppL1465, L1507Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T20:09:11Z.
Review: CHANGES_REQUESTED
Ran it merged onto current
mainon RADV (RDNA2, amdgpu): build + ctest 401/401.agc_driver_dcc_keys_first_writealso passes on CI's lavapipe. On amdgpu it takes the "host imports are compared, not watched" path and passes, so the R9 380 failure looks fixed by a8ba1c53 (@NahuelGenchi, a rerun on GCN would confirm it).Negative checks: the new execution test fails without the
MarkDirtystore, without the wait inProvedKeys, without the fill value inFillBuffer, and without the value on the key store. Two gaps:tests/Recorder.cpp:2702-2735:agc_driver_graphicsstill passes with every non-test change of the PR reverted tomain, and also with only theMarkDirtystore disabled. Itsdrawdoesn't reachStorageTexture::MarkDirty, so these new checks don't test this change. Please make them reach the storage-image first write, or drop them.Texture.cpp:2105: nothing covers the!IsDccClear(filledKeys)guard. With it removed, both tests still pass. Recorder.cpp:2733-2735 looks meant to cover it, but see the point above. A case inDccKeysFirstWrite.cppwould pin it: a 0x40 key fill after the clear, then a storage write, and the keys must still read 0x40.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T21:14:43Z.
Thanks for the negative checks; they're what found both gaps. I've pushed 124375cc.
MarkDirty, but they sit inagc_driver_recorder_tests, which ctest never builds or runs, so they tested nothing in CI. I dropped them and left that coverage toagc_driver_dcc_keys_first_write, which fails without the store.DccKeysFirstWrite.cpp, and with!IsDccClear(filledKeys)removed it fails on NVIDIA and lavapipe. One difference from what you suggested: a dispatch right after the fill refreshes the image first, which clears it again under 0001 and then correctly stores 0xff. So the case marks the write before any refresh has seen the fill, which is the only path that reaches the guard.While testing this I found one sequence the guard still gets wrong: a 0x40 fill, then a kernel storing 0000 over the keys, then a storage write. On write-watched memory the refresh sees 0000, which matches the keys the image was uploaded under, so
FilledKeyskeeps the stale 0001 and the first write skips its store; the reader then sees the clear colour. It isn't a regression againstmain, which never stores at the first write, but it's the same kind of bug this PR is for, so I'll push a fix (dropfilledKeyswhen a refresh sees keys that differ from the fill) with a test for that sequence here.Details
Without the store:
a kernel reading the keys after the first write of a 0000-cleared surface: 0 of 256 key bytes are 0xff (key 0 is 0x00)Without the guard:
a write marked after a 0001 key fill over a cleared image, before a refresh saw the fill: 0 of 256 key bytes are 0x40 (key 0 is 0xff)Both fail the same way on an RTX 3080 and on llvmpipe. The merge with current
mainbuilds, and the DCC, image and graphics tests pass on both.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T21:26:15Z.
Review: APPROVED
Re-checked 124375cc merged onto current
mainon RADV (RDNA2): build + ctest 407/407. Both earlier points are addressed.Mutation checks on the new test: it fails without the
!IsDccClear(filledKeys)guard, without the first-write store, without the fill value inFillBufferor on the key store, and whenWaitForKeyWritersalways or never waits. Two mutants survived, so I added a commit with two rows inDccKeysFirstWrite.cpp:PendingFillsLeaveUncompressedoldest-first);Rebased onto
main, build + ctest green. Merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T21:30:32Z.
Thanks for the two extra rows, both are good catches. I'll leave this branch as it is so it can go in, and send the stale
FilledKeysfix I mentioned as a separate follow-up PR once this is merged, with the test for that sequence.