From patchwork Tue Jun 30 08:30:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 27136 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 5489BC3264 for ; Tue, 30 Jun 2026 08:30:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0DA7165F44; Tue, 30 Jun 2026 10:30:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TkPNS0ad"; 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 E61B465F3D for ; Tue, 30 Jun 2026 10:30:34 +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 E86ECD52; Tue, 30 Jun 2026 10:29:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1782808191; bh=DrcjWOg6Ivq0gSPYlbd8/w+kFElaFQqO7rfUPeoQ+bc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TkPNS0adtELyDXRAQzOpIZHnk6PTOc/lSX9VCWv16EeEJARqTjSdOByRVeAPdKt8v wcb6BjTqkgSbzBFFJ5Cf1F4ldh2BXCTzYIVM7IBOc+nXB6VLZ5DEKWgnYv4SnxZMZW KXHUSHnkeL0npt8O4ZPTFyS6sRjMn4J+cnvFMF1k= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Bryan O'Donoghue Subject: [PATCH 1/4] libcamera: shaders: Move header generation to shaders directory Date: Tue, 30 Jun 2026 11:30:28 +0300 Message-ID: <20260630083031.3197714-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260630083031.3197714-1-laurent.pinchart@ideasonboard.com> References: <20260630083031.3197714-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 src/libcamera/shaders/ directory contains all libcamera shaders for the software ISP. Move the related build logic to convert shaders to headers to the same directory to make shaders self-contained. This changes the location of the glsl_shaders.h header, update debayer_egl.cpp accordingly. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal Reviewed-by: Barnabás Pőcze --- src/libcamera/meson.build | 10 ---------- src/libcamera/shaders/meson.build | 10 ++++++++++ src/libcamera/software_isp/debayer_egl.cpp | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 6aedacbdb04d..17c1b2cb3479 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -184,16 +184,6 @@ libcamera_deps += [ libyaml, ] -# Generate headers from shaders -libcamera_shader_headers = custom_target( - 'gen-shader-headers', - input : [shader_files], - output : 'glsl_shaders.h', - command : [gen_shader_headers, meson.project_source_root(), '@OUTPUT@', '@INPUT@'], -) - -libcamera_internal_headers += libcamera_shader_headers - # We add '/' to the build_rpath as a 'safe' path to act as a boolean flag. # The build_rpath is stripped at install time by meson, so we determine at # runtime if the library is running from an installed location by checking diff --git a/src/libcamera/shaders/meson.build b/src/libcamera/shaders/meson.build index dd441a577670..adac77327a3b 100644 --- a/src/libcamera/shaders/meson.build +++ b/src/libcamera/shaders/meson.build @@ -8,3 +8,13 @@ shader_files = files([ 'bayer_unpacked.vert', 'identity.vert', ]) + +# Generate headers from shaders +libcamera_shader_headers = custom_target( + 'gen-shader-headers', + input : [shader_files], + output : 'glsl_shaders.h', + command : [gen_shader_headers, meson.project_source_root(), '@OUTPUT@', '@INPUT@'], +) + +libcamera_internal_headers += libcamera_shader_headers diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 0ec2a98cfafb..af9b9d426920 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -24,7 +24,7 @@ #include "libcamera/internal/formats.h" #include "libcamera/internal/framebuffer.h" -#include "../glsl_shaders.h" +#include "../shaders/glsl_shaders.h" namespace libcamera { From patchwork Tue Jun 30 08:30:29 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 27137 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 CEB82C3264 for ; Tue, 30 Jun 2026 08:30:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 98A3765F4E; Tue, 30 Jun 2026 10:30:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="q/y/wdyW"; 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 03ECC65F3F for ; Tue, 30 Jun 2026 10:30:36 +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 322E8D52; Tue, 30 Jun 2026 10:29:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1782808192; bh=aW5t+7LnOeEWb2hlVGf4cRvYqMTO1Vef42mzNX33KgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q/y/wdyWRxnRUh3kNwU1GW6HcW16cpwamI5a584AG2t/R0E3s7ax7xQqZIXGQe/Fo fyLBLWwon7UOHLqYHKCp0yjrFSp0MVsEh/x2VRZyepHofoutra4DO94J+Ota03dgLf abFYYUlqWCGlO6wfelmPPVsVLM6bG1uBsiJdoJvM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Bryan O'Donoghue Subject: [PATCH 2/4] utils: Merge shader header generation scripts Date: Tue, 30 Jun 2026 11:30:29 +0300 Message-ID: <20260630083031.3197714-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260630083031.3197714-1-laurent.pinchart@ideasonboard.com> References: <20260630083031.3197714-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 shader header is generated by a combination of a shell script and a Python script. Simplify this by merging everything into a single script. The output of the old and new script only differ in white spaces. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal Reviewed-by: Barnabás Pőcze Reviewed-by: Bryan O'Donoghue --- src/libcamera/shaders/meson.build | 2 +- utils/gen-shader-header.py | 37 ---------------- utils/gen-shader-headers.py | 71 +++++++++++++++++++++++++++++++ utils/gen-shader-headers.sh | 54 ----------------------- utils/meson.build | 2 +- 5 files changed, 73 insertions(+), 93 deletions(-) delete mode 100755 utils/gen-shader-header.py create mode 100755 utils/gen-shader-headers.py delete mode 100755 utils/gen-shader-headers.sh diff --git a/src/libcamera/shaders/meson.build b/src/libcamera/shaders/meson.build index adac77327a3b..4f4e8da607c7 100644 --- a/src/libcamera/shaders/meson.build +++ b/src/libcamera/shaders/meson.build @@ -14,7 +14,7 @@ libcamera_shader_headers = custom_target( 'gen-shader-headers', input : [shader_files], output : 'glsl_shaders.h', - command : [gen_shader_headers, meson.project_source_root(), '@OUTPUT@', '@INPUT@'], + command : [gen_shader_headers, '-o', '@OUTPUT@', '@INPUT@'], ) libcamera_internal_headers += libcamera_shader_headers diff --git a/utils/gen-shader-header.py b/utils/gen-shader-header.py deleted file mode 100755 index 745852b4c03f..000000000000 --- a/utils/gen-shader-header.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2025, Bryan O'Donoghue. -# -# Author: Bryan O'Donoghue -# -# A Python script which takes a list of shader files and converts each of them -# into a C header. -# -import sys - -try: - with open(sys.argv[2], "rb") as file: - data = file.read() - data_len = len(data) - - name = sys.argv[1].replace(".", "_") - name_len = name + "_len" - - j = 0 - print("unsigned char const", name, "[] = {") - for ch in data: - print(f"0x{ch:02x}, ", end="") - j = (j + 1) % 16 - if j == 0: - print() - if j != 0: - print() - print("};") - - print() - print(f"const unsigned int {name_len}={data_len};") - -except FileNotFoundError: - print(f"File {sys.argv[2]} not found", file=sys.stderr) -except IOError: - print(f"Unable to read {sys.argv[2]}", file=sys.stderr) diff --git a/utils/gen-shader-headers.py b/utils/gen-shader-headers.py new file mode 100755 index 000000000000..908217a2bd2e --- /dev/null +++ b/utils/gen-shader-headers.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (C) 2025, Bryan O'Donoghue +# Copyright (C) 2026, Ideas on Board Oy +# +# Generate a C header file containing hex-encoded shader sources + +import argparse +import binascii +import math +import os +import sys + + +def process_file(name, out): + data = open(name, 'rb').read() + + hex_data = [f'0x{c:02x}' for c in data] + var_name = os.path.basename(name).replace('.', '_') + + out.write(f'unsigned char const {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') + + +def main(argv): + parser = argparse.ArgumentParser( + description='Generate a C header file containing hex-encoded shader sources') + parser.add_argument('--output', '-o', metavar='file', default=sys.stdout, + type=argparse.FileType('w', encoding='utf-8'), + help='Output file name. Defaults to standard output if not specified.') + parser.add_argument('input', nargs='+', type=str, + help='Input file names.') + args = parser.parse_args(argv[1:]) + + args.output.write('''/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* This file is auto-generated, do not edit! */ + +#pragma once + +/* + * List the names of the shaders at the top of header for readability's sake. + * +''') + + for name in args.input: + name = os.path.basename(name).replace('.', '_') + args.output.write(f' * unsigned char {name};\n') + + args.output.write(''' */ + +/* Hex encoded shader data */ +''') + + for name in args.input: + process_file(name, args.output) + args.output.write('\n') + + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + diff --git a/utils/gen-shader-headers.sh b/utils/gen-shader-headers.sh deleted file mode 100755 index 0d6649521a7a..000000000000 --- a/utils/gen-shader-headers.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-or-later - -set -e - -usage() { - echo "Usage: $0 [shader_file2 ...]" - echo - echo "Generates a C header file containing hex-encoded shader data." - echo - echo "Arguments:" - echo " src_dir Path to the base of the source directory" - echo " output_header Path to the generated header file" - echo " shader_file(s) One or more shader files to embed in the header" - exit 1 -} - -if [ $# -lt 4 ]; then - echo "Error: Invalid argument count." - usage -fi - -src_dir="$1"; shift -build_path="$1"; shift - -cat < "$build_path" -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* This file is auto-generated, do not edit! */ - -#pragma once - -EOF - -cat <> "$build_path" -/* - * List the names of the shaders at the top of - * header for readability's sake - * -EOF - -for file in "$@"; do - name=$(basename "$file" | tr '.' '_') - echo "[SHADER-GEN] $name" - echo " * unsigned char $name;" >> "$build_path" -done - -echo "*/" >> "$build_path" - -echo "/* Hex encoded shader data */" >> "$build_path" -for file in "$@"; do - name=$(basename "$file") - "$src_dir/utils/gen-shader-header.py" "$name" "$file" >> "$build_path" - echo >> "$build_path" -done diff --git a/utils/meson.build b/utils/meson.build index 9c598793035c..17a7aa7c3f5e 100644 --- a/utils/meson.build +++ b/utils/meson.build @@ -3,7 +3,7 @@ subdir('codegen') subdir('ipu3') -gen_shader_headers = files('gen-shader-headers.sh') +gen_shader_headers = files('gen-shader-headers.py') ## Module signing gen_ipa_priv_key = files('gen-ipa-priv-key.sh') From patchwork Tue Jun 30 08:30:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 27138 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 EC356C3264 for ; Tue, 30 Jun 2026 08:30:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AEDC365F56; Tue, 30 Jun 2026 10:30:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MfuEbhYp"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4788E65F3B for ; Tue, 30 Jun 2026 10:30:37 +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 8D81A196B; Tue, 30 Jun 2026 10:29:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1782808193; bh=OS0/dkfyW5Es0t2EzfGWOYOw0j9Ibmke5xITPN4ORRY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MfuEbhYpvWFrngrYTPLo84ifGElZEsOemYUYoNxLC77VfcDBLPg57GRdBK1l2TN1T +7My0va+GfDfz2LYrLi0MyES9SYGrGT+qIkgWKqowkZr15pwPTEx4jixZBOi6AaVvP w50X03pSJhB6IYRJgGgafjx8JR6co26CJTgUio34= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Bryan O'Donoghue Subject: [PATCH 3/4] utils: Rename and move shader header generation script Date: Tue, 30 Jun 2026 11:30:30 +0300 Message-ID: <20260630083031.3197714-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260630083031.3197714-1-laurent.pinchart@ideasonboard.com> References: <20260630083031.3197714-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 gen-shader-headers.py script generates a single header. Rename it to gen-shader-header.py, and move it to the codegen directory with the other code generation scripts. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal Reviewed-by: Barnabás Pőcze Reviewed-by: Bryan O'Donoghue --- src/libcamera/shaders/meson.build | 8 ++++---- .../gen-shader-header.py} | 0 utils/codegen/meson.build | 1 + utils/meson.build | 2 -- 4 files changed, 5 insertions(+), 6 deletions(-) rename utils/{gen-shader-headers.py => codegen/gen-shader-header.py} (100%) diff --git a/src/libcamera/shaders/meson.build b/src/libcamera/shaders/meson.build index 4f4e8da607c7..c409ff9b0b1c 100644 --- a/src/libcamera/shaders/meson.build +++ b/src/libcamera/shaders/meson.build @@ -9,12 +9,12 @@ shader_files = files([ 'identity.vert', ]) -# Generate headers from shaders -libcamera_shader_headers = custom_target( +# Generate header from shaders +libcamera_shader_header = custom_target( 'gen-shader-headers', input : [shader_files], output : 'glsl_shaders.h', - command : [gen_shader_headers, '-o', '@OUTPUT@', '@INPUT@'], + command : [gen_shader_header, '-o', '@OUTPUT@', '@INPUT@'], ) -libcamera_internal_headers += libcamera_shader_headers +libcamera_internal_headers += libcamera_shader_header diff --git a/utils/gen-shader-headers.py b/utils/codegen/gen-shader-header.py similarity index 100% rename from utils/gen-shader-headers.py rename to utils/codegen/gen-shader-header.py diff --git a/utils/codegen/meson.build b/utils/codegen/meson.build index 8d1c690866e1..70c228d68804 100644 --- a/utils/codegen/meson.build +++ b/utils/codegen/meson.build @@ -14,6 +14,7 @@ gen_formats = files('gen-formats.py') gen_gst_controls = files('gen-gst-controls.py') gen_header = files('gen-header.sh') gen_ipa_pub_key = files('gen-ipa-pub-key.py') +gen_shader_header = files('gen-shader-header.py') gen_tracepoints = files('gen-tp-header.py') py_mod_controls = files('controls.py') diff --git a/utils/meson.build b/utils/meson.build index 17a7aa7c3f5e..6e1b885b3688 100644 --- a/utils/meson.build +++ b/utils/meson.build @@ -3,8 +3,6 @@ subdir('codegen') subdir('ipu3') -gen_shader_headers = files('gen-shader-headers.py') - ## Module signing gen_ipa_priv_key = files('gen-ipa-priv-key.sh') From patchwork Tue Jun 30 08:30:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 27139 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 7DC7DC3264 for ; Tue, 30 Jun 2026 08:30:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DBFB065F63; Tue, 30 Jun 2026 10:30:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZlloVHo5"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7EF8365F3B for ; Tue, 30 Jun 2026 10:30:38 +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 BFD41196B; Tue, 30 Jun 2026 10:29:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1782808194; bh=QgDj/lXMODb0LfK1v9l2IgS2HGDMEQN8/y31ew8X/34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZlloVHo5/RtMKbQ19sg7/+Doxt0gE1QmzVKvTehs24JxFjf1n1WwlVT42Jrc4+b4o fOTR9p4ZRFPpB8kg9b/FcHKCBAkUCRCeg+bG0Nk5L7PLEdPgGnKTZJbVZ93Kl3zjMY Fs4MGjSPv/Fq6TzSH2DUZNDjS4TKoUpVcUMpBjUw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Bryan O'Donoghue Subject: [PATCH 4/4] libcamera: shaders: Replace C array with std::array Date: Tue, 30 Jun 2026 11:30:31 +0300 Message-ID: <20260630083031.3197714-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260630083031.3197714-1-laurent.pinchart@ideasonboard.com> References: <20260630083031.3197714-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 --- src/libcamera/software_isp/debayer_egl.cpp | 23 +++++++--------------- utils/codegen/gen-shader-header.py | 7 ++++--- 2 files changed, 11 insertions(+), 19 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 908217a2bd2e..0bcf76653d77 100755 --- a/utils/codegen/gen-shader-header.py +++ b/utils/codegen/gen-shader-header.py @@ -19,15 +19,14 @@ def process_file(name, out): hex_data = [f'0x{c:02x}' for c in data] var_name = os.path.basename(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): @@ -45,6 +44,8 @@ def main(argv): #pragma once +#include + /* * List the names of the shaders at the top of header for readability's sake. *