From patchwork Sat Dec 11 16:57:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 15140 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 28FBFBDB13 for ; Sat, 11 Dec 2021 16:56:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 92E2C60898; Sat, 11 Dec 2021 17:56:33 +0100 (CET) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BA336608A7 for ; Sat, 11 Dec 2021 17:56:28 +0100 (CET) Received: (Authenticated sender: jacopo@jmondi.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 291FB20004; Sat, 11 Dec 2021 16:56:27 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 11 Dec 2021 17:57:08 +0100 Message-Id: <20211211165714.23067-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211211165714.23067-1-jacopo@jmondi.org> References: <20211211165714.23067-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 05/11] libcamera: request: Add Fence to Request::addBuffer() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add an optional fence parameter to Request::addBuffer() to allow associating a Fence with a FrameBuffer. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/request.h | 4 +++- src/libcamera/request.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/libcamera/request.h b/include/libcamera/request.h index 8c78970d88ab..1eb537e9b09b 100644 --- a/include/libcamera/request.h +++ b/include/libcamera/request.h @@ -17,6 +17,7 @@ #include #include +#include namespace libcamera { @@ -51,7 +52,8 @@ public: ControlList &controls() { return *controls_; } ControlList &metadata() { return *metadata_; } const BufferMap &buffers() const { return bufferMap_; } - int addBuffer(const Stream *stream, FrameBuffer *buffer); + int addBuffer(const Stream *stream, FrameBuffer *buffer, + std::unique_ptr fence = nullptr); FrameBuffer *findBuffer(const Stream *stream) const; uint32_t sequence() const; diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 692202473360..6c9d67bec05d 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -294,6 +295,7 @@ void Request::reuse(ReuseFlag flags) * \brief Add a FrameBuffer with its associated Stream to the Request * \param[in] stream The stream the buffer belongs to * \param[in] buffer The FrameBuffer to add to the request + * \param[in] fence The optional fence * * A reference to the buffer is stored in the request. The caller is responsible * for ensuring that the buffer will remain valid until the request complete @@ -302,11 +304,27 @@ void Request::reuse(ReuseFlag flags) * A request can only contain one buffer per stream. If a buffer has already * been added to the request for the same stream, this function returns -EEXIST. * + * A Fence can be optionally associated with the \a buffer. + * + * When a valid Fence is provided to this function, \a fence is moved to \a + * buffer and this Request will only be queued to the device once the + * fences of all its buffers have been correctly signalled. + * + * If the \a fence associated with \a buffer isn't signalled, the request will + * fail after a timeout. The buffer will still contain the fence, which + * applications must retrieve with FrameBuffer::releaseFence() before the buffer + * can be reused in another request. Attempting to add a buffer that still + * contains a fence to a request will result in this function returning -EEXIST. + * + * \sa FrameBuffer::releaseFence() + * * \return 0 on success or a negative error code otherwise * \retval -EEXIST The request already contains a buffer for the stream + * or the buffer still references a fence * \retval -EINVAL The buffer does not reference a valid Stream */ -int Request::addBuffer(const Stream *stream, FrameBuffer *buffer) +int Request::addBuffer(const Stream *stream, FrameBuffer *buffer, + std::unique_ptr fence) { if (!stream) { LOG(Request, Error) << "Invalid stream reference"; @@ -323,6 +341,18 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer) _d()->pending_.insert(buffer); bufferMap_[stream] = buffer; + /* + * Make sure the fence has been extracted from the buffer + * to avoid waiting on a stale fence. + */ + if (buffer->_d()->fence()) { + LOG(Request, Error) << "Can't add buffer that still references a fence"; + return -EEXIST; + } + + if (fence && fence->isValid()) + buffer->_d()->setFence(std::move(fence)); + return 0; }