From patchwork Wed Dec 17 10:01:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 25574 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 366D4C326C for ; Wed, 17 Dec 2025 10:01:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8087461A37; Wed, 17 Dec 2025 11:01:45 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="RmSrsvWH"; dkim-atps=neutral Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4810161A2C for ; Wed, 17 Dec 2025 11:01:43 +0100 (CET) Received: by mail-wm1-x341.google.com with SMTP id 5b1f17b1804b1-477a2ab455fso59485825e9.3 for ; Wed, 17 Dec 2025 02:01:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765965702; x=1766570502; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dZHtM5rS1+WasttTnOa/hgF19f8pxm9uPEY0c2MJV14=; b=RmSrsvWH9jgiRhMvEn5xbNVHx/Mro0LxV77n0Le01NLG4cZpn8EAFFTI5YB4aRWjEl C/6OQ0Va8PqP6BA0Z1YzEIOv+cF8xAgVFteINuQpCEWk74MAA0EpUyoNipvCPlePyL64 xccokET6dUGN3pbaMMDSaP11t7hqsbVeWIz6HV4P96n/NdGn/RS1LcGt97BhXkmryBw4 1MVDMWCBPrUUn+FKmqlB6T+HZpT9DJqlm+OiEzplzw3feMZZWqJZfwDmcMn1ZxlVOahE WbSWb1f3H8L8HcatTgnnE2aDYTCZubYYaSFuMq4aZGtKluiI0Q4TNBO3X4wGmGwtpQxg a4Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765965702; x=1766570502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dZHtM5rS1+WasttTnOa/hgF19f8pxm9uPEY0c2MJV14=; b=wpmbApgdoGkJCRgP1rcPwxedqKBBzZ0IjILtsjWhTEqTl1vbMfrB53VNLAl2jceLaJ KXcY1dgzyTkrhum8DcMbsY78Vx7BB/xsb1EWaw9uIm/oEuH8K9KvUzosR6PKpAr0TTkl PmCGzbHMxacbhv3k48N6i0CCYTIhNEOgvWri/aD/Is/d8ypgoEQHstcdLu3DUFaaMR79 wrhLOpzFGQMGvkfepfeYGrt0Pf/PPlzMfZ+Vji8QhCCFeEX3f5AjcSdor0Iap5rslFGK ehslBxmaSUbmTqK0WKonNIwT85yhMXhbbfC7Ksrwkc4asNUcv1URWzzYPbJDYWbRsMCi qK+w== X-Gm-Message-State: AOJu0Yworxukr4t214YnLXsIvOdJONnxPrty4ld8ROyM8LlVcYB4EwwW OEQYtUw8g2MGP9qfg+R1QMgZzV5tCA2MlWg4/zcy8oPZpe4SozMPKpZmfiVgbKaUEjucbmy7JLj 8nlL72Gg= X-Gm-Gg: AY/fxX4CJ/wwPxD0nqtDPW2itw3Oe3k5B6NeET/PGyckJWTNWOQQgt2voU2lUVTt3PA ZDluvf1VyxYehPmD1FNzM1IL/0QRpo89bZ6+OvLmxtjL4BrCRIab/alPQ2ed0sV0NESPM4inBUq ec0SDJqDO0tOrsGp3BC3LUGPvZV4dGbSgLYNs0OEb5ZUEUYI9gcmzGG3dMuT8m1juSL8ZRCfdPj en1gkDldEkaH95dwv+qwwZ8BCLV4bfZwj9TiJNP/d6evFnRikf/tmJunN6ZjG8o9OcQ3q0JAATU aLwcpdRM4HRz0nJvIdOGl7FZ5CyIqExsLpOTC/+cSWwkBePYT24YdHIswtXJShndl1ypedXCYid +MiejY47ACWoN+eRoR8TsGjuDAkVXu6dbc82naxsQnPkfquhY0Sv99SvJ61L1XyJxMDOVizAGVW YawUyTI86J2vgO5WTDAZWWrmhSn0rJZtQ1wvqTaXXQot2rYk8dH8HjlJkcOtDLRCWm4cM= X-Google-Smtp-Source: AGHT+IHMTrPrehygcRjE2z/y9prMTCpPyyhNNyfOPbLgTjg29NyqDEMimKI+CpaAnhVH8xaKxGDXtw== X-Received: by 2002:a05:600c:19cd:b0:47a:819f:3acf with SMTP id 5b1f17b1804b1-47a8f8abfa7mr186808455e9.10.1765965702492; Wed, 17 Dec 2025 02:01:42 -0800 (PST) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47bdc1583fbsm32292585e9.0.2025.12.17.02.01.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 02:01:42 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Kieran Bingham , Milan Zamazal Subject: [PATCH v9 01/26] libcamera: software_isp: gbm: Add a GBM helper class for GPU surface access Date: Wed, 17 Dec 2025 10:01:13 +0000 Message-ID: <20251217100138.82525-2-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251217100138.82525-1-bryan.odonoghue@linaro.org> References: <20251217100138.82525-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" A helper class to interact with GBM. This will allow us to specify the internal storage format of the GPU when making a texture for the Debayer vertex/fragment shaders and thus ensure we receive an uncompressed and untiled output buffer. Acked-by: Kieran Bingham Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue Reviewed-by: Robert Mader --- include/libcamera/internal/gbm.h | 39 ++++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/gbm.cpp | 130 +++++++++++++++++++++++++ src/libcamera/meson.build | 10 ++ 4 files changed, 180 insertions(+) create mode 100644 include/libcamera/internal/gbm.h create mode 100644 src/libcamera/gbm.cpp diff --git a/include/libcamera/internal/gbm.h b/include/libcamera/internal/gbm.h new file mode 100644 index 000000000..09811d1ef --- /dev/null +++ b/include/libcamera/internal/gbm.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Linaro Ltd. + * + * Authors: + * Bryan O'Donoghue + * + * Helper class for managing GBM interactions + */ + +#pragma once + +#include + +#include + +#include + +namespace libcamera { + +LOG_DECLARE_CATEGORY(GBM) + +class GBM +{ +public: + GBM(); + ~GBM(); + + int createDevice(); + struct gbm_device *getDevice(); + PixelFormat getPixelFormat(); + +private: + int fd_; + struct gbm_device *gbmDevice_; + PixelFormat format_; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index e9540a2f7..b8324996b 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -23,6 +23,7 @@ libcamera_internal_headers = files([ 'dma_buf_allocator.h', 'formats.h', 'framebuffer.h', + 'gbm.h', 'global_configuration.h', 'ipa_data_serializer.h', 'ipa_manager.h', diff --git a/src/libcamera/gbm.cpp b/src/libcamera/gbm.cpp new file mode 100644 index 000000000..659860500 --- /dev/null +++ b/src/libcamera/gbm.cpp @@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Linaro Ltd. + * + * Authors: + * Bryan O'Donoghue + * + * Helper class for managing GBM interactions + */ + +#include "libcamera/internal/gbm.h" + +#include +#include +#include +#include +#include + +#include +#include + +namespace libcamera { + +LOG_DEFINE_CATEGORY(GBM) + +/** + * \class GBM + * \brief Helper class for managing GBM interactions + * + * The GBM class provides a simplified interface for creating and managing + * GBM devices. It handles the initialization and teardown of GBM devices + * used for buffer allocation in graphics and camera pipelines. + * + * This class is responsible for opening a DRI render node, creating a GBM + * device, and providing access to the device and its associated pixel format. + */ + +/** + *\var GBM::fd_ + *\brief file descriptor to DRI device + */ + +/** + *\var GBM::gbmDevice_ + *\brief Pointer to GBM device structure derived from fd_ + */ + +/** + *\var GBM::format_ + *\brief Pixel format the GBM surface was created in + */ + +/** + *\brief GBM constructor. + * + * Creates a GBM instance with unitialised state. + */ +GBM::GBM() +{ + fd_ = 0; + gbmDevice_ = nullptr; +} + +/** + *\brief GBM destructor + * + * Cleans up the GBM device if it was successfully created, and closes + * the associated file descriptor. + */ +GBM::~GBM() +{ + if (gbmDevice_) + gbm_device_destroy(gbmDevice_); +} + +/** + * \brief Create and initialize a GBM device + * + * \todo Get dri device name from envOption setting + * + * Opens the DRI render node (/dev/dri/renderD128) and creates a GBM + * device using the libgbm library. Sets the default pixel format to + * ARGB8888. + * + * \return 0 on success, or a negative error code on failure + */ +int GBM::createDevice() +{ + const char *dri_node = "/dev/dri/renderD128"; + + fd_ = open(dri_node, O_RDWR | O_CLOEXEC); + if (fd_ < 0) { + LOG(GBM, Error) << "Open " << dri_node << " fail " << fd_; + return fd_; + } + + gbmDevice_ = gbm_create_device(fd_); + if (!gbmDevice_) { + LOG(GBM, Error) << "gbm_create_device fail"; + close(fd_); + return -errno; + } + + format_ = libcamera::formats::ARGB8888; + + return 0; +} + +/** + * \brief Retrieve the GBM device handle + * + * \return Pointer to the gbm_device structure, or nullptr if the device + * has not been created + */ +struct gbm_device *GBM::getDevice() +{ + return gbmDevice_; +} + +/** + * \brief Retrieve the pixel format + * + * \return The PixelFormat used by this GBM instance (ARGB8888) + */ + +PixelFormat GBM::getPixelFormat() +{ + return format_; +} +} /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 575408b2c..e5b5330a8 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -70,6 +70,15 @@ libcamera_deps = [] libatomic = cc.find_library('atomic', required : false) libthreads = dependency('threads') +libgbm = cc.find_library('gbm', required: false) +gbm_works = cc.check_header('gbm.h', required: false) + +if libgbm.found() and gbm_works + libcamera_internal_sources += files([ + 'gbm.cpp', + ]) +endif + subdir('base') subdir('converter') subdir('ipa') @@ -178,6 +187,7 @@ libcamera_deps += [ libcamera_base_private, libcrypto, libdl, + libgbm, liblttng, libudev, libyaml,