Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "GrGLCaps.h" | 9 #include "GrGLCaps.h" |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 this->init(contextOptions, ctxInfo, glInterface); | 58 this->init(contextOptions, ctxInfo, glInterface); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void GrGLCaps::init(const GrContextOptions& contextOptions, | 61 void GrGLCaps::init(const GrContextOptions& contextOptions, |
| 62 const GrGLContextInfo& ctxInfo, | 62 const GrGLContextInfo& ctxInfo, |
| 63 const GrGLInterface* gli) { | 63 const GrGLInterface* gli) { |
| 64 GrGLStandard standard = ctxInfo.standard(); | 64 GrGLStandard standard = ctxInfo.standard(); |
| 65 GrGLVersion version = ctxInfo.version(); | 65 GrGLVersion version = ctxInfo.version(); |
| 66 | 66 |
| 67 /************************************************************************** | 67 /************************************************************************** |
| 68 * Caps specific to GrGLSLCaps | |
| 69 **************************************************************************/ | |
| 70 | |
| 71 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); | |
| 72 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration(); | |
| 73 | |
| 74 if (kGLES_GrGLStandard == standard) { | |
| 75 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) { | |
| 76 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0)); | |
| 77 glslCaps->fFBFetchSupport = true; | |
| 78 glslCaps->fFBFetchColorName = "gl_LastFragData[0]"; | |
| 79 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch "; | |
| 80 } | |
| 81 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) { | |
| 82 // Actually, we haven't seen an ES3.0 device with this extension yet , so we don't know | |
| 83 glslCaps->fFBFetchNeedsCustomOutput = false; | |
| 84 glslCaps->fFBFetchSupport = true; | |
| 85 glslCaps->fFBFetchColorName = "gl_LastFragData[0]"; | |
| 86 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch" ; | |
| 87 } | |
| 88 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) { | |
| 89 // The arm extension also requires an additional flag which we will set onResetContext | |
| 90 glslCaps->fFBFetchNeedsCustomOutput = false; | |
| 91 glslCaps->fFBFetchSupport = true; | |
| 92 glslCaps->fFBFetchColorName = "gl_LastFragColorARM"; | |
| 93 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch "; | |
| 94 } | |
| 95 glslCaps->fUsesPrecisionModifiers = true; | |
| 96 } | |
| 97 | |
| 98 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_tex ture"); | |
| 99 | |
| 100 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader | |
| 101 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor(); | |
| 102 | |
| 103 /************************************************************************** | |
| 104 * Caps specific to GrGLCaps | 68 * Caps specific to GrGLCaps |
| 105 **************************************************************************/ | 69 **************************************************************************/ |
| 106 | 70 |
| 107 if (kGLES_GrGLStandard == standard) { | 71 if (kGLES_GrGLStandard == standard) { |
| 108 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, | 72 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
| 109 &fMaxFragmentUniformVectors); | 73 &fMaxFragmentUniformVectors); |
| 110 } else { | 74 } else { |
| 111 SkASSERT(kGL_GrGLStandard == standard); | 75 SkASSERT(kGL_GrGLStandard == standard); |
| 112 GrGLint max; | 76 GrGLint max; |
| 113 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); | 77 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() || | 276 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() || |
| 313 kChromium_GrGLDriver == ctxInfo.driver(); | 277 kChromium_GrGLDriver == ctxInfo.driver(); |
| 314 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA). | 278 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA). |
| 315 fRGBA8888PixelsOpsAreSlow = isANGLE; | 279 fRGBA8888PixelsOpsAreSlow = isANGLE; |
| 316 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is s till true and | 280 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is s till true and |
| 317 // check DX11 ANGLE. | 281 // check DX11 ANGLE. |
| 318 fPartialFBOReadIsSlow = isANGLE; | 282 fPartialFBOReadIsSlow = isANGLE; |
| 319 #endif | 283 #endif |
| 320 | 284 |
| 321 /************************************************************************** | 285 /************************************************************************** |
| 322 * GrShaderCaps fields | |
| 323 **************************************************************************/ | |
| 324 | |
| 325 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli ); | |
| 326 | |
| 327 // For now these two are equivalent but we could have dst read in shader via some other method | |
| 328 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport; | |
| 329 | |
| 330 // Enable supported shader-related caps | |
| 331 if (kGL_GrGLStandard == standard) { | |
| 332 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3 , 3) || | |
| 333 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) && | |
| 334 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration()); | |
| 335 glslCaps->fShaderDerivativeSupport = true; | |
| 336 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS | |
| 337 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) && | |
| 338 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; | |
| 339 } | |
| 340 else { | |
| 341 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blen d_func_extended"); | |
| 342 | |
| 343 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0 ) || | |
| 344 ctxInfo.hasExtension("GL_OES_standard_derivatives"); | |
| 345 } | |
| 346 | |
| 347 // We need dual source blending and the ability to disable multisample in or der to support mixed | |
| 348 // samples in every corner case. | |
| 349 if (fMultisampleDisableSupport && glslCaps->fDualSourceBlendingSupport) { | |
| 350 // We understand "mixed samples" to mean the collective capability of 3 different extensions | |
| 351 glslCaps->fMixedSamplesSupport = | |
| 352 ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") && | |
| 353 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") && | |
| 354 ctxInfo.hasExtension("GL_EXT_raster_multisample"); | |
| 355 } | |
| 356 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed sample s. | |
| 357 if (kNVIDIA_GrGLDriver == ctxInfo.driver() && fShaderCaps->mixedSamplesSuppo rt()) { | |
| 358 fDiscardRenderTargetSupport = false; | |
| 359 fInvalidateFBType = kNone_InvalidateFBType; | |
| 360 } | |
| 361 glslCaps->fProgrammableSampleLocationsSupport = | |
| 362 ctxInfo.hasExtension("GL_NV_sample_locations") || | |
| 363 ctxInfo.hasExtension("GL_ARB_sample_locations"); | |
| 364 | |
| 365 | |
| 366 /************************************************************************** | |
| 367 * GrCaps fields | 286 * GrCaps fields |
| 368 **************************************************************************/ | 287 **************************************************************************/ |
| 369 | 288 |
| 370 this->initFSAASupport(ctxInfo, gli); | 289 this->initFSAASupport(ctxInfo, gli); |
| 371 this->initBlendEqationSupport(ctxInfo); | 290 this->initBlendEqationSupport(ctxInfo); |
| 372 this->initStencilFormats(ctxInfo); | 291 this->initStencilFormats(ctxInfo); |
| 373 | 292 |
| 374 if (kGL_GrGLStandard == standard) { | 293 if (kGL_GrGLStandard == standard) { |
| 375 // we could also look for GL_ATI_separate_stencil extension or | 294 // we could also look for GL_ATI_separate_stencil extension or |
| 376 // GL_EXT_stencil_two_side but they use different function signatures | 295 // GL_EXT_stencil_two_side but they use different function signatures |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 version >= GR_GL_VER(3, 2) || | 425 version >= GR_GL_VER(3, 2) || |
| 507 (ctxInfo.hasExtension("GL_ARB_draw_instanced") && | 426 (ctxInfo.hasExtension("GL_ARB_draw_instanced") && |
| 508 ctxInfo.hasExtension("GL_ARB_instanced_arrays")); | 427 ctxInfo.hasExtension("GL_ARB_instanced_arrays")); |
| 509 } else { | 428 } else { |
| 510 fSupportsInstancedDraws = | 429 fSupportsInstancedDraws = |
| 511 version >= GR_GL_VER(3, 0) || | 430 version >= GR_GL_VER(3, 0) || |
| 512 (ctxInfo.hasExtension("GL_EXT_draw_instanced") && | 431 (ctxInfo.hasExtension("GL_EXT_draw_instanced") && |
| 513 ctxInfo.hasExtension("GL_EXT_instanced_arrays")); | 432 ctxInfo.hasExtension("GL_EXT_instanced_arrays")); |
| 514 } | 433 } |
| 515 | 434 |
| 435 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); | |
| 436 | |
| 516 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport); | 437 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport); |
| 517 this->initConfigRenderableTable(ctxInfo, srgbSupport); | 438 this->initConfigRenderableTable(ctxInfo, srgbSupport); |
| 518 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps); | 439 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps); |
| 519 | 440 |
| 520 this->applyOptionsOverrides(contextOptions); | 441 this->applyOptionsOverrides(contextOptions); |
| 521 glslCaps->applyOptionsOverrides(contextOptions); | 442 glslCaps->applyOptionsOverrides(contextOptions); |
| 522 } | 443 } |
| 523 | 444 |
| 445 const char* get_glsl_version_decl_string(const GrGLContextInfo& info) { | |
| 446 switch (info.glslGeneration()) { | |
| 447 case k110_GrGLSLGeneration: | |
| 448 if (kGLES_GrGLStandard == info.standard()) { | |
| 449 // ES2s shader language is based on version 1.20 but is version | |
| 450 // 1.00 of the ES language. | |
| 451 return "#version 100\n"; | |
| 452 } else { | |
| 453 SkASSERT(kGL_GrGLStandard == info.standard()); | |
| 454 return "#version 110\n"; | |
| 455 } | |
| 456 case k130_GrGLSLGeneration: | |
| 457 SkASSERT(kGL_GrGLStandard == info.standard()); | |
| 458 return "#version 130\n"; | |
| 459 case k140_GrGLSLGeneration: | |
| 460 SkASSERT(kGL_GrGLStandard == info.standard()); | |
| 461 return "#version 140\n"; | |
| 462 case k150_GrGLSLGeneration: | |
| 463 SkASSERT(kGL_GrGLStandard == info.standard()); | |
| 464 if (info.caps()->isCoreProfile()) { | |
| 465 return "#version 150\n"; | |
| 466 } else { | |
| 467 return "#version 150 compatibility\n"; | |
| 468 } | |
| 469 case k330_GrGLSLGeneration: | |
| 470 if (kGLES_GrGLStandard == info.standard()) { | |
| 471 return "#version 300 es\n"; | |
| 472 } else { | |
| 473 SkASSERT(kGL_GrGLStandard == info.standard()); | |
| 474 if (info.caps()->isCoreProfile()) { | |
| 475 return "#version 330\n"; | |
| 476 } else { | |
| 477 return "#version 330 compatibility\n"; | |
| 478 } | |
| 479 } | |
| 480 case k310es_GrGLSLGeneration: | |
| 481 SkASSERT(kGLES_GrGLStandard == info.standard()); | |
| 482 return "#version 310 es\n"; | |
| 483 } | |
| 484 return "<no version>"; | |
| 485 } | |
| 486 | |
| 487 void GrGLCaps::initGLSL(const GrContextOptions& contextOptions, | |
| 488 const GrGLContextInfo& ctxInfo, | |
| 489 const GrGLInterface* gli) { | |
| 490 GrGLStandard standard = ctxInfo.standard(); | |
| 491 GrGLVersion version = ctxInfo.version(); | |
| 492 | |
| 493 /************************************************************************** | |
| 494 * Caps specific to GrGLSLCaps | |
| 495 **************************************************************************/ | |
| 496 | |
| 497 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); | |
| 498 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration(); | |
| 499 | |
| 500 if (kGLES_GrGLStandard == standard) { | |
| 501 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) { | |
| 502 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0)); | |
| 503 glslCaps->fFBFetchSupport = true; | |
| 504 glslCaps->fFBFetchColorName = "gl_LastFragData[0]"; | |
| 505 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch "; | |
| 506 } | |
| 507 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) { | |
| 508 // Actually, we haven't seen an ES3.0 device with this extension yet , so we don't know | |
| 509 glslCaps->fFBFetchNeedsCustomOutput = false; | |
| 510 glslCaps->fFBFetchSupport = true; | |
| 511 glslCaps->fFBFetchColorName = "gl_LastFragData[0]"; | |
| 512 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch" ; | |
| 513 } | |
| 514 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) { | |
| 515 // The arm extension also requires an additional flag which we will set onResetContext | |
| 516 glslCaps->fFBFetchNeedsCustomOutput = false; | |
| 517 glslCaps->fFBFetchSupport = true; | |
| 518 glslCaps->fFBFetchColorName = "gl_LastFragColorARM"; | |
| 519 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch "; | |
| 520 } | |
| 521 glslCaps->fUsesPrecisionModifiers = true; | |
| 522 } | |
| 523 | |
| 524 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_tex ture"); | |
| 525 | |
| 526 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader | |
| 527 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor(); | |
| 528 | |
| 529 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation er ror "Calls to any | |
| 530 // function that may require a gradient calculation inside a conditional blo ck may return | |
| 531 // undefined results". This appears to be an issue with the 'any' call since even the simple | |
| 532 // "result=black; if (any()) result=white;" code fails to compile. This issu e comes into play | |
| 533 // from our GrTextureDomain processor. | |
| 534 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.ve ndor(); | |
|
egdaniel
2015/10/21 21:32:44
These three functions here are the new parts of th
| |
| 535 | |
| 536 glslCaps->fForceHighPrecisionNDSTransform = kARM_GrGLVendor != ctxInfo.vendo r(); | |
| 537 | |
| 538 glslCaps->fVersionDeclString = get_glsl_version_decl_string(ctxInfo); | |
| 539 | |
| 540 /************************************************************************** | |
| 541 * GrShaderCaps fields | |
| 542 **************************************************************************/ | |
| 543 | |
| 544 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli ); | |
| 545 | |
| 546 // For now these two are equivalent but we could have dst read in shader via some other method | |
| 547 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport; | |
| 548 | |
| 549 // Enable supported shader-related caps | |
| 550 if (kGL_GrGLStandard == standard) { | |
| 551 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3 , 3) || | |
| 552 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) && | |
| 553 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration()); | |
| 554 glslCaps->fShaderDerivativeSupport = true; | |
| 555 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS | |
| 556 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) && | |
| 557 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; | |
| 558 } | |
| 559 else { | |
| 560 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blen d_func_extended"); | |
| 561 | |
| 562 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0 ) || | |
| 563 ctxInfo.hasExtension("GL_OES_standard_derivatives"); | |
| 564 } | |
| 565 | |
| 566 // We need dual source blending and the ability to disable multisample in or der to support mixed | |
| 567 // samples in every corner case. | |
| 568 if (fMultisampleDisableSupport && glslCaps->fDualSourceBlendingSupport) { | |
| 569 // We understand "mixed samples" to mean the collective capability of 3 different extensions | |
| 570 glslCaps->fMixedSamplesSupport = | |
| 571 ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") && | |
| 572 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") && | |
| 573 ctxInfo.hasExtension("GL_EXT_raster_multisample"); | |
| 574 } | |
| 575 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed sample s. | |
| 576 if (kNVIDIA_GrGLDriver == ctxInfo.driver() && fShaderCaps->mixedSamplesSuppo rt()) { | |
| 577 fDiscardRenderTargetSupport = false; | |
| 578 fInvalidateFBType = kNone_InvalidateFBType; | |
| 579 } | |
| 580 glslCaps->fProgrammableSampleLocationsSupport = | |
| 581 ctxInfo.hasExtension("GL_NV_sample_locations") || | |
| 582 ctxInfo.hasExtension("GL_ARB_sample_locations"); | |
| 583 | |
| 584 | |
|
bsalomon
2015/10/22 13:02:55
extra newlines?
| |
| 585 } | |
| 586 | |
| 524 bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrG LInterface* gli) { | 587 bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrG LInterface* gli) { |
| 525 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rende ring"); | 588 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rende ring"); |
| 526 | 589 |
| 527 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRenderi ng)) { | 590 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRenderi ng)) { |
| 528 return false; | 591 return false; |
| 529 } | 592 } |
| 530 | 593 |
| 531 if (kGL_GrGLStandard == ctxInfo.standard()) { | 594 if (kGL_GrGLStandard == ctxInfo.standard()) { |
| 532 if (ctxInfo.version() < GR_GL_VER(4, 3) && | 595 if (ctxInfo.version() < GR_GL_VER(4, 3) && |
| 533 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) { | 596 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) { |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1200 for (int p = 0; p < kGrSLPrecisionCount; ++p) { | 1263 for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
| 1201 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] = | 1264 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] = |
| 1202 glslCaps->fFloatPrecisions[kVerte x_GrShaderType][p]; | 1265 glslCaps->fFloatPrecisions[kVerte x_GrShaderType][p]; |
| 1203 } | 1266 } |
| 1204 } | 1267 } |
| 1205 } | 1268 } |
| 1206 | 1269 |
| 1207 | 1270 |
| 1208 | 1271 |
| 1209 | 1272 |
| OLD | NEW |