From patchwork Sat Jun 20 23:00:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 27003 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 20281C3303 for ; Sat, 20 Jun 2026 23:00:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D0109656F1; Sun, 21 Jun 2026 01:00:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hNOYGvmn"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 08420656E3 for ; Sun, 21 Jun 2026 01:00:37 +0200 (CEST) Received: from [192.168.0.240] (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5331618E5; Sun, 21 Jun 2026 01:00:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1781996400; bh=/no/cZODy8Va4tcU7NE+8kpiju3sSy4KKajESvyHYLA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hNOYGvmnk1K/wTNRY6yLDmOzQx7LkmheoPQMsvHeis4VWordHR8Y3W3wsEF42Sti5 Xza2vUjkwLeMLgjy3K9fYDapThI9u9XAtRW3tcVsUQD8+D9uAq1jfGos+ZA9asceNh QpABLyOG3MEigCpSZu77Z7Eff/O4vkDtGTGUv4zM= From: Kieran Bingham Date: Sun, 21 Jun 2026 00:00:34 +0100 Subject: [PATCH 7/7] shaders: bayer: Use native matrix multiplication MIME-Version: 1.0 Message-Id: <20260621-kbingham-awb-saturation-v1-7-b91ea59c6cfb@ideasonboard.com> References: <20260621-kbingham-awb-saturation-v1-0-b91ea59c6cfb@ideasonboard.com> In-Reply-To: <20260621-kbingham-awb-saturation-v1-0-b91ea59c6cfb@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1781996434; l=6299; i=kieran.bingham@ideasonboard.com; s=20260204; h=from:subject:message-id; bh=/no/cZODy8Va4tcU7NE+8kpiju3sSy4KKajESvyHYLA=; b=TQyiWYqBzG73gnXB6atj42B8Z78pCJk6BbEPzk3k+IDoJAUDIsS4H9/QtSf8xth6u/Z3aODG3 07D7nfZx3BKAucGMglLJDHga3TF247rWNXbBgoS2BTVx2cdJwjILBH1 X-Developer-Key: i=kieran.bingham@ideasonboard.com; a=ed25519; pk=IOxS2C6nWHNjLfkDR71Iesk904i6wJDfEERqV7hDBdY= 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" Remove the open coded matrix multiplication as glsl can perform this directly. Adapt the uniform ccmUniformDataIn_ to ensure we correctly upload the matrix in row major ordering. Signed-off-by: Kieran Bingham --- src/libcamera/shaders/bayer_1x_packed.frag | 45 ++---------------------------- src/libcamera/shaders/bayer_unpacked.frag | 45 ++---------------------------- src/libcamera/software_isp/debayer_egl.cpp | 13 +-------- 3 files changed, 5 insertions(+), 98 deletions(-) diff --git a/src/libcamera/shaders/bayer_1x_packed.frag b/src/libcamera/shaders/bayer_1x_packed.frag index 6b3f7532c177f277e43c27e498dfadcb9cd4e26c..0b641a5f35c53a20811315c4e5def18f301cae69 100644 --- a/src/libcamera/shaders/bayer_1x_packed.frag +++ b/src/libcamera/shaders/bayer_1x_packed.frag @@ -235,49 +235,8 @@ void main(void) /* Apply AWB gains, and saturate each channel at sensor range */ rgb = clamp(rgb * awb, vec3(0.0), vec3(1.0)); - /* - * CCM is a 3x3 in the format - * - * +--------------+----------------+---------------+ - * | RedRedGain | RedGreenGain | RedBlueGain | - * +--------------+----------------+---------------+ - * | GreenRedGain | GreenGreenGain | GreenBlueGain | - * +--------------+----------------+---------------+ - * | BlueRedGain | BlueGreenGain | BlueBlueGain | - * +--------------+----------------+---------------+ - * - * Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin - * Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin - * Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin - * - * We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm); - * - * CPU - * float ccm [] = { - * RedRedGain, RedGreenGain, RedBlueGain, - * GreenRedGain, GreenGreenGain, GreenBlueGain, - * BlueRedGain, BlueGreenGain, BlueBlueGain, - * }; - * - * GPU - * ccm = { - * RedRedGain, GreenRedGain, BlueRedGain, - * RedGreenGain, GreenGreenGain, BlueGreenGain, - * RedBlueGain, GreenBlueGain, BlueBlueGain, - * } - * - * However the indexing for the mat data-type is column major hence - * ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain - * - */ - float rin, gin, bin; - rin = rgb.r; - gin = rgb.g; - bin = rgb.b; - - rgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]); - rgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]); - rgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]); + /* Colour Correction Matrix */ + rgb = ccm * rgb; /* * Contrast diff --git a/src/libcamera/shaders/bayer_unpacked.frag b/src/libcamera/shaders/bayer_unpacked.frag index 44535312125d0e7e5cca372f4e8e0f8ad9fce8b3..10c5e941b67c6409312d4091e54d87c1037fae32 100644 --- a/src/libcamera/shaders/bayer_unpacked.frag +++ b/src/libcamera/shaders/bayer_unpacked.frag @@ -138,49 +138,8 @@ void main(void) { /* Apply AWB gains, and saturate each channel at sensor range */ rgb = clamp(rgb * awb, vec3(0.0), vec3(1.0)); - /* - * CCM is a 3x3 in the format - * - * +--------------+----------------+---------------+ - * | RedRedGain | RedGreenGain | RedBlueGain | - * +--------------+----------------+---------------+ - * | GreenRedGain | GreenGreenGain | GreenBlueGain | - * +--------------+----------------+---------------+ - * | BlueRedGain | BlueGreenGain | BlueBlueGain | - * +--------------+----------------+---------------+ - * - * Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin - * Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin - * Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin - * - * We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm); - * - * CPU - * float ccm [] = { - * RedRedGain, RedGreenGain, RedBlueGain, - * GreenRedGain, GreenGreenGain, GreenBlueGain, - * BlueRedGain, BlueGreenGain, BlueBlueGain, - * }; - * - * GPU - * ccm = { - * RedRedGain, GreenRedGain, BlueRedGain, - * RedGreenGain, GreenGreenGain, BlueGreenGain, - * RedBlueGain, GreenBlueGain, BlueBlueGain, - * } - * - * However the indexing for the mat data-type is column major hence - * ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain - * - */ - float rin, gin, bin; - rin = rgb.r; - gin = rgb.g; - bin = rgb.b; - - rgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]); - rgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]); - rgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]); + /* Colour Correction Matrix */ + rgb = ccm * rgb; /* * Contrast diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 6ba197966d85e1ab3bdc337b9e4ddeb20f1ec2fa..0ec2a98cfafbf87f4de8f160b7b779f61943d287 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -486,18 +486,7 @@ void DebayerEGL::setShaderVariableValues(const DebayerParams ¶ms) << " textureUniformStrideFactor_ " << Stride << " textureUniformProjMatrix_ " << textureUniformProjMatrix_; - GLfloat ccm[9] = { - params.combinedMatrix[0][0], - params.combinedMatrix[0][1], - params.combinedMatrix[0][2], - params.combinedMatrix[1][0], - params.combinedMatrix[1][1], - params.combinedMatrix[1][2], - params.combinedMatrix[2][0], - params.combinedMatrix[2][1], - params.combinedMatrix[2][2], - }; - glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm); + glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_TRUE, params.combinedMatrix.data().data()); LOG(Debayer, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix; /*