second try to implement a more correct safe texture cache, implemented full hashing of tlut textures as they are the more problematic, this should solve virtually all the problems with characters in all the games that have them.

sorry to tell but this will bring a speed drop, so let you decide if this change stay or not.( used the fastest open source hash algorithm i know) 
do not apply full hashing to other format because it kills the performance.
for popular request added 9x SSAA believe me will kill your graphic card even if is the best but the image quality is exceptional.
as always please test and let me know the results.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5034 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Rodolfo Osvaldo Bogado
2010-02-08 23:23:04 +00:00
parent 2d58a2a864
commit e93e777ffb
11 changed files with 332 additions and 175 deletions

View File

@ -88,57 +88,58 @@ int TexDecoder_GetTextureSizeInBytes(int width, int height, int format)
return (width * height * TexDecoder_GetTexelSizeInNibbles(format)) / 2;
}
/*u64 TexDecoder_GetTlutHash(const u8* src, int len)
u64 TexDecoder_GetFullHash(const u8 *key, int len, u64 seed)
{
//char str[40000], st[20]; str[0]='\0';for (int i=0;i<len;i++){sprintf(st,"%02x ",src[i]);strcat(str,st);}
u64 hash = 0xbeefbabe1337c0de;
int step = len / 29 / 8;
if (!step) step = 1;
for (int i = 0; i < len/8; i += step) {
hash = _rotl64(hash, 17) ^ ((u64 *)(src + i))[0];
}
return hash;
}
const u64 m = 0xc6a4a7935bd1e995;
const int r = 47;
u64 TexDecoder_GetSafeTextureHash(const u8 *src, int width, int height, int texformat, u32 seed)
u64 h = seed ^ (len * m);
const u64 * data = (const u64 *)key;
const u64 * end = data + (len/8);
while(data != end)
{
u64 k = *data++;
k *= m;
k ^= k >> r;
k *= m;
h ^= k;
h *= m;
}
const u8 * data2 = (const u8*)data;
switch(len & 7)
{
case 7: h ^= u64(data2[6]) << 48;
case 6: h ^= u64(data2[5]) << 40;
case 5: h ^= u64(data2[4]) << 32;
case 4: h ^= u64(data2[3]) << 24;
case 3: h ^= u64(data2[2]) << 16;
case 2: h ^= u64(data2[1]) << 8;
case 1: h ^= u64(data2[0]);
h *= m;
};
h ^= h >> r;
h *= m;
h ^= h >> r;
return h;
}
u64 TexDecoder_GetFastHash(const u8 *src, int len, u64 seed)
{
int len = TexDecoder_GetTextureSizeInBytes(width, height, texformat);
u64 hash = seed ? seed : 0xbeefbabe1337c0de;
int step = len / 29 / 8;
u64 hash = seed ? seed : 0x1337c0debeefbabe;
int step = (len / 8) / 37;
if (!step) step = 1;
for (int i = 0; i < len / 8; i += step) {
hash = _rotl(hash, 17) ^ ((u64 *)src)[i];
}
return hash;
}
*/
u32 TexDecoder_GetTlutHash(const u8* src, int len)
{
//char str[40000], st[20]; str[0]='\0';for (int i=0;i<len;i++){sprintf(st,"%02x ",src[i]);strcat(str,st);}
u32 hash = 0xbeefbabe;
for (int i = 0; i < len / 4; i ++) {
hash = _rotl(hash, 7) ^ ((u32 *)src)[i];
hash = _rotl64(hash, 19) ^ ((u64 *)src)[i];
hash += 7; // to add a bit more entropy/mess in here
}
return hash;
}
u32 TexDecoder_GetSafeTextureHash(const u8 *src, int width, int height, int texformat, u32 seed)
{
int sz = TexDecoder_GetTextureSizeInBytes(width, height, texformat);
u32 hash = seed ? seed : 0x1337c0de;
if (sz < 2048) {
for (int i = 0; i < sz / 4; i += 13) {
hash = _rotl(hash, 19) ^ ((u32 *)src)[i];
}
return hash;
} else {
int step = sz / 23 / 4;
for (int i = 0; i < sz / 4; i += step) {
hash = _rotl(hash, 19) ^ ((u32 *)src)[i];
}
}
}
return hash;
}

View File

@ -89,8 +89,8 @@ PC_TexFormat GetPC_TexFormat(int texformat, int tlutfmt);
void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth, int texformat, int tlutaddr, int tlutfmt);
u32 TexDecoder_GetSafeTextureHash(const u8 *src, int width, int height, int texformat, u32 seed=0);
u32 TexDecoder_GetTlutHash(const u8* src, int len);
u64 TexDecoder_GetFullHash(const u8 *src, int len, u64 seed = 0);
u64 TexDecoder_GetFastHash(const u8 *src, int len, u64 seed = 0);
void TexDecoder_SetTexFmtOverlayOptions(bool enable, bool center);