diff --git a/Source/Core/Core/Src/HW/SystemTimers.cpp b/Source/Core/Core/Src/HW/SystemTimers.cpp index 6106eb8f85..48c6bdbae9 100644 --- a/Source/Core/Core/Src/HW/SystemTimers.cpp +++ b/Source/Core/Core/Src/HW/SystemTimers.cpp @@ -132,11 +132,10 @@ int IPC_HLE_PERIOD = GetTicksPerSecond() / 250, // For DC watchdog hack - // Once every 10 frame-period seems to be enough (arbitrary taking 60fps as the ref). + // Once every 4 frame-period seems to be enough (arbitrary taking 60fps as the ref). // TODO: make it VI output frame rate compliant (30/60 and 25/50) // Assuming game's frame-finish-watchdog wait more than 10 emulated frame-period before starting its mess. - // Note: 1/4 sec is the very maximum for ZTP to work in DC... 1/6 for safety. - FAKE_GP_WATCHDOG_PERIOD = GetTicksPerSecond() / 6; + FAKE_GP_WATCHDOG_PERIOD = GetTicksPerSecond() / 15; /////////////////////////////////// diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.cpp b/Source/Core/VideoCommon/Src/TextureDecoder.cpp index de8e383f91..a7a5356dce 100644 --- a/Source/Core/VideoCommon/Src/TextureDecoder.cpp +++ b/Source/Core/VideoCommon/Src/TextureDecoder.cpp @@ -65,11 +65,12 @@ int TexDecoder_GetTextureSizeInBytes(int width, int height, int format) return (width * height * TexDecoder_GetTexelSizeInNibbles(format)) / 2; } -u32 TexDecoder_GetTlutHash(const u16 *src, int len) +u32 TexDecoder_GetTlutHash(const u8* src, int len) { u32 hash = 0xbeefbabe; - for (int i = 0; i < len / 2; i += 2) { - hash = _rotl(hash, 17) ^ ((u32 *)src)[i]; + for (int i = 0; i < len ; i++) { + hash = _rotl(hash, 7) ^ src[i]; + hash += 7; } return hash; } diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.h b/Source/Core/VideoCommon/Src/TextureDecoder.h index 9fdfd36850..ceb1d61fff 100644 --- a/Source/Core/VideoCommon/Src/TextureDecoder.h +++ b/Source/Core/VideoCommon/Src/TextureDecoder.h @@ -78,7 +78,7 @@ enum PC_TexFormat PC_TexFormat TexDecoder_Decode(u8 *dst, const u8 *src, int width, int height, 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 u16 *src, int len); +u32 TexDecoder_GetTlutHash(const u8* src, int len); void TexDecoder_SetTexFmtOverlayOptions(bool enable, bool center); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp index 7e88d41627..85a4bd87e7 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp @@ -219,65 +219,50 @@ void TextureMngr::Cleanup() TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width, int height, int format, int tlutaddr, int tlutfmt) { + // TODO: - clean this up when ready to kill old "unsafe texture cache" + // - fix pokemun coloseum font for bSafeTextureCache (works with !bSafeTextureCache) + // TODO (mb2): get why other fmt needs a tlut hash too (pokemon coloseum font -> fmt 1 or 8 or 14 iirc) if (address == 0) return NULL; - TexCache::iterator iter = textures.find(address); TexMode0 &tm0 = bpmem.tex[texstage > 3].texMode0[texstage & 3]; u8 *ptr = g_VideoInitialize.pGetMemoryPointer(address); + u32 hash_value; // Needed for texture format using tlut. - // TODO: Slower == Safer. Recalculate tlut length for each cases just to be sure. - u32 hashseed = 0; - switch (format) { - case GX_TF_C4: - hashseed = TexDecoder_GetTlutHash((u16*)(texMem + tlutaddr), 128); - break; - case GX_TF_C8: - hashseed = TexDecoder_GetTlutHash((u16*)(texMem + tlutaddr), 256); - break; - case GX_TF_C14X2: - hashseed = TexDecoder_GetTlutHash((u16*)(texMem + tlutaddr), 512); - break; - } - - int palSize = TexDecoder_GetPaletteSize(format); - u32 palhash = 0xc0debabe; - - if (palSize) { - if (palSize > 32) - palSize = 32; //let's not do excessive amount of checking - u8 *pal = g_VideoInitialize.pGetMemoryPointer(tlutaddr); - if (pal != 0) { - for (int i = 0; i < palSize; i++) { - palhash = _rotl(palhash,13); - palhash ^= pal[i]; - palhash += 31; - } - } - } + u32 hashseed; + //if ( (format == GX_TF_C4) || (format == GX_TF_C8) || (format == GX_TF_C14X2) ) + // tlut size mask can be up to 0x3FFF (GX_TF_C14X2) but Safer == Slower. + //hashseed = TexDecoder_GetTlutHash(&texMem[tlutaddr], TexDecoder_GetPaletteSize(format)&0x7FFF); + hashseed = TexDecoder_GetTlutHash(texMem + tlutaddr, 32); + //else + // hashseed = address; int bs = TexDecoder_GetBlockWidthInTexels(format) - 1; int expandedWidth = (width + bs) & (~bs); + if (g_Config.bSafeTextureCache) + hash_value = TexDecoder_GetSafeTextureHash(ptr, expandedWidth, height, format, hashseed); + bool skip_texture_create = false; - if (iter != textures.end()) { + TexCache::iterator iter = textures.find(g_Config.bSafeTextureCache ? hash_value : address); + + if (iter != textures.end()) { TCacheEntry &entry = iter->second; - u32 hash_value; - if (g_Config.bSafeTextureCache) - hash_value = TexDecoder_GetSafeTextureHash(ptr, expandedWidth, height, format, hashseed); - else + if (!g_Config.bSafeTextureCache) hash_value = ((u32 *)ptr)[entry.hashoffset]; - if (entry.isRenderTarget || (hash_value == entry.hash && palhash == entry.paletteHash)) { + if (entry.isRenderTarget || ((address == entry.addr) && (hash_value == entry.hash))) { entry.frameCount = frameCount; //glEnable(entry.isNonPow2?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D); glBindTexture(entry.isNonPow2 ? GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D, entry.texture); if (entry.mode.hex != tm0.hex) entry.SetTextureParameters(tm0); - return &entry; + //DebugLog("%cC addr: %08x | fmt: %i | e.hash: %08x | w:%04i h:%04i", g_Config.bSafeTextureCache ? 'S' : 'U' + // , address, format, entry.hash, width, height); + return &entry; } else { @@ -302,17 +287,20 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width PC_TexFormat dfmt = TexDecoder_Decode(temp, ptr, expandedWidth, height, format, tlutaddr, tlutfmt); //Make an entry in the table - TCacheEntry& entry = textures[address]; + TCacheEntry& entry = textures[ g_Config.bSafeTextureCache ? hash_value : address ]; entry.hashoffset = 0; - entry.paletteHash = palhash; + entry.paletteHash = hashseed; entry.oldpixel = ((u32 *)ptr)[entry.hashoffset]; if (g_Config.bSafeTextureCache) { - entry.hash = TexDecoder_GetSafeTextureHash(ptr, expandedWidth, height, format, hashseed); + entry.hash = hash_value; } else { entry.hash = (u32)(((double)rand() / RAND_MAX) * 0xFFFFFFFF); ((u32 *)ptr)[entry.hashoffset] = entry.hash; } + //DebugLog("%c addr: %08x | fmt: %i | e.hash: %08x | w:%04i h:%04i", g_Config.bSafeTextureCache ? 'S' : 'U' + // , address, format, entry.hash, width, height); + entry.addr = address; entry.isRenderTarget = false;