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

Clear tiles with zoom dependent line-width layers from the terrain render cache #12510

Merged
merged 4 commits into from
Jan 25, 2023

Conversation

stepankuzmin
Copy link
Contributor

@stepankuzmin stepankuzmin commented Jan 11, 2023

GL JS is not considering a line width change as a prerequisite to clear off tiles from the terrain render cache. Because of that, while zooming between two zoom levels, GL JS is using a stale zoom in getPixelsToTileUnitsMatrix during the entire range [z..z+1].

This fix clears tiles with zoom-dependent line-width layers from the terrain render cache. One thing that bugs me is that most Mapbox core styles use a composite source with zoom-dependant line layers. So we are basically disabling the terrain render cache for the composite source in core styles here.

Closes #11956

Benchmarks

After running benchmarks comparing the main branch with this PR, there is a regression in frameTimeAverage and percentDroppedFrames, see:

Before

before-line-width-fix.mov

After

after-line-width-fix.mov

Launch Checklist

  • briefly describe the changes in this PR
  • include before/after visuals or gifs if this PR includes visual changes
  • post benchmark scores
  • manually test the debug page
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>fix blur on draped lines while zoom-in</changelog>

Copy link
Contributor

@karimnaaji karimnaaji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good in itself, like you mentioned it's a bit worrisome to regress on performance with that change, putting the links to the benchmarks of the style for reference:

rendering-3d
Screen Shot 2023-01-20 at 11 53 23 AM
rendering-globe
Screen Shot 2023-01-20 at 11 53 31 AM

Screen Shot 2023-01-20 at 11 54 51 AM

Before going forward with this change, is there any alternative approach we could think about? For example, only trigger the render cache reload on larger/visible line-width differences (e.g. > 1/2px) in order to try and retain performance while still giving accurate results.

Otherwise, we should probably prefer the accuracy of the result and optimize this in the style itself.

@stepankuzmin
Copy link
Contributor Author

@karimnaaji I've tried an approach that @mourner suggested — to clear terrain render cache on map moveend. The line issue is still visible while the map is moving, but after the move ends, it clears the render cache, and lines are refined. According to the benchmark, the performance is much better (indeterminate compared to the version without the fix). What do you think of this approach?

this._style.map.on('moveend', () => {
this._clearTilesFromRenderCache();
});

https://sites.mapbox.com/benchmap-js-results/runs/1289
https://sites.mapbox.com/benchmap-js-results/runs/1290

@karimnaaji
Copy link
Contributor

@karimnaaji I've tried an approach that @mourner suggested — to clear terrain render cache on map moveend. The line issue is still visible while the map is moving, but after the move ends, it clears the render cache, and lines are refined.

Yes that's a good idea and seems like a good compromise, the benchmarks look good now 👍

src/terrain/terrain.js Outdated Show resolved Hide resolved
Copy link
Contributor

@karimnaaji karimnaaji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Fix looks good to me

@karimnaaji karimnaaji merged commit 18d719b into main Jan 25, 2023
@karimnaaji karimnaaji deleted the fix-11956 branch January 25, 2023 20:06
@stepankuzmin
Copy link
Contributor Author

Note: I've tried to cover the issue in the render test but couldn't reproduce it

test case
{
  "version": 8,
  "metadata": {
    "test": {
      "operations": [
        ["setProjection", "globe"],
        ["wait"],
        ["zoomTo", 2.9, {"duration": 2000}],
        ["wait"]
      ]
    }
  },
  "center": [0, 0],
  "zoom": 2.0,
  "pitch": 0,
  "bearing": 0,
  "sources": {
    "geojson": {
      "type": "geojson",
      "data": {
        "type": "MultiLineString",
        "coordinates": [
          [
            [
              0,
              20
            ],
            [
              20,
              0
            ],
            [
              0,
              -20
            ],
            [
              -20,
              0
            ],
            [
              0,
              20
            ]
          ]
        ]
      }
    }
  },
  "layers": [
    {
      "id": "background",
      "type": "background",
      "paint": {
        "background-color": "white"
      }
    },
    {
      "id": "line",
      "type": "line",
      "source": "geojson",
      "paint": {
        "line-width": 10,
        "line-opacity": 1
      }
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blur on draped lines inconsistent depending on zoom direction
2 participants