From patchwork Wed Jun 24 08:58:40 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: 27027 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 7F52CC3306 for ; Wed, 24 Jun 2026 08:59:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 39B126587E; Wed, 24 Jun 2026 10:59:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="R1B/fOe+"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5186765871 for ; Wed, 24 Jun 2026 10:59:01 +0200 (CEST) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-490cf322ed0so7761855e9.1 for ; Wed, 24 Jun 2026 01:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782291541; x=1782896341; 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=6h4OQ/s+gFr1NSlfpnHCoeE5/7D8tFJMOobc3VjW2hA=; b=R1B/fOe+2nUG5dz2edWTBmjuBLAHWEY6BsVHKYWtEZK6UMsqCrwAhvcHwkuRpTXblZ ShuNuq4V8VWx2sW2CvR8FLy5hsZXkbwb0zEh4p0qGI7WIoIwcQfEarh0CRLxavNrLdcM RaaHCcE+j8xDzlWM05Wxe6U1l2krcjfT3z/P84qUsp7HfPzBgYCoa8I29e9W4heDzxCR MUaaLmbVHVIzBFES57YXNy72fD08/DdopZ0B8NePvESdRWjprz5nbIJ9+vlb+C1SNC/9 h72BpV8tOBOnt74wIpI/A72gcIQrzS15s7osZA46lFA2KJ30WrZaBtgCOOItKnE1TFKE IVxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782291541; x=1782896341; 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=6h4OQ/s+gFr1NSlfpnHCoeE5/7D8tFJMOobc3VjW2hA=; b=MMo+za2IsLETtJPw/ogFaZHhVEwkk2RwM6oHXxBIu7QOcgZPaLhTTtMzWhKZvohdRg YHiW4uMDOV54Bq6qORd3ud3le84sQe8+5erWGAWbtzxYn4S74E5cQHcrB8xfLy18TrBr K3yXMmW2a3ImPXYFCUY6Sm1YzPToXRzAFRmp1iN5WGH6E4bkDC8u2Ut0/CyI+xZSpwBL PCKflktVtMAvsuRBqNpYeR2zQwblmXgDnw5hltPcpCVmBPKZNvGCkbe5cBNAfgxkDsuo 6Sg1Ew7iwPa1PfaHTGvWJp9xLzlkHp4CQt1sGEg0bc/ZFbbbUtkUB3lbOg1p3odmKYtP wEbw== X-Gm-Message-State: AOJu0Ywm7PQFnVYZHTvW0BczBIipH3tzgayWkR5SQ4Q5G0CeHcjZp1jR FUd1vXJl4kx0ht7eHK/rP55hGbYpvCVM3iYErc1pKT6E3RVePv+yGzTGJbBEVSEkovIJkrVLja4 Ta4JqQ8o= X-Gm-Gg: AfdE7ckKlJwO5v8aOXdJdDHcG9atO0n2wTUDOLIeCsaOF4sF2bv/VyDgN9upYyu5DxL Wb41igmbU0omeCxDSCdZJAs/vRSXkSijzmsqOt6vQUhB5cIfQpNRMKvpoyAXCh1RbqyD2jrAcZX LzPue0N9NicR17Tz/dY49mJ+SMM/nbjUUvC0PyEguAGvcFw3YDzhVkpu/mow/76tFdgCVHzVgxP rDdQpQzuP/GL/yEqskmZvwR6i9IS+MkbT3UwWhtT9ut5+7NWcJAaQfX83vVQmPGTcKYa0s1tfY0 WIopxEfP/rG0zyYG/MXdlXoTh85vLveNQO0JI7/gRkm13cgOOJ89ktA9aDig0ynJtKsU3QzVUa9 6cm7ayM8cHAbyA00RqNaF2G4IJ/GS5sqn82F4RP5kZgDdoBG2pvpBwY8daK48hm/Yj1YAaldFun X9lIZD8C/SvZT/lmmUc0086nYbGYwIPSQvW2arYdo= X-Received: by 2002:a05:600c:c494:b0:492:5a58:3c6a with SMTP id 5b1f17b1804b1-492608496d5mr29809635e9.5.1782291540786; Wed, 24 Jun 2026 01:59:00 -0700 (PDT) Received: from inspiron14p-linux ([109.76.100.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49261063d6esm25128375e9.2.2026.06.24.01.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 01:58:59 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH 01/10] libcamera: v4l2_videodevice: Output cache hit as a parameter Date: Wed, 24 Jun 2026 09:58:40 +0100 Message-ID: <20260624085849.873784-2-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260624085849.873784-1-bryan.odonoghue@linaro.org> References: <20260624085849.873784-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 existing V4L2BufferCache::get routine evaluates if a cache hit has occured by way of an internal variable. It is in fact very useful to a user of this API to understand if a hit has occured as using logic may wish to differentiate based on hit or miss. This differentiation is required for GPUISP. Rather than add a routine to interrogate if a cache hit exists - add an output parameter to the get routine. In simple terms if you are trying to cache data about the last thing you want to to is interrogate the cache twice so, a `hit` output parameter adds a small cost in the stack for a large pivot in using code's ability to understand how much work it needs to do on hit v miss. Signed-off-by: Bryan O'Donoghue Reviewed-by: Robert Mader --- include/libcamera/internal/v4l2_videodevice.h | 2 +- src/libcamera/v4l2_videodevice.cpp | 9 ++++++--- test/v4l2_videodevice/buffer_cache.cpp | 14 +++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 10367e4e1..49165a565 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -129,7 +129,7 @@ public: ~V4L2BufferCache(); bool isEmpty() const; - int get(const FrameBuffer &buffer); + int get(const FrameBuffer &buffer, bool &hit); void put(unsigned int index); private: diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index ca8759830..6496eb324 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -217,6 +217,7 @@ bool V4L2BufferCache::isEmpty() const /** * \brief Find the best V4L2 buffer for a FrameBuffer * \param[in] buffer The FrameBuffer + * \param[out] hit. Indicates if there was a cache hit * * Find the best V4L2 buffer index to be used for the FrameBuffer \a buffer * based on previous mappings of frame buffers to V4L2 buffers. If a free V4L2 @@ -227,12 +228,13 @@ bool V4L2BufferCache::isEmpty() const * \return The index of the best V4L2 buffer, or -ENOENT if no free V4L2 buffer * is available */ -int V4L2BufferCache::get(const FrameBuffer &buffer) +int V4L2BufferCache::get(const FrameBuffer &buffer, bool &hit) { - bool hit = false; int use = -1; uint64_t oldest = UINT64_MAX; + hit = false; + for (unsigned int index = 0; index < cache_.size(); index++) { const Entry &entry = cache_[index]; @@ -1649,6 +1651,7 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer, const V4L2Request *request { struct v4l2_plane v4l2Planes[VIDEO_MAX_PLANES] = {}; struct v4l2_buffer buf = {}; + bool hit; int ret; if (state_ == State::Stopping) { @@ -1666,7 +1669,7 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer, const V4L2Request *request return -ENOENT; } - ret = cache_->get(*buffer); + ret = cache_->get(*buffer, hit); if (ret < 0) return ret; diff --git a/test/v4l2_videodevice/buffer_cache.cpp b/test/v4l2_videodevice/buffer_cache.cpp index 613e0d7ce..e41c30059 100644 --- a/test/v4l2_videodevice/buffer_cache.cpp +++ b/test/v4l2_videodevice/buffer_cache.cpp @@ -35,7 +35,8 @@ public: { for (unsigned int i = 0; i < buffers.size() * 100; i++) { int nBuffer = i % buffers.size(); - int index = cache->get(*buffers[nBuffer].get()); + bool hit; + int index = cache->get(*buffers[nBuffer].get(), hit); if (index != nBuffer) { std::cout << "Expected index " << nBuffer @@ -60,7 +61,8 @@ public: for (unsigned int i = 0; i < buffers.size() * 100; i++) { int nBuffer = dist(generator_); - int index = cache->get(*buffers[nBuffer].get()); + bool hit; + int index = cache->get(*buffers[nBuffer].get(), hit); if (index < 0) { std::cout << "Failed lookup from cache" @@ -90,7 +92,8 @@ public: /* Pick a hot buffer at random and store its index. */ int hotBuffer = dist(generator_); - int hotIndex = cache->get(*buffers[hotBuffer].get()); + bool hit; + int hotIndex = cache->get(*buffers[hotBuffer].get(), hit); cache->put(hotIndex); /* @@ -106,7 +109,7 @@ public: else nBuffer = dist(generator_); - index = cache->get(*buffers[nBuffer].get()); + index = cache->get(*buffers[nBuffer].get(), hit); if (index < 0) { std::cout << "Failed lookup from cache" @@ -135,7 +138,8 @@ public: for (const auto &buffer : buffers) { FrameBuffer &b = *buffer.get(); - cache.get(b); + bool hit; + cache.get(b, hit); } if (cache.isEmpty()) From patchwork Wed Jun 24 08:58:41 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: 27028 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 0A9DFC3306 for ; Wed, 24 Jun 2026 08:59:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 74A7465890; Wed, 24 Jun 2026 10:59:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="z2Vy+Mm9"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0856265881 for ; Wed, 24 Jun 2026 10:59:02 +0200 (CEST) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-490ace40f4bso7839925e9.3 for ; Wed, 24 Jun 2026 01:59:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782291541; x=1782896341; 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=DGSX4mJkH/NgV4HkrvHTAen8yB9jSEbQDaqlO5PH55E=; b=z2Vy+Mm9PhuTr3ApY5O29hlXis/BXAx36Ph4zocNYSzxWk4GwHHjAk2H2Bej5jLsIk zE35UYTovo7Fh5WDZuCKJ5jmWiL1UXXf88xn9PlQcOzVdnqY+b0DxP2AR2FW0oIuh0Yk JlLPwHISTj55xkx7sIGJ4W5qeoi8NFFQuh9/J+xNCslJd71FF4DgQglsn06ymRe6FrwE v6O+Q057BRQUms4So1GKzPQiaalxLxYxxMvuauqWDR80X189A0uBxqquQKqGMAKp4yeF RCEfURXTEktle//v08++EAfK3NOH1nDvmOchBh3QEbuZJH7jBDYSzNOSHCKV4vZRo/0g /vug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782291541; x=1782896341; 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=DGSX4mJkH/NgV4HkrvHTAen8yB9jSEbQDaqlO5PH55E=; b=FOayKRD8ro3nCvFSIDdsnnFYQnWdTzTbNAmri8lY/cdtKRXSNIzmb224WkXBi9JQmS VIDqpk8TcVQ2qA/svr858MXmloJQ5Y6pHDz0QXcS+QQxoqHJunwR9kescy7QQYzNub8F VngkvFg5pho2hjvj5Bv/52OZS1ZcmfEhMvyneqmMeZofsfJAjQrGL3DfQewpsSWH/RLh Apa9j2H0DNlv5rhYPRmu7T0ahxD1dCG8zlUpUtJOzCyBqgiRbvYrkumY2n9F3Wwar6At DTEVjYRN+BwNcQvdrbRA+FmHhQfdQmqTxOCR3cqV1GdUAC55tqyxHqFPNLQ5qI/9lA4u e8DQ== X-Gm-Message-State: AOJu0YyyZByKwlZ1N4YbW/GxIkkjq0eGALbcEI5MEYM2SYEVWidNwwTM X2AG1akH5569X4xcwP8VV04Ck+D8mGiJFg4sYLsoR0fMmQ22j/QOk8Qfrm/EQYEXPvQvpr28clD z02uRZuo= X-Gm-Gg: AfdE7clvfcaPq55Cmjj/RgNxdbE11cYixmjo4Gu5cSdgypIs1XWbgvIu9iaXIe2c0k0 IhHB752RU5/JumA4Vpng8MTDBkohVrS1WegiM2GWii/qEp/NgYmo9aBIiSoPWDQt5RwgBqxQwZV d5iXmB4FHxaGJiS3bNTdHVETyULO7XnBXH5GXeT9UeJl+GAl/U6Ob2E1NdZGOGv5GqLJdzwVFmE u0TYr0Vd8aZOvIXkvPcUqtAlAcfhKIqX9arkaS722jtyNd7ns2n75h/GRAgkmjXT9hWSeXslK31 CHljVdU20SMqAdS+9KUlTqFday790CcCD/iPHt66D9/FI5oAszZAGxajSkFptnR4KgkFXWWn9Cs ONipXpXFj0xnAqdJTHeO1VEhE2j1FhP4Y18GmtbYmtrzdccOhAnkYejyUbbB0tUt0/iEyNIqVqy oy7Q37A1lSNGTwcDzZlnsf0EFNauhiMBN5Cq9sciM= X-Received: by 2002:a05:600c:4ecb:b0:492:37b7:607a with SMTP id 5b1f17b1804b1-492608796bemr33705045e9.31.1782291541557; Wed, 24 Jun 2026 01:59:01 -0700 (PDT) Received: from inspiron14p-linux ([109.76.100.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49261063d6esm25128375e9.2.2026.06.24.01.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 01:59:01 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH 02/10] libcamera: egl: Add new helper attachTextureToFBO Date: Wed, 24 Jun 2026 09:58:41 +0100 Message-ID: <20260624085849.873784-3-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260624085849.873784-1-bryan.odonoghue@linaro.org> References: <20260624085849.873784-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. Signed-off-by: Bryan O'Donoghue Reviewed-by: Robert Mader --- 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 f7bfb28d4..4b0757afd 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 f03abb8ae..e83e24606 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 Wed Jun 24 08:58:42 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: 27029 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 7BBF5C3306 for ; Wed, 24 Jun 2026 08:59:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 817E06588D; Wed, 24 Jun 2026 10:59:08 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="OPQzNKFL"; dkim-atps=neutral Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DFD0F65878 for ; Wed, 24 Jun 2026 10:59:02 +0200 (CEST) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-490ac357c55so7053825e9.1 for ; Wed, 24 Jun 2026 01:59:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782291542; x=1782896342; 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=br9Q7T1ldP/TlFZGIutApjjAtcXAdKfOFS9iVRyulvE=; b=OPQzNKFLOnXfz9CO2GH9GE9V+NCgOpp/q9nxBW2M8sFAjhCSl6GP5TNV/Qmy3UB9oP +mLTqenpoNjfSuseInUQZm0+pNviN1lfvvh3zTStpqf5kEt8JoVs+BhNd25g4Dl69vYP UUzO4FI8tGmqroofOprXmDzi2GjEFtRPbONk52b2AyqU1xBSQz6HlpxpLRd66//Ymdul UJAJhoP1nrEMee0y54ciEjKvOMO7AkCuf++K/V4D94FYEimjnSNwxFd2DjcG8M6gvtMX cHyz93nijT5hpiRZukVvGg3EghRE5rJKKy9gNByRd3YhbP7C1ps43PaB4lNvFdYcUbLC VzYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782291542; x=1782896342; 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=br9Q7T1ldP/TlFZGIutApjjAtcXAdKfOFS9iVRyulvE=; b=ep767KvmWEGnx5G+CseN2WUaK2sW35A7Q0IuNQGJIIRjeh8bRq0JMKgT5yH8bQVsPl SQFXooaXHpJfeN1WHW5zkn66sXMMb8nsuaGj5MarFrIZN8w6ild1NU+SUs5d1P1xUhDI /lPZ3WoRI2Q+ON+P6QNtNKYv6eGv7VdC82W4PeSRhHCYNcLuhfwhQFswPmmKKSQhgbhd YhEKFM0CS/1ymnugyIfgOuhhuW4E6t2MjnrMZIFaL7AWn5x40CrOcA3SSDoJVuLzauJg R1uEvvlCeqbYicjQ0SDt7YpqOi6d+Gld7M8tW64rHDvQYYyZq4LhvU78AV5TsPCEQV7J gyxA== X-Gm-Message-State: AOJu0YyvmcUIDMVJsVtRQNRRwRlQ0JVFc6Z3+RWd9Y0YnqrNeTIG8nbE JtRfX7zCScM1zWSzfGhqqFR5Il8ntvcPGgyQH/RMw0MSdCWDBiFkmQ3BppFAb/wHE/y9uzLH5rN suJYu/OQ= X-Gm-Gg: AfdE7clH1eVel6TYhxc7yOMs/gSgqwq+JSMo5dE57Zv1fCTUX4D89Ofapfno0MoZCxg zi2rGxi8G0xkDOrFvmh3HQ/xoP7/trOg5oSZGyvqdWe72XvUVWKF8wShfP5isXZrLsJlag9ViR4 RHY5GSoiARcRF9eo7veewD+zmomvYuxmELw7UzDJhvdeN6S9V/RT+BMybT8VE40SplJd5j0DI+n wqWIG4JaPWmfinsbBSJBCyQu49f1bHIhsnCUSNcFwqVoYb4+kk3RU1RtbRiRK8/sZLqMmzU5BFN Zz6P4JoLhYj0W+Kh9Ih4BOw5ErwtDzKVSO0gLTxVZnMAOUVcQ2BM/+LWZfQsdL7/i0aIfpk23q8 iE6k9K9V0wf3igqdWghRIy2rtC6Wq0pR5QUZZ9FEnGqZsSkLvm30jic93a1V4Z6rOp4MAOdrQ/0 WGyFUA93Yx7vwQ6qEb0unLJ2RtGHTj X-Received: by 2002:a05:600c:8518:b0:490:a298:acf7 with SMTP id 5b1f17b1804b1-4926086d16bmr35890145e9.17.1782291542242; Wed, 24 Jun 2026 01:59:02 -0700 (PDT) Received: from inspiron14p-linux ([109.76.100.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49261063d6esm25128375e9.2.2026.06.24.01.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 01:59:01 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH 03/10] libcamera: egl: Extend eGL::createTexture2D to understand floats Date: Wed, 24 Jun 2026 09:58:42 +0100 Message-ID: <20260624085849.873784-4-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260624085849.873784-1-bryan.odonoghue@linaro.org> References: <20260624085849.873784-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 want to have the option to use floats as an intermediary format between different stages of a multi-pass pipeline. Adding floats means also plumbing the infrastructure to differentiate on data-type on the input to texture creation. Add the floats and the plumbing. Signed-off-by: Bryan O'Donoghue Reviewed-by: Robert Mader --- src/libcamera/egl.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index e83e24606..8d80a6d1a 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -268,13 +268,29 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd) */ void eGL::createTexture2D(eGLImage &eglImage, void *data) { + GLenum format; + GLenum type = GL_UNSIGNED_BYTE; + ASSERT(tid_ == Thread::currentId()); glActiveTexture(eglImage.texture_unit_); glBindTexture(GL_TEXTURE_2D, eglImage.texture_); + switch (eglImage.format_) { + case GL_R16F: + format = GL_RED; + type = GL_HALF_FLOAT; + break; + case GL_RG8: + format = GL_RG; + break; + case GL_LUMINANCE: + format = GL_LUMINANCE; + break; + } + // 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); + glTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, format, type, data); // Nearest filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); From patchwork Wed Jun 24 08:58:43 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: 27030 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 1C690C3306 for ; Wed, 24 Jun 2026 08:59:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EBB226587B; Wed, 24 Jun 2026 10:59:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="eLKUrkqx"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5DEDC65880 for ; Wed, 24 Jun 2026 10:59:03 +0200 (CEST) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4926046fbc5so6661425e9.0 for ; Wed, 24 Jun 2026 01:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782291543; x=1782896343; 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=x3IY0F3UjUxJGXv2KSdGvBjFnMvOa+oW1cFk+rb0RrQ=; b=eLKUrkqxewYZVUwRFvuhQtLJBGdBVuhs8oTFNjABp3peVUCulttA581hiX68ekvNE4 fsQi1djEVhl//Hs1ntN86SPbp9hdj+AT0YuGQYe2o73QUTJxb689PDupI8VswojYodt5 T+ahSXY55sGa4KwKJxNc4C5rc84Y9aUaEISiaAQg5V1l+Qwh1aFn7JkbV+//bE0NGI33 01/LM5qTcHPRB23I7gkDP0XSqVlb/3DpBjHJu5FA6kzSSKPGYdt1LiGe3+Eual4P1ctQ gqhHgm4qbDco+r4Q1Nqpa5kk61MtIWv4T36T1izArDKn6mqhH/xg6RjJdeiLvv4vhPGW 9NGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782291543; x=1782896343; 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=x3IY0F3UjUxJGXv2KSdGvBjFnMvOa+oW1cFk+rb0RrQ=; b=iXehcFrSOmmQin5rVq9fzlM3I6M78Eiky2NVSQ23MO9E0i/E8qSnatoOBU34Rj2es0 Ev7iFWehcglKYOheUqSoN5Yqd632HrEWEa/BPmm+sIgrLFPOJzjhS/zRYA8gUCO/Iz+v 21uaJtmX5wHgsi9JonybwGtZYvdrEzC/RSZ9XCwf/0x1beiZPKYg62uQ+z/EDhlvrht5 aHiONSo5ujHDVxCPek0Xw5T7j5/PCghE7OxgkshzJjJ4uPbJk2Hl5HRF9outboBoC7b3 JHdh/lO9xKMUncXrdse2FAyyv/f3Qq9HJrIkRmhQdtl5tiUbeIihWrgCT+6qw5MEFMxU +sBw== X-Gm-Message-State: AOJu0YwwzKT6mGbFInDd4/Fra5B35FhwXZ2rR2GzOrwdPfEpKc+w39sP nbutMBA9vmgnJVoYm1PVRXZJwQW/N/iGeGSYWQyA0QU8/1aPOjj7+bgogjrQd11X9mILmhhJPw4 8qwoJgtA= X-Gm-Gg: AfdE7clOG2bJD9leIgiOA4H56WTfjiWhp8Af2a9L+W7F3xUtEWJkvbxulpPkkzBwko+ 7x5UAWJhiJaeQ/8YhFQGhMS2x0E3gk8w3SHLwxUHBXV4UZh9j6A+hwj+aaeMDt0YF3r2Yxm5zjs Jw2DObsFl0D7a/m1x38bNPkqELTyG9kxlzpZSxMwfTXc0luNzXrha3aR3nV3UEYTYADbzPnVQ9Q bZEsF2vBFFWp/Cr4f67TxODSfvtoZeot3fXZBqSJg5+XVYOrLlKE0cCkJ9j98lnTQg1sFHtloLI aPNaA5UAjg72Ks9ksOlBgWqCvJnKI4we3BaBWjMSRrnjURmt4cOhMzOZc9GBXHI1UtcxABYULyV ZyjF1GuPQfJsptwC3w0AKYhOrcCHRxN5mXW57vemyaxQp+vj5TxPAXQbx1ueoWQO1xRpv1Tp68c 8akniKHpOMIvXiQNrh0gFeAmr+NnIZ X-Received: by 2002:a05:600c:6692:b0:490:c1cb:48f4 with SMTP id 5b1f17b1804b1-4925a0b5505mr87016355e9.12.1782291542952; Wed, 24 Jun 2026 01:59:02 -0700 (PDT) Received: from inspiron14p-linux ([109.76.100.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49261063d6esm25128375e9.2.2026.06.24.01.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 01:59:02 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH 04/10] libcamera: egl: Rename createTexture2D to createInputTexture2D Date: Wed, 24 Jun 2026 09:58:43 +0100 Message-ID: <20260624085849.873784-5-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260624085849.873784-1-bryan.odonoghue@linaro.org> References: <20260624085849.873784-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" Right now this routine makes a texture from a supplied data-buffer. It should have a more descriptive and accurate name. Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/egl.h | 2 +- src/libcamera/egl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 4b0757afd..0709f9019 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -107,7 +107,7 @@ public: int createInputDMABufTexture2D(eGLImage &eglImage, int fd); int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); - void createTexture2D(eGLImage &eglImage, void *data); + void createInputTexture2D(eGLImage &eglImage, void *data); int attachTextureToFBO(eGLImage &eglImage); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 8d80a6d1a..2825d34d3 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -266,7 +266,7 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd) * is useful for uploading static data like lookup tables or uniform color * matrices to the GPU. */ -void eGL::createTexture2D(eGLImage &eglImage, void *data) +void eGL::createInputTexture2D(eGLImage &eglImage, void *data) { GLenum format; GLenum type = GL_UNSIGNED_BYTE; From patchwork Wed Jun 24 08:58:44 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: 27031 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 C0308C3306 for ; Wed, 24 Jun 2026 08:59:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7754B65890; Wed, 24 Jun 2026 10:59:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ngp6Ewap"; 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 2DCB26588B for ; Wed, 24 Jun 2026 10:59:04 +0200 (CEST) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-490cf322ed0so7762595e9.1 for ; Wed, 24 Jun 2026 01:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782291544; x=1782896344; 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=rvAQEVMSRheyGM8shl7R1Ii/hn68JOYesKLUlq7bdnc=; b=ngp6EwapBGiYmXOHkkFA0kmJ3fg+4idn7+LbBYksXo6KZ1e7PW1rrA1t6HDrJ3pWp9 TG0/UVubh0v7eOz9aLW4i68m7EjR00xd5eSkk6KlOzsIXwCU7KXPoBmCxrtZHbX6m8vP cu4itzwGQnqTvu9eSPYFvp9j5xglA64VjSwIK91sTABTfTJpjD1b/Kbkp78jXp2NzD14 6kRR0CWNMCOQMdM+mbnp8wayWC3hWp+5JvKceA7fs/yZHpcVpj4x2jFsKhogCuAvu0l6 /kctsX00IMgLsQ6JCWnRj0JObJTlaNgnrm2O+6YFdur3a4LcORb2ogQwX0ackfLDm0z/ UgEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782291544; x=1782896344; 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=rvAQEVMSRheyGM8shl7R1Ii/hn68JOYesKLUlq7bdnc=; b=O/Zg2N9qD80kbHbdstYngMrlTSvREnjPOP34SNrggGtzI/PmP/Sr5li7ieD8IC5M3T XJwqYZFq9eP/XasAprPCCAuBxdxLESdXJ2w2MVeCiE/CC+C1suJ9rFxFIfTmzTt9hJoA dW4NvKCl5l7OWwOsK/o1yCm+yLtWznSU/xt209WG6e9bKAxT5WJaZHMYa8eGQ69ABxz4 fQABWgfW6gmKJa1fOnaSJ/OgdF2zoeoKpKolVYEADxPDqja53/+tTP9Y7AWOYrI+te5V 4tsuf1c65neRBu0eI6dcfZY+Cx3ply/I4PHEDasb4bEhlDkxXVetvjGpm65Xi2BOLv9b LtHA== X-Gm-Message-State: AOJu0YyHGWuY2H49J96ByvD+cg6y64nISE9NOSbTyQKZgTI/hekhK4Aw tcqmSdv/Qf5CEbOiLsALLUZli5eyJrtGxRSwohBpHdqelUb33hm7bszEK4rq7H78/9Dymuw26pJ ADPjrZ1k= X-Gm-Gg: AfdE7cnuTByU9cf2kNnf3MplyBZwpHHY3owbQbWoSx2CN9dMYwIl1n1JTpZ3NikinvI 2hL0LJ17SIngearmeuLyOitr/4xXc/srsqQWz1ZPls/5e78n8kkAuMAqaUmKVXZrIX9mLyr22pa UF4fzZcQ8p+MHPXQQPIhsVZjiCFodMbdlMSnvLNK3BZMlERU6kBzQsD4SFF9ETbN+/UvjRmC+c0 cM8fzNG8Wm+4rlkO5DRL+P7ozjuQ6y/CRuG/RRCXdcF7zgazt+H1iMe22xBJNvd6HlJRBuWnV7A cFJxYwdFgb1qbkYrwJ0u8KbpSR0OEe0SNDqVu6uHdroCQVIom1BaXGhPhYN+Cd2gqINaR3Xskby K65oUXPcnvv6kB1POZrbzH4qVZnUQp1UzJLr+EbH5xIsoy/UHBqOrD7WJMyMtx5tZZCVm9vRyGG uU4mmkpEQMCo7dCyAdogWL8ccdHRis X-Received: by 2002:a05:600c:3110:b0:492:51aa:2d46 with SMTP id 5b1f17b1804b1-492608521a0mr29036095e9.13.1782291543628; Wed, 24 Jun 2026 01:59:03 -0700 (PDT) Received: from inspiron14p-linux ([109.76.100.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49261063d6esm25128375e9.2.2026.06.24.01.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 01:59:03 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH 05/10] libcamera: egl: Add createOutputTexture2D Date: Wed, 24 Jun 2026 09:58:44 +0100 Message-ID: <20260624085849.873784-6-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260624085849.873784-1-bryan.odonoghue@linaro.org> References: <20260624085849.873784-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. Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 0709f9019..b992baf25 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 createInputTexture2D(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 2825d34d3..123653b58 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -345,6 +345,22 @@ 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 + * \param[in] format OpenGL internal format (e.g., GL_RGB, GL_RGBA) + * + * Creates a 2D texture in VRAM. The texture + * is configured with nearest filtering and clamp-to-edge wrapping. This + * is useful for uploading static data like lookup tables or uniform color + * matrices to the GPU. + */ +void eGL::createOutputTexture2D(eGLImage &eglImage) +{ + createInputTexture2D(eglImage, NULL); + attachTextureToFBO(eglImage); +} + /** * \brief Initialise the EGL context * From patchwork Wed Jun 24 08:58:45 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: 27032 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 22562C3308 for ; Wed, 24 Jun 2026 08:59:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E4CB26588B; Wed, 24 Jun 2026 10:59:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="IS69L03Z"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D29336587B for ; Wed, 24 Jun 2026 10:59:04 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-490ace40f4bso7840405e9.3 for ; Wed, 24 Jun 2026 01:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782291544; x=1782896344; 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=flfSSfWZJxE4D8DY7Vyt/cuEj4PNcIobfHtmpG3tyRc=; b=IS69L03ZQmXDEUDs19Xt6b5Qq3KENt6XWeagSqXzIe4ZDuduPT6UZBa/P3XpsLI/Af LwtwQCFTQSAZdMApG5UYR55sJPDOBTA04EW452IsRNE5TW5cZarDHZZX5GztOJfaw8EA nkufge060HXnzZlbyUrM73sZ5n8aksm7bF808bhvXl42GK5LANYUTM1eJf4fXcyETLsr 8lC1lLUjQi5UJ00iIeEU/ZPNLf+YY8L53cZ3Ul+qv7OrKSNZPiMwcELuS/CExQ4YT95N maXo+ygr0LRxt5Ezf3d9ZJY/1ceK1SqyizJ5fY6gfOhyMlrWq4XhX2zy2Umx6QENEDHI gcog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782291544; x=1782896344; 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=flfSSfWZJxE4D8DY7Vyt/cuEj4PNcIobfHtmpG3tyRc=; b=apTUoEmpIPXiQABx3jeAsF1YYbNBqDyE3RNPGcAtBHIT26jQghYq0zG53Nwk2DVeD0 CSWG2G/XuRHtfl8/lOgBJG2xNbCtjoL5Obo3j/8346gfLWQxZXn947BG7Ya+x+BojR5C ++xmRrHtC7x1XhDYuDswXExV5LG2Pqx5LdHFN9LyvSLeAblCJ0btaQhqU6+WqxtrmmEe j1LHZmWvnppB12IGoKQ8ZNLejSmONcI4MwjUhNPQ/CGEPNAziAzI3LBSzT7yupa6KP0R lFNTgRmE4iR/7M4cmRpqC+f3uJV1dKKiW9TWm7f7G5ebTUXvu3rZk2se3Ld3XNtUUISu PFOQ== X-Gm-Message-State: AOJu0YzSUflvEz1d7xKUyWU0jZ2h/DB6G+UBZZ5nyD1oODOKcgom9dqu UQevEiiIKtkQ+QapkDZP5P9HNIptjhIKxjNfF86DW+KHO2/17n04j6Gquerc3AK80Ogkqm3uCME Uj+qEaz8= X-Gm-Gg: AfdE7ckmaL6Dhfa+Af0W7e75gSXtnaRKnUy9TSDFoMQ8yS+CkkT5iaBlVxYY0L7nPzp w3pq0jWc/mlYyyaPzB3pi/QK5pU1suv8hhU/nijnY22KgzS5T3WedV6PT1BRoiNSd64WWrCyAop I2ol4LJ9H7nfWKKNXE785ziL7kf1gLdYsmRlaJH2jD3hB6GSP/Nil2wZyOkkk6WkVQQCyycy9WK 7YsPsPDJ3/iuuNJpRRu8MMsQbfnjcoINo0O1GDd26EK4AEK0ySghxGbna/7vm2D2GPCsBLE76Km VF9oIK5NFZSacXcARqEvdtJAAPqiLSUPrqwUARgi/N/6mWpB90ymF7y7txWmOX93HizJz5nHEhc WndwHI6cHTUb8Pf6M2YKaXkNux1aPrlxQASVrWfBmASoA8Rnm2pTOFLuTRLiAxHbHDNXVcfI3Ea STqdWt9EY6PQbO4X/el0n8ui9JwFD1 X-Received: by 2002:a05:600d:8486:20b0:490:3c15:7146 with SMTP id 5b1f17b1804b1-49260872a09mr23749255e9.19.1782291544372; Wed, 24 Jun 2026 01:59:04 -0700 (PDT) Received: from inspiron14p-linux ([109.76.100.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49261063d6esm25128375e9.2.2026.06.24.01.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 01:59:04 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH 06/10] libcamera: egl: Add updateInputTexture2D Date: Wed, 24 Jun 2026 09:58:45 +0100 Message-ID: <20260624085849.873784-7-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260624085849.873784-1-bryan.odonoghue@linaro.org> References: <20260624085849.873784-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. Signed-off-by: Bryan O'Donoghue Reviewed-by: Robert Mader --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 34 ++++++++++++++++++++++ src/libcamera/software_isp/debayer_egl.cpp | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index b992baf25..f1fa75d96 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 createInputTexture2D(eGLImage &eglImage, void *data); + void updateInputTexture2D(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 123653b58..6134b05f9 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -345,6 +345,40 @@ 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::updateInputTexture2D(eGLImage &eglImage, void *data) +{ + GLenum format; + GLenum type = GL_UNSIGNED_BYTE; + + ASSERT(tid_ == Thread::currentId()); + + glActiveTexture(eglImage.texture_unit_); + glBindTexture(GL_TEXTURE_2D, eglImage.texture_); + + switch (eglImage.format_) { + case GL_R16F: + format = GL_RED; + type = GL_HALF_FLOAT; + break; + case GL_RG8: + format = GL_RG; + break; + case GL_LUMINANCE: + format = GL_LUMINANCE; + break; + } + + // Update an already exsiting texture + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, eglImage.width_, eglImage.height_, format, type, 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 diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 0ec2a98cf..cdceacf96 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -536,7 +536,7 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye LOG(Debayer, Error) << "mmap-ing buffer(s) failed"; return -ENODEV; } - egl_.createTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data()); + egl_.createInputTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data()); } /* Generate the output render framebuffer as render to texture */ From patchwork Wed Jun 24 08:58:46 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: 27033 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 23AB5C3306 for ; Wed, 24 Jun 2026 08:59:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C2873658A4; Wed, 24 Jun 2026 10:59:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="xWS2j76z"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E68C65870 for ; Wed, 24 Jun 2026 10:59:05 +0200 (CEST) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4923139e940so4872405e9.3 for ; Wed, 24 Jun 2026 01:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782291545; x=1782896345; 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=NUS4ldqtNiG20r3GBYJr0jvyQGDFpx2Gb3eb+pQy1x8=; b=xWS2j76zCZ99iEqddghkKXki0aFa0sedD8ri0mhhlTFnNLw06juhgrZtpfPUSJQWP+ khpjjoNajbDDIQdliSViIQWmpxvHCmbEl6tapguElBOqJandii0aC23myeFFmA15r6uH wWcirIe/l70hHY/JA1mKbpHB5Fq8rh4l6xTQAuBNAfaUHG5g+UX8Dg/4A0DO1M0YHx9N tR63KrNtIM3BtPhL5kzVqWtDT4vZbLgIbAYoUWXZSZ1YhxqYg2kiC03iwU7gPO+Kvgqi s8yDUc5J33E67arsP7+w+vgiKGJy1vMd0JsjrWdpkjC87/sYKlyC8yZbdx8lal9mB073 WWXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782291545; x=1782896345; 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=NUS4ldqtNiG20r3GBYJr0jvyQGDFpx2Gb3eb+pQy1x8=; b=X1u4rNZN5gI9q4hhYBL81nVh7E6btTlqmZ0pn5wAFAiCM1Tb5CRY3y/+bo76j2sEYs pkDZ/Iq5c6aZoI+IPYjlW4LMQEn0nFbQk5DwXhYZ00BLV9LSSORMJ2RVnlLvsQ7b+Wcj ehHijNPXl/FtA1bk+DSdZdvu/HQulO7tT78j8I3FECMFLGsHIcvUJb8yrgGaaDREOqsB 8iMCa2mWp3khBnmnJhBMt4CzvK1skzsBpa/UHb9/X3RCEri91eaXuxTWiCVsswvaxYZK qOtAG3SLAxjxv2kYZqo8wmHSZv9kSaY7Dj+zCGCQ/hNT088XYeirUyQMkj5wJ7CmwCCb pTkQ== X-Gm-Message-State: AOJu0YyQrYgAhP5EzsUOosvnLzs2u2Sj8TcprV3Zqj4dna4CqFsJfC5x ApI/Fzvqm5dtIsPnS/zrwxc/bdnHIITHAgZE2S9SBgYhfWjVhlsSS04IqIacPbTRbb0TPWxOukj HWIz5Ueo= X-Gm-Gg: AfdE7ck2D9Qrk6dMJSHkM0/bvmSb9YRwi/zGXz9K0auOXFbB7+u1fkWvxXuimkdnt9B TqJmvIR9sPXILbXWNFJ6eP/jYH6rbMbUihji6zH1VEKn67ukLUaTnedCqLdjpsbmm2YxyH3oGP1 NKh70wWOOr3XJbh46T1snRqz0h1q2R699rphwVZPH6qcOc8e1b/y5mKpTf2BOTJL5pZqwIhcejB p5uQoO4qz/PvVpiZyUsvY3XI4Z/0n1fa7zIyfvFT13Pmp66vwd+WRc4h8lz4bcvi9TUs2OpM5db XbXS6mkCk96sP120n8vnpwI58MoWwHol/Jr2xqmsR/l4fnHYCGKTYIF1KXuGk58VpMLVeZ4xkkz sQUdrW90Bradn0L7lAukssWrKtVnKvAYbjDI3wWISweWFNaw3YDYtMbhBTvKsQkcIbWEF7KcHfI /8Axo2L6EVJj2BRpsu1LeZgTfyH/tI X-Received: by 2002:a05:600c:3e88:b0:489:5022:39a4 with SMTP id 5b1f17b1804b1-4925b3532ffmr95245295e9.9.1782291545074; Wed, 24 Jun 2026 01:59:05 -0700 (PDT) Received: from inspiron14p-linux ([109.76.100.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49261063d6esm25128375e9.2.2026.06.24.01.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 01:59:04 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH 07/10] libcamera: egl: Add activateBindTexture Date: Wed, 24 Jun 2026 09:58:46 +0100 Message-ID: <20260624085849.873784-8-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260624085849.873784-1-bryan.odonoghue@linaro.org> References: <20260624085849.873784-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. Signed-off-by: Bryan O'Donoghue Reviewed-by: Robert Mader --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index f1fa75d96..59fd52749 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 6134b05f9..f26fe2e53 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -138,6 +138,13 @@ int eGL::attachTextureToFBO(eGLImage &eglImage) return ret; } +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 +204,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); @@ -273,8 +278,7 @@ void eGL::createInputTexture2D(eGLImage &eglImage, void *data) ASSERT(tid_ == Thread::currentId()); - glActiveTexture(eglImage.texture_unit_); - glBindTexture(GL_TEXTURE_2D, eglImage.texture_); + activateBindTexture(eglImage); switch (eglImage.format_) { case GL_R16F: From patchwork Wed Jun 24 08:58:47 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: 27034 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 0ACD2C3308 for ; Wed, 24 Jun 2026 08:59:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AB16D658A6; Wed, 24 Jun 2026 10:59:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="vpSEMMCB"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5EDE365881 for ; Wed, 24 Jun 2026 10:59:06 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-49258ac7294so5342045e9.0 for ; Wed, 24 Jun 2026 01:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782291546; x=1782896346; 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=nRwCPeGqJXiXkiIP/SKGTBYoNGqKiysO7kBIfJxUMRk=; b=vpSEMMCBMr6HXaY+g33V7PF5PDeULohpEDuurDh96uEyRlb1FDijlNhmbP/kZYFs+L Yi84o2hCI2M2Oz6MOoy7RfXcPwQ3XMf4N6G50g3+bl3xXHIihFOiZfzD+x8uNvPwYqA8 9bOm42BXkXxs7I+ZW248zxZoU53E9zCARPnhJq7MhHF6FC18ugHIDx6Lr5yz2AT6HBv8 h7gbLVk6AM3NG98pB3RAhcizZ+JAURCDGFbcHeNCbBUfLRNR1r1miBI3FOD3CNVB1MYm 8oUYzRtMyAIL/encVL+ObcvYND+5GWCAdPiPff3GfBBT9E881cqnt7Qz1dxqwGp3MWCj H3OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782291546; x=1782896346; 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=nRwCPeGqJXiXkiIP/SKGTBYoNGqKiysO7kBIfJxUMRk=; b=I2fDzgEtLlSPp8SkSSjzn0acrH79XvT1iaZUEz8hfgm38f55/qpSWbpT7Djp4qG2VM od1BcfUO3e1eMCDZBnf2YFToyCYP3TZ/DRYtG7984N4qTjM7PcnGYkfHKpbRuy5rhwrE YOo1RaaYh7rfiyBVlGjCXTsFURyegTL/hMhKAOXGFFDyxlhZ1LJgvHZYGlnlzBFLmRPs 9sZY9NietQeL1H4rbPtvCkxf+0wHZQVZuddyvt7g9iqmDzPh2HnT+bWU95fR9H++Ilu2 LTIrSCOq3LiQFhF+0MuP3Z4FQWZ7HMK74j9LulM7DlO7Hwsag7S45gHPCM7zhocHff1j Qptg== X-Gm-Message-State: AOJu0Yw4zEhWNblmJTPSpYYezBHZV/dWlMN/HFAvp+szHkF0UrF6IW0n zNEWKT5fwkb0LTK9R/eKhBLQ+jsHPe45KaYSWy42dnMxWPXSGrsQEQScidh1K1M/6zBizydCxys yWd2zwoQ= X-Gm-Gg: AfdE7cmD61pIFhfuo6xUHvH26Kx5OpjKNg1xTYer2EuAJpzUEuJzQLpZQe1u1KT8Q+u aLfPuc+B7Up319CoGdx52vT8rpeKHbo4UnICW/MPxK/kMldo9KNbxhlia6jBtZYQC5C2W6nymEJ xKBjxLfw3ubdLrjDDymrwIS0mdsItud2dck8UbnER+/Ahg7gi1YOw9HbbPkHLfaTqkLGFB+wq0M AMz0TweaeR/j/GIO50oz+JRiarJzn2c2U88s7iYtGOnJHRuZ22B3VBqcqp3G5WKeE5jl9miziuc h8jzj57ZBVPBfOF91tjYgR+mrwoflEXutOEosfD0llXE7uMzSoLGNIVaNgI6UEu4I9xzhrydg40 95E+N1nNw43xekHDhhriFndOCcqNV+WwVE6wllAEYDc6EuO178/E0mwt+wa4tpB/blRhZ3fbC9E CVswh2ni/J5QUTm1iTMBHKb51ZBlMYc1cqeFE4kpA= X-Received: by 2002:a05:600c:3f07:b0:490:c024:2eba with SMTP id 5b1f17b1804b1-49260872b71mr31522885e9.22.1782291545875; Wed, 24 Jun 2026 01:59:05 -0700 (PDT) Received: from inspiron14p-linux ([109.76.100.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49261063d6esm25128375e9.2.2026.06.24.01.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 01:59:05 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH 08/10] libcamera: software_isp: debayer_egl: Pass eglImage as parameter to setShaderVariables Date: Wed, 24 Jun 2026 09:58:47 +0100 Message-ID: <20260624085849.873784-9-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260624085849.873784-1-bryan.odonoghue@linaro.org> References: <20260624085849.873784-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. Signed-off-by: Bryan O'Donoghue Reviewed-by: Robert Mader --- 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 cdceacf96..f6b7b11e1 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -397,7 +397,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 @@ -453,7 +453,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: @@ -542,7 +542,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 Wed Jun 24 08:58:48 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: 27035 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 24CC5C3306 for ; Wed, 24 Jun 2026 08:59:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CDAD065881; Wed, 24 Jun 2026 10:59:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="KXl0itHz"; 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 1FA5E6588E for ; Wed, 24 Jun 2026 10:59:07 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-490c0c92cffso5300535e9.2 for ; Wed, 24 Jun 2026 01:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782291547; x=1782896347; 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=2bIZGrUQwPgXcjdXPjamqzwXBECgXjVAW95gyrhVmes=; b=KXl0itHzw+rjGwLg81Y/8UfoM5OiPf8dPAGqpKWavfJiVAHOXQRel4WGGooPDid6xw 2i4uJ4PNaf+XYAY3748U7GM3KMFhMQTjQcpFUdcvfcBh4XNTXbtgeUYZWE/LnBJRSdwO 2ImbXmLYEtDv1G3jskaB7bbvAKxgsiY1Xsgwh8ObsCp+zRvaoTD6wZgK/sByC9yAutVt FxXQ6fb63cfzogKh4b9poKTPwZ4ya0e8M5jWWmpNN3zY8GQXGOX/QyMYpPogiJn0e/Tk Jo2WnUG7L2uU8Gctp11AFx/Bm3S9S70+MxCTX1cG/t4x0ZWns5csA6n5sf8rnJ0UXeEG V0kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782291547; x=1782896347; 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=2bIZGrUQwPgXcjdXPjamqzwXBECgXjVAW95gyrhVmes=; b=mETINXcuxptrwXBhl4kZI/ooyUx23bgeAVSTvg1TYAmLELGxRsKdKa8JRbGzqNwzJd +I9Kx9VlbcDvbTPLvmNAgr7PY7Z51su4dutfdwLh396EoEMXgTG5RazUDwjTz6X0N8st yihWlK+wR6BZVBYwwOZO8MBJcS0VUn/KhhfE6+0Yz0B1Op8jyrsInPJaDR3ORwlXoRfl K3tWSt3USHZztQ/aZUh1cNaJ9QQ9mwpH3Dh/FUFffw0YE+k2dgMes9pbxAdzTaXmJr/y jX0q2fXFraD1l4DzANuy3dQ17Km0PSZwbgBnhZNnCCMR100iMNY5YWG0Wn95/jgxtv/1 uI8w== X-Gm-Message-State: AOJu0YxaQt2T1zykUNl+DwkBQgSygyxC6FnQJfco2nXJzNBMzrDYym8R Sm6XMb5c0Xvmh5S0G7r3qKLwS99FF2JFTPNxoE9nRMwdMzyLXktFpSfbbbfw4bmwFPLigp4dJvp E4wpwCMU= X-Gm-Gg: AfdE7cl3TV99NbKvWYxQNu8w7yrY59/OgCnM+Eu1KS4Wddo5SGRqTvLCDWmSmWKxjI3 BgtOgFXB9gfhXp6g6upgsyayZnUfmMurhPJOKu30VWKZIINW/Z8Dk0kImz0pG3lD3J2rQjCiX5+ CkldsdXa13kKvgpeMGdQJFHNaURb6jgS/mGjhulR8d6emdyYGAUR2uavbM+la9S3FB9DXFVSEMP 15F1gWf3asJyO/PaRHb5Rxh918mUCok7SJtAhnOM+obWWfg9dA1np2MxHjXPA9FggtedzvQDV8a V4kg39BkwQCZRsyrYpKotc5ttgCpficG9IkAmzlLJWlVKG3kDbQida07CMuPJz6oKz8S79OL8N2 403jBv3AgFA8LajWGPDsoByGu5ck6SNz5xhFn8ar36U0Yr3JpZShLvO7Dyx85JRohCBwDzN8wAb pfLDUn90ieRIV1ozhnCgYdVWF6mSea X-Received: by 2002:a05:600c:4443:b0:491:8043:5c4a with SMTP id 5b1f17b1804b1-49260879105mr30625795e9.31.1782291546594; Wed, 24 Jun 2026 01:59:06 -0700 (PDT) Received: from inspiron14p-linux ([109.76.100.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49261063d6esm25128375e9.2.2026.06.24.01.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 01:59:06 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH 09/10] libcamera: software_isp: debayer_egl: Flag dmabuf use once per session not for every frame Date: Wed, 24 Jun 2026 09:58:48 +0100 Message-ID: <20260624085849.873784-10-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260624085849.873784-1-bryan.odonoghue@linaro.org> References: <20260624085849.873784-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" Once we get as far a streaming if we have one dmabuf import failure, take that failure as canonical and do not try further imports. Add a flag to debayer_egl which gets reset on any configure() to control this logic, flip the dmabuf bit on the first failure for all subsequent frames. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/debayer_egl.cpp | 13 ++++++------- src/libcamera/software_isp/debayer_egl.h | 2 ++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index f6b7b11e1..0568c413b 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -316,6 +316,7 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, inputPixelFormat_ = inputCfg.pixelFormat; width_ = inputCfg.size.width; height_ = inputCfg.size.height; + use_dmabuf_ = true; if (outputCfgs.size() != 1) { LOG(Debayer, Error) @@ -515,21 +516,19 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, 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 + if (use_dmabuf_) { + if (egl_.createInputDMABufTexture2D(*eglImageBayerIn_, input->planes()[0].fd.get()) != 0) { + use_dmabuf_ = false; LOG(Debayer, Info) << "Importing input buffer with DMABuf import failed, falling back to upload"; + } } /* 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()) { diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index 348d7305b..d8509e9f2 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -68,6 +68,8 @@ private: void setShaderVariableValues(eGLImage &eGLImageIn, const DebayerParams ¶ms); int debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *mappedInputBuffer, std::optional *inputBufferDmaSyncer); + bool use_dmabuf_; + /* Shader program identifiers */ GLuint vertexShaderId_ = 0; GLuint fragmentShaderId_ = 0; From patchwork Wed Jun 24 08:58:49 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: 27036 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 EE8B4C3308 for ; Wed, 24 Jun 2026 08:59:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 79F4C65895; Wed, 24 Jun 2026 10:59:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="jGh1QZqe"; 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 8BBC265891 for ; Wed, 24 Jun 2026 10:59:08 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4924593f45dso8073385e9.1 for ; Wed, 24 Jun 2026 01:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782291548; x=1782896348; 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=LvpHhq7SDZeODR/gVrmxjhKv6G3W7LqpHWaMD33/8yc=; b=jGh1QZqe0JkL8Bn4+Xlq1G/PlJi+XewVawIdb3Rq/1OM51XLJN0Z1BDmJY1D+6sgBa +AKLAwYNKFBvc9yZL6M6wEqLf+FSh9uqCzy0boiPT1KZbL+rH9ndgyYd+HIRIbsgoPpC mX4mteY9QeCB5ZHtMFIDsPvq9WG2tndDEflPGYgO1Upfgmf1eRWUezunkIPA/+ZpTtqY sVa3uUpyk9sxRjQdsHJs/rBiTiTQ32IPaHH+mcP5i/O7cMKPYWV8w4WVYT2uZXshvUkL /0aKvPuI0Pu6Ad9tUHclB3/WUGavhRxIw2/RAegQkIS0UfxYPeKMbhoFWwIA7/iZLAX1 6qEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782291548; x=1782896348; 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=LvpHhq7SDZeODR/gVrmxjhKv6G3W7LqpHWaMD33/8yc=; b=A05gQToU1ecLr+3q+hj8Xt+Wd9wAZHc4x7chdkPdm7Co/HIRr2KzQtnjyLt2zZrSiU 9aKsR7dXzeN9yRRCUuQ7YsgxKMaBguWmWyBSp/G70WviUBFLzaq/VXNOlfT8PxKNIQgk BnSaTlSzZdhajY7vNk6evA59GHdnosSOJp1NKyktPZzbYFjGWw3yRuzRPnpJlHumt8Qv 5GLu0MODOkxwJ5la2g+qpaUSt61c1HC+ji7XJ/i61zn6QaqnyGxrkOXdae2HBrMc2umC 241820C4y6G8tgIwHm1ai6SLHdeVMRi6GA2DmoAhHooIQD4nLeEQi1ppwKF7BucxrWXs XfZQ== X-Gm-Message-State: AOJu0YwXtVIeaitRPO1qX2fvZTPL9VCD7Umm40fDhXewmgswNQYVHP14 u9aIbMeIWvC87q/uBC3JMOW4ykPDKJn8eFR/XtDDDvLPc+gCTHgs0E4ZS+aukaFhs9/pF0LgJ8t xCGOwusw= X-Gm-Gg: AfdE7cmOSP+WslFDzqAijgZiaBlT+7jfs56F0vJvAPz27a2nhRc9tr2AcXKMBDqYMlT 1AETPwR0hAaeTm6li0lc1kw3Sajq8xYEY47vHk6R7ZABJl8v7WoVyjWsRzdxHmv4S5pdxBA+kaz tKbgD9CJkc5/ox6kIfoVbPn2R2g+qSmXVyvAJW0NPTlBOjMPP9XNkZfx1+o4jKtFvqFjwqFb18H N23s291AApPw/aOfTd9/CfyGiVjZWkq0/uhaNeZvOBq+Xbwr0SRmh85Ixt7XJolutlgyq8O+ROG HPRDIQN6r/zALRakV99XNClfAGWuPzay2m0wJCvf2HnT7xC/oIpzrtl9eylsXEqlJvqXcfgIhfq avjamXXoss1knZws1WYcQOsnq9ZJPrV4BTL0xdPgVjaQiTvORLSR7Mk8xLx8VAio4rhEa84+D7u pr9GKbwdeflpH4Zfqm7xIAD76whRon X-Received: by 2002:a05:600c:a012:b0:492:2e1c:1d19 with SMTP id 5b1f17b1804b1-49260875bbamr32747295e9.31.1782291547966; Wed, 24 Jun 2026 01:59:07 -0700 (PDT) Received: from inspiron14p-linux ([109.76.100.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49261063d6esm25128375e9.2.2026.06.24.01.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 01:59:06 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH 10/10] libcamera: software_isp: debayer_egl: Implement input/output frame caching mechanism Date: Wed, 24 Jun 2026 09:58:49 +0100 Message-ID: <20260624085849.873784-11-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260624085849.873784-1-bryan.odonoghue@linaro.org> References: <20260624085849.873784-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 Tested-by: Robert Mader Reviewed-by: Robert Mader --- src/libcamera/software_isp/debayer_egl.cpp | 108 +++++++++++++++++---- src/libcamera/software_isp/debayer_egl.h | 12 ++- 2 files changed, 100 insertions(+), 20 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 0568c413b..8ac5cb76f 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -355,6 +355,12 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, */ stats_->setWindow(Rectangle(window_.size())); + inputBufferCache_ = std::make_unique(inputCfg.bufferCount); + outputBufferCache_ = std::make_unique(outputCfg.bufferCount); + + eglImageBayerIn_.resize(inputCfg.bufferCount); + eglImageBayerOut_.resize(outputCfg.bufferCount); + return 0; } @@ -514,34 +520,106 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara return; } -int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *inMapped, std::optional *inDmaSyncer) +int DebayerEGL::getBufferCache(V4L2BufferCache &cache, FrameBuffer *framebuffer, bool &cache_hit) { - /* eGL context switch */ - egl_.makeCurrent(); + int cache_idx; + + cache_idx = cache.get(*framebuffer, cache_hit); + if (cache_idx < 0) { + LOG(Debayer, Error) << "buffer exceeds configured cache size"; + return -ENODEV; + } + cache.put(cache_idx); + + return cache_idx; +} + +eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer) +{ + eGLImage *eglImageIn; + bool cache_hit; + int cache_idx; + + cache_idx = getBufferCache(*inputBufferCache_, input, cache_hit); + if (cache_idx < 0) + return nullptr; + + if (!cache_hit) { + eglImageBayerIn_[cache_idx] = std::make_unique(glFormat_, inputConfig_.stride / bytesPerPixel_, + height_, inputConfig_.stride, GL_TEXTURE0, 0); + } + + eglImageIn = eglImageBayerIn_[cache_idx].get(); /* Try to create texture for input buffer via dmabuf import */ - if (use_dmabuf_) { - if (egl_.createInputDMABufTexture2D(*eglImageBayerIn_, input->planes()[0].fd.get()) != 0) { + if (use_dmabuf_ && !cache_hit) { + if (egl_.createInputDMABufTexture2D(*eglImageIn, input->planes()[0].fd.get()) != 0) { use_dmabuf_ = false; LOG(Debayer, Info) << "Importing input buffer with DMABuf import failed, falling back to upload"; } } + /* Cache hit using dmabuf activate and bind */ + if (use_dmabuf_ && cache_hit) { + egl_.activateBindTexture(*eglImageIn); + } + /* Otherwise create texture for input buffer via upload from CPU */ 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; + return nullptr; } - egl_.createInputTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data()); + if (cache_hit) + egl_.updateInputTexture2D(*eglImageIn, inMapped->value().planes()[0].data()); + else + egl_.createInputTexture2D(*eglImageIn, inMapped->value().planes()[0].data()); } - /* Generate the output render framebuffer as render to texture */ - egl_.createOutputDMABufTexture2D(*eglImageBayerOut_, output->planes()[0].fd.get()); + return eglImageIn; +} + +eGLImage *DebayerEGL::getCachedOutputFrameBuffer(FrameBuffer *output) +{ + eGLImage *eglImageOut; + bool cache_hit; + int cache_idx; + + cache_idx = getBufferCache(*outputBufferCache_, output, cache_hit); + if (cache_idx < 0) + return nullptr; + + if (!cache_hit) { + eglImageBayerOut_[cache_idx] = std::make_unique(GL_RGBA, outputSize_.width, + outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); + egl_.createOutputDMABufTexture2D(*eglImageBayerOut_[cache_idx], output->planes()[0].fd.get()); + } + eglImageOut = eglImageBayerOut_[cache_idx].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(); + + 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); @@ -623,19 +701,13 @@ 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(); if (programId_) glDeleteProgram(programId_); diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index d8509e9f2..238fe7345 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -22,6 +22,7 @@ #include "libcamera/internal/mapped_framebuffer.h" #include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/software_isp/swstats_cpu.h" +#include "libcamera/internal/v4l2_videodevice.h" #include #include @@ -70,14 +71,21 @@ private: bool use_dmabuf_; + int getBufferCache(V4L2BufferCache &buffercache, FrameBuffer *framebuffer, bool &hit); + eGLImage *getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer); + eGLImage *getCachedOutputFrameBuffer(FrameBuffer *output); + + std::unique_ptr inputBufferCache_; + std::unique_ptr outputBufferCache_; + /* 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::vector> eglImageBayerIn_; + std::vector> eglImageBayerOut_; /* Shader parameters */ float firstRed_x_;