From patchwork Thu Nov 20 23:33:47 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: 25147 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 B4D72BD80A for ; Thu, 20 Nov 2025 23:34:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 81C0D60BDD; Fri, 21 Nov 2025 00: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="kvvfOO3+"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 886CF60A81 for ; Fri, 21 Nov 2025 00:34:37 +0100 (CET) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-477aa218f20so9457165e9.0 for ; Thu, 20 Nov 2025 15:34:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1763681676; x=1764286476; 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=24wXGFYfJlCqjSrTdSPnfcrWmHqpLPl1rwQ64/Nr/cU=; b=kvvfOO3+gqUyFx3zRC8D6RPBtPPpCM/NbRmguuTRGatba4YDabEaSBVpU1DEUmBBqR jlDgjs50w9k2woivSJRDWs+YI+nfQA0VJC/fPkClLw8jSsmAukujLqCotc7PLtmyjn+5 Jjmx3l31zdfd7b3gty4z0eJG21LrnWseNEL3sBfnUk5QpYECJbgePGmKtD7Wjd8eAj9J J0X4vV2rsYeM0QKkNgl1FA4zKFNmGfWCyBJoeTKYLdYwIxw1w2ojj5vzybyFvb1Yljj3 zKHfHWLr/3ujn7Obsq2rFKIGrkGMd3ZoAhqfEDT3n2A/urHBMnl9UlCs4KS2SedGb5mC REZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763681676; x=1764286476; 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=24wXGFYfJlCqjSrTdSPnfcrWmHqpLPl1rwQ64/Nr/cU=; b=lze1JV7g6Vp1By7pRtIKB5183ASPOiuvYvrgfjvM311HrkCtcQjJAOKHJy1Zo19Tee QfH6om6QhMNK5i+ntWyIoyPukywd8YoDtZtPywuKXQzeItUsCqaU+7B6i5xP8D3Phbwm fmtkbxsoypous+cpCry6RlfFs1GQ0HjFLi3wHZFrSqapFIMXu0mU4XTXwB9vLwWH3D5x He7ypz/ss6Qn59Xexv2d9rFJUzKAZMKIDJfwuvAIFFteoS1eUuizhNY8bIiZjUj5gijY 4h3KDp4WhMYaTtSzRyEh35kpKSefh1ukjo20rPfK2Sj45D1HQP/7eh+avRCS16r/Ml+k SGig== X-Gm-Message-State: AOJu0Yy/9xCrlmEDYxcMwFboYLvFld95/aCVC1H8t58aHwyyl1sQBdM0 ojsVe3efPuRKRR0wMlddaBBLdlsVSVjTk17TbWr+VXxXtKvdSKaOOUgE55h6P5KUkzzNr7j2zEj K88ecIww= X-Gm-Gg: ASbGncsheChv0GHonWcu/v4q5LNTsn/krMHx6CN7hEQiiHx4oWT3aHA5vTG+Suq0Eag Z3jERCFAoAxK/65l9ICLJpw1Xt1wu3YCUB2/3Duaj9W3zLiWaC2unSbKw2kokYHdW5rNBGROPw+ ifZJ99W8GvvMweMvAJXnb7jhkAuPbha0Z3UHCA6GsuBOxAfCPFDkhfXQdH61H4ZeWe7jV2D42mE 4Xgr9w02Zzca/Dw5Z/UxFbzHEF85Fu3XLkUq32B/VWiaJ3BLUzKKvL0apE+CB6TiftxQ9pCsQWF BSvcjk4PuNQe6UppEE2Mt88rZRBlO5wQnMEe91UpJ+evDyi6UuePRvvmLBuUOQpI4glcsQU6Z9f X/G5oHhuTNQ554bLOa3aAu+/jc1axyOfirCZDIPAP+fZUI0J1UJYmqk/McjaaG65v42bRUvkqOW 0l/E4pFYq5q1O1MLPRy9LBsQe0ww3YsHPvtyQFNF4W/PLzxTMni57hwoU1PjjM9SJMjcg= X-Google-Smtp-Source: AGHT+IGA5odhzQMJfqG2PjkGPrl3xueKaJtHABi9J3j/Es6ViwTE+h5HZ8Y85WidHT0xCPjmS9kTAg== X-Received: by 2002:a05:600c:3baa:b0:475:de12:d3b5 with SMTP id 5b1f17b1804b1-477c01ecc7cmr3070765e9.34.1763681676444; Thu, 20 Nov 2025 15:34:36 -0800 (PST) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7fa3a81sm7984139f8f.26.2025.11.20.15.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Nov 2025 15:34:35 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue Subject: [PATCH v4 23/23] libcamera: software_isp: lut: Skip calculation lookup tables if gpuIspEnabled is true. Date: Thu, 20 Nov 2025 23:33:47 +0000 Message-ID: <20251120233347.5046-24-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251120233347.5046-1-bryan.odonoghue@linaro.org> References: <20251120233347.5046-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. 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 7f223e812..618219b17 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]; + } } }