From patchwork Mon Sep 16 14:11:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 21285 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 1F047C3257 for ; Mon, 16 Sep 2024 14:11:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DECC2634FD; Mon, 16 Sep 2024 16:11:43 +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="JtUl3a71"; dkim-atps=neutral Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7CC3A634F5 for ; Mon, 16 Sep 2024 16:11:41 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1726495898; cv=none; d=zohomail.com; s=zohoarc; b=FsyhHX5a+yMY5OzWQ9lE0qetYjGZozScppRQVjWhz4fG2da1dSGSg71P6F6j74gqpYi8m2JrKUQ/5oB6IkLMYHOnu7x3BEobo5m3cnza4HViwQug2jmdFccK1cgpwWWbyP7ajJtKuYfLOBACgt7eqPUYXTgG33Gtt97F+AvgcHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726495898; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=W4afRv48D4WfuLtGhUZ4DV33/lOaRTHjogzUeVJa7qU=; b=EktK8390J2O+KfwCwwUxQTJhWZBT7bDVxFU79RKO9Fc8PRMiE1kVVut+oP1VqwVxmZKqTKu6fDZtX0i5nrkyzXdCnnqlLYJDLa1M8IIx6p0P6DqeCJ7kKbZ+N3zMPoPs5yd8eOJyMuVceonHJ4MCIvDmlW7y9MG2218K6Wf+S6s= 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=1726495898; 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=W4afRv48D4WfuLtGhUZ4DV33/lOaRTHjogzUeVJa7qU=; b=JtUl3a71+ZZpuY+uBRDUr5RgSiJtSP8vVDCFsRFXCU68gHOQT+SEbsc3Ub8oXy3P MDm66KQK7S6Dd57zh2ROy9iBLGuMffIbRLeDnBG5wCXG7hhibHxv+sJ/QqdLsGPICa5 CqixHbO62bGLBLUz2ZYHrV3eON4n9AaYXkQgW7KE= Received: by mx.zohomail.com with SMTPS id 1726495896890779.0329775157529; Mon, 16 Sep 2024 07:11:36 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v3] libcamera: debayer_cpu: Sync DMABUFs Date: Mon, 16 Sep 2024 16:11:25 +0200 Message-ID: <20240916141125.212973-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 output. Not doing so currently results in occasional tearing and/or backlashes in GL/VK clients that use the buffers directly for rendering. An alternative approach to have the sync code in `MappedFrameBuffer` was considered but rejected for now, in order to allow clients more flexibility. Signed-off-by: Robert Mader Reviewed-by: Kieran Bingham --- Changes in v3: - add syncBufferForCPU() helper function Changes in v2: - sync input buffer as well - update commit title accordingly - small changes to the commit message - linting fixes, should pass now --- src/libcamera/software_isp/debayer_cpu.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index 077f7f4b..3748bd7c 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -12,8 +12,11 @@ #include "debayer_cpu.h" #include +#include #include +#include + #include #include "libcamera/internal/bayer_format.h" @@ -718,6 +721,17 @@ void DebayerCpu::process4(const uint8_t *src, uint8_t *dst) } } +static void syncBufferForCPU(FrameBuffer *buffer, uint64_t syncFlags) +{ + for (const FrameBuffer::Plane &plane : buffer->planes()) { + const int fd = plane.fd.get(); + struct dma_buf_sync sync = { syncFlags }; + + if (ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync) < 0) + LOG(Debayer, Error) << "Syncing buffer FD " << fd << "failed: " << errno; + } +} + static inline int64_t timeDiff(timespec &after, timespec &before) { return (after.tv_sec - before.tv_sec) * 1000000000LL + @@ -733,6 +747,9 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime); } + syncBufferForCPU(input, DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ); + syncBufferForCPU(output, DMA_BUF_SYNC_START | DMA_BUF_SYNC_WRITE); + green_ = params.green; red_ = swapRedBlueGains_ ? params.blue : params.red; blue_ = swapRedBlueGains_ ? params.red : params.blue; @@ -760,6 +777,9 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams metadata.planes()[0].bytesused = out.planes()[0].size(); + syncBufferForCPU(output, DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE); + syncBufferForCPU(input, DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ); + /* Measure before emitting signals */ if (measuredFrames_ < DebayerCpu::kLastFrameToMeasure && ++measuredFrames_ > DebayerCpu::kFramesToSkip) {