aboutsummaryrefslogtreecommitdiff
path: root/src/common/container_hash.h
diff options
context:
space:
mode:
authorTakoroka <137927095+Takoroka@users.noreply.github.com>2026-10-29 07:05:03 -0400
committerTakoroka <137927095+Takoroka@users.noreply.github.com>2026-10-29 20:49:47 -0400
commit6b7185676d59976bf02f6666368032067ff344bc (patch)
treebcd2114dce7b4d591db3c19b43214e62e1deddd3 /src/common/container_hash.h
parentbe449da3db512f790c71d60a58e027a5898a0446 (diff)
common: pass-through hash for integer and pointer keys; RangeSet::Intersects
Common::unordered_map/set defaulted to std::hash, a byte-wise FNV-1a on MSVC for integers and pointers, which boost's flat containers then mix again: the GPU thread's page maps (shader and query cache invalidation, per inline upload) spent ~1% in it. Integer and pointer keys now go through as they are and boost mixes them. BufferCache::IsRegionGpuModified visited every GPU-written range inside the query just to answer yes or no; without per-fence downloads those ranges stay fragmented and it was ~4% of title 1's GPU thread (inline uploads). RangeSet::Intersects answers with one lookup. Inline uploads: 10.5% -> 7.5% of the GPU thread.
Diffstat (limited to 'src/common/container_hash.h')
-rw-r--r--src/common/container_hash.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/container_hash.h b/src/common/container_hash.h
index d7477f7e4f..f06f69ad8b 100644
--- a/src/common/container_hash.h
+++ b/src/common/container_hash.h
@@ -19,6 +19,28 @@
namespace Common {
+/// The default hash of Common::unordered_map/set. std::hash of an integer or a pointer is a
+/// byte-wise FNV-1a on MSVC, and boost's flat containers mix a hash that does not say it
+/// avalanches anyway: pass those keys through (the GPU thread's page maps looked keys up
+/// tens of thousands of times a second with it). Other keys keep std::hash.
+template <class Key>
+struct FastHash : std::hash<Key> {};
+
+template <class Key>
+ requires std::is_integral_v<Key>
+struct FastHash<Key> {
+ std::size_t operator()(Key key) const noexcept {
+ return static_cast<std::size_t>(key);
+ }
+};
+
+template <class T>
+struct FastHash<T*> {
+ std::size_t operator()(T* pointer) const noexcept {
+ return reinterpret_cast<std::size_t>(pointer);
+ }
+};
+
namespace detail {
template <typename T>