From b8cec8de172e9aa0988d44aa966a062b80c126c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 31 Dec 2022 18:04:29 +0100 Subject: [PATCH] GL: use a single allocation instead of two in Shader::submitCompile(). --- src/Magnum/GL/Shader.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Magnum/GL/Shader.cpp b/src/Magnum/GL/Shader.cpp index 63c28da34..cb690f7bc 100644 --- a/src/Magnum/GL/Shader.cpp +++ b/src/Magnum/GL/Shader.cpp @@ -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 pointers(_sources.size()); - Containers::Array 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 pointers; + Containers::ArrayView 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) {