{"id":26963,"url":"https://patchwork.libcamera.org/api/patches/26963/?format=json","web_url":"https://patchwork.libcamera.org/patch/26963/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260618122245.946138-31-bryan.odonoghue@linaro.org>","date":"2026-06-18T12:22:43","name":"[30/30] libcamera: software_isp: gpu: Cache input framebuffers, only do texture creation when required","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e1bb5d48d0f4c755245ff81fc0c507e29f6ddc18","submitter":{"id":175,"url":"https://patchwork.libcamera.org/api/people/175/?format=json","name":"Bryan O'Donoghue","email":"bryan.odonoghue@linaro.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26963/mbox/","series":[{"id":6005,"url":"https://patchwork.libcamera.org/api/series/6005/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=6005","date":"2026-06-18T12:22:13","name":"RFC/RFT: gpuisp: Multipass with speed optimisations on top","version":1,"mbox":"https://patchwork.libcamera.org/series/6005/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26963/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26963/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 9A7CFC3338\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 18 Jun 2026 12:23:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E754E656E3;\n\tThu, 18 Jun 2026 14:23:41 +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 15843656C4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Jun 2026 14:23:21 +0200 (CEST)","by mail-wm1-x334.google.com with SMTP id\n\t5b1f17b1804b1-490ae94a89eso6315175e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Jun 2026 05:23:21 -0700 (PDT)","from inspiron14p-linux ([109.76.144.236])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-4922fa3a4easm275198015e9.3.2026.06.18.05.23.19\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 18 Jun 2026 05:23:20 -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=\"VM7Z0FcQ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1781785400; x=1782390200;\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=PAemZUMSTf1dCHeubdqFLgMjI0YFMUlFc/W87+NWYEI=;\n\tb=VM7Z0FcQnq9kcqs41MC3Ncjfnkbmimb58hUY1O3VMspqHEbm9NM42jbrGOcKuwBAbo\n\tssbykuTPQG19U7Vm4Kh/7qIyIBnFJiFGBBs8sRzRbjdXRUPd+OnzpYn9h8Jw4I+YisKO\n\tdFPU/LhcIyyjabai1HoOB9/eb12c4hdAdNL7gch0HMnUaHjuFgxKVnezmQm8Q70sNmhe\n\t/rBg6phfPFT1yZiYnFscPC2RHwA4jJw1vDfoNsqcBdqy2pp5mv3TEmMmO9Wqwd1D/tKJ\n\tc1FsBmc37pLaxiEA3ttYf48VlHUGR1Tgotcg0HlnW7q7KA2WOThwDd6PgEeW8gN6bjea\n\tJ85Q==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1781785400; x=1782390200;\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=PAemZUMSTf1dCHeubdqFLgMjI0YFMUlFc/W87+NWYEI=;\n\tb=rQr9qPQxoBhpcsZcluv2eS3ja/tss9YbSEjuDMcy+zF5gijhN991QxZPH4EDffNVya\n\t3F2TEUAUMQ6fnYp3+vU9pxYb00TK6bNzzzRw/dF+8nQbUA35+f/5EzZSLzNwAUFViVRR\n\tz59sx05sxKDwLqU0WCMl+XF3AwMS6LW5wP6AaWhOBCJVPpdIAf7yB+7F9iPR8+PJqRki\n\t0HTq8LlGWglh77RODWjSLj1YSPB/u19IlYtirGRsdWcXNVzVls0vnlbeDPm2Bgqwdt6c\n\t25zqybK0cmjbYxRTjZ4kmRgKojsCsHGVCfq/QfQXIWnrFEFrDDlG64NnDivkU4VvCI4P\n\teTLw==","X-Gm-Message-State":"AOJu0Yy2cPU3kji8cjQ65PE+FiVQlDrQdmZs9TDstqNTm21q9VQfbrQY\n\trZtJkXIPLu5Ldvs4D0dcv+03M3nE3KSmTpKdnmz5/sT3smKljHzrbmb+bn0z7RclwCcF4H+EC6D\n\tL6aZh37Y=","X-Gm-Gg":"AfdE7ck6HTYfQghPHrdLh6luK1MBb5ydH5NjLzkVT1hLwbtzyC4RwsOWFZcD2xUisxW\n\tuPJA5R9/dBXv1WG8Cpr/NJ3qrSPhmaQzs9CLh7Nntgw3hms+jK6OslikeWb/zEV2A4WFuOvH7QP\n\tfuaCX/5QZZ8qQGOgvb/T7m2Yxk1mGAxQ44WjRNoUoFPQGtGxK37BmVA0gGys0Qm0TkewYzpJp6u\n\taI3s5wNxCa2FMpxy6Io8+8m1+81co0OAlkxONlCxFgU7aPeTT4kexJgMP/gmFCCI2nhAXW7l7xo\n\tOwklbRWSKpW+JX5mNaaQp2LyMin4BpDd0+mB5bFi84w02g3gcXNcuA3j9rle9rL1LCAv7HX78PI\n\tMnVkxr3NqWQH60mT6OT6pVXDEraPJs6WxOSnhuJ4ywsaPbEp7PdYJpr2lvaILwWBVHPnDIhM8G3\n\tZGUQyQQDhNxhQ+9EGHZqMjHu6nWf1v","X-Received":"by 2002:a05:600c:3acd:b0:492:1edf:9fbc with SMTP id\n\t5b1f17b1804b1-492381e4a2cmr48878855e9.1.1781785400445; \n\tThu, 18 Jun 2026 05:23:20 -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 30/30] libcamera: software_isp: gpu: Cache input\n\tframebuffers, only do texture creation when required","Date":"Thu, 18 Jun 2026 13:22:43 +0100","Message-ID":"<20260618122245.946138-31-bryan.odonoghue@linaro.org>","X-Mailer":"git-send-email 2.54.0","In-Reply-To":"<20260618122245.946138-1-bryan.odonoghue@linaro.org>","References":"<20260618122245.946138-1-bryan.odonoghue@linaro.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","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 cache of input textures - making one texture for each input\nFrameBuffer we see.\n\n➜  libcamera git:(0.7.0-multipass-v4) ✗ grep Bench after.log\n[26:30:50.382000193] [1232323]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 594603us, 19820 us/frame\n[26:30:57.401535061] [1232356]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 573922us, 19130 us/frame\n[26:31:00.693007555] [1232386]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 619533us, 20651 us/frame\n[26:31:04.943431215] [1232415]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 595097us, 19836 us/frame\n[26:31:08.495371222] [1232444]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 596719us, 19890 us/frame\n[26:31:14.057239566] [1232479]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 586299us, 19543 us/frame\n[26:31:18.201198235] [1232509]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 639572us, 21319 us/frame\n[26:31:21.971954439] [1232539]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 610732us, 20357 us/frame\n[26:31:25.391881496] [1232574]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 596533us, 19884 us/frame\n[26:31:29.887852761] [1232603]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 552319us, 18410 us/frame\n\n➜  libcamera git:(0.7.0-multipass-v4) ✗ grep Bench before.log\n[26:32:12.443884778] [1232907]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 591871us, 19729 us/frame\n[26:32:21.394113992] [1232943]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 634355us, 21145 us/frame\n[26:32:24.923236983] [1232983]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 601128us, 20037 us/frame\n[26:32:28.173610317] [1233017]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 578252us, 19275 us/frame\n[26:32:33.265933583] [1233050]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 598317us, 19943 us/frame\n[26:32:36.590115049] [1233091]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 586617us, 19553 us/frame\n[26:32:40.014877516] [1233127]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 594843us, 19828 us/frame\n[26:33:03.293347156] [1233182]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 586804us, 19560 us/frame\n[26:33:07.471525107] [1233221]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 615955us, 20531 us/frame\n[26:33:13.015977863] [1233262]  INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 576757us, 19225 us/frame\n\nSigned-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n---\n .../software_isp_pipeline_gpu.cpp             | 25 ++++++++++++-------\n .../software_isp/software_isp_pipeline_gpu.h  |  2 +-\n 2 files changed, 17 insertions(+), 10 deletions(-)","diff":"diff --git a/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp b/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp\nindex bc5d59575..0bcd4df58 100644\n--- a/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp\n+++ b/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp\n@@ -244,9 +244,18 @@ int SoftwareIspPipelineGpu::processGPU(FrameBuffer *input, FrameBuffer *output,\n \t/* eGL context switch */\n \tegl_.makeCurrent();\n \n+\tauto [input_cache, input_miss] = eglImageBayerIn_.try_emplace(input);\n+\tif (input_miss) {\n+\t\t/* Raw bayer input as texture */\n+\t\tinput_cache->second = std::make_unique<eGLImage>(gpuIspShaderPassBlcNormalise_.glFormat_,\n+\t\t\t\t\t\t\t\t inputConfig_.stride / gpuIspShaderPassBlcNormalise_.getBytesPerPixel(),\n+\t\t\t\t\t\t\t\t height_, inputConfig_.stride, GL_TEXTURE0, 0);\n+\t}\n+\teGLImage &eglImageBayerIn = *input_cache->second;\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+\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@@ -260,7 +269,9 @@ int SoftwareIspPipelineGpu::processGPU(FrameBuffer *input, FrameBuffer *output,\n \t\t\tLOG(Debayer, Error) << \"mmap-ing buffer(s) failed\";\n \t\t\treturn -ENODEV;\n \t\t}\n-\t\tegl_.updateInputTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data());\n+\t\tif (input_miss)\n+\t\t\tegl_.createInputTexture2D(eglImageBayerIn, NULL);\n+\t\tegl_.updateInputTexture2D(eglImageBayerIn, inMapped->value().planes()[0].data());\n \t}\n \n \t/* Find an existing eglImage in the cache */\n@@ -272,7 +283,7 @@ int SoftwareIspPipelineGpu::processGPU(FrameBuffer *input, FrameBuffer *output,\n \t}\n \teGLImage &eglImageRGBAOut = *output_cache->second;\n \n-\tpipelineResult = gpuIspShaderPassBlcNormalise_.process(*eglImageBayerIn_, *eglImagePingPong_[0], width_, height_, params);\n+\tpipelineResult = gpuIspShaderPassBlcNormalise_.process(eglImageBayerIn, *eglImagePingPong_[0], width_, height_, params);\n \tif (pipelineResult) {\n \t\tLOG(Debayer, Error) << \"BlcNormalise fail\";\n \t\treturn pipelineResult;\n@@ -370,14 +381,10 @@ int SoftwareIspPipelineGpu::start()\n \n \tinitShaderBenchMarks();\n \n-\t/* Raw bayer input as texture */\n-\teglImageBayerIn_ = std::make_unique<eGLImage>(gpuIspShaderPassBlcNormalise_.glFormat_, inputConfig_.stride / gpuIspShaderPassBlcNormalise_.getBytesPerPixel(), height_, inputConfig_.stride, GL_TEXTURE0, 0);\n-\n \t/* Intermediary ping/pong textures */\n \teglImagePingPong_[0] = std::make_unique<eGLImage>(gpuIspShaderPassDemosiac_.glFormat_, width_, height_, outputConfig_.stride, GL_TEXTURE1, 1);\n \teglImagePingPong_[1] = std::make_unique<eGLImage>(gpuIspShaderPassDemosiac_.glFormat_, width_, height_, outputConfig_.stride, GL_TEXTURE2, 2);\n \n-\tegl_.createInputTexture2D(*eglImageBayerIn_, NULL);\n \tegl_.createOutputTexture2D(*eglImagePingPong_[0]);\n \tegl_.createOutputTexture2D(*eglImagePingPong_[1]);\n \n@@ -389,7 +396,7 @@ void SoftwareIspPipelineGpu::stop()\n \teglImageRGBAOut_.clear();\n \teglImagePingPong_[1].reset();\n \teglImagePingPong_[0].reset();\n-\teglImageBayerIn_.reset();\n+\teglImageBayerIn_.clear();\n \n \tgpuIspShaderPassDemosiac_.stop();\n }\ndiff --git a/src/libcamera/software_isp/software_isp_pipeline_gpu.h b/src/libcamera/software_isp/software_isp_pipeline_gpu.h\nindex 995e84295..e2aceefdc 100644\n--- a/src/libcamera/software_isp/software_isp_pipeline_gpu.h\n+++ b/src/libcamera/software_isp/software_isp_pipeline_gpu.h\n@@ -67,7 +67,7 @@ private:\n \tvoid printShaderBenchMarks(void);\n \n \t/* Pointer to object representing input texture */\n-\tstd::unique_ptr<eGLImage> eglImageBayerIn_;\n+\tstd::unordered_map<FrameBuffer *, std::unique_ptr<eGLImage>> eglImageBayerIn_;\n \tstd::unique_ptr<eGLImage> eglImagePingPong_[2];\n \tstd::unordered_map<FrameBuffer *, std::unique_ptr<eGLImage>> eglImageRGBAOut_;\n \n","prefixes":["30/30"]}