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"
37 #include "util/u_math.h"
39 #include "st_context.h"
40 #include "st_extensions.h"
41 #include "st_format.h"
45 * Note: we use these function rather than the MIN2, MAX2, CLAMP macros to
46 * avoid evaluating arguments (which are often function calls) more than once.
49 static unsigned _min(unsigned a
, unsigned b
)
51 return (a
< b
) ? a
: b
;
54 static float _maxf(float a
, float b
)
56 return (a
> b
) ? a
: b
;
59 static int _clamp(int a
, int min
, int max
)
71 * Query driver to get implementation limits.
72 * Note that we have to limit/clamp against Mesa's internal limits too.
74 void st_init_limits(struct pipe_screen
*screen
,
75 struct gl_constants
*c
, struct gl_extensions
*extensions
)
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
));
128 /* these are not queryable. Note that GL basically mandates a 1.0 minimum
129 * for non-aa sizes, but we can go down to 0.0 for aa points.
131 c
->MinPointSize
= 1.0f
;
132 c
->MinPointSizeAA
= 0.0f
;
134 c
->MaxTextureMaxAnisotropy
135 = _maxf(2.0f
, screen
->get_paramf(screen
,
136 PIPE_CAPF_MAX_TEXTURE_ANISOTROPY
));
139 = screen
->get_paramf(screen
, PIPE_CAPF_MAX_TEXTURE_LOD_BIAS
);
141 c
->QuadsFollowProvokingVertexConvention
= screen
->get_param(
142 screen
, PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION
);
144 c
->MaxUniformBlockSize
=
145 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
146 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
);
147 if (c
->MaxUniformBlockSize
< 16384) {
151 for (sh
= 0; sh
< PIPE_SHADER_TYPES
; ++sh
) {
152 struct gl_shader_compiler_options
*options
;
153 struct gl_program_constants
*pc
;
156 case PIPE_SHADER_FRAGMENT
:
157 pc
= &c
->Program
[MESA_SHADER_FRAGMENT
];
158 options
= &c
->ShaderCompilerOptions
[MESA_SHADER_FRAGMENT
];
160 case PIPE_SHADER_VERTEX
:
161 pc
= &c
->Program
[MESA_SHADER_VERTEX
];
162 options
= &c
->ShaderCompilerOptions
[MESA_SHADER_VERTEX
];
164 case PIPE_SHADER_GEOMETRY
:
165 pc
= &c
->Program
[MESA_SHADER_GEOMETRY
];
166 options
= &c
->ShaderCompilerOptions
[MESA_SHADER_GEOMETRY
];
168 case PIPE_SHADER_TESS_CTRL
:
169 pc
= &c
->Program
[MESA_SHADER_TESS_CTRL
];
170 options
= &c
->ShaderCompilerOptions
[MESA_SHADER_TESS_CTRL
];
172 case PIPE_SHADER_TESS_EVAL
:
173 pc
= &c
->Program
[MESA_SHADER_TESS_EVAL
];
174 options
= &c
->ShaderCompilerOptions
[MESA_SHADER_TESS_EVAL
];
177 /* compute shader, etc. */
181 pc
->MaxTextureImageUnits
=
182 _min(screen
->get_shader_param(screen
, sh
,
183 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS
),
184 MAX_TEXTURE_IMAGE_UNITS
);
186 pc
->MaxInstructions
= pc
->MaxNativeInstructions
=
187 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_INSTRUCTIONS
);
188 pc
->MaxAluInstructions
= pc
->MaxNativeAluInstructions
=
189 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS
);
190 pc
->MaxTexInstructions
= pc
->MaxNativeTexInstructions
=
191 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS
);
192 pc
->MaxTexIndirections
= pc
->MaxNativeTexIndirections
=
193 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS
);
194 pc
->MaxAttribs
= pc
->MaxNativeAttribs
=
195 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_INPUTS
);
196 pc
->MaxTemps
= pc
->MaxNativeTemps
=
197 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_TEMPS
);
198 pc
->MaxAddressRegs
= pc
->MaxNativeAddressRegs
=
199 sh
== PIPE_SHADER_VERTEX
? 1 : 0;
200 pc
->MaxParameters
= pc
->MaxNativeParameters
=
201 screen
->get_shader_param(screen
, sh
,
202 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) / sizeof(float[4]);
203 pc
->MaxInputComponents
=
204 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_INPUTS
) * 4;
205 pc
->MaxOutputComponents
=
206 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_OUTPUTS
) * 4;
208 pc
->MaxUniformComponents
= 4 * MIN2(pc
->MaxNativeParameters
, MAX_UNIFORMS
);
210 pc
->MaxUniformBlocks
=
211 screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
);
212 if (pc
->MaxUniformBlocks
)
213 pc
->MaxUniformBlocks
-= 1; /* The first one is for ordinary uniforms. */
214 pc
->MaxUniformBlocks
= _min(pc
->MaxUniformBlocks
, MAX_UNIFORM_BUFFERS
);
216 pc
->MaxCombinedUniformComponents
= (pc
->MaxUniformComponents
+
217 c
->MaxUniformBlockSize
/ 4 *
218 pc
->MaxUniformBlocks
);
220 /* Gallium doesn't really care about local vs. env parameters so use the
223 pc
->MaxLocalParams
= MIN2(pc
->MaxParameters
, MAX_PROGRAM_LOCAL_PARAMS
);
224 pc
->MaxEnvParams
= MIN2(pc
->MaxParameters
, MAX_PROGRAM_ENV_PARAMS
);
226 options
->EmitNoNoise
= TRUE
;
228 /* TODO: make these more fine-grained if anyone needs it */
229 options
->MaxIfDepth
= screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH
);
230 options
->EmitNoLoops
= !screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH
);
231 options
->EmitNoFunctions
= !screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_SUBROUTINES
);
232 options
->EmitNoMainReturn
= !screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_SUBROUTINES
);
234 options
->EmitNoCont
= !screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED
);
236 options
->EmitNoIndirectInput
= !screen
->get_shader_param(screen
, sh
,
237 PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR
);
238 options
->EmitNoIndirectOutput
= !screen
->get_shader_param(screen
, sh
,
239 PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR
);
240 options
->EmitNoIndirectTemp
= !screen
->get_shader_param(screen
, sh
,
241 PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR
);
242 options
->EmitNoIndirectUniform
= !screen
->get_shader_param(screen
, sh
,
243 PIPE_SHADER_CAP_INDIRECT_CONST_ADDR
);
245 if (pc
->MaxNativeInstructions
&&
246 (options
->EmitNoIndirectUniform
|| pc
->MaxUniformBlocks
< 12)) {
250 if (options
->EmitNoLoops
)
251 options
->MaxUnrollIterations
= MIN2(screen
->get_shader_param(screen
, sh
, PIPE_SHADER_CAP_MAX_INSTRUCTIONS
), 65536);
253 options
->LowerClipDistance
= true;
256 c
->LowerTessLevel
= true;
258 c
->MaxCombinedTextureImageUnits
=
259 _min(c
->Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
+
260 c
->Program
[MESA_SHADER_TESS_CTRL
].MaxTextureImageUnits
+
261 c
->Program
[MESA_SHADER_TESS_EVAL
].MaxTextureImageUnits
+
262 c
->Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
+
263 c
->Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
,
264 MAX_COMBINED_TEXTURE_IMAGE_UNITS
);
266 /* This depends on program constants. */
267 c
->MaxTextureCoordUnits
268 = _min(c
->Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
, MAX_TEXTURE_COORD_UNITS
);
270 c
->MaxTextureUnits
= _min(c
->Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
, c
->MaxTextureCoordUnits
);
272 c
->Program
[MESA_SHADER_VERTEX
].MaxAttribs
= MIN2(c
->Program
[MESA_SHADER_VERTEX
].MaxAttribs
, 16);
274 /* PIPE_SHADER_CAP_MAX_INPUTS for the FS specifies the maximum number
275 * of inputs. It's always 2 colors + N generic inputs. */
276 c
->MaxVarying
= screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
277 PIPE_SHADER_CAP_MAX_INPUTS
);
278 c
->MaxVarying
= MIN2(c
->MaxVarying
, MAX_VARYING
);
279 c
->MaxGeometryOutputVertices
= screen
->get_param(screen
, PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES
);
280 c
->MaxGeometryTotalOutputComponents
= screen
->get_param(screen
, PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS
);
281 c
->MaxTessPatchComponents
=
282 MAX2(screen
->get_param(screen
, PIPE_CAP_MAX_SHADER_PATCH_VARYINGS
),
285 c
->MinProgramTexelOffset
= screen
->get_param(screen
, PIPE_CAP_MIN_TEXEL_OFFSET
);
286 c
->MaxProgramTexelOffset
= screen
->get_param(screen
, PIPE_CAP_MAX_TEXEL_OFFSET
);
288 c
->MaxProgramTextureGatherComponents
= screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS
);
289 c
->MinProgramTextureGatherOffset
= screen
->get_param(screen
, PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET
);
290 c
->MaxProgramTextureGatherOffset
= screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET
);
292 c
->MaxTransformFeedbackBuffers
=
293 screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
);
294 c
->MaxTransformFeedbackBuffers
= MIN2(c
->MaxTransformFeedbackBuffers
, MAX_FEEDBACK_BUFFERS
);
295 c
->MaxTransformFeedbackSeparateComponents
=
296 screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS
);
297 c
->MaxTransformFeedbackInterleavedComponents
=
298 screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS
);
299 c
->MaxVertexStreams
=
300 MAX2(1, screen
->get_param(screen
, PIPE_CAP_MAX_VERTEX_STREAMS
));
302 /* The vertex stream must fit into pipe_stream_output_info::stream */
303 assert(c
->MaxVertexStreams
<= 4);
305 c
->MaxVertexAttribStride
306 = screen
->get_param(screen
, PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE
);
308 c
->StripTextureBorder
= GL_TRUE
;
310 c
->GLSLSkipStrictMaxUniformLimitCheck
=
311 screen
->get_param(screen
, PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS
);
314 extensions
->ARB_uniform_buffer_object
= GL_TRUE
;
315 c
->UniformBufferOffsetAlignment
=
316 screen
->get_param(screen
, PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
317 c
->MaxCombinedUniformBlocks
= c
->MaxUniformBufferBindings
=
318 c
->Program
[MESA_SHADER_VERTEX
].MaxUniformBlocks
+
319 c
->Program
[MESA_SHADER_TESS_CTRL
].MaxUniformBlocks
+
320 c
->Program
[MESA_SHADER_TESS_EVAL
].MaxUniformBlocks
+
321 c
->Program
[MESA_SHADER_GEOMETRY
].MaxUniformBlocks
+
322 c
->Program
[MESA_SHADER_FRAGMENT
].MaxUniformBlocks
;
323 assert(c
->MaxCombinedUniformBlocks
<= MAX_COMBINED_UNIFORM_BUFFERS
);
329 * Given a member \c x of struct gl_extensions, return offset of
332 #define o(x) offsetof(struct gl_extensions, x)
335 struct st_extension_cap_mapping
{
336 int extension_offset
;
340 struct st_extension_format_mapping
{
341 int extension_offset
[2];
342 enum pipe_format format
[8];
344 /* If TRUE, at least one format must be supported for the extensions to be
345 * advertised. If FALSE, all the formats must be supported. */
346 GLboolean need_at_least_one
;
350 * Enable extensions if certain pipe formats are supported by the driver.
351 * What extensions will be enabled and what formats must be supported is
352 * described by the array of st_extension_format_mapping.
354 * target and bind_flags are passed to is_format_supported.
357 init_format_extensions(struct pipe_screen
*screen
,
358 struct gl_extensions
*extensions
,
359 const struct st_extension_format_mapping
*mapping
,
360 unsigned num_mappings
,
361 enum pipe_texture_target target
,
364 GLboolean
*extension_table
= (GLboolean
*) extensions
;
367 int num_formats
= ARRAY_SIZE(mapping
->format
);
368 int num_ext
= ARRAY_SIZE(mapping
->extension_offset
);
370 for (i
= 0; i
< num_mappings
; i
++) {
371 int num_supported
= 0;
373 /* Examine each format in the list. */
374 for (j
= 0; j
< num_formats
&& mapping
[i
].format
[j
]; j
++) {
375 if (screen
->is_format_supported(screen
, mapping
[i
].format
[j
],
376 target
, 0, bind_flags
)) {
381 if (!num_supported
||
382 (!mapping
[i
].need_at_least_one
&& num_supported
!= j
)) {
386 /* Enable all extensions in the list. */
387 for (j
= 0; j
< num_ext
&& mapping
[i
].extension_offset
[j
]; j
++)
388 extension_table
[mapping
[i
].extension_offset
[j
]] = GL_TRUE
;
394 * Given a list of formats and bind flags, return the maximum number
395 * of samples supported by any of those formats.
398 get_max_samples_for_formats(struct pipe_screen
*screen
,
399 unsigned num_formats
,
400 enum pipe_format
*formats
,
401 unsigned max_samples
,
406 for (i
= max_samples
; i
> 0; --i
) {
407 for (f
= 0; f
< num_formats
; f
++) {
408 if (screen
->is_format_supported(screen
, formats
[f
],
409 PIPE_TEXTURE_2D
, i
, bind
)) {
419 * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
420 * which GL extensions are supported.
421 * Quite a few extensions are always supported because they are standard
422 * features or can be built on top of other gallium features.
423 * Some fine tuning may still be needed.
425 void st_init_extensions(struct pipe_screen
*screen
,
426 struct gl_constants
*consts
,
427 struct gl_extensions
*extensions
,
428 struct st_config_options
*options
,
429 boolean has_lib_dxtc
)
432 int glsl_feature_level
;
433 GLboolean
*extension_table
= (GLboolean
*) extensions
;
435 static const struct st_extension_cap_mapping cap_mapping
[] = {
436 { o(ARB_base_instance
), PIPE_CAP_START_INSTANCE
},
437 { o(ARB_buffer_storage
), PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT
},
438 { o(ARB_depth_clamp
), PIPE_CAP_DEPTH_CLIP_DISABLE
},
439 { o(ARB_depth_texture
), PIPE_CAP_TEXTURE_SHADOW_MAP
},
440 { o(ARB_draw_buffers_blend
), PIPE_CAP_INDEP_BLEND_FUNC
},
441 { o(ARB_draw_instanced
), PIPE_CAP_TGSI_INSTANCEID
},
442 { o(ARB_fragment_program_shadow
), PIPE_CAP_TEXTURE_SHADOW_MAP
},
443 { o(ARB_instanced_arrays
), PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR
},
444 { o(ARB_occlusion_query
), PIPE_CAP_OCCLUSION_QUERY
},
445 { o(ARB_occlusion_query2
), PIPE_CAP_OCCLUSION_QUERY
},
446 { o(ARB_pipeline_statistics_query
), PIPE_CAP_QUERY_PIPELINE_STATISTICS
},
447 { o(ARB_point_sprite
), PIPE_CAP_POINT_SPRITE
},
448 { o(ARB_seamless_cube_map
), PIPE_CAP_SEAMLESS_CUBE_MAP
},
449 { o(ARB_shader_stencil_export
), PIPE_CAP_SHADER_STENCIL_EXPORT
},
450 { o(ARB_shader_texture_lod
), PIPE_CAP_SM3
},
451 { o(ARB_shadow
), PIPE_CAP_TEXTURE_SHADOW_MAP
},
452 { o(ARB_texture_mirror_clamp_to_edge
), PIPE_CAP_TEXTURE_MIRROR_CLAMP
},
453 { o(ARB_texture_non_power_of_two
), PIPE_CAP_NPOT_TEXTURES
},
454 { o(ARB_timer_query
), PIPE_CAP_QUERY_TIMESTAMP
},
455 { o(ARB_transform_feedback2
), PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME
},
456 { o(ARB_transform_feedback3
), PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME
},
458 { o(EXT_blend_equation_separate
), PIPE_CAP_BLEND_EQUATION_SEPARATE
},
459 { o(EXT_draw_buffers2
), PIPE_CAP_INDEP_BLEND_ENABLE
},
460 { o(EXT_stencil_two_side
), PIPE_CAP_TWO_SIDED_STENCIL
},
461 { o(EXT_texture_array
), PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS
},
462 { o(EXT_texture_filter_anisotropic
), PIPE_CAP_ANISOTROPIC_FILTER
},
463 { o(EXT_texture_mirror_clamp
), PIPE_CAP_TEXTURE_MIRROR_CLAMP
},
464 { o(EXT_texture_swizzle
), PIPE_CAP_TEXTURE_SWIZZLE
},
465 { o(EXT_transform_feedback
), PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
},
467 { o(AMD_pinned_memory
), PIPE_CAP_RESOURCE_FROM_USER_MEMORY
},
468 { o(AMD_seamless_cubemap_per_texture
), PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE
},
469 { o(ATI_separate_stencil
), PIPE_CAP_TWO_SIDED_STENCIL
},
470 { o(ATI_texture_mirror_once
), PIPE_CAP_TEXTURE_MIRROR_CLAMP
},
471 { o(NV_conditional_render
), PIPE_CAP_CONDITIONAL_RENDER
},
472 { o(NV_texture_barrier
), PIPE_CAP_TEXTURE_BARRIER
},
473 /* GL_NV_point_sprite is not supported by gallium because we don't
474 * support the GL_POINT_SPRITE_R_MODE_NV option. */
476 { o(OES_standard_derivatives
), PIPE_CAP_SM3
},
477 { o(OES_texture_float_linear
), PIPE_CAP_TEXTURE_FLOAT_LINEAR
},
478 { o(OES_texture_half_float_linear
), PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR
},
479 { o(ARB_texture_cube_map_array
), PIPE_CAP_CUBE_MAP_ARRAY
},
480 { o(ARB_texture_multisample
), PIPE_CAP_TEXTURE_MULTISAMPLE
},
481 { o(ARB_texture_query_lod
), PIPE_CAP_TEXTURE_QUERY_LOD
},
482 { o(ARB_sample_shading
), PIPE_CAP_SAMPLE_SHADING
},
483 { o(ARB_draw_indirect
), PIPE_CAP_DRAW_INDIRECT
},
484 { o(ARB_derivative_control
), PIPE_CAP_TGSI_FS_FINE_DERIVATIVE
},
485 { o(ARB_conditional_render_inverted
), PIPE_CAP_CONDITIONAL_RENDER_INVERTED
},
486 { o(ARB_texture_view
), PIPE_CAP_SAMPLER_VIEW_TARGET
},
487 { o(ARB_clip_control
), PIPE_CAP_CLIP_HALFZ
},
488 { o(EXT_polygon_offset_clamp
), PIPE_CAP_POLYGON_OFFSET_CLAMP
},
491 /* Required: render target and sampler support */
492 static const struct st_extension_format_mapping rendertarget_mapping
[] = {
493 { { o(ARB_texture_float
) },
494 { PIPE_FORMAT_R32G32B32A32_FLOAT
,
495 PIPE_FORMAT_R16G16B16A16_FLOAT
} },
497 { { o(OES_texture_float
) },
498 { PIPE_FORMAT_R32G32B32A32_FLOAT
} },
500 { { o(OES_texture_half_float
) },
501 { PIPE_FORMAT_R16G16B16A16_FLOAT
} },
503 { { o(ARB_texture_rgb10_a2ui
) },
504 { PIPE_FORMAT_R10G10B10A2_UINT
,
505 PIPE_FORMAT_B10G10R10A2_UINT
},
506 GL_TRUE
}, /* at least one format must be supported */
508 { { o(EXT_framebuffer_sRGB
) },
509 { PIPE_FORMAT_A8B8G8R8_SRGB
,
510 PIPE_FORMAT_B8G8R8A8_SRGB
},
511 GL_TRUE
}, /* at least one format must be supported */
513 { { o(EXT_packed_float
) },
514 { PIPE_FORMAT_R11G11B10_FLOAT
} },
516 { { o(EXT_texture_integer
) },
517 { PIPE_FORMAT_R32G32B32A32_UINT
,
518 PIPE_FORMAT_R32G32B32A32_SINT
} },
520 { { o(ARB_texture_rg
) },
521 { PIPE_FORMAT_R8_UNORM
,
522 PIPE_FORMAT_R8G8_UNORM
} },
525 /* Required: depth stencil and sampler support */
526 static const struct st_extension_format_mapping depthstencil_mapping
[] = {
527 { { o(ARB_depth_buffer_float
) },
528 { PIPE_FORMAT_Z32_FLOAT
,
529 PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
} },
532 /* Required: sampler support */
533 static const struct st_extension_format_mapping texture_mapping
[] = {
534 { { o(ARB_texture_compression_rgtc
) },
535 { PIPE_FORMAT_RGTC1_UNORM
,
536 PIPE_FORMAT_RGTC1_SNORM
,
537 PIPE_FORMAT_RGTC2_UNORM
,
538 PIPE_FORMAT_RGTC2_SNORM
} },
540 { { o(EXT_texture_compression_latc
) },
541 { PIPE_FORMAT_LATC1_UNORM
,
542 PIPE_FORMAT_LATC1_SNORM
,
543 PIPE_FORMAT_LATC2_UNORM
,
544 PIPE_FORMAT_LATC2_SNORM
} },
546 { { o(EXT_texture_compression_s3tc
),
547 o(ANGLE_texture_compression_dxt
) },
548 { PIPE_FORMAT_DXT1_RGB
,
549 PIPE_FORMAT_DXT1_RGBA
,
550 PIPE_FORMAT_DXT3_RGBA
,
551 PIPE_FORMAT_DXT5_RGBA
} },
553 { { o(ARB_texture_compression_bptc
) },
554 { PIPE_FORMAT_BPTC_RGBA_UNORM
,
555 PIPE_FORMAT_BPTC_SRGBA
,
556 PIPE_FORMAT_BPTC_RGB_FLOAT
,
557 PIPE_FORMAT_BPTC_RGB_UFLOAT
} },
559 { { o(EXT_texture_shared_exponent
) },
560 { PIPE_FORMAT_R9G9B9E5_FLOAT
} },
562 { { o(EXT_texture_snorm
) },
563 { PIPE_FORMAT_R8G8B8A8_SNORM
} },
565 { { o(EXT_texture_sRGB
),
566 o(EXT_texture_sRGB_decode
) },
567 { PIPE_FORMAT_A8B8G8R8_SRGB
,
568 PIPE_FORMAT_B8G8R8A8_SRGB
},
569 GL_TRUE
}, /* at least one format must be supported */
571 { { o(ATI_texture_compression_3dc
) },
572 { PIPE_FORMAT_LATC2_UNORM
} },
574 { { o(MESA_ycbcr_texture
) },
577 GL_TRUE
}, /* at least one format must be supported */
579 { { o(OES_compressed_ETC1_RGB8_texture
) },
580 { PIPE_FORMAT_ETC1_RGB8
,
581 PIPE_FORMAT_R8G8B8A8_UNORM
},
582 GL_TRUE
}, /* at least one format must be supported */
584 { { o(ARB_stencil_texturing
) },
585 { PIPE_FORMAT_X24S8_UINT
,
586 PIPE_FORMAT_S8X24_UINT
},
587 GL_TRUE
}, /* at least one format must be supported */
590 /* Required: vertex fetch support. */
591 static const struct st_extension_format_mapping vertex_mapping
[] = {
592 { { o(ARB_vertex_type_2_10_10_10_rev
) },
593 { PIPE_FORMAT_R10G10B10A2_UNORM
,
594 PIPE_FORMAT_B10G10R10A2_UNORM
,
595 PIPE_FORMAT_R10G10B10A2_SNORM
,
596 PIPE_FORMAT_B10G10R10A2_SNORM
,
597 PIPE_FORMAT_R10G10B10A2_USCALED
,
598 PIPE_FORMAT_B10G10R10A2_USCALED
,
599 PIPE_FORMAT_R10G10B10A2_SSCALED
,
600 PIPE_FORMAT_B10G10R10A2_SSCALED
} },
601 { { o(ARB_vertex_type_10f_11f_11f_rev
) },
602 { PIPE_FORMAT_R11G11B10_FLOAT
} },
605 static const struct st_extension_format_mapping tbo_rgb32
[] = {
606 { {o(ARB_texture_buffer_object_rgb32
) },
607 { PIPE_FORMAT_R32G32B32_FLOAT
,
608 PIPE_FORMAT_R32G32B32_UINT
,
609 PIPE_FORMAT_R32G32B32_SINT
,
614 * Extensions that are supported by all Gallium drivers:
616 extensions
->ARB_ES2_compatibility
= GL_TRUE
;
617 extensions
->ARB_draw_elements_base_vertex
= GL_TRUE
;
618 extensions
->ARB_explicit_attrib_location
= GL_TRUE
;
619 extensions
->ARB_explicit_uniform_location
= GL_TRUE
;
620 extensions
->ARB_fragment_coord_conventions
= GL_TRUE
;
621 extensions
->ARB_fragment_program
= GL_TRUE
;
622 extensions
->ARB_fragment_shader
= GL_TRUE
;
623 extensions
->ARB_half_float_vertex
= GL_TRUE
;
624 extensions
->ARB_internalformat_query
= GL_TRUE
;
625 extensions
->ARB_map_buffer_range
= GL_TRUE
;
626 extensions
->ARB_texture_border_clamp
= GL_TRUE
; /* XXX temp */
627 extensions
->ARB_texture_cube_map
= GL_TRUE
;
628 extensions
->ARB_texture_env_combine
= GL_TRUE
;
629 extensions
->ARB_texture_env_crossbar
= GL_TRUE
;
630 extensions
->ARB_texture_env_dot3
= GL_TRUE
;
631 extensions
->ARB_vertex_program
= GL_TRUE
;
632 extensions
->ARB_vertex_shader
= GL_TRUE
;
634 extensions
->EXT_blend_color
= GL_TRUE
;
635 extensions
->EXT_blend_func_separate
= GL_TRUE
;
636 extensions
->EXT_blend_minmax
= GL_TRUE
;
637 extensions
->EXT_gpu_program_parameters
= GL_TRUE
;
638 extensions
->EXT_pixel_buffer_object
= GL_TRUE
;
639 extensions
->EXT_point_parameters
= GL_TRUE
;
640 extensions
->EXT_provoking_vertex
= GL_TRUE
;
642 extensions
->EXT_texture_env_dot3
= GL_TRUE
;
643 extensions
->EXT_vertex_array_bgra
= GL_TRUE
;
645 extensions
->ATI_texture_env_combine3
= GL_TRUE
;
647 extensions
->MESA_pack_invert
= GL_TRUE
;
649 extensions
->NV_fog_distance
= GL_TRUE
;
650 extensions
->NV_texture_env_combine4
= GL_TRUE
;
651 extensions
->NV_texture_rectangle
= GL_TRUE
;
653 extensions
->OES_EGL_image
= GL_TRUE
;
654 extensions
->OES_EGL_image_external
= GL_TRUE
;
655 extensions
->OES_draw_texture
= GL_TRUE
;
657 /* Expose the extensions which directly correspond to gallium caps. */
658 for (i
= 0; i
< ARRAY_SIZE(cap_mapping
); i
++) {
659 if (screen
->get_param(screen
, cap_mapping
[i
].cap
)) {
660 extension_table
[cap_mapping
[i
].extension_offset
] = GL_TRUE
;
664 /* Expose the extensions which directly correspond to gallium formats. */
665 init_format_extensions(screen
, extensions
, rendertarget_mapping
,
666 ARRAY_SIZE(rendertarget_mapping
), PIPE_TEXTURE_2D
,
667 PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
);
668 init_format_extensions(screen
, extensions
, depthstencil_mapping
,
669 ARRAY_SIZE(depthstencil_mapping
), PIPE_TEXTURE_2D
,
670 PIPE_BIND_DEPTH_STENCIL
| PIPE_BIND_SAMPLER_VIEW
);
671 init_format_extensions(screen
, extensions
, texture_mapping
,
672 ARRAY_SIZE(texture_mapping
), PIPE_TEXTURE_2D
,
673 PIPE_BIND_SAMPLER_VIEW
);
674 init_format_extensions(screen
, extensions
, vertex_mapping
,
675 ARRAY_SIZE(vertex_mapping
), PIPE_BUFFER
,
676 PIPE_BIND_VERTEX_BUFFER
);
678 if (extensions
->ARB_stencil_texturing
)
679 extensions
->ARB_texture_stencil8
= GL_TRUE
;
681 /* Figure out GLSL support. */
682 glsl_feature_level
= screen
->get_param(screen
, PIPE_CAP_GLSL_FEATURE_LEVEL
);
684 consts
->GLSLVersion
= glsl_feature_level
;
685 if (glsl_feature_level
>= 410)
686 consts
->GLSLVersion
= 410;
688 _mesa_override_glsl_version(consts
);
690 if (options
->force_glsl_version
> 0 &&
691 options
->force_glsl_version
<= consts
->GLSLVersion
) {
692 consts
->ForceGLSLVersion
= options
->force_glsl_version
;
695 if (glsl_feature_level
>= 400)
696 extensions
->ARB_gpu_shader5
= GL_TRUE
;
697 if (glsl_feature_level
>= 410)
698 extensions
->ARB_shader_precision
= GL_TRUE
;
700 /* This extension needs full OpenGL 3.2, but we don't know if that's
701 * supported at this point. Only check the GLSL version. */
702 if (consts
->GLSLVersion
>= 150 &&
703 screen
->get_param(screen
, PIPE_CAP_TGSI_VS_LAYER_VIEWPORT
)) {
704 extensions
->AMD_vertex_shader_layer
= GL_TRUE
;
707 if (consts
->GLSLVersion
>= 130) {
708 consts
->NativeIntegers
= GL_TRUE
;
709 consts
->MaxClipPlanes
= 8;
711 if (screen
->get_param(screen
, PIPE_CAP_VERTEXID_NOBASE
)) {
712 consts
->VertexID_is_zero_based
= GL_TRUE
;
715 /* Extensions that either depend on GLSL 1.30 or are a subset thereof. */
716 extensions
->ARB_conservative_depth
= GL_TRUE
;
717 extensions
->ARB_shading_language_packing
= GL_TRUE
;
718 extensions
->OES_depth_texture_cube_map
= GL_TRUE
;
719 extensions
->ARB_shading_language_420pack
= GL_TRUE
;
720 extensions
->ARB_texture_query_levels
= GL_TRUE
;
721 extensions
->ARB_shader_subroutine
= GL_TRUE
;
723 if (!options
->disable_shader_bit_encoding
) {
724 extensions
->ARB_shader_bit_encoding
= GL_TRUE
;
727 extensions
->EXT_shader_integer_mix
= GL_TRUE
;
729 /* Optional integer support for GLSL 1.2. */
730 if (screen
->get_shader_param(screen
, PIPE_SHADER_VERTEX
,
731 PIPE_SHADER_CAP_INTEGERS
) &&
732 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
733 PIPE_SHADER_CAP_INTEGERS
)) {
734 consts
->NativeIntegers
= GL_TRUE
;
736 extensions
->EXT_shader_integer_mix
= GL_TRUE
;
739 /* Integer textures make no sense before GLSL 1.30 */
740 extensions
->EXT_texture_integer
= GL_FALSE
;
743 consts
->UniformBooleanTrue
= consts
->NativeIntegers
? ~0U : fui(1.0f
);
745 /* Below are the cases which cannot be moved into tables easily. */
747 if (!has_lib_dxtc
&& !options
->force_s3tc_enable
) {
748 extensions
->EXT_texture_compression_s3tc
= GL_FALSE
;
749 extensions
->ANGLE_texture_compression_dxt
= GL_FALSE
;
752 if (screen
->get_shader_param(screen
, PIPE_SHADER_GEOMETRY
,
753 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0) {
754 #if 0 /* XXX re-enable when GLSL compiler again supports geometry shaders */
755 extensions
->ARB_geometry_shader4
= GL_TRUE
;
759 if (screen
->get_shader_param(screen
, PIPE_SHADER_TESS_CTRL
,
760 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0) {
761 extensions
->ARB_tessellation_shader
= GL_TRUE
;
764 if (screen
->get_param(screen
, PIPE_CAP_PRIMITIVE_RESTART
)) {
765 extensions
->NV_primitive_restart
= GL_TRUE
;
768 /* ARB_color_buffer_float. */
769 if (screen
->get_param(screen
, PIPE_CAP_VERTEX_COLOR_UNCLAMPED
)) {
770 extensions
->ARB_color_buffer_float
= GL_TRUE
;
773 if (screen
->fence_finish
) {
774 extensions
->ARB_sync
= GL_TRUE
;
777 /* Maximum sample count. */
779 enum pipe_format color_formats
[] = {
780 PIPE_FORMAT_R8G8B8A8_UNORM
,
781 PIPE_FORMAT_B8G8R8A8_UNORM
,
782 PIPE_FORMAT_A8R8G8B8_UNORM
,
783 PIPE_FORMAT_A8B8G8R8_UNORM
,
785 enum pipe_format depth_formats
[] = {
786 PIPE_FORMAT_Z16_UNORM
,
787 PIPE_FORMAT_Z24X8_UNORM
,
788 PIPE_FORMAT_X8Z24_UNORM
,
789 PIPE_FORMAT_Z32_UNORM
,
790 PIPE_FORMAT_Z32_FLOAT
792 enum pipe_format int_formats
[] = {
793 PIPE_FORMAT_R8G8B8A8_SINT
797 get_max_samples_for_formats(screen
, ARRAY_SIZE(color_formats
),
799 PIPE_BIND_RENDER_TARGET
);
801 consts
->MaxColorTextureSamples
=
802 get_max_samples_for_formats(screen
, ARRAY_SIZE(color_formats
),
803 color_formats
, consts
->MaxSamples
,
804 PIPE_BIND_SAMPLER_VIEW
);
806 consts
->MaxDepthTextureSamples
=
807 get_max_samples_for_formats(screen
, ARRAY_SIZE(depth_formats
),
808 depth_formats
, consts
->MaxSamples
,
809 PIPE_BIND_SAMPLER_VIEW
);
811 consts
->MaxIntegerSamples
=
812 get_max_samples_for_formats(screen
, ARRAY_SIZE(int_formats
),
813 int_formats
, consts
->MaxSamples
,
814 PIPE_BIND_SAMPLER_VIEW
);
816 if (consts
->MaxSamples
== 1) {
817 /* one sample doesn't really make sense */
818 consts
->MaxSamples
= 0;
820 else if (consts
->MaxSamples
>= 2) {
821 extensions
->EXT_framebuffer_multisample
= GL_TRUE
;
822 extensions
->EXT_framebuffer_multisample_blit_scaled
= GL_TRUE
;
825 if (consts
->MaxSamples
== 0 && screen
->get_param(screen
, PIPE_CAP_FAKE_SW_MSAA
)) {
826 consts
->FakeSWMSAA
= GL_TRUE
;
827 extensions
->EXT_framebuffer_multisample
= GL_TRUE
;
828 extensions
->EXT_framebuffer_multisample_blit_scaled
= GL_TRUE
;
829 extensions
->ARB_texture_multisample
= GL_TRUE
;
832 if (consts
->MaxDualSourceDrawBuffers
> 0 &&
833 !options
->disable_blend_func_extended
)
834 extensions
->ARB_blend_func_extended
= GL_TRUE
;
836 if (screen
->get_param(screen
, PIPE_CAP_QUERY_TIME_ELAPSED
) ||
837 extensions
->ARB_timer_query
) {
838 extensions
->EXT_timer_query
= GL_TRUE
;
841 if (extensions
->ARB_transform_feedback2
&&
842 extensions
->ARB_draw_instanced
) {
843 extensions
->ARB_transform_feedback_instanced
= GL_TRUE
;
845 if (options
->force_glsl_extensions_warn
)
846 consts
->ForceGLSLExtensionsWarn
= 1;
848 if (options
->disable_glsl_line_continuations
)
849 consts
->DisableGLSLLineContinuations
= 1;
851 if (options
->allow_glsl_extension_directive_midshader
)
852 consts
->AllowGLSLExtensionDirectiveMidShader
= GL_TRUE
;
854 consts
->MinMapBufferAlignment
=
855 screen
->get_param(screen
, PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT
);
857 if (screen
->get_param(screen
, PIPE_CAP_TEXTURE_BUFFER_OBJECTS
)) {
858 extensions
->ARB_texture_buffer_object
= GL_TRUE
;
860 consts
->MaxTextureBufferSize
=
861 _min(screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE
),
863 consts
->TextureBufferOffsetAlignment
=
864 screen
->get_param(screen
, PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT
);
866 if (consts
->TextureBufferOffsetAlignment
)
867 extensions
->ARB_texture_buffer_range
= GL_TRUE
;
869 init_format_extensions(screen
, extensions
, tbo_rgb32
,
870 ARRAY_SIZE(tbo_rgb32
), PIPE_BUFFER
,
871 PIPE_BIND_SAMPLER_VIEW
);
874 if (screen
->get_param(screen
, PIPE_CAP_MIXED_FRAMEBUFFER_SIZES
)) {
875 extensions
->ARB_framebuffer_object
= GL_TRUE
;
878 /* Unpacking a varying in the fragment shader costs 1 texture indirection.
879 * If the number of available texture indirections is very limited, then we
880 * prefer to disable varying packing rather than run the risk of varying
881 * packing preventing a shader from running.
883 if (screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
884 PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS
) <= 8) {
885 /* We can't disable varying packing if transform feedback is available,
886 * because transform feedback code assumes a packed varying layout.
888 if (!extensions
->EXT_transform_feedback
)
889 consts
->DisableVaryingPacking
= GL_TRUE
;
892 consts
->MaxViewports
= screen
->get_param(screen
, PIPE_CAP_MAX_VIEWPORTS
);
893 if (consts
->MaxViewports
>= 16) {
894 consts
->ViewportBounds
.Min
= -16384.0;
895 consts
->ViewportBounds
.Max
= 16384.0;
896 extensions
->ARB_viewport_array
= GL_TRUE
;
897 extensions
->ARB_fragment_layer_viewport
= GL_TRUE
;
898 if (extensions
->AMD_vertex_shader_layer
)
899 extensions
->AMD_vertex_shader_viewport_index
= GL_TRUE
;
902 if (consts
->MaxProgramTextureGatherComponents
> 0)
903 extensions
->ARB_texture_gather
= GL_TRUE
;
905 /* GL_ARB_ES3_compatibility.
907 * Assume that ES3 is supported if GLSL 3.30 is supported.
908 * (OpenGL 3.3 is a requirement for that extension.)
910 if (consts
->GLSLVersion
>= 330 &&
911 /* Requirements for ETC2 emulation. */
912 screen
->is_format_supported(screen
, PIPE_FORMAT_R8G8B8A8_UNORM
,
914 PIPE_BIND_SAMPLER_VIEW
) &&
915 screen
->is_format_supported(screen
, PIPE_FORMAT_B8G8R8A8_SRGB
,
917 PIPE_BIND_SAMPLER_VIEW
) &&
918 screen
->is_format_supported(screen
, PIPE_FORMAT_R16_UNORM
,
920 PIPE_BIND_SAMPLER_VIEW
) &&
921 screen
->is_format_supported(screen
, PIPE_FORMAT_R16G16_UNORM
,
923 PIPE_BIND_SAMPLER_VIEW
) &&
924 screen
->is_format_supported(screen
, PIPE_FORMAT_R16_SNORM
,
926 PIPE_BIND_SAMPLER_VIEW
) &&
927 screen
->is_format_supported(screen
, PIPE_FORMAT_R16G16_SNORM
,
929 PIPE_BIND_SAMPLER_VIEW
)) {
930 extensions
->ARB_ES3_compatibility
= GL_TRUE
;
933 if (screen
->get_video_param
&&
934 screen
->get_video_param(screen
, PIPE_VIDEO_PROFILE_UNKNOWN
,
935 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
936 PIPE_VIDEO_CAP_SUPPORTS_INTERLACED
)) {
937 extensions
->NV_vdpau_interop
= GL_TRUE
;
940 if (screen
->get_shader_param(screen
, PIPE_SHADER_VERTEX
,
941 PIPE_SHADER_CAP_DOUBLES
) &&
942 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
943 PIPE_SHADER_CAP_DOUBLES
)) {
944 extensions
->ARB_gpu_shader_fp64
= GL_TRUE
;
945 extensions
->ARB_vertex_attrib_64bit
= GL_TRUE
;