Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Replace robin-hood-hashing with unordered_dense #7473

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/vvl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,27 @@ jobs:

linux:
runs-on: ubuntu-22.04
name: "linux (${{matrix.sanitize}} sanitizer, ${{matrix.config}}, robinhood ${{matrix.robin_hood}} )"
name: "linux (${{matrix.sanitize}} sanitizer, ${{matrix.config}}, unordered_dense ${{matrix.unordered_dense}} )"
strategy:
fail-fast: false
matrix:
sanitize: [ address, thread ]
config: [debug, release]
robin_hood: [ "ON" ]
unordered_dense: [ "ON" ]
include:
# Test with Robin Hood disabled
# Test with unordered_dense disabled
# Chromium build, and some package managers don't use it.
- config: release
robin_hood: "OFF"
unordered_dense: "OFF"
sanitize: address
steps:
- uses: actions/checkout@v4
- uses: lukka/get-cmake@latest
- uses: hendrikmuhs/[email protected]
with:
key: ${{ matrix.config }}-${{ matrix.sanitize }}-${{matrix.robin_hood}}
key: ${{ matrix.config }}-${{ matrix.sanitize }}-${{matrix.unordered_dense}}
- run: sudo apt-get -qq update && sudo apt-get install -y libwayland-dev xorg-dev
- run: python scripts/tests.py --build --config ${{ matrix.config }} --cmake='-DUSE_ROBIN_HOOD_HASHING=${{matrix.robin_hood}}'
- run: python scripts/tests.py --build --config ${{ matrix.config }} --cmake='-DUSE_UNORDERED_DENSE=${{matrix.unordered_dense}}'
env:
CFLAGS: -fsanitize=${{ matrix.sanitize }}
CXXFLAGS: -fsanitize=${{ matrix.sanitize }}
Expand Down Expand Up @@ -145,7 +145,7 @@ jobs:
build-ci/external/glslang/build/install
build-ci/external/googltest/build/install
build-ci/external/mimalloc/build/install
build-ci/external/robin-hood-hashing/build/install
build-ci/external/unordered_dense/build/install
build-ci/external/SPIRV-Headers/build/install
build-ci/external/SPIRV-Tools/build/install
build-ci/external/Vulkan-Headers/build/install
Expand Down
10 changes: 5 additions & 5 deletions layers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ target_link_libraries(VkLayer_utils PUBLIC
target_include_directories(VkLayer_utils SYSTEM PRIVATE external)
target_include_directories(VkLayer_utils PUBLIC . ${API_TYPE})

find_package(robin_hood CONFIG)
option(USE_ROBIN_HOOD_HASHING "robin_hood provides faster versions of std::unordered_map and std::unordered_set" ${robin_hood_FOUND})
if (USE_ROBIN_HOOD_HASHING)
target_link_libraries(VkLayer_utils PUBLIC robin_hood::robin_hood)
target_compile_definitions(VkLayer_utils PUBLIC USE_ROBIN_HOOD_HASHING)
find_package(unordered_dense CONFIG)
option(USE_UNORDERED_DENSE "unordered_denser provides faster versions of std::unordered_map and std::unordered_set" ${unordered_dense_FOUND})
if (USE_UNORDERED_DENSE)
target_link_libraries(VkLayer_utils PUBLIC unordered_dense::unordered_dense)
target_compile_definitions(VkLayer_utils PUBLIC USE_UNORDERED_DENSE)
endif()

# Using mimalloc on non-Windows OSes currently results in unit test instability with some
Expand Down
59 changes: 9 additions & 50 deletions layers/containers/custom_containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,65 +32,27 @@
#include <optional>
#include <utility>

#ifdef USE_ROBIN_HOOD_HASHING
#include "robin_hood.h"
#ifdef USE_UNORDERED_DENSE
#include "ankerl/unordered_dense.h"
#else
#include <unordered_set>
#endif

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

#ifdef USE_ROBIN_HOOD_HASHING
#ifdef USE_UNORDERED_DENSE
template <typename T>
using hash = robin_hood::hash<T>;
using hash = ankerl::unordered_dense::hash<T>;

template <typename Key, typename Hash = robin_hood::hash<Key>, typename KeyEqual = std::equal_to<Key>>
using unordered_set = robin_hood::unordered_set<Key, Hash, KeyEqual>;
template <typename Key, typename Hash = ankerl::unordered_dense::hash<Key>, typename KeyEqual = std::equal_to<Key>>
using unordered_set = ankerl::unordered_dense::set<Key, Hash, KeyEqual>;

template <typename Key, typename T, typename Hash = robin_hood::hash<Key>, typename KeyEqual = std::equal_to<Key>>
using unordered_map = robin_hood::unordered_map<Key, T, Hash, KeyEqual>;
template <typename Key, typename T, typename Hash = ankerl::unordered_dense::hash<Key>, typename KeyEqual = std::equal_to<Key>>
using unordered_map = ankerl::unordered_dense::map<Key, T, Hash, KeyEqual>;

template <typename Key, typename T>
using map_entry = robin_hood::pair<Key, T>;

// robin_hood-compatible insert_iterator (std:: uses the wrong insert method)
// NOTE: std::iterator was deprecated in C++17, and newer versions of libstdc++ appear to mark this as such.
template <typename T>
struct insert_iterator {
using iterator_category = std::output_iterator_tag;
using value_type = typename T::value_type;
using iterator = typename T::iterator;
using difference_type = void;
using pointer = void;
using reference = T &;

insert_iterator(reference t, iterator i) : container(&t), iter(i) {}

insert_iterator &operator=(const value_type &value) {
auto result = container->insert(value);
iter = result.first;
++iter;
return *this;
}

insert_iterator &operator=(value_type &&value) {
auto result = container->insert(std::move(value));
iter = result.first;
++iter;
return *this;
}

insert_iterator &operator*() { return *this; }

insert_iterator &operator++() { return *this; }

insert_iterator &operator++(int) { return *this; }

private:
T *container;
iterator iter;
};
using map_entry = std::pair<Key, T>;
#else
template <typename T>
using hash = std::hash<T>;
Expand All @@ -103,9 +65,6 @@ using unordered_map = std::unordered_map<Key, T, Hash, KeyEqual>;

template <typename Key, typename T>
using map_entry = std::pair<Key, T>;

template <typename T>
using insert_iterator = std::insert_iterator<T>;
#endif

} // namespace vvl
Expand Down
7 changes: 2 additions & 5 deletions layers/core_checks/cc_image_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,8 @@ void CoreChecks::TransitionFinalSubpassLayouts(vvl::CommandBuffer *cb_state) {

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

// Helper to update the Global or Overlay layout map
Expand Down
6 changes: 3 additions & 3 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ if (UPDATE_DEPS)
include("${UPDATE_DEPS_DIR}/helper.cmake")
endif()
endif()
if (ROBIN_HOOD_HASHING_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${ROBIN_HOOD_HASHING_INSTALL_DIR})
set(CMAKE_REQUIRE_FIND_PACKAGE_robin_hood TRUE PARENT_SCOPE)
if (UNORDERED_DENSE_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${UNORDERED_DENSE_INSTALL_DIR})
set(CMAKE_REQUIRE_FIND_PACKAGE_unordered_dense TRUE PARENT_SCOPE)
endif()
if (GLSLANG_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${GLSLANG_INSTALL_DIR})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vulkan_utility_libraries_dir = "//external/Vulkan-Utility-Libraries"
vvl_spirv_tools_dir = "//external/SPIRV-Tools"
vvl_spirv_headers_dir = "//external/SPIRV-Headers"
vvl_glslang_dir = "//external/glslang/"
robin_hood_headers_dir = "//external/robin-hood-hashing/src/include"
unordered_dense_headers_dir = "//external/unordered_dense/include"

# Subdirectories for generated files
vulkan_data_subdir = ""
Expand Down
17 changes: 7 additions & 10 deletions scripts/known_good.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@
"commit": "7657cb1c698aa684cfb0546b97b5ff64626a5300"
},
{
"name": "robin-hood-hashing",
"url": "https://github.com/martinus/robin-hood-hashing.git",
"sub_dir": "robin-hood-hashing",
"build_dir": "robin-hood-hashing/build",
"install_dir": "robin-hood-hashing/build/install",
"cmake_options": [
"-DRH_STANDALONE_PROJECT=OFF"
],
"commit": "3.11.5"
"name": "unordered_dense",
"url": "https://github.com/martinus/unordered_dense.git",
"sub_dir": "unordered_dense",
"build_dir": "unordered_dense/build",
"install_dir": "unordered_dense/build/install",
"commit": "v4.4.0"
},
{
"name": "mimalloc",
Expand Down Expand Up @@ -149,7 +146,7 @@
"Vulkan-Utility-Libraries": "VULKAN_UTILITY_LIBRARIES_INSTALL_DIR",
"SPIRV-Headers": "SPIRV_HEADERS_INSTALL_DIR",
"SPIRV-Tools": "SPIRV_TOOLS_INSTALL_DIR",
"robin-hood-hashing": "ROBIN_HOOD_HASHING_INSTALL_DIR",
"unordered_dense": "UNORDERED_DENSE_INSTALL_DIR",
"googletest": "GOOGLETEST_INSTALL_DIR",
"mimalloc": "MIMALLOC_INSTALL_DIR"
}
Expand Down
Loading