Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Store gfx::DrawScope objects with associated render objects. #15395

Merged
merged 3 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

- [core] Fix potential visual artifact for line-dasharray ([#16202](https://github.com/mapbox/mapbox-gl-native/pull/16202))

- Store gfx::DrawScope objects with associated render objects. ([#15395](https://github.com/mapbox/mapbox-gl-native/pull/15395))

We used some shared SegmentVectors, e.g. for drawing raster or background tiles. In longer running maps, this lead to resource accumulation. By storing the SegmentVectors and the contained gfx::DrawScope objects, we ensure that resources get released when the associated render objects vanish.

### 🏁 Performance improvements

- [core] Loading images to style optimization ([#16187](https://github.com/mapbox/mapbox-gl-native/pull/16187))
Expand Down
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,6 @@ add_library(
${PROJECT_SOURCE_DIR}/src/mbgl/util/http_timeout.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/i18n.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/i18n.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/id.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/id.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/interpolate.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/intersection_tests.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/intersection_tests.hpp
Expand Down
2 changes: 1 addition & 1 deletion metrics/binary-size/linux-clang8/metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
6470600
]
]
}
}
5 changes: 1 addition & 4 deletions src/mbgl/renderer/buckets/debug_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <mbgl/geometry/debug_font_data.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/id.hpp>

#include <cmath>
#include <string>
Expand All @@ -20,9 +19,7 @@ DebugBucket::DebugBucket(const OverscaledTileID& id,
complete(complete_),
modified(std::move(modified_)),
expires(std::move(expires_)),
debugMode(debugMode_),
drawScopeID("__debug/" + util::toHex(util::nextID())) {

debugMode(debugMode_) {
auto addText = [&] (const std::string& text, double left, double baseline, double scale) {
for (uint8_t c : text) {
if (c < 32 || c >= 127)
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/buckets/debug_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class DebugBucket : private util::noncopyable {
gfx::IndexVector<gfx::Lines> indices;

SegmentVector<DebugAttributes> segments;
SegmentVector<DebugAttributes> tileBorderSegments;
optional<gfx::VertexBuffer<DebugLayoutVertex>> vertexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
const std::string drawScopeID;
};

} // namespace mbgl
14 changes: 5 additions & 9 deletions src/mbgl/renderer/buckets/raster_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@
#include <mbgl/renderer/layers/render_raster_layer.hpp>
#include <mbgl/programs/raster_program.hpp>
#include <mbgl/gfx/upload_pass.hpp>
#include <mbgl/util/id.hpp>

namespace mbgl {

using namespace style;

RasterBucket::RasterBucket(PremultipliedImage&& image_)
: image(std::make_shared<PremultipliedImage>(std::move(image_))),
drawScopeID(util::toHex(util::nextID())) {
}
: image(std::make_shared<PremultipliedImage>(std::move(image_))) {}

RasterBucket::RasterBucket(std::shared_ptr<PremultipliedImage> image_)
: image(std::move(image_)),
drawScopeID(util::toHex(util::nextID())) {
}
RasterBucket::RasterBucket(std::shared_ptr<PremultipliedImage> image_) : image(std::move(image_)) {}

RasterBucket::~RasterBucket() = default;

Expand All @@ -27,8 +21,10 @@ void RasterBucket::upload(gfx::UploadPass& uploadPass) {
if (!texture) {
texture = uploadPass.createTexture(*image);
}
if (!segments.empty()) {
if (!vertices.empty()) {
vertexBuffer = uploadPass.createVertexBuffer(std::move(vertices));
}
if (!indices.empty()) {
indexBuffer = uploadPass.createIndexBuffer(std::move(indices));
}
uploaded = true;
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/renderer/buckets/raster_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class RasterBucket final : public Bucket {

optional<gfx::VertexBuffer<RasterLayoutVertex>> vertexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
const std::string drawScopeID;
};

} // namespace mbgl
76 changes: 37 additions & 39 deletions src/mbgl/renderer/layers/render_background_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <mbgl/renderer/image_manager.hpp>
#include <mbgl/renderer/render_static_data.hpp>
#include <mbgl/programs/programs.hpp>
#include <mbgl/programs/background_program.hpp>
#include <mbgl/util/tile_cover.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
Expand All @@ -18,7 +17,7 @@ using namespace style;

namespace {

inline const BackgroundLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) {
inline const BackgroundLayer::Impl& impl_cast(const Immutable<style::Layer::Impl>& impl) {
assert(impl->getTypeInfo() == BackgroundLayer::Impl::staticTypeInfo());
return static_cast<const style::BackgroundLayer::Impl&>(*impl);
}
Expand All @@ -27,13 +26,12 @@ inline const BackgroundLayer::Impl& impl(const Immutable<style::Layer::Impl>& im

RenderBackgroundLayer::RenderBackgroundLayer(Immutable<style::BackgroundLayer::Impl> _impl)
: RenderLayer(makeMutable<BackgroundLayerProperties>(std::move(_impl))),
unevaluated(impl(baseImpl).paint.untransitioned()) {
}
unevaluated(impl_cast(baseImpl).paint.untransitioned()) {}

RenderBackgroundLayer::~RenderBackgroundLayer() = default;

void RenderBackgroundLayer::transition(const TransitionParameters &parameters) {
unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated));
unevaluated = impl_cast(baseImpl).paint.transitioned(parameters, std::move(unevaluated));
}

void RenderBackgroundLayer::evaluate(const PropertyEvaluationParameters &parameters) {
Expand Down Expand Up @@ -69,7 +67,7 @@ void RenderBackgroundLayer::render(PaintParameters& parameters) {
const Properties<>::PossiblyEvaluated properties;
const BackgroundProgram::Binders paintAttributeData(properties, 0);

auto draw = [&](auto& program, auto&& uniformValues, const auto& textureBindings, const UnwrappedTileID& id) {
auto draw = [&](auto& program, auto&& uniformValues, const auto& textureBindings, const uint32_t id) {
const auto allUniformValues = program.computeAllUniformValues(
std::move(uniformValues),
paintAttributeData,
Expand All @@ -88,20 +86,24 @@ void RenderBackgroundLayer::render(PaintParameters& parameters) {
parameters.context,
*parameters.renderPass,
gfx::Triangles(),
parameters.depthModeForSublayer(0, parameters.pass == RenderPass::Opaque
? gfx::DepthMaskType::ReadWrite
: gfx::DepthMaskType::ReadOnly),
parameters.depthModeForSublayer(
0,
parameters.pass == RenderPass::Opaque ? gfx::DepthMaskType::ReadWrite : gfx::DepthMaskType::ReadOnly),
gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gfx::CullFaceMode::disabled(),
*parameters.staticData.quadTriangleIndexBuffer,
parameters.staticData.tileTriangleSegments,
segments,
allUniformValues,
allAttributeBindings,
textureBindings,
getID() + "/" + util::toString(id)
);
util::toString(id));
};

if (segments.empty()) {
segments = parameters.staticData.tileTriangleSegments();
}

const auto& evaluated = static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).evaluated;
const auto& crossfade = static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).crossfade;
if (!evaluated.get<BackgroundPattern>().to.empty()) {
Expand All @@ -113,24 +115,21 @@ void RenderBackgroundLayer::render(PaintParameters& parameters) {
if (!imagePosA || !imagePosB)
return;

uint32_t i = 0;
for (const auto& tileID : util::tileCover(parameters.state, parameters.state.getIntegerZoom())) {
draw(
parameters.programs.getBackgroundLayerPrograms().backgroundPattern,
BackgroundPatternProgram::layoutUniformValues(
parameters.matrixForTile(tileID),
evaluated.get<BackgroundOpacity>(),
parameters.patternAtlas.getPixelSize(),
*imagePosA,
*imagePosB,
crossfade,
tileID,
parameters.state
),
BackgroundPatternProgram::TextureBindings{
textures::image::Value{ parameters.patternAtlas.textureBinding() },
},
tileID
);
draw(parameters.programs.getBackgroundLayerPrograms().backgroundPattern,
BackgroundPatternProgram::layoutUniformValues(parameters.matrixForTile(tileID),
evaluated.get<BackgroundOpacity>(),
parameters.patternAtlas.getPixelSize(),
*imagePosA,
*imagePosB,
crossfade,
tileID,
parameters.state),
BackgroundPatternProgram::TextureBindings{
textures::image::Value{parameters.patternAtlas.textureBinding()},
},
i++);
}
} else {
auto backgroundRenderPass = (evaluated.get<BackgroundColor>().a >= 1.0f
Expand All @@ -139,17 +138,16 @@ void RenderBackgroundLayer::render(PaintParameters& parameters) {
if (parameters.pass != backgroundRenderPass) {
return;
}
uint32_t i = 0;
for (const auto& tileID : util::tileCover(parameters.state, parameters.state.getIntegerZoom())) {
draw(
parameters.programs.getBackgroundLayerPrograms().background,
BackgroundProgram::LayoutUniformValues {
uniforms::matrix::Value( parameters.matrixForTile(tileID) ),
uniforms::color::Value( evaluated.get<BackgroundColor>() ),
uniforms::opacity::Value( evaluated.get<BackgroundOpacity>() ),
},
BackgroundProgram::TextureBindings{},
tileID
);
draw(parameters.programs.getBackgroundLayerPrograms().background,
BackgroundProgram::LayoutUniformValues{
uniforms::matrix::Value(parameters.matrixForTile(tileID)),
uniforms::color::Value(evaluated.get<BackgroundColor>()),
uniforms::opacity::Value(evaluated.get<BackgroundOpacity>()),
},
BackgroundProgram::TextureBindings{},
i++);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/renderer/layers/render_background_layer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <mbgl/programs/background_program.hpp>
#include <mbgl/renderer/render_layer.hpp>
#include <mbgl/style/layers/background_layer_impl.hpp>
#include <mbgl/style/layers/background_layer_properties.hpp>
Expand All @@ -22,6 +23,7 @@ class RenderBackgroundLayer final : public RenderLayer {

// Paint properties
style::BackgroundPaintProperties::Unevaluated unevaluated;
SegmentVector<BackgroundAttributes> segments;
};

} // namespace mbgl
7 changes: 3 additions & 4 deletions src/mbgl/renderer/layers/render_circle_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using namespace style;

namespace {

inline const style::CircleLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) {
inline const style::CircleLayer::Impl& impl_cast(const Immutable<style::Layer::Impl>& impl) {
assert(impl->getTypeInfo() == CircleLayer::Impl::staticTypeInfo());
return static_cast<const style::CircleLayer::Impl&>(*impl);
}
Expand All @@ -26,11 +26,10 @@ inline const style::CircleLayer::Impl& impl(const Immutable<style::Layer::Impl>&

RenderCircleLayer::RenderCircleLayer(Immutable<style::CircleLayer::Impl> _impl)
: RenderLayer(makeMutable<CircleLayerProperties>(std::move(_impl))),
unevaluated(impl(baseImpl).paint.untransitioned()) {
}
unevaluated(impl_cast(baseImpl).paint.untransitioned()) {}

void RenderCircleLayer::transition(const TransitionParameters& parameters) {
unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated));
unevaluated = impl_cast(baseImpl).paint.transitioned(parameters, std::move(unevaluated));
}

void RenderCircleLayer::evaluate(const PropertyEvaluationParameters& parameters) {
Expand Down
7 changes: 3 additions & 4 deletions src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using namespace style;

namespace {

inline const FillExtrusionLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) {
inline const FillExtrusionLayer::Impl& impl_cast(const Immutable<style::Layer::Impl>& impl) {
assert(impl->getTypeInfo() == FillExtrusionLayer::Impl::staticTypeInfo());
return static_cast<const FillExtrusionLayer::Impl&>(*impl);
}
Expand All @@ -32,13 +32,12 @@ inline const FillExtrusionLayer::Impl& impl(const Immutable<style::Layer::Impl>&

RenderFillExtrusionLayer::RenderFillExtrusionLayer(Immutable<style::FillExtrusionLayer::Impl> _impl)
: RenderLayer(makeMutable<FillExtrusionLayerProperties>(std::move(_impl))),
unevaluated(impl(baseImpl).paint.untransitioned()) {
}
unevaluated(impl_cast(baseImpl).paint.untransitioned()) {}

RenderFillExtrusionLayer::~RenderFillExtrusionLayer() = default;

void RenderFillExtrusionLayer::transition(const TransitionParameters& parameters) {
unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated));
unevaluated = impl_cast(baseImpl).paint.transitioned(parameters, std::move(unevaluated));
}

void RenderFillExtrusionLayer::evaluate(const PropertyEvaluationParameters& parameters) {
Expand Down
7 changes: 3 additions & 4 deletions src/mbgl/renderer/layers/render_fill_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace style;

namespace {

inline const FillLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) {
inline const FillLayer::Impl& impl_cast(const Immutable<style::Layer::Impl>& impl) {
assert(impl->getTypeInfo() == FillLayer::Impl::staticTypeInfo());
return static_cast<const FillLayer::Impl&>(*impl);
}
Expand All @@ -33,13 +33,12 @@ inline const FillLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) {

RenderFillLayer::RenderFillLayer(Immutable<style::FillLayer::Impl> _impl)
: RenderLayer(makeMutable<FillLayerProperties>(std::move(_impl))),
unevaluated(impl(baseImpl).paint.untransitioned()) {
}
unevaluated(impl_cast(baseImpl).paint.untransitioned()) {}

RenderFillLayer::~RenderFillLayer() = default;

void RenderFillLayer::transition(const TransitionParameters& parameters) {
unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated));
unevaluated = impl_cast(baseImpl).paint.transitioned(parameters, std::move(unevaluated));
}

void RenderFillLayer::evaluate(const PropertyEvaluationParameters& parameters) {
Expand Down
22 changes: 12 additions & 10 deletions src/mbgl/renderer/layers/render_heatmap_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/render_static_data.hpp>
#include <mbgl/programs/programs.hpp>
#include <mbgl/programs/heatmap_program.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/style/layers/heatmap_layer.hpp>
#include <mbgl/style/layers/heatmap_layer_impl.hpp>
Expand All @@ -21,7 +20,7 @@ using namespace style;

namespace {

inline const HeatmapLayer::Impl& impl(const Immutable<Layer::Impl>& impl) {
inline const HeatmapLayer::Impl& impl_cast(const Immutable<Layer::Impl>& impl) {
assert(impl->getTypeInfo() == HeatmapLayer::Impl::staticTypeInfo());
return static_cast<const HeatmapLayer::Impl&>(*impl);
}
Expand All @@ -30,13 +29,13 @@ inline const HeatmapLayer::Impl& impl(const Immutable<Layer::Impl>& impl) {

RenderHeatmapLayer::RenderHeatmapLayer(Immutable<HeatmapLayer::Impl> _impl)
: RenderLayer(makeMutable<HeatmapLayerProperties>(std::move(_impl))),
unevaluated(impl(baseImpl).paint.untransitioned()), colorRamp({256, 1}) {
}
unevaluated(impl_cast(baseImpl).paint.untransitioned()),
colorRamp({256, 1}) {}

RenderHeatmapLayer::~RenderHeatmapLayer() = default;

void RenderHeatmapLayer::transition(const TransitionParameters& parameters) {
unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated));
unevaluated = impl_cast(baseImpl).paint.transitioned(parameters, std::move(unevaluated));
updateColorRamp();
}

Expand Down Expand Up @@ -177,6 +176,10 @@ void RenderHeatmapLayer::render(PaintParameters& parameters) {

checkRenderability(parameters, programInstance.activeBindingCount(allAttributeBindings));

if (segments.empty()) {
// Copy over the segments so that we can create our own DrawScopes.
segments = parameters.staticData.heatmapTextureSegments();
}
programInstance.draw(
parameters.context,
*parameters.renderPass,
Expand All @@ -186,15 +189,14 @@ void RenderHeatmapLayer::render(PaintParameters& parameters) {
parameters.colorModeForRenderPass(),
gfx::CullFaceMode::disabled(),
*parameters.staticData.quadTriangleIndexBuffer,
parameters.staticData.heatmapTextureSegments,
segments,
allUniformValues,
allAttributeBindings,
HeatmapTextureProgram::TextureBindings{
textures::image::Value{ renderTexture->getTexture().getResource(), gfx::TextureFilterType::Linear },
textures::color_ramp::Value{ colorRampTexture->getResource(), gfx::TextureFilterType::Linear },
textures::image::Value{renderTexture->getTexture().getResource(), gfx::TextureFilterType::Linear},
textures::color_ramp::Value{colorRampTexture->getResource(), gfx::TextureFilterType::Linear},
},
getID()
);
getID());
}
}

Expand Down
Loading