From patchwork Thu Nov 27 02:37:16 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: 25238 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 C2614C3257 for ; Thu, 27 Nov 2025 02:37:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6280360AA4; Thu, 27 Nov 2025 03:37:48 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="v6e1zN0n"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B74A2609DE for ; Thu, 27 Nov 2025 03:37:46 +0100 (CET) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-47795f6f5c0so1431565e9.1 for ; Wed, 26 Nov 2025 18:37:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764211066; x=1764815866; 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=25pB8O0ewcdP9Lkbp8q4k2CjU62VSX7AV+aAc5IUYUA=; b=v6e1zN0noHZ0CcfQcwz++p9RmMQvLttJuoaLjJJWxvTYSJy0B2stl1wlu8v5hpIute KGbDZjh6cWBjoskL11wM+ROpLE/jmTMepm+Gu33yA9o1gYrEDi0SNnBM+4EqnKL9UiTH feesg9K3H6ubzSujN1dIM9v0eFlm0nEGV6sLxQyt5qifeJDh5rEsrQHbBNLinabu4km/ IERC1MV3X6tI/ffFGECoZD+L6t0UprtKu89Yq8XizMYdQMs/bkp1QzuW9VDekkWtk5Ml aVhboGgJs+9l6fRuGcrRBGRDgD6bOFY2Ji+FNqXIvMPjnHDYCAURWkzCAlzSbXkCMYsd fazQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764211066; x=1764815866; 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=25pB8O0ewcdP9Lkbp8q4k2CjU62VSX7AV+aAc5IUYUA=; b=a6/SqjblBMccaAwm2RwfTaFQFt+54FKNcPs8Ap0W10roDWOiFO+mfgdV5Kg6p7PBtb L2L0ASh8mSr2kIsp9uRbqU+BOqF8oSjGlTZOXSu+hzK9sUpfFuwTOrEnGnHZTPgB1fYw H1XgyAcNBcGDz7ija/rN6etY2uMJnT5uH0QCNqs7JVbjuSuhnKW+80c0wtmLrTaF/jIj yBqZ+MCdNMIM4fD0VxxfybVHTYHLAvmzuE+pN/Erritkbk4bMmVUzae4yM7pmkowGn8W cKbnK4lDKF1Wa/bHiQLcLSwHLv6SXg/zihHu3y0HHE8MmiWMI5u0WUuHlJcWEloKVBkd v1uQ== X-Gm-Message-State: AOJu0YypC7bqz5hpKoaUQr5QBp2L+GWx7RtHDZduuHdIbuSLLOKcXGx1 /wX5EfALUkJjNOYW9obOH0KDrJI0rdHNlF3C4YlE35fDnQj0arE1MU900eHKDux5gXbSa3pWdQm ArNCkGlc= X-Gm-Gg: ASbGncvu7qeACSsKbbcfKUkB0DIdPfoPNWn2ajmfSFoXNr5/QPsPG/dHA3walhLi9D2 dGWO7np7p++n0Ug3XFFLMPX13zNwR+OniSQOn7/MLKamGlZL4L93BC7fve8Ipve84I4zCdQAzV8 7wub+uJivYhE8BNZDOryHIETvAFK9MpL4+2fHvpuFFRqN9AgYWr4CAZ9+kneeL1zleeArJGz0z5 6HqyhXwbA76ahyzibAUskg0aMmAXP3M/pOwOCwuMwxptjOqXxJ4PPHN4IkcDmRUT4qBmUQhhQv7 nW2374IheNk+ytOjkdcDuX97o7lJvzbu00V6Sqm/SnzucyNJZwsDfH83nUmKTMZjT7lNTdBLJyr NEORZkXGVZl0Js4X1nb2oR9JqiAlfphWZHxRdVkCKGtNv3PWZpZ8F449rYbmYiuNor2Ld8c+wUI 9t6OT8lPvLhkCz4RdqSTbECWaiVtJAiHWRgIvVH8LLdQ/v/8Gs9YaVK45+wzC1njiJdNLt0vPa5 MWCkg== X-Google-Smtp-Source: AGHT+IGcWhzJBO2L5Al6zpkMFC0ws+AAOa45xxwnHeRxra6E2mmlTLUqG6m1lew8WR6uSrq0euRG+Q== X-Received: by 2002:a05:600c:474b:b0:477:8b2e:aa8f with SMTP id 5b1f17b1804b1-477c0181287mr253291615e9.15.1764211066059; Wed, 26 Nov 2025 18:37:46 -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-4790552c3c9sm58186345e9.0.2025.11.26.18.37.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 18:37:44 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Kieran Bingham Subject: [PATCH v5 01/24] libcamera: software_isp: gbm: Add a GBM helper class for GPU surface access Date: Thu, 27 Nov 2025 02:37:16 +0000 Message-ID: <20251127023739.179652-2-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251127023739.179652-1-bryan.odonoghue@linaro.org> References: <20251127023739.179652-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 Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/gbm.h | 39 ++++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/gbm.cpp | 130 +++++++++++++++++++++++++ src/libcamera/meson.build | 11 +++ 4 files changed, 181 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..6852def58 --- /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 + * + * gbm.h - 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 *gbm_device_; + 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..7d53cd43e --- /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 + * + * egl.cpp - 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::gbm_device_ + *\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; + gbm_device_ = NULL; +} + +/** + *\brief GBM destructor + * + * Cleans up the GBM device if it was successfully created, and closes + * the associated file descriptor. + */ +GBM::~GBM() +{ + if (gbm_device_) + gbm_device_destroy(gbm_device_); +} + +/** + * \brief Create and initialize a GBM device + * + * 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"; //TODO: get from an env or config setting + + fd_ = open(dri_node, O_RDWR | O_CLOEXEC); + if (fd_ < 0) { + LOG(GBM, Error) << "Open " << dri_node << " fail " << fd_; + return fd_; + } + + gbm_device_ = gbm_create_device(fd_); + if (!gbm_device_) { + LOG(GBM, Error) << "gbm_crate_device fail"; + goto fail; + } + + format_ = libcamera::formats::ARGB8888; + + return 0; +fail: + close(fd_); + return -errno; +} + +/** + * \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 gbm_device_; +} + +/** + * \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 90d434a5a..4eaa42062 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -70,6 +70,16 @@ 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 + config_h.set('HAVE_GBM', 1) + libcamera_internal_sources += files([ + 'gbm.cpp', + ]) +endif + subdir('base') subdir('converter') subdir('ipa') @@ -178,6 +188,7 @@ libcamera_deps += [ libcamera_base_private, libcrypto, libdl, + libgbm, liblttng, libudev, libyaml,