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

Ensure symbol shader attrib bound at 0 is always valid and used #4688

Merged
merged 3 commits into from
May 19, 2017

Conversation

lbud
Copy link
Contributor

@lbud lbud commented May 8, 2017

Fixes #4607.
@jfirebaugh found the culprit in Firefox: binding an attrib to position 0 without using it "forces the browser to do expensive emulation work when running on desktop OpenGL platforms, for example on Mac." In this case, a_size was frequently being bound to position 0 and was not always used. This PR manually binds a_data (which is always used — either this or a_pos_offset would work) to position 0, and then lets the program dynamically bind the rest.

Lauren Budorick added 3 commits May 8, 2017 13:51
(Binding unused/undefined attribs to position 0 causes symbols to not render in Safari)
@lbud lbud requested a review from jfirebaugh May 8, 2017 22:14
Copy link
Contributor

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

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

Ah, the old "don't disable attribute 0" gotcha. We've been bitten several times in the past by this. It would be good to come up with a test that fails if this regresses again. Would this have been hitting

but we just never caught it in a debug build?

In native our strategy is to explicitly bind everything with bindAttribLocation and a fixed order of attributes.

@lbud
Copy link
Contributor Author

lbud commented May 9, 2017

@jfirebaugh I haven't dug too far into it yet, but it appears it's not entering that branch because the OES_vertex_array_object (gl.extVertexArrayObject here) is present. Moreover, I'm not 100% clear on how the shader binding works but it appears that attrib positions are already determined by this point, having been dynamically/automatically assigned in painter.js.

It also appears that in Chrome on master when we rely on webgl to dynamically assign attribute locations (I think this happens in gl.linkProgram…?), a_data already happens to be assigned to position 0, whereas on Safari a_size is assigned to position 0, so I'm not sure that we'd even be able to reliably create a test for this, since we can't control browser environments on CI 🤕

It'd probably be a good idea to eventually take the same approach as native with explicit bindings.

@kkaefer
Copy link
Contributor

kkaefer commented May 10, 2017

I think this happens in gl.linkProgram…?

Yeah, if you don't define explicit bindings, it auto-assigns them when linking.

I'm not sure that we'd even be able to reliably create a test for this, since we can't control browser environments on CI

This is pretty hard to test. It only happens for me every 5-10 reloads of the map. When the labels are vanishing, the map is also really slow. Since this is a race condition we're trying to remove, I don't think there's a good way to test this. Even if we had a test, we'd only catch the error in a very limited number of test runs.

Longer term, it might make more sense to force explicit bindings, similar to how GL native does it.

@dagjomar
Copy link
Contributor

Anybody have time to review this? Waiting for the specific bugfix so we can upgrade the version :)

Copy link
Contributor

@anandthakker anandthakker left a comment

Choose a reason for hiding this comment

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

Sheesh. What a weird issue, nice catch.

@lbud lbud merged commit ca1d581 into master May 19, 2017
@lbud lbud deleted the 4607-symbol-attrib-order branch May 19, 2017 16:35
chrisvoll pushed a commit to chrisvoll/mapbox-gl-js that referenced this pull request May 25, 2017
…ox#4688)

Manually bind a_data at position 0 for symbolSDF shader. Binding unused/undefined attributes to position 0 causes symbols to not render in Safari.
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.

5 participants