From patchwork Tue Jun 30 12:52:13 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 27146 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 30A90C3261 for ; Tue, 30 Jun 2026 12:52:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2447B65F85; Tue, 30 Jun 2026 14:52:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="a5+hR+c2"; 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 8D4A565F8A for ; Tue, 30 Jun 2026 14:52:20 +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 A99E1104C; Tue, 30 Jun 2026 14:51:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1782823896; bh=3EB43kR/8724N22Ojui+sl9PvDfsTKCtI3RwCjGr5kY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a5+hR+c2Z6n/kW9KQnPExlZnTxcP3XHCNbMnDvP9ASnM39hGWwELXPnufJN54MXdy Uk4ysjMMwmIvEiS1H6urKjK6YaR9rmNY5EYImbAfNffGJA6Qu34nm6YleVjcfpQgBJ e5d+cAbb3P1nBN28O89cIXb97vDvel9EhoHsJGGQ= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Bryan O'Donoghue Subject: [PATCH v2 4/5] libcamera: shaders: Replace C array with std::array Date: Tue, 30 Jun 2026 15:52:13 +0300 Message-ID: <20260630125214.3327516-5-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" Using C arrays and separate length variables is error-prone. Replace them with std::array in the generated shader header, and update the software ISP code accordingly. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal Reviewed-by: Barnabás Pőcze Reviewed-by: Bryan O'Donoghue --- Changes since v1: - Drop "unsigned char" from comment block in generated header --- src/libcamera/software_isp/debayer_egl.cpp | 23 +++++++--------------- utils/codegen/gen-shader-header.py | 9 +++++---- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index af9b9d426920..1f5fc6a4466d 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -145,10 +146,8 @@ int DebayerEGL::getShaderVariableLocations(void) int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat) { std::vector shaderEnv; - unsigned int fragmentShaderDataLen = 0; - const unsigned char *fragmentShaderData = 0; - unsigned int vertexShaderDataLen = 0; - const unsigned char *vertexShaderData = 0; + Span fragmentShaderData; + Span vertexShaderData; GLenum err; /* Target gles 100 glsl requires "#version x" as first directive in shader */ @@ -216,9 +215,7 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm case libcamera::formats::SGRBG8: case libcamera::formats::SRGGB8: fragmentShaderData = bayer_unpacked_frag; - fragmentShaderDataLen = bayer_unpacked_frag_len; vertexShaderData = bayer_unpacked_vert; - vertexShaderDataLen = bayer_unpacked_vert_len; break; case libcamera::formats::SBGGR10_CSI2P: case libcamera::formats::SGBRG10_CSI2P: @@ -227,16 +224,12 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm egl_.pushEnv(shaderEnv, "#define RAW10P"); if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { fragmentShaderData = bayer_unpacked_frag; - fragmentShaderDataLen = bayer_unpacked_frag_len; vertexShaderData = bayer_unpacked_vert; - vertexShaderDataLen = bayer_unpacked_vert_len; glFormat_ = GL_RG; bytesPerPixel_ = 2; } else { fragmentShaderData = bayer_1x_packed_frag; - fragmentShaderDataLen = bayer_1x_packed_frag_len; vertexShaderData = identity_vert; - vertexShaderDataLen = identity_vert_len; shaderStridePixels_ = width_; } break; @@ -247,28 +240,26 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm egl_.pushEnv(shaderEnv, "#define RAW12P"); if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { fragmentShaderData = bayer_unpacked_frag; - fragmentShaderDataLen = bayer_unpacked_frag_len; vertexShaderData = bayer_unpacked_vert; - vertexShaderDataLen = bayer_unpacked_vert_len; glFormat_ = GL_RG; bytesPerPixel_ = 2; } else { fragmentShaderData = bayer_1x_packed_frag; - fragmentShaderDataLen = bayer_1x_packed_frag_len; vertexShaderData = identity_vert; - vertexShaderDataLen = identity_vert_len; shaderStridePixels_ = width_; } break; }; - if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, vertexShaderDataLen, shaderEnv)) { + if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData.data(), + vertexShaderData.size(), shaderEnv)) { LOG(Debayer, Error) << "Compile vertex shader fail"; return -ENODEV; } utils::scope_exit vShaderGuard([&] { glDeleteShader(vertexShaderId_); }); - if (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData, fragmentShaderDataLen, shaderEnv)) { + if (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData.data(), + fragmentShaderData.size(), shaderEnv)) { LOG(Debayer, Error) << "Compile fragment shader fail"; return -ENODEV; } diff --git a/utils/codegen/gen-shader-header.py b/utils/codegen/gen-shader-header.py index fe4f06065f0c..994e19c8e8e0 100755 --- a/utils/codegen/gen-shader-header.py +++ b/utils/codegen/gen-shader-header.py @@ -19,15 +19,14 @@ def process_file(path, out): hex_data = [f'0x{c:02x}' for c in data] var_name = path.name.replace('.', '_') - out.write(f'unsigned char const {var_name}[] = {{\n') + out.write(f'static constexpr std::array {var_name}{{\n') for i in range(math.ceil(len(data) / 16)): out.write('\t') out.write(', '.join(hex_data[16 * i:16 * (i + 1)])) out.write(',\n') - out.write('};\n\n') - out.write(f'const unsigned int {var_name}_len = {len(data)};\n') + out.write('};\n') def main(argv): @@ -46,6 +45,8 @@ def main(argv): #pragma once +#include + /* * List the names of the shaders at the top of header for readability's sake. * @@ -53,7 +54,7 @@ def main(argv): for path in args.inputs: name = path.name.replace('.', '_') - args.output.write(f' * unsigned char {name};\n') + args.output.write(f' * - {name}\n') args.output.write('''\ */