st_extensions.c revision 3464ebd5
1/**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * Copyright (c) 2008 VMware, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29#include "main/imports.h"
30#include "main/context.h"
31#include "main/macros.h"
32#include "main/mfeatures.h"
33
34#include "pipe/p_context.h"
35#include "pipe/p_defines.h"
36#include "pipe/p_screen.h"
37
38#include "st_context.h"
39#include "st_extensions.h"
40
41
42static int _min(int a, int b)
43{
44   return (a < b) ? a : b;
45}
46
47static float _maxf(float a, float b)
48{
49   return (a > b) ? a : b;
50}
51
52static int _clamp(int a, int min, int max)
53{
54   if (a < min)
55      return min;
56   else if (a > max)
57      return max;
58   else
59      return a;
60}
61
62
63/**
64 * Query driver to get implementation limits.
65 * Note that we have to limit/clamp against Mesa's internal limits too.
66 */
67void st_init_limits(struct st_context *st)
68{
69   struct pipe_screen *screen = st->pipe->screen;
70   struct gl_constants *c = &st->ctx->Const;
71   gl_shader_type sh;
72
73   c->MaxTextureLevels
74      = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
75            MAX_TEXTURE_LEVELS);
76
77   c->Max3DTextureLevels
78      = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS),
79            MAX_3D_TEXTURE_LEVELS);
80
81   c->MaxCubeTextureLevels
82      = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS),
83            MAX_CUBE_TEXTURE_LEVELS);
84
85   c->MaxTextureRectSize
86      = _min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE);
87
88   c->MaxTextureImageUnits
89      = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS),
90            MAX_TEXTURE_IMAGE_UNITS);
91
92   c->MaxVertexTextureImageUnits
93      = _min(screen->get_param(screen, PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS),
94             MAX_VERTEX_TEXTURE_IMAGE_UNITS);
95
96   c->MaxCombinedTextureImageUnits
97      = _min(screen->get_param(screen, PIPE_CAP_MAX_COMBINED_SAMPLERS),
98             MAX_COMBINED_TEXTURE_IMAGE_UNITS);
99
100   c->MaxTextureCoordUnits
101      = _min(c->MaxTextureImageUnits, MAX_TEXTURE_COORD_UNITS);
102
103   c->MaxTextureUnits = _min(c->MaxTextureImageUnits, c->MaxTextureCoordUnits);
104
105   c->MaxDrawBuffers
106      = _clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
107              1, MAX_DRAW_BUFFERS);
108
109   c->MaxLineWidth
110      = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH));
111   c->MaxLineWidthAA
112      = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH_AA));
113
114   c->MaxPointSize
115      = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH));
116   c->MaxPointSizeAA
117      = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH_AA));
118   /* called after _mesa_create_context/_mesa_init_point, fix default user
119    * settable max point size up
120    */
121   st->ctx->Point.MaxSize = MAX2(c->MaxPointSize, c->MaxPointSizeAA);
122   /* these are not queryable. Note that GL basically mandates a 1.0 minimum
123    * for non-aa sizes, but we can go down to 0.0 for aa points.
124    */
125   c->MinPointSize = 1.0f;
126   c->MinPointSizeAA = 0.0f;
127
128   c->MaxTextureMaxAnisotropy
129      = _maxf(2.0f, screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_ANISOTROPY));
130
131   c->MaxTextureLodBias
132      = screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_LOD_BIAS);
133
134   c->MaxDrawBuffers
135      = CLAMP(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
136              1, MAX_DRAW_BUFFERS);
137
138   /* Quads always follow GL provoking rules. */
139   c->QuadsFollowProvokingVertexConvention = GL_FALSE;
140
141   for (sh = 0; sh < MESA_SHADER_TYPES; ++sh) {
142      struct gl_shader_compiler_options *options =
143         &st->ctx->ShaderCompilerOptions[sh];
144      struct gl_program_constants *pc;
145
146      switch (sh) {
147      case PIPE_SHADER_FRAGMENT:
148         pc = &c->FragmentProgram;
149         break;
150      case PIPE_SHADER_VERTEX:
151         pc = &c->VertexProgram;
152         break;
153      case PIPE_SHADER_GEOMETRY:
154         pc = &c->GeometryProgram;
155         break;
156      default:
157         assert(0);
158         continue;
159      }
160
161      pc->MaxNativeInstructions    = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
162      pc->MaxNativeAluInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS);
163      pc->MaxNativeTexInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS);
164      pc->MaxNativeTexIndirections = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS);
165      pc->MaxNativeAttribs         = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INPUTS);
166      pc->MaxNativeTemps           = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEMPS);
167      pc->MaxNativeAddressRegs     = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ADDRS);
168      pc->MaxNativeParameters      = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONSTS);
169      pc->MaxUniformComponents     = 4 * MIN2(pc->MaxNativeParameters, MAX_UNIFORMS);
170      /* raise MaxParameters if native support is higher */
171      pc->MaxParameters            = MAX2(pc->MaxParameters, pc->MaxNativeParameters);
172
173      options->EmitNoNoise = TRUE;
174
175      /* TODO: make these more fine-grained if anyone needs it */
176      options->EmitNoIfs = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
177      options->EmitNoLoops = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
178      options->EmitNoFunctions = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
179      options->EmitNoMainReturn = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
180
181      options->EmitNoCont = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED);
182
183      options->EmitNoIndirectInput = !screen->get_shader_param(screen, sh,
184                                        PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR);
185      options->EmitNoIndirectOutput = !screen->get_shader_param(screen, sh,
186                                        PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR);
187      options->EmitNoIndirectTemp = !screen->get_shader_param(screen, sh,
188                                        PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR);
189      options->EmitNoIndirectUniform = !screen->get_shader_param(screen, sh,
190                                        PIPE_SHADER_CAP_INDIRECT_CONST_ADDR);
191
192      if (options->EmitNoLoops)
193         options->MaxUnrollIterations = MIN2(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS), 65536);
194   }
195
196   /* PIPE_CAP_MAX_FS_INPUTS specifies the number of COLORn + GENERICn inputs
197    * and is set in MaxNativeAttribs. It's always 2 colors + N generic
198    * attributes. The GLSL compiler never uses COLORn for varyings, so we
199    * subtract the 2 colors to get the maximum number of varyings (generic
200    * attributes) supported by a driver. */
201   c->MaxVarying = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT, PIPE_SHADER_CAP_MAX_INPUTS) - 2;
202   c->MaxVarying = MIN2(c->MaxVarying, MAX_VARYING);
203
204   /* XXX we'll need a better query here someday */
205   if (screen->get_param(screen, PIPE_CAP_GLSL)) {
206      c->GLSLVersion = 120;
207   }
208}
209
210
211static GLboolean st_get_s3tc_override(void)
212{
213   const char *override = _mesa_getenv("force_s3tc_enable");
214   if (override && !strcmp(override, "true"))
215      return GL_TRUE;
216   return GL_FALSE;
217}
218
219
220/**
221 * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
222 * which GL extensions are supported.
223 * Quite a few extensions are always supported because they are standard
224 * features or can be built on top of other gallium features.
225 * Some fine tuning may still be needed.
226 */
227void st_init_extensions(struct st_context *st)
228{
229   struct pipe_screen *screen = st->pipe->screen;
230   struct gl_context *ctx = st->ctx;
231
232   /*
233    * Extensions that are supported by all Gallium drivers:
234    */
235   ctx->Extensions.ARB_copy_buffer = GL_TRUE;
236   ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
237   ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
238   ctx->Extensions.ARB_fragment_program = GL_TRUE;
239   ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
240   ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
241   ctx->Extensions.ARB_multisample = GL_TRUE;
242   ctx->Extensions.ARB_sampler_objects = GL_TRUE;
243   ctx->Extensions.ARB_texture_border_clamp = GL_TRUE; /* XXX temp */
244   ctx->Extensions.ARB_texture_compression = GL_TRUE;
245   ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
246   ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
247   ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
248   ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
249   ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
250   ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;
251   ctx->Extensions.ARB_vertex_program = GL_TRUE;
252   ctx->Extensions.ARB_window_pos = GL_TRUE;
253
254   ctx->Extensions.EXT_blend_color = GL_TRUE;
255   ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
256   ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
257   ctx->Extensions.EXT_blend_minmax = GL_TRUE;
258   ctx->Extensions.EXT_blend_subtract = GL_TRUE;
259   ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
260   ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
261   ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
262   ctx->Extensions.EXT_fog_coord = GL_TRUE;
263   ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
264   ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;
265   ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
266   ctx->Extensions.EXT_point_parameters = GL_TRUE;
267   ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
268   ctx->Extensions.EXT_secondary_color = GL_TRUE;
269   ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
270   ctx->Extensions.EXT_texture_env_add = GL_TRUE;
271   ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
272   ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
273   ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
274   ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
275   if (ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2)
276	   ctx->Extensions.EXT_texture_format_BGRA8888 = GL_TRUE;
277
278   ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
279
280   ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
281
282   ctx->Extensions.MESA_pack_invert = GL_TRUE;
283
284   ctx->Extensions.NV_blend_square = GL_TRUE;
285   ctx->Extensions.NV_texgen_reflection = GL_TRUE;
286   ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
287   ctx->Extensions.NV_texture_rectangle = GL_TRUE;
288#if 0
289   /* possibly could support the following two */
290   ctx->Extensions.NV_vertex_program = GL_TRUE;
291   ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
292#endif
293
294#if FEATURE_OES_EGL_image
295   ctx->Extensions.OES_EGL_image = GL_TRUE;
296#endif
297#if FEATURE_OES_draw_texture
298   ctx->Extensions.OES_draw_texture = GL_TRUE;
299#endif
300
301   ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;
302
303   /*
304    * Extensions that depend on the driver/hardware:
305    */
306   if (screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS) > 0) {
307      ctx->Extensions.ARB_draw_buffers = GL_TRUE;
308   }
309
310   if (screen->get_param(screen, PIPE_CAP_TEXTURE_SWIZZLE) > 0) {
311      ctx->Extensions.EXT_texture_swizzle = GL_TRUE;
312   }
313
314   if (screen->get_param(screen, PIPE_CAP_GLSL)) {
315      ctx->Extensions.ARB_fragment_shader = GL_TRUE;
316      ctx->Extensions.ARB_vertex_shader = GL_TRUE;
317      ctx->Extensions.ARB_shader_objects = GL_TRUE;
318      ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
319      ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE;
320      ctx->Extensions.EXT_separate_shader_objects = GL_TRUE;
321   }
322
323   if (screen->get_param(screen, PIPE_CAP_TEXTURE_MIRROR_REPEAT) > 0) {
324      ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
325   }
326
327   if (screen->get_param(screen, PIPE_CAP_BLEND_EQUATION_SEPARATE)) {
328      ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
329   }
330
331   if (screen->get_param(screen, PIPE_CAP_TEXTURE_MIRROR_CLAMP) > 0) {
332      ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
333      ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
334   }
335
336   if (screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) {
337      ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
338   }
339
340   if (screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS) > 1) {
341      ctx->Extensions.ARB_multitexture = GL_TRUE;
342   }
343
344   if (screen->get_param(screen, PIPE_CAP_TWO_SIDED_STENCIL)) {
345      ctx->Extensions.ATI_separate_stencil = GL_TRUE;
346      ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
347   }
348
349   if (screen->get_param(screen, PIPE_CAP_ANISOTROPIC_FILTER)) {
350      ctx->Extensions.EXT_texture_filter_anisotropic = GL_TRUE;
351   }
352
353   if (screen->get_param(screen, PIPE_CAP_POINT_SPRITE)) {
354      ctx->Extensions.ARB_point_sprite = GL_TRUE;
355      /* GL_NV_point_sprite is not supported by gallium because we don't
356       * support the GL_POINT_SPRITE_R_MODE_NV option.
357       */
358   }
359
360   if (screen->get_param(screen, PIPE_CAP_OCCLUSION_QUERY)) {
361      ctx->Extensions.ARB_occlusion_query = GL_TRUE;
362      ctx->Extensions.ARB_occlusion_query2 = GL_TRUE;
363   }
364   if (screen->get_param(screen, PIPE_CAP_TIMER_QUERY)) {
365     ctx->Extensions.EXT_timer_query = GL_TRUE;
366   }
367
368   if (screen->get_param(screen, PIPE_CAP_TEXTURE_SHADOW_MAP)) {
369      ctx->Extensions.ARB_depth_texture = GL_TRUE;
370      ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE;
371      ctx->Extensions.ARB_shadow = GL_TRUE;
372      ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
373      /*ctx->Extensions.ARB_shadow_ambient = GL_TRUE;*/
374   }
375
376   /* GL_EXT_packed_depth_stencil requires both the ability to render to
377    * a depth/stencil buffer and texture from depth/stencil source.
378    */
379   if (screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
380                                   PIPE_TEXTURE_2D, 0,
381                                   PIPE_BIND_DEPTH_STENCIL) &&
382       screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
383                                   PIPE_TEXTURE_2D, 0,
384                                   PIPE_BIND_SAMPLER_VIEW)) {
385      ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
386   }
387   else if (screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
388                                        PIPE_TEXTURE_2D, 0,
389                                        PIPE_BIND_DEPTH_STENCIL) &&
390            screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
391                                        PIPE_TEXTURE_2D, 0,
392                                        PIPE_BIND_SAMPLER_VIEW)) {
393      ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
394   }
395
396   /* float support - assume nothing exclusively supports 64-bit floats */
397   if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_FLOAT,
398                                   PIPE_TEXTURE_2D, 0,
399                                   PIPE_BIND_SAMPLER_VIEW |
400                                   PIPE_BIND_RENDER_TARGET) &&
401      screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
402                                   PIPE_TEXTURE_2D, 0,
403                                   PIPE_BIND_SAMPLER_VIEW |
404                                   PIPE_BIND_RENDER_TARGET)) {
405      ctx->Extensions.ARB_texture_float = GL_TRUE;
406   }
407
408   /* sRGB support */
409   if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
410                                   PIPE_TEXTURE_2D, 0,
411                                   PIPE_BIND_SAMPLER_VIEW) ||
412      screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
413                                   PIPE_TEXTURE_2D, 0,
414                                   PIPE_BIND_SAMPLER_VIEW)) {
415      ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
416      ctx->Extensions.EXT_texture_sRGB_decode = GL_TRUE;
417      if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
418                                   PIPE_TEXTURE_2D, 0,
419                                   PIPE_BIND_RENDER_TARGET) ||
420          screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
421                                   PIPE_TEXTURE_2D, 0,
422                                   PIPE_BIND_RENDER_TARGET)) {
423         ctx->Extensions.EXT_framebuffer_sRGB = GL_TRUE;
424         ctx->Const.sRGBCapable = GL_TRUE;
425      }
426   }
427
428   if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM,
429                                   PIPE_TEXTURE_2D, 0,
430                                   PIPE_BIND_SAMPLER_VIEW)) {
431      ctx->Extensions.ARB_texture_rg = GL_TRUE;
432   }
433
434   /* s3tc support */
435   if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
436                                   PIPE_TEXTURE_2D, 0,
437                                   PIPE_BIND_SAMPLER_VIEW) &&
438       (ctx->Mesa_DXTn || st_get_s3tc_override())) {
439      ctx->Extensions.EXT_texture_compression_s3tc = GL_TRUE;
440      ctx->Extensions.S3_s3tc = GL_TRUE;
441   }
442
443   if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_UNORM,
444                                   PIPE_TEXTURE_2D, 0,
445                                   PIPE_BIND_SAMPLER_VIEW) &&
446       screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_SNORM,
447				   PIPE_TEXTURE_2D, 0,
448                                   PIPE_BIND_SAMPLER_VIEW) &&
449       screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_UNORM,
450                                   PIPE_TEXTURE_2D, 0,
451                                   PIPE_BIND_SAMPLER_VIEW) &&
452       screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_SNORM,
453                                   PIPE_TEXTURE_2D, 0,
454                                   PIPE_BIND_SAMPLER_VIEW)
455       ) {
456     ctx->Extensions.ARB_texture_compression_rgtc = GL_TRUE;
457   }
458
459   if (screen->is_format_supported(screen, PIPE_FORMAT_LATC1_UNORM,
460                                   PIPE_TEXTURE_2D, 0,
461                                   PIPE_BIND_SAMPLER_VIEW) &&
462       screen->is_format_supported(screen, PIPE_FORMAT_LATC1_SNORM,
463                                   PIPE_TEXTURE_2D, 0,
464                                   PIPE_BIND_SAMPLER_VIEW) &&
465       screen->is_format_supported(screen, PIPE_FORMAT_LATC2_UNORM,
466                                   PIPE_TEXTURE_2D, 0,
467                                   PIPE_BIND_SAMPLER_VIEW) &&
468       screen->is_format_supported(screen, PIPE_FORMAT_LATC2_SNORM,
469                                   PIPE_TEXTURE_2D, 0,
470                                   PIPE_BIND_SAMPLER_VIEW)) {
471      ctx->Extensions.EXT_texture_compression_latc = GL_TRUE;
472   }
473
474   if (screen->is_format_supported(screen, PIPE_FORMAT_LATC2_UNORM,
475                                   PIPE_TEXTURE_2D, 0,
476                                   PIPE_BIND_SAMPLER_VIEW)) {
477      ctx->Extensions.ATI_texture_compression_3dc = GL_TRUE;
478   }
479
480   if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SNORM,
481                                   PIPE_TEXTURE_2D, 0,
482                                   PIPE_BIND_SAMPLER_VIEW)) {
483      ctx->Extensions.EXT_texture_snorm = GL_TRUE;
484   }
485
486   /* ycbcr support */
487   if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY,
488                                   PIPE_TEXTURE_2D, 0,
489                                   PIPE_BIND_SAMPLER_VIEW) ||
490       screen->is_format_supported(screen, PIPE_FORMAT_YUYV,
491                                   PIPE_TEXTURE_2D, 0,
492                                   PIPE_BIND_SAMPLER_VIEW)) {
493      ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
494   }
495
496   /* GL_EXT_texture_array */
497   if (screen->get_param(screen, PIPE_CAP_ARRAY_TEXTURES)) {
498      ctx->Extensions.EXT_texture_array = GL_TRUE;
499      ctx->Extensions.MESA_texture_array = GL_TRUE;
500   }
501
502   /* GL_ARB_framebuffer_object */
503   if (ctx->Extensions.EXT_packed_depth_stencil) {
504      /* we support always support GL_EXT_framebuffer_blit */
505      ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
506   }
507
508   if (st->pipe->render_condition) {
509      ctx->Extensions.NV_conditional_render = GL_TRUE;
510   }
511
512   if (screen->get_param(screen, PIPE_CAP_INDEP_BLEND_ENABLE)) {
513      ctx->Extensions.EXT_draw_buffers2 = GL_TRUE;
514   }
515
516   if (screen->get_param(screen, PIPE_CAP_INDEP_BLEND_FUNC)) {
517      ctx->Extensions.ARB_draw_buffers_blend = GL_TRUE;
518   }
519
520   /* GL_ARB_half_float_vertex */
521   if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
522                                   PIPE_BUFFER, 0,
523                                   PIPE_BIND_VERTEX_BUFFER)) {
524      ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
525   }
526
527   if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_FIXED,
528                                   PIPE_BUFFER, 0,
529                                   PIPE_BIND_VERTEX_BUFFER)) {
530      ctx->Extensions.ARB_ES2_compatibility = GL_TRUE;
531   }
532
533   if (screen->get_shader_param(screen, PIPE_SHADER_GEOMETRY, PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
534#if 0 /* XXX re-enable when GLSL compiler again supports geometry shaders */
535      ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
536#endif
537   }
538
539   if (screen->get_param(screen, PIPE_CAP_PRIMITIVE_RESTART)) {
540      ctx->Extensions.NV_primitive_restart = GL_TRUE;
541   }
542
543   if (screen->get_param(screen, PIPE_CAP_DEPTH_CLAMP)) {
544      ctx->Extensions.ARB_depth_clamp = GL_TRUE;
545   }
546
547   /* This extension does not actually require support of floating point
548    * render targets, just clamping controls.
549    * Advertise this extension if either fragment color clamping is supported
550    * or no render targets having color values outside of the range [0, 1]
551    * are supported, in which case the fragment color clamping has no effect
552    * on rendering.
553    */
554   if (screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL) ||
555       (!screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SNORM,
556                                     PIPE_TEXTURE_2D, 0,
557                                     PIPE_BIND_RENDER_TARGET) &&
558        !screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SNORM,
559                                     PIPE_TEXTURE_2D, 0,
560                                     PIPE_BIND_RENDER_TARGET) &&
561        !screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
562                                     PIPE_TEXTURE_2D, 0,
563                                     PIPE_BIND_RENDER_TARGET) &&
564        !screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_FLOAT,
565                                     PIPE_TEXTURE_2D, 0,
566                                     PIPE_BIND_RENDER_TARGET) &&
567        !screen->is_format_supported(screen, PIPE_FORMAT_R11G11B10_FLOAT,
568                                     PIPE_TEXTURE_2D, 0,
569                                     PIPE_BIND_RENDER_TARGET) &&
570        !screen->is_format_supported(screen, PIPE_FORMAT_R9G9B9E5_FLOAT,
571                                     PIPE_TEXTURE_2D, 0,
572                                     PIPE_BIND_RENDER_TARGET))) {
573      ctx->Extensions.ARB_color_buffer_float = GL_TRUE;
574   }
575
576   if (screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT)) {
577      ctx->Extensions.ARB_shader_stencil_export = GL_TRUE;
578   }
579
580   if (screen->get_param(screen, PIPE_CAP_TGSI_INSTANCEID)) {
581      ctx->Extensions.ARB_draw_instanced = GL_TRUE;
582   }
583   if (screen->get_param(screen, PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR)) {
584      ctx->Extensions.ARB_instanced_arrays = GL_TRUE;
585   }
586
587   if (screen->fence_finish) {
588      ctx->Extensions.ARB_sync = GL_TRUE;
589   }
590
591   if (st->pipe->texture_barrier) {
592      ctx->Extensions.NV_texture_barrier = GL_TRUE;
593   }
594
595   if (screen->is_format_supported(screen, PIPE_FORMAT_R9G9B9E5_FLOAT,
596                                   PIPE_TEXTURE_2D, 0,
597                                   PIPE_BIND_SAMPLER_VIEW)) {
598      ctx->Extensions.EXT_texture_shared_exponent = GL_TRUE;
599   }
600
601   if (screen->is_format_supported(screen, PIPE_FORMAT_R11G11B10_FLOAT,
602                                   PIPE_TEXTURE_2D, 0,
603                                   PIPE_BIND_RENDER_TARGET |
604                                   PIPE_BIND_SAMPLER_VIEW)) {
605      ctx->Extensions.EXT_packed_float = GL_TRUE;
606   }
607
608   if (screen->get_param(screen, PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE)) {
609      ctx->Extensions.ARB_seamless_cube_map = GL_TRUE;
610      ctx->Extensions.AMD_seamless_cubemap_per_texture = GL_TRUE;
611   }
612   else if (screen->get_param(screen, PIPE_CAP_SEAMLESS_CUBE_MAP)) {
613      ctx->Extensions.ARB_seamless_cube_map = GL_TRUE;
614   }
615
616   if (screen->get_param(screen, PIPE_CAP_SM3)) {
617      ctx->Extensions.ARB_shader_texture_lod = GL_TRUE;
618   }
619}
620