fix: close STEP-085 V4 renderer efficiency
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled
This commit is contained in:
@@ -141,24 +141,20 @@ std::optional<MaterializedColorProjection> materializeColorProjection(const Colo
|
||||
const auto* p0 = findPlane(*projection.t0Frame, projection.contentIdentity.binding.plane);
|
||||
const auto* p1 = findPlane(*projection.t1Frame, projection.contentIdentity.binding.plane);
|
||||
if (!p0 || !p1) return {};
|
||||
MaterializedColorProjection result{baseSnapshot(*projection.t0Frame, projection.contentIdentity.t0Plane),
|
||||
baseSnapshot(*projection.t1Frame, projection.contentIdentity.t1Plane),
|
||||
projection.contentIdentity,
|
||||
projection.sampleState};
|
||||
if (!scalarSnapshot(*projection.t0Frame, *p0, result.t0) || !scalarSnapshot(*projection.t1Frame, *p1, result.t1))
|
||||
auto t0 = std::make_shared<ParticleFieldSnapshot>(baseSnapshot(*projection.t0Frame, projection.contentIdentity.t0Plane));
|
||||
auto t1 = std::make_shared<ParticleFieldSnapshot>(baseSnapshot(*projection.t1Frame, projection.contentIdentity.t1Plane));
|
||||
if (!scalarSnapshot(*projection.t0Frame, *p0, *t0) || !scalarSnapshot(*projection.t1Frame, *p1, *t1))
|
||||
return {};
|
||||
return result;
|
||||
return MaterializedColorProjection{std::move(t0), std::move(t1), projection.contentIdentity, projection.sampleState};
|
||||
}
|
||||
|
||||
std::optional<MaterializedParticleProjection> materializeParticleProjection(const ParticleProjection& projection) {
|
||||
if (!projection.t0Frame || !projection.t1Frame || !compatible(*projection.t0Frame, *projection.t1Frame)) return {};
|
||||
MaterializedParticleProjection result{baseSnapshot(*projection.t0Frame, projection.contentIdentity.t0FirstPlane),
|
||||
baseSnapshot(*projection.t1Frame, projection.contentIdentity.t1FirstPlane),
|
||||
projection.contentIdentity,
|
||||
projection.sampleState};
|
||||
if (!vectorSnapshot(*projection.t0Frame, projection.contentIdentity.binding, result.t0) ||
|
||||
!vectorSnapshot(*projection.t1Frame, projection.contentIdentity.binding, result.t1))
|
||||
auto t0 = std::make_shared<ParticleFieldSnapshot>(baseSnapshot(*projection.t0Frame, projection.contentIdentity.t0FirstPlane));
|
||||
auto t1 = std::make_shared<ParticleFieldSnapshot>(baseSnapshot(*projection.t1Frame, projection.contentIdentity.t1FirstPlane));
|
||||
if (!vectorSnapshot(*projection.t0Frame, projection.contentIdentity.binding, *t0) ||
|
||||
!vectorSnapshot(*projection.t1Frame, projection.contentIdentity.binding, *t1))
|
||||
return {};
|
||||
return result;
|
||||
return MaterializedParticleProjection{std::move(t0), std::move(t1), projection.contentIdentity, projection.sampleState};
|
||||
}
|
||||
} // namespace mbgl::particle
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <mbgl/gfx/texture2d.hpp>
|
||||
#include <mbgl/map/transform_state.hpp>
|
||||
#include <mbgl/particle/field/offline_fixture_particle_adapter.hpp>
|
||||
#include <mbgl/particle/renderer_debug_counters.hpp>
|
||||
#include <mbgl/renderer/buckets/heatmap_bucket.hpp>
|
||||
#include <mbgl/renderer/change_request.hpp>
|
||||
#include <mbgl/renderer/layer_group.hpp>
|
||||
@@ -405,6 +406,7 @@ public:
|
||||
|
||||
void resetSequence(const char* reason) {
|
||||
++resetCount;
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::GpuResourceRelease);
|
||||
Log::Info(Event::Render,
|
||||
"ParticleGPU: event=SIMULATION_RESET reason=" + std::string(reason) + " renderLayerInstanceId=" +
|
||||
std::to_string(renderLayerInstanceId) + " resourceGeneration=" + std::to_string(generation) +
|
||||
@@ -451,6 +453,7 @@ namespace {
|
||||
constexpr uint32_t MaxParticleVerticesPerSegment = std::numeric_limits<uint16_t>::max() + 1u;
|
||||
|
||||
void rebuildParticleDrawResources(const std::shared_ptr<ParticleGpuResources>& resources) {
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::ParticleDrawableRebuild);
|
||||
auto vertices = std::make_shared<gfx::VertexVector<HeatmapTextureLayoutVertex>>();
|
||||
auto coverageVertices = std::make_shared<gfx::VertexVector<HeatmapTextureLayoutVertex>>();
|
||||
vertices->reserve(resources->particleCount * 2);
|
||||
@@ -1103,7 +1106,12 @@ bool RenderRasterParticleLayer::needsRepaint() const {
|
||||
if (!properties.active || (formalSource && (!sourceField || !sourceNextField)) ||
|
||||
baseImpl->visibility == style::VisibilityType::None)
|
||||
return false;
|
||||
return !formalSource || !sourceTimeline || sourceTimeline->cadenceDue(std::chrono::steady_clock::now());
|
||||
const bool repaint = !formalSource ||
|
||||
(sourceUsesV4Projection
|
||||
? sourceV4Cadence && sourceV4Cadence->cadenceDue(std::chrono::steady_clock::now())
|
||||
: !sourceTimeline || sourceTimeline->cadenceDue(std::chrono::steady_clock::now()));
|
||||
if (repaint) particle::incrementRendererDebugCounter(particle::RendererDebugCounter::ParticleNeedsRepaint);
|
||||
return repaint;
|
||||
}
|
||||
|
||||
bool RenderRasterParticleLayer::needsHiddenLayerSourceCleanup(const RenderSource& renderSource) const {
|
||||
@@ -1168,22 +1176,26 @@ void RenderRasterParticleLayer::prepare(const LayerPrepareParameters& parameters
|
||||
sourceNextField = projection.t1;
|
||||
sourceProjectionMix = projection.sampleState.mix;
|
||||
sourceTimeline.reset();
|
||||
sourceV4Cadence = source.impl().v4Cadence;
|
||||
sourceUsesV4Projection = true;
|
||||
return;
|
||||
}
|
||||
sourceV4Cadence.reset();
|
||||
sourceTimeline = source.impl().timeline;
|
||||
if (sourceTimeline) {
|
||||
const auto frame = sourceTimeline->frame();
|
||||
sourceField = *frame.t0;
|
||||
sourceNextField = *frame.t1;
|
||||
sourceField = frame.t0;
|
||||
sourceNextField = frame.t1;
|
||||
sourceTimelineWindowRevision = frame.windowRevision;
|
||||
return;
|
||||
}
|
||||
sourceField.reset();
|
||||
sourceNextField.reset();
|
||||
if (source.impl().field) {
|
||||
sourceField = *source.impl().field;
|
||||
sourceNextField = source.impl().nextField ? *source.impl().nextField : *source.impl().field;
|
||||
sourceField = std::make_shared<const particle::ParticleFieldSnapshot>(*source.impl().field);
|
||||
sourceNextField = source.impl().nextField
|
||||
? std::make_shared<const particle::ParticleFieldSnapshot>(*source.impl().nextField)
|
||||
: sourceField;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1193,6 +1205,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
const std::shared_ptr<UpdateParameters>&,
|
||||
const RenderTree&,
|
||||
UniqueChangeRequestVec& changes) {
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::ParticleUpdate);
|
||||
if (!layerGroup) {
|
||||
if (auto group = context.createLayerGroup(layerIndex, 1, getID())) {
|
||||
setLayerGroup(std::move(group), changes);
|
||||
@@ -1212,6 +1225,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
if (target && target->getLayerGroup(0)) target->getLayerGroup(0)->clearDrawables();
|
||||
for (const auto& target : gpuResources->trailTargets)
|
||||
if (target && target->getLayerGroup(0)) target->getLayerGroup(0)->clearDrawables();
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::GpuResourceRelease);
|
||||
gpuResources.reset();
|
||||
}
|
||||
return;
|
||||
@@ -1224,6 +1238,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
if (layerGroup) static_cast<LayerGroup&>(*layerGroup).clearDrawables();
|
||||
if (gpuResources) {
|
||||
removeTargets(gpuResources->registeredTargets, changes);
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::GpuResourceRelease);
|
||||
gpuResources.reset();
|
||||
}
|
||||
return;
|
||||
@@ -1246,15 +1261,18 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
cadenceRevision = frame.cadenceRevision;
|
||||
cadenceAdvanced = frame.cadenceRevision != sourceTimelineCadenceRevision;
|
||||
if (frame.windowRevision != sourceTimelineWindowRevision) {
|
||||
sourceField = *frame.t0;
|
||||
sourceNextField = *frame.t1;
|
||||
sourceField = frame.t0;
|
||||
sourceNextField = frame.t1;
|
||||
sourceTimelineWindowRevision = frame.windowRevision;
|
||||
}
|
||||
} else if (formalSource && sourceUsesV4Projection && sourceV4Cadence) {
|
||||
cadenceAdvanced = sourceV4Cadence->consumeIfDue(std::chrono::steady_clock::now());
|
||||
}
|
||||
auto resources = gpuResources;
|
||||
if (resources && resources->contextDestroyed) {
|
||||
// VALIDATION ONLY: follow the 30-02 resource-generation rule. No stale
|
||||
// State, Trail, or Mask texture survives a notified context loss.
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::GpuResourceRelease);
|
||||
gpuResources.reset();
|
||||
resources.reset();
|
||||
}
|
||||
@@ -1262,6 +1280,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
auto owned = std::make_shared<ParticleGpuResources>();
|
||||
owned->renderLayerInstanceId = renderLayerInstanceId;
|
||||
owned->generation = ++nextGpuGeneration;
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::GpuResourceCreate);
|
||||
owned->formalDisplay = formalSource;
|
||||
owned->shader = context.getGenericShader(shaders, ShaderName);
|
||||
owned->vertices = std::make_shared<gfx::VertexVector<HeatmapTextureLayoutVertex>>(
|
||||
@@ -1492,6 +1511,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
.wrapV = gfx::TextureWrapType::Clamp});
|
||||
scale = fieldVelocityScale(field);
|
||||
++resources->fieldUploadCount;
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::FieldTextureUpload);
|
||||
Log::Info(Event::Render,
|
||||
"ParticleGPU: event=FIELD_UPLOAD reason=NEW_CONTENT fieldUploadCount=" +
|
||||
std::to_string(resources->fieldUploadCount) +
|
||||
@@ -1733,6 +1753,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
return false;
|
||||
}
|
||||
resources->trailSize = viewport;
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::TrailTargetCreateOrResize);
|
||||
resources->trailRead = 0;
|
||||
resources->trailSeeded = false;
|
||||
Log::Info(
|
||||
@@ -1898,7 +1919,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
|
||||
// Camera-driven frames may recompose existing weather drawables, but do
|
||||
// not advance the shared timeline, State, or Trail before the deadline.
|
||||
if (formalSource && sourceTimeline && !cadenceAdvanced) {
|
||||
if (formalSource && (sourceTimeline || sourceUsesV4Projection) && !cadenceAdvanced) {
|
||||
auto& compositeGroup = static_cast<LayerGroup&>(*layerGroup);
|
||||
compositeGroup.clearDrawables();
|
||||
const auto center = transformState.getLatLng(LatLng::Unwrapped);
|
||||
@@ -1923,6 +1944,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
}
|
||||
|
||||
const auto stateWrite = resources->stateWrite();
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::ParticleSimulationAdvance);
|
||||
const auto trailWrite = resources->trailWrite();
|
||||
auto& stateGroup = static_cast<LayerGroup&>(*resources->stateTargets[stateWrite]->getLayerGroup(0));
|
||||
auto& trailGroup = static_cast<LayerGroup&>(*resources->trailTargets[trailWrite]->getLayerGroup(0));
|
||||
|
||||
@@ -33,9 +33,10 @@ private:
|
||||
void markContextDestroyed() override;
|
||||
|
||||
std::shared_ptr<ParticleGpuResources> gpuResources;
|
||||
std::optional<particle::ParticleFieldSnapshot> sourceField;
|
||||
std::optional<particle::ParticleFieldSnapshot> sourceNextField;
|
||||
std::shared_ptr<const particle::ParticleFieldSnapshot> sourceField;
|
||||
std::shared_ptr<const particle::ParticleFieldSnapshot> sourceNextField;
|
||||
std::shared_ptr<style::RasterArrayTimelineRuntime> sourceTimeline;
|
||||
std::shared_ptr<style::RasterArrayRendererCadence> sourceV4Cadence;
|
||||
float sourceProjectionMix = 0.0f;
|
||||
bool sourceUsesV4Projection = false;
|
||||
uint64_t sourceTimelineWindowRevision = 0;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <mbgl/gfx/shader_registry.hpp>
|
||||
#include <mbgl/gfx/texture2d.hpp>
|
||||
#include <mbgl/gfx/vertex_attribute.hpp>
|
||||
#include <mbgl/particle/renderer_debug_counters.hpp>
|
||||
#include <mbgl/renderer/buckets/heatmap_bucket.hpp>
|
||||
#include <mbgl/renderer/layer_group.hpp>
|
||||
#include <mbgl/renderer/render_static_data.hpp>
|
||||
@@ -88,22 +89,18 @@ struct Resources {
|
||||
float scale0 = 1.0f;
|
||||
float scale1 = 1.0f;
|
||||
style::FieldValueSource valueSource = style::FieldValueSource::VectorMagnitude;
|
||||
float mix = 0.0f;
|
||||
float opacity = 1.0f;
|
||||
std::vector<style::WeatherColorStop> stops;
|
||||
int16_t firstWrap = 0;
|
||||
int16_t lastWrap = -1;
|
||||
uint64_t drawableRebuildCount = 0;
|
||||
};
|
||||
|
||||
class Tweaker final : public gfx::DrawableTweaker {
|
||||
public:
|
||||
Tweaker(std::shared_ptr<Resources> resources_,
|
||||
float mix_,
|
||||
float opacity_,
|
||||
int16_t wrap_,
|
||||
std::vector<style::WeatherColorStop> stops_,
|
||||
style::FieldValueSource valueSource_)
|
||||
: resources(std::move(resources_)),
|
||||
mix(mix_),
|
||||
opacity(opacity_),
|
||||
wrap(wrap_),
|
||||
stops(std::move(stops_)),
|
||||
valueSource(valueSource_) {}
|
||||
Tweaker(std::shared_ptr<Resources> resources_, int16_t wrap_)
|
||||
: resources(std::move(resources_)), wrap(wrap_) {}
|
||||
void init(gfx::Drawable&) override {}
|
||||
void execute(gfx::Drawable& drawable, PaintParameters& parameters) override {
|
||||
drawable.setTexture(resources->texture0, shaders::idParticleGpuValidationPreviousTexture);
|
||||
@@ -111,9 +108,9 @@ public:
|
||||
drawable.setTexture(resources->texture1, shaders::idParticleGpuValidationNextFieldTexture);
|
||||
shaders::ParticleGpuValidationUBO ubo = {
|
||||
.pass = {5.0f, 0.0f, 0.0f, 0.0f},
|
||||
.marker = {mix, 0.0f, 0.0f, 0.0f},
|
||||
.marker = {resources->mix, 0.0f, 0.0f, 0.0f},
|
||||
.mask = {0, 0, 0, 0},
|
||||
.visual = {opacity, 0, 0, 0},
|
||||
.visual = {resources->opacity, 0, 0, 0},
|
||||
.fieldBounds = bounds(resources->t0),
|
||||
.respawnBounds = bounds(resources->t0),
|
||||
.fieldScale = {resources->scale0, resources->scale1, 0, 0},
|
||||
@@ -127,22 +124,18 @@ public:
|
||||
.weatherRamp = {},
|
||||
.matrix = util::cast<float>(parameters.matrixForTile({wrap, {0, 0, 0}})),
|
||||
};
|
||||
ubo.weatherRamp[0] = static_cast<float>(stops.size());
|
||||
ubo.weatherRamp[1] = valueSource == style::FieldValueSource::VectorMagnitude ? 1.0f : 0.0f;
|
||||
for (size_t i = 0; i < stops.size(); ++i) {
|
||||
ubo.weatherStops[i][0] = stops[i].value;
|
||||
ubo.weatherColors[i] = stops[i].color;
|
||||
ubo.weatherRamp[0] = static_cast<float>(resources->stops.size());
|
||||
ubo.weatherRamp[1] = resources->valueSource == style::FieldValueSource::VectorMagnitude ? 1.0f : 0.0f;
|
||||
for (size_t i = 0; i < resources->stops.size(); ++i) {
|
||||
ubo.weatherStops[i][0] = resources->stops[i].value;
|
||||
ubo.weatherColors[i] = resources->stops[i].color;
|
||||
}
|
||||
drawable.mutableUniformBuffers().createOrUpdate(shaders::idParticleGpuValidationUBO, &ubo, parameters.context);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<Resources> resources;
|
||||
float mix;
|
||||
float opacity;
|
||||
int16_t wrap;
|
||||
std::vector<style::WeatherColorStop> stops;
|
||||
style::FieldValueSource valueSource;
|
||||
};
|
||||
|
||||
bool same(const particle::ParticleFieldSnapshot& a, const particle::ParticleFieldSnapshot& b) {
|
||||
@@ -163,6 +156,7 @@ bool uploadField(gfx::Context& context,
|
||||
outputTexture->setSamplerConfiguration({.filter = gfx::TextureFilterType::Linear,
|
||||
.wrapU = gfx::TextureWrapType::Clamp,
|
||||
.wrapV = gfx::TextureWrapType::Clamp});
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::FieldTextureUpload);
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
@@ -180,9 +174,10 @@ void RenderWeatherColorLayer::evaluate(const PropertyEvaluationParameters&) {
|
||||
}
|
||||
bool RenderWeatherColorLayer::needsRepaint() const {
|
||||
if (!isLayerRenderable() || !sourceField || !sourceNextField) return false;
|
||||
if (!sourceTimeline) return true;
|
||||
return sourceTimeline->frame().state == style::RasterArrayPlaybackState::Playing &&
|
||||
sourceTimeline->cadenceDue(std::chrono::steady_clock::now());
|
||||
const bool repaint = sourceTimeline && sourceTimeline->frame().state == style::RasterArrayPlaybackState::Playing &&
|
||||
sourceTimeline->cadenceDue(std::chrono::steady_clock::now());
|
||||
if (repaint) particle::incrementRendererDebugCounter(particle::RendererDebugCounter::WeatherColorNeedsRepaint);
|
||||
return repaint;
|
||||
}
|
||||
bool RenderWeatherColorLayer::needsHiddenLayerSourceCleanup(const RenderSource& renderSource) const {
|
||||
if (!resources || renderSource.baseImpl->type != style::SourceType::RasterArray) return false;
|
||||
@@ -217,11 +212,13 @@ void RenderWeatherColorLayer::prepare(const LayerPrepareParameters& parameters)
|
||||
sourceTimeline = source.impl().timeline;
|
||||
if (sourceTimeline) {
|
||||
const auto frame = sourceTimeline->frame();
|
||||
sourceField = *frame.t0;
|
||||
sourceNextField = *frame.t1;
|
||||
sourceField = frame.t0;
|
||||
sourceNextField = frame.t1;
|
||||
} else if (source.impl().field) {
|
||||
sourceField = *source.impl().field;
|
||||
sourceNextField = source.impl().nextField ? *source.impl().nextField : *source.impl().field;
|
||||
sourceField = std::make_shared<const particle::ParticleFieldSnapshot>(*source.impl().field);
|
||||
sourceNextField = source.impl().nextField
|
||||
? std::make_shared<const particle::ParticleFieldSnapshot>(*source.impl().nextField)
|
||||
: sourceField;
|
||||
} else {
|
||||
sourceField.reset();
|
||||
sourceNextField.reset();
|
||||
@@ -233,6 +230,7 @@ void RenderWeatherColorLayer::update(gfx::ShaderRegistry& shaders,
|
||||
const std::shared_ptr<UpdateParameters>&,
|
||||
const RenderTree&,
|
||||
UniqueChangeRequestVec& changes) {
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::WeatherColorUpdate);
|
||||
if (!layerGroup)
|
||||
if (auto group = context.createLayerGroup(layerIndex, 1, getID())) setLayerGroup(std::move(group), changes);
|
||||
if (!sourceField || !sourceNextField) {
|
||||
@@ -261,8 +259,8 @@ void RenderWeatherColorLayer::update(gfx::ShaderRegistry& shaders,
|
||||
if (timelineFrame.state == style::RasterArrayPlaybackState::Playing) {
|
||||
timelineFrame = sourceTimeline->advanceIfDue(std::chrono::steady_clock::now()).frame;
|
||||
}
|
||||
sourceField = *timelineFrame.t0;
|
||||
sourceNextField = *timelineFrame.t1;
|
||||
sourceField = timelineFrame.t0;
|
||||
sourceNextField = timelineFrame.t1;
|
||||
}
|
||||
auto state = std::static_pointer_cast<Resources>(resources);
|
||||
if (!state) {
|
||||
@@ -331,11 +329,21 @@ void RenderWeatherColorLayer::update(gfx::ShaderRegistry& shaders,
|
||||
}
|
||||
const float mix = sourceTimeline ? timelineFrame.mix : (sourceUsesV4Projection ? sourceProjectionMix : 0.0f);
|
||||
const float opacity = static_cast<const style::WeatherColorLayer::Impl&>(*baseImpl).opacity;
|
||||
state->mix = mix;
|
||||
state->opacity = opacity;
|
||||
state->stops = static_cast<const style::WeatherColorLayer::Impl&>(*baseImpl).colorStops;
|
||||
auto& group = static_cast<LayerGroup&>(*layerGroup);
|
||||
group.clearDrawables();
|
||||
const auto center = transformState.getLatLng(LatLng::Unwrapped);
|
||||
const auto centerWrap = static_cast<int16_t>(std::floor((center.longitude() + 180.0) / 360.0));
|
||||
for (int16_t wrap = centerWrap - 1; wrap <= centerWrap + 1; ++wrap) {
|
||||
const int16_t firstWrap = centerWrap - 1;
|
||||
const int16_t lastWrap = centerWrap + 1;
|
||||
if (state->firstWrap == firstWrap && state->lastWrap == lastWrap) return;
|
||||
group.clearDrawables();
|
||||
state->firstWrap = firstWrap;
|
||||
state->lastWrap = lastWrap;
|
||||
++state->drawableRebuildCount;
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::WeatherColorDrawableRebuild);
|
||||
for (int16_t wrap = firstWrap; wrap <= lastWrap; ++wrap) {
|
||||
auto attributes = context.createVertexAttributeArray();
|
||||
if (const auto& attribute = attributes->set(shaders::idParticleGpuValidationPosVertexAttribute))
|
||||
attribute->setSharedRawData(state->vertices,
|
||||
@@ -358,13 +366,7 @@ void RenderWeatherColorLayer::update(gfx::ShaderRegistry& shaders,
|
||||
builder->setTexture(state->texture0, shaders::idParticleGpuValidationPreviousTexture);
|
||||
builder->setTexture(state->texture0, shaders::idParticleGpuValidationFieldTexture);
|
||||
builder->setTexture(state->texture1, shaders::idParticleGpuValidationNextFieldTexture);
|
||||
builder->addTweaker(
|
||||
std::make_shared<Tweaker>(state,
|
||||
mix,
|
||||
opacity,
|
||||
wrap,
|
||||
static_cast<const style::WeatherColorLayer::Impl&>(*baseImpl).colorStops,
|
||||
valueSource));
|
||||
builder->addTweaker(std::make_shared<Tweaker>(state, wrap));
|
||||
builder->flush(context);
|
||||
auto drawables = builder->clearDrawables();
|
||||
if (drawables.size() == 1 && drawables.front()) group.addDrawable(std::move(drawables.front()));
|
||||
|
||||
@@ -29,8 +29,8 @@ private:
|
||||
void markContextDestroyed() override;
|
||||
|
||||
std::shared_ptr<void> resources;
|
||||
std::optional<particle::ParticleFieldSnapshot> sourceField;
|
||||
std::optional<particle::ParticleFieldSnapshot> sourceNextField;
|
||||
std::shared_ptr<const particle::ParticleFieldSnapshot> sourceField;
|
||||
std::shared_ptr<const particle::ParticleFieldSnapshot> sourceNextField;
|
||||
std::shared_ptr<style::RasterArrayTimelineRuntime> sourceTimeline;
|
||||
float sourceProjectionMix = 0.0f;
|
||||
bool sourceUsesV4Projection = false;
|
||||
|
||||
@@ -27,8 +27,8 @@ public:
|
||||
explicit RenderRasterArraySource(Immutable<style::RasterArraySource::Impl> impl)
|
||||
: RenderSource(std::move(impl)) {}
|
||||
bool isLoaded() const override {
|
||||
return impl().field.has_value() || impl().v4RendererState.color.has_value() ||
|
||||
impl().v4RendererState.particle.has_value();
|
||||
return impl().field.has_value() || static_cast<bool>(impl().v4RendererState.color) ||
|
||||
static_cast<bool>(impl().v4RendererState.particle);
|
||||
}
|
||||
void update(Immutable<style::Source::Impl> value,
|
||||
const std::vector<Immutable<style::LayerProperties>>&,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <mbgl/particle/field/offline_fixture_particle_adapter.hpp>
|
||||
#include <mbgl/particle/field/local_particle_field_feed.hpp>
|
||||
#include <mbgl/particle/renderer_debug_counters.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/storage/resource.hpp>
|
||||
#include <mbgl/style/source_observer.hpp>
|
||||
@@ -62,11 +63,11 @@ bool sameSnapshot(const particle::ParticleFieldSnapshot& a, const particle::Part
|
||||
particle::sameFieldGpuContent(a, b);
|
||||
}
|
||||
template <class Projection>
|
||||
bool sameProjection(const std::optional<Projection>& a, const std::optional<Projection>& b) {
|
||||
if (a.has_value() != b.has_value()) return false;
|
||||
bool sameProjection(const std::shared_ptr<const Projection>& a, const std::shared_ptr<const Projection>& b) {
|
||||
if (static_cast<bool>(a) != static_cast<bool>(b)) return false;
|
||||
return !a || (a->contentIdentity == b->contentIdentity && a->sampleState.mix == b->sampleState.mix &&
|
||||
a->sampleState.requestedForecastTimeMs == b->sampleState.requestedForecastTimeMs &&
|
||||
sameSnapshot(a->t0, b->t0) && sameSnapshot(a->t1, b->t1));
|
||||
a->t0 && b->t0 && a->t1 && b->t1 && sameSnapshot(*a->t0, *b->t0) && sameSnapshot(*a->t1, *b->t1));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -136,6 +137,40 @@ RasterArrayTimelineFrame RasterArrayTimelineRuntime::frame() const {
|
||||
return frameLocked();
|
||||
}
|
||||
|
||||
bool RasterArrayRendererCadence::consumeIfDue(const std::chrono::steady_clock::time_point now) {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
if (targetFps_ != RasterArrayTargetFps::Auto && lastTick.time_since_epoch().count() != 0) {
|
||||
const auto interval = std::chrono::duration<double>(1.0 / static_cast<uint8_t>(targetFps_));
|
||||
if (now - lastTick < interval) return false;
|
||||
}
|
||||
lastTick = now;
|
||||
++revision_;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RasterArrayRendererCadence::cadenceDue(const std::chrono::steady_clock::time_point now) const {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
if (targetFps_ == RasterArrayTargetFps::Auto || lastTick.time_since_epoch().count() == 0) return true;
|
||||
const auto interval = std::chrono::duration<double>(1.0 / static_cast<uint8_t>(targetFps_));
|
||||
return now - lastTick >= interval;
|
||||
}
|
||||
|
||||
void RasterArrayRendererCadence::setTargetFps(const RasterArrayTargetFps target) {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
targetFps_ = target;
|
||||
lastTick = {};
|
||||
}
|
||||
|
||||
RasterArrayTargetFps RasterArrayRendererCadence::targetFps() const {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
return targetFps_;
|
||||
}
|
||||
|
||||
uint64_t RasterArrayRendererCadence::revision() const {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
return revision_;
|
||||
}
|
||||
|
||||
float RasterArrayTimelineRuntime::playbackSpeed() const {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
return speed;
|
||||
@@ -461,16 +496,23 @@ void RasterArraySource::refreshV4RendererState() {
|
||||
Impl::V4RendererState next;
|
||||
if (colorBinding) {
|
||||
const auto resolved = resolveColorProjection();
|
||||
if (resolved.accepted()) next.color = particle::materializeColorProjection(*resolved.projection);
|
||||
if (const auto materialized = resolved.accepted() ? particle::materializeColorProjection(*resolved.projection)
|
||||
: std::nullopt)
|
||||
next.color = std::make_shared<const particle::MaterializedColorProjection>(std::move(*materialized));
|
||||
if (next.color) particle::incrementRendererDebugCounter(particle::RendererDebugCounter::V4ProjectionMaterialize);
|
||||
}
|
||||
if (particleBinding) {
|
||||
const auto resolved = resolveParticleProjection();
|
||||
if (resolved.accepted()) next.particle = particle::materializeParticleProjection(*resolved.projection);
|
||||
if (const auto materialized = resolved.accepted() ? particle::materializeParticleProjection(*resolved.projection)
|
||||
: std::nullopt)
|
||||
next.particle = std::make_shared<const particle::MaterializedParticleProjection>(std::move(*materialized));
|
||||
if (next.particle) particle::incrementRendererDebugCounter(particle::RendererDebugCounter::V4ProjectionMaterialize);
|
||||
}
|
||||
const auto& current = impl().v4RendererState;
|
||||
if (sameProjection(current.color, next.color) && sameProjection(current.particle, next.particle)) return;
|
||||
auto updated = makeMutable<Impl>(impl());
|
||||
updated->v4RendererState = std::move(next);
|
||||
particle::incrementRendererDebugCounter(particle::RendererDebugCounter::FieldWindowRevision);
|
||||
baseImpl = std::move(updated);
|
||||
loaded = true;
|
||||
observer->onSourceChanged(*this);
|
||||
@@ -1119,6 +1161,7 @@ bool RasterArraySource::setRuntimeTargetFps(const uint8_t requested) {
|
||||
}
|
||||
targetFps = next;
|
||||
if (timeline) timeline->setTargetFps(next);
|
||||
if (impl().v4Cadence) impl().v4Cadence->setTargetFps(next);
|
||||
observer->onSourceChanged(*this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace mbgl::style {
|
||||
class RasterArraySource::Impl final : public Source::Impl {
|
||||
public:
|
||||
struct V4RendererState {
|
||||
std::optional<particle::MaterializedColorProjection> color;
|
||||
std::optional<particle::MaterializedParticleProjection> particle;
|
||||
std::shared_ptr<const particle::MaterializedColorProjection> color;
|
||||
std::shared_ptr<const particle::MaterializedParticleProjection> particle;
|
||||
};
|
||||
Impl(std::string sourceID,
|
||||
std::string fixtureID_,
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
localFields(other.localFields),
|
||||
hostFieldSubmission(other.hostFieldSubmission),
|
||||
timeline(other.timeline),
|
||||
v4Cadence(other.v4Cadence),
|
||||
v4RendererState(other.v4RendererState),
|
||||
field(std::move(field_)) {}
|
||||
Impl(const Impl& other, particle::ParticleFieldSnapshot field_, particle::ParticleFieldSnapshot nextField_)
|
||||
@@ -66,6 +67,7 @@ public:
|
||||
std::vector<RasterArrayLocalFieldDescriptor> localFields;
|
||||
bool hostFieldSubmission = false;
|
||||
std::shared_ptr<RasterArrayTimelineRuntime> timeline;
|
||||
std::shared_ptr<RasterArrayRendererCadence> v4Cadence = std::make_shared<RasterArrayRendererCadence>();
|
||||
// Immutable renderer-facing V4 state. It is intentionally separate from
|
||||
// the legacy V3 timeline/field pair.
|
||||
V4RendererState v4RendererState;
|
||||
|
||||
Reference in New Issue
Block a user