[{"id":37193,"web_url":"https://patchwork.libcamera.org/comment/37193/","msgid":"<85a4zz37ce.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-12-03T15:36:49","subject":"Re: [PATCH v6 01/24] libcamera: software_isp: gbm: Add a GBM helper\n\tclass for GPU surface access","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"https://lists.libcamera.org/pipermail/libcamera-devel/2025-June/050901.html\nstill not addressed.\n\nBryan O'Donoghue <bryan.odonoghue@linaro.org> writes:\n\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> 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              |  11 +++\n>  4 files changed, 181 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..6852def58\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> + * 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 createDevice();\n> +\tstruct gbm_device *getDevice();\n> +\tPixelFormat getPixelFormat();\n> +\n> +private:\n> +\tint fd_;\n> +\tstruct gbm_device *gbm_device_;\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..7d53cd43e\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> + * egl.cpp - 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::gbm_device_\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> +\tgbm_device_ = NULL;\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 (gbm_device_)\n> +\t\tgbm_device_destroy(gbm_device_);\n> +}\n> +\n> +/**\n> + * \\brief Create and initialize a GBM device\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\"; //TODO: get from an env or config setting\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> +\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> +\tformat_ = libcamera::formats::ARGB8888;\n> +\n> +\treturn 0;\n> +fail:\n> +\tclose(fd_);\n> +\treturn -errno;\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 gbm_device_;\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 90d434a5a..4eaa42062 100644\n> --- a/src/libcamera/meson.build\n> +++ b/src/libcamera/meson.build\n> @@ -70,6 +70,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> @@ -178,6 +188,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 E933FBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Dec 2025 15:36:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E006360F5F;\n\tWed,  3 Dec 2025 16:36:56 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 80D07609D8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Dec 2025 16:36:55 +0100 (CET)","from mail-wm1-f70.google.com (mail-wm1-f70.google.com\n\t[209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-307-mWDsg7IsPqKHwS5-fEMPTg-1; Wed, 03 Dec 2025 10:36:53 -0500","by mail-wm1-f70.google.com with SMTP id\n\t5b1f17b1804b1-477a0ddd1d4so38444455e9.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 03 Dec 2025 07:36:53 -0800 (PST)","from mzamazal-thinkpadp1gen7.tpbc.csb\n\t(ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-4792a79715fsm54871205e9.1.2025.12.03.07.36.50\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 03 Dec 2025 07:36:50 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"gIVflvxc\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1764776214;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=XMVX2Z/IghfU7CvdO0uIDPZiHLBvza3xUeJFvSNfalo=;\n\tb=gIVflvxcI9bgChrWtmKJbS70fUCD2ImrBEWSRB905+bn4itshK/99QCwYun82b1p3epu9g\n\tOda0THuCEyefoxiV2+8KEf7B9ifuqHfuv1ooZy0TuXo4nCP+rfsnymtVwhs150YBWs1VhC\n\tJ1hW+MBdeTy03BLyDLOkMzWDBHO34EM=","X-MC-Unique":"mWDsg7IsPqKHwS5-fEMPTg-1","X-Mimecast-MFC-AGG-ID":"mWDsg7IsPqKHwS5-fEMPTg_1764776212","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1764776211; x=1765381011;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject\n\t:date:message-id:reply-to;\n\tbh=XMVX2Z/IghfU7CvdO0uIDPZiHLBvza3xUeJFvSNfalo=;\n\tb=OKbwWJsHWdYSVubKuXelB29m/fBkdb5Yh6H2Qh2g39jycSQVvZZM2V3QrlQPTO+06h\n\tagl837QvSAhbxPtNL+tUZvSPxEt35QM5E5n9TL7znIZDuKxT680H1pIXsgcIW4x5NFxG\n\thU4FtsN3Gr8PDtE0JVGM+NtvUqGQyR6JIxtANPAq9z6+Kdt04hbLiDgnH9geaIRM58yg\n\tBNw8ifnOv80UOY8iZGPZ/JvfGkLWPnHHizj2pju7glP2lrWoHunXdEiL0vZ4D9U+6YGh\n\tPBe7Nb/E3d5bMKCUjLk5DKWxBuMhMmQ/GHZHsJhpgoDRa/gJLFBhSGhgGj4MZuEPraro\n\t7bTg==","X-Gm-Message-State":"AOJu0YwEEgrskT5EPg3gZqKSE6g3Rt2XbqQ+ybq8Jm2vMYK/amPbb9x/\n\tNcd1+UelaSYqRlvGBR9/MLjwZ6qUk8RnELEGzjf9L9rdBqUlMBxCmdpobV0vofsPxWrQBjfBE2e\n\t9XOfDqHOf+AGoBtEXJYP+fighRrTjfqAy+4TctUHWtIbuU2FIKONeBokCc12IGX3r8zSwqrVjhV\n\tN6c620HCU=","X-Gm-Gg":"ASbGncthzvrH1g5Ux1JPIMnHToCPNonerHcsbcGGkWf++IEAuUIGrArIxFooUERWrTK\n\tWcXiGyyktjN0IGbfcx7TexsOnxep6O93vbMK1W4cfom0uoRkOw5yKl2hCtUkCg7xa5vRUKDx3J4\n\tQrO73BDiTQWvpgR/GIdUrty4sw4V00kMSv4SgEMJ88m2C0U8KdvPYVGOip7gPZA81j5Wyg9A5/D\n\ttoGzr6DEc2l/eqJWpXm9Kif90lgmEv4C3bo9tHqYnYrgU6bDJO5cHvl9pNAR2D/g72vl5oYDsrm\n\ttJctDFGE1PVF9NBYorZ2LIxvolWPPYtSgBPzVNb3uwIg5ep5NjVLZxNMpYIAfO3IDWRJxqemAVZ\n\tVk6swpMNF05eZQqX7TcOInqrFBSo32VSySm0Qvk39utdELgb8tnQzNC3L43oU7Xc=","X-Received":["by 2002:a05:600c:3152:b0:475:dae5:d972 with SMTP id\n\t5b1f17b1804b1-4792af3dedfmr26598885e9.23.1764776211535; \n\tWed, 03 Dec 2025 07:36:51 -0800 (PST)","by 2002:a05:600c:3152:b0:475:dae5:d972 with SMTP id\n\t5b1f17b1804b1-4792af3dedfmr26598655e9.23.1764776211037; \n\tWed, 03 Dec 2025 07:36:51 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IG6qfiNZP/qzxUn+WMLCz9DM4Wu7biKk3QB63pThx2x38lvALZZsfzMukegEDeSUtbx/k3qAA==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Cc":"libcamera-devel@lists.libcamera.org,  pavel@ucw.cz,  Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v6 01/24] libcamera: software_isp: gbm: Add a GBM helper\n\tclass for GPU surface access","In-Reply-To":"<20251202134544.662446-2-bryan.odonoghue@linaro.org> (Bryan\n\tO'Donoghue's message of \"Tue, 2 Dec 2025 13:45:21 +0000\")","References":"<20251202134544.662446-1-bryan.odonoghue@linaro.org>\n\t<20251202134544.662446-2-bryan.odonoghue@linaro.org>","Date":"Wed, 03 Dec 2025 16:36:49 +0100","Message-ID":"<85a4zz37ce.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"niP1Nxln38xFvdqXcKzdN9QmwEo9uWycEcAotxwxHNs_1764776212","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>"}}]