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

Fix label clipping by switching to layer-by-layer rendering #1727

Closed
wants to merge 56 commits into from

Conversation

lucaswoj
Copy link
Contributor

@lucaswoj
Copy link
Contributor Author

There's still a chunk of work to be done here but rendering is already so much smoother than master

@mourner
Copy link
Member

mourner commented Nov 14, 2015

command npm run preinstall && npm update && npm run postinstall && npm run prepublish took more than 120 minutes to run

Oh wow, wtf.

@yhahn
Copy link
Member

yhahn commented Nov 16, 2015

😮

@mourner
Copy link
Member

mourner commented Nov 16, 2015

I spent a long time trying to do the rebase without squashing but it was really difficult due to broken intermediate states.

When I did a similar thing for the earcut branch, it was much easier to manually look through the old PR bit by bit and enter the changes manually on a fresh master-based branch. Rebasing is hell on very outdated branches, and even if you end up making it work, there's still a lot of broken stuff usually.

@lucaswoj lucaswoj force-pushed the layer-by-layer2 branch 2 times, most recently from 55c6178 to 1eb900c Compare November 16, 2015 20:30
@lucaswoj
Copy link
Contributor Author

It looks like symbol render order (namely, overlapping symbols within the same layer) is going different with layer-by-layer rendering. This might be acceptable for our users but is not acceptable for mapbox-gl-test-suite.

@jfirebaugh
Copy link
Contributor

Symbols should be z-ordered by y coordinate. AFAIK, both gl-js and native (which already uses layer-by-layer rendering) agree on this currently; if this PR changes the ordering in gl-js, it's probably a bug.

@lucaswoj
Copy link
Contributor Author

Ah! Ok. I didn't know there was a deterministic symbol rendering order. I'll keep working on that one.

Some other test-suite failures appear to be headless-gl specific. They are not replicable in the browser. This one occurs whether we pull in earcut or not.

Test Suite

screen shot 2015-11-16 at 2 57 10 pm

Browser

screen shot 2015-11-16 at 2 57 27 pm

@lucaswoj lucaswoj force-pushed the layer-by-layer2 branch 2 times, most recently from db9f830 to b8f057b Compare November 18, 2015 00:26
@lucaswoj
Copy link
Contributor Author

I'm pleased to report that the fill rendering problems are resolved now (along with a number of other problems). This is shaping up nicely!

UPDATE: nope 👎

@lucaswoj lucaswoj force-pushed the layer-by-layer2 branch 2 times, most recently from b0446ce to 7e467ea Compare November 24, 2015 20:12
@lucaswoj
Copy link
Contributor Author

Interesting clue on the disappearing fills: rendering all fills during the "translucent" pass fixes almost all of the fill test cases.

@lucaswoj
Copy link
Contributor Author

lucaswoj commented Dec 8, 2015

I think I'm onto something -- not rendering background layers fixes most of the rendering problems in test-suite.

@lucaswoj
Copy link
Contributor Author

lucaswoj commented Dec 8, 2015

While I still can't reproduce the exact rendering errors that I'm seeing in headless-gl, I have stumbled across a test case that produces seemingly-related wrong behavior in the browser. These two styles render exactly the same, even though their layer order is reversed.

{
    "version": 8,
    "sources": {
      "mapbox": {
          "type": "vector",
          "url": "mapbox://mapbox.mapbox-streets-v6"
      }
    },
    "layers": [{
        "id": "background",
        "type": "background",
        "paint": {
            "background-color": "red"
        }
    },
    {
        "id": "water",
        "type": "fill",
        "source": "mapbox",
        "source-layer": "water",
        "paint": {
            "fill-color": "blue",
            "fill-antialias": false
        }
    }]
}
{
    "version": 8,
    "sources": {
      "mapbox": {
          "type": "vector",
          "url": "mapbox://mapbox.mapbox-streets-v6"
      }
    },
    "layers": [{
        "id": "water",
        "type": "fill",
        "source": "mapbox",
        "source-layer": "water",
        "paint": {
            "fill-color": "blue",
            "fill-antialias": false
        }, {
        "id": "background",
        "type": "background",
        "paint": {
            "background-color": "red"
        }
    }]
}

@lucaswoj lucaswoj force-pushed the layer-by-layer2 branch 2 times, most recently from 171a425 to 81f653b Compare December 10, 2015 00:57
@lucaswoj
Copy link
Contributor Author

only 25 failing test-suite tests ❗

@lucaswoj
Copy link
Contributor Author

Before optimization, FPS perf seems pretty good

duration: 3000
44.3 fps https://api.tiles.mapbox.com/mapbox-gl-js/v0.10.0/mapbox-gl.js
52.2 fps https://api.tiles.mapbox.com/mapbox-gl-js/v0.12.1/mapbox-gl.js
48.5 fps /dist/mapbox-gl.js
43.8 fps https://api.tiles.mapbox.com/mapbox-gl-js/v0.10.0/mapbox-gl.js
50.9 fps https://api.tiles.mapbox.com/mapbox-gl-js/v0.12.1/mapbox-gl.js
49.6 fps /dist/mapbox-gl.js

@lucaswoj lucaswoj changed the title Implement layer by layer rendering redux [DO NOT MERGE] Fix label clipping by switching to layer-by-layer rendering Dec 12, 2015
@lucaswoj lucaswoj force-pushed the layer-by-layer2 branch 2 times, most recently from 9ff71c8 to 7715e51 Compare December 16, 2015 22:27
@lucaswoj
Copy link
Contributor Author

This is ready for some serious 👀 @mourner @jfirebaugh @ansis @tmcw @kkaefer.

@lucaswoj
Copy link
Contributor Author

If you want to follow the full commit history, it begins at #1197

@@ -81,7 +81,7 @@ function Bucket(options) {
* @private
*/
Bucket.prototype.addFeatures = function() {
for (var i = 0; i < this.features.length; i++) {
for (var i = this.features.length - 1; i >= 0; i--) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the iteration order reversed here (and in LineBucket)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we are using the gl.ONE_MINUS_DST_ALPHA blending function, features are effectively rendered in reverse order.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. Native does not work this way. It iterates forward.

If this is affecting rendering there must be some other difference between native and JS that is reversed.

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 will spend some more time trying to understand this, I don't have an immediate explanation. This is what I had to do to make test-suite pass 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This reversal might lead to some rendering bugs. While rendering order is reversed during translucent passes, it is in the expected order during opaque passes.

Copy link
Contributor

Choose a reason for hiding this comment

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

The reverse iteration here makes the rendered order of features more similar to the previous rendered order, but that previous order was arbitrary. I think it should be safe to remove this and update the render tests.

ansis added 2 commits January 4, 2016 14:42
The reversal made rendering more similar to previous rendering
but the previous order was completely arbitrary.
@ansis
Copy link
Contributor

ansis commented Jan 5, 2016

squashed, rebased and merged in #1886

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

Successfully merging this pull request may close these issues.

Labels slipping/cropping at tile bounds
5 participants