Skip to content

Commit d032769

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 fbb23c2 commit d032769

File tree

9 files changed

+43
-85
lines changed

9 files changed

+43
-85
lines changed

.github/workflows/vvl.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,27 @@ jobs:
6060

6161
linux:
6262
runs-on: ubuntu-22.04
63-
name: "linux (${{matrix.sanitize}} sanitizer, ${{matrix.config}}, robinhood ${{matrix.robin_hood}} )"
63+
name: "linux (${{matrix.sanitize}} sanitizer, ${{matrix.config}}, unordered_dense ${{matrix.unordered_dense}} )"
6464
strategy:
6565
fail-fast: false
6666
matrix:
6767
sanitize: [ address, thread ]
6868
config: [debug, release]
69-
robin_hood: [ "ON" ]
69+
unordered_dense: [ "ON" ]
7070
include:
71-
# Test with Robin Hood disabled
71+
# Test with unordered_dense disabled
7272
# Chromium build, and some package managers don't use it.
7373
- config: release
74-
robin_hood: "OFF"
74+
unordered_dense: "OFF"
7575
sanitize: address
7676
steps:
7777
- uses: actions/checkout@v4
7878
- uses: lukka/get-cmake@latest
7979
- uses: hendrikmuhs/[email protected]
8080
with:
81-
key: ${{ matrix.config }}-${{ matrix.sanitize }}-${{matrix.robin_hood}}
81+
key: ${{ matrix.config }}-${{ matrix.sanitize }}-${{matrix.unordered_dense}}
8282
- run: sudo apt-get -qq update && sudo apt-get install -y libwayland-dev xorg-dev
83-
- run: python scripts/tests.py --build --config ${{ matrix.config }} --cmake='-DUSE_ROBIN_HOOD_HASHING=${{matrix.robin_hood}}'
83+
- run: python scripts/tests.py --build --config ${{ matrix.config }} --cmake='-DUSE_CUSTOM_HASH_MAP=${{matrix.unordered_dense}}'
8484
env:
8585
CFLAGS: -fsanitize=${{ matrix.sanitize }}
8686
CXXFLAGS: -fsanitize=${{ matrix.sanitize }}
@@ -145,7 +145,7 @@ jobs:
145145
build-ci/external/glslang/build/install
146146
build-ci/external/googltest/build/install
147147
build-ci/external/mimalloc/build/install
148-
build-ci/external/robin-hood-hashing/build/install
148+
build-ci/external/unordered_dense/build/install
149149
build-ci/external/SPIRV-Headers/build/install
150150
build-ci/external/SPIRV-Tools/build/install
151151
build-ci/external/Vulkan-Headers/build/install

layers/CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ target_link_libraries(VkLayer_utils PUBLIC
8181
target_include_directories(VkLayer_utils SYSTEM PRIVATE external)
8282
target_include_directories(VkLayer_utils PUBLIC . ${API_TYPE})
8383

84-
find_package(robin_hood CONFIG)
85-
option(USE_ROBIN_HOOD_HASHING "robin_hood provides faster versions of std::unordered_map and std::unordered_set" ${robin_hood_FOUND})
86-
if (USE_ROBIN_HOOD_HASHING)
87-
target_link_libraries(VkLayer_utils PUBLIC robin_hood::robin_hood)
88-
target_compile_definitions(VkLayer_utils PUBLIC USE_ROBIN_HOOD_HASHING)
84+
find_package(unordered_dense CONFIG)
85+
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})
86+
if (USE_CUSTOM_HASH_MAP)
87+
target_link_libraries(VkLayer_utils PUBLIC unordered_dense::unordered_dense)
88+
target_compile_definitions(VkLayer_utils PUBLIC USE_CUSTOM_HASH_MAP)
8989
endif()
9090

9191
# 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
@@ -32,65 +32,32 @@
3232
#include <optional>
3333
#include <utility>
3434

35-
#ifdef USE_ROBIN_HOOD_HASHING
36-
#include "robin_hood.h"
35+
#ifdef USE_CUSTOM_HASH_MAP
36+
#include "ankerl/unordered_dense.h"
3737
#else
3838
#include <unordered_set>
3939
#endif
4040

4141
// namespace aliases to allow map and set implementations to easily be swapped out
4242
namespace vvl {
4343

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

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

86-
insert_iterator &operator++() { return *this; }
53+
template <typename Key, typename Hash = ankerl::unordered_dense::hash<Key>, typename KeyEqual = std::equal_to<Key>>
54+
using unordered_set = ankerl::unordered_dense::set<Key, Hash, KeyEqual>;
8755

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

90-
private:
91-
T *container;
92-
iterator iter;
93-
};
59+
template <typename Key, typename T>
60+
using map_entry = std::pair<Key, T>;
9461
#else
9562
template <typename T>
9663
using hash = std::hash<T>;
@@ -103,9 +70,6 @@ using unordered_map = std::unordered_map<Key, T, Hash, KeyEqual>;
10370

10471
template <typename Key, typename T>
10572
using map_entry = std::pair<Key, T>;
106-
107-
template <typename T>
108-
using insert_iterator = std::insert_iterator<T>;
10973
#endif
11074

11175
} // namespace vvl

layers/core_checks/cc_image_layout.cpp

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

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

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

layers/state_tracker/image_state.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ std::vector<VkPresentModeKHR> Surface::GetPresentModes(VkPhysicalDevice phys_dev
667667
assert(phys_dev);
668668
std::vector<VkPresentModeKHR> result;
669669
if (auto search = present_modes_data_.find(phys_dev); search != present_modes_data_.end()) {
670-
for (auto mode = search->second.begin(); mode != search->second.end(); mode++) {
670+
for (auto mode = search->second.begin(); mode != search->second.end(); ++mode) {
671671
result.push_back(mode->first);
672672
}
673673
return result;

layers/utils/vk_layer_utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ class vl_concurrent_unordered_map {
606606
private:
607607
static const int BUCKETS = (1 << BUCKETSLOG2);
608608

609-
vvl::unordered_map<Key, T, Hash> maps[BUCKETS];
609+
std::array<vvl::unordered_map<Key, T, Hash>, BUCKETS> maps;
610610
struct alignas(get_hardware_destructive_interference_size()) AlignedSharedMutex {
611611
std::shared_mutex lock;
612612
};

scripts/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ~~~
2-
# Copyright (c) 2023 LunarG, Inc.
2+
# Copyright (c) 2023-2024 LunarG, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -122,9 +122,9 @@ if (UPDATE_DEPS)
122122
include("${UPDATE_DEPS_DIR}/helper.cmake")
123123
endif()
124124
endif()
125-
if (ROBIN_HOOD_HASHING_INSTALL_DIR)
126-
list(APPEND CMAKE_PREFIX_PATH ${ROBIN_HOOD_HASHING_INSTALL_DIR})
127-
set(CMAKE_REQUIRE_FIND_PACKAGE_robin_hood TRUE PARENT_SCOPE)
125+
if (UNORDERED_DENSE_INSTALL_DIR)
126+
list(APPEND CMAKE_PREFIX_PATH ${UNORDERED_DENSE_INSTALL_DIR})
127+
set(CMAKE_REQUIRE_FIND_PACKAGE_unordered_dense TRUE PARENT_SCOPE)
128128
endif()
129129
if (GLSLANG_INSTALL_DIR)
130130
list(APPEND CMAKE_PREFIX_PATH ${GLSLANG_INSTALL_DIR})

scripts/gn/secondary/build_overrides/vulkan_validation_layers.gni

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2023 LunarG, Inc.
1+
# Copyright (c) 2019-2024 LunarG, Inc.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -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": "04896c462d9f3f504c99a4698605b6524af813c1"
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)