feat: add retained underlay revision invalidation

This commit is contained in:
tei
2026-09-22 21:01:01 +09:00
parent 07a17b4c70
commit bcec6ce5e0
11 changed files with 817 additions and 24 deletions

View File

@@ -75,6 +75,8 @@ void logRetainedRendererCounters(const RetainedUnderlayCache& cache) {
<< " fallback=" << retained.fallback
<< " invalidation=" << retained.invalidation
<< " reason=" << retained.lastReason
<< " staticRevision=" << cache.getStaticRevision()
<< " buildRevision=" << cache.getBuildRevision()
<< " staticDraw=" << detailed.retainedUnderlayStaticGroupDraw
<< " dynamicDraw=" << detailed.retainedDynamicGroupDraw
<< " particleAdvance=" << detailed.particleSimulationAdvance;
@@ -301,14 +303,19 @@ void Renderer::Impl::render(const RenderTree& renderTree, const std::shared_ptr<
std::optional<RetainedUnderlayKey> retainedKey;
const auto retainedBoundary = orchestrator.getRetainedDynamicBoundary();
size_t retainedStaticGroupCount = 0;
RetainedUnderlayTopologySnapshot retainedTopology{.boundary = retainedBoundary, .staticPrefix = {}};
mat4 retainedCameraMatrix;
state.getProjMatrix(retainedCameraMatrix);
if (retainedBoundary) {
orchestrator.visitLayerGroupsBefore(*retainedBoundary,
[&](LayerGroupBase&, size_t) { ++retainedStaticGroupCount; });
mat4 cameraMatrix;
state.getProjMatrix(cameraMatrix);
retainedKey = RetainedUnderlayKey{size, *retainedBoundary, cameraMatrix};
orchestrator.visitLayerGroupsBefore(*retainedBoundary, [&](LayerGroupBase& layerGroup, size_t) {
retainedTopology.staticPrefix.push_back({.layerIndex = layerGroup.getLayerIndex(),
.groupName = layerGroup.getName(),
.groupType = static_cast<uint8_t>(layerGroup.getType())});
});
retainedKey = RetainedUnderlayKey{size, *retainedBoundary, retainedCameraMatrix};
}
const auto retainedTopologyRevision = retainedUnderlayTopologyTracker.observe(retainedTopology);
const auto retainedStaticGroupCount = retainedTopology.staticPrefix.size();
bool legacyBelowBoundary = false;
if (retainedBoundary) {
for (const auto& item : layerRenderItems) {
@@ -325,11 +332,33 @@ void Renderer::Impl::render(const RenderTree& renderTree, const std::shared_ptr<
const bool retainedPlacementStable =
!retainedStaticUsesPlacement ||
(!renderTreeParameters.placementChanged && renderTreeParameters.symbolFadeChange == 0.0f);
const bool retainedUnsupportedStaticLayer =
retainedBoundary && orchestrator.retainedUnderlayHasUnsupportedLayer(*retainedBoundary);
const auto retainedContentRevision = orchestrator.getRetainedUnderlayContentRevision();
const auto retainedContentReason = orchestrator.getRetainedUnderlayContentReason();
const RetainedUnderlayRevisionState retainedRevisionState{
.viewport = size,
.cameraMatrix = retainedCameraMatrix,
.boundary = retainedBoundary,
.pixelRatio = updateParameters->pixelRatio,
.contentRevision = retainedContentRevision,
.topologyRevision = retainedTopologyRevision,
.mapMode = static_cast<uint8_t>(updateParameters->mode),
.debugOptions = static_cast<uint32_t>(renderTreeParameters.debugOptions),
.styleLoaded = updateParameters->styleLoaded,
.renderTreeLoaded = renderTreeParameters.loaded,
.staticStable = retainedStaticStable,
.placementStable = retainedPlacementStable,
.has3D = renderTreeParameters.has3D,
.unsupportedStaticLayer = retainedUnsupportedStaticLayer,
};
const auto retainedStaticRevision = retainedUnderlayRevisionTracker.observe(
retainedRevisionState, retainedUnderlayReasonText(retainedContentReason));
const bool retainedSupported = retainedBoundary && retainedStaticGroupCount > 0 &&
renderTreeParameters.loaded && !renderTreeParameters.has3D &&
renderTreeParameters.debugOptions == MapDebugOptions::NoDebug &&
retainedStaticStable && retainedPlacementStable &&
!legacyBelowBoundary;
!legacyBelowBoundary && !retainedUnsupportedStaticLayer;
const char* retainedFallbackReason = !retainedBoundary ? "no-boundary"
: retainedStaticGroupCount == 0 ? "empty-static-prefix"
: !renderTreeParameters.loaded ? "style-not-loaded"
@@ -341,10 +370,13 @@ void Renderer::Impl::render(const RenderTree& renderTree, const std::shared_ptr<
: !retainedPlacementStable
? "static-placement"
: legacyBelowBoundary ? "legacy-ordering"
: retainedUnsupportedStaticLayer ? "unsupported"
: nullptr;
auto retainedDecision = retainedUnderlayCache->evaluate(retainedKey,
retainedStaticRevision,
retainedSupported,
retainedFallbackReason);
retainedFallbackReason,
retainedUnderlayRevisionTracker.reason().c_str());
if ((retainedDecision == RetainedUnderlayDecision::Build ||
retainedDecision == RetainedUnderlayDecision::Reuse) &&
(!staticData->shaders || !retainedUnderlayCache->prepareResources(context, *staticData->shaders, *retainedKey))) {