bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | |
| 9 | #include "GrGLCaps.h" |
joshualitt | b4384b9 | 2014-10-21 12:53:15 -0700 | [diff] [blame] | 10 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 11 | #include "GrGLContext.h" |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 12 | #include "glsl/GrGLSLCaps.h" |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 13 | #include "SkTSearch.h" |
bsalomon@google.com | 20f7f17 | 2013-05-17 19:05:03 +0000 | [diff] [blame] | 14 | #include "SkTSort.h" |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 15 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 16 | GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions, |
| 17 | const GrGLContextInfo& ctxInfo, |
| 18 | const GrGLInterface* glInterface) : INHERITED(contextOptions) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 19 | fVerifiedColorConfigs.reset(); |
| 20 | fStencilFormats.reset(); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 21 | fMSFBOType = kNone_MSFBOType; |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 22 | fInvalidateFBType = kNone_InvalidateFBType; |
krajcevski | 3217c4a | 2014-06-09 09:10:04 -0700 | [diff] [blame] | 23 | fLATCAlias = kLATC_LATCAlias; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 24 | fMapBufferType = kNone_MapBufferType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 25 | fMaxFragmentUniformVectors = 0; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 26 | fMaxVertexAttributes = 0; |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 27 | fMaxFragmentTextureUnits = 0; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 28 | fRGBA8RenderbufferSupport = false; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 29 | fBGRAIsInternalFormat = false; |
| 30 | fTextureSwizzleSupport = false; |
| 31 | fUnpackRowLengthSupport = false; |
| 32 | fUnpackFlipYSupport = false; |
| 33 | fPackRowLengthSupport = false; |
| 34 | fPackFlipYSupport = false; |
| 35 | fTextureUsageSupport = false; |
| 36 | fTexStorageSupport = false; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 37 | fTextureRedSupport = false; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 38 | fImagingSupport = false; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 39 | fTwoFormatLimit = false; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 40 | fFragCoordsConventionSupport = false; |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 41 | fVertexArrayObjectSupport = false; |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 42 | fInstancedDrawingSupport = false; |
| 43 | fDirectStateAccessSupport = false; |
| 44 | fDebugSupport = false; |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 45 | fES2CompatibilitySupport = false; |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 46 | fMultisampleDisableSupport = false; |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 47 | fUseNonVBOVertexAndIndexDynamicData = false; |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 48 | fIsCoreProfile = false; |
joshualitt | c1f56b5 | 2015-06-22 12:31:31 -0700 | [diff] [blame] | 49 | fBindFragDataLocationSupport = false; |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 50 | fSRGBWriteControl = false; |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 51 | fRGBA8888PixelsOpsAreSlow = false; |
| 52 | fPartialFBOReadIsSlow = false; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 53 | |
| 54 | fReadPixelsSupportedCache.reset(); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 55 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 56 | fShaderCaps.reset(new GrGLSLCaps(contextOptions)); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 57 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 58 | this->init(contextOptions, ctxInfo, glInterface); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 59 | } |
| 60 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 61 | void GrGLCaps::init(const GrContextOptions& contextOptions, |
| 62 | const GrGLContextInfo& ctxInfo, |
| 63 | const GrGLInterface* gli) { |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 64 | GrGLStandard standard = ctxInfo.standard(); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 65 | GrGLVersion version = ctxInfo.version(); |
| 66 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 67 | /************************************************************************** |
| 68 | * Caps specific to GrGLCaps |
| 69 | **************************************************************************/ |
| 70 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 71 | if (kGLES_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 72 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
| 73 | &fMaxFragmentUniformVectors); |
| 74 | } else { |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 75 | SkASSERT(kGL_GrGLStandard == standard); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 76 | GrGLint max; |
| 77 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); |
| 78 | fMaxFragmentUniformVectors = max / 4; |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 79 | if (version >= GR_GL_VER(3, 2)) { |
| 80 | GrGLint profileMask; |
| 81 | GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); |
| 82 | fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); |
| 83 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 84 | } |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 85 | GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes); |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 86 | GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 87 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 88 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 89 | fRGBA8RenderbufferSupport = true; |
| 90 | } else { |
commit-bot@chromium.org | c5dffe4 | 2013-08-20 15:25:21 +0000 | [diff] [blame] | 91 | fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) || |
| 92 | ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 93 | ctxInfo.hasExtension("GL_ARM_rgba8"); |
| 94 | } |
| 95 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 96 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 97 | fTextureSwizzleSupport = version >= GR_GL_VER(3,3) || |
| 98 | ctxInfo.hasExtension("GL_ARB_texture_swizzle"); |
| 99 | } else { |
commit-bot@chromium.org | 6364b5e | 2013-08-20 20:22:52 +0000 | [diff] [blame] | 100 | fTextureSwizzleSupport = version >= GR_GL_VER(3,0); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 101 | } |
| 102 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 103 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 104 | fUnpackRowLengthSupport = true; |
| 105 | fUnpackFlipYSupport = false; |
| 106 | fPackRowLengthSupport = true; |
| 107 | fPackFlipYSupport = false; |
| 108 | } else { |
commit-bot@chromium.org | dc3134c | 2013-08-16 16:12:23 +0000 | [diff] [blame] | 109 | fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) || |
| 110 | ctxInfo.hasExtension("GL_EXT_unpack_subimage"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 111 | fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy"); |
commit-bot@chromium.org | dc3134c | 2013-08-16 16:12:23 +0000 | [diff] [blame] | 112 | fPackRowLengthSupport = version >= GR_GL_VER(3,0) || |
| 113 | ctxInfo.hasExtension("GL_NV_pack_subimage"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 114 | fPackFlipYSupport = |
| 115 | ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order"); |
| 116 | } |
| 117 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 118 | fTextureUsageSupport = (kGLES_GrGLStandard == standard) && |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 119 | ctxInfo.hasExtension("GL_ANGLE_texture_usage"); |
| 120 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 121 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 7a434a2 | 2013-08-21 14:01:56 +0000 | [diff] [blame] | 122 | // The EXT version can apply to either GL or GLES. |
| 123 | fTexStorageSupport = version >= GR_GL_VER(4,2) || |
| 124 | ctxInfo.hasExtension("GL_ARB_texture_storage") || |
| 125 | ctxInfo.hasExtension("GL_EXT_texture_storage"); |
| 126 | } else { |
| 127 | // Qualcomm Adreno drivers appear to have issues with texture storage. |
| 128 | fTexStorageSupport = (version >= GR_GL_VER(3,0) && |
| 129 | kQualcomm_GrGLVendor != ctxInfo.vendor()) || |
| 130 | ctxInfo.hasExtension("GL_EXT_texture_storage"); |
| 131 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 132 | |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 133 | if (kGL_GrGLStandard == standard) { |
| 134 | fTextureBarrierSupport = version >= GR_GL_VER(4,5) || |
| 135 | ctxInfo.hasExtension("GL_ARB_texture_barrier") || |
| 136 | ctxInfo.hasExtension("GL_NV_texture_barrier"); |
| 137 | } else { |
| 138 | fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier"); |
| 139 | } |
| 140 | |
hendrikw | a0d5ad7 | 2014-12-02 07:30:30 -0800 | [diff] [blame] | 141 | // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED |
| 142 | // and GL_RG on FBO textures. |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 143 | if (kMesa_GrGLDriver != ctxInfo.driver()) { |
hendrikw | a0d5ad7 | 2014-12-02 07:30:30 -0800 | [diff] [blame] | 144 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 145 | fTextureRedSupport = version >= GR_GL_VER(3,0) || |
| 146 | ctxInfo.hasExtension("GL_ARB_texture_rg"); |
hendrikw | a0d5ad7 | 2014-12-02 07:30:30 -0800 | [diff] [blame] | 147 | } else { |
| 148 | fTextureRedSupport = version >= GR_GL_VER(3,0) || |
| 149 | ctxInfo.hasExtension("GL_EXT_texture_rg"); |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 150 | } |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 151 | } |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 152 | fImagingSupport = kGL_GrGLStandard == standard && |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 153 | ctxInfo.hasExtension("GL_ARB_imaging"); |
| 154 | |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 155 | // ES 2 only guarantees RGBA/uchar + one other format/type combo for |
| 156 | // ReadPixels. The other format has to checked at run-time since it |
| 157 | // can change based on which render target is bound |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 158 | fTwoFormatLimit = kGLES_GrGLStandard == standard; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 159 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 160 | // We only enable srgb support if both textures and FBOs support srgb. |
| 161 | bool srgbSupport = false; |
| 162 | if (kGL_GrGLStandard == standard) { |
| 163 | if (ctxInfo.version() >= GR_GL_VER(3,0)) { |
| 164 | srgbSupport = true; |
| 165 | } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) { |
| 166 | if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") || |
| 167 | ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) { |
| 168 | srgbSupport = true; |
| 169 | } |
| 170 | } |
| 171 | // All the above srgb extensions support toggling srgb writes |
| 172 | fSRGBWriteControl = srgbSupport; |
| 173 | } else { |
bsalomon | 58b4395 | 2015-07-30 16:27:50 -0700 | [diff] [blame] | 174 | // See http://skbug.com/4148 for PowerVR issue. |
| 175 | srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() && |
| 176 | (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB")); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 177 | // ES through 3.1 requires EXT_srgb_write_control to support toggling |
| 178 | // sRGB writing for destinations. |
| 179 | fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control"); |
| 180 | } |
| 181 | |
rmistry | 63a9f84 | 2014-10-17 06:07:08 -0700 | [diff] [blame] | 182 | // Frag Coords Convention support is not part of ES |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 183 | // Known issue on at least some Intel platforms: |
| 184 | // http://code.google.com/p/skia/issues/detail?id=946 |
rmistry | 63a9f84 | 2014-10-17 06:07:08 -0700 | [diff] [blame] | 185 | if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) { |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 186 | fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration || |
| 187 | ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"); |
| 188 | } |
| 189 | |
bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 190 | // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with |
| 191 | // frequently changing VBOs. We've measured a performance increase using non-VBO vertex |
| 192 | // data for dynamic content on these GPUs. Perhaps we should read the renderer string and |
| 193 | // limit this decision to specific GPU families rather than basing it on the vendor alone. |
| 194 | if (!GR_GL_MUST_USE_VBO && |
bsalomon | ed82c4e | 2014-09-02 07:54:47 -0700 | [diff] [blame] | 195 | (kARM_GrGLVendor == ctxInfo.vendor() || |
| 196 | kImagination_GrGLVendor == ctxInfo.vendor() || |
| 197 | kQualcomm_GrGLVendor == ctxInfo.vendor())) { |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 198 | fUseNonVBOVertexAndIndexDynamicData = true; |
| 199 | } |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 200 | |
egdaniel | 9250d24 | 2015-05-18 13:04:26 -0700 | [diff] [blame] | 201 | // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand. |
| 202 | // Thus we are blacklisting this extension for now on Adreno4xx devices. |
| 203 | if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() && |
| 204 | ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) || |
| 205 | (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) || |
| 206 | ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) { |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 207 | fDiscardRenderTargetSupport = true; |
| 208 | fInvalidateFBType = kInvalidate_InvalidateFBType; |
| 209 | } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) { |
| 210 | fDiscardRenderTargetSupport = true; |
| 211 | fInvalidateFBType = kDiscard_InvalidateFBType; |
| 212 | } |
robertphillips@google.com | a6ffb58 | 2013-04-29 16:50:17 +0000 | [diff] [blame] | 213 | |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 214 | if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) { |
| 215 | fFullClearIsFree = true; |
| 216 | } |
| 217 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 218 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 219 | fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
tomhudson | 612e926 | 2014-11-24 11:22:36 -0800 | [diff] [blame] | 220 | ctxInfo.hasExtension("GL_ARB_vertex_array_object") || |
| 221 | ctxInfo.hasExtension("GL_APPLE_vertex_array_object"); |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 222 | } else { |
commit-bot@chromium.org | 2276c01 | 2013-08-16 15:53:33 +0000 | [diff] [blame] | 223 | fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
| 224 | ctxInfo.hasExtension("GL_OES_vertex_array_object"); |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 225 | } |
| 226 | |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 227 | if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3,2)) || |
| 228 | (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0))) { |
| 229 | fInstancedDrawingSupport = true; |
| 230 | } else { |
| 231 | fInstancedDrawingSupport = (ctxInfo.hasExtension("GL_ARB_draw_instanced") || |
| 232 | ctxInfo.hasExtension("GL_EXT_draw_instanced")) && |
| 233 | (ctxInfo.hasExtension("GL_ARB_instanced_arrays") || |
| 234 | ctxInfo.hasExtension("GL_EXT_instanced_arrays")); |
| 235 | } |
| 236 | |
| 237 | if (kGL_GrGLStandard == standard) { |
| 238 | fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access"); |
| 239 | } else { |
| 240 | fDirectStateAccessSupport = false; |
| 241 | } |
| 242 | |
| 243 | if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) { |
| 244 | fDebugSupport = true; |
| 245 | } else { |
| 246 | fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug"); |
| 247 | } |
| 248 | |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 249 | if (kGL_GrGLStandard == standard) { |
| 250 | fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility"); |
| 251 | } |
| 252 | else { |
| 253 | fES2CompatibilitySupport = true; |
| 254 | } |
| 255 | |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 256 | if (kGL_GrGLStandard == standard) { |
| 257 | fMultisampleDisableSupport = true; |
| 258 | } else { |
kkinnunen | bf49e46 | 2015-07-30 22:43:52 -0700 | [diff] [blame] | 259 | fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility"); |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 260 | } |
| 261 | |
kkinnunen | d94708e | 2015-07-30 22:47:04 -0700 | [diff] [blame] | 262 | if (kGL_GrGLStandard == standard) { |
| 263 | if (version >= GR_GL_VER(3, 0)) { |
| 264 | fBindFragDataLocationSupport = true; |
| 265 | } |
| 266 | } else { |
| 267 | if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) { |
| 268 | fBindFragDataLocationSupport = true; |
| 269 | } |
joshualitt | c1f56b5 | 2015-06-22 12:31:31 -0700 | [diff] [blame] | 270 | } |
| 271 | |
joshualitt | 7bdd70a | 2015-10-01 06:28:11 -0700 | [diff] [blame] | 272 | fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location"); |
| 273 | |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 274 | #ifdef SK_BUILD_FOR_WIN |
| 275 | // We're assuming that on Windows Chromium we're using ANGLE. |
| 276 | bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() || |
| 277 | kChromium_GrGLDriver == ctxInfo.driver(); |
| 278 | // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA). |
| 279 | fRGBA8888PixelsOpsAreSlow = isANGLE; |
| 280 | // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and |
| 281 | // check DX11 ANGLE. |
| 282 | fPartialFBOReadIsSlow = isANGLE; |
| 283 | #endif |
| 284 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 285 | /************************************************************************** |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 286 | * GrCaps fields |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 287 | **************************************************************************/ |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 288 | |
| 289 | this->initFSAASupport(ctxInfo, gli); |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 290 | this->initBlendEqationSupport(ctxInfo); |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 291 | this->initStencilFormats(ctxInfo); |
| 292 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 293 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 294 | // we could also look for GL_ATI_separate_stencil extension or |
| 295 | // GL_EXT_stencil_two_side but they use different function signatures |
| 296 | // than GL2.0+ (and than each other). |
| 297 | fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0)); |
| 298 | // supported on GL 1.4 and higher or by extension |
| 299 | fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) || |
| 300 | ctxInfo.hasExtension("GL_EXT_stencil_wrap"); |
| 301 | } else { |
| 302 | // ES 2 has two sided stencil and stencil wrap |
| 303 | fTwoSidedStencilSupport = true; |
| 304 | fStencilWrapOpsSupport = true; |
| 305 | } |
| 306 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 307 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 308 | fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO |
| 309 | // extension includes glMapBuffer. |
| 310 | if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) { |
| 311 | fMapBufferFlags |= kSubset_MapFlag; |
| 312 | fMapBufferType = kMapBufferRange_MapBufferType; |
| 313 | } else { |
| 314 | fMapBufferType = kMapBuffer_MapBufferType; |
| 315 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 316 | } else { |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 317 | // Unextended GLES2 doesn't have any buffer mapping. |
| 318 | fMapBufferFlags = kNone_MapBufferType; |
| 319 | if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) { |
| 320 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 321 | fMapBufferType = kChromium_MapBufferType; |
| 322 | } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) { |
| 323 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 324 | fMapBufferType = kMapBufferRange_MapBufferType; |
| 325 | } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) { |
| 326 | fMapBufferFlags = kCanMap_MapFlag; |
| 327 | fMapBufferType = kMapBuffer_MapBufferType; |
| 328 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 329 | } |
| 330 | |
joshualitt | e5b74c6 | 2015-06-01 14:17:47 -0700 | [diff] [blame] | 331 | // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the |
| 332 | // threshold to the maximum unless the client gives us a hint that map memory is cheap. |
| 333 | if (fGeometryBufferMapThreshold < 0) { |
bsalomon | bc23375 | 2015-06-26 11:38:25 -0700 | [diff] [blame] | 334 | // We think mapping on Chromium will be cheaper once we know ahead of time how much space |
| 335 | // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using |
| 336 | // a small subset. |
| 337 | #if 0 |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 338 | fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32; |
bsalomon | bc23375 | 2015-06-26 11:38:25 -0700 | [diff] [blame] | 339 | #else |
| 340 | fGeometryBufferMapThreshold = SK_MaxS32; |
| 341 | #endif |
joshualitt | e5b74c6 | 2015-06-01 14:17:47 -0700 | [diff] [blame] | 342 | } |
| 343 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 344 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 345 | SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) || |
| 346 | ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")); |
| 347 | fNPOTTextureTileSupport = true; |
| 348 | fMipMapSupport = true; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 349 | } else { |
| 350 | // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only |
commit-bot@chromium.org | 22dd6b9 | 2013-08-16 18:13:48 +0000 | [diff] [blame] | 351 | // ES3 has no limitations. |
| 352 | fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) || |
| 353 | ctxInfo.hasExtension("GL_OES_texture_npot"); |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 354 | // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP |
| 355 | // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently, |
| 356 | // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to |
| 357 | // to alllow arbitrary wrap modes, however. |
| 358 | fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot"); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 359 | } |
| 360 | |
bsalomon | e72bd02 | 2015-10-26 07:33:03 -0700 | [diff] [blame^] | 361 | // Using MIPs on this GPU seems to be a source of trouble. |
| 362 | if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) { |
| 363 | fMipMapSupport = false; |
| 364 | } |
| 365 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 366 | GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize); |
| 367 | GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize); |
| 368 | // Our render targets are always created with textures as the color |
| 369 | // attachment, hence this min: |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 370 | fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 371 | |
bsalomon | c59a1df | 2015-06-01 07:13:42 -0700 | [diff] [blame] | 372 | // This GPU seems to have problems when tiling small textures |
| 373 | if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) { |
| 374 | fMinTextureSize = 16; |
| 375 | } |
| 376 | |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 377 | fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker"); |
| 378 | |
robertphillips@google.com | 8995b7b | 2013-11-01 15:03:34 +0000 | [diff] [blame] | 379 | // Disable scratch texture reuse on Mali and Adreno devices |
| 380 | fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() && |
| 381 | kQualcomm_GrGLVendor != ctxInfo.vendor(); |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 382 | |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 383 | #if 0 |
| 384 | fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() && |
| 385 | kQualcomm_GrGLVendor != ctxInfo.vendor(); |
| 386 | #endif |
| 387 | |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 388 | if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 389 | GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount); |
| 390 | } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) { |
| 391 | GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount); |
| 392 | } |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 393 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 394 | if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() || |
bsalomon | e702d97 | 2015-01-29 10:07:32 -0800 | [diff] [blame] | 395 | kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() || |
bsalomon | a8fcea0 | 2015-02-13 09:00:39 -0800 | [diff] [blame] | 396 | kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) { |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 397 | fUseDrawInsteadOfClear = true; |
| 398 | } |
| 399 | |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 400 | if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) { |
| 401 | fUseDrawInsteadOfPartialRenderTargetWrite = true; |
| 402 | } |
| 403 | |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 404 | #ifdef SK_BUILD_FOR_WIN |
| 405 | // On ANGLE deferring flushes can lead to GPU starvation |
| 406 | fPreferVRAMUseOverFlushes = !isANGLE; |
| 407 | #endif |
| 408 | |
bsalomon | 7dea7b7 | 2015-08-19 08:26:51 -0700 | [diff] [blame] | 409 | if (kChromium_GrGLDriver == ctxInfo.driver()) { |
| 410 | fMustClearUploadedBufferData = true; |
| 411 | } |
| 412 | |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 413 | if (kGL_GrGLStandard == standard) { |
| 414 | // ARB allows mixed size FBO attachments, EXT does not. |
| 415 | if (ctxInfo.version() >= GR_GL_VER(3, 0) || |
| 416 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
| 417 | fOversizedStencilSupport = true; |
| 418 | } else { |
| 419 | SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object")); |
| 420 | } |
| 421 | } else { |
| 422 | // ES 3.0 supports mixed size FBO attachments, 2.0 does not. |
| 423 | fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0); |
| 424 | } |
| 425 | |
joshualitt | 5800155 | 2015-06-26 12:46:36 -0700 | [diff] [blame] | 426 | if (kGL_GrGLStandard == standard) { |
| 427 | // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about |
| 428 | // instanced arrays, but we could make this more granular if we wanted |
| 429 | fSupportsInstancedDraws = |
| 430 | version >= GR_GL_VER(3, 2) || |
| 431 | (ctxInfo.hasExtension("GL_ARB_draw_instanced") && |
| 432 | ctxInfo.hasExtension("GL_ARB_instanced_arrays")); |
| 433 | } else { |
| 434 | fSupportsInstancedDraws = |
| 435 | version >= GR_GL_VER(3, 0) || |
| 436 | (ctxInfo.hasExtension("GL_EXT_draw_instanced") && |
| 437 | ctxInfo.hasExtension("GL_EXT_instanced_arrays")); |
| 438 | } |
| 439 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 440 | // Must init GLSLCaps after setting GLCaps |
| 441 | this->initGLSL(contextOptions, ctxInfo, gli); |
| 442 | GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); |
| 443 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 444 | this->initConfigTexturableTable(ctxInfo, gli, srgbSupport); |
| 445 | this->initConfigRenderableTable(ctxInfo, srgbSupport); |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 446 | this->initShaderPrecisionTable(ctxInfo, gli, glslCaps); |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 447 | |
| 448 | this->applyOptionsOverrides(contextOptions); |
| 449 | glslCaps->applyOptionsOverrides(contextOptions); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 450 | } |
| 451 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 452 | const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation, |
| 453 | bool isCoreProfile) { |
| 454 | switch (generation) { |
| 455 | case k110_GrGLSLGeneration: |
| 456 | if (kGLES_GrGLStandard == standard) { |
| 457 | // ES2s shader language is based on version 1.20 but is version |
| 458 | // 1.00 of the ES language. |
| 459 | return "#version 100\n"; |
| 460 | } else { |
| 461 | SkASSERT(kGL_GrGLStandard == standard); |
| 462 | return "#version 110\n"; |
| 463 | } |
| 464 | case k130_GrGLSLGeneration: |
| 465 | SkASSERT(kGL_GrGLStandard == standard); |
| 466 | return "#version 130\n"; |
| 467 | case k140_GrGLSLGeneration: |
| 468 | SkASSERT(kGL_GrGLStandard == standard); |
| 469 | return "#version 140\n"; |
| 470 | case k150_GrGLSLGeneration: |
| 471 | SkASSERT(kGL_GrGLStandard == standard); |
| 472 | if (isCoreProfile) { |
| 473 | return "#version 150\n"; |
| 474 | } else { |
| 475 | return "#version 150 compatibility\n"; |
| 476 | } |
| 477 | case k330_GrGLSLGeneration: |
| 478 | if (kGLES_GrGLStandard == standard) { |
| 479 | return "#version 300 es\n"; |
| 480 | } else { |
| 481 | SkASSERT(kGL_GrGLStandard == standard); |
| 482 | if (isCoreProfile) { |
| 483 | return "#version 330\n"; |
| 484 | } else { |
| 485 | return "#version 330 compatibility\n"; |
| 486 | } |
| 487 | } |
| 488 | case k310es_GrGLSLGeneration: |
| 489 | SkASSERT(kGLES_GrGLStandard == standard); |
| 490 | return "#version 310 es\n"; |
| 491 | } |
| 492 | return "<no version>"; |
| 493 | } |
| 494 | |
| 495 | void GrGLCaps::initGLSL(const GrContextOptions& contextOptions, |
| 496 | const GrGLContextInfo& ctxInfo, |
| 497 | const GrGLInterface* gli) { |
| 498 | GrGLStandard standard = ctxInfo.standard(); |
| 499 | GrGLVersion version = ctxInfo.version(); |
| 500 | |
| 501 | /************************************************************************** |
| 502 | * Caps specific to GrGLSLCaps |
| 503 | **************************************************************************/ |
| 504 | |
| 505 | GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); |
| 506 | glslCaps->fGLSLGeneration = ctxInfo.glslGeneration(); |
| 507 | |
| 508 | if (kGLES_GrGLStandard == standard) { |
| 509 | if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) { |
| 510 | glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0)); |
| 511 | glslCaps->fFBFetchSupport = true; |
| 512 | glslCaps->fFBFetchColorName = "gl_LastFragData[0]"; |
| 513 | glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch"; |
| 514 | } |
| 515 | else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) { |
| 516 | // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know |
| 517 | glslCaps->fFBFetchNeedsCustomOutput = false; |
| 518 | glslCaps->fFBFetchSupport = true; |
| 519 | glslCaps->fFBFetchColorName = "gl_LastFragData[0]"; |
| 520 | glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch"; |
| 521 | } |
| 522 | else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) { |
| 523 | // The arm extension also requires an additional flag which we will set onResetContext |
| 524 | glslCaps->fFBFetchNeedsCustomOutput = false; |
| 525 | glslCaps->fFBFetchSupport = true; |
| 526 | glslCaps->fFBFetchColorName = "gl_LastFragColorARM"; |
| 527 | glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch"; |
| 528 | } |
| 529 | glslCaps->fUsesPrecisionModifiers = true; |
| 530 | } |
| 531 | |
| 532 | glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture"); |
| 533 | |
| 534 | // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader |
| 535 | glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor(); |
| 536 | |
| 537 | // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any |
| 538 | // function that may require a gradient calculation inside a conditional block may return |
| 539 | // undefined results". This appears to be an issue with the 'any' call since even the simple |
| 540 | // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play |
| 541 | // from our GrTextureDomain processor. |
| 542 | glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor(); |
| 543 | |
egdaniel | cae0085 | 2015-10-22 11:08:08 -0700 | [diff] [blame] | 544 | glslCaps->fForceHighPrecisionNDSTransform = kARM_GrGLVendor == ctxInfo.vendor() || |
| 545 | kPowerVR54x_GrGLRenderer == ctxInfo.renderer(); |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 546 | |
| 547 | glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration, |
| 548 | fIsCoreProfile); |
| 549 | |
| 550 | /************************************************************************** |
| 551 | * GrShaderCaps fields |
| 552 | **************************************************************************/ |
| 553 | |
| 554 | glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli); |
| 555 | |
| 556 | // For now these two are equivalent but we could have dst read in shader via some other method |
| 557 | glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport; |
| 558 | |
| 559 | // Enable supported shader-related caps |
| 560 | if (kGL_GrGLStandard == standard) { |
| 561 | glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) || |
| 562 | ctxInfo.hasExtension("GL_ARB_blend_func_extended")) && |
| 563 | GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration()); |
| 564 | glslCaps->fShaderDerivativeSupport = true; |
| 565 | // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS |
| 566 | glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) && |
| 567 | ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; |
| 568 | } |
| 569 | else { |
| 570 | glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended"); |
| 571 | |
| 572 | glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) || |
| 573 | ctxInfo.hasExtension("GL_OES_standard_derivatives"); |
| 574 | } |
| 575 | |
| 576 | // We need dual source blending and the ability to disable multisample in order to support mixed |
| 577 | // samples in every corner case. |
| 578 | if (fMultisampleDisableSupport && glslCaps->fDualSourceBlendingSupport) { |
| 579 | // We understand "mixed samples" to mean the collective capability of 3 different extensions |
| 580 | glslCaps->fMixedSamplesSupport = |
| 581 | ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") && |
| 582 | ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") && |
| 583 | ctxInfo.hasExtension("GL_EXT_raster_multisample"); |
| 584 | } |
| 585 | // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples. |
| 586 | if (kNVIDIA_GrGLDriver == ctxInfo.driver() && fShaderCaps->mixedSamplesSupport()) { |
| 587 | fDiscardRenderTargetSupport = false; |
| 588 | fInvalidateFBType = kNone_InvalidateFBType; |
| 589 | } |
| 590 | glslCaps->fProgrammableSampleLocationsSupport = |
| 591 | ctxInfo.hasExtension("GL_NV_sample_locations") || |
| 592 | ctxInfo.hasExtension("GL_ARB_sample_locations"); |
| 593 | } |
| 594 | |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 595 | bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 596 | bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering"); |
| 597 | |
| 598 | if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) { |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 599 | return false; |
| 600 | } |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 601 | |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 602 | if (kGL_GrGLStandard == ctxInfo.standard()) { |
| 603 | if (ctxInfo.version() < GR_GL_VER(4, 3) && |
| 604 | !ctxInfo.hasExtension("GL_ARB_program_interface_query")) { |
| 605 | return false; |
| 606 | } |
| 607 | } else { |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 608 | if (!hasChromiumPathRendering && |
| 609 | ctxInfo.version() < GR_GL_VER(3, 1)) { |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 610 | return false; |
| 611 | } |
| 612 | } |
| 613 | // We only support v1.3+ of GL_NV_path_rendering which allows us to |
| 614 | // set individual fragment inputs with ProgramPathFragmentInputGen. The API |
| 615 | // additions are detected by checking the existence of the function. |
| 616 | // We also use *Then* functions that not all drivers might have. Check |
| 617 | // them for consistency. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 618 | if (nullptr == gli->fFunctions.fStencilThenCoverFillPath || |
| 619 | nullptr == gli->fFunctions.fStencilThenCoverStrokePath || |
| 620 | nullptr == gli->fFunctions.fStencilThenCoverFillPathInstanced || |
| 621 | nullptr == gli->fFunctions.fStencilThenCoverStrokePathInstanced || |
| 622 | nullptr == gli->fFunctions.fProgramPathFragmentInputGen) { |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 623 | return false; |
| 624 | } |
| 625 | return true; |
| 626 | } |
| 627 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 628 | void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo, bool srgbSupport) { |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 629 | // OpenGL < 3.0 |
| 630 | // no support for render targets unless the GL_ARB_framebuffer_object |
| 631 | // extension is supported (in which case we get ALPHA, RED, RG, RGB, |
| 632 | // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we |
| 633 | // probably don't get R8 in this case. |
| 634 | |
| 635 | // OpenGL 3.0 |
| 636 | // base color renderable: ALPHA, RED, RG, RGB, and RGBA |
| 637 | // sized derivatives: ALPHA8, R8, RGBA4, RGBA8 |
| 638 | |
| 639 | // >= OpenGL 3.1 |
| 640 | // base color renderable: RED, RG, RGB, and RGBA |
| 641 | // sized derivatives: R8, RGBA4, RGBA8 |
| 642 | // if the GL_ARB_compatibility extension is supported then we get back |
| 643 | // support for GL_ALPHA and ALPHA8 |
| 644 | |
| 645 | // GL_EXT_bgra adds BGRA render targets to any version |
| 646 | |
| 647 | // ES 2.0 |
| 648 | // color renderable: RGBA4, RGB5_A1, RGB565 |
| 649 | // GL_EXT_texture_rg adds support for R8 as a color render target |
| 650 | // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8 |
| 651 | // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support |
| 652 | |
| 653 | // ES 3.0 |
| 654 | // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called |
| 655 | // below already account for this). |
| 656 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 657 | GrGLStandard standard = ctxInfo.standard(); |
| 658 | |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 659 | enum { |
| 660 | kNo_MSAA = 0, |
| 661 | kYes_MSAA = 1, |
| 662 | }; |
| 663 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 664 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 665 | // Post 3.0 we will get R8 |
| 666 | // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object) |
| 667 | if (ctxInfo.version() >= GR_GL_VER(3,0) || |
| 668 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 669 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true; |
| 670 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 671 | } |
| 672 | } else { |
| 673 | // On ES we can only hope for R8 |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 674 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport; |
| 675 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 676 | } |
| 677 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 678 | if (kGL_GrGLStandard != standard) { |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 679 | // only available in ES |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 680 | fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true; |
| 681 | fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | // we no longer support 444 as a render target |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 685 | fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false; |
| 686 | fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 687 | |
| 688 | if (this->fRGBA8RenderbufferSupport) { |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 689 | fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true; |
commit-bot@chromium.org | da3d69c | 2013-10-28 15:09:13 +0000 | [diff] [blame] | 690 | fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 691 | } |
| 692 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 693 | if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) { |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 694 | fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true; |
| 695 | // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of |
| 696 | // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample. |
commit-bot@chromium.org | 4256d24 | 2013-10-17 16:29:41 +0000 | [diff] [blame] | 697 | // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms. |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame] | 698 | if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) { |
commit-bot@chromium.org | 4256d24 | 2013-10-17 16:29:41 +0000 | [diff] [blame] | 699 | fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true; |
| 700 | } else { |
| 701 | fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = |
| 702 | !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers(); |
| 703 | } |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 704 | } |
| 705 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 706 | if (this->fRGBA8RenderbufferSupport && srgbSupport) { |
| 707 | fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true; |
| 708 | fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true; |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 709 | } |
| 710 | |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 711 | if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) { |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 712 | if (kGL_GrGLStandard == standard) { |
jvanverth | a60b2ea | 2014-12-12 05:58:06 -0800 | [diff] [blame] | 713 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 714 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true; |
| 715 | } else { |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 716 | // for now we only enable this on desktop, because on ES we'd have to solve many |
| 717 | // precision issues and no clients actually want this yet |
| 718 | /* |
jvanverth | a60b2ea | 2014-12-12 05:58:06 -0800 | [diff] [blame] | 719 | if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) { |
| 720 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true; |
| 721 | } else { |
| 722 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false; |
| 723 | } |
| 724 | // for now we don't support floating point MSAA on ES |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 725 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/ |
| 726 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false; |
jvanverth | fb5df43 | 2015-05-21 08:12:27 -0700 | [diff] [blame] | 727 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 728 | } |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 729 | } |
| 730 | |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 731 | if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) { |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 732 | if (kGL_GrGLStandard == standard) { |
jvanverth | a60b2ea | 2014-12-12 05:58:06 -0800 | [diff] [blame] | 733 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 734 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true; |
jvanverth | 1334c21 | 2014-12-18 05:44:55 -0800 | [diff] [blame] | 735 | } else if (ctxInfo.version() >= GR_GL_VER(3,0)) { |
| 736 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true; |
| 737 | // for now we don't support floating point MSAA on ES |
| 738 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 739 | } else { |
jvanverth | 1334c21 | 2014-12-18 05:44:55 -0800 | [diff] [blame] | 740 | if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) { |
| 741 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true; |
| 742 | } else { |
| 743 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false; |
| 744 | } |
| 745 | // for now we don't support floating point MSAA on ES |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 746 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false; |
| 747 | } |
| 748 | } |
| 749 | |
jvanverth | fb5df43 | 2015-05-21 08:12:27 -0700 | [diff] [blame] | 750 | if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) { |
| 751 | if (kGL_GrGLStandard == standard) { |
| 752 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true; |
| 753 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true; |
| 754 | } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) { |
| 755 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true; |
| 756 | // for now we don't support floating point MSAA on ES |
| 757 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false; |
| 758 | } else { |
| 759 | if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) { |
| 760 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true; |
| 761 | } else { |
| 762 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false; |
| 763 | } |
| 764 | // for now we don't support floating point MSAA on ES |
| 765 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false; |
| 766 | } |
| 767 | } |
| 768 | |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 769 | // If we don't support MSAA then undo any places above where we set a config as renderable with |
| 770 | // msaa. |
| 771 | if (kNone_MSFBOType == fMSFBOType) { |
| 772 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 773 | fConfigRenderSupport[i][kYes_MSAA] = false; |
| 774 | } |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 775 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 776 | } |
| 777 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 778 | void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, |
| 779 | bool srgbSupport) { |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 780 | GrGLStandard standard = ctxInfo.standard(); |
| 781 | GrGLVersion version = ctxInfo.version(); |
| 782 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 783 | // Base texture support |
| 784 | fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true; |
| 785 | fConfigTextureSupport[kRGB_565_GrPixelConfig] = true; |
| 786 | fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true; |
| 787 | fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true; |
| 788 | |
reed | 56f38fb | 2015-09-14 09:09:00 -0700 | [diff] [blame] | 789 | // Disable this for now, while we investigate skbug.com/4333 |
| 790 | if (false) { |
| 791 | // Check for 8-bit palette.. |
| 792 | GrGLint numFormats; |
| 793 | GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); |
| 794 | if (numFormats) { |
| 795 | SkAutoSTMalloc<10, GrGLint> formats(numFormats); |
| 796 | GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats); |
| 797 | for (int i = 0; i < numFormats; ++i) { |
| 798 | if (GR_GL_PALETTE8_RGBA8 == formats[i]) { |
| 799 | fConfigTextureSupport[kIndex_8_GrPixelConfig] = true; |
| 800 | break; |
| 801 | } |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | // Check for BGRA |
| 807 | if (kGL_GrGLStandard == standard) { |
| 808 | fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = |
| 809 | version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra"); |
| 810 | } else { |
| 811 | if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) { |
| 812 | fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true; |
| 813 | } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) { |
| 814 | fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true; |
| 815 | fBGRAIsInternalFormat = true; |
| 816 | } |
| 817 | SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] || |
| 818 | kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig); |
| 819 | } |
| 820 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 821 | fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = srgbSupport; |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 822 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 823 | // Compressed texture support |
| 824 | |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 825 | // glCompressedTexImage2D is available on all OpenGL ES devices... |
| 826 | // however, it is only available on standard OpenGL after version 1.3 |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 827 | bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3)); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 828 | |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 829 | fCompressedTexSubImageSupport = |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 830 | hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D); |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 831 | |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 832 | // Check for ETC1 |
| 833 | bool hasETC1 = false; |
| 834 | |
| 835 | // First check version for support |
| 836 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 837 | hasETC1 = hasCompressTex2D && |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 838 | (version >= GR_GL_VER(4, 3) || |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 839 | ctxInfo.hasExtension("GL_ARB_ES3_compatibility")); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 840 | } else { |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 841 | hasETC1 = hasCompressTex2D && |
| 842 | (version >= GR_GL_VER(3, 0) || |
| 843 | ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") || |
| 844 | // ETC2 is a superset of ETC1, so we can just check for that, too. |
| 845 | (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") && |
| 846 | ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 847 | } |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 848 | fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1; |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 849 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 850 | // Check for LATC under its various forms |
| 851 | LATCAlias alias = kLATC_LATCAlias; |
| 852 | bool hasLATC = hasCompressTex2D && |
| 853 | (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") || |
| 854 | ctxInfo.hasExtension("GL_NV_texture_compression_latc")); |
| 855 | |
| 856 | // Check for RGTC |
| 857 | if (!hasLATC) { |
| 858 | // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format. |
| 859 | if (kGL_GrGLStandard == standard) { |
| 860 | hasLATC = version >= GR_GL_VER(3, 0); |
| 861 | } |
| 862 | |
| 863 | if (!hasLATC) { |
| 864 | hasLATC = |
| 865 | ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") || |
| 866 | ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc"); |
| 867 | } |
| 868 | |
| 869 | if (hasLATC) { |
| 870 | alias = kRGTC_LATCAlias; |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | // Check for 3DC |
| 875 | if (!hasLATC) { |
| 876 | hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture"); |
| 877 | if (hasLATC) { |
| 878 | alias = k3DC_LATCAlias; |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC; |
| 883 | fLATCAlias = alias; |
krajcevski | 238b456 | 2014-06-30 09:09:22 -0700 | [diff] [blame] | 884 | |
krajcevski | b3abe90 | 2014-07-30 13:08:11 -0700 | [diff] [blame] | 885 | // Check for R11_EAC ... We don't support R11_EAC on desktop, as most |
| 886 | // cards default to decompressing the textures in the driver, and is |
| 887 | // generally slower. |
| 888 | if (kGL_GrGLStandard != standard) { |
krajcevski | 238b456 | 2014-06-30 09:09:22 -0700 | [diff] [blame] | 889 | fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0); |
| 890 | } |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 891 | |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 892 | // Check for ASTC |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 893 | fConfigTextureSupport[kASTC_12x12_GrPixelConfig] = |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 894 | ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") || |
| 895 | ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") || |
| 896 | ctxInfo.hasExtension("GL_OES_texture_compression_astc"); |
| 897 | |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 898 | // Check for floating point texture support |
| 899 | // NOTE: We disallow floating point textures on ES devices if linear |
| 900 | // filtering modes are not supported. This is for simplicity, but a more |
| 901 | // granular approach is possible. Coincidentally, floating point textures became part of |
| 902 | // the standard in ES3.1 / OGL 3.1, hence the shorthand |
| 903 | bool hasFPTextures = version >= GR_GL_VER(3, 1); |
| 904 | if (!hasFPTextures) { |
| 905 | hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") || |
jvanverth | a60b2ea | 2014-12-12 05:58:06 -0800 | [diff] [blame] | 906 | (ctxInfo.hasExtension("GL_OES_texture_float_linear") && |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 907 | ctxInfo.hasExtension("GL_OES_texture_float")); |
| 908 | } |
| 909 | fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 910 | |
| 911 | // Check for fp16 texture support |
| 912 | // NOTE: We disallow floating point textures on ES devices if linear |
| 913 | // filtering modes are not supported. This is for simplicity, but a more |
| 914 | // granular approach is possible. Coincidentally, 16-bit floating point textures became part of |
| 915 | // the standard in ES3.1 / OGL 3.1, hence the shorthand |
| 916 | bool hasHalfFPTextures = version >= GR_GL_VER(3, 1); |
| 917 | if (!hasHalfFPTextures) { |
| 918 | hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") || |
jvanverth | 1334c21 | 2014-12-18 05:44:55 -0800 | [diff] [blame] | 919 | (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") && |
| 920 | ctxInfo.hasExtension("GL_OES_texture_half_float")); |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 921 | } |
jvanverth | 1334c21 | 2014-12-18 05:44:55 -0800 | [diff] [blame] | 922 | fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures; |
jvanverth | fb5df43 | 2015-05-21 08:12:27 -0700 | [diff] [blame] | 923 | fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures; |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 924 | } |
| 925 | |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 926 | bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf, |
| 927 | GrGLenum format, |
| 928 | GrGLenum type) const { |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 929 | if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) { |
| 930 | // ES 2 guarantees this format is supported |
robertphillips@google.com | eca2dfb | 2012-06-27 20:13:49 +0000 | [diff] [blame] | 931 | return true; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | if (!fTwoFormatLimit) { |
| 935 | // not limited by ES 2's constraints |
| 936 | return true; |
| 937 | } |
| 938 | |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 939 | GrGLint otherFormat = GR_GL_RGBA; |
| 940 | GrGLint otherType = GR_GL_UNSIGNED_BYTE; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 941 | |
| 942 | // The other supported format/type combo supported for ReadPixels |
| 943 | // can change based on which render target is bound |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 944 | GR_GL_GetIntegerv(intf, |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 945 | GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, |
| 946 | &otherFormat); |
| 947 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 948 | GR_GL_GetIntegerv(intf, |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 949 | GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, |
| 950 | &otherType); |
| 951 | |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 952 | return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 953 | } |
| 954 | |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 955 | bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, |
| 956 | GrGLenum format, |
| 957 | GrGLenum type, |
| 958 | GrGLenum currFboFormat) const { |
mtklein | 2aa1f7e | 2015-02-20 12:35:32 -0800 | [diff] [blame] | 959 | ReadPixelsSupportedFormat key = {format, type, currFboFormat}; |
| 960 | if (const bool* supported = fReadPixelsSupportedCache.find(key)) { |
| 961 | return *supported; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 962 | } |
mtklein | 2aa1f7e | 2015-02-20 12:35:32 -0800 | [diff] [blame] | 963 | bool supported = this->doReadPixelsSupported(intf, format, type); |
| 964 | fReadPixelsSupportedCache.set(key, supported); |
| 965 | return supported; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 966 | } |
| 967 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 968 | void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 969 | |
| 970 | fMSFBOType = kNone_MSFBOType; |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 971 | if (kGL_GrGLStandard != ctxInfo.standard()) { |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 972 | // We prefer the EXT/IMG extension over ES3 MSAA because we've observed |
| 973 | // ES3 driver bugs on at least one device with a tiled GPU (N10). |
| 974 | if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { |
| 975 | fMSFBOType = kES_EXT_MsToTexture_MSFBOType; |
| 976 | } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { |
| 977 | fMSFBOType = kES_IMG_MsToTexture_MSFBOType; |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 978 | } else if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) { |
| 979 | fMSFBOType = kMixedSamples_MSFBOType; |
commit-bot@chromium.org | 92b7884 | 2014-01-16 20:49:46 +0000 | [diff] [blame] | 980 | } else if (ctxInfo.version() >= GR_GL_VER(3,0)) { |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 981 | fMSFBOType = GrGLCaps::kES_3_0_MSFBOType; |
| 982 | } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
| 983 | // chrome's extension is equivalent to the EXT msaa |
| 984 | // and fbo_blit extensions. |
| 985 | fMSFBOType = kDesktop_EXT_MSFBOType; |
| 986 | } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { |
| 987 | fMSFBOType = kES_Apple_MSFBOType; |
| 988 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 989 | } else { |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 990 | if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) { |
| 991 | fMSFBOType = kMixedSamples_MSFBOType; |
| 992 | } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 993 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 994 | fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 995 | } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && |
| 996 | ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 997 | fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 998 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 1002 | void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) { |
| 1003 | GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); |
| 1004 | |
| 1005 | // Disabling advanced blend on various platforms with major known issues. We also block Chrome |
| 1006 | // for now until its own blacklists can be updated. |
| 1007 | if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() || |
| 1008 | kIntel_GrGLDriver == ctxInfo.driver() || |
joel.liang | 9764c40 | 2015-07-09 19:46:18 -0700 | [diff] [blame] | 1009 | kChromium_GrGLDriver == ctxInfo.driver()) { |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 1010 | return; |
| 1011 | } |
| 1012 | |
| 1013 | if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) { |
| 1014 | fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport; |
| 1015 | glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction; |
| 1016 | } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) { |
| 1017 | fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport; |
| 1018 | glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction; |
| 1019 | } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() && |
| 1020 | ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) { |
| 1021 | // Non-coherent advanced blend has an issue on NVIDIA pre 337.00. |
| 1022 | return; |
| 1023 | } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) { |
| 1024 | fBlendEquationSupport = kAdvanced_BlendEquationSupport; |
| 1025 | glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction; |
| 1026 | } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) { |
| 1027 | fBlendEquationSupport = kAdvanced_BlendEquationSupport; |
| 1028 | glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction; |
| 1029 | // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is |
| 1030 | // slow on a particular platform. |
| 1031 | } else { |
| 1032 | return; // No advanced blend support. |
| 1033 | } |
| 1034 | |
| 1035 | SkASSERT(this->advancedBlendEquationSupport()); |
| 1036 | |
| 1037 | if (kNVIDIA_GrGLDriver == ctxInfo.driver()) { |
| 1038 | // Blacklist color-dodge and color-burn on NVIDIA until the fix is released. |
| 1039 | fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) | |
| 1040 | (1 << kColorBurn_GrBlendEquation); |
| 1041 | } |
joel.liang | 9764c40 | 2015-07-09 19:46:18 -0700 | [diff] [blame] | 1042 | if (kARM_GrGLVendor == ctxInfo.vendor()) { |
| 1043 | // Blacklist color-burn on ARM until the fix is released. |
| 1044 | fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation); |
| 1045 | } |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1048 | namespace { |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1049 | const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { |
| 1053 | |
| 1054 | // Build up list of legal stencil formats (though perhaps not supported on |
| 1055 | // the particular gpu/driver) from most preferred to least. |
| 1056 | |
| 1057 | // these consts are in order of most preferred to least preferred |
| 1058 | // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 |
| 1059 | |
| 1060 | static const StencilFormat |
| 1061 | // internal Format stencil bits total bits packed? |
| 1062 | gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, |
| 1063 | gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, |
| 1064 | gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, |
| 1065 | gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 1066 | // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1067 | gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; |
| 1068 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 1069 | if (kGL_GrGLStandard == ctxInfo.standard()) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1070 | bool supportsPackedDS = |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1071 | ctxInfo.version() >= GR_GL_VER(3,0) || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1072 | ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || |
| 1073 | ctxInfo.hasExtension("GL_ARB_framebuffer_object"); |
| 1074 | |
| 1075 | // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we |
| 1076 | // require FBO support we can expect these are legal formats and don't |
| 1077 | // check. These also all support the unsized GL_STENCIL_INDEX. |
| 1078 | fStencilFormats.push_back() = gS8; |
| 1079 | fStencilFormats.push_back() = gS16; |
| 1080 | if (supportsPackedDS) { |
| 1081 | fStencilFormats.push_back() = gD24S8; |
| 1082 | } |
| 1083 | fStencilFormats.push_back() = gS4; |
| 1084 | if (supportsPackedDS) { |
| 1085 | fStencilFormats.push_back() = gDS; |
| 1086 | } |
| 1087 | } else { |
| 1088 | // ES2 has STENCIL_INDEX8 without extensions but requires extensions |
| 1089 | // for other formats. |
| 1090 | // ES doesn't support using the unsized format. |
| 1091 | |
| 1092 | fStencilFormats.push_back() = gS8; |
| 1093 | //fStencilFormats.push_back() = gS16; |
commit-bot@chromium.org | 04c500f | 2013-09-06 15:28:01 +0000 | [diff] [blame] | 1094 | if (ctxInfo.version() >= GR_GL_VER(3,0) || |
| 1095 | ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1096 | fStencilFormats.push_back() = gD24S8; |
| 1097 | } |
| 1098 | if (ctxInfo.hasExtension("GL_OES_stencil4")) { |
| 1099 | fStencilFormats.push_back() = gS4; |
| 1100 | } |
| 1101 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1104 | SkString GrGLCaps::dump() const { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1105 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1106 | SkString r = INHERITED::dump(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1107 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1108 | r.appendf("--- GL-Specific ---\n"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1109 | for (int i = 0; i < fStencilFormats.count(); ++i) { |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1110 | r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1111 | i, |
| 1112 | fStencilFormats[i].fStencilBits, |
| 1113 | fStencilFormats[i].fTotalBits); |
| 1114 | } |
| 1115 | |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 1116 | static const char* kMSFBOExtStr[] = { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1117 | "None", |
| 1118 | "ARB", |
| 1119 | "EXT", |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 1120 | "ES 3.0", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1121 | "Apple", |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 1122 | "IMG MS To Texture", |
| 1123 | "EXT MS To Texture", |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 1124 | "MixedSamples", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1125 | }; |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 1126 | GR_STATIC_ASSERT(0 == kNone_MSFBOType); |
| 1127 | GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType); |
| 1128 | GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType); |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 1129 | GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType); |
| 1130 | GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType); |
| 1131 | GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType); |
| 1132 | GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType); |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 1133 | GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 1134 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1); |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 1135 | |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 1136 | static const char* kInvalidateFBTypeStr[] = { |
| 1137 | "None", |
| 1138 | "Discard", |
| 1139 | "Invalidate", |
| 1140 | }; |
| 1141 | GR_STATIC_ASSERT(0 == kNone_InvalidateFBType); |
| 1142 | GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType); |
| 1143 | GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType); |
| 1144 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1); |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 1145 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 1146 | static const char* kMapBufferTypeStr[] = { |
| 1147 | "None", |
| 1148 | "MapBuffer", |
| 1149 | "MapBufferRange", |
| 1150 | "Chromium", |
| 1151 | }; |
| 1152 | GR_STATIC_ASSERT(0 == kNone_MapBufferType); |
| 1153 | GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType); |
| 1154 | GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType); |
| 1155 | GR_STATIC_ASSERT(3 == kChromium_MapBufferType); |
| 1156 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1); |
| 1157 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1158 | r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1159 | r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]); |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 1160 | r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]); |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 1161 | r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1162 | r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); |
| 1163 | r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1164 | r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes); |
| 1165 | r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1166 | r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO")); |
| 1167 | r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO")); |
| 1168 | r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO")); |
| 1169 | r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO")); |
| 1170 | r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO")); |
| 1171 | r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO")); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1172 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1173 | r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO")); |
| 1174 | r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO")); |
| 1175 | r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); |
| 1176 | r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); |
| 1177 | r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); |
| 1178 | r.appendf("Fragment coord conventions support: %s\n", |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1179 | (fFragCoordsConventionSupport ? "YES": "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1180 | r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO")); |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 1181 | r.appendf("Instanced drawing support: %s\n", (fInstancedDrawingSupport ? "YES": "NO")); |
| 1182 | r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO")); |
| 1183 | r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO")); |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 1184 | r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1185 | r.appendf("Use non-VBO for dynamic data: %s\n", |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1186 | (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 1187 | r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO")); |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 1188 | r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO")); |
| 1189 | r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO")); |
joshualitt | 7bdd70a | 2015-10-01 06:28:11 -0700 | [diff] [blame] | 1190 | r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO")); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1191 | return r; |
| 1192 | } |
| 1193 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1194 | static GrGLenum precision_to_gl_float_type(GrSLPrecision p) { |
| 1195 | switch (p) { |
| 1196 | case kLow_GrSLPrecision: |
| 1197 | return GR_GL_LOW_FLOAT; |
| 1198 | case kMedium_GrSLPrecision: |
| 1199 | return GR_GL_MEDIUM_FLOAT; |
| 1200 | case kHigh_GrSLPrecision: |
| 1201 | return GR_GL_HIGH_FLOAT; |
| 1202 | } |
| 1203 | SkFAIL("Unknown precision."); |
| 1204 | return -1; |
| 1205 | } |
| 1206 | |
| 1207 | static GrGLenum shader_type_to_gl_shader(GrShaderType type) { |
| 1208 | switch (type) { |
| 1209 | case kVertex_GrShaderType: |
| 1210 | return GR_GL_VERTEX_SHADER; |
| 1211 | case kGeometry_GrShaderType: |
| 1212 | return GR_GL_GEOMETRY_SHADER; |
| 1213 | case kFragment_GrShaderType: |
| 1214 | return GR_GL_FRAGMENT_SHADER; |
| 1215 | } |
| 1216 | SkFAIL("Unknown shader type."); |
| 1217 | return -1; |
| 1218 | } |
| 1219 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1220 | void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, |
| 1221 | const GrGLInterface* intf, |
| 1222 | GrGLSLCaps* glslCaps) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1223 | if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) || |
| 1224 | ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) { |
| 1225 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 1226 | if (kGeometry_GrShaderType != s) { |
| 1227 | GrShaderType shaderType = static_cast<GrShaderType>(s); |
| 1228 | GrGLenum glShader = shader_type_to_gl_shader(shaderType); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1229 | GrShaderCaps::PrecisionInfo* first = nullptr; |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1230 | glslCaps->fShaderPrecisionVaries = false; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1231 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
| 1232 | GrSLPrecision precision = static_cast<GrSLPrecision>(p); |
| 1233 | GrGLenum glPrecision = precision_to_gl_float_type(precision); |
| 1234 | GrGLint range[2]; |
| 1235 | GrGLint bits; |
| 1236 | GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits); |
| 1237 | if (bits) { |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1238 | glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0]; |
| 1239 | glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1]; |
| 1240 | glslCaps->fFloatPrecisions[s][p].fBits = bits; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1241 | if (!first) { |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1242 | first = &glslCaps->fFloatPrecisions[s][p]; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1243 | } |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1244 | else if (!glslCaps->fShaderPrecisionVaries) { |
| 1245 | glslCaps->fShaderPrecisionVaries = |
| 1246 | (*first != glslCaps->fFloatPrecisions[s][p]); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | } |
| 1250 | } |
| 1251 | } |
| 1252 | } |
| 1253 | else { |
| 1254 | // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float. |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1255 | glslCaps->fShaderPrecisionVaries = false; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1256 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 1257 | if (kGeometry_GrShaderType != s) { |
| 1258 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1259 | glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127; |
| 1260 | glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127; |
| 1261 | glslCaps->fFloatPrecisions[s][p].fBits = 23; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | } |
| 1266 | // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're |
| 1267 | // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for |
| 1268 | // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that |
| 1269 | // are recommended against. |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1270 | if (glslCaps->fGeometryShaderSupport) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1271 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1272 | glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] = |
| 1273 | glslCaps->fFloatPrecisions[kVertex_GrShaderType][p]; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1274 | } |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | |
| 1279 | |
| 1280 | |