-
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 1 commit
a95c480
82ceec3
7f73d24
410a2b4
143a2dd
f3e8670
a39935d
3e00584
4a267d2
6c57da1
5259e5c
001113c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ class RenderTile; | |
class TransformState; | ||
class PatternAtlas; | ||
class LineAtlas; | ||
class SymbolBucket; | ||
|
||
class LayerRenderData { | ||
public: | ||
|
@@ -29,7 +30,7 @@ class LayerRenderData { | |
|
||
class LayerPlacementData { | ||
public: | ||
std::reference_wrapper<Bucket> bucket; | ||
std::reference_wrapper<SymbolBucket> bucket; | ||
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. it's better to keep generic interface here, otherwise LTO will not be able to reduce SymbolLayer-related symbols from the binary if the symbol layer is disabled. 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. Right, thanks! I switched back to |
||
std::reference_wrapper<const RenderTile> tile; | ||
std::shared_ptr<FeatureIndex> featureIndex; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
#include <mbgl/tile/geometry_tile.hpp> | ||
#include <mbgl/util/math.hpp> | ||
#include <utility> | ||
#include <list> | ||
|
||
namespace mbgl { | ||
|
||
|
@@ -111,9 +112,45 @@ Placement::Placement() : collisionIndex({}, MapMode::Static), collisionGroups(tr | |
|
||
void Placement::placeLayer(const RenderLayer& layer) { | ||
std::set<uint32_t> seenCrossTileIDs; | ||
std::list<BucketPlacementParameters> parameters; | ||
|
||
for (const auto& item : layer.getPlacementData()) { | ||
Bucket& bucket = item.bucket; | ||
BucketPlacementParameters params{item.tile, layer.baseImpl->source, item.featureIndex}; | ||
SymbolBucket& bucket = item.bucket; | ||
if (bucket.sortKeyRanges.size() == 0) { | ||
BucketPlacementParameters params{ | ||
item.bucket, | ||
item.tile, | ||
projMatrix, | ||
layer.baseImpl->source, | ||
item.featureIndex, | ||
showCollisionBoxes, | ||
0.0f, | ||
0, | ||
bucket.symbolInstances.size()}; | ||
parameters.push_back(params); | ||
|
||
} else { | ||
for (const SortKeyRange& sortKeyRange : bucket.sortKeyRanges) { | ||
BucketPlacementParameters params{ | ||
item.bucket, | ||
item.tile, | ||
projMatrix, | ||
layer.baseImpl->source, | ||
item.featureIndex, | ||
showCollisionBoxes, | ||
sortKeyRange.sortKey, | ||
sortKeyRange.symbolInstanceStart, | ||
sortKeyRange.symbolInstanceEnd}; | ||
|
||
auto sortPosition = std::upper_bound(parameters.cbegin(), parameters.cend(), params); | ||
parameters.insert(sortPosition, std::move(params)); | ||
} | ||
} | ||
} | ||
|
||
|
||
for (auto& params : parameters) { | ||
SymbolBucket& bucket = params.bucket; | ||
bucket.place(*this, params, seenCrossTileIDs); | ||
} | ||
} | ||
|
@@ -656,8 +693,9 @@ 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); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,9 +88,15 @@ class CollisionGroups { | |
|
||
class BucketPlacementParameters { | ||
public: | ||
friend bool operator<(const BucketPlacementParameters& lhs, const BucketPlacementParameters& rhs) { return lhs.sortKey < rhs.sortKey; } | ||
SymbolBucket& bucket; | ||
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.
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. Would it be ok 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. Could we instead just pre-sort 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. Yep, changed to your suggestion. This means that there are now possibly multiple entries into LayerPlacementData per tile which we have to account for elsewhere |
||
const RenderTile& tile; | ||
std::string sourceId; | ||
std::shared_ptr<FeatureIndex> featureIndex; | ||
bool showCollisionBoxes; | ||
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