SetPixelFormat() delay

Hello everybody,

Until yesterday, when initializing an OpenGL application, I was ok with functions such as SetPixelFormat() / DescribePixelFormat() / ChoosePixelFormat() taking about 1 second before returning, the first time one of these was called in my application. No problem, that was something that was done once during the initialization and that was fine.

Then yesterday I bought and downloaded a debugging software (remedybg debugger) and saw that the application loads instantly. I open remedybg and I instantly see the nice hardware rasterized ImGui interface with no delay at all.

I was wondering if anyone knows of some reason why those functions (SetPixelFormat, etc) could take longer under some circumstances. I have been playing with some compilation flags, I have been also trying to change some window class and window creation flags, all without success. I know maybe for many people 1 second delay is not of much concern in this situation, but now that I know that instant application initialization and context creation is possible I cannot ignore the fact that things can be done better!!!

I have seen other topics with similar title to this one, explaining that it was probably an issue related to the driver implementation, or a virus issue, or something regarding windows making some operations while the applicationm runs, firewall, etc. Given the fact that I have another application working the way I would expect, I think these cannot be the causes of that problem. As a last remark I’ve checked the dll dependencies of remedybg and seen that it is using dx11 instead of OpenGL. Does anybody know if there is a noticeable diference in this initialization issue when it comes to using OpenGL or DX?

Summarizing, if anyone knows about this and can cast some light on the fact that SetPixelFormat() and these functions are so slow I would greatly appreciate it.

I was curious about your post, so I did some timing here with a recent NVidia GPU and drivers.

After several consecutive runs, here’s what I see:

 520.0 msec = ChoosePixelFormat
   0.1 msec = SetPixelFormat
   0.1 msec = wglGetPixelFormatAttribivARB (Query num formats)
  16.2 msec = wglGetPixelFormatAttribivARB (Query each of all 670 formats) 
  13.8 msec = wglChoosePixelFormatARB

Websearching around, this is a well-known issue.

Apparently, in the first call to a *PixelFormat API, the display system and/or graphics driver does quite a bit of loading and setup.

A few links on this. See the first one in particular:

Based on this, my suspicion is that when running your app under an instrumented debugger, the debugger may have already “taken the hit” of initializing the connection to the graphics driver for you, so that what you perceive as your app’s init is fast. But that’s a guess.

Thank you very much for your detailed answer! I didn’t actually find that link at handmade hero’s. My measurements are similar to yours, approx. half a second takes to the first *PixelFormat function that is executed. It’s really annoying. Seems like a driver issue to me. Regarding the debugger I mentioned before, it is not my application executing under that debugger, but the debugger itself which loads instantly (when I run my application under that debugger, it takes the same half a second until *PixelFormat() finishes). This debugger’s interface is rendered using dx11, so I’m really thinking this whole *PixelFormat() delay issue must have something to do with this specific nvidia’s OpenGL driver implementation. I don’t own myself hardware from other vendors which use different drivers, but I’ve read that the same problem seems to appear in AMD cards… so I don’t know.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.