From patchwork Tue Jan 6 17:00:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 25655 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 4229EBDCC0 for ; Tue, 6 Jan 2026 17:01:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EE4C661FE8; Tue, 6 Jan 2026 18:01:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="xzGK2tgl"; dkim-atps=neutral Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 20B9E61F9F for ; Tue, 6 Jan 2026 18:01:07 +0100 (CET) Received: by mail-wr1-x444.google.com with SMTP id ffacd0b85a97d-42fb2314eb0so867968f8f.2 for ; Tue, 06 Jan 2026 09:01:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1767718866; x=1768323666; 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=dIJd7ak0Ig7Al4IlYwKYLFZCqKzLA54/kQmBA9xRHAI=; b=xzGK2tglHLszAl7ZIq9mP52yJcMbKtfEqNBVMXGMYEGaPEg7U+2HnLRt5aVvPGodAP 3tuhhc75y7FQnCsvCwhj7hoAFy1YsZAObzJfa14u0JPEek309X9MXQcH45fx2jvoN06N ffGd3dl83DPl+j6vGg1AGgVbriPBCTD/KbMisaYiORZN0+9qhmyNff2JaDeCLK6I67Fc 1RFxFPgOhRLOTRsWVsKzw2e4BONI/WPcS5mA2zy6ni2CVss+zD8fU1fDMwYKKAHmWEiF cUXy3kyQsSIkMy38mUsisXU514FyPpnMLGSuzhfyS4CCfhvkKJoPEmifrvfpo42tU0SS RIVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767718866; x=1768323666; 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=dIJd7ak0Ig7Al4IlYwKYLFZCqKzLA54/kQmBA9xRHAI=; b=uQ6FHI7kRq9upyS2R2P5ZbtJ6sWN/IRzU4ompzOSzw/AcYi0OYIa0Ns18M2SoDGJlZ V7poQU0i0yK65GVR+CxN55xy9bYkxSdZy1eB6KMfenh3UguRV1nWLTJcyuSVIVx9lOmh 18DOn/2shyi8i/CuBWkHpw5bNm6AUlBn/y+waEseDDX4GZe7WoY3Do0KsiPSMGD6dsfH grJ72IzHpbjsmNwqFvaKgnZl2IKdQy8aLNL/Dk1az3G+nCKCh5Vyq7qB5y4VDtVBJGQt fFz6q6MmEsUmWSgXuMuZu4DWPtlqp9obGP8rEMUyc0g3KHyXfbx9wYQBXOWlGrPKksTW F4QA== X-Gm-Message-State: AOJu0YyOTds5KUqIlKQh5ck3hyPgTwfAGyMgjHMLOha4x5WlRWQuwwm7 GSeVi/gegxx35VVV8NBMnYeaoaajOZVYbjeUAbCWLJ3C6UrCX/d+NFuQRbxpMdFmZ7k5eFPndPs FdnvfATeHZw== X-Gm-Gg: AY/fxX7u5Mx75AgFgf5nPEVrRk+5/T6WolyEaP09UPH1emih1CtVgznSj08Vefck05W ZcDnoWfra+KhU/52kNhKhpC+J8qs7007CWRa1HAEr+qY9fTNVPftes9v2Gp+lkrr9P/+8PKmNVp 5IFi734NkSC6Tni6bDp3t02BTYY+6A510G1wIVNpjM705LmMwtC4BShKBPFSApSILusDoxB+UQw e2gxZnWkTueuWCGMOcnPdBLFKFeD4Wi/IO3/guIX0zGkSggxvamGvwRefSuqhH53BBEtiimSTV+ Mr2uPyPiAXV7AiZI225Yi03cEIk7DgxQtM7uRlMAGwbBcetnKExrjMM6cZKlH0jh+AKgUMgTooc goA/wAGINmoKPauTkqpttoZY9H7OaziErdGXf81+FZrlPFSf6MK1lLCJg/RchXUL/jcpkBm9l7G JcvGtw2eIsnPZlpXXlGYUjs+h4zRjqOwoXJ8BL5nFqxtNrp5wK6ZOgLq17ItXukE86+xo= X-Google-Smtp-Source: AGHT+IEoSutKybrCsXzaTsn4ULJhLID7aLMymrnwLWy0LjOLzCpA8KF6SlkklKOxarC6nDXI08k0UQ== X-Received: by 2002:a05:6000:420f:b0:430:fd9f:e6e2 with SMTP id ffacd0b85a97d-432bca18993mr4224564f8f.9.1767718864770; Tue, 06 Jan 2026 09:01:04 -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 ffacd0b85a97d-432bd0dadcfsm5515322f8f.3.2026.01.06.09.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 09:01:04 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Kieran Bingham , Milan Zamazal , Robert Mader , Hans de Goede Subject: [PATCH v11 02/24] libcamera: software_isp: gbm: Add a GBM helper class for GPU surface access Date: Tue, 6 Jan 2026 17:00:37 +0000 Message-ID: <20260106170059.56193-3-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260106170059.56193-1-bryan.odonoghue@linaro.org> References: <20260106170059.56193-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 Reviewed-by: Robert Mader Tested-by: Hans de Goede # ThinkPad T14s gen 6 (arm64) ov02c10 + X1c gen 12 ov08x40 Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/gbm.h | 55 +++++++++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/gbm.cpp | 107 +++++++++++++++++++++++++ src/libcamera/meson.build | 10 +++ 4 files changed, 173 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..c10be06c1 --- /dev/null +++ b/include/libcamera/internal/gbm.h @@ -0,0 +1,55 @@ +/* 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 + +#include + +namespace libcamera { + +LOG_DECLARE_CATEGORY(GBM) + +class GBM +{ +public: + GBM(); + ~GBM(); + + int createDevice(); + + /** + * \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 *device() const { return gbmDevice_; } + + /** + * \brief Retrieve the pixel format + * + * \return The PixelFormat used by this GBM instance (ARGB8888) + */ + PixelFormat format() const { return format_; } + +private: + LIBCAMERA_DISABLE_COPY_AND_MOVE(GBM) + + UniqueFD fd_; + struct gbm_device *gbmDevice_ = nullptr; + 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..d37808b0c --- /dev/null +++ b/src/libcamera/gbm.cpp @@ -0,0 +1,107 @@ +/* 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 uninitialised state. + */ +GBM::GBM() +{ +} + +/** + *\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"; + + int fd = open(dri_node, O_RDWR | O_CLOEXEC | O_NOCTTY); + if (fd < 0) { + LOG(GBM, Error) << "Open " << dri_node << " fail " << strerror(errno); + return -errno; + } + fd_ = UniqueFD(fd); + + gbmDevice_ = gbm_create_device(fd_.get()); + if (!gbmDevice_) { + LOG(GBM, Error) << "gbm_create_device fail" << strerror(errno); + return -errno; + } + + format_ = libcamera::formats::ARGB8888; + + return 0; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 575408b2c..cb7863852 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 = dependency('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,