[{"id":21073,"web_url":"https://patchwork.libcamera.org/comment/21073/","msgid":"<YZqK1WYKxtavT46F@pendragon.ideasonboard.com>","date":"2021-11-21T18:07:17","subject":"Re: [libcamera-devel] [PATCH v2 03/12] libcamera: framebuffer:\n\tprivate: Add Fence","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Sat, Nov 20, 2021 at 12:13:04PM +0100, Jacopo Mondi wrote:\n> Add to the FrameBuffer::Private class a uniquely owned Fence instance.\n> \n> The Fence will be used to signal the availability of the Framebuffer to\n> incoming data transfer.\n> \n> Add a set of function to set, cancel and retrieve a refence to the\n> Fence.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  include/libcamera/framebuffer.h          |  3 +++\n>  include/libcamera/internal/framebuffer.h |  9 ++++++++\n>  src/libcamera/framebuffer.cpp            | 26 ++++++++++++++++++++++++\n>  3 files changed, 38 insertions(+)\n> \n> diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h\n> index 7f2f176af691..aa2a1f5193c7 100644\n> --- a/include/libcamera/framebuffer.h\n> +++ b/include/libcamera/framebuffer.h\n> @@ -19,6 +19,7 @@\n>  \n>  namespace libcamera {\n>  \n> +class Fence;\n>  class Request;\n>  \n>  struct FrameMetadata {\n> @@ -66,6 +67,8 @@ public:\n>  \tunsigned int cookie() const { return cookie_; }\n>  \tvoid setCookie(unsigned int cookie) { cookie_ = cookie; }\n>  \n> +\tFence *fence() const;\n> +\n>  \tvoid cancel() { metadata_.status = FrameMetadata::FrameCancelled; }\n>  \n>  private:\n> diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h\n> index cd33c295466e..9e1699a6875d 100644\n> --- a/include/libcamera/internal/framebuffer.h\n> +++ b/include/libcamera/internal/framebuffer.h\n> @@ -7,10 +7,14 @@\n>  #ifndef __LIBCAMERA_INTERNAL_FRAMEBUFFER_H__\n>  #define __LIBCAMERA_INTERNAL_FRAMEBUFFER_H__\n>  \n> +#include <memory>\n> +\n>  #include <libcamera/base/class.h>\n>  \n>  #include <libcamera/framebuffer.h>\n>  \n> +#include <libcamera/internal/fence.h>\n> +\n>  namespace libcamera {\n>  \n>  class FrameBuffer::Private : public Extensible::Private\n> @@ -23,8 +27,13 @@ public:\n>  \tvoid setRequest(Request *request) { request_ = request; }\n>  \tbool isContiguous() const { return isContiguous_; }\n>  \n> +\tvoid setFence(std::unique_ptr<Fence> &&fence) { fence_ = std::move(fence); }\n> +\tvoid closeFence() { fence_.reset(); }\n\nI think I'd call this resetFence(). Another option would be to call\nsetFence(nullptr) instead, and drop the function. I think resetFence()\nwould be better, I'm thinking it could return the\nstd::unique_ptr<Fence>, in order to extract the fence from the\nFrameBuffer when the request completes. We would need a resetFence()\nfunction in the FrameBuffer class too, which could replace the existing\nfence() function. I'll comment further on that in subsequent patches.\n\n> +\tFence *fence() const { return fence_.get(); }\n> +\n>  private:\n>  \tRequest *request_;\n> +\tstd::unique_ptr<Fence> fence_;\n>  \tbool isContiguous_;\n>  };\n>  \n> diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\n> index 337ea1155a38..63c4ce6ab450 100644\n> --- a/src/libcamera/framebuffer.cpp\n> +++ b/src/libcamera/framebuffer.cpp\n> @@ -126,6 +126,23 @@ FrameBuffer::Private::Private()\n>   * handlers, it is called by the pipeline handlers themselves.\n>   */\n>  \n> +/**\n> + * \\fn FrameBuffer::Private::setFence()\n> + * \\brief Set the synchronization fence for this buffer\n> + * \\param[in] fence The synchronization fence\n> + */\n> +\n> +/**\n> + * \\fn FrameBuffer::Private::closeFence()\n> + * \\brief Close the synchronization fence for this buffer\n> + */\n> +\n> +/**\n> + * \\fn FrameBuffer::Private::fence()\n> + * \\brief Retrieve a pointer to the synchronization fence of this buffer\n> + * \\return A pointer to the buffer fence, nullptr if the buffer has not fence\n> + */\n> +\n>  /**\n>   * \\fn FrameBuffer::Private::isContiguous()\n>   * \\brief Check if the frame buffer stores planes contiguously in memory\n> @@ -305,6 +322,15 @@ Request *FrameBuffer::request() const\n>   * libcamera core never modifies the buffer cookie.\n>   */\n>  \n> +/**\n> + * \\brief Retrieve a reference to the Fence associated with this Framebuffer\n> + * \\return A pointer to the Fence, if set, nullptr otherwise\n> + */\n> +Fence *FrameBuffer::fence() const\n> +{\n> +\treturn _d()->fence();\n> +}\n> +\n>  /**\n>   * \\fn FrameBuffer::cancel()\n>   * \\brief Marks the buffer as cancelled","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 7F404BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 21 Nov 2021 18:07:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BAFEA60378;\n\tSun, 21 Nov 2021 19:07:42 +0100 (CET)","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 0FDEF60233\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 21 Nov 2021 19:07:41 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 72DC29DD;\n\tSun, 21 Nov 2021 19:07:40 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"gi97/vma\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637518060;\n\tbh=ySq50qmkkQyw0EOvcYtQ/oGkubC320zb9bb12F4m+rM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=gi97/vmaAqhGcR/5MBYk5+Tl0+T4BT9z4AdjW6OtogZf2n8grBe0cuDLkt/pVfKGQ\n\tzIXrtFlG/VzwoxYilBB2yLzTI0f2u44839/xqPk1T0SZdTRhHkKDGUvjKoMOcsnOFj\n\tJa42jwsZP9hpe0ACtbM5CGUXRSRW5zbZnmOsdado=","Date":"Sun, 21 Nov 2021 20:07:17 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<YZqK1WYKxtavT46F@pendragon.ideasonboard.com>","References":"<20211120111313.106621-1-jacopo@jmondi.org>\n\t<20211120111313.106621-4-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211120111313.106621-4-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v2 03/12] libcamera: framebuffer:\n\tprivate: Add Fence","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]