[{"id":31286,"web_url":"https://patchwork.libcamera.org/comment/31286/","msgid":"<95efc3add89043f91b6f8089cb93587912103138.camel@ndufresne.ca>","date":"2024-09-20T16:52:20","subject":"Re: [PATCH v5] libcamera: debayer_cpu: Sync DMABUFs","submitter":{"id":30,"url":"https://patchwork.libcamera.org/api/people/30/","name":"Nicolas Dufresne","email":"nicolas@ndufresne.ca"},"content":"Hi,\n\nLe vendredi 20 septembre 2024 à 12:49 +0100, Kieran Bingham a écrit :\n> From: Robert Mader <robert.mader@collabora.com>\n> \n> Using `DMA_BUF_IOCTL_SYNC` is required for DMABUFs in order to ensure\n> correct output. Not doing so currently results in occasional tearing\n> and/or backlashes in GL/VK clients that use the buffers directly for\n> rendering.\n> \n> An alternative approach to have the sync code in `MappedFrameBuffer` was\n> considered but rejected for now, in order to allow clients more\n> flexibility.\n> \n> While the new helper is added to an annoymous namespace, add\n> timeDiff to the same namespace and remove the static definition as a\n> drive by.\n> \n> Signed-off-by: Robert Mader <robert.mader@collabora.com>\n> Tested-by: Milan Zamazal <mzamazal@redhat.com> # Debix\n> Tested-by: Hans de Goede <hdegoede@redhat.com> # IPU6 + ov2740\n> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com> # Lenovo X13s + OV5675\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nIf we generalize this in the future, a more C++ friendly implementation would be\nnice. I'd see something similar to the mutex locker, something you can't forget\nto close.\n\nReviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> v5: Kieran:\n>  - Remove static\n>  - Fix ret negation that I suggested incorrectly.\n> \n>  src/libcamera/software_isp/debayer_cpu.cpp | 32 +++++++++++++++++++++-\n>  1 file changed, 31 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\n> index 077f7f4bc45b..8a757fe9e02d 100644\n> --- a/src/libcamera/software_isp/debayer_cpu.cpp\n> +++ b/src/libcamera/software_isp/debayer_cpu.cpp\n> @@ -12,8 +12,11 @@\n>  #include \"debayer_cpu.h\"\n>  \n>  #include <stdlib.h>\n> +#include <sys/ioctl.h>\n>  #include <time.h>\n>  \n> +#include <linux/dma-buf.h>\n> +\n>  #include <libcamera/formats.h>\n>  \n>  #include \"libcamera/internal/bayer_format.h\"\n> @@ -718,12 +721,33 @@ void DebayerCpu::process4(const uint8_t *src, uint8_t *dst)\n>  \t}\n>  }\n>  \n> -static inline int64_t timeDiff(timespec &after, timespec &before)\n> +namespace {\n> +\n> +void syncBufferForCPU(FrameBuffer *buffer, uint64_t syncFlags)\n> +{\n> +\tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n> +\t\tconst int fd = plane.fd.get();\n> +\t\tstruct dma_buf_sync sync = { syncFlags };\n> +\t\tint ret;\n> +\n> +\t\tret = ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);\n> +\t\tif (ret < 0) {\n> +\t\t\tret = errno;\n> +\t\t\tLOG(Debayer, Error)\n> +\t\t\t\t<< \"Syncing buffer FD \" << fd << \" with flags \"\n> +\t\t\t\t<< syncFlags << \" failed: \" << strerror(ret);\n> +\t\t}\n> +\t}\n> +}\n> +\n> +inline int64_t timeDiff(timespec &after, timespec &before)\n>  {\n>  \treturn (after.tv_sec - before.tv_sec) * 1000000000LL +\n>  \t       (int64_t)after.tv_nsec - (int64_t)before.tv_nsec;\n>  }\n>  \n> +} /* namespace */\n> +\n>  void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams params)\n>  {\n>  \ttimespec frameStartTime;\n> @@ -733,6 +757,9 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams\n>  \t\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime);\n>  \t}\n>  \n> +\tsyncBufferForCPU(input, DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ);\n> +\tsyncBufferForCPU(output, DMA_BUF_SYNC_START | DMA_BUF_SYNC_WRITE);\n> +\n>  \tgreen_ = params.green;\n>  \tred_ = swapRedBlueGains_ ? params.blue : params.red;\n>  \tblue_ = swapRedBlueGains_ ? params.red : params.blue;\n> @@ -760,6 +787,9 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams\n>  \n>  \tmetadata.planes()[0].bytesused = out.planes()[0].size();\n>  \n> +\tsyncBufferForCPU(output, DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE);\n> +\tsyncBufferForCPU(input, DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ);\n> +\n>  \t/* Measure before emitting signals */\n>  \tif (measuredFrames_ < DebayerCpu::kLastFrameToMeasure &&\n>  \t    ++measuredFrames_ > DebayerCpu::kFramesToSkip) {","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 5B39AC324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Sep 2024 16:52:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 10AFA634F5;\n\tFri, 20 Sep 2024 18:52:26 +0200 (CEST)","from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com\n\t[IPv6:2607:f8b0:4864:20::f30])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4816C618E2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Sep 2024 18:52:23 +0200 (CEST)","by mail-qv1-xf30.google.com with SMTP id\n\t6a1803df08f44-6c3552ce7faso18612566d6.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Sep 2024 09:52:23 -0700 (PDT)","from nicolas-tpx395.lan ([2606:6d00:15:862e::580])\n\tby smtp.gmail.com with ESMTPSA id\n\t6a1803df08f44-6c75e470546sm19843966d6.55.2024.09.20.09.52.21\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 20 Sep 2024 09:52:21 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=ndufresne-ca.20230601.gappssmtp.com\n\theader.i=@ndufresne-ca.20230601.gappssmtp.com\n\theader.b=\"qjR1M1kp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ndufresne-ca.20230601.gappssmtp.com; s=20230601; t=1726851142;\n\tx=1727455942; darn=lists.libcamera.org; \n\th=mime-version:user-agent:content-transfer-encoding:references\n\t:in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject\n\t:date:message-id:reply-to;\n\tbh=pUfuT75YMaW2O9OUsL0KPB9LzfOs/JtXIHUnq864guE=;\n\tb=qjR1M1kpMKoQ0Vxx/AWgqLXgM6yF23JrwBEEOVdWHJzmZxs4j+9zaGX9OgRX6nwVMY\n\txsDjbb5/ae/rBw4RS1D3hk/HsofNufaDvSNVCT92kPjU1exu/RwlL5bi5zet0ogJef3S\n\t08Rr0ewrEUKZfxVjLgeV5kcJx6Yl9MJ0Km0yS9Cs3hOslH8ik5mlfRmiBjGoJxahE7O1\n\tMKQIeHtjzlES3UJsh8R6+Srh+yE+hfiE69h+6qkTG2m7ejGFpKL52a+b4V+9ehjj9Z2m\n\tIUyvKTajpYPJUt+Uz7fWoJWU3vcn2uHsAxvhHrBDgtHHrtIx+4IfGLa0egltN1lkY0ri\n\tprFw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1726851142; x=1727455942;\n\th=mime-version:user-agent:content-transfer-encoding:references\n\t:in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state\n\t:from:to:cc:subject:date:message-id:reply-to;\n\tbh=pUfuT75YMaW2O9OUsL0KPB9LzfOs/JtXIHUnq864guE=;\n\tb=q77O7kjAtpxkN8j63m7yoMoBDONfZksl36uYujRJB11U/bACKdTql8L1Erm21Zas+x\n\txP0PVkz55PTt8hO1gUab4bkuoFQI7MAJWcQVufofgH0dItgK4DDT2JQ40bIT/KoUutgj\n\twwLgUd+YifHOIPMMRbIjCQX6GD7sCFsNUV3DY6CCLiVr0UHdWcIuC6IuJMI4wDrhydue\n\t9IQc1OkCXvavkoR+9lOofPC4TjO48hQzyQh5282q0mfMa+Oon+7GckrhJ/ROBoh8HBhV\n\tZsSAVtU6QDTua19POlyfoK1mJxw84Ry7uN32KA7JvExwV5PFDDkMmaV5vf4ZMWwwoBct\n\twmmg==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCWbEqk8VZ01eKgxgyrWmpKJbC5SfXS7KBmyekzG1CF3z/qz1CXQLtMf1V5VPYZzwGZuIt4WfCQ19zmEqeY0xAE=@lists.libcamera.org","X-Gm-Message-State":"AOJu0YxujHUXKE8qhTHmwruV7Q+UojtjMS8efy/P0xfJlgsQ69LtCyZD\n\tjPNeegz5ugzaHR+xoQTJTrSovh2Gv8cU4pNRdtnh6vEWNuCp8oK0dgFHGPIKjwQ0/UvSIeM5qWY\n\tS","X-Google-Smtp-Source":"AGHT+IEBvaReE1v1pVvoUQ9B8MeegRoWEFiQts7ykVe9EkdUt579Vy4LuDzFv9qxXMsnEdECObPtWA==","X-Received":"by 2002:ad4:5b88:0:b0:6b0:8ac1:26bc with SMTP id\n\t6a1803df08f44-6c67fee561amr127228176d6.14.1726851142016; \n\tFri, 20 Sep 2024 09:52:22 -0700 (PDT)","Message-ID":"<95efc3add89043f91b6f8089cb93587912103138.camel@ndufresne.ca>","Subject":"Re: [PATCH v5] libcamera: debayer_cpu: Sync DMABUFs","From":"Nicolas Dufresne <nicolas@ndufresne.ca>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>, libcamera devel\n\t<libcamera-devel@lists.libcamera.org>","Cc":"Robert Mader <robert.mader@collabora.com>, Milan Zamazal\n\t<mzamazal@redhat.com>, Hans de Goede <hdegoede@redhat.com>","Date":"Fri, 20 Sep 2024 12:52:20 -0400","In-Reply-To":"<20240920114915.32728-1-kieran.bingham@ideasonboard.com>","References":"<20240920114915.32728-1-kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","User-Agent":"Evolution 3.52.4 (3.52.4-1.fc40) ","MIME-Version":"1.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>"}},{"id":31292,"web_url":"https://patchwork.libcamera.org/comment/31292/","msgid":"<CAC=wSGXiN1XX+w7Uq3Zr_0vkFkU-g497Mz2JtQhqBr5b0vQfdg@mail.gmail.com>","date":"2024-09-23T07:52:32","subject":"Re: [PATCH v5] libcamera: debayer_cpu: Sync DMABUFs","submitter":{"id":148,"url":"https://patchwork.libcamera.org/api/people/148/","name":"Cheng-Hao Yang","email":"chenghaoyang@google.com"},"content":"Hi Robert and developers,\n\nSorry to be late to the party, as I saw the v5 patch is already accepted\n[1].\n\nHowever, I'm wondering if it makes sense to add the DMABUF\nsynchronization as a generic function in the DmaBufAllocator,\nlike CrOS had done [2]. CrOS mtkisp7 needs the sync as well,\nand maybe we can save some duplicated code this way.\n\nWhether the input is a single fd or a FrameBuffer (that we sync\nall fds in all planes) can be discussed.\n\nI'd be happy to add the new patch, and update the usages in SoftwareISP\nif this is the way to go.\n\nThanks!\nHarvey\n\n[1]: https://patchwork.libcamera.org/patch/21290/\n[2]:\nhttps://chromium-review.googlesource.com/c/chromiumos/third_party/libcamera/+/4714763/21/src/libcamera/dma_heaps.cpp#79\n\nOn Sat, Sep 21, 2024 at 12:52 AM Nicolas Dufresne <nicolas@ndufresne.ca>\nwrote:\n\n> Hi,\n>\n> Le vendredi 20 septembre 2024 à 12:49 +0100, Kieran Bingham a écrit :\n> > From: Robert Mader <robert.mader@collabora.com>\n> >\n> > Using `DMA_BUF_IOCTL_SYNC` is required for DMABUFs in order to ensure\n> > correct output. Not doing so currently results in occasional tearing\n> > and/or backlashes in GL/VK clients that use the buffers directly for\n> > rendering.\n> >\n> > An alternative approach to have the sync code in `MappedFrameBuffer` was\n> > considered but rejected for now, in order to allow clients more\n> > flexibility.\n> >\n> > While the new helper is added to an annoymous namespace, add\n> > timeDiff to the same namespace and remove the static definition as a\n> > drive by.\n> >\n> > Signed-off-by: Robert Mader <robert.mader@collabora.com>\n> > Tested-by: Milan Zamazal <mzamazal@redhat.com> # Debix\n> > Tested-by: Hans de Goede <hdegoede@redhat.com> # IPU6 + ov2740\n> > Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com> # Lenovo\n> X13s + OV5675\n> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>\n> If we generalize this in the future, a more C++ friendly implementation\n> would be\n> nice. I'd see something similar to the mutex locker, something you can't\n> forget\n> to close.\n>\n> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n>\n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> >\n> > ---\n> > v5: Kieran:\n> >  - Remove static\n> >  - Fix ret negation that I suggested incorrectly.\n> >\n> >  src/libcamera/software_isp/debayer_cpu.cpp | 32 +++++++++++++++++++++-\n> >  1 file changed, 31 insertions(+), 1 deletion(-)\n> >\n> > diff --git a/src/libcamera/software_isp/debayer_cpu.cpp\n> b/src/libcamera/software_isp/debayer_cpu.cpp\n> > index 077f7f4bc45b..8a757fe9e02d 100644\n> > --- a/src/libcamera/software_isp/debayer_cpu.cpp\n> > +++ b/src/libcamera/software_isp/debayer_cpu.cpp\n> > @@ -12,8 +12,11 @@\n> >  #include \"debayer_cpu.h\"\n> >\n> >  #include <stdlib.h>\n> > +#include <sys/ioctl.h>\n> >  #include <time.h>\n> >\n> > +#include <linux/dma-buf.h>\n> > +\n> >  #include <libcamera/formats.h>\n> >\n> >  #include \"libcamera/internal/bayer_format.h\"\n> > @@ -718,12 +721,33 @@ void DebayerCpu::process4(const uint8_t *src,\n> uint8_t *dst)\n> >       }\n> >  }\n> >\n> > -static inline int64_t timeDiff(timespec &after, timespec &before)\n> > +namespace {\n> > +\n> > +void syncBufferForCPU(FrameBuffer *buffer, uint64_t syncFlags)\n> > +{\n> > +     for (const FrameBuffer::Plane &plane : buffer->planes()) {\n> > +             const int fd = plane.fd.get();\n> > +             struct dma_buf_sync sync = { syncFlags };\n> > +             int ret;\n> > +\n> > +             ret = ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);\n> > +             if (ret < 0) {\n> > +                     ret = errno;\n> > +                     LOG(Debayer, Error)\n> > +                             << \"Syncing buffer FD \" << fd << \" with\n> flags \"\n> > +                             << syncFlags << \" failed: \" <<\n> strerror(ret);\n> > +             }\n> > +     }\n> > +}\n> > +\n> > +inline int64_t timeDiff(timespec &after, timespec &before)\n> >  {\n> >       return (after.tv_sec - before.tv_sec) * 1000000000LL +\n> >              (int64_t)after.tv_nsec - (int64_t)before.tv_nsec;\n> >  }\n> >\n> > +} /* namespace */\n> > +\n> >  void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output,\n> DebayerParams params)\n> >  {\n> >       timespec frameStartTime;\n> > @@ -733,6 +757,9 @@ void DebayerCpu::process(FrameBuffer *input,\n> FrameBuffer *output, DebayerParams\n> >               clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime);\n> >       }\n> >\n> > +     syncBufferForCPU(input, DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ);\n> > +     syncBufferForCPU(output, DMA_BUF_SYNC_START | DMA_BUF_SYNC_WRITE);\n> > +\n> >       green_ = params.green;\n> >       red_ = swapRedBlueGains_ ? params.blue : params.red;\n> >       blue_ = swapRedBlueGains_ ? params.red : params.blue;\n> > @@ -760,6 +787,9 @@ void DebayerCpu::process(FrameBuffer *input,\n> FrameBuffer *output, DebayerParams\n> >\n> >       metadata.planes()[0].bytesused = out.planes()[0].size();\n> >\n> > +     syncBufferForCPU(output, DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE);\n> > +     syncBufferForCPU(input, DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ);\n> > +\n> >       /* Measure before emitting signals */\n> >       if (measuredFrames_ < DebayerCpu::kLastFrameToMeasure &&\n> >           ++measuredFrames_ > DebayerCpu::kFramesToSkip) {\n>\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 85A62C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Sep 2024 07:53:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 736206037E;\n\tMon, 23 Sep 2024 09:53:12 +0200 (CEST)","from mail-lf1-x130.google.com (mail-lf1-x130.google.com\n\t[IPv6:2a00:1450:4864:20::130])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 831F96037E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Sep 2024 09:53:10 +0200 (CEST)","by mail-lf1-x130.google.com with SMTP id\n\t2adb3069b0e04-53661d95508so12431e87.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Sep 2024 00:53:10 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"s9jJTybG\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20230601; t=1727077990; x=1727682790;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=BawsymAzfab03t98fyiKF8f95d9Nb5/lK3fLW0pRNzs=;\n\tb=s9jJTybGrbYtxTPXZ7dTDk+zn0T9CUPazmfxIUHBG0T+5pk8sjnTv1hny4cmSRKkhf\n\tm7+HPjwh666DHKHZPFF7+7Zv2pXIxQiypwuL6SoHGeIpCdn+hroWBjcU5eSiIV+9Mqsr\n\tG8pCgFifhaErFpabST7Hmro+zr9dOfL1a35FZevuUDh7vhuQd4J3Q2i8FrwcruwFBWHD\n\tiNUkdut5Y9+pOkeIt3Zcl9U89NFV75I9VKZltNUlzJdBE7x+HyJ+ihkDPXgsm8Uy3Djb\n\tYiP2sOYgj+9rxyL4+ptfIJGZJLfDenIh1DdhgmiXOjiezNN0p2ix7ghKksf618eb5Wv5\n\tfwTw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727077990; x=1727682790;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=BawsymAzfab03t98fyiKF8f95d9Nb5/lK3fLW0pRNzs=;\n\tb=lBjlqi5MXUT27RvUCtXNTIf9BfIk3Df/0arCI7SB9ZLplXqDyNUVQdwEevlRzSY5y8\n\tR3zw8Oi4T4z6TphNTDs9Gau43sclrNz4iugkLPs4YHdjtPcCurXC0IzIuyUsyItgcopO\n\tV9TfOM0HSyEKjHx4BS+224mmeZizIGGEjkMI5SxZnJbZvqK3jQQUDia12DkeOV7OAWXr\n\t5/xIKghG1W0L+3z6EgPsSv1LIFPPe8lLO9wu7Dsoa9ja6KPlSnqmvBYICW6ndzKtMVsW\n\twS4VE9uRoTxL5AKlkkb9TOvohQ+WO1Qqjq2bO8OLfZN6WTauzfDl4HjPOaRWdQan++RY\n\tbMKg==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCU0pHBWmHWF7eifMdRD/m8n03hRcbSYZbJ5HMaihv0bbhAeknjCwC/ALZttEqDn9/jdoQmnOCbIfz5ytf8ttCs=@lists.libcamera.org","X-Gm-Message-State":"AOJu0YwHzAt5LKgX9Ojj0z458kKvqcx+Q/Y+g4IEdjqJ2xEERVczxBFy\n\ttfPdKm8n3KK9Gb6jxUTSWL0Or7KjqQQFLxd1Gko66CB6b3iZPMsxP/CxaB5/wceV1cMUpxTC48o\n\ti4fkWE/WU7OQf3qJmopmfpAnYKt8n6AW1M6bn","X-Google-Smtp-Source":"AGHT+IG9ADJsCzXb22UWg+thL1otm5nf2ck3H48rN09l4+LMn5bVTlbT2Lh9bdR4Y1U1zQbwXGtWFeGqI9bjD8A82iA=","X-Received":"by 2002:a05:6512:3085:b0:530:baaa:ee10 with SMTP id\n\t2adb3069b0e04-53799615935mr246069e87.3.1727077989336; Mon, 23 Sep 2024\n\t00:53:09 -0700 (PDT)","MIME-Version":"1.0","References":"<20240920114915.32728-1-kieran.bingham@ideasonboard.com>\n\t<95efc3add89043f91b6f8089cb93587912103138.camel@ndufresne.ca>","In-Reply-To":"<95efc3add89043f91b6f8089cb93587912103138.camel@ndufresne.ca>","From":"Cheng-Hao Yang <chenghaoyang@google.com>","Date":"Mon, 23 Sep 2024 15:52:32 +0800","Message-ID":"<CAC=wSGXiN1XX+w7Uq3Zr_0vkFkU-g497Mz2JtQhqBr5b0vQfdg@mail.gmail.com>","Subject":"Re: [PATCH v5] libcamera: debayer_cpu: Sync DMABUFs","To":"Nicolas Dufresne <nicolas@ndufresne.ca>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>, \n\tlibcamera devel <libcamera-devel@lists.libcamera.org>, \n\tRobert Mader <robert.mader@collabora.com>,\n\tMilan Zamazal <mzamazal@redhat.com>, Hans de Goede <hdegoede@redhat.com>","Content-Type":"multipart/alternative; boundary=\"0000000000000ed21f0622c4ae16\"","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>"}},{"id":31297,"web_url":"https://patchwork.libcamera.org/comment/31297/","msgid":"<172708219408.129190.11135937370296237556@ping.linuxembedded.co.uk>","date":"2024-09-23T09:03:14","subject":"Re: [PATCH v5] libcamera: debayer_cpu: Sync DMABUFs","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Cheng-Hao Yang (2024-09-23 08:52:32)\n> Hi Robert and developers,\n> \n> Sorry to be late to the party, as I saw the v5 patch is already accepted\n> [1].\n> \n> However, I'm wondering if it makes sense to add the DMABUF\n> synchronization as a generic function in the DmaBufAllocator,\n> like CrOS had done [2]. CrOS mtkisp7 needs the sync as well,\n> and maybe we can save some duplicated code this way.\n> \n> Whether the input is a single fd or a FrameBuffer (that we sync\n> all fds in all planes) can be discussed.\n> \n> I'd be happy to add the new patch, and update the usages in SoftwareISP\n> if this is the way to go.\n\nWorking on a clean generic helper to save duplications is worthwhile. We\ndid discuss that in the patches, but went for the simple/local merged\nversion as it only currently affected the soft-isp, and we can't put it\nin a code-path that is used by all other pipelines all the time.\n\nI don't know where it should go yet though. Will the allocator be the\nright place for it ?  What happens if the buffers come from an external\nsource ? (Or maybe in that case, the provider is responsible?)\n\n--\nKieran\n\n\n> \n> Thanks!\n> Harvey\n> \n> [1]: https://patchwork.libcamera.org/patch/21290/\n> [2]:\n> https://chromium-review.googlesource.com/c/chromiumos/third_party/libcamera/+/4714763/21/src/libcamera/dma_heaps.cpp#79\n> \n> On Sat, Sep 21, 2024 at 12:52 AM Nicolas Dufresne <nicolas@ndufresne.ca>\n> wrote:\n> \n> > Hi,\n> >\n> > Le vendredi 20 septembre 2024 à 12:49 +0100, Kieran Bingham a écrit :\n> > > From: Robert Mader <robert.mader@collabora.com>\n> > >\n> > > Using `DMA_BUF_IOCTL_SYNC` is required for DMABUFs in order to ensure\n> > > correct output. Not doing so currently results in occasional tearing\n> > > and/or backlashes in GL/VK clients that use the buffers directly for\n> > > rendering.\n> > >\n> > > An alternative approach to have the sync code in `MappedFrameBuffer` was\n> > > considered but rejected for now, in order to allow clients more\n> > > flexibility.\n> > >\n> > > While the new helper is added to an annoymous namespace, add\n> > > timeDiff to the same namespace and remove the static definition as a\n> > > drive by.\n> > >\n> > > Signed-off-by: Robert Mader <robert.mader@collabora.com>\n> > > Tested-by: Milan Zamazal <mzamazal@redhat.com> # Debix\n> > > Tested-by: Hans de Goede <hdegoede@redhat.com> # IPU6 + ov2740\n> > > Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com> # Lenovo\n> > X13s + OV5675\n> > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> >\n> > If we generalize this in the future, a more C++ friendly implementation\n> > would be\n> > nice. I'd see something similar to the mutex locker, something you can't\n> > forget\n> > to close.\n> >\n> > Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> >\n> > > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > >\n> > > ---\n> > > v5: Kieran:\n> > >  - Remove static\n> > >  - Fix ret negation that I suggested incorrectly.\n> > >\n> > >  src/libcamera/software_isp/debayer_cpu.cpp | 32 +++++++++++++++++++++-\n> > >  1 file changed, 31 insertions(+), 1 deletion(-)\n> > >\n> > > diff --git a/src/libcamera/software_isp/debayer_cpu.cpp\n> > b/src/libcamera/software_isp/debayer_cpu.cpp\n> > > index 077f7f4bc45b..8a757fe9e02d 100644\n> > > --- a/src/libcamera/software_isp/debayer_cpu.cpp\n> > > +++ b/src/libcamera/software_isp/debayer_cpu.cpp\n> > > @@ -12,8 +12,11 @@\n> > >  #include \"debayer_cpu.h\"\n> > >\n> > >  #include <stdlib.h>\n> > > +#include <sys/ioctl.h>\n> > >  #include <time.h>\n> > >\n> > > +#include <linux/dma-buf.h>\n> > > +\n> > >  #include <libcamera/formats.h>\n> > >\n> > >  #include \"libcamera/internal/bayer_format.h\"\n> > > @@ -718,12 +721,33 @@ void DebayerCpu::process4(const uint8_t *src,\n> > uint8_t *dst)\n> > >       }\n> > >  }\n> > >\n> > > -static inline int64_t timeDiff(timespec &after, timespec &before)\n> > > +namespace {\n> > > +\n> > > +void syncBufferForCPU(FrameBuffer *buffer, uint64_t syncFlags)\n> > > +{\n> > > +     for (const FrameBuffer::Plane &plane : buffer->planes()) {\n> > > +             const int fd = plane.fd.get();\n> > > +             struct dma_buf_sync sync = { syncFlags };\n> > > +             int ret;\n> > > +\n> > > +             ret = ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);\n> > > +             if (ret < 0) {\n> > > +                     ret = errno;\n> > > +                     LOG(Debayer, Error)\n> > > +                             << \"Syncing buffer FD \" << fd << \" with\n> > flags \"\n> > > +                             << syncFlags << \" failed: \" <<\n> > strerror(ret);\n> > > +             }\n> > > +     }\n> > > +}\n> > > +\n> > > +inline int64_t timeDiff(timespec &after, timespec &before)\n> > >  {\n> > >       return (after.tv_sec - before.tv_sec) * 1000000000LL +\n> > >              (int64_t)after.tv_nsec - (int64_t)before.tv_nsec;\n> > >  }\n> > >\n> > > +} /* namespace */\n> > > +\n> > >  void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output,\n> > DebayerParams params)\n> > >  {\n> > >       timespec frameStartTime;\n> > > @@ -733,6 +757,9 @@ void DebayerCpu::process(FrameBuffer *input,\n> > FrameBuffer *output, DebayerParams\n> > >               clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime);\n> > >       }\n> > >\n> > > +     syncBufferForCPU(input, DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ);\n> > > +     syncBufferForCPU(output, DMA_BUF_SYNC_START | DMA_BUF_SYNC_WRITE);\n> > > +\n> > >       green_ = params.green;\n> > >       red_ = swapRedBlueGains_ ? params.blue : params.red;\n> > >       blue_ = swapRedBlueGains_ ? params.red : params.blue;\n> > > @@ -760,6 +787,9 @@ void DebayerCpu::process(FrameBuffer *input,\n> > FrameBuffer *output, DebayerParams\n> > >\n> > >       metadata.planes()[0].bytesused = out.planes()[0].size();\n> > >\n> > > +     syncBufferForCPU(output, DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE);\n> > > +     syncBufferForCPU(input, DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ);\n> > > +\n> > >       /* Measure before emitting signals */\n> > >       if (measuredFrames_ < DebayerCpu::kLastFrameToMeasure &&\n> > >           ++measuredFrames_ > DebayerCpu::kFramesToSkip) {\n> >\n> >\n> \n> -- \n> BR,\n> Harvey Yang","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 B532EC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Sep 2024 09:03:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 700DA63500;\n\tMon, 23 Sep 2024 11:03:18 +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 E830E6037E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Sep 2024 11:03:16 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C4C3A670;\n\tMon, 23 Sep 2024 11:01:50 +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=\"kfZzswr/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727082110;\n\tbh=0HEtGP5RGvrA6dx+ra7XfhKeq7lrbw1W7JvhAlTngE0=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=kfZzswr/0gqgz2QoaLx+Iw5Hvjc9XM6Tf+Nyr+WmXzY/cZJ1216M+9NJHB4KP9h8a\n\t3ZY3L5YOZNbdbsh8NR5rQ0VUYXkoRrpMokVwL6r8TU6MLbcfgAEWlS10APbXi/Xs8r\n\tJxDJoPROHI48vj+E/3DqErPopOVuUHLU/E5hdiEU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<CAC=wSGXiN1XX+w7Uq3Zr_0vkFkU-g497Mz2JtQhqBr5b0vQfdg@mail.gmail.com>","References":"<20240920114915.32728-1-kieran.bingham@ideasonboard.com>\n\t<95efc3add89043f91b6f8089cb93587912103138.camel@ndufresne.ca>\n\t<CAC=wSGXiN1XX+w7Uq3Zr_0vkFkU-g497Mz2JtQhqBr5b0vQfdg@mail.gmail.com>","Subject":"Re: [PATCH v5] libcamera: debayer_cpu: Sync DMABUFs","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>,\n\tRobert Mader <robert.mader@collabora.com>,\n\tMilan Zamazal <mzamazal@redhat.com>, Hans de Goede <hdegoede@redhat.com>","To":"Cheng-Hao Yang <chenghaoyang@google.com>,\n\tNicolas Dufresne <nicolas@ndufresne.ca>","Date":"Mon, 23 Sep 2024 10:03:14 +0100","Message-ID":"<172708219408.129190.11135937370296237556@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}},{"id":31302,"web_url":"https://patchwork.libcamera.org/comment/31302/","msgid":"<CAC=wSGVAgYthUD==H9rAAeyJdedmV5Mqs3FhAex8+oNPWJ-G6Q@mail.gmail.com>","date":"2024-09-23T10:07:58","subject":"Re: [PATCH v5] libcamera: debayer_cpu: Sync DMABUFs","submitter":{"id":148,"url":"https://patchwork.libcamera.org/api/people/148/","name":"Cheng-Hao Yang","email":"chenghaoyang@google.com"},"content":"Hi Kieran,\n\nOn Mon, Sep 23, 2024 at 5:03 PM Kieran Bingham <\nkieran.bingham@ideasonboard.com> wrote:\n\n> Quoting Cheng-Hao Yang (2024-09-23 08:52:32)\n> > Hi Robert and developers,\n> >\n> > Sorry to be late to the party, as I saw the v5 patch is already accepted\n> > [1].\n> >\n> > However, I'm wondering if it makes sense to add the DMABUF\n> > synchronization as a generic function in the DmaBufAllocator,\n> > like CrOS had done [2]. CrOS mtkisp7 needs the sync as well,\n> > and maybe we can save some duplicated code this way.\n> >\n> > Whether the input is a single fd or a FrameBuffer (that we sync\n> > all fds in all planes) can be discussed.\n> >\n> > I'd be happy to add the new patch, and update the usages in SoftwareISP\n> > if this is the way to go.\n>\n> Working on a clean generic helper to save duplications is worthwhile. We\n> did discuss that in the patches, but went for the simple/local merged\n> version as it only currently affected the soft-isp, and we can't put it\n> in a code-path that is used by all other pipelines all the time.\n\n\n> I don't know where it should go yet though. Will the allocator be the\n> right place for it ?  What happens if the buffers come from an external\n> source ? (Or maybe in that case, the provider is responsible?)\n>\n\nYeah that's a question that we need to figure out indeed.\n\nMaybe an option is to keep the information that the fd is allocated by\nDmaBufAllocator in UniqueFD/SharedFD, and the sync helper\nfunction/class would abort if the input is not from the allocator?\nWe may also be able to make it a function in SharedFD in this way.\n\nI'm also fine with the idea that the provider is responsible though.\n\nBTW, CrOS mtkisp7 also has a class DmaSyncer [1], which manages\nthe sync with the instance's lifetime. I think it's worth a thought as well.\n\n[1]:\nhttps://chromium-review.googlesource.com/c/chromiumos/third_party/libcamera/+/5674883\n\nBR,\nHarvey\n\n\n> --\n> Kieran\n>\n>\n> >\n> > Thanks!\n> > Harvey\n> >\n> > [1]: https://patchwork.libcamera.org/patch/21290/\n> > [2]:\n> >\n> https://chromium-review.googlesource.com/c/chromiumos/third_party/libcamera/+/4714763/21/src/libcamera/dma_heaps.cpp#79\n> >\n> > On Sat, Sep 21, 2024 at 12:52 AM Nicolas Dufresne <nicolas@ndufresne.ca>\n> > wrote:\n> >\n> > > Hi,\n> > >\n> > > Le vendredi 20 septembre 2024 à 12:49 +0100, Kieran Bingham a écrit :\n> > > > From: Robert Mader <robert.mader@collabora.com>\n> > > >\n> > > > Using `DMA_BUF_IOCTL_SYNC` is required for DMABUFs in order to ensure\n> > > > correct output. Not doing so currently results in occasional tearing\n> > > > and/or backlashes in GL/VK clients that use the buffers directly for\n> > > > rendering.\n> > > >\n> > > > An alternative approach to have the sync code in `MappedFrameBuffer`\n> was\n> > > > considered but rejected for now, in order to allow clients more\n> > > > flexibility.\n> > > >\n> > > > While the new helper is added to an annoymous namespace, add\n> > > > timeDiff to the same namespace and remove the static definition as a\n> > > > drive by.\n> > > >\n> > > > Signed-off-by: Robert Mader <robert.mader@collabora.com>\n> > > > Tested-by: Milan Zamazal <mzamazal@redhat.com> # Debix\n> > > > Tested-by: Hans de Goede <hdegoede@redhat.com> # IPU6 + ov2740\n> > > > Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com> # Lenovo\n> > > X13s + OV5675\n> > > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > >\n> > > If we generalize this in the future, a more C++ friendly implementation\n> > > would be\n> > > nice. I'd see something similar to the mutex locker, something you\n> can't\n> > > forget\n> > > to close.\n> > >\n> > > Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> > >\n> > > > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > > >\n> > > > ---\n> > > > v5: Kieran:\n> > > >  - Remove static\n> > > >  - Fix ret negation that I suggested incorrectly.\n> > > >\n> > > >  src/libcamera/software_isp/debayer_cpu.cpp | 32\n> +++++++++++++++++++++-\n> > > >  1 file changed, 31 insertions(+), 1 deletion(-)\n> > > >\n> > > > diff --git a/src/libcamera/software_isp/debayer_cpu.cpp\n> > > b/src/libcamera/software_isp/debayer_cpu.cpp\n> > > > index 077f7f4bc45b..8a757fe9e02d 100644\n> > > > --- a/src/libcamera/software_isp/debayer_cpu.cpp\n> > > > +++ b/src/libcamera/software_isp/debayer_cpu.cpp\n> > > > @@ -12,8 +12,11 @@\n> > > >  #include \"debayer_cpu.h\"\n> > > >\n> > > >  #include <stdlib.h>\n> > > > +#include <sys/ioctl.h>\n> > > >  #include <time.h>\n> > > >\n> > > > +#include <linux/dma-buf.h>\n> > > > +\n> > > >  #include <libcamera/formats.h>\n> > > >\n> > > >  #include \"libcamera/internal/bayer_format.h\"\n> > > > @@ -718,12 +721,33 @@ void DebayerCpu::process4(const uint8_t *src,\n> > > uint8_t *dst)\n> > > >       }\n> > > >  }\n> > > >\n> > > > -static inline int64_t timeDiff(timespec &after, timespec &before)\n> > > > +namespace {\n> > > > +\n> > > > +void syncBufferForCPU(FrameBuffer *buffer, uint64_t syncFlags)\n> > > > +{\n> > > > +     for (const FrameBuffer::Plane &plane : buffer->planes()) {\n> > > > +             const int fd = plane.fd.get();\n> > > > +             struct dma_buf_sync sync = { syncFlags };\n> > > > +             int ret;\n> > > > +\n> > > > +             ret = ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);\n> > > > +             if (ret < 0) {\n> > > > +                     ret = errno;\n> > > > +                     LOG(Debayer, Error)\n> > > > +                             << \"Syncing buffer FD \" << fd << \" with\n> > > flags \"\n> > > > +                             << syncFlags << \" failed: \" <<\n> > > strerror(ret);\n> > > > +             }\n> > > > +     }\n> > > > +}\n> > > > +\n> > > > +inline int64_t timeDiff(timespec &after, timespec &before)\n> > > >  {\n> > > >       return (after.tv_sec - before.tv_sec) * 1000000000LL +\n> > > >              (int64_t)after.tv_nsec - (int64_t)before.tv_nsec;\n> > > >  }\n> > > >\n> > > > +} /* namespace */\n> > > > +\n> > > >  void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output,\n> > > DebayerParams params)\n> > > >  {\n> > > >       timespec frameStartTime;\n> > > > @@ -733,6 +757,9 @@ void DebayerCpu::process(FrameBuffer *input,\n> > > FrameBuffer *output, DebayerParams\n> > > >               clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime);\n> > > >       }\n> > > >\n> > > > +     syncBufferForCPU(input, DMA_BUF_SYNC_START |\n> DMA_BUF_SYNC_READ);\n> > > > +     syncBufferForCPU(output, DMA_BUF_SYNC_START |\n> DMA_BUF_SYNC_WRITE);\n> > > > +\n> > > >       green_ = params.green;\n> > > >       red_ = swapRedBlueGains_ ? params.blue : params.red;\n> > > >       blue_ = swapRedBlueGains_ ? params.red : params.blue;\n> > > > @@ -760,6 +787,9 @@ void DebayerCpu::process(FrameBuffer *input,\n> > > FrameBuffer *output, DebayerParams\n> > > >\n> > > >       metadata.planes()[0].bytesused = out.planes()[0].size();\n> > > >\n> > > > +     syncBufferForCPU(output, DMA_BUF_SYNC_END |\n> DMA_BUF_SYNC_WRITE);\n> > > > +     syncBufferForCPU(input, DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ);\n> > > > +\n> > > >       /* Measure before emitting signals */\n> > > >       if (measuredFrames_ < DebayerCpu::kLastFrameToMeasure &&\n> > > >           ++measuredFrames_ > DebayerCpu::kFramesToSkip) {\n> > >\n> > >\n> >\n> > --\n> > BR,\n> > Harvey Yang\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 95B5DC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Sep 2024 10:08:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4E76A618DE;\n\tMon, 23 Sep 2024 12:08:39 +0200 (CEST)","from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com\n\t[IPv6:2a00:1450:4864:20::52f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 05BF96037E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Sep 2024 12:08:36 +0200 (CEST)","by mail-ed1-x52f.google.com with SMTP id\n\t4fb4d7f45d1cf-5c2460e885dso9813a12.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Sep 2024 03:08:36 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"Baryp0UA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20230601; t=1727086116; x=1727690916;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=butVtE5SLBZj0BMy586e3FmgxMcJRhCez++NKCRGhZE=;\n\tb=Baryp0UAH3HGGK/KecYmYVW1ytHQaYO7WJI+8ddbXXakN5nxrNHB/aGAbPAp0Qec9c\n\tVx+ibWfpSzfu3hKJmZEiYQXOdX4HXtCuP5wJWtvS/8fBSJJ+4H1OntW48R/6YxFYr4kQ\n\tV93c0ec24oeLIYamnineR3Wr+EoH345i6qILZUyOwT47a2JZuz3t+N8T6f/MdWzsQJmT\n\tXetpqh8zd65UPZr3wDp78vGRKYDDDMiOuMIg8sCFcFj+8oVBBmvDn3d2D/1PZ2BsnSj+\n\tfun6NoXCfSpDhsZXTLn1F13wPtXSiRciCrZyi4r62yQG7x2+AgG5UrSuJQOOwfpKbL1A\n\txF+w==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727086116; x=1727690916;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=butVtE5SLBZj0BMy586e3FmgxMcJRhCez++NKCRGhZE=;\n\tb=P8SepOXiD+tfLvXIZex3o26K9NGQ1ljS1jc8GeIHsUrkQbjRXgJfqpKfj7rooPgdgs\n\t6pE6Wef4szN4BVNdnfEPrQ4X0bdhUYWeKQmPt561jmafl4MdohPg+y+QcLsOaTmSMh3J\n\tYI2h0vpD4hfeye7+PhLYVSqNwstoiHmWTjMuVWHlTDWm55mozSC6ZV9/+56myyQ2tHEo\n\t/4S1j3MCh2r4Cy5HP8izTqLR8kO0NZQpU2L6/2N5YPZ1iLXzx4td2aGogbrI+nVTW7po\n\tC2A1sV//01Icka6jipURPxt2i44pNJfUi7NoD4ffxLL48kdXvXwauKD8Tmds7sr6HDoM\n\tJCpg==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCU+dfYBEDboX82CVk0xNfHiZeMDHT2PAlJFT3k9TdWP5HUXsvNcO6bCBVg0Pz8qoms3GfA1WIrKkz0R1lwTCXg=@lists.libcamera.org","X-Gm-Message-State":"AOJu0YxKy4/JXBm/cvCq7we+1XrIwIu90nhMLsNHVuGz8Qwj0jfwps2s\n\tPe35ES357GsAgHZyv9Zv5KGzc/zN8hMcY3mo8D+ywayfJuJdeKbjZ2FmzNuEX6TkTAayfLp191o\n\tFgdKB/4m+SOAgrrDWcpfyuS9TYEtFAYyBoKzL","X-Google-Smtp-Source":"AGHT+IH5IX93nB0gikETjmkiFiyyEtZLz3tho6ZtAeFyR3bZaZm0c6ghX/uRcIPsCY+dpmPp8s3ojbmoWaTxe6Cu1Pc=","X-Received":"by 2002:aa7:df18:0:b0:5c5:b85c:9549 with SMTP id\n\t4fb4d7f45d1cf-5c5b85c95a5mr223206a12.1.1727086115966; Mon, 23 Sep 2024\n\t03:08:35 -0700 (PDT)","MIME-Version":"1.0","References":"<20240920114915.32728-1-kieran.bingham@ideasonboard.com>\n\t<95efc3add89043f91b6f8089cb93587912103138.camel@ndufresne.ca>\n\t<CAC=wSGXiN1XX+w7Uq3Zr_0vkFkU-g497Mz2JtQhqBr5b0vQfdg@mail.gmail.com>\n\t<172708219408.129190.11135937370296237556@ping.linuxembedded.co.uk>","In-Reply-To":"<172708219408.129190.11135937370296237556@ping.linuxembedded.co.uk>","From":"Cheng-Hao Yang <chenghaoyang@google.com>","Date":"Mon, 23 Sep 2024 18:07:58 +0800","Message-ID":"<CAC=wSGVAgYthUD==H9rAAeyJdedmV5Mqs3FhAex8+oNPWJ-G6Q@mail.gmail.com>","Subject":"Re: [PATCH v5] libcamera: debayer_cpu: Sync DMABUFs","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Nicolas Dufresne <nicolas@ndufresne.ca>, \n\tlibcamera devel <libcamera-devel@lists.libcamera.org>, \n\tRobert Mader <robert.mader@collabora.com>,\n\tMilan Zamazal <mzamazal@redhat.com>, Hans de Goede <hdegoede@redhat.com>","Content-Type":"multipart/alternative; boundary=\"00000000000070c4490622c6926e\"","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>"}}]