From 1442a64810e59dffe08c029727455cc88776bb15 Mon Sep 17 00:00:00 2001 From: wanghoi Date: Mon, 4 Aug 2025 21:24:21 +0800 Subject: [PATCH 1/2] RenderStateCache: Use XX128Hasher to compute DeviceHash Which makes hash consistent between 32 and 64 bits. (#688 related) --- Graphics/GraphicsTools/include/RenderStateCacheImpl.hpp | 2 +- Graphics/GraphicsTools/interface/XXH128Hasher.hpp | 2 ++ Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp | 8 +++++--- Graphics/GraphicsTools/src/XXH128Hasher.cpp | 5 +++++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Graphics/GraphicsTools/include/RenderStateCacheImpl.hpp b/Graphics/GraphicsTools/include/RenderStateCacheImpl.hpp index 40e9365ac0..3d82e06b25 100644 --- a/Graphics/GraphicsTools/include/RenderStateCacheImpl.hpp +++ b/Graphics/GraphicsTools/include/RenderStateCacheImpl.hpp @@ -137,7 +137,7 @@ class RenderStateCacheImpl final : public ObjectBase private: RefCntAutoPtr m_pDevice; const RENDER_DEVICE_TYPE m_DeviceType; - const size_t m_DeviceHash; // Hash of the device-specific properties + const XXH128Hash m_DeviceHash; // Hash of the device-specific properties const RenderStateCacheCreateInfo m_CI; RefCntAutoPtr m_pReloadSource; RefCntAutoPtr m_pSerializationDevice; diff --git a/Graphics/GraphicsTools/interface/XXH128Hasher.hpp b/Graphics/GraphicsTools/interface/XXH128Hasher.hpp index 44c433b779..8b1e1e12c9 100644 --- a/Graphics/GraphicsTools/interface/XXH128Hasher.hpp +++ b/Graphics/GraphicsTools/interface/XXH128Hasher.hpp @@ -123,6 +123,8 @@ struct XXH128State final void Update(const ShaderCreateInfo& ShaderCI) noexcept; + void Update(const XXH128Hash& Hash) noexcept; + template typename std::enable_if<(std::is_same::type, SamplerDesc>::value || std::is_same::type, StencilOpDesc>::value || diff --git a/Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp b/Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp index ce8d2d888d..3899268748 100644 --- a/Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp +++ b/Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp @@ -144,13 +144,15 @@ std::string RenderStateCacheImpl::MakeHashStr(const char* Name, const XXH128Hash } -static size_t ComputeDeviceAttribsHash(IRenderDevice* pDevice) +static XXH128Hash ComputeDeviceAttribsHash(IRenderDevice* pDevice) { if (pDevice == nullptr) - return 0; + return {}; const RenderDeviceInfo& DeviceInfo = pDevice->GetDeviceInfo(); - return ComputeHash(DeviceInfo.Type, DeviceInfo.NDC.MinZ, DeviceInfo.Features.SeparablePrograms); + XXH128State Hasher; + Hasher.Update(DeviceInfo.Type, DeviceInfo.NDC.MinZ, DeviceInfo.Features.SeparablePrograms); + return Hasher.Digest(); } RenderStateCacheImpl::RenderStateCacheImpl(IReferenceCounters* pRefCounters, diff --git a/Graphics/GraphicsTools/src/XXH128Hasher.cpp b/Graphics/GraphicsTools/src/XXH128Hasher.cpp index f08fff788d..1fea7f30c5 100644 --- a/Graphics/GraphicsTools/src/XXH128Hasher.cpp +++ b/Graphics/GraphicsTools/src/XXH128Hasher.cpp @@ -108,4 +108,9 @@ void XXH128State::Update(const ShaderCreateInfo& ShaderCI) noexcept } } +void XXH128State::Update(const XXH128Hash& Hash) noexcept +{ + Update(Hash.LowPart, Hash.HighPart); +} + } // namespace Diligent From cc901b67cea0b0be186a5098ede6db7210449ee1 Mon Sep 17 00:00:00 2001 From: wanghoi Date: Mon, 4 Aug 2025 21:34:31 +0800 Subject: [PATCH 2/2] chore: fix RenderStateCacheImpl.cpp format --- Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp b/Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp index 3899268748..245afcca11 100644 --- a/Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp +++ b/Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp @@ -150,7 +150,7 @@ static XXH128Hash ComputeDeviceAttribsHash(IRenderDevice* pDevice) return {}; const RenderDeviceInfo& DeviceInfo = pDevice->GetDeviceInfo(); - XXH128State Hasher; + XXH128State Hasher; Hasher.Update(DeviceInfo.Type, DeviceInfo.NDC.MinZ, DeviceInfo.Features.SeparablePrograms); return Hasher.Digest(); }