Patch Detail
Show a patch.
GET /api/1.1/patches/23527/?format=api
{ "id": 23527, "url": "https://patchwork.libcamera.org/api/1.1/patches/23527/?format=api", "web_url": "https://patchwork.libcamera.org/patch/23527/", "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": "<20250611013245.133785-22-bryan.odonoghue@linaro.org>", "date": "2025-06-11T01:32:31", "name": "[21/35] libcamera: software_isp: gbm: Add in a GBM helper class for GPU surface access", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "5d662d344f8291e6dfca0c22081dfe841231edad", "submitter": { "id": 175, "url": "https://patchwork.libcamera.org/api/1.1/people/175/?format=api", "name": "Bryan O'Donoghue", "email": "bryan.odonoghue@linaro.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/23527/mbox/", "series": [ { "id": 5212, "url": "https://patchwork.libcamera.org/api/1.1/series/5212/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5212", "date": "2025-06-11T01:32:10", "name": "Add GLES 2.0 GPUISP to libcamera", "version": 1, "mbox": "https://patchwork.libcamera.org/series/5212/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/23527/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/23527/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 A5641C332E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 11 Jun 2025 01:34:03 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9B33468DE8;\n\tWed, 11 Jun 2025 03:34:02 +0200 (CEST)", "from mail-wm1-x329.google.com (mail-wm1-x329.google.com\n\t[IPv6:2a00:1450:4864:20::329])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3EEE168DDC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Jun 2025 03:34:00 +0200 (CEST)", "by mail-wm1-x329.google.com with SMTP id\n\t5b1f17b1804b1-43edecbfb94so73702195e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 Jun 2025 18:34:00 -0700 (PDT)", "from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie.\n\t[188.141.3.146]) by smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-4532514138asm5680625e9.3.2025.06.10.18.33.56\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 10 Jun 2025 18:33:59 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"sfXQIYHe\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1749605639; x=1750210439;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=Z2sgjAf/EwAQKD9LSQAsz8mndmwtt3Mb1vEfn9JsBDg=;\n\tb=sfXQIYHeyiZ19y84beByW9wVjXIStbFfx6pQbLo+C7k67rKjqgxPmPfdlSYuls78Xm\n\ttk8T1S9hp7slKcLLsJoZkmuEGQMACdFpQM2cw3rVBaVaECS3n7x4V80fL48lSQquIbrT\n\tQJgyMO+cF1wDjGCu8UEEniAo7wYKtJYNrLoH7OKn+zzPGzXkSTJGr6eneKPKTskXeSk4\n\tWoudHZnRdRT9wPoadxhtZG5i/Rg/7m6aYbXSRGTHLFnOKFjjFT0eU5gZFNI6kBoKPGju\n\tUIHgmQSCx9q0XTPbtVTF9j8kw7KOGne4LFN89FNR0CpcaL1eLi8evozHbI6Dpqlg9RL8\n\tlOag==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1749605639; x=1750210439;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=Z2sgjAf/EwAQKD9LSQAsz8mndmwtt3Mb1vEfn9JsBDg=;\n\tb=ASFi4lXle4ig2aNMDgifIURw0UwnEmP06dLmIofrQU3tuV30u/jVuICAkvvYIUfyqy\n\tNQ2KXxpB9fdeCNusbWi/UrZcnU2yyMjrkKXDYLr0paLn4UfnVRndEjwPiLBHu9HthYli\n\tPKQyt6ikMJBWkO3ovgl40qPkAzXjgeoOiN8zBauhPgAoD9NQyFO7O5/6F4HMbszbfb9r\n\t1F6AAgKBUccCCxnNdJyxyEKsQvVLAWNaxUU+wCjVm0k3tBK+Yh3aw2ma+dDBcapLZnWM\n\tvR76gDMmYcE/GRTbjFePNm1Bww2KzljRhX0NlFkehCJOcOdmnhF2oTDwIBOZLuHPAu+f\n\tQGzw==", "X-Gm-Message-State": "AOJu0Yy5PE1SwDD5t1be9g7xE9Tf0blK1AUGmyZcU8maOm3E6hGsAREu\n\tWGbXr4CNTR5yayb1p8ECjyzuuusxc5Sw1gfpWOXeDLadouJ5OnN2SljNH3LnQZV/hihpt7x/OzH\n\tY/uhePIc=", "X-Gm-Gg": "ASbGncsvTkv4hODFjoMWmhBNebHvagxcDAQrx7hBhHBCI9NuZ5DVlAhCe9DF2K1Ccih\n\tVjhoalCWbSlflq8wZHx7lpxw+/MaQIHlIk23ZV6G4nJPKaL0WNNkvY484DXI+EjeQUUrUGbwBBy\n\t0BnDaocxqUMIyWJAPEtzVt60ZXIbUZclKcSNeiNJYwMsYsN41vpMWIzNkzWtwJOlzqNN/pcCyd4\n\t+MA6M8I8mWc+tqBRTbtu4yniinpzjBFM9tsdIvEhr/ADdLEYDBAPC5saWqVqV0ZejOCQJ10CnQE\n\tentC2XmB5+SGUv0rhVVv+nYU7U6EbfGbb6XrMZVsYM2bKzYJTJY252vASrX1Wb3lg/HBNeD5eMn\n\tZ08EBW+iIFJLLdFbQY7tz7hv/iD9lFDgi16OJy7wAqA==", "X-Google-Smtp-Source": "AGHT+IEAB4AVvfYSnon/TOzXtlv+LWRuNAYkH6sNmYSwpzAT2yCPTVuiSqVdbnjBhcY2VQ1xmPh/nw==", "X-Received": "by 2002:a05:600c:4e4b:b0:453:9bf:6f7c with SMTP id\n\t5b1f17b1804b1-453248837fcmr9267265e9.9.1749605639516; \n\tTue, 10 Jun 2025 18:33:59 -0700 (PDT)", "From": "Bryan O'Donoghue <bryan.odonoghue@linaro.org>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Bryan O'Donoghue <bryan.odonoghue@linaro.org>", "Subject": "[PATCH 21/35] libcamera: software_isp: gbm: Add in a GBM helper\n\tclass for GPU surface access", "Date": "Wed, 11 Jun 2025 02:32:31 +0100", "Message-ID": "<20250611013245.133785-22-bryan.odonoghue@linaro.org>", "X-Mailer": "git-send-email 2.49.0", "In-Reply-To": "<20250611013245.133785-1-bryan.odonoghue@linaro.org>", "References": "<20250611013245.133785-1-bryan.odonoghue@linaro.org>", "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": "A helper class to interact with GBM. This will allow us to specify the\ninternal storage format of the CPU when making a texture for the Debayer\nvertext/fragment shaders and thus ensure we receive an uncompressed and\nuntiled output buffer.\n\nSigned-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n---\n include/libcamera/internal/gbm.h | 55 ++++++++++\n include/libcamera/internal/meson.build | 1 +\n src/libcamera/gbm.cpp | 137 +++++++++++++++++++++++++\n src/libcamera/meson.build | 11 ++\n 4 files changed, 204 insertions(+)\n create mode 100644 include/libcamera/internal/gbm.h\n create mode 100644 src/libcamera/gbm.cpp", "diff": "diff --git a/include/libcamera/internal/gbm.h b/include/libcamera/internal/gbm.h\nnew file mode 100644\nindex 00000000..a5486cc9\n--- /dev/null\n+++ b/include/libcamera/internal/gbm.h\n@@ -0,0 +1,55 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Linaro Ltd.\n+ *\n+ * Authors:\n+ * Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n+ *\n+ * gbm.h - Helper class for managing GBM interactions.\n+ */\n+\n+#pragma once\n+\n+#include <gbm.h>\n+\n+#include <libcamera/base/log.h>\n+\n+#include <libcamera/formats.h>\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(GBM)\n+\n+class GBM\n+{\n+public:\n+\tGBM();\n+\t~GBM();\n+\n+\tint initSurface(uint32_t width, uint32_t height);\n+\tint mapSurface();\n+\tint getFrameBufferData(uint8_t *data_out, size_t data_len);\n+\tstruct gbm_device *getDevice() { return gbm_device_; }\n+\tstruct gbm_surface *getSurface() { return gbm_surface_; }\n+\tuint32_t getFrameSize() { return framesize_; }\n+\tuint32_t getStride() { return stride_; }\n+\tPixelFormat getPixelFormat() { return format_; }\n+\n+private:\n+\tint fd_;\n+\tstruct gbm_device *gbm_device_;\n+\tstruct gbm_surface *gbm_surface_;\n+\n+\tstruct gbm_bo *gbm_bo_;\n+\tuint32_t width_;\n+\tuint32_t height_;\n+\tuint32_t stride_;\n+\tuint32_t offset_;\n+\tuint32_t framesize_;\n+\tvoid *map_;\n+\tint bo_fd_;\n+\n+\tPixelFormat format_;\n+};\n+\n+} // namespace libcamera\ndiff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\nindex c0b593bf..4a2919f6 100644\n--- a/include/libcamera/internal/meson.build\n+++ b/include/libcamera/internal/meson.build\n@@ -23,6 +23,7 @@ libcamera_internal_headers = files([\n 'dma_buf_allocator.h',\n 'formats.h',\n 'framebuffer.h',\n+ 'gbm.h',\n 'ipa_data_serializer.h',\n 'ipa_manager.h',\n 'ipa_module.h',\ndiff --git a/src/libcamera/gbm.cpp b/src/libcamera/gbm.cpp\nnew file mode 100644\nindex 00000000..43032093\n--- /dev/null\n+++ b/src/libcamera/gbm.cpp\n@@ -0,0 +1,137 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Linaro Ltd.\n+ *\n+ * Authors:\n+ * Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n+ *\n+ * egl.cpp - Helper class for managing GBM interactions.\n+ */\n+\n+#include \"libcamera/internal/gbm.h\"\n+\n+#include <fcntl.h>\n+#include <sys/ioctl.h>\n+#include <sys/mman.h>\n+#include <unistd.h>\n+\n+#include <linux/dma-buf.h>\n+#include <linux/dma-heap.h>\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(GBM)\n+\n+GBM::GBM()\n+{\n+\tfd_ = 0;\n+}\n+\n+GBM::~GBM()\n+{\n+\tif (gbm_surface_)\n+\t\tgbm_surface_destroy(gbm_surface_);\n+\n+\tif (gbm_device_)\n+\t\tgbm_device_destroy(gbm_device_);\n+\n+\tif (fd_ >= 0)\n+\t\tclose(fd_);\n+}\n+\n+// this should probably go into its own class to deal with the\n+// allocation and deletion of frambuffers attached to GBM devices/objects\n+int GBM::initSurface(uint32_t width, uint32_t height)\n+{\n+\tconst char *dri_node = \"/dev/dri/renderD128\"; //TODO: get from an env or config setting\n+\n+\tfd_ = open(dri_node, O_RDWR | O_CLOEXEC); //TODO: CLOEXEC ?\n+\tif (fd_ < 0) {\n+\t\tLOG(GBM, Error) << \"Open \" << dri_node << \" fail \" << fd_;\n+\t\treturn fd_;\n+\t}\n+\n+\tgbm_device_ = gbm_create_device(fd_);\n+\tif (!gbm_device_) {\n+\t\tLOG(GBM, Error) << \"gbm_crate_device fail\";\n+\t\tgoto fail;\n+\t}\n+\n+\t// GBM_FORMAT_RGBA8888 is not supported mesa::src/gbm/dri/gbm_dri.c::gbm_dri_visuals_table[]\n+\t// This means we need to choose XRGB8888 or ARGB8888 as the raw buffer format\n+\tgbm_surface_ = gbm_surface_create(gbm_device_, width, height, GBM_FORMAT_ARGB8888,\n+\t\t\t\t\t GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR);\n+\tif (!gbm_surface_) {\n+\t\tLOG(GBM, Error) << \"Unable to create linear gbm surface\";\n+\t\tgoto fail;\n+\t}\n+\n+\tformat_ = libcamera::formats::ARGB8888;\n+\n+\treturn 0;\n+fail:\n+\treturn -ENODEV;\n+}\n+\n+int GBM::mapSurface()\n+{\n+\tgbm_bo_ = gbm_surface_lock_front_buffer(gbm_surface_);\n+\tif (!gbm_bo_) {\n+\t\tLOG(GBM, Error) << \"GBM input buffer object create fail\";\n+\t\treturn -ENODEV;\n+\t}\n+\tgbm_surface_release_buffer(gbm_surface_, gbm_bo_);\n+\n+\tbo_fd_ = gbm_bo_get_fd(gbm_bo_);\n+\n+\tif (!bo_fd_) {\n+\t\tgbm_surface_release_buffer(gbm_surface_, gbm_bo_);\n+\t\tLOG(GBM, Error) << \"Unable to get fd for bo: \" << bo_fd_;\n+\t\treturn -ENODEV;\n+\t}\n+\n+\tstride_ = gbm_bo_get_stride(gbm_bo_);\n+\twidth_ = gbm_bo_get_width(gbm_bo_);\n+\theight_ = gbm_bo_get_height(gbm_bo_);\n+\toffset_ = gbm_bo_get_offset(gbm_bo_, 0);\n+\tframesize_ = height_ * stride_;\n+\n+\tmap_ = mmap(NULL, height_ * stride_, PROT_READ, MAP_SHARED, bo_fd_, 0);\n+\tif (map_ == MAP_FAILED) {\n+\t\tLOG(GBM, Error) << \"mmap gbm_bo_ fail\";\n+\t\treturn -ENODEV;\n+\t}\n+\n+\tLOG(GBM, Debug) << \" stride \" << stride_\n+\t\t\t<< \" width \" << width_\n+\t\t\t<< \" height \" << height_\n+\t\t\t<< \" offset \" << offset_\n+\t\t\t<< \" framesize \" << framesize_;\n+\n+\treturn 0;\n+}\n+\n+int GBM::getFrameBufferData(uint8_t *data, size_t data_len)\n+{\n+\tstruct dma_buf_sync sync;\n+\n+\tgbm_surface_lock_front_buffer(gbm_surface_);\n+\n+\tsync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ;\n+\tioctl(bo_fd_, DMA_BUF_IOCTL_SYNC, &sync);\n+\n+\tif (data_len > framesize_) {\n+\t\tLOG(GBM, Error) << \"Invalid read size \" << data_len << \" max is \" << framesize_;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tmemcpy(data, map_, data_len);\n+\n+\tsync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ;\n+\tioctl(bo_fd_, DMA_BUF_IOCTL_SYNC, &sync);\n+\n+\tgbm_surface_release_buffer(gbm_surface_, gbm_bo_);\n+\n+\treturn 0;\n+}\n+} //namespace libcamera\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 202db1ef..0d004694 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -67,6 +67,16 @@ libcamera_deps = []\n libatomic = cc.find_library('atomic', required : false)\n libthreads = dependency('threads')\n \n+libgbm = cc.find_library('gbm', required: false)\n+gbm_works = cc.check_header('gbm.h', required: false) \n+\n+if libgbm.found() and gbm_works\n+ config_h.set('HAVE_GBM', 1)\n+ libcamera_internal_sources += files([\n+ 'gbm.cpp',\n+ ])\n+endif\n+\n subdir('base')\n subdir('converter')\n subdir('ipa')\n@@ -188,6 +198,7 @@ libcamera_deps += [\n libcamera_base_private,\n libcrypto,\n libdl,\n+ libgbm,\n liblttng,\n libudev,\n libyaml,\n", "prefixes": [ "21/35" ] }