From patchwork Wed Jun 11 01:32:27 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: 23523 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 458F9C332B for ; Wed, 11 Jun 2025 01:33:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3AD3068DE9; Wed, 11 Jun 2025 03:33:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="kL9YGQPY"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B898868DDE for ; Wed, 11 Jun 2025 03:33:48 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-442e9c00bf4so50646485e9.3 for ; Tue, 10 Jun 2025 18:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1749605628; x=1750210428; 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=Bu8bAsFBaqMQEQkx5cdIdQP+OHMD0PNQhcyagmWH6gY=; b=kL9YGQPYYWoYWQSY4vCW9PxNdikT8cZP6Lkz1+8R+ItQbymxoSXw1f8C27Sxl1PyL3 eSYjKT08OAGg1e5U3AInF6ErL31AE0OSAm427HppqQE7OZtJyvK04aCr3DSBlLkoTFtf ptCUf+fdy78/suTWN6JFgThgEbtWz1eHLG7M2adON5Rv1UtfsWbUIQFK/X+B0VCYhCnc A1G780KWrBzUQsw3hKvVHZp9xDJXlPTzbFjOFKcY2cBxLkcHolRqHjOY2/fPyVsv5NPZ D+g7A76mji7dXqv0JL4feRXTyh9nfjkwWhgWVRQeC/Tf+gfhgkx79F6xQqdTcaI+eS3W bnLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749605628; x=1750210428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bu8bAsFBaqMQEQkx5cdIdQP+OHMD0PNQhcyagmWH6gY=; b=eZZg0rTrr9XZPkKqlvTd4BRquDvAC86LatSDq0tWVb8O/c6Gtye8i1fjXS0xXaona6 as11YxZrYPf3ZpRBvojj4HRZfOcwyUYa38JFj3RlbrMUo/qlK2oO9WyRDZPQwMijEW+i KnlFhZ8CHawyDojB4PRWVmSBJv04+h0on2wkvJzhzz8v7ZkdSfPnR5kKBwwl8uo6QVD7 xxx4QiRpe9hXqWXSnHYKywLaqZBDO0DuktVNVtlmENvqvao51TMngz6YPnnm3kNIOXqk rPZnQQHN55T5kosIv1VDT1BWdAhkKdcCMMPQbMqFNYWYHBx6898TGwG4mhI9QO1pAqbT maRQ== X-Gm-Message-State: AOJu0Yx7poepn8yT5nUiemScE7vvl81OV/VNU7Idlte0Fz8iOnk23aEq FQhbdSTIL1JOisNE7h6hEnres1s2Gu0Q0KxsCutu0NdNheeCOmKl+KKIELVsPWK5GsowOT3fhEO +tDq0aIs= X-Gm-Gg: ASbGncvlRBXsnfshwRcE/eMiHXerd0OoNpYEbnMGeAdRzJcfMaecC4OHogE4FO50h9I a9QVTxbEu5fEy0QQbE692+0qFJ0kTiSvZmy4tjD/m6CYK/WFKKk21EmEa95lGNMMegM5F83c9k7 yF0MK6q3Y+CVPs+p2XlSkM0xlf4a123LeNY7GYtn7zAIxWIY90hNcqjRIKrlIba/v6T5ERRlQyp 2JsQyD4Z6gHVnc7nP8UF5Q5QtfOdEMSXFQ3OhwdS8aXvxnzlj5ONmwEx+2rF43En0KPD0so6nqt h/CVc+iT70HiMytThrah3nSxwuL5IzrYvO95uqpwrBuwX3kvnImFf9Y3s69sbruJIMv964gSbWf 8VEMn2H2/HmsyaOu62+JUz4nni8cHdKJiAjaoeU2ahQ== X-Google-Smtp-Source: AGHT+IFimr21puVb8EtyrS/3T/KgKyIGY6mdse51NaZlDl4KrAuCpEUEBSONu/zpV6ioIKdUvGiSnQ== X-Received: by 2002:a05:600c:3f0e:b0:43d:9d5:474d with SMTP id 5b1f17b1804b1-45324d04de8mr8549755e9.0.1749605628104; Tue, 10 Jun 2025 18:33:48 -0700 (PDT) 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-4532514138asm5680625e9.3.2025.06.10.18.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 18:33:47 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: Bryan O'Donoghue Subject: [PATCH 17/35] utils: gen-shader-headers: Add a utility to generate headers from shaders Date: Wed, 11 Jun 2025 02:32:27 +0100 Message-ID: <20250611013245.133785-18-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611013245.133785-1-bryan.odonoghue@linaro.org> References: <20250611013245.133785-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. Signed-off-by: Bryan O'Donoghue --- utils/gen-shader-header.py | 38 ++++++++++++++++++++++++++++++++ utils/gen-shader-headers.sh | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 82 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 00000000..6668e648 --- /dev/null +++ b/utils/gen-shader-header.py @@ -0,0 +1,38 @@ +#!/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 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 + if j == 16: + print() + j = 0 + 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 00000000..ca4f19f0 --- /dev/null +++ b/utils/gen-shader-headers.sh @@ -0,0 +1,44 @@ +#!/bin/sh +set -x + +if [ $# -lt 4 ]; then + echo "Invalid arg count must be >= 5" + exit 1 +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! */ +/* + * Copyright (C) 2025, Linaro Ltd. + * + */ + +#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 + echo "file is $file" + name=$(basename "$build_dir/$file" | tr '.' '_') + 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