diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 333d4f4414..50ee98027d 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -405,8 +405,7 @@ inline void DeIndexTexture4Optimal(ClutT *dest, const u32 texaddr, int length, C DeIndexTexture4Optimal(dest, indexed, length, color); } -void *TextureCache::readIndexedTex(int level, u32 texaddr, int bytesPerIndex, GLuint dstFmt) { - int bufw = GetLevelBufw(level, texaddr); +void *TextureCache::ReadIndexedTex(int level, u32 texaddr, int bytesPerIndex, GLuint dstFmt, int bufw) { int w = gstate.getTextureWidth(level); int h = gstate.getTextureHeight(level); int length = bufw * h; @@ -796,6 +795,26 @@ static const u8 bitsPerPixel[16] = { 0, // INVALID, }; +// Masks to downalign bufw to 16 bytes. +static const u32 alignMask16[16] = { + ~(((8 * 16) / 16) - 1), //GE_TFMT_5650, + ~(((8 * 16) / 16) - 1), //GE_TFMT_5551, + ~(((8 * 16) / 16) - 1), //GE_TFMT_4444, + ~(((8 * 16) / 32) - 1), //GE_TFMT_8888, + ~(((8 * 16) / 4) - 1), //GE_TFMT_CLUT4, + ~(((8 * 16) / 8) - 1), //GE_TFMT_CLUT8, + ~(((8 * 16) / 16) - 1), //GE_TFMT_CLUT16, + ~(((8 * 16) / 32) - 1), //GE_TFMT_CLUT32, + ~(((8 * 16) / 4) - 1), //GE_TFMT_DXT1, + ~(((8 * 16) / 8) - 1), //GE_TFMT_DXT3, + ~(((8 * 16) / 8) - 1), //GE_TFMT_DXT5, + 0, // INVALID, + 0, // INVALID, + 0, // INVALID, + 0, // INVALID, + 0, // INVALID, +}; + static inline u32 MiniHash(const u32 *ptr) { return ptr[0]; } @@ -1289,7 +1308,11 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c u32 texaddr = (gstate.texaddr[level] & 0xFFFFF0) | ((gstate.texbufwidth[level] << 8) & 0x0F000000); - int bufw = GetLevelBufw(level, texaddr); + int bufw = GetLevelBufw(level, texaddr) & alignMask16[format]; + if (bufw == 0) { + // If it's less than 16 bytes, use 16 bytes. + bufw = (8 * 16) / bitsPerPixel[format]; + } int w = gstate.getTextureWidth(level); int h = gstate.getTextureHeight(level); @@ -1299,9 +1322,6 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c case GE_TFMT_CLUT4: { dstFmt = getClutDestFormat(clutformat); - // Don't allow this to be less than 16 bytes (32 * 4 / 8 = 16.) - if (bufw < 32) - bufw = 32; const bool mipmapShareClut = (gstate.texmode & 0x100) == 0; const int clutSharingOffset = mipmapShareClut ? 0 : level * 16; @@ -1360,34 +1380,26 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c break; case GE_TFMT_CLUT8: - if (bufw < 8) - bufw = 8; dstFmt = getClutDestFormat(gstate.getClutPaletteFormat()); texByteAlign = texByteAlignMap[gstate.getClutPaletteFormat()]; - finalBuf = readIndexedTex(level, texaddr, 1, dstFmt); + finalBuf = ReadIndexedTex(level, texaddr, 1, dstFmt, bufw); break; case GE_TFMT_CLUT16: - if (bufw < 8) - bufw = 8; dstFmt = getClutDestFormat(gstate.getClutPaletteFormat()); texByteAlign = texByteAlignMap[gstate.getClutPaletteFormat()]; - finalBuf = readIndexedTex(level, texaddr, 2, dstFmt); + finalBuf = ReadIndexedTex(level, texaddr, 2, dstFmt, bufw); break; case GE_TFMT_CLUT32: - if (bufw < 4) - bufw = 4; dstFmt = getClutDestFormat(gstate.getClutPaletteFormat()); texByteAlign = texByteAlignMap[gstate.getClutPaletteFormat()]; - finalBuf = readIndexedTex(level, texaddr, 4, dstFmt); + finalBuf = ReadIndexedTex(level, texaddr, 4, dstFmt, bufw); break; case GE_TFMT_4444: case GE_TFMT_5551: case GE_TFMT_5650: - if (bufw < 8) - bufw = 8; if (format == GE_TFMT_4444) dstFmt = GL_UNSIGNED_SHORT_4_4_4_4; else if (format == GE_TFMT_5551) @@ -1410,8 +1422,6 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c break; case GE_TFMT_8888: - if (bufw < 4) - bufw = 4; dstFmt = GL_UNSIGNED_BYTE; if (!gstate.isTextureSwizzled()) { // Special case: if we don't need to deal with packing, we don't need to copy. diff --git a/GPU/GLES/TextureCache.h b/GPU/GLES/TextureCache.h index bf7e58c573..7c1880b2df 100644 --- a/GPU/GLES/TextureCache.h +++ b/GPU/GLES/TextureCache.h @@ -115,7 +115,7 @@ private: void Decimate(); // Run this once per frame to get rid of old textures. void *UnswizzleFromMem(u32 texaddr, u32 bufw, u32 bytesPerPixel, u32 level); - void *readIndexedTex(int level, u32 texaddr, int bytesPerIndex, GLuint dstFmt); + void *ReadIndexedTex(int level, u32 texaddr, int bytesPerIndex, GLuint dstFmt, int bufw); void UpdateSamplingParams(TexCacheEntry &entry, bool force); void LoadTextureLevel(TexCacheEntry &entry, int level, bool replaceImages); void *DecodeTextureLevel(GETextureFormat format, GEPaletteFormat clutformat, int level, u32 &texByteAlign, GLenum &dstFmt);