-display dbus: add win32 support
cover -display dbus: add win32 support
From: Marc-André Lureau <[email protected]>
Hi,
The D-Bus display doesn't work on Windows, since it relies on FDs transfer over Unix domain socket. This isn't (yet) supported on Windows. To make it work, the interfaces are adapted to use 'ay' WSASocketW data instead of 'h' (in a similar fashion as QMP 'get-win32-socket').
A simple XML preprocessor helps generating the target-specific OS interfaces.
The performance on Windows isn't great though, since there is no DMABUF scanout sharing between QEMU and the client for example. The first improvement introduces a org.qemu.Display1.Listener.Win32.Map interface for shared display/console memory. This can work regardless of 3d accelerated or not, and should work across various GL implementations as well.
The second improvement relies on ANGLE/EGL Direct3D extensions enabled in virgl (pending review at
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1103) to create shareable Texture2Ds and share them when the client implements the org.qemu.Display1.Listener.Win32.D3D11 interface. This should give comparable performance as in-process display hopefully.
Marc-André Lureau (21):
ui/egl: export qemu_egl_get_error_string() ui/egl: fix make_context_current() callback return value ui/dbus: compile without gio/gunixfdlist.h
scripts: add a XML preprocessor script
ui/dbus: win32 support
qtest: add qtest_pid()
tests: make dbus-display-test work on win32 ui/dbus: introduce "Interfaces" properties console/win32: allocate shareable display surface virtio-gpu/win32: allocate shareable 2d resources/images ui/dbus: use shared memory when possible on win32
ui: add egl-headless support on win32
ui/egl: default to GLES on windows
ui: add egl_fb_read_rect()
ui/dbus: add GL support on win32
ui/dbus: add some GL traces
virtio-gpu-virgl: teach it to get the QEMU EGL display ui/egl: query ANGLE d3d device
ui: add optional d3d texture pointer to scanout texture
virtio-gpu-virgl: use D3D11_SHARE_TEXTURE when available ui/dbus: use shared D3D11 Texture2D when possible
MAINTAINERS | 1 + meson.build | 10 +- qapi/ui.json | 5 +- include/hw/virtio/virtio-gpu.h | 3 + include/sysemu/os-win32.h | 3 + include/ui/console.h | 15 +- include/ui/egl-helpers.h | 11 +- include/ui/gtk.h | 6 +- include/ui/sdl2.h | 3 +- tests/qtest/libqtest.h | 9 + ui/dbus.h | 6 + audio/dbusaudio.c | 43 ++- hw/display/virtio-gpu-virgl.c | 43 ++- hw/display/virtio-gpu.c | 46 ++- tests/qtest/dbus-display-test.c | 43 ++- tests/qtest/libqtest.c | 5 + ui/console.c | 70 ++++- ui/dbus-chardev.c | 20 +- ui/dbus-console.c | 64 +++- ui/dbus-listener.c | 527 +++++++++++++++++++++++++++++--- ui/dbus.c | 4 - ui/egl-context.c | 10 +- ui/egl-headless.c | 25 +- ui/egl-helpers.c | 98 +++++- ui/gtk-egl.c | 14 +- ui/gtk-gl-area.c | 5 +- ui/qemu-pixman.c | 1 + ui/sdl2-gl.c | 3 +- ui/spice-display.c | 3 +- util/oslib-win32.c | 33 ++ scripts/meson.build | 2 + scripts/xml-preprocess-test.py | 136 +++++++++ scripts/xml-preprocess.py | 293 ++++++++++++++++++ tests/qtest/meson.build | 2 +- ui/dbus-display1.xml | 240 ++++++++++++++- ui/meson.build | 15 +- ui/trace-events | 8 +- util/trace-events | 4 + 38 files changed, 1704 insertions(+), 125 deletions(-) create mode 100644 scripts/xml-preprocess-test.py create mode 100755 scripts/xml-preprocess.py
Signature · 1 line
2.40.1
PATCH 1/21 ui/egl: export qemu_egl_get_error_string()
From: Marc-André Lureau <[email protected]>
It will be used from other units.
--- include/ui/egl-helpers.h | 2 ++ ui/egl-helpers.c | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-)
include/ui/egl-helpers.h +2 -0
@@ -67,4 +67,6 @@ bool qemu_egl_has_dmabuf(void);bool egl_init (const char *rendernode,DisplayGLMode mode,Error **errp); +const char *qemu_egl_get_error_string (void ); +#endif /* EGL_HELPERS_H */
ui/egl-helpers.c +5 -7
@@ -28,8 +28,7 @@ DisplayGLMode qemu_egl_mode;/* ------------------------------------------------------------------ */ -#if defined(CONFIG_X11 ) || defined(CONFIG_GBM ) -static const char *egl_get_error_string (void ) +const char *qemu_egl_get_error_string (void ) {EGLint error =eglGetError ();
@@ -68,7 +67,6 @@ static const char *egl_get_error_string(void)return "Unknown EGL error" ; } } -#endif static void egl_fb_delete_texture (egl_fb *fb) {
@@ -482,20 +480,20 @@ static int qemu_egl_init_dpy(EGLNativeDisplayType dpy, qemu_egl_display =qemu_egl_get_display (dpy, platform);if (qemu_egl_display ==EGL_NO_DISPLAY ) { -error_report ("egl: eglGetDisplay failed: %s" ,egl_get_error_string ()); +error_report ("egl: eglGetDisplay failed: %s" ,qemu_egl_get_error_string ());return -1 ; } b =eglInitialize (qemu_egl_display, &major, &minor);if (b ==EGL_FALSE ) { -error_report ("egl: eglInitialize failed: %s" ,egl_get_error_string ()); +error_report ("egl: eglInitialize failed: %s" ,qemu_egl_get_error_string ());return -1 ; } b =eglBindAPI (gles ?EGL_OPENGL_ES_API :EGL_OPENGL_API );if (b ==EGL_FALSE ) {error_report ("egl: eglBindAPI failed (%s mode): %s" , - gles ?"gles" :"core" ,egl_get_error_string ()); + gles ?"gles" :"core" ,qemu_egl_get_error_string ());return -1 ; }
@@ -504,7 +502,7 @@ static int qemu_egl_init_dpy(EGLNativeDisplayType dpy, &qemu_egl_config, 1, &n);if (b ==EGL_FALSE || n !=1 ) {error_report ("egl: eglChooseConfig failed (%s mode): %s" , - gles ?"gles" :"core" ,egl_get_error_string ()); + gles ?"gles" :"core" ,qemu_egl_get_error_string ());return -1 ; }
Signature · 1 line
2.40.1
PATCH 2/21 ui/egl: fix make_context_current() callback return value
In reply to [email protected]From: Marc-André Lureau <[email protected]>
eglMakeCurrent() returns 1/EGL_TRUE on success. This is not what the callback expects, where 0 indicates success.
While at it, print the EGL error to ease debugging.
As with virgl_renderer_callbacks, the return value is now checked since version >= 4:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/commit/7f09e6bf0c6ceea6727bd0049781256a28cab0e5
--- ui/egl-context.c | 10 ++++++++-- ui/gtk-egl.c | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-)
ui/egl-context.c +8 -2
@@ -1,4 +1,5 @@#include "qemu/osdep.h" +#include "qemu/error-report.h" #include "ui/egl-context.h" QEMUGLContext qemu_egl_create_context(DisplayGLCtx *dgc,
@@ -32,6 +33,11 @@ void qemu_egl_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx)int qemu_egl_make_context_current (DisplayGLCtx *dgc,QEMUGLContext ctx) { -return eglMakeCurrent (qemu_egl_display, -EGL_NO_SURFACE ,EGL_NO_SURFACE , ctx); +if (!eglMakeCurrent (qemu_egl_display, +EGL_NO_SURFACE ,EGL_NO_SURFACE , ctx)) { +error_report ("egl: eglMakeCurrent failed: %s" ,qemu_egl_get_error_string ()); +return -1 ; + } + +return 0 ; }
ui/gtk-egl.c +7 -2
@@ -368,6 +368,11 @@ int gd_egl_make_current(DisplayGLCtx *dgc, {VirtualConsole *vc =container_of (dgc, VirtualConsole, gfx.dgc); -return eglMakeCurrent (qemu_egl_display, vc->gfx.esurface, - vc->gfx.esurface, ctx); +if (!eglMakeCurrent (qemu_egl_display, vc->gfx.esurface, + vc->gfx.esurface, ctx)) { +error_report ("egl: eglMakeCurrent failed: %s" ,qemu_egl_get_error_string ()); +return -1 ; + } + +return 0 ; }
Signature · 1 line
2.40.1
PATCH 3/21 ui/dbus: compile without gio/gunixfdlist.h
In reply to [email protected]From: Marc-André Lureau <[email protected]>
D-Bus on windows doesn't support fd-passing. Let's isolate the fdlist-related code as a first step, before adding Windows support, using another mechanism.
--- audio/dbusaudio.c | 7 +++++++ ui/dbus-chardev.c | 6 ++++++ ui/dbus-console.c | 8 ++++++++ ui/dbus-listener.c | 2 ++ 4 files changed, 23 insertions(+)
audio/dbusaudio.c +7 -0
@@ -29,7 +29,10 @@#include "qemu/timer.h" #include "qemu/dbus.h" +#ifdef G_OS_UNIX #include <gio/gunixfdlist.h> +#endif +#include "ui/dbus-display1.h" #define AUDIO_CAP "dbus"
@@ -419,6 +422,7 @@ dbus_audio_fini(void *opaque)g_free (da); } +#ifdef G_OS_UNIX static void listener_out_vanished_cb(GDBusConnection *connection, gboolean remote_peer_vanished,
@@ -591,6 +595,7 @@ dbus_audio_register_in_listener(AudioState *s,return dbus_audio_register_listener (s, invocation, fd_list, arg_listener, false); } +#endif static void dbus_audio_set_server (AudioState *s,GDBusObjectManagerServer *server,bool p2p)
@@ -605,12 +610,14 @@ dbus_audio_set_server(AudioState *s, GDBusObjectManagerServer *server, bool p2p) da->audio =g_dbus_object_skeleton_new (DBUS_DISPLAY1_AUDIO_PATH ); da->iface =qemu_dbus_display1_audio_skeleton_new (); +#ifdef G_OS_UNIX g_object_connect (da->iface,"swapped-signal::handle-register-in-listener" , dbus_audio_register_in_listener, s,"swapped-signal::handle-register-out-listener" , dbus_audio_register_out_listener, s,NULL ); +#endif g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (da->audio),G_DBUS_INTERFACE_SKELETON (da->iface));
ui/dbus-chardev.c +6 -0
@@ -27,7 +27,9 @@#include "qemu/config-file.h" #include "qemu/option.h" +#ifdef G_OS_UNIX #include <gio/gunixfdlist.h> +#endif #include "dbus.h"
@@ -108,6 +110,7 @@ dbus_chardev_init(DBusDisplay *dpy) dbus_display_chardev_foreach, dpy); } +#ifdef G_OS_UNIX static gboolean dbus_chr_register( DBusChardev *dc,
@@ -145,6 +148,7 @@ dbus_chr_register(qemu_dbus_display1_chardev_complete_register (object, invocation,NULL );return DBUS_METHOD_INVOCATION_HANDLED ; } +#endif static gboolean dbus_chr_send_break(
@@ -175,8 +179,10 @@ dbus_chr_open(Chardev *chr, ChardevBackend *backend, dc->iface =qemu_dbus_display1_chardev_skeleton_new ();g_object_set (dc->iface,"name" , backend->u.dbus.data->name,NULL );g_object_connect (dc->iface, +#ifdef G_OS_UNIX"swapped-signal::handle-register" , dbus_chr_register, dc, +#endif"swapped-signal::handle-send-break" , dbus_chr_send_break, dc,NULL );
ui/dbus-console.c +8 -0
@@ -28,7 +28,9 @@#include "ui/kbd-state.h" #include "trace.h" +#ifdef G_OS_UNIX #include <gio/gunixfdlist.h> +#endif #include "dbus.h"
@@ -160,6 +162,7 @@ dbus_display_console_class_init(DBusDisplayConsoleClass *klass) gobject_class->dispose = dbus_display_console_dispose; } +#ifdef G_OS_UNIX static void listener_vanished_cb (DBusDisplayListener *listener) {
@@ -171,6 +174,7 @@ listener_vanished_cb(DBusDisplayListener *listener)g_hash_table_remove (ddc->listeners, name);qkbd_state_lift_all_keys (ddc->kbd); } +#endif static gboolean dbus_console_set_ui_info(DBusDisplayConsole *ddc,
@@ -204,6 +208,7 @@ dbus_console_set_ui_info(DBusDisplayConsole *ddc,return DBUS_METHOD_INVOCATION_HANDLED ; } +#ifdef G_OS_UNIX static gboolean dbus_console_register_listener(DBusDisplayConsole *ddc, GDBusMethodInvocation *invocation,
@@ -279,6 +284,7 @@ dbus_console_register_listener(DBusDisplayConsole *ddc,trace_dbus_registered_listener (sender);return DBUS_METHOD_INVOCATION_HANDLED ; } +#endif static gboolean dbus_kbd_press(DBusDisplayConsole *ddc,
@@ -467,8 +473,10 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)"device-address" , device_addr, NULL);g_object_connect (ddc->iface, +#ifdef G_OS_UNIX"swapped-signal::handle-register-listener" , dbus_console_register_listener, ddc, +#endif"swapped-signal::handle-set-uiinfo" , dbus_console_set_ui_info, ddc,NULL );
ui/dbus-listener.c +2 -0
@@ -25,7 +25,9 @@#include "qemu/error-report.h" #include "sysemu/sysemu.h" #include "dbus.h" +#ifdef G_OS_UNIX #include <gio/gunixfdlist.h> +#endif #ifdef CONFIG_OPENGL #include "ui/shader.h"
Signature · 1 line
2.40.1
PATCH 4/21 scripts: add a XML preprocessor script
In reply to [email protected]From: Marc-André Lureau <[email protected]>
gdbus-codegen doesn't support conditions or pre-processing.
Rather than duplicating D-Bus interfaces for win32 adaptation, let's have a preprocess step, so we can have platform-specific interfaces.
The python script is based on
https://github.com/peitaosu/XML-Preprocessor, with bug fixes, some testing and replacing lxml dependency with the built-in xml module.
This preprocessing syntax style is not very common, but is similar to the one provided by WiX (https://wixtoolset.org/docs/v3/overview/preprocessor/)
or wixl, that we adopted in QEMU for packaging the guest agent.
--- MAINTAINERS | 1 + scripts/meson.build | 2 + scripts/xml-preprocess-test.py | 136 +++++++++++++++ scripts/xml-preprocess.py | 293 +++++++++++++++++++++++++++++++++ 4 files changed, 432 insertions(+) create mode 100644 scripts/xml-preprocess-test.py create mode 100755 scripts/xml-preprocess.py
MAINTAINERS +1 -0
@@ -3194,6 +3194,7 @@ F: docs/interop/dbus* F: docs/sphinx/dbus* F: docs/sphinx/fakedbusdoc.py F: tests/qtest/dbus* +F: scripts/xml-preprocess* Seccomp M: Daniel P. Berrange <[email protected]>
scripts/meson.build +2 -0
@@ -1,3 +1,5 @@ if stap.found() install_data('qemu-trace-stap', install_dir: get_option('bindir')) endif + +test('xml-preprocess', files('xml-preprocess-test.py'), suite: ['unit'])
scripts/xml-preprocess-test.py new file +136 -0
136 lines not on this page · raw message
scripts/xml-preprocess.py new file +293 -0
293 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH 5/21 ui/dbus: win32 support
In reply to [email protected]From: Marc-André Lureau <[email protected]>
D-Bus doesn't support fd-passing on Windows (AF_UNIX doesn't have SCM_RIGHTS yet, but there are other means to share objects. I have proposed various solutions upstream, but none seem fitting enough atm).
To make the "-display dbus" work on Windows, implement an alternative D-Bus interface where all the 'h' (FDs) arguments are replaced with 'ay' (WSASocketW data), and sockets are passed to the other end via WSADuplicateSocket().
--- meson.build | 4 +-- ui/dbus.h | 6 +++++ audio/dbusaudio.c | 44 +++++++++++++++++++++++++++------ ui/dbus-chardev.c | 22 +++++++++++++---- ui/dbus-console.c | 59 ++++++++++++++++++++++++++++++++++++++------ ui/dbus-display1.xml | 28 +++++++++++++++++++++ ui/meson.build | 9 ++++++- 7 files changed, 149 insertions(+), 23 deletions(-)
meson.build +2 -2
@@ -838,6 +838,8 @@ if gdbus_codegen.found() and get_option('cfi') gdbus_codegen_error = '@0@ uses gdbus-codegen, which does not support control flow integrity' endif +xml_pp = find_program('scripts/xml-preprocess.py') + lttng = not_found if 'ust' in get_option('trace_backends') lttng = dependency('lttng-ust', required: true, version: '>= 2.1',
@@ -2008,8 +2010,6 @@ dbus_display = get_option('dbus_display') \ error_message: '-display dbus requires glib>=2.64') \ .require(gdbus_codegen.found(), error_message: gdbus_codegen_error.format('-display dbus')) \ - .require(targetos != 'windows', - error_message: '-display dbus is not available on Windows') \ .allowed() have_virtfs = get_option('virtfs') \
ui/dbus.h +6 -0
@@ -62,6 +62,12 @@ struct DBusDisplay {Notifier notifier; }; +#ifdef WIN32 +bool +dbus_win32_import_socket (GDBusMethodInvocation *invocation, +GVariant *arg_listener,int *socket); +#endif +#define TYPE_DBUS_DISPLAY "dbus-display"OBJECT_DECLARE_SIMPLE_TYPE (DBusDisplay,DBUS_DISPLAY )
audio/dbusaudio.c +36 -8
121 lines not on this page · raw message
ui/dbus-chardev.c +17 -5
@@ -110,18 +110,24 @@ dbus_chardev_init(DBusDisplay *dpy) dbus_display_chardev_foreach, dpy); } -#ifdef G_OS_UNIX static gboolean dbus_chr_register (DBusChardev *dc,GDBusMethodInvocation *invocation, +#ifdef G_OS_UNIX GUnixFDList *fd_list, +#endifGVariant *arg_stream,QemuDBusDisplay1Chardev *object) {g_autoptr (GError) err =NULL ;int fd; +#ifdef G_OS_WIN32 +if (!dbus_win32_import_socket (invocation, arg_stream, &fd)) { +return DBUS_METHOD_INVOCATION_HANDLED ; + } +#else fd =g_unix_fd_list_get (fd_list,g_variant_get_handle (arg_stream), &err);if (err) { g_dbus_method_invocation_return_error(
@@ -131,13 +137,18 @@ dbus_chr_register( "Couldn't get peer FD: %s", err->message); return DBUS_METHOD_INVOCATION_HANDLED; } +#endif if (qemu_chr_add_client (CHARDEV (dc), fd) <0 ) {g_dbus_method_invocation_return_error (invocation,DBUS_DISPLAY_ERROR ,DBUS_DISPLAY_ERROR_FAILED ,"Couldn't register FD!" ); +#ifdef G_OS_WIN32 +closesocket (fd); +#else close (fd); +#endif return DBUS_METHOD_INVOCATION_HANDLED ; }
@@ -145,10 +156,13 @@ dbus_chr_register("owner" ,g_dbus_method_invocation_get_sender (invocation), NULL); -qemu_dbus_display1_chardev_complete_register (object, invocation,NULL ); +qemu_dbus_display1_chardev_complete_register (object, invocation +#ifndef G_OS_WIN32 + ,NULL +#endif + );return DBUS_METHOD_INVOCATION_HANDLED ; } -#endif static gboolean dbus_chr_send_break(
@@ -179,10 +193,8 @@ dbus_chr_open(Chardev *chr, ChardevBackend *backend, dc->iface =qemu_dbus_display1_chardev_skeleton_new ();g_object_set (dc->iface,"name" , backend->u.dbus.data->name,NULL );g_object_connect (dc->iface, -#ifdef G_OS_UNIX"swapped-signal::handle-register" , dbus_chr_register, dc, -#endif"swapped-signal::handle-send-break" , dbus_chr_send_break, dc,NULL );
ui/dbus-console.c +52 -7
119 lines not on this page · raw message
ui/dbus-display1.xml +28 -0
@@ -56,7 +56,13 @@ :dbus:iface:`org.qemu.Display1.Listener` interface. --> <method name="RegisterListener"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="listener" direction="in"/> + <?endif?> </method> <!--
@@ -293,6 +299,9 @@ </arg> </method> + <?if $(env.TARGETOS) == windows?> + <!-- Add shared memory/texture support --> + <?else?> <!-- ScanoutDMABUF: @dmabuf: the DMABUF file descriptor.
@@ -331,6 +340,7 @@ <arg type="i" name="width" direction="in"/> <arg type="i" name="height" direction="in"/> </method> + <?endif?> <!-- Disable:
@@ -491,7 +501,13 @@ :dbus:iface:`org.qemu.Display1.AudioOutListener` interface. --> <method name="RegisterOutListener"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="listener" direction="in"/> + <?endif?> </method> <!--
@@ -506,7 +522,13 @@ :dbus:iface:`org.qemu.Display1.AudioInListener` interface. --> <method name="RegisterInListener"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="listener" direction="in"/> + <?endif?> </method> </interface>
@@ -719,7 +741,13 @@ The current handler, if any, will be replaced. --> <method name="Register"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="stream" direction="in"/> + <?endif?> </method> <!--
ui/meson.build +8 -1
@@ -74,9 +74,16 @@ endif if dbus_display dbus_ss = ss.source_set() + env = environment() + env.set('TARGETOS', targetos) + xml = custom_target('dbus-display preprocess', + input: 'dbus-display1.xml', + output: 'dbus-display1.xml', + env: env, + command: [xml_pp, '@INPUT@', '@OUTPUT@']) dbus_display1 = custom_target('dbus-display gdbus-codegen', output: ['dbus-display1.h', 'dbus-display1.c'], - input: files('dbus-display1.xml'), + input: xml, command: [gdbus_codegen, '@INPUT@', '--glib-min-required', '2.64', '--output-directory', meson.current_build_dir(),
Signature · 1 line
2.40.1
PATCH 6/21 qtest: add qtest_pid()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Used in the following test on win32, to share sockets with the QEMU process.
--- tests/qtest/libqtest.h | 9 +++++++++ tests/qtest/libqtest.c | 5 +++++ 2 files changed, 14 insertions(+)
tests/qtest/libqtest.h +9 -0
@@ -985,4 +985,13 @@ void qtest_qom_set_bool(QTestState *s, const char *path, const char *property,* Returns: Value retrieved from property. */ bool qtest_qom_get_bool (QTestState *s,const char *path,const char *property); + +/** +* qtest_pid: +* @s: QTestState instance to operate on. +* +* Returns: the PID of the QEMU process, or <= 0 +*/ +pid_t qtest_pid (QTestState *s); +#endif
tests/qtest/libqtest.c +5 -0
@@ -142,6 +142,11 @@ static int socket_accept(int sock)return ret; } +pid_t qtest_pid (QTestState *s) +{ +return s->qemu_pid; +} +bool qtest_probe_child (QTestState *s) {pid_t pid = s->qemu_pid;
Signature · 1 line
2.40.1
Re: [PATCH 06/21] qtest: add qtest_pid()
Quoted 10 lines · On 06/06/2023 13.56, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Used in the following test on win32, to share sockets with the QEMU process.
Signed-off-by Marc-André Lureau <[email protected]>--- tests/qtest/libqtest.h | 9 +++++++++ tests/qtest/libqtest.c | 5 +++++ 2 files changed, 14 insertions(+)
PATCH 7/21 tests: make dbus-display-test work on win32
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- tests/qtest/dbus-display-test.c | 43 ++++++++++++++++++++++++++++++--- tests/qtest/meson.build | 2 +- 2 files changed, 41 insertions(+), 4 deletions(-)
tests/qtest/dbus-display-test.c +40 -3
@@ -1,4 +1,5 @@#include "qemu/osdep.h" +#include "qemu/sockets.h" #include "qemu/dbus.h" #include "qemu/sockets.h" #include <gio/gio.h>
@@ -14,7 +15,11 @@ test_dbus_p2p_from_fd(int fd)g_autoptr (GSocketConnection) socketc =NULL ;GDBusConnection *conn; +#ifdef WIN32 + socket =g_socket_new_from_fd (_get_osfhandle (fd), &err); +#else socket =g_socket_new_from_fd (fd, &err); +#endif g_assert_no_error (err); socketc =g_socket_connection_factory_create_connection (socket);
@@ -126,7 +131,10 @@ test_dbus_console_registered(GObject *source_object, qemu_dbus_display1_console_call_register_listener_finish( QEMU_DBUS_DISPLAY1_CONSOLE(source_object), -NULL , res, &err); +#ifndef WIN32 +NULL , +#endif + res, &err);g_assert_no_error (err); test->listener_conn =g_thread_join (test->thread);
@@ -145,17 +153,25 @@ test_dbus_display_console(void)g_autoptr (GError) err =NULL ;g_autoptr (GDBusConnection) conn =NULL ;g_autoptr (QemuDBusDisplay1ConsoleProxy) console =NULL ; -g_autoptr (GUnixFDList) fd_list =NULL ;g_autoptr (GMainLoop) loop =NULL ;QTestState *qts =NULL ; -int pair[2 ], idx; +int pair[2 ];TestDBusConsoleRegister test; +#ifdef WIN32 +WSAPROTOCOL_INFOW info; +g_autoptr (GVariant) listener =NULL ; +#else +g_autoptr (GUnixFDList) fd_list =NULL ; +int idx; +#endif test_setup (&qts, &conn); g_assert_cmpint(qemu_socketpair(AF_UNIX, SOCK_STREAM, 0, pair), ==, 0); +#ifndef WIN32 fd_list =g_unix_fd_list_new (); idx =g_unix_fd_list_append (fd_list, pair[1 ],NULL ); +#endif console = QEMU_DBUS_DISPLAY1_CONSOLE_PROXY( qemu_dbus_display1_console_proxy_new_sync(
@@ -171,12 +187,33 @@ test_dbus_display_console(void) test.thread =g_thread_new (NULL , test_dbus_p2p_server_setup_thread,GINT_TO_POINTER (pair[0 ])); +#ifdef WIN32 +if (WSADuplicateSocketW (_get_osfhandle (pair[1 ]), +GetProcessId ((HANDLE )qtest_pid (qts)), + &info) ==SOCKET_ERROR ) + { + g_autofree char *emsg = g_win32_error_message(WSAGetLastError()); +g_error ("WSADuplicateSocket failed: %s" , emsg); + } +close (pair[1 ]); + listener =g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE , + &info, +sizeof (info), +1 ); +#endif + qemu_dbus_display1_console_call_register_listener( QEMU_DBUS_DISPLAY1_CONSOLE(console), +#ifdef WIN32 + listener, +#elseg_variant_new_handle (idx), +#endifG_DBUS_CALL_FLAGS_NONE ,-1 , +#ifndef WIN32 fd_list, +#endifNULL , test_dbus_console_registered, &test);
tests/qtest/meson.build +1 -1
@@ -103,7 +103,7 @@ qtests_i386 = \ 'numa-test' ] -if dbus_display and targetos != 'windows' +if dbus_display qtests_i386 += ['dbus-display-test'] endif
Signature · 1 line
2.40.1
Re: [PATCH 07/21] tests: make dbus-display-test work on win32
Quoted 7 lines · On 06/06/2023 13.56, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Signed-off-by Marc-André Lureau <[email protected]>--- tests/qtest/dbus-display-test.c | 43 ++++++++++++++++++++++++++++++--- tests/qtest/meson.build | 2 +- 2 files changed, 41 insertions(+), 4 deletions(-)
PATCH 8/21 ui/dbus: introduce "Interfaces" properties
In reply to [email protected]From: Marc-André Lureau <[email protected]>
This property is similar to ``org.freedesktop.DBus.Interfaces`` property on the bus interface: it's an array of strings listing the extra interfaces and capabilities available, in a convenient way.
Most interfaces are implicit, as they are required. For ``org/qemu/Display1_$id``, we can list the Keyboard And Mouse interfaces. Those could be optional.
--- ui/dbus-console.c | 6 +++ ui/dbus-display1.xml | 118 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 122 insertions(+), 2 deletions(-)
ui/dbus-console.c +6 -0
@@ -494,6 +494,11 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)char device_addr[256 ] ="" ;DBusDisplayConsole *ddc;int idx; +const char *interfaces[] = { +"org.qemu.Display1.Keyboard" , +"org.qemu.Display1.Mouse" , +NULL + };assert (display);assert (con);
@@ -518,6 +523,7 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)"width" ,qemu_console_get_width (con,0 ),"height" ,qemu_console_get_height (con,0 ),"device-address" , device_addr, +"interfaces" , interfaces, NULL); g_object_connect(ddc->iface, "swapped-signal::handle-register-listener",
ui/dbus-display1.xml +116 -2
176 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH 9/21 console/win32: allocate shareable display surface
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Introduce qemu_win32_map_alloc() and qemu_win32_map_free() to allocate shared memory mapping. The handle can be used to share the mapping with another process.
Teach qemu_create_displaysurface() to allocate shared memory. Following patches will introduce other places for shared memory allocation.
Other patches for -display dbus will share the memory when possible with the client, to avoid expensive memory copy between the processes.
--- include/sysemu/os-win32.h | 3 ++ include/ui/console.h | 8 ++++++ ui/console.c | 59 ++++++++++++++++++++++++++++++++++----- ui/qemu-pixman.c | 1 + util/oslib-win32.c | 33 ++++++++++++++++++++++ ui/trace-events | 2 +- util/trace-events | 4 +++ 7 files changed, 102 insertions(+), 8 deletions(-)
include/sysemu/os-win32.h +3 -0
@@ -263,6 +263,9 @@ EXCEPTION_DISPOSITION win32_close_exception_handler(struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*); +void *qemu_win32_map_alloc (size_t size,HANDLE *h,Error **errp); +void qemu_win32_map_free (void *ptr,HANDLE h,Error **errp); + #ifdef __cplusplus }#endif
include/ui/console.h +8 -0
@@ -128,6 +128,10 @@ typedef struct DisplaySurface {GLenum gltype;GLuint texture;#endif +#ifdef WIN32 +HANDLE handle; +uint32_t handle_offset; +#endif } DisplaySurface; typedef struct QemuUIInfo {
@@ -314,6 +318,10 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height,DisplaySurface *qemu_create_displaysurface_pixman (pixman_image_t *image);DisplaySurface *qemu_create_placeholder_surface (int w,int h,const char *msg); +#ifdef WIN32 +void qemu_displaysurface_win32_set_handle (DisplaySurface *surface, +HANDLE h,uint32_t offset); +#endif PixelFormat qemu_default_pixelformat (int bpp);DisplaySurface *qemu_create_displaysurface (int width,int height);
ui/console.c +52 -7
76 lines not on this page · raw message
ui/qemu-pixman.c +1 -0
@@ -6,6 +6,7 @@#include "qemu/osdep.h" #include "ui/console.h" #include "standard-headers/drm/drm_fourcc.h" +#include "trace.h" PixelFormat qemu_pixelformat_from_pixman (pixman_format_code_t format) {
util/oslib-win32.c +33 -0
@@ -835,3 +835,36 @@ int qemu_msync(void *addr, size_t length, int fd)*/ return qemu_fdatasync (fd); } + +void *qemu_win32_map_alloc (size_t size,HANDLE *h,Error **errp) +{ +void *bits; + +trace_win32_map_alloc (size); + + *h =CreateFileMapping (INVALID_HANDLE_VALUE ,NULL ,PAGE_READWRITE ,0 , + size,NULL ); +if (*h ==NULL ) { +error_setg_win32 (errp,GetLastError (),"Failed to CreateFileMapping" ); +return NULL ; + } + + bits =MapViewOfFile (*h,FILE_MAP_ALL_ACCESS ,0 ,0 , size); +if (bits ==NULL ) { +error_setg_win32 (errp,GetLastError (),"Failed to MapViewOfFile" ); +CloseHandle (*h); +return NULL ; + } + +return bits; +} + +void qemu_win32_map_free (void *ptr,HANDLE h,Error **errp) +{ +trace_win32_map_free (ptr, h); + +if (UnmapViewOfFile (ptr) ==0 ) { +error_setg_win32 (errp,GetLastError (),"Failed to UnmapViewOfFile" ); + } +CloseHandle (h); +}
ui/trace-events +1 -1
@@ -9,7 +9,7 @@ console_putchar_unhandled(int ch) "unhandled escape character '%c'" console_txt_new(int w, int h) "%dx%d" console_select(int nr) "%d" console_refresh(int interval) "interval %d ms" -displaysurface_create(void *display_surface, int w, int h) "surface=%p, %dx%d" +displaysurface_create(int w, int h) "%dx%d" displaysurface_create_from(void *display_surface, int w, int h, uint32_t format) "surface=%p, %dx%d, format 0x%x" displaysurface_create_pixman(void *display_surface) "surface=%p" displaysurface_free(void *display_surface) "surface=%p"
util/trace-events +4 -0
@@ -52,6 +52,10 @@ qemu_anon_ram_alloc(size_t size, void *ptr) "size %zu ptr %p" qemu_vfree(void *ptr) "ptr %p" qemu_anon_ram_free(void *ptr, size_t size) "ptr %p size %zu" +# oslib-win32.c +win32_map_alloc(size_t size) "size:%zd" +win32_map_free(void *ptr, void *h) "ptr:%p handle:%p" + # hbitmap.c hbitmap_iter_skip_words(const void *hb, void *hbi, uint64_t pos, unsigned long cur) "hb %p hbi %p pos %"PRId64" cur 0x%lx" hbitmap_reset(void *hb, uint64_t start, uint64_t count, uint64_t sbit, uint64_t ebit) "hb %p items %"PRIu64",%"PRIu64" bits %"PRIu64"..%"PRIu64
Signature · 1 line
2.40.1
PATCH 10/21 virtio-gpu/win32: allocate shareable 2d resources/images
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Allocate pixman bits for scanouts with qemu_win32_map_alloc() so we can set a shareable handle on the associated display surface.
Note: when bits are provided to pixman_image_create_bits(), you must also give the rowstride (the argument is ignored when bits is NULL)
--- include/hw/virtio/virtio-gpu.h | 3 +++ hw/display/virtio-gpu.c | 46 +++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-)
include/hw/virtio/virtio-gpu.h +3 -0
@@ -48,6 +48,9 @@ struct virtio_gpu_simple_resource {unsigned int iov_cnt;uint32_t scanout_bitmask;pixman_image_t *image; +#ifdef WIN32 +HANDLE handle; +#endif uint64_t hostmem;uint64_t blob_size;
hw/display/virtio-gpu.c +43 -3
94 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH 11/21 ui/dbus: use shared memory when possible on win32
In reply to [email protected]From: Marc-André Lureau <[email protected]>
When the display surface has an associated HANDLE, we can duplicate it to the client process and let it map the memory to avoid expensive copies.
Introduce two new win32-specific methods ScanoutMap and UpdateMap. The first is used to inform the listener about the a shared map availability, and the second for display updates.
--- ui/dbus-listener.c | 165 ++++++++++++++++++++++++++++++++++++++++++- ui/dbus-display1.xml | 48 ++++++++++++- 2 files changed, 208 insertions(+), 5 deletions(-)
ui/dbus-listener.c +163 -2
@@ -48,6 +48,14 @@ struct _DBusDisplayListener {DisplayChangeListener dcl;DisplaySurface *ds;int gl_updates; + +bool ds_mapped; +bool can_share_map; + +#ifdef WIN32 +QemuDBusDisplay1ListenerWin32Map *map_proxy; +HANDLE peer_process; +#endif };G_DEFINE_TYPE (DBusDisplayListener, dbus_display_listener,G_TYPE_OBJECT )
@@ -119,7 +127,61 @@ static void dbus_scanout_dmabuf(DisplayChangeListener *dcl, fd_list, NULL, NULL, NULL); } +#endif /* OPENGL & GBM */ + +#ifdef WIN32 +static bool dbus_scanout_map (DBusDisplayListener *ddl) +{ +g_autoptr (GError) err =NULL ; +BOOL success; +HANDLE target_handle; + +if (ddl->ds_mapped) { +return true; + } + +if (!ddl->can_share_map || !ddl->ds->handle) { +return false; + } + + success =DuplicateHandle ( +GetCurrentProcess (), + ddl->ds->handle, + ddl->peer_process, + &target_handle, +FILE_MAP_READ |SECTION_QUERY , + FALSE,0 ); +if (!success) { + g_autofree char *msg = g_win32_error_message(GetLastError()); +g_debug ("Failed to DuplicateHandle: %s" , msg); + ddl->can_share_map = false; +return false; + } + +if (!qemu_dbus_display1_listener_win32_map_call_scanout_map_sync ( + ddl->map_proxy, +GPOINTER_TO_UINT (target_handle), + ddl->ds->handle_offset, +surface_width (ddl->ds), +surface_height (ddl->ds), +surface_stride (ddl->ds), +surface_format (ddl->ds), +G_DBUS_CALL_FLAGS_NONE , +DBUS_DEFAULT_TIMEOUT , +NULL , + &err)) { +g_debug ("Failed to call ScanoutMap: %s" , err->message); + ddl->can_share_map = false; +return false; + } + + ddl->ds_mapped = true; + +return true; +} +#endif +#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) static void dbus_scanout_texture(DisplayChangeListener *dcl, uint32_t tex_id, bool backing_y_0_top,
@@ -239,7 +301,7 @@ static void dbus_gl_refresh(DisplayChangeListener *dcl) ddl->gl_updates = 0; } } -#endif +#endif /* OPENGL & GBM */ static void dbus_refresh (DisplayChangeListener *dcl) {
@@ -265,10 +327,20 @@ static void dbus_gfx_update(DisplayChangeListener *dcl,size_t stride;assert (ddl->ds); - stride = w *DIV_ROUND_UP (PIXMAN_FORMAT_BPP (surface_format (ddl->ds)),8 );trace_dbus_update (x, y, w, h); +#ifdef WIN32 +if (dbus_scanout_map (ddl)) { +qemu_dbus_display1_listener_win32_map_call_update_map ( + ddl->map_proxy, + x, y, w, h, +G_DBUS_CALL_FLAGS_NONE , +DBUS_DEFAULT_TIMEOUT ,NULL ,NULL ,NULL ); +return ; + } +#endif +if (x ==0 && y ==0 && w ==surface_width (ddl->ds) && h ==surface_height (ddl->ds)) { v_data = g_variant_new_from_data( G_VARIANT_TYPE("ay"),
@@ -290,6 +362,7 @@ static void dbus_gfx_update(DisplayChangeListener *dcl, }/* make a copy, since gvariant only handles linear data */ + stride = w *DIV_ROUND_UP (PIXMAN_FORMAT_BPP (surface_format (ddl->ds)),8 ); img =pixman_image_create_bits (surface_format (ddl->ds), w, h,NULL , stride); pixman_image_composite(PIXMAN_OP_SRC, ddl->ds->image, NULL, img,
@@ -333,6 +406,9 @@ static void dbus_gfx_switch(DisplayChangeListener *dcl,DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); ddl->ds = new_surface; +#ifdef WIN32 + ddl->ds_mapped = false; +#endif if (!ddl->ds) {/* why not call disable instead? */ return ;
@@ -414,6 +490,10 @@ dbus_display_listener_dispose(GObject *object)g_clear_object (&ddl->conn);g_clear_pointer (&ddl->bus_name, g_free);g_clear_object (&ddl->proxy); +#ifdef WIN32 +g_clear_object (&ddl->map_proxy); +g_clear_pointer (&ddl->peer_process, CloseHandle); +#endif G_OBJECT_CLASS (dbus_display_listener_parent_class)->dispose (object); }
@@ -459,6 +539,85 @@ dbus_display_listener_get_console(DBusDisplayListener *ddl)return ddl->console; } +#ifdef WIN32 +static bool +dbus_display_listener_implements (DBusDisplayListener *ddl,const char *iface) +{ +QemuDBusDisplay1Listener *l =QEMU_DBUS_DISPLAY1_LISTENER (ddl->proxy); +bool implements; + + implements =g_strv_contains (qemu_dbus_display1_listener_get_interfaces (l), iface); +if (!implements) { +g_debug ("Display listener does not implement: `%s`" , iface); + } + +return implements; +} +#endif + +static void +dbus_display_listener_setup_shared_map (DBusDisplayListener *ddl) +{ +#ifdef WIN32 +g_autoptr (GError) err =NULL ; +GDBusConnection *conn; +GIOStream *stream; +GSocket *sock; +g_autoptr (GCredentials) creds =NULL ; +DWORD *pid; + +if (!dbus_display_listener_implements (ddl,"org.qemu.Display1.Listener.Win32.Map" )) { +return ; + } + + conn =g_dbus_proxy_get_connection (G_DBUS_PROXY (ddl->proxy)); + stream =g_dbus_connection_get_stream (conn); + +if (!G_IS_UNIX_CONNECTION (stream)) { +return ; + } + + sock =g_socket_connection_get_socket (G_SOCKET_CONNECTION (stream)); + creds =g_socket_get_credentials (sock, &err); + +if (!creds) { +g_debug ("Failed to get peer credentials: %s" , err->message); +return ; + } + + pid =g_credentials_get_native (creds,G_CREDENTIALS_TYPE_WIN32_PID ); + +if (pid ==NULL ) { +g_debug ("Failed to get peer PID" ); +return ; + } + + ddl->peer_process =OpenProcess ( +PROCESS_DUP_HANDLE |PROCESS_QUERY_INFORMATION , + false, *pid); + +if (!ddl->peer_process) { + g_autofree char *msg = g_win32_error_message(GetLastError()); +g_debug ("Failed to OpenProcess: %s" , msg); +return ; + } + + ddl->map_proxy = +qemu_dbus_display1_listener_win32_map_proxy_new_sync (conn, +G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START , +NULL , +"/org/qemu/Display1/Listener" , +NULL , + &err); +if (!ddl->map_proxy) { +g_debug ("Failed to setup win32 map proxy: %s" , err->message); +return ; + } + + ddl->can_share_map = true; +#endif +} +DBusDisplayListener * dbus_display_listener_new(const char *bus_name, GDBusConnection *conn,
@@ -487,6 +646,8 @@ dbus_display_listener_new(const char *bus_name, ddl->conn = conn; ddl->console = console; +dbus_display_listener_setup_shared_map (ddl); + con =qemu_console_lookup_by_index (dbus_display_console_get_index (console));assert (con); ddl->dcl.con = con;
ui/dbus-display1.xml +45 -3
60 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH 12/21 ui: add egl-headless support on win32
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Make GBM optional for EGL code, and enable the build for win32.
--- qapi/ui.json | 5 ++--- include/ui/egl-helpers.h | 7 ++++++- ui/egl-headless.c | 20 +++++++++++++------- ui/egl-helpers.c | 38 +++++++++++++++++++++++++++++++------- ui/meson.build | 6 +++--- 5 files changed, 55 insertions(+), 21 deletions(-)
qapi/ui.json +2 -3
@@ -1484,8 +1484,7 @@ { 'name': 'none' }, { 'name': 'gtk', 'if': 'CONFIG_GTK' }, { 'name': 'sdl', 'if': 'CONFIG_SDL' }, - { 'name': 'egl-headless', - 'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } }, + { 'name': 'egl-headless', 'if': 'CONFIG_OPENGL' }, { 'name': 'curses', 'if': 'CONFIG_CURSES' }, { 'name': 'cocoa', 'if': 'CONFIG_COCOA' }, { 'name': 'spice-app', 'if': 'CONFIG_SPICE' },
@@ -1525,7 +1524,7 @@ 'cocoa': { 'type': 'DisplayCocoa', 'if': 'CONFIG_COCOA' }, 'curses': { 'type': 'DisplayCurses', 'if': 'CONFIG_CURSES' }, 'egl-headless': { 'type': 'DisplayEGLHeadless', - 'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } }, + 'if': 'CONFIG_OPENGL' }, 'dbus': { 'type': 'DisplayDBus', 'if': 'CONFIG_DBUS_DISPLAY' }, 'sdl': { 'type': 'DisplaySDL', 'if': 'CONFIG_SDL' } }
include/ui/egl-helpers.h +6 -1
@@ -36,11 +36,12 @@ void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip);void egl_texture_blend (QemuGLShader *gls,egl_fb *dst,egl_fb *src,bool flip,int x,int y,double scale_x,double scale_y); +extern EGLContext qemu_egl_rn_ctx; +#ifdef CONFIG_GBM extern int qemu_egl_rn_fd;extern struct gbm_device *qemu_egl_rn_gbm_dev; -extern EGLContext qemu_egl_rn_ctx;int egl_rendernode_init (const char *rendernode,DisplayGLMode mode); int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc,
@@ -62,6 +63,10 @@ int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode);#endif +#ifdef WIN32 +int qemu_egl_init_dpy_win32 (EGLNativeDisplayType dpy,DisplayGLMode mode); +#endif +EGLContext qemu_egl_init_ctx (void );bool qemu_egl_has_dmabuf (void );
ui/egl-headless.c +13 -7
@@ -79,6 +79,8 @@ static void egl_scanout_texture(DisplayChangeListener *dcl, } } +#ifdef CONFIG_GBM +static void egl_scanout_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf) {
@@ -110,6 +112,14 @@ static void egl_cursor_dmabuf(DisplayChangeListener *dcl, } } +static void egl_release_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf) +{ +egl_dmabuf_release_texture (dmabuf); +} + +#endif +static void egl_cursor_position (DisplayChangeListener *dcl,uint32_t pos_x,uint32_t pos_y) {
@@ -119,12 +129,6 @@ static void egl_cursor_position(DisplayChangeListener *dcl, edpy->pos_y = pos_y; } -static void egl_release_dmabuf (DisplayChangeListener *dcl, -QemuDmaBuf *dmabuf) -{ -egl_dmabuf_release_texture (dmabuf); -} -static void egl_scanout_flush (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h)
@@ -160,10 +164,12 @@ static const DisplayChangeListenerOps egl_ops = { .dpy_gl_scanout_disable = egl_scanout_disable, .dpy_gl_scanout_texture = egl_scanout_texture, +#ifdef CONFIG_GBM .dpy_gl_scanout_dmabuf = egl_scanout_dmabuf, .dpy_gl_cursor_dmabuf = egl_cursor_dmabuf, - .dpy_gl_cursor_position = egl_cursor_position, .dpy_gl_release_dmabuf = egl_release_dmabuf, +#endif + .dpy_gl_cursor_position = egl_cursor_position, .dpy_gl_update = egl_scanout_flush, };
ui/egl-helpers.c +31 -7
@@ -199,11 +199,12 @@ void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,/* ---------------------------------------------------------------------- */ +EGLContext qemu_egl_rn_ctx; +#ifdef CONFIG_GBM int qemu_egl_rn_fd;struct gbm_device *qemu_egl_rn_gbm_dev; -EGLContext qemu_egl_rn_ctx;int egl_rendernode_init (const char *rendernode,DisplayGLMode mode) {
@@ -400,7 +401,7 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win)/* ---------------------------------------------------------------------- */ -#if defined(CONFIG_X11 ) || defined(CONFIG_GBM ) +#if defined(CONFIG_X11 ) || defined(CONFIG_GBM ) || defined(WIN32 )/* * Taken from glamor_egl.h from the Xorg xserver, which is MIT licensed
@@ -510,6 +511,9 @@ static int qemu_egl_init_dpy(EGLNativeDisplayType dpy,return 0 ; } +#endif + +#if defined(CONFIG_X11 ) || defined(CONFIG_GBM )int qemu_egl_init_dpy_x11 (EGLNativeDisplayType dpy,DisplayGLMode mode) {#ifdef EGL_KHR_platform_x11
@@ -527,7 +531,14 @@ int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode)return qemu_egl_init_dpy (dpy,0 , mode); #endif } +#endif + +#ifdef WIN32 +int qemu_egl_init_dpy_win32 (EGLNativeDisplayType dpy,DisplayGLMode mode) +{ +return qemu_egl_init_dpy (dpy,0 , mode); +}#endif bool qemu_egl_has_dmabuf (void )
@@ -579,15 +590,28 @@ bool egl_init(const char *rendernode, DisplayGLMode mode, Error **errp)return false; } -#ifdef CONFIG_GBM +#ifdef WIN32 +if (qemu_egl_init_dpy_win32 (EGL_DEFAULT_DISPLAY , mode) <0 ) { +error_setg (errp,"egl: init failed" ); +return false; + } + qemu_egl_rn_ctx =qemu_egl_init_ctx (); +if (!qemu_egl_rn_ctx) { +error_setg (errp,"egl: egl_init_ctx failed" ); +return false; + } +#elif defined(CONFIG_GBM )if (egl_rendernode_init (rendernode, mode) <0 ) {error_setg (errp,"egl: render node init failed" );return false; } +#endif + +if (!qemu_egl_rn_ctx) { +error_setg (errp,"egl: not available on this platform" ); +return false; + } + display_opengl =1 ;return true; -#else -error_setg (errp,"egl: not available on this platform" ); -return false; -#endif }
ui/meson.build +3 -3
@@ -65,10 +65,10 @@ if opengl.found() ui_modules += {'opengl' : opengl_ss} endif -if opengl.found() and gbm.found() +if opengl.found() egl_headless_ss = ss.source_set() - egl_headless_ss.add(when: [opengl, gbm, pixman], - if_true: files('egl-headless.c')) + egl_headless_ss.add(when: [opengl, pixman], + if_true: [files('egl-headless.c'), gbm]) ui_modules += {'egl-headless' : egl_headless_ss} endif
Signature · 1 line
2.40.1
PATCH 13/21 ui/egl: default to GLES on windows
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Windows GL drivers are notoriously not very good. Otoh, ANGLE provides rock solid GLES implementation on top of direct3d. We should recommend it and default to ES when using EGL (users can easily override this if necessary)
--- ui/egl-helpers.c | 4 ++++ 1 file changed, 4 insertions(+)
ui/egl-helpers.c +4 -0
@@ -537,6 +537,10 @@ int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode)#ifdef WIN32 int qemu_egl_init_dpy_win32 (EGLNativeDisplayType dpy,DisplayGLMode mode) { +/* prefer GL ES, as that's what ANGLE supports */ +if (mode ==DISPLAYGL_MODE_ON ) { + mode =DISPLAYGL_MODE_ES ; + }return qemu_egl_init_dpy (dpy,0 , mode); }#endif
Signature · 1 line
2.40.1
PATCH 14/21 ui: add egl_fb_read_rect()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Similar to egl_fb_read(), same limitations, but with extra arguments to read a subset of the framebuffer. Used in following commits.
--- include/ui/egl-helpers.h | 1 + ui/egl-helpers.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
include/ui/egl-helpers.h +1 -0
@@ -31,6 +31,7 @@ void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,void egl_fb_setup_new_tex (egl_fb *fb,int width,int height);void egl_fb_blit (egl_fb *dst,egl_fb *src,bool flip);void egl_fb_read (DisplaySurface *dst,egl_fb *src); +void egl_fb_read_rect (DisplaySurface *dst,egl_fb *src,int x,int y,int w,int h);void egl_texture_blit (QemuGLShader *gls,egl_fb *dst,egl_fb *src,bool flip); void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
ui/egl-helpers.c +14 -0
@@ -169,6 +169,20 @@ void egl_fb_read(DisplaySurface *dst, egl_fb *src) GL_BGRA, GL_UNSIGNED_BYTE, surface_data(dst)); } +void egl_fb_read_rect (DisplaySurface *dst,egl_fb *src,int x,int y,int w,int h) +{ +assert (surface_width (dst) == src->width); +assert (surface_height (dst) == src->height); +assert (surface_format (dst) == PIXMAN_x8r8g8b8); + +glBindFramebuffer (GL_READ_FRAMEBUFFER , src->framebuffer); +glReadBuffer (GL_COLOR_ATTACHMENT0_EXT ); +glPixelStorei (GL_PACK_ROW_LENGTH ,surface_stride (dst) /4 ); +glReadPixels (x, y, w, h, +GL_BGRA ,GL_UNSIGNED_BYTE ,surface_data (dst) + x *4 ); +glPixelStorei (GL_PACK_ROW_LENGTH ,0 ); +} +void egl_texture_blit (QemuGLShader *gls,egl_fb *dst,egl_fb *src,bool flip) {glBindFramebuffer (GL_FRAMEBUFFER_EXT , dst->framebuffer);
Signature · 1 line
2.40.1
PATCH 15/21 ui/dbus: add GL support on win32
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Enable usage of dbus,gl= on win32. At this point, the scanout texture is read on the DisplaySurface memory, and the client is then updated with the "2D" API (with shared memory if possible).
--- ui/dbus-listener.c | 98 ++++++++++++++++++++++++++++++++-------------- ui/dbus.c | 4 -- 2 files changed, 68 insertions(+), 34 deletions(-)
ui/dbus-listener.c +68 -30
@@ -36,6 +36,9 @@#endif #include "trace.h" +static void dbus_gfx_switch (DisplayChangeListener *dcl, +struct DisplaySurface *new_surface); +struct _DBusDisplayListener {GObject parent;
@@ -55,12 +58,28 @@ struct _DBusDisplayListener {#ifdef WIN32 QemuDBusDisplay1ListenerWin32Map *map_proxy;HANDLE peer_process; +#ifdef CONFIG_OPENGL +egl_fb fb; +#endif #endif }; G_DEFINE_TYPE(DBusDisplayListener, dbus_display_listener, G_TYPE_OBJECT) -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +static void dbus_gfx_update (DisplayChangeListener *dcl, +int x,int y,int w,int h); + +#ifdef CONFIG_OPENGL +static void dbus_scanout_disable (DisplayChangeListener *dcl) +{ +DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); + + ddl->ds =NULL ; +qemu_dbus_display1_listener_call_disable ( + ddl->proxy,G_DBUS_CALL_FLAGS_NONE ,-1 ,NULL ,NULL ,NULL ); +} + +#ifdef CONFIG_GBM static void dbus_update_gl_cb (GObject *source_object,GAsyncResult *res,gpointer user_data)
@@ -76,29 +95,31 @@ static void dbus_update_gl_cb(GObject *source_object,graphic_hw_gl_block (ddl->dcl.con, false);g_object_unref (ddl); } +#endif -static void dbus_call_update_gl (DBusDisplayListener *ddl, +static void dbus_call_update_gl (DisplayChangeListener *dcl,int x,int y,int w,int h) { -graphic_hw_gl_block (ddl->dcl.con, true); +DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); +glFlush (); +#ifdef CONFIG_GBM +graphic_hw_gl_block (ddl->dcl.con, true);qemu_dbus_display1_listener_call_update_dmabuf (ddl->proxy, x, y, w, h,G_DBUS_CALL_FLAGS_NONE ,DBUS_DEFAULT_TIMEOUT ,NULL , dbus_update_gl_cb,g_object_ref (ddl)); -} - -static void dbus_scanout_disable (DisplayChangeListener *dcl) -{ -DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); +#endif - ddl->ds =NULL ; -qemu_dbus_display1_listener_call_disable ( - ddl->proxy,G_DBUS_CALL_FLAGS_NONE ,-1 ,NULL ,NULL ,NULL ); +#ifdef WIN32 +egl_fb_read_rect (ddl->ds, &ddl->fb, x, y, w, h); +dbus_gfx_update (dcl, x, y, w, h); +#endif } +#ifdef CONFIG_GBM static void dbus_scanout_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf) {
@@ -127,7 +148,8 @@ static void dbus_scanout_dmabuf(DisplayChangeListener *dcl, fd_list, NULL, NULL, NULL); } -#endif /* OPENGL & GBM */ +#endif /* GBM */ +#endif /* OPENGL */ #ifdef WIN32 static bool dbus_scanout_map (DBusDisplayListener *ddl)
@@ -181,7 +203,7 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl) }#endif -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +#ifdef CONFIG_OPENGL static void dbus_scanout_texture(DisplayChangeListener *dcl, uint32_t tex_id, bool backing_y_0_top,
@@ -190,6 +212,7 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { +#ifdef CONFIG_GBM QemuDmaBuf dmabuf = { .width = backing_width, .height = backing_height,
@@ -212,8 +235,19 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl,dbus_scanout_dmabuf (dcl, &dmabuf);close (dmabuf.fd); +#endif + +#ifdef WIN32 +DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); + +/* there must be a matching gfx_switch before */ +assert (surface_width (ddl->ds) == w); +assert (surface_height (ddl->ds) == h); +egl_fb_setup_for_tex (&ddl->fb, backing_width, backing_height, tex_id, false); +#endif } +#ifdef CONFIG_GBM static void dbus_cursor_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf,bool have_hot,uint32_t hot_x,uint32_t hot_y)
@@ -260,7 +294,14 @@ static void dbus_cursor_dmabuf(DisplayChangeListener *dcl, NULL); } -static void dbus_cursor_position (DisplayChangeListener *dcl, +static void dbus_release_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf) +{ +dbus_scanout_disable (dcl); +} +#endif /* GBM */ + +static void dbus_gl_cursor_position (DisplayChangeListener *dcl,uint32_t pos_x,uint32_t pos_y) {DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl);
@@ -270,19 +311,11 @@ static void dbus_cursor_position(DisplayChangeListener *dcl, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); } -static void dbus_release_dmabuf (DisplayChangeListener *dcl, -QemuDmaBuf *dmabuf) -{ -dbus_scanout_disable (dcl); -} -static void dbus_scanout_update (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h) { -DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); - -dbus_call_update_gl (ddl, x, y, w, h); +dbus_call_update_gl (dcl, x, y, w, h); }static void dbus_gl_refresh (DisplayChangeListener *dcl)
@@ -296,19 +329,19 @@ static void dbus_gl_refresh(DisplayChangeListener *dcl) }if (ddl->gl_updates) { -dbus_call_update_gl (ddl,0 ,0 , +dbus_call_update_gl (dcl,0 ,0 ,surface_width (ddl->ds),surface_height (ddl->ds)); ddl->gl_updates =0 ; } } -#endif /* OPENGL & GBM */ +#endif /* OPENGL */ static void dbus_refresh (DisplayChangeListener *dcl) {graphic_hw_update (dcl->con); } -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +#ifdef CONFIG_OPENGL static void dbus_gl_gfx_update (DisplayChangeListener *dcl,int x,int y,int w,int h) {
@@ -382,7 +415,7 @@ static void dbus_gfx_update(DisplayChangeListener *dcl, DBUS_DEFAULT_TIMEOUT, NULL, NULL, NULL); } -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +#ifdef CONFIG_OPENGL static void dbus_gl_gfx_switch (DisplayChangeListener *dcl,struct DisplaySurface *new_surface) {
@@ -452,7 +485,7 @@ static void dbus_cursor_define(DisplayChangeListener *dcl, NULL); } -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +#ifdef CONFIG_OPENGL const DisplayChangeListenerOps dbus_gl_dcl_ops = { .dpy_name ="dbus-gl" , .dpy_gfx_update = dbus_gl_gfx_update,
@@ -464,10 +497,12 @@ const DisplayChangeListenerOps dbus_gl_dcl_ops = { .dpy_gl_scanout_disable = dbus_scanout_disable, .dpy_gl_scanout_texture = dbus_scanout_texture, +#ifdef CONFIG_GBM .dpy_gl_scanout_dmabuf = dbus_scanout_dmabuf, .dpy_gl_cursor_dmabuf = dbus_cursor_dmabuf, - .dpy_gl_cursor_position = dbus_cursor_position, .dpy_gl_release_dmabuf = dbus_release_dmabuf, +#endif + .dpy_gl_cursor_position = dbus_gl_cursor_position, .dpy_gl_update = dbus_scanout_update, };#endif
@@ -493,6 +528,9 @@ dbus_display_listener_dispose(GObject *object)#ifdef WIN32 g_clear_object (&ddl->map_proxy);g_clear_pointer (&ddl->peer_process, CloseHandle); +#ifdef CONFIG_OPENGL +egl_fb_destroy (&ddl->fb); +#endif #endif G_OBJECT_CLASS (dbus_display_listener_parent_class)->dispose (object);
@@ -504,7 +542,7 @@ dbus_display_listener_constructed(GObject *object)DBusDisplayListener *ddl =DBUS_DISPLAY_LISTENER (object); ddl->dcl.ops = &dbus_dcl_ops; -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +#ifdef CONFIG_OPENGL if (display_opengl) { ddl->dcl.ops = &dbus_gl_dcl_ops; }
ui/dbus.c +0 -4
@@ -47,10 +47,8 @@ static DBusDisplay *dbus_display;static QEMUGLContext dbus_create_context (DisplayGLCtx *dgc,QEMUGLParams *params) { -#ifdef CONFIG_GBM eglMakeCurrent (qemu_egl_display,EGL_NO_SURFACE ,EGL_NO_SURFACE , qemu_egl_rn_ctx); -#endif return qemu_egl_create_context (dgc, params); }
@@ -59,9 +57,7 @@ dbus_is_compatible_dcl(DisplayGLCtx *dgc, DisplayChangeListener *dcl) {return -#ifdef CONFIG_GBM dcl->ops == &dbus_gl_dcl_ops || -#endif dcl->ops == &dbus_console_dcl_ops; }
Signature · 1 line
2.40.1
PATCH 16/21 ui/dbus: add some GL traces
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- ui/dbus-listener.c | 6 ++++++ ui/trace-events | 3 +++ 2 files changed, 9 insertions(+)
ui/dbus-listener.c +6 -0
@@ -102,6 +102,8 @@ static void dbus_call_update_gl(DisplayChangeListener *dcl, {DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); +trace_dbus_update_gl (x, y, w, h); +glFlush ();#ifdef CONFIG_GBM graphic_hw_gl_block (ddl->dcl.con, true);
@@ -212,6 +214,8 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { +trace_dbus_scanout_texture (tex_id ,backing_y_0_top , +backing_width ,backing_height ,x ,y ,w ,h );#ifdef CONFIG_GBM QemuDmaBuf dmabuf = { .width = backing_width,
@@ -421,6 +425,8 @@ static void dbus_gl_gfx_switch(DisplayChangeListener *dcl, {DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); +trace_dbus_gl_gfx_switch (new_surface); + ddl->ds = new_surface;if (ddl->ds) {int width =surface_width (ddl->ds);
ui/trace-events +3 -0
@@ -155,6 +155,9 @@ dbus_mouse_release(unsigned int button) "button %u" dbus_mouse_set_pos(unsigned int x, unsigned int y) "x=%u, y=%u" dbus_mouse_rel_motion(int dx, int dy) "dx=%d, dy=%d" dbus_update(int x, int y, int w, int h) "x=%d, y=%d, w=%d, h=%d" +dbus_update_gl(int x, int y, int w, int h) "x=%d, y=%d, w=%d, h=%d" dbus_clipboard_grab_failed(void) "" dbus_clipboard_register(const char *bus_name) "peer %s" dbus_clipboard_unregister(const char *bus_name) "peer %s" +dbus_scanout_texture(uint32_t tex_id, bool backing_y_0_top, uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h) "tex_id:%u y0top:%d back:%ux%u %u+%u-%ux%u" +dbus_gl_gfx_switch(void *p) "surf: %p"
Signature · 1 line
2.40.1
PATCH 17/21 virtio-gpu-virgl: teach it to get the QEMU EGL display
In reply to [email protected]From: Marc-André Lureau <[email protected]>
virgl offers a few features that require to have access to the underlying EGLDisplay. This is the case for the D3D texture sharing support.
The API callback is merged for virgl 1.0:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1113
--- hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-virgl.c +16 -1
@@ -18,9 +18,17 @@#include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "ui/egl-helpers.h" +#include <virglrenderer.h> -static struct virgl_renderer_callbacks virtio_gpu_3d_cbs; +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +static void * +virgl_get_egl_display(G_GNUC_UNUSED void *cookie) +{ +return qemu_egl_display; +} +#endif static void virgl_cmd_create_resource_2d (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd)
@@ -608,6 +616,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) {int ret; +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +if (qemu_egl_display) { + virtio_gpu_3d_cbs.version =4 ; + virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display; + } +#endif + ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs);if (ret !=0 ) {error_report ("virgl could not be initialized: %d" , ret);
Signature · 1 line
2.40.1
Re: [PATCH 17/21] virtio-gpu-virgl: teach it to get the QEMU EGL display
Hi Marc-André,
I've been testing this, but I can't find where qemu_egl_display is set when using sdl.
Whil ui/gtk.c sets that in gl_area_realize, from my understanding there is no equivalent call in ui/sdl2-gl.c
Also, in which case SDL would use EGL, and is there a way to request that (e.g. as opposed to GLX)?
Kind regards,
Antonio Caggiano
Quoted 50 lines · On 06/06/2023 13:56, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
virgl offers a few features that require to have access to the underlying EGLDisplay. This is the case for the D3D texture sharing support.
The API callback is merged for virgl 1.0:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1113Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +16
-1@@ -18,9 +18,17 @@#include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "ui/egl-helpers.h" +#include <virglrenderer.h> -static struct virgl_renderer_callbacks virtio_gpu_3d_cbs; +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +static void * +virgl_get_egl_display(G_GNUC_UNUSED void *cookie) +{ +return qemu_egl_display; +} +#endif static void virgl_cmd_create_resource_2d (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd)@@ -608,6 +616,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) {int ret; +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +if (qemu_egl_display) { + virtio_gpu_3d_cbs.version =4 ; + virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display; + } +#endif + ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs);if (ret !=0 ) {error_report ("virgl could not be initialized: %d" , ret);
Re: [PATCH 17/21] virtio-gpu-virgl: teach it to get the QEMU EGL display
In reply to [email protected]Hi Marc-André,
I've been testing this, but I can't find where qemu_egl_display is set when using sdl.
Whil ui/gtk.c sets that in gl_area_realize, from my understanding there is no equivalent call in ui/sdl2-gl.c
Also, in which case SDL would use EGL, and is there a way to request that (e.g. as opposed to GLX)?
Kind regards,
Antonio Caggiano
Quoted 50 lines · On 06/06/2023 13:56, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
virgl offers a few features that require to have access to the underlying EGLDisplay. This is the case for the D3D texture sharing support.
The API callback is merged for virgl 1.0:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1113Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +16
-1@@ -18,9 +18,17 @@#include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "ui/egl-helpers.h" +#include <virglrenderer.h> -static struct virgl_renderer_callbacks virtio_gpu_3d_cbs; +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +static void * +virgl_get_egl_display(G_GNUC_UNUSED void *cookie) +{ +return qemu_egl_display; +} +#endif static void virgl_cmd_create_resource_2d (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd)@@ -608,6 +616,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) {int ret; +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +if (qemu_egl_display) { + virtio_gpu_3d_cbs.version =4 ; + virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display; + } +#endif + ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs);if (ret !=0 ) {error_report ("virgl could not be initialized: %d" , ret);
Re: [PATCH 17/21] virtio-gpu-virgl: teach it to get the QEMU EGL display
Hi Antonio
Quoted 11 lines · Antonio Caggiano
Hi Marc-André,
I've been testing this, but I can't find where
qemu_egl_displayis set when using sdl.Whil
ui/gtk.csets that ingl_area_realize, from my understanding there is no equivalent call inui/sdl2-gl.cAlso, in which case SDL would use EGL, and is there a way to request that (e.g. as opposed to GLX)?
I am not sure, it's a tricky question. It seems SDL will use EGL when requesting ES (-display sdl,gl=es), at least with x11 and wayland (and win32 iirc). There is also SDL_VIDEO_X11_FORCE_EGL.
Yes, some code is missing in sdl2.c to set qemu_egl_display so virgl can rely on it. Patches welcome!
Quoted 56 lines
Kind regards,
Antonio CaggianoQuoted 50 lines · On 06/06/2023 13:56, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
virgl offers a few features that require to have access to the underlying EGLDisplay. This is the case for the D3D texture sharing support.
The API callback is merged for virgl 1.0:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1113Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +16
-1@@ -18,9 +18,17 @@#include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "ui/egl-helpers.h" +#include <virglrenderer.h> -static struct virgl_renderer_callbacks virtio_gpu_3d_cbs; +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +static void * +virgl_get_egl_display(G_GNUC_UNUSED void *cookie) +{ +return qemu_egl_display; +} +#endif static void virgl_cmd_create_resource_2d (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd)@@ -608,6 +616,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) {int ret; +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +if (qemu_egl_display) { + virtio_gpu_3d_cbs.version =4 ; + virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display; + } +#endif + ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs);if (ret !=0 ) {error_report ("virgl could not be initialized: %d" , ret);
Re: [PATCH 17/21] virtio-gpu-virgl: teach it to get the QEMU EGL display
Thanks for your answer, that'll help.
Quoted 13 lines · Marc-André Lureau
Hi Antonio
Quoted 9 lines · Antonio Caggiano
Hi Marc-André,
I've been testing this, but I can't find where
qemu_egl_displayis set when using sdl.Whil
ui/gtk.csets that ingl_area_realize, from my understanding there is no equivalent call inui/sdl2-gl.c
Quoted 8 lines
Quoted 2 lines
Also, in which case SDL would use EGL, and is there a way to request that (e.g. as opposed to GLX)?
I am not sure, it's a tricky question. It seems SDL will use EGL when requesting ES (-display sdl,gl=es), at least with x11 and wayland (and win32 iirc). There is also
SDL_VIDEO_X11_FORCE_EGL>
Yes, some code is missing insdl2.cto setqemu_egl_displayso virgl can rely on it. Patches welcome!
Good, I'll take care of that.
Quoted 46 lines
Quoted 46 lines
Kind regards,
Antonio CaggianoQuoted 40 lines · On 06/06/2023 13:56, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
virgl offers a few features that require to have access to the underlying EGLDisplay. This is the case for the D3D texture sharing support.
The API callback is merged for virgl 1.0:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1113Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +9
-1@@ -18,9 +18,17 @@#include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "ui/egl-helpers.h" +#include <virglrenderer.h> -static struct virgl_renderer_callbacks virtio_gpu_3d_cbs; +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +static void * +virgl_get_egl_display(G_GNUC_UNUSED void *cookie) +{ +return qemu_egl_display; +} +#endif static void virgl_cmd_create_resource_2d (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd)@@ -608,6 +616,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) {int ret;
Quoted 12 lines
Quoted 11 lines
hw/display/virtio-gpu-virgl.c int virtio_gpu_virgl_init(VirtIOGPU *g) · line 628
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +7
-0+#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +if (qemu_egl_display) { + virtio_gpu_3d_cbs.version =4 ; + virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display; + } +#endif + ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs);if (ret !=0 ) {error_report ("virgl could not be initialized: %d" , ret);
Cheers,
Antonio Caggiano
PATCH 18/21 ui/egl: query ANGLE d3d device
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Check if ANGLE is being used with D3D backend.
--- include/ui/egl-helpers.h | 1 + ui/egl-helpers.c | 32 +++++++++++++++++++++++++++++++- ui/trace-events | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-)
include/ui/egl-helpers.h +1 -0
@@ -12,6 +12,7 @@extern EGLDisplay *qemu_egl_display;extern EGLConfig qemu_egl_config;extern DisplayGLMode qemu_egl_mode; +extern bool qemu_egl_angle_d3d; typedef struct egl_fb { int width;
ui/egl-helpers.c +31 -1
@@ -15,16 +15,19 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #include "qemu/osdep.h" +#include "qemu/drm.h" #include "qemu/error-report.h" #include "ui/console.h" #include "ui/egl-helpers.h" #include "sysemu/sysemu.h" #include "qapi/error.h" +#include "trace.h" EGLDisplay *qemu_egl_display;EGLConfig qemu_egl_config;DisplayGLMode qemu_egl_mode; +bool qemu_egl_angle_d3d;/* ------------------------------------------------------------------ */
@@ -555,7 +558,34 @@ int qemu_egl_init_dpy_win32(EGLNativeDisplayType dpy, DisplayGLMode mode)if (mode ==DISPLAYGL_MODE_ON ) { mode =DISPLAYGL_MODE_ES ; } - return qemu_egl_init_dpy(dpy, 0, mode); + +if (qemu_egl_init_dpy (dpy,0 , mode) <0 ) { +return -1 ; + } + +#ifdef EGL_D3D11_DEVICE_ANGLE +if (epoxy_has_egl_extension (qemu_egl_display,"EGL_EXT_device_query" )) { +EGLDeviceEXT device; +void *d3d11_device; + +if (!eglQueryDisplayAttribEXT (qemu_egl_display, +EGL_DEVICE_EXT , + (EGLAttrib *)&device)) { +return 0 ; + } + +if (!eglQueryDeviceAttribEXT (device, +EGL_D3D11_DEVICE_ANGLE , + (EGLAttrib *)&d3d11_device)) { +return 0 ; + } + +trace_egl_init_d3d11_device (device); + qemu_egl_angle_d3d = device !=NULL ; + } +#endif + + return 0; }#endif
ui/trace-events +3 -0
@@ -161,3 +161,6 @@ dbus_clipboard_register(const char *bus_name) "peer %s" dbus_clipboard_unregister(const char *bus_name) "peer %s" dbus_scanout_texture(uint32_t tex_id, bool backing_y_0_top, uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h) "tex_id:%u y0top:%d back:%ux%u %u+%u-%ux%u" dbus_gl_gfx_switch(void *p) "surf: %p" + +# egl-helpers.c +egl_init_d3d11_device(void *p) "d3d device: %p"
Signature · 1 line
2.40.1
PATCH 19/21 ui: add optional d3d texture pointer to scanout texture
In reply to [email protected]From: Marc-André Lureau <[email protected]>
The following patch will get the underlying D3D11 Texture2D from the virgl renderer scanout. Pass it along to the texture scanout callbacks as a priliminary step, to simplify review.
--- include/ui/console.h | 7 +++++-- include/ui/gtk.h | 6 ++++-- include/ui/sdl2.h | 3 ++- hw/display/virtio-gpu-virgl.c | 4 +++- ui/console.c | 11 +++++++---- ui/dbus-console.c | 3 ++- ui/dbus-listener.c | 5 +++-- ui/egl-headless.c | 5 +++-- ui/gtk-egl.c | 5 +++-- ui/gtk-gl-area.c | 5 +++-- ui/sdl2-gl.c | 3 ++- ui/spice-display.c | 3 ++- 12 files changed, 39 insertions(+), 21 deletions(-)
include/ui/console.h +5 -2
@@ -117,6 +117,7 @@ typedef struct ScanoutTexture {uint32_t y;uint32_t width;uint32_t height; +void *d3d_tex2d; } ScanoutTexture; typedef struct DisplaySurface {
@@ -255,7 +256,8 @@ typedef struct DisplayChangeListenerOps {uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h); + uint32_t w, uint32_t h, + void *d3d_tex2d);/* optional (default to true if has dpy_gl_scanout_dmabuf) */ bool (*dpy_has_dmabuf)(DisplayChangeListener *dcl);/* optional */
@@ -363,7 +365,8 @@ void dpy_gl_scanout_disable(QemuConsole *con);void dpy_gl_scanout_texture (QemuConsole *con,uint32_t backing_id,bool backing_y_0_top,uint32_t backing_width,uint32_t backing_height, -uint32_t x,uint32_t y,uint32_t w,uint32_t h); +uint32_t x,uint32_t y,uint32_t w,uint32_t h, +void *d3d_tex2d);void dpy_gl_scanout_dmabuf (QemuConsole *con,QemuDmaBuf *dmabuf); void dpy_gl_cursor_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf,
include/ui/gtk.h +4 -2
@@ -175,7 +175,8 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h); + uint32_t w, uint32_t h, + void *d3d_tex2d);void gd_egl_scanout_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf); void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl,
@@ -211,7 +212,8 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h); + uint32_t w, uint32_t h, + void *d3d_tex2d);void gd_gl_area_scanout_disable (DisplayChangeListener *dcl);void gd_gl_area_scanout_flush (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h);
include/ui/sdl2.h +2 -1
@@ -90,7 +90,8 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h); + uint32_t w, uint32_t h, + void *d3d_tex2d);void sdl2_gl_scanout_flush (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h);
hw/display/virtio-gpu-virgl.c +3 -1
@@ -154,6 +154,7 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, {struct virtio_gpu_set_scanout ss;struct virgl_renderer_resource_info info; +void *d3d_tex2d =NULL ;int ret;VIRTIO_GPU_FILL_CMD (ss);
@@ -186,7 +187,8 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, g->parent_obj.scanout[ss.scanout_id].con, info.tex_id, info.flags &VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP , info.width, info.height, - ss.r.x, ss.r.y, ss.r.width, ss.r.height); + ss.r.x, ss.r.y, ss.r.width, ss.r.height, + d3d_tex2d); }else {dpy_gfx_replace_surface ( g->parent_obj.scanout[ss.scanout_id].con,NULL );
ui/console.c +7 -4
@@ -1223,7 +1223,8 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl, con->scanout.texture.x, con->scanout.texture.y, con->scanout.texture.width, - con->scanout.texture.height); + con->scanout.texture.height, + con->scanout.texture.d3d_tex2d); } }
@@ -2050,7 +2051,8 @@ void dpy_gl_scanout_texture(QemuConsole *con,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t width, uint32_t height) + uint32_t width, uint32_t height, + void *d3d_tex2d) { DisplayState *s = con->ds;DisplayChangeListener *dcl;
@@ -2058,7 +2060,7 @@ void dpy_gl_scanout_texture(QemuConsole *con, con->scanout.kind =SCANOUT_TEXTURE ; con->scanout.texture = (ScanoutTexture ) { backing_id, backing_y_0_top, backing_width, backing_height, - x, y, width, height + x, y, width, height, d3d_tex2d, }; QLIST_FOREACH(dcl, &s->listeners, next) {if (con != (dcl->con ? dcl->con : active_console)) {
@@ -2068,7 +2070,8 @@ void dpy_gl_scanout_texture(QemuConsole *con, dcl->ops->dpy_gl_scanout_texture (dcl, backing_id, backing_y_0_top, backing_width, backing_height, - x, y, width, height); + x, y, width, height, + d3d_tex2d); } } }
ui/dbus-console.c +2 -1
@@ -95,7 +95,8 @@ dbus_gl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { DBusDisplayConsole *ddc = container_of(dcl, DBusDisplayConsole, dcl);
ui/dbus-listener.c +3 -2
@@ -212,7 +212,8 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) {trace_dbus_scanout_texture (tex_id ,backing_y_0_top ,backing_width ,backing_height ,x ,y ,w ,h );
@@ -434,7 +435,7 @@ static void dbus_gl_gfx_switch(DisplayChangeListener *dcl,/* TODO: lazy send dmabuf (there are unnecessary sent otherwise) */ dbus_scanout_texture (&ddl->dcl, ddl->ds->texture, false, - width, height, 0, 0, width, height); + width, height, 0, 0, width, height, NULL); } }#endif
ui/egl-headless.c +3 -2
@@ -61,7 +61,8 @@ static void egl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
@@ -91,7 +92,7 @@ static void egl_scanout_dmabuf(DisplayChangeListener *dcl,egl_scanout_texture (dcl, dmabuf->texture, false, dmabuf->width, dmabuf->height, -0 ,0 , dmabuf->width, dmabuf->height); +0 ,0 , dmabuf->width, dmabuf->height,NULL ); } static void egl_cursor_dmabuf(DisplayChangeListener *dcl,
ui/gtk-egl.c +3 -2
@@ -223,7 +223,8 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl, uint32_t backing_id, bool backing_y_0_top, uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
@@ -257,7 +258,7 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,gd_egl_scanout_texture (dcl, dmabuf->texture, dmabuf->y0_top, dmabuf->width, dmabuf->height, -0 ,0 , dmabuf->width, dmabuf->height); +0 ,0 , dmabuf->width, dmabuf->height,NULL );if (dmabuf->allow_fences) { vc->gfx.guest_fb.dmabuf = dmabuf;
ui/gtk-gl-area.c +3 -2
@@ -244,7 +244,8 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
@@ -299,7 +300,7 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,gd_gl_area_scanout_texture (dcl, dmabuf->texture, dmabuf->y0_top, dmabuf->width, dmabuf->height, -0 ,0 , dmabuf->width, dmabuf->height); +0 ,0 , dmabuf->width, dmabuf->height,NULL );if (dmabuf->allow_fences) { vc->gfx.guest_fb.dmabuf = dmabuf;
ui/sdl2-gl.c +2 -1
@@ -205,7 +205,8 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
ui/spice-display.c +2 -1
@@ -935,7 +935,8 @@ static void qemu_spice_gl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);EGLint stride =0 , fourcc =0 ;
Signature · 1 line
2.40.1
PATCH 20/21 virtio-gpu-virgl: use D3D11_SHARE_TEXTURE when available
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Enable D3D texture sharing when possible, and pass it to the texture display callbacks.
--- meson.build | 6 ++++++ hw/display/virtio-gpu-virgl.c | 24 +++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-)
meson.build +6 -0
@@ -1072,6 +1072,12 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu virgl = dependency('virglrenderer', method: 'pkg-config', required: get_option('virglrenderer')) + if virgl.found() + config_host_data.set('HAVE_VIRGL_D3D_INFO_EXT', + cc.has_member('struct virgl_renderer_resource_info_ext', 'd3d_tex2d', + prefix: '#include <virglrenderer.h>', + dependencies: virgl)) + endif endif blkio = not_found if not get_option('blkio').auto() or have_block
hw/display/virtio-gpu-virgl.c +19 -5
@@ -153,8 +153,6 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) {struct virtio_gpu_set_scanout ss; -struct virgl_renderer_resource_info info; -void *d3d_tex2d =NULL ;int ret;VIRTIO_GPU_FILL_CMD (ss);
@@ -169,10 +167,20 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, } g->parent_obj.enable =1 ; -memset (&info,0 ,sizeof (info)); -if (ss.resource_id && ss.r.width && ss.r.height) { +struct virgl_renderer_resource_info info; +void *d3d_tex2d =NULL ; + +#ifdef HAVE_VIRGL_D3D_INFO_EXT +struct virgl_renderer_resource_info_ext ext; +memset (&ext,0 ,sizeof (ext)); + ret =virgl_renderer_resource_get_info_ext (ss.resource_id, &ext); + info = ext.base; + d3d_tex2d = ext.d3d_tex2d; +#else +memset (&info,0 ,sizeof (info)); ret =virgl_renderer_resource_get_info (ss.resource_id, &info); +#endif if (ret ==-1 ) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\n",
@@ -617,6 +625,7 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g)int virtio_gpu_virgl_init (VirtIOGPU *g) {int ret; +uint32_t flags =0 ;#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 if (qemu_egl_display) {
@@ -624,8 +633,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display; }#endif +#ifdef VIRGL_RENDERER_D3D11_SHARE_TEXTURE +if (qemu_egl_angle_d3d) { + flags |=VIRGL_RENDERER_D3D11_SHARE_TEXTURE ; + } +#endif - ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs); + ret =virgl_renderer_init (g, flags, &virtio_gpu_3d_cbs);if (ret !=0 ) {error_report ("virgl could not be initialized: %d" , ret);return ret;
Signature · 1 line
2.40.1
PATCH 21/21 ui/dbus: use shared D3D11 Texture2D when possible
In reply to [email protected]From: Marc-André Lureau <[email protected]>
When the client implements "org.qemu.Display1.Listener.Win32.D3d11" and we are running on ANGLE/win32, share the scanout texture with the peer process, and draw with ScanoutTexture2d/UpdateTexture2d methods.
--- ui/dbus-listener.c | 299 ++++++++++++++++++++++++++++++++++++++----- ui/dbus-display1.xml | 56 +++++++- 2 files changed, 324 insertions(+), 31 deletions(-)
ui/dbus-listener.c +270 -29
@@ -23,11 +23,16 @@*/ #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qapi/error.h" #include "sysemu/sysemu.h" #include "dbus.h" #ifdef G_OS_UNIX #include <gio/gunixfdlist.h> #endif +#ifdef WIN32 +#include <d3d11.h> +#include <dxgi1_2.h> +#endif #ifdef CONFIG_OPENGL #include "ui/shader.h"
@@ -39,6 +44,12 @@static void dbus_gfx_switch (DisplayChangeListener *dcl,struct DisplaySurface *new_surface); +enum share_kind { +SHARE_KIND_NONE , +SHARE_KIND_MAPPED , +SHARE_KIND_D3DTEX , +}; +struct _DBusDisplayListener {GObject parent;
@@ -50,6 +61,8 @@ struct _DBusDisplayListener {DisplayChangeListener dcl;DisplaySurface *ds; +enum share_kind ds_share; +int gl_updates;bool ds_mapped;
@@ -57,7 +70,9 @@ struct _DBusDisplayListener {#ifdef WIN32 QemuDBusDisplay1ListenerWin32Map *map_proxy; +QemuDBusDisplay1ListenerWin32D3d11 *d3d11_proxy;HANDLE peer_process; +ID3D11Texture2D *d3d_texture;#ifdef CONFIG_OPENGL egl_fb fb;#endif
@@ -74,28 +89,120 @@ static void dbus_scanout_disable(DisplayChangeListener *dcl) {DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); - ddl->ds =NULL ;qemu_dbus_display1_listener_call_disable ( ddl->proxy,G_DBUS_CALL_FLAGS_NONE ,-1 ,NULL ,NULL ,NULL ); } -#ifdef CONFIG_GBM +#ifdef WIN32 +static bool d3d_texture2d_share (ID3D11Texture2D *d3d_texture, +HANDLE *handle,Error **errp) +{ +IDXGIResource1 *dxgiResource =NULL ; +HRESULT hr; + + hr = d3d_texture->lpVtbl->QueryInterface (d3d_texture, + &IID_IDXGIResource1, + (void **)&dxgiResource); +if (FAILED (hr)) { + goto fail; + } + + hr = dxgiResource->lpVtbl->CreateSharedHandle ( + dxgiResource, +NULL , +DXGI_SHARED_RESOURCE_READ |DXGI_SHARED_RESOURCE_WRITE , +NULL , + handle + ); + + dxgiResource->lpVtbl->Release (dxgiResource); + +if (SUCCEEDED (hr)) { +return true; + } + +fail: +error_setg_win32 (errp,GetLastError (),"failed to create shared handle" ); +return false; +} + +static bool d3d_texture2d_acquire0 (ID3D11Texture2D *d3d_texture,Error **errp) +{ +IDXGIKeyedMutex *dxgiMutex =NULL ; +HRESULT hr; + + hr = d3d_texture->lpVtbl->QueryInterface (d3d_texture, + &IID_IDXGIKeyedMutex, + (void **)&dxgiMutex); +if (FAILED (hr)) { + goto fail; + } + + hr = dxgiMutex->lpVtbl->AcquireSync (dxgiMutex,0 ,INFINITE ); + + dxgiMutex->lpVtbl->Release (dxgiMutex); + +if (SUCCEEDED (hr)) { +return true; + } + +fail: +error_setg_win32 (errp,GetLastError (),"failed to acquire texture mutex" ); +return false; +} + +static bool d3d_texture2d_release0 (ID3D11Texture2D *d3d_texture,Error **errp) +{ +IDXGIKeyedMutex *dxgiMutex =NULL ; +HRESULT hr; + + hr = d3d_texture->lpVtbl->QueryInterface (d3d_texture, + &IID_IDXGIKeyedMutex, + (void **)&dxgiMutex); +if (FAILED (hr)) { + goto fail; + } + + hr = dxgiMutex->lpVtbl->ReleaseSync (dxgiMutex,0 ); + + dxgiMutex->lpVtbl->Release (dxgiMutex); + +if (SUCCEEDED (hr)) { +return true; + } + +fail: +error_setg_win32 (errp,GetLastError (),"failed to release texture mutex" ); +return false; +} +#endif /* WIN32 */ +static void dbus_update_gl_cb (GObject *source_object, -GAsyncResult *res, -gpointer user_data) +GAsyncResult *res, +gpointer user_data) {g_autoptr (GError) err =NULL ;DBusDisplayListener *ddl = user_data; +bool success; + +#ifdef CONFIG_GBM + success =qemu_dbus_display1_listener_call_update_dmabuf_finish ( + ddl->proxy, res, &err); +#endif + +#ifdef WIN32 + success =qemu_dbus_display1_listener_win32_d3d11_call_update_texture2d_finish ( + ddl->d3d11_proxy, res, &err); +d3d_texture2d_acquire0 (ddl->d3d_texture, &error_warn); +#endif -if (!qemu_dbus_display1_listener_call_update_dmabuf_finish (ddl->proxy, - res, &err)) { +if (!success) {error_report ("Failed to call update: %s" , err->message); }graphic_hw_gl_block (ddl->dcl.con, false);g_object_unref (ddl); } -#endif static void dbus_call_update_gl (DisplayChangeListener *dcl,int x,int y,int w,int h)
@@ -116,8 +223,31 @@ static void dbus_call_update_gl(DisplayChangeListener *dcl,#endif #ifdef WIN32 -egl_fb_read_rect (ddl->ds, &ddl->fb, x, y, w, h); -dbus_gfx_update (dcl, x, y, w, h); +switch (ddl->ds_share) { +case SHARE_KIND_MAPPED : +egl_fb_read_rect (ddl->ds, &ddl->fb, x, y, w, h); +dbus_gfx_update (dcl, x, y, w, h); +break ; +case SHARE_KIND_D3DTEX : +Error *err =NULL ; +assert (ddl->d3d_texture); + +graphic_hw_gl_block (ddl->dcl.con, true); +if (!d3d_texture2d_release0 (ddl->d3d_texture, &err)) { +error_report_err (err); +return ; + } +qemu_dbus_display1_listener_win32_d3d11_call_update_texture2d ( + ddl->d3d11_proxy, + x, y, w, h, +G_DBUS_CALL_FLAGS_NONE , +DBUS_DEFAULT_TIMEOUT ,NULL , + dbus_update_gl_cb, +g_object_ref (ddl)); +break ; +default : +g_warn_if_reached (); + }#endif }
@@ -160,7 +290,7 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl)BOOL success;HANDLE target_handle; -if (ddl->ds_mapped) { +if (ddl->ds_share ==SHARE_KIND_MAPPED ) {return true; }
@@ -199,7 +329,69 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl)return false; } - ddl->ds_mapped = true; + ddl->ds_share =SHARE_KIND_MAPPED ; + +return true; +} + +static bool +dbus_scanout_share_d3d_texture ( +DBusDisplayListener *ddl, +ID3D11Texture2D *tex, +bool backing_y_0_top, +uint32_t backing_width, +uint32_t backing_height, +uint32_t x,uint32_t y, +uint32_t w,uint32_t h) +{ +Error *err =NULL ; +BOOL success; +HANDLE share_handle, target_handle; + +if (!d3d_texture2d_release0 (tex, &err)) { +error_report_err (err); +return false; + } + +if (!d3d_texture2d_share (tex, &share_handle, &err)) { +error_report_err (err); +return false; + } + + success =DuplicateHandle ( +GetCurrentProcess (), + share_handle, + ddl->peer_process, + &target_handle, +0 , + FALSE,DUPLICATE_SAME_ACCESS ); +if (!success) { + g_autofree char *msg = g_win32_error_message(GetLastError()); +g_debug ("Failed to DuplicateHandle: %s" , msg); +CloseHandle (share_handle); +return false; + } + +qemu_dbus_display1_listener_win32_d3d11_call_scanout_texture2d ( + ddl->d3d11_proxy, +GPOINTER_TO_INT (target_handle), + backing_width, + backing_height, + backing_y_0_top, + x, y, w, h, +G_DBUS_CALL_FLAGS_NONE , +-1 , +NULL ,NULL ,NULL ); + +CloseHandle (share_handle); + +if (!d3d_texture2d_acquire0 (tex, &err)) { +error_report_err (err); +return false; + } + + ddl->d3d_texture = tex; + ddl->ds_share =SHARE_KIND_D3DTEX ;return true; }
@@ -248,7 +440,14 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl,/* there must be a matching gfx_switch before */ assert (surface_width (ddl->ds) == w);assert (surface_height (ddl->ds) == h); -egl_fb_setup_for_tex (&ddl->fb, backing_width, backing_height, tex_id, false); + +if (d3d_tex2d) { +dbus_scanout_share_d3d_texture (ddl, d3d_tex2d, backing_y_0_top, + backing_width, backing_height, x, y, w, h); + }else { +dbus_scanout_map (ddl); +egl_fb_setup_for_tex (&ddl->fb, backing_width, backing_height, tex_id, false); + }#endif }
@@ -429,6 +628,7 @@ static void dbus_gl_gfx_switch(DisplayChangeListener *dcl,trace_dbus_gl_gfx_switch (new_surface); ddl->ds = new_surface; + ddl->ds_share =SHARE_KIND_NONE ;if (ddl->ds) {int width =surface_width (ddl->ds);int height =surface_height (ddl->ds);
@@ -446,13 +646,7 @@ static void dbus_gfx_switch(DisplayChangeListener *dcl,DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); ddl->ds = new_surface; -#ifdef WIN32 - ddl->ds_mapped = false; -#endif -if (!ddl->ds) { -/* why not call disable instead? */ -return ; - } + ddl->ds_share =SHARE_KIND_NONE ; } static void dbus_mouse_set(DisplayChangeListener *dcl,
@@ -534,6 +728,7 @@ dbus_display_listener_dispose(GObject *object)g_clear_object (&ddl->proxy);#ifdef WIN32 g_clear_object (&ddl->map_proxy); +g_clear_object (&ddl->d3d11_proxy);g_clear_pointer (&ddl->peer_process, CloseHandle);#ifdef CONFIG_OPENGL egl_fb_destroy (&ddl->fb);
@@ -598,12 +793,10 @@ dbus_display_listener_implements(DBusDisplayListener *ddl, const char *iface)return implements; } -#endif -static void -dbus_display_listener_setup_shared_map (DBusDisplayListener *ddl) +static bool +dbus_display_listener_setup_peer_process (DBusDisplayListener *ddl) { -#ifdef WIN32 g_autoptr (GError) err =NULL ;GDBusConnection *conn;GIOStream *stream;
@@ -611,15 +804,15 @@ dbus_display_listener_setup_shared_map(DBusDisplayListener *ddl)g_autoptr (GCredentials) creds =NULL ;DWORD *pid; -if (!dbus_display_listener_implements (ddl,"org.qemu.Display1.Listener.Win32.Map" )) { -return ; +if (ddl->peer_process) { +return true; } conn =g_dbus_proxy_get_connection (G_DBUS_PROXY (ddl->proxy)); stream =g_dbus_connection_get_stream (conn);if (!G_IS_UNIX_CONNECTION (stream)) { -return ; +return false; } sock =g_socket_connection_get_socket (G_SOCKET_CONNECTION (stream));
@@ -627,14 +820,14 @@ dbus_display_listener_setup_shared_map(DBusDisplayListener *ddl)if (!creds) {g_debug ("Failed to get peer credentials: %s" , err->message); -return ; +return false; } pid =g_credentials_get_native (creds,G_CREDENTIALS_TYPE_WIN32_PID );if (pid ==NULL ) {g_debug ("Failed to get peer PID" ); -return ; +return false; } ddl->peer_process = OpenProcess(
@@ -644,11 +837,58 @@ dbus_display_listener_setup_shared_map(DBusDisplayListener *ddl)if (!ddl->peer_process) { g_autofree char *msg = g_win32_error_message(GetLastError());g_debug ("Failed to OpenProcess: %s" , msg); +return false; + } + +return true; +} +#endif + +static void +dbus_display_listener_setup_d3d11 (DBusDisplayListener *ddl) +{ +#ifdef WIN32 +g_autoptr (GError) err =NULL ; + +if (!dbus_display_listener_implements (ddl, +"org.qemu.Display1.Listener.Win32.D3d11" )) { +return ; + } + +if (!dbus_display_listener_setup_peer_process (ddl)) { +return ; + } + + ddl->d3d11_proxy = +qemu_dbus_display1_listener_win32_d3d11_proxy_new_sync (ddl->conn, +G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START , +NULL , +"/org/qemu/Display1/Listener" , +NULL , + &err); +if (!ddl->d3d11_proxy) { +g_debug ("Failed to setup win32 d3d11 proxy: %s" , err->message); +return ; + } +#endif +} + +static void +dbus_display_listener_setup_shared_map (DBusDisplayListener *ddl) +{ +#ifdef WIN32 +g_autoptr (GError) err =NULL ; + +if (!dbus_display_listener_implements (ddl,"org.qemu.Display1.Listener.Win32.Map" )) { +return ; + } + +if (!dbus_display_listener_setup_peer_process (ddl)) {return ; } ddl->map_proxy = - qemu_dbus_display1_listener_win32_map_proxy_new_sync(conn, + qemu_dbus_display1_listener_win32_map_proxy_new_sync(ddl->conn, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, "/org/qemu/Display1/Listener",
@@ -692,6 +932,7 @@ dbus_display_listener_new(const char *bus_name, ddl->console = console;dbus_display_listener_setup_shared_map (ddl); +dbus_display_listener_setup_d3d11 (ddl); con =qemu_console_lookup_by_index (dbus_display_console_get_index (console));assert (con);
ui/dbus-display1.xml +54 -2
68 lines not on this page · raw message
Signature · 1 line
2.40.1