[{"id":38390,"web_url":"https://patchwork.libcamera.org/comment/38390/","msgid":"<bbd7c276-d276-46b8-84b7-6933d6be4f6d@ideasonboard.com>","date":"2026-03-24T08:39:11","subject":"Re: [PATCH v2] libcamera: software_isp: debayer_egl: Teardown the\n\toutput texture","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2026. 03. 23. 21:10 keltezéssel, Gianfranco Mariotti írta:\n> Destroy the EGL image associated with the output DMA-BUF texture\n> after processing the frame.\n> \n> Without this change memory can be seen building up while running\n> a gstreamer pipeline using GPUISP, and on end of available memory\n> the stream freezes and the error message `eglCreateImageKHR fail`\n> is reported repeatedly.\n> \n> Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>\n> ---\n\nI think\n\n   Fixes: f520b29fe9e6 (\"libcamera: software_isp: debayer_egl: Add an eGL Debayer class\")\n\ncould be added.\n\nTested-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> # ThinkPad X1 Yoga Gen 7 + ov2740\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\nBut after thinking about this a bit, I think maybe `eGLImage::image_` could be removed altogether.\nI believe the EGLImage may be deleted right after the `glEGLImageTargetTexture2DOES()` call since\nit will be referenced by the texture, at least that's what I would expect based on the mesa code\nand given how opengl et al generally operates. The below change appears to work.\n\n\ndiff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h\nindex 8a2d96d7a..0ad2320b1 100644\n--- a/include/libcamera/internal/egl.h\n+++ b/include/libcamera/internal/egl.h\n@@ -88,7 +88,6 @@ public:\n  \tGLenum texture_unit_; /**< Texture unit associated with this image eg (GL_TEXTURE0) */\n  \tGLuint texture_; /**< OpenGL texture object ID */\n  \tGLuint fbo_; /**< OpenGL frame buffer object ID */\n-\tEGLImageKHR image_; /**< EGL Image handle */\n  \n  private:\n  \tLIBCAMERA_DISABLE_COPY_AND_MOVE(eGLImage)\n@@ -104,7 +103,6 @@ public:\n  \n  \tint createInputDMABufTexture2D(eGLImage &eglImage, int fd);\n  \tint createOutputDMABufTexture2D(eGLImage &eglImage, int fd);\n-\tvoid destroyDMABufTexture(eGLImage &eglImage);\n  \tvoid createTexture2D(eGLImage &eglImage, GLint format, uint32_t width, uint32_t height, void *data);\n  \n  \tvoid pushEnv(std::vector<std::string> &shaderEnv, const char *str);\ndiff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp\nindex 5b9bbf410..d8d6e3a42 100644\n--- a/src/libcamera/egl.cpp\n+++ b/src/libcamera/egl.cpp\n@@ -112,8 +112,6 @@ void eGL::syncOutput()\n   */\n  int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output)\n  {\n-\tint ret = 0;\n-\n  \tASSERT(tid_ == Thread::currentId());\n  \n  \t// clang-format off\n@@ -130,22 +128,23 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output)\n  \t};\n  \t// clang-format on\n  \n-\teglImage.image_ = eglCreateImageKHR(display_, EGL_NO_CONTEXT,\n-\t\t\t\t\t    EGL_LINUX_DMA_BUF_EXT,\n-\t\t\t\t\t    NULL, image_attrs);\n+\tEGLImageKHR image = eglCreateImageKHR(display_, EGL_NO_CONTEXT,\n+\t\t\t\t\t      EGL_LINUX_DMA_BUF_EXT,\n+\t\t\t\t\t      NULL, image_attrs);\n  \n-\tif (eglImage.image_ == EGL_NO_IMAGE_KHR) {\n+\tif (image == EGL_NO_IMAGE_KHR) {\n  \t\tLOG(eGL, Error) << \"eglCreateImageKHR fail\";\n-\t\tret = -ENODEV;\n-\t\tgoto done;\n+\t\treturn -ENODEV;\n  \t}\n  \n+\tutils::scope_exit imageGuard([&] { eglDestroyImageKHR(display_, image); });\n+\n  \t// Bind texture unit and texture\n  \tglActiveTexture(eglImage.texture_unit_);\n  \tglBindTexture(GL_TEXTURE_2D, eglImage.texture_);\n  \n  \t// Generate texture with filter semantics\n-\tglEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eglImage.image_);\n+\tglEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);\n  \n  \t// Nearest filtering\n  \tglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\n@@ -163,13 +162,11 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output)\n  \t\tGLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER);\n  \t\tif (err != GL_FRAMEBUFFER_COMPLETE) {\n  \t\t\tLOG(eGL, Error) << \"glFrameBufferTexture2D error \" << err;\n-\t\t\teglDestroyImageKHR(display_, eglImage.image_);\n-\t\t\tret = -ENODEV;\n-\t\t\tgoto done;\n+\t\t\treturn -ENODEV;\n  \t\t}\n  \t}\n-done:\n-\treturn ret;\n+\n+\treturn 0;\n  }\n  \n  /**\n@@ -209,19 +206,6 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)\n  \treturn createDMABufTexture2D(eglImage, fd, true);\n  }\n  \n-/**\n- * \\brief Destroy a DMA-BUF texture's EGL image\n- * \\param[in,out] eglImage EGL image to destroy\n- *\n- * Destroys the EGL image associated with a DMA-BUF texture. The OpenGL\n- * texture and framebuffer objects are destroyed separately in the\n- * eGLImage destructor.\n- */\n-void eGL::destroyDMABufTexture(eGLImage &eglImage)\n-{\n-\teglDestroyImage(display_, std::exchange(eglImage.image_, EGL_NO_IMAGE_KHR));\n-}\n-\n  /**\n   * \\brief Create a 2D texture from a memory buffer\n   * \\param[in,out] eglImage EGL image to associate with the texture\n\n\n> Changes in v2:\n> - use utils::scope_exit to teardown\n> \n>   src/libcamera/software_isp/debayer_egl.cpp | 1 +\n>   1 file changed, 1 insertion(+)\n> \n> diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\n> index 8147eca1..14ea98eb 100644\n> --- a/src/libcamera/software_isp/debayer_egl.cpp\n> +++ b/src/libcamera/software_isp/debayer_egl.cpp\n> @@ -506,6 +506,7 @@ int DebayerEGL::debayerGPU(MappedFrameBuffer &in, int out_fd, const DebayerParam\n>   \n>   \t/* Generate the output render framebuffer as render to texture */\n>   \tegl_.createOutputDMABufTexture2D(*eglImageBayerOut_, out_fd);\n> +\tutils::scope_exit outImageGuard([&] { egl_.destroyDMABufTexture(*eglImageBayerOut_); });\n>   \n>   \tsetShaderVariableValues(params);\n>   \tglViewport(0, 0, width_, height_);","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C34E2BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 24 Mar 2026 08:39:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C7A9162784;\n\tTue, 24 Mar 2026 09:39:17 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2385B62010\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 24 Mar 2026 09:39:16 +0100 (CET)","from [192.168.33.36] (185.221.143.129.nat.pool.zt.hu\n\t[185.221.143.129])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D9F67741;\n\tTue, 24 Mar 2026 09:37:58 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"hZA4mGTq\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1774341478;\n\tbh=TozUSeuZHh4LB5y4ExtaYE7b2xGnFI5XBlPNR/oH/J4=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=hZA4mGTq4dAusUs2p80cJdnjasWiC+8ewnLm9PBg/0DXkG0BKWiK8OzC4tGm0PtLl\n\tYhgK/w7z63/dG/Beslzv6mNrLzfgxhtrDWxSjJGGbpRW7/8e9nSlsFJeyH8FHKjcBJ\n\taZ9PpDJ65GHmkAnNspuB0H9k3D/lNCnoCVLagS+A=","Message-ID":"<bbd7c276-d276-46b8-84b7-6933d6be4f6d@ideasonboard.com>","Date":"Tue, 24 Mar 2026 09:39:11 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2] libcamera: software_isp: debayer_egl: Teardown the\n\toutput texture","To":"Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20260323201015.4480-1-gianfranco.mariotti94@gmail.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20260323201015.4480-1-gianfranco.mariotti94@gmail.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":38404,"web_url":"https://patchwork.libcamera.org/comment/38404/","msgid":"<965d8d4a-c5f4-4221-a614-ab1d71877148@nxsw.ie>","date":"2026-03-25T15:12:09","subject":"Re: [PATCH v2] libcamera: software_isp: debayer_egl: Teardown the\n\toutput texture","submitter":{"id":226,"url":"https://patchwork.libcamera.org/api/people/226/","name":"Bryan O'Donoghue","email":"bod.linux@nxsw.ie"},"content":"On 24/03/2026 08:39, Barnabás Pőcze wrote:\n> +\tEGLImageKHR image = eglCreateImageKHR(display_, EGL_NO_CONTEXT,\n> +\t\t\t\t\t      EGL_LINUX_DMA_BUF_EXT,\n> +\t\t\t\t\t      NULL, image_attrs);\n> \n> -\tif (eglImage.image_ == EGL_NO_IMAGE_KHR) {\n> +\tif (image == EGL_NO_IMAGE_KHR) {\n>    \t\tLOG(eGL, Error) << \"eglCreateImageKHR fail\";\n> -\t\tret = -ENODEV;\n> -\t\tgoto done;\n> +\t\treturn -ENODEV;\n>    \t}\n> \n> +\tutils::scope_exit imageGuard([&] { eglDestroyImageKHR(display_, image); });\n\nPart of storing the image_ was the thought we might use it for \nmulti-pass but I don't think that will be necessary.\n\nWhy ssope guard this at all though ?\n\nJust delete direction after glEGLImageTargetTexture2DOES() as you're \nright the texture will be resident in VRAM.\n\n---\nbod","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id CDAA0BE086\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 25 Mar 2026 15:12:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 01142627D7;\n\tWed, 25 Mar 2026 16:12:16 +0100 (CET)","from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3EEBE6274D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Mar 2026 16:12:14 +0100 (CET)","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby sea.source.kernel.org (Postfix) with ESMTP id 5A51C43CA4;\n\tWed, 25 Mar 2026 15:12:12 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 8F9DDC4CEF7;\n\tWed, 25 Mar 2026 15:12:11 +0000 (UTC)"],"Message-ID":"<965d8d4a-c5f4-4221-a614-ab1d71877148@nxsw.ie>","Date":"Wed, 25 Mar 2026 15:12:09 +0000","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2] libcamera: software_isp: debayer_egl: Teardown the\n\toutput texture","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tGianfranco Mariotti <gianfranco.mariotti94@gmail.com>, \n\tlibcamera-devel@lists.libcamera.org","References":"<20260323201015.4480-1-gianfranco.mariotti94@gmail.com>\n\t<YFARqs3puBP2N4rl9lJNLIvpv2G9rurWcilj8OGRYgKHFitfhWTCVpm4pXO3i9NmlDqYGnL96gczt_Y-tT9BDA==@protonmail.internalid>\n\t<bbd7c276-d276-46b8-84b7-6933d6be4f6d@ideasonboard.com>","From":"Bryan O'Donoghue <bod.linux@nxsw.ie>","Content-Language":"en-US","In-Reply-To":"<bbd7c276-d276-46b8-84b7-6933d6be4f6d@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":38424,"web_url":"https://patchwork.libcamera.org/comment/38424/","msgid":"<f536cd2f-0337-4665-9b9a-bad1df3b285a@ideasonboard.com>","date":"2026-03-27T07:31:32","subject":"Re: [PATCH v2] libcamera: software_isp: debayer_egl: Teardown the\n\toutput texture","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2026. 03. 25. 16:12 keltezéssel, Bryan O'Donoghue írta:\n> On 24/03/2026 08:39, Barnabás Pőcze wrote:\n>> +    EGLImageKHR image = eglCreateImageKHR(display_, EGL_NO_CONTEXT,\n>> +                          EGL_LINUX_DMA_BUF_EXT,\n>> +                          NULL, image_attrs);\n>>\n>> -    if (eglImage.image_ == EGL_NO_IMAGE_KHR) {\n>> +    if (image == EGL_NO_IMAGE_KHR) {\n>>            LOG(eGL, Error) << \"eglCreateImageKHR fail\";\n>> -        ret = -ENODEV;\n>> -        goto done;\n>> +        return -ENODEV;\n>>        }\n>>\n>> +    utils::scope_exit imageGuard([&] { eglDestroyImageKHR(display_, image); });\n> \n> Part of storing the image_ was the thought we might use it for multi-pass but I don't think that will be necessary.\n\nEven if it is used, I think it's easy to bring it back. But currently it is not needed,\nso I think it makes sense to remove it (for now at least).\n\n> \n> Why ssope guard this at all though ?\n> \n> Just delete direction after glEGLImageTargetTexture2DOES() as you're right the texture will be resident in VRAM.\n\nGood question... I was testing some things and did not know how the code\nis going to end up. But it's probably simpler to just delete it after `glEGLImageTargetTexture2DOES()`.\n\n\nRegards,\nBarnabás Pőcze\n\n\n> \n> ---\n> bod","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 6D0D4BE086\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 Mar 2026 07:31:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 855F862895;\n\tFri, 27 Mar 2026 08:31:37 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CCE86274D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Mar 2026 08:31:36 +0100 (CET)","from [192.168.33.24] (185.221.143.129.nat.pool.zt.hu\n\t[185.221.143.129])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C11451783;\n\tFri, 27 Mar 2026 08:30:16 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"B0gBIZpY\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1774596616;\n\tbh=qBHdoAfdpyou9819QzeP0u7OHYjSZQd62gbqO8sMU1Y=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=B0gBIZpY1MPSe6TJvJBNKFVS1zbAOuocBqZPg0ZypVFqlhKYhxt/6JNk0FcJlY1Ns\n\t5LI7HNYIk3aMysONVuP1GfTDsU0UAAjy//A4Zt22VQb78QrbMiNPeJCERlx4QB62sY\n\t9UGRlvEIUUi3MUuj3jITkDCU0wGFzIVuKj15rrJ8=","Message-ID":"<f536cd2f-0337-4665-9b9a-bad1df3b285a@ideasonboard.com>","Date":"Fri, 27 Mar 2026 08:31:32 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2] libcamera: software_isp: debayer_egl: Teardown the\n\toutput texture","To":"Bryan O'Donoghue <bod.linux@nxsw.ie>,\n\tGianfranco Mariotti <gianfranco.mariotti94@gmail.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20260323201015.4480-1-gianfranco.mariotti94@gmail.com>\n\t<YFARqs3puBP2N4rl9lJNLIvpv2G9rurWcilj8OGRYgKHFitfhWTCVpm4pXO3i9NmlDqYGnL96gczt_Y-tT9BDA==@protonmail.internalid>\n\t<bbd7c276-d276-46b8-84b7-6933d6be4f6d@ideasonboard.com>\n\t<965d8d4a-c5f4-4221-a614-ab1d71877148@nxsw.ie>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<965d8d4a-c5f4-4221-a614-ab1d71877148@nxsw.ie>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]