From 09e16d78d8c8f003ace5c9f6ecc7562fa9c5e11a Mon Sep 17 00:00:00 2001 From: mwilsnd <53413200+mwilsnd@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:03:37 -0500 Subject: [PATCH] Fill: Don't query UBOs to determine shader variant (#1885) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../renderer/layers/render_fill_layer.cpp | 72 ++++++++++++------- .../renderer/layers/render_fill_layer.hpp | 9 +++ 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index 41cfd4dc9b7..7441a7a967d 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -516,26 +516,35 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, // If we already have drawables for this tile, update them. auto updateExisting = [&](gfx::Drawable& drawable) { - if (drawable.getLayerTweaker() != layerTweaker) { - // This drawable was produced on a previous style/bucket, and should not be updated. - return false; - } - auto& uniforms = drawable.mutableUniformBuffers(); - if (uniforms.get(FillLayerTweaker::idFillInterpolateUBOName)) { - uniforms.createOrUpdate(FillLayerTweaker::idFillInterpolateUBOName, &getFillInterpolateUBO(), context); - } else if (uniforms.get(idFillOutlineInterpolateUBOName)) { - uniforms.createOrUpdate(idFillOutlineInterpolateUBOName, &getFillOutlineInterpolateUBO(), context); - } else if (uniforms.get(idFillPatternInterpolateUBOName)) { - uniforms.createOrUpdate(idFillPatternInterpolateUBOName, &getFillPatternInterpolateUBO(), context); - uniforms.createOrUpdate(idFillPatternTilePropsUBOName, &getFillPatternTilePropsUBO(), context); - } else if (uniforms.get(idFillOutlinePatternInterpolateUBOName)) { - uniforms.createOrUpdate( - idFillOutlinePatternInterpolateUBOName, &getFillOutlinePatternInterpolateUBO(), context); - uniforms.createOrUpdate( - idFillOutlinePatternTilePropsUBOName, &getFillOutlinePatternTilePropsUBO(), context); - } else { - assert(false); + switch (static_cast(drawable.getType())) { + case FillVariant::Fill: { + uniforms.createOrUpdate( + FillLayerTweaker::idFillInterpolateUBOName, &getFillInterpolateUBO(), context); + break; + } + case FillVariant::FillOutline: { + uniforms.createOrUpdate(idFillOutlineInterpolateUBOName, &getFillOutlineInterpolateUBO(), context); + break; + } + case FillVariant::FillPattern: { + uniforms.createOrUpdate(idFillPatternInterpolateUBOName, &getFillPatternInterpolateUBO(), context); + uniforms.createOrUpdate(idFillPatternTilePropsUBOName, &getFillPatternTilePropsUBO(), context); + break; + } + case FillVariant::FillOutlinePattern: { + uniforms.createOrUpdate( + idFillOutlinePatternInterpolateUBOName, &getFillOutlinePatternInterpolateUBO(), context); + uniforms.createOrUpdate( + idFillOutlinePatternTilePropsUBOName, &getFillOutlinePatternTilePropsUBO(), context); + break; + } + default: { +#ifndef NDEBUG + mbgl::Log::Error(mbgl::Event::Render, "Invalid fill variant type supplied during drawable update!"); +#endif + break; + } } drawable.setVertexAttributes(vertexAttrs); @@ -588,12 +597,14 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, const auto finish = [&](gfx::DrawableBuilder& builder, const StringIdentity interpolateUBONameId, - const auto& interpolateUBO) { + const auto& interpolateUBO, + FillVariant type) { builder.flush(); for (auto& drawable : builder.clearDrawables()) { drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); + drawable->setType(static_cast(type)); auto& uniforms = drawable->mutableUniformBuffers(); uniforms.createOrUpdate(interpolateUBONameId, &interpolateUBO, context); @@ -615,15 +626,20 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, bucket.sharedTriangles, bucket.triangleSegments.data(), bucket.triangleSegments.size()); - finish(*fillBuilder, FillLayerTweaker::idFillInterpolateUBOName, getFillInterpolateUBO()); + finish(*fillBuilder, + FillLayerTweaker::idFillInterpolateUBOName, + getFillInterpolateUBO(), + FillVariant::Fill); } if (outlineBuilder && bucket.sharedLines->elements()) { outlineBuilder->setShader(outlineShader); outlineBuilder->setRawVertices({}, vertexCount, gfx::AttributeDataType::Short2); outlineBuilder->setSegments( gfx::Lines(2), bucket.sharedLines, bucket.lineSegments.data(), bucket.lineSegments.size()); - finish( - *outlineBuilder, FillLayerTweaker::idFillOutlineInterpolateUBOName, getFillOutlineInterpolateUBO()); + finish(*outlineBuilder, + FillLayerTweaker::idFillOutlineInterpolateUBOName, + getFillOutlineInterpolateUBO(), + FillVariant::FillOutline); } } else { // FillPattern is defined if ((renderPass & RenderPass::Translucent) == 0) { @@ -681,12 +697,14 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, const StringIdentity interpolateNameId, const auto& interpolateUBO, const StringIdentity tileUBONameId, - const auto& tileUBO) { + const auto& tileUBO, + FillVariant type) { builder.flush(); for (auto& drawable : builder.clearDrawables()) { drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); + drawable->setType(static_cast(type)); auto& uniforms = drawable->mutableUniformBuffers(); uniforms.createOrUpdate(interpolateNameId, &interpolateUBO, context); @@ -715,7 +733,8 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, idFillPatternInterpolateUBOName, getFillPatternInterpolateUBO(), idFillPatternTilePropsUBOName, - getFillPatternTilePropsUBO()); + getFillPatternTilePropsUBO(), + FillVariant::FillPattern); } if (outlinePatternBuilder && bucket.sharedLines->elements()) { outlinePatternBuilder->setShader(outlineShader); @@ -728,7 +747,8 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, idFillOutlinePatternInterpolateUBOName, getFillOutlinePatternInterpolateUBO(), idFillOutlinePatternTilePropsUBOName, - getFillOutlinePatternTilePropsUBO()); + getFillOutlinePatternTilePropsUBO(), + FillVariant::FillOutlinePattern); } } } diff --git a/src/mbgl/renderer/layers/render_fill_layer.hpp b/src/mbgl/renderer/layers/render_fill_layer.hpp index a2975954e0d..064b1c0c715 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.hpp +++ b/src/mbgl/renderer/layers/render_fill_layer.hpp @@ -21,6 +21,15 @@ using FillLayerTweakerPtr = std::shared_ptr; #endif // MLN_DRAWABLE_RENDERER class RenderFillLayer final : public RenderLayer { +public: + enum class FillVariant : uint8_t { + Fill, + FillPattern, + FillOutline, + FillOutlinePattern, + Undefined = 255 + }; + public: explicit RenderFillLayer(Immutable); ~RenderFillLayer() override;