From patchwork Fri Dec 4 03:18:58 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remy Alipoursafari X-Patchwork-Id: 29163 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 74D94C3300 for ; Fri, 4 Dec 2026 03:20:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 127656AB70; Fri, 4 Dec 2026 04:20:25 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=coolgi.dev header.i=@coolgi.dev header.b="Qz8AGz1p"; dkim=pass (2048-bit key; unprotected) header.d=coolgi.dev header.i=@coolgi.dev header.b="VJxW5Xew"; dkim-atps=neutral Received: from mail.coolgi.dev (mail.coolgi.dev [185.193.17.204]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 65F1E6AB6B for ; Fri, 4 Dec 2026 04:20:23 +0100 (CET) From: Remy Alipoursafari DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=coolgi.dev; s=rsa-2026-08; t=1796354422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A+Vy81JfPYFKKnAoPnPXkoSkwYLUr/UzYkjdxHkN9/g=; b=Qz8AGz1pWYLqX3QQCCs4gjxr3C5TL2IMB7a/bduGwGgZJh7LT643GvPY6UbOrK+4cW3MGI pCyR/pZGsAITQ9vMBW3lP1Yoaa0xKvFsT4Yu62QLCFOyL51e7a0JwH+YU2xZlzIc+bHImI Ghf5aHHJMhne6/qRSsCKm9Owvz76dxhliXs4sACtbFoYkxxjMKuTRpkTqICxnPPPm8WFw0 0l+KeuTVqIze3Qd54GGEk65Giv/Y3AU02mmZ96w7YG8GMWfmylCLB0H6f6eZ2vGJiFE1J+ f6V9OXxpCLRK7YZTwxTd534OT8JUqEREDuxK0ulumlLcIsM1J1zdM1rOhlt/yw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=coolgi.dev; s=rsa-2026-11; t=1796354422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A+Vy81JfPYFKKnAoPnPXkoSkwYLUr/UzYkjdxHkN9/g=; b=VJxW5XewZF9wLCLg7fg7z0RXZga6Xwez/o5oyZpfmHmWOk+aFlbxZtGc0pC64ECqbQsS35 6+k4z15FfYw+U5FdxCQejNSu1whVsWAQqUZtTBkLSpkEROFrxYuOv1k5swk/NJCs7hNMnU d/mHZty1n8471IjeX2+d8dKBja0ZUUwFsZa3xKNtfF3cmGFCCNXfFOBJfIv9Ncg4S+XX+n Yz7ORzn61pGQ+qIk/ra93GSxeN2O18/KbgkLgnKlv8LZjF4hcC1Jmo6Lut76dLuFwjZwfy RtGbrGyz9p+hcFwkT8oSa51velaY94wCyHh4LR7B6WADmn+puSwLnio5Re5FSw== To: libcamera-devel@lists.libcamera.org Cc: Remy Alipoursafari , =?utf-8?q?Lo?= =?utf-8?q?=C3=AFc_Molinari?= , Robert Mader Subject: [PATCH v2 6/6] software_isp: benchmark: Add GPU benchmarking Date: Fri, 4 Dec 2026 16:18:58 +1300 Message-ID: <20261204031914.117401-7-me@coolgi.dev> In-Reply-To: <20261204031914.117401-1-me@coolgi.dev> References: <20261204031914.117401-1-me@coolgi.dev> 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 From: Remy Alipoursafari 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 | 105 ++++++++++++++++++ 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, 301 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 1d1c530c..dc444139 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -120,6 +120,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); @@ -159,10 +166,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 df5b542d..eeddb56f 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 * @@ -462,6 +557,7 @@ 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"); contextGuard.release(); @@ -526,6 +622,8 @@ void eGL::resetEGLContext() glesMajor_ = 0; glesMinor_ = 0; + disjointTimerExtensionAvailable_ = false; + tid_ = -1; vtable_ = {}; } @@ -567,6 +665,13 @@ void eGL::locateProcAddresses(VTable *vtable) GET_PROC_ADDRESS(vtable->eglCreateImageKHR, "eglCreateImageKHR"); GET_PROC_ADDRESS(vtable->eglDestroyImageKHR, "eglDestroyImageKHR"); GET_PROC_ADDRESS(vtable->glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES"); + + GET_PROC_ADDRESS(vtable->glGenQueriesEXT, "glGenQueriesEXT"); + GET_PROC_ADDRESS(vtable->glDeleteQueriesEXT, "glDeleteQueriesEXT"); + GET_PROC_ADDRESS(vtable->glBeginQueryEXT, "glBeginQueryEXT"); + GET_PROC_ADDRESS(vtable->glEndQueryEXT, "glEndQueryEXT"); + GET_PROC_ADDRESS(vtable->glGetQueryObjectivEXT, "glGetQueryObjectivEXT"); + GET_PROC_ADDRESS(vtable->glGetQueryObjectui64vEXT, "glGetQueryObjectui64vEXT"); } /** 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 += [