fix(agc): leave the uncompressed key store out when the guest replaced the keys by another clear code #16411
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16411"
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 SleglJan on 2026-11-06T16:23:55Z.
What
A storage image uploaded under fast-clear DCC keys stores uncompressed keys (0xff) at its first GPU write and at its write-backs. Whether the keys still are that clear kind is decided earlier, by the lookup, which can answer in three ways without seeing a guest write that landed after the thread's earlier collect of the key range in the same collect epoch: from the memoized collect behind the key proof, from the refresh's own proof, and, with
APS5_DRAW_PIPELINE, inside the epoch of the last proof with no collect at all.When the guest replaced the keys by another clear code in that window, the lookup keeps the image as uploaded under the old code, and the first write's store then puts uncompressed keys over texels taken under the replaced code. Where main sees such a write it honours the guest's code in either order. A lookup that sees it before the first write takes the image under the new code (as stored for the register clear code, whose keys stay): the order "clear before the draw". Once an image holds results, a fixed clear code written over them wins ("new keys that are a clear code make every result dead on hardware too", the comment over
droppableinStorageTexture::refresh, for images tracked in 64 KiB units), and the register clear code stays in memory once the first write has stored its keys: the order "clear after the draw". Here the store covers the guest's code, which neither order gives outside the two cases below. This PR gives the second.For a fixed clear code main's result is still the first order in two cases: the first write covers every texel of the surface, or the two codes decode to the same texels for the surface's format. There this PR gives the other order, the guest's clear after the draw.
test(agc): six modes of theagc_driver_dcc_keys_first_write_testsexecutable. Each uploads an image under 0000 keys in a watched block, collects the keys, lets the guest write in the same collect epoch, looks the image up again (the step requires that the lookup kept the clear keys) and marks it written. Each step also requires the path that answers that lookup, read through the driver library (StorageTexture::RefreshesProved()and the thread'sRefreshProvedlookup outcome): neither moves for a refresh under the memoized collect, both rise by one for the refresh's own proof, andRefreshesProved()alone rises for an answer inside the epoch of the last proof.agc_driver_dcc_keys_rewrite_after_memo: every key replaced by another clear code (1111); the lookup is answered by the memoized proof.agc_driver_dcc_keys_rewrite_after_refresh_proof: the same, the lookup answered by the refresh's own proof (required by the step).agc_driver_dcc_keys_rewrite_after_epoch_proof: the same, the lookup answered inside the epoch of the last proof (required by the step;APS5_DRAW_PIPELINE=1).On main these three fail with
AGC graphics: a storage image's first write stored uncompressed keys over keys the guest had replaced by another clear code after a memoized collect: 0 of 256 key bytes are 0xc0 (key 0 is 0xff).agc_driver_dcc_keys_rewrite_to_register_clear: every key replaced by the register clear code. On main it fails withAGC graphics: a storage image's first write stored uncompressed keys over keys the guest had replaced by the register clear code after a memoized collect: 0 of 256 key bytes are 0x20 (key 0 is 0xff).agc_driver_dcc_keys_partial_rewrite_keeps_store: half of the keys replaced. The half the guest did not touch must read uncompressed after the first write. The rewritten half is not checked (see Limits).agc_driver_dcc_keys_write_beside_keys_keeps_store: a guest write beside the keys, in their page. Every key must read uncompressed after the first write.These two pass on main and with the fix.
The steps run with
APS5_NO_HOST_IMPORT=1, because an upload's host import ends the write watch over the test's block; every skip prints its reason.fix(agc): the check is made at the store.StorageTexture::keysReplacedByClearruns inMarkDirtyand at the three write-back stores. It answers yes only when the proved key count is the stored key count, a key proof for the uploaded kind exists, the caller holds the device lock, no recorded work writes the keys, the guest wrote the key range since the proof (GuestMemory::CpuWroteSince, new: the uncached collect and CPU-stamp compare ofUnchangedSinceCollected, answering "no" where it cannot tell), and the keys read again as another clear code (0000, 0001, 1110, 1111 or the register clear). Then the store is left out and the guest's clear stands.Limits:
guestBytes / 256(single-level pipe-aligned R64KBX with 4-byte elements). For element sizes that do not divide 256 main reads single-colour keys as uncompressed and leaves them in place where it sees them; here the store covers them.MarkDirtyhas already taken the image out of its clear kind when the write-back runs.ProvedCurrentDccKeys(the register clear's proof) has the same window and is not changed here.Cost: one uncached collect of the key range per first write, and per write-back store that finds the image still under its clear kind, of an image that has a proof for its uploaded kind and no key tail; a read of the keys only when that collect finds a CPU write.
Related: #6209 (open) changes
ProvedCurrentDccKeysandProvedClearKeys, which this PR does not touch. #6186 (open) keeps CPU stores made after a deferred key store was recorded, the window after this one.Tested
Head
5287cda761is this PR's three commits on upstream/main3bd88ca119(the third, test only, came after review: see the thread). The runs below are clean merges onto main9f2b939606: main + the two test commits, main + the head, and main + the head + the head of #15456.ctest -V -R '^agc_driver_dcc_key'withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1, on an AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.2.4) and on lavapipe (llvmpipe, LLVM 23.1.1, Mesa 26.2.4). The pattern matches the six new steps and the two existing key tests,agc_driver_dcc_keys_first_writeandagc_driver_dcc_key_presync.VUID-.VUID-.6330546a47, where the draw pipeline is on unlessAPS5_NO_DRAW_PIPELINEis set): all eight pass on both drivers, none skipped. NoVUID-.VK_LAYER_KHRONOS_validationinserted; no log reportswas not found but was requested by env var VK_INSTANCE_LAYERS.ctest -R '^agc'on the RX 9070 XT, without the validation layer, main + the head: 1 of 1352 fails,agc_driver_tessellation(segmentation fault), and 23 tests skip. On the earlier headb04dc41f0aover main3bd88ca119: 5 of 1349 failed with the test commit alone and 1 of 1349 with the fix; the four rewrite steps were the only difference in the failed list, with the same failing test and the same 23 skipped names as now.b04dc41f0athe epoch step failed there (JJenkx's run in this thread), by the code because the test read a header-defined counter across the library boundary;5287cda761reads through the library instead.python3 tools/check_conventions.py --base upstream/main: passes.No title effect is claimed.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-06T16:55:09Z.
Review: COMMENTED
One interaction with #15456 (the draw finisher by default), which edits neither file, so nothing will flag it as an overlap. On #15456's head
ShaderResources::EpochProofs()returnsDrawPipelineEnabled(), and that is true unlessAPS5_NO_DRAW_PIPELINEis set. Once it lands, every mode here runs with epoch proofs.--rewrite-after-memoand--rewrite-after-refresh-proofcan then be answered by the epoch proof instead of the memoized collect or the refresh's own proof. Their names and the description would no longer match the path they test, while--rewrite-after-epoch-proofstill passes. SettingAPS5_NO_DRAW_PIPELINE=1on the five non-epoch modes (and droppingAPS5_DRAW_PIPELINE=1from the epoch mode) would keep each mode on its own path, whichever of the two lands second.The rest reads right to me:
keysReplacedByClearonly keeps the store off when the guest wrote the keys since the key proof's generation, nothing recorded is pending over them, and what they hold now is a different clear code.AI-assisted: yes (Claude Code)