{"id":26488,"url":"https://patchwork.libcamera.org/api/patches/26488/?format=json","web_url":"https://patchwork.libcamera.org/patch/26488/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260407-kbingham-awb-split-v1-5-a39af3f4dc20@ideasonboard.com>","date":"2026-04-07T22:01:08","name":"[05/13] shaders: bayer: Use native matrix multiplication","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"7c155b5c94807e8cae68ce4ea335c0773aa55080","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26488/mbox/","series":[{"id":5874,"url":"https://patchwork.libcamera.org/api/series/5874/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5874","date":"2026-04-07T22:01:03","name":"ipa: simple: Convert to libipa AWB implementation","version":1,"mbox":"https://patchwork.libcamera.org/series/5874/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26488/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26488/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 84A40BDCBD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Apr 2026 22:02:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F2A7B62DBE;\n\tWed,  8 Apr 2026 00:02:49 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E1D8C62D9D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Apr 2026 00:02:41 +0200 (CEST)","from [192.168.0.204] (ams.linuxembedded.co.uk [209.38.108.23])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 39CB61C4D;\n\tWed,  8 Apr 2026 00:01:14 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"bCK0dQ7P\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1775599274;\n\tbh=pnU+rcO/VXxf1fNpcS7C00kKk27svJxN5ZJorFc2y74=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=bCK0dQ7P/qqqvn/4jPlBUSjSIEkqS3MhTdurZXEm1K/xhLiAVD8W5UCwGHsSI9QQa\n\tNR7bRhGEITI43UnrJNzRuy8nKO7zXT09KDK9PmrJd5O7Nqrt9AtY2lydaA0acCTdU6\n\txEDWIjnU46d7hqkJxTVuN/bZ+r93I8yaCtsIZTDg=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Date":"Tue, 07 Apr 2026 23:01:08 +0100","Subject":"[PATCH 05/13] shaders: bayer: Use native matrix multiplication","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20260407-kbingham-awb-split-v1-5-a39af3f4dc20@ideasonboard.com>","References":"<20260407-kbingham-awb-split-v1-0-a39af3f4dc20@ideasonboard.com>","In-Reply-To":"<20260407-kbingham-awb-split-v1-0-a39af3f4dc20@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>","X-Mailer":"b4 0.14.2","X-Developer-Signature":"v=1; a=ed25519-sha256; t=1775599359; l=6348;\n\ti=kieran.bingham@ideasonboard.com; s=20260204;\n\th=from:subject:message-id; \n\tbh=pnU+rcO/VXxf1fNpcS7C00kKk27svJxN5ZJorFc2y74=;\n\tb=VtoBd1eV/n9TUeovxEFRzQU6Tto//wqicGKX2OPhjlwK4N9SRcAOiwPV0X21cVYs18Ialu7E8\n\t8coyDLAwuXcDSV++eMBwPNy1374C2LpIqpT73hi23xGavLJTdWkfJx6","X-Developer-Key":"i=kieran.bingham@ideasonboard.com; a=ed25519;\n\tpk=IOxS2C6nWHNjLfkDR71Iesk904i6wJDfEERqV7hDBdY=","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Remove the open coded matrix multiplication as glsl can perform this\ndirectly. Adapt the uniform ccmUniformDataIn_ to ensure we correctly\nupload the matrix in row major ordering.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/shaders/bayer_1x_packed.frag | 45 ++----------------------------\n src/libcamera/shaders/bayer_unpacked.frag  | 44 ++---------------------------\n src/libcamera/software_isp/debayer_egl.cpp | 12 ++------\n 3 files changed, 7 insertions(+), 94 deletions(-)","diff":"diff --git a/src/libcamera/shaders/bayer_1x_packed.frag b/src/libcamera/shaders/bayer_1x_packed.frag\nindex 9a1992e219dd066945b3f46ec509f47a31590385..57f0be9b264bdbdf523291dc9b35ab5fd6c9ef6a 100644\n--- a/src/libcamera/shaders/bayer_1x_packed.frag\n+++ b/src/libcamera/shaders/bayer_1x_packed.frag\n@@ -231,49 +231,8 @@ void main(void)\n \t/* Apply AWB gains, and saturate each channel at sensor range */\n \trgb = clamp(rgb * awb, vec3(0.0), vec3(1.0) - blacklevel);\n \n-\t/*\n-\t *   CCM is a 3x3 in the format\n-\t *\n-\t *   +--------------+----------------+---------------+\n-\t *   | RedRedGain   | RedGreenGain   | RedBlueGain   |\n-\t *   +--------------+----------------+---------------+\n-\t *   | GreenRedGain | GreenGreenGain | GreenBlueGain |\n-\t *   +--------------+----------------+---------------+\n-\t *   | BlueRedGain  |  BlueGreenGain | BlueBlueGain  |\n-\t *   +--------------+----------------+---------------+\n-\t *\n-\t *   Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin\n-\t *   Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin\n-\t *   Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin\n-\t *\n-\t *   We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm);\n-\t *\n-\t *   CPU\n-\t *   float ccm [] = {\n-\t *             RedRedGain,   RedGreenGain,   RedBlueGain,\n-\t *             GreenRedGain, GreenGreenGain, GreenBlueGain,\n-\t *             BlueRedGain,  BlueGreenGain,  BlueBlueGain,\n-\t *   };\n-\t *\n-\t *   GPU\n-\t *   ccm = {\n-\t *             RedRedGain,   GreenRedGain,   BlueRedGain,\n-\t *             RedGreenGain, GreenGreenGain, BlueGreenGain,\n-\t *             RedBlueGain,  GreenBlueGain,  BlueBlueGain,\n-\t *   }\n-\t *\n-\t *   However the indexing for the mat data-type is column major hence\n-\t *   ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain\n-\t *\n-\t */\n-\tfloat rin, gin, bin;\n-\trin = rgb.r;\n-\tgin = rgb.g;\n-\tbin = rgb.b;\n-\n-\trgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]);\n-\trgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]);\n-\trgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]);\n+\t/* Row major Colour Correction Matrix multiplication */\n+\trgb = ccm * rgb;\n \n \t/*\n \t * Contrast\ndiff --git a/src/libcamera/shaders/bayer_unpacked.frag b/src/libcamera/shaders/bayer_unpacked.frag\nindex 87e4e4915fe19679943fdcc3d213a0224b89065e..52de0a7901cfac33dbc7b306f1840ec0048cd8ea 100644\n--- a/src/libcamera/shaders/bayer_unpacked.frag\n+++ b/src/libcamera/shaders/bayer_unpacked.frag\n@@ -134,49 +134,9 @@ void main(void) {\n \t/* Apply AWB gains, and saturate each channel at sensor range */\n \trgb = clamp(rgb * awb, vec3(0.0), vec3(1.0) - blacklevel);\n \n-\t/*\n-\t *   CCM is a 3x3 in the format\n-\t *\n-\t *   +--------------+----------------+---------------+\n-\t *   | RedRedGain   | RedGreenGain   | RedBlueGain   |\n-\t *   +--------------+----------------+---------------+\n-\t *   | GreenRedGain | GreenGreenGain | GreenBlueGain |\n-\t *   +--------------+----------------+---------------+\n-\t *   | BlueRedGain  |  BlueGreenGain | BlueBlueGain  |\n-\t *   +--------------+----------------+---------------+\n-\t *\n-\t *   Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin\n-\t *   Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin\n-\t *   Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin\n-\t *\n-\t *   We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm);\n-\t *\n-\t *   CPU\n-\t *   float ccm [] = {\n-\t *             RedRedGain,   RedGreenGain,   RedBlueGain,\n-\t *             GreenRedGain, GreenGreenGain, GreenBlueGain,\n-\t *             BlueRedGain,  BlueGreenGain,  BlueBlueGain,\n-\t *   };\n-\t *\n-\t *   GPU\n-\t *   ccm = {\n-\t *             RedRedGain,   GreenRedGain,   BlueRedGain,\n-\t *             RedGreenGain, GreenGreenGain, BlueGreenGain,\n-\t *             RedBlueGain,  GreenBlueGain,  BlueBlueGain,\n-\t *   }\n-\t *\n-\t *   However the indexing for the mat data-type is column major hence\n-\t *   ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain\n-\t *\n-\t */\n-\tfloat rin, gin, bin;\n-\trin = rgb.r;\n-\tgin = rgb.g;\n-\tbin = rgb.b;\n \n-\trgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]);\n-\trgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]);\n-\trgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]);\n+\t/* Row major Colour Correction Matrix multiplication */\n+\trgb = ccm * rgb;\n \n \t/*\n \t * Contrast\ndiff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\nindex 738036e649224f370bdf9a0cc59b399f8b1066de..1022f595cc71751cd0c9133b3e5755f591224dc4 100644\n--- a/src/libcamera/software_isp/debayer_egl.cpp\n+++ b/src/libcamera/software_isp/debayer_egl.cpp\n@@ -464,15 +464,9 @@ void DebayerEGL::setShaderVariableValues(const DebayerParams &params)\n \t\t\t    << \" textureUniformProjMatrix_ \" << textureUniformProjMatrix_;\n \n \tGLfloat ccm[9] = {\n-\t\tparams.combinedMatrix[0][0],\n-\t\tparams.combinedMatrix[0][1],\n-\t\tparams.combinedMatrix[0][2],\n-\t\tparams.combinedMatrix[1][0],\n-\t\tparams.combinedMatrix[1][1],\n-\t\tparams.combinedMatrix[1][2],\n-\t\tparams.combinedMatrix[2][0],\n-\t\tparams.combinedMatrix[2][1],\n-\t\tparams.combinedMatrix[2][2],\n+\t\tparams.combinedMatrix[0][0], params.combinedMatrix[1][0], params.combinedMatrix[2][0],\n+\t\tparams.combinedMatrix[0][1], params.combinedMatrix[1][1], params.combinedMatrix[2][1],\n+\t\tparams.combinedMatrix[0][2], params.combinedMatrix[1][2], params.combinedMatrix[2][2],\n \t};\n \tglUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm);\n \tLOG(Debayer, Debug) << \" ccmUniformDataIn_ \" << ccmUniformDataIn_ << \" data \" << params.combinedMatrix;\n","prefixes":["05/13"]}