Hello,
I've stumbled across an issue were Mesa failed to create a context when it's used as a opengl32 surrogate (from Qt). The weird thing was that the failure only happened on certain graphics hardware, even though Mesa was supposed to take over GL duties. As it turns out, the problem was the call to the GDI SetPixelFormat() function, which occasionally failed & broke the DC. The failure reason isn't quite clear, but it appears to be some sort of race condition, as everything works now and then, or when things happen with different timings.

Anyway, since Mesa is supposed to replace opengl32 entirely it seems appropriate to avoid calling GDI SetPixelFormat(). The code path that calls SetPixelFormat() will have set the pixel format in the Mesa-related structures, so GetPixelFormat() won't be called by the context creation anyway.

Thoughts on that? Does the reasoning sound sensible?

-f.r.
>From a0edbefb032c38a865870de779777570638cddf3 Mon Sep 17 00:00:00 2001
From: Frank Richter <frank.rich...@dynardo.de>
Date: Mon, 5 Nov 2018 11:42:55 +0100
Subject: [PATCH] gallium/wgl: Avoid calling SetPixelFormat if used as drop-in
 opengl32

If Mesa is used as a drop-in replacement GetPixelFormat() won't be called
from wglCreateContext() anyway, so we don't need to handle that case.
Also, this fixes issues where the SetPixelFormat() occasionally fails
and breaks the DC.
---
 src/gallium/state_trackers/wgl/stw_framebuffer.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c
index 232ab1d230..c578f97f65 100644
--- a/src/gallium/state_trackers/wgl/stw_framebuffer.c
+++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c
@@ -39,6 +39,7 @@
 #include "stw_winsys.h"
 #include "stw_tls.h"
 #include "stw_context.h"
+#include "stw_ext_context.h"
 #include "stw_st.h"
 
 
@@ -455,9 +456,12 @@ DrvSetPixelFormat(HDC hdc, LONG iPixelFormat)
    stw_framebuffer_unlock( fb );
 
    /* Some applications mistakenly use the undocumented wglSetPixelFormat
-    * function instead of SetPixelFormat, so we call SetPixelFormat here to
-    * avoid opengl32.dll's wglCreateContext to fail */
-   if (GetPixelFormat(hdc) == 0) {
+    * function instead of SetPixelFormat, so if we're used as an ICD
+    * call SetPixelFormat here to avoid opengl32.dll's wglCreateContext
+    * to fail.
+    * However, if used as a drop-in, avoid calling into opengl32.dll. */
+   if ((wglCreateContext_func != &wglCreateContext) &&
+       (GetPixelFormat(hdc) == 0)) {
       BOOL bRet = SetPixelFormat(hdc, iPixelFormat, NULL);
       if (!bRet) {
 	  debug_printf("SetPixelFormat failed\n");
-- 
2.17.2

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to