From eeaad06a076ed7890a95a8ce126835d0b854675f Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 14 Jan 2015 00:14:53 +0100 Subject: [PATCH 1/8] CustomTexture: check for min/max index on paletted textures --- Source/Core/VideoCommon/HiresTextures.cpp | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index 633e6407a9..9e81c6891b 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -82,6 +82,42 @@ void HiresTexture::Init(const std::string& gameCode) std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format) { + // checking for min/max on paletted textures + u32 min = 0xffff; + u32 max = 0; + switch(tlut_size) + { + case 0: break; + case 16 * 2: + for (size_t i = 0; i < texture_size; i++) + { + min = std::min(min, texture[i] & 0xf); + min = std::min(min, texture[i] >> 4); + max = std::max(max, texture[i] & 0xf); + max = std::max(max, texture[i] >> 4); + } + break; + case 256 * 2: + for (size_t i = 0; i < texture_size; i++) + { + min = std::min(min, texture[i]); + max = std::max(max, texture[i]); + } + break; + case 16384 * 2: + for (size_t i = 0; i < texture_size/2; i++) + { + min = std::min(min, Common::swap16(((u16*)texture)[i]) & 0x3fff); + max = std::max(max, Common::swap16(((u16*)texture)[i]) & 0x3fff); + } + break; + } + if (tlut_size > 0) + { + tlut_size = 2 * (max + 1 - min); + tlut += 2 * min; + } + u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples); u64 tlut_hash = 0; u64 hash = tex_hash; From a353ead3cb489e404ab747b06eab37c7c4b35a08 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 14 Jan 2015 20:25:40 +0100 Subject: [PATCH 2/8] CustomTexture: Use always safe texture hash --- Source/Core/Common/Hash.h | 2 +- Source/Core/VideoCommon/HiresTextures.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/Common/Hash.h b/Source/Core/Common/Hash.h index 841a10386b..1aa2eefa81 100644 --- a/Source/Core/Common/Hash.h +++ b/Source/Core/Common/Hash.h @@ -13,7 +13,7 @@ u32 HashAdler32(const u8* data, size_t len); // Fairly accurate, slightl u32 HashFNV(const u8* ptr, int length); // Another fast and decent hash u32 HashEctor(const u8* ptr, int length); // JUNK. DO NOT USE FOR NEW THINGS u64 GetCRC32(const u8 *src, int len, u32 samples); // SSE4.2 version of CRC32 -u64 GetHashHiresTexture(const u8 *src, int len, u32 samples); +u64 GetHashHiresTexture(const u8 *src, int len, u32 samples = 0); u64 GetMurmurHash3(const u8 *src, int len, u32 samples); u64 GetHash64(const u8 *src, int len, u32 samples); void SetHash64Function(); diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index 9e81c6891b..ec678f8c50 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -118,12 +118,12 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co tlut += 2 * min; } - u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples); + u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size); u64 tlut_hash = 0; u64 hash = tex_hash; if (tlut_size) { - tlut_hash = GetHashHiresTexture(tlut, (int)tlut_size, g_ActiveConfig.iSafeTextureCache_ColorSamples); + tlut_hash = GetHashHiresTexture(tlut, (int)tlut_size); hash ^= tlut_hash; } return StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32)hash, (u16)format); From ee9d05d67f4d8d2c1f754c0b40f7f54cfbd8d4fd Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 14 Jan 2015 21:25:33 +0100 Subject: [PATCH 3/8] CustomTexture: Use another file name with wildcards --- Source/Core/VideoCommon/HiresTextures.cpp | 20 +++++++++++--------- Source/Core/VideoCommon/HiresTextures.h | 2 +- Source/Core/VideoCommon/TextureCacheBase.cpp | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index ec678f8c50..bf76ad0dc0 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -80,7 +80,7 @@ void HiresTexture::Init(const std::string& gameCode) } } -std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format) +std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format, bool dump) { // checking for min/max on paletted textures u32 min = 0xffff; @@ -119,14 +119,16 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co } u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size); - u64 tlut_hash = 0; - u64 hash = tex_hash; - if (tlut_size) - { - tlut_hash = GetHashHiresTexture(tlut, (int)tlut_size); - hash ^= tlut_hash; - } - return StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32)hash, (u16)format); + u64 tlut_hash = tlut_size ? GetHashHiresTexture(tlut, (int)tlut_size) : 0; + + std::string basename = StringFromFormat("tex1_%dx%d_%016lx", width, height, tex_hash); + std::string tlutname = tlut_size ? StringFromFormat("_%016lx", tlut_hash) : ""; + std::string formatname = StringFromFormat("_%d", format); + + if (!dump && textureMap.find(basename + "_*" + formatname) != textureMap.end()) + return basename + "_*" + formatname; + + return basename + tlutname + formatname; } HiresTexture* HiresTexture::Search(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format) diff --git a/Source/Core/VideoCommon/HiresTextures.h b/Source/Core/VideoCommon/HiresTextures.h index bd009424b6..a1a16ff1c4 100644 --- a/Source/Core/VideoCommon/HiresTextures.h +++ b/Source/Core/VideoCommon/HiresTextures.h @@ -25,7 +25,7 @@ public: const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, - int format + int format, bool dump = false ); ~HiresTexture(); diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 684dc56b5e..1159159690 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -476,7 +476,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(const u32 stage) src_data, texture_size, &texMem[tlutaddr], palette_size, width, height, - texformat + texformat, true ); DumpTexture(entry, basename, 0); } From 62402efa6c2777c4e9829767c39fed71fe3de60a Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 15 Jan 2015 21:33:22 +0100 Subject: [PATCH 4/8] CustomTexture: Mark textures with mipmaps --- Source/Core/VideoCommon/HiresTextures.cpp | 8 ++++---- Source/Core/VideoCommon/HiresTextures.h | 5 +++-- Source/Core/VideoCommon/TextureCacheBase.cpp | 7 ++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index bf76ad0dc0..2c916ec0f8 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -80,7 +80,7 @@ void HiresTexture::Init(const std::string& gameCode) } } -std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format, bool dump) +std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format, bool has_mipmaps, bool dump) { // checking for min/max on paletted textures u32 min = 0xffff; @@ -121,7 +121,7 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size); u64 tlut_hash = tlut_size ? GetHashHiresTexture(tlut, (int)tlut_size) : 0; - std::string basename = StringFromFormat("tex1_%dx%d_%016lx", width, height, tex_hash); + std::string basename = StringFromFormat("tex1%s_%dx%d_%016lx", has_mipmaps ? "_m" : "", width, height, tex_hash); std::string tlutname = tlut_size ? StringFromFormat("_%016lx", tlut_hash) : ""; std::string formatname = StringFromFormat("_%d", format); @@ -131,9 +131,9 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co return basename + tlutname + formatname; } -HiresTexture* HiresTexture::Search(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format) +HiresTexture* HiresTexture::Search(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format, bool has_mipmaps) { - std::string base_filename = GenBaseName(texture, texture_size, tlut, tlut_size, width, height, format); + std::string base_filename = GenBaseName(texture, texture_size, tlut, tlut_size, width, height, format, has_mipmaps); HiresTexture* ret = nullptr; for (int level = 0;; level++) diff --git a/Source/Core/VideoCommon/HiresTextures.h b/Source/Core/VideoCommon/HiresTextures.h index a1a16ff1c4..340d660706 100644 --- a/Source/Core/VideoCommon/HiresTextures.h +++ b/Source/Core/VideoCommon/HiresTextures.h @@ -18,14 +18,15 @@ public: const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, - int format + int format, bool has_mipmaps ); static std::string GenBaseName( const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, - int format, bool dump = false + int format, bool has_mipmaps, + bool dump = false ); ~HiresTexture(); diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 1159159690..3e61ea11f3 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -304,8 +304,8 @@ TextureCache::TCacheEntryBase* TextureCache::Load(const u32 stage) const int texformat = tex.texImage0[id].format; const u32 tlutaddr = tex.texTlut[id].tmem_offset << 9; const u32 tlutfmt = tex.texTlut[id].tlut_format; - const bool use_mipmaps = (tex.texMode0[id].min_filter & 3) != 0; u32 tex_levels = (tex.texMode1[id].max_lod + 0xf) / 0x10 + 1; + const bool use_mipmaps = (tex.texMode0[id].min_filter & 3) != 0 && tex_levels > 0; const bool from_tmem = tex.texImage1[id].image_type != 0; if (0 == address) @@ -410,7 +410,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(const u32 stage) src_data, texture_size, &texMem[tlutaddr], palette_size, width, height, - texformat + texformat, use_mipmaps )); if (hires_tex) @@ -476,7 +476,8 @@ TextureCache::TCacheEntryBase* TextureCache::Load(const u32 stage) src_data, texture_size, &texMem[tlutaddr], palette_size, width, height, - texformat, true + texformat, use_mipmaps, + true ); DumpTexture(entry, basename, 0); } From f9ced4eb133809b01abb1e3d1a7b11535fd92989 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 14 Jan 2015 21:53:05 +0100 Subject: [PATCH 5/8] CustomTexture: also support the legacy format --- Source/Core/VideoCommon/HiresTextures.cpp | 136 +++++++++++++--------- Source/Core/VideoCommon/HiresTextures.h | 2 - 2 files changed, 84 insertions(+), 54 deletions(-) diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index 2c916ec0f8..e41b591fc5 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -18,11 +18,18 @@ #include "VideoCommon/HiresTextures.h" #include "VideoCommon/VideoConfig.h" -std::unordered_map HiresTexture::textureMap; +static std::unordered_map s_textureMap; +static bool s_check_native_format; +static bool s_check_new_format; + +static const std::string s_format_prefix = "tex1_"; + void HiresTexture::Init(const std::string& gameCode) { - textureMap.clear(); + s_textureMap.clear(); + s_check_native_format = false; + s_check_new_format = false; CFileSearch::XStringVector Directories; @@ -66,69 +73,94 @@ void HiresTexture::Init(const std::string& gameCode) const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames(); const std::string code = StringFromFormat("%s_", gameCode.c_str()); + const std::string code2 = ""; - if (rFilenames.size() > 0) + for (auto& rFilename : rFilenames) { - for (auto& rFilename : rFilenames) - { - std::string FileName; - SplitPath(rFilename, nullptr, &FileName, nullptr); + std::string FileName; + SplitPath(rFilename, nullptr, &FileName, nullptr); - if (FileName.substr(0, code.length()).compare(code) == 0 && textureMap.find(FileName) == textureMap.end()) - textureMap.insert(std::map::value_type(FileName, rFilename)); + if (FileName.substr(0, code.length()) == code) + { + s_textureMap[FileName] = rFilename; + s_check_native_format = true; + } + + if (FileName.substr(0, s_format_prefix.length()) == s_format_prefix) + { + s_textureMap[FileName] = rFilename; + s_check_new_format = true; } } } std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format, bool has_mipmaps, bool dump) { - // checking for min/max on paletted textures - u32 min = 0xffff; - u32 max = 0; - switch(tlut_size) + if (!dump && s_check_native_format) { - case 0: break; - case 16 * 2: - for (size_t i = 0; i < texture_size; i++) - { - min = std::min(min, texture[i] & 0xf); - min = std::min(min, texture[i] >> 4); - max = std::max(max, texture[i] & 0xf); - max = std::max(max, texture[i] >> 4); - } - break; - case 256 * 2: - for (size_t i = 0; i < texture_size; i++) - { - min = std::min(min, texture[i]); - max = std::max(max, texture[i]); - } - break; - case 16384 * 2: - for (size_t i = 0; i < texture_size/2; i++) - { - min = std::min(min, Common::swap16(((u16*)texture)[i]) & 0x3fff); - max = std::max(max, Common::swap16(((u16*)texture)[i]) & 0x3fff); - } - break; - } - if (tlut_size > 0) - { - tlut_size = 2 * (max + 1 - min); - tlut += 2 * min; + // try to load the old format first + u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples); + u64 tlut_hash = tlut_size ? GetHashHiresTexture(tlut, (int)tlut_size, g_ActiveConfig.iSafeTextureCache_ColorSamples) : 0; + std::string name = StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32)(tex_hash ^ tlut_hash), (u16)format); + if (s_textureMap.find(name) != s_textureMap.end()) + return name; } - u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size); - u64 tlut_hash = tlut_size ? GetHashHiresTexture(tlut, (int)tlut_size) : 0; + if (dump || s_check_new_format) + { + // checking for min/max on paletted textures + u32 min = 0xffff; + u32 max = 0; + switch(tlut_size) + { + case 0: break; + case 16 * 2: + for (size_t i = 0; i < texture_size; i++) + { + min = std::min(min, texture[i] & 0xf); + min = std::min(min, texture[i] >> 4); + max = std::max(max, texture[i] & 0xf); + max = std::max(max, texture[i] >> 4); + } + break; + case 256 * 2: + for (size_t i = 0; i < texture_size; i++) + { + min = std::min(min, texture[i]); + max = std::max(max, texture[i]); + } + break; + case 16384 * 2: + for (size_t i = 0; i < texture_size/2; i++) + { + min = std::min(min, Common::swap16(((u16*)texture)[i]) & 0x3fff); + max = std::max(max, Common::swap16(((u16*)texture)[i]) & 0x3fff); + } + break; + } + if (tlut_size > 0) + { + tlut_size = 2 * (max + 1 - min); + tlut += 2 * min; + } - std::string basename = StringFromFormat("tex1%s_%dx%d_%016lx", has_mipmaps ? "_m" : "", width, height, tex_hash); - std::string tlutname = tlut_size ? StringFromFormat("_%016lx", tlut_hash) : ""; - std::string formatname = StringFromFormat("_%d", format); + u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size); + u64 tlut_hash = tlut_size ? GetHashHiresTexture(tlut, (int)tlut_size) : 0; - if (!dump && textureMap.find(basename + "_*" + formatname) != textureMap.end()) - return basename + "_*" + formatname; + std::string basename = s_format_prefix + StringFromFormat("%s%dx%d_%016lx", has_mipmaps ? "m_" : "", width, height, tex_hash); + std::string tlutname = tlut_size ? StringFromFormat("_%016lx", tlut_hash) : ""; + std::string formatname = StringFromFormat("_%d", format); - return basename + tlutname + formatname; + // try to match a wildcard template + if (!dump && s_textureMap.find(basename + "_*" + formatname) != s_textureMap.end()) + return basename + "_*" + formatname; + + // else generate the complete texture + if (dump || s_textureMap.find(basename + tlutname + formatname) != s_textureMap.end()) + return basename + tlutname + formatname; + } + + return ""; } HiresTexture* HiresTexture::Search(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format, bool has_mipmaps) @@ -144,12 +176,12 @@ HiresTexture* HiresTexture::Search(const u8* texture, size_t texture_size, const filename += StringFromFormat("_mip%u", level); } - if (textureMap.find(filename) != textureMap.end()) + if (s_textureMap.find(filename) != s_textureMap.end()) { Level l; File::IOFile file; - file.Open(textureMap[filename], "rb"); + file.Open(s_textureMap[filename], "rb"); std::vector buffer(file.GetSize()); file.ReadBytes(buffer.data(), file.GetSize()); diff --git a/Source/Core/VideoCommon/HiresTextures.h b/Source/Core/VideoCommon/HiresTextures.h index 340d660706..f49f578625 100644 --- a/Source/Core/VideoCommon/HiresTextures.h +++ b/Source/Core/VideoCommon/HiresTextures.h @@ -39,8 +39,6 @@ public: }; std::vector m_levels; - static std::unordered_map textureMap; - private: HiresTexture() {} From 84c8645d2265acce61315e98689355f31f012f9a Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 14 Jan 2015 23:19:10 +0100 Subject: [PATCH 6/8] CustomTexture: Convert old format automatically --- Source/Core/VideoCommon/HiresTextures.cpp | 87 +++++++++++++++++++++-- Source/Core/VideoCommon/VideoConfig.cpp | 3 + Source/Core/VideoCommon/VideoConfig.h | 1 + 3 files changed, 84 insertions(+), 7 deletions(-) diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index e41b591fc5..b90296e7b5 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -16,6 +16,7 @@ #include "Core/ConfigManager.h" #include "VideoCommon/HiresTextures.h" +#include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/VideoConfig.h" static std::unordered_map s_textureMap; @@ -24,7 +25,6 @@ static bool s_check_new_format; static const std::string s_format_prefix = "tex1_"; - void HiresTexture::Init(const std::string& gameCode) { s_textureMap.clear(); @@ -96,17 +96,24 @@ void HiresTexture::Init(const std::string& gameCode) std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format, bool has_mipmaps, bool dump) { + std::string name = ""; + bool convert = false; if (!dump && s_check_native_format) { // try to load the old format first u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples); u64 tlut_hash = tlut_size ? GetHashHiresTexture(tlut, (int)tlut_size, g_ActiveConfig.iSafeTextureCache_ColorSamples) : 0; - std::string name = StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32)(tex_hash ^ tlut_hash), (u16)format); + name = StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32)(tex_hash ^ tlut_hash), (u16)format); if (s_textureMap.find(name) != s_textureMap.end()) - return name; + { + if (g_ActiveConfig.bConvertHiresTextures) + convert = true; + else + return name; + } } - if (dump || s_check_new_format) + if (dump || s_check_new_format || convert) { // checking for min/max on paletted textures u32 min = 0xffff; @@ -150,17 +157,83 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co std::string basename = s_format_prefix + StringFromFormat("%s%dx%d_%016lx", has_mipmaps ? "m_" : "", width, height, tex_hash); std::string tlutname = tlut_size ? StringFromFormat("_%016lx", tlut_hash) : ""; std::string formatname = StringFromFormat("_%d", format); + std::string fullname = basename + tlutname + formatname; + + for (int level = 0; level < 10 && convert; level++) + { + std::string oldname = name; + if (level) + oldname += StringFromFormat("_mip%d", level); + + // skip not existing levels + if (s_textureMap.find(oldname) == s_textureMap.end()) + continue; + + for (int i = 0;; i++) + { + // for hash collisions, padd with an integer + std::string newname = fullname; + if (level) + newname += StringFromFormat("_mip%d", level); + if (i) + newname += StringFromFormat(".%d", i); + + // new texture + if (s_textureMap.find(newname) == s_textureMap.end()) + { + std::string src = s_textureMap[oldname]; + size_t postfix = src.find_last_of('.'); + std::string dst = src.substr(0, postfix - oldname.length()) + newname + src.substr(postfix, src.length() - postfix); + if (File::Rename(src, dst)) + { + s_textureMap.erase(oldname); + s_textureMap[newname] = dst; + s_check_new_format = true; + OSD::AddMessage(StringFromFormat("Rename custom texture %s to %s", oldname.c_str(), newname.c_str()), 5000); + } + else + { + ERROR_LOG(VIDEO, "rename failed"); + } + break; + } + else + { + // dst fail already exist, compare content + std::string a, b; + File::ReadFileToString(s_textureMap[oldname], a); + File::ReadFileToString(s_textureMap[newname], b); + + if (a == b && a != "") + { + // equal, so remove + if (File::Delete(s_textureMap[oldname])) + { + s_textureMap.erase(oldname); + OSD::AddMessage(StringFromFormat("Delete double old custom texture %s", oldname.c_str()), 5000); + } + else + { + ERROR_LOG(VIDEO, "delete failed"); + } + break; + } + + // else continue in this loop with the next higher padding variable + } + } + } // try to match a wildcard template if (!dump && s_textureMap.find(basename + "_*" + formatname) != s_textureMap.end()) return basename + "_*" + formatname; // else generate the complete texture - if (dump || s_textureMap.find(basename + tlutname + formatname) != s_textureMap.end()) - return basename + tlutname + formatname; + if (dump || s_textureMap.find(fullname) != s_textureMap.end()) + return fullname; } - return ""; + return name; } HiresTexture* HiresTexture::Search(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format, bool has_mipmaps) diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index f0bba36ffd..f6fe38d663 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -70,6 +70,7 @@ void VideoConfig::Load(const std::string& ini_file) settings->Get("ShowEFBCopyRegions", &bShowEFBCopyRegions, false); settings->Get("DumpTextures", &bDumpTextures, 0); settings->Get("HiresTextures", &bHiresTextures, 0); + settings->Get("ConvertHiresTextures", &bConvertHiresTextures, 0); settings->Get("DumpEFBTarget", &bDumpEFBTarget, 0); settings->Get("FreeLook", &bFreeLook, 0); settings->Get("UseFFV1", &bUseFFV1, 0); @@ -150,6 +151,7 @@ void VideoConfig::GameIniLoad() CHECK_SETTING("Video_Settings", "UseRealXFB", bUseRealXFB); CHECK_SETTING("Video_Settings", "SafeTextureCacheColorSamples", iSafeTextureCache_ColorSamples); CHECK_SETTING("Video_Settings", "HiresTextures", bHiresTextures); + CHECK_SETTING("Video_Settings", "ConvertHiresTextures", bConvertHiresTextures); CHECK_SETTING("Video_Settings", "EnablePixelLighting", bEnablePixelLighting); CHECK_SETTING("Video_Settings", "FastDepthCalc", bFastDepthCalc); CHECK_SETTING("Video_Settings", "MSAA", iMultisampleMode); @@ -257,6 +259,7 @@ void VideoConfig::Save(const std::string& ini_file) settings->Set("OverlayProjStats", bOverlayProjStats); settings->Set("DumpTextures", bDumpTextures); settings->Set("HiresTextures", bHiresTextures); + settings->Set("ConvertHiresTextures", bConvertHiresTextures); settings->Set("DumpEFBTarget", bDumpEFBTarget); settings->Set("FreeLook", bFreeLook); settings->Set("UseFFV1", bUseFFV1); diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index f156ddcfc8..cf6ea92b32 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -103,6 +103,7 @@ struct VideoConfig final // Utility bool bDumpTextures; bool bHiresTextures; + bool bConvertHiresTextures; bool bDumpEFBTarget; bool bUseFFV1; bool bFreeLook; From 1d0557a5e622b822d4d0d2f31036188f4051b604 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 21 Jan 2015 21:45:14 +0100 Subject: [PATCH 7/8] CustomTexture: use xxhash --- Source/Core/VideoCommon/HiresTextures.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index b90296e7b5..e4d90700dd 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "Common/CommonPaths.h" @@ -151,8 +152,8 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co tlut += 2 * min; } - u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size); - u64 tlut_hash = tlut_size ? GetHashHiresTexture(tlut, (int)tlut_size) : 0; + u64 tex_hash = XXH64(texture, texture_size, 0); + u64 tlut_hash = tlut_size ? XXH64(tlut, tlut_size, 0) : 0; std::string basename = s_format_prefix + StringFromFormat("%s%dx%d_%016lx", has_mipmaps ? "m_" : "", width, height, tex_hash); std::string tlutname = tlut_size ? StringFromFormat("_%016lx", tlut_hash) : ""; From 7cf4dd63e45af0617ef7eabc25e3f39f36f1fe84 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 21 Jan 2015 23:06:18 +0100 Subject: [PATCH 8/8] CustomTexture: fix texture format --- Source/Core/VideoCommon/HiresTextures.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index e4d90700dd..9483fe3b3f 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include @@ -155,8 +156,8 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co u64 tex_hash = XXH64(texture, texture_size, 0); u64 tlut_hash = tlut_size ? XXH64(tlut, tlut_size, 0) : 0; - std::string basename = s_format_prefix + StringFromFormat("%s%dx%d_%016lx", has_mipmaps ? "m_" : "", width, height, tex_hash); - std::string tlutname = tlut_size ? StringFromFormat("_%016lx", tlut_hash) : ""; + std::string basename = s_format_prefix + StringFromFormat("%dx%d%s_%016" PRIx64, width, height, has_mipmaps ? "_m" : "", tex_hash); + std::string tlutname = tlut_size ? StringFromFormat("_%016" PRIx64, tlut_hash) : ""; std::string formatname = StringFromFormat("_%d", format); std::string fullname = basename + tlutname + formatname;