[{"id":37422,"web_url":"https://patchwork.libcamera.org/comment/37422/","msgid":"<f473f526-b98c-435b-80a6-80a6325ba184@collabora.com>","date":"2025-12-17T10:30:32","subject":"Re: [PATCH v9 01/26] libcamera: software_isp: gbm: Add a GBM helper\n\tclass for GPU surface access","submitter":{"id":140,"url":"https://patchwork.libcamera.org/api/people/140/","name":"Robert Mader","email":"robert.mader@collabora.com"},"content":"We might want switch away from the GBM platform in a follow-up. For now:\n\nReviewed-by: Robert Mader <robert.mader@collabora.com>\n\nOn 17.12.25 11:01, Bryan O'Donoghue wrote:\n> A helper class to interact with GBM. This will allow us to specify the\n> internal storage format of the GPU when making a texture for the Debayer\n> vertex/fragment shaders and thus ensure we receive an uncompressed and\n> untiled output buffer.\n>\n> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>\n> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n> ---\n>   include/libcamera/internal/gbm.h       |  39 ++++++++\n>   include/libcamera/internal/meson.build |   1 +\n>   src/libcamera/gbm.cpp                  | 130 +++++++++++++++++++++++++\n>   src/libcamera/meson.build              |  10 ++\n>   4 files changed, 180 insertions(+)\n>   create mode 100644 include/libcamera/internal/gbm.h\n>   create mode 100644 src/libcamera/gbm.cpp\n>\n> diff --git a/include/libcamera/internal/gbm.h b/include/libcamera/internal/gbm.h\n> new file mode 100644\n> index 000000000..09811d1ef\n> --- /dev/null\n> +++ b/include/libcamera/internal/gbm.h\n> @@ -0,0 +1,39 @@\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> + * 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 createDevice();\n> +\tstruct gbm_device *getDevice();\n> +\tPixelFormat getPixelFormat();\n> +\n> +private:\n> +\tint fd_;\n> +\tstruct gbm_device *gbmDevice_;\n> +\tPixelFormat format_;\n> +};\n> +\n> +} /* namespace libcamera */\n> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\n> index e9540a2f7..b8324996b 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>       'global_configuration.h',\n>       'ipa_data_serializer.h',\n>       'ipa_manager.h',\n> diff --git a/src/libcamera/gbm.cpp b/src/libcamera/gbm.cpp\n> new file mode 100644\n> index 000000000..659860500\n> --- /dev/null\n> +++ b/src/libcamera/gbm.cpp\n> @@ -0,0 +1,130 @@\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> + * Helper class for managing GBM interactions\n> + */\n> +\n> +#include \"libcamera/internal/gbm.h\"\n> +\n> +#include <errno.h>\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> +/**\n> + * \\class GBM\n> + * \\brief Helper class for managing GBM interactions\n> + *\n> + * The GBM class provides a simplified interface for creating and managing\n> + * GBM devices. It handles the initialization and teardown of GBM devices\n> + * used for buffer allocation in graphics and camera pipelines.\n> + *\n> + * This class is responsible for opening a DRI render node, creating a GBM\n> + * device, and providing access to the device and its associated pixel format.\n> + */\n> +\n> +/**\n> + *\\var GBM::fd_\n> + *\\brief file descriptor to DRI device\n> + */\n> +\n> +/**\n> + *\\var GBM::gbmDevice_\n> + *\\brief Pointer to GBM device structure derived from fd_\n> + */\n> +\n> +/**\n> + *\\var GBM::format_\n> + *\\brief Pixel format the GBM surface was created in\n> + */\n> +\n> +/**\n> + *\\brief GBM constructor.\n> + *\n> + * Creates a GBM instance with unitialised state.\n> + */\n> +GBM::GBM()\n> +{\n> +\tfd_ = 0;\n> +\tgbmDevice_ = nullptr;\n> +}\n> +\n> +/**\n> + *\\brief GBM destructor\n> + *\n> + * Cleans up the GBM device if it was successfully created, and closes\n> + * the associated file descriptor.\n> + */\n> +GBM::~GBM()\n> +{\n> +\tif (gbmDevice_)\n> +\t\tgbm_device_destroy(gbmDevice_);\n> +}\n> +\n> +/**\n> + * \\brief Create and initialize a GBM device\n> + *\n> + * \\todo Get dri device name from envOption setting\n> + *\n> + * Opens the DRI render node (/dev/dri/renderD128) and creates a GBM\n> + * device using the libgbm library. Sets the default pixel format to\n> + * ARGB8888.\n> + *\n> + * \\return 0 on success, or a negative error code on failure\n> + */\n> +int GBM::createDevice()\n> +{\n> +\tconst char *dri_node = \"/dev/dri/renderD128\";\n> +\n> +\tfd_ = open(dri_node, O_RDWR | O_CLOEXEC);\n> +\tif (fd_ < 0) {\n> +\t\tLOG(GBM, Error) << \"Open \" << dri_node << \" fail \" << fd_;\n> +\t\treturn fd_;\n> +\t}\n> +\n> +\tgbmDevice_ = gbm_create_device(fd_);\n> +\tif (!gbmDevice_) {\n> +\t\tLOG(GBM, Error) << \"gbm_create_device fail\";\n> +\t\tclose(fd_);\n> +\t\treturn -errno;\n> +\t}\n> +\n> +\tformat_ = libcamera::formats::ARGB8888;\n> +\n> +\treturn 0;\n> +}\n> +\n> +/**\n> + * \\brief Retrieve the GBM device handle\n> + *\n> + * \\return Pointer to the gbm_device structure, or nullptr if the device\n> + * has not been created\n> + */\n> +struct gbm_device *GBM::getDevice()\n> +{\n> +\treturn gbmDevice_;\n> +}\n> +\n> +/**\n> + * \\brief Retrieve the pixel format\n> + *\n> + * \\return The PixelFormat used by this GBM instance (ARGB8888)\n> + */\n> +\n> +PixelFormat GBM::getPixelFormat()\n> +{\n> +\treturn format_;\n> +}\n> +} /* namespace libcamera */\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 575408b2c..e5b5330a8 100644\n> --- a/src/libcamera/meson.build\n> +++ b/src/libcamera/meson.build\n> @@ -70,6 +70,15 @@ 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> +    libcamera_internal_sources += files([\n> +        'gbm.cpp',\n> +    ])\n> +endif\n> +\n>   subdir('base')\n>   subdir('converter')\n>   subdir('ipa')\n> @@ -178,6 +187,7 @@ libcamera_deps += [\n>       libcamera_base_private,\n>       libcrypto,\n>       libdl,\n> +    libgbm,\n>       liblttng,\n>       libudev,\n>       libyaml,","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 A2A07C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 17 Dec 2025 10:30:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 52F5961A5B;\n\tWed, 17 Dec 2025 11:30:41 +0100 (CET)","from sender4-op-o12.zoho.com (sender4-op-o12.zoho.com\n\t[136.143.188.12])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E7D961A2C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Dec 2025 11:30:39 +0100 (CET)","by mx.zohomail.com with SMTPS id 176596743408147.42195420254427;\n\tWed, 17 Dec 2025 02:30:34 -0800 (PST)"],"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=\"Y0xaDnqo\"; \n\tdkim-atps=neutral","ARC-Seal":"i=1; a=rsa-sha256; t=1765967435; cv=none; \n\td=zohomail.com; s=zohoarc; \n\tb=V02k9jzS3QV3zOs65QQkNz8F+GMQEVoCnyeTOHXfO0CbdU5fLu1OJ0vhoBrTGNNO++G8K6R9QL4v25TUGMxHLSqY2/7Knns9lzJiuG+i7aqfHPeZeRsBrH6XwqQQ7TSnt/3V674TjhDBV9yEkJWxTWPvHGNgnEjT+hsTcShJGm4=","ARC-Message-Signature":"i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; \n\ts=zohoarc; t=1765967435;\n\th=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To:Cc;\n\tbh=+mqjhT07/4hLrduuhBX3oRb7h/p+3A+DAQ00SpPd5l4=; \n\tb=hEH+IqZ+nG7ms3/sqYvCLMCdKJt2D9adIpXvaTIZKTEFQgPVJWo4Hf7iLuOdYe3YRCm668/edIXlBQ74kaq6kI3lBI8t/YhGHLSKi9Vn58RlIfUoSvaMVA1g2jYrMnlfjExe/qlhtLH2YhQJYdRXw5mH8XiFz80UbFfh7ZvFMuQ=","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=1765967435;\n\ts=zohomail; d=collabora.com; i=robert.mader@collabora.com;\n\th=Message-ID:Date:Date:MIME-Version:Subject:Subject:To:To:References:From:From:In-Reply-To:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To:Cc;\n\tbh=+mqjhT07/4hLrduuhBX3oRb7h/p+3A+DAQ00SpPd5l4=;\n\tb=Y0xaDnqoPrwnKCVeByzA8ApPg8W2gRDO+wM3dBalZBGFo0wSz1iblNFZYTBmy15K\n\tY3uNgXV8CtNZbFrIgLw0euf/YQIKlhAq8VLaDQT+gpLkNt4IdsJcKKSyyHVU1JCQTad\n\tfFwgUFaEqOSz1DOyK+PFf2wjRvUFK1KlpRntFibs=","Message-ID":"<f473f526-b98c-435b-80a6-80a6325ba184@collabora.com>","Date":"Wed, 17 Dec 2025 11:30:32 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v9 01/26] libcamera: software_isp: gbm: Add a GBM helper\n\tclass for GPU surface access","To":"libcamera-devel@lists.libcamera.org","References":"<20251217100138.82525-1-bryan.odonoghue@linaro.org>\n\t<20251217100138.82525-2-bryan.odonoghue@linaro.org>","Content-Language":"en-US, de-DE","From":"Robert Mader <robert.mader@collabora.com>","In-Reply-To":"<20251217100138.82525-2-bryan.odonoghue@linaro.org>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>"}}]