From 0b466249e005a5e47a479bce0e4be67ad2dcecb0 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 15 Nov 2016 22:19:51 +0100 Subject: [PATCH 1/2] CustomTextures: Drop format convertion. --- Source/Core/Core/Config/GraphicsSettings.cpp | 2 - Source/Core/Core/Config/GraphicsSettings.h | 1 - .../Core/ConfigLoaders/IsSettingSaveable.cpp | 1 - Source/Core/VideoCommon/HiresTextures.cpp | 75 +------------------ Source/Core/VideoCommon/VideoConfig.cpp | 1 - Source/Core/VideoCommon/VideoConfig.h | 1 - 6 files changed, 1 insertion(+), 80 deletions(-) diff --git a/Source/Core/Core/Config/GraphicsSettings.cpp b/Source/Core/Core/Config/GraphicsSettings.cpp index 4455cb63af..8811d36bad 100644 --- a/Source/Core/Core/Config/GraphicsSettings.cpp +++ b/Source/Core/Core/Config/GraphicsSettings.cpp @@ -38,8 +38,6 @@ const ConfigInfo GFX_OVERLAY_STATS{{System::GFX, "Settings", "OverlayStats const ConfigInfo GFX_OVERLAY_PROJ_STATS{{System::GFX, "Settings", "OverlayProjStats"}, false}; const ConfigInfo GFX_DUMP_TEXTURES{{System::GFX, "Settings", "DumpTextures"}, false}; const ConfigInfo GFX_HIRES_TEXTURES{{System::GFX, "Settings", "HiresTextures"}, false}; -const ConfigInfo GFX_CONVERT_HIRES_TEXTURES{{System::GFX, "Settings", "ConvertHiresTextures"}, - false}; const ConfigInfo GFX_CACHE_HIRES_TEXTURES{{System::GFX, "Settings", "CacheHiresTextures"}, false}; const ConfigInfo GFX_DUMP_EFB_TARGET{{System::GFX, "Settings", "DumpEFBTarget"}, false}; diff --git a/Source/Core/Core/Config/GraphicsSettings.h b/Source/Core/Core/Config/GraphicsSettings.h index 475edf8a8b..82cadfdb81 100644 --- a/Source/Core/Core/Config/GraphicsSettings.h +++ b/Source/Core/Core/Config/GraphicsSettings.h @@ -32,7 +32,6 @@ extern const ConfigInfo GFX_OVERLAY_STATS; extern const ConfigInfo GFX_OVERLAY_PROJ_STATS; extern const ConfigInfo GFX_DUMP_TEXTURES; extern const ConfigInfo GFX_HIRES_TEXTURES; -extern const ConfigInfo GFX_CONVERT_HIRES_TEXTURES; extern const ConfigInfo GFX_CACHE_HIRES_TEXTURES; extern const ConfigInfo GFX_DUMP_EFB_TARGET; extern const ConfigInfo GFX_DUMP_XFB_TARGET; diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index 36cde2a9d9..fdee06283f 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -33,7 +33,6 @@ bool IsSettingSaveable(const Config::ConfigLocation& config_location) Config::GFX_SHOW_NETPLAY_MESSAGES.location, Config::GFX_LOG_RENDER_TIME_TO_FILE.location, Config::GFX_OVERLAY_STATS.location, Config::GFX_OVERLAY_PROJ_STATS.location, Config::GFX_DUMP_TEXTURES.location, Config::GFX_HIRES_TEXTURES.location, - Config::GFX_CONVERT_HIRES_TEXTURES.location, Config::GFX_CACHE_HIRES_TEXTURES.location, Config::GFX_DUMP_EFB_TARGET.location, Config::GFX_DUMP_FRAMES_AS_IMAGES.location, Config::GFX_FREE_LOOK.location, Config::GFX_USE_FFV1.location, Config::GFX_DUMP_FORMAT.location, Config::GFX_DUMP_CODEC.location, diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index 0132733574..d658980999 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -229,7 +229,6 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co bool has_mipmaps, bool dump) { std::string name = ""; - bool convert = false; if (!dump && s_check_native_format) { // try to load the old format first @@ -242,14 +241,11 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co (u32)(tex_hash ^ tlut_hash), (u16)format); if (s_textureMap.find(name) != s_textureMap.end()) { - if (g_ActiveConfig.bConvertHiresTextures) - convert = true; - else return name; } } - if (dump || s_check_new_format || convert) + if (dump || s_check_new_format) { // checking for min/max on paletted textures u32 min = 0xffff; @@ -297,75 +293,6 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co std::string formatname = StringFromFormat("_%d", static_cast(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].path; - 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, false}; - 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].path, a); - File::ReadFileToString(s_textureMap[newname].path, b); - - if (a == b && a != "") - { - // equal, so remove - if (File::Delete(s_textureMap[oldname].path)) - { - 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; diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index 6c68fd5e37..9a54fedcc9 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -75,7 +75,6 @@ void VideoConfig::Refresh() bOverlayProjStats = Config::Get(Config::GFX_OVERLAY_PROJ_STATS); bDumpTextures = Config::Get(Config::GFX_DUMP_TEXTURES); bHiresTextures = Config::Get(Config::GFX_HIRES_TEXTURES); - bConvertHiresTextures = Config::Get(Config::GFX_CONVERT_HIRES_TEXTURES); bCacheHiresTextures = Config::Get(Config::GFX_CACHE_HIRES_TEXTURES); bDumpEFBTarget = Config::Get(Config::GFX_DUMP_EFB_TARGET); bDumpXFBTarget = Config::Get(Config::GFX_DUMP_XFB_TARGET); diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index 103b63b423..b56e95ec31 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -93,7 +93,6 @@ struct VideoConfig final // Utility bool bDumpTextures; bool bHiresTextures; - bool bConvertHiresTextures; bool bCacheHiresTextures; bool bDumpEFBTarget; bool bDumpXFBTarget; From a5a05991458cd83b022491cf5ac020b7497272b9 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 15 Nov 2016 22:25:35 +0100 Subject: [PATCH 2/2] CustomTexture: Drop old texture format. --- Source/Core/Common/Hash.cpp | 115 -------------------- Source/Core/Common/Hash.h | 1 - Source/Core/VideoCommon/HiresTextures.cpp | 127 +++++++++------------- 3 files changed, 49 insertions(+), 194 deletions(-) diff --git a/Source/Core/Common/Hash.cpp b/Source/Core/Common/Hash.cpp index 8ff20affe7..7074e12e55 100644 --- a/Source/Core/Common/Hash.cpp +++ b/Source/Core/Common/Hash.cpp @@ -332,64 +332,6 @@ static u64 GetCRC32(const u8* src, u32 len, u32 samples) #endif -/* - * NOTE: This hash function is used for custom texture loading/dumping, so - * it should not be changed, which would require all custom textures to be - * recalculated for their new hash values. If the hashing function is - * changed, make sure this one is still used when the legacy parameter is - * true. - */ -u64 GetHashHiresTexture(const u8* src, u32 len, u32 samples) -{ - const u64 m = 0xc6a4a7935bd1e995; - u64 h = len * m; - const int r = 47; - u32 Step = (len / 8); - const u64* data = (const u64*)src; - const u64* end = data + Step; - if (samples == 0) - samples = std::max(Step, 1u); - Step = Step / samples; - if (Step < 1) - Step = 1; - while (data < end) - { - u64 k = data[0]; - data += Step; - k *= m; - k ^= k >> r; - k *= m; - h ^= k; - h *= m; - } - - const u8* data2 = (const u8*)end; - - switch (len & 7) - { - case 7: - h ^= u64(data2[6]) << 48; - case 6: - h ^= u64(data2[5]) << 40; - case 5: - h ^= u64(data2[4]) << 32; - case 4: - h ^= u64(data2[3]) << 24; - case 3: - h ^= u64(data2[2]) << 16; - case 2: - h ^= u64(data2[1]) << 8; - case 1: - h ^= u64(data2[0]); - h *= m; - }; - - h ^= h >> r; - h *= m; - h ^= h >> r; - - return h; -} #else // CRC32 hash using the SSE4.2 instruction @@ -553,63 +495,6 @@ static u64 GetMurmurHash3(const u8* src, u32 len, u32 samples) return *((u64*)&out); } - -/* - * FIXME: The old 32-bit version of this hash made different hashes than the - * 64-bit version. Until someone can make a new version of the 32-bit one that - * makes identical hashes, this is just a c/p of the 64-bit one. - */ -u64 GetHashHiresTexture(const u8* src, u32 len, u32 samples) -{ - const u64 m = 0xc6a4a7935bd1e995ULL; - u64 h = len * m; - const int r = 47; - u32 Step = (len / 8); - const u64* data = (const u64*)src; - const u64* end = data + Step; - if (samples == 0) - samples = std::max(Step, 1u); - Step = Step / samples; - if (Step < 1) - Step = 1; - while (data < end) - { - u64 k = data[0]; - data += Step; - k *= m; - k ^= k >> r; - k *= m; - h ^= k; - h *= m; - } - - const u8* data2 = (const u8*)end; - - switch (len & 7) - { - case 7: - h ^= u64(data2[6]) << 48; - case 6: - h ^= u64(data2[5]) << 40; - case 5: - h ^= u64(data2[4]) << 32; - case 4: - h ^= u64(data2[3]) << 24; - case 3: - h ^= u64(data2[2]) << 16; - case 2: - h ^= u64(data2[1]) << 8; - case 1: - h ^= u64(data2[0]); - h *= m; - }; - - h ^= h >> r; - h *= m; - h ^= h >> r; - - return h; -} #endif u64 GetHash64(const u8* src, u32 len, u32 samples) diff --git a/Source/Core/Common/Hash.h b/Source/Core/Common/Hash.h index 4e5010d6ee..42f5741b40 100644 --- a/Source/Core/Common/Hash.h +++ b/Source/Core/Common/Hash.h @@ -11,6 +11,5 @@ u32 HashFletcher(const u8* data_u8, size_t length); // FAST. Length & 1 == 0. u32 HashAdler32(const u8* data, size_t len); // Fairly accurate, slightly slower u32 HashEctor(const u8* ptr, int length); // JUNK. DO NOT USE FOR NEW THINGS -u64 GetHashHiresTexture(const u8* src, u32 len, u32 samples = 0); u64 GetHash64(const u8* src, u32 len, u32 samples); void SetHash64Function(); diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index d658980999..6362636387 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -44,8 +44,6 @@ static std::unordered_map> s_textureC static std::mutex s_textureCacheMutex; static std::mutex s_textureCacheAquireMutex; // for high priority access static Common::Flag s_textureCacheAbortLoading; -static bool s_check_native_format; -static bool s_check_new_format; static std::thread s_prefetcher; @@ -57,9 +55,6 @@ HiresTexture::Level::Level() : data(nullptr, SOIL_free_image_data) void HiresTexture::Init() { - s_check_native_format = false; - s_check_new_format = false; - Update(); } @@ -112,12 +107,6 @@ void HiresTexture::Update() std::string filename; SplitPath(path, nullptr, &filename, nullptr); - if (filename.substr(0, code.length()) == code) - { - s_textureMap[filename] = {path, false}; - s_check_native_format = true; - } - if (filename.substr(0, s_format_prefix.length()) == s_format_prefix) { const size_t arb_index = filename.rfind("_arb"); @@ -125,7 +114,6 @@ void HiresTexture::Update() if (has_arbitrary_mipmaps) filename.erase(arb_index, 4); s_textureMap[filename] = {path, has_arbitrary_mipmaps}; - s_check_new_format = true; } } @@ -228,81 +216,64 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co size_t tlut_size, u32 width, u32 height, TextureFormat format, bool has_mipmaps, bool dump) { - std::string name = ""; - if (!dump && s_check_native_format) + if (!dump && s_textureMap.empty()) + return ""; + + // checking for min/max on paletted textures + u32 min = 0xffff; + u32 max = 0; + switch (tlut_size) { - // 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; - name = StringFromFormat("%s_%08x_%i", SConfig::GetInstance().GetGameID().c_str(), - (u32)(tex_hash ^ tlut_hash), (u16)format); - if (s_textureMap.find(name) != s_textureMap.end()) + case 0: + break; + case 16 * 2: + for (size_t i = 0; i < texture_size; i++) { - return name; + 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; } - 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; - } + u64 tex_hash = XXH64(texture, texture_size, 0); + u64 tlut_hash = tlut_size ? XXH64(tlut, tlut_size, 0) : 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("%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", static_cast(format)); + std::string fullname = basename + tlutname + formatname; - 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", static_cast(format)); - std::string fullname = basename + tlutname + formatname; + // try to match a wildcard template + if (!dump && s_textureMap.find(basename + "_*" + formatname) != s_textureMap.end()) + return basename + "_*" + 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(fullname) != s_textureMap.end()) + return fullname; - // else generate the complete texture - if (dump || s_textureMap.find(fullname) != s_textureMap.end()) - return fullname; - } - - return name; + return ""; } u32 HiresTexture::CalculateMipCount(u32 width, u32 height)