From patchwork Wed Nov 18 09:57:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 28964 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 0ED77BDE17 for ; Wed, 18 Nov 2026 09:57:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E4E646A8BC; Wed, 18 Nov 2026 10:57:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="wb03uW8y"; 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 D6ADC6A8A9 for ; Wed, 18 Nov 2026 10:57:50 +0100 (CET) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4bb69f5b161so4779205e9.0 for ; Wed, 18 Nov 2026 01:57:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995870; x=1795600670; darn=lists.libcamera.org; h=content-transfer-encoding:content-type: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=N87jJyrGKI7O+C+OiA+G7kS5BY5sQYLkzhBP6ypTR9g=; b=wb03uW8yHcJVwZ6LICZIvqE0NxVxXNADFy73qDnkf/GSmgFL9moRS2TAT58ChN1dpH WYUFmJF1/cwokNLl4j0anTC5lJ1FhqwvIeMmRIUcxnMmHA2Om2zSAMvlbw7GGyeqktKr Rm6bFZodJU1QIzvSHiRCf5dGBjDKSM3PMQzM7Bxy43zHUpD9ba9QgGivKe++jt5aIhYI wHk5NQSAeIyy6wlgNkbbF42QB4cGRgTw5XYrvWhd74TSvyvx9djCE+uvLAiH21tSruH3 D7nb2HYU8uk0QpqRAsUueojnnuuZEUIgRBRmH8m2zSpdGd0l1/FnfdCnr9sZ4/DYrAC3 mciA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995870; x=1795600670; h=content-transfer-encoding:content-type: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=N87jJyrGKI7O+C+OiA+G7kS5BY5sQYLkzhBP6ypTR9g=; b=f2923jUVDo7Fiu0fHIXqwkNl8UVnYQEf2bq3DEdmhHs9QEUgiJrR5+orKAiUsxgC/G rqNkK+aKPCMldbylHEs96HW2koAkH52k/oWCNTOidTcI8xy1zOJ+rVvdM78BiJ/flDRG YHx14X7Dk832oc+K1bWTpetpLabTyk5atEmWWqchUt4B+3Dem82DyBA4rMjLHZqVNZFx O0yocof9tYwJENpW9AGIxDagqQ0r0ffYderb2Z4dwZr8NZoZ13q3RMvQ8PR1X/BeBZPj w+CiDO3dIJfjh8CmnGK+6s1rXVSyv1kEIrJdqP+3VAiuufTV03r4YljXOX3oLNLp3w5v r0jQ== X-Gm-Message-State: APuU4Z9HTVWqDkQW+vZELmoVeQzCuB22t3Zq6bZmEzAj1tVJbWNRmnEg r+vzjSf2MLfyHm5lHnWGs949PNOLFSvUUbB8PE53efOX5UcjYxOrdzH6ajZ8NCcuhN9oxWfjWvh upuAKxXU= X-Gm-Gg: AYBFou2/3qaeJO5ttaCktu0eRIo5kSeK/gniFgiBOQZG1EEwJqBE/cJbjYKQqIiUhk9 WpvVl0a60Td5tncBvfk0hh5CUkWpPZU9PJIxhrJirLW81fkwb4geZwaHCj8LHUkVA4osdvFhEK9 40pUQi8aaof47S1YD5KJhv2qJn5Sbqz8EpVujRPZYNifBakoXpyqDQEi49+LmvPmXDxlM7UOt4W fXC4hOkuwYVCI1TZQE5AvsbWvBSkd323lJWZiI3SQL5AxBVtKRxjB41OyPISPxhA6L7h+C6z+Dz 3rGccohjN8nQ27TtiMVjd7wmFhdFl2Y+LBhdUlx2Z9Fox0/9d9uzfDweSlPbcojrRnPtZ8oCd24 ctwC8Q91gjg5W288a7kPpKLsjl7EncR6PHBQdkTWiLAgyDIPCMDbj2j+edkrkpoc0R9Tm1v70i4 eBpOmEFRLu+GFZXjlggjEkGGVPck7FTxhYWmVqg9PAas2pgAIzQ6ZYdz156SsK8MvJRQw0Vtusc AClES6ujUd7xpFLwVQIBeAp1esG7qCLVwW+jNFU0Ef9GwzyXgPZBkd4I7WLFX6/szVKr0am/r6k WlQ6U9M0j+8gWMWKioFC4nJhW2bs6bxqMIAaR6Td1I4DUw== X-Received: by 2002:a05:600c:1c1f:b0:4bb:6847:7943 with SMTP id 5b1f17b1804b1-4bb7da28927mr42636035e9.26.1794995869039; Wed, 18 Nov 2026 01:57:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:48 -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 01/26] libcamera: software_isp: Rename Bayer classes to SoftwareIspInstance Date: Wed, 18 Nov 2026 10:57:08 +0100 Message-ID: <20261118095735.170587-2-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" The GPUISP multi-pass really wants to run a series of shaders inside of its process() block. Looking at the classes we have now the Debayer class really implements high level logic for the ISP that just so happens to be centered around Bayer operations. We have already done alot of work to make softisp mesa/thread safe so the logical step to take is to start adding in support for more shaders to our existing EGL implementation. It feels lazy sticking to the debayer_-> object and naming convention and moreover it won't be accurate in later patches. Its a little less satisfying for the DebayerCpu to rename it to SoftwareIspInstanceCpu but it also isn't a lie. SoftIsp itself doesn't especially need to know what is happening inside of the invokeMethod(process) signal save that "sutff" happens and data is returned. For obvious reasons we started with a base class of type Debayer but, now that we are expanding the capabilities of SoftIsp to go beyond things that happen in the demosiac phase - we also need to outgrow the constraining name Bayer - no disrespect to Bruce Bayer himself intended. Signed-off-by: Bryan O'Donoghue --- .../internal/software_isp/software_isp.h | 4 +- src/libcamera/software_isp/meson.build | 6 +- src/libcamera/software_isp/software_isp.cpp | 58 ++--- ...{debayer.cpp => software_isp_instance.cpp} | 88 ++++---- .../{debayer.h => software_isp_instance.h} | 8 +- ..._cpu.cpp => software_isp_instance_cpu.cpp} | 200 +++++++++--------- ...ayer_cpu.h => software_isp_instance_cpu.h} | 16 +- ..._egl.cpp => software_isp_instance_gpu.cpp} | 102 ++++----- ...ayer_egl.h => software_isp_instance_gpu.h} | 8 +- 9 files changed, 245 insertions(+), 245 deletions(-) rename src/libcamera/software_isp/{debayer.cpp => software_isp_instance.cpp} (72%) rename src/libcamera/software_isp/{debayer.h => software_isp_instance.h} (93%) rename src/libcamera/software_isp/{debayer_cpu.cpp => software_isp_instance_cpu.cpp} (81%) rename src/libcamera/software_isp/{debayer_cpu.h => software_isp_instance_cpu.h} (93%) rename src/libcamera/software_isp/{debayer_egl.cpp => software_isp_instance_gpu.cpp} (83%) rename src/libcamera/software_isp/{debayer_egl.h => software_isp_instance_gpu.h} (94%) diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index b64910637..3a2bd556e 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -36,7 +36,7 @@ namespace libcamera { -class Debayer; +class SoftwareIspInstance; class FrameBuffer; class PixelFormat; class Stream; @@ -95,7 +95,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 isp_; Thread ispWorkerThread_; SharedMemObject sharedParams_; DebayerParams debayerParams_; diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index 15f9e4032..f241e4489 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -21,8 +21,8 @@ summary({'SoftISP GPU acceleration' : mesa_works}, libcamera_internal_sources += files([ 'benchmark.cpp', - 'debayer.cpp', - 'debayer_cpu.cpp', + 'software_isp_instance.cpp', + 'software_isp_instance_cpu.cpp', 'software_isp.cpp', 'swstats_cpu.cpp', ]) @@ -31,7 +31,7 @@ if mesa_works config_h.set('HAVE_DEBAYER_EGL', 1) libcamera_internal_sources += files([ '../egl.cpp', - 'debayer_egl.cpp', + 'software_isp_instance_gpu.cpp', ]) libcamera_deps += [ libegl, diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 627625b4f..e07f18ff8 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -27,9 +27,9 @@ #include "libcamera/internal/framebuffer.h" #include "libcamera/internal/software_isp/debayer_params.h" -#include "debayer_cpu.h" +#include "software_isp_instance_cpu.h" #if HAVE_DEBAYER_EGL -#include "debayer_egl.h" +#include "software_isp_instance_gpu.h" #endif /** @@ -121,7 +121,7 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, if (!softISPMode || softISPMode == "gpu") { auto display = eGL::probeDisplay(); if (display != EGL_NO_DISPLAY) { - debayer_ = std::make_unique(std::move(stats), cm, display); + isp_ = std::make_unique(std::move(stats), cm, display); } else { LOG(SoftwareIsp, Info) << "EGL not available, falling back to CPU debayer"; @@ -129,17 +129,17 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, } #endif - if (!debayer_) - debayer_ = std::make_unique(std::move(stats), cm); + if (!isp_) + isp_ = std::make_unique(std::move(stats), cm); - debayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady); - debayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady); + isp_->inputBufferReady.connect(this, &SoftwareIsp::inputReady); + isp_->outputBufferReady.connect(this, &SoftwareIsp::outputReady); ipa_ = pipe->createIPA(0, 0); if (!ipa_) { LOG(SoftwareIsp, Error) << "Creating IPA for software ISP failed"; - debayer_.reset(); + isp_.reset(); return; } @@ -158,7 +158,7 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, } ret = ipa_->init(IPASettings{ ipaTuningFile, sensor->model() }, - debayer_->getStatsFD(), + isp_->getStatsFD(), sharedParams_.fd(), sensorInfo, sensor->controls(), @@ -167,7 +167,7 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, &lscEnabled_); if (ret) { LOG(SoftwareIsp, Error) << "IPA init failed"; - debayer_.reset(); + isp_.reset(); return; } @@ -178,13 +178,13 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, }); ipa_->setSensorControls.connect(this, &SoftwareIsp::setSensorCtrls); - debayer_->moveToThread(&ispWorkerThread_); + isp_->moveToThread(&ispWorkerThread_); } SoftwareIsp::~SoftwareIsp() { - /* make sure to destroy the DebayerCpu before the ispWorkerThread_ is gone */ - debayer_.reset(); + /* make sure to destroy the SoftwareIspInstanceCpu before the ispWorkerThread_ is gone */ + isp_.reset(); } /** @@ -219,7 +219,7 @@ void SoftwareIsp::processStats(const uint32_t frame, const uint32_t bufferId, */ bool SoftwareIsp::isValid() const { - return !!debayer_; + return !!isp_; } /** @@ -229,9 +229,9 @@ bool SoftwareIsp::isValid() const */ std::vector SoftwareIsp::formats(PixelFormat inputFormat) { - ASSERT(debayer_); + ASSERT(isp_); - return debayer_->formats(inputFormat); + return isp_->formats(inputFormat); } /** @@ -242,9 +242,9 @@ std::vector SoftwareIsp::formats(PixelFormat inputFormat) */ SizeRange SoftwareIsp::sizes(PixelFormat inputFormat, const Size &inputSize) { - ASSERT(debayer_); + ASSERT(isp_); - return debayer_->sizes(inputFormat, inputSize); + return isp_->sizes(inputFormat, inputSize); } /** @@ -257,9 +257,9 @@ SizeRange SoftwareIsp::sizes(PixelFormat inputFormat, const Size &inputSize) std::tuple SoftwareIsp::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) { - ASSERT(debayer_); + ASSERT(isp_); - return debayer_->strideAndFrameSize(outputFormat, size); + return isp_->strideAndFrameSize(outputFormat, size); } /** @@ -270,9 +270,9 @@ SoftwareIsp::strideAndFrameSize(const PixelFormat &outputFormat, const Size &siz */ uint32_t SoftwareIsp::preferredInputStride(const PixelFormat &inputFormat, const Size &size) { - ASSERT(debayer_); + ASSERT(isp_); - return debayer_->preferredInputStride(inputFormat, size); + return isp_->preferredInputStride(inputFormat, size); } /** @@ -288,13 +288,13 @@ int SoftwareIsp::configure(const StreamConfiguration &inputCfg, const ipa::softisp::IPAConfigInfo &configInfo, ControlInfoMap *ipaControls) { - ASSERT(ipa_ && debayer_); + ASSERT(ipa_ && isp_); int ret = ipa_->configure(configInfo, ipaControls); if (ret < 0) return ret; - ret = debayer_->configure(inputCfg, outputCfgs, ccmEnabled_, lscEnabled_); + ret = isp_->configure(inputCfg, outputCfgs, ccmEnabled_, lscEnabled_); if (ret < 0) return ret; @@ -317,13 +317,13 @@ int SoftwareIsp::configure(const StreamConfiguration &inputCfg, int SoftwareIsp::exportBuffers(const Stream *stream, unsigned int count, std::vector> *buffers) { - ASSERT(debayer_ != nullptr); + ASSERT(isp_ != nullptr); /* single output for now */ if (stream == nullptr) return -EINVAL; - return dmaHeap_.exportBuffers(count, { debayer_->frameSize() }, buffers); + return dmaHeap_.exportBuffers(count, { isp_->frameSize() }, buffers); } /** @@ -385,7 +385,7 @@ int SoftwareIsp::start() ispWorkerThread_.start(); - return debayer_->invokeMethod(&Debayer::start, + return isp_->invokeMethod(&SoftwareIspInstance::start, ConnectionTypeBlocking); } @@ -402,7 +402,7 @@ void SoftwareIsp::stop() if (!ispWorkerThread_.isRunning()) return; - debayer_->invokeMethod(&Debayer::stop, + isp_->invokeMethod(&SoftwareIspInstance::stop, ConnectionTypeBlocking); ispWorkerThread_.exit(); @@ -434,7 +434,7 @@ void SoftwareIsp::stop() void SoftwareIsp::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output) { ipa_->computeParams(frame); - debayer_->invokeMethod(&Debayer::process, + isp_->invokeMethod(&SoftwareIspInstance::process, ConnectionTypeQueued, frame, input, output, debayerParams_); } diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/software_isp_instance.cpp similarity index 72% rename from src/libcamera/software_isp/debayer.cpp rename to src/libcamera/software_isp/software_isp_instance.cpp index 4f6659000..2c4b72d51 100644 --- a/src/libcamera/software_isp/debayer.cpp +++ b/src/libcamera/software_isp/software_isp_instance.cpp @@ -9,7 +9,7 @@ * debayer base class */ -#include "debayer.h" +#include "software_isp_instance.h" namespace libcamera { @@ -85,29 +85,29 @@ namespace libcamera { */ /** - * \class Debayer + * \class SoftwareIspInstance * \brief Base debayering class * * Base class that provides functions for setting up the debayering process. */ -LOG_DEFINE_CATEGORY(Debayer) +LOG_DEFINE_CATEGORY(SoftwareIspInstance) /** - * \brief Construct a Debayer object + * \brief Construct a SoftwareIspInstance object * \param[in] cm The camera manager */ -Debayer::Debayer(const CameraManager &cm) - : bench_(cm, "Debayer") +SoftwareIspInstance::SoftwareIspInstance(const CameraManager &cm) + : bench_(cm, "SoftwareIspInstance") { } -Debayer::~Debayer() +SoftwareIspInstance::~SoftwareIspInstance() { } /** - * \fn int Debayer::configure() + * \fn int SoftwareIspInstance::configure() * \brief Configure the debayer object according to the passed in parameters * \param[in] inputCfg The input configuration * \param[in] outputCfgs The output configurations @@ -118,7 +118,7 @@ Debayer::~Debayer() */ /** - * \fn Size Debayer::patternSize(PixelFormat inputFormat) + * \fn Size SoftwareIspInstance::patternSize(PixelFormat inputFormat) * \brief Get the width and height at which the bayer pattern repeats * \param[in] inputFormat The input format * @@ -128,7 +128,7 @@ Debayer::~Debayer() */ /** - * \fn std::vector Debayer::formats(PixelFormat inputFormat) + * \fn std::vector SoftwareIspInstance::formats(PixelFormat inputFormat) * \brief Get the supported output formats * \param[in] inputFormat The input format * @@ -136,7 +136,7 @@ Debayer::~Debayer() */ /** - * \fn std::tuple Debayer::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) + * \fn std::tuple SoftwareIspInstance::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) * \brief Get the stride and the frame size * \param[in] outputFormat The output format * \param[in] size The output size @@ -146,7 +146,7 @@ Debayer::~Debayer() */ /** - * \fn uint32_t Debayer::preferredInputStride(const PixelFormat &inputFormat, const Size &size) + * \fn uint32_t SoftwareIspInstance::preferredInputStride(const PixelFormat &inputFormat, const Size &size) * Get the preferred input stride in bytes for the given input format and size * \param[in] inputFormat The input format * \param[in] size The input size (width and height in pixels) @@ -154,7 +154,7 @@ Debayer::~Debayer() */ /** - * \fn void Debayer::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params) + * \fn void SoftwareIspInstance::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params) * \brief Process the bayer data into the requested format * \param[in] frame The frame number * \param[in] input The input buffer @@ -166,7 +166,7 @@ Debayer::~Debayer() */ /** - * \fn virtual SizeRange Debayer::sizes(PixelFormat inputFormat, const Size &inputSize) + * \fn virtual SizeRange SoftwareIspInstance::sizes(PixelFormat inputFormat, const Size &inputSize) * \brief Get the supported output sizes for the given input format and size * \param[in] inputFormat The input format * \param[in] inputSize The input size @@ -175,7 +175,7 @@ Debayer::~Debayer() */ /** - * \fn const SharedFD &Debayer::getStatsFD() + * \fn const SharedFD &SoftwareIspInstance::getStatsFD() * \brief Get the file descriptor for the statistics * * This file descriptor provides access to the output statistics buffer @@ -185,7 +185,7 @@ Debayer::~Debayer() */ /** - * \fn unsigned int Debayer::frameSize() + * \fn unsigned int SoftwareIspInstance::frameSize() * \brief Get the output frame size * * \return The total output frame size in bytes as configured for the @@ -193,17 +193,17 @@ Debayer::~Debayer() */ /** - * \var Signal Debayer::inputBufferReady + * \var Signal SoftwareIspInstance::inputBufferReady * \brief Signals when the input buffer is ready */ /** - * \var Signal Debayer::outputBufferReady + * \var Signal SoftwareIspInstance::outputBufferReady * \brief Signals when the output buffer is ready */ /** - * \struct Debayer::DebayerInputConfig + * \struct SoftwareIspInstance::DebayerInputConfig * \brief Structure describing the incoming Bayer parameters * * The DebayerInputConfig structure defines the characteristics of the raw @@ -212,37 +212,37 @@ Debayer::~Debayer() * - Memory layout parameters such as stride and bytes per pixel (\ref bpp) * - A list of supported output pixel formats. * - * \var Debayer::DebayerInputConfig::patternSize + * \var SoftwareIspInstance::DebayerInputConfig::patternSize * Size of the Bayer pattern in pixels. For standard Bayer formats such as * BGGR, GRBG, GBRG, and RGGB, this is typically 2×2 pixels. * - * \var Debayer::DebayerInputConfig::bpp + * \var SoftwareIspInstance::DebayerInputConfig::bpp * Number of bytes used per pixel in memory. This reflects storage size, * not precision. * - * \var Debayer::DebayerInputConfig::stride + * \var SoftwareIspInstance::DebayerInputConfig::stride * Line stride in bytes for the Bayer input frame. * - * \var Debayer::DebayerInputConfig::outputFormats + * \var SoftwareIspInstance::DebayerInputConfig::outputFormats * List of pixel formats supported as output for this input configuration. */ /** - * \struct Debayer::DebayerOutputConfig + * \struct SoftwareIspInstance::DebayerOutputConfig * \brief Structure describing the output frame configuration * * Defines how the output of the debayer process is laid out in memory. * It includes per-pixel size, stride, and total frame size. * - * \var Debayer::DebayerOutputConfig::stride + * \var SoftwareIspInstance::DebayerOutputConfig::stride * Line stride in bytes for the output frame. * - * \var Debayer::DebayerOutputConfig::frameSize + * \var SoftwareIspInstance::DebayerOutputConfig::frameSize * Total frame size in bytes for the output buffer. */ /** - * \var Debayer::inputConfig_ + * \var SoftwareIspInstance::inputConfig_ * \brief Input configuration parameters for the current debayer operation * * Holds metadata describing the incoming Bayer image layout, including @@ -251,7 +251,7 @@ Debayer::~Debayer() */ /** - * \var Debayer::outputConfig_ + * \var SoftwareIspInstance::outputConfig_ * \brief Output configuration data for the debayered frame * * Contains bytes per pixel, stride, and total frame size for the @@ -259,22 +259,22 @@ Debayer::~Debayer() */ /** - * \var Debayer::inputPixelFormat_ + * \var SoftwareIspInstance::inputPixelFormat_ * \brief The incoming pixel format */ /** - * \var Debayer::outputPixelFormat_ + * \var SoftwareIspInstance::outputPixelFormat_ * \brief The output pixel format */ /** - * \var Debayer::outputSize_ + * \var SoftwareIspInstance::outputSize_ * \brief Output size object */ /** - * \var Debayer::swapRedBlueGains_ + * \var SoftwareIspInstance::swapRedBlueGains_ * \brief Flag indicating whether red and blue channel gains should be swapped * * Used when the Bayer pattern order indicates that red/blue color channels are @@ -282,7 +282,7 @@ Debayer::~Debayer() */ /** - * \var Debayer::bench_ + * \var SoftwareIspInstance::bench_ * \brief Benchmarking utility instance for performance measurements * * Used internally to track timing and performance metrics during @@ -290,35 +290,35 @@ Debayer::~Debayer() */ /** - * \fn int Debayer::start() + * \fn int SoftwareIspInstance::start() * \brief Execute a start signal in the debayer object from workerthread context * - * The start() method is invoked so that a Debayer object can initialise + * The start() method is invoked so that a SoftwareIspInstance object can initialise * internal variables or data. It is called from the software_isp::start * method. * - * This method is particularly useful with DebayerEGL as it allows for the + * This method is particularly useful with SoftwareIspInstanceGpu as it allows for the * initialisation of the EGL stack after configure in a thread-safe manner. */ /** - * \fn void Debayer::stop() + * \fn void SoftwareIspInstance::stop() * \brief Stop the debayering process and perform cleanup * * The stop() method is invoked as the logically corollary of start(). - * Debayer::stop() will be called by software_isp::stop() allowing for any + * SoftwareIspInstance::stop() will be called by software_isp::stop() allowing for any * cleanup which should happend with stop(). * - * The stop method similar to start() is useful for DebayerEGL as it allows + * The stop method similar to start() is useful for SoftwareIspInstanceGpu as it allows * for cleanup of EGL context and/or data that happens in - * DebayerEGL::start. + * SoftwareIspInstanceGpu::start. */ /** - * \fn void Debayer::dmaSyncBegin(DebayerParams ¶ms) + * \fn void SoftwareIspInstance::dmaSyncBegin(DebayerParams ¶ms) * \brief Common CPU/GPU Dma Sync Buffer begin */ -void Debayer::dmaSyncBegin(std::vector &dmaSyncers, FrameBuffer *input, FrameBuffer *output) +void SoftwareIspInstance::dmaSyncBegin(std::vector &dmaSyncers, FrameBuffer *input, FrameBuffer *output) { for (const FrameBuffer::Plane &plane : input->planes()) dmaSyncers.emplace_back(plane.fd, DmaSyncer::SyncType::Read); @@ -330,10 +330,10 @@ void Debayer::dmaSyncBegin(std::vector &dmaSyncers, FrameBuffer *inpu } /** - * \fn void Debayer::isStandardBayerOrder(BayerFormat::Order order) + * \fn void SoftwareIspInstance::isStandardBayerOrder(BayerFormat::Order order) * \brief Common method to validate standard 2x2 Bayer pattern of 2 Green, 1 Blue, 1 Red pixels */ -bool Debayer::isStandardBayerOrder(BayerFormat::Order order) +bool SoftwareIspInstance::isStandardBayerOrder(BayerFormat::Order order) { return order == BayerFormat::BGGR || order == BayerFormat::GBRG || order == BayerFormat::GRBG || order == BayerFormat::RGGB; diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/software_isp_instance.h similarity index 93% rename from src/libcamera/software_isp/debayer.h rename to src/libcamera/software_isp/software_isp_instance.h index e30a05279..56728b111 100644 --- a/src/libcamera/software_isp/debayer.h +++ b/src/libcamera/software_isp/software_isp_instance.h @@ -30,13 +30,13 @@ namespace libcamera { class CameraManager; class FrameBuffer; -LOG_DECLARE_CATEGORY(Debayer) +LOG_DECLARE_CATEGORY(SoftwareIspInstance) -class Debayer : public Object +class SoftwareIspInstance : public Object { public: - Debayer(const CameraManager &cm); - virtual ~Debayer() = 0; + SoftwareIspInstance(const CameraManager &cm); + virtual ~SoftwareIspInstance() = 0; virtual int configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfgs, diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/software_isp_instance_cpu.cpp similarity index 81% rename from src/libcamera/software_isp/debayer_cpu.cpp rename to src/libcamera/software_isp/software_isp_instance_cpu.cpp index 91867baa6..2d71d11d4 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/software_isp_instance_cpu.cpp @@ -9,7 +9,7 @@ * CPU based debayering class */ -#include "debayer_cpu.h" +#include "software_isp_instance_cpu.h" #include #include @@ -36,10 +36,10 @@ namespace libcamera { * * Implementation for CPU based debayering threads. */ -class DebayerCpuThread : public Thread, public Object +class SoftwareIspInstanceCpuThread : public Thread, public Object { public: - DebayerCpuThread(DebayerCpu *debayer, unsigned int threadIndex, + SoftwareIspInstanceCpuThread(SoftwareIspInstanceCpu *isp, unsigned int threadIndex, bool enableInputMemcpy); void configure(unsigned int yStart, unsigned int yEnd); @@ -55,7 +55,7 @@ private: /* Max. supported Bayer pattern height is 4, debayering this requires 5 lines */ static constexpr unsigned int kMaxLineBuffers = 5; - DebayerCpu *debayer_; + SoftwareIspInstanceCpu *isp_; unsigned int threadIndex_; unsigned int yStart_; unsigned int yEnd_; @@ -67,34 +67,34 @@ private: }; /** - * \brief Construct a DebayerCpuThread object - * \param[in] debayer pointer back to the DebayerCpuObject this thread belongs to + * \brief Construct a SoftwareIspInstanceCpuThread object + * \param[in] isp pointer back to the DebayerCpuObject this thread belongs to * \param[in] threadIndex 0 .. n thread-index value for the thread * \param[in] enableInputMemcpy when set copy input data to a heap buffer before use */ -DebayerCpuThread::DebayerCpuThread(DebayerCpu *debayer, unsigned int threadIndex, +SoftwareIspInstanceCpuThread::SoftwareIspInstanceCpuThread(SoftwareIspInstanceCpu *isp, unsigned int threadIndex, bool enableInputMemcpy) - : Thread("DebayerCpu:" + std::to_string(threadIndex)), - debayer_(debayer), threadIndex_(threadIndex), + : Thread("SoftwareIspInstanceCpu:" + std::to_string(threadIndex)), + isp_(isp), threadIndex_(threadIndex), enableInputMemcpy_(enableInputMemcpy) { moveToThread(this); } /** - * \class DebayerCpu + * \class SoftwareIspInstanceCpu * \brief Class for debayering on the CPU * * Implementation for CPU based debayering */ /** - * \brief Constructs a DebayerCpu object + * \brief Constructs a SoftwareIspInstanceCpu object * \param[in] stats Pointer to the stats object to use * \param[in] cm The camera manager */ -DebayerCpu::DebayerCpu(std::unique_ptr stats, const CameraManager &cm) - : Debayer(cm), stats_(std::move(stats)) +SoftwareIspInstanceCpu::SoftwareIspInstanceCpu(std::unique_ptr stats, const CameraManager &cm) + : SoftwareIspInstance(cm), stats_(std::move(stats)) { /* * Reading from uncached buffers may be very slow. @@ -117,12 +117,12 @@ DebayerCpu::DebayerCpu(std::unique_ptr stats, const CameraManager &c threads_.resize(threadCount); for (unsigned int i = 0; i < threads_.size(); i++) - threads_[i] = std::make_unique(this, i, enableInputMemcpy); + threads_[i] = std::make_unique(this, i, enableInputMemcpy); - LOG(Debayer, Debug) << "Thread count " << threadCount; + LOG(SoftwareIspInstance, Debug) << "Thread count " << threadCount; } -DebayerCpu::~DebayerCpu() = default; +SoftwareIspInstanceCpu::~SoftwareIspInstanceCpu() = default; #define DECLARE_SRC_POINTERS(pixel_t) \ const pixel_t *prev = (const pixel_t *)src[0] + xShift_; \ @@ -194,7 +194,7 @@ DebayerCpu::~DebayerCpu() = default; curr[x] / (div)) template -void DebayerCpu::debayer8_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer8_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) { DECLARE_SRC_POINTERS(uint8_t) @@ -205,7 +205,7 @@ void DebayerCpu::debayer8_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer8_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer8_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) { DECLARE_SRC_POINTERS(uint8_t) @@ -216,7 +216,7 @@ void DebayerCpu::debayer8_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer10_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer10_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) { DECLARE_SRC_POINTERS(uint16_t) @@ -228,7 +228,7 @@ void DebayerCpu::debayer10_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer10_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer10_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) { DECLARE_SRC_POINTERS(uint16_t) @@ -240,7 +240,7 @@ void DebayerCpu::debayer10_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer12_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer12_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) { DECLARE_SRC_POINTERS(uint16_t) @@ -252,7 +252,7 @@ void DebayerCpu::debayer12_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer12_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer12_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) { DECLARE_SRC_POINTERS(uint16_t) @@ -264,7 +264,7 @@ void DebayerCpu::debayer12_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer10P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer10P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) { const int widthInBytes = window_.width * 5 / 4; const uint8_t *prev = src[0]; @@ -290,7 +290,7 @@ void DebayerCpu::debayer10P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer10P_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer10P_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) { const int widthInBytes = window_.width * 5 / 4; const uint8_t *prev = src[0]; @@ -311,7 +311,7 @@ void DebayerCpu::debayer10P_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer10P_GBGB_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer10P_GBGB_BGR888(uint8_t *dst, const uint8_t *src[]) { const int widthInBytes = window_.width * 5 / 4; const uint8_t *prev = src[0]; @@ -332,7 +332,7 @@ void DebayerCpu::debayer10P_GBGB_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer10P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer10P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]) { const int widthInBytes = window_.width * 5 / 4; const uint8_t *prev = src[0]; @@ -353,7 +353,7 @@ void DebayerCpu::debayer10P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer12P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer12P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) { const int widthInBytes = window_.width * 3 / 2; const uint8_t *prev = src[0]; @@ -371,7 +371,7 @@ void DebayerCpu::debayer12P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer12P_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer12P_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) { const int widthInBytes = window_.width * 3 / 2; const uint8_t *prev = src[0]; @@ -389,7 +389,7 @@ void DebayerCpu::debayer12P_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer12P_GBGB_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer12P_GBGB_BGR888(uint8_t *dst, const uint8_t *src[]) { const int widthInBytes = window_.width * 3 / 2; const uint8_t *prev = src[0]; @@ -407,7 +407,7 @@ void DebayerCpu::debayer12P_GBGB_BGR888(uint8_t *dst, const uint8_t *src[]) } template -void DebayerCpu::debayer12P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]) +void SoftwareIspInstanceCpu::debayer12P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]) { const int widthInBytes = window_.width * 3 / 2; const uint8_t *prev = src[0]; @@ -425,11 +425,11 @@ void DebayerCpu::debayer12P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]) } /* - * Setup the Debayer object according to the passed in parameters. + * Setup the SoftwareIspInstance object according to the passed in parameters. * Return 0 on success, a negative errno value on failure * (unsupported parameters). */ -int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config) +int SoftwareIspInstanceCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config) { BayerFormat bayerFormat = BayerFormat::fromPixelFormat(inputFormat); @@ -470,7 +470,7 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf return 0; } - LOG(Debayer, Debug) + LOG(SoftwareIspInstance, Debug) << "Unsupported input format " << inputFormat; return -EINVAL; } @@ -479,7 +479,7 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf * Check for standard Bayer orders and set xShift_ and swap debayer0/1, so that * a single pair of BGGR debayer functions can be used for all 4 standard orders. */ -int DebayerCpu::setupStandardBayerOrder(BayerFormat::Order order) +int SoftwareIspInstanceCpu::setupStandardBayerOrder(BayerFormat::Order order) { switch (order) { case BayerFormat::BGGR: @@ -503,13 +503,13 @@ int DebayerCpu::setupStandardBayerOrder(BayerFormat::Order order) #define SET_DEBAYER_METHODS(method0, method1) \ debayer0_ = addAlphaByte \ - ? (ccmEnabled ? &DebayerCpu::method0 : &DebayerCpu::method0) \ - : (ccmEnabled ? &DebayerCpu::method0 : &DebayerCpu::method0); \ + ? (ccmEnabled ? &SoftwareIspInstanceCpu::method0 : &SoftwareIspInstanceCpu::method0) \ + : (ccmEnabled ? &SoftwareIspInstanceCpu::method0 : &SoftwareIspInstanceCpu::method0); \ debayer1_ = addAlphaByte \ - ? (ccmEnabled ? &DebayerCpu::method1 : &DebayerCpu::method1) \ - : (ccmEnabled ? &DebayerCpu::method1 : &DebayerCpu::method1); + ? (ccmEnabled ? &SoftwareIspInstanceCpu::method1 : &SoftwareIspInstanceCpu::method1) \ + : (ccmEnabled ? &SoftwareIspInstanceCpu::method1 : &SoftwareIspInstanceCpu::method1); -int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat, +int SoftwareIspInstanceCpu::setDebayerFunctions(PixelFormat inputFormat, PixelFormat outputFormat, bool ccmEnabled) { @@ -521,7 +521,7 @@ int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat, swapRedBlueGains_ = false; auto invalidFmt = []() -> int { - LOG(Debayer, Error) << "Unsupported input output format combination"; + LOG(SoftwareIspInstance, Error) << "Unsupported input output format combination"; return -EINVAL; }; @@ -622,13 +622,13 @@ int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat, return invalidFmt(); } -int DebayerCpu::configure(const StreamConfiguration &inputCfg, +int SoftwareIspInstanceCpu::configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfgs, bool ccmEnabled, [[maybe_unused]] bool lscEnabled) { if (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0) { - LOG(Debayer, Error) + LOG(SoftwareIspInstance, Error) << "Unsupported input format " << inputCfg.pixelFormat; return -EINVAL; } @@ -639,7 +639,7 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg, const Size &statsPatternSize = stats_->patternSize(); if (inputConfig_.patternSize.width != statsPatternSize.width || inputConfig_.patternSize.height != statsPatternSize.height) { - LOG(Debayer, Error) + LOG(SoftwareIspInstance, Error) << "mismatching stats and debayer pattern sizes for " << inputCfg.pixelFormat.toString(); return -EINVAL; @@ -648,7 +648,7 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg, inputConfig_.stride = inputCfg.stride; if (outputCfgs.size() != 1) { - LOG(Debayer, Error) + LOG(SoftwareIspInstance, Error) << "Unsupported number of output streams: " << outputCfgs.size(); return -EINVAL; @@ -660,7 +660,7 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg, strideAndFrameSize(outputCfg.pixelFormat, outputCfg.size); if (!outSizeRange.contains(outputCfg.size) || outputConfig_.stride != outputCfg.stride) { - LOG(Debayer, Error) + LOG(SoftwareIspInstance, Error) << "Invalid output size/stride: " << "\n " << outputCfg.size << " (" << outSizeRange << ")" << "\n " << outputCfg.stride << " (" << outputConfig_.stride << ")"; @@ -718,16 +718,16 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg, * * Configure the thread to process lines from yStart to yEnd - 1. */ -void DebayerCpuThread::configure(unsigned int yStart, unsigned int yEnd) +void SoftwareIspInstanceCpuThread::configure(unsigned int yStart, unsigned int yEnd) { - Debayer::DebayerInputConfig &inputConfig = debayer_->inputConfig_; + SoftwareIspInstance::DebayerInputConfig &inputConfig = isp_->inputConfig_; yStart_ = yStart; yEnd_ = yEnd; /* pad with patternSize.Width on both left and right side */ lineBufferPadding_ = inputConfig.patternSize.width * inputConfig.bpp / 8; - lineBufferLength_ = debayer_->window_.width * inputConfig.bpp / 8 + + lineBufferLength_ = isp_->window_.width * inputConfig.bpp / 8 + 2 * lineBufferPadding_; if (enableInputMemcpy_) { @@ -740,9 +740,9 @@ void DebayerCpuThread::configure(unsigned int yStart, unsigned int yEnd) * Get width and height at which the bayer-pattern repeats. * Return pattern-size or an empty Size for an unsupported inputFormat. */ -Size DebayerCpu::patternSize(PixelFormat inputFormat) +Size SoftwareIspInstanceCpu::patternSize(PixelFormat inputFormat) { - DebayerCpu::DebayerInputConfig config; + SoftwareIspInstanceCpu::DebayerInputConfig config; if (getInputConfig(inputFormat, config) != 0) return {}; @@ -750,9 +750,9 @@ Size DebayerCpu::patternSize(PixelFormat inputFormat) return config.patternSize; } -std::vector DebayerCpu::formats(PixelFormat inputFormat) +std::vector SoftwareIspInstanceCpu::formats(PixelFormat inputFormat) { - DebayerCpu::DebayerInputConfig config; + SoftwareIspInstanceCpu::DebayerInputConfig config; if (getInputConfig(inputFormat, config) != 0) return std::vector(); @@ -761,16 +761,16 @@ std::vector DebayerCpu::formats(PixelFormat inputFormat) } std::tuple -DebayerCpu::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) +SoftwareIspInstanceCpu::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) { /* round up to multiple of 8 for 64 bits alignment */ const PixelFormatInfo &info = PixelFormatInfo::info(outputFormat); return std::make_tuple(info.stride(size.width, 0, 8), info.frameSize(size, 8)); } -void DebayerCpuThread::setupInputMemcpy(const uint8_t *linePointers[]) +void SoftwareIspInstanceCpuThread::setupInputMemcpy(const uint8_t *linePointers[]) { - const unsigned int patternHeight = debayer_->inputConfig_.patternSize.height; + const unsigned int patternHeight = isp_->inputConfig_.patternSize.height; if (!enableInputMemcpy_) return; @@ -786,20 +786,20 @@ void DebayerCpuThread::setupInputMemcpy(const uint8_t *linePointers[]) lineBufferIndex_ = patternHeight; } -void DebayerCpuThread::shiftLinePointers(const uint8_t *linePointers[], const uint8_t *src) +void SoftwareIspInstanceCpuThread::shiftLinePointers(const uint8_t *linePointers[], const uint8_t *src) { - const unsigned int patternHeight = debayer_->inputConfig_.patternSize.height; + const unsigned int patternHeight = isp_->inputConfig_.patternSize.height; for (unsigned int i = 0; i < patternHeight; i++) linePointers[i] = linePointers[i + 1]; linePointers[patternHeight] = - src + (patternHeight / 2) * (int)debayer_->inputConfig_.stride; + src + (patternHeight / 2) * (int)isp_->inputConfig_.stride; } -void DebayerCpuThread::memcpyNextLine(const uint8_t *linePointers[]) +void SoftwareIspInstanceCpuThread::memcpyNextLine(const uint8_t *linePointers[]) { - const unsigned int patternHeight = debayer_->inputConfig_.patternSize.height; + const unsigned int patternHeight = isp_->inputConfig_.patternSize.height; if (!enableInputMemcpy_) return; @@ -818,32 +818,32 @@ void DebayerCpuThread::memcpyNextLine(const uint8_t *linePointers[]) * \param[in] src The source buffer * \param[in] dst The destination buffer */ -void DebayerCpuThread::process(uint32_t frame, const uint8_t *src, uint8_t *dst) +void SoftwareIspInstanceCpuThread::process(uint32_t frame, const uint8_t *src, uint8_t *dst) { - Rectangle &window = debayer_->window_; + Rectangle &window = isp_->window_; /* Adjust src to top left corner of the window */ - src += (window.y + yStart_) * debayer_->inputConfig_.stride + - window.x * debayer_->inputConfig_.bpp / 8; + src += (window.y + yStart_) * isp_->inputConfig_.stride + + window.x * isp_->inputConfig_.bpp / 8; /* Adjust dst for yStart_ */ - dst += yStart_ * debayer_->outputConfig_.stride; + dst += yStart_ * isp_->outputConfig_.stride; - if (debayer_->inputConfig_.patternSize.height == 2) + if (isp_->inputConfig_.patternSize.height == 2) process2(frame, src, dst); else process4(frame, src, dst); - debayer_->workPendingMutex_.lock(); - debayer_->workPending_ &= ~(1 << threadIndex_); - debayer_->workPendingMutex_.unlock(); - debayer_->workPendingCv_.notify_one(); + isp_->workPendingMutex_.lock(); + isp_->workPending_ &= ~(1 << threadIndex_); + isp_->workPendingMutex_.unlock(); + isp_->workPendingCv_.notify_one(); } -void DebayerCpuThread::process2(uint32_t frame, const uint8_t *src, uint8_t *dst) +void SoftwareIspInstanceCpuThread::process2(uint32_t frame, const uint8_t *src, uint8_t *dst) { - unsigned int outputStride = debayer_->outputConfig_.stride; - unsigned int inputStride = debayer_->inputConfig_.stride; - Rectangle &window = debayer_->window_; + unsigned int outputStride = isp_->outputConfig_.stride; + unsigned int inputStride = isp_->inputConfig_.stride; + Rectangle &window = isp_->window_; unsigned int yEnd = yEnd_; /* Holds [0] previous- [1] current- [2] next-line */ const uint8_t *linePointers[3]; @@ -876,14 +876,14 @@ void DebayerCpuThread::process2(uint32_t frame, const uint8_t *src, uint8_t *dst for (unsigned int y = yStart_; y < yEnd; y += 2) { shiftLinePointers(linePointers, src); memcpyNextLine(linePointers); - debayer_->stats_->processLine0(frame, y, linePointers, threadIndex_); - debayer_->debayer0(dst, linePointers); + isp_->stats_->processLine0(frame, y, linePointers, threadIndex_); + isp_->debayer0(dst, linePointers); src += inputStride; dst += outputStride; shiftLinePointers(linePointers, src); memcpyNextLine(linePointers); - debayer_->debayer1(dst, linePointers); + isp_->debayer1(dst, linePointers); src += inputStride; dst += outputStride; } @@ -891,24 +891,24 @@ void DebayerCpuThread::process2(uint32_t frame, const uint8_t *src, uint8_t *dst if (window.y == 0 && yEnd_ == window.height) { shiftLinePointers(linePointers, src); memcpyNextLine(linePointers); - debayer_->stats_->processLine0(frame, yEnd, linePointers, threadIndex_); - debayer_->debayer0(dst, linePointers); + isp_->stats_->processLine0(frame, yEnd, linePointers, threadIndex_); + isp_->debayer0(dst, linePointers); src += inputStride; dst += outputStride; shiftLinePointers(linePointers, src); /* next line may point outside of src, use prev. */ linePointers[2] = linePointers[0]; - debayer_->debayer1(dst, linePointers); + isp_->debayer1(dst, linePointers); src += inputStride; dst += outputStride; } } -void DebayerCpuThread::process4(uint32_t frame, const uint8_t *src, uint8_t *dst) +void SoftwareIspInstanceCpuThread::process4(uint32_t frame, const uint8_t *src, uint8_t *dst) { - unsigned int outputStride = debayer_->outputConfig_.stride; - unsigned int inputStride = debayer_->inputConfig_.stride; + unsigned int outputStride = isp_->outputConfig_.stride; + unsigned int inputStride = isp_->inputConfig_.stride; /* * This holds pointers to [0] 2-lines-up [1] 1-line-up [2] current-line @@ -932,33 +932,33 @@ void DebayerCpuThread::process4(uint32_t frame, const uint8_t *src, uint8_t *dst for (unsigned int y = yStart_; y < yEnd_; y += 4) { shiftLinePointers(linePointers, src); memcpyNextLine(linePointers); - debayer_->stats_->processLine0(frame, y, linePointers, threadIndex_); - debayer_->debayer0(dst, linePointers); + isp_->stats_->processLine0(frame, y, linePointers, threadIndex_); + isp_->debayer0(dst, linePointers); src += inputStride; dst += outputStride; shiftLinePointers(linePointers, src); memcpyNextLine(linePointers); - debayer_->debayer1(dst, linePointers); + isp_->debayer1(dst, linePointers); src += inputStride; dst += outputStride; shiftLinePointers(linePointers, src); memcpyNextLine(linePointers); - debayer_->stats_->processLine2(frame, y, linePointers, threadIndex_); - debayer_->debayer2(dst, linePointers); + isp_->stats_->processLine2(frame, y, linePointers, threadIndex_); + isp_->debayer2(dst, linePointers); src += inputStride; dst += outputStride; shiftLinePointers(linePointers, src); memcpyNextLine(linePointers); - debayer_->debayer3(dst, linePointers); + isp_->debayer3(dst, linePointers); src += inputStride; dst += outputStride; } } -void DebayerCpu::updateGammaTable(const DebayerParams ¶ms) +void SoftwareIspInstanceCpu::updateGammaTable(const DebayerParams ¶ms) { const float gamma = params.gamma; const float contrastExp = params.contrastExp; @@ -976,7 +976,7 @@ void DebayerCpu::updateGammaTable(const DebayerParams ¶ms) } } -void DebayerCpu::updateLookupTables(const DebayerParams ¶ms) +void SoftwareIspInstanceCpu::updateLookupTables(const DebayerParams ¶ms) { const bool gammaUpdateNeeded = params.gamma != params_.gamma || @@ -1036,8 +1036,8 @@ void DebayerCpu::updateLookupTables(const DebayerParams ¶ms) } } - LOG(Debayer, Debug) - << "Debayer parameters: blackLevel=" << params.blackLevel + LOG(SoftwareIspInstance, Debug) + << "SoftwareIspInstance parameters: blackLevel=" << params.blackLevel << "; gamma=" << params.gamma << "; contrastExp=" << params.contrastExp << "; gains=" << params.gains @@ -1046,7 +1046,7 @@ void DebayerCpu::updateLookupTables(const DebayerParams ¶ms) params_ = params; } -void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms) +void SoftwareIspInstanceCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms) { bench_.startFrame(); @@ -1065,7 +1065,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output 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"; + LOG(SoftwareIspInstance, Error) << "mmap-ing buffer(s) failed"; metadata.status = FrameMetadata::FrameError; return; } @@ -1077,7 +1077,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output workPendingMutex_.unlock(); for (auto &thread : threads_) - thread->invokeMethod(&DebayerCpuThread::process, + thread->invokeMethod(&SoftwareIspInstanceCpuThread::process, ConnectionTypeQueued, frame, in.planes()[0].data(), out.planes()[0].data()); @@ -1105,7 +1105,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output inputBufferReady.emit(input); } -int DebayerCpu::start() +int SoftwareIspInstanceCpu::start() { for (auto &thread : threads_) thread->start(); @@ -1113,7 +1113,7 @@ int DebayerCpu::start() return 0; } -void DebayerCpu::stop() +void SoftwareIspInstanceCpu::stop() { for (auto &thread : threads_) thread->exit(); @@ -1122,7 +1122,7 @@ void DebayerCpu::stop() thread->wait(); } -SizeRange DebayerCpu::sizes(PixelFormat inputFormat, const Size &inputSize) +SizeRange SoftwareIspInstanceCpu::sizes(PixelFormat inputFormat, const Size &inputSize) { Size patternSize = this->patternSize(inputFormat); unsigned int borderHeight = patternSize.height; @@ -1140,7 +1140,7 @@ SizeRange DebayerCpu::sizes(PixelFormat inputFormat, const Size &inputSize) */ if (inputSize.width < (3 * patternSize.width) || inputSize.height < (2 * borderHeight + patternSize.height)) { - LOG(Debayer, Warning) + LOG(SoftwareIspInstance, Warning) << "Input format size too small: " << inputSize.toString(); return {}; } diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/software_isp_instance_cpu.h similarity index 93% rename from src/libcamera/software_isp/debayer_cpu.h rename to src/libcamera/software_isp/software_isp_instance_cpu.h index ae570893b..01448ab81 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/software_isp_instance_cpu.h @@ -24,16 +24,16 @@ #include "libcamera/internal/software_isp/debayer_params.h" #include "libcamera/internal/software_isp/swstats_cpu.h" -#include "debayer.h" +#include "software_isp_instance.h" namespace libcamera { -class DebayerCpuThread; -class DebayerCpu : public Debayer +class SoftwareIspInstanceCpuThread; +class SoftwareIspInstanceCpu : public SoftwareIspInstance { public: - DebayerCpu(std::unique_ptr stats, const CameraManager &cm); - ~DebayerCpu(); + SoftwareIspInstanceCpu(std::unique_ptr stats, const CameraManager &cm); + ~SoftwareIspInstanceCpu(); int configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfgs, @@ -50,7 +50,7 @@ public: const SharedFD &getStatsFD() override { return stats_->getStatsFD(); } private: - friend class DebayerCpuThread; + friend class SoftwareIspInstanceCpuThread; /** * \brief Called to debayer 1 line of Bayer input data to output format @@ -80,7 +80,7 @@ private: * pointers are passed holding: src[0] = 2-lines-up, src[1] = 1-line-up * src[2] = current-line, src[3] = 1-line-down, src[4] = 2-lines-down. */ - using debayerFn = void (DebayerCpu::*)(uint8_t *dst, const uint8_t *src[]); + using debayerFn = void (SoftwareIspInstanceCpu::*)(uint8_t *dst, const uint8_t *src[]); void debayer0(uint8_t *dst, const uint8_t *src[]) { (this->*debayer0_)(dst, src); } void debayer1(uint8_t *dst, const uint8_t *src[]) { (this->*debayer1_)(dst, src); } @@ -164,7 +164,7 @@ private: unsigned int workPending_ LIBCAMERA_TSA_GUARDED_BY(workPendingMutex_); Mutex workPendingMutex_; ConditionVariable workPendingCv_; - std::vector> threads_; + std::vector> threads_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/software_isp_instance_gpu.cpp similarity index 83% rename from src/libcamera/software_isp/debayer_egl.cpp rename to src/libcamera/software_isp/software_isp_instance_gpu.cpp index 33933b11d..db6b23144 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/software_isp_instance_gpu.cpp @@ -7,7 +7,7 @@ * */ -#include "debayer_egl.h" +#include "software_isp_instance_gpu.h" #include #include @@ -30,28 +30,28 @@ namespace libcamera { /** - * \class DebayerEGL + * \class SoftwareIspInstanceGpu * \brief Class for debayering using an EGL Shader * * Implements an EGL shader based debayering solution. */ /** - * \brief Construct a DebayerEGL object + * \brief Construct a SoftwareIspInstanceGpu object * \param[in] stats Statistics processing object * \param[in] cm The camera manager * \param[in] display The EGL display to use */ -DebayerEGL::DebayerEGL(std::unique_ptr stats, const CameraManager &cm, EGLDisplay display) - : Debayer(cm), stats_(std::move(stats)), egl_(display) +SoftwareIspInstanceGpu::SoftwareIspInstanceGpu(std::unique_ptr stats, const CameraManager &cm, EGLDisplay display) + : SoftwareIspInstance(cm), stats_(std::move(stats)), egl_(display) { } -DebayerEGL::~DebayerEGL() +SoftwareIspInstanceGpu::~SoftwareIspInstanceGpu() { } -int DebayerEGL::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config) +int SoftwareIspInstanceGpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config) { BayerFormat bayerFormat = BayerFormat::fromPixelFormat(inputFormat); @@ -91,13 +91,13 @@ int DebayerEGL::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf return 0; } - LOG(Debayer, Debug) + LOG(SoftwareIspInstance, Debug) << "Unsupported input format " << inputFormat; return -EINVAL; } -int DebayerEGL::getShaderVariableLocations(void) +int SoftwareIspInstanceGpu::getShaderVariableLocations(void) { attributeVertex_ = glGetAttribLocation(programId_, "vertexIn"); attributeTexture_ = glGetAttribLocation(programId_, "textureIn"); @@ -117,7 +117,7 @@ int DebayerEGL::getShaderVariableLocations(void) textureUniformLsc_ = glGetUniformLocation(programId_, "lsc_tex"); - LOG(Debayer, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ + LOG(SoftwareIspInstance, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ << " tex_y " << textureUniformBayerDataIn_ << " awb " << awbUniformDataIn_ << " ccm " << ccmUniformDataIn_ @@ -133,7 +133,7 @@ int DebayerEGL::getShaderVariableLocations(void) return 0; } -int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat) +int SoftwareIspInstanceGpu::initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat) { std::span fragmentShaderData; std::span vertexShaderData; @@ -162,7 +162,7 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm egl_.pushEnv(shaderEnv, "#define SWAP_BLUE"); break; default: - LOG(Debayer, Error) << "Unsupported output format"; + LOG(SoftwareIspInstance, Error) << "Unsupported output format"; return -EINVAL; } @@ -197,7 +197,7 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm firstRed_y_ = 0.0; break; default: - LOG(Debayer, Error) << "Unsupported input format"; + LOG(SoftwareIspInstance, Error) << "Unsupported input format"; return -EINVAL; }; @@ -246,20 +246,20 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, shaderEnv)) { - LOG(Debayer, Error) << "Compile vertex shader fail"; + LOG(SoftwareIspInstance, Error) << "Compile vertex shader fail"; return -ENODEV; } utils::scope_exit vShaderGuard([&] { glDeleteShader(vertexShaderId_); }); if (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData, shaderEnv)) { - LOG(Debayer, Error) << "Compile fragment shader fail"; + LOG(SoftwareIspInstance, Error) << "Compile fragment shader fail"; return -ENODEV; } utils::scope_exit fShaderGuard([&] { glDeleteShader(fragmentShaderId_); }); if (egl_.linkProgram(programId_, vertexShaderId_, fragmentShaderId_)) { - LOG(Debayer, Error) << "Linking program fail"; + LOG(SoftwareIspInstance, Error) << "Linking program fail"; return -ENODEV; } @@ -270,20 +270,20 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm glUseProgram(programId_); err = glGetError(); if (err != GL_NO_ERROR) { - LOG(Debayer, Error) << "Use program error " << err; + LOG(SoftwareIspInstance, Error) << "Use program error " << err; return -ENODEV; } return getShaderVariableLocations(); } -int DebayerEGL::configure(const StreamConfiguration &inputCfg, +int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfgs, [[maybe_unused]] bool ccmEnabled, bool lscEnabled) { if (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0) { - LOG(Debayer, Error) + LOG(SoftwareIspInstance, Error) << "Unsupported input format " << inputCfg.pixelFormat; return -EINVAL; } @@ -294,7 +294,7 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, 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) + LOG(SoftwareIspInstance, Error) << "mismatching stats and debayer pattern sizes for " << inputCfg.pixelFormat; return -EINVAL; @@ -308,7 +308,7 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, height_ = inputCfg.size.height; if (outputCfgs.size() != 1) { - LOG(Debayer, Error) + LOG(SoftwareIspInstance, Error) << "Unsupported number of output streams: " << outputCfgs.size(); return -EINVAL; @@ -320,7 +320,7 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, strideAndFrameSize(outputCfg.pixelFormat, outputCfg.size); if (!outSizeRange.contains(outputCfg.size) || outputConfig_.stride != outputCfg.stride) { - LOG(Debayer, Error) + LOG(SoftwareIspInstance, Error) << "Invalid output size/stride: " << "\n " << outputCfg.size << " (" << outSizeRange << ")" << "\n " << outputCfg.stride << " (" << outputConfig_.stride << ")"; @@ -350,9 +350,9 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, return 0; } -Size DebayerEGL::patternSize(PixelFormat inputFormat) +Size SoftwareIspInstanceGpu::patternSize(PixelFormat inputFormat) { - DebayerEGL::DebayerInputConfig config; + SoftwareIspInstanceGpu::DebayerInputConfig config; if (getInputConfig(inputFormat, config) != 0) return {}; @@ -360,9 +360,9 @@ Size DebayerEGL::patternSize(PixelFormat inputFormat) return config.patternSize; } -std::vector DebayerEGL::formats(PixelFormat inputFormat) +std::vector SoftwareIspInstanceGpu::formats(PixelFormat inputFormat) { - DebayerEGL::DebayerInputConfig config; + SoftwareIspInstanceGpu::DebayerInputConfig config; if (getInputConfig(inputFormat, config) != 0) return std::vector(); @@ -371,20 +371,20 @@ std::vector DebayerEGL::formats(PixelFormat inputFormat) } std::tuple -DebayerEGL::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) +SoftwareIspInstanceGpu::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) { /* Align stride to 256 bytes as a generic GPU memory access alignment */ const PixelFormatInfo &info = PixelFormatInfo::info(outputFormat); return std::make_tuple(info.stride(size.width, 0, 256), info.frameSize(size, 256)); } -uint32_t DebayerEGL::preferredInputStride(const PixelFormat &inputFormat, const Size &size) +uint32_t SoftwareIspInstanceGpu::preferredInputStride(const PixelFormat &inputFormat, const Size &size) { const PixelFormatInfo &info = PixelFormatInfo::info(inputFormat); return info.stride(size.width, 0, 256); } -void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) +void SoftwareIspInstanceGpu::setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) { /* * Raw Bayer 8-bit, and packed raw Bayer 10-bit/12-bit formats @@ -456,14 +456,14 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara glUniform1f(textureUniformStrideFactor_, Stride); glUniformMatrix4fv(textureUniformProjMatrix_, 1, GL_FALSE, projMatrix); - LOG(Debayer, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ + LOG(SoftwareIspInstance, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ << " tex_y " << textureUniformBayerDataIn_ << " tex_step " << textureUniformStep_ << " tex_size " << textureUniformSize_ << " stride_factor " << textureUniformStrideFactor_ << " tex_bayer_first_red " << textureUniformBayerFirstRed_; - LOG(Debayer, Debug) << "textureUniformY_ = 0 " + LOG(SoftwareIspInstance, Debug) << "textureUniformY_ = 0 " << " firstRed.x " << firstRed[0] << " firstRed.y " << firstRed[1] << " textureUniformSize_.width " << imgSize[0] @@ -476,40 +476,40 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara /* Pre-transpose matrix for GLES 2.0. */ Matrix ccm = params.combinedMatrix.transpose(); glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm.data().data()); - LOG(Debayer, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix; + LOG(SoftwareIspInstance, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix; if (lscEnabled_ && params.lscLutVersion != lscLutVersion_) { egl_.updateTexture2D(*eglImageLscLookup_, params.lscLut.data()); lscLutVersion_ = params.lscLutVersion; glUniform1i(textureUniformLsc_, eglImageLscLookup_->texture_unit_uniform_id_); - LOG(Debayer, Debug) << "LSC texture updated to version " << lscLutVersion_.value_or(-1); + LOG(SoftwareIspInstance, Debug) << "LSC texture updated to version " << lscLutVersion_.value_or(-1); } /* * 0 = Red, 1 = Green, 2 = Blue */ glUniform3f(blackLevelUniformDataIn_, params.blackLevel[0], params.blackLevel[1], params.blackLevel[2]); - LOG(Debayer, Debug) << " blackLevelUniformDataIn_ " << blackLevelUniformDataIn_ << " data " << params.blackLevel; + LOG(SoftwareIspInstance, Debug) << " blackLevelUniformDataIn_ " << blackLevelUniformDataIn_ << " data " << params.blackLevel; glUniform3f(awbUniformDataIn_, params.gains[0], params.gains[1], params.gains[2]); - LOG(Debayer, Debug) << " awbUniformDataIn_ " << awbUniformDataIn_ << " data " << params.gains; + LOG(SoftwareIspInstance, Debug) << " awbUniformDataIn_ " << awbUniformDataIn_ << " data " << params.gains; /* * Gamma */ glUniform1f(gammaUniformDataIn_, params.gamma); - LOG(Debayer, Debug) << " gammaUniformDataIn_ " << gammaUniformDataIn_ << " data " << params.gamma; + LOG(SoftwareIspInstance, Debug) << " gammaUniformDataIn_ " << gammaUniformDataIn_ << " data " << params.gamma; /* * Contrast */ glUniform1f(contrastExpUniformDataIn_, params.contrastExp); - LOG(Debayer, Debug) << " contrastExpUniformDataIn_ " << contrastExpUniformDataIn_ << " data " << params.contrastExp; + LOG(SoftwareIspInstance, Debug) << " contrastExpUniformDataIn_ " << contrastExpUniformDataIn_ << " data " << params.contrastExp; return; } -eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer) +eGLImage *SoftwareIspInstanceGpu::getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer) { const SharedFD &fd = input->planes()[0].fd; bool cache_miss = true; @@ -526,7 +526,7 @@ eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optiona if (cache_miss) { if (eglImageInCache_.size() >= inputBufferCount_) { eglImageInCache_.pop_front(); - LOG(Debayer, Debug) << "Input cache " << inputBufferCount_ << " exceeded evicted entry"; + LOG(SoftwareIspInstance, Debug) << "Input cache " << inputBufferCount_ << " exceeded evicted entry"; } eglImageInCache_.emplace_back(fd, std::make_unique(glFormat_, inputConfig_.stride / bytesPerPixel_, height_, inputConfig_.stride, GL_TEXTURE0, 0)); @@ -536,7 +536,7 @@ eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optiona return eglImageIn; if (eglImageInCache_.size() == 1) - LOG(Debayer, Info) + LOG(SoftwareIspInstance, Info) << "Importing input DMABuf failed, falling back to upload"; } else if (!eglImageIn->dmabuf_import_failed_) { egl_.activateBindTexture(*eglImageIn); @@ -547,7 +547,7 @@ eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optiona inDmaSyncer->emplace(input->planes()[0].fd, DmaSyncer::SyncType::Read); inMapped->emplace(input, MappedFrameBuffer::MapFlag::Read); if (!inMapped->value().isValid()) { - LOG(Debayer, Error) << "mmap-ing buffer(s) failed"; + LOG(SoftwareIspInstance, Error) << "mmap-ing buffer(s) failed"; if (cache_miss) { eglImageInCache_.pop_back(); } @@ -561,7 +561,7 @@ eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optiona return eglImageIn; } -eGLImage *DebayerEGL::getCachedOutputFrameBuffer(FrameBuffer *output) +eGLImage *SoftwareIspInstanceGpu::getCachedOutputFrameBuffer(FrameBuffer *output) { const SharedFD &fd = output->planes()[0].fd; bool cache_miss = true; @@ -578,7 +578,7 @@ eGLImage *DebayerEGL::getCachedOutputFrameBuffer(FrameBuffer *output) if (cache_miss) { if (eglImageOutCache_.size() >= outputBufferCount_) { eglImageOutCache_.pop_front(); - LOG(Debayer, Debug) << "Output cache " << outputBufferCount_ << " exceeded evicted entry"; + LOG(SoftwareIspInstance, Debug) << "Output cache " << outputBufferCount_ << " exceeded evicted entry"; } eglImageOutCache_.emplace_back(fd, std::make_unique(GL_RGBA, outputSize_.width, @@ -594,7 +594,7 @@ eGLImage *DebayerEGL::getCachedOutputFrameBuffer(FrameBuffer *output) return eglImageOut; } -int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *inMapped, std::optional *inDmaSyncer) +int SoftwareIspInstanceGpu::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *inMapped, std::optional *inDmaSyncer) { eGLImage *eglImageIn; eGLImage *eglImageOut; @@ -624,7 +624,7 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye return 0; } -void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms) +void SoftwareIspInstanceGpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms) { egl_.assertThread(); bench_.startFrame(); @@ -639,7 +639,7 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output std::optional inDmaSyncer; if (debayerGPU(input, output, params, &inMapped, &inDmaSyncer)) { - LOG(Debayer, Error) << "debayerGPU failed"; + LOG(SoftwareIspInstance, Error) << "debayerGPU failed"; goto error; } @@ -677,7 +677,7 @@ error: return; } -int DebayerEGL::start() +int SoftwareIspInstanceGpu::start() { GLint maxTextureImageUnits; @@ -686,7 +686,7 @@ int DebayerEGL::start() glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits); - LOG(Debayer, Debug) << "Available fragment shader texture units " << maxTextureImageUnits; + LOG(SoftwareIspInstance, Debug) << "Available fragment shader texture units " << maxTextureImageUnits; if (initBayerShaders(inputPixelFormat_, outputPixelFormat_)) return -EINVAL; @@ -706,7 +706,7 @@ int DebayerEGL::start() return 0; } -void DebayerEGL::stop() +void SoftwareIspInstanceGpu::stop() { eglImageOutCache_.clear(); eglImageInCache_.clear(); @@ -720,7 +720,7 @@ void DebayerEGL::stop() egl_.resetEGLContext(); } -SizeRange DebayerEGL::sizes(PixelFormat inputFormat, const Size &inputSize) +SizeRange SoftwareIspInstanceGpu::sizes(PixelFormat inputFormat, const Size &inputSize) { Size patternSize = this->patternSize(inputFormat); unsigned int borderHeight = patternSize.height; @@ -738,7 +738,7 @@ SizeRange DebayerEGL::sizes(PixelFormat inputFormat, const Size &inputSize) */ if (inputSize.width < (3 * patternSize.width) || inputSize.height < (2 * borderHeight + patternSize.height)) { - LOG(Debayer, Warning) + LOG(SoftwareIspInstance, Warning) << "Input format size too small: " << inputSize; return {}; } diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/software_isp_instance_gpu.h similarity index 94% rename from src/libcamera/software_isp/debayer_egl.h rename to src/libcamera/software_isp/software_isp_instance_gpu.h index cbbc6a450..90cab1b9e 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/software_isp_instance_gpu.h @@ -28,7 +28,7 @@ #include #include -#include "debayer.h" +#include "software_isp_instance.h" namespace libcamera { @@ -37,11 +37,11 @@ namespace libcamera { class CameraManager; -class DebayerEGL : public Debayer +class SoftwareIspInstanceGpu : public SoftwareIspInstance { public: - DebayerEGL(std::unique_ptr stats, const CameraManager &cm, EGLDisplay display); - ~DebayerEGL(); + SoftwareIspInstanceGpu(std::unique_ptr stats, const CameraManager &cm, EGLDisplay display); + ~SoftwareIspInstanceGpu(); int configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfgs, From patchwork Wed Nov 18 09:57:09 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: 28963 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 24ABEBDE17 for ; Wed, 18 Nov 2026 09:57:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CE4FD6A8B1; Wed, 18 Nov 2026 10:57:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Dg2L0Wwv"; 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 95B306A7EA for ; Wed, 18 Nov 2026 10:57:50 +0100 (CET) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-490d59c3f0aso294556f8f.1 for ; Wed, 18 Nov 2026 01:57:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995870; x=1795600670; 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=mu+3zKntSemaZs7194jB7jwYkT7HFXb0haZNtJEHqNU=; b=Dg2L0Wwvlc3yHDAgo5JZ0x81P5yd1ZRRSRIMO7nL7XjTQkH8G+y5i3jS2DqTFpeMbi W9Yzu0a9srxJxAj2y7diw8UaDP3QCVEavHe1tW33PNjiMxzDNE7Bj/v87dlPaPX6/m7p A9SA13vqmWD1fxmyVvkSuSqP06Ix4F+mqCQq7bNGd/LnUaXxNyfACyg3mt/1shzF8Tsd qg+3+FNS+b0af7AChTMUTkYlRDvYpLD4DbU3dI9fx8OXPL8FmFWSbn2Bim9+0eZq0I+A Si/wjs3PRCOZ/XWNpbNqW7cydHTjQgYgoHrbr2b7EbyAasrr/bHXut+W6tGFX1KSR40c UuGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995870; x=1795600670; 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=mu+3zKntSemaZs7194jB7jwYkT7HFXb0haZNtJEHqNU=; b=EkKuM2MH2NIjLRg102dXYbAR46KDKXRzkba/IwoMTVYwwQ/aAfmLavFx3WGSxpnYH0 ISo6tSYIMy1sjm7p6c9CsfUouYcciZXhr6rht8mtTxjRPdmN90XJsLnTIcPvxp7hRxuZ bmYMezdqlMTVDdcTKegFd8BM8bt8gzeg6e0Rta1goIvKmyMMeCJZ6cXzX9Ss4ucgHCvH LR+nPAeqF9rQwCv0wgWqyZGlRTx8IsxNwWlJFrdQgm8SU9UAHVsDsL1VIMx1fJ0xd1E0 DtDhDvAwnquzb/azXzRZXUn5+sp8zEh4/jjO8oj7m9WjW5zqul+9Ra6owtPFJFjryHtP pQiA== X-Gm-Message-State: APuU4Z+bKPTXweEUWJc9UDFIJ0BQnLwH1WkmAPC9eYtaa2o7lzok2DwI lKsir9/SH50NxHEGLMlLHhZ96E25TaW0hrAPZ4oQA9sKyBW+OAh3iaCdlaGmKpW4iMcsum3BEcZ sG8W7OoE= X-Gm-Gg: AZFdTZdpP4mKNCevkbYWRPxcWK8VHb1o6Wpw5azXCLkfzXIl96kINdrh+KY1ilgfs2Z T0o4WbEaVpqNfwZET8BGR9gFBYP984K5U1Ncr3WMtvhtiJ8TbqnFb4z6A9QHampc5ErXARyFImv Zqp6UmcOC+kKu6fOG1Q8LR8b3KJ44WvPHz3oa9K8FMWMLN6x7SGL367AH/6qsJH+pFMsonxWE2c mhDPjF+3AmM9CEavNcsxy8/7X1R6aKHSwDZk2HUMQqUGMavsvkwA+iuitHvHAzjkstj9yMjiqRU 4QdGWJxYeDUieMMNEI12SMJBnxojJNQChqJnhX3OHVN5DaHvB1gQwA3mUARIa4WvnrWIWjOHMai 90Dy27ueIoRNpwhPLZxVv20wcHexM+1K2FA/sR44Akbmyl0+oQ/vGrt+z3TPLkTgXVnLxIhkhpW xSXUOQJW5cErbhVadVZPftQinNceZws2KswGtplK23y5dKAK9OS66AQ+eFxCpqkMmAqgq3xTazb vuiT4+14cfjtU3KGXcJ8x6t15zqj/UMdm4TrZiX+wOlRvtxRRW3fAPHWBMnwaR3/khBpDLMmJlC S+3yjzN5DOQwuNLeNr+YHMUwGF39NWmXAs2wHpV7xfFGUlY= X-Received: by 2002:a05:6000:3c4:b0:48b:1a0:5630 with SMTP id ffacd0b85a97d-4a63d985408mr4287795f8f.41.1794995870055; Wed, 18 Nov 2026 01:57:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:49 -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 02/26] libcamera: software_isp: gpu: rename debayerGPU to processGPU Date: Wed, 18 Nov 2026 10:57:09 +0100 Message-ID: <20261118095735.170587-3-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" This function will do more than debayer, rename it to reflect. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/software_isp_instance_gpu.cpp | 4 ++-- src/libcamera/software_isp/software_isp_instance_gpu.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.cpp b/src/libcamera/software_isp/software_isp_instance_gpu.cpp index db6b23144..b71413fca 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.cpp +++ b/src/libcamera/software_isp/software_isp_instance_gpu.cpp @@ -594,7 +594,7 @@ eGLImage *SoftwareIspInstanceGpu::getCachedOutputFrameBuffer(FrameBuffer *output return eglImageOut; } -int SoftwareIspInstanceGpu::debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *inMapped, std::optional *inDmaSyncer) +int SoftwareIspInstanceGpu::processGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *inMapped, std::optional *inDmaSyncer) { eGLImage *eglImageIn; eGLImage *eglImageOut; @@ -638,7 +638,7 @@ void SoftwareIspInstanceGpu::process(uint32_t frame, FrameBuffer *input, FrameBu std::optional inMapped; std::optional inDmaSyncer; - if (debayerGPU(input, output, params, &inMapped, &inDmaSyncer)) { + if (processGPU(input, output, params, &inMapped, &inDmaSyncer)) { LOG(SoftwareIspInstance, Error) << "debayerGPU failed"; goto error; } diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.h b/src/libcamera/software_isp/software_isp_instance_gpu.h index 90cab1b9e..d729b80e1 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.h +++ b/src/libcamera/software_isp/software_isp_instance_gpu.h @@ -67,7 +67,7 @@ private: int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat); int getShaderVariableLocations(); void setShaderVariableValues(eGLImage &eGLImageIn, const DebayerParams ¶ms); - int debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *mappedInputBuffer, std::optional *inputBufferDmaSyncer); + int processGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *mappedInputBuffer, std::optional *inputBufferDmaSyncer); eGLImage *getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer); eGLImage *getCachedOutputFrameBuffer(FrameBuffer *output); From patchwork Wed Nov 18 09:57:10 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: 28965 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 6E9CBBDE17 for ; Wed, 18 Nov 2026 09:57:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 17B826A8C4; Wed, 18 Nov 2026 10:57:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="bKQab0mt"; 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 AB7266A8B0 for ; Wed, 18 Nov 2026 10:57:52 +0100 (CET) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-48dfc0421d9so598147f8f.1 for ; Wed, 18 Nov 2026 01:57:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995872; x=1795600672; 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=OYuqmQtv68YLL5Eezwz3DHdGo3X9/WrrF5vKFay5Mg4=; b=bKQab0mtyv1N4UzNvJVxaO3S09AmuVhiFyCbvdJeGMOMgIYc1CxcQbg3q/D0NvAamo j9Gw/qt5c5rnM/FfU3mx4ljyIPix4mQozXd6hyqUIIWmhNUAcUoM9CJ/WAKZYOwhcBEn IDy2Pac5hXzHRD3xnOJ/VfvuCkZvm+fGqOqwj5/sqC461OILy+DTTJDjGR9gO9b1TXJo yoiImBymqWxAHGMjXyngAMKDoLln3VrHCCwmXpmoV4cGL+lDALpUburw1+Bz7fqyucMq vPXfbEaToyalP0PmvsPmTQT4ptgs9V6b3h81joyK9mnbLXEnGtoFnhtassV8UvApZ1X0 xNfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995872; x=1795600672; 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=OYuqmQtv68YLL5Eezwz3DHdGo3X9/WrrF5vKFay5Mg4=; b=X4tyGUKYLUhvDLp8fbsvvtVDzJwtj8yygH3XNZbOxM1s+EIoOu9A27ZZyfWY3YyrMt tJAMTamAdu76AyT6v+EYKndGdz5gQ+8sx5xwSShXT1jWfUgvpC7KLauGFChMbjAix0F8 tJfNiJws8i2qA/TM0dRf/v1QDeBkF7nsOW9pFkGzi6w46+Mbnk/jvU4pSmXS9+flURpi 3AZM6+FK/GtHqZ1539RDQbw+E2bqQXfcERg+Dva51rZpz08M2YcO/kyYZhv9RgM9+rNi v00sVDCjMFZF64iS//FWpEHhyo5ZQcvQGjL/5HE+puQBnnl/Wy9Zz44GArV4QemhT4gp yaUw== X-Gm-Message-State: APuU4Z9exENk/AEzvWqK30pz9T+b9E7usdfoVVcYT64XLse82oxix1aV gIxE85JbVFxCc/t41MmID5mgXwhAZLvLGc4EOucNGJFmvREJo6bm080knz4FWWmVdOQva1ClAWZ 2cX6w834= X-Gm-Gg: AZFdTZfl9pqn6Y93/CF5ZpGJSWZAgL9QpiOD2z4xcPrlrzKlVJ9Z1YdKLRyn1Oiex2T 5+IVHJmgIx3wQ7mzDPVLYIU/0kJiMwO/SzuUxvMORAulkQlGq1ZdJkCVGb6VEBAgIZXSOTD+f08 QC3w1aCGUws6NTSo96MuTXVwEaz4fVNfGZK71lSnIO5QWWFmTFXCfZl88OPhSHTOAMGdS+/LIVq +oEOt+19c8lP1nkQhCVukYpaOhjfG0ciz8USVp6yWqZ7RnFzxCJovBVRhEwzGJ6dV9HEgnIPvIz PQpiSyWtu2ep1M+g0wWi69zoS8Nz4n/n+JqTwgmWrR8wZclqQD1vx24To2v51Ca8mBh3HuFjdS/ iuz3Sq60G/RNPh0wP66irFHTVRGvm7X91QeGU2SIpH48NUSUmygj6eNXEtA9M7hJNcuU2zECSXz /Rm/acZFsdzgDmrJlCwSZ7w6yWEBYgK+pgMf9/iZyd9yZsWymEYGmHnDKQ9kvBhTJDL+uIM0XlN gorE05EHOXOH+44DtVNHWNwV2rDniFcpW/pJUKjEfimuT0l99d1tBNOaDYxdS0fywdJ6fpvywks DCcX2OI9SUgv3U/j4qxn6LmkqiRErtVjCIlUOJZeUIoNJQ== X-Received: by 2002:a05:6000:4703:b0:4a6:4f35:31fa with SMTP id ffacd0b85a97d-4a64f35323dmr3951871f8f.3.1794995871254; Wed, 18 Nov 2026 01:57:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:50 -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 03/26] libcamera: software_isp: gpu_pipeline_shader_pass: Add base class GpuPipelineShaderPass Date: Wed, 18 Nov 2026 10:57:10 +0100 Message-ID: <20261118095735.170587-4-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" Signed-off-by: Bryan O'Donoghue --- .../software_isp/gpu_pipeline_shader_pass.cpp | 79 +++++++++++++++++ .../software_isp/gpu_pipeline_shader_pass.h | 85 +++++++++++++++++++ src/libcamera/software_isp/meson.build | 1 + 3 files changed, 165 insertions(+) create mode 100644 src/libcamera/software_isp/gpu_pipeline_shader_pass.cpp create mode 100644 src/libcamera/software_isp/gpu_pipeline_shader_pass.h diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass.cpp b/src/libcamera/software_isp/gpu_pipeline_shader_pass.cpp new file mode 100644 index 000000000..241ea5d8d --- /dev/null +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass.cpp @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Linaro Ltd + * + * GPU ISP shader pass implementation + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include "libcamera/internal/framebuffer.h" +#include "libcamera/internal/ipa_manager.h" +#include "libcamera/internal/software_isp/debayer_params.h" + +#include "gpu_pipeline_shader_pass.h" + +/** + * \file gpu_pipeline_shader_pass.cpp + * \brief GPU ISP shader pass implementation + */ + +namespace libcamera { + +LOG_DEFINE_CATEGORY(GpuShaderPass) + +int GpuIspShaderPass::process(eGLImage &eglImageIn, eGLImage &eglImageOut, uint32_t width, uint32_t height, const DebayerParams ¶ms) +{ + /* Use the program associated with this pass */ + glUseProgram(programId_); + + /* Switch to the output framebuffer */ + egl_.attachTextureToFBO(eglImageOut); + + setShaderVariableValues(eglImageIn, params); + + glViewport(0, 0, width, height); + glClear(GL_COLOR_BUFFER_BIT); + glDrawArrays(GL_TRIANGLE_FAN, 0, DEBAYER_OPENGL_COORDS); + + GLenum err = glGetError(); + if (err != GL_NO_ERROR) { + LOG(GpuShaderPass, Error) << "Drawing scene fail " << err; + return -EIO; + } else { + egl_.flushOutput(); + } + + return 0; +} + +int GpuIspShaderPass::start() +{ + return 0; +} + +void GpuIspShaderPass::stop() +{ + if (programId_) + glDeleteProgram(programId_); +} + +void GpuIspShaderPass::configure(const struct PassConfig &passInputCfg, const struct PassConfig &passOutputCfg) +{ + passInputCfg_ = passInputCfg; + passOutputCfg_ = passOutputCfg; +} + +} diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass.h b/src/libcamera/software_isp/gpu_pipeline_shader_pass.h new file mode 100644 index 000000000..5e3748621 --- /dev/null +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass.h @@ -0,0 +1,85 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Linaro Ltd + * + * Authors: + * Bryan O'Donoghue + * + * GpuIspShaderPass base class + */ + +#pragma once + +#include + +#include +#include +#include + +#include +#include + +#include "libcamera/internal/egl.h" +#include "libcamera/internal/software_isp/debayer_params.h" + +#include +#include +#include + +#include "../shaders/glsl_shaders.h" + +namespace libcamera { + +#define DEBAYER_OPENGL_COORDS 4 + +class FrameBuffer; + +struct PassConfig { + Size size; + unsigned int stride; + PixelFormat format; + Rectangle window; +}; + +class GpuIspShaderPass : public Object +{ +public: + GpuIspShaderPass(eGL& egl) : egl_(egl) {} + virtual ~GpuIspShaderPass() = default; + + virtual int process(eGLImage &eglImageIn, eGLImage &eglImageOut, uint32_t width, uint32_t height, const DebayerParams ¶ms); + virtual int start(); + virtual void stop(); + virtual void configure(const struct PassConfig &passInputCfg, const struct PassConfig &passOutputCfg); + virtual int initShaders(PixelFormat inputFormat, PixelFormat outputFormat) = 0; + virtual int getShaderVariableLocations(void) = 0; + virtual void setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) = 0; + virtual const char *name() const { return "GpuIspShaderPass"; } + + unsigned int getBytesPerPixel() { return bytesPerPixel_; }; + + /* glFormat_ is a special case we are moving to one shader which will use GL_R + * so rather than do a hack make glFormat_ available to the upper level class. + * This variabile will be dropped at the end of the series anyway. + */ + GLint glFormat_; + +private: + LIBCAMERA_DISABLE_COPY_AND_MOVE(GpuIspShaderPass) + +protected: + eGL& egl_; + + /* Shader calculates this getter provides ability to interrogate if needed */ + unsigned int bytesPerPixel_; + + /* Shader program identifiers */ + GLuint vertexShaderId_ = 0; + GLuint fragmentShaderId_ = 0; + GLuint programId_ = 0; + + struct PassConfig passInputCfg_; + struct PassConfig passOutputCfg_; +}; + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index f241e4489..91274e968 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -32,6 +32,7 @@ if mesa_works libcamera_internal_sources += files([ '../egl.cpp', 'software_isp_instance_gpu.cpp', + 'gpu_pipeline_shader_pass.cpp', ]) libcamera_deps += [ libegl, From patchwork Wed Nov 18 09:57:11 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: 28966 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 013C6BDE17 for ; Wed, 18 Nov 2026 09:57:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7075C6A8C5; Wed, 18 Nov 2026 10:57:58 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="GBpVe0cr"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 202036A8BD for ; Wed, 18 Nov 2026 10:57:53 +0100 (CET) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-4a42b34e930so525551f8f.2 for ; Wed, 18 Nov 2026 01:57:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995872; x=1795600672; 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=RQVwgEVHMuFWrXov8O0zYvMSEKS3K1ZP00F5l+qtmi4=; b=GBpVe0crrvswMeXR/U4s3xSrTTSw6sHnACyYRVVCKpZopIR16a2ko4p6xxPtuSyVwp emDcElgIO2xodDCV5M5ttKETuIXuu1fbgNseLBlZO5Oh5BkpjqRa9uTfpsz2v175/QvL rp7bhmTIZtsGTzM5nMdjx3Y3WU/6W3dyFhd2L6FmUfgliGszXWmRxghhsNygtaj73Ipx 7Eq3KJF90rwmx37TsOXy375bk8JDIQoxJZQ4fk3ywpiGx9Xjv9wAbDwa82A7j7ConFS6 sDJiCFLqaLAZ4cZ/+cPrF1vX1FurfASSyQqYtfrKPZBVVr3ItxenKArwersXSLqlVHia F2Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995872; x=1795600672; 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=RQVwgEVHMuFWrXov8O0zYvMSEKS3K1ZP00F5l+qtmi4=; b=F5gATkU+02JMrkIF0DLB4V1+oUa1lc9ohoMK4ZhylCoFAl/knYYuP1y/VMq01RJNYF I2zBSIo/U0MF72KCq5yuXGy5bODSPe8H8lL7QGf1GYKHeYj85Kf8TSWYISNSzmTtcEhL rRCLAA56V0e2jb7eoRZCbM+PicIlHjykrhHgQvA/ORSKUj/tC3pMxJtRfnoqlgtfWId1 pgkht7GfXyL3WBXw6O9c1NpXD74uE7pKDcwUEFqw3OvbJeBPBjEMQkURP/ER23dHQ7sH hq6LQ2A2PdqOCQDr4trR4yb1ZfPIqfW2O73rY4b08A6lK13wqSwvXesTgXaFfZDTY/hK Obdg== X-Gm-Message-State: APuU4Z9KnNEe040+7ZuhBPhoCejxZxwXO1+vs37Ne07urmzr4sp1ktn3 4PXp1oa7tcG7/KAO1o+FB0IHGcN6VVf5/Bzj3e0BVk9aEhOEw1W4cZ5Hpv6kI7dPQ9MRXYSwLhW C0e9S/qI= X-Gm-Gg: AZFdTZcMddrhrV3ZIZi8udh0IQ46/wmT6DagjZ668FOE4I3vKduk0an5CHoeMYntEtP IdIf0DLXW4gRvA+jJ63PIrXTQPyrit6gStrrMG3iueu72xX4tHhzDMSdrnQ5gM+ZRoGRp/hdJEH 6cAM6/tjYq08ByhL1hD61kdB4yxryM+UsxJAKTIM3ks9lUcRYR1fuZn+QtkaoBBoxcXRCpGEfaV siX9mmzdp66jnPcoemFDOUmz2/HhULsvplLWU9+yUjDi9YCuPBbQ1Vxc+trjn3Egd9vgkSiao9u 8bDxmXO18WAh5x6OlwCW+1Yhm4/mWe3JK2jlhsbHrpsNZjDOoEau58LpPHqYx5YdMy3caeTYZSO 6a2vSSYpVgZlz/oG/uDjetYctufwgyxb4Fc+FT3EGN+zVal06Ym6KHKfmx57gtVUt1dMpqFS7oV yrwmZRC6aUe4+2FYn2Fjpt8o/LgSqcXtj11rt+AsIMq+T67+sRa6JXv+JLUja8CUcDom5f0O4Ot elQujtsypWgAxEXUnngseuTjYVt6RLeqQNHLDJorBhJ9TKWndV1FWBjKVnEvFukAGHYwv9eLl9q N1pEr8zQiYQjvd/0tFzlsgYNnoGHJTIS8IMMWI7EI+QW0w== X-Received: by 2002:a05:6000:1616:b0:499:3450:5b4c with SMTP id ffacd0b85a97d-4a63d1dab8bmr2822876f8f.51.1794995872430; Wed, 18 Nov 2026 01:57:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:51 -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 04/26] libcamera: software_isp: gpu_pipeline_shader_pass: Add GpuPipelineShaderPassDemosiac Date: Wed, 18 Nov 2026 10:57:11 +0100 Message-ID: <20261118095735.170587-5-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" Signed-off-by: Bryan O'Donoghue --- .../gpu_pipeline_shader_pass_demosiac.cpp | 332 ++++++++++++++++++ .../gpu_pipeline_shader_pass_demosiac.h | 73 ++++ src/libcamera/software_isp/meson.build | 1 + 3 files changed, 406 insertions(+) create mode 100644 src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp create mode 100644 src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp new file mode 100644 index 000000000..1c821c9fd --- /dev/null +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp @@ -0,0 +1,332 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Linaro Ltd + * + * GPU ISP Demosiac pass + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/framebuffer.h" +#include "libcamera/internal/ipa_manager.h" +#include "libcamera/internal/software_isp/debayer_params.h" + +#include "gpu_pipeline_shader_pass_demosiac.h" + +/** + * \file software_isp.cpp + * \brief Simple software ISP implementation + */ + +namespace libcamera { + +LOG_DEFINE_CATEGORY(GpuShaderDemosiac) + +int GpuIspShaderPassDemosiac::initShaders(PixelFormat inputFormat, PixelFormat outputFormat) +{ + std::span fragmentShaderData; + std::span vertexShaderData; + std::vector shaderEnv; + GLenum err; + + /* 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"); + + /* + * Tell shaders how to re-order output taking account of how the pixels + * are actually stored by EGL. + */ + switch (outputFormat) { + case formats::ARGB8888: + case formats::XRGB8888: + break; + case formats::ABGR8888: + case formats::XBGR8888: + egl_.pushEnv(shaderEnv, "#define SWAP_BLUE"); + break; + default: + LOG(GpuShaderDemosiac, Error) << "Unsupported output format"; + return -EINVAL; + } + + /* Pixel location parameters */ + glFormat_ = GL_LUMINANCE; + bytesPerPixel_ = 1; + shaderStridePixels_ = passInputCfg_.stride; + + 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: + LOG(GpuShaderDemosiac, Error) << "Unsupported input format"; + return -EINVAL; + }; + + /* Shader selection */ + switch (inputFormat) { + case libcamera::formats::SBGGR8: + case libcamera::formats::SGBRG8: + case libcamera::formats::SGRBG8: + case libcamera::formats::SRGGB8: + fragmentShaderData = bayer_unpacked_frag; + vertexShaderData = bayer_unpacked_vert; + 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"); + if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { + fragmentShaderData = bayer_unpacked_frag; + vertexShaderData = bayer_unpacked_vert; + glFormat_ = GL_RG; + bytesPerPixel_ = 2; + } else { + fragmentShaderData = bayer_1x_packed_frag; + 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(shaderEnv, "#define RAW12P"); + if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { + fragmentShaderData = bayer_unpacked_frag; + vertexShaderData = bayer_unpacked_vert; + glFormat_ = GL_RG; + bytesPerPixel_ = 2; + } else { + fragmentShaderData = bayer_1x_packed_frag; + vertexShaderData = identity_vert; + shaderStridePixels_ = passInputCfg_.size.width; + } + break; + }; + + if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, + shaderEnv)) { + LOG(GpuShaderDemosiac, Error) << "Compile vertex shader fail"; + return -ENODEV; + } + utils::scope_exit vShaderGuard([&] { glDeleteShader(vertexShaderId_); }); + + if (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData, + shaderEnv)) { + LOG(GpuShaderDemosiac, Error) << "Compile fragment shader fail"; + return -ENODEV; + } + utils::scope_exit fShaderGuard([&] { glDeleteShader(fragmentShaderId_); }); + + if (egl_.linkProgram(programId_, vertexShaderId_, fragmentShaderId_)) { + LOG(GpuShaderDemosiac, Error) << "Linking program fail"; + return -ENODEV; + } + + egl_.dumpShaderSource(vertexShaderId_); + egl_.dumpShaderSource(fragmentShaderId_); + + /* Ensure we set the programId_ */ + glUseProgram(programId_); + err = glGetError(); + if (err != GL_NO_ERROR) { + LOG(GpuShaderDemosiac, Error) << "Use program error " << err; + return -ENODEV; + } + + return getShaderVariableLocations(); + +} + +int GpuIspShaderPassDemosiac::getShaderVariableLocations(void) +{ + attributeVertex_ = glGetAttribLocation(programId_, "vertexIn"); + attributeTexture_ = glGetAttribLocation(programId_, "textureIn"); + + textureUniformBayerDataIn_ = glGetUniformLocation(programId_, "tex_y"); + awbUniformDataIn_ = glGetUniformLocation(programId_, "awb"); + ccmUniformDataIn_ = glGetUniformLocation(programId_, "ccm"); + blackLevelUniformDataIn_ = glGetUniformLocation(programId_, "blacklevel"); + gammaUniformDataIn_ = glGetUniformLocation(programId_, "gamma"); + contrastExpUniformDataIn_ = glGetUniformLocation(programId_, "contrastExp"); + + 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(GpuShaderDemosiac, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ + << " tex_y " << textureUniformBayerDataIn_ + << " awb " << awbUniformDataIn_ + << " ccm " << ccmUniformDataIn_ + << " blacklevel " << blackLevelUniformDataIn_ + << " gamma " << gammaUniformDataIn_ + << " contrastExp " << contrastExpUniformDataIn_ + << " tex_step " << textureUniformStep_ + << " tex_size " << textureUniformSize_ + << " stride_factor " << textureUniformStrideFactor_ + << " tex_bayer_first_red " << textureUniformBayerFirstRed_ + << " proj_matrix " << textureUniformProjMatrix_; + return 0; + +} + +void GpuIspShaderPassDemosiac::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 the output size from the native size the algorithm produces for + * the input size. Keep the aspect ratio and prefer cropping over black + * bars. + */ + GLfloat scale = std::max((GLfloat)passOutputCfg_.size.width / passOutputCfg_.window.size().width, + (GLfloat)passOutputCfg_.size.height / passOutputCfg_.window.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(GpuShaderDemosiac, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ + << " tex_y " << textureUniformBayerDataIn_ + << " tex_step " << textureUniformStep_ + << " tex_size " << textureUniformSize_ + << " stride_factor " << textureUniformStrideFactor_ + << " tex_bayer_first_red " << textureUniformBayerFirstRed_; + + LOG(GpuShaderDemosiac, 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_; + + /* Pre-transpose matrix for GLES 2.0. */ + Matrix ccm = params.combinedMatrix.transpose(); + glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm.data().data()); + LOG(GpuShaderDemosiac, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix; + + /* + * 0 = Red, 1 = Green, 2 = Blue + */ + glUniform3f(blackLevelUniformDataIn_, params.blackLevel[0], params.blackLevel[1], params.blackLevel[2]); + LOG(GpuShaderDemosiac, Debug) << " blackLevelUniformDataIn_ " << blackLevelUniformDataIn_ << " data " << params.blackLevel; + + glUniform3f(awbUniformDataIn_, params.gains[0], params.gains[1], params.gains[2]); + LOG(GpuShaderDemosiac, Debug) << " awbUniformDataIn_ " << awbUniformDataIn_ << " data " << params.gains; + + /* + * Gamma + */ + glUniform1f(gammaUniformDataIn_, params.gamma); + LOG(GpuShaderDemosiac, Debug) << " gammaUniformDataIn_ " << gammaUniformDataIn_ << " data " << params.gamma; + + /* + * Contrast + */ + glUniform1f(contrastExpUniformDataIn_, params.contrastExp); + LOG(GpuShaderDemosiac, Debug) << " contrastExpUniformDataIn_ " << contrastExpUniformDataIn_ << " data " << params.contrastExp; + + return; +} + +} diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h new file mode 100644 index 000000000..eccab94f9 --- /dev/null +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Linaro Ltd + * + * Authors: + * Bryan O'Donoghue + * + * GpuIspIspShaderPass 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 GpuIspShaderPassDemosiac : public GpuIspShaderPass +{ +public: + GpuIspShaderPassDemosiac(eGL& egl) : GpuIspShaderPass(egl) {}; + + /* Things that every ISP pipeline pass will need to do */ + int initShaders(PixelFormat inputFormat, PixelFormat outputFormat) override; + int getShaderVariableLocations(void) override; + void setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) override; + + const char *name() const override { return "GpuIspShaderPassDemosiac"; } +private: + /* Shader parameters */ + float firstRed_x_; + float firstRed_y_; + GLint attributeVertex_; + GLint attributeTexture_; + GLint textureUniformStep_; + GLint textureUniformSize_; + GLint textureUniformStrideFactor_; + GLint textureUniformBayerFirstRed_; + GLint textureUniformProjMatrix_; + GLint textureUniformBayerDataIn_; + + uint32_t shaderStridePixels_; + + /* Per-frame AWB gains */ + GLint awbUniformDataIn_; + + /* Represent per-frame CCM as a uniform vector of floats 3 x 3 */ + GLint ccmUniformDataIn_; + + /* Black Level compensation */ + GLint blackLevelUniformDataIn_; + + /* Gamma */ + GLint gammaUniformDataIn_; + + /* Contrast */ + GLint contrastExpUniformDataIn_; +}; + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index 91274e968..bad821351 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -33,6 +33,7 @@ if mesa_works '../egl.cpp', 'software_isp_instance_gpu.cpp', 'gpu_pipeline_shader_pass.cpp', + 'gpu_pipeline_shader_pass_demosiac.cpp', ]) libcamera_deps += [ libegl, From patchwork Wed Nov 18 09:57:12 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: 28967 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 D9C14BDE17 for ; Wed, 18 Nov 2026 09:58:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9555B6A8C1; Wed, 18 Nov 2026 10:57:59 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="mD4XwrQ7"; 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 227C26A7EA for ; Wed, 18 Nov 2026 10:57:54 +0100 (CET) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-4a7b8abe209so156832f8f.0 for ; Wed, 18 Nov 2026 01:57:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995874; x=1795600674; 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=Ur2XLfwoeFuqH1nFOEOZ3nxmycfg2lV0KINd0LFocGI=; b=mD4XwrQ7p6MJ8s+qp5/+YNnrNlu5hJ54UzG8LPefHGj4EmT6L2JVnxnc13YQjEzELi rf+fFNFvv2ReCIvI+BJlpbMWHTeLbvxSFeh0vD4MuHHwTcSVjStKQnh82cn5vSS1ltjE oE+F/blLyys/xl83Uo8BTasrF2YwSwcDR4lLL5hIw/4l7ohbTPTGnW0liLWDi1EXd7/S tpGMICnkPi766Ij4hpIycOtZpjEW4n5y2ykWHHBulLbwbAMAwAwbLOt7EMuc+4SjXJqb 6T4QVL0IxiotPR1qrzEdZUAH0kHjA8MCPg9hXSxhKl1Fg3UuNmB4p3YCKgle3Uy1q+XB 82fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995874; x=1795600674; 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=Ur2XLfwoeFuqH1nFOEOZ3nxmycfg2lV0KINd0LFocGI=; b=Tq2lwI8SE8LW2rrkGZIWKdw+oBbdPNvbUPpf0AsdH8I8yLaTZVJCGZuIqv/SfCxh8O NK1EZ8JZmNtG2Bpg3Le3enskC3wkCocbhKmV5Jdg1BUoqys7y+ORJaqL8vUj1yGhzcTs AzpsD8ak8nVXYyJ86h1BLvVnfW47gOq31dCAxVyOlJyOID54ivgV8kBhQwKbQrTfCggl zut+zuJM4QPKNNWMYBZ4cSFaJhKlC5B80kMq5vutd1ompiRzsTjbE0/Nr5tQAtDBt4IQ FKv6DuYmSnuiC9QDFCktbuSDQlgZXcgj4dx6LAzXgOpU+emErViArWwgb9tYUtioLvHv Ya7Q== X-Gm-Message-State: APuU4Z8e8RMsLXVm2PrMlAp+fysg9mPZhHk69HtbkP/mSxbHsMbVid6r Ph3ZbH0AJCaHw/RHuAHEw03oXO2FZFzeb4d/BueUoHBMZq9AwWKee+RIEp1o8OSuTj4S5hwnuLL x5SlhMFI= X-Gm-Gg: AZFdTZetJzjrJhhrR5Cf16K1iUf4EQ5aWwsrH9LKgtEmigIO5pmHPSjnuFZBVJyVmaA Pr/M8zDiOKb24rknrF0ZazffB9H0F2fvHGoO/UD2WSFq/627G8cxKFSRpOk9G+H2vDoifIcP31O 86F2WPgrME7LJJCmPxpuPTstc2gnrGpWUBSzqF6j0n8wxC1jRD5lvB1FoDrQ113J229aImoPfa9 4lu3zLSJ7bkPWUGbrQ08BZRnJTeNZgt5m9+1WriUHKn+AYVc5e0scl0EVwJshfL7DSBGMIZ+Wvz djeUxLzLUqlLDhc+/wkGAzjM0/Mdfa3eTr8oc8gCJD27BJQePtFIyKgDI0KU2DduNtca4JcMpcW 37y5iJSkR2vdYizuk2aKJ0+n3CE5yLx97PGcPbD3QfyYtDkAicAYnLzjYxnIS6EFlnQS+J88lTv vnc7H8kFXJAgbDBMA7RDKwi9g9zPPKgWZzcMw+41HzLcSgxJNkNGpzEEFjQWlbBrV+FJR6zpsmF /sbmE3VYRdo+jdATuULIaUFkCTRCy2b4BrANTEWFCY5/qIn+IJ+yyT4MnQxqSQr8h/laT8T6gsP +GrP21pFTgmNdincgRSTnAk0zUX9SXKaaZ//QU/w5E6LMg== X-Received: by 2002:a05:6000:1a8d:b0:48d:fdd0:6ce8 with SMTP id ffacd0b85a97d-4a636582533mr4649514f8f.3.1794995873534; Wed, 18 Nov 2026 01:57:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:52 -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 05/26] libcamera: software_isp: gpu: Switch to using GpuIspShaderPassDemosiac Date: Wed, 18 Nov 2026 10:57:12 +0100 Message-ID: <20261118095735.170587-6-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" Switch to using GpuIspShaderPassDemosiac as the first instance of our multi-pass GPUISP implementation. Subsequent patches will move elements of this leviathan into discreet elements with an objective of eliminating register spill, separation of concerns and de-spaghettification. Code red patches are always best. Signed-off-by: Bryan O'Donoghue --- .../gpu_pipeline_shader_pass_demosiac.cpp | 29 ++ .../gpu_pipeline_shader_pass_demosiac.h | 9 + .../software_isp_instance_gpu.cpp | 352 +----------------- .../software_isp/software_isp_instance_gpu.h | 48 +-- 4 files changed, 57 insertions(+), 381 deletions(-) diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp index 1c821c9fd..8c46e5795 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp @@ -48,6 +48,10 @@ int GpuIspShaderPassDemosiac::initShaders(PixelFormat inputFormat, PixelFormat o /* Specify GL_OES_EGL_image_external */ egl_.pushEnv(shaderEnv, "#extension GL_OES_EGL_image_external: enable"); + /* LSC flag */ + if (lscEnabled_) + egl_.pushEnv(shaderEnv, "#define APPLY_LSC"); + /* * Tell shaders how to re-order output taking account of how the pixels * are actually stored by EGL. @@ -173,6 +177,15 @@ int GpuIspShaderPassDemosiac::initShaders(PixelFormat inputFormat, PixelFormat o return -ENODEV; } + if (lscEnabled_) { + constexpr unsigned int gridSize = DebayerParams::kLscGridSize; + constexpr unsigned int stride = gridSize * DebayerParams::kLscBytesPerCell; + + eglImageLscLookup_.emplace(GL_RGBA, gridSize, gridSize, stride, + GL_TEXTURE2, 2); + egl_.createTexture2D(*eglImageLscLookup_, nullptr, GL_LINEAR); + } + return getShaderVariableLocations(); } @@ -188,6 +201,7 @@ int GpuIspShaderPassDemosiac::getShaderVariableLocations(void) blackLevelUniformDataIn_ = glGetUniformLocation(programId_, "blacklevel"); gammaUniformDataIn_ = glGetUniformLocation(programId_, "gamma"); contrastExpUniformDataIn_ = glGetUniformLocation(programId_, "contrastExp"); + textureUniformLsc_ = glGetUniformLocation(programId_, "lsc_tex"); textureUniformStep_ = glGetUniformLocation(programId_, "tex_step"); textureUniformSize_ = glGetUniformLocation(programId_, "tex_size"); @@ -305,6 +319,13 @@ void GpuIspShaderPassDemosiac::setShaderVariableValues(eGLImage &eglImageIn, con glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm.data().data()); LOG(GpuShaderDemosiac, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix; + /* LSC table */ + if (lscEnabled_ && params.lscLutVersion != lscLutVersion_) { + egl_.updateTexture2D(*eglImageLscLookup_, params.lscLut.data()); + lscLutVersion_ = params.lscLutVersion; + glUniform1i(textureUniformLsc_, eglImageLscLookup_->texture_unit_uniform_id_); + } + /* * 0 = Red, 1 = Green, 2 = Blue */ @@ -329,4 +350,12 @@ void GpuIspShaderPassDemosiac::setShaderVariableValues(eGLImage &eglImageIn, con return; } +void GpuIspShaderPassDemosiac::stop() +{ + eglImageLscLookup_.reset(); + lscLutVersion_.reset(); + + GpuIspShaderPass::stop(); +} + } diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h index eccab94f9..97f84d444 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h @@ -38,6 +38,9 @@ public: int getShaderVariableLocations(void) override; void setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) override; + void setLscEnabled(bool enabled) { lscEnabled_ = enabled; } + void stop() override; + const char *name() const override { return "GpuIspShaderPassDemosiac"; } private: /* Shader parameters */ @@ -68,6 +71,12 @@ private: /* Contrast */ GLint contrastExpUniformDataIn_; + + /* Lens shading correction */ + bool lscEnabled_ = false; + std::optional eglImageLscLookup_; + std::optional lscLutVersion_; + GLint textureUniformLsc_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.cpp b/src/libcamera/software_isp/software_isp_instance_gpu.cpp index b71413fca..4cec8f598 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.cpp +++ b/src/libcamera/software_isp/software_isp_instance_gpu.cpp @@ -43,7 +43,7 @@ namespace libcamera { * \param[in] display The EGL display to use */ SoftwareIspInstanceGpu::SoftwareIspInstanceGpu(std::unique_ptr stats, const CameraManager &cm, EGLDisplay display) - : SoftwareIspInstance(cm), stats_(std::move(stats)), egl_(display) + : SoftwareIspInstance(cm), stats_(std::move(stats)), egl_(display), gpuIspShaderPassDemosiac_(egl_) { } @@ -97,184 +97,9 @@ int SoftwareIspInstanceGpu::getInputConfig(PixelFormat inputFormat, DebayerInput return -EINVAL; } -int SoftwareIspInstanceGpu::getShaderVariableLocations(void) -{ - attributeVertex_ = glGetAttribLocation(programId_, "vertexIn"); - attributeTexture_ = glGetAttribLocation(programId_, "textureIn"); - - textureUniformBayerDataIn_ = glGetUniformLocation(programId_, "tex_y"); - awbUniformDataIn_ = glGetUniformLocation(programId_, "awb"); - ccmUniformDataIn_ = glGetUniformLocation(programId_, "ccm"); - blackLevelUniformDataIn_ = glGetUniformLocation(programId_, "blacklevel"); - gammaUniformDataIn_ = glGetUniformLocation(programId_, "gamma"); - contrastExpUniformDataIn_ = glGetUniformLocation(programId_, "contrastExp"); - - 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"); - - textureUniformLsc_ = glGetUniformLocation(programId_, "lsc_tex"); - - LOG(SoftwareIspInstance, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ - << " tex_y " << textureUniformBayerDataIn_ - << " awb " << awbUniformDataIn_ - << " ccm " << ccmUniformDataIn_ - << " blacklevel " << blackLevelUniformDataIn_ - << " gamma " << gammaUniformDataIn_ - << " contrastExp " << contrastExpUniformDataIn_ - << " tex_step " << textureUniformStep_ - << " tex_size " << textureUniformSize_ - << " stride_factor " << textureUniformStrideFactor_ - << " tex_bayer_first_red " << textureUniformBayerFirstRed_ - << " proj_matrix " << textureUniformProjMatrix_ - << " tex_lsc " << textureUniformLsc_; - return 0; -} - int SoftwareIspInstanceGpu::initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat) { - std::span fragmentShaderData; - std::span vertexShaderData; - std::vector shaderEnv; - GLenum err; - - /* 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"); - - if (lscEnabled_) - egl_.pushEnv(shaderEnv, "#define APPLY_LSC"); - - /* - * Tell shaders how to re-order output taking account of how the pixels - * are actually stored by EGL. - */ - switch (outputFormat) { - case formats::ARGB8888: - case formats::XRGB8888: - break; - case formats::ABGR8888: - case formats::XBGR8888: - egl_.pushEnv(shaderEnv, "#define SWAP_BLUE"); - break; - default: - LOG(SoftwareIspInstance, Error) << "Unsupported output format"; - return -EINVAL; - } - - /* Pixel location parameters */ - glFormat_ = GL_LUMINANCE; - bytesPerPixel_ = 1; - shaderStridePixels_ = inputConfig_.stride; - - 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: - LOG(SoftwareIspInstance, Error) << "Unsupported input format"; - return -EINVAL; - }; - - /* Shader selection */ - switch (inputFormat) { - case libcamera::formats::SBGGR8: - case libcamera::formats::SGBRG8: - case libcamera::formats::SGRBG8: - case libcamera::formats::SRGGB8: - fragmentShaderData = bayer_unpacked_frag; - vertexShaderData = bayer_unpacked_vert; - 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"); - if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { - fragmentShaderData = bayer_unpacked_frag; - vertexShaderData = bayer_unpacked_vert; - glFormat_ = GL_RG; - bytesPerPixel_ = 2; - } else { - fragmentShaderData = bayer_1x_packed_frag; - vertexShaderData = identity_vert; - shaderStridePixels_ = width_; - } - 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"); - if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { - fragmentShaderData = bayer_unpacked_frag; - vertexShaderData = bayer_unpacked_vert; - glFormat_ = GL_RG; - bytesPerPixel_ = 2; - } else { - fragmentShaderData = bayer_1x_packed_frag; - vertexShaderData = identity_vert; - shaderStridePixels_ = width_; - } - break; - }; - - if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, - shaderEnv)) { - LOG(SoftwareIspInstance, Error) << "Compile vertex shader fail"; - return -ENODEV; - } - utils::scope_exit vShaderGuard([&] { glDeleteShader(vertexShaderId_); }); - - if (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData, - shaderEnv)) { - LOG(SoftwareIspInstance, Error) << "Compile fragment shader fail"; - return -ENODEV; - } - utils::scope_exit fShaderGuard([&] { glDeleteShader(fragmentShaderId_); }); - - if (egl_.linkProgram(programId_, vertexShaderId_, fragmentShaderId_)) { - LOG(SoftwareIspInstance, Error) << "Linking program fail"; - return -ENODEV; - } - - egl_.dumpShaderSource(vertexShaderId_); - egl_.dumpShaderSource(fragmentShaderId_); - - /* Ensure we set the programId_ */ - glUseProgram(programId_); - err = glGetError(); - if (err != GL_NO_ERROR) { - LOG(SoftwareIspInstance, Error) << "Use program error " << err; - return -ENODEV; - } - - return getShaderVariableLocations(); + return gpuIspShaderPassDemosiac_.initShaders(inputFormat, outputFormat); } int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg, @@ -300,7 +125,7 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg, return -EINVAL; } - lscEnabled_ = lscEnabled; + gpuIspShaderPassDemosiac_.setLscEnabled(lscEnabled); inputConfig_.stride = inputCfg.stride; inputPixelFormat_ = inputCfg.pixelFormat; @@ -347,6 +172,12 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg, inputBufferCount_ = inputCfg.bufferCount; outputBufferCount_ = outputCfg.bufferCount; + /* Configure for one pass */ + PassConfig rawSensorIn = { inputCfg.size, inputConfig_.stride, inputPixelFormat_, window_ }; + PassConfig rgbaOut = { outputCfg.size, outputConfig_.stride, outputPixelFormat_, Rectangle(nativeOutputSize_) }; + + gpuIspShaderPassDemosiac_.configure(rawSensorIn, rgbaOut); + return 0; } @@ -384,131 +215,6 @@ uint32_t SoftwareIspInstanceGpu::preferredInputStride(const PixelFormat &inputFo return info.stride(size.width, 0, 256); } -void SoftwareIspInstanceGpu::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)width_, - (GLfloat)height_ }; - GLfloat Step[] = { static_cast(bytesPerPixel_) / (inputConfig_.stride - 1), - 1.0f / (height_ - 1) }; - GLfloat Stride = (GLfloat)width_ / (shaderStridePixels_ / bytesPerPixel_); - /* - * Scale the output size from the native size the algorithm produces for - * the input size. Keep the aspect ratio and prefer cropping over black - * bars. - */ - GLfloat scale = std::max((GLfloat)outputSize_.width / nativeOutputSize_.width, - (GLfloat)outputSize_.height / nativeOutputSize_.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(SoftwareIspInstance, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ - << " tex_y " << textureUniformBayerDataIn_ - << " tex_step " << textureUniformStep_ - << " tex_size " << textureUniformSize_ - << " stride_factor " << textureUniformStrideFactor_ - << " tex_bayer_first_red " << textureUniformBayerFirstRed_; - - LOG(SoftwareIspInstance, 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_; - - /* Pre-transpose matrix for GLES 2.0. */ - Matrix ccm = params.combinedMatrix.transpose(); - glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm.data().data()); - LOG(SoftwareIspInstance, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix; - - if (lscEnabled_ && params.lscLutVersion != lscLutVersion_) { - egl_.updateTexture2D(*eglImageLscLookup_, params.lscLut.data()); - lscLutVersion_ = params.lscLutVersion; - glUniform1i(textureUniformLsc_, eglImageLscLookup_->texture_unit_uniform_id_); - LOG(SoftwareIspInstance, Debug) << "LSC texture updated to version " << lscLutVersion_.value_or(-1); - } - - /* - * 0 = Red, 1 = Green, 2 = Blue - */ - glUniform3f(blackLevelUniformDataIn_, params.blackLevel[0], params.blackLevel[1], params.blackLevel[2]); - LOG(SoftwareIspInstance, Debug) << " blackLevelUniformDataIn_ " << blackLevelUniformDataIn_ << " data " << params.blackLevel; - - glUniform3f(awbUniformDataIn_, params.gains[0], params.gains[1], params.gains[2]); - LOG(SoftwareIspInstance, Debug) << " awbUniformDataIn_ " << awbUniformDataIn_ << " data " << params.gains; - - /* - * Gamma - */ - glUniform1f(gammaUniformDataIn_, params.gamma); - LOG(SoftwareIspInstance, Debug) << " gammaUniformDataIn_ " << gammaUniformDataIn_ << " data " << params.gamma; - - /* - * Contrast - */ - glUniform1f(contrastExpUniformDataIn_, params.contrastExp); - LOG(SoftwareIspInstance, Debug) << " contrastExpUniformDataIn_ " << contrastExpUniformDataIn_ << " data " << params.contrastExp; - - return; -} - eGLImage *SoftwareIspInstanceGpu::getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer) { const SharedFD &fd = input->planes()[0].fd; @@ -529,7 +235,9 @@ eGLImage *SoftwareIspInstanceGpu::getCachedInputFrameBuffer(FrameBuffer *input, LOG(SoftwareIspInstance, Debug) << "Input cache " << inputBufferCount_ << " exceeded evicted entry"; } - eglImageInCache_.emplace_back(fd, std::make_unique(glFormat_, inputConfig_.stride / bytesPerPixel_, height_, inputConfig_.stride, GL_TEXTURE0, 0)); + eglImageInCache_.emplace_back(fd, std::make_unique(gpuIspShaderPassDemosiac_.glFormat_, + inputConfig_.stride / gpuIspShaderPassDemosiac_.getBytesPerPixel(), + height_, inputConfig_.stride, GL_TEXTURE0, 0)); eglImageIn = eglImageInCache_.back().second.get(); if (egl_.createInputDMABufTexture2D(*eglImageIn, input->planes()[0].fd.get()) == 0) @@ -596,6 +304,7 @@ eGLImage *SoftwareIspInstanceGpu::getCachedOutputFrameBuffer(FrameBuffer *output int SoftwareIspInstanceGpu::processGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms, std::optional *inMapped, std::optional *inDmaSyncer) { + int pipelineResult = 0; eGLImage *eglImageIn; eGLImage *eglImageOut; @@ -606,22 +315,9 @@ int SoftwareIspInstanceGpu::processGPU(FrameBuffer *input, FrameBuffer *output, if (!eglImageOut) return -ENOMEM; - egl_.attachTextureToFBO(*eglImageOut); - setShaderVariableValues(*eglImageIn, params); - - glViewport(0, 0, width_, height_); - glClear(GL_COLOR_BUFFER_BIT); - glDrawArrays(GL_TRIANGLE_FAN, 0, DEBAYER_OPENGL_COORDS); + pipelineResult = gpuIspShaderPassDemosiac_.process(*eglImageIn, *eglImageOut, width_, height_, params); - GLenum err = glGetError(); - if (err != GL_NO_ERROR) { - LOG(eGL, Error) << "Drawing scene fail " << err; - return -ENODEV; - } else { - egl_.flushOutput(); - } - - return 0; + return pipelineResult; } void SoftwareIspInstanceGpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms) @@ -691,18 +387,6 @@ int SoftwareIspInstanceGpu::start() if (initBayerShaders(inputPixelFormat_, outputPixelFormat_)) return -EINVAL; - if (lscEnabled_) { - constexpr unsigned int gridSize = DebayerParams::kLscGridSize; - constexpr unsigned int stride = gridSize * DebayerParams::kLscBytesPerCell; - eglImageLscLookup_.emplace(GL_RGBA, - gridSize, - gridSize, - stride, - GL_TEXTURE2, - 2); - egl_.createTexture2D(*eglImageLscLookup_, nullptr, GL_LINEAR); - } - return 0; } @@ -711,11 +395,7 @@ void SoftwareIspInstanceGpu::stop() eglImageOutCache_.clear(); eglImageInCache_.clear(); - eglImageLscLookup_.reset(); - lscLutVersion_.reset(); - - if (programId_) - glDeleteProgram(programId_); + gpuIspShaderPassDemosiac_.stop(); egl_.resetEGLContext(); } diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.h b/src/libcamera/software_isp/software_isp_instance_gpu.h index d729b80e1..4a9de99ad 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.h +++ b/src/libcamera/software_isp/software_isp_instance_gpu.h @@ -29,11 +29,11 @@ #include #include "software_isp_instance.h" +#include "gpu_pipeline_shader_pass_demosiac.h" namespace libcamera { #define DEBAYER_EGL_MIN_SIMPLE_RGB_GAIN_TEXTURE_UNITS 4 -#define DEBAYER_OPENGL_COORDS 4 class CameraManager; @@ -72,62 +72,20 @@ private: eGLImage *getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer); eGLImage *getCachedOutputFrameBuffer(FrameBuffer *output); - /* Shader program identifiers */ - GLuint vertexShaderId_ = 0; - GLuint fragmentShaderId_ = 0; - GLuint programId_ = 0; - /* Pointer to object representing input texture */ std::deque>> eglImageInCache_; std::deque>> eglImageOutCache_; unsigned int inputBufferCount_; unsigned int outputBufferCount_; - /* LSC lookup table */ - bool lscEnabled_; - std::optional eglImageLscLookup_; - std::optional lscLutVersion_; - - /* Shader parameters */ - float firstRed_x_; - float firstRed_y_; - GLint attributeVertex_; - GLint attributeTexture_; - GLint textureUniformStep_; - GLint textureUniformSize_; - GLint textureUniformStrideFactor_; - GLint textureUniformBayerFirstRed_; - GLint textureUniformProjMatrix_; - - GLint textureUniformBayerDataIn_; - - /* Per-frame AWB gains */ - GLint awbUniformDataIn_; - - /* Lens shading correction */ - GLint textureUniformLsc_; - - /* Represent per-frame CCM as a uniform vector of floats 3 x 3 */ - GLint ccmUniformDataIn_; - - /* Black Level compensation */ - GLint blackLevelUniformDataIn_; - - /* Gamma */ - GLint gammaUniformDataIn_; - - /* Contrast */ - GLint contrastExpUniformDataIn_; - Size nativeOutputSize_; Rectangle window_; std::unique_ptr stats_; eGL egl_; uint32_t width_; uint32_t height_; - GLint glFormat_; - unsigned int bytesPerPixel_; - uint32_t shaderStridePixels_; + + GpuIspShaderPassDemosiac gpuIspShaderPassDemosiac_; }; } /* namespace libcamera */ From patchwork Wed Nov 18 09:57:13 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: 28968 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 536C1C3355 for ; Wed, 18 Nov 2026 09:58:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9EC316A8B9; Wed, 18 Nov 2026 10:58:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="b0gxSW2G"; 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 1192A6A8AA for ; Wed, 18 Nov 2026 10:57:55 +0100 (CET) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-4a357b1c649so391799f8f.3 for ; Wed, 18 Nov 2026 01:57:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995875; x=1795600675; 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=QZskon6kHLcmiYpqHAXOnpz2FYA2mgCT4CsAt6KaUE0=; b=b0gxSW2G5s8uR69LadsqcDBbyubEgKhKakFQ8xC4DXhMjjLwjCV5ebifsOSv4d3/CO 3i6Prw9ffW0GTbYIt0tQYm5k6bxNv1Mkai03hNLkJ0Td0Tt8KdnF+LtaGD4nGepdLQIM kUbdLbAn6lsSuJIpsg/wepbpAcL524cEKxlOaosvJ2xLDj1v/hw365j2kGHl/MeR4pSh Z0uvmpZW/e1oDryGGUvESUtEPtpg3eqA2sJUT2j+uwWOlVTyw6qB73YYoBP/K8sTQqJO 1r6ALulN2ul8M3XuMP4JCFIISfV3pjneVB1pVQBkeY6jMfr9tgBgqiZcdJtAIFjKVW3g D+Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995875; x=1795600675; 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=QZskon6kHLcmiYpqHAXOnpz2FYA2mgCT4CsAt6KaUE0=; b=BdeZ5ByfvfzBAPkR/rdA0IyaofA3AkjOtuzaE7cn827Y0Yur0dgQ7VYwdGm9VhOz8t s89GNlUyNLD2z4sglTJ5UDLfLf3eOqFvJn/UsincKbZnNcGcFvfXd64ft/mt0X4F8pQ+ fB7UPVviLu69EkffRCdcZMkZvvMgoe9NGmfmI7D0+FAaAPPYRLBrzCH6it3e8tmY9Gv/ AkG+OBWEYsb6bhs90XrApgky8i/TJEM4G/TlWpLp0K+30Rcfjr0JE03lF1H81iqFKBTI G9tAGgKHnNTpcNjKe4wAxKa0zI792yHSIo7V67Sg+FfOZF8C4e37ZKxM/3ey6pCmJ/Hj WyWw== X-Gm-Message-State: APuU4Z8FDblH1Rb8chy84tU2ZTIJ6OMbsHjZfhcLDixnBPy+osx5Nkb2 3siqSBpVRpet+Uu7+Dd34R/6TwT0UGR39AQ0uqMZdrFX4A8ZBxpP6DSJOEU9nPY8iCzOY5fe6eg eOzt9vp8= X-Gm-Gg: AZFdTZeatr5lGeDHCUFcXDS/xdcTf+j5/bG/xjMA0Enr1wu5Eug4kqNdf3kCGIhVA+Z SWTRFN3OJ6l+CaIdZjpOuIddXUFwwKAl8OD2nAtwcNlYCSl2JyZVFDQn2GDtD4tpx2iuGYfMzA7 NoZZdR/zFQw4vGquPe5UuBohUrp9YfgfuczULfCTYku9hCeu16qItgOc8awgh13FRnydLPPcmXl WstNGwfb8lIIClA2u7dSoOw7HeEeb9bkwqhEoJnK19ZJ+bVV2Y2N/mzhaCpO0Y8YVzbLxSoHzgR gHbzGv1et84AbZdWGMzbvDTngCPkX0lkiZXazUWHA0PjZmPu13SBJWx10RPkjW2z66mT1fTen42 vIPETMj7LuRhFEc4ZgVEF8wGyddaz8brJogaqaJs15vPHI6tub+snFRt2mI8mDP9Nzgs2xQDT4S gKyEEWaY9QtXbcT1t6O32AfFoA4q/4FGzGvN8ZwAh1t+5PLaAoRYXGlI7oVAaQBMbPAenkAZGRv d9qYhmsHPTXWaFXiuB+3QV32P4qBJ/fJEGSBWrU1Mwkp/pYkRmhA7LI/ztHgMJnayY0ThQgr0Sh HNWxysvd1alF+k7usbJ/CgddWSdcJJfIpU8iFiuG/+vQ1ZaPB7C8bKQqLP/qhiqBH3M= X-Received: by 2002:a05:6000:46ce:b0:490:9fe2:6a2d with SMTP id ffacd0b85a97d-4a63a5b55c8mr2480224f8f.26.1794995874542; Wed, 18 Nov 2026 01:57:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:53 -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 06/26] libcamera: software_isp: gpu: Make Rectangle window_ a local variable in configure() Date: Wed, 18 Nov 2026 10:57:13 +0100 Message-ID: <20261118095735.170587-7-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" Class member window_ is only used in one method now so make it a local to that method instead. Signed-off-by: Bryan O'Donoghue --- .../software_isp/software_isp_instance_gpu.cpp | 16 +++++++++------- .../software_isp/software_isp_instance_gpu.h | 1 - 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.cpp b/src/libcamera/software_isp/software_isp_instance_gpu.cpp index 4cec8f598..5c473948c 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.cpp +++ b/src/libcamera/software_isp/software_isp_instance_gpu.cpp @@ -107,6 +107,8 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg, [[maybe_unused]] bool ccmEnabled, bool lscEnabled) { + Rectangle window; + if (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0) { LOG(SoftwareIspInstance, Error) << "Unsupported input format " << inputCfg.pixelFormat; @@ -156,24 +158,24 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg, outputSize_ = outputCfg.size; nativeOutputSize_ = outSizeRange.max; - window_.x = ((inputCfg.size.width - outputCfg.size.width) / 2) & + window.x = ((inputCfg.size.width - outputCfg.size.width) / 2) & ~(inputConfig_.patternSize.width - 1); - window_.y = ((inputCfg.size.height - outputCfg.size.height) / 2) & + window.y = ((inputCfg.size.height - outputCfg.size.height) / 2) & ~(inputConfig_.patternSize.height - 1); - window_.width = outputCfg.size.width; - window_.height = outputCfg.size.height; + window.width = outputCfg.size.width; + window.height = outputCfg.size.height; /* - * Don't pass x,y from window_ since process() already adjusts for it. + * Don't pass x,y from window since process() already adjusts for it. * But crop the window to 2/3 of its width and height for speedup. */ - stats_->setWindow(Rectangle(window_.size())); + stats_->setWindow(Rectangle(window.size())); inputBufferCount_ = inputCfg.bufferCount; outputBufferCount_ = outputCfg.bufferCount; /* Configure for one pass */ - PassConfig rawSensorIn = { inputCfg.size, inputConfig_.stride, inputPixelFormat_, window_ }; + PassConfig rawSensorIn = { inputCfg.size, inputConfig_.stride, inputPixelFormat_, window }; PassConfig rgbaOut = { outputCfg.size, outputConfig_.stride, outputPixelFormat_, Rectangle(nativeOutputSize_) }; gpuIspShaderPassDemosiac_.configure(rawSensorIn, rgbaOut); diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.h b/src/libcamera/software_isp/software_isp_instance_gpu.h index 4a9de99ad..695fbd8d5 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.h +++ b/src/libcamera/software_isp/software_isp_instance_gpu.h @@ -79,7 +79,6 @@ private: unsigned int outputBufferCount_; Size nativeOutputSize_; - Rectangle window_; std::unique_ptr stats_; eGL egl_; uint32_t width_; From patchwork Wed Nov 18 09:57:14 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: 28969 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 C6C93BDE17 for ; Wed, 18 Nov 2026 09:58:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5E1776A8BD; Wed, 18 Nov 2026 10:58:02 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="AN2Z1L7x"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3D37B6A8AA for ; Wed, 18 Nov 2026 10:57:56 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-48e09aa5264so371949f8f.2 for ; Wed, 18 Nov 2026 01:57:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995876; x=1795600676; 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=8of6o73sNzdiL69kdCd/SEtGC2WiEnG/3dU1ojuwP3c=; b=AN2Z1L7xNiXHLj5MU6uIi5rwkp65BVnNLo6kpPhqGfzsxRsqDakRjbTuoAbU1BgND5 a0ijozEkrl5/du7B1VREPSXkihsoLC5MxQBxp/b1eD6QS40sCzdI16/7rBgKcHUzWbfk LpgRx1+gGR1uNRyK423CKK6YbFI1/OaxgANgqh5q3Od7yDgdNO0wZhTDX3L7nF5LF3Sm H0Q5U40cS4/aEk/xQdktxbWSI0rwsT2mVUYH36+pukaYTPs+RxZ3SXoSyjXo2JMzuqQi 8UEXQl6On5U37qbvpLHa4giLRI4Ej/tHyySlriSCWZWZRv6eVma+u9sSiLiFUpPwEtJx er0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995876; x=1795600676; 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=8of6o73sNzdiL69kdCd/SEtGC2WiEnG/3dU1ojuwP3c=; b=CGJEVKCHlMW3WOKNhuTpD3w/v7QNUI5/6pTzn4TKINFfobdQnbMKdd9OfLsml4x0dx toFjOquqReV+gQAL821Z7lS7P9phao9XDqwzFztpsFL2MzcMgP6oKqsg6P7mgZX9IHrp fIAGxwMM88alRmF1SGsyIgTbgFKC6BPEiDp9FZkF4xiSN2Hd/wfPAGqRwUZBGwSFjKL/ 68JMZ2c6Xf2YmcKysRKiqE2N+OMaEmSLNKLqhSUSiVXUO7NaA7uIjzOty75zt5mTwVc2 EEBuZCxZnUOsrbkk9t+u81m94ZOkEG4nbX67xGRPgm8kiUdFzZ1t1sFAiG2pR2g7ADAy ZibA== X-Gm-Message-State: APuU4Z/jpiomFEtY4ugHx+7sUXRIkJr+xuGLGGqjcF2o9WUBlXPSbXXv RZKQAm8D9Jam7YuiiCBrjuheputs2tYNrRe0ng3ISB/Ob2qVOm6UnEFNhXMfm4KSzNwl1vBrGbq 3d7MyH8k= X-Gm-Gg: AZFdTZc7u4ZzmsQIHL9XG6MavsUzMWwsv+PCsnwmQQm8U2ic/3LONy360RyoatxW09k mCtWYY2awmd9RbeVbEUUVx9jPknXzxqP5O1+COAyzdREfszWKoEtamQDtYwZ3GUElNkYyQmzNvC vo+MbTw6LMxRmVC4c+48zdV/daxZTT0soGQlKGl6ZHP9tCfbV5bhbFAiUnycfavG0le2aFbJOjT rUINYQm8aQmUoOl0Kr0E92BYgtyENBxj8QNzwsiTCCFUv5DcvaXSFeL0BBq0OmEhjST2ItIK1q3 OlKBRjyD7wLWO66t2qgcGqJjWBObNpvAou2HJKfNK28U9aB2EDhPq6YAYmm3Wfmh79bjrQvkvdn 4w048lqUBlEdifn6jsT8uQGE3ef/DeVpg3FNZFA4paj6M9R5h79gnOWNoRd2kHF3qtD5r+VHU4v koD95nuzyx+yb7f7I7H/9RqjAZKQbAResE5nCNOOVBmwhW32fnfsCCwDjxR3XSVg8ojF3lClzFc gqwldpeX/+bJvVRvX1pIOPyrR4rdXumAkVAO0fWXLg/Si1IybuWGCzgm3uf8weo5F7biS8uQ4LV 5eqIMEIFMzBS5uobdq3F2Q5Whn6AGQuaVl1/jDY+m2yIcQ== X-Received: by 2002:adf:f4d2:0:b0:48d:b940:af7a with SMTP id ffacd0b85a97d-4a63c656d42mr3626649f8f.55.1794995875614; Wed, 18 Nov 2026 01:57:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:55 -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 07/26] libcamera: software_isp: gpu_pipeline_shader_pass: Move common attribute and uniform variables to base shader class Date: Wed, 18 Nov 2026 10:57:14 +0100 Message-ID: <20261118095735.170587-8-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" Every shader pass will want to set these variables so define them in the base class not in the demosiac class. Render therefore unto Cesar the things which are Cesar's. Signed-off-by: Bryan O'Donoghue --- .../software_isp/gpu_pipeline_shader_pass.h | 13 +++++++++++++ .../gpu_pipeline_shader_pass_demosiac.h | 10 ---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass.h b/src/libcamera/software_isp/gpu_pipeline_shader_pass.h index 5e3748621..9611edc84 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass.h +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass.h @@ -80,6 +80,19 @@ protected: struct PassConfig passInputCfg_; struct PassConfig passOutputCfg_; + + /* Common shader attributes */ + GLint attributeVertex_; + GLint attributeTexture_; + GLint textureUniformProjMatrix_; + GLint textureUniformBayerDataIn_; + GLint textureUniformStrideFactor_; + uint32_t shaderStridePixels_; + + /* Bayer shader parameters - useful to potentially more than one shader */ + GLint textureUniformBayerFirstRed_; + float firstRed_x_; + float firstRed_y_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h index 97f84d444..a4c0befe6 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h @@ -44,18 +44,8 @@ public: const char *name() const override { return "GpuIspShaderPassDemosiac"; } private: /* Shader parameters */ - float firstRed_x_; - float firstRed_y_; - GLint attributeVertex_; - GLint attributeTexture_; GLint textureUniformStep_; GLint textureUniformSize_; - GLint textureUniformStrideFactor_; - GLint textureUniformBayerFirstRed_; - GLint textureUniformProjMatrix_; - GLint textureUniformBayerDataIn_; - - uint32_t shaderStridePixels_; /* Per-frame AWB gains */ GLint awbUniformDataIn_; From patchwork Wed Nov 18 09:57:15 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: 28970 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 D5A7EBDE17 for ; Wed, 18 Nov 2026 09:58:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9B3F46A8CC; Wed, 18 Nov 2026 10:58:03 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="PSb/Gh1W"; 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 2FF766A8C5 for ; Wed, 18 Nov 2026 10:57:57 +0100 (CET) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-48e20ed3b9dso590217f8f.2 for ; Wed, 18 Nov 2026 01:57:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995877; x=1795600677; 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=RsCFamd1JtNr5jFpHSlJbCoyxEcTyhVNIuFwv5M61G8=; b=PSb/Gh1Wjr4/vwv2afsi5ENXUFojO0LmdrTJROO0/MpOdd9xyCOyqN8iDPRuOX1tah ZPzRLc8f755Meowny9nfYxfaH9ZCZcnewGWKrZbqhyyiAzKDDdQkGFOAdgXNb79zVqhS ccbX6AuzON5IMY4shf2+QtPROqxMiC5ktmU/0AJRVG6R2tEGUOBB9CQX3qdIHHAvWLPu HcCr/d61lezG0styoXmN+Q9dq5ji6h5F93mlyb1sOWDv0FZ9KiIVeNNawz+wJXSVPVV3 BxcCr94/BGTwZSM8RRpNn4eDenT1N5z3QjRBzbGO5f2/G2lNkA8AkE76sxoRLkKaAFoz SbYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995877; x=1795600677; 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=RsCFamd1JtNr5jFpHSlJbCoyxEcTyhVNIuFwv5M61G8=; b=FXO4vnQUdUmAf4N70ZcYUTuBqaKa4am738CX1clTdX8PXuFJzNaQ0/ZGRiMWJv+Y64 oqWefGtg/qlNpMoovHPoA2p79Ket4cogiCLuoN1wxAXBzh+WsWfZH5v7v3UsCuSjeZUm 6hSSlqx6liM9hV2Ary0akv0NxMY07xWZmmCzTJuNd2PuAFB8tR3RnzgEblQVS0PW+pNZ FmPuUZrWGxQ+4DyaeRk/Cd+hfZZiJXTpSTuXwQtyak8PTTzAvzFVIQgHeKmTM2Bj4GAb V2MAdWhNTT8OxV+GGLbDsjH4yAuTACRMc1pBZS+TGcXQiYzaIoGl+IsWbSP9xXyDqPtN 3qvA== X-Gm-Message-State: APuU4Z8wdLTcYT7pL7aqIa3pQgRy0/AEOvUJP4Req44FiZ78TsokzhQK EFn4OqzeEcv7jt4Ehw0whFoQvau9xs42yrUrVZM53/OePVHYcsc4mx+nr8TzFfHvrieJ3aGWtnr q/OMlT/c= X-Gm-Gg: AZFdTZdviJGwwsXAvEgvLcxQqBI4P8IkPFpHob9VgapNxvdx60uyeLHX8MdJ2g/aOgi EnC5QwX7EZiwQABv6q8TgUkSpdqSGkPSBEHNmEY0KQISI+axvkSfE6ju41LHb5THde8ZOI0Xn5s z1WmiEga1jwzZQsCeMtFFWG334mA7pt8QUOBiWynxZHrbVi1L+mdqJ1gNwP7/M76BS5jHlcwjL0 CL35R/ej7U2TQJvfmApexK0Z4AruP8vy8a0l0D2Womygk95Vk4VbMbeOTxhVecV8cbHDAFFZ9kQ /DhnsBxyuDpqNSGPwOtZfXg7I1KHfle+78GkDC3NuNELR/Hza55IiNwGGavNBN0SMoRr7vA/klG aGqeACcfl65yBB+k+qpwfL8R5gcFAImVLLFyVEQTAYJ6E4Vwx9JyOQhRCcODqTdL2vUHrh6n+us S6EgIcVxGWTthwFBFcDV1SDtQ5KAM0k6asybq8OcnespAsNlxYe/pQcE2ZhVTxUBQPWfFSBYQDA bSJfMTKsA/Uj0wY2jeu27nv3lYZ7zSByGMfOsD0U1RZsSyQqSjIXtVEliec+09uBfXdcFFnLDRH yYyOpXm2LfCUkunKqW/HPNKANBK7Q/6uLCFLB0y8Y46T2g== X-Received: by 2002:a05:6000:29ca:b0:493:2eb8:e7d2 with SMTP id ffacd0b85a97d-4a63a98b0d3mr2961980f8f.41.1794995876606; Wed, 18 Nov 2026 01:57:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:56 -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 08/26] libcamera: software_isp: gpu_pipeline_shader_pass: Move common shader selection logic into base class in new method initShaders() Date: Wed, 18 Nov 2026 10:57:15 +0100 Message-ID: <20261118095735.170587-9-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" Shader initialisation has some common and some pass-specific logic that needs to happen. - Common: Environment setup such as defining top-level defines as flags to include features when compiling shaders. This will have to be consistent from one shader feeding the next. - Shader specific: Selecting which vertex, fragment and potentially compute shaders to run - populating the shader compile environment with any defines specific to that shader. - Common: Compiling and linking a shader program. Error checking and associating a compiled vertex/fragment or compute shader with a given programId_. Move the common code to the base class and have the base class call out to a pure virtual funtion that the derived class must implement. In this way GpuIspShaderPass::initShaders() calls the derived class GpuIspShaderPassDerivedClass::selectShader() while encapsulating that call in the afore mentioned common pieces of logic. Signed-off-by: Bryan O'Donoghue --- .../software_isp/gpu_pipeline_shader_pass.cpp | 100 +++++++++++++++ .../software_isp/gpu_pipeline_shader_pass.h | 9 +- .../gpu_pipeline_shader_pass_demosiac.cpp | 119 +++--------------- .../gpu_pipeline_shader_pass_demosiac.h | 2 +- 4 files changed, 124 insertions(+), 106 deletions(-) diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass.cpp b/src/libcamera/software_isp/gpu_pipeline_shader_pass.cpp index 241ea5d8d..faea7666c 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass.cpp +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass.cpp @@ -76,4 +76,104 @@ void GpuIspShaderPass::configure(const struct PassConfig &passInputCfg, const st passOutputCfg_ = passOutputCfg; } +int GpuIspShaderPass::initShaders(PixelFormat inputFormat, PixelFormat outputFormat) +{ + struct ShaderConfig shaderCfg; + GLenum err; + int ret; + + /* Target gles 100 glsl requires "#version x" as first directive in shader */ + egl_.pushEnv(shaderCfg.shaderEnv, "#version 100"); + + /* Specify GL_OES_EGL_image_external */ + egl_.pushEnv(shaderCfg.shaderEnv, "#extension GL_OES_EGL_image_external: enable"); + + /* + * Tell shaders how to re-order output taking account of how the pixels + * are actually stored by EGL. + */ + switch (outputFormat) { + case formats::ARGB8888: + case formats::XRGB8888: + break; + case formats::ABGR8888: + case formats::XBGR8888: + egl_.pushEnv(shaderCfg.shaderEnv, "#define SWAP_BLUE"); + break; + default: + LOG(GpuShaderPass, Error) << "Unsupported output format"; + return -EINVAL; + } + + 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: + LOG(GpuShaderPass, Error) << "Unsupported input format"; + return -EINVAL; + }; + + ret = selectShaders(shaderCfg, inputFormat, outputFormat); + if (ret) { + LOG(GpuShaderPass, Error) << "selectShaders fail"; + return ret; + } + + LOG(GpuShaderPass, Info) << "ShaderPass = " << typeid(this).name(); + + if (egl_.compileVertexShader(vertexShaderId_, shaderCfg.vertexShaderData, + shaderCfg.shaderEnv)) { + LOG(GpuShaderPass, Error) << "Compile vertex shader fail"; + return -ENODEV; + } + utils::scope_exit vShaderGuard([&] { glDeleteShader(vertexShaderId_); }); + + if (egl_.compileFragmentShader(fragmentShaderId_, shaderCfg.fragmentShaderData, + shaderCfg.shaderEnv)) { + LOG(GpuShaderPass, Error) << "Compile fragment shader fail"; + return -ENODEV; + } + utils::scope_exit fShaderGuard([&] { glDeleteShader(fragmentShaderId_); }); + + if (egl_.linkProgram(programId_, vertexShaderId_, fragmentShaderId_)) { + LOG(GpuShaderPass, Error) << "Linking program fail"; + return -ENODEV; + } + + egl_.dumpShaderSource(vertexShaderId_); + egl_.dumpShaderSource(fragmentShaderId_); + + /* Ensure we set the programId_ */ + glUseProgram(programId_); + err = glGetError(); + if (err != GL_NO_ERROR) { + LOG(GpuShaderPass, Error) << "Use program error " << err; + return -ENODEV; + } + + return getShaderVariableLocations(); +} + } diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass.h b/src/libcamera/software_isp/gpu_pipeline_shader_pass.h index 9611edc84..29aa4b852 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass.h +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass.h @@ -41,6 +41,12 @@ struct PassConfig { Rectangle window; }; +struct ShaderConfig { + std::span fragmentShaderData; + std::span vertexShaderData; + std::vector shaderEnv; +}; + class GpuIspShaderPass : public Object { public: @@ -51,7 +57,8 @@ public: virtual int start(); virtual void stop(); virtual void configure(const struct PassConfig &passInputCfg, const struct PassConfig &passOutputCfg); - virtual int initShaders(PixelFormat inputFormat, PixelFormat outputFormat) = 0; + virtual int initShaders(PixelFormat inputFormat, PixelFormat outputFormat); + virtual int selectShaders(struct ShaderConfig &shaderCfg, PixelFormat &inputFormat, PixelFormat &outputFormat) = 0; virtual int getShaderVariableLocations(void) = 0; virtual void setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) = 0; virtual const char *name() const { return "GpuIspShaderPass"; } diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp index 8c46e5795..458d4c02c 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp @@ -35,97 +35,39 @@ namespace libcamera { LOG_DEFINE_CATEGORY(GpuShaderDemosiac) -int GpuIspShaderPassDemosiac::initShaders(PixelFormat inputFormat, PixelFormat outputFormat) +int GpuIspShaderPassDemosiac::selectShaders(struct ShaderConfig &shaderCfg, [[maybe_unused]]PixelFormat &inputFormat, [[maybe_unused]]PixelFormat &outputFormat) { - std::span fragmentShaderData; - std::span vertexShaderData; - std::vector shaderEnv; - GLenum err; - - /* 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"); - /* LSC flag */ if (lscEnabled_) - egl_.pushEnv(shaderEnv, "#define APPLY_LSC"); - - /* - * Tell shaders how to re-order output taking account of how the pixels - * are actually stored by EGL. - */ - switch (outputFormat) { - case formats::ARGB8888: - case formats::XRGB8888: - break; - case formats::ABGR8888: - case formats::XBGR8888: - egl_.pushEnv(shaderEnv, "#define SWAP_BLUE"); - break; - default: - LOG(GpuShaderDemosiac, Error) << "Unsupported output format"; - return -EINVAL; - } + egl_.pushEnv(shaderCfg.shaderEnv, "#define APPLY_LSC"); /* Pixel location parameters */ glFormat_ = GL_LUMINANCE; bytesPerPixel_ = 1; shaderStridePixels_ = passInputCfg_.stride; - 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: - LOG(GpuShaderDemosiac, Error) << "Unsupported input format"; - return -EINVAL; - }; - /* Shader selection */ switch (inputFormat) { case libcamera::formats::SBGGR8: case libcamera::formats::SGBRG8: case libcamera::formats::SGRBG8: case libcamera::formats::SRGGB8: - fragmentShaderData = bayer_unpacked_frag; - vertexShaderData = bayer_unpacked_vert; + shaderCfg.fragmentShaderData = bayer_unpacked_frag; + shaderCfg.vertexShaderData = bayer_unpacked_vert; 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"); + egl_.pushEnv(shaderCfg.shaderEnv, "#define RAW10P"); if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { - fragmentShaderData = bayer_unpacked_frag; - vertexShaderData = bayer_unpacked_vert; + shaderCfg.fragmentShaderData = bayer_unpacked_frag; + shaderCfg.vertexShaderData = bayer_unpacked_vert; glFormat_ = GL_RG; bytesPerPixel_ = 2; } else { - fragmentShaderData = bayer_1x_packed_frag; - vertexShaderData = identity_vert; + shaderCfg.fragmentShaderData = bayer_1x_packed_frag; + shaderCfg.vertexShaderData = identity_vert; shaderStridePixels_ = passInputCfg_.size.width; } break; @@ -133,50 +75,20 @@ int GpuIspShaderPassDemosiac::initShaders(PixelFormat inputFormat, PixelFormat o case libcamera::formats::SGBRG12_CSI2P: case libcamera::formats::SGRBG12_CSI2P: case libcamera::formats::SRGGB12_CSI2P: - egl_.pushEnv(shaderEnv, "#define RAW12P"); + egl_.pushEnv(shaderCfg.shaderEnv, "#define RAW12P"); if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { - fragmentShaderData = bayer_unpacked_frag; - vertexShaderData = bayer_unpacked_vert; + shaderCfg.fragmentShaderData = bayer_unpacked_frag; + shaderCfg.vertexShaderData = bayer_unpacked_vert; glFormat_ = GL_RG; bytesPerPixel_ = 2; } else { - fragmentShaderData = bayer_1x_packed_frag; - vertexShaderData = identity_vert; + shaderCfg.fragmentShaderData = bayer_1x_packed_frag; + shaderCfg.vertexShaderData = identity_vert; shaderStridePixels_ = passInputCfg_.size.width; } break; }; - if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, - shaderEnv)) { - LOG(GpuShaderDemosiac, Error) << "Compile vertex shader fail"; - return -ENODEV; - } - utils::scope_exit vShaderGuard([&] { glDeleteShader(vertexShaderId_); }); - - if (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData, - shaderEnv)) { - LOG(GpuShaderDemosiac, Error) << "Compile fragment shader fail"; - return -ENODEV; - } - utils::scope_exit fShaderGuard([&] { glDeleteShader(fragmentShaderId_); }); - - if (egl_.linkProgram(programId_, vertexShaderId_, fragmentShaderId_)) { - LOG(GpuShaderDemosiac, Error) << "Linking program fail"; - return -ENODEV; - } - - egl_.dumpShaderSource(vertexShaderId_); - egl_.dumpShaderSource(fragmentShaderId_); - - /* Ensure we set the programId_ */ - glUseProgram(programId_); - err = glGetError(); - if (err != GL_NO_ERROR) { - LOG(GpuShaderDemosiac, Error) << "Use program error " << err; - return -ENODEV; - } - if (lscEnabled_) { constexpr unsigned int gridSize = DebayerParams::kLscGridSize; constexpr unsigned int stride = gridSize * DebayerParams::kLscBytesPerCell; @@ -186,8 +98,7 @@ int GpuIspShaderPassDemosiac::initShaders(PixelFormat inputFormat, PixelFormat o egl_.createTexture2D(*eglImageLscLookup_, nullptr, GL_LINEAR); } - return getShaderVariableLocations(); - + return 0; } int GpuIspShaderPassDemosiac::getShaderVariableLocations(void) diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h index a4c0befe6..47ac8f7e2 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h @@ -34,9 +34,9 @@ public: GpuIspShaderPassDemosiac(eGL& egl) : GpuIspShaderPass(egl) {}; /* Things that every ISP pipeline pass will need to do */ - int initShaders(PixelFormat inputFormat, PixelFormat outputFormat) override; int getShaderVariableLocations(void) override; void setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) override; + int selectShaders(struct ShaderConfig &shaderCfg, PixelFormat &inputFormat, PixelFormat &outputFormat) override; void setLscEnabled(bool enabled) { lscEnabled_ = enabled; } void stop() override; From patchwork Wed Nov 18 09:57:16 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: 28971 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 A6311BDE17 for ; Wed, 18 Nov 2026 09:58:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1A7016A8D9; Wed, 18 Nov 2026 10:58:07 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="xOP2L5kz"; 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 94BDB6A8C8 for ; Wed, 18 Nov 2026 10:57:58 +0100 (CET) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-49465892f7bso535191f8f.1 for ; Wed, 18 Nov 2026 01:57:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995878; x=1795600678; 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=BTcx1UeBLlSMGaXkloThBotj5wVQaiibN+Q3tG4VB/8=; b=xOP2L5kzg9XlluICmJeRSRn+qfTlC8juyZ0Xwf/Fvk1zkgrH/hvcMfKUgqEpraEhiD fa5phwg268ZmBF7dQdTt0BzEr98OpJH79US+sWNyG1zNgePO4gG0/TvZsJkpF5vrG2wn ZtNzZr9Xz7w2Q85DzsQFhXbsg4jCuEvWuk1bEMWW+tZuHxhgulvOFvH5kRL4Spb2QH8h D0oID5oQF4p0sYpqRWqUeisEyLDv5B924Vd9nuCK4kYapqwa/Q86ABytFas2mMXQwpN4 Bg41L5p8wIVE7SZ/CJ8jjXj3OEaQWw7DjMz4BxA9DTQiTQlWenaQFl6845W5pctdj9e4 +Fwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995878; x=1795600678; 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=BTcx1UeBLlSMGaXkloThBotj5wVQaiibN+Q3tG4VB/8=; b=Q0b5peGSlRuaGCf7GrdBUIXJRsbYZ7zmet1dBYStnzBXso3PInCItOIfws4nCURq5g Gy9pycZI5hTvzSCrD5nNbafsuKdkVpigcDO2QuAA3aFj0+wV4JCz8ocPezt7m5/UowQ9 GOvnc7jFAlxYbM3sV87jxbwPQ3ISzBlCEGCX6aOtlHLRHBsTQ8MRZC7/YV1nIty88SHX qxeGvhI4TfKSZ27hPiwTOpgJ0Azzc3K3XCPqMKx4JGM421xrfj8STRuJil0Q3EUSOgHU ZqorFzR0fNb7Gcq2YJEXYqcYFBtePwB1k3LQT3yGhJa7016GzknJbOF2YMuWx7afPR7Q 4fVA== X-Gm-Message-State: APuU4Z+aNvlOdTasLEAycyPklpDJGAwX7DzVpEnCMIXpKK/OO2Btd/pJ L+tZJaJ/chLIjDTgJp+PFHDYs4wZft2ITvZ9ZXBZ3gSS4zQ+NsR5ecBBRva+E7gop2VyI2qLut+ Mx2WX/0I= X-Gm-Gg: AZFdTZdcrq9I5lnlOuCfGj/q0fq5SNPY6k+qmk2hfCfd/zFPAkrxCuUFTOCVI3fK8bo c3ySzlT2eirDINf1IWmeBXf01FkasLI7/6qkkh7K3nBRKuRY0cYhuBDMFQAfHOQbp+Bd6GTLi/N tny5+J1LyLOf543xYbtC/XLn3Gt3h8RVJbyf3/b5RCnOycyiuM9KslaSX9n+66DMxOJ29x7DOue fwSQaOZhqJLJzTZKT5yco5Tki3eQtOcTkOtnIGeP6YkyiLy6/6GComUjyrDHdDvP7QZftFKMuds i3Tbd+l8CUz+2yMeY7a4kh7e3fgZD/YBSClAejHlUiB536XGZuMJ4A6SH5S2dGPRpxI8o+a7LXG 5336cqxkqANKfExgRe1MiKP+R+9yPBh20SZshxl5bg5/4Dn/qXEUhZS3TxVMKxvH/jlRiec/wqZ WWwLLsF6jiwoEiI9jf0MkCxZCfmoF4fQ7fukZkz480p95Sj9aFCi07tzrem2EEVWexfIQn9B7NO i52jurRUIcQFSZf+yqz+GIQ6fIuNLwZfLfjIKJIWFF2O51Zby8wYql4DrddEMiY8bFwxb3ig7BQ yuZ8c3AOn4fdyqOFVAygn84SNA+vCwmazSSMKiAHweEqzw== X-Received: by 2002:a05:6000:41c9:b0:48d:ba3b:af36 with SMTP id ffacd0b85a97d-4a63b9d9524mr4088685f8f.37.1794995877792; Wed, 18 Nov 2026 01:57:57 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:57 -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 09/26] libcamera: shaders: Split packed and unpacked demosiac up Date: Wed, 18 Nov 2026 10:57:16 +0100 Message-ID: <20261118095735.170587-10-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" Take the existing bayer_1x_packed.frag and split it up so that the texture2D() sampling happens in a first pass shader whose job it is to normalise the data-stream to GLR16F output. Thus far we have had two shaders for packed and unpacked MIPI streams which also differ in how they demosiac nearest-neighbour v bilinear. This is alot of maintenance we shouldn't really have to do and means that for reasons we don't seem to have chosen you get different demosiac quality if you have a packed or unpacked input stream. With a two-pass system though we can have the first shader pass produce a standard 16 bit float intermediary framebuffer which the subsequent pass can then demosiac. This lets us use the same code irrespective of the incoming MIPI stream which is obviously the right thing to do from a design/maintenance POV. Signed-off-by: Bryan O'Donoghue --- .../shaders/bayer_1x_packed_to_glr16f.frag | 93 +++++++++ .../shaders/bayer_glr16f_to_rgba.frag | 183 ++++++++++++++++++ .../shaders/bayer_unpacked_to_glr16f.frag | 46 +++++ src/libcamera/shaders/meson.build | 3 + 4 files changed, 325 insertions(+) create mode 100644 src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag create mode 100644 src/libcamera/shaders/bayer_glr16f_to_rgba.frag create mode 100644 src/libcamera/shaders/bayer_unpacked_to_glr16f.frag diff --git a/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag b/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag new file mode 100644 index 000000000..57814dc49 --- /dev/null +++ b/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag @@ -0,0 +1,93 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Based on the code from http://jgt.akpeters.com/papers/McGuire08/ + * + * Copyright (c) 2008, Morgan McGuire. All rights reserved. + * + * Modified by Linaro Ltd for 10/12-bit packed raw Bayer format. + * Copyright (C) 2020, Linaro + * + * precursor_packed.frag - Precursor shader to decode MIPI packed raw Bayer + * data and output normalised single-channel float to an R16F FBO. + * Pairs with identity.vert. + */ + +#ifdef GL_ES +precision highp float; +#endif + +/* + * These constants are used to select the bytes containing the HS part of + * the pixel value: + * BPP - bytes per pixel, + * THRESHOLD_L = fract(BPP) * 0.5 + 0.02 + * THRESHOLD_H = 1.0 - fract(BPP) * 1.5 + 0.02 + * Let X is the x coordinate in the texture measured in bytes (so that the + * range is from 0 to (stride_-1)) aligned on the nearest pixel. + * E.g. for RAW10P: + * -------------+-------------------+-------------------+-- + * pixel No | 0 1 2 3 | 4 5 6 7 | ... + * -------------+-------------------+-------------------+-- + * byte offset | 0 1 2 3 4 | 5 6 7 8 9 | ... + * -------------+-------------------+-------------------+-- + * X | 0.0 1.25 2.5 3.75 | 5.0 6.25 7.5 8.75 | ... + * -------------+-------------------+-------------------+-- + * If fract(X) < THRESHOLD_L then the previous byte contains the LS + * bits of the pixel values and needs to be skipped. + * If fract(X) > THRESHOLD_H then the next byte contains the LS bits + * of the pixel values and needs to be skipped. + */ +#if defined(RAW10P) +#define BPP 1.25 +#define THRESHOLD_L 0.14 +#define THRESHOLD_H 0.64 +#elif defined(RAW12P) +#define BPP 1.5 +#define THRESHOLD_L 0.27 +#define THRESHOLD_H 0.27 +#else +#error Invalid raw format +#endif + +varying vec2 textureOut; + +/* the texture size in pixels */ +uniform vec2 tex_size; +uniform vec2 tex_step; + +uniform sampler2D tex_y; + +void main(void) +{ + /* + * center_bytes holds the coordinates of the MS byte of the pixel + * being sampled on the [0, stride-1/height-1] range. + * center_pixel holds the coordinates of the pixel being sampled + * on the [0, width/height-1] range. + */ + vec2 center_bytes; + vec2 center_pixel; + + /* + * The coordinates passed to the shader in textureOut may point + * to a place in between the pixels if the texture format doesn't + * match the image format. In particular, MIPI packed raw Bayer + * formats don't have a matching texture format. + * In this case align the coordinates to the left nearest pixel + * by hand. + */ + center_pixel = floor(textureOut * tex_size); + center_bytes.y = center_pixel.y; + + /* + * Add a small number (a few mantissa's LSBs) to avoid float + * representation issues. + */ + center_bytes.x = BPP * center_pixel.x + 0.02; + center_bytes.x = floor(center_bytes.x); + center_bytes *= tex_step; + + float C = texture2D(tex_y, center_bytes).r; + + gl_FragColor = vec4(C, 0.0, 0.0, 0.0); +} diff --git a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag new file mode 100644 index 000000000..f3883a82b --- /dev/null +++ b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag @@ -0,0 +1,183 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* +From http://jgt.akpeters.com/papers/McGuire08/ + +Efficient, High-Quality Bayer Demosaic Filtering on GPUs + +Morgan McGuire + +This paper appears in issue Volume 13, Number 4. +--------------------------------------------------------- +Copyright (c) 2008, Morgan McGuire. All rights reserved. + +Modified by Linaro Ltd to integrate it into libcamera. +Copyright (C) 2021-2026, Linaro +*/ + +//Pixel Shader +#ifdef GL_ES +precision highp float; +#endif + +/** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/ +uniform sampler2D tex_y; +varying vec4 center; +varying vec4 yCoord; +varying vec4 xCoord; +uniform mat3 ccm; +uniform float gamma; +uniform float contrastExp; + +float apply_contrast(float value) +{ + // Apply simple S-curve + if (value < 0.5) + return 0.5 * pow(value / 0.5, contrastExp); + else + return 1.0 - 0.5 * pow((1.0 - value) / 0.5, contrastExp); +} + +void main(void) { + vec3 rgb; + + /* Sample from R16F input texture */ + #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r + + float C = fetch(center.x, center.y); // ( 0, 0) + const vec4 kC = vec4( 4.0, 6.0, 5.0, 5.0) / 8.0; + + // Determine which of four types of pixels we are on. + vec2 alternate = mod(floor(center.zw), 2.0); + + vec4 Dvec = vec4( + fetch(xCoord[1], yCoord[1]), // (-1,-1) + fetch(xCoord[1], yCoord[2]), // (-1, 1) + fetch(xCoord[2], yCoord[1]), // ( 1,-1) + fetch(xCoord[2], yCoord[2])); // ( 1, 1) + + vec4 PATTERN = (kC.xyz * C).xyzz; + + // Can also be a dot product with (1,1,1,1) on hardware where that is + // specially optimized. + // Equivalent to: D = Dvec[0] + Dvec[1] + Dvec[2] + Dvec[3]; + Dvec.xy += Dvec.zw; + Dvec.x += Dvec.y; + + vec4 value = vec4( + fetch(center.x, yCoord[0]), // ( 0,-2) + fetch(center.x, yCoord[1]), // ( 0,-1) + fetch(xCoord[0], center.y), // (-2, 0) + fetch(xCoord[1], center.y)); // (-1, 0) + + vec4 temp = vec4( + fetch(center.x, yCoord[3]), // ( 0, 2) + fetch(center.x, yCoord[2]), // ( 0, 1) + fetch(xCoord[3], center.y), // ( 2, 0) + fetch(xCoord[2], center.y)); // ( 1, 0) + + // Even the simplest compilers should be able to constant-fold these to + // avoid the division. + // Note that on scalar processors these constants force computation of some + // identical products twice. + const vec4 kA = vec4(-1.0, -1.5, 0.5, -1.0) / 8.0; + const vec4 kB = vec4( 2.0, 0.0, 0.0, 4.0) / 8.0; + const vec4 kD = vec4( 0.0, 2.0, -1.0, -1.0) / 8.0; + + // Conserve constant registers and take advantage of free swizzle on load + #define kE (kA.xywz) + #define kF (kB.xywz) + + value += temp; + + // There are five filter patterns (identity, cross, checker, + // theta, phi). Precompute the terms from all of them and then + // use swizzles to assign to color channels. + // + // Channel Matches + // x cross (e.g., EE G) + // y checker (e.g., EE B) + // z theta (e.g., EO R) + // w phi (e.g., EO R) + #define A (value[0]) + #define B (value[1]) + #define D (Dvec.x) + #define E (value[2]) + #define F (value[3]) + + // Avoid zero elements. On a scalar processor this saves two MADDs + // and it has no effect on a vector processor. + PATTERN.yzw += (kD.yz * D).xyy; + + PATTERN += (kA.xyz * A).xyzx + (kE.xyw * E).xyxz; + PATTERN.xw += kB.xw * B; + PATTERN.xz += kF.xz * F; + + 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)); + + /* + * 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]); + + /* + * Contrast + */ + rgb = clamp(rgb, 0.0, 1.0); + rgb.r = apply_contrast(rgb.r); + rgb.g = apply_contrast(rgb.g); + rgb.b = apply_contrast(rgb.b); + + /* Apply gamma after colour correction */ + rgb = pow(rgb, vec3(gamma)); + + #if defined (SWAP_BLUE) + gl_FragColor = vec4(rgb.bgr, 1.0); + #else + gl_FragColor = vec4(rgb, 1.0); + #endif +} diff --git a/src/libcamera/shaders/bayer_unpacked_to_glr16f.frag b/src/libcamera/shaders/bayer_unpacked_to_glr16f.frag new file mode 100644 index 000000000..00ed47ce8 --- /dev/null +++ b/src/libcamera/shaders/bayer_unpacked_to_glr16f.frag @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Based on the code from http://jgt.akpeters.com/papers/McGuire08/ + * + * Copyright (c) 2008, Morgan McGuire. All rights reserved. + * + * Modified by Linaro Ltd to integrate it into libcamera. + * Copyright (C) 2021, Linaro + * + * precursor_unpacked.frag - Precursor shader to decode unpacked raw Bayer + * data (R8, RG8 with split 10/12-bit values) and output normalised + * single-channel float to an R16F FBO. + * Pairs with identity.vert. + */ + +#ifdef GL_ES +precision highp float; +#endif + +varying vec2 textureOut; + +uniform sampler2D tex_y; + +void main(void) +{ + /* + * Reconstruct the pixel value from the texture format. + * + * For RAW10P the 10-bit value is split across two 8-bit channels: + * value = R / 4.0 + G * 64.0 + * For RAW12P the 12-bit value is split across two 8-bit channels: + * value = R / 16.0 + G * 16.0 + * Otherwise the value is a plain single-channel sample. + */ +#if defined(RAW10P) + vec4 p = texture2D(tex_y, textureOut); + float C = p.r / 4.0 + p.g * 64.0; +#elif defined(RAW12P) + vec4 p = texture2D(tex_y, textureOut); + float C = p.r / 16.0 + p.g * 16.0; +#else + float C = texture2D(tex_y, textureOut).r; +#endif + + gl_FragColor = vec4(C, 0.0, 0.0, 1.0); +} diff --git a/src/libcamera/shaders/meson.build b/src/libcamera/shaders/meson.build index c409ff9b0..8483e169e 100644 --- a/src/libcamera/shaders/meson.build +++ b/src/libcamera/shaders/meson.build @@ -3,6 +3,9 @@ # List of shader files to convert to header hex # for the purposes of inclusion in OpenGL debayering shader_files = files([ + 'bayer_1x_packed_to_glr16f.frag', + 'bayer_unpacked_to_glr16f.frag', + 'bayer_glr16f_to_rgba.frag', 'bayer_1x_packed.frag', 'bayer_unpacked.frag', 'bayer_unpacked.vert', From patchwork Wed Nov 18 09:57:17 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: 28972 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 1FE1BBDE17 for ; Wed, 18 Nov 2026 09:58:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D0186A8E1; Wed, 18 Nov 2026 10:58:10 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="nY9HBaKR"; 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 568576A8B1 for ; Wed, 18 Nov 2026 10:57:59 +0100 (CET) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-491f34b4e0fso292796f8f.2 for ; Wed, 18 Nov 2026 01:57:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995879; x=1795600679; 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=Y7APu1C+L8EW4xuPBVaUkON2MnXXNCiVAjDyQZBHTH8=; b=nY9HBaKRtbAQrJ6SJ1zr1OtfAdMlx4Yr8g533zhXbtinx/b0VEyX9sVEzXnZEyRQo8 k9XXZuPysmtydUDwlfNNb3V7hlLkjtUyNblWXJE22WSUSAj5OW/+xIOeMtp16IGpjjqe zHzvVKxUTs040OTbZyPcVUkljn/o+KOHwmdChb3aKglCGYIGkbxeg9C9NhpGtTJ7guge inp1BEMLP+Ohf+kzjyuo+KWABNFs/4NyT5sdAtKxsTojYXb7zeUMovQKnL3aFnYEeUuC M9t+ysfDwo4W4OKp7tlLurznqp4ZmWkLXGol40Kn+HmYhHddUWlLu9DNgIni71qb76Tm BRrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995879; x=1795600679; 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=Y7APu1C+L8EW4xuPBVaUkON2MnXXNCiVAjDyQZBHTH8=; b=ARUdjyO4WQozOCfcejdnOCRpHLCTSRDamPkmp9bbqltLecJSM/1Lx7mMMhVNEsPTor 0BThkt7z6x5zAhar4mQJBEcONVnTuOKvd2UwgX+m4sLhvMiPt2HZmc35ESDyzlvr8Zz0 kiAqcvMhQYM6EBEfeGnt5QvxVznFx+D9HZdJpcLDH3l9LMCLizVm2wWh8wxn139eIHTL X++TVm2AQ2rBvACiiO48UfYoPRZ3vFXUSMmfAhwtHOu3th6imYxUqTn2JCWOSI/IUDaV R5P1ideNbLh7fw9HwKXAPV8cxGMcc3YPmLyUq2F4jhTzp7fkfSHiwuiZOVZm5eXzdtEP fDkQ== X-Gm-Message-State: APuU4Z9LdJD5YivMxzQnI/SILCLAA6I37EbyMBdoqNASLv5qvNLHK1KL qbtw2nKJTV113CGkY13wGLoLNNrxN/kodrVsHmiekzid46Q8+suap2iNzNbeCjTbkIZdOaIhZlA QoWwNkjY= X-Gm-Gg: AZFdTZfVtHNpjX9iw1yHe/ZMIP10NHFZ5VSaz1QGGW3nqa5mJ8mod+upakEiGRualh0 wK2kI3QpOlOvlhOILuMgnO43lg/A7kG4/Jqi9gxiorymdIoZsZZoNobKNN4AjgCC8sbF0S+ZOPk 7kWX59HqSNQORlTr3YSLmH4Ig5oO1cyjG1RVt3qmrsCi8jXoz+sJZbYFz8G/YcgRvqNO+DhHf2f 0KsmDpymhN9WfLw0FPKqvLDjjdOY01uDbNkMrUSJHzKAkWkSPVAox7kdd78l+Cy+2Yp9rBQX5p5 JwoqsTp4E6aMpSF+IqDLbSINzejvmj+pj35lnIzhSZjCGwF1MUtQetk3noxmXcoitbpg3823X8y 3HPro+SndSwrp1NtHsXuhuG8hsnkckzft23xx4s6ntv+h3hBnLplY7cGm5h2noBA0rA1AeTblTg g8Ce8XcqOXSANAKeWgaN645C4kZQVgPMMUDkupw+eOK8guuYkUgTzF5DHCVX2O7XOS2j6vTBnDK hechczJki9jdJqKODXQynAhYeZjgVH9ZteczIC1291FkCkqynEp9JVj1aZM0NIR1ZxbBEWIYRO4 pNOVojpNpdNOym4bYxO6fu7v54Ys/vd1WdufwL4pNcYqFj+ARaBcsOOcJvJ3dfH1lCM= X-Received: by 2002:a5d:5f51:0:b0:4a7:b365:19dd with SMTP id ffacd0b85a97d-4a7b3651a4dmr1175849f8f.53.1794995878731; Wed, 18 Nov 2026 01:57:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:58 -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 10/26] libcamera: shaders: bayer_glr16_to_rgba.frag: Use bilinear filtering Date: Wed, 18 Nov 2026 10:57:17 +0100 Message-ID: <20261118095735.170587-11-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" To create the multi-pass shader we used the bayer_1x_packed.frag and broke it into chunks. This original neighbour uses nearest-neighbour interpolation however the unpacked shader bayer_unpacked.frag has a nicer bilinear algorithm we can use instead. Replace the interpolation with the unpacked.frag version. Signed-off-by: Bryan O'Donoghue --- .../shaders/bayer_glr16f_to_rgba.frag | 114 +++++++----------- 1 file changed, 43 insertions(+), 71 deletions(-) diff --git a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag index f3883a82b..4a2e5af87 100644 --- a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag +++ b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag @@ -44,81 +44,53 @@ void main(void) { #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r float C = fetch(center.x, center.y); // ( 0, 0) - const vec4 kC = vec4( 4.0, 6.0, 5.0, 5.0) / 8.0; - // Determine which of four types of pixels we are on. + /* Which of the four CFA phases are we on (0 = even). Same as McGuire. */ vec2 alternate = mod(floor(center.zw), 2.0); + bool even_col = alternate.x < 1.0; + bool even_row = alternate.y < 1.0; - vec4 Dvec = vec4( - fetch(xCoord[1], yCoord[1]), // (-1,-1) - fetch(xCoord[1], yCoord[2]), // (-1, 1) - fetch(xCoord[2], yCoord[1]), // ( 1,-1) - fetch(xCoord[2], yCoord[2])); // ( 1, 1) - - vec4 PATTERN = (kC.xyz * C).xyzz; - - // Can also be a dot product with (1,1,1,1) on hardware where that is - // specially optimized. - // Equivalent to: D = Dvec[0] + Dvec[1] + Dvec[2] + Dvec[3]; - Dvec.xy += Dvec.zw; - Dvec.x += Dvec.y; - - vec4 value = vec4( - fetch(center.x, yCoord[0]), // ( 0,-2) - fetch(center.x, yCoord[1]), // ( 0,-1) - fetch(xCoord[0], center.y), // (-2, 0) - fetch(xCoord[1], center.y)); // (-1, 0) - + /* + * +----+----+----+ + * | D2 | A1 | D3 | + * +----+----+----+ + * | B0 | C | B1 | + * +----+----+----+ + * | D0 | A0 | D1 | + * +----+----+----+ + * + * patterns.x = (A0 + A1) / 2 vertical neighbours + * patterns.y = (B0 + B1) / 2 horizontal neighbours + * patterns.z = (A0+A1+B0+B1) / 4 cross average (green at R/B sites) + * patterns.w = (D0+D1+D2+D3) / 4 diagonal average (other colour at R/B sites) + * + * xCoord[1] = -1, xCoord[2] = +1, yCoord[1] = -1, yCoord[2] = +1 + * (xCoord[0]/[3] and yCoord[0]/[3] = +-2 are unused here; the vertex + * shader still emits them so the VS is identical to the McGuire path). + */ + vec4 patterns = vec4( + fetch(center.x, yCoord[1]), /* A0: ( 0,-1) */ + fetch(xCoord[1], center.y), /* B0: (-1, 0) */ + fetch(xCoord[1], yCoord[1]), /* D0: (-1,-1) */ + fetch(xCoord[2], yCoord[1])); /* D1: ( 1,-1) */ vec4 temp = vec4( - fetch(center.x, yCoord[3]), // ( 0, 2) - fetch(center.x, yCoord[2]), // ( 0, 1) - fetch(xCoord[3], center.y), // ( 2, 0) - fetch(xCoord[2], center.y)); // ( 1, 0) - - // Even the simplest compilers should be able to constant-fold these to - // avoid the division. - // Note that on scalar processors these constants force computation of some - // identical products twice. - const vec4 kA = vec4(-1.0, -1.5, 0.5, -1.0) / 8.0; - const vec4 kB = vec4( 2.0, 0.0, 0.0, 4.0) / 8.0; - const vec4 kD = vec4( 0.0, 2.0, -1.0, -1.0) / 8.0; - - // Conserve constant registers and take advantage of free swizzle on load - #define kE (kA.xywz) - #define kF (kB.xywz) - - value += temp; - - // There are five filter patterns (identity, cross, checker, - // theta, phi). Precompute the terms from all of them and then - // use swizzles to assign to color channels. - // - // Channel Matches - // x cross (e.g., EE G) - // y checker (e.g., EE B) - // z theta (e.g., EO R) - // w phi (e.g., EO R) - #define A (value[0]) - #define B (value[1]) - #define D (Dvec.x) - #define E (value[2]) - #define F (value[3]) - - // Avoid zero elements. On a scalar processor this saves two MADDs - // and it has no effect on a vector processor. - PATTERN.yzw += (kD.yz * D).xyy; - - PATTERN += (kA.xyz * A).xyzx + (kE.xyw * E).xyxz; - PATTERN.xw += kB.xw * B; - PATTERN.xz += kF.xz * F; - - 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)); + fetch(center.x, yCoord[2]), /* A1: ( 0, 1) */ + fetch(xCoord[2], center.y), /* B1: ( 1, 0) */ + fetch(xCoord[2], yCoord[2]), /* D3: ( 1, 1) */ + fetch(xCoord[1], yCoord[2])); /* D2: (-1, 1) */ + + patterns = (patterns + temp) * 0.5; + /* .x=(A0+A1)/2 .y=(B0+B1)/2 .z=(D0+D3)/2 .w=(D1+D2)/2 */ + patterns.w = (patterns.z + patterns.w) * 0.5; /* diagonal avg */ + patterns.z = (patterns.x + patterns.y) * 0.5; /* cross avg */ + + rgb = even_col ? + (even_row ? + vec3(C, patterns.zw) : + vec3(patterns.x, C, patterns.y)) : + (even_row ? + vec3(patterns.y, C, patterns.x) : + vec3(patterns.wz, C)); /* * CCM is a 3x3 in the format From patchwork Wed Nov 18 09:57:18 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: 28974 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 BF275BDE17 for ; Wed, 18 Nov 2026 09:58:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 481FE6A8D8; Wed, 18 Nov 2026 10:58:14 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="RzbEt1Ti"; dkim-atps=neutral Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 124FB6A8C7 for ; Wed, 18 Nov 2026 10:58:00 +0100 (CET) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-48e3b22e971so345889f8f.0 for ; Wed, 18 Nov 2026 01:58:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995879; x=1795600679; 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=BN4LTS/k0y6tXF/ATICS4zHlVufchr5Lxm0QV4AgHrc=; b=RzbEt1Ti4eGYtf1qL/xFRN/05YbYtiC/K/HugXE6kejHF5jpY4QuClEVNuvnGMJCtH TmU8iRhZUtPhyX2Us/gcbEW9JAvL3Gni8Vw+WiPZtvAAuvgEznwILEyVar/3h+4GulPH ZITywacrjaGtZa5IoYddA0GhCQu7/elr/xeeJLnvkmGxpjuB3sGBBHKgFAUn6CTPctRv wMYNJUJc2jIYF/6wccf0oNkT5a/skkPhMICspO8UE+zAgClpxuk508JlXGhApEyK8xSO BgU+Mr6uwfbNVLEWMprJbIcPRyb/uFt4l2Nfo3A6KeubjjYbcuTL03OWt8gG5LG22YFk ZZRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995879; x=1795600679; 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=BN4LTS/k0y6tXF/ATICS4zHlVufchr5Lxm0QV4AgHrc=; b=u5SmaAX/ShpLlrQKmGD7LIjwvzM00jBGoxdYPMeVLVX4LmdfWk5EhGhG8LAA+M1Y4e 4LvPhEzSxGULwgfrTbw1Qppdv0Dj+d3zdZUA7iZAC37UNhDaQbjqKRmbyAxvnm9GCgiq gwYZgETHhzhC1xRxIQHoV3taSKlJzNFerTSdRmGym7ex+/BbQ1V8qG8IcM4sFmzlNZqS Ih/3IIrEK6LXvYM+3HqTOEjFU0x4Oq/vgvfZLd+Xigj+hl4Emto6tDVm0mHkXsuaLkAO uKmTCoRCQA/YzWaH7hZKmIG03xNQUrPZrV/xg5qOOn+DYohtyW7kgQTNBPpejUPC7d2N urdQ== X-Gm-Message-State: APuU4Z8xhmlq7eLoVsOaICMo//NgX7fSuNRwwhWZ2n3uU3NiaAi908Hw O6+fS+bVfPWrFaQ6PgGfiC9MDRhSlo91rTFLJGjf7DIurdJ6sVVWg0rJ2D/P5h6cXMAYSNeITvU PBltTtBk= X-Gm-Gg: AZFdTZfMQdXnrUL5+JguVf6NQNY70fBd9xQMR4eyMZGwN8RdfHhExtrbKN1bTORlsDE 5FCtD/SeoqrW1j/b50BgOTuLUCmqhKXTcQS3C5JRM5ft1D5B1j+Xm5hxswP/2UdYvzN4v7KaFsJ 11edrBPauy3q+5xFjvE8HUvETgHwKpqbhHyLyvD1sYmjK34paMgyHIA6zHGwvYyD2WPLOb9cGZe lj59wYHQ37RlKxBY3sXtBb9EoBKkzA0a6PgTbLOBwoCTMQ6/QMxA0Ig6rso+F2TF/piSCgQ9e7o EDOLgYxYevLtgnaUvse7Gy0qxfAPGsbwJYT3Uh+Qaa7EB9BG3htbkjy+Q4VzdZsIs3hRtYEsJyZ 6Ax767D5pXdH5rKy/KmAI3AeZCsR2sQDzKtNNjqb6/rOIGPB6a7Xs0q7mEjn3+gHKah9RZ8MeIK VoFkokrcyJFA14FdO1aPmKDzH979R3Cli0/viDdIaro8Zv1o9jT9NryGrUCgbi2FpqCpYhjCziR lVRQ3+4HnGl5bcoRmbTKZjiJcfGqX4dog5E8NaUPxj8oa1j6oQT+WEYG/NuALEEN0mrpIORKvYM 5lZTTw2u2MjO+5no3c2+aiSlRKlZ0V/PVoiUalfmt76llQ== X-Received: by 2002:a5d:6f19:0:b0:491:286f:8e63 with SMTP id ffacd0b85a97d-4a639940d10mr4663747f8f.14.1794995879577; Wed, 18 Nov 2026 01:57:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:59 -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 11/26] libcamera: shaders: bayer_{1x_packed|unpacked}_to_glr16f.frag: Add blacklevel correction to bayer domain shaders Date: Wed, 18 Nov 2026 10:57:18 +0100 Message-ID: <20261118095735.170587-12-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" We want to do our black level correction in the bayer not the RGB domain. Implement the BLC in the first-pass Bayer domain shaders. Signed-off-by: Bryan O'Donoghue --- src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag | 4 ++++ src/libcamera/shaders/bayer_unpacked_to_glr16f.frag | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag b/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag index 57814dc49..418a9e063 100644 --- a/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag +++ b/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag @@ -55,6 +55,8 @@ varying vec2 textureOut; uniform vec2 tex_size; uniform vec2 tex_step; +uniform vec3 blacklevel; + uniform sampler2D tex_y; void main(void) @@ -89,5 +91,7 @@ void main(void) float C = texture2D(tex_y, center_bytes).r; + C = (C - blacklevel[0]) / (1.0 - blacklevel[0]); + gl_FragColor = vec4(C, 0.0, 0.0, 0.0); } diff --git a/src/libcamera/shaders/bayer_unpacked_to_glr16f.frag b/src/libcamera/shaders/bayer_unpacked_to_glr16f.frag index 00ed47ce8..dadfbd5e2 100644 --- a/src/libcamera/shaders/bayer_unpacked_to_glr16f.frag +++ b/src/libcamera/shaders/bayer_unpacked_to_glr16f.frag @@ -19,6 +19,8 @@ precision highp float; varying vec2 textureOut; +uniform vec3 blacklevel; + uniform sampler2D tex_y; void main(void) @@ -42,5 +44,7 @@ void main(void) float C = texture2D(tex_y, textureOut).r; #endif + C = (C - blacklevel[0]) / (1.0 - blacklevel[0]); + gl_FragColor = vec4(C, 0.0, 0.0, 1.0); } 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, From patchwork Wed Nov 18 09:57:20 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: 28975 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 E9A06BDE17 for ; Wed, 18 Nov 2026 09:58:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3CA0D6A8DD; Wed, 18 Nov 2026 10:58:15 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="G1nIG0c5"; 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 3CFA26A8BB for ; Wed, 18 Nov 2026 10:58:02 +0100 (CET) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4a2153c8525so5707095e9.3 for ; Wed, 18 Nov 2026 01:58:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995882; x=1795600682; 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=oMLh/FIhxkunl1diVPilsxfc7As/nKsyOr2DfYKotSw=; b=G1nIG0c5zd2+Q36wnRh+4bD+UpOLLU8VVNn/tAveQILODzNziw9T1FbqQkeDgIjyRe Ho0kZevusdy9wo3ux/DSVIh4FPdnGJgaOhwXWA/V15hdGWy8/1opzifz0lG1MdLeh4el XY7gmlSBB2PhWrvknv/CxJrJKJ7RG6Pl4/VDXvmEPxlovEHohpnNtXJVsYn5ITpwO0xa C2dE2doFGJwgAHnAZHNjwHzRRJ6i7aEINvKf56CUd+rz2doGkU7u5zG1ZTkc11x2mZRf YyqobRJCVxTvjtWvqGxCzgedSOX/UsR4KaP86+K9Xxe3CM5SFLpGPf/+zIuQ4OtaxvNj g+zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995882; x=1795600682; 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=oMLh/FIhxkunl1diVPilsxfc7As/nKsyOr2DfYKotSw=; b=Wz3KlqKc81XjRQHJ0Qf0hRx3q+MThr2Dz27ADrhSyzbyk9JK2bDTcHnTAiDC2w6viz mSCHb/sfIehCEGcYWYbBnFms3IXB6lhpHTEq5S583j0MbkqhY+qVei3IJP+AnnmbcGmA dNqDD2Y/Txzf/56qgEeykECxBF7gMx3Ejd3Z2jqRt76lCiE8Ql4qnHq+Kucsl/EfXlU5 r8nYxzXn28GyC3c1y+OU0vKia5Ukv8e95DR0lKcRgSqkH3hCsLHxgFEKghgGhIBSutT1 n14c+nwf81VlCYAaK34pAQ4YBq2UYL4CZSRZZFNJ+GFsSJdODsAn4zcPGNChmUg7B3ck /+Yg== X-Gm-Message-State: APuU4Z9KpsLfKjBR9oEgEm2rsLAxJBCjGbkGDMA2LBbs5xys8AFxlf0e W6+Zo2MQWzk2c61ZEG0G6chMj/h3qE022m23IN5SG5gmzyA2irAEfc62Kw1WZAzIGNhVAVXnteP Gu7awvSs= X-Gm-Gg: AYBFou3HIGAvvLSWcwfjtV+84zNa1AlCwUldj+3pD5FlbSAfEKgQOwQy7MnZEHULbb9 wO7R9u1XSCew1S2cV91Jj4eKpxDCpofGxq2KYgnziBYNj2ZbWfF1scV2Cd+p5ad4bLFRbANwyk5 zFBvaRYSptxKKptLVOX88XPupZQASRvUW9SLA7fVbzsjnCTEkvf4LEQdfsm8eI2adIE7o1hzyiW SVvIF1W6u0/ZpL8LIjZUuUpvwflj83vPKlX1BXG/gfdA5TI80XnDDGfsoPSnd8cpU/qGYjvfOT0 0qWql/FYdumUTTvoeF+3AmFbQaroOz2Fl/uq15jgh9YrKlnh+EkNcvr27ZVJVG+qrgNVPjBZV2c gX1tXQqE0UQDmJ58x1kDJ61Mrvog4Ydgkvhk+6V7PjUS7qmS2szbjS60vSwadtdzLARHCBS1gwv esLBWQCRTc2ahbcp8sbPsF89HG7mLcTQ6Q6LEcTnpRWhrvzzkc5ObvfeYcMAGEq0Z1dba1xJrHD C6lLuaTxBC9f1E+Dkc9rwovoThtZro1JW4LHtYP2sMsRTwdwyz7CxnT+DohcxBZALMO24xBVUaS LNOKcJh06+JjeBeHVNm5UulHo5/jQdU1xad+QWXjaLir7g== X-Received: by 2002:a05:600c:b99:b0:4ba:6d8:dfad with SMTP id 5b1f17b1804b1-4bb7da1aa22mr36743825e9.14.1794995881584; Wed, 18 Nov 2026 01:58:01 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:01 -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 13/26] libcamera: software_isp: egl: Extend eGL::createTexture2D to understand floats Date: Wed, 18 Nov 2026 10:57:20 +0100 Message-ID: <20261118095735.170587-14-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" Signed-off-by: Bryan O'Donoghue --- src/libcamera/egl.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index ff9e54a19..b5337ccd7 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -288,12 +288,31 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd) */ void eGL::createTexture2D(eGLImage &eglImage, const void *data, GLint filter) { + GLenum format; + GLenum type = GL_UNSIGNED_BYTE; + assertThread(); activateBindTexture(eglImage); + switch (eglImage.format_) { + case GL_R16F: + format = GL_RED; + type = GL_HALF_FLOAT; + break; + case GL_RG8: + format = GL_RG; + break; + case GL_LUMINANCE: + format = GL_LUMINANCE; + break; + default: + LOG(eGL, Error) << "Unsupported texture format " << eglImage.format_; + return; + } + // Generate texture, bind, associate image to texture, configure, unbind - glTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, eglImage.format_, GL_UNSIGNED_BYTE, data); + glTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, format, type, data); // Nearest filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); From patchwork Wed Nov 18 09:57:21 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: 28976 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 9F3C1BDE17 for ; Wed, 18 Nov 2026 09:58:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ACD956A8D5; Wed, 18 Nov 2026 10:58:16 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ZlLYC/Zg"; 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 439D26A8C4 for ; Wed, 18 Nov 2026 10:58:03 +0100 (CET) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-492690dd5daso527982f8f.1 for ; Wed, 18 Nov 2026 01:58:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995883; x=1795600683; 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=c8RUvlmpAN9QONOJLKGBt/PTTZXJVrwK7+Zl+r8/8Ck=; b=ZlLYC/ZgXbSlkAvlU8Lkqfg6CH+bDvDWCIU0htGqjD2JNfz6OwAObJTz1wWGYjLmAi y+FybUZnE8JQNPJmPKG/UzOaeNrLSBu9KYWNob29vzY2gvPzR5LMmwWj0JVYABI1XxoT HzyrxZwgZxF79vUediohOj2Lp3+IgNtHM9GyvPMaGFJAwqWU8zwRuDo2NwA7gPHw/AHP oht45KLKmjMczG5C+Ni9mzL4Bfzauqy84EpRHfvbIm7XUCyaFx1tf2ttGWTE5al04EnN m5QrI9r5aEJD3Z8dfmYmn8ldLOd9qO2FaHb53trbDqD8lDdF0eg48ujraOVzB53OhoaM ebgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995883; x=1795600683; 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=c8RUvlmpAN9QONOJLKGBt/PTTZXJVrwK7+Zl+r8/8Ck=; b=YllHLEHigfNxZf7PTpb4R28ajVVf/SrcWx9vGd3qvQsA7ffDRspFeSl6E54Ni6Vc/a LnofWJcihC+xRIhcWAQeDRXvJFViAYfPn9x8KetM/N+amSadW7QBy1IVUX1Sl9INSXei PXU9CxeKxCTxWz25RoXeOq1VNWy8vL88HZ0zMqbUbtYy/CxpIhQbpgbn/OO0n7jsXp0h 6HcWRXEBSdQgYqr6X7yyzYQbQYtt7A6QL7bwYzfL4Cr0dguq/H7EmE5ANkRqDoZS0WOE bkTQhi3ZLK1B3yJ1gkKkf5c+riTE2D9/qKKXVLHszMGJ6qyAfeGUrKqS/+AT0aXcpXxr RO1w== X-Gm-Message-State: APuU4Z9I7KF/b1Lm18HyYMtu8w6qNFexBNgfIALEVLmUrdBjZhzKUkTA 7XpZwCGXweQDPT7mEvzQblYlgAQMf+SVOrU7pZ7QyTTwkAo/PnECzgzMFJAK2HYt33UqVxHmjeE R2y3qDWc= X-Gm-Gg: AZFdTZcErjDNMqPU9ZvxjTZvmc3+CEBkKl9w+z+09sN43B12SmsI6SCMKJ9YJ/ECOAs SGbRIhJmCrAIPNRXxWXdDAD2L/u8oo9Zfu1Y2/mcp8Pzuuvr8YW98z8/GeRCVkSL5fDFH1wIVYl 5w6uLrFFXneoARdMo7bnDjxjwbPehJnKhwk1Y1Q/Q5Tv6P1RiKwToZd7z6F1rdJPhrI5at9CGeW oRxa5rEBclUF93KCIQJNTBx/X623X41i9bk3tDcMCEMZD0gLpjCOd6tvQN2OUbkxpyQ4UD8a+pa QyPjb4j6tCFEDraVIOj2YvD7Av5SgVJowzOlJKx6sfSCf9gpHCu5x3DbFdb6XnPXbj3qsBmhv93 Kx60xibu7O8eMXsxZXcDgyt2uOvdh8dlYF+7n+SQCB6VwiAZaZ0Cxi6OCPPOjstDaovCFM64Lij XkHscsZEq/5BkBUx0qmKRv4XfBBOjF6XLBYPBVjZhtXc2ImYnELOMvV+6nf8dSlAqwYUDzqwFvs tLRkxYkxndOgNGCfwLywdqMBpeD5Kyh/l7q1HQ01T5DrDr27GQZnQfsWrYiRMFn6TrtMOq+eewI HBCqIK8Dqww99Gy90tMoHOxbSBSbGnOjm0Yi15HuAVjVDQ== X-Received: by 2002:a05:6000:4812:b0:491:49c2:3b3 with SMTP id ffacd0b85a97d-4a63bea7c57mr4419991f8f.51.1794995882763; Wed, 18 Nov 2026 01:58:02 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:02 -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 14/26] libcamera: software_isp: egl: Use Texture Unit 3 for final output texture Date: Wed, 18 Nov 2026 10:57:21 +0100 Message-ID: <20261118095735.170587-15-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" We will use ping/pong buffers as intermediary steps in the GPUISP pipeline. The last texture should logically be texture unit #3. TEXTURE0 = Input TEXTURE1 = Ping TEXTURE2 = Pong TEXTURE3 = Output We don't have ping/pong yet but in preparation make the small change to TEXTURE3 for the existing output framebuffer. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/software_isp_instance_gpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.cpp b/src/libcamera/software_isp/software_isp_instance_gpu.cpp index 5c473948c..31b57d2a0 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.cpp +++ b/src/libcamera/software_isp/software_isp_instance_gpu.cpp @@ -292,7 +292,7 @@ eGLImage *SoftwareIspInstanceGpu::getCachedOutputFrameBuffer(FrameBuffer *output } eglImageOutCache_.emplace_back(fd, std::make_unique(GL_RGBA, outputSize_.width, - outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1)); + outputSize_.height, outputConfig_.stride, GL_TEXTURE3, 3)); eglImageOut = eglImageOutCache_.back().second.get(); if (egl_.createOutputDMABufTexture2D(*eglImageOut, output->planes()[0].fd.get())) { From patchwork Wed Nov 18 09:57:22 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: 28977 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 CD9C1BDE17 for ; Wed, 18 Nov 2026 09:58:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4E6D96A8EB; Wed, 18 Nov 2026 10:58:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="qf+0cjrt"; 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 8BFF96A8CE for ; Wed, 18 Nov 2026 10:58:04 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4b467581b98so8969695e9.0 for ; Wed, 18 Nov 2026 01:58:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995884; x=1795600684; 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=OvVj1MPSIuvxR3EjJvzP8Vaao2f2RfJ+Xkp/Rxj9hXs=; b=qf+0cjrtjISVGSeN5qwVdaQzbysyduS3LQYTi6z0DGivFC/cUNuDIz9GCp/VLEwMs+ Q9q37b4MVu2vY9DBfH4TwsqoO6Qe/QPFVXPy7Cs3x9bHoyBczhwuzB/TJX6HQRwUbXQR 9Eb47bMKQUTHhn2S33zfd+0CGva8VxVe1a5q5iYPlixHLHtZhZJiRN99LBQgYQ1Q5V9n dqZUyboOoJP0i3CcZL/bS9D0IERXX9R2Sa1Cw5pcg3imDB4nT8Jb9k4joWANnDY9kNte vpp5Pa1O/nKu7WUrkSjQKv0ZtkC6SJs+DduAFjJns4BGDLnpKajQ2URsMk2U3JMhwzKx Nwhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995884; x=1795600684; 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=OvVj1MPSIuvxR3EjJvzP8Vaao2f2RfJ+Xkp/Rxj9hXs=; b=NTt5hr9dAi/gtUYOAxPpz0vnx+up8pmAJgtJUYH+a1nYPkw1D0cVNM4PE9Af+Mce3Q kpd2hfj5wa6HMKBZ+A4WttLZtC/SekCHatHWSKHPQyfSESPpxZwh0+LxEq9VAl6h+Td7 Nng90dL6uGXnXZLD79gUYmdq1xENlTtkXxZFlEbXUHruX/ANfbAn6FLxzN7vsFxIXdGz 5GXXlGFR8lUJHWlLWIvRhcG17PKq+thGl4sSzeSbPDf9oI0IQXDBsWZ3l8YIo/cpO5a+ Ha21MLVpEUq2oeDjHujMTMr0P2UQPrLQMr9VH2nKx+XG+s7on9qQnTzkb1wTQ3EKVk8S 311A== X-Gm-Message-State: APuU4Z+YqK1B5gNj0wMPRUPN1UTus4MnSmRMb6XQLoPTpIaSp5Tdod9u UnSraAlOjeruuxFNqdbUu5Knb9+V0KZ2HVxOkk1ejQ9sJ3Scly1AWUosKurzJdk2R7lKFcuJzKJ fY5Gh7yc= X-Gm-Gg: AYBFou3+XnBrbiG5ICIUagJlMvo/AacPtrtiDzyI5/5P9s/8cNk1Xwh5hmsCVgjUQDA 1Je8EDcwOc//RZpQEeRfJxNRnhiDFMw64O9EoLXhnC44ECjUKydfIe/Rka2Ik1DGrW3II3xq5BI kvhX4084j2X6tpIcrXePv96vqCblKFDuySmBzuCoGpPCybhNujuh8mlBttDgx8HiI6RWw7f8/Bx +nzLz0wKzFVARml3iCSvwzBsu/jzUR//UwpcJNdfg21V/asmzkQTi4IMJ0sbH4+2o8Hml4p+1iU KXwT9aH5K/2VNsFE2rFuye8r/kWJuLoLg8KxTuqirmNer8BZtIhG0OPkuu9QNmWD5Byu7Iu19XX yi8likxVd15ewJAxqu7KAXG8u94EjVsIHoxbpaI+FSYVykb49r/uj9OMxsIVrC779ic/VvNK39r 9YrqJH5cw+izAhyMIdeHTVTQY1Kpv0HeApkYny2z0jsLdw/s1jFnz2Fnobmx1Y91gK5x/DofygF 2NPuiyVkz3v29s/korIP+t/TyFMpBNLFvUJ6J6V95X/YQzi8G287pDEKu51qnKcH3CT/3FSaNRt R8o+6hLcl03Wt5+8lUMzZRvYdQOkjV+5y6a2KE0WzQE9toM= X-Received: by 2002:a05:600c:8b8b:b0:4a6:30c3:1114 with SMTP id 5b1f17b1804b1-4bb7da19d2emr34245245e9.12.1794995884024; Wed, 18 Nov 2026 01:58:04 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:03 -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 15/26] libcamera: software_isp: egl: Add Ping/Pong buffers with start/stop bindings only Date: Wed, 18 Nov 2026 10:57:22 +0100 Message-ID: <20261118095735.170587-16-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" Add in the Ping/Pong texture buffers, don't bind them to anything yet. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/software_isp_instance_gpu.cpp | 6 ++++++ src/libcamera/software_isp/software_isp_instance_gpu.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.cpp b/src/libcamera/software_isp/software_isp_instance_gpu.cpp index 31b57d2a0..85820b267 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.cpp +++ b/src/libcamera/software_isp/software_isp_instance_gpu.cpp @@ -389,6 +389,10 @@ int SoftwareIspInstanceGpu::start() if (initBayerShaders(inputPixelFormat_, outputPixelFormat_)) return -EINVAL; + /* Intermediary ping/pong textures */ + eglImagePingPong_[0] = std::make_unique(gpuIspShaderPassDemosiac_.glFormat_, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); + eglImagePingPong_[1] = std::make_unique(gpuIspShaderPassDemosiac_.glFormat_, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE2, 2); + return 0; } @@ -396,6 +400,8 @@ void SoftwareIspInstanceGpu::stop() { eglImageOutCache_.clear(); eglImageInCache_.clear(); + eglImagePingPong_[1].reset(); + eglImagePingPong_[0].reset(); gpuIspShaderPassDemosiac_.stop(); diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.h b/src/libcamera/software_isp/software_isp_instance_gpu.h index 695fbd8d5..9da9e717b 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.h +++ b/src/libcamera/software_isp/software_isp_instance_gpu.h @@ -71,6 +71,8 @@ private: eGLImage *getCachedInputFrameBuffer(FrameBuffer *input, std::optional *inMapped, std::optional *inDmaSyncer); eGLImage *getCachedOutputFrameBuffer(FrameBuffer *output); + /* Pointer to object representing input texture */ + std::unique_ptr eglImagePingPong_[2]; /* Pointer to object representing input texture */ std::deque>> eglImageInCache_; From patchwork Wed Nov 18 09:57:23 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: 28979 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 70B1DBDE17 for ; Wed, 18 Nov 2026 09:58:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A50CF6A8E3; Wed, 18 Nov 2026 10:58:22 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Kv+oseTc"; dkim-atps=neutral Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BB24F6A8BF for ; Wed, 18 Nov 2026 10:58:05 +0100 (CET) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-48dee593f18so582624f8f.3 for ; Wed, 18 Nov 2026 01:58:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995885; x=1795600685; 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=kmd73Zvt6PWfdw34Ciy9RdsHEmOxMQ4QVnZVG/eb6i4=; b=Kv+oseTckpRzTK0Zp8slhNjLHtM+PmN3lPPFpmexDWW+Wp2ZeTK5Sp1UVDpjpFi9E3 dxkXH+xWqLJJmSlmSQJ3TjDjuJkljtLUvqyJTy0BGkUIeiu/b/KvxS1xc8e5fNMtHU6R cH39aVgjROzU+dJpDimbwfKNv62BH9kST1MEMkpuzCygtS651yLAf4dMwS/PdFsFKURY eyFBtnhdPvHlcgfY+js8X7t/yrJt2igbEAu4yl9bvOOFTgbJ7VR9hrin/9YAcTQHWdUW HzIXTa6jUxf8W6aky/Dlt40mEMHlOPoQtLEXoqUOEMc6wZ0GqksLErC6PwwISCtZiEAW UOug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995885; x=1795600685; 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=kmd73Zvt6PWfdw34Ciy9RdsHEmOxMQ4QVnZVG/eb6i4=; b=oCnw5kK+VNnMajSU3KdUKddNRQ7L4SUTfwOZX6k9n5KgjwYnA3cd6tnhgJ8ZUGgfpI SZjoBtal8F+DrZ/SxrlvH8ZzELjx3xAe/mfrdJaRngkFbkfLQ5pmximMQCeGKkC93cTP HPRi/Ffk1N2g4l3axs6YGmXN2/UMRTZxniQfnhl9KhEniuLBy7Ynan1I6f7ebeaWdQTM R9XMS727c898djFGpHLqTXS2Da2gm256JED+x7ZxxEyxxjVa1+F+W3NO7uu+gbOk8O85 ZvYeKm0UZDk+R4DGIDLpnTmebgh6a6kXhJkrlwIkeGQ9vMcym84TimWZUZRvUUr8kokD iyLA== X-Gm-Message-State: APuU4Z+fFZ853WZ0ScnYoOfrze5siSfwF9GpR8X9E2Dgaiza2HTHUnl7 hgoZC24sK+ZCfgruy0BM5RagT1GCzF+MxPUnkmGw1koxxLgNO2+LOrnfg7SCzwBUmY+buANHZbf kbG9eo5M= X-Gm-Gg: AZFdTZd48bQcyJ9ajd4wAKGYfXezoi2epvzDEcnxxDTP1a0NacePUUvO+B1d6U6ZWJD Zho9ahMmKSxZO8eHunQccvbXvJbS22K0Pal43Bjn8yaxeoDC8ENdBHs3Ps++hhEjTu9/8faLYTo KiGoJTy9FonJ3HBz3e8wE/efCIm2NkCzNzrcvrOBW73X7LLdTHyZ0o17GFWCFFA7WaeYa4VEk8F o31PxMXaK+wGz2ZCgSh/Riqx4VMMbYoIFuL4vA7RvKKWhfiV9DNnoZ3VXIMxLect8GL+NBD0wD7 1ZkoXsYnrJaRYxCuBUxIf5LDuzYz9v9FfhKhLb3hWV+d6my3rAKiKMLQSpry1AgXdI0XZTMPKzP Cx+TJixwkNnqu5B+3Ohe4rJ4xfdz7frxO2tNfqpZLlyaBhI2Bg3n2rHM+4A+1UW/Hn/u9GKRCI0 2P4nZpzasihXJuqTkUNmLZSPv91rOwekIkp16USK/cqLyLBhWSdqeJ+Rmqo8CUQsV34/h0gauGy xnhwfbT586XNEh9/SqIDOcVka1aWUXyMs+rX06dItHk1bXJ/VqquSjO1uxTK8j0whks+O+Pg+V2 fIBcGG5HUNXc0HFsnO8pxd05C3cNB1Vwi1mECXwXcKeMiQ== X-Received: by 2002:a5d:5888:0:b0:492:46e:d4ce with SMTP id ffacd0b85a97d-4a63833821emr4143873f8f.13.1794995885242; Wed, 18 Nov 2026 01:58:05 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:04 -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 16/26] libcamera: software_isp: gpu: Include GpuIspShaderPassBlcNormalise in init sequence Date: Wed, 18 Nov 2026 10:57:23 +0100 Message-ID: <20261118095735.170587-17-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" Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/software_isp_instance_gpu.cpp | 8 +++++++- src/libcamera/software_isp/software_isp_instance_gpu.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.cpp b/src/libcamera/software_isp/software_isp_instance_gpu.cpp index 85820b267..ba364516f 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.cpp +++ b/src/libcamera/software_isp/software_isp_instance_gpu.cpp @@ -43,7 +43,7 @@ namespace libcamera { * \param[in] display The EGL display to use */ SoftwareIspInstanceGpu::SoftwareIspInstanceGpu(std::unique_ptr stats, const CameraManager &cm, EGLDisplay display) - : SoftwareIspInstance(cm), stats_(std::move(stats)), egl_(display), gpuIspShaderPassDemosiac_(egl_) + : SoftwareIspInstance(cm), stats_(std::move(stats)), egl_(display), gpuIspShaderPassDemosiac_(egl_), gpuIspShaderPassBlcNormalise_(egl_) { } @@ -99,6 +99,12 @@ int SoftwareIspInstanceGpu::getInputConfig(PixelFormat inputFormat, DebayerInput int SoftwareIspInstanceGpu::initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat) { + int ret; + + ret = gpuIspShaderPassBlcNormalise_.initShaders(inputFormat, outputFormat); + if (ret) + return ret; + return gpuIspShaderPassDemosiac_.initShaders(inputFormat, outputFormat); } diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.h b/src/libcamera/software_isp/software_isp_instance_gpu.h index 9da9e717b..95cbea566 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.h +++ b/src/libcamera/software_isp/software_isp_instance_gpu.h @@ -29,6 +29,7 @@ #include #include "software_isp_instance.h" +#include "gpu_pipeline_shader_pass_blc_normalise.h" #include "gpu_pipeline_shader_pass_demosiac.h" namespace libcamera { @@ -87,6 +88,7 @@ private: uint32_t height_; GpuIspShaderPassDemosiac gpuIspShaderPassDemosiac_; + GpuIspShaderPassBlcNormalise gpuIspShaderPassBlcNormalise_; }; } /* namespace libcamera */ From patchwork Wed Nov 18 09:57:24 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: 28978 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 D3901BDE17 for ; Wed, 18 Nov 2026 09:58:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 78BAA6A8F1; Wed, 18 Nov 2026 10:58:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YKmAqffr"; 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 50C916A8DA for ; Wed, 18 Nov 2026 10:58:07 +0100 (CET) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4a210470b49so6710325e9.2 for ; Wed, 18 Nov 2026 01:58:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995887; x=1795600687; 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=H3yaLXLKrl/tHsPQkdHfE9aVdZPQd0ODo73jt87lwyA=; b=YKmAqffrB75z5aPQWplFeoricPXpA6kJFFyD6VptToOWgiPKqhiD5LfuwERZ49YWZq vvfc+x8mg9vv2P0XcaOKWCUGlCouFqultBuwqurlZPmSUZ1/Yl2mD8EwliGcvLpxs4rc pephqI4ce7tsdw/c3VpIA5QEOrSJhvBOO+ofhqz1CamiV1d3iVjr6P7sIgIAb5tRr2AO AiHcwGp+t0rbbthvGn5n9cPqEI7lEWxkiWlFiI+cb4Z7+cMKBIsKM96xqyrP8F1jd4Qb ecz6mbkLF6ln6nEuXN9ffvITB9ZTqQKbph5ct4sX8rrLd2czon3rRMHeIbOubmFZnSmn tUMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995887; x=1795600687; 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=H3yaLXLKrl/tHsPQkdHfE9aVdZPQd0ODo73jt87lwyA=; b=rsqswf2aSq/7rofgk5EtfVjZ+7/dv4UoNPl55ni+SBIAbc3r0rfJVHgjOgNOJT46Dr ZeD9EWPopovrfCtlxVpLRzbq+ssKBluW/cSdGQtLuB/9IYICR+nB8k8e5mwLeFiozutb glIZYLtXsBO5MgdjfxlH0cLAE2b31C/VOt0a1s3rBTmltclJcVW7tObAutl3cTr362oh SNxpeaDf0qY7X6ZIRqwcN9dgXDxbgV00VSb46WdWoPWGuAMDW4IG6uQYe1ZNOnUXjvoB MYG/6F9rKlxo6vvwI65nMsXimBiJmY+Foo3rBqPI5vS4DJccd5elNboI4m97PRle7Qdm 0SBQ== X-Gm-Message-State: APuU4Z/XsxA7J01d/Xb2AAIsAmQAMMjLymUhmoOZO6CBGH9uA4nLmiw1 gfvqSyG3BYdGsR3XfMHdygaNwAl7oqVYU+h+MGNS4SmW458MjdLY5sUY0s/8ExAL//b3b20cNcD ag+OjQEk= X-Gm-Gg: AZFdTZfCfTnwV2NzNnPo8YCHwsuNcSTXxol+EjKVEs3Wzs4AUWRC6Wuvem6bF/JBlRO oBHxH3uFa/eJ1lTmsgGScP2ZTmaNuY5Qh6l6y3ZBZrT6Rnsm+GZRKjvl0+sW+4PE39GOVf2Y4nt L4v+KGTN2kPtFF/HvrBX9eH53T6pajZL8MrlGGyk4jj86SULBXkOL9FOktVZPV6AuC41TXxTgy7 zHYknNDMwbHaKP8rqR1SQK07pBw9RHEDMid32jFW4Pgws/D+Z5ylzeSW4EjQQifDR3hMW8cSPS8 k8JrQwLit8bf6hltx3lBMFL5gVXM3clsxx8Uhoi1BAq118GT850dou7d+f9VJI41tnu1fdMpiEf 0io8/q23Ye3VuAuCMys+9c7VL5JFq903LFzVrA4SporDw0TLnz+iAtoNl6dyRjAdLtV3Tw52RUU sM9fdckd6CJXf/F2elbK/+LI1XN5GJHkOQZCnu8R5Lc0UBllkfOMNfhLwC4QLKJ31C/0RgWTVm2 zHagdxOZW74GV+6vL+2s9IGST+H9iznhuwvrIeNGwDtZDUwYY65XmIJnk2N5d312aPHGknZqDZT cYHuMHWC+V87tZW+3STc5l3f5MSWq7C69oX8hveuAWfuEw== X-Received: by 2002:a05:6000:2509:b0:4a7:e4c7:2775 with SMTP id ffacd0b85a97d-4a7e4c72812mr730046f8f.45.1794995886710; Wed, 18 Nov 2026 01:58:06 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:05 -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 17/26] libcamera: software_isp: gpu: Swtich to two pass logic Date: Wed, 18 Nov 2026 10:57:24 +0100 Message-ID: <20261118095735.170587-18-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" Signed-off-by: Bryan O'Donoghue --- ...gpu_pipeline_shader_pass_blc_normalise.cpp | 11 ++-- .../gpu_pipeline_shader_pass_demosiac.cpp | 31 ++++------- .../gpu_pipeline_shader_pass_demosiac.h | 3 -- .../software_isp_instance_gpu.cpp | 54 ++++++++++++------- 4 files changed, 50 insertions(+), 49 deletions(-) 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 index 86681061a..c5c19f85d 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.cpp +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.cpp @@ -84,6 +84,8 @@ int GpuIspShaderPassBlcNormalise::selectShaders(struct ShaderConfig &shaderCfg, break; }; + LOG(GpuShaderBlc, Info) << "ShaderPass = " << typeid(this).name() << " selected shader pair "; + return 0; } @@ -95,15 +97,14 @@ int GpuIspShaderPassBlcNormalise::getShaderVariableLocations(void) 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"); + blackLevelUniformDataIn_ = glGetUniformLocation(programId_, "blacklevel"); 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 */ @@ -169,13 +170,11 @@ void GpuIspShaderPassBlcNormalise::setShaderVariableValues(eGLImage &eglImageIn, /* * 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); @@ -185,8 +184,7 @@ void GpuIspShaderPassBlcNormalise::setShaderVariableValues(eGLImage &eglImageIn, << " tex_y " << textureUniformBayerDataIn_ << " tex_step " << textureUniformStep_ << " tex_size " << textureUniformSize_ - << " stride_factor " << textureUniformStrideFactor_ - << " tex_bayer_first_red " << textureUniformBayerFirstRed_; + << " stride_factor " << textureUniformStrideFactor_; LOG(GpuShaderBlc, Debug) << "textureUniformY_ = 0 " << " firstRed.x " << firstRed[0] @@ -202,6 +200,7 @@ void GpuIspShaderPassBlcNormalise::setShaderVariableValues(eGLImage &eglImageIn, * 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; diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp index 458d4c02c..47daa1f1f 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp @@ -42,18 +42,18 @@ int GpuIspShaderPassDemosiac::selectShaders(struct ShaderConfig &shaderCfg, [[ma egl_.pushEnv(shaderCfg.shaderEnv, "#define APPLY_LSC"); /* Pixel location parameters */ - glFormat_ = GL_LUMINANCE; + glFormat_ = GL_R16F; //todo: not all systems support floating point framebuffers so gl_luminance will be default unless indicated by interrogation bytesPerPixel_ = 1; shaderStridePixels_ = passInputCfg_.stride; - /* Shader selection */ + shaderCfg.fragmentShaderData = bayer_unpacked_frag; + shaderCfg.vertexShaderData = bayer_unpacked_vert; + switch (inputFormat) { case libcamera::formats::SBGGR8: case libcamera::formats::SGBRG8: case libcamera::formats::SGRBG8: case libcamera::formats::SRGGB8: - shaderCfg.fragmentShaderData = bayer_unpacked_frag; - shaderCfg.vertexShaderData = bayer_unpacked_vert; break; case libcamera::formats::SBGGR10_CSI2P: case libcamera::formats::SGBRG10_CSI2P: @@ -61,13 +61,9 @@ int GpuIspShaderPassDemosiac::selectShaders(struct ShaderConfig &shaderCfg, [[ma case libcamera::formats::SRGGB10_CSI2P: egl_.pushEnv(shaderCfg.shaderEnv, "#define RAW10P"); if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { - shaderCfg.fragmentShaderData = bayer_unpacked_frag; - shaderCfg.vertexShaderData = bayer_unpacked_vert; glFormat_ = GL_RG; bytesPerPixel_ = 2; } else { - shaderCfg.fragmentShaderData = bayer_1x_packed_frag; - shaderCfg.vertexShaderData = identity_vert; shaderStridePixels_ = passInputCfg_.size.width; } break; @@ -77,13 +73,9 @@ int GpuIspShaderPassDemosiac::selectShaders(struct ShaderConfig &shaderCfg, [[ma case libcamera::formats::SRGGB12_CSI2P: egl_.pushEnv(shaderCfg.shaderEnv, "#define RAW12P"); if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) { - shaderCfg.fragmentShaderData = bayer_unpacked_frag; - shaderCfg.vertexShaderData = bayer_unpacked_vert; glFormat_ = GL_RG; bytesPerPixel_ = 2; } else { - shaderCfg.fragmentShaderData = bayer_1x_packed_frag; - shaderCfg.vertexShaderData = identity_vert; shaderStridePixels_ = passInputCfg_.size.width; } break; @@ -98,6 +90,8 @@ int GpuIspShaderPassDemosiac::selectShaders(struct ShaderConfig &shaderCfg, [[ma egl_.createTexture2D(*eglImageLscLookup_, nullptr, GL_LINEAR); } + LOG(GpuShaderDemosiac, Info) << "ShaderPass = " << typeid(this).name() << " selected shader pair "; + return 0; } @@ -109,26 +103,23 @@ int GpuIspShaderPassDemosiac::getShaderVariableLocations(void) textureUniformBayerDataIn_ = glGetUniformLocation(programId_, "tex_y"); awbUniformDataIn_ = glGetUniformLocation(programId_, "awb"); ccmUniformDataIn_ = glGetUniformLocation(programId_, "ccm"); - blackLevelUniformDataIn_ = glGetUniformLocation(programId_, "blacklevel"); gammaUniformDataIn_ = glGetUniformLocation(programId_, "gamma"); contrastExpUniformDataIn_ = glGetUniformLocation(programId_, "contrastExp"); textureUniformLsc_ = glGetUniformLocation(programId_, "lsc_tex"); - 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"); + textureUniformBayerDataIn_ = glGetUniformLocation(programId_, "tex_y"); + textureUniformStep_ = glGetUniformLocation(programId_, "tex_step"); + textureUniformSize_ = glGetUniformLocation(programId_, "tex_size"); LOG(GpuShaderDemosiac, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ << " tex_y " << textureUniformBayerDataIn_ << " awb " << awbUniformDataIn_ << " ccm " << ccmUniformDataIn_ - << " blacklevel " << blackLevelUniformDataIn_ << " gamma " << gammaUniformDataIn_ << " contrastExp " << contrastExpUniformDataIn_ - << " tex_step " << textureUniformStep_ - << " tex_size " << textureUniformSize_ << " stride_factor " << textureUniformStrideFactor_ << " tex_bayer_first_red " << textureUniformBayerFirstRed_ << " proj_matrix " << textureUniformProjMatrix_; @@ -210,8 +201,6 @@ void GpuIspShaderPassDemosiac::setShaderVariableValues(eGLImage &eglImageIn, con LOG(GpuShaderDemosiac, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ << " tex_y " << textureUniformBayerDataIn_ - << " tex_step " << textureUniformStep_ - << " tex_size " << textureUniformSize_ << " stride_factor " << textureUniformStrideFactor_ << " tex_bayer_first_red " << textureUniformBayerFirstRed_; @@ -240,8 +229,6 @@ void GpuIspShaderPassDemosiac::setShaderVariableValues(eGLImage &eglImageIn, con /* * 0 = Red, 1 = Green, 2 = Blue */ - glUniform3f(blackLevelUniformDataIn_, params.blackLevel[0], params.blackLevel[1], params.blackLevel[2]); - LOG(GpuShaderDemosiac, Debug) << " blackLevelUniformDataIn_ " << blackLevelUniformDataIn_ << " data " << params.blackLevel; glUniform3f(awbUniformDataIn_, params.gains[0], params.gains[1], params.gains[2]); LOG(GpuShaderDemosiac, Debug) << " awbUniformDataIn_ " << awbUniformDataIn_ << " data " << params.gains; diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h index 47ac8f7e2..4d91254a2 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h @@ -53,9 +53,6 @@ private: /* Represent per-frame CCM as a uniform vector of floats 3 x 3 */ GLint ccmUniformDataIn_; - /* Black Level compensation */ - GLint blackLevelUniformDataIn_; - /* Gamma */ GLint gammaUniformDataIn_; diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.cpp b/src/libcamera/software_isp/software_isp_instance_gpu.cpp index ba364516f..13d27ab7a 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.cpp +++ b/src/libcamera/software_isp/software_isp_instance_gpu.cpp @@ -29,6 +29,8 @@ namespace libcamera { +LOG_DEFINE_CATEGORY(SoftwareIspInstanceGpu) + /** * \class SoftwareIspInstanceGpu * \brief Class for debayering using an EGL Shader @@ -91,7 +93,7 @@ int SoftwareIspInstanceGpu::getInputConfig(PixelFormat inputFormat, DebayerInput return 0; } - LOG(SoftwareIspInstance, Debug) + LOG(SoftwareIspInstanceGpu, Debug) << "Unsupported input format " << inputFormat; return -EINVAL; @@ -127,7 +129,7 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg, const Size &stats_pattern_size = stats_->patternSize(); if (inputConfig_.patternSize.width != stats_pattern_size.width || inputConfig_.patternSize.height != stats_pattern_size.height) { - LOG(SoftwareIspInstance, Error) + LOG(SoftwareIspInstanceGpu, Error) << "mismatching stats and debayer pattern sizes for " << inputCfg.pixelFormat; return -EINVAL; @@ -141,7 +143,7 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg, height_ = inputCfg.size.height; if (outputCfgs.size() != 1) { - LOG(SoftwareIspInstance, Error) + LOG(SoftwareIspInstanceGpu, Error) << "Unsupported number of output streams: " << outputCfgs.size(); return -EINVAL; @@ -153,7 +155,7 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg, strideAndFrameSize(outputCfg.pixelFormat, outputCfg.size); if (!outSizeRange.contains(outputCfg.size) || outputConfig_.stride != outputCfg.stride) { - LOG(SoftwareIspInstance, Error) + LOG(SoftwareIspInstanceGpu, Error) << "Invalid output size/stride: " << "\n " << outputCfg.size << " (" << outSizeRange << ")" << "\n " << outputCfg.stride << " (" << outputConfig_.stride << ")"; @@ -182,9 +184,12 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg, /* Configure for one pass */ PassConfig rawSensorIn = { inputCfg.size, inputConfig_.stride, inputPixelFormat_, window }; + PassConfig pingPongOut = { inputCfg.size, inputCfg.size.width, inputPixelFormat_, Rectangle(inputCfg.size) }; + PassConfig pingPongIn = pingPongOut; PassConfig rgbaOut = { outputCfg.size, outputConfig_.stride, outputPixelFormat_, Rectangle(nativeOutputSize_) }; - gpuIspShaderPassDemosiac_.configure(rawSensorIn, rgbaOut); + gpuIspShaderPassBlcNormalise_.configure(rawSensorIn, pingPongOut); + gpuIspShaderPassDemosiac_.configure(pingPongIn, rgbaOut); return 0; } @@ -240,11 +245,11 @@ eGLImage *SoftwareIspInstanceGpu::getCachedInputFrameBuffer(FrameBuffer *input, if (cache_miss) { if (eglImageInCache_.size() >= inputBufferCount_) { eglImageInCache_.pop_front(); - LOG(SoftwareIspInstance, Debug) << "Input cache " << inputBufferCount_ << " exceeded evicted entry"; + LOG(SoftwareIspInstanceGpu, Debug) << "Input cache " << inputBufferCount_ << " exceeded evicted entry"; } - eglImageInCache_.emplace_back(fd, std::make_unique(gpuIspShaderPassDemosiac_.glFormat_, - inputConfig_.stride / gpuIspShaderPassDemosiac_.getBytesPerPixel(), + eglImageInCache_.emplace_back(fd, std::make_unique(gpuIspShaderPassBlcNormalise_.glFormat_, + inputConfig_.stride / gpuIspShaderPassBlcNormalise_.getBytesPerPixel(), height_, inputConfig_.stride, GL_TEXTURE0, 0)); eglImageIn = eglImageInCache_.back().second.get(); @@ -252,7 +257,7 @@ eGLImage *SoftwareIspInstanceGpu::getCachedInputFrameBuffer(FrameBuffer *input, return eglImageIn; if (eglImageInCache_.size() == 1) - LOG(SoftwareIspInstance, Info) + LOG(SoftwareIspInstanceGpu, Info) << "Importing input DMABuf failed, falling back to upload"; } else if (!eglImageIn->dmabuf_import_failed_) { egl_.activateBindTexture(*eglImageIn); @@ -263,7 +268,7 @@ eGLImage *SoftwareIspInstanceGpu::getCachedInputFrameBuffer(FrameBuffer *input, inDmaSyncer->emplace(input->planes()[0].fd, DmaSyncer::SyncType::Read); inMapped->emplace(input, MappedFrameBuffer::MapFlag::Read); if (!inMapped->value().isValid()) { - LOG(SoftwareIspInstance, Error) << "mmap-ing buffer(s) failed"; + LOG(SoftwareIspInstanceGpu, Error) << "mmap-ing buffer(s) failed"; if (cache_miss) { eglImageInCache_.pop_back(); } @@ -294,7 +299,7 @@ eGLImage *SoftwareIspInstanceGpu::getCachedOutputFrameBuffer(FrameBuffer *output if (cache_miss) { if (eglImageOutCache_.size() >= outputBufferCount_) { eglImageOutCache_.pop_front(); - LOG(SoftwareIspInstance, Debug) << "Output cache " << outputBufferCount_ << " exceeded evicted entry"; + LOG(SoftwareIspInstanceGpu, Debug) << "Output cache " << outputBufferCount_ << " exceeded evicted entry"; } eglImageOutCache_.emplace_back(fd, std::make_unique(GL_RGBA, outputSize_.width, @@ -323,9 +328,19 @@ int SoftwareIspInstanceGpu::processGPU(FrameBuffer *input, FrameBuffer *output, if (!eglImageOut) return -ENOMEM; - pipelineResult = gpuIspShaderPassDemosiac_.process(*eglImageIn, *eglImageOut, width_, height_, params); + pipelineResult = gpuIspShaderPassBlcNormalise_.process(*eglImageIn, *eglImagePingPong_[0], width_, height_, params); + if (pipelineResult) { + LOG(SoftwareIspInstanceGpu, Error) << "BlcNormalise fail"; + return pipelineResult; + } - return pipelineResult; + pipelineResult = gpuIspShaderPassDemosiac_.process(*eglImagePingPong_[0], *eglImageOut, width_, height_, params); + if (pipelineResult) { + LOG(SoftwareIspInstanceGpu, Error) << "Demosiac fail"; + return pipelineResult; + } + + return 0; } void SoftwareIspInstanceGpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms) @@ -343,7 +358,7 @@ void SoftwareIspInstanceGpu::process(uint32_t frame, FrameBuffer *input, FrameBu std::optional inDmaSyncer; if (processGPU(input, output, params, &inMapped, &inDmaSyncer)) { - LOG(SoftwareIspInstance, Error) << "debayerGPU failed"; + LOG(SoftwareIspInstanceGpu, Error) << "debayerGPU failed"; goto error; } @@ -390,14 +405,17 @@ int SoftwareIspInstanceGpu::start() glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits); - LOG(SoftwareIspInstance, Debug) << "Available fragment shader texture units " << maxTextureImageUnits; + LOG(SoftwareIspInstanceGpu, Debug) << "Available fragment shader texture units " << maxTextureImageUnits; if (initBayerShaders(inputPixelFormat_, outputPixelFormat_)) return -EINVAL; /* Intermediary ping/pong textures */ - eglImagePingPong_[0] = std::make_unique(gpuIspShaderPassDemosiac_.glFormat_, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); - eglImagePingPong_[1] = std::make_unique(gpuIspShaderPassDemosiac_.glFormat_, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE2, 2); + eglImagePingPong_[0] = std::make_unique(gpuIspShaderPassDemosiac_.glFormat_, width_, height_, outputConfig_.stride, GL_TEXTURE1, 1); + eglImagePingPong_[1] = std::make_unique(gpuIspShaderPassDemosiac_.glFormat_, width_, height_, outputConfig_.stride, GL_TEXTURE2, 2); + + egl_.createOutputTexture2D(*eglImagePingPong_[0]); + egl_.createOutputTexture2D(*eglImagePingPong_[1]); return 0; } @@ -432,7 +450,7 @@ SizeRange SoftwareIspInstanceGpu::sizes(PixelFormat inputFormat, const Size &inp */ if (inputSize.width < (3 * patternSize.width) || inputSize.height < (2 * borderHeight + patternSize.height)) { - LOG(SoftwareIspInstance, Warning) + LOG(SoftwareIspInstanceGpu, Warning) << "Input format size too small: " << inputSize; return {}; } From patchwork Wed Nov 18 09:57:25 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: 28981 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 D9A38BDE17 for ; Wed, 18 Nov 2026 09:58:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7BFEA6A8F9; Wed, 18 Nov 2026 10:58:26 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="M5+J+LQC"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1BA116A8C8 for ; Wed, 18 Nov 2026 10:58:08 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-490f38e9688so435375f8f.0 for ; Wed, 18 Nov 2026 01:58:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995888; x=1795600688; 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=axyCX8IRvg1Maa6h/NSfsasoGZ5fBp4secxjSuJ9foo=; b=M5+J+LQCjFzhSnkRkFT3UA+9aTuDyhP1/5x0AEIThdlwKmtD9ZAZFIkL77OmMEPpo1 7ZTm6TkTuQEu1+EzfwjTgxmeqSa3qIzQmAznnv3axJCT6fS3H/7KeT6fH8nq4Q0nXI6x TxpoqKARF27E6UB1C76WAF9ChR6BEv9If3VOUENxYfPJ4wZw8C3lZ8CzJ8f4NF579jfg H0AU8CsrWMG+MHsFAsIgz4qTI4GOhxdM2vBc550mUSFJgFP8aip+uwHl363b5d792vDn xgbGszXP119Pnb6+1JChXEVMsNeruVrZdpGKFWVC+vDRzl4FyuPtT91yRtFnNCYBK04g ktzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995888; x=1795600688; 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=axyCX8IRvg1Maa6h/NSfsasoGZ5fBp4secxjSuJ9foo=; b=ppaJhaaLR+ZmmkbNaSfnDptamHcMpE5UMV3ew8STP+cZyzKVeEHtyXHqmhASVIgoYI u7kZvdig8PzC1lurAzLd/B4m4F2E1m3tdLsXwXYx6LCwxzOtcpIHEaNTci66Wna36B/s AB8Cz60yiUORyhuQ/Bf2vQzy2eFNBNC2p/e2GY328i9UW0DBEekzxPg6bWytMZaGqKNK 9OKtW4rDhH1p6KGdCj/oBlNh41sS1OtIksqkd42ejISpxnpZ4zVZP32E9P8hXgD6COXs PNx+uRapXAaDTIQMBovWsTepKv4NsC5GK7pwVwuu80RHywhmT/qICkRNOafVIg3qZlPb vVrw== X-Gm-Message-State: APuU4Z+LIt9yNLRohBWjAPsvl2/aO+z9ZAXKrD8XZJoKGiClFcd9sZda OvQUh6oq0Lk+IfZZo5dex/zrzMwfN4r3CIMb8MxsVfizHsRVH2er5f7nPiqRyJdgacpPSLl3hxe x8V/fOwk= X-Gm-Gg: AZFdTZfSvljxf7G4TLolOgSfxTdT0UYONhaC+qJ0aOMJrbqzebXBKfgncFeqBkMQPUN uSM0Zbh4GXaGWds3/XX47zOsV2z2cXs2crg5o9AXN4Pm37egq1eziXifTinnJ2v3GPYnZxZ/fID ++3wyuP20fHUgcmIIAaumQq9ApKRmOpxVQQhKu8DKluqz5fNqoDHmPgfD157QhnHH/JfMqkgHD2 6I9PEeqgsXQrjHJ2jKcqEmLOOiA+Ju4NQWJLye4ijJl3lHmH6uE1QziiKirFYcqcfq8mAnS9K5Z qydpasCH6c2rtzOXiXnxW8MVErMxvJ3c7bCrwjycx6sVI2b5Pk1S++8ZY3mwIq9FZ8ePOoihSdz iPY506ruL8q/YIS0LsckJBBVYSmVeJpFTCIzbkaldlblJBXvQabwK3Qh32ggc3DXgLjKSZ65ypE 5jrAJko8NcX9esq78Kr5bQhh4+6Q3n5yLAcxjCQE2MIOGMIVhdk10lKhtm98IdbK1p9AOeFfVlh A32FHQd9O+I7sec0iFM18f8nAVAjyeEGazVjM4NUri0FeE5oTGHFV2ekq/LTje7wxFQjcmaWCTY fen3zDPBrs+iZRvg4MUJpVyoIIFVMUmSUGH8KFzqbArycQ== X-Received: by 2002:a05:6000:200c:b0:4a7:9630:7b36 with SMTP id ffacd0b85a97d-4a796308082mr1482998f8f.21.1794995887554; Wed, 18 Nov 2026 01:58:07 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:07 -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 18/26] libcamera: shaders: bayer_glr16_to_rgba.frag: Make fetch() into a function Date: Wed, 18 Nov 2026 10:57:25 +0100 Message-ID: <20261118095735.170587-19-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" Do some simple functional decomposition to make the subjectively ugly define into a function. Signed-off-by: Bryan O'Donoghue --- src/libcamera/shaders/bayer_glr16f_to_rgba.frag | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag index 4a2e5af87..0b2db1d7a 100644 --- a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag +++ b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag @@ -37,12 +37,14 @@ float apply_contrast(float value) return 1.0 - 0.5 * pow((1.0 - value) / 0.5, contrastExp); } +float fetch(float x, float y) +{ + return texture2D(tex_y, vec2(x, y)).r; +} + void main(void) { vec3 rgb; - /* Sample from R16F input texture */ - #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r - float C = fetch(center.x, center.y); // ( 0, 0) /* Which of the four CFA phases are we on (0 = even). Same as McGuire. */ From patchwork Wed Nov 18 09:57:26 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: 28980 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 5AFD4BDE17 for ; Wed, 18 Nov 2026 09:58:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A7A4A6A8DE; Wed, 18 Nov 2026 10:58:24 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="L17qYSFu"; dkim-atps=neutral Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E449F6A8B1 for ; Wed, 18 Nov 2026 10:58:08 +0100 (CET) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-491846221ffso597168f8f.3 for ; Wed, 18 Nov 2026 01:58:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995888; x=1795600688; 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=bAvV9R2dji1iwN0aImkStWk7rXYdAx/mWGRTkDAD/Cw=; b=L17qYSFuzANNh/p91CE2AyU1hBYfJth3GF0rfCSSSGEK7I0G82gCtycfGyvuKJawiq ArYoUPfnW8kYYKkdrm1vop6FGzoZFI+B0di6tCrrVx/Z5bn61PmJeT38nbGt3esuQJE3 EeBAzGqhJBmMxKbJZpfSlEkDQ02cc4PvLSpBN2R8IJTy2Gs+BbmB335mf0KmH77vop/a kjOENwRha8H9eSZOLCFQsweD7ANtQn96p+Sn3ht+aqauWlj5mdcvkK23rlvPwhCiMJ9P F1Wlk/MU9hJkBE1HCgB0Y9Lv3lYXMwqd9pEF3Fl7WhnaagGQImf/IUCmYc0gdZ08qXen 5jvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995888; x=1795600688; 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=bAvV9R2dji1iwN0aImkStWk7rXYdAx/mWGRTkDAD/Cw=; b=VCQxITDLM32YOqyH9uW3PCbzFpW6Zvy6OphUh57CjwzpjkV+y41p4HLVwlZzE6MVuw xYi6HyzIF98dX/k2gHU/woA9NuxUIcRhTzKiMl/65aiWaABMlyQ47y4lz/dKUOfXhlbh Ha23pGSGcHpkiWD/zPZn8hgGuKGBZPMCsZFjVwyPDDBACuMhrsbMU1Xx6FKWrISuW+Hq l8nCmIF+qMEceyF+7NyjOMlgilK4sl6vtVVuoJ5PgzwGkPpwbvPyDISPeIMMuWDq1gbc fGkmJJCwf4QaD34fuswcmW+iCJ+XwwHhAQ44J4xQ92XldGhXm0z+JwxWM50USBexwyip 5N1Q== X-Gm-Message-State: APuU4Z9xfgO7v1zcSOnajRn+DBkgT4O8OnOgfnocZN0NLLDoFcbU5nuF YnALgr86Jkmht79b6vFY1fAU9X8NGRkpPVDLBNTzgSgW3bCSatvhSswxXZe0PMN/mg15GM3+r4y Qp2eKtlY= X-Gm-Gg: AZFdTZeh1kAK9XddT3ZfF8o2wkBLG9iAM9VU7Iqe8wGxY2seFxzrJCPXoAQlv51JX9r sOmmNxgRoqXXxx8aG0p7NAF4ulQcu51eX3LYUc/1CGKwNVWghETvv0o+TXNriLtSqtAiMuxAMog mXeOwAzc0Q9GVQ9XeHuns57AX19YgSDThmWATwaJphE+vkH/x+choTV3/z8lF62V5ikDbBRnyMh m9URcAZHMCj5UKTOi7UHsJh2qSBlc89TWcVzYzqR8232YdUUmkBFOkvsydxYLyPJgjcfBRv5mFt fkDSyxOVssg5JvQPIxChw/YBuAqSzGOqU+9M5VAxYhrAK/ZiT+R81V2TugcA8Tqik4fGZ2Megl2 O98KDpgEUsz9yv0IfMSOnwOaWl4p0eGp7rqLfDnjiBBvy/GbcNdGufGuqSNb7kQWgt7/0xXApKU b3PJ/BrnVm2frFHOM4gzAonJX9YVZ9fkRYMrytAROc2pfA7a5FEfU1/ZyjDQsHA9NBfW5lyJDqp /+ay+1a7HAtVXriPyiv504EnTofGBFGYlkhxX7vCbsQ1I5+vNt7G9girhCEizhef5iKt+HcNZ/V I+BUNpZz7q1RyyZYGSjTeY6Stw9xt3ansD+RN/StrERWWA== X-Received: by 2002:a05:6000:2907:b0:492:9630:6a7f with SMTP id ffacd0b85a97d-4a63d983a14mr4850666f8f.55.1794995888440; Wed, 18 Nov 2026 01:58:08 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:08 -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 19/26] libcamera: software_isp: gpu_pipeline_shader_pass_demosiac: Switch to unified fragment shader Date: Wed, 18 Nov 2026 10:57:26 +0100 Message-ID: <20261118095735.170587-20-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" Signed-off-by: Bryan O'Donoghue --- .../software_isp/gpu_pipeline_shader_pass_demosiac.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp index 47daa1f1f..bceb5f68d 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp @@ -46,7 +46,7 @@ int GpuIspShaderPassDemosiac::selectShaders(struct ShaderConfig &shaderCfg, [[ma bytesPerPixel_ = 1; shaderStridePixels_ = passInputCfg_.stride; - shaderCfg.fragmentShaderData = bayer_unpacked_frag; + shaderCfg.fragmentShaderData = bayer_glr16f_to_rgba_frag; shaderCfg.vertexShaderData = bayer_unpacked_vert; switch (inputFormat) { From patchwork Wed Nov 18 09:57:27 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: 28982 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 74A9BBDE17 for ; Wed, 18 Nov 2026 09:58:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B8AC86A90A; Wed, 18 Nov 2026 10:58:27 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="E6nGRrRb"; dkim-atps=neutral Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F40A56A8C7 for ; Wed, 18 Nov 2026 10:58:09 +0100 (CET) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-498f5fa4f70so625376f8f.0 for ; Wed, 18 Nov 2026 01:58:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995889; x=1795600689; 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=EAXfo5aTxuaRdwcl5F0KUKiTldHBFE8N/fKyXanghHI=; b=E6nGRrRb+DlZ/3USijQ0tHg0DZ7ahHtIZ8lAAAjaol130lKNJCpT5eZvJVyPQQHoE2 aSKtENylrEnOp9g3/CbW1PNCJ4HT0iwuCXY2Dr06k+tZtPgsG8OAXD/P0t/L5dq//xpX cpYKcyILZC2ya4E5DC93OdARysKmUl3lOebZnAA+JYGcRTugHseKC7UFmYwUx+dlSGkO sDIqoXQrDVlW29V0X2X3RLmN1FYgV8810K1uK2ekjNimbf4uLrTNeqzLfUXU3J62cACs VlXheCTAVPXPaRrK4uig13VxCo1WNvVifpuajHngkkH8rX5bCvjYNW1UnLhXalCj4weU bBTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995889; x=1795600689; 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=EAXfo5aTxuaRdwcl5F0KUKiTldHBFE8N/fKyXanghHI=; b=EGqJ0Skaun8UFzAyB+nP7wvefG55UYD3l/tF4Rtge5bzVpE7oqNR34I7nMqMIneDth jC6HLqo3u/2YpNVkNH3yGz9w7sGrtKlOZutmuYwj/Zgz69OH48yuRy3sjiDu0T+hnobE ClxcEqQm0Un/SoD6+dxvuY/bt2rPnm0rdFVG8lipQFM6RR8RrelpLQbKBo4fHePfQCM6 p5Qb/+IQh6JhtB3aV7GIxECT+XtewTQbKojaX9U54QgvKdTbjltNlGKUMhN9+1nfSHW/ haalSmeY6NMErvqgs/XdJPnNFUrl7UfsIj+lPPu8aUI2h6XaWiezdq8ZnkOpadNMWzL9 otCA== X-Gm-Message-State: APuU4Z/TxdHC7VzlGQGwq+Z8J4dKXWVpOZPRizu6ATpHo1yN8daLADTe OPg35JIzWzi4dgazoOc82yMxRyEhOfNTf1QLxW4Bh0FbU71dk2P2zf/i2i7hXNmH8wvDrJIhRJr N1EcEIGg= X-Gm-Gg: AZFdTZfGuMULYGNke+c8vjn43DY3T9ZKZE2KVV7RQk/SJG5xWv5LB68yzH5fHJYFJN+ vrhbz+/ore6lDa5zaJF7Yxk5ZU+DEo3yzez6UFw8fq497kdQRYa2H29IdJd/7FnWUcavE6SPX6n UkAPGqXOd67oRN1u4bJASgURAHTVlUitqp/7MpOe6XqcIofvwKDTDZ3VcldsRFxv2sIt72AKUN3 dy1rGnt9lNOAzMuGbvOSV2+1o+zb4kMbnHWcFngbjhT9xh4suID7ByjOuWEb6sYQ51occ0+aOFL j8mXFEISXUIb7J/eXGes6GN+ms1NQkSM6qPrf154BN0y4SSMKEYCYNTTdrraA1gXbGEKdqbBA9u xmvmy/xJ/djlPFwOy/VkCq3IjJn0cyapyvP3ejRnKZlNLcj0n4GhvZ7gCdyDnkCCklqgKEZgfJL +bKR/4oVt7JQV1LYzKnQ9Vvg+4umgkteR6Lbew1QVIGIlU8zUYCPUVlJMudnr0TbVfb+jaRzglj T7FyqUu7T96rwteFMtL35XIZ8Rx1fK1EZjwaKHCErGqmX3VhFV+Xis8rSvR/ozVcYeZVjn9keuD 2yrQss0dvGVk+6gb8NijvO5fuYFm+RMLNMrErRLMAVOC1Newv537X+iBmUWoVQZly2w= X-Received: by 2002:a05:6000:470b:b0:4a4:368:409d with SMTP id ffacd0b85a97d-4a633785fc0mr4494571f8f.3.1794995889494; Wed, 18 Nov 2026 01:58:09 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:08 -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 20/26] libcamera: shaders: bayer_glr16_to_rgba.frag: Sample pixels into a structure Date: Wed, 18 Nov 2026 10:57:27 +0100 Message-ID: <20261118095735.170587-21-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" Sample the raw bayer pixels into a structure. This makes the code a bit more readable and sets us up for fetching pixels once in the code when doing statistics. Signed-off-by: Bryan O'Donoghue --- .../shaders/bayer_glr16f_to_rgba.frag | 64 +++++++++++++------ 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag index 0b2db1d7a..ce334de48 100644 --- a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag +++ b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag @@ -28,6 +28,12 @@ uniform mat3 ccm; uniform float gamma; uniform float contrastExp; +struct samples_3x3 { + float row0a, row0b, row0c; + float row1a, center, row1c; + float row2a, row2b, row2c; +}; + float apply_contrast(float value) { // Apply simple S-curve @@ -42,10 +48,26 @@ float fetch(float x, float y) return texture2D(tex_y, vec2(x, y)).r; } +void sample_3x3(inout samples_3x3 samples) +{ + samples.row0a = fetch(xCoord[1], yCoord[2]); + samples.row0b = fetch(center.x, yCoord[2]); + samples.row0c = fetch(xCoord[2], yCoord[2]); + samples.row1a = fetch(xCoord[1], center.y); + samples.center = fetch(center.x, center.y); + samples.row1c = fetch(xCoord[2], center.y); + samples.row2a = fetch(xCoord[1], yCoord[1]); + samples.row2b = fetch(center.x, yCoord[1]); + samples.row2c = fetch(xCoord[2], yCoord[1]); +} + void main(void) { + samples_3x3 samples; vec3 rgb; - float C = fetch(center.x, center.y); // ( 0, 0) + sample_3x3(samples); + + float C = samples.center; /* Which of the four CFA phases are we on (0 = even). Same as McGuire. */ vec2 alternate = mod(floor(center.zw), 2.0); @@ -53,36 +75,36 @@ void main(void) { bool even_row = alternate.y < 1.0; /* - * +----+----+----+ - * | D2 | A1 | D3 | - * +----+----+----+ - * | B0 | C | B1 | - * +----+----+----+ - * | D0 | A0 | D1 | - * +----+----+----+ + * +-------+-------+-------+ + * | row0a | row0b | row0c | + * +-------+-------+-------+ + * | row1a | center| row1c | + * +-------+-------+-------+ + * | row2a | row2b | row2c | + * +-------+-------+-------+ * - * patterns.x = (A0 + A1) / 2 vertical neighbours - * patterns.y = (B0 + B1) / 2 horizontal neighbours - * patterns.z = (A0+A1+B0+B1) / 4 cross average (green at R/B sites) - * patterns.w = (D0+D1+D2+D3) / 4 diagonal average (other colour at R/B sites) + * patterns.x = (row2b + row0b) / 2 vertical neighbours + * patterns.y = (row1a + row1c) / 2 horizontal neighbours + * patterns.z = (row2b + row0b + row1a + row1c) / 4 cross average (green at R/B sites) + * patterns.w = (row2a + row2c + row0a + row0c) / 4 diagonal average (other colour at R/B sites) * * xCoord[1] = -1, xCoord[2] = +1, yCoord[1] = -1, yCoord[2] = +1 * (xCoord[0]/[3] and yCoord[0]/[3] = +-2 are unused here; the vertex * shader still emits them so the VS is identical to the McGuire path). */ vec4 patterns = vec4( - fetch(center.x, yCoord[1]), /* A0: ( 0,-1) */ - fetch(xCoord[1], center.y), /* B0: (-1, 0) */ - fetch(xCoord[1], yCoord[1]), /* D0: (-1,-1) */ - fetch(xCoord[2], yCoord[1])); /* D1: ( 1,-1) */ + samples.row2b, /* row2b: ( 0,-1) */ + samples.row1a, /* row1a: (-1, 0) */ + samples.row2a, /* row2a: (-1,-1) */ + samples.row2c); /* row2c: ( 1,-1) */ vec4 temp = vec4( - fetch(center.x, yCoord[2]), /* A1: ( 0, 1) */ - fetch(xCoord[2], center.y), /* B1: ( 1, 0) */ - fetch(xCoord[2], yCoord[2]), /* D3: ( 1, 1) */ - fetch(xCoord[1], yCoord[2])); /* D2: (-1, 1) */ + samples.row0b, /* row0b: ( 0, 1) */ + samples.row1c, /* row1c: ( 1, 0) */ + samples.row0c, /* row0c: ( 1, 1) */ + samples.row0a); /* row0a: (-1, 1) */ patterns = (patterns + temp) * 0.5; - /* .x=(A0+A1)/2 .y=(B0+B1)/2 .z=(D0+D3)/2 .w=(D1+D2)/2 */ + /* .x=(row2b+row0b)/2 .y=(row1a+row1c)/2 .z=(row2a+row0c)/2 .w=(row2c+row0a)/2 */ patterns.w = (patterns.z + patterns.w) * 0.5; /* diagonal avg */ patterns.z = (patterns.x + patterns.y) * 0.5; /* cross avg */ From patchwork Wed Nov 18 09:57:28 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: 28983 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 1C81FBDE17 for ; Wed, 18 Nov 2026 09:58:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6075A6A8E7; Wed, 18 Nov 2026 10:58:29 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="lYOmchv9"; dkim-atps=neutral Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3A3D56A8E3 for ; Wed, 18 Nov 2026 10:58:11 +0100 (CET) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-48e20ed3b9dso590461f8f.2 for ; Wed, 18 Nov 2026 01:58:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995891; x=1795600691; 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=0bdIMGSJARuaABcMHiUve+Qx0/XAC6+UYe4ZLALtaWA=; b=lYOmchv95P6waF5TrxhRCq/LZH3u/YDKI+8oMoVBfmHwB4hXzjtBKc8S9r/z6/HvR5 x/EPh1OTK2yeb03gqp4htojgWtLjj3LYzaCJqY4ZNt8buw/AL+CIuEm3z9Nq2QWS9bcB gBXZwSQyn6WgUEbYVophT6iwbyFgG2M6Fb6XWrdNbAt7Z/9ayIN5ATT49OuiqiW6VYRQ oIHElVaO95TfshacknOrP03950W9RnE0UOdqQ+PXoSjvYd0nxCcr60uwiAygT7UBKCCI SeneoHSU94le0wA41vniQQJNTAmzlI9dXO5f5qc7Ihxi/sIs6wtjK7dhhcRxcTahSLq3 AjBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995891; x=1795600691; 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=0bdIMGSJARuaABcMHiUve+Qx0/XAC6+UYe4ZLALtaWA=; b=d7rdBP1qWDTllZnJi5BkckWB2mcPR0q+mKPy3DLIpTNFdA6xXqC09WHYRf+lop8nOI sIxMCK6Ofjl8JEA5BEdYKRoy3CKE4QaiN6e2lTP5y8nDEDKXlM3Um35H8tLEtUYwM+kd pI3LDhzwZ23MbZ3dPiw8SXOwtaVJ1ZRvyK75et0wsx+c6Ll70I9uI//wM4QV3OBxLspk wMMdjapbnche6BHrCt2CZOOShrWnBU8f1PgxYlSC70DA4vUipioUVFIaSBWGM+jctyo3 FbZNSClcE7X5i9SPtGahd2xBkQflRKnTxZmZJDYeA3YEj9d+gg41zEjlb5nmRztAsRMK KdYw== X-Gm-Message-State: APuU4Z8CTWmxJIRoZ+h85LhKktpYdY/Vb+gvs9XVGrUCjkMIZlIazNii rvphcxPAJT0647XSFzBR+nVNzzLUW8RvNd00sdUdKKEw1IUvaIE4StBf9zPP2N0cJBS3YdOp+FE LDTZhxPU= X-Gm-Gg: AZFdTZduvv8LZYW9Al9NRp9xn9VwgouflApUuNTZpJCkwkOyTpJ+0s6Dy7bhybYoFB5 XIhldZTeWdzx+qLTMhBdELmXS1eZ3h74oHx/XciVlmtENLhCi7sjXtzLPKtlWUurM6LuqKfVjov vphJH+mqIh2CCzOuEhol9MN+mAU3sTTFg6smspjAvgl0oixN+VpQZndsCgbhZNseGinqDBtl0Ts /4t/CFzUyu6bn28r93weqrIrlTgxEnaZdulueLEbf06qEj7jPRokRmkLIW9JL4Ey/hKGEXmQCej +g4y9K2CoHmsflLbaqcOT+vlUCA+qL3WwOi/WTTPzYLoQKvGZ53WtiYoDofYlIEMmpgjEOdfCHL l48PvrWGxrUb/mwEzSCynwQ1zaWI+HMr1it/C+7MWrgEGC8U9a7C/0qzdAZz3WEvB/XUAlYTod3 PxGjHwJQZ1MeFtSyqU8J+Ovbe9Q4f3qN8XTM3/uechDtO5U3hsfdJzNNI6yTjhtCXTPodvejher I8Wc2FfqQ1SHc+Yu3KVDf9ng1ImDkromHN4c1uWZkEV86aDSh+0/7J71h50GxP2iUQ5Ypo1RBUW Q62JGgaZ33bptBCAs7CIoBcF06ZZZhndTDmPM87+fUkpzg== X-Received: by 2002:a05:6000:2602:b0:48e:824:f0b9 with SMTP id ffacd0b85a97d-4a63ae5678fmr4103981f8f.45.1794995890596; Wed, 18 Nov 2026 01:58:10 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:09 -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 21/26] libcamera: shaders: bayer_glr16_to_rgba.frag: Move debayer logic to a routine Date: Wed, 18 Nov 2026 10:57:28 +0100 Message-ID: <20261118095735.170587-22-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" Tidy up the debayer portion into its own method. We may choose to support different adjacent methods so sectioning off into a standalone method facilitates in addition to isolating and aggregating specific logic to a specific localised place. Signed-off-by: Bryan O'Donoghue --- src/libcamera/shaders/bayer_glr16f_to_rgba.frag | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag index ce334de48..c613e9842 100644 --- a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag +++ b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag @@ -61,12 +61,8 @@ void sample_3x3(inout samples_3x3 samples) samples.row2c = fetch(xCoord[2], yCoord[1]); } -void main(void) { - samples_3x3 samples; - vec3 rgb; - - sample_3x3(samples); - +void bilinear_demosiac(inout vec3 rgb, in samples_3x3 samples) +{ float C = samples.center; /* Which of the four CFA phases are we on (0 = even). Same as McGuire. */ @@ -115,6 +111,15 @@ void main(void) { (even_row ? vec3(patterns.y, C, patterns.x) : vec3(patterns.wz, C)); +} + +void main(void) { + samples_3x3 samples; + vec3 rgb; + + sample_3x3(samples); + + bilinear_demosiac(rgb, samples); /* * CCM is a 3x3 in the format From patchwork Wed Nov 18 09:57:29 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: 28984 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 D0CC9BDE17 for ; Wed, 18 Nov 2026 09:58:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4F4436A8ED; Wed, 18 Nov 2026 10:58:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="gs3fcEdh"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 769EC6A8E0 for ; Wed, 18 Nov 2026 10:58:12 +0100 (CET) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-490c3ae81d3so451350f8f.2 for ; Wed, 18 Nov 2026 01:58:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995892; x=1795600692; 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=4sQ/Rn3HRthPdmB6xG+GmTxaBFr9DH/Hz6KAGK/e/sY=; b=gs3fcEdhfSyCMKPUHnzw/S/RCJQ1jjBRxmBz0kxe1JPUaUB/A6p/tmvpGV9/Ccebas qAU3wFDRqwvaC+87o9axahBXd2FvuoRJhheQV/CHCQWUVsor4tVJ/oUNKwQHPIbukhsk Uu8P1u6dxMFdWzHI3TN+gVi2HP1/KskzsrX/RS4sjKi/0UFPFCFg1f+vyFrxkRv3lL28 DI/2XGDFLF6vNEDGETMD6V4u9qUiMyqAGEhIJbImL+nLBkBSBro3rVJ/kXG7ZGyxB6/h 5znAJt15YbNabcpDusQE1T4YhALCFJgRLCbUGJ+FXyEFuiqTelFAv2h32OwvYLg8h7++ N1Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995892; x=1795600692; 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=4sQ/Rn3HRthPdmB6xG+GmTxaBFr9DH/Hz6KAGK/e/sY=; b=ADQP/dj391DtYSg8XCvp6/I+cncGPP5VZb7yIHTmrNPF3fFQdlJDY2BLFts0KSFkSJ rnOporOiSW/iSSQ+Bs+mH2cMfE1JbkWFfCDniCXrEHj7egygm6POEEGvNT3nGHW0bFEs uPtnFG4FXrW9QfP4vr0l2i/SaOmsMW68V5P2xTbSaRV4L+lViBvHfb53DRdbne1pOV7d ob7GISYsry2mYjl0lnSVBMc+LmyGH7LIx/vOHFCdF4jDsmKKY6sMUAIcjZdtCe/Acnyw OyO+lKgs/1xH2xKDh0WmDlcT5B/IbeMr7rGt/fz4wQvm7wCHkLCv2JtC0n/zTEWn/B5J JfRw== X-Gm-Message-State: APuU4Z9iHBEX8OFeDjWbBQkXA8Nppt+FcS3tHKr9jnpbgRsAPKgcMvFj LmIHlaybUL91MITJYYAKFl4VSjLAOiqSPhK+H6LztCuwDnuhjzVdYodzWNyGEK9zsD3N4TzYXvy eEjqmXP4= X-Gm-Gg: AZFdTZccakxLNZWLas5/e4CbB8Ev3xodln0Ejljppp9H0BcNLNutVwGrzXNYkkQdgt5 hKxxVIjcY2uWonowMrFtSnuLVU1SJTbiACzmkLxjn1zI5olZbCvuTw+EHvffSInIHniZQPDk0h4 lIBWDmIK6czYlLaKz60KdBUXobLQwbiEdWMJ4k6eaqWt0HI2DCzecbU667lxGnAWLTvS+0PkzZE IaWKXCuUhKu9w099VngTNE1h7ibYGZGayyZ7vcEr3fOB/9rHAB656/dCHbkijkKa+wt3p7fwl4+ pyU9TDU1hIcYfxEpf5YkSktPJSg5s2tBFDIQN45zGcqbO8CnOMvIpJiNGyfl+K2I64RK+X4fzaf 0I35/S7+N16RBWedtnjj962MH+SvOiNTsJVHVBtMTIUg7UiUDKAhOcRpPZLj64b1uXHn/W/nlN5 e+0KIgurAAmjk1brnyTXxfAt5l0YeKRRN1vP8Y/ssy7myqBmVvO7dx6UiKVHPAi6OiwlhFdmu0d 6zGlpAwZxm/oFJuQ8Lgg23kdd8Wi0+iPXjlt7qnFI2w3Q9SkpeBRAwDXs5M6c2z9KcuLLt70uCn u5bDf+hofaLeIQqyIVCfsMbsPBH7wYqsUcjsHLz39DOZrw== X-Received: by 2002:a05:6000:3ca:b0:48f:bcdf:6f68 with SMTP id ffacd0b85a97d-4a63e03b638mr4446956f8f.37.1794995891796; Wed, 18 Nov 2026 01:58:11 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:11 -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 22/26] libcamera: software_isp: egl: Move scaling to the second stage Date: Wed, 18 Nov 2026 10:57:29 +0100 Message-ID: <20261118095735.170587-23-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" If we scale in the blc/normalise pass when we write to the output buffer we will be dropping Bayer encoded data. OTOH if we scale at the output of the demosaic phase the data we end up dropping has already been interpolated into RGB. Dropping at the BLC phase means losing the data-source to properly interpolate. Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/software_isp_instance_gpu.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcamera/software_isp/software_isp_instance_gpu.cpp b/src/libcamera/software_isp/software_isp_instance_gpu.cpp index 13d27ab7a..31940bdc6 100644 --- a/src/libcamera/software_isp/software_isp_instance_gpu.cpp +++ b/src/libcamera/software_isp/software_isp_instance_gpu.cpp @@ -183,9 +183,10 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg, outputBufferCount_ = outputCfg.bufferCount; /* Configure for one pass */ - PassConfig rawSensorIn = { inputCfg.size, inputConfig_.stride, inputPixelFormat_, window }; + PassConfig rawSensorIn = { inputCfg.size, inputConfig_.stride, inputPixelFormat_, Rectangle(inputCfg.size) }; PassConfig pingPongOut = { inputCfg.size, inputCfg.size.width, inputPixelFormat_, Rectangle(inputCfg.size) }; PassConfig pingPongIn = pingPongOut; + pingPongIn.window = window; PassConfig rgbaOut = { outputCfg.size, outputConfig_.stride, outputPixelFormat_, Rectangle(nativeOutputSize_) }; gpuIspShaderPassBlcNormalise_.configure(rawSensorIn, pingPongOut); From patchwork Wed Nov 18 09:57:30 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: 28985 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 841E0BDE17 for ; Wed, 18 Nov 2026 09:58:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E60046A90F; Wed, 18 Nov 2026 10:58:32 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="kC4M/bY9"; dkim-atps=neutral Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4540D6A8E7 for ; Wed, 18 Nov 2026 10:58:13 +0100 (CET) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-4a358881793so339700f8f.0 for ; Wed, 18 Nov 2026 01:58:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995893; x=1795600693; 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=O9T9MF8rCVzXbohesTp8C4DzVCwKDTj4cLX4G4awFQg=; b=kC4M/bY9CUz07Qc1hU8IOPxg2TjmOz/XRbFtjtIGA0sRemsGvZy8xy2eTm6s7BpE+C XZ+vpHdC7gdYrCLqhq0rU0pZl6lEfcE7gKoo+MrbwBS7218CdnODqFQW/cIPRcCr7bkm XdHygniAYD/ZTVDB9JNs3xJ5rqqWi9WF4C+e0i7ScDZhIjqOr/hGcjdn5QfzQvLKnlsx knYCcK7Ttzzb5FpMonx90SqwsWWgh4JfhlpNvZZx1iai/wg3UYbyOt94ei4X+O5zBNUV dKh7wJ2Fhk9jlsJa97qZqExWevJl0BCUPqfZci/Q3KjsJ5QamZ+jlF8XpvpF+0BqGwQ9 2DgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995893; x=1795600693; 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=O9T9MF8rCVzXbohesTp8C4DzVCwKDTj4cLX4G4awFQg=; b=LDDt0ZWM6Jg0GdksSY5JJmEjW5lbo32egAa1JF1x2dW4IROrnwRBWXnMN/3/09K6F5 ycXbYEbY1eRgpf6VuZtko9oVT3AY1CJ6zLMxV/kFJVuNjIncBLa+E/DgPfxvfeQX1+5/ 240i7bKRI02HPj0J25yuTpepK1cdxoZEWsIEC85kkKoPei/s63bP/s8nHJojDGD0Edxy hqk6K6c2OloP+pWCRllUccFifkc6VgkCA8WyXn4dlNETIwaE7E5yxgVkzNNbAOCAiRBv vR7vrSHY9nji3hGmv43R1ebPs5OPV9kaCD0GlBaT5e0Elql8cmmHS70ZuXgDtzGXr/ol HYLw== X-Gm-Message-State: APuU4Z+fELhTNAEftevK/VFMO3Kab/oFroV2H3n88nC6cm+iSq2Zxvh4 2DkGhquXnA63hebF8FcTCXyXPBTiII2hn/d8Q2uCKx54NAB/steXV9Po7w1kauFfzrqB/30UtFQ MpzkMI9M= X-Gm-Gg: AZFdTZe5Ps+gzKx+K9qhoQCWV/DcYsT807iD8/x1i4uKIzsrVFbTWai3Id/VYXW92RT YigtTqBd1mFGT59Z/p7oj3f3agx8QK1rHcUvoRATR0RuzisskZ8o1Px8UUfsuWenN3CXdXHGabk A2rTi17p8K7coNO+B9xH6YCiGFMGEi3yq8H7o6Noili/CsCSQ/BPQxqgRzw0Zw2uojcipmZme08 9cr4sUDH7Gl7Ztubcg9iVkUNXbRHl3qF8iLU9RQDfbISxCqM0KIMcGkwe+HeMVXkN3CudMkglJK ZEpLZYziDaaw1MzHiYdbY8SNG4TMfXIm9BT3zFlzCgQnf5mxICXPfSlOQf5MxRMAjQDLwwF11Qp ocyEqqZDlvnMZu/iy6Egl4+XSkqT3MQ8neuEs05418+xKSD3WZjN2JUdEFIbfN68RrsX/3zXbMM Jr35guoB196jzDibjAUyzygbTky1QW3l16jEfCWHG+H5UpbwxMV3zehEnA3xSGYiALZSrG0kG6A 9DAhepwzZiTig5amymjoaHD3KT3eabWM+kVttY+qCNw/hvZkhqPEwveDC3LWSIwca5rit/9wr0K ZnzMEdu7upkc6zyPl6ZuvySnAzG27L1e4nJyBxjcgcKLJA== X-Received: by 2002:a05:6000:3c4:b0:48b:1a0:5630 with SMTP id ffacd0b85a97d-4a63d985408mr4289734f8f.41.1794995892668; Wed, 18 Nov 2026 01:58:12 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:12 -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 23/26] libcamera: shaders: bayer_1x_packed_to_blc_glr16f.frag: Sample inputs at the texel centers Date: Wed, 18 Nov 2026 10:57:30 +0100 Message-ID: <20261118095735.170587-24-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" texture2D() takes inputs in the range 0.0f..1.0f for any x/y coordinate. This means a byte index has to be scaled into the range 0.0f..1.0f. When we mean to sample byte where x = 5.0 we calculate 4.964. This is very much dependent on how an individual implementation does GL_NEAREST filtering. For example on a reference Qualcomm system I see no error however using SwiftShader, whose textured unit works in steps of 1/65536 we can easily elicit an invalid read. Change the logic of where to sample by forcing the "asked" for co-ordinate into the middle of the texel not the periphery. We do this by adding 0.5f to each x/y before multiplying by tex_step. The outcome looks like this: pixel 4 of row 7 in a 2410-byte, 1088-row RAW10 frame is byte 5 of row 7: byte 4 byte 5 +-------------+-------------+ row 6 | | | | x | | x before: read (4.96, 6.99) +-------------X-------------+ X before: asked (5.0, 7.0) row 7 | | | | | o | o after: asked (5.5, 7.5), | | | read (5.48, 7.49) +-------------+-------------+ before: byte 4 of row 6, the low bits of pixels 0-3 on the row above after: byte 5 of row 7 This is easy to reproduce on SwitfShader because its texture unit is coarser than most real hardware. For any implementation we have an upper limit on what can be supported by frame-based floating point sampling. Later patches will interrogate shader precision and reject resolutions we can't support. For now implement the immediate sampling fix as given above. Signed-off-by: Bryan O'Donoghue --- src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag b/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag index 418a9e063..22eb74444 100644 --- a/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag +++ b/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag @@ -87,7 +87,7 @@ void main(void) */ center_bytes.x = BPP * center_pixel.x + 0.02; center_bytes.x = floor(center_bytes.x); - center_bytes *= tex_step; + center_bytes = (center_bytes + 0.5) * tex_step; float C = texture2D(tex_y, center_bytes).r; From patchwork Wed Nov 18 09:57:31 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: 28986 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 1AF1EBDE17 for ; Wed, 18 Nov 2026 09:58:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 73ACE6A908; Wed, 18 Nov 2026 10:58:34 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="HwW/D11m"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B8C96A8C1 for ; Wed, 18 Nov 2026 10:58:14 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-4a68190a2a7so535933f8f.1 for ; Wed, 18 Nov 2026 01:58:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995894; x=1795600694; 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=n8hJeCScvg+HimevVdFSpwGk3mxw5pJ2z+g/K2h5wo8=; b=HwW/D11mpi7ZlErC0Gc2cAGeCznwpPKVX2T9CBscwJKAGFZ86sx+gRu5tcjvHsIdG+ ZDduo7Vn352zn0zTpbU3/eOI73JyziDdSjWK0QDkeIv+L3eRQgoUI6S91J8HTilxxjkE o+AKnLxk079IzMpgsTiR/ewIpn4SRMudbDvudcQ7L46ricyrBW67dm32EfaFFVV48JmR pOAB92Z5gpHFTMfc2uMx0IWdZiyMwxNHiypbuNPWn2gZl3NqICCVLd3WvEHOV0k5mOA6 HMILraSoFQBQojJ7jSAa5/52nEaKM/rOsc5DKwFSwoSy0ofFOD2zy6kkYs7o6s9URtx0 MmTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995894; x=1795600694; 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=n8hJeCScvg+HimevVdFSpwGk3mxw5pJ2z+g/K2h5wo8=; b=zJb9Ffv7rgdwI82dlRdwjR/CJKt4Q1d0xq5H9IB+rSx18T4xQ4Ylmx9zUlce6CgRVe 2iJXG8nryc3VsxevaSGFvXzego1aAQlXsTJJN8QkX3krf6piI0+cgFrVL2ONyyPQDtab P4sbspKIo1w1HTaRow1Mj3dsB1Ri1lmNkcCrAvlq+WBRBP+qBzU7641RDdPH9JX4Y8M0 RP/XFGB0qjziLuuEPDcWeIQ+xH7iRfR+PAipfzKu/K2jLAPPY0YuoFGq5OrFPO0Hdp86 49YxUrmZpYOcnPqVsyj/SPhrFJHzS+6MfmKaI/orbywsefEiN7w7jJZzonjDFeyheEE+ n+8w== X-Gm-Message-State: APuU4Z/fRBAnb+mSogxaZBZ8s0S60q7ohjgLZ6+N5o/E8fzwcvcyPw3J v/whCVC6+41vsTBYXlocY6i19284aGC1IjkCcnIeH98Q1rh2bAFUWOuZ2+jstbji4xbk2FxHQoj QZY3bdOc= X-Gm-Gg: AZFdTZec6XtnyoqRChAvYKTSJNWexVNNfE9WLGt+/Z2CAVw7nD+BNyYMS9ZMrX2D9T8 c/6U+9j186KaGsoyQ6pvm/jNBCN4TuCFGQ7EuJXudRhQfzoUaKmlao8jtHpKZtUoe7JTe6FTxNU Gl1ntaBxLAt2C04LRmzPOyORak0j3HFwinnmX/jkb4j+LeZG3lLRyKYHhMg31WSa6NkDFuEYvYr zi9RB9tosW1ILvsBlywPWeOw7a752aTFtiMkaSIxERuYOCS6hVL5cG0i1nz5oVdhj+Its/kmVCC h9wmU3jQ1A6QYiGxPEUJrf0RbEWPmDDHyasJ83/5YznNnTio0uXsr15ovwawtZnOZk/THOjSrOU P8rBWjgJMjUkCVJVgss3kEZgfMrLHLYi2tmQzQm+WM78QImbu1PMZjwpTrU1yEueFvexyOhH+Oo V/4VD37W8zDKggIlJAMkNIL0H72DqHNMzc2pv4/FywTetb6yq6iD3XCqkp197ZzkF0Iy2a3wT6i 9GmOepW6iObndQszESlVO/BwRiM0tuhbm6G/7mUtm8b/EgAXHCn8PPw0LGevO9+uSHY6IddE233 MnQ1NDQFZChB/u0gRVVdUBDuYwRA/UB9yZwVCGlwnCRCmg== X-Received: by 2002:a05:6000:4616:b0:491:8286:5f0e with SMTP id ffacd0b85a97d-4a63db6f472mr4003095f8f.55.1794995893606; Wed, 18 Nov 2026 01:58:13 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:13 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: rstrode@redhat.com, robert.mader@collabora.com, barnabas.pocze@ideasonboard.com, Ray Strode , Bryan O'Donoghue Subject: [RFC PATCH v2 24/26] libcamera: software_isp: gpu_pipeline_shader_pass_blc_normalise: Fix texture sampling steps Date: Wed, 18 Nov 2026 10:57:31 +0100 Message-ID: <20261118095735.170587-25-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" From: Ray Strode This commit removes thin horizontal color artifacts caused by the GPU debayer sampling the wrong Bayer rows. The shader samples neighboring Bayer pixels using offsets in normalized texture coordinates. The step denominators currently subtract one from the input byte stride and image height, making the offsets larger than one texel. Scaling can then place a lookup on the wrong side of a texel boundary. A uniform synthetic Bayer image reproduces the lines seen in live GPU captures. The offsets now match the reciprocal texture dimensions: bytes per pixel divided by byte stride horizontally, and one divided by image height vertically. Fixes: f520b29fe9e6 ("libcamera: software_isp: debayer_egl: Add an eGL Debayer class") Signed-off-by: Ray Strode Signed-off-by: Bryan O'Donoghue --- .../software_isp/gpu_pipeline_shader_pass_blc_normalise.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index c5c19f85d..cc9969beb 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.cpp +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_blc_normalise.cpp @@ -121,8 +121,8 @@ void GpuIspShaderPassBlcNormalise::setShaderVariableValues(eGLImage &eglImageIn, 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 Step[] = { static_cast(bytesPerPixel_) / (passInputCfg_.stride), + 1.0f / (passInputCfg_.size.height) }; GLfloat Stride = (GLfloat)passInputCfg_.size.width / (shaderStridePixels_ / bytesPerPixel_); /* * Scale input to output size, keeping the aspect ratio and preferring From patchwork Wed Nov 18 09:57:32 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: 28987 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 0DE35BDE17 for ; Wed, 18 Nov 2026 09:58:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7E98A6A905; Wed, 18 Nov 2026 10:58:35 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="LJczs1ov"; dkim-atps=neutral Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 66A166A8DF for ; Wed, 18 Nov 2026 10:58:15 +0100 (CET) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-48dee593f18so582827f8f.3 for ; Wed, 18 Nov 2026 01:58:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995895; x=1795600695; 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=eUAfO7ZC79LR1j54ugGOe9gxt5LvymPyktJgvVW7Gs8=; b=LJczs1ovBVJnFaJh5E773RON6lQzoeMmGx5QIgrZ3MYXcLWQaR9hCHReAZtNf4Nf6F BYM8n3r7E9G/3E4WQPGQkH/q0Kw07SXbVG3Ml/PzWZ6/Twu50WyoG7ajsEABzJEThtze 44YJkinBBwhejJWIkmLmalq7AwzzZ8H/Z1fPPMCwTl5c+IetS3dzJBmzeG4chffCDQNF 8s06c+Cae7r7pyxSfokXBhQfBnrAv3/rzDBzIJYfNM0XEc/vmSdVHEFMmMXkhGsuzimP 1XhG4wMV8CDxY6TyWYBEF4RgTbxIZ8Re77REgfrSE5FKb3e6niXqZiEHTmGrgWjR7UKQ dtTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995895; x=1795600695; 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=eUAfO7ZC79LR1j54ugGOe9gxt5LvymPyktJgvVW7Gs8=; b=exoO2NwOamryTnVoHxf0wuIxf063jp6CGycXmpK5x5xWSEYiqNbCbFqWlImeRKEK2x T8yFD6V0d4ZDPkRz4aKuZnGpMYyduJjqXg7a0o9UX15QfmBvsZGxwwt6GW2e05w4HunT HQc+6f7RYzfsh3eeZYCZiMNCPwWlb7BQ18ePHfEy+2oEgT5qtiEZ96RvwbjEtpNCpoVc O2Gn1TJ0VJVncVNNLhW+JZHXyB0PHPqrzECyIphA1zhQrTPePXuE6Iy0Dq1+XabY/zEp HmHNhk5GXvyp688py4SZqyLGrRSplS72Zt6llQNH9yhvTNdxjXhXImUGc2iDzrlG2o1G OzuQ== X-Gm-Message-State: APuU4Z+U+71M03t/Ww/EX/R/dHjCp/kIw9EYoLJlXyT2I12Q6Z/e1MrN bDXxNtXth1bPh7ECqOEDVhByRrqS3IjeubLmoG+nNQkisCmnOXzS2xeJ43VxU9SzktNviThu7Zg QjT8ceTk= X-Gm-Gg: AZFdTZcWOPCONQoHLoW3tfiUJEK664Dz2xWwLyE884VPmso00wTW5QfaNUqiuWtkKvf 6yBW7RpoBi5bm6cn6xl7/KVjGpyCwb1htwS6BwmGvc1JhMX9/aVtILiInr2JXeWNl3zd7YQ+Xf1 PQrDP1VPjQv3FLSyphwSpifASPMnhCDbXlxCT+2m0uTpZnPVHA1fN6BercgelNMfnA0n7Yif18X y7p5q4kuZufBXEhorfFuY/BYkset4scZ9r88PWBWNuSjM/JIAMFg5MxV7t6Erjdq3+zxmHfwX8C vl96pnMIKfAEpYOq2FLU28dVOht9uR+QSRsl2FGQDnsjw2p4OwiCRK+j8ZEZReaQG9Z9bO7/vjy jZFtfHFyyTYAK9ytghqkE4TaaOIEc5A2mF/a+7iAXZrZDD4mdK0HNVzvwosg6+HslL9TsnNo6DA alWnXShqJskA5BBEd/6WdzhoF3z3MzJkbKUWpnW+wuMRpYarW7pKGoyDcCRsfaXB+Hu1pYenXU7 HJtSBDzIYHMm4ZK8P9iHAvJq7++RCA9vP8+aBLwjbLmbNQWC25SwfdLxCTaVk6NhlZwXx8LhKPk DE6WxjRD8vjKlwzkXLKcoxpYiJKb0PvDoa9EFXEP7fCn2Q== X-Received: by 2002:a05:6000:240e:b0:48e:4f1e:5e24 with SMTP id ffacd0b85a97d-4a638339786mr4604981f8f.14.1794995894749; Wed, 18 Nov 2026 01:58:14 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:14 -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 25/26] libcamera: shaders: bayer_glr16_to_rgba.frag: Use center.zw to derive 3x3 texel center Date: Wed, 18 Nov 2026 10:57:32 +0100 Message-ID: <20261118095735.170587-26-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" Currently both center.zw and XCoord/YCoord are used to determine where the sample texel should be. We end up sampling in the range 0.0f..1.0f so when the sample lands on a line the XCoord/YCoord and center.zw can disagree on what is being sampled. Switch entirely to center.zw using a similar algorithm blc-normalise logic; specifically to add 0.5f to the calculated center byte before dividing - thus ensuring we always hit in the middle of the range of the texel we are targetting when dividing down to 0.0f..1.0f not at the edge. As a result we can drop XCoord/YCoord. Signed-off-by: Bryan O'Donoghue --- .../shaders/bayer_glr16f_to_rgba.frag | 51 ++++++++++++++++--- src/libcamera/shaders/bayer_unpacked.vert | 14 ----- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag index c613e9842..a3cd71a4b 100644 --- a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag +++ b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag @@ -22,11 +22,11 @@ precision highp float; /** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/ uniform sampler2D tex_y; varying vec4 center; -varying vec4 yCoord; -varying vec4 xCoord; uniform mat3 ccm; uniform float gamma; uniform float contrastExp; +uniform vec2 tex_size; +uniform vec2 tex_bayer_first_red; struct samples_3x3 { float row0a, row0b, row0c; @@ -50,14 +50,51 @@ float fetch(float x, float y) void sample_3x3(inout samples_3x3 samples) { + /* + * @pos comes from bayer_unpacked.vert + * which then feeds into bayer_1x_packed_to_blc_glr16f.frag + * + * Where center.zw = textureIn * tex_size + tex_bayer_first_red; + * + * @texel_center has 0.5 added to it to ensure when we convert + * from a texel to a float in the range 0.0f..1.0f that we land + * in the middle of the texel we are sampling before divinding + * down to the 0.0..1.0f range. + * + * @texel_step because texture2D() above annoyingly operates on + * the range 0.0f..1.0f so we have to convert every texel + * into a number between 0.0f and 1.0f + * + * @xCoord and yCoord taking xCoord as the example. + * texel_center.x is the center of the pixel which we added 0.5f + * to ensure it is center as a fraction of the + * image width. + * texel_step.x is the width of one pixel as a fraction 1.0f / width + * xCoord therefore is the vector of the surrounding pixels centered. + * + * e.g. + * Width 1928, sample pixel 100: + * + * texel_center.x = 100.5 / 1928 + * texel_step.x = 1 / 1928 + * xCoord => adjacent pixels (98.5, 99.5, 101.5, 102.5) / 1928 + * + * The division by width is necessary because we sample between 0.0f..1.0f + */ + vec2 pos = floor(center.zw); + vec2 texel_center = (pos - tex_bayer_first_red + 0.5) / tex_size; + vec2 texel_step = 1.0 / tex_size; + vec4 xCoord = texel_center.x + vec4(-2.0, -1.0, 1.0, 2.0) * texel_step.x; + vec4 yCoord = texel_center.y + vec4(-2.0, -1.0, 1.0, 2.0) * texel_step.y; + samples.row0a = fetch(xCoord[1], yCoord[2]); - samples.row0b = fetch(center.x, yCoord[2]); + samples.row0b = fetch(texel_center.x, yCoord[2]); samples.row0c = fetch(xCoord[2], yCoord[2]); - samples.row1a = fetch(xCoord[1], center.y); - samples.center = fetch(center.x, center.y); - samples.row1c = fetch(xCoord[2], center.y); + samples.row1a = fetch(xCoord[1], texel_center.y); + samples.center = fetch(texel_center.x, texel_center.y); + samples.row1c = fetch(xCoord[2], texel_center.y); samples.row2a = fetch(xCoord[1], yCoord[1]); - samples.row2b = fetch(center.x, yCoord[1]); + samples.row2b = fetch(texel_center.x, yCoord[1]); samples.row2c = fetch(xCoord[2], yCoord[1]); } diff --git a/src/libcamera/shaders/bayer_unpacked.vert b/src/libcamera/shaders/bayer_unpacked.vert index 423dde0fa..72a6d1bc2 100644 --- a/src/libcamera/shaders/bayer_unpacked.vert +++ b/src/libcamera/shaders/bayer_unpacked.vert @@ -22,7 +22,6 @@ attribute vec2 textureIn; uniform mat4 proj_matrix; uniform vec2 tex_size; /* The texture size in pixels */ -uniform vec2 tex_step; /** Pixel position of the first red pixel in the */ /** Bayer pattern. [{0,1}, {0, 1}]*/ @@ -32,24 +31,11 @@ uniform vec2 tex_bayer_first_red; .zw = ...on the range [0, sourceSize], offset by firstRed */ varying vec4 center; -/** center.x + (-2/w, -1/w, 1/w, 2/w); These are the x-positions */ -/** of the adjacent pixels.*/ -varying vec4 xCoord; - -/** center.y + (-2/h, -1/h, 1/h, 2/h); These are the y-positions */ -/** of the adjacent pixels.*/ -varying vec4 yCoord; - uniform float stride_factor; void main(void) { center.xy = vec2(textureIn.x * stride_factor, textureIn.y); center.zw = textureIn * tex_size + tex_bayer_first_red; - xCoord = center.x + vec4(-2.0 * tex_step.x, - -tex_step.x, tex_step.x, 2.0 * tex_step.x); - yCoord = center.y + vec4(-2.0 * tex_step.y, - -tex_step.y, tex_step.y, 2.0 * tex_step.y); - gl_Position = proj_matrix * vertexIn; } From patchwork Wed Nov 18 09:57:33 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: 28988 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 0A6DBBDE17 for ; Wed, 18 Nov 2026 09:58:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A0E476A8FF; Wed, 18 Nov 2026 10:58:36 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="JhRGkL+J"; 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 11B176A8F4 for ; Wed, 18 Nov 2026 10:58:16 +0100 (CET) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-4a5024b3c28so752348f8f.0 for ; Wed, 18 Nov 2026 01:58:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995895; x=1795600695; 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=7AKjWY+g5ALOXEY2gV5O8weT0+WGv5bQT6WaY62CpK4=; b=JhRGkL+Jx67SxvZDck+HGQQPkgM578TGQfxxDvNDGhicOJWFlhlUJXhCqyvGLMSp6g 8xDxMjxGZuU+ehJNqGWpSUX/lwhXzPPo/lSkLBlDm3f+ht4P83NZFDwbbP/nOgIkMqwz k+ljN/Al6HVnF0MptFDYrQuhkpPbQu5xZZv4KqdZ8otq3hT7BphuuuG/31IenFG+shUQ u+/QHg7Q3VIzzPyZ1DGc04oCevmpWF3GA5ys2XrLq83CbbXLP5vT5QpMsJJqYlAB4V+1 ChyzUkHCd80efRlRptwOGD3u9OH0MnSYXfFagN5GY60IBDbJ4nH/s3MSunLI4YttjXWB V0bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995895; x=1795600695; 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=7AKjWY+g5ALOXEY2gV5O8weT0+WGv5bQT6WaY62CpK4=; b=NP8oc87A8SzsbhIlehh5Gk1LsSV06wb/0yRKIITZhnp9ddOllUNE+4i/K3p8L1JW5j Yx1DXznrvpaQS3dhc5048n865JNO3EeD5HpdvRcRFg41MqOhq5qxDJPQOFkeIDnrxgUE EFqQcAj5nAmXwkxdLZrC2o1jXWqfJtgXRTD9b6YcC+DZ8rwAaD20JNtjVj/xcM3GWny+ SW/yg1bgt7x0HSzu0vpXqwCtcNL+Y++qVxyd1x5jAYJ0vOYSzWrVrk8m7wko7KYx+0Lq EBurHPMrudaeSGaGKfXa6tvwzZ3QDId5gPEUQZgqvwYtpFIPRk4kIToIh4DAv0hStlkh B1Mw== X-Gm-Message-State: APuU4Z/op/mERfmH3U1z3cTkLiTNmK0R+aLHhz+K3tDdXseBlJ/AxA0S xMWX/ELLPZ9hLh38Mgg0Qi76e1ATqufIITBzpz1Idz+3wHILw878Qqhv1M45jPgHWzvgFKpajoE ujgL+zS0= X-Gm-Gg: AZFdTZdwcFITIOBs2v+euUA+Jh95TOZ1HxlrnFnaVI/kEn2h+hT+KC+fvJVf2nqy3SO +3V9DHqU/KxvAvQ/+lcVCE0M2rYgOfWdSYy0SXajJ9c7TjzVWI5z5BHjMd2BOWP5nqNZFAauRso jg1y3L5ONqYUCwqLv5sPU631ynA5vO2Q2JJPOT012zZUmq+clWsDxjaT3IJQQCSi5rziFGFL+YE TzYf1EBy1wA5g2IYvJCgBkXFwPwf2OAsqZTfv2bDGZEqCeRg6GyhIPl2AXk5KY1WzC/0gpHT8WY ULo5dAkuQgQJ2LEYS44X3cNM6mbJuyzU37KFjVlKIbC3CPiaP+bOT5TAK7lpLTpMuVENQOsPv5x v0OGH4Xqt6Fa4LbAIrzs4FFUnOzXEV+4r/OFeuPZY+Jh88pWhNFVL6sjQq0t0sQcYLiNZFuCabW s8HMtdEgR8JwmF18l3HK+rdRSWI1aFRVr+UuDIP2dc3pjvwQb8qULz0i8Fl6chUP3SJLCRhuyIJ 8twOHggTLgvsnv8VrvrxqiDVJaW2uOH5+uCqvEI7k+rQ9rwxZEsgslM8hQw/cBzc5qrE/K+GpYw Vk4fByNIM9sMoxysslnTu4q9vxH4mYydiREjdivyD9JzqQ== X-Received: by 2002:a05:6000:4b0e:b0:491:c392:1f31 with SMTP id ffacd0b85a97d-4a377f4eef4mr11080139f8f.28.1794995895626; Wed, 18 Nov 2026 01:58:15 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:15 -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 26/26] libcamera: software_isp: gpu_pipeline_shader_pass_demosiac: Remove unnecessary tex_step input Date: Wed, 18 Nov 2026 10:57:33 +0100 Message-ID: <20261118095735.170587-27-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" The fragment shader associated with this class no longer depends on tex_step as input. Thus we can shed the supporting infrastructure feeding it. Signed-off-by: Bryan O'Donoghue --- .../software_isp/gpu_pipeline_shader_pass_demosiac.cpp | 6 ------ .../software_isp/gpu_pipeline_shader_pass_demosiac.h | 1 - 2 files changed, 7 deletions(-) diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp index bceb5f68d..3232ff3f5 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.cpp @@ -111,7 +111,6 @@ int GpuIspShaderPassDemosiac::getShaderVariableLocations(void) textureUniformBayerFirstRed_ = glGetUniformLocation(programId_, "tex_bayer_first_red"); textureUniformProjMatrix_ = glGetUniformLocation(programId_, "proj_matrix"); textureUniformBayerDataIn_ = glGetUniformLocation(programId_, "tex_y"); - textureUniformStep_ = glGetUniformLocation(programId_, "tex_step"); textureUniformSize_ = glGetUniformLocation(programId_, "tex_size"); LOG(GpuShaderDemosiac, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_ @@ -137,8 +136,6 @@ void GpuIspShaderPassDemosiac::setShaderVariableValues(eGLImage &eglImageIn, con 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 the output size from the native size the algorithm produces for @@ -195,7 +192,6 @@ void GpuIspShaderPassDemosiac::setShaderVariableValues(eGLImage &eglImageIn, con */ glUniform2fv(textureUniformBayerFirstRed_, 1, firstRed); glUniform2fv(textureUniformSize_, 1, imgSize); - glUniform2fv(textureUniformStep_, 1, Step); glUniform1f(textureUniformStrideFactor_, Stride); glUniformMatrix4fv(textureUniformProjMatrix_, 1, GL_FALSE, projMatrix); @@ -209,8 +205,6 @@ void GpuIspShaderPassDemosiac::setShaderVariableValues(eGLImage &eglImageIn, con << " firstRed.y " << firstRed[1] << " textureUniformSize_.width " << imgSize[0] << " textureUniformSize_.height " << imgSize[1] - << " textureUniformStep_.x " << Step[0] - << " textureUniformStep_.y " << Step[1] << " textureUniformStrideFactor_ " << Stride << " textureUniformProjMatrix_ " << textureUniformProjMatrix_; diff --git a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h index 4d91254a2..0d9d02547 100644 --- a/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h +++ b/src/libcamera/software_isp/gpu_pipeline_shader_pass_demosiac.h @@ -44,7 +44,6 @@ public: const char *name() const override { return "GpuIspShaderPassDemosiac"; } private: /* Shader parameters */ - GLint textureUniformStep_; GLint textureUniformSize_; /* Per-frame AWB gains */