Skip to content

Commit

Permalink
Fixed metal line render tests (#1868)
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
alexcristici and pre-commit-ci[bot] authored Nov 15, 2023
1 parent 15cfb35 commit 08f24a6
Showing 1 changed file with 108 additions and 24 deletions.
132 changes: 108 additions & 24 deletions src/mbgl/renderer/layers/line_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#if MLN_RENDER_BACKEND_METAL
#include <mbgl/shaders/mtl/line.hpp>
#include <mbgl/shaders/mtl/line_gradient.hpp>
#endif // MLN_RENDER_BACKEND_METAL

namespace mbgl {
Expand Down Expand Up @@ -110,30 +111,6 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
};

#if MLN_RENDER_BACKEND_METAL
if (permutationUpdated) {
const LinePermutationUBO permutationUBO = {
/* .color = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(2), /*.expression=*/{}},
/* .blur = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(3), /*.expression=*/{}},
/* .opacity = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(4), /*.expression=*/{}},
/* .gapwidth = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(5), /*.expression=*/{}},
/* .offset = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(6), /*.expression=*/{}},
/* .width = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(7), /*.expression=*/{}},
/* .floorwidth = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .pattern_from = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .pattern_to = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .overdrawInspector = */ overdrawInspector,
/* .pad = */ 0,
0,
0,
0};

if (permutationUniformBuffer) {
permutationUniformBuffer->update(&permutationUBO, sizeof(permutationUBO));
} else {
permutationUniformBuffer = context.createUniformBuffer(&permutationUBO, sizeof(permutationUBO));
}
permutationUpdated = false;
}
if (!expressionUniformBuffer) {
const auto expressionUBO = buildExpressionUBO(zoom, parameters.frameCount);
expressionUniformBuffer = context.createUniformBuffer(&expressionUBO, sizeof(expressionUBO));
Expand Down Expand Up @@ -168,6 +145,29 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters

// properties UBO
uniforms.addOrReplace(idLinePropertiesUBOName, getLinePropsBuffer());

#if MLN_RENDER_BACKEND_METAL
if (permutationUpdated) {
const LinePermutationUBO permutationUBO = {
/* .color = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(2), /*.expression=*/{}},
/* .blur = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(3), /*.expression=*/{}},
/* .opacity = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(4), /*.expression=*/{}},
/* .gapwidth = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(5), /*.expression=*/{}},
/* .offset = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(6), /*.expression=*/{}},
/* .width = */ {/*.source=*/getAttributeSource<BuiltIn::LineShader>(7), /*.expression=*/{}},
/* .floorwidth = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .pattern_from = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .pattern_to = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .overdrawInspector = */ overdrawInspector,
/* .pad = */ 0,
0,
0,
0};

context.emplaceOrUpdateUniformBuffer(permutationUniformBuffer, &permutationUBO);
permutationUpdated = false;
}
#endif
} break;

case LineType::Gradient: {
Expand All @@ -180,6 +180,34 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters

// properties UBO
uniforms.addOrReplace(idLineGradientPropertiesUBOName, getLineGradientPropsBuffer());

#if MLN_RENDER_BACKEND_METAL
if (permutationUpdated) {
const LinePermutationUBO permutationUBO = {
/* .color = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .blur = */
{/*.source=*/getAttributeSource<BuiltIn::LineGradientShader>(2), /*.expression=*/{}},
/* .opacity = */
{/*.source=*/getAttributeSource<BuiltIn::LineGradientShader>(3), /*.expression=*/{}},
/* .gapwidth = */
{/*.source=*/getAttributeSource<BuiltIn::LineGradientShader>(4), /*.expression=*/{}},
/* .offset = */
{/*.source=*/getAttributeSource<BuiltIn::LineGradientShader>(5), /*.expression=*/{}},
/* .width = */
{/*.source=*/getAttributeSource<BuiltIn::LineGradientShader>(6), /*.expression=*/{}},
/* .floorwidth = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .pattern_from = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .pattern_to = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .overdrawInspector = */ overdrawInspector,
/* .pad = */ 0,
0,
0,
0};

context.emplaceOrUpdateUniformBuffer(permutationUniformBuffer, &permutationUBO);
permutationUpdated = false;
}
#endif
} break;

case LineType::Pattern: {
Expand All @@ -205,6 +233,36 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters

// properties UBO
uniforms.addOrReplace(idLinePatternPropertiesUBOName, getLinePatternPropsBuffer());

#if MLN_RENDER_BACKEND_METAL
if (permutationUpdated) {
const LinePermutationUBO permutationUBO = {
/* .color = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .blur = */
{/*.source=*/getAttributeSource<BuiltIn::LinePatternShader>(2), /*.expression=*/{}},
/* .opacity = */
{/*.source=*/getAttributeSource<BuiltIn::LinePatternShader>(3), /*.expression=*/{}},
/* .gapwidth = */
{/*.source=*/getAttributeSource<BuiltIn::LinePatternShader>(4), /*.expression=*/{}},
/* .offset = */
{/*.source=*/getAttributeSource<BuiltIn::LinePatternShader>(5), /*.expression=*/{}},
/* .width = */
{/*.source=*/getAttributeSource<BuiltIn::LinePatternShader>(6), /*.expression=*/{}},
/* .floorwidth = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .pattern_from = */
{/*.source=*/getAttributeSource<BuiltIn::LinePatternShader>(7), /*.expression=*/{}},
/* .pattern_to = */
{/*.source=*/getAttributeSource<BuiltIn::LinePatternShader>(8), /*.expression=*/{}},
/* .overdrawInspector = */ overdrawInspector,
/* .pad = */ 0,
0,
0,
0};

context.emplaceOrUpdateUniformBuffer(permutationUniformBuffer, &permutationUBO);
permutationUpdated = false;
}
#endif
} break;

case LineType::SDF: {
Expand Down Expand Up @@ -251,6 +309,32 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
// properties UBO
uniforms.addOrReplace(idLineSDFPropertiesUBOName, getLineSDFPropsBuffer());
}

#if MLN_RENDER_BACKEND_METAL
if (permutationUpdated) {
const LinePermutationUBO permutationUBO = {
/* .color = */ {/*.source=*/getAttributeSource<BuiltIn::LineSDFShader>(2), /*.expression=*/{}},
/* .blur = */ {/*.source=*/getAttributeSource<BuiltIn::LineSDFShader>(3), /*.expression=*/{}},
/* .opacity = */
{/*.source=*/getAttributeSource<BuiltIn::LineSDFShader>(4), /*.expression=*/{}},
/* .gapwidth = */
{/*.source=*/getAttributeSource<BuiltIn::LineSDFShader>(5), /*.expression=*/{}},
/* .offset = */ {/*.source=*/getAttributeSource<BuiltIn::LineSDFShader>(6), /*.expression=*/{}},
/* .width = */ {/*.source=*/getAttributeSource<BuiltIn::LineSDFShader>(7), /*.expression=*/{}},
/* .floorwidth = */
{/*.source=*/getAttributeSource<BuiltIn::LineSDFShader>(8), /*.expression=*/{}},
/* .pattern_from = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .pattern_to = */ {/*.source=*/AttributeSource::Constant, /*.expression=*/{}},
/* .overdrawInspector = */ overdrawInspector,
/* .pad = */ 0,
0,
0,
0};

context.emplaceOrUpdateUniformBuffer(permutationUniformBuffer, &permutationUBO);
permutationUpdated = false;
}
#endif
} break;

default: {
Expand Down

0 comments on commit 08f24a6

Please sign in to comment.