From patchwork Mon Aug 10 10:59:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27723 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id CC6E1BE080 for ; Mon, 10 Aug 2026 10:59:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 96D76681B5; Mon, 10 Aug 2026 12:59:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oWniou1j"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F718681AF for ; Mon, 10 Aug 2026 12:59:46 +0200 (CEST) Received: from pb-laptop.local (185.221.141.208.nat.pool.zt.hu [185.221.141.208]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5AC401F8; Mon, 10 Aug 2026 12:58:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1786359512; bh=xyQQHSwnAGPbBILOJJLiDhhjw28voxfdkz0e30YJFr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oWniou1jpjMiUyCxAb4kdGX5oWLALeFnLgkQN1KphVyMol5ScVZFL2Oue4o2NFrU/ if3tpWchTL8f0yIRVQ7OSOCwhApdWWar7hmRO5c7EP+ynYOYfL7pEkDNnmHDI8rzOg Naydi5HNBNFx2rJJb8elofM+yvXaao5/X39tXYbs= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH v2 1/8] libcamera: egl: Remove `gl{Use, Delete}Program()` Date: Mon, 10 Aug 2026 12:59:35 +0200 Message-ID: <20260810105942.1098192-2-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> References: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" `eGL::deleteProgram()` is currently unused, and the only user of `eGL::useProgram()` is `debayer_egl.cpp`, which is already using numerous gl calls directly without going through the `eGL` type. So remove these trivial wrappers. Signed-off-by: Barnabás Pőcze Reviewed-by: Milan Zamazal --- include/libcamera/internal/egl.h | 2 -- src/libcamera/egl.cpp | 28 ---------------------- src/libcamera/software_isp/debayer_egl.cpp | 2 +- 3 files changed, 1 insertion(+), 31 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 7ef1ca0d93..c43684808d 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -123,8 +123,6 @@ public: Span shaderEnv); int linkProgram(GLuint &programId, GLuint fragmentshaderId, GLuint vertexshaderId); void dumpShaderSource(GLuint shaderId); - void useProgram(GLuint programId); - void deleteProgram(GLuint programId); void syncOutput(); void flushOutput(); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 01e51cda8e..780b7bc2d5 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -464,34 +464,6 @@ void eGL::makeCurrent() } } -/** - * \brief Activate a shader program for rendering - * \param[in] programId OpenGL program object ID - * - * Sets the specified program as the current rendering program. All - * subsequent draw calls will use this program's shaders. - */ -void eGL::useProgram(GLuint programId) -{ - ASSERT(tid_ == Thread::currentId()); - - glUseProgram(programId); -} - -/** - * \brief Delete a shader program - * \param[in] programId OpenGL program object ID - * - * Deletes a shader program and frees associated resources. The program - * must not be currently in use. - */ -void eGL::deleteProgram(GLuint programId) -{ - ASSERT(tid_ == Thread::currentId()); - - glDeleteProgram(programId); -} - /** * \brief Add a preprocessor definition to shader environment * \param[in,out] shaderEnv Vector of shader environment strings diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 20b478b1c3..ede3be2352 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -261,7 +261,7 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm egl_.dumpShaderSource(fragmentShaderId_); /* Ensure we set the programId_ */ - egl_.useProgram(programId_); + glUseProgram(programId_); err = glGetError(); if (err != GL_NO_ERROR) { LOG(Debayer, Error) << "Use program error " << err; From patchwork Mon Aug 10 10:59:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27724 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id CE82FBE080 for ; Mon, 10 Aug 2026 10:59:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6DC786820C; Mon, 10 Aug 2026 12:59:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rC7yKdGj"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E6B6681B4 for ; Mon, 10 Aug 2026 12:59:46 +0200 (CEST) Received: from pb-laptop.local (185.221.141.208.nat.pool.zt.hu [185.221.141.208]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 903D282A; Mon, 10 Aug 2026 12:58:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1786359512; bh=elkYYkqX+KHuYeIDySAqaqyXgsXWqVYcCep+RijFu/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rC7yKdGjaZ2D2JssshhYdQPUiuOLhC65p4oGLZyZVguHTNXzzKtcVYpKSJn0Au+bS dZGIXUiJgkSmtlZ5Dhw7lBLtktO/DetN+dyjjBmITORG4VjF9T38Op/gQUtB2tkvD1 RhBEObFBoioXCJ8DbcK3TBL3HVbqMEP43Vq4UnVs= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH v2 2/8] libcamera: egl: Remove `eGL::surface_` Date: Mon, 10 Aug 2026 12:59:36 +0200 Message-ID: <20260810105942.1098192-3-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> References: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This member has always been unused, so remove it. Signed-off-by: Barnabás Pőcze Reviewed-by: Milan Zamazal --- include/libcamera/internal/egl.h | 1 - src/libcamera/egl.cpp | 8 -------- 2 files changed, 9 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index c43684808d..f8ae486a8d 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -133,7 +133,6 @@ private: EGLDisplay display_ = EGL_NO_DISPLAY; EGLContext context_ = EGL_NO_CONTEXT; - EGLSurface surface_ = EGL_NO_SURFACE; int compileShader(int shaderType, GLuint &shaderId, Span shaderData, Span shaderEnv); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 780b7bc2d5..900d2174df 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -57,11 +57,6 @@ LOG_DEFINE_CATEGORY(eGL) *\brief EGL context handle */ -/** - *\var eGL::surface_ - *\brief EGL sufrace handle - */ - /** * \brief Construct an EGL helper * \param[in] display The EGL display to use @@ -84,9 +79,6 @@ eGL::~eGL() { if (context_ != EGL_NO_CONTEXT) eglDestroyContext(display_, context_); - - if (surface_ != EGL_NO_SURFACE) - eglDestroySurface(display_, surface_); } /** From patchwork Mon Aug 10 10:59:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27725 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6514CBE080 for ; Mon, 10 Aug 2026 10:59:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D56756820A; Mon, 10 Aug 2026 12:59:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="e+2tdJOO"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C51B9681B5 for ; Mon, 10 Aug 2026 12:59:46 +0200 (CEST) Received: from pb-laptop.local (185.221.141.208.nat.pool.zt.hu [185.221.141.208]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C5FBB12F for ; Mon, 10 Aug 2026 12:58:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1786359512; bh=xUiaQZd5tzlL4fxEfKE3i0B6g9ntU+CSgwbX3/eG+E4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=e+2tdJOO7edPHGf3YJ+wP1wKXZ9Mrr6ltyndvCi7w0WaFJJJFRmf5yV1IMoo61G6C QTtWrKipAqZGNRcK39wF/zqGJ+0h8p8WtxvM6R0LQYdE6dalPReGilrDKJ+KMGMxSN tklcE5W+qTYZld7PEVEb5zV6W+a1iwCkOT4eAkBQ= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v2 3/8] libcamera: egl: Do not load `glGetString` dynamically Date: Mon, 10 Aug 2026 12:59:37 +0200 Message-ID: <20260810105942.1098192-4-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> References: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" `glGetString()` should be available in all version of OpenGL and OpenGL ES, so there should be no need to load it with `eglGetProcAddress()` like it is done for extension functions. Signed-off-by: Barnabás Pőcze Reviewed-by: Milan Zamazal --- include/libcamera/internal/egl.h | 1 - src/libcamera/egl.cpp | 6 ------ 2 files changed, 7 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index f8ae486a8d..6abb02bf3b 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -142,6 +142,5 @@ private: PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; - PFNGLGETSTRINGPROC glGetString; }; } //namespace libcamera diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 900d2174df..0768a840e6 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -410,12 +410,6 @@ int eGL::initEGLContext() goto fail; } - glGetString = (PFNGLGETSTRINGPROC)eglGetProcAddress("glGetString"); - if (!glGetString) { - LOG(eGL, Error) << "glGetString not found"; - goto fail; - } - if (eglChooseConfig(display_, configAttribs, &config, 1, &numConfigs) != EGL_TRUE) { LOG(eGL, Error) << "eglChooseConfig fail"; goto fail; From patchwork Mon Aug 10 10:59:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27726 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B17F3BE080 for ; Mon, 10 Aug 2026 10:59:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3DE1E68203; Mon, 10 Aug 2026 12:59:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lbKuPw5L"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F410B681B7 for ; Mon, 10 Aug 2026 12:59:46 +0200 (CEST) Received: from pb-laptop.local (185.221.141.208.nat.pool.zt.hu [185.221.141.208]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 021AF887; Mon, 10 Aug 2026 12:58:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1786359513; bh=ETgfREqfXJEar8GnJwST8O23mQ/NQ6vjCwtuJN3WpsE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lbKuPw5LhYw9y/GtEOVGDPkRSVnZGZsptVjEgiY7rquwvpsPVV/y6JFrUwVXifZxD 7/16Z+xfKOoPoceMbDwbNhxELgbt1olINIaSrGpTbEYIT7AxD7BhuCbG+JnXXAh7Z8 rj9tXi1+Mgd6JJeZULw/ua5TXNAa+6JA2o/5Wv6M= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH v2 4/8] libcamera: egl: Ensure all members are always initialized Date: Mon, 10 Aug 2026 12:59:38 +0200 Message-ID: <20260810105942.1098192-5-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> References: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The `tid_` and function pointer members were not previously initialize before calling `initEGLContext()`, fix that. Signed-off-by: Barnabás Pőcze Reviewed-by: Milan Zamazal --- include/libcamera/internal/egl.h | 10 ++++++---- src/libcamera/egl.cpp | 24 +++++++++++++----------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 6abb02bf3b..fb77225ac4 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -129,7 +129,7 @@ public: private: LIBCAMERA_DISABLE_COPY_AND_MOVE(eGL) - pid_t tid_; + pid_t tid_ = -1; EGLDisplay display_ = EGL_NO_DISPLAY; EGLContext context_ = EGL_NO_CONTEXT; @@ -139,8 +139,10 @@ private: int createDMABufTexture2D(eGLImage &eglImage, int fd, bool output); - PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; - PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; - PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; + struct VTable { + PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; + PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; + PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; + } vtable_ = {}; }; } //namespace libcamera diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 0768a840e6..3de5fab816 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -199,9 +199,9 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) }; // clang-format on - EGLImageKHR image = eglCreateImageKHR(display_, EGL_NO_CONTEXT, - EGL_LINUX_DMA_BUF_EXT, - NULL, image_attrs); + EGLImageKHR image = vtable_.eglCreateImageKHR(display_, EGL_NO_CONTEXT, + EGL_LINUX_DMA_BUF_EXT, + NULL, image_attrs); if (image == EGL_NO_IMAGE_KHR) { LOG(eGL, Debug) << "eglCreateImageKHR fail"; @@ -212,8 +212,8 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) activateBindTexture(eglImage); // Generate texture with filter semantics - glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); - eglDestroyImageKHR(display_, image); + vtable_.glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); + vtable_.eglDestroyImageKHR(display_, image); // Nearest filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -379,6 +379,7 @@ int eGL::initEGLContext() EGL_NONE }; + VTable vtable = {}; EGLint numConfigs; EGLConfig config; @@ -392,20 +393,20 @@ int eGL::initEGLContext() LOG(eGL, Info) << "EGL: EGL_CLIENT_APIS: " << eglQueryString(display_, EGL_CLIENT_APIS); LOG(eGL, Info) << "EGL: EGL_EXTENSIONS: " << eglQueryString(display_, EGL_EXTENSIONS); - eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); - if (!eglCreateImageKHR) { + vtable.eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); + if (!vtable.eglCreateImageKHR) { LOG(eGL, Error) << "eglCreateImageKHR not found"; goto fail; } - eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); - if (!eglDestroyImageKHR) { + vtable.eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); + if (!vtable.eglDestroyImageKHR) { LOG(eGL, Error) << "eglDestroyImageKHR not found"; goto fail; } - glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); - if (!glEGLImageTargetTexture2DOES) { + vtable.glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); + if (!vtable.glEGLImageTargetTexture2DOES) { LOG(eGL, Error) << "glEGLImageTargetTexture2DOES not found"; goto fail; } @@ -422,6 +423,7 @@ int eGL::initEGLContext() } tid_ = Thread::currentId(); + vtable_ = vtable; makeCurrent(); From patchwork Mon Aug 10 10:59:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27727 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DB87BBE080 for ; Mon, 10 Aug 2026 10:59:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D2DBE6820C; Mon, 10 Aug 2026 12:59:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="i8gN+dkF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C77C681C0 for ; Mon, 10 Aug 2026 12:59:47 +0200 (CEST) Received: from pb-laptop.local (185.221.141.208.nat.pool.zt.hu [185.221.141.208]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 36D5312F for ; Mon, 10 Aug 2026 12:58:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1786359513; bh=ehJ8meUetMIHbPR9HDPOsgBuTQSDYi0Whd2yT4TJb9g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=i8gN+dkF88zmYfdnAs84p1puhQirQFu88SDs1NKXujSspGWoftPudlJThhZevcbyK Z7NVDzGI1FLAFVOuAjTXGcW38ERGOgdXJ2NLp0/J2n6z/U02tsL9PmwzPGi3qRujOz BSNLetDoIrln/UqP2W62WNpmP4kGgOFbTwTTha9o= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v2 5/8] libcamera: egl: Add `resetEGLContext()` Date: Mon, 10 Aug 2026 12:59:39 +0200 Message-ID: <20260810105942.1098192-6-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> References: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a function that undoes the effects of `initEGLContext()`. Signed-off-by: Barnabás Pőcze Reviewed-by: Milan Zamazal --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index fb77225ac4..e18bb91f4d 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -103,6 +103,7 @@ public: ~eGL(); int initEGLContext(); + void resetEGLContext(); static EGLDisplay probeDisplay(); int createInputDMABufTexture2D(eGLImage &eglImage, int fd); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 3de5fab816..237791bca1 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -71,14 +71,11 @@ eGL::eGL(EGLDisplay display) } /** - * \brief Destroy the EGL helper - * - * Destroys the EGL context and surface if they were successfully created. + * \brief Release all EGL resources */ eGL::~eGL() { - if (context_ != EGL_NO_CONTEXT) - eglDestroyContext(display_, context_); + resetEGLContext(); } /** @@ -436,6 +433,24 @@ fail: return -ENODEV; } +/** + * \brief Destroy the EGL context + * + * This function destroys the EGL context created by initEGLContext(). + */ +void eGL::resetEGLContext() +{ + if (context_ != EGL_NO_CONTEXT) { + if (tid_ == Thread::currentId()) + eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + eglDestroyContext(display_, std::exchange(context_, EGL_NO_CONTEXT)); + } + + tid_ = -1; + vtable_ = {}; +} + /** * \brief Make the EGL context current for the calling thread * From patchwork Mon Aug 10 10:59:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27728 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E3D4DBE080 for ; Mon, 10 Aug 2026 10:59:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 99C44681E5; Mon, 10 Aug 2026 12:59:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HWWug15h"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 60E59681AC for ; Mon, 10 Aug 2026 12:59:47 +0200 (CEST) Received: from pb-laptop.local (185.221.141.208.nat.pool.zt.hu [185.221.141.208]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6757812B2; Mon, 10 Aug 2026 12:58:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1786359513; bh=38EagsNVr1wqqvZpAjsOVYqxH8qxGpsgYbBuUr/Hkkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HWWug15hq8Y06CdO7ATkYTX9tzsS7dovHFB873AR0wXP9dADqxf7wspb28wJa8CEh JHNk3O0RfyuV9rct//Qrz7baBvwMD9tLDk5zT1+ummm0OKyv4cTClPzkeZL5FEnngB 3zlV2B0MoSmUY7MU14azE5s6SsFcvEYvuoPJdRCc= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH v2 6/8] libcamera: software_isp: debayer_egl: Avoid EGL context leaks Date: Mon, 10 Aug 2026 12:59:40 +0200 Message-ID: <20260810105942.1098192-7-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> References: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Currently each `start()` invocation causes a new EGL context to be acquired, and only the last allocation will be properly freed in the `eGL` destructor. To avoid that, call `eGL::resetEGLContext()` in `stop()`. Signed-off-by: Barnabás Pőcze Reviewed-by: Milan Zamazal --- src/libcamera/software_isp/debayer_egl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index ede3be2352..35a5c56321 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -682,6 +682,8 @@ void DebayerEGL::stop() if (programId_) glDeleteProgram(programId_); + + egl_.resetEGLContext(); } SizeRange DebayerEGL::sizes(PixelFormat inputFormat, const Size &inputSize) From patchwork Mon Aug 10 10:59:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27729 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id CF416BE080 for ; Mon, 10 Aug 2026 10:59:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6215D681ED; Mon, 10 Aug 2026 12:59:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lYF+1Omn"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 962DB681C3 for ; Mon, 10 Aug 2026 12:59:47 +0200 (CEST) Received: from pb-laptop.local (185.221.141.208.nat.pool.zt.hu [185.221.141.208]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9B0D212F; Mon, 10 Aug 2026 12:58:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1786359513; bh=hOXIrgAkDqFOHHjYBnbtJrcts6fWrCKpXn+dDVvbW5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lYF+1OmnPKR8VOyrw2nE6mt7wOihn7ha03WtKiEJWFqtWPfZTAVN4z6ulvEI6acrA 1Rg+lu0VMGEEyRfqti2XsXPjN65sc7VIhIbkQZE7BijIKWSlWajtRnZBZ7dMVLaD65 jR0h8dc5wQY81ded/yyTDv3/fsdYsqjCAiQMM1xY= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH v2 7/8] libcamera: egl: initEGLContext(): Avoid double init Date: Mon, 10 Aug 2026 12:59:41 +0200 Message-ID: <20260810105942.1098192-8-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> References: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" If the initialization is already done, reject further attempts, otherwise resources would be leaked. Signed-off-by: Barnabás Pőcze Reviewed-by: Milan Zamazal --- src/libcamera/egl.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 237791bca1..edb00ef997 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -357,7 +357,7 @@ void eGL::createOutputTexture2D(eGLImage &eglImage) * - eglCreateImageKHR / eglDestroyImageKHR * - glEGLImageTargetTexture2DOES * - * \return 0 on success, or -ENODEV on failure + * \return 0 on success, or negative error code on failure */ int eGL::initEGLContext() { @@ -380,6 +380,9 @@ int eGL::initEGLContext() EGLint numConfigs; EGLConfig config; + if (context_ != EGL_NO_CONTEXT) + return -EEXIST; + if (!eglBindAPI(EGL_OPENGL_ES_API)) { LOG(eGL, Error) << "API bind fail"; goto fail; From patchwork Mon Aug 10 10:59:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27730 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7A832C3264 for ; Mon, 10 Aug 2026 11:00:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3041A681F3; Mon, 10 Aug 2026 12:59:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Og0kFwYK"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CA2A7681C7 for ; Mon, 10 Aug 2026 12:59:47 +0200 (CEST) Received: from pb-laptop.local (185.221.141.208.nat.pool.zt.hu [185.221.141.208]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CE29513D3 for ; Mon, 10 Aug 2026 12:58:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1786359513; bh=QBuKO1f/dviTboXk+ksOHrAGhNlUynY34fgZD3Rzmt8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Og0kFwYKjjbLFlPnVZavfWpZ7xBrGYr94uewies0trAROaAA3Pw96DpYTKjm8easH GsZX3fl7iuXS8TvPlHwinCBX8YJL2dT7QsrGpE8LGQBurWM3GHQ5YE4X6bUAGTZZWN og6uduHCDx8EJzVsQ363a27gfSV8Zo7kKZjnV1PM= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v2 8/8] libcamera: software_isp: debayer_egl: Remove EGL context switch Date: Mon, 10 Aug 2026 12:59:42 +0200 Message-ID: <20260810105942.1098192-9-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> References: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" `eGL::initEGLContext()`, which is called from the worker thread already includes a call to `eGL::makeCurrent()`, so calling it for each `process()` is not necessary, so skip it. Instead, add a function that asserts that the execution is in the correct thread, and call that. Signed-off-by: Barnabás Pőcze --- include/libcamera/internal/egl.h | 9 ++++++++- src/libcamera/egl.cpp | 8 ++++++++ src/libcamera/software_isp/debayer_egl.cpp | 4 +--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index e18bb91f4d..8f2ef296c3 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -14,6 +14,7 @@ #include #include +#include #include /* @@ -116,7 +117,6 @@ public: void activateBindTexture(eGLImage &eglImage); void pushEnv(std::vector &shaderEnv, const char *str); - void makeCurrent(); int compileVertexShader(GLuint &shaderId, Span shaderData, Span shaderEnv); @@ -127,6 +127,11 @@ public: void syncOutput(); void flushOutput(); + void assertThread() const + { + ASSERT(tid_ == Thread::currentId()); + } + private: LIBCAMERA_DISABLE_COPY_AND_MOVE(eGL) @@ -140,6 +145,8 @@ private: int createDMABufTexture2D(eGLImage &eglImage, int fd, bool output); + void makeCurrent(); + struct VTable { PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index edb00ef997..5e5535f2be 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -104,6 +104,14 @@ void eGL::flushOutput() glFlush(); } +/** + * \fn eGL::assertThread() + * \brief Assert that the execution is in the right thread + * + * Asserts that the execution is in the thread for which + * the created EGL context has been made current. + */ + /** * \brief Attach a texture to a frame-buffer-object * diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 35a5c56321..97aa037935 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -578,9 +578,6 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye eGLImage *eglImageIn; eGLImage *eglImageOut; - /* eGL context switch */ - egl_.makeCurrent(); - eglImageIn = getCachedInputFrameBuffer(input, inMapped, inDmaSyncer); if (!eglImageIn) return -ENOMEM; @@ -608,6 +605,7 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms) { + egl_.assertThread(); bench_.startFrame(); /* Copy metadata from the input buffer */