-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Bind only active attributes in order to avoid exceeding attribute limits #9373
Conversation
src/mbgl/gl/attribute.hpp
Outdated
} | ||
|
||
return Locations{ bindAttributeLocation( | ||
id, locationToBindAttribute(activeAttributes, As::name()), As::name())... }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)...
};
src/mbgl/gl/attribute.hpp
Outdated
@@ -242,7 +247,18 @@ class Attributes { | |||
static constexpr std::size_t Index = TypeIndex<A, As...>::value; | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/mbgl/gl/attribute.cpp
Outdated
namespace mbgl { | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add assert(location <= 8)
for good measure.
@lbud Currently crashes on android devices:
|
…d as many attributes as are assigned locations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
src/mbgl/gl/attribute.hpp
Outdated
@@ -255,8 +266,9 @@ class Attributes { | |||
} | |||
|
|||
template <class DrawMode> | |||
static Bindings bindings(const VertexBuffer<Vertex, DrawMode>& buffer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
uniformsState
andattributeLocations
in theProgram
constructor, so that the program is initially linked before callingattributeLocations
,Attributes::bindLocations
to query active attributes, temporarily store a set of those attributes, and then manually bind only the active attributes, and