From patchwork Tue May 19 19:39:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 26781 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 AF16BC32F4 for ; Tue, 19 May 2026 19:39:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 34A1F6302A; Tue, 19 May 2026 21:39:41 +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="Jsq2oUpe"; 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 C419462FE8 for ; Tue, 19 May 2026 21:39:38 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1779219574; cv=none; d=zohomail.com; s=zohoarc; b=HNtqadN2Ogb18lXqACs5WAsIiu9A2sI7KWFBD+6CBZ7n1KyXm90bSB7p1NhHbnqTgoxmf7wMFcOPDJD/WPaq4tEBgt9OMfZglHW0UN2yRyOQaEjkV45fkXEvpgq6rKHqgkZyA+hVd9CPUFJ/QI+gCIWj17Ea9lTTYKGyocekV54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779219574; 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=8EFLgFlwCAVbk5DhsdGh5G5uLW1flfwkpQlBHsT+ZQI=; b=KCHgcq+4KmlvR2ud/50zzEiNcFPOXpL7k4LtHlYbV9jd6f0zpFwc4IzgMvRdG6wH54Z18iVkOGOaNUGDKD54+KXasbweCWknCyrIPtZuJvXO+i0MTt3yXQpd5oe/4/F3EzXaF6dLmciHo8FeusesQGKz48rDWdpF9bkf5XY8930= 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=1779219574; 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=8EFLgFlwCAVbk5DhsdGh5G5uLW1flfwkpQlBHsT+ZQI=; b=Jsq2oUpeGwywznnkBj362K7WdaEgIeAM3gNHTDc9XTFJKYlOiCagoVcx+C9V173z WkZZ308peROaHaqRrACSxse8rKPN2oXXRlG0fJHCy8jsHWgG+pOaXhpzgkOntbrP808 BG0NKjEPBvHy/E1dCQgk6nUtPR6cPjom36LkFBBw= Received: by mx.zohomail.com with SMTPS id 1779219572897860.9292318309206; Tue, 19 May 2026 12:39:32 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v3 1/5] egl: Add GL format parameter to eGLImage constructor Date: Tue, 19 May 2026 21:39:03 +0200 Message-ID: <20260519193907.86812-2-robert.mader@collabora.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519193907.86812-1-robert.mader@collabora.com> References: <20260519193907.86812-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 preparation for the following commits. This requires a minor reordering in DebayerEGL::start() as the value for the input texture is only known after initBayerShaders(). Signed-off-by: Robert Mader --- include/libcamera/internal/egl.h | 6 ++++-- src/libcamera/egl.cpp | 22 +++++++++++++++++++++- src/libcamera/software_isp/debayer_egl.cpp | 10 +++++----- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 0ad2320b1..eb340eb58 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -51,14 +51,15 @@ class eGLImage public: /** * \brief Construct an eGLImage with explicit stride + * \param[in] format Image GL format * \param[in] width Image width in pixels * \param[in] height Image height in pixels * \param[in] stride Row stride in bytes * \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 +80,7 @@ public: glDeleteTextures(1, &texture_); } + GLint format_; /**< Image GL format */ uint32_t width_; /**< Image width in pixels */ uint32_t height_; /**< Image height in pixels */ uint32_t stride_; /**< Row stride in bytes */ diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 357918711..e02e3edc3 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -20,6 +20,8 @@ #include +#include + namespace libcamera { LOG_DEFINE_CATEGORY(eGL) @@ -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_, diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index eae4c57f4..4e4e375c5 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -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_, width_, 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 Tue May 19 19:39:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 26783 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 CA25AC3300 for ; Tue, 19 May 2026 19:39:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 41A736303B; Tue, 19 May 2026 21:39:45 +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="fsPEHSQU"; 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 4B7126302C for ; Tue, 19 May 2026 21:39:41 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1779219576; cv=none; d=zohomail.com; s=zohoarc; b=Ib2ovs6TN0R6HNNEdxgsk8TvhRhEABtROU9y4xjMTQRnJLkqeJ0OtLqUvUPyeTBdPMYl9++v4qdjwEC8j+OnpPrLgDqfOrr2rhIeoFY3xyM7DjavI22W+9c41AYfRmOH55hQDgD20Y8f19c4ZbiIOtCpoiLzFMe9emXe2qx+CuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779219576; 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=3OVohcrGmT9Piqot259Nlx8w/EYDuMq0JmbS9g7b0vw=; b=jGWNE07yxAe5PzkUcGyTtnnleo574ooSW43Go2+5MvFyo4n3JGnjpezNyH2qm71BZa7ZYjHhb+aD2mHW8IxVJJj4x7j+tvnuNvlyuKA/mr/26lEbUbNltjkUGpJdvsUBuj7Voi/K2rzSArVjuqzSUF058d1Wml4pKMG1pBLlDhA= 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=1779219576; 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=3OVohcrGmT9Piqot259Nlx8w/EYDuMq0JmbS9g7b0vw=; b=fsPEHSQUqovPLADtAXI15kp4SqM84IJSutbSSaG1SvEom6PfVqEGFRMLeSELR4IH iHGEA8xYtz6sTyhR2wNhDwIpt830igy73iJdysnCWghkBdheE0zuoBumfiPLfpTudn0 lqNpfJKuonmJZBqSKB2SGQmLMJQ4/pVJfrvKZ6TI= Received: by mx.zohomail.com with SMTPS id 1779219574432748.2348091653535; Tue, 19 May 2026 12:39:34 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v3 2/5] egl: Remove some parameters from createTexture2D() Date: Tue, 19 May 2026 21:39:04 +0200 Message-ID: <20260519193907.86812-3-robert.mader@collabora.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519193907.86812-1-robert.mader@collabora.com> References: <20260519193907.86812-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" And use the values set in the constructor instead, bringing the function in line with createInputDMABufTexture2D() and createOutputDMABufTexture2D(). Adopt the value passed into the constructor accordingly, which previously was never used. Signed-off-by: Robert Mader --- include/libcamera/internal/egl.h | 2 +- src/libcamera/egl.cpp | 7 ++----- src/libcamera/software_isp/debayer_egl.cpp | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index eb340eb58..6869fa69b 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -105,7 +105,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 e02e3edc3..b51defbdd 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -227,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 @@ -237,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()); @@ -245,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 4e4e375c5..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); @@ -586,7 +586,7 @@ int DebayerEGL::start() return -EINVAL; /* Raw bayer input as texture */ - eglImageBayerIn_ = std::make_unique(glFormat_, 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(GL_RGBA, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); From patchwork Tue May 19 19:39: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: 26784 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 CAFB6C32F4 for ; Tue, 19 May 2026 19:39:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DE5516302C; Tue, 19 May 2026 21:39:45 +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="iP7CLjez"; 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 8B79263035 for ; Tue, 19 May 2026 21:39:41 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1779219576; cv=none; d=zohomail.com; s=zohoarc; b=NwzCObXTwmRbLpNkFAGVOP1RsOIjAz+sKDLo3VsOwEZ/EFRXb73Kyee/Pu3jKeCOcfNafoLaCvC8Q+OqraWM7gUOcJCOuSlr7jjVkoQTf4qa3fxg/Cmkn37MbhPqR2Xi4HuBWzBjRpltYzdD3hyoCo+nrD2QLo7ayhC0vZvVtSg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779219576; 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=2US6PQNWHOHw1P5M7cN6ib8CWzcdBXpsSJ5Gg/SjQXI=; b=NcI6+/iR3/tuyNUnIuwzrjI+QW8dpdRC1Sx7/CHQWhvLc25y4YkHhKlMyMROvtcPWIzfnNX4FUllTJUQg28eXPY6/GAwErN/n8aIfWMrvROt6nsjaFHoY0UES94LcuvzzaV8uJP3JEicSOjkoT1n46kTi/KNtov7Rz+BnMJMFgU= 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=1779219576; 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=2US6PQNWHOHw1P5M7cN6ib8CWzcdBXpsSJ5Gg/SjQXI=; b=iP7CLjezpTU2DibLL1tassqpVL6TbD+OUCGs1MjC2/pw9BODbLbFy7eP64At8qw0 AzLPwTdU7lIlI/Afv5X0lqyJacUEq0Ic16jhN035kTc7SqCNqO3ZREK72cyXJ1PpMfh mD4Y3meq+iQrBn6fOUfwBKGy+0eVZIm3PYn99PvQ= Received: by mx.zohomail.com with SMTPS id 1779219575945619.5835395482512; Tue, 19 May 2026 12:39:35 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v3 3/5] debayer_egl: Implement dmabuf import for input buffers Date: Tue, 19 May 2026 21:39:05 +0200 Message-ID: <20260519193907.86812-4-robert.mader@collabora.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519193907.86812-1-robert.mader@collabora.com> References: <20260519193907.86812-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 | 40 ++++++++++++++-------- src/libcamera/software_isp/debayer_egl.h | 4 ++- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index a217e3798..750895d10 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -500,16 +500,32 @@ 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()); + /* Try to create texture for input buffer via dmabuf import */ + if (!dmabuf_import_failed_) { + if (egl_.createInputDMABufTexture2D(*eglImageBayerIn_, input->planes()[0].fd.get()) != 0) { + LOG(Debayer, Info) << "Importing input buffer with DMABuf import failed, falling back to upload"; + dmabuf_import_failed_ = true; + } + } + + /* Otherwise create texture for input buffer via upload from CPU */ + if (dmabuf_import_failed_) { + 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 +547,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 +565,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..fd8c577d3 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; @@ -109,6 +109,8 @@ private: GLint glFormat_; unsigned int bytesPerPixel_; uint32_t shaderStridePixels_; + + bool dmabuf_import_failed_; }; } /* namespace libcamera */ From patchwork Tue May 19 19:39: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: 26782 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 A695DBDCBC for ; Tue, 19 May 2026 19:39:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4942763034; Tue, 19 May 2026 21:39:44 +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="cMpSA13/"; 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 B751663026 for ; Tue, 19 May 2026 21:39:40 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1779219578; cv=none; d=zohomail.com; s=zohoarc; b=DD4R1bpL3+6ZoW78OmGc2rsvXyBXixCpXdZ9ZcKhVG/qxInIdRCVq5sF1NDI6icDB+stDFm1wm20YDqdYqn7Nyah7S2CjkcXUPuZm4i3rqenKIiQ2q+XzJvVXLiQuQNoCbJv/MkaOvOCPhT4KP0hNy10UTIto7S5DtF0aB5cjxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779219578; 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=6duHg11cjc6WmA3iHFeeWRyhW3km6TpAJofxljES0Wk=; b=fRpYzYJ0MR1qEJGl4KEtzsc0TN2fDVTT0nH/xBvT0QEgoSbyaK2iSMF+sx+Cvk6w9bPzBQtOGt6I4kkDWwCRsArNzFsGFSiopkzQcHaLpSckVlgHwbW44bE/c2yMw5va5HEaElE6KzjlRK76ipPSBmnwEaYyOPydqXwFYIFe4dc= 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=1779219578; 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=6duHg11cjc6WmA3iHFeeWRyhW3km6TpAJofxljES0Wk=; b=cMpSA13/iplVZJ7LkYcyK1Q5JJ//FY7fmplEzsbf+Em8o1h4lDxzFaV2+hpx3AX2 XrKmYgSaqmrx2FbeZpxpHSMLv7jqrUUlJEUObZWJHu8zNQpmyiAbYiaSZaQIp4yw9MP 2Eyn5zI4mD/0DJINvncFDiwG8NKs2WhXgOkNQ3e4= Received: by mx.zohomail.com with SMTPS id 1779219577511784.8805317784354; Tue, 19 May 2026 12:39:37 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v3 4/5] egl: Demote an error log to debug Date: Tue, 19 May 2026 21:39:06 +0200 Message-ID: <20260519193907.86812-5-robert.mader@collabora.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519193907.86812-1-robert.mader@collabora.com> References: <20260519193907.86812-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 now that DebayerEGL::debayerGPU() tries dmabuf imports for input buffers, making import failures expected results. 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 b51defbdd..d5e52d5b3 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 Tue May 19 19:39:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 26785 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 23889C3301 for ; Tue, 19 May 2026 19:39:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 85EE663042; Tue, 19 May 2026 21:39:47 +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="aAZzoyjN"; 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 7E53C63039 for ; Tue, 19 May 2026 21:39:44 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1779219580; cv=none; d=zohomail.com; s=zohoarc; b=lQw0oBvo1Fynu5UUsuz1cSSxjy+SCnQ1Qi7hQHDvqqiDiTSzFVlwu5xIU5zA8lX4umEbepaWZ+pvLsuaqR6VkTlNtWEuI4X9uW4fXfY4YWU1Y3HGB7hMRr+sqA+XoTMRepJF8M7o7hSP0JQnT3FxxTFZV5ZJhXJigl30hsn1edI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779219580; 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=9IpGrraSJ7sUGI34EHGr3n24fwxPRGwvRVz0XyOZyZI=; b=EyccH1Yb2UH2oikNNCzxeXWN4GJ4COBeOEVcW4oB+Yc1zGEQF7HMh6ZSC0wS8Tfp1jleE7x6TvkTSv9HqZDq1Z12Hpd6srqk6kac1k+q74s0493VmqS9CgNQ/jtxVLNVqLVBXKnpRijmTxetxad837KWE+r995SoobXpMpZF9l4= 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=1779219580; 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=9IpGrraSJ7sUGI34EHGr3n24fwxPRGwvRVz0XyOZyZI=; b=aAZzoyjN+kFGhQO0gZLufXrg+0JLfjLzRvk+2sPybukXSIuiBcojW+eJI+L0qgFR eEfLkroynlVQyx2vBseB2nhBZGYl9UHtgTT42xoFP4y5JHw78QmiahrpQmGLDPRux2y 7RFDy4PCCSrhHzc7Zi0j31n8O4nPBk+sMuH3jl5o= Received: by mx.zohomail.com with SMTPS id 1779219579147677.4954399650786; Tue, 19 May 2026 12:39:39 -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 v3 5/5] debayer_egl: Sync output buffer after processing stats Date: Tue, 19 May 2026 21:39:07 +0200 Message-ID: <20260519193907.86812-6-robert.mader@collabora.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519193907.86812-1-robert.mader@collabora.com> References: <20260519193907.86812-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 750895d10..41176973b 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -536,8 +536,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; @@ -560,8 +558,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 */ @@ -570,6 +566,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);