Enable FastPFOR encodings in MLT (#4146)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
Tim Sylvester
2026-07-14 12:31:41 -07:00
committed by GitHub
parent f442c704b8
commit 247c776d26
34 changed files with 227 additions and 78 deletions

View File

@@ -54,6 +54,7 @@ Map::Impl::Impl(RendererFrontend& frontend_,
mode(mapOptions.mapMode()),
pixelRatio(mapOptions.pixelRatio()),
crossSourceCollisions(mapOptions.crossSourceCollisions()),
fastPFOREnabled(mapOptions.fastPFOREnabled()),
fileSource(std::move(fileSource_)),
style(std::make_unique<style::Style>(fileSource, pixelRatio, frontend_.getThreadPool())),
annotationManager(*style) {
@@ -132,6 +133,7 @@ void Map::Impl::onUpdate() {
.prefetchZoomDelta = prefetchZoomDelta,
.stillImageRequest = bool(stillImageRequest),
.crossSourceCollisions = crossSourceCollisions,
.fastPFOREnabled = fastPFOREnabled,
.tileLodMinRadius = tileLodMinRadius,
.tileLodScale = tileLodScale,
.tileLodPitchThreshold = tileLodPitchThreshold,

View File

@@ -91,6 +91,7 @@ public:
const MapMode mode;
const float pixelRatio;
const bool crossSourceCollisions;
const bool fastPFOREnabled;
MapDebugOptions debugOptions{MapDebugOptions::NoDebug};
std::unique_ptr<gfx::RenderingStatsView> renderingStatsView;

View File

@@ -11,6 +11,7 @@ public:
bool crossSourceCollisions = true;
Size size = {64, 64};
float pixelRatio = 1.0;
bool fastPFOREnabled = false;
};
// These requires the complete type of Impl.
@@ -82,4 +83,13 @@ float MapOptions::pixelRatio() const {
return impl_->pixelRatio;
}
MapOptions& MapOptions::withFastPFOREnabled(bool enable) {
impl_->fastPFOREnabled = enable;
return *this;
}
bool MapOptions::fastPFOREnabled() const {
return impl_->fastPFOREnabled;
}
} // namespace mbgl

View File

@@ -339,6 +339,7 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
std::unique_ptr<RenderSource> renderSource = RenderSource::create(entry.second, threadPool);
renderSource->setObserver(this);
renderSource->setCacheEnabled(tileCacheEnabled);
renderSource->setFastPFOREnabled(updateParameters->fastPFOREnabled);
renderSources.emplace(entry.first, std::move(renderSource));
}
transformState = updateParameters->transformState;

View File

@@ -3,13 +3,14 @@
#include <mbgl/annotation/render_annotation_source.hpp>
#include <mbgl/layermanager/layer_manager.hpp>
#include <mbgl/renderer/render_source_observer.hpp>
#include <mbgl/renderer/sources/render_geojson_source.hpp>
#include <mbgl/renderer/sources/render_raster_source.hpp>
#include <mbgl/renderer/sources/render_raster_dem_source.hpp>
#include <mbgl/renderer/sources/render_vector_source.hpp>
#include <mbgl/renderer/sources/render_image_source.hpp>
#include <mbgl/renderer/sources/render_custom_geometry_source.hpp>
#include <mbgl/renderer/sources/render_geojson_source.hpp>
#include <mbgl/renderer/sources/render_image_source.hpp>
#include <mbgl/renderer/sources/render_raster_dem_source.hpp>
#include <mbgl/renderer/sources/render_raster_source.hpp>
#include <mbgl/renderer/sources/render_vector_source.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
#include <mbgl/renderer/update_parameters.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/util/constants.hpp>
@@ -21,28 +22,24 @@ namespace mbgl {
using namespace style;
std::unique_ptr<RenderSource> RenderSource::create(const Immutable<Source::Impl>& impl,
const TaggedScheduler& threadPool_) {
const TaggedScheduler& threadPool) {
switch (impl->type) {
case SourceType::Vector:
// the TileSet isn't available yet, so we can't make different sources by format
return std::make_unique<RenderVectorSource>(staticImmutableCast<TileSource::Impl>(impl),
std::move(threadPool_));
return std::make_unique<RenderVectorSource>(staticImmutableCast<TileSource::Impl>(impl), threadPool);
case SourceType::Raster:
return std::make_unique<RenderRasterSource>(staticImmutableCast<TileSource::Impl>(impl),
std::move(threadPool_));
return std::make_unique<RenderRasterSource>(staticImmutableCast<TileSource::Impl>(impl), threadPool);
case SourceType::RasterDEM:
return std::make_unique<RenderRasterDEMSource>(staticImmutableCast<TileSource::Impl>(impl),
std::move(threadPool_));
return std::make_unique<RenderRasterDEMSource>(staticImmutableCast<TileSource::Impl>(impl), threadPool);
case SourceType::GeoJSON:
return std::make_unique<RenderGeoJSONSource>(staticImmutableCast<GeoJSONSource::Impl>(impl),
std::move(threadPool_));
return std::make_unique<RenderGeoJSONSource>(staticImmutableCast<GeoJSONSource::Impl>(impl), threadPool);
case SourceType::Video:
assert(false);
return nullptr;
case SourceType::Annotations:
if (LayerManager::annotationsEnabled) {
return std::make_unique<RenderAnnotationSource>(staticImmutableCast<AnnotationSource::Impl>(impl),
std::move(threadPool_));
threadPool);
} else {
assert(false);
return nullptr;
@@ -51,7 +48,7 @@ std::unique_ptr<RenderSource> RenderSource::create(const Immutable<Source::Impl>
return std::make_unique<RenderImageSource>(staticImmutableCast<ImageSource::Impl>(impl));
case SourceType::CustomVector:
return std::make_unique<RenderCustomGeometrySource>(staticImmutableCast<CustomGeometrySource::Impl>(impl),
std::move(threadPool_));
threadPool);
}
// Not reachable, but placate GCC.

View File

@@ -33,6 +33,7 @@ class Tile;
class TileParameters;
class TransformParameters;
class TransformState;
class UpdateParameters;
namespace gfx {
class UploadPass;
@@ -103,7 +104,9 @@ public:
const std::optional<std::string>&,
const std::optional<std::string>&) {}
virtual void setCacheEnabled(bool) {};
virtual void setCacheEnabled(bool) {}
virtual void setFastPFOREnabled(bool) {}
virtual void reduceMemoryUse() = 0;

View File

@@ -22,29 +22,30 @@ void RenderVectorSource::updateInternal(const Tileset& tileset,
const bool needsRendering,
const bool needsRelayout,
const TileParameters& parameters) {
tilePyramid.update(
layers,
needsRendering,
needsRelayout,
parameters,
*baseImpl,
util::tileSize_I,
tileset.zoomRange,
tileset.bounds,
[&](const OverscaledTileID& tileID, TileObserver* observer_) -> std::unique_ptr<VectorTile> {
if (!isMLT.has_value()) {
auto impl = staticImmutableCast<style::TileSource::Impl>(baseImpl);
assert(impl->tileset); // we should have one by now
if (impl->tileset) {
isMLT = (impl->tileset->vectorEncoding == Tileset::VectorEncoding::MLT);
}
}
if (isMLT && *isMLT) {
return std::make_unique<VectorMLTTile>(tileID, baseImpl->id, parameters, tileset, observer_);
} else {
return std::make_unique<VectorMVTTile>(tileID, baseImpl->id, parameters, tileset, observer_);
}
});
tilePyramid.update(layers,
needsRendering,
needsRelayout,
parameters,
*baseImpl,
util::tileSize_I,
tileset.zoomRange,
tileset.bounds,
[&](const OverscaledTileID& tileID, TileObserver* observer_) -> std::unique_ptr<VectorTile> {
if (!isMLT.has_value()) {
auto impl = staticImmutableCast<style::TileSource::Impl>(baseImpl);
assert(impl->tileset); // we should have one by now
if (impl->tileset) {
isMLT = (impl->tileset->vectorEncoding == Tileset::VectorEncoding::MLT);
}
}
if (isMLT && *isMLT) {
return std::make_unique<VectorMLTTile>(
tileID, baseImpl->id, parameters, tileset, observer_, fastPFOREnabled);
} else {
return std::make_unique<VectorMVTTile>(
tileID, baseImpl->id, parameters, tileset, observer_);
}
});
}
} // namespace mbgl

View File

@@ -10,16 +10,22 @@ class RenderVectorSource final : public RenderTileSetSource {
public:
explicit RenderVectorSource(Immutable<style::TileSource::Impl>, const TaggedScheduler&);
private:
/// Enable the decoding of MLT tiles with FastPFOR integer encodings.
/// Default is false. Such tiles will fail if not explicitly enabled.
void setFastPFOREnabled(bool enable) override { fastPFOREnabled = enable; }
protected:
void updateInternal(const Tileset&,
const std::vector<Immutable<style::LayerProperties>>&,
bool needsRendering,
bool needsRelayout,
const TileParameters&) override;
const std::optional<Tileset>& getTileset() const override;
private:
std::optional<bool> isMLT;
bool fastPFOREnabled = false;
};
} // namespace mbgl

View File

@@ -48,6 +48,8 @@ public:
const bool crossSourceCollisions;
const bool fastPFOREnabled = false;
double tileLodMinRadius = 3;
double tileLodScale = 1;
double tileLodPitchThreshold = (60.0 / 180.0) * std::numbers::pi;

View File

@@ -12,8 +12,10 @@ VectorMLTTile::VectorMLTTile(const OverscaledTileID& id_,
std::string sourceID_,
const TileParameters& parameters_,
const Tileset& tileset_,
TileObserver* observer_)
: VectorTile(id_, std::move(sourceID_), parameters_, tileset_, observer_) {}
TileObserver* observer_,
bool fastPFOREnabled_)
: VectorTile(id_, std::move(sourceID_), parameters_, tileset_, observer_),
fastPFOREnabled(fastPFOREnabled_) {}
VectorMLTTile::~VectorMLTTile() {
// this needs to be explicitly deleted in the most-derived destructor
@@ -26,7 +28,7 @@ VectorMLTTile::~VectorMLTTile() {
void VectorMLTTile::setData(const std::shared_ptr<const std::string>& data_) {
if (!obsolete) {
GeometryTile::setData(data_ ? std::make_unique<VectorMLTTileData>(data_) : nullptr);
GeometryTile::setData(data_ ? std::make_unique<VectorMLTTileData>(data_, fastPFOREnabled) : nullptr);
}
}

View File

@@ -15,11 +15,15 @@ public:
std::string sourceID,
const TileParameters&,
const Tileset&,
TileObserver* observer = nullptr);
TileObserver* observer,
bool fastPFOREnabled);
~VectorMLTTile() override;
void setData(const std::shared_ptr<const std::string>& data) override;
private:
bool fastPFOREnabled;
};
} // namespace mbgl

View File

@@ -78,7 +78,7 @@ const PropertyMap& VectorMLTTileFeature::getProperties() const {
}
FeatureIdentifier VectorMLTTileFeature::getID() const {
return feature.getID();
return feature.getID().has_value() ? mapbox::feature::identifier(*feature.getID()) : mapbox::feature::null_value;
}
namespace {
@@ -174,12 +174,14 @@ std::string VectorMLTTileLayer::getName() const {
return layer.getName();
}
VectorMLTTileData::VectorMLTTileData(std::shared_ptr<const std::string> data_)
: data(std::move(data_)) {}
VectorMLTTileData::VectorMLTTileData(std::shared_ptr<const std::string> data_, bool fastPFOREnabled_)
: data(std::move(data_)),
fastPFOREnabled(fastPFOREnabled_) {}
VectorMLTTileData::VectorMLTTileData(const VectorMLTTileData& other)
: data(other.data),
tile(other.tile) {}
tile(other.tile),
fastPFOREnabled(other.fastPFOREnabled) {}
std::unique_ptr<GeometryTileData> VectorMLTTileData::clone() const {
return std::make_unique<VectorMLTTileData>(*this);
@@ -191,7 +193,7 @@ std::unique_ptr<GeometryTileLayer> VectorMLTTileData::getLayer(const std::string
if (data && !tile) {
try {
mlt::DataView tileData{data->data(), data->size()};
tile = std::make_shared<MapLibreTile>(mlt::Decoder().decode(tileData));
tile = std::make_shared<MapLibreTile>(mlt::Decoder(fastPFOREnabled).decode(tileData));
} catch (const std::exception& ex) {
Log::Warning(Event::ParseTile, "MLT parse failed: " + std::string(ex.what()));
}

View File

@@ -68,7 +68,7 @@ private:
class VectorMLTTileData : public GeometryTileData {
public:
VectorMLTTileData(std::shared_ptr<const std::string> data);
VectorMLTTileData(std::shared_ptr<const std::string> data, bool fastPFOREnabled);
VectorMLTTileData(const VectorMLTTileData&);
VectorMLTTileData(VectorMLTTileData&&) = default;
@@ -80,6 +80,7 @@ public:
private:
mutable std::shared_ptr<const std::string> data;
mutable std::shared_ptr<const MapLibreTile> tile;
bool fastPFOREnabled;
};
} // namespace mbgl