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 | |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 11 | #include "GrContextOptions.h" |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 12 | #include "GrGLContext.h" |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 13 | #include "GrGLRenderTarget.h" |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 14 | #include "glsl/GrGLSLCaps.h" |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 15 | #include "SkTSearch.h" |
bsalomon@google.com | 20f7f17 | 2013-05-17 19:05:03 +0000 | [diff] [blame] | 16 | #include "SkTSort.h" |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 17 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 18 | GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions, |
| 19 | const GrGLContextInfo& ctxInfo, |
| 20 | const GrGLInterface* glInterface) : INHERITED(contextOptions) { |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 21 | fStandard = ctxInfo.standard(); |
| 22 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 23 | fStencilFormats.reset(); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 24 | fMSFBOType = kNone_MSFBOType; |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 25 | fInvalidateFBType = kNone_InvalidateFBType; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 26 | fMapBufferType = kNone_MapBufferType; |
jvanverth | d7a2c1f | 2015-12-07 07:36:44 -0800 | [diff] [blame] | 27 | fTransferBufferType = kNone_TransferBufferType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 28 | fMaxFragmentUniformVectors = 0; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 29 | fMaxVertexAttributes = 0; |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 30 | fMaxFragmentTextureUnits = 0; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 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; |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 39 | fVertexArrayObjectSupport = false; |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 40 | fDirectStateAccessSupport = false; |
| 41 | fDebugSupport = false; |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 42 | fES2CompatibilitySupport = false; |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 43 | fMultisampleDisableSupport = false; |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 44 | fDrawIndirectSupport = false; |
| 45 | fMultiDrawIndirectSupport = false; |
| 46 | fBaseInstanceSupport = 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 | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 50 | fExternalTextureSupport = false; |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 51 | fRectangleTextureSupport = false; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 52 | fTextureSwizzleSupport = false; |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 53 | fSRGBWriteControl = false; |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 54 | fRGBA8888PixelsOpsAreSlow = false; |
| 55 | fPartialFBOReadIsSlow = false; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 56 | |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 57 | fBlitFramebufferSupport = kNone_BlitFramebufferSupport; |
| 58 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 59 | fShaderCaps.reset(new GrGLSLCaps(contextOptions)); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 60 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 61 | this->init(contextOptions, ctxInfo, glInterface); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 62 | } |
| 63 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 64 | void GrGLCaps::init(const GrContextOptions& contextOptions, |
| 65 | const GrGLContextInfo& ctxInfo, |
| 66 | const GrGLInterface* gli) { |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 67 | GrGLStandard standard = ctxInfo.standard(); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 68 | GrGLVersion version = ctxInfo.version(); |
| 69 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 70 | /************************************************************************** |
| 71 | * Caps specific to GrGLCaps |
| 72 | **************************************************************************/ |
| 73 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 74 | if (kGLES_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 75 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
| 76 | &fMaxFragmentUniformVectors); |
| 77 | } else { |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 78 | SkASSERT(kGL_GrGLStandard == standard); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 79 | GrGLint max; |
| 80 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); |
| 81 | fMaxFragmentUniformVectors = max / 4; |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 82 | if (version >= GR_GL_VER(3, 2)) { |
| 83 | GrGLint profileMask; |
| 84 | GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); |
| 85 | fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); |
| 86 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 87 | } |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 88 | GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes); |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 89 | GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 90 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 91 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 92 | fUnpackRowLengthSupport = true; |
| 93 | fUnpackFlipYSupport = false; |
| 94 | fPackRowLengthSupport = true; |
| 95 | fPackFlipYSupport = false; |
| 96 | } else { |
commit-bot@chromium.org | dc3134c | 2013-08-16 16:12:23 +0000 | [diff] [blame] | 97 | fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) || |
| 98 | ctxInfo.hasExtension("GL_EXT_unpack_subimage"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 99 | fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy"); |
commit-bot@chromium.org | dc3134c | 2013-08-16 16:12:23 +0000 | [diff] [blame] | 100 | fPackRowLengthSupport = version >= GR_GL_VER(3,0) || |
| 101 | ctxInfo.hasExtension("GL_NV_pack_subimage"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 102 | fPackFlipYSupport = |
| 103 | ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order"); |
| 104 | } |
| 105 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 106 | fTextureUsageSupport = (kGLES_GrGLStandard == standard) && |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 107 | ctxInfo.hasExtension("GL_ANGLE_texture_usage"); |
| 108 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 109 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 7a434a2 | 2013-08-21 14:01:56 +0000 | [diff] [blame] | 110 | // The EXT version can apply to either GL or GLES. |
| 111 | fTexStorageSupport = version >= GR_GL_VER(4,2) || |
| 112 | ctxInfo.hasExtension("GL_ARB_texture_storage") || |
| 113 | ctxInfo.hasExtension("GL_EXT_texture_storage"); |
| 114 | } else { |
| 115 | // Qualcomm Adreno drivers appear to have issues with texture storage. |
| 116 | fTexStorageSupport = (version >= GR_GL_VER(3,0) && |
| 117 | kQualcomm_GrGLVendor != ctxInfo.vendor()) || |
| 118 | ctxInfo.hasExtension("GL_EXT_texture_storage"); |
| 119 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 120 | |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 121 | if (kGL_GrGLStandard == standard) { |
| 122 | fTextureBarrierSupport = version >= GR_GL_VER(4,5) || |
| 123 | ctxInfo.hasExtension("GL_ARB_texture_barrier") || |
| 124 | ctxInfo.hasExtension("GL_NV_texture_barrier"); |
| 125 | } else { |
| 126 | fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier"); |
| 127 | } |
| 128 | |
hendrikw | a0d5ad7 | 2014-12-02 07:30:30 -0800 | [diff] [blame] | 129 | // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED |
| 130 | // and GL_RG on FBO textures. |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 131 | if (kMesa_GrGLDriver != ctxInfo.driver()) { |
hendrikw | a0d5ad7 | 2014-12-02 07:30:30 -0800 | [diff] [blame] | 132 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 133 | fTextureRedSupport = version >= GR_GL_VER(3,0) || |
| 134 | ctxInfo.hasExtension("GL_ARB_texture_rg"); |
hendrikw | a0d5ad7 | 2014-12-02 07:30:30 -0800 | [diff] [blame] | 135 | } else { |
| 136 | fTextureRedSupport = version >= GR_GL_VER(3,0) || |
| 137 | ctxInfo.hasExtension("GL_EXT_texture_rg"); |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 138 | } |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 139 | } |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 140 | fImagingSupport = kGL_GrGLStandard == standard && |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 141 | ctxInfo.hasExtension("GL_ARB_imaging"); |
| 142 | |
bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 143 | // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with |
| 144 | // frequently changing VBOs. We've measured a performance increase using non-VBO vertex |
| 145 | // data for dynamic content on these GPUs. Perhaps we should read the renderer string and |
| 146 | // limit this decision to specific GPU families rather than basing it on the vendor alone. |
| 147 | if (!GR_GL_MUST_USE_VBO && |
bsalomon | ed82c4e | 2014-09-02 07:54:47 -0700 | [diff] [blame] | 148 | (kARM_GrGLVendor == ctxInfo.vendor() || |
| 149 | kImagination_GrGLVendor == ctxInfo.vendor() || |
| 150 | kQualcomm_GrGLVendor == ctxInfo.vendor())) { |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 151 | fUseNonVBOVertexAndIndexDynamicData = true; |
| 152 | } |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 153 | |
egdaniel | 9250d24 | 2015-05-18 13:04:26 -0700 | [diff] [blame] | 154 | // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand. |
| 155 | // Thus we are blacklisting this extension for now on Adreno4xx devices. |
| 156 | if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() && |
| 157 | ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) || |
| 158 | (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) || |
| 159 | ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) { |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 160 | fDiscardRenderTargetSupport = true; |
| 161 | fInvalidateFBType = kInvalidate_InvalidateFBType; |
| 162 | } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) { |
| 163 | fDiscardRenderTargetSupport = true; |
| 164 | fInvalidateFBType = kDiscard_InvalidateFBType; |
| 165 | } |
robertphillips@google.com | a6ffb58 | 2013-04-29 16:50:17 +0000 | [diff] [blame] | 166 | |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 167 | if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) { |
| 168 | fFullClearIsFree = true; |
| 169 | } |
| 170 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 171 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 172 | fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
tomhudson | 612e926 | 2014-11-24 11:22:36 -0800 | [diff] [blame] | 173 | ctxInfo.hasExtension("GL_ARB_vertex_array_object") || |
| 174 | ctxInfo.hasExtension("GL_APPLE_vertex_array_object"); |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 175 | } else { |
commit-bot@chromium.org | 2276c01 | 2013-08-16 15:53:33 +0000 | [diff] [blame] | 176 | fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
| 177 | ctxInfo.hasExtension("GL_OES_vertex_array_object"); |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 178 | } |
| 179 | |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 180 | if (kGL_GrGLStandard == standard) { |
| 181 | fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access"); |
| 182 | } else { |
| 183 | fDirectStateAccessSupport = false; |
| 184 | } |
| 185 | |
| 186 | if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) { |
| 187 | fDebugSupport = true; |
| 188 | } else { |
| 189 | fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug"); |
| 190 | } |
| 191 | |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 192 | if (kGL_GrGLStandard == standard) { |
| 193 | fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility"); |
| 194 | } |
| 195 | else { |
| 196 | fES2CompatibilitySupport = true; |
| 197 | } |
| 198 | |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 199 | if (kGL_GrGLStandard == standard) { |
| 200 | fMultisampleDisableSupport = true; |
| 201 | } else { |
kkinnunen | bf49e46 | 2015-07-30 22:43:52 -0700 | [diff] [blame] | 202 | fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility"); |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 203 | } |
| 204 | |
kkinnunen | d94708e | 2015-07-30 22:47:04 -0700 | [diff] [blame] | 205 | if (kGL_GrGLStandard == standard) { |
| 206 | if (version >= GR_GL_VER(3, 0)) { |
| 207 | fBindFragDataLocationSupport = true; |
| 208 | } |
| 209 | } else { |
| 210 | if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) { |
| 211 | fBindFragDataLocationSupport = true; |
| 212 | } |
joshualitt | c1f56b5 | 2015-06-22 12:31:31 -0700 | [diff] [blame] | 213 | } |
| 214 | |
bsalomon | b8909d3 | 2016-01-28 07:09:52 -0800 | [diff] [blame] | 215 | #if 0 // Disabled due to https://bug.skia.org/4454 |
joshualitt | 7bdd70a | 2015-10-01 06:28:11 -0700 | [diff] [blame] | 216 | fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location"); |
bsalomon | b8909d3 | 2016-01-28 07:09:52 -0800 | [diff] [blame] | 217 | #else |
| 218 | fBindUniformLocationSupport = false; |
| 219 | #endif |
joshualitt | 7bdd70a | 2015-10-01 06:28:11 -0700 | [diff] [blame] | 220 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 221 | if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) { |
| 222 | if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) { |
| 223 | fExternalTextureSupport = true; |
| 224 | } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") || |
| 225 | ctxInfo.hasExtension("OES_EGL_image_external_essl3")) { |
| 226 | // At least one driver has been found that has this extension without the "GL_" prefix. |
| 227 | fExternalTextureSupport = true; |
| 228 | } |
| 229 | } |
| 230 | |
bsalomon | e179a91 | 2016-01-20 06:18:10 -0800 | [diff] [blame] | 231 | if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 1)) || |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 232 | ctxInfo.hasExtension("GL_ARB_texture_rectangle")) { |
bsalomon | e179a91 | 2016-01-20 06:18:10 -0800 | [diff] [blame] | 233 | // We also require textureSize() support for rectangle 2D samplers which was added in GLSL |
| 234 | // 1.40. |
| 235 | if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) { |
| 236 | fRectangleTextureSupport = true; |
| 237 | } |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 238 | } |
| 239 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 240 | if (kGL_GrGLStandard == standard) { |
| 241 | if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) { |
| 242 | fTextureSwizzleSupport = true; |
| 243 | } |
| 244 | } else { |
| 245 | if (version >= GR_GL_VER(3,0)) { |
| 246 | fTextureSwizzleSupport = true; |
| 247 | } |
| 248 | } |
| 249 | |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 250 | #ifdef SK_BUILD_FOR_WIN |
| 251 | // We're assuming that on Windows Chromium we're using ANGLE. |
| 252 | bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() || |
| 253 | kChromium_GrGLDriver == ctxInfo.driver(); |
| 254 | // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA). |
| 255 | fRGBA8888PixelsOpsAreSlow = isANGLE; |
| 256 | // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and |
| 257 | // check DX11 ANGLE. |
| 258 | fPartialFBOReadIsSlow = isANGLE; |
| 259 | #endif |
| 260 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 261 | /************************************************************************** |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 262 | * GrShaderCaps fields |
| 263 | **************************************************************************/ |
| 264 | |
egdaniel | 0a48233 | 2015-10-26 08:59:10 -0700 | [diff] [blame] | 265 | // This must be called after fCoreProfile is set on the GrGLCaps |
| 266 | this->initGLSL(ctxInfo); |
| 267 | GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); |
| 268 | |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 269 | glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli); |
| 270 | |
| 271 | // For now these two are equivalent but we could have dst read in shader via some other method. |
| 272 | // Before setting this, initGLSL() must have been called. |
| 273 | glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport; |
| 274 | |
| 275 | // Enable supported shader-related caps |
| 276 | if (kGL_GrGLStandard == standard) { |
| 277 | glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) || |
| 278 | ctxInfo.hasExtension("GL_ARB_blend_func_extended")) && |
| 279 | GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration()); |
| 280 | glslCaps->fShaderDerivativeSupport = true; |
| 281 | // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS |
| 282 | glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) && |
| 283 | ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 284 | glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) && |
| 285 | ctxInfo.glslGeneration() >= k130_GrGLSLGeneration; |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 286 | } |
| 287 | else { |
| 288 | glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended"); |
| 289 | |
| 290 | glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) || |
| 291 | ctxInfo.hasExtension("GL_OES_standard_derivatives"); |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 292 | |
| 293 | glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) && |
| 294 | ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0. |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 295 | } |
| 296 | |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 297 | if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) { |
| 298 | #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63 |
| 299 | GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT, |
| 300 | &glslCaps->fPixelLocalStorageSize); |
| 301 | glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport; |
| 302 | } |
| 303 | else { |
| 304 | glslCaps->fPixelLocalStorageSize = 0; |
| 305 | glslCaps->fPLSPathRenderingSupport = false; |
| 306 | } |
| 307 | |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 308 | /************************************************************************** |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 309 | * GrCaps fields |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 310 | **************************************************************************/ |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 311 | |
cdalton | 63f6c1f | 2015-11-06 07:09:43 -0800 | [diff] [blame] | 312 | // We need dual source blending and the ability to disable multisample in order to support mixed |
| 313 | // samples in every corner case. |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 314 | if (fMultisampleDisableSupport && |
| 315 | glslCaps->dualSourceBlendingSupport() && |
| 316 | fShaderCaps->pathRenderingSupport()) { |
| 317 | fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") || |
kkinnunen | ea40943 | 2015-12-10 01:21:59 -0800 | [diff] [blame] | 318 | ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples"); |
cdalton | 63f6c1f | 2015-11-06 07:09:43 -0800 | [diff] [blame] | 319 | // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples. |
kkinnunen | 9f63b44 | 2016-01-25 00:31:49 -0800 | [diff] [blame] | 320 | if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() || |
| 321 | kChromium_GrGLDriver == ctxInfo.driver())) { |
cdalton | 63f6c1f | 2015-11-06 07:09:43 -0800 | [diff] [blame] | 322 | fDiscardRenderTargetSupport = false; |
| 323 | fInvalidateFBType = kNone_InvalidateFBType; |
| 324 | } |
| 325 | } |
| 326 | |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 327 | // fUsesMixedSamples must be set before calling initFSAASupport. |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 328 | this->initFSAASupport(ctxInfo, gli); |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 329 | this->initBlendEqationSupport(ctxInfo); |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 330 | this->initStencilFormats(ctxInfo); |
| 331 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 332 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 333 | // we could also look for GL_ATI_separate_stencil extension or |
| 334 | // GL_EXT_stencil_two_side but they use different function signatures |
| 335 | // than GL2.0+ (and than each other). |
| 336 | fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0)); |
| 337 | // supported on GL 1.4 and higher or by extension |
| 338 | fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) || |
| 339 | ctxInfo.hasExtension("GL_EXT_stencil_wrap"); |
| 340 | } else { |
| 341 | // ES 2 has two sided stencil and stencil wrap |
| 342 | fTwoSidedStencilSupport = true; |
| 343 | fStencilWrapOpsSupport = true; |
| 344 | } |
| 345 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 346 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 347 | fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO |
| 348 | // extension includes glMapBuffer. |
| 349 | if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) { |
| 350 | fMapBufferFlags |= kSubset_MapFlag; |
| 351 | fMapBufferType = kMapBufferRange_MapBufferType; |
| 352 | } else { |
| 353 | fMapBufferType = kMapBuffer_MapBufferType; |
| 354 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 355 | } else { |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 356 | // Unextended GLES2 doesn't have any buffer mapping. |
| 357 | fMapBufferFlags = kNone_MapBufferType; |
| 358 | if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) { |
| 359 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 360 | fMapBufferType = kChromium_MapBufferType; |
| 361 | } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) { |
| 362 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 363 | fMapBufferType = kMapBufferRange_MapBufferType; |
| 364 | } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) { |
| 365 | fMapBufferFlags = kCanMap_MapFlag; |
| 366 | fMapBufferType = kMapBuffer_MapBufferType; |
| 367 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 368 | } |
| 369 | |
jvanverth | d7a2c1f | 2015-12-07 07:36:44 -0800 | [diff] [blame] | 370 | if (kGL_GrGLStandard == standard) { |
| 371 | if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) { |
| 372 | fTransferBufferType = kPBO_TransferBufferType; |
| 373 | } |
| 374 | } else { |
| 375 | if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) { |
| 376 | fTransferBufferType = kPBO_TransferBufferType; |
| 377 | } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) { |
| 378 | fTransferBufferType = kChromium_TransferBufferType; |
| 379 | } |
| 380 | } |
| 381 | |
joshualitt | e5b74c6 | 2015-06-01 14:17:47 -0700 | [diff] [blame] | 382 | // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the |
| 383 | // threshold to the maximum unless the client gives us a hint that map memory is cheap. |
| 384 | if (fGeometryBufferMapThreshold < 0) { |
bsalomon | bc23375 | 2015-06-26 11:38:25 -0700 | [diff] [blame] | 385 | // We think mapping on Chromium will be cheaper once we know ahead of time how much space |
| 386 | // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using |
| 387 | // a small subset. |
| 388 | #if 0 |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 389 | fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32; |
bsalomon | bc23375 | 2015-06-26 11:38:25 -0700 | [diff] [blame] | 390 | #else |
| 391 | fGeometryBufferMapThreshold = SK_MaxS32; |
| 392 | #endif |
joshualitt | e5b74c6 | 2015-06-01 14:17:47 -0700 | [diff] [blame] | 393 | } |
| 394 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 395 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 396 | SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) || |
| 397 | ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")); |
| 398 | fNPOTTextureTileSupport = true; |
| 399 | fMipMapSupport = true; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 400 | } else { |
| 401 | // 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] | 402 | // ES3 has no limitations. |
| 403 | fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) || |
| 404 | ctxInfo.hasExtension("GL_OES_texture_npot"); |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 405 | // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP |
| 406 | // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently, |
| 407 | // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to |
| 408 | // to alllow arbitrary wrap modes, however. |
| 409 | fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot"); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 410 | } |
| 411 | |
bsalomon | e72bd02 | 2015-10-26 07:33:03 -0700 | [diff] [blame] | 412 | // Using MIPs on this GPU seems to be a source of trouble. |
| 413 | if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) { |
| 414 | fMipMapSupport = false; |
| 415 | } |
| 416 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 417 | GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize); |
| 418 | GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize); |
| 419 | // Our render targets are always created with textures as the color |
| 420 | // attachment, hence this min: |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 421 | fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 422 | |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 423 | fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker"); |
| 424 | |
robertphillips@google.com | 8995b7b | 2013-11-01 15:03:34 +0000 | [diff] [blame] | 425 | // Disable scratch texture reuse on Mali and Adreno devices |
| 426 | fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() && |
| 427 | kQualcomm_GrGLVendor != ctxInfo.vendor(); |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 428 | |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 429 | #if 0 |
| 430 | fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() && |
| 431 | kQualcomm_GrGLVendor != ctxInfo.vendor(); |
| 432 | #endif |
| 433 | |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 434 | // initFSAASupport() must have been called before this point |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 435 | if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) { |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 436 | GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 437 | } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) { |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 438 | GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 439 | } |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 440 | // We only have a use for raster multisample if there is coverage modulation from mixed samples. |
| 441 | if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) { |
| 442 | GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples); |
| 443 | // This is to guard against platforms that may not support as many samples for |
| 444 | // glRasterSamples as they do for framebuffers. |
| 445 | fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples); |
| 446 | } |
| 447 | fMaxColorSampleCount = fMaxStencilSampleCount; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 448 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 449 | if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() || |
bsalomon | e702d97 | 2015-01-29 10:07:32 -0800 | [diff] [blame] | 450 | kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() || |
bsalomon | a8fcea0 | 2015-02-13 09:00:39 -0800 | [diff] [blame] | 451 | kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) { |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 452 | fUseDrawInsteadOfClear = true; |
| 453 | } |
| 454 | |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 455 | if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) { |
| 456 | fUseDrawInsteadOfPartialRenderTargetWrite = true; |
| 457 | } |
| 458 | |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 459 | #ifdef SK_BUILD_FOR_WIN |
| 460 | // On ANGLE deferring flushes can lead to GPU starvation |
| 461 | fPreferVRAMUseOverFlushes = !isANGLE; |
| 462 | #endif |
| 463 | |
bsalomon | 7dea7b7 | 2015-08-19 08:26:51 -0700 | [diff] [blame] | 464 | if (kChromium_GrGLDriver == ctxInfo.driver()) { |
| 465 | fMustClearUploadedBufferData = true; |
| 466 | } |
| 467 | |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 468 | if (kGL_GrGLStandard == standard) { |
| 469 | // ARB allows mixed size FBO attachments, EXT does not. |
| 470 | if (ctxInfo.version() >= GR_GL_VER(3, 0) || |
| 471 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
| 472 | fOversizedStencilSupport = true; |
| 473 | } else { |
| 474 | SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object")); |
| 475 | } |
| 476 | } else { |
| 477 | // ES 3.0 supports mixed size FBO attachments, 2.0 does not. |
| 478 | fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0); |
| 479 | } |
| 480 | |
joshualitt | 5800155 | 2015-06-26 12:46:36 -0700 | [diff] [blame] | 481 | if (kGL_GrGLStandard == standard) { |
| 482 | // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about |
| 483 | // instanced arrays, but we could make this more granular if we wanted |
| 484 | fSupportsInstancedDraws = |
| 485 | version >= GR_GL_VER(3, 2) || |
| 486 | (ctxInfo.hasExtension("GL_ARB_draw_instanced") && |
| 487 | ctxInfo.hasExtension("GL_ARB_instanced_arrays")); |
| 488 | } else { |
| 489 | fSupportsInstancedDraws = |
| 490 | version >= GR_GL_VER(3, 0) || |
| 491 | (ctxInfo.hasExtension("GL_EXT_draw_instanced") && |
| 492 | ctxInfo.hasExtension("GL_EXT_instanced_arrays")); |
| 493 | } |
| 494 | |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 495 | if (kGL_GrGLStandard == standard) { |
| 496 | // We don't use ARB_draw_indirect because it does not support a base instance. |
| 497 | // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER. |
| 498 | fDrawIndirectSupport = |
| 499 | fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3); |
| 500 | } else { |
| 501 | fDrawIndirectSupport = version >= GR_GL_VER(3,1); |
| 502 | fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect"); |
| 503 | fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance"); |
| 504 | } |
| 505 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 506 | this->initShaderPrecisionTable(ctxInfo, gli, glslCaps); |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 507 | |
| 508 | if (contextOptions.fUseShaderSwizzling) { |
| 509 | fTextureSwizzleSupport = false; |
| 510 | } |
| 511 | |
| 512 | // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have |
| 513 | // already been detected. |
| 514 | this->initConfigTable(ctxInfo, gli, glslCaps); |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 515 | |
| 516 | this->applyOptionsOverrides(contextOptions); |
| 517 | glslCaps->applyOptionsOverrides(contextOptions); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 518 | } |
| 519 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 520 | const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation, |
| 521 | bool isCoreProfile) { |
| 522 | switch (generation) { |
| 523 | case k110_GrGLSLGeneration: |
| 524 | if (kGLES_GrGLStandard == standard) { |
| 525 | // ES2s shader language is based on version 1.20 but is version |
| 526 | // 1.00 of the ES language. |
| 527 | return "#version 100\n"; |
| 528 | } else { |
| 529 | SkASSERT(kGL_GrGLStandard == standard); |
| 530 | return "#version 110\n"; |
| 531 | } |
| 532 | case k130_GrGLSLGeneration: |
| 533 | SkASSERT(kGL_GrGLStandard == standard); |
| 534 | return "#version 130\n"; |
| 535 | case k140_GrGLSLGeneration: |
| 536 | SkASSERT(kGL_GrGLStandard == standard); |
| 537 | return "#version 140\n"; |
| 538 | case k150_GrGLSLGeneration: |
| 539 | SkASSERT(kGL_GrGLStandard == standard); |
| 540 | if (isCoreProfile) { |
| 541 | return "#version 150\n"; |
| 542 | } else { |
| 543 | return "#version 150 compatibility\n"; |
| 544 | } |
| 545 | case k330_GrGLSLGeneration: |
| 546 | if (kGLES_GrGLStandard == standard) { |
| 547 | return "#version 300 es\n"; |
| 548 | } else { |
| 549 | SkASSERT(kGL_GrGLStandard == standard); |
| 550 | if (isCoreProfile) { |
| 551 | return "#version 330\n"; |
| 552 | } else { |
| 553 | return "#version 330 compatibility\n"; |
| 554 | } |
| 555 | } |
| 556 | case k310es_GrGLSLGeneration: |
| 557 | SkASSERT(kGLES_GrGLStandard == standard); |
| 558 | return "#version 310 es\n"; |
| 559 | } |
| 560 | return "<no version>"; |
| 561 | } |
| 562 | |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 563 | void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) { |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 564 | GrGLStandard standard = ctxInfo.standard(); |
| 565 | GrGLVersion version = ctxInfo.version(); |
| 566 | |
| 567 | /************************************************************************** |
| 568 | * Caps specific to GrGLSLCaps |
| 569 | **************************************************************************/ |
| 570 | |
| 571 | GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); |
| 572 | glslCaps->fGLSLGeneration = ctxInfo.glslGeneration(); |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 573 | if (kGLES_GrGLStandard == standard) { |
| 574 | if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) { |
| 575 | glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0)); |
| 576 | glslCaps->fFBFetchSupport = true; |
| 577 | glslCaps->fFBFetchColorName = "gl_LastFragData[0]"; |
| 578 | glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch"; |
| 579 | } |
| 580 | else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) { |
| 581 | // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know |
| 582 | glslCaps->fFBFetchNeedsCustomOutput = false; |
| 583 | glslCaps->fFBFetchSupport = true; |
| 584 | glslCaps->fFBFetchColorName = "gl_LastFragData[0]"; |
| 585 | glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch"; |
| 586 | } |
| 587 | else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) { |
| 588 | // The arm extension also requires an additional flag which we will set onResetContext |
| 589 | glslCaps->fFBFetchNeedsCustomOutput = false; |
| 590 | glslCaps->fFBFetchSupport = true; |
| 591 | glslCaps->fFBFetchColorName = "gl_LastFragColorARM"; |
| 592 | glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch"; |
| 593 | } |
| 594 | glslCaps->fUsesPrecisionModifiers = true; |
| 595 | } |
| 596 | |
| 597 | glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture"); |
| 598 | |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame^] | 599 | if (kGL_GrGLStandard == standard) { |
| 600 | glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration; |
| 601 | } else { |
| 602 | glslCaps->fFlatInterpolationSupport = |
| 603 | ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0. |
| 604 | } |
| 605 | |
| 606 | if (kGL_GrGLStandard == standard) { |
| 607 | glslCaps->fNoPerspectiveInterpolationSupport = |
| 608 | ctxInfo.glslGeneration() >= k130_GrGLSLGeneration; |
| 609 | } else { |
| 610 | if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) { |
| 611 | glslCaps->fNoPerspectiveInterpolationSupport = true; |
| 612 | glslCaps->fNoPerspectiveInterpolationExtensionString = |
| 613 | "GL_NV_shader_noperspective_interpolation"; |
| 614 | } |
| 615 | } |
| 616 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 617 | // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader |
| 618 | glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor(); |
| 619 | |
| 620 | // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any |
| 621 | // function that may require a gradient calculation inside a conditional block may return |
| 622 | // undefined results". This appears to be an issue with the 'any' call since even the simple |
| 623 | // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play |
| 624 | // from our GrTextureDomain processor. |
| 625 | glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor(); |
| 626 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 627 | glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration, |
| 628 | fIsCoreProfile); |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 629 | |
| 630 | if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) { |
| 631 | glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives"; |
| 632 | } |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 633 | |
| 634 | // Frag Coords Convention support is not part of ES |
| 635 | // Known issue on at least some Intel platforms: |
| 636 | // http://code.google.com/p/skia/issues/detail?id=946 |
| 637 | if (kIntel_GrGLVendor != ctxInfo.vendor() && |
| 638 | kGLES_GrGLStandard != standard && |
| 639 | (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration || |
| 640 | ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) { |
| 641 | glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions"; |
| 642 | } |
| 643 | |
| 644 | if (kGLES_GrGLStandard == standard) { |
| 645 | glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended"; |
| 646 | } |
| 647 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 648 | if (fExternalTextureSupport) { |
| 649 | if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) { |
| 650 | glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external"; |
| 651 | } else { |
| 652 | glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3"; |
| 653 | } |
| 654 | } |
| 655 | |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 656 | // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do |
| 657 | // the abs first in a separate expression. |
| 658 | if (kTegra3_GrGLRenderer == ctxInfo.renderer()) { |
| 659 | glslCaps->fCanUseMinAndAbsTogether = false; |
| 660 | } |
| 661 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 662 | // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 663 | // thus must us -1.0 * %s.x to work correctly |
| 664 | if (kIntel_GrGLVendor == ctxInfo.vendor()) { |
| 665 | glslCaps->fMustForceNegatedAtanParamToFloat = true; |
| 666 | } |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 667 | } |
| 668 | |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 669 | bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 670 | bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering"); |
| 671 | |
| 672 | if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) { |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 673 | return false; |
| 674 | } |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 675 | |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 676 | if (kGL_GrGLStandard == ctxInfo.standard()) { |
| 677 | if (ctxInfo.version() < GR_GL_VER(4, 3) && |
| 678 | !ctxInfo.hasExtension("GL_ARB_program_interface_query")) { |
| 679 | return false; |
| 680 | } |
| 681 | } else { |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 682 | if (!hasChromiumPathRendering && |
| 683 | ctxInfo.version() < GR_GL_VER(3, 1)) { |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 684 | return false; |
| 685 | } |
| 686 | } |
| 687 | // We only support v1.3+ of GL_NV_path_rendering which allows us to |
| 688 | // set individual fragment inputs with ProgramPathFragmentInputGen. The API |
| 689 | // additions are detected by checking the existence of the function. |
| 690 | // We also use *Then* functions that not all drivers might have. Check |
| 691 | // them for consistency. |
bsalomon | 9f2dc27 | 2016-02-08 07:22:17 -0800 | [diff] [blame] | 692 | if (!gli->fFunctions.fStencilThenCoverFillPath || |
| 693 | !gli->fFunctions.fStencilThenCoverStrokePath || |
| 694 | !gli->fFunctions.fStencilThenCoverFillPathInstanced || |
| 695 | !gli->fFunctions.fStencilThenCoverStrokePathInstanced || |
| 696 | !gli->fFunctions.fProgramPathFragmentInputGen) { |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 697 | return false; |
| 698 | } |
| 699 | return true; |
| 700 | } |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 701 | |
| 702 | bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig, |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 703 | GrPixelConfig readConfig, |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 704 | std::function<void (GrGLenum, GrGLint*)> getIntegerv, |
| 705 | std::function<bool ()> bindRenderTarget) const { |
bsalomon | e957331 | 2016-01-25 14:33:25 -0800 | [diff] [blame] | 706 | // If it's not possible to even have a render target of rtConfig then read pixels is |
| 707 | // not supported regardless of readConfig. |
| 708 | if (!this->isConfigRenderable(rtConfig, false)) { |
| 709 | return false; |
| 710 | } |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 711 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 712 | GrGLenum readFormat; |
| 713 | GrGLenum readType; |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 714 | if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) { |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 715 | return false; |
| 716 | } |
| 717 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 718 | if (kGL_GrGLStandard == fStandard) { |
bsalomon | e957331 | 2016-01-25 14:33:25 -0800 | [diff] [blame] | 719 | // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However, |
| 720 | // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed: |
| 721 | // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE, |
| 722 | // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use. |
| 723 | if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA && |
| 724 | readFormat != GR_GL_BGRA) { |
| 725 | return false; |
| 726 | } |
| 727 | // There is also a set of allowed types, but all the types we use are in the set: |
| 728 | // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, |
| 729 | // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, |
| 730 | // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, |
| 731 | // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, |
| 732 | // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2, |
| 733 | // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV, |
| 734 | // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV. |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 735 | return true; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 736 | } |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 737 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 738 | // See Section 16.1.2 in the ES 3.2 specification. |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 739 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 740 | if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) { |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 741 | if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) { |
| 742 | return true; |
| 743 | } |
| 744 | } else { |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 745 | SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType); |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 746 | if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) { |
| 747 | return true; |
| 748 | } |
| 749 | } |
| 750 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 751 | if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) { |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 752 | ReadPixelsFormat* rpFormat = |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 753 | const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat); |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 754 | GrGLint format = 0, type = 0; |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 755 | if (!bindRenderTarget()) { |
| 756 | return false; |
| 757 | } |
| 758 | getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format); |
| 759 | getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type); |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 760 | rpFormat->fFormat = format; |
| 761 | rpFormat->fType = type; |
| 762 | } |
| 763 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 764 | return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat && |
| 765 | fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 766 | } |
| 767 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 768 | void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 769 | |
| 770 | fMSFBOType = kNone_MSFBOType; |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 771 | if (kGL_GrGLStandard != ctxInfo.standard()) { |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 772 | // We prefer the EXT/IMG extension over ES3 MSAA because we've observed |
| 773 | // ES3 driver bugs on at least one device with a tiled GPU (N10). |
| 774 | if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { |
| 775 | fMSFBOType = kES_EXT_MsToTexture_MSFBOType; |
| 776 | } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { |
| 777 | fMSFBOType = kES_IMG_MsToTexture_MSFBOType; |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 778 | } else if (fUsesMixedSamples) { |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 779 | fMSFBOType = kMixedSamples_MSFBOType; |
commit-bot@chromium.org | 92b7884 | 2014-01-16 20:49:46 +0000 | [diff] [blame] | 780 | } else if (ctxInfo.version() >= GR_GL_VER(3,0)) { |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 781 | fMSFBOType = GrGLCaps::kES_3_0_MSFBOType; |
| 782 | } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
| 783 | // chrome's extension is equivalent to the EXT msaa |
| 784 | // and fbo_blit extensions. |
| 785 | fMSFBOType = kDesktop_EXT_MSFBOType; |
| 786 | } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { |
| 787 | fMSFBOType = kES_Apple_MSFBOType; |
| 788 | } |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 789 | |
| 790 | // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer |
| 791 | // is available. |
| 792 | if (ctxInfo.version() >= GR_GL_VER(3, 0)) { |
| 793 | fBlitFramebufferSupport = kFull_BlitFramebufferSupport; |
| 794 | } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
| 795 | // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its |
| 796 | // limitations. |
| 797 | fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport; |
| 798 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 799 | } else { |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 800 | if (fUsesMixedSamples) { |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 801 | fMSFBOType = kMixedSamples_MSFBOType; |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 802 | fBlitFramebufferSupport = kFull_BlitFramebufferSupport; |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 803 | } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 804 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 805 | fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType; |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 806 | fBlitFramebufferSupport = kFull_BlitFramebufferSupport; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 807 | } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && |
| 808 | ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 809 | fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType; |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 810 | fBlitFramebufferSupport = kFull_BlitFramebufferSupport; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 811 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 815 | void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) { |
| 816 | GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); |
| 817 | |
| 818 | // Disabling advanced blend on various platforms with major known issues. We also block Chrome |
| 819 | // for now until its own blacklists can be updated. |
| 820 | if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() || |
| 821 | kIntel_GrGLDriver == ctxInfo.driver() || |
joel.liang | 9764c40 | 2015-07-09 19:46:18 -0700 | [diff] [blame] | 822 | kChromium_GrGLDriver == ctxInfo.driver()) { |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 823 | return; |
| 824 | } |
| 825 | |
| 826 | if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) { |
| 827 | fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport; |
| 828 | glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction; |
| 829 | } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) { |
| 830 | fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport; |
| 831 | glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction; |
| 832 | } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() && |
| 833 | ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) { |
| 834 | // Non-coherent advanced blend has an issue on NVIDIA pre 337.00. |
| 835 | return; |
| 836 | } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) { |
| 837 | fBlendEquationSupport = kAdvanced_BlendEquationSupport; |
| 838 | glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction; |
| 839 | } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) { |
| 840 | fBlendEquationSupport = kAdvanced_BlendEquationSupport; |
| 841 | glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction; |
| 842 | // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is |
| 843 | // slow on a particular platform. |
| 844 | } else { |
| 845 | return; // No advanced blend support. |
| 846 | } |
| 847 | |
| 848 | SkASSERT(this->advancedBlendEquationSupport()); |
| 849 | |
| 850 | if (kNVIDIA_GrGLDriver == ctxInfo.driver()) { |
| 851 | // Blacklist color-dodge and color-burn on NVIDIA until the fix is released. |
| 852 | fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) | |
| 853 | (1 << kColorBurn_GrBlendEquation); |
| 854 | } |
joel.liang | 9764c40 | 2015-07-09 19:46:18 -0700 | [diff] [blame] | 855 | if (kARM_GrGLVendor == ctxInfo.vendor()) { |
| 856 | // Blacklist color-burn on ARM until the fix is released. |
| 857 | fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation); |
| 858 | } |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 859 | } |
| 860 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 861 | namespace { |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 862 | const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { |
| 866 | |
| 867 | // Build up list of legal stencil formats (though perhaps not supported on |
| 868 | // the particular gpu/driver) from most preferred to least. |
| 869 | |
| 870 | // these consts are in order of most preferred to least preferred |
| 871 | // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 |
| 872 | |
| 873 | static const StencilFormat |
| 874 | // internal Format stencil bits total bits packed? |
| 875 | gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, |
| 876 | gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, |
| 877 | gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, |
| 878 | gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 879 | // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 880 | gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; |
| 881 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 882 | if (kGL_GrGLStandard == ctxInfo.standard()) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 883 | bool supportsPackedDS = |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 884 | ctxInfo.version() >= GR_GL_VER(3,0) || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 885 | ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || |
| 886 | ctxInfo.hasExtension("GL_ARB_framebuffer_object"); |
| 887 | |
| 888 | // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we |
| 889 | // require FBO support we can expect these are legal formats and don't |
| 890 | // check. These also all support the unsized GL_STENCIL_INDEX. |
| 891 | fStencilFormats.push_back() = gS8; |
| 892 | fStencilFormats.push_back() = gS16; |
| 893 | if (supportsPackedDS) { |
| 894 | fStencilFormats.push_back() = gD24S8; |
| 895 | } |
| 896 | fStencilFormats.push_back() = gS4; |
| 897 | if (supportsPackedDS) { |
| 898 | fStencilFormats.push_back() = gDS; |
| 899 | } |
| 900 | } else { |
| 901 | // ES2 has STENCIL_INDEX8 without extensions but requires extensions |
| 902 | // for other formats. |
| 903 | // ES doesn't support using the unsized format. |
| 904 | |
| 905 | fStencilFormats.push_back() = gS8; |
| 906 | //fStencilFormats.push_back() = gS16; |
commit-bot@chromium.org | 04c500f | 2013-09-06 15:28:01 +0000 | [diff] [blame] | 907 | if (ctxInfo.version() >= GR_GL_VER(3,0) || |
| 908 | ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 909 | fStencilFormats.push_back() = gD24S8; |
| 910 | } |
| 911 | if (ctxInfo.hasExtension("GL_OES_stencil4")) { |
| 912 | fStencilFormats.push_back() = gS4; |
| 913 | } |
| 914 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 915 | } |
| 916 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 917 | SkString GrGLCaps::dump() const { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 918 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 919 | SkString r = INHERITED::dump(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 920 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 921 | r.appendf("--- GL-Specific ---\n"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 922 | for (int i = 0; i < fStencilFormats.count(); ++i) { |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 923 | 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] | 924 | i, |
| 925 | fStencilFormats[i].fStencilBits, |
| 926 | fStencilFormats[i].fTotalBits); |
| 927 | } |
| 928 | |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 929 | static const char* kMSFBOExtStr[] = { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 930 | "None", |
| 931 | "ARB", |
| 932 | "EXT", |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 933 | "ES 3.0", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 934 | "Apple", |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 935 | "IMG MS To Texture", |
| 936 | "EXT MS To Texture", |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 937 | "MixedSamples", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 938 | }; |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 939 | GR_STATIC_ASSERT(0 == kNone_MSFBOType); |
| 940 | GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType); |
| 941 | GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType); |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 942 | GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType); |
| 943 | GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType); |
| 944 | GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType); |
| 945 | GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType); |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 946 | GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 947 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1); |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 948 | |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 949 | static const char* kInvalidateFBTypeStr[] = { |
| 950 | "None", |
| 951 | "Discard", |
| 952 | "Invalidate", |
| 953 | }; |
| 954 | GR_STATIC_ASSERT(0 == kNone_InvalidateFBType); |
| 955 | GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType); |
| 956 | GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType); |
| 957 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1); |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 958 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 959 | static const char* kMapBufferTypeStr[] = { |
| 960 | "None", |
| 961 | "MapBuffer", |
| 962 | "MapBufferRange", |
| 963 | "Chromium", |
| 964 | }; |
| 965 | GR_STATIC_ASSERT(0 == kNone_MapBufferType); |
| 966 | GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType); |
| 967 | GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType); |
| 968 | GR_STATIC_ASSERT(3 == kChromium_MapBufferType); |
| 969 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1); |
| 970 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 971 | r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 972 | r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]); |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 973 | r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]); |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 974 | r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 975 | r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); |
| 976 | r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 977 | r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 978 | r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO")); |
| 979 | r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO")); |
| 980 | r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO")); |
| 981 | r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO")); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 982 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 983 | r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO")); |
| 984 | r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO")); |
| 985 | r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); |
| 986 | r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 987 | r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO")); |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 988 | r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO")); |
| 989 | r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO")); |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 990 | r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO")); |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 991 | r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO")); |
| 992 | r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO")); |
| 993 | r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 994 | r.appendf("Use non-VBO for dynamic data: %s\n", |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 995 | (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 996 | r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO")); |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 997 | r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO")); |
| 998 | r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO")); |
joshualitt | 7bdd70a | 2015-10-01 06:28:11 -0700 | [diff] [blame] | 999 | r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO")); |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1000 | r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO")); |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 1001 | r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO")); |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1002 | r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO")); |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1003 | |
| 1004 | r.append("Configs\n-------\n"); |
| 1005 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 1006 | r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: " |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1007 | "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, " |
| 1008 | "i_for_renderbuffer: 0x%08x\n", |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1009 | i, |
| 1010 | fConfigTable[i].fFlags, |
| 1011 | fConfigTable[i].fFormats.fBaseInternalFormat, |
| 1012 | fConfigTable[i].fFormats.fSizedInternalFormat, |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1013 | fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage], |
| 1014 | fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage], |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1015 | fConfigTable[i].fFormats.fExternalType, |
| 1016 | fConfigTable[i].fFormats.fInternalFormatTexImage, |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1017 | fConfigTable[i].fFormats.fInternalFormatRenderbuffer); |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1018 | } |
| 1019 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1020 | return r; |
| 1021 | } |
| 1022 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1023 | static GrGLenum precision_to_gl_float_type(GrSLPrecision p) { |
| 1024 | switch (p) { |
| 1025 | case kLow_GrSLPrecision: |
| 1026 | return GR_GL_LOW_FLOAT; |
| 1027 | case kMedium_GrSLPrecision: |
| 1028 | return GR_GL_MEDIUM_FLOAT; |
| 1029 | case kHigh_GrSLPrecision: |
| 1030 | return GR_GL_HIGH_FLOAT; |
| 1031 | } |
| 1032 | SkFAIL("Unknown precision."); |
| 1033 | return -1; |
| 1034 | } |
| 1035 | |
| 1036 | static GrGLenum shader_type_to_gl_shader(GrShaderType type) { |
| 1037 | switch (type) { |
| 1038 | case kVertex_GrShaderType: |
| 1039 | return GR_GL_VERTEX_SHADER; |
| 1040 | case kGeometry_GrShaderType: |
| 1041 | return GR_GL_GEOMETRY_SHADER; |
| 1042 | case kFragment_GrShaderType: |
| 1043 | return GR_GL_FRAGMENT_SHADER; |
| 1044 | } |
| 1045 | SkFAIL("Unknown shader type."); |
| 1046 | return -1; |
| 1047 | } |
| 1048 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1049 | void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, |
| 1050 | const GrGLInterface* intf, |
| 1051 | GrGLSLCaps* glslCaps) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1052 | if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) || |
| 1053 | ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) { |
| 1054 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 1055 | if (kGeometry_GrShaderType != s) { |
| 1056 | GrShaderType shaderType = static_cast<GrShaderType>(s); |
| 1057 | GrGLenum glShader = shader_type_to_gl_shader(shaderType); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1058 | GrShaderCaps::PrecisionInfo* first = nullptr; |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1059 | glslCaps->fShaderPrecisionVaries = false; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1060 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
| 1061 | GrSLPrecision precision = static_cast<GrSLPrecision>(p); |
| 1062 | GrGLenum glPrecision = precision_to_gl_float_type(precision); |
| 1063 | GrGLint range[2]; |
| 1064 | GrGLint bits; |
| 1065 | GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits); |
| 1066 | if (bits) { |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1067 | glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0]; |
| 1068 | glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1]; |
| 1069 | glslCaps->fFloatPrecisions[s][p].fBits = bits; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1070 | if (!first) { |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1071 | first = &glslCaps->fFloatPrecisions[s][p]; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1072 | } |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1073 | else if (!glslCaps->fShaderPrecisionVaries) { |
| 1074 | glslCaps->fShaderPrecisionVaries = |
| 1075 | (*first != glslCaps->fFloatPrecisions[s][p]); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | else { |
| 1083 | // 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] | 1084 | glslCaps->fShaderPrecisionVaries = false; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1085 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 1086 | if (kGeometry_GrShaderType != s) { |
| 1087 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1088 | glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127; |
| 1089 | glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127; |
| 1090 | glslCaps->fFloatPrecisions[s][p].fBits = 23; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | } |
| 1094 | } |
| 1095 | // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're |
| 1096 | // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for |
| 1097 | // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that |
| 1098 | // are recommended against. |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1099 | if (glslCaps->fGeometryShaderSupport) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1100 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 1101 | glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] = |
| 1102 | glslCaps->fFloatPrecisions[kVertex_GrShaderType][p]; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1107 | bool GrGLCaps::bgraIsInternalFormat() const { |
| 1108 | return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA; |
| 1109 | } |
| 1110 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1111 | bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig, |
| 1112 | GrGLenum* internalFormat, GrGLenum* externalFormat, |
| 1113 | GrGLenum* externalType) const { |
| 1114 | if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage, |
| 1115 | externalFormat, externalType)) { |
| 1116 | return false; |
| 1117 | } |
| 1118 | *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage; |
| 1119 | return true; |
| 1120 | } |
| 1121 | |
| 1122 | bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig, |
| 1123 | GrGLenum* internalFormat) const { |
| 1124 | if (!GrPixelConfigIsCompressed(surfaceConfig)) { |
| 1125 | return false; |
| 1126 | } |
| 1127 | *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage; |
| 1128 | return true; |
| 1129 | } |
| 1130 | |
| 1131 | bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig, |
| 1132 | GrGLenum* externalFormat, GrGLenum* externalType) const { |
| 1133 | if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage, |
| 1134 | externalFormat, externalType)) { |
| 1135 | return false; |
| 1136 | } |
| 1137 | return true; |
| 1138 | } |
| 1139 | |
| 1140 | bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const { |
| 1141 | if (GrPixelConfigIsCompressed(config)) { |
| 1142 | return false; |
| 1143 | } |
| 1144 | *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer; |
| 1145 | return true; |
| 1146 | } |
| 1147 | |
| 1148 | bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig, |
| 1149 | ExternalFormatUsage usage, GrGLenum* externalFormat, |
| 1150 | GrGLenum* externalType) const { |
| 1151 | SkASSERT(externalFormat && externalType); |
| 1152 | if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) { |
| 1153 | return false; |
| 1154 | } |
| 1155 | |
| 1156 | bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig); |
| 1157 | bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig); |
| 1158 | |
| 1159 | // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be |
| 1160 | // made to work in many cases using glPixelStore and what not but is not needed currently. |
| 1161 | if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) { |
| 1162 | return false; |
| 1163 | } |
| 1164 | |
| 1165 | *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage]; |
| 1166 | *externalType = fConfigTable[memoryConfig].fFormats.fExternalType; |
| 1167 | |
bsalomon | e957331 | 2016-01-25 14:33:25 -0800 | [diff] [blame] | 1168 | // When GL_RED is supported as a texture format, our alpha-only textures are stored using |
| 1169 | // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the |
| 1170 | // surface is not alpha-only and we want alpha to really mean the alpha component of the |
| 1171 | // texture, not the red component. |
| 1172 | if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) { |
| 1173 | if (this->textureRedSupport()) { |
| 1174 | SkASSERT(GR_GL_RED == *externalFormat); |
| 1175 | *externalFormat = GR_GL_ALPHA; |
| 1176 | } |
| 1177 | } |
| 1178 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1179 | return true; |
| 1180 | } |
| 1181 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1182 | void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, |
| 1183 | GrGLSLCaps* glslCaps) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1184 | /* |
| 1185 | Comments on renderability of configs on various GL versions. |
| 1186 | OpenGL < 3.0: |
| 1187 | no built in support for render targets. |
| 1188 | GL_EXT_framebuffer_object adds possible support for any sized format with base internal |
| 1189 | format RGB, RGBA and NV float formats we don't use. |
| 1190 | This is the following: |
| 1191 | R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8 |
| 1192 | RGB10_A2, RGBA12,RGBA16 |
| 1193 | Though, it is hard to believe the more obscure formats such as RGBA12 would work |
| 1194 | since they aren't required by later standards and the driver can simply return |
| 1195 | FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow. |
| 1196 | GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally |
| 1197 | any sized internal format with a base internal format of ALPHA, LUMINANCE, |
| 1198 | LUMINANCE_ALPHA, INTENSITY, RED, and RG. |
| 1199 | This adds a lot of additional renderable sized formats, including ALPHA8. |
| 1200 | The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI, |
| 1201 | 16F, 32I, 32UI, and 32F variants). |
| 1202 | Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED. |
| 1203 | |
| 1204 | For both the above extensions we limit ourselves to those that are also required by |
| 1205 | OpenGL 3.0. |
| 1206 | |
| 1207 | OpenGL 3.0: |
| 1208 | Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable" |
| 1209 | but are not required to be supported as renderable textures/renderbuffer. |
| 1210 | Required renderable color formats: |
| 1211 | - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I, |
| 1212 | RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and |
| 1213 | RGB10_A2. |
| 1214 | - R11F_G11F_B10F. |
| 1215 | - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I, |
| 1216 | and RG8UI. |
| 1217 | - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI. |
| 1218 | - ALPHA8 |
| 1219 | |
| 1220 | OpenGL 3.1, 3.2, 3.3 |
| 1221 | Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile. |
| 1222 | OpengGL 3.3, 4.0, 4.1 |
| 1223 | Adds RGB10_A2UI. |
| 1224 | OpengGL 4.2 |
| 1225 | Adds |
| 1226 | - RGB5_A1, RGBA4 |
| 1227 | - RGB565 |
| 1228 | OpenGL 4.4 |
| 1229 | Does away with the separate list and adds a column to the sized internal color format |
| 1230 | table. However, no new formats become required color renderable. |
| 1231 | |
| 1232 | ES 2.0 |
| 1233 | color renderable: RGBA4, RGB5_A1, RGB565 |
| 1234 | GL_EXT_texture_rg adds support for R8, RG5 as a color render target |
| 1235 | GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8 |
| 1236 | GL_ARM_rgba8 adds support for RGBA8 (but not RGB8) |
| 1237 | GL_EXT_texture_format_BGRA8888 does not add renderbuffer support |
| 1238 | GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable |
| 1239 | GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support |
| 1240 | |
| 1241 | ES 3.0 |
| 1242 | - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I, |
| 1243 | RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and |
| 1244 | RGB5_A1. |
| 1245 | - RGB8 and RGB565. |
| 1246 | - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI. |
| 1247 | - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI |
| 1248 | ES 3.1 |
| 1249 | Adds RGB10_A2, RGB10_A2UI, |
| 1250 | ES 3.2 |
| 1251 | Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F. |
| 1252 | */ |
| 1253 | uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag; |
| 1254 | if (kNone_MSFBOType != fMSFBOType) { |
| 1255 | allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag; |
| 1256 | } |
| 1257 | |
| 1258 | GrGLStandard standard = ctxInfo.standard(); |
| 1259 | GrGLVersion version = ctxInfo.version(); |
| 1260 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1261 | fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0; |
| 1262 | fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1263 | fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1264 | fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1265 | fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1266 | fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1267 | |
| 1268 | fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; |
| 1269 | fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1270 | fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = |
| 1271 | GR_GL_RGBA; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1272 | fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1273 | fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1274 | fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1275 | if (kGL_GrGLStandard == standard) { |
| 1276 | // We require some form of FBO support and all GLs with FBO support can render to RGBA8 |
| 1277 | fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags; |
egdaniel | 4999df8 | 2016-01-07 17:06:04 -0800 | [diff] [blame] | 1278 | } else { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1279 | if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || |
| 1280 | ctxInfo.hasExtension("GL_ARM_rgba8")) { |
| 1281 | fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags; |
| 1282 | } |
egdaniel | 4999df8 | 2016-01-07 17:06:04 -0800 | [diff] [blame] | 1283 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1284 | fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1285 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1286 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = |
| 1287 | GR_GL_BGRA; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1288 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1289 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1290 | if (kGL_GrGLStandard == standard) { |
| 1291 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; |
| 1292 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8; |
| 1293 | if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) { |
| 1294 | // Since the internal format is RGBA8, it is also renderable. |
| 1295 | fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag | |
| 1296 | allRenderFlags; |
| 1297 | } |
| 1298 | } else { |
| 1299 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA; |
| 1300 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8; |
| 1301 | if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) { |
| 1302 | // The APPLE extension doesn't make this renderable. |
| 1303 | fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1304 | if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) { |
| 1305 | // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension. |
| 1306 | // Though, that seems to not be the case if the texture storage extension is |
| 1307 | // present. The specs don't exactly make that clear. |
| 1308 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; |
| 1309 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8; |
| 1310 | } |
| 1311 | } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) { |
| 1312 | fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag | |
| 1313 | ConfigInfo::kRenderable_Flag; |
| 1314 | if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") && |
kkinnunen | 9f63b44 | 2016-01-25 00:31:49 -0800 | [diff] [blame] | 1315 | (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1316 | fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= |
| 1317 | ConfigInfo::kRenderableWithMSAA_Flag; |
| 1318 | } |
| 1319 | } |
| 1320 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1321 | fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1322 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1323 | // We only enable srgb support if both textures and FBOs support srgb. |
| 1324 | bool srgbSupport = false; |
| 1325 | if (kGL_GrGLStandard == standard) { |
| 1326 | if (ctxInfo.version() >= GR_GL_VER(3,0)) { |
| 1327 | srgbSupport = true; |
| 1328 | } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) { |
| 1329 | if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") || |
| 1330 | ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) { |
| 1331 | srgbSupport = true; |
| 1332 | } |
| 1333 | } |
| 1334 | // All the above srgb extensions support toggling srgb writes |
| 1335 | fSRGBWriteControl = srgbSupport; |
| 1336 | } else { |
| 1337 | // See https://bug.skia.org/4148 for PowerVR issue. |
| 1338 | srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() && |
| 1339 | (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB")); |
| 1340 | // ES through 3.1 requires EXT_srgb_write_control to support toggling |
| 1341 | // sRGB writing for destinations. |
| 1342 | fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control"); |
| 1343 | } |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1344 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA; |
| 1345 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8; |
| 1346 | // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the |
| 1347 | // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image. |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1348 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = |
| 1349 | GR_GL_RGBA; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1350 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1351 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1352 | if (srgbSupport) { |
| 1353 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag | |
| 1354 | allRenderFlags; |
| 1355 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1356 | fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1357 | |
| 1358 | fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB; |
| 1359 | if (this->ES2CompatibilitySupport()) { |
| 1360 | fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565; |
| 1361 | } else { |
| 1362 | fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5; |
| 1363 | } |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1364 | fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = |
| 1365 | GR_GL_RGB; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1366 | fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1367 | fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1368 | fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1369 | if (kGL_GrGLStandard == standard) { |
| 1370 | if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) { |
| 1371 | fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags; |
| 1372 | } |
| 1373 | } else { |
| 1374 | fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags; |
| 1375 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1376 | fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1377 | |
| 1378 | fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; |
| 1379 | fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1380 | fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = |
| 1381 | GR_GL_RGBA; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1382 | fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1383 | fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1384 | fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1385 | if (kGL_GrGLStandard == standard) { |
| 1386 | if (version >= GR_GL_VER(4, 2)) { |
| 1387 | fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags; |
| 1388 | } |
| 1389 | } else { |
| 1390 | fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags; |
| 1391 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1392 | fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1393 | |
| 1394 | if (this->textureRedSupport()) { |
| 1395 | fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED; |
| 1396 | fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1397 | fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = |
| 1398 | GR_GL_RED; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1399 | fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1400 | } else { |
| 1401 | fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA; |
| 1402 | fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1403 | fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = |
| 1404 | GR_GL_ALPHA; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1405 | fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1406 | } |
| 1407 | fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1408 | fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1409 | fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1410 | if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) { |
| 1411 | // desktop ARB extension/3.0+ supports ALPHA8 as renderable. |
| 1412 | // Core profile removes ALPHA8 support, but we should have chosen R8 in that case. |
| 1413 | fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags; |
| 1414 | } |
| 1415 | |
| 1416 | // Check for [half] floating point texture support |
| 1417 | // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not |
| 1418 | // supported. This is for simplicity, but a more granular approach is possible. Coincidentally, |
| 1419 | // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0. |
| 1420 | bool hasFPTextures = false; |
| 1421 | bool hasHalfFPTextures = false; |
| 1422 | // for now we don't support floating point MSAA on ES |
| 1423 | uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? |
| 1424 | allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag; |
| 1425 | |
| 1426 | if (kGL_GrGLStandard == standard) { |
| 1427 | if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) { |
| 1428 | hasFPTextures = true; |
| 1429 | hasHalfFPTextures = true; |
| 1430 | } |
| 1431 | } else { |
| 1432 | if (version >= GR_GL_VER(3, 1)) { |
| 1433 | hasFPTextures = true; |
| 1434 | hasHalfFPTextures = true; |
| 1435 | } else { |
| 1436 | if (ctxInfo.hasExtension("GL_OES_texture_float_linear") && |
| 1437 | ctxInfo.hasExtension("GL_OES_texture_float")) { |
| 1438 | hasFPTextures = true; |
| 1439 | } |
| 1440 | if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") && |
| 1441 | ctxInfo.hasExtension("GL_OES_texture_half_float")) { |
| 1442 | hasHalfFPTextures = true; |
| 1443 | } |
| 1444 | } |
| 1445 | } |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1446 | |
| 1447 | fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; |
| 1448 | fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1449 | fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = |
| 1450 | GR_GL_RGBA; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1451 | fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1452 | fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1453 | if (hasFPTextures) { |
| 1454 | fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1455 | // For now we only enable rendering to float on desktop, because on ES we'd have to solve |
| 1456 | // many precision issues and no clients actually want this yet. |
| 1457 | if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) || |
| 1458 | ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) { |
| 1459 | fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags; |
| 1460 | } |
| 1461 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1462 | fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1463 | |
| 1464 | if (this->textureRedSupport()) { |
| 1465 | fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED; |
| 1466 | fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1467 | fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] |
| 1468 | = GR_GL_RED; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1469 | fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1470 | } else { |
| 1471 | fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA; |
| 1472 | fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1473 | fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] |
| 1474 | = GR_GL_ALPHA; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1475 | fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1476 | } |
| 1477 | if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) { |
| 1478 | fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT; |
| 1479 | } else { |
| 1480 | fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES; |
| 1481 | } |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1482 | fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1483 | if (hasHalfFPTextures) { |
| 1484 | fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1485 | // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for |
| 1486 | // GL_RED internal format. |
| 1487 | if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) || |
| 1488 | (this->textureRedSupport() && |
| 1489 | ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) { |
| 1490 | fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags; |
| 1491 | } |
| 1492 | } |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1493 | |
| 1494 | fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; |
| 1495 | fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1496 | fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = |
| 1497 | GR_GL_RGBA; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1498 | if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) { |
| 1499 | fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT; |
| 1500 | } else { |
| 1501 | fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES; |
| 1502 | } |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1503 | fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1504 | if (hasHalfFPTextures) { |
| 1505 | fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1506 | // ES requires 3.2 or EXT_color_buffer_half_float. |
| 1507 | if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) || |
| 1508 | ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) { |
| 1509 | fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags; |
| 1510 | } |
| 1511 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1512 | fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1513 | |
| 1514 | // Compressed texture support |
| 1515 | |
| 1516 | // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard |
| 1517 | // OpenGL after version 1.3. We'll assume at least that level of OpenGL support. |
| 1518 | |
| 1519 | // TODO: Fix command buffer bindings and remove this. |
| 1520 | fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1521 | |
| 1522 | // No sized/unsized internal format distinction for compressed formats, no external format. |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1523 | // Below we set the external formats and types to 0. |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1524 | |
| 1525 | fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8; |
| 1526 | fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1527 | fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1528 | fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1529 | fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1530 | // Disable this for now, while we investigate https://bug.skia.org/4333 |
| 1531 | if (false) { |
| 1532 | // Check for 8-bit palette.. |
| 1533 | GrGLint numFormats; |
| 1534 | GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); |
| 1535 | if (numFormats) { |
| 1536 | SkAutoSTMalloc<10, GrGLint> formats(numFormats); |
| 1537 | GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats); |
| 1538 | for (int i = 0; i < numFormats; ++i) { |
| 1539 | if (GR_GL_PALETTE8_RGBA8 == formats[i]) { |
| 1540 | fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1541 | break; |
| 1542 | } |
| 1543 | } |
| 1544 | } |
| 1545 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1546 | fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1547 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1548 | // May change the internal format based on extensions. |
| 1549 | fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = |
| 1550 | GR_GL_COMPRESSED_LUMINANCE_LATC1; |
| 1551 | fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat = |
| 1552 | GR_GL_COMPRESSED_LUMINANCE_LATC1; |
| 1553 | if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") || |
| 1554 | ctxInfo.hasExtension("GL_NV_texture_compression_latc")) { |
| 1555 | fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1556 | } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) || |
| 1557 | ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") || |
| 1558 | ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) { |
| 1559 | // RGTC is identical and available on OpenGL 3.0+ as well as with extensions |
| 1560 | fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1561 | fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = |
| 1562 | GR_GL_COMPRESSED_RED_RGTC1; |
| 1563 | fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat = |
| 1564 | GR_GL_COMPRESSED_RED_RGTC1; |
| 1565 | } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) { |
| 1566 | fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1567 | fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X; |
| 1568 | fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat = |
| 1569 | GR_GL_COMPRESSED_3DC_X; |
| 1570 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1571 | } |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1572 | fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1573 | fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1574 | fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1575 | fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1576 | |
| 1577 | fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8; |
| 1578 | fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1579 | fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1580 | fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1581 | fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1582 | if (kGL_GrGLStandard == standard) { |
| 1583 | if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) { |
| 1584 | fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1585 | } |
| 1586 | } else { |
| 1587 | if (version >= GR_GL_VER(3, 0) || |
| 1588 | ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") || |
| 1589 | // ETC2 is a superset of ETC1, so we can just check for that, too. |
| 1590 | (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") && |
| 1591 | ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) { |
| 1592 | fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1593 | } |
| 1594 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1595 | fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1596 | |
| 1597 | fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC; |
| 1598 | fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1599 | fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1600 | fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1601 | fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1602 | // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to |
| 1603 | // decompressing the textures in the driver, and is generally slower. |
| 1604 | if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) { |
| 1605 | fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1606 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1607 | fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1608 | |
| 1609 | fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat = |
| 1610 | GR_GL_COMPRESSED_RGBA_ASTC_12x12; |
| 1611 | fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat = |
| 1612 | GR_GL_COMPRESSED_RGBA_ASTC_12x12; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1613 | fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = |
| 1614 | 0; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1615 | fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1616 | fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1617 | if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") || |
| 1618 | ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") || |
| 1619 | ctxInfo.hasExtension("GL_OES_texture_compression_astc")) { |
| 1620 | fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1621 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1622 | fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1623 | |
| 1624 | // Bulk populate the texture internal/external formats here and then deal with exceptions below. |
| 1625 | |
| 1626 | // ES 2.0 requires that the internal/external formats match. |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1627 | bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() || |
| 1628 | ctxInfo.version() >= GR_GL_VER(3,0)); |
| 1629 | // All ES versions (thus far) require sized internal formats for render buffers. |
| 1630 | // TODO: Always use sized internal format? |
| 1631 | bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard(); |
| 1632 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1633 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1634 | // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format> |
| 1635 | // param to glTex[Sub]Image. |
| 1636 | fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] = |
| 1637 | fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage]; |
| 1638 | fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ? |
| 1639 | fConfigTable[i].fFormats.fSizedInternalFormat : |
| 1640 | fConfigTable[i].fFormats.fBaseInternalFormat; |
| 1641 | fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ? |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1642 | fConfigTable[i].fFormats.fSizedInternalFormat : |
| 1643 | fConfigTable[i].fFormats.fBaseInternalFormat; |
| 1644 | } |
| 1645 | // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format> |
| 1646 | // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match. |
| 1647 | // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param. |
| 1648 | // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage. |
| 1649 | if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) { |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1650 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] = |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1651 | GR_GL_SRGB_ALPHA; |
| 1652 | } |
| 1653 | |
| 1654 | // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image |
| 1655 | // as a base format. |
| 1656 | // GL_EXT_texture_format_BGRA8888: |
| 1657 | // This extension GL_BGRA as an unsized internal format. However, it is written against ES |
| 1658 | // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal |
| 1659 | // formats. |
| 1660 | // GL_APPLE_texture_format_BGRA8888: |
| 1661 | // ES 2.0: the extension makes BGRA an external format but not an internal format. |
| 1662 | // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for |
| 1663 | // glTexImage (just for glTexStorage). |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1664 | if (useSizedTexFormats && this->bgraIsInternalFormat()) { |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1665 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA; |
| 1666 | } |
| 1667 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1668 | // If we don't have texture swizzle support then the shader generator must insert the |
| 1669 | // swizzle into shader code. |
| 1670 | if (!this->textureSwizzleSupport()) { |
| 1671 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 1672 | glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle; |
| 1673 | } |
| 1674 | } |
| 1675 | |
bsalomon | 7f9b2e4 | 2016-01-12 13:29:26 -0800 | [diff] [blame] | 1676 | // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to |
| 1677 | // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel |
| 1678 | // gets written to the single component. |
| 1679 | if (this->textureRedSupport()) { |
| 1680 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 1681 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
| 1682 | if (GrPixelConfigIsAlphaOnly(config) && |
| 1683 | fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) { |
| 1684 | glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA(); |
| 1685 | } |
| 1686 | } |
| 1687 | } |
| 1688 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1689 | #ifdef SK_DEBUG |
| 1690 | // Make sure we initialized everything. |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1691 | ConfigInfo defaultEntry; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1692 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1693 | SkASSERT(defaultEntry.fFormats.fBaseInternalFormat != |
| 1694 | fConfigTable[i].fFormats.fBaseInternalFormat); |
| 1695 | SkASSERT(defaultEntry.fFormats.fSizedInternalFormat != |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1696 | fConfigTable[i].fFormats.fSizedInternalFormat); |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1697 | for (int j = 0; j < kExternalFormatUsageCnt; ++j) { |
| 1698 | SkASSERT(defaultEntry.fFormats.fExternalFormat[j] != |
| 1699 | fConfigTable[i].fFormats.fExternalFormat[j]); |
| 1700 | } |
| 1701 | SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1702 | } |
| 1703 | #endif |
| 1704 | } |
| 1705 | |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 1706 | void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {} |