Skip to content

Commit f74ae97

Browse files
jeremyg-lunargarno-lunarg
authored andcommitted
build: Replace robin-hood-hashing with unordered_dense
robin-hood-hashing is no longer developed. unordered_dense is its replacement, by the same author.
1 parent 74ba799 commit f74ae97

File tree

7 files changed

+42
-80
lines changed

7 files changed

+42
-80
lines changed

.github/workflows/vvl.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ jobs:
7676
linux:
7777
needs: check_vvl
7878
runs-on: ubuntu-22.04
79-
name: "linux (${{matrix.sanitize}} sanitizer, ${{matrix.config}}, robinhood ${{matrix.robin_hood}} )"
79+
name: "linux (${{matrix.sanitize}} sanitizer, ${{matrix.config}}, unordered_dense ${{matrix.unordered_dense}} )"
8080
strategy:
8181
fail-fast: false
8282
matrix:
8383
sanitize: [ address, thread ]
8484
config: [debug, release]
85-
robin_hood: [ "ON" ]
85+
unordered_dense: [ "ON" ]
8686
include:
87-
# Test with Robin Hood disabled
87+
# Test with unordered_dense disabled
8888
# Chromium build, and some package managers don't use it.
8989
- config: release
90-
robin_hood: "OFF"
90+
unordered_dense: "OFF"
9191
sanitize: address
9292
exclude:
9393
# Have found over time this finds nothing extra, while taking the longest and using the most CI minutes.
@@ -99,12 +99,12 @@ jobs:
9999
- uses: lukka/get-cmake@latest
100100
- uses: hendrikmuhs/[email protected]
101101
with:
102-
key: ${{ matrix.config }}-${{ matrix.sanitize }}-${{matrix.robin_hood}}
102+
key: ${{ matrix.config }}-${{ matrix.sanitize }}-${{matrix.unordered_dense}}
103103
- run: sudo apt-get -qq update && sudo apt-get install -y libwayland-dev xorg-dev
104104
# This is to combat a bug when using 6.6 linux kernels with thread/address sanitizer
105105
# https://github.com/google/sanitizers/issues/1716
106106
- run: sudo sysctl vm.mmap_rnd_bits=28
107-
- run: python scripts/tests.py --build --config ${{ matrix.config }} --cmake='-DUSE_ROBIN_HOOD_HASHING=${{matrix.robin_hood}}'
107+
- run: python scripts/tests.py --build --config ${{ matrix.config }} --cmake='-DUSE_CUSTOM_HASH_MAP=${{matrix.unordered_dense}}'
108108
env:
109109
CFLAGS: -fsanitize=${{ matrix.sanitize }}
110110
CXXFLAGS: -fsanitize=${{ matrix.sanitize }}
@@ -208,7 +208,7 @@ jobs:
208208
build-ci/external/glslang/build/install
209209
build-ci/external/googltest/build/install
210210
build-ci/external/mimalloc/build/install
211-
build-ci/external/robin-hood-hashing/build/install
211+
build-ci/external/unordered_dense/build/install
212212
build-ci/external/SPIRV-Headers/build/install
213213
build-ci/external/SPIRV-Tools/build/install
214214
build-ci/external/Vulkan-Headers/build/install

layers/CMakeLists.txt

+8-4
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,15 @@ target_link_libraries(VkLayer_utils PUBLIC
7979
target_include_directories(VkLayer_utils SYSTEM PRIVATE external)
8080
target_include_directories(VkLayer_utils PUBLIC . ${API_TYPE})
8181

82-
find_package(robin_hood CONFIG)
83-
option(USE_ROBIN_HOOD_HASHING "robin_hood provides faster versions of std::unordered_map and std::unordered_set" ${robin_hood_FOUND})
8482
if (USE_ROBIN_HOOD_HASHING)
85-
target_link_libraries(VkLayer_utils PUBLIC robin_hood::robin_hood)
86-
target_compile_definitions(VkLayer_utils PUBLIC USE_ROBIN_HOOD_HASHING)
83+
message(WARNING "Option USE_ROBIN_HOOD_HASHING has been deprecated. Use USE_CUSTOM_HASH_MAP instead.")
84+
endif ()
85+
86+
find_package(unordered_dense CONFIG)
87+
option(USE_CUSTOM_HASH_MAP "Use a custom hash map (unordered_dense). It provides faster versions of std::unordered_map and std::unordered_set" ${unordered_dense_FOUND})
88+
if (USE_CUSTOM_HASH_MAP)
89+
target_link_libraries(VkLayer_utils PUBLIC unordered_dense::unordered_dense)
90+
target_compile_definitions(VkLayer_utils PUBLIC USE_CUSTOM_HASH_MAP)
8791
endif()
8892

8993
# Using mimalloc on non-Windows OSes currently results in unit test instability with some

layers/containers/custom_containers.h

+14-50
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#include <optional>
3131
#include <utility>
3232

33-
#ifdef USE_ROBIN_HOOD_HASHING
34-
#include "robin_hood.h"
33+
#ifdef USE_CUSTOM_HASH_MAP
34+
#include "ankerl/unordered_dense.h"
3535
#else
3636
#include <map>
3737
#include <set>
@@ -43,56 +43,23 @@
4343
// namespace aliases to allow map and set implementations to easily be swapped out
4444
namespace vvl {
4545

46-
#ifdef USE_ROBIN_HOOD_HASHING
46+
#ifdef USE_CUSTOM_HASH_MAP
4747
template <typename T>
48-
using hash = robin_hood::hash<T>;
48+
struct hash {
49+
std::size_t operator()(const T &s) const noexcept { return static_cast<std::size_t>(internal_hash{}(s)); }
4950

50-
template <typename Key, typename Hash = robin_hood::hash<Key>, typename KeyEqual = std::equal_to<Key>>
51-
using unordered_set = robin_hood::unordered_set<Key, Hash, KeyEqual>;
52-
53-
template <typename Key, typename T, typename Hash = robin_hood::hash<Key>, typename KeyEqual = std::equal_to<Key>>
54-
using unordered_map = robin_hood::unordered_map<Key, T, Hash, KeyEqual>;
55-
56-
template <typename Key, typename T>
57-
using map_entry = robin_hood::pair<Key, T>;
58-
59-
// robin_hood-compatible insert_iterator (std:: uses the wrong insert method)
60-
// NOTE: std::iterator was deprecated in C++17, and newer versions of libstdc++ appear to mark this as such.
61-
template <typename T>
62-
struct insert_iterator {
63-
using iterator_category = std::output_iterator_tag;
64-
using value_type = typename T::value_type;
65-
using iterator = typename T::iterator;
66-
using difference_type = void;
67-
using pointer = void;
68-
using reference = T &;
69-
70-
insert_iterator(reference t, iterator i) : container(&t), iter(i) {}
71-
72-
insert_iterator &operator=(const value_type &value) {
73-
auto result = container->insert(value);
74-
iter = result.first;
75-
++iter;
76-
return *this;
77-
}
78-
79-
insert_iterator &operator=(value_type &&value) {
80-
auto result = container->insert(std::move(value));
81-
iter = result.first;
82-
++iter;
83-
return *this;
84-
}
85-
86-
insert_iterator &operator*() { return *this; }
51+
private:
52+
using internal_hash = ankerl::unordered_dense::hash<T>;
53+
};
8754

88-
insert_iterator &operator++() { return *this; }
55+
template <typename Key, typename Hash = ankerl::unordered_dense::hash<Key>, typename KeyEqual = std::equal_to<Key>>
56+
using unordered_set = ankerl::unordered_dense::set<Key, Hash, KeyEqual>;
8957

90-
insert_iterator &operator++(int) { return *this; }
58+
template <typename Key, typename T, typename Hash = ankerl::unordered_dense::hash<Key>, typename KeyEqual = std::equal_to<Key>>
59+
using unordered_map = ankerl::unordered_dense::segmented_map<Key, T, Hash, KeyEqual>;
9160

92-
private:
93-
T *container;
94-
iterator iter;
95-
};
61+
template <typename Key, typename T>
62+
using map_entry = std::pair<Key, T>;
9663
#else
9764
template <typename T>
9865
using hash = std::hash<T>;
@@ -105,9 +72,6 @@ using unordered_map = std::unordered_map<Key, T, Hash, KeyEqual>;
10572

10673
template <typename Key, typename T>
10774
using map_entry = std::pair<Key, T>;
108-
109-
template <typename T>
110-
using insert_iterator = std::insert_iterator<T>;
11175
#endif
11276

11377
#if 1

layers/core_checks/cc_image_layout.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,8 @@ void CoreChecks::TransitionFinalSubpassLayouts(vvl::CommandBuffer &cb_state) {
161161

162162
static GlobalImageLayoutRangeMap *GetLayoutRangeMap(GlobalImageLayoutMap &map, const vvl::Image &image_state) {
163163
// This approach allows for a single hash lookup or/create new
164-
auto &layout_map = map[&image_state];
165-
if (!layout_map) {
166-
layout_map.emplace(image_state.subresource_encoder.SubresourceCount());
167-
}
168-
return &(*layout_map);
164+
auto result = map.emplace(&image_state, image_state.subresource_encoder.SubresourceCount());
165+
return &(result.first->second.value());
169166
}
170167

171168
// Helper to update the Global or Overlay layout map

scripts/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ if (UPDATE_DEPS)
126126
include("${UPDATE_DEPS_DIR}/helper.cmake")
127127
endif()
128128
endif()
129-
if (ROBIN_HOOD_HASHING_INSTALL_DIR)
130-
list(APPEND CMAKE_PREFIX_PATH ${ROBIN_HOOD_HASHING_INSTALL_DIR})
131-
set(CMAKE_REQUIRE_FIND_PACKAGE_robin_hood TRUE PARENT_SCOPE)
129+
if (UNORDERED_DENSE_INSTALL_DIR)
130+
list(APPEND CMAKE_PREFIX_PATH ${UNORDERED_DENSE_INSTALL_DIR})
131+
set(CMAKE_REQUIRE_FIND_PACKAGE_unordered_dense TRUE PARENT_SCOPE)
132132
endif()
133133
if (GLSLANG_INSTALL_DIR)
134134
list(APPEND CMAKE_PREFIX_PATH ${GLSLANG_INSTALL_DIR})

scripts/gn/secondary/build_overrides/vulkan_validation_layers.gni

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ vulkan_utility_libraries_dir = "//external/Vulkan-Utility-Libraries"
1818
vvl_spirv_tools_dir = "//external/SPIRV-Tools"
1919
vvl_spirv_headers_dir = "//external/SPIRV-Headers"
2020
vvl_glslang_dir = "//external/glslang/"
21-
robin_hood_headers_dir = "//external/robin-hood-hashing/src/include"
21+
unordered_dense_headers_dir = "//external/unordered_dense/include"
2222

2323
# Subdirectories for generated files
2424
vulkan_data_subdir = ""

scripts/known_good.json

+7-10
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,12 @@
4646
"commit": "02433568af277324e6d7fe4582b663f14165c563"
4747
},
4848
{
49-
"name": "robin-hood-hashing",
50-
"url": "https://github.com/martinus/robin-hood-hashing.git",
51-
"sub_dir": "robin-hood-hashing",
52-
"build_dir": "robin-hood-hashing/build",
53-
"install_dir": "robin-hood-hashing/build/install",
54-
"cmake_options": [
55-
"-DRH_STANDALONE_PROJECT=OFF"
56-
],
57-
"commit": "3.11.5"
49+
"name": "unordered_dense",
50+
"url": "https://github.com/martinus/unordered_dense.git",
51+
"sub_dir": "unordered_dense",
52+
"build_dir": "unordered_dense/build",
53+
"install_dir": "unordered_dense/build/install",
54+
"commit": "v4.0.4"
5855
},
5956
{
6057
"name": "mimalloc",
@@ -149,7 +146,7 @@
149146
"Vulkan-Utility-Libraries": "VULKAN_UTILITY_LIBRARIES_INSTALL_DIR",
150147
"SPIRV-Headers": "SPIRV_HEADERS_INSTALL_DIR",
151148
"SPIRV-Tools": "SPIRV_TOOLS_INSTALL_DIR",
152-
"robin-hood-hashing": "ROBIN_HOOD_HASHING_INSTALL_DIR",
149+
"unordered_dense": "UNORDERED_DENSE_INSTALL_DIR",
153150
"googletest": "GOOGLETEST_INSTALL_DIR",
154151
"mimalloc": "MIMALLOC_INSTALL_DIR"
155152
}

0 commit comments

Comments
 (0)