From patchwork Mon Jul 6 11:01:14 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 27238 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 4FD9AC330F for ; Mon, 6 Jul 2026 11:01:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D84966021; Mon, 6 Jul 2026 13:01:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="f6/P395r"; dkim-atps=neutral Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DF3C4658E0 for ; Mon, 6 Jul 2026 13:01:31 +0200 (CEST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-47122683cf3so1815216f8f.0 for ; Mon, 06 Jul 2026 04:01:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783335691; x=1783940491; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s3J/NrfJsMXq4eaqAQimcvyIokeKF2MgvnNr4M7DXMo=; b=f6/P395ryGRD827SoUjiJICy0gjHgBhMxYsGzPIgDh93nIIKAgA9k8H1pXHlc0hOFK ciyBSi1XfCXs+N9BO4ij5HE05Fw07B7zAVssDv2ZhPLlqE/VvDjg4EC13QCxqCNihmxW o+f0RET8IuNLWaPKi7y7r5/zY9wzB8t/Qkw/rmWa4SAyTlLtxt1Kg3m28ZdSa+kN1l+v mASCzc6lKJaqHI7ZOt52iKXxaeckfB6pBa1kflf34gQ8+Ibg8R45D01fbweyavCYe4fh t31euJL9egDs9pmLwMZSgb4hjKR7OivDkK1e5BI3Bhv3wq3Plm8as80rbwo1Z6tfLdyj V4mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783335691; x=1783940491; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=s3J/NrfJsMXq4eaqAQimcvyIokeKF2MgvnNr4M7DXMo=; b=AViIcL+pkoJNj7EAF810io/JFbllG6T/tSTdAiqVbf6aTc1VS82vmrXr/TJzf3rV4y WjsN4EimKVmiZf/kudpORPugOfCo1Lx1dTYzvGD/q4QLiUM3elDFZQFo7TPJJTaieajc lbgzNBXZM9yExqcCBHnKXnOxITsEv8J/Y2QtUzd6vzt5HFlts7Ptc62I7p6YvhbblvDZ IZChoRBc9h7SRTGtwOTP5TFURMPS89PWlQM+z4iE2RuEbjJ6HQ/t7zRLxYvXeTbieQOJ G5NgYVmaq6Cf6Ykuw3637PSODDS5Vj8/bQKBnmJTmd5IaV+gbl9A+ZM6nnQCkBE/34ir faxQ== X-Gm-Message-State: AOJu0YzFZvJXrVoenqY9B6sWi2amGDxBFIsSXo7t0lYiiJ9g2zt1oUrA pVD4YrnVZ14wyf79uhInAEmDdTE09/K4Y+HUg/1Kinw513BIcu6fx9Asrw/eDaAgG0DqlbgO5Di FwGnr X-Gm-Gg: AfdE7cme4sneSMHiAIds83uA/AdObm35ngpK3MxoGOOaatt0CK80tLw7uTotpfIICCK RBYHGU3ZkOz210jHLyNVrWUEZz0tpe52naCC3bmLVQnaBuYVT7bV/Qvim7RbvkwNa0VgwPb/bWT v8uzOM1YHnYGolNz2NHQyekCfgMSezBb/e0a5CohnEgEx4gvzu/Z34oHo6/NI8sM8NmU862Nbd/ Ip3zP1ozuO/mATASX91Dg2A7aRlLstkeoOUdwTocece2vwEcXXC0Igu9xMF0dSEmsNpgYySvZm+ 97ueLf3/5eb74WePga1Qjy4oK375+d9dckBESKoMrIcLQrYcFzmTngzv1WvU9a0kz1VEiJmNcvR ogZ3dPNsamQJSSC6dr7vYma3jnsfSMSswgoXeu106VzzmfmAeRVT8KeLFVXHe7AAYKSd/e27Hvy ZszBFl1JSRYCbtEUreMbOl48RE2/48 X-Received: by 2002:a5d:6f13:0:b0:475:f0f0:9ef0 with SMTP id ffacd0b85a97d-47aaee4cf42mr10114815f8f.53.1783335691319; Mon, 06 Jul 2026 04:01:31 -0700 (PDT) Received: from inspiron14p-linux ([109.77.44.220]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0960634sm25190846f8f.26.2026.07.06.04.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:01:30 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz, Robert Mader , Milan Zamazal Subject: [PATCH v4 1/7] libcamera: software_isp: debayer_egl: Pass eglImage as parameter to setShaderVariables Date: Mon, 6 Jul 2026 12:01:14 +0100 Message-ID: <20260706110120.2509826-2-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> References: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> 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" We will create a cache of textures and eGLImages which means the value assigned to the shader texture unit will come from one of those now cached eGLImage objects. Pass eGLImage as a parameter to facilitate future differentiation. Reviewed-by: Robert Mader Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/debayer_egl.cpp | 6 +++--- src/libcamera/software_isp/debayer_egl.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 56545816e..c3a7b7952 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -388,7 +388,7 @@ uint32_t DebayerEGL::preferredInputStride(const PixelFormat &inputFormat, const return info.stride(size.width, 0, 256); } -void DebayerEGL::setShaderVariableValues(const DebayerParams ¶ms) +void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) { /* * Raw Bayer 8-bit, and packed raw Bayer 10-bit/12-bit formats @@ -444,7 +444,7 @@ void DebayerEGL::setShaderVariableValues(const DebayerParams ¶ms) * To simultaneously sample multiple textures we need to use multiple * texture units */ - glUniform1i(textureUniformBayerDataIn_, eglImageBayerIn_->texture_unit_uniform_id_); + glUniform1i(textureUniformBayerDataIn_, eglImageIn.texture_unit_uniform_id_); /* * These values are: @@ -533,7 +533,7 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye /* Generate the output render framebuffer as render to texture */ egl_.createOutputDMABufTexture2D(*eglImageBayerOut_, output->planes()[0].fd.get()); - setShaderVariableValues(params); + setShaderVariableValues(*eglImageBayerIn_, params); glViewport(0, 0, width_, height_); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLE_FAN, 0, DEBAYER_OPENGL_COORDS); diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index 4c7c86472..348d7305b 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -65,7 +65,7 @@ private: static int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config); int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat); int getShaderVariableLocations(); - void setShaderVariableValues(const DebayerParams ¶ms); + void setShaderVariableValues(eGLImage &eGLImageIn, const DebayerParams ¶ms); int debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *mappedInputBuffer, std::optional *inputBufferDmaSyncer); /* Shader program identifiers */ From patchwork Mon Jul 6 11:01:15 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 27239 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 C7A5DC330A for ; Mon, 6 Jul 2026 11:01:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 58ECE6601E; Mon, 6 Jul 2026 13:01:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="mvBO5g1f"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C097966007 for ; Mon, 6 Jul 2026 13:01:32 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-493c19bad03so26453695e9.2 for ; Mon, 06 Jul 2026 04:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783335692; x=1783940492; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sCherSufb0on4kaTY2CKoIjTcZ+GTv1qK3dt1yZ0ysg=; b=mvBO5g1f7tJ6PKUdt0ZhBXCcr5meLfrqRN2iqRk8gqJQSDA3RwCAfX+snkqxf6IBOJ XO4T2LCADaHtiFWdoYhsxCKS9TAi59lY9zqnHVRDbNPsmHh0teM6U1CEPPIzk/mz8MFp gYbw1GxrocrQQFFmzZUZ8870kPQZqju6uRUOM3pNg5epVv5s809BLdFbrQdwiM8/gzEs j0f2ZEbdkcX5W9zRJaPb8gwXTXHQUx8o0XjVCWVQrw6R5jMAvz3lmHyNqaSFBnDA16lT G0mLLsT6It8ow0ImqB3RNTa3ISuyUhcwhMNE4aPmCY8DFo/fl5KAaavdxkfJWXqCYfU0 L9Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783335692; x=1783940492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=sCherSufb0on4kaTY2CKoIjTcZ+GTv1qK3dt1yZ0ysg=; b=CAGj335mBVe5GXv2i43r6fV8gHLCo/VSBbokNAmWq4bGfN8pMcdfNCWDvzV4ZykLuG grrF4Xz6YuU2UWW9MoQuhJ3LA0LyhnAWWdiMhwKQ3pb+jYebrKOMDpxLNhRjs4a9mom8 3rfA5ae6C/W234FsTz7lYbhX6eDC7A6IMp5akd6Wij85uwIET0mHYdOIA2aQ6gvzKOKX abl5w18vAe1fShqZGvujqn30WnQ1Lv7B3ybfMFEiEuxB8035X68W96RI3CR7GfHBFNmd 7Tbnl7SHXEsWScedUFAMOsdvJ42jqanSidIeuzY6gMCV/gryUAwK9ER/vyNxytU9d1gi S9Xw== X-Gm-Message-State: AOJu0YztEoRpOhrWmMSyL5i4wjzUm6MZFjsMHDmZyq4uus/TrOlVtCex 74RzzRIGlD98RhJOpvLxrbZyMzGSK2/66K/yJp81lxUVTd972QYhMbjwvD7GuZnn88nNsAZTVWZ W6I2B X-Gm-Gg: AfdE7cldx9ygtZk9kObPte0d4jSgjzywFvlKT2g2/9cFsLjcCIevQiH18bTkFTJHWDT Nw3OBBeZwCq3sWCB6aWE1jSFrNV6RSdtJWr9kH7q4EHmtnmmN+NoleY0eZxl6QIZ6KsQM2C569R E4wE9feLRE5BJ7lfFxXLKhrLdakPLfMZb/fFEC6t0eSH+sJa3IVZZTiHSolFH00yp91Gm4w6oGm YJatwGm2sJHfv4vPuUUl8eam1RoLeEdDecSxvvOb/g9alYM3WafZoIgPPC30QJAbr5kfYCC919/ imCXTcF93HMaR6lAZMpVJ7pJoKLwyXeTWY7BKZ7QHB+uoHVzHKJ+euW50iscaDivBlMf3uenmWJ zbs5fIMIAqcn5tp37gn/laXZZ6yB11vNDApluqUwpQWjcn2OeGypoGOEjhOp2lkjUvNQk8OdeNY Ilv6oKWT5bsKzm2RZOlyArhkWjl/4/ X-Received: by 2002:a05:600c:34cb:b0:493:b150:c607 with SMTP id 5b1f17b1804b1-493d11d936amr110500875e9.12.1783335692234; Mon, 06 Jul 2026 04:01:32 -0700 (PDT) Received: from inspiron14p-linux ([109.77.44.220]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0960634sm25190846f8f.26.2026.07.06.04.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:01:31 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz, Robert Mader , Milan Zamazal Subject: [PATCH v4 2/7] libcamera: egl: Add new helper attachTextureToFBO Date: Mon, 6 Jul 2026 12:01:15 +0100 Message-ID: <20260706110120.2509826-3-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> References: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> 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 method does what it says on the tin. It attaches a texture to a framebuffer object, splitting existing code into a helper function which we will use in subsequent patches. Reviewed-by: Robert Mader Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/egl.h | 2 ++ src/libcamera/egl.cpp | 42 +++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 523a62aa8..085a371f3 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -109,6 +109,8 @@ public: int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); void createTexture2D(eGLImage &eglImage, void *data); + int attachTextureToFBO(eGLImage &eglImage); + void pushEnv(std::vector &shaderEnv, const char *str); void makeCurrent(); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index b5a5dc60b..ed67aca7b 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -112,6 +112,32 @@ void eGL::flushOutput() glFlush(); } +/** + * \brief Attach a texture to a frame-buffer-object + * + * \param[in,out] eglImage EGL image containing texture to attach to FBO + * + * Helper function to make attachment of texture to FBO easy to reuse. + * + * \return 0 on success, or -ENODEV on failure + */ +int eGL::attachTextureToFBO(eGLImage &eglImage) +{ + int ret = 0; + + // Generate a framebuffer from our texture direct to dma-buf handle buffer + glBindFramebuffer(GL_FRAMEBUFFER, eglImage.fbo_); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, eglImage.texture_, 0); + + GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (err != GL_FRAMEBUFFER_COMPLETE) { + LOG(eGL, Error) << "glFrameBufferTexture2D error " << err; + ret = -ENODEV; + } + + return ret; +} + /** * \brief Create a DMA-BUF backed 2D texture * \param[in,out] eglImage EGL image to associate with the DMA-BUF @@ -127,6 +153,7 @@ void eGL::flushOutput() int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) { EGLint drm_format; + int ret = 0; ASSERT(tid_ == Thread::currentId()); @@ -186,19 +213,10 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - if (output) { - // Generate a framebuffer from our texture direct to dma-buf handle buffer - glBindFramebuffer(GL_FRAMEBUFFER, eglImage.fbo_); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, eglImage.texture_, 0); + if (output) + ret = attachTextureToFBO(eglImage); - GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (err != GL_FRAMEBUFFER_COMPLETE) { - LOG(eGL, Error) << "glFrameBufferTexture2D error " << err; - return -ENODEV; - } - } - - return 0; + return ret; } /** From patchwork Mon Jul 6 11:01:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 27240 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 A7FBCC330F for ; Mon, 6 Jul 2026 11:01:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5DF476600A; Mon, 6 Jul 2026 13:01:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="gPkkj/me"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AEB2966009 for ; Mon, 6 Jul 2026 13:01:33 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-493bb510ce4so21686625e9.1 for ; Mon, 06 Jul 2026 04:01:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783335693; x=1783940493; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=39/wg15FASnXwYPaNXZRuMgZsbEtqLQEwRNrqEYsJnk=; b=gPkkj/mebEFhnO2hWCz1NWb8//93i73O7xH43v0yDIFYs5CJrhUFZFPNcHtt3dfKCu 56wfP2pj9unSjIbqVSmaGGRsv8EbNZwz+e3KAuwzMOAOOIZ4x8LrNeN+mmDQ/T6TZmdl FideonFLETVfAW007ZrkZpK7MOocFq6W/hLefclHbv5HGjmaDWPL7l+eAliop5QiYvWL JwkMGr5yNT5AgUn+DZu5B6MswA8mCJG21CVvmuSTAMkUkXZK4S2O88oRE3jWb5a/JbKw 0CTcOoUBi1nFi+08G4ndy3sN1YvPFNu5oeypnehSiESsqDF5Xdj2ia79G3z26/qZj3+g 9okA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783335693; x=1783940493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=39/wg15FASnXwYPaNXZRuMgZsbEtqLQEwRNrqEYsJnk=; b=KnwEqj8IuF27Jsy3k/ahjjlliqaWgsS1Grh8aDZpaXYQrK3p9+D0eCbr5nqisNEuZ2 +2Z4mmJc/7aA296zlucC0tseB9uM3mR1ENpdmFqQ6d6kOyqnO5w+pRA3w3XODRw8mTAF H8Sh3CcJWw8fqoklZQH6jtDuSuDBntppkErQiE9JuR7GhYJN8pTX+Ea6qCqbqyPaqiDo iUpqRS+3c75bTNJQoRw008RITsIZHe2oOPGctjRhpKi4tjb3XZjLDMRi5E8CW6tWFtPN J+8jQZqTzK5o23TnCS4ALezZdXAwd06fB4/apTfPD/1mof96JJA18evb+Lz5+4Wjans/ VasA== X-Gm-Message-State: AOJu0YzlxYuN6mR10cPb8koyJI03BCdWay/LXmZ2fgXqBEFJ0V/QPXhn KermmVxW8WBDrlPnlgCF9/dlaGB8eLhRZf3hxz4fvP3KVtHEXqQW9ws4WVE4CgLcg9UmDinQFFK lqb9T X-Gm-Gg: AfdE7clLqp8c5KM+CWLJeveN1IlKDew1CBzRlpE/PB0bfDvl+mF9jGclfdznk7aj86Y aZO3aIG4F7CELPYdc7ZwU+4S8y2I+vX/w6AFdAs9z1gznfeEDyhSCHgqX30nWwDrm/3BlhtjRm7 krBcH59kVNN+zxa//rnhwakAoMZw3AR3zqfBlNiDJoBA9rIQdRN2LzF5KOPuaCUpj0R6Zvfrr4i bfDSu39w4skyz5gi1O/m90IMnDURY9H8HXhxiTASMIxN5dmXKBzdk2jRiYMBDGd8YJC0lKcNJOM d2hPNLiagOXVJO6GJ666rsXgWDnvTYJdEV9n+AgCnaOejNLQYqCHFXwrnErZnEFK6E01hQIL50O PJzj6Yp7DqBiJvl3C6ZplOTugLhbQ5AR84ip5Ck79nCI19Ya6RJiDho/pD3+UBvFPTHF4Xt68l8 YmnCAqzWLbknr8pVvBKFo7PrCcZppb X-Received: by 2002:a05:600c:528c:b0:493:c194:4e7a with SMTP id 5b1f17b1804b1-493d11d3d1dmr114044425e9.3.1783335693085; Mon, 06 Jul 2026 04:01:33 -0700 (PDT) Received: from inspiron14p-linux ([109.77.44.220]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0960634sm25190846f8f.26.2026.07.06.04.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:01:32 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz, Milan Zamazal Subject: [PATCH v4 3/7] libcamera: egl: Add createOutputTexture2D Date: Mon, 6 Jul 2026 12:01:16 +0100 Message-ID: <20260706110120.2509826-4-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> References: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> 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" Creates a non-dmabuf texture attached to a frame-buffer-object FBO, which allows for render-to-texture. Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 085a371f3..1955d09c5 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -108,6 +108,7 @@ public: int createInputDMABufTexture2D(eGLImage &eglImage, int fd); int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); void createTexture2D(eGLImage &eglImage, void *data); + void createOutputTexture2D(eGLImage &eglImage); int attachTextureToFBO(eGLImage &eglImage); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index ed67aca7b..c1b5514b6 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -329,6 +329,19 @@ bool eGL::isAvailable() return true; } +/** + * \brief Create a 2D texture attached to an FBO for render-to-texture + * \param[in,out] eglImage EGL image to associate with the texture + * + * Creates a 2D texture in VRAM. Subsequetly attach the texture to the + * texture unit specified in the eGLImage object. + */ +void eGL::createOutputTexture2D(eGLImage &eglImage) +{ + createTexture2D(eglImage, NULL); + attachTextureToFBO(eglImage); +} + /** * \brief Initialise the EGL context * From patchwork Mon Jul 6 11:01:17 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 27241 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 830A6C3318 for ; Mon, 6 Jul 2026 11:01:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EA4666602B; Mon, 6 Jul 2026 13:01:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="EtouIF7O"; dkim-atps=neutral Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A09AD66007 for ; Mon, 6 Jul 2026 13:01:34 +0200 (CEST) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-475881b9a4bso2493008f8f.3 for ; Mon, 06 Jul 2026 04:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783335694; x=1783940494; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jm28t3W8seSh/4fiCoMetv0uEp/689cCMRBSitfqhw4=; b=EtouIF7O87jh5QNQGt+CYjmDdcWrUDmeHaWz/ajnZjcj4lenawcA/WS7/3T/ifw32U KEuI6Vo+GR3R5tyHjHuTZv5tsZbqwtNUYZJJY9xncrrpy9D7yySJMIJ+1Mmd3MdpBBPO X5UVth0oAqrtmEZOdBiIoMzQGz8Rog1nuouluR4SZx1snhCtlMm9qvIVIcRD1TfxOKb1 Mdk0gN2Zb6jOLPqtONpXGFUOiDHlmVTxhEizfETvewAwWhZ6iFgQwOL8b7zHf/ih5NDe wLKS8vpS8TnBN0R7cfcAEzwj4gYUBA/JFenIbB8UjXuUsen+WSku8vs8bCP9g+qKPZwY ottg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783335694; x=1783940494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=jm28t3W8seSh/4fiCoMetv0uEp/689cCMRBSitfqhw4=; b=p9qIzDsV/dz4Lvk58b78tjPgUB78+SDJs2izZrbT0XL+/R237JWYE4VSC2kuBwMIas j+a77mj9pSF8JiPLvaL2A5Z+Cki2beZjMYiVfNTHzANYumHlabul2Kkyx1678OzuBRdp pk8zWItB8wtbw9DD+Zqkzwj2xfWL9ik5aEqUz6A3N1OEY3H7oLUValqfYVc1Ay04fhgm kqCnpmUM3edXGcSvGRvh16xuX4LUoDCb/I+4l8FPAkqkGfWf34Rw55D72i6KorYi1VGd /CSJEo8oY+OjHKH9/qIfZBo0MfNPB4e4nFftW/9IOfiHRmYKrVBbl7lW6QiHZTrPwntY rghw== X-Gm-Message-State: AOJu0YzdSj6B4ajs9s3EPFA7BMoMRTr4IVWzGJEqJJQSPkSx52XbjQuK r+xCvFZWhkq/Yc/0Ie9CcM7Ic+dhBULSRAJYOHL1sKQaHL8abn4LSA242zLcLxj0/+p8cnXQW/s 6zQHZ X-Gm-Gg: AfdE7cnSin8wDkyM1x8Lu9WtUBwcvaXUylFAsCKh7kqutlnLp1PzYY/9OQC/7YFBvOM uKmIGs3eIhLqJd8/6vr7VmllbyupqRkdbtBmLG1Bb1plu9Y9rW7lSKdTlpADxIxSUhnEo82VBYw Aw3frNtH6AZz2SQ5/aURWnlvEbHuw5neXWmG5QdOEL+p9nn8332Jq5tVwGHuFhO6MKb5NZ5e02c NBUIH8rBx7mSyXxPOR+Q9tny46Ps171WUocyM7BKBpRgghSJP5Ng68hsyoqnhXtT6cYTa8cNmxw IY3pceNr9yjgYqwz0DYwUl1u3Rp27bV2UKJ5HqoPiz5cwJWS4T+U0PFsPkzMHwkvE/430fuhcTN hruYdQjHlw3Hdw+ubhvY+xPtQ+0jQ1ZXToc9dyW8mwcN7gIINhZ56VLXstDRS9mMd0kiWoabXKT VpfW+eGbe7svnscqgmPFmbskfRu2fq X-Received: by 2002:adf:f3c6:0:b0:460:1301:dec6 with SMTP id ffacd0b85a97d-47aab57d2d8mr7214883f8f.10.1783335694131; Mon, 06 Jul 2026 04:01:34 -0700 (PDT) Received: from inspiron14p-linux ([109.77.44.220]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0960634sm25190846f8f.26.2026.07.06.04.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:01:33 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz, Robert Mader , Milan Zamazal Subject: [PATCH v4 4/7] libcamera: egl: Add updateTexture2D Date: Mon, 6 Jul 2026 12:01:17 +0100 Message-ID: <20260706110120.2509826-5-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> References: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> 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 internet box tells me that glTextSubImage2D lets us update a texture's data only, instead of recreating the texture and uploading data. This is a smallish optimisation but we are hunting for every possible cycle and watt so add the routine as precursor to using it in-place of createTexture2D on every upload cycle. Reviewed-by: Robert Mader Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 1955d09c5..9b4261c55 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -108,6 +108,7 @@ public: int createInputDMABufTexture2D(eGLImage &eglImage, int fd); int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); void createTexture2D(eGLImage &eglImage, void *data); + void updateTexture2D(eGLImage &eglImage, void *data); void createOutputTexture2D(eGLImage &eglImage); int attachTextureToFBO(eGLImage &eglImage); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index c1b5514b6..b91f9096a 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -329,6 +329,24 @@ bool eGL::isAvailable() return true; } +/** + * \brief Update a 2D texture already created + * \param[in,out] eglImage EGL image to associate with the texture + * \param[data] Data to update the texture with + * + * Updates a 2D texture in VRAM. + */ +void eGL::updateTexture2D(eGLImage &eglImage, void *data) +{ + ASSERT(tid_ == Thread::currentId()); + + glActiveTexture(eglImage.texture_unit_); + glBindTexture(GL_TEXTURE_2D, eglImage.texture_); + + // Update an already existing texture + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, eglImage.width_, eglImage.height_, eglImage.format_, GL_UNSIGNED_BYTE, data); +} + /** * \brief Create a 2D texture attached to an FBO for render-to-texture * \param[in,out] eglImage EGL image to associate with the texture From patchwork Mon Jul 6 11:01:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 27242 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 445D1C330A for ; Mon, 6 Jul 2026 11:01:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0EF9666017; Mon, 6 Jul 2026 13:01:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="rfOlRj/e"; dkim-atps=neutral Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E7BD56602D for ; Mon, 6 Jul 2026 13:01:35 +0200 (CEST) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-474303f3c72so1680808f8f.0 for ; Mon, 06 Jul 2026 04:01:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783335695; x=1783940495; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fVHnbZZMdwqZk7BriO9P1JA0RaTstJWzBgni6R3v/IE=; b=rfOlRj/e+VZWhjkFHMhg6qqFPHJMfhnP+EKgMH+8DgdDU5MSeAAjebyzWEfLLke565 fZL9lfxCGhx9X4n1oKsjRuAz26D4AfNXLxcl/7/AUKIoODlhv3Kshc00ZZyVsJJ1INbl wAheN5Bz8ijUVZFbemfig77irE0mLrtFi6t0c3zaFDcRg847Vn2fk9X4st4Tv4S9eegM rU7l/mQXsKIAWQbr4AZDc7YOjb8VDdAszAFPJ544NanJ68e6m1vEzcARUFyvIBQl+Ucj /GHnsUE8F+5gMLPv3TGkAXAkRDlXgXRslqGCd3+IpqUrSy0gEFdrx3kixE83dzzxDK5r M61w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783335695; x=1783940495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=fVHnbZZMdwqZk7BriO9P1JA0RaTstJWzBgni6R3v/IE=; b=he576qzGP1kPKVhw9hygV9Ve6IX4TieRAiRXXDmblEyV7Bq1BdhgA7CW6zbyfeZAr1 WatEcfJAeNrXYts9YksQMdKt51HQ5g0NoDmS3lkrfKxhT8Dy9f/Fl3ppT20/QYQs+p7S P3OhM2mSQcSTrcSDwI1J2vnbJakjacPzDRwDMWEznqUOhrqxZmRvkDIhx34R4/H3oe7/ Hyju1sWZoRZgPhvpk3UPXJqpwsyTbXlgw74sECL5EmxGt/IIVUkaiIGUi6+Jf5TCMt4K L/viDYG9etuS8t7cTK3Fiy4LfjBEexLWdi1iXm9nZaqGtXWuPVmkY87iSAyNs5NzDPP5 E9Iw== X-Gm-Message-State: AOJu0YzOTh7Ax6Ja3vq4HvHvngTlONM5Wp+k36DU4CbLjHA9bpDJEYSf LETtzkgm/TnB/AZJldInI9FABYSvbfwux1D+SHkpU76t+Kuz9mgnmsn5NjnbQ1QxygqP91ZXAs/ En1tw X-Gm-Gg: AfdE7ckHpwGSPU/Bz63UGQJai3Bhookqni9HaGNCVIFF4BH6fJDue6XFFmhknJZ3uvn trYhLnVCOBsA7p0ZkjPDOhx9ote+ZUFDJei2haxNAYEoYFyK04jAcpo4vL/Xeygkc2aZQsBPY0d 55FB27a5rR3k41kCHA7PP0pUs3+HNNEBQV4OGS/ADOWAcW2sj0434Ca5Q+Id+0cpuhZREunZo/j IuvHhFvFewTLaBLXSnKUxKv/tqNa/y52VacCLmhHXOGVD+3rVxMfSKck04dTktU6BTHuvJBATvj y1LsBF8nvkjlUi4nJPPI1Aq8XO+BPb73ix7ZqudFnXBB/12DhkgwxssRL5+Iao+P3STHMykKfbe 8XLTID60lIkQSg/IcuyamNqTHRurzlnrlGoDs/PhHErt6uJybWW3dyBXdn6fBSNvSyRER9P/t92 2EtFCDWk0D8GJRx0g+UYCiHrx7IFlX X-Received: by 2002:a05:6000:61e:b0:475:da0e:7465 with SMTP id ffacd0b85a97d-47aa92c070dmr12584346f8f.5.1783335695236; Mon, 06 Jul 2026 04:01:35 -0700 (PDT) Received: from inspiron14p-linux ([109.77.44.220]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0960634sm25190846f8f.26.2026.07.06.04.01.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:01:34 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz, Robert Mader , Milan Zamazal Subject: [PATCH v4 5/7] libcamera: egl: Add activateBindTexture Date: Mon, 6 Jul 2026 12:01:18 +0100 Message-ID: <20260706110120.2509826-6-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> References: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> 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" When operating from a texture cache on dma-buf inputs we will no longer create new textures nor attach those textures for dma-buf handles we have already encountered. This means we will use the texture id associated with a given texture unit to switch between one texture and another. The pages associated with the texture will have been populated with new data by the CSI2 receiver. All we will do is say to the GPU "reuse this texture id" aka zero-copy. However we must also activate and bind that texture for each loop. This cost is small but necessary for zero-copy. Reviewed-by: Robert Mader Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 9b4261c55..1e31d490b 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -112,6 +112,7 @@ public: void createOutputTexture2D(eGLImage &eglImage); int attachTextureToFBO(eGLImage &eglImage); + void activateBindTexture(eGLImage &eglImage); void pushEnv(std::vector &shaderEnv, const char *str); void makeCurrent(); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index b91f9096a..fae907881 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -138,6 +138,23 @@ int eGL::attachTextureToFBO(eGLImage &eglImage) return ret; } +/** + * \brief Activate a texture unit and bind a texture to that unit + * \param[in,out] eglImage EGL image containing data related to unit and texture id + * + * When we create a texture we will bind a texture unit and texture id so + * we can set filters. For the case where a texture already exists though + * we need to activate and bind an existing texture. This helper function + * facilitates both cases. + * + */ +void eGL::activateBindTexture(eGLImage &eglImage) +{ + // Bind texture unit and texture + glActiveTexture(eglImage.texture_unit_); + glBindTexture(GL_TEXTURE_2D, eglImage.texture_); +} + /** * \brief Create a DMA-BUF backed 2D texture * \param[in,out] eglImage EGL image to associate with the DMA-BUF @@ -197,9 +214,7 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) return -ENODEV; } - // Bind texture unit and texture - glActiveTexture(eglImage.texture_unit_); - glBindTexture(GL_TEXTURE_2D, eglImage.texture_); + activateBindTexture(eglImage); // Generate texture with filter semantics glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); @@ -270,8 +285,7 @@ void eGL::createTexture2D(eGLImage &eglImage, void *data) { ASSERT(tid_ == Thread::currentId()); - glActiveTexture(eglImage.texture_unit_); - glBindTexture(GL_TEXTURE_2D, eglImage.texture_); + activateBindTexture(eglImage); // Generate texture, bind, associate image to texture, configure, unbind glTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, eglImage.format_, GL_UNSIGNED_BYTE, data); From patchwork Mon Jul 6 11:01:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 27243 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 03F10C330F for ; Mon, 6 Jul 2026 11:01:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9B14766033; Mon, 6 Jul 2026 13:01:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="gnLOmaGz"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 959106600A for ; Mon, 6 Jul 2026 13:01:36 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-493ce08a75bso11843845e9.1 for ; Mon, 06 Jul 2026 04:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783335696; x=1783940496; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iBRWJUBS/Uq8NB/fn6jxhZu1bX+RaDP4LLlVacS3Kt8=; b=gnLOmaGzWzRQ87zJ2YLDGOctGXtRC3h28pOtxPgCrhuZbnkG9PRBKdyPD+8+GzpvQ5 bx1yxdhFojmu8Pnag8ATm8PZJYzl2HMl/LF5yg/GrYiMMg6txLYqwdkIP7zFE32thzNG p4CKhoo5tIaPujGT+WQvRlvLwwtNZCtlT16bUjZj7BfzkN8K4e3h3RtFbNkqvD0Hq/BA wygopG28onD7OlwwwN6n3RBtcndxYmfmFP7WArsSyvCENmMv08y8gnR1hFtn637swbNO Czslz63vN7dViTwJkMdjfZ3pGu4KpeA8Xui2SWu/0gsyejwyGiyXCCe1P8KWVKltB5b1 Q/jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783335696; x=1783940496; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iBRWJUBS/Uq8NB/fn6jxhZu1bX+RaDP4LLlVacS3Kt8=; b=g/2YaqQwueqxJkYIGRoqcK7sZOseosEeiX5aXd1CgiTs/YxxSKSt+PS7STw4wn4hfJ BjJr/gES2wGPlV3Q5+EC53nQYGKXq8dG2vG0yWFTRjZ+bxonO92qKn+NJJlutybOqYId C6wVDW5c4rX06BxXbaJD3T28tplQMAQGXh5dYDkmdu/rzw1/DJP0Y69X+bSf2eajsjsG 3fdWhqvmP38zXIZXJmUh2kKmt8Jb/wGPllxl+5f8sIjV+ZS0wJWJFcJd1p1mlVEKAuUQ pFaAuuawxVbOQPKb6J72vXtEffhOTw1qbu4qbxto0o20MDaoEu+wpswsFqiL0Evmvmkt KU7Q== X-Gm-Message-State: AOJu0Yw6iN/+Ctkku192X2DbgqJv131UbwFNdG5apGjB3JhFka+8o4vY AOZEEJMJ2ygAjI3abugwMnqPmAW7uaWpvGt3bRWBsd8M+8X0I4M3B383fw0DOSnTxvbDoDBa45/ omKtZ X-Gm-Gg: AfdE7ckTeveeXkbo+oTP+mm7zfCOqRM3c52tXniljOpZ/0fZFyQt+NZzPlM8VHcb+7v erZXFX9aUaKJ6TE6sE8s3n65vfoRMkQlJ87CZGTDDMpI3Ii70yKgCvF1fCUof+E2fGbnRa0wgHq JAZMY14x8NUEuqWKOg/jp/Yn3u54ZWYfH3YfLwnHTVvpTS3FiIelavfQ+aLR5OglpzncmudrhYU ud7lkQasBX9iMs8OcexzR9cQnDhvZOkNa+dMcsxcdz+3pH8a/J8qKK39Uh63Do4qYACI0eN1IdR a9xqvOFzphSpPhCmgUY6QpvdKp8l81vLFD878jezVVvn1yfcfFcDd2voff6Gznsa02YD93c6UGx 2wO1PZ0dnnbMULb38yRSIUK+92RxrD5BI/QT4tbiQxVnTmzi3D/PqVDgAwLNO/jva6o8sqhK9iw SakXYO3i0C6SXdCZbTU8oUwirC3XiO X-Received: by 2002:a05:600c:3b10:b0:492:3e44:214b with SMTP id 5b1f17b1804b1-493d11d7373mr109945035e9.13.1783335696148; Mon, 06 Jul 2026 04:01:36 -0700 (PDT) Received: from inspiron14p-linux ([109.77.44.220]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0960634sm25190846f8f.26.2026.07.06.04.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:01:35 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz, Robert Mader , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v4 6/7] libcamera: base: shared_fd: Add hash template Date: Mon, 6 Jul 2026 12:01:19 +0100 Message-ID: <20260706110120.2509826-7-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> References: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> 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" From: Robert Mader Suggested-by: Barnabás Pőcze Signed-off-by: Robert Mader Signed-off-by: Bryan O'Donoghue --- Documentation/Doxyfile-common.in | 2 ++ include/libcamera/base/shared_fd.h | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/Documentation/Doxyfile-common.in b/Documentation/Doxyfile-common.in index f11ec593d..c0696496c 100644 --- a/Documentation/Doxyfile-common.in +++ b/Documentation/Doxyfile-common.in @@ -75,3 +75,5 @@ PREDEFINED = __DOXYGEN__ \ @PREDEFINED@ HAVE_DOT = YES + +BUILTIN_STL_SUPPORT = YES diff --git a/include/libcamera/base/shared_fd.h b/include/libcamera/base/shared_fd.h index 61fe11c1d..65b1044c7 100644 --- a/include/libcamera/base/shared_fd.h +++ b/include/libcamera/base/shared_fd.h @@ -7,6 +7,7 @@ #pragma once +#include #include namespace libcamera { @@ -57,3 +58,11 @@ static inline bool operator!=(const SharedFD &lhs, const SharedFD &rhs) } } /* namespace libcamera */ + +template<> +struct std::hash : private std::hash { + auto operator()(const libcamera::SharedFD &x) const noexcept + { + return std::hash::operator()(x.get()); + } +}; From patchwork Mon Jul 6 11:01:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 27244 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 13A9FC3318 for ; Mon, 6 Jul 2026 11:01:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AB07F66049; Mon, 6 Jul 2026 13:01:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="wxxhdkvD"; dkim-atps=neutral Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A965F6601E for ; Mon, 6 Jul 2026 13:01:37 +0200 (CEST) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-493d3135f62so9214475e9.2 for ; Mon, 06 Jul 2026 04:01:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783335697; x=1783940497; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iBp5CTAibDRDjJr1C9jbaznxXxt4zBdSgPR4F1nm75g=; b=wxxhdkvDyjBC41/rmAuJXR9g18jaCVLvuuVSUUqWD0Hc/I2Sd6dL2uFjLhpKvT6ahM SsdpCuvH6pqsLH3glMbnMSvQ9H7AyvvsMkXt5M42AtdARHOolXtyIodt2/Ztx0R4uYFt 77R55E4kRedeieX52CvO+ZzocWRwBj1o4c1lzCbg+uHnVsCVBg3we13D5jccz148A5Ht DTdG/44K7zqGtVdZDDQ1bi3urjHOb+OBiSNf25aVc8nDLxZyJMItbALEWz19aTmOf+kd H6vY2v/fiRlC/t6MLmqA3VGlskNHvhE0sQqAf9o41gFg+xi5npH4y8vMF7xWkV76YVh/ sipw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783335697; x=1783940497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iBp5CTAibDRDjJr1C9jbaznxXxt4zBdSgPR4F1nm75g=; b=k008U8OIu+zCJX3uhqD20+NSlHc0mDCgiy97uclfejKCOKOXocUgbdqceNXXiLfeax u4jgex8+s7PO0K9iTT9NUZes5qSCwfgjdbnX6oCW5JVEYQB7MQ3bh8H6VVo/YMG74DQP 6vtu43SwmvbhHUZlp2AUbgyZBgM8oQtpVHbTxvS5TiIspX8MYaqxGOerYyW3Fv+w8OT/ ndzQl2Lzqdk7dwDD/vmZzLTSRbfgoimgVOqqN6WWduRQyKjNqHSXtv31C/+62UwWjVJy p+oTPPT+SHvlNQNHopSarUPDWxsaZoCIN9K2LmTiD6Ui34w4ltQXT3lLEPLjo+h4yxSo LqbQ== X-Gm-Message-State: AOJu0YzVdHt/esGpSuHQlJ+ZrLxPQGemZFO0yZqdgtXB2ym5xJ8m7Q3a UWTSWHKQijwEYIMz3tTVtVDyQ9vAIeOBKJekTbdquyn09NJgRxALSuKlw/sdBxGWGU88NS5+SD2 mqEdL X-Gm-Gg: AfdE7clVvtuo/kf6hzzuOJ85e3QVSqyHmzmxrtG+JFFWmNMT6hb4sXIU4xS1vqS5sIP DUjX+tnttOVaQJJl0jpVftDDgpPPS1QwRctQ1d56hVUIEAs7V9v9OnZGSEWOtKMaZEBargTW2B2 cHvRxRn4Icph1L0yrmKL0WfZuQIhoX4LEsCTwhGUAQsp/kobcjJh/gCgX8nXW3ge9kMMV2kwz7Q 5WOSDfuoqS8dTE0vMXAEYSvl7xjhcS+o+V19KKOUFOT+Cin28PzGGV7nxMIugklDnfjvjm7Z08Y R+t30BUW7VDvO8i7eHcHARb37H93ke6hJKZm+klUrLJTqTyQTIMy+DYj2q6SBgjoOWJ6IhaGE3z hTQKROvgj/21CL8i6J3Sb8+Sk+bqPXSerhBSlFFtikIY8MIad8eeREy659wIQ01XeY8Kpqy6voz bNM/QQyKJt8YZQQ0FXFwN70EsqdHv5 X-Received: by 2002:a05:600c:6992:b0:493:bc4a:fb50 with SMTP id 5b1f17b1804b1-493d11fdfb6mr112574575e9.38.1783335697116; Mon, 06 Jul 2026 04:01:37 -0700 (PDT) Received: from inspiron14p-linux ([109.77.44.220]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0960634sm25190846f8f.26.2026.07.06.04.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:01:36 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH v4 7/7] libcamera: software_isp: debayer_egl: Implement input/output frame caching mechanism Date: Mon, 6 Jul 2026 12:01:20 +0100 Message-ID: <20260706110120.2509826-8-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> References: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> 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" Implement a texture caching mechanism for both input and output frames and for both types of input frame. The before/after on a Qualcomm x1e is: 9.737ms per frame 5.691ms per frame The before/after on a Qualcomm sm8250 is: 21.710ms per frame 17.336ms per frame for i in {1..20} do cam -c /base/soc@0/cci@ac16000/i2c-bus@1/camera@10 -s width=1920,height=1080 --capture=60 Interestingly there appears to be an absolute ~ 4.x ms per frame uplift as opposed to what intuition might suggest a proportional. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/debayer_egl.cpp | 112 ++++++++++++++++----- src/libcamera/software_isp/debayer_egl.h | 13 ++- 2 files changed, 96 insertions(+), 29 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index c3a7b7952..ca3353d9f 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -345,6 +345,9 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, */ stats_->setWindow(Rectangle(window_.size())); + inputBufferCount_ = inputCfg.bufferCount; + outputBufferCount_ = outputCfg.bufferCount; + return 0; } @@ -504,36 +507,95 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara return; } -int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *inMapped, std::optional *inDmaSyncer) +eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer) { - bool dmabuf_import_succeeded = false; - - /* eGL context switch */ - egl_.makeCurrent(); - - /* Try to create texture for input buffer via dmabuf import */ - if (!eglImageBayerIn_->dmabuf_import_failed_) { - if (egl_.createInputDMABufTexture2D(*eglImageBayerIn_, input->planes()[0].fd.get()) == 0) - dmabuf_import_succeeded = true; - else - LOG(Debayer, Info) << "Importing input buffer with DMABuf import failed, falling back to upload"; + const SharedFD &fd = input->planes()[0].fd; + bool use_dmabuf = false; + + auto [input_cache, cache_miss] = eglImageBayerIn_.try_emplace(fd); + if (cache_miss) { + if (eglImageBayerIn_.size() > inputBufferCount_) { + eglImageBayerIn_.erase(inputRing_.front()); + inputRing_.pop_front(); + LOG(Debayer, Error) << "Input cache " << inputBufferCount_ << " exceeded evicted entry"; + } + input_cache->second = std::make_unique(glFormat_, inputConfig_.stride / bytesPerPixel_, + height_, inputConfig_.stride, GL_TEXTURE0, 0); + inputRing_.push_back(fd); + } + eGLImage *eglImageIn = input_cache->second.get(); + + /* Try to create texture for input buffer via dmabuf import only on cache miss */ + if (cache_miss) { + if (egl_.createInputDMABufTexture2D(*eglImageIn, input->planes()[0].fd.get()) == 0) + use_dmabuf = true; + } else if (!eglImageIn->dmabuf_import_failed_) { + use_dmabuf = true; + egl_.activateBindTexture(*eglImageIn); } - /* Otherwise create texture for input buffer via upload from CPU */ - if (!dmabuf_import_succeeded) { + if (!use_dmabuf) { inDmaSyncer->emplace(input->planes()[0].fd, DmaSyncer::SyncType::Read); inMapped->emplace(input, MappedFrameBuffer::MapFlag::Read); if (!inMapped->value().isValid()) { LOG(Debayer, Error) << "mmap-ing buffer(s) failed"; - return -ENODEV; + if (cache_miss) { + eglImageBayerIn_.erase(input_cache); + inputRing_.pop_back(); + } + return nullptr; + } + if (cache_miss) + egl_.createTexture2D(*eglImageIn, inMapped->value().planes()[0].data()); + else + egl_.updateTexture2D(*eglImageIn, inMapped->value().planes()[0].data()); + } + + return eglImageIn; +} + +eGLImage *DebayerEGL::getCachedOutputFrameBuffer(FrameBuffer *output) +{ + const SharedFD &fd = output->planes()[0].fd; + + auto [output_cache, cache_miss] = eglImageBayerOut_.try_emplace(fd); + if (cache_miss) { + if (eglImageBayerOut_.size() > outputBufferCount_) { + eglImageBayerOut_.erase(outputRing_.front()); + outputRing_.pop_front(); + LOG(Debayer, Error) << "Output cache " << outputBufferCount_ << " exceeded evicted entry"; } - egl_.createTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data()); + output_cache->second = std::make_unique(GL_RGBA, outputSize_.width, + outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); + if (egl_.createOutputDMABufTexture2D(*output_cache->second, output->planes()[0].fd.get())) { + eglImageBayerOut_.erase(output_cache); + return nullptr; + } + outputRing_.push_back(fd); } + eGLImage *eglImageOut = output_cache->second.get(); + + return eglImageOut; +} + +int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *inMapped, std::optional *inDmaSyncer) +{ + eGLImage *eglImageIn; + eGLImage *eglImageOut; + + /* eGL context switch */ + egl_.makeCurrent(); - /* Generate the output render framebuffer as render to texture */ - egl_.createOutputDMABufTexture2D(*eglImageBayerOut_, output->planes()[0].fd.get()); + eglImageIn = getCachedInputFrameBuffer(input, inMapped, inDmaSyncer); + if (!eglImageIn) + return -ENOMEM; + eglImageOut = getCachedOutputFrameBuffer(output); + if (!eglImageOut) + return -ENOMEM; + + egl_.attachTextureToFBO(*eglImageOut); + setShaderVariableValues(*eglImageIn, params); - setShaderVariableValues(*eglImageBayerIn_, params); glViewport(0, 0, width_, height_); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLE_FAN, 0, DEBAYER_OPENGL_COORDS); @@ -615,19 +677,15 @@ int DebayerEGL::start() if (initBayerShaders(inputPixelFormat_, outputPixelFormat_)) return -EINVAL; - /* Raw bayer input as texture */ - eglImageBayerIn_ = std::make_unique(glFormat_, inputConfig_.stride / bytesPerPixel_, height_, inputConfig_.stride, GL_TEXTURE0, 0); - - /* Texture we will render to */ - eglImageBayerOut_ = std::make_unique(GL_RGBA, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); - return 0; } void DebayerEGL::stop() { - eglImageBayerOut_.reset(); - eglImageBayerIn_.reset(); + eglImageBayerOut_.clear(); + eglImageBayerIn_.clear(); + outputRing_.clear(); + inputRing_.clear(); if (programId_) glDeleteProgram(programId_); diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index 348d7305b..dde6ba9bf 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -9,9 +9,11 @@ #pragma once +#include #include #include #include +#include #include #define GL_GLEXT_PROTOTYPES @@ -68,14 +70,21 @@ private: void setShaderVariableValues(eGLImage &eGLImageIn, const DebayerParams ¶ms); int debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *mappedInputBuffer, std::optional *inputBufferDmaSyncer); + eGLImage *getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer); + eGLImage *getCachedOutputFrameBuffer(FrameBuffer *output); + /* Shader program identifiers */ GLuint vertexShaderId_ = 0; GLuint fragmentShaderId_ = 0; GLuint programId_ = 0; /* Pointer to object representing input texture */ - std::unique_ptr eglImageBayerIn_; - std::unique_ptr eglImageBayerOut_; + std::unordered_map> eglImageBayerIn_; + std::unordered_map> eglImageBayerOut_; + std::deque inputRing_; + std::deque outputRing_; + unsigned int inputBufferCount_; + unsigned int outputBufferCount_; /* Shader parameters */ float firstRed_x_;