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