From patchwork Wed Dec 10 00:31:19 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: 25398 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 7254ABD1F1 for ; Wed, 10 Dec 2025 00:32:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2C6FD61422; Wed, 10 Dec 2025 01:32:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="P6TkjOng"; dkim-atps=neutral Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C824C61420 for ; Wed, 10 Dec 2025 01:32:01 +0100 (CET) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-bfb84c2fe5eso151207a12.1 for ; Tue, 09 Dec 2025 16:32:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765326720; x=1765931520; 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=tzLWYj/4uneBvx5zEyrPndszFCBrsmGlpqApy0qMaaw=; b=P6TkjOngt0SWGlwnBgViSpGhYxuUkmAmITAo0nZq3MTCL4i6jjVyWfOBhZkvwLZ7Ll 6d3XTr46K+HrwEtZktjgSnggUOuworFI6LySb1sp0fV2GPd6GF1zE03LygMWmxnmYwxf 3FLA1CmN1EV6yP1kdaWiQr2ZxJLVhQWtPp009bpJosbrQQLs2mwKv4SWn5iPuviK+5Db aohqe8AE5XDqFsukxky41tDffWaRiglrHVyGHYBxvW5fQQZhcCZJRoVG9o7jUewBeRbA 3SjnuP1s3dXB4tCNQrZ+dbPnelOHldVwyCt9rxEJTRyZyi52c2aGm5ScBDHmBKw+zhDJ 6a8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765326720; x=1765931520; 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=tzLWYj/4uneBvx5zEyrPndszFCBrsmGlpqApy0qMaaw=; b=NRpM0I+aK8lUhtrZlLQD50rJP+RFg2/IaDhBAA1LF5sc+RYimXIE7XM1NTcAuzITa6 SBArf4nzOUBwMMziJsGkDPoTdFZGVj9XmeAGTfik8Y6it7w/n5aj9Yksuib68sei/Z9G H3SzMNmHtPGJovuuDJAa6+y4OdCKTHXrDrxkc8uzPvP1uMEIIN7NrNnut/NG5dZsrwIS oqrMOy7fyBF0CrrzA8AWOVm67YswOZnES5nZOc1YFDMBQLICevhpF5KpRtzxH8+uds1e yacr0aWM19gijDccMEt6CFQlT7TGRenjW73awHMuZ2wmUMMC5/24nJaV9H42xAZ71fjz e2HA== X-Gm-Message-State: AOJu0Yw7BKADJkkUmjbvLkRK8OFSUBnFbtlTQhKE2P6j0SnA/Iia1pzn HctcXxoQ64ahVeEaFBOIdJMH5ZnVpzTZxEKqMh0BvtbW+13z0okLvGoRkpWuzf8SRyIFJg+c0Uc cTa8f X-Gm-Gg: AY/fxX5jwPeiP48jzsy+oRDvHry7+j38FJNp2SB9yzSdHh6NWOb2hsqe/9wwKZ7JP9A LZvgA2QGDAN8DYrV9/2hxnOKPJAcDGn32POOJPwEWCa8u+Wjpi/UeTs9/x6fxCY8a9zdPnu85QW 3S5uEzu5+8viXyKX/flm6ZNjIP4AZAjs/zmNBkX14QzDpeHtydxEjisPajrZJn6Rrxw4XOGNBtj k+Cuzu5OZUNZ+kQFgvOEEbyXQourPpwPibHeerIdGHZAR6n1NXxgjpG593Fb/buUbzZtKa7jW7q NG0zDdA5lf570polkgbgHthbjGoWOjhiUo72EZ28rSD7VfR1hcYR5DUqYbFGwlQ4BYZu1BCLGB4 gQfHYCvbr5nGnJ8QEY6+Jwa1uf7BW2QrkH9jqg9GdeUcTtmCXZlUUhSMye2S1fvmVw9FZbkzknj aOmNcX8Q6oSjr81IohA56b0g8H6Ex0LhuAEjbQ9GjDg27dH5+M9ZjGOEMa1Wianq2u X-Google-Smtp-Source: AGHT+IHRWEobcGDc/UcJdAC4T7BSAjc56jau7ocAjiT/9SrRaogXhAfSQbvfGIYXfcTw1oZbZPVhpg== X-Received: by 2002:a17:90b:17d0:b0:32e:2fa7:fe6b with SMTP id 98e67ed59e1d1-34a728ea521mr529512a91.14.1765326720030; Tue, 09 Dec 2025 16:32:00 -0800 (PST) Received: from inspiron14p-linux (p96936b06.osaknt01.ap.so-net.ne.jp. [150.147.107.6]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34a70427ea6sm566580a91.3.2025.12.09.16.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Dec 2025 16:31:59 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Kieran Bingham , Milan Zamazal Subject: [PATCH v4 02/20] utils: gen-shader-headers: Add a utility to generate headers from shaders Date: Wed, 10 Dec 2025 00:31:19 +0000 Message-ID: <20251210003139.43606-3-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251210003139.43606-1-bryan.odonoghue@linaro.org> References: <20251210003139.43606-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 Reviewed-by: Milan Zamazal 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