From patchwork Tue Jun 30 12:52:14 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 27147 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 0D9AEC3304 for ; Tue, 30 Jun 2026 12:52:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B51C565F7E; Tue, 30 Jun 2026 14:52:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ps08ho4r"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C9FD165F8E for ; Tue, 30 Jun 2026 14:52:21 +0200 (CEST) Received: from killaraus.ideasonboard.com (2001-14ba-70f3-e800--a06.rev.dnainternet.fi [IPv6:2001:14ba:70f3:e800::a06]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DAB511E8A; Tue, 30 Jun 2026 14:51:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1782823898; bh=KHWjspJyNIFBIEH0UtjGouz5PGW3yeXSbCLYzYAoqN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ps08ho4rr3jmmwK4rIKL29/t7JnPiVteK7E9DQ/Z1xxj3CVblDJm8GrLVUECn87Zr CZLZvtjRNaoTG1D0MF6+rSlTpeVccA6A3aBOzy8aB5g9OJVRDLD/gmLM1s+jv02o+L YZM/lo7v78+QYYSGcPzfoUDCPm37unq0HtYpOcM0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Bryan O'Donoghue Subject: [PATCH v2 5/5] libcamera: egl: Replace pointer and length with span for shader sources Date: Tue, 30 Jun 2026 15:52:14 +0300 Message-ID: <20260630125214.3327516-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260630125214.3327516-1-laurent.pinchart@ideasonboard.com> References: <20260630125214.3327516-1-laurent.pinchart@ideasonboard.com> 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" The compileVertexShader() and compileFragmentShader() functions take a pointer and length to the shader source code as separate arguments. This is an error-prone practice. Replace them with a Span<>. Suggested-by: Barnabás Pőcze Signed-off-by: Laurent Pinchart Reviewed-by: Bryan O'Donoghue Reviewed-by: Barnabás Pőcze --- include/libcamera/internal/egl.h | 9 +++---- src/libcamera/egl.cpp | 29 ++++++++++------------ src/libcamera/software_isp/debayer_egl.cpp | 8 +++--- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index f7bfb28d4e9a..523a62aa89d5 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -112,11 +112,9 @@ public: void pushEnv(std::vector &shaderEnv, const char *str); void makeCurrent(); - int compileVertexShader(GLuint &shaderId, const unsigned char *shaderData, - unsigned int shaderDataLen, + int compileVertexShader(GLuint &shaderId, Span shaderData, Span shaderEnv); - int compileFragmentShader(GLuint &shaderId, const unsigned char *shaderData, - unsigned int shaderDataLen, + int compileFragmentShader(GLuint &shaderId, Span shaderData, Span shaderEnv); int linkProgram(GLuint &programId, GLuint fragmentshaderId, GLuint vertexshaderId); void dumpShaderSource(GLuint shaderId); @@ -135,8 +133,7 @@ private: EGLSurface surface_ = EGL_NO_SURFACE; static EGLDisplay probeDisplay(); - int compileShader(int shaderType, GLuint &shaderId, const unsigned char *shaderData, - unsigned int shaderDataLen, + int compileShader(int shaderType, GLuint &shaderId, Span shaderData, Span shaderEnv); int createDMABufTexture2D(eGLImage &eglImage, int fd, bool output); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index f03abb8ae07d..b5a5dc60b110 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -463,8 +463,7 @@ void eGL::pushEnv(std::vector &shaderEnv, const char *str) /** * \brief Compile a vertex shader * \param[out] shaderId OpenGL shader object ID - * \param[in] shaderData Pointer to shader source code - * \param[in] shaderDataLen Length of shader source in bytes + * \param[in] shaderData Shader source code * \param[in] shaderEnv Span of preprocessor definitions to prepend * * Compiles a vertex shader from source code with optional preprocessor @@ -472,18 +471,17 @@ void eGL::pushEnv(std::vector &shaderEnv, const char *str) * * \return 0 on success, or -EINVAL on compilation failure */ -int eGL::compileVertexShader(GLuint &shaderId, const unsigned char *shaderData, - unsigned int shaderDataLen, +int eGL::compileVertexShader(GLuint &shaderId, + Span shaderData, Span shaderEnv) { - return compileShader(GL_VERTEX_SHADER, shaderId, shaderData, shaderDataLen, shaderEnv); + return compileShader(GL_VERTEX_SHADER, shaderId, shaderData, shaderEnv); } /** * \brief Compile a fragment shader * \param[out] shaderId OpenGL shader object ID - * \param[in] shaderData Pointer to shader source code - * \param[in] shaderDataLen Length of shader source in bytes + * \param[in] shaderData Shader source code * \param[in] shaderEnv Span of preprocessor definitions to prepend * * Compiles a fragment shader from source code with optional preprocessor @@ -491,19 +489,18 @@ int eGL::compileVertexShader(GLuint &shaderId, const unsigned char *shaderData, * * \return 0 on success, or -EINVAL on compilation failure */ -int eGL::compileFragmentShader(GLuint &shaderId, const unsigned char *shaderData, - unsigned int shaderDataLen, +int eGL::compileFragmentShader(GLuint &shaderId, + Span shaderData, Span shaderEnv) { - return compileShader(GL_FRAGMENT_SHADER, shaderId, shaderData, shaderDataLen, shaderEnv); + return compileShader(GL_FRAGMENT_SHADER, shaderId, shaderData, shaderEnv); } /** * \brief Compile a shader of specified type * \param[in] shaderType GL_VERTEX_SHADER or GL_FRAGMENT_SHADER * \param[out] shaderId OpenGL shader object ID - * \param[in] shaderData Pointer to shader source code - * \param[in] shaderDataLen Length of shader source in bytes + * \param[in] shaderData Shader source code * \param[in] shaderEnv Span of preprocessor definitions to prepend * * Internal helper function for shader compilation. Prepends environment @@ -511,8 +508,8 @@ int eGL::compileFragmentShader(GLuint &shaderId, const unsigned char *shaderData * * \return 0 on success, or -EINVAL on compilation failure */ -int eGL::compileShader(int shaderType, GLuint &shaderId, const unsigned char *shaderData, - unsigned int shaderDataLen, +int eGL::compileShader(int shaderType, GLuint &shaderId, + Span shaderData, Span shaderEnv) { GLint success; @@ -531,8 +528,8 @@ int eGL::compileShader(int shaderType, GLuint &shaderId, const unsigned char *sh } // Now the main body of the shader program - shaderSourceData[i] = reinterpret_cast(shaderData); - shaderDataLengths[i] = shaderDataLen; + shaderSourceData[i] = reinterpret_cast(shaderData.data()); + shaderDataLengths[i] = shaderData.size(); // And create the shader shaderId = glCreateShader(shaderType); diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 1f5fc6a4466d..56545816ead5 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -251,15 +251,15 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm break; }; - if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData.data(), - vertexShaderData.size(), shaderEnv)) { + if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, + shaderEnv)) { LOG(Debayer, Error) << "Compile vertex shader fail"; return -ENODEV; } utils::scope_exit vShaderGuard([&] { glDeleteShader(vertexShaderId_); }); - if (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData.data(), - fragmentShaderData.size(), shaderEnv)) { + if (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData, + shaderEnv)) { LOG(Debayer, Error) << "Compile fragment shader fail"; return -ENODEV; }