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
->MaxUnrollIterations
= screen
->get_shader_param(screen
, sh
,
254 PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT
);
256 options
->LowerClipDistance
= true;
259 c
->LowerTessLevel
= true;
261 c
->MaxCombinedTextureImageUnits
=
262 _min(c
->Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
+
263 c
->Program
[MESA_SHADER_TESS_CTRL
].MaxTextureImageUnits
+
264 c
->Program
[MESA_SHADER_TESS_EVAL
].MaxTextureImageUnits
+
265 c
->Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
+
266 c
->Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
,
267 MAX_COMBINED_TEXTURE_IMAGE_UNITS
);
269 /* This depends on program constants. */
270 c
->MaxTextureCoordUnits
271 = _min(c
->Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
, MAX_TEXTURE_COORD_UNITS
);
273 c
->MaxTextureUnits
= _min(c
->Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
, c
->MaxTextureCoordUnits
);
275 c
->Program
[MESA_SHADER_VERTEX
].MaxAttribs
= MIN2(c
->Program
[MESA_SHADER_VERTEX
].MaxAttribs
, 16);
277 /* PIPE_SHADER_CAP_MAX_INPUTS for the FS specifies the maximum number
278 * of inputs. It's always 2 colors + N generic inputs. */
279 c
->MaxVarying
= screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
280 PIPE_SHADER_CAP_MAX_INPUTS
);
281 c
->MaxVarying
= MIN2(c
->MaxVarying
, MAX_VARYING
);
282 c
->MaxGeometryOutputVertices
= screen
->get_param(screen
, PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES
);
283 c
->MaxGeometryTotalOutputComponents
= screen
->get_param(screen
, PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS
);
284 c
->MaxTessPatchComponents
=
285 MAX2(screen
->get_param(screen
, PIPE_CAP_MAX_SHADER_PATCH_VARYINGS
),
288 c
->MinProgramTexelOffset
= screen
->get_param(screen
, PIPE_CAP_MIN_TEXEL_OFFSET
);
289 c
->MaxProgramTexelOffset
= screen
->get_param(screen
, PIPE_CAP_MAX_TEXEL_OFFSET
);
291 c
->MaxProgramTextureGatherComponents
= screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS
);
292 c
->MinProgramTextureGatherOffset
= screen
->get_param(screen
, PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET
);
293 c
->MaxProgramTextureGatherOffset
= screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET
);
295 c
->MaxTransformFeedbackBuffers
=
296 screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
);
297 c
->MaxTransformFeedbackBuffers
= MIN2(c
->MaxTransformFeedbackBuffers
, MAX_FEEDBACK_BUFFERS
);
298 c
->MaxTransformFeedbackSeparateComponents
=
299 screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS
);
300 c
->MaxTransformFeedbackInterleavedComponents
=
301 screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS
);
302 c
->MaxVertexStreams
=
303 MAX2(1, screen
->get_param(screen
, PIPE_CAP_MAX_VERTEX_STREAMS
));
305 /* The vertex stream must fit into pipe_stream_output_info::stream */
306 assert(c
->MaxVertexStreams
<= 4);
308 c
->MaxVertexAttribStride
309 = screen
->get_param(screen
, PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE
);
311 c
->StripTextureBorder
= GL_TRUE
;
313 c
->GLSLSkipStrictMaxUniformLimitCheck
=
314 screen
->get_param(screen
, PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS
);
317 extensions
->ARB_uniform_buffer_object
= GL_TRUE
;
318 c
->UniformBufferOffsetAlignment
=
319 screen
->get_param(screen
, PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
320 c
->MaxCombinedUniformBlocks
= c
->MaxUniformBufferBindings
=
321 c
->Program
[MESA_SHADER_VERTEX
].MaxUniformBlocks
+
322 c
->Program
[MESA_SHADER_TESS_CTRL
].MaxUniformBlocks
+
323 c
->Program
[MESA_SHADER_TESS_EVAL
].MaxUniformBlocks
+
324 c
->Program
[MESA_SHADER_GEOMETRY
].MaxUniformBlocks
+
325 c
->Program
[MESA_SHADER_FRAGMENT
].MaxUniformBlocks
;
326 assert(c
->MaxCombinedUniformBlocks
<= MAX_COMBINED_UNIFORM_BUFFERS
);
332 * Given a member \c x of struct gl_extensions, return offset of
335 #define o(x) offsetof(struct gl_extensions, x)
338 struct st_extension_cap_mapping
{
339 int extension_offset
;
343 struct st_extension_format_mapping
{
344 int extension_offset
[2];
345 enum pipe_format format
[8];
347 /* If TRUE, at least one format must be supported for the extensions to be
348 * advertised. If FALSE, all the formats must be supported. */
349 GLboolean need_at_least_one
;
353 * Enable extensions if certain pipe formats are supported by the driver.
354 * What extensions will be enabled and what formats must be supported is
355 * described by the array of st_extension_format_mapping.
357 * target and bind_flags are passed to is_format_supported.
360 init_format_extensions(struct pipe_screen
*screen
,
361 struct gl_extensions
*extensions
,
362 const struct st_extension_format_mapping
*mapping
,
363 unsigned num_mappings
,
364 enum pipe_texture_target target
,
367 GLboolean
*extension_table
= (GLboolean
*) extensions
;
370 int num_formats
= ARRAY_SIZE(mapping
->format
);
371 int num_ext
= ARRAY_SIZE(mapping
->extension_offset
);
373 for (i
= 0; i
< num_mappings
; i
++) {
374 int num_supported
= 0;
376 /* Examine each format in the list. */
377 for (j
= 0; j
< num_formats
&& mapping
[i
].format
[j
]; j
++) {
378 if (screen
->is_format_supported(screen
, mapping
[i
].format
[j
],
379 target
, 0, bind_flags
)) {
384 if (!num_supported
||
385 (!mapping
[i
].need_at_least_one
&& num_supported
!= j
)) {
389 /* Enable all extensions in the list. */
390 for (j
= 0; j
< num_ext
&& mapping
[i
].extension_offset
[j
]; j
++)
391 extension_table
[mapping
[i
].extension_offset
[j
]] = GL_TRUE
;
397 * Given a list of formats and bind flags, return the maximum number
398 * of samples supported by any of those formats.
401 get_max_samples_for_formats(struct pipe_screen
*screen
,
402 unsigned num_formats
,
403 enum pipe_format
*formats
,
404 unsigned max_samples
,
409 for (i
= max_samples
; i
> 0; --i
) {
410 for (f
= 0; f
< num_formats
; f
++) {
411 if (screen
->is_format_supported(screen
, formats
[f
],
412 PIPE_TEXTURE_2D
, i
, bind
)) {
422 * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
423 * which GL extensions are supported.
424 * Quite a few extensions are always supported because they are standard
425 * features or can be built on top of other gallium features.
426 * Some fine tuning may still be needed.
428 void st_init_extensions(struct pipe_screen
*screen
,
429 struct gl_constants
*consts
,
430 struct gl_extensions
*extensions
,
431 struct st_config_options
*options
,
432 boolean has_lib_dxtc
)
435 int glsl_feature_level
;
436 GLboolean
*extension_table
= (GLboolean
*) extensions
;
438 static const struct st_extension_cap_mapping cap_mapping
[] = {
439 { o(ARB_base_instance
), PIPE_CAP_START_INSTANCE
},
440 { o(ARB_buffer_storage
), PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT
},
441 { o(ARB_color_buffer_float
), PIPE_CAP_VERTEX_COLOR_UNCLAMPED
},
442 { o(ARB_copy_image
), PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS
},
443 { o(ARB_depth_clamp
), PIPE_CAP_DEPTH_CLIP_DISABLE
},
444 { o(ARB_depth_texture
), PIPE_CAP_TEXTURE_SHADOW_MAP
},
445 { o(ARB_draw_buffers_blend
), PIPE_CAP_INDEP_BLEND_FUNC
},
446 { o(ARB_draw_instanced
), PIPE_CAP_TGSI_INSTANCEID
},
447 { o(ARB_fragment_program_shadow
), PIPE_CAP_TEXTURE_SHADOW_MAP
},
448 { o(ARB_framebuffer_object
), PIPE_CAP_MIXED_FRAMEBUFFER_SIZES
},
449 { o(ARB_instanced_arrays
), PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR
},
450 { o(ARB_occlusion_query
), PIPE_CAP_OCCLUSION_QUERY
},
451 { o(ARB_occlusion_query2
), PIPE_CAP_OCCLUSION_QUERY
},
452 { o(ARB_pipeline_statistics_query
), PIPE_CAP_QUERY_PIPELINE_STATISTICS
},
453 { o(ARB_point_sprite
), PIPE_CAP_POINT_SPRITE
},
454 { o(ARB_seamless_cube_map
), PIPE_CAP_SEAMLESS_CUBE_MAP
},
455 { o(ARB_shader_stencil_export
), PIPE_CAP_SHADER_STENCIL_EXPORT
},
456 { o(ARB_shader_texture_image_samples
), PIPE_CAP_TGSI_TXQS
},
457 { o(ARB_shader_texture_lod
), PIPE_CAP_SM3
},
458 { o(ARB_shadow
), PIPE_CAP_TEXTURE_SHADOW_MAP
},
459 { o(ARB_texture_buffer_object
), PIPE_CAP_TEXTURE_BUFFER_OBJECTS
},
460 { o(ARB_texture_gather
), PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS
},
461 { o(ARB_texture_mirror_clamp_to_edge
), PIPE_CAP_TEXTURE_MIRROR_CLAMP
},
462 { o(ARB_texture_non_power_of_two
), PIPE_CAP_NPOT_TEXTURES
},
463 { o(ARB_timer_query
), PIPE_CAP_QUERY_TIMESTAMP
},
464 { o(ARB_transform_feedback2
), PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME
},
465 { o(ARB_transform_feedback3
), PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME
},
467 { o(EXT_blend_equation_separate
), PIPE_CAP_BLEND_EQUATION_SEPARATE
},
468 { o(EXT_draw_buffers2
), PIPE_CAP_INDEP_BLEND_ENABLE
},
469 { o(EXT_stencil_two_side
), PIPE_CAP_TWO_SIDED_STENCIL
},
470 { o(EXT_texture_array
), PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS
},
471 { o(EXT_texture_filter_anisotropic
), PIPE_CAP_ANISOTROPIC_FILTER
},
472 { o(EXT_texture_mirror_clamp
), PIPE_CAP_TEXTURE_MIRROR_CLAMP
},
473 { o(EXT_texture_swizzle
), PIPE_CAP_TEXTURE_SWIZZLE
},
474 { o(EXT_transform_feedback
), PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
},
476 { o(AMD_pinned_memory
), PIPE_CAP_RESOURCE_FROM_USER_MEMORY
},
477 { o(AMD_seamless_cubemap_per_texture
), PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE
},
478 { o(ATI_separate_stencil
), PIPE_CAP_TWO_SIDED_STENCIL
},
479 { o(ATI_texture_mirror_once
), PIPE_CAP_TEXTURE_MIRROR_CLAMP
},
480 { o(NV_conditional_render
), PIPE_CAP_CONDITIONAL_RENDER
},
481 { o(NV_primitive_restart
), PIPE_CAP_PRIMITIVE_RESTART
},
482 { o(NV_texture_barrier
), PIPE_CAP_TEXTURE_BARRIER
},
483 /* GL_NV_point_sprite is not supported by gallium because we don't
484 * support the GL_POINT_SPRITE_R_MODE_NV option. */
486 { o(OES_standard_derivatives
), PIPE_CAP_SM3
},
487 { o(OES_texture_float_linear
), PIPE_CAP_TEXTURE_FLOAT_LINEAR
},
488 { o(OES_texture_half_float_linear
), PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR
},
489 { o(ARB_texture_cube_map_array
), PIPE_CAP_CUBE_MAP_ARRAY
},
490 { o(ARB_texture_multisample
), PIPE_CAP_TEXTURE_MULTISAMPLE
},
491 { o(ARB_texture_query_lod
), PIPE_CAP_TEXTURE_QUERY_LOD
},
492 { o(ARB_sample_shading
), PIPE_CAP_SAMPLE_SHADING
},
493 { o(ARB_draw_indirect
), PIPE_CAP_DRAW_INDIRECT
},
494 { o(ARB_derivative_control
), PIPE_CAP_TGSI_FS_FINE_DERIVATIVE
},
495 { o(ARB_conditional_render_inverted
), PIPE_CAP_CONDITIONAL_RENDER_INVERTED
},
496 { o(ARB_texture_view
), PIPE_CAP_SAMPLER_VIEW_TARGET
},
497 { o(ARB_clip_control
), PIPE_CAP_CLIP_HALFZ
},
498 { o(EXT_polygon_offset_clamp
), PIPE_CAP_POLYGON_OFFSET_CLAMP
},
499 { o(EXT_depth_bounds_test
), PIPE_CAP_DEPTH_BOUNDS_TEST
},
502 /* Required: render target and sampler support */
503 static const struct st_extension_format_mapping rendertarget_mapping
[] = {
504 { { o(ARB_texture_float
) },
505 { PIPE_FORMAT_R32G32B32A32_FLOAT
,
506 PIPE_FORMAT_R16G16B16A16_FLOAT
} },
508 { { o(OES_texture_float
) },
509 { PIPE_FORMAT_R32G32B32A32_FLOAT
} },
511 { { o(OES_texture_half_float
) },
512 { PIPE_FORMAT_R16G16B16A16_FLOAT
} },
514 { { o(ARB_texture_rgb10_a2ui
) },
515 { PIPE_FORMAT_R10G10B10A2_UINT
,
516 PIPE_FORMAT_B10G10R10A2_UINT
},
517 GL_TRUE
}, /* at least one format must be supported */
519 { { o(EXT_framebuffer_sRGB
) },
520 { PIPE_FORMAT_A8B8G8R8_SRGB
,
521 PIPE_FORMAT_B8G8R8A8_SRGB
},
522 GL_TRUE
}, /* at least one format must be supported */
524 { { o(EXT_packed_float
) },
525 { PIPE_FORMAT_R11G11B10_FLOAT
} },
527 { { o(EXT_texture_integer
) },
528 { PIPE_FORMAT_R32G32B32A32_UINT
,
529 PIPE_FORMAT_R32G32B32A32_SINT
} },
531 { { o(ARB_texture_rg
) },
532 { PIPE_FORMAT_R8_UNORM
,
533 PIPE_FORMAT_R8G8_UNORM
} },
536 /* Required: depth stencil and sampler support */
537 static const struct st_extension_format_mapping depthstencil_mapping
[] = {
538 { { o(ARB_depth_buffer_float
) },
539 { PIPE_FORMAT_Z32_FLOAT
,
540 PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
} },
543 /* Required: sampler support */
544 static const struct st_extension_format_mapping texture_mapping
[] = {
545 { { o(ARB_texture_compression_rgtc
) },
546 { PIPE_FORMAT_RGTC1_UNORM
,
547 PIPE_FORMAT_RGTC1_SNORM
,
548 PIPE_FORMAT_RGTC2_UNORM
,
549 PIPE_FORMAT_RGTC2_SNORM
} },
551 { { o(EXT_texture_compression_latc
) },
552 { PIPE_FORMAT_LATC1_UNORM
,
553 PIPE_FORMAT_LATC1_SNORM
,
554 PIPE_FORMAT_LATC2_UNORM
,
555 PIPE_FORMAT_LATC2_SNORM
} },
557 { { o(EXT_texture_compression_s3tc
),
558 o(ANGLE_texture_compression_dxt
) },
559 { PIPE_FORMAT_DXT1_RGB
,
560 PIPE_FORMAT_DXT1_RGBA
,
561 PIPE_FORMAT_DXT3_RGBA
,
562 PIPE_FORMAT_DXT5_RGBA
} },
564 { { o(ARB_texture_compression_bptc
) },
565 { PIPE_FORMAT_BPTC_RGBA_UNORM
,
566 PIPE_FORMAT_BPTC_SRGBA
,
567 PIPE_FORMAT_BPTC_RGB_FLOAT
,
568 PIPE_FORMAT_BPTC_RGB_UFLOAT
} },
570 { { o(EXT_texture_shared_exponent
) },
571 { PIPE_FORMAT_R9G9B9E5_FLOAT
} },
573 { { o(EXT_texture_snorm
) },
574 { PIPE_FORMAT_R8G8B8A8_SNORM
} },
576 { { o(EXT_texture_sRGB
),
577 o(EXT_texture_sRGB_decode
) },
578 { PIPE_FORMAT_A8B8G8R8_SRGB
,
579 PIPE_FORMAT_B8G8R8A8_SRGB
},
580 GL_TRUE
}, /* at least one format must be supported */
582 { { o(ATI_texture_compression_3dc
) },
583 { PIPE_FORMAT_LATC2_UNORM
} },
585 { { o(MESA_ycbcr_texture
) },
588 GL_TRUE
}, /* at least one format must be supported */
590 { { o(OES_compressed_ETC1_RGB8_texture
) },
591 { PIPE_FORMAT_ETC1_RGB8
,
592 PIPE_FORMAT_R8G8B8A8_UNORM
},
593 GL_TRUE
}, /* at least one format must be supported */
595 { { o(ARB_stencil_texturing
),
596 o(ARB_texture_stencil8
) },
597 { PIPE_FORMAT_X24S8_UINT
,
598 PIPE_FORMAT_S8X24_UINT
},
599 GL_TRUE
}, /* at least one format must be supported */
602 /* Required: vertex fetch support. */
603 static const struct st_extension_format_mapping vertex_mapping
[] = {
604 { { o(ARB_vertex_type_2_10_10_10_rev
) },
605 { PIPE_FORMAT_R10G10B10A2_UNORM
,
606 PIPE_FORMAT_B10G10R10A2_UNORM
,
607 PIPE_FORMAT_R10G10B10A2_SNORM
,
608 PIPE_FORMAT_B10G10R10A2_SNORM
,
609 PIPE_FORMAT_R10G10B10A2_USCALED
,
610 PIPE_FORMAT_B10G10R10A2_USCALED
,
611 PIPE_FORMAT_R10G10B10A2_SSCALED
,
612 PIPE_FORMAT_B10G10R10A2_SSCALED
} },
613 { { o(ARB_vertex_type_10f_11f_11f_rev
) },
614 { PIPE_FORMAT_R11G11B10_FLOAT
} },
617 static const struct st_extension_format_mapping tbo_rgb32
[] = {
618 { {o(ARB_texture_buffer_object_rgb32
) },
619 { PIPE_FORMAT_R32G32B32_FLOAT
,
620 PIPE_FORMAT_R32G32B32_UINT
,
621 PIPE_FORMAT_R32G32B32_SINT
,
626 * Extensions that are supported by all Gallium drivers:
628 extensions
->ARB_ES2_compatibility
= GL_TRUE
;
629 extensions
->ARB_draw_elements_base_vertex
= GL_TRUE
;
630 extensions
->ARB_explicit_attrib_location
= GL_TRUE
;
631 extensions
->ARB_explicit_uniform_location
= GL_TRUE
;
632 extensions
->ARB_fragment_coord_conventions
= GL_TRUE
;
633 extensions
->ARB_fragment_program
= GL_TRUE
;
634 extensions
->ARB_fragment_shader
= GL_TRUE
;
635 extensions
->ARB_half_float_vertex
= GL_TRUE
;
636 extensions
->ARB_internalformat_query
= GL_TRUE
;
637 extensions
->ARB_map_buffer_range
= GL_TRUE
;
638 extensions
->ARB_texture_border_clamp
= GL_TRUE
; /* XXX temp */
639 extensions
->ARB_texture_cube_map
= GL_TRUE
;
640 extensions
->ARB_texture_env_combine
= GL_TRUE
;
641 extensions
->ARB_texture_env_crossbar
= GL_TRUE
;
642 extensions
->ARB_texture_env_dot3
= GL_TRUE
;
643 extensions
->ARB_vertex_program
= GL_TRUE
;
644 extensions
->ARB_vertex_shader
= GL_TRUE
;
646 extensions
->EXT_blend_color
= GL_TRUE
;
647 extensions
->EXT_blend_func_separate
= GL_TRUE
;
648 extensions
->EXT_blend_minmax
= GL_TRUE
;
649 extensions
->EXT_gpu_program_parameters
= GL_TRUE
;
650 extensions
->EXT_pixel_buffer_object
= GL_TRUE
;
651 extensions
->EXT_point_parameters
= GL_TRUE
;
652 extensions
->EXT_provoking_vertex
= GL_TRUE
;
654 extensions
->EXT_texture_env_dot3
= GL_TRUE
;
655 extensions
->EXT_vertex_array_bgra
= GL_TRUE
;
657 extensions
->ATI_texture_env_combine3
= GL_TRUE
;
659 extensions
->MESA_pack_invert
= GL_TRUE
;
661 extensions
->NV_fog_distance
= GL_TRUE
;
662 extensions
->NV_texture_env_combine4
= GL_TRUE
;
663 extensions
->NV_texture_rectangle
= GL_TRUE
;
665 extensions
->OES_EGL_image
= GL_TRUE
;
666 extensions
->OES_EGL_image_external
= GL_TRUE
;
667 extensions
->OES_draw_texture
= GL_TRUE
;
669 /* Expose the extensions which directly correspond to gallium caps. */
670 for (i
= 0; i
< ARRAY_SIZE(cap_mapping
); i
++) {
671 if (screen
->get_param(screen
, cap_mapping
[i
].cap
)) {
672 extension_table
[cap_mapping
[i
].extension_offset
] = GL_TRUE
;
676 /* Expose the extensions which directly correspond to gallium formats. */
677 init_format_extensions(screen
, extensions
, rendertarget_mapping
,
678 ARRAY_SIZE(rendertarget_mapping
), PIPE_TEXTURE_2D
,
679 PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
);
680 init_format_extensions(screen
, extensions
, depthstencil_mapping
,
681 ARRAY_SIZE(depthstencil_mapping
), PIPE_TEXTURE_2D
,
682 PIPE_BIND_DEPTH_STENCIL
| PIPE_BIND_SAMPLER_VIEW
);
683 init_format_extensions(screen
, extensions
, texture_mapping
,
684 ARRAY_SIZE(texture_mapping
), PIPE_TEXTURE_2D
,
685 PIPE_BIND_SAMPLER_VIEW
);
686 init_format_extensions(screen
, extensions
, vertex_mapping
,
687 ARRAY_SIZE(vertex_mapping
), PIPE_BUFFER
,
688 PIPE_BIND_VERTEX_BUFFER
);
690 /* Figure out GLSL support. */
691 glsl_feature_level
= screen
->get_param(screen
, PIPE_CAP_GLSL_FEATURE_LEVEL
);
693 consts
->GLSLVersion
= glsl_feature_level
;
694 if (glsl_feature_level
>= 410)
695 consts
->GLSLVersion
= 410;
697 _mesa_override_glsl_version(consts
);
699 if (options
->force_glsl_version
> 0 &&
700 options
->force_glsl_version
<= consts
->GLSLVersion
) {
701 consts
->ForceGLSLVersion
= options
->force_glsl_version
;
704 if (glsl_feature_level
>= 400)
705 extensions
->ARB_gpu_shader5
= GL_TRUE
;
706 if (glsl_feature_level
>= 410)
707 extensions
->ARB_shader_precision
= GL_TRUE
;
709 /* This extension needs full OpenGL 3.2, but we don't know if that's
710 * supported at this point. Only check the GLSL version. */
711 if (consts
->GLSLVersion
>= 150 &&
712 screen
->get_param(screen
, PIPE_CAP_TGSI_VS_LAYER_VIEWPORT
)) {
713 extensions
->AMD_vertex_shader_layer
= GL_TRUE
;
716 if (consts
->GLSLVersion
>= 130) {
717 consts
->NativeIntegers
= GL_TRUE
;
718 consts
->MaxClipPlanes
= 8;
720 if (screen
->get_param(screen
, PIPE_CAP_VERTEXID_NOBASE
)) {
721 consts
->VertexID_is_zero_based
= GL_TRUE
;
724 /* Extensions that either depend on GLSL 1.30 or are a subset thereof. */
725 extensions
->ARB_conservative_depth
= GL_TRUE
;
726 extensions
->ARB_shading_language_packing
= GL_TRUE
;
727 extensions
->OES_depth_texture_cube_map
= GL_TRUE
;
728 extensions
->ARB_shading_language_420pack
= GL_TRUE
;
729 extensions
->ARB_texture_query_levels
= GL_TRUE
;
730 extensions
->ARB_shader_subroutine
= GL_TRUE
;
732 if (!options
->disable_shader_bit_encoding
) {
733 extensions
->ARB_shader_bit_encoding
= GL_TRUE
;
736 extensions
->EXT_shader_integer_mix
= GL_TRUE
;
738 /* Optional integer support for GLSL 1.2. */
739 if (screen
->get_shader_param(screen
, PIPE_SHADER_VERTEX
,
740 PIPE_SHADER_CAP_INTEGERS
) &&
741 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
742 PIPE_SHADER_CAP_INTEGERS
)) {
743 consts
->NativeIntegers
= GL_TRUE
;
745 extensions
->EXT_shader_integer_mix
= GL_TRUE
;
748 /* Integer textures make no sense before GLSL 1.30 */
749 extensions
->EXT_texture_integer
= GL_FALSE
;
752 consts
->UniformBooleanTrue
= consts
->NativeIntegers
? ~0U : fui(1.0f
);
754 /* Below are the cases which cannot be moved into tables easily. */
756 if (!has_lib_dxtc
&& !options
->force_s3tc_enable
) {
757 extensions
->EXT_texture_compression_s3tc
= GL_FALSE
;
758 extensions
->ANGLE_texture_compression_dxt
= GL_FALSE
;
761 if (screen
->get_shader_param(screen
, PIPE_SHADER_TESS_CTRL
,
762 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0) {
763 extensions
->ARB_tessellation_shader
= GL_TRUE
;
766 if (screen
->fence_finish
) {
767 extensions
->ARB_sync
= GL_TRUE
;
770 /* Maximum sample count. */
772 enum pipe_format color_formats
[] = {
773 PIPE_FORMAT_R8G8B8A8_UNORM
,
774 PIPE_FORMAT_B8G8R8A8_UNORM
,
775 PIPE_FORMAT_A8R8G8B8_UNORM
,
776 PIPE_FORMAT_A8B8G8R8_UNORM
,
778 enum pipe_format depth_formats
[] = {
779 PIPE_FORMAT_Z16_UNORM
,
780 PIPE_FORMAT_Z24X8_UNORM
,
781 PIPE_FORMAT_X8Z24_UNORM
,
782 PIPE_FORMAT_Z32_UNORM
,
783 PIPE_FORMAT_Z32_FLOAT
785 enum pipe_format int_formats
[] = {
786 PIPE_FORMAT_R8G8B8A8_SINT
790 get_max_samples_for_formats(screen
, ARRAY_SIZE(color_formats
),
792 PIPE_BIND_RENDER_TARGET
);
794 consts
->MaxColorTextureSamples
=
795 get_max_samples_for_formats(screen
, ARRAY_SIZE(color_formats
),
796 color_formats
, consts
->MaxSamples
,
797 PIPE_BIND_SAMPLER_VIEW
);
799 consts
->MaxDepthTextureSamples
=
800 get_max_samples_for_formats(screen
, ARRAY_SIZE(depth_formats
),
801 depth_formats
, consts
->MaxSamples
,
802 PIPE_BIND_SAMPLER_VIEW
);
804 consts
->MaxIntegerSamples
=
805 get_max_samples_for_formats(screen
, ARRAY_SIZE(int_formats
),
806 int_formats
, consts
->MaxSamples
,
807 PIPE_BIND_SAMPLER_VIEW
);
809 if (consts
->MaxSamples
== 1) {
810 /* one sample doesn't really make sense */
811 consts
->MaxSamples
= 0;
813 else if (consts
->MaxSamples
>= 2) {
814 extensions
->EXT_framebuffer_multisample
= GL_TRUE
;
815 extensions
->EXT_framebuffer_multisample_blit_scaled
= GL_TRUE
;
818 if (consts
->MaxSamples
== 0 && screen
->get_param(screen
, PIPE_CAP_FAKE_SW_MSAA
)) {
819 consts
->FakeSWMSAA
= GL_TRUE
;
820 extensions
->EXT_framebuffer_multisample
= GL_TRUE
;
821 extensions
->EXT_framebuffer_multisample_blit_scaled
= GL_TRUE
;
822 extensions
->ARB_texture_multisample
= GL_TRUE
;
825 if (consts
->MaxDualSourceDrawBuffers
> 0 &&
826 !options
->disable_blend_func_extended
)
827 extensions
->ARB_blend_func_extended
= GL_TRUE
;
829 if (screen
->get_param(screen
, PIPE_CAP_QUERY_TIME_ELAPSED
) ||
830 extensions
->ARB_timer_query
) {
831 extensions
->EXT_timer_query
= GL_TRUE
;
834 if (extensions
->ARB_transform_feedback2
&&
835 extensions
->ARB_draw_instanced
) {
836 extensions
->ARB_transform_feedback_instanced
= GL_TRUE
;
838 if (options
->force_glsl_extensions_warn
)
839 consts
->ForceGLSLExtensionsWarn
= 1;
841 if (options
->disable_glsl_line_continuations
)
842 consts
->DisableGLSLLineContinuations
= 1;
844 if (options
->allow_glsl_extension_directive_midshader
)
845 consts
->AllowGLSLExtensionDirectiveMidShader
= GL_TRUE
;
847 consts
->MinMapBufferAlignment
=
848 screen
->get_param(screen
, PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT
);
850 if (extensions
->ARB_texture_buffer_object
) {
851 consts
->MaxTextureBufferSize
=
852 _min(screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE
),
854 consts
->TextureBufferOffsetAlignment
=
855 screen
->get_param(screen
, PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT
);
857 if (consts
->TextureBufferOffsetAlignment
)
858 extensions
->ARB_texture_buffer_range
= GL_TRUE
;
860 init_format_extensions(screen
, extensions
, tbo_rgb32
,
861 ARRAY_SIZE(tbo_rgb32
), PIPE_BUFFER
,
862 PIPE_BIND_SAMPLER_VIEW
);
865 /* Unpacking a varying in the fragment shader costs 1 texture indirection.
866 * If the number of available texture indirections is very limited, then we
867 * prefer to disable varying packing rather than run the risk of varying
868 * packing preventing a shader from running.
870 if (screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
871 PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS
) <= 8) {
872 /* We can't disable varying packing if transform feedback is available,
873 * because transform feedback code assumes a packed varying layout.
875 if (!extensions
->EXT_transform_feedback
)
876 consts
->DisableVaryingPacking
= GL_TRUE
;
879 consts
->MaxViewports
= screen
->get_param(screen
, PIPE_CAP_MAX_VIEWPORTS
);
880 if (consts
->MaxViewports
>= 16) {
881 if (glsl_feature_level
>= 400) {
882 consts
->ViewportBounds
.Min
= -32768.0;
883 consts
->ViewportBounds
.Max
= 32767.0;
885 consts
->ViewportBounds
.Min
= -16384.0;
886 consts
->ViewportBounds
.Max
= 16383.0;
888 extensions
->ARB_viewport_array
= GL_TRUE
;
889 extensions
->ARB_fragment_layer_viewport
= GL_TRUE
;
890 if (extensions
->AMD_vertex_shader_layer
)
891 extensions
->AMD_vertex_shader_viewport_index
= GL_TRUE
;
894 /* GL_ARB_ES3_compatibility.
896 * Assume that ES3 is supported if GLSL 3.30 is supported.
897 * (OpenGL 3.3 is a requirement for that extension.)
899 if (consts
->GLSLVersion
>= 330 &&
900 /* Requirements for ETC2 emulation. */
901 screen
->is_format_supported(screen
, PIPE_FORMAT_R8G8B8A8_UNORM
,
903 PIPE_BIND_SAMPLER_VIEW
) &&
904 screen
->is_format_supported(screen
, PIPE_FORMAT_B8G8R8A8_SRGB
,
906 PIPE_BIND_SAMPLER_VIEW
) &&
907 screen
->is_format_supported(screen
, PIPE_FORMAT_R16_UNORM
,
909 PIPE_BIND_SAMPLER_VIEW
) &&
910 screen
->is_format_supported(screen
, PIPE_FORMAT_R16G16_UNORM
,
912 PIPE_BIND_SAMPLER_VIEW
) &&
913 screen
->is_format_supported(screen
, PIPE_FORMAT_R16_SNORM
,
915 PIPE_BIND_SAMPLER_VIEW
) &&
916 screen
->is_format_supported(screen
, PIPE_FORMAT_R16G16_SNORM
,
918 PIPE_BIND_SAMPLER_VIEW
)) {
919 extensions
->ARB_ES3_compatibility
= GL_TRUE
;
922 if (screen
->get_video_param
&&
923 screen
->get_video_param(screen
, PIPE_VIDEO_PROFILE_UNKNOWN
,
924 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
925 PIPE_VIDEO_CAP_SUPPORTS_INTERLACED
)) {
926 extensions
->NV_vdpau_interop
= GL_TRUE
;
929 if (screen
->get_shader_param(screen
, PIPE_SHADER_VERTEX
,
930 PIPE_SHADER_CAP_DOUBLES
) &&
931 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
932 PIPE_SHADER_CAP_DOUBLES
)) {
933 extensions
->ARB_gpu_shader_fp64
= GL_TRUE
;
934 extensions
->ARB_vertex_attrib_64bit
= GL_TRUE
;