From patchwork Tue Dec 2 13:45:21 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: 25310 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 605AEC3260 for ; Tue, 2 Dec 2025 13:45:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 977A860C88; Tue, 2 Dec 2025 14:45:55 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="AhyndsQq"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7190E60C77 for ; Tue, 2 Dec 2025 14:45:53 +0100 (CET) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4779adb38d3so41021105e9.2 for ; Tue, 02 Dec 2025 05:45:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764683152; x=1765287952; 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=n/Dr3v1jgs2rQ+R/y4XCcTtZPdFoLGM7Zc7OE3xBNt0=; b=AhyndsQqpCs9FbJlPxS8yb2eJ3NQDtSqyFUDxpODH9kqcG18kxen3hp67JV61zFKkP 3am1VNEvXVNj9X3tuUb5cuqYdCpNmvdrwA26pYze/CV5+LwZ/yMLyTQ9JhKw/4wKGgw6 Mj0utGZtt2sBB7JNknxfzhHZJxniCLkbDkUQk3777J8cWwoVongnkR9bZuxRDu5g21cL 7lRobMawP3NLdSvmgO8DXyAdDW7bMeym8NpIJJWV9871+B+jTluQAsi9zMDfkgScop7T avXQNRUPg0qevSRPHXFpNJCexyjvPtb8WhbgveR6Oe/lyzisbDLtxVdkgkIE/fUcV4Yz f+1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764683152; x=1765287952; 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=n/Dr3v1jgs2rQ+R/y4XCcTtZPdFoLGM7Zc7OE3xBNt0=; b=dJ++ohvwofHFNbvHAMaecKQYrSCabDh6YogDlpIJp7EJbz4Sl3JKo1ArDTGBFbUC3O kmNHqgZApFo2CBAkvlRKUVVcaK3IcXlOJM6bDM0mGAGVN26JG4YoxcAWYKsaKvBCEDBI RIt3oWu+xMnRtslEe/CtKH+r7NW7jctYXppNO4t9/YjW0RRT7KihMz75id0p8Sgn55RF aYbmE9oGWHjuczMwyDgu/ytFS8WIPWDBTCFdUGbFGOVY78crPdaknZAsFMVb4zruXJlZ E6ad/F0PkRNU1saJzj74rG0zajwikz1lqLhfp8zS8vxzGWqBL0oQX1XpjocEDTydul6Z PwMg== X-Gm-Message-State: AOJu0Yy8NUL7LSPTNqL+SE0SxYWYyNz3ouwiBLPMz3Pe7UkD3nXeQbJn UvtZUaHm6xKZHz7OIPzQouOrtd3+bnJ5sMMagOVp7q122c52ygAAzdpkDF0zqBHOvrSBOTGCeAT uCL3S X-Gm-Gg: ASbGncvEbxEWhhBWzO6L/CuoEYyh3grXmt+yw/ZkJWHgt0ElPT7tzWgg9m3n/1nb1/w x4tXsZUSZ7LHNU/iCUjFYFGX2x7TCrKiH+DLP+vD03Nuoqz+qRr5Lpwi9PNJgBUtCsdypHAA5g3 Z3TSYq4x4T37xRpd5yYw7DdYzrthiQgZbKMM5up1BmqZzsxhVrn8/SXG2QJP9WRBa9/FaYfxHen Ve1hOPJe9CQVsV4LPKAmHAjIr95tzaOU5f3f1GWnNIDY8Kjfvzrl97LoGsGp1lJzovLDQ/gQTVG nuz2mQSUilD9FvDuoOtWEyQ2NmJS5URs/F3HfR9VGL1dVCOSrmn9VJsjddC5FcbfZN1vhwfV4kp fl/wxCw7sHVEX/BM+sIgGL2EaGsqjoH7QSB4+QeRIhwHgC2mFfLB6P/K2r0TfMnOq1SjbhiMoQT WNvC/XH9E/zixIuKWPWHQJecjYkdq2K+Rrg9qmlxBC2PB1U1c1fn/JpyD+oz1l5XD8+LM= X-Google-Smtp-Source: AGHT+IEBsZK4czuOzq1ubBK5Kfa39erknNowrvyEPdkj74mAjIaCEACEykbwuweQOPhjiMD1KmkRsg== X-Received: by 2002:a05:600c:c8c:b0:471:d2f:7987 with SMTP id 5b1f17b1804b1-47904b23c04mr275801315e9.26.1764683152429; Tue, 02 Dec 2025 05:45:52 -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-47926f0ec69sm19383375e9.1.2025.12.02.05.45.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Dec 2025 05:45:51 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Kieran Bingham Subject: [PATCH v6 01/24] libcamera: software_isp: gbm: Add a GBM helper class for GPU surface access Date: Tue, 2 Dec 2025 13:45:21 +0000 Message-ID: <20251202134544.662446-2-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251202134544.662446-1-bryan.odonoghue@linaro.org> References: <20251202134544.662446-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,