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 += [