From 1424ddc356b9665f98ea98ef95840c5e429cb9fd Mon Sep 17 00:00:00 2001 From: Xu Date: Thu, 2 Jan 2025 11:06:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BC=95=E5=85=A5=20rapidhash=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E4=BD=BF=E7=94=A8=20wyhash=20=E8=BF=99?= =?UTF-8?q?=E4=BC=9A=E4=BD=BF=E6=95=88=E6=9E=9C=E7=BC=93=E5=AD=98=E5=A4=B1?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Magpie.Core/EffectCacheManager.cpp | 4 +- src/Magpie.Core/EffectCompiler.cpp | 3 +- src/Magpie.Core/FastHasher.cpp | 89 --------------------- src/Magpie.Core/FastHasher.h | 9 --- src/Magpie.Core/Magpie.Core.vcxproj | 2 - src/Magpie.Core/Magpie.Core.vcxproj.filters | 2 - src/Magpie/conanfile.txt | 1 + 7 files changed, 4 insertions(+), 106 deletions(-) delete mode 100644 src/Magpie.Core/FastHasher.cpp delete mode 100644 src/Magpie.Core/FastHasher.h diff --git a/src/Magpie.Core/EffectCacheManager.cpp b/src/Magpie.Core/EffectCacheManager.cpp index 7ada628f..365fc6f1 100644 --- a/src/Magpie.Core/EffectCacheManager.cpp +++ b/src/Magpie.Core/EffectCacheManager.cpp @@ -5,7 +5,7 @@ #include "Logger.h" #include "CommonSharedConstants.h" #include -#include "FastHasher.h" +#include #include "YasHelper.h" namespace yas::detail { @@ -239,7 +239,7 @@ void EffectCacheManager::Save(std::wstring_view effectName, uint32_t flags, std: } static std::wstring HexHash(std::span data) { - uint64_t hashBytes = FastHasher::HashData(data); + uint64_t hashBytes = rapidhash(data.data(), data.size()); static wchar_t oct2Hex[16] = { L'0',L'1',L'2',L'3',L'4',L'5',L'6',L'7', diff --git a/src/Magpie.Core/EffectCompiler.cpp b/src/Magpie.Core/EffectCompiler.cpp index 21a4d7ab..4f689304 100644 --- a/src/Magpie.Core/EffectCompiler.cpp +++ b/src/Magpie.Core/EffectCompiler.cpp @@ -1042,7 +1042,6 @@ static uint32_t GeneratePassSource( std::string_view cbHlsl, const SmallVector& commonBlocks, std::string_view passBlock, - const phmap::flat_hash_map* inlineParams, std::string& result, std::vector>& macros ) { @@ -1392,7 +1391,7 @@ static uint32_t CompilePasses( Win32Helper::RunParallel([&](uint32_t id) { std::string source; std::vector> macros; - if (GeneratePassSource(desc, id + 1, cbHlsl, commonBlocks, passBlocks[id], inlineParams, source, macros)) { + if (GeneratePassSource(desc, id + 1, cbHlsl, commonBlocks, passBlocks[id], source, macros)) { Logger::Get().Error(fmt::format("生成 Pass{} 失败", id + 1)); return; } diff --git a/src/Magpie.Core/FastHasher.cpp b/src/Magpie.Core/FastHasher.cpp deleted file mode 100644 index 9854fbd9..00000000 --- a/src/Magpie.Core/FastHasher.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "pch.h" -#include "FastHasher.h" -#include "Logger.h" -#include "StrHelper.h" - -namespace Magpie { - -//////////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// 哈希算法来自 https://github.com/wangyi-fudan/wyhash/blob/b8b740844c2e9830fd205302df76dcdd4fadcec9/wyhash.h -// -//////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// multiply and xor mix function, aka MUM -static uint64_t _wymix(uint64_t lhs, uint64_t rhs) noexcept { -#ifdef _M_X64 - uint64_t hi; - uint64_t lo = _umul128(lhs, rhs, &hi); -#elif defined(_M_ARM64) - uint64_t lo = lhs * rhs; - uint64_t hi = __umulh(lhs, rhs); -#else -#error "不支持的 CPU 架构" -#endif - return lo ^ hi; -} - -// read functions -static uint64_t _wyr8(const uint8_t* p) noexcept { - uint64_t v; - memcpy(&v, p, 8); - return v; -} - -static uint64_t _wyr4(const uint8_t* p) noexcept { - uint32_t v; - memcpy(&v, p, 4); - return v; -} - -static uint64_t _wyr3(const uint8_t* p, size_t k) noexcept { - return (((uint64_t)p[0]) << 16) | (((uint64_t)p[k >> 1]) << 8) | p[k - 1]; -} - -// the default secret parameters -static const uint64_t _wyp[4] = { 0xa0761d6478bd642full, 0xe7037ed1a0b428dbull, 0x8ebc6af09c88c6e3ull, 0x589965cc75374cc3ull }; - -uint64_t FastHasher::HashData(std::span data) noexcept { - const size_t len = data.size(); - uint64_t seed = _wyp[0]; - - const uint8_t* p = (const uint8_t*)data.data(); - uint64_t a, b; - if (len <= 16) { - if (len >= 4) { - a = (_wyr4(p) << 32) | _wyr4(p + ((len >> 3) << 2)); - b = (_wyr4(p + len - 4) << 32) | _wyr4(p + len - 4 - ((len >> 3) << 2)); - } else if (len > 0) { - a = _wyr3(p, len); - b = 0; - } else { - a = b = 0; - } - } else { - size_t i = len; - if (i > 48) { - uint64_t see1 = seed, see2 = seed; - do { - seed = _wymix(_wyr8(p) ^ _wyp[1], _wyr8(p + 8) ^ seed); - see1 = _wymix(_wyr8(p + 16) ^ _wyp[2], _wyr8(p + 24) ^ see1); - see2 = _wymix(_wyr8(p + 32) ^ _wyp[3], _wyr8(p + 40) ^ see2); - p += 48; - i -= 48; - } while (i > 48); - seed ^= see1 ^ see2; - } - - while (i > 16) { - seed = _wymix(_wyr8(p) ^ _wyp[1], _wyr8(p + 8) ^ seed); - i -= 16; - p += 16; - } - a = _wyr8(p + i - 16); b = _wyr8(p + i - 8); - } - - return _wymix(_wyp[1] ^ len, _wymix(a ^ _wyp[1], b ^ seed)); -} - -} diff --git a/src/Magpie.Core/FastHasher.h b/src/Magpie.Core/FastHasher.h deleted file mode 100644 index f197ead4..00000000 --- a/src/Magpie.Core/FastHasher.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -namespace Magpie { - -struct FastHasher { - static uint64_t HashData(std::span data) noexcept; -}; - -} diff --git a/src/Magpie.Core/Magpie.Core.vcxproj b/src/Magpie.Core/Magpie.Core.vcxproj index 29247972..ac8cc1e2 100644 --- a/src/Magpie.Core/Magpie.Core.vcxproj +++ b/src/Magpie.Core/Magpie.Core.vcxproj @@ -60,7 +60,6 @@ - @@ -125,7 +124,6 @@ - diff --git a/src/Magpie.Core/Magpie.Core.vcxproj.filters b/src/Magpie.Core/Magpie.Core.vcxproj.filters index 74be6b52..1ed4f95c 100644 --- a/src/Magpie.Core/Magpie.Core.vcxproj.filters +++ b/src/Magpie.Core/Magpie.Core.vcxproj.filters @@ -110,7 +110,6 @@ Include - Include @@ -184,7 +183,6 @@ - diff --git a/src/Magpie/conanfile.txt b/src/Magpie/conanfile.txt index b2bfcfb7..a8d0dc14 100644 --- a/src/Magpie/conanfile.txt +++ b/src/Magpie/conanfile.txt @@ -7,6 +7,7 @@ kuba-zip/0.3.2 muparser/2.3.4 yas/7.1.0 imgui/1.91.5 +rapidhash/1.0 [generators] MSBuildDeps