X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fversion.c;h=418d20e5cb2fd61cee6779c1629e23f8bf03ceb6;hb=0ca266025ab309d538ed8c804cb46d2945c6a547;hp=68079f4ebbba10160ad28ee79083674c363bbb50;hpb=734bef372d80a2ebf5677eb4fbd0e939f2b3cfb4;p=mesa.git diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c index 68079f4ebbb..418d20e5cb2 100644 --- a/src/mesa/main/version.c +++ b/src/mesa/main/version.c @@ -25,7 +25,7 @@ #include #include "context.h" -#include "imports.h" + #include "mtypes.h" #include "version.h" #include "git_sha1.h" @@ -64,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); @@ -120,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, @@ -157,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; } } @@ -256,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); @@ -335,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 && @@ -370,6 +367,7 @@ compute_version(const struct gl_extensions *extensions, 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 && @@ -388,8 +386,8 @@ compute_version(const struct gl_extensions *extensions, extensions->NV_texture_barrier); const bool ver_4_6 = (ver_4_5 && consts->GLSLVersion >= 460 && - /* extensions->ARB_gl_spirv */ 0 && - /* extensions->ARB_spirv_extensions */ 0 && + extensions->ARB_gl_spirv && + extensions->ARB_spirv_extensions && extensions->ARB_indirect_parameters && extensions->ARB_pipeline_statistics_query && extensions->ARB_polygon_offset_clamp && @@ -513,24 +511,29 @@ 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 && es31_compute_shader && extensions->ARB_draw_indirect && @@ -543,9 +546,11 @@ compute_version_es2(const struct gl_extensions *extensions, 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); 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 && @@ -580,12 +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. */ + /* Disable higher GLSL versions for legacy contexts. + * This disallows creation of higher compatibility contexts. */ if (!consts->AllowHigherCompatVersion) { - if (consts->GLSLVersion > 130) { - consts->GLSLVersion = 130; - } + consts->GLSLVersion = consts->GLSLVersionCompat; } /* fall through */ case API_OPENGL_CORE: @@ -607,7 +610,7 @@ 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; @@ -615,8 +618,16 @@ _mesa_compute_version(struct gl_context *ctx) /* 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; @@ -624,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; } } @@ -651,6 +663,10 @@ _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; } @@ -665,3 +681,67 @@ _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; +}