From patchwork Tue Dec 2 13:45:43 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: 25332 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 C4EEAC3330 for ; Tue, 2 Dec 2025 13:46:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2183860D36; Tue, 2 Dec 2025 14:46:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="HmMP+mUF"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 35E7160F78 for ; Tue, 2 Dec 2025 14:46:27 +0100 (CET) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-47778b23f64so32157985e9.0 for ; Tue, 02 Dec 2025 05:46:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764683186; x=1765287986; 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=St8BDxwP4t/WaFpYmjnDvCofVLPqsqEHtlV+2cA2P1g=; b=HmMP+mUFEbYdy8cqPxMhNgAaxbz4F7hc7TEZqxY2HO7WL/4m2U4zeLKYayAzgtrIfn J6RYFpde6jIA7GaW6FyNH3EYL9xGVlUcfW4UiIG3vpYZWw8BR4pE/qb/1OXT/FCPoouJ 6Zn3CkRFyl/y7uwtRJmGxyA7r2BesQu4UXjfEg0Oc+JSeBqb1jlIipPQnU+omIUh61LS kl7G9C3OnbWTfEDVGOkhLPUJ3YzX6TmVeaXWmrzh6CYfRdauaIr0jAxvSdN79mPPLLhJ ocjIlhqt3B6xiJ/sbHFeWTdPpDUNTF1TJtuXmLY3dBLjxLTXAKX2ZmwzzF677BjS82fc Ew3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764683186; x=1765287986; 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=St8BDxwP4t/WaFpYmjnDvCofVLPqsqEHtlV+2cA2P1g=; b=kr66hEvqPPPgC8PcAJ7pJKSye6UoOwFw0mUsH1k/sQCGWCO+87OyKPSN0mjSwrx+Ij oBymBIePGTt0unFb1Ho2vxCpsqmdOnh5gP4EBZbOPvFDruXo4j9+/2D//GWIPcr8eBd2 c1yxWENPiiPmxKOj2xtezL96mmvHt42+Em4Fl+/bpdcEQh5nfaPcZffXpRAxQ+ONWe63 /gldGZJlk8obRIDjmA6UpHrpYzeQI3JEbV9yCZzKrccrQ/PtZZmz/riTArVcAwTQjGwf /edV+lPaFxJ5dCrcHEgNllumj9Tyw4Xb9md23pialn1iLvnIGJi8s7y5VI+QC0zqxb+R ir0Q== X-Gm-Message-State: AOJu0YzF08wC7H3uNjZTqJJS8RKUe2/bZU40mVH+fOaGvUTrdDqOK4n6 ATdWXuX1DjAXq8hFatN8jR2bqdg1RrcrG9nVrnC+N+wOlnmmwnircvz9eAnQNmVpJwkPgm2Or8g 6v9ln X-Gm-Gg: ASbGncsb5TZKTaKzxvfLN2JRUtRjCCcBYGyMig6Pn/9tMPWYRBWL+hkQyj7MU4AOGOF gvOdrtLj3yQKcgwaJTcMx+TJTBgnTfPCjUURwxRDWgFNTOMtEuIYlk/G5zBi8J12DYc47OoibWs JNK5AeZBor+KGKKdl/rQVnzKJE0UQzJrMnCZXdUDNHEKPMdqOKUSTSXJUg0cCvO/E2gqgmvmc1e tvzACiAgOhl/PIoJ2xJrT+SNYvuvN+HPBjYl3IjHxjyhF1VC6hpyn4l8Y68K/fhHT4aR/XOO+Fv fKXXUEhOYCF0gl80SMQ0GBCcDDyvgIRKq3Kiagm1cW4Z/vSmrGuKiWqGXd15lYzw2bKKtlgyPcp shxjxMhd9cJaFfqcGpr5PorOdCWcBI2dOsQRKoETt3uymv34bi6p9q9SzB6INHrVNHdHV075Iut FilcAFntH5Lh8dKuWQVkCjAvcFJstdSHnmkQk7apvTDvbqa3apFVqNJSBnT30uYfbwFoY= X-Google-Smtp-Source: AGHT+IEfihEi2WV4Rb6i2UrinCmuqFEvrmQhplNCftWhO+XsEoKKHsNDhfMBK633eLOTzkFq3BOFtw== X-Received: by 2002:a05:600c:c492:b0:477:8985:4039 with SMTP id 5b1f17b1804b1-477c1143024mr411348075e9.17.1764683185383; Tue, 02 Dec 2025 05:46:25 -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 5b1f17b1804b1-47926f0ec69sm19383375e9.1.2025.12.02.05.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Dec 2025 05:46:24 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue Subject: [PATCH v6 23/24] libcamera: software_isp: lut: Skip calculation lookup tables if gpuIspEnabled is true. Date: Tue, 2 Dec 2025 13:45:43 +0000 Message-ID: <20251202134544.662446-24-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251202134544.662446-1-bryan.odonoghue@linaro.org> References: <20251202134544.662446-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]; + } } }