From patchwork Fri Jun 26 11:33:23 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: 27053 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 BA038C3305 for ; Fri, 26 Jun 2026 11:33:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2462B65EE7; Fri, 26 Jun 2026 13:33:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Bcl1K1kQ"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9939965ED9 for ; Fri, 26 Jun 2026 13:33:44 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-491609cdd8fso5636225e9.2 for ; Fri, 26 Jun 2026 04:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782473624; x=1783078424; 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=2KTYsvtLCYMoZAZ84aLQ+1jc+QNVClAOTdv+yBbXJ0w=; b=Bcl1K1kQJkJvtqJOgMebG2wn/SM+C5Xp5aw6WH1nfPS+yoXkPMRNlMtpS4s8jJPbRJ lh9uXVU9WByRdmhE37f1wMsEhwZ7RQz9GvlsEDdP4QENtVibtcpdhVF/0L4rroyJXtN+ re2cPUNGk+5PbrsAZ6zEHTcgzRmwK/KZoP1yePIgoyFHZzMD4iCVLqU3PvL3HE5Gp3nB KOB5Vx2k03q51xcMAYDDIRublzyO/Kl/exFAUVtd+urZbUye+gfvAN0tQhitGWWW6ZvZ M7sOQc83em2zL4jwA3LfubvC4u9yD2YZriDw5mQRHGGlwrpNxEUpkGmB7Jfq8TqVIvdi anuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473624; x=1783078424; 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=2KTYsvtLCYMoZAZ84aLQ+1jc+QNVClAOTdv+yBbXJ0w=; b=UJHSfFfTM06zT9Q72wlHuTCSjlhWR7qxV3B61ovn8L8RXa3Le/LzVF2t3mDtb3Xtmw VfP++hIoDJAkD33NcFRNzKXfo36LAgaH5NG/IceL+U3KLWEA/yEpg0dUq5u3zOWApQAQ LDdISTPsnf614FWIFd5tVSQWUWpV1lGMXirSGyw/j4wDa06Lnihw2aS1sMf4JDvfFWnY xH2Z4h4KYDUMUMgSy2Sntn2L11gISbMPxWy2DjRTvYBKQDETTHzqNF/b8ivnvREwhOh3 1ZUVwihti6rdumkOBsXvIWHUib1ji1XGqbhh2h2oEBcKjBn4O7hX2GxgIhX4NAhgGrBa mQbg== X-Gm-Message-State: AOJu0YwjMJHpn0UmlCvp1/Rfr3D++VVNS9ukOWlhs8yg3lI7/g4AQHYf cbG74W5sxyCqr98bQZP0CoXKF80QYYUZTh3Jt4VEFP6K4obJtBWwawe7YyZHz93MQlfLRfWcjTG pUu7xilQ= X-Gm-Gg: AfdE7cnGAvUXi8/6wAD8htV0vV6BQQthLJapz6m+JM6rTOy8Snot0EG7eDICSThcL2E fzslk43UqVEDpsZW9QnOjEhTOKJ5q67zVDKkac5giCWXMUi0qIHVuL2SgaazjAeC2Iu6kEoxd9f LXB1i8yAUrfvo8fjc2qwTWInWHDuQ0SnBjSbsPwOek66YKVH5DWw8y/H+6l2B0x+WuVRqk9B1wv sNlxHTSE6PsuFD/+TXcGZI/x0n9ezGPmyeGVgwM4XNe6dT5Y/7zMLge8QCX76DyhRUNhi0e/Brk Tx1LsoqKPcu2QZk0C0LKcTVP0gHJb8OGo9riUG00IyGtDN9fOypq40kQYqTjznjSVlQMaYjjcjP mOSYWGFFzLunH2rMvsWnhDTszpaDHsXV60o/VqDyHHwT6HlnMhQoQQuZuKRT7eLLa1XAY4/VOtF ncMIo3xN7ZrUmYgNEzmYCfkONbzA== X-Received: by 2002:a05:600c:3e0d:b0:492:4723:166b with SMTP id 5b1f17b1804b1-49266873f80mr91322505e9.13.1782473624138; Fri, 26 Jun 2026 04:33:44 -0700 (PDT) Received: from inspiron14p-linux ([109.76.78.98]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49268fe31b0sm79265985e9.4.2026.06.26.04.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:33:43 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz, Robert Mader Subject: [PATCH v3 6/8] libcamera: egl: Add activateBindTexture Date: Fri, 26 Jun 2026 12:33:23 +0100 Message-ID: <20260626113325.3218045-7-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260626113325.3218045-1-bryan.odonoghue@linaro.org> References: <20260626113325.3218045-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 Signed-off-by: Bryan O'Donoghue Reviewed-by: Milan Zamazal --- 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 9b679332c..e4d366abd 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 22f46e92a..4eabddcc7 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 thought + * 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);