#include <stdio.h>
#include "context.h"
-#include "imports.h"
+
#include "mtypes.h"
#include "version.h"
#include "git_sha1.h"
bool fc_suffix;
bool compat_suffix;
} override[] = {
- { -1, false, false},
- { -1, false, false},
- { -1, false, false},
- { -1, false, false},
+ [API_OPENGL_COMPAT] = { -1, false, false},
+ [API_OPENGLES] = { -1, false, false},
+ [API_OPENGLES2] = { -1, false, false},
+ [API_OPENGL_CORE] = { -1, false, false},
};
STATIC_ASSERT(ARRAY_SIZE(override) == API_OPENGL_LAST + 1);
}
/**
- * Builds the MESA version string.
+ * Builds the Mesa version string.
*/
static void
create_version_string(struct gl_context *ctx, const char *prefix)
ctx->VersionString = malloc(max);
if (ctx->VersionString) {
- _mesa_snprintf(ctx->VersionString, max,
- "%s%u.%u%s Mesa " PACKAGE_VERSION
-#ifdef MESA_GIT_SHA1
- " (" MESA_GIT_SHA1 ")"
-#endif
- ,
+ snprintf(ctx->VersionString, max,
+ "%s%u.%u%s Mesa " PACKAGE_VERSION MESA_GIT_SHA1,
prefix,
ctx->Version / 10, ctx->Version % 10,
- (ctx->API == API_OPENGL_CORE) ? " (Core Profile)" : ""
+ (ctx->API == API_OPENGL_CORE) ? " (Core Profile)" :
+ (ctx->API == API_OPENGL_COMPAT && ctx->Version >= 32) ?
+ " (Compatibility Profile)" : ""
);
}
}
/**
- * Override the context's version and/or API type if the
- * environment variable MESA_GL_VERSION_OVERRIDE is set.
+ * Override the context's version and/or API type if the environment variables
+ * MESA_GL_VERSION_OVERRIDE or MESA_GLES_VERSION_OVERRIDE are set.
*
* Example uses of MESA_GL_VERSION_OVERRIDE:
*
- * 2.1: select a compatibility (non-Core) profile with GL version 2.1
- * 3.0: select a compatibility (non-Core) profile with GL version 3.0
- * 3.0FC: select a Core+Forward Compatible profile with GL version 3.0
- * 3.1: select a Core profile with GL version 3.1
- * 3.1FC: select a Core+Forward Compatible profile with GL version 3.1
+ * 2.1: select a compatibility (non-Core) profile with GL version 2.1.
+ * 3.0: select a compatibility (non-Core) profile with GL version 3.0.
+ * 3.0FC: select a Core+Forward Compatible profile with GL version 3.0.
+ * 3.1: select GL version 3.1 with GL_ARB_compatibility enabled per the driver default.
+ * 3.1FC: select GL version 3.1 with forward compatibility and GL_ARB_compatibility disabled.
+ * 3.1COMPAT: select GL version 3.1 with GL_ARB_compatibility enabled.
+ * X.Y: override GL version to X.Y without changing the profile.
+ * X.YFC: select a Core+Forward Compatible profile with GL version X.Y.
+ * X.YCOMPAT: select a Compatibility profile with GL version X.Y.
+ *
+ * Example uses of MESA_GLES_VERSION_OVERRIDE:
+ *
+ * 2.0: select GLES version 2.0.
+ * 3.0: select GLES version 3.0.
+ * 3.1: select GLES version 3.1.
*/
bool
_mesa_override_gl_version_contextless(struct gl_constants *consts,
if (version > 0) {
*versionOut = version;
- /* 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.
- */
+ /* Modify the API and context flags as needed. */
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 {
+ } else if (compat_context) {
*apiOut = API_OPENGL_COMPAT;
}
}
* <version number><space><vendor-specific information>"
*/
create_version_string(ctx, _mesa_is_gles(ctx) ? "OpenGL ES " : "");
+ ctx->Extensions.Version = ctx->Version;
}
}
extensions->ARB_fragment_shader &&
extensions->ARB_texture_non_power_of_two &&
extensions->EXT_blend_equation_separate &&
-
- /* Technically, 2.0 requires the functionality of the
- * EXT version. Enable 2.0 if either extension is
- * available, and assume that a driver that only
- * exposes the ATI extension will fallback to
- * software when necessary.
- */
- (extensions->EXT_stencil_two_side
- || extensions->ATI_separate_stencil));
+ extensions->EXT_stencil_two_side);
const bool ver_2_1 = (ver_2_0 &&
extensions->EXT_pixel_buffer_object &&
extensions->EXT_texture_sRGB);
extensions->ARB_gpu_shader5 &&
extensions->ARB_gpu_shader_fp64 &&
extensions->ARB_sample_shading &&
- extensions->ARB_shader_subroutine &&
extensions->ARB_tessellation_shader &&
extensions->ARB_texture_buffer_object_rgb32 &&
extensions->ARB_texture_cube_map_array &&
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 &&
+ consts->Program[MESA_SHADER_VERTEX].MaxUniformBlocks >= 14 &&
+ 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 &&
+ consts->MaxVertexAttribStride >= 2048 &&
+ 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);
+ const bool ver_4_6 = (ver_4_5 &&
+ consts->GLSLVersion >= 460 &&
+ extensions->ARB_gl_spirv &&
+ extensions->ARB_spirv_extensions &&
+ extensions->ARB_indirect_parameters &&
+ extensions->ARB_pipeline_statistics_query &&
+ extensions->ARB_polygon_offset_clamp &&
+ extensions->ARB_shader_atomic_counter_ops &&
+ extensions->ARB_shader_draw_parameters &&
+ extensions->ARB_shader_group_vote &&
+ extensions->ARB_texture_filter_anisotropic &&
+ extensions->ARB_transform_feedback_overflow_query);
+
+ if (ver_4_6) {
+ major = 4;
+ minor = 6;
+ }
+ else 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->ARB_internalformat_query &&
extensions->ARB_map_buffer_range &&
extensions->ARB_shader_texture_lod &&
- extensions->ARB_texture_float &&
+ extensions->OES_texture_float &&
+ extensions->OES_texture_half_float &&
+ extensions->OES_texture_half_float_linear &&
extensions->ARB_texture_rg &&
extensions->ARB_depth_buffer_float &&
- extensions->EXT_draw_buffers2 &&
- /* extensions->ARB_framebuffer_object && */
- extensions->EXT_framebuffer_sRGB &&
+ extensions->ARB_framebuffer_object &&
+ extensions->EXT_sRGB &&
extensions->EXT_packed_float &&
extensions->EXT_texture_array &&
extensions->EXT_texture_shared_exponent &&
+ extensions->EXT_texture_sRGB &&
extensions->EXT_transform_feedback &&
extensions->ARB_draw_instanced &&
extensions->ARB_uniform_buffer_object &&
extensions->EXT_texture_snorm &&
extensions->NV_primitive_restart &&
- extensions->OES_depth_texture_cube_map);
+ extensions->OES_depth_texture_cube_map &&
+ extensions->EXT_texture_type_2_10_10_10_REV);
+ const bool es31_compute_shader =
+ consts->MaxComputeWorkGroupInvocations >= 128;
const bool ver_3_1 = (ver_3_0 &&
+ consts->MaxVertexAttribStride >= 2048 &&
extensions->ARB_arrays_of_arrays &&
- extensions->ARB_compute_shader &&
+ es31_compute_shader &&
extensions->ARB_draw_indirect &&
extensions->ARB_explicit_uniform_location &&
extensions->ARB_framebuffer_no_attachments &&
extensions->ARB_shading_language_packing &&
extensions->ARB_stencil_texturing &&
extensions->ARB_texture_multisample &&
- extensions->ARB_gpu_shader5 &&
+ extensions->ARB_texture_gather &&
+ extensions->MESA_shader_integer_functions &&
extensions->EXT_shader_integer_mix);
-
- if (ver_3_1) {
+ const bool ver_3_2 = (ver_3_1 &&
+ extensions->EXT_draw_buffers2 &&
+ extensions->KHR_blend_equation_advanced &&
+ extensions->KHR_robustness &&
+ 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 &&
+ extensions->OES_sample_variables &&
+ extensions->ARB_tessellation_shader &&
+ extensions->ARB_texture_border_clamp &&
+ extensions->OES_texture_buffer &&
+ extensions->OES_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;
{
switch (api) {
case API_OPENGL_COMPAT:
- /* Disable GLSL 1.40 and later for legacy contexts.
- * This disallows creation of the GL 3.1 compatibility context. */
- if (consts->GLSLVersion > 130) {
- consts->GLSLVersion = 130;
+ /* Disable higher GLSL versions for legacy contexts.
+ * This disallows creation of higher compatibility contexts. */
+ if (!consts->AllowHigherCompatVersion) {
+ consts->GLSLVersion = consts->GLSLVersionCompat;
}
/* fall through */
case API_OPENGL_CORE:
case API_OPENGLES:
return compute_version_es1(extensions);
case API_OPENGLES2:
- return compute_version_es2(extensions);
+ return compute_version_es2(extensions, consts);
}
return 0;
}
_mesa_compute_version(struct gl_context *ctx)
{
if (ctx->Version)
- return;
+ goto done;
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.
*/
- if (ctx->API == API_OPENGL_CORE) {
+ if (_mesa_is_desktop_gl(ctx)) {
switch (ctx->Version) {
+ case 20:
+ /* fall-through, GLSL 1.20 is the minimum we support */
+ case 21:
+ ctx->Const.GLSLVersion = 120;
+ break;
+ case 30:
+ ctx->Const.GLSLVersion = 130;
+ break;
case 31:
ctx->Const.GLSLVersion = 140;
break;
ctx->Const.GLSLVersion = 150;
break;
default:
- ctx->Const.GLSLVersion = ctx->Version * 10;
+ if (ctx->Version >= 33)
+ ctx->Const.GLSLVersion = ctx->Version * 10;
break;
}
}
create_version_string(ctx, "OpenGL ES ");
break;
}
+
+done:
+ if (ctx->API == API_OPENGL_COMPAT && ctx->Version >= 31)
+ ctx->Extensions.ARB_compatibility = GL_TRUE;
+}
+
+
+void
+_mesa_get_driver_uuid(struct gl_context *ctx, GLint *uuid)
+{
+ ctx->Driver.GetDriverUuid(ctx, (char*) uuid);
+}
+
+void
+_mesa_get_device_uuid(struct gl_context *ctx, GLint *uuid)
+{
+ ctx->Driver.GetDeviceUuid(ctx, (char*) uuid);
+}
+
+/**
+ * Get the i-th GLSL version string. If index=0, return the most recent
+ * supported version.
+ * \param ctx context to query
+ * \param index which version string to return, or -1 if none
+ * \param versionOut returns the vesrion string
+ * \return total number of shading language versions.
+ */
+int
+_mesa_get_shading_language_version(const struct gl_context *ctx,
+ int index,
+ char **versionOut)
+{
+ int n = 0;
+
+#define GLSL_VERSION(S) \
+ if (n++ == index) \
+ *versionOut = S
+
+ /* GLSL core */
+ if (ctx->Const.GLSLVersion >= 460)
+ GLSL_VERSION("460");
+ if (ctx->Const.GLSLVersion >= 450)
+ GLSL_VERSION("450");
+ if (ctx->Const.GLSLVersion >= 440)
+ GLSL_VERSION("440");
+ if (ctx->Const.GLSLVersion >= 430)
+ GLSL_VERSION("430");
+ if (ctx->Const.GLSLVersion >= 420)
+ GLSL_VERSION("420");
+ if (ctx->Const.GLSLVersion >= 410)
+ GLSL_VERSION("410");
+ if (ctx->Const.GLSLVersion >= 400)
+ GLSL_VERSION("400");
+ if (ctx->Const.GLSLVersion >= 330)
+ GLSL_VERSION("330");
+ if (ctx->Const.GLSLVersion >= 150)
+ GLSL_VERSION("150");
+ if (ctx->Const.GLSLVersion >= 140)
+ GLSL_VERSION("140");
+ if (ctx->Const.GLSLVersion >= 130)
+ GLSL_VERSION("130");
+ if (ctx->Const.GLSLVersion >= 120)
+ GLSL_VERSION("120");
+ /* The GL spec says to return the empty string for GLSL 1.10 */
+ if (ctx->Const.GLSLVersion >= 110)
+ GLSL_VERSION("");
+
+ /* GLSL es */
+ if ((ctx->API == API_OPENGLES2 && ctx->Version >= 32) ||
+ ctx->Extensions.ARB_ES3_2_compatibility)
+ GLSL_VERSION("320 es");
+ if (_mesa_is_gles31(ctx) || ctx->Extensions.ARB_ES3_1_compatibility)
+ GLSL_VERSION("310 es");
+ if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility)
+ GLSL_VERSION("300 es");
+ if (ctx->API == API_OPENGLES2 || ctx->Extensions.ARB_ES2_compatibility)
+ GLSL_VERSION("100");
+
+#undef GLSL_VERSION
+
+ return n;
}