From patchwork Mon Jul 6 22:22: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: 27257 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 A4B60C3308 for ; Mon, 6 Jul 2026 22:23:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D66DA6606D; Tue, 7 Jul 2026 00:23:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="w9MAXx16"; dkim-atps=neutral Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B68B466054 for ; Tue, 7 Jul 2026 00:23:01 +0200 (CEST) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-45fd464d51fso1814869f8f.3 for ; Mon, 06 Jul 2026 15:23:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783376581; x=1783981381; 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=hvwKB7CQKp8AngpWiJmPSQs7XuQyPTLQJEhfb8AHvCw=; b=w9MAXx16IUTiD3cUdtk0UUyoc6qo9MMydvOOx72mxckmBNrfppvLn/KOuwu12BLCgd EnP+v8hTh7WuwWV1/+4mFX9yUiVs0vwmrycsBYi6Eb5NwEzTctqiZLW15TTfGL4fctbs Byeech4BU07nh2oQi2kGwscTBZr2qXsGZPhtW7rfQcmjrCYncyiTS/eTYh9nscVR77ql ZwevjzRLoZjN7IS0xdETJAtPjeZkwLh2vH7aAmyxnyLMYXJYeCI92A/sYJPw2XEHRJyw mMBvscmNSWcPMwAAgqfNfsdNm5+MV1cCmvhpwHuKBfESN0HtMRcCHWOzN5Ooa3Vs7n5/ +frQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783376581; x=1783981381; 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=hvwKB7CQKp8AngpWiJmPSQs7XuQyPTLQJEhfb8AHvCw=; b=mSnkQhOOFxlMOEzMpKsLyfwBkaiGVpS5r03L7Xr5FOdA+EgQd6NPH+L10OH0bqOJJi KwF9u7wNgJ0s/lTf3q1gYy5aA9Dcl8Gq54P+W+YFuQ1BaOiFiLWsDYSFewk2T3tc1+Hh mprRmaGB9vjlGY3A7f2pp+U9sQ7kPibGlv1neMywb+XjCf9ZxivbAngmBFDY4KHbCrM2 lqL/6AOxotqMr30U78e0pxCESlydFwY/MRnpv2CBztETo9LBwN8VQGJRLlWh6hb4fiyB 4MLU/CaT0b/UxY5kxtTHGNnxSPcwjDWoJqRv6ToH1hXa5VvFSlmOoxhnXkyXbRI/4olx R2gw== X-Gm-Message-State: AOJu0YyLYAUqeBI49A7imub2/SY8snH7+b3emkyoZ+yVGKGXEBkWxNFY wzvcbWhVrOF2VB/Eo+1BHjvzof9ABRT6e8V97dPetkLS9oo62TrHVTFasES62rjPDoT+WAFRrBD h8KN5 X-Gm-Gg: AfdE7cm/IEiBk32lve+NPdhIwLs3bv+WiLgWgZDV4HMUsNxaT61K/1TnBBammnvIEzf 3LRdnFTxG4baB2nzMbDwRXJgclc+zKoSclz7QVHzZBVuTtLwxwMpt8E2AKxSfXnG9rJRz1GXQDb pZWvLcjycD0rhgoQho8Ft7sZgWMWjCjFzxaYW1ogtqgkYUKVLwDe3d74/SbiT/wNlePoDXH4mbs a6QzFT6Wfo3oObaqmKAxpK1YLlzx62ZXV6huygynhE11MhRSMLL8ehQLWLRA39yWP3kBGWCETON akJsd2O9sm4DvU7s56Gj8ZzPrzYFNmQahIGB73pldEAf4fJEj3AxRTRJydHNH0lYnvv/2IDXnuV 6nK8CrfPQdL05mWC7wQRLB546q2QVQtRONjQ1Fqsyvmhal8a2duzUJXgNRAIkMPVgUtaKobev9d j3gOKnKu/FEN2MxsGb4NbmyNH2VDPI0ECwNeQrqV4= X-Received: by 2002:a5d:4ecd:0:b0:46f:7d90:8125 with SMTP id ffacd0b85a97d-47de665b2ecmr1530441f8f.15.1783376581282; Mon, 06 Jul 2026 15:23:01 -0700 (PDT) Received: from inspiron14p-linux ([109.77.44.220]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa039ad21sm27916413f8f.20.2026.07.06.15.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 15:23:00 -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 v6 4/6] libcamera: egl: Add activateBindTexture Date: Mon, 6 Jul 2026 23:22:43 +0100 Message-ID: <20260706222245.247396-5-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260706222245.247396-1-bryan.odonoghue@linaro.org> References: <20260706222245.247396-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);