From patchwork Sat Sep 27 17:59:58 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: 24478 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 72FFEBDB1C for ; Sat, 27 Sep 2025 18:00:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 66C9E6B5F8; Sat, 27 Sep 2025 20:00:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="X+9jgfCK"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [IPv6:2600:3c0a:e001:78e:0:1991:8:25]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6B6476B5A2 for ; Sat, 27 Sep 2025 20:00:09 +0200 (CEST) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 6B60F44A46 for ; Sat, 27 Sep 2025 18:00:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EEF2C4CEE7; Sat, 27 Sep 2025 18:00:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758996007; bh=LdbUu4Ki/VD7Ep3GwBtC1+QMAZE7/xYTKhtt1nxcOuc=; h=From:To:Cc:Subject:Date:From; b=X+9jgfCKxFhELlsGlWYvr1YuO7uOcKcTA00tLgPNOSPzxZZv9uX3BglAnvQAccgHd K1T0XBaH6sVnFYt4jXPNIiMBB1CLTaJUKSEiUcJ124TNFzT0v8pIECHZ7gbclFegsW pLGvML9/lS5n7e/FBWYjN7YJ+H0Z/xykSJ77d5iAt9Uy714+D/IVCruSe8yVML4ShG 6uKL2RUXFOttyNBI0snHegNUw4P44LLCukPqNcImpP+nT+QcrVdiE6NbGOCLuwzVLY nrrtL1nejQ3PYKQ+6edprr3YwVp+Zf6fJgCLhXHu2Ln6DhwRzHmZRDvn1WvLuRdLsS SCeYAz5qYPFkw== From: Hans de Goede To: libcamera-devel@lists.libcamera.org Cc: Hans de Goede Subject: [PATCH v3 0/6] ipa: software_isp: AGC: Fox AGC oscillation bug Date: Sat, 27 Sep 2025 19:59:58 +0200 Message-ID: <20250927180004.84620-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. v3 has successfully passed CI, see: https://gitlab.freedesktop.org/camera/libcamera-softisp/-/commit/76f37231527d10399bc123a546f8e252faaa8310/pipelines?ref=softisp-agc-oscillation-fixes-v3 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 | 26 ++++++++++--------- src/ipa/simple/algorithms/awb.cpp | 3 +++ src/ipa/simple/algorithms/blc.cpp | 3 +++ src/ipa/simple/ipa_context.h | 2 +- src/ipa/simple/soft_simple.cpp | 7 ++++- src/libcamera/software_isp/debayer_cpu.cpp | 25 +++++++++++------- src/libcamera/software_isp/debayer_cpu.h | 4 +-- src/libcamera/software_isp/swstats_cpu.cpp | 9 ++++++- src/libcamera/software_isp/swstats_cpu.h | 5 +++- 10 files changed, 61 insertions(+), 28 deletions(-)