From patchwork Mon May 18 20:15:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 26769 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 AC3ADBDCBD for ; Mon, 18 May 2026 20:16:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 63E3563026; Mon, 18 May 2026 22:16:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=robert.mader@collabora.com header.b="iUKxw+E4"; dkim-atps=neutral Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3518162FE1 for ; Mon, 18 May 2026 22:16:17 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1779135372; cv=none; d=zohomail.com; s=zohoarc; b=fRnNaFoHnb5FjIWue8PrJQB83z/vza4Fli0Ztzs+xZ8lEo2vKsCX5XKySyXC5b1oZAUjAI4x6n4eDU0jFZYZp3b2MQ2kpGV9ngYSC/H7snLS8vowdejcE3g76dBSXzulibFgLr6m47AzWt2Y8qGvRMkUFcMwXgmPj6KAVSNXmBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779135372; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=RctL3Zn3g/C7zA8lhPhIkstnVNimymWPBcHt6xePCKY=; b=dQfXpwBbTp+fIXoD1x1YGqTkWKZ6gB4sEWSxJL/E1abK7j703ggJW8d8iidblEnmAikZxRuLdgmKInWIKe7Vt9fJrX+GVvFWj/N9mPb1aUBaT3rTO6eI8lZ21w5RaP3hu3OHgYCOdw2Cmi78vN6t7SOIbXP33ijFLg2VUu4QjdM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=robert.mader@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1779135372; s=zohomail; d=collabora.com; i=robert.mader@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=RctL3Zn3g/C7zA8lhPhIkstnVNimymWPBcHt6xePCKY=; b=iUKxw+E4SDKkD4aQLjVVgvn9qTvKT/XSPyZCC1/FnYMKxsmtHGVE5N7fHgm45Q88 JjSt0Y84Cz1RWYP9M07Yrag6vmJcqEqu8j2CdzU+jK8gAdtWO0eBWkm3RvPWqZkNNUo hEfesU9RjvWQZ92gC10l2w1pcT7LEmmUf64Za/Vw= Received: by mx.zohomail.com with SMTPS id 1779135370420773.2495325728922; Mon, 18 May 2026 13:16:10 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v2 1/4] egl: Set more eGLImage paramters in constructor Date: Mon, 18 May 2026 22:15:05 +0200 Message-ID: <20260518201508.140849-2-robert.mader@collabora.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260518201508.140849-1-robert.mader@collabora.com> References: <20260518201508.140849-1-robert.mader@collabora.com> 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 parameters - format, width, height and stride - never change. Set them during construction and remove them from createTexture2D(), making the later match createInputDMABufTexture2D() and createOutputDMABufTexture2D(). Signed-off-by: Robert Mader --- include/libcamera/internal/egl.h | 7 +++--- src/libcamera/egl.cpp | 29 +++++++++++++++++----- src/libcamera/software_isp/debayer_egl.cpp | 12 ++++----- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 0ad2320b1..8d80d6fb5 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -57,8 +57,8 @@ public: * \param[in] texture_unit OpenGL texture unit * \param[in] texture_unit_uniform_id Shader uniform ID */ - eGLImage(uint32_t width, uint32_t height, uint32_t stride, GLenum texture_unit, uint32_t texture_unit_uniform_id) - : width_(width), height_(height), stride_(stride), + eGLImage(GLint format, uint32_t width, uint32_t height, uint32_t stride, GLenum texture_unit, uint32_t texture_unit_uniform_id) + : format_(format), width_(width), height_(height), stride_(stride), framesize_(stride * height), texture_unit_uniform_id_(texture_unit_uniform_id), texture_unit_(texture_unit) @@ -79,6 +79,7 @@ public: glDeleteTextures(1, &texture_); } + GLint format_; uint32_t width_; /**< Image width in pixels */ uint32_t height_; /**< Image height in pixels */ uint32_t stride_; /**< Row stride in bytes */ @@ -103,7 +104,7 @@ public: int createInputDMABufTexture2D(eGLImage &eglImage, int fd); int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); - void createTexture2D(eGLImage &eglImage, GLint format, uint32_t width, uint32_t height, void *data); + void createTexture2D(eGLImage &eglImage, void *data); void pushEnv(std::vector &shaderEnv, const char *str); void makeCurrent(); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 357918711..b8f5d9b85 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include #include #include @@ -111,13 +113,31 @@ void eGL::syncOutput() */ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) { + EGLint drm_format; + ASSERT(tid_ == Thread::currentId()); + switch (eglImage.format_) { + case GL_RED: + case GL_LUMINANCE: + drm_format = DRM_FORMAT_R8; + break; + case GL_RG: + drm_format = DRM_FORMAT_RG88; + break; + case GL_RGBA: + drm_format = DRM_FORMAT_ARGB8888; + break; + default: + LOG(eGL, Error) << "unhandled GL format"; + return -ENODEV; + } + // clang-format off EGLint image_attrs[] = { EGL_WIDTH, (EGLint)eglImage.width_, EGL_HEIGHT, (EGLint)eglImage.height_, - EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888, + EGL_LINUX_DRM_FOURCC_EXT, drm_format, EGL_DMA_BUF_PLANE0_FD_EXT, fd, EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, EGL_DMA_BUF_PLANE0_PITCH_EXT, (EGLint)eglImage.stride_, @@ -207,9 +227,6 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd) /** * \brief Create a 2D texture from a memory buffer * \param[in,out] eglImage EGL image to associate with the texture - * \param[in] format OpenGL internal format (e.g., GL_RGB, GL_RGBA) - * \param[in] width Texture width in pixels - * \param[in] height Texture height in pixels * \param[in] data Pointer to pixel data, or nullptr for uninitialised texture * * Creates a 2D texture from a CPU-accessible memory buffer. The texture @@ -217,7 +234,7 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd) * is useful for uploading static data like lookup tables or uniform color * matrices to the GPU. */ -void eGL::createTexture2D(eGLImage &eglImage, GLint format, uint32_t width, uint32_t height, void *data) +void eGL::createTexture2D(eGLImage &eglImage, void *data) { ASSERT(tid_ == Thread::currentId()); @@ -225,7 +242,7 @@ void eGL::createTexture2D(eGLImage &eglImage, GLint format, uint32_t width, uint glBindTexture(GL_TEXTURE_2D, eglImage.texture_); // Generate texture, bind, associate image to texture, configure, unbind - glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data); + glTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, eglImage.format_, GL_UNSIGNED_BYTE, data); // Nearest filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index eae4c57f4..a217e3798 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -506,7 +506,7 @@ int DebayerEGL::debayerGPU(MappedFrameBuffer &in, int out_fd, const DebayerParam egl_.makeCurrent(); /* Create a standard texture input */ - egl_.createTexture2D(*eglImageBayerIn_, glFormat_, inputConfig_.stride / bytesPerPixel_, height_, in.planes()[0].data()); + egl_.createTexture2D(*eglImageBayerIn_, in.planes()[0].data()); /* Generate the output render framebuffer as render to texture */ egl_.createOutputDMABufTexture2D(*eglImageBayerOut_, out_fd); @@ -582,14 +582,14 @@ int DebayerEGL::start() LOG(Debayer, Debug) << "Available fragment shader texture units " << maxTextureImageUnits; + if (initBayerShaders(inputPixelFormat_, outputPixelFormat_)) + return -EINVAL; + /* Raw bayer input as texture */ - eglImageBayerIn_ = std::make_unique(width_, height_, inputConfig_.stride, GL_TEXTURE0, 0); + eglImageBayerIn_ = std::make_unique(glFormat_, inputConfig_.stride / bytesPerPixel_, height_, inputConfig_.stride, GL_TEXTURE0, 0); /* Texture we will render to */ - eglImageBayerOut_ = std::make_unique(outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); - - if (initBayerShaders(inputPixelFormat_, outputPixelFormat_)) - return -EINVAL; + eglImageBayerOut_ = std::make_unique(GL_RGBA, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); return 0; } From patchwork Mon May 18 20:15:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 26771 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 DDB3CBDCBD for ; Mon, 18 May 2026 20:16:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E3EAA63022; Mon, 18 May 2026 22:16:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=robert.mader@collabora.com header.b="HIdkTA/u"; dkim-atps=neutral Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B85B86301A for ; Mon, 18 May 2026 22:16:17 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1779135374; cv=none; d=zohomail.com; s=zohoarc; b=AwTvJbePTtgR9jzYyKA+ScQSZaRo3uk3ibGm2eUcdggHVi0UTJW8Q9KE/kfd/HM7L1tEQ4g2+dtto1ZQ7TBSo2P571R9RadLiWhVdqIAGdzwnJTq5xazYkVGomkse7nHQPAdkxjDzgTSnuy9IDqvXmuBg6rS1bUeZeqmm8rbu+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779135374; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=4UMKQQTRIGXANS/drfnj5pP4GKU12zBy8r6tXB+Yz/M=; b=AAS4SFWMdvJ3PKhCGmx02+d7wCnZAyRsLF4WcdSWvJ5qT0nruX7SDRCwC672o03xqX36j5hD71/fSaULhRqth8d5YgF31Y6kFdoQkYnRhsszsqlqlHoNNxUeMaa1hNOLG80sjsxdY67InSKsxzU7Skqs2RJjS32S7j3oYknDztE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=robert.mader@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1779135374; s=zohomail; d=collabora.com; i=robert.mader@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=4UMKQQTRIGXANS/drfnj5pP4GKU12zBy8r6tXB+Yz/M=; b=HIdkTA/urwewgD85gF3Xb3sNhTZiCLQfuETlgiczV5CEzIk/5tuMkggcubPjhtxI upDp3IFFRwzsHarAlZ4lX3DFCA4p6YzvDxjrmwwksn+6EXoVY8c53cS8ZhwEmnYn2mS XmUCn78/NJ96VXIFD7ucb83lYdCK0OuYbv1u7Vxo= Received: by mx.zohomail.com with SMTPS id 1779135371957487.08478252564714; Mon, 18 May 2026 13:16:11 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v2 2/4] egl: Demote an error log to debug Date: Mon, 18 May 2026 22:15:06 +0200 Message-ID: <20260518201508.140849-3-robert.mader@collabora.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260518201508.140849-1-robert.mader@collabora.com> References: <20260518201508.140849-1-robert.mader@collabora.com> 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" In order to avoid flodding logs in cases where import failure is an expected result. Signed-off-by: Robert Mader --- src/libcamera/egl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index b8f5d9b85..df4eec757 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -152,7 +152,7 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) NULL, image_attrs); if (image == EGL_NO_IMAGE_KHR) { - LOG(eGL, Error) << "eglCreateImageKHR fail"; + LOG(eGL, Debug) << "eglCreateImageKHR fail"; return -ENODEV; } From patchwork Mon May 18 20:15:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 26770 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 E3CFCC32F4 for ; Mon, 18 May 2026 20:16:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1B04663030; Mon, 18 May 2026 22:16:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=robert.mader@collabora.com header.b="PNFt2HX3"; dkim-atps=neutral Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 66AAB62FEC for ; Mon, 18 May 2026 22:16:17 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1779135374; cv=none; d=zohomail.com; s=zohoarc; b=BoI6IYUyGmA6C3yKidp4zEIpJ9mn6zjMSTeH3NJ9mQntgPbiRnmLJxU7xUIbkm2hkWAktkMZDgOaUptb/2bk/7Jm0k73vjdQRC58Io+Vo8wk9MdP7Ot7W+mUb32Qv440tqtYhuVsnATLcQZOlV/Iuj669lvy8HegfFR254zmzQk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779135374; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=hTPfehAIGuGVuZradoz4Gns7kWlYb3dOc1wahtblfyQ=; b=btEmtU0AuB3fjHxrO+RdlpqN7+N4PI8Xh9jk167NkIjQDnHgimLk4HOkDB16K35DhRtsP+VbNwa13KOtqUSFY2TWN9VZZF3lFZjtBAnBkKP715MnaH9yOrRPJLPZn7WspPq8z3po0pTny14XsARPJm6vQXXUZQ2gd88483S7/w0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=robert.mader@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1779135374; s=zohomail; d=collabora.com; i=robert.mader@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=hTPfehAIGuGVuZradoz4Gns7kWlYb3dOc1wahtblfyQ=; b=PNFt2HX3I81vw2CZ6xAa+izmZ7EMbacpYhVl66gu9fDm08yGeYSQYlRSOVK5VSyv qNaI1SWd8vicAefXC5ElxNp+jx/Ry4wtZJakIrpTFHphAQ+MEH7QtqpeVOH/b/QWToo vpOnMmzKS+jyqg58pHWJn6XUEIFv7bV1iyyU0Ch8= Received: by mx.zohomail.com with SMTPS id 1779135373467224.49950436502218; Mon, 18 May 2026 13:16:13 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v2 3/4] debayer_egl: Implement dmabuf import for input buffers Date: Mon, 18 May 2026 22:15:07 +0200 Message-ID: <20260518201508.140849-4-robert.mader@collabora.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260518201508.140849-1-robert.mader@collabora.com> References: <20260518201508.140849-1-robert.mader@collabora.com> 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" In many cases we can import the GPU-ISP input buffers, dmabufs from v4l2, directly into EGL instead of mapping and uploading - i.e. copying - them. Doing so can have positive effects in multiple areas, including reducing memory bandwidth and CPU usage, as well as avoiding expensive dmabuf syncs and syscalls. The main reason direct imports may not work are the more demanding stride alignment requirements many GPUs have - often 128 or 256 bytes - compared to ISPs - apparently often closer to 32 bytes. Thus we first try to import buffers directly and - if that fails - fall back to the previous upload path. Failing imports should come at low cost as drivers know the limitations and can bail out early, without causing additional IO or context switches. In the future we might be able to request buffers with a matching stride from v4l2 drivers in many cases, making direct import the norm instead of a hit-or-miss. An optional kernel API for that exists, but doesn't seem to be implemented by any driver tested so far. While on it, add some minor code adjustments to make it easier to follow. Signed-off-by: Robert Mader --- src/libcamera/software_isp/debayer_egl.cpp | 32 ++++++++++++---------- src/libcamera/software_isp/debayer_egl.h | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index a217e3798..e5a661d2c 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -500,16 +500,26 @@ void DebayerEGL::setShaderVariableValues(const DebayerParams ¶ms) return; } -int DebayerEGL::debayerGPU(MappedFrameBuffer &in, int out_fd, const DebayerParams ¶ms) +int DebayerEGL::debayerGPU(FrameBuffer *input, std::optional *inputBufferDmaSyncer, FrameBuffer *output, const DebayerParams ¶ms) { /* eGL context switch */ egl_.makeCurrent(); /* Create a standard texture input */ - egl_.createTexture2D(*eglImageBayerIn_, in.planes()[0].data()); + if (egl_.createInputDMABufTexture2D(*eglImageBayerIn_, input->planes()[0].fd.get()) != 0) { + LOG(Debayer, Debug) << "Importing input buffer with DMABuf import failed, falling back to upload"; + + inputBufferDmaSyncer->emplace(input->planes()[0].fd, DmaSyncer::SyncType::Read); + MappedFrameBuffer in(input, MappedFrameBuffer::MapFlag::Read); + if (!in.isValid()) { + LOG(Debayer, Error) << "mmap-ing buffer(s) failed"; + return -ENODEV; + } + egl_.createTexture2D(*eglImageBayerIn_, in.planes()[0].data()); + } /* Generate the output render framebuffer as render to texture */ - egl_.createOutputDMABufTexture2D(*eglImageBayerOut_, out_fd); + egl_.createOutputDMABufTexture2D(*eglImageBayerOut_, output->planes()[0].fd.get()); setShaderVariableValues(params); glViewport(0, 0, width_, height_); @@ -531,23 +541,15 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output { bench_.startFrame(); - std::vector dmaSyncers; - - dmaSyncBegin(dmaSyncers, input, nullptr); - /* Copy metadata from the input buffer */ FrameMetadata &metadata = output->_d()->metadata(); metadata.status = input->metadata().status; metadata.sequence = input->metadata().sequence; metadata.timestamp = input->metadata().timestamp; - MappedFrameBuffer in(input, MappedFrameBuffer::MapFlag::Read); - if (!in.isValid()) { - LOG(Debayer, Error) << "mmap-ing buffer(s) failed"; - goto error; - } + std::optional inputBufferDmaSyncer; - if (debayerGPU(in, output->planes()[0].fd.get(), params)) { + if (debayerGPU(input, &inputBufferDmaSyncer, output, params)) { LOG(Debayer, Error) << "debayerGPU failed"; goto error; } @@ -557,8 +559,10 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output metadata.planes()[0].bytesused = output->planes()[0].length; /* Calculate stats for the whole frame */ + if (!inputBufferDmaSyncer && (frame % SwStatsCpu::kStatPerNumFrames) == 0) + inputBufferDmaSyncer.emplace(input->planes()[0].fd, DmaSyncer::SyncType::Read); stats_->processFrame(frame, 0, input); - dmaSyncers.clear(); + inputBufferDmaSyncer.reset(); outputBufferReady.emit(output); inputBufferReady.emit(input); diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index 141fb288f..a98a8139a 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -65,7 +65,7 @@ private: int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat); int getShaderVariableLocations(); void setShaderVariableValues(const DebayerParams ¶ms); - int debayerGPU(MappedFrameBuffer &in, int out_fd, const DebayerParams ¶ms); + int debayerGPU(FrameBuffer *input, std::optional *inputBufferDmaSyncer, FrameBuffer *output, const DebayerParams ¶ms); /* Shader program identifiers */ GLuint vertexShaderId_ = 0; From patchwork Mon May 18 20:15:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 26772 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 066C7C32F4 for ; Mon, 18 May 2026 20:16:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AECCC63025; Mon, 18 May 2026 22:16:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=robert.mader@collabora.com header.b="hponlkvw"; dkim-atps=neutral Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 55F1263025 for ; Mon, 18 May 2026 22:16:19 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1779135376; cv=none; d=zohomail.com; s=zohoarc; b=SdynNuFoxC6mRh3yRzRAy3kzZu+Qz5npyhRXEgiRcsLfFsYAQXFBMbO5NxsbqFfYgx+8Dyvo7NM3OU4/dZSjPCbIeDYklPcXx4HOF2AArXYe5gF51INRFYAR8i76+bu83g1ScWK21XFLiPw246QXSM76/T6FPkjvcHfnQhFR3/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779135376; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=z04t+WWR8x1KGFPoPbqytUTK3kj7WYJMqqN20b+oqYw=; b=lS9nMvwinjj2NtOaMH3QiXOr9GyJQgynB1IMdrxnSLIgRSwVO4LMw7MynLzZCkCNYBdLOwiYmsVYxnuEKYBt/5nUWZVttgRdCOd+0BV3YaojrFH3TNAOafEAWmhTr2ikICOKe0hOaOrtkrNKuXPZAcicn/eHWXNyb1WXUD6APqQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=robert.mader@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1779135376; s=zohomail; d=collabora.com; i=robert.mader@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=z04t+WWR8x1KGFPoPbqytUTK3kj7WYJMqqN20b+oqYw=; b=hponlkvw1MbxAsfGcKyrYnkSveyVWokEVQnj1RE+zhbHbUCQrPx5SDe0khO3gF6M WASXrn9UzaEiYtTdyoI2aj4fN1Fp2GRWK3tBbbQUcxB/rnS2200fFTnfs15XPmyCDy8 rFvQl3bjoNjiLNI5H/cir5PZ09UTse/pwcwPymyQ= Received: by mx.zohomail.com with SMTPS id 1779135375002510.8641157658823; Mon, 18 May 2026 13:16:15 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader , =?utf-8?q?Barnab=C3=A1s_P?= =?utf-8?b?xZFjemU=?= Subject: [PATCH v2 4/4] debayer_egl: Sync output buffer after processing stats Date: Mon, 18 May 2026 22:15:08 +0200 Message-ID: <20260518201508.140849-5-robert.mader@collabora.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260518201508.140849-1-robert.mader@collabora.com> References: <20260518201508.140849-1-robert.mader@collabora.com> 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" Instead of waiting for the GPU to finish the output buffer *before* computing stats, do so afterwards. This allows work to happen in parallel on the GPU and CPU, potentially improving throughput and reducing latency. This, however, requires us to include stats computation into the debayer benchmark data. Signed-off-by: Robert Mader Reviewed-by: Barnabás Pőcze --- src/libcamera/software_isp/debayer_egl.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index e5a661d2c..9ad0c871f 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -530,8 +530,6 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, std::optional *inputBu if (err != GL_NO_ERROR) { LOG(eGL, Error) << "Drawing scene fail " << err; return -ENODEV; - } else { - egl_.syncOutput(); } return 0; @@ -554,8 +552,6 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output goto error; } - bench_.finishFrame(); - metadata.planes()[0].bytesused = output->planes()[0].length; /* Calculate stats for the whole frame */ @@ -564,6 +560,9 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output stats_->processFrame(frame, 0, input); inputBufferDmaSyncer.reset(); + egl_.syncOutput(); + bench_.finishFrame(); + outputBufferReady.emit(output); inputBufferReady.emit(input);