{"id":25261,"url":"https://patchwork.libcamera.org/api/1.1/patches/25261/?format=json","web_url":"https://patchwork.libcamera.org/patch/25261/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20251127023739.179652-25-bryan.odonoghue@linaro.org>","date":"2025-11-27T02:37:39","name":"[v5,24/24] libcamera: software_isp: lut: Skip calculation lookup tables if gpuIspEnabled is true.","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"d41e5eb8481fc103a2c49de9204e1adfdc672e39","submitter":{"id":175,"url":"https://patchwork.libcamera.org/api/1.1/people/175/?format=json","name":"Bryan O'Donoghue","email":"bryan.odonoghue@linaro.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25261/mbox/","series":[{"id":5617,"url":"https://patchwork.libcamera.org/api/1.1/series/5617/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5617","date":"2025-11-27T02:37:15","name":"Add GLES 2.0 GPUISP to libcamera","version":5,"mbox":"https://patchwork.libcamera.org/series/5617/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25261/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25261/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 23785C32DE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 Nov 2025 02:38:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 97EFF60C6F;\n\tThu, 27 Nov 2025 03:38:37 +0100 (CET)","from mail-wm1-x332.google.com (mail-wm1-x332.google.com\n\t[IPv6:2a00:1450:4864:20::332])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AB18860AC5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Nov 2025 03:38:33 +0100 (CET)","by mail-wm1-x332.google.com with SMTP id\n\t5b1f17b1804b1-477a219dbcaso2595435e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Nov 2025 18:38:33 -0800 (PST)","from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie.\n\t[188.141.3.146]) by smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-4790552c3c9sm58186345e9.0.2025.11.26.18.38.31\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 26 Nov 2025 18:38:32 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"eLStOLLh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1764211113; x=1764815913;\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=24wXGFYfJlCqjSrTdSPnfcrWmHqpLPl1rwQ64/Nr/cU=;\n\tb=eLStOLLhjBRy6rS2yX//f/fQJqg3luyj8d27ELRhQ4n5su0WRVKvhowF7J661XWSXM\n\tS8LMINNPW7hrUTbam9d1jxF25jHC5B+lTwwVhv6cArWN+/88OodRCcKrr8CDOwWI62/i\n\tUojWkAfeJtHGSFKverFSvfbU2g2uWPmRIaHWWRe8qwS5zi5UNn7w9mHVLXYKjNJs7vok\n\tRLCmuU7lXvzaZ73Us09mQ4X6ywrA6PUHCz/i5M+zKgwJupYY8kdkIxW74tdMihvQenvt\n\tPbStImDQ7XfQgJirMTP7mIaw8dui/IREmRXgqcbNTUPhlbf3aqs7K3aWGWUcgUDbvJcY\n\tCEfw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1764211113; x=1764815913;\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=24wXGFYfJlCqjSrTdSPnfcrWmHqpLPl1rwQ64/Nr/cU=;\n\tb=lMRvA6+kUSmf49ttEpJQ7W4RulGoOAYxe5AB6lgYXKw4lvu3giMucPrOyb1586RGZE\n\t9NsdOSaHBfepyNa6RujhPaCe8YL0Li1fsnwyjRGpIr4hhbqxvKmNJ/IdkZJPuvxkvmpm\n\tyIhkKW2NLNu3Qs46FG5wyA6axLWLhz+HernoNFR9VcH9U9xCbT1N2NU+ehP2iZxp/en3\n\tUBUKk39l/WBrxrNEvrjkacCAIUw+5rfHiSkHFNbIiOo19ewJwqGY2bOaoSfglQNYePIn\n\twuJHkmaYg/ubZCRgYykOMFwIpznlJkKufKROJNpuewH5mJWVcAknZfT1m1KXexYqWnPf\n\t4KQA==","X-Gm-Message-State":"AOJu0Yy1+7dwIGffMnU0PXiK0Bk1efvMdtN8H6nLIkxe1XYtqAc1S7FI\n\t+WvnFXuyoFHJm0twicuH/3XfM46/dF1Ff2pYbU5R7pQQkvrWcmMkHJpBoU+XCFaql6sBT65f+6M\n\t7zEbQJdk=","X-Gm-Gg":"ASbGncvdvuRf39e50okUAchnb8OKEa115L5YPUrEXFt07JSE4loPrdh1TNjgckJJ9CX\n\tF5WP7layFXyXaERDMK/NZI2daheGKeAtMvUbtPxcejtGfMB3voj7V1hmDqcWqsVODixIMRqC+XN\n\tffl97E/kVMTzbOj9+yPw+1qSoSk5o83rVhoYatlIAQGFYf2wN96FhUoYPn21kXjdTzd0v5LmxJ8\n\tRNskvYJohuBBRNaUf8hDGQc9hdTUpxBmgp99xiUEnm8q7XtJSu+gPdmkjvV1zsZXScpj7iduJ7f\n\tzJ5u+4VIDLv7uDxvgPWguARFvhxC9em41XWQCBK6JfAf3eqMBnNbSQLiDD9uNTmMpSey9Cr08lw\n\tD6Wbwr1y8yA+zOU+otXAyyGjIa4Uw4P9ENMzGgyCiKk3UHj4yKulwk3QczVxf568llzqdqtpvb8\n\tdyjvgzTckO1p4bWhK/dLFblQXxtwcFy61dpd9HSLPi567z6WMy5sEKio31Qbfm8O6XLIo=","X-Google-Smtp-Source":"AGHT+IGZ4j/tpVqxp8xe6nXiI8C7jsbS/ubjuR2ZPCWLAO9dJIaMM+yCcFxv1dxMlnfVsWXedGBTog==","X-Received":"by 2002:a05:600c:474b:b0:46e:35a0:3587 with SMTP id\n\t5b1f17b1804b1-477c01ee377mr215704155e9.27.1764211113012; \n\tWed, 26 Nov 2025 18:38:33 -0800 (PST)","From":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","To":"libcamera-devel@lists.libcamera.org","Cc":"pavel@ucw.cz,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>","Subject":"[PATCH v5 24/24] libcamera: software_isp: lut: Skip calculation\n\tlookup tables if gpuIspEnabled is true.","Date":"Thu, 27 Nov 2025 02:37:39 +0000","Message-ID":"<20251127023739.179652-25-bryan.odonoghue@linaro.org>","X-Mailer":"git-send-email 2.51.2","In-Reply-To":"<20251127023739.179652-1-bryan.odonoghue@linaro.org>","References":"<20251127023739.179652-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":"On my reference platform Qualcomm RB5 sm8520 the qcam application CPU\noccupancy drops from ~100% to about 95% of a single core so this one change\nsheds aprox 5% CPU usage.\n\nSigned-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n---\n src/ipa/simple/algorithms/lut.cpp | 70 ++++++++++++++++---------------\n 1 file changed, 37 insertions(+), 33 deletions(-)","diff":"diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp\nindex 7f223e812..618219b17 100644\n--- a/src/ipa/simple/algorithms/lut.cpp\n+++ b/src/ipa/simple/algorithms/lut.cpp\n@@ -56,32 +56,34 @@ void Lut::queueRequest(typename Module::Context &context,\n \n void Lut::updateGammaTable(IPAContext &context)\n {\n-\tauto &gammaTable = context.activeState.gamma.gammaTable;\n \tconst auto blackLevel = context.activeState.blc.level;\n-\tconst unsigned int blackIndex = blackLevel * gammaTable.size() / 256;\n \tconst auto contrast = context.activeState.knobs.contrast.value_or(1.0);\n \n-\tconst float divisor = gammaTable.size() - blackIndex - 1.0;\n-\tfor (unsigned int i = blackIndex; i < gammaTable.size(); i++) {\n-\t\tdouble normalized = (i - blackIndex) / divisor;\n-\t\t/* Convert 0..2 to 0..infinity; avoid actual inifinity at tan(pi/2) */\n-\t\tdouble contrastExp = tan(std::clamp(contrast * M_PI_4, 0.0, M_PI_2 - 0.00001));\n-\t\t/* Apply simple S-curve */\n-\t\tif (normalized < 0.5)\n-\t\t\tnormalized = 0.5 * std::pow(normalized / 0.5, contrastExp);\n-\t\telse\n-\t\t\tnormalized = 1.0 - 0.5 * std::pow((1.0 - normalized) / 0.5, contrastExp);\n-\t\tgammaTable[i] = UINT8_MAX *\n-\t\t\t\tstd::pow(normalized, context.configuration.gamma);\n+\tif (!context.gpuIspEnabled) {\n+\t\tauto &gammaTable = context.activeState.gamma.gammaTable;\n+\t\tconst unsigned int blackIndex = blackLevel * gammaTable.size() / 256;\n+\t\tconst float divisor = gammaTable.size() - blackIndex - 1.0;\n+\t\tfor (unsigned int i = blackIndex; i < gammaTable.size(); i++) {\n+\t\t\tdouble normalized = (i - blackIndex) / divisor;\n+\t\t\t/* Convert 0..2 to 0..infinity; avoid actual inifinity at tan(pi/2) */\n+\t\t\tdouble contrastExp = tan(std::clamp(contrast * M_PI_4, 0.0, M_PI_2 - 0.00001));\n+\t\t\t/* Apply simple S-curve */\n+\t\t\tif (normalized < 0.5)\n+\t\t\t\tnormalized = 0.5 * std::pow(normalized / 0.5, contrastExp);\n+\t\t\telse\n+\t\t\t\tnormalized = 1.0 - 0.5 * std::pow((1.0 - normalized) / 0.5, contrastExp);\n+\t\t\tgammaTable[i] = UINT8_MAX *\n+\t\t\t\t\tstd::pow(normalized, context.configuration.gamma);\n+\t\t}\n+\t\t/*\n+\t\t * Due to CCM operations, the table lookup may reach indices below the black\n+\t\t * level. Let's set the table values below black level to the minimum\n+\t\t * non-black value to prevent problems when the minimum value is\n+\t\t * significantly non-zero (for example, when the image should be all grey).\n+\t\t */\n+\t\tstd::fill(gammaTable.begin(), gammaTable.begin() + blackIndex,\n+\t\t\t  gammaTable[blackIndex]);\n \t}\n-\t/*\n-\t * Due to CCM operations, the table lookup may reach indices below the black\n-\t * level. Let's set the table values below black level to the minimum\n-\t * non-black value to prevent problems when the minimum value is\n-\t * significantly non-zero (for example, when the image should be all grey).\n-\t */\n-\tstd::fill(gammaTable.begin(), gammaTable.begin() + blackIndex,\n-\t\t  gammaTable[blackIndex]);\n \n \tcontext.activeState.gamma.blackLevel = blackLevel;\n \tcontext.activeState.gamma.contrast = contrast;\n@@ -134,17 +136,19 @@ void Lut::prepare(IPAContext &context,\n \t\tauto &green = params->greenCcm;\n \t\tauto &blue = params->blueCcm;\n \t\tparams->ccm = ccm;\n-\t\tfor (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) {\n-\t\t\tred[i].r = ccmValue(i, ccm[0][0]);\n-\t\t\tred[i].g = ccmValue(i, ccm[1][0]);\n-\t\t\tred[i].b = ccmValue(i, ccm[2][0]);\n-\t\t\tgreen[i].r = ccmValue(i, ccm[0][1]);\n-\t\t\tgreen[i].g = ccmValue(i, ccm[1][1]);\n-\t\t\tgreen[i].b = ccmValue(i, ccm[2][1]);\n-\t\t\tblue[i].r = ccmValue(i, ccm[0][2]);\n-\t\t\tblue[i].g = ccmValue(i, ccm[1][2]);\n-\t\t\tblue[i].b = ccmValue(i, ccm[2][2]);\n-\t\t\tparams->gammaLut[i] = gammaTable[i / div];\n+\t\tif (!context.gpuIspEnabled) {\n+\t\t\tfor (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) {\n+\t\t\t\tred[i].r = ccmValue(i, ccm[0][0]);\n+\t\t\t\tred[i].g = ccmValue(i, ccm[1][0]);\n+\t\t\t\tred[i].b = ccmValue(i, ccm[2][0]);\n+\t\t\t\tgreen[i].r = ccmValue(i, ccm[0][1]);\n+\t\t\t\tgreen[i].g = ccmValue(i, ccm[1][1]);\n+\t\t\t\tgreen[i].b = ccmValue(i, ccm[2][1]);\n+\t\t\t\tblue[i].r = ccmValue(i, ccm[0][2]);\n+\t\t\t\tblue[i].g = ccmValue(i, ccm[1][2]);\n+\t\t\t\tblue[i].b = ccmValue(i, ccm[2][2]);\n+\t\t\t\tparams->gammaLut[i] = gammaTable[i / div];\n+\t\t\t}\n \t\t}\n \t}\n \n","prefixes":["v5","24/24"]}