xref: /third_party/mesa3d/src/mesa/main/version.c (revision bf215546)
1/*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2010  VMware, Inc.  All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26#include <stdio.h>
27#include "context.h"
28#include "draw_validate.h"
29
30#include "util/os_misc.h"
31#include "util/simple_mtx.h"
32
33#include "mtypes.h"
34#include "version.h"
35#include "git_sha1.h"
36
37#include "state_tracker/st_context.h"
38
39static simple_mtx_t override_lock = _SIMPLE_MTX_INITIALIZER_NP;
40
41/**
42 * Scans 'string' to see if it ends with 'ending'.
43 */
44static bool
45check_for_ending(const char *string, const char *ending)
46{
47   const size_t len1 = strlen(string);
48   const size_t len2 = strlen(ending);
49
50   if (len2 > len1)
51      return false;
52
53   return strcmp(string + (len1 - len2), ending) == 0;
54}
55
56/**
57 * Returns the gl override data
58 *
59 * version > 0 indicates there is an override requested
60 * fwd_context is only valid if version > 0
61 */
62static void
63get_gl_override(gl_api api, int *version, bool *fwd_context,
64                bool *compat_context)
65{
66   const char *env_var = (api == API_OPENGL_CORE || api == API_OPENGL_COMPAT)
67      ? "MESA_GL_VERSION_OVERRIDE" : "MESA_GLES_VERSION_OVERRIDE";
68   const char *version_str;
69   int major, minor, n;
70   static struct override_info {
71      int version;
72      bool fc_suffix;
73      bool compat_suffix;
74   } override[] = {
75      [API_OPENGL_COMPAT] = { -1, false, false},
76      [API_OPENGLES]      = { -1, false, false},
77      [API_OPENGLES2]     = { -1, false, false},
78      [API_OPENGL_CORE]   = { -1, false, false},
79   };
80
81   STATIC_ASSERT(ARRAY_SIZE(override) == API_OPENGL_LAST + 1);
82
83   simple_mtx_lock(&override_lock);
84
85   if (api == API_OPENGLES)
86      goto exit;
87
88   if (override[api].version < 0) {
89      override[api].version = 0;
90
91      version_str = os_get_option(env_var);
92      if (version_str) {
93         override[api].fc_suffix = check_for_ending(version_str, "FC");
94         override[api].compat_suffix = check_for_ending(version_str, "COMPAT");
95
96         n = sscanf(version_str, "%u.%u", &major, &minor);
97         if (n != 2) {
98            fprintf(stderr, "error: invalid value for %s: %s\n",
99                    env_var, version_str);
100            override[api].version = 0;
101         } else {
102            override[api].version = major * 10 + minor;
103
104            /* There is no such thing as compatibility or forward-compatible for
105             * OpenGL ES 2.0 or 3.x APIs.
106             */
107            if ((override[api].version < 30 && override[api].fc_suffix) ||
108                (api == API_OPENGLES2 && (override[api].fc_suffix ||
109                                          override[api].compat_suffix))) {
110               fprintf(stderr, "error: invalid value for %s: %s\n",
111                       env_var, version_str);
112            }
113         }
114      }
115   }
116
117exit:
118   *version = override[api].version;
119   *fwd_context = override[api].fc_suffix;
120   *compat_context = override[api].compat_suffix;
121
122   simple_mtx_unlock(&override_lock);
123}
124
125/**
126 * Builds the Mesa version string.
127 */
128static void
129create_version_string(struct gl_context *ctx, const char *prefix)
130{
131   static const int max = 100;
132
133   ctx->VersionString = malloc(max);
134   if (ctx->VersionString) {
135      snprintf(ctx->VersionString, max,
136		     "%s%u.%u%s Mesa " PACKAGE_VERSION MESA_GIT_SHA1,
137		     prefix,
138		     ctx->Version / 10, ctx->Version % 10,
139		     (ctx->API == API_OPENGL_CORE) ? " (Core Profile)" :
140                     (ctx->API == API_OPENGL_COMPAT && ctx->Version >= 32) ?
141                        " (Compatibility Profile)" : ""
142		     );
143   }
144}
145
146/**
147 * Override the context's version and/or API type if the environment variables
148 * MESA_GL_VERSION_OVERRIDE or MESA_GLES_VERSION_OVERRIDE are set.
149 *
150 * Example uses of MESA_GL_VERSION_OVERRIDE:
151 *
152 * 2.1: select a compatibility (non-Core) profile with GL version 2.1.
153 * 3.0: select a compatibility (non-Core) profile with GL version 3.0.
154 * 3.0FC: select a Core+Forward Compatible profile with GL version 3.0.
155 * 3.1: select GL version 3.1 with GL_ARB_compatibility enabled per the driver default.
156 * 3.1FC: select GL version 3.1 with forward compatibility and GL_ARB_compatibility disabled.
157 * 3.1COMPAT: select GL version 3.1 with GL_ARB_compatibility enabled.
158 * X.Y: override GL version to X.Y without changing the profile.
159 * X.YFC: select a Core+Forward Compatible profile with GL version X.Y.
160 * X.YCOMPAT: select a Compatibility profile with GL version X.Y.
161 *
162 * Example uses of MESA_GLES_VERSION_OVERRIDE:
163 *
164 * 2.0: select GLES version 2.0.
165 * 3.0: select GLES version 3.0.
166 * 3.1: select GLES version 3.1.
167 */
168bool
169_mesa_override_gl_version_contextless(struct gl_constants *consts,
170                                      gl_api *apiOut, GLuint *versionOut)
171{
172   int version;
173   bool fwd_context, compat_context;
174
175   get_gl_override(*apiOut, &version, &fwd_context, &compat_context);
176
177   if (version > 0) {
178      *versionOut = version;
179
180      /* Modify the API and context flags as needed. */
181      if (*apiOut == API_OPENGL_CORE || *apiOut == API_OPENGL_COMPAT) {
182         if (version >= 30 && fwd_context) {
183            *apiOut = API_OPENGL_CORE;
184            consts->ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
185         } else if (compat_context) {
186            *apiOut = API_OPENGL_COMPAT;
187         }
188      }
189
190      return true;
191   }
192   return false;
193}
194
195void
196_mesa_override_gl_version(struct gl_context *ctx)
197{
198   if (_mesa_override_gl_version_contextless(&ctx->Const, &ctx->API,
199                                             &ctx->Version)) {
200      /* We need to include API in version string for OpenGL ES, otherwise
201       * application can not detect GLES via glGetString(GL_VERSION) query.
202       *
203       * From OpenGL ES 3.2 spec, Page 436:
204       *
205       *     "The VERSION string is laid out as follows:
206       *
207       *     OpenGL ES N.M vendor-specific information"
208       *
209       * From OpenGL 4.5 spec, Page 538:
210       *
211       *     "The VERSION and SHADING_LANGUAGE_VERSION strings are laid out as
212       *     follows:
213       *
214       *     <version number><space><vendor-specific information>"
215       */
216      create_version_string(ctx, _mesa_is_gles(ctx) ? "OpenGL ES " : "");
217      ctx->Extensions.Version = ctx->Version;
218   }
219}
220
221/**
222 * Override the context's GLSL version if the environment variable
223 * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
224 * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
225 */
226void
227_mesa_override_glsl_version(struct gl_constants *consts)
228{
229   const char *env_var = "MESA_GLSL_VERSION_OVERRIDE";
230   const char *version;
231   int n;
232
233   version = getenv(env_var);
234   if (!version) {
235      return;
236   }
237
238   n = sscanf(version, "%u", &consts->GLSLVersion);
239   if (n != 1) {
240      fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
241      return;
242   }
243}
244
245/**
246 * Examine enabled GL extensions to determine GL version.
247 */
248static GLuint
249compute_version(const struct gl_extensions *extensions,
250                const struct gl_constants *consts, gl_api api)
251{
252   GLuint major, minor, version;
253
254   const bool ver_1_4 = (extensions->ARB_shadow);
255   const bool ver_1_5 = (ver_1_4 &&
256                         extensions->ARB_occlusion_query);
257   const bool ver_2_0 = (ver_1_5 &&
258                         extensions->ARB_point_sprite &&
259                         extensions->ARB_vertex_shader &&
260                         extensions->ARB_fragment_shader &&
261                         extensions->ARB_texture_non_power_of_two &&
262                         extensions->EXT_blend_equation_separate &&
263                         extensions->EXT_stencil_two_side);
264   const bool ver_2_1 = (ver_2_0 &&
265                         extensions->EXT_pixel_buffer_object &&
266                         extensions->EXT_texture_sRGB);
267   /* We lie about the minimum number of color attachments. Strictly, OpenGL
268    * 3.0 requires 8, whereas OpenGL ES requires 4. OpenGL ES 3.0 class
269    * hardware may only support 4 render targets. Advertise non-conformant
270    * OpenGL 3.0 anyway. Affects freedreno on a3xx
271    */
272   const bool ver_3_0 = (ver_2_1 &&
273                         consts->GLSLVersion >= 130 &&
274                         consts->MaxColorAttachments >= 4 &&
275                         (consts->MaxSamples >= 4 || consts->FakeSWMSAA) &&
276                         (api == API_OPENGL_CORE ||
277                          extensions->ARB_color_buffer_float) &&
278                         extensions->ARB_depth_buffer_float &&
279                         extensions->ARB_half_float_vertex &&
280                         extensions->ARB_map_buffer_range &&
281                         extensions->ARB_shader_texture_lod &&
282                         extensions->ARB_texture_float &&
283                         extensions->ARB_texture_rg &&
284                         extensions->ARB_texture_compression_rgtc &&
285                         extensions->EXT_draw_buffers2 &&
286                         extensions->ARB_framebuffer_object &&
287                         extensions->EXT_framebuffer_sRGB &&
288                         extensions->EXT_packed_float &&
289                         extensions->EXT_texture_array &&
290                         extensions->EXT_texture_shared_exponent &&
291                         extensions->EXT_transform_feedback &&
292                         extensions->NV_conditional_render);
293   const bool ver_3_1 = (ver_3_0 &&
294                         consts->GLSLVersion >= 140 &&
295                         extensions->ARB_draw_instanced &&
296                         extensions->ARB_texture_buffer_object &&
297                         extensions->ARB_uniform_buffer_object &&
298                         extensions->EXT_texture_snorm &&
299                         extensions->NV_primitive_restart &&
300                         extensions->NV_texture_rectangle &&
301                         consts->Program[MESA_SHADER_VERTEX].MaxTextureImageUnits >= 16);
302   const bool ver_3_2 = (ver_3_1 &&
303                         consts->GLSLVersion >= 150 &&
304                         extensions->ARB_depth_clamp &&
305                         extensions->ARB_draw_elements_base_vertex &&
306                         extensions->ARB_fragment_coord_conventions &&
307                         extensions->EXT_provoking_vertex &&
308                         extensions->ARB_seamless_cube_map &&
309                         extensions->ARB_sync &&
310                         extensions->ARB_texture_multisample &&
311                         extensions->EXT_vertex_array_bgra);
312   const bool ver_3_3 = (ver_3_2 &&
313                         consts->GLSLVersion >= 330 &&
314                         extensions->ARB_blend_func_extended &&
315                         extensions->ARB_explicit_attrib_location &&
316                         extensions->ARB_instanced_arrays &&
317                         extensions->ARB_occlusion_query2 &&
318                         extensions->ARB_shader_bit_encoding &&
319                         extensions->ARB_texture_rgb10_a2ui &&
320                         extensions->ARB_timer_query &&
321                         extensions->ARB_vertex_type_2_10_10_10_rev &&
322                         extensions->EXT_texture_swizzle);
323   /* ARB_sampler_objects is always enabled in mesa */
324
325   const bool ver_4_0 = (ver_3_3 &&
326                         consts->GLSLVersion >= 400 &&
327                         extensions->ARB_draw_buffers_blend &&
328                         extensions->ARB_draw_indirect &&
329                         extensions->ARB_gpu_shader5 &&
330                         extensions->ARB_gpu_shader_fp64 &&
331                         extensions->ARB_sample_shading &&
332                         extensions->ARB_tessellation_shader &&
333                         extensions->ARB_texture_buffer_object_rgb32 &&
334                         extensions->ARB_texture_cube_map_array &&
335                         extensions->ARB_texture_query_lod &&
336                         extensions->ARB_transform_feedback2 &&
337                         extensions->ARB_transform_feedback3);
338   const bool ver_4_1 = (ver_4_0 &&
339                         consts->GLSLVersion >= 410 &&
340                         consts->MaxTextureSize >= 16384 &&
341                         consts->MaxRenderbufferSize >= 16384 &&
342                         extensions->ARB_ES2_compatibility &&
343                         extensions->ARB_shader_precision &&
344                         extensions->ARB_vertex_attrib_64bit &&
345                         extensions->ARB_viewport_array);
346   const bool ver_4_2 = (ver_4_1 &&
347                         consts->GLSLVersion >= 420 &&
348                         extensions->ARB_base_instance &&
349                         extensions->ARB_conservative_depth &&
350                         extensions->ARB_internalformat_query &&
351                         extensions->ARB_shader_atomic_counters &&
352                         extensions->ARB_shader_image_load_store &&
353                         extensions->ARB_shading_language_420pack &&
354                         extensions->ARB_shading_language_packing &&
355                         extensions->ARB_texture_compression_bptc &&
356                         extensions->ARB_transform_feedback_instanced);
357   const bool ver_4_3 = (ver_4_2 &&
358                         consts->GLSLVersion >= 430 &&
359                         consts->Program[MESA_SHADER_VERTEX].MaxUniformBlocks >= 14 &&
360                         extensions->ARB_ES3_compatibility &&
361                         extensions->ARB_arrays_of_arrays &&
362                         extensions->ARB_compute_shader &&
363                         extensions->ARB_copy_image &&
364                         extensions->ARB_explicit_uniform_location &&
365                         extensions->ARB_fragment_layer_viewport &&
366                         extensions->ARB_framebuffer_no_attachments &&
367                         extensions->ARB_internalformat_query2 &&
368                         extensions->ARB_robust_buffer_access_behavior &&
369                         extensions->ARB_shader_image_size &&
370                         extensions->ARB_shader_storage_buffer_object &&
371                         extensions->ARB_stencil_texturing &&
372                         extensions->ARB_texture_buffer_range &&
373                         extensions->ARB_texture_query_levels &&
374                         extensions->ARB_texture_view);
375   const bool ver_4_4 = (ver_4_3 &&
376                         consts->GLSLVersion >= 440 &&
377                         consts->MaxVertexAttribStride >= 2048 &&
378                         extensions->ARB_buffer_storage &&
379                         extensions->ARB_clear_texture &&
380                         extensions->ARB_enhanced_layouts &&
381                         extensions->ARB_query_buffer_object &&
382                         extensions->ARB_texture_mirror_clamp_to_edge &&
383                         extensions->ARB_texture_stencil8 &&
384                         extensions->ARB_vertex_type_10f_11f_11f_rev);
385   const bool ver_4_5 = (ver_4_4 &&
386                         consts->GLSLVersion >= 450 &&
387                         extensions->ARB_ES3_1_compatibility &&
388                         extensions->ARB_clip_control &&
389                         extensions->ARB_conditional_render_inverted &&
390                         extensions->ARB_cull_distance &&
391                         extensions->ARB_derivative_control &&
392                         extensions->ARB_shader_texture_image_samples &&
393                         extensions->NV_texture_barrier);
394   const bool ver_4_6 = (ver_4_5 &&
395                         consts->GLSLVersion >= 460 &&
396                         extensions->ARB_gl_spirv &&
397                         extensions->ARB_spirv_extensions &&
398                         extensions->ARB_indirect_parameters &&
399                         extensions->ARB_pipeline_statistics_query &&
400                         extensions->ARB_polygon_offset_clamp &&
401                         extensions->ARB_shader_atomic_counter_ops &&
402                         extensions->ARB_shader_draw_parameters &&
403                         extensions->ARB_shader_group_vote &&
404                         extensions->ARB_texture_filter_anisotropic &&
405                         extensions->ARB_transform_feedback_overflow_query);
406
407   if (ver_4_6) {
408      major = 4;
409      minor = 6;
410   }
411   else if (ver_4_5) {
412      major = 4;
413      minor = 5;
414   }
415   else if (ver_4_4) {
416      major = 4;
417      minor = 4;
418   }
419   else if (ver_4_3) {
420      major = 4;
421      minor = 3;
422   }
423   else if (ver_4_2) {
424      major = 4;
425      minor = 2;
426   }
427   else if (ver_4_1) {
428      major = 4;
429      minor = 1;
430   }
431   else if (ver_4_0) {
432      major = 4;
433      minor = 0;
434   }
435   else if (ver_3_3) {
436      major = 3;
437      minor = 3;
438   }
439   else if (ver_3_2) {
440      major = 3;
441      minor = 2;
442   }
443   else if (ver_3_1) {
444      major = 3;
445      minor = 1;
446   }
447   else if (ver_3_0) {
448      major = 3;
449      minor = 0;
450   }
451   else if (ver_2_1) {
452      major = 2;
453      minor = 1;
454   }
455   else if (ver_2_0) {
456      major = 2;
457      minor = 0;
458   }
459   else if (ver_1_5) {
460      major = 1;
461      minor = 5;
462   }
463   else if (ver_1_4) {
464      major = 1;
465      minor = 4;
466   }
467   else {
468      major = 1;
469      minor = 3;
470   }
471
472   version = major * 10 + minor;
473
474   if (api == API_OPENGL_CORE && version < 31)
475      return 0;
476
477   return version;
478}
479
480static GLuint
481compute_version_es2(const struct gl_extensions *extensions,
482                    const struct gl_constants *consts)
483{
484   /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
485   const bool ver_2_0 = (extensions->ARB_vertex_shader &&
486                         extensions->ARB_fragment_shader &&
487                         extensions->ARB_texture_non_power_of_two &&
488                         extensions->EXT_blend_equation_separate);
489   /* FINISHME: This list isn't quite right. */
490   const bool ver_3_0 = (extensions->ARB_half_float_vertex &&
491                         extensions->ARB_internalformat_query &&
492                         extensions->ARB_map_buffer_range &&
493                         extensions->ARB_shader_texture_lod &&
494                         extensions->OES_texture_float &&
495                         extensions->OES_texture_half_float &&
496                         extensions->OES_texture_half_float_linear &&
497                         extensions->ARB_texture_rg &&
498                         extensions->ARB_depth_buffer_float &&
499                         extensions->ARB_framebuffer_object &&
500                         extensions->EXT_sRGB &&
501                         extensions->EXT_packed_float &&
502                         extensions->EXT_texture_array &&
503                         extensions->EXT_texture_shared_exponent &&
504                         extensions->EXT_texture_sRGB &&
505                         extensions->EXT_transform_feedback &&
506                         extensions->ARB_draw_instanced &&
507                         extensions->ARB_uniform_buffer_object &&
508                         extensions->EXT_texture_snorm &&
509                         (extensions->NV_primitive_restart ||
510                          consts->PrimitiveRestartFixedIndex) &&
511                         extensions->OES_depth_texture_cube_map &&
512                         extensions->EXT_texture_type_2_10_10_10_REV &&
513                         consts->MaxColorAttachments >= 4);
514   const bool es31_compute_shader =
515      consts->MaxComputeWorkGroupInvocations >= 128 &&
516      consts->Program[MESA_SHADER_COMPUTE].MaxShaderStorageBlocks &&
517      consts->Program[MESA_SHADER_COMPUTE].MaxAtomicBuffers &&
518      consts->Program[MESA_SHADER_COMPUTE].MaxImageUniforms;
519   const bool ver_3_1 = (ver_3_0 &&
520                         consts->MaxVertexAttribStride >= 2048 &&
521                         extensions->ARB_arrays_of_arrays &&
522                         es31_compute_shader &&
523                         extensions->ARB_draw_indirect &&
524                         extensions->ARB_explicit_uniform_location &&
525                         extensions->ARB_framebuffer_no_attachments &&
526                         extensions->ARB_shading_language_packing &&
527                         extensions->ARB_stencil_texturing &&
528                         extensions->ARB_texture_multisample &&
529                         extensions->ARB_texture_gather &&
530                         extensions->MESA_shader_integer_functions &&
531                         extensions->EXT_shader_integer_mix);
532   const bool ver_3_2 = (ver_3_1 &&
533                         /* ES 3.2 requires that images/buffers be accessible
534                          * from fragment shaders as well
535                          */
536                         extensions->ARB_shader_atomic_counters &&
537                         extensions->ARB_shader_image_load_store &&
538                         extensions->ARB_shader_image_size &&
539                         extensions->ARB_shader_storage_buffer_object &&
540
541                         extensions->EXT_draw_buffers2 &&
542                         extensions->KHR_blend_equation_advanced &&
543                         extensions->KHR_robustness &&
544                         extensions->KHR_texture_compression_astc_ldr &&
545                         extensions->OES_copy_image &&
546                         extensions->ARB_draw_buffers_blend &&
547                         extensions->ARB_draw_elements_base_vertex &&
548                         extensions->OES_geometry_shader &&
549                         extensions->OES_primitive_bounding_box &&
550                         extensions->OES_sample_variables &&
551                         extensions->ARB_tessellation_shader &&
552                         extensions->OES_texture_buffer &&
553                         extensions->OES_texture_cube_map_array &&
554                         extensions->ARB_texture_stencil8);
555
556   if (ver_3_2) {
557      return 32;
558   } else if (ver_3_1) {
559      return 31;
560   } else if (ver_3_0) {
561      return 30;
562   } else if (ver_2_0) {
563      return 20;
564   } else {
565      return 0;
566   }
567}
568
569GLuint
570_mesa_get_version(const struct gl_extensions *extensions,
571                  struct gl_constants *consts, gl_api api)
572{
573   switch (api) {
574   case API_OPENGL_COMPAT:
575      /* Disable higher GLSL versions for legacy contexts.
576       * This disallows creation of higher compatibility contexts. */
577      if (!consts->AllowHigherCompatVersion) {
578         consts->GLSLVersion = consts->GLSLVersionCompat;
579      }
580      FALLTHROUGH;
581   case API_OPENGL_CORE:
582      return compute_version(extensions, consts, api);
583   case API_OPENGLES:
584      return 11;
585   case API_OPENGLES2:
586      return compute_version_es2(extensions, consts);
587   }
588   return 0;
589}
590
591/**
592 * Set the context's Version and VersionString fields.
593 * This should only be called once as part of context initialization
594 * or to perform version check for GLX_ARB_create_context_profile.
595 */
596void
597_mesa_compute_version(struct gl_context *ctx)
598{
599   if (ctx->Version)
600      goto done;
601
602   ctx->Version = _mesa_get_version(&ctx->Extensions, &ctx->Const, ctx->API);
603   ctx->Extensions.Version = ctx->Version;
604
605   /* Make sure that the GLSL version lines up with the GL version. In some
606    * cases it can be too high, e.g. if an extension is missing.
607    */
608   if (_mesa_is_desktop_gl(ctx)) {
609      switch (ctx->Version) {
610      case 20:
611         FALLTHROUGH; /* GLSL 1.20 is the minimum we support */
612      case 21:
613         ctx->Const.GLSLVersion = 120;
614         break;
615      case 30:
616         ctx->Const.GLSLVersion = 130;
617         break;
618      case 31:
619         ctx->Const.GLSLVersion = 140;
620         break;
621      case 32:
622         ctx->Const.GLSLVersion = 150;
623         break;
624      default:
625         if (ctx->Version >= 33)
626            ctx->Const.GLSLVersion = ctx->Version * 10;
627         break;
628      }
629   }
630
631   switch (ctx->API) {
632   case API_OPENGL_COMPAT:
633   case API_OPENGL_CORE:
634      create_version_string(ctx, "");
635      break;
636
637   case API_OPENGLES:
638      if (!ctx->Version) {
639         _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
640         return;
641      }
642      create_version_string(ctx, "OpenGL ES-CM ");
643      break;
644
645   case API_OPENGLES2:
646      if (!ctx->Version) {
647         _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
648         return;
649      }
650      create_version_string(ctx, "OpenGL ES ");
651      break;
652   }
653
654done:
655   if (ctx->API == API_OPENGL_COMPAT && ctx->Version >= 31)
656      ctx->Extensions.ARB_compatibility = GL_TRUE;
657
658   /* Precompute valid primitive types for faster draw time validation. */
659   /* All primitive type enums are less than 32, so we can use the shift. */
660   ctx->SupportedPrimMask = (1 << GL_POINTS) |
661                           (1 << GL_LINES) |
662                           (1 << GL_LINE_LOOP) |
663                           (1 << GL_LINE_STRIP) |
664                           (1 << GL_TRIANGLES) |
665                           (1 << GL_TRIANGLE_STRIP) |
666                           (1 << GL_TRIANGLE_FAN);
667
668   if (ctx->API == API_OPENGL_COMPAT) {
669      ctx->SupportedPrimMask |= (1 << GL_QUADS) |
670                               (1 << GL_QUAD_STRIP) |
671                               (1 << GL_POLYGON);
672   }
673
674   if (_mesa_has_geometry_shaders(ctx)) {
675      ctx->SupportedPrimMask |= (1 << GL_LINES_ADJACENCY) |
676                               (1 << GL_LINE_STRIP_ADJACENCY) |
677                               (1 << GL_TRIANGLES_ADJACENCY) |
678                               (1 << GL_TRIANGLE_STRIP_ADJACENCY);
679   }
680
681   if (_mesa_has_tessellation(ctx))
682      ctx->SupportedPrimMask |= 1 << GL_PATCHES;
683
684   /* First time initialization. */
685   _mesa_update_valid_to_render_state(ctx);
686}
687
688
689void
690_mesa_get_driver_uuid(struct gl_context *ctx, GLint *uuid)
691{
692   struct pipe_screen *screen = ctx->pipe->screen;
693   assert(GL_UUID_SIZE_EXT >= PIPE_UUID_SIZE);
694   memset(uuid, 0, GL_UUID_SIZE_EXT);
695   screen->get_driver_uuid(screen, (char *)uuid);
696}
697
698void
699_mesa_get_device_uuid(struct gl_context *ctx, GLint *uuid)
700{
701   struct pipe_screen *screen = ctx->pipe->screen;
702   assert(GL_UUID_SIZE_EXT >= PIPE_UUID_SIZE);
703   memset(uuid, 0, GL_UUID_SIZE_EXT);
704   screen->get_device_uuid(screen, (char *)uuid);
705}
706
707void
708_mesa_get_device_luid(struct gl_context *ctx, GLint *luid)
709{
710   struct pipe_screen *screen = ctx->pipe->screen;
711   assert(GL_LUID_SIZE_EXT >= PIPE_LUID_SIZE);
712   memset(luid, 0, GL_UUID_SIZE_EXT);
713   screen->get_device_luid(screen, (char *)luid);
714}
715
716/**
717 * Get the i-th GLSL version string.  If index=0, return the most recent
718 * supported version.
719 * \param ctx context to query
720 * \param index  which version string to return, or -1 if none
721 * \param versionOut returns the vesrion string
722 * \return total number of shading language versions.
723 */
724int
725_mesa_get_shading_language_version(const struct gl_context *ctx,
726                                   int index,
727                                   char **versionOut)
728{
729   int n = 0;
730
731#define GLSL_VERSION(S) \
732   if (n++ == index) \
733      *versionOut = S
734
735   /* GLSL core */
736   if (ctx->Const.GLSLVersion >= 460)
737      GLSL_VERSION("460");
738   if (ctx->Const.GLSLVersion >= 450)
739      GLSL_VERSION("450");
740   if (ctx->Const.GLSLVersion >= 440)
741      GLSL_VERSION("440");
742   if (ctx->Const.GLSLVersion >= 430)
743      GLSL_VERSION("430");
744   if (ctx->Const.GLSLVersion >= 420)
745      GLSL_VERSION("420");
746   if (ctx->Const.GLSLVersion >= 410)
747      GLSL_VERSION("410");
748   if (ctx->Const.GLSLVersion >= 400)
749      GLSL_VERSION("400");
750   if (ctx->Const.GLSLVersion >= 330)
751      GLSL_VERSION("330");
752   if (ctx->Const.GLSLVersion >= 150)
753      GLSL_VERSION("150");
754   if (ctx->Const.GLSLVersion >= 140)
755      GLSL_VERSION("140");
756   if (ctx->Const.GLSLVersion >= 130)
757      GLSL_VERSION("130");
758   if (ctx->Const.GLSLVersion >= 120)
759      GLSL_VERSION("120");
760   /* The GL spec says to return the empty string for GLSL 1.10 */
761   if (ctx->Const.GLSLVersion >= 110)
762      GLSL_VERSION("");
763
764   /* GLSL es */
765   if ((ctx->API == API_OPENGLES2 && ctx->Version >= 32) ||
766        ctx->Extensions.ARB_ES3_2_compatibility)
767      GLSL_VERSION("320 es");
768   if (_mesa_is_gles31(ctx) || ctx->Extensions.ARB_ES3_1_compatibility)
769      GLSL_VERSION("310 es");
770   if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility)
771      GLSL_VERSION("300 es");
772   if (ctx->API == API_OPENGLES2 || ctx->Extensions.ARB_ES2_compatibility)
773      GLSL_VERSION("100");
774
775#undef GLSL_VERSION
776
777   return n;
778}
779