Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1634EC3ABD8 for ; Thu, 15 May 2025 02:50:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uFOf6-0006kX-Tc; Wed, 14 May 2025 22:49:33 -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 1uFOf5-0006jU-Bo for qemu-devel@nongnu.org; Wed, 14 May 2025 22:49:31 -0400 Received: from mgamail.intel.com ([192.198.163.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uFOf3-0005iL-DS for qemu-devel@nongnu.org; Wed, 14 May 2025 22:49:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747277369; x=1778813369; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=STthhcuiYFhtaPFn0z3oX1IbTphb/i1MPiWVLMqKqJI=; b=lvVbuurdjY/pj1QDTE0dsFNzC1s2u0ZsiHs19gHbMigJ6oGvg5tNvdt9 yiK8ugN4ugDVhepgafWGu8QqHsuMRjtpyU1iIl6zHA3vkugzz356pPrcS WRwutw/Zxk5xEglVHSMxvNvH4DnmeZ3/FyFoBuE8KSA0ub2wI1w62E83E kJJ5+fFHpvzCxWaTpIBIbyXIf87JsI9bKOi2se8h89E7vsmZIJl6FyW0i CVvsySJPQwhUY4dO17ZQcxedQFqeMtPwQKqYCkOqRCwOQ6io8JFIEuga4 Pm214+3Ujm3ThqMJVplaN1eMbS2ePzPBtV06SHkJYKQDBHpX/F2gaYFG8 Q==; X-CSE-ConnectionGUID: XD083olhSVu6ml71s8h6gw== X-CSE-MsgGUID: dwYHp72AQDy/GTrImhzA0Q== X-IronPort-AV: E=McAfee;i="6700,10204,11433"; a="36819309" X-IronPort-AV: E=Sophos;i="6.15,289,1739865600"; d="scan'208";a="36819309" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2025 19:49:19 -0700 X-CSE-ConnectionGUID: YImCxpjPTGKvLXh+wYKggw== X-CSE-MsgGUID: vCrJft5PR6S+vBrtvqknpg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,289,1739865600"; d="scan'208";a="142246658" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2025 19:49:19 -0700 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 v4 5/7] ui/console-gl: Add a helper to create a texture with linear memory layout Date: Wed, 14 May 2025 19:45:43 -0700 Message-ID: <20250515024734.758335-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250515024734.758335-1-vivek.kasireddy@intel.com> References: <20250515024734.758335-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=192.198.163.16; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -60 X-Spam_score: -6.1 X-Spam_bar: ------ X-Spam_report: (-6.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.686, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org There are cases where we do not want the memory layout of a texture to be tiled as the component processing the texture would not know how to de-tile either via software or hardware. Therefore, ensuring that the memory backing the texture has a linear layout is absolutely necessary in these situations. Cc: Gerd Hoffmann Cc: Marc-André Lureau Cc: Dmitry Osipenko Cc: Frediano Ziglio Cc: Dongwon Kim Signed-off-by: Vivek Kasireddy --- include/ui/console.h | 2 ++ ui/console-gl.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/ui/console.h b/include/ui/console.h index 46b3128185..5cfa6ae215 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -422,6 +422,8 @@ bool console_gl_check_format(DisplayChangeListener *dcl, pixman_format_code_t format); void surface_gl_create_texture(QemuGLShader *gls, DisplaySurface *surface); +bool surface_gl_create_texture_from_fd(DisplaySurface *surface, + int fd, GLuint *texture); void surface_gl_update_texture(QemuGLShader *gls, DisplaySurface *surface, int x, int y, int w, int h); diff --git a/ui/console-gl.c b/ui/console-gl.c index 103b954017..97f7989651 100644 --- a/ui/console-gl.c +++ b/ui/console-gl.c @@ -25,6 +25,7 @@ * THE SOFTWARE. */ #include "qemu/osdep.h" +#include "qemu/error-report.h" #include "ui/console.h" #include "ui/shader.h" @@ -96,6 +97,37 @@ void surface_gl_create_texture(QemuGLShader *gls, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } +bool surface_gl_create_texture_from_fd(DisplaySurface *surface, + int fd, GLuint *texture) +{ + unsigned long size = surface_stride(surface) * surface_height(surface); + GLenum err = glGetError(); + GLuint mem_obj; + + if (!epoxy_has_gl_extension("GL_EXT_memory_object") || + !epoxy_has_gl_extension("GL_EXT_memory_object_fd")) { + return false; + } + +#ifdef GL_EXT_memory_object_fd + glCreateMemoryObjectsEXT(1, &mem_obj); + glImportMemoryFdEXT(mem_obj, size, GL_HANDLE_TYPE_OPAQUE_FD_EXT, fd); + + err = glGetError(); + if (err != GL_NO_ERROR) { + error_report("spice: cannot import memory object from fd"); + return false; + } + + glGenTextures(1, texture); + glBindTexture(GL_TEXTURE_2D, *texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_TILING_EXT, GL_LINEAR_TILING_EXT); + glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, surface_width(surface), + surface_height(surface), mem_obj, 0); +#endif + return *texture > 0 && glGetError() == GL_NO_ERROR; +} + void surface_gl_update_texture(QemuGLShader *gls, DisplaySurface *surface, int x, int y, int w, int h) -- 2.49.0