1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * Copyright (c) 2008 VMware, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL 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.
26 *
27 **************************************************************************/
28
29 #include "main/imports.h"
30 #include "main/context.h"
31 #include "main/macros.h"
32 #include "main/version.h"
33
34 #include "pipe/p_context.h"
35 #include "pipe/p_defines.h"
36 #include "pipe/p_screen.h"
37 #include "util/u_math.h"
38
39 #include "st_context.h"
40 #include "st_debug.h"
41 #include "st_extensions.h"
42 #include "st_format.h"
43
44
45 /*
46 * Note: we use these function rather than the MIN2, MAX2, CLAMP macros to
47 * avoid evaluating arguments (which are often function calls) more than once.
48 */
49
_min(unsigned a,unsigned b)50 static unsigned _min(unsigned a, unsigned b)
51 {
52 return (a < b) ? a : b;
53 }
54
_maxf(float a,float b)55 static float _maxf(float a, float b)
56 {
57 return (a > b) ? a : b;
58 }
59
_clamp(int a,int min,int max)60 static int _clamp(int a, int min, int max)
61 {
62 if (a < min)
63 return min;
64 else if (a > max)
65 return max;
66 else
67 return a;
68 }
69
70
71 /**
72 * Query driver to get implementation limits.
73 * Note that we have to limit/clamp against Mesa's internal limits too.
74 */
st_init_limits(struct pipe_screen * screen,struct gl_constants * c,struct gl_extensions * extensions,gl_api api)75 void st_init_limits(struct pipe_screen *screen,
76 struct gl_constants *c, struct gl_extensions *extensions,
77 gl_api api)
78 {
79 int supported_irs;
80 unsigned sh;
81 boolean can_ubo = TRUE;
82 int temp;
83 bool ssbo_atomic = true;
84
85 c->MaxTextureLevels
86 = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
87 MAX_TEXTURE_LEVELS);
88
89 c->Max3DTextureLevels
90 = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS),
91 MAX_3D_TEXTURE_LEVELS);
92
93 c->MaxCubeTextureLevels
94 = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS),
95 MAX_CUBE_TEXTURE_LEVELS);
96
97 c->MaxTextureRectSize
98 = _min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE);
99
100 c->MaxArrayTextureLayers
101 = screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS);
102
103 /* Define max viewport size and max renderbuffer size in terms of
104 * max texture size (note: max tex RECT size = max tex 2D size).
105 * If this isn't true for some hardware we'll need new PIPE_CAP_ queries.
106 */
107 c->MaxViewportWidth =
108 c->MaxViewportHeight =
109 c->MaxRenderbufferSize = c->MaxTextureRectSize;
110
111 c->ViewportSubpixelBits =
112 screen->get_param(screen, PIPE_CAP_VIEWPORT_SUBPIXEL_BITS);
113
114 c->MaxDrawBuffers = c->MaxColorAttachments =
115 _clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
116 1, MAX_DRAW_BUFFERS);
117
118 c->MaxDualSourceDrawBuffers =
119 _clamp(screen->get_param(screen,
120 PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS),
121 0, MAX_DRAW_BUFFERS);
122
123 c->MaxLineWidth =
124 _maxf(1.0f, screen->get_paramf(screen, PIPE_CAPF_MAX_LINE_WIDTH));
125 c->MaxLineWidthAA =
126 _maxf(1.0f, screen->get_paramf(screen, PIPE_CAPF_MAX_LINE_WIDTH_AA));
127
128 c->MaxPointSize =
129 _maxf(1.0f, screen->get_paramf(screen, PIPE_CAPF_MAX_POINT_WIDTH));
130 c->MaxPointSizeAA =
131 _maxf(1.0f, screen->get_paramf(screen, PIPE_CAPF_MAX_POINT_WIDTH_AA));
132
133 /* these are not queryable. Note that GL basically mandates a 1.0 minimum
134 * for non-aa sizes, but we can go down to 0.0 for aa points.
135 */
136 c->MinPointSize = 1.0f;
137 c->MinPointSizeAA = 0.0f;
138
139 c->MaxTextureMaxAnisotropy =
140 _maxf(2.0f,
141 screen->get_paramf(screen, PIPE_CAPF_MAX_TEXTURE_ANISOTROPY));
142
143 c->MaxTextureLodBias =
144 screen->get_paramf(screen, PIPE_CAPF_MAX_TEXTURE_LOD_BIAS);
145
146 c->QuadsFollowProvokingVertexConvention =
147 screen->get_param(screen,
148 PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION);
149
150 c->MaxUniformBlockSize =
151 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
152 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE);
153 if (c->MaxUniformBlockSize < 16384) {
154 can_ubo = FALSE;
155 }
156
157 for (sh = 0; sh < PIPE_SHADER_TYPES; ++sh) {
158 struct gl_shader_compiler_options *options;
159 struct gl_program_constants *pc;
160
161 switch (sh) {
162 case PIPE_SHADER_FRAGMENT:
163 pc = &c->Program[MESA_SHADER_FRAGMENT];
164 options = &c->ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
165 break;
166 case PIPE_SHADER_VERTEX:
167 pc = &c->Program[MESA_SHADER_VERTEX];
168 options = &c->ShaderCompilerOptions[MESA_SHADER_VERTEX];
169 break;
170 case PIPE_SHADER_GEOMETRY:
171 pc = &c->Program[MESA_SHADER_GEOMETRY];
172 options = &c->ShaderCompilerOptions[MESA_SHADER_GEOMETRY];
173 break;
174 case PIPE_SHADER_TESS_CTRL:
175 pc = &c->Program[MESA_SHADER_TESS_CTRL];
176 options = &c->ShaderCompilerOptions[MESA_SHADER_TESS_CTRL];
177 break;
178 case PIPE_SHADER_TESS_EVAL:
179 pc = &c->Program[MESA_SHADER_TESS_EVAL];
180 options = &c->ShaderCompilerOptions[MESA_SHADER_TESS_EVAL];
181 break;
182 case PIPE_SHADER_COMPUTE:
183 pc = &c->Program[MESA_SHADER_COMPUTE];
184 options = &c->ShaderCompilerOptions[MESA_SHADER_COMPUTE];
185
186 if (!screen->get_param(screen, PIPE_CAP_COMPUTE))
187 continue;
188 supported_irs =
189 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUPPORTED_IRS);
190 if (!(supported_irs & (1 << PIPE_SHADER_IR_TGSI)))
191 continue;
192 break;
193 default:
194 assert(0);
195 }
196
197 pc->MaxTextureImageUnits =
198 _min(screen->get_shader_param(screen, sh,
199 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS),
200 MAX_TEXTURE_IMAGE_UNITS);
201
202 pc->MaxInstructions =
203 pc->MaxNativeInstructions =
204 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
205 pc->MaxAluInstructions =
206 pc->MaxNativeAluInstructions =
207 screen->get_shader_param(screen, sh,
208 PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS);
209 pc->MaxTexInstructions =
210 pc->MaxNativeTexInstructions =
211 screen->get_shader_param(screen, sh,
212 PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS);
213 pc->MaxTexIndirections =
214 pc->MaxNativeTexIndirections =
215 screen->get_shader_param(screen, sh,
216 PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS);
217 pc->MaxAttribs =
218 pc->MaxNativeAttribs =
219 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INPUTS);
220 pc->MaxTemps =
221 pc->MaxNativeTemps =
222 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEMPS);
223 pc->MaxAddressRegs =
224 pc->MaxNativeAddressRegs = sh == PIPE_SHADER_VERTEX ? 1 : 0;
225 pc->MaxParameters =
226 pc->MaxNativeParameters =
227 screen->get_shader_param(screen, sh,
228 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE) / sizeof(float[4]);
229 pc->MaxInputComponents =
230 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INPUTS) * 4;
231 pc->MaxOutputComponents =
232 screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_OUTPUTS) * 4;
233
234 pc->MaxUniformComponents =
235 4 * MIN2(pc->MaxNativeParameters, MAX_UNIFORMS);
236
237 pc->MaxUniformBlocks =
238 screen->get_shader_param(screen, sh,
239 PIPE_SHADER_CAP_MAX_CONST_BUFFERS);
240 if (pc->MaxUniformBlocks)
241 pc->MaxUniformBlocks -= 1; /* The first one is for ordinary uniforms. */
242 pc->MaxUniformBlocks = _min(pc->MaxUniformBlocks, MAX_UNIFORM_BUFFERS);
243
244 pc->MaxCombinedUniformComponents = (pc->MaxUniformComponents +
245 c->MaxUniformBlockSize / 4 *
246 pc->MaxUniformBlocks);
247
248 temp = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS);
249 if (temp) {
250 /*
251 * for separate atomic counters get the actual hw limits
252 * per stage on atomic counters and buffers
253 */
254 ssbo_atomic = false;
255 pc->MaxAtomicCounters = temp;
256 pc->MaxAtomicBuffers = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS);
257 pc->MaxShaderStorageBlocks = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_SHADER_BUFFERS);
258 } else {
259 pc->MaxAtomicCounters = MAX_ATOMIC_COUNTERS;
260 pc->MaxAtomicBuffers = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_SHADER_BUFFERS) / 2;
261 pc->MaxShaderStorageBlocks = pc->MaxAtomicBuffers;
262 }
263 pc->MaxImageUniforms = screen->get_shader_param(
264 screen, sh, PIPE_SHADER_CAP_MAX_SHADER_IMAGES);
265
266 /* Gallium doesn't really care about local vs. env parameters so use the
267 * same limits.
268 */
269 pc->MaxLocalParams = MIN2(pc->MaxParameters, MAX_PROGRAM_LOCAL_PARAMS);
270 pc->MaxEnvParams = MIN2(pc->MaxParameters, MAX_PROGRAM_ENV_PARAMS);
271
272 if (screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_INTEGERS)) {
273 pc->LowInt.RangeMin = 31;
274 pc->LowInt.RangeMax = 30;
275 pc->LowInt.Precision = 0;
276 pc->MediumInt = pc->HighInt = pc->LowInt;
277 }
278
279 /* TODO: make these more fine-grained if anyone needs it */
280 options->MaxIfDepth =
281 screen->get_shader_param(screen, sh,
282 PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
283 options->EmitNoLoops =
284 !screen->get_shader_param(screen, sh,
285 PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
286 options->EmitNoMainReturn =
287 !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
288
289 options->EmitNoCont =
290 !screen->get_shader_param(screen, sh,
291 PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED);
292
293 options->EmitNoIndirectInput =
294 !screen->get_shader_param(screen, sh,
295 PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR);
296 options->EmitNoIndirectOutput =
297 !screen->get_shader_param(screen, sh,
298 PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR);
299 options->EmitNoIndirectTemp =
300 !screen->get_shader_param(screen, sh,
301 PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR);
302 options->EmitNoIndirectUniform =
303 !screen->get_shader_param(screen, sh,
304 PIPE_SHADER_CAP_INDIRECT_CONST_ADDR);
305
306 if (pc->MaxNativeInstructions &&
307 (options->EmitNoIndirectUniform || pc->MaxUniformBlocks < 12)) {
308 can_ubo = FALSE;
309 }
310
311 if (options->EmitNoLoops)
312 options->MaxUnrollIterations =
313 MIN2(screen->get_shader_param(screen, sh,
314 PIPE_SHADER_CAP_MAX_INSTRUCTIONS),
315 65536);
316 else
317 options->MaxUnrollIterations =
318 screen->get_shader_param(screen, sh,
319 PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT);
320
321 options->LowerCombinedClipCullDistance = true;
322 options->LowerBufferInterfaceBlocks = true;
323 }
324
325 c->GLSLOptimizeConservatively =
326 screen->get_param(screen, PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY);
327 c->LowerTessLevel = true;
328 c->LowerCsDerivedVariables = true;
329 c->PrimitiveRestartForPatches =
330 screen->get_param(screen, PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES);
331
332 c->MaxCombinedTextureImageUnits =
333 _min(c->Program[MESA_SHADER_VERTEX].MaxTextureImageUnits +
334 c->Program[MESA_SHADER_TESS_CTRL].MaxTextureImageUnits +
335 c->Program[MESA_SHADER_TESS_EVAL].MaxTextureImageUnits +
336 c->Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits +
337 c->Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits +
338 c->Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits,
339 MAX_COMBINED_TEXTURE_IMAGE_UNITS);
340
341 /* This depends on program constants. */
342 c->MaxTextureCoordUnits
343 = _min(c->Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits,
344 MAX_TEXTURE_COORD_UNITS);
345
346 c->MaxTextureUnits =
347 _min(c->Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits,
348 c->MaxTextureCoordUnits);
349
350 c->Program[MESA_SHADER_VERTEX].MaxAttribs =
351 MIN2(c->Program[MESA_SHADER_VERTEX].MaxAttribs, 16);
352
353 /* PIPE_SHADER_CAP_MAX_INPUTS for the FS specifies the maximum number
354 * of inputs. It's always 2 colors + N generic inputs. */
355 c->MaxVarying = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
356 PIPE_SHADER_CAP_MAX_INPUTS);
357 c->MaxVarying = MIN2(c->MaxVarying, MAX_VARYING);
358 c->MaxGeometryOutputVertices =
359 screen->get_param(screen, PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES);
360 c->MaxGeometryTotalOutputComponents =
361 screen->get_param(screen, PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS);
362 c->MaxTessPatchComponents =
363 MIN2(screen->get_param(screen, PIPE_CAP_MAX_SHADER_PATCH_VARYINGS),
364 MAX_VARYING) * 4;
365
366 c->MinProgramTexelOffset =
367 screen->get_param(screen, PIPE_CAP_MIN_TEXEL_OFFSET);
368 c->MaxProgramTexelOffset =
369 screen->get_param(screen, PIPE_CAP_MAX_TEXEL_OFFSET);
370
371 c->MaxProgramTextureGatherComponents =
372 screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS);
373 c->MinProgramTextureGatherOffset =
374 screen->get_param(screen, PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET);
375 c->MaxProgramTextureGatherOffset =
376 screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET);
377
378 c->MaxTransformFeedbackBuffers =
379 screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS);
380 c->MaxTransformFeedbackBuffers = MIN2(c->MaxTransformFeedbackBuffers,
381 MAX_FEEDBACK_BUFFERS);
382 c->MaxTransformFeedbackSeparateComponents =
383 screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS);
384 c->MaxTransformFeedbackInterleavedComponents =
385 screen->get_param(screen,
386 PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS);
387 c->MaxVertexStreams =
388 MAX2(1, screen->get_param(screen, PIPE_CAP_MAX_VERTEX_STREAMS));
389
390 /* The vertex stream must fit into pipe_stream_output_info::stream */
391 assert(c->MaxVertexStreams <= 4);
392
393 c->MaxVertexAttribStride
394 = screen->get_param(screen, PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE);
395
396 c->StripTextureBorder = GL_TRUE;
397
398 c->GLSLSkipStrictMaxUniformLimitCheck =
399 screen->get_param(screen, PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS);
400
401 c->UniformBufferOffsetAlignment =
402 screen->get_param(screen, PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT);
403
404 if (can_ubo) {
405 extensions->ARB_uniform_buffer_object = GL_TRUE;
406 c->MaxCombinedUniformBlocks = c->MaxUniformBufferBindings =
407 c->Program[MESA_SHADER_VERTEX].MaxUniformBlocks +
408 c->Program[MESA_SHADER_TESS_CTRL].MaxUniformBlocks +
409 c->Program[MESA_SHADER_TESS_EVAL].MaxUniformBlocks +
410 c->Program[MESA_SHADER_GEOMETRY].MaxUniformBlocks +
411 c->Program[MESA_SHADER_FRAGMENT].MaxUniformBlocks +
412 c->Program[MESA_SHADER_COMPUTE].MaxUniformBlocks;
413 assert(c->MaxCombinedUniformBlocks <= MAX_COMBINED_UNIFORM_BUFFERS);
414 }
415
416 c->GLSLFragCoordIsSysVal =
417 screen->get_param(screen, PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL);
418 c->GLSLFrontFacingIsSysVal =
419 screen->get_param(screen, PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL);
420
421 /* GL_ARB_get_program_binary
422 *
423 * The QT framework has a bug in their shader program cache, which is built
424 * on GL_ARB_get_program_binary. In an effort to allow them to fix the bug
425 * we don't enable more than 1 binary format for compatibility profiles.
426 */
427 if (api != API_OPENGL_COMPAT &&
428 screen->get_disk_shader_cache && screen->get_disk_shader_cache(screen))
429 c->NumProgramBinaryFormats = 1;
430
431 c->MaxAtomicBufferBindings =
432 c->Program[MESA_SHADER_FRAGMENT].MaxAtomicBuffers;
433
434 if (!ssbo_atomic) {
435 /* for separate atomic buffers - there atomic buffer size will be
436 limited */
437 c->MaxAtomicBufferSize = c->Program[MESA_SHADER_FRAGMENT].MaxAtomicCounters * ATOMIC_COUNTER_SIZE;
438 /* on all HW with separate atomic (evergreen) the following
439 lines are true. not sure it's worth adding CAPs for this at this
440 stage. */
441 c->MaxCombinedAtomicCounters = c->Program[MESA_SHADER_FRAGMENT].MaxAtomicCounters;
442 c->MaxCombinedAtomicBuffers = c->Program[MESA_SHADER_FRAGMENT].MaxAtomicBuffers;
443 } else {
444 c->MaxCombinedAtomicBuffers =
445 c->Program[MESA_SHADER_VERTEX].MaxAtomicBuffers +
446 c->Program[MESA_SHADER_TESS_CTRL].MaxAtomicBuffers +
447 c->Program[MESA_SHADER_TESS_EVAL].MaxAtomicBuffers +
448 c->Program[MESA_SHADER_GEOMETRY].MaxAtomicBuffers +
449 c->Program[MESA_SHADER_FRAGMENT].MaxAtomicBuffers;
450 assert(c->MaxCombinedAtomicBuffers <= MAX_COMBINED_ATOMIC_BUFFERS);
451 }
452
453 if (c->MaxCombinedAtomicBuffers > 0) {
454 extensions->ARB_shader_atomic_counters = GL_TRUE;
455 extensions->ARB_shader_atomic_counter_ops = GL_TRUE;
456 }
457
458 c->MaxCombinedShaderOutputResources = c->MaxDrawBuffers;
459 c->ShaderStorageBufferOffsetAlignment =
460 screen->get_param(screen, PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT);
461 if (c->ShaderStorageBufferOffsetAlignment) {
462 /* for hw atomic counters leaves these at default for now */
463 if (ssbo_atomic)
464 c->MaxCombinedShaderStorageBlocks = c->MaxShaderStorageBufferBindings =
465 c->MaxCombinedAtomicBuffers;
466 c->MaxCombinedShaderOutputResources +=
467 c->MaxCombinedShaderStorageBlocks;
468 c->MaxShaderStorageBlockSize = 1 << 27;
469 extensions->ARB_shader_storage_buffer_object = GL_TRUE;
470 }
471
472 c->MaxCombinedImageUniforms =
473 c->Program[MESA_SHADER_VERTEX].MaxImageUniforms +
474 c->Program[MESA_SHADER_TESS_CTRL].MaxImageUniforms +
475 c->Program[MESA_SHADER_TESS_EVAL].MaxImageUniforms +
476 c->Program[MESA_SHADER_GEOMETRY].MaxImageUniforms +
477 c->Program[MESA_SHADER_FRAGMENT].MaxImageUniforms +
478 c->Program[MESA_SHADER_COMPUTE].MaxImageUniforms;
479 c->MaxCombinedShaderOutputResources += c->MaxCombinedImageUniforms;
480 c->MaxImageUnits = MAX_IMAGE_UNITS;
481 if (c->MaxCombinedImageUniforms) {
482 extensions->ARB_shader_image_load_store = GL_TRUE;
483 extensions->ARB_shader_image_size = GL_TRUE;
484 }
485
486 /* ARB_framebuffer_no_attachments */
487 c->MaxFramebufferWidth = c->MaxViewportWidth;
488 c->MaxFramebufferHeight = c->MaxViewportHeight;
489 /* NOTE: we cheat here a little by assuming that
490 * PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS has the same
491 * number of layers as we need, although we technically
492 * could have more the generality is not really useful
493 * in practicality.
494 */
495 c->MaxFramebufferLayers =
496 screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS);
497
498 c->MaxWindowRectangles =
499 screen->get_param(screen, PIPE_CAP_MAX_WINDOW_RECTANGLES);
500
501 c->SparseBufferPageSize =
502 screen->get_param(screen, PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE);
503
504 c->AllowMappedBuffersDuringExecution =
505 screen->get_param(screen, PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION);
506
507 c->UseSTD430AsDefaultPacking =
508 screen->get_param(screen, PIPE_CAP_LOAD_CONSTBUF);
509
510 /* limit the max combined shader output resources to a driver limit */
511 temp = screen->get_param(screen, PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES);
512 if (temp > 0 && c->MaxCombinedShaderOutputResources > temp)
513 c->MaxCombinedShaderOutputResources = temp;
514 }
515
516
517 /**
518 * Given a member \c x of struct gl_extensions, return offset of
519 * \c x in bytes.
520 */
521 #define o(x) offsetof(struct gl_extensions, x)
522
523
524 struct st_extension_cap_mapping {
525 int extension_offset;
526 int cap;
527 };
528
529 struct st_extension_format_mapping {
530 int extension_offset[2];
531 enum pipe_format format[32];
532
533 /* If TRUE, at least one format must be supported for the extensions to be
534 * advertised. If FALSE, all the formats must be supported. */
535 GLboolean need_at_least_one;
536 };
537
538 /**
539 * Enable extensions if certain pipe formats are supported by the driver.
540 * What extensions will be enabled and what formats must be supported is
541 * described by the array of st_extension_format_mapping.
542 *
543 * target and bind_flags are passed to is_format_supported.
544 */
545 static void
init_format_extensions(struct pipe_screen * screen,struct gl_extensions * extensions,const struct st_extension_format_mapping * mapping,unsigned num_mappings,enum pipe_texture_target target,unsigned bind_flags)546 init_format_extensions(struct pipe_screen *screen,
547 struct gl_extensions *extensions,
548 const struct st_extension_format_mapping *mapping,
549 unsigned num_mappings,
550 enum pipe_texture_target target,
551 unsigned bind_flags)
552 {
553 GLboolean *extension_table = (GLboolean *) extensions;
554 unsigned i;
555 int j;
556 int num_formats = ARRAY_SIZE(mapping->format);
557 int num_ext = ARRAY_SIZE(mapping->extension_offset);
558
559 for (i = 0; i < num_mappings; i++) {
560 int num_supported = 0;
561
562 /* Examine each format in the list. */
563 for (j = 0; j < num_formats && mapping[i].format[j]; j++) {
564 if (screen->is_format_supported(screen, mapping[i].format[j],
565 target, 0, bind_flags)) {
566 num_supported++;
567 }
568 }
569
570 if (!num_supported ||
571 (!mapping[i].need_at_least_one && num_supported != j)) {
572 continue;
573 }
574
575 /* Enable all extensions in the list. */
576 for (j = 0; j < num_ext && mapping[i].extension_offset[j]; j++)
577 extension_table[mapping[i].extension_offset[j]] = GL_TRUE;
578 }
579 }
580
581
582 /**
583 * Given a list of formats and bind flags, return the maximum number
584 * of samples supported by any of those formats.
585 */
586 static unsigned
get_max_samples_for_formats(struct pipe_screen * screen,unsigned num_formats,const enum pipe_format * formats,unsigned max_samples,unsigned bind)587 get_max_samples_for_formats(struct pipe_screen *screen,
588 unsigned num_formats,
589 const enum pipe_format *formats,
590 unsigned max_samples,
591 unsigned bind)
592 {
593 unsigned i, f;
594
595 for (i = max_samples; i > 0; --i) {
596 for (f = 0; f < num_formats; f++) {
597 if (screen->is_format_supported(screen, formats[f],
598 PIPE_TEXTURE_2D, i, bind)) {
599 return i;
600 }
601 }
602 }
603 return 0;
604 }
605
606
607 /**
608 * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
609 * which GL extensions are supported.
610 * Quite a few extensions are always supported because they are standard
611 * features or can be built on top of other gallium features.
612 * Some fine tuning may still be needed.
613 */
st_init_extensions(struct pipe_screen * screen,struct gl_constants * consts,struct gl_extensions * extensions,struct st_config_options * options,gl_api api)614 void st_init_extensions(struct pipe_screen *screen,
615 struct gl_constants *consts,
616 struct gl_extensions *extensions,
617 struct st_config_options *options,
618 gl_api api)
619 {
620 unsigned i;
621 GLboolean *extension_table = (GLboolean *) extensions;
622
623 static const struct st_extension_cap_mapping cap_mapping[] = {
624 { o(ARB_base_instance), PIPE_CAP_START_INSTANCE },
625 { o(ARB_bindless_texture), PIPE_CAP_BINDLESS_TEXTURE },
626 { o(ARB_buffer_storage), PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT },
627 { o(ARB_clear_texture), PIPE_CAP_CLEAR_TEXTURE },
628 { o(ARB_clip_control), PIPE_CAP_CLIP_HALFZ },
629 { o(ARB_color_buffer_float), PIPE_CAP_VERTEX_COLOR_UNCLAMPED },
630 { o(ARB_conditional_render_inverted), PIPE_CAP_CONDITIONAL_RENDER_INVERTED },
631 { o(ARB_copy_image), PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS },
632 { o(OES_copy_image), PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS },
633 { o(ARB_cull_distance), PIPE_CAP_CULL_DISTANCE },
634 { o(ARB_depth_clamp), PIPE_CAP_DEPTH_CLIP_DISABLE },
635 { o(ARB_derivative_control), PIPE_CAP_TGSI_FS_FINE_DERIVATIVE },
636 { o(ARB_draw_buffers_blend), PIPE_CAP_INDEP_BLEND_FUNC },
637 { o(ARB_draw_indirect), PIPE_CAP_DRAW_INDIRECT },
638 { o(ARB_draw_instanced), PIPE_CAP_TGSI_INSTANCEID },
639 { o(ARB_framebuffer_object), PIPE_CAP_MIXED_FRAMEBUFFER_SIZES },
640 { o(ARB_gpu_shader_int64), PIPE_CAP_INT64 },
641 { o(ARB_indirect_parameters), PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS },
642 { o(ARB_instanced_arrays), PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR },
643 { o(ARB_occlusion_query), PIPE_CAP_OCCLUSION_QUERY },
644 { o(ARB_occlusion_query2), PIPE_CAP_OCCLUSION_QUERY },
645 { o(ARB_pipeline_statistics_query), PIPE_CAP_QUERY_PIPELINE_STATISTICS },
646 { o(ARB_point_sprite), PIPE_CAP_POINT_SPRITE },
647 { o(ARB_polygon_offset_clamp), PIPE_CAP_POLYGON_OFFSET_CLAMP },
648 { o(ARB_post_depth_coverage), PIPE_CAP_POST_DEPTH_COVERAGE },
649 { o(ARB_query_buffer_object), PIPE_CAP_QUERY_BUFFER_OBJECT },
650 { o(ARB_robust_buffer_access_behavior), PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR },
651 { o(ARB_sample_shading), PIPE_CAP_SAMPLE_SHADING },
652 { o(ARB_seamless_cube_map), PIPE_CAP_SEAMLESS_CUBE_MAP },
653 { o(ARB_shader_ballot), PIPE_CAP_TGSI_BALLOT },
654 { o(ARB_shader_clock), PIPE_CAP_TGSI_CLOCK },
655 { o(ARB_shader_draw_parameters), PIPE_CAP_DRAW_PARAMETERS },
656 { o(ARB_shader_group_vote), PIPE_CAP_TGSI_VOTE },
657 { o(ARB_shader_stencil_export), PIPE_CAP_SHADER_STENCIL_EXPORT },
658 { o(ARB_shader_texture_image_samples), PIPE_CAP_TGSI_TXQS },
659 { o(ARB_shader_texture_lod), PIPE_CAP_SM3 },
660 { o(ARB_sparse_buffer), PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE },
661 { o(ARB_texture_buffer_object), PIPE_CAP_TEXTURE_BUFFER_OBJECTS },
662 { o(ARB_texture_cube_map_array), PIPE_CAP_CUBE_MAP_ARRAY },
663 { o(ARB_texture_gather), PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS },
664 { o(ARB_texture_mirror_clamp_to_edge), PIPE_CAP_TEXTURE_MIRROR_CLAMP },
665 { o(ARB_texture_multisample), PIPE_CAP_TEXTURE_MULTISAMPLE },
666 { o(ARB_texture_non_power_of_two), PIPE_CAP_NPOT_TEXTURES },
667 { o(ARB_texture_query_lod), PIPE_CAP_TEXTURE_QUERY_LOD },
668 { o(ARB_texture_view), PIPE_CAP_SAMPLER_VIEW_TARGET },
669 { o(ARB_timer_query), PIPE_CAP_QUERY_TIMESTAMP },
670 { o(ARB_transform_feedback2), PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME },
671 { o(ARB_transform_feedback3), PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS },
672 { o(ARB_transform_feedback_overflow_query), PIPE_CAP_QUERY_SO_OVERFLOW },
673
674 { o(KHR_blend_equation_advanced), PIPE_CAP_TGSI_FS_FBFETCH },
675
676 { o(EXT_blend_equation_separate), PIPE_CAP_BLEND_EQUATION_SEPARATE },
677 { o(EXT_depth_bounds_test), PIPE_CAP_DEPTH_BOUNDS_TEST },
678 { o(EXT_draw_buffers2), PIPE_CAP_INDEP_BLEND_ENABLE },
679 { o(EXT_memory_object), PIPE_CAP_MEMOBJ },
680 { o(EXT_memory_object_fd), PIPE_CAP_MEMOBJ },
681 { o(EXT_texture_array), PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS },
682 { o(EXT_texture_filter_anisotropic), PIPE_CAP_ANISOTROPIC_FILTER },
683 { o(EXT_texture_mirror_clamp), PIPE_CAP_TEXTURE_MIRROR_CLAMP },
684 { o(EXT_texture_swizzle), PIPE_CAP_TEXTURE_SWIZZLE },
685 { o(EXT_transform_feedback), PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS },
686 { o(EXT_window_rectangles), PIPE_CAP_MAX_WINDOW_RECTANGLES },
687
688 { o(AMD_pinned_memory), PIPE_CAP_RESOURCE_FROM_USER_MEMORY },
689 { o(ATI_meminfo), PIPE_CAP_QUERY_MEMORY_INFO },
690 { o(AMD_seamless_cubemap_per_texture), PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE },
691 { o(ATI_texture_mirror_once), PIPE_CAP_TEXTURE_MIRROR_CLAMP },
692 { o(MESA_tile_raster_order), PIPE_CAP_TILE_RASTER_ORDER },
693 { o(NV_conditional_render), PIPE_CAP_CONDITIONAL_RENDER },
694 { o(NV_fill_rectangle), PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE },
695 { o(NV_primitive_restart), PIPE_CAP_PRIMITIVE_RESTART },
696 { o(NV_texture_barrier), PIPE_CAP_TEXTURE_BARRIER },
697 { o(NVX_gpu_memory_info), PIPE_CAP_QUERY_MEMORY_INFO },
698 /* GL_NV_point_sprite is not supported by gallium because we don't
699 * support the GL_POINT_SPRITE_R_MODE_NV option. */
700
701 { o(OES_standard_derivatives), PIPE_CAP_SM3 },
702 { o(OES_texture_float_linear), PIPE_CAP_TEXTURE_FLOAT_LINEAR },
703 { o(OES_texture_half_float_linear), PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR },
704 };
705
706 /* Required: render target and sampler support */
707 static const struct st_extension_format_mapping rendertarget_mapping[] = {
708 { { o(ARB_texture_float) },
709 { PIPE_FORMAT_R32G32B32A32_FLOAT,
710 PIPE_FORMAT_R16G16B16A16_FLOAT } },
711
712 { { o(OES_texture_float) },
713 { PIPE_FORMAT_R32G32B32A32_FLOAT } },
714
715 { { o(OES_texture_half_float) },
716 { PIPE_FORMAT_R16G16B16A16_FLOAT } },
717
718 { { o(ARB_texture_rgb10_a2ui) },
719 { PIPE_FORMAT_R10G10B10A2_UINT,
720 PIPE_FORMAT_B10G10R10A2_UINT },
721 GL_TRUE }, /* at least one format must be supported */
722
723 { { o(EXT_framebuffer_sRGB) },
724 { PIPE_FORMAT_A8B8G8R8_SRGB,
725 PIPE_FORMAT_B8G8R8A8_SRGB },
726 GL_TRUE }, /* at least one format must be supported */
727
728 { { o(EXT_packed_float) },
729 { PIPE_FORMAT_R11G11B10_FLOAT } },
730
731 { { o(EXT_texture_integer) },
732 { PIPE_FORMAT_R32G32B32A32_UINT,
733 PIPE_FORMAT_R32G32B32A32_SINT } },
734
735 { { o(ARB_texture_rg) },
736 { PIPE_FORMAT_R8_UNORM,
737 PIPE_FORMAT_R8G8_UNORM } },
738 };
739
740 /* Required: depth stencil and sampler support */
741 static const struct st_extension_format_mapping depthstencil_mapping[] = {
742 { { o(ARB_depth_buffer_float) },
743 { PIPE_FORMAT_Z32_FLOAT,
744 PIPE_FORMAT_Z32_FLOAT_S8X24_UINT } },
745 };
746
747 /* Required: sampler support */
748 static const struct st_extension_format_mapping texture_mapping[] = {
749 { { o(ARB_texture_compression_rgtc) },
750 { PIPE_FORMAT_RGTC1_UNORM,
751 PIPE_FORMAT_RGTC1_SNORM,
752 PIPE_FORMAT_RGTC2_UNORM,
753 PIPE_FORMAT_RGTC2_SNORM } },
754
755 { { o(EXT_texture_compression_latc) },
756 { PIPE_FORMAT_LATC1_UNORM,
757 PIPE_FORMAT_LATC1_SNORM,
758 PIPE_FORMAT_LATC2_UNORM,
759 PIPE_FORMAT_LATC2_SNORM } },
760
761 { { o(EXT_texture_compression_s3tc),
762 o(ANGLE_texture_compression_dxt) },
763 { PIPE_FORMAT_DXT1_RGB,
764 PIPE_FORMAT_DXT1_RGBA,
765 PIPE_FORMAT_DXT3_RGBA,
766 PIPE_FORMAT_DXT5_RGBA } },
767
768 { { o(ARB_texture_compression_bptc) },
769 { PIPE_FORMAT_BPTC_RGBA_UNORM,
770 PIPE_FORMAT_BPTC_SRGBA,
771 PIPE_FORMAT_BPTC_RGB_FLOAT,
772 PIPE_FORMAT_BPTC_RGB_UFLOAT } },
773
774 { { o(KHR_texture_compression_astc_ldr) },
775 { PIPE_FORMAT_ASTC_4x4,
776 PIPE_FORMAT_ASTC_5x4,
777 PIPE_FORMAT_ASTC_5x5,
778 PIPE_FORMAT_ASTC_6x5,
779 PIPE_FORMAT_ASTC_6x6,
780 PIPE_FORMAT_ASTC_8x5,
781 PIPE_FORMAT_ASTC_8x6,
782 PIPE_FORMAT_ASTC_8x8,
783 PIPE_FORMAT_ASTC_10x5,
784 PIPE_FORMAT_ASTC_10x6,
785 PIPE_FORMAT_ASTC_10x8,
786 PIPE_FORMAT_ASTC_10x10,
787 PIPE_FORMAT_ASTC_12x10,
788 PIPE_FORMAT_ASTC_12x12,
789 PIPE_FORMAT_ASTC_4x4_SRGB,
790 PIPE_FORMAT_ASTC_5x4_SRGB,
791 PIPE_FORMAT_ASTC_5x5_SRGB,
792 PIPE_FORMAT_ASTC_6x5_SRGB,
793 PIPE_FORMAT_ASTC_6x6_SRGB,
794 PIPE_FORMAT_ASTC_8x5_SRGB,
795 PIPE_FORMAT_ASTC_8x6_SRGB,
796 PIPE_FORMAT_ASTC_8x8_SRGB,
797 PIPE_FORMAT_ASTC_10x5_SRGB,
798 PIPE_FORMAT_ASTC_10x6_SRGB,
799 PIPE_FORMAT_ASTC_10x8_SRGB,
800 PIPE_FORMAT_ASTC_10x10_SRGB,
801 PIPE_FORMAT_ASTC_12x10_SRGB,
802 PIPE_FORMAT_ASTC_12x12_SRGB } },
803
804 { { o(EXT_texture_shared_exponent) },
805 { PIPE_FORMAT_R9G9B9E5_FLOAT } },
806
807 { { o(EXT_texture_snorm) },
808 { PIPE_FORMAT_R8G8B8A8_SNORM } },
809
810 { { o(EXT_texture_sRGB),
811 o(EXT_texture_sRGB_decode) },
812 { PIPE_FORMAT_A8B8G8R8_SRGB,
813 PIPE_FORMAT_B8G8R8A8_SRGB },
814 GL_TRUE }, /* at least one format must be supported */
815
816 { { o(EXT_texture_type_2_10_10_10_REV) },
817 { PIPE_FORMAT_R10G10B10A2_UNORM,
818 PIPE_FORMAT_B10G10R10A2_UNORM },
819 GL_TRUE }, /* at least one format must be supported */
820
821 { { o(ATI_texture_compression_3dc) },
822 { PIPE_FORMAT_LATC2_UNORM } },
823
824 { { o(MESA_ycbcr_texture) },
825 { PIPE_FORMAT_UYVY,
826 PIPE_FORMAT_YUYV },
827 GL_TRUE }, /* at least one format must be supported */
828
829 { { o(OES_compressed_ETC1_RGB8_texture) },
830 { PIPE_FORMAT_ETC1_RGB8,
831 PIPE_FORMAT_R8G8B8A8_UNORM },
832 GL_TRUE }, /* at least one format must be supported */
833
834 { { o(ARB_stencil_texturing),
835 o(ARB_texture_stencil8) },
836 { PIPE_FORMAT_X24S8_UINT,
837 PIPE_FORMAT_S8X24_UINT },
838 GL_TRUE }, /* at least one format must be supported */
839 };
840
841 /* Required: vertex fetch support. */
842 static const struct st_extension_format_mapping vertex_mapping[] = {
843 { { o(EXT_vertex_array_bgra) },
844 { PIPE_FORMAT_B8G8R8A8_UNORM } },
845 { { o(ARB_vertex_type_2_10_10_10_rev) },
846 { PIPE_FORMAT_R10G10B10A2_UNORM,
847 PIPE_FORMAT_B10G10R10A2_UNORM,
848 PIPE_FORMAT_R10G10B10A2_SNORM,
849 PIPE_FORMAT_B10G10R10A2_SNORM,
850 PIPE_FORMAT_R10G10B10A2_USCALED,
851 PIPE_FORMAT_B10G10R10A2_USCALED,
852 PIPE_FORMAT_R10G10B10A2_SSCALED,
853 PIPE_FORMAT_B10G10R10A2_SSCALED } },
854 { { o(ARB_vertex_type_10f_11f_11f_rev) },
855 { PIPE_FORMAT_R11G11B10_FLOAT } },
856 };
857
858 static const struct st_extension_format_mapping tbo_rgb32[] = {
859 { {o(ARB_texture_buffer_object_rgb32) },
860 { PIPE_FORMAT_R32G32B32_FLOAT,
861 PIPE_FORMAT_R32G32B32_UINT,
862 PIPE_FORMAT_R32G32B32_SINT,
863 } },
864 };
865
866 /*
867 * Extensions that are supported by all Gallium drivers:
868 */
869 extensions->ARB_ES2_compatibility = GL_TRUE;
870 extensions->ARB_depth_texture = GL_TRUE;
871 extensions->ARB_draw_elements_base_vertex = GL_TRUE;
872 extensions->ARB_explicit_attrib_location = GL_TRUE;
873 extensions->ARB_explicit_uniform_location = GL_TRUE;
874 extensions->ARB_fragment_coord_conventions = GL_TRUE;
875 extensions->ARB_fragment_program = GL_TRUE;
876 extensions->ARB_fragment_program_shadow = GL_TRUE;
877 extensions->ARB_fragment_shader = GL_TRUE;
878 extensions->ARB_half_float_vertex = GL_TRUE;
879 extensions->ARB_internalformat_query = GL_TRUE;
880 extensions->ARB_internalformat_query2 = GL_TRUE;
881 extensions->ARB_map_buffer_range = GL_TRUE;
882 extensions->ARB_shadow = GL_TRUE;
883 extensions->ARB_sync = GL_TRUE;
884 extensions->ARB_texture_border_clamp = GL_TRUE;
885 extensions->ARB_texture_cube_map = GL_TRUE;
886 extensions->ARB_texture_env_combine = GL_TRUE;
887 extensions->ARB_texture_env_crossbar = GL_TRUE;
888 extensions->ARB_texture_env_dot3 = GL_TRUE;
889 extensions->ARB_vertex_program = GL_TRUE;
890 extensions->ARB_vertex_shader = GL_TRUE;
891
892 extensions->EXT_blend_color = GL_TRUE;
893 extensions->EXT_blend_func_separate = GL_TRUE;
894 extensions->EXT_blend_minmax = GL_TRUE;
895 extensions->EXT_gpu_program_parameters = GL_TRUE;
896 extensions->EXT_pixel_buffer_object = GL_TRUE;
897 extensions->EXT_point_parameters = GL_TRUE;
898 extensions->EXT_provoking_vertex = GL_TRUE;
899 extensions->EXT_stencil_two_side = GL_TRUE;
900 extensions->EXT_texture_env_dot3 = GL_TRUE;
901
902 extensions->ATI_fragment_shader = GL_TRUE;
903 extensions->ATI_separate_stencil = GL_TRUE;
904 extensions->ATI_texture_env_combine3 = GL_TRUE;
905
906 extensions->MESA_pack_invert = GL_TRUE;
907
908 extensions->NV_fog_distance = GL_TRUE;
909 extensions->NV_texture_env_combine4 = GL_TRUE;
910 extensions->NV_texture_rectangle = GL_TRUE;
911
912 extensions->OES_EGL_image = GL_TRUE;
913 extensions->OES_EGL_image_external = GL_TRUE;
914 extensions->OES_draw_texture = GL_TRUE;
915
916 /* Expose the extensions which directly correspond to gallium caps. */
917 for (i = 0; i < ARRAY_SIZE(cap_mapping); i++) {
918 if (screen->get_param(screen, cap_mapping[i].cap)) {
919 extension_table[cap_mapping[i].extension_offset] = GL_TRUE;
920 }
921 }
922
923 /* Expose the extensions which directly correspond to gallium formats. */
924 init_format_extensions(screen, extensions, rendertarget_mapping,
925 ARRAY_SIZE(rendertarget_mapping), PIPE_TEXTURE_2D,
926 PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW);
927 init_format_extensions(screen, extensions, depthstencil_mapping,
928 ARRAY_SIZE(depthstencil_mapping), PIPE_TEXTURE_2D,
929 PIPE_BIND_DEPTH_STENCIL | PIPE_BIND_SAMPLER_VIEW);
930 init_format_extensions(screen, extensions, texture_mapping,
931 ARRAY_SIZE(texture_mapping), PIPE_TEXTURE_2D,
932 PIPE_BIND_SAMPLER_VIEW);
933 init_format_extensions(screen, extensions, vertex_mapping,
934 ARRAY_SIZE(vertex_mapping), PIPE_BUFFER,
935 PIPE_BIND_VERTEX_BUFFER);
936
937 /* Figure out GLSL support and set GLSLVersion to it. */
938 consts->GLSLVersion = screen->get_param(screen, PIPE_CAP_GLSL_FEATURE_LEVEL);
939
940 _mesa_override_glsl_version(consts);
941
942 if (options->force_glsl_version > 0 &&
943 options->force_glsl_version <= consts->GLSLVersion) {
944 consts->ForceGLSLVersion = options->force_glsl_version;
945 }
946
947 consts->AllowHigherCompatVersion = options->allow_higher_compat_version;
948
949 consts->ForceGLSLAbsSqrt = options->force_glsl_abs_sqrt;
950
951 consts->AllowGLSLBuiltinVariableRedeclaration = options->allow_glsl_builtin_variable_redeclaration;
952
953 consts->dri_config_options_sha1 = options->config_options_sha1;
954
955 consts->AllowGLSLCrossStageInterpolationMismatch = options->allow_glsl_cross_stage_interpolation_mismatch;
956
957 if (consts->GLSLVersion >= 400)
958 extensions->ARB_gpu_shader5 = GL_TRUE;
959 if (consts->GLSLVersion >= 410)
960 extensions->ARB_shader_precision = GL_TRUE;
961
962 /* This extension needs full OpenGL 3.2, but we don't know if that's
963 * supported at this point. Only check the GLSL version. */
964 if (consts->GLSLVersion >= 150 &&
965 screen->get_param(screen, PIPE_CAP_TGSI_VS_LAYER_VIEWPORT)) {
966 extensions->AMD_vertex_shader_layer = GL_TRUE;
967 }
968
969 if (consts->GLSLVersion >= 140) {
970 if (screen->get_param(screen, PIPE_CAP_TGSI_ARRAY_COMPONENTS))
971 extensions->ARB_enhanced_layouts = GL_TRUE;
972 }
973
974 if (consts->GLSLVersion >= 130) {
975 consts->NativeIntegers = GL_TRUE;
976 consts->MaxClipPlanes = 8;
977
978 if (screen->get_param(screen, PIPE_CAP_VERTEXID_NOBASE)) {
979 consts->VertexID_is_zero_based = GL_TRUE;
980 }
981
982 /* Extensions that either depend on GLSL 1.30 or are a subset thereof. */
983 extensions->ARB_conservative_depth = GL_TRUE;
984 extensions->ARB_shading_language_packing = GL_TRUE;
985 extensions->OES_depth_texture_cube_map = GL_TRUE;
986 extensions->ARB_shading_language_420pack = GL_TRUE;
987 extensions->ARB_texture_query_levels = GL_TRUE;
988
989 if (!options->disable_shader_bit_encoding) {
990 extensions->ARB_shader_bit_encoding = GL_TRUE;
991 }
992
993 extensions->EXT_shader_integer_mix = GL_TRUE;
994 extensions->ARB_arrays_of_arrays = GL_TRUE;
995 extensions->MESA_shader_integer_functions = GL_TRUE;
996 } else {
997 /* Optional integer support for GLSL 1.2. */
998 if (screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
999 PIPE_SHADER_CAP_INTEGERS) &&
1000 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
1001 PIPE_SHADER_CAP_INTEGERS)) {
1002 consts->NativeIntegers = GL_TRUE;
1003
1004 extensions->EXT_shader_integer_mix = GL_TRUE;
1005 }
1006
1007 /* Integer textures make no sense before GLSL 1.30 */
1008 extensions->EXT_texture_integer = GL_FALSE;
1009 }
1010
1011 consts->GLSLZeroInit = options->glsl_zero_init;
1012
1013 consts->UniformBooleanTrue = consts->NativeIntegers ? ~0U : fui(1.0f);
1014
1015 /* Below are the cases which cannot be moved into tables easily. */
1016
1017 if (screen->get_shader_param(screen, PIPE_SHADER_TESS_CTRL,
1018 PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
1019 extensions->ARB_tessellation_shader = GL_TRUE;
1020 }
1021
1022 /* What this is really checking for is the ability to support multiple
1023 * invocations of a geometry shader. There is no separate cap for that, so
1024 * we check the GLSLVersion.
1025 */
1026 if (consts->GLSLVersion >= 400 &&
1027 screen->get_shader_param(screen, PIPE_SHADER_GEOMETRY,
1028 PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
1029 extensions->OES_geometry_shader = GL_TRUE;
1030 }
1031
1032 /* Needs PIPE_CAP_SAMPLE_SHADING + all the sample-related bits of
1033 * ARB_gpu_shader5. This enables all the per-sample shading ES extensions.
1034 */
1035 extensions->OES_sample_variables = extensions->ARB_sample_shading &&
1036 extensions->ARB_gpu_shader5;
1037
1038 /* Maximum sample count. */
1039 {
1040 static const enum pipe_format color_formats[] = {
1041 PIPE_FORMAT_R8G8B8A8_UNORM,
1042 PIPE_FORMAT_B8G8R8A8_UNORM,
1043 PIPE_FORMAT_A8R8G8B8_UNORM,
1044 PIPE_FORMAT_A8B8G8R8_UNORM,
1045 };
1046 static const enum pipe_format depth_formats[] = {
1047 PIPE_FORMAT_Z16_UNORM,
1048 PIPE_FORMAT_Z24X8_UNORM,
1049 PIPE_FORMAT_X8Z24_UNORM,
1050 PIPE_FORMAT_Z32_UNORM,
1051 PIPE_FORMAT_Z32_FLOAT
1052 };
1053 static const enum pipe_format int_formats[] = {
1054 PIPE_FORMAT_R8G8B8A8_SINT
1055 };
1056 static const enum pipe_format void_formats[] = {
1057 PIPE_FORMAT_NONE
1058 };
1059
1060 consts->MaxSamples =
1061 get_max_samples_for_formats(screen, ARRAY_SIZE(color_formats),
1062 color_formats, 16,
1063 PIPE_BIND_RENDER_TARGET);
1064
1065 consts->MaxImageSamples =
1066 get_max_samples_for_formats(screen, ARRAY_SIZE(color_formats),
1067 color_formats, 16,
1068 PIPE_BIND_SHADER_IMAGE);
1069
1070 consts->MaxColorTextureSamples =
1071 get_max_samples_for_formats(screen, ARRAY_SIZE(color_formats),
1072 color_formats, consts->MaxSamples,
1073 PIPE_BIND_SAMPLER_VIEW);
1074
1075 consts->MaxDepthTextureSamples =
1076 get_max_samples_for_formats(screen, ARRAY_SIZE(depth_formats),
1077 depth_formats, consts->MaxSamples,
1078 PIPE_BIND_SAMPLER_VIEW);
1079
1080 consts->MaxIntegerSamples =
1081 get_max_samples_for_formats(screen, ARRAY_SIZE(int_formats),
1082 int_formats, consts->MaxSamples,
1083 PIPE_BIND_SAMPLER_VIEW);
1084
1085 /* ARB_framebuffer_no_attachments, assume max no. of samples 32 */
1086 consts->MaxFramebufferSamples =
1087 get_max_samples_for_formats(screen, ARRAY_SIZE(void_formats),
1088 void_formats, 32,
1089 PIPE_BIND_RENDER_TARGET);
1090 }
1091
1092 if (consts->MaxSamples >= 2) {
1093 /* Real MSAA support */
1094 extensions->EXT_framebuffer_multisample = GL_TRUE;
1095 extensions->EXT_framebuffer_multisample_blit_scaled = GL_TRUE;
1096 }
1097 else if (consts->MaxSamples > 0 &&
1098 screen->get_param(screen, PIPE_CAP_FAKE_SW_MSAA)) {
1099 /* fake MSAA support */
1100 consts->FakeSWMSAA = GL_TRUE;
1101 extensions->EXT_framebuffer_multisample = GL_TRUE;
1102 extensions->EXT_framebuffer_multisample_blit_scaled = GL_TRUE;
1103 extensions->ARB_texture_multisample = GL_TRUE;
1104 }
1105
1106 if (consts->MaxDualSourceDrawBuffers > 0 &&
1107 !options->disable_blend_func_extended)
1108 extensions->ARB_blend_func_extended = GL_TRUE;
1109
1110 if (screen->get_param(screen, PIPE_CAP_QUERY_TIME_ELAPSED) ||
1111 extensions->ARB_timer_query) {
1112 extensions->EXT_timer_query = GL_TRUE;
1113 }
1114
1115 if (extensions->ARB_transform_feedback2 &&
1116 extensions->ARB_draw_instanced) {
1117 extensions->ARB_transform_feedback_instanced = GL_TRUE;
1118 }
1119 if (options->force_glsl_extensions_warn)
1120 consts->ForceGLSLExtensionsWarn = 1;
1121
1122 if (options->disable_glsl_line_continuations)
1123 consts->DisableGLSLLineContinuations = 1;
1124
1125 if (options->allow_glsl_extension_directive_midshader)
1126 consts->AllowGLSLExtensionDirectiveMidShader = GL_TRUE;
1127
1128 consts->MinMapBufferAlignment =
1129 screen->get_param(screen, PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT);
1130
1131 /* The OpenGL Compatibility profile requires arbitrary buffer swizzling. */
1132 if (api == API_OPENGL_COMPAT &&
1133 screen->get_param(screen, PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY))
1134 extensions->ARB_texture_buffer_object = GL_FALSE;
1135
1136 if (extensions->ARB_texture_buffer_object) {
1137 consts->MaxTextureBufferSize =
1138 _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE),
1139 (1u << 31) - 1);
1140 consts->TextureBufferOffsetAlignment =
1141 screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT);
1142
1143 if (consts->TextureBufferOffsetAlignment)
1144 extensions->ARB_texture_buffer_range = GL_TRUE;
1145
1146 init_format_extensions(screen, extensions, tbo_rgb32,
1147 ARRAY_SIZE(tbo_rgb32), PIPE_BUFFER,
1148 PIPE_BIND_SAMPLER_VIEW);
1149 }
1150
1151 extensions->OES_texture_buffer =
1152 extensions->ARB_texture_buffer_object &&
1153 extensions->ARB_texture_buffer_range &&
1154 extensions->ARB_texture_buffer_object_rgb32 &&
1155 extensions->ARB_shader_image_load_store;
1156
1157 /* Unpacking a varying in the fragment shader costs 1 texture indirection.
1158 * If the number of available texture indirections is very limited, then we
1159 * prefer to disable varying packing rather than run the risk of varying
1160 * packing preventing a shader from running.
1161 */
1162 if (screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
1163 PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS) <= 8) {
1164 /* We can't disable varying packing if transform feedback is available,
1165 * because transform feedback code assumes a packed varying layout.
1166 */
1167 if (!extensions->EXT_transform_feedback)
1168 consts->DisableVaryingPacking = GL_TRUE;
1169 }
1170
1171 consts->MaxViewports = screen->get_param(screen, PIPE_CAP_MAX_VIEWPORTS);
1172 if (consts->MaxViewports >= 16) {
1173 if (consts->GLSLVersion >= 400) {
1174 consts->ViewportBounds.Min = -32768.0;
1175 consts->ViewportBounds.Max = 32767.0;
1176 } else {
1177 consts->ViewportBounds.Min = -16384.0;
1178 consts->ViewportBounds.Max = 16383.0;
1179 }
1180 extensions->ARB_viewport_array = GL_TRUE;
1181 extensions->ARB_fragment_layer_viewport = GL_TRUE;
1182 if (extensions->AMD_vertex_shader_layer)
1183 extensions->AMD_vertex_shader_viewport_index = GL_TRUE;
1184 }
1185
1186 if (extensions->AMD_vertex_shader_layer &&
1187 extensions->AMD_vertex_shader_viewport_index &&
1188 screen->get_param(screen, PIPE_CAP_TGSI_TES_LAYER_VIEWPORT))
1189 extensions->ARB_shader_viewport_layer_array = GL_TRUE;
1190
1191 /* ARB_framebuffer_no_attachments */
1192 if (screen->get_param(screen, PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT) &&
1193 ((consts->MaxSamples >= 4 && consts->MaxFramebufferLayers >= 2048) ||
1194 (consts->MaxFramebufferSamples >= consts->MaxSamples &&
1195 consts->MaxFramebufferLayers >= consts->MaxArrayTextureLayers)))
1196 extensions->ARB_framebuffer_no_attachments = GL_TRUE;
1197
1198 /* GL_ARB_ES3_compatibility.
1199 *
1200 * Assume that ES3 is supported if GLSL 3.30 is supported.
1201 * (OpenGL 3.3 is a requirement for that extension.)
1202 */
1203 if (consts->GLSLVersion >= 330 &&
1204 /* Requirements for ETC2 emulation. */
1205 screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_UNORM,
1206 PIPE_TEXTURE_2D, 0,
1207 PIPE_BIND_SAMPLER_VIEW) &&
1208 screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
1209 PIPE_TEXTURE_2D, 0,
1210 PIPE_BIND_SAMPLER_VIEW) &&
1211 screen->is_format_supported(screen, PIPE_FORMAT_R16_UNORM,
1212 PIPE_TEXTURE_2D, 0,
1213 PIPE_BIND_SAMPLER_VIEW) &&
1214 screen->is_format_supported(screen, PIPE_FORMAT_R16G16_UNORM,
1215 PIPE_TEXTURE_2D, 0,
1216 PIPE_BIND_SAMPLER_VIEW) &&
1217 screen->is_format_supported(screen, PIPE_FORMAT_R16_SNORM,
1218 PIPE_TEXTURE_2D, 0,
1219 PIPE_BIND_SAMPLER_VIEW) &&
1220 screen->is_format_supported(screen, PIPE_FORMAT_R16G16_SNORM,
1221 PIPE_TEXTURE_2D, 0,
1222 PIPE_BIND_SAMPLER_VIEW)) {
1223 extensions->ARB_ES3_compatibility = GL_TRUE;
1224 }
1225
1226 #ifdef HAVE_ST_VDPAU
1227 if (screen->get_video_param &&
1228 screen->get_video_param(screen, PIPE_VIDEO_PROFILE_UNKNOWN,
1229 PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
1230 PIPE_VIDEO_CAP_SUPPORTS_INTERLACED)) {
1231 extensions->NV_vdpau_interop = GL_TRUE;
1232 }
1233 #endif
1234
1235 if (screen->get_param(screen, PIPE_CAP_DOUBLES)) {
1236 extensions->ARB_gpu_shader_fp64 = GL_TRUE;
1237 extensions->ARB_vertex_attrib_64bit = GL_TRUE;
1238 }
1239
1240 if ((ST_DEBUG & DEBUG_GREMEDY) &&
1241 screen->get_param(screen, PIPE_CAP_STRING_MARKER))
1242 extensions->GREMEDY_string_marker = GL_TRUE;
1243
1244 if (screen->get_param(screen, PIPE_CAP_COMPUTE)) {
1245 int compute_supported_irs =
1246 screen->get_shader_param(screen, PIPE_SHADER_COMPUTE,
1247 PIPE_SHADER_CAP_SUPPORTED_IRS);
1248 if (compute_supported_irs & (1 << PIPE_SHADER_IR_TGSI)) {
1249 uint64_t grid_size[3], block_size[3];
1250 uint64_t max_local_size, max_threads_per_block;
1251
1252 screen->get_compute_param(screen, PIPE_SHADER_IR_TGSI,
1253 PIPE_COMPUTE_CAP_MAX_GRID_SIZE, grid_size);
1254 screen->get_compute_param(screen, PIPE_SHADER_IR_TGSI,
1255 PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE, block_size);
1256 screen->get_compute_param(screen, PIPE_SHADER_IR_TGSI,
1257 PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK,
1258 &max_threads_per_block);
1259 screen->get_compute_param(screen, PIPE_SHADER_IR_TGSI,
1260 PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE,
1261 &max_local_size);
1262
1263 consts->MaxComputeWorkGroupInvocations = max_threads_per_block;
1264 consts->MaxComputeSharedMemorySize = max_local_size;
1265
1266 for (i = 0; i < 3; i++) {
1267 consts->MaxComputeWorkGroupCount[i] = grid_size[i];
1268 consts->MaxComputeWorkGroupSize[i] = block_size[i];
1269 }
1270
1271 extensions->ARB_compute_shader =
1272 extensions->ARB_shader_image_load_store &&
1273 extensions->ARB_shader_atomic_counters;
1274
1275 if (extensions->ARB_compute_shader) {
1276 uint64_t max_variable_threads_per_block = 0;
1277
1278 screen->get_compute_param(screen, PIPE_SHADER_IR_TGSI,
1279 PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK,
1280 &max_variable_threads_per_block);
1281
1282 for (i = 0; i < 3; i++) {
1283 /* Clamp the values to avoid having a local work group size
1284 * greater than the maximum number of invocations.
1285 */
1286 consts->MaxComputeVariableGroupSize[i] =
1287 MIN2(consts->MaxComputeWorkGroupSize[i],
1288 max_variable_threads_per_block);
1289 }
1290 consts->MaxComputeVariableGroupInvocations =
1291 max_variable_threads_per_block;
1292
1293 extensions->ARB_compute_variable_group_size =
1294 max_variable_threads_per_block > 0;
1295 }
1296 }
1297 }
1298
1299 if (extensions->EXT_texture_filter_anisotropic &&
1300 screen->get_paramf(screen, PIPE_CAPF_MAX_TEXTURE_ANISOTROPY) >= 16.0)
1301 extensions->ARB_texture_filter_anisotropic = GL_TRUE;
1302
1303 extensions->KHR_robustness = extensions->ARB_robust_buffer_access_behavior;
1304
1305 /* If we support ES 3.1, we support the ES3_1_compatibility ext. However
1306 * there's no clean way of telling whether we would support ES 3.1 from
1307 * here, so copy the condition from compute_version_es2 here. A lot of
1308 * these are redunant, but simpler to just have a (near-)exact copy here.
1309 */
1310 extensions->ARB_ES3_1_compatibility =
1311 extensions->ARB_ES3_compatibility &&
1312 extensions->ARB_arrays_of_arrays &&
1313 extensions->ARB_compute_shader &&
1314 extensions->ARB_draw_indirect &&
1315 extensions->ARB_explicit_uniform_location &&
1316 extensions->ARB_framebuffer_no_attachments &&
1317 extensions->ARB_shader_atomic_counters &&
1318 extensions->ARB_shader_image_load_store &&
1319 extensions->ARB_shader_image_size &&
1320 extensions->ARB_shader_storage_buffer_object &&
1321 extensions->ARB_shading_language_packing &&
1322 extensions->ARB_stencil_texturing &&
1323 extensions->ARB_texture_multisample &&
1324 extensions->ARB_gpu_shader5 &&
1325 extensions->EXT_shader_integer_mix;
1326
1327 extensions->OES_texture_cube_map_array =
1328 extensions->ARB_ES3_1_compatibility &&
1329 extensions->OES_geometry_shader &&
1330 extensions->ARB_texture_cube_map_array;
1331
1332 extensions->OES_viewport_array =
1333 extensions->ARB_ES3_1_compatibility &&
1334 extensions->OES_geometry_shader &&
1335 extensions->ARB_viewport_array;
1336
1337 extensions->OES_primitive_bounding_box = extensions->ARB_ES3_1_compatibility;
1338 consts->NoPrimitiveBoundingBoxOutput = true;
1339
1340 extensions->ANDROID_extension_pack_es31a =
1341 extensions->KHR_texture_compression_astc_ldr &&
1342 extensions->KHR_blend_equation_advanced &&
1343 extensions->OES_sample_variables &&
1344 extensions->ARB_shader_image_load_store &&
1345 extensions->ARB_texture_stencil8 &&
1346 extensions->ARB_texture_multisample &&
1347 extensions->OES_copy_image &&
1348 extensions->ARB_draw_buffers_blend &&
1349 extensions->OES_geometry_shader &&
1350 extensions->ARB_gpu_shader5 &&
1351 extensions->OES_primitive_bounding_box &&
1352 extensions->ARB_tessellation_shader &&
1353 extensions->ARB_texture_border_clamp &&
1354 extensions->OES_texture_buffer &&
1355 extensions->OES_texture_cube_map_array &&
1356 extensions->EXT_texture_sRGB_decode;
1357
1358 /* Same deal as for ARB_ES3_1_compatibility - this has to be computed
1359 * before overall versions are selected. Also it's actually a subset of ES
1360 * 3.2, since it doesn't require ASTC or advanced blending.
1361 */
1362 extensions->ARB_ES3_2_compatibility =
1363 extensions->ARB_ES3_1_compatibility &&
1364 extensions->KHR_robustness &&
1365 extensions->ARB_copy_image &&
1366 extensions->ARB_draw_buffers_blend &&
1367 extensions->ARB_draw_elements_base_vertex &&
1368 extensions->OES_geometry_shader &&
1369 extensions->ARB_gpu_shader5 &&
1370 extensions->ARB_sample_shading &&
1371 extensions->ARB_tessellation_shader &&
1372 extensions->ARB_texture_border_clamp &&
1373 extensions->OES_texture_buffer &&
1374 extensions->ARB_texture_cube_map_array &&
1375 extensions->ARB_texture_stencil8 &&
1376 extensions->ARB_texture_multisample;
1377 }
1378