From patchwork Fri Jun 26 11:33: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: 27048 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 CE158C3301 for ; Fri, 26 Jun 2026 11:33:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9FBD2658FE; Fri, 26 Jun 2026 13:33:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="c6gVsJjA"; dkim-atps=neutral Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4B908658F4 for ; Fri, 26 Jun 2026 13:33:38 +0200 (CEST) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-49249707788so7531815e9.2 for ; Fri, 26 Jun 2026 04:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782473618; x=1783078418; 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=AIHm6rbPGluS8yMRW43DSurymjR5fEjks6iSsfrj5Vg=; b=c6gVsJjAmjWJxCJq4IAs4H5ipXrfS28VEl7VKtFeqWzd7YKTBpOkobQ5TuW5//NGtF tQPafbq235f6DBIokt4+Q6n2gJeBX8DlU8O5PgtjbBVu8rWT2tK5H8yRPf/tv46z1Tab 0oCE893puIbu8l1CDZ5XHd/RIFbmizYYhK2rruIXLgPS/8yYRNBg255mln1jJldFD0AE F3zi2jpnaycZ519SpullhnpzN+46+XNv0TFTD12E5osTPXf62pFkdjGlYCE/Bf8Rfj85 XZZs5zTqSVD4A7a2gVgu4yewYlz55goZmSJFzSqxQgwWGxcqSzYcshYnv5GB5mP+3s12 oOdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473618; x=1783078418; 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=AIHm6rbPGluS8yMRW43DSurymjR5fEjks6iSsfrj5Vg=; b=VMd50i7WORGk1C0HHPAXeK+Sh/mhculJqtjE1hXr/yKChK1MLYwtsKXhjTOj/YWTXE MRFAyr/RneIZIcCxdGNxDB2FyjU65hG1AZ6rfq+OHIsnOQKcOKMeiDEqtJQ2AO7Zk3xr cpZv6Rd1c1yh7guojtM6j6/D0yzjgJdYcp01eaSRJ6wQO/JpbAyUdB7GC0lSqHrRKOye EhdYFTvzn1+uMaWDwCXI+IdQqZLD2Pe17JsZa+sfGzRtSCVQ2yZkjoyWQokwvHb5h4B0 BoorzNvX4VfwaoV0g7WX0odt1lzEvagUU8kKZHh1SCvCthzj/aR88QE7IYDugJhvZ7IN yXnw== X-Gm-Message-State: AOJu0Yw9ucmWIDsQGD1ecweMKmXFgqcyLiMRAXoOUwR8bfntbHRGHZLO F0YN+n/G/ywWhmbacunS6dbsMDzKO2E3PbPAeTeEbHYag1A42HgINPyOaoJhgRWvUFuQyiKCTs4 ObI2Tu8Q= X-Gm-Gg: AfdE7cnONMN18EL3VB4sZc8anuYwnKASnpw2cZieH8yhge3xZi+vWHXwoNrCfaXej4A b7Qqb3Ek3Dmb0MdX08xYv2Bu6+8W4/lysVOIAiLwc6Xp9P4ahrDAqwGUOBTd9DXXPTZ7qUA1FjE h3W+qwPiG1o3xuj7/dSORJinXhNbhFW+wy9HFFBXlzZAR79C7vEjXKGJp1n2QJ5kS2sZ8gLyATc KSvUJYd0XOz6DP/HpzKLxh+rEDiOWXkw+s3gixDWSL9Ouy5NRFphGMxdq752agZB/OSzPzyzCOi pXOmkR/E2OfopVgmOy8t2r5Hk7WRF1EDOd8SM6HTEtKQzKKcJ4UD55QKpP/VDT9C4xa1rwG0VKl 0+rENRakDMIVrfAD8Paj5ei4rWqcm/M8jGp4tOHR5JpcfA0yDt5kM249CswFO6e+sGK0uSj2STa xRqNUTPQWFS1OsDpUx47hJQPQFMQ== X-Received: by 2002:a05:600c:4e0b:b0:490:44eb:c1ea with SMTP id 5b1f17b1804b1-4926fc78e30mr6165485e9.24.1782473617839; Fri, 26 Jun 2026 04:33:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:33:36 -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 1/8] libcamera: software_isp: debayer_egl: Pass eglImage as parameter to setShaderVariables Date: Fri, 26 Jun 2026 12:33:18 +0100 Message-ID: <20260626113325.3218045-2-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" 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. Reviewed-by: Robert Mader Signed-off-by: Bryan O'Donoghue Reviewed-by: Milan Zamazal --- 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 0ec2a98cf..14eeb9a29 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 Fri Jun 26 11:33:19 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: 27049 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 E468BC3302 for ; Fri, 26 Jun 2026 11:33:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 351E465ED5; Fri, 26 Jun 2026 13:33:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="NBYyOzp0"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 97777658FB for ; Fri, 26 Jun 2026 13:33:39 +0200 (CEST) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4926fe5be4bso691325e9.0 for ; Fri, 26 Jun 2026 04:33:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782473619; x=1783078419; 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=lwy1OBNeUsMVfQ9YO3r6PrYvUXJ8It2Sz/tQewNmuR4=; b=NBYyOzp0P+w0omeSMQF4nxFKE7+h1D1xpgFcedChpddJllK2uCyZQDfwP2Ppv6twY2 VU4Eqv4dg/X1/0X4kn0SPHPI/CXmexXwnXwkBlNc4qmhwO58jtPM8ssw2jbGipnctUXE igXE/aO8GHbyBkOiVw+HG0MxYExoNi0w9tfpJTjpuCJRuz+1EaCojjsYZMTLNVDsZLcK gg9zn6tmNO1oVrhTx8riQgaOXaVmmVt9x8f6lJBHzqQHSJmu46BpAzVYif9HgSRk/BtC xm8K8FJMBy3PHO1e1VU+2mBVg2g+WgTtcs4z995LqHDulIKPWxXIg2Y9umEcHjU/67/+ c1qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473619; x=1783078419; 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=lwy1OBNeUsMVfQ9YO3r6PrYvUXJ8It2Sz/tQewNmuR4=; b=r0A2z3MoThrM47ogULOyCFqvfYfy54lkHfm1bg7/yhS1X8fzqKo0lFDhwqdqhbvx8u evpC88gXuLwRN4l/y8+oHvmh6kES65IIkIJfd8Oh7zHYpGdrKYQUKuDFRix1chZrbJWy DEcLcvkTNnBmWPo2cmhSZ6oXK5oqjM33eunq0q1GILRQDf2f6c4iUAGrLTRNpdRle8Op pa1hVhY0HIqpu8c0mqGZBijP0GIcr6oGWedkQvUiyWDdsUTuaI4yRSqef5ppeex+nqyV SB60MhjfKcCvp7UFgZ5568E2PIgLbx+QGztd1ZAtUb9ATnQF9C8RYbn6Hdld7oKtBzdl owxg== X-Gm-Message-State: AOJu0YyYoRKng8VaMaplDUrQ6h9vuiMCneQEurqmHF8kqKcIFDBIPn1c bv1y7jgG9ct5PUQzB8kdkAHyrNFyECKc9Dc2bcLSU+pUMi1gqEjuv+M+GbSO/KQh+G9UZUa1UWj qXGWKOxE= X-Gm-Gg: AfdE7ckABwPtsN8/17n3+9UspI/rpcx8RH30Vnln7nqUTxbc7xfNXScyRYWqcmspTPw b81ndW98pCUYF8wdeU8bR5vaed0AdyN+ad1h1IxrHg4CXuyWPUy/xrM3RfpHBaD3vPlErmlGs50 J8G+DS0jQLX0Nf+Rb6GYp5d4AfjAiKFtxNjQrXdeFPOL6MRSPCiIRejlbHxZ3Jld5MHwIql6SSN uoQ7tFx1admP/7gM4tLbV6062TginmkSbENZBqgbIiZ1CloTnyBL/WtjR3IRwrRWEyz/hf5kAS9 4UGD9nnQNI+IYrGI273Q+EiR0KQ0Tb04KNYkIzcQ2LKir5yRaN3KJJRKDCwbfs3Pl7k087kFNxh afnvgUVV51PEj0htx7yjlVQQrZbQr/tCTxiRb3jC3UJOeqzfFhi0FwHCP5GdHRzIIzJz7Qps9k+ 75mxFUQD5bAJHpoXtcaQkyg7bBWQ== X-Received: by 2002:a05:600c:83c9:b0:492:379c:32ee with SMTP id 5b1f17b1804b1-4926fc2f61dmr6292335e9.6.1782473619029; Fri, 26 Jun 2026 04:33:39 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:33:38 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH v3 2/8] libcamera: software_isp: debayer_egl: Flag dmabuf use once per session not for every frame Date: Fri, 26 Jun 2026 12:33:19 +0100 Message-ID: <20260626113325.3218045-3-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" 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 Reviewed-by: Robert Mader Reviewed-by: Milan Zamazal --- 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 14eeb9a29..53bb67c17 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 Fri Jun 26 11:33:20 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: 27050 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 18F06C3303 for ; Fri, 26 Jun 2026 11:33:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6A29565902; Fri, 26 Jun 2026 13:33:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="b12rW2fW"; 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 209EE658F7 for ; Fri, 26 Jun 2026 13:33:41 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-490cf3000f0so8767895e9.1 for ; Fri, 26 Jun 2026 04:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782473621; x=1783078421; 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=LrHNd8eVo+wksS/oQ0Oh5AIQ6rb4Iv4ObWfNNR4zJvg=; b=b12rW2fWaA163AKi+VM9PwV8abAnfwTZjpGGs0gdQVeivtAKMUmF1BhUzMW8bPdu9X 075JFvYG/KJQHy1GMU6ou4JCqew/eABOBreXZI6s5hTIAOCAlORpVdZyUOmu7qAOny+I eK+0UM1Ni9o26iWINsdhDusc516dg4FVIbSrLU8aWW+itmIjFFS8t2XdBKNo4T3+xF6w P1Tmwc3i+ZaBXKbl0Ro7eF5R/lsJmDxEo3NeqAtBROjAAwO085mMr8ifdhfub0/Laek4 tSfDor8aV8wE5Ypp+ScR+8QTe6YITAxmAfHjbDPtm9LPkBG57ptJQdAcV6ARnmEj8lla ZBcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473621; x=1783078421; 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=LrHNd8eVo+wksS/oQ0Oh5AIQ6rb4Iv4ObWfNNR4zJvg=; b=kArrbHOMs4cKM4VnDJj3cJArM992M/QNdLT4/A8RG1C+tyKRps8AN4zgVt6FFGUlt5 ivlWdh9YZM+dwDQN3A4mgqbZXrSFQ6tkwub5xZ5XHfkkD4mukWYt2NBeuVA2SUf1FN5N XLqAeukgofby9F6FBcVBtz/KVoSvS9VXguJ1ImpQMAgkNqiXP5/giOVyu6A+7Gg0CnNe DbXeVjq6j1Tw0t52MNUTg2iSELprJb+7uxiNZO4sUNmpQaDpDK82rlXmh/1L7fbC6Pol fR94xtCvdpiuWNc0yDkS/IVbmF0u0G9VHsAel4WrmxY4JDoU+AVLlt17fTEJ+CsV5Epe DAzQ== X-Gm-Message-State: AOJu0YyH0lqq8eEJbJPavk4J7TdBGP9s72FEB6Zs4n2ttZMcKXO/33CM m2EdJkVhg+q31hILDOr+tVDfQ15j0Jjrg0TquudTsf+d8bPCSG1ynh5eKQJ3oS+1IJtF4dCBu1b A4IlA81A= X-Gm-Gg: AfdE7ckAaVc7RLPV6l6uYTq9+ka1Tw+FJYy5ABanF0MozEETlnsSNVLwX0coOUZ9exu OpPMYpPP1NtyjV/H3WD6Btce9YMgbGp/sps1xxr/+GAnSI7ia9ornW8i3FPhxzRttFoKjbHUkps FeGXv+Lqz1fjlxsrhayNJlr310xt/3f6nGD9Cr86+C/2qEYtuk+mbJQWpxfO5xC5vJwH7JpKNIM dBRgZaE62LtY97nHhRY9F0JcQ1jeFEkVxD2c7LsNx24cmikUBNfCWZacArayguUlpzCbunmIcw1 t6P7bW0tv5O1YZ30m2UvC1GDCNm6VhYiK+RC2do9RZgyvPwv9oVFX9MtYMi6l8NJHVmB7SEPJhu ysmhCg/pzAVTg0X3gFaQ1YMSu62PbA2nacldhY56PVat7HKYtvy/OqpGzWueYVfke9mmZLjizh4 9zCy/ZwreA23c60vhfn6YYlRi2gw== X-Received: by 2002:a05:600c:3552:b0:492:700b:deea with SMTP id 5b1f17b1804b1-492700bdef5mr3810595e9.13.1782473620548; Fri, 26 Jun 2026 04:33:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:33:39 -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 3/8] libcamera: egl: Add new helper attachTextureToFBO Date: Fri, 26 Jun 2026 12:33:20 +0100 Message-ID: <20260626113325.3218045-4-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" 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. Reviewed-by: Robert Mader Signed-off-by: Bryan O'Donoghue Reviewed-by: Milan Zamazal --- 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 Fri Jun 26 11:33:21 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: 27051 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 B0AE9C3264 for ; Fri, 26 Jun 2026 11:33:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 590D765EDD; Fri, 26 Jun 2026 13:33:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="gWy/lazx"; 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 5EEE465902 for ; Fri, 26 Jun 2026 13:33:42 +0200 (CEST) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-461edb387ddso853909f8f.3 for ; Fri, 26 Jun 2026 04:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782473622; x=1783078422; 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=jUQq+g3RcjEZNYlYpd5HRjFjfEB5jMW9ZdOwMImzcgY=; b=gWy/lazxciK1ZKuzVcSvzsUcpdJ5vVycn01MVWlkDXcinSE1OJgxndX0/VU8EXPNNr 1JSff9EVQwmAoOX9u8NmjHzlWdkTqClSEr9hIZyjQ1XDouf/VYbF4BH7Cs/GdC+6KkhW ryxmbxXhKnfDfOQ1K8mF/zR8y7w3/c4Qisr83o9GFF5+zwF9H7tCk4j6HU4XH4h3jqjf EknxdOxUH+oiQqFXZ8baTVPgl7kkfD/nA6DiVsgheVLve3zlcUVVxvzPs7In46nmqsdj af818ufFDp2IZsLev6E985MUXxLJNCjf9D1H/ZLIDoc4ORYDTEtksEol/HApnd4zzTt/ 4f2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473622; x=1783078422; 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=jUQq+g3RcjEZNYlYpd5HRjFjfEB5jMW9ZdOwMImzcgY=; b=W/Z5NBGBStgkoQCrVYc+4P7jH2kMlTMn7n0ENUcBEMmGU2z2qLGWcGQX6j6FKpyT8r VFeQqoErcQs2cvG7s1goWxCcB3vqQdYBowi/ivB7MOSsR8d2mez9CIUI72Z0kkhpHz6u Ds2OGXkbq2kFd4WkNCpV1Jgk8B3yP9Hz3EUAu9Fqe42bgoF4nREXCPkRd2Sit4yqiwZy 6jYaEetscZWtK5izd4tWNUBS776A1Tss0xWKuIVT40Zex8/7dVHu2/tZVh/y+t0P5kBw SZujN6itoVtXY659pZU4kLX6OE9X3TI41vaFxL8RwfGrc75x8l5pWX0qziTzslUjYRLV Q5XQ== X-Gm-Message-State: AOJu0Yz0niEqQ+WfEcoDTf1+bDfnP2eGJu1Rqh124GTrj4FOdtudM1Vv Zqz4MOc6x330MOg3pDhKh36iGEmaOw3f362XQVSssuoDbMhNv6ycCKU5N/Oo71rfTlQ0UFaUBIR FTS6e3Fo= X-Gm-Gg: AfdE7cltiGYSM6XhEZvJKpeVZ/+u+5uDVdrqhOPSd3mOFVULbqK2yGwOaSIsSUgZKIg mjbQ8UBm5eLQFgn4CDJclZW7RmhEbTazTkYtdUrMjbvZ5JcYNwhKbYWEknsQcOHdJPSB7xIHYma rkog2KtIwFKHdaEYJHpSxpT4yqdY98PBc8xF1l3jizgTZyd3eQAZ4dF4Go5hd5COl4M2Qs/9GT9 iNtDjyVYpIweJY2JmCDQCMY/KDGzJE606z1fCV1Dgvwk2OtpzP6KdzoHrdC0//0zShsW+vi+kCx tXbxD06zSYpbXAA5Qei7i+RW+fnpKn6mh3OG7q7hjVyFATlC7mRNxm/u53HEwOw+0ak4g8b9cJr 8/U76M/EQZUEhz0XRSR8Y6kNg4aIDXcirqy+Zj6DxyVCSSXGwvSP4fvp+j3dEjveI2XI3NnAHuJ JF0alyLge56lg2OX9OTgrYAPJMDQ== X-Received: by 2002:a05:600c:a49:b0:492:5bb6:6d4b with SMTP id 5b1f17b1804b1-4926689abd5mr89120615e9.34.1782473621893; Fri, 26 Jun 2026 04:33:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:33:40 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH v3 4/8] libcamera: egl: Add createOutputTexture2D Date: Fri, 26 Jun 2026 12:33:21 +0100 Message-ID: <20260626113325.3218045-5-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" Creates a non-dmabuf texture attached to a frame-buffer-object FBO, which allows for render-to-texture. Signed-off-by: Bryan O'Donoghue Reviewed-by: Milan Zamazal --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 4b0757afd..e24a726dc 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 createTexture2D(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 e83e24606..8e8d61813 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -329,6 +329,19 @@ 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 + * + * Creates a 2D texture in VRAM. Subsequet attach the texture to the + * texture unit specified in the eGLImage object. + */ +void eGL::createOutputTexture2D(eGLImage &eglImage) +{ + createTexture2D(eglImage, NULL); + attachTextureToFBO(eglImage); +} + /** * \brief Initialise the EGL context * From patchwork Fri Jun 26 11:33:22 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: 27052 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 D2C6BC3304 for ; Fri, 26 Jun 2026 11:33:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5D5A065EE0; Fri, 26 Jun 2026 13:33:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Ax9NxrNd"; 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 88F08658FE for ; Fri, 26 Jun 2026 13:33:43 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-490cf3000f0so8768165e9.1 for ; Fri, 26 Jun 2026 04:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782473623; x=1783078423; 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=oKZ71QaBtM6ROt/Onecsm43QmMC4gfI0FGbAVT9Ibl4=; b=Ax9NxrNdFqHSFAoeZ4lz5J1I5KM211xOLkB0bf9nNDtlxGXqsSP5SYEEjYBqgyuY8X tH0Scn4FFHMFIyfvFnvqYDVwLIYoaH6sL3GB5yG6h52I9sfzuLlLG7bK1Eef4N/Nk8U2 4/9EN5IlP45TtnsxxUNUr7ebw1fnmF+UpHWAM6gJWtzF8aF4duIe2VqiZAxBakTdXgaM yxYVh9bO0bGQkattzT6cCnSVfJjmTquINF3p0JHGHzFTqZgHjQiDJraTaZ0dkcArObSz 197vzF8og40n2691Tyqk2wvbu2OjH7Fh7H/RwJHeK7cRv1uN1klAo7vx9kHZ/hBV3oEy qRAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473623; x=1783078423; 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=oKZ71QaBtM6ROt/Onecsm43QmMC4gfI0FGbAVT9Ibl4=; b=aNy2Ybth2NtiBrZawTGKMJCYu9UYYscIUpomKQk55pgjLU2S9rFAs7mqOipIYAGNq+ Y6wKs9UhNEOVUx0yHqGuL4AyQye770nMFSbJNpuo5KszQfKF/pARn+4tmfx0pVpu906h lJAxdL0F7AkxVOgIu8jC0podbRGFfL5LK3TBnHHOyehbwQkUk3SEFW6djNPlFStEZU1n xCUpxvNnK7KMDGkhw0dksMFNOWXCUCD8gwkebbryu0O3/mCC4QfZjWVpfpzMGptFIG15 z1XUWqWJuTUPPEK5VUoHvqES0RyYdIRycAtZmB1469eybp5ScrWsGHcn6xlwo1szndDf ObAw== X-Gm-Message-State: AOJu0YwKtEwGWz//1Pot9KrsX2S+6w9g5I2SbgbDxm/XMOBgS+kucfXO MU32x2AznD6qCzZnohmpisG0DFO9XoZdYqHigU3Kx0PowNrBEJ8mdVOjHyy/xj/hjxNoQi4PaUi AMlmz1HM= X-Gm-Gg: AfdE7ckNAsMNlSAI/nq3AxhTRs5goabZ+7GhMzaXqBbd10PznrI0YU4gOM410itk3iu 6ICU/QPveVqfBFLqLX1SpXMPYpoMlzztru9SIK30MXJe13r8Vc/OZwYO+dp4b9yK6w+580n4Ly+ oipHUR9wTNtspXexqa9ja0XKpNcVjLeAJxb+LPVuYdErA35Lr17fyR9nhT1hMojYnSAKPbQdpyv cdMaA1Mk8j5XOTZu6NvLV0Ehci19kYX4+1SOGm9brGDnNbA/a59MCXjn+1WSPneS2xNXWKoc2HO Bxl+LgfRLGSPd058qsj1Akdf3LjIB6Jkp8Wr93vVvQHa5iQMdT7xG1sOx7nv4em15BV9FojABSE paS4wwP8V1YL3a1q6ALp1+8grrUrusm7xgYaxGoOB08Wq4D/4B90YjntRCg8FpKOkHurcrQmdD0 QjiLhAwBiNw63ao9JY1nK6ZIoqazN7jlQ1Hjkg X-Received: by 2002:a05:600c:1d0e:b0:492:63ff:d577 with SMTP id 5b1f17b1804b1-49266899cf0mr97714435e9.27.1782473623005; Fri, 26 Jun 2026 04:33:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:33:42 -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 5/8] libcamera: egl: Add updateTexture2D Date: Fri, 26 Jun 2026 12:33:22 +0100 Message-ID: <20260626113325.3218045-6-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" 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. Reviewed-by: Robert Mader Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index e24a726dc..9b679332c 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 createTexture2D(eGLImage &eglImage, void *data); + void updateTexture2D(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 8e8d61813..22f46e92a 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -329,6 +329,41 @@ 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::updateTexture2D(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: + default: + 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 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); From patchwork Fri Jun 26 11:33:24 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: 27054 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 8F9EDC3306 for ; Fri, 26 Jun 2026 11:33:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 13BA865EEA; Fri, 26 Jun 2026 13:33:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="qLfj5qOW"; dkim-atps=neutral Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BE6F1658F7 for ; Fri, 26 Jun 2026 13:33:45 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4926ee9e8d9so1532145e9.0 for ; Fri, 26 Jun 2026 04:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782473625; x=1783078425; 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=wUTK8M+uWf50J9eOZKpDSPxAGvL5i5epNISJptGTKUQ=; b=qLfj5qOWwCAG7E4i1EnH5jTB6kYLXX7k0u9xUr64P1cOQ12f1IiPIuK50jIKkp4BYo tfyzGzsgSZ/pwkWE9qUdaxhOY4trkYVWRmlOKueOAGMTbMDlCN2pwedgP3RPKgzT1ppF 4ghAt/Ra9pEWRrCHYpwIM8V2MwaXcjMp+EIp9tarQYoIFtGgfSfww6SgJaKrPUUtZjGl AKRa+cBmm1hrZWUy9JEcuAx6cYa9V96xin61LVitoPSkbuBIbnPldrB6pWWX+AvI18yH CQIyA15Jd864DHoOrsURbsZt1As9e8NSTZvfynZUVvFBkuKRBE+hQISsm1iAAdqbx6EW rhmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473625; x=1783078425; 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=wUTK8M+uWf50J9eOZKpDSPxAGvL5i5epNISJptGTKUQ=; b=SaYuJJzlFtcaUUG+0sAGU139zidukoOcmVJ82dZKBdATwPwoUnvwwPhU7yUq5iLCdY 8z6oYS/wNhG03jUmvUfSjjOtMwtm6JrvKNvw2OVcTfFAqf7lRB+FaJt3gKqliJDy9Mk1 Tn8z0gbzRIKpqUsOGC7m8WUyqgVjLa7uLeW3wMV7HjYte4BKWPc65ZDlSX2AaAU3TCOp ctzN0Ydjob7LYSU0CYw6iglKxiUeIT+tuhJfCyW6E/Oj3tohYbGiDQyl+4hCa0l9PbQA sHl49F5QKPdNJHc3YOuLrzzYhrvQD51QJLsVnKDVytVlv49wnISAepQPnojrt9HMXHAF L5ZA== X-Gm-Message-State: AOJu0YwqRiNcgIcfD/zEidJhpTqvC1FHB+Mn/5DNu4fdMKBPvr/p1qnJ yZUxEM+mbcbp//qUUh+cM/yA7iu9QXQcIhYA8Uo7T10IQWlgphTuW83joKVrcTcxCvlg98nmq/R fdQtxaaE= X-Gm-Gg: AfdE7ck2HLufNJQyX3zldFBzsVVcRQeXUNAtc1hkVIr6YkR7bdsPhcdJkFyVfcR0IXe PlKF7NviMq3Y+tZX/hRYveh2BMd8S8ag10GPdBJCbDQG+ColgOXCn/R9fUOaKgi3NR4Aa48awv7 OuRnvgdDHZ3RJms5YxR4swvXRm89/axprGH9+DJSUhmdJ8M9f2UNhLoDDNmDU5DqUBgDyr0ZSoS uGnRTEzYpzeiaYe8oVKxTv/Nxt7idWLPPb4U9KMGDnsHkWdJH4Vu45a31KkTPqscSBDPTWo3hhi xPj359tk96Xcqi9XRGWHuMa5WLP2fQ5cRBaZKv89NGdNsB0L7vq/qUqC6RIxLae+xGGOhVosm9l Zvu0IIkFQ7nKQh3Q/mjJzJFAPY6/luTCfEFTuYdzJH/gx+Fd4rxq24TnDR7A1/xQ5e5FAGc6A2j It13CVMpPQM8XjcPHxdgaZzc60AA== X-Received: by 2002:a05:600c:1551:b0:490:3cf0:8d81 with SMTP id 5b1f17b1804b1-492664241a4mr82720495e9.13.1782473625269; Fri, 26 Jun 2026 04:33:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:33:44 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH v3 7/8] libcamera: egl: Drop dmabuf_import_failed_ Date: Fri, 26 Jun 2026 12:33:24 +0100 Message-ID: <20260626113325.3218045-8-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" Drop per eGLImage flag dmabuf_import_failed_. We use a per-session import flag use_dmabuf_ so there's no need to mark failure per image anymore. Signed-off-by: Bryan O'Donoghue Reviewed-by: Robert Mader --- include/libcamera/internal/egl.h | 1 - src/libcamera/egl.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index e4d366abd..d2c4d1a7b 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -90,7 +90,6 @@ public: GLenum texture_unit_; /**< Texture unit associated with this image eg (GL_TEXTURE0) */ GLuint texture_; /**< OpenGL texture object ID */ GLuint fbo_; /**< OpenGL frame buffer object ID */ - bool dmabuf_import_failed_ = false; /**< Previous image import failed */ private: LIBCAMERA_DISABLE_COPY_AND_MOVE(eGLImage) diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 4eabddcc7..ce451d521 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -210,7 +210,6 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) if (image == EGL_NO_IMAGE_KHR) { LOG(eGL, Debug) << "eglCreateImageKHR fail"; - eglImage.dmabuf_import_failed_ = true; return -ENODEV; } From patchwork Fri Jun 26 11:33:25 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: 27055 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 ACDB8C3307 for ; Fri, 26 Jun 2026 11:33:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DF18F6590C; Fri, 26 Jun 2026 13:33:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="AdSWOPZV"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CF2C65902 for ; Fri, 26 Jun 2026 13:33:47 +0200 (CEST) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-49222fb062bso8934565e9.1 for ; Fri, 26 Jun 2026 04:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782473627; x=1783078427; 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=ggDf+Tx2g2b9HHWJEEpcyZgRvHrHYXQMzOnA7eG6sds=; b=AdSWOPZVjYCx6HLEjAtqHBFCp0OqCRZzotQt5LulnARU9E4o3eSU/CCA9IIWtzQ9/n fjQTi+Li/3PBk7QYIXRNEMm2+2a/7Ozx2wBUtA0d4ELHdjcmvDaUaqsii81IUSD85oe+ Hyqb1pqANGLBoCVg2CW1T8UT1ylP40LahKZf8w+whiCEosamchJ6woxhrT6apOskGJWV YD5b6hl17+FtpSO06L3xogJ3Ir/+qAF16EKK0yBAddQVeL+gu5P/q5bhsJkr/2TpPAIb ypn7+qS2+W7+5XumDQHgRYSAXbyKPu9R957R/2p7hAKdOlgIiKZRkjSvpR8ghwtcqnOD B98g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473627; x=1783078427; 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=ggDf+Tx2g2b9HHWJEEpcyZgRvHrHYXQMzOnA7eG6sds=; b=D4mtCSuxiEBDmPHM6IKojdgUDIKjkufZl50ez1HdBNfB6Cx2WBwYn14gY6qsFlrF1w 25mvzu6Ent6Vl6VdFh+2r8nQRKrnbuBcqQ8X66v1rJCGzYq0QfsBA+60169L+6x+Vw+v nH93gnP2UseAak25HArAREunBGz/VY5B0nBFwSEv4uBzFJpyylFnYpDfIUg/2saf+Q0m get5Tu0s1qKO/yKu/eRhDp90tazRv0YcpMlCNngEmbCsdNcXeHZI5zqx7+BpagTYEHnB uIe2rKbmki1hUcfNzs3xeMGPc8UdmIoBarC+uY0I3M8v9Znj1eDj2Z37w66R3S2Ickt6 3vlA== X-Gm-Message-State: AOJu0YxWhHVMhIHrfMgoKe6UdTHlvUA6ej9a3B5tgy7Tm+HAmZfu3SN+ 53Dsws4YiFMkk/SA3C10f72VbHw9iwjaMBkHst9bXUouhyeiLyuRNAYqt2zG0ToI5GXY9hAe3b8 uT1MT4WU= X-Gm-Gg: AfdE7clJ78tIoAQmbo+mBbAVTSAQQnH20bCkgf1sf6SuoAqHiIb+ETDw1CBrAnsrAue PYbznnFGwAm8yrRQ7go0Xv+wLBubO3aQB8H16cwCgzzJyStaeVnuU4uVTK4u8nY8MWeEBAnF+aW fxVA/fVT0SIo2hbr2fG9BXhV2SE0gCa04j3H+I/YOR6vjkKURHzdi6UhWfN6gi4Yyf7M9FuxXpr 6EICUz+Qs/c7hgpG/KzUb0BvhMOJ484S0oLrqvFKIHz6Ar8t21uY7H4Nn5g4dI2VApi+RoQP9yw lRjFTC3zv15MziMrq5uanFQHr8echX2Wabxg5eKhedblRl2IGQ4WLOBREo+4hj5hmk0zWqzcEBo xyH4xZ6mEVHEo2YA/YgjKXUoD2v2gAehHEGhUydJchqv/ECsdrQ9NQRU2gpEHNoWnqTe+yRl0zd fTK7d1XJKCSGb5zGagoS7mZ27NK8OYiaYxpTk9 X-Received: by 2002:a05:600c:4e87:b0:492:25a0:1730 with SMTP id 5b1f17b1804b1-49266893494mr90648115e9.32.1782473626579; Fri, 26 Jun 2026 04:33:46 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:33:45 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH v3 8/8] libcamera: software_isp: debayer_egl: Implement input/output frame caching mechanism Date: Fri, 26 Jun 2026 12:33:25 +0100 Message-ID: <20260626113325.3218045-9-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" 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 Reviewed-by: Robert Mader --- src/libcamera/software_isp/debayer_egl.cpp | 87 +++++++++++++++++----- src/libcamera/software_isp/debayer_egl.h | 10 ++- 2 files changed, 75 insertions(+), 22 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 53bb67c17..fc37f0b75 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -355,6 +355,9 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, */ stats_->setWindow(Rectangle(window_.size())); + inputBufferCount_ = inputCfg.bufferCount; + outputBufferCount_ = outputCfg.bufferCount; + return 0; } @@ -514,34 +517,84 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara return; } -int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *inMapped, std::optional *inDmaSyncer) +eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer) { - /* eGL context switch */ - egl_.makeCurrent(); + auto [input_cache, cache_miss] = eglImageBayerIn_.try_emplace(input->planes()[0].fd.get()); + if (cache_miss) { + if (eglImageBayerIn_.size() > inputBufferCount_) { + LOG(Debayer, Error) << "Input count " << inputBufferCount_ << " exhausted"; + return nullptr; + } + input_cache->second = std::make_unique(glFormat_, inputConfig_.stride / bytesPerPixel_, + height_, inputConfig_.stride, GL_TEXTURE0, 0); + } + eGLImage *eglImageIn = input_cache->second.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_miss) { + 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"; } } - /* Otherwise create texture for input buffer via upload from CPU */ - if (!use_dmabuf_) { + if (use_dmabuf_) { + /* Cache hit using dmabuf activate and bind */ + if (!cache_miss) + egl_.activateBindTexture(*eglImageIn); + } else { + /* Otherwise create texture for input buffer via upload from CPU */ 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_.createTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data()); + if (cache_miss) + egl_.createTexture2D(*eglImageIn, inMapped->value().planes()[0].data()); + else + egl_.updateTexture2D(*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) +{ + auto [output_cache, cache_miss] = eglImageBayerOut_.try_emplace(output->planes()[0].fd.get()); + if (cache_miss) { + if (eglImageBayerOut_.size() > outputBufferCount_) { + LOG(Debayer, Error) << "Output buffer count " << outputBufferCount_ << " exhaustion"; + return nullptr; + } + output_cache->second = std::make_unique(GL_RGBA, outputSize_.width, + outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); + egl_.createOutputDMABufTexture2D(*output_cache->second, output->planes()[0].fd.get()); + } + eGLImage *eglImageOut = output_cache->second.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 +676,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..ddb3ef378 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,19 @@ private: bool use_dmabuf_; + eGLImage *getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer); + eGLImage *getCachedOutputFrameBuffer(FrameBuffer *output); + /* 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::unordered_map> eglImageBayerIn_; + std::unordered_map> eglImageBayerOut_; + unsigned int inputBufferCount_; + unsigned int outputBufferCount_; /* Shader parameters */ float firstRed_x_;