From patchwork Mon Jul 6 11:38:54 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: 27246 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 AD278C330A for ; Mon, 6 Jul 2026 11:39:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1BFE466023; Mon, 6 Jul 2026 13:39:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="jv6ch5f5"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5F34265EFF for ; Mon, 6 Jul 2026 13:39:12 +0200 (CEST) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-493c1950518so19422195e9.1 for ; Mon, 06 Jul 2026 04:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783337952; x=1783942752; 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=s3J/NrfJsMXq4eaqAQimcvyIokeKF2MgvnNr4M7DXMo=; b=jv6ch5f5sy41XS74LiRTV0INiZ4dYhr/P3zUci17PlA15ceeDOZqeKvxdMbzhVqjt6 Ia6dwf6LiQByDDWELTA2HIg5VLUZud0gTLAvx+Nl+RzH146EtU+brA89Hsf/xXkwd96W mbrYwbu6A0HPi/k6FqDRy1RMVxb7p3zjpVZ0vHs7i/PdgUtqGWI8FvBmz5w/OwjzSmOw cJ2Y1022arBjr8GmuiouXMfgpAsZS+kDPPzM+izFxXS5WRL8oyJwXCIQ6spE6b/2kDc8 WkMt5BQyqtBs/NyJgsf8BjZUKuZruG3zj/w0Rjit7tXtjv3QO2wsWyhoFjrbrtP6uRId ppAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783337952; x=1783942752; 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=s3J/NrfJsMXq4eaqAQimcvyIokeKF2MgvnNr4M7DXMo=; b=JzXWKYRM3VjXxE/fC/VFfVxDNnK5qQvOqNonX13tWEWfVbaLRNEeH79w+dR5kEErh2 AalOkJ7TSKscGZE3L0/WBB+woIUXGUHxcX/jKAQrZ1L1lXhaxT1qvv68ZGVFuPhA6ASO BpLSH8xyf27vEyslV1VfF8KMkqnTYDPewKOkKWSsJD3/4hPslMESJ5qglX2drFyz/mU+ +2EdZFnjycw8nZ62yx0GlcP3WczS6V3OpwsLPEbXBFDnNqY+duFOqum1trBHN/IwlFQr ke3MHCy1OoexlChnPqxSLbh4Fi5sF2uMT7ElBfIshHcNF0IVj5JNxZxfSMGRbC82BExt cPyw== X-Gm-Message-State: AOJu0YxCr+303pQlckGVXKZ8XdUQGqiDwEIH2eATd9c9WdwcJmiv9oGm TPsElrzrzvREcKcRBowppy8OElicVH+112Tq8XwCaDG/mdtngVOuLXSh/bVvgBwlevNyzVIjUGA cpdHo X-Gm-Gg: AfdE7clQ2lEExzHfH+bOsZ6nJlhMOpcVR2zBAIG8N78fUsqIYmpABSDs39d0r6Y5lJa 4rwm/Y/n6P340vE4LMb2JLwIHAtzC3na1GpZ1V6frYxlpQnZDik8s22yGqspNwYqEerHeHPOuG7 rpZ/SmaCxOhyWs8FF//cRIbiZI2Zh4hUl3p+wOcDRQx+33BgsdVCc9sPBSWibPETMRbj97lkpIO PG+NIyrnLH7pkg4T1pbT8FCqMTXvYn2yXmZmSWTop/01qZNTF7wnuwSZIpNY0oCrcwisndEVWW1 UGGtE/rPc2jaI7uMKdbyH5RSeg8d5DeBBG2alMpC/hgOC0k2AJZdT/NGYEyrXPE5dxD4JIgQWyJ 5vuWp9aomNTuibtm+YEe/I1Q4hafuZXD4thIVFTuT7F2fD0s3rbVGuS+nGrLGEVZT/a9Pv33oZI XslRxpi0zoMYRYy80rWkTfVB2wGPhe X-Received: by 2002:a05:600c:1908:b0:493:d3c5:6c32 with SMTP id 5b1f17b1804b1-493decbf10amr4212745e9.6.1783337951887; Mon, 06 Jul 2026 04:39:11 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:39:11 -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 1/7] libcamera: software_isp: debayer_egl: Pass eglImage as parameter to setShaderVariables Date: Mon, 6 Jul 2026 12:38:54 +0100 Message-ID: <20260706113900.2530549-2-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" 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 Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- 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 56545816e..c3a7b7952 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -388,7 +388,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 @@ -444,7 +444,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: @@ -533,7 +533,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 Mon Jul 6 11:38:55 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: 27247 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 95A83C330A for ; Mon, 6 Jul 2026 11:39:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4EDAA66023; Mon, 6 Jul 2026 13:39:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="xGD4BWn7"; dkim-atps=neutral Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 60F4066030 for ; Mon, 6 Jul 2026 13:39:13 +0200 (CEST) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-47c2b362ee2so1523466f8f.1 for ; Mon, 06 Jul 2026 04:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783337953; x=1783942753; 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=sCherSufb0on4kaTY2CKoIjTcZ+GTv1qK3dt1yZ0ysg=; b=xGD4BWn7VEAW5mipZlXFi2fLOmqB5FZvNIv/5hvhZWx1OcP1SS5+0bkMoEhGkK7jEH lYYs0nSLhP+3GAVV7x/7XOChxE+YOHOLePhNsv9ME6C0bmy/6EvHUpGTKJmTVVhHhEQ6 zPeQ6BiYRGlgtHYXLGM/C64UAapU49aW6DNiEAUh79Vw1L45r58J5RyDbU1w36Owj8dC v6tPG+9CJ17saLEZkK/ESrWc98a8FXHLQp8kSmNyB5D5JmsIkaYmpJR469fiXeQXBeTD MvYHTK5N1z9VQJVaY1uKGeHeDFkGqcynOEgSHsv63G2rJrS204WoJY224o7z75Z0M2zz +FTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783337953; x=1783942753; 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=sCherSufb0on4kaTY2CKoIjTcZ+GTv1qK3dt1yZ0ysg=; b=CRk4OHs/Btlrh7wuIz4QFTokhFeqcXY/dYJ44HfHhPr50QyGFsVkJ7vfAbMMc0QlKZ V5gwu+o3K5SJOEy3wuPQSvuY2vPeDA/+KXn7Cqs80upbtllt+JcQWgjzF1RzV0Zu5fNd CSqMEVko/i3R4kbXuBTwdTLfPfPs2DnhiLK5QwSDRBIdeI25YmNtk/pfH30ZtqVcnKLU b32VMK+c0sB5bsu+X0O1fioitjHC5+Kmo9uS6TjIdWnsuo0+hpC+zE2lIN0Zz7jxWa2i RjIjdw0ylcTukNLy7xNyO3m2co7BUbOlNxduLTZeFNadO6rvTTQTQM8xlynP7ALGak/K kfew== X-Gm-Message-State: AOJu0YwAVCZAjYUtgAxVADsGECU46oxtdgDIqzxdi6c4svlofy84LWCQ mTDCQja3DXuvJwfrTufLoInwZQHvLO0NRXGV/BRyVEjDTvdP8Y92pRRhpNX2iO8AXVui8wXTA2T ujB83 X-Gm-Gg: AfdE7cmt5piq/4IbdVg6sg+kz7U/a9fBUQT3R5aVdzq1YkWcr15bdOSA+KcK0AyZQDg Idw77C3mVRAwa6u56Jn70tUyM51Ic/2k/OSRzsXFWXTkE3sxPH6S5k8zHIeFQxBmx0yi1KeL6By 9Ef3uojm5ZUc/ePzVLHqPyUgDmLftKX9NL/1lMMHPzmGWo7zNwz9gI/cvo5R4D2+Pf0tfc7+WQ3 bflOghgVzhh4PLQOd+YS1t3jM31uyaOyD7fhqtSs4aFIBILd8MZpbvA31H7L0IrqudVdH7jxgu+ C756Sjil8ldwhzYtPn286Ca4USIcqvZhCqWOyM6hwq8NI4CQog6vF74kUFq0l6e/E//MNogNN1D k9lYMuscZ8RkEBUzZcU1sLmzgWL3A3At17N5oOMGs23P0Xy68Ofur+jd/KZ2ljUrsrnLVirRxA9 8xvVpUNjNCseBPYQpHH/RHUG3xBFZo X-Received: by 2002:a05:6000:184d:b0:47d:ca2:6234 with SMTP id ffacd0b85a97d-47d0ca26431mr7636412f8f.19.1783337952677; Mon, 06 Jul 2026 04:39:12 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:39:12 -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 2/7] libcamera: egl: Add new helper attachTextureToFBO Date: Mon, 6 Jul 2026 12:38:55 +0100 Message-ID: <20260706113900.2530549-3-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" 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 Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- 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 523a62aa8..085a371f3 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 b5a5dc60b..ed67aca7b 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 Mon Jul 6 11:38:56 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: 27248 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 BBC7BC330A for ; Mon, 6 Jul 2026 11:39:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 49C4D6604D; 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="d7EZIqQq"; dkim-atps=neutral Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F05866601C for ; Mon, 6 Jul 2026 13:39:13 +0200 (CEST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-47d6c634f45so968045f8f.3 for ; Mon, 06 Jul 2026 04:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783337953; x=1783942753; 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=39/wg15FASnXwYPaNXZRuMgZsbEtqLQEwRNrqEYsJnk=; b=d7EZIqQqOoKTvNxQFXsowZcCnhvVcy1pW9TMPv7kf5OC5pycHTkl36MeVGiCrUjhYr igJV1dRennq+x+PzT0hEmaZLnykcHyFWziJuc4q7Qltn3GjL+H3IXxUsSlmYVee4iBmp u1xIH6qxF1X4zIs6rkEjYAIG3IUteSLO9Ck7XXFnIrDp16ezJIgX5rZXapscU/TEHMDf YyuarIv69S5txv63BIjwFVw5Ue5Mz9VMwO2bmMndWiWInu5k9tBnt6NlKDacJLqOwa75 aHhfgAX2GOsW7xt4dKYiOvxzvxlo754H0CIQIPzBT1oOBFwe1lWMadBB0NwBQFKL3+EM Vx6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783337953; x=1783942753; 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=39/wg15FASnXwYPaNXZRuMgZsbEtqLQEwRNrqEYsJnk=; b=A1Jt+hKcY6YWW1WO2o5+9IM0DyHsFd8gJVjY1aehComCwaRlMoUA8yga+CZ2wvxq/P G8x9YI/q9GcfinTCVU89/Hkm+26f0eoP0Imapzri3XYkyPa24jDEtyAnbutpMhTiDZiy Q82wKJp7YaNvv+k7kCwdzYKBtYQljHkCG8zyVT+joOE2xDidjj9aMm1o+TKS5dDCGK9s qBrQ8YvNFizPZurwkghSPx7x8Y4eVuOCUwp6M2TjBMh6mLvUOyj7YHpFus1BqA5QZ80l MtWH6DPF7K/2BB45XhtIR9dL5mQ9whyPbent9Xtfgz+bk2O4gz+4vGrXbXRsuxa9kgAd 9CpA== X-Gm-Message-State: AOJu0YxSUtt2zB2Ait4K/CofDOtAgKjDDlPnK8q0FQ/9DmpuQxsX9dhe 7AG/uQHcV2BWiQQcpgRMtp7fqJI3HwzV7cziszsWPkwFMS0aQ1jG/u/gJZv9Ed7daKy/nkGckaN /+oNt X-Gm-Gg: AfdE7clWcJefh6vBZa7hyct0K/EqqN9/XjEmraohGwRtfGqlwjUAffZDSPIJWDXE8w+ U9BFk0P/MiDdJciY9VJGnNJ0AlScU0vMXOMC9cHS3fN7nnTa3QDRcvoS3uUeqRBlGQhQGsk7PYZ X/xeQoJkD1xM0A2rP7/EADv6RUS7SknhmPeV8w3oZxHbsCZ0Do4aXkcrrb7hSMk/GY+8e8EEE/J 9GSZ2uUtKITyQwA0kGJgAu7Qg5VWL7mEM8ag2SVhW1rdAA62rnbgWkOIoTwuFeB1CzWYm2JTOvR X9o9dp9xswb3fnNWFV/MUyZUbGUME1xZlnLlPx27SJKZLzuca7LIUFO8B87ZZqGfmDjjEzn5mt9 KScG/KAoQe+zDCgnQuY7xCf4jpjzzXkKLEWHR9UzVKsvAbwl61HbjSXjtSBmIZrvx7OtZXDXSzv J78/zFK0YIKNiRoRwggD5YC0NxQpqm X-Received: by 2002:adf:f00f:0:b0:475:f0c2:5b04 with SMTP id ffacd0b85a97d-47aad54d643mr8112013f8f.58.1783337953466; Mon, 06 Jul 2026 04:39:13 -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.12 (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, Milan Zamazal Subject: [PATCH v5 3/7] libcamera: egl: Add createOutputTexture2D Date: Mon, 6 Jul 2026 12:38:56 +0100 Message-ID: <20260706113900.2530549-4-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" Creates a non-dmabuf texture attached to a frame-buffer-object FBO, which allows for render-to-texture. Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- 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 085a371f3..1955d09c5 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 ed67aca7b..c1b5514b6 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. Subsequetly 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 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); From patchwork Mon Jul 6 11:38:58 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: 27250 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 CB512C330A for ; Mon, 6 Jul 2026 11:39:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 91E9966030; Mon, 6 Jul 2026 13:39:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Mnreu3TL"; dkim-atps=neutral Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9CFBA6600A for ; Mon, 6 Jul 2026 13:39:15 +0200 (CEST) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-4720f3bf164so1931706f8f.1 for ; Mon, 06 Jul 2026 04:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783337955; x=1783942755; 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=/B6GIAyW48ah9/xcsZgbpJ85k5AYURJJX6RMJWKLdbo=; b=Mnreu3TLiDs8ZvIuEMr6OSDGSkTCkLGdpQ3IIQUtPpuhCrFyxgok0DzMma9wVhy8Vs JBaeieSx1cjeKeW42dYqZ96xILBraSjGV9sRrRSOosADd4A4f2GRbfVVXrKRWHUzV+XD N3Fwzv5nGfbbWDoIT3Hy0ODjdZj16l26S2qUX2xOCxke2dxdsOE6wcshMZt1ODf4T7BC r4YfZhRVbD836t4yMFXtigcrgbAZTDAIkI1/11eGc0gAkiAFa3f22LqBlnBUKi9GTBV0 c6d/FasqvDLV9YEoq/WRGYdUxoN3iwvjB0YZ3EE4oOrZOYZfkSB+0yPI+xCpY9OjlJAi rzug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783337955; x=1783942755; 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=/B6GIAyW48ah9/xcsZgbpJ85k5AYURJJX6RMJWKLdbo=; b=N/TFLUAMX1Qc0HtYWR/1tnnNuAPojaxLRzuVgVEFv6Q0NFYgNDk3ED7vVKgsDfmZm/ ed3zKu3Y0FBey3GU50pZur+DFnfjTZO0dCIehUJwjvb3Zogc99Hzic/ylvqGV3hzEX4f P40nuedEvmvRnwzSr7ldeZ8nGETFDrDalLzxYciKlv1iC+RA0Fi7XtPPhOp1VC54j97/ fEr7/XI2eaWTy8uvQM9iCXGepISW5QE4C3vOxKVAFoheEZFAXi2CwKrMOrePO2KnLtO2 T//8sn/2AuMxS68wwbc8/tmyQj21XiV3Viep+a7NozONlkdyO6tS69VWdp7adkwl3gyE 0IOw== X-Gm-Message-State: AOJu0Yzyr83SCbmaAdBlkIMz3cbtuS2Cw39TkIPwb8vaQSdAPMFD5zbW kjS2zD8TgdUMimjnK3pNy01O4erwQIqpJs0PPaVuUr8SJp03zGg4yda00tMi0w29tiBLtLbQBJa M+Gk0 X-Gm-Gg: AfdE7cnsInnuJLHWdmekGQxXuxJBp3EWwQEciYJK+KfYAtjM2qSUpkDrA8xuQSXEYof RDYQkxqpy8zb92+2V165Sx3PnXj6fy5SWv/5IDyKzrS9R/SVk/12xDcVurlpUQUqAUq2H1DfWVz ELbxDEEbctCmhS+eJbYzfpd0e44tgUyAxFryZroGFqdGMmqya5Q7PKzjJ4zzhyg6xNx5pjcy5kd tkl3z4JyyLH4O+jt3gkFCNXBz4vp1ybNRlPpiavsqH+H4cy4Hlff3QaY0poixibiXvN0KnhntOF irR0Vv4CKzOin0YzlX8PkRLHZ++LSOoJj1F+3qySPU3QDbbJWP9LrMAB1qOY3/mMjJFfNYiQsfp slP4DJVr4HGzzcRapxv17ziv34TbRUSx8EHCuZkWudrDZ0sOYXf7EfgE57O3X5vU6+5KJMq/iho +p6WPhCXrmzlKpBXLrQ2vzozSL4YSd X-Received: by 2002:adf:f84e:0:b0:474:a0a3:df0c with SMTP id ffacd0b85a97d-47de6173bb0mr369642f8f.10.1783337955185; Mon, 06 Jul 2026 04:39:15 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:39:14 -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 5/7] libcamera: egl: Add updateTexture2D Date: Mon, 6 Jul 2026 12:38:58 +0100 Message-ID: <20260706113900.2530549-6-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" 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 Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 64196213a..1e31d490b 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 0726b63f2..7ec7a654d 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -343,6 +343,23 @@ 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) +{ + ASSERT(tid_ == Thread::currentId()); + + activateBindTexture(eglImage); + + // Update an already existing texture + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, eglImage.width_, eglImage.height_, eglImage.format_, GL_UNSIGNED_BYTE, 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 Mon Jul 6 11:38:59 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 27251 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 8AC8DC330F for ; Mon, 6 Jul 2026 11:39:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4954666031; Mon, 6 Jul 2026 13:39:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="kJknxjPB"; dkim-atps=neutral Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B1F136600A for ; Mon, 6 Jul 2026 13:39:16 +0200 (CEST) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-4703bc0a99aso1579564f8f.3 for ; Mon, 06 Jul 2026 04:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783337956; x=1783942756; 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=iBRWJUBS/Uq8NB/fn6jxhZu1bX+RaDP4LLlVacS3Kt8=; b=kJknxjPBBPUXDRJVtWLj9UPfx0c6GtDN34wHMUVbnR1lF3+j/S8MwMxFvWXNxuYDjQ w9H9cXZ87m/RrndEZxqR8RYmu9kk7qopDwUr4mD64kLjEPZFzskuOhxaicG/wVldwEZO sjUs5GoNGAhrYvdX7+CQNPZ20M0uieyZ3vpZuDZzfRgFouS/qcK+teT64IPHMCLRALF0 sIlZEoi8wcimZyGrr3eN5AdU0yNlq0DXur1K8kaN2TACbGJTbcLVlw4qrpqXJj1BYAeu LeB8ktKMP85qwuD6pjyod6i8VuVTrNf5FZ7zT4yBMKws5X332Y1gMBAya7bX+AKcYggh SZ6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783337956; x=1783942756; 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=iBRWJUBS/Uq8NB/fn6jxhZu1bX+RaDP4LLlVacS3Kt8=; b=mflwEr9nVdeEZBFBqIboLkWBCFzRb+wbuSeC3mO6QuYqwXLSDolnHy2bJm505q1Bor iA2NJ6pGt7w1OzzdOlngXytIMr0Xc4IOXCbgP5r36Z1CawPgAziGiDHrllBDOaKc7lfL 2zuuiVDwWEjRmC78eH36KMxVBJmure2VhomabnmL2+vXAeUt88c+eQ/fufHndZ8xE3+s ORctZNktFZTu1J8Xsw/k+DQfVBBGJ80Ox/ROhCdXPcK5/tm0H0DoGknj1tKHS0BjtWr1 aNSV5LFK7ldzsKem+iG0bsvin32WIbIb01qAJoOma9IU7q1EXgna6jJaQqrtT0wIBU2Y /M1w== X-Gm-Message-State: AOJu0YzliBdALzRP+BH7NoDT+EbvZJEjlI7iSpWOohLYV7ucB6XlV8Kg ieUekxaZrxeDF5XB7fjnWumVMed7ATHlXU0UU6D+xgkMjArc8+ow55MKjhT1nmzI1voi+tN4UK6 Lpohu X-Gm-Gg: AfdE7cmQH20s+fd/09bDOMkieKUf74f0/xB/69BWyvEIajcfF8BYWWd7alArnvsiZts HmXVE7K7OOST7PM697/fk36PqVCjB/2viYBwR5go3dJGfNbHBp8M43FLGY7ZAlCHHY1TMD9G/h8 3DtPcLcMDhXuHmsgJ1hRV8jLilj7vdwCgG346zyRSHcGh/RdxnoiOYBr8FXXty7CsXiwf5WxA37 1BuK3OHUZf0nhKq0NXIienYHbKjK4DUWSABLhuNzX+6Uy6zW428yRxq4DLtk2xvCHBUt0vACrQb XuUG0vc1jDUoyPCfoK9rqLVHmloX5pMX1FhK/OIBYbm7zRPIYh65vPOewdaek4bYSUsbq5h6/rE L6TDeUwpK8pVD0auKSXvOO8V95wTupVGYtfIGM7zLINd1TrGSVlej8XYGjHafyVBuJJr5qjMcWy DsuN/Iv37rfhc76ePGBgOcD301ABRQ X-Received: by 2002:a05:6000:29d3:b0:472:67de:27c2 with SMTP id ffacd0b85a97d-47aab76fe87mr7454974f8f.40.1783337956188; Mon, 06 Jul 2026 04:39:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:39:15 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz, Robert Mader , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v5 6/7] libcamera: base: shared_fd: Add hash template Date: Mon, 6 Jul 2026 12:38:59 +0100 Message-ID: <20260706113900.2530549-7-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" From: Robert Mader Suggested-by: Barnabás Pőcze Signed-off-by: Robert Mader Signed-off-by: Bryan O'Donoghue --- Documentation/Doxyfile-common.in | 2 ++ include/libcamera/base/shared_fd.h | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/Documentation/Doxyfile-common.in b/Documentation/Doxyfile-common.in index f11ec593d..c0696496c 100644 --- a/Documentation/Doxyfile-common.in +++ b/Documentation/Doxyfile-common.in @@ -75,3 +75,5 @@ PREDEFINED = __DOXYGEN__ \ @PREDEFINED@ HAVE_DOT = YES + +BUILTIN_STL_SUPPORT = YES diff --git a/include/libcamera/base/shared_fd.h b/include/libcamera/base/shared_fd.h index 61fe11c1d..65b1044c7 100644 --- a/include/libcamera/base/shared_fd.h +++ b/include/libcamera/base/shared_fd.h @@ -7,6 +7,7 @@ #pragma once +#include #include namespace libcamera { @@ -57,3 +58,11 @@ static inline bool operator!=(const SharedFD &lhs, const SharedFD &rhs) } } /* namespace libcamera */ + +template<> +struct std::hash : private std::hash { + auto operator()(const libcamera::SharedFD &x) const noexcept + { + return std::hash::operator()(x.get()); + } +}; From patchwork Mon Jul 6 11:39:00 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: 27252 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 5DEF1C330A for ; Mon, 6 Jul 2026 11:39:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3E4DF66045; Mon, 6 Jul 2026 13:39:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="HmFJWVuh"; dkim-atps=neutral Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 96D7A6604A for ; Mon, 6 Jul 2026 13:39:17 +0200 (CEST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-4720d22c94aso2906527f8f.1 for ; Mon, 06 Jul 2026 04:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783337957; x=1783942757; 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=iBp5CTAibDRDjJr1C9jbaznxXxt4zBdSgPR4F1nm75g=; b=HmFJWVuhbGyJquuQK/joVOlkIPjew1VpWH6+JUqGSdF6EgsOXwsT8419HeUYqryWkw GdmlxoPqXHEmrhdDZLWsLaDdLsWYWUqwwzyaruL8mjFP22oZYa6UnSdG870SoSqemngq 5v/Hf7aAMib1q/fLJnz0cBxWOIxSK816lNSuaQTeVrgwp04p4sFqvgy+8Mk/qwN2kAM2 6X95egt6CI2x8JrPs6fbqnRkuJmYySLIX4Ao9109xAN6HlN1m3Giov1LNtJc88yQPG8L X5lX7bvdPQFrpPYYTsQjRQDxuPYL5KQS5lrdQKXnVhk3lV7M/jPc5K3x71kscUQc2/Ig Bgfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783337957; x=1783942757; 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=iBp5CTAibDRDjJr1C9jbaznxXxt4zBdSgPR4F1nm75g=; b=Mu7lYbT4TeLK2IsZUktBMmthlD/JpWke7ciI4wedYEplz/Wjpv+031jSSC9k2SUIIu X+GFzOb54mtAMWsDHqJu2SRDnc+WZxq2NoSh7QzF7jhZwNtRc4NAlQkxmaCBfihQUulg myJm10UYCO/D5IUOZpJ9DHu3y4AHKy9ExhAG5AeJbC1KMcYGlZJu+cXg0GGOJiV4mOy0 hsfXM4nwHKukbdx2XFyCMUZ1CE3i9dDA78qHiiG+F9FA/j7cuhLHZM81voSnPJjvjO5J +8xDixUhCKVvoGfSDJ9Xf6M2n8Z5wpWHwZjPWsw2IhjQ5BhSzVDdn0wutNQwuyFamcnD TFXg== X-Gm-Message-State: AOJu0YyPylEy9Rm+mulX3YbxDyEbBU0JsQdwoyBlcilsX7GaskfBx1KW 2gLp2nT+NONsfs3JfFNgktB1PEa5tf/yY36XOgjTjWwFkLDg2tUxdAfaChDgVqlMk/OgeEzHgDv WfOew X-Gm-Gg: AfdE7cl8uacFh14r0yBhOEi7IL/w4cT1S+DFnTvs8lBh6vcj6X0UGnejdopMolRCcxy haZpck6GVJ6RyC7Z3XqYfgmJzxgv6ngGZeICBf2//AhGBYseB0oWxYYwH5KDNcv9bqBD5tjb9dF KJ+KOkOdFw3P+TpiY+Rn3kUCnNbRMX882yH4BkHmT6cVCsjaX2033RkakN6SBE/XTovTBTud4Of 3szPUDCIedksLou4I6StX3a2QLFte/X4UKK6+smxn69uHNk+kspHlzGUVppbaNsSqg2u8CNhKAG idxre5Rd46gln+wRj4YgDVWzbW+kaeqaLd7LpubxTLM0rtrxBI7711RXfhk72/lPECuneE473Q7 8vfHMW+PIXPKZGZtZKGTYhId54M6XDguizt6kmr7y3P1SNiHUtYnJLqkpkO9MChVC8VAt635HBs 2LQfDqZqeDm05pOIbLjuGRFWyQ4e12MFRfllHHFfI= X-Received: by 2002:a05:6000:188a:b0:467:f84c:4ca0 with SMTP id ffacd0b85a97d-47aaaada7d2mr10692693f8f.22.1783337957027; Mon, 06 Jul 2026 04:39:17 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 04:39:16 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH v5 7/7] libcamera: software_isp: debayer_egl: Implement input/output frame caching mechanism Date: Mon, 6 Jul 2026 12:39:00 +0100 Message-ID: <20260706113900.2530549-8-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" 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 --- src/libcamera/software_isp/debayer_egl.cpp | 112 ++++++++++++++++----- src/libcamera/software_isp/debayer_egl.h | 13 ++- 2 files changed, 96 insertions(+), 29 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index c3a7b7952..ca3353d9f 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -345,6 +345,9 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, */ stats_->setWindow(Rectangle(window_.size())); + inputBufferCount_ = inputCfg.bufferCount; + outputBufferCount_ = outputCfg.bufferCount; + return 0; } @@ -504,36 +507,95 @@ 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) { - 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 - LOG(Debayer, Info) << "Importing input buffer with DMABuf import failed, falling back to upload"; + const SharedFD &fd = input->planes()[0].fd; + bool use_dmabuf = false; + + auto [input_cache, cache_miss] = eglImageBayerIn_.try_emplace(fd); + if (cache_miss) { + if (eglImageBayerIn_.size() > inputBufferCount_) { + eglImageBayerIn_.erase(inputRing_.front()); + inputRing_.pop_front(); + LOG(Debayer, Error) << "Input cache " << inputBufferCount_ << " exceeded evicted entry"; + } + input_cache->second = std::make_unique(glFormat_, inputConfig_.stride / bytesPerPixel_, + height_, inputConfig_.stride, GL_TEXTURE0, 0); + inputRing_.push_back(fd); + } + eGLImage *eglImageIn = input_cache->second.get(); + + /* Try to create texture for input buffer via dmabuf import only on cache miss */ + if (cache_miss) { + if (egl_.createInputDMABufTexture2D(*eglImageIn, input->planes()[0].fd.get()) == 0) + use_dmabuf = true; + } else if (!eglImageIn->dmabuf_import_failed_) { + use_dmabuf = true; + egl_.activateBindTexture(*eglImageIn); } - /* 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()) { LOG(Debayer, Error) << "mmap-ing buffer(s) failed"; - return -ENODEV; + if (cache_miss) { + eglImageBayerIn_.erase(input_cache); + inputRing_.pop_back(); + } + return nullptr; + } + if (cache_miss) + egl_.createTexture2D(*eglImageIn, inMapped->value().planes()[0].data()); + else + egl_.updateTexture2D(*eglImageIn, inMapped->value().planes()[0].data()); + } + + return eglImageIn; +} + +eGLImage *DebayerEGL::getCachedOutputFrameBuffer(FrameBuffer *output) +{ + const SharedFD &fd = output->planes()[0].fd; + + auto [output_cache, cache_miss] = eglImageBayerOut_.try_emplace(fd); + if (cache_miss) { + if (eglImageBayerOut_.size() > outputBufferCount_) { + eglImageBayerOut_.erase(outputRing_.front()); + outputRing_.pop_front(); + LOG(Debayer, Error) << "Output cache " << outputBufferCount_ << " exceeded evicted entry"; } - egl_.createTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data()); + output_cache->second = std::make_unique(GL_RGBA, outputSize_.width, + outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); + if (egl_.createOutputDMABufTexture2D(*output_cache->second, output->planes()[0].fd.get())) { + eglImageBayerOut_.erase(output_cache); + return nullptr; + } + outputRing_.push_back(fd); } + 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(); - /* Generate the output render framebuffer as render to texture */ - egl_.createOutputDMABufTexture2D(*eglImageBayerOut_, output->planes()[0].fd.get()); + 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); @@ -615,19 +677,15 @@ 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(); + outputRing_.clear(); + inputRing_.clear(); if (programId_) glDeleteProgram(programId_); diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index 348d7305b..dde6ba9bf 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -9,9 +9,11 @@ #pragma once +#include #include #include #include +#include #include #define GL_GLEXT_PROTOTYPES @@ -68,14 +70,21 @@ private: void setShaderVariableValues(eGLImage &eGLImageIn, const DebayerParams ¶ms); int debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *mappedInputBuffer, std::optional *inputBufferDmaSyncer); + 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_; + std::deque inputRing_; + std::deque outputRing_; + unsigned int inputBufferCount_; + unsigned int outputBufferCount_; /* Shader parameters */ float firstRed_x_;