Skip to content

Commit

Permalink
Fill: Don't query UBOs to determine shader variant (#1885)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
mwilsnd and pre-commit-ci[bot] authored Nov 22, 2023
1 parent 287f202 commit 09e16d7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 26 deletions.
72 changes: 46 additions & 26 deletions src/mbgl/renderer/layers/render_fill_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FillVariant>(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);
Expand Down Expand Up @@ -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<size_t>(type));

auto& uniforms = drawable->mutableUniformBuffers();
uniforms.createOrUpdate(interpolateUBONameId, &interpolateUBO, context);
Expand All @@ -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) {
Expand Down Expand Up @@ -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<size_t>(type));

auto& uniforms = drawable->mutableUniformBuffers();
uniforms.createOrUpdate(interpolateNameId, &interpolateUBO, context);
Expand Down Expand Up @@ -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);
Expand All @@ -728,7 +747,8 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
idFillOutlinePatternInterpolateUBOName,
getFillOutlinePatternInterpolateUBO(),
idFillOutlinePatternTilePropsUBOName,
getFillOutlinePatternTilePropsUBO());
getFillOutlinePatternTilePropsUBO(),
FillVariant::FillOutlinePattern);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/mbgl/renderer/layers/render_fill_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ using FillLayerTweakerPtr = std::shared_ptr<FillLayerTweaker>;
#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<style::FillLayer::Impl>);
~RenderFillLayer() override;
Expand Down

0 comments on commit 09e16d7

Please sign in to comment.