From patchwork Tue Sep 30 15:04:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 24533 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 72769C328C for ; Tue, 30 Sep 2025 15:04:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EF8836B5F0; Tue, 30 Sep 2025 17:04:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="aITFf9wQ"; dkim-atps=neutral Received: from tor.source.kernel.org (tor.source.kernel.org [IPv6:2600:3c04:e001:324:0:1991:8:25]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 197EE62C35 for ; Tue, 30 Sep 2025 17:04:34 +0200 (CEST) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id C0EAA62392 for ; Tue, 30 Sep 2025 15:04:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA774C116C6; Tue, 30 Sep 2025 15:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759244672; bh=JtmL/i/cz9TgKfkCs1cXAc2A0qBkCFiQHQcJTWvKDpE=; h=From:To:Cc:Subject:Date:From; b=aITFf9wQhv15QTg7BIRqY7uBbJZjXvVuINvoyVghXW1FDH2d6GKoBkkhPBHPnl9PE sTubgMY0ffnIAUxXBAnBQezvW/YZkUdVJk5cNdc6Y80Tt+qI812A3MjwELV72ALop6 YfJTXRdeH1Ql+g3zfwjQs6tuaUR60qpdmbiAfsda69GG8NhG1HNByfSaGwpf2WMsfu LS4eNXbKJ+8KL+pSqfsRuSAWcYBCvaNsO8Zdrv1NcmRMC1pQf4o+u5Yh0tjZ0gEECx lRE3xr4ChRo/B97I1A4u6MzUnZpYySAgweYCPDXNYZaJW5ImnECzKigfSZ+cAeLgTS xLcZky9alh3NQ== From: Hans de Goede To: libcamera-devel@lists.libcamera.org Cc: Hans de Goede Subject: [PATCH v4 0/6] ipa: software_isp: AGC: Fix AGC oscillation bug Date: Tue, 30 Sep 2025 17:04:22 +0200 Message-ID: <20250930150428.11101-1-hansg@kernel.org> X-Mailer: git-send-email 2.51.0 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" Hi All, Due to a combination of not having correct control-delay information for various sensors as well as the generic nature of the simple-pipeline + software-ISP meaning that any pipeline delays are unknown it is impossible to get reliable control-delay values. Wrong control-delay values can lead to pretty bad oscilation. See the v1 cover-letter for more details. This series fixes some unrelated issues in the softIPA AGC algorithm and in the last 2 patches addresses the oscillation issue. Note v2 and later take a new approach to fixing the oscilation by only generating statistics for every 4th frame and having the IPA only run its algorithms when there actually are statistics. This saves CPU time, while at the same time avoiding the oscillation issue. v4 has successfully passed CI, see: https://gitlab.freedesktop.org/camera/libcamera-softisp/-/commit/e749d265ff6ec85752198dc1ab23ef2a42ab36af/pipelines?ref=softisp-agc-oscillation-fixes-v4 Changes in v4: - AGC: Add an empty line after the agc substruct declaration - AGC: Init active-state agc gain and exposue from sensor values in case updateExposure() does not run for the first frame - SwStats: Document why to skip 3 frames / why once every 4 frames - Pass frame number to SwStatsCpu::startFrame() SwStatsCpu::processLine?() and move all skipping handling to inside the SwStatsCpu class Changes in v3: - Drop if (!stats_->valid) early exit from IPASoftSimple::processStats() - Save last AGC calculated new gain and exposure values and re-use these for frames without statistics, this avoids delayedCtrl history underruns - Improve SwIspStats.valid documentation Changes in v2: - Skip running IPA algorithms when there are no statistics - Only generate statistics for every 4th frame Note the speed of the AGC algorithm converges on the desired brightness level is unchanged compared to v1 since in v1 the AGC algorithm would skip 3 frames after every gain/exposure change. Regards, Hans Hans de Goede (6): ipa: software_isp: Fix context_.configuration.agc.againMin init ipa: software_isp: AGC: Do not lower gain below 1.0 ipa: software_isp: AGC: Raise exposure or gain not both at the same time ipa: software_isp: AGC: Only use integers for exposure calculations libcamera: software_isp: Add valid flag to struct SwIspStats libcamera: software_isp: Run sw-statistics once every 4th frame .../internal/software_isp/swisp_stats.h | 5 ++ src/ipa/simple/algorithms/agc.cpp | 47 ++++++++++++++----- src/ipa/simple/algorithms/awb.cpp | 3 ++ src/ipa/simple/algorithms/blc.cpp | 3 ++ src/ipa/simple/ipa_context.h | 7 ++- src/ipa/simple/soft_simple.cpp | 7 ++- src/libcamera/software_isp/debayer_cpu.cpp | 18 +++---- src/libcamera/software_isp/debayer_cpu.h | 4 +- src/libcamera/software_isp/swstats_cpu.cpp | 18 +++++-- src/libcamera/software_isp/swstats_cpu.h | 20 ++++++-- 10 files changed, 100 insertions(+), 32 deletions(-)