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