From patchwork Thu Nov 20 09:49:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 25085 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 71C18C0F1B for ; Thu, 20 Nov 2025 09:50:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A46C7606E6; Thu, 20 Nov 2025 10:49:59 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=robert.mader@collabora.com header.b="PN+lxRFN"; dkim-atps=neutral Received: from sender3-pp-f112.zoho.com (sender3-pp-f112.zoho.com [136.143.184.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BA170606E6 for ; Thu, 20 Nov 2025 10:49:57 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; t=1763632192; cv=none; d=zohomail.com; s=zohoarc; b=ejXNiCBIXkRi/VD1GqSFWGCnrKT1BtukHm81d0SR+5kCIvxgTyyt3578e+OsI6K/f+ozgcPYIspAue8U8I52Ps6OOCE4vOLoEzNoWt1uS4N82l/vjXNpKLud2ddP00Qq9QE2lHMdf5TPqlEb//Xbuo5yp3svUn0fE1W0OsQFY9I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763632192; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=+iIAm30aDRC67zfxTSzYYlgjiEwVx4EFyui3p76t5wE=; b=ZxOLMYp8SlVUsju+8IPBg3IfYKopwhvxi35c0LMRUd0HACCOf/XedTmSMkow4C1+/Rx7IdnUaQoxQGXIg5pAbDJ5GUzUSkbOPsrWV1D92Gi+2b8rwOPI5T90/ojL/Yu0+QsncU2EzMZZbdY7MgBcUH0fXkIc1RfOKen8+g81TGM= 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=1763632192; 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=+iIAm30aDRC67zfxTSzYYlgjiEwVx4EFyui3p76t5wE=; b=PN+lxRFN7zipSFR+3Ltbb/mi/HkWJr5pX8OtMtYg//f9rKM0zrkgDMcQxQBw5HzV dDi6bD/AcymzS4kVp+PzeJ+UkJmqqf1vwth3sv9MQqszWMqpzAFuME+pA8wcELfabzo zptdbLofAv2KSfoVcz2YgFdJiqNGOxkqJNVROx2M= Received: by mx.zohomail.com with SMTPS id 1763632190746400.6753210444941; Thu, 20 Nov 2025 01:49:50 -0800 (PST) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH] qcam: Sync buffers before import Date: Thu, 20 Nov 2025 10:49:19 +0100 Message-ID: <20251120094919.12138-1-robert.mader@collabora.com> X-Mailer: git-send-email 2.51.1 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" Use the DmaSyncer handler to ensure the data from the buffer is coherent. This is required by the spec - from https://docs.kernel.org/driver-api/dma-buf.html#c.dma_buf_sync: > When a DMA buffer is accessed from the CPU via mmap, it is not always > possible to guarantee coherency between the CPU-visible map and > underlying memory. To manage coherency, DMA_BUF_IOCTL_SYNC must be used > to bracket any CPU access to give the kernel the chance to shuffle memory > around if needed. This was reported to fix glitches with the upcoming GPU-ISP, in which case the accessed data in written by the GPU. Note that in the GPU-ISP case we are effectively seeing a round-trip of the buffer contents - from GPU synced to CPU, copied to GPU again. We could avoid that in the future by implementing direct dmabuf import in qcam. Signed-off-by: Robert Mader --- src/apps/qcam/viewfinder_gl.cpp | 10 ++++++++-- src/apps/qcam/viewfinder_qt.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/apps/qcam/viewfinder_gl.cpp b/src/apps/qcam/viewfinder_gl.cpp index f31956ff0..0121c97ad 100644 --- a/src/apps/qcam/viewfinder_gl.cpp +++ b/src/apps/qcam/viewfinder_gl.cpp @@ -9,14 +9,16 @@ #include +#include + +#include "libcamera/internal/dma_buf_allocator.h" + #include #include #include #include #include -#include - #include "../common/image.h" static const QList supportedFormats{ @@ -542,6 +544,10 @@ void ViewFinderGL::doRender() /* Stride of the first plane, in pixels. */ unsigned int stridePixels; + std::vector dmaSyncers; + for (const libcamera::FrameBuffer::Plane &plane : buffer_->planes()) + dmaSyncers.emplace_back(plane.fd, libcamera::DmaSyncer::SyncType::Read); + switch (format_) { case libcamera::formats::NV12: case libcamera::formats::NV21: diff --git a/src/apps/qcam/viewfinder_qt.cpp b/src/apps/qcam/viewfinder_qt.cpp index 1a238922b..4d00f154d 100644 --- a/src/apps/qcam/viewfinder_qt.cpp +++ b/src/apps/qcam/viewfinder_qt.cpp @@ -11,6 +11,7 @@ #include #include +#include "libcamera/internal/dma_buf_allocator.h" #include #include @@ -114,6 +115,10 @@ void ViewFinderQt::render(libcamera::FrameBuffer *buffer, Image *image) * Otherwise, convert the format and release the frame * buffer immediately. */ + std::vector dmaSyncers; + for (const libcamera::FrameBuffer::Plane &plane : buffer->planes()) + dmaSyncers.emplace_back(plane.fd, libcamera::DmaSyncer::SyncType::Read); + converter_.convert(image, size, &image_); } } @@ -161,6 +166,12 @@ void ViewFinderQt::paintEvent(QPaintEvent *) /* If we have an image, draw it, with black letterbox rectangles. */ if (!image_.isNull()) { + if (buffer_) { + std::vector dmaSyncers; + for (const libcamera::FrameBuffer::Plane &plane : buffer_->planes()) + dmaSyncers.emplace_back(plane.fd, libcamera::DmaSyncer::SyncType::Read); + } + if (place_.width() < width()) { QRect rect{ 0, 0, (width() - place_.width()) / 2, height() }; painter.drawRect(rect);