From cd9e6a8d23a830d45f6f6b39c5ced27bb568dcfc Mon Sep 17 00:00:00 2001 From: "baby.lueshi" Date: Fri, 4 Feb 2011 22:51:17 +0000 Subject: [PATCH] Change the recent speedup to the hashing function to fall back to the old version for custom textures. Re-fixed custom textures higher than 1024x1024. (It must have accidentally got reverted somewhere during the video plugin merge) git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7064 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/Hash.cpp | 9 +++++++-- Source/Core/Common/Src/Hash.h | 2 +- Source/Core/VideoCommon/Src/TextureCacheBase.cpp | 13 +++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Source/Core/Common/Src/Hash.cpp b/Source/Core/Common/Src/Hash.cpp index 6741ec2f14..f7e6dba6f5 100644 --- a/Source/Core/Common/Src/Hash.cpp +++ b/Source/Core/Common/Src/Hash.cpp @@ -133,18 +133,23 @@ u64 GetCRC32(const u8 *src, int len, u32 samples) #endif } -u64 GetHash64(const u8 *src, int len, u32 samples) +u64 GetHash64(const u8 *src, int len, u32 samples, bool legacy) { const u64 m = 0xc6a4a7935bd1e995; u64 h = len * m; #if _M_SSE >= 0x402 - if (cpu_info.bSSE4_2) + if (cpu_info.bSSE4_2 && !legacy) { h = GetCRC32(src, len, samples); } else #endif + /* NOTE: This hash function is used for custom texture loading/dumping, so + it should not be changed, which would require all custom textures to be + recalculated for their new hash values. If the hashing function is + changed, make sure this one is still used when the legacy parameter is + true. */ { const int r = 47; u32 Step = (len / 8); diff --git a/Source/Core/Common/Src/Hash.h b/Source/Core/Common/Src/Hash.h index 5b71444f32..fb5a3b1127 100644 --- a/Source/Core/Common/Src/Hash.h +++ b/Source/Core/Common/Src/Hash.h @@ -25,5 +25,5 @@ u32 HashAdler32(const u8* data, size_t len); // Fairly accurate, slightl u32 HashFNV(const u8* ptr, int length); // Another fast and decent hash u32 HashEctor(const u8* ptr, int length); // JUNK. DO NOT USE FOR NEW THINGS u64 GetCRC32(const u8 *src, int len, u32 samples); // SSE4.2 version of CRC32 -u64 GetHash64(const u8 *src, int len, u32 samples); +u64 GetHash64(const u8 *src, int len, u32 samples, bool legacy = false); #endif // _HASH_H_ diff --git a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp index ad487acd18..3989cc57b6 100644 --- a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp @@ -17,7 +17,7 @@ extern int frameCount; enum { - TEMP_SIZE = (1024 * 1024 * 4), + TEMP_SIZE = (2048 * 2048 * 4), TEXTURE_KILL_THRESHOLD = 200, }; @@ -180,6 +180,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, const u32 texture_size = TexDecoder_GetTextureSizeInBytes(expandedWidth, expandedHeight, texformat); const u32 palette_size = TexDecoder_GetPaletteSize(texformat); bool texture_is_dynamic = false; + bool forceLegacyHash = (g_ActiveConfig.bHiresTextures || g_ActiveConfig.bDumpTextures); unsigned int texLevels; PC_TexFormat pcfmt = PC_TEX_FMT_NONE; @@ -190,9 +191,9 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, full_format = texformat | (tlutfmt << 16); // hires texture loading and texture dumping require accurate hashes - if (g_ActiveConfig.bSafeTextureCache || g_ActiveConfig.bHiresTextures || g_ActiveConfig.bDumpTextures) + if (g_ActiveConfig.bSafeTextureCache || forceLegacyHash) { - texHash = GetHash64(ptr, texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples); + texHash = GetHash64(ptr, texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples, forceLegacyHash); if (isC4_C8_C14X2) { @@ -205,7 +206,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, // we must make sure that texture with different tluts get different IDs. const u64 tlutHash = GetHash64(texMem + tlutaddr, palette_size, - g_ActiveConfig.iSafeTextureCache_ColorSamples); + g_ActiveConfig.iSafeTextureCache_ColorSamples, forceLegacyHash); texHash ^= tlutHash; @@ -285,7 +286,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, unsigned int newWidth = width; unsigned int newHeight = height; - sprintf(texPathTemp, "%s_%08llx_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), texHash, texformat); + sprintf(texPathTemp, "%s_%08lx_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32) (texHash & 0x00000000FFFFFFFFLL), texformat); pcfmt = HiresTextures::GetHiresTex(texPathTemp, &newWidth, &newHeight, texformat, temp); if (pcfmt != PC_TEX_FMT_NONE) @@ -386,7 +387,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, if (false == File::Exists(szDir) || false == File::IsDirectory(szDir)) File::CreateDir(szDir); - sprintf(szTemp, "%s/%s_%08llx_%i.png", szDir, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), texHash, texformat); + sprintf(szTemp, "%s/%s_%08lx_%i.png", szDir, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32) (texHash & 0x00000000FFFFFFFFLL), texformat); if (false == File::Exists(szTemp)) entry->Save(szTemp);