After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 792407 - Windows: GL context sharing fails in async loading mode.
Windows: GL context sharing fails in async loading mode.
Status: RESOLVED NOTGNOME
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
1.12.4
Other Windows
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2018-01-10 15:48 UTC by Petros
Modified: 2018-03-27 00:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
async_load attempt (18.86 KB, text/plain)
2018-01-10 15:48 UTC, Petros
Details
sync_load success (1.36 MB, text/plain)
2018-01-10 15:49 UTC, Petros
Details

Description Petros 2018-01-10 15:48:36 UTC
Created attachment 366603 [details]
async_load attempt

Hi,

I m currently testing the GstPlayer implementation I ve written for Cinder [1] under Windows 10 [2] and I m hitting a snag.

The player so far has been battle tested on Linux which is my main development platform but also ( albeit less ) on macOS. I would also like to make it available under Windows but I m experiencing different behavior there.

More specifically the player works fine in sync loading mode after setting the uri to load on playbin. e.g.

gst_element_set_state( pipeline, GST_STATE_PAUSED  );
gst_element_get_state( pipeline, nullptr, nullptr, GST_CLOCK_TIME_NONE );

but not in async mode:

gst_element_set_state( pipeline, GST_STATE_PAUSED  );

In the second case it throws :

ERROR from element convert : failed to share contexts through wglShareLists 0xaa
Debugging info : gstglbasefilter.c(393): gst_gl_base_filter_decide_allocation (): /GstPlayBin:playbinsink/GstPlaySink:playsink/GstBin:vbin/GstBin:cinder-vbin/GstGLColorConvertElement:convert

Attached you can find an async_load attemt log and a successfull sync_load log both with GST_DEBUG=*gl*:7

Any hints would be greatly appreciated.

Cheers,
Petros

[1] https://github.com/cinder/Cinder/blob/master/src/cinder/linux/GstPlayer.cpp
[2] https://github.com/cinder/Cinder/pull/1947
Comment 1 Petros 2018-01-10 15:49:06 UTC
Created attachment 366604 [details]
sync_load success
Comment 2 Matthew Waters (ystreet00) 2018-01-11 23:55:43 UTC
This may be a condition of the wglShareLists() function that you're hitting that's explained in the comment at https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/ext/qt/gstqtglutility.cc#n213

The crux is that on windows, you need to make sure that the GL context one is sharing with is not current anywhere before attempting to share.  As such this is really a limitation of the GL drivers on Windows not providing proper wglCreateContextAttribsARB() support where this limitation does not apply.
Comment 3 Petros 2018-01-14 11:18:33 UTC
Thanks for your reply Matthew.

What puzzles me is that as can see from the logs wglCreateContextAttribsARB() seems to succeed in the case of the sync loading but fails in the async case where it tries to fallback to wglShareLists().

Relevant parts for sync case:

0:00:00.232938009  3816 000002237BFB9280 DEBUG               glwindow gstglwindow_win32.c:276:gst_gl_window_win32_create_window: gl window created: 5047178
0:00:00.233103134  3816 000002237BFB9280 LOG                 glwindow gstglwindow_win32.c:287:gst_gl_window_win32_create_window: Created a win32 window
0:00:00.237788218  3816 000002237BFB9280 INFO               glcontext gstglcontext.c:1231:gst_gl_context_create_thread:<glcontextwgl0> Attempting to create opengl context. user chosen api(s) (any), compiled api support (opengl opengl3) display api (any)
0:00:00.238253707  3816 000002237BFB9280 DEBUG              glcontext gstglcontext_wgl.c:174:gst_gl_context_wgl_create_context: gl context created: 65537
0:00:00.260883084  3816 000002237BFB9280 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.5 context
0:00:00.261583431  3816 000002237BFB9280 LOG                glcontext gstglcontext_wgl.c:261:gst_gl_context_wgl_create_context: gl context id: 131073
0:00:00.261605468  3816 000002237BFB9280 INFO               glcontext gstglcontext.c:1242:gst_gl_context_create_thread:<glcontextwgl0> created context
0:00:00.261623581  3816 000002237BFB9280 DEBUG              glcontext gstglcontext.c:749:gst_gl_context_activate:<glcontextwgl0> activate:1
0:00:00.262248158  3816 000002237BFB9280 INFO               glcontext gstglcontext.c:1258:gst_gl_context_create_thread:<glcontextwgl0> available GL APIs: opengl3
0:00:00.262269591  3816 000002237BFB9280 DEBUG              glcontext gstglcontext.c:1277:gst_gl_context_create_thread:<glcontextwgl0> Filling info
0:00:00.266241648  3816 000002237BFB9280 INFO               glcontext gstglcontext.c:1071:_create_context_info:<glcontextwgl0> GL_VERSION: 4.5.0 NVIDIA 382.66
0:00:00.266280892  3816 000002237BFB9280 INFO               glcontext gstglcontext.c:1074:_create_context_info:<glcontextwgl0> GL_SHADING_LANGUAGE_VERSION: 4.50 NVIDIA
0:00:00.266312287  3816 000002237BFB9280 INFO               glcontext gstglcontext.c:1076:_create_context_info:<glcontextwgl0> GL_VENDOR: NVIDIA Corporation
0:00:00.266385038  3816 000002237BFB9280 INFO               glcontext gstglcontext.c:1078:_create_context_info:<glcontextwgl0> GL_RENDERER: GeForce GTX 1080 Ti/PCIe/SSE2

and for the async case :

0:00:00.175514642 11992 0000022C62A4A280 LOG                 glwindow gstglwindow_win32.c:226:gst_gl_window_win32_create_window: Attempting to create a win32 window
0:00:00.176678366 11992 0000022C62A4A280 TRACE               glwindow gstglwindow_win32.c:394:window_proc: WM_CREATE
0:00:00.176752627 11992 0000022C62A4A280 DEBUG               glwindow gstglwindow_win32.c:276:gst_gl_window_win32_create_window: gl window created: 4131516
0:00:00.176780399 11992 0000022C62A4A280 LOG                 glwindow gstglwindow_win32.c:287:gst_gl_window_win32_create_window: Created a win32 window
0:00:00.180643480 11992 0000022C62A4A280 INFO               glcontext gstglcontext.c:1231:gst_gl_context_create_thread:<glcontextwgl0> Attempting to create opengl context. user chosen api(s) (any), compiled api support (opengl opengl3) display api (any)
0:00:00.181140969 11992 0000022C62A4A280 DEBUG              glcontext gstglcontext_wgl.c:174:gst_gl_context_wgl_create_context: gl context created: 65537
0:00:00.193910840 11992 0000022C62A4A280 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.5 context
0:00:00.194472024 11992 0000022C62A4A280 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.4 context
0:00:00.194989134 11992 0000022C62A4A280 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.3 context
0:00:00.195507149 11992 0000022C62A4A280 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.2 context
0:00:00.196016713 11992 0000022C62A4A280 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.1 context
0:00:00.196531408 11992 0000022C62A4A280 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.0 context
0:00:00.197033122 11992 0000022C62A4A280 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 3.3 context
0:00:00.197541176 11992 0000022C62A4A280 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 3.2 context
0:00:00.198905043 11992 0000022C62A4A280 WARN               glcontext gstglcontext.c:1235:gst_gl_context_create_thread:<glcontextwgl0> Failed to create context
0:00:00.198932815 11992 0000022C5CEBED40 INFO               glcontext gstglcontext.c:1037:gst_gl_context_create:<glcontextwgl0> gl thread created
0:00:00.198963606 11992 0000022C5CEBED40 WARN            glbasefilter gstglbasefilter.c:393:gst_gl_base_filter_decide_allocation:<convert> error: failed to share contexts through wglShareLists 0xaa

On top of that I tried the same code on Windows VM ( VMware with mesa drivers and Core Profile support enabled ) and there wglCreateContextAttribsARB() seems that its working properly for both the sync and the async case. Relevant parts of the log file :

0:00:00.632404185  7544 0000020741299580 LOG                 glwindow gstglwindow_win32.c:226:gst_gl_window_win32_create_window: Attempting to create a win32 window
0:00:00.643493634  7544 0000020741299580 TRACE               glwindow gstglwindow_win32.c:394:window_proc: WM_CREATE
0:00:00.644985625  7544 0000020741299580 DEBUG               glwindow gstglwindow_win32.c:276:gst_gl_window_win32_create_window: gl window created: 459564
0:00:00.648208861  7544 0000020741299580 LOG                 glwindow gstglwindow_win32.c:287:gst_gl_window_win32_create_window: Created a win32 window
0:00:00.650459284  7544 0000020741299580 INFO               glcontext gstglcontext.c:1231:gst_gl_context_create_thread:<glcontextwgl0> Attempting to create opengl context. user chosen api(s) (any), compiled api support (opengl opengl3) display api (any)
0:00:00.659322789  7544 0000020741299580 DEBUG              glcontext gstglcontext_wgl.c:174:gst_gl_context_wgl_create_context: gl context created: 65537
0:00:00.706056952  7544 0000020741299580 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.5 context
0:00:00.707850578  7544 0000020741299580 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.4 context
0:00:00.709045276  7544 0000020741299580 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.3 context
0:00:00.710477255  7544 0000020741299580 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.2 context
0:00:00.768884399  7544 0000020741299580 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.1 context
0:00:00.818529503  7544 0000020741299580 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 4.0 context
0:00:00.834999435  7544 0000020741299580 DEBUG              glcontext gstglcontext_wgl.c:212:gst_gl_context_wgl_create_context:<glcontextwgl0> trying to create a GL 3.3 context
0:00:00.871651707  7544 0000020741299580 LOG                glcontext gstglcontext_wgl.c:261:gst_gl_context_wgl_create_context: gl context id: 327681
0:00:00.872887860  7544 0000020741299580 INFO               glcontext gstglcontext.c:1242:gst_gl_context_create_thread:<glcontextwgl0> created context
0:00:00.873748548  7544 0000020741299580 DEBUG              glcontext gstglcontext.c:749:gst_gl_context_activate:<glcontextwgl0> activate:1
0:00:00.875465581  7544 0000020741299580 INFO               glcontext gstglcontext.c:1258:gst_gl_context_create_thread:<glcontextwgl0> available GL APIs: opengl3
0:00:00.876377989  7544 0000020741299580 DEBUG              glcontext gstglcontext.c:1277:gst_gl_context_create_thread:<glcontextwgl0> Filling info
0:00:00.885748036  7544 0000020741299580 INFO               glcontext gstglcontext.c:1071:_create_context_info:<glcontextwgl0> GL_VERSION: 3.3 (Core Profile) Mesa 10.6.0 (git-beb7765)
0:00:00.886978662  7544 0000020741299580 INFO               glcontext gstglcontext.c:1074:_create_context_info:<glcontextwgl0> GL_SHADING_LANGUAGE_VERSION: 3.30
0:00:00.889731284  7544 0000020741299580 INFO               glcontext gstglcontext.c:1076:_create_context_info:<glcontextwgl0> GL_VENDOR: VMware, Inc.
0:00:00.891676912  7544 0000020741299580 INFO               glcontext gstglcontext.c:1078:_create_context_info:<glcontextwgl0> GL_RENDERER: Gallium 0.4 on SVGA3D; build: RELEASE;  LLVM;

These tests make me wonder if I m hitting some kind of driver issue. 

In any case, I would like to provide proper fallback support when wglCreateContextAttribsARB() fails so my question would be at which point exactly should one disable and then (re)enable the application context ( in this case the one coming from Cinder ) on a playbin - appsink based pipeline so that wglShareLists() doesn't fail when GStreamer tries to setup/share the context internally ?

Thanks again!
Comment 4 Matthew Waters (ystreet00) 2018-01-14 12:36:31 UTC
(In reply to Petros from comment #3)
> In any case, I would like to provide proper fallback support when
> wglCreateContextAttribsARB() fails so my question would be at which point
> exactly should one disable and then (re)enable the application context ( in
> this case the one coming from Cinder ) on a playbin - appsink based pipeline
> so that wglShareLists() doesn't fail when GStreamer tries to setup/share the
> context internally ?

Step 1 is to figure out why wglCreateContextAttribsARB fails exactly. This situation might be avoidable for the NVIDIA drivers.  Failing that, a bug with NVIDIA with might be prudent to get this fixed at the source.

As for a workaround, the only real way to know when the GL context has been created is by overriding the 'create-context' signal on GstGLDisplay and creating the GL context there with the cinder GL context not current.
Comment 5 Gordon Nickel 2018-03-26 15:47:06 UTC
(In reply to Matthew Waters (ystreet00) from comment #4)
> (In reply to Petros from comment #3)
> > In any case, I would like to provide proper fallback support when
> > wglCreateContextAttribsARB() fails so my question would be at which point
> > exactly should one disable and then (re)enable the application context ( in
> > this case the one coming from Cinder ) on a playbin - appsink based pipeline
> > so that wglShareLists() doesn't fail when GStreamer tries to setup/share the
> > context internally ?
> 
> Step 1 is to figure out why wglCreateContextAttribsARB fails exactly. This
> situation might be avoidable for the NVIDIA drivers.  Failing that, a bug
> with NVIDIA with might be prudent to get this fixed at the source.
> 
> As for a workaround, the only real way to know when the GL context has been
> created is by overriding the 'create-context' signal on GstGLDisplay and
> creating the GL context there with the cinder GL context not current.

Hi Matt, I'm working with the same source as Petros, and was able to get async state changes working by using your suggestion of override the 'create-context' signal. However, the only way it would work was to manually create a context using gst_gl_context_new and share it with the main openGL context using gst_gl_context_create. This introduces an approximately 1.5-2.0 second delay in the main thread while the GstGLContext is created. Are there any ways to avoid that delay or speed it up?

Here's the relevant context creation code (sGstAsyncContext is returned for the create-context signal later): 
if(!sGstGLDisplay)
	sGstGLDisplay = gst_gl_display_new();
else
	holdDisplayRef = true;
ci::gl::env()->makeContextCurrent(nullptr);
auto platformData = std::dynamic_pointer_cast<ci::gl::PlatformDataMsw>(ci::gl::context()->getPlatformData());
mGstData.context = gst_gl_context_new_wrapped(sGstGLDisplay, (guintptr)platformData->mGlrc, GST_GL_PLATFORM_WGL, GST_GL_API_OPENGL);

if(sEnableAsyncStateChange && !sGstAsyncContext) {
	if(!sGstAsyncContext) {
		sGstAsyncContext = gst_gl_context_new(sGstGLDisplay);
		GError* err = NULL;
		if(!gst_gl_context_create(sGstAsyncContext, mGstData.context, &err) && err) {
			//g_printerr("Context not created with error " << err->code << " " << err->domain << " " << err->message);
		}
	} else {
		gst_object_ref(sGstAsyncContext);
	}
}
Comment 6 Matthew Waters (ystreet00) 2018-03-27 00:52:33 UTC
There's not much that I can say without profiling the context creation.  I would assume that the delay is caused by the GL driver for a myriad of reasons.

In any case, I think we can say this isn't really a GStreamer bug but a lacklustre support of wglCreateContextAttribsARB() by the GL driver and status quo for the platform when hitting the fallback.