From patchwork Tue Dec 2 13:31:33 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: 25288 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 22C61C326B for ; Tue, 2 Dec 2025 13:32:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1EBF260C89; Tue, 2 Dec 2025 14:32:07 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="HYLEJE0j"; dkim-atps=neutral Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9CAB560C84 for ; Tue, 2 Dec 2025 14:32:03 +0100 (CET) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-42b38de7940so2702837f8f.3 for ; Tue, 02 Dec 2025 05:32:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764682323; x=1765287123; 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=xiceLMWMoyliOmwPMu7d0tXHUd/qrCD+ZjX032QIGew=; b=HYLEJE0ju+LAk0Nc+eqmJcgliQ7IDazpV+td7sbTQpPoxFqDrVcw4LNRP9qarkaHzp FHUnPu9Ds5s4LoO9tXJ4nQ7jCm04B3zNAnDs/sKH582SjSiynuXxEFa3WINzHvFfCfIf 4/MkKWpi7XnpIxkyCmGu27I1odpgliKa8hCFliCtGxbaKDejfVhCk+qYZLezDCHJJZSO 7a0/FnkmgdYeMPjwXdImRSBKI8ZAyLX2Ba19xTkMIhw1Q3HvHM0zSlfPfP94MIFT+YdG V1rVMdCRem6PwB9IFbkfO5Xu4JeMPssSoZdfNkJ+XBQz/spiLd6Sp0Nfep9b8WGnJKW0 PmIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764682323; x=1765287123; 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=xiceLMWMoyliOmwPMu7d0tXHUd/qrCD+ZjX032QIGew=; b=Mb/aXCFLxhJ5OjJBTfTCl+lzMYroEnWFzO59oJkkI0mM+ocfzN2GbMM+xu4uGm53R9 IUAnjdsFLGyrzQRagt/d6v0d5PRcbqDC6BHO7nvOKpdoRE/1lD7c4+Z9N6qExJY9Nn02 kigKXDVQyI0aF6+PMCJi7El/Xa/M1authkMfE9DMqlmkxG/heqgcL57MJBtWHoNZUJrQ iuStA0Jg0z8b+krwg9JzABvJ5bGUBdcsjcBwg7Fr9WOmhC6/BW2qUVTOT5aG+jmHXOgK eC6vlPKjfDhsE8TsPvVR9WqbOWOQXaVb2/dtqoWMaJUEIDwNnp4+nYJ4j8pTgRiCjuaj 3RAQ== X-Gm-Message-State: AOJu0YzBZt0I7JrvLzQZGMDbT9owcbSKGkAeCKhDzLWTpGo7vKXv3uJx cecTCKBip9e3QywEt6vOafhp3qK9ox+F6d+YI0ptkfsi9LzWmNZo86JioNesqh6UzGPaUgCxoTd ibZ2W X-Gm-Gg: ASbGnct7dTgj5xDCEg0qYyxsV9ohfazrMLx9kjnWpCHwKK4ufteg+tzyIGWnx8YXBBP sSd0kkG6BRTLnuFqrVtxjAbIr+JU9IgtSQ7fSyStcH/Qq3MgFUZw3Hfj/hbAjJsiCg6u6QDIMwh wA96X3W++IqZs/iHksrI7tBepo5BrWecXCzH1ES7YJH2NoHo3MsfMTfOAmrtq8lDcxqH4vuUkA2 rqUGD/uxb0xTaPguWo/w0nPL4mPe4mkSwpmYtDSNESKT019/010Pdr2LhH9SoB5jCRy8S/aMtpb wf8ZRDKhrZDZojIPbjmunVWPsDxVbZM0rjECqRjBwYwQrdxBvTrJGln9jxlwTOUSI60fRTZMAIo 87hZh49U/kjvPB0HwQiv1RJXWknHIV5J4jJPiRgc7h9m+nDTRG1rbOMQnfHZLErOzSrXZuRZv+w B2Aubulkrb7gCYFX5W5xAIu16k0UqLlKEAIalHsqobFJzKmykOWcVSmug6wgVrDfek6z5pKA2P2 Lt6WQ== X-Google-Smtp-Source: AGHT+IHK2o/b45kvptj+8v9oK+ESKitLmfgVY3DKqLtx0vIm+0fvXjNvmbhyq304blf9f0EnC9lz6A== X-Received: by 2002:a05:6000:186b:b0:42b:3dbe:3a53 with SMTP id ffacd0b85a97d-42cc1d0c716mr48166394f8f.40.1764682322600; Tue, 02 Dec 2025 05:32:02 -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-42e1c5c30c4sm33363322f8f.9.2025.12.02.05.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Dec 2025 05:32:02 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Kieran Bingham Subject: [PATCH v3 02/22] utils: gen-shader-headers: Add a utility to generate headers from shaders Date: Tue, 2 Dec 2025 13:31:33 +0000 Message-ID: <20251202133157.661407-3-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251202133157.661407-1-bryan.odonoghue@linaro.org> References: <20251202133157.661407-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..745852b4c --- /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], "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.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