1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
4 * Copyright (c) 2008 VMware, Inc.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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 VMWARE 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.
27 **************************************************************************/
29 #include "main/imports.h"
30 #include "main/context.h"
31 #include "main/macros.h"
32 #include "main/version.h"
34 #include "pipe/p_context.h"
35 #include "pipe/p_defines.h"
36 #include "pipe/p_screen.h"
38 #include "st_context.h"
39 #include "st_extensions.h"
40 #include "st_format.h"
44 * Note: we use these function rather than the MIN2, MAX2, CLAMP macros to
45 * avoid evaluating arguments (which are often function calls) more than once.
48 static unsigned _min(unsigned a
, unsigned b
)
50 return (a
< b
) ? a
: b
;
53 static float _maxf(float a
, float b
)
55 return (a
> b
) ? a
: b
;
58 static int _clamp(int a
, int min
, int max
)
70 * Query driver to get implementation limits.
71 * Note that we have to limit/clamp against Mesa's internal limits too.
73 void st_init_limits(struct st_context
*st
)
75 struct pipe_screen
*screen
= st
->pipe
->screen
;
76 struct gl_constants
*c
= &st
->ctx
->Const
;
78 boolean can_ubo
= TRUE
;
81 = _min(screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
),
85 = _min(screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_3D_LEVELS
),
86 MAX_3D_TEXTURE_LEVELS
);
88 c
->MaxCubeTextureLevels
89 = _min(screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS
),
90 MAX_CUBE_TEXTURE_LEVELS
);
93 = _min(1 << (c
->MaxTextureLevels
- 1), MAX_TEXTURE_RECT_SIZE
);
95 c
->MaxArrayTextureLayers
96 = screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS
);
98 /* Define max viewport size and max renderbuffer size in terms of
99 * max texture size (note: max tex RECT size = max tex 2D size).
100 * If this isn't true for some hardware we'll need new PIPE_CAP_ queries.
102 c
->MaxViewportWidth
=
103 c
->MaxViewportHeight
=
104 c
->MaxRenderbufferSize
= c
->MaxTextureRectSize
;
106 c
->MaxDrawBuffers
= c
->MaxColorAttachments
=
107 _clamp(screen
->get_param(screen
, PIPE_CAP_MAX_RENDER_TARGETS
),
108 1, MAX_DRAW_BUFFERS
);
110 c
->MaxDualSourceDrawBuffers
111 = _clamp(screen
->get_param(screen
, PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS
),
112 0, MAX_DRAW_BUFFERS
);
115 = _maxf(1.0f
, screen
->get_paramf(screen
,
116 PIPE_CAPF_MAX_LINE_WIDTH
));
118 = _maxf(1.0f
, screen
->get_paramf(screen
,
119 PIPE_CAPF_MAX_LINE_WIDTH_AA
));
122 = _maxf(1.0f
, screen
->get_paramf(screen
,
123 PIPE_CAPF_MAX_POINT_WIDTH
));
125 = _maxf(1.0f
, screen
->get_paramf(screen
,
126 PIPE_CAPF_MAX_POINT_WIDTH_AA
));
127 /* called after _mesa_create_context/_mesa_init_point, fix default user
128 * settable max point size up
130 st
->ctx
->Point
.MaxSize
= MAX2(c
->MaxPointSize
, c
->MaxPointSizeAA
);
131 /* these are not queryable. Note that GL basically mandates a 1.0 minimum
132 * for non-aa sizes, but we can go down to 0.0 for aa points.
134 c
->MinPointSize
= 1.0f
;
135 c
->MinPointSizeAA
= 0.0f
;
137 c
->MaxTextureMaxAnisotropy
138 = _maxf(2.0f
, screen
->get_paramf(screen
,
139 PIPE_CAPF_MAX_TEXTURE_ANISOTROPY
));
142 = screen
->get_paramf(screen
, PIPE_CAPF_MAX_TEXTURE_LOD_BIAS
);
144 c
->QuadsFollowProvokingVertexConvention
= screen
->get_param(
145 screen
, PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION
);
147 c
->MaxUniformBlockSize
=
148 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
149 PIPE_SHADER_CAP_MAX_CONSTS
) * 16;
150 if (c
->MaxUniformBlockSize
< 16384) {
154 for (sh
= 0; sh
< PIPE_SHADER_TYPES
; ++sh
) {
155 struct gl_shader_compiler_options
*options
;
156 struct gl_program_constants
*pc
;
159 case PIPE_SHADER_FRAGMENT
:
160 pc
= &c
->Program
[MESA_SHADER_FRAGMENT
];
161 options
= &st
->ctx
->ShaderCompilerOptions
[MESA_SHADER_FRAGMENT
];
163 case PIPE_SHADER_VERTEX
:
164 pc
= &c
->Program
[MESA_SHADER_VERTEX
];
165 options
= &st
->ctx
->ShaderCompilerOptions
[MESA_SHADER_VERTEX
];
167 case PIPE_SHADER_GEOMETRY
:
168 pc
= &c
->Program
[MESA_SHADER_GEOMETRY
];
169 options
= &st
->ctx
->ShaderCompilerOptions
[MESA_SHADER_GEOMETRY
];
172 /* compute shader, etc. */
176 pc
->MaxTextureImageUnits
=
177 _min(screen
->get_shader_param(screen
, sh
,
178 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS
),
179 MAX_TEXTURE_IMAGE_UNITS
);
181 pc
->MaxInstructions
= pc
->MaxNativeInstructions
=
182 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_INSTRUCTIONS
);
183 pc
->MaxAluInstructions
= pc
->MaxNativeAluInstructions
=
184 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS
);
185 pc
->MaxTexInstructions
= pc
->MaxNativeTexInstructions
=
186 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS
);
187 pc
->MaxTexIndirections
= pc
->MaxNativeTexIndirections
=
188 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS
);
189 pc
->MaxAttribs
= pc
->MaxNativeAttribs
=
190 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_INPUTS
);
191 pc
->MaxTemps
= pc
->MaxNativeTemps
=
192 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_TEMPS
);
193 pc
->MaxAddressRegs
= pc
->MaxNativeAddressRegs
=
194 _min(screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_ADDRS
),
195 MAX_PROGRAM_ADDRESS_REGS
);
196 pc
->MaxParameters
= pc
->MaxNativeParameters
=
197 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_CONSTS
);
199 pc
->MaxUniformComponents
= 4 * MIN2(pc
->MaxNativeParameters
, MAX_UNIFORMS
);
201 pc
->MaxUniformBlocks
=
202 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
);
203 if (pc
->MaxUniformBlocks
)
204 pc
->MaxUniformBlocks
-= 1; /* The first one is for ordinary uniforms. */
205 pc
->MaxUniformBlocks
= _min(pc
->MaxUniformBlocks
, MAX_UNIFORM_BUFFERS
);
207 pc
->MaxCombinedUniformComponents
= (pc
->MaxUniformComponents
+
208 c
->MaxUniformBlockSize
/ 4 *
209 pc
->MaxUniformBlocks
);
211 /* Gallium doesn't really care about local vs. env parameters so use the
214 pc
->MaxLocalParams
= MIN2(pc
->MaxParameters
, MAX_PROGRAM_LOCAL_PARAMS
);
215 pc
->MaxEnvParams
= MIN2(pc
->MaxParameters
, MAX_PROGRAM_ENV_PARAMS
);
217 options
->EmitNoNoise
= TRUE
;
219 /* TODO: make these more fine-grained if anyone needs it */
220 options
->MaxIfDepth
= screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH
);
221 options
->EmitNoLoops
= !screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH
);
222 options
->EmitNoFunctions
= !screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_SUBROUTINES
);
223 options
->EmitNoMainReturn
= !screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_SUBROUTINES
);
225 options
->EmitNoCont
= !screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED
);
227 options
->EmitNoIndirectInput
= !screen
->get_shader_param(screen
, sh
,
228 PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR
);
229 options
->EmitNoIndirectOutput
= !screen
->get_shader_param(screen
, sh
,
230 PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR
);
231 options
->EmitNoIndirectTemp
= !screen
->get_shader_param(screen
, sh
,
232 PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR
);
233 options
->EmitNoIndirectUniform
= !screen
->get_shader_param(screen
, sh
,
234 PIPE_SHADER_CAP_INDIRECT_CONST_ADDR
);
236 if (pc
->MaxNativeInstructions
&&
237 (options
->EmitNoIndirectUniform
|| pc
->MaxUniformBlocks
< 12)) {
241 if (options
->EmitNoLoops
)
242 options
->MaxUnrollIterations
= MIN2(screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_INSTRUCTIONS
), 65536);
244 options
->MaxUnrollIterations
= 255; /* SM3 limit */
245 options
->LowerClipDistance
= true;
248 c
->MaxCombinedTextureImageUnits
=
249 _min(c
->Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
+
250 c
->Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
+
251 c
->Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
,
252 MAX_COMBINED_TEXTURE_IMAGE_UNITS
);
254 /* This depends on program constants. */
255 c
->MaxTextureCoordUnits
256 = _min(c
->Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
, MAX_TEXTURE_COORD_UNITS
);
258 c
->MaxTextureUnits
= _min(c
->Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
, c
->MaxTextureCoordUnits
);
260 c
->Program
[MESA_SHADER_VERTEX
].MaxAttribs
= MIN2(c
->Program
[MESA_SHADER_VERTEX
].MaxAttribs
, 16);
262 /* PIPE_SHADER_CAP_MAX_INPUTS for the FS specifies the maximum number
263 * of inputs. It's always 2 colors + N generic inputs. */
264 c
->MaxVarying
= screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
265 PIPE_SHADER_CAP_MAX_INPUTS
);
266 c
->MaxVarying
= MIN2(c
->MaxVarying
, MAX_VARYING
);
267 c
->Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
= c
->MaxVarying
* 4;
268 c
->Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= c
->MaxVarying
* 4;
269 c
->Program
[MESA_SHADER_GEOMETRY
].MaxInputComponents
= c
->MaxVarying
* 4;
270 c
->Program
[MESA_SHADER_GEOMETRY
].MaxOutputComponents
= c
->MaxVarying
* 4;
271 c
->MaxGeometryOutputVertices
= screen
->get_param(screen
, PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES
);
272 c
->MaxGeometryTotalOutputComponents
= screen
->get_param(screen
, PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS
);
274 c
->MinProgramTexelOffset
= screen
->get_param(screen
, PIPE_CAP_MIN_TEXEL_OFFSET
);
275 c
->MaxProgramTexelOffset
= screen
->get_param(screen
, PIPE_CAP_MAX_TEXEL_OFFSET
);
277 c
->MaxProgramTextureGatherComponents
= screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS
);
278 c
->MinProgramTextureGatherOffset
= screen
->get_param(screen
, PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET
);
279 c
->MaxProgramTextureGatherOffset
= screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET
);
281 c
->UniformBooleanTrue
= ~0;
283 c
->MaxTransformFeedbackBuffers
=
284 screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
);
285 c
->MaxTransformFeedbackBuffers
= MIN2(c
->MaxTransformFeedbackBuffers
, MAX_FEEDBACK_BUFFERS
);
286 c
->MaxTransformFeedbackSeparateComponents
=
287 screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS
);
288 c
->MaxTransformFeedbackInterleavedComponents
=
289 screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS
);
290 c
->MaxVertexStreams
=
291 MAX2(1, screen
->get_param(screen
, PIPE_CAP_MAX_VERTEX_STREAMS
));
293 /* The vertex stream must fit into pipe_stream_output_info::stream */
294 assert(c
->MaxVertexStreams
<= 4);
296 c
->StripTextureBorder
= GL_TRUE
;
298 c
->GLSLSkipStrictMaxUniformLimitCheck
=
299 screen
->get_param(screen
, PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS
);
302 st
->ctx
->Extensions
.ARB_uniform_buffer_object
= GL_TRUE
;
303 c
->UniformBufferOffsetAlignment
=
304 screen
->get_param(screen
, PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
305 c
->MaxCombinedUniformBlocks
= c
->MaxUniformBufferBindings
=
306 c
->Program
[MESA_SHADER_VERTEX
].MaxUniformBlocks
+
307 c
->Program
[MESA_SHADER_GEOMETRY
].MaxUniformBlocks
+
308 c
->Program
[MESA_SHADER_FRAGMENT
].MaxUniformBlocks
;
309 assert(c
->MaxCombinedUniformBlocks
<= MAX_COMBINED_UNIFORM_BUFFERS
);
315 * Given a member \c x of struct gl_extensions, return offset of
318 #define o(x) offsetof(struct gl_extensions, x)
321 struct st_extension_cap_mapping
{
322 int extension_offset
;
326 struct st_extension_format_mapping
{
327 int extension_offset
[2];
328 enum pipe_format format
[8];
330 /* If TRUE, at least one format must be supported for the extensions to be
331 * advertised. If FALSE, all the formats must be supported. */
332 GLboolean need_at_least_one
;
336 * Enable extensions if certain pipe formats are supported by the driver.
337 * What extensions will be enabled and what formats must be supported is
338 * described by the array of st_extension_format_mapping.
340 * target and bind_flags are passed to is_format_supported.
342 static void init_format_extensions(struct st_context
*st
,
343 const struct st_extension_format_mapping
*mapping
,
344 unsigned num_mappings
,
345 enum pipe_texture_target target
,
348 struct pipe_screen
*screen
= st
->pipe
->screen
;
349 GLboolean
*extensions
= (GLboolean
*) &st
->ctx
->Extensions
;
352 int num_formats
= Elements(mapping
->format
);
353 int num_ext
= Elements(mapping
->extension_offset
);
355 for (i
= 0; i
< num_mappings
; i
++) {
356 int num_supported
= 0;
358 /* Examine each format in the list. */
359 for (j
= 0; j
< num_formats
&& mapping
[i
].format
[j
]; j
++) {
360 if (screen
->is_format_supported(screen
, mapping
[i
].format
[j
],
361 target
, 0, bind_flags
)) {
366 if (!num_supported
||
367 (!mapping
[i
].need_at_least_one
&& num_supported
!= j
)) {
371 /* Enable all extensions in the list. */
372 for (j
= 0; j
< num_ext
&& mapping
[i
].extension_offset
[j
]; j
++)
373 extensions
[mapping
[i
].extension_offset
[j
]] = GL_TRUE
;
378 * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
379 * which GL extensions are supported.
380 * Quite a few extensions are always supported because they are standard
381 * features or can be built on top of other gallium features.
382 * Some fine tuning may still be needed.
384 void st_init_extensions(struct st_context
*st
)
386 struct pipe_screen
*screen
= st
->pipe
->screen
;
387 struct gl_context
*ctx
= st
->ctx
;
388 int i
, glsl_feature_level
;
389 GLboolean
*extensions
= (GLboolean
*) &ctx
->Extensions
;
391 static const struct st_extension_cap_mapping cap_mapping
[] = {
392 { o(ARB_base_instance
), PIPE_CAP_START_INSTANCE
},
393 { o(ARB_buffer_storage
), PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT
},
394 { o(ARB_depth_clamp
), PIPE_CAP_DEPTH_CLIP_DISABLE
},
395 { o(ARB_depth_texture
), PIPE_CAP_TEXTURE_SHADOW_MAP
},
396 { o(ARB_draw_buffers_blend
), PIPE_CAP_INDEP_BLEND_FUNC
},
397 { o(ARB_draw_instanced
), PIPE_CAP_TGSI_INSTANCEID
},
398 { o(ARB_fragment_program_shadow
), PIPE_CAP_TEXTURE_SHADOW_MAP
},
399 { o(ARB_instanced_arrays
), PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR
},
400 { o(ARB_occlusion_query
), PIPE_CAP_OCCLUSION_QUERY
},
401 { o(ARB_occlusion_query2
), PIPE_CAP_OCCLUSION_QUERY
},
402 { o(ARB_point_sprite
), PIPE_CAP_POINT_SPRITE
},
403 { o(ARB_seamless_cube_map
), PIPE_CAP_SEAMLESS_CUBE_MAP
},
404 { o(ARB_shader_stencil_export
), PIPE_CAP_SHADER_STENCIL_EXPORT
},
405 { o(ARB_shader_texture_lod
), PIPE_CAP_SM3
},
406 { o(ARB_shadow
), PIPE_CAP_TEXTURE_SHADOW_MAP
},
407 { o(ARB_texture_mirror_clamp_to_edge
), PIPE_CAP_TEXTURE_MIRROR_CLAMP
},
408 { o(ARB_texture_non_power_of_two
), PIPE_CAP_NPOT_TEXTURES
},
409 { o(ARB_timer_query
), PIPE_CAP_QUERY_TIMESTAMP
},
410 { o(ARB_transform_feedback2
), PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME
},
411 { o(ARB_transform_feedback3
), PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME
},
413 { o(EXT_blend_equation_separate
), PIPE_CAP_BLEND_EQUATION_SEPARATE
},
414 { o(EXT_draw_buffers2
), PIPE_CAP_INDEP_BLEND_ENABLE
},
415 { o(EXT_stencil_two_side
), PIPE_CAP_TWO_SIDED_STENCIL
},
416 { o(EXT_texture_array
), PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS
},
417 { o(EXT_texture_filter_anisotropic
), PIPE_CAP_ANISOTROPIC_FILTER
},
418 { o(EXT_texture_mirror_clamp
), PIPE_CAP_TEXTURE_MIRROR_CLAMP
},
419 { o(EXT_texture_swizzle
), PIPE_CAP_TEXTURE_SWIZZLE
},
420 { o(EXT_transform_feedback
), PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
},
422 { o(AMD_seamless_cubemap_per_texture
), PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE
},
423 { o(ATI_separate_stencil
), PIPE_CAP_TWO_SIDED_STENCIL
},
424 { o(ATI_texture_mirror_once
), PIPE_CAP_TEXTURE_MIRROR_CLAMP
},
425 { o(NV_conditional_render
), PIPE_CAP_CONDITIONAL_RENDER
},
426 { o(NV_texture_barrier
), PIPE_CAP_TEXTURE_BARRIER
},
427 /* GL_NV_point_sprite is not supported by gallium because we don't
428 * support the GL_POINT_SPRITE_R_MODE_NV option. */
430 { o(OES_standard_derivatives
), PIPE_CAP_SM3
},
431 { o(ARB_texture_cube_map_array
), PIPE_CAP_CUBE_MAP_ARRAY
},
432 { o(ARB_texture_multisample
), PIPE_CAP_TEXTURE_MULTISAMPLE
},
433 { o(ARB_texture_query_lod
), PIPE_CAP_TEXTURE_QUERY_LOD
},
434 { o(ARB_sample_shading
), PIPE_CAP_SAMPLE_SHADING
},
435 { o(ARB_draw_indirect
), PIPE_CAP_DRAW_INDIRECT
}
438 /* Required: render target and sampler support */
439 static const struct st_extension_format_mapping rendertarget_mapping
[] = {
440 { { o(ARB_texture_float
) },
441 { PIPE_FORMAT_R32G32B32A32_FLOAT
,
442 PIPE_FORMAT_R16G16B16A16_FLOAT
} },
444 { { o(ARB_texture_rgb10_a2ui
) },
445 { PIPE_FORMAT_R10G10B10A2_UINT
,
446 PIPE_FORMAT_B10G10R10A2_UINT
},
447 GL_TRUE
}, /* at least one format must be supported */
449 { { o(EXT_framebuffer_sRGB
) },
450 { PIPE_FORMAT_A8B8G8R8_SRGB
,
451 PIPE_FORMAT_B8G8R8A8_SRGB
},
452 GL_TRUE
}, /* at least one format must be supported */
454 { { o(EXT_packed_float
) },
455 { PIPE_FORMAT_R11G11B10_FLOAT
} },
457 { { o(EXT_texture_integer
) },
458 { PIPE_FORMAT_R32G32B32A32_UINT
,
459 PIPE_FORMAT_R32G32B32A32_SINT
} },
461 { { o(ARB_texture_rg
) },
462 { PIPE_FORMAT_R8_UNORM
,
463 PIPE_FORMAT_R8G8_UNORM
} },
466 /* Required: depth stencil and sampler support */
467 static const struct st_extension_format_mapping depthstencil_mapping
[] = {
468 { { o(ARB_depth_buffer_float
) },
469 { PIPE_FORMAT_Z32_FLOAT
,
470 PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
} },
473 /* Required: sampler support */
474 static const struct st_extension_format_mapping texture_mapping
[] = {
475 { { o(ARB_texture_compression_rgtc
) },
476 { PIPE_FORMAT_RGTC1_UNORM
,
477 PIPE_FORMAT_RGTC1_SNORM
,
478 PIPE_FORMAT_RGTC2_UNORM
,
479 PIPE_FORMAT_RGTC2_SNORM
} },
481 { { o(EXT_texture_compression_latc
) },
482 { PIPE_FORMAT_LATC1_UNORM
,
483 PIPE_FORMAT_LATC1_SNORM
,
484 PIPE_FORMAT_LATC2_UNORM
,
485 PIPE_FORMAT_LATC2_SNORM
} },
487 { { o(EXT_texture_compression_s3tc
),
488 o(ANGLE_texture_compression_dxt
) },
489 { PIPE_FORMAT_DXT1_RGB
,
490 PIPE_FORMAT_DXT1_RGBA
,
491 PIPE_FORMAT_DXT3_RGBA
,
492 PIPE_FORMAT_DXT5_RGBA
} },
494 { { o(EXT_texture_shared_exponent
) },
495 { PIPE_FORMAT_R9G9B9E5_FLOAT
} },
497 { { o(EXT_texture_snorm
) },
498 { PIPE_FORMAT_R8G8B8A8_SNORM
} },
500 { { o(EXT_texture_sRGB
),
501 o(EXT_texture_sRGB_decode
) },
502 { PIPE_FORMAT_A8B8G8R8_SRGB
,
503 PIPE_FORMAT_B8G8R8A8_SRGB
},
504 GL_TRUE
}, /* at least one format must be supported */
506 { { o(ATI_texture_compression_3dc
) },
507 { PIPE_FORMAT_LATC2_UNORM
} },
509 { { o(MESA_ycbcr_texture
) },
512 GL_TRUE
}, /* at least one format must be supported */
514 { { o(OES_compressed_ETC1_RGB8_texture
) },
515 { PIPE_FORMAT_ETC1_RGB8
} },
517 { { o(ARB_stencil_texturing
) },
518 { PIPE_FORMAT_X24S8_UINT
,
519 PIPE_FORMAT_S8X24_UINT
},
520 GL_TRUE
}, /* at least one format must be supported */
523 /* Required: vertex fetch support. */
524 static const struct st_extension_format_mapping vertex_mapping
[] = {
525 { { o(ARB_vertex_type_2_10_10_10_rev
) },
526 { PIPE_FORMAT_R10G10B10A2_UNORM
,
527 PIPE_FORMAT_B10G10R10A2_UNORM
,
528 PIPE_FORMAT_R10G10B10A2_SNORM
,
529 PIPE_FORMAT_B10G10R10A2_SNORM
,
530 PIPE_FORMAT_R10G10B10A2_USCALED
,
531 PIPE_FORMAT_B10G10R10A2_USCALED
,
532 PIPE_FORMAT_R10G10B10A2_SSCALED
,
533 PIPE_FORMAT_B10G10R10A2_SSCALED
} },
534 { { o(ARB_vertex_type_10f_11f_11f_rev
) },
535 { PIPE_FORMAT_R11G11B10_FLOAT
} },
538 static const struct st_extension_format_mapping tbo_rgb32
[] = {
539 { {o(ARB_texture_buffer_object_rgb32
) },
540 { PIPE_FORMAT_R32G32B32_FLOAT
,
541 PIPE_FORMAT_R32G32B32_UINT
,
542 PIPE_FORMAT_R32G32B32_SINT
,
547 * Extensions that are supported by all Gallium drivers:
549 ctx
->Extensions
.ARB_ES2_compatibility
= GL_TRUE
;
550 ctx
->Extensions
.ARB_draw_elements_base_vertex
= GL_TRUE
;
551 ctx
->Extensions
.ARB_explicit_attrib_location
= GL_TRUE
;
552 ctx
->Extensions
.ARB_explicit_uniform_location
= GL_TRUE
;
553 ctx
->Extensions
.ARB_fragment_coord_conventions
= GL_TRUE
;
554 ctx
->Extensions
.ARB_fragment_program
= GL_TRUE
;
555 ctx
->Extensions
.ARB_fragment_shader
= GL_TRUE
;
556 ctx
->Extensions
.ARB_half_float_vertex
= GL_TRUE
;
557 ctx
->Extensions
.ARB_internalformat_query
= GL_TRUE
;
558 ctx
->Extensions
.ARB_map_buffer_range
= GL_TRUE
;
559 ctx
->Extensions
.ARB_texture_border_clamp
= GL_TRUE
; /* XXX temp */
560 ctx
->Extensions
.ARB_texture_cube_map
= GL_TRUE
;
561 ctx
->Extensions
.ARB_texture_env_combine
= GL_TRUE
;
562 ctx
->Extensions
.ARB_texture_env_crossbar
= GL_TRUE
;
563 ctx
->Extensions
.ARB_texture_env_dot3
= GL_TRUE
;
564 ctx
->Extensions
.ARB_vertex_program
= GL_TRUE
;
565 ctx
->Extensions
.ARB_vertex_shader
= GL_TRUE
;
567 ctx
->Extensions
.EXT_blend_color
= GL_TRUE
;
568 ctx
->Extensions
.EXT_blend_func_separate
= GL_TRUE
;
569 ctx
->Extensions
.EXT_blend_minmax
= GL_TRUE
;
570 ctx
->Extensions
.EXT_gpu_program_parameters
= GL_TRUE
;
571 ctx
->Extensions
.EXT_pixel_buffer_object
= GL_TRUE
;
572 ctx
->Extensions
.EXT_point_parameters
= GL_TRUE
;
573 ctx
->Extensions
.EXT_provoking_vertex
= GL_TRUE
;
575 ctx
->Extensions
.EXT_texture_env_dot3
= GL_TRUE
;
576 ctx
->Extensions
.EXT_vertex_array_bgra
= GL_TRUE
;
578 ctx
->Extensions
.ATI_texture_env_combine3
= GL_TRUE
;
580 ctx
->Extensions
.MESA_pack_invert
= GL_TRUE
;
582 ctx
->Extensions
.NV_fog_distance
= GL_TRUE
;
583 ctx
->Extensions
.NV_texture_env_combine4
= GL_TRUE
;
584 ctx
->Extensions
.NV_texture_rectangle
= GL_TRUE
;
585 ctx
->Extensions
.NV_vdpau_interop
= GL_TRUE
;
587 ctx
->Extensions
.OES_EGL_image
= GL_TRUE
;
588 ctx
->Extensions
.OES_EGL_image_external
= GL_TRUE
;
589 ctx
->Extensions
.OES_draw_texture
= GL_TRUE
;
591 /* Expose the extensions which directly correspond to gallium caps. */
592 for (i
= 0; i
< Elements(cap_mapping
); i
++) {
593 if (screen
->get_param(screen
, cap_mapping
[i
].cap
)) {
594 extensions
[cap_mapping
[i
].extension_offset
] = GL_TRUE
;
598 /* Expose the extensions which directly correspond to gallium formats. */
599 init_format_extensions(st
, rendertarget_mapping
,
600 Elements(rendertarget_mapping
), PIPE_TEXTURE_2D
,
601 PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
);
602 init_format_extensions(st
, depthstencil_mapping
,
603 Elements(depthstencil_mapping
), PIPE_TEXTURE_2D
,
604 PIPE_BIND_DEPTH_STENCIL
| PIPE_BIND_SAMPLER_VIEW
);
605 init_format_extensions(st
, texture_mapping
, Elements(texture_mapping
),
606 PIPE_TEXTURE_2D
, PIPE_BIND_SAMPLER_VIEW
);
607 init_format_extensions(st
, vertex_mapping
, Elements(vertex_mapping
),
608 PIPE_BUFFER
, PIPE_BIND_VERTEX_BUFFER
);
610 /* Figure out GLSL support. */
611 glsl_feature_level
= screen
->get_param(screen
, PIPE_CAP_GLSL_FEATURE_LEVEL
);
613 ctx
->Const
.GLSLVersion
= glsl_feature_level
;
614 if (glsl_feature_level
>= 330)
615 ctx
->Const
.GLSLVersion
= 330;
617 _mesa_override_glsl_version(st
->ctx
);
619 if (st
->options
.force_glsl_version
> 0 &&
620 st
->options
.force_glsl_version
<= ctx
->Const
.GLSLVersion
) {
621 ctx
->Const
.ForceGLSLVersion
= st
->options
.force_glsl_version
;
624 /* This extension needs full OpenGL 3.2, but we don't know if that's
625 * supported at this point. Only check the GLSL version. */
626 if (ctx
->Const
.GLSLVersion
>= 150 &&
627 screen
->get_param(screen
, PIPE_CAP_TGSI_VS_LAYER
)) {
628 ctx
->Extensions
.AMD_vertex_shader_layer
= GL_TRUE
;
631 if (ctx
->Const
.GLSLVersion
>= 130) {
632 ctx
->Const
.NativeIntegers
= GL_TRUE
;
633 ctx
->Const
.MaxClipPlanes
= 8;
635 /* Extensions that either depend on GLSL 1.30 or are a subset thereof. */
636 ctx
->Extensions
.ARB_conservative_depth
= GL_TRUE
;
637 ctx
->Extensions
.ARB_shading_language_packing
= GL_TRUE
;
638 ctx
->Extensions
.OES_depth_texture_cube_map
= GL_TRUE
;
639 ctx
->Extensions
.ARB_shading_language_420pack
= GL_TRUE
;
640 ctx
->Extensions
.ARB_texture_query_levels
= GL_TRUE
;
642 if (!st
->options
.disable_shader_bit_encoding
) {
643 ctx
->Extensions
.ARB_shader_bit_encoding
= GL_TRUE
;
646 ctx
->Extensions
.EXT_shader_integer_mix
= GL_TRUE
;
648 /* Optional integer support for GLSL 1.2. */
649 if (screen
->get_shader_param(screen
, PIPE_SHADER_VERTEX
,
650 PIPE_SHADER_CAP_INTEGERS
) &&
651 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
652 PIPE_SHADER_CAP_INTEGERS
)) {
653 ctx
->Const
.NativeIntegers
= GL_TRUE
;
655 ctx
->Extensions
.EXT_shader_integer_mix
= GL_TRUE
;
659 /* Below are the cases which cannot be moved into tables easily. */
661 if (!ctx
->Mesa_DXTn
&& !st
->options
.force_s3tc_enable
) {
662 ctx
->Extensions
.EXT_texture_compression_s3tc
= GL_FALSE
;
663 ctx
->Extensions
.ANGLE_texture_compression_dxt
= GL_FALSE
;
666 if (screen
->get_shader_param(screen
, PIPE_SHADER_GEOMETRY
,
667 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0) {
668 #if 0 /* XXX re-enable when GLSL compiler again supports geometry shaders */
669 ctx
->Extensions
.ARB_geometry_shader4
= GL_TRUE
;
673 ctx
->Extensions
.NV_primitive_restart
= GL_TRUE
;
674 if (!screen
->get_param(screen
, PIPE_CAP_PRIMITIVE_RESTART
)) {
675 ctx
->Const
.PrimitiveRestartInSoftware
= GL_TRUE
;
678 /* ARB_color_buffer_float. */
679 if (screen
->get_param(screen
, PIPE_CAP_VERTEX_COLOR_UNCLAMPED
)) {
680 ctx
->Extensions
.ARB_color_buffer_float
= GL_TRUE
;
682 if (!screen
->get_param(screen
, PIPE_CAP_VERTEX_COLOR_CLAMPED
)) {
683 st
->clamp_vert_color_in_shader
= TRUE
;
686 if (!screen
->get_param(screen
, PIPE_CAP_FRAGMENT_COLOR_CLAMPED
)) {
687 st
->clamp_frag_color_in_shader
= TRUE
;
690 /* For drivers which cannot do color clamping, it's better to just
691 * disable ARB_color_buffer_float in the core profile, because
692 * the clamping is deprecated there anyway. */
693 if (ctx
->API
== API_OPENGL_CORE
&&
694 (st
->clamp_frag_color_in_shader
|| st
->clamp_vert_color_in_shader
)) {
695 st
->clamp_vert_color_in_shader
= GL_FALSE
;
696 st
->clamp_frag_color_in_shader
= GL_FALSE
;
697 ctx
->Extensions
.ARB_color_buffer_float
= GL_FALSE
;
701 if (screen
->fence_finish
) {
702 ctx
->Extensions
.ARB_sync
= GL_TRUE
;
705 /* Maximum sample count. */
706 for (i
= 16; i
> 0; --i
) {
707 enum pipe_format pformat
= st_choose_format(st
, GL_RGBA
,
710 PIPE_BIND_RENDER_TARGET
, FALSE
);
711 if (pformat
!= PIPE_FORMAT_NONE
) {
712 ctx
->Const
.MaxSamples
= i
;
713 ctx
->Const
.MaxColorTextureSamples
= i
;
717 for (i
= ctx
->Const
.MaxSamples
; i
> 0; --i
) {
718 enum pipe_format pformat
= st_choose_format(st
, GL_DEPTH_STENCIL
,
721 PIPE_BIND_DEPTH_STENCIL
, FALSE
);
722 if (pformat
!= PIPE_FORMAT_NONE
) {
723 ctx
->Const
.MaxDepthTextureSamples
= i
;
727 for (i
= ctx
->Const
.MaxSamples
; i
> 0; --i
) {
728 enum pipe_format pformat
= st_choose_format(st
, GL_RGBA_INTEGER
,
731 PIPE_BIND_RENDER_TARGET
, FALSE
);
732 if (pformat
!= PIPE_FORMAT_NONE
) {
733 ctx
->Const
.MaxIntegerSamples
= i
;
737 if (ctx
->Const
.MaxSamples
== 1) {
738 /* one sample doesn't really make sense */
739 ctx
->Const
.MaxSamples
= 0;
741 else if (ctx
->Const
.MaxSamples
>= 2) {
742 ctx
->Extensions
.EXT_framebuffer_multisample
= GL_TRUE
;
743 ctx
->Extensions
.EXT_framebuffer_multisample_blit_scaled
= GL_TRUE
;
746 if (ctx
->Const
.MaxSamples
== 0 && screen
->get_param(screen
, PIPE_CAP_FAKE_SW_MSAA
)) {
747 ctx
->Const
.FakeSWMSAA
= GL_TRUE
;
748 ctx
->Extensions
.EXT_framebuffer_multisample
= GL_TRUE
;
749 ctx
->Extensions
.EXT_framebuffer_multisample_blit_scaled
= GL_TRUE
;
750 ctx
->Extensions
.ARB_texture_multisample
= GL_TRUE
;
753 if (ctx
->Const
.MaxDualSourceDrawBuffers
> 0 &&
754 !st
->options
.disable_blend_func_extended
)
755 ctx
->Extensions
.ARB_blend_func_extended
= GL_TRUE
;
757 st
->has_time_elapsed
=
758 screen
->get_param(screen
, PIPE_CAP_QUERY_TIME_ELAPSED
);
760 if (st
->has_time_elapsed
||
761 ctx
->Extensions
.ARB_timer_query
) {
762 ctx
->Extensions
.EXT_timer_query
= GL_TRUE
;
765 if (ctx
->Extensions
.ARB_transform_feedback2
&&
766 ctx
->Extensions
.ARB_draw_instanced
) {
767 ctx
->Extensions
.ARB_transform_feedback_instanced
= GL_TRUE
;
769 if (st
->options
.force_glsl_extensions_warn
)
770 ctx
->Const
.ForceGLSLExtensionsWarn
= 1;
772 if (st
->options
.disable_glsl_line_continuations
)
773 ctx
->Const
.DisableGLSLLineContinuations
= 1;
775 ctx
->Const
.MinMapBufferAlignment
=
776 screen
->get_param(screen
, PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT
);
778 if (screen
->get_param(screen
, PIPE_CAP_TEXTURE_BUFFER_OBJECTS
)) {
779 ctx
->Extensions
.ARB_texture_buffer_object
= GL_TRUE
;
781 ctx
->Const
.MaxTextureBufferSize
=
782 _min(screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE
),
784 ctx
->Const
.TextureBufferOffsetAlignment
=
785 screen
->get_param(screen
, PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT
);
787 if (ctx
->Const
.TextureBufferOffsetAlignment
)
788 ctx
->Extensions
.ARB_texture_buffer_range
= GL_TRUE
;
790 init_format_extensions(st
, tbo_rgb32
, Elements(tbo_rgb32
),
791 PIPE_BUFFER
, PIPE_BIND_SAMPLER_VIEW
);
794 if (screen
->get_param(screen
, PIPE_CAP_MIXED_FRAMEBUFFER_SIZES
)) {
795 ctx
->Extensions
.ARB_framebuffer_object
= GL_TRUE
;
798 /* Unpacking a varying in the fragment shader costs 1 texture indirection.
799 * If the number of available texture indirections is very limited, then we
800 * prefer to disable varying packing rather than run the risk of varying
801 * packing preventing a shader from running.
803 if (screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
804 PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS
) <= 8) {
805 /* We can't disable varying packing if transform feedback is available,
806 * because transform feedback code assumes a packed varying layout.
808 if (!ctx
->Extensions
.EXT_transform_feedback
)
809 ctx
->Const
.DisableVaryingPacking
= GL_TRUE
;
812 if (ctx
->API
== API_OPENGL_CORE
) {
813 ctx
->Const
.MaxViewports
= screen
->get_param(screen
, PIPE_CAP_MAX_VIEWPORTS
);
814 if (ctx
->Const
.MaxViewports
>= 16) {
815 ctx
->Const
.ViewportBounds
.Min
= -16384.0;
816 ctx
->Const
.ViewportBounds
.Max
= 16384.0;
817 ctx
->Extensions
.ARB_viewport_array
= GL_TRUE
;
818 ctx
->Extensions
.ARB_fragment_layer_viewport
= GL_TRUE
;
819 if (ctx
->Extensions
.AMD_vertex_shader_layer
)
820 ctx
->Extensions
.AMD_vertex_shader_viewport_index
= GL_TRUE
;
823 if (ctx
->Const
.MaxProgramTextureGatherComponents
> 0)
824 ctx
->Extensions
.ARB_texture_gather
= GL_TRUE
;