Patch Detail
Show a patch.
GET /api/1.1/patches/21286/?format=api
{ "id": 21286, "url": "https://patchwork.libcamera.org/api/1.1/patches/21286/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21286/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20240916161231.238116-1-robert.mader@collabora.com>", "date": "2024-09-16T16:12:31", "name": "[v4] libcamera: debayer_cpu: Sync DMABUFs", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "65014dd6ef027073b26f14995f3873cfcb8f8736", "submitter": { "id": 140, "url": "https://patchwork.libcamera.org/api/1.1/people/140/?format=api", "name": "Robert Mader", "email": "robert.mader@collabora.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/21286/mbox/", "series": [ { "id": 4603, "url": "https://patchwork.libcamera.org/api/1.1/series/4603/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4603", "date": "2024-09-16T16:12:31", "name": "[v4] libcamera: debayer_cpu: Sync DMABUFs", "version": 4, "mbox": "https://patchwork.libcamera.org/series/4603/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21286/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21286/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 87906C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Sep 2024 16:13:03 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 498DF634FD;\n\tMon, 16 Sep 2024 18:13:02 +0200 (CEST)", "from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com\n\t[136.143.188.112])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C28DF634F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Sep 2024 18:13:00 +0200 (CEST)", "by mx.zohomail.com with SMTPS id 1726503175338244.25185611963502; \n\tMon, 16 Sep 2024 09:12:55 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=collabora.com\n\theader.i=robert.mader@collabora.com header.b=\"fsfrA7eu\"; \n\tdkim-atps=neutral", "ARC-Seal": "i=1; a=rsa-sha256; t=1726503177; cv=none; \n\td=zohomail.com; s=zohoarc; \n\tb=fGQSv8WNWytUemO9HNtxFZcmfSVicspoastwhdCepZ0gMQ9eplrPo8gXFCkJS813yrZ3xzgDyGONCfu8DxhunMakv9OGAzgj6lKrtwqG7Jqh8BCQqLL0FpjfpXK88ihe4doq8Gf108axujVpE7S5+8fn5nmWMIYh4oAyQ0hi6tg=", "ARC-Message-Signature": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; \n\ts=zohoarc; t=1726503177;\n\th=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To;\n\tbh=GGzkvg0O4b2dghmpBel4ye0Wgb0a4n0UwUb7oLqjiy4=; \n\tb=C6xKhajOeavlYXDOsyAoF9GJUtBiyLo8K3WYaHnrMXGrlM4LbkHiSX2NxeaIH75vy9u+Wi7HaS262StzzpVIL0oY92cMX564D/GX/Bwcoa3r/H8vkBZu3gp+UaJRv56suUZmvLQrCUUeF64yu7rIH2b0tDOokWlPpVwbj3/J2Fc=", "ARC-Authentication-Results": "i=1; mx.zohomail.com;\n\tdkim=pass header.i=collabora.com;\n\tspf=pass smtp.mailfrom=robert.mader@collabora.com;\n\tdmarc=pass header.from=<robert.mader@collabora.com>", "DKIM-Signature": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1726503177;\n\ts=zohomail; d=collabora.com; i=robert.mader@collabora.com;\n\th=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To;\n\tbh=GGzkvg0O4b2dghmpBel4ye0Wgb0a4n0UwUb7oLqjiy4=;\n\tb=fsfrA7eu67Dj2jbsot2TV0T5HtTDM1JhAQo20lWJv3CTzBO3bCJv3540HaLWmzEy\n\tKjiObb2U+tCCbVdkDV3EraKvdeGKCFIBtww/8KjfmJgDszfSTpqGQR+5ntSEdWbcSdI\n\tlh4tjj4fVi9/kYWs5CCWtJgRpl/4YSh58VriaGro=", "From": "Robert Mader <robert.mader@collabora.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Robert Mader <robert.mader@collabora.com>", "Subject": "[PATCH v4] libcamera: debayer_cpu: Sync DMABUFs", "Date": "Mon, 16 Sep 2024 18:12:31 +0200", "Message-ID": "<20240916161231.238116-1-robert.mader@collabora.com>", "X-Mailer": "git-send-email 2.46.0", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Using `DMA_BUF_IOCTL_SYNC` is required for DMABUFs in order to ensure\ncorrect output. Not doing so currently results in occasional tearing\nand/or backlashes in GL/VK clients that use the buffers directly for\nrendering.\n\nAn alternative approach to have the sync code in `MappedFrameBuffer` was\nconsidered but rejected for now, in order to allow clients more\nflexibility.\n\nSigned-off-by: Robert Mader <robert.mader@collabora.com>\n\n---\n\nChanges in v4:\n - Fixed errno handling\n - Added sync flags to error message\n - Wrapped syncBufferForCPU() and timeDiff() into an anonymous namespace\n\nChanges in v3:\n - add syncBufferForCPU() helper function\n\nChanges in v2:\n - sync input buffer as well\n - update commit title accordingly\n - small changes to the commit message\n - linting fixes, should pass now\n---\n src/libcamera/software_isp/debayer_cpu.cpp | 30 ++++++++++++++++++++++\n 1 file changed, 30 insertions(+)", "diff": "diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex 077f7f4b..96cf2c71 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -12,8 +12,11 @@\n #include \"debayer_cpu.h\"\n \n #include <stdlib.h>\n+#include <sys/ioctl.h>\n #include <time.h>\n \n+#include <linux/dma-buf.h>\n+\n #include <libcamera/formats.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n@@ -718,12 +721,33 @@ void DebayerCpu::process4(const uint8_t *src, uint8_t *dst)\n \t}\n }\n \n+namespace {\n+\n+static void syncBufferForCPU(FrameBuffer *buffer, uint64_t syncFlags)\n+{\n+\tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n+\t\tconst int fd = plane.fd.get();\n+\t\tstruct dma_buf_sync sync = { syncFlags };\n+\t\tint ret;\n+\n+\t\tret = ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);\n+\t\tif (ret < 0) {\n+\t\t\tret = errno;\n+\t\t\tLOG(Debayer, Error)\n+\t\t\t\t<< \"Syncing buffer FD \" << fd << \" with flags \"\n+\t\t\t\t<< syncFlags << \" failed: \" << strerror(-ret);\n+\t\t}\n+\t}\n+}\n+\n static inline int64_t timeDiff(timespec &after, timespec &before)\n {\n \treturn (after.tv_sec - before.tv_sec) * 1000000000LL +\n \t (int64_t)after.tv_nsec - (int64_t)before.tv_nsec;\n }\n \n+} /* namespace */\n+\n void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams params)\n {\n \ttimespec frameStartTime;\n@@ -733,6 +757,9 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams\n \t\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime);\n \t}\n \n+\tsyncBufferForCPU(input, DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ);\n+\tsyncBufferForCPU(output, DMA_BUF_SYNC_START | DMA_BUF_SYNC_WRITE);\n+\n \tgreen_ = params.green;\n \tred_ = swapRedBlueGains_ ? params.blue : params.red;\n \tblue_ = swapRedBlueGains_ ? params.red : params.blue;\n@@ -760,6 +787,9 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams\n \n \tmetadata.planes()[0].bytesused = out.planes()[0].size();\n \n+\tsyncBufferForCPU(output, DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE);\n+\tsyncBufferForCPU(input, DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ);\n+\n \t/* Measure before emitting signals */\n \tif (measuredFrames_ < DebayerCpu::kLastFrameToMeasure &&\n \t ++measuredFrames_ > DebayerCpu::kFramesToSkip) {\n", "prefixes": [ "v4" ] }