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