Skip to content

Commit

Permalink
Retain property update flags (#2083)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSylvester authored Feb 1, 2024
1 parent d2feec2 commit 14bfb5d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 32 deletions.
38 changes: 15 additions & 23 deletions src/mbgl/renderer/layers/fill_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
#endif

// Only run each update function once
bool fillUniformBufferUpdated = false;
bool fillOutlineUniformBufferUpdated = false;
bool fillPatternUniformBufferUpdated = false;
bool fillOutlinePatternUniformBufferUpdated = false;

const auto UpdateFillUniformBuffers = [&]() {
if (fillUniformBufferUpdated) return;
if (propertiesUpdated) {
fillUniformBufferUpdated = true;
fillOutlineUniformBufferUpdated = true;
fillPatternUniformBufferUpdated = true;
fillOutlinePatternUniformBufferUpdated = true;
propertiesUpdated = false;
}

if (!fillPropsUniformBuffer || propertiesUpdated) {
const auto UpdateFillUniformBuffers = [&]() {
if (!fillPropsUniformBuffer || fillUniformBufferUpdated) {
const FillEvaluatedPropsUBO paramsUBO = {
/* .color = */ evaluated.get<FillColor>().constantOr(FillColor::defaultValue()),
/* .opacity = */ evaluated.get<FillOpacity>().constantOr(FillOpacity::defaultValue()),
Expand All @@ -62,14 +61,12 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
0,
};
context.emplaceOrUpdateUniformBuffer(fillPropsUniformBuffer, &paramsUBO);
fillUniformBufferUpdated = false;
}
};

const auto UpdateFillOutlineUniformBuffers = [&]() {
if (fillOutlineUniformBufferUpdated) return;
fillOutlineUniformBufferUpdated = true;

if (!fillOutlinePropsUniformBuffer || propertiesUpdated) {
if (!fillOutlinePropsUniformBuffer || fillOutlineUniformBufferUpdated) {
const FillOutlineEvaluatedPropsUBO paramsUBO = {
/* .outline_color = */ evaluated.get<FillOutlineColor>().constantOr(FillOutlineColor::defaultValue()),
/* .opacity = */ evaluated.get<FillOpacity>().constantOr(FillOpacity::defaultValue()),
Expand All @@ -78,36 +75,33 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
0,
};
context.emplaceOrUpdateUniformBuffer(fillOutlinePropsUniformBuffer, &paramsUBO);
fillOutlineUniformBufferUpdated = false;
}
};

const auto UpdateFillPatternUniformBuffers = [&]() {
if (fillPatternUniformBufferUpdated) return;
fillPatternUniformBufferUpdated = true;

if (!fillPatternPropsUniformBuffer || propertiesUpdated) {
if (!fillPatternPropsUniformBuffer || fillPatternUniformBufferUpdated) {
const FillPatternEvaluatedPropsUBO paramsUBO = {
/* .opacity = */ evaluated.get<FillOpacity>().constantOr(FillOpacity::defaultValue()),
/* .fade = */ crossfade.t,
0,
0,
};
context.emplaceOrUpdateUniformBuffer(fillPatternPropsUniformBuffer, &paramsUBO);
fillPatternUniformBufferUpdated = false;
}
};

const auto UpdateFillOutlinePatternUniformBuffers = [&]() {
if (fillOutlinePatternUniformBufferUpdated) return;
fillOutlinePatternUniformBufferUpdated = true;

if (!fillOutlinePatternPropsUniformBuffer || propertiesUpdated) {
if (!fillOutlinePatternPropsUniformBuffer || fillOutlinePatternUniformBufferUpdated) {
const FillOutlinePatternEvaluatedPropsUBO paramsUBO = {
/* .opacity = */ evaluated.get<FillOpacity>().constantOr(FillOpacity::defaultValue()),
/* .fade = */ crossfade.t,
0,
0,
};
context.emplaceOrUpdateUniformBuffer(fillOutlinePatternPropsUniformBuffer, &paramsUBO);
fillOutlinePatternUniformBufferUpdated = false;
}
};

Expand Down Expand Up @@ -214,8 +208,6 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
}
}
});

propertiesUpdated = false;
}

} // namespace mbgl
6 changes: 6 additions & 0 deletions src/mbgl/renderer/layers/fill_layer_tweaker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class FillLayerTweaker : public LayerTweaker {
gfx::UniformBufferPtr fillOutlinePropsUniformBuffer;
gfx::UniformBufferPtr fillPatternPropsUniformBuffer;
gfx::UniformBufferPtr fillOutlinePatternPropsUniformBuffer;

// Only run each update function once per property update
bool fillUniformBufferUpdated = true;
bool fillOutlineUniformBufferUpdated = true;
bool fillPatternUniformBufferUpdated = true;
bool fillOutlinePatternUniformBufferUpdated = true;
};

} // namespace mbgl
3 changes: 1 addition & 2 deletions src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet
/* .intensity = */ evaluated.get<HeatmapIntensity>(),
/* .padding = */ 0};
parameters.context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO);
propertiesUpdated = false;
}
return evaluatedPropsUniformBuffer;
};
Expand All @@ -67,8 +68,6 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet

uniforms.createOrUpdate(idHeatmapDrawableUBO, &drawableUBO, context);
});

propertiesUpdated = false;
}

} // namespace mbgl
3 changes: 1 addition & 2 deletions src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam
/* .shadow = */ evaluated.get<HillshadeShadowColor>(),
/* .accent = */ evaluated.get<HillshadeAccentColor>()};
parameters.context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO);
propertiesUpdated = false;
}
return evaluatedPropsUniformBuffer;
};
Expand All @@ -72,8 +73,6 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam
/* .light = */ getLight(parameters, evaluated)};
uniforms.createOrUpdate(idHillshadeDrawableUBO, &drawableUBO, parameters.context);
});

propertiesUpdated = false;
}

} // namespace mbgl
12 changes: 7 additions & 5 deletions src/mbgl/renderer/layers/line_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
const auto& crossfade = static_cast<const LineLayerProperties&>(*evaluatedProperties).crossfade;

// Each property UBO is updated at most once if new evaluated properties were set
bool simplePropertiesUpdated = propertiesUpdated;
bool gradientPropertiesUpdated = propertiesUpdated;
bool patternPropertiesUpdated = propertiesUpdated;
bool sdfPropertiesUpdated = propertiesUpdated;
propertiesUpdated = false;
if (propertiesUpdated) {
simplePropertiesUpdated = true;
gradientPropertiesUpdated = true;
patternPropertiesUpdated = true;
sdfPropertiesUpdated = true;
propertiesUpdated = false;
}

const auto getLinePropsBuffer = [&]() {
if (!linePropertiesBuffer || simplePropertiesUpdated) {
Expand Down
5 changes: 5 additions & 0 deletions src/mbgl/renderer/layers/line_layer_tweaker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class LineLayerTweaker : public LayerTweaker {
gfx::UniformBufferPtr permutationUniformBuffer;
gfx::UniformBufferPtr expressionUniformBuffer;
#endif // MLN_RENDER_BACKEND_METAL

bool simplePropertiesUpdated = true;
bool gradientPropertiesUpdated = true;
bool patternPropertiesUpdated = true;
bool sdfPropertiesUpdated = true;
};

} // namespace mbgl

0 comments on commit 14bfb5d

Please sign in to comment.