This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Remove re-linking programs approach (#14482)
Remove re-linking programs as redundant. It costs (cheaper to link once than twice) and (subjective) is not that common GL API usage pattern, although perfectly legal and permitted. Initial idea, behind the removed code, was to enable work on optimization that would reduce number of attrib setup calls in case when VAO is not available (as described in #9433). As such optimization is not implemented, and it is arguable if it makes sense to do it now, we can remove re-linking. Related to closed PRs #9433 and PR #11583. I have [measured the time spent just on relinking](https://gist.github.com/astojilj/29bd5a5c5dc0b2d9f29ecb660da07fbf) using release build on iPhone SE (A9, same as iPhone 6S): - 1st run after reboot or installation Total 37.14ms, average per program:1.86ms - reopening Total: 2.47ms, average per program: 0.12ms This time we save using the patch here.
- Loading branch information
Showing
5 changed files
with
35 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,19 @@ | ||
#include <mbgl/gl/attribute.hpp> | ||
#include <mbgl/gl/context.hpp> | ||
#include <mbgl/gl/defines.hpp> | ||
|
||
namespace mbgl { | ||
namespace gl { | ||
|
||
using namespace platform; | ||
|
||
void bindAttributeLocation(Context& context, ProgramID id, AttributeLocation location, const char* name) { | ||
// We're using sequentially numberered attribute locations starting with 0. Therefore we can use | ||
// the location as a proxy for the number of attributes. | ||
if (location >= context.maximumVertexBindingCount) { | ||
// Don't bind the location on this hardware since it exceeds the limit (otherwise we'd get | ||
// an OpenGL error). This means we'll see rendering errors, and possibly slow rendering due | ||
// to unbound attributes. | ||
optional<AttributeLocation> queryLocation(ProgramID id, const char* name) { | ||
GLint attributeLocation = MBGL_CHECK_ERROR(glGetAttribLocation(id, name)); | ||
if (attributeLocation != -1) { | ||
return attributeLocation; | ||
} else { | ||
MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name)); | ||
return {}; | ||
} | ||
} | ||
|
||
std::set<std::string> getActiveAttributes(ProgramID id) { | ||
std::set<std::string> activeAttributes; | ||
|
||
GLint attributeCount; | ||
MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &attributeCount)); | ||
|
||
GLint maxAttributeLength; | ||
MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeLength)); | ||
|
||
std::string attributeName; | ||
attributeName.resize(maxAttributeLength); | ||
|
||
GLsizei actualLength; | ||
GLint size; | ||
GLenum type; | ||
|
||
for (int32_t i = 0; i < attributeCount; i++) { | ||
MBGL_CHECK_ERROR(glGetActiveAttrib(id, i, maxAttributeLength, &actualLength, &size, &type, &attributeName[0])); | ||
activeAttributes.emplace(std::string(attributeName, 0, actualLength)); | ||
} | ||
|
||
return activeAttributes; | ||
} | ||
|
||
} // namespace gl | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters