From 04cd6c4f7db1e8ca3b7c7fd3868c1dc6f2ca52a3 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 7 Nov 2022 18:15:14 -0800 Subject: [PATCH] TexCache: Align expandClut buffer, cleanup sizes. We shouldn't need larger than 2 KB CLUT buffers, since it's actually only 1 KB. We have a hack that allows 2 KB for separate mip map levels. --- GPU/Common/TextureCacheCommon.cpp | 18 +++++++++--------- GPU/Common/TextureCacheCommon.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 53962e7644..eece8ac9d5 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -105,19 +105,18 @@ inline int dimHeight(u16 dim) { return 1 << ((dim >> 8) & 0xFF); } -// Vulkan color formats: -// TODO TextureCacheCommon::TextureCacheCommon(Draw::DrawContext *draw, Draw2D *draw2D) : draw_(draw), draw2D_(draw2D) { decimationCounter_ = TEXCACHE_DECIMATION_INTERVAL; - // TODO: Clamp down to 256/1KB? Need to check mipmapShareClut and clamp loadclut. - clutBufRaw_ = (u32 *)AllocateAlignedMemory(1024 * sizeof(u32), 16); // 4KB - clutBufConverted_ = (u32 *)AllocateAlignedMemory(1024 * sizeof(u32), 16); // 4KB + // It's only possible to have 1KB of palette entries, although we allow 2KB in a hack. + clutBufRaw_ = (u32 *)AllocateAlignedMemory(2048, 16); + clutBufConverted_ = (u32 *)AllocateAlignedMemory(2048, 16); + expandClut_ = (u32 *)AllocateAlignedMemory(1024, 16); // Zap so we get consistent behavior if the game fails to load some of the CLUT. - memset(clutBufRaw_, 0, 1024 * sizeof(u32)); - memset(clutBufConverted_, 0, 1024 * sizeof(u32)); + memset(clutBufRaw_, 0, 2048); + memset(clutBufConverted_, 0, 2048); clutBuf_ = clutBufConverted_; // These buffers will grow if necessary, but most won't need more than this. @@ -134,6 +133,7 @@ TextureCacheCommon::~TextureCacheCommon() { FreeAlignedMemory(clutBufConverted_); FreeAlignedMemory(clutBufRaw_); + FreeAlignedMemory(expandClut_); } // Produces a signed 1.23.8 value. @@ -1236,8 +1236,7 @@ void TextureCacheCommon::LoadClut(u32 clutAddr, u32 loadBytes) { return; } - u32 startPos = gstate.getClutIndexStartPos(); - + _assert_(loadBytes <= 2048); clutTotalBytes_ = loadBytes; clutRenderAddress_ = 0xFFFFFFFF; @@ -1320,6 +1319,7 @@ void TextureCacheCommon::LoadClut(u32 clutAddr, u32 loadBytes) { // It's possible for a game to load CLUT outside valid memory without crashing, should result in zeroes. u32 bytes = Memory::ValidSize(clutAddr, loadBytes); + _assert_(bytes <= 2048); bool performDownload = PSP_CoreParameter().compat.flags().AllowDownloadCLUT; if (GPURecord::IsActive()) performDownload = true; diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 889dbb85b5..bbaf0eecde 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -507,7 +507,7 @@ protected: bool isBgraBackend_ = false; - u32 expandClut_[256]; + u32 *expandClut_; }; inline bool TexCacheEntry::Matches(u16 dim2, u8 format2, u8 maxLevel2) const {