Render tests fix for Symbol (#1370)

This commit is contained in:
Stefan Karschti
2023-07-14 00:57:05 +03:00
committed by Bart Louwers
parent 0d0ad6a8f5
commit b63074407f
12 changed files with 91 additions and 55 deletions

View File

@@ -26,9 +26,13 @@ public:
isText(isText_) {}
~DrawableAtlasesTweaker() override = default;
void init(Drawable&) override;
void execute(Drawable&, const PaintParameters&) override;
protected:
void setupTextures(Drawable&);
TileAtlasTexturesPtr atlases;
std::string iconName;
std::string glyphName;

View File

@@ -21,6 +21,8 @@ public:
: host(host_) {}
~DrawableCustomLayerHostTweaker() override = default;
void init(Drawable&) override{};
void execute(Drawable&, const PaintParameters&) override;
protected:

View File

@@ -20,6 +20,9 @@ protected:
public:
virtual ~DrawableTweaker() = default;
/// Called as the drawable gets added to the layer
virtual void init(Drawable&) = 0;
/// Called just before rendering
virtual void execute(Drawable&, const PaintParameters&) = 0;
};

View File

@@ -290,8 +290,8 @@ public:
if (auto& binder = binders.template get<DataDrivenPaintProperty>()) {
using Attribute = typename DataDrivenPaintProperty::Attribute;
using Type = typename Attribute::Type; // ::mbgl::gfx::AttributeType<type_, n_>
using Value = typename Type::Value; // std::array<T, N>
using InterpType = ZoomInterpolatedAttributeType<Type>;
using Value = typename Type::Value; // std::array<T, N>
using InterpValue = typename InterpType::Value; // std::array<T, 2*N>
const auto vertexCount = binder->getVertexCount();

View File

@@ -57,6 +57,9 @@ public:
virtual std::size_t clearDrawables() = 0;
/// Add a drawable
void addDrawable(gfx::UniqueDrawable&);
/// Called before starting each frame
virtual void preRender(RenderOrchestrator&, PaintParameters&) {}
/// Called during the upload pass

View File

@@ -7,7 +7,7 @@
namespace mbgl {
namespace gfx {
void DrawableAtlasesTweaker::execute(gfx::Drawable& drawable, const PaintParameters&) {
void DrawableAtlasesTweaker::setupTextures(gfx::Drawable& drawable) {
if (const auto& shader = drawable.getShader()) {
if (const auto samplerLocation = shader->getSamplerLocation(glyphName)) {
if (const auto iconSamplerLocation = shader->getSamplerLocation(iconName)) {
@@ -21,5 +21,13 @@ void DrawableAtlasesTweaker::execute(gfx::Drawable& drawable, const PaintParamet
}
}
void DrawableAtlasesTweaker::init(gfx::Drawable& drawable) {
setupTextures(drawable);
}
void DrawableAtlasesTweaker::execute(gfx::Drawable& drawable, const PaintParameters&) {
setupTextures(drawable);
}
} // namespace gfx
} // namespace mbgl

View File

@@ -1,6 +1,7 @@
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/gfx/upload_pass.hpp>
#include <mbgl/gfx/drawable_tweaker.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/render_orchestrator.hpp>
@@ -8,6 +9,13 @@
namespace mbgl {
void LayerGroupBase::addDrawable(gfx::UniqueDrawable& drawable) {
// init their tweakers
for (const auto& tweaker : drawable->getTweakers()) {
tweaker->init(*drawable);
}
}
struct LayerGroup::Impl {
using DrawableCollection = std::set<gfx::UniqueDrawable, gfx::DrawableLessByPriority>;
DrawableCollection drawables;
@@ -24,6 +32,7 @@ std::size_t LayerGroup::getDrawableCount() const {
}
void LayerGroup::addDrawable(gfx::UniqueDrawable&& drawable) {
LayerGroupBase::addDrawable(drawable);
impl->drawables.emplace(std::move(drawable));
}

View File

@@ -748,8 +748,7 @@ constexpr auto fadeOpacityAttribName = "a_fade_opacity";
constexpr auto texUniformName = "u_texture";
constexpr auto iconTexUniformName = "u_texture_icon";
std::vector<std::string> updateTileAttributes(gfx::Context& context,
const SymbolBucket::Buffer& buffer,
std::vector<std::string> updateTileAttributes(const SymbolBucket::Buffer& buffer,
const bool isText,
const SymbolBucket::PaintProperties& paintProps,
const SymbolPaintProperties::PossiblyEvaluated& evaluated,
@@ -836,7 +835,7 @@ void updateTileDrawable(gfx::Drawable& drawable,
// See `Placement::updateBucketDynamicVertices`
gfx::VertexAttributeArray attribs;
updateTileAttributes(context, buffer, isText, paintProps, evaluated, attribs);
updateTileAttributes(buffer, isText, paintProps, evaluated, attribs);
drawable.setVertexAttributes(std::move(attribs));
}
@@ -933,9 +932,20 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders,
}
};
addRenderables(bucket.icon, SymbolType::IconRGBA);
addRenderables(bucket.sdfIcon, SymbolType::IconSDF);
addRenderables(bucket.text, SymbolType::Text);
const auto& atlases = tile.getAtlasTextures();
if (!atlases) {
continue;
}
if (bucket.hasIconData() && atlases->icon) {
addRenderables(bucket.icon, SymbolType::IconRGBA);
}
if (bucket.hasSdfIconData() && atlases->icon) {
addRenderables(bucket.sdfIcon, SymbolType::IconSDF);
}
if (bucket.hasTextData() && atlases->glyph) {
addRenderables(bucket.text, SymbolType::Text);
}
}
// We'll be processing renderables across tiles, potentially out-of-order, so keep
@@ -973,8 +983,7 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders,
const auto vertexCount = buffer.vertices().elements();
gfx::VertexAttributeArray attribs;
const auto uniformProps = updateTileAttributes(
context, buffer, isText, bucketPaintProperties, evaluated, attribs);
const auto uniformProps = updateTileAttributes(buffer, isText, bucketPaintProperties, evaluated, attribs);
const auto textHalo = evaluated.get<style::TextHaloColor>().constantOr(Color::black()).a > 0.0f &&
evaluated.get<style::TextHaloWidth>().constantOr(1);
@@ -1014,17 +1023,13 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders,
builder->setRenderPass(passes);
builder->setCullFaceMode(gfx::CullFaceMode::disabled());
builder->setDepthType(gfx::DepthMaskType::ReadOnly);
builder->setColorMode(passes == RenderPass::Translucent ? gfx::ColorMode::alphaBlended()
: gfx::ColorMode::unblended());
builder->setColorMode(
((mbgl::underlying_type(passes) & mbgl::underlying_type(RenderPass::Translucent)) != 0)
? gfx::ColorMode::alphaBlended()
: gfx::ColorMode::unblended());
builder->setVertexAttrName(posOffsetAttribName);
}
builder->clearTweakers();
builder->addTweaker(isText ? tileInfo.textTweaker : tileInfo.iconTweaker);
builder->setRawVertices({}, vertexCount, gfx::AttributeDataType::Short4);
builder->setDrawableName(layerPrefix + std::string(suffix));
builder->setVertexAttributes(attribs);
const auto shader = std::static_pointer_cast<gfx::ShaderProgramBase>(
shaderGroup->getOrCreateShader(context, uniformProps, posOffsetAttribName));
if (!shader) {
@@ -1032,6 +1037,12 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders,
}
builder->setShader(shader);
builder->clearTweakers();
builder->addTweaker(isText ? tileInfo.textTweaker : tileInfo.iconTweaker);
builder->setRawVertices({}, vertexCount, gfx::AttributeDataType::Short4);
builder->setDrawableName(layerPrefix + std::string(suffix));
builder->setVertexAttributes(attribs);
// TODO: texture filtering
// const bool linear = parameters.state.isChanging() || transformed ||
// !partiallyEvaluatedTextSize.isZoomConstant; const auto filterType = linear ?

View File

@@ -32,8 +32,7 @@ void Renderer::render(const std::shared_ptr<UpdateParameters>& updateParameters)
assert(updateParameters);
if (auto renderTree = impl->orchestrator.createRenderTree(updateParameters)) {
renderTree->prepare();
impl->preRender(*renderTree, updateParameters);
impl->render(*renderTree);
impl->render(*renderTree, updateParameters);
}
}

View File

@@ -66,9 +66,9 @@ void Renderer::Impl::setObserver(RendererObserver* observer_) {
observer = observer_ ? observer_ : &nullObserver();
}
void Renderer::Impl::preRender([[maybe_unused]] const RenderTree& renderTree,
[[maybe_unused]] const std::shared_ptr<UpdateParameters>& updateParameters) {
[[maybe_unused]] auto& context = backend.getContext();
void Renderer::Impl::render(const RenderTree& renderTree,
[[maybe_unused]] const std::shared_ptr<UpdateParameters>& updateParameters) {
auto& context = backend.getContext();
// Blocks execution until the renderable is available.
backend.getDefaultRenderable().wait();
@@ -92,23 +92,11 @@ void Renderer::Impl::preRender([[maybe_unused]] const RenderTree& renderTree,
const auto& renderTreeParameters = renderTree.getParameters();
staticData->has3D = renderTreeParameters.has3D;
#if MLN_DRAWABLE_RENDERER
// update layers
if (staticData && staticData->shaders) {
orchestrator.updateLayers(
*staticData->shaders, context, renderTreeParameters.transformParams.state, updateParameters, renderTree);
}
#endif
}
void Renderer::Impl::render(const RenderTree& renderTree) {
if (renderState == RenderState::Never) {
observer->onWillStartRenderingMap();
}
observer->onWillStartRenderingFrame();
auto& context = backend.getContext();
const auto& renderTreeParameters = renderTree.getParameters();
PaintParameters parameters{context,
pixelRatio,
@@ -127,22 +115,6 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
const auto& sourceRenderItems = renderTree.getSourceRenderItems();
const auto& layerRenderItems = renderTree.getLayerRenderItems();
#if MLN_DRAWABLE_RENDERER
// Run changes
orchestrator.processChanges();
// Run layer tweakers to update any dynamic elements
orchestrator.observeLayerGroups([&](LayerGroupBase& layerGroup) {
if (const auto& tweaker = layerGroup.getLayerTweaker()) {
tweaker->execute(layerGroup, renderTree, parameters);
}
});
// Give the layers a chance to do setup
// orchestrator.observeLayerGroups([&](LayerGroup& layerGroup) { layerGroup.preRender(orchestrator, parameters);
// });
#endif
// - UPLOAD PASS -------------------------------------------------------------------------------
// Uploads all required buffers and images before we do any actual rendering.
{
@@ -158,15 +130,41 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
staticData->upload(*uploadPass);
renderTree.getLineAtlas().upload(*uploadPass);
renderTree.getPatternAtlas().upload(*uploadPass);
}
#if MLN_DRAWABLE_RENDERER
// - LAYER GROUP UPDATE ------------------------------------------------------------------------
// Updates all layer groups and process changes
if (staticData && staticData->shaders) {
orchestrator.updateLayers(
*staticData->shaders, context, renderTreeParameters.transformParams.state, updateParameters, renderTree);
}
// Run changes
orchestrator.processChanges();
// Run layer tweakers to update any dynamic elements
orchestrator.observeLayerGroups([&](LayerGroupBase& layerGroup) {
if (layerGroup.getLayerTweaker()) {
layerGroup.getLayerTweaker()->execute(layerGroup, renderTree, parameters);
}
});
// Give the layers a chance to do setup
// orchestrator.observeLayerGroups([&](LayerGroup& layerGroup) { layerGroup.preRender(orchestrator, parameters);
// });
// Upload layer groups
{
const auto uploadPass = parameters.encoder->createUploadPass("layerGroup-upload");
// Give the layers a chance to upload
orchestrator.observeLayerGroups([&](LayerGroupBase& layerGroup) { layerGroup.upload(*uploadPass); });
// Give the render targets a chance to upload
orchestrator.observeRenderTargets([&](RenderTarget& renderTarget) { renderTarget.upload(*uploadPass); });
#endif
}
#endif
// - 3D PASS
// -------------------------------------------------------------------------------------

View File

@@ -26,9 +26,7 @@ private:
void setObserver(RendererObserver*);
void preRender(const RenderTree&, const std::shared_ptr<UpdateParameters>&);
void render(const RenderTree&);
void render(const RenderTree&, const std::shared_ptr<UpdateParameters>&);
void reduceMemoryUse();

View File

@@ -77,6 +77,7 @@ std::vector<gfx::UniqueDrawable> TileLayerGroup::removeDrawables(mbgl::RenderPas
void TileLayerGroup::addDrawable(mbgl::RenderPass pass, const OverscaledTileID& id, gfx::UniqueDrawable&& drawable) {
assert(impl->drawablesByTile.size() == impl->sortedDrawables.size());
if (drawable) {
LayerGroupBase::addDrawable(drawable);
[[maybe_unused]] const auto result = impl->sortedDrawables.insert(drawable.get());
assert(result.second);
impl->drawablesByTile.insert(std::make_pair(TileLayerGroupTileKey{pass, id}, std::move(drawable)));