From patchwork Thu Feb 5 10:21:56 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 26095 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 BACBABD78E for ; Thu, 5 Feb 2026 10:22:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9F3626204A; Thu, 5 Feb 2026 11:22:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Ajg4tIBU"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 924D361F84 for ; Thu, 5 Feb 2026 11:21:59 +0100 (CET) Received: from pb-laptop.local (185.221.141.206.nat.pool.zt.hu [185.221.141.206]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 997DD227; Thu, 5 Feb 2026 11:21:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1770286876; bh=GmACjKMWOcU7DXqghEumcezcd6/Hz8hixTfyzHOU79g=; h=From:To:Cc:Subject:Date:From; b=Ajg4tIBUARE3wq5kby6qY8D5FYdXjKDo80iw68hl8KkOwNejeL3qIK3DWRlNp8z1J YZkt+oxFPYGJqialJthykwgC3J2OB8vbaOtbPbNh/Gg+Vl43ieW0JyFAw7GokbqvjQ GBsNWp7mLIQ/4QTBvf807AdqeSfGF71ItxEbU9Lc= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Bryan O'Donoghue Subject: [PATCH v2] libcamera: software_isp: debayer: Take `DebayerParams` by ref Date: Thu, 5 Feb 2026 11:21:56 +0100 Message-ID: <20260205102156.2591211-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When calling `Debayer::process()` from `SoftwareIsp::process()`, the `DebayerParams` object is copied multiple times: (1) call of `BoundMethodMember<...>::activate()` inside `Object::invokeMethod()` (2) constructor of `BoundMethodArgs<...>` inside `BoundMethodMember<...>::activate()` (3) call of `BoundMethodMember<...>::invoke()` inside `BoundMethodArgs::invokePack()` (4) call of the actual pointer to member function inside `BoundMethodMember::invoke()` While compilers might avoid one or two of the above copies, this is still not ideal. By making `Debayer::process()` take the parameter object by const lvalue reference, only the copy in the `BoundMethodArgs` constructor remains. So do that. Before: [0:12:51.133836595] [12424] DEBUG SoftwareIsp software_isp.cpp:399 params=0x7d0a691f57d0 copy from 0x7d0a691f57d0 into 0x7baa65f2bf30 copy from 0x7baa65f2bf30 into 0x7c6a69209758 copy from 0x7c6a69209758 into 0x7baa63223930 copy from 0x7baa63223930 into 0x7baa63223a70 [0:12:51.134559602] [12426] DEBUG eGL debayer_egl.cpp:538 params=0x7baa63223a70 771.099877 (30.06 fps) cam0-stream0 seq: 000031 bytesused: 8666112 After: [0:13:42.861691943] [12543] DEBUG SoftwareIsp software_isp.cpp:399 params=0x7cfaad5f57d0 copy from 0x7cfaad5f57d0 into 0x7c5aad609758 [0:13:42.862453917] [12545] DEBUG eGL debayer_egl.cpp:538 params=0x7c5aad609758 822.827388 (30.02 fps) cam0-stream0 seq: 000031 bytesused: 8666112 Signed-off-by: Barnabás Pőcze Reviewed-by: Milan Zamazal Reviewed-by: Bryan O'Donoghue --- changes in v2: * rebase * reword and extend commit message v1: https://patchwork.libcamera.org/patch/25898/ --- src/libcamera/software_isp/debayer.h | 2 +- src/libcamera/software_isp/debayer_cpu.cpp | 6 +++--- src/libcamera/software_isp/debayer_cpu.h | 6 +++--- src/libcamera/software_isp/debayer_egl.cpp | 6 +++--- src/libcamera/software_isp/debayer_egl.h | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) -- 2.53.0 diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h index 652cff4cc..ce9350b7b 100644 --- a/src/libcamera/software_isp/debayer.h +++ b/src/libcamera/software_isp/debayer.h @@ -47,7 +47,7 @@ public: virtual std::tuple strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) = 0; - virtual void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params) = 0; + virtual void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms) = 0; virtual int start() { return 0; } virtual void stop() {} diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index af7af0a8d..d09883577 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -750,7 +750,7 @@ void DebayerCpu::process4(uint32_t frame, const uint8_t *src, uint8_t *dst) } } -void DebayerCpu::updateGammaTable(DebayerParams ¶ms) +void DebayerCpu::updateGammaTable(const DebayerParams ¶ms) { const RGB blackLevel = params.blackLevel; /* Take let's say the green channel black level */ @@ -780,7 +780,7 @@ void DebayerCpu::updateGammaTable(DebayerParams ¶ms) gammaTable_[blackIndex]); } -void DebayerCpu::updateLookupTables(DebayerParams ¶ms) +void DebayerCpu::updateLookupTables(const DebayerParams ¶ms) { const bool gammaUpdateNeeded = params.gamma != params_.gamma || @@ -842,7 +842,7 @@ void DebayerCpu::updateLookupTables(DebayerParams ¶ms) params_ = params; } -void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params) +void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms) { bench_.startFrame(); diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index b5cbb5bd2..7a6517462 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -39,7 +39,7 @@ public: std::vector formats(PixelFormat input); std::tuple strideAndFrameSize(const PixelFormat &outputFormat, const Size &size); - void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params); + void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms); SizeRange sizes(PixelFormat inputFormat, const Size &inputSize); const SharedFD &getStatsFD() { return stats_->getStatsFD(); } @@ -110,8 +110,8 @@ private: void memcpyNextLine(const uint8_t *linePointers[]); void process2(uint32_t frame, const uint8_t *src, uint8_t *dst); void process4(uint32_t frame, const uint8_t *src, uint8_t *dst); - void updateGammaTable(DebayerParams ¶ms); - void updateLookupTables(DebayerParams ¶ms); + void updateGammaTable(const DebayerParams ¶ms); + void updateLookupTables(const DebayerParams ¶ms); /* Max. supported Bayer pattern height is 4, debayering this requires 5 lines */ static constexpr unsigned int kMaxLineBuffers = 5; diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 4d0caa6ef..93f7c6946 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -383,7 +383,7 @@ DebayerEGL::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size return std::make_tuple(stride, stride * size.height); } -void DebayerEGL::setShaderVariableValues(DebayerParams ¶ms) +void DebayerEGL::setShaderVariableValues(const DebayerParams ¶ms) { /* * Raw Bayer 8-bit, and packed raw Bayer 10-bit/12-bit formats @@ -506,7 +506,7 @@ void DebayerEGL::setShaderVariableValues(DebayerParams ¶ms) return; } -int DebayerEGL::debayerGPU(MappedFrameBuffer &in, int out_fd, DebayerParams ¶ms) +int DebayerEGL::debayerGPU(MappedFrameBuffer &in, int out_fd, const DebayerParams ¶ms) { /* eGL context switch */ egl_.makeCurrent(); @@ -533,7 +533,7 @@ int DebayerEGL::debayerGPU(MappedFrameBuffer &in, int out_fd, DebayerParams &par return 0; } -void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params) +void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms) { bench_.startFrame(); diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index cfbaf8e9d..59aebcc81 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -50,7 +50,7 @@ public: std::vector formats(PixelFormat input); std::tuple strideAndFrameSize(const PixelFormat &outputFormat, const Size &size); - void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params); + void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms); int start(); void stop(); @@ -72,9 +72,9 @@ private: std::vector shaderEnv); int linkShaderProgram(void); int getShaderVariableLocations(); - void setShaderVariableValues(DebayerParams ¶ms); + void setShaderVariableValues(const DebayerParams ¶ms); void configureTexture(GLuint &texture); - int debayerGPU(MappedFrameBuffer &in, int out_fd, DebayerParams ¶ms); + int debayerGPU(MappedFrameBuffer &in, int out_fd, const DebayerParams ¶ms); /* Shader program identifiers */ GLuint vertexShaderId_ = 0;