Issue/1687 (#1697)

Co-authored-by: Bart Louwers <bart@emeel.net>
Co-authored-by: mwilsnd <mwilsnd@gmail.com>
This commit is contained in:
Tim Sylvester
2023-09-28 11:18:42 -07:00
committed by GitHub
parent 2d8cde8abf
commit 810be67fa2
94 changed files with 1467 additions and 1043 deletions

View File

@@ -70,8 +70,17 @@ void RenderHeatmapLayer::evaluate(const PropertyEvaluationParameters& parameters
evaluatedProperties = std::move(properties);
#if MLN_DRAWABLE_RENDERER
updateLayerTweaker();
updateLayerTextureTweaker();
if (layerGroup) {
auto newTextureTweaker = std::make_shared<HeatmapTextureLayerTweaker>(getID(), evaluatedProperties);
replaceTweaker(textureTweaker, std::move(newTextureTweaker), {layerGroup});
}
if (renderTarget) {
if (auto tileLayerGroup = renderTarget->getLayerGroup(0)) {
auto newTweaker = std::make_shared<HeatmapLayerTweaker>(getID(), evaluatedProperties);
replaceTweaker(layerTweaker, std::move(newTweaker), {std::move(tileLayerGroup)});
}
}
#endif
}
@@ -247,17 +256,24 @@ void RenderHeatmapLayer::markLayerRenderable(bool willRender, UniqueChangeReques
activateRenderTarget(renderTarget, willRender, changes);
}
void RenderHeatmapLayer::removeTile(RenderPass renderPass, const OverscaledTileID& tileID) {
auto* tileLayerGroup = static_cast<TileLayerGroup*>(renderTarget->getLayerGroup(0).get());
stats.drawablesRemoved += tileLayerGroup->removeDrawables(renderPass, tileID).size();
std::size_t RenderHeatmapLayer::removeTile(RenderPass renderPass, const OverscaledTileID& tileID) {
if (auto* tileLayerGroup = static_cast<TileLayerGroup*>(renderTarget->getLayerGroup(0).get())) {
const auto count = tileLayerGroup->removeDrawables(renderPass, tileID).size();
stats.drawablesRemoved += count;
return count;
}
return 0;
}
void RenderHeatmapLayer::removeAllDrawables() {
RenderLayer::removeAllDrawables();
std::size_t RenderHeatmapLayer::removeAllDrawables() {
auto removed = RenderLayer::removeAllDrawables();
if (renderTarget) {
stats.drawablesRemoved += renderTarget->getLayerGroup(0)->getDrawableCount();
const auto count = renderTarget->getLayerGroup(0)->getDrawableCount();
removed += count;
stats.drawablesRemoved += count;
renderTarget->getLayerGroup(0)->clearDrawables();
}
return removed;
}
namespace {
@@ -273,27 +289,6 @@ static const StringIdentity idTexColorRampName = StringIndexer::get("u_color_ram
using namespace shaders;
#if MLN_DRAWABLE_RENDERER
void RenderHeatmapLayer::updateLayerTweaker() {
if (renderTarget) {
tweaker = std::make_shared<HeatmapLayerTweaker>(getID(), evaluatedProperties);
#if MLN_RENDER_BACKEND_METAL
tweaker->setPropertiesAsUniforms(propertiesAsUniforms);
#endif // MLN_RENDER_BACKEND_METAL
tweaker->enableOverdrawInspector(overdrawInspector);
renderTarget->getLayerGroup(0)->setLayerTweaker(tweaker);
}
}
void RenderHeatmapLayer::updateLayerTextureTweaker() {
if (layerGroup) {
textureTweaker = std::make_shared<HeatmapTextureLayerTweaker>(getID(), evaluatedProperties);
textureTweaker->enableOverdrawInspector(overdrawInspector);
layerGroup->setLayerTweaker(textureTweaker);
}
}
#endif // MLN_DRAWABLE_RENDERER
void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
gfx::Context& context,
const TransformState& state,
@@ -324,7 +319,7 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
return;
}
renderTarget->addLayerGroup(tileLayerGroup, /*replace=*/true);
updateLayerTweaker();
textureTweaker.reset();
}
if (renderTarget->getTexture()->getSize() != size) {
@@ -341,14 +336,11 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
return;
}
const bool overdraw = !!(updateParameters->debugOptions & MapDebugOptions::Overdraw);
if (overdrawInspector != overdraw) {
overdrawInspector = overdraw;
if (tweaker) {
tweaker->enableOverdrawInspector(overdrawInspector);
textureTweaker->enableOverdrawInspector(overdrawInspector);
}
if (!layerTweaker) {
layerTweaker = std::make_shared<HeatmapLayerTweaker>(getID(), evaluatedProperties);
tileLayerGroup->addLayerTweaker(layerTweaker);
}
layerTweaker->enableOverdrawInspector(!!(updateParameters->debugOptions & MapDebugOptions::Overdraw));
std::unique_ptr<gfx::DrawableBuilder> heatmapBuilder;
constexpr auto renderPass = RenderPass::Translucent;
@@ -361,6 +353,7 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
[&](gfx::Drawable& drawable) { return drawable.getTileID() && !hasRenderTile(*drawable.getTileID()); });
const auto& evaluated = static_cast<const HeatmapLayerProperties&>(*evaluatedProperties).evaluated;
std::unordered_set<StringIdentity> propertiesAsUniforms;
for (const RenderTile& tile : *renderTiles) {
const auto& tileID = tile.getOverscaledTileID();
@@ -389,6 +382,10 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
/* .padding = */ {0}};
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;
}
drawable.mutableUniformBuffers().createOrUpdate(idHeatmapInterpolateUBOName, &interpolateUBO, context);
});
@@ -397,25 +394,18 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
}
gfx::VertexAttributeArray heatmapVertexAttrs;
propertiesAsUniforms.clear();
heatmapVertexAttrs.readDataDrivenPaintProperties<HeatmapWeight, HeatmapRadius>(
paintPropertyBinders, evaluated, propertiesAsUniforms);
const auto propertiesAsUniforms_ =
heatmapVertexAttrs.readDataDrivenPaintProperties<HeatmapWeight, HeatmapRadius>(paintPropertyBinders,
evaluated);
if (!heatmapShaderGroup) {
continue;
}
const auto heatmapShader = heatmapShaderGroup->getOrCreateShader(context, propertiesAsUniforms_);
const auto heatmapShader = heatmapShaderGroup->getOrCreateShader(context, propertiesAsUniforms);
if (!heatmapShader) {
continue;
}
#if MLN_RENDER_BACKEND_METAL
propertiesAsUniforms = std::move(propertiesAsUniforms_);
if (tweaker) {
tweaker->setPropertiesAsUniforms(propertiesAsUniforms);
if (layerTweaker) {
layerTweaker->setPropertiesAsUniforms(propertiesAsUniforms);
}
#endif // MLN_RENDER_BACKEND_METAL
if (const auto& attr = heatmapVertexAttrs.add(idVertexAttribName)) {
attr->setSharedRawData(bucket.sharedVertices,
@@ -441,6 +431,8 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
for (auto& drawable : heatmapBuilder->clearDrawables()) {
drawable->setTileID(tileID);
drawable->setLayerTweaker(layerTweaker);
drawable->mutableUniformBuffers().createOrUpdate(idHeatmapInterpolateUBOName, &interpolateUBO, context);
tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable));
@@ -450,13 +442,20 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
// Set up texture layer group
if (!layerGroup) {
auto layerGroup_ = context.createLayerGroup(layerIndex, /*initialCapacity=*/1, getID());
if (!layerGroup_) {
if (auto layerGroup_ = context.createLayerGroup(layerIndex, /*initialCapacity=*/1, getID())) {
if (textureTweaker) {
layerGroup_->addLayerTweaker(textureTweaker);
}
setLayerGroup(std::move(layerGroup_), changes);
} else {
return;
}
setLayerGroup(std::move(layerGroup_), changes);
updateLayerTextureTweaker();
}
if (!textureTweaker) {
textureTweaker = std::make_shared<HeatmapTextureLayerTweaker>(getID(), evaluatedProperties);
layerGroup->addLayerTweaker(textureTweaker);
}
textureTweaker->enableOverdrawInspector(!!(updateParameters->debugOptions & MapDebugOptions::Overdraw));
if (!heatmapTextureShader) {
heatmapTextureShader = context.getGenericShader(shaders, HeatmapTextureShaderGroupName);
@@ -467,6 +466,7 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
}
auto* textureLayerGroup = static_cast<LayerGroup*>(layerGroup.get());
// TODO: Don't rebuild drawables every time
textureLayerGroup->clearDrawables();
std::unique_ptr<gfx::DrawableBuilder> heatmapTextureBuilder;
@@ -516,6 +516,7 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
heatmapTextureBuilder->flush();
for (auto& drawable : heatmapTextureBuilder->clearDrawables()) {
drawable->setLayerTweaker(textureTweaker);
textureLayerGroup->addDrawable(std::move(drawable));
++stats.drawablesAdded;
}