Repository navigation
Bind only active attributes in order to avoid exceeding attribute limits - #9373
Conversation
| } | ||
|
|
||
| return Locations{ bindAttributeLocation( | ||
| id, locationToBindAttribute(activeAttributes, As::name()), As::name())... }; |
There was a problem hiding this comment.
This is close, but we want to number them in the order defined by the As argument pack, rather than lexicographical order by name. The latter might put an attribute that's sometimes disabled at location 0, which as we know, causes issues. Try this:
AttributeLocation location = 0;
return Locations {
(activeAttributes.count(As::name()) ? bindAttributeLocation(id, location++, As::name()) : -1)...
};|
|
||
| static Locations bindLocations(const ProgramID& id) { | ||
| return Locations { bindAttributeLocation(id, Index<As>, As::name())... }; | ||
| std::set<std::string> activeAttributes; |
There was a problem hiding this comment.
You can minimize the declarations and code here in the header by writing:
std::set<std::string> activeAttributes = getActiveAttributes(id);Then getActiveAttributes is the only thing that needs to be declared; everything else can go in the .cpp.
| namespace gl { | ||
|
|
||
| AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) { | ||
| MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name)); |
There was a problem hiding this comment.
Add assert(location <= 8) for good measure.
|
@lbud Currently crashes on android devices: |
…d as many attributes as are assigned locations
ivovandongen
left a comment
There was a problem hiding this comment.
Looks to be working well on the Nexus 4 now. Thanks!
|
One small thing I wanted to flag is that is that I had to make |
| } | ||
|
|
||
| template <class DrawMode> | ||
| static Bindings bindings(const VertexBuffer<Vertex, DrawMode>& buffer) { |
There was a problem hiding this comment.
Does anything actually fail if you don't make this change? In theory, this function is called only for active attributes. If it's called for an attribute that isn't actually present, then there's a bug somewhere I think.
There was a problem hiding this comment.
🤔 @jfirebaugh good question — I added it after this build, which was terminated during the render tests with
terminate called after throwing an instance of 'mbgl::gl::Error'
what(): glEnableVertexAttribArray(location): Error GL_INVALID_VALUE at ../../../src/mbgl/gl/attribute.cpp:62
(glEnableVertexAttribArray documentation)
But I was able to reproduce that error locally at the time using a fill-color property function, which now works locally if I remove it… I'll remove it and see if any of the CI builds still have issues.
There was a problem hiding this comment.
Actually, I spoke too soon — locally I get the same error:
libc++abi.dylib: terminating with uncaught exception of type mbgl::gl::Error: glEnableVertexAttribArray(location): Error GL_INVALID_VALUE at /Users/lbud/src/mapbox-gl-native/src/mbgl/gl/attribute.cpp:70
jfirebaugh
left a comment
There was a problem hiding this comment.
Ah, the attempt to bind at location -1 comes from the FillProgram, which includes fill-outline-color in its paint properties, but doesn't use it or have an a_outline_color attribute. Can you add a comment to the if (location == -1) return; explaining this? Looks good otherwise!
I think this fixes #9331, although I'm not sure how to go about testing on an older Android device.
This PR
uniformsStateandattributeLocationsin theProgramconstructor, so that the program is initially linked before callingattributeLocations,Attributes::bindLocationsto query active attributes, temporarily store a set of those attributes, and then manually bind only the active attributes, and