Add Tracy instrumentation for CPU and GPU in OpenGL mode. (#2417)

This commit is contained in:
alasram
2024-06-17 10:20:14 -07:00
committed by GitHub
parent 30484d8f50
commit 4f0f3bac51
45 changed files with 1091 additions and 19 deletions

View File

@@ -19,6 +19,7 @@
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/tile/geometry_tile_worker.hpp>
#include <mbgl/tile/tile_observer.hpp>
#include <mbgl/util/instrumentation.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/thread_pool.hpp>
@@ -28,6 +29,8 @@
namespace mbgl {
LayerRenderData* GeometryTile::LayoutResult::getLayerRenderData(const style::Layer::Impl& layerImpl) {
MLN_TRACE_FUNC();
auto it = layerRenderData.find(layerImpl.id);
if (it == layerRenderData.end()) {
return nullptr;
@@ -62,6 +65,8 @@ private:
using namespace style;
std::optional<ImagePosition> GeometryTileRenderData::getPattern(const std::string& pattern) const {
MLN_TRACE_FUNC();
if (layoutResult) {
const auto& iconAtlas = layoutResult->iconAtlas;
auto it = iconAtlas.patternPositions.find(pattern);
@@ -73,6 +78,8 @@ std::optional<ImagePosition> GeometryTileRenderData::getPattern(const std::strin
}
void GeometryTileRenderData::upload(gfx::UploadPass& uploadPass) {
MLN_TRACE_FUNC();
if (!layoutResult) return;
auto uploadFn = [&](Bucket& bucket) {
@@ -127,6 +134,8 @@ void GeometryTileRenderData::upload(gfx::UploadPass& uploadPass) {
}
void GeometryTileRenderData::prepare(const SourcePrepareParameters& parameters) {
MLN_TRACE_FUNC();
if (!layoutResult) return;
imagePatches = layoutResult->iconAtlas.getImagePatchesAndUpdateVersions(parameters.imageManager);
}
@@ -177,6 +186,8 @@ GeometryTile::GeometryTile(const OverscaledTileID& id_, std::string sourceID_, c
showCollisionBoxes(parameters.debugOptions & MapDebugOptions::Collision) {}
GeometryTile::~GeometryTile() {
MLN_TRACE_FUNC();
markObsolete();
glyphManager->removeRequestor(*this);
@@ -203,6 +214,8 @@ void GeometryTile::setError(std::exception_ptr err) {
}
void GeometryTile::setData(std::unique_ptr<const GeometryTileData> data_) {
MLN_TRACE_FUNC();
if (obsolete) {
return;
}
@@ -217,6 +230,8 @@ void GeometryTile::setData(std::unique_ptr<const GeometryTileData> data_) {
}
void GeometryTile::reset() {
MLN_TRACE_FUNC();
// Mark the tile as pending again if it was complete before to prevent
// signaling a complete state despite pending parse operations.
pending = true;
@@ -226,10 +241,14 @@ void GeometryTile::reset() {
}
std::unique_ptr<TileRenderData> GeometryTile::createRenderData() {
MLN_TRACE_FUNC();
return std::make_unique<GeometryTileRenderData>(layoutResult, atlasTextures);
}
void GeometryTile::setLayers(const std::vector<Immutable<LayerProperties>>& layers) {
MLN_TRACE_FUNC();
// Mark the tile as pending again if it was complete before to prevent
// signaling a complete state despite pending parse operations.
pending = true;
@@ -256,6 +275,8 @@ void GeometryTile::setLayers(const std::vector<Immutable<LayerProperties>>& laye
}
void GeometryTile::setShowCollisionBoxes(const bool showCollisionBoxes_) {
MLN_TRACE_FUNC();
if (showCollisionBoxes != showCollisionBoxes_) {
showCollisionBoxes = showCollisionBoxes_;
++correlationID;
@@ -264,6 +285,8 @@ void GeometryTile::setShowCollisionBoxes(const bool showCollisionBoxes_) {
}
void GeometryTile::onLayout(std::shared_ptr<LayoutResult> result, const uint64_t resultCorrelationID) {
MLN_TRACE_FUNC();
loaded = true;
renderable = true;
if (resultCorrelationID == correlationID) {
@@ -287,10 +310,14 @@ void GeometryTile::onError(std::exception_ptr err, const uint64_t resultCorrelat
}
void GeometryTile::onGlyphsAvailable(GlyphMap glyphs) {
MLN_TRACE_FUNC();
worker.self().invoke(&GeometryTileWorker::onGlyphsAvailable, std::move(glyphs));
}
void GeometryTile::getGlyphs(GlyphDependencies glyphDependencies) {
MLN_TRACE_FUNC();
if (fileSource) {
glyphManager->getGlyphs(*this, std::move(glyphDependencies), *fileSource);
}
@@ -300,6 +327,8 @@ void GeometryTile::onImagesAvailable(ImageMap images,
ImageMap patterns,
ImageVersionMap versionMap,
uint64_t imageCorrelationID) {
MLN_TRACE_FUNC();
worker.self().invoke(&GeometryTileWorker::onImagesAvailable,
std::move(images),
std::move(patterns),
@@ -308,6 +337,8 @@ void GeometryTile::onImagesAvailable(ImageMap images,
}
void GeometryTile::getImages(ImageRequestPair pair) {
MLN_TRACE_FUNC();
imageManager->getImages(*this, std::move(pair));
}
@@ -316,6 +347,8 @@ std::shared_ptr<FeatureIndex> GeometryTile::getFeatureIndex() const {
}
bool GeometryTile::layerPropertiesUpdated(const Immutable<style::LayerProperties>& layerProperties) {
MLN_TRACE_FUNC();
LayerRenderData* renderData = getLayerRenderData(*layerProperties->baseImpl);
if (!renderData) {
return false;
@@ -337,10 +370,14 @@ const GeometryTileData* GeometryTile::getData() const {
}
LayerRenderData* GeometryTile::getLayerRenderData(const style::Layer::Impl& layerImpl) {
MLN_TRACE_FUNC();
return layoutResult ? layoutResult->getLayerRenderData(layerImpl) : nullptr;
}
float GeometryTile::getQueryPadding(const std::unordered_map<std::string, const RenderLayer*>& layers) {
MLN_TRACE_FUNC();
float queryPadding = 0;
for (const auto& pair : layers) {
const LayerRenderData* data = getLayerRenderData(*pair.second->baseImpl);
@@ -358,6 +395,8 @@ void GeometryTile::queryRenderedFeatures(std::unordered_map<std::string, std::ve
const RenderedQueryOptions& options,
const mat4& projMatrix,
const SourceFeatureState& featureState) {
MLN_TRACE_FUNC();
if (!getData()) return;
const float queryPadding = getQueryPadding(layers);
@@ -380,6 +419,8 @@ void GeometryTile::queryRenderedFeatures(std::unordered_map<std::string, std::ve
}
void GeometryTile::querySourceFeatures(std::vector<Feature>& result, const SourceQueryOptions& options) {
MLN_TRACE_FUNC();
// Data not yet available, or tile is empty
if (!getData()) {
return;
@@ -435,6 +476,8 @@ void GeometryTile::performedFadePlacement() {
}
void GeometryTile::setFeatureState(const LayerFeatureStates& states) {
MLN_TRACE_FUNC();
auto layers = getData();
if ((layers == nullptr) || states.empty() || !layoutResult) {
return;