From patchwork Thu Nov 20 23:33:25 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: 25125 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 9F459BD80A for ; Thu, 20 Nov 2025 23:33:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6BC4960A86; Fri, 21 Nov 2025 00:33:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="A7Ws+7lz"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A71EF606A0 for ; Fri, 21 Nov 2025 00:33:55 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4775e891b5eso6648935e9.2 for ; Thu, 20 Nov 2025 15:33:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1763681635; x=1764286435; 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=iucmzPJRyyFFPoxeUBz8sxRzHoEk6MZ17eyAcHe13fo=; b=A7Ws+7lz6a/vOyISpy2QZv2HJ49Rb/l5csw4/9lnmnjYXJA2ncWhmyeq8kpgjlOZqD Jw0jn4970bjZC83OyEIczHpvYnQxUlUI28ZvWIFLe06pR2pByLjq2Qx6hJTtqeDtUprH KatteMbdSDgrfuI/4dCsXcWqTxgJeGLnlebI4cslx55QaNPcPNzoyjRG2mxt5VJDpLMu eqtBo7+C0yZiGMDlUbKE0Z82Vf8RGW+9ujtuySf3oU9eSobt5MyYX3ESbHteCzEmLc+d Jhw5sxHk7BHtouh1imgVqX1Eic8Z2cizMcvzGphm+8s2PM3Vn5CFA5zg0mbamfYKMOBc 16lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763681635; x=1764286435; 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=iucmzPJRyyFFPoxeUBz8sxRzHoEk6MZ17eyAcHe13fo=; b=sVi/YO/Rjog60Fi89OGuo666eNgYfDQRy2WGGdi6o7lWlW8iTwWHJgANIIJTF2T01t 41GO4zzYKmDIkGrZkl9T/n7S3koCRLkKhIYaSphVoe0P/Pg3EJOT5X5pYYsxP0TzsTLT S2XWJ6e7kSSolLrtKu8aiM5iHchVHNzgbwxtL2exH8uLaNw3oHDAOOVe7vW20vwcjlnS P3+y0ICjRSbtTs7H+wRBS6o3ILlkU/ZeC5CcxXWil0ezcZUPzDZcx1IgsNuc9Ygz7Elh Gdhb2S2yYgQ4xfNkMOB+jyvGON/VLUb48CIoE6lVO0jATMB7RAXps8hIYbDVqejNOV26 ysgQ== X-Gm-Message-State: AOJu0YyJ7VW8CeM8hAefeC1lLNd58s4HSdpiV7YqmRSRjeatuOPBccFa JyXlHsvbuHMhl7dTUNllJ9LFljawpxZn/KbULsakieToxxkBVsvbc+xNhQyt+MoCp7cnlz78Vs6 Uva5SgNY= X-Gm-Gg: ASbGnct1wy1Vl5/9pbzzwYcut2cb/e5FMdHg7uA6UVWjpCpE/AF+6go62CSB72749DV Ep5xkANczYu9j+tKG9X8Ezl4FZNe1HCBS9jWRuOdr4d3xs8yqIOvTdqnApvWxeRjuaOjN5D+IIx hwCcDDxXqVKrSbBLmyconUJD9jEqds7vsuv1Q/6F3JCL0AC+k680D/+JQ9PWtJhw6AiHF9Cjl37 kPSz4XjS6dCnLED57knr1WXCWOkonoiq2sZf+LejluGJlvYPU6hCbhNnSWuUuqhV9l8zeYSeRsi ZZLH1+ZxUkyf57F18m0ewoPanVyJRT2Q2FpUpiTdvLY+cS1+wn1hCQBSa3y3tWf/hIu8/JW8uBk uuqlP3q80QxckvNiekk9geQ1fJGQxASbGCOLAyBXJXeDgsPA/dAfTYthcT5T+qbtWFFNZ3Fx13a eF6ymLNaMqfehR1JOn+O7T/9wY4HcEXrlI3kTVbAVX1GXeaz2s5hqxgrZs3UNl4cQqD41QPWv0K PIOBQ== X-Google-Smtp-Source: AGHT+IGTjWV6hXGyzKVwyiIRM0X5EfxOZv+NuPQ3cTbMfZ65g9VNhW1w13Q1e0v6kRfyIBNVm93GGA== X-Received: by 2002:a05:600c:4e87:b0:46d:a04:50c6 with SMTP id 5b1f17b1804b1-477c01ebc76mr3292465e9.30.1763681635017; Thu, 20 Nov 2025 15:33:55 -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-42cb7fa3a81sm7984139f8f.26.2025.11.20.15.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Nov 2025 15:33:53 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Kieran Bingham Subject: [PATCH v4 01/23] libcamera: software_isp: gbm: Add a GBM helper class for GPU surface access Date: Thu, 20 Nov 2025 23:33:25 +0000 Message-ID: <20251120233347.5046-2-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251120233347.5046-1-bryan.odonoghue@linaro.org> References: <20251120233347.5046-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 | 84 ++++++++++++++++++++++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/gbm.cpp | 61 +++++++++++++++++++ src/libcamera/meson.build | 11 ++++ 4 files changed, 157 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..8a908ddc8 --- /dev/null +++ b/include/libcamera/internal/gbm.h @@ -0,0 +1,84 @@ +/* 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) + +/** + * \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. + */ +class GBM +{ +public: + /** + *\brief GBM constructor. + * + * Creates a GBM instance with unitialised state. + */ + GBM(); + + /** + *\brief GBM destructor + * + * Cleans up the GBM device if it was successfully created, and closes + * the associated file descriptor. + */ + ~GBM(); + + /** + * \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 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 *getDevice() { return gbm_device_; } + + /** + * \brief Retrieve the pixel format + * + * \return The PixelFormat used by this GBM instance (ARGB8888) + */ + PixelFormat getPixelFormat() { return format_; } + +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 ecb7c9fa8..01a365955 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -24,6 +24,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..fa15b709a --- /dev/null +++ b/src/libcamera/gbm.cpp @@ -0,0 +1,61 @@ +/* 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) + +GBM::GBM() +{ + fd_ = 0; + gbm_device_ = NULL; +} + +GBM::~GBM() +{ + if (gbm_device_) + gbm_device_destroy(gbm_device_); +} + +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; +} +} //namespace libcamera diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 5b9b86f21..fe60c8752 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -69,6 +69,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') @@ -176,6 +186,7 @@ libcamera_deps += [ libcamera_base_private, libcrypto, libdl, + libgbm, liblttng, libudev, libyaml,