-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Disable terrain render cache during style property transitions #10485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/terrain/terrain.js
Outdated
const options = this.painter.options; | ||
this.renderCached = (options.zooming || options.moving || options.rotating || !!this.forceRenderCached) && !this._invalidateRenderCache; | ||
this.renderCached = (options.zooming || options.moving || options.rotating || !!this.forceRenderCached) && !this._invalidateRenderCache && !options.styleDirty; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's similar implementation used for crossfade below:
mapbox-gl-js/src/terrain/terrain.js
Lines 830 to 836 in 5db8469
_shouldDisableRenderCache(): boolean { | |
// Disable render caches on dynamic events due to fading. | |
const isCrossFading = id => { | |
const layer = this._style._layers[id]; | |
const isHidden = !layer.isHidden(this.painter.transform.zoom); | |
const crossFade = layer.getCrossfadeParameters(); | |
const isFading = !!crossFade && crossFade.t !== 1; |
should we add this.style.hasTransitions() there instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I agree, I also think that would be a better place to consolidate this logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I've updated the PR by moving the introduced logic to _shouldDisableRenderCache
. I was initially concerned if some of the transition events could be missed because style.update()
was called before painter.render()
leading to "transition" flags being clear before rendering of the frame was done. But this works correctly as render cache contents gets updated in the very first frame after transitions have finished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit to maybe consolidate logic in _shouldDisableRenderCache, otherwise LGTM.
src/terrain/terrain.js
Outdated
const options = this.painter.options; | ||
this.renderCached = (options.zooming || options.moving || options.rotating || !!this.forceRenderCached) && !this._invalidateRenderCache; | ||
this.renderCached = (options.zooming || options.moving || options.rotating || !!this.forceRenderCached) && !this._invalidateRenderCache && !options.styleDirty; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I agree, I also think that would be a better place to consolidate this logic.
a3aac05
to
57ec76e
Compare
const layer = this._style._layers[id]; | ||
const isHidden = !layer.isHidden(this.painter.transform.zoom); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed a possible bug where isHidden
was negated twice leading to wrong result. Hidden layers are now properly skipped when determining whether caching should be disabled. @astojilj can you confirm this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great find. This relates to raster fade on terrain and good to recheck the details (a192ebb) - there is render cache there that seems to be passing now, too.
Edit: please ignore this, wrong about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The terrain feature uses render cache for optimizing rendering performance by caching intermediate rendering results of tiles in cache textures when certain conditions are met. The cache is supposed to get invalidated on style changes but the code is not currently taking transitions into account. Terrain class correctly listens for style data events but those are sent only once at the beginning of transitions.
The following snippet changes water color correctly in Streets-style when the transition duration is set to zero.
But the render cache does not get invalidated properly when a transition duration is set.
This pull request fixes the cache invalidation by disabling the render cache for the duration of style property transitions. The PR does not fix cache issues caused by re-evalution of paint properties (#10302). Six new render tests have been added (most of which fails before the patch and passes after it) for validating the fix.
Launch Checklist
mapbox-gl-js
changelog:<changelog>Fix style property transitions not invalidating the terrain render cache</changelog>