[{"id":21662,"web_url":"https://patchwork.libcamera.org/comment/21662/","msgid":"<YbB9rIeP5lBh4pWF@pendragon.ideasonboard.com>","date":"2021-12-08T09:41:00","subject":"Re: [libcamera-devel] [PATCH v4 04/11] libcamera: framebuffer: Add\n\tFence to FrameBuffer","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 Wed, Dec 01, 2021 at 03:29:29PM +0100, Jacopo Mondi wrote:\n> Add to the FrameBuffer::Private class a unique pointer to a\n> synchronization Fence.\n\ns/synchronization Fence/Fence/\n\n> The Fence will be used to signal the availability of the Framebuffer for\n> incoming data transfer.\n> \n> The Fence will be associated to a FrameBuffer at Request::addBuffer()\n> time, and if correctly signalled, reset by the core at Request queue\n> time.\n> \n> If a FrameBuffer completes with errors, due to a Fence wait failure, the\n> Fence will still be owned by the FrameBuffer and it is application\n> responsibility to correctly reset it before reusing the buffer.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  include/libcamera/framebuffer.h          |  4 ++\n>  include/libcamera/internal/framebuffer.h |  8 ++++\n>  src/libcamera/framebuffer.cpp            | 58 ++++++++++++++++++++++++\n>  3 files changed, 70 insertions(+)\n> \n> diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h\n> index 357bbe189551..39ebbdaebf47 100644\n> --- a/include/libcamera/framebuffer.h\n> +++ b/include/libcamera/framebuffer.h\n> @@ -9,6 +9,7 @@\n>  \n>  #include <assert.h>\n>  #include <limits>\n> +#include <memory>\n>  #include <stdint.h>\n>  #include <vector>\n>  \n> @@ -18,6 +19,7 @@\n>  \n>  namespace libcamera {\n>  \n> +class Fence;\n>  class Request;\n>  \n>  struct FrameMetadata {\n> @@ -65,6 +67,8 @@ public:\n>  \tunsigned int cookie() const { return cookie_; }\n>  \tvoid setCookie(unsigned int cookie) { cookie_ = cookie; }\n>  \n> +\tstd::unique_ptr<Fence> releaseFence();\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 908b478985e7..fc9f4a2fc768 100644\n> --- a/include/libcamera/internal/framebuffer.h\n> +++ b/include/libcamera/internal/framebuffer.h\n> @@ -7,8 +7,12 @@\n>  \n>  #pragma once\n>  \n> +#include <memory>\n> +#include <utility>\n> +\n>  #include <libcamera/base/class.h>\n>  \n> +#include <libcamera/fence.h>\n>  #include <libcamera/framebuffer.h>\n>  \n>  namespace libcamera {\n> @@ -23,7 +27,11 @@ public:\n>  \tvoid setRequest(Request *request) { request_ = request; }\n>  \tbool isContiguous() const { return isContiguous_; }\n>  \n> +\tFence *fence() const { return fence_.get(); }\n> +\tvoid setFence(std::unique_ptr<Fence> fence) { fence_ = std::move(fence); }\n> +\n>  private:\n> +\tstd::unique_ptr<Fence> fence_;\n>  \tRequest *request_;\n>  \tbool isContiguous_;\n>  };\n> diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\n> index 701212f3ae21..a2cb0486e14d 100644\n> --- a/src/libcamera/framebuffer.cpp\n> +++ b/src/libcamera/framebuffer.cpp\n> @@ -140,6 +140,45 @@ FrameBuffer::Private::Private()\n>   * \\return True if the planes are stored contiguously in memory, false otherwise\n>   */\n>  \n> +/**\n> + * \\fn FrameBuffer::Private::fence()\n> + * \\brief Retrieve a const pointer to the Fence\n> + *\n> + * This function does only return a reference to the the fence and does not\n> + * change its ownership. The fence is stored in the FrameBuffer and can only be\n> + * reset with FrameBuffer::releaseFence() in case the buffer has completed with\n> + * error due to a Fence wait failure.\n> + *\n> + * If buffer with a Fence completes with errors due to a failure in handling\n> + * the fence, applications are responsible for releasing the Fence before\n> + * calling Request::addBuffer() again.\n> + *\n> + * \\sa Request::addBuffer()\n> + *\n> + * \\return A const pointer to the Fence if any, nullptr otherwise\n> + */\n> +\n> +/**\n> + * \\fn FrameBuffer::Private::setFence()\n> + * \\brief Move a \\a fence in this buffer\n> + * \\param[in] fence The synchronization fence\n\ns/synchronization fence/fence/\n\n> + *\n> + * This function associates a Fence with this Framebuffer. The intended caller\n> + * is the Request::addBuffer() function.\n> + *\n> + * Once a FrameBuffer is associated with a Fence, the FrameBuffer will only be\n> + * made available to the hardware device once the synchronization Fence has been\n\ns/synchronization Fence/Fence/\n\n> + * correctly signalled.\n> + *\n> + * \\sa Request::prepare()\n> + *\n> + * If the FrameBuffer completes successfully the core releases the Fence and the\n> + * Buffer can be reused immediately. If handling of the Fence fails during the\n> + * request preparation, the Fence is not reset and is left in the FrameBuffer.\n\ns/reset/released/ maybe ?\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> + * It is applications responsibility to correctly release the fence and handle\n> + * it opportunely before using the buffer again.\n> + */\n> +\n>  /**\n>   * \\class FrameBuffer\n>   * \\brief Frame buffer data and its associated dynamic metadata\n> @@ -329,6 +368,25 @@ Request *FrameBuffer::request() const\n>   * libcamera core never modifies the buffer cookie.\n>   */\n>  \n> +/**\n> + * \\brief Extract the Fence associated with this Framebuffer\n> + *\n> + * This function moves the buffer's fence ownership to the caller.\n> + * After the fence has been released, calling this function always return\n> + * nullptr.\n> + *\n> + * If buffer with a Fence completes with errors due to a failure in handling\n> + * the fence, applications are responsible for releasing the Fence before\n> + * calling Request::addBuffer() again.\n> + *\n> + * \\return A unique pointer to the Fence if set, or nullptr if the fence has\n> + * been released already\n> + */\n> +std::unique_ptr<Fence> FrameBuffer::releaseFence()\n> +{\n> +\treturn std::move(_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 7512BBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 Dec 2021 09:41:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BD3B460868;\n\tWed,  8 Dec 2021 10:41:32 +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 01C1C60225\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Dec 2021 10:41:30 +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 5EF8E8BB;\n\tWed,  8 Dec 2021 10:41:30 +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=\"NGu2pbyY\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638956490;\n\tbh=VapInNSk5K6ENPoNTpCMjUA4fUgG0ChRkk71Y0SawV8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=NGu2pbyYk02vbQDmbLW7LYUk1KkAiWkEEUW1jch3gLWmzm2IQ5JyrjJ/DKHsRsHmb\n\tnrOlrHndz8TtUB/vG2FwsPtqCm0kFZvrRbIuoo6YABLPHbzQ7yg1xlx7UVGKkWqofh\n\tH79UwjczunmUP8lS8Bs2VHL5gB0YI9J3Ayo9Iv3g=","Date":"Wed, 8 Dec 2021 11:41:00 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<YbB9rIeP5lBh4pWF@pendragon.ideasonboard.com>","References":"<20211201142936.107405-1-jacopo@jmondi.org>\n\t<20211201142936.107405-5-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211201142936.107405-5-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v4 04/11] libcamera: framebuffer: Add\n\tFence to FrameBuffer","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>"}}]