From patchwork Wed Dec 2 15:13:02 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 29138 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 6BC5AC3304 for ; Wed, 2 Dec 2026 15:13:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1152E6AAF8; Wed, 2 Dec 2026 16:13:27 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="BwK5hb8A"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 328BF6AAEE for ; Wed, 2 Dec 2026 16:13:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796224405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q5wWBasm5ZwZvAEIHm8xKi0Nix0Hh1ZLYBh+RAChGGU=; b=BwK5hb8AfHsbtHZ3MLEP/ecUOxjSqIobUAxzjcAGQJBXmYlhZCnBOyw8Cy2zaycLp+SLar 3OkFiwxEWLR8/SH50tR8JrB6/G0SHhIaExbHfVktPNoUEqt5aQpAh4VtoVQv2GlUFVI4N/ HL3p+SxLfUSR0zM1VwxRH1WSfCZkuIk= X-MC-Rep: binary re single Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-LBlDoDKxMfmAyuCOd3wcbA-1; Wed, 2 Dec 2026 15:13:19 +0000 X-MC-Unique: LBlDoDKxMfmAyuCOd3wcbA-1 X-Mimecast-MFC-AGG-ID: LBlDoDKxMfmAyuCOd3wcbA_1796224398 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5C7D01855799; Wed, 2 Dec 2026 15:13:18 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 07CC43000398; Wed, 2 Dec 2026 15:13:16 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Hans de Goede , Robert Mader Subject: [PATCH v4 2/4] libcamera: software_isp: Use specified LSC grid size in debayering Date: Wed, 2 Dec 2026 16:13:02 +0100 Message-ID: <20261202151305.132644-3-mzamazal@redhat.com> In-Reply-To: <20261202151305.132644-1-mzamazal@redhat.com> References: <20261202151305.132644-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: d2Zog8OodPxGqzu4EayUKPhRV-CHaolm8s7wT2F6c9w_1796224398 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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 The lens shading correction texture (grid) has currently the fixed size of 17x17 cells in software ISP. Let's make the size flexible instead, in order to be able to reuse external tuning data, perhaps make GPU happier with sizes of powers of 2, and to provide size flexibility generally. This commit prepares GPU debayering for this change. lscEnabled_ is replaced by lscGridSize_. It is empty in case lens shading correction is disabled and contains the grid size otherwise. Software ISP still passes to GPU debayering either an empty grid size or the grid size of 17x17. Making the grid size flexible is implemented in the followup commits. Signed-off-by: Milan Zamazal --- .../internal/software_isp/software_isp.h | 1 + src/libcamera/software_isp/debayer.cpp | 3 ++- src/libcamera/software_isp/debayer.h | 2 +- src/libcamera/software_isp/debayer_cpu.cpp | 2 +- src/libcamera/software_isp/debayer_cpu.h | 2 +- src/libcamera/software_isp/debayer_egl.cpp | 18 +++++++++--------- src/libcamera/software_isp/debayer_egl.h | 4 ++-- src/libcamera/software_isp/software_isp.cpp | 7 ++++++- 8 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index b64910637..c8ed91949 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -102,6 +102,7 @@ private: DmaBufAllocator dmaHeap_; bool ccmEnabled_; bool lscEnabled_; + std::optional lscGridSize_; std::unique_ptr ipa_; std::deque queuedInputBuffers_; diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp index 4f6659000..65820eabd 100644 --- a/src/libcamera/software_isp/debayer.cpp +++ b/src/libcamera/software_isp/debayer.cpp @@ -112,7 +112,8 @@ Debayer::~Debayer() * \param[in] inputCfg The input configuration * \param[in] outputCfgs The output configurations * \param[in] ccmEnabled Whether a color correction matrix is applied - * \param[in] lscEnabled Whether lens shading correction grid is provided + * \param[in] lscGridSize The size of the lens shading correction grid; + empty if the correction is not enabled * * \return 0 on success, a negative errno on failure */ diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h index e30a05279..246b85b67 100644 --- a/src/libcamera/software_isp/debayer.h +++ b/src/libcamera/software_isp/debayer.h @@ -41,7 +41,7 @@ public: virtual int configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfgs, bool ccmEnabled, - bool lscEnabled) = 0; + const std::optional &lscGridSize) = 0; virtual std::vector formats(PixelFormat inputFormat) = 0; diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index 91867baa6..2ac4f142f 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -625,7 +625,7 @@ int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat, int DebayerCpu::configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfgs, bool ccmEnabled, - [[maybe_unused]] bool lscEnabled) + [[maybe_unused]] const std::optional &lscGridSize) { if (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0) { LOG(Debayer, Error) diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index ae570893b..5759ad08f 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -38,7 +38,7 @@ public: int configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfgs, bool ccmEnabled, - bool lscEnabled) override; + const std::optional &lscGridSize) override; Size patternSize(PixelFormat inputFormat) override; std::vector formats(PixelFormat input) override; std::tuple diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 33933b11d..ce836f088 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -146,7 +146,7 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm /* Specify GL_OES_EGL_image_external */ egl_.pushEnv(shaderEnv, "#extension GL_OES_EGL_image_external: enable"); - if (lscEnabled_) + if (lscGridSize_) egl_.pushEnv(shaderEnv, "#define APPLY_LSC"); /* @@ -280,7 +280,7 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm int DebayerEGL::configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfgs, [[maybe_unused]] bool ccmEnabled, - bool lscEnabled) + const std::optional &lscGridSize) { if (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0) { LOG(Debayer, Error) @@ -300,7 +300,7 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, return -EINVAL; } - lscEnabled_ = lscEnabled; + lscGridSize_ = lscGridSize; inputConfig_.stride = inputCfg.stride; inputPixelFormat_ = inputCfg.pixelFormat; @@ -478,7 +478,7 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm.data().data()); LOG(Debayer, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix; - if (lscEnabled_ && params.lscLutVersion != lscLutVersion_) { + if (lscGridSize_ && params.lscLutVersion != lscLutVersion_) { egl_.updateTexture2D(*eglImageLscLookup_, params.lscLut.data()); lscLutVersion_ = params.lscLutVersion; glUniform1i(textureUniformLsc_, eglImageLscLookup_->texture_unit_uniform_id_); @@ -691,12 +691,12 @@ int DebayerEGL::start() if (initBayerShaders(inputPixelFormat_, outputPixelFormat_)) return -EINVAL; - if (lscEnabled_) { - constexpr unsigned int gridSize = DebayerParams::kLscGridSize; - constexpr unsigned int stride = gridSize * DebayerParams::kLscBytesPerCell; + if (lscGridSize_) { + const Size &gridSize = lscGridSize_.value(); + const unsigned int stride = gridSize.width * DebayerParams::kLscBytesPerCell; eglImageLscLookup_.emplace(GL_RGBA, - gridSize, - gridSize, + gridSize.width, + gridSize.height, stride, GL_TEXTURE2, 2); diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index cbbc6a450..977e1871e 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -46,7 +46,7 @@ public: int configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfgs, bool ccmEnabled, - bool lscEnabled) override; + const std::optional &lscGridSize) override; Size patternSize(PixelFormat inputFormat) override; @@ -84,7 +84,7 @@ private: unsigned int outputBufferCount_; /* LSC lookup table */ - bool lscEnabled_; + std::optional lscGridSize_; std::optional eglImageLscLookup_; std::optional lscLutVersion_; diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 627625b4f..88349598a 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -171,6 +171,11 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, return; } + if (lscEnabled_) + lscGridSize_ = Size(DebayerParams::kLscGridSize, DebayerParams::kLscGridSize); + else + lscGridSize_.reset(); + ipa_->paramsComputed.connect(this, &SoftwareIsp::saveIspParams); ipa_->metadataReady.connect(this, [this](uint32_t frame, const ControlList &metadata) { @@ -294,7 +299,7 @@ int SoftwareIsp::configure(const StreamConfiguration &inputCfg, if (ret < 0) return ret; - ret = debayer_->configure(inputCfg, outputCfgs, ccmEnabled_, lscEnabled_); + ret = debayer_->configure(inputCfg, outputCfgs, ccmEnabled_, lscGridSize_); if (ret < 0) return ret;