mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(agc): size CMASK by whole 1024x512 metablocks
A CMASK holds 4 KiB per 1024x512-pixel metablock, not one nibble per 8x8 tile of the target: 1920x1080 spans 0x6000 bytes, as titles clear it, not 16200. The swizzled nibbles of the lower-right tiles lie past the packed size, so the fast-clear check missed them and the expanded store left them cleared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -102,6 +102,7 @@ ShaderStages DecodeShaderStages(const QueueState& queue);
|
||||
State DecodeState(const QueueState& queue);
|
||||
std::array<std::uint8_t, 8> ExportMappings(const State& state);
|
||||
ColorTarget DecodeColorBuffer(const Registers& context, std::uint32_t slot);
|
||||
std::size_t CmaskBytes(std::uint32_t width, std::uint32_t height);
|
||||
|
||||
struct ColorMetadataPass {
|
||||
enum class Mode { EliminateFastClear, DccDecompress };
|
||||
|
||||
@@ -631,6 +631,13 @@ std::array<std::uint8_t, 8> ExportMappings(const State& state) {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
std::size_t CmaskBytes(std::uint32_t width, std::uint32_t height) {
|
||||
constexpr std::size_t metablockWidth = 1024;
|
||||
constexpr std::size_t metablockHeight = 512;
|
||||
constexpr std::size_t metablockBytes = 4096;
|
||||
return ((width + metablockWidth - 1) / metablockWidth) * ((height + metablockHeight - 1) / metablockHeight) * metablockBytes;
|
||||
}
|
||||
|
||||
ColorTarget DecodeColorBuffer(const Registers& cx, std::uint32_t slot) {
|
||||
const auto stride = slot * 0xfu;
|
||||
ColorTarget color{};
|
||||
@@ -695,7 +702,7 @@ ColorTarget DecodeColorBuffer(const Registers& cx, std::uint32_t slot) {
|
||||
const auto cmaskHigh = find(cx, 0x398 + slot);
|
||||
color.cmaskAddress = ((cmaskHigh == cx.end() ? 0ull : static_cast<std::uint64_t>(cmaskHigh->second & 0xffu)) << 40u) | (static_cast<std::uint64_t>(read(cx, 0x31f + stride)) << 8u);
|
||||
Require(color.cmaskAddress != 0, "CMASK fast clears without a CMASK address are unsupported");
|
||||
color.cmaskBytes = (static_cast<std::size_t>((color.extent.width + 7u) / 8u) * ((color.extent.height + 7u) / 8u) + 1u) / 2u;
|
||||
color.cmaskBytes = CmaskBytes(color.extent.width, color.extent.height);
|
||||
}
|
||||
if ((info & 0x10000000u) != 0) {
|
||||
if (maxMip == 0) {
|
||||
|
||||
@@ -819,7 +819,7 @@ void metadataPassTests() {
|
||||
}
|
||||
}
|
||||
|
||||
alignas(256) std::array<std::uint8_t, 4> cmaskMemory{};
|
||||
alignas(256) std::array<std::uint8_t, 4096> cmaskMemory{};
|
||||
|
||||
void cmaskTests() {
|
||||
using AgcDriver::Graphics::DecodeColorBuffer;
|
||||
@@ -833,6 +833,8 @@ void cmaskTests() {
|
||||
const auto target = DecodeColorBuffer(queue.context, 0);
|
||||
Require(target.cmaskAddress == cmaskAddress && target.cmaskBytes == cmaskMemory.size(), "the fast-clear target lost its CMASK");
|
||||
Require(DecodeColorBuffer(makeState().context, 0).cmaskAddress == 0, "a target without FAST_CLEAR got a CMASK");
|
||||
using AgcDriver::Graphics::CmaskBytes;
|
||||
Require(CmaskBytes(1920, 1080) == 0x6000 && CmaskBytes(960, 544) == 0x2000 && CmaskBytes(800, 450) == 0x1000 && CmaskBytes(1024, 512) == 0x1000 && CmaskBytes(3840, 2160) == 0x14000, "a CMASK does not span whole 1024x512 metablocks");
|
||||
auto mipmapped = queue;
|
||||
mipmapped.context[0x3b0] |= 1u << 28u;
|
||||
expectFailure([&] { DecodeColorBuffer(mipmapped.context, 0); }, "mipmapped, 3D or array");
|
||||
@@ -862,7 +864,8 @@ void cmaskTests() {
|
||||
std::memset(colorMemory.data(), 0x5a, colorMemory.size());
|
||||
AgcDriver::Graphics::RunColorMetadataPass(context, *pass);
|
||||
Require(texels(0x5a5a5a5au) && cmaskIs(0xff), "a pass over an expanded CMASK changed the texels");
|
||||
cmaskMemory = {0x00, 0xff, 0x00, 0x00};
|
||||
cmaskMemory.fill(0);
|
||||
cmaskMemory[cmaskMemory.size() - 1] = 0xff;
|
||||
expectFailure([&] { AgcDriver::Graphics::RunColorMetadataPass(context, *pass); }, "not all fast-cleared or all expanded");
|
||||
Require(texels(0x5a5a5a5au), "a refused pass changed the texels");
|
||||
|
||||
|
||||
@@ -273,7 +273,7 @@ Throughout the project, every function at every stage either **does exactly what
|
||||
- The Linux placement of the `--to-intel` stubs in the [ELF patcher](../../core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp) is covered only by a synthetic test.
|
||||
- The libc [SSE4a trap emulation](../../core/libs/prx/libc/src/specifics/windows/Sse4aEmulation.hpp) on Windows is superseded by `--to-intel` and remains only until the relinked title has been verified without it.
|
||||
- [Descriptor pool chain](../../core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp) (libSceAgcDriver) - each pool holds two storage buffer descriptors more than a set can take, as a workaround: RADV (Mesa 26.0 and later) lets a `FREE_DESCRIPTOR_SET` pool place a set up to 32 bytes past the pool's buffer ([`util_vma_heap_init`](https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/amd/vulkan/radv_descriptor_pool.c) is given `bo_size + RADV_POOL_HEAP_OFFSET` as a size), and with a page-multiple pool size those bytes are an unmapped page
|
||||
- [CMASK fast clears](../../core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp) (libSceAgcDriver) - only a CMASK whose nibbles are all fast-cleared (0) or all expanded (0xF) is modeled, checked over one nibble per 8x8 tile of the target from its start; the console's CMASK layout (pipe alignment, padding) is not decoded. The first draw or fast-clear eliminate over a fast-cleared CMASK fills the whole target with `CB_COLOR_CLEAR_WORD` and stores those bytes as expanded, so a draw that covers only part of the target reads the clear value in the rest as the eliminate would leave it. On a DCC target the clear is in the DCC keys, so its CMASK must be all expanded. A mixed CMASK throws, as does a DCC target's CMASK that is not all expanded and a fast clear of a mipmapped, 3D or array color target
|
||||
- [CMASK fast clears](../../core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp) (libSceAgcDriver) - only a CMASK whose nibbles are all fast-cleared (0) or all expanded (0xF) is modeled, checked over the target's whole CMASK, 4 KiB per 1024x512-pixel metablock (the size PS5 titles clear, for every color format seen); the addressing within a metablock is not decoded. The first draw or fast-clear eliminate over a fast-cleared CMASK fills the whole target with `CB_COLOR_CLEAR_WORD` and stores those bytes as expanded, so a draw that covers only part of the target reads the clear value in the rest as the eliminate would leave it. On a DCC target the clear is in the DCC keys, so its CMASK must be all expanded. A mixed CMASK throws, as does a DCC target's CMASK that is not all expanded and a fast clear of a mipmapped, 3D or array color target
|
||||
- [DCC display buffers](../../core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp) are presented only from uniform uncompressed or fast-clear keys; other keys, and register-clear keys over a pending image, throw. Keys are read as one byte per 256 bytes (the driver's model), not in the console's layout.
|
||||
- [8_SRGB color targets](../../core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp) (libSceAgcDriver) on a device that cannot attach and blend R8_SRGB render into an RGBA8_SRGB copy of the target, so the sRGB encode, decode and blend rounding are the device's; the console's are not measured.
|
||||
- [8_SRGB color targets](../../core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp) (libSceAgcDriver) on such a device throw unless they are single-mip 2D surfaces with a resident image; linear targets have none.
|
||||
|
||||
Reference in New Issue
Block a user