From patchwork Mon Jul 6 11:38:57 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: 27249 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 D6D73C330A for ; Mon, 6 Jul 2026 11:39:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E98F46603F; Mon, 6 Jul 2026 13:39:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="L+GzB1UQ"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DEC7D6603F for ; Mon, 6 Jul 2026 13:39:14 +0200 (CEST) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-47c2b362ee2so1523492f8f.1 for ; Mon, 06 Jul 2026 04:39:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783337954; x=1783942754; 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=hvwKB7CQKp8AngpWiJmPSQs7XuQyPTLQJEhfb8AHvCw=; b=L+GzB1UQQJTZ5JGTTxcJdkvlHigwtwFH0tGZkoMaie/fg46FJ6xFyCfEKie/j08pfQ IWGit+zNsaFsukEOdYn+C994nljaS/D/jiOv+SwRHcs1qBt/W3cAj/NS83qnaKLGm9ho IhiVI3FLeu2B/jkVagipvYTm5a/jSd1WepecoqsomSFcFM/+xOAQEihV/i+XCyi0zQPg 3bYy7ywaePfAz9HEdnJ9t5qbQ3sYkawe4eAbX5JxxcXei0b+RyviPYCgcMzq7wiMqwoX /sIugagh4BXHSqtSPG3rl86DWMhXPOLdanXEu8vDMWINFoQ0Zw26xppa3Z7eULFXaw6I E36w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783337954; x=1783942754; 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=hvwKB7CQKp8AngpWiJmPSQs7XuQyPTLQJEhfb8AHvCw=; b=Vi2zOn3gJAQ7ZkzdYIPseUEDQg3eEmBpJ6tgYhPTFU+3SsxbOiq30x/NL7SEfQ5L7L l5cjp9F2WpkStgymoP+D/EjF9+I77ch8jAWExgIEBYuEdGFzK0t9njwlzMKsOiHBdxVK pgVg104Zb2Xto3cBZe6AfpVamrwl81A85hfK5nimg1ukQKljGwWdjLUWTkPgp9VNgsrA Ox6JOCU5nI0YYyO29rzceTth+6Pohxh7ZVrNi71UFcyxpjOsahDXWc/3Y9aRrJFqCw+2 WgJm3sEQAfF7GN7g3zQXiUPNqHQ5fk0fVgCuqE3iB0JxEvi0msgBVyeckdIx+UJ9yBFk fcLA== X-Gm-Message-State: AOJu0YxdJEvfmE2TUAs8XegmnytvUenyRAc/GOvM7/mJnua+hfLLpGMn YgEx5lKmc+mjFxJcJHx+L72RAErTvPUeeJZxxmqRvZ616xASJV9cNb7K7j8KaO+LokLwY4+b5gS RgUlw X-Gm-Gg: AfdE7cmRNZJk8d4Y9I9XQy/IZCEVGpPiQ5xlCyZUxOSLig4HxhyfVILIk4TaYChmTe4 64fWPK0XQvDU9QAOeV9x1F38i5AStYMH7j83ZtAc+zV2OhW/bdpYfO6e3UZ/Yf3bMyrTdcqtnfb sCQfUntvTGqBmCMxscVlBoURc3lqzQfsbR5yvZFek1iU0JA1PHtSR2QBXLbRdaT4xsyLdaSE6yq rI/osCdfF3jCFaPrOXbcvIkGYLfLHOEauVb0hiXRyQAXqz7xBO7mXSEBTxkog4+Ay2YqhsjB/Ja 6w9XsCm38FlE03nI41sKrBOKZ6iBNxliNGi8aRcPOqTQdrHp9cOoz0Qfv5ScTF+E6NYHlb+rfgr mm1Bv3/+5bjJXoYC5XmerctFpwquJx957jnY8jdmAL6/9WTR4geLaYL89GB1+xLe4iAZPzS2R5a 0jxRGtpBs6Gr3LxB4VbGOx8zYCHLMA X-Received: by 2002:a05:6000:24c9:b0:475:f0c2:75a9 with SMTP id ffacd0b85a97d-47aad07bbfdmr12385017f8f.58.1783337954308; Mon, 06 Jul 2026 04:39:14 -0700 (PDT) Received: from inspiron14p-linux ([109.77.44.220]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47a9de1e6ccsm24796084f8f.5.2026.07.06.04.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:39:13 -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 v5 4/7] libcamera: egl: Add activateBindTexture Date: Mon, 6 Jul 2026 12:38:57 +0100 Message-ID: <20260706113900.2530549-5-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260706113900.2530549-1-bryan.odonoghue@linaro.org> References: <20260706113900.2530549-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 1955d09c5..64196213a 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -111,6 +111,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 c1b5514b6..0726b63f2 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);