The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

c/client: Avoid using shared context on synchronization

+54 -22
+12 -2
src/xrt/compositor/client/comp_egl_client.c
··· 417 417 } 418 418 419 419 static xrt_result_t 420 - client_egl_context_begin(struct xrt_compositor *xc) 420 + client_egl_context_begin(struct xrt_compositor *xc, enum client_gl_context_reason reason) 421 421 { 422 422 struct client_egl_compositor *eglc = client_egl_compositor(xc); 423 + 424 + //! @todo Handle this better, don't just assume that the context is current. 425 + if (reason == CLIENT_GL_CONTEXT_REASON_SYNCHRONIZE) { 426 + return XRT_SUCCESS; 427 + } 423 428 424 429 save_context(&eglc->previous); 425 430 struct client_egl_context *cur = &eglc->current; ··· 431 436 } 432 437 433 438 static void 434 - client_egl_context_end(struct xrt_compositor *xc) 439 + client_egl_context_end(struct xrt_compositor *xc, enum client_gl_context_reason reason) 435 440 { 436 441 struct client_egl_compositor *eglc = client_egl_compositor(xc); 442 + 443 + //! @todo Handle this better, don't just assume that the context is current. 444 + if (reason == CLIENT_GL_CONTEXT_REASON_SYNCHRONIZE) { 445 + return; 446 + } 437 447 438 448 restore_context(&eglc->previous); 439 449 }
+8 -8
src/xrt/compositor/client/comp_gl_client.c
··· 386 386 387 387 sync_handle = XRT_GRAPHICS_SYNC_HANDLE_INVALID; 388 388 389 - xrt_result_t xret = client_gl_compositor_context_begin(xc); 389 + xrt_result_t xret = client_gl_compositor_context_begin(xc, CLIENT_GL_CONTEXT_REASON_SYNCHRONIZE); 390 390 if (xret == XRT_SUCCESS) { 391 391 sync_handle = handle_fencing_or_finish(c); 392 - client_gl_compositor_context_end(xc); 392 + client_gl_compositor_context_end(xc, CLIENT_GL_CONTEXT_REASON_SYNCHRONIZE); 393 393 } 394 394 395 395 COMP_TRACE_IDENT(layer_commit); ··· 439 439 return XRT_ERROR_SWAPCHAIN_FORMAT_UNSUPPORTED; 440 440 } 441 441 442 - xret = client_gl_compositor_context_begin(xc); 442 + xret = client_gl_compositor_context_begin(xc, CLIENT_GL_CONTEXT_REASON_OTHER); 443 443 if (xret != XRT_SUCCESS) { 444 444 return xret; 445 445 } ··· 448 448 const char *version_str = (const char *)glGetString(GL_VERSION); 449 449 if (strstr(version_str, "OpenGL ES 2.") == version_str) { 450 450 U_LOG_E("Only one array layer is supported with OpenGL ES 2"); 451 - client_gl_compositor_context_end(xc); 451 + client_gl_compositor_context_end(xc, CLIENT_GL_CONTEXT_REASON_OTHER); 452 452 return XRT_ERROR_SWAPCHAIN_FLAG_VALID_BUT_UNSUPPORTED; 453 453 } 454 454 } ··· 465 465 xret = xrt_comp_native_create_swapchain(c->xcn, &vkinfo, &xscn); 466 466 467 467 if (xret != XRT_SUCCESS) { 468 - client_gl_compositor_context_end(xc); 468 + client_gl_compositor_context_end(xc, CLIENT_GL_CONTEXT_REASON_OTHER); 469 469 return xret; 470 470 } 471 471 assert(xscn != NULL); ··· 484 484 if (NULL == c->create_swapchain(xc, &xinfo, xscn, &sc)) { 485 485 // Drop our reference, does NULL checking. 486 486 xrt_swapchain_reference(&xsc, NULL); 487 - client_gl_compositor_context_end(xc); 487 + client_gl_compositor_context_end(xc, CLIENT_GL_CONTEXT_REASON_OTHER); 488 488 return XRT_ERROR_OPENGL; 489 489 } 490 490 491 491 if (sc == NULL) { 492 492 U_LOG_E("Could not create OpenGL swapchain."); 493 - client_gl_compositor_context_end(xc); 493 + client_gl_compositor_context_end(xc, CLIENT_GL_CONTEXT_REASON_OTHER); 494 494 return XRT_ERROR_OPENGL; 495 495 } 496 496 ··· 512 512 513 513 glBindTexture(tex_target, prev_texture); 514 514 515 - client_gl_compositor_context_end(xc); 515 + client_gl_compositor_context_end(xc, CLIENT_GL_CONTEXT_REASON_OTHER); 516 516 517 517 *out_xsc = &sc->base.base; 518 518 return XRT_SUCCESS;
+28 -6
src/xrt/compositor/client/comp_gl_client.h
··· 53 53 }; 54 54 55 55 /*! 56 + * What's the reason to make the context current, this is needed currently for 57 + * EGL where we have to create a shared context in some cases. But when we 58 + * want to synchronize (insert a fence or call glFinish) we can not use the 59 + * shared context and must use the context that the app provided on creation. 60 + */ 61 + enum client_gl_context_reason 62 + { 63 + /*! 64 + * Used when the compositor needs to insert a fence in the command 65 + * stream of the apps context, this needs to be done in the given 66 + * context and not the shared one that may be created. 67 + */ 68 + CLIENT_GL_CONTEXT_REASON_SYNCHRONIZE, 69 + /*! 70 + * Any other reason to make the context current, 71 + * the shared may be used by now. 72 + */ 73 + CLIENT_GL_CONTEXT_REASON_OTHER, 74 + }; 75 + 76 + /*! 56 77 * Fetches the OpenGL context that is current on this thread and makes the 57 78 * OpenGL context given in the graphics binding current instead. Only one thread 58 79 * at a time can operate on the sections between ··· 67 88 * If the return value is not XRT_SUCCESS, 68 89 * @ref client_gl_context_end_locked_func_t should not be called. 69 90 */ 70 - typedef xrt_result_t (*client_gl_context_begin_locked_func_t)(struct xrt_compositor *xc); 91 + typedef xrt_result_t (*client_gl_context_begin_locked_func_t)(struct xrt_compositor *xc, 92 + enum client_gl_context_reason reason); 71 93 72 94 /*! 73 95 * Makes the OpenGL context current that was current before ··· 78 100 * not released by this function, but @ref client_gl_compositor_context_end does 79 101 * release it. 80 102 */ 81 - typedef void (*client_gl_context_end_locked_func_t)(struct xrt_compositor *xc); 103 + typedef void (*client_gl_context_end_locked_func_t)(struct xrt_compositor *xc, enum client_gl_context_reason reason); 82 104 83 105 /*! 84 106 * The type of a swapchain create constructor. ··· 207 229 * @public @memberof client_gl_compositor 208 230 */ 209 231 static inline xrt_result_t 210 - client_gl_compositor_context_begin(struct xrt_compositor *xc) 232 + client_gl_compositor_context_begin(struct xrt_compositor *xc, enum client_gl_context_reason reason) 211 233 { 212 234 struct client_gl_compositor *cgc = client_gl_compositor(xc); 213 235 214 236 os_mutex_lock(&cgc->context_mutex); 215 237 216 - xrt_result_t xret = cgc->context_begin_locked(xc); 238 + xrt_result_t xret = cgc->context_begin_locked(xc, reason); 217 239 if (xret != XRT_SUCCESS) { 218 240 os_mutex_unlock(&cgc->context_mutex); 219 241 } ··· 229 251 * @public @memberof client_gl_compositor 230 252 */ 231 253 static inline void 232 - client_gl_compositor_context_end(struct xrt_compositor *xc) 254 + client_gl_compositor_context_end(struct xrt_compositor *xc, enum client_gl_context_reason reason) 233 255 { 234 256 struct client_gl_compositor *cgc = client_gl_compositor(xc); 235 257 236 - cgc->context_end_locked(xc); 258 + cgc->context_end_locked(xc, reason); 237 259 238 260 os_mutex_unlock(&cgc->context_mutex); 239 261 }
+2 -2
src/xrt/compositor/client/comp_gl_memobj_swapchain.c
··· 50 50 uint32_t image_count = sc->base.base.base.image_count; 51 51 52 52 struct client_gl_compositor *c = sc->base.gl_compositor; 53 - enum xrt_result xret = client_gl_compositor_context_begin(&c->base.base); 53 + enum xrt_result xret = client_gl_compositor_context_begin(&c->base.base, CLIENT_GL_CONTEXT_REASON_OTHER); 54 54 55 55 if (image_count > 0) { 56 56 if (xret == XRT_SUCCESS) { ··· 64 64 } 65 65 66 66 if (xret == XRT_SUCCESS) { 67 - client_gl_compositor_context_end(&c->base.base); 67 + client_gl_compositor_context_end(&c->base.base, CLIENT_GL_CONTEXT_REASON_OTHER); 68 68 } 69 69 70 70 // Drop our reference, does NULL checking.
+2 -2
src/xrt/compositor/client/comp_gl_win32_client.c
··· 76 76 } 77 77 78 78 static xrt_result_t 79 - client_gl_context_begin_locked(struct xrt_compositor *xc) 79 + client_gl_context_begin_locked(struct xrt_compositor *xc, enum client_gl_context_reason reason) 80 80 { 81 81 struct client_gl_win32_compositor *c = client_gl_win32_compositor(xc); 82 82 ··· 99 99 } 100 100 101 101 static void 102 - client_gl_context_end_locked(struct xrt_compositor *xc) 102 + client_gl_context_end_locked(struct xrt_compositor *xc, enum client_gl_context_reason reason) 103 103 { 104 104 struct client_gl_win32_compositor *c = client_gl_win32_compositor(xc); 105 105
+2 -2
src/xrt/compositor/client/comp_gl_xlib_client.c
··· 74 74 } 75 75 76 76 static xrt_result_t 77 - client_gl_context_begin_locked(struct xrt_compositor *xc) 77 + client_gl_context_begin_locked(struct xrt_compositor *xc, enum client_gl_context_reason reason) 78 78 { 79 79 struct client_gl_xlib_compositor *c = client_gl_xlib_compositor(xc); 80 80 ··· 97 97 } 98 98 99 99 static void 100 - client_gl_context_end_locked(struct xrt_compositor *xc) 100 + client_gl_context_end_locked(struct xrt_compositor *xc, enum client_gl_context_reason reason) 101 101 { 102 102 struct client_gl_xlib_compositor *c = client_gl_xlib_compositor(xc); 103 103