Skip to content

Commit 1442a64

Browse files
committed
RenderStateCache: Use XX128Hasher to compute DeviceHash
Which makes hash consistent between 32 and 64 bits. (#688 related)
1 parent f3e5352 commit 1442a64

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

Graphics/GraphicsTools/include/RenderStateCacheImpl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class RenderStateCacheImpl final : public ObjectBase<IRenderStateCache>
137137
private:
138138
RefCntAutoPtr<IRenderDevice> m_pDevice;
139139
const RENDER_DEVICE_TYPE m_DeviceType;
140-
const size_t m_DeviceHash; // Hash of the device-specific properties
140+
const XXH128Hash m_DeviceHash; // Hash of the device-specific properties
141141
const RenderStateCacheCreateInfo m_CI;
142142
RefCntAutoPtr<IShaderSourceInputStreamFactory> m_pReloadSource;
143143
RefCntAutoPtr<ISerializationDevice> m_pSerializationDevice;

Graphics/GraphicsTools/interface/XXH128Hasher.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ struct XXH128State final
123123

124124
void Update(const ShaderCreateInfo& ShaderCI) noexcept;
125125

126+
void Update(const XXH128Hash& Hash) noexcept;
127+
126128
template <typename T>
127129
typename std::enable_if<(std::is_same<typename std::remove_cv<T>::type, SamplerDesc>::value ||
128130
std::is_same<typename std::remove_cv<T>::type, StencilOpDesc>::value ||

Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,15 @@ std::string RenderStateCacheImpl::MakeHashStr(const char* Name, const XXH128Hash
144144
}
145145

146146

147-
static size_t ComputeDeviceAttribsHash(IRenderDevice* pDevice)
147+
static XXH128Hash ComputeDeviceAttribsHash(IRenderDevice* pDevice)
148148
{
149149
if (pDevice == nullptr)
150-
return 0;
150+
return {};
151151

152152
const RenderDeviceInfo& DeviceInfo = pDevice->GetDeviceInfo();
153-
return ComputeHash(DeviceInfo.Type, DeviceInfo.NDC.MinZ, DeviceInfo.Features.SeparablePrograms);
153+
XXH128State Hasher;
154+
Hasher.Update(DeviceInfo.Type, DeviceInfo.NDC.MinZ, DeviceInfo.Features.SeparablePrograms);
155+
return Hasher.Digest();
154156
}
155157

156158
RenderStateCacheImpl::RenderStateCacheImpl(IReferenceCounters* pRefCounters,

Graphics/GraphicsTools/src/XXH128Hasher.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,9 @@ void XXH128State::Update(const ShaderCreateInfo& ShaderCI) noexcept
108108
}
109109
}
110110

111+
void XXH128State::Update(const XXH128Hash& Hash) noexcept
112+
{
113+
Update(Hash.LowPart, Hash.HighPart);
114+
}
115+
111116
} // namespace Diligent

0 commit comments

Comments
 (0)