{"id":14919,"url":"https://patchwork.libcamera.org/api/1.1/patches/14919/?format=json","web_url":"https://patchwork.libcamera.org/patch/14919/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211130233634.34173-6-jacopo@jmondi.org>","date":"2021-11-30T23:36:28","name":"[libcamera-devel,v3,05/11] libcamera: request: Add Fence to Request::addBuffer()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"452c70b6c46232f507beca032ad47391dc25be65","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14919/mbox/","series":[{"id":2788,"url":"https://patchwork.libcamera.org/api/1.1/series/2788/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2788","date":"2021-11-30T23:36:23","name":"libcamera: Add support for Fence","version":3,"mbox":"https://patchwork.libcamera.org/series/2788/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14919/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14919/checks/","tags":{},"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 0074EC324F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 23:35:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 940D460710;\n\tWed,  1 Dec 2021 00:35:54 +0100 (CET)","from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3950160737\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  1 Dec 2021 00:35:53 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 6FA9E1BF206;\n\tTue, 30 Nov 2021 23:35:52 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  1 Dec 2021 00:36:28 +0100","Message-Id":"<20211130233634.34173-6-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.33.1","In-Reply-To":"<20211130233634.34173-1-jacopo@jmondi.org>","References":"<20211130233634.34173-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 05/11] libcamera: request: Add Fence to\n\tRequest::addBuffer()","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>"},"content":"Add an optional synchronization fence to Request::addBuffer() to allow\nassociating a Fence with a FrameBuffer part of a Request.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/request.h |  4 +++-\n src/libcamera/request.cpp   | 26 +++++++++++++++++++++++++-\n 2 files changed, 28 insertions(+), 2 deletions(-)","diff":"diff --git a/include/libcamera/request.h b/include/libcamera/request.h\nindex 8c78970d88ab..1eb537e9b09b 100644\n--- a/include/libcamera/request.h\n+++ b/include/libcamera/request.h\n@@ -17,6 +17,7 @@\n #include <libcamera/base/signal.h>\n \n #include <libcamera/controls.h>\n+#include <libcamera/fence.h>\n \n namespace libcamera {\n \n@@ -51,7 +52,8 @@ public:\n \tControlList &controls() { return *controls_; }\n \tControlList &metadata() { return *metadata_; }\n \tconst BufferMap &buffers() const { return bufferMap_; }\n-\tint addBuffer(const Stream *stream, FrameBuffer *buffer);\n+\tint addBuffer(const Stream *stream, FrameBuffer *buffer,\n+\t\t      std::unique_ptr<Fence> fence = nullptr);\n \tFrameBuffer *findBuffer(const Stream *stream) const;\n \n \tuint32_t sequence() const;\ndiff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\nindex 692202473360..699ea1db2e16 100644\n--- a/src/libcamera/request.cpp\n+++ b/src/libcamera/request.cpp\n@@ -14,6 +14,7 @@\n \n #include <libcamera/camera.h>\n #include <libcamera/control_ids.h>\n+#include <libcamera/fence.h>\n #include <libcamera/framebuffer.h>\n #include <libcamera/stream.h>\n \n@@ -294,6 +295,7 @@ void Request::reuse(ReuseFlag flags)\n  * \\brief Add a FrameBuffer with its associated Stream to the Request\n  * \\param[in] stream The stream the buffer belongs to\n  * \\param[in] buffer The FrameBuffer to add to the request\n+ * \\param[in] fence The optional synchronization Fence\n  *\n  * A reference to the buffer is stored in the request. The caller is responsible\n  * for ensuring that the buffer will remain valid until the request complete\n@@ -302,11 +304,24 @@ void Request::reuse(ReuseFlag flags)\n  * A request can only contain one buffer per stream. If a buffer has already\n  * been added to the request for the same stream, this function returns -EEXIST.\n  *\n+ * A synchronization Fence can be optionally associated with the \\a buffer.\n+ *\n+ * When a valid fence is provided to this function, \\a fence is moved to \\a\n+ * buffer and this Request will only be queued to the device once the\n+ * synchronization fences of all its buffers have been correctly signalled.\n+ *\n+ * If the \\a fence associated with \\a buffer fails, the application is\n+ * responsible for resetting it before associating this buffer with a new\n+ * Request by calling this function again.\n+ *\n+ * \\sa FrameBuffer::resetFence()\n+ *\n  * \\return 0 on success or a negative error code otherwise\n  * \\retval -EEXIST The request already contains a buffer for the stream\n  * \\retval -EINVAL The buffer does not reference a valid Stream\n  */\n-int Request::addBuffer(const Stream *stream, FrameBuffer *buffer)\n+int Request::addBuffer(const Stream *stream, FrameBuffer *buffer,\n+\t\t       std::unique_ptr<Fence> fence)\n {\n \tif (!stream) {\n \t\tLOG(Request, Error) << \"Invalid stream reference\";\n@@ -323,6 +338,15 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer)\n \t_d()->pending_.insert(buffer);\n \tbufferMap_[stream] = buffer;\n \n+\t/*\n+\t * Make sure the fence has been extracted from the buffer\n+\t * to avoid waiting on a stale fence.\n+\t */\n+\tASSERT(!buffer->fence());\n+\n+\tif (fence && fence->isValid())\n+\t\tbuffer->_d()->setFence(std::move(fence));\n+\n \treturn 0;\n }\n \n","prefixes":["libcamera-devel","v3","05/11"]}