Patch Detail
Show a patch.
GET /api/patches/27036/?format=api
{ "id": 27036, "url": "https://patchwork.libcamera.org/api/patches/27036/?format=api", "web_url": "https://patchwork.libcamera.org/patch/27036/", "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": "<20260624085849.873784-11-bryan.odonoghue@linaro.org>", "date": "2026-06-24T08:58:49", "name": "[10/10] libcamera: software_isp: debayer_egl: Implement input/output frame caching mechanism", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "b6a6a58795d614c464e28ba1d8cbe134e859ab50", "submitter": { "id": 175, "url": "https://patchwork.libcamera.org/api/people/175/?format=api", "name": "Bryan O'Donoghue", "email": "bryan.odonoghue@linaro.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/27036/mbox/", "series": [ { "id": 6015, "url": "https://patchwork.libcamera.org/api/series/6015/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6015", "date": "2026-06-24T08:58:39", "name": "libcamera: software_isp: gpu: Add go faster stripes", "version": 1, "mbox": "https://patchwork.libcamera.org/series/6015/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/27036/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/27036/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 EE8B4C3308\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 24 Jun 2026 08:59:21 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 79F4C65895;\n\tWed, 24 Jun 2026 10:59:21 +0200 (CEST)", "from mail-wm1-x334.google.com (mail-wm1-x334.google.com\n\t[IPv6:2a00:1450:4864:20::334])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8BBC265891\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Jun 2026 10:59:08 +0200 (CEST)", "by mail-wm1-x334.google.com with SMTP id\n\t5b1f17b1804b1-4924593f45dso8073385e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Jun 2026 01:59:08 -0700 (PDT)", "from inspiron14p-linux ([109.76.100.231])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-49261063d6esm25128375e9.2.2026.06.24.01.59.06\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 24 Jun 2026 01:59:06 -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=\"jGh1QZqe\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1782291548; x=1782896348;\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;\n\tbh=LvpHhq7SDZeODR/gVrmxjhKv6G3W7LqpHWaMD33/8yc=;\n\tb=jGh1QZqe0JkL8Bn4+Xlq1G/PlJi+XewVawIdb3Rq/1OM51XLJN0Z1BDmJY1D+6sgBa\n\t+AKLAwYNKFBvc9yZL6M6wEqLf+FSh9uqCzy0boiPT1KZbL+rH9ndgyYd+HIRIbsgoPpC\n\tmX4mteY9QeCB5ZHtMFIDsPvq9WG2tndDEflPGYgO1Upfgmf1eRWUezunkIPA/+ZpTtqY\n\tsVa3uUpyk9sxRjQdsHJs/rBiTiTQ32IPaHH+mcP5i/O7cMKPYWV8w4WVYT2uZXshvUkL\n\t/0aKvPuI0Pu6Ad9tUHclB3/WUGavhRxIw2/RAegQkIS0UfxYPeKMbhoFWwIA7/iZLAX1\n\t6qEA==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1782291548; x=1782896348;\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;\n\tbh=LvpHhq7SDZeODR/gVrmxjhKv6G3W7LqpHWaMD33/8yc=;\n\tb=A05gQToU1ecLr+3q+hj8Xt+Wd9wAZHc4x7chdkPdm7Co/HIRr2KzQtnjyLt2zZrSiU\n\t9aKsR7dXzeN9yRRCUuQ7YsgxKMaBguWmWyBSp/G70WviUBFLzaq/VXNOlfT8PxKNIQgk\n\tBnSaTlSzZdhajY7vNk6evA59GHdnosSOJp1NKyktPZzbYFjGWw3yRuzRPnpJlHumt8Qv\n\t5GLu0MODOkxwJ5la2g+qpaUSt61c1HC+ji7XJ/i61zn6QaqnyGxrkOXdae2HBrMc2umC\n\t241820C4y6G8tgIwHm1ai6SLHdeVMRi6GA2DmoAhHooIQD4nLeEQi1ppwKF7BucxrWXs\n\tXfZQ==", "X-Gm-Message-State": "AOJu0YwXtVIeaitRPO1qX2fvZTPL9VCD7Umm40fDhXewmgswNQYVHP14\n\tu9aIbMeIWvC87q/uBC3JMOW4ykPDKJn8eFR/XtDDDvLPc+gCTHgs0E4ZS+aukaFhs9/pF0LgJ8t\n\txCGOwusw=", "X-Gm-Gg": "AfdE7cmOSP+WslFDzqAijgZiaBlT+7jfs56F0vJvAPz27a2nhRc9tr2AcXKMBDqYMlT\n\t1AETPwR0hAaeTm6li0lc1kw3Sajq8xYEY47vHk6R7ZABJl8v7WoVyjWsRzdxHmv4S5pdxBA+kaz\n\ttKbgD9CJkc5/ox6kIfoVbPn2R2g+qSmXVyvAJW0NPTlBOjMPP9XNkZfx1+o4jKtFvqFjwqFb18H\n\tN23s291AApPw/aOfTd9/CfyGiVjZWkq0/uhaNeZvOBq+Xbwr0SRmh85Ixt7XJolutlgyq8O+ROG\n\tHPRDIQN6r/zALRakV99XNClfAGWuPzay2m0wJCvf2HnT7xC/oIpzrtl9eylsXEqlJvqXcfgIhfq\n\tavjamXXoss1knZws1WYcQOsnq9ZJPrV4BTL0xdPgVjaQiTvORLSR7Mk8xLx8VAio4rhEa84+D7u\n\tpr9GKbwdeflpH4Zfqm7xIAD76whRon", "X-Received": "by 2002:a05:600c:a012:b0:492:2e1c:1d19 with SMTP id\n\t5b1f17b1804b1-49260875bbamr32747295e9.31.1782291547966; \n\tWed, 24 Jun 2026 01:59:07 -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 10/10] libcamera: software_isp: debayer_egl: Implement\n\tinput/output frame caching mechanism", "Date": "Wed, 24 Jun 2026 09:58:49 +0100", "Message-ID": "<20260624085849.873784-11-bryan.odonoghue@linaro.org>", "X-Mailer": "git-send-email 2.54.0", "In-Reply-To": "<20260624085849.873784-1-bryan.odonoghue@linaro.org>", "References": "<20260624085849.873784-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 | 108 +++++++++++++++++----\n src/libcamera/software_isp/debayer_egl.h | 12 ++-\n 2 files changed, 100 insertions(+), 20 deletions(-)", "diff": "diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\nindex 0568c413b..8ac5cb76f 100644\n--- a/src/libcamera/software_isp/debayer_egl.cpp\n+++ b/src/libcamera/software_isp/debayer_egl.cpp\n@@ -355,6 +355,12 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg,\n \t */\n \tstats_->setWindow(Rectangle(window_.size()));\n \n+\tinputBufferCache_ = std::make_unique<V4L2BufferCache>(inputCfg.bufferCount);\n+\toutputBufferCache_ = std::make_unique<V4L2BufferCache>(outputCfg.bufferCount);\n+\n+\teglImageBayerIn_.resize(inputCfg.bufferCount);\n+\teglImageBayerOut_.resize(outputCfg.bufferCount);\n+\n \treturn 0;\n }\n \n@@ -514,34 +520,106 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara\n \treturn;\n }\n \n-int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional<MappedFrameBuffer> *inMapped, std::optional<DmaSyncer> *inDmaSyncer)\n+int DebayerEGL::getBufferCache(V4L2BufferCache &cache, FrameBuffer *framebuffer, bool &cache_hit)\n {\n-\t/* eGL context switch */\n-\tegl_.makeCurrent();\n+\tint cache_idx;\n+\n+\tcache_idx = cache.get(*framebuffer, cache_hit);\n+\tif (cache_idx < 0) {\n+\t\tLOG(Debayer, Error) << \"buffer exceeds configured cache size\";\n+\t\treturn -ENODEV;\n+\t}\n+\tcache.put(cache_idx);\n+\n+\treturn cache_idx;\n+}\n+\n+eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optional<MappedFrameBuffer> *inMapped, std::optional<DmaSyncer> *inDmaSyncer)\n+{\n+\teGLImage *eglImageIn;\n+\tbool cache_hit;\n+\tint cache_idx;\n+\n+\tcache_idx = getBufferCache(*inputBufferCache_, input, cache_hit);\n+\tif (cache_idx < 0)\n+\t\treturn nullptr;\n+\n+\tif (!cache_hit) {\n+\t\teglImageBayerIn_[cache_idx] = std::make_unique<eGLImage>(glFormat_, inputConfig_.stride / bytesPerPixel_,\n+\t\t\t\t\t\t\t\t\t height_, inputConfig_.stride, GL_TEXTURE0, 0);\n+\t}\n+\n+\teglImageIn = eglImageBayerIn_[cache_idx].get();\n \n \t/* Try to create texture for input buffer via dmabuf import */\n-\tif (use_dmabuf_) {\n-\t\tif (egl_.createInputDMABufTexture2D(*eglImageBayerIn_, input->planes()[0].fd.get()) != 0) {\n+\tif (use_dmabuf_ && !cache_hit) {\n+\t\tif (egl_.createInputDMABufTexture2D(*eglImageIn, input->planes()[0].fd.get()) != 0) {\n \t\t\tuse_dmabuf_ = false;\n \t\t\tLOG(Debayer, Info) << \"Importing input buffer with DMABuf import failed, falling back to upload\";\n \t\t}\n \t}\n \n+\t/* Cache hit using dmabuf activate and bind */\n+\tif (use_dmabuf_ && cache_hit) {\n+\t\tegl_.activateBindTexture(*eglImageIn);\n+\t}\n+\n \t/* Otherwise create texture for input buffer via upload from CPU */\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\treturn nullptr;\n \t\t}\n-\t\tegl_.createInputTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data());\n+\t\tif (cache_hit)\n+\t\t\tegl_.updateInputTexture2D(*eglImageIn, inMapped->value().planes()[0].data());\n+\t\telse\n+\t\t\tegl_.createInputTexture2D(*eglImageIn, inMapped->value().planes()[0].data());\n \t}\n \n-\t/* Generate the output render framebuffer as render to texture */\n-\tegl_.createOutputDMABufTexture2D(*eglImageBayerOut_, output->planes()[0].fd.get());\n+\treturn eglImageIn;\n+}\n+\n+eGLImage *DebayerEGL::getCachedOutputFrameBuffer(FrameBuffer *output)\n+{\n+\teGLImage *eglImageOut;\n+\tbool cache_hit;\n+\tint cache_idx;\n+\n+\tcache_idx = getBufferCache(*outputBufferCache_, output, cache_hit);\n+\tif (cache_idx < 0)\n+\t\treturn nullptr;\n+\n+\tif (!cache_hit) {\n+\t\teglImageBayerOut_[cache_idx] = std::make_unique<eGLImage>(GL_RGBA, outputSize_.width,\n+\t\t\t\t\t\t\t\t\t outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1);\n+\t\tegl_.createOutputDMABufTexture2D(*eglImageBayerOut_[cache_idx], output->planes()[0].fd.get());\n+\t}\n+\teglImageOut = eglImageBayerOut_[cache_idx].get();\n+\n+\treturn eglImageOut;\n+}\n+\n+int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, 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+\teglImageIn = getCachedInputFrameBuffer(input, inMapped, inDmaSyncer);\n+\tif (!eglImageIn)\n+\t\treturn -ENOMEM;\n+\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@@ -623,19 +701,13 @@ 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 \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 d8509e9f2..238fe7345 100644\n--- a/src/libcamera/software_isp/debayer_egl.h\n+++ b/src/libcamera/software_isp/debayer_egl.h\n@@ -22,6 +22,7 @@\n #include \"libcamera/internal/mapped_framebuffer.h\"\n #include \"libcamera/internal/software_isp/benchmark.h\"\n #include \"libcamera/internal/software_isp/swstats_cpu.h\"\n+#include \"libcamera/internal/v4l2_videodevice.h\"\n \n #include <EGL/egl.h>\n #include <EGL/eglext.h>\n@@ -70,14 +71,21 @@ private:\n \n \tbool use_dmabuf_;\n \n+\tint getBufferCache(V4L2BufferCache &buffercache, FrameBuffer *framebuffer, bool &hit);\n+\teGLImage *getCachedInputFrameBuffer(FrameBuffer *input, std::optional<MappedFrameBuffer> *inMapped, std::optional<DmaSyncer> *inDmaSyncer);\n+\teGLImage *getCachedOutputFrameBuffer(FrameBuffer *output);\n+\n+\tstd::unique_ptr<V4L2BufferCache> inputBufferCache_;\n+\tstd::unique_ptr<V4L2BufferCache> outputBufferCache_;\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::vector<std::unique_ptr<eGLImage>> eglImageBayerIn_;\n+\tstd::vector<std::unique_ptr<eGLImage>> eglImageBayerOut_;\n \n \t/* Shader parameters */\n \tfloat firstRed_x_;\n", "prefixes": [ "10/10" ] }