From 3a48a57dc765008e3aa4afdd1c9f2f85b9e32d80 Mon Sep 17 00:00:00 2001 From: Celegans12 <53881228+Celegans12@users.noreply.github.com> Date: Mon, 5 Oct 2026 23:17:14 +0200 Subject: [PATCH] feat(agc): encode the DCC clear codes of A2R10G10B10 color targets LayoutFor had no case for VK_FORMAT_A2R10G10B10_UNORM_PACK32, the format of a COLOR_2_10_10_10 color target with the alternate component swap, so FillDccClear could not encode its 0001, 1110 and 1111 clear codes. The format now takes the A2B10G10R10 layout: the codes set the three color channels alike, so both packings give the same words. A draw into a copied target under these keys now starts from the clear value instead of the stored texels, and clearTexel (the CB metadata pass and storeClearTexels) returns the texel instead of throwing. Textures and resident targets, stored as A2B10G10R10, and DccAlphaOnMsb are unchanged. Split out of #648. --- .../Graphics/src/DccMetadata.cpp | 2 +- .../prx/libSceAgcDriver/tests/Graphics.cpp | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/DccMetadata.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/DccMetadata.cpp index 43d168e2e..76f32bb58 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/DccMetadata.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/DccMetadata.cpp @@ -327,7 +327,7 @@ bool LayoutFor(VkFormat format, Layout& layout) { case VK_FORMAT_R16G16_UINT: layout = {2, {16, 16}, Kind::Uint}; return true; case VK_FORMAT_R16G16_SINT: layout = {2, {16, 16}, Kind::Sint}; return true; case VK_FORMAT_R16G16_SFLOAT: layout = {2, {16, 16}, Kind::Float}; return true; - case VK_FORMAT_A2B10G10R10_UNORM_PACK32: layout = {4, {10, 10, 10, 2}, Kind::Unorm}; return true; + case VK_FORMAT_A2B10G10R10_UNORM_PACK32: case VK_FORMAT_A2R10G10B10_UNORM_PACK32: layout = {4, {10, 10, 10, 2}, Kind::Unorm}; return true; case VK_FORMAT_A2B10G10R10_UINT_PACK32: layout = {4, {10, 10, 10, 2}, Kind::Uint}; return true; case VK_FORMAT_R8G8B8A8_UNORM: case VK_FORMAT_R8G8B8A8_SRGB: case VK_FORMAT_B8G8R8A8_UNORM: case VK_FORMAT_B8G8R8A8_SRGB: layout = {4, {8, 8, 8, 8}, Kind::Unorm}; return true; case VK_FORMAT_R8G8B8A8_SNORM: layout = {4, {8, 8, 8, 8}, Kind::Snorm}; return true; diff --git a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp index 75b240db0..eb8cfad1c 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp @@ -5,6 +5,7 @@ #include "prx/libSceAgcDriver/Graphics/include/VertexInput.hpp" #include "prx/libSceAgcDriver/Graphics/include/Draw.hpp" #include "prx/libSceAgcDriver/Graphics/include/ShaderInputState.hpp" +#include "prx/libSceAgcDriver/Graphics/include/DccMetadata.hpp" #include "ControlFlow/RequestSerializer.hpp" #include #include @@ -698,6 +699,31 @@ void metadataPassTests() { pass->targets[0].dccAddress = 0; AgcDriver::Graphics::RunColorMetadataPass(context, *pass); Require(texels(0x5a5a5a5au), "a pass over a target without DCC changed its texels"); + + using AgcDriver::Graphics::DccKeys; + struct TenBitClear { + std::uint8_t key; + DccKeys keys; + std::uint32_t texel; + const char* code; + }; + for (const std::uint32_t swap : {0u, 1u}) { + auto tenBit = queue; + tenBit.context[0x31c] = (tenBit.context[0x31c] & ~0x187cu) | (9u << 2u) | (swap << 11u); + const auto tenBitPass = DecodeColorMetadataPass(tenBit); + const auto format = swap == 0 ? VK_FORMAT_A2B10G10R10_UNORM_PACK32 : VK_FORMAT_A2R10G10B10_UNORM_PACK32; + const std::string name = swap == 0 ? "A2B10G10R10" : "A2R10G10B10"; + Require(tenBitPass.has_value() && tenBitPass->targets.size() == 1 && tenBitPass->targets[0].format == format && tenBitPass->targets[0].dccAlphaOnMsb, "the " + name + " metadata pass target changed"); + for (const auto& clear : {TenBitClear{0x00, DccKeys::Clear0000, 0u, "0000"}, TenBitClear{0x40, DccKeys::Clear0001, 0xc0000000u, "0001"}, TenBitClear{0x80, DccKeys::Clear1110, 0x3fffffffu, "1110"}, TenBitClear{0xc0, DccKeys::Clear1111, 0xffffffffu, "1111"}}) { + std::memset(colorMemory.data(), 0x5a, colorMemory.size()); + dccKeys.fill(clear.key); + AgcDriver::Graphics::RunColorMetadataPass(context, *tenBitPass); + Require(texels(clear.texel) && keysAre(0xff), "a " + std::string(clear.code) + " fast clear of an " + name + " target was not eliminated into its 10/10/10/2 texel"); + std::array copied{}; + copied.fill(0x5a5a5a5au); + Require(AgcDriver::Graphics::FillDccClear(tenBitPass->targets[0].format, clear.keys, tenBitPass->targets[0].dccAlphaOnMsb, std::as_writable_bytes(std::span(copied))) && std::ranges::all_of(copied, [&](std::uint32_t word) { return word == clear.texel; }), "a copied " + name + " target under " + clear.code + " keys was not filled with its 10/10/10/2 texel"); + } + } } void DepthClipTests() {