From patchwork Mon Aug 12 11:50:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 20887 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 0AACBC324E for ; Mon, 12 Aug 2024 11:50:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7E6B8633D9; Mon, 12 Aug 2024 13:50:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="bA/RPFGE"; 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 9C786633C7 for ; Mon, 12 Aug 2024 13:50:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723463441; 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=RYkEQqU4OQMZuH1F9JMEKFSiqPXzGv1mheEG5il1IjA=; b=bA/RPFGEW4kEj1hnjWZ7tcLKJv848N0Nra7hYIv6T0DrSN1DAnEK7ksKKmKareILZ/CUD+ BY1vmbjIFxGCmCA7aGt52Ss686Zrg3NTIAdoM4zcipNagZ1PBgTv7gWztLiU9fVPSJ1Y0E 5dqhifovCbqTKC0DmHwwBLkgcwf7eTg= Received: from mx-prod-mc-05.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-657-sN3QjctLOk6o-JQBfG5abA-1; Mon, 12 Aug 2024 07:50:40 -0400 X-MC-Unique: sN3QjctLOk6o-JQBfG5abA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9749B1955F3D for ; Mon, 12 Aug 2024 11:50:39 +0000 (UTC) Received: from nuthatch.redhat.com (unknown [10.45.225.57]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8B9C419772C4; Mon, 12 Aug 2024 11:50:38 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [PATCH 13/16] libcamera: software_isp: Allocate statistics buffers Date: Mon, 12 Aug 2024 13:50:02 +0200 Message-ID: <20240812115009.946036-14-mzamazal@redhat.com> In-Reply-To: <20240812115009.946036-1-mzamazal@redhat.com> References: <20240812115009.946036-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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" In order to be able to use multiple shared statistics buffers, we must allocate them. They are allocated in SoftwareIsp and passed to SwIspStats. This changes the previous behavior when the (single) shared statistics buffer was created in SwIspStats. Centralizing it to SoftwareIsp makes sharing multiple buffers with IPA easier. Currently only one of the allocated buffers is used. This will be changed once the buffers are shared with IPA in a followup patch. Signed-off-by: Milan Zamazal --- .../internal/software_isp/software_isp.h | 5 +++ src/libcamera/software_isp/software_isp.cpp | 44 ++++++++++++++++--- src/libcamera/software_isp/swstats_cpu.cpp | 16 ++++--- src/libcamera/software_isp/swstats_cpu.h | 9 ++-- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index ae64b247..a6ba4a07 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -33,6 +33,8 @@ #include "libcamera/internal/shared_mem_object.h" #include "libcamera/internal/software_isp/debayer_params.h" +#include "software_isp/swstats_cpu.h" + namespace libcamera { class DebayerCpu; @@ -100,6 +102,9 @@ private: DebayerParams debayerParams_; std::queue availableParams_; bool allocateParamsBuffers(const unsigned int bufferCount); + std::unique_ptr allocateStatsBuffers( + std::vector &fdStats, + const unsigned int bufferCount); DmaBufAllocator dmaHeap_; std::unique_ptr ipa_; diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 5d9f5008..1e224b6f 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include @@ -20,7 +22,9 @@ #include #include "libcamera/internal/ipa_manager.h" +#include "libcamera/internal/shared_mem_object.h" #include "libcamera/internal/software_isp/debayer_params.h" +#include "libcamera/internal/software_isp/swisp_stats.h" #include "debayer_cpu.h" @@ -79,17 +83,15 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, if (!allocateParamsBuffers(bufferCount)) return; - auto stats = std::make_unique(); - if (!stats->isValid()) { - LOG(SoftwareIsp, Error) << "Failed to create SwStatsCpu object"; - return; - } - stats->statsReady.connect(this, &SoftwareIsp::statsReady); - std::vector fdParams; for (auto &item : sharedParams_) fdParams.emplace_back(item.second.fd()); + std::vector fdStats; + auto stats = allocateStatsBuffers(fdStats, bufferCount); + if (!stats) + return; + debayer_ = std::make_unique(std::move(stats), fdParams); debayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady); debayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady); @@ -169,6 +171,34 @@ bool SoftwareIsp::allocateParamsBuffers(const unsigned int bufferCount) return true; } +std::unique_ptr SoftwareIsp::allocateStatsBuffers( + std::vector &fdStats, + const unsigned int bufferCount) +{ + auto sharedStats = std::make_unique>>(); + for (unsigned int i = 0; i < bufferCount; i++) { + auto shared = SharedMemObject("softIsp_stats"); + if (!shared) { + LOG(SoftwareIsp, Error) << "Failed to create shared memory for statistics"; + return std::unique_ptr(); + } + if (!shared.fd().isValid()) { + LOG(SoftwareIsp, Error) << "Invalid fd of shared statistics"; + return std::unique_ptr(); + } + + ASSERT(shared.fd().get() >= 0); + unsigned int bufferId = shared.fd().get(); + fdStats.emplace_back(shared.fd()); + sharedStats->emplace(bufferId, std::move(shared)); + } + + auto stats = std::make_unique(std::move(sharedStats)); + stats->statsReady.connect(this, &SoftwareIsp::statsReady); + + return stats; +} + /** * \fn int SoftwareIsp::loadConfiguration([[maybe_unused]] const std::string &filename) * \brief Load a configuration from a file diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index b8ee06a0..cb411a18 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -11,6 +11,8 @@ #include "swstats_cpu.h" +#include + #include #include @@ -129,12 +131,14 @@ namespace libcamera { LOG_DEFINE_CATEGORY(SwStatsCpu) -SwStatsCpu::SwStatsCpu() - : sharedStats_("softIsp_stats") +/** + * \brief The constructor of SwStatsCpu + * \param [in] sharedStats Mapping of statistics buffer ids to statistics + * instances that are shared with the IPA + */ +SwStatsCpu::SwStatsCpu(std::unique_ptr>> sharedStats) + : sharedStats_(std::move(sharedStats)) { - if (!sharedStats_) - LOG(SwStatsCpu, Error) - << "Failed to create shared memory for statistics"; } static constexpr unsigned int kRedYMul = 77; /* 0.299 * 256 */ @@ -316,7 +320,7 @@ void SwStatsCpu::startFrame([[maybe_unused]] const uint32_t statsBufferId) */ void SwStatsCpu::finishFrame(uint32_t frame, const uint32_t statsBufferId) { - *sharedStats_ = stats_; + *(sharedStats_->at(statsBufferId)) = stats_; statsReady.emit(frame, statsBufferId); } diff --git a/src/libcamera/software_isp/swstats_cpu.h b/src/libcamera/software_isp/swstats_cpu.h index 402eef2d..fbdea4a3 100644 --- a/src/libcamera/software_isp/swstats_cpu.h +++ b/src/libcamera/software_isp/swstats_cpu.h @@ -11,6 +11,7 @@ #pragma once +#include #include #include @@ -29,12 +30,12 @@ struct StreamConfiguration; class SwStatsCpu { public: - SwStatsCpu(); + SwStatsCpu(std::unique_ptr>> sharedStats); ~SwStatsCpu() = default; - bool isValid() const { return sharedStats_.fd().isValid(); } + bool isValid() const { return sharedStats_->begin()->second.fd().isValid(); } - const SharedFD &getStatsFD() { return sharedStats_.fd(); } + const SharedFD &getStatsFD() { return sharedStats_->begin()->second.fd(); } const Size &patternSize() { return patternSize_; } @@ -90,7 +91,7 @@ private: unsigned int xShift_; - SharedMemObject sharedStats_; + std::unique_ptr>> sharedStats_; SwIspStats stats_; };