From 3c1f62d6913930a8e83d374ff8187c1e6b1c52fb Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Sat, 6 May 2017 14:51:24 +0200 Subject: [PATCH] Expose XXHASH for Texture Replacement --- Core/TextureReplacer.cpp | 24 ++++++++++++++++++++++++ Core/TextureReplacer.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/Core/TextureReplacer.cpp b/Core/TextureReplacer.cpp index d60e28b4b9..18a6cf17b3 100644 --- a/Core/TextureReplacer.cpp +++ b/Core/TextureReplacer.cpp @@ -82,6 +82,10 @@ bool TextureReplacer::LoadIni() { // TODO: crc32c. if (strcasecmp(hash.c_str(), "quick") == 0) { hash_ = ReplacedTextureHash::QUICK; + } else if (strcasecmp(hash.c_str(), "xxh32") == 0) { + hash_ = ReplacedTextureHash::XXH32; + } else if (strcasecmp(hash.c_str(), "xxh64") == 0) { + hash_ = ReplacedTextureHash::XXH64; } else { ERROR_LOG(G3D, "Unsupported hash type: %s", hash.c_str()); return false; @@ -180,6 +184,10 @@ u32 TextureReplacer::ComputeHash(u32 addr, int bufw, int w, int h, GETextureForm switch (hash_) { case ReplacedTextureHash::QUICK: return StableQuickTexHash(checkp, sizeInRAM); + case ReplacedTextureHash::XXH32: + return DoReliableHash32(checkp, sizeInRAM, 0xBACD7814); + case ReplacedTextureHash::XXH64: + return DoReliableHash64(checkp, sizeInRAM, 0xBACD7814); default: return 0; } @@ -198,6 +206,22 @@ u32 TextureReplacer::ComputeHash(u32 addr, int bufw, int w, int h, GETextureForm } break; + case ReplacedTextureHash::XXH32: + for (int y = 0; y < h; ++y) { + u32 rowHash = DoReliableHash32(checkp, bytesPerLine, 0xBACD7814); + result = (result * 11) ^ rowHash; + checkp += stride; + } + break; + + case ReplacedTextureHash::XXH64: + for (int y = 0; y < h; ++y) { + u32 rowHash = DoReliableHash64(checkp, bytesPerLine, 0xBACD7814); + result = (result * 11) ^ rowHash; + checkp += stride; + } + break; + default: break; } diff --git a/Core/TextureReplacer.h b/Core/TextureReplacer.h index b3fdc0d462..52c6330bf4 100644 --- a/Core/TextureReplacer.h +++ b/Core/TextureReplacer.h @@ -50,6 +50,8 @@ enum class ReplacedTextureAlpha { enum class ReplacedTextureHash { // TODO: Maybe only support crc32c for now? QUICK, + XXH32, + XXH64, }; struct ReplacedTextureLevel {