From patchwork Thu Jun 18 12:22:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 26963 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9A7CFC3338 for ; Thu, 18 Jun 2026 12:23:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E754E656E3; Thu, 18 Jun 2026 14:23:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="VM7Z0FcQ"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 15843656C4 for ; Thu, 18 Jun 2026 14:23:21 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-490ae94a89eso6315175e9.1 for ; Thu, 18 Jun 2026 05:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1781785400; x=1782390200; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PAemZUMSTf1dCHeubdqFLgMjI0YFMUlFc/W87+NWYEI=; b=VM7Z0FcQnq9kcqs41MC3Ncjfnkbmimb58hUY1O3VMspqHEbm9NM42jbrGOcKuwBAbo ssbykuTPQG19U7Vm4Kh/7qIyIBnFJiFGBBs8sRzRbjdXRUPd+OnzpYn9h8Jw4I+YisKO dFPU/LhcIyyjabai1HoOB9/eb12c4hdAdNL7gch0HMnUaHjuFgxKVnezmQm8Q70sNmhe /rBg6phfPFT1yZiYnFscPC2RHwA4jJw1vDfoNsqcBdqy2pp5mv3TEmMmO9Wqwd1D/tKJ c1FsBmc37pLaxiEA3ttYf48VlHUGR1Tgotcg0HlnW7q7KA2WOThwDd6PgEeW8gN6bjea J85Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781785400; x=1782390200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PAemZUMSTf1dCHeubdqFLgMjI0YFMUlFc/W87+NWYEI=; b=rQr9qPQxoBhpcsZcluv2eS3ja/tss9YbSEjuDMcy+zF5gijhN991QxZPH4EDffNVya 3F2TEUAUMQ6fnYp3+vU9pxYb00TK6bNzzzRw/dF+8nQbUA35+f/5EzZSLzNwAUFViVRR z59sx05sxKDwLqU0WCMl+XF3AwMS6LW5wP6AaWhOBCJVPpdIAf7yB+7F9iPR8+PJqRki 0HTq8LlGWglh77RODWjSLj1YSPB/u19IlYtirGRsdWcXNVzVls0vnlbeDPm2Bgqwdt6c 25zqybK0cmjbYxRTjZ4kmRgKojsCsHGVCfq/QfQXIWnrFEFrDDlG64NnDivkU4VvCI4P eTLw== X-Gm-Message-State: AOJu0Yy2cPU3kji8cjQ65PE+FiVQlDrQdmZs9TDstqNTm21q9VQfbrQY rZtJkXIPLu5Ldvs4D0dcv+03M3nE3KSmTpKdnmz5/sT3smKljHzrbmb+bn0z7RclwCcF4H+EC6D L6aZh37Y= X-Gm-Gg: AfdE7ck6HTYfQghPHrdLh6luK1MBb5ydH5NjLzkVT1hLwbtzyC4RwsOWFZcD2xUisxW uPJA5R9/dBXv1WG8Cpr/NJ3qrSPhmaQzs9CLh7Nntgw3hms+jK6OslikeWb/zEV2A4WFuOvH7QP fuaCX/5QZZ8qQGOgvb/T7m2Yxk1mGAxQ44WjRNoUoFPQGtGxK37BmVA0gGys0Qm0TkewYzpJp6u aI3s5wNxCa2FMpxy6Io8+8m1+81co0OAlkxONlCxFgU7aPeTT4kexJgMP/gmFCCI2nhAXW7l7xo OwklbRWSKpW+JX5mNaaQp2LyMin4BpDd0+mB5bFi84w02g3gcXNcuA3j9rle9rL1LCAv7HX78PI MnVkxr3NqWQH60mT6OT6pVXDEraPJs6WxOSnhuJ4ywsaPbEp7PdYJpr2lvaILwWBVHPnDIhM8G3 ZGUQyQQDhNxhQ+9EGHZqMjHu6nWf1v X-Received: by 2002:a05:600c:3acd:b0:492:1edf:9fbc with SMTP id 5b1f17b1804b1-492381e4a2cmr48878855e9.1.1781785400445; Thu, 18 Jun 2026 05:23:20 -0700 (PDT) Received: from inspiron14p-linux ([109.76.144.236]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4922fa3a4easm275198015e9.3.2026.06.18.05.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2026 05:23:20 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz Subject: [PATCH 30/30] libcamera: software_isp: gpu: Cache input framebuffers, 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 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Implement a cache of input textures - making one texture for each input FrameBuffer we see. ➜ libcamera git:(0.7.0-multipass-v4) ✗ grep Bench after.log [26:30:50.382000193] [1232323] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 594603us, 19820 us/frame [26:30:57.401535061] [1232356] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 573922us, 19130 us/frame [26:31:00.693007555] [1232386] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 619533us, 20651 us/frame [26:31:04.943431215] [1232415] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 595097us, 19836 us/frame [26:31:08.495371222] [1232444] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 596719us, 19890 us/frame [26:31:14.057239566] [1232479] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 586299us, 19543 us/frame [26:31:18.201198235] [1232509] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 639572us, 21319 us/frame [26:31:21.971954439] [1232539] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 610732us, 20357 us/frame [26:31:25.391881496] [1232574] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 596533us, 19884 us/frame [26:31:29.887852761] [1232603] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 552319us, 18410 us/frame ➜ libcamera git:(0.7.0-multipass-v4) ✗ grep Bench before.log [26:32:12.443884778] [1232907] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 591871us, 19729 us/frame [26:32:21.394113992] [1232943] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 634355us, 21145 us/frame [26:32:24.923236983] [1232983] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 601128us, 20037 us/frame [26:32:28.173610317] [1233017] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 578252us, 19275 us/frame [26:32:33.265933583] [1233050] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 598317us, 19943 us/frame [26:32:36.590115049] [1233091] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 586617us, 19553 us/frame [26:32:40.014877516] [1233127] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 594843us, 19828 us/frame [26:33:03.293347156] [1233182] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 586804us, 19560 us/frame [26:33:07.471525107] [1233221] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 615955us, 20531 us/frame [26:33:13.015977863] [1233262] INFO Benchmark benchmark.cpp:89 Debayer processed 30 frames in 576757us, 19225 us/frame Signed-off-by: Bryan O'Donoghue --- .../software_isp_pipeline_gpu.cpp | 25 ++++++++++++------- .../software_isp/software_isp_pipeline_gpu.h | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp b/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp index bc5d59575..0bcd4df58 100644 --- a/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp +++ b/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp @@ -244,9 +244,18 @@ int SoftwareIspPipelineGpu::processGPU(FrameBuffer *input, FrameBuffer *output, /* eGL context switch */ egl_.makeCurrent(); + auto [input_cache, input_miss] = eglImageBayerIn_.try_emplace(input); + if (input_miss) { + /* Raw bayer input as texture */ + input_cache->second = std::make_unique(gpuIspShaderPassBlcNormalise_.glFormat_, + inputConfig_.stride / gpuIspShaderPassBlcNormalise_.getBytesPerPixel(), + height_, inputConfig_.stride, GL_TEXTURE0, 0); + } + eGLImage &eglImageBayerIn = *input_cache->second; + /* Try to create texture for input buffer via dmabuf import */ - if (!eglImageBayerIn_->dmabuf_import_failed_) { - if (egl_.createInputDMABufTexture2D(*eglImageBayerIn_, input->planes()[0].fd.get()) == 0) + if (!eglImageBayerIn.dmabuf_import_failed_) { + if (egl_.createInputDMABufTexture2D(eglImageBayerIn, input->planes()[0].fd.get()) == 0) dmabuf_import_succeeded = true; else LOG(Debayer, Info) << "Importing input buffer with DMABuf import failed, falling back to upload"; @@ -260,7 +269,9 @@ int SoftwareIspPipelineGpu::processGPU(FrameBuffer *input, FrameBuffer *output, LOG(Debayer, Error) << "mmap-ing buffer(s) failed"; return -ENODEV; } - egl_.updateInputTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data()); + if (input_miss) + egl_.createInputTexture2D(eglImageBayerIn, NULL); + egl_.updateInputTexture2D(eglImageBayerIn, inMapped->value().planes()[0].data()); } /* Find an existing eglImage in the cache */ @@ -272,7 +283,7 @@ int SoftwareIspPipelineGpu::processGPU(FrameBuffer *input, FrameBuffer *output, } eGLImage &eglImageRGBAOut = *output_cache->second; - pipelineResult = gpuIspShaderPassBlcNormalise_.process(*eglImageBayerIn_, *eglImagePingPong_[0], width_, height_, params); + pipelineResult = gpuIspShaderPassBlcNormalise_.process(eglImageBayerIn, *eglImagePingPong_[0], width_, height_, params); if (pipelineResult) { LOG(Debayer, Error) << "BlcNormalise fail"; return pipelineResult; @@ -370,14 +381,10 @@ int SoftwareIspPipelineGpu::start() initShaderBenchMarks(); - /* Raw bayer input as texture */ - eglImageBayerIn_ = std::make_unique(gpuIspShaderPassBlcNormalise_.glFormat_, inputConfig_.stride / gpuIspShaderPassBlcNormalise_.getBytesPerPixel(), height_, inputConfig_.stride, GL_TEXTURE0, 0); - /* Intermediary ping/pong textures */ eglImagePingPong_[0] = std::make_unique(gpuIspShaderPassDemosiac_.glFormat_, width_, height_, outputConfig_.stride, GL_TEXTURE1, 1); eglImagePingPong_[1] = std::make_unique(gpuIspShaderPassDemosiac_.glFormat_, width_, height_, outputConfig_.stride, GL_TEXTURE2, 2); - egl_.createInputTexture2D(*eglImageBayerIn_, NULL); egl_.createOutputTexture2D(*eglImagePingPong_[0]); egl_.createOutputTexture2D(*eglImagePingPong_[1]); @@ -389,7 +396,7 @@ void SoftwareIspPipelineGpu::stop() eglImageRGBAOut_.clear(); eglImagePingPong_[1].reset(); eglImagePingPong_[0].reset(); - eglImageBayerIn_.reset(); + eglImageBayerIn_.clear(); gpuIspShaderPassDemosiac_.stop(); } diff --git a/src/libcamera/software_isp/software_isp_pipeline_gpu.h b/src/libcamera/software_isp/software_isp_pipeline_gpu.h index 995e84295..e2aceefdc 100644 --- a/src/libcamera/software_isp/software_isp_pipeline_gpu.h +++ b/src/libcamera/software_isp/software_isp_pipeline_gpu.h @@ -67,7 +67,7 @@ private: void printShaderBenchMarks(void); /* Pointer to object representing input texture */ - std::unique_ptr eglImageBayerIn_; + std::unordered_map> eglImageBayerIn_; std::unique_ptr eglImagePingPong_[2]; std::unordered_map> eglImageRGBAOut_;