Skip to content
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

Disable terrain render cache during style property transitions #10485

Merged
merged 4 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/terrain/terrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,15 +827,30 @@ export class Terrain extends Elevation {
}

_shouldDisableRenderCache(): boolean {
// Disable render caches on dynamic events due to fading.
const isCrossFading = id => {
if (!this.renderCached) {
return true;
}

// Disable render caches on dynamic events due to fading or transitioning.
if (this._style.light && this._style.light.hasTransition()) {
return true;
}

for (const id in this._style._sourceCaches) {
if (this._style._sourceCaches[id].hasTransition()) {
return true;
}
}

const fadingOrTransitioning = id => {
const layer = this._style._layers[id];
const isHidden = !layer.isHidden(this.painter.transform.zoom);
Copy link
Contributor Author

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?

Copy link
Contributor

@astojilj astojilj Mar 22, 2021

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.

const isHidden = layer.isHidden(this.painter.transform.zoom);
const crossFade = layer.getCrossfadeParameters();
const isFading = !!crossFade && crossFade.t !== 1;
return layer.type !== 'custom' && !isHidden && isFading;
const isTransitioning = layer.hasTransition();
return layer.type !== 'custom' && !isHidden && (isFading || isTransitioning);
};
return !this.renderCached || this._style.order.some(isCrossFading);
return this._style.order.some(fadingOrTransitioning);
}

_clearRasterFadeFromRenderCache() {
Expand Down
7 changes: 7 additions & 0 deletions test/integration/lib/operation-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ export const operationHandlers = {
map.updateImage(params[0], image);
doneCb();
});
},
forceRenderCached(map, params, doneCb) {
const terrain = map.painter.terrain;
if (terrain) {
terrain.forceRenderCached = params[0];
}
doneCb();
}
};

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256,
"width": 256,
"operations": [
["forceRenderCached", true],
["wait"],
["setPaintProperty", "background", "background-color", ["rgba", 117.0, 207.0, 0.0, 1.0 ]],
["wait", 0],
["wait", 350]
]
}
},
"center": [-113.26903, 35.9654],
"zoom": 11,
"pitch": 45,
"terrain": {
"source": "rgbterrain"
},
"sources": {
"rgbterrain": {
"type": "raster-dem",
"tiles": [
"local://tiles/{z}-{x}-{y}.terrain.png"
],
"maxzoom": 15,
"tileSize": 256
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": [
"rgba",
117.00000762939453,
207.00001525878907,
240.00001525878907,
1.0
]
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256,
"width": 256,
"operations": [
["forceRenderCached", true],
["wait"],
["setPaintProperty", "fill", "fill-color", ["rgba", 117.0, 207.0, 0.0, 1.0 ]],
["wait", 0],
["wait", 350]
]
}
},
"center": [-113.26903, 35.9654],
"zoom": 11,
"pitch": 45,
"terrain": {
"source": "rgbterrain"
},
"sources": {
"rgbterrain": {
"type": "raster-dem",
"tiles": [
"local://tiles/{z}-{x}-{y}.terrain.png"
],
"maxzoom": 15,
"tileSize": 256
},
"geojson": {
"type": "geojson",
"data": {
"type": "Polygon",
"coordinates": [
[
[
-113.27384948730469,
35.962
],
[
-113.26421051269531,
35.962
],
[
-113.26421051269531,
35.97
],
[
-113.27384948730469,
35.97
],
[
-113.28412743652345,
35.964
],
[
-113.27384948730469,
35.962
]
]
]
}
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": [
"rgba",
117.00000762939453,
207.00001525878907,
240.00001525878907,
1.0
]
}
},
{
"id": "fill",
"type": "fill",
"source": "geojson",
"paint": {
"fill-color": "yellow"
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256,
"width": 256,
"operations": [
["forceRenderCached", true],
["wait"],
["setLayoutProperty", "fill", "visibility", "none"],
["wait", 0],
["wait", 350]
]
}
},
"center": [-113.26903, 35.9654],
"zoom": 11,
"pitch": 45,
"terrain": {
"source": "rgbterrain"
},
"sources": {
"rgbterrain": {
"type": "raster-dem",
"tiles": [
"local://tiles/{z}-{x}-{y}.terrain.png"
],
"maxzoom": 15,
"tileSize": 256
},
"geojson": {
"type": "geojson",
"data": {
"type": "Polygon",
"coordinates": [
[
[
-113.27384948730469,
35.962
],
[
-113.26421051269531,
35.962
],
[
-113.26421051269531,
35.97
],
[
-113.27384948730469,
35.97
],
[
-113.28412743652345,
35.964
],
[
-113.27384948730469,
35.962
]
]
]
}
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": [
"rgba",
117.00000762939453,
207.00001525878907,
240.00001525878907,
1.0
]
}
},
{
"id": "fill",
"type": "fill",
"source": "geojson",
"paint": {
"fill-color": "yellow"
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256,
"width": 256,
"operations": [
["forceRenderCached", true],
["wait"],
["setPaintProperty", "hillshade", "hillshade-exaggeration", 0.1],
["wait", 0],
["wait", 350]
]
}
},
"center": [-113.2935, 35.9529],
"zoom": 11.2,
"pitch": 30,
"terrain": {
"source": "terrain"
},
"sources": {
"terrain": {
"type": "raster-dem",
"tiles": [
"local://tiles/terrain-buffer-0/{z}-{x}-{y}.png"
],
"maxzoom": 15,
"tileSize": 256
}
},
"layers": [
{
"id": "hillshade",
"type": "hillshade",
"source": "terrain",
"paint": {
"hillshade-exaggeration": 1
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256,
"width": 256,
"operations": [
["forceRenderCached", true],
["wait"],
["removeLayer", "hillshade"],
["wait", 0],
["wait", 350]
]
}
},
"center": [-113.2935, 35.9529],
"zoom": 11.2,
"pitch": 30,
"terrain": {
"source": "terrain"
},
"sources": {
"terrain": {
"type": "raster-dem",
"tiles": [
"local://tiles/terrain-buffer-0/{z}-{x}-{y}.png"
],
"maxzoom": 15,
"tileSize": 256
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": [
"rgba",
117.00000762939453,
207.00001525878907,
240.00001525878907,
1.0
]
}
},
{
"id": "hillshade",
"type": "hillshade",
"source": "terrain",
"paint": {
"hillshade-exaggeration": 1
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading