Allegro.cc - Online Community
Post Reply

Allegro.cc Forums » Allegro Development » slow detection of GL extensions on some hardware

rss feed Print
slow detection of GL extensions on some hardware
tobing
Member #5,213
November 2004
avatar

Hi, recently I switched my setup to use a 4k monitor next to the laptop, desktop is extended to two screens. You know, home office and such things.

I found that OpenGL usage becomes really slow during startup, so I did some debugging. The slow function is

is_wgl_extension_supported()
{
   // some code
   _wglGetExtensionsStringARB = (_ALLEGRO_wglGetExtensionsStringARB_t)
      wglGetProcAddress("wglGetExtensionsStringARB");
   // more code
}

and some google search revealed, that it seems to be a known problem for some graphics cards and some drivers, but unknown reasons, that the detection of gl extensions is really slow. Nonetheless, somebody hinted to not call this in a loop anyways, but that's what allegro is doing in

read_pixel_format_ext

called by

get_available_pixel_formats_ext()
{
   // some code
   for (j = i = 0; i < maxindex; i++) {
      ALLEGRO_INFO("-- \n");
      ALLEGRO_INFO("Decoding visual no. %i...\n", i+1);
      eds_list[j] = read_pixel_format_ext(i, testdc);
      // more code
   }
   // more code
}

so I changed is_wgl_extension_supported to get the proc address only once and reuse it:

#SelectExpand
1static bool is_wgl_extension_supported(const char *extension, HDC dc) 2{ 3 static _ALLEGRO_wglGetExtensionsStringARB_t _wglGetExtensionsStringARB; 4 static ext_is_initialized = false; // this is a simple blocker, would not be safe for multi-threading 5 int ret; 6 7 /* XXX deprecated in OpenGL 3.0 */ 8 if (!glGetString(GL_EXTENSIONS)) 9 return false; 10 11 if(!ext_is_initialized) 12 { 13 _wglGetExtensionsStringARB = (_ALLEGRO_wglGetExtensionsStringARB_t) 14 wglGetProcAddress("wglGetExtensionsStringARB"); 15 ext_is_initialized = true; 16 } 17 if (!_wglGetExtensionsStringARB) 18 return false; 19 20 ret = _al_ogl_look_for_an_extension(extension, 21 (const GLubyte*)_wglGetExtensionsStringARB(dc)); 22 23 return ret; 24}

but I'm not sure, iff that would work for all compilers, because it's not old-style-enough, I guess. I'm really much going modern C++ these days, so I forgot how to write it properly for allegro...

And it does the trick, now there's less than a second and allegro is up. As they said in the but report I found, that is still WAY too long, as long as it's not called in a loop, I can live with it.

So maybe one of the Windows / OpenGL experts can apply this or a similar change to wgl_disp.c? Or even other places with similar patterns?

SiegeLord
Member #7,827
October 2006
avatar

Looks good to me, let's ship it (https://github.com/liballeg/allegro5/issues/1125).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

tobing
Member #5,213
November 2004
avatar

Here's a patch, I haven't forked allegro (yet), so I think I can't just create a pull request.

Thanks in advance!

#SelectExpand
1From 4d45eb36f0873f48672f02328693872c86a55815 Mon Sep 17 00:00:00 2001 2From: Tobias Scheuer <tobias@scheuer42.de> 3Date: Sun, 29 Mar 2020 12:24:59 +0200 4Subject: [PATCH] initialize wgl extension string only once 5 6--- 7 src/win/wgl_disp.c | 11 ++++++++--- 8 1 file changed, 8 insertions(+), 3 deletions(-) 9 10diff --git a/src/win/wgl_disp.c b/src/win/wgl_disp.c 11index b8e0878fc..893d56041 100644 12--- a/src/win/wgl_disp.c 13+++ b/src/win/wgl_disp.c 14@@ -68,15 +68,20 @@ typedef struct WGL_DISPLAY_PARAMETERS { 15 16 static bool is_wgl_extension_supported(const char *extension, HDC dc) 17 { 18- _ALLEGRO_wglGetExtensionsStringARB_t _wglGetExtensionsStringARB; 19+ static _ALLEGRO_wglGetExtensionsStringARB_t _wglGetExtensionsStringARB; 20+ static ext_is_initialized = false; // this is a simple blocker, would not be safe for multi-threading 21 int ret; 22 23 /* XXX deprecated in OpenGL 3.0 */ 24 if (!glGetString(GL_EXTENSIONS)) 25 return false; 26 27- _wglGetExtensionsStringARB = (_ALLEGRO_wglGetExtensionsStringARB_t) 28- wglGetProcAddress("wglGetExtensionsStringARB"); 29+ if(!ext_is_initialized) 30+ { 31+ _wglGetExtensionsStringARB = (_ALLEGRO_wglGetExtensionsStringARB_t) 32+ wglGetProcAddress("wglGetExtensionsStringARB"); 33+ ext_is_initialized = true; 34+ } 35 if (!_wglGetExtensionsStringARB) 36 return false; 37 38-- 392.24.1.windows.2

Post Reply
Go to: