[vlc-commits] [Git][videolan/vlc][master] 6 commits: opengl: gl_common: add glGetShaderSource

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Sep 29 14:37:43 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
1f22c3af by Alexandre Janniaux at 2023-09-29T14:21:27+00:00
opengl: gl_common: add glGetShaderSource

Getting the shader source enable better debugging when an error happens.

- - - - -
bb82ea90 by Alexandre Janniaux at 2023-09-29T14:21:27+00:00
opengl: gl_util: dump shader in case of error

- - - - -
ce861a7c by Alexandre Janniaux at 2023-09-29T14:21:27+00:00
opengl: sampler: store the glsl version used

The GLSL version will be used to generate the correct function names for
non-forward compatible functions.

- - - - -
7ffcdfb3 by Alexandre Janniaux at 2023-09-29T14:21:27+00:00
opengl: sampler: fix deprecated usage of texture2D

texture() should be used after GLSL 130 on OpenGL, and must be used
after GLSL 300 es on OpenGL ES.

Fixes #28369

- - - - -
fcbf3899 by Alexandre Janniaux at 2023-09-29T14:21:27+00:00
opengl: gl_util: use early return

- - - - -
a7d9d5c3 by Alexandre Janniaux at 2023-09-29T14:21:27+00:00
opengl: gl_util: reindent after last changes

- - - - -


4 changed files:

- modules/video_output/opengl/gl_api.c
- modules/video_output/opengl/gl_common.h
- modules/video_output/opengl/gl_util.c
- modules/video_output/opengl/sampler.c


Changes:

=====================================
modules/video_output/opengl/gl_api.c
=====================================
@@ -99,6 +99,7 @@ vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl)
     GET_PROC_ADDR(GetShaderiv);
     GET_PROC_ADDR(GetProgramInfoLog);
     GET_PROC_ADDR(GetShaderInfoLog);
+    GET_PROC_ADDR(GetShaderSource);
 
     GET_PROC_ADDR(GetUniformLocation);
     GET_PROC_ADDR(GetAttribLocation);


=====================================
modules/video_output/opengl/gl_common.h
=====================================
@@ -266,6 +266,7 @@ typedef void (APIENTRY *PFNGLREADPIXELSPROC) (GLint, GLint, GLsizei, GLsizei, GL
 #if defined(USE_OPENGL_ES2) || defined(__APPLE__)
 #   define PFNGLGETPROGRAMIVPROC             typeof(glGetProgramiv)*
 #   define PFNGLGETPROGRAMINFOLOGPROC        typeof(glGetProgramInfoLog)*
+#   define PFNGLGETSHADERSOURCEPROC          typeof(glGetShaderSource)*
 #   define PFNGLGETSHADERIVPROC              typeof(glGetShaderiv)*
 #   define PFNGLGETSHADERINFOLOGPROC         typeof(glGetShaderInfoLog)*
 #   define PFNGLGETUNIFORMLOCATIONPROC       typeof(glGetUniformLocation)*
@@ -373,6 +374,7 @@ typedef struct {
     PFNGLGETSHADERIVPROC        GetShaderiv;
     PFNGLGETPROGRAMINFOLOGPROC  GetProgramInfoLog;
     PFNGLGETSHADERINFOLOGPROC   GetShaderInfoLog;
+    PFNGLGETSHADERSOURCEPROC    GetShaderSource;
 
     /* Shader variables commands */
     PFNGLGETUNIFORMLOCATIONPROC      GetUniformLocation;


=====================================
modules/video_output/opengl/gl_util.c
=====================================
@@ -29,22 +29,68 @@
 #include <vlc_modules.h>
 #include <vlc_configuration.h>
 
+#include <vlc_memstream.h>
+
 static void
 LogShaderErrors(vlc_object_t *obj, const opengl_vtable_t *vt, GLuint id)
 {
     GLint info_len;
     vt->GetShaderiv(id, GL_INFO_LOG_LENGTH, &info_len);
-    if (info_len > 0)
+    if (info_len <= 0)
+        return;
+
+    char *info_log = malloc(info_len);
+    if (info_log == NULL)
+        return;
+
+    GLsizei written;
+    vt->GetShaderInfoLog(id, info_len, &written, info_log);
+
+    GLint size;
+    vt->GetShaderiv(id, GL_SHADER_SOURCE_LENGTH, &size);
+    char *sources = malloc(size + 1);
+    if (sources == NULL)
+        goto end;
+
+    vt->GetShaderSource(id, size + 1, NULL, sources);
+
+    struct vlc_memstream stream;
+    int ret = vlc_memstream_open(&stream);
+
+    /* This is debugging code, we don't want an hard failure if
+     * the allocation failed. */
+    if (ret != 0)
+        goto end;
+
+    const char *cursor = sources;
+    size_t line = 1;
+    while (cursor != NULL && *cursor != '\0')
     {
-        char *info_log = malloc(info_len);
-        if (info_log)
+        const char *end = strchr(cursor, '\n');
+        if (end != NULL)
         {
-            GLsizei written;
-            vt->GetShaderInfoLog(id, info_len, &written, info_log);
-            msg_Err(obj, "shader: %s", info_log);
-            free(info_log);
+            vlc_memstream_printf(&stream, "%4zu: %.*s\n", line, (int)(ptrdiff_t)(end - cursor), cursor);
+            cursor = end + 1;
         }
+        else
+        {
+            vlc_memstream_printf(&stream, "%4zu: %s", line, cursor);
+            break;
+        }
+        line++;
     }
+
+    ret = vlc_memstream_close(&stream);
+    if (ret != 0)
+        goto end;
+
+    msg_Err(obj, "Shader:\n%s", stream.ptr);
+    free(stream.ptr);
+
+end:
+    msg_Err(obj, "shader: %s", info_log);
+    free(info_log);
+    free(sources);
 }
 
 static void


=====================================
modules/video_output/opengl/sampler.c
=====================================
@@ -73,6 +73,8 @@ struct vlc_gl_sampler_priv {
     bool expose_planes;
     unsigned plane;
 
+    int glsl_version;
+
     struct vlc_gl_extension_vt extension_vt;
 };
 
@@ -523,17 +525,24 @@ opengl_init_swizzle(struct vlc_gl_sampler *sampler,
 }
 
 static void
-GetNames(GLenum tex_target, const char **glsl_sampler, const char **texture)
+GetNames(struct vlc_gl_sampler *sampler, GLenum tex_target,
+         const char **glsl_sampler, const char **texture)
 {
+    struct vlc_gl_sampler_priv *priv = PRIV(sampler);
+
+    bool has_texture_func =
+        (priv->gl->api_type == VLC_OPENGL && priv->glsl_version >= 130) ||
+        (priv->gl->api_type = VLC_OPENGL_ES2 && priv->glsl_version >= 300);
+
     switch (tex_target)
     {
         case GL_TEXTURE_EXTERNAL_OES:
             *glsl_sampler = "samplerExternalOES";
-            *texture = "texture2D";
+            *texture = has_texture_func ? "texture" : "texture2D";
             break;
         case GL_TEXTURE_2D:
             *glsl_sampler = "sampler2D";
-            *texture = "texture2D";
+            *texture = has_texture_func ? "texture" : "texture2D";
             break;
         case GL_TEXTURE_RECTANGLE:
             *glsl_sampler = "sampler2DRect";
@@ -616,7 +625,7 @@ sampler_planes_init(struct vlc_gl_sampler *sampler)
 
     const char *sampler_type;
     const char *texture_fn;
-    GetNames(tex_target, &sampler_type, &texture_fn);
+    GetNames(sampler, tex_target, &sampler_type, &texture_fn);
 
     ADDF("uniform %s Texture;\n", sampler_type);
 
@@ -738,7 +747,7 @@ opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, bool expose_planes)
     }
 
     const char *glsl_sampler, *lookup;
-    GetNames(tex_target, &glsl_sampler, &lookup);
+    GetNames(sampler, tex_target, &glsl_sampler, &lookup);
 
     struct vlc_memstream ms;
     if (vlc_memstream_open(&ms) != 0)
@@ -993,6 +1002,7 @@ vlc_gl_sampler_New(struct vlc_gl_t *gl, const struct vlc_gl_api *api,
         if (asprintf(&sampler->shader.version, "#version %d\n", glsl_version) < 0)
             goto error;
     }
+    priv->glsl_version = glsl_version;
 
 #ifdef HAVE_LIBPLACEBO_GL
     priv->uloc.pl_vars = NULL;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b33eba973205409712188bb4109d3dd35f33cf7a...a7d9d5c3823a1ae1976ef1132a1dc8c039125576

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b33eba973205409712188bb4109d3dd35f33cf7a...a7d9d5c3823a1ae1976ef1132a1dc8c039125576
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list