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