From 8e09869ac25d2c0b1a867b8e0b3b39e397023855 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 24 Nov 2012 10:43:16 -0800 Subject: [PATCH 1/3] Invalidate the texcache without restarting loop. --- GPU/GLES/TextureCache.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index ca1a532d35..c5711cd548 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -84,16 +84,18 @@ void TextureCache_Clear(bool delete_them) // Removes old textures. void TextureCache_Decimate() { - // TODO: Need a better way to keep looping -restart: - for (TexCache::iterator iter = cache.begin(); iter != cache.end(); ++iter) + for (TexCache::iterator iter = cache.begin(); iter != cache.end(); ) { if (iter->second.frameCounter + TEXTURE_KILL_AGE < gpuStats.numFrames) { + TexCacheEntry &entry = iter->second; + NOTICE_LOG(G3D, "Deleted texture %i from %08x: fmt: %i", entry.texture, entry.addr, entry.format); + glDeleteTextures(1, &iter->second.texture); - cache.erase(iter); - goto restart; + cache.erase(iter++); } + else + ++iter; } } From 11868f26a985044c900650004a808fbfd8317f46 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 24 Nov 2012 10:58:10 -0800 Subject: [PATCH 2/3] Cache textures based on more parameters. This makes Tales of Eternia run much faster. --- GPU/GLES/TextureCache.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index c5711cd548..dc03857eae 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -53,7 +53,7 @@ struct TexCacheEntry GLuint texture; }; -typedef std::map TexCache; +typedef std::map TexCache; static TexCache cache; u32 tmpTexBuf32[1024 * 1024]; @@ -527,11 +527,15 @@ void PSPSetTexture() u8 level = 0; u32 format = gstate.texformat & 0xF; u32 clutformat = gstate.clutformat & 3; + u32 clutaddr = GetClutAddr(clutformat == GE_CMODE_32BIT_ABGR8888 ? 4 : 2); DEBUG_LOG(G3D,"Texture at %08x",texaddr); u8 *texptr = Memory::GetPointer(texaddr); + u32 texhash = texptr ? *(u32*)texptr : 0; - TexCache::iterator iter = cache.find(texaddr); + u64 cachekey = texaddr ^ clutaddr; + cachekey |= (u64) texhash << 32; + TexCache::iterator iter = cache.find(cachekey); if (iter != cache.end()) { //Validate the texture here (width, height etc) @@ -541,13 +545,13 @@ void PSPSetTexture() bool match = true; //TODO: Check more texture parameters, compute real texture hash - if (dim != entry.dim || entry.hash != *(u32*)texptr || entry.format != format) + if (dim != entry.dim || entry.hash != texhash || entry.format != format) match = false; //TODO: Check more clut parameters, compute clut hash if (match && (format >= GE_TFMT_CLUT4 && format <= GE_TFMT_CLUT32) && (entry.clutformat != clutformat || - entry.clutaddr != GetClutAddr(clutformat == GE_CMODE_32BIT_ABGR8888 ? 4 : 2) || + entry.clutaddr != clutaddr || entry.cluthash != Memory::Read_U32(entry.clutaddr))) match = false; @@ -574,7 +578,7 @@ void PSPSetTexture() TexCacheEntry entry; entry.addr = texaddr; - entry.hash = *(u32*)texptr; + entry.hash = texhash; entry.format = format; entry.frameCounter = gpuStats.numFrames; @@ -837,5 +841,5 @@ void PSPSetTexture() //glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_ALIGNMENT, 1); - cache[texaddr] = entry; + cache[cachekey] = entry; } From 8971ff7e997d417ca107e3ef270656ad20c0e00d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 24 Nov 2012 11:00:29 -0800 Subject: [PATCH 3/3] Don't log texture cache evictions. --- GPU/GLES/TextureCache.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index dc03857eae..0fa436b8d5 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -88,9 +88,6 @@ void TextureCache_Decimate() { if (iter->second.frameCounter + TEXTURE_KILL_AGE < gpuStats.numFrames) { - TexCacheEntry &entry = iter->second; - NOTICE_LOG(G3D, "Deleted texture %i from %08x: fmt: %i", entry.texture, entry.addr, entry.format); - glDeleteTextures(1, &iter->second.texture); cache.erase(iter++); }