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