[vlc-commits] [Git][videolan/vlc][master] 6 commits: opengl: parse GLSL version from implementation
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Mon Aug 28 18:44:55 UTC 2023
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
1fe7bc9b by Niklas Haas at 2023-08-28T18:28:10+00:00
opengl: parse GLSL version from implementation
- - - - -
8278b313 by Niklas Haas at 2023-08-28T18:28:10+00:00
opengl: sampler: add error label (cosmetic)
To be re-used.
- - - - -
920c0631 by Niklas Haas at 2023-08-28T18:28:10+00:00
opengl: sampler: add preambles to vlc_gl_sampler
This allows vlc_gl_sampler to be used with the appropriate version of
GLSL enabled, which allows the use of more up-to-date GLSL features.
To avoid unnecessary complicated preprocessor interventions, we limit
the upper version of desktop GLSL to 410, which is the last version that
retains compatibility for attribute/varying declarations.
- - - - -
734e5f57 by Niklas Haas at 2023-08-28T18:28:10+00:00
opengl: switch to sampler->shader.version/precision
Handily eliminates a bunch of needless repetition of this logic, as well
as allowing us to support higher versions of GLSL in vlc_gl_sampler.
- - - - -
ce7acd81 by Niklas Haas at 2023-08-28T18:28:10+00:00
opengl: sampler: expose GLSL version to libplacebo
- - - - -
1c7dadae by Niklas Haas at 2023-08-28T18:28:10+00:00
opengl: sampler: print libplacebo shader description
Provides a clearer picture of what the shader is doing. Useful for
debugging, and user feedback (since it shows e.g. what tone-mapping mode
is active and what the source/target nits are).
- - - - -
8 changed files:
- modules/video_filter/deinterlace/glblend.c
- modules/video_output/opengl/filter_draw.c
- modules/video_output/opengl/filter_mock.c
- modules/video_output/opengl/gl_api.c
- modules/video_output/opengl/gl_api.h
- modules/video_output/opengl/renderer.c
- modules/video_output/opengl/sampler.c
- modules/video_output/opengl/sampler.h
Changes:
=====================================
modules/video_filter/deinterlace/glblend.c
=====================================
@@ -188,29 +188,16 @@ Open(struct vlc_gl_filter *filter, const config_chain_t *config,
" gl_FragColor = (pix + pix_up) / 2.0;\n"
"}\n";
- const char *shader_version;
- const char *shader_precision;
- if (filter->api->is_gles)
- {
- shader_version = "#version 100\n";
- shader_precision = "precision highp float;\n";
- }
- else
- {
- shader_version = "#version 120\n";
- shader_precision = "";
- }
-
const char *extensions = sampler->shader.extensions
? sampler->shader.extensions : "";
const opengl_vtable_t *vt = &filter->api->vt;
- const char *vertex_shader[] = { shader_version, VERTEX_SHADER };
+ const char *vertex_shader[] = { sampler->shader.version, VERTEX_SHADER };
const char *fragment_shader[] = {
- shader_version,
+ sampler->shader.version,
extensions,
- shader_precision,
+ sampler->shader.precision,
sampler->shader.body,
FRAGMENT_SHADER,
};
=====================================
modules/video_output/opengl/filter_draw.c
=====================================
@@ -169,30 +169,17 @@ Open(struct vlc_gl_filter *filter, const config_chain_t *config,
const opengl_vtable_t *vt = &filter->api->vt;
- const char *shader_version;
- const char *shader_precision;
- if (filter->api->is_gles)
- {
- shader_version = "#version 100\n";
- shader_precision = "precision highp float;\n";
- }
- else
- {
- shader_version = "#version 120\n";
- shader_precision = "";
- }
-
config_ChainParse(filter, DRAW_CFG_PREFIX, filter_options, config);
sys->vflip = var_InheritBool(filter, DRAW_CFG_PREFIX "vflip");
const char *vertex_shader[] = {
- shader_version,
+ sampler->shader.version,
VERTEX_SHADER_BODY,
};
const char *fragment_shader[] = {
- shader_version,
+ sampler->shader.version,
extensions,
- shader_precision,
+ sampler->shader.precision,
sampler->shader.body,
FRAGMENT_SHADER_BODY,
};
=====================================
modules/video_output/opengl/filter_mock.c
=====================================
@@ -412,27 +412,14 @@ InitMask(struct vlc_gl_filter *filter, const struct vlc_gl_format *glfmt)
const char *extensions = sampler->shader.extensions
? sampler->shader.extensions : "";
- const char *shader_version;
- const char *shader_precision;
- if (filter->api->is_gles)
- {
- shader_version = "#version 100\n";
- shader_precision = "precision highp float;\n";
- }
- else
- {
- shader_version = "#version 120\n";
- shader_precision = "";
- }
-
const char *vertex_shader[] = {
- shader_version,
+ sampler->shader.version,
VERTEX_SHADER_BODY,
};
const char *fragment_shader[] = {
- shader_version,
+ sampler->shader.version,
extensions,
- shader_precision,
+ sampler->shader.precision,
sampler->shader.body,
FRAGMENT_SHADER_BODY,
};
@@ -516,27 +503,14 @@ InitPlane(struct vlc_gl_filter *filter, const struct vlc_gl_format *glfmt)
const char *extensions = sampler->shader.extensions
? sampler->shader.extensions : "";
- const char *shader_version;
- const char *shader_precision;
- if (filter->api->is_gles)
- {
- shader_version = "#version 100\n";
- shader_precision = "precision highp float;\n";
- }
- else
- {
- shader_version = "#version 120\n";
- shader_precision = "";
- }
-
const char *vertex_shader[] = {
- shader_version,
+ sampler->shader.version,
VERTEX_SHADER_BODY,
};
const char *fragment_shader[] = {
- shader_version,
+ sampler->shader.version,
extensions,
- shader_precision,
+ sampler->shader.precision,
sampler->shader.body,
FRAGMENT_SHADER_BODY,
};
=====================================
modules/video_output/opengl/gl_api.c
=====================================
@@ -157,9 +157,17 @@ vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl)
GL_ASSERT_NOERROR(&api->vt);
GLint version;
+ GLchar *glsl_version;
api->vt.GetIntegerv(GL_MAJOR_VERSION, &version);
+ glsl_version = (GLchar *) api->vt.GetString(GL_SHADING_LANGUAGE_VERSION);
GLenum error = api->vt.GetError();
+ if (glsl_version) {
+ int major = 0, minor = 0;
+ if (sscanf(glsl_version, "%d.%d", &major, &minor) == 2)
+ api->glsl_version = major * 100 + minor;
+ }
+
/* OpenGL >= 3.0:
* https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glRenderbufferStorageMultisample.xhtml
* OpenGL ES >= 3.0:
@@ -180,12 +188,16 @@ vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl)
/* OpenGL ES 2 includes support for non-power of 2 textures by specification
* so checks for extensions are bound to fail. Check for OpenGL ES version instead. */
api->supports_npot = true;
+ if (!api->glsl_version)
+ api->glsl_version = version >= 3 ? 300 : 100;
}
else
{
api->is_gles = false;
api->supports_npot = vlc_gl_HasExtension(&extension_vt, "GL_ARB_texture_non_power_of_two") ||
vlc_gl_HasExtension(&extension_vt, "GL_APPLE_texture_2D_limited_npot");
+ if (!api->glsl_version)
+ api->glsl_version = 120;
}
return VLC_SUCCESS;
=====================================
modules/video_output/opengl/gl_api.h
=====================================
@@ -35,6 +35,9 @@
struct vlc_gl_api {
opengl_vtable_t vt;
+ /* Highest GLSL version supported by the API */
+ int glsl_version;
+
/* True if the current API is OpenGL ES, set by the caller */
bool is_gles;
=====================================
modules/video_output/opengl/renderer.c
=====================================
@@ -203,27 +203,14 @@ opengl_link_program(struct vlc_gl_filter *filter)
const char *extensions = sampler->shader.extensions
? sampler->shader.extensions : "";
- const char *shader_version;
- const char *shader_precision;
- if (filter->api->is_gles)
- {
- shader_version = "#version 100\n";
- shader_precision = "precision highp float;\n";
- }
- else
- {
- shader_version = "#version 120\n";
- shader_precision = "";
- }
-
const char *vertex_shader[] = {
- shader_version,
+ sampler->shader.version,
VERTEX_SHADER_BODY,
};
const char *fragment_shader[] = {
- shader_version,
+ sampler->shader.version,
extensions,
- shader_precision,
+ sampler->shader.precision,
sampler->shader.body,
FRAGMENT_SHADER_BODY,
};
=====================================
modules/video_output/opengl/sampler.c
=====================================
@@ -809,6 +809,11 @@ opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, bool expose_planes)
}
const struct pl_shader_res *res = priv->pl_sh_res = pl_shader_finalize(sh);
+# if PL_API_VER >= 266
+ msg_Dbg(priv->gl, "libplacebo shader: %s", res->info->description);
+# elif PL_API_VER >= 151
+ msg_Dbg(priv->gl, "libplacebo shader: %s", res->description);
+# endif
FREENULL(priv->uloc.pl_vars);
priv->uloc.pl_vars = calloc(res->num_variables, sizeof(GLint));
@@ -970,6 +975,25 @@ vlc_gl_sampler_New(struct vlc_gl_t *gl, const struct vlc_gl_api *api,
sampler->shader.extensions = NULL;
sampler->shader.body = NULL;
+ int glsl_version;
+ if (api->is_gles) {
+ sampler->shader.precision = "precision highp float;\n";
+ if (api->glsl_version >= 300) {
+ sampler->shader.version = strdup("#version 300 es\n");
+ glsl_version = 300;
+ } else {
+ sampler->shader.version = strdup("#version 100\n");
+ glsl_version = 100;
+ }
+ } else {
+ sampler->shader.precision = "";
+ /* GLSL version 420+ breaks backwards compatibility with pre-GLSL 130
+ * syntax, which we use in our vertex/fragment shaders. */
+ glsl_version = __MIN(api->glsl_version, 410);
+ if (asprintf(&sampler->shader.version, "#version %d\n", glsl_version) < 0)
+ goto error;
+ }
+
#ifdef HAVE_LIBPLACEBO_GL
priv->uloc.pl_vars = NULL;
priv->uloc.pl_descs = NULL;
@@ -1009,7 +1033,7 @@ vlc_gl_sampler_New(struct vlc_gl_t *gl, const struct vlc_gl_api *api,
priv->pl_sh = pl_shader_alloc(priv->pl_log, &(struct pl_shader_params) {
.gpu = priv->pl_opengl->gpu,
.glsl = {
- .version = gl->api_type == VLC_OPENGL_ES2 ? 100 : 120,
+ .version = glsl_version,
.gles = gl->api_type == VLC_OPENGL_ES2,
},
});
@@ -1017,12 +1041,13 @@ vlc_gl_sampler_New(struct vlc_gl_t *gl, const struct vlc_gl_api *api,
int ret = opengl_fragment_shader_init(sampler, expose_planes);
if (ret != VLC_SUCCESS)
- {
- vlc_gl_sampler_Delete(sampler);
- return NULL;
- }
+ goto error;
return sampler;
+
+error:
+ vlc_gl_sampler_Delete(sampler);
+ return NULL;
}
void
@@ -1043,6 +1068,7 @@ vlc_gl_sampler_Delete(struct vlc_gl_sampler *sampler)
free(sampler->shader.extensions);
free(sampler->shader.body);
+ free(sampler->shader.version);
free(priv);
}
=====================================
modules/video_output/opengl/sampler.h
=====================================
@@ -89,6 +89,16 @@ struct vlc_gl_sampler {
const float *pic_to_tex_matrix;
struct {
+ /**
+ * Version header that is appropriate for this shader.
+ */
+ char *version;
+
+ /**
+ * Precision preamble that is appropriate for this shader.
+ */
+ const char *precision;
+
/**
* Piece of fragment shader code declaration OpenGL extensions.
*
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/25b39a43a5d336adea9960009ecb41dceaefa438...1c7dadaecc6542554a8285a6ddd9ca3427e55196
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/25b39a43a5d336adea9960009ecb41dceaefa438...1c7dadaecc6542554a8285a6ddd9ca3427e55196
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