From patchwork Sat Aug 31 19:05:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 21129 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 280B6C324C for ; Sat, 31 Aug 2024 19:05:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E4E9E634A6; Sat, 31 Aug 2024 21:05:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=robert.mader@collabora.com header.b="SIeQ4Jkm"; dkim-atps=neutral Received: from sender4-op-o10.zoho.com (sender4-op-o10.zoho.com [136.143.188.10]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A5B96345D for ; Sat, 31 Aug 2024 21:05:20 +0200 (CEST) Delivered-To: robert.mader@collabora.com ARC-Seal: i=1; a=rsa-sha256; t=1725131117; cv=none; d=zohomail.com; s=zohoarc; b=IhAlkPMGH2StUY9HrN0eb+tXNCnrsk8xirdMq7C9IuSegH+Zm4VpXcg+xzr5sJknxBDiPkG9VPjkq4bTbGbw+TETWFGfkJcdffSrposU0dgiKmZ+Osni1UVmXiRgT15/VBdfs7qzSBvWOBlCBrdHK4fVtlD7umI8Idr+igqfUGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725131117; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=jT/ibiwe89QiZJuc3fBwZcESm8chbR2WdGDJRxF1muY=; b=EDpAu2qSSsEG8LPb79b4ujs2uYzTXTTWmPn3CSqKo3Ns59hYzUgJpyJ/bKWFR2pWyhp/qzMZdBLWGIyTCV6ylfhZaAN21/KTiAYlEarpsQMXD+5TAciwoK2xdSCnhw83qOSe/Y47ZPcFIYhl8fvkRujVJ/bzIipQL4bl+dk+kN8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=robert.mader@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1725131117; s=zohomail; d=collabora.com; i=robert.mader@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=jT/ibiwe89QiZJuc3fBwZcESm8chbR2WdGDJRxF1muY=; b=SIeQ4Jkmj/SDTmGjJt49scgXaX8hAMARH9y0gUNzFQX73aa09hZjcDi5VxhF8h6x 2E3hW4tjalAlBz/jQ3Ml7CbQz63yTnXd8kPwn3hndfX7TOCHEVgUAlyB/b1qkeRIk7Z HJIMtDGHvwnwXj+d7WThYCT8Y65fnITvKVtcye50= Received: by mx.zohomail.com with SMTPS id 1725131115907906.7921780898891; Sat, 31 Aug 2024 12:05:15 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH] libcamera: debayer_cpu: Sync output buffer Date: Sat, 31 Aug 2024 21:05:11 +0200 Message-ID: <20240831190511.128151-1-robert.mader@collabora.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 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" Using `DMA_BUF_IOCTL_SYNC` is required for dmabufs in order to ensure correct results. Not doing so currently results in occasional tearing and/or backlashes in GL/VK clients that use the buffers directly for rendering. Signed-off-by: Robert Mader --- src/libcamera/software_isp/debayer_cpu.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index 077f7f4b..6c953b03 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -11,7 +11,9 @@ #include "debayer_cpu.h" +#include #include +#include #include #include @@ -733,6 +735,16 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime); } + for (const FrameBuffer::Plane &plane : output->planes()) { + const int fd = plane.fd.get(); + struct dma_buf_sync sync = { DMA_BUF_SYNC_START }; + + sync.flags |= DMA_BUF_SYNC_WRITE; + + if (ioctl (fd, DMA_BUF_IOCTL_SYNC, &sync) < 0) + LOG(Debayer, Error) << "Syncing buffer FD " << fd << "failed: " << errno; + } + green_ = params.green; red_ = swapRedBlueGains_ ? params.blue : params.red; blue_ = swapRedBlueGains_ ? params.red : params.blue; @@ -760,6 +772,16 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams metadata.planes()[0].bytesused = out.planes()[0].size(); + for (const FrameBuffer::Plane &plane : output->planes()) { + const int fd = plane.fd.get(); + struct dma_buf_sync sync = { DMA_BUF_SYNC_END }; + + sync.flags |= DMA_BUF_SYNC_WRITE; + + if (ioctl (fd, DMA_BUF_IOCTL_SYNC, &sync) < 0) + LOG(Debayer, Error) << "Syncing buffer FD " << fd << "failed: " << errno; + } + /* Measure before emitting signals */ if (measuredFrames_ < DebayerCpu::kLastFrameToMeasure && ++measuredFrames_ > DebayerCpu::kFramesToSkip) {