From nobody Tue May 14 22:44:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1709764070; cv=none; d=zohomail.com; s=zohoarc; b=YDIJsfTkTwaMKzAauD3CyQ4ewmNQSfccoDgw6GLESompmoX+nc8N98QEsx4/ndy7VchIBcrFYJyPf/zDLIyxu6KBI0Ma5PVGSOpg0a04pVwbevrNPTcpcj8d9MAegsFDJH+ZH7/eUGuwJxHJunJ+1ifyKn5hZtAm2WCb+4VOLnc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709764070; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=8mTMZZuOS79w8DqjOfbbP3RKkJZqMfQqHKILMLVfiU0=; b=EcDJU9Lfvcfo9pmu+ZLC/Qq1cC311FhVsI8nk8Ur1S/btqxY8u4R8+G1xk3VvONaC394Wf7untUhHNGIoeKToZuPCJkMwjQf5MMhdVxGW62k2iGSAmfECALoSGBOM5EuKJ3g4MRlNp/h1POWy1r669PnDPqdVH4R2gz46aGCv2o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170976407066480.15625181555151; Wed, 6 Mar 2024 14:27:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhziw-0006Fu-90; Wed, 06 Mar 2024 17:26:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhziu-0006Fc-Ev for qemu-devel@nongnu.org; Wed, 06 Mar 2024 17:26:52 -0500 Received: from mgamail.intel.com ([198.175.65.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhzis-0001q6-4y for qemu-devel@nongnu.org; Wed, 06 Mar 2024 17:26:52 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 14:26:45 -0800 Received: from dongwonk-z390-aorus-ultra.fm.intel.com ([10.105.129.124]) by fmviesa009.fm.intel.com with ESMTP; 06 Mar 2024 14:26:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709764011; x=1741300011; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=RrARhO2dmUsgC4o+SC6z0Izhmm3hFZPqY74ISjvlfXM=; b=e9xnZd+51F8ZsZTT1wCKaS9K5IwoxW0P5wycWfQFRfezuVJt+hWt0Fsr ldHpkMGI6t7pihlFzA0grk6t5hWWS79UdCYC/6eRsHxbtQMt9MmWFVfT0 Jr9GaA4/U/Q2FIJPnySezF/f7V8Lf9X1AOZvVira9mQSr65s+kLx+dW+G pDVkmht0pXouRhxjNwbOXuH8fOuIDp2Z8oO1nyUGXGZwsL/ArYYaL0HB5 d0q2/vrzZpSXe063fFMs6uVoZwyGvjKuYh83gUcJ4y0IW3GsILleSgvgf j6zsv+LkjHWJE2MDhpUh75gQl1OeQAAj41Rucsr+zK9N/xLLwI5Gxjkd1 g==; X-IronPort-AV: E=McAfee;i="6600,9927,11005"; a="8223863" X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="8223863" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="9785416" From: dongwon.kim@intel.com To: qemu-devel@nongnu.org Subject: [PATCH v3] ui/gtk: flush display pipeline before saving vmstate when blob=true Date: Wed, 6 Mar 2024 14:25:23 -0800 Message-Id: <20240306222523.3236832-1-dongwon.kim@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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=198.175.65.14; envelope-from=dongwon.kim@intel.com; helo=mgamail.intel.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.365, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1709764072468100003 From: Dongwon Kim If the guest state is paused before it gets a response for the current scanout frame submission (resource-flush), it won't flush new frames after being restored as it still waits for the old response, which is accepted as a scanout render done signal. So it's needed to unblock the current scanout render pipeline before the run state is changed to make sure the guest receives the response for the current frame submission. v2: Giving some time for the fence to be signaled before flushing the pipeline v3: Prevent redundant call of gd_hw_gl_flushed by checking dmabuf and fence_fd >=3D 0 in it (e.g. during and after eglClientWaitSync in gd_change_runstate). Destroy sync object later in gd_hw_fl_flushed Cc: Marc-Andr=C3=A9 Lureau Cc: Vivek Kasireddy Signed-off-by: Dongwon Kim --- ui/egl-helpers.c | 2 -- ui/gtk.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c index 3d19dbe382..a77f9e57d9 100644 --- a/ui/egl-helpers.c +++ b/ui/egl-helpers.c @@ -385,8 +385,6 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf) if (dmabuf->sync) { dmabuf->fence_fd =3D eglDupNativeFenceFDANDROID(qemu_egl_display, dmabuf->sync); - eglDestroySyncKHR(qemu_egl_display, dmabuf->sync); - dmabuf->sync =3D NULL; } } =20 diff --git a/ui/gtk.c b/ui/gtk.c index 810d7fc796..eaca890cba 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -597,10 +597,14 @@ void gd_hw_gl_flushed(void *vcon) VirtualConsole *vc =3D vcon; QemuDmaBuf *dmabuf =3D vc->gfx.guest_fb.dmabuf; =20 - qemu_set_fd_handler(dmabuf->fence_fd, NULL, NULL, NULL); - close(dmabuf->fence_fd); - dmabuf->fence_fd =3D -1; - graphic_hw_gl_block(vc->gfx.dcl.con, false); + if (dmabuf && dmabuf->fence_fd >=3D 0) { + qemu_set_fd_handler(dmabuf->fence_fd, NULL, NULL, NULL); + close(dmabuf->fence_fd); + dmabuf->fence_fd =3D -1; + eglDestroySyncKHR(qemu_egl_display, dmabuf->sync); + dmabuf->sync =3D NULL; + graphic_hw_gl_block(vc->gfx.dcl.con, false); + } } =20 /** DisplayState Callbacks (opengl version) **/ @@ -678,6 +682,25 @@ static const DisplayGLCtxOps egl_ctx_ops =3D { static void gd_change_runstate(void *opaque, bool running, RunState state) { GtkDisplayState *s =3D opaque; + int i; + + if (state =3D=3D RUN_STATE_SAVE_VM) { + for (i =3D 0; i < s->nb_vcs; i++) { + VirtualConsole *vc =3D &s->vc[i]; + + if (vc->gfx.guest_fb.dmabuf && + vc->gfx.guest_fb.dmabuf->fence_fd >=3D 0) { + eglClientWaitSync(qemu_egl_display, + vc->gfx.guest_fb.dmabuf->sync, + EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, + 100000000); + + /* force flushing current scanout blob rendering process + * just in case the fence is still not signaled */ + gd_hw_gl_flushed(vc); + } + } + } =20 gd_update_caption(s); } --=20 2.34.1