[v2,3/3] libcamera: software_isp: debayer_egl: Only assign static shader variables once
diff mbox series

Message ID 20261027122844.56616-4-remy.alipoursafari@collabora.com
State New
Headers show
Series
  • Support rockchip-cif and do slight checks on softisp
Related show

Commit Message

Remy Alipoursafari Oct. 27, 2026, 12:28 p.m. UTC
Both uniforms and attributes in GLSL do not change from one shader
invocation to another, allowing static value assignments to be moved out
of the main loop, and only be assigned on start.

This results in only a negligible performance increase.

Signed-off-by: Remy Alipoursafari <remy.alipoursafari@collabora.com>
---
 src/libcamera/software_isp/debayer_egl.cpp | 21 +++++++++++++--------
 src/libcamera/software_isp/debayer_egl.h   |  1 +
 2 files changed, 14 insertions(+), 8 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp
index 5236e1f9..1386cb54 100644
--- a/src/libcamera/software_isp/debayer_egl.cpp
+++ b/src/libcamera/software_isp/debayer_egl.cpp
@@ -298,6 +298,8 @@  int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm
 		return -ENODEV;
 	}
 
+	setShaderUniformValues();
+
 	return 0;
 }
 
@@ -408,7 +410,7 @@  uint32_t DebayerEGL::preferredInputStride(const PixelFormat &inputFormat, const
 	return info.stride(size.width, 0, 256);
 }
 
-void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams &params)
+void DebayerEGL::setShaderUniformValues()
 {
 	/*
 	 * Raw Bayer 8-bit, and packed raw Bayer 10-bit/12-bit formats
@@ -459,13 +461,6 @@  void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara
 	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
@@ -496,6 +491,16 @@  void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara
 			    << " textureUniformStep_.y " << Step[1]
 			    << " textureUniformStrideFactor_ " << Stride
 			    << " textureUniformProjMatrix_ " << textureUniformProjMatrix_;
+}
+
+void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams &params)
+{
+	/*
+	 * 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_);
 
 	/* Pre-transpose matrix for GLES 2.0. */
 	Matrix<float, 3, 3> ccm = params.combinedMatrix.transpose();
diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h
index cbbc6a45..45692aa4 100644
--- a/src/libcamera/software_isp/debayer_egl.h
+++ b/src/libcamera/software_isp/debayer_egl.h
@@ -66,6 +66,7 @@  private:
 	static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
 	int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat);
 	int getShaderVariableLocations();
+	void setShaderUniformValues();
 	void setShaderVariableValues(eGLImage &eGLImageIn, const DebayerParams &params);
 	int debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams &params, std::optional<MappedFrameBuffer> *mappedInputBuffer, std::optional<DmaSyncer> *inputBufferDmaSyncer);