fix: close STEP-085 V4 renderer efficiency
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled

This commit is contained in:
tei
2026-09-19 22:16:36 +09:00
parent bc6b8dd84b
commit 70f112ea27
19 changed files with 501 additions and 111 deletions

View File

@@ -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));