Patch Detail
Show a patch.
GET /api/1.1/patches/27146/?format=api
{ "id": 27146, "url": "https://patchwork.libcamera.org/api/1.1/patches/27146/?format=api", "web_url": "https://patchwork.libcamera.org/patch/27146/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260630125214.3327516-5-laurent.pinchart@ideasonboard.com>", "date": "2026-06-30T12:52:13", "name": "[v2,4/5] libcamera: shaders: Replace C array with std::array", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "0ac31ce2088fedc4f5543fa755e2e6abc0d18de0", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/27146/mbox/", "series": [ { "id": 6029, "url": "https://patchwork.libcamera.org/api/1.1/series/6029/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6029", "date": "2026-06-30T12:52:09", "name": "libcamera: Improve shader header generation", "version": 2, "mbox": "https://patchwork.libcamera.org/series/6029/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/27146/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/27146/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 30A90C3261\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Jun 2026 12:52:25 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2447B65F85;\n\tTue, 30 Jun 2026 14:52:24 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D4A565F8A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Jun 2026 14:52:20 +0200 (CEST)", "from killaraus.ideasonboard.com\n\t(2001-14ba-70f3-e800--a06.rev.dnainternet.fi\n\t[IPv6:2001:14ba:70f3:e800::a06])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A99E1104C;\n\tTue, 30 Jun 2026 14:51:36 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"a5+hR+c2\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1782823896;\n\tbh=3EB43kR/8724N22Ojui+sl9PvDfsTKCtI3RwCjGr5kY=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=a5+hR+c2Z6n/kW9KQnPExlZnTxcP3XHCNbMnDvP9ASnM39hGWwELXPnufJN54MXdy\n\tUk4ysjMMwmIvEiS1H6urKjK6YaR9rmNY5EYImbAfNffGJA6Qu34nm6YleVjcfpQgBJ\n\te5d+cAbb3P1nBN28O89cIXb97vDvel9EhoHsJGGQ=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Bryan O'Donoghue <bryan.odonoghue@linaro.org>", "Subject": "[PATCH v2 4/5] libcamera: shaders: Replace C array with std::array", "Date": "Tue, 30 Jun 2026 15:52:13 +0300", "Message-ID": "<20260630125214.3327516-5-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.54.0", "In-Reply-To": "<20260630125214.3327516-1-laurent.pinchart@ideasonboard.com>", "References": "<20260630125214.3327516-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Using C arrays and separate length variables is error-prone. Replace\nthem with std::array in the generated shader header, and update the\nsoftware ISP code accordingly.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\nReviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n---\nChanges since v1:\n\n- Drop \"unsigned char\" from comment block in generated header\n---\n src/libcamera/software_isp/debayer_egl.cpp | 23 +++++++---------------\n utils/codegen/gen-shader-header.py | 9 +++++----\n 2 files changed, 12 insertions(+), 20 deletions(-)", "diff": "diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\nindex af9b9d426920..1f5fc6a4466d 100644\n--- a/src/libcamera/software_isp/debayer_egl.cpp\n+++ b/src/libcamera/software_isp/debayer_egl.cpp\n@@ -17,6 +17,7 @@\n #include <tuple>\n #include <vector>\n \n+#include <libcamera/base/span.h>\n #include <libcamera/base/utils.h>\n \n #include <libcamera/formats.h>\n@@ -145,10 +146,8 @@ int DebayerEGL::getShaderVariableLocations(void)\n int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat)\n {\n \tstd::vector<std::string> shaderEnv;\n-\tunsigned int fragmentShaderDataLen = 0;\n-\tconst unsigned char *fragmentShaderData = 0;\n-\tunsigned int vertexShaderDataLen = 0;\n-\tconst unsigned char *vertexShaderData = 0;\n+\tSpan<const unsigned char> fragmentShaderData;\n+\tSpan<const unsigned char> vertexShaderData;\n \tGLenum err;\n \n \t/* Target gles 100 glsl requires \"#version x\" as first directive in shader */\n@@ -216,9 +215,7 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm\n \tcase libcamera::formats::SGRBG8:\n \tcase libcamera::formats::SRGGB8:\n \t\tfragmentShaderData = bayer_unpacked_frag;\n-\t\tfragmentShaderDataLen = bayer_unpacked_frag_len;\n \t\tvertexShaderData = bayer_unpacked_vert;\n-\t\tvertexShaderDataLen = bayer_unpacked_vert_len;\n \t\tbreak;\n \tcase libcamera::formats::SBGGR10_CSI2P:\n \tcase libcamera::formats::SGBRG10_CSI2P:\n@@ -227,16 +224,12 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm\n \t\tegl_.pushEnv(shaderEnv, \"#define RAW10P\");\n \t\tif (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) {\n \t\t\tfragmentShaderData = bayer_unpacked_frag;\n-\t\t\tfragmentShaderDataLen = bayer_unpacked_frag_len;\n \t\t\tvertexShaderData = bayer_unpacked_vert;\n-\t\t\tvertexShaderDataLen = bayer_unpacked_vert_len;\n \t\t\tglFormat_ = GL_RG;\n \t\t\tbytesPerPixel_ = 2;\n \t\t} else {\n \t\t\tfragmentShaderData = bayer_1x_packed_frag;\n-\t\t\tfragmentShaderDataLen = bayer_1x_packed_frag_len;\n \t\t\tvertexShaderData = identity_vert;\n-\t\t\tvertexShaderDataLen = identity_vert_len;\n \t\t\tshaderStridePixels_ = width_;\n \t\t}\n \t\tbreak;\n@@ -247,28 +240,26 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm\n \t\tegl_.pushEnv(shaderEnv, \"#define RAW12P\");\n \t\tif (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) {\n \t\t\tfragmentShaderData = bayer_unpacked_frag;\n-\t\t\tfragmentShaderDataLen = bayer_unpacked_frag_len;\n \t\t\tvertexShaderData = bayer_unpacked_vert;\n-\t\t\tvertexShaderDataLen = bayer_unpacked_vert_len;\n \t\t\tglFormat_ = GL_RG;\n \t\t\tbytesPerPixel_ = 2;\n \t\t} else {\n \t\t\tfragmentShaderData = bayer_1x_packed_frag;\n-\t\t\tfragmentShaderDataLen = bayer_1x_packed_frag_len;\n \t\t\tvertexShaderData = identity_vert;\n-\t\t\tvertexShaderDataLen = identity_vert_len;\n \t\t\tshaderStridePixels_ = width_;\n \t\t}\n \t\tbreak;\n \t};\n \n-\tif (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, vertexShaderDataLen, shaderEnv)) {\n+\tif (egl_.compileVertexShader(vertexShaderId_, vertexShaderData.data(),\n+\t\t\t\t vertexShaderData.size(), shaderEnv)) {\n \t\tLOG(Debayer, Error) << \"Compile vertex shader fail\";\n \t\treturn -ENODEV;\n \t}\n \tutils::scope_exit vShaderGuard([&] { glDeleteShader(vertexShaderId_); });\n \n-\tif (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData, fragmentShaderDataLen, shaderEnv)) {\n+\tif (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData.data(),\n+\t\t\t\t fragmentShaderData.size(), shaderEnv)) {\n \t\tLOG(Debayer, Error) << \"Compile fragment shader fail\";\n \t\treturn -ENODEV;\n \t}\ndiff --git a/utils/codegen/gen-shader-header.py b/utils/codegen/gen-shader-header.py\nindex fe4f06065f0c..994e19c8e8e0 100755\n--- a/utils/codegen/gen-shader-header.py\n+++ b/utils/codegen/gen-shader-header.py\n@@ -19,15 +19,14 @@ def process_file(path, out):\n hex_data = [f'0x{c:02x}' for c in data]\n var_name = path.name.replace('.', '_')\n \n- out.write(f'unsigned char const {var_name}[] = {{\\n')\n+ out.write(f'static constexpr std::array<unsigned char, {len(data)}> {var_name}{{\\n')\n \n for i in range(math.ceil(len(data) / 16)):\n out.write('\\t')\n out.write(', '.join(hex_data[16 * i:16 * (i + 1)]))\n out.write(',\\n')\n \n- out.write('};\\n\\n')\n- out.write(f'const unsigned int {var_name}_len = {len(data)};\\n')\n+ out.write('};\\n')\n \n \n def main(argv):\n@@ -46,6 +45,8 @@ def main(argv):\n \n #pragma once\n \n+#include <array>\n+\n /*\n * List the names of the shaders at the top of header for readability's sake.\n *\n@@ -53,7 +54,7 @@ def main(argv):\n \n for path in args.inputs:\n name = path.name.replace('.', '_')\n- args.output.write(f' * unsigned char {name};\\n')\n+ args.output.write(f' * - {name}\\n')\n \n args.output.write('''\\\n */\n", "prefixes": [ "v2", "4/5" ] }