diff options
author | Julian Eisel <julian@blender.org> | 2020-03-17 18:54:03 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-03-17 18:54:53 +0300 |
commit | f0ccb6ab46e1287244a6abb75eb55d502d6f2279 (patch) | |
tree | 492a47b17a48340ba4aa9be2afe26c0692671d42 | |
parent | 2f2f5878818cc7d0a60e9b5786dd3eda6db90e1c (diff) |
Fix crash when rendering Eevee/Workbench while VR session runs
We have to set the main draw-manager mutex.
Also some related cleanup.
-rw-r--r-- | source/blender/draw/DRW_engine.h | 7 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 59 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_xr.c | 3 |
3 files changed, 42 insertions, 27 deletions
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h index 0aa38de27e5..7ecf9df275d 100644 --- a/source/blender/draw/DRW_engine.h +++ b/source/blender/draw/DRW_engine.h @@ -140,10 +140,13 @@ void DRW_opengl_context_destroy(void); void DRW_opengl_context_enable(void); void DRW_opengl_context_disable(void); -/* Not nice to expose these. Code to render offscreen viewports can save expensive context switches - * by using this directly however. */ +#ifdef WITH_XR_OPENXR +/* XXX see comment on DRW_xr_opengl_context_get() */ void *DRW_xr_opengl_context_get(void); void *DRW_xr_gpu_context_get(void); +void DRW_xr_drawing_begin(void); +void DRW_xr_drawing_end(void); +#endif /* For garbage collection */ void DRW_cache_free_old_batches(struct Main *bmain); diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index ce6d391c481..618922d8544 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2795,30 +2795,6 @@ void DRW_opengl_context_disable(void) DRW_opengl_context_disable_ex(true); } -#ifdef WITH_XR_OPENXR - -/* XXX - * There should really be no such getter, but for VR we currently can't easily avoid it. OpenXR - * needs some low level info for the OpenGL context that will be used for submitting the - * final framebuffer. VR could in theory create its own context, but that would mean we have to - * switch to it just to submit the final frame, which has notable performance impact. - * - * We could "inject" a context through DRW_opengl_render_context_enable(), but that would have to - * work from the main thread, which is tricky to get working too. The preferable solution would be - * using a separate thread for VR drawing where a single context can stay active. */ -void *DRW_xr_opengl_context_get(void) -{ - return DST.gl_context; -} - -/* XXX See comment on DRW_xr_opengl_context_get(). */ -void *DRW_xr_gpu_context_get(void) -{ - return DST.gpu_context; -} - -#endif - void DRW_opengl_render_context_enable(void *re_gl_context) { /* If thread is main you should use DRW_opengl_context_enable(). */ @@ -2854,4 +2830,39 @@ void DRW_gpu_render_context_disable(void *UNUSED(re_gpu_context)) GPU_context_active_set(NULL); } +#ifdef WITH_XR_OPENXR + +/* XXX + * There should really be no such getter, but for VR we currently can't easily avoid it. OpenXR + * needs some low level info for the OpenGL context that will be used for submitting the + * final framebuffer. VR could in theory create its own context, but that would mean we have to + * switch to it just to submit the final frame, which has notable performance impact. + * + * We could "inject" a context through DRW_opengl_render_context_enable(), but that would have to + * work from the main thread, which is tricky to get working too. The preferable solution would be + * using a separate thread for VR drawing where a single context can stay active. */ +void *DRW_xr_opengl_context_get(void) +{ + return DST.gl_context; +} + +/* XXX See comment on DRW_xr_opengl_context_get(). */ +void *DRW_xr_gpu_context_get(void) +{ + return DST.gpu_context; +} + +/* XXX See comment on DRW_xr_opengl_context_get(). */ +void DRW_xr_drawing_begin(void) +{ + BLI_ticket_mutex_lock(DST.gl_context_mutex); +} + +/* XXX See comment on DRW_xr_opengl_context_get(). */ +void DRW_xr_drawing_end(void) +{ + BLI_ticket_mutex_unlock(DST.gl_context_mutex); +} + +#endif /** \} */ diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c index 19d05826341..bd9fd7cdc3e 100644 --- a/source/blender/windowmanager/intern/wm_xr.c +++ b/source/blender/windowmanager/intern/wm_xr.c @@ -516,9 +516,10 @@ static void wm_xr_session_surface_draw(bContext *C) if (!GHOST_XrSessionIsRunning(wm->xr.runtime->context)) { return; } + DRW_xr_drawing_begin(); GHOST_XrSessionDrawViews(wm->xr.runtime->context, C); - GPU_offscreen_unbind(surface_data->offscreen, false); + DRW_xr_drawing_end(); } static void wm_xr_session_free_data(wmSurface *surface) |