[{"id":36313,"web_url":"https://patchwork.libcamera.org/comment/36313/","msgid":"<85ldlbdqiy.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-10-16T11:39:33","subject":"Re: [PATCH v3 24/39] libcamera: software_isp: gbm: Add in a GBM\n\thelper class for GPU surface access","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hi Bryan,\n\nsee\nhttps://lists.libcamera.org/pipermail/libcamera-devel/2025-June/050901.html\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 CPU when making a texture for the Debayer\n> vertext/fragment shaders and thus ensure we receive an uncompressed and\n> untiled output buffer.\n>\n> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n> ---\n>  include/libcamera/internal/gbm.h | 43 ++++++++++++++++++\n>  include/libcamera/internal/meson.build |  1 +\n>  src/libcamera/gbm.cpp | 61 ++++++++++++++++++++++++++\n>  src/libcamera/meson.build              | 11 +++++\n>  4 files changed, 116 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 00000000..41b5e00f\n> --- /dev/null\n> +++ b/include/libcamera/internal/gbm.h\n> @@ -0,0 +1,43 @@\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> +/**\n> + * \\brief Helper class for managing GBM interactions\n> + *\n> + */\n> +class GBM\n> +{\n> +public:\n> +\tGBM();\n> +\t~GBM();\n> +\n> +\tint createDevice();\n> +\tstruct gbm_device *getDevice() { return gbm_device_; }\n> +\tPixelFormat getPixelFormat() { return format_; }\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 ecb7c9fa..01a36595 100644\n> --- a/include/libcamera/internal/meson.build\n> +++ b/include/libcamera/internal/meson.build\n> @@ -24,6 +24,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 00000000..caf9ca1c\n> --- /dev/null\n> +++ b/src/libcamera/gbm.cpp\n> @@ -0,0 +1,61 @@\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_device_)\n> +\t\tgbm_device_destroy(gbm_device_);\n> +\n> +\tif (fd_ >= 0)\n> +\t\tclose(fd_);\n> +}\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> +\treturn -ENODEV;\n> +}\n> +} //namespace libcamera\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 5b9b86f2..fe60c875 100644\n> --- a/src/libcamera/meson.build\n> +++ b/src/libcamera/meson.build\n> @@ -69,6 +69,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> @@ -176,6 +186,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 EE158C32CE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 16 Oct 2025 11:39:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 47B3560684;\n\tThu, 16 Oct 2025 13:39:43 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 84AFC60678\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Oct 2025 13:39:40 +0200 (CEST)","from mail-lf1-f71.google.com (mail-lf1-f71.google.com\n\t[209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-606-SjfrXXfRMgiTb9qPrezXxA-1; Thu, 16 Oct 2025 07:39:38 -0400","by mail-lf1-f71.google.com with SMTP id\n\t2adb3069b0e04-590655b187aso600445e87.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Oct 2025 04:39:37 -0700 (PDT)","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\t2adb3069b0e04-59088563c37sm7018662e87.59.2025.10.16.04.39.34\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 16 Oct 2025 04:39:35 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"IbbimOwc\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1760614779;\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=4Y9OiBK8SUi56J6ksQe1vaNwsHXp42tFvfQfc22r0Pw=;\n\tb=IbbimOwc/VIH+Aupde61oOHdgDsCP/Mw5ZwlTzONScwslIPBj4BsWfIQOyjlX8YN9gDJBN\n\t5CGsQgYMfsONECb4J1Vx8qxCTFwhtbFOgYFkRkk7+13Q8nFFCf1M+iC2uKztRIvPpGhF+p\n\tgGVHR2gmxM8myAKGZfd7BHWFjMbJVIc=","X-MC-Unique":"SjfrXXfRMgiTb9qPrezXxA-1","X-Mimecast-MFC-AGG-ID":"SjfrXXfRMgiTb9qPrezXxA_1760614777","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1760614776; x=1761219576;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=4Y9OiBK8SUi56J6ksQe1vaNwsHXp42tFvfQfc22r0Pw=;\n\tb=ELffD3pHfQnaquFHfPIjwSPiDE1fUcAeIunZg6f890ITb3YpyaWq9dRqdU7C3gHQtE\n\tVAoAmxbdw5PLCCYBrtjQp8WCxfszPHFsCylEGbb4zce8kKdf9dldCU2i1eJruB6JVtpB\n\tq2TP/b0t3Bn+ZDOv1TqlYEdf+sylXcxy8GwHZ3mxyy/oDODF3cyeaM1xvl64FFUla+lY\n\tmoV56M+PEL1FSn2fw61CYSilyznmnMIEqY7EVIXFgmullWoa6aftyB2GSKdur0sQwodk\n\tgKyEhKiGuNNzEu7Srg9Zgwti+IcexvEvvuMY7XmHXJARQoaez7VtbH2RUx4gpuZT3cm9\n\tCotg==","X-Gm-Message-State":"AOJu0Yw3y2TGBY5XxaSDmNXjUnusSzxgU4xiecnfrkJtMVzGYE/f+ZtA\n\tfz6D8WKntWJy0d+3xQqzHOV4PHEUb/MvykH0A+hMzV7HManHd6SYGxJJHQtf2v3uz/KJBmzQvbR\n\tuok0NlUv+neTAlcM5dlbro01GbTNkznEQF8lXf0ekwjL/vO2upkIeEORhxWWRgcShW0iwYR/olk\n\tg=","X-Gm-Gg":"ASbGncvSYVNXswo5utRAbTNhTSg17RAKl9s9kyVp9CsiY58MXh9JoTNG1yJMa6pJp49\n\tef+DUr6CWxF8Gi//+EIl/v8DGointe+CYyDL3IG89M28bormr+WZxJE/4wh5HV7T85yOt2U683n\n\tezy81rbzVIXC76ZJhqQUlD9E2DvWOEsfbLAMwu+6aQt1aaFPkDJ6baapLfRY0CwKhl9n+53fQox\n\tgc4IwSO9+A9ChnT2oGdyIa0ZVtzKnKV3lLfNBqhSutmXFamxjJ9sa4TJhMtQ0lizt4ysZhxPZSW\n\t+zMxK7a20rlW9dodYbX2v2tkOtDjE5YR7c4Zgp63xwB+k1mJlbTkrhcSe3UnZ+3+NtwAdAilm94\n\tFO9Gn/0EDY0Zf4PHKBFGTVvWBPLIe8tPyxhBClWeerTyK95bzmgpF","X-Received":["by 2002:a05:6512:3d21:b0:55f:4c1d:47f3 with SMTP id\n\t2adb3069b0e04-5906d8e64a4mr9801810e87.28.1760614776312; \n\tThu, 16 Oct 2025 04:39:36 -0700 (PDT)","by 2002:a05:6512:3d21:b0:55f:4c1d:47f3 with SMTP id\n\t2adb3069b0e04-5906d8e64a4mr9801794e87.28.1760614775817; \n\tThu, 16 Oct 2025 04:39:35 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IHrFBJQe+OFcjRMgeU5AlcZKanMz7Lby3aAKXDVZUgSLeymKvaVH8R5zGXQchDtkahpuJJgtg==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Cc":"libcamera-devel@lists.libcamera.org,  hdegoede@redhat.com,\n\tbod.linux@nxsw.ie","Subject":"Re: [PATCH v3 24/39] libcamera: software_isp: gbm: Add in a GBM\n\thelper class for GPU surface access","In-Reply-To":"<20251015012251.17508-25-bryan.odonoghue@linaro.org> (Bryan\n\tO'Donoghue's message of \"Wed, 15 Oct 2025 02:22:36 +0100\")","References":"<20251015012251.17508-1-bryan.odonoghue@linaro.org>\n\t<20251015012251.17508-25-bryan.odonoghue@linaro.org>","Date":"Thu, 16 Oct 2025 13:39:33 +0200","Message-ID":"<85ldlbdqiy.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":"tHkfgFabv5Jy3_oLBsBbDeJ2OfVhIVJxJ1Sbl66_pPU_1760614777","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>"}},{"id":36809,"web_url":"https://patchwork.libcamera.org/comment/36809/","msgid":"<aRcWgb5oVe2GJ5R2@duo.ucw.cz>","date":"2025-11-14T11:46:09","subject":"Re: [PATCH v3 24/39] libcamera: software_isp: gbm: Add in a GBM\n\thelper class for GPU surface access","submitter":{"id":49,"url":"https://patchwork.libcamera.org/api/people/49/","name":"Pavel Machek","email":"pavel@ucw.cz"},"content":"Hi!\n\n(I hope I got headers right; archive damaged them).\n\n> A helper class to interact with GBM. This will allow us to specify the\n> internal storage format of the CPU when making a texture for the Debayer\n> vertext/fragment shaders and thus ensure we receive an uncompressed and\n> untiled output buffer.\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> +\treturn -ENODEV;\n> +}\n\nfail: needs to close(fd_), AFAICT.\n\nReturn code is confusing here, btw. If you wanted to return errno in\nthe first case, you'd need to \"return -errno\".\n\nBest regards,\n\t\t\t\t\t\t\t\tPavel","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 9D315C3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 14 Nov 2025 11:46:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AD1EB60A8B;\n\tFri, 14 Nov 2025 12:46:12 +0100 (CET)","from jabberwock.ucw.cz (jabberwock.ucw.cz [46.255.230.98])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8112D606E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 14 Nov 2025 12:46:10 +0100 (CET)","by jabberwock.ucw.cz (Postfix, from userid 1017)\n\tid 0F0A51C00AB; Fri, 14 Nov 2025 12:46:10 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ucw.cz header.i=@ucw.cz header.b=\"aIF9xG0O\";\n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1;\n\tt=1763120770;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=oXlTue/bSA7RyU3I0BFxRJsTS6wYMrpzXV6Ybr61yzE=;\n\tb=aIF9xG0OS5q2xOe9BiIecDSqyjDazCXRDc1p3IOV8OTGu5Khc3hAS/APZFNHzonbLG8l7k\n\tSlO3+/La+LlaVSae/RmVGapFmG+id0N+umFE3gVmgip+40AjGlqwOc/ECgxoSI2un3QvOd\n\tRo1OneE781pf/vIYh6Hhjd09iBf2MJE=","Date":"Fri, 14 Nov 2025 12:46:09 +0100","From":"Pavel Machek <pavel@ucw.cz>","To":"libcamera-devel@lists.libcamera.org, bryan.odonoghue@linaro.org","Subject":"Re: [PATCH v3 24/39] libcamera: software_isp: gbm: Add in a GBM\n\thelper class for GPU surface access","Message-ID":"<aRcWgb5oVe2GJ5R2@duo.ucw.cz>","References":"<20251015012251.17508-1-bryan.odonoghue@linaro.org>\n\t<20251015012251.17508-25-bryan.odonoghue@linaro.org>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha1;\n\tprotocol=\"application/pgp-signature\"; boundary=\"46qoElnsjr1YqLSQ\"","Content-Disposition":"inline","In-Reply-To":"<20251015012251.17508-25-bryan.odonoghue@linaro.org>","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>"}}]