[{"id":37208,"web_url":"https://patchwork.libcamera.org/comment/37208/","msgid":"<85ldjjz2nh.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-12-03T21:17:06","subject":"Re: [PATCH v6 23/24] libcamera: software_isp: lut: Skip calculation\n\tlookup tables if gpuIspEnabled is true.","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes:\n\n> On my reference platform Qualcomm RB5 sm8520 the qcam application CPU\n> occupancy drops from ~100% to about 95% of a single core so this one change\n> sheds aprox 5% CPU usage.\n>\n> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n\nNo dot at the end of the commit title.\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  src/ipa/simple/algorithms/lut.cpp | 70 ++++++++++++++++---------------\n>  1 file changed, 37 insertions(+), 33 deletions(-)\n>\n> diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp\n> index 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}","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 A0960BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Dec 2025 21:17:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A7A56610B2;\n\tWed,  3 Dec 2025 22:17:14 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5FD46609D8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Dec 2025 22:17:12 +0100 (CET)","from mail-wr1-f71.google.com (mail-wr1-f71.google.com\n\t[209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-636-14UoxpVvO2aRJMOTmKP75w-1; Wed, 03 Dec 2025 16:17:10 -0500","by mail-wr1-f71.google.com with SMTP id\n\tffacd0b85a97d-42b366a76ffso133653f8f.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 03 Dec 2025 13:17:10 -0800 (PST)","from mzamazal-thinkpadp1gen7.tpbc.csb\n\t(ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-42e1caa5d02sm42130207f8f.36.2025.12.03.13.17.07\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 03 Dec 2025 13:17:07 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"IXaY0/V/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1764796631;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=5KVLiuYmtpHi7RS15rq+0XifvCaggL0BadIKCcXT7M8=;\n\tb=IXaY0/V/ZEt+BgnxrpLgj9KmhyaCWpVLXCMZUOTLu88k09lc5oEmn+QZPQ/7wFl6HCJnpn\n\t1uzar9N+5J2l7bu3+LqrvbDrxumg7UbPEBf6hBX/MYmeuV44fUMhJFeXjhuljMi3D6qu3I\n\t3+yDJb4G2TXBBoK+iwy+uNHXtasBvFk=","X-MC-Unique":"14UoxpVvO2aRJMOTmKP75w-1","X-Mimecast-MFC-AGG-ID":"14UoxpVvO2aRJMOTmKP75w_1764796629","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1764796629; x=1765401429;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject\n\t:date:message-id:reply-to;\n\tbh=5KVLiuYmtpHi7RS15rq+0XifvCaggL0BadIKCcXT7M8=;\n\tb=ieGev1HzO/R9uaxf8SauWXhj9FbLnP3l0pA1DLX7NCh6Drhbz+NYoUJwvaI2IOQenI\n\tNCVD1Wnejn2+t7+hyl1xDrsmLCHeDnhBbR8io1gM7hNCQyauv5RQk5ma8TI7bp81OpQ+\n\tiFseX38hk6I8MaaM+OGvtQednlx5sQyS2kTHX3JIDgwvMpVsqyKBX0ExjqD8fyAUNhWO\n\t0AIYAIJeOIH94iPF4mUGbv8ft0VwGCxXoCtOcRRqRh4EpBm7YurNhb1G6fzlCTg7BX+3\n\tVS7pgYTJERIoIaUpjPcFAY3oMizCXtqIZrb6NnC+0NYXEZ03U44xU+riwuvNMX3+QNeI\n\tteJw==","X-Gm-Message-State":"AOJu0Ywp1d8BqAqNsVC5wIbxToR1LfNRyP40h4FHOerAFXIfNVf8eeIt\n\tMVnvpttqcQfuQK0m/BJf+AjzvK5pkQDHVDdlmz29JYy2EMkCNaD+wNYy8HL42cDOOj5W9Vc5KXu\n\tck4YKS3IOO/bhj74bgp0Cs6VQ0FCrY9y4xNU9Aq+o3tG6tPN4pPFw9PHqyjtD+mbs6paw/9MvpH\n\tL4S1e58Ik=","X-Gm-Gg":"ASbGncvBAPyWf5HI0ZqQSiqJS1k/4KvtXeu1yjmZakUr1I/w4/09RdP2L5C5JvhfRME\n\ta7tFpxuHuRbASt5q3yQTvpfdvUGY7aXFCPuCOocH3/88aOTQ+5HnNFx/w/AbRXYdqp5mTHyUOKv\n\tr918xl3GjDIJGkCaBSvO0efsFPAm8v5/Ehz3B71NVqHRCmkA/fzt9eI+U5+OVl6H25XdIPz7zPO\n\tTPmH6jWJt5BA1rHH8whYuSj3tQ0lKeJV3YNb5q0x/Esp7RoYMeSbnPuu5APZWjAQbFJYKqDpa1o\n\t/gWHydsbs2OcxgYpWBm5RLPBDRUuLfzBWXrP8izM39muoFE+Tj41PvWBtvq94qt78mMTGSVpamj\n\tpp3zy0PvqhfmFK6mW/LBmc4eBeLPprsbHTqmvrdaQJOaYPSpW7Y5l53aYqMQ/Cyc=","X-Received":["by 2002:a05:6000:26ca:b0:429:cd3f:f43a with SMTP id\n\tffacd0b85a97d-42f7980006bmr385695f8f.7.1764796628610; \n\tWed, 03 Dec 2025 13:17:08 -0800 (PST)","by 2002:a05:6000:26ca:b0:429:cd3f:f43a with SMTP id\n\tffacd0b85a97d-42f7980006bmr385680f8f.7.1764796628201; \n\tWed, 03 Dec 2025 13:17:08 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IF8MupcXCgKlPDtcddebQrkiyRxyB3YKq59GTwTVISqFQn8kufDN/u7WYnczHqD0wtPShJltA==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Cc":"libcamera-devel@lists.libcamera.org,  pavel@ucw.cz","Subject":"Re: [PATCH v6 23/24] libcamera: software_isp: lut: Skip calculation\n\tlookup tables if gpuIspEnabled is true.","In-Reply-To":"<20251202134544.662446-24-bryan.odonoghue@linaro.org> (Bryan\n\tO'Donoghue's message of \"Tue, 2 Dec 2025 13:45:43 +0000\")","References":"<20251202134544.662446-1-bryan.odonoghue@linaro.org>\n\t<20251202134544.662446-24-bryan.odonoghue@linaro.org>","Date":"Wed, 03 Dec 2025 22:17:06 +0100","Message-ID":"<85ldjjz2nh.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"PWqVCh3Nb46pVE50GMnGgIMZUD4Fojeellcs5VOTAtw_1764796629","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>"}}]