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;