mesa: Eliminate parameters to dd_function_table::Viewport
[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/version.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 #include "st_format.h"
41
42 static unsigned _min(unsigned a, unsigned b)
43 {
44 return (a < b) ? a : b;
45 }
46
47 static float _maxf(float a, float b)
48 {
49 return (a > b) ? a : b;
50 }
51
52 static 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 */
67 void 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 unsigned sh;
72 boolean can_ubo = TRUE;
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->MaxCombinedTextureImageUnits
93 = _min(screen->get_param(screen, PIPE_CAP_MAX_COMBINED_SAMPLERS),
94 MAX_COMBINED_TEXTURE_IMAGE_UNITS);
95
96 /* Define max viewport size and max renderbuffer size in terms of
97 * max texture size (note: max tex RECT size = max tex 2D size).
98 * If this isn't true for some hardware we'll need new PIPE_CAP_ queries.
99 */
100 c->MaxViewportWidth =
101 c->MaxViewportHeight =
102 c->MaxRenderbufferSize = c->MaxTextureRectSize;
103
104 c->MaxDrawBuffers = c->MaxColorAttachments =
105 _clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
106 1, MAX_DRAW_BUFFERS);
107
108 c->MaxDualSourceDrawBuffers
109 = _clamp(screen->get_param(screen, PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS),
110 0, MAX_DRAW_BUFFERS);
111
112 c->MaxLineWidth
113 = _maxf(1.0f, screen->get_paramf(screen,
114 PIPE_CAPF_MAX_LINE_WIDTH));
115 c->MaxLineWidthAA
116 = _maxf(1.0f, screen->get_paramf(screen,
117 PIPE_CAPF_MAX_LINE_WIDTH_AA));
118
119 c->MaxPointSize
120 = _maxf(1.0f, screen->get_paramf(screen,
121 PIPE_CAPF_MAX_POINT_WIDTH));
122 c->MaxPointSizeAA
123 = _maxf(1.0f, screen->get_paramf(screen,
124 PIPE_CAPF_MAX_POINT_WIDTH_AA));
125 /* called after _mesa_create_context/_mesa_init_point, fix default user
126 * settable max point size up
127 */
128 st->ctx->Point.MaxSize = MAX2(c->MaxPointSize, c->MaxPointSizeAA);
129 /* these are not queryable. Note that GL basically mandates a 1.0 minimum
130 * for non-aa sizes, but we can go down to 0.0 for aa points.
131 */
132 c->MinPointSize = 1.0f;
133 c->MinPointSizeAA = 0.0f;
134
135 c->MaxTextureMaxAnisotropy
136 = _maxf(2.0f, screen->get_paramf(screen,
137 PIPE_CAPF_MAX_TEXTURE_ANISOTROPY));
138
139 c->MaxTextureLodBias
140 = screen->get_paramf(screen, PIPE_CAPF_MAX_TEXTURE_LOD_BIAS);
141
142 c->QuadsFollowProvokingVertexConvention = screen->get_param(
143 screen, PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION);
144
145 c->MaxUniformBlockSize =
146 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
147 PIPE_SHADER_CAP_MAX_CONSTS) * 16;
148 if (c->MaxUniformBlockSize < 16384) {
149 can_ubo = FALSE;
150 }
151
152 for (sh = 0; sh < PIPE_SHADER_TYPES; ++sh) {
153 struct gl_shader_compiler_options *options;
154 struct gl_program_constants *pc;
155
156 switch (sh) {
157 case PIPE_SHADER_FRAGMENT:
158 pc = &c->Program[MESA_SHADER_FRAGMENT];
159 options = &st->ctx->ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
160 break;
161 case PIPE_SHADER_VERTEX:
162 pc = &c->Program[MESA_SHADER_VERTEX];
163 options = &st->ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX];
164 break;
165 case PIPE_SHADER_GEOMETRY:
166 pc = &c->Program[MESA_SHADER_GEOMETRY];
167 options = &st->ctx->ShaderCompilerOptions[MESA_SHADER_GEOMETRY];
168 break;
169 default:
170 /* compute shader, etc. */
171 continue;
172 }
173
174 pc->MaxTextureImageUnits =
175 _min(screen->get_shader_param(screen, sh,
176 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS),
177 MAX_TEXTURE_IMAGE_UNITS);
178
179 pc->MaxInstructions = pc->MaxNativeInstructions =
180 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
181 pc->MaxAluInstructions = pc->MaxNativeAluInstructions =
182 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS);
183 pc->MaxTexInstructions = pc->MaxNativeTexInstructions =
184 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS);
185 pc->MaxTexIndirections = pc->MaxNativeTexIndirections =
186 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS);
187 pc->MaxAttribs = pc->MaxNativeAttribs =
188 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INPUTS);
189 pc->MaxTemps = pc->MaxNativeTemps =
190 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEMPS);
191 pc->MaxAddressRegs = pc->MaxNativeAddressRegs =
192 _min(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ADDRS),
193 MAX_PROGRAM_ADDRESS_REGS);
194 pc->MaxParameters = pc->MaxNativeParameters =
195 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONSTS);
196
197 pc->MaxUniformComponents = 4 * MIN2(pc->MaxNativeParameters, MAX_UNIFORMS);
198
199 pc->MaxUniformBlocks =
200 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONST_BUFFERS);
201 if (pc->MaxUniformBlocks)
202 pc->MaxUniformBlocks -= 1; /* The first one is for ordinary uniforms. */
203 pc->MaxUniformBlocks = _min(pc->MaxUniformBlocks, MAX_UNIFORM_BUFFERS);
204
205 pc->MaxCombinedUniformComponents = (pc->MaxUniformComponents +
206 c->MaxUniformBlockSize / 4 *
207 pc->MaxUniformBlocks);
208
209 /* Gallium doesn't really care about local vs. env parameters so use the
210 * same limits.
211 */
212 pc->MaxLocalParams = MIN2(pc->MaxParameters, MAX_PROGRAM_LOCAL_PARAMS);
213 pc->MaxEnvParams = MIN2(pc->MaxParameters, MAX_PROGRAM_ENV_PARAMS);
214
215 options->EmitNoNoise = TRUE;
216
217 /* TODO: make these more fine-grained if anyone needs it */
218 options->MaxIfDepth = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
219 options->EmitNoLoops = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
220 options->EmitNoFunctions = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
221 options->EmitNoMainReturn = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
222
223 options->EmitNoCont = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED);
224
225 options->EmitNoIndirectInput = !screen->get_shader_param(screen, sh,
226 PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR);
227 options->EmitNoIndirectOutput = !screen->get_shader_param(screen, sh,
228 PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR);
229 options->EmitNoIndirectTemp = !screen->get_shader_param(screen, sh,
230 PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR);
231 options->EmitNoIndirectUniform = !screen->get_shader_param(screen, sh,
232 PIPE_SHADER_CAP_INDIRECT_CONST_ADDR);
233
234 if (pc->MaxNativeInstructions &&
235 (options->EmitNoIndirectUniform || pc->MaxUniformBlocks < 12)) {
236 can_ubo = FALSE;
237 }
238
239 if (options->EmitNoLoops)
240 options->MaxUnrollIterations = MIN2(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS), 65536);
241 else
242 options->MaxUnrollIterations = 255; /* SM3 limit */
243 options->LowerClipDistance = true;
244 }
245
246 /* This depends on program constants. */
247 c->MaxTextureCoordUnits
248 = _min(c->Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits, MAX_TEXTURE_COORD_UNITS);
249
250 c->MaxTextureUnits = _min(c->Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits, c->MaxTextureCoordUnits);
251
252 c->Program[MESA_SHADER_VERTEX].MaxAttribs = MIN2(c->Program[MESA_SHADER_VERTEX].MaxAttribs, 16);
253
254 /* PIPE_SHADER_CAP_MAX_INPUTS for the FS specifies the maximum number
255 * of inputs. It's always 2 colors + N generic inputs. */
256 c->MaxVarying = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
257 PIPE_SHADER_CAP_MAX_INPUTS);
258 c->MaxVarying = MIN2(c->MaxVarying, MAX_VARYING);
259 c->Program[MESA_SHADER_FRAGMENT].MaxInputComponents = c->MaxVarying * 4;
260 c->Program[MESA_SHADER_VERTEX].MaxOutputComponents = c->MaxVarying * 4;
261 c->Program[MESA_SHADER_GEOMETRY].MaxInputComponents = c->MaxVarying * 4;
262 c->Program[MESA_SHADER_GEOMETRY].MaxOutputComponents = c->MaxVarying * 4;
263
264 c->MinProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MIN_TEXEL_OFFSET);
265 c->MaxProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MAX_TEXEL_OFFSET);
266
267 c->UniformBooleanTrue = ~0;
268
269 c->MaxTransformFeedbackBuffers =
270 screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS);
271 c->MaxTransformFeedbackBuffers = MIN2(c->MaxTransformFeedbackBuffers, MAX_FEEDBACK_BUFFERS);
272 c->MaxTransformFeedbackSeparateComponents =
273 screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS);
274 c->MaxTransformFeedbackInterleavedComponents =
275 screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS);
276
277 c->StripTextureBorder = GL_TRUE;
278
279 c->GLSLSkipStrictMaxUniformLimitCheck =
280 screen->get_param(screen, PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS);
281
282 if (can_ubo) {
283 st->ctx->Extensions.ARB_uniform_buffer_object = GL_TRUE;
284 c->UniformBufferOffsetAlignment =
285 screen->get_param(screen, PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT);
286 c->MaxCombinedUniformBlocks = c->MaxUniformBufferBindings =
287 c->Program[MESA_SHADER_VERTEX].MaxUniformBlocks +
288 c->Program[MESA_SHADER_GEOMETRY].MaxUniformBlocks +
289 c->Program[MESA_SHADER_FRAGMENT].MaxUniformBlocks;
290 assert(c->MaxCombinedUniformBlocks <= MAX_COMBINED_UNIFORM_BUFFERS);
291 }
292 }
293
294
295 /**
296 * Given a member \c x of struct gl_extensions, return offset of
297 * \c x in bytes.
298 */
299 #define o(x) offsetof(struct gl_extensions, x)
300
301
302 struct st_extension_cap_mapping {
303 int extension_offset;
304 int cap;
305 };
306
307 struct st_extension_format_mapping {
308 int extension_offset[2];
309 enum pipe_format format[8];
310
311 /* If TRUE, at least one format must be supported for the extensions to be
312 * advertised. If FALSE, all the formats must be supported. */
313 GLboolean need_at_least_one;
314 };
315
316 /**
317 * Enable extensions if certain pipe formats are supported by the driver.
318 * What extensions will be enabled and what formats must be supported is
319 * described by the array of st_extension_format_mapping.
320 *
321 * target and bind_flags are passed to is_format_supported.
322 */
323 static void init_format_extensions(struct st_context *st,
324 const struct st_extension_format_mapping *mapping,
325 unsigned num_mappings,
326 enum pipe_texture_target target,
327 unsigned bind_flags)
328 {
329 struct pipe_screen *screen = st->pipe->screen;
330 GLboolean *extensions = (GLboolean *) &st->ctx->Extensions;
331 unsigned i;
332 int j;
333 int num_formats = Elements(mapping->format);
334 int num_ext = Elements(mapping->extension_offset);
335
336 for (i = 0; i < num_mappings; i++) {
337 int num_supported = 0;
338
339 /* Examine each format in the list. */
340 for (j = 0; j < num_formats && mapping[i].format[j]; j++) {
341 if (screen->is_format_supported(screen, mapping[i].format[j],
342 target, 0, bind_flags)) {
343 num_supported++;
344 }
345 }
346
347 if (!num_supported ||
348 (!mapping[i].need_at_least_one && num_supported != j)) {
349 continue;
350 }
351
352 /* Enable all extensions in the list. */
353 for (j = 0; j < num_ext && mapping[i].extension_offset[j]; j++)
354 extensions[mapping[i].extension_offset[j]] = GL_TRUE;
355 }
356 }
357
358 /**
359 * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
360 * which GL extensions are supported.
361 * Quite a few extensions are always supported because they are standard
362 * features or can be built on top of other gallium features.
363 * Some fine tuning may still be needed.
364 */
365 void st_init_extensions(struct st_context *st)
366 {
367 struct pipe_screen *screen = st->pipe->screen;
368 struct gl_context *ctx = st->ctx;
369 int i, glsl_feature_level;
370 GLboolean *extensions = (GLboolean *) &ctx->Extensions;
371
372 static const struct st_extension_cap_mapping cap_mapping[] = {
373 { o(ARB_base_instance), PIPE_CAP_START_INSTANCE },
374 { o(ARB_depth_clamp), PIPE_CAP_DEPTH_CLIP_DISABLE },
375 { o(ARB_depth_texture), PIPE_CAP_TEXTURE_SHADOW_MAP },
376 { o(ARB_draw_buffers_blend), PIPE_CAP_INDEP_BLEND_FUNC },
377 { o(ARB_draw_instanced), PIPE_CAP_TGSI_INSTANCEID },
378 { o(ARB_fragment_program_shadow), PIPE_CAP_TEXTURE_SHADOW_MAP },
379 { o(ARB_instanced_arrays), PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR },
380 { o(ARB_occlusion_query), PIPE_CAP_OCCLUSION_QUERY },
381 { o(ARB_occlusion_query2), PIPE_CAP_OCCLUSION_QUERY },
382 { o(ARB_point_sprite), PIPE_CAP_POINT_SPRITE },
383 { o(ARB_seamless_cube_map), PIPE_CAP_SEAMLESS_CUBE_MAP },
384 { o(ARB_shader_stencil_export), PIPE_CAP_SHADER_STENCIL_EXPORT },
385 { o(ARB_shader_texture_lod), PIPE_CAP_SM3 },
386 { o(ARB_shadow), PIPE_CAP_TEXTURE_SHADOW_MAP },
387 { o(ARB_texture_mirror_clamp_to_edge), PIPE_CAP_TEXTURE_MIRROR_CLAMP },
388 { o(ARB_texture_non_power_of_two), PIPE_CAP_NPOT_TEXTURES },
389 { o(ARB_timer_query), PIPE_CAP_QUERY_TIMESTAMP },
390 { o(ARB_transform_feedback2), PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME },
391 { o(ARB_transform_feedback3), PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME },
392
393 { o(EXT_blend_equation_separate), PIPE_CAP_BLEND_EQUATION_SEPARATE },
394 { o(EXT_draw_buffers2), PIPE_CAP_INDEP_BLEND_ENABLE },
395 { o(EXT_stencil_two_side), PIPE_CAP_TWO_SIDED_STENCIL },
396 { o(EXT_texture_array), PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS },
397 { o(EXT_texture_filter_anisotropic), PIPE_CAP_ANISOTROPIC_FILTER },
398 { o(EXT_texture_mirror_clamp), PIPE_CAP_TEXTURE_MIRROR_CLAMP },
399 { o(EXT_texture_swizzle), PIPE_CAP_TEXTURE_SWIZZLE },
400 { o(EXT_transform_feedback), PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS },
401
402 { o(AMD_seamless_cubemap_per_texture), PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE },
403 { o(ATI_separate_stencil), PIPE_CAP_TWO_SIDED_STENCIL },
404 { o(ATI_texture_mirror_once), PIPE_CAP_TEXTURE_MIRROR_CLAMP },
405 { o(NV_conditional_render), PIPE_CAP_CONDITIONAL_RENDER },
406 { o(NV_texture_barrier), PIPE_CAP_TEXTURE_BARRIER },
407 /* GL_NV_point_sprite is not supported by gallium because we don't
408 * support the GL_POINT_SPRITE_R_MODE_NV option. */
409
410 { o(OES_standard_derivatives), PIPE_CAP_SM3 },
411 { o(ARB_texture_cube_map_array), PIPE_CAP_CUBE_MAP_ARRAY },
412 { o(ARB_texture_multisample), PIPE_CAP_TEXTURE_MULTISAMPLE }
413 };
414
415 /* Required: render target and sampler support */
416 static const struct st_extension_format_mapping rendertarget_mapping[] = {
417 { { o(ARB_texture_float) },
418 { PIPE_FORMAT_R32G32B32A32_FLOAT,
419 PIPE_FORMAT_R16G16B16A16_FLOAT } },
420
421 { { o(ARB_texture_rgb10_a2ui) },
422 { PIPE_FORMAT_B10G10R10A2_UINT } },
423
424 { { o(EXT_framebuffer_sRGB) },
425 { PIPE_FORMAT_A8B8G8R8_SRGB,
426 PIPE_FORMAT_B8G8R8A8_SRGB },
427 GL_TRUE }, /* at least one format must be supported */
428
429 { { o(EXT_packed_float) },
430 { PIPE_FORMAT_R11G11B10_FLOAT } },
431
432 { { o(EXT_texture_integer) },
433 { PIPE_FORMAT_R32G32B32A32_UINT,
434 PIPE_FORMAT_R32G32B32A32_SINT } },
435
436 { { o(ARB_texture_rg) },
437 { PIPE_FORMAT_R8_UNORM,
438 PIPE_FORMAT_R8G8_UNORM } },
439 };
440
441 /* Required: depth stencil and sampler support */
442 static const struct st_extension_format_mapping depthstencil_mapping[] = {
443 { { o(ARB_depth_buffer_float) },
444 { PIPE_FORMAT_Z32_FLOAT,
445 PIPE_FORMAT_Z32_FLOAT_S8X24_UINT } },
446 };
447
448 /* Required: sampler support */
449 static const struct st_extension_format_mapping texture_mapping[] = {
450 { { o(ARB_texture_compression_rgtc) },
451 { PIPE_FORMAT_RGTC1_UNORM,
452 PIPE_FORMAT_RGTC1_SNORM,
453 PIPE_FORMAT_RGTC2_UNORM,
454 PIPE_FORMAT_RGTC2_SNORM } },
455
456 { { o(EXT_texture_compression_latc) },
457 { PIPE_FORMAT_LATC1_UNORM,
458 PIPE_FORMAT_LATC1_SNORM,
459 PIPE_FORMAT_LATC2_UNORM,
460 PIPE_FORMAT_LATC2_SNORM } },
461
462 { { o(EXT_texture_compression_s3tc),
463 o(ANGLE_texture_compression_dxt) },
464 { PIPE_FORMAT_DXT1_RGB,
465 PIPE_FORMAT_DXT1_RGBA,
466 PIPE_FORMAT_DXT3_RGBA,
467 PIPE_FORMAT_DXT5_RGBA } },
468
469 { { o(EXT_texture_shared_exponent) },
470 { PIPE_FORMAT_R9G9B9E5_FLOAT } },
471
472 { { o(EXT_texture_snorm) },
473 { PIPE_FORMAT_R8G8B8A8_SNORM } },
474
475 { { o(EXT_texture_sRGB),
476 o(EXT_texture_sRGB_decode) },
477 { PIPE_FORMAT_A8B8G8R8_SRGB,
478 PIPE_FORMAT_B8G8R8A8_SRGB },
479 GL_TRUE }, /* at least one format must be supported */
480
481 { { o(ATI_texture_compression_3dc) },
482 { PIPE_FORMAT_LATC2_UNORM } },
483
484 { { o(MESA_ycbcr_texture) },
485 { PIPE_FORMAT_UYVY,
486 PIPE_FORMAT_YUYV },
487 GL_TRUE }, /* at least one format must be supported */
488
489 { { o(OES_compressed_ETC1_RGB8_texture) },
490 { PIPE_FORMAT_ETC1_RGB8 } },
491 };
492
493 /* Required: vertex fetch support. */
494 static const struct st_extension_format_mapping vertex_mapping[] = {
495 { { o(ARB_vertex_type_2_10_10_10_rev) },
496 { PIPE_FORMAT_R10G10B10A2_UNORM,
497 PIPE_FORMAT_B10G10R10A2_UNORM,
498 PIPE_FORMAT_R10G10B10A2_SNORM,
499 PIPE_FORMAT_B10G10R10A2_SNORM,
500 PIPE_FORMAT_R10G10B10A2_USCALED,
501 PIPE_FORMAT_B10G10R10A2_USCALED,
502 PIPE_FORMAT_R10G10B10A2_SSCALED,
503 PIPE_FORMAT_B10G10R10A2_SSCALED } },
504 { { o(ARB_vertex_type_10f_11f_11f_rev) },
505 { PIPE_FORMAT_R11G11B10_FLOAT } },
506 };
507
508 static const struct st_extension_format_mapping tbo_rgb32[] = {
509 { {o(ARB_texture_buffer_object_rgb32) },
510 { PIPE_FORMAT_R32G32B32_FLOAT,
511 PIPE_FORMAT_R32G32B32_UINT,
512 PIPE_FORMAT_R32G32B32_SINT,
513 } },
514 };
515
516 /*
517 * Extensions that are supported by all Gallium drivers:
518 */
519 ctx->Extensions.ARB_ES2_compatibility = GL_TRUE;
520 ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
521 ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE;
522 ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
523 ctx->Extensions.ARB_fragment_program = GL_TRUE;
524 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
525 ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
526 ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
527 ctx->Extensions.ARB_internalformat_query = GL_TRUE;
528 ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
529 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE; /* XXX temp */
530 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
531 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
532 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
533 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
534 ctx->Extensions.ARB_vertex_program = GL_TRUE;
535 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
536
537 ctx->Extensions.EXT_blend_color = GL_TRUE;
538 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
539 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
540 ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
541 ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
542 ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
543 ctx->Extensions.EXT_point_parameters = GL_TRUE;
544 ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
545
546 /* IMPORTANT:
547 * Don't enable EXT_separate_shader_objects. It disallows a certain
548 * optimization in the GLSL compiler and therefore is considered
549 * harmful.
550 */
551 ctx->Extensions.EXT_separate_shader_objects = GL_FALSE;
552
553 ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
554 ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
555
556 ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
557
558 ctx->Extensions.MESA_pack_invert = GL_TRUE;
559
560 ctx->Extensions.NV_fog_distance = GL_TRUE;
561 ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
562 ctx->Extensions.NV_texture_rectangle = GL_TRUE;
563 ctx->Extensions.NV_vdpau_interop = GL_TRUE;
564
565 ctx->Extensions.OES_EGL_image = GL_TRUE;
566 ctx->Extensions.OES_EGL_image_external = GL_TRUE;
567 ctx->Extensions.OES_draw_texture = GL_TRUE;
568
569 /* Expose the extensions which directly correspond to gallium caps. */
570 for (i = 0; i < Elements(cap_mapping); i++) {
571 if (screen->get_param(screen, cap_mapping[i].cap)) {
572 extensions[cap_mapping[i].extension_offset] = GL_TRUE;
573 }
574 }
575
576 /* Expose the extensions which directly correspond to gallium formats. */
577 init_format_extensions(st, rendertarget_mapping,
578 Elements(rendertarget_mapping), PIPE_TEXTURE_2D,
579 PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW);
580 init_format_extensions(st, depthstencil_mapping,
581 Elements(depthstencil_mapping), PIPE_TEXTURE_2D,
582 PIPE_BIND_DEPTH_STENCIL | PIPE_BIND_SAMPLER_VIEW);
583 init_format_extensions(st, texture_mapping, Elements(texture_mapping),
584 PIPE_TEXTURE_2D, PIPE_BIND_SAMPLER_VIEW);
585 init_format_extensions(st, vertex_mapping, Elements(vertex_mapping),
586 PIPE_BUFFER, PIPE_BIND_VERTEX_BUFFER);
587
588 /* Figure out GLSL support. */
589 glsl_feature_level = screen->get_param(screen, PIPE_CAP_GLSL_FEATURE_LEVEL);
590
591 ctx->Const.GLSLVersion = glsl_feature_level;
592 if (glsl_feature_level >= 330)
593 ctx->Const.GLSLVersion = 330;
594
595 _mesa_override_glsl_version(st->ctx);
596
597 if (st->options.force_glsl_version > 0 &&
598 st->options.force_glsl_version <= ctx->Const.GLSLVersion) {
599 ctx->Const.ForceGLSLVersion = st->options.force_glsl_version;
600 }
601
602 /* This extension needs full OpenGL 3.2, but we don't know if that's
603 * supported at this point. Only check the GLSL version. */
604 if (ctx->Const.GLSLVersion >= 150 &&
605 screen->get_param(screen, PIPE_CAP_TGSI_VS_LAYER)) {
606 ctx->Extensions.AMD_vertex_shader_layer = GL_TRUE;
607 }
608
609 if (ctx->Const.GLSLVersion >= 130) {
610 ctx->Const.NativeIntegers = GL_TRUE;
611 ctx->Const.MaxClipPlanes = 8;
612
613 /* Extensions that either depend on GLSL 1.30 or are a subset thereof. */
614 ctx->Extensions.ARB_conservative_depth = GL_TRUE;
615 ctx->Extensions.ARB_shading_language_packing = GL_TRUE;
616 ctx->Extensions.OES_depth_texture_cube_map = GL_TRUE;
617 ctx->Extensions.ARB_shading_language_420pack = GL_TRUE;
618
619 if (!st->options.disable_shader_bit_encoding) {
620 ctx->Extensions.ARB_shader_bit_encoding = GL_TRUE;
621 }
622 } else {
623 /* Optional integer support for GLSL 1.2. */
624 if (screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
625 PIPE_SHADER_CAP_INTEGERS) &&
626 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
627 PIPE_SHADER_CAP_INTEGERS)) {
628 ctx->Const.NativeIntegers = GL_TRUE;
629 }
630 }
631
632 /* Below are the cases which cannot be moved into tables easily. */
633
634 if (!ctx->Mesa_DXTn && !st->options.force_s3tc_enable) {
635 ctx->Extensions.EXT_texture_compression_s3tc = GL_FALSE;
636 ctx->Extensions.ANGLE_texture_compression_dxt = GL_FALSE;
637 }
638
639 if (screen->get_shader_param(screen, PIPE_SHADER_GEOMETRY,
640 PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
641 #if 0 /* XXX re-enable when GLSL compiler again supports geometry shaders */
642 ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
643 #endif
644 }
645
646 ctx->Extensions.NV_primitive_restart = GL_TRUE;
647 if (!screen->get_param(screen, PIPE_CAP_PRIMITIVE_RESTART)) {
648 ctx->Const.PrimitiveRestartInSoftware = GL_TRUE;
649 }
650
651 /* ARB_color_buffer_float. */
652 if (screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_UNCLAMPED)) {
653 ctx->Extensions.ARB_color_buffer_float = GL_TRUE;
654
655 if (!screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_CLAMPED)) {
656 st->clamp_vert_color_in_shader = TRUE;
657 }
658
659 if (!screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMPED)) {
660 st->clamp_frag_color_in_shader = TRUE;
661 }
662
663 /* For drivers which cannot do color clamping, it's better to just
664 * disable ARB_color_buffer_float in the core profile, because
665 * the clamping is deprecated there anyway. */
666 if (ctx->API == API_OPENGL_CORE &&
667 (st->clamp_frag_color_in_shader || st->clamp_vert_color_in_shader)) {
668 st->clamp_vert_color_in_shader = GL_FALSE;
669 st->clamp_frag_color_in_shader = GL_FALSE;
670 ctx->Extensions.ARB_color_buffer_float = GL_FALSE;
671 }
672 }
673
674 if (screen->fence_finish) {
675 ctx->Extensions.ARB_sync = GL_TRUE;
676 }
677
678 /* Maximum sample count. */
679 for (i = 16; i > 0; --i) {
680 enum pipe_format pformat = st_choose_format(st, GL_RGBA,
681 GL_NONE, GL_NONE,
682 PIPE_TEXTURE_2D, i,
683 PIPE_BIND_RENDER_TARGET, FALSE);
684 if (pformat != PIPE_FORMAT_NONE) {
685 ctx->Const.MaxSamples = i;
686 ctx->Const.MaxColorTextureSamples = i;
687 break;
688 }
689 }
690 for (i = ctx->Const.MaxSamples; i > 0; --i) {
691 enum pipe_format pformat = st_choose_format(st, GL_DEPTH_STENCIL,
692 GL_NONE, GL_NONE,
693 PIPE_TEXTURE_2D, i,
694 PIPE_BIND_DEPTH_STENCIL, FALSE);
695 if (pformat != PIPE_FORMAT_NONE) {
696 ctx->Const.MaxDepthTextureSamples = i;
697 break;
698 }
699 }
700 for (i = ctx->Const.MaxSamples; i > 0; --i) {
701 enum pipe_format pformat = st_choose_format(st, GL_RGBA_INTEGER,
702 GL_NONE, GL_NONE,
703 PIPE_TEXTURE_2D, i,
704 PIPE_BIND_RENDER_TARGET, FALSE);
705 if (pformat != PIPE_FORMAT_NONE) {
706 ctx->Const.MaxIntegerSamples = i;
707 break;
708 }
709 }
710 if (ctx->Const.MaxSamples == 1) {
711 /* one sample doesn't really make sense */
712 ctx->Const.MaxSamples = 0;
713 }
714 else if (ctx->Const.MaxSamples >= 2) {
715 ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
716 ctx->Extensions.EXT_framebuffer_multisample_blit_scaled = GL_TRUE;
717 }
718
719 if (ctx->Const.MaxDualSourceDrawBuffers > 0 &&
720 !st->options.disable_blend_func_extended)
721 ctx->Extensions.ARB_blend_func_extended = GL_TRUE;
722
723 st->has_time_elapsed =
724 screen->get_param(screen, PIPE_CAP_QUERY_TIME_ELAPSED);
725
726 if (st->has_time_elapsed ||
727 ctx->Extensions.ARB_timer_query) {
728 ctx->Extensions.EXT_timer_query = GL_TRUE;
729 }
730
731 if (ctx->Extensions.ARB_transform_feedback2 &&
732 ctx->Extensions.ARB_draw_instanced) {
733 ctx->Extensions.ARB_transform_feedback_instanced = GL_TRUE;
734 }
735 if (st->options.force_glsl_extensions_warn)
736 ctx->Const.ForceGLSLExtensionsWarn = 1;
737
738 if (st->options.disable_glsl_line_continuations)
739 ctx->Const.DisableGLSLLineContinuations = 1;
740
741 ctx->Const.MinMapBufferAlignment =
742 screen->get_param(screen, PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT);
743 if (ctx->Const.MinMapBufferAlignment >= 64) {
744 ctx->Extensions.ARB_map_buffer_alignment = GL_TRUE;
745 }
746 if (screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OBJECTS)) {
747 ctx->Extensions.ARB_texture_buffer_object = GL_TRUE;
748
749 ctx->Const.MaxTextureBufferSize =
750 _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE),
751 (1u << 31) - 1);
752 ctx->Const.TextureBufferOffsetAlignment =
753 screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT);
754
755 if (ctx->Const.TextureBufferOffsetAlignment)
756 ctx->Extensions.ARB_texture_buffer_range = GL_TRUE;
757
758 init_format_extensions(st, tbo_rgb32, Elements(tbo_rgb32),
759 PIPE_BUFFER, PIPE_BIND_SAMPLER_VIEW);
760 }
761
762 if (screen->get_param(screen, PIPE_CAP_MIXED_FRAMEBUFFER_SIZES)) {
763 ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
764 }
765
766 /* Unpacking a varying in the fragment shader costs 1 texture indirection.
767 * If the number of available texture indirections is very limited, then we
768 * prefer to disable varying packing rather than run the risk of varying
769 * packing preventing a shader from running.
770 */
771 if (screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
772 PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS) <= 8) {
773 /* We can't disable varying packing if transform feedback is available,
774 * because transform feedback code assumes a packed varying layout.
775 */
776 if (!ctx->Extensions.EXT_transform_feedback)
777 ctx->Const.DisableVaryingPacking = GL_TRUE;
778 }
779 }