[{"id":35933,"web_url":"https://patchwork.libcamera.org/comment/35933/","msgid":"<20250921024932.GA30137@pendragon.ideasonboard.com>","date":"2025-09-21T02:49:32","subject":"Re: [PATCH v18 09/12] libcamera: software_isp: Make input buffer\n\tcopying configurable","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Milan,\n\nThank you for the patch.\n\nOn Fri, Sep 12, 2025 at 04:29:11PM +0200, Milan Zamazal wrote:\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 its 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\nYes, that should be automatic in the future. I suppose it replaces TODO\n#6 :-)\n\n> Completes software ISP TODO #6.\n> \n> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  Documentation/runtime_configuration.rst     | 13 +++++++++++++\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, 22 insertions(+), 15 deletions(-)\n> \n> diff --git a/Documentation/runtime_configuration.rst b/Documentation/runtime_configuration.rst\n> index 8792232d7..6610e8bec 100644\n> --- a/Documentation/runtime_configuration.rst\n> +++ b/Documentation/runtime_configuration.rst\n> @@ -55,6 +55,8 @@ file structure:\n>          supported_devices:\n>          - driver: # driver name, e.g. `mxc-isi`\n>            software_isp: # true/false\n> +    software_isp:\n> +      copy_input_buffer: # true/false\n\nIt may be useful to set this option on a per-camera basis, but I would\nprefer working on automating the default instead. In any case, that's\nfor later.\n\n>  \n>  Configuration file example\n>  --------------------------\n> @@ -88,6 +90,8 @@ Configuration file example\n>           supported_devices:\n>           - driver: mxc-isi\n>             software_isp: true\n> +     software_isp:\n> +       copy_input_buffer: false\n>  \n>  List of variables and configuration options\n>  -------------------------------------------\n> @@ -154,6 +158,15 @@ pipelines.simple.supported_devices.driver, pipelines.simple.supported_devices.so\n>  \n>     Example `software_isp` value: ``true``\n>  \n> +software_isp.copy_input_buffer\n> +   Define whether input buffers should be copied into standard (cached)\n> +   memory in software ISP. This is done by default to prevent very slow\n> +   processing on platforms with non-cached buffers. It can be set to\n> +   false on platforms with cached buffers to avoid an unnecessary\n> +   overhead.\n> +\n> +   Example value: ``false``\n> +\n>  Further details\n>  ---------------\n>  \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> -> \t: stats_(std::move(stats)), gammaCorrection_(1.0)\n> -> {\n> -> \tenableInputMemcpy_ = 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..cec6cc6be 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>  \t: stats_(std::move(stats))\n>  {\n>  \t/*\n> @@ -50,7 +52,8 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats)\n>  \t * always set it to true as the safer choice but this should be changed in\n>  \t * future.\n>  \t */\n\nI'll add a\n\n\t/*\n\t * \\todo Make memcpy automatic based on runtime detection of platform\n\t * capabilities.\n\t */\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> -\tenableInputMemcpy_ = true;\n> +\tenableInputMemcpy_ =\n> +\t\tconfiguration.option<bool>({ \"software_isp\", \"copy_input_buffer\" }).value_or(true);\n>  \n>  \t/* Initialize color lookup tables */\n>  \tfor (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> -\tDebayerCpu(std::unique_ptr<SwStatsCpu> stats);\n> +\tDebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration);\n>  \t~DebayerCpu();\n>  \n>  \tint 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>  \t}\n>  \tstats->statsReady.connect(this, &SoftwareIsp::statsReady);\n>  \n> -\tdebayer_ = std::make_unique<DebayerCpu>(std::move(stats));\n> +\tconst GlobalConfiguration &configuration = pipe->cameraManager()->_d()->configuration();\n> +\tdebayer_ = std::make_unique<DebayerCpu>(std::move(stats), configuration);\n>  \tdebayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady);\n>  \tdebayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady);\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 BE170C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 21 Sep 2025 02:50:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 79A4A6B59C;\n\tSun, 21 Sep 2025 04:50:04 +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 4705762C35\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 21 Sep 2025 04:50:03 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 6F7E26A6;\n\tSun, 21 Sep 2025 04:48:41 +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=\"ju6l+8f2\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1758422921;\n\tbh=YMXKy/jks0QSxdCuI2lsUqjaZSh59873wpOPGOW3zGM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ju6l+8f2NldVqG0BRo7K8p66bMDrcNeqRuce53tQ1Fzzi9qA9nKthRA/bHfhJbjkp\n\tkF2WsM44rbSvMhLuXjXjyRlSnqD8aE3P0GBd9lsnrF5j0XRtOtx3QNvW/P2TjcAWKh\n\t8gWhTvpINT4im8G08dvfxlFBh/pkW/AsQ0C47qZE=","Date":"Sun, 21 Sep 2025 05:49:32 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>, =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?=\n\t<barnabas.pocze@ideasonboard.com>, Paul Elder\n\t<paul.elder@ideasonboard.com>","Subject":"Re: [PATCH v18 09/12] libcamera: software_isp: Make input buffer\n\tcopying configurable","Message-ID":"<20250921024932.GA30137@pendragon.ideasonboard.com>","References":"<20250912142915.53949-1-mzamazal@redhat.com>\n\t<20250912142915.53949-11-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250912142915.53949-11-mzamazal@redhat.com>","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>"}}]