From patchwork Sun Oct 25 15:50:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 28599 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 D36B9C324C for ; Sun, 25 Oct 2026 15:50:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 45E0668FBC; Sun, 25 Oct 2026 16:50:32 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.b="Rlv6QJuc"; dkim=pass (2048-bit key; unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="N9hpXo8y"; dkim-atps=neutral Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E05368FA2 for ; Sun, 25 Oct 2026 16:50:30 +0100 (CET) Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69PFjL1F339265 for ; Sun, 25 Oct 2026 15:50:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=qcppdkim1; bh=lpAjVOjo/XznVfdrcN/RFIDy2seAPD/+cHS zRKLdrT8=; b=Rlv6QJuc/JpFQaPupj8xwOqrPpzn0k4rEbCVMv1uZ6jikTnAJlO FZKqzBeQeMpYiO15lA+SLuvH5F0HSSPiCromDV/fEUSjWDAiW9HfkVZyUPlEO3if Mc8LKZGnmtkCUPGZ9SrLZ/ok0hO21gNuzc0Wz8Q/tnMVWIK9B0O+3kfhO5Bsjml9 6RvQm7tmSsH+0ICg6EkH2cCIDQcNOXJjEL3QiaxHS67koltcVITky7Sj1oA7j+zZ B7FU6UDQQswwxzS2LqkJp90Q8lj7duA7969N1IKyu0DMbg7xeE6JwjDb+QB1mE/q BVsgQ/BG287DBBa2Kml2aPnKXXcGgXsaYCQ== Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hgm0gkf03-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sun, 25 Oct 2026 15:50:28 +0000 (GMT) Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-91c0f73807eso34432266d6.0 for ; Sun, 25 Oct 2026 08:50:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1792943428; x=1793548228; 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:content-type; bh=lpAjVOjo/XznVfdrcN/RFIDy2seAPD/+cHSzRKLdrT8=; b=N9hpXo8yk/rgS1Rx8U7iWRpi37EWdwA2wAtA5LIGfvnud6OlVKDP8Gb8DDVnGjftrS 0dir+wBDhh0JenqVquV7Eu6fBSCUV/+rWgd1p9Pnn49ro+UMRoXGnokchct30uasW7hg 0rSezhUM4YIK8AR6SWEU1FZRjzufoKLW8K/7J4CMzu+x+/swjPk0USAAEqVOnvexHIZJ iRVraJMaRZa6oiUm0YQ2csjOP9uf/AjIDNttthIE9wYcQWV2ECuwtG09APa2wNDmkDRu 7y596Pv/RpxD/9uj1XuVPJUJX6lqxz8yUlDkaUa2vlGcgbSvlTm2TBUbSizhip/eeXP6 c2UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792943428; x=1793548228; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lpAjVOjo/XznVfdrcN/RFIDy2seAPD/+cHSzRKLdrT8=; b=aQDmvEXMy6bBcx3/PB9SULtbyN/CeSLKNQh2no1hHRbpjQUjMvclhQKQ11OGtwLJyJ IGCweX0W/KdJ0+7USe715xSnUBeXpBsLQX/uoOArhHRCcBWanRscxODVcv0iwQVBC36t SA+xR67a8msf40RbG9PPGQZZRiPu6P3vnIufLZ4JZlodsbMZCp8vRDExqQtnIWY8PRu/ 7kMztAkbdAE35IB+BbpccIvNWXgVLbf9E5ELRUzQS4zUlsLv3An9BNxPrKqRd/ibs0I4 qPaaFgHHQokKDbWhVZFjN0zP9O4RyPJpfb2lE8+32T8cN0wbw/eBvsLo8uxmmYcO/v2n 3d/Q== X-Gm-Message-State: AFq9FYJZ0XIXdsvPNf4H1dYkHzmZTxGQW/M0ppu2BlmjHU0np9YNjY6t 9bRBzEmfwQCXv96WBaIbmbGpPF/DgdSjnqf/Ht7ITDmb3hulcsrnMCZ1YNCSsl5XVf3YszsLb+U 5X1T8s+hA3EJWiKhhH58DRS3GjxQQR46bdFmPugOZNrUOkgMtl7q+L7rXI9Ezrr0oTJeZEKONs9 K9MpNeQLvl X-Gm-Gg: AYBFou2EPKXKG6N2vCMF8yEPn7JzU6D5ySvC639EVnVE8k9dCXGKZ8ojA3ReJyjgJ4+ LP+5eppk9fgwWkn+ybJoZ4hw8CIwGogKHZtchBpv1UhwNbQ7gDx6EuwZUKAtAnuZIhce9ogWFMv e5UkaOCokFZRRXZU+ykMivtYo3rH0NhE3b8Yx+VkbtHz+kfBSzgqLnjsUm7EtJfp0gxpSXcYaR/ bOH37rVcyD5vgnyGl88rxecii4ruFecnw5wiuMebDRnc4ZxphR5TrVzoUcLsjfWbdlY6rz/NV1e feJitGKojPi8CB1T9CdxpGho3qM4Q5YUV+PQ3ZxV1uwlPtNF0rKDDF5NK1iZMNBYcHqp+EIDVpi ONu+AbvqTwAkytCfvtImyZhOdAivVhktIxqNlZfINEAAL7J4cHMQBI2bugeaHWe+FgW08HcQE+b ZI5n4n8U9CKjSUXg== X-Received: by 2002:a05:620a:458e:b0:93c:b7f3:9f5b with SMTP id af79cd13be357-940ef95515fmr720483385a.45.1792943428210; Sun, 25 Oct 2026 08:50:28 -0700 (PDT) X-Received: by 2002:a05:620a:458e:b0:93c:b7f3:9f5b with SMTP id af79cd13be357-940ef95515fmr720479985a.45.1792943427600; Sun, 25 Oct 2026 08:50:27 -0700 (PDT) Received: from shalem (2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:5bfa:a036:83f0:f9ec]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c46bd4e9995sm212039566b.15.2026.10.25.08.50.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2026 08:50:25 -0700 (PDT) From: Hans de Goede To: libcamera-devel@lists.libcamera.org, Kieran Bingham Cc: Hans de Goede Subject: [PATCH] libcamera: pipeline: simple: Prefer CSI2 packed bayer formats over unpacket formats Date: Sun, 25 Oct 2026 16:50:24 +0100 Message-ID: <20261025155024.113171-1-johannes.goede@oss.qualcomm.com> X-Mailer: git-send-email 2.56.0 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 7bjJo66X9Kh9dNtbxcWNRrwXCNjxbnRb X-Authority-Analysis: v=2.4 cv=UfTE26SN c=1 sm=1 tr=0 ts=6ade2545 cx=c_pps a=oc9J++0uMp73DTRD5QyR2A==:117 a=xqWC_Br6kY4A:10 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=e5mUnYsNAAAA:8 a=EUspDBNiAAAA:8 a=G4xvjrRAINwNJuQsRa8A:9 a=iYH6xdkBrDN1Jqds4HTS:22 a=Vxmtnl_E_bksehYqCbjh:22 X-Proofpoint-GUID: 7bjJo66X9Kh9dNtbxcWNRrwXCNjxbnRb X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI1MDA2MyBTYWx0ZWRfX7RLaD8fT7K1j yLVlF0ictB6FBMGCks3H9+WACPBs7EGMqKJUJmAYSwKN9UnHr4MMTLy2lPyKgE3szhnbgw63TQw 6yRNk1Uu412gYhBS07ATPAnFESJW4jOdoHYuzzgJsdFV4YEpsfwHsOpxOLpobkaRLhhvqzNvNm4 1PnF38ZVeRXY8L3EerPoNHo6FMpZJf954tchTHqXHKKKUjHXRlxabPHSLsl45omWp0OKBX223J7 cNOG9gGOfwTeLIpTTB7j+srrwqFEWD0bb0g1w6IjSWZrNHNRGKXMTJghkL4ZdgS2SkSHKLxpi+2 RI3rWZuqS1/lZpZAsuDCUc74fA3kAZSxhZBtYTEXKzrP5uD5x9J1mcBWTAa1tmRCNkkrraIVfeR 2WEzDVL0LB++pZ45o9im54Ohab44AxRHfLdddW9/eWldfX23ulwwWlE5APtKoR0HrjR9QbKjDLq XKreXaAYd+K0tgsHgfQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI1MDA2MyBTYWx0ZWRfX3b+h4RpGK4j2 x6SBV+HIjHxg32/s1o6qyrVEAFM52iKkVkscEaO3bkmyk1JzUp6GzZW2oU6sKENhqU2R4TZfddp hL81PXxf7wkcZcfnDwsehJrKVw6oq00= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293, Aquarius:18.0.1176, Hydra:6.1.138, FMLib:17.12.100.49 definitions=2026-10-25_04,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 spamscore=0 bulkscore=0 suspectscore=0 impostorscore=0 phishscore=0 adultscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610250063 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" Some CSI2 receivers like the IPU6 isys can store e.g. 10 bpp Bayer formats in either CSI2 packed (5 bytes / 4 pixels) or unpacked (2 bytes / pixel) formats. Before this change the simple-pipeline handler would pick whatever format was enumerated first as capture format in this case. Which on IPU6 boards comes down to picking unpacked. Packed formats use less memory and typically perform better due to reduced RAM bandwidth requirements. E.g. on a Lenovo ThinkPad X1 Yoga Gen 8 with i7-1370P CPU and a ov2740 sensor running at full sensor (FHD) resolution, 3 consecutive benchmark runs using libcamera's software ISP's builtin Debayer benchmark gives the following results: Unpacked EGL us/frame: 6398 / 7393 / 7524 CSI2 pack EGL us/frame: 5682 / 5536 / 5634 Unpacked CPU us/frame: 7653 / 8147 / 8614 CSI2 pack CPU us/frame: 7183 / 7063 / 6318 Modify the simple pipeline handler to prefer the more performant CSI2 packed format when both formats are available. This also fixes a problem with unpacked formats on IPU6 where sometimes at the start of a stream the IPU6 isys CSI2 receiver may return a corrupt unpacked frame with high bits set which causes libcamera to crash with an out of bound array access as the software ISP code expects the high bits of unpacked formats to always be 0. Closes: https://gitlab.freedesktop.org/camera/libcamera/-/work_items/328 Signed-off-by: Hans de Goede --- src/libcamera/pipeline/simple/simple.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 35c29ceca..3b59087ae 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -1216,6 +1216,9 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate() * Then pick, among the possible configuration for the pixel format, * the smallest sensor resolution that can accommodate all streams * without upscaling. + * + * If both packed and unpacked Bayer capture formats are support prefer + * packed for lower memory usage and better software ISP performance. */ const SimpleCameraData::Configuration *maxPipeConfig = nullptr; pipeConfig_ = nullptr; @@ -1223,12 +1226,25 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate() for (const SimpleCameraData::Configuration *pipeConfig : *configs) { const Size &captureSize = pipeConfig->captureSize; const Size &maxOutputSize = pipeConfig->outputSizes.max; + bool curCfgPacked = false; + bool newCfgPacked = false; + + if (pipeConfig_) { + BayerFormat curBayerFmt = BayerFormat::fromPixelFormat(pipeConfig_->captureFormat); + BayerFormat newBayerFmt = BayerFormat::fromPixelFormat(pipeConfig->captureFormat); + /* Only compare packed vs unpacked if both formats are Bayer */ + if (curBayerFmt.isValid() && newBayerFmt.isValid()) { + curCfgPacked = curBayerFmt.packing == BayerFormat::Packing::CSI2; + newCfgPacked = newBayerFmt.packing == BayerFormat::Packing::CSI2; + } + } if (maxOutputSize.width >= maxProcessedStreamSize.width && maxOutputSize.height >= maxProcessedStreamSize.height && captureSize.width >= maxRawStreamSize.width && captureSize.height >= maxRawStreamSize.height) { - if (!pipeConfig_ || captureSize < pipeConfig_->captureSize) + if (!pipeConfig_ || captureSize < pipeConfig_->captureSize || + (captureSize <= pipeConfig_->captureSize && !curCfgPacked && newCfgPacked)) pipeConfig_ = pipeConfig; }