From 60889db1a61ce492657cf5886b7b47200868cf67 Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Tue, 19 Nov 2024 11:33:58 -0800 Subject: [PATCH 1/9] Set deferred deletions aside and schedule them once per frame (per source) --- CMakeLists.txt | 1 + bazel/core.bzl | 1 + include/mbgl/util/unique_function.hpp | 71 +++++++++++++++++++++++++++ src/mbgl/renderer/tile_pyramid.cpp | 3 ++ src/mbgl/tile/tile_cache.cpp | 70 +++++++++++++++----------- src/mbgl/tile/tile_cache.hpp | 6 ++- 6 files changed, 123 insertions(+), 29 deletions(-) create mode 100644 include/mbgl/util/unique_function.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 52267c770b0..3fc30bd8917 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -435,6 +435,7 @@ list(APPEND INCLUDE_FILES ${PROJECT_SOURCE_DIR}/include/mbgl/util/traits.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/type_list.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/unitbezier.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/util/unique_function.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/util.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/variant.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/vectors.hpp diff --git a/bazel/core.bzl b/bazel/core.bzl index 472fde18105..c6781ca3cfd 100644 --- a/bazel/core.bzl +++ b/bazel/core.bzl @@ -861,6 +861,7 @@ MLN_CORE_HEADERS = [ "include/mbgl/util/traits.hpp", "include/mbgl/util/type_list.hpp", "include/mbgl/util/unitbezier.hpp", + "include/mbgl/util/unique_function.hpp", "include/mbgl/util/util.hpp", "include/mbgl/util/variant.hpp", "include/mbgl/util/vectors.hpp", diff --git a/include/mbgl/util/unique_function.hpp b/include/mbgl/util/unique_function.hpp new file mode 100644 index 00000000000..c02efeb631a --- /dev/null +++ b/include/mbgl/util/unique_function.hpp @@ -0,0 +1,71 @@ +#pragma once + +#include + +namespace mbgl { +namespace util { + +// C++20 non-copying lambda capture, pending C++23 `move_only_function` +// Adapted from https://stackoverflow.com/a/52358928/135138 +template +class unique_function : public std::function { + using base = std::function; + +public: + unique_function() noexcept = default; + + unique_function(std::nullptr_t) noexcept + : base(nullptr) {} + + template + requires requires(Fn f) { + { f() } -> std::same_as>; + } + unique_function(Fn &&f) + : base(wrapper>{std::forward>(f)}) {} + + unique_function(unique_function &&) = default; + + unique_function &operator=(unique_function &&) = default; + + template + requires requires(Fn f) { + { f() } -> std::same_as>; + } + unique_function &operator=(Fn &&f) { + base::operator=(wrapper>{std::forward>(f)}); + return *this; + } + + using base::operator(); + +private: + template + struct wrapper; + + // specialization for MoveConstructible-only Fn + template + struct wrapper && std::is_move_constructible_v>> { + Fn fn; + + wrapper(Fn &&fn) + : fn(std::forward(fn)) {} + wrapper(wrapper &&) = default; + wrapper &operator=(wrapper &&) = default; + + // these two functions are instantiated by std::function and are never called + // We can't delete this or `fn` is uninitialized for non-DefaultContructible types + wrapper(const wrapper &rhs) + : fn(const_cast(rhs.fn)) { + throw std::runtime_error{{}}; + } + wrapper &operator=(const wrapper &) = delete; + + template + auto operator()(Args &&...args) { + return fn(std::forward(args)...); + } + }; +}; +} // namespace util +} // namespace mbgl diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp index 4533e6f7549..3e79657b5bf 100644 --- a/src/mbgl/renderer/tile_pyramid.cpp +++ b/src/mbgl/renderer/tile_pyramid.cpp @@ -82,6 +82,7 @@ void TilePyramid::update(const std::vector>& l tiles.clear(); renderedTiles.clear(); + cache.deferPendingReleases(); return; } @@ -279,6 +280,8 @@ void TilePyramid::update(const std::vector>& l tile.usedByRenderedLayers |= tile.layerPropertiesUpdated(layerProperties); } } + + cache.deferPendingReleases(); } void TilePyramid::handleWrapJump(float lng) { diff --git a/src/mbgl/tile/tile_cache.cpp b/src/mbgl/tile/tile_cache.cpp index 2bbde03a82b..512dbe9beaf 100644 --- a/src/mbgl/tile/tile_cache.cpp +++ b/src/mbgl/tile/tile_cache.cpp @@ -1,6 +1,9 @@ #include + #include #include +#include + #include namespace mbgl { @@ -26,16 +29,17 @@ void TileCache::setSize(size_t size_) { } namespace { - -/// This exists solely to prevent a problem where temporary lambda captures -/// are retained for the duration of the scope instead of being destroyed immediately. -template +// Capturing `std::vector>` directly produces an error related to +// copying, but this somehow avoids the same problem. It may be possible to eliminate it. struct CaptureWrapper { - CaptureWrapper(std::unique_ptr&& item_) - : item(std::move(item_)) {} - CaptureWrapper(const CaptureWrapper& other) - : item(other.item) {} - std::shared_ptr item; + std::vector> releases; + + CaptureWrapper(std::vector>&& x) + : releases(std::move(x)) {} + CaptureWrapper(CaptureWrapper&&) = default; + CaptureWrapper& operator=(CaptureWrapper&&) = default; + CaptureWrapper(CaptureWrapper const&) = delete; + CaptureWrapper& operator=(CaptureWrapper const&) = delete; }; } // namespace @@ -43,26 +47,36 @@ void TileCache::deferredRelease(std::unique_ptr&& tile) { MLN_TRACE_FUNC(); tile->cancel(); + pendingReleases.push_back(std::move(tile)); +} + +void TileCache::deferPendingReleases() { + MLN_TRACE_FUNC(); + + constexpr std::size_t scheduleThreshold = 1; + if (pendingReleases.size() < scheduleThreshold) { + return; + } + + // Block destruction until the cleanup task is complete + { + std::lock_guard counterLock{deferredSignalLock}; + deferredDeletionsPending++; + } + + threadPool.schedule( + util::unique_function{[this, wrap_{CaptureWrapper{std::move(pendingReleases)}}]() mutable { + MLN_TRACE_ZONE(deferPendingReleases lambda); + MLN_ZONE_VALUE(wrap_.releases.size()); + + // Run the deletions + wrap_.releases.clear(); - // The `std::function` must be created in a separate statement from the `schedule` call. - // Creating a `std::function` from a lambda involves a copy, which is why we must use - // `shared_ptr` rather than `unique_ptr` for the capture. As a result, a temporary holds - // a reference until the construction is complete and the lambda is destroyed. - // If this temporary outlives the `schedule` call, and the function is executed immediately - // by a waiting thread and is already complete, that temporary reference ends up being the - // last one and the destruction actually occurs here on this thread. - std::function func{[tile_{CaptureWrapper{std::move(tile)}}, this]() mutable { - tile_.item = {}; - - std::lock_guard counterLock(deferredSignalLock); - deferredDeletionsPending--; - deferredSignal.notify_all(); - }}; - - std::unique_lock counterLock(deferredSignalLock); - deferredDeletionsPending++; - - threadPool.schedule(std::move(func)); + // Wake up a waiting destructor + std::lock_guard counterLock{deferredSignalLock}; + deferredDeletionsPending--; + deferredSignal.notify_all(); + }}); } void TileCache::add(const OverscaledTileID& key, std::unique_ptr&& tile) { diff --git a/src/mbgl/tile/tile_cache.hpp b/src/mbgl/tile/tile_cache.hpp index db9f8658c46..72a4ccd15ec 100644 --- a/src/mbgl/tile/tile_cache.hpp +++ b/src/mbgl/tile/tile_cache.hpp @@ -43,13 +43,17 @@ class TileCache { bool has(const OverscaledTileID& key); void clear(); - /// Destroy a tile without blocking + /// Set aside a tile to be destroyed later, without blocking void deferredRelease(std::unique_ptr&&); + /// Schedule any accumulated deferred tiles to be destroyed + void deferPendingReleases(); + private: std::map> tiles; std::list orderedKeys; TaggedScheduler threadPool; + std::vector> pendingReleases; size_t deferredDeletionsPending{0}; std::mutex deferredSignalLock; std::condition_variable deferredSignal; From d31954523bf906e8d9f10bb7c73ff4454ae1ff93 Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Tue, 19 Nov 2024 11:53:02 -0800 Subject: [PATCH 2/9] release pending items before waiting --- include/mbgl/util/unique_function.hpp | 4 ++-- src/mbgl/tile/tile_cache.cpp | 12 ++++++++++++ src/mbgl/tile/tile_cache.hpp | 10 +--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/mbgl/util/unique_function.hpp b/include/mbgl/util/unique_function.hpp index c02efeb631a..880748ad79e 100644 --- a/include/mbgl/util/unique_function.hpp +++ b/include/mbgl/util/unique_function.hpp @@ -48,8 +48,8 @@ class unique_function : public std::function { struct wrapper && std::is_move_constructible_v>> { Fn fn; - wrapper(Fn &&fn) - : fn(std::forward(fn)) {} + wrapper(Fn &&fn_) + : fn(std::forward(fn_)) {} wrapper(wrapper &&) = default; wrapper &operator=(wrapper &&) = default; diff --git a/src/mbgl/tile/tile_cache.cpp b/src/mbgl/tile/tile_cache.cpp index 512dbe9beaf..619afd9a1ad 100644 --- a/src/mbgl/tile/tile_cache.cpp +++ b/src/mbgl/tile/tile_cache.cpp @@ -8,6 +8,18 @@ namespace mbgl { +TileCache::~TileCache() { + MLN_TRACE_FUNC(); + + clear(); + pendingReleases.clear(); + + std::unique_lock counterLock(deferredSignalLock); + while (deferredDeletionsPending != 0) { + deferredSignal.wait(counterLock); + } +} + void TileCache::setSize(size_t size_) { MLN_TRACE_FUNC(); diff --git a/src/mbgl/tile/tile_cache.hpp b/src/mbgl/tile/tile_cache.hpp index 72a4ccd15ec..fea185a32ba 100644 --- a/src/mbgl/tile/tile_cache.hpp +++ b/src/mbgl/tile/tile_cache.hpp @@ -18,15 +18,7 @@ class TileCache { TileCache(const TaggedScheduler& threadPool_, size_t size_ = 0) : threadPool(threadPool_), size(size_) {} - - ~TileCache() { - clear(); - - std::unique_lock counterLock(deferredSignalLock); - while (deferredDeletionsPending != 0) { - deferredSignal.wait(counterLock); - } - } + ~TileCache(); /// Change the maximum size of the cache. void setSize(size_t); From 0bf1090f0f47e71144c9e562027c5cca67d3c86c Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Tue, 19 Nov 2024 15:28:24 -0800 Subject: [PATCH 3/9] clear vector to resume a well-defined state --- src/mbgl/tile/tile_cache.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/mbgl/tile/tile_cache.cpp b/src/mbgl/tile/tile_cache.cpp index 619afd9a1ad..3bbaa2b083f 100644 --- a/src/mbgl/tile/tile_cache.cpp +++ b/src/mbgl/tile/tile_cache.cpp @@ -76,19 +76,21 @@ void TileCache::deferPendingReleases() { deferredDeletionsPending++; } - threadPool.schedule( - util::unique_function{[this, wrap_{CaptureWrapper{std::move(pendingReleases)}}]() mutable { - MLN_TRACE_ZONE(deferPendingReleases lambda); - MLN_ZONE_VALUE(wrap_.releases.size()); - - // Run the deletions - wrap_.releases.clear(); - - // Wake up a waiting destructor - std::lock_guard counterLock{deferredSignalLock}; - deferredDeletionsPending--; - deferredSignal.notify_all(); - }}); + CaptureWrapper wrap{std::move(pendingReleases)}; + pendingReleases.clear(); + + threadPool.schedule(util::unique_function{[this, wrap_{std::move(wrap)}]() mutable { + MLN_TRACE_ZONE(deferPendingReleases lambda); + MLN_ZONE_VALUE(wrap_.releases.size()); + + // Run the deletions + wrap_.releases.clear(); + + // Wake up a waiting destructor + std::lock_guard counterLock{deferredSignalLock}; + deferredDeletionsPending--; + deferredSignal.notify_all(); + }}); } void TileCache::add(const OverscaledTileID& key, std::unique_ptr&& tile) { From 2e43839a11625e63ae8debcc16fde16ff91bf9b5 Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Wed, 20 Nov 2024 13:49:57 -0800 Subject: [PATCH 4/9] back out capture changes --- CMakeLists.txt | 1 - bazel/core.bzl | 1 - include/mbgl/util/unique_function.hpp | 71 --------------------------- src/mbgl/tile/tile_cache.cpp | 38 +++++++------- 4 files changed, 21 insertions(+), 90 deletions(-) delete mode 100644 include/mbgl/util/unique_function.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fc30bd8917..52267c770b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -435,7 +435,6 @@ list(APPEND INCLUDE_FILES ${PROJECT_SOURCE_DIR}/include/mbgl/util/traits.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/type_list.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/unitbezier.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/util/unique_function.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/util.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/variant.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/vectors.hpp diff --git a/bazel/core.bzl b/bazel/core.bzl index c6781ca3cfd..472fde18105 100644 --- a/bazel/core.bzl +++ b/bazel/core.bzl @@ -861,7 +861,6 @@ MLN_CORE_HEADERS = [ "include/mbgl/util/traits.hpp", "include/mbgl/util/type_list.hpp", "include/mbgl/util/unitbezier.hpp", - "include/mbgl/util/unique_function.hpp", "include/mbgl/util/util.hpp", "include/mbgl/util/variant.hpp", "include/mbgl/util/vectors.hpp", diff --git a/include/mbgl/util/unique_function.hpp b/include/mbgl/util/unique_function.hpp deleted file mode 100644 index 880748ad79e..00000000000 --- a/include/mbgl/util/unique_function.hpp +++ /dev/null @@ -1,71 +0,0 @@ -#pragma once - -#include - -namespace mbgl { -namespace util { - -// C++20 non-copying lambda capture, pending C++23 `move_only_function` -// Adapted from https://stackoverflow.com/a/52358928/135138 -template -class unique_function : public std::function { - using base = std::function; - -public: - unique_function() noexcept = default; - - unique_function(std::nullptr_t) noexcept - : base(nullptr) {} - - template - requires requires(Fn f) { - { f() } -> std::same_as>; - } - unique_function(Fn &&f) - : base(wrapper>{std::forward>(f)}) {} - - unique_function(unique_function &&) = default; - - unique_function &operator=(unique_function &&) = default; - - template - requires requires(Fn f) { - { f() } -> std::same_as>; - } - unique_function &operator=(Fn &&f) { - base::operator=(wrapper>{std::forward>(f)}); - return *this; - } - - using base::operator(); - -private: - template - struct wrapper; - - // specialization for MoveConstructible-only Fn - template - struct wrapper && std::is_move_constructible_v>> { - Fn fn; - - wrapper(Fn &&fn_) - : fn(std::forward(fn_)) {} - wrapper(wrapper &&) = default; - wrapper &operator=(wrapper &&) = default; - - // these two functions are instantiated by std::function and are never called - // We can't delete this or `fn` is uninitialized for non-DefaultContructible types - wrapper(const wrapper &rhs) - : fn(const_cast(rhs.fn)) { - throw std::runtime_error{{}}; - } - wrapper &operator=(const wrapper &) = delete; - - template - auto operator()(Args &&...args) { - return fn(std::forward(args)...); - } - }; -}; -} // namespace util -} // namespace mbgl diff --git a/src/mbgl/tile/tile_cache.cpp b/src/mbgl/tile/tile_cache.cpp index 3bbaa2b083f..c0c534a2c75 100644 --- a/src/mbgl/tile/tile_cache.cpp +++ b/src/mbgl/tile/tile_cache.cpp @@ -2,7 +2,6 @@ #include #include -#include #include @@ -41,17 +40,17 @@ void TileCache::setSize(size_t size_) { } namespace { -// Capturing `std::vector>` directly produces an error related to -// copying, but this somehow avoids the same problem. It may be possible to eliminate it. +/// This exists solely to prevent a problem where temporary lambda captures +/// are retained for the duration of the scope instead of being destroyed immediately. struct CaptureWrapper { - std::vector> releases; - - CaptureWrapper(std::vector>&& x) - : releases(std::move(x)) {} + CaptureWrapper(std::vector>&& items_) + : items(items_.size()) { + std::ranges::move(items_, items.begin()); + } CaptureWrapper(CaptureWrapper&&) = default; - CaptureWrapper& operator=(CaptureWrapper&&) = default; - CaptureWrapper(CaptureWrapper const&) = delete; - CaptureWrapper& operator=(CaptureWrapper const&) = delete; + CaptureWrapper(const CaptureWrapper& other) + : items(other.items) {} + std::vector> items; }; } // namespace @@ -79,18 +78,23 @@ void TileCache::deferPendingReleases() { CaptureWrapper wrap{std::move(pendingReleases)}; pendingReleases.clear(); - threadPool.schedule(util::unique_function{[this, wrap_{std::move(wrap)}]() mutable { + // The `std::function` must be created in a separate statement from the `schedule` call. + // Creating a `std::function` from a lambda involves a copy, which is why we must use + // `shared_ptr` rather than `unique_ptr` for the capture. As a result, a temporary holds + // a reference until the construction is complete and the lambda is destroyed. + // If this temporary outlives the `schedule` call, and the function is executed immediately + // by a waiting thread and is already complete, that temporary reference ends up being the + // last one and the destruction actually occurs here on this thread. + std::function func{[tile_{CaptureWrapper{std::move(wrap)}}, this]() mutable { MLN_TRACE_ZONE(deferPendingReleases lambda); MLN_ZONE_VALUE(wrap_.releases.size()); + tile_.items.clear(); - // Run the deletions - wrap_.releases.clear(); - - // Wake up a waiting destructor - std::lock_guard counterLock{deferredSignalLock}; + std::lock_guard counterLock(deferredSignalLock); deferredDeletionsPending--; deferredSignal.notify_all(); - }}); + }}; + threadPool.schedule(std::move(func)); } void TileCache::add(const OverscaledTileID& key, std::unique_ptr&& tile) { From f10768bc77a797ca46338ca86a46a9b85fdf6549 Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Wed, 20 Nov 2024 13:54:05 -0800 Subject: [PATCH 5/9] normalize syntax --- src/mbgl/tile/tile_cache.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mbgl/tile/tile_cache.cpp b/src/mbgl/tile/tile_cache.cpp index c0c534a2c75..9a05cefaaf4 100644 --- a/src/mbgl/tile/tile_cache.cpp +++ b/src/mbgl/tile/tile_cache.cpp @@ -13,10 +13,8 @@ TileCache::~TileCache() { clear(); pendingReleases.clear(); - std::unique_lock counterLock(deferredSignalLock); - while (deferredDeletionsPending != 0) { - deferredSignal.wait(counterLock); - } + std::unique_lock counterLock{deferredSignalLock}; + deferredSignal.wait(counterLock, [&]() { return deferredDeletionsPending == 0; }); } void TileCache::setSize(size_t size_) { @@ -94,6 +92,7 @@ void TileCache::deferPendingReleases() { deferredDeletionsPending--; deferredSignal.notify_all(); }}; + threadPool.schedule(std::move(func)); } From 949ef8bb02af63688e672e0228bd89a50532a4e9 Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Mon, 2 Dec 2024 10:14:40 -0800 Subject: [PATCH 6/9] improve coverage, rebase on main --- src/mbgl/tile/tile_cache.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mbgl/tile/tile_cache.cpp b/src/mbgl/tile/tile_cache.cpp index 9a05cefaaf4..9985352e022 100644 --- a/src/mbgl/tile/tile_cache.cpp +++ b/src/mbgl/tile/tile_cache.cpp @@ -46,8 +46,13 @@ struct CaptureWrapper { std::ranges::move(items_, items.begin()); } CaptureWrapper(CaptureWrapper&&) = default; + + // coverage:ignore-start + /// This copy constructor is required to build, but doesn't seem to be called. CaptureWrapper(const CaptureWrapper& other) : items(other.items) {} + // coverage:ignore-end + std::vector> items; }; } // namespace From a017ae45201dfa876f8b42d1dfdf2214fafc1c32 Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Mon, 2 Dec 2024 15:22:01 -0800 Subject: [PATCH 7/9] cherry-pick 366ebcc7d0 --- .github/workflows/android-ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index a26ad33a352..c121ca7bc01 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -212,6 +212,18 @@ jobs: working-directory: test/android steps: + - name: Free Disk Space (Ubuntu) + if: startsWith(runner.name, 'GitHub Actions') + uses: jlumbroso/free-disk-space@main + with: + tool-cache: false + android: false + dotnet: true + haskell: true + large-packages: true + docker-images: true + swap-storage: false + - uses: actions/checkout@v4 with: submodules: recursive From 0509b4086bd7730fda7b7ae0d97976b325217d5a Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Fri, 6 Dec 2024 08:27:41 -0800 Subject: [PATCH 8/9] test coverage --- src/mbgl/tile/tile_cache.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mbgl/tile/tile_cache.cpp b/src/mbgl/tile/tile_cache.cpp index 9985352e022..5104c3ea6ef 100644 --- a/src/mbgl/tile/tile_cache.cpp +++ b/src/mbgl/tile/tile_cache.cpp @@ -47,11 +47,9 @@ struct CaptureWrapper { } CaptureWrapper(CaptureWrapper&&) = default; - // coverage:ignore-start /// This copy constructor is required to build, but doesn't seem to be called. CaptureWrapper(const CaptureWrapper& other) : items(other.items) {} - // coverage:ignore-end std::vector> items; }; From 11d930f36b54598e0240facc74b74bb26c0704e1 Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Fri, 6 Dec 2024 09:36:57 -0800 Subject: [PATCH 9/9] fix type warnings --- src/mbgl/vulkan/context.cpp | 2 +- src/mbgl/vulkan/descriptor_set.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mbgl/vulkan/context.cpp b/src/mbgl/vulkan/context.cpp index 1acb4d691d4..bfa821aa6ef 100644 --- a/src/mbgl/vulkan/context.cpp +++ b/src/mbgl/vulkan/context.cpp @@ -584,7 +584,7 @@ void Context::buildUniformDescriptorSetLayout(vk::UniqueDescriptorSetLayout& lay for (size_t i = 0; i < uniformCount; ++i) { bindings.push_back(vk::DescriptorSetLayoutBinding() - .setBinding(i) + .setBinding(static_cast(i)) .setStageFlags(stageFlags) .setDescriptorType(vk::DescriptorType::eUniformBuffer) .setDescriptorCount(1)); diff --git a/src/mbgl/vulkan/descriptor_set.cpp b/src/mbgl/vulkan/descriptor_set.cpp index d8d6866e5e7..f27f0a23c3e 100644 --- a/src/mbgl/vulkan/descriptor_set.cpp +++ b/src/mbgl/vulkan/descriptor_set.cpp @@ -50,7 +50,7 @@ void DescriptorSet::createDescriptorPool(DescriptorPoolGrowable& growablePool) { const auto descriptorPoolInfo = vk::DescriptorPoolCreateInfo(poolFlags).setPoolSizes(size).setMaxSets(maxSets); growablePool.pools.emplace_back(device->createDescriptorPoolUnique(descriptorPoolInfo), maxSets); - growablePool.currentPoolIndex = growablePool.pools.size() - 1; + growablePool.currentPoolIndex = static_cast(growablePool.pools.size() - 1); }; void DescriptorSet::allocate() { @@ -73,7 +73,8 @@ void DescriptorSet::allocate() { growablePool.pools.begin(), growablePool.pools.end(), [&](const auto& p) { return !p.unusedSets.empty(); }); if (unusedPoolIt != growablePool.pools.end()) { - growablePool.currentPoolIndex = std::distance(growablePool.pools.begin(), unusedPoolIt); + growablePool.currentPoolIndex = static_cast( + std::distance(growablePool.pools.begin(), unusedPoolIt)); } else #endif { @@ -83,7 +84,8 @@ void DescriptorSet::allocate() { [&](const auto& p) { return p.remainingSets >= layouts.size(); }); if (freePoolIt != growablePool.pools.end()) { - growablePool.currentPoolIndex = std::distance(growablePool.pools.begin(), freePoolIt); + growablePool.currentPoolIndex = static_cast( + std::distance(growablePool.pools.begin(), freePoolIt)); } else { createDescriptorPool(growablePool); } @@ -161,7 +163,7 @@ void UniformDescriptorSet::update(const gfx::UniformBufferArray& uniforms, .setBufferInfo(descriptorBufferInfo) .setDescriptorCount(1) .setDescriptorType(vk::DescriptorType::eUniformBuffer) - .setDstBinding(index) + .setDstBinding(static_cast(index)) .setDstSet(descriptorSets[frameIndex]); device->updateDescriptorSets(writeDescriptorSet, nullptr); @@ -197,7 +199,7 @@ void ImageDescriptorSet::update(const std::array(id)) .setDstSet(descriptorSets[frameIndex]); device->updateDescriptorSets(writeDescriptorSet, nullptr);