From bc3a7bdce3c29cccca836259e1f50fe830a39ae7 Mon Sep 17 00:00:00 2001 From: "memberTwo.mb2" Date: Thu, 4 Dec 2008 22:55:17 +0000 Subject: [PATCH] Better tlut hash for fixing MPs font. Didn't notice any slowdown for now. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1402 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Core/VideoCommon/Src/TextureDecoder.cpp | 9 +++++++++ Source/Core/VideoCommon/Src/TextureDecoder.h | 2 +- .../Plugin_VideoOGL/Src/TextureMngr.cpp | 20 ++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.cpp b/Source/Core/VideoCommon/Src/TextureDecoder.cpp index a1654a72ca..9f2b7c00bd 100644 --- a/Source/Core/VideoCommon/Src/TextureDecoder.cpp +++ b/Source/Core/VideoCommon/Src/TextureDecoder.cpp @@ -62,6 +62,15 @@ 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 hash = 0xbeefbabe; + for (int i = 0; i < len / 2; i += 2) { + hash = _rotl(hash, 17) ^ ((u32 *)src)[i]; + } + return hash; +} + u32 TexDecoder_GetSafeTextureHash(const u8 *src, int width, int height, int texformat, u32 seed) { int sz = TexDecoder_GetTextureSizeInBytes(width, height, texformat); diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.h b/Source/Core/VideoCommon/Src/TextureDecoder.h index 2c0647f737..b981f3384c 100644 --- a/Source/Core/VideoCommon/Src/TextureDecoder.h +++ b/Source/Core/VideoCommon/Src/TextureDecoder.h @@ -77,8 +77,8 @@ 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 TexDecoder_GetSafeTextureHash(const u8 *src, int width, int height, int texformat, u32 seed=0); +u32 TexDecoder_GetTlutHash(const u16 *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 de85b75a8f..fe5c127491 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp @@ -203,12 +203,22 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width TexMode0 &tm0 = bpmem.tex[texstage > 3].texMode0[texstage & 3]; u8 *ptr = g_VideoInitialize.pGetMemoryPointer(address); - // not very robust but this is a fast fix for MPs font issue. - // GX_TF_C4, GX_TF_C8, GX_TF_C14X2 use tlutaddr. - // So the other cases could be needed later. - u32 hashseed = format!=GX_TF_C4 ? 0 : *(u32*)(u16*)(texMem + tlutaddr); + // Needed for texture format using tlut. + // TODO: Slower == Safer. Recalculate tlut lenght 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), 384); + break; + } - int palSize = TexDecoder_GetPaletteSize(format); + int palSize = TexDecoder_GetPaletteSize(format); u32 palhash = 0xc0debabe; if (palSize) {