From patchwork Thu Nov 26 11:03:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Remy Alipoursafari X-Patchwork-Id: 29092 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 1D778BDE17 for ; Thu, 26 Nov 2026 11:05:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F3C686AA0F; Thu, 26 Nov 2026 12:05:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="M0dLPzjg"; dkim-atps=neutral Received: from sender5-pp-f112.zoho.com (sender5-pp-f112.zoho.com [165.173.182.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A7E9C6AA0F for ; Thu, 26 Nov 2026 12:05:06 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; t=1795691102; cv=none; d=zohomail.com; s=zohoarc; b=BHVwWTfYtrZyqvoRC05AEyQIuyhO5pxMW44PduxA/Q4DkyGiIZ0JyG6rKNj6zQUPuBV2zTF1D/R0F7qGVmEqNA6sjUsRaEKj/DNz85wvC477q7hArGXJ/jTcDeDbvb2ecLymI8Wl0bWYne6uoXOTleu9bJ21fxfombcKiFAGoPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795691102; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=4NtcfY+QZ6HTVbZVHLng7C7WL3NOte0ZzRgvPwoGKjA=; b=R/D+rRhKpeboyS9MPr0bgkeq0P7fBquWptEmdYTVywKQL5wntg/zcitSctVyO/iqwtFrM34dAAaNWSLeMD5AtH1mbA6QdzMv41VhQx9Cg6CXGcmnlrx923YEfZ86veeZBPSh1bAH2biy/r776V3PSa1ArpHIo3fMFKWSxMGZXUw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=remy.alipoursafari@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=M0dLPzjge2EXsx/xAT2LN0IsMlPSr6ot9es/FqT6kEhSfx5o2T1r9uVd8lOUGkF6yc/PG2J/bNqTYMaUOlRf5D3ZCobrZ90PkN2s5LXrvH5ByO1fb2+X1R98o9X0VxnfQpd25yCZOx2nZ19mIa+UfKCb/T3eKj78K04BzplsYSE=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=4NtcfY+QZ6HTVbZVHLng7C7WL3NOte0ZzRgvPwoGKjA=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1795691101073268.86673859042844; Thu, 26 Nov 2026 03:05:01 -0800 (PST) From: Remy Alipoursafari To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Lo=C3=AFc_Molinari?= , Robert Mader , Remy Alipoursafari Subject: [PATCH 1/6] libcamera: egl: Add GL extension & version checks Date: Fri, 27 Nov 2026 00:03:39 +1300 Message-ID: <20261126110422.362455-2-remy.alipoursafari@collabora.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261126110422.362455-1-remy.alipoursafari@collabora.com> References: <20261126110422.362455-1-remy.alipoursafari@collabora.com> MIME-Version: 1.0 X-ZohoMailClient: External 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: Loïc Molinari Allow EGL and OpenGL ES extensions to be queried for whether or not they exist in the current context. Also allows for checking the OpenGL ES context's version. Signed-off-by: Loïc Molinari Signed-off-by: Remy Alipoursafari Reviewed-by: Robert Mader --- include/libcamera/internal/egl.h | 11 ++++ src/libcamera/egl.cpp | 89 +++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index d6fb6fe0..10a9a3c5 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -109,6 +109,10 @@ public: void resetEGLContext(); static EGLDisplay probeDisplay(); + bool hasEGLExtension(const char *name) const; + bool hasGLESExtension(const char *name) const; + bool hasGLESVersion(unsigned int major, unsigned int minor) const; + int createInputDMABufTexture2D(eGLImage &eglImage, int fd); int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); void createTexture2D(eGLImage &eglImage, const void *data, GLint filter); @@ -142,6 +146,13 @@ private: EGLDisplay display_ = EGL_NO_DISPLAY; EGLContext context_ = EGL_NO_CONTEXT; + const char *eglExtensions_ = NULL; + const char *glesExtensions_ = NULL; + unsigned int glesMajor_ = 0; + unsigned int glesMinor_ = 0; + + static bool hasExtension(const char *extensions, const char *name); + int compileShader(int shaderType, GLuint &shaderId, std::span shaderData, std::span shaderEnv); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index ff9e54a1..8bc70b7d 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -10,6 +10,7 @@ #include "libcamera/internal/egl.h" #include +#include #include #include #include @@ -397,6 +398,7 @@ int eGL::initEGLContext() VTable vtable = {}; EGLint numConfigs; EGLConfig config; + const char *glesVersion; if (context_ != EGL_NO_CONTEXT) return -EEXIST; @@ -409,7 +411,8 @@ int eGL::initEGLContext() LOG(eGL, Info) << "EGL: EGL_VERSION: " << eglQueryString(display_, EGL_VERSION); LOG(eGL, Info) << "EGL: EGL_VENDOR: " << eglQueryString(display_, EGL_VENDOR); LOG(eGL, Info) << "EGL: EGL_CLIENT_APIS: " << eglQueryString(display_, EGL_CLIENT_APIS); - LOG(eGL, Info) << "EGL: EGL_EXTENSIONS: " << eglQueryString(display_, EGL_EXTENSIONS); + eglExtensions_ = eglQueryString(display_, EGL_EXTENSIONS); + LOG(eGL, Info) << "EGL: EGL_EXTENSIONS: " << eglExtensions_; vtable.eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); if (!vtable.eglCreateImageKHR) { @@ -446,7 +449,16 @@ int eGL::initEGLContext() makeCurrent(); LOG(eGL, Info) << "EGL: GL_RENDERER: " << glGetString(GL_RENDERER); - LOG(eGL, Info) << "EGL: GL_VERSION: " << glGetString(GL_VERSION); + glesVersion = (const char *)glGetString(GL_VERSION); + LOG(eGL, Info) << "EGL: GL_VERSION: " << glesVersion; + glesExtensions_ = (const char *)glGetString(GL_EXTENSIONS); + LOG(eGL, Info) << "EGL: GL_EXTENSIONS: " << glesExtensions_; + + if (sscanf(glesVersion, "OpenGL ES %u.%u", + &glesMajor_, &glesMinor_) != 2) { + LOG(eGL, Error) << "glGetString(GL_VERSION) invalid"; + goto fail; + } return 0; fail: @@ -454,6 +466,74 @@ fail: return -ENODEV; } +/** + * \brief Check EGL extension availability + * \param[in] name Extension name + * + * Checks whether a given EGL extension is currently available. + * + * \return True when available, false if not + */ +bool eGL::hasEGLExtension(const char *name) const +{ + return hasExtension(eglExtensions_, name); +} + +/** + * \brief Check GLES extension availability + * \param[in] name Extension name + * + * Checks whether a given OpenGL ES extension is currently available in the + * context. + * + * \return True when available, false if not + */ +bool eGL::hasGLESExtension(const char *name) const +{ + return hasExtension(glesExtensions_, name); +} + +/** + * \brief Checks extension availability + * \param[in] extensions Space separated string listing available extensions + * \param[in] name Extension name to check against + * + * Checks whether a given extension is within the extensions list. + * + * \return True when available, false if not + */ +bool eGL::hasExtension(const char *extensions, const char *name) +{ + size_t len = strlen(name); + const char *p = extensions; + + if (!extensions) + return false; + + // Full match search (separated by spaces or begin/end of string). + while ((p = strstr(p, name))) { + if ((p == extensions || p[-1] == ' ') && + (p[len] == ' ' || p[len] == '\0')) { + return true; + } + p += len; + } + + return false; +} + +/** + * \brief Whether the GLES version is at or above a minimum version + * \param[in] major Major version number + * \param[in] minor Minor version number + * + * \return True when at or beyond specified version, false otherwise + */ +bool eGL::hasGLESVersion(unsigned int major, unsigned int minor) const +{ + return glesMajor_ > major || (glesMajor_ == major && glesMinor_ >= minor); +} + /** * \brief Destroy the EGL context * @@ -468,6 +548,11 @@ void eGL::resetEGLContext() eglDestroyContext(display_, std::exchange(context_, EGL_NO_CONTEXT)); } + eglExtensions_ = NULL; + glesExtensions_ = NULL; + glesMajor_ = 0; + glesMinor_ = 0; + tid_ = -1; vtable_ = {}; } From patchwork Thu Nov 26 11:03:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Remy Alipoursafari X-Patchwork-Id: 29093 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 2515CBDE17 for ; Thu, 26 Nov 2026 11:05:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2A10C6AA20; Thu, 26 Nov 2026 12:05:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="XjkeZcVj"; dkim-atps=neutral Received: from sender6-pp-f112.zoho.com (sender6-pp-f112.zoho.com [165.173.180.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 80F2C6AA15 for ; Thu, 26 Nov 2026 12:05:08 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; t=1795691104; cv=none; d=zohomail.com; s=zohoarc; b=Cj7bf0YYkNzxoG3M9cUQvQECsXnxfGlUDPAw5bWV6L9euSlAV96dQGpb5gzH+BY22jYLZkOZIEtxYziUkVW5mPZXHYuOnhZOhGOWkMfkEtBceWiJ0Z+XM1MTQitzk7hTZ6uKaadzKancA6CyuOcbNCFXrYTw5TtYCE0+DK+49rM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795691104; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=IlkrgwFG4/PL/2hbt7QrmI9CP7Ae4sGukvsdQCh7geo=; b=Xpjf7UkHRQIdolJPI3dQqJ0H2BaZILkU2oqSutX45XDgP8zSut0u3iuvIuFB+UacG2cm3SpxDSDGch7dcVAxmEC+SbMaCXJhxitle/1DQwBk6KRVNnskTExPjJCBdoJBf1pq3yMhWYIz4GdknGN+sNtzEMPj7rH5qy7iWX0/6BU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=remy.alipoursafari@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=XjkeZcVjR+IeP8XNO56e5GDpBwX2JdG0wXHut2LnaIxEgI/0ZMJRs3fHJnBnaDdE3RhKazf2gGZOD64BbkIQxeHXWqMun+WYkvhz+lM09SIo968odCkGnvFBbeJG7JWjFaGsQSacwQmDlj2+k9FxoNuZOF/su8MFG5s3XfawuWM=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=IlkrgwFG4/PL/2hbt7QrmI9CP7Ae4sGukvsdQCh7geo=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1795691102636524.8262358664242; Thu, 26 Nov 2026 03:05:02 -0800 (PST) From: Remy Alipoursafari To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Lo=C3=AFc_Molinari?= , Robert Mader , Remy Alipoursafari Subject: [PATCH 2/6] libcamera: egl: Ensure required extensions are supported Date: Fri, 27 Nov 2026 00:03:40 +1300 Message-ID: <20261126110422.362455-3-remy.alipoursafari@collabora.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261126110422.362455-1-remy.alipoursafari@collabora.com> References: <20261126110422.362455-1-remy.alipoursafari@collabora.com> MIME-Version: 1.0 X-ZohoMailClient: External 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" Ensures that the EGL context supports EGL_EXT_image_dma_buf_import, and the OpenGL ES context supports GL_OES_EGL_image. Signed-off-by: Loïc Molinari Signed-off-by: Remy Alipoursafari Reviewed-by: Robert Mader --- src/libcamera/egl.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 8bc70b7d..f88fb7c4 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -460,6 +460,19 @@ int eGL::initEGLContext() goto fail; } +#define CHECK_EXTENSION(name, func) ({ \ + if (!func(name)) { \ + LOG(eGL, Error) << name << " not supported"; \ + resetEGLContext(); \ + goto fail; \ + } \ +}) +#define CHECK_EGL_EXTENSION(name) CHECK_EXTENSION(name, hasEGLExtension); +#define CHECK_GLES_EXTENSION(name) CHECK_EXTENSION(name, hasGLESExtension); + + CHECK_EGL_EXTENSION("EGL_EXT_image_dma_buf_import"); + CHECK_GLES_EXTENSION("GL_OES_EGL_image"); + return 0; fail: From patchwork Thu Nov 26 11:03:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Remy Alipoursafari X-Patchwork-Id: 29095 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 54829C3355 for ; Thu, 26 Nov 2026 11:05:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A73CB6AA29; Thu, 26 Nov 2026 12:05:14 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="GZiJ9b29"; dkim-atps=neutral Received: from sender6-pp-f112.zoho.com (sender6-pp-f112.zoho.com [165.173.180.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F0DCF6AA20 for ; Thu, 26 Nov 2026 12:05:09 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; t=1795691106; cv=none; d=zohomail.com; s=zohoarc; b=e+OJ5OxmYIbLtyuEPVPzSz2JWWJ/+CqRU7WpgOirBxgY+TRugPtBN8dbxPsmU7ljoK7Y8f60Kk1J/1rUWCQ4Scf3GTJ98EJtkG4Di6SGvijrf2p30OMUbAnamlqSjBa7hPhalBcAVUf+bdKCQ7grSG6jhPeoJ3cfIwnoN3sj+38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795691106; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=8imxRdk6wBF0XerE/ppuDK/iM1wnP8hW/MFMu7fEt8k=; b=GgTOjD1wnkJBn9ZMXWZHx0qArX8BfZSFRnrDHvm2ILU+ciurBIlSRAoGcYMZHBGkQWoa4MTBPxS0BDXOifUeLx7kYoprYza57Sh8gOff1fgR47oIozyK5nxI/KaF/EfxmF76WKrxlkIAxnLXgQmvL84xeZI/HaGCk/vveIR0Wrw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=remy.alipoursafari@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=GZiJ9b29iB6dz0DqOw3LpWaG03CxpxGkNch3U45h6gCpMWXUNzFfXnLBoshjAWJRibSVzsGYW2YfFtKwBdrgnQm8Jz2pT8De5BeQ/MK27nY0OddYKLwOrqPZt2Bt2AH0T4zY8HkxNt66wlgaEaBiNhLqkgQStW80SqmtIXTW1DU=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=8imxRdk6wBF0XerE/ppuDK/iM1wnP8hW/MFMu7fEt8k=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1795691104061459.92536478501665; Thu, 26 Nov 2026 03:05:04 -0800 (PST) From: Remy Alipoursafari To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Lo=C3=AFc_Molinari?= , Robert Mader Subject: [PATCH 3/6] libcamera: software_isp: debayer_egl: Check GL_RG support Date: Fri, 27 Nov 2026 00:03:41 +1300 Message-ID: <20261126110422.362455-4-remy.alipoursafari@collabora.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261126110422.362455-1-remy.alipoursafari@collabora.com> References: <20261126110422.362455-1-remy.alipoursafari@collabora.com> MIME-Version: 1.0 X-ZohoMailClient: External 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: Loïc Molinari Unpacked 10 and 12-bit raw input formats require either OpenGL ES 3.0 or the GL_EXT_texture_rg extension. Signed-off-by: Loïc Molinari Reviewed-by: Robert Mader --- src/libcamera/software_isp/debayer_egl.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 33933b11..d94a06d1 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -244,6 +244,13 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm break; }; + /* GL_RG textures need GL_EXT_texture_rg before ES 3.0 */ + if (glFormat_ == GL_RG && !egl_.hasGLESVersion(3, 0) && + !egl_.hasGLESExtension("GL_EXT_texture_rg")) { + LOG(Debayer, Error) << "GL_EXT_texture_rg not supported for unpacked input format"; + return -EINVAL; + } + if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, shaderEnv)) { LOG(Debayer, Error) << "Compile vertex shader fail"; From patchwork Thu Nov 26 11:03:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remy Alipoursafari X-Patchwork-Id: 29094 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 CE4A0BDE17 for ; Thu, 26 Nov 2026 11:05:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E51066AA2A; Thu, 26 Nov 2026 12:05:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="ReF4j+C7"; dkim-atps=neutral Received: from sender6-pp-f112.zoho.com (sender6-pp-f112.zoho.com [165.173.180.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3D5E06AA21 for ; Thu, 26 Nov 2026 12:05:10 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; t=1795691106; cv=none; d=zohomail.com; s=zohoarc; b=UPa0tCrKY2RYkxDsaGlGcZydiG32kHuUlcbJXnxv+TVVBz34BGtfRd0+AMWylBUQZB7pO/KCfqd/7AiLNtHqavNFphmWZPw0rrtJttfR6ILzhtFZMzKNsysNBjl2I5Fb8Q7ey5FI8qk7UxOaKDXU8BBmuJ1EmPcnTM3aMr3MNvs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795691106; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=ABqjkLFhogY6BMiEfPBAFj4WRyQSBeH3nsF6lfCJ1Pw=; b=SKy2TnhFKUcTooWFTZT+E8SEK2kgGBVpEZzGctwXPtXL1+C9hW2GAv0IN1I/aY6WoEBhDCXOemZ/1IiIWA9CEi99yi8gdTZZD5EiARblQsl1Dy2eKtW08yqIIC/g+JpiGGLBOKHGfuJccKYzh1SwAa0crSoGYbze+XzYQFwD1H0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=remy.alipoursafari@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=ReF4j+C7KKFhRghNVF1dQs3RYLKziGAlQQFR+DXFdv4fFlDJI/s8nMTYKXHhZzVF3GzLLhbzOnhdCxqAaRkVWUTtj9/9QD5Tb2CsHZL7ugKidoVsJXNGuFLqKr2O5bOOWKlJe01ayYkWyl8IPeiOI69jsPVtr0OWBbyKa2WYuU0=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=ABqjkLFhogY6BMiEfPBAFj4WRyQSBeH3nsF6lfCJ1Pw=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1795691105657417.59321187963064; Thu, 26 Nov 2026 03:05:05 -0800 (PST) From: Remy Alipoursafari To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Lo=C3=AFc_Molinari?= , Robert Mader , Remy Alipoursafari Subject: [PATCH 4/6] libcamera: egl: Separate proc address search into its own function Date: Fri, 27 Nov 2026 00:03:42 +1300 Message-ID: <20261126110422.362455-5-remy.alipoursafari@collabora.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261126110422.362455-1-remy.alipoursafari@collabora.com> References: <20261126110422.362455-1-remy.alipoursafari@collabora.com> MIME-Version: 1.0 X-ZohoMailClient: External 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" Separates searching for proc addresses using eglGetProcAddress into its own function so that future searches can be more easily added. Signed-off-by: Remy Alipoursafari Reviewed-by: Robert Mader --- include/libcamera/internal/egl.h | 2 ++ src/libcamera/egl.cpp | 41 +++++++++++++++++++------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 10a9a3c5..6a146405 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -165,5 +165,7 @@ private: PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; } vtable_ = {}; + + void locateProcAddresses(VTable *vtable); }; } //namespace libcamera diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index f88fb7c4..df0bba8e 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -414,23 +414,7 @@ int eGL::initEGLContext() eglExtensions_ = eglQueryString(display_, EGL_EXTENSIONS); LOG(eGL, Info) << "EGL: EGL_EXTENSIONS: " << eglExtensions_; - vtable.eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); - if (!vtable.eglCreateImageKHR) { - LOG(eGL, Error) << "eglCreateImageKHR not found"; - goto fail; - } - - vtable.eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); - if (!vtable.eglDestroyImageKHR) { - LOG(eGL, Error) << "eglDestroyImageKHR not found"; - goto fail; - } - - vtable.glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); - if (!vtable.glEGLImageTargetTexture2DOES) { - LOG(eGL, Error) << "glEGLImageTargetTexture2DOES not found"; - goto fail; - } + locateProcAddresses(&vtable); if (eglChooseConfig(display_, configAttribs, &config, 1, &numConfigs) != EGL_TRUE) { LOG(eGL, Error) << "eglChooseConfig fail"; @@ -586,6 +570,29 @@ void eGL::makeCurrent() } } +/** + * \brief Gets the addresses for EGL extension functions + * \param[in,out] vtable VTable to store the function addresses + * + * Locates the relevant runtime function addresses needed to fill the VTable. + * This does not fail when a function pointer is not found, nor does it validate + * the functions are available for the GL context, so it is also expected to + * also check the extension availability. + */ +void eGL::locateProcAddresses(VTable *vtable) +{ +#define GET_PROC_ADDRESS(location, name, type) ({ \ + location = (type)eglGetProcAddress(name); \ + if (!location) { \ + LOG(eGL, Debug) << name << " not found"; \ + } \ +}) + + GET_PROC_ADDRESS(vtable->eglCreateImageKHR, "eglCreateImageKHR", PFNEGLCREATEIMAGEKHRPROC); + GET_PROC_ADDRESS(vtable->eglDestroyImageKHR, "eglDestroyImageKHR", PFNEGLDESTROYIMAGEKHRPROC); + GET_PROC_ADDRESS(vtable->glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", PFNGLEGLIMAGETARGETTEXTURE2DOESPROC); +} + /** * \brief Add a preprocessor definition to shader environment * \param[in,out] shaderEnv Vector of shader environment strings From patchwork Thu Nov 26 11:03:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remy Alipoursafari X-Patchwork-Id: 29096 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 DB514BDE17 for ; Thu, 26 Nov 2026 11:05:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9CD366AA25; Thu, 26 Nov 2026 12:05:19 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="TIae61i3"; dkim-atps=neutral Received: from sender6-pp-f112.zoho.com (sender6-pp-f112.zoho.com [165.173.180.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 82D986AA1F for ; Thu, 26 Nov 2026 12:05:12 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; t=1795691108; cv=none; d=zohomail.com; s=zohoarc; b=c3FtINiJ8SGWUjFy50cZZSQgpSLPCkCZ/BVyKb4nvNL63Dy0bUmAyuR7E5Jb+xmJcJKJmsmJTNnonmOdnwzORReLVhCaXQoXWVFJZ/jLENE3rhclE4RFqgINKnuSbSawrASjndpyZcr99ICjGckPyufmhMO8r5Cx8i+syQyMc6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795691108; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=eyFOA5I10Pxw+44De1FeIgG4Rnp1f0zeW4R3OLODitM=; b=gfSDwjdK7lysqyFWjUlPm2blESvw/Yijs3gCLm+OjKyVs0o/69KGPjGo0t1/Nyy7Rnx3zIFIna71aAkanqf11I6UqLyD9/w9f76JMvGWtDHro3S5zgq+VskQmGjwDxN5QsbNKEWbYFernLAg2mE4Ss6QDDSmD2fR1O0Haza/hhs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=remy.alipoursafari@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=TIae61i3wG1qxH6Wf+HGzmYF4PeNlFEtAfmltcRXuy0cPdbapifd0zaTLiO7VZHeu0Y1ZqgcYSkaN/aGPcKZ7ZxgrGOjMcmyATaeErcDE9OvzsQFiFQt4kkkms4J8+yxkJjWj2JzYLhy4AUFqTYntNX0NoUmYmPgiwnyJZBgv0s=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=eyFOA5I10Pxw+44De1FeIgG4Rnp1f0zeW4R3OLODitM=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1795691107240644.3250544502131; Thu, 26 Nov 2026 03:05:07 -0800 (PST) From: Remy Alipoursafari To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Lo=C3=AFc_Molinari?= , Robert Mader , Remy Alipoursafari Subject: [PATCH 5/6] software_isp: benchmark: Make benchmark into an abstract class Date: Fri, 27 Nov 2026 00:03:43 +1300 Message-ID: <20261126110422.362455-6-remy.alipoursafari@collabora.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261126110422.362455-1-remy.alipoursafari@collabora.com> References: <20261126110422.362455-1-remy.alipoursafari@collabora.com> MIME-Version: 1.0 X-ZohoMailClient: External 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" Makes the Benchmark class abstract, splitting off the CPU-specific timing code to a separate file to allow for different benchmarking methods to be added in the future. Signed-off-by: Remy Alipoursafari Reviewed-by: Robert Mader --- .../internal/software_isp/benchmark.h | 18 ++- .../internal/software_isp/benchmark_cpu.h | 37 ++++++ .../internal/software_isp/meson.build | 2 +- .../internal/software_isp/swstats_cpu.h | 5 +- src/libcamera/software_isp/benchmark.cpp | 108 ++++++++++++++---- src/libcamera/software_isp/benchmark_cpu.cpp | 74 ++++++++++++ src/libcamera/software_isp/debayer.h | 4 +- src/libcamera/software_isp/debayer_cpu.cpp | 1 + src/libcamera/software_isp/debayer_egl.cpp | 2 + src/libcamera/software_isp/debayer_egl.h | 1 - src/libcamera/software_isp/meson.build | 1 + src/libcamera/software_isp/swstats_cpu.cpp | 1 + 12 files changed, 220 insertions(+), 34 deletions(-) create mode 100644 include/libcamera/internal/software_isp/benchmark_cpu.h create mode 100644 src/libcamera/software_isp/benchmark_cpu.cpp diff --git a/include/libcamera/internal/software_isp/benchmark.h b/include/libcamera/internal/software_isp/benchmark.h index cc7f9d71..be2f6ca5 100644 --- a/include/libcamera/internal/software_isp/benchmark.h +++ b/include/libcamera/internal/software_isp/benchmark.h @@ -1,18 +1,18 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Red Hat Inc. + * Copyright (C) 2026, Collabora Inc. * * Authors: * Hans de Goede + * Remy Alipoursafari * * Simple builtin benchmark to measure software ISP processing times */ #pragma once -#include #include -#include namespace libcamera { @@ -22,18 +22,26 @@ class Benchmark { public: Benchmark(const CameraManager &cm, const std::string &name); - ~Benchmark(); + virtual ~Benchmark(); void startFrame(void); void finishFrame(void); + void queryFrame(void); + +protected: + /* Cumulative time in nanoseconds */ + int64_t frameProcessTime_ = 0; + + virtual bool timeFrameStart(void) = 0; + virtual bool timeFrameEnd(void) = 0; + virtual bool timeFrameQuery(void) = 0; private: std::string name_; - timespec frameStartTime_; + /* Whether to process the current frame */ bool measure_; /* Skip 30 frames for things to stabilize then measure 30 frames */ unsigned int encounteredFrames_ = 0; - int64_t frameProcessTime_ = 0; unsigned int skipBeforeMeasure_ = 30; unsigned int framesToMeasure_ = 30; }; diff --git a/include/libcamera/internal/software_isp/benchmark_cpu.h b/include/libcamera/internal/software_isp/benchmark_cpu.h new file mode 100644 index 00000000..b61737d4 --- /dev/null +++ b/include/libcamera/internal/software_isp/benchmark_cpu.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Red Hat Inc. + * Copyright (C) 2026, Collabora Inc. + * + * Authors: + * Hans de Goede + * Remy Alipoursafari + * + * Simple builtin benchmark to measure software ISP CPU processing times + */ + +#pragma once + +#include +#include + +#include "libcamera/internal/software_isp/benchmark.h" + +namespace libcamera { + +class BenchmarkCpu : public Benchmark +{ +public: + BenchmarkCpu(const CameraManager &cm, const std::string &name); + ~BenchmarkCpu(); + +protected: + bool timeFrameStart(void) override; + bool timeFrameEnd(void) override; + bool timeFrameQuery(void) override; + +private: + timespec frameStartTime_; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build index df7c3b97..89161600 100644 --- a/include/libcamera/internal/software_isp/meson.build +++ b/include/libcamera/internal/software_isp/meson.build @@ -1,7 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 libcamera_internal_headers += files([ - 'benchmark.h', + 'benchmark_cpu.h', 'debayer_params.h', 'software_isp.h', 'swisp_stats.h', diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h index 55187092..e7871e41 100644 --- a/include/libcamera/internal/software_isp/swstats_cpu.h +++ b/include/libcamera/internal/software_isp/swstats_cpu.h @@ -22,8 +22,7 @@ #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/shared_mem_object.h" #include "libcamera/internal/software_isp/swisp_stats.h" - -#include "benchmark.h" +#include "benchmark_cpu.h" namespace libcamera { @@ -123,7 +122,7 @@ private: std::vector stats_; SharedMemObject sharedStats_; - Benchmark bench_; + BenchmarkCpu bench_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/benchmark.cpp b/src/libcamera/software_isp/benchmark.cpp index 96f0ae00..8f2fa84c 100644 --- a/src/libcamera/software_isp/benchmark.cpp +++ b/src/libcamera/software_isp/benchmark.cpp @@ -1,9 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Red Hat Inc. + * Copyright (C) 2026, Collabora Inc. * * Authors: * Hans de Goede + * Remy Alipoursafari * * Simple builtin benchmark to measure software ISP processing times */ @@ -35,38 +37,74 @@ Benchmark::Benchmark(const CameraManager &cm, const std::string &name) const GlobalConfiguration &configuration = cm._d()->configuration(); skipBeforeMeasure_ = configuration.option( - { "software_isp", "measure", "skip" }) - .value_or(skipBeforeMeasure_); + { "software_isp", "measure", "skip" }) + .value_or(skipBeforeMeasure_); framesToMeasure_ = configuration.option( { "software_isp", "measure", "number" }) - .value_or(framesToMeasure_); + .value_or(framesToMeasure_); } Benchmark::~Benchmark() { } -static inline int64_t timeDiff(timespec &after, timespec &before) -{ - return (after.tv_sec - before.tv_sec) * 1000000000LL + - (int64_t)after.tv_nsec - (int64_t)before.tv_nsec; -} +/** + * \var Benchmark::frameProcessTime_ + * \brief Cumulative time in nanoseconds + */ + +/** + * \fn Benchmark::timeFrameStart() + * \brief Start measuring process time for a single frame + * \return True on success, false on failure. On failure, the rest of the + * pipeline is skipped + * \sa timeFrameEnd() + * \sa timeFrameQuery() + */ + +/** + * \fn Benchmark::timeFrameEnd() + * \brief Finish measuring process time for a single frame + * \return True on success, false on failure. On failure, the rest of the + * pipeline is skipped + * \sa timeFrameStart() + * \sa timeFrameQuery() + */ + +/** + * \fn Benchmark::timeFrameQuery() + * \brief Query the processing time between the timer's start & end + * + * Queries for the time between the timer's start & end, and putting the result + * in Benchmark::frameProcessTime_. + * + * \return True on success, false on failure. On failure, the rest of the + * pipeline is skipped + * \sa timeFrameStart() + * \sa timeFrameEnd() + */ /** * \brief Start measuring process time for a single frame * * Call this function before processing frame data to start measuring * the process time for a frame. + * + * \sa finishFrame() + * \sa queryFrame() */ -void Benchmark::startFrame(void) +void Benchmark::startFrame() { measure_ = framesToMeasure_ > 0 && encounteredFrames_ < skipBeforeMeasure_ + framesToMeasure_ && ++encounteredFrames_ > skipBeforeMeasure_; if (measure_) { - frameStartTime_ = {}; - clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime_); + if (!timeFrameStart()) { + LOG(Benchmark, Error) << name_ << " failed starting time benchmark"; + encounteredFrames_--; + measure_ = false; + } } } @@ -76,21 +114,47 @@ void Benchmark::startFrame(void) * Call this function after processing frame data to finish measuring * the process time for a frame. * + * \sa startFrame() + * \sa queryFrame() + */ +void Benchmark::finishFrame() +{ + if (measure_) { + if (!timeFrameEnd()) { + LOG(Benchmark, Error) << name_ << " failed ending time benchmark"; + encounteredFrames_--; + measure_ = false; + } + } +} + +/** + * \brief Query & potentially print the processing time for a single frame + * + * Call this function once Benchmark::startFrame() & Benchmark::finishFrame() + * have been called. + * * This function will log frame processing time information after - * Benchmark::kLastFrameToMeasure frames have been processed. + * (Benchmark::skipBeforeMeasure_ + Benchmark::framesToMeasure_) successful + * frames have been processed. + * + * \sa startFrame() + * \sa finishFrame() */ -void Benchmark::finishFrame(void) +void Benchmark::queryFrame() { if (measure_) { - timespec frameEndTime = {}; - clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime); - frameProcessTime_ += timeDiff(frameEndTime, frameStartTime_); - if (encounteredFrames_ == skipBeforeMeasure_ + framesToMeasure_) { - LOG(Benchmark, Info) - << name_ << " processed " << framesToMeasure_ - << " frames in " << frameProcessTime_ / 1000 << "us, " - << frameProcessTime_ / (1000 * framesToMeasure_) - << " us/frame"; + if (timeFrameQuery()) { + if (encounteredFrames_ == skipBeforeMeasure_ + framesToMeasure_) { + LOG(Benchmark, Info) + << name_ << " processed " << framesToMeasure_ + << " frames in " << frameProcessTime_ / 1000 << "us, " + << frameProcessTime_ / (1000 * framesToMeasure_) + << " us/frame"; + } + } else { + LOG(Benchmark, Error) << name_ << " failed querying time benchmark"; + encounteredFrames_--; } } } diff --git a/src/libcamera/software_isp/benchmark_cpu.cpp b/src/libcamera/software_isp/benchmark_cpu.cpp new file mode 100644 index 00000000..3b9eb629 --- /dev/null +++ b/src/libcamera/software_isp/benchmark_cpu.cpp @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Red Hat Inc. + * Copyright (C) 2026, Collabora Inc. + * + * Authors: + * Hans de Goede + * Remy Alipoursafari + * + * Simple builtin benchmark to measure software ISP CPU processing times + */ + +#include "libcamera/internal/software_isp/benchmark_cpu.h" + +namespace libcamera { + +/** + * \class BenchmarkCpu + * \brief Simple builtin benchmark for mesuring CPU time + * + * Simple builtin benchmark to measure software ISP CPU processing times. + */ + +/** + * \brief Constructs a BenchmarkCpu object + */ +BenchmarkCpu::BenchmarkCpu(const CameraManager &cm, const std::string &name) + : Benchmark(cm, name) +{ +} + +BenchmarkCpu::~BenchmarkCpu() +{ +} + +static inline int64_t timeDiff(timespec &after, timespec &before) +{ + return (after.tv_sec - before.tv_sec) * 1000000000LL + + (int64_t)after.tv_nsec - (int64_t)before.tv_nsec; +} + +/** + * \brief Start measuring process time for a single frame + */ +bool BenchmarkCpu::timeFrameStart() +{ + frameStartTime_ = {}; + clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime_); + + return true; +} + +/** + * \brief Finish measuring process time for a single frame + */ +bool BenchmarkCpu::timeFrameEnd() +{ + timespec frameEndTime = {}; + clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime); + frameProcessTime_ += timeDiff(frameEndTime, frameStartTime_); + + return true; +} + +/** + * \brief Query the processing time between the timer's start & end + */ +bool BenchmarkCpu::timeFrameQuery() +{ + // Querying the processing time is done in BenchmarkCpu::timeFrameEnd() + return true; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h index e30a0527..c9423263 100644 --- a/src/libcamera/software_isp/debayer.h +++ b/src/libcamera/software_isp/debayer.h @@ -22,7 +22,7 @@ #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/dma_buf_allocator.h" -#include "libcamera/internal/software_isp/benchmark.h" +#include "libcamera/internal/software_isp/benchmark_cpu.h" #include "libcamera/internal/software_isp/debayer_params.h" namespace libcamera { @@ -80,7 +80,7 @@ public: PixelFormat inputPixelFormat_; PixelFormat outputPixelFormat_; bool swapRedBlueGains_; - Benchmark bench_; + BenchmarkCpu bench_; private: virtual Size patternSize(PixelFormat inputFormat) = 0; diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index 91867baa..23e519c3 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -1094,6 +1094,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output /* Measure before emitting signals */ bench_.finishFrame(); + bench_.queryFrame(); /* * Buffer ids are currently not used, so pass zeros as its parameter. diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index d94a06d1..ca99bdc2 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -672,6 +672,7 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output egl_.syncOutput(); bench_.finishFrame(); + bench_.queryFrame(); outputBufferReady.emit(output); inputBufferReady.emit(input); @@ -680,6 +681,7 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output error: bench_.finishFrame(); + bench_.queryFrame(); metadata.status = FrameMetadata::FrameError; return; } diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index cbbc6a45..4185d32b 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -21,7 +21,6 @@ #include "libcamera/internal/egl.h" #include "libcamera/internal/mapped_framebuffer.h" -#include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/software_isp/swstats_cpu.h" #include diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index 15f9e403..f6ee6700 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -21,6 +21,7 @@ summary({'SoftISP GPU acceleration' : mesa_works}, libcamera_internal_sources += files([ 'benchmark.cpp', + 'benchmark_cpu.cpp', 'debayer.cpp', 'debayer_cpu.cpp', 'software_isp.cpp', diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 74633815..0f08b19e 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -632,6 +632,7 @@ void SwStatsCpu::processFrame(uint32_t frame, uint32_t bufferId, MappedFrameBuff (this->*processFrame_)(input); finishFrame(frame, bufferId); bench_.finishFrame(); + bench_.queryFrame(); } } /* namespace libcamera */ From patchwork Thu Nov 26 11:03:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remy Alipoursafari X-Patchwork-Id: 29097 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 44B09C3360 for ; Thu, 26 Nov 2026 11:05:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AD04D6AA32; Thu, 26 Nov 2026 12:05:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="jWapbvK6"; dkim-atps=neutral Received: from sender6-pp-f112.zoho.com (sender6-pp-f112.zoho.com [165.173.180.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2FFAE6AA2D for ; Thu, 26 Nov 2026 12:05:15 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; t=1795691110; cv=none; d=zohomail.com; s=zohoarc; b=XEWx4czpKOk4jbIk8BDPu1LkZAVHjX4tJA+u1cYEtSl3SsRK3mSEvCObyjvh/P8MeCfjtZQAakyIWIDWuTp6N+Ojk6iV1Aa45ODtxX3ixjNkjdArKBtfvYU//2dJOFn0gthMgZIDvcrgxyVuueW4iPakssO4FVJZQmkQxOi+jno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795691110; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=oHf0C/J7OD182sGXxQKt6xx+3bRHtvpqQLTc2UWENPM=; b=Ke86VU/nEk8sIKrQt4A4+sZKVfsJB+76bXejRflv+S9DTUVRRBfBLTCRge3c8x6SsZqg0MU3mv5wcnYoqIF83Wa7cCJpirnu2Pnum1Qrq8mKj9AjvS+ent4wa884CWxRtEuIlh7X7dBK5VuLe/EKTm1lVfNzdAkNagG2B0zOAUc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=remy.alipoursafari@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=jWapbvK6VMu/JS3TUN9sQ/NkytK4PKF7+v4RjhzNswAn7UFQUbdLpBVtmPTraAe20HeqzJugN9uO076KnLmYpnIWEbQ642sJ+vnYbhosc2NVMS4mi8wki3DQu2wuQEU+MrXxuhy7yzQXG5ZC8Bp/TT+CYxyH0XzsccbqGCZiAVc=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=oHf0C/J7OD182sGXxQKt6xx+3bRHtvpqQLTc2UWENPM=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1795691108825310.27006043276003; Thu, 26 Nov 2026 03:05:08 -0800 (PST) From: Remy Alipoursafari To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Lo=C3=AFc_Molinari?= , Robert Mader , Remy Alipoursafari Subject: [PATCH 6/6] software_isp: benchmark: Add GPU benchmarking Date: Fri, 27 Nov 2026 00:03:44 +1300 Message-ID: <20261126110422.362455-7-remy.alipoursafari@collabora.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261126110422.362455-1-remy.alipoursafari@collabora.com> References: <20261126110422.362455-1-remy.alipoursafari@collabora.com> MIME-Version: 1.0 X-ZohoMailClient: External 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" Add a method for benchmarking the time taken by GPU in the softisp EGL implementation using the EXT_disjoint_timer_query OpenGL extension. On a Radxa ROCK 5B with Radxa Camera 4K, which uses the imx415 sensor, it results in the following processing time for 30 frames: - Debayer : 45958 us/frame - Debayer EGL : 17556 us/frame - CPU stats : 135974 us/frame Signed-off-by: Remy Alipoursafari Reviewed-by: Robert Mader --- include/libcamera/internal/egl.h | 16 +++ .../internal/software_isp/benchmark_egl.h | 43 +++++++ .../internal/software_isp/meson.build | 1 + src/libcamera/egl.cpp | 106 ++++++++++++++++++ src/libcamera/software_isp/benchmark_egl.cpp | 98 ++++++++++++++++ src/libcamera/software_isp/debayer_egl.cpp | 37 +++++- src/libcamera/software_isp/debayer_egl.h | 3 + src/libcamera/software_isp/meson.build | 1 + 8 files changed, 302 insertions(+), 3 deletions(-) create mode 100644 include/libcamera/internal/software_isp/benchmark_egl.h create mode 100644 src/libcamera/software_isp/benchmark_egl.cpp diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 6a146405..a3595cd3 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -119,6 +119,13 @@ public: void updateTexture2D(eGLImage &eglImage, const void *data); void createOutputTexture2D(eGLImage &eglImage); + bool timerQueryAvailable(); + void createTimerQuery(GLuint *id); + void deleteTimerQuery(GLuint *id); + void beginTimerQuery(GLuint id); + void endTimerQuery(); + int queryTimerQuery(GLuint id, GLuint64 *out); + int attachTextureToFBO(eGLImage &eglImage); void activateBindTexture(eGLImage &eglImage); @@ -160,10 +167,19 @@ private: void makeCurrent(); + bool disjointTimerExtensionAvailable_ = false; + struct VTable { PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; + + PFNGLGENQUERIESEXTPROC glGenQueriesEXT; + PFNGLDELETEQUERIESEXTPROC glDeleteQueriesEXT; + PFNGLBEGINQUERYEXTPROC glBeginQueryEXT; + PFNGLENDQUERYEXTPROC glEndQueryEXT; + PFNGLGETQUERYOBJECTIVEXTPROC glGetQueryObjectivEXT; + PFNGLGETQUERYOBJECTUI64VEXTPROC glGetQueryObjectui64vEXT; } vtable_ = {}; void locateProcAddresses(VTable *vtable); diff --git a/include/libcamera/internal/software_isp/benchmark_egl.h b/include/libcamera/internal/software_isp/benchmark_egl.h new file mode 100644 index 00000000..930139fe --- /dev/null +++ b/include/libcamera/internal/software_isp/benchmark_egl.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Collabora Inc. + * + * Authors: + * Remy Alipoursafari + * + * Simple builtin benchmark to measure software ISP GPU processing times + */ + +#pragma once + +#include + +#include "libcamera/internal/egl.h" +#include "libcamera/internal/software_isp/benchmark.h" + +#include + +namespace libcamera { + +class BenchmarkEgl : public Benchmark +{ +public: + BenchmarkEgl(const CameraManager &cm, const std::string &name, eGL &egl); + ~BenchmarkEgl(); + + bool hasTimerQuery(void); + + void initTimer(void); + void deleteTimer(void); + +protected: + bool timeFrameStart(void) override; + bool timeFrameEnd(void) override; + bool timeFrameQuery(void) override; + +private: + eGL &egl_; + GLuint timerQuery_ = 0; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build index 89161600..48dcfc5a 100644 --- a/include/libcamera/internal/software_isp/meson.build +++ b/include/libcamera/internal/software_isp/meson.build @@ -2,6 +2,7 @@ libcamera_internal_headers += files([ 'benchmark_cpu.h', + 'benchmark_egl.h', 'debayer_params.h', 'software_isp.h', 'swisp_stats.h', diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index df0bba8e..a0f119c5 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -363,6 +363,101 @@ void eGL::createOutputTexture2D(eGLImage &eglImage) attachTextureToFBO(eglImage); } +/** + * \brief Checks whether timer queries are available + * + * Checks whether the GL_EXT_disjoint_timer_query extension is available in the + * current OpenGL ES context. + * + * \sa createTimerQuery() + */ +bool eGL::timerQueryAvailable() +{ + return disjointTimerExtensionAvailable_; +} + +/** + * \brief Create a disjoint timer query object + * \param[out] id Location to store the disjoint timer query + * + * Creates a disjoint timer query provided by EXT_disjoint_timer_query for GPU + * timing if the extension is available. + * + * \sa timerQueryAvailble() + * \sa deleteTimerQuery() + */ +void eGL::createTimerQuery(GLuint *id) +{ + if (!timerQueryAvailable()) + return; + + vtable_.glGenQueriesEXT(1, id); +} + +/** + * \brief Deletes a disjoint timer query object + * \param[in,out] id The location of the disjoint timer query + * + * Creates a disjoint timer query provided by EXT_disjoint_timer_query for GPU + * timing. + * + * \sa createTimerQuery() + */ +void eGL::deleteTimerQuery(GLuint *id) +{ + vtable_.glDeleteQueriesEXT(1, id); +} + +/** + * \brief Begins the disjoint timer query + * \param[in] id The ID of the disjoint timer query object + * \sa createTimerQuery() + * \sa endTimerQuery() + * \sa queryTimerQuery() + */ +void eGL::beginTimerQuery(GLuint id) +{ + vtable_.glBeginQueryEXT(GL_TIME_ELAPSED_EXT, id); +} + +/** + * \brief Ends the disjoint timer query + * + * Ends the most recently started non-previously-stopped timer query. + * + * \sa beginTimerQuery() + * \sa queryTimerQuery() + */ +void eGL::endTimerQuery() +{ + vtable_.glEndQueryEXT(GL_TIME_ELAPSED_EXT); +} + +/** + * \brief Gets the result of the timer query + * \param[in] id The ID of the disjoint timer query object + * \param[out] out Time from beginning query in nanoseconds + * + * Once the GPU has finished processing the timer query, this gives the GPU + * processing time between beginning and ending the timer query. + * + * \return 0 on success, -1 on failure (called too early?) + * \sa beginTimerQuery() + * \sa endTimerQuery() + */ +int eGL::queryTimerQuery(GLuint id, GLuint64 *out) +{ + int available = 0; + + vtable_.glGetQueryObjectivEXT(id, GL_QUERY_RESULT_AVAILABLE, &available); + if (!available) + return -1; + + vtable_.glGetQueryObjectui64vEXT(id, GL_QUERY_RESULT, out); + + return 0; +} + /** * \brief Initialise the EGL context * @@ -457,6 +552,8 @@ int eGL::initEGLContext() CHECK_EGL_EXTENSION("EGL_EXT_image_dma_buf_import"); CHECK_GLES_EXTENSION("GL_OES_EGL_image"); + disjointTimerExtensionAvailable_ = hasGLESExtension("GL_EXT_disjoint_timer_query"); + return 0; fail: @@ -550,6 +647,8 @@ void eGL::resetEGLContext() glesMajor_ = 0; glesMinor_ = 0; + disjointTimerExtensionAvailable_ = false; + tid_ = -1; vtable_ = {}; } @@ -591,6 +690,13 @@ void eGL::locateProcAddresses(VTable *vtable) GET_PROC_ADDRESS(vtable->eglCreateImageKHR, "eglCreateImageKHR", PFNEGLCREATEIMAGEKHRPROC); GET_PROC_ADDRESS(vtable->eglDestroyImageKHR, "eglDestroyImageKHR", PFNEGLDESTROYIMAGEKHRPROC); GET_PROC_ADDRESS(vtable->glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", PFNGLEGLIMAGETARGETTEXTURE2DOESPROC); + + GET_PROC_ADDRESS(vtable->glGenQueriesEXT, "glGenQueriesEXT", PFNGLGENQUERIESEXTPROC); + GET_PROC_ADDRESS(vtable->glDeleteQueriesEXT, "glDeleteQueriesEXT", PFNGLDELETEQUERIESEXTPROC); + GET_PROC_ADDRESS(vtable->glBeginQueryEXT, "glBeginQueryEXT", PFNGLBEGINQUERYEXTPROC); + GET_PROC_ADDRESS(vtable->glEndQueryEXT, "glEndQueryEXT", PFNGLENDQUERYEXTPROC); + GET_PROC_ADDRESS(vtable->glGetQueryObjectivEXT, "glGetQueryObjectivEXT", PFNGLGETQUERYOBJECTIVEXTPROC); + GET_PROC_ADDRESS(vtable->glGetQueryObjectui64vEXT, "glGetQueryObjectui64vEXT", PFNGLGETQUERYOBJECTUI64VEXTPROC); } /** diff --git a/src/libcamera/software_isp/benchmark_egl.cpp b/src/libcamera/software_isp/benchmark_egl.cpp new file mode 100644 index 00000000..bfd78c1d --- /dev/null +++ b/src/libcamera/software_isp/benchmark_egl.cpp @@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Collabora Inc. + * + * Authors: + * Remy Alipoursafari + * + * Simple builtin benchmark to measure software ISP GPU processing times + */ + +#include "libcamera/internal/software_isp/benchmark_egl.h" + +#include + +namespace libcamera { + +LOG_DEFINE_CATEGORY(BenchmarkEgl) + +/** + * \class BenchmarkEgl + * \brief Simple builtin benchmark for mesuring GPU time + * + * Simple builtin benchmark to measure software ISP GPU processing times. + */ + +/** + * \brief Constructs a BenchmarkEgl object + */ +BenchmarkEgl::BenchmarkEgl(const CameraManager &cm, const std::string &name, eGL &egl) + : Benchmark(cm, name), egl_{ egl } +{ +} + +BenchmarkEgl::~BenchmarkEgl() +{ +} + +/** + * \brief Checks if the timer query has been created + */ +bool BenchmarkEgl::hasTimerQuery() +{ + return timerQuery_ != 0; +} + +/** + * \brief Initialises the timer query + * + * Sets up the disjoint timer query for the current OpenGL context. + */ +void BenchmarkEgl::initTimer() +{ + egl_.createTimerQuery(&timerQuery_); +} + +/** + * \brief Deletes the timer query + */ +void BenchmarkEgl::deleteTimer() +{ + egl_.deleteTimerQuery(&timerQuery_); + timerQuery_ = 0; +} + +/** + * \brief Start measuring process time for a single frame + */ +bool BenchmarkEgl::timeFrameStart() +{ + egl_.beginTimerQuery(timerQuery_); + return true; +} + +/** + * \brief Finish measuring process time for a single frame + */ +bool BenchmarkEgl::timeFrameEnd() +{ + egl_.endTimerQuery(); + return true; +} + +/** + * \brief Query the processing time between the timer's start & end + */ +bool BenchmarkEgl::timeFrameQuery() +{ + GLuint64 elapsed = -1; + + if (egl_.queryTimerQuery(timerQuery_, &elapsed)) { + return false; + } + + frameProcessTime_ += elapsed; + return true; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index ca99bdc2..fc75968a 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -43,7 +43,7 @@ namespace libcamera { * \param[in] display The EGL display to use */ DebayerEGL::DebayerEGL(std::unique_ptr stats, const CameraManager &cm, EGLDisplay display) - : Debayer(cm), stats_(std::move(stats)), egl_(display) + : Debayer(cm), benchEgl_(cm, "Debayer EGL", egl_), stats_(std::move(stats)), egl_(display) { } @@ -51,6 +51,14 @@ DebayerEGL::~DebayerEGL() { } +/** + * \var DebayerEGL::benchEgl_ + * \brief Benchmarking utility instance for GPU performance measurements + * + * Used internally to track GPU timing and performance metrics during + * debayer processing. + */ + int DebayerEGL::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config) { BayerFormat bayerFormat = @@ -606,12 +614,21 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye eGLImage *eglImageIn; eGLImage *eglImageOut; + if (benchEgl_.hasTimerQuery()) + benchEgl_.startFrame(); + eglImageIn = getCachedInputFrameBuffer(input, inMapped, inDmaSyncer); - if (!eglImageIn) + if (!eglImageIn) { + if (benchEgl_.hasTimerQuery()) + benchEgl_.finishFrame(); return -ENOMEM; + } eglImageOut = getCachedOutputFrameBuffer(output); - if (!eglImageOut) + if (!eglImageOut) { + if (benchEgl_.hasTimerQuery()) + benchEgl_.finishFrame(); return -ENOMEM; + } egl_.attachTextureToFBO(*eglImageOut); setShaderVariableValues(*eglImageIn, params); @@ -620,6 +637,9 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLE_FAN, 0, DEBAYER_OPENGL_COORDS); + if (benchEgl_.hasTimerQuery()) + benchEgl_.finishFrame(); + GLenum err = glGetError(); if (err != GL_NO_ERROR) { LOG(eGL, Error) << "Drawing scene fail " << err; @@ -674,6 +694,9 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output bench_.finishFrame(); bench_.queryFrame(); + if (benchEgl_.hasTimerQuery()) + benchEgl_.queryFrame(); + outputBufferReady.emit(output); inputBufferReady.emit(input); @@ -682,6 +705,8 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output error: bench_.finishFrame(); bench_.queryFrame(); + if (benchEgl_.hasTimerQuery()) + benchEgl_.queryFrame(); metadata.status = FrameMetadata::FrameError; return; } @@ -700,6 +725,9 @@ int DebayerEGL::start() if (initBayerShaders(inputPixelFormat_, outputPixelFormat_)) return -EINVAL; + if (egl_.timerQueryAvailable()) + benchEgl_.initTimer(); + if (lscEnabled_) { constexpr unsigned int gridSize = DebayerParams::kLscGridSize; constexpr unsigned int stride = gridSize * DebayerParams::kLscBytesPerCell; @@ -723,6 +751,9 @@ void DebayerEGL::stop() eglImageLscLookup_.reset(); lscLutVersion_.reset(); + if (benchEgl_.hasTimerQuery()) + benchEgl_.deleteTimer(); + if (programId_) glDeleteProgram(programId_); diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index 4185d32b..140d20fa 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -21,6 +21,7 @@ #include "libcamera/internal/egl.h" #include "libcamera/internal/mapped_framebuffer.h" +#include "libcamera/internal/software_isp/benchmark_egl.h" #include "libcamera/internal/software_isp/swstats_cpu.h" #include @@ -61,6 +62,8 @@ public: SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) override; + BenchmarkEgl benchEgl_; + private: static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config); int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat); diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index f6ee6700..6676db6f 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -32,6 +32,7 @@ if mesa_works config_h.set('HAVE_DEBAYER_EGL', 1) libcamera_internal_sources += files([ '../egl.cpp', + 'benchmark_egl.cpp', 'debayer_egl.cpp', ]) libcamera_deps += [