From 2cb9e09ad3edaa859fdc1796b69c4d4e26c2a1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 25 Jul 2022 20:51:52 +0200 Subject: [PATCH] Implement new discovery of a larger CLUT than we thought, plus non-shared CLUTs for 8-bit indices. Not sure yet what limitations apply, regarding using it for even more 16-bit colors, etc... --- GPU/Common/FragmentShaderGenerator.cpp | 4 ++-- GPU/Common/TextureCacheCommon.cpp | 8 ++++++-- GPU/GPUState.h | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index 285d813531..2a6296ab70 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -560,7 +560,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu } } else { if (texture3D) { - WRITE(p, " float bias = pow(u_mipBias, 1.0);\n"); + WRITE(p, " float bias = u_mipBias * 1.0;\n"); if (doTextureProjection) { WRITE(p, " vec4 t = %sProj(tex, vec4(%s.xy, bias, %s.z));\n", compat.texture, texcoord, texcoord); } else { @@ -573,7 +573,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, " vec4 t = %s(tex, %s.xy);\n", compat.texture, texcoord); } } - } + } } else { if (doTextureProjection) { // We don't use textureProj because we need better control and it's probably not much of a savings anyway. diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index bd214bbb4b..92605780a1 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1678,10 +1678,13 @@ CheckAlphaResult TextureCacheCommon::ReadIndexedTex(u8 *out, int outPitch, int l texptr = (u8 *)tmpTexBuf32_.data(); } + const bool mipmapShareClut = gstate.isClutSharedForMipmaps(); + const int clutSharingOffset = mipmapShareClut ? 0 : (level & 1) * 256; + GEPaletteFormat palFormat = (GEPaletteFormat)gstate.getClutPaletteFormat(); - const u16 *clut16 = (const u16 *)clutBuf_; - const u32 *clut32 = (const u32 *)clutBuf_; + const u16 *clut16 = (const u16 *)clutBuf_ + clutSharingOffset; + const u32 *clut32 = (const u32 *)clutBuf_ + clutSharingOffset; if (expandTo32Bit && palFormat != GE_CMODE_32BIT_ABGR8888) { ConvertFormatToRGBA8888(GEPaletteFormat(palFormat), expandClut_, clut16, 256); @@ -1721,6 +1724,7 @@ CheckAlphaResult TextureCacheCommon::ReadIndexedTex(u8 *out, int outPitch, int l case GE_CMODE_32BIT_ABGR8888: { + switch (bytesPerIndex) { case 1: for (int y = 0; y < h; ++y) { diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 4bd4dae890..8675afd109 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -300,8 +300,8 @@ struct GPUgstate { bool isTextureFormatIndexed() const { return (texformat & 4) != 0; } // GE_TFMT_CLUT4 - GE_TFMT_CLUT32 are 0b1xx. int getTextureEnvColRGB() const { return texenvcolor & 0x00FFFFFF; } u32 getClutAddress() const { return (clutaddr & 0x00FFFFF0) | ((clutaddrupper << 8) & 0x0F000000); } - int getClutLoadBytes() const { return (loadclut & 0x3F) * 32; } - int getClutLoadBlocks() const { return (loadclut & 0x3F); } + int getClutLoadBytes() const { return (loadclut & 0x7F) * 32; } + int getClutLoadBlocks() const { return (loadclut & 0x7F); } GEPaletteFormat getClutPaletteFormat() const { return static_cast(clutformat & 3); } int getClutIndexShift() const { return (clutformat >> 2) & 0x1F; } int getClutIndexMask() const { return (clutformat >> 8) & 0xFF; }