From patchwork Mon Jul 6 11:01:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 27242 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 445D1C330A for ; Mon, 6 Jul 2026 11:01:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0EF9666017; Mon, 6 Jul 2026 13:01:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="rfOlRj/e"; dkim-atps=neutral Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E7BD56602D for ; Mon, 6 Jul 2026 13:01:35 +0200 (CEST) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-474303f3c72so1680808f8f.0 for ; Mon, 06 Jul 2026 04:01:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783335695; x=1783940495; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fVHnbZZMdwqZk7BriO9P1JA0RaTstJWzBgni6R3v/IE=; b=rfOlRj/e+VZWhjkFHMhg6qqFPHJMfhnP+EKgMH+8DgdDU5MSeAAjebyzWEfLLke565 fZL9lfxCGhx9X4n1oKsjRuAz26D4AfNXLxcl/7/AUKIoODlhv3Kshc00ZZyVsJJ1INbl wAheN5Bz8ijUVZFbemfig77irE0mLrtFi6t0c3zaFDcRg847Vn2fk9X4st4Tv4S9eegM rU7l/mQXsKIAWQbr4AZDc7YOjb8VDdAszAFPJ544NanJ68e6m1vEzcARUFyvIBQl+Ucj /GHnsUE8F+5gMLPv3TGkAXAkRDlXgXRslqGCd3+IpqUrSy0gEFdrx3kixE83dzzxDK5r M61w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783335695; x=1783940495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=fVHnbZZMdwqZk7BriO9P1JA0RaTstJWzBgni6R3v/IE=; b=he576qzGP1kPKVhw9hygV9Ve6IX4TieRAiRXXDmblEyV7Bq1BdhgA7CW6zbyfeZAr1 WatEcfJAeNrXYts9YksQMdKt51HQ5g0NoDmS3lkrfKxhT8Dy9f/Fl3ppT20/QYQs+p7S P3OhM2mSQcSTrcSDwI1J2vnbJakjacPzDRwDMWEznqUOhrqxZmRvkDIhx34R4/H3oe7/ Hyju1sWZoRZgPhvpk3UPXJqpwsyTbXlgw74sECL5EmxGt/IIVUkaiIGUi6+Jf5TCMt4K L/viDYG9etuS8t7cTK3Fiy4LfjBEexLWdi1iXm9nZaqGtXWuPVmkY87iSAyNs5NzDPP5 E9Iw== X-Gm-Message-State: AOJu0YzOTh7Ax6Ja3vq4HvHvngTlONM5Wp+k36DU4CbLjHA9bpDJEYSf LETtzkgm/TnB/AZJldInI9FABYSvbfwux1D+SHkpU76t+Kuz9mgnmsn5NjnbQ1QxygqP91ZXAs/ En1tw X-Gm-Gg: AfdE7ckHpwGSPU/Bz63UGQJai3Bhookqni9HaGNCVIFF4BH6fJDue6XFFmhknJZ3uvn trYhLnVCOBsA7p0ZkjPDOhx9ote+ZUFDJei2haxNAYEoYFyK04jAcpo4vL/Xeygkc2aZQsBPY0d 55FB27a5rR3k41kCHA7PP0pUs3+HNNEBQV4OGS/ADOWAcW2sj0434Ca5Q+Id+0cpuhZREunZo/j IuvHhFvFewTLaBLXSnKUxKv/tqNa/y52VacCLmhHXOGVD+3rVxMfSKck04dTktU6BTHuvJBATvj y1LsBF8nvkjlUi4nJPPI1Aq8XO+BPb73ix7ZqudFnXBB/12DhkgwxssRL5+Iao+P3STHMykKfbe 8XLTID60lIkQSg/IcuyamNqTHRurzlnrlGoDs/PhHErt6uJybWW3dyBXdn6fBSNvSyRER9P/t92 2EtFCDWk0D8GJRx0g+UYCiHrx7IFlX X-Received: by 2002:a05:6000:61e:b0:475:da0e:7465 with SMTP id ffacd0b85a97d-47aa92c070dmr12584346f8f.5.1783335695236; Mon, 06 Jul 2026 04:01:35 -0700 (PDT) Received: from inspiron14p-linux ([109.77.44.220]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0960634sm25190846f8f.26.2026.07.06.04.01.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:01:34 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz, Robert Mader , Milan Zamazal Subject: [PATCH v4 5/7] libcamera: egl: Add activateBindTexture Date: Mon, 6 Jul 2026 12:01:18 +0100 Message-ID: <20260706110120.2509826-6-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> References: <20260706110120.2509826-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When operating from a texture cache on dma-buf inputs we will no longer create new textures nor attach those textures for dma-buf handles we have already encountered. This means we will use the texture id associated with a given texture unit to switch between one texture and another. The pages associated with the texture will have been populated with new data by the CSI2 receiver. All we will do is say to the GPU "reuse this texture id" aka zero-copy. However we must also activate and bind that texture for each loop. This cost is small but necessary for zero-copy. Reviewed-by: Robert Mader Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 9b4261c55..1e31d490b 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -112,6 +112,7 @@ public: void createOutputTexture2D(eGLImage &eglImage); int attachTextureToFBO(eGLImage &eglImage); + void activateBindTexture(eGLImage &eglImage); void pushEnv(std::vector &shaderEnv, const char *str); void makeCurrent(); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index b91f9096a..fae907881 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -138,6 +138,23 @@ int eGL::attachTextureToFBO(eGLImage &eglImage) return ret; } +/** + * \brief Activate a texture unit and bind a texture to that unit + * \param[in,out] eglImage EGL image containing data related to unit and texture id + * + * When we create a texture we will bind a texture unit and texture id so + * we can set filters. For the case where a texture already exists though + * we need to activate and bind an existing texture. This helper function + * facilitates both cases. + * + */ +void eGL::activateBindTexture(eGLImage &eglImage) +{ + // Bind texture unit and texture + glActiveTexture(eglImage.texture_unit_); + glBindTexture(GL_TEXTURE_2D, eglImage.texture_); +} + /** * \brief Create a DMA-BUF backed 2D texture * \param[in,out] eglImage EGL image to associate with the DMA-BUF @@ -197,9 +214,7 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) return -ENODEV; } - // Bind texture unit and texture - glActiveTexture(eglImage.texture_unit_); - glBindTexture(GL_TEXTURE_2D, eglImage.texture_); + activateBindTexture(eglImage); // Generate texture with filter semantics glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); @@ -270,8 +285,7 @@ void eGL::createTexture2D(eGLImage &eglImage, void *data) { ASSERT(tid_ == Thread::currentId()); - glActiveTexture(eglImage.texture_unit_); - glBindTexture(GL_TEXTURE_2D, eglImage.texture_); + activateBindTexture(eglImage); // Generate texture, bind, associate image to texture, configure, unbind glTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, eglImage.format_, GL_UNSIGNED_BYTE, data);