From patchwork Mon Feb 16 20:30:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 26181 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 5F3AFC0DA4 for ; Mon, 16 Feb 2026 20:31:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F17596223C; Mon, 16 Feb 2026 21:31:07 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="KHqiBGA4"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D04596222B for ; Mon, 16 Feb 2026 21:31:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771273864; 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=668hMHR70XZOb9RF+lQOpoi1B8/acRs0FdbnirSL43I=; b=KHqiBGA40cv4dbZq7jzlkMS4hJm3U4Lpt/fD4/Z3T3R/jHi65GE9Uo3K5Wyr1VNKJXGCTD O0Ns0uCTt+5aDpb7tsMn23ST0WOR2ZQSfYi/FF0I75W89eyoF+C9YvTqkEloftqNHWL5Co Z0wq1dVBdYV+bm+ZW4BTszzVt69f5mg= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-34-TNwyuSzvNSWAmEqAhBoWOw-1; Mon, 16 Feb 2026 15:31:03 -0500 X-MC-Unique: TNwyuSzvNSWAmEqAhBoWOw-1 X-Mimecast-MFC-AGG-ID: TNwyuSzvNSWAmEqAhBoWOw_1771273862 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7C2A219560B7 for ; Mon, 16 Feb 2026 20:31:02 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.32.25]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 57E6218004AD; Mon, 16 Feb 2026 20:31:01 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH v2 12/14] libcamera: software_isp: Track statistics buffers Date: Mon, 16 Feb 2026 21:30:31 +0100 Message-ID: <20260216203034.27558-13-mzamazal@redhat.com> In-Reply-To: <20260216203034.27558-1-mzamazal@redhat.com> References: <20260216203034.27558-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Z7FoDZ5LN0AO1WnbpyzODBKWhimcgBeyDHHU7AAOk00_1771273862 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 passing the shared statistics buffers to IPA, this patch introduces tracking statistics buffer ids. SofwareIsp::availableStats_ is a queue of ids of the buffers available for use. When a fresh statistics 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. We use buffers' file descriptors as buffer ids. The statistics buffers will be shared with the IPA, SwIspStats and debayering and we need their common identification everywhere. The buffer file descriptors are shared unchanged so they can be used for the purpose, avoiding a need to pass a special mapping to the IPA and debayering on initialization. Note that the statistics buffer id is still actually unused, this will be changed once the buffers are shared with the IPA. Signed-off-by: Milan Zamazal --- .../libcamera/internal/software_isp/software_isp.h | 1 + src/libcamera/software_isp/debayer_egl.cpp | 4 ++-- src/libcamera/software_isp/software_isp.cpp | 13 +++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index 1f3eb75f6..45128f25f 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -104,6 +104,7 @@ private: DebayerParams debayerParams_; std::queue availableParams_; bool allocateParamsBuffers(const unsigned int bufferCount); + std::queue availableStats_; std::unique_ptr allocateStatsBuffers( const GlobalConfiguration &configuration, std::vector &fdStats, diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 5715b80ae..66e1fcac2 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -537,7 +537,7 @@ int DebayerEGL::debayerGPU(MappedFrameBuffer &in, int out_fd, const DebayerParam } void DebayerEGL::process(uint32_t frame, - [[maybe_unused]] const uint32_t statsBufferId, + const uint32_t statsBufferId, const uint32_t paramsBufferId, FrameBuffer *input, FrameBuffer *output) @@ -573,7 +573,7 @@ void DebayerEGL::process(uint32_t frame, metadata.planes()[0].bytesused = output->planes()[0].length; /* Calculate stats for the whole frame */ - stats_->processFrame(frame, 0, input); + stats_->processFrame(frame, statsBufferId, input); dmaSyncers.clear(); outputBufferReady.emit(output); diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index a1a9ddbf4..f3ee5773b 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -222,6 +222,7 @@ std::unique_ptr SoftwareIsp::allocateStatsBuffers( unsigned int bufferId = shared.fd().get(); fdStats.emplace_back(shared.fd()); sharedStats->emplace(bufferId, std::move(shared)); + availableStats_.push(bufferId); } auto stats = std::make_unique(configuration, std::move(sharedStats)); @@ -457,11 +458,18 @@ void SoftwareIsp::process(uint32_t frame, FrameBuffer *input, FrameBuffer *outpu while (availableParams_.empty()) ; } + if (availableStats_.empty()) { + LOG(SoftwareIsp, Error) << "Statistics buffer underrun"; + /* Well, busy loop, but this situation shouldn't normally happen. */ + while (availableStats_.empty()) + ; + } const uint32_t paramsBufferId = availableParams_.front(); availableParams_.pop(); + const uint32_t statsBufferId = availableStats_.front(); + availableStats_.pop(); ipa_->computeParams(frame, paramsBufferId); - const uint32_t statsBufferId = 0; debayer_->invokeMethod(&Debayer::process, ConnectionTypeQueued, frame, statsBufferId, paramsBufferId, input, output); @@ -487,8 +495,9 @@ void SoftwareIsp::statsReady(uint32_t frame, const uint32_t statsBufferId) ispStatsReady.emit(frame, statsBufferId); } -void SoftwareIsp::statsProcessed([[maybe_unused]] const uint32_t statsBufferId) +void SoftwareIsp::statsProcessed(const uint32_t statsBufferId) { + availableStats_.push(statsBufferId); } void SoftwareIsp::inputReady(FrameBuffer *input)