From 565653c77b031dee1162ecb7a394e6e4c85cceab Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 30 Apr 2016 15:18:45 -0700 Subject: [PATCH] Save and load textures using full key. Of course, need this, not just the hash. --- Core/TextureReplacer.cpp | 8 ++++---- Core/TextureReplacer.h | 4 ++-- GPU/Directx9/TextureCacheDX9.cpp | 4 ++-- GPU/GLES/TextureCache.cpp | 4 ++-- GPU/Vulkan/TextureCacheVulkan.cpp | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Core/TextureReplacer.cpp b/Core/TextureReplacer.cpp index dbecb4d128..cf72d94687 100644 --- a/Core/TextureReplacer.cpp +++ b/Core/TextureReplacer.cpp @@ -73,7 +73,7 @@ u32 TextureReplacer::ComputeHash(u32 addr, int bufw, int w, int h, GETextureForm return DoQuickTexHash(checkp, sizeInRAM); } -ReplacedTexture TextureReplacer::FindReplacement(u32 hash) { +ReplacedTexture TextureReplacer::FindReplacement(u64 cachekey, u32 hash) { _assert_msg_(G3D, enabled_, "Replacement not enabled"); ReplacedTexture result; @@ -109,15 +109,15 @@ static bool WriteTextureToPNG(png_imagep image, const std::string &filename, int } #endif -void TextureReplacer::NotifyTextureDecoded(u32 hash, u32 addr, const void *data, int pitch, int w, int h, ReplacedTextureFormat fmt) { +void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, const void *data, int pitch, int w, int h, ReplacedTextureFormat fmt) { _assert_msg_(G3D, enabled_, "Replacement not enabled"); if (!g_Config.bSaveNewTextures) { // Ignore. return; } - char hashname[8 + 4 + 1] = {}; - snprintf(hashname, sizeof(hashname), "%08x.png", hash); + char hashname[16 + 8 + 4 + 1] = {}; + snprintf(hashname, sizeof(hashname), "%016llx%08x.png", cachekey, hash); const std::string filename = basePath_ + hashname; // TODO: Check for ini ignored or aliased textures. diff --git a/Core/TextureReplacer.h b/Core/TextureReplacer.h index fd02d6db50..7d758dfa2b 100644 --- a/Core/TextureReplacer.h +++ b/Core/TextureReplacer.h @@ -99,9 +99,9 @@ public: u32 ComputeHash(u32 addr, int bufw, int w, int h, GETextureFormat fmt, u16 maxSeenV); - ReplacedTexture FindReplacement(u32 hash); + ReplacedTexture FindReplacement(u64 cachekey, u32 hash); - void NotifyTextureDecoded(u32 hash, u32 addr, const void *data, int pitch, int w, int h, ReplacedTextureFormat fmt); + void NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, const void *data, int pitch, int w, int h, ReplacedTextureFormat fmt); protected: bool LookupHashRange(u32 addr, int &w, int &h); diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 957cc14fd9..309397873e 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -1255,7 +1255,7 @@ void TextureCacheDX9::SetTexture(bool force) { scaleFactor = scaleFactor > 4 ? 4 : (scaleFactor > 2 ? 2 : 1); } - ReplacedTexture replaced = replacer.FindReplacement(entry->fullhash); + ReplacedTexture replaced = replacer.FindReplacement(cachekey, entry->fullhash); if (replaced.GetSize(0, w, h)) { // We're replacing, so we won't scale. scaleFactor = 1; @@ -1674,7 +1674,7 @@ void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &re if (replacer.Enabled()) { int bpp = dstFmt == D3DFMT_A8R8G8B8 ? 4 : 2; - replacer.NotifyTextureDecoded(entry.fullhash, entry.addr, pixelData, w * bpp, w, h, FromD3D9Format(dstFmt)); + replacer.NotifyTextureDecoded(entry.CacheKey(), entry.fullhash, entry.addr, pixelData, w * bpp, w, h, FromD3D9Format(dstFmt)); } } diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index a864d45112..cd3c6c1083 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -1364,7 +1364,7 @@ void TextureCache::SetTexture(bool force) { scaleFactor = scaleFactor > 4 ? 4 : (scaleFactor > 2 ? 2 : 1); } - ReplacedTexture replaced = replacer.FindReplacement(entry->fullhash); + ReplacedTexture replaced = replacer.FindReplacement(cachekey, entry->fullhash); if (replaced.GetSize(0, w, h)) { // We're replacing, so we won't scale. scaleFactor = 1; @@ -1813,7 +1813,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &repla if (replacer.Enabled()) { int bpp = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2; - replacer.NotifyTextureDecoded(entry.fullhash, entry.addr, pixelData, (useUnpack ? bufw : w) * bpp, w, h, FromGLESFormat(dstFmt, useBGRA)); + replacer.NotifyTextureDecoded(entry.CacheKey(), entry.fullhash,entry.addr, pixelData, (useUnpack ? bufw : w) * bpp, w, h, FromGLESFormat(dstFmt, useBGRA)); } } diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index f31c66e8f1..e7741eca46 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -1237,7 +1237,7 @@ void TextureCacheVulkan::SetTexture(VulkanPushBuffer *uploadBuffer) { scaleFactor = scaleFactor > 4 ? 4 : (scaleFactor > 2 ? 2 : 1); } - ReplacedTexture replaced = replacer.FindReplacement(entry->fullhash); + ReplacedTexture replaced = replacer.FindReplacement(cachekey, entry->fullhash); if (replaced.GetSize(0, w, h)) { // We're replacing, so we won't scale. scaleFactor = 1; @@ -1348,7 +1348,7 @@ void TextureCacheVulkan::SetTexture(VulkanPushBuffer *uploadBuffer) { } else { LoadTextureLevel(*entry, (uint8_t *)data, stride, i, scaleFactor, dstFmt); if (replacer.Enabled()) { - replacer.NotifyTextureDecoded(entry->fullhash, texaddr, data, stride, mipWidth, mipHeight, FromVulkanFormat(actualFmt)); + replacer.NotifyTextureDecoded(cachekey, entry->fullhash, texaddr, data, stride, mipWidth, mipHeight, FromVulkanFormat(actualFmt)); } } entry->vkTex->texture_->UploadMip(i, mipWidth, mipHeight, texBuf, bufferOffset, stride / bpp);