[{"id":39615,"web_url":"https://patchwork.libcamera.org/comment/39615/","msgid":"<94ce44c9-4dad-4af8-8d8f-7d452ec97aec@collabora.com>","date":"2026-07-07T07:35:11","subject":"Re: [PATCH v6 6/6] libcamera: software_isp: debayer_egl: Implement\n\tinput/output frame caching mechanism","submitter":{"id":140,"url":"https://patchwork.libcamera.org/api/people/140/","name":"Robert Mader","email":"robert.mader@collabora.com"},"content":"Hi Bryan,\n\nOn 07.07.26 00:22, Bryan O'Donoghue wrote:\n> Implement a texture caching mechanism for both input and output frames and\n> for both types of input frame.\n>\n> The before/after on a Qualcomm x1e is:\n>\n> 9.737ms per frame\n> 5.691ms per frame\n>\n> The before/after on a Qualcomm sm8250 is:\n>\n> 21.710ms per frame\n> 17.336ms per frame\n>\n> for i in {1..20} do\n> cam -c /base/soc@0/cci@ac16000/i2c-bus@1/camera@10 -s width=1920,height=1080 --capture=60\n>\n> Interestingly there appears to be an absolute ~ 4.x ms per frame uplift as\n> opposed to what intuition might suggest a proportional.\n>\n> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n\nthanks, looks great to me!\n\nReviewed-by: Robert Mader <robert.mader@collabora.com>\n\n> ---\n>   src/libcamera/software_isp/debayer_egl.cpp | 125 ++++++++++++++++-----\n>   src/libcamera/software_isp/debayer_egl.h   |  10 +-\n>   2 files changed, 104 insertions(+), 31 deletions(-)\n>\n> diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\n> index c3a7b7952..a7cca5dde 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,106 @@ 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> +\tconst SharedFD &fd = input->planes()[0].fd;\n> +\tbool cache_miss = true;\n> +\teGLImage *eglImageIn;\n> +\n> +\tfor (auto &[ifd, img] : eglImageInCache_) {\n> +\t\tif (ifd == fd) {\n> +\t\t\teglImageIn = img.get();\n> +\t\t\tcache_miss = false;\n> +\t\t\tbreak;\n> +\t\t}\n> +\t}\n>   \n> -\t/* eGL context switch */\n> -\tegl_.makeCurrent();\n> +\tif (cache_miss) {\n> +\t\tif (eglImageInCache_.size() >= inputBufferCount_) {\n> +\t\t\teglImageInCache_.pop_front();\n> +\t\t\tLOG(Debayer, Debug) << \"Input cache \" << inputBufferCount_ << \" exceeded evicted entry\";\n> +\t\t}\n> +\n> +\t\teglImageInCache_.emplace_back(fd, std::make_unique<eGLImage>(glFormat_, inputConfig_.stride / bytesPerPixel_, height_, inputConfig_.stride, GL_TEXTURE0, 0));\n> +\t\teglImageIn = eglImageInCache_.back().second.get();\n> +\n> +\t\tif (egl_.createInputDMABufTexture2D(*eglImageIn, input->planes()[0].fd.get()) == 0)\n> +\t\t\treturn eglImageIn;\n> +\n> +\t} else if (!eglImageIn->dmabuf_import_failed_) {\n> +\t\tegl_.activateBindTexture(*eglImageIn);\n> +\t\treturn eglImageIn;\n> +\t}\n> +\n> +\t/* DMA mode fail create/update an existing texture using the slow path */\n> +\tinDmaSyncer->emplace(input->planes()[0].fd, DmaSyncer::SyncType::Read);\n> +\tinMapped->emplace(input, MappedFrameBuffer::MapFlag::Read);\n> +\tif (!inMapped->value().isValid()) {\n> +\t\tLOG(Debayer, Error) << \"mmap-ing buffer(s) failed\";\n> +\t\tif (cache_miss) {\n> +\t\t\teglImageInCache_.pop_back();\n> +\t\t}\n> +\t\treturn nullptr;\n> +\t}\n> +\tif (cache_miss)\n> +\t\tegl_.createTexture2D(*eglImageIn, inMapped->value().planes()[0].data());\n> +\telse\n> +\t\tegl_.updateTexture2D(*eglImageIn, inMapped->value().planes()[0].data());\n> +\n> +\treturn eglImageIn;\n> +}\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> +eGLImage *DebayerEGL::getCachedOutputFrameBuffer(FrameBuffer *output)\n> +{\n> +\tconst SharedFD &fd = output->planes()[0].fd;\n> +\tbool cache_miss = true;\n> +\teGLImage *eglImageOut;\n> +\n> +\tfor (auto &[ifd, img] : eglImageOutCache_) {\n> +\t\tif (ifd == fd) {\n> +\t\t\teglImageOut = img.get();\n> +\t\t\tcache_miss = false;\n> +\t\t\tbreak;\n> +\t\t}\n>   \t}\n>   \n> -\t/* Otherwise create texture for input buffer via upload from CPU */\n> -\tif (!dmabuf_import_succeeded) {\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> +\tif (cache_miss) {\n> +\t\tif (eglImageOutCache_.size() >= outputBufferCount_) {\n> +\t\t\teglImageOutCache_.pop_front();\n> +\t\t\tLOG(Debayer, Debug) << \"Output cache \" << outputBufferCount_ << \" exceeded evicted entry\";\n> +\t\t}\n> +\n> +\t\teglImageOutCache_.emplace_back(fd, std::make_unique<eGLImage>(GL_RGBA, outputSize_.width,\n> +\t\t\t\t\t       outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1));\n> +\t\teglImageOut = eglImageOutCache_.back().second.get();\n> +\n> +\t\tif (egl_.createOutputDMABufTexture2D(*eglImageOut, output->planes()[0].fd.get())) {\n> +\t\t\teglImageOutCache_.pop_back();\n> +\t\t\treturn nullptr;\n>   \t\t}\n> -\t\tegl_.createTexture2D(*eglImageBayerIn_, 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 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> +\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 +688,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> +\teglImageOutCache_.clear();\n> +\teglImageInCache_.clear();\n>   \n>   \tif (programId_)\n>   \t\tglDeleteProgram(programId_);\n> diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h\n> index 348d7305b..d6223f3a9 100644\n> --- a/src/libcamera/software_isp/debayer_egl.h\n> +++ b/src/libcamera/software_isp/debayer_egl.h\n> @@ -9,6 +9,7 @@\n>   \n>   #pragma once\n>   \n> +#include <deque>\n>   #include <memory>\n>   #include <stdint.h>\n>   #include <tuple>\n> @@ -68,14 +69,19 @@ 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::deque<std::pair<SharedFD, std::unique_ptr<eGLImage>>> eglImageInCache_;\n> +\tstd::deque<std::pair<SharedFD, std::unique_ptr<eGLImage>>> eglImageOutCache_;\n> +\tunsigned int inputBufferCount_;\n> +\tunsigned int outputBufferCount_;\n>   \n>   \t/* Shader parameters */\n>   \tfloat firstRed_x_;","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 C6719C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Jul 2026 07:35:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C315B66058;\n\tTue,  7 Jul 2026 09:35:22 +0200 (CEST)","from sender4-op-o12.zoho.com (sender4-op-o12.zoho.com\n\t[136.143.188.12])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 714FA65FA2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Jul 2026 09:35:20 +0200 (CEST)","by mx.zohomail.com with SMTPS id 1783409714182183.81419775210725; \n\tTue, 7 Jul 2026 00:35:14 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=collabora.com\n\theader.i=robert.mader@collabora.com header.b=\"AHsCB1F6\"; \n\tdkim-atps=neutral","ARC-Seal":"i=1; a=rsa-sha256; t=1783409716; cv=none; \n\td=zohomail.com; s=zohoarc; \n\tb=lBNnVTvP4eiXqysrBjQ8rbI1wC2by1mEbd1hN1aSs9SkxYLxZFhj0gg99bKEo/Lcb2o+W2mgiJYEMuLOXHXxFDNZVDv8eGAzSB9wDkWtzNWcBFhUaiNLDwC/hBI97CcXddeIeBu+o4SNIVqFwelGifG1N34dKHd9miFFjbJ/t3k=","ARC-Message-Signature":"i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; \n\ts=zohoarc; t=1783409716;\n\th=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To:Cc;\n\tbh=ZWFlPMeGFSm1PEISXbwhp2QMp7UuYA7k3Len2ejdqCk=; \n\tb=M5019gSe0/B2qoGFINRs7dPY82VIL++pS5YQLFlBbczRz2ePrSYtvOVWAUcSNiMNkQNpKqxoQwD/tMHHXoo6y7hhq8gkGo1gDWpRj+ACzBoOSxiBwHhwU/+lxzmeR7kTXad/YVNvzyNaaph0J/ahzOlR78PIu5HpQtvnsqZZW6c=","ARC-Authentication-Results":"i=1; mx.zohomail.com;\n\tdkim=pass  header.i=collabora.com;\n\tspf=pass  smtp.mailfrom=robert.mader@collabora.com;\n\tdmarc=pass header.from=<robert.mader@collabora.com>","DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1783409716;\n\ts=zohomail; d=collabora.com; i=robert.mader@collabora.com;\n\th=Message-ID:Date:Date:MIME-Version:Subject:Subject:To:To:References:From:From:In-Reply-To:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To:Cc;\n\tbh=ZWFlPMeGFSm1PEISXbwhp2QMp7UuYA7k3Len2ejdqCk=;\n\tb=AHsCB1F6JGjb772/Boi3Z1pEBPhbH/pEFZd/Qa5ImLow1ZEzure2WlHKeW7zFD7K\n\tqfux6goAussWKsqoWTS93pMGCV4IAExYdB0B9oF6IdoFe4a8Rj/UqeKEmTDbqnxEnl8\n\tll7qw6V39XsotCKa1EJuJlzZWQJRoDaUSoExKpUU=","Message-ID":"<94ce44c9-4dad-4af8-8d8f-7d452ec97aec@collabora.com>","Date":"Tue, 7 Jul 2026 09:35:11 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v6 6/6] libcamera: software_isp: debayer_egl: Implement\n\tinput/output frame caching mechanism","To":"libcamera-devel@lists.libcamera.org","References":"<20260706222245.247396-1-bryan.odonoghue@linaro.org>\n\t<20260706222245.247396-7-bryan.odonoghue@linaro.org>","Content-Language":"en-US, de-DE","From":"Robert Mader <robert.mader@collabora.com>","In-Reply-To":"<20260706222245.247396-7-bryan.odonoghue@linaro.org>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>"}},{"id":39627,"web_url":"https://patchwork.libcamera.org/comment/39627/","msgid":"<857bn6y21h.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2026-07-07T20:31:38","subject":"Re: [PATCH v6 6/6] libcamera: software_isp: debayer_egl: Implement\n\tinput/output frame caching mechanism","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes:\n\n> Implement a texture caching mechanism for both input and output frames and\n> for both types of input frame.\n>\n> The before/after on a Qualcomm x1e is:\n>\n> 9.737ms per frame\n> 5.691ms per frame\n>\n> The before/after on a Qualcomm sm8250 is:\n>\n> 21.710ms per frame\n> 17.336ms per frame\n>\n> for i in {1..20} do\n> cam -c /base/soc@0/cci@ac16000/i2c-bus@1/camera@10 -s width=1920,height=1080 --capture=60\n>\n> Interestingly there appears to be an absolute ~ 4.x ms per frame uplift as\n> opposed to what intuition might suggest a proportional.\n\nThere seems to be a slight difference on RPi 4 too, ~3 ms of 170-175 ms\nwith 3840x2464, ~1 ms of ~40 ms with 1916x1080.\n\n> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n\nLooks plausible AFAICS:\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  src/libcamera/software_isp/debayer_egl.cpp | 125 ++++++++++++++++-----\n>  src/libcamera/software_isp/debayer_egl.h   |  10 +-\n>  2 files changed, 104 insertions(+), 31 deletions(-)\n>\n> diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\n> index c3a7b7952..a7cca5dde 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,106 @@ 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> +\tconst SharedFD &fd = input->planes()[0].fd;\n> +\tbool cache_miss = true;\n> +\teGLImage *eglImageIn;\n> +\n> +\tfor (auto &[ifd, img] : eglImageInCache_) {\n> +\t\tif (ifd == fd) {\n> +\t\t\teglImageIn = img.get();\n> +\t\t\tcache_miss = false;\n> +\t\t\tbreak;\n> +\t\t}\n> +\t}\n>  \n> -\t/* eGL context switch */\n> -\tegl_.makeCurrent();\n> +\tif (cache_miss) {\n> +\t\tif (eglImageInCache_.size() >= inputBufferCount_) {\n> +\t\t\teglImageInCache_.pop_front();\n> +\t\t\tLOG(Debayer, Debug) << \"Input cache \" << inputBufferCount_ << \" exceeded evicted entry\";\n> +\t\t}\n> +\n> +\t\teglImageInCache_.emplace_back(fd, std::make_unique<eGLImage>(glFormat_, inputConfig_.stride / bytesPerPixel_, height_, inputConfig_.stride, GL_TEXTURE0, 0));\n> +\t\teglImageIn = eglImageInCache_.back().second.get();\n> +\n> +\t\tif (egl_.createInputDMABufTexture2D(*eglImageIn, input->planes()[0].fd.get()) == 0)\n> +\t\t\treturn eglImageIn;\n> +\n> +\t} else if (!eglImageIn->dmabuf_import_failed_) {\n> +\t\tegl_.activateBindTexture(*eglImageIn);\n> +\t\treturn eglImageIn;\n> +\t}\n> +\n> +\t/* DMA mode fail create/update an existing texture using the slow path */\n> +\tinDmaSyncer->emplace(input->planes()[0].fd, DmaSyncer::SyncType::Read);\n> +\tinMapped->emplace(input, MappedFrameBuffer::MapFlag::Read);\n> +\tif (!inMapped->value().isValid()) {\n> +\t\tLOG(Debayer, Error) << \"mmap-ing buffer(s) failed\";\n> +\t\tif (cache_miss) {\n> +\t\t\teglImageInCache_.pop_back();\n> +\t\t}\n> +\t\treturn nullptr;\n> +\t}\n> +\tif (cache_miss)\n> +\t\tegl_.createTexture2D(*eglImageIn, inMapped->value().planes()[0].data());\n> +\telse\n> +\t\tegl_.updateTexture2D(*eglImageIn, inMapped->value().planes()[0].data());\n> +\n> +\treturn eglImageIn;\n> +}\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> +eGLImage *DebayerEGL::getCachedOutputFrameBuffer(FrameBuffer *output)\n> +{\n> +\tconst SharedFD &fd = output->planes()[0].fd;\n> +\tbool cache_miss = true;\n> +\teGLImage *eglImageOut;\n> +\n> +\tfor (auto &[ifd, img] : eglImageOutCache_) {\n> +\t\tif (ifd == fd) {\n> +\t\t\teglImageOut = img.get();\n> +\t\t\tcache_miss = false;\n> +\t\t\tbreak;\n> +\t\t}\n>  \t}\n>  \n> -\t/* Otherwise create texture for input buffer via upload from CPU */\n> -\tif (!dmabuf_import_succeeded) {\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> +\tif (cache_miss) {\n> +\t\tif (eglImageOutCache_.size() >= outputBufferCount_) {\n> +\t\t\teglImageOutCache_.pop_front();\n> +\t\t\tLOG(Debayer, Debug) << \"Output cache \" << outputBufferCount_ << \" exceeded evicted entry\";\n> +\t\t}\n> +\n> +\t\teglImageOutCache_.emplace_back(fd, std::make_unique<eGLImage>(GL_RGBA, outputSize_.width,\n> +\t\t\t\t\t       outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1));\n> +\t\teglImageOut = eglImageOutCache_.back().second.get();\n> +\n> +\t\tif (egl_.createOutputDMABufTexture2D(*eglImageOut, output->planes()[0].fd.get())) {\n> +\t\t\teglImageOutCache_.pop_back();\n> +\t\t\treturn nullptr;\n>  \t\t}\n> -\t\tegl_.createTexture2D(*eglImageBayerIn_, 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 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> +\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 +688,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> +\teglImageOutCache_.clear();\n> +\teglImageInCache_.clear();\n>  \n>  \tif (programId_)\n>  \t\tglDeleteProgram(programId_);\n> diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h\n> index 348d7305b..d6223f3a9 100644\n> --- a/src/libcamera/software_isp/debayer_egl.h\n> +++ b/src/libcamera/software_isp/debayer_egl.h\n> @@ -9,6 +9,7 @@\n>  \n>  #pragma once\n>  \n> +#include <deque>\n>  #include <memory>\n>  #include <stdint.h>\n>  #include <tuple>\n> @@ -68,14 +69,19 @@ 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::deque<std::pair<SharedFD, std::unique_ptr<eGLImage>>> eglImageInCache_;\n> +\tstd::deque<std::pair<SharedFD, std::unique_ptr<eGLImage>>> eglImageOutCache_;\n> +\tunsigned int inputBufferCount_;\n> +\tunsigned int outputBufferCount_;\n>  \n>  \t/* Shader parameters */\n>  \tfloat firstRed_x_;","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 BF9B9C3264\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Jul 2026 20:31:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DC1C36606D;\n\tTue,  7 Jul 2026 22:31:48 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D3F91658BF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Jul 2026 22:31:46 +0200 (CEST)","from mail-wm1-f72.google.com (mail-wm1-f72.google.com\n\t[209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-661-eLFY023KMTWr8guuob5Exg-1; Tue, 07 Jul 2026 16:31:44 -0400","by mail-wm1-f72.google.com with SMTP id\n\t5b1f17b1804b1-493a7fa8481so7111075e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 07 Jul 2026 13:31:43 -0700 (PDT)","from mzamazal-thinkpadp1gen7.tpbc.csb\n\t(ip-77-48-47-4.net.vodafone.cz. [77.48.47.4])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-47aa039af67sm42473020f8f.17.2026.07.07.13.31.41\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 07 Jul 2026 13:31:41 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"edJuEyBz\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1783456305;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=RCrhNzDsNxYDsZY9Ju39/GDNSfCyy8y3LaYt/F4YI3I=;\n\tb=edJuEyBzUd0evtT/EmOQE7OA4UuuolVflken82CNmyiNPYg8UcUV7r8jSwfgPJSmEDZLe/\n\tG9vm+9xTUAXC4mDjVljTXZx2utlGwF/HURyPSuPzybhyV7pxLGt8mY627UHwykuQ+Oa04L\n\tvDOb7EXWIX+ABIJs8TcQKJdfpY4S1BY=","X-MC-Unique":"eLFY023KMTWr8guuob5Exg-1","X-Mimecast-MFC-AGG-ID":"eLFY023KMTWr8guuob5Exg_1783456303","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1783456303; x=1784061103;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject\n\t:date:message-id:reply-to;\n\tbh=RCrhNzDsNxYDsZY9Ju39/GDNSfCyy8y3LaYt/F4YI3I=;\n\tb=FxV4alBu5mUvj6z9aOUUakZhsv+gLOPGVBFiIQ69+T/plfm3qip6B612+4nu1vrc3P\n\thT36JRVfh56MXRt7TDBcHWlrpuF5r8bJNaYwWZKt02LqPRx4xp8gmAWoNGYE9n6KglgH\n\t60lCG82z0Z8391pb/UYxMaMoazNBKibG41yU2JNqmxtLDbSBIHXUGHY9bch8fpe00W+I\n\tGgDz6SeNfFX4WHVgoX8IipOJPSY6D0bCuKUo8Zv+btXhs4+XtD7oJlpPKid9TPqFlNPi\n\t6wfHYFOpcDEHMx93SCPqviyq1mOSw7prma5Q24KOkWBwW4eHMnOshs8JVBCkT3IufWKg\n\tx2tg==","X-Gm-Message-State":"AOJu0YxnN/0wbuPLkyjKkbnkYQAVEviduAgKWfqhNE7T77KTOL3A8Zqe\n\ttawsasHpiNcGAtTtsWpYq6Ng+I4eGmiRAaX6gprGr5mOBZc64tcQDwDz/AEbPeXZdsMc77NQf7+\n\tgweQWSQb+n78MNe9aDbS80GehRNri8XJOfLcaszv6tQ4YVjxoP0ecERpR8WyvZnHAqp2MJTPRiW\n\tc=","X-Gm-Gg":"AfdE7cmx+N5m6xDji/6OJ58NHku+9kUy7nVXb/6bIHi3BKyj0DpEgbiI6cYPHEJDlUO\n\tRxdyv7HxkQqBRX/jXj1amRWmtlYsEV/rmtsQDb8fpAmhpPGLdP6mZ0jq5rjdQaHlAFHRlXRu1fu\n\tYQZog7WKlHGjv1rnsTT8rrncrcjN5qP7BBreHxco12dZwyT0t3pR0nxLmE/j4njHS5KBcZH9ZL8\n\tkW15ieZx6/6eu3WLB0afPoU9ZWgEWBfTQZ0ssJU6DkyGgfYQ3nzo6wjo38DpzZi5b+tFDhR8usd\n\tvrIOKyx8wOUx0U357pyoS8gZA07RDajR5q21wziZ9uPX10is/df2aIxNE1Z71Mv/bVYtyY7udFo\n\tcf11RCaQi42uppQqemhL4pt2HDZc9RAh8vOAatvJbAHpfB744GU4YA9yyZSOBMobY","X-Received":["by 2002:a05:6000:258a:b0:464:fff6:489a with SMTP id\n\tffacd0b85a97d-47de97d614cmr5961383f8f.6.1783456302835; \n\tTue, 07 Jul 2026 13:31:42 -0700 (PDT)","by 2002:a05:6000:258a:b0:464:fff6:489a with SMTP id\n\tffacd0b85a97d-47de97d614cmr5961367f8f.6.1783456302447; \n\tTue, 07 Jul 2026 13:31:42 -0700 (PDT)"],"From":"Milan Zamazal <mzamazal@redhat.com>","To":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Cc":"libcamera-devel@lists.libcamera.org,  pavel@ucw.cz","Subject":"Re: [PATCH v6 6/6] libcamera: software_isp: debayer_egl: Implement\n\tinput/output frame caching mechanism","In-Reply-To":"<20260706222245.247396-7-bryan.odonoghue@linaro.org> (Bryan\n\tO'Donoghue's message of \"Mon, 6 Jul 2026 23:22:45 +0100\")","References":"<20260706222245.247396-1-bryan.odonoghue@linaro.org>\n\t<20260706222245.247396-7-bryan.odonoghue@linaro.org>","Date":"Tue, 07 Jul 2026 22:31:38 +0200","Message-ID":"<857bn6y21h.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"krrs4V7ZDB_rYz0De7168HcICzve6CKoZgQ2xL9J9w0_1783456303","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>"}}]