Commit e662bb43 by Nicolas Capens Committed by Nicolas Capens

Improve the sampling routine cache key hash

On 64-bit platforms more collisions can be prevented by spreading the three 32-bit values more widely apart. Bug: b/137649247 Change-Id: Icf429b4fc5a3d5d4472b346b190e48ac429bf881 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34929 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent f046402b
...@@ -122,10 +122,12 @@ inline bool vk::Device::SamplingRoutineCache::Key::operator < (const Key& rhs) c ...@@ -122,10 +122,12 @@ inline bool vk::Device::SamplingRoutineCache::Key::operator < (const Key& rhs) c
inline std::size_t vk::Device::SamplingRoutineCache::Key::Hash::operator() (const Key& key) const noexcept inline std::size_t vk::Device::SamplingRoutineCache::Key::Hash::operator() (const Key& key) const noexcept
{ {
auto hash = key.instruction; // Combine three 32-bit integers into a 64-bit hash.
hash = (hash * 31) ^ key.sampler; // 2642239 is the largest prime which when cubed is smaller than 2^64.
hash = (hash * 31) ^ key.imageView; uint64_t hash = key.instruction;
return hash; hash = (hash * 2642239) ^ key.sampler;
hash = (hash * 2642239) ^ key.imageView;
return static_cast<std::size_t>(hash); // Truncates to 32-bits on 32-bit platforms.
} }
} // namespace vk } // namespace vk
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment