From patchwork Tue Apr 22 21:58:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23214 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 1D2B4C327D for ; Tue, 22 Apr 2025 21:59:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CD0A868AD0; Tue, 22 Apr 2025 23:59:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Sx8+ob8N"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4CEF3617E3 for ; Tue, 22 Apr 2025 23:59:24 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-43ed8d32a95so49910485e9.3 for ; Tue, 22 Apr 2025 14:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359164; x=1745963964; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O/XNpCvNvuFewDwxBLgujn8Rp4YOl/7WSgH2ZliwlXs=; b=Sx8+ob8NQgRClu5pLeJom2KzwKkMMcCz5k++jeaY5EomBDmE30PST3nMNZ1+pdixU9 vnbDe83KE0fh5dCw7yMqkYaN2HoVuAkrvH8Rv78hdM1iwgIhm2UlxU2yrJ5u3OUvQl8K gQ9FlamD662PY/F6TxYwv8Q27mCf9yWxhWKPm9JDrhp6naIhadqBwcKKjo3vewEOKYQC RPwUSvj6HnxUlXPtSohfZf7lY40bLjoqg0Kcsx4DOGYeAPys8yM0HskXeIy6FixZl2RJ rc7QV6wqodYRlbzNs+ibVp5+JZ+a8caR8RgVTOEubHXjJrC38xyTx8OQKiZ1fBbmLEfa soTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359164; x=1745963964; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O/XNpCvNvuFewDwxBLgujn8Rp4YOl/7WSgH2ZliwlXs=; b=Su9uxptAhVaOoZ2dbGU1By5I+ygZzO4+dKHP7NbKrWSRRjPpc1YSMpize6RZiiht5x IwX3aK4J7+qmm1K7i/Qn4j7mvvw073IBaBiQ3B38U7WVBUQRfEZbNHp0zRnWEI8csQJU i1e05Wun8gADEiaPHR5VeEh+ZR76YwczyrhisvryKq2qYzJB36r81RTawnDuCI+diC4S XFbfpmm22t9hURJhtZEOc64EUJKI2BJ1ciMg573VxQReQvwn/fVX1SpLozr+hUZeoByC 1r+hCPqEY6p420a9TcJa+Sx9kq6sVDqaJ+GT0ZPm8kC2R0Y89E0qoMRcHK3zdzATGQgm QcEA== X-Gm-Message-State: AOJu0Ywn6UzYNpaUy9l9ZzCta2UjrxFv6HiYvqxIjXOOMpBa53VyIqym GVHlCMNAqm4KOA4JbxymyhKx4LSbTeCXNABN6ma7UgJOp31o9kiMiJ/KNtyy66u9wGOH80Zwe+L Bu8Q= X-Gm-Gg: ASbGncuTlGT+t0/isf//jcs4iE6gSrW3SxPWRaQb3mBJQu0hFp3bgn9sCGAkK49CZOK bc5HgmPuhEdKxln7zBwdMEFEJmpSbBoEXual7qKNCzHgy2Y4/f4XllpKVm4zUA6oRQOlI7tP8zi LPp7FwXlRIx5eL1n1THSXdr6n7iod8Cz/itg9px7vDlswMqTxJ2BVeZ8m174mj0dYfPrk9fPAZT BZjEBoTTiwAgXLw993BVWBLR2K20TFAxRMh4krK0HbuztzGQ5bQY1aZF+cdNloB+p8fc/w6E46t 3TEaxbIecS/fY0/DCwhONXgOFUD5FCRthgqpBBg/Rs556U+pkHNkCcYfWH0T27P12AEtRSV9tDJ HpMcOO3PgigvBU5TGCRk2 X-Google-Smtp-Source: AGHT+IFpsn55n5+XS9RfN/BqshkJPEi0St5FZzLqzC+GWhguxB4E8cy+924yWUP9RXCbc5v+2F/s6g== X-Received: by 2002:a05:600c:3b0d:b0:43d:7413:cb3e with SMTP id 5b1f17b1804b1-4406ab7f548mr133478695e9.1.1745359163662; Tue, 22 Apr 2025 14:59:23 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:23 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 01/27] libcamera: MappedFrameBuffer: Add tracking of mmap file descriptors to MappedFrameBuffer Date: Tue, 22 Apr 2025 22:58:54 +0100 Message-ID: <20250422215920.4297-2-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" In order to import via eglCreateImageKHR via an file descriptor we need to have access to the file descriptor associated with the plane. Extend MappedFrameBuffer to track the file descriptor giving an accessor method in-line with the existing planes_ accessor. Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/mapped_framebuffer.h | 2 ++ src/libcamera/mapped_framebuffer.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h index 6aaabf50..cb81243e 100644 --- a/include/libcamera/internal/mapped_framebuffer.h +++ b/include/libcamera/internal/mapped_framebuffer.h @@ -31,6 +31,7 @@ public: bool isValid() const { return error_ == 0; } int error() const { return error_; } const std::vector &planes() const { return planes_; } + const std::vector &fds() const { return fds_; } protected: MappedBuffer(); @@ -38,6 +39,7 @@ protected: int error_; std::vector planes_; std::vector maps_; + std::vector fds_; private: LIBCAMERA_DISABLE_COPY(MappedBuffer) diff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp index f54bbf21..82ab132c 100644 --- a/src/libcamera/mapped_framebuffer.cpp +++ b/src/libcamera/mapped_framebuffer.cpp @@ -237,6 +237,7 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags) } planes_.emplace_back(info.address + plane.offset, plane.length); + fds_.emplace_back(fd); } } From patchwork Tue Apr 22 21:58:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23215 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 D28E4C327D for ; Tue, 22 Apr 2025 21:59:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 68DEF68ACE; Tue, 22 Apr 2025 23:59:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Zwx0IxOn"; dkim-atps=neutral Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3001C68AC5 for ; Tue, 22 Apr 2025 23:59:25 +0200 (CEST) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-43cf05f0c3eso42937905e9.0 for ; Tue, 22 Apr 2025 14:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359164; x=1745963964; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aCH9ke+xdNCLAOtJ17RTjBinWjVzpYUWWqrcCCjVgQ4=; b=Zwx0IxOnXhsVUTnXGvoKyBGfyNoVlM9Cw1/kTewO7e7DYrXoXmgZI6RCXG1yRwUgXu uqqm7b+PPHkgy2+f6bpoFQmMvasq8ROKeQR/k3zR4BFlurvYddCFV7/QIlY25QdyIAYV 8v7yb9Bvy6j5kBtRmrAA7upT7FmhtnlWtI9mShVgfazQqXV5TiXsmgC05P60n2Fifo88 PpUEQRIPvfe6wXd+PbCepXChSBf8hbO7ITnohJ57kxXH5vU7nPYAtRRqdPJvuqqmvJkI MFOEAcPOvFdQLTPdRyftsj2SIoucV/PaZy+QWZTHzPbXOooM6Ymkt30kAalzeLG4rRn4 ExdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359164; x=1745963964; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aCH9ke+xdNCLAOtJ17RTjBinWjVzpYUWWqrcCCjVgQ4=; b=CpEg4QVfN3IanhP7QXbBG/vc19ra8GEWJ2qB3SBYspE3f4TvyQT2cP0sXCaMqsP6H2 o7aUY7NIYZWtMjy26wyXIoPbMoJQEHtgrP4ig0l7q/SZWk7z+XMsRufQ7a9OKwEOABEn qFjx+pD0TY4zx35ZbFrtoa0y1Li9Oa/4fRnDY8M44KIddzooVwjYCvPjLMaL7fP2a1xW XgF//Sm2TNRz2x0qXXXRxnORDPU7OJO5EFIriS+mtaC8zKm8cTR0pU3nFYfQ5xa7D0su mmy4T+viqWape/oPawukmv6eZd6ZBh1QbdCrXMkzJkLlVNBsmiCFgEVSVs+N4ANV7CEf 1kOQ== X-Gm-Message-State: AOJu0YwgMrcmwIj0HGIfIt5Auk0MwS1S76LyBAjVjx+/1ssERyFpNe/M NuKjFNHEgiMUJLCshs1tp2j6EzU/jn4+Fm42XoFwMZwPw2+XEfn3XMeQtqxbUe7y33YXZKxc46x ZRXo= X-Gm-Gg: ASbGnctgJ33lAhzP5J+bjiCQ4lSZgkmy9bxT004L9VR4rAzXA3O64mu4+je4Ml/yzwG CFVQjFPsUKQWITwEdD62p0qjHOkilPPLF+mBGY5hnjvEeqCAeVd2Mvt6c+U6WICb1RyAnvpvLVN lRUVJuwnJ7GFkB3ldeO3+IU7J2F8eE1z+VGaSmWBGi+781zEHa6TOEnn+jVEmIIwfhGreCPu3bz fwihHvLfrZziz/QqHEx9OBiweUyNTnr9ysYTZowQPJUQfxFCLf3NK+sSsNjGTw8tIfOYmnQ5o+W MJFgzDVV3QxbWilkL9mVhaWOou2fGr7ACzOZFaK5HXvvmKbRMmVomj5N1vJloWzASC/mh5ahaFp AOJiCC1iXmWl7Avqfc8sd X-Google-Smtp-Source: AGHT+IEJqwk2IA3oHJC/U0MQoktphPGBVlOs7unj1u+rPVMHryuKGPwmhIR5kT9nZwIRATs/BxYcHw== X-Received: by 2002:a05:600c:4f12:b0:43c:f050:fed3 with SMTP id 5b1f17b1804b1-4406ab96ad3mr130306875e9.11.1745359164584; Tue, 22 Apr 2025 14:59:24 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:24 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 02/27] libcamera: MappedFrameBuffer: Add accessor for MappedFrameBuffer plane maps Date: Tue, 22 Apr 2025 22:58:55 +0100 Message-ID: <20250422215920.4297-3-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/mapped_framebuffer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h index cb81243e..68b30740 100644 --- a/include/libcamera/internal/mapped_framebuffer.h +++ b/include/libcamera/internal/mapped_framebuffer.h @@ -31,6 +31,7 @@ public: bool isValid() const { return error_ == 0; } int error() const { return error_; } const std::vector &planes() const { return planes_; } + const std::vector &maps() const { return maps_; } const std::vector &fds() const { return fds_; } protected: From patchwork Tue Apr 22 21:58:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23216 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 27CA7C32A2 for ; Tue, 22 Apr 2025 21:59:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EE68B68AD8; Tue, 22 Apr 2025 23:59:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="u1daEMSh"; dkim-atps=neutral Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3FFDA617E3 for ; Tue, 22 Apr 2025 23:59:26 +0200 (CEST) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-43cef035a3bso39939665e9.1 for ; Tue, 22 Apr 2025 14:59:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359165; x=1745963965; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L2Y6auKQbWbB47K5RKdIYrjH8wAq46MTq5RtJq3yzk8=; b=u1daEMShs9VIRRXUukPCi0faMNDUJWEHNsNdbMlRfAwYmvXg8+S9bTLQlaptCtZze2 u0l5qw+q+FJi1ju8LHD6O1ddtsv9qzRXyRZCKUTTrMuFy9qlJhXcPOc73lq9mnXbCyvu qX1pKl7OB5oKyvRJIAcSuLN/9tsGB6FFSSIxl75e3sgX1lOafZ1lyu1cTDaMwYODIo8n AUgit+LAorAqPs9vrJXDSsa0bx5B+sMpKf33rsA6E3qrcgp+8ivNTzDGgXlrcTCEiTHu dGQSKG0KHOEOidBt1iycYxoKPaaK3UQKYY8Jw2SQdBZWSdAkZVAZdt8SpFPHtz6pVXEQ Kdew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359165; x=1745963965; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L2Y6auKQbWbB47K5RKdIYrjH8wAq46MTq5RtJq3yzk8=; b=JOGmg3U6XTNvmjuLxO4HcBhDLLSv430wBLT58kGBhdq51KkFlRm6SndSMwNm4m+dEA EaU4+asyalVrj1KTnRC5vlKa+8FM+DM/9Kb3EMbxu3lXDDJSuluQSgQCIFPVrBJZat8/ +pb0mT1WwZf5EXYGvRxbm0+P8mIMMeb8r0eNNRN6miBMwUUGDE4skg2KBOAA/sUBHW3D wy3kUhb6Zy1197IJmPQG9sDUDAJElTNZdrGzeDrbn8Ok7EDVHqI1lnwTzd1cBOCRqH03 YREk8mLpUw7Vivdw3VPSxoMmupsylFJEDmLQeA8+cnR3idZGPEMbEDwB/zuA7Oxv22va fhHw== X-Gm-Message-State: AOJu0Yx6QXjsJ0Lqe2mRPt5Pi5OdPuWZQhRnRFHMAbuEBFyxkmapCjYz XtCCDLhXSQmLlra7tQOPedIgEJEyif/shGitNBlqxmwdHqruDY36/QxBT1HFP9QT8qL+8dJVxdw uCfM= X-Gm-Gg: ASbGncsUU4nBRvnoagcb/QtrKbyW+BG70shmupn7wDq5az9zb+ado6OJ2gYgxOFdNzw TSlG2TwyNiptOXb/27bzTE46mXStQOa5Obg4bp1aiVy4YaaRoVaRAPQQPnCnGCQ80aWyu8If3ur 23+s9TqPU0UhcjnEv55ADWh7NwmowuyV0GsC61l2GaBp8/ggjGKGTPAkdiADbO4wHAEc5lVaDwl J3Q0CyysKM6hCCScAtas/JB3Sg+eOdqk0SCUhtMqzxO1Vn7eNrx+O52XW7XfdOdnpCgBoCohxBo FCiQCVe+EWmPzH56ozEfBkOxV9kVgzF2HlFlLmQA+LNwSvndTIO4xtamD/NPvcTsAQd5pv5BKgy +LBVCvUdEP0zUu1lpofio X-Google-Smtp-Source: AGHT+IEdb5JRZXYkKfavS9mMAPjUvQO/riVMgzKTbQoEzy/XbjElgaJf4tCCwrVEFScRQpYE60JxdQ== X-Received: by 2002:a05:600c:1911:b0:43d:9d5:474d with SMTP id 5b1f17b1804b1-4406aa8b882mr160895285e9.0.1745359165425; Tue, 22 Apr 2025 14:59:25 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:25 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 03/27] libcamera: dma_buf_allocator: Favour udmabuf over cma heap allocations Date: Tue, 22 Apr 2025 22:58:56 +0100 Message-ID: <20250422215920.4297-4-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" When /dev/dma_heap/linux,cma or /dev/dma_heap/system exist currently we favour allocation from this type of heap over /dev/udmabuf. We ought to favour udmabuf though - udmabuf is the preferred method by various distros for security reasons - Contiguous memory is a scarce resource Change the ordering of the allocator lookup so that the udmabuf lookup comes first. Fixes: ea4baaacc325 ("libcamera: DmaBufAllocator: Support allocating from /dev/udmabuf") Signed-off-by: Bryan O'Donoghue --- src/libcamera/dma_buf_allocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp index d8c62dd6..722ffd46 100644 --- a/src/libcamera/dma_buf_allocator.cpp +++ b/src/libcamera/dma_buf_allocator.cpp @@ -45,10 +45,10 @@ static constexpr std::array providerInfos = { { * /dev/dma_heap/linux,cma is the CMA dma-heap. When the cma heap size is * specified on the kernel command line, this gets renamed to "reserved". */ + { DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf, "/dev/udmabuf" }, { DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap, "/dev/dma_heap/linux,cma" }, { DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap, "/dev/dma_heap/reserved" }, { DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap, "/dev/dma_heap/system" }, - { DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf, "/dev/udmabuf" }, } }; LOG_DEFINE_CATEGORY(DmaBufAllocator) From patchwork Tue Apr 22 21:58:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23217 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 49B8BC327D for ; Tue, 22 Apr 2025 21:59:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 208A668ACB; Tue, 22 Apr 2025 23:59:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="cg8Gm4fB"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2365368ACD for ; Tue, 22 Apr 2025 23:59:27 +0200 (CEST) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-43edecbfb94so59329255e9.1 for ; Tue, 22 Apr 2025 14:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359166; x=1745963966; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=81Ng/LIxFB09YHT8LrVidJKxmT29lxMXyQw7vM5fRDM=; b=cg8Gm4fBmFMjKnmGKEyT4UqurNjdCA5P9sWmx/87Sk427PWVPcLx2yLIv5zTuZO8UD Cd35C/qvKYwkHQDEInsnPUPfLtHhTGw511sSyMqyWZc3BSZpcWFucGrojXKGRwmUpQDJ NBeyvuiLHyQXTydIBHMu5xHBNmrdZS3Gmq92lBlbw4aR5mcUz0lKCTQEFh7J8X7y7vSV xE4xWOCGxEOKPviIRr8f0vvS214bOHag4YUQG3MNnrznWzmckbxnHLfzz0PXN+TKxoci 2pCNMOAU3GmiVhVEWMP6K5SKtNCKlwl0gjWIfQ5Pg+AizfYy5qhDd0heZsXrVuptx6gh BdXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359166; x=1745963966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=81Ng/LIxFB09YHT8LrVidJKxmT29lxMXyQw7vM5fRDM=; b=TiKzvWxay02ugF0EEgh4jn/YviJIOSzsPm1ep/0TN9Y4I4sBve60jaDbAJw6GnwCxA ptFtuPDhUs8FjQwpctv5xLq1lUA0XuYMi0jsLdq2W7708xE0Hk3HtFu1k6aChpyAyCBk 8i2x9vs/ly/3I3bbWn31cstT7DfmfHD4kArFxmXpY2JlgKipjvfSGoYTDS9qFyUzEUri Mdv05FxAKxFQg7Ru1IQW5mjWD7vblDpmxIcB+Q4TvEnfkeU2DLU+OdCtVguu33rVCHtm QME203BP3LcOwNOowechM/K3pT5hv1hQM5yyJljTKFH0wjKoKe74vxuGO92kOO3DNsER Eg1g== X-Gm-Message-State: AOJu0YwoWi5dfoMEH3zrhrRy24uEpCBQT/2rhDiqeM2aSDNY/vW8MKHw VQk/CgJ6RPsvNCVm0MT+QCPNXx26jgFbuUd6vZMo5CjDtQVasVNtf/44bKkbVFPNfNew2SawIYx vjcI= X-Gm-Gg: ASbGnctrZpXLiobWj7D3G78XWZYKIxMngMGBsgoybEfXOUfBVbcZHoA3tbMFu7tL5QV cF3hbwKvWugdQ1suJOR7Y4DuPa/xIJkcfVkSRHB1ctARR6MEl2LOLcI74cAO3UmKkHJ7I4bel/s LGZhe8NWV/FkioMbars4ND9aUePuOnjQOiaZKme29qbjb/tplMRDEqXA4GZ2snp3cKajgH3ALXA knw3FAcu/F1tIg0mMARuujr5wLLnjGrRnRcuNFOrixHOkbfbq5iZNEAYQr4KBu6jOBRhQYm4igd fIcUMYMxfCGs7IidHFMqH791U4dyLEQzC7kUQDTJKlZ4miz7tA2cCShW+kRKgDpf2lpthOYe8dU RIy/ZXgjSiIeEJNsIyOkf X-Google-Smtp-Source: AGHT+IHwLIfGIollYB1itH5BH4CXaw9NF5DXkHW5/Fxrr/2PcMDLrzZ83lcZ5M/esgdaMQhtxBqtgg== X-Received: by 2002:a05:600c:548e:b0:440:6a5f:c31f with SMTP id 5b1f17b1804b1-4406ab93420mr151139435e9.11.1745359166430; Tue, 22 Apr 2025 14:59:26 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:25 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie, Kieran Bingham Subject: [PATCH 04/27] libcamera: swstats_cpu: Update statsProcessFn() / processLine0() documentation Date: Tue, 22 Apr 2025 22:58:57 +0100 Message-ID: <20250422215920.4297-5-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" From: Hans de Goede Update the documentation of the statsProcessFn() / processLine0() src[] pointer argument to take into account that swstats_cpu may also be used with planar input data or with non Bayer single plane input data. The statsProcessFn typedef is private, so no documentation is generated for it. Move the new updated src[] pointer argument documentation to processLine0() so that it gets included in the generated docs. Reviewed-by: Kieran Bingham Reviewed-by: Milan Zamazal Signed-off-by: Hans de Goede Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/swstats_cpu.cpp | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index c520c806..a9a3e77a 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -71,6 +71,19 @@ namespace libcamera { * patternSize height == 1. * It'll process line 0 and 1 for input formats with patternSize height >= 2. * This function may only be called after a successful setWindow() call. + * + * This function takes an array of src pointers each pointing to a line in + * the source image. + * + * Bayer input data requires (patternSize_.height + 1) src pointers, with + * the middle element of the array pointing to the actual line being processed. + * Earlier element(s) will point to the previous line(s) and later element(s) + * to the next line(s). See the DebayerCpu::debayerFn documentation for details. + * + * Planar input data requires a src pointer for each plane, with src[0] pointing + * to the line in plane 0, etc. + * + * For non Bayer single plane input data only a single src pointer is required. */ /** @@ -89,20 +102,6 @@ namespace libcamera { * \brief Signals that the statistics are ready */ -/** - * \typedef SwStatsCpu::statsProcessFn - * \brief Called when there is data to get statistics from - * \param[in] src The input data - * - * These functions take an array of (patternSize_.height + 1) src - * pointers each pointing to a line in the source image. The middle - * element of the array will point to the actual line being processed. - * Earlier element(s) will point to the previous line(s) and later - * element(s) to the next line(s). - * - * See the documentation of DebayerCpu::debayerFn for more details. - */ - /** * \var unsigned int SwStatsCpu::ySkipMask_ * \brief Skip lines where this bitmask is set in y From patchwork Tue Apr 22 21:58:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23218 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 68A50C331E for ; Tue, 22 Apr 2025 21:59:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C756268B24; Tue, 22 Apr 2025 23:59:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="SUWpLBvA"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 093D568ACA for ; Tue, 22 Apr 2025 23:59:28 +0200 (CEST) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43cfe574976so42544365e9.1 for ; Tue, 22 Apr 2025 14:59:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359167; x=1745963967; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=smZwtpbTz29j4hcPfA9P6oUHmTi9LVToPOlGCRTmB7Y=; b=SUWpLBvAaMy0vhEKdiCx7KPIkmJqnX3eaTqyVR5cKNvK06Y5E/ELEvqHWzvvC2hF9r QzJX+JnSDW/drhmhmwmBxrR4N0miO+UeD4QvWbqOKA8yz2Baaea6cpjVG5ctbn+bZxqf fUNaHnb8PKUZ3g9+D59jmN3i9Iy+sibTXGpQubSmHb9QS1s0XQbiigL6Pq8CCuhx+Ibv YB4YHBhvSzLTDR6bNsQwAEjoZmu2DHy0IfnuBLuHSNyA4H65JdKwX4a8mO6AbnW9lbpD wX+o0FhLZgQlssBIbaYpTavzl2EkyugzfjNAkGtXl/mhJbnUckqDUJgaH2Jfm7nlVpGx v40w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359167; x=1745963967; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=smZwtpbTz29j4hcPfA9P6oUHmTi9LVToPOlGCRTmB7Y=; b=X/otsHRAtzG4kN19XT011W/UAZNlH5vNymw9mVDnpm/Y7zLmObicqP8Kjh26VcTOOD v7nIgyMqmmWVtiV6w30sxNthB7hZvksH6/4q91typFy8HZJn2NhniXeRrZ4bYGO0Yo9y 7s5KbP3UIFhwRDxfuJkQz2S5bvZqPzQxhiWd4d2fcYkqZeCpCCwhckLJlR7nAJnhed+i WfK+TkM0+c/XDhgJDJA/1UCjsLMGOP40zVDMynZxEnZBGqWi9AR57LZVxT9uQWxBGuhi H62zv2y+shSUZOfnUqk75/cFuRnYbJNXTur4+K4LQdt5dByoT6/0q1XspFA7QutZ31DC vPxw== X-Gm-Message-State: AOJu0Yz+hR8vPTyFCDt78TmT/ZjO4y+A0FgD4Xf8WBqwsVSbAnFnmgsb 3+9KGckgE5Jd73C4et/RIXM+kI9GfMl2bcUIAgzt4Fvp5iCZkEVVkPBbhc/ssAE0khemYwOWLqQ h19k= X-Gm-Gg: ASbGncvfAak8NIYUbR/FcBrKAN7AM8GR0RuMr+8L5hD1dsD+h0mBD9Uwce0jf76rKrF rvymPJJzR9YLXBQqRojOonOjDOH2OwydiR8ZArpTbR6l2Qgk9iG5uids/Tf7IcWGDDw+a0H0L1f mJmrqsmZIdb3C4yEFZxh98WIay9UpWahKtm21UNtmCon37P/+He3UZmq5sd5JJEBOwgKo0O2WTa ueHsWqaM0CbF4jAaiZwYjWuJFfm84xxpnqG2KLIqMeqXoeVrrIr8jUwWPvNZ8LBEgi0qHHSoK2n 4OQ6HRPWAajKxyA9fFpAJp75NrX/OdZeEGYD24F79db6WFmfVs+R6g8ImjAULxERlOJ2omr7wxG CfMMWAaFiAzk7hnvKqErM X-Google-Smtp-Source: AGHT+IErBE9F/OlI/GautObTB87ngxUybNwQwc920fwDAlivg2ay5xKeywVxkGGZPBCydYZQTwrdEg== X-Received: by 2002:a05:600c:4ecc:b0:43b:c0fa:f9dd with SMTP id 5b1f17b1804b1-4406ac007b8mr135722955e9.25.1745359167359; Tue, 22 Apr 2025 14:59:27 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:26 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie, Kieran Bingham Subject: [PATCH 05/27] libcamera: swstats_cpu: Drop patternSize_ documentation Date: Tue, 22 Apr 2025 22:58:58 +0100 Message-ID: <20250422215920.4297-6-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" From: Hans de Goede patternSize_ is a private variable and its meaning is already documented in the patternSize() getter documentation. Move the list of valid sizes to the patternSize() getter documentation and drop the patternSize_ documentation. While at it also add 1x1 as valid size for use with future support of single plane non Bayer input data. Reviewed-by: Kieran Bingham Reviewed-by: Milan Zamazal Signed-off-by: Hans de Goede Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/swstats_cpu.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index a9a3e77a..5e4246a9 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -58,6 +58,8 @@ namespace libcamera { * also indicates if processLine2() should be called or not. * This may only be called after a successful configure() call. * + * Valid sizes are: 1x1, 2x2, 4x2 or 4x4. + * * \return The pattern size */ @@ -112,13 +114,6 @@ namespace libcamera { * \brief Statistics window, set by setWindow(), used every line */ -/** - * \var Size SwStatsCpu::patternSize_ - * \brief The size of the bayer pattern - * - * Valid sizes are: 2x2, 4x2 or 4x4. - */ - /** * \var unsigned int SwStatsCpu::xShift_ * \brief The offset of x, applied to window_.x for bayer variants From patchwork Tue Apr 22 21:58:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23219 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 39C43C32A2 for ; Tue, 22 Apr 2025 21:59:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E23C068B2A; Tue, 22 Apr 2025 23:59:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="H1KuB6ez"; dkim-atps=neutral Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0FB7268AD9 for ; Tue, 22 Apr 2025 23:59:29 +0200 (CEST) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-39efc1365e4so2059265f8f.1 for ; Tue, 22 Apr 2025 14:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359168; x=1745963968; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NL86VTXgXgeQtJwMlBiBDgKApRvuNu2cPMHijbRU9yo=; b=H1KuB6ez99mh9tg/2hpuplddll0/zET3UfRPoveuTvHrIFPvjh2BDfhg6zOKE7HFWy L3D70/D/RCx4M1hm2jZV2JMkjyjzb0fwF/aWYPLpyfwTMqhiLxt1oSaKFwvQOoUvPin4 YvXr8YXwl/JQAaEMSZmdHhzTL6JXAN/PhMg7+8g6du+UZl9nURrKSxbQEXPiBQTbqupO 6O1yiJ0jKyLdltj1w9tyfNbr/Z605qdOw1wcW9dJV253d2mLogSLBe92ydvRTfyRlTuV 5T36wnVyN3jcpFp5SsAW1FfUmXzHq+tMZFDsPBH+w3uAjH5Qql5rzPPUtM66A9KLJwH1 wT6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359168; x=1745963968; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NL86VTXgXgeQtJwMlBiBDgKApRvuNu2cPMHijbRU9yo=; b=Q9/C5Qd/RxzAb2Qpk5bItla0dzp376SVZ9yA+kUssCzMujKkMTHv512C6oQOzOHW2a yUm9mS7k6ePh66cDkkGNIQ/O+2aRcJwFNeLXjnt1Bq5iUuAn3kaG6m/nIJhp/9/oy8U9 gSnn4u7yWUNRmRR8CfKTf2gSHSWWjZrD6+s3dWsez2hGb4g9lytZJjrQBTYYAjKMsnNJ KIclXJ4ZSu3dPudP704msyCJYotEEdhvILxWpDhoDdEuHhvEsSma5doFDFuPTK1DZvRA C/fY1knRw9DkPcAFg+qCpC6Xpspdd+fkjLxxrmlqQPrTBAaGQ9j3YBx6I8M6YR3ElO7C 8StA== X-Gm-Message-State: AOJu0YwyBY0UgRtud8XQ65U1cdYT5qFyBXshlmlFpGqXjQVn5XvnaGyW vY/1tMJGiM2K+r68Qs25Qb22266ZrCQXgwbHOjrgo89S2lAzPCKEggy2rwPSfZT7YpluLNTGV3H pGWY= X-Gm-Gg: ASbGncsXx55o7urIK2oKRNeYX+shDfWZCw+EHl5IJyQsV6lVku8mOmogXf0GK/BhVQj Ksp1CDVq5zO2nfv3M0WctpceLZ2/rkg0TQTPwFiyKjf+FQQkBtZ0QYcF0R8q4yrQt+8zyx7S22T wjBKJY+llVoYwBts/WjFYGtd0Z55T5YxV7sNXPWTnz0KaGiQzWUHaFqweP0tU/R9aXOuhKuBlxd hATCRW23URJiPtPQtnzwL/5wBj8SVcZP+1mQGLKMfDcJDW3f5zeJCq9tcoFuYVwGxG4nQ/1Mrgo p0UwlT5d7uRfURMSuxI3xUmA1voU/UmCA+TcOdy0MEOxH/vq71oUkufWw4h/ili//pZQgBatjXX 7CENxqOtABA/RuOl0ryHj X-Google-Smtp-Source: AGHT+IGiTgRjWIY/8L+Vth5Qai6xIQmdiAnk+4gf2Ep1fYEyxz6LqXb2MCYZWOX/09VAAa0CTASwJA== X-Received: by 2002:a05:6000:22c7:b0:391:3988:1c97 with SMTP id ffacd0b85a97d-39efba4af82mr14396217f8f.17.1745359168357; Tue, 22 Apr 2025 14:59:28 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:27 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie, Kieran Bingham Subject: [PATCH 06/27] libcamera: software_isp: Move benchmark code to its own class Date: Tue, 22 Apr 2025 22:58:59 +0100 Message-ID: <20250422215920.4297-7-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" From: Hans de Goede Move the code for the builtin benchmark to its own small Benchmark class. Reviewed-by: Kieran Bingham Reviewed-by: Milan Zamazal Signed-off-by: Hans de Goede --- Changes since the RFC: - Add doxygen documentation to for all the public methods Signed-off-by: Bryan O'Donoghue --- .../internal/software_isp/benchmark.h | 36 +++++++ .../internal/software_isp/meson.build | 1 + src/libcamera/software_isp/benchmark.cpp | 93 +++++++++++++++++++ src/libcamera/software_isp/debayer_cpu.cpp | 36 +------ src/libcamera/software_isp/debayer_cpu.h | 7 +- src/libcamera/software_isp/meson.build | 1 + 6 files changed, 135 insertions(+), 39 deletions(-) create mode 100644 include/libcamera/internal/software_isp/benchmark.h create mode 100644 src/libcamera/software_isp/benchmark.cpp diff --git a/include/libcamera/internal/software_isp/benchmark.h b/include/libcamera/internal/software_isp/benchmark.h new file mode 100644 index 00000000..8af25015 --- /dev/null +++ b/include/libcamera/internal/software_isp/benchmark.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Red Hat Inc. + * + * Authors: + * Hans de Goede + * + * Simple builtin benchmark to measure software ISP processing times + */ + +#pragma once + +#include +#include + +namespace libcamera { + +class Benchmark +{ +public: + Benchmark(); + ~Benchmark(); + + void startFrame(void); + void finishFrame(void); + +private: + unsigned int measuredFrames_; + int64_t frameProcessTime_; + timespec frameStartTime_; + /* Skip 30 frames for things to stabilize then measure 30 frames */ + static constexpr unsigned int kFramesToSkip = 30; + static constexpr unsigned int kLastFrameToMeasure = 60; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build index 508ddddc..a7e606d2 100644 --- a/include/libcamera/internal/software_isp/meson.build +++ b/include/libcamera/internal/software_isp/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 libcamera_internal_headers += files([ + 'benchmark.h', 'debayer_params.h', 'software_isp.h', 'swisp_stats.h', diff --git a/src/libcamera/software_isp/benchmark.cpp b/src/libcamera/software_isp/benchmark.cpp new file mode 100644 index 00000000..b3da3c41 --- /dev/null +++ b/src/libcamera/software_isp/benchmark.cpp @@ -0,0 +1,93 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Red Hat Inc. + * + * Authors: + * Hans de Goede + * + * Simple builtin benchmark to measure software ISP processing times + */ + +#include "libcamera/internal/software_isp/benchmark.h" + +#include + +namespace libcamera { + +LOG_DEFINE_CATEGORY(Benchmark) + +/** + * \class Benchmark + * \brief Simple builtin benchmark + * + * Simple builtin benchmark to measure software ISP processing times. + */ + +/** + * \brief Constructs a Benchmark object + */ +Benchmark::Benchmark() + : measuredFrames_(0), frameProcessTime_(0) +{ +} + +Benchmark::~Benchmark() +{ +} + +static inline int64_t timeDiff(timespec &after, timespec &before) +{ + return (after.tv_sec - before.tv_sec) * 1000000000LL + + (int64_t)after.tv_nsec - (int64_t)before.tv_nsec; +} + +/** + * \brief Start measuring process time for a single frame + * + * Call this function before processing frame data to start measuring + * the process time for a frame. + */ +void Benchmark::startFrame(void) +{ + if (measuredFrames_ >= Benchmark::kLastFrameToMeasure) + return; + + frameStartTime_ = {}; + clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime_); +} + +/** + * \brief Finish measuring process time for a single frame + * + * Call this function after processing frame data to finish measuring + * the process time for a frame. + * + * This function will log frame processing time information after + * Benchmark::kLastFrameToMeasure frames have been processed. + */ +void Benchmark::finishFrame(void) +{ + if (measuredFrames_ >= Benchmark::kLastFrameToMeasure) + return; + + measuredFrames_++; + + if (measuredFrames_ <= Benchmark::kFramesToSkip) + return; + + timespec frameEndTime = {}; + clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime); + frameProcessTime_ += timeDiff(frameEndTime, frameStartTime_); + + if (measuredFrames_ == Benchmark::kLastFrameToMeasure) { + const unsigned int measuredFrames = Benchmark::kLastFrameToMeasure - + Benchmark::kFramesToSkip; + LOG(Benchmark, Info) + << "Processed " << measuredFrames + << " frames in " << frameProcessTime_ / 1000 << "us, " + << frameProcessTime_ / (1000 * measuredFrames) + << " us/frame"; + } +} + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index 66f6038c..8d30bf4a 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -554,9 +554,6 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg, lineBuffers_[i].resize(lineBufferLength_); } - measuredFrames_ = 0; - frameProcessTime_ = 0; - return 0; } @@ -746,24 +743,9 @@ void DebayerCpu::process4(const uint8_t *src, uint8_t *dst) } } -namespace { - -inline int64_t timeDiff(timespec &after, timespec &before) -{ - return (after.tv_sec - before.tv_sec) * 1000000000LL + - (int64_t)after.tv_nsec - (int64_t)before.tv_nsec; -} - -} /* namespace */ - void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params) { - timespec frameStartTime; - - if (measuredFrames_ < DebayerCpu::kLastFrameToMeasure) { - frameStartTime = {}; - clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime); - } + bench_.startFrame(); std::vector dmaSyncers; for (const FrameBuffer::Plane &plane : input->planes()) @@ -817,21 +799,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output dmaSyncers.clear(); /* Measure before emitting signals */ - if (measuredFrames_ < DebayerCpu::kLastFrameToMeasure && - ++measuredFrames_ > DebayerCpu::kFramesToSkip) { - timespec frameEndTime = {}; - clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime); - frameProcessTime_ += timeDiff(frameEndTime, frameStartTime); - if (measuredFrames_ == DebayerCpu::kLastFrameToMeasure) { - const unsigned int measuredFrames = DebayerCpu::kLastFrameToMeasure - - DebayerCpu::kFramesToSkip; - LOG(Debayer, Info) - << "Processed " << measuredFrames - << " frames in " << frameProcessTime_ / 1000 << "us, " - << frameProcessTime_ / (1000 * measuredFrames) - << " us/frame"; - } - } + bench_.finishFrame(); /* * Buffer ids are currently not used, so pass zeros as its parameter. diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index 926195e9..d6820d5e 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -17,6 +17,7 @@ #include +#include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/bayer_format.h" #include "debayer.h" @@ -160,11 +161,7 @@ private: unsigned int xShift_; /* Offset of 0/1 applied to window_.x */ bool enableInputMemcpy_; bool swapRedBlueGains_; - unsigned int measuredFrames_; - int64_t frameProcessTime_; - /* Skip 30 frames for things to stabilize then measure 30 frames */ - static constexpr unsigned int kFramesToSkip = 30; - static constexpr unsigned int kLastFrameToMeasure = 60; + Benchmark bench_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index aac7eda7..59fa5f02 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -8,6 +8,7 @@ if not softisp_enabled endif libcamera_internal_sources += files([ + 'benchmark.cpp', 'debayer.cpp', 'debayer_cpu.cpp', 'software_isp.cpp', From patchwork Tue Apr 22 21:59:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23220 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 2C1D4C331F for ; Tue, 22 Apr 2025 21:59:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C748A68B2E; Tue, 22 Apr 2025 23:59:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="mmrfnrki"; dkim-atps=neutral Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1CFA868ADC for ; Tue, 22 Apr 2025 23:59:30 +0200 (CEST) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-43cebe06e9eso47638665e9.3 for ; Tue, 22 Apr 2025 14:59:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359169; x=1745963969; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0Ek6jmyDtRYKIUfKdQ2Duk5zmK3pCbgsZ+bQyRX+gec=; b=mmrfnrkixhkvZdaunLhDPWfdHBP9+BRKQHNFa8TLQi8KPKxJf6/B0pDxuenryla+dd HgRCvqR4JZT4n465qYzxOiw8dLysT7st0KtjDbJar9JbSlCSTJjKl7SbeokcARh7ewZQ KACGAvo/YuNJSCT2M0TC8ry/H8zTpvvIPh0pRGWNHdQMUUpR3etYcMOY/LMuOkA4pbFc Awa+FlIl7InhcLppOC99QOaRCuZLGdiV5FNc36dJsw6SD7mYDPg6HHPBunM4ZTX6pNuL oyfX4fvv/t5rqa0xbhHVhAavGjA+IhQkqVVaqW+IIoHtNgaZ0RYxTE64eiCM0IHFkVS+ 0ghw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359169; x=1745963969; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0Ek6jmyDtRYKIUfKdQ2Duk5zmK3pCbgsZ+bQyRX+gec=; b=pMvoK1bDborg0Zoj58LqWyICbfWskhiqnMoymN+jFREUxwFXbKOF9g+QarhBgux5Tt if3GaUWDa6Rlg5IGo8LFREDAqI1As22vJJ1GIGLoD+JE/+aBlVduOqxz49B6RREtfkEO JKbr8ILsM6cc/APrpL/LsuHghqUaczM7G7LVP/5dkLrJ46FKAbZn9nudt+cNKVJbx+jU 0FeEKHEruzcvkJILhEKS748PxMOqeeUYLsc+Sf6YhtYGeNm/wiEJr1Vv4U7HJj3zMHRv HFOR42t2LDM4/HragtniVg5pNvnGMzRavA00SfmycQXwqWa9HwoAA8X4AZby/Bpfdahw MObA== X-Gm-Message-State: AOJu0YzoUj7QVzWIDfS4s828LABaYI1ZySwruC3Dohm12mxabdxN+AG+ +A9R2vgEeMU2dpKEVuMj1U6xXDM0aaQZU8o9pRxMO3tULYPSK2wyeq7G7QqggmACZgL1DKxuKJV Me+Y= X-Gm-Gg: ASbGnctZmYIbvMFXP7aLfWQPfnACRFWUyP/Y+A9NIVrcDnthCXKavNPcHUFvEveLskd glfAq4LjLDFr3Og/Nug5a6Lp6XOkRaVLga8LdI1K+ZKZsVE4LveaWzsgiQeVq1H1IAUGaJ7eHT7 xHsrAR+KUeur/IIgWy6HUwQodm+CT53+sD/FTie41t1HL4hL+DtPK889JEiD/Us5xlGtV5I+JA4 CFHVi1Wg9r2zrdIs59SRv3NZUZf5ciEoim3HOVx2A52V5YvMdxLG4gTF132PMSRHGrjfXcrdL5C 36wg852SaJIxhPhOVMRm8pHcIhBDvHVobmhSyp7LxLUFRz9+Rrj9jOsu5xRZ8bNAClacxEMsGeT X7kqT2fEtdJGiLsYvlh68 X-Google-Smtp-Source: AGHT+IHmZmFyH8dP26NLUxZpRzrfIDqhpoAvHdN+xIYOB6zlvzv1v5Hk7cI1KkWr0p5qV6qNUB76iQ== X-Received: by 2002:a05:600c:5491:b0:43c:eeee:b706 with SMTP id 5b1f17b1804b1-4406abf93c8mr136303875e9.24.1745359169461; Tue, 22 Apr 2025 14:59:29 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:28 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 07/27] libcamera: swstats_cpu: Add processFrame() method Date: Tue, 22 Apr 2025 22:59:00 +0100 Message-ID: <20250422215920.4297-8-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" From: Hans de Goede Add a method to the SwstatsCpu class to process a whole Framebuffer in one go, rather then line by line. This is useful for gathering stats when debayering is not necessary or is not done on the CPU. Reviewed-by: Milan Zamazal Signed-off-by: Hans de Goede --- Changes since the RFC: - Make processFrame() call startFrame() and finishFrame() rather then making the caller do this - Add doxygen documentation for processFrame() Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/swstats_cpu.cpp | 51 ++++++++++++++++++++++ src/libcamera/software_isp/swstats_cpu.h | 12 +++++ 2 files changed, 63 insertions(+) diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 5e4246a9..af407b4d 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -16,6 +16,7 @@ #include #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/mapped_framebuffer.h" namespace libcamera { @@ -360,11 +361,14 @@ int SwStatsCpu::setupStandardBayerOrder(BayerFormat::Order order) */ int SwStatsCpu::configure(const StreamConfiguration &inputCfg) { + stride_ = inputCfg.stride; + BayerFormat bayerFormat = BayerFormat::fromPixelFormat(inputCfg.pixelFormat); if (bayerFormat.packing == BayerFormat::Packing::None && setupStandardBayerOrder(bayerFormat.order) == 0) { + processFrame_ = &SwStatsCpu::processBayerFrame2; switch (bayerFormat.bitDepth) { case 8: stats0_ = &SwStatsCpu::statsBGGR8Line0; @@ -385,6 +389,7 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg) /* Skip every 3th and 4th line, sample every other 2x2 block */ ySkipMask_ = 0x02; xShift_ = 0; + processFrame_ = &SwStatsCpu::processBayerFrame2; switch (bayerFormat.order) { case BayerFormat::BGGR: @@ -425,4 +430,50 @@ void SwStatsCpu::setWindow(const Rectangle &window) window_.height &= ~(patternSize_.height - 1); } +void SwStatsCpu::processBayerFrame2(MappedFrameBuffer &in) +{ + const uint8_t *src = in.planes()[0].data(); + const uint8_t *linePointers[3]; + + /* Adjust src for starting at window_.y */ + src += window_.y * stride_; + + for (unsigned int y = 0; y < window_.height; y += 2) { + if (y & ySkipMask_) { + src += stride_ * 2; + continue; + } + + /* linePointers[0] is not used by any stats0_ functions */ + linePointers[1] = src; + linePointers[2] = src + stride_; + (this->*stats0_)(linePointers); + src += stride_ * 2; + } +} + +/** + * \brief Calculate statistics for a frame in one go + * \param[in] frame The frame number + * \param[in] bufferId ID of the statistics buffer + * \param[in] input The frame to process + * + * This may only be called after a successful setWindow() call. + */ +void SwStatsCpu::processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input) +{ + bench_.startFrame(); + startFrame(); + + MappedFrameBuffer in(input, MappedFrameBuffer::MapFlag::Read); + if (!in.isValid()) { + LOG(SwStatsCpu, Error) << "mmap-ing buffer(s) failed"; + return; + } + + (this->*processFrame_)(in); + finishFrame(frame, bufferId); + bench_.finishFrame(); +} + } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/swstats_cpu.h b/src/libcamera/software_isp/swstats_cpu.h index 26a2f462..fa47cec9 100644 --- a/src/libcamera/software_isp/swstats_cpu.h +++ b/src/libcamera/software_isp/swstats_cpu.h @@ -18,12 +18,16 @@ #include #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/framebuffer.h" #include "libcamera/internal/shared_mem_object.h" #include "libcamera/internal/software_isp/swisp_stats.h" +#include "benchmark.h" + namespace libcamera { class PixelFormat; +class MappedFrameBuffer; struct StreamConfiguration; class SwStatsCpu @@ -42,6 +46,7 @@ public: void setWindow(const Rectangle &window); void startFrame(); void finishFrame(uint32_t frame, uint32_t bufferId); + void processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input); void processLine0(unsigned int y, const uint8_t *src[]) { @@ -65,6 +70,7 @@ public: private: using statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]); + using processFrameFn = void (SwStatsCpu::*)(MappedFrameBuffer &in); int setupStandardBayerOrder(BayerFormat::Order order); /* Bayer 8 bpp unpacked */ @@ -77,6 +83,10 @@ private: void statsBGGR10PLine0(const uint8_t *src[]); void statsGBRG10PLine0(const uint8_t *src[]); + void processBayerFrame2(MappedFrameBuffer &in); + + processFrameFn processFrame_; + /* Variables set by configure(), used every line */ statsProcessFn stats0_; statsProcessFn stats2_; @@ -89,9 +99,11 @@ private: Size patternSize_; unsigned int xShift_; + unsigned int stride_; SharedMemObject sharedStats_; SwIspStats stats_; + Benchmark bench_; }; } /* namespace libcamera */ From patchwork Tue Apr 22 21:59:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23221 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 75CF2C327D for ; Tue, 22 Apr 2025 21:59:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E4F8F68B2D; Tue, 22 Apr 2025 23:59:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="FXKRirtz"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2421768ADB for ; Tue, 22 Apr 2025 23:59:31 +0200 (CEST) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-43ede096d73so41972645e9.2 for ; Tue, 22 Apr 2025 14:59:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359170; x=1745963970; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2WyL2xMXY/h3W3raFwPBVRPThikL44NlUcetTPcUj1c=; b=FXKRirtz1oDqwiOACQTdBdoflW3IHlNcnmu31yJ3NpDyctDMN6nDkuvOCtOiKYfzie iffrGk33Np+uHZpNIMQG4aYgO9lQ8ZUqGepKFyGV6T6dG5KOf0C+gVYD6Lm//9ePdBMm 7CZ3ND2t/DCNrFPIXIY1PJMyiCad/YOiBTJ74LbPmhjkaRMyrX5DCnxjsbNcvR8/xCqI MolPCewpKp4Rhbx1avP3PaXLvDW5gjRxiswfLzvLmM7NyO4LQuMqnwXPkI2F1CESSJd/ gK0bNnh0Z3ToMzLH4WObIfBcBJ+WEM2gQlHAVJlH+WMKhgFNji58lN1Q2CBrUeHOTWEs 9kug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359170; x=1745963970; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2WyL2xMXY/h3W3raFwPBVRPThikL44NlUcetTPcUj1c=; b=xSmGoBSFpEJGDLKEWC55t4ScdVG4ZVPMOvcVPr+cEqZtDA9rApMap8Iy4qoAh6rPki vEpVi+j7zZ4WXquLWvdGBX7uYpSEWhlD8dDEuDD5RqQfrfXAN/F91x+8bFpG4hf3HtEG 9/VYmggzmiDjzlMG3fFqOWs8t+MldxovGGfuhQ8pvhGsvY03JWom5qhyjxdj+Yjrnnw5 /soDydt89j5A6Z2Fp3fBtMpM8LUKHgcVODSj0VW/r4hmbmRCIMpakAt6WsN20nemn0s2 HjAnwafx1wirEuLO2/Srbvb1q105Al5feJLZRdX1dKToqu1CIwbz0NNx3dLqqJHTHLu2 1MGQ== X-Gm-Message-State: AOJu0YzLoBLGDBovKKh2dvJNppQMEu4vQZSvMbfDXFhfupl8qfxoeCRq YKG9HgOmzuvfG4HeBGUuw2IePpvWv3LStPX/zXj4ZqfaRgoz5WgjW9Z9mmn10KYAxzctGc7S+Ot LZrE= X-Gm-Gg: ASbGnctphSIWFsGzwps47H/lJT+thkKrLW7ic9SRdJj2IKWaDMP714nJ4kgzGG5VYKN M9Oad46ug+X4bM1qq2kOkK2UR4cxXwoIPpAgMBGZIfUZYEYgcxPcG3jsqCz3h4Q3P7uN9cUGpNl HcMbCHDENB6JrRw/JLjr1lChbFiRaBavfiG11zELtzTln9DUw6dxgVK7R5py824TayPlef1AWCd zfdClcYpvso5gkg9lg8Y9RLtxg+n7JmvwKKtMQAJpyz5IuH496dxGT+ZsLLlouDkMzrjdrOZmUy J4gdpmR3av04pQst8SohOAc1P5YhQIBwmZM4g7CVRXbwGVKAoQHUw709K+9tldzgBS95qY0y0tJ wUUo0IcwpiwQkimwxWphi X-Google-Smtp-Source: AGHT+IGXu9D/E6Y8htk5I6VD7HQ+l0EEcucqsKaG1t6kZBbUDJj2SggbN6uYn0qilGr2V8knEwVrLA== X-Received: by 2002:a05:600c:3d14:b0:43d:ed:acd5 with SMTP id 5b1f17b1804b1-4406ab97abbmr190953805e9.10.1745359170470; Tue, 22 Apr 2025 14:59:30 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:29 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 08/27] libcamera: swstats_cpu: Add support for YUV420 Date: Tue, 22 Apr 2025 22:59:01 +0100 Message-ID: <20250422215920.4297-9-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" From: Hans de Goede Add support for processing YUV420 data. Signed-off-by: Hans de Goede Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/swstats_cpu.cpp | 89 ++++++++++++++++++++++ src/libcamera/software_isp/swstats_cpu.h | 6 ++ 2 files changed, 95 insertions(+) diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index af407b4d..3ec9656c 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -13,6 +13,7 @@ #include +#include #include #include "libcamera/internal/bayer_format.h" @@ -288,6 +289,40 @@ void SwStatsCpu::statsGBRG10PLine0(const uint8_t *src[]) SWSTATS_FINISH_LINE_STATS() } +void SwStatsCpu::statsYUV420Line0(const uint8_t *src[]) +{ + uint64_t sumY = 0; + uint64_t sumU = 0; + uint64_t sumV = 0; + uint8_t y, u, v; + + /* Adjust src[] for starting at window_.x */ + src[0] += window_.x; + src[1] += window_.x / 2; + src[2] += window_.x / 2; + + /* x += 4 sample every other 2x2 block */ + for (int x = 0; x < (int)window_.width; x += 4) { + /* + * Take y from the top left corner of the 2x2 block instead + * of averaging 4 y-s. + */ + y = src[0][x]; + u = src[1][x]; + v = src[2][x]; + + sumY += y; + sumU += u; + sumV += v; + + stats_.yHistogram[y * SwIspStats::kYHistogramSize / 256]++; + } + + stats_.sumR_ += sumY; + stats_.sumG_ += sumU; + stats_.sumB_ += sumV; +} + /** * \brief Reset state to start statistics gathering for a new frame * @@ -313,6 +348,9 @@ void SwStatsCpu::startFrame(void) */ void SwStatsCpu::finishFrame(uint32_t frame, uint32_t bufferId) { + if (finishFrame_) + (this->*finishFrame_)(); + *sharedStats_ = stats_; statsReady.emit(frame, bufferId); } @@ -362,6 +400,20 @@ int SwStatsCpu::setupStandardBayerOrder(BayerFormat::Order order) int SwStatsCpu::configure(const StreamConfiguration &inputCfg) { stride_ = inputCfg.stride; + finishFrame_ = NULL; + + if (inputCfg.pixelFormat == formats::YUV420) { + patternSize_.height = 2; + patternSize_.width = 2; + /* Skip every 3th and 4th line, sample every other 2x2 block */ + ySkipMask_ = 0x02; + xShift_ = 0; + swapLines_ = false; + stats0_ = &SwStatsCpu::statsYUV420Line0; + processFrame_ = &SwStatsCpu::processYUV420Frame; + finishFrame_ = &SwStatsCpu::finishYUV420Frame; + return 0; + } BayerFormat bayerFormat = BayerFormat::fromPixelFormat(inputCfg.pixelFormat); @@ -430,6 +482,43 @@ void SwStatsCpu::setWindow(const Rectangle &window) window_.height &= ~(patternSize_.height - 1); } +void SwStatsCpu::processYUV420Frame(MappedFrameBuffer &in) +{ + const uint8_t *linePointers[3]; + + linePointers[0] = in.planes()[0].data(); + linePointers[1] = in.planes()[1].data(); + linePointers[2] = in.planes()[2].data(); + + /* Adjust linePointers for starting at window_.y */ + linePointers[0] += window_.y * stride_; + linePointers[1] += window_.y * stride_ / 4; + linePointers[2] += window_.y * stride_ / 4; + + for (unsigned int y = 0; y < window_.height; y += 2) { + if (!(y & ySkipMask_)) + (this->*stats0_)(linePointers); + + linePointers[0] += stride_ * 2; + linePointers[1] += stride_ / 2; + linePointers[2] += stride_ / 2; + } +} + +void SwStatsCpu::finishYUV420Frame() +{ + /* sumR_ / G_ / B_ contain Y / U / V sums convert this */ + double divider = (uint64_t)window_.width * window_.height * 256 / 16; + double Y = (double)stats_.sumR_ / divider; + /* U and V 0 - 255 values represent -128 - 127 range */ + double U = (double)stats_.sumG_ / divider - 0.5; + double V = (double)stats_.sumB_ / divider - 0.5; + + stats_.sumR_ = (Y + 1.140 * V) * divider; + stats_.sumG_ = (Y - 0.395 * U - 0.581 * V) * divider; + stats_.sumB_ = (Y + 2.032 * U) * divider; +} + void SwStatsCpu::processBayerFrame2(MappedFrameBuffer &in) { const uint8_t *src = in.planes()[0].data(); diff --git a/src/libcamera/software_isp/swstats_cpu.h b/src/libcamera/software_isp/swstats_cpu.h index fa47cec9..a043861c 100644 --- a/src/libcamera/software_isp/swstats_cpu.h +++ b/src/libcamera/software_isp/swstats_cpu.h @@ -71,6 +71,7 @@ public: private: using statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]); using processFrameFn = void (SwStatsCpu::*)(MappedFrameBuffer &in); + using finishFrameFn = void (SwStatsCpu::*)(); int setupStandardBayerOrder(BayerFormat::Order order); /* Bayer 8 bpp unpacked */ @@ -82,10 +83,15 @@ private: /* Bayer 10 bpp packed */ void statsBGGR10PLine0(const uint8_t *src[]); void statsGBRG10PLine0(const uint8_t *src[]); + /* YUV420 3 planes */ + void statsYUV420Line0(const uint8_t *src[]); void processBayerFrame2(MappedFrameBuffer &in); + void processYUV420Frame(MappedFrameBuffer &in); + void finishYUV420Frame(); processFrameFn processFrame_; + finishFrameFn finishFrame_; /* Variables set by configure(), used every line */ statsProcessFn stats0_; From patchwork Tue Apr 22 21:59:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23222 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 E04FFC331E for ; Tue, 22 Apr 2025 21:59:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 883B468B35; Tue, 22 Apr 2025 23:59:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="G+ioLDAb"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8C41068AD0 for ; Tue, 22 Apr 2025 23:59:32 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-43edecbfb46so42560845e9.0 for ; Tue, 22 Apr 2025 14:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359171; x=1745963971; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Unisxf724wKPeDmdCw8LDPHqe3S8flwsX/29uC+sYFk=; b=G+ioLDAbk6pnH/Gg5gp15ReYuMJAwYyEQtMj6Ui4ygXhkAThlsex5YjH7MxRQ6nEiM BSCA9MAysmsJH6den4lay4pjRkyGwzAbZQux3/7u0KV8dTjJ0awD5jypjTwdnr4TCvOW OLNW4Pd/5wbb0bVN7ZkJsPXH0P+0QSc0pGdMoY7sc3flccyN93O6ZSFKD6e+X4vFq9A1 /oUAeAgnXCccso/aEMGhwveuUXQdZF0scYkxlV/jUm00G9fSgdAgOUMH4aXkw0Htz+ge Uvmt0duJwe2SxFfcphSP9H3J7hzl7SY9UDjAd6dOdfejWa71YWUrQG1TuXJi77UQRVh7 UXMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359171; x=1745963971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Unisxf724wKPeDmdCw8LDPHqe3S8flwsX/29uC+sYFk=; b=nZ7N2KQjbnfvQPvrfFOoNk7adKIk19OuizXnp3tCouvrhloNRQCNVkwQKBRp1tw5PC qf+ezcu4AWWyhz96+RHzcc04aX/oqFw4x1bcFJUlp6hBzigRTU9KQzo2AwIphN6U5ifD lT0Smu67TEQWjTSGuA81A2vYe7oCZCA91f4emguqNUScftckYhPwZlUjvrzNEMgFVLyR dRQGN2ZDHlHl+twX4/bOFKXA4hVSrO3unGoVZf+76n2px2eGKotuoLxQ0oI6ae48/Apt 7vBMfGP6DcAy06u8Du37Pjvcl4qhlABjhoN4/sZDLegGbTlxV18Smgwn5kdTR4hsz9jS bNMA== X-Gm-Message-State: AOJu0YzHKFUtN745chHjZuFSQ49k8rjG/4nr1oKv2a2EF2qWAMWmyLY2 sy02Fgb2BR+6MQ6lJdQhEgYULd2RnPA6YEtSm/M1JxanBfe1WmrWxg1p2oaDuouJ+ruUG3H6Qki G88U= X-Gm-Gg: ASbGncu5ZosOvwvOWEOgG7ikMRQ4FJPHxBNdHtvhqgeT6bdqB8DuwLxcoSc8V3aOPlI 2OSjR9blKC+3ruTgO8xcmIXRzbHiQK+f4MQn904q1zcRZj858jboQ4ubL2JRhmz6KvqMDNGOeOj TW8KBfRSuiK4aFIXg40GL3XoaELagcle9AWnAK6krD20tLLAnU67mNjRlAmmhNXgy+ymENqoovf Jx+2DhWdiHxvbCR/4kqzw1kudDAF0bV3FubRmJFGoFiPJa7AP25EJ19T6KwS1lTd3BP2/z4yfa3 ojYglcGn1oeWsX3lLL/80poq/ynJwDqPr9DIlZWzW4ilFgBTG4J3Hi52TS8x0rWpRXK2ZbWnet1 Q7TL9hAv8787QBviBApwgzyjjANgRerk= X-Google-Smtp-Source: AGHT+IHW63qwj7PPXPxJPTw2zh+7AfDT6Xn18mDDfoGgc5cgoftQ1Iwu9urWWeFU2O7YJ8F0u5cAxQ== X-Received: by 2002:a05:600c:8711:b0:43d:934:ea97 with SMTP id 5b1f17b1804b1-4406ac0f82bmr143845175e9.27.1745359171446; Tue, 22 Apr 2025 14:59:31 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:31 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 09/27] libcamera: swstats_cpu: Move header to libcamera/internal/software_isp Date: Tue, 22 Apr 2025 22:59:02 +0100 Message-ID: <20250422215920.4297-10-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" From: Hans de Goede Move the swstats_cpu.h file to include/libcamera/internal/software_isp/ so that it can be used outside the src/libcamera/software_isp/ directory. Signed-off-by: Hans de Goede Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/software_isp/meson.build | 1 + .../libcamera/internal}/software_isp/swstats_cpu.h | 0 src/libcamera/software_isp/debayer_cpu.h | 2 +- src/libcamera/software_isp/swstats_cpu.cpp | 2 +- 4 files changed, 3 insertions(+), 2 deletions(-) rename {src/libcamera => include/libcamera/internal}/software_isp/swstats_cpu.h (100%) diff --git a/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build index a7e606d2..df7c3b97 100644 --- a/include/libcamera/internal/software_isp/meson.build +++ b/include/libcamera/internal/software_isp/meson.build @@ -5,4 +5,5 @@ libcamera_internal_headers += files([ 'debayer_params.h', 'software_isp.h', 'swisp_stats.h', + 'swstats_cpu.h', ]) diff --git a/src/libcamera/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h similarity index 100% rename from src/libcamera/software_isp/swstats_cpu.h rename to include/libcamera/internal/software_isp/swstats_cpu.h diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index d6820d5e..182607cd 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -19,9 +19,9 @@ #include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/software_isp/swstats_cpu.h" #include "debayer.h" -#include "swstats_cpu.h" namespace libcamera { diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 3ec9656c..e81c96a2 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -9,7 +9,7 @@ * CPU based software statistics implementation */ -#include "swstats_cpu.h" +#include "libcamera/internal/software_isp/swstats_cpu.h" #include From patchwork Tue Apr 22 21:59:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23223 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 78275C3320 for ; Tue, 22 Apr 2025 21:59:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2187268B39; Tue, 22 Apr 2025 23:59:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="mPvkJEjG"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1526168B25 for ; Tue, 22 Apr 2025 23:59:33 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-43cfa7e7f54so2378965e9.1 for ; Tue, 22 Apr 2025 14:59:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359172; x=1745963972; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wJmpJgXrFEG5KEN1zSnXvlqRixc3EGKyYYkVA8Fbs4k=; b=mPvkJEjGOKGn0UcVsN9/UcxBEa+22ZED2/h5Cgio7sFL3lKCBuDdRqgwwxRzYXg6oE qos6IBBQ++kfOgtGIETRVTHKftZI5641ychmnrxEO06goxaGOCz/4QDz7EP1k3delqF5 +LcbCrr3zENfRR/zl9YYEMFk858n73cEGVmDkLhKTPeMq7eAQFGzisjNX23MW+krrcYX //0Y1oc7PwSsHOp/pyHAsLbODcGNZMZKawJij5VyboRGG8ZqjgdEd8JMcjgH32ZL9iR0 ffa6kj38cqHu/9w692cfaPsltekXatAHmYSJoTlFIpnPs1xvh6S8E0VUwWNvXKG83KG1 V7ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359172; x=1745963972; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wJmpJgXrFEG5KEN1zSnXvlqRixc3EGKyYYkVA8Fbs4k=; b=PP5JKOnxiD3U1IYUKAnWSnAeCQluJnaRb1mAmn0ZcNYWuxkKALDsKuxzRVDV7eEkaX HDkMaDNPMIdAiTfs8O7p9eell7mNq4WhJYvzLUs07BoZKGiagqvWp2W7OnvHkICXw67i jV05vmu4xQtWAQYPXdbIGWHSFxtJo96AhrqntfvI7w2oHi2edvQrO7YmjPlDVg1HEaXM 0df4o//T0va5iYjIL6IXhQFnKtJiZYHp1J3ETNO6wkfTze77j0KIE0PGKhJowbnPEuGU o5TDTI4bLlb2aUtbuyguJ4Z9JLXQM7DzMxlUh2VKIiYwJoIgyVCOjZh/0omPr92u3DZS 7miw== X-Gm-Message-State: AOJu0Yx9DWDqnTDyYW5Or7EjO1o3rLXbTJMqHRWx4q0Jis3KdKmZXcdl JXqVibQR/1zEppBZ1nrbycq53T6p5OnHcFwnXwdkxVp6li1uF7nNGO5tdA4uRx02RO89tiyhxKq d558= X-Gm-Gg: ASbGncsN+7mEE0lbQyH6edvsopYWBP7CmlleLVTSC3cRUb/4irge2XuvLA0wnAEXF38 dhBrMgfgICZy212I98AVkGYs+0TJjiqCoSTFLQBs1M+3Z9KlW5x2tYyYeplLMwizurdBAYuVODy oVbXh/R7GR0RbdFnEEmG+0Ahp36nyUMc4/T4eG98UeDWTvxAGj+27ujBylDMlYmDXyPkTnZjP37 RWVVQy0wkx02fEaj8nBQATNFJv+2w65YsM/wwcuorY0AEhT3+ITMgdke0w8WoTkxpAX650NI/ip OFhelDIN0MRr0JTT48UgJDSv9K+r2oiyAqqu5HJoUngkv8vdtwn1cRnilPUxKKLcg5KeXzi95KZ Vfo3366u+MGnPFjNFBlnh X-Google-Smtp-Source: AGHT+IFubzulSIaleFtvZ/1sAxA9nhmqbt6gLnDqmrgkbiAZNHA75lMTureXquHN6a0/h2IC8/wejg== X-Received: by 2002:a05:600c:698e:b0:440:6a68:826a with SMTP id 5b1f17b1804b1-44091f6f402mr5184395e9.13.1745359172422; Tue, 22 Apr 2025 14:59:32 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:31 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 10/27] libcamera: software_isp: Start the ISP thread in configure Date: Tue, 22 Apr 2025 22:59:03 +0100 Message-ID: <20250422215920.4297-11-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" OpenGL is not thread-safe and in fact associates invisible handles with the threadid of the calling context. As a result we need to make configure() and process() in SoftISP execute on the same thread. Move start thread into configure() as a first step towards this. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/software_isp.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 28e2a360..7bee8f06 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -159,8 +159,6 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, metadataReady.emit(frame, metadata); }); ipa_->setSensorControls.connect(this, &SoftwareIsp::setSensorCtrls); - - debayer_->moveToThread(&ispWorkerThread_); } SoftwareIsp::~SoftwareIsp() @@ -262,6 +260,9 @@ int SoftwareIsp::configure(const StreamConfiguration &inputCfg, if (ret < 0) return ret; + debayer_->moveToThread(&ispWorkerThread_); + ispWorkerThread_.start(); + return debayer_->configure(inputCfg, outputCfgs, ccmEnabled_); } @@ -343,7 +344,6 @@ int SoftwareIsp::start() if (ret) return ret; - ispWorkerThread_.start(); return 0; } From patchwork Tue Apr 22 21:59:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23224 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 93202C32A2 for ; Tue, 22 Apr 2025 21:59:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0267868B3C; Tue, 22 Apr 2025 23:59:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="IMyfQDKD"; dkim-atps=neutral Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D22568B2B for ; Tue, 22 Apr 2025 23:59:34 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43cec5cd73bso36789445e9.3 for ; Tue, 22 Apr 2025 14:59:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359173; x=1745963973; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JZAXC64SF7x+tdFk+QdWciV7YnJqIucxPuLyTZBOoB0=; b=IMyfQDKDN/gTLC2PTnZw5zRaVLdj9L7ig+Ef+HSoJbepEeFDHUoErWio8ZMF5CPyGa Dm9BRYnAlTMCfE/QNwrbr8K2S336ccU2N1xZswPlJcJy/9ytPwoCPFUHFtzU8BalIdiY 7NkLo2/Hs/L22dZwUV7XU/7h25JBjBlYSAZ89gkVsu9jldjBRm5jfX/TYQ8TKW7B8kmJ RImFu9UBUM1gIxtB9saxsyrpuN54N3YVlOdHpS9bcodcP6mEicbLnbcqgcofa9GXLtlM GvZ4qZ6DFAMTCT9j/vxCsmyLAGShhXJqy4eU28AJRXxKQSAEV3LWqyETr7hvMPPAaDPN jrsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359173; x=1745963973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JZAXC64SF7x+tdFk+QdWciV7YnJqIucxPuLyTZBOoB0=; b=khvvfqCclxVc92kVmBt3lyFVnHKJtFOEaAVHeQ7iS/qm1Sq2XS5EywAUgqkl9eXxK9 GphDRbM2iiUYNkeA+vWuavIDHFNOt2+MgnPbhoLBkbeCuXxY0soQFknMutz7Kr3y7OU1 1Y/RzmdJNQw++xcg1DZcDmojioY0i7iEG0AqvBKCvTr/TJGA/jgALuSpau8S/1HjZpLB yKojddghVrjhKY4fXx87NIcrxa+NArvUfmrfo9+ZEugvtCpQ8WjsLjSPRsj7MYUw0jEp IU3E/+CqQ0nOzFZUjbeOpLznVYrIjTeshwdHJStustEePrbiM103gIOoJBxBBguXn4ZT I3MA== X-Gm-Message-State: AOJu0YxRoJfXbpApg5uFqkYOZsyOfmBxXgoaU0ZSBWxkDJeZ1hVdllI1 dfkbtJhtV8GH4FT9CbSqz9vGf80GE9vXnDyWBElXYGXymMinRJYKgfOFZXFQZwVjYgPr0ri920P iFeA= X-Gm-Gg: ASbGncvXi39NfDYU3rpD4Zz7Gxy62CnrnOedPVUoKxO0lbXXk/wEVTQeQ2psqI5sa58 2gN2sR9jmig1A8MWwyRxPwMA6+YFrCtifvurKigLspbQ93Efeq8pZwhIdY1hZZZalEZEQpb+y/L Pk/mT5qlPxZuQRWLXI1zCZtm+HN8skfmTxN11wDJuObL4bCK79kn3a+yWMCnfk2ESPk9VqqKC6O M4U1hpHz4XSLzwowTL/u18tLkKpjI6Y3qQKYkha3X6k6+mOjWTTN6cNCNsJ70uICtmaCUsk6mTI rPn+cj0kJmbaqQ4LPJFLZaNBOvk2Zc4bnl0WrZAWZ3D3Gcn0/RXwVqo5yl5LaleO3HfNgPWPZu1 d351XpYB/jktiVl6mWR+6 X-Google-Smtp-Source: AGHT+IE4eoEIb+FUPEKdYVaNv69yaImxYFh6cymcfpC4HucULbXK3xKiFi8u5uwLytf9BOpk4sUQtg== X-Received: by 2002:a05:600c:3c9b:b0:43c:ec4c:25b1 with SMTP id 5b1f17b1804b1-4406abfbcd7mr137550675e9.23.1745359173450; Tue, 22 Apr 2025 14:59:33 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:32 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 11/27] libcamera: software_isp: Move configure to worker thread Date: Tue, 22 Apr 2025 22:59:04 +0100 Message-ID: <20250422215920.4297-12-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" OpenGL requires both configure() and process() to operate on the same thread. As preparation for that, move current CPU configure into the WorkerThread with a ConnectionTypeBlocking invocation of &DebayerCpu::configure. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/software_isp.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 7bee8f06..e36aa246 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -263,7 +263,9 @@ int SoftwareIsp::configure(const StreamConfiguration &inputCfg, debayer_->moveToThread(&ispWorkerThread_); ispWorkerThread_.start(); - return debayer_->configure(inputCfg, outputCfgs, ccmEnabled_); + return debayer_->invokeMethod(&DebayerCpu::configure, + ConnectionTypeBlocking, inputCfg, + outputCfgs, ccmEnabled_); } /** From patchwork Tue Apr 22 21:59:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23225 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 616C1C331F for ; Tue, 22 Apr 2025 21:59:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BF1B068B37; Tue, 22 Apr 2025 23:59:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="SIfIwKwY"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0902068AD9 for ; Tue, 22 Apr 2025 23:59:35 +0200 (CEST) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43cfa7e7f54so2379075e9.1 for ; Tue, 22 Apr 2025 14:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359174; x=1745963974; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pIYKGEgJHbPpVkSe0i1IAX+OEn10lQm6h+GbVEYh0uM=; b=SIfIwKwYFSZuJHPc+NTE3USP30p3WgzoYbEmMPJulnJtzOK++e3EB7NXNMk89fnbJi zAHj2vMhQSUVJB4kmYJj1fskWefeYXIcTkjaMjsiL3xUjPQLLdyR2szv2xl8Jjn3Hqcm gqkzyY2ZcTuxD9tbDmhDU8DV91SUfgKVB74fsWM367H1jtdT49/usnOTqdxxKuc71vKS nkTrBKc7EbF4pYvRbBxeTuZqcVTTGXRnwyZhrzK3jTC56z1ZCus2/TRraV+df+zN2222 wGNjIXPP1z6Z/mr1ezxu4OrUfWLBo0lDmrkja4CWp6tKueCX0BmccCv16OjwikbwmAz8 acpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359174; x=1745963974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pIYKGEgJHbPpVkSe0i1IAX+OEn10lQm6h+GbVEYh0uM=; b=F7i3Tvt4Ayn1c9SfkKcmlFfjCL22AJfx3649Ncq9S5zYKEJipKyziH0N5Ca4cOML1l mH0l69MPfrxISvcuuHZNjmha2NQpi9vilOa0//Qf0+cexSA2kwac464X9+xClAZDLt2r ml3SiuMNuP0i3cW7RejXE9Dl82r4Mp1DvM8Dtls63KAAy+pdpPD1vciyulzMljnwy27f Hdp1xCmolfDdNxxGlZOTWeGqW4QJNLfODTDwyEAoRTW2RxmM2xfIvr4JKFvYEnCmYYfb eV2NMoqM/wUld6R/WIh2/pG+xR/AL7x84mliqUqN8GKQ7/V074MTOV3EK8nrkfTBRldC et1w== X-Gm-Message-State: AOJu0YxQxDw+rMXtV+UXFdc0OHL57rMQXPqlquZC9wENgj8PQBIMYbTe 8sA5d+ed2U98pxEGcr8URYWAJhvYmdZT3vg7xAzP2F0cVtdrykIYxxjUqtkrDgODit7IskFBvme BDUU= X-Gm-Gg: ASbGncvFw4d7OAr8+JT5EQnK4IZxI3MeYTgfdHcNgrovQweVTj1osocchcQhv/Bt6Ii BmHwjuvfb98CO/JkSfEPoqm21KmenO1Zf6/69QYmgn0tUbwPHFoaI3oq+f5+mryhQ7nqg37faFr oNhpqQZXEN9CgAYgVZDcLk8yAxUdlrAANZ5L85f8z/D47Q6c922Q58p1DEUH/RZA4195exYffD+ D/jFsk0I2d/P1pDSQJV7kNtjSSXUo4on2onwtv6BB89A0i6+stuwf922yoL8FOreKD+0ZLAkSK+ aWdDke2fjJrxSp9d4zLlFGrY7HFnXSfV18knFbwnXbFtvin61cHMbPuXyt7swNCZ/6+kxgcl35a CfByaRYZ8RrlxTLumC9XK X-Google-Smtp-Source: AGHT+IFnWONnQx15SzWWQSn3bPx2mTYSYvL9cjSABg6B9o3vsAw6PHgKh6LHwWk5QUZhUu0NnqIb7g== X-Received: by 2002:a05:600c:4e0a:b0:439:5f04:4f8d with SMTP id 5b1f17b1804b1-44091f1facdmr4124395e9.12.1745359174334; Tue, 22 Apr 2025 14:59:34 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:33 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 12/27] libcamera: software_isp: Virtual base class reference in invokeMethod Date: Tue, 22 Apr 2025 22:59:05 +0100 Message-ID: <20250422215920.4297-13-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Use the virtual base class function pointer in invokeMethod. When we point the debayer_ object to a different class the instantiation of the virtual method will be invoked. This means we can take a pointer to DebayerCpu or DebayerOpenGL and get the desired function @ invokeMethod. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/software_isp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index e36aa246..c3dc21de 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -263,7 +263,7 @@ int SoftwareIsp::configure(const StreamConfiguration &inputCfg, debayer_->moveToThread(&ispWorkerThread_); ispWorkerThread_.start(); - return debayer_->invokeMethod(&DebayerCpu::configure, + return debayer_->invokeMethod(&Debayer::configure, ConnectionTypeBlocking, inputCfg, outputCfgs, ccmEnabled_); } @@ -388,7 +388,7 @@ void SoftwareIsp::stop() void SoftwareIsp::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output) { ipa_->computeParams(frame); - debayer_->invokeMethod(&DebayerCpu::process, + debayer_->invokeMethod(&Debayer::process, ConnectionTypeQueued, frame, input, output, debayerParams_); } From patchwork Tue Apr 22 21:59:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23226 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 DA707C327D for ; Tue, 22 Apr 2025 21:59:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7285B68B44; Tue, 22 Apr 2025 23:59:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="wDRew07J"; dkim-atps=neutral Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5C84D68B30 for ; Tue, 22 Apr 2025 23:59:36 +0200 (CEST) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-39c1ef4acf2so3680184f8f.0 for ; Tue, 22 Apr 2025 14:59:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359175; x=1745963975; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NoLLyeMcYw0WZHw+CBw8JHWe/oH++8f3vXYrkMExzgM=; b=wDRew07JdnZV2xaQZXYm0IINk4gR3Sz1PWlp6CjEEl8CSC7bd+vF95bb8LNKOOY3SH VADRN4/gQy5uhPZrhC6AyMsBl370fwvnWw4ZCAt+OCEqHqJwYL60YpAQi9Br/2/rx5A6 7syZnu3Ysz/8vthHwLHX1gyKo/hTYaEqGgstX9oTOjbx6LtxIqqPWzz/Lcs8ad4I4OJd XOSRgGDaIx5lbiKB4w3UXHl0zy937RP5qRcO6PFXg1hpBGYqPHLyWu1XBRunTkcdrwBg bPiV05eghYPrH7nkyTQPjYSR3sqjedPDop36cHq1n87Xn8d3gFe3fcbVLG01kUdvQ15I R9tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359175; x=1745963975; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NoLLyeMcYw0WZHw+CBw8JHWe/oH++8f3vXYrkMExzgM=; b=FE8MFmKKfy2oNE6eGfql9BagvtIfiSuSlwArhiSoAkXO4eoWJB6J5InQm40pG2TREI SnFaxMlJaWacPpuHs4mzONmDKpgmPHo95MTjZ+gVgs/zRlf3TrH/evKnCqLXuxFI+tO4 VdcQ9zBCMz5lLpdJbNUpMBhRDpv+m3a+uyThZdT6oacBzWfTboj2P6mOBjfn9mXGIa1q CpEmTzGab02ebM6FxC7fieQ153nyRkUxfxdjjudgxs1EEfbkCZQxz2WfLux9T2q2AaZY pkH2RW6DhobHL5PmKcMaO8/gScU+HW/qq3SBI4xehjPRuaFgRq72c+ljCI3w3HDHCSPY HdqQ== X-Gm-Message-State: AOJu0Yy0IUu3OXEt0k5VcxAAt4Mv2rRyZZpJTWnXzoxPTTKPfCp+qQWI EvHEOK/liUeE3FqUl5/fVqYSyfb49XkaCVMttETSGGpHKXqJs8WonsLWb+/kD9p4uKLyexjtv2W MW1E= X-Gm-Gg: ASbGncvbL2/FopSa74uqz0t2jh1YATf6kuo6Xa13Ahc5Xd7fJ+Uik5gmojWB7H07XPo g2YwtcgOJKKmtGn4ULK+BLJPP20+MjERDasXSkVeWSo4w0TVUYyFp9/vhmP8LNW3IzsY1F701iZ mSR/TnjhrFZ6JhAlxlUOwATqN+UjVsq6vetg2mSPANn5e75I2mCMVMH+Y1F8jF1/NnPI852xzNu 35q5F8Z9HLh9rzG0zQM81LMxJpoveEDW6V/lDFTE+2/Tt7AFhs2K9w6QI9rkwmx1WsBVhCgmCtd Oxp4MZuPhnTUVaPWB+hqEnXtmxeuvXJ4hiUMUrhtLoWWg71Cwk1ZfCGH6pDKv/4DMUfC4pIryTW jT9TNINsUjOTKxics7Y6WTRXs+Cm2V2Y= X-Google-Smtp-Source: AGHT+IG8XChv8dt+ee21hrbNGl8xt2CF5TIozgTXTi/ysEcKfhiuZjU6Tm79O9RVY8LPTY3l7PQoZQ== X-Received: by 2002:a5d:598b:0:b0:390:e8d4:6517 with SMTP id ffacd0b85a97d-39efba3d0e2mr14041727f8f.21.1745359175462; Tue, 22 Apr 2025 14:59:35 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:34 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 13/27] libcamera: software_isp: gbm: Add in a GBM helper class for GPU surface access Date: Tue, 22 Apr 2025 22:59:06 +0100 Message-ID: <20250422215920.4297-14-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" A helper class to interact with GBM. This will allow us to specify the internal storage format of the CPU when making a texture for the Debayer vertext/fragment shaders and thus ensure we receive an uncompressed and untiled output buffer. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/gbm.cpp | 136 +++++++++++++++++++++++++++++ src/libcamera/software_isp/gbm.h | 52 +++++++++++ 2 files changed, 188 insertions(+) create mode 100644 src/libcamera/software_isp/gbm.cpp create mode 100644 src/libcamera/software_isp/gbm.h diff --git a/src/libcamera/software_isp/gbm.cpp b/src/libcamera/software_isp/gbm.cpp new file mode 100644 index 00000000..1be00f1f --- /dev/null +++ b/src/libcamera/software_isp/gbm.cpp @@ -0,0 +1,136 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Linaro Ltd. + * + * Authors: + * Bryan O'Donoghue + * + * egl.cpp - Helper class for managing GBM interactions. + */ + +#include +#include + +#include +#include +#include +#include + +#include "gbm.h" + +namespace libcamera { + +LOG_DEFINE_CATEGORY(GBM) + +GBM::GBM() { + fd_ = 0; +}; + +GBM::~GBM() { + if (gbm_surface_) + gbm_surface_destroy(gbm_surface_); + + if (gbm_device_) + gbm_device_destroy(gbm_device_); + + if (fd_ >= 0) + close(fd_); +}; + +// this should probably go into its own class to deal with the +// allocation and deletion of frambuffers attached to GBM devices/objects +int GBM::initSurface(uint32_t width, uint32_t height) +{ + const char *dri_node = "/dev/dri/renderD128"; //TODO: get from an env or config setting + + fd_ = open(dri_node, O_RDWR | O_CLOEXEC); //TODO: CLOEXEC ? + if (fd_ < 0) { + LOG(GBM, Error) << "Open " << dri_node<< " fail " << fd_; + return fd_; + } + + gbm_device_ = gbm_create_device(fd_); + if (!gbm_device_) { + LOG(GBM, Error) << "gbm_crate_device fail"; + goto fail; + } + + // GBM_FORMAT_RGBA8888 is not supported mesa::src/gbm/dri/gbm_dri.c::gbm_dri_visuals_table[] + // This means we need to choose XRGB8888 or ARGB8888 as the raw buffer format + gbm_surface_ = gbm_surface_create(gbm_device_, width, height, GBM_FORMAT_ARGB8888, + GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR); + if (!gbm_surface_) { + LOG(GBM, Error) << "Unable to create linear gbm surface"; + goto fail; + } + + format = libcamera::formats::ARGB8888; + + return 0; +fail: + return -ENODEV; + +} + +int GBM::mapSurface() +{ + gbm_bo_ = gbm_surface_lock_front_buffer(gbm_surface_); + if (!gbm_bo_) { + LOG(GBM, Error) << "GBM input buffer object create fail"; + return -ENODEV; + } + gbm_surface_release_buffer(gbm_surface_, gbm_bo_); + + bo_fd_ = gbm_bo_get_fd(gbm_bo_); + + if (!bo_fd_) { + gbm_surface_release_buffer(gbm_surface_, gbm_bo_); + LOG(GBM, Error) << "Unable to get fd for bo: " << bo_fd_; + return -ENODEV; + } + + stride_ = gbm_bo_get_stride(gbm_bo_); + width_ = gbm_bo_get_width(gbm_bo_); + height_ = gbm_bo_get_height(gbm_bo_); + offset_ = gbm_bo_get_offset(gbm_bo_, 0); + framesize_ = height_ * stride_; + + map_ = mmap(NULL, height_ * stride_, PROT_READ, MAP_SHARED, bo_fd_, 0); + if (map_ == MAP_FAILED) { + LOG(GBM, Error) << "mmap gbm_bo_ fail"; + return -ENODEV; + } + + LOG(GBM, Debug) << " stride " << stride_ + << " width " << width_ + << " height " << height_ + << " offset " << offset_ + << " framesize " << framesize_; + + return 0; +} + +int GBM::getFrameBufferData(uint8_t *data, size_t data_len) +{ + struct dma_buf_sync sync; + + gbm_surface_lock_front_buffer(gbm_surface_); + + sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ; + ioctl(bo_fd_, DMA_BUF_IOCTL_SYNC, &sync); + + if (data_len > framesize_) { + LOG(GBM, Error) << "Invalid read size " << data_len << " max is " << framesize_; + return -EINVAL; + } + + memcpy(data, map_, data_len); + + sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ; + ioctl(bo_fd_, DMA_BUF_IOCTL_SYNC, &sync); + + gbm_surface_release_buffer(gbm_surface_, gbm_bo_); + + return 0; +} +}; //namespace libcamera diff --git a/src/libcamera/software_isp/gbm.h b/src/libcamera/software_isp/gbm.h new file mode 100644 index 00000000..9ccfb1ba --- /dev/null +++ b/src/libcamera/software_isp/gbm.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Linaro Ltd. + * + * Authors: + * Bryan O'Donoghue + * + * gbm.h - Helper class for managing GBM interactions. + */ + +#pragma once + +#include + +#include +#include + +namespace libcamera { + +LOG_DECLARE_CATEGORY(GBM) + +class GBM { +public: + GBM(); + ~GBM(); + + int initSurface(uint32_t width, uint32_t height); + int mapSurface(); + int getFrameBufferData(uint8_t *data_out, size_t data_len); + struct gbm_device *getDevice() { return gbm_device_; }; + struct gbm_surface *getSurface() { return gbm_surface_; }; + uint32_t getFrameSize() { return framesize_; }; + uint32_t getStride() { return stride_; }; + + PixelFormat format; + +private: + int fd_; + struct gbm_device *gbm_device_; + struct gbm_surface *gbm_surface_; + + struct gbm_bo *gbm_bo_; + uint32_t width_; + uint32_t height_; + uint32_t stride_; + uint32_t offset_; + uint32_t framesize_; + void *map_; + int bo_fd_; +}; + +}; From patchwork Tue Apr 22 21:59:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23227 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 60908C331E for ; Tue, 22 Apr 2025 21:59:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8134C68B4A; Tue, 22 Apr 2025 23:59:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YtR+0mZF"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 477A368ADB for ; Tue, 22 Apr 2025 23:59:37 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-43d04dc73b7so52250695e9.3 for ; Tue, 22 Apr 2025 14:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359177; x=1745963977; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xk1344nZ8W/t2QKGcYFtSu2hlITWsBUFu9+PpTYsa9k=; b=YtR+0mZFBH22j8/i4ApfGnmJ/uM+5AqBDKsq6FYkyk0IEE6iNK1wHEq6sjz8iW4dab MvgKbKnyfFhE5tNeKSMVWdaEKasrQxTLl73JJwgEVnCYVoWhXGzBqHGq2/EzZiEo4sMp JnrU67Zk3Vsu4rFtz892e+X9vgVfGT2mDtqdgU7PmGePBGNcggNvTzfhfpz3i0dVceip 9NoCUz3/hlZ9E8lF2pW5nbhJ9P8VfhhVWDZl87mBmJzZN+Nb55LMvUT7jVis4wSXXtCf 2QCn6BvIu2FU48QHfj6I0/18y8usVJNVRiHwhzqg6wNJOA4xDgUowIDvOUzDwviNsofc xDbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359177; x=1745963977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xk1344nZ8W/t2QKGcYFtSu2hlITWsBUFu9+PpTYsa9k=; b=wNPHXqXIPpy2WBScv7fpBJLmuxPSxEm5GX5G/0ne7M7D6R5+Mq8AcqSKsXZdhLvsEA 2OT2FAYPoDA0foNq2kvqYYE0qZk8kNLoQf6vjWRG7y9a1oOiX0QPcC5Hjd3VDVWGKqzw QmG9azWplgS+HVrTUf+EfRoEMFoxTia8s+Q+qo1XccaS/H5zv0IYT9wSiuEfiSdwANDX 0Hr9HbyO7U4QRPYU1UNXAdenwPaeY6Rqgl9ea6S8FupMv5DawUe9Ky+Z4P17KI9/lZf8 yOLPUQCRcxDifZyqZNwPq2ZenfmJZXMusNeP1Cc+Gx1lbQOzr3nlOrkk6giFyu13tXXY 4EBg== X-Gm-Message-State: AOJu0YxtSXFc7MWam2LGnBot86j5sf6lF+nUeKJEqUxC6XjVgSak4RpO wKUtHCZGtjtSyIfwBSlc5hFQL7ksmsSrgWPRfmv0uI4+gL/SvjVMpdRqcU+OGhw6D+5ULD6z90u lk+4= X-Gm-Gg: ASbGnct+wyZwWsTlmjbrOl0uWAj2XlF59x0N/d9GKBihDYTAIvwPwjmF2tqhRkjpwBh TGZo1kc6k6OotZqgvebnYCa22Z/WdTNJFSn7iDqxtw9XS5nOs2zVFZPDQBCwmUOkbBLAS7OXAqQ lrydquoEnSmKHGv/G8JmWK0OS2Wuzz5iRtyPw1sM/N9Y9d/g9Zq6Dr2nSVFr0OMe2PZ55q8SpVC /58C/a6Y5W7fZvie2EiB3w3g1NEf1skucnNrESV55YoMtZLRgkv9kAR84c1i1fAoVzk3IXHvYxN Dcw5R/dRyXQQm+p7I1ymh7dK5aW5oosiJfuPmlwB8lFxWjQzHz1RtxEYN5iudxQQ3IpPt0uY6iK RS95CWl3/k2hutgz1MmIctq9YWl4Mm2g= X-Google-Smtp-Source: AGHT+IGxREPG94hstT9WkfsbJ3FRwL1My8OSde7/zXPcC10spvyfsf5DaIBLZH+LPFMKRpVAc/b3aw== X-Received: by 2002:a05:600c:a143:b0:43d:878c:7c40 with SMTP id 5b1f17b1804b1-44076c9c6fbmr105466655e9.10.1745359176550; Tue, 22 Apr 2025 14:59:36 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:35 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 14/27] libcamera: software_isp: egl: Introduce an eGL base helper class Date: Tue, 22 Apr 2025 22:59:07 +0100 Message-ID: <20250422215920.4297-15-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Introduce an eGL base helper class which provides an eGL context based on a passed width and height. The initGLContext function could be overloaded to provide an interface to a real display. A set of helper functions is provided to compile and link GLSL shaders. linkShaderProgram currently compiles vertex/fragment pairs but could be overloaded or passed a parameter to link a compute shader instead. Breaking the eGL interface away from debayering - allows to use the eGL context inside of a dma-buf heap cleanly, reuse that context inside of a debayer layer and conceivably reuse the context in a multi-stage shader pass. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/egl.cpp | 346 +++++++++++++++++++++++++++++ src/libcamera/software_isp/egl.h | 106 +++++++++ 2 files changed, 452 insertions(+) create mode 100644 src/libcamera/software_isp/egl.cpp create mode 100644 src/libcamera/software_isp/egl.h diff --git a/src/libcamera/software_isp/egl.cpp b/src/libcamera/software_isp/egl.cpp new file mode 100644 index 00000000..c3eb8290 --- /dev/null +++ b/src/libcamera/software_isp/egl.cpp @@ -0,0 +1,346 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Linaro Ltd. + * + * Authors: + * Bryan O'Donoghue + * + * egl.cpp - Helper class for managing eGL interactions. + */ + +#include +#include + +#include +#include +#include +#include + +#include "egl.h" + +namespace libcamera { + +LOG_DEFINE_CATEGORY(eGL) + +eGL::eGL() +{ +} + +eGL::~eGL() +{ +} + +// Create linear image attached to previous BO object +int eGL::createDMABufTexture2D(eGLImage *eglImage, int fd) +{ + int ret = 0; + + eglImage->stride_ = eglImage->width_ * eglImage->height_; + eglImage->offset_ = 0; + eglImage->framesize_ = eglImage->height_ * eglImage->stride_; + + LOG(eGL, Info) << __func__ << " stride " << eglImage->stride_ << " width " << eglImage->width_ << + " height " << eglImage->height_ << " offset " << eglImage->offset_ << " framesize " << + eglImage->framesize_; + + // TODO: use the dma buf handle from udma heap here directly + // should work for both input and output with fencing + EGLint image_attrs[] = { + EGL_WIDTH, (EGLint)eglImage->width_, + EGL_HEIGHT, (EGLint)eglImage->height_, + EGL_LINUX_DRM_FOURCC_EXT, (int)GBM_FORMAT_ARGB8888, + EGL_DMA_BUF_PLANE0_FD_EXT, fd, + EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, + EGL_DMA_BUF_PLANE0_PITCH_EXT, (EGLint)eglImage->framesize_, + EGL_NONE, EGL_NONE, /* modifier lo */ + EGL_NONE, EGL_NONE, /* modifier hi */ + EGL_NONE, + }; + + eglImage->image_ = eglCreateImageKHR(display_, EGL_NO_CONTEXT, + EGL_LINUX_DMA_BUF_EXT, + NULL, image_attrs); + + if (eglImage->image_ == EGL_NO_IMAGE_KHR) { + LOG(eGL, Error) << "eglCreateImageKHR fail"; + ret = -ENODEV; + goto done; + } + + // Generate texture, bind, associate image to texture, configure, unbind + glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eglImage->image_); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + +done: + return ret; +} + +void eGL::destroyDMABufTexture(eGLImage *eglImage) +{ + eglDestroyImage(display_, eglImage->image_); +} + +// +// Generate a 2D texture from an input buffer directly +void eGL::createTexture2D(eGLImage *eglImage, uint32_t width, uint32_t height, void *data) +{ + glBindTexture(GL_TEXTURE_2D, eglImage->texture_); + + // Generate texture, bind, associate image to texture, configure, unbind + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data); + + // Nearest filtering + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + // Wrap to edge to avoid edge artifacts + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); +} + +int eGL::initEGLContext(GBM *gbmContext) +{ + EGLint configAttribs[] = { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_NONE + }; + + EGLint contextAttribs[] = { + EGL_CONTEXT_MAJOR_VERSION, 2, + EGL_NONE + }; + EGLint numConfigs; + EGLConfig config; + EGLint major; + EGLint minor; + + if (!eglBindAPI(EGL_OPENGL_ES_API)) { + LOG(eGL, Error) << "API bind fail"; + goto fail; + } + + //TODO: use optional eglGetPlatformDisplayEXT ? + display_ = eglGetDisplay(gbmContext->getDevice()); + if (display_ == EGL_NO_DISPLAY) { + LOG(eGL, Error) << "Unable to get EGL display"; + goto fail; + } + + if (eglInitialize(display_, &major, &minor) != EGL_TRUE) { + LOG(eGL, Error) << "eglInitialize fail"; + goto fail; + } + + LOG(eGL, Info) << "EGL: version " << major << "." << minor; + LOG(eGL, Info) << "EGL: EGL_VERSION: " << eglQueryString(display_, EGL_VERSION); + LOG(eGL, Info) << "EGL: EGL_VENDOR: " << eglQueryString(display_, EGL_VENDOR); + LOG(eGL, Info) << "EGL: EGL_CLIENT_APIS: " << eglQueryString(display_, EGL_CLIENT_APIS); + LOG(eGL, Info) << "EGL: EGL_EXTENSIONS: " << eglQueryString(display_, EGL_EXTENSIONS); + + //TODO: interrogate strings to make sure we aren't hooking unsupported functions + // and remember to error out if a function we depend on isn't found. + eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); + eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); + eglExportDMABUFImageMESA = (PFNEGLEXPORTDMABUFIMAGEMESAPROC)eglGetProcAddress("eglExportDMABUFImageMESA"); + glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); + eglClientWaitSyncKHR = (PFNEGLCLIENTWAITSYNCKHRPROC)eglGetProcAddress("eglClientWaitSyncKHR"); + eglCreateSyncKHR = (PFNEGLCREATESYNCKHRPROC)eglGetProcAddress("eglCreateSyncKHR"); + + if (eglChooseConfig(display_, configAttribs, &config, 1, &numConfigs) != EGL_TRUE) { + LOG(eGL, Error) << "eglChooseConfig fail"; + goto fail; + } + + context_ = eglCreateContext(display_, config, EGL_NO_CONTEXT, contextAttribs); + if (context_ == EGL_NO_CONTEXT) { + LOG(eGL, Error) << "eglContext returned EGL_NO_CONTEXT"; + goto fail; + } + + surface_ = eglCreateWindowSurface(display_, config, + (EGLNativeWindowType)gbmContext->getSurface(), + NULL); + if (surface_ == EGL_NO_SURFACE) { + LOG(eGL, Error) << "eglCreateWindowSurface fail"; + goto fail; + } + + makeCurrent(); + swapBuffers(); + + return 0; +fail: + + return -ENODEV; +} + +void eGL::makeCurrent(void) +{ + if (eglMakeCurrent(display_, surface_, surface_, context_) != EGL_TRUE) { + LOG(eGL, Error) << "eglMakeCurrent fail"; + } +} + +void eGL::swapBuffers(void) +{ + if (eglSwapBuffers(display_, surface_) != EGL_TRUE) { + LOG(eGL, Error) << "eglSwapBuffers fail"; + } +} + +void eGL::useProgram(GLuint programId) +{ + glUseProgram(programId); +} + +void eGL::pushEnv(std::vector& shaderEnv, const char *str) +{ + std::string addStr = str; + + addStr.push_back('\n'); + shaderEnv.push_back(addStr); +} + +int eGL::compileVertexShader(GLuint &shaderId, unsigned char *shaderData, + unsigned int shaderDataLen, + std::vector shaderEnv) +{ + return compileShader(GL_VERTEX_SHADER, shaderId, shaderData, shaderDataLen, shaderEnv); +} + +int eGL::compileFragmentShader(GLuint &shaderId, unsigned char *shaderData, + unsigned int shaderDataLen, + std::vector shaderEnv) +{ + return compileShader(GL_FRAGMENT_SHADER, shaderId, shaderData, shaderDataLen, shaderEnv); +} + +int eGL::compileShader(int shaderType, GLuint &shaderId, unsigned char *shaderData, + unsigned int shaderDataLen, + std::vector shaderEnv) +{ + GLchar **shaderSourceData; + GLint *shaderDataLengths; + GLint success; + GLsizei count; + size_t i; + + count = 1 + shaderEnv.size(); + shaderSourceData = new GLchar*[count]; + shaderDataLengths = new GLint[count]; + + // Prefix defines before main body of shader + for (i = 0; i < shaderEnv.size(); i++) { + shaderSourceData[i] = (GLchar*)shaderEnv[i].c_str(); + shaderDataLengths[i] = shaderEnv[i].length(); + } + + // Now the main body of the shader program + shaderSourceData[i] = (GLchar*)shaderData; + shaderDataLengths[i] = shaderDataLen; + + // And create the shader + shaderId = glCreateShader(shaderType); + glShaderSource(shaderId, count, shaderSourceData, shaderDataLengths); + glCompileShader(shaderId); + + // Check status + glGetShaderiv(shaderId, GL_COMPILE_STATUS, &success); + if (success == GL_FALSE) { + GLint sizeLog = 0; + GLchar *infoLog; + + glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &sizeLog); + infoLog = new GLchar[sizeLog]; + + glGetShaderInfoLog(shaderId, sizeLog, &sizeLog, infoLog); + LOG(eGL, Error) << infoLog; + + delete [] infoLog; + } + + delete [] shaderSourceData; + delete [] shaderDataLengths; + + return !(success == GL_TRUE); +} + +void eGL::dumpShaderSource(GLuint shaderId) +{ + GLint shaderLength = 0; + GLchar *shaderSource; + + glGetShaderiv(shaderId, GL_SHADER_SOURCE_LENGTH, &shaderLength); + + LOG(eGL, Debug) <<"Shader length is " << shaderLength; + + if (shaderLength > 0) { + shaderSource = new GLchar[shaderLength]; + if (!shaderSource) + return; + + glGetShaderSource(shaderId, shaderLength, &shaderLength, shaderSource); + if (shaderLength) { + LOG(eGL, Info) << "Shader source = " << shaderSource; + } + delete [] shaderSource; + } +} + +int eGL::linkProgram(GLuint &programId, GLuint vertexshaderId, GLuint fragmentshaderId) +{ + GLint success; + GLenum err; + + programId = glCreateProgram(); + if (!programId) + goto fail; + + glAttachShader(programId, vertexshaderId); + if ((err = glGetError()) != GL_NO_ERROR) { + LOG(eGL, Error) << "Attach compute vertex shader fail"; + goto fail; + } + + glAttachShader(programId, fragmentshaderId); + if ((err = glGetError()) != GL_NO_ERROR) { + LOG(eGL, Error) << "Attach compute vertex shader fail"; + goto fail; + } + + glLinkProgram(programId); + if ((err = glGetError()) != GL_NO_ERROR) { + LOG(eGL, Error) << "Link program fail"; + goto fail; + } + + glDetachShader(programId, fragmentshaderId); + glDetachShader(programId, vertexshaderId); + + // Check status + glGetProgramiv(programId, GL_LINK_STATUS, &success); + if (success == GL_FALSE) { + GLint sizeLog = 0; + GLchar *infoLog; + + glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &sizeLog); + infoLog = new GLchar[sizeLog]; + + glGetProgramInfoLog(programId, sizeLog, &sizeLog, infoLog); + LOG(eGL, Error) << infoLog; + + delete [] infoLog; + goto fail; + } + + return 0; +fail: + return -ENODEV; +} +} diff --git a/src/libcamera/software_isp/egl.h b/src/libcamera/software_isp/egl.h new file mode 100644 index 00000000..f3c5d50f --- /dev/null +++ b/src/libcamera/software_isp/egl.h @@ -0,0 +1,106 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Linaro Ltd. + * + * Authors: + * Bryan O'Donoghue + * + * egl_context.cpp - Helper class for managing eGL interactions. + */ + +#pragma once + +#define GL_GLEXT_PROTOTYPES +#include +#define EGL_EGLEXT_PROTOTYPES +#include +#include +#include + +#include + +#include // close + +#include "gbm.h" + +namespace libcamera { + +LOG_DECLARE_CATEGORY(eGL) + +class eGLImage { +public: + eGLImage(uint32_t width, uint32_t height, uint32_t bpp) { + image_ = EGL_NO_IMAGE_KHR; + width_ = width; + height_ = height; + bpp_ = bpp; + stride_ = width_ * bpp_ / 4; + framesize_ = stride_ * height_; + + glGenTextures(1, &texture_); + } + + ~eGLImage() { + glDeleteTextures(1, &texture_); + }; + + GLuint texture_; + EGLImageKHR image_; + uint32_t width_; + uint32_t height_; + uint32_t stride_; + uint32_t offset_; + uint32_t framesize_; + uint32_t bpp_; +}; + +class eGL +{ +public: + eGL(); + ~eGL(); + + int initEGLContext(GBM *gbmContext); + int createDMABufTexture2D(eGLImage *eglImage, int fd); + void destroyDMABufTexture(eGLImage *eglImage); + void createTexture2D(eGLImage *eglImage, uint32_t width, uint32_t height, void *data); + void createTexture1D(eGLImage *eglImage, uint32_t width, void *data); + + void pushEnv(std::vector &shaderEnv, const char *str); + void makeCurrent(); + void swapBuffers(); + + int compileVertexShader(GLuint &shaderId, unsigned char *shaderData, + unsigned int shaderDataLen, + std::vector shaderEnv); + int compileFragmentShader(GLuint &shaderId, unsigned char *shaderData, + unsigned int shaderDataLen, + std::vector shaderEnv); + int linkProgram(GLuint &programIdd, GLuint fragmentshaderId, GLuint vertexshaderId); + void dumpShaderSource(GLuint shaderId); + void useProgram(GLuint programId); + +private: + int fd_; + + EGLDisplay display_; + EGLContext context_; + EGLSurface surface_; + + int compileShader(int shaderType, GLuint &shaderId, unsigned char *shaderData, + unsigned int shaderDataLen, + std::vector shaderEnv); + + PFNEGLEXPORTDMABUFIMAGEMESAPROC eglExportDMABUFImageMESA; + PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; + + PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; + PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; + + PFNEGLCLIENTWAITSYNCKHRPROC eglClientWaitSyncKHR; + PFNEGLCREATESYNCKHRPROC eglCreateSyncKHR; +protected: + +}; + +}; From patchwork Tue Apr 22 21:59:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23228 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 858E6C3320 for ; Tue, 22 Apr 2025 21:59:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 160B468B47; Tue, 22 Apr 2025 23:59:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="SCpNfJnB"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C57768B33 for ; Tue, 22 Apr 2025 23:59:38 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-43cfa7e7f54so2379195e9.1 for ; Tue, 22 Apr 2025 14:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359177; x=1745963977; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wtckwzkmaU4Et0QIN3FBwnzzUA21kmyVM0rQImxpaL0=; b=SCpNfJnBWtP2mU3tOWim/Vywqy/2lKCpw8M1qDaawLPg7lgxVNMtWL67xhSlG+LjEM LXSVo9mLfk6EnnSXvX0d+rPCI0PVllicwszBs8Bt1JgO4ZjUPA+A+H+7IEHtObJYDYEU PFF1spzlMZzi2g6Gyi7jOTVgOEsMoMflQnGBECrV84qem2geK4qnDpj4SqMdQFVXhtxq clrzTrP2j9lOolWva/WtUkG2QQ44jFMoIR/tzK62QTYQoPgt7Rf4LDJ2HbLweLycEUqq 8iljjNt6zqcuqOv3XfBo7VROPmU1vmJOD5dLuL3xTx+z/aT+868chq/oib36MJLdxLl9 Zg2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359177; x=1745963977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wtckwzkmaU4Et0QIN3FBwnzzUA21kmyVM0rQImxpaL0=; b=jVNIg66yXZ2c+z1D4Qh5kveVaUZApoIeJNNngC8D6G+9okxok3vwaDRZli49CM1mTS aG+d0WC3LgDVcfdLlpBNvOTVWqvlBZud5Lr1HmbBC8iJgzwsX9tIvxKAtOe2YidfrfXT uCy0+D6O6xnGjEkM9ItsHkRwRMcuGIRmG0GoIyadWzE8MbsqTPAOTrFHeQVEqcnKXuR1 QJbSE8EyvWobpwUopx7w8ieliFqOlYH61wTQU/P9vts7CY03crDALTct0Iicx0YeZtRs 8suaNxTgws1JS4bfgcLFQkE9Ci4UQlkp36O+8WPWMCdJpa4N87ZHdYgQyHb9ZxITqq0v 2+Gg== X-Gm-Message-State: AOJu0YwMyBG81DZDwOKhAmndYSGhogRtPiIJEQdjRLU298+WojrscrmZ WIwX+XXnELtMtyu5UCHhuFHQqMb5ov+s00jR3tKEnjFTsnflW7ZcJk1d5BRYzcEHpv4OpfLtsAv jo20= X-Gm-Gg: ASbGncvxCs3EixTlE2qz4aw7TWzAakeIMchOjqDfjsffkmr0uD3xwImLw+r6zxKxA4J 1rfcnqQu+mf3IVmN1XjYSwLm+cgzGv3UWXzT28MPJTI3I74KoclbA/Wdr83YnN+URoburW2Ifpc M+/ZJ1H+kSmW6KX1KoPhfFsEfc4huRnnGIvRMZipHLuDCUzPECXalVJvPkO33VPJBnS0uZ10Pve 4Ex7yOoqbC5fzA6U7aRE3vxk5WADE/6ZGwLm4E34nEruO7UkL/goMK1cZ6DEM9S/UKhqv1OPCQc 1cWIjDoeyE7a2196TWANgaJXC9/KPhnC5t5u/OWlgWDmhSntSWKqpZtZenGf7vD2iXiKQYHXw9M QZaJwzyaiod1rn82MxDay X-Google-Smtp-Source: AGHT+IHpQPHt75gmoBCGW5v77VPAJw6TAV63lAOiMPAA+55nk84XlkIFMr03XqR3C63vWF0NXBEXzg== X-Received: by 2002:a05:600c:5119:b0:43d:fa5f:7d30 with SMTP id 5b1f17b1804b1-44091fabcd8mr3249645e9.16.1745359177503; Tue, 22 Apr 2025 14:59:37 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:37 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 15/27] libcamera: software_isp: Move useful items from DebayerCpu to Debayer base class Date: Tue, 22 Apr 2025 22:59:08 +0100 Message-ID: <20250422215920.4297-16-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" The DebayerCpu class has a number of variables, embedded structures and methods which are useful to DebayerGpu implementation. Move relevant variables and methods to base class. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/debayer.h | 34 +++++++++++++++++++++++- src/libcamera/software_isp/debayer_cpu.h | 34 +----------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h index ba033d44..dd26b9d8 100644 --- a/src/libcamera/software_isp/debayer.h +++ b/src/libcamera/software_isp/debayer.h @@ -14,11 +14,13 @@ #include #include +#include #include #include #include +#include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/software_isp/debayer_params.h" namespace libcamera { @@ -27,7 +29,7 @@ class FrameBuffer; LOG_DECLARE_CATEGORY(Debayer) -class Debayer +class Debayer : public Object { public: virtual ~Debayer() = 0; @@ -45,10 +47,40 @@ public: virtual SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) = 0; + virtual const SharedFD &getStatsFD() = 0; + + unsigned int frameSize() { return outputConfig_.frameSize; } + Signal inputBufferReady; Signal outputBufferReady; + struct DebayerInputConfig { + Size patternSize; + unsigned int bpp; /* Memory used per pixel, not precision */ + unsigned int stride; + std::vector outputFormats; + }; + + struct DebayerOutputConfig { + unsigned int bpp; /* Memory used per pixel, not precision */ + unsigned int stride; + unsigned int frameSize; + }; + + DebayerInputConfig inputConfig_; + DebayerOutputConfig outputConfig_; + DebayerParams::LookupTable red_; + DebayerParams::LookupTable green_; + DebayerParams::LookupTable blue_; + DebayerParams::CcmLookupTable redCcm_; + DebayerParams::CcmLookupTable greenCcm_; + DebayerParams::CcmLookupTable blueCcm_; + DebayerParams::LookupTable gammaLut_; + bool swapRedBlueGains_; + Benchmark bench_; + private: + virtual Size patternSize(PixelFormat inputFormat) = 0; }; diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index 182607cd..0b4b16e1 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -17,7 +17,6 @@ #include -#include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/software_isp/swstats_cpu.h" @@ -25,7 +24,7 @@ namespace libcamera { -class DebayerCpu : public Debayer, public Object +class DebayerCpu : public Debayer { public: DebayerCpu(std::unique_ptr stats); @@ -48,13 +47,6 @@ public: */ const SharedFD &getStatsFD() { return stats_->getStatsFD(); } - /** - * \brief Get the output frame size - * - * \return The output frame size - */ - unsigned int frameSize() { return outputConfig_.frameSize; } - private: /** * \brief Called to debayer 1 line of Bayer input data to output format @@ -111,19 +103,6 @@ private: template void debayer10P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]); - struct DebayerInputConfig { - Size patternSize; - unsigned int bpp; /* Memory used per pixel, not precision */ - unsigned int stride; - std::vector outputFormats; - }; - - struct DebayerOutputConfig { - unsigned int bpp; /* Memory used per pixel, not precision */ - unsigned int stride; - unsigned int frameSize; - }; - int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config); int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config); int setupStandardBayerOrder(BayerFormat::Order order); @@ -139,20 +118,11 @@ private: /* Max. supported Bayer pattern height is 4, debayering this requires 5 lines */ static constexpr unsigned int kMaxLineBuffers = 5; - DebayerParams::LookupTable red_; - DebayerParams::LookupTable green_; - DebayerParams::LookupTable blue_; - DebayerParams::CcmLookupTable redCcm_; - DebayerParams::CcmLookupTable greenCcm_; - DebayerParams::CcmLookupTable blueCcm_; - DebayerParams::LookupTable gammaLut_; debayerFn debayer0_; debayerFn debayer1_; debayerFn debayer2_; debayerFn debayer3_; Rectangle window_; - DebayerInputConfig inputConfig_; - DebayerOutputConfig outputConfig_; std::unique_ptr stats_; std::vector lineBuffers_[kMaxLineBuffers]; unsigned int lineBufferLength_; @@ -160,8 +130,6 @@ private: unsigned int lineBufferIndex_; unsigned int xShift_; /* Offset of 0/1 applied to window_.x */ bool enableInputMemcpy_; - bool swapRedBlueGains_; - Benchmark bench_; }; } /* namespace libcamera */ From patchwork Tue Apr 22 21:59:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23229 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 87DCBC32A2 for ; Tue, 22 Apr 2025 21:59:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2F04968B48; Tue, 22 Apr 2025 23:59:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="XmfD5RAS"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0EBFE68B28 for ; Tue, 22 Apr 2025 23:59:39 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-43cfba466b2so57634725e9.3 for ; Tue, 22 Apr 2025 14:59:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359178; x=1745963978; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Id0ekAEOjr9NRA9szz5nSdTr2ruvPZ3UziB6jBOQNuM=; b=XmfD5RAStjG7G89N5LxFlH1nymWi4ulVkAK6q0YAcDDDjrCqQkSOOJ/jeCvBleekPI dc/8zVSHpyKBCKgUANsz0qEWO/cgZZNohMCgbW3mCGG41DoBZf9VSIjDraln01kpuNDq ByVm3fERmz8Z71NUhEgvvviOWCB6DiIIA/Bw5V/Uv6qGC0xrvczRYRkKtebxciTe6gFx KPDdJ2ngVi8LN6KGNpAYGKpV2GNA4zGGDwmE6e5sduyjdDbS7fH4CbewHOZBwWS4pJ7o rfiuu3aCYzIbSS3Me16BfEyDJ3lv4PoV2EWkNmhpDMa2JSs2FHnTvShJ0uDEP4TBBVa9 lHeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359178; x=1745963978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Id0ekAEOjr9NRA9szz5nSdTr2ruvPZ3UziB6jBOQNuM=; b=qMLCTcy3YNG6YK+Yw3f+NyXUyknI2FxuFIdOZ5WvOG+gL4bDxTNR8E4k0dFpB4lw3I 0I6WQc5kvI+tbgypAYQpMKC4wp1Jz8O3nEdyLhfFeZCdrqVvD320CRUJoUdkmyM+7Hqw BlxWQaDS3Pgzp67ndTjjh+dnerY7M8sz4TZlMgDXGshqV1HFVF8SwsTU/5ZYO+XGrPA5 YK/Jga0p/7hOLWhlaEV7U8zG5aESx3z9rS9aRx1lpzmIiweseUidvTeDgETuniZbDPN8 QLocnSnlBrJy5/6RMU5USYC+1wsGzaeb66gTA+Enl0Y/NGIJbF1HQ++YhbwbXs6FNd4K cavw== X-Gm-Message-State: AOJu0YzUetdXYwoAFxmCiM2d3fs6L9WecX168Gpq8SX6rUCrF980WWhu sxDZSY1b2bqQ9N5yiTy7G5t2/c/rdQnhXNPb+P3hgLRk13kuLL+0c0cgsPX0USLuMrP6h0KMr+B b0gg= X-Gm-Gg: ASbGncsdCSEmC23qPNeIJAOi9NySLXc5suipEPKYuCMtTWqZ6ao75U1wyO8IsxcWW1I dUyTnQtaIBVCCfrxWc1UD/+TUSBs/UYW0Fl1h2/6/oNPg0/NAWdnuqttEyOIC19YG5T91wv5/40 Rl5F7kunJ9IDC9DahaelaTJHlheRcpbXmMTurcsDKunC7MhElQNJ7VxLjAEm0hncCGrL7eherWw niIFoxIkDJmREzGLJZZfqkj0JOF69udqVRUHFbCKbqGJhYe354lNoBvGH0UWIUvK6asDc4SiJeA 8dVNzv9az8MgM6n5+IWZ8D3EPqoRlO/AdBBipb4funyjcXfexN5jpv/1ok1TEWLumUX2kpH0WGB PHg/tW7ExuhYhGVtWL91P X-Google-Smtp-Source: AGHT+IFo70Eh9anSE9Q+86f3h02J5TIcuxAlK2QmEg5VsBRlKoxqrmnY5sB+lQeCOdOuHvz6b0qQdw== X-Received: by 2002:a05:600c:358b:b0:439:9424:1b70 with SMTP id 5b1f17b1804b1-4406ac17329mr168864905e9.30.1745359178430; Tue, 22 Apr 2025 14:59:38 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:37 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 16/27] libcamera: software_isp: Move param select code to Debayer base class Date: Tue, 22 Apr 2025 22:59:09 +0100 Message-ID: <20250422215920.4297-17-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Move the parameter selection code into the Debayer base class in-order to facilitate reuse of the lookup tables in the eGL shaders. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/debayer.cpp | 27 ++++++++++++++++++++++ src/libcamera/software_isp/debayer.h | 5 ++++ src/libcamera/software_isp/debayer_cpu.cpp | 19 +-------------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp index e9e18c48..3d883b28 100644 --- a/src/libcamera/software_isp/debayer.cpp +++ b/src/libcamera/software_isp/debayer.cpp @@ -176,4 +176,31 @@ Debayer::~Debayer() * \brief Signals when the output buffer is ready */ +/** + * \fn void Debayer::setParams(DebayerParams ¶ms) + * \brief Select the bayer params to use for the next frame debayer + * \param[in] params The parameters to be used in debayering + */ +void Debayer::setParams(DebayerParams ¶ms) +{ + green_ = params.green; + greenCcm_ = params.greenCcm; + if (swapRedBlueGains_) { + red_ = params.blue; + blue_ = params.red; + redCcm_ = params.blueCcm; + blueCcm_ = params.redCcm; + for (unsigned int i = 0; i < 256; i++) { + std::swap(redCcm_[i].r, redCcm_[i].b); + std::swap(blueCcm_[i].r, blueCcm_[i].b); + } + } else { + red_ = params.red; + blue_ = params.blue; + redCcm_ = params.redCcm; + blueCcm_ = params.blueCcm; + } + gammaLut_ = params.gammaLut; +} + } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h index dd26b9d8..9cebcbe8 100644 --- a/src/libcamera/software_isp/debayer.h +++ b/src/libcamera/software_isp/debayer.h @@ -82,6 +82,11 @@ public: private: virtual Size patternSize(PixelFormat inputFormat) = 0; + +protected: + + void setParams(DebayerParams ¶ms); + }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index 8d30bf4a..baec4799 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -754,24 +754,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output for (const FrameBuffer::Plane &plane : output->planes()) dmaSyncers.emplace_back(plane.fd, DmaSyncer::SyncType::Write); - green_ = params.green; - greenCcm_ = params.greenCcm; - if (swapRedBlueGains_) { - red_ = params.blue; - blue_ = params.red; - redCcm_ = params.blueCcm; - blueCcm_ = params.redCcm; - for (unsigned int i = 0; i < 256; i++) { - std::swap(redCcm_[i].r, redCcm_[i].b); - std::swap(blueCcm_[i].r, blueCcm_[i].b); - } - } else { - red_ = params.red; - blue_ = params.blue; - redCcm_ = params.redCcm; - blueCcm_ = params.blueCcm; - } - gammaLut_ = params.gammaLut; + setParams(params); /* Copy metadata from the input buffer */ FrameMetadata &metadata = output->_d()->metadata(); From patchwork Tue Apr 22 21:59:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23230 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 D7D7EC331F for ; Tue, 22 Apr 2025 21:59:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CABA368B4D; Tue, 22 Apr 2025 23:59:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="gr9iCbVw"; dkim-atps=neutral Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1A86868B38 for ; Tue, 22 Apr 2025 23:59:40 +0200 (CEST) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-39ee651e419so3305100f8f.3 for ; Tue, 22 Apr 2025 14:59:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359179; x=1745963979; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HecQjDX8odq8vh0GEKVOyqoBNzt/soNQ5HnQV1kdZcU=; b=gr9iCbVwfdaLlcIyeb25Saw2HeESwK1JWeA+bzbWiWI6Lmbj/3dARq12tATBNiWcmv 41nvueZVDU2uS1tSaIqPjjja2YdtqfjF91dcyvuShQ295VbzmcGUd6zhrogHS7/TcOIp KfxgXKEMM8SzvLu8bXdWBr1f36kzxdlZYovvE+gb7Yn53G4H6VmmvuoKv6vrM00vZNic OKOfHChE8+dYArjpmptSI9LBm1WsK8/Ghk3b0aw/KKg2Z2QbJa7ipe5KQFSshapnUxHV +5VOTKC7xbMFGs4p0bDQXmIzMGZriz0F8KUtqSlBf5XIxTHvWv6e898YZFDMctdRtheC R4bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359179; x=1745963979; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HecQjDX8odq8vh0GEKVOyqoBNzt/soNQ5HnQV1kdZcU=; b=MYvuMHQfPeMMYQquxtUpRjOHt/lOe6RCDiURHRdbYw97DsNo52w/lfHKLgU9yoR86E l8DoIwPqBVpNSZdcRwS57sKjXEr0ChxK3JjmibQIWJXkaQ4UnJ+ucKK+t+jjNzXcQ43X Nqa3Gzmd1/j9Y3ISNuqnc92GljYCk8sRUWHHpcmey/r8cue1zvwDlMKkkqu+Vw11/lR/ MptRdTWP7ykqP6uw3kaj6mRPC9R3qGNNtU55nn5B7+MeKlnTdTv9lqK93BkOrsT96aiI yPTXbxtTQeaNJ3lfdMUAWwMjjGpqQ83e5tcFttr3GwVsdMZjVNZehtkqy0JHscqKi79p F4sQ== X-Gm-Message-State: AOJu0YzJYISgyNXi0Zs1bwPYUdUCEh17V+wWPWCmeirhvwQ0nBhOQn2a CvItQzCXs+X4OVpzGBKeM94GJeww9otneTmqOeYhQgFGea69cQdVBfXvbFhtGJ+xFdnmGISUbY4 XqS4= X-Gm-Gg: ASbGncsOiRaT/OywQCgJEhk4XCqTbjKcC7mKsUZvTrUGR1NYonw0V968azbq27gNaK6 Yxa6jziaMKWg2v3mhKFWNXzi9hRV1WSFNGu9ALcNLLNhRL1ojH+7vZnPh2nMzAcZHq2J+Ujm4RO Y+7jzJTjQQFn1Zgh1tro+ESHIl1sKTZq22h+IuOmzqr9wc8oJIhhui7BkVGSGEtAj/7l0UMuR6O bkXHTJuFYkKqspN7Rv0up4aHDpGmDG2BNOJ8QSH/oXrI6/KOkb8XCcSnd3m9sp4NYunlHnIRNxT EwrUrLUCq5+Lrxv16qBW+RUWM4fPlE4RYrFXX3GDgdv0mV0rfLtS803OCzHLD9yTPfwWtDW8aW8 /TeSxKRk4KSq9KxX+54Vg X-Google-Smtp-Source: AGHT+IEGU+TzHtJXKaxOds8dOYgc4To9Q4jKhwW6GsSrwqBYIXW3BQbApvL5/9yNzU8xFMog+gGNiw== X-Received: by 2002:a05:6000:40dc:b0:39e:cbca:922f with SMTP id ffacd0b85a97d-39efba3655cmr11768385f8f.12.1745359179434; Tue, 22 Apr 2025 14:59:39 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:38 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 17/27] libcamera: software_isp: Move DMA sync code to common place in Debayer base Date: Tue, 22 Apr 2025 22:59:10 +0100 Message-ID: <20250422215920.4297-18-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" The DMA Sync code is directly reusable in eGLISP move to the Debayer base class to facilitate reuse. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/debayer.cpp | 13 +++++++++++++ src/libcamera/software_isp/debayer.h | 2 ++ src/libcamera/software_isp/debayer_cpu.cpp | 6 +----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp index 3d883b28..25cfd1a1 100644 --- a/src/libcamera/software_isp/debayer.cpp +++ b/src/libcamera/software_isp/debayer.cpp @@ -203,4 +203,17 @@ void Debayer::setParams(DebayerParams ¶ms) gammaLut_ = params.gammaLut; } +/** + * \fn void Debayer::dmaSyncBegin(DebayerParams ¶ms) + * \brief Common CPU/GPU Dma Sync Buffer begin + */ +void Debayer::dmaSyncBegin(std::vector &dmaSyncers, FrameBuffer *input, FrameBuffer *output) +{ + for (const FrameBuffer::Plane &plane : input->planes()) + dmaSyncers.emplace_back(plane.fd, DmaSyncer::SyncType::Read); + + for (const FrameBuffer::Plane &plane : output->planes()) + dmaSyncers.emplace_back(plane.fd, DmaSyncer::SyncType::Write); +} + } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h index 9cebcbe8..c8ce14f0 100644 --- a/src/libcamera/software_isp/debayer.h +++ b/src/libcamera/software_isp/debayer.h @@ -20,6 +20,7 @@ #include #include +#include "libcamera/internal/dma_buf_allocator.h" #include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/software_isp/debayer_params.h" @@ -86,6 +87,7 @@ private: protected: void setParams(DebayerParams ¶ms); + void dmaSyncBegin(std::vector &dmaSyncers,FrameBuffer *input, FrameBuffer *output); }; diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index baec4799..987f225f 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -22,7 +22,6 @@ #include #include "libcamera/internal/bayer_format.h" -#include "libcamera/internal/dma_buf_allocator.h" #include "libcamera/internal/framebuffer.h" #include "libcamera/internal/mapped_framebuffer.h" @@ -748,11 +747,8 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output bench_.startFrame(); std::vector dmaSyncers; - for (const FrameBuffer::Plane &plane : input->planes()) - dmaSyncers.emplace_back(plane.fd, DmaSyncer::SyncType::Read); - for (const FrameBuffer::Plane &plane : output->planes()) - dmaSyncers.emplace_back(plane.fd, DmaSyncer::SyncType::Write); + dmaSyncBegin(dmaSyncers, input, output); setParams(params); From patchwork Tue Apr 22 21:59:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23231 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 75C3FC3321 for ; Tue, 22 Apr 2025 21:59:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 063D368B38; Tue, 22 Apr 2025 23:59:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="vhW8DeEk"; dkim-atps=neutral Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0404E68AD0 for ; Tue, 22 Apr 2025 23:59:41 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43690d4605dso46293375e9.0 for ; Tue, 22 Apr 2025 14:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359180; x=1745963980; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s22tvATEek2jn56FeC27txLuiJp6vxiU1oIGShzPMbs=; b=vhW8DeEkTgPnzHtjtj/nTg/Wqmj3ak4v1jg2HfFaCVnSpqPaZM7F9plXWi0z53NRvO aA9QobuzlEFJBqIA8OiDeTz1nwBGgmQAwVovpb7vW2hqqVJf5+kHptCL/oBKIwDV3IMO 1MNAVrioyqmR7Zaz/aE6gGZTN+jQWgwZC0QkXNI58rMygdcPgWRIg49sTyKi5dEQeXSW pYdAuYsClqS9I9E2tZaNJs96iK4n2E9Xx7EYq6BdcKmN4kFunKd8wgPx43ZuZHc7k8+U 32bUxLDFasmV+U72h4fZBXXpMwdRNKh4UrvS8+qlokJe+zKWpyvigH2ZqXbX47UHHG4+ BqUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359180; x=1745963980; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s22tvATEek2jn56FeC27txLuiJp6vxiU1oIGShzPMbs=; b=IJAjjZTr1coR7HRoDQ+YIdAEkcgLmPm1tOumogTDci2OvagjNxESAssuBHEc0USrgp ST5DMaGcgYB1yzIcuet9G1sa72RRSJk5m303Ls0kcNyDWVDRfzS1fcpou5TFgTevLfnu o3ItPAP25sKa3EesY1AvLro8lcVwxURKy8331mfAlBHVxn93X//ilceRUliOClWB/Jtt z/Hw+nV7Dzb5ibxvtX/FE22+98se+irKy+sKpVmjgzkzYpZfZ+lnMlWLAQeUJ6iDGyqE OphB9Q7xyWkMzQKxd0YCKGVU4vzNsPyaX/VBCiWBNRQBjGPB/g04stzkTo4+T3zoASwW 7zuw== X-Gm-Message-State: AOJu0YwczJcdMBZHEf6NTdcH5bQTGS+UXNpVqc291FkW1FMyNlpgoFuN YULoex/psmHUCrHEfY6OhKXvJsA/dZ9BSmEpsL5AgF5AB16CKDp1g8VjtEkGSWl6hNH8IPTislE WfY4= X-Gm-Gg: ASbGncu5Yok/VnGoZ5IFP7oWF/0f2U9YWvWniiCA9sZ8OmAfcJnZ5XKcE0fGeWe/t7o 9P0YqqOdRwh9g41k7kMTuEFT0PYJv0dbY24sQ0QJLmqY9gyek7r+pW5z88DRVdefAEptZdawyeq JdOvdESlpQZvVwTZ5XhWJJBFPxa5l4c1Y2IG3P8QUrOQt0DwF5xfcHoDObUIc73W3wrTgW4UdfZ 1NSASq7aUvPUqxdXpDgfjxH3VFzOfYfoEaQDTmQVQXGFgvVSVgONc85j+1wINy+Dd+jCaUGokp9 tLe9V1lojkD6PQmXURGAR+zrF3ZWYDZUvTZnmFrNfsghlmV42VLauT/JMai/HK2ciBJ3Go3vv3a sPAVZ0S+w51RGXlLhD6VI X-Google-Smtp-Source: AGHT+IGOWZNCI3xjk2EeqvStTWbtCYGgJ/lu9QTkmFs0PYwwzNyIYcWci8opl93Jz/qBdGy5HztUMg== X-Received: by 2002:a05:600c:4e09:b0:43c:f513:958a with SMTP id 5b1f17b1804b1-4406ab9e3ecmr163334415e9.13.1745359180387; Tue, 22 Apr 2025 14:59:40 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:39 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 18/27] libcamera: software_isp: Make the debayer_ object of type class Debayer not DebayerCpu Date: Tue, 22 Apr 2025 22:59:11 +0100 Message-ID: <20250422215920.4297-19-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Make the type of object Debayer not DebayerCpu thus allowing us to assign the object to either DebayerCpu or DebayerEGL. Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/software_isp/software_isp.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index 78624659..ad89c9b3 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -37,7 +37,7 @@ namespace libcamera { -class DebayerCpu; +class Debayer; class FrameBuffer; class PixelFormat; class Stream; @@ -94,8 +94,7 @@ private: void statsReady(uint32_t frame, uint32_t bufferId); void inputReady(FrameBuffer *input); void outputReady(FrameBuffer *output); - - std::unique_ptr debayer_; + std::unique_ptr debayer_; Thread ispWorkerThread_; SharedMemObject sharedParams_; DebayerParams debayerParams_; From patchwork Tue Apr 22 21:59:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23232 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 E4895C327D for ; Tue, 22 Apr 2025 21:59:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5FCE668AD9; Tue, 22 Apr 2025 23:59:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="mKkGIi1l"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3666368B36 for ; Tue, 22 Apr 2025 23:59:42 +0200 (CEST) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43d04dc73b7so52251125e9.3 for ; Tue, 22 Apr 2025 14:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359181; x=1745963981; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rPosaOH1mtkxvmAKqwhdY3CYDHFWTfkbfbfqGtuksa4=; b=mKkGIi1lT7cMNuWX47AVqWn3elJoNBi2w/Ebg6DmkTawjN5nTvjqRobEeI89znvYNa WM2wdZeerhRlaBLf/8JyaHwrraeU63m2Ww8yMuPWzsJEIwLx7ptRkRrZme1D9UHcSfY0 HONXJlNsGS44gWAC+8Ae0CU2jmMcVv1TL6grLb1L19YFUp8W4dFpc4BK3OCZXNl5t5QI aMBrA0YNUTmGr2mnXmN+JGM/3ZWjcEvZApMy45pQBN5kmPprPIIGYX82NNCW3rCoiYkF zUCqI1rHw0UHp0anSabW60VvQBywC7tIqfr823WjxzabXWGAkdhGCXFmZGqDlv7nhALt 0RwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359181; x=1745963981; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rPosaOH1mtkxvmAKqwhdY3CYDHFWTfkbfbfqGtuksa4=; b=oumPGtAJlvySoXewSOktjByr3IiJ4PMaZtjDPzamB20yRG6ony3b2HXNlPlA79FTf5 9AbXg4k3OGQhcYoP3G0L04fgqgsK2EIcX2S0SZ1a2SK/hshTgIJlkcP3I3rxVY1q8743 XIaCp+tscRxkTrGhdA1TkC3wQhe9Zo+CCciUHYdMTx/TFqL5+QwErPbPqve0G9ylXtkB fIg82h4cklBOSJmsJ1ABuW9x6BlBusduppuiCHReUU40qdZ1AguVFdhBzOQzjU/bdK7u 85w6iYBwVqDZr76Lfsf66lz4x6TloGUlXi+FPEW7kzOezi4oT9Mg8fh0AERI51GxdiWW q4CQ== X-Gm-Message-State: AOJu0Yx3zDz11kBOqAine/VmGtJL9ld61xDGGiaRMjnI+qv2+uwWEZzz ktZ171MKarIzWgEQafogJq7/PhB/wxh9zXoTMpn4vheUMIkgJm1hvn1/y6USX/33GRxolC5Mw93 u5VU= X-Gm-Gg: ASbGncv8qcG3c5Zm4JY4SN9fCWjvoGAWcuMc/zj6sFSGoVIy3tFKeb7Cke1LXzm1oKq cQtnVg4ADitwmF4RtUiJc/Nb/XA55aDtmp5sNO8fzz3qL+BfQ0/mHXr69Fd7fz4Cb0sydCSilI3 qmp1yR0yLBKHGnE6x6SzKpt9VboMUcXnxkzeJomid0RY7+j7xu0QH/TDu+tOSkGWAMsgI/+UCXC XD+n3uOJ58QGq71gcodKD6oTWb4388wfDIB7Fo93NIEdzIWEGqQDhiC9NgQOo8t1ilToUvCL7/g O8hWiZo8LE9HSW0Cq5EC6d7HBI+oG7zxqZ6H3nUjVf4DrA8e/ngSqIzKt61RdBiQJqeIrtp70w5 o2oCP30KfyGLYyv0pdOHAQe5JCbZMeh8= X-Google-Smtp-Source: AGHT+IHjuU3u6SF/3/4Ta9WlQP9bnpbH3jDhkuonLtp7sCPzymz6BASspe1bAuwohx5/+oOkubQ+TQ== X-Received: by 2002:a05:600c:1e0c:b0:43d:fa59:bcee with SMTP id 5b1f17b1804b1-4406ac1feebmr146436505e9.33.1745359181477; Tue, 22 Apr 2025 14:59:41 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:40 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 19/27] libcamera: software_isp: debayer_egl: Add an eGL debayer class Date: Tue, 22 Apr 2025 22:59:12 +0100 Message-ID: <20250422215920.4297-20-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Add a class to run the existing glsl debayer shaders on a GBM surface. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/debayer_egl.cpp | 529 +++++++++++++++++++++ src/libcamera/software_isp/debayer_egl.h | 168 +++++++ src/libcamera/software_isp/meson.build | 30 ++ 3 files changed, 727 insertions(+) create mode 100644 src/libcamera/software_isp/debayer_egl.cpp create mode 100644 src/libcamera/software_isp/debayer_egl.h diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp new file mode 100644 index 00000000..008938f8 --- /dev/null +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -0,0 +1,529 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Linaro Ltd. + * + * Authors: + * Bryan O'Donoghue + * + * debayer_cpu.cpp - EGL based debayering class + */ + +#include +#include +#include + +#include + +#include "libcamera/internal/glsl_shaders.h" +#include "debayer_egl.h" + +namespace libcamera { + +DebayerEGL::DebayerEGL(std::unique_ptr stats) + : stats_(std::move(stats)) +{ +} + +DebayerEGL::~DebayerEGL() +{ + if (eglImageBayerIn_) + delete eglImageBayerIn_; +} + +// 0xB0D make into public in the base +static bool isStandardBayerOrder(BayerFormat::Order order) +{ + return order == BayerFormat::BGGR || order == BayerFormat::GBRG || + order == BayerFormat::GRBG || order == BayerFormat::RGGB; +} + +// 0xB0D make into public in the base +int DebayerEGL::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config) +{ + BayerFormat bayerFormat = + BayerFormat::fromPixelFormat(inputFormat); + + if ((bayerFormat.bitDepth == 8 || bayerFormat.bitDepth == 10) && + bayerFormat.packing == BayerFormat::Packing::None && + isStandardBayerOrder(bayerFormat.order)) { + config.bpp = (bayerFormat.bitDepth + 7) & ~7; + config.patternSize.width = 2; + config.patternSize.height = 2; + config.outputFormats = std::vector({ formats::ARGB8888 }); + return 0; + } + + if (bayerFormat.bitDepth == 10 && + bayerFormat.packing == BayerFormat::Packing::CSI2 && + isStandardBayerOrder(bayerFormat.order)) { + config.bpp = 10; + config.patternSize.width = 4; /* 5 bytes per *4* pixels */ + config.patternSize.height = 2; + config.outputFormats = std::vector({ formats::ARGB8888 }); + return 0; + } + + LOG(Debayer, Info) + << "Unsupported input format " << inputFormat.toString(); + return -EINVAL; +} + +// 0xB0D make into public in the base +int DebayerEGL::getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config) +{ + if (outputFormat == formats::ARGB8888) { + config.bpp = 32; + return 0; + } + + LOG(Debayer, Error) + << "Unsupported output format " << outputFormat.toString(); + + return -EINVAL; +} + +int DebayerEGL::getShaderVariableLocations(void) +{ + attributeVertex_ = glGetAttribLocation(programId_, "vertexIn"); + attributeTexture_ = glGetAttribLocation(programId_, "textureIn"); + + textureUniformY_ = glGetUniformLocation(programId_, "tex_y"); + textureUniformU_ = glGetUniformLocation(programId_, "tex_u"); + textureUniformV_ = glGetUniformLocation(programId_, "tex_v"); + textureUniformStep_ = glGetUniformLocation(programId_, "tex_step"); + textureUniformSize_ = glGetUniformLocation(programId_, "tex_size"); + textureUniformStrideFactor_ = glGetUniformLocation(programId_, "stride_factor"); + textureUniformBayerFirstRed_ = glGetUniformLocation(programId_, "tex_bayer_first_red"); + textureUniformProjMatrix_ = glGetUniformLocation(programId_, "proj_matrix"); + + LOG(Debayer, Info) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ + << " tex_y " << textureUniformY_ + << " tex_u " << textureUniformU_ + << " tex_v " << textureUniformV_ + << " tex_step " << textureUniformStep_ + << " tex_size " << textureUniformSize_ + << " stride_factor " << textureUniformStrideFactor_ + << " tex_bayer_first_red " << textureUniformBayerFirstRed_ + << " proj_matrix " << textureUniformProjMatrix_; + return 0; +} + +int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat) +{ + std::vector shaderEnv; + unsigned int fragmentShaderDataLen; + unsigned char *fragmentShaderData; + unsigned int vertexShaderDataLen; + unsigned char *vertexShaderData; + GLenum err; + + swapRedBlueGains_ = false; + + // Target gles 100 glsl requires "#version x" as first directive in shader + egl_.pushEnv(shaderEnv, "#version 100"); + + // Specify GL_OES_EGL_image_external + egl_.pushEnv(shaderEnv, "#extension GL_OES_EGL_image_external: enable"); + + switch (outputFormat) { + case formats::ARGB8888: + break; + case formats::BGRA8888: + swapRedBlueGains_ = true; + break; + default: + goto invalid_fmt; + } + + // Pixel location parameters + switch (inputFormat) { + case libcamera::formats::SBGGR8: + case libcamera::formats::SBGGR10_CSI2P: + case libcamera::formats::SBGGR12_CSI2P: + firstRed_x_ = 1.0; + firstRed_y_ = 1.0; + break; + case libcamera::formats::SGBRG8: + case libcamera::formats::SGBRG10_CSI2P: + case libcamera::formats::SGBRG12_CSI2P: + firstRed_x_ = 0.0; + firstRed_y_ = 1.0; + break; + case libcamera::formats::SGRBG8: + case libcamera::formats::SGRBG10_CSI2P: + case libcamera::formats::SGRBG12_CSI2P: + firstRed_x_ = 1.0; + firstRed_y_ = 0.0; + break; + case libcamera::formats::SRGGB8: + case libcamera::formats::SRGGB10_CSI2P: + case libcamera::formats::SRGGB12_CSI2P: + firstRed_x_ = 0.0; + firstRed_y_ = 0.0; + break; + default: + goto invalid_fmt; + break; + }; + + // Shader selection + switch (inputFormat) { + case libcamera::formats::SBGGR8: + case libcamera::formats::SGBRG8: + case libcamera::formats::SGRBG8: + case libcamera::formats::SRGGB8: + fragmentShaderData = bayer_8_frag; + fragmentShaderDataLen = bayer_8_frag_len; + vertexShaderData = bayer_8_vert; + vertexShaderDataLen = bayer_8_vert_len; + break; + case libcamera::formats::SBGGR10_CSI2P: + case libcamera::formats::SGBRG10_CSI2P: + case libcamera::formats::SGRBG10_CSI2P: + case libcamera::formats::SRGGB10_CSI2P: + egl_.pushEnv(shaderEnv, "#define RAW10P"); + fragmentShaderData = bayer_1x_packed_frag; + fragmentShaderDataLen = bayer_1x_packed_frag_len; + vertexShaderData = identity_vert; + vertexShaderDataLen = identity_vert_len; + break; + case libcamera::formats::SBGGR12_CSI2P: + case libcamera::formats::SGBRG12_CSI2P: + case libcamera::formats::SGRBG12_CSI2P: + case libcamera::formats::SRGGB12_CSI2P: + egl_.pushEnv(shaderEnv, "#define RAW12P"); + fragmentShaderData = bayer_1x_packed_frag; + fragmentShaderDataLen = bayer_1x_packed_frag_len; + vertexShaderData = identity_vert; + vertexShaderDataLen = identity_vert_len; + break; + default: + goto invalid_fmt; + break; + }; + + if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, vertexShaderDataLen, shaderEnv)) + goto compile_fail; + + if (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData, fragmentShaderDataLen, shaderEnv)) + goto compile_fail; + + if (egl_.linkProgram(programId_, vertexShaderId_, fragmentShaderId_)) + goto link_fail; + + egl_.dumpShaderSource(vertexShaderId_); + egl_.dumpShaderSource(fragmentShaderId_); + + /* Ensure we set the programId_ */ + egl_.useProgram(programId_); + err = glGetError(); + if (err != GL_NO_ERROR) + goto program_fail; + + if (getShaderVariableLocations()) + goto parameters_fail; + + return 0; + +parameters_fail: + LOG(Debayer, Error) << "Program parameters fail"; + return -ENODEV; + +program_fail: + LOG(Debayer, Error) << "Use program error " << err; + return -ENODEV; + +link_fail: + LOG(Debayer, Error) << "Linking program fail"; + return -ENODEV; + + +compile_fail: + LOG(Debayer, Error) << "Compile debayer shaders fail"; + return -ENODEV; + +invalid_fmt: + LOG(Debayer, Error) << "Unsupported input output format combination"; + return -EINVAL; +} + +int DebayerEGL::configure(const StreamConfiguration &inputCfg, + const std::vector> &outputCfgs, + bool ccmEnabled) +{ + if (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0) + return -EINVAL; + + if (stats_->configure(inputCfg) != 0) + return -EINVAL; + + const Size &stats_pattern_size = stats_->patternSize(); + if (inputConfig_.patternSize.width != stats_pattern_size.width || + inputConfig_.patternSize.height != stats_pattern_size.height) { + LOG(Debayer, Error) + << "mismatching stats and debayer pattern sizes for " + << inputCfg.pixelFormat.toString(); + return -EINVAL; + } +(void)ccmEnabled; + inputConfig_.stride = inputCfg.stride; + width_ = inputCfg.size.width; + height_ = inputCfg.size.height; + + if (outputCfgs.size() != 1) { + LOG(Debayer, Error) + << "Unsupported number of output streams: " + << outputCfgs.size(); + return -EINVAL; + } + + LOG(Debayer, Info) << "Input size " << inputCfg.size << " stride " << inputCfg.stride; + + if (gbmSurface_.initSurface(inputCfg.size.width, inputCfg.size.height)) + return -ENODEV; + + if (egl_.initEGLContext(&gbmSurface_)) + return -ENODEV; + + eglImageBayerIn_ = new eGLImage(width_, height_, 32); + + // Create a single BO (calling gbm_surface_lock_front_buffer() again before gbm_surface_release_buffer() would create another BO) + if (gbmSurface_.mapSurface()) + return -ENODEV; + + StreamConfiguration &outputCfg = outputCfgs[0]; + SizeRange outSizeRange = sizes(inputCfg.pixelFormat, inputCfg.size); + + outputConfig_.stride = gbmSurface_.getStride(); + outputConfig_.frameSize = gbmSurface_.getFrameSize(); + + LOG(Debayer, Debug) << "Overriding stream config stride " + << outputCfg.stride << " with GBM surface stride " + << outputConfig_.stride; + outputCfg.stride = outputConfig_.stride; + + if (!outSizeRange.contains(outputCfg.size) || outputConfig_.stride != outputCfg.stride) { + LOG(Debayer, Error) + << "Invalid output size/stride: " + << "\n " << outputCfg.size << " (" << outSizeRange << ")" + << "\n " << outputCfg.stride << " (" << outputConfig_.stride << ")"; + return -EINVAL; + } + + window_.x = ((inputCfg.size.width - outputCfg.size.width) / 2) & + ~(inputConfig_.patternSize.width - 1); + window_.y = ((inputCfg.size.height - outputCfg.size.height) / 2) & + ~(inputConfig_.patternSize.height - 1); + window_.width = outputCfg.size.width; + window_.height = outputCfg.size.height; + + /* Don't pass x,y since process() already adjusts src before passing it */ + stats_->setWindow(Rectangle(window_.size())); + + LOG(Debayer, Info) << "Input width " << inputCfg.size.width << " height " << inputCfg.size.height; + LOG(Debayer, Info) << "Output width " << outputCfg.size.width << " height " << outputCfg.size.height; + LOG(Debayer, Info) << "Output stride " << outputCfg.size.width << " height " << outputCfg.size.height; + + if (initBayerShaders(inputCfg.pixelFormat, outputCfg.pixelFormat)) + return -EINVAL; + + return 0; +} + +Size DebayerEGL::patternSize(PixelFormat inputFormat) +{ + DebayerEGL::DebayerInputConfig config; + + if (getInputConfig(inputFormat, config) != 0) + return {}; + + return config.patternSize; +} + +std::vector DebayerEGL::formats(PixelFormat inputFormat) +{ + DebayerEGL::DebayerInputConfig config; + + if (getInputConfig(inputFormat, config) != 0) + return std::vector(); + + return config.outputFormats; +} + +std::tuple +DebayerEGL::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) +{ + DebayerEGL::DebayerOutputConfig config; + + if (getOutputConfig(outputFormat, config) != 0) + return std::make_tuple(0, 0); + + /* round up to multiple of 8 for 64 bits alignment */ + unsigned int stride = (size.width * config.bpp / 8 + 7) & ~7; + + return std::make_tuple(stride, stride * size.height); +} + +void DebayerEGL::setShaderVariableValues(void) +{ + /* + * Raw Bayer 8-bit, and packed raw Bayer 10-bit/12-bit formats + * are stored in a GL_LUMINANCE texture. The texture width is + * equal to the stride. + */ + GLfloat firstRed[] = {firstRed_x_, firstRed_y_}; + GLfloat imgSize[] = {(GLfloat)width_, + (GLfloat)height_}; + GLfloat Step[] = {1.0f / (inputConfig_.stride - 1), + 1.0f / (height_ - 1)}; + GLfloat Stride = 1.0f; + GLfloat projIdentityMatrix[] = { + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + + // vertexIn - bayer_8.vert + glEnableVertexAttribArray(attributeVertex_); + glVertexAttribPointer(attributeVertex_, 2, GL_FLOAT, GL_TRUE, + 2 * sizeof(GLfloat), vcoordinates); + + // textureIn - bayer_8.vert + glEnableVertexAttribArray(attributeTexture_); + glVertexAttribPointer(attributeTexture_, 2, GL_FLOAT, GL_TRUE, + 2 * sizeof(GLfloat), tcoordinates); + + glUniform1i(textureUniformY_, 0); // tex_y - bayer_8.vert - set for no reason + glUniform2fv(textureUniformBayerFirstRed_, 1, firstRed); // tex_bayer_first_red - bayer_8.vert + glUniform2fv(textureUniformSize_, 1, imgSize); // tex_size - bayer_8.vert + glUniform2fv(textureUniformStep_, 1, Step); // tex_step - bayer_8.vert + glUniform1f(textureUniformStrideFactor_, Stride); // stride_factor - identity.vert + glUniformMatrix4fv(textureUniformProjMatrix_, 1, + GL_FALSE, projIdentityMatrix); // No scaling + + LOG(Debayer, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ + << " tex_y " << textureUniformY_ + << " tex_u " << textureUniformU_ + << " tex_v " << textureUniformV_ + << " tex_step " << textureUniformStep_ + << " tex_size " << textureUniformSize_ + << " stride_factor " << textureUniformStrideFactor_ + << " tex_bayer_first_red " << textureUniformBayerFirstRed_; + + LOG (Debayer, Debug) << "textureUniformY_ = 0 " << + " firstRed.x " << firstRed[0] << + " firstRed.y " << firstRed[1] << + " textureUniformSize_.width " << imgSize[0] << " " + " textureUniformSize_.height " << imgSize[1] << + " textureUniformStep_.x " << Step[0] << + " textureUniformStep_.y " << Step[1] << + " textureUniformStrideFactor_ " << Stride << + " textureUniformProjMatrix_ " << textureUniformProjMatrix_; + return; +} + +void DebayerEGL::debayerGPU(MappedFrameBuffer &in, MappedFrameBuffer &out) +{ + LOG(Debayer, Debug) + << "Input height " << height_ + << " width " << width_ + << " fd " << in.fds()[0]; + + // eGL context switch + egl_.makeCurrent(); + + // make texture unit 0 explicit this doesn't really matter probably remove ? + glActiveTexture(GL_TEXTURE0); + + // Greate a standard texture + // we will replace this with the DMA version at some point + egl_.createTexture2D(eglImageBayerIn_, inputConfig_.stride, height_, in.planes()[0].data()); + + // Setup the scene + setShaderVariableValues(); + glViewport(0, 0, width_, height_); + glClear(GL_COLOR_BUFFER_BIT); + glDisable(GL_BLEND); + + // Draw the scene + glDrawArrays(GL_TRIANGLE_FAN, 0, DEBAYER_OPENGL_COORDS); + + // eglclientWaitScynKhr / eglwaitsynckr ? + egl_.swapBuffers(); + + // Copy from the output GBM buffer to our output plane + // once we get render to texture working the + // explicit lock ioctl, memcpy and unlock ioctl won't be required + gbmSurface_.getFrameBufferData(out.planes()[0].data(), out.planes()[0].size()); +} + +void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params) +{ + bench_.startFrame(); + + std::vector dmaSyncers; + + dmaSyncBegin(dmaSyncers, input, output); + + setParams(params); + + /* Copy metadata from the input buffer */ + FrameMetadata &metadata = output->_d()->metadata(); + metadata.status = input->metadata().status; + metadata.sequence = input->metadata().sequence; + metadata.timestamp = input->metadata().timestamp; + + MappedFrameBuffer in(input, MappedFrameBuffer::MapFlag::Read); + MappedFrameBuffer out(output, MappedFrameBuffer::MapFlag::Write); + if (!in.isValid() || !out.isValid()) { + LOG(Debayer, Error) << "mmap-ing buffer(s) failed"; + metadata.status = FrameMetadata::FrameError; + return; + } + + debayerGPU(in, out); + + dmaSyncers.clear(); + + bench_.finishFrame(); + + metadata.planes()[0].bytesused = out.planes()[0].size(); + + // Calculate stats for the whole frame + stats_->processFrame(frame, 0, input); + + outputBufferReady.emit(output); + inputBufferReady.emit(input); +} + +SizeRange DebayerEGL::sizes(PixelFormat inputFormat, const Size &inputSize) +{ + Size patternSize = this->patternSize(inputFormat); + unsigned int borderHeight = patternSize.height; + + if (patternSize.isNull()) + return {}; + + /* No need for top/bottom border with a pattern height of 2 */ + if (patternSize.height == 2) + borderHeight = 0; + + /* + * For debayer interpolation a border is kept around the entire image + * and the minimum output size is pattern-height x pattern-width. + */ + if (inputSize.width < (3 * patternSize.width) || + inputSize.height < (2 * borderHeight + patternSize.height)) { + LOG(Debayer, Warning) + << "Input format size too small: " << inputSize.toString(); + return {}; + } + + return SizeRange(Size(patternSize.width, patternSize.height), + Size((inputSize.width - 2 * patternSize.width) & ~(patternSize.width - 1), + (inputSize.height - 2 * borderHeight) & ~(patternSize.height - 1)), + patternSize.width, patternSize.height); +} + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h new file mode 100644 index 00000000..14f6997a --- /dev/null +++ b/src/libcamera/software_isp/debayer_egl.h @@ -0,0 +1,168 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2025, Bryan O'Donoghue. + * + * Authors: + * Bryan O'Donoghue + * + * debayer_opengl.h - EGL debayer header + */ + +#pragma once + +#include +#include +#include + +#define GL_GLEXT_PROTOTYPES +#include +#define EGL_EGLEXT_PROTOTYPES +#include +#include +#include + +#include + +#include "debayer.h" +#include "egl.h" + +#include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/framebuffer.h" +#include "libcamera/internal/mapped_framebuffer.h" +#include "libcamera/internal/software_isp/benchmark.h" +#include "libcamera/internal/software_isp/swstats_cpu.h" + +namespace libcamera { + +/** + * \class DebayerEGL + * \brief Class for debayering using an EGL Shader + * + * Implements an EGL shader based debayering solution. + */ +class DebayerEGL : public Debayer +{ +public: + /** + * \brief Constructs a DebayerEGL object. + * \param[in] stats Pointer to the stats object to use. + */ + DebayerEGL(std::unique_ptr stats); + ~DebayerEGL(); + + /* + * Setup the Debayer object according to the passed in parameters. + * Return 0 on success, a negative errno value on failure + * (unsupported parameters). + */ + int configure(const StreamConfiguration &inputCfg, + const std::vector> &outputCfgs, + bool ccmEnabled); + + /* + * Get width and height at which the bayer-pattern repeats. + * Return pattern-size or an empty Size for an unsupported inputFormat. + */ + Size patternSize(PixelFormat inputFormat); + + std::vector formats(PixelFormat input); + std::tuple + strideAndFrameSize(const PixelFormat &outputFormat, const Size &size); + + void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params); + + /** + * \brief Get the file descriptor for the statistics. + * + * \return the file descriptor pointing to the statistics. + */ + const SharedFD &getStatsFD() { return stats_->getStatsFD(); } + + /** + * \brief Get the output frame size. + * + * \return The output frame size. + */ + unsigned int frameSize() { return outputConfig_.frameSize; } + + SizeRange sizes(PixelFormat inputFormat, const Size &inputSize); + + /** + * \brief EGL context is associated with a PID so don't moveToThread + * + * \return nothing + */ + void moveToThread(Thread *thread) { (void)thread; return; } + +private: + + int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config); + int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config); + int setupStandardBayerOrder(BayerFormat::Order order); + void pushEnv(std::vector &shaderEnv, const char *str); + int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat); + int initEGLContext(); + int generateTextures(); + int compileShaderProgram(GLuint &shaderId, GLenum shaderType, + unsigned char *shaderData, int shaderDataLen, + std::vector shaderEnv); + int linkShaderProgram(void); + int getShaderVariableLocations(); + void setShaderVariableValues(void); + void configureTexture(GLuint &texture); + void debayerGPU(MappedFrameBuffer &in, MappedFrameBuffer &out); + + // Shader program identifiers + GLuint vertexShaderId_; + GLuint fragmentShaderId_; + GLuint programId_; + enum { + BAYER_INPUT_INDEX = 0, + BAYER_OUTPUT_INDEX, + BAYER_BUF_NUM, + }; + + // Pointer to object representing input texture + eGLImage *eglImageBayerIn_; + + // Shader parameters + float firstRed_x_; + float firstRed_y_; + GLint attributeVertex_; + GLint attributeTexture_; + GLint textureUniformY_; + GLint textureUniformU_; + GLint textureUniformV_; + GLint textureUniformStep_; + GLint textureUniformSize_; + GLint textureUniformStrideFactor_; + GLint textureUniformBayerFirstRed_; + GLint textureUniformProjMatrix_; + + Rectangle window_; + std::unique_ptr stats_; + eGL egl_; + GBM gbmSurface_; + uint32_t width_; + uint32_t height_; + + #define DEBAYER_OPENGL_COORDS 4 + + GLfloat vcoordinates[DEBAYER_OPENGL_COORDS][2] = { + /* Vertex coordinates */ + -1.0f, -1.0f, + -1.0f, +1.0f, + +1.0f, +1.0f, + +1.0f, -1.0f, + }; + + GLfloat tcoordinates[DEBAYER_OPENGL_COORDS][2] = { + /* Texture coordinates */ + 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 0.0f, + 1.0f, 1.0f, + }; +}; + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index 59fa5f02..9a7ac455 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -14,3 +14,33 @@ libcamera_internal_sources += files([ 'software_isp.cpp', 'swstats_cpu.cpp', ]) + +libegl = cc.find_library('EGL', required : false) +libgbm = cc.find_library('gbm', required: false) +libglesv2 = cc.find_library('GLESv2', required : false) + +if libegl.found() + config_h.set('HAVE_LIBEGL', 1) +endif + +if libgbm.found() + config_h.set('HAVE_GBM', 1) +endif + +if libglesv2.found() + config_h.set('HAVE_GLESV2', 1) +endif + +if libegl.found() and libgbm.found() and libglesv2.found() +libcamera_deps += [ + libegl, + libgbm, + libglesv2, +] + +libcamera_internal_sources += files([ + 'debayer_egl.cpp', + 'egl.cpp', + 'gbm.cpp', +]) +endif From patchwork Tue Apr 22 21:59:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23233 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 2BCF5C331E for ; Tue, 22 Apr 2025 22:00:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6532668AD9; Tue, 22 Apr 2025 23:59:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="TjMPDZ5P"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 51F6068B3E for ; Tue, 22 Apr 2025 23:59:43 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-43cebe06e9eso47639735e9.3 for ; Tue, 22 Apr 2025 14:59:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359182; x=1745963982; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1+V+tT+5bE8QKuoSfA3FLpmNoP41vVB3yUTW2/ZNDdc=; b=TjMPDZ5PXaCXvZstXbX3j1gZVqW9Uu0PiT5TA9E3MGQDPI8K7Sp+Ekg8NZASAq0Qrt N5qiX0hnsk6NZ/fTZ87rwzr4fIQ1RN42dkGhpYlBH9aXYNyv3xZszWTN51rZNhMzhAJ1 7RmQN8OjULYhEP35EEmj0M22E3xqunYKeOiJZ0Np7rCmE3Ld9AAptdovEbQfupL/U2mr +zl60DS3eJZHKFetzEF5VFi5BE6IExMxGX9LkUOn3dDQcjIfMEw1gZSfG+nndY1EFU83 gBGkRtDORj3dDEo6HnJCcfv1GA5JTjHORKYP8jHkmmRqO/abNB59JeZvid7/P2eYCaje v4ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359182; x=1745963982; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1+V+tT+5bE8QKuoSfA3FLpmNoP41vVB3yUTW2/ZNDdc=; b=ND+I9R8bIv0dUef6uGa9GB80t4l8wQQNpE23DqOEbj0Y21Kez9NO50nXA7uxiHF45D 8smK6ZK/Sh8kxcPk0IfBTP8Wc5L3bHR10fJewHZDwEwADQSkxiJV6Sq0K4I+xzLjXLBm j9//o703mD/15ncewsAosBxvwt9mILypYww7sVVkDIhL6c9fsNMrjKMaL0Uj3EJVI33g MFQd7GunVx1khXrl9T8Uja4BEPvPaku58zUpc7GDuL1GIAkc2q9boKoQiE4J5EpJStvf Vs1pdJA/5RlXzzj9MYk1sW0EanI/govfbPxAAGkQJdRyZxR88im53gRJlLTARe56/BHA /ptw== X-Gm-Message-State: AOJu0Yz1QH5TvyELKgTyIl4rfJIc4EZQ/bXiLcqAyNrKYdn8Xbyzi+FQ KLBiXhLEMUZPieNlwxc/dXPcCWUXfyznOB81egliwg/KfXNbmI9NzfRl2eePx5YXS0vU1h9NDc6 /LsI= X-Gm-Gg: ASbGncvsAoHZHb8y4RFVFuhS4AQj15g0R9DPT9rFTEXkltLusy4dmW6NjuQ2tCBJ+uP g75QBP1LvI/YyCBJPsNcatNzbO1K18I4VShiFcbQTNF18HF8ev8OO0jRWCao5lZZ/Jc0xfbeB1+ g0vZTMDyts1D8E4MSRpezc+vnJl187pW/Ld7NC1kwYz2Z/RZnKdQohU3F8JIf1iX5P1Q5/D3fVa iVbp/ParPbbHO2U6/7IkBOkANwMHv3vjWOEPW9hb4gzNJE/1cT5yEluJ3u8nKQ3d/D4iPtjlqxc gpANtYpJkpqXyWLxoWeuaGkJeLNLP4HCCr4nS+0Oh9LJQgevb0foU/WIWCIKxYI4lQaOV4KgR/V zI05yJHZOUFP0v10ySo/s X-Google-Smtp-Source: AGHT+IEOxUWQw6/5ixhOH5WdHssUArvknGU+ztgqIBZDDfyZizCqWDwi+O3kWCLH2Lv2XrJdMg9HIw== X-Received: by 2002:a05:600c:5395:b0:43d:db5:7b1a with SMTP id 5b1f17b1804b1-4406ab96f63mr164481765e9.12.1745359182425; Tue, 22 Apr 2025 14:59:42 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:41 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 20/27] libcamera: software_isp: debayer_egl: Extend logic to enable application of softISP RGB debayer params Date: Tue, 22 Apr 2025 22:59:13 +0100 Message-ID: <20250422215920.4297-21-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" The existing SoftISP calculates RGB gain values as a lookup table of 256 values which shifts for each frame depending on the required correction. We can pass the required tables into the debayer shaders as textures, one texture for R, G and B respectively. The debayer shader will do its debayer interpolation and then if the appropriate define is specified use the calculated R, G and B values as indexes into our bayer colour gain table. TODO: - Validate the number of available texture units and bail out if < 4 In reality ~ all hardware has at least 16 units - Rename the debayer class to something like eglDebayer to reflect the fact its eGL based. - Add in the CCM tables too. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/debayer_egl.cpp | 74 +++++++++++++++++----- src/libcamera/software_isp/debayer_egl.h | 15 +++-- 2 files changed, 69 insertions(+), 20 deletions(-) diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 008938f8..f02ec8b2 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -26,6 +26,15 @@ DebayerEGL::DebayerEGL(std::unique_ptr stats) DebayerEGL::~DebayerEGL() { + if (eglImageBlueLookup_) + delete eglImageBlueLookup_; + + if (eglImageGreenLookup_) + delete eglImageGreenLookup_; + + if (eglImageRedLookup_) + delete eglImageRedLookup_; + if (eglImageBayerIn_) delete eglImageBayerIn_; } @@ -87,9 +96,11 @@ int DebayerEGL::getShaderVariableLocations(void) attributeVertex_ = glGetAttribLocation(programId_, "vertexIn"); attributeTexture_ = glGetAttribLocation(programId_, "textureIn"); - textureUniformY_ = glGetUniformLocation(programId_, "tex_y"); - textureUniformU_ = glGetUniformLocation(programId_, "tex_u"); - textureUniformV_ = glGetUniformLocation(programId_, "tex_v"); + textureUniformBayerDataIn_ = glGetUniformLocation(programId_, "tex_y"); + textureUniformRedLookupDataIn_ = glGetUniformLocation(programId_, "red_param"); + textureUniformGreenLookupDataIn_ = glGetUniformLocation(programId_, "green_param"); + textureUniformBlueLookupDataIn_ = glGetUniformLocation(programId_, "blue_param"); + textureUniformStep_ = glGetUniformLocation(programId_, "tex_step"); textureUniformSize_ = glGetUniformLocation(programId_, "tex_size"); textureUniformStrideFactor_ = glGetUniformLocation(programId_, "stride_factor"); @@ -97,9 +108,10 @@ int DebayerEGL::getShaderVariableLocations(void) textureUniformProjMatrix_ = glGetUniformLocation(programId_, "proj_matrix"); LOG(Debayer, Info) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ - << " tex_y " << textureUniformY_ - << " tex_u " << textureUniformU_ - << " tex_v " << textureUniformV_ + << " tex_y " << textureUniformBayerDataIn_ + << " red_param " << textureUniformRedLookupDataIn_ + << " red_param " << textureUniformGreenLookupDataIn_ + << " red_param " << textureUniformBlueLookupDataIn_ << " tex_step " << textureUniformStep_ << " tex_size " << textureUniformSize_ << " stride_factor " << textureUniformStrideFactor_ @@ -202,6 +214,9 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm break; }; + // Flag to shaders that we have parameter gain tables + egl_.pushEnv(shaderEnv, "#define APPLY_BAYER_PARAMETERS"); + if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, vertexShaderDataLen, shaderEnv)) goto compile_fail; @@ -285,7 +300,24 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, if (egl_.initEGLContext(&gbmSurface_)) return -ENODEV; - eglImageBayerIn_ = new eGLImage(width_, height_, 32); + // Raw bayer input as texture + eglImageBayerIn_ = new eGLImage(width_, height_, 32, GL_TEXTURE0, 0); + if (!eglImageBayerIn_) + return -ENOMEM; + + /// RGB correction tables as 2d textures + // eGL doesn't support glTexImage2D so we do a little hack with 2D to compensate + eglImageRedLookup_ = new eGLImage(DebayerParams::kRGBLookupSize, 1, 32, GL_TEXTURE1, 1); + if (!eglImageRedLookup_) + return -ENOMEM; + + eglImageGreenLookup_ = new eGLImage(DebayerParams::kRGBLookupSize, 1, 32, GL_TEXTURE2, 2); + if (!eglImageGreenLookup_) + return -ENOMEM; + + eglImageBlueLookup_ = new eGLImage(DebayerParams::kRGBLookupSize, 1, 32, GL_TEXTURE3, 3); + if (!eglImageBlueLookup_) + return -ENOMEM; // Create a single BO (calling gbm_surface_lock_front_buffer() again before gbm_surface_release_buffer() would create another BO) if (gbmSurface_.mapSurface()) @@ -394,7 +426,14 @@ void DebayerEGL::setShaderVariableValues(void) glVertexAttribPointer(attributeTexture_, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(GLfloat), tcoordinates); - glUniform1i(textureUniformY_, 0); // tex_y - bayer_8.vert - set for no reason + // Set the sampler2D to the respective texture unit for each texutre + // To simultaneously sample multiple textures we need to use multiple + // texture units + glUniform1i(textureUniformBayerDataIn_, eglImageBayerIn_->texture_unit_uniform_id_); + glUniform1i(textureUniformRedLookupDataIn_, eglImageRedLookup_->texture_unit_uniform_id_); + glUniform1i(textureUniformGreenLookupDataIn_, eglImageGreenLookup_->texture_unit_uniform_id_); + glUniform1i(textureUniformBlueLookupDataIn_, eglImageBlueLookup_->texture_unit_uniform_id_); + glUniform2fv(textureUniformBayerFirstRed_, 1, firstRed); // tex_bayer_first_red - bayer_8.vert glUniform2fv(textureUniformSize_, 1, imgSize); // tex_size - bayer_8.vert glUniform2fv(textureUniformStep_, 1, Step); // tex_step - bayer_8.vert @@ -403,9 +442,10 @@ void DebayerEGL::setShaderVariableValues(void) GL_FALSE, projIdentityMatrix); // No scaling LOG(Debayer, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ - << " tex_y " << textureUniformY_ - << " tex_u " << textureUniformU_ - << " tex_v " << textureUniformV_ + << " tex_y " << textureUniformBayerDataIn_ + << " red_param " << textureUniformRedLookupDataIn_ + << " red_param " << textureUniformGreenLookupDataIn_ + << " red_param " << textureUniformBlueLookupDataIn_ << " tex_step " << textureUniformStep_ << " tex_size " << textureUniformSize_ << " stride_factor " << textureUniformStrideFactor_ @@ -423,7 +463,7 @@ void DebayerEGL::setShaderVariableValues(void) return; } -void DebayerEGL::debayerGPU(MappedFrameBuffer &in, MappedFrameBuffer &out) +void DebayerEGL::debayerGPU(MappedFrameBuffer &in, MappedFrameBuffer &out, DebayerParams ¶ms) { LOG(Debayer, Debug) << "Input height " << height_ @@ -433,13 +473,15 @@ void DebayerEGL::debayerGPU(MappedFrameBuffer &in, MappedFrameBuffer &out) // eGL context switch egl_.makeCurrent(); - // make texture unit 0 explicit this doesn't really matter probably remove ? - glActiveTexture(GL_TEXTURE0); - // Greate a standard texture // we will replace this with the DMA version at some point egl_.createTexture2D(eglImageBayerIn_, inputConfig_.stride, height_, in.planes()[0].data()); + // Populate bayer parameters + egl_.createTexture2D(eglImageRedLookup_, DebayerParams::kRGBLookupSize, 1, ¶ms.red); + egl_.createTexture2D(eglImageGreenLookup_, DebayerParams::kRGBLookupSize, 1, ¶ms.green); + egl_.createTexture2D(eglImageBlueLookup_, DebayerParams::kRGBLookupSize, 1, ¶ms.blue); + // Setup the scene setShaderVariableValues(); glViewport(0, 0, width_, height_); @@ -482,7 +524,7 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output return; } - debayerGPU(in, out); + debayerGPU(in, out, params); dmaSyncers.clear(); diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index 14f6997a..c8a19c3c 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -110,7 +110,7 @@ private: int getShaderVariableLocations(); void setShaderVariableValues(void); void configureTexture(GLuint &texture); - void debayerGPU(MappedFrameBuffer &in, MappedFrameBuffer &out); + void debayerGPU(MappedFrameBuffer &in, MappedFrameBuffer &out, DebayerParams ¶ms); // Shader program identifiers GLuint vertexShaderId_; @@ -125,20 +125,27 @@ private: // Pointer to object representing input texture eGLImage *eglImageBayerIn_; + eGLImage *eglImageRedLookup_; + eGLImage *eglImageGreenLookup_; + eGLImage *eglImageBlueLookup_; + // Shader parameters float firstRed_x_; float firstRed_y_; GLint attributeVertex_; GLint attributeTexture_; - GLint textureUniformY_; - GLint textureUniformU_; - GLint textureUniformV_; GLint textureUniformStep_; GLint textureUniformSize_; GLint textureUniformStrideFactor_; GLint textureUniformBayerFirstRed_; GLint textureUniformProjMatrix_; + #define DEBAYER_EGL_MIN_TEXTURE_UNITS 4 + GLint textureUniformBayerDataIn_; + GLint textureUniformRedLookupDataIn_; + GLint textureUniformGreenLookupDataIn_; + GLint textureUniformBlueLookupDataIn_; + Rectangle window_; std::unique_ptr stats_; eGL egl_; From patchwork Tue Apr 22 21:59:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23234 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 C36F8C3320 for ; Tue, 22 Apr 2025 22:00:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 17F2968B37; Wed, 23 Apr 2025 00:00:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="pUjlyZN3"; dkim-atps=neutral Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F18068B3B for ; Tue, 22 Apr 2025 23:59:44 +0200 (CEST) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-39c1ef4acf2so3680252f8f.0 for ; Tue, 22 Apr 2025 14:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359183; x=1745963983; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dfrf9NfeIzeHZUKoKR6Xey4sb9Odqh4LqL16fz3Aurk=; b=pUjlyZN3wzoXbNf4yeD5wqSUVCD/jaW0n74YNEppTDl42ATDezvfisq63Oj6I+OR8X MhvA7vCtQB/pjxv/QF2NSK7qOMJoyA6jPvMaWiSWnvSP3Nx7PybDSLGGsKsWr2+RjEez gZCneI4spWIMGfSjnOVCCxJoKUffHdZ3+4KyGvlrExu0AO7AOLSJ9czW+EycwJMxw4Kx kbBBIwihvahppeWPFRIuD0jdMuxc/A/D5/owKLqG6pvrgbA6/T/FVzg3G/q5U5ixVXhN 8akgO98igLmvvM0NbHqOXquANcJk+rbk5CxKD0vjlNoM/7GM1RA1fe8coH6lGkW//Kp3 zxXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359183; x=1745963983; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dfrf9NfeIzeHZUKoKR6Xey4sb9Odqh4LqL16fz3Aurk=; b=sv+unWVtMctRW1On3tF7xT/pYSX5xKCdMAGWI+kbjRrCCbcaCFE4ncZkk5ZClUlE0R QSa2UFqk0JtJdxqFeyLvRWITzC6xuU1HE3WWARSaU3abJ7v+KHUMlUATsqjCUtDhcFkn AenmrITwVhA33Sr0RKERHQvTiWUNvGTT9ATefQAlAsAEf6yZ+Be5UkCL3ad5RX+xNGke PAG8U/+9FJnPeErZ3qmeLd5V7JGehk5Xn4wbOq1fc3wteATuGmmE3SLoXyeN8Mj3jytU FiMLcfzCzzLfihnp1qrdOS0sKOHR0pFOPHn4CtFDk/x0p2iIVKTafY30kqBLZFV3Odjp wEuw== X-Gm-Message-State: AOJu0YybsZoUw0LhK3GQgTHdU3lvmdsH0WdgzLcPOvy7/RTvo2lfOk4E leYN6XwG12p/9ch0dYGFGrsep1ehNuIm0+w27WziFfamHri21wbRDfEoyTGksgRKLT8Za8hfSha tX2Y= X-Gm-Gg: ASbGncuz7wEnTdqxlJfunbC0HiWc0Jw/60XoDojhtM64x3wI5SLm0HvytYNP9ku9ZAN NnVLDeDuWNsAn6vHPldMTNxssR3yzZMChGHGVEFpnD/PYbHuXD22WQhhF7x5DEa2iWboDJLmzwe Yrfv0uJJxXIjX71GU8LSdIii426eylawRaaddoCFFLZfJgunK+IIUrTyElxOGuZn8m4J69ONhl6 XmaEGL6EkgJ3Szd9GRaJLLnmryx85PSrK1JIZe0kHvcXlvZWJAIFiGTvnM0RdBgOz5UDGhEph3z J3/5VC9RWIBBKfS/MZdFAZ+Vwk2cG3HKreZqafVULH3cXlgnGgSBsMEexXuK5eSkmouqw63aPj9 4CJiMgd1ckq5CH1zjtVN6 X-Google-Smtp-Source: AGHT+IFq3iNq33PAXIwtpC5e1ualOsqGlxo7UJzEBasQHsQAg1Dcovnyc4/zHwxboOs+sqziSjHTYA== X-Received: by 2002:a05:6000:40ce:b0:39c:1257:dba8 with SMTP id ffacd0b85a97d-39efbaf201amr12617212f8f.56.1745359183430; Tue, 22 Apr 2025 14:59:43 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:42 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 21/27] libcamera: software_isp: debayer_egl: Make DebayerEGL the default debayer method Date: Tue, 22 Apr 2025 22:59:14 +0100 Message-ID: <20250422215920.4297-22-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Try the EGL debayer method, if that fails then try the CPU version before bailing out entirely. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/software_isp.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index c3dc21de..e4c7fda1 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -25,6 +25,7 @@ #include "libcamera/internal/software_isp/debayer_params.h" #include "debayer_cpu.h" +#include "debayer_egl.h" /** * \file software_isp.cpp @@ -114,7 +115,17 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, } stats->statsReady.connect(this, &SoftwareIsp::statsReady); - debayer_ = std::make_unique(std::move(stats)); + //TODO: derive the selection from file/environment variable + debayer_ = std::make_unique(std::move(stats)); + if (!debayer_) { + LOG(SoftwareIsp, Error) << "Failed to create DebayerEGL object"; + debayer_ = std::make_unique(std::move(stats)); + if (!debayer_) { + LOG(SoftwareIsp, Error) << "Failed to create DebayerCPUGL object"; + return; + } + } + debayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady); debayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady); From patchwork Tue Apr 22 21:59:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23235 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 8D011C3322 for ; Tue, 22 Apr 2025 22:00:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CC76768B3B; Wed, 23 Apr 2025 00:00:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="gzaVBkQD"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E565C68B3C for ; Tue, 22 Apr 2025 23:59:44 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-43d0782d787so40757395e9.0 for ; Tue, 22 Apr 2025 14:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359184; x=1745963984; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iEIy8k+5TThGQoOX04wnJpO98XLgjGigWGAQBmfK/uY=; b=gzaVBkQDwsgj4uLoViMyC1syuDStEyqsYZtSQo1WE82nasaA+p/A1JmU4CNy530V7Y Sp8LmxP07rb023hficnNUjmiccK0sYtJ6b3Zos1aQOOoY0DXBOyw5qwMigSBtkR6SRHi 48LZy5zOunNolnERC07cvP197KebvWUF58rTIZ4PLMQ524WUAeMXZxkzdJMFJrghkws1 Ze3lIaw9S0C88Q6zwC/NYx3LQEkudx8v9ypKYLxuHnf2T9MIxA7/ppxVHZrl/RXct6fD ixp53vtJXNGfSNHSS42iUYDH9BgWGLyJxPKolkLKhrHLg6OSE9suEzOz2T8/LgSMtaF+ eH2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359184; x=1745963984; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iEIy8k+5TThGQoOX04wnJpO98XLgjGigWGAQBmfK/uY=; b=UGR9fzuxLKvRoRnNGd0HJEHPsandt7Rpa648KsSP5NJgIRBaqPEsL8ShKR+74Y8/mO Il9IzEycKhsdMDGGiWV+Ve6vZbXKzU+H0x9zSUXQDLGw9l/BBnNOrqUIk1eIS7tEVYpw ycZV2qGTHlfOwlpicrMqovK7K37c4dnrTwXmJScZyftcDbCEHKV31SyXNzKS3vNj7R6/ qjUyVAGRXQazhF9c5CANq5bqedZDqJsU6wJ2AfGtISNqRmXPSDbW0ACwatEIIznn5088 JApdbUV1V9RDL/QOoVB7heCTVK6Nx8QFDFW6Pvri7Qj5ACPmUvmXbv1tkLHj1+D/psZT AE2A== X-Gm-Message-State: AOJu0YzmbB3j82GWDyl+LaZoB/+/vxC9CN/vwOAy8Ic2LjDEIynVVIrl WfAzEFVIynOspx6Z7830gIoYiq9+ovThmcbOXdKu3Ss7OmIQq2jBQzzNXrnX0zFcnJ6p9xBkLbB a7/c= X-Gm-Gg: ASbGncvKgAZoKyVkHLfrSU+pgspMwzZXFr1kVfMCsSMaMAve5Li2zYWXZdZODK+Ed2w Jf3+V1U/QosZrkVvp9EGj/kv9MwU7z4vj5Lo6D9DnXU42FY1TFzVlhbrTJj2vwQALW9RRWCAzgI n0W0l+2hP8GPTezO8rR8TMMJrXwIp9s8RbiqGy1nLHo4PV1kvpfeMJoc/OSq9E2iFtOde31BvOb RycsNbqpq+IsWGG2wJRFA3HeZZUaS6Qxl34CIkmqusMvhwUVNpcFe6m91rtp1iQk7/5Ck57QN2h MVDvmCH+M/o6BvSPMnwnSQgvoV96WD+xJevmvD21Rtt2pXQosikWNveRiWpImrhpcyLF4YA8YSo uNQP7UbO309jjV6ake88r X-Google-Smtp-Source: AGHT+IHpsghOASku6uGLoJ3eU5orWbyf1WRAKi5yC6xNAAbGhjvbp8b/bSxAguL3ir2MxR35noNF1g== X-Received: by 2002:a05:600c:3107:b0:43c:f64c:447f with SMTP id 5b1f17b1804b1-4406ac163bemr115608335e9.29.1745359184323; Tue, 22 Apr 2025 14:59:44 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:43 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 22/27] libcamera: software_isp: egl: Bind each eglImage to its own texture unit Date: Tue, 22 Apr 2025 22:59:15 +0100 Message-ID: <20250422215920.4297-23-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/egl.cpp | 1 + src/libcamera/software_isp/egl.h | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libcamera/software_isp/egl.cpp b/src/libcamera/software_isp/egl.cpp index c3eb8290..885eaa84 100644 --- a/src/libcamera/software_isp/egl.cpp +++ b/src/libcamera/software_isp/egl.cpp @@ -85,6 +85,7 @@ void eGL::destroyDMABufTexture(eGLImage *eglImage) // Generate a 2D texture from an input buffer directly void eGL::createTexture2D(eGLImage *eglImage, uint32_t width, uint32_t height, void *data) { + glActiveTexture(eglImage->texture_unit_); glBindTexture(GL_TEXTURE_2D, eglImage->texture_); // Generate texture, bind, associate image to texture, configure, unbind diff --git a/src/libcamera/software_isp/egl.h b/src/libcamera/software_isp/egl.h index f3c5d50f..64cf2a87 100644 --- a/src/libcamera/software_isp/egl.h +++ b/src/libcamera/software_isp/egl.h @@ -29,13 +29,15 @@ LOG_DECLARE_CATEGORY(eGL) class eGLImage { public: - eGLImage(uint32_t width, uint32_t height, uint32_t bpp) { + eGLImage(uint32_t width, uint32_t height, uint32_t bpp, GLenum texture_unit, uint32_t texture_unit_uniform_id) { image_ = EGL_NO_IMAGE_KHR; width_ = width; height_ = height; bpp_ = bpp; stride_ = width_ * bpp_ / 4; framesize_ = stride_ * height_; + texture_unit_ = texture_unit; + texture_unit_uniform_id_ = texture_unit_uniform_id; glGenTextures(1, &texture_); } @@ -44,14 +46,16 @@ public: glDeleteTextures(1, &texture_); }; - GLuint texture_; - EGLImageKHR image_; uint32_t width_; uint32_t height_; uint32_t stride_; uint32_t offset_; uint32_t framesize_; uint32_t bpp_; + uint32_t texture_unit_uniform_id_; + GLenum texture_unit_; + GLuint texture_; + EGLImageKHR image_; }; class eGL From patchwork Tue Apr 22 21:59:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23236 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 DC075C32A2 for ; Tue, 22 Apr 2025 22:00:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D525868B36; Wed, 23 Apr 2025 00:00:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="NvOLafmz"; dkim-atps=neutral Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C779268B40 for ; Tue, 22 Apr 2025 23:59:45 +0200 (CEST) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-43cf257158fso37902725e9.2 for ; Tue, 22 Apr 2025 14:59:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359185; x=1745963985; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aHV/OzBettE9JMBz8rxXsO0JyXp6g3150ZsuVLe9cQ0=; b=NvOLafmzSzR7jvTcURNl+cWoaOLGe/dIQkj+lZctBmB5t+Pw8gSEv/WN9jSe0jmnJJ 43ZGYDJacBAoU0Xv3LXWA/qXYV0ysgFvvQtnHB33Hg6q4zTtKx34Ej01Len0aiAmUrE6 gnD3zrp95IwwUtrdb57f3bx0vM62wocix8KW2aISU/cbGmnFT+bwaftyY4LsJ+ZPlhU/ 1lEDBVuGk8idBemgG76psjnpRM1quZKZ+yU6tOA8vQqM0tH/cf55pT9bOs3mXxppkdvb pIzkrEXX/zvi1KCGwHIPN8hR+LUFax+9tSG9VgeX/YCZwWKrskvSYpm0YsziuzEUdBgV EfpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359185; x=1745963985; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aHV/OzBettE9JMBz8rxXsO0JyXp6g3150ZsuVLe9cQ0=; b=jjVm0RlA7fypuTIDGxIfE478UMiiJijpze3uHfB3wZWKTAHQOL7+SQopTloZL4Nq4J +6oE5KY83zaliKeL1JTQbTBzf5xo94U73V7s/SnLMgebBT5saz2jcL0oiAHI020hz2AG TQ3K8MTIi8AAfHydwFghPIJK4WPZ2XjUTooxSKq1vHbFIOHr5EDvABhJ67g33b+nmpD7 yW6O02kNzza6lQ5HE+/RM1ZV3eNG/MiN3DKu3HwZ9Zyh+rIMyrVznxdIGVSu3nuvMu8g e+yzHNV1OcwOKTFQ3flRftNcqUEx18012LRC+/PAHXQeINyAhUV7jWUCOxo9DJgO50ON AOkA== X-Gm-Message-State: AOJu0YwoHErErEdgnbJ4IHD9VAlOSVIe/FC4UZPFA4B1b0epsm2Ori0g AOJuU0nLyNxAa/500ZX8Ca5uGNEwPCKCJk6Nz0SgoFYQdMFoXCsOtcUE2be4aZ4slpUlfeqdeYD 6/QI= X-Gm-Gg: ASbGncswv0C1iB3Eynkm92HAcnp2XfDVAq1mKtkj6oHYpPTTvV+YcOvjwiS48rZW3U6 Ro8o2nmVPRJ/+Ydlrx1+Iqdkr6oya8Mzcxzt38Hskaysc9DKyVGTxJ1LGd9Ce3SKGvTWWGbv94G XOzI5VHL86LXdYnalz35A96J4MzFj97vy9u8vJPRamzEAWoLRA6iq+hdjjqdg8kRA2vLsh9SWUd GNcGVtwTaMPM2kX1IaCA4ixAcST1RwJ38tJ8b5QQ/G5iuMOz6nnIMicUsCI8lpqTOpYAx7eit3H 9unQwvIMT7m9J9t7H8P7prSYi6piZyVwNEccDgJ7rTYavPgGRpTEeYmri+fdCtNy3+fEaDw7mWz xBYWhz4n9OeoELJc9wC8kukqd5bkf5gs= X-Google-Smtp-Source: AGHT+IGoNtvjoDWPqZBIAPAQUPdPrlP+qS7fUcII/7qdawBqNzL9XJABbhc6SBUpmFTbrITLwCmQCw== X-Received: by 2002:a05:600c:1d0d:b0:43c:fae1:5151 with SMTP id 5b1f17b1804b1-4406abf90f4mr114923525e9.25.1745359185199; Tue, 22 Apr 2025 14:59:45 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:44 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 23/27] libcamera: shaders: Use highp not mediump for float precision Date: Tue, 22 Apr 2025 22:59:16 +0100 Message-ID: <20250422215920.4297-24-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" We get better sample resolution with highp instead of mediump. Signed-off-by: Bryan O'Donoghue --- src/apps/qcam/assets/shader/RGB.frag | 2 +- src/apps/qcam/assets/shader/YUV_2_planes.frag | 2 +- src/apps/qcam/assets/shader/YUV_3_planes.frag | 2 +- src/apps/qcam/assets/shader/YUV_packed.frag | 2 +- src/apps/qcam/assets/shader/bayer_1x_packed.frag | 2 +- src/apps/qcam/assets/shader/bayer_8.frag | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/apps/qcam/assets/shader/RGB.frag b/src/apps/qcam/assets/shader/RGB.frag index 4c374ac9..72439589 100644 --- a/src/apps/qcam/assets/shader/RGB.frag +++ b/src/apps/qcam/assets/shader/RGB.frag @@ -6,7 +6,7 @@ */ #ifdef GL_ES -precision mediump float; +precision highp float; #endif varying vec2 textureOut; diff --git a/src/apps/qcam/assets/shader/YUV_2_planes.frag b/src/apps/qcam/assets/shader/YUV_2_planes.frag index 1d5d1206..d286f117 100644 --- a/src/apps/qcam/assets/shader/YUV_2_planes.frag +++ b/src/apps/qcam/assets/shader/YUV_2_planes.frag @@ -6,7 +6,7 @@ */ #ifdef GL_ES -precision mediump float; +precision highp float; #endif varying vec2 textureOut; diff --git a/src/apps/qcam/assets/shader/YUV_3_planes.frag b/src/apps/qcam/assets/shader/YUV_3_planes.frag index 8f788e90..8e3e0b4a 100644 --- a/src/apps/qcam/assets/shader/YUV_3_planes.frag +++ b/src/apps/qcam/assets/shader/YUV_3_planes.frag @@ -6,7 +6,7 @@ */ #ifdef GL_ES -precision mediump float; +precision highp float; #endif varying vec2 textureOut; diff --git a/src/apps/qcam/assets/shader/YUV_packed.frag b/src/apps/qcam/assets/shader/YUV_packed.frag index b9ef9d41..3c9e3e39 100644 --- a/src/apps/qcam/assets/shader/YUV_packed.frag +++ b/src/apps/qcam/assets/shader/YUV_packed.frag @@ -6,7 +6,7 @@ */ #ifdef GL_ES -precision mediump float; +precision highp float; #endif varying vec2 textureOut; diff --git a/src/apps/qcam/assets/shader/bayer_1x_packed.frag b/src/apps/qcam/assets/shader/bayer_1x_packed.frag index f53f5575..19b13ad0 100644 --- a/src/apps/qcam/assets/shader/bayer_1x_packed.frag +++ b/src/apps/qcam/assets/shader/bayer_1x_packed.frag @@ -20,7 +20,7 @@ */ #ifdef GL_ES -precision mediump float; +precision highp float; #endif /* diff --git a/src/apps/qcam/assets/shader/bayer_8.frag b/src/apps/qcam/assets/shader/bayer_8.frag index 7e35ca88..aa7a1b00 100644 --- a/src/apps/qcam/assets/shader/bayer_8.frag +++ b/src/apps/qcam/assets/shader/bayer_8.frag @@ -16,7 +16,7 @@ Copyright (C) 2021, Linaro //Pixel Shader #ifdef GL_ES -precision mediump float; +precision highp float; #endif /** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/ From patchwork Tue Apr 22 21:59:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23237 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 08DEBC331F for ; Tue, 22 Apr 2025 22:00:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AEA5468B47; Wed, 23 Apr 2025 00:00:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="lANPso9k"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C731168B37 for ; Tue, 22 Apr 2025 23:59:46 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-43edecbfb94so59331195e9.1 for ; Tue, 22 Apr 2025 14:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359186; x=1745963986; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ad4DFb+tDm+2Co7srTTrLGrL0wSemjiSTQC9DUdMUhc=; b=lANPso9kOZlosWGm4e66OHXzl22DPYIHZBL3Jb+3mJibAQ761AQ6X1z4loAK1qWu4j mQyNFEWqls0l7CMeUqbEi6FGl9RPUX4Myi1/Aru2vcj2up1ozsQEUNClZahgi5F44C1L 8MW5wfRDwvfL/7HePQBilAbUlFpeuDLmLNykyMGHp8CKMu4RSRRCOcOb1pKAx4wv6a/Y N7o5OtDcUoaSAoWPcVNx93FZE88xZLtcq/LtfFdiBI7XlqLmoV4eL0LyXIpseH9l6KEX +6X7uk+X0JmS/l/Be2I5T0EO3vvyl8WhX8mzTBjUwOPci6LWssvkyloYwkxcxeOTziwc 38+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359186; x=1745963986; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ad4DFb+tDm+2Co7srTTrLGrL0wSemjiSTQC9DUdMUhc=; b=cb84+kB1OnBuedclo9CVb8JzOwdTf6pRcLZOn8tfTC1NHZ58fvY5rw27R+SK0i7I+8 7Ya/1MyipsOC4SnVETT17k7J9CRY7EBRCQIPHN4zl97nuP5JPLuBoWtOi43bLu1RIjFp iq8k+N0OqInL5tkWeqLftm68u9GREH4JBxud/BcXtLFPNPv0K4+r0zcxI1PHAEJ+zrAn dU5dv0P2PjLc4vYEftWW4nA4qWEhWk44CGLtCbq9FBC/lPmUUvYFHXk8v+OdwBT1EFHz YwGJax/+y5iWP7HTsSXTujkh2UPSUVlmgV+1BzxgNveXbax29q2xohcHfUt3HYW9XiQZ EyrA== X-Gm-Message-State: AOJu0YykTMlC4uViPzDq7eYmqazccL2y2QU6I7xiqJPgxAk5I6dvsFpI WzYP2LkvZ24SMGZ2cl0bElkmF/902ztvKaOsBfSfO8RJ5/jute2Z56b5XJGTAtLzn2QGiLfsp6t H8vg= X-Gm-Gg: ASbGnctDBdDpdSUVZNJ/nDGrJp31DNtq/jy76zfB/qhG9IOUsjuGdBGgS14fRuvfEb8 KeCeQzwzODFP6+V54hOoBjyZOJVJ/R62XtZlCNkyX3T/0kG0SVkq9QNt2KFVWoXzCD4B3UfMIhb z/zGsdm5ppjyAfTWf+UtBPRclwH7nch+VOO1pArm4EyvsPPl4wkfCuL7ApljZy5wvLJH+I9Z4MV yMYrygX02nhXXTzntQZY8rBzrSh856xbCduhwu4UnG5XRLBHdI1MwInJkHZKlRubg89bAb4gkOF rafo41arNXvGXAlyBbRDHWnR7pgtwVzMEcSbu+kNySR1pbCuHVksqYakWDW1JnVLJ50MjtI466o TdIbwrlvHGZXe0Zi9HGMW X-Google-Smtp-Source: AGHT+IE3r185+/KAz7I8jOa2YhCFWt3jkn9edo9eA/5w94MhuQfOajQRaW36Twin+/ufoNDVS94Ymw== X-Received: by 2002:a05:600c:3d18:b0:43c:f629:66f3 with SMTP id 5b1f17b1804b1-4406aba71f6mr174862965e9.18.1745359186141; Tue, 22 Apr 2025 14:59:46 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:45 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 24/27] libcamera: shaders: Move GL shader programs to src/libcamera/assets/shader Date: Tue, 22 Apr 2025 22:59:17 +0100 Message-ID: <20250422215920.4297-25-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Moving the GL shaders to src/libcamera/assets/shader to allow for reuse of these inside of the SoftISP. Signed-off-by: Bryan O'Donoghue --- .../libcamera/internal/shaders}/RGB.frag | 0 .../internal/shaders}/YUV_2_planes.frag | 0 .../internal/shaders}/YUV_3_planes.frag | 0 .../internal/shaders}/YUV_packed.frag | 0 .../internal/shaders}/bayer_1x_packed.frag | 0 .../libcamera/internal/shaders}/bayer_8.frag | 0 .../libcamera/internal/shaders}/bayer_8.vert | 0 .../libcamera/internal/shaders}/identity.vert | 0 src/apps/qcam/assets/shader/shaders.qrc | 16 ++--- src/apps/qcam/viewfinder_gl.cpp | 70 +++++++++---------- 10 files changed, 43 insertions(+), 43 deletions(-) rename {src/apps/qcam/assets/shader => include/libcamera/internal/shaders}/RGB.frag (100%) rename {src/apps/qcam/assets/shader => include/libcamera/internal/shaders}/YUV_2_planes.frag (100%) rename {src/apps/qcam/assets/shader => include/libcamera/internal/shaders}/YUV_3_planes.frag (100%) rename {src/apps/qcam/assets/shader => include/libcamera/internal/shaders}/YUV_packed.frag (100%) rename {src/apps/qcam/assets/shader => include/libcamera/internal/shaders}/bayer_1x_packed.frag (100%) rename {src/apps/qcam/assets/shader => include/libcamera/internal/shaders}/bayer_8.frag (100%) rename {src/apps/qcam/assets/shader => include/libcamera/internal/shaders}/bayer_8.vert (100%) rename {src/apps/qcam/assets/shader => include/libcamera/internal/shaders}/identity.vert (100%) diff --git a/src/apps/qcam/assets/shader/RGB.frag b/include/libcamera/internal/shaders/RGB.frag similarity index 100% rename from src/apps/qcam/assets/shader/RGB.frag rename to include/libcamera/internal/shaders/RGB.frag diff --git a/src/apps/qcam/assets/shader/YUV_2_planes.frag b/include/libcamera/internal/shaders/YUV_2_planes.frag similarity index 100% rename from src/apps/qcam/assets/shader/YUV_2_planes.frag rename to include/libcamera/internal/shaders/YUV_2_planes.frag diff --git a/src/apps/qcam/assets/shader/YUV_3_planes.frag b/include/libcamera/internal/shaders/YUV_3_planes.frag similarity index 100% rename from src/apps/qcam/assets/shader/YUV_3_planes.frag rename to include/libcamera/internal/shaders/YUV_3_planes.frag diff --git a/src/apps/qcam/assets/shader/YUV_packed.frag b/include/libcamera/internal/shaders/YUV_packed.frag similarity index 100% rename from src/apps/qcam/assets/shader/YUV_packed.frag rename to include/libcamera/internal/shaders/YUV_packed.frag diff --git a/src/apps/qcam/assets/shader/bayer_1x_packed.frag b/include/libcamera/internal/shaders/bayer_1x_packed.frag similarity index 100% rename from src/apps/qcam/assets/shader/bayer_1x_packed.frag rename to include/libcamera/internal/shaders/bayer_1x_packed.frag diff --git a/src/apps/qcam/assets/shader/bayer_8.frag b/include/libcamera/internal/shaders/bayer_8.frag similarity index 100% rename from src/apps/qcam/assets/shader/bayer_8.frag rename to include/libcamera/internal/shaders/bayer_8.frag diff --git a/src/apps/qcam/assets/shader/bayer_8.vert b/include/libcamera/internal/shaders/bayer_8.vert similarity index 100% rename from src/apps/qcam/assets/shader/bayer_8.vert rename to include/libcamera/internal/shaders/bayer_8.vert diff --git a/src/apps/qcam/assets/shader/identity.vert b/include/libcamera/internal/shaders/identity.vert similarity index 100% rename from src/apps/qcam/assets/shader/identity.vert rename to include/libcamera/internal/shaders/identity.vert diff --git a/src/apps/qcam/assets/shader/shaders.qrc b/src/apps/qcam/assets/shader/shaders.qrc index 96c709f9..04f9d706 100644 --- a/src/apps/qcam/assets/shader/shaders.qrc +++ b/src/apps/qcam/assets/shader/shaders.qrc @@ -1,13 +1,13 @@ - RGB.frag - YUV_2_planes.frag - YUV_3_planes.frag - YUV_packed.frag - bayer_1x_packed.frag - bayer_8.frag - bayer_8.vert - identity.vert + ../../../../../include/libcamera/internal/shaders/RGB.frag + ../../../../../include/libcamera/internal/shaders/YUV_2_planes.frag + ../../../../../include/libcamera/internal/shaders/YUV_3_planes.frag + ../../../../../include/libcamera/internal/shaders/YUV_packed.frag + ../../../../../include/libcamera/internal/shaders/bayer_1x_packed.frag + ../../../../../include/libcamera/internal/shaders/bayer_8.frag + ../../../../../include/libcamera/internal/shaders/bayer_8.vert + ../../../../../include/libcamera/internal/shaders/identity.vert diff --git a/src/apps/qcam/viewfinder_gl.cpp b/src/apps/qcam/viewfinder_gl.cpp index f31956ff..70f60065 100644 --- a/src/apps/qcam/viewfinder_gl.cpp +++ b/src/apps/qcam/viewfinder_gl.cpp @@ -141,7 +141,7 @@ bool ViewFinderGL::selectFormat(const libcamera::PixelFormat &format) textureMinMagFilters_ = GL_LINEAR; /* Use identity.vert as the default vertex shader. */ - vertexShaderFile_ = ":identity.vert"; + vertexShaderFile_ = ":include/libcamera/internal/shaders/identity.vert"; fragmentShaderDefines_.clear(); @@ -150,170 +150,170 @@ bool ViewFinderGL::selectFormat(const libcamera::PixelFormat &format) horzSubSample_ = 2; vertSubSample_ = 2; fragmentShaderDefines_.append("#define YUV_PATTERN_UV"); - fragmentShaderFile_ = ":YUV_2_planes.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_2_planes.frag"; break; case libcamera::formats::NV21: horzSubSample_ = 2; vertSubSample_ = 2; fragmentShaderDefines_.append("#define YUV_PATTERN_VU"); - fragmentShaderFile_ = ":YUV_2_planes.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_2_planes.frag"; break; case libcamera::formats::NV16: horzSubSample_ = 2; vertSubSample_ = 1; fragmentShaderDefines_.append("#define YUV_PATTERN_UV"); - fragmentShaderFile_ = ":YUV_2_planes.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_2_planes.frag"; break; case libcamera::formats::NV61: horzSubSample_ = 2; vertSubSample_ = 1; fragmentShaderDefines_.append("#define YUV_PATTERN_VU"); - fragmentShaderFile_ = ":YUV_2_planes.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_2_planes.frag"; break; case libcamera::formats::NV24: horzSubSample_ = 1; vertSubSample_ = 1; fragmentShaderDefines_.append("#define YUV_PATTERN_UV"); - fragmentShaderFile_ = ":YUV_2_planes.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_2_planes.frag"; break; case libcamera::formats::NV42: horzSubSample_ = 1; vertSubSample_ = 1; fragmentShaderDefines_.append("#define YUV_PATTERN_VU"); - fragmentShaderFile_ = ":YUV_2_planes.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_2_planes.frag"; break; case libcamera::formats::YUV420: horzSubSample_ = 2; vertSubSample_ = 2; - fragmentShaderFile_ = ":YUV_3_planes.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_3_planes.frag"; break; case libcamera::formats::YVU420: horzSubSample_ = 2; vertSubSample_ = 2; - fragmentShaderFile_ = ":YUV_3_planes.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_3_planes.frag"; break; case libcamera::formats::UYVY: fragmentShaderDefines_.append("#define YUV_PATTERN_UYVY"); - fragmentShaderFile_ = ":YUV_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_packed.frag"; break; case libcamera::formats::VYUY: fragmentShaderDefines_.append("#define YUV_PATTERN_VYUY"); - fragmentShaderFile_ = ":YUV_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_packed.frag"; break; case libcamera::formats::YUYV: fragmentShaderDefines_.append("#define YUV_PATTERN_YUYV"); - fragmentShaderFile_ = ":YUV_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_packed.frag"; break; case libcamera::formats::YVYU: fragmentShaderDefines_.append("#define YUV_PATTERN_YVYU"); - fragmentShaderFile_ = ":YUV_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/YUV_packed.frag"; break; case libcamera::formats::ABGR8888: fragmentShaderDefines_.append("#define RGB_PATTERN rgb"); - fragmentShaderFile_ = ":RGB.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/RGB.frag"; break; case libcamera::formats::ARGB8888: fragmentShaderDefines_.append("#define RGB_PATTERN bgr"); - fragmentShaderFile_ = ":RGB.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/RGB.frag"; break; case libcamera::formats::BGRA8888: fragmentShaderDefines_.append("#define RGB_PATTERN gba"); - fragmentShaderFile_ = ":RGB.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/RGB.frag"; break; case libcamera::formats::RGBA8888: fragmentShaderDefines_.append("#define RGB_PATTERN abg"); - fragmentShaderFile_ = ":RGB.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/RGB.frag"; break; case libcamera::formats::BGR888: fragmentShaderDefines_.append("#define RGB_PATTERN rgb"); - fragmentShaderFile_ = ":RGB.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/RGB.frag"; break; case libcamera::formats::RGB888: fragmentShaderDefines_.append("#define RGB_PATTERN bgr"); - fragmentShaderFile_ = ":RGB.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/RGB.frag"; break; case libcamera::formats::SBGGR8: firstRed_.setX(1.0); firstRed_.setY(1.0); - vertexShaderFile_ = ":bayer_8.vert"; - fragmentShaderFile_ = ":bayer_8.frag"; + vertexShaderFile_ = ":include/libcamera/internal/shaders/bayer_8.vert"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_8.frag"; textureMinMagFilters_ = GL_NEAREST; break; case libcamera::formats::SGBRG8: firstRed_.setX(0.0); firstRed_.setY(1.0); - vertexShaderFile_ = ":bayer_8.vert"; - fragmentShaderFile_ = ":bayer_8.frag"; + vertexShaderFile_ = ":include/libcamera/internal/shaders/bayer_8.vert"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_8.frag"; textureMinMagFilters_ = GL_NEAREST; break; case libcamera::formats::SGRBG8: firstRed_.setX(1.0); firstRed_.setY(0.0); - vertexShaderFile_ = ":bayer_8.vert"; - fragmentShaderFile_ = ":bayer_8.frag"; + vertexShaderFile_ = ":include/libcamera/internal/shaders/bayer_8.vert"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_8.frag"; textureMinMagFilters_ = GL_NEAREST; break; case libcamera::formats::SRGGB8: firstRed_.setX(0.0); firstRed_.setY(0.0); - vertexShaderFile_ = ":bayer_8.vert"; - fragmentShaderFile_ = ":bayer_8.frag"; + vertexShaderFile_ = ":include/libcamera/internal/shaders/bayer_8.vert"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_8.frag"; textureMinMagFilters_ = GL_NEAREST; break; case libcamera::formats::SBGGR10_CSI2P: firstRed_.setX(1.0); firstRed_.setY(1.0); fragmentShaderDefines_.append("#define RAW10P"); - fragmentShaderFile_ = ":bayer_1x_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_1x_packed.frag"; textureMinMagFilters_ = GL_NEAREST; break; case libcamera::formats::SGBRG10_CSI2P: firstRed_.setX(0.0); firstRed_.setY(1.0); fragmentShaderDefines_.append("#define RAW10P"); - fragmentShaderFile_ = ":bayer_1x_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_1x_packed.frag"; textureMinMagFilters_ = GL_NEAREST; break; case libcamera::formats::SGRBG10_CSI2P: firstRed_.setX(1.0); firstRed_.setY(0.0); fragmentShaderDefines_.append("#define RAW10P"); - fragmentShaderFile_ = ":bayer_1x_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_1x_packed.frag"; textureMinMagFilters_ = GL_NEAREST; break; case libcamera::formats::SRGGB10_CSI2P: firstRed_.setX(0.0); firstRed_.setY(0.0); fragmentShaderDefines_.append("#define RAW10P"); - fragmentShaderFile_ = ":bayer_1x_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_1x_packed.frag"; textureMinMagFilters_ = GL_NEAREST; break; case libcamera::formats::SBGGR12_CSI2P: firstRed_.setX(1.0); firstRed_.setY(1.0); fragmentShaderDefines_.append("#define RAW12P"); - fragmentShaderFile_ = ":bayer_1x_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_1x_packed.frag"; textureMinMagFilters_ = GL_NEAREST; break; case libcamera::formats::SGBRG12_CSI2P: firstRed_.setX(0.0); firstRed_.setY(1.0); fragmentShaderDefines_.append("#define RAW12P"); - fragmentShaderFile_ = ":bayer_1x_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_1x_packed.frag"; textureMinMagFilters_ = GL_NEAREST; break; case libcamera::formats::SGRBG12_CSI2P: firstRed_.setX(1.0); firstRed_.setY(0.0); fragmentShaderDefines_.append("#define RAW12P"); - fragmentShaderFile_ = ":bayer_1x_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_1x_packed.frag"; textureMinMagFilters_ = GL_NEAREST; break; case libcamera::formats::SRGGB12_CSI2P: firstRed_.setX(0.0); firstRed_.setY(0.0); fragmentShaderDefines_.append("#define RAW12P"); - fragmentShaderFile_ = ":bayer_1x_packed.frag"; + fragmentShaderFile_ = ":include/libcamera/internal/shaders/bayer_1x_packed.frag"; textureMinMagFilters_ = GL_NEAREST; break; default: From patchwork Tue Apr 22 21:59:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23238 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 C9889C3321 for ; Tue, 22 Apr 2025 22:00:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E17D568B41; Wed, 23 Apr 2025 00:00:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Tpff/V3U"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A5DA868B30 for ; Tue, 22 Apr 2025 23:59:47 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-43cec5cd73bso36790035e9.3 for ; Tue, 22 Apr 2025 14:59:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359187; x=1745963987; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xohWrDtN8ZGpfN7nKguwckSAOm+5HFgcjnATjqv8kuU=; b=Tpff/V3UKw4BExfD7xa10OwP4ONXV9kFloFRHfgtJR88KUEk2T3/zWxHa5cOaeBfU8 dKrbztoEd0bB8vZ6z3Q78eoSsXUotXROgP5jeTXAmKSISu63SPLMIDUUHLHuDTBWHci7 tu3q7iE1y3dUCsGQJOuwNlICqdT3OeFkeMCuG7OFs5k/GqfFmK5mC28eyeHw50XuZhBn BysjRRCDK7mKvF0tsxYjjftKr9lbhSn1noeBD1ixxmpRHefi91pchT0inETGjrDp4AVf OCx34YsLEOQF9/wcSQAEY2JKLd87D5DWju50wi3ktIIxdus7vh1QPmDJ0YnXipDnBvtW xtsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359187; x=1745963987; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xohWrDtN8ZGpfN7nKguwckSAOm+5HFgcjnATjqv8kuU=; b=odpEfnONzWVPZ7/7GZvNN+WS6dhkmCBsN1POvbk7wdyOUOhfSJevSJpmyQSvYe2ySW FCmLZx2+OOpjMp912yRDoNSM6PX/B0LazgCS0DFMn0ozLgZ91ENlKiWt9jMfaNCcSQ2k rxu+pABYefaBEBzB9etXaHQHCk1eO7WWbcqLFCoR8xq5Rqdv2NCVmqXYVvC9eoBKloVX VJyr1t/w1/xoFlNN+qDycQsCORDT+Np+gWCP2f1btX/SDzTkTM3VJmuk+nEu0mwDCTf7 wOSnp6tFQY8obRFc0lEOOS9zsyUWFaFiQ+fOUgZpIEKhrwRqUvZFh1UjNi5BlNHffB5q IJKg== X-Gm-Message-State: AOJu0Yy9yPg7NKIKPeNVK+B9dc8umSXcem+15eB0XMa7pX6epUUJgkXX DP5Vf8Poe03x5A1ZX0zMRnAaCQh5WZzAKLP+c1v7dXO+Rsoyk0m5i3Bb2LVihsvh5l6yXkovdmo kii4= X-Gm-Gg: ASbGnctwezywMt+MZYXXofaUwxP/SuSsfpKSOSor8kbzak+tGRkQxLzUJua7p1WEO/Y DEaefz1Lq9ZQ8zrbVWSUEVVJNsCO6vKJrv/17jIR2kh5knGb1iV84qc2BRbKXzBvzEANa8lYXaa vXp0QOgsGdScCEbs3mWJRW4TXxhCYNMd6Hrw0x1deMKTmegPqh+zv0idNvhD8gqnL2rO4uWtf+u Aak1+I4TYwpBB5bOEiPj6CogRMx2F0AS/DaLpN9uD9BoF9TiWcUuYYWHcjXjckmzD4Sn5xNQaFS ZMn9snD97YFrXPMXdVjioNyAH8r1FVxD89faxISe9i0Ir0yK1AwKVklm7twa1WqM1rrRzBgSDWI XHswJdcwaEgpHnTVAu6ct X-Google-Smtp-Source: AGHT+IFlT4G5zPKTzkfL0Ioy9cR32CVNcbrFIN7N6EBLTntYJRVwf0/gzBanfNJ94RWsERooQOVNwQ== X-Received: by 2002:a05:600c:1554:b0:43c:ee62:33f5 with SMTP id 5b1f17b1804b1-4406ac1fd90mr143471365e9.27.1745359186984; Tue, 22 Apr 2025 14:59:46 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:46 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 25/27] utils: gen-shader-headers: Add a utility to generate headers from shaders Date: Tue, 22 Apr 2025 22:59:18 +0100 Message-ID: <20250422215920.4297-26-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Two simple script to generate a header that contains GLSL shaders translated to C arrays. Signed-off-by: Bryan O'Donoghue --- utils/gen-shader-header.py | 38 ++++++++++++++++++++++++++++++++++ utils/gen-shader-headers.sh | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 utils/gen-shader-header.py create mode 100755 utils/gen-shader-headers.sh diff --git a/utils/gen-shader-header.py b/utils/gen-shader-header.py new file mode 100755 index 00000000..a6799857 --- /dev/null +++ b/utils/gen-shader-header.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2025, Bryan O'Donoghue. +# +# Author: Bryan O'Donoghue +# +# A python script which takes a list of shader files and converts into a C +# header. +# +import sys + +try: + with open(sys.argv[2]) as file: + data = file.read() + data_len = len(data) + + name = sys.argv[1].replace(".", "_") + name_len = name + "_len" + + j = 0 + print ("unsigned char", name, "[] = {") + for ch in data: + print(f"0x{ord(ch):02x}, ", end="") + j = j + 1 + if j == 16: + print() + j = 0 + if j != 0: + print() + print ("};") + + print() + print(f"const unsigned int {name_len}={data_len};") + +except FileNotFoundError: + print(f"File {sys.argv[2]} not found", file=sys.stderr) +except IOError: + print(f"Unable to read {sys.argv[2]}", file=sys.stderr) diff --git a/utils/gen-shader-headers.sh b/utils/gen-shader-headers.sh new file mode 100755 index 00000000..e1742165 --- /dev/null +++ b/utils/gen-shader-headers.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +if [ $# -lt 4 ]; then + echo "Invalid arg count must be >= 5" + exit 1 +fi +src_dir="$1"; shift +dst_dir="$1"; shift +dst_path=$dst_dir/"$1"; shift + +cat < "$dst_path" +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* This file is auto-generated, do not edit! */ +/* + * Copyright (C) 2024, Linaro Ltd. + * + */ + +#pragma once + +EOF + +cat <> "$dst_path" +/* + * List the names of the shaders at the top of + * header for readability's sake + * +EOF +for file in $@; do + name=`basename $src_dir/src/$file | tr '.' '_'` + echo " * unsigned char $name;" >> $dst_path +done + +echo "*/" >> $dst_path + +echo "/* Hex encoded shader data */" >> $dst_path +for file in $@; do + name=`basename $src_dir/src/$file` + $src_dir/utils/gen-shader-header.py $name $src_dir/src/$file >> $dst_path + echo >> $dst_path +done From patchwork Tue Apr 22 21:59:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23239 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 08ED8C327D for ; Tue, 22 Apr 2025 22:00:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7AC7468B3A; Wed, 23 Apr 2025 00:00:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="TlpT8OvI"; dkim-atps=neutral Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8EE4A68B41 for ; Tue, 22 Apr 2025 23:59:48 +0200 (CEST) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-391342fc0b5so4703318f8f.3 for ; Tue, 22 Apr 2025 14:59:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359188; x=1745963988; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fTSmECeJyXTca49Z/7YULmR0N2gCFQELi3K5iShO2Yo=; b=TlpT8OvIpS1p85iosstRq1FXW0cCTTe0EyfEGrYygC7HrFq4iSVPqavMIT3KAZsquh jESaex90DIzw9ZoHvpZ+0K05ED1buX6f9f6Kut6vwFT9UA9MvYvlo4qZEtb69csaM+04 UCEckb8oEAqrcu0QtozJAgPLSgTtpeqlh80MsGacylhRe3tmbD2BqgqenWFz11Gx7YEs Bw+EMjZ7qq2bxgVfbed9kgcvuOk4sRifc/VT2mf0kEyM+M5q0CZXhkXTb3b7Tcj3KxB9 h+AEu+xurP5yNUfCjQXrFTjfHq/D2BAqtmr49gKVse8ufE/kwtGaMCx8zy+20opYCUs3 +ahA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359188; x=1745963988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fTSmECeJyXTca49Z/7YULmR0N2gCFQELi3K5iShO2Yo=; b=ElFcwzPVmIjZ4+O1zLIiiJOckDOPCjDse2qvxwXl3HIzX8O3NMAnstmdMZT5FrkcVr 5fAj8nhSzmaw+Vye2ApQO4d+IHtB3iFVc7J94NmhFEBdmF01QQDDJKww9fibBVPJk9dq CBVxONZ0hDQcdIfU05EdC9QNmGbSU/p4JN2+E4eJ/K137+g6lvFGINbSDPcTnxFLaLn0 ZUxV75k8LEklRqHecFokHWbb7BzKy8hyZN3UkmYsm+fR2jLheqGc0CHaS34Zce7NGO6h SJCjFrRl8VkiAt8+ogA0f+lLohgzRJOVcLrZW+ENxC3Uy8MGu7tVERm5wXk8rOp50BVJ rLDg== X-Gm-Message-State: AOJu0YynMk620/lDZzFOnKBCwVAshtjeNY1e3byv1iqmsX+TSquoUllZ vzMmuhp7CYra5e2qi5GSpzidQlIc6ANi2d20fgQFnEB89QSorYR9x0edw1jxE8zwAn0KhMhaIdg 6E7Q= X-Gm-Gg: ASbGnctu5gYbaGm+zS4+BBBM3QMa+lxmSq71vMBoSd28VI9Jsx1egIYcQKLJteMtRGf 103DftfoO7bNrji/iWthGn/4bHMobIO5u3eIs57d0BCQXjKeva8eZsIgC79U+D9Nxgh2RvTVYmD YebSy4Lc7S6vkebEbSNBSJ3hhiE5dRu5C1cd8nHNh3p7qTFhqRpEqMGaxIthiMd/qb99FuDwGH1 pdci8Ksp3jSu7lypW8ArKrsBuEVsYUWrk2JAShfdvHQRgx/9EMi/JsfPHf6ZeSuxoUiNA4TPdcu Q8Ptk+GyqNELWeBlCVY7DbjeadEpTXWwEPmj0/xThXluepe1tsAbqKVfEmxJ+CXaXECwWuP0XWF 5GXMN+ZOK4FyhTtVnffko X-Google-Smtp-Source: AGHT+IElAOSpZGrmqvFgKwbc4mb+TviYAr/wclm4q+D+YVXyf2yM7qm2W2esvxyYkGFrZ1prh0PvNw== X-Received: by 2002:a5d:64ae:0:b0:390:e7c1:59c4 with SMTP id ffacd0b85a97d-39efba50a80mr14943572f8f.13.1745359187945; Tue, 22 Apr 2025 14:59:47 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:47 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 26/27] meson: Automatically generate glsl_shaders.h from specified shader programs Date: Tue, 22 Apr 2025 22:59:19 +0100 Message-ID: <20250422215920.4297-27-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Encode the bayer shader files into a header as part of the build process. Qcam already compiles the shader files down into a QT resource file which it references internally. In order to share the debayering shader programs outside of qcam create a generic header which both qcam and libcamera can operate from. Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/meson.build | 10 ++++++++++ include/libcamera/internal/shaders/meson.build | 10 ++++++++++ utils/meson.build | 2 ++ 3 files changed, 22 insertions(+) create mode 100644 include/libcamera/internal/shaders/meson.build diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 45408b31..10cd4930 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 subdir('tracepoints') +subdir('shaders') libcamera_internal_headers = files([ 'bayer_format.h', @@ -56,5 +57,14 @@ tracepoints_h = custom_target( libcamera_internal_headers += tracepoints_h +libcamera_shader_headers = custom_target( + 'gen-shader-headers', + input : [shader_files], + output : 'glsl_shaders.h', + command : [gen_shader_headers, meson.project_source_root(), meson.project_build_root(), '@OUTPUT@', '@INPUT@'], +) + +libcamera_internal_headers += libcamera_shader_headers + subdir('converter') subdir('software_isp') diff --git a/include/libcamera/internal/shaders/meson.build b/include/libcamera/internal/shaders/meson.build new file mode 100644 index 00000000..386b342d --- /dev/null +++ b/include/libcamera/internal/shaders/meson.build @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: CC0-1.0 + +# List of shader files to convert to header hex +# for the purposes of inclusion in OpenGL debayering +shader_files = files([ + 'bayer_1x_packed.frag', + 'bayer_8.frag', + 'bayer_8.vert', + 'identity.vert', +]) diff --git a/utils/meson.build b/utils/meson.build index 95d657ac..3deed8ad 100644 --- a/utils/meson.build +++ b/utils/meson.build @@ -3,5 +3,7 @@ subdir('codegen') subdir('ipu3') +gen_shader_headers = files('gen-shader-headers.sh') + ## Module signing gen_ipa_priv_key = files('gen-ipa-priv-key.sh') From patchwork Tue Apr 22 21:59:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 23240 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 820BDC331E for ; Tue, 22 Apr 2025 22:00:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 09F0568B54; Wed, 23 Apr 2025 00:00:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Q4238P8T"; dkim-atps=neutral Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 644F668B49 for ; Tue, 22 Apr 2025 23:59:49 +0200 (CEST) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-39c14016868so5711679f8f.1 for ; Tue, 22 Apr 2025 14:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359189; x=1745963989; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wmRwDLedsnMO6yr9mFqNtiEcjM/t9yyved9O22mAiPA=; b=Q4238P8TMxnfadUIOweUFGr14ijCjBr6yXWfZyi9ZhJ4RfQpnT+Ke745Lv344PkoS8 Iqn6O/xxUDiO8WLwhU6ntiBL3UsEUQpPLuus/+uodURchTCZBKC2wcERu+DQ9AL9qxW3 89jNS5ssuYE09ANzHxhzO2UpjksJqMzEW+VW5b5F8MlVqrwc8zIXUmkbKd0NKr9MSeKh XFzenQIpZMUk/FvQKiaaNKa7NpW4b2mn1z5s/I8ryc7JFGw05jdt0zyV9dAprV6oFvTu 2pvRwwJHaAlJxO2kecCTin3X6a2A7dl0tWRPvO5ObgEzIEGmGWDdspeIeCMYrLylJA9r eyhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359189; x=1745963989; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wmRwDLedsnMO6yr9mFqNtiEcjM/t9yyved9O22mAiPA=; b=osINqGDxUx2UHP+QkpWoBcV+ehN6VL0mT708dlaLCyMVXfT8IklfOe0aeUWgCsh2cU xRexF16rrapIqi6H3fn/QcWVbwYdOW8Q8HlgImG75ExLqaqhSMg2julJSqVVqoHMnIKt 8afWq3tfOM53DPVGRlGEBXq6+88YE7MZKnw5CFpDQpZ4oQRqQghjsNK7iOVHnvvg2PgS oXh6+v04R4c7UJBnwC/oxYgNt0riL34k+JMVv26YwExVNjUqlyLtySWR00NGrM7VgPVi +vcXY/lmSS+Jx0bbjmsSsq9e2SOgTNR7iiQMIVnIcNr3uFZDCojM8x+mNi4m0jlz+ypV G+3g== X-Gm-Message-State: AOJu0Yw+dxw+NCoj5pvChqVxKZWNsP/c4XNBcnar5bZM4CqJC9ASqrcV f8lo1KIb8+OhZK6lFEsgcxeotltnnGA8A72bHsn/wZB7p0VMYOGJV2tbYAZhSyaUfYavp+9K/su 935Q= X-Gm-Gg: ASbGncsVOjCO9v3/EaKsZ1o6vCIhvQi7DwyRqDbNf4sLeRAYbBBfcMhTUzunsfigRXb LwFu6MN+tGWsTbgeOdQDDLlJQjexxcjG98X81IW/stBSwBcdOEG/xbnc+ZN9T9lHmtpQ4Z2iRvf A/0pVf7G/pZNesL8oW0C3VykU7Oy9pWzEpV6YxnS9gM2lXFXFTMnX+o/iZXC1k0XbijEWMnA+BG Jnu8zqKpeGQIgZ2t+GGdyvC2dtDPAjy7YvYS7DC2lAAjdFTi6/+BSJ0bKB1Yh3A1rVAq7mvDUEw zD1WUbJGiZxmgPG62seWGR4FAUna80lD+2NXdb9Qa6T0WzF0i1BoYLbNIBPkBoWS81pO8M0blwM cyQTjD86qXGUQtS95FBNdMH0/YvLU7n0= X-Google-Smtp-Source: AGHT+IErHHN8UwkVL/aHJiMvcryGHUWcDvKLh32XQZ2hNYUDCi6fuRiBZZxDJ9pu6EIeo3+hjc4BhA== X-Received: by 2002:a05:6000:40cf:b0:39c:12f2:2f86 with SMTP id ffacd0b85a97d-39efba2ab5amr13237543f8f.8.1745359188758; Tue, 22 Apr 2025 14:59:48 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:48 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH 27/27] shaders: Extend debayer shaders to apply RGB gain values on output Date: Tue, 22 Apr 2025 22:59:20 +0100 Message-ID: <20250422215920.4297-28-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-1-bryan.odonoghue@linaro.org> 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" Signed-off-by: Bryan O'Donoghue --- .../internal/shaders/bayer_1x_packed.frag | 10 ++++++++++ include/libcamera/internal/shaders/bayer_8.frag | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/shaders/bayer_1x_packed.frag b/include/libcamera/internal/shaders/bayer_1x_packed.frag index 19b13ad0..9a2389f7 100644 --- a/include/libcamera/internal/shaders/bayer_1x_packed.frag +++ b/include/libcamera/internal/shaders/bayer_1x_packed.frag @@ -65,6 +65,9 @@ uniform vec2 tex_step; uniform vec2 tex_bayer_first_red; uniform sampler2D tex_y; +uniform sampler2D red_param; +uniform sampler2D green_param; +uniform sampler2D blue_param; void main(void) { @@ -212,5 +215,12 @@ void main(void) vec3(patterns.y, C, patterns.x) : vec3(patterns.wz, C)); +#if defined(APPLY_BAYER_PARAMETERS) + /* Apply bayer params */ + rgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r; + rgb.g = texture2D(red_param, vec2(rgb.g, 0.5)).g; + rgb.b = texture2D(red_param, vec2(rgb.b, 0.5)).b; +#endif + gl_FragColor = vec4(rgb, 1.0); } diff --git a/include/libcamera/internal/shaders/bayer_8.frag b/include/libcamera/internal/shaders/bayer_8.frag index aa7a1b00..a7ed75c8 100644 --- a/include/libcamera/internal/shaders/bayer_8.frag +++ b/include/libcamera/internal/shaders/bayer_8.frag @@ -21,11 +21,16 @@ precision highp float; /** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/ uniform sampler2D tex_y; +uniform sampler2D red_param; +uniform sampler2D green_param; +uniform sampler2D blue_param; varying vec4 center; varying vec4 yCoord; varying vec4 xCoord; void main(void) { + vec3 rgb; + #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r float C = texture2D(tex_y, center.xy).r; // ( 0, 0) @@ -97,11 +102,20 @@ void main(void) { PATTERN.xw += kB.xw * B; PATTERN.xz += kF.xz * F; - gl_FragColor.rgb = (alternate.y == 0.0) ? + rgb = (alternate.y == 0.0) ? ((alternate.x == 0.0) ? vec3(C, PATTERN.xy) : vec3(PATTERN.z, C, PATTERN.w)) : ((alternate.x == 0.0) ? vec3(PATTERN.w, C, PATTERN.z) : vec3(PATTERN.yx, C)); + +#if defined(APPLY_BAYER_PARAMETERS) + /* Apply bayer params */ + rgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r; + rgb.g = texture2D(red_param, vec2(rgb.g, 0.5)).g; + rgb.b = texture2D(red_param, vec2(rgb.b, 0.5)).b; +#endif + + gl_FragColor.rgb = rgb; }