Bug 100668

Summary: No pixel formats with WGL_SWAP_UNDEFINED_ARB && WGL_DOUBLE_BUFFER_ARB=true
Product: Mesa Reporter: Charles Huber <genpfault>
Component: Mesa coreAssignee: mesa-dev
Status: RESOLVED NOTABUG QA Contact: mesa-dev
Severity: major    
Priority: medium CC: brianp, jfonseca
Version: 17.0   
Hardware: x86 (IA32)   
OS: Windows (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: Init WGL & show number of matching pixel formats

Description Charles Huber 2017-04-12 23:08:55 UTC
I'm using llvmpipe on Windows 7 x64, though LLVM & Mesa are built for 32-bit.

Requesting WGL_SWAP_UNDEFINED_ARB or WGL_SWAP_COPY_ARB in conjunction with WGL_DOUBLE_BUFFER_ARB = TRUE results in wglChoosePixelFormatARB() returning zero supported pixel formats.

These attributes work:

int pixel_attributes[] =
{
    WGL_SUPPORT_OPENGL_ARB, TRUE,
    WGL_DOUBLE_BUFFER_ARB, TRUE,
    0
};

These do not:

int pixel_attributes[] =
{
    WGL_SUPPORT_OPENGL_ARB, TRUE,
    WGL_DOUBLE_BUFFER_ARB, TRUE,
    WGL_SWAP_METHOD_ARB, WGL_SWAP_UNDEFINED_ARB,
    0
};

This is causing ANGLE to fail to get a valid pixel format when using Mesa as its OpenGL backend: https://chromium.googlesource.com/angle/angle.git/+/master/src/libANGLE/renderer/gl/wgl/wgl_utils.cpp#35
Comment 1 Charles Huber 2017-04-13 18:48:51 UTC
Created attachment 130833 [details]
Init WGL & show number of matching pixel formats
Comment 2 Brian Paul 2017-04-18 16:30:20 UTC
Hi Charles,

I compiled your test program and ran it with Mesa in a Windows VM and wglChoosePixelFormatARB failed to find a pixel format.  But I found the exact same failure when I ran it with NVIDIA's OpenGL driver on a Windows 7 system.

I also used the wglinfo utility to examine the double buffered pixel formats offered with NVIDIA's driver.  None of them use WGL_SWAP_UNDEFINED_ARB.  They're all tagged with either WGL_SWAP_EXCHANGE_ARB or WGL_SWAP_COPY_ARB.

I would expect that ANGLE is tested with NVIDIA's OpenGL driver, but I don't know how things could work with the ANGLE code I see.

When you specify WGL_SWAP_METHOD_ARB = WGL_SWAP_UNDEFINED_ARB you're asking for a very specific type of implementation of wglSwapBuffers().  Any given Windows OpenGL driver is free to implement any of the three swap methods.  AFAIK, none are required.  Note that WGL_SWAP_UNDEFINED_ARB doesn't mean "don't care".

Does ANGLE really require this specific type of buffer swap behavior?  If not, the WGL_SWAP_METHOD_ARB attribute should simply be omitted.
Comment 3 Charles Huber 2017-04-19 16:16:19 UTC
My guess is that the intent was to support eglChooseConfig()'s EGL_SWAP_BEHAVIOR_PRESERVED_BIT and eglSurfaceAttrib()'s EGL_BUFFER_PRESERVED/EGL_BUFFER_DESTROYED but currently GetDefaultPixelFormatAttributes()'s only caller unconditionally sets preservedSwap to false and always tries WGL_SWAP_UNDEFINED_ARB.

I'll file a bug on ANGLE's tracker and see if they like the "if preservedSwap == false -> omit WGL_SWAP_METHOD_ARB entirely" idea.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.