Skip to content

Commit

Permalink
GL: avoid populating and sorting (!!) a vector of strings for exts.
Browse files Browse the repository at this point in the history
Ew. At first I tried to just port a growable Array of StringViews (which
would already save quite a lot), but then I realized I have a clear
upper bound on the extensions and so can use a "counting sort" without
having to deduplicate anything after.

After the previous (rather minimal) reduction by the Context cleanup,
this reduces the size of magnum-gl-info.wasm from 245 to 237 kB. Quite
significant, I'd say!
  • Loading branch information
mosra committed Mar 3, 2021
1 parent 32a7ade commit e96996e
Show file tree
Hide file tree
Showing 25 changed files with 242 additions and 163 deletions.
11 changes: 0 additions & 11 deletions src/Magnum/GL/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,6 @@ namespace GL {
namespace Implementation {
struct ContextState;
struct State;

enum: std::size_t {
ExtensionCount =
#ifndef MAGNUM_TARGET_GLES
192
#elif !defined(MAGNUM_TARGET_WEBGL)
160
#else
48
#endif
};
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/Magnum/GL/GL.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* @brief Forward declarations for the @ref Magnum::GL namespace
*/

#include <cstddef>

#include "Magnum/Types.h"

#ifndef DOXYGEN_GENERATING_OUTPUT
Expand All @@ -40,6 +42,20 @@ typedef unsigned int GLuint; /* Needed by Implementation/State.h */
namespace Magnum { namespace GL {

#ifndef DOXYGEN_GENERATING_OUTPUT
namespace Implementation {
/* Needed by Context as well as all Implementation::*State classes */
enum: std::size_t {
ExtensionCount =
#ifndef MAGNUM_TARGET_GLES
192
#elif !defined(MAGNUM_TARGET_WEBGL)
160
#else
48
#endif
};
}

/* FramebufferClear[Mask], FramebufferBlit[Mask], FramebufferBlitFilter,
FramebufferTarget enums used only directly with framebuffer instance */
class AbstractFramebuffer;
Expand Down
11 changes: 7 additions & 4 deletions src/Magnum/GL/Implementation/BufferState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ std::size_t BufferState::indexForTarget(Buffer::TargetHint target) {
CORRADE_INTERNAL_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */
}

BufferState::BufferState(Context& context, std::vector<std::string>& extensions): bindings()
BufferState::BufferState(Context& context, Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions): bindings()
#ifndef MAGNUM_TARGET_GLES2
#ifndef MAGNUM_TARGET_GLES
, minMapAlignment(0)
Expand All @@ -99,7 +99,8 @@ BufferState::BufferState(Context& context, std::vector<std::string>& extensions)
context.isDriverWorkaroundDisabled("intel-windows-crazy-broken-buffer-dsa"_s))
#endif
) {
extensions.emplace_back(Extensions::ARB::direct_state_access::string());
extensions[Extensions::ARB::direct_state_access::Index] =
Extensions::ARB::direct_state_access::string();

createImplementation = &Buffer::createImplementationDSA;
copyImplementation = &Buffer::copyImplementationDSA;
Expand Down Expand Up @@ -140,7 +141,8 @@ BufferState::BufferState(Context& context, std::vector<std::string>& extensions)

#ifndef MAGNUM_TARGET_GLES
if(context.isExtensionSupported<Extensions::ARB::invalidate_subdata>()) {
extensions.emplace_back(Extensions::ARB::invalidate_subdata::string());
extensions[Extensions::ARB::invalidate_subdata::Index] =
Extensions::ARB::invalidate_subdata::string();

invalidateImplementation = &Buffer::invalidateImplementationARB;
invalidateSubImplementation = &Buffer::invalidateSubImplementationARB;
Expand All @@ -154,7 +156,8 @@ BufferState::BufferState(Context& context, std::vector<std::string>& extensions)
#ifndef MAGNUM_TARGET_GLES2
#ifndef MAGNUM_TARGET_GLES
if(context.isExtensionSupported<Extensions::ARB::multi_bind>()) {
extensions.emplace_back(Extensions::ARB::multi_bind::string());
extensions[Extensions::ARB::multi_bind::Index] =
Extensions::ARB::multi_bind::string();

bindBasesImplementation = &Buffer::bindImplementationMulti;
bindRangesImplementation = &Buffer::bindImplementationMulti;
Expand Down
4 changes: 1 addition & 3 deletions src/Magnum/GL/Implementation/BufferState.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
DEALINGS IN THE SOFTWARE.
*/

#include <vector>

#include "Magnum/GL/Buffer.h"

namespace Magnum { namespace GL { namespace Implementation {
Expand All @@ -46,7 +44,7 @@ struct BufferState {
static std::size_t indexForTarget(Buffer::TargetHint target);
static const Buffer::TargetHint targetForIndex[TargetCount-1];

explicit BufferState(Context& context, std::vector<std::string>& extensions);
explicit BufferState(Context& context, Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions);

void reset();

Expand Down
2 changes: 1 addition & 1 deletion src/Magnum/GL/Implementation/ContextState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Magnum { namespace GL { namespace Implementation {

using namespace Containers::Literals;

ContextState::ContextState(Context& context, std::vector<std::string>&) {
ContextState::ContextState(Context& context, Containers::StaticArrayView<Implementation::ExtensionCount, const char*>) {
#ifndef MAGNUM_TARGET_GLES
if((context.detectedDriver() & Context::DetectedDriver::NVidia) &&
!context.isDriverWorkaroundDisabled("nv-zero-context-profile-mask"_s))
Expand Down
6 changes: 2 additions & 4 deletions src/Magnum/GL/Implementation/ContextState.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
DEALINGS IN THE SOFTWARE.
*/

#include <string>
#include <vector>

#include "Magnum/Magnum.h"
#include "Magnum/GL/GL.h"

#ifdef _MSC_VER
Expand All @@ -40,7 +38,7 @@
namespace Magnum { namespace GL { namespace Implementation {

struct ContextState {
explicit ContextState(Context& context, std::vector<std::string>& extensions);
explicit ContextState(Context& context, Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions);

#ifndef MAGNUM_TARGET_GLES
enum class CoreProfile {
Expand Down
17 changes: 11 additions & 6 deletions src/Magnum/GL/Implementation/DebugState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace Magnum { namespace GL { namespace Implementation {

DebugState::DebugState(Context& context, std::vector<std::string>& extensions):
DebugState::DebugState(Context& context, Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions):
maxLabelLength{0},
maxLoggedMessages{0},
maxMessageLength{0},
Expand All @@ -45,7 +45,8 @@ DebugState::DebugState(Context& context, std::vector<std::string>& extensions):
#endif
{
#ifndef MAGNUM_TARGET_GLES
extensions.emplace_back(Extensions::KHR::debug::string());
extensions[Extensions::KHR::debug::Index] =
Extensions::KHR::debug::string();
#endif

getLabelImplementation = &AbstractObject::getLabelImplementationKhrDesktopES32;
Expand All @@ -60,7 +61,8 @@ DebugState::DebugState(Context& context, std::vector<std::string>& extensions):
#endif
#ifdef MAGNUM_TARGET_GLES
if(context.isExtensionSupported<Extensions::KHR::debug>()) {
extensions.emplace_back(Extensions::KHR::debug::string());
extensions[Extensions::KHR::debug::Index] =
Extensions::KHR::debug::string();

getLabelImplementation = &AbstractObject::getLabelImplementationKhrES;
labelImplementation = &AbstractObject::labelImplementationKhrES;
Expand All @@ -74,7 +76,8 @@ DebugState::DebugState(Context& context, std::vector<std::string>& extensions):
#endif
{
if(context.isExtensionSupported<Extensions::EXT::debug_label>()) {
extensions.emplace_back(Extensions::EXT::debug_label::string());
extensions[Extensions::EXT::debug_label::Index] =
Extensions::EXT::debug_label::string();

getLabelImplementation = &AbstractObject::getLabelImplementationExt;
labelImplementation = &AbstractObject::labelImplementationExt;
Expand All @@ -84,14 +87,16 @@ DebugState::DebugState(Context& context, std::vector<std::string>& extensions):
}

if(context.isExtensionSupported<Extensions::EXT::debug_marker>()) {
extensions.emplace_back(Extensions::EXT::debug_marker::string());
extensions[Extensions::EXT::debug_marker::Index] =
Extensions::EXT::debug_marker::string();

pushGroupImplementation = &DebugGroup::pushImplementationExt;
popGroupImplementation = &DebugGroup::popImplementationExt;
messageInsertImplementation = &DebugMessage::insertImplementationExt;
#ifndef MAGNUM_TARGET_GLES
} else if(context.isExtensionSupported<Extensions::GREMEDY::string_marker>()) {
extensions.emplace_back(Extensions::GREMEDY::string_marker::string());
extensions[Extensions::GREMEDY::string_marker::Index] =
Extensions::GREMEDY::string_marker::string();

pushGroupImplementation = &DebugGroup::pushImplementationNoOp;
popGroupImplementation = &DebugGroup::popImplementationNoOp;
Expand Down
5 changes: 1 addition & 4 deletions src/Magnum/GL/Implementation/DebugState.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
DEALINGS IN THE SOFTWARE.
*/

#include <string>
#include <vector>

#include "Magnum/GL/DebugOutput.h"
#include "Magnum/GL/GL.h"

Expand All @@ -38,7 +35,7 @@
namespace Magnum { namespace GL { namespace Implementation {

struct DebugState {
explicit DebugState(Context& context, std::vector<std::string>& extensions);
explicit DebugState(Context& context, Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions);

std::string(*getLabelImplementation)(GLenum, GLuint);
void(*labelImplementation)(GLenum, GLuint, Containers::ArrayView<const char>);
Expand Down
Loading

0 comments on commit e96996e

Please sign in to comment.