[{"id":35964,"web_url":"https://patchwork.libcamera.org/comment/35964/","msgid":"<857bxom6ec.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-09-24T11:33:47","subject":"Re: [PATCH 0/5] ipa: software_isp: AGC: Fox AGC oscillation bug","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hans de Goede <hansg@kernel.org> writes:\n\n> Hi All,\n>\n> Due to a combination of not having correct control-delay information for\n> various sensors as well as the generic nature of the simple-pipeline +\n> software-ISP meaning that any pipeline delays are unknown it is impossible\n> to get reliable control-delay values.\n>\n> Wrong control-delay values can lead to pretty bad oscilation. An example\n> oscilation which I observed while debugging this went as follows:\n>\n> 1. gain is set at 910 of 1000 max\n> 2. a new frame is processed and is found to not be bright enough, gain gets\n>    changed to 1000\n> 3. the gain gets applied 1 frame earlier then expected\n> 4. a new frame with gain 1000 is processed and is now found to be too bright\n>    (gain overshoot), the AGC code starts with the old gain of 910 due to\n>    the control-delay issue and decreases this to 820, this gets applied\n>    1 frame earlier then expected\n> 5. a new frame with gain 820 get processed, this frame is not bright\n>    enough so the gain gets increased from 1000 to 1000 (clipped at max),\n>    this gets applied 1 frame earlier then expected\n> 6. a new frame with gain 1000 is processed and is now found to be too bright\n>    (gain overshoot), the AGC code starts with the old gain of 820 due to\n>    the control-delay issue and decreases this to 740, this gets applied\n>    1 frame earlier then expected ...\n>\n> This repeats over and over increasing the oscilation (by decreasing the low\n> gain value)  until the gain bounces between gain-min and gain max leading\n> to pretty bad flickering.\n>\n> This series fixes this by remembering the last set gain and exposure values\n> instead of using the delayed-ctrls values, combined with skipping a fixed\n> number of frames after changing values.\n\nIt fixes the issue in my environment, without any very obvious problem.\n\nTested-by: Milan Zamazal <mzamazal@redhat.com>\n\n> This effectively reverts commit bb1aa92eb9ee (\"libcamera: software_isp:\n> Initialize exposure+gain before agc calculations\"). That commit was added\n> to fix the initial gain and exposure starting at 0, this series initializes\n> the cached values with the actual sensor values on the first frame to\n> avoid re-introducing this problem.\n>\n> This deviates from how other ISPs do things which is not ideal, but atm\n> it is not possible to fix the wrong control-delay values, so this is\n> the best we can do.\n>\n> Regards,\n>\n> Hans\n>\n>\n> Hans de Goede (5):\n>   ipa: software_isp: Fix context_.configuration.agc.againMin init\n>   ipa: software_isp: AGC: do not lower gain below default gain value\n>   ipa: software_isp: AGC: Raise exposure or gain not both at the same\n>     time\n>   ipa: software_isp: AGC: Only use integers for exposure calculations\n>   ipa: software_isp: AGC: Stop using delayed control for previous values\n>\n>  src/ipa/simple/algorithms/agc.cpp | 53 +++++++++++++++++++++----------\n>  src/ipa/simple/algorithms/agc.h   |  3 +-\n>  src/ipa/simple/ipa_context.h      |  8 ++++-\n>  src/ipa/simple/soft_simple.cpp    | 11 +++++--\n>  4 files changed, 53 insertions(+), 22 deletions(-)","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 E3CDFBDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 24 Sep 2025 11:33:53 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 72E8C6B5FB;\n\tWed, 24 Sep 2025 13:33:53 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5A2DF6B5F0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Sep 2025 13:33:52 +0200 (CEST)","from mail-wm1-f72.google.com (mail-wm1-f72.google.com\n\t[209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-371-FXtQD4eYOiWYwss_jVmGdA-1; Wed, 24 Sep 2025 07:33:50 -0400","by mail-wm1-f72.google.com with SMTP id\n\t5b1f17b1804b1-45f2c1556aeso21328395e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Sep 2025 04:33:50 -0700 (PDT)","from mzamazal-thinkpadp1gen7.tpbc.csb ([85.93.96.130])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-46e1dab52d7sm36011585e9.2.2025.09.24.04.33.47\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 24 Sep 2025 04:33:47 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"UWyJ5OhK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1758713631;\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=U5+baffJxr+KkaC8IdzREan5FzbvkKxBFsCvLnMWeJg=;\n\tb=UWyJ5OhKfFNWREItNJJnVSzeoXDMlrUSKo+vxO2j+eV5gLpJGeYG4zACQdl8uvXmMKhU0p\n\t8BBNYVvfHWUznZPhRicp5LJLCalvpm8Ui4dsaMchh0rhDLRL5pA1XO6obSzxfHRTSDD6B6\n\tjI+Uckjj526OFLGMRdJ2916WFKwARYQ=","X-MC-Unique":"FXtQD4eYOiWYwss_jVmGdA-1","X-Mimecast-MFC-AGG-ID":"FXtQD4eYOiWYwss_jVmGdA_1758713629","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1758713629; x=1759318429;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject: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h0vGixm3LHU+j\n\tzW3oSpyPiJgHM3RQinV0FUTODjv/57tMVyGBIM5PwI7e6u4sknu0lxpgYhMyQmtgxg==","X-Received":["by 2002:a05:6000:1789:b0:3fe:34ec:2fab with SMTP id\n\tffacd0b85a97d-405cb3e61a9mr5172610f8f.63.1758713628631; \n\tWed, 24 Sep 2025 04:33:48 -0700 (PDT)","by 2002:a05:6000:1789:b0:3fe:34ec:2fab with SMTP id\n\tffacd0b85a97d-405cb3e61a9mr5172579f8f.63.1758713628100; \n\tWed, 24 Sep 2025 04:33:48 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IHh02S+oUd6o/+UFWWqaBMawGMB84WD4jaAMvVPk+UFmRwfhatvxhN5n7/8quaQe/MBkRnuzQ==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Hans de Goede <hansg@kernel.org>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 0/5] ipa: software_isp: AGC: Fox AGC oscillation bug","In-Reply-To":"<20250923190657.21453-1-hansg@kernel.org> (Hans de Goede's\n\tmessage of \"Tue, 23 Sep 2025 21:06:52 +0200\")","References":"<20250923190657.21453-1-hansg@kernel.org>","Date":"Wed, 24 Sep 2025 13:33:47 +0200","Message-ID":"<857bxom6ec.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":"qbuxtoQAikNy876GlQ1b8TkUtwRu_ftPobXba7HUFew_1758713629","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>"}},{"id":35979,"web_url":"https://patchwork.libcamera.org/comment/35979/","msgid":"<175880246722.1246375.17629668028433453792@ping.linuxembedded.co.uk>","date":"2025-09-25T12:14:27","subject":"Re: [PATCH 0/5] ipa: software_isp: AGC: Fox AGC oscillation bug","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Hans de Goede (2025-09-23 20:06:52)\n> Hi All,\n> \n> Due to a combination of not having correct control-delay information for\n> various sensors as well as the generic nature of the simple-pipeline +\n> software-ISP meaning that any pipeline delays are unknown it is impossible\n> to get reliable control-delay values.\n> \n> Wrong control-delay values can lead to pretty bad oscilation. An example\n> oscilation which I observed while debugging this went as follows:\n> \n> 1. gain is set at 910 of 1000 max\n> 2. a new frame is processed and is found to not be bright enough, gain gets\n>    changed to 1000\n> 3. the gain gets applied 1 frame earlier then expected\n> 4. a new frame with gain 1000 is processed and is now found to be too bright\n>    (gain overshoot), the AGC code starts with the old gain of 910 due to\n>    the control-delay issue and decreases this to 820, this gets applied\n>    1 frame earlier then expected\n> 5. a new frame with gain 820 get processed, this frame is not bright\n>    enough so the gain gets increased from 1000 to 1000 (clipped at max),\n>    this gets applied 1 frame earlier then expected\n> 6. a new frame with gain 1000 is processed and is now found to be too bright\n>    (gain overshoot), the AGC code starts with the old gain of 820 due to\n>    the control-delay issue and decreases this to 740, this gets applied\n>    1 frame earlier then expected ...\n> \n> This repeats over and over increasing the oscilation (by decreasing the low\n> gain value)  until the gain bounces between gain-min and gain max leading\n> to pretty bad flickering.\n> \n> This series fixes this by remembering the last set gain and exposure values\n> instead of using the delayed-ctrls values, combined with skipping a fixed\n> number of frames after changing values.\n> \n> This effectively reverts commit bb1aa92eb9ee (\"libcamera: software_isp:\n> Initialize exposure+gain before agc calculations\"). That commit was added\n> to fix the initial gain and exposure starting at 0, this series initializes\n> the cached values with the actual sensor values on the first frame to\n> avoid re-introducing this problem.\n> \n> This deviates from how other ISPs do things which is not ideal, but atm\n> it is not possible to fix the wrong control-delay values, so this is\n> the best we can do.\n\n\nI've tested this - and I can say it improves my camera and makes it\nusable.\n\nSo to me that's enough to think we should indeed merge this already.\n\nThe response time for the AGC is /slow/ and I can easily push it into\nsituations where I can over expose my face - but I think that's me\npurposefully pushing the limits.\n\nGiven our current state on master I think we should merge this series -\nand then work on future improvements on top.\n\nThis will return the SoftISP to working and usable camera for users\nwhich is the most critical aspect at the moment.\n\nTested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> Regards,\n> \n> Hans\n> \n> \n> Hans de Goede (5):\n>   ipa: software_isp: Fix context_.configuration.agc.againMin init\n>   ipa: software_isp: AGC: do not lower gain below default gain value\n>   ipa: software_isp: AGC: Raise exposure or gain not both at the same\n>     time\n>   ipa: software_isp: AGC: Only use integers for exposure calculations\n>   ipa: software_isp: AGC: Stop using delayed control for previous values\n> \n>  src/ipa/simple/algorithms/agc.cpp | 53 +++++++++++++++++++++----------\n>  src/ipa/simple/algorithms/agc.h   |  3 +-\n>  src/ipa/simple/ipa_context.h      |  8 ++++-\n>  src/ipa/simple/soft_simple.cpp    | 11 +++++--\n>  4 files changed, 53 insertions(+), 22 deletions(-)\n> \n> -- \n> 2.51.0\n>","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 1D89AC32A9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 25 Sep 2025 12:14:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0E13D6B5F3;\n\tThu, 25 Sep 2025 14:14:32 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B0DD69318\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Sep 2025 14:14:30 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A85951419;\n\tThu, 25 Sep 2025 14:13:05 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"bPjXajfC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1758802385;\n\tbh=Uo/x+LSV4TeBLGUR3wU1Pl4FG5FGHeU0kPmvbTP20AE=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=bPjXajfCNh89yW8+IHk1bJt/7AfY5nE/I88zbMXgPCsDvVcNOdHbNm4NPLxMHqeMT\n\t3HMzPEi9R9ceSbdWJy9FMZ4Dvnj5c+Cze2KlfeCC9G2TKfL+5POVfkpSl+4Gi0zDzZ\n\tNMrjEw/BVrXhwHSAcVqBDlwPtGb19jQHHAeykyq0=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250923190657.21453-1-hansg@kernel.org>","References":"<20250923190657.21453-1-hansg@kernel.org>","Subject":"Re: [PATCH 0/5] ipa: software_isp: AGC: Fox AGC oscillation bug","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Hans de Goede <hansg@kernel.org>","To":"Hans de Goede <hansg@kernel.org>, libcamera-devel@lists.libcamera.org","Date":"Thu, 25 Sep 2025 13:14:27 +0100","Message-ID":"<175880246722.1246375.17629668028433453792@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]