[{"id":35739,"web_url":"https://patchwork.libcamera.org/comment/35739/","msgid":"<175741023797.2127323.13396933237866864867@neptunite.rasen.tech>","date":"2025-09-09T09:30:37","subject":"Re: [PATCH v16 09/12] libcamera: software_isp: Make input buffer\n\tcopying configurable","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Milan,\n\nThanks for the patch.\n\nQuoting Milan Zamazal (2025-07-29 16:31:57)\n> On some platforms, working directly on the input buffer is very slow due\n> to disabled caching.  This is why we copy the input buffer into standard\n> (cached) memory.  This is an unnecessary overhead on platforms with\n> cached buffers.\n> \n> Let's make input buffer copying configurable.  The default is still\n> copying, as it's overhead is much lower than contingent operations on\n> non-cached memory.  Ideally, we should improve this in future to set the\n> default to non-copying if we can be sure under observable circumstances\n> that we are working with cached buffers.\n> \n> Completes software ISP TODO #6.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  Documentation/runtime_configuration.rst     |  2 ++\n>  src/libcamera/software_isp/TODO             | 11 -----------\n>  src/libcamera/software_isp/debayer_cpu.cpp  |  7 +++++--\n>  src/libcamera/software_isp/debayer_cpu.h    |  3 ++-\n>  src/libcamera/software_isp/software_isp.cpp |  3 ++-\n>  5 files changed, 11 insertions(+), 15 deletions(-)\n> \n> diff --git a/Documentation/runtime_configuration.rst b/Documentation/runtime_configuration.rst\n> index 8fd80c311..57285cadb 100644\n> --- a/Documentation/runtime_configuration.rst\n> +++ b/Documentation/runtime_configuration.rst\n> @@ -52,6 +52,7 @@ file structure:\n>            pipeline_handler:\n>              ...\n>        simple:\n> +        copy_input_buffer: # true/false\n>          supported_devices:\n>          - driver: # driver name, e.g. `mxc-isi`\n>            software_isp: # true/false\n> @@ -85,6 +86,7 @@ Configuration file example\n>               min_unicam_buffers: 2\n>               min_total_unicam_buffers: 2\n>         simple:\n> +         copy_input_buffer: false\n>           supported_devices:\n>           - driver: mxc-isi\n>             software_isp: true\n> diff --git a/src/libcamera/software_isp/TODO b/src/libcamera/software_isp/TODO\n> index a50db668e..2c919f442 100644\n> --- a/src/libcamera/software_isp/TODO\n> +++ b/src/libcamera/software_isp/TODO\n> @@ -71,17 +71,6 @@ per-frame buffers like we do for hardware ISPs.\n>  \n>  ---\n>  \n> -6. Input buffer copying configuration\n> -\n> -> DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats)\n> ->      : stats_(std::move(stats)), gammaCorrection_(1.0)\n> -> {\n> ->      enableInputMemcpy_ = true;\n> -\n> -Set this appropriately and/or make it configurable.\n> -\n> ----\n> -\n>  7. Performance measurement configuration\n>  \n>  > void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams params)\n> diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\n> index 66f6038c1..704d4e487 100644\n> --- a/src/libcamera/software_isp/debayer_cpu.cpp\n> +++ b/src/libcamera/software_isp/debayer_cpu.cpp\n> @@ -24,6 +24,7 @@\n>  #include \"libcamera/internal/bayer_format.h\"\n>  #include \"libcamera/internal/dma_buf_allocator.h\"\n>  #include \"libcamera/internal/framebuffer.h\"\n> +#include \"libcamera/internal/global_configuration.h\"\n>  #include \"libcamera/internal/mapped_framebuffer.h\"\n>  \n>  namespace libcamera {\n> @@ -38,8 +39,9 @@ namespace libcamera {\n>  /**\n>   * \\brief Constructs a DebayerCpu object\n>   * \\param[in] stats Pointer to the stats object to use\n> + * \\param[in] configuration The global configuration\n>   */\n> -DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats)\n> +DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration)\n>         : stats_(std::move(stats))\n>  {\n>         /*\n> @@ -50,7 +52,8 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats)\n>          * always set it to true as the safer choice but this should be changed in\n>          * future.\n>          */\n> -       enableInputMemcpy_ = true;\n> +       enableInputMemcpy_ =\n> +               configuration.option<bool>({ \"pipelines\", \"simple\", \"copy_input_buffer\" }).value_or(true);\n\nI like how clean this becomes!\n\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n>  \n>         /* Initialize color lookup tables */\n>         for (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) {\n> diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\n> index 926195e98..2f35aa18b 100644\n> --- a/src/libcamera/software_isp/debayer_cpu.h\n> +++ b/src/libcamera/software_isp/debayer_cpu.h\n> @@ -18,6 +18,7 @@\n>  #include <libcamera/base/object.h>\n>  \n>  #include \"libcamera/internal/bayer_format.h\"\n> +#include \"libcamera/internal/global_configuration.h\"\n>  \n>  #include \"debayer.h\"\n>  #include \"swstats_cpu.h\"\n> @@ -27,7 +28,7 @@ namespace libcamera {\n>  class DebayerCpu : public Debayer, public Object\n>  {\n>  public:\n> -       DebayerCpu(std::unique_ptr<SwStatsCpu> stats);\n> +       DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration);\n>         ~DebayerCpu();\n>  \n>         int configure(const StreamConfiguration &inputCfg,\n> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> index 28e2a360e..b7651b7d2 100644\n> --- a/src/libcamera/software_isp/software_isp.cpp\n> +++ b/src/libcamera/software_isp/software_isp.cpp\n> @@ -114,7 +114,8 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n>         }\n>         stats->statsReady.connect(this, &SoftwareIsp::statsReady);\n>  \n> -       debayer_ = std::make_unique<DebayerCpu>(std::move(stats));\n> +       const GlobalConfiguration &configuration = pipe->cameraManager()->_d()->configuration();\n> +       debayer_ = std::make_unique<DebayerCpu>(std::move(stats), configuration);\n>         debayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady);\n>         debayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady);\n>  \n> -- \n> 2.50.1\n>","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 593EEBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  9 Sep 2025 09:30:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2FCCA6936B;\n\tTue,  9 Sep 2025 11:30:48 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C145069339\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  9 Sep 2025 11:30:44 +0200 (CEST)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:6f3a:4f34:f1fa:8b3])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id F3450605;\n\tTue,  9 Sep 2025 11:29:30 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"RJnbrhex\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1757410171;\n\tbh=76pLjSmS3W9s5xjTZZ9hCrKlD/KygsrcszEgpsLi6lw=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=RJnbrhex3Lw5dhB/7M/E1xGWeI2BCfWWpVpS5/bRrgAw6Ga2s65PRC8XxEzM6+X8S\n\tMESH8k9+MtMdwlNPSnEoEIytrZmJes/YijGB8o12x7xWVsxtZI1dfRUt5C892YO/Zz\n\triX9IlydUdXbH2eodasWbCYwB2RI/+pt55Qox4JU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250729073201.5369-10-mzamazal@redhat.com>","References":"<20250729073201.5369-1-mzamazal@redhat.com>\n\t<20250729073201.5369-10-mzamazal@redhat.com>","Subject":"Re: [PATCH v16 09/12] libcamera: software_isp: Make input buffer\n\tcopying configurable","From":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>, =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?=\n\t<barnabas.pocze@ideasonboard.com>, Laurent Pinchart\n\t<laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Date":"Tue, 09 Sep 2025 18:30:37 +0900","Message-ID":"<175741023797.2127323.13396933237866864867@neptunite.rasen.tech>","User-Agent":"alot/0.0.0","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>"}}]