From patchwork Mon Aug 12 11:49:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 20882 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 4E457C323E for ; Mon, 12 Aug 2024 11:50:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 830D5633D3; Mon, 12 Aug 2024 13:50:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="C8uoMFJj"; 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 3AE89633C0 for ; Mon, 12 Aug 2024 13:50:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723463434; 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=t/AeldxtUm1Ot/bNwPa6PVHmDctwluBTF6dzD6k2h+E=; b=C8uoMFJjlaBH60UIYHQSfRazK4YCsotzdEFNUxbf/QGBlCWmoMJRUVUG7fccxbPvZRbA2g hpGylGyPhl2HpmIey79Y0NvjhYa7LOc4RIZcF9bI3H1V3w+kS2Uys4xAwtKp49Z60hji99 xGibdz0w6ZqoCOv9Z609jFAKbWPs1l4= Received: from mx-prod-mc-04.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-379-ZxrDM5SsPFyxaCRQR9hprw-1; Mon, 12 Aug 2024 07:50:32 -0400 X-MC-Unique: ZxrDM5SsPFyxaCRQR9hprw-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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 121C9191815B for ; Mon, 12 Aug 2024 11:50:32 +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 D164B19772C4; Mon, 12 Aug 2024 11:50:30 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [PATCH 08/16] libcamera: software_isp: Share parameters buffers with debayering Date: Mon, 12 Aug 2024 13:49:57 +0200 Message-ID: <20240812115009.946036-9-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" Share the multiple parameters buffers with debayering rather than copying the current parameters buffer there. This is done in a similar way as sharing the buffers with IPA in the preceding patch. The last missing step about parameters sharing is to avoid copying the color lookup arrays in debayering, which will be addressed in the next patch. Signed-off-by: Milan Zamazal --- src/libcamera/software_isp/debayer.cpp | 3 +- src/libcamera/software_isp/debayer.h | 3 +- src/libcamera/software_isp/debayer_cpu.cpp | 36 +++++++++++++++------ src/libcamera/software_isp/debayer_cpu.h | 7 ++-- src/libcamera/software_isp/software_isp.cpp | 6 ++-- 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp index 8bd58c3d..52df8c23 100644 --- a/src/libcamera/software_isp/debayer.cpp +++ b/src/libcamera/software_isp/debayer.cpp @@ -94,13 +94,12 @@ Debayer::~Debayer() */ /** - * \fn void Debayer::process(uint32_t frame, const uint32_t paramsBufferId, FrameBuffer *input, FrameBuffer *output, DebayerParams params) + * \fn void Debayer::process(uint32_t frame, const uint32_t paramsBufferId, FrameBuffer *input, FrameBuffer *output) * \brief Process the bayer data into the requested format * \param[in] frame The frame number * \param[in] paramsBufferId The id of the params buffer in use * \param[in] input The input buffer * \param[in] output The output buffer - * \param[in] params The parameters to be used in debayering * * \note DebayerParams is passed by value deliberately so that a copy is passed * when this is run in another thread by invokeMethod(). diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h index 93020735..251b14fd 100644 --- a/src/libcamera/software_isp/debayer.h +++ b/src/libcamera/software_isp/debayer.h @@ -42,8 +42,7 @@ public: virtual void process(uint32_t frame, const uint32_t paramsBufferId, - FrameBuffer *input, FrameBuffer *output, - DebayerParams params) = 0; + FrameBuffer *input, FrameBuffer *output) = 0; virtual SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) = 0; diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index 20a15ae0..af08ab10 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -11,9 +11,10 @@ #include "debayer_cpu.h" -#include #include +#include + #include #include "libcamera/internal/bayer_format.h" @@ -32,8 +33,10 @@ namespace libcamera { /** * \brief Constructs a DebayerCpu object * \param[in] stats Pointer to the stats object to use + * \param[in] paramBuffers SharedFDs of parameter buffers */ -DebayerCpu::DebayerCpu(std::unique_ptr stats) +DebayerCpu::DebayerCpu(std::unique_ptr stats, + const std::vector ¶mBuffers) : stats_(std::move(stats)) { /* @@ -49,6 +52,20 @@ DebayerCpu::DebayerCpu(std::unique_ptr stats) /* Initialize color lookup tables */ for (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) red_[i] = green_[i] = blue_[i] = i; + + paramsBuffers_ = std::map(); + + for (auto &sharedFd : paramBuffers) { + void *mem = mmap(nullptr, sizeof(DebayerParams), PROT_WRITE, + MAP_SHARED, sharedFd.get(), 0); + if (mem == MAP_FAILED) { + LOG(Debayer, Error) << "Unable to map Parameters"; + return; + } + + ASSERT(sharedFd.get() >= 0); + paramsBuffers_[sharedFd.get()] = static_cast(mem); + } } DebayerCpu::~DebayerCpu() = default; @@ -608,8 +625,7 @@ void DebayerCpu::memcpyNextLine(const uint8_t *linePointers[]) memcpy(lineBuffers_[lineBufferIndex_].data(), linePointers[patternHeight] - lineBufferPadding_, lineBufferLength_); - linePointers[patternHeight] = lineBuffers_[lineBufferIndex_].data() - + lineBufferPadding_; + linePointers[patternHeight] = lineBuffers_[lineBufferIndex_].data() + lineBufferPadding_; lineBufferIndex_ = (lineBufferIndex_ + 1) % (patternHeight + 1); } @@ -726,7 +742,7 @@ static inline int64_t timeDiff(timespec &after, timespec &before) void DebayerCpu::process(uint32_t frame, const uint32_t paramsBufferId, - FrameBuffer *input, FrameBuffer *output, DebayerParams params) + FrameBuffer *input, FrameBuffer *output) { timespec frameStartTime; @@ -735,12 +751,14 @@ void DebayerCpu::process(uint32_t frame, clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime); } - green_ = params.green; - red_ = swapRedBlueGains_ ? params.blue : params.red; - blue_ = swapRedBlueGains_ ? params.red : params.blue; - + DebayerParams *params = paramsBuffers_.at(paramsBufferId); releaseIspParams.emit(paramsBufferId); + /* \todo Avoid copying here. */ + green_ = params->green; + red_ = swapRedBlueGains_ ? params->blue : params->red; + blue_ = swapRedBlueGains_ ? params->red : params->blue; + /* Copy metadata from the input buffer */ FrameMetadata &metadata = output->_d()->metadata(); metadata.status = input->metadata().status; diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index 0b5a5258..324fc6c0 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -16,6 +16,7 @@ #include #include +#include #include "libcamera/internal/bayer_format.h" @@ -27,7 +28,8 @@ namespace libcamera { class DebayerCpu : public Debayer, public Object { public: - DebayerCpu(std::unique_ptr stats); + DebayerCpu(std::unique_ptr stats, + const std::vector ¶mBuffers); ~DebayerCpu(); int configure(const StreamConfiguration &inputCfg, @@ -38,7 +40,7 @@ public: strideAndFrameSize(const PixelFormat &outputFormat, const Size &size); void process(uint32_t frame, const uint32_t paramsBufferId, - FrameBuffer *input, FrameBuffer *output, DebayerParams params); + FrameBuffer *input, FrameBuffer *output); SizeRange sizes(PixelFormat inputFormat, const Size &inputSize); /** @@ -160,6 +162,7 @@ private: /* Skip 30 frames for things to stabilize then measure 30 frames */ static constexpr unsigned int kFramesToSkip = 30; static constexpr unsigned int kLastFrameToMeasure = 60; + std::map paramsBuffers_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 480ecf6e..db77f6f9 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -86,10 +86,11 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, } stats->statsReady.connect(this, &SoftwareIsp::statsReady); - debayer_ = std::make_unique(std::move(stats)); std::vector fdParams; for (auto &item : sharedParams_) fdParams.emplace_back(item.second.fd()); + + debayer_ = std::make_unique(std::move(stats), fdParams); debayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady); debayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady); debayer_->releaseIspParams.connect(this, &SoftwareIsp::releaseIspParams); @@ -385,9 +386,8 @@ void SoftwareIsp::process(uint32_t frame, FrameBuffer *input, FrameBuffer *outpu const uint32_t paramsBufferId = availableParams_.front(); availableParams_.pop(); ipa_->prepare(frame, paramsBufferId); - debayerParams_ = *sharedParams_.at(paramsBufferId); debayer_->invokeMethod(&DebayerCpu::process, - ConnectionTypeQueued, frame, paramsBufferId, input, output, debayerParams_); + ConnectionTypeQueued, frame, paramsBufferId, input, output); } void SoftwareIsp::saveIspParams(uint32_t paramsBufferId)