From patchwork Thu Nov 27 02:22:34 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: 25216 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 0307FC3260 for ; Thu, 27 Nov 2025 02:23:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B3CE860AA3; Thu, 27 Nov 2025 03:23:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="o6w3dVk8"; dkim-atps=neutral Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A14DB609E0 for ; Thu, 27 Nov 2025 03:23:08 +0100 (CET) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-477bf34f5f5so1993785e9.0 for ; Wed, 26 Nov 2025 18:23:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764210188; x=1764814988; 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=uyC98X/XHaAyWYIaQyyLtwB29WLvfE+rI98R7oKQJ7g=; b=o6w3dVk8Y5COPUFcCDWixtS3NUOoJwZQMaRB6MDN42Iky0ZUejdQbR6O3pscJ0yHOm 6fUltxiCX8wEJ7LFH8XBdIfo/IJTYp6D4hhiPhQyAGU+b2UqaJ7oy5VQLJAcJrh5XF2E i/gun8bbXJ1ajC388x5dk6Q5+BZJuT5oqOTi6V/GOvQs+PtgZxWeXy3PdPQhA6kj4uQ+ 6hJ+DktL+5L7Ljk3Nb/jKD7HE/DwI/llKnr/QHDXmAUlbZ8Bwl/odkSUz9xWjZttVF13 0k76uZEOPdXjww4jQg1toZqvMZS7UM7rxWcTNeVVBJgtNvrst0bhPl5HjePTSmCZLQZE 5Scw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764210188; x=1764814988; 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=uyC98X/XHaAyWYIaQyyLtwB29WLvfE+rI98R7oKQJ7g=; b=IkCJp3jC2swBwDtpqqYq6iKoWbO55V71uSIxHGKkV4XmD1xpkfKQCBfz8Yi6AqK0UT icUm0qwxELhR2oDQgr1yl/XFJH3hS/XpJr4i9i+rH/7bmDqhqipAZkNVqUroSowjaBtg 2WJgwCqTvIG143Oe/IXScLMpxoy+c5S2Tp1nfUqUa0sYbwJvOR14kJNMy0YGFRsn+s0P 5lwCyJ/aDYqmdoLHwuUMpvdrqzqLDqMdSt1njHRvwspOKibkjDS1fFQvGnLnP6krL3mL DyEfNawgzajjd2Em3omw47NsT63+aCxC/WK2v3Im2CppXYBgdSXwCvoqB747uBJtT3VV RsxQ== X-Gm-Message-State: AOJu0YxErqBMUCw7CxmvAKpPcHF3FQuvBAWchD9A96ecpt3KJq/yTU/j si6lGNieT+T+L7Xpej6Ymp63qEBBkn5HSw2BsQmXPfgT1slmbz/CMKWWW/QOVHceUQlbmsgncee dQEPj5HQ= X-Gm-Gg: ASbGncv3ZPT0c3Bqb9xwmlGsyP5L+IDh/dbXAX0f02cMQ3pAmPv/VNs1QxcgueWrqaH hRGmDPH4xxSvBQ7NMEuxD3J4eNuV/FHjmqWLSm+hEglFW1vHFpkZwpnIMdMYMOVmdjuvdtyFbT8 HImNQuoLgQJrAs5k82BbVLXEwn4DlwLJxjryleTn2sdugzs7MSPU8zFQXau1akSKYLReSf5wMJv wJP0/hz/Cpupa8RXWZLy2C2Ju6W8zPzjD2Wdy1jrHTXcjG4faP6a+77DOS6aix4oWHTsTcAJ7QG xxqNhqcp/z+S5NApvNNkDZvwVyJOvheV68NWrXRSH6W2ubpvRYBvb0ZqkrUnhKgCG0VgEWYYVj7 wkbBoCu4Bq2ZeKZd2821G45W3peULC7EHz+bVh1xr+PH5dBbMQL8UwVqINGiGWiR1ExlhQoYWoJ MI+UhdrgONyKT5EQ7qcXBRoht/p41xV0zWejAYmgiWFeNHklLtG3PHWMFrZ37v4zLQCzE= X-Google-Smtp-Source: AGHT+IHTGtwXx09/kvhaqmu1L22ZFwtFr3LbaGgboPRLcTfUTs0flmY04A2zwG3fTs5u30TFeUlFDg== X-Received: by 2002:a05:600c:354c:b0:477:a977:b8c2 with SMTP id 5b1f17b1804b1-47904ae7322mr87633155e9.13.1764210188037; Wed, 26 Nov 2025 18:23:08 -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-4790b0e21e8sm71549495e9.15.2025.11.26.18.23.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 18:23:07 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Kieran Bingham Subject: [PATCH v2 02/22] utils: gen-shader-headers: Add a utility to generate headers from shaders Date: Thu, 27 Nov 2025 02:22:34 +0000 Message-ID: <20251127022256.178929-3-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251127022256.178929-1-bryan.odonoghue@linaro.org> References: <20251127022256.178929-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" Two simple script to generate a header that contains GLSL shaders translated to C arrays. Acked-by: Kieran Bingham Signed-off-by: Bryan O'Donoghue --- utils/gen-shader-header.py | 37 +++++++++++++++++++++++++ utils/gen-shader-headers.sh | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100755 utils/gen-shader-header.py create mode 100755 utils/gen-shader-headers.sh diff --git a/utils/gen-shader-header.py b/utils/gen-shader-header.py new file mode 100755 index 000000000..731a63b41 --- /dev/null +++ b/utils/gen-shader-header.py @@ -0,0 +1,37 @@ +#!/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]) as file: + data = file.read() + data_len = len(data) + + name = sys.argv[1].replace(".", "_") + name_len = name + "_len" + + j = 0 + print("unsigned char", name, "[] = {") + for ch in data: + print(f"0x{ord(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.sh b/utils/gen-shader-headers.sh new file mode 100755 index 000000000..81bf1584c --- /dev/null +++ b/utils/gen-shader-headers.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +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 " build_dir Directory where shader files are located and header will be written" + echo " output_header_name Name of the generated header file (relative to build_dir)" + 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_dir="$1"; shift +build_path=$build_dir/"$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 "$build_dir/$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 "$build_dir/$file") + "$src_dir/utils/gen-shader-header.py" "$name" "$build_dir/$file" >> "$build_path" + echo >> "$build_path" +done