From 4f925fa5f2fca95e46e4fb007e75a88479420055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 11 Jun 2026 11:51:43 +0200 Subject: [PATCH] Minor code cleanup --- GPU/Common/TextureCacheCommon.cpp | 31 +++++++++++++++++-------------- GPU/Common/TextureCacheCommon.h | 22 ++++++++-------------- GPU/GLES/TextureCacheGLES.cpp | 16 +++++++++------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index dc006f6ce8..0bd6347ae4 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -385,21 +385,24 @@ void TextureCacheCommon::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutB clutBuf_ = clutBufRaw_; // Special optimization: fonts typically draw clut4 with just alpha values in a single color. - clutAlphaLinear_ = false; - clutAlphaLinearColor_ = 0; + bool alphaLinear = false; + u16 alphaLinearColor = 0; if (clutFormat == GE_CMODE_16BIT_ABGR4444 && clutIndexIsSimple) { - const u16_le *clut = GetCurrentClut(); - clutAlphaLinear_ = true; - clutAlphaLinearColor_ = clut[15] & 0x0FFF; + const u16 *clut = (const u16 *)(clutBuf_); + alphaLinear = true; + alphaLinearColor = clut[15] & 0x0FFF; for (int i = 0; i < 16; ++i) { - u16 step = clutAlphaLinearColor_ | (i << 12); + u16 step = alphaLinearColor | (i << 12); if (clut[i] != step) { - clutAlphaLinear_ = false; + alphaLinear = false; break; } } } + clutProperties_.clutAlphaLinear = alphaLinear; + clutProperties_.clutAlphaLinearColor = alphaLinearColor; + clutLastFormat_ = gstate.clutformat; } @@ -1841,23 +1844,23 @@ TextureAlpha TextureCacheCommon::DecodeTextureLevel(u8 *out, int outPitch, GETex { // The w > 1 check is to not need a case that handles a single pixel // in DeIndexTexture4Optimal. - if (clutAlphaLinear_ && mipmapShareClut && !expandTo32bit && w >= 4) { - // We don't bother with fullalpha here (clutAlphaLinear_) + if (clutProperties_.clutAlphaLinear && mipmapShareClut && !expandTo32bit && w >= 4) { + // We don't bother with fullalpha here (clutAlphaLinear) // Here, reverseColors means the CLUT is already reversed. if (reverseColors) { for (int y = 0; y < h; ++y) { - DeIndexTexture4Optimal((u16 *)(out + outPitch * y), texptr + (bufw * y) / 2, w, clutAlphaLinearColor_); + DeIndexTexture4Optimal((u16 *)(out + outPitch * y), texptr + (bufw * y) / 2, w, clutProperties_.clutAlphaLinearColor); } } else { for (int y = 0; y < h; ++y) { - DeIndexTexture4OptimalRev((u16 *)(out + outPitch * y), texptr + (bufw * y) / 2, w, clutAlphaLinearColor_); + DeIndexTexture4OptimalRev((u16 *)(out + outPitch * y), texptr + (bufw * y) / 2, w, clutProperties_.clutAlphaLinearColor); } } } else { // Need to have the "un-reversed" (raw) CLUT here since we are using a generic conversion function. if (expandTo32bit) { // We simply expand the CLUT to 32-bit, then we deindex as usual. Probably the fastest way. - const u16 *clut = GetCurrentRawClut() + clutSharingOffset; + const u16 *clut = (const u16 *)(clutBufRaw_) + clutSharingOffset; const int clutStart = gstate.getClutIndexStartPos(); if (gstate.getClutIndexShift() == 0 || gstate.getClutIndexMask() <= 16) { ConvertFormatToRGBA8888(clutformat, expandClut_ + clutStart, clut + clutStart, 16); @@ -1871,7 +1874,7 @@ TextureAlpha TextureCacheCommon::DecodeTextureLevel(u8 *out, int outPitch, GETex } } else { // If we're reversing colors, the CLUT was already reversed, no special handling needed. - const u16 *clut = GetCurrentClut() + clutSharingOffset; + const u16 *clut = (const u16 *)(clutBuf_) + clutSharingOffset; fullAlphaMask = ClutFormatToFullAlpha(clutformat, reverseColors); for (int y = 0; y < h; ++y) { DeIndexTexture4((u16 *)(out + outPitch * y), texptr + (bufw * y) / 2, w, clut, &alphaSum); @@ -1888,7 +1891,7 @@ TextureAlpha TextureCacheCommon::DecodeTextureLevel(u8 *out, int outPitch, GETex case GE_CMODE_32BIT_ABGR8888: { - const u32 *clut = GetCurrentClut() + clutSharingOffset; + const u32 *clut = (const u32 *)(clutBuf_) + clutSharingOffset; fullAlphaMask = 0xFF000000; for (int y = 0; y < h; ++y) { DeIndexTexture4((u32 *)(out + outPitch * y), texptr + (bufw * y) / 2, w, clut, &alphaSum); diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 1592a135f3..8804620089 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -247,6 +247,12 @@ struct AttachCandidate { std::string ToString() const; }; +struct CLUTProperties { + // True if the clut is just alpha values in the same order (RGBA4444-bit only.) + bool clutAlphaLinear = false; + u16 clutAlphaLinearColor; +}; + class FramebufferManagerCommon; struct BuildTexturePlan { @@ -416,16 +422,6 @@ protected: // Return value is mapData normally, but could be another buffer allocated with AllocateAlignedMemory. void LoadTextureLevel(TexCacheEntry &entry, uint8_t *mapData, size_t dataSize, int mapRowPitch, BuildTexturePlan &plan, int srcLevel, Draw::DataFormat dstFmt, TexDecodeFlags texDecFlags); - template - inline const T *GetCurrentClut() { - return (const T *)clutBuf_; - } - - template - inline const T *GetCurrentRawClut() { - return (const T *)clutBufRaw_; - } - // These need to be member functions just for IsVideo and Replacer. SamplerCacheKey GetSamplingParams(int maxLevel, const TexCacheEntry *entry, bool flatZ); SamplerCacheKey GetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight); @@ -517,16 +513,14 @@ protected: u32 *clutBufConverted_; // This is the active one. u32 *clutBuf_; + u32 clutLastFormat_ = 0xFFFFFFFF; u32 clutTotalBytes_ = 0; u32 clutMaxBytes_ = 0; u32 clutRenderAddress_ = 0xFFFFFFFF; u32 clutRenderOffset_; GEBufferFormat clutRenderFormat_; - - // True if the clut is just alpha values in the same order (RGBA4444-bit only.) - bool clutAlphaLinear_ = false; - u16 clutAlphaLinearColor_; + CLUTProperties clutProperties_; // Facilities for GPU depal of static textures. Draw::Framebuffer *dynamicClutTemp_ = nullptr; diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index e78d5c6b75..8519ac369e 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -174,20 +174,22 @@ void TextureCacheGLES::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBas } // Special optimization: fonts typically draw clut4 with just alpha values in a single color. - clutAlphaLinear_ = false; - clutAlphaLinearColor_ = 0; + bool alphaLinear = false; + u16 alphaLinearColor = 0; if (clutFormat == GE_CMODE_16BIT_ABGR4444 && clutIndexIsSimple) { - const u16_le *clut = GetCurrentClut(); - clutAlphaLinear_ = true; - clutAlphaLinearColor_ = clut[15] & 0xFFF0; + const u16 *clut = (const u16 *)(clutBuf_); + alphaLinear = true; + alphaLinearColor = clut[15] & 0xFFF0; for (int i = 0; i < 16; ++i) { - u16 step = clutAlphaLinearColor_ | i; + u16 step = alphaLinearColor | i; if (clut[i] != step) { - clutAlphaLinear_ = false; + alphaLinear = false; break; } } } + clutProperties_.clutAlphaLinear = alphaLinear; + clutProperties_.clutAlphaLinearColor = alphaLinearColor; clutLastFormat_ = gstate.clutformat; }