From ccddd4f89b2ef5398a7c225a3e9671567226c754 Mon Sep 17 00:00:00 2001 From: Celegans12 <53881228+Celegans12@users.noreply.github.com> Date: Thu, 8 Oct 2026 12:55:45 +0200 Subject: [PATCH] fix(agc): forget a DCC key fill once a refresh sees other keys StorageTexture::MarkDirty skips the first write's uncompressed key store while the image's filledKeys holds a clear code, and only an upload or clearByKeysFill reset that fill. After a 0001 key fill, a kernel storing 0000 over the keys and a storage write, the refresh of write-watched memory read 0000, the keys the image was uploaded under, so it did not upload again and kept the stale 0001. The write then left the 0000 keys in memory, and a kernel reading them saw the clear colour. StorageTexture::ProvedKeys, the key read of Refresh and the fast revalidation, now forgets the fill when it reads other keys while the image has no results pending. An image with pending results keeps it, since its write-backs treat those results as killed by that fill. --- .../Graphics/include/Texture.hpp | 2 +- .../libSceAgcDriver/Graphics/src/Texture.cpp | 13 ++++++------- .../tests/execution/DccKeysFirstWrite.cpp | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp index 31916bbd9..7072b93dd 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp @@ -422,7 +422,7 @@ private: std::vector original; // DCC keys the image content was uploaded under: a fast-cleared surface starts as its clear value. DccKeys uploadedKeys = DccKeys::Uncompressed; - DccKeys filledKeys = DccKeys::Uncompressed; + mutable DccKeys filledKeys = DccKeys::Uncompressed; mutable DccKeyProof keyProof; struct ForeignKeyProof { std::uint64_t dccAddress = 0; diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp index 249b7f754..10aa6052d 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp @@ -1324,13 +1324,12 @@ bool StorageTexture::Refresh() { } DccKeys StorageTexture::ProvedKeys() const { - if (descriptor.dccAddress != 0 && uploadedKeys == DccKeys::Uncompressed) { - if (const auto keys = WaitForKeyWriters(descriptor, guestBytes)) { - keyProof = {}; - return *keys; - } - } - return ProvedClearKeys(descriptor, guestBytes, keyProof); + std::optional keys; + if (descriptor.dccAddress != 0 && uploadedKeys == DccKeys::Uncompressed) keys = WaitForKeyWriters(descriptor, guestBytes); + if (keys.has_value()) keyProof = {}; + else keys = ProvedClearKeys(descriptor, guestBytes, keyProof); + if (IsDccClear(filledKeys) && *keys != filledKeys && !anyLayerPending()) filledKeys = DccKeys::Uncompressed; + return *keys; } bool StorageTexture::ServesKeysAt(std::uint64_t dccAddress) const { diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/DccKeysFirstWrite.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/DccKeysFirstWrite.cpp index 0375be15f..365b32358 100644 --- a/core/libs/prx/libSceAgcDriver/tests/execution/DccKeysFirstWrite.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/execution/DccKeysFirstWrite.cpp @@ -268,6 +268,24 @@ void Run(AgcDriver::VulkanDevice& device, std::uint8_t* block) { StorageTexture::FlushPending(surface, SurfaceBytes, nullptr, "test"); device.WaitIdle(); requireTexels("a first write followed by a kernel's 0000 store over half the keys"); + fillKeys(0x00, DccKeys::Clear0000); + image->Refresh(); + Require(image->UploadedKeys() == DccKeys::Clear0000 && image->FilledKeys() == DccKeys::Uncompressed, "the refresh after a 0000 key fill did not clear the image"); + fillKeys(0x40, DccKeys::Clear0001); + Require(image->FilledKeys() == DccKeys::Clear0001, "the 0001 key fill over the cleared image was not noted on it"); + Dispatch(device, ClearKeysCode, clearData); + const auto overFill = image->ProvedKeys(); + std::snprintf(message, sizeof(message), "a key read after a kernel's 0000 store over a 0001 key fill: the keys read %s and the image keeps a %s fill (expected 0000 and none)", AgcDriver::Graphics::DccKeysName(overFill), AgcDriver::Graphics::DccKeysName(image->FilledKeys())); + Require(overFill == DccKeys::Clear0000 && image->FilledKeys() == DccKeys::Uncompressed, message); + std::memset(copied, 0xaa, KeyBytes); + fillKeys(0x40, DccKeys::Clear0001); + Dispatch(device, ClearKeysCode, clearData); + Dispatch(device, WriteCode, writeData); + Dispatch(device, CopyKeysCode, copyData); + RequireKeys(copied, 0xff, "a kernel reading the keys after a 0001 key fill, a kernel's 0000 store over them and a write"); + StorageTexture::FlushPending(surface, SurfaceBytes, nullptr, "test"); + device.WaitIdle(); + requireTexels("a write after a 0001 key fill and a kernel's 0000 store over the keys"); const auto fill = [&](std::size_t offset, std::size_t bytes, std::uint8_t key) { const std::uint32_t word = key * 0x01010101u; const std::array pattern{word, word, word, word};