[v5,11/24] libcamera: shaders: Fix input sampling when width != stride
diff mbox series

Message ID 20251127023739.179652-12-bryan.odonoghue@linaro.org
State New
Headers show
Series
  • Add GLES 2.0 GPUISP to libcamera
Related show

Commit Message

Bryan O'Donoghue Nov. 27, 2025, 2:37 a.m. UTC
From: Hans de Goede <johannes.goede@oss.qualcomm.com>

When bayer_unpacked.vert is calculating the center and x/yCoord values
stride != width is taken into account for x/yCoord deltas since it is taken
into account by debayer_egl when setting the x part of tex_step uniform.

But it is not taken into account for the center.x which is just directly
copied from textureIn, leading to the input width sampling covering
the entire input stride instead of just covering the input width.

Use the existing and currently unused stride_factor uniform to pass
the width/stride ratio and correct center.x for this. This fixes
the misrendering seen on x86 laptops which is caused by the CSI2 receiver
there requiring a stride which is a multiple of 32 often leading to
stride != width.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 src/libcamera/shaders/bayer_unpacked.vert | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/shaders/bayer_unpacked.vert b/src/libcamera/shaders/bayer_unpacked.vert
index fb5109eee..423dde0fa 100644
--- a/src/libcamera/shaders/bayer_unpacked.vert
+++ b/src/libcamera/shaders/bayer_unpacked.vert
@@ -21,7 +21,7 @@  attribute vec2 textureIn;
 
 uniform mat4 proj_matrix;
 
-uniform vec2 tex_size;	/* The texture size in pixels */
+uniform vec2 tex_size;  /* The texture size in pixels */
 uniform vec2 tex_step;
 
 /** Pixel position of the first red pixel in the */
@@ -40,8 +40,10 @@  varying vec4            xCoord;
 /** of the adjacent pixels.*/
 varying vec4            yCoord;
 
+uniform float stride_factor;
+
 void main(void) {
-    center.xy = textureIn;
+    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,