From nobody Thu Oct 31 00:19:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612277425; cv=none; d=zohomail.com; s=zohoarc; b=aeyYvfkcD9e5a/h8KBGA8Qmo/vzQoBAoUpHvzNz6r9pWq2UNmpRmRACXYHvf/cuD7J/aVPxlX+2rAB4r5/npDNd3ux3gqwkUA3I6iSP6lHglcV5v4JRSn7z8p9uwkwZLCgr1gSR9kg/Hr44LjCG+Zsr98Z1AGcWOXVk1otqO6Oo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612277425; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eFvI+HYDT/uNmb9gv/g+8Wj2/+by2z6yvIFI5ecFucY=; b=XGMfxesoGJbqKmuSjTZsVPgq/MXdujXgr2IY7RtlU3OTjOl/UpcvXZI6gtCA7jgtmFq6smmgXJsnvsHm/JlK0pdTgxhEOYPNDsHWnJkrmMJjGbhllxu6zNEtO5/noP8MMU1WxVddLoZqtaorXDwmV57RWhjf9wOWLXJ7MJN2W+Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612277425907713.8228496248911; Tue, 2 Feb 2021 06:50:25 -0800 (PST) Received: from localhost ([::1]:60628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6x0a-00011F-Df for importer@patchew.org; Tue, 02 Feb 2021 09:50:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6whg-00059p-J5 for qemu-devel@nongnu.org; Tue, 02 Feb 2021 09:30:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46819) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6whe-0004Y8-Fk for qemu-devel@nongnu.org; Tue, 02 Feb 2021 09:30:52 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-452-_WVTgapfOHWfBkRHP6l0BQ-1; Tue, 02 Feb 2021 09:30:47 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3993C7424 for ; Tue, 2 Feb 2021 14:30:25 +0000 (UTC) Received: from localhost (unknown [10.36.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A25562A02; Tue, 2 Feb 2021 14:30:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612276249; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eFvI+HYDT/uNmb9gv/g+8Wj2/+by2z6yvIFI5ecFucY=; b=b1QHAo39XRzXNcp7Km9kAagLOd8+8qV4Y/pKybTVFb60oNI3LSdYgXB4gkIjuOSbTKOAXg bbkiJ+x5xBTJAcKM18zwaPAfKn7UZnfodb4ryvzZRdfZIeH6MaH/x1qufBQm9ylYyQr4XP DhzVKkLtmfvp8ixuS/VX0KS0C9Q7AsY= X-MC-Unique: _WVTgapfOHWfBkRHP6l0BQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 18/20] display/ui: add a callback to indicate GL state is flushed Date: Tue, 2 Feb 2021 18:26:23 +0400 Message-Id: <20210202142625.609070-19-marcandre.lureau@redhat.com> In-Reply-To: <20210202142625.609070-1-marcandre.lureau@redhat.com> References: <20210202142625.609070-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Displaying rendered resources requires blocking qemu GPU to avoid extra framebuffer copies. For an external display, via Spice currently, there is a callback to block/unblock the rendering in the same thread. But with the vhost-user-gpu backend, the qemu process doesn't handle the rendering itself, and the blocking callback isn't effective. Instead, the backend must be notified when the display code is done. Fix this by adding a new GraphicHwOps callback to indicate the GL state is flushed, and we are done manipulating the shared GL resources. Call it from gtk and spice display. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/hw/virtio/virtio-gpu.h | 2 +- include/ui/console.h | 2 ++ hw/display/vhost-user-gpu.c | 4 ++-- hw/display/virtio-gpu-base.c | 17 ++++++++++++----- hw/display/virtio-gpu.c | 4 ++-- hw/display/virtio-vga.c | 11 +++++++++++ ui/console.c | 9 +++++++++ ui/gtk-egl.c | 3 +++ ui/gtk-gl-area.c | 3 +++ ui/sdl2-gl.c | 2 ++ ui/spice-display.c | 1 + 11 files changed, 48 insertions(+), 10 deletions(-) diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 0043268e90..fae149235c 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -121,7 +121,7 @@ struct VirtIOGPUBase { struct VirtIOGPUBaseClass { VirtioDeviceClass parent; =20 - void (*gl_unblock)(VirtIOGPUBase *g); + void (*gl_flushed)(VirtIOGPUBase *g); }; =20 #define VIRTIO_GPU_BASE_PROPERTIES(_state, _conf) \ diff --git a/include/ui/console.h b/include/ui/console.h index 875885d9c7..d30e972d0b 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -387,6 +387,7 @@ typedef struct GraphicHwOps { void (*update_interval)(void *opaque, uint64_t interval); int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info); void (*gl_block)(void *opaque, bool block); + void (*gl_flushed)(void *opaque); } GraphicHwOps; =20 QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head, @@ -402,6 +403,7 @@ void graphic_hw_update_done(QemuConsole *con); void graphic_hw_invalidate(QemuConsole *con); void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata); void graphic_hw_gl_block(QemuConsole *con, bool block); +void graphic_hw_gl_flushed(QemuConsole *con); =20 void qemu_console_early_init(void); =20 diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index b7bde9feb6..4d8cb3525b 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -360,7 +360,7 @@ vhost_user_gpu_update_blocked(VhostUserGPU *g, bool blo= cked) } =20 static void -vhost_user_gpu_gl_unblock(VirtIOGPUBase *b) +vhost_user_gpu_gl_flushed(VirtIOGPUBase *b) { VhostUserGPU *g =3D VHOST_USER_GPU(b); =20 @@ -578,7 +578,7 @@ vhost_user_gpu_class_init(ObjectClass *klass, void *dat= a) VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); VirtIOGPUBaseClass *vgc =3D VIRTIO_GPU_BASE_CLASS(klass); =20 - vgc->gl_unblock =3D vhost_user_gpu_gl_unblock; + vgc->gl_flushed =3D vhost_user_gpu_gl_flushed; =20 vdc->realize =3D vhost_user_gpu_device_realize; vdc->reset =3D vhost_user_gpu_reset; diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c index 82c37aac62..6d6b5eed63 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -97,21 +97,27 @@ static int virtio_gpu_ui_info(void *opaque, uint32_t id= x, QemuUIInfo *info) } =20 static void -virtio_gpu_gl_block(void *opaque, bool block) +virtio_gpu_gl_flushed(void *opaque) { VirtIOGPUBase *g =3D opaque; VirtIOGPUBaseClass *vgc =3D VIRTIO_GPU_BASE_GET_CLASS(g); =20 + if (vgc->gl_flushed) { + vgc->gl_flushed(g); + } +} + +static void +virtio_gpu_gl_block(void *opaque, bool block) +{ + VirtIOGPUBase *g =3D opaque; + if (block) { g->renderer_blocked++; } else { g->renderer_blocked--; } assert(g->renderer_blocked >=3D 0); - - if (g->renderer_blocked =3D=3D 0) { - vgc->gl_unblock(g); - } } =20 static int @@ -136,6 +142,7 @@ static const GraphicHwOps virtio_gpu_ops =3D { .text_update =3D virtio_gpu_text_update, .ui_info =3D virtio_gpu_ui_info, .gl_block =3D virtio_gpu_gl_block, + .gl_flushed =3D virtio_gpu_gl_flushed, }; =20 bool diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 7eb4265a6d..2e4a9822b6 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -850,7 +850,7 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g) g->processing_cmdq =3D false; } =20 -static void virtio_gpu_gl_unblock(VirtIOGPUBase *b) +static void virtio_gpu_gl_flushed(VirtIOGPUBase *b) { VirtIOGPU *g =3D VIRTIO_GPU(b); =20 @@ -1257,7 +1257,7 @@ static void virtio_gpu_class_init(ObjectClass *klass,= void *data) VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); VirtIOGPUBaseClass *vgc =3D VIRTIO_GPU_BASE_CLASS(klass); =20 - vgc->gl_unblock =3D virtio_gpu_gl_unblock; + vgc->gl_flushed =3D virtio_gpu_gl_flushed; vdc->realize =3D virtio_gpu_device_realize; vdc->reset =3D virtio_gpu_reset; vdc->get_config =3D virtio_gpu_get_config; diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c index b071909b68..d3c6404061 100644 --- a/hw/display/virtio-vga.c +++ b/hw/display/virtio-vga.c @@ -68,6 +68,16 @@ static void virtio_vga_base_gl_block(void *opaque, bool = block) } } =20 +static void virtio_vga_base_gl_flushed(void *opaque) +{ + VirtIOVGABase *vvga =3D opaque; + VirtIOGPUBase *g =3D vvga->vgpu; + + if (g->hw_ops->gl_flushed) { + g->hw_ops->gl_flushed(g); + } +} + static int virtio_vga_base_get_flags(void *opaque) { VirtIOVGABase *vvga =3D opaque; @@ -83,6 +93,7 @@ static const GraphicHwOps virtio_vga_base_ops =3D { .text_update =3D virtio_vga_base_text_update, .ui_info =3D virtio_vga_base_ui_info, .gl_block =3D virtio_vga_base_gl_block, + .gl_flushed =3D virtio_vga_base_gl_flushed, }; =20 static const VMStateDescription vmstate_virtio_vga_base =3D { diff --git a/ui/console.c b/ui/console.c index 47124e8cad..0de287713f 100644 --- a/ui/console.c +++ b/ui/console.c @@ -294,6 +294,15 @@ void graphic_hw_gl_block(QemuConsole *con, bool block) } } =20 +void graphic_hw_gl_flushed(QemuConsole *con) +{ + assert(con !=3D NULL); + + if (con->hw_ops->gl_flushed) { + con->hw_ops->gl_flushed(con->hw); + } +} + int qemu_console_get_window_id(QemuConsole *con) { return con->window_id; diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index 71c3d698b4..588e7b1bb1 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -92,6 +92,9 @@ void gd_egl_draw(VirtualConsole *vc) vc->gfx.scale_x =3D (double)ww / surface_width(vc->gfx.ds); vc->gfx.scale_y =3D (double)wh / surface_height(vc->gfx.ds); } + + glFlush(); + graphic_hw_gl_flushed(vc->gfx.dcl.con); } =20 void gd_egl_update(DisplayChangeListener *dcl, diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c index 72bcd94918..e7ca73c7b1 100644 --- a/ui/gtk-gl-area.c +++ b/ui/gtk-gl-area.c @@ -70,6 +70,9 @@ void gd_gl_area_draw(VirtualConsole *vc) surface_gl_setup_viewport(vc->gfx.gls, vc->gfx.ds, ww, wh); surface_gl_render_texture(vc->gfx.gls, vc->gfx.ds); } + + glFlush(); + graphic_hw_gl_flushed(vc->gfx.dcl.con); } =20 void gd_gl_area_update(DisplayChangeListener *dcl, diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c index 82139ba49e..fd594d7461 100644 --- a/ui/sdl2-gl.c +++ b/ui/sdl2-gl.c @@ -58,6 +58,7 @@ static void sdl2_gl_render_surface(struct sdl2_console *s= con) =20 surface_gl_render_texture(scon->gls, scon->surface); SDL_GL_SwapWindow(scon->real_window); + graphic_hw_gl_flushed(scon->dcl.con); } =20 void sdl2_gl_update(DisplayChangeListener *dcl, @@ -240,4 +241,5 @@ void sdl2_gl_scanout_flush(DisplayChangeListener *dcl, egl_fb_blit(&scon->win_fb, &scon->guest_fb, !scon->y0_top); =20 SDL_GL_SwapWindow(scon->real_window); + graphic_hw_gl_flushed(dcl->con); } diff --git a/ui/spice-display.c b/ui/spice-display.c index 6a5e189a67..7247a93924 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -826,6 +826,7 @@ static void qemu_spice_gl_unblock_bh(void *opaque) SimpleSpiceDisplay *ssd =3D opaque; =20 qemu_spice_gl_block(ssd, false); + graphic_hw_gl_flushed(ssd->dcl.con); } =20 static void qemu_spice_gl_block_timer(void *opaque) --=20 2.29.0