glsl: fix #version 150 not working with profiles

The spec allows the core/compatibility profiles to be used
with #version 150.

Also tighten up the tests to check for default profiles being chosen
correctly.
This commit is contained in:
Matthew Waters 2016-11-01 17:30:03 +11:00
parent 8eef23eb38
commit 4b43862cdb
2 changed files with 88 additions and 22 deletions

View file

@ -191,11 +191,11 @@ _is_valid_version_profile (GstGLSLVersion version, GstGLSLProfile profile)
return profile == GST_GLSL_PROFILE_ES; return profile == GST_GLSL_PROFILE_ES;
/* required profile and no ES profile for normal GL contexts */ /* required profile and no ES profile for normal GL contexts */
if (version >= GST_GLSL_VERSION_330) if (version == GST_GLSL_VERSION_150 || version >= GST_GLSL_VERSION_330)
return profile == GST_GLSL_PROFILE_NONE || profile == GST_GLSL_PROFILE_CORE return profile == GST_GLSL_PROFILE_NONE || profile == GST_GLSL_PROFILE_CORE
|| profile == GST_GLSL_PROFILE_COMPATIBILITY; || profile == GST_GLSL_PROFILE_COMPATIBILITY;
if (version <= GST_GLSL_VERSION_150) if (version <= GST_GLSL_VERSION_140)
return profile == GST_GLSL_PROFILE_NONE return profile == GST_GLSL_PROFILE_NONE
|| profile == GST_GLSL_PROFILE_COMPATIBILITY; || profile == GST_GLSL_PROFILE_COMPATIBILITY;
@ -213,7 +213,7 @@ gst_glsl_version_profile_to_string (GstGLSLVersion version,
version_s = gst_glsl_version_to_string (version); version_s = gst_glsl_version_to_string (version);
/* no profiles in GL/ES <= 150 */ /* no profiles in GL/ES <= 150 */
if (version <= GST_GLSL_VERSION_150) if (version <= GST_GLSL_VERSION_140)
profile_s = NULL; profile_s = NULL;
else else
profile_s = gst_glsl_profile_to_string (profile); profile_s = gst_glsl_profile_to_string (profile);
@ -233,10 +233,10 @@ _fixup_version_profile (GstGLSLVersion * version, GstGLSLProfile * profile)
if (*version == GST_GLSL_VERSION_100 || *version == GST_GLSL_VERSION_300 if (*version == GST_GLSL_VERSION_100 || *version == GST_GLSL_VERSION_300
|| *version == GST_GLSL_VERSION_310 || *version == GST_GLSL_VERSION_320) || *version == GST_GLSL_VERSION_310 || *version == GST_GLSL_VERSION_320)
*profile = GST_GLSL_PROFILE_ES; *profile = GST_GLSL_PROFILE_ES;
else if (*version <= GST_GLSL_VERSION_150) else if (*version <= GST_GLSL_VERSION_140)
*profile = GST_GLSL_PROFILE_COMPATIBILITY; *profile = GST_GLSL_PROFILE_COMPATIBILITY;
else if (*profile == GST_GLSL_PROFILE_NONE else if (*profile == GST_GLSL_PROFILE_NONE
&& *version >= GST_GLSL_VERSION_330) && (*version >= GST_GLSL_VERSION_150 || *version >= GST_GLSL_VERSION_330))
*profile = GST_GLSL_PROFILE_CORE; *profile = GST_GLSL_PROFILE_CORE;
} }
@ -324,7 +324,7 @@ gst_glsl_version_profile_from_string (const gchar * string,
goto error; goto error;
} }
/* got a profile when none was expected */ /* got a profile when none was expected */
if (version <= GST_GLSL_VERSION_150 && profile != GST_GLSL_PROFILE_NONE) { if (version <= GST_GLSL_VERSION_140 && profile != GST_GLSL_PROFILE_NONE) {
GST_WARNING GST_WARNING
("Found a profile (%s) with a version (%s) that does not support " ("Found a profile (%s) with a version (%s) that does not support "
"profiles", gst_glsl_version_to_string (version), "profiles", gst_glsl_version_to_string (version),

View file

@ -63,13 +63,21 @@ static const struct {GstGLSLProfile profile; const gchar * name;} glsl_profiles[
{GST_GLSL_PROFILE_COMPATIBILITY, "compatibility"}, {GST_GLSL_PROFILE_COMPATIBILITY, "compatibility"},
}; };
static const struct {GstGLSLVersion version; GstGLSLProfile profile; const gchar * name;} glsl_version_profiles[] = { struct version_profile_s
{
GstGLSLVersion version;
GstGLSLProfile profile;
const gchar * name;
};
static const struct version_profile_s glsl_version_profiles_valid[] = {
{GST_GLSL_VERSION_100, GST_GLSL_PROFILE_ES, "100"}, {GST_GLSL_VERSION_100, GST_GLSL_PROFILE_ES, "100"},
{GST_GLSL_VERSION_110, GST_GLSL_PROFILE_COMPATIBILITY, "110"}, {GST_GLSL_VERSION_110, GST_GLSL_PROFILE_COMPATIBILITY, "110"},
{GST_GLSL_VERSION_120, GST_GLSL_PROFILE_COMPATIBILITY, "120"}, {GST_GLSL_VERSION_120, GST_GLSL_PROFILE_COMPATIBILITY, "120"},
{GST_GLSL_VERSION_130, GST_GLSL_PROFILE_COMPATIBILITY, "130"}, {GST_GLSL_VERSION_130, GST_GLSL_PROFILE_COMPATIBILITY, "130"},
{GST_GLSL_VERSION_140, GST_GLSL_PROFILE_COMPATIBILITY, "140"}, {GST_GLSL_VERSION_140, GST_GLSL_PROFILE_COMPATIBILITY, "140"},
{GST_GLSL_VERSION_150, GST_GLSL_PROFILE_COMPATIBILITY, "150"}, {GST_GLSL_VERSION_150, GST_GLSL_PROFILE_CORE, "150 core"},
{GST_GLSL_VERSION_150, GST_GLSL_PROFILE_COMPATIBILITY, "150 compatibility"},
{GST_GLSL_VERSION_300, GST_GLSL_PROFILE_ES, "300 es"}, {GST_GLSL_VERSION_300, GST_GLSL_PROFILE_ES, "300 es"},
{GST_GLSL_VERSION_310, GST_GLSL_PROFILE_ES, "310 es"}, {GST_GLSL_VERSION_310, GST_GLSL_PROFILE_ES, "310 es"},
{GST_GLSL_VERSION_320, GST_GLSL_PROFILE_ES, "320 es"}, {GST_GLSL_VERSION_320, GST_GLSL_PROFILE_ES, "320 es"},
@ -89,6 +97,39 @@ static const struct {GstGLSLVersion version; GstGLSLProfile profile; const gchar
{GST_GLSL_VERSION_450, GST_GLSL_PROFILE_COMPATIBILITY, "450 compatibility"}, {GST_GLSL_VERSION_450, GST_GLSL_PROFILE_COMPATIBILITY, "450 compatibility"},
}; };
/* combinations that produce different results between serializing/deserializing
* due to default values being imposed */
static const struct version_profile_s glsl_version_profiles_valid_serialize[] = {
{GST_GLSL_VERSION_100, GST_GLSL_PROFILE_NONE, "100"},
{GST_GLSL_VERSION_110, GST_GLSL_PROFILE_NONE, "110"},
{GST_GLSL_VERSION_120, GST_GLSL_PROFILE_NONE, "120"},
{GST_GLSL_VERSION_130, GST_GLSL_PROFILE_NONE, "130"},
{GST_GLSL_VERSION_140, GST_GLSL_PROFILE_NONE, "140"},
{GST_GLSL_VERSION_150, GST_GLSL_PROFILE_NONE, "150"},
{GST_GLSL_VERSION_330, GST_GLSL_PROFILE_NONE, "330"},
{GST_GLSL_VERSION_400, GST_GLSL_PROFILE_NONE, "400"},
{GST_GLSL_VERSION_410, GST_GLSL_PROFILE_NONE, "410"},
{GST_GLSL_VERSION_420, GST_GLSL_PROFILE_NONE, "420"},
{GST_GLSL_VERSION_430, GST_GLSL_PROFILE_NONE, "430"},
{GST_GLSL_VERSION_440, GST_GLSL_PROFILE_NONE, "440"},
{GST_GLSL_VERSION_450, GST_GLSL_PROFILE_NONE, "450"},
};
static const struct version_profile_s glsl_version_profiles_valid_deserialize[] = {
{GST_GLSL_VERSION_100, GST_GLSL_PROFILE_ES, "100"},
{GST_GLSL_VERSION_110, GST_GLSL_PROFILE_COMPATIBILITY, "110"},
{GST_GLSL_VERSION_120, GST_GLSL_PROFILE_COMPATIBILITY, "120"},
{GST_GLSL_VERSION_130, GST_GLSL_PROFILE_COMPATIBILITY, "130"},
{GST_GLSL_VERSION_140, GST_GLSL_PROFILE_COMPATIBILITY, "140"},
{GST_GLSL_VERSION_150, GST_GLSL_PROFILE_CORE, "150"},
{GST_GLSL_VERSION_330, GST_GLSL_PROFILE_CORE, "330"},
{GST_GLSL_VERSION_400, GST_GLSL_PROFILE_CORE, "400"},
{GST_GLSL_VERSION_410, GST_GLSL_PROFILE_CORE, "410"},
{GST_GLSL_VERSION_420, GST_GLSL_PROFILE_CORE, "420"},
{GST_GLSL_VERSION_430, GST_GLSL_PROFILE_CORE, "430"},
{GST_GLSL_VERSION_440, GST_GLSL_PROFILE_CORE, "440"},
{GST_GLSL_VERSION_450, GST_GLSL_PROFILE_CORE, "450"},
};
static const gchar * invalid_deserialize_glsl[] = { static const gchar * invalid_deserialize_glsl[] = {
"", "",
" \t\r\n", " \t\r\n",
@ -101,8 +142,6 @@ static const gchar * invalid_deserialize_glsl[] = {
"100 core", "100 core",
"100 compatibility", "100 compatibility",
"150 es", "150 es",
"150 core",
"150 compatibility",
"300 core", "300 core",
"300 compatibility", "300 compatibility",
"310 core", "310 core",
@ -124,7 +163,6 @@ static const struct {GstGLSLVersion version; GstGLSLProfile profile;} invalid_se
{GST_GLSL_VERSION_140, GST_GLSL_PROFILE_ES}, {GST_GLSL_VERSION_140, GST_GLSL_PROFILE_ES},
{GST_GLSL_VERSION_140, GST_GLSL_PROFILE_CORE}, {GST_GLSL_VERSION_140, GST_GLSL_PROFILE_CORE},
{GST_GLSL_VERSION_150, GST_GLSL_PROFILE_ES}, {GST_GLSL_VERSION_150, GST_GLSL_PROFILE_ES},
{GST_GLSL_VERSION_150, GST_GLSL_PROFILE_CORE},
{GST_GLSL_VERSION_300, GST_GLSL_PROFILE_NONE}, {GST_GLSL_VERSION_300, GST_GLSL_PROFILE_NONE},
{GST_GLSL_VERSION_300, GST_GLSL_PROFILE_CORE}, {GST_GLSL_VERSION_300, GST_GLSL_PROFILE_CORE},
{GST_GLSL_VERSION_300, GST_GLSL_PROFILE_COMPATIBILITY}, {GST_GLSL_VERSION_300, GST_GLSL_PROFILE_COMPATIBILITY},
@ -190,27 +228,55 @@ GST_START_TEST (test_serialization)
gst_glsl_profile_to_string (profile)); gst_glsl_profile_to_string (profile));
} }
for (i = 0; i < G_N_ELEMENTS (glsl_version_profiles); i++) { for (i = 0; i < G_N_ELEMENTS (glsl_version_profiles_valid); i++) {
gchar *version_profile_s; gchar *version_profile_s;
GstGLSLVersion version; GstGLSLVersion version;
GstGLSLProfile profile; GstGLSLProfile profile;
version_profile_s = version_profile_s =
gst_glsl_version_profile_to_string (glsl_version_profiles[i].version, gst_glsl_version_profile_to_string (glsl_version_profiles_valid
glsl_version_profiles[i].profile); [i].version, glsl_version_profiles_valid[i].profile);
fail_unless (g_strcmp0 (version_profile_s, fail_unless (g_strcmp0 (version_profile_s,
glsl_version_profiles[i].name) == 0, "%s != %s", version_profile_s, glsl_version_profiles_valid[i].name) == 0, "%s != %s",
glsl_version_profiles[i].name); version_profile_s, glsl_version_profiles_valid[i].name);
fail_unless (gst_glsl_version_profile_from_string (glsl_version_profiles fail_unless (gst_glsl_version_profile_from_string
[i].name, &version, &profile), "Failed to parse %s", (glsl_version_profiles_valid[i].name, &version, &profile),
glsl_version_profiles[i].name); "Failed to parse %s", glsl_version_profiles_valid[i].name);
fail_unless (profile == glsl_version_profiles[i].profile fail_unless (profile == glsl_version_profiles_valid[i].profile
&& version == glsl_version_profiles[i].version, "%s != %s %s", && version == glsl_version_profiles_valid[i].version, "%s != %s %s",
glsl_version_profiles[i].name, gst_glsl_version_to_string (version), glsl_version_profiles_valid[i].name,
gst_glsl_version_to_string (version),
gst_glsl_profile_to_string (profile)); gst_glsl_profile_to_string (profile));
g_free (version_profile_s); g_free (version_profile_s);
} }
for (i = 0; i < G_N_ELEMENTS (glsl_version_profiles_valid_serialize); i++) {
gchar *version_profile_s;
version_profile_s =
gst_glsl_version_profile_to_string
(glsl_version_profiles_valid_serialize[i].version,
glsl_version_profiles_valid_serialize[i].profile);
fail_unless (g_strcmp0 (version_profile_s,
glsl_version_profiles_valid_serialize[i].name) == 0, "%s != %s",
version_profile_s, glsl_version_profiles_valid_serialize[i].name);
g_free (version_profile_s);
}
for (i = 0; i < G_N_ELEMENTS (glsl_version_profiles_valid_deserialize); i++) {
GstGLSLVersion version;
GstGLSLProfile profile;
fail_unless (gst_glsl_version_profile_from_string
(glsl_version_profiles_valid_deserialize[i].name, &version, &profile),
"Failed to parse %s", glsl_version_profiles_valid_deserialize[i].name);
fail_unless (profile == glsl_version_profiles_valid_deserialize[i].profile
&& version == glsl_version_profiles_valid_deserialize[i].version,
"%s != %s %s", glsl_version_profiles_valid_deserialize[i].name,
gst_glsl_version_to_string (version),
gst_glsl_profile_to_string (profile));
}
/* failures */ /* failures */
for (i = 0; i < G_N_ELEMENTS (invalid_deserialize_glsl); i++) { for (i = 0; i < G_N_ELEMENTS (invalid_deserialize_glsl); i++) {
GstGLSLVersion version; GstGLSLVersion version;