From nobody Sun Nov 16 00:59:25 2025 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=1745907198; cv=none; d=zohomail.com; s=zohoarc; b=He/oUDRxphhvgh5kgR/1WkvnVBd+wLU/mWeiMG28piL/AyFVihHOdPva/+jlvZKHa+TZwD28bR9JvJYFLnsiVgnNM4V1rasfs0kC+5vE+R2wnRdyZydVrvEMKXINncXg9/dF4o/dTVt6dNkDO8EFLqesVMstwJQaee4SJgq6i54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745907198; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wMNXTWLrMXkASkaRrX7djPL9AxU2oMo/25nK5TOFx/g=; b=AvYa9Xw5W8IUlnKLTR4xSxWry+RvwEiv9prYKdxH59404DVkQB1lVDCdJjB8U3OJb3CAaVL02/eXbnnDkt8Avjll33SFNL2C5LJET4hCrHPz860T9ujNVlIoc95qfCo69cFzbLGIl1whwsotGQS3omMPuUKfsVFX2GSBG0f6ZgA= 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 1745907198665986.8746403546991; Mon, 28 Apr 2025 23:13:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u9eCv-0000pG-2E; Tue, 29 Apr 2025 02:12:41 -0400 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 1u9eCf-0000ap-UX for qemu-devel@nongnu.org; Tue, 29 Apr 2025 02:12:29 -0400 Received: from mgamail.intel.com ([192.198.163.9]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u9eCe-0005Ma-5h for qemu-devel@nongnu.org; Tue, 29 Apr 2025 02:12:25 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 23:12:10 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 23:12:05 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745907144; x=1777443144; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q/7IV4zXWPUNZVc5NISNGgaHsZd/LQO2N4LerTRJBK4=; b=D9izVgN3VRYivMvIs3vpwlqoOjaJwj4BjBRlgCJRKNmsHNsjm2vGkNeL 2rfwAuHuTEpOzCYPUlhezuUFHQY3apdExDGSfh76y/O5IKD+kussvYqZq 2aLT/7yBkdFg8GfbZBH0NeQUNCd+oq0dBNHgbI8CbNGfeOkztknQQ7mUT i+oG310zCtheqyiKtRIaCLhC+/MB+mQEux8vj9teNWjeMIYFGEWyFgynK V9RdWyGkM/RHuZRLG6mg8+f51MqR0eJA+oimOAx5X2A9FpF1uc+xu33Lr pMY5pVtgbF31Ev1YB9PotdfXZ13+Jskv7NLotusTowxtZeaOwPBye6aqt w==; X-CSE-ConnectionGUID: m2cpyFRIQjCm8Q7j3lxKyQ== X-CSE-MsgGUID: nxFtkTgSTVWn1Mxdyv6wfw== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58169841" X-IronPort-AV: E=Sophos;i="6.15,248,1739865600"; d="scan'208";a="58169841" X-CSE-ConnectionGUID: MZTwtlBtTSqclV3Z+pp9Pw== X-CSE-MsgGUID: 8iHTZ+NNSp6G8aGvDJ9oCg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,248,1739865600"; d="scan'208";a="133687174" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Dmitry Osipenko , Frediano Ziglio , Dongwon Kim Subject: [PATCH v3 5/6] ui/spice: Create a new texture with linear layout when gl=on is enabled Date: Mon, 28 Apr 2025 23:08:29 -0700 Message-ID: <20250429060952.59508-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429060952.59508-1-vivek.kasireddy@intel.com> References: <20250429060952.59508-1-vivek.kasireddy@intel.com> 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=192.198.163.9; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.484, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1745907199983019000 Since most encoders/decoders (invoked by Spice) may not work with tiled memory associated with a texture, we need to create another texture that has linear memory layout and use that instead. Note that, there does not seem to be a direct way to indicate to the GL implementation that a texture's backing memory needs to be linear. Instead, we have to do it in a roundabout way where we need to first create a tiled texture and import that as a memory object to create a new texture that has a linear memory layout. Cc: Gerd Hoffmann Cc: Marc-Andr=C3=A9 Lureau Cc: Dmitry Osipenko Cc: Frediano Ziglio Cc: Dongwon Kim Signed-off-by: Vivek Kasireddy --- ui/spice-display.c | 63 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/ui/spice-display.c b/ui/spice-display.c index 2c4daa0707..047d453a0b 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -26,6 +26,7 @@ #include "ui/console.h" #include "trace.h" =20 +#include "standard-headers/drm/drm_fourcc.h" #include "ui/spice-display.h" =20 bool spice_opengl; @@ -890,11 +891,65 @@ static void spice_gl_update(DisplayChangeListener *dc= l, ssd->gl_updates++; } =20 +static bool spice_gl_replace_fd_texture(SimpleSpiceDisplay *ssd, + EGLint *stride, EGLint *fourcc, + EGLuint64KHR *modifier, + int *fd) +{ + GLuint texture =3D 0; + + if (!remote_client) { + return true; + } + + if (surface_format(ssd->ds) =3D=3D PIXMAN_r5g6b5) { + return true; + } + + if (*modifier =3D=3D DRM_FORMAT_MOD_LINEAR) { + return true; + } + + /* + * We really want to ensure that the memory layout of the texture + * is linear; otherwise, the encoder's output may show corruption. + */ + surface_gl_create_texture_from_fd(ssd->ds, *fd, &texture); + + /* + * A successful return after glImportMemoryFdEXT() means that + * the ownership of fd has been passed to GL. In other words, + * the fd we got above should not be used anymore. + */ + if (texture > 0) { + *fd =3D egl_get_fd_for_texture(texture, + stride, fourcc, + NULL); + if (*fd < 0) { + glDeleteTextures(1, &texture); + *fd =3D egl_get_fd_for_texture(ssd->ds->texture, + stride, fourcc, + NULL); + if (*fd < 0) { + surface_gl_destroy_texture(ssd->gls, ssd->ds); + warn_report("spice: no texture available to display"); + return false; + } + } else { + surface_gl_destroy_texture(ssd->gls, ssd->ds); + ssd->ds->texture =3D texture; + } + } + return true; +} + static void spice_gl_switch(DisplayChangeListener *dcl, struct DisplaySurface *new_surface) { SimpleSpiceDisplay *ssd =3D container_of(dcl, SimpleSpiceDisplay, dcl); EGLint stride, fourcc; + EGLuint64KHR modifier; + bool ret; int fd; =20 if (ssd->ds) { @@ -905,12 +960,18 @@ static void spice_gl_switch(DisplayChangeListener *dc= l, surface_gl_create_texture(ssd->gls, ssd->ds); fd =3D egl_get_fd_for_texture(ssd->ds->texture, &stride, &fourcc, - NULL); + &modifier); if (fd < 0) { surface_gl_destroy_texture(ssd->gls, ssd->ds); return; } =20 + ret =3D spice_gl_replace_fd_texture(ssd, &stride, &fourcc, &modifi= er, &fd); + if (!ret) { + surface_gl_destroy_texture(ssd->gls, ssd->ds); + return; + } + trace_qemu_spice_gl_surface(ssd->qxl.id, surface_width(ssd->ds), surface_height(ssd->ds), --=20 2.49.0