st/mesa: use table-driven approach to exposing extensions based on CAPs
[mesa.git] / src / mesa / state_tracker / st_extensions.c
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 #include "main/version.h"
34
35 #include "pipe/p_context.h"
36 #include "pipe/p_defines.h"
37 #include "pipe/p_screen.h"
38
39 #include "st_context.h"
40 #include "st_extensions.h"
41
42
43 static int _min(int a, int b)
44 {
45 return (a < b) ? a : b;
46 }
47
48 static float _maxf(float a, float b)
49 {
50 return (a > b) ? a : b;
51 }
52
53 static int _clamp(int a, int min, int max)
54 {
55 if (a < min)
56 return min;
57 else if (a > max)
58 return max;
59 else
60 return a;
61 }
62
63
64 /**
65 * Query driver to get implementation limits.
66 * Note that we have to limit/clamp against Mesa's internal limits too.
67 */
68 void st_init_limits(struct st_context *st)
69 {
70 struct pipe_screen *screen = st->pipe->screen;
71 struct gl_constants *c = &st->ctx->Const;
72 gl_shader_type sh;
73
74 c->MaxTextureLevels
75 = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
76 MAX_TEXTURE_LEVELS);
77
78 c->Max3DTextureLevels
79 = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS),
80 MAX_3D_TEXTURE_LEVELS);
81
82 c->MaxCubeTextureLevels
83 = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS),
84 MAX_CUBE_TEXTURE_LEVELS);
85
86 c->MaxTextureRectSize
87 = _min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE);
88
89 c->MaxArrayTextureLayers
90 = screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS);
91
92 c->MaxTextureImageUnits
93 = _min(screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
94 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS),
95 MAX_TEXTURE_IMAGE_UNITS);
96
97 c->MaxVertexTextureImageUnits
98 = _min(screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
99 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS),
100 MAX_VERTEX_TEXTURE_IMAGE_UNITS);
101
102 c->MaxCombinedTextureImageUnits
103 = _min(screen->get_param(screen, PIPE_CAP_MAX_COMBINED_SAMPLERS),
104 MAX_COMBINED_TEXTURE_IMAGE_UNITS);
105
106 c->MaxTextureCoordUnits
107 = _min(c->MaxTextureImageUnits, MAX_TEXTURE_COORD_UNITS);
108
109 c->MaxTextureUnits = _min(c->MaxTextureImageUnits, c->MaxTextureCoordUnits);
110
111 c->MaxDrawBuffers
112 = _clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
113 1, MAX_DRAW_BUFFERS);
114
115 c->MaxLineWidth
116 = _maxf(1.0f, screen->get_paramf(screen,
117 PIPE_CAPF_MAX_LINE_WIDTH));
118 c->MaxLineWidthAA
119 = _maxf(1.0f, screen->get_paramf(screen,
120 PIPE_CAPF_MAX_LINE_WIDTH_AA));
121
122 c->MaxPointSize
123 = _maxf(1.0f, screen->get_paramf(screen,
124 PIPE_CAPF_MAX_POINT_WIDTH));
125 c->MaxPointSizeAA
126 = _maxf(1.0f, screen->get_paramf(screen,
127 PIPE_CAPF_MAX_POINT_WIDTH_AA));
128 /* called after _mesa_create_context/_mesa_init_point, fix default user
129 * settable max point size up
130 */
131 st->ctx->Point.MaxSize = MAX2(c->MaxPointSize, c->MaxPointSizeAA);
132 /* these are not queryable. Note that GL basically mandates a 1.0 minimum
133 * for non-aa sizes, but we can go down to 0.0 for aa points.
134 */
135 c->MinPointSize = 1.0f;
136 c->MinPointSizeAA = 0.0f;
137
138 c->MaxTextureMaxAnisotropy
139 = _maxf(2.0f, screen->get_paramf(screen,
140 PIPE_CAPF_MAX_TEXTURE_ANISOTROPY));
141
142 c->MaxTextureLodBias
143 = screen->get_paramf(screen, PIPE_CAPF_MAX_TEXTURE_LOD_BIAS);
144
145 c->MaxDrawBuffers
146 = CLAMP(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
147 1, MAX_DRAW_BUFFERS);
148
149 /* Quads always follow GL provoking rules. */
150 c->QuadsFollowProvokingVertexConvention = GL_FALSE;
151
152 for (sh = 0; sh < MESA_SHADER_TYPES; ++sh) {
153 struct gl_shader_compiler_options *options =
154 &st->ctx->ShaderCompilerOptions[sh];
155 struct gl_program_constants *pc;
156
157 switch (sh) {
158 case PIPE_SHADER_FRAGMENT:
159 pc = &c->FragmentProgram;
160 break;
161 case PIPE_SHADER_VERTEX:
162 pc = &c->VertexProgram;
163 break;
164 case PIPE_SHADER_GEOMETRY:
165 pc = &c->GeometryProgram;
166 break;
167 default:
168 assert(0);
169 continue;
170 }
171
172 pc->MaxNativeInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
173 pc->MaxNativeAluInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS);
174 pc->MaxNativeTexInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS);
175 pc->MaxNativeTexIndirections = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS);
176 pc->MaxNativeAttribs = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INPUTS);
177 pc->MaxNativeTemps = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEMPS);
178 pc->MaxNativeAddressRegs = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ADDRS);
179 pc->MaxNativeParameters = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONSTS);
180 pc->MaxUniformComponents = 4 * MIN2(pc->MaxNativeParameters, MAX_UNIFORMS);
181 /* raise MaxParameters if native support is higher */
182 pc->MaxParameters = MAX2(pc->MaxParameters, pc->MaxNativeParameters);
183
184 /* Gallium doesn't really care about local vs. env parameters so use the
185 * same limits.
186 */
187 pc->MaxLocalParams = MIN2(pc->MaxParameters, MAX_PROGRAM_LOCAL_PARAMS);
188 pc->MaxEnvParams = MIN2(pc->MaxParameters, MAX_PROGRAM_ENV_PARAMS);
189
190 options->EmitNoNoise = TRUE;
191
192 /* TODO: make these more fine-grained if anyone needs it */
193 options->MaxIfDepth = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
194 options->EmitNoLoops = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
195 options->EmitNoFunctions = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
196 options->EmitNoMainReturn = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
197
198 options->EmitNoCont = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED);
199
200 options->EmitNoIndirectInput = !screen->get_shader_param(screen, sh,
201 PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR);
202 options->EmitNoIndirectOutput = !screen->get_shader_param(screen, sh,
203 PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR);
204 options->EmitNoIndirectTemp = !screen->get_shader_param(screen, sh,
205 PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR);
206 options->EmitNoIndirectUniform = !screen->get_shader_param(screen, sh,
207 PIPE_SHADER_CAP_INDIRECT_CONST_ADDR);
208
209 if (options->EmitNoLoops)
210 options->MaxUnrollIterations = MIN2(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS), 65536);
211 }
212
213 /* PIPE_SHADER_CAP_MAX_INPUTS for the FS specifies the maximum number
214 * of inputs. It's always 2 colors + N generic inputs. */
215 c->MaxVarying = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
216 PIPE_SHADER_CAP_MAX_INPUTS);
217 c->MaxVarying = MIN2(c->MaxVarying, MAX_VARYING);
218
219 c->MinProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MIN_TEXEL_OFFSET);
220 c->MaxProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MAX_TEXEL_OFFSET);
221
222 c->UniformBooleanTrue = ~0;
223
224 c->MaxTransformFeedbackSeparateAttribs =
225 screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS);
226 c->MaxTransformFeedbackSeparateComponents =
227 screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS);
228 c->MaxTransformFeedbackInterleavedComponents =
229 screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS);
230
231 c->StripTextureBorder = GL_TRUE;
232
233 c->GLSLSkipStrictMaxUniformLimitCheck =
234 screen->get_param(screen, PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS);
235
236 c->GLSLSkipStrictMaxVaryingLimitCheck =
237 screen->get_param(screen, PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS);
238 }
239
240
241 static GLboolean st_get_s3tc_override(void)
242 {
243 const char *override = _mesa_getenv("force_s3tc_enable");
244 if (override && !strcmp(override, "true"))
245 return GL_TRUE;
246 return GL_FALSE;
247 }
248
249 /**
250 * Given a member \c x of struct gl_extensions, return offset of
251 * \c x in bytes.
252 */
253 #define o(x) offsetof(struct gl_extensions, x)
254
255
256 struct st_extension_cap_mapping {
257 int extension_offset;
258 int cap;
259 };
260
261
262 /**
263 * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
264 * which GL extensions are supported.
265 * Quite a few extensions are always supported because they are standard
266 * features or can be built on top of other gallium features.
267 * Some fine tuning may still be needed.
268 */
269 void st_init_extensions(struct st_context *st)
270 {
271 struct pipe_screen *screen = st->pipe->screen;
272 struct gl_context *ctx = st->ctx;
273 int i, glsl_feature_level;
274 GLboolean *extensions = (GLboolean *) &ctx->Extensions;
275
276 static const struct st_extension_cap_mapping cap_mapping[] = {
277 { o(ARB_depth_clamp), PIPE_CAP_DEPTH_CLIP_DISABLE },
278 { o(ARB_depth_texture), PIPE_CAP_TEXTURE_SHADOW_MAP },
279 { o(ARB_draw_buffers_blend), PIPE_CAP_INDEP_BLEND_FUNC },
280 { o(ARB_draw_instanced), PIPE_CAP_TGSI_INSTANCEID },
281 { o(ARB_fragment_program_shadow), PIPE_CAP_TEXTURE_SHADOW_MAP },
282 { o(ARB_instanced_arrays), PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR },
283 { o(ARB_occlusion_query), PIPE_CAP_OCCLUSION_QUERY },
284 { o(ARB_occlusion_query2), PIPE_CAP_OCCLUSION_QUERY },
285 { o(ARB_point_sprite), PIPE_CAP_POINT_SPRITE },
286 { o(ARB_seamless_cube_map), PIPE_CAP_SEAMLESS_CUBE_MAP },
287 { o(ARB_shader_stencil_export), PIPE_CAP_SHADER_STENCIL_EXPORT },
288 { o(ARB_shader_texture_lod), PIPE_CAP_SM3 },
289 { o(ARB_shadow), PIPE_CAP_TEXTURE_SHADOW_MAP },
290 { o(ARB_texture_non_power_of_two), PIPE_CAP_NPOT_TEXTURES },
291 { o(ARB_transform_feedback2), PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME },
292
293 { o(EXT_blend_equation_separate), PIPE_CAP_BLEND_EQUATION_SEPARATE },
294 { o(EXT_draw_buffers2), PIPE_CAP_INDEP_BLEND_ENABLE },
295 { o(EXT_shadow_funcs), PIPE_CAP_TEXTURE_SHADOW_MAP },
296 { o(EXT_stencil_two_side), PIPE_CAP_TWO_SIDED_STENCIL },
297 { o(EXT_texture_array), PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS },
298 { o(EXT_texture_filter_anisotropic), PIPE_CAP_ANISOTROPIC_FILTER },
299 { o(EXT_texture_mirror_clamp), PIPE_CAP_TEXTURE_MIRROR_CLAMP },
300 { o(EXT_texture_swizzle), PIPE_CAP_TEXTURE_SWIZZLE },
301 { o(EXT_timer_query), PIPE_CAP_TIMER_QUERY },
302 { o(EXT_transform_feedback), PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS },
303
304 { o(AMD_seamless_cubemap_per_texture), PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE },
305 { o(ATI_separate_stencil), PIPE_CAP_TWO_SIDED_STENCIL },
306 { o(ATI_texture_mirror_once), PIPE_CAP_TEXTURE_MIRROR_CLAMP },
307 { o(NV_conditional_render), PIPE_CAP_CONDITIONAL_RENDER },
308 { o(NV_texture_barrier), PIPE_CAP_TEXTURE_BARRIER },
309 /* GL_NV_point_sprite is not supported by gallium because we don't
310 * support the GL_POINT_SPRITE_R_MODE_NV option. */
311 { o(MESA_texture_array), PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS },
312 };
313
314 /*
315 * Extensions that are supported by all Gallium drivers:
316 */
317 ctx->Extensions.ARB_copy_buffer = GL_TRUE;
318 ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
319 ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE;
320 ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
321 ctx->Extensions.ARB_fragment_program = GL_TRUE;
322 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
323 ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
324 ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
325 ctx->Extensions.ARB_sampler_objects = GL_TRUE;
326 ctx->Extensions.ARB_shader_objects = GL_TRUE;
327 ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
328 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE; /* XXX temp */
329 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
330 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
331 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
332 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
333 ctx->Extensions.ARB_texture_storage = GL_TRUE;
334 ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
335 ctx->Extensions.ARB_vertex_program = GL_TRUE;
336 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
337 ctx->Extensions.ARB_window_pos = GL_TRUE;
338
339 ctx->Extensions.EXT_blend_color = GL_TRUE;
340 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
341 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
342 ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
343 ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
344 ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
345 ctx->Extensions.EXT_fog_coord = GL_TRUE;
346 ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
347 ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
348 ctx->Extensions.EXT_point_parameters = GL_TRUE;
349 ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
350 ctx->Extensions.EXT_secondary_color = GL_TRUE;
351 ctx->Extensions.EXT_separate_shader_objects = GL_TRUE;
352 ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
353 ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
354
355 ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
356
357 ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
358
359 ctx->Extensions.MESA_pack_invert = GL_TRUE;
360
361 ctx->Extensions.NV_blend_square = GL_TRUE;
362 ctx->Extensions.NV_fog_distance = GL_TRUE;
363 ctx->Extensions.NV_texgen_reflection = GL_TRUE;
364 ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
365 ctx->Extensions.NV_texture_rectangle = GL_TRUE;
366 #if 0
367 /* possibly could support the following two */
368 ctx->Extensions.NV_vertex_program = GL_TRUE;
369 ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
370 #endif
371
372 #if FEATURE_OES_EGL_image
373 ctx->Extensions.OES_EGL_image = GL_TRUE;
374 if (ctx->API != API_OPENGL)
375 ctx->Extensions.OES_EGL_image_external = GL_TRUE;
376 #endif
377 #if FEATURE_OES_draw_texture
378 ctx->Extensions.OES_draw_texture = GL_TRUE;
379 #endif
380
381 /* Expose the extensions which directly correspond to gallium caps. */
382 for (i = 0; i < Elements(cap_mapping); i++) {
383 if (screen->get_param(screen, cap_mapping[i].cap)) {
384 extensions[cap_mapping[i].extension_offset] = GL_TRUE;
385 }
386 }
387
388 /* Figure out GLSL support. */
389 glsl_feature_level = screen->get_param(screen, PIPE_CAP_GLSL_FEATURE_LEVEL);
390
391 if (glsl_feature_level >= 130) {
392 ctx->Const.GLSLVersion = 130;
393 } else {
394 ctx->Const.GLSLVersion = 120;
395 }
396
397 _mesa_override_glsl_version(st->ctx);
398
399 if (ctx->Const.GLSLVersion >= 130) {
400 ctx->Const.NativeIntegers = GL_TRUE;
401 ctx->Const.MaxClipPlanes = 8;
402
403 /* Extensions that only depend on GLSL 1.3. */
404 ctx->Extensions.ARB_conservative_depth = GL_TRUE;
405 } else {
406 /* Optional integer support for GLSL 1.2. */
407 if (screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
408 PIPE_SHADER_CAP_INTEGERS) &&
409 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
410 PIPE_SHADER_CAP_INTEGERS)) {
411 ctx->Const.NativeIntegers = GL_TRUE;
412 }
413 }
414
415 /*
416 * Extensions that depend on the driver/hardware:
417 */
418 /* GL_EXT_packed_depth_stencil requires both the ability to render to
419 * a depth/stencil buffer and texture from depth/stencil source.
420 */
421 if (screen->is_format_supported(screen, PIPE_FORMAT_S8_UINT_Z24_UNORM,
422 PIPE_TEXTURE_2D, 0,
423 PIPE_BIND_DEPTH_STENCIL |
424 PIPE_BIND_SAMPLER_VIEW) ||
425 screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_UINT,
426 PIPE_TEXTURE_2D, 0,
427 PIPE_BIND_DEPTH_STENCIL |
428 PIPE_BIND_SAMPLER_VIEW)) {
429 ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
430 ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
431 }
432
433 /* float support - assume nothing exclusively supports 64-bit floats */
434 if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_FLOAT,
435 PIPE_TEXTURE_2D, 0,
436 PIPE_BIND_SAMPLER_VIEW |
437 PIPE_BIND_RENDER_TARGET) &&
438 screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
439 PIPE_TEXTURE_2D, 0,
440 PIPE_BIND_SAMPLER_VIEW |
441 PIPE_BIND_RENDER_TARGET)) {
442 ctx->Extensions.ARB_texture_float = GL_TRUE;
443 }
444
445 /* sRGB support */
446 if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
447 PIPE_TEXTURE_2D, 0,
448 PIPE_BIND_SAMPLER_VIEW) ||
449 screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
450 PIPE_TEXTURE_2D, 0,
451 PIPE_BIND_SAMPLER_VIEW)) {
452 ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
453 ctx->Extensions.EXT_texture_sRGB_decode = GL_TRUE;
454 if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
455 PIPE_TEXTURE_2D, 0,
456 PIPE_BIND_RENDER_TARGET) ||
457 screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
458 PIPE_TEXTURE_2D, 0,
459 PIPE_BIND_RENDER_TARGET)) {
460 ctx->Extensions.EXT_framebuffer_sRGB = GL_TRUE;
461 }
462 }
463
464 if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM,
465 PIPE_TEXTURE_2D, 0,
466 PIPE_BIND_SAMPLER_VIEW)) {
467 ctx->Extensions.ARB_texture_rg = GL_TRUE;
468 }
469
470 /* s3tc support */
471 if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_RGB,
472 PIPE_TEXTURE_2D, 0,
473 PIPE_BIND_SAMPLER_VIEW) &&
474 screen->is_format_supported(screen, PIPE_FORMAT_DXT1_RGBA,
475 PIPE_TEXTURE_2D, 0,
476 PIPE_BIND_SAMPLER_VIEW) &&
477 screen->is_format_supported(screen, PIPE_FORMAT_DXT3_RGBA,
478 PIPE_TEXTURE_2D, 0,
479 PIPE_BIND_SAMPLER_VIEW) &&
480 screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
481 PIPE_TEXTURE_2D, 0,
482 PIPE_BIND_SAMPLER_VIEW) &&
483 (ctx->Mesa_DXTn || st_get_s3tc_override())) {
484 ctx->Extensions.EXT_texture_compression_s3tc = GL_TRUE;
485 ctx->Extensions.S3_s3tc = GL_TRUE;
486 }
487
488 if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_UNORM,
489 PIPE_TEXTURE_2D, 0,
490 PIPE_BIND_SAMPLER_VIEW) &&
491 screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_SNORM,
492 PIPE_TEXTURE_2D, 0,
493 PIPE_BIND_SAMPLER_VIEW) &&
494 screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_UNORM,
495 PIPE_TEXTURE_2D, 0,
496 PIPE_BIND_SAMPLER_VIEW) &&
497 screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_SNORM,
498 PIPE_TEXTURE_2D, 0,
499 PIPE_BIND_SAMPLER_VIEW)
500 ) {
501 ctx->Extensions.ARB_texture_compression_rgtc = GL_TRUE;
502 }
503
504 if (screen->is_format_supported(screen, PIPE_FORMAT_LATC1_UNORM,
505 PIPE_TEXTURE_2D, 0,
506 PIPE_BIND_SAMPLER_VIEW) &&
507 screen->is_format_supported(screen, PIPE_FORMAT_LATC1_SNORM,
508 PIPE_TEXTURE_2D, 0,
509 PIPE_BIND_SAMPLER_VIEW) &&
510 screen->is_format_supported(screen, PIPE_FORMAT_LATC2_UNORM,
511 PIPE_TEXTURE_2D, 0,
512 PIPE_BIND_SAMPLER_VIEW) &&
513 screen->is_format_supported(screen, PIPE_FORMAT_LATC2_SNORM,
514 PIPE_TEXTURE_2D, 0,
515 PIPE_BIND_SAMPLER_VIEW)) {
516 ctx->Extensions.EXT_texture_compression_latc = GL_TRUE;
517 }
518
519 if (screen->is_format_supported(screen, PIPE_FORMAT_LATC2_UNORM,
520 PIPE_TEXTURE_2D, 0,
521 PIPE_BIND_SAMPLER_VIEW)) {
522 ctx->Extensions.ATI_texture_compression_3dc = GL_TRUE;
523 }
524
525 if (ctx->API != API_OPENGL) {
526 if (screen->is_format_supported(screen, PIPE_FORMAT_ETC1_RGB8,
527 PIPE_TEXTURE_2D, 0,
528 PIPE_BIND_SAMPLER_VIEW)) {
529 ctx->Extensions.OES_compressed_ETC1_RGB8_texture = GL_TRUE;
530 }
531 }
532
533 if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SNORM,
534 PIPE_TEXTURE_2D, 0,
535 PIPE_BIND_SAMPLER_VIEW)) {
536 ctx->Extensions.EXT_texture_snorm = GL_TRUE;
537 }
538
539 /* ycbcr support */
540 if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY,
541 PIPE_TEXTURE_2D, 0,
542 PIPE_BIND_SAMPLER_VIEW) ||
543 screen->is_format_supported(screen, PIPE_FORMAT_YUYV,
544 PIPE_TEXTURE_2D, 0,
545 PIPE_BIND_SAMPLER_VIEW)) {
546 ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
547 }
548
549 /* GL_ARB_half_float_vertex */
550 if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
551 PIPE_BUFFER, 0,
552 PIPE_BIND_VERTEX_BUFFER)) {
553 ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
554 }
555
556 if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_FIXED,
557 PIPE_BUFFER, 0,
558 PIPE_BIND_VERTEX_BUFFER)) {
559 ctx->Extensions.ARB_ES2_compatibility = GL_TRUE;
560 }
561
562 if (screen->is_format_supported(screen, PIPE_FORMAT_R10G10B10A2_UNORM,
563 PIPE_BUFFER, 0,
564 PIPE_BIND_VERTEX_BUFFER) &&
565 screen->is_format_supported(screen, PIPE_FORMAT_B10G10R10A2_UNORM,
566 PIPE_BUFFER, 0,
567 PIPE_BIND_VERTEX_BUFFER) &&
568 screen->is_format_supported(screen, PIPE_FORMAT_R10G10B10A2_SNORM,
569 PIPE_BUFFER, 0,
570 PIPE_BIND_VERTEX_BUFFER) &&
571 screen->is_format_supported(screen, PIPE_FORMAT_B10G10R10A2_SNORM,
572 PIPE_BUFFER, 0,
573 PIPE_BIND_VERTEX_BUFFER) &&
574 screen->is_format_supported(screen, PIPE_FORMAT_R10G10B10A2_USCALED,
575 PIPE_BUFFER, 0,
576 PIPE_BIND_VERTEX_BUFFER) &&
577 screen->is_format_supported(screen, PIPE_FORMAT_B10G10R10A2_USCALED,
578 PIPE_BUFFER, 0,
579 PIPE_BIND_VERTEX_BUFFER) &&
580 screen->is_format_supported(screen, PIPE_FORMAT_R10G10B10A2_SSCALED,
581 PIPE_BUFFER, 0,
582 PIPE_BIND_VERTEX_BUFFER) &&
583 screen->is_format_supported(screen, PIPE_FORMAT_B10G10R10A2_SSCALED,
584 PIPE_BUFFER, 0,
585 PIPE_BIND_VERTEX_BUFFER)) {
586 ctx->Extensions.ARB_vertex_type_2_10_10_10_rev = GL_TRUE;
587 }
588
589 if (screen->get_shader_param(screen, PIPE_SHADER_GEOMETRY,
590 PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
591 #if 0 /* XXX re-enable when GLSL compiler again supports geometry shaders */
592 ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
593 #endif
594 }
595
596 ctx->Extensions.NV_primitive_restart = GL_TRUE;
597 if (!screen->get_param(screen, PIPE_CAP_PRIMITIVE_RESTART)) {
598 st->sw_primitive_restart = GL_TRUE;
599 }
600
601 if (screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_UNCLAMPED)) {
602 ctx->Extensions.ARB_color_buffer_float = GL_TRUE;
603
604 if (!screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_CLAMPED)) {
605 st->clamp_vert_color_in_shader = TRUE;
606 }
607
608 if (!screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMPED)) {
609 st->clamp_frag_color_in_shader = TRUE;
610 }
611 }
612
613 if (screen->fence_finish) {
614 ctx->Extensions.ARB_sync = GL_TRUE;
615 }
616
617 if (screen->is_format_supported(screen, PIPE_FORMAT_R9G9B9E5_FLOAT,
618 PIPE_TEXTURE_2D, 0,
619 PIPE_BIND_SAMPLER_VIEW)) {
620 ctx->Extensions.EXT_texture_shared_exponent = GL_TRUE;
621 }
622
623 if (screen->is_format_supported(screen, PIPE_FORMAT_R11G11B10_FLOAT,
624 PIPE_TEXTURE_2D, 0,
625 PIPE_BIND_RENDER_TARGET |
626 PIPE_BIND_SAMPLER_VIEW)) {
627 ctx->Extensions.EXT_packed_float = GL_TRUE;
628 }
629
630 /* Maximum sample count. */
631 for (i = 16; i > 0; --i) {
632 if (screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_UNORM,
633 PIPE_TEXTURE_2D, i,
634 PIPE_BIND_RENDER_TARGET)) {
635 ctx->Const.MaxSamples = i;
636 break;
637 }
638 }
639
640 if (screen->is_format_supported(screen, PIPE_FORMAT_Z32_FLOAT,
641 PIPE_TEXTURE_2D, 0,
642 PIPE_BIND_DEPTH_STENCIL |
643 PIPE_BIND_SAMPLER_VIEW) &&
644 screen->is_format_supported(screen, PIPE_FORMAT_Z32_FLOAT_S8X24_UINT,
645 PIPE_TEXTURE_2D, 0,
646 PIPE_BIND_DEPTH_STENCIL |
647 PIPE_BIND_SAMPLER_VIEW)) {
648 ctx->Extensions.ARB_depth_buffer_float = GL_TRUE;
649 }
650
651 if (screen->is_format_supported(screen, PIPE_FORMAT_B10G10R10A2_UINT,
652 PIPE_TEXTURE_2D, 0,
653 PIPE_BIND_SAMPLER_VIEW))
654 ctx->Extensions.ARB_texture_rgb10_a2ui = GL_TRUE;
655
656 if (ctx->Const.NativeIntegers &&
657 screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_UINT, PIPE_TEXTURE_2D, 0,
658 PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET) &&
659 screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_SINT, PIPE_TEXTURE_2D, 0,
660 PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET))
661 ctx->Extensions.EXT_texture_integer = GL_TRUE;
662 }