#include <stdio.h>
+#include "context.h"
#include "imports.h"
#include "mtypes.h"
#include "version.h"
* fwd_context is only valid if version > 0
*/
static void
-get_gl_override(int *version, bool *fwd_context, bool *compat_context)
+get_gl_override(gl_api api, int *version, bool *fwd_context,
+ bool *compat_context)
{
- const char *env_var = "MESA_GL_VERSION_OVERRIDE";
+ const char *env_var = (api == API_OPENGL_CORE || api == API_OPENGL_COMPAT)
+ ? "MESA_GL_VERSION_OVERRIDE" : "MESA_GLES_VERSION_OVERRIDE";
const char *version_str;
int major, minor, n;
- static int override_version = -1;
- static bool fc_suffix = false;
- static bool compat_suffix = false;
+ static struct override_info {
+ int version;
+ bool fc_suffix;
+ bool compat_suffix;
+ } override[] = {
+ { -1, false, false},
+ { -1, false, false},
+ { -1, false, false},
+ { -1, false, false},
+ };
- if (override_version < 0) {
- override_version = 0;
+ STATIC_ASSERT(ARRAY_SIZE(override) == API_OPENGL_LAST + 1);
+
+ if (api == API_OPENGLES)
+ goto exit;
+
+ if (override[api].version < 0) {
+ override[api].version = 0;
version_str = getenv(env_var);
if (version_str) {
- fc_suffix = check_for_ending(version_str, "FC");
- compat_suffix = check_for_ending(version_str, "COMPAT");
+ override[api].fc_suffix = check_for_ending(version_str, "FC");
+ override[api].compat_suffix = check_for_ending(version_str, "COMPAT");
n = sscanf(version_str, "%u.%u", &major, &minor);
if (n != 2) {
fprintf(stderr, "error: invalid value for %s: %s\n",
env_var, version_str);
- override_version = 0;
+ override[api].version = 0;
} else {
- override_version = major * 10 + minor;
- if (override_version < 30 && fc_suffix) {
+ override[api].version = major * 10 + minor;
+
+ /* There is no such thing as compatibility or forward-compatible for
+ * OpenGL ES 2.0 or 3.x APIs.
+ */
+ if ((override[api].version < 30 && override[api].fc_suffix) ||
+ (api == API_OPENGLES2 && (override[api].fc_suffix ||
+ override[api].compat_suffix))) {
fprintf(stderr, "error: invalid value for %s: %s\n",
env_var, version_str);
}
}
}
- *version = override_version;
- *fwd_context = fc_suffix;
- *compat_context = compat_suffix;
+exit:
+ *version = override[api].version;
+ *fwd_context = override[api].fc_suffix;
+ *compat_context = override[api].compat_suffix;
}
/**
- * Builds the MESA version string.
+ * Builds the Mesa version string.
*/
static void
create_version_string(struct gl_context *ctx, const char *prefix)
int version;
bool fwd_context, compat_context;
- get_gl_override(&version, &fwd_context, &compat_context);
+ get_gl_override(*apiOut, &version, &fwd_context, &compat_context);
if (version > 0) {
*versionOut = version;
- if (version >= 30 && fwd_context) {
- *apiOut = API_OPENGL_CORE;
- consts->ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
- } else if (version >= 31 && !compat_context) {
- *apiOut = API_OPENGL_CORE;
- } else {
- *apiOut = API_OPENGL_COMPAT;
+
+ /* If the API is a desktop API, adjust the context flags. We may also
+ * need to modify the API depending on the version. For example, Mesa
+ * does not support a GL 3.3 compatibility profile.
+ */
+ if (*apiOut == API_OPENGL_CORE || *apiOut == API_OPENGL_COMPAT) {
+ if (version >= 30 && fwd_context) {
+ *apiOut = API_OPENGL_CORE;
+ consts->ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
+ } else if (version >= 31 && !compat_context) {
+ *apiOut = API_OPENGL_CORE;
+ } else {
+ *apiOut = API_OPENGL_COMPAT;
+ }
}
+
return true;
}
return false;
{
if (_mesa_override_gl_version_contextless(&ctx->Const, &ctx->API,
&ctx->Version)) {
- create_version_string(ctx, "");
+ /* We need to include API in version string for OpenGL ES, otherwise
+ * application can not detect GLES via glGetString(GL_VERSION) query.
+ *
+ * From OpenGL ES 3.2 spec, Page 436:
+ *
+ * "The VERSION string is laid out as follows:
+ *
+ * OpenGL ES N.M vendor-specific information"
+ *
+ * From OpenGL 4.5 spec, Page 538:
+ *
+ * "The VERSION and SHADING_LANGUAGE_VERSION strings are laid out as
+ * follows:
+ *
+ * <version number><space><vendor-specific information>"
+ */
+ create_version_string(ctx, _mesa_is_gles(ctx) ? "OpenGL ES " : "");
+ ctx->Extensions.Version = ctx->Version;
}
}
-/**
- * Returns the gl override value
- *
- * version > 0 indicates there is an override requested
- */
-int
-_mesa_get_gl_version_override(void)
-{
- int version;
- bool fwd_context, compat_context;
-
- get_gl_override(&version, &fwd_context, &compat_context);
-
- return version;
-}
-
/**
* Override the context's GLSL version if the environment variable
* MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
extensions->ARB_gpu_shader5 &&
extensions->ARB_gpu_shader_fp64 &&
extensions->ARB_sample_shading &&
- false /*extensions->ARB_shader_subroutine*/ &&
+ extensions->ARB_shader_subroutine &&
extensions->ARB_tessellation_shader &&
extensions->ARB_texture_buffer_object_rgb32 &&
extensions->ARB_texture_cube_map_array &&
consts->GLSLVersion >= 410 &&
extensions->ARB_ES2_compatibility &&
extensions->ARB_shader_precision &&
- false /*extensions->ARB_vertex_attrib_64bit*/ &&
+ extensions->ARB_vertex_attrib_64bit &&
extensions->ARB_viewport_array);
const bool ver_4_2 = (ver_4_1 &&
consts->GLSLVersion >= 420 &&
extensions->ARB_shading_language_packing &&
extensions->ARB_texture_compression_bptc &&
extensions->ARB_transform_feedback_instanced);
-
- if (ver_4_2) {
+ const bool ver_4_3 = (ver_4_2 &&
+ consts->GLSLVersion >= 430 &&
+ extensions->ARB_ES3_compatibility &&
+ extensions->ARB_arrays_of_arrays &&
+ extensions->ARB_compute_shader &&
+ extensions->ARB_copy_image &&
+ extensions->ARB_explicit_uniform_location &&
+ extensions->ARB_fragment_layer_viewport &&
+ extensions->ARB_framebuffer_no_attachments &&
+ extensions->ARB_internalformat_query2 &&
+ extensions->ARB_robust_buffer_access_behavior &&
+ extensions->ARB_shader_image_size &&
+ extensions->ARB_shader_storage_buffer_object &&
+ extensions->ARB_stencil_texturing &&
+ extensions->ARB_texture_buffer_range &&
+ extensions->ARB_texture_query_levels &&
+ extensions->ARB_texture_view);
+ const bool ver_4_4 = (ver_4_3 &&
+ consts->GLSLVersion >= 440 &&
+ extensions->ARB_buffer_storage &&
+ extensions->ARB_clear_texture &&
+ extensions->ARB_enhanced_layouts &&
+ extensions->ARB_query_buffer_object &&
+ extensions->ARB_texture_mirror_clamp_to_edge &&
+ extensions->ARB_texture_stencil8 &&
+ extensions->ARB_vertex_type_10f_11f_11f_rev);
+ const bool ver_4_5 = (ver_4_4 &&
+ consts->GLSLVersion >= 450 &&
+ extensions->ARB_ES3_1_compatibility &&
+ extensions->ARB_clip_control &&
+ extensions->ARB_conditional_render_inverted &&
+ extensions->ARB_cull_distance &&
+ extensions->ARB_derivative_control &&
+ extensions->ARB_shader_texture_image_samples &&
+ extensions->NV_texture_barrier);
+
+ if (ver_4_5) {
+ major = 4;
+ minor = 5;
+ }
+ else if (ver_4_4) {
+ major = 4;
+ minor = 4;
+ }
+ else if (ver_4_3) {
+ major = 4;
+ minor = 3;
+ }
+ else if (ver_4_2) {
major = 4;
minor = 2;
}
}
static GLuint
-compute_version_es2(const struct gl_extensions *extensions)
+compute_version_es2(const struct gl_extensions *extensions,
+ const struct gl_constants *consts)
{
/* OpenGL ES 2.0 is derived from OpenGL 2.0 */
const bool ver_2_0 = (extensions->ARB_texture_cube_map &&
extensions->EXT_texture_snorm &&
extensions->NV_primitive_restart &&
extensions->OES_depth_texture_cube_map);
- if (ver_3_0) {
+ const bool es31_compute_shader =
+ consts->MaxComputeWorkGroupInvocations >= 128;
+ const bool ver_3_1 = (ver_3_0 &&
+ extensions->ARB_arrays_of_arrays &&
+ es31_compute_shader &&
+ extensions->ARB_draw_indirect &&
+ extensions->ARB_explicit_uniform_location &&
+ extensions->ARB_framebuffer_no_attachments &&
+ extensions->ARB_shader_atomic_counters &&
+ extensions->ARB_shader_image_load_store &&
+ extensions->ARB_shader_image_size &&
+ extensions->ARB_shader_storage_buffer_object &&
+ extensions->ARB_shading_language_packing &&
+ extensions->ARB_stencil_texturing &&
+ extensions->ARB_texture_multisample &&
+ extensions->ARB_gpu_shader5 &&
+ extensions->EXT_shader_integer_mix);
+ const bool ver_3_2 = (ver_3_1 &&
+ /*extensions->KHR_blend_equation_advanced*/ false &&
+ extensions->KHR_texture_compression_astc_ldr &&
+ extensions->OES_copy_image &&
+ extensions->ARB_draw_buffers_blend &&
+ extensions->ARB_draw_elements_base_vertex &&
+ extensions->OES_geometry_shader &&
+ /*extensions->OES_primitive_bounding_box*/ false &&
+ extensions->OES_sample_variables &&
+ extensions->ARB_tessellation_shader &&
+ extensions->ARB_texture_border_clamp &&
+ extensions->OES_texture_buffer &&
+ extensions->ARB_texture_cube_map_array &&
+ extensions->ARB_texture_stencil8);
+
+ if (ver_3_2) {
+ return 32;
+ } else if (ver_3_1) {
+ return 31;
+ } else if (ver_3_0) {
return 30;
} else if (ver_2_0) {
return 20;
case API_OPENGLES:
return compute_version_es1(extensions);
case API_OPENGLES2:
- return compute_version_es2(extensions);
+ return compute_version_es2(extensions, consts);
}
return 0;
}
return;
ctx->Version = _mesa_get_version(&ctx->Extensions, &ctx->Const, ctx->API);
+ ctx->Extensions.Version = ctx->Version;
/* Make sure that the GLSL version lines up with the GL version. In some
* cases it can be too high, e.g. if an extension is missing.