Merge branch 'topic/metal-sep21' into main (#1695)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Tim Sylvester <tim@wetdogweather.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
Co-authored-by: Alex Cristici <alex.cristici@gmail.com>
Co-authored-by: Stefan Karschti <stefan.karschti@gmail.com>
Co-authored-by: Alex Cristici <alex@skoon.energy>
Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
Co-authored-by: Wei Chen <alanchenboy@gmail.com>
Co-authored-by: Siarhei Fedartsou <siarhei.fedartsou@gmail.com>
Co-authored-by: tdcosta100 <tdcosta100@gmail.com>
This commit is contained in:
mwilsnd
2023-10-02 09:22:19 -04:00
committed by GitHub
parent 34a2097bdd
commit f4d3cb6b69
48 changed files with 754 additions and 576 deletions

View File

@@ -21,16 +21,6 @@
#include <mbgl/util/logging.hpp>
#include <mbgl/util/math.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/drawable_builder.hpp>
#include <mbgl/gfx/drawable_atlases_tweaker.hpp>
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/renderer/layers/line_layer_tweaker.hpp>
#include <mbgl/gfx/line_drawable_data.hpp>
#include <mbgl/shaders/shader_program_base.hpp>
#include <mbgl/util/string_indexer.hpp>
#endif
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/drawable_atlases_tweaker.hpp>
#include <mbgl/gfx/drawable_builder.hpp>
@@ -40,6 +30,7 @@
#include <mbgl/renderer/update_parameters.hpp>
#include <mbgl/shaders/line_layer_ubo.hpp>
#include <mbgl/shaders/shader_program_base.hpp>
#include <mbgl/util/string_indexer.hpp>
#endif
namespace mbgl {
@@ -90,7 +81,10 @@ void RenderLineLayer::evaluate(const PropertyEvaluationParameters& parameters) {
evaluatedProperties = std::move(properties);
#if MLN_DRAWABLE_RENDERER
updateLayerTweaker();
if (layerGroup) {
auto newTweaker = std::make_shared<LineLayerTweaker>(getID(), evaluatedProperties);
replaceTweaker(layerTweaker, std::move(newTweaker), {layerGroup});
}
#endif
}
@@ -364,16 +358,6 @@ static const StringIdentity idLineSDFInterpolationUBOName = StringIndexer::get("
/// Evaluated properties that depend on the tile
static const StringIdentity idLinePatternTilePropertiesUBOName = StringIndexer::get("LinePatternTilePropertiesUBO");
void RenderLineLayer::updateLayerTweaker() {
if (layerGroup) {
tweaker = std::make_shared<LineLayerTweaker>(getID(), evaluatedProperties);
#if MLN_RENDER_BACKEND_METAL
tweaker->setPropertiesAsUniforms(propertiesAsUniforms);
#endif // MLN_RENDER_BACKEND_METAL
tweaker->enableOverdrawInspector(overdrawInspector);
layerGroup->setLayerTweaker(tweaker);
}
}
static const StringIdentity idLineImageUniformName = StringIndexer::get("u_image");
@@ -390,23 +374,22 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
return;
}
const bool overdraw = !!(updateParameters->debugOptions & MapDebugOptions::Overdraw);
if (overdrawInspector != overdraw) {
overdrawInspector = overdraw;
if (tweaker) {
tweaker->enableOverdrawInspector(overdrawInspector);
}
}
// Set up a layer group
if (!layerGroup) {
if (auto layerGroup_ = context.createTileLayerGroup(layerIndex, /*initialCapacity=*/64, getID())) {
setLayerGroup(std::move(layerGroup_), changes);
updateLayerTweaker();
} else {
return;
}
}
auto* tileLayerGroup = static_cast<TileLayerGroup*>(layerGroup.get());
if (!layerTweaker) {
layerTweaker = std::make_shared<LineLayerTweaker>(getID(), evaluatedProperties);
layerGroup->addLayerTweaker(layerTweaker);
}
layerTweaker->enableOverdrawInspector(!!(updateParameters->debugOptions & MapDebugOptions::Overdraw));
if (!lineShaderGroup) {
lineShaderGroup = shaders.getShaderGroup("LineShader");
}
@@ -486,6 +469,11 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
}
auto& bucket = static_cast<LineBucket&>(*renderData->bucket);
if (!bucket.sharedTriangles->elements()) {
removeTile(renderPass, tileID);
continue;
}
const auto& paintPropertyBinders = bucket.paintPropertyBinders.at(getID());
const auto& evaluated = getEvaluated<LineLayerProperties>(renderData->layerProperties);
const auto& crossfade = getCrossfade<LineLayerProperties>(renderData->layerProperties);
@@ -546,6 +534,11 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
// update existing drawables
tileLayerGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
if (drawable.getLayerTweaker() != layerTweaker) {
// This drawable was produced on a previous style/bucket, and should not be updated.
return;
}
const auto& shader = drawable.getShader();
const auto& shaderUniforms = shader->getUniformBlocks();
auto& drawableUniforms = drawable.mutableUniformBuffers();
@@ -581,29 +574,26 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
if (!evaluated.get<LineDasharray>().from.empty()) {
// dash array line (SDF)
gfx::VertexAttributeArray vertexAttrs;
auto propertiesAsUniforms_ = vertexAttrs.readDataDrivenPaintProperties<LineColor,
LineBlur,
LineOpacity,
LineGapWidth,
LineOffset,
LineWidth,
LineFloorWidth>(paintPropertyBinders,
evaluated);
auto propertiesAsUniforms = vertexAttrs.readDataDrivenPaintProperties<LineColor,
LineBlur,
LineOpacity,
LineGapWidth,
LineOffset,
LineWidth,
LineFloorWidth>(paintPropertyBinders,
evaluated);
if (!lineSDFShaderGroup) {
continue;
}
auto shader = lineSDFShaderGroup->getOrCreateShader(context, propertiesAsUniforms_);
auto shader = lineSDFShaderGroup->getOrCreateShader(context, propertiesAsUniforms);
if (!shader) {
continue;
}
#if MLN_RENDER_BACKEND_METAL
propertiesAsUniforms = std::move(propertiesAsUniforms_);
if (tweaker) {
tweaker->setPropertiesAsUniforms(propertiesAsUniforms);
if (layerTweaker) {
layerTweaker->setPropertiesAsUniforms(std::move(propertiesAsUniforms));
}
#endif // MLN_RENDER_BACKEND_METAL
auto builder = createLineBuilder("lineSDF", std::move(shader));
@@ -618,6 +608,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
for (auto& drawable : builder->clearDrawables()) {
drawable->setType(mbgl::underlying_type(LineLayerTweaker::LineType::SDF));
drawable->setTileID(tileID);
drawable->setLayerTweaker(layerTweaker);
drawable->setData(std::make_unique<gfx::LineDrawableData>(cap));
drawable->mutableUniformBuffers().createOrUpdate(
idLineSDFInterpolationUBOName, &lineSDFInterpolationUBO, context);
@@ -629,28 +620,25 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
// pattern line
gfx::VertexAttributeArray vertexAttrs;
paintPropertyBinders.setPatternParameters(patternPosA, patternPosB, crossfade);
auto propertiesAsUniforms_ = vertexAttrs.readDataDrivenPaintProperties<LineBlur,
LineOpacity,
LineOffset,
LineGapWidth,
LineWidth,
LinePattern>(paintPropertyBinders,
evaluated);
auto propertiesAsUniforms = vertexAttrs.readDataDrivenPaintProperties<LineBlur,
LineOpacity,
LineOffset,
LineGapWidth,
LineWidth,
LinePattern>(paintPropertyBinders,
evaluated);
if (!linePatternShaderGroup) {
continue;
}
auto shader = linePatternShaderGroup->getOrCreateShader(context, propertiesAsUniforms_);
auto shader = linePatternShaderGroup->getOrCreateShader(context, propertiesAsUniforms);
if (!shader) {
continue;
}
#if MLN_RENDER_BACKEND_METAL
propertiesAsUniforms = std::move(propertiesAsUniforms_);
if (tweaker) {
tweaker->setPropertiesAsUniforms(propertiesAsUniforms);
if (layerTweaker) {
layerTweaker->setPropertiesAsUniforms(std::move(propertiesAsUniforms));
}
#endif // MLN_RENDER_BACKEND_METAL
auto builder = createLineBuilder("linePattern", std::move(shader));
@@ -679,6 +667,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
for (auto& drawable : builder->clearDrawables()) {
drawable->setType(mbgl::underlying_type(LineLayerTweaker::LineType::Pattern));
drawable->setTileID(tileID);
drawable->setLayerTweaker(layerTweaker);
drawable->mutableUniformBuffers().createOrUpdate(
idLinePatternInterpolationUBOName, &linePatternInterpolationUBO, context);
drawable->mutableUniformBuffers().createOrUpdate(
@@ -691,24 +680,21 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
} else if (!unevaluated.get<LineGradient>().getValue().isUndefined()) {
// gradient line
gfx::VertexAttributeArray vertexAttrs;
auto propertiesAsUniforms_ =
auto propertiesAsUniforms =
vertexAttrs.readDataDrivenPaintProperties<LineBlur, LineOpacity, LineGapWidth, LineOffset, LineWidth>(
paintPropertyBinders, evaluated);
if (!lineGradientShaderGroup) {
continue;
}
auto shader = lineGradientShaderGroup->getOrCreateShader(context, propertiesAsUniforms_);
auto shader = lineGradientShaderGroup->getOrCreateShader(context, propertiesAsUniforms);
if (!shader) {
continue;
}
#if MLN_RENDER_BACKEND_METAL
propertiesAsUniforms = std::move(propertiesAsUniforms_);
if (tweaker) {
tweaker->setPropertiesAsUniforms(propertiesAsUniforms);
if (layerTweaker) {
layerTweaker->setPropertiesAsUniforms(std::move(propertiesAsUniforms));
}
#endif // MLN_RENDER_BACKEND_METAL
auto builder = createLineBuilder("lineGradient", std::move(shader));
@@ -736,6 +722,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
for (auto& drawable : builder->clearDrawables()) {
drawable->setType(mbgl::underlying_type(LineLayerTweaker::LineType::Gradient));
drawable->setTileID(tileID);
drawable->setLayerTweaker(layerTweaker);
drawable->mutableUniformBuffers().createOrUpdate(
idLineGradientInterpolationUBOName, &lineGradientInterpolationUBO, context);
@@ -748,33 +735,30 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
} else {
// simple line
gfx::VertexAttributeArray vertexAttrs;
const auto propertiesAsUniforms_ = vertexAttrs.readDataDrivenPaintProperties<LineColor,
LineBlur,
LineOpacity,
LineGapWidth,
LineOffset,
LineWidth>(
paintPropertyBinders, evaluated);
const auto propertiesAsUniforms = vertexAttrs.readDataDrivenPaintProperties<LineColor,
LineBlur,
LineOpacity,
LineGapWidth,
LineOffset,
LineWidth>(paintPropertyBinders,
evaluated);
assert(6 == propertiesAsUniforms_.size());
assert(vertexAttrs.size() == (size_t)std::count_if(propertiesAsUniforms_.begin(),
propertiesAsUniforms_.end(),
assert(6 == propertiesAsUniforms.size());
assert(vertexAttrs.size() == (size_t)std::count_if(propertiesAsUniforms.begin(),
propertiesAsUniforms.end(),
[](const auto& s) { return s.empty(); }));
if (!lineShaderGroup) {
continue;
}
auto shader = lineShaderGroup->getOrCreateShader(context, propertiesAsUniforms_);
auto shader = lineShaderGroup->getOrCreateShader(context, propertiesAsUniforms);
if (!shader) {
continue;
}
#if MLN_RENDER_BACKEND_METAL
propertiesAsUniforms = std::move(propertiesAsUniforms_);
if (tweaker) {
tweaker->setPropertiesAsUniforms(propertiesAsUniforms);
if (layerTweaker) {
layerTweaker->setPropertiesAsUniforms(std::move(propertiesAsUniforms));
}
#endif // MLN_RENDER_BACKEND_METAL
auto builder = createLineBuilder("line", std::move(shader));
@@ -787,6 +771,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
for (auto& drawable : builder->clearDrawables()) {
drawable->setType(mbgl::underlying_type(LineLayerTweaker::LineType::Simple));
drawable->setTileID(tileID);
drawable->setLayerTweaker(layerTweaker);
drawable->mutableUniformBuffers().createOrUpdate(
idLineInterpolationUBOName, &lineInterpolationUBO, context);