{"id":26939,"url":"https://patchwork.libcamera.org/api/patches/26939/?format=json","web_url":"https://patchwork.libcamera.org/patch/26939/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260618122245.946138-8-bryan.odonoghue@linaro.org>","date":"2026-06-18T12:22:20","name":"[07/30] libcamera: software_isp: gpu: Switch to using GpuIspShaderPassDemosiac","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"b3e1824d364a0163cc759279dadd463165336e94","submitter":{"id":175,"url":"https://patchwork.libcamera.org/api/people/175/?format=json","name":"Bryan O'Donoghue","email":"bryan.odonoghue@linaro.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26939/mbox/","series":[{"id":6005,"url":"https://patchwork.libcamera.org/api/series/6005/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=6005","date":"2026-06-18T12:22:13","name":"RFC/RFT: gpuisp: Multipass with speed optimisations on top","version":1,"mbox":"https://patchwork.libcamera.org/series/6005/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26939/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26939/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5F770C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 18 Jun 2026 12:23:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BDD6363282;\n\tThu, 18 Jun 2026 14:23:13 +0200 (CEST)","from mail-wm1-x331.google.com (mail-wm1-x331.google.com\n\t[IPv6:2a00:1450:4864:20::331])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 21716629A8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Jun 2026 14:23:03 +0200 (CEST)","by mail-wm1-x331.google.com with SMTP id\n\t5b1f17b1804b1-490a76757e5so5337325e9.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Jun 2026 05:23:03 -0700 (PDT)","from inspiron14p-linux ([109.76.144.236])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-4922fa3a4easm275198015e9.3.2026.06.18.05.23.01\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 18 Jun 2026 05:23:02 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"ihEb2XJ1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1781785383; x=1782390183;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=VB0s4jG0bcGQ61Eh7lGd1mDOIM5NsnJDGJohBvZSWks=;\n\tb=ihEb2XJ1Wy75pBV8OLmM7xQKROslUCHR6mguTV4pgzfi+d6JOcfJBU0Y0D9T2NyAgE\n\t2Ip+a0Saq5j1Xku2GnVaNKqlNVwpG03WCssNKTVESnYurRNBXo7pntJG97F8za1d6ow7\n\tfOO9zj7wCWgmrmtje2qsXPwHkwVUB0Ak7Alp2fd2yMYmR0PTjw7ZesDQJuXV+XyqQp0/\n\tiCWu7OXaURM5UfL5TrIv2zc3cq6d14+/pyh0B2NUOCyMPaFtx8ZQD8uPh9dx8/DCvfqg\n\two9x35wPRvFxADKHfqPw66BepKc90cRSU33NzTMtqWDOIZeIjYZWIklIqdXaMW9ILMlX\n\tjAJg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1781785383; x=1782390183;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=VB0s4jG0bcGQ61Eh7lGd1mDOIM5NsnJDGJohBvZSWks=;\n\tb=oX1+okDic/oG2JnrOAdxHSLhQLoCgTybLIiwARaXngEFLAPdVFqCylCzhfWSi1lRKB\n\tbgjDllfK2MNjqdOnwqY/5kt9Jgge5VpuRH+1OeoVCRnv5WGjvK/1X+8IlNNFAZvS6wSl\n\tNBjch4muEsp3M2WKw1J2vc/R1xV7tpHtBelKE1C4pWCHedO8v6O3mb5IAPmFrynQc/IM\n\tZRY1+L60U+jBnQ7+MDJP3bKMNknOFxWHhJQTo477iBymtl+vEGpCcXOf805pASuVbF0q\n\teMqp0e+WLuqcjFcpBaUkfdEC7n7BRjepR0OTQ3MEBIUqrMWY04YyKTAp8xnqFfFJQv4m\n\tC3jw==","X-Gm-Message-State":"AOJu0YygPpTc+l4ggEZ7p98EuZSMBx89jXaHK/4LuJzObvyixkQDx6CT\n\t8WTLVxPSTSSOZfR+/CptxYe5znZtlA2A/+sZZnxo3LED++3L5gXDSMPdxzz0hZJssNbcvZPdC/b\n\t3KhTumsU=","X-Gm-Gg":"AfdE7ckvayd1tRoDXyOFi2FBNQRoUVBY/KLX+N0JRcGf827/83vOArm4BPMBFvAcXFv\n\tTP5q9le2A+eQ0nUNAZP1bFdIuXWlSSZThNkx9YYyl44S6xKICErkJlfDkuAT6yL2TLm/Bv8WSH6\n\tHeLnB28rOlAFRvf9rAmcRo68FxHQBOAWDWnY/ObQrvLZyRhlmIyxwaEj95XjNgLUywLRnFOPLeh\n\tvYcShumhkBXQEcHh79V5lOKe4UM8HjbIkpt1nu5KXfwibLOU2NROzl6llqH/ZT6HrQmowlecASp\n\ttDSX3U3EyIQ0JdjbT6gEIZMpsPV8f7LlsB9WVxuocYu1Z2znHFmIqm7N26/Z5qMvRUfLTRUyOhZ\n\t9wjiI+/RHflgQOfyHOqrpqBSw+AlzRUDeXVQqmtqA7SyDY3oGPxjtMg7gxEnUw689zKMlDkw5Kx\n\t0oYrebTdVHOiIdKQM7/6OembkSV7B5","X-Received":"by 2002:a05:600c:5394:b0:490:aef9:aa3b with SMTP id\n\t5b1f17b1804b1-4923822b876mr56053925e9.32.1781785382457; \n\tThu, 18 Jun 2026 05:23:02 -0700 (PDT)","From":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","To":"libcamera-devel@lists.libcamera.org","Cc":"bryan.odonoghue@linaro.org,\n\tpavel@ucw.cz","Subject":"[PATCH 07/30] libcamera: software_isp: gpu: Switch to using\n\tGpuIspShaderPassDemosiac","Date":"Thu, 18 Jun 2026 13:22:20 +0100","Message-ID":"<20260618122245.946138-8-bryan.odonoghue@linaro.org>","X-Mailer":"git-send-email 2.54.0","In-Reply-To":"<20260618122245.946138-1-bryan.odonoghue@linaro.org>","References":"<20260618122245.946138-1-bryan.odonoghue@linaro.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Switch to using GpuIspShaderPassDemosiac as the first instance of our\nmulti-pass GPUISP implementation.\n\nSubsequent patches will move elements of this leviathan into discreet\nelements with an objective of eliminating register spill, separation of\nconcerns and de-spaghettification.\n\nCode red patches are always best.\n\nSigned-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n---\n src/libcamera/egl.cpp                         |   6 +-\n .../software_isp_pipeline_gpu.cpp             | 325 +-----------------\n .../software_isp/software_isp_pipeline_gpu.h  |  41 +--\n 3 files changed, 20 insertions(+), 352 deletions(-)","diff":"diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp\nindex 3ea694d7c..4da335a53 100644\n--- a/src/libcamera/egl.cpp\n+++ b/src/libcamera/egl.cpp\n@@ -153,7 +153,6 @@ int eGL::attachTextureToFBO(eGLImage &eglImage)\n int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output)\n {\n \tEGLint drm_format;\n-\tint ret;\n \n \tASSERT(tid_ == Thread::currentId());\n \n@@ -213,10 +212,7 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output)\n \tglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);\n \tglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);\n \n-\tif (output)\n-\t\tret = attachTextureToFBO(eglImage);\n-\n-\treturn ret;\n+\treturn 0;\n }\n \n /**\ndiff --git a/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp b/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp\nindex 6f988d672..6f329cf40 100644\n--- a/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp\n+++ b/src/libcamera/software_isp/software_isp_pipeline_gpu.cpp\n@@ -41,7 +41,7 @@ namespace libcamera {\n  * \\param[in] cm The camera manager\n  */\n SoftwareIspPipelineGpu::SoftwareIspPipelineGpu(std::unique_ptr<SwStatsCpu> stats, const CameraManager &cm)\n-\t: SoftwareIspPipeline(cm), stats_(std::move(stats))\n+\t: SoftwareIspPipeline(cm), stats_(std::move(stats)), gpuIspShaderPassDemosiac_(egl_)\n {\n }\n \n@@ -109,186 +109,13 @@ int SoftwareIspPipelineGpu::getOutputConfig(PixelFormat outputFormat, DebayerOut\n \treturn -EINVAL;\n }\n \n-int SoftwareIspPipelineGpu::getShaderVariableLocations(void)\n-{\n-\tattributeVertex_ = glGetAttribLocation(programId_, \"vertexIn\");\n-\tattributeTexture_ = glGetAttribLocation(programId_, \"textureIn\");\n-\n-\ttextureUniformBayerDataIn_ = glGetUniformLocation(programId_, \"tex_y\");\n-\tccmUniformDataIn_ = glGetUniformLocation(programId_, \"ccm\");\n-\tblackLevelUniformDataIn_ = glGetUniformLocation(programId_, \"blacklevel\");\n-\tgammaUniformDataIn_ = glGetUniformLocation(programId_, \"gamma\");\n-\tcontrastExpUniformDataIn_ = glGetUniformLocation(programId_, \"contrastExp\");\n-\n-\ttextureUniformStep_ = glGetUniformLocation(programId_, \"tex_step\");\n-\ttextureUniformSize_ = glGetUniformLocation(programId_, \"tex_size\");\n-\ttextureUniformStrideFactor_ = glGetUniformLocation(programId_, \"stride_factor\");\n-\ttextureUniformBayerFirstRed_ = glGetUniformLocation(programId_, \"tex_bayer_first_red\");\n-\ttextureUniformProjMatrix_ = glGetUniformLocation(programId_, \"proj_matrix\");\n-\n-\tLOG(Debayer, Debug) << \"vertexIn \" << attributeVertex_ << \" textureIn \" << attributeTexture_\n-\t\t\t    << \" tex_y \" << textureUniformBayerDataIn_\n-\t\t\t    << \" ccm \" << ccmUniformDataIn_\n-\t\t\t    << \" blacklevel \" << blackLevelUniformDataIn_\n-\t\t\t    << \" gamma \" << gammaUniformDataIn_\n-\t\t\t    << \" contrastExp \" << contrastExpUniformDataIn_\n-\t\t\t    << \" tex_step \" << textureUniformStep_\n-\t\t\t    << \" tex_size \" << textureUniformSize_\n-\t\t\t    << \" stride_factor \" << textureUniformStrideFactor_\n-\t\t\t    << \" tex_bayer_first_red \" << textureUniformBayerFirstRed_\n-\t\t\t    << \" proj_matrix \" << textureUniformProjMatrix_;\n-\treturn 0;\n-}\n-\n int SoftwareIspPipelineGpu::initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat)\n {\n-\tstd::vector<std::string> shaderEnv;\n-\tunsigned int fragmentShaderDataLen = 0;\n-\tconst unsigned char *fragmentShaderData = 0;\n-\tunsigned int vertexShaderDataLen = 0;\n-\tconst unsigned char *vertexShaderData = 0;\n-\tGLenum err;\n-\n-\t/* Target gles 100 glsl requires \"#version x\" as first directive in shader */\n-\tegl_.pushEnv(shaderEnv, \"#version 100\");\n-\n-\t/* Specify GL_OES_EGL_image_external */\n-\tegl_.pushEnv(shaderEnv, \"#extension GL_OES_EGL_image_external: enable\");\n-\n-\t/*\n-\t * Tell shaders how to re-order output taking account of how the pixels\n-\t * are actually stored by EGL.\n-\t */\n-\tswitch (outputFormat) {\n-\tcase formats::ARGB8888:\n-\tcase formats::XRGB8888:\n-\t\tbreak;\n-\tcase formats::ABGR8888:\n-\tcase formats::XBGR8888:\n-\t\tegl_.pushEnv(shaderEnv, \"#define SWAP_BLUE\");\n-\t\tbreak;\n-\tdefault:\n-\t\tLOG(Debayer, Error) << \"Unsupported output format\";\n-\t\treturn -EINVAL;\n-\t}\n-\n-\t/* Pixel location parameters */\n-\tglFormat_ = GL_LUMINANCE;\n-\tbytesPerPixel_ = 1;\n-\tshaderStridePixels_ = inputConfig_.stride;\n-\n-\tswitch (inputFormat) {\n-\tcase libcamera::formats::SBGGR8:\n-\tcase libcamera::formats::SBGGR10_CSI2P:\n-\tcase libcamera::formats::SBGGR12_CSI2P:\n-\t\tfirstRed_x_ = 1.0;\n-\t\tfirstRed_y_ = 1.0;\n-\t\tbreak;\n-\tcase libcamera::formats::SGBRG8:\n-\tcase libcamera::formats::SGBRG10_CSI2P:\n-\tcase libcamera::formats::SGBRG12_CSI2P:\n-\t\tfirstRed_x_ = 0.0;\n-\t\tfirstRed_y_ = 1.0;\n-\t\tbreak;\n-\tcase libcamera::formats::SGRBG8:\n-\tcase libcamera::formats::SGRBG10_CSI2P:\n-\tcase libcamera::formats::SGRBG12_CSI2P:\n-\t\tfirstRed_x_ = 1.0;\n-\t\tfirstRed_y_ = 0.0;\n-\t\tbreak;\n-\tcase libcamera::formats::SRGGB8:\n-\tcase libcamera::formats::SRGGB10_CSI2P:\n-\tcase libcamera::formats::SRGGB12_CSI2P:\n-\t\tfirstRed_x_ = 0.0;\n-\t\tfirstRed_y_ = 0.0;\n-\t\tbreak;\n-\tdefault:\n-\t\tLOG(Debayer, Error) << \"Unsupported input format\";\n-\t\treturn -EINVAL;\n-\t};\n-\n-\t/* Shader selection */\n-\tswitch (inputFormat) {\n-\tcase libcamera::formats::SBGGR8:\n-\tcase libcamera::formats::SGBRG8:\n-\tcase libcamera::formats::SGRBG8:\n-\tcase libcamera::formats::SRGGB8:\n-\t\tfragmentShaderData = bayer_unpacked_frag;\n-\t\tfragmentShaderDataLen = bayer_unpacked_frag_len;\n-\t\tvertexShaderData = bayer_unpacked_vert;\n-\t\tvertexShaderDataLen = bayer_unpacked_vert_len;\n-\t\tbreak;\n-\tcase libcamera::formats::SBGGR10_CSI2P:\n-\tcase libcamera::formats::SGBRG10_CSI2P:\n-\tcase libcamera::formats::SGRBG10_CSI2P:\n-\tcase libcamera::formats::SRGGB10_CSI2P:\n-\t\tegl_.pushEnv(shaderEnv, \"#define RAW10P\");\n-\t\tif (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) {\n-\t\t\tfragmentShaderData = bayer_unpacked_frag;\n-\t\t\tfragmentShaderDataLen = bayer_unpacked_frag_len;\n-\t\t\tvertexShaderData = bayer_unpacked_vert;\n-\t\t\tvertexShaderDataLen = bayer_unpacked_vert_len;\n-\t\t\tglFormat_ = GL_RG;\n-\t\t\tbytesPerPixel_ = 2;\n-\t\t} else {\n-\t\t\tfragmentShaderData = bayer_1x_packed_frag;\n-\t\t\tfragmentShaderDataLen = bayer_1x_packed_frag_len;\n-\t\t\tvertexShaderData = identity_vert;\n-\t\t\tvertexShaderDataLen = identity_vert_len;\n-\t\t\tshaderStridePixels_ = width_;\n-\t\t}\n-\t\tbreak;\n-\tcase libcamera::formats::SBGGR12_CSI2P:\n-\tcase libcamera::formats::SGBRG12_CSI2P:\n-\tcase libcamera::formats::SGRBG12_CSI2P:\n-\tcase libcamera::formats::SRGGB12_CSI2P:\n-\t\tegl_.pushEnv(shaderEnv, \"#define RAW12P\");\n-\t\tif (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) {\n-\t\t\tfragmentShaderData = bayer_unpacked_frag;\n-\t\t\tfragmentShaderDataLen = bayer_unpacked_frag_len;\n-\t\t\tvertexShaderData = bayer_unpacked_vert;\n-\t\t\tvertexShaderDataLen = bayer_unpacked_vert_len;\n-\t\t\tglFormat_ = GL_RG;\n-\t\t\tbytesPerPixel_ = 2;\n-\t\t} else {\n-\t\t\tfragmentShaderData = bayer_1x_packed_frag;\n-\t\t\tfragmentShaderDataLen = bayer_1x_packed_frag_len;\n-\t\t\tvertexShaderData = identity_vert;\n-\t\t\tvertexShaderDataLen = identity_vert_len;\n-\t\t\tshaderStridePixels_ = width_;\n-\t\t}\n-\t\tbreak;\n-\t};\n-\n-\tif (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, vertexShaderDataLen, shaderEnv)) {\n-\t\tLOG(Debayer, Error) << \"Compile vertex shader fail\";\n-\t\treturn -ENODEV;\n-\t}\n-\tutils::scope_exit vShaderGuard([&] { glDeleteShader(vertexShaderId_); });\n-\n-\tif (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData, fragmentShaderDataLen, shaderEnv)) {\n-\t\tLOG(Debayer, Error) << \"Compile fragment shader fail\";\n-\t\treturn -ENODEV;\n-\t}\n-\tutils::scope_exit fShaderGuard([&] { glDeleteShader(fragmentShaderId_); });\n+\tint ret;\n \n-\tif (egl_.linkProgram(programId_, vertexShaderId_, fragmentShaderId_)) {\n-\t\tLOG(Debayer, Error) << \"Linking program fail\";\n-\t\treturn -ENODEV;\n-\t}\n-\n-\tegl_.dumpShaderSource(vertexShaderId_);\n-\tegl_.dumpShaderSource(fragmentShaderId_);\n-\n-\t/* Ensure we set the programId_ */\n-\tegl_.useProgram(programId_);\n-\terr = glGetError();\n-\tif (err != GL_NO_ERROR) {\n-\t\tLOG(Debayer, Error) << \"Use program error \" << err;\n-\t\treturn -ENODEV;\n-\t}\n+\tret = gpuIspShaderPassDemosiac_.initShaders(inputFormat, outputFormat);\n \n-\treturn getShaderVariableLocations();\n+\treturn ret;\n }\n \n int SoftwareIspPipelineGpu::configure(const StreamConfiguration &inputCfg,\n@@ -351,6 +178,12 @@ int SoftwareIspPipelineGpu::configure(const StreamConfiguration &inputCfg,\n \t */\n \tstats_->setWindow(Rectangle(window_.size()));\n \n+\t/* Configure for one pass */\n+\tPassConfig rawSensorIn = { inputCfg.size, inputConfig_.stride, inputPixelFormat_, window_ };\n+\tPassConfig rgbaOut = { outputCfg.size, outputConfig_.stride, outputPixelFormat_, Rectangle(outputSize_) };\n+\n+\tgpuIspShaderPassDemosiac_.configure(rawSensorIn, rgbaOut);\n+\n \treturn 0;\n }\n \n@@ -388,132 +221,10 @@ SoftwareIspPipelineGpu::strideAndFrameSize(const PixelFormat &outputFormat, cons\n \treturn std::make_tuple(stride, stride * size.height);\n }\n \n-void SoftwareIspPipelineGpu::setShaderVariableValues(const DebayerParams &params)\n-{\n-\t/*\n-\t * Raw Bayer 8-bit, and packed raw Bayer 10-bit/12-bit formats\n-\t * are stored in a GL_LUMINANCE texture. The texture width is\n-\t * equal to the stride.\n-\t */\n-\tGLfloat firstRed[] = { firstRed_x_, firstRed_y_ };\n-\tGLfloat imgSize[] = { (GLfloat)width_,\n-\t\t\t      (GLfloat)height_ };\n-\tGLfloat Step[] = { static_cast<float>(bytesPerPixel_) / (inputConfig_.stride - 1),\n-\t\t\t   1.0f / (height_ - 1) };\n-\tGLfloat Stride = (GLfloat)width_ / (shaderStridePixels_ / bytesPerPixel_);\n-\t/*\n-\t * Scale input to output size, keeping the aspect ratio and preferring\n-\t * cropping over black bars.\n-\t */\n-\tGLfloat scale = std::max((GLfloat)window_.width / width_,\n-\t\t\t\t (GLfloat)window_.height / height_);\n-\tGLfloat trans = -(1.0f - scale);\n-\tGLfloat projMatrix[] = {\n-\t\tscale, 0, 0, 0,\n-\t\t0, scale, 0, 0,\n-\t\t0, 0, 1, 0,\n-\t\ttrans, trans, 0, 1\n-\t};\n-\t/* Static const coordinates */\n-\tstatic const GLfloat vcoordinates[4][2] = {\n-\t\t{ -1.0f, -1.0f },\n-\t\t{ -1.0f, +1.0f },\n-\t\t{ +1.0f, +1.0f },\n-\t\t{ +1.0f, -1.0f },\n-\t};\n-\tstatic const GLfloat tcoordinates[4][2] = {\n-\t\t{ 0.0f, 0.0f },\n-\t\t{ 0.0f, 1.0f },\n-\t\t{ 1.0f, 1.0f },\n-\t\t{ 1.0f, 0.0f },\n-\t};\n-\n-\t/* vertexIn - bayer_8.vert */\n-\tglEnableVertexAttribArray(attributeVertex_);\n-\tglVertexAttribPointer(attributeVertex_, 2, GL_FLOAT, GL_TRUE,\n-\t\t\t      2 * sizeof(GLfloat), vcoordinates);\n-\n-\t/* textureIn - bayer_8.vert */\n-\tglEnableVertexAttribArray(attributeTexture_);\n-\tglVertexAttribPointer(attributeTexture_, 2, GL_FLOAT, GL_TRUE,\n-\t\t\t      2 * sizeof(GLfloat), tcoordinates);\n-\n-\t/*\n-\t * Set the sampler2D to the respective texture unit for each texutre\n-\t * To simultaneously sample multiple textures we need to use multiple\n-\t * texture units\n-\t */\n-\tglUniform1i(textureUniformBayerDataIn_, eglImageBayerIn_->texture_unit_uniform_id_);\n-\n-\t/*\n-\t * These values are:\n-\t * firstRed = tex_bayer_first_red - bayer_8.vert\n-\t * imgSize = tex_size - bayer_8.vert\n-\t * step = tex_step - bayer_8.vert\n-\t * Stride = stride_factor identity.vert\n-\t * textureUniformProjMatri = No scaling\n-\t */\n-\tglUniform2fv(textureUniformBayerFirstRed_, 1, firstRed);\n-\tglUniform2fv(textureUniformSize_, 1, imgSize);\n-\tglUniform2fv(textureUniformStep_, 1, Step);\n-\tglUniform1f(textureUniformStrideFactor_, Stride);\n-\tglUniformMatrix4fv(textureUniformProjMatrix_, 1, GL_FALSE, projMatrix);\n-\n-\tLOG(Debayer, Debug) << \"vertexIn \" << attributeVertex_ << \" textureIn \" << attributeTexture_\n-\t\t\t    << \" tex_y \" << textureUniformBayerDataIn_\n-\t\t\t    << \" tex_step \" << textureUniformStep_\n-\t\t\t    << \" tex_size \" << textureUniformSize_\n-\t\t\t    << \" stride_factor \" << textureUniformStrideFactor_\n-\t\t\t    << \" tex_bayer_first_red \" << textureUniformBayerFirstRed_;\n-\n-\tLOG(Debayer, Debug) << \"textureUniformY_ = 0 \"\n-\t\t\t    << \" firstRed.x \" << firstRed[0]\n-\t\t\t    << \" firstRed.y \" << firstRed[1]\n-\t\t\t    << \" textureUniformSize_.width \" << imgSize[0]\n-\t\t\t    << \" textureUniformSize_.height \" << imgSize[1]\n-\t\t\t    << \" textureUniformStep_.x \" << Step[0]\n-\t\t\t    << \" textureUniformStep_.y \" << Step[1]\n-\t\t\t    << \" textureUniformStrideFactor_ \" << Stride\n-\t\t\t    << \" textureUniformProjMatrix_ \" << textureUniformProjMatrix_;\n-\n-\tGLfloat ccm[9] = {\n-\t\tparams.combinedMatrix[0][0],\n-\t\tparams.combinedMatrix[0][1],\n-\t\tparams.combinedMatrix[0][2],\n-\t\tparams.combinedMatrix[1][0],\n-\t\tparams.combinedMatrix[1][1],\n-\t\tparams.combinedMatrix[1][2],\n-\t\tparams.combinedMatrix[2][0],\n-\t\tparams.combinedMatrix[2][1],\n-\t\tparams.combinedMatrix[2][2],\n-\t};\n-\tglUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm);\n-\tLOG(Debayer, Debug) << \" ccmUniformDataIn_ \" << ccmUniformDataIn_ << \" data \" << params.combinedMatrix;\n-\n-\t/*\n-\t * 0 = Red, 1 = Green, 2 = Blue\n-\t */\n-\tglUniform3f(blackLevelUniformDataIn_, params.blackLevel[0], params.blackLevel[1], params.blackLevel[2]);\n-\tLOG(Debayer, Debug) << \" blackLevelUniformDataIn_ \" << blackLevelUniformDataIn_ << \" data \" << params.blackLevel;\n-\n-\t/*\n-\t * Gamma\n-\t */\n-\tglUniform1f(gammaUniformDataIn_, params.gamma);\n-\tLOG(Debayer, Debug) << \" gammaUniformDataIn_ \" << gammaUniformDataIn_ << \" data \" << params.gamma;\n-\n-\t/*\n-\t * Contrast\n-\t */\n-\tglUniform1f(contrastExpUniformDataIn_, params.contrastExp);\n-\tLOG(Debayer, Debug) << \" contrastExpUniformDataIn_ \" << contrastExpUniformDataIn_ << \" data \" << params.contrastExp;\n-\n-\treturn;\n-}\n-\n int SoftwareIspPipelineGpu::processGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams &params, std::optional<MappedFrameBuffer> *inMapped, std::optional<DmaSyncer> *inDmaSyncer)\n {\n \tbool dmabuf_import_succeeded = false;\n+\tint pipelineResult = 0;\n \n \t/* eGL context switch */\n \tegl_.makeCurrent();\n@@ -540,20 +251,17 @@ int SoftwareIspPipelineGpu::processGPU(FrameBuffer *input, FrameBuffer *output,\n \t/* Generate the output render framebuffer as render to texture */\n \tegl_.createOutputDMABufTexture2D(*eglImageRGBAOut_, output->planes()[0].fd.get());\n \n-\tsetShaderVariableValues(params);\n-\tglViewport(0, 0, width_, height_);\n-\tglClear(GL_COLOR_BUFFER_BIT);\n-\tglDrawArrays(GL_TRIANGLE_FAN, 0, DEBAYER_OPENGL_COORDS);\n+\tpipelineResult = gpuIspShaderPassDemosiac_.process(*eglImageBayerIn_, *eglImageRGBAOut_, width_, height_, params);\n \n \tGLenum err = glGetError();\n \tif (err != GL_NO_ERROR) {\n \t\tLOG(eGL, Error) << \"Drawing scene fail \" << err;\n-\t\treturn -ENODEV;\n+\t\tpipelineResult = -ENODEV;\n \t} else {\n \t\tegl_.flushOutput();\n \t}\n \n-\treturn 0;\n+\treturn pipelineResult;\n }\n \n void SoftwareIspPipelineGpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams &params)\n@@ -623,7 +331,7 @@ int SoftwareIspPipelineGpu::start()\n \t\treturn -EINVAL;\n \n \t/* Raw bayer input as texture */\n-\teglImageBayerIn_ = std::make_unique<eGLImage>(glFormat_, inputConfig_.stride / bytesPerPixel_, height_, inputConfig_.stride, GL_TEXTURE0, 0);\n+\teglImageBayerIn_ = std::make_unique<eGLImage>(gpuIspShaderPassDemosiac_.glFormat_, inputConfig_.stride / gpuIspShaderPassDemosiac_.getBytesPerPixel(), height_, inputConfig_.stride, GL_TEXTURE0, 0);\n \n \t/* Texture we will render to */\n \teglImageRGBAOut_ = std::make_unique<eGLImage>(GL_RGBA, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1);\n@@ -636,8 +344,7 @@ void SoftwareIspPipelineGpu::stop()\n \teglImageRGBAOut_.reset();\n \teglImageBayerIn_.reset();\n \n-\tif (programId_)\n-\t\tglDeleteProgram(programId_);\n+\tgpuIspShaderPassDemosiac_.stop();\n }\n \n SizeRange SoftwareIspPipelineGpu::sizes(PixelFormat inputFormat, const Size &inputSize)\ndiff --git a/src/libcamera/software_isp/software_isp_pipeline_gpu.h b/src/libcamera/software_isp/software_isp_pipeline_gpu.h\nindex f0515d889..6a9df2f04 100644\n--- a/src/libcamera/software_isp/software_isp_pipeline_gpu.h\n+++ b/src/libcamera/software_isp/software_isp_pipeline_gpu.h\n@@ -23,16 +23,12 @@\n #include \"libcamera/internal/software_isp/benchmark.h\"\n #include \"libcamera/internal/software_isp/swstats_cpu.h\"\n \n-#include <EGL/egl.h>\n-#include <EGL/eglext.h>\n-#include <GLES3/gl32.h>\n-\n #include \"software_isp_pipeline.h\"\n+#include \"gpu_pipeline_shader_pass_demosiac.h\"\n \n namespace libcamera {\n \n #define DEBAYER_EGL_MIN_SIMPLE_RGB_GAIN_TEXTURE_UNITS 4\n-#define DEBAYER_OPENGL_COORDS 4\n \n class CameraManager;\n \n@@ -68,48 +64,17 @@ private:\n \tint processGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams &params, std::optional<MappedFrameBuffer> *mappedInputBuffer, std::optional<DmaSyncer> *inputBufferDmaSyncer);\n \tvoid configureTexture(GLuint &texture);\n \n-\t/* Shader program identifiers */\n-\tGLuint vertexShaderId_ = 0;\n-\tGLuint fragmentShaderId_ = 0;\n-\tGLuint programId_ = 0;\n-\n \t/* Pointer to object representing input texture */\n \tstd::unique_ptr<eGLImage> eglImageBayerIn_;\n \tstd::unique_ptr<eGLImage> eglImageRGBAOut_;\n \n-\t/* Shader parameters */\n-\tfloat firstRed_x_;\n-\tfloat firstRed_y_;\n-\tGLint attributeVertex_;\n-\tGLint attributeTexture_;\n-\tGLint textureUniformStep_;\n-\tGLint textureUniformSize_;\n-\tGLint textureUniformStrideFactor_;\n-\tGLint textureUniformBayerFirstRed_;\n-\tGLint textureUniformProjMatrix_;\n-\n-\tGLint textureUniformBayerDataIn_;\n-\n-\t/* Represent per-frame CCM as a uniform vector of floats 3 x 3 */\n-\tGLint ccmUniformDataIn_;\n-\n-\t/* Black Level compensation */\n-\tGLint blackLevelUniformDataIn_;\n-\n-\t/* Gamma */\n-\tGLint gammaUniformDataIn_;\n-\n-\t/* Contrast */\n-\tGLint contrastExpUniformDataIn_;\n-\n \tRectangle window_;\n \tstd::unique_ptr<SwStatsCpu> stats_;\n \teGL egl_;\n \tuint32_t width_;\n \tuint32_t height_;\n-\tGLint glFormat_;\n-\tunsigned int bytesPerPixel_;\n-\tuint32_t shaderStridePixels_;\n+\n+\tGpuIspShaderPassDemosiac gpuIspShaderPassDemosiac_;\n };\n \n } /* namespace libcamera */\n","prefixes":["07/30"]}