From patchwork Wed Dec 10 00:53:29 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: 25418 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 511EAC3257 for ; Wed, 10 Dec 2025 00:54:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0A6E06142E; Wed, 10 Dec 2025 01:54:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="gYqLgZHm"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 256E460C8A for ; Wed, 10 Dec 2025 01:54:18 +0100 (CET) Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-3436d6ca17bso6272988a91.3 for ; Tue, 09 Dec 2025 16:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765328056; x=1765932856; 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=UBzd3bPYq1z+FSzalswMcsz5+qWYsGqRnVaooRo7brY=; b=gYqLgZHmQl5SCSyAoTrWIyUJf7K59TqbXF8g+apKHDC/58ys8mLYbgw0OW318evdD6 0LYuJj6S6ocn647P6Jw5Hlczm0Ihil2skGGzIkAHX1Kzksrdb5J9+GE2vrU/hofkCmZ4 c0SmPfeNo2LYJ9jl7tKeyTahraLlqIkkYeG6u1LTlL68eWGQ1MoxrPCi4pj45s5P9llw 7+nMZkIsimTZFHxliRi5MEzzGC9gIR+XHW2dZH3qV8rBPXTYMzeVtK8ZTyh8GCnvHQKj cLQLB5e3jZVmTpuvNN+GsTDC9jeCsh4I5ixBob/eZVbDBNvrGl0EvTRgKy6QyNGT+KLT sLnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765328056; x=1765932856; 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=UBzd3bPYq1z+FSzalswMcsz5+qWYsGqRnVaooRo7brY=; b=EcIUqPWvTNZqEgfFU63rh+JS1aLSRLRZusb9Pr5QDUjmmR9cJeoLGW6LfsikmKAiV/ YbLuZ/smMeaOrO/7qQSUhmMYjGMnhQcipC8zQiMbjxvXLFVj9UogqE3jus4no+8IVkyt WNWYKSjfpNlASakj3qla05idgOezs5UHSpPDNPZiSLDcyGfP8ihF/jD/+sdBD2Il/3Ax Et4NqyuuXr9OnOfJCquiMis/wkpE4Cgp0p/FPBmlDNnPzyIL1phshPkoj6Re99t/UI5y pUKyWqJBnlHI0N5GtS5F+nvMQW0koc8eD9x6cPqUpX7t8JfZKv5pL4iFIGUFjjv+r23R ysow== X-Gm-Message-State: AOJu0YyIBNx9NNywnT5hS/dStCXsGBhlccwQpEmjc+GC9Drjj8LGu/t6 JCUFOiHGfMy7uT5feGmGNQyG5v2SdDtTIpFptZcJgCGv8k60j3t/ggktXBclZUrG9U19GEf1piQ 90WMm X-Gm-Gg: AY/fxX7ARX2n+3a5Ab5phlkEWeka7zDqkUGWkbvecWUqPGSQ9C9vvbDJba/pWJpghL4 8XVrQWKwy88kc5UewgQ6YK4tDZpEZHMe8VpW68SLVqa8iW4hjqrAS1fLLZfnereqaa8wPMLO2S/ JMa/5qp3T+jMl8Ygg0JoUnJKaLwX8pAcwIaQm8v3+rWwQX1rkAE+XbCoNj7+Uu8d1kkSSXXfmYF NPUxGzjEiHeVZvLnaQ/5qhojkupQ2xq5Ep1usDpARuD7LYpkbsR4i0y9iQtkbsd6y4LrbXW7ClG pbW6vR5e6iaXCVOwEalL9eudKKDzi+7gDv78hxleWACO1FM5/zL4EfpBb0KHtvNpRE/Ybk6J8MS BxRHt59LOb/REVFe1E/NJKt0PkCut7t6qWTsIqXMvrxPMNXgevQKIl8n8wfs6I4ZAppsJmsuLk2 1D8N48mmE6uf2a4jVx7AHqQOJXITC1yhXPw+DnXIBTX5x4MagSQnO63w062AxkvwstLAAVdemDY jI= X-Google-Smtp-Source: AGHT+IE/1D8bnPQBO9mzbWfWfuFe0bC4IgpxJDleoFpaw7WP7lXYr5BWbCb6PNHLVBXNbExvjHIZgQ== X-Received: by 2002:a17:90b:2808:b0:33b:b020:597a with SMTP id 98e67ed59e1d1-34a727159ffmr632116a91.0.1765328056515; Tue, 09 Dec 2025 16:54:16 -0800 (PST) Received: from inspiron14p-linux (p96936b06.osaknt01.ap.so-net.ne.jp. [150.147.107.6]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bf6875cc8eesm16057762a12.16.2025.12.09.16.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Dec 2025 16:54:16 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Kieran Bingham Subject: [PATCH v7 01/26] libcamera: software_isp: gbm: Add a GBM helper class for GPU surface access Date: Wed, 10 Dec 2025 00:53:29 +0000 Message-ID: <20251210005354.44726-2-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251210005354.44726-1-bryan.odonoghue@linaro.org> References: <20251210005354.44726-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..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..fcd8dd53c --- /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_ = NULL; +} + +/** + *\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 + * + * 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_; + } + + gbmDevice_ = gbm_create_device(fd_); + if (!gbmDevice_) { + LOG(GBM, Error) << "gbm_create_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 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 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,