From patchwork Mon Feb 16 19:02:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 26167 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 B0570C0DA4 for ; Mon, 16 Feb 2026 19:02:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2971F62214; Mon, 16 Feb 2026 20:02:17 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.b="MJd7ThD+"; dkim=pass (2048-bit key; unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="R1XjJN0Z"; dkim-atps=neutral Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B94362201 for ; Mon, 16 Feb 2026 20:02:14 +0100 (CET) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61GG1jeQ048861 for ; Mon, 16 Feb 2026 19:02:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=UVPPPmSuPjO m3wDBERqYZg3W4pI5aWj8jXPV/ADSsQE=; b=MJd7ThD+M9VpwE7kHnetYMCgv/1 Ojobp/IBnaSrZK4Cdlbo9lBGuPS+qLpw1fxQeEvGtwh9k79Bhvp9xanK+vNlLPiX jojKW4C+W7bvE+bPMCvx7WZ2W5hjywECzyGS1d9EP8v624QEpaDehjLEZh84XR/9 B24s2EC58oJ7uRbrDvH1OAB+ezaxPBlt3TQW6jD8GW22icIvTfRl0WWX2bCYoeW4 CuI4f+CaI2E51xFBs45gkc5typ7e04YD93w2RocqNHTyQocq4YOBgOvUz0AGWKkR FVyu6UrSvhV0ZkNjDqrWubZoZT636f6MlXxeWSTOLrG3s0meFNzwUmgluLg== Received: from mail-vk1-f200.google.com (mail-vk1-f200.google.com [209.85.221.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cc6d80dxw-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 16 Feb 2026 19:02:12 +0000 (GMT) Received: by mail-vk1-f200.google.com with SMTP id 71dfb90a1353d-5674e566967so5946604e0c.0 for ; Mon, 16 Feb 2026 11:02:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1771268531; x=1771873331; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UVPPPmSuPjOm3wDBERqYZg3W4pI5aWj8jXPV/ADSsQE=; b=R1XjJN0ZQMPcI3k3qlBS8aiGLXCji6p9yE0gH6qCJDwwQKxBsCLDzR+fTwCTJKScaz hAwLOSAFby1ae0mYrky62JFz0rSao23XX0/D2DmeMH/l7Pht2oMyaOEPnpAwTjiEYYIf r862M0zLbR0vkpXtcLFngWO3QF9KA/tIlqFcGSKu0ya2iGKlO6DLDytO3IIc2557iGdK xPeb7Ae2hcNW5alTOha2whC9zjA6VOVRNyUKT1eeSX3KC0iiX7+MSXyospwtXKYU7nDE 588RZed2wXEVDI3g5yzN0OzWJuEFJNuaFJfpsd/M/EKUuZ5ysyOtoQGZ0L3jprF4G3th kCfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771268531; x=1771873331; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UVPPPmSuPjOm3wDBERqYZg3W4pI5aWj8jXPV/ADSsQE=; b=bGV6hpdQvthkqcZHBUNkxmzunCKXWclYR1sKOqWsYt+Iy519GUzX4h6glUMxO2quPN 7hZwZb87pWFXY9XD3IfyirzUShhQ8/AzBcsdAmFLoDx3mFOrgmDGrjZQPPdNH9WZ1k4s 7ZXhadX6dPlahsWLj73vuXFl1L1cLoAv6DkRAeaWek+KRzUbetA81D96UbJFiQlPINrz C5k2lnYPZFIgjtNvL8NuDgABLbH4aZiuU8NqKfIQX/3Lc5HDJZDqCxzh0G9ODEEqC2ku hpqFT4ieKDut00d67SBptttVi3YP0InjKVVrNVu17or4UW7EY+vyO+JUgHEDhoVg1MF0 XmHA== X-Gm-Message-State: AOJu0YzyWJxIVkAVDGZyn9QvVBnvhbeqnRb+z8ZNHGshPHiYVfQanu5t iBxSSBkaroOuAEwL74LxNZwLuKChddmApDVAjrwveXZyJA4s2wEiCRQlD/O+NWoSt+UWVpMYgGD wnQPaDqk8K5Z4/qXHwinNgEl/ZuOd+ct4Ml6K4qarW2qJT7KZdex1WYuRoyQa2kTHw8LVqeXPgF m7Jqm5KN/R X-Gm-Gg: AZuq6aJ9McwzB9ZdZ0YfdIkB3vS74dhGsFY1hH8QNJ/qYjXA8G0E3BKBMva8zp4amGg r9U1iWaxadhK3WY77u2z+XwXnkOBQnksgW884UKZgWki4/dPnu5/P1ZFO7o52XOtQdlWZs3xzg4 FijQaYNpZkxAN14Ap0jQO2iwqXtkBA+RR+UR+gincubfDD52zUh72cVV5ue/37vbM3FnNHAQVbx yd+3FQWwPGyYYbG1zssmIAJ3kvvhnXkDjra92IZmJn3qThFm3WI7LQFE5FEMbSNj1Q8PquyzuCN pCX2rPeqJyD47/vuELLVR+mQNzSRljPKy+whv/K9LiceIFblghDEobCpciDdcHc0IiD7MbexZLp +EKSFrQP9ZjxzmgR3hvKZaMYEuTAUMOKhpI6b6of45NynhgyMsH7xNynVsce3PYVi6PFlMKHPzO lvenEj7CyJ9Pa04aiUl8Nn2S15nUbQJebH9DJ+ X-Received: by 2002:a05:6122:8cb:b0:559:6663:8b1a with SMTP id 71dfb90a1353d-56768179c4bmr3391296e0c.4.1771268531259; Mon, 16 Feb 2026 11:02:11 -0800 (PST) X-Received: by 2002:a05:6122:8cb:b0:559:6663:8b1a with SMTP id 71dfb90a1353d-56768179c4bmr3391251e0c.4.1771268530732; Mon, 16 Feb 2026 11:02:10 -0800 (PST) Received: from shalem (2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:5bfa:a036:83f0:f9ec]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8fc735e587sm276698966b.2.2026.02.16.11.02.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Feb 2026 11:02:10 -0800 (PST) From: Hans de Goede To: libcamera-devel@lists.libcamera.org, Milan Zamazal Cc: Hans de Goede Subject: [PATCH 5/5] software_isp: debayer_cpu: Add multi-threading support Date: Mon, 16 Feb 2026 20:02:04 +0100 Message-ID: <20260216190204.106922-6-johannes.goede@oss.qualcomm.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260216190204.106922-1-johannes.goede@oss.qualcomm.com> References: <20260216190204.106922-1-johannes.goede@oss.qualcomm.com> MIME-Version: 1.0 X-Authority-Analysis: v=2.4 cv=bqVBxUai c=1 sm=1 tr=0 ts=699369b4 cx=c_pps a=wuOIiItHwq1biOnFUQQHKA==:117 a=xqWC_Br6kY4A:10 a=HzLeVaNsDn8A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=EUspDBNiAAAA:8 a=j_KrAe4nr5UCvrO7opAA:9 a=XD7yVLdPMpWraOa8Un9W:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjE2MDE2MyBTYWx0ZWRfX7y7/Aj986YaI bnp9X6JZwSiTkToyPBurh9iEQUqCGGN67os+D90pSlt405/4jnLcU5EzUi3vFKdGM5gTbebyADD TiJ4Oto/ZeyfRQM2SDm476IwseMaZAizJztp7kFyYD7oYo0tt+XgR/xmIBdi9UmxlwULOryrb6o E7grrGUcM3G4fCnCsjaluaaLbeMe1e8BLvXVkEhwHRFZTQbicEz10vLuQYb7h4H7X1qiOST7Z1V x2cmoLELlMj3OprfpEiDBgBU27dtbdHUAvDuHWm8LfKfSxn/5K3/sw+2LWoTGa41MjRTAJBjw2d h9O/xHrbtPAsVO8+ZGojIfkMebRrEzO/3JC9jCeomUrXAKh5hGSR1pV0n74zSUmbOCyb4/NvRb+ qdwmTU/4QbPYfP8+Lgn1anhnYqaBcVv4s27HCH3QO5jaeT98q/AtWyuQds09nzIaJAKxoGAX3K7 7kYtEXqX4YqG9qzy5NA== X-Proofpoint-GUID: _8f0PnRls08v-KVJwkZ5cn_Zp9e3vuY3 X-Proofpoint-ORIG-GUID: _8f0PnRls08v-KVJwkZ5cn_Zp9e3vuY3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293, Aquarius:18.0.1121, Hydra:6.1.51, FMLib:17.12.100.49 definitions=2026-02-16_06,2026-02-16_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 spamscore=0 adultscore=0 phishscore=0 clxscore=1015 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602160163 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 CPU soft ISP multi-threading support. Benchmark results for the Uno-Q with a weak CPU which is good for performance testing, all numbers with an IMX219 running at 3280x2464 -> 3272x2464: 1 thread : 147ms / frame, ~6.5 fps 2 threads: 81ms / frame, ~12 fps 3 threads: 66ms / frame, ~14.5 fps Adding a 4th thread does not improve performance. Signed-off-by: Hans de Goede --- src/libcamera/software_isp/debayer_cpu.cpp | 49 +++++++++++++++++----- src/libcamera/software_isp/debayer_cpu.h | 2 +- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index 5e168554..c4b6c5b8 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ namespace libcamera { * \param[in] configuration The global configuration */ DebayerCpu::DebayerCpu(std::unique_ptr stats, const GlobalConfiguration &configuration) - : Debayer(configuration), stats_(std::move(stats)), threadCount_(1) + : Debayer(configuration), stats_(std::move(stats)) { /* * Reading from uncached buffers may be very slow. @@ -56,6 +57,9 @@ DebayerCpu::DebayerCpu(std::unique_ptr stats, const GlobalConfigurat */ enableInputMemcpy_ = configuration.option({ "software_isp", "copy_input_buffer" }).value_or(true); + threadCount_ = + configuration.option({ "software_isp", "threads" }).value_or(3); + threadCount_ = std::clamp(threadCount_, 1u, kMaxThreads); } DebayerCpu::~DebayerCpu() = default; @@ -692,7 +696,7 @@ void DebayerCpu::process2(uint32_t frame, const uint8_t *src, uint8_t *dst, for (unsigned int y = threadData->yStart; y < threadData->yEnd; y += 2) { shiftLinePointers(linePointers, src); memcpyNextLine(linePointers, threadData); - stats_->processLine0(frame, y, linePointers, &statsBuffer_); + stats_->processLine0(frame, y, linePointers, threadData->statsBuffer); (this->*debayer0_)(dst, linePointers); src += inputConfig_.stride; dst += outputConfig_.stride; @@ -707,7 +711,8 @@ void DebayerCpu::process2(uint32_t frame, const uint8_t *src, uint8_t *dst, if (threadData->processLastLinesSeperately) { shiftLinePointers(linePointers, src); memcpyNextLine(linePointers, threadData); - stats_->processLine0(frame, threadData->yEnd, linePointers, &statsBuffer_); + stats_->processLine0(frame, threadData->yEnd, linePointers, + threadData->statsBuffer); (this->*debayer0_)(dst, linePointers); src += inputConfig_.stride; dst += outputConfig_.stride; @@ -749,7 +754,7 @@ void DebayerCpu::process4(uint32_t frame, const uint8_t *src, uint8_t *dst, for (unsigned int y = threadData->yStart; y < threadData->yEnd; y += 4) { shiftLinePointers(linePointers, src); memcpyNextLine(linePointers, threadData); - stats_->processLine0(frame, y, linePointers, &statsBuffer_); + stats_->processLine0(frame, y, linePointers, threadData->statsBuffer); (this->*debayer0_)(dst, linePointers); src += inputConfig_.stride; dst += outputConfig_.stride; @@ -762,7 +767,7 @@ void DebayerCpu::process4(uint32_t frame, const uint8_t *src, uint8_t *dst, shiftLinePointers(linePointers, src); memcpyNextLine(linePointers, threadData); - stats_->processLine2(frame, y, linePointers, &statsBuffer_); + stats_->processLine2(frame, y, linePointers, threadData->statsBuffer); (this->*debayer2_)(dst, linePointers); src += inputConfig_.stride; dst += outputConfig_.stride; @@ -869,6 +874,10 @@ void DebayerCpu::updateLookupTables(const DebayerParams ¶ms) void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms) { + std::unique_ptr threads[threadCount_ - 1]; + SwIspStats statsBuffer[threadCount_]; + unsigned int i; + bench_.startFrame(); std::vector dmaSyncers; @@ -891,11 +900,31 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output return; } - stats_->startFrame(frame, &statsBuffer_, 1); + stats_->startFrame(frame, statsBuffer, threadCount_); - threadData_[0].yStart = 0; - threadData_[0].yEnd = window_.height; - (this->*processInner_)(frame, in.planes()[0].data(), out.planes()[0].data(), &threadData_[0]); + unsigned int yStart = 0; + unsigned int linesPerThread = (window_.height / threadCount_) & + ~(inputConfig_.patternSize.width - 1); + for (i = 0; i < (threadCount_ - 1); i++) { + threadData_[i].yStart = yStart; + threadData_[i].yEnd = yStart + linesPerThread; + threadData_[i].statsBuffer = &statsBuffer[i]; + threads[i] = std::make_unique( + processInner_, this, frame, + in.planes()[0].data(), + out.planes()[0].data() + yStart * outputConfig_.stride, + &threadData_[i]); + yStart += linesPerThread; + } + threadData_[i].yStart = yStart; + threadData_[i].yEnd = window_.height; + threadData_[i].statsBuffer = &statsBuffer[i]; + (this->*processInner_)(frame, in.planes()[0].data(), + out.planes()[0].data() + yStart * outputConfig_.stride, + &threadData_[i]); + + for (i = 0; i < (threadCount_ - 1); i++) + threads[i]->join(); metadata.planes()[0].bytesused = out.planes()[0].size(); @@ -909,7 +938,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output * * \todo Pass real bufferId once stats buffer passing is changed. */ - stats_->finishFrame(frame, 0, &statsBuffer_, 1); + stats_->finishFrame(frame, 0, statsBuffer, threadCount_); outputBufferReady.emit(output); inputBufferReady.emit(input); } diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index b85dd11c..63fa7710 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -85,6 +85,7 @@ private: unsigned int lineBufferIndex; /* Stored here to avoid causing register pressure in inner loop */ bool processLastLinesSeperately; + SwIspStats *statsBuffer; }; using processFn = void (DebayerCpu::*)(uint32_t frame, const uint8_t *src, uint8_t *dst, @@ -150,7 +151,6 @@ private: Rectangle window_; /* Variables used every line */ - SwIspStats statsBuffer_; debayerFn debayer0_; debayerFn debayer1_; debayerFn debayer2_;