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