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