X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fversion.c;h=418d20e5cb2fd61cee6779c1629e23f8bf03ceb6;hb=0ca266025ab309d538ed8c804cb46d2945c6a547;hp=8bc00ace5c483b3741d34fb26f884f34a68b4e8d;hpb=7d88ab42b9dda825feddbae774a2a48ddf3cbec2;p=mesa.git diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c index 8bc00ace5c4..418d20e5cb2 100644 --- a/src/mesa/main/version.c +++ b/src/mesa/main/version.c @@ -24,7 +24,8 @@ #include -#include "imports.h" +#include "context.h" + #include "mtypes.h" #include "version.h" #include "git_sha1.h" @@ -63,10 +64,10 @@ get_gl_override(gl_api api, int *version, bool *fwd_context, 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); @@ -110,7 +111,7 @@ exit: } /** - * Builds the MESA version string. + * Builds the Mesa version string. */ static void create_version_string(struct gl_context *ctx, const char *prefix) @@ -119,30 +120,38 @@ 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, @@ -156,17 +165,12 @@ _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; } } @@ -181,7 +185,24 @@ _mesa_override_gl_version(struct gl_context *ctx) { 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: + * + * " + */ + create_version_string(ctx, _mesa_is_gles(ctx) ? "OpenGL ES " : ""); + ctx->Extensions.Version = ctx->Version; } } @@ -238,15 +259,7 @@ compute_version(const struct gl_extensions *extensions, 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); @@ -309,7 +322,6 @@ compute_version(const struct gl_extensions *extensions, extensions->ARB_gpu_shader5 && extensions->ARB_gpu_shader_fp64 && extensions->ARB_sample_shading && - false /*extensions->ARB_shader_subroutine*/ && extensions->ARB_tessellation_shader && extensions->ARB_texture_buffer_object_rgb32 && extensions->ARB_texture_cube_map_array && @@ -318,6 +330,8 @@ compute_version(const struct gl_extensions *extensions, extensions->ARB_transform_feedback3); const bool ver_4_1 = (ver_4_0 && consts->GLSLVersion >= 410 && + consts->MaxTextureSize >= 16384 && + consts->MaxRenderbufferSize >= 16384 && extensions->ARB_ES2_compatibility && extensions->ARB_shader_precision && extensions->ARB_vertex_attrib_64bit && @@ -333,8 +347,73 @@ compute_version(const struct gl_extensions *extensions, 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; } @@ -415,7 +494,8 @@ compute_version_es1(const struct gl_extensions *extensions) } 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 && @@ -431,36 +511,64 @@ compute_version_es2(const struct gl_extensions *extensions) 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->NV_primitive_restart || + consts->PrimitiveRestartFixedIndex) && + 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 && - false /*extensions->ARB_framebuffer_no_attachments*/ && + extensions->ARB_explicit_uniform_location && + extensions->ARB_framebuffer_no_attachments && extensions->ARB_shader_atomic_counters && extensions->ARB_shader_image_load_store && - false /*extensions->ARB_shader_image_size*/ && - false /*extensions->ARB_shader_storage_buffer_object*/ && + extensions->ARB_shader_image_size && + extensions->ARB_shader_storage_buffer_object && extensions->ARB_shading_language_packing && extensions->ARB_stencil_texturing && - extensions->ARB_gpu_shader5 && + extensions->ARB_texture_multisample && + 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; @@ -477,10 +585,10 @@ _mesa_get_version(const struct gl_extensions *extensions, { 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: @@ -488,7 +596,7 @@ _mesa_get_version(const struct gl_extensions *extensions, case API_OPENGLES: return compute_version_es1(extensions); case API_OPENGLES2: - return compute_version_es2(extensions); + return compute_version_es2(extensions, consts); } return 0; } @@ -502,15 +610,24 @@ void _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; @@ -518,7 +635,8 @@ _mesa_compute_version(struct gl_context *ctx) ctx->Const.GLSLVersion = 150; break; default: - ctx->Const.GLSLVersion = ctx->Version * 10; + if (ctx->Version >= 33) + ctx->Const.GLSLVersion = ctx->Version * 10; break; } } @@ -545,4 +663,85 @@ _mesa_compute_version(struct gl_context *ctx) 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; }