From patchwork Sat Nov 20 11:13:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 14672 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 404AEC324F for ; Sat, 20 Nov 2021 11:12:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C530A6048E; Sat, 20 Nov 2021 12:12:28 +0100 (CET) Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 12F1D6033C for ; Sat, 20 Nov 2021 12:12:25 +0100 (CET) Received: (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 99372100002; Sat, 20 Nov 2021 11:12:24 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 20 Nov 2021 12:13:05 +0100 Message-Id: <20211120111313.106621-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211120111313.106621-1-jacopo@jmondi.org> References: <20211120111313.106621-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/12] 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 overloaded version of Request::addBuffer() that allows application to specify a Fence instance to be associated with the Framebuffer. Signed-off-by: Jacopo Mondi --- include/libcamera/request.h | 5 ++++ src/libcamera/request.cpp | 58 ++++++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/include/libcamera/request.h b/include/libcamera/request.h index f0c5163d987e..37aebc41834e 100644 --- a/include/libcamera/request.h +++ b/include/libcamera/request.h @@ -22,6 +22,7 @@ namespace libcamera { class Camera; class CameraControlValidator; +class Fence; class FrameBuffer; class Stream; @@ -52,6 +53,8 @@ public: 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); FrameBuffer *findBuffer(const Stream *stream) const; uint32_t sequence() const; @@ -65,6 +68,8 @@ public: private: LIBCAMERA_DISABLE_COPY(Request) + int _addBuffer(const Stream *stream, FrameBuffer *buffer); + ControlList *controls_; ControlList *metadata_; BufferMap bufferMap_; diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 90c436648405..1d47698a6263 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -19,6 +19,7 @@ #include "libcamera/internal/camera.h" #include "libcamera/internal/camera_controls.h" +#include "libcamera/internal/fence.h" #include "libcamera/internal/framebuffer.h" #include "libcamera/internal/tracepoints.h" @@ -316,6 +317,26 @@ void Request::reuse(ReuseFlag flags) * \return The map of Stream to FrameBuffer */ +int Request::_addBuffer(const Stream *stream, FrameBuffer *buffer) +{ + if (!stream) { + LOG(Request, Error) << "Invalid stream reference"; + return -EINVAL; + } + + auto it = bufferMap_.find(stream); + if (it != bufferMap_.end()) { + LOG(Request, Error) << "FrameBuffer already set for stream"; + return -EEXIST; + } + + buffer->_d()->setRequest(this); + _d()->pending_.insert(buffer); + bufferMap_[stream] = buffer; + + return 0; +} + /** * \brief Add a FrameBuffer with its associated Stream to the Request * \param[in] stream The stream the buffer belongs to @@ -334,22 +355,33 @@ void Request::reuse(ReuseFlag flags) */ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer) { - if (!stream) { - LOG(Request, Error) << "Invalid stream reference"; - return -EINVAL; - } + int ret = _addBuffer(stream, buffer); + if (ret) + return ret; + + /* + * Drop the buffer Fence, if any. + * + * Buffers can be re-used and might still have a Fence associated from + * a previous run if the Fence has failed. Drop it here. + */ + buffer->_d()->closeFence(); - auto it = bufferMap_.find(stream); - if (it != bufferMap_.end()) { - LOG(Request, Error) << "FrameBuffer already set for stream"; - return -EEXIST; - } + return 0; +} - buffer->_d()->setRequest(this); - _d()->pending_.insert(buffer); - bufferMap_[stream] = buffer; +/** + * \brief Add a FrameBuffer with its associated Stream and Fence + * \copydoc Request::addBuffer(const Stream *stream, FrameBuffer *buffer) + * \param[in] fence The synchronization fence associated with \a buffer + */ +int Request::addBuffer(const Stream *stream, FrameBuffer *buffer, + std::unique_ptr &&fence) +{ + if (fence->isValid()) + buffer->_d()->setFence(std::move(fence)); - return 0; + return _addBuffer(stream, buffer); } /**