Skip to content

Commit

Permalink
GL: use a single allocation instead of two in Shader::submitCompile().
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Dec 31, 2022
1 parent 1d3f50e commit 6e619fc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Magnum/GL/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,15 @@ bool Shader::compile() {
void Shader::submitCompile() {
CORRADE_ASSERT(_sources.size() > 1, "GL::Shader::compile(): no files added", );

/** @todo ArrayTuple/VLAs */
Containers::Array<const GLchar*> pointers(_sources.size());
Containers::Array<GLint> sizes(_sources.size());
/* Coalesce the two arrays into one allocation. Still worse than not
allocating anything, OTOH the driver (or at least Mesa) then performs
~45k allocations on its own, so this is just a drop in the ocean. */
Containers::ArrayView<const GLchar*> pointers;
Containers::ArrayView<GLint> sizes;
Containers::ArrayTuple data{
{NoInit, _sources.size(), pointers},
{NoInit, _sources.size(), sizes},
};

/* Upload sources of all shaders */
for(std::size_t i = 0; i != _sources.size(); ++i) {
Expand Down

0 comments on commit 6e619fc

Please sign in to comment.