Drawable Renderer (#1570), Sync from PR 1

This commit is contained in:
mwilsnd
2023-07-25 16:35:04 -04:00
committed by Bart Louwers
parent 62deb02265
commit 780053622c
23 changed files with 48 additions and 48 deletions

View File

@@ -82,7 +82,7 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const RenderTre
layerGroup.setEnabled(true);
int32_t samplerLocation = -1;
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
layerGroup.visitDrawables([&](gfx::Drawable& drawable) {
assert(drawable.getTileID());
// We assume that drawables don't change between pattern and non-pattern.

View File

@@ -90,7 +90,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup,
evaluatedPropsUniformBuffer = context.createUniformBuffer(&evaluatedPropsUBO, sizeof(evaluatedPropsUBO));
}
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
layerGroup.visitDrawables([&](gfx::Drawable& drawable) {
auto& uniforms = drawable.mutableUniformBuffers();
uniforms.addOrReplace(CirclePaintParamsUBOName, paintParamsUniformBuffer);
uniforms.addOrReplace(CircleEvaluatedPropsUBOName, evaluatedPropsUniformBuffer);

View File

@@ -101,7 +101,7 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup,
propsBuffer->update(&paramsUBO, sizeof(paramsUBO));
}
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
layerGroup.visitDrawables([&](gfx::Drawable& drawable) {
auto& uniforms = drawable.mutableUniformBuffers();
uniforms.addOrReplace(FillExtrusionDrawablePropsUBOName, propsBuffer);

View File

@@ -69,7 +69,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup,
propsBuffer = context.createUniformBuffer(&paramsUBO, sizeof(paramsUBO));
}
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
layerGroup.visitDrawables([&](gfx::Drawable& drawable) {
auto& uniforms = drawable.mutableUniformBuffers();
uniforms.addOrReplace(FillDrawablePropsUBOName, propsBuffer);

View File

@@ -56,7 +56,7 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup,
sizeof(evaluatedPropsUBO));
}
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
layerGroup.visitDrawables([&](gfx::Drawable& drawable) {
auto& uniforms = drawable.mutableUniformBuffers();
uniforms.addOrReplace(HeatmapEvaluatedPropsUBOName, evaluatedPropsUniformBuffer);

View File

@@ -37,7 +37,7 @@ void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup,
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
#endif
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
layerGroup.visitDrawables([&](gfx::Drawable& drawable) {
const auto& size = parameters.staticData.backendSize;
mat4 viewportMat;
matrix::ortho(viewportMat, 0, size.width, size.height, 0, 0, 1);

View File

@@ -65,7 +65,7 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup,
sizeof(evaluatedPropsUBO));
}
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
layerGroup.visitDrawables([&](gfx::Drawable& drawable) {
drawable.mutableUniformBuffers().addOrReplace(HillshadeEvaluatedPropsUBOName, evaluatedPropsUniformBuffer);
if (!drawable.getTileID()) {

View File

@@ -47,7 +47,7 @@ void HillshadePrepareLayerTweaker::execute(LayerGroupBase& layerGroup,
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
#endif
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
layerGroup.visitDrawables([&](gfx::Drawable& drawable) {
if (!drawable.getTileID() || !drawable.getData()) {
return;
}

View File

@@ -170,7 +170,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup,
return lineSDFPropertiesBuffer;
};
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
layerGroup.visitDrawables([&](gfx::Drawable& drawable) {
const auto shader = drawable.getShader();
if (!drawable.getTileID() || !shader) {
return;

View File

@@ -37,7 +37,7 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup,
[[maybe_unused]] const PaintParameters& parameters) {
const auto& evaluated = static_cast<const RasterLayerProperties&>(*evaluatedProperties).evaluated;
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
layerGroup.visitDrawables([&](gfx::Drawable& drawable) {
const auto spinWeights = [](float spin) -> std::array<float, 4> {
spin = util::deg2radf(spin);
const float s = std::sin(spin);

View File

@@ -281,7 +281,7 @@ void RenderBackgroundLayer::update(gfx::ShaderRegistry& shaders,
std::unique_ptr<gfx::DrawableBuilder> builder;
tileLayerGroup->observeDrawables([&](gfx::Drawable& drawable) -> bool {
tileLayerGroup->visitDrawables([&](gfx::Drawable& drawable) -> bool {
// Has this tile dropped out of the cover set?
return (!drawable.getTileID() || hasRenderTile(*drawable.getTileID()));
});

View File

@@ -319,8 +319,8 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
return;
}
stats.drawablesRemoved += tileLayerGroup->observeDrawablesRemove(
[&](gfx::Drawable& drawable) { return (!drawable.getTileID() || hasRenderTile(*drawable.getTileID())); });
stats.drawablesRemoved += tileLayerGroup->removeDrawablesIf(
[&](gfx::Drawable& drawable) { return !(!drawable.getTileID() || hasRenderTile(*drawable.getTileID())); });
const auto& evaluated = static_cast<const CircleLayerProperties&>(*evaluatedProperties).evaluated;
@@ -363,7 +363,7 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
auto& uniforms = drawable.mutableUniformBuffers();
uniforms.createOrUpdate(CircleInterpolateUBOName, &interpolateUBO, context);
};
if (0 < tileLayerGroup->observeDrawables(renderPass, tileID, std::move(updateExisting))) {
if (0 < tileLayerGroup->visitDrawables(renderPass, tileID, std::move(updateExisting))) {
continue;
}

View File

@@ -308,9 +308,9 @@ void RenderFillExtrusionLayer::update(gfx::ShaderRegistry& shaders,
// in the "3D pass".
constexpr auto drawPass = RenderPass::Translucent;
stats.drawablesRemoved += tileLayerGroup->observeDrawablesRemove([&](gfx::Drawable& drawable) {
stats.drawablesRemoved += tileLayerGroup->removeDrawablesIf([&](gfx::Drawable& drawable) {
// If the render pass has changed or the tile has dropped out of the cover set, remove it.
return (drawable.getRenderPass() == drawPass &&
return !(drawable.getRenderPass() == drawPass &&
(!drawable.getTileID() || hasRenderTile(*drawable.getTileID())));
});
@@ -384,7 +384,7 @@ void RenderFillExtrusionLayer::update(gfx::ShaderRegistry& shaders,
// If we already have drawables for this tile, update them.
if (tileLayerGroup->getDrawableCount(drawPass, tileID) > 0) {
// Just update the drawables we already created
tileLayerGroup->observeDrawables(drawPass, tileID, [&](gfx::Drawable& drawable) {
tileLayerGroup->visitDrawables(drawPass, tileID, [&](gfx::Drawable& drawable) {
auto& uniforms = drawable.mutableUniformBuffers();
uniforms.createOrUpdate(
FillExtrusionLayerTweaker::FillExtrusionTilePropsUBOName, &tilePropsUBO, context);

View File

@@ -362,9 +362,9 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
builder.setEnableStencil(true);
};
stats.drawablesRemoved += tileLayerGroup->observeDrawablesRemove([&](gfx::Drawable& drawable) {
stats.drawablesRemoved += tileLayerGroup->removeDrawablesIf([&](gfx::Drawable& drawable) {
// If the render pass has changed or the tile has dropped out of the cover set, remove it.
return drawable.getRenderPass() == renderPass && drawable.getTileID() && hasRenderTile(*drawable.getTileID());
return !(drawable.getRenderPass() == renderPass && drawable.getTileID() && hasRenderTile(*drawable.getTileID()));
});
for (const RenderTile& tile : *renderTiles) {
@@ -432,7 +432,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
uniforms.createOrUpdate(FillLayerTweaker::FillTilePropsUBOName, &tileProps, context);
drawable.setVertexAttributes(vertexAttrs);
};
if (0 < tileLayerGroup->observeDrawables(renderPass, tileID, std::move(updateExisting))) {
if (0 < tileLayerGroup->visitDrawables(renderPass, tileID, std::move(updateExisting))) {
continue;
}

View File

@@ -338,8 +338,8 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
return;
}
stats.drawablesRemoved += tileLayerGroup->observeDrawablesRemove(
[&](gfx::Drawable& drawable) { return (!drawable.getTileID() || hasRenderTile(*drawable.getTileID())); });
stats.drawablesRemoved += tileLayerGroup->removeDrawablesIf(
[&](gfx::Drawable& drawable) { return !(!drawable.getTileID() || hasRenderTile(*drawable.getTileID())); });
const auto& evaluated = static_cast<const HeatmapLayerProperties&>(*evaluatedProperties).evaluated;
@@ -369,7 +369,7 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
/* .radius_t = */ std::get<0>(paintPropertyBinders.get<HeatmapRadius>()->interpolationFactor(zoom)),
/* .padding = */ {0}};
tileLayerGroup->observeDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
tileLayerGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
drawable.mutableUniformBuffers().createOrUpdate(HeatmapInterpolateUBOName, &interpolateUBO, context);
});

View File

@@ -324,8 +324,8 @@ void RenderHillshadeLayer::update(gfx::ShaderRegistry& shaders,
return;
}
stats.drawablesRemoved += tileLayerGroup->observeDrawablesRemove(
[&](gfx::Drawable& drawable) { return (!drawable.getTileID() || hasRenderTile(*drawable.getTileID())); });
stats.drawablesRemoved += tileLayerGroup->removeDrawablesIf(
[&](gfx::Drawable& drawable) { return !(!drawable.getTileID() || hasRenderTile(*drawable.getTileID())); });
if (!staticDataSharedVertices) {
staticDataSharedVertices = std::make_shared<HillshadeVertexVector>(RenderStaticData::rasterVertices());
@@ -454,7 +454,7 @@ void RenderHillshadeLayer::update(gfx::ShaderRegistry& shaders,
hillshadeBuilder = context.createDrawableBuilder("hillshade");
if (tileLayerGroup->getDrawableCount(renderPass, tileID) > 0) {
tileLayerGroup->observeDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
tileLayerGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
drawable.setVertexAttributes(std::move(hillshadeVertexAttrs));
drawable.setVertices({}, vertices->elements(), gfx::AttributeDataType::Short2);

View File

@@ -455,9 +455,9 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
const RenderPass renderPass = static_cast<RenderPass>(evaluatedProperties->renderPasses &
~mbgl::underlying_type(RenderPass::Opaque));
stats.drawablesRemoved += tileLayerGroup->observeDrawablesRemove([&](gfx::Drawable& drawable) {
stats.drawablesRemoved += tileLayerGroup->removeDrawablesIf([&](gfx::Drawable& drawable) {
// If the render pass has changed or the tile has dropped out of the cover set, remove it.
return (drawable.getRenderPass() == renderPass &&
return !(drawable.getRenderPass() == renderPass &&
(!drawable.getTileID() || hasRenderTile(*drawable.getTileID())));
});
@@ -573,7 +573,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
/*pattern_to =*/patternPosB ? util::cast<float>(patternPosB->tlbr()) : std::array<float, 4>{0}};
// update existing drawables
tileLayerGroup->observeDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
tileLayerGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
// simple line interpolation UBO
if (drawable.getShader()->getUniformBlocks().get(std::string(LineInterpolationUBOName))) {
drawable.mutableUniformBuffers().createOrUpdate(

View File

@@ -425,7 +425,7 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
gfx::AttributeDataType::Short4);
}
tileLayerGroup->observeDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
tileLayerGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
drawable.setVertexAttributes(std::move(vertexAttrs));
drawable.setVertices({}, vertices->elements(), gfx::AttributeDataType::Short2);
@@ -504,9 +504,9 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
}
} else if (renderTiles) {
if (layerGroup) {
stats.drawablesRemoved += layerGroup->observeDrawablesRemove([&](gfx::Drawable& drawable) {
stats.drawablesRemoved += layerGroup->removeDrawablesIf([&](gfx::Drawable& drawable) {
// Has this tile dropped out of the cover set?
return (!drawable.getTileID() || hasRenderTile(*drawable.getTileID()));
return !(!drawable.getTileID() || hasRenderTile(*drawable.getTileID()));
});
} else {
// Set up a tile layer group

View File

@@ -873,13 +873,13 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders,
}
auto* tileLayerGroup = static_cast<TileLayerGroup*>(layerGroup.get());
stats.drawablesRemoved += tileLayerGroup->observeDrawablesRemove([&](gfx::Drawable& drawable) {
stats.drawablesRemoved += tileLayerGroup->removeDrawablesIf([&](gfx::Drawable& drawable) {
// If the render pass has changed or the tile has dropped out of the cover set, remove it.
const auto& tileID = drawable.getTileID();
if (drawable.getRenderPass() != passes || (tileID && !hasRenderTile(*tileID))) {
return false;
return true;
}
return true;
return false;
});
const bool sortFeaturesByKey = !impl_cast(baseImpl).layout.get<SymbolSortKey>().isUndefined();
@@ -914,7 +914,7 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders,
// If we already have drawables for this tile, update them.
if (tileLayerGroup->getDrawableCount(passes, tileID) > 0) {
// Just update the drawables we already created
tileLayerGroup->observeDrawables(passes, tileID, [&](gfx::Drawable& drawable) {
tileLayerGroup->visitDrawables(passes, tileID, [&](gfx::Drawable& drawable) {
const auto& evaluated = getEvaluated<SymbolLayerProperties>(renderData.layerProperties);
updateTileDrawable(drawable, context, bucket, bucketPaintProperties, evaluated, state);
});

View File

@@ -111,7 +111,7 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup,
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
#endif
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
layerGroup.visitDrawables([&](gfx::Drawable& drawable) {
if (!drawable.getTileID() || !drawable.getData()) {
return;
}

View File

@@ -844,7 +844,7 @@ const LayerGroupBasePtr& RenderOrchestrator::getLayerGroup(const int32_t layerIn
return (hit == layerGroupsByLayerIndex.end()) ? no_group : hit->second;
}
void RenderOrchestrator::observeLayerGroups(std::function<void(LayerGroupBase&)> f) {
void RenderOrchestrator::visitLayerGroups(std::function<void(LayerGroupBase&)> f) {
for (auto& pair : layerGroupsByLayerIndex) {
if (pair.second) {
f(*pair.second);
@@ -852,7 +852,7 @@ void RenderOrchestrator::observeLayerGroups(std::function<void(LayerGroupBase&)>
}
}
void RenderOrchestrator::observeLayerGroups(std::function<void(const LayerGroupBase&)> f) const {
void RenderOrchestrator::visitLayerGroups(std::function<void(const LayerGroupBase&)> f) const {
for (const auto& pair : layerGroupsByLayerIndex) {
if (pair.second) {
f(*pair.second);

View File

@@ -104,8 +104,8 @@ public:
bool removeLayerGroup(const int32_t layerIndex);
size_t numLayerGroups() const noexcept;
const LayerGroupBasePtr& getLayerGroup(const int32_t layerIndex) const;
void observeLayerGroups(std::function<void(LayerGroupBase&)>);
void observeLayerGroups(std::function<void(const LayerGroupBase&)>) const;
void visitLayerGroups(std::function<void(LayerGroupBase&)>);
void visitLayerGroups(std::function<void(const LayerGroupBase&)>) const;
void updateLayers(gfx::ShaderRegistry&,
gfx::Context&,

View File

@@ -144,14 +144,14 @@ void Renderer::Impl::render(const RenderTree& renderTree,
orchestrator.processChanges();
// Run layer tweakers to update any dynamic elements
orchestrator.observeLayerGroups([&](LayerGroupBase& layerGroup) {
orchestrator.visitLayerGroups([&](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);
// orchestrator.visitLayerGroups([&](LayerGroup& layerGroup) { layerGroup.preRender(orchestrator, parameters);
// });
// Upload layer groups
@@ -159,7 +159,7 @@ void Renderer::Impl::render(const RenderTree& renderTree,
const auto uploadPass = parameters.encoder->createUploadPass("layerGroup-upload");
// Give the layers a chance to upload
orchestrator.observeLayerGroups([&](LayerGroupBase& layerGroup) { layerGroup.upload(*uploadPass); });
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) { layerGroup.upload(*uploadPass); });
// Give the render targets a chance to upload
orchestrator.observeRenderTargets([&](RenderTarget& renderTarget) { renderTarget.upload(*uploadPass); });
@@ -194,7 +194,7 @@ void Renderer::Impl::render(const RenderTree& renderTree,
parameters.currentLayer = 0;
// draw layer groups, opaque pass
orchestrator.observeLayerGroups([&](LayerGroupBase& layerGroup) {
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) {
layerGroup.render(orchestrator, parameters);
parameters.currentLayer++;
});
@@ -252,7 +252,7 @@ void Renderer::Impl::render(const RenderTree& renderTree,
PaintParameters::depthEpsilon;
// draw layer groups, opaque pass
orchestrator.observeLayerGroups([&](LayerGroupBase& layerGroup) {
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) {
layerGroup.render(orchestrator, parameters);
parameters.currentLayer++;
});
@@ -266,7 +266,7 @@ void Renderer::Impl::render(const RenderTree& renderTree,
PaintParameters::depthEpsilon;
// draw layer groups, translucent pass
orchestrator.observeLayerGroups([&](LayerGroupBase& layerGroup) {
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) {
layerGroup.render(orchestrator, parameters);
if (parameters.currentLayer != 0) {
parameters.currentLayer--;
@@ -443,7 +443,7 @@ void Renderer::Impl::render(const RenderTree& renderTree,
#if MLN_DRAWABLE_RENDERER
// Give the layers a chance to do cleanup
orchestrator.observeLayerGroups(
orchestrator.visitLayerGroups(
[&](LayerGroupBase& layerGroup) { layerGroup.postRender(orchestrator, parameters); });
#endif