Show a patch.

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

{
    "id": 27252,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/27252/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/27252/",
    "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": "<20260706113900.2530549-8-bryan.odonoghue@linaro.org>",
    "date": "2026-07-06T11:39:00",
    "name": "[v5,7/7] libcamera: software_isp: debayer_egl: Implement input/output frame caching mechanism",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "a449636900391388f113ae4f35e88e84c7dea362",
    "submitter": {
        "id": 175,
        "url": "https://patchwork.libcamera.org/api/1.1/people/175/?format=api",
        "name": "Bryan O'Donoghue",
        "email": "bryan.odonoghue@linaro.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/27252/mbox/",
    "series": [
        {
            "id": 6041,
            "url": "https://patchwork.libcamera.org/api/1.1/series/6041/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6041",
            "date": "2026-07-06T11:38:53",
            "name": "libcamera: software_isp: gpu: Add go faster stripes",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/6041/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/27252/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/27252/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 5DEF1C330A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Jul 2026 11:39:22 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3E4DF66045;\n\tMon,  6 Jul 2026 13:39:21 +0200 (CEST)",
            "from mail-wr1-x432.google.com (mail-wr1-x432.google.com\n\t[IPv6:2a00:1450:4864:20::432])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 96D7A6604A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  6 Jul 2026 13:39:17 +0200 (CEST)",
            "by mail-wr1-x432.google.com with SMTP id\n\tffacd0b85a97d-4720d22c94aso2906527f8f.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 06 Jul 2026 04:39:17 -0700 (PDT)",
            "from inspiron14p-linux ([109.77.44.220])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-47a9de1e6ccsm24796084f8f.5.2026.07.06.04.39.16\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 06 Jul 2026 04:39:16 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"HmFJWVuh\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1783337957; x=1783942757;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to:content-type;\n\tbh=iBp5CTAibDRDjJr1C9jbaznxXxt4zBdSgPR4F1nm75g=;\n\tb=HmFJWVuhbGyJquuQK/joVOlkIPjew1VpWH6+JUqGSdF6EgsOXwsT8419HeUYqryWkw\n\tGdmlxoPqXHEmrhdDZLWsLaDdLsWYWUqwwzyaruL8mjFP22oZYa6UnSdG870SoSqemngq\n\t5v/Hf7aAMib1q/fLJnz0cBxWOIxSK816lNSuaQTeVrgwp04p4sFqvgy+8Mk/qwN2kAM2\n\t6X95egt6CI2x8JrPs6fbqnRkuJmYySLIX4Ao9109xAN6HlN1m3Giov1LNtJc88yQPG8L\n\tX5lX7bvdPQFrpPYYTsQjRQDxuPYL5KQS5lrdQKXnVhk3lV7M/jPc5K3x71kscUQc2/Ig\n\tBgfg==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1783337957; x=1783942757;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to:content-type;\n\tbh=iBp5CTAibDRDjJr1C9jbaznxXxt4zBdSgPR4F1nm75g=;\n\tb=Mu7lYbT4TeLK2IsZUktBMmthlD/JpWke7ciI4wedYEplz/Wjpv+031jSSC9k2SUIIu\n\tX+GFzOb54mtAMWsDHqJu2SRDnc+WZxq2NoSh7QzF7jhZwNtRc4NAlQkxmaCBfihQUulg\n\tmyJm10UYCO/D5IUOZpJ9DHu3y4AHKy9ExhAG5AeJbC1KMcYGlZJu+cXg0GGOJiV4mOy0\n\thsfXM4nwHKukbdx2XFyCMUZ1CE3i9dDA78qHiiG+F9FA/j7cuhLHZM81voSnPJjvjO5J\n\t+8xDixUhCKVvoGfSDJ9Xf6M2n8Z5wpWHwZjPWsw2IhjQ5BhSzVDdn0wutNQwuyFamcnD\n\tTFXg==",
        "X-Gm-Message-State": "AOJu0YyPylEy9Rm+mulX3YbxDyEbBU0JsQdwoyBlcilsX7GaskfBx1KW\n\t2gLp2nT+NONsfs3JfFNgktB1PEa5tf/yY36XOgjTjWwFkLDg2tUxdAfaChDgVqlMk/OgeEzHgDv\n\tWfOew",
        "X-Gm-Gg": "AfdE7cl8uacFh14r0yBhOEi7IL/w4cT1S+DFnTvs8lBh6vcj6X0UGnejdopMolRCcxy\n\thaZpck6GVJ6RyC7Z3XqYfgmJzxgv6ngGZeICBf2//AhGBYseB0oWxYYwH5KDNcv9bqBD5tjb9dF\n\tKJ+KOkOdFw3P+TpiY+Rn3kUCnNbRMX882yH4BkHmT6cVCsjaX2033RkakN6SBE/XTovTBTud4Of\n\t3szPUDCIedksLou4I6StX3a2QLFte/X4UKK6+smxn69uHNk+kspHlzGUVppbaNsSqg2u8CNhKAG\n\tidxre5Rd46gln+wRj4YgDVWzbW+kaeqaLd7LpubxTLM0rtrxBI7711RXfhk72/lPECuneE473Q7\n\t8vfHMW+PIXPKZGZtZKGTYhId54M6XDguizt6kmr7y3P1SNiHUtYnJLqkpkO9MChVC8VAt635HBs\n\t2LQfDqZqeDm05pOIbLjuGRFWyQ4e12MFRfllHHFfI=",
        "X-Received": "by 2002:a05:6000:188a:b0:467:f84c:4ca0 with SMTP id\n\tffacd0b85a97d-47aaaada7d2mr10692693f8f.22.1783337957027; \n\tMon, 06 Jul 2026 04:39:17 -0700 (PDT)",
        "From": "Bryan O'Donoghue <bryan.odonoghue@linaro.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "bryan.odonoghue@linaro.org,\n\tpavel@ucw.cz",
        "Subject": "[PATCH v5 7/7] libcamera: software_isp: debayer_egl: Implement\n\tinput/output frame caching mechanism",
        "Date": "Mon,  6 Jul 2026 12:39:00 +0100",
        "Message-ID": "<20260706113900.2530549-8-bryan.odonoghue@linaro.org>",
        "X-Mailer": "git-send-email 2.54.0",
        "In-Reply-To": "<20260706113900.2530549-1-bryan.odonoghue@linaro.org>",
        "References": "<20260706113900.2530549-1-bryan.odonoghue@linaro.org>",
        "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": "Implement a texture caching mechanism for both input and output frames and\nfor both types of input frame.\n\nThe before/after on a Qualcomm x1e is:\n\n9.737ms per frame\n5.691ms per frame\n\nThe before/after on a Qualcomm sm8250 is:\n\n21.710ms per frame\n17.336ms per frame\n\nfor i in {1..20} do\ncam -c /base/soc@0/cci@ac16000/i2c-bus@1/camera@10 -s width=1920,height=1080 --capture=60\n\nInterestingly there appears to be an absolute ~ 4.x ms per frame uplift as\nopposed to what intuition might suggest a proportional.\n\nSigned-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n---\n src/libcamera/software_isp/debayer_egl.cpp | 112 ++++++++++++++++-----\n src/libcamera/software_isp/debayer_egl.h   |  13 ++-\n 2 files changed, 96 insertions(+), 29 deletions(-)",
    "diff": "diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\nindex c3a7b7952..ca3353d9f 100644\n--- a/src/libcamera/software_isp/debayer_egl.cpp\n+++ b/src/libcamera/software_isp/debayer_egl.cpp\n@@ -345,6 +345,9 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg,\n \t */\n \tstats_->setWindow(Rectangle(window_.size()));\n \n+\tinputBufferCount_ = inputCfg.bufferCount;\n+\toutputBufferCount_ = outputCfg.bufferCount;\n+\n \treturn 0;\n }\n \n@@ -504,36 +507,95 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara\n \treturn;\n }\n \n-int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams &params, std::optional<MappedFrameBuffer> *inMapped, std::optional<DmaSyncer> *inDmaSyncer)\n+eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optional<MappedFrameBuffer> *inMapped, std::optional<DmaSyncer> *inDmaSyncer)\n {\n-\tbool dmabuf_import_succeeded = false;\n-\n-\t/* eGL context switch */\n-\tegl_.makeCurrent();\n-\n-\t/* Try to create texture for input buffer via dmabuf import */\n-\tif (!eglImageBayerIn_->dmabuf_import_failed_) {\n-\t\tif (egl_.createInputDMABufTexture2D(*eglImageBayerIn_, input->planes()[0].fd.get()) == 0)\n-\t\t\tdmabuf_import_succeeded = true;\n-\t\telse\n-\t\t\tLOG(Debayer, Info) << \"Importing input buffer with DMABuf import failed, falling back to upload\";\n+\tconst SharedFD &fd = input->planes()[0].fd;\n+\tbool use_dmabuf = false;\n+\n+\tauto [input_cache, cache_miss] = eglImageBayerIn_.try_emplace(fd);\n+\tif (cache_miss) {\n+\t\tif (eglImageBayerIn_.size() > inputBufferCount_) {\n+\t\t\teglImageBayerIn_.erase(inputRing_.front());\n+\t\t\tinputRing_.pop_front();\n+\t\t\tLOG(Debayer, Error) << \"Input cache \" << inputBufferCount_ << \" exceeded evicted entry\";\n+\t\t}\n+\t\tinput_cache->second = std::make_unique<eGLImage>(glFormat_, inputConfig_.stride / bytesPerPixel_,\n+\t\t\t\t\t\t\t\t height_, inputConfig_.stride, GL_TEXTURE0, 0);\n+\t\tinputRing_.push_back(fd);\n+\t}\n+\teGLImage *eglImageIn = input_cache->second.get();\n+\n+\t/* Try to create texture for input buffer via dmabuf import only on cache miss */\n+\tif (cache_miss) {\n+\t\tif (egl_.createInputDMABufTexture2D(*eglImageIn, input->planes()[0].fd.get()) == 0)\n+\t\t\tuse_dmabuf = true;\n+\t} else if (!eglImageIn->dmabuf_import_failed_) {\n+\t\tuse_dmabuf = true;\n+\t\tegl_.activateBindTexture(*eglImageIn);\n \t}\n \n-\t/* Otherwise create texture for input buffer via upload from CPU */\n-\tif (!dmabuf_import_succeeded) {\n+\tif (!use_dmabuf) {\n \t\tinDmaSyncer->emplace(input->planes()[0].fd, DmaSyncer::SyncType::Read);\n \t\tinMapped->emplace(input, MappedFrameBuffer::MapFlag::Read);\n \t\tif (!inMapped->value().isValid()) {\n \t\t\tLOG(Debayer, Error) << \"mmap-ing buffer(s) failed\";\n-\t\t\treturn -ENODEV;\n+\t\t\tif (cache_miss) {\n+\t\t\t\teglImageBayerIn_.erase(input_cache);\n+\t\t\t\tinputRing_.pop_back();\n+\t\t\t}\n+\t\t\treturn nullptr;\n+\t\t}\n+\t\tif (cache_miss)\n+\t\t\tegl_.createTexture2D(*eglImageIn, inMapped->value().planes()[0].data());\n+\t\telse\n+\t\t\tegl_.updateTexture2D(*eglImageIn, inMapped->value().planes()[0].data());\n+\t}\n+\n+\treturn eglImageIn;\n+}\n+\n+eGLImage *DebayerEGL::getCachedOutputFrameBuffer(FrameBuffer *output)\n+{\n+\tconst SharedFD &fd = output->planes()[0].fd;\n+\n+\tauto [output_cache, cache_miss] = eglImageBayerOut_.try_emplace(fd);\n+\tif (cache_miss) {\n+\t\tif (eglImageBayerOut_.size() > outputBufferCount_) {\n+\t\t\teglImageBayerOut_.erase(outputRing_.front());\n+\t\t\toutputRing_.pop_front();\n+\t\t\tLOG(Debayer, Error) << \"Output cache \" << outputBufferCount_ << \" exceeded evicted entry\";\n \t\t}\n-\t\tegl_.createTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data());\n+\t\toutput_cache->second = std::make_unique<eGLImage>(GL_RGBA, outputSize_.width,\n+\t\t\t\t\t\t\t\t  outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1);\n+\t\tif (egl_.createOutputDMABufTexture2D(*output_cache->second, output->planes()[0].fd.get())) {\n+\t\t\teglImageBayerOut_.erase(output_cache);\n+\t\t\treturn nullptr;\n+\t\t}\n+\t\toutputRing_.push_back(fd);\n \t}\n+\teGLImage *eglImageOut = output_cache->second.get();\n+\n+\treturn eglImageOut;\n+}\n+\n+int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams &params, std::optional<MappedFrameBuffer> *inMapped, std::optional<DmaSyncer> *inDmaSyncer)\n+{\n+\teGLImage *eglImageIn;\n+\teGLImage *eglImageOut;\n+\n+\t/* eGL context switch */\n+\tegl_.makeCurrent();\n \n-\t/* Generate the output render framebuffer as render to texture */\n-\tegl_.createOutputDMABufTexture2D(*eglImageBayerOut_, output->planes()[0].fd.get());\n+\teglImageIn = getCachedInputFrameBuffer(input, inMapped, inDmaSyncer);\n+\tif (!eglImageIn)\n+\t\treturn -ENOMEM;\n+\teglImageOut = getCachedOutputFrameBuffer(output);\n+\tif (!eglImageOut)\n+\t\treturn -ENOMEM;\n+\n+\tegl_.attachTextureToFBO(*eglImageOut);\n+\tsetShaderVariableValues(*eglImageIn, params);\n \n-\tsetShaderVariableValues(*eglImageBayerIn_, params);\n \tglViewport(0, 0, width_, height_);\n \tglClear(GL_COLOR_BUFFER_BIT);\n \tglDrawArrays(GL_TRIANGLE_FAN, 0, DEBAYER_OPENGL_COORDS);\n@@ -615,19 +677,15 @@ int DebayerEGL::start()\n \tif (initBayerShaders(inputPixelFormat_, outputPixelFormat_))\n \t\treturn -EINVAL;\n \n-\t/* Raw bayer input as texture */\n-\teglImageBayerIn_ = std::make_unique<eGLImage>(glFormat_, inputConfig_.stride / bytesPerPixel_, height_, inputConfig_.stride, GL_TEXTURE0, 0);\n-\n-\t/* Texture we will render to */\n-\teglImageBayerOut_ = std::make_unique<eGLImage>(GL_RGBA, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1);\n-\n \treturn 0;\n }\n \n void DebayerEGL::stop()\n {\n-\teglImageBayerOut_.reset();\n-\teglImageBayerIn_.reset();\n+\teglImageBayerOut_.clear();\n+\teglImageBayerIn_.clear();\n+\toutputRing_.clear();\n+\tinputRing_.clear();\n \n \tif (programId_)\n \t\tglDeleteProgram(programId_);\ndiff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h\nindex 348d7305b..dde6ba9bf 100644\n--- a/src/libcamera/software_isp/debayer_egl.h\n+++ b/src/libcamera/software_isp/debayer_egl.h\n@@ -9,9 +9,11 @@\n \n #pragma once\n \n+#include <deque>\n #include <memory>\n #include <stdint.h>\n #include <tuple>\n+#include <unordered_map>\n #include <vector>\n \n #define GL_GLEXT_PROTOTYPES\n@@ -68,14 +70,21 @@ private:\n \tvoid setShaderVariableValues(eGLImage &eGLImageIn, const DebayerParams &params);\n \tint debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams &params, std::optional<MappedFrameBuffer> *mappedInputBuffer, std::optional<DmaSyncer> *inputBufferDmaSyncer);\n \n+\teGLImage *getCachedInputFrameBuffer(FrameBuffer *input, std::optional<MappedFrameBuffer> *inMapped, std::optional<DmaSyncer> *inDmaSyncer);\n+\teGLImage *getCachedOutputFrameBuffer(FrameBuffer *output);\n+\n \t/* Shader program identifiers */\n \tGLuint vertexShaderId_ = 0;\n \tGLuint fragmentShaderId_ = 0;\n \tGLuint programId_ = 0;\n \n \t/* Pointer to object representing input texture */\n-\tstd::unique_ptr<eGLImage> eglImageBayerIn_;\n-\tstd::unique_ptr<eGLImage> eglImageBayerOut_;\n+\tstd::unordered_map<SharedFD, std::unique_ptr<eGLImage>> eglImageBayerIn_;\n+\tstd::unordered_map<SharedFD, std::unique_ptr<eGLImage>> eglImageBayerOut_;\n+\tstd::deque<SharedFD> inputRing_;\n+\tstd::deque<SharedFD> outputRing_;\n+\tunsigned int inputBufferCount_;\n+\tunsigned int outputBufferCount_;\n \n \t/* Shader parameters */\n \tfloat firstRed_x_;\n",
    "prefixes": [
        "v5",
        "7/7"
    ]
}