Drawable Renderer (#1570), Improve handling of multiple drawables per tile

This commit is contained in:
Tim Sylvester
2023-06-01 08:47:33 -07:00
committed by Bart Louwers
parent 51c270495b
commit ee7f57fcb4
5 changed files with 30 additions and 28 deletions

View File

@@ -77,9 +77,10 @@ public:
~TileLayerGroup() override;
void updateLayerIndex(int32_t newLayerIndex);
std::size_t getDrawableCount() const;
std::size_t getDrawableCount(mbgl::RenderPass, const OverscaledTileID&) const;
const gfx::UniqueDrawable& getDrawable(mbgl::RenderPass, const OverscaledTileID&) const;
std::vector<gfx::UniqueDrawable> removeDrawables(mbgl::RenderPass, const OverscaledTileID&);
void addDrawable(mbgl::RenderPass, const OverscaledTileID&, gfx::UniqueDrawable&&);
@@ -87,7 +88,11 @@ public:
void observeDrawables(std::function<void(const gfx::Drawable&)>) const override;
void observeDrawables(std::function<void(gfx::UniqueDrawable&)>) override;
void clearDrawables();
/// Call the provided function for each drawable for the given tile
void observeDrawables(mbgl::RenderPass, const OverscaledTileID&,
std::function<void(const gfx::Drawable&)>) const;
std::size_t clearDrawables();
protected:
struct Impl;

View File

@@ -48,9 +48,9 @@ std::size_t TileLayerGroup::getDrawableCount() const {
static const gfx::UniqueDrawable no_tile;
const gfx::UniqueDrawable& TileLayerGroup::getDrawable(mbgl::RenderPass pass, const OverscaledTileID& id) const {
const auto hit = impl->tileDrawables.find({pass, id});
return (hit == impl->tileDrawables.end()) ? no_tile : hit->second;
std::size_t TileLayerGroup::getDrawableCount(mbgl::RenderPass pass, const OverscaledTileID& id) const {
const auto range = impl->tileDrawables.equal_range({pass, id});
return std::distance(range.first, range.second);
}
std::vector<gfx::UniqueDrawable> TileLayerGroup::removeDrawables(mbgl::RenderPass pass, const OverscaledTileID& id) {
@@ -100,8 +100,16 @@ void TileLayerGroup::observeDrawables(std::function<void(gfx::UniqueDrawable&)>
}
}
void TileLayerGroup::clearDrawables() {
void TileLayerGroup::observeDrawables(mbgl::RenderPass pass, const OverscaledTileID& tileID,
std::function<void(const gfx::Drawable&)> f) const {
const auto range = impl->tileDrawables.equal_range({pass, tileID});
std::for_each(range.first, range.second, [&f](const auto& pair){ f(*pair.second); });
}
std::size_t TileLayerGroup::clearDrawables() {
const auto count = impl->tileDrawables.size();
impl->tileDrawables.clear();
return count;
}
} // namespace mbgl

View File

@@ -286,19 +286,9 @@ void RenderBackgroundLayer::update(gfx::ShaderRegistry& shaders,
// For each tile in the cover set, add a tile drawable if one doesn't already exist.
// We currently assume only one drawable per tile.
for (const auto& tileID : tileCover) {
auto& tileDrawable = tileLayerGroup->getDrawable(renderPass, tileID);
if (!(renderPass & drawPasses)) {
// Not in this pass
if (tileDrawable) {
tileLayerGroup->removeDrawables(renderPass, tileID);
++stats.tileDrawablesRemoved;
}
continue;
}
if (tileDrawable) {
// Already created, update it.
// If we already have drawables for this tile, skip.
// If a drawable needs to be updated, that's handled in the layer tweaker.
if (tileLayerGroup->getDrawableCount(renderPass, tileID) > 0) {
continue;
}

View File

@@ -311,8 +311,7 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
for (const RenderTile& tile : *renderTiles) {
const auto& tileID = tile.getOverscaledTileID();
auto& tileDrawable = tileLayerGroup->getDrawable(renderPass, tileID);
if (tileDrawable) {
if (tileLayerGroup->getDrawableCount(renderPass, tileID) > 0) {
continue;
}

View File

@@ -20,6 +20,7 @@
#include <mbgl/tile/tile.hpp>
#include <mbgl/util/convert.hpp>
#include <mbgl/util/intersection_tests.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/math.hpp>
namespace mbgl {
@@ -287,8 +288,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
if (!renderTiles || renderTiles->empty()) {
if (tileLayerGroup) {
stats.tileDrawablesRemoved += tileLayerGroup->getDrawableCount();
tileLayerGroup->clearDrawables();
stats.tileDrawablesRemoved += tileLayerGroup->clearDrawables();
}
return;
}
@@ -359,7 +359,11 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
for (const RenderTile& tile : *renderTiles) {
const auto& tileID = tile.getOverscaledTileID();
auto& tileDrawable = tileLayerGroup->getDrawable(renderPass, tileID);
// If we already have drawables for this tile, skip.
// If a drawable needs to be updated, that's handled in the layer tweaker.
if (tileLayerGroup->getDrawableCount(renderPass, tileID) > 0) {
continue;
}
const LayerRenderData* renderData = getRenderDataForPass(tile, renderPass);
if (!renderData) {
@@ -449,10 +453,6 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
}
}
if (tileDrawable) {
continue;
}
if (doFill && !fillBuilder && fillShader) {
fillBuilder = context.createDrawableBuilder("fill");
fillBuilder->setShader(fillShader);