From patchwork Fri Dec 12 00:29:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 25539 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 1CDDCBD1F1 for ; Fri, 12 Dec 2025 00:34:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D027E61925; Fri, 12 Dec 2025 01:34:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="N0qJADf+"; dkim-atps=neutral Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F26C06191A for ; Fri, 12 Dec 2025 01:34:37 +0100 (CET) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-7baf61be569so781715b3a.3 for ; Thu, 11 Dec 2025 16:34:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765499676; x=1766104476; 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=0x9sYofuRKBarctBdgKuhUSV0fpuyAnEk7YI+eA7X6s=; b=N0qJADf+pAbtIGAWqHwQz6dhJafgy2ugKOqKOOuseDocugzToWSit+jC92oWIwO3Qx k+1518pgNxjZ5RiLpw2GfRnItU/afI8nr6OiriPo7QybKc5/EE8nR8Cc9KAsgUe1/jgO WJtnTUNvXLQMZlGMGIPwl3m/blZeioEbs1gaIpVrnAvZ8jRIjG2TqyLOlgDIkQivQIS8 B/zWEPNmcQvAZi6ppfpdA8/jZkA2kyWl8o4Kba+CeFLty810sd+iBUeZrXCbYdgPxxMV eByd9yiKCipJOH/A9bPurSe1SfLp6TU90C2IiZhrCrNbHk4QVc9FgmKgcskM7L5wqVZt TFXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765499676; x=1766104476; 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=0x9sYofuRKBarctBdgKuhUSV0fpuyAnEk7YI+eA7X6s=; b=efrs88P9AX0hlFS3hpO62toVfTzfGXLAdM7Vk6t3aOIDpfXFtpX6/F+seIuuplD1MY 2O26puunal1cxxgyRCeeL4z9csM3NGBYHnBa/NL1H6KMoqd3bKqpKW4oCVh2SieyoQug Ai2Yid6N462yF1RrJqhO2g/SrYhhaHaIQpJGkfOW9Oawkui10iymBZ2o2+vQ2OLTvQUZ WYAyqGhkjAfao+KTWV53owPDeCMy/bHYQx2Y4M8mAeMtHfzP/e8EI5kEmNHZKt/mHJZQ pSd4Zv8Jv37zCFXZFWY2uOmgnG7uJGLlW4bIK2V/DuQYHGcZyIJWGrqwVNm1LjzY7DL0 5M8w== X-Gm-Message-State: AOJu0Yz3w1uaixdKSgAzy5tN9eLs6mrE4m9BiWZcdICtZL5iiPXJDIUr kVaTeYN98D/S3atWWX7j8rquskflyVZYLrTgyfqsYjEHkMfoaHBKokffZ3lDhHJxzp0Dlm+MZhr mFX3F X-Gm-Gg: AY/fxX6j40SSIm15JseH6HpJMETyRFXeeMdASMohAuUZiafDaQ8WgPXBL304roddI4P L+Aiwas/d6BoDWO+qomBTzJ7uWi4g7bV6IVZnVEzUhDTDFtWujrSjOLWSROiCC06IvAvY6/lQf5 rOrsI0uCZT+2BEx26Qe6lZIEbw4spRZXSNO1uBA+aE2+QEJ95Hg5WNolBw7W5MvNStX36GxrAMP zA7UMyb1O6+pdHbUVgTyNyOinjgeisrSXZoYKaO5HVAWJeL/tkJY3Ho+aVh9y2lEKsoNswE4P7K l7rzRKMWo4ulxCBkwpT27VGA6zJvX/9vWtQynsa5ZNTP60WZzY8lWfNi2AjHEgeprVsUJ6SOhIK tA6YJab5b40QUCl7kgXkaP3hvcVfI7vlPgPU6FuYELvHs7fOJbDocPK0YtxIYGLdlrBy60/lLi9 oaPr1xVkgUJFP3/DYfDLX4vWgfULac8+OpiDUxXf19anlkvPsso/hKCgVodtK/4fRNBMsjsA== X-Google-Smtp-Source: AGHT+IGUw1KdU7VqkmWHA9in62nj+LUg9oDUHiiMOBlLI6S7XbKMUf4eiFy+vtAOg5BVaG4tnaMPkA== X-Received: by 2002:a05:6a21:e082:b0:366:14ac:8c67 with SMTP id adf61e73a8af0-369affed061mr301899637.61.1765499676289; Thu, 11 Dec 2025 16:34:36 -0800 (PST) Received: from inspiron14p-linux (p99250-ipoefx.ipoe.ocn.ne.jp. [153.246.134.249]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c0c26eb0f6bsm3317282a12.14.2025.12.11.16.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 16:34:35 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Milan Zamazal Subject: [PATCH v8 24/26] libcamera: software_isp: lut: Skip calculation lookup tables if gpuIspEnabled is true Date: Fri, 12 Dec 2025 00:29:35 +0000 Message-ID: <20251212002937.3118-25-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251212002937.3118-1-bryan.odonoghue@linaro.org> References: <20251212002937.3118-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" On my reference platform Qualcomm RB5 sm8520 the qcam application CPU occupancy drops from ~100% to about 95% of a single core so this one change sheds aprox 5% CPU usage. Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- src/ipa/simple/algorithms/lut.cpp | 70 ++++++++++++++++--------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp index 9aaab54f1..adf411768 100644 --- a/src/ipa/simple/algorithms/lut.cpp +++ b/src/ipa/simple/algorithms/lut.cpp @@ -56,32 +56,34 @@ void Lut::queueRequest(typename Module::Context &context, void Lut::updateGammaTable(IPAContext &context) { - auto &gammaTable = context.activeState.gamma.gammaTable; const auto blackLevel = context.activeState.blc.level; - const unsigned int blackIndex = blackLevel * gammaTable.size() / 256; const auto contrast = context.activeState.knobs.contrast.value_or(1.0); - const float divisor = gammaTable.size() - blackIndex - 1.0; - for (unsigned int i = blackIndex; i < gammaTable.size(); i++) { - double normalized = (i - blackIndex) / divisor; - /* Convert 0..2 to 0..infinity; avoid actual inifinity at tan(pi/2) */ - double contrastExp = tan(std::clamp(contrast * M_PI_4, 0.0, M_PI_2 - 0.00001)); - /* Apply simple S-curve */ - if (normalized < 0.5) - normalized = 0.5 * std::pow(normalized / 0.5, contrastExp); - else - normalized = 1.0 - 0.5 * std::pow((1.0 - normalized) / 0.5, contrastExp); - gammaTable[i] = UINT8_MAX * - std::pow(normalized, context.configuration.gamma); + if (!context.gpuIspEnabled) { + auto &gammaTable = context.activeState.gamma.gammaTable; + const unsigned int blackIndex = blackLevel * gammaTable.size() / 256; + const float divisor = gammaTable.size() - blackIndex - 1.0; + for (unsigned int i = blackIndex; i < gammaTable.size(); i++) { + double normalized = (i - blackIndex) / divisor; + /* Convert 0..2 to 0..infinity; avoid actual inifinity at tan(pi/2) */ + double contrastExp = tan(std::clamp(contrast * M_PI_4, 0.0, M_PI_2 - 0.00001)); + /* Apply simple S-curve */ + if (normalized < 0.5) + normalized = 0.5 * std::pow(normalized / 0.5, contrastExp); + else + normalized = 1.0 - 0.5 * std::pow((1.0 - normalized) / 0.5, contrastExp); + gammaTable[i] = UINT8_MAX * + std::pow(normalized, context.configuration.gamma); + } + /* + * Due to CCM operations, the table lookup may reach indices below the black + * level. Let's set the table values below black level to the minimum + * non-black value to prevent problems when the minimum value is + * significantly non-zero (for example, when the image should be all grey). + */ + std::fill(gammaTable.begin(), gammaTable.begin() + blackIndex, + gammaTable[blackIndex]); } - /* - * Due to CCM operations, the table lookup may reach indices below the black - * level. Let's set the table values below black level to the minimum - * non-black value to prevent problems when the minimum value is - * significantly non-zero (for example, when the image should be all grey). - */ - std::fill(gammaTable.begin(), gammaTable.begin() + blackIndex, - gammaTable[blackIndex]); context.activeState.gamma.blackLevel = blackLevel; context.activeState.gamma.contrast = contrast; @@ -134,17 +136,19 @@ void Lut::prepare(IPAContext &context, auto &green = params->greenCcm; auto &blue = params->blueCcm; params->ccm = ccm; - for (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) { - red[i].r = ccmValue(i, ccm[0][0]); - red[i].g = ccmValue(i, ccm[1][0]); - red[i].b = ccmValue(i, ccm[2][0]); - green[i].r = ccmValue(i, ccm[0][1]); - green[i].g = ccmValue(i, ccm[1][1]); - green[i].b = ccmValue(i, ccm[2][1]); - blue[i].r = ccmValue(i, ccm[0][2]); - blue[i].g = ccmValue(i, ccm[1][2]); - blue[i].b = ccmValue(i, ccm[2][2]); - params->gammaLut[i] = gammaTable[i / div]; + if (!context.gpuIspEnabled) { + for (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) { + red[i].r = ccmValue(i, ccm[0][0]); + red[i].g = ccmValue(i, ccm[1][0]); + red[i].b = ccmValue(i, ccm[2][0]); + green[i].r = ccmValue(i, ccm[0][1]); + green[i].g = ccmValue(i, ccm[1][1]); + green[i].b = ccmValue(i, ccm[2][1]); + blue[i].r = ccmValue(i, ccm[0][2]); + blue[i].g = ccmValue(i, ccm[1][2]); + blue[i].b = ccmValue(i, ccm[2][2]); + params->gammaLut[i] = gammaTable[i / div]; + } } }