From patchwork Mon Jun 8 15:03:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 26856 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 36A8EC328C for ; Mon, 8 Jun 2026 15:04:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C564461F1B; Mon, 8 Jun 2026 17:04:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="J1peoxoI"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 03D7D61F00 for ; Mon, 8 Jun 2026 17:04:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780931073; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4tddGy712352sjbLd3X1jE2tUkVJDxQazhu578EYriU=; b=J1peoxoIdVpb77axm5R78YtknLFSXARwYhHPS9nr2m6Bu5WP7i2kh0q59oX1W91HUykSIs VZ9UIKwasnJcb3a3BwZ5EH9e0NOGdMrtl74qDRo+lfnOg/TzzcfKNcUHNyw38Nr3aDYdOR KjfB98nOY+yYcuXmL4w8Y5X3vKpNZ/E= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-103-Luh4S9tlNRaod2-3MdTlzQ-1; Mon, 08 Jun 2026 11:04:15 -0400 X-MC-Unique: Luh4S9tlNRaod2-3MdTlzQ-1 X-Mimecast-MFC-AGG-ID: Luh4S9tlNRaod2-3MdTlzQ_1780931054 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DBEBF1800847; Mon, 8 Jun 2026 15:04:13 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.48.51]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3A5CD1800351; Mon, 8 Jun 2026 15:04:11 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Kieran Bingham , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= , johannes.goede@oss.qualcomm.com Subject: [RFC PATCH v4 07/17] libcamera: software_isp: Track unused parameters buffers Date: Mon, 8 Jun 2026 17:03:36 +0200 Message-ID: <20260608150349.134371-8-mzamazal@redhat.com> In-Reply-To: <20260608150349.134371-1-mzamazal@redhat.com> References: <20260608150349.134371-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: JYyxR0JUegyBuU0SEZPdui3z3RItDRfLTN5VaBSjR5g_1780931054 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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" As a preparation for introducing a ring of parameters buffers, this patch introduces tracking of parameters buffers available for use. SoftwareIsp::availableParams_ is a vector of ids of the buffers available for use. When a fresh parameter buffer is needed, its id is retrieved from there and once the buffer is no longer needed, it's put back there, in a method invoked by a signal. This is similar to what the hardware pipelines do. If a parameters buffer is requested but there is no free available, it is an erroneous situation. To recover from it, we have currently no better mechanism than to wait for an available buffer. Simply returning from the processing would mean the finishing signals are not called, resulting in e.g. the input buffer not being returned. This is different from the hardware pipelines, which are structured somewhat differently. We use 0 as the buffer id for now. In followup patches, we will have to make and pass a special id->buffer mapping to the IPA and debayering on initialisation. Note that the parameters buffer id is still actually unused and the only buffer currently used is still copied when passed to debayering. This patch is just preparation for followup patches that will introduce multiple buffers. Signed-off-by: Milan Zamazal --- .../internal/software_isp/software_isp.h | 3 ++- src/libcamera/software_isp/software_isp.cpp | 27 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index f97d25f0a..58fb9d752 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -79,7 +79,7 @@ public: int queueBuffers(uint32_t frame, FrameBuffer *input, const std::map &outputs); - void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output); + int process(uint32_t frame, FrameBuffer *input, FrameBuffer *output); Signal inputBufferReady; Signal outputBufferReady; @@ -99,6 +99,7 @@ private: Thread ispWorkerThread_; SharedMemObject sharedParams_; DebayerParams debayerParams_; + std::vector availableParams_; DmaBufAllocator dmaHeap_; bool ccmEnabled_; diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 774f2bf75..d48cd00ad 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -185,6 +185,9 @@ bool SoftwareIsp::allocateParamsBuffers() return false; } + /* Just a single buffer for now, let's use 0 as its id. */ + availableParams_.push_back(0); + return true; } @@ -353,7 +356,12 @@ int SoftwareIsp::queueBuffers(uint32_t frame, FrameBuffer *input, for (const auto &[stream, buffer] : outputs) { queuedInputBuffers_.push_back(input); queuedOutputBuffers_.push_back(buffer); - process(frame, input, buffer); + int ret = process(frame, input, buffer); + if (ret) { + queuedInputBuffers_.pop_back(); + queuedOutputBuffers_.pop_back(); + return ret; + } } return 0; @@ -413,15 +421,23 @@ void SoftwareIsp::stop() * \param[in] frame The frame number * \param[in] input The input framebuffer * \param[out] output The framebuffer to write the processed frame to + * \return 0 on success, -EAGAIN if a parameter buffer underrun occurs */ -void SoftwareIsp::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output) +int SoftwareIsp::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output) { - /* \todo Provide a real value */ - constexpr uint32_t paramsBufferId = 0; + if (availableParams_.empty()) { + LOG(SoftwareIsp, Error) << "Parameters buffer underrun"; + return -EAGAIN; + } + + const uint32_t paramsBufferId = availableParams_.back(); + availableParams_.pop_back(); ipa_->computeParams(frame, paramsBufferId); debayer_->invokeMethod(&Debayer::process, ConnectionTypeQueued, frame, paramsBufferId, input, output, debayerParams_); + + return 0; } void SoftwareIsp::saveIspParams([[maybe_unused]] const uint32_t paramsBufferId) @@ -429,8 +445,9 @@ void SoftwareIsp::saveIspParams([[maybe_unused]] const uint32_t paramsBufferId) debayerParams_ = *sharedParams_; } -void SoftwareIsp::paramsBufferReady([[maybe_unused]] const uint32_t paramsBufferId) +void SoftwareIsp::paramsBufferReady(const uint32_t paramsBufferId) { + availableParams_.push_back(paramsBufferId); } void SoftwareIsp::setSensorCtrls(const ControlList &sensorControls)