[vlc-commits] opengl: avoid intermediate transpose step

Romain Vimont git at videolan.org
Mon Jan 27 17:45:47 CET 2020


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Wed Jan 15 14:46:59 2020 +0100| [1ef0a4de4ccd6e57f7b0a427b3e50153ab1d27a1] | committer: Thomas Guillem

opengl: avoid intermediate transpose step

Directly initialize the conversion matrix in place in column-major
order.

Note: We could not just pass GL_TRUE to the transpose parameter of
glUniformMatrix4fv, because it is not supported on OpenGL ES 2:

> GL_INVALID_VALUE is generated if transpose is not GL_FALSE.

<https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glUniform.xml>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1ef0a4de4ccd6e57f7b0a427b3e50153ab1d27a1
---

 modules/video_output/opengl/fragment_shaders.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index 078a0ac394..2ffd653a4c 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -96,7 +96,9 @@ init_conv_matrix(float conv_matrix_out[],
             space_matrix = MATRIX_BT709;
     }
 
-    /* Init the conversion matrix in row-major order. */
+    /* Init the conversion matrix in column-major order (OpenGL expects
+     * column-major order by default, and OpenGL ES does not support row-major
+     * order at all). */
 
     const float *range_matrix = color_range == COLOR_RANGE_FULL
                               ? MATRIX_COLOR_RANGE_FULL
@@ -111,15 +113,17 @@ init_conv_matrix(float conv_matrix_out[],
             double sum = 0;
             for (int k = 0; k < 3; ++k)
                 sum += space_matrix[y * 3 + k] * range_matrix[k * 4 + x];
-            conv_matrix_out[y * 4 + x] = sum;
+            /* Notice the reversed indices: x is now the row, y is the
+             * column. */
+            conv_matrix_out[x * 4 + y] = sum;
         }
     }
 
-    /* Add a row to fill a 4x4 matrix.
+    /* Add a row to fill a 4x4 matrix (remember it's in column-major order).
      * (non-square matrices are not supported on old OpenGL ES versions) */
-    conv_matrix_out[12] = 0;
-    conv_matrix_out[13] = 0;
-    conv_matrix_out[14] = 0;
+    conv_matrix_out[3] = 0;
+    conv_matrix_out[7] = 0;
+    conv_matrix_out[11] = 0;
     conv_matrix_out[15] = 1;
 }
 
@@ -131,7 +135,7 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, vlc_fourcc_t chroma,
 {
     /* The current implementation always converts from limited to full range. */
     const video_color_range_t range = COLOR_RANGE_LIMITED;
-    float matrix[4*4];
+    float *matrix = tc->yuv_coefficients;
     init_conv_matrix(matrix, yuv_space, range);
 
     if (desc->pixel_size == 2)
@@ -164,11 +168,6 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, vlc_fourcc_t chroma,
         }
     }
 
-    for (int i = 0; i < 4; i++) {
-        for (int j = 0; j < 4; j++)
-            tc->yuv_coefficients[i*4+j] = matrix[j*4+i];
-    }
-
     tc->yuv_color = true;
 
     *swap_uv = chroma == VLC_CODEC_YV12 || chroma == VLC_CODEC_YV9 ||



More information about the vlc-commits mailing list