Patch Detail
Show a patch.
GET /api/patches/27055/?format=api
{ "id": 27055, "url": "https://patchwork.libcamera.org/api/patches/27055/?format=api", "web_url": "https://patchwork.libcamera.org/patch/27055/", "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": "<20260626113325.3218045-9-bryan.odonoghue@linaro.org>", "date": "2026-06-26T11:33:25", "name": "[v3,8/8] libcamera: software_isp: debayer_egl: Implement input/output frame caching mechanism", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "7d75aecbe6a59b941c1b0675b44520f27973ca32", "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/27055/mbox/", "series": [ { "id": 6020, "url": "https://patchwork.libcamera.org/api/series/6020/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6020", "date": "2026-06-26T11:33:17", "name": "libcamera: software_isp: gpu: Add go faster stripes", "version": 3, "mbox": "https://patchwork.libcamera.org/series/6020/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/27055/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/27055/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 ACDB8C3307\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 26 Jun 2026 11:33:52 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DF18F6590C;\n\tFri, 26 Jun 2026 13:33:51 +0200 (CEST)", "from mail-wm1-x329.google.com (mail-wm1-x329.google.com\n\t[IPv6:2a00:1450:4864:20::329])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CF2C65902\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 26 Jun 2026 13:33:47 +0200 (CEST)", "by mail-wm1-x329.google.com with SMTP id\n\t5b1f17b1804b1-49222fb062bso8934565e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 26 Jun 2026 04:33:47 -0700 (PDT)", "from inspiron14p-linux ([109.76.78.98])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-49268fe31b0sm79265985e9.4.2026.06.26.04.33.45\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 26 Jun 2026 04:33:45 -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=\"AdSWOPZV\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1782473627; x=1783078427;\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=ggDf+Tx2g2b9HHWJEEpcyZgRvHrHYXQMzOnA7eG6sds=;\n\tb=AdSWOPZVjYCx6HLEjAtqHBFCp0OqCRZzotQt5LulnARU9E4o3eSU/CCA9IIWtzQ9/n\n\tfjQTi+Li/3PBk7QYIXRNEMm2+2a/7Ozx2wBUtA0d4ELHdjcmvDaUaqsii81IUSD85oe+\n\tHyqb1pqANGLBoCVg2CW1T8UT1ylP40LahKZf8w+whiCEosamchJ6woxhrT6apOskGJWV\n\tYD5b6hl17+FtpSO06L3xogJ3Ir/+qAF16EKK0yBAddQVeL+gu5P/q5bhsJkr/2TpPAIb\n\typn7+qS2+W7+5XumDQHgRYSAXbyKPu9R957R/2p7hAKdOlgIiKZRkjSvpR8ghwtcqnOD\n\tB98g==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1782473627; x=1783078427;\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=ggDf+Tx2g2b9HHWJEEpcyZgRvHrHYXQMzOnA7eG6sds=;\n\tb=D4mtCSuxiEBDmPHM6IKojdgUDIKjkufZl50ez1HdBNfB6Cx2WBwYn14gY6qsFlrF1w\n\t25mvzu6Ent6Vl6VdFh+2r8nQRKrnbuBcqQ8X66v1rJCGzYq0QfsBA+60169L+6x+Vw+v\n\tnH93gnP2UseAak25HArAREunBGz/VY5B0nBFwSEv4uBzFJpyylFnYpDfIUg/2saf+Q0m\n\tget5Tu0s1qKO/yKu/eRhDp90tazRv0YcpMlCNngEmbCsdNcXeHZI5zqx7+BpagTYEHnB\n\tuIe2rKbmki1hUcfNzs3xeMGPc8UdmIoBarC+uY0I3M8v9Znj1eDj2Z37w66R3S2Ickt6\n\t3vlA==", "X-Gm-Message-State": "AOJu0YxWhHVMhIHrfMgoKe6UdTHlvUA6ej9a3B5tgy7Tm+HAmZfu3SN+\n\t53Dsws4YiFMkk/SA3C10f72VbHw9iwjaMBkHst9bXUouhyeiLyuRNAYqt2zG0ToI5GXY9hAe3b8\n\tuT1MT4WU=", "X-Gm-Gg": "AfdE7clJ78tIoAQmbo+mBbAVTSAQQnH20bCkgf1sf6SuoAqHiIb+ETDw1CBrAnsrAue\n\tPYbznnFGwAm8yrRQ7go0Xv+wLBubO3aQB8H16cwCgzzJyStaeVnuU4uVTK4u8nY8MWeEBAnF+aW\n\tfxVA/fVT0SIo2hbr2fG9BXhV2SE0gCa04j3H+I/YOR6vjkKURHzdi6UhWfN6gi4Yyf7M9FuxXpr\n\t6EICUz+Qs/c7hgpG/KzUb0BvhMOJ484S0oLrqvFKIHz6Ar8t21uY7H4Nn5g4dI2VApi+RoQP9yw\n\tlRjFTC3zv15MziMrq5uanFQHr8echX2Wabxg5eKhedblRl2IGQ4WLOBREo+4hj5hmk0zWqzcEBo\n\txyH4xZ6mEVHEo2YA/YgjKXUoD2v2gAehHEGhUydJchqv/ECsdrQ9NQRU2gpEHNoWnqTe+yRl0zd\n\tfTK7d1XJKCSGb5zGagoS7mZ27NK8OYiaYxpTk9", "X-Received": "by 2002:a05:600c:4e87:b0:492:25a0:1730 with SMTP id\n\t5b1f17b1804b1-49266893494mr90648115e9.32.1782473626579; \n\tFri, 26 Jun 2026 04:33:46 -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 v3 8/8] libcamera: software_isp: debayer_egl: Implement\n\tinput/output frame caching mechanism", "Date": "Fri, 26 Jun 2026 12:33:25 +0100", "Message-ID": "<20260626113325.3218045-9-bryan.odonoghue@linaro.org>", "X-Mailer": "git-send-email 2.54.0", "In-Reply-To": "<20260626113325.3218045-1-bryan.odonoghue@linaro.org>", "References": "<20260626113325.3218045-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 | 87 +++++++++++++++++-----\n src/libcamera/software_isp/debayer_egl.h | 10 ++-\n 2 files changed, 75 insertions(+), 22 deletions(-)", "diff": "diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\nindex 53bb67c17..fc37f0b75 100644\n--- a/src/libcamera/software_isp/debayer_egl.cpp\n+++ b/src/libcamera/software_isp/debayer_egl.cpp\n@@ -355,6 +355,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@@ -514,34 +517,84 @@ 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+eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optional<MappedFrameBuffer> *inMapped, std::optional<DmaSyncer> *inDmaSyncer)\n {\n-\t/* eGL context switch */\n-\tegl_.makeCurrent();\n+\tauto [input_cache, cache_miss] = eglImageBayerIn_.try_emplace(input->planes()[0].fd.get());\n+\tif (cache_miss) {\n+\t\tif (eglImageBayerIn_.size() > inputBufferCount_) {\n+\t\t\tLOG(Debayer, Error) << \"Input count \" << inputBufferCount_ << \" exhausted\";\n+\t\t\treturn nullptr;\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}\n+\teGLImage *eglImageIn = input_cache->second.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_miss) {\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/* Otherwise create texture for input buffer via upload from CPU */\n-\tif (!use_dmabuf_) {\n+\tif (use_dmabuf_) {\n+\t\t/* Cache hit using dmabuf activate and bind */\n+\t\tif (!cache_miss)\n+\t\t\tegl_.activateBindTexture(*eglImageIn);\n+\t} else {\n+\t\t/* Otherwise create texture for input buffer via upload from CPU */\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_.createTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data());\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-\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+\tauto [output_cache, cache_miss] = eglImageBayerOut_.try_emplace(output->planes()[0].fd.get());\n+\tif (cache_miss) {\n+\t\tif (eglImageBayerOut_.size() > outputBufferCount_) {\n+\t\t\tLOG(Debayer, Error) << \"Output buffer count \" << outputBufferCount_ << \" exhaustion\";\n+\t\t\treturn nullptr;\n+\t\t}\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\tegl_.createOutputDMABufTexture2D(*output_cache->second, output->planes()[0].fd.get());\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 ¶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 +676,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..ddb3ef378 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,19 @@ private:\n \n \tbool use_dmabuf_;\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<int, std::unique_ptr<eGLImage>> eglImageBayerIn_;\n+\tstd::unordered_map<int, std::unique_ptr<eGLImage>> eglImageBayerOut_;\n+\tunsigned int inputBufferCount_;\n+\tunsigned int outputBufferCount_;\n \n \t/* Shader parameters */\n \tfloat firstRed_x_;\n", "prefixes": [ "v3", "8/8" ] }