Show a patch.

GET /api/patches/27139/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 27139,
    "url": "https://patchwork.libcamera.org/api/patches/27139/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/27139/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20260630083031.3197714-5-laurent.pinchart@ideasonboard.com>",
    "date": "2026-06-30T08:30:31",
    "name": "[4/4] libcamera: shaders: Replace C array with std::array",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "5157046e1a7c223ac66fd0e3cd68774c596aeb3f",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/27139/mbox/",
    "series": [
        {
            "id": 6027,
            "url": "https://patchwork.libcamera.org/api/series/6027/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6027",
            "date": "2026-06-30T08:30:27",
            "name": "libcamera: Improve shader header generation",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/6027/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/27139/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/27139/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 7DC7DC3264\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Jun 2026 08:30:42 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DBFB065F63;\n\tTue, 30 Jun 2026 10:30:41 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7EF8365F3B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Jun 2026 10:30:38 +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 BFD41196B;\n\tTue, 30 Jun 2026 10:29:54 +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=\"ZlloVHo5\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1782808194;\n\tbh=QgDj/lXMODb0LfK1v9l2IgS2HGDMEQN8/y31ew8X/34=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ZlloVHo5/RtMKbQ19sg7/+Doxt0gE1QmzVKvTehs24JxFjf1n1WwlVT42Jrc4+b4o\n\tfOTR9p4ZRFPpB8kg9b/FcHKCBAkUCRCeg+bG0Nk5L7PLEdPgGnKTZJbVZ93Kl3zjMY\n\tFs4MGjSPv/Fq6TzSH2DUZNDjS4TKoUpVcUMpBjUw=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Bryan O'Donoghue <bryan.odonoghue@linaro.org>",
        "Subject": "[PATCH 4/4] libcamera: shaders: Replace C array with std::array",
        "Date": "Tue, 30 Jun 2026 11:30:31 +0300",
        "Message-ID": "<20260630083031.3197714-5-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.53.0",
        "In-Reply-To": "<20260630083031.3197714-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20260630083031.3197714-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "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>\n---\n src/libcamera/software_isp/debayer_egl.cpp | 23 +++++++---------------\n utils/codegen/gen-shader-header.py         |  7 ++++---\n 2 files changed, 11 insertions(+), 19 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 908217a2bd2e..0bcf76653d77 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(name, out):\n     hex_data = [f'0x{c:02x}' for c in data]\n     var_name = os.path.basename(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@@ -45,6 +44,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",
    "prefixes": [
        "4/4"
    ]
}