-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core] sort symbols using symbol-sort-key before placement #16023
Changes from 10 commits
a95c480
82ceec3
7f73d24
410a2b4
143a2dd
f3e8670
a39935d
3e00584
4a267d2
6c57da1
5259e5c
001113c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,6 +424,8 @@ void RenderSymbolLayer::render(PaintParameters& parameters) { | |
assert(bucket.paintProperties.find(getID()) != bucket.paintProperties.end()); | ||
const auto& bucketPaintProperties = bucket.paintProperties.at(getID()); | ||
|
||
bucket.justReloaded = false; | ||
|
||
auto addRenderables = [&renderableSegments, &tile, renderData, &bucketPaintProperties, it = renderableSegments.begin()] (auto& segments, const SymbolType type) mutable { | ||
for (auto& segment : segments) { | ||
it = renderableSegments.emplace_hint(it, SegmentWrapper{std::ref(segment)}, tile, *renderData, bucketPaintProperties, segment.sortKey, type); | ||
|
@@ -580,7 +582,32 @@ void RenderSymbolLayer::prepare(const LayerPrepareParameters& params) { | |
const Tile* tile = params.source->getRenderedTile(renderTile.id); | ||
assert(tile); | ||
assert(tile->kind == Tile::Kind::Geometry); | ||
placementData.push_back({*bucket, renderTile, static_cast<const GeometryTile*>(tile)->getFeatureIndex()}); | ||
|
||
bool firstInBucket = true; | ||
|
||
if (bucket->sortKeyRanges.size() == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
placementData.push_back({*bucket, | ||
renderTile, | ||
static_cast<const GeometryTile*>(tile)->getFeatureIndex(), | ||
firstInBucket, | ||
0.0f, | ||
0, | ||
bucket->symbolInstances.size()}); | ||
} else { | ||
for (const SortKeyRange& sortKeyRange : bucket->sortKeyRanges) { | ||
LayerPlacementData layerData{*bucket, | ||
renderTile, | ||
static_cast<const GeometryTile*>(tile)->getFeatureIndex(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: might make sense to cache |
||
firstInBucket, | ||
sortKeyRange.sortKey, | ||
sortKeyRange.symbolInstanceStart, | ||
sortKeyRange.symbolInstanceEnd}; | ||
auto sortPosition = std::upper_bound(placementData.cbegin(), placementData.cend(), layerData); | ||
placementData.insert(sortPosition, std::move(layerData)); | ||
|
||
firstInBucket = false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#include <mbgl/text/placement.hpp> | ||
|
||
#include <list> | ||
#include <mbgl/layout/symbol_layout.hpp> | ||
#include <mbgl/renderer/bucket.hpp> | ||
#include <mbgl/renderer/buckets/symbol_bucket.hpp> | ||
#include <mbgl/renderer/render_layer.hpp> | ||
#include <mbgl/renderer/render_tile.hpp> | ||
#include <mbgl/renderer/update_parameters.hpp> | ||
#include <mbgl/text/placement.hpp> | ||
#include <mbgl/tile/geometry_tile.hpp> | ||
#include <mbgl/util/math.hpp> | ||
#include <utility> | ||
|
@@ -113,7 +113,12 @@ void Placement::placeLayer(const RenderLayer& layer) { | |
std::set<uint32_t> seenCrossTileIDs; | ||
for (const auto& item : layer.getPlacementData()) { | ||
Bucket& bucket = item.bucket; | ||
BucketPlacementParameters params{item.tile, layer.baseImpl->source, item.featureIndex}; | ||
BucketPlacementParameters params{item.tile, | ||
layer.baseImpl->source, | ||
item.featureIndex, | ||
item.sortKey, | ||
item.symbolInstanceStart, | ||
item.symbolInstanceEnd}; | ||
bucket.place(*this, params, seenCrossTileIDs); | ||
} | ||
} | ||
|
@@ -656,18 +661,17 @@ void Placement::placeBucket(const SymbolBucket& bucket, | |
} | ||
|
||
} else { | ||
for (const SymbolInstance& symbol : bucket.symbolInstances) { | ||
placeSymbol(symbol); | ||
auto endIt = bucket.symbolInstances.begin() + params.symbolInstanceEnd; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we check that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, would an assert be what you're looking for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert is fine (as long as there are no possible code paths that could violate it 😄 ) |
||
for (auto it = bucket.symbolInstances.begin() + params.symbolInstanceStart; it != endIt; it++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. styling nit: better have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: ++it |
||
placeSymbol(*it); | ||
} | ||
} | ||
|
||
bucket.justReloaded = false; | ||
|
||
// As long as this placement lives, we have to hold onto this bucket's | ||
// matching FeatureIndex/data for querying purposes | ||
retainedQueryData.emplace(std::piecewise_construct, | ||
std::forward_as_tuple(bucket.bucketInstanceId), | ||
std::forward_as_tuple(bucket.bucketInstanceId, params.featureIndex, overscaledID)); | ||
std::forward_as_tuple(bucket.bucketInstanceId), | ||
std::forward_as_tuple(bucket.bucketInstanceId, params.featureIndex, overscaledID)); | ||
} | ||
|
||
void Placement::commit() { | ||
|
@@ -737,7 +741,9 @@ void Placement::commit() { | |
void Placement::updateLayerBuckets(const RenderLayer& layer, const TransformState& state, bool updateOpacities) const { | ||
std::set<uint32_t> seenCrossTileIDs; | ||
for (const auto& item : layer.getPlacementData()) { | ||
item.bucket.get().updateVertices(*this, updateOpacities, state, item.tile, seenCrossTileIDs); | ||
if (item.firstInBucket) { | ||
item.bucket.get().updateVertices(*this, updateOpacities, state, item.tile, seenCrossTileIDs); | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,9 @@ class BucketPlacementParameters { | |
const RenderTile& tile; | ||
std::string sourceId; | ||
std::shared_ptr<FeatureIndex> featureIndex; | ||
float sortKey; | ||
size_t symbolInstanceStart; | ||
size_t symbolInstanceEnd; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could the newly added fields be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These properties come from |
||
}; | ||
|
||
class Placement; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sortKeyRanges.back().symbolInstanceEnd = symbolInstances.size();
shall be enough, no?begin()
+ size =end()
🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like I'm setting it before adding the new symbol instance. I guess moving it after and removing the
+ 1
would be cleaner