[PATCH v1 1/6] ui/sdl2: Restore original context after new context creation

Dmitry Osipenko posted 6 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH v1 1/6] ui/sdl2: Restore original context after new context creation
Posted by Dmitry Osipenko 1 month, 2 weeks ago
SDL API changes GL context to a newly created GL context, which differs
from other GL providers that don't switch context. Change SDL backend to
restore the original GL context. This allows Qemu's virtio-gpu to support
new virglrenderer async-fencing feature for Virgl context, otherwise it's
impossible for virglrenderer to switch GL context from a thread that waits
for async-fences.

Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
 ui/sdl2-gl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index e01d9ab0c7bf..b1fe96d6af22 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -168,6 +168,9 @@ QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc,
                             SDL_GL_CONTEXT_PROFILE_ES);
         ctx = SDL_GL_CreateContext(scon->real_window);
     }
+
+    SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
+
     return (QEMUGLContext)ctx;
 }
 
-- 
2.46.0
Re: [PATCH v1 1/6] ui/sdl2: Restore original context after new context creation
Posted by Akihiko Odaki 1 month, 2 weeks ago
On 2024/10/07 8:23, Dmitry Osipenko wrote:
> SDL API changes GL context to a newly created GL context, which differs
> from other GL providers that don't switch context. Change SDL backend to
> restore the original GL context. This allows Qemu's virtio-gpu to support
> new virglrenderer async-fencing feature for Virgl context, otherwise it's
> impossible for virglrenderer to switch GL context from a thread that waits
> for async-fences.

The expression "to switch GL context" is somewhat unclear. I suppose it 
means to switch to the newly created GL context. It would be nice if it 
describes why such a switching operation fails.

> 
> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> ---
>   ui/sdl2-gl.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
> index e01d9ab0c7bf..b1fe96d6af22 100644
> --- a/ui/sdl2-gl.c
> +++ b/ui/sdl2-gl.c
> @@ -168,6 +168,9 @@ QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc,
>                               SDL_GL_CONTEXT_PROFILE_ES);
>           ctx = SDL_GL_CreateContext(scon->real_window);
>       }
> +
> +    SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
> +
>       return (QEMUGLContext)ctx;
>   }
>