Problem with context sharing (glupload) with an OVR thread (Oculus Mobile SDK)

Matthew Waters ystreet00 at gmail.com
Tue Feb 20 02:05:09 UTC 2018


On 20/02/18 09:52, jeremi.wojcicki wrote:
> I have used GAPID tool for OpenGL debugging (which actually is quite an
> awesome tool) and I have confirmed that indeed gstreamer creates a new GL
> context with eglCreateContext but with share_context as NULL. This means
> that for some reasons the context I provide, using methods shown in sdlshare
> and sdlshare2 examples, is ignored.
>
> <http://gstreamer-devel.966125.n4.nabble.com/file/t377800/gapid.png> 
>
> This slightly narrows down the problem, but I still don't get what is the
> reason. Looking into the gstglcontext_egl.c I don't see a clear point in
> which the "other_context" could be stripped:
>
> static gboolean
> gst_gl_context_egl_create_context (GstGLContext * context,
>     GstGLAPI gl_api, GstGLContext * other_context, GError ** error)
> {
>   GstGLContextEGL *egl;
>   GstGLWindow *window = NULL;
>   EGLNativeWindowType window_handle = (EGLNativeWindowType) 0;
>   EGLint majorVersion;
>   EGLint minorVersion;
>   gboolean need_surface = TRUE;
>   guintptr external_gl_context = 0;
>   GstGLDisplay *display;
>
>   egl = GST_GL_CONTEXT_EGL (context);
>   window = gst_gl_context_get_window (context);
>
>   GST_DEBUG_OBJECT (context, "Creating EGL context");
>
>   if (other_context) { 
> // ======= I don’t know if other_context is != NULL at this point, but it is
> quite possible
>     
>     if (gst_gl_context_get_gl_platform (other_context) !=
> GST_GL_PLATFORM_EGL) {
>       g_set_error (error, GST_GL_CONTEXT_ERROR,
>           GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
>           "Cannot share context with non-EGL context");
> // ======== I don’t reach this point
>       goto failure;
>     }
>     external_gl_context = gst_gl_context_get_gl_context (other_context);
>   }
>
>   if ((gl_api & (GST_GL_API_OPENGL | GST_GL_API_OPENGL3 | GST_GL_API_GLES2))
> ==
>       GST_GL_API_NONE) {
>
> ...
> // =========== OPENGL case – not relevant
> ...
>
>
>   } else if (gl_api & GST_GL_API_GLES2) {
>     gint i;
>
>   try_gles2:
>     if (!eglBindAPI (EGL_OPENGL_ES_API)) {
>       g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
>           "Failed to bind OpenGL|ES API: %s",
>           gst_gl_context_egl_get_error_string (eglGetError ()));
>       goto failure;
>     }
>
> // ============ I get this message
>
>     GST_INFO ("Bound OpenGL|ES"); 
>
>
>     for (i = 0; i < G_N_ELEMENTS (gles2_versions); i++) {
>       gint profileMask = 0;
>       gint contextFlags = 0;
>
>       if (!gst_gl_context_egl_choose_config (egl, GST_GL_API_GLES2,
>               gles2_versions[i].major, error)) {
>         continue;
>       }
> #if defined(EGL_KHR_create_context)
>       /* try a debug context */
>       contextFlags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
>
>       egl->egl_context =
>           _create_context_with_flags (egl, (EGLContext) external_gl_context,
>           GST_GL_API_GLES2, gles2_versions[i].major,
>           gles2_versions[i].minor, contextFlags, profileMask);
>
>       if (egl->egl_context)
>         break;
>
>       /* try without a debug context */
>       contextFlags &= ~EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
> #endif
>
>       egl->egl_context =
>           _create_context_with_flags (egl, (EGLContext) external_gl_context,
>           GST_GL_API_GLES2, gles2_versions[i].major,
>           gles2_versions[i].minor, contextFlags, profileMask);
>
>       if (egl->egl_context)
>         break;
>     }
>     egl->gl_api = GST_GL_API_GLES2;
>   }
>
>   if (egl->egl_context != EGL_NO_CONTEXT) {
> // ====== I get this message
>     GST_INFO ("gl context created: %" G_GUINTPTR_FORMAT,
>         (guintptr) egl->egl_context); 
>   } else {
>     g_set_error (error, GST_GL_CONTEXT_ERROR,
>         GST_GL_CONTEXT_ERROR_CREATE_CONTEXT,
>         "Failed to create a OpenGL context: %s",
>         gst_gl_context_egl_get_error_string (eglGetError ()));
>     goto failure;
>   }
>
> Just for reference, I share the current version of context setting (in the
> bus need-context callback):
>
>         case GST_MESSAGE_NEED_CONTEXT:
>         {
>
>             // we got gl_display and gl_context and starting of the main
> loop
>
>             GstElement *element = GST_ELEMENT (message->src);
>             const gchar *name = gst_element_get_name(element);
>
>             LOG_INFO("Element %s asks for context. We give => 0x%08x
> 0x%08x", name, data->egl_context, data->egl_display);
>
>             const gchar *context_type;
>
>             gst_message_parse_context_type (message, &context_type);
>             g_print ("got need context %s\n", context_type);
>
>             if (g_strcmp0 (context_type, GST_GL_DISPLAY_CONTEXT_TYPE) == 0)
> {
>                 GstContext *display_context =
>                         gst_context_new (GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
>                 gst_context_set_gl_display (display_context,
> data->gst_display);
>                 gst_element_set_context (GST_ELEMENT (message->src),
> display_context);
>                 return TRUE;
>             } else if (g_strcmp0 (context_type, "gst.gl.app_context") == 0)
> {
>                 GstContext *app_context = gst_context_new
> ("gst.gl.app_context", TRUE);
>                 GstStructure *s = gst_context_writable_structure
> (app_context);
>                 gst_structure_set (s, "context", GST_GL_TYPE_CONTEXT,
> data->gst_context, NULL);
>                 gst_element_set_context (GST_ELEMENT (message->src),
> app_context);
>                 return TRUE;
>             }
>             break;
>
>         }

This code looks good assuming that this callback is from the sync bus
handler and not the async bus handler and that data->gst_context holds a
valid GstGLContext.

The other thing to check is the GStreamer debug logs, specifically with
GST_DEBUG=gl*:7,GST_CONTEXT:7 to ensure that your provided GL context is
being used correctly.

Cheers
-Matt

> Any remarks would be much appreciated.
>
> Best,
> Jeremi

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 516 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20180220/17f72be6/attachment.sig>


More information about the gstreamer-devel mailing list