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};