From patchwork Wed Nov 18 09:57:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 28973 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 421B3BDE17 for ; Wed, 18 Nov 2026 09:58:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 70FAA6A8E5; Wed, 18 Nov 2026 10:58:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Q/L4lcdu"; 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 6ADFD6A8D2 for ; Wed, 18 Nov 2026 10:58:01 +0100 (CET) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-48e3b22e971so345903f8f.0 for ; Wed, 18 Nov 2026 01:58:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995881; x=1795600681; 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:content-type; bh=nwr7mEv9NFggxR++Fsf8mCEFiwhIADDVs7b6PXYsLCk=; b=Q/L4lcduQE/K+z9TKS724ai3ZF0cnwco0Fxr2jKuyKAKu8Y9vm5b7I0dbGh2vobPWX TxPsGx7PDrFkt25xnvWiKTCLfTavy5HoCeF1LKqodOUQMoVKXA9mpBja10saSQCIdnWE cOV6Tx/QrdH1I/aTKIBcFg9wPzXCQrWPWJkKCUis4lFwE+X+i3O8BIVOnM9uCGYsEjOX mcbgZ4U0gHKSwqP+RrlMFQKhYgBhm3mKU7qvJeABUQ57qPNLBnPVvdMyKvQuYuSsKC3s hXr7i3OIlkPq4FvQfenERHEKcKPPfv5yKR47/FSONfv/8YMZGNLXWEMb5W5Y0Gf6/CYU evuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995881; x=1795600681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=nwr7mEv9NFggxR++Fsf8mCEFiwhIADDVs7b6PXYsLCk=; b=tv6Y0Nx34lgKBOPIHJQ06ZRAT41bs088W10hmzyQUlaXUBIFiTyEeVIRHtVw1HACUY 5Njbt+0e4Ve1FlGfQx3X6Mm5gUQsxpTGY2olciK9QQ3wZJttAJDZt0WzwLoZBCRP3Pty yhyjd4HCIGvRlM++R0+lF5Vfn6Kuozk+AZtz9x4GzexciA3KqgRGTzWc3z96iqbIK2vS 6w88KSovUFJje8h0MbnWelAea7rM2F2ylg+vJGFwY3M98ZmETGMwX4r8nbDHdm1Qfz3M h8JDUpBLNJfv2Fcp4L3hF/KfIVQgAsHMy3f1J5IlEHaVLlPGDeO+8G48cWOOzqfcqPTu NYOw== X-Gm-Message-State: APuU4Z+9QYAUqUnaVU40QzPvQbpcbK7hO5iuDGTT04IrfrlpAcQaP+8s pch3sd4ujVC1ps1p6QtPtCPA9jXa/LJwWy3yaO5ZZ2LMWtHTQ886MDOHJE1Vk+YLMeTf/nKrG9d 8qTP1V60= X-Gm-Gg: AZFdTZcw5atvJY6SW1q1dfxlr+4fCh6P5zoqOd8Qzmp0Q5Di2A+F+UpwdAuOjbCNbrq azXsThXJCYe9EiegJJTgEkNaMLuJxJBAEsHiuHik4owqtopTZElfsqbSo9oGuJxRaUoHHlOVs3t SqKx4IWY54pTcyJLr7sL72saNFCDZr/x43IAW11UF6+++0lQsBv4iZCrsr+tHO3NLorbj3p/C4y CXLKtW4TCO3TJILuywwzxzPUEyyIUMNWjoAvLoYOGf0XkN4SqKNIOTwibwxLVxKMqp5eDsq+In6 xAFUr86kzwxs7wfWZBRFIdssgw4U81FvH+XvY3vi638nfu7o0PlgC7W2fCLY4vZocZYFv+zm+N+ TQ1yi0nYJgS2JLbCF7dRQzDgA8BF8RzTmxQDYicOUZuwzsiHd698/FcrmDDFPgP+8/craIwbU69 SSLHOSMR+LgmFu0IApycOlq2+cL4CM8WWuS8fEAKfIsBEWmu+llsFnGgtiGYAYJO0XjUWlyiUXe +IV52JZczph0HTwtRxjXQe8TmxVRNKaFFlcTm1qBl+7Pn3HvW5Wv2YZlHzESmwE8bLXMYbvslOp Uy2YvIUJ9pj6/ts8CMRn2TnE1Yv+VX4OmeJazyK5pqmMhg== X-Received: by 2002:a05:6000:2798:b0:4a5:1789:90fe with SMTP id ffacd0b85a97d-4a63b0436d0mr2888634f8f.32.1794995880755; Wed, 18 Nov 2026 01:58:00 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:00 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: rstrode@redhat.com, robert.mader@collabora.com, barnabas.pocze@ideasonboard.com, Bryan O'Donoghue Subject: [RFC PATCH v2 12/26] libcamera: software_isp: gpu: Add GpuIspShaderPassBlcNormalise Date: Wed, 18 Nov 2026 10:57:19 +0100 Message-ID: <20261118095735.170587-13-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261118095735.170587-1-bryan.odonoghue@linaro.org> References: <20261118095735.170587-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 GpuIspShaderPassBlcNormalise which takes existing logic to select fragment/vertex shaders based on the incoming CSI2 packign but, select new shaders whose task in life is to apply our blacklevel normalisation step and output a normalised 16 bit float. The unpacked 16f will then be fed into the existing unpacked demosiac shader. This patch compiles but doesn't do anything useful yet. Signed-off-by: Bryan O'Donoghue --- ...gpu_pipeline_shader_pass_blc_normalise.cpp | 210 ++++++++++++++++++ .../gpu_pipeline_shader_pass_blc_normalise.h | 52 +++++ src/libcamera/software_isp/meson.build | 1 + 3 files changed, 263 insertions(+) create mode 100644 src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.cpp create mode 100644 src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.h diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.cpp b/src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.cpp new file mode 100644 index 000000000..86681061a --- /dev/null +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.cpp @@ -0,0 +1,210 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Linaro Ltd + * + * Authors: + * Bryan O'Donoghue + * + * GpuIspShaderPassBlcNormalise base class + */ + +#include + +#include +#include +#include + +#include +#include +#include + +#include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/egl.h" +#include "libcamera/internal/software_isp/debayer_params.h" + +#include "gpu_pipeline_shader_pass_blc_normalise.h" + +/** + * \file software_isp.cpp + * \brief Simple software ISP implementation + */ + +namespace libcamera { + +LOG_DEFINE_CATEGORY(GpuShaderBlc) + + +int GpuIspShaderPassBlcNormalise::selectShaders(struct ShaderConfig &shaderCfg, [[maybe_unused]]PixelFormat &inputFormat, [[maybe_unused]]PixelFormat &outputFormat) +{ + /* Pixel location parameters */ + glFormat_ = GL_LUMINANCE; + bytesPerPixel_ = 1; + shaderStridePixels_ = passInputCfg_.stride; + + /* Shader selection */ + switch (inputFormat) { + case libcamera::formats::SBGGR8: + case libcamera::formats::SGBRG8: + case libcamera::formats::SGRBG8: + case libcamera::formats::SRGGB8: + shaderCfg.fragmentShaderData = bayer_unpacked_to_glr16f_frag; + shaderCfg.vertexShaderData = identity_vert; + break; + case libcamera::formats::SBGGR10_CSI2P: + case libcamera::formats::SGBRG10_CSI2P: + case libcamera::formats::SGRBG10_CSI2P: + case libcamera::formats::SRGGB10_CSI2P: + egl_.pushEnv(shaderCfg.shaderEnv, "#define RAW10P"); + if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { + shaderCfg.fragmentShaderData = bayer_unpacked_to_glr16f_frag; + shaderCfg.vertexShaderData = bayer_unpacked_vert; + glFormat_ = GL_RG; + bytesPerPixel_ = 2; + } else { + shaderCfg.fragmentShaderData = bayer_1x_packed_to_glr16f_frag; + shaderCfg.vertexShaderData = identity_vert; + shaderStridePixels_ = passInputCfg_.size.width; + } + break; + case libcamera::formats::SBGGR12_CSI2P: + case libcamera::formats::SGBRG12_CSI2P: + case libcamera::formats::SGRBG12_CSI2P: + case libcamera::formats::SRGGB12_CSI2P: + egl_.pushEnv(shaderCfg.shaderEnv, "#define RAW12P"); + if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { + shaderCfg.fragmentShaderData = bayer_unpacked_to_glr16f_frag; + shaderCfg.vertexShaderData = bayer_unpacked_vert; + glFormat_ = GL_RG; + bytesPerPixel_ = 2; + } else { + shaderCfg.fragmentShaderData = bayer_1x_packed_to_glr16f_frag; + shaderCfg.vertexShaderData = identity_vert; + shaderStridePixels_ = passInputCfg_.size.width; + } + break; + }; + + return 0; +} + +int GpuIspShaderPassBlcNormalise::getShaderVariableLocations(void) +{ + attributeVertex_ = glGetAttribLocation(programId_, "vertexIn"); + attributeTexture_ = glGetAttribLocation(programId_, "textureIn"); + textureUniformBayerDataIn_ = glGetUniformLocation(programId_, "tex_y"); + 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(GpuShaderBlc, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ + << " tex_y " << textureUniformBayerDataIn_ + << " tex_step " << textureUniformStep_ + << " tex_size " << textureUniformSize_ + << " stride_factor " << textureUniformStrideFactor_ + << " tex_bayer_first_red " << textureUniformBayerFirstRed_ + << " proj_matrix " << textureUniformProjMatrix_; + + /* TODO: trap errors */ + return 0; +} + +void GpuIspShaderPassBlcNormalise::setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) +{ + /* + * 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)passInputCfg_.size.width, + (GLfloat)passInputCfg_.size.height }; + GLfloat Step[] = { static_cast(bytesPerPixel_) / (passInputCfg_.stride - 1), + 1.0f / (passInputCfg_.size.height - 1) }; + GLfloat Stride = (GLfloat)passInputCfg_.size.width / (shaderStridePixels_ / bytesPerPixel_); + /* + * Scale input to output size, keeping the aspect ratio and preferring + * cropping over black bars. + */ + GLfloat scale = std::max((GLfloat)passInputCfg_.window.width / passInputCfg_.size.width, + (GLfloat)passInputCfg_.window.height / passInputCfg_.size.height); + GLfloat trans = -(1.0f - scale); + GLfloat projMatrix[] = { + scale, 0, 0, 0, + 0, scale, 0, 0, + 0, 0, 1, 0, + trans, trans, 0, 1 + }; + /* Static const coordinates */ + static const GLfloat vcoordinates[4][2] = { + { -1.0f, -1.0f }, + { -1.0f, +1.0f }, + { +1.0f, +1.0f }, + { +1.0f, -1.0f }, + }; + static const GLfloat tcoordinates[4][2] = { + { 0.0f, 0.0f }, + { 0.0f, 1.0f }, + { 1.0f, 1.0f }, + { 1.0f, 0.0f }, + }; + + /* 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); + + /* + * 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_, eglImageIn.texture_unit_uniform_id_); + + /* + * These values are: + * firstRed = tex_bayer_first_red - bayer_8.vert + * imgSize = tex_size - bayer_8.vert + * step = tex_step - bayer_8.vert + * Stride = stride_factor identity.vert + * textureUniformProjMatri = No scaling + */ + glUniform2fv(textureUniformBayerFirstRed_, 1, firstRed); + glUniform2fv(textureUniformSize_, 1, imgSize); + glUniform2fv(textureUniformStep_, 1, Step); + glUniform1f(textureUniformStrideFactor_, Stride); + glUniformMatrix4fv(textureUniformProjMatrix_, 1, GL_FALSE, projMatrix); + + LOG(GpuShaderBlc, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ + << " tex_y " << textureUniformBayerDataIn_ + << " tex_step " << textureUniformStep_ + << " tex_size " << textureUniformSize_ + << " stride_factor " << textureUniformStrideFactor_ + << " tex_bayer_first_red " << textureUniformBayerFirstRed_; + + LOG(GpuShaderBlc, 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_; + + /* + * 0 = Red, 1 = Green, 2 = Blue + */ + glUniform3f(blackLevelUniformDataIn_, params.blackLevel[0], params.blackLevel[1], params.blackLevel[2]); + LOG(GpuShaderBlc, Debug) << " blackLevelUniformDataIn_ " << blackLevelUniformDataIn_ << " data " << params.blackLevel; + + return; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.h b/src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.h new file mode 100644 index 000000000..3f3a87434 --- /dev/null +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Linaro Ltd + * + * Authors: + * Bryan O'Donoghue + * + * GpuIspPipelineShaderPass base class + */ + +#pragma once + +#include + +#include +#include +#include + +#include +#include + +#include "libcamera/internal/egl.h" +#include "libcamera/internal/software_isp/debayer_params.h" + +#include "gpu_pipeline_shader_pass.h" + +namespace libcamera { + +class FrameBuffer; + +class GpuIspShaderPassBlcNormalise : public GpuIspShaderPass +{ +public: + GpuIspShaderPassBlcNormalise(eGL& egl) : GpuIspShaderPass(egl) {}; + + /* Things that every ISP pipeline pass will need to do */ + int getShaderVariableLocations(void) override; + void setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) override; + int selectShaders(struct ShaderConfig &shaderCfg, PixelFormat &inputFormat, PixelFormat &outputFormat) override; + const char *name() const override { return "GpuIspShaderPassBlcNormalise"; } + +private: + /* Shader parameters */ + GLint textureUniformStep_; + GLint textureUniformSize_; + + /* Black Level compensation */ + GLint blackLevelUniformDataIn_; + +}; + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index bad821351..ebc3c6952 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -34,6 +34,7 @@ if mesa_works 'software_isp_instance_gpu.cpp', 'gpu_pipeline_shader_pass.cpp', 'gpu_pipeline_shader_pass_demosiac.cpp', + 'gpu_pipeline_shader_pass_blc_normalise.cpp', ]) libcamera_deps += [ libegl,