From patchwork Tue Dec 19 12:57:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19331 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 634CBC3237 for ; Tue, 19 Dec 2023 12:57:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 889BD62B40; Tue, 19 Dec 2023 13:57:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1702990668; bh=2muJviFFwC86J2o8vkxSurEXIPvqnkATbtdsU3FV030=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=poNDuNUA1xCSrZjuZ+CrfizQ4x0k1C2l67oGa7k6XJt6Gww9QG7cI/riNyiMKuqUx UCHBfPsIe2Dg3CbcBz4HMMChrfvdlMuJ5p8M+PIX39ZzwxcL3xgCQyWs8bf0rRWIa4 MNCLr/YRmqPV5z1Gcn8Qzro48Q6utbehFvo4iaCHU9gJCad1hL1pY2oR0Huf16pGxe y1wvSpqO15HqqhJ8cesaJOQ6P0BYsOGNdIprb/3X/9qLqq/EVy3wTDeWj6/4oZg4i0 aZKusxwn+iP3DxJXguZNix6fQ0hKioktva24ox7J3DFWV3tAvxJ7hInOugHqJ1/2ge ENj6Uhkd37EJg== Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 15FA161D92 for ; Tue, 19 Dec 2023 13:57:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="GxvzSA8L"; dkim-atps=neutral Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-336746a545fso297992f8f.0 for ; Tue, 19 Dec 2023 04:57:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1702990665; x=1703595465; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=gezPCwisSNY45pW6B+HxcM1fy76Yf4nX1BMlf0ge7jc=; b=GxvzSA8L3MEEJkx9BhBQ7mXa2+5+vKVh73QFTrKoTIai5fBkkodZ1thVTF7u2Q8MGf pRo6KfITbF2LWKVjK9KAHyuJotllb6kLQRYfELnPPvwOyA0oz2qFZxV31Z5YChwiAqTJ RgoMBEi+HBAWuo+Oll4nYsfZyyhPKgvsRZYIKPXOrmqVfVV3U3CPWgUrup7JZmQmQzsr CzGS+B82GgfVf5Cke+olIGAyW4ukpyW6LPp7yf0Z9LjPt5ZCAd9wl10TOK8V2u3YWQ4q C8Q6ifvgc6OcEMQgS+z/k6KlEPMkI4EmlRi84K2EdZB9StbD8avCiroY1LWKEFtYrDL1 H05Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702990665; x=1703595465; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gezPCwisSNY45pW6B+HxcM1fy76Yf4nX1BMlf0ge7jc=; b=MfJA/zE4J9nc4P+raK15ot+cLbsaNORt1nhqKkxbtXr2HckjT9FYMFra+thH98lxMW 4eVGD+/vH30pHx6xxhllOvGzAQ/OBvc7nAveEal3t6bMu+vAkIdawjylQ+INf4h6eTGc T8VWouy8s5pCG2h8gZDGpfhtAqpIw7bZWvKEfuUonWw4EVXrV9Ot8NJcc4m/zpHpGcNw OYN8CFJTFW5YXgtymzzSP9xXdgswIO0ZrnI/752D7BaP0x9T162FzKMF5MQN2t86fB1K I4nBnoSN4aimumj2pRRCuxF8esD+dz5aaZcDN6keeir6Wigyj0lAxwOny2hoqMRkX5xh wKkQ== X-Gm-Message-State: AOJu0Ywl1Df8pKcdAgd+7b3UHeEeaUNQti8p0vH4oCiRTLXrqXA7k+M4 o/+rs/IE6pviOvIt8UYiJEQ6lAbIzzHNBRHubIg= X-Google-Smtp-Source: AGHT+IFx9XuYnifU+TvuhNyVumUh1JShocHzEwH6eirRahiiNXyrvVVHaFN2nbzSpyxrZTM5hgH1IA== X-Received: by 2002:adf:f58d:0:b0:336:68c1:36fa with SMTP id f13-20020adff58d000000b0033668c136famr598687wro.5.1702990665248; Tue, 19 Dec 2023 04:57:45 -0800 (PST) Received: from localhost.localdomain ([188.39.149.98]) by smtp.gmail.com with ESMTPSA id p16-20020a5d48d0000000b0033616ea5a0fsm26241297wrs.45.2023.12.19.04.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 04:57:44 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Dec 2023 12:57:49 +0000 Message-Id: <20231219125749.14362-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] ipa: rpi: Add hardware line rate constraints 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: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Advertise hardware constraints on the pixel processing rate through the Controller::HardwareConfig structure. When calculating the minimum line length during a configure() operation, ensure that we don't exceed this constraint. If we do exceed the hardware constraints, increase the modes's minimum line length so the pixel processing rate falls below the hardware limit. If this is not possible, throw a loud error message in the logs. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Nick Hollinghurst --- src/ipa/rpi/common/ipa_base.cpp | 26 ++++++++++++++++++++++++++ src/ipa/rpi/controller/controller.cpp | 3 +++ src/ipa/rpi/controller/controller.h | 2 ++ 3 files changed, 31 insertions(+) diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index 6ac9d5de2f88..419f19f120da 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -531,6 +531,32 @@ void IpaBase::setMode(const IPACameraSensorInfo &sensorInfo) mode_.minLineLength = sensorInfo.minLineLength * (1.0s / sensorInfo.pixelRate); mode_.maxLineLength = sensorInfo.maxLineLength * (1.0s / sensorInfo.pixelRate); + /* + * Ensure that the maximum pixel processing rate does not exceed the ISP + * hardware capabilities. If it does, try adjusting the minimum line + * length to compensate if possible. + */ + Duration minPixelTime = controller_.getHardwareConfig().minPixelProcessingTime; + Duration pixelTime = mode_.minLineLength / mode_.width; + if (minPixelTime && pixelTime < minPixelTime) { + Duration adjustedLineLength = minPixelTime * mode_.width; + if (adjustedLineLength <= mode_.maxLineLength) { + LOG(IPARPI, Info) + << "Adjusting mode minimum line length from " << mode_.minLineLength + << " to " << adjustedLineLength << " because of HW constraints."; + mode_.minLineLength = adjustedLineLength; + } else { + LOG(IPARPI, Error) + << "Sensor minimum line length of " << pixelTime * mode_.width + << " (" << 1us / pixelTime << " MPix/s)" + << " is below the minimum allowable HW limit of " << minPixelTime * mode_.width + << " (" << 1us / minPixelTime << " MPix/s) "; + LOG(IPARPI, Error) + << "THIS WILL CAUSE IMAGE CORRUPTION!!! " + << "Please update the driver to allow more horizontal blanking control."; + } + } + /* * Set the frame length limits for the mode to ensure exposure and * framerate calculations are clipped appropriately. diff --git a/src/ipa/rpi/controller/controller.cpp b/src/ipa/rpi/controller/controller.cpp index e62becd87e85..f81edf769736 100644 --- a/src/ipa/rpi/controller/controller.cpp +++ b/src/ipa/rpi/controller/controller.cpp @@ -17,6 +17,7 @@ using namespace RPiController; using namespace libcamera; +using namespace std::literals::chrono_literals; LOG_DEFINE_CATEGORY(RPiController) @@ -37,6 +38,7 @@ static const std::map HardwareConfigMap .numGammaPoints = 33, .pipelineWidth = 13, .statsInline = false, + .minPixelProcessingTime = 0s, } }, { @@ -51,6 +53,7 @@ static const std::map HardwareConfigMap .numGammaPoints = 64, .pipelineWidth = 16, .statsInline = true, + .minPixelProcessingTime = 1.0us / 380, /* 380 MPix/s */ } }, }; diff --git a/src/ipa/rpi/controller/controller.h b/src/ipa/rpi/controller/controller.h index 6e5f595284fd..170aea740789 100644 --- a/src/ipa/rpi/controller/controller.h +++ b/src/ipa/rpi/controller/controller.h @@ -15,6 +15,7 @@ #include #include +#include #include "libcamera/internal/yaml_parser.h" #include "camera_mode.h" @@ -47,6 +48,7 @@ public: unsigned int numGammaPoints; unsigned int pipelineWidth; bool statsInline; + libcamera::utils::Duration minPixelProcessingTime; }; Controller();