Patch Detail
Show a patch.
GET /api/1.1/patches/20882/?format=api
{ "id": 20882, "url": "https://patchwork.libcamera.org/api/1.1/patches/20882/?format=api", "web_url": "https://patchwork.libcamera.org/patch/20882/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20240812115009.946036-9-mzamazal@redhat.com>", "date": "2024-08-12T11:49:57", "name": "[08/16] libcamera: software_isp: Share parameters buffers with debayering", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "40653d3e70dcf0bf65d134d40c79ebd64f9b8271", "submitter": { "id": 177, "url": "https://patchwork.libcamera.org/api/1.1/people/177/?format=api", "name": "Milan Zamazal", "email": "mzamazal@redhat.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/20882/mbox/", "series": [ { "id": 4511, "url": "https://patchwork.libcamera.org/api/1.1/series/4511/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4511", "date": "2024-08-12T11:49:49", "name": "Software ISP: Share params and stats buffers", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4511/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/20882/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/20882/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 4E457C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Aug 2024 11:50:41 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 830D5633D3;\n\tMon, 12 Aug 2024 13:50:40 +0200 (CEST)", "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3AE89633C0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2024 13:50:35 +0200 (CEST)", "from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-379-ZxrDM5SsPFyxaCRQR9hprw-1;\n\tMon, 12 Aug 2024 07:50:32 -0400", "from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.15])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS\n\tid 121C9191815B for <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2024 11:50:32 +0000 (UTC)", "from nuthatch.redhat.com (unknown [10.45.225.57])\n\tby mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id D164B19772C4; Mon, 12 Aug 2024 11:50:30 +0000 (UTC)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"C8uoMFJj\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1723463434;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=t/AeldxtUm1Ot/bNwPa6PVHmDctwluBTF6dzD6k2h+E=;\n\tb=C8uoMFJjlaBH60UIYHQSfRazK4YCsotzdEFNUxbf/QGBlCWmoMJRUVUG7fccxbPvZRbA2g\n\thpGylGyPhl2HpmIey79Y0NvjhYa7LOc4RIZcF9bI3H1V3w+kS2Uys4xAwtKp49Z60hji99\n\txGibdz0w6ZqoCOv9Z609jFAKbWPs1l4=", "X-MC-Unique": "ZxrDM5SsPFyxaCRQR9hprw-1", "From": "Milan Zamazal <mzamazal@redhat.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Milan Zamazal <mzamazal@redhat.com>", "Subject": "[PATCH 08/16] libcamera: software_isp: Share parameters buffers with\n\tdebayering", "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", "Content-Transfer-Encoding": "8bit", "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": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Share the multiple parameters buffers with debayering rather than\ncopying the current parameters buffer there. This is done in a similar\nway as sharing the buffers with IPA in the preceding patch.\n\nThe last missing step about parameters sharing is to avoid copying the\ncolor lookup arrays in debayering, which will be addressed in the next\npatch.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n src/libcamera/software_isp/debayer.cpp | 3 +-\n src/libcamera/software_isp/debayer.h | 3 +-\n src/libcamera/software_isp/debayer_cpu.cpp | 36 +++++++++++++++------\n src/libcamera/software_isp/debayer_cpu.h | 7 ++--\n src/libcamera/software_isp/software_isp.cpp | 6 ++--\n 5 files changed, 37 insertions(+), 18 deletions(-)", "diff": "diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp\nindex 8bd58c3d..52df8c23 100644\n--- a/src/libcamera/software_isp/debayer.cpp\n+++ b/src/libcamera/software_isp/debayer.cpp\n@@ -94,13 +94,12 @@ Debayer::~Debayer()\n */\n \n /**\n- * \\fn void Debayer::process(uint32_t frame, const uint32_t paramsBufferId, FrameBuffer *input, FrameBuffer *output, DebayerParams params)\n+ * \\fn void Debayer::process(uint32_t frame, const uint32_t paramsBufferId, FrameBuffer *input, FrameBuffer *output)\n * \\brief Process the bayer data into the requested format\n * \\param[in] frame The frame number\n * \\param[in] paramsBufferId The id of the params buffer in use\n * \\param[in] input The input buffer\n * \\param[in] output The output buffer\n- * \\param[in] params The parameters to be used in debayering\n *\n * \\note DebayerParams is passed by value deliberately so that a copy is passed\n * when this is run in another thread by invokeMethod().\ndiff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h\nindex 93020735..251b14fd 100644\n--- a/src/libcamera/software_isp/debayer.h\n+++ b/src/libcamera/software_isp/debayer.h\n@@ -42,8 +42,7 @@ public:\n \n \tvirtual void process(uint32_t frame,\n \t\t\t const uint32_t paramsBufferId,\n-\t\t\t FrameBuffer *input, FrameBuffer *output,\n-\t\t\t DebayerParams params) = 0;\n+\t\t\t FrameBuffer *input, FrameBuffer *output) = 0;\n \n \tvirtual SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) = 0;\n \ndiff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex 20a15ae0..af08ab10 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -11,9 +11,10 @@\n \n #include \"debayer_cpu.h\"\n \n-#include <stdlib.h>\n #include <time.h>\n \n+#include <libcamera/base/shared_fd.h>\n+\n #include <libcamera/formats.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n@@ -32,8 +33,10 @@ namespace libcamera {\n /**\n * \\brief Constructs a DebayerCpu object\n * \\param[in] stats Pointer to the stats object to use\n+ * \\param[in] paramBuffers SharedFDs of parameter buffers\n */\n-DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats)\n+DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats,\n+\t\t const std::vector<SharedFD> ¶mBuffers)\n \t: stats_(std::move(stats))\n {\n \t/*\n@@ -49,6 +52,20 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats)\n \t/* Initialize color lookup tables */\n \tfor (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++)\n \t\tred_[i] = green_[i] = blue_[i] = i;\n+\n+\tparamsBuffers_ = std::map<unsigned int, DebayerParams *>();\n+\n+\tfor (auto &sharedFd : paramBuffers) {\n+\t\tvoid *mem = mmap(nullptr, sizeof(DebayerParams), PROT_WRITE,\n+\t\t\t\t MAP_SHARED, sharedFd.get(), 0);\n+\t\tif (mem == MAP_FAILED) {\n+\t\t\tLOG(Debayer, Error) << \"Unable to map Parameters\";\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tASSERT(sharedFd.get() >= 0);\n+\t\tparamsBuffers_[sharedFd.get()] = static_cast<DebayerParams *>(mem);\n+\t}\n }\n \n DebayerCpu::~DebayerCpu() = default;\n@@ -608,8 +625,7 @@ void DebayerCpu::memcpyNextLine(const uint8_t *linePointers[])\n \tmemcpy(lineBuffers_[lineBufferIndex_].data(),\n \t linePointers[patternHeight] - lineBufferPadding_,\n \t lineBufferLength_);\n-\tlinePointers[patternHeight] = lineBuffers_[lineBufferIndex_].data()\n-\t\t\t\t + lineBufferPadding_;\n+\tlinePointers[patternHeight] = lineBuffers_[lineBufferIndex_].data() + lineBufferPadding_;\n \n \tlineBufferIndex_ = (lineBufferIndex_ + 1) % (patternHeight + 1);\n }\n@@ -726,7 +742,7 @@ static inline int64_t timeDiff(timespec &after, timespec &before)\n \n void DebayerCpu::process(uint32_t frame,\n \t\t\t const uint32_t paramsBufferId,\n-\t\t\t FrameBuffer *input, FrameBuffer *output, DebayerParams params)\n+\t\t\t FrameBuffer *input, FrameBuffer *output)\n {\n \ttimespec frameStartTime;\n \n@@ -735,12 +751,14 @@ void DebayerCpu::process(uint32_t frame,\n \t\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime);\n \t}\n \n-\tgreen_ = params.green;\n-\tred_ = swapRedBlueGains_ ? params.blue : params.red;\n-\tblue_ = swapRedBlueGains_ ? params.red : params.blue;\n-\n+\tDebayerParams *params = paramsBuffers_.at(paramsBufferId);\n \treleaseIspParams.emit(paramsBufferId);\n \n+\t/* \\todo Avoid copying here. */\n+\tgreen_ = params->green;\n+\tred_ = swapRedBlueGains_ ? params->blue : params->red;\n+\tblue_ = swapRedBlueGains_ ? params->red : params->blue;\n+\n \t/* Copy metadata from the input buffer */\n \tFrameMetadata &metadata = output->_d()->metadata();\n \tmetadata.status = input->metadata().status;\ndiff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\nindex 0b5a5258..324fc6c0 100644\n--- a/src/libcamera/software_isp/debayer_cpu.h\n+++ b/src/libcamera/software_isp/debayer_cpu.h\n@@ -16,6 +16,7 @@\n #include <vector>\n \n #include <libcamera/base/object.h>\n+#include <libcamera/base/shared_fd.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n \n@@ -27,7 +28,8 @@ namespace libcamera {\n class DebayerCpu : public Debayer, public Object\n {\n public:\n-\tDebayerCpu(std::unique_ptr<SwStatsCpu> stats);\n+\tDebayerCpu(std::unique_ptr<SwStatsCpu> stats,\n+\t\t const std::vector<SharedFD> ¶mBuffers);\n \t~DebayerCpu();\n \n \tint configure(const StreamConfiguration &inputCfg,\n@@ -38,7 +40,7 @@ public:\n \tstrideAndFrameSize(const PixelFormat &outputFormat, const Size &size);\n \tvoid process(uint32_t frame,\n \t\t const uint32_t paramsBufferId,\n-\t\t FrameBuffer *input, FrameBuffer *output, DebayerParams params);\n+\t\t FrameBuffer *input, FrameBuffer *output);\n \tSizeRange sizes(PixelFormat inputFormat, const Size &inputSize);\n \n \t/**\n@@ -160,6 +162,7 @@ private:\n \t/* Skip 30 frames for things to stabilize then measure 30 frames */\n \tstatic constexpr unsigned int kFramesToSkip = 30;\n \tstatic constexpr unsigned int kLastFrameToMeasure = 60;\n+\tstd::map<unsigned int, DebayerParams *> paramsBuffers_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\nindex 480ecf6e..db77f6f9 100644\n--- a/src/libcamera/software_isp/software_isp.cpp\n+++ b/src/libcamera/software_isp/software_isp.cpp\n@@ -86,10 +86,11 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n \t}\n \tstats->statsReady.connect(this, &SoftwareIsp::statsReady);\n \n-\tdebayer_ = std::make_unique<DebayerCpu>(std::move(stats));\n \tstd::vector<SharedFD> fdParams;\n \tfor (auto &item : sharedParams_)\n \t\tfdParams.emplace_back(item.second.fd());\n+\n+\tdebayer_ = std::make_unique<DebayerCpu>(std::move(stats), fdParams);\n \tdebayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady);\n \tdebayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady);\n \tdebayer_->releaseIspParams.connect(this, &SoftwareIsp::releaseIspParams);\n@@ -385,9 +386,8 @@ void SoftwareIsp::process(uint32_t frame, FrameBuffer *input, FrameBuffer *outpu\n \tconst uint32_t paramsBufferId = availableParams_.front();\n \tavailableParams_.pop();\n \tipa_->prepare(frame, paramsBufferId);\n-\tdebayerParams_ = *sharedParams_.at(paramsBufferId);\n \tdebayer_->invokeMethod(&DebayerCpu::process,\n-\t\t\t ConnectionTypeQueued, frame, paramsBufferId, input, output, debayerParams_);\n+\t\t\t ConnectionTypeQueued, frame, paramsBufferId, input, output);\n }\n \n void SoftwareIsp::saveIspParams(uint32_t paramsBufferId)\n", "prefixes": [ "08/16" ] }