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" |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 15 | #include "SkJSONWriter.h" |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 16 | #include "SkTSearch.h" |
bsalomon@google.com | 20f7f17 | 2013-05-17 19:05:03 +0000 | [diff] [blame] | 17 | #include "SkTSort.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; |
Robert Phillips | 5ab7276 | 2017-06-07 12:04:18 -0400 | [diff] [blame] | 35 | fAlpha8IsRenderable = false; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 36 | fImagingSupport = false; |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 37 | fVertexArrayObjectSupport = false; |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 38 | fDebugSupport = false; |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 39 | fES2CompatibilitySupport = false; |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 40 | fDrawIndirectSupport = false; |
| 41 | fMultiDrawIndirectSupport = false; |
| 42 | fBaseInstanceSupport = false; |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 43 | fIsCoreProfile = false; |
joshualitt | c1f56b5 | 2015-06-22 12:31:31 -0700 | [diff] [blame] | 44 | fBindFragDataLocationSupport = false; |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 45 | fRectangleTextureSupport = false; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 46 | fTextureSwizzleSupport = false; |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 47 | fRGBA8888PixelsOpsAreSlow = false; |
| 48 | fPartialFBOReadIsSlow = false; |
cblume | 09bd2c0 | 2016-03-01 14:08:28 -0800 | [diff] [blame] | 49 | fMipMapLevelAndLodControlSupport = false; |
ericrk | b4ecabd | 2016-03-11 15:18:20 -0800 | [diff] [blame] | 50 | fRGBAToBGRAReadbackConversionsAreSlow = false; |
Robert Phillips | f2ec024 | 2018-03-01 16:51:25 -0500 | [diff] [blame] | 51 | fUseBufferDataNullHint = SkToBool(GR_GL_USE_BUFFER_DATA_NULL_HINT); |
brianosman | 09563ce | 2016-06-02 08:59:34 -0700 | [diff] [blame] | 52 | fDoManualMipmapping = false; |
brianosman | 851c238 | 2016-12-07 10:03:25 -0800 | [diff] [blame] | 53 | fSRGBDecodeDisableAffectsMipmaps = false; |
Eric Karl | aeaf22b | 2017-05-18 15:08:09 -0700 | [diff] [blame] | 54 | fClearToBoundaryValuesIsBroken = false; |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 55 | fClearTextureSupport = false; |
Chris Dalton | 9926f4b | 2017-05-17 15:15:50 -0600 | [diff] [blame] | 56 | fDrawArraysBaseVertexIsBroken = false; |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 57 | fUseDrawToClearColor = false; |
Mike Klein | 31550db | 2017-06-06 23:29:53 +0000 | [diff] [blame] | 58 | fUseDrawToClearStencilClip = false; |
Brian Salomon | 9bada54 | 2017-06-12 12:09:30 -0400 | [diff] [blame] | 59 | fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false; |
| 60 | fUseDrawInsteadOfAllRenderTargetWrites = false; |
Brian Salomon | 6d9c88b | 2017-06-12 10:24:42 -0400 | [diff] [blame] | 61 | fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false; |
Ethan Nicholas | 06d55fb | 2017-11-08 09:48:50 -0500 | [diff] [blame] | 62 | fProgramBinarySupport = false; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 63 | |
Brian Salomon | e5e7eb1 | 2016-10-14 16:18:33 -0400 | [diff] [blame] | 64 | fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag; |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 65 | fMaxInstancesPerDrawArraysWithoutCrashing = 0; |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 66 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 67 | fShaderCaps.reset(new GrShaderCaps(contextOptions)); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 68 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 69 | this->init(contextOptions, ctxInfo, glInterface); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 70 | } |
| 71 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 72 | void GrGLCaps::init(const GrContextOptions& contextOptions, |
| 73 | const GrGLContextInfo& ctxInfo, |
| 74 | const GrGLInterface* gli) { |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 75 | GrGLStandard standard = ctxInfo.standard(); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 76 | GrGLVersion version = ctxInfo.version(); |
| 77 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 78 | if (kGLES_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 79 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
| 80 | &fMaxFragmentUniformVectors); |
| 81 | } else { |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 82 | SkASSERT(kGL_GrGLStandard == standard); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 83 | GrGLint max; |
| 84 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); |
| 85 | fMaxFragmentUniformVectors = max / 4; |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 86 | if (version >= GR_GL_VER(3, 2)) { |
| 87 | GrGLint profileMask; |
| 88 | GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); |
| 89 | fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); |
| 90 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 91 | } |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 92 | GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 93 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 94 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 95 | fUnpackRowLengthSupport = true; |
| 96 | fUnpackFlipYSupport = false; |
| 97 | fPackRowLengthSupport = true; |
| 98 | fPackFlipYSupport = false; |
| 99 | } else { |
commit-bot@chromium.org | dc3134c | 2013-08-16 16:12:23 +0000 | [diff] [blame] | 100 | fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) || |
| 101 | ctxInfo.hasExtension("GL_EXT_unpack_subimage"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 102 | fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy"); |
commit-bot@chromium.org | dc3134c | 2013-08-16 16:12:23 +0000 | [diff] [blame] | 103 | fPackRowLengthSupport = version >= GR_GL_VER(3,0) || |
| 104 | ctxInfo.hasExtension("GL_NV_pack_subimage"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 105 | fPackFlipYSupport = |
| 106 | ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order"); |
| 107 | } |
| 108 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 109 | fTextureUsageSupport = (kGLES_GrGLStandard == standard) && |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 110 | ctxInfo.hasExtension("GL_ANGLE_texture_usage"); |
| 111 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 112 | if (kGL_GrGLStandard == standard) { |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 113 | fTextureBarrierSupport = version >= GR_GL_VER(4,5) || |
| 114 | ctxInfo.hasExtension("GL_ARB_texture_barrier") || |
| 115 | ctxInfo.hasExtension("GL_NV_texture_barrier"); |
| 116 | } else { |
| 117 | fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier"); |
| 118 | } |
| 119 | |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 120 | if (kGL_GrGLStandard == standard) { |
| 121 | fSampleLocationsSupport = version >= GR_GL_VER(3,2) || |
| 122 | ctxInfo.hasExtension("GL_ARB_texture_multisample"); |
| 123 | } else { |
| 124 | fSampleLocationsSupport = version >= GR_GL_VER(3,1); |
| 125 | } |
| 126 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 127 | fImagingSupport = kGL_GrGLStandard == standard && |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 128 | ctxInfo.hasExtension("GL_ARB_imaging"); |
| 129 | |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 130 | if (((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) || |
egdaniel | 9250d24 | 2015-05-18 13:04:26 -0700 | [diff] [blame] | 131 | (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) || |
| 132 | ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) { |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 133 | fDiscardRenderTargetSupport = true; |
| 134 | fInvalidateFBType = kInvalidate_InvalidateFBType; |
| 135 | } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) { |
| 136 | fDiscardRenderTargetSupport = true; |
| 137 | fInvalidateFBType = kDiscard_InvalidateFBType; |
| 138 | } |
robertphillips@google.com | a6ffb58 | 2013-04-29 16:50:17 +0000 | [diff] [blame] | 139 | |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 140 | // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and |
| 141 | // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1. |
| 142 | if (kGLES_GrGLStandard == standard) { |
| 143 | // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively. |
| 144 | // TODO: Evaluate on PowerVR. |
| 145 | // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it. |
| 146 | if (kARM_GrGLVendor == ctxInfo.vendor()) { |
| 147 | fUsePrimitiveRestart = version >= GR_GL_VER(3,0); |
| 148 | } |
| 149 | } |
| 150 | |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 151 | if (kARM_GrGLVendor == ctxInfo.vendor() || |
| 152 | kImagination_GrGLVendor == ctxInfo.vendor() || |
| 153 | kQualcomm_GrGLVendor == ctxInfo.vendor() ) { |
| 154 | fPreferFullscreenClears = true; |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 155 | } |
| 156 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 157 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 158 | fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
tomhudson | 612e926 | 2014-11-24 11:22:36 -0800 | [diff] [blame] | 159 | ctxInfo.hasExtension("GL_ARB_vertex_array_object") || |
| 160 | ctxInfo.hasExtension("GL_APPLE_vertex_array_object"); |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 161 | } else { |
commit-bot@chromium.org | 2276c01 | 2013-08-16 15:53:33 +0000 | [diff] [blame] | 162 | fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
| 163 | ctxInfo.hasExtension("GL_OES_vertex_array_object"); |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 164 | } |
| 165 | |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 166 | if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) { |
| 167 | fDebugSupport = true; |
| 168 | } else { |
| 169 | fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug"); |
| 170 | } |
| 171 | |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 172 | if (kGL_GrGLStandard == standard) { |
| 173 | fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility"); |
| 174 | } |
| 175 | else { |
| 176 | fES2CompatibilitySupport = true; |
| 177 | } |
| 178 | |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 179 | if (kGL_GrGLStandard == standard) { |
| 180 | fMultisampleDisableSupport = true; |
| 181 | } else { |
kkinnunen | bf49e46 | 2015-07-30 22:43:52 -0700 | [diff] [blame] | 182 | fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility"); |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 183 | } |
| 184 | |
kkinnunen | d94708e | 2015-07-30 22:47:04 -0700 | [diff] [blame] | 185 | if (kGL_GrGLStandard == standard) { |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 186 | // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about |
| 187 | // instanced arrays, but we could make this more granular if we wanted |
| 188 | fInstanceAttribSupport = |
| 189 | version >= GR_GL_VER(3, 2) || |
| 190 | (ctxInfo.hasExtension("GL_ARB_draw_instanced") && |
| 191 | ctxInfo.hasExtension("GL_ARB_instanced_arrays")); |
| 192 | } else { |
| 193 | fInstanceAttribSupport = |
| 194 | version >= GR_GL_VER(3, 0) || |
| 195 | (ctxInfo.hasExtension("GL_EXT_draw_instanced") && |
| 196 | ctxInfo.hasExtension("GL_EXT_instanced_arrays")); |
| 197 | } |
| 198 | |
| 199 | if (kGL_GrGLStandard == standard) { |
kkinnunen | d94708e | 2015-07-30 22:47:04 -0700 | [diff] [blame] | 200 | if (version >= GR_GL_VER(3, 0)) { |
| 201 | fBindFragDataLocationSupport = true; |
| 202 | } |
| 203 | } else { |
| 204 | if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) { |
| 205 | fBindFragDataLocationSupport = true; |
| 206 | } |
joshualitt | c1f56b5 | 2015-06-22 12:31:31 -0700 | [diff] [blame] | 207 | } |
| 208 | |
joshualitt | 7bdd70a | 2015-10-01 06:28:11 -0700 | [diff] [blame] | 209 | fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location"); |
| 210 | |
kkinnunen | e06ed25 | 2016-02-16 23:15:40 -0800 | [diff] [blame] | 211 | if (kGL_GrGLStandard == standard) { |
| 212 | if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) { |
| 213 | // We also require textureSize() support for rectangle 2D samplers which was added in |
| 214 | // GLSL 1.40. |
| 215 | if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) { |
| 216 | fRectangleTextureSupport = true; |
| 217 | } |
bsalomon | e179a91 | 2016-01-20 06:18:10 -0800 | [diff] [blame] | 218 | } |
kkinnunen | e06ed25 | 2016-02-16 23:15:40 -0800 | [diff] [blame] | 219 | } else { |
| 220 | // Command buffer exposes this in GL ES context for Chromium reasons, |
| 221 | // but it should not be used. Also, at the time of writing command buffer |
| 222 | // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support. |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 223 | } |
| 224 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 225 | if (kGL_GrGLStandard == standard) { |
| 226 | if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) { |
| 227 | fTextureSwizzleSupport = true; |
| 228 | } |
| 229 | } else { |
| 230 | if (version >= GR_GL_VER(3,0)) { |
| 231 | fTextureSwizzleSupport = true; |
| 232 | } |
| 233 | } |
| 234 | |
cblume | 09bd2c0 | 2016-03-01 14:08:28 -0800 | [diff] [blame] | 235 | if (kGL_GrGLStandard == standard) { |
| 236 | fMipMapLevelAndLodControlSupport = true; |
| 237 | } else if (kGLES_GrGLStandard == standard) { |
| 238 | if (version >= GR_GL_VER(3,0)) { |
| 239 | fMipMapLevelAndLodControlSupport = true; |
| 240 | } |
| 241 | } |
| 242 | |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 243 | #ifdef SK_BUILD_FOR_WIN |
| 244 | // We're assuming that on Windows Chromium we're using ANGLE. |
| 245 | bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() || |
| 246 | kChromium_GrGLDriver == ctxInfo.driver(); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 247 | // 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] | 248 | fRGBA8888PixelsOpsAreSlow = isANGLE; |
| 249 | // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and |
| 250 | // check DX11 ANGLE. |
| 251 | fPartialFBOReadIsSlow = isANGLE; |
| 252 | #endif |
| 253 | |
ericrk | b4ecabd | 2016-03-11 15:18:20 -0800 | [diff] [blame] | 254 | bool isMESA = kMesa_GrGLDriver == ctxInfo.driver(); |
| 255 | bool isMAC = false; |
| 256 | #ifdef SK_BUILD_FOR_MAC |
| 257 | isMAC = true; |
| 258 | #endif |
| 259 | |
| 260 | // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or |
| 261 | // vis-versa. |
| 262 | fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC; |
| 263 | |
Robert Phillips | f2ec024 | 2018-03-01 16:51:25 -0500 | [diff] [blame] | 264 | if (GrContextOptions::Enable::kNo == contextOptions.fUseGLBufferDataNullHint) { |
| 265 | fUseBufferDataNullHint = false; |
| 266 | } else if (GrContextOptions::Enable::kYes == contextOptions.fUseGLBufferDataNullHint) { |
| 267 | fUseBufferDataNullHint = true; |
| 268 | } |
| 269 | |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 270 | if (kGL_GrGLStandard == standard) { |
| 271 | if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) { |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 272 | fClearTextureSupport = true; |
| 273 | } |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 274 | } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) { |
| 275 | fClearTextureSupport = true; |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 276 | } |
| 277 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 278 | /************************************************************************** |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 279 | * GrShaderCaps fields |
| 280 | **************************************************************************/ |
| 281 | |
egdaniel | 0a48233 | 2015-10-26 08:59:10 -0700 | [diff] [blame] | 282 | // This must be called after fCoreProfile is set on the GrGLCaps |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 283 | this->initGLSL(ctxInfo, gli); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 284 | GrShaderCaps* shaderCaps = fShaderCaps.get(); |
egdaniel | 0a48233 | 2015-10-26 08:59:10 -0700 | [diff] [blame] | 285 | |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 286 | shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli); |
| 287 | #if GR_TEST_UTILS |
| 288 | if (contextOptions.fSuppressPathRendering) { |
| 289 | shaderCaps->fPathRenderingSupport = false; |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 290 | } |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 291 | #endif |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 292 | |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 293 | // Enable supported shader-related caps |
| 294 | if (kGL_GrGLStandard == standard) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 295 | shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) || |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 296 | ctxInfo.hasExtension("GL_ARB_blend_func_extended")) && |
| 297 | GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration()); |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 298 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 299 | shaderCaps->fShaderDerivativeSupport = true; |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 300 | |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 301 | // 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] | 302 | shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) && |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 303 | ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 304 | if (shaderCaps->fGeometryShaderSupport) { |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 305 | if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) { |
| 306 | shaderCaps->fGSInvocationsSupport = true; |
| 307 | } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) { |
| 308 | shaderCaps->fGSInvocationsSupport = true; |
| 309 | shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5"; |
| 310 | } |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 311 | } |
| 312 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 313 | shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) && |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 314 | ctxInfo.glslGeneration() >= k130_GrGLSLGeneration; |
Chris Dalton | 8fd7955 | 2018-01-11 00:46:14 -0500 | [diff] [blame] | 315 | } else { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 316 | shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended"); |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 317 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 318 | shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) || |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 319 | ctxInfo.hasExtension("GL_OES_standard_derivatives"); |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 320 | |
Chris Dalton | faca00d | 2018-01-19 15:56:07 -0700 | [diff] [blame] | 321 | // Mali has support for geometry shaders, but in practice with ccpr they are slower than the |
| 322 | // backup impl that only uses vertex shaders. |
| 323 | if (kARM_GrGLVendor != ctxInfo.vendor()) { |
| 324 | if (ctxInfo.version() >= GR_GL_VER(3,2)) { |
| 325 | shaderCaps->fGeometryShaderSupport = true; |
| 326 | } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) { |
| 327 | shaderCaps->fGeometryShaderSupport = true; |
| 328 | shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader"; |
| 329 | } |
Chris Dalton | faca00d | 2018-01-19 15:56:07 -0700 | [diff] [blame] | 330 | shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport; |
Chris Dalton | 8fd7955 | 2018-01-11 00:46:14 -0500 | [diff] [blame] | 331 | } |
csmartdalton | 1d2aed0 | 2017-02-15 21:43:20 -0700 | [diff] [blame] | 332 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 333 | shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) && |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 334 | ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0. |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 335 | } |
| 336 | |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 337 | // Protect ourselves against tracking huge amounts of texture state. |
| 338 | static const uint8_t kMaxSaneSamplers = 32; |
| 339 | GrGLint maxSamplers; |
| 340 | GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 341 | shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers); |
| 342 | if (shaderCaps->fGeometryShaderSupport) { |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 343 | GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 344 | shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers); |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 345 | } |
| 346 | GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 347 | shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers); |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 348 | GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 349 | shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers); |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 350 | |
Brian Salomon | bbf0575 | 2017-11-30 11:30:48 -0500 | [diff] [blame] | 351 | // This is all *very* approximate. |
| 352 | switch (ctxInfo.vendor()) { |
| 353 | case kNVIDIA_GrGLVendor: |
| 354 | // We've seen a range from 100 x 100 (TegraK1, GTX660) up to 300 x 300 (GTX 1070) |
| 355 | // but it doesn't clearly align with Pascal vs Maxwell vs Kepler. |
| 356 | fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 150 * 150; |
| 357 | break; |
Brian Salomon | 64fa70a | 2017-11-30 11:56:25 -0500 | [diff] [blame] | 358 | case kImagination_GrGLVendor: |
| 359 | // Two PowerVR Rogues, Nexus Player and Chromebook Cb5-312T (PowerVR GX6250), show that |
| 360 | // it is always a win to use multitexturing. |
| 361 | if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) { |
| 362 | fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = |
| 363 | std::numeric_limits<size_t>::max(); |
| 364 | } |
| 365 | break; |
Brian Salomon | 0c56d47 | 2017-12-04 08:37:44 -0500 | [diff] [blame] | 366 | case kATI_GrGLVendor: |
| 367 | // So far no AMD GPU shows a performance difference. A tie goes to disabling |
| 368 | // multitexturing for simplicity's sake. |
| 369 | fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 0; |
| 370 | break; |
Brian Salomon | bbf0575 | 2017-11-30 11:30:48 -0500 | [diff] [blame] | 371 | default: |
| 372 | break; |
| 373 | } |
| 374 | |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 375 | // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with |
| 376 | // frequently changing VBOs. We've measured a performance increase using non-VBO vertex |
| 377 | // data for dynamic content on these GPUs. Perhaps we should read the renderer string and |
| 378 | // limit this decision to specific GPU families rather than basing it on the vendor alone. |
| 379 | if (!GR_GL_MUST_USE_VBO && |
| 380 | !fIsCoreProfile && |
| 381 | (kARM_GrGLVendor == ctxInfo.vendor() || |
| 382 | kImagination_GrGLVendor == ctxInfo.vendor() || |
| 383 | kQualcomm_GrGLVendor == ctxInfo.vendor())) { |
| 384 | fPreferClientSideDynamicBuffers = true; |
| 385 | } |
| 386 | |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 387 | if (!contextOptions.fAvoidStencilBuffers) { |
| 388 | // To reduce surface area, if we avoid stencil buffers, we also disable MSAA. |
| 389 | this->initFSAASupport(contextOptions, ctxInfo, gli); |
| 390 | this->initStencilSupport(ctxInfo); |
| 391 | } |
Greg Daniel | cd2f512 | 2017-05-25 10:50:40 -0400 | [diff] [blame] | 392 | |
| 393 | // Setup blit framebuffer |
| 394 | if (kGL_GrGLStandard != ctxInfo.standard()) { |
| 395 | if (ctxInfo.version() >= GR_GL_VER(3, 0)) { |
| 396 | fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag | |
| 397 | kNoMSAADst_BlitFramebufferFlag | |
| 398 | kRectsMustMatchForMSAASrc_BlitFramebufferFlag; |
| 399 | } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") || |
| 400 | ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) { |
| 401 | // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its |
| 402 | // limitations. |
| 403 | fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag | |
| 404 | kResolveMustBeFull_BlitFrambufferFlag | |
| 405 | kNoMSAADst_BlitFramebufferFlag | |
| 406 | kNoFormatConversion_BlitFramebufferFlag | |
| 407 | kRectsMustMatchForMSAASrc_BlitFramebufferFlag; |
| 408 | } |
| 409 | } else { |
| 410 | if (fUsesMixedSamples || |
| 411 | ctxInfo.version() >= GR_GL_VER(3,0) || |
| 412 | ctxInfo.hasExtension("GL_ARB_framebuffer_object") || |
| 413 | ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { |
| 414 | fBlitFramebufferFlags = 0; |
| 415 | } |
| 416 | } |
| 417 | |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 418 | this->initBlendEqationSupport(ctxInfo); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 419 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 420 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 421 | fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO |
| 422 | // extension includes glMapBuffer. |
| 423 | if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) { |
| 424 | fMapBufferFlags |= kSubset_MapFlag; |
| 425 | fMapBufferType = kMapBufferRange_MapBufferType; |
| 426 | } else { |
| 427 | fMapBufferType = kMapBuffer_MapBufferType; |
| 428 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 429 | } else { |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 430 | // Unextended GLES2 doesn't have any buffer mapping. |
| 431 | fMapBufferFlags = kNone_MapBufferType; |
kkinnunen | f655e93 | 2016-03-03 07:39:48 -0800 | [diff] [blame] | 432 | if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) { |
kkinnunen | 45c2c81 | 2016-02-25 02:03:43 -0800 | [diff] [blame] | 433 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 434 | fMapBufferType = kChromium_MapBufferType; |
kkinnunen | f655e93 | 2016-03-03 07:39:48 -0800 | [diff] [blame] | 435 | } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) { |
| 436 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 437 | fMapBufferType = kMapBufferRange_MapBufferType; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 438 | } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) { |
| 439 | fMapBufferFlags = kCanMap_MapFlag; |
| 440 | fMapBufferType = kMapBuffer_MapBufferType; |
| 441 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 442 | } |
| 443 | |
jvanverth | d7a2c1f | 2015-12-07 07:36:44 -0800 | [diff] [blame] | 444 | if (kGL_GrGLStandard == standard) { |
| 445 | if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) { |
| 446 | fTransferBufferType = kPBO_TransferBufferType; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 447 | } |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 448 | } else { |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 449 | if (version >= GR_GL_VER(3, 0) || |
| 450 | (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") && |
| 451 | // GL_EXT_unpack_subimage needed to support subtexture rectangles |
| 452 | ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) { |
jvanverth | d7a2c1f | 2015-12-07 07:36:44 -0800 | [diff] [blame] | 453 | fTransferBufferType = kPBO_TransferBufferType; |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 454 | // TODO: get transfer buffers working in Chrome |
| 455 | // } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) { |
| 456 | // fTransferBufferType = kChromium_TransferBufferType; |
jvanverth | d7a2c1f | 2015-12-07 07:36:44 -0800 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
joshualitt | e5b74c6 | 2015-06-01 14:17:47 -0700 | [diff] [blame] | 460 | // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the |
| 461 | // 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] | 462 | if (fBufferMapThreshold < 0) { |
bsalomon | bc23375 | 2015-06-26 11:38:25 -0700 | [diff] [blame] | 463 | #if 0 |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 464 | // We think mapping on Chromium will be cheaper once we know ahead of time how much space |
| 465 | // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and |
| 466 | // using a small subset. |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 467 | fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32; |
bsalomon | bc23375 | 2015-06-26 11:38:25 -0700 | [diff] [blame] | 468 | #else |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 469 | fBufferMapThreshold = SK_MaxS32; |
bsalomon | bc23375 | 2015-06-26 11:38:25 -0700 | [diff] [blame] | 470 | #endif |
joshualitt | e5b74c6 | 2015-06-01 14:17:47 -0700 | [diff] [blame] | 471 | } |
| 472 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 473 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 474 | fNPOTTextureTileSupport = true; |
| 475 | fMipMapSupport = true; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 476 | } else { |
| 477 | // 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] | 478 | // ES3 has no limitations. |
| 479 | fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) || |
| 480 | ctxInfo.hasExtension("GL_OES_texture_npot"); |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 481 | // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP |
| 482 | // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently, |
| 483 | // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to |
| 484 | // to alllow arbitrary wrap modes, however. |
| 485 | fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot"); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 486 | } |
| 487 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 488 | GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize); |
| 489 | GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize); |
| 490 | // Our render targets are always created with textures as the color |
| 491 | // attachment, hence this min: |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 492 | fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize); |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 493 | fMaxPreferredRenderTargetSize = fMaxRenderTargetSize; |
| 494 | |
| 495 | if (kARM_GrGLVendor == ctxInfo.vendor()) { |
| 496 | // On Mali G71, RT's above 4k have been observed to incur a performance cost. |
| 497 | fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize); |
| 498 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 499 | |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 500 | fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker"); |
| 501 | |
robertphillips@google.com | 8995b7b | 2013-11-01 15:03:34 +0000 | [diff] [blame] | 502 | // Disable scratch texture reuse on Mali and Adreno devices |
brianosman | 5702c86 | 2016-08-09 14:02:13 -0700 | [diff] [blame] | 503 | fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor(); |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 504 | |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 505 | #if 0 |
| 506 | fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() && |
| 507 | kQualcomm_GrGLVendor != ctxInfo.vendor(); |
| 508 | #endif |
| 509 | |
csmartdalton | 9bc1187 | 2016-08-09 12:42:47 -0700 | [diff] [blame] | 510 | if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) { |
| 511 | GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles); |
csmartdalton | 9bc1187 | 2016-08-09 12:42:47 -0700 | [diff] [blame] | 512 | } |
| 513 | |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 514 | #ifdef SK_BUILD_FOR_WIN |
| 515 | // On ANGLE deferring flushes can lead to GPU starvation |
| 516 | fPreferVRAMUseOverFlushes = !isANGLE; |
| 517 | #endif |
| 518 | |
bsalomon | 7dea7b7 | 2015-08-19 08:26:51 -0700 | [diff] [blame] | 519 | if (kChromium_GrGLDriver == ctxInfo.driver()) { |
| 520 | fMustClearUploadedBufferData = true; |
| 521 | } |
| 522 | |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 523 | if (kGL_GrGLStandard == standard) { |
| 524 | // ARB allows mixed size FBO attachments, EXT does not. |
| 525 | if (ctxInfo.version() >= GR_GL_VER(3, 0) || |
| 526 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
| 527 | fOversizedStencilSupport = true; |
| 528 | } else { |
| 529 | SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object")); |
| 530 | } |
| 531 | } else { |
| 532 | // ES 3.0 supports mixed size FBO attachments, 2.0 does not. |
| 533 | fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0); |
| 534 | } |
| 535 | |
joshualitt | 5800155 | 2015-06-26 12:46:36 -0700 | [diff] [blame] | 536 | if (kGL_GrGLStandard == standard) { |
csmartdalton | 5cebf8c | 2016-06-03 08:28:47 -0700 | [diff] [blame] | 537 | fDrawIndirectSupport = version >= GR_GL_VER(4,0) || |
| 538 | ctxInfo.hasExtension("GL_ARB_draw_indirect"); |
| 539 | fBaseInstanceSupport = version >= GR_GL_VER(4,2); |
| 540 | fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) || |
csmartdalton | 4c18b62 | 2016-07-29 12:19:28 -0700 | [diff] [blame] | 541 | (fDrawIndirectSupport && |
| 542 | !fBaseInstanceSupport && // The ARB extension has no base inst. |
csmartdalton | 5cebf8c | 2016-06-03 08:28:47 -0700 | [diff] [blame] | 543 | ctxInfo.hasExtension("GL_ARB_multi_draw_indirect")); |
bsalomon | fc9527a | 2016-08-29 09:18:39 -0700 | [diff] [blame] | 544 | fDrawRangeElementsSupport = version >= GR_GL_VER(2,0); |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 545 | } else { |
| 546 | fDrawIndirectSupport = version >= GR_GL_VER(3,1); |
csmartdalton | 4c18b62 | 2016-07-29 12:19:28 -0700 | [diff] [blame] | 547 | fMultiDrawIndirectSupport = fDrawIndirectSupport && |
| 548 | ctxInfo.hasExtension("GL_EXT_multi_draw_indirect"); |
| 549 | fBaseInstanceSupport = fDrawIndirectSupport && |
| 550 | ctxInfo.hasExtension("GL_EXT_base_instance"); |
bsalomon | fc9527a | 2016-08-29 09:18:39 -0700 | [diff] [blame] | 551 | fDrawRangeElementsSupport = version >= GR_GL_VER(3,0); |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 552 | } |
| 553 | |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 554 | if (kGL_GrGLStandard == standard) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 555 | if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) { |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 556 | fSampleShadingSupport = true; |
| 557 | } |
| 558 | } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) { |
| 559 | fSampleShadingSupport = true; |
| 560 | } |
| 561 | |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 562 | // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync |
| 563 | if (kGL_GrGLStandard == standard) { |
| 564 | if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) { |
| 565 | fFenceSyncSupport = true; |
| 566 | } |
Brian Osman | 93a2346 | 2017-06-21 15:13:39 -0400 | [diff] [blame] | 567 | } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) { |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 568 | fFenceSyncSupport = true; |
| 569 | } |
| 570 | |
Brian Osman | 0eb4ecb | 2017-05-16 13:30:11 -0400 | [diff] [blame] | 571 | // Safely moving textures between contexts requires fences. |
Brian Osman | 2c2bc11 | 2017-02-28 10:02:49 -0500 | [diff] [blame] | 572 | fCrossContextTextureSupport = fFenceSyncSupport; |
Brian Osman | 2c2bc11 | 2017-02-28 10:02:49 -0500 | [diff] [blame] | 573 | |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 574 | fSRGBDecodeDisableSupport = ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode"); |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 575 | |
brianosman | 851c238 | 2016-12-07 10:03:25 -0800 | [diff] [blame] | 576 | fSRGBDecodeDisableAffectsMipmaps = fSRGBDecodeDisableSupport && |
| 577 | kChromium_GrGLDriver != ctxInfo.driver(); |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 578 | |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 579 | if (kGL_GrGLStandard == standard) { |
| 580 | if (version >= GR_GL_VER(4, 1)) { |
| 581 | fProgramBinarySupport = true; |
| 582 | } |
| 583 | } else if (version >= GR_GL_VER(3, 0)) { |
| 584 | fProgramBinarySupport = true; |
| 585 | } |
Ethan Nicholas | 98ad5b7 | 2018-03-13 09:53:02 -0400 | [diff] [blame] | 586 | if (fProgramBinarySupport) { |
| 587 | GrGLint count; |
| 588 | GR_GL_GetIntegerv(gli, GR_GL_NUM_SHADER_BINARY_FORMATS, &count); |
| 589 | fProgramBinarySupport = count > 0; |
| 590 | } |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 591 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 592 | // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have |
| 593 | // already been detected. |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 594 | this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps); |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 595 | |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 596 | if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { |
| 597 | this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps); |
| 598 | } |
| 599 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 600 | this->applyOptionsOverrides(contextOptions); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 601 | shaderCaps->applyOptionsOverrides(contextOptions); |
Chris Dalton | 0a94e4c | 2018-01-18 15:06:50 -0700 | [diff] [blame] | 602 | |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 603 | // For now these two are equivalent but we could have dst read in shader via some other method. |
| 604 | shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 605 | } |
| 606 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 607 | const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation, |
| 608 | bool isCoreProfile) { |
| 609 | switch (generation) { |
| 610 | case k110_GrGLSLGeneration: |
| 611 | if (kGLES_GrGLStandard == standard) { |
| 612 | // ES2s shader language is based on version 1.20 but is version |
| 613 | // 1.00 of the ES language. |
| 614 | return "#version 100\n"; |
| 615 | } else { |
| 616 | SkASSERT(kGL_GrGLStandard == standard); |
| 617 | return "#version 110\n"; |
| 618 | } |
| 619 | case k130_GrGLSLGeneration: |
| 620 | SkASSERT(kGL_GrGLStandard == standard); |
| 621 | return "#version 130\n"; |
| 622 | case k140_GrGLSLGeneration: |
| 623 | SkASSERT(kGL_GrGLStandard == standard); |
| 624 | return "#version 140\n"; |
| 625 | case k150_GrGLSLGeneration: |
| 626 | SkASSERT(kGL_GrGLStandard == standard); |
| 627 | if (isCoreProfile) { |
| 628 | return "#version 150\n"; |
| 629 | } else { |
| 630 | return "#version 150 compatibility\n"; |
| 631 | } |
| 632 | case k330_GrGLSLGeneration: |
| 633 | if (kGLES_GrGLStandard == standard) { |
| 634 | return "#version 300 es\n"; |
| 635 | } else { |
| 636 | SkASSERT(kGL_GrGLStandard == standard); |
| 637 | if (isCoreProfile) { |
| 638 | return "#version 330\n"; |
| 639 | } else { |
| 640 | return "#version 330 compatibility\n"; |
| 641 | } |
| 642 | } |
cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 643 | case k400_GrGLSLGeneration: |
| 644 | SkASSERT(kGL_GrGLStandard == standard); |
| 645 | if (isCoreProfile) { |
| 646 | return "#version 400\n"; |
| 647 | } else { |
| 648 | return "#version 400 compatibility\n"; |
| 649 | } |
Brian Salomon | d327e8c | 2016-11-15 13:26:08 -0500 | [diff] [blame] | 650 | case k420_GrGLSLGeneration: |
| 651 | SkASSERT(kGL_GrGLStandard == standard); |
| 652 | if (isCoreProfile) { |
| 653 | return "#version 420\n"; |
| 654 | } |
| 655 | else { |
| 656 | return "#version 420 compatibility\n"; |
| 657 | } |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 658 | case k310es_GrGLSLGeneration: |
| 659 | SkASSERT(kGLES_GrGLStandard == standard); |
| 660 | return "#version 310 es\n"; |
cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 661 | case k320es_GrGLSLGeneration: |
| 662 | SkASSERT(kGLES_GrGLStandard == standard); |
| 663 | return "#version 320 es\n"; |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 664 | } |
| 665 | return "<no version>"; |
| 666 | } |
| 667 | |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 668 | bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) { |
| 669 | if (kGLES_GrGLStandard != ctxInfo.standard() && |
| 670 | ctxInfo.version() < GR_GL_VER(4,1) && |
| 671 | !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) { |
| 672 | // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float. |
| 673 | return true; |
| 674 | } |
| 675 | // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the |
| 676 | // geometry shaders don't have lower precision than vertex and fragment. |
| 677 | for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) { |
| 678 | GrGLint range[2]; |
| 679 | GrGLint bits; |
| 680 | GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits); |
| 681 | if (range[0] < 127 || range[1] < 127 || bits < 23) { |
| 682 | return false; |
| 683 | } |
| 684 | } |
| 685 | return true; |
| 686 | } |
| 687 | |
| 688 | void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 689 | GrGLStandard standard = ctxInfo.standard(); |
| 690 | GrGLVersion version = ctxInfo.version(); |
| 691 | |
| 692 | /************************************************************************** |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 693 | * Caps specific to GrShaderCaps |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 694 | **************************************************************************/ |
| 695 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 696 | GrShaderCaps* shaderCaps = fShaderCaps.get(); |
| 697 | shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration(); |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 698 | if (kGLES_GrGLStandard == standard) { |
| 699 | if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 700 | shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0)); |
| 701 | shaderCaps->fFBFetchSupport = true; |
| 702 | shaderCaps->fFBFetchColorName = "gl_LastFragData[0]"; |
| 703 | shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch"; |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 704 | } |
| 705 | else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) { |
| 706 | // 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] | 707 | shaderCaps->fFBFetchNeedsCustomOutput = false; |
| 708 | shaderCaps->fFBFetchSupport = true; |
| 709 | shaderCaps->fFBFetchColorName = "gl_LastFragData[0]"; |
| 710 | shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch"; |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 711 | } |
| 712 | else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) { |
| 713 | // 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] | 714 | shaderCaps->fFBFetchNeedsCustomOutput = false; |
| 715 | shaderCaps->fFBFetchSupport = true; |
| 716 | shaderCaps->fFBFetchColorName = "gl_LastFragColorARM"; |
| 717 | shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch"; |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 718 | } |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 719 | shaderCaps->fUsesPrecisionModifiers = true; |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 720 | } |
| 721 | |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 722 | if (kGL_GrGLStandard == standard) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 723 | shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration; |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 724 | } else { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 725 | shaderCaps->fFlatInterpolationSupport = |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 726 | ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0. |
| 727 | } |
Brian Salomon | 4127456 | 2017-09-15 09:40:03 -0700 | [diff] [blame] | 728 | // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530). |
| 729 | shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport && |
| 730 | kQualcomm_GrGLVendor != ctxInfo.vendor(); |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 731 | if (kGL_GrGLStandard == standard) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 732 | shaderCaps->fNoPerspectiveInterpolationSupport = |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 733 | ctxInfo.glslGeneration() >= k130_GrGLSLGeneration; |
| 734 | } else { |
| 735 | if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 736 | shaderCaps->fNoPerspectiveInterpolationSupport = true; |
| 737 | shaderCaps->fNoPerspectiveInterpolationExtensionString = |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 738 | "GL_NV_shader_noperspective_interpolation"; |
| 739 | } |
| 740 | } |
| 741 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 742 | shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard, |
| 743 | shaderCaps->fGLSLGeneration, |
| 744 | fIsCoreProfile); |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 745 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 746 | if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) { |
| 747 | shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives"; |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 748 | } |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 749 | |
| 750 | // Frag Coords Convention support is not part of ES |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 751 | if (kGLES_GrGLStandard != standard && |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 752 | (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration || |
| 753 | ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 754 | shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions"; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | if (kGLES_GrGLStandard == standard) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 758 | shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended"; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 759 | } |
| 760 | |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 761 | if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) { |
Brian Osman | c585e20 | 2018-04-04 14:08:27 -0400 | [diff] [blame] | 762 | if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) { |
| 763 | shaderCaps->fExternalTextureSupport = true; |
Brian Osman | 91fba61 | 2018-03-15 14:12:04 -0400 | [diff] [blame] | 764 | shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external"; |
Brian Osman | c585e20 | 2018-04-04 14:08:27 -0400 | [diff] [blame] | 765 | } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") || |
| 766 | ctxInfo.hasExtension("OES_EGL_image_external_essl3")) { |
| 767 | // At least one driver has been found that has this extension without the "GL_" prefix. |
| 768 | shaderCaps->fExternalTextureSupport = true; |
| 769 | shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3"; |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | |
cdalton | c04ce67 | 2016-03-11 14:07:38 -0800 | [diff] [blame] | 773 | if (kGL_GrGLStandard == standard) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 774 | shaderCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration; |
cdalton | c04ce67 | 2016-03-11 14:07:38 -0800 | [diff] [blame] | 775 | } else { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 776 | shaderCaps->fTexelFetchSupport = |
cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 777 | ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0. |
| 778 | } |
| 779 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 780 | if (shaderCaps->fTexelFetchSupport) { |
cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 781 | if (kGL_GrGLStandard == standard) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 782 | shaderCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(3, 1) && |
cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 783 | ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; |
| 784 | } else { |
| 785 | if (ctxInfo.version() >= GR_GL_VER(3, 2) && |
| 786 | ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 787 | shaderCaps->fTexelBufferSupport = true; |
cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 788 | } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 789 | shaderCaps->fTexelBufferSupport = true; |
| 790 | shaderCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer"; |
cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 791 | } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 792 | shaderCaps->fTexelBufferSupport = true; |
| 793 | shaderCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer"; |
cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 794 | } |
cdalton | c04ce67 | 2016-03-11 14:07:38 -0800 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 798 | if (kGL_GrGLStandard == standard) { |
| 799 | shaderCaps->fVertexIDSupport = true; |
| 800 | } else { |
| 801 | // Desktop GLSL 3.30 == ES GLSL 3.00. |
| 802 | shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; |
| 803 | } |
| 804 | |
Chris Dalton | 7c7ff03 | 2018-03-28 20:09:58 -0600 | [diff] [blame] | 805 | if (kGL_GrGLStandard == standard) { |
| 806 | shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration; |
| 807 | } else { |
| 808 | shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration; |
| 809 | } |
| 810 | |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 811 | shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT); |
| 812 | shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT); |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 813 | } |
| 814 | |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 815 | bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 816 | bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering"); |
| 817 | |
| 818 | if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) { |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 819 | return false; |
| 820 | } |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 821 | |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 822 | if (kGL_GrGLStandard == ctxInfo.standard()) { |
| 823 | if (ctxInfo.version() < GR_GL_VER(4, 3) && |
| 824 | !ctxInfo.hasExtension("GL_ARB_program_interface_query")) { |
| 825 | return false; |
| 826 | } |
| 827 | } else { |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 828 | if (!hasChromiumPathRendering && |
| 829 | ctxInfo.version() < GR_GL_VER(3, 1)) { |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 830 | return false; |
| 831 | } |
| 832 | } |
| 833 | // We only support v1.3+ of GL_NV_path_rendering which allows us to |
| 834 | // set individual fragment inputs with ProgramPathFragmentInputGen. The API |
| 835 | // additions are detected by checking the existence of the function. |
| 836 | // We also use *Then* functions that not all drivers might have. Check |
| 837 | // them for consistency. |
bsalomon | 9f2dc27 | 2016-02-08 07:22:17 -0800 | [diff] [blame] | 838 | if (!gli->fFunctions.fStencilThenCoverFillPath || |
| 839 | !gli->fFunctions.fStencilThenCoverStrokePath || |
| 840 | !gli->fFunctions.fStencilThenCoverFillPathInstanced || |
| 841 | !gli->fFunctions.fStencilThenCoverStrokePathInstanced || |
| 842 | !gli->fFunctions.fProgramPathFragmentInputGen) { |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 843 | return false; |
| 844 | } |
| 845 | return true; |
| 846 | } |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 847 | |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 848 | bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig, |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 849 | GrPixelConfig readConfig, |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 850 | std::function<void (GrGLenum, GrGLint*)> getIntegerv, |
bsalomon | 2c3db32 | 2016-11-08 13:26:24 -0800 | [diff] [blame] | 851 | std::function<bool ()> bindRenderTarget, |
| 852 | std::function<void ()> unbindRenderTarget) const { |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 853 | // 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] | 854 | // not supported regardless of readConfig. |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 855 | if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) { |
bsalomon | e957331 | 2016-01-25 14:33:25 -0800 | [diff] [blame] | 856 | return false; |
| 857 | } |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 858 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 859 | GrGLenum readFormat; |
| 860 | GrGLenum readType; |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 861 | if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) { |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 862 | return false; |
| 863 | } |
| 864 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 865 | if (kGL_GrGLStandard == fStandard) { |
bsalomon | e957331 | 2016-01-25 14:33:25 -0800 | [diff] [blame] | 866 | // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However, |
| 867 | // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed: |
| 868 | // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE, |
| 869 | // 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] | 870 | // The manual does not seem to fully match the spec as the spec allows integer formats |
| 871 | // when the bound color buffer is an integer buffer. It doesn't specify which integer |
| 872 | // 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] | 873 | if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB && |
| 874 | readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA && |
| 875 | readFormat != GR_GL_RGBA_INTEGER) { |
bsalomon | e957331 | 2016-01-25 14:33:25 -0800 | [diff] [blame] | 876 | return false; |
| 877 | } |
| 878 | // There is also a set of allowed types, but all the types we use are in the set: |
| 879 | // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, |
| 880 | // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, |
| 881 | // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, |
| 882 | // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, |
| 883 | // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2, |
| 884 | // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV, |
| 885 | // 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] | 886 | return true; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 887 | } |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 888 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 889 | // See Section 16.1.2 in the ES 3.2 specification. |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 890 | switch (fConfigTable[surfaceConfig].fFormatType) { |
| 891 | case kNormalizedFixedPoint_FormatType: |
| 892 | if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) { |
| 893 | return true; |
| 894 | } |
| 895 | break; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 896 | case kFloat_FormatType: |
| 897 | if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) { |
| 898 | return true; |
| 899 | } |
| 900 | break; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 901 | } |
| 902 | |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 903 | if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) { |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 904 | ReadPixelsFormat* rpFormat = |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 905 | const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat); |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 906 | GrGLint format = 0, type = 0; |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 907 | if (!bindRenderTarget()) { |
| 908 | return false; |
| 909 | } |
| 910 | getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format); |
| 911 | getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type); |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 912 | rpFormat->fFormat = format; |
| 913 | rpFormat->fType = type; |
bsalomon | 2c3db32 | 2016-11-08 13:26:24 -0800 | [diff] [blame] | 914 | unbindRenderTarget(); |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 915 | } |
| 916 | |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 917 | return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat && |
| 918 | fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 921 | void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo, |
| 922 | const GrGLInterface* gli) { |
| 923 | // We need dual source blending and the ability to disable multisample in order to support mixed |
| 924 | // samples in every corner case. We only use mixed samples if the stencil-and-cover path |
| 925 | // renderer is available and enabled; no other path renderers support this feature. |
| 926 | if (fMultisampleDisableSupport && |
| 927 | this->shaderCaps()->dualSourceBlendingSupport() && |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 928 | this->shaderCaps()->pathRenderingSupport() |
| 929 | #if GR_TEST_UTILS |
| 930 | && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) |
| 931 | #endif |
| 932 | ) { |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 933 | fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") || |
Robert Phillips | 3b3307f | 2017-05-24 07:44:02 -0400 | [diff] [blame] | 934 | ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples"); |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 935 | } |
| 936 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 937 | if (kGL_GrGLStandard != ctxInfo.standard()) { |
Greg Daniel | 2501917 | 2017-10-26 13:32:33 -0400 | [diff] [blame] | 938 | if (ctxInfo.version() >= GR_GL_VER(3,0) && |
| 939 | ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) { |
| 940 | // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though |
| 941 | // it is part of the spec. Thus alpha8 will not be renderable for those devices. |
| 942 | fAlpha8IsRenderable = true; |
| 943 | } |
Brian Salomon | 25d07fc | 2018-03-07 09:01:05 -0500 | [diff] [blame] | 944 | // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed |
| 945 | // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using |
| 946 | // mixed samples we can't use multisampled-render-to-texture. |
| 947 | if (fUsesMixedSamples) { |
| 948 | fMSFBOType = kMixedSamples_MSFBOType; |
| 949 | } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 950 | fMSFBOType = kES_EXT_MsToTexture_MSFBOType; |
| 951 | } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { |
| 952 | fMSFBOType = kES_IMG_MsToTexture_MSFBOType; |
Robert Phillips | 5ab7276 | 2017-06-07 12:04:18 -0400 | [diff] [blame] | 953 | } else if (ctxInfo.version() >= GR_GL_VER(3,0)) { |
| 954 | fMSFBOType = kStandard_MSFBOType; |
Robert Phillips | 5ab7276 | 2017-06-07 12:04:18 -0400 | [diff] [blame] | 955 | } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
Brian Salomon | 00731b4 | 2016-10-14 11:30:51 -0400 | [diff] [blame] | 956 | fMSFBOType = kStandard_MSFBOType; |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 957 | } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) { |
Robert Phillips | 5ab7276 | 2017-06-07 12:04:18 -0400 | [diff] [blame] | 958 | fMSFBOType = kStandard_MSFBOType; |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 959 | } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { |
| 960 | fMSFBOType = kES_Apple_MSFBOType; |
| 961 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 962 | } else { |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 963 | if (fUsesMixedSamples) { |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 964 | fMSFBOType = kMixedSamples_MSFBOType; |
Brian Salomon | 00731b4 | 2016-10-14 11:30:51 -0400 | [diff] [blame] | 965 | } else if (ctxInfo.version() >= GR_GL_VER(3,0) || |
| 966 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
Robert Phillips | 5ab7276 | 2017-06-07 12:04:18 -0400 | [diff] [blame] | 967 | |
Brian Salomon | 00731b4 | 2016-10-14 11:30:51 -0400 | [diff] [blame] | 968 | fMSFBOType = kStandard_MSFBOType; |
Robert Phillips | 5ab7276 | 2017-06-07 12:04:18 -0400 | [diff] [blame] | 969 | if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) { |
| 970 | // Core profile removes ALPHA8 support. |
| 971 | // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable. |
| 972 | // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is |
| 973 | // present. |
| 974 | fAlpha8IsRenderable = true; |
| 975 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 976 | } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && |
| 977 | ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { |
Robert Phillips | 5ab7276 | 2017-06-07 12:04:18 -0400 | [diff] [blame] | 978 | fMSFBOType = kStandard_MSFBOType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 979 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 980 | } |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 981 | |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 982 | // We disable MSAA across the board for Intel GPUs for performance reasons. |
Robert Phillips | 3b3307f | 2017-05-24 07:44:02 -0400 | [diff] [blame] | 983 | if (kIntel_GrGLVendor == ctxInfo.vendor()) { |
| 984 | fMSFBOType = kNone_MSFBOType; |
| 985 | } |
| 986 | |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 987 | // We only have a use for raster multisample if there is coverage modulation from mixed samples. |
| 988 | if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) { |
| 989 | GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples); |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 990 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 991 | } |
| 992 | |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 993 | void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 994 | GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get()); |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 995 | |
Greg Daniel | 210883c | 2017-11-27 15:14:01 -0500 | [diff] [blame] | 996 | bool layoutQualifierSupport = false; |
| 997 | if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) || |
| 998 | (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) { |
| 999 | layoutQualifierSupport = true; |
| 1000 | } |
| 1001 | |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 1002 | if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) { |
| 1003 | fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport; |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 1004 | shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction; |
Greg Daniel | 210883c | 2017-11-27 15:14:01 -0500 | [diff] [blame] | 1005 | } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") && |
| 1006 | layoutQualifierSupport) { |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 1007 | fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport; |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 1008 | shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction; |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 1009 | } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) { |
| 1010 | fBlendEquationSupport = kAdvanced_BlendEquationSupport; |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 1011 | shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction; |
Greg Daniel | 210883c | 2017-11-27 15:14:01 -0500 | [diff] [blame] | 1012 | } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) { |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 1013 | fBlendEquationSupport = kAdvanced_BlendEquationSupport; |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 1014 | shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction; |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 1015 | // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is |
| 1016 | // slow on a particular platform. |
joel.liang | 9764c40 | 2015-07-09 19:46:18 -0700 | [diff] [blame] | 1017 | } |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1020 | namespace { |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1021 | const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 1024 | void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1025 | |
| 1026 | // Build up list of legal stencil formats (though perhaps not supported on |
| 1027 | // the particular gpu/driver) from most preferred to least. |
| 1028 | |
| 1029 | // these consts are in order of most preferred to least preferred |
| 1030 | // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 |
| 1031 | |
| 1032 | static const StencilFormat |
| 1033 | // internal Format stencil bits total bits packed? |
| 1034 | gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, |
| 1035 | gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, |
| 1036 | gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, |
| 1037 | gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 1038 | // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1039 | gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; |
| 1040 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 1041 | if (kGL_GrGLStandard == ctxInfo.standard()) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1042 | bool supportsPackedDS = |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1043 | ctxInfo.version() >= GR_GL_VER(3,0) || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1044 | ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || |
| 1045 | ctxInfo.hasExtension("GL_ARB_framebuffer_object"); |
| 1046 | |
| 1047 | // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we |
| 1048 | // require FBO support we can expect these are legal formats and don't |
| 1049 | // check. These also all support the unsized GL_STENCIL_INDEX. |
| 1050 | fStencilFormats.push_back() = gS8; |
| 1051 | fStencilFormats.push_back() = gS16; |
| 1052 | if (supportsPackedDS) { |
| 1053 | fStencilFormats.push_back() = gD24S8; |
| 1054 | } |
| 1055 | fStencilFormats.push_back() = gS4; |
| 1056 | if (supportsPackedDS) { |
| 1057 | fStencilFormats.push_back() = gDS; |
| 1058 | } |
| 1059 | } else { |
| 1060 | // ES2 has STENCIL_INDEX8 without extensions but requires extensions |
| 1061 | // for other formats. |
| 1062 | // ES doesn't support using the unsized format. |
| 1063 | |
| 1064 | fStencilFormats.push_back() = gS8; |
| 1065 | //fStencilFormats.push_back() = gS16; |
commit-bot@chromium.org | 04c500f | 2013-09-06 15:28:01 +0000 | [diff] [blame] | 1066 | if (ctxInfo.version() >= GR_GL_VER(3,0) || |
| 1067 | ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1068 | fStencilFormats.push_back() = gD24S8; |
| 1069 | } |
| 1070 | if (ctxInfo.hasExtension("GL_OES_stencil4")) { |
| 1071 | fStencilFormats.push_back() = gS4; |
| 1072 | } |
| 1073 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1076 | void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1077 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1078 | // We are called by the base class, which has already called beginObject(). We choose to nest |
| 1079 | // all of our caps information in a named sub-object. |
| 1080 | writer->beginObject("GL caps"); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1081 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1082 | writer->beginArray("Stencil Formats"); |
| 1083 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1084 | for (int i = 0; i < fStencilFormats.count(); ++i) { |
Brian Osman | 8048822 | 2017-08-10 13:29:30 -0400 | [diff] [blame] | 1085 | writer->beginObject(nullptr, false); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1086 | writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits); |
| 1087 | writer->appendS32("total bits", fStencilFormats[i].fTotalBits); |
| 1088 | writer->endObject(); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1091 | writer->endArray(); |
| 1092 | |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 1093 | static const char* kMSFBOExtStr[] = { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1094 | "None", |
Brian Salomon | 00731b4 | 2016-10-14 11:30:51 -0400 | [diff] [blame] | 1095 | "Standard", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1096 | "Apple", |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 1097 | "IMG MS To Texture", |
| 1098 | "EXT MS To Texture", |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 1099 | "MixedSamples", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1100 | }; |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 1101 | GR_STATIC_ASSERT(0 == kNone_MSFBOType); |
Robert Phillips | 5ab7276 | 2017-06-07 12:04:18 -0400 | [diff] [blame] | 1102 | GR_STATIC_ASSERT(1 == kStandard_MSFBOType); |
| 1103 | GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType); |
| 1104 | GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType); |
| 1105 | GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType); |
| 1106 | GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 1107 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1); |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 1108 | |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 1109 | static const char* kInvalidateFBTypeStr[] = { |
| 1110 | "None", |
| 1111 | "Discard", |
| 1112 | "Invalidate", |
| 1113 | }; |
| 1114 | GR_STATIC_ASSERT(0 == kNone_InvalidateFBType); |
| 1115 | GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType); |
| 1116 | GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType); |
| 1117 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1); |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 1118 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 1119 | static const char* kMapBufferTypeStr[] = { |
| 1120 | "None", |
| 1121 | "MapBuffer", |
| 1122 | "MapBufferRange", |
| 1123 | "Chromium", |
| 1124 | }; |
| 1125 | GR_STATIC_ASSERT(0 == kNone_MapBufferType); |
| 1126 | GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType); |
| 1127 | GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType); |
| 1128 | GR_STATIC_ASSERT(3 == kChromium_MapBufferType); |
| 1129 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1); |
| 1130 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1131 | writer->appendBool("Core Profile", fIsCoreProfile); |
| 1132 | writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]); |
| 1133 | writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]); |
| 1134 | writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]); |
| 1135 | writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors); |
| 1136 | writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport); |
| 1137 | writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport); |
| 1138 | writer->appendBool("Pack Row length support", fPackRowLengthSupport); |
| 1139 | writer->appendBool("Pack Flip Y support", fPackFlipYSupport); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1140 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1141 | writer->appendBool("Texture Usage support", fTextureUsageSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1142 | writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable); |
| 1143 | writer->appendBool("GL_ARB_imaging support", fImagingSupport); |
| 1144 | writer->appendBool("Vertex array object support", fVertexArrayObjectSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1145 | writer->appendBool("Debug support", fDebugSupport); |
| 1146 | writer->appendBool("Draw indirect support", fDrawIndirectSupport); |
| 1147 | writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport); |
| 1148 | writer->appendBool("Base instance support", fBaseInstanceSupport); |
| 1149 | writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow); |
| 1150 | writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow); |
| 1151 | writer->appendBool("Bind uniform location support", fBindUniformLocationSupport); |
| 1152 | writer->appendBool("Rectangle texture support", fRectangleTextureSupport); |
| 1153 | writer->appendBool("Texture swizzle support", fTextureSwizzleSupport); |
| 1154 | writer->appendBool("BGRA to RGBA readback conversions are slow", |
| 1155 | fRGBAToBGRAReadbackConversionsAreSlow); |
Robert Phillips | f2ec024 | 2018-03-01 16:51:25 -0500 | [diff] [blame] | 1156 | writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 1157 | writer->appendBool("Draw To clear color", fUseDrawToClearColor); |
| 1158 | writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1159 | writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs", |
| 1160 | fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO); |
| 1161 | writer->appendBool("Intermediate texture for all updates of textures bound to FBOs", |
| 1162 | fUseDrawInsteadOfAllRenderTargetWrites); |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 1163 | writer->appendBool("Max instances per glDrawArraysInstanced without crashing (or zero)", |
| 1164 | fMaxInstancesPerDrawArraysWithoutCrashing); |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1165 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1166 | writer->beginArray("configs"); |
| 1167 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1168 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
Brian Osman | 8048822 | 2017-08-10 13:29:30 -0400 | [diff] [blame] | 1169 | writer->beginObject(nullptr, false); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1170 | writer->appendHexU32("flags", fConfigTable[i].fFlags); |
| 1171 | writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat); |
| 1172 | writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat); |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1173 | writer->appendHexU32("e_format_read_pixels", |
| 1174 | fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1175 | writer->appendHexU32( |
| 1176 | "e_format_teximage", |
| 1177 | fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]); |
| 1178 | writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType); |
| 1179 | writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage); |
| 1180 | writer->appendHexU32("i_for_renderbuffer", |
| 1181 | fConfigTable[i].fFormats.fInternalFormatRenderbuffer); |
| 1182 | writer->endObject(); |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1183 | } |
| 1184 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1185 | writer->endArray(); |
| 1186 | writer->endObject(); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1189 | bool GrGLCaps::bgraIsInternalFormat() const { |
| 1190 | return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA; |
| 1191 | } |
| 1192 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1193 | bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig, |
| 1194 | GrGLenum* internalFormat, GrGLenum* externalFormat, |
| 1195 | GrGLenum* externalType) const { |
| 1196 | if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage, |
| 1197 | externalFormat, externalType)) { |
| 1198 | return false; |
| 1199 | } |
| 1200 | *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage; |
| 1201 | return true; |
| 1202 | } |
| 1203 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1204 | bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig, |
| 1205 | GrGLenum* externalFormat, GrGLenum* externalType) const { |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1206 | if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage, |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1207 | externalFormat, externalType)) { |
| 1208 | return false; |
| 1209 | } |
| 1210 | return true; |
| 1211 | } |
| 1212 | |
| 1213 | bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const { |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1214 | *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer; |
| 1215 | return true; |
| 1216 | } |
| 1217 | |
| 1218 | bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig, |
| 1219 | ExternalFormatUsage usage, GrGLenum* externalFormat, |
| 1220 | GrGLenum* externalType) const { |
| 1221 | SkASSERT(externalFormat && externalType); |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1222 | |
| 1223 | bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig); |
| 1224 | bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig); |
| 1225 | |
| 1226 | // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 1227 | // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but |
| 1228 | // is not needed currently. |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1229 | if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) { |
| 1230 | return false; |
| 1231 | } |
| 1232 | |
| 1233 | *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage]; |
| 1234 | *externalType = fConfigTable[memoryConfig].fFormats.fExternalType; |
| 1235 | |
bsalomon | e957331 | 2016-01-25 14:33:25 -0800 | [diff] [blame] | 1236 | // When GL_RED is supported as a texture format, our alpha-only textures are stored using |
| 1237 | // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the |
| 1238 | // surface is not alpha-only and we want alpha to really mean the alpha component of the |
| 1239 | // texture, not the red component. |
| 1240 | if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) { |
Brian Salomon | e609e81 | 2018-01-17 14:00:47 -0500 | [diff] [blame] | 1241 | if (GR_GL_RED == *externalFormat) { |
bsalomon | e957331 | 2016-01-25 14:33:25 -0800 | [diff] [blame] | 1242 | *externalFormat = GR_GL_ALPHA; |
| 1243 | } |
| 1244 | } |
| 1245 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1246 | return true; |
| 1247 | } |
| 1248 | |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 1249 | void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, |
| 1250 | const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 1251 | GrShaderCaps* shaderCaps) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1252 | /* |
| 1253 | Comments on renderability of configs on various GL versions. |
| 1254 | OpenGL < 3.0: |
| 1255 | no built in support for render targets. |
| 1256 | GL_EXT_framebuffer_object adds possible support for any sized format with base internal |
| 1257 | format RGB, RGBA and NV float formats we don't use. |
| 1258 | This is the following: |
| 1259 | R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8 |
| 1260 | RGB10_A2, RGBA12,RGBA16 |
| 1261 | Though, it is hard to believe the more obscure formats such as RGBA12 would work |
| 1262 | since they aren't required by later standards and the driver can simply return |
| 1263 | FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow. |
| 1264 | GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally |
| 1265 | any sized internal format with a base internal format of ALPHA, LUMINANCE, |
| 1266 | LUMINANCE_ALPHA, INTENSITY, RED, and RG. |
| 1267 | This adds a lot of additional renderable sized formats, including ALPHA8. |
| 1268 | The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI, |
| 1269 | 16F, 32I, 32UI, and 32F variants). |
| 1270 | Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED. |
| 1271 | |
| 1272 | For both the above extensions we limit ourselves to those that are also required by |
| 1273 | OpenGL 3.0. |
| 1274 | |
| 1275 | OpenGL 3.0: |
| 1276 | Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable" |
| 1277 | but are not required to be supported as renderable textures/renderbuffer. |
| 1278 | Required renderable color formats: |
| 1279 | - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I, |
| 1280 | RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and |
| 1281 | RGB10_A2. |
| 1282 | - R11F_G11F_B10F. |
| 1283 | - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I, |
| 1284 | and RG8UI. |
| 1285 | - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI. |
| 1286 | - ALPHA8 |
| 1287 | |
| 1288 | OpenGL 3.1, 3.2, 3.3 |
| 1289 | Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile. |
| 1290 | OpengGL 3.3, 4.0, 4.1 |
| 1291 | Adds RGB10_A2UI. |
| 1292 | OpengGL 4.2 |
| 1293 | Adds |
| 1294 | - RGB5_A1, RGBA4 |
| 1295 | - RGB565 |
| 1296 | OpenGL 4.4 |
| 1297 | Does away with the separate list and adds a column to the sized internal color format |
| 1298 | table. However, no new formats become required color renderable. |
| 1299 | |
| 1300 | ES 2.0 |
| 1301 | color renderable: RGBA4, RGB5_A1, RGB565 |
| 1302 | GL_EXT_texture_rg adds support for R8, RG5 as a color render target |
| 1303 | GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8 |
| 1304 | GL_ARM_rgba8 adds support for RGBA8 (but not RGB8) |
| 1305 | GL_EXT_texture_format_BGRA8888 does not add renderbuffer support |
| 1306 | GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable |
| 1307 | GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support |
| 1308 | |
| 1309 | ES 3.0 |
| 1310 | - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I, |
| 1311 | RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and |
| 1312 | RGB5_A1. |
| 1313 | - RGB8 and RGB565. |
| 1314 | - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI. |
| 1315 | - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI |
| 1316 | ES 3.1 |
| 1317 | Adds RGB10_A2, RGB10_A2UI, |
| 1318 | ES 3.2 |
| 1319 | Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F. |
| 1320 | */ |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1321 | |
| 1322 | // Correctness workarounds. |
| 1323 | bool disableTextureRedForMesa = false; |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1324 | bool disableSRGBForX86PowerVR = false; |
| 1325 | bool disableSRGBWriteControlForAdreno4xx = false; |
| 1326 | bool disableR8TexStorageForANGLEGL = false; |
| 1327 | bool disableSRGBRenderWithMSAAForMacAMD = false; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1328 | bool disableRGB8ForMali400 = false; |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1329 | |
| 1330 | if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { |
| 1331 | // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED |
| 1332 | // and GL_RG on FBO textures. |
| 1333 | disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer(); |
| 1334 | |
| 1335 | bool isX86PowerVR = false; |
| 1336 | #if defined(SK_CPU_X86) |
| 1337 | if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) { |
| 1338 | isX86PowerVR = true; |
| 1339 | } |
| 1340 | #endif |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1341 | // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to |
| 1342 | // blacklist that device (and any others that might be sharing the same driver). |
| 1343 | disableSRGBForX86PowerVR = isX86PowerVR; |
| 1344 | disableSRGBWriteControlForAdreno4xx = kAdreno4xx_GrGLRenderer == ctxInfo.renderer(); |
| 1345 | |
| 1346 | // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8 |
| 1347 | // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to |
| 1348 | // check that we are not going to OpenGL. |
| 1349 | disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend(); |
| 1350 | |
| 1351 | // MacPro devices with AMD cards fail to create MSAA sRGB render buffers. |
| 1352 | #if defined(SK_BUILD_FOR_MAC) |
| 1353 | disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor(); |
| 1354 | #endif |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1355 | // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8. |
| 1356 | disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer(); |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1357 | } |
| 1358 | |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 1359 | uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag | |
| 1360 | ConfigInfo::kFBOColorAttachment_Flag; |
| 1361 | uint32_t allRenderFlags = nonMSAARenderFlags; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1362 | if (kNone_MSFBOType != fMSFBOType) { |
| 1363 | allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag; |
| 1364 | } |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1365 | GrGLStandard standard = ctxInfo.standard(); |
| 1366 | GrGLVersion version = ctxInfo.version(); |
| 1367 | |
cblume | 790d513 | 2016-02-29 11:13:29 -0800 | [diff] [blame] | 1368 | bool texStorageSupported = false; |
| 1369 | if (kGL_GrGLStandard == standard) { |
| 1370 | // The EXT version can apply to either GL or GLES. |
| 1371 | texStorageSupported = version >= GR_GL_VER(4,2) || |
| 1372 | ctxInfo.hasExtension("GL_ARB_texture_storage") || |
| 1373 | ctxInfo.hasExtension("GL_EXT_texture_storage"); |
| 1374 | } else { |
Brian Salomon | 3ab83e2 | 2016-11-28 13:14:00 -0500 | [diff] [blame] | 1375 | texStorageSupported = version >= GR_GL_VER(3,0) || |
| 1376 | ctxInfo.hasExtension("GL_EXT_texture_storage"); |
cblume | 790d513 | 2016-02-29 11:13:29 -0800 | [diff] [blame] | 1377 | } |
| 1378 | |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 1379 | bool texelBufferSupport = this->shaderCaps()->texelBufferSupport(); |
| 1380 | |
Brian Salomon | e609e81 | 2018-01-17 14:00:47 -0500 | [diff] [blame] | 1381 | bool textureRedSupport = false; |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1382 | |
| 1383 | if (!disableTextureRedForMesa) { |
Brian Salomon | e609e81 | 2018-01-17 14:00:47 -0500 | [diff] [blame] | 1384 | if (kGL_GrGLStandard == standard) { |
| 1385 | textureRedSupport = |
| 1386 | version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg"); |
| 1387 | } else { |
| 1388 | textureRedSupport = |
| 1389 | version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg"); |
| 1390 | } |
| 1391 | } |
| 1392 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1393 | fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0; |
| 1394 | fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1395 | fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1396 | fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1397 | fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1398 | fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1399 | |
| 1400 | fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; |
| 1401 | fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1402 | fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1403 | GR_GL_RGBA; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1404 | fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1405 | fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1406 | fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1407 | if (kGL_GrGLStandard == standard) { |
| 1408 | // We require some form of FBO support and all GLs with FBO support can render to RGBA8 |
| 1409 | fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags; |
egdaniel | 4999df8 | 2016-01-07 17:06:04 -0800 | [diff] [blame] | 1410 | } else { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1411 | if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || |
| 1412 | ctxInfo.hasExtension("GL_ARM_rgba8")) { |
| 1413 | fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags; |
| 1414 | } |
egdaniel | 4999df8 | 2016-01-07 17:06:04 -0800 | [diff] [blame] | 1415 | } |
cblume | 790d513 | 2016-02-29 11:13:29 -0800 | [diff] [blame] | 1416 | if (texStorageSupported) { |
| 1417 | fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1418 | } |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 1419 | if (texelBufferSupport) { |
| 1420 | fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag; |
| 1421 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1422 | fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1423 | |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1424 | fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB; |
| 1425 | fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8; |
| 1426 | // Our external RGB data always has a byte where alpha would be. When calling read pixels we |
| 1427 | // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would |
| 1428 | // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't |
| 1429 | // currently expect to ever read back GrColorType::kRGB_888x because our implementation of |
| 1430 | // supportedReadPixelsColorType never returns it. |
| 1431 | fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA; |
| 1432 | fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
| 1433 | fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
| 1434 | fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1435 | if (kGL_GrGLStandard == standard) { |
| 1436 | // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a |
| 1437 | // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL |
| 1438 | // we don't support MSAA for GL_RGB8. On 4.2+ we could check using |
| 1439 | // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this |
| 1440 | // becomes an issue. |
| 1441 | // This also would probably work in mixed-samples mode where there is no MSAA color buffer |
| 1442 | // but we don't support that just for simplicity's sake. |
| 1443 | fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags; |
| 1444 | } else { |
| 1445 | // 3.0 and the extension support this as a render buffer format. |
| 1446 | if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) { |
| 1447 | fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags; |
| 1448 | } |
| 1449 | } |
| 1450 | if (texStorageSupported) { |
| 1451 | fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1452 | } |
| 1453 | fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
| 1454 | if (disableRGB8ForMali400) { |
| 1455 | fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0; |
| 1456 | } |
| 1457 | |
| 1458 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1459 | GR_GL_BGRA; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1460 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1461 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
Greg Daniel | 0ff79b2 | 2018-02-15 12:33:33 -0500 | [diff] [blame] | 1462 | |
| 1463 | // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the |
| 1464 | // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and |
| 1465 | // GL_EXT_texture_format_BGRA8888. |
| 1466 | bool supportsBGRATexStorage = false; |
| 1467 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1468 | if (kGL_GrGLStandard == standard) { |
| 1469 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; |
| 1470 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8; |
| 1471 | if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) { |
| 1472 | // Since the internal format is RGBA8, it is also renderable. |
| 1473 | fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag | |
| 1474 | allRenderFlags; |
| 1475 | } |
Greg Daniel | 0ff79b2 | 2018-02-15 12:33:33 -0500 | [diff] [blame] | 1476 | // Since we are using RGBA8 we can use tex storage. |
| 1477 | supportsBGRATexStorage = true; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1478 | } else { |
| 1479 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA; |
| 1480 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8; |
Alexis Hetu | 0e90f98 | 2018-03-15 10:08:42 -0400 | [diff] [blame] | 1481 | if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) { |
| 1482 | fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag | |
| 1483 | nonMSAARenderFlags; |
| 1484 | |
| 1485 | if (ctxInfo.hasExtension("GL_EXT_texture_storage")) { |
| 1486 | supportsBGRATexStorage = true; |
| 1487 | } |
| 1488 | if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") && |
| 1489 | (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) { |
| 1490 | fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= |
| 1491 | ConfigInfo::kRenderableWithMSAA_Flag; |
| 1492 | } |
| 1493 | } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) { |
Brian Osman | 48c9919 | 2017-06-02 08:45:06 -0400 | [diff] [blame] | 1494 | // This APPLE extension introduces complexity on ES2. It leaves the internal format |
| 1495 | // as RGBA, but allows BGRA as the external format. From testing, it appears that the |
| 1496 | // driver remembers the external format when the texture is created (with TexImage). |
| 1497 | // If you then try to upload data in the other swizzle (with TexSubImage), it fails. |
| 1498 | // We could work around this, but it adds even more state tracking to code that is |
| 1499 | // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension. |
| 1500 | // This also side-steps some ambiguous interactions with the texture storage extension. |
| 1501 | if (version >= GR_GL_VER(3,0)) { |
| 1502 | // The APPLE extension doesn't make this renderable. |
| 1503 | fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
Greg Daniel | 0ff79b2 | 2018-02-15 12:33:33 -0500 | [diff] [blame] | 1504 | supportsBGRATexStorage = true; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1505 | } |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1506 | } |
| 1507 | } |
Brian Osman | 48c9919 | 2017-06-02 08:45:06 -0400 | [diff] [blame] | 1508 | |
Greg Daniel | 0ff79b2 | 2018-02-15 12:33:33 -0500 | [diff] [blame] | 1509 | if (texStorageSupported && supportsBGRATexStorage) { |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1510 | fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
cblume | 790d513 | 2016-02-29 11:13:29 -0800 | [diff] [blame] | 1511 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1512 | fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1513 | |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 1514 | // We only enable srgb support if both textures and FBOs support srgb, |
brianosman | 35b784d | 2016-05-05 11:52:53 -0700 | [diff] [blame] | 1515 | // *and* we can disable sRGB decode-on-read, to support "legacy" mode. |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1516 | if (kGL_GrGLStandard == standard) { |
| 1517 | if (ctxInfo.version() >= GR_GL_VER(3,0)) { |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 1518 | fSRGBSupport = true; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1519 | } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) { |
| 1520 | if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") || |
| 1521 | ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) { |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 1522 | fSRGBSupport = true; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | // All the above srgb extensions support toggling srgb writes |
bsalomon | 44d427e | 2016-05-10 09:05:06 -0700 | [diff] [blame] | 1526 | if (fSRGBSupport) { |
| 1527 | fSRGBWriteControl = true; |
| 1528 | } |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1529 | } else { |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 1530 | fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"); |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1531 | if (disableSRGBForX86PowerVR) { |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 1532 | fSRGBSupport = false; |
| 1533 | } |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1534 | // ES through 3.1 requires EXT_srgb_write_control to support toggling |
| 1535 | // sRGB writing for destinations. |
brianosman | c9986b6 | 2016-05-23 06:23:27 -0700 | [diff] [blame] | 1536 | // See https://bug.skia.org/5329 for Adreno4xx issue. |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1537 | fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx && |
brianosman | c9986b6 | 2016-05-23 06:23:27 -0700 | [diff] [blame] | 1538 | ctxInfo.hasExtension("GL_EXT_sRGB_write_control"); |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1539 | } |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 1540 | if (contextOptions.fRequireDecodeDisableForSRGB && !fSRGBDecodeDisableSupport) { |
| 1541 | // To support "legacy" L32 mode, we require the ability to turn off sRGB decode. Clients |
| 1542 | // 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] | 1543 | fSRGBSupport = false; |
| 1544 | } |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 1545 | |
| 1546 | // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable |
| 1547 | // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace, |
| 1548 | // and sBGRA is basically impossible to support on any version of ES (with our current code). |
| 1549 | // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair |
| 1550 | // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what |
| 1551 | // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily |
| 1552 | // affects Windows. |
| 1553 | if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) { |
| 1554 | fSRGBSupport = false; |
| 1555 | } |
| 1556 | |
Brian Osman | 48c9919 | 2017-06-02 08:45:06 -0400 | [diff] [blame] | 1557 | // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format |
| 1558 | // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions. |
| 1559 | bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0); |
| 1560 | |
Brian Osman | 6799939 | 2017-05-31 16:19:34 -0400 | [diff] [blame] | 1561 | uint32_t srgbRenderFlags = allRenderFlags; |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1562 | if (disableSRGBRenderWithMSAAForMacAMD) { |
Brian Osman | 6799939 | 2017-05-31 16:19:34 -0400 | [diff] [blame] | 1563 | srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag; |
| 1564 | } |
Brian Osman | 6799939 | 2017-05-31 16:19:34 -0400 | [diff] [blame] | 1565 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1566 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA; |
| 1567 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8; |
| 1568 | // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the |
| 1569 | // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image. |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1570 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1571 | GR_GL_RGBA; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1572 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1573 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 1574 | if (fSRGBSupport) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1575 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag | |
Brian Osman | 6799939 | 2017-05-31 16:19:34 -0400 | [diff] [blame] | 1576 | srgbRenderFlags; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1577 | } |
Brian Osman | 48c9919 | 2017-06-02 08:45:06 -0400 | [diff] [blame] | 1578 | // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT |
| 1579 | if (texStorageSupported && !isCommandBufferES2) { |
cblume | 790d513 | 2016-02-29 11:13:29 -0800 | [diff] [blame] | 1580 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1581 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1582 | fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 1583 | // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where |
| 1584 | // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows |
| 1585 | // is in this format, for example). |
| 1586 | fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA; |
| 1587 | fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8; |
| 1588 | // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the |
| 1589 | // external format is GL_BGRA. |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1590 | fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 1591 | GR_GL_BGRA; |
| 1592 | fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
| 1593 | fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 1594 | if (fSRGBSupport && kGL_GrGLStandard == standard) { |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 1595 | fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag | |
Brian Osman | 6799939 | 2017-05-31 16:19:34 -0400 | [diff] [blame] | 1596 | srgbRenderFlags; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 1597 | } |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 1598 | |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 1599 | if (texStorageSupported) { |
| 1600 | fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1601 | } |
| 1602 | fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
| 1603 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1604 | fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB; |
| 1605 | if (this->ES2CompatibilitySupport()) { |
| 1606 | fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565; |
| 1607 | } else { |
| 1608 | fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5; |
| 1609 | } |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1610 | fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1611 | GR_GL_RGB; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1612 | fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5; |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1613 | fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1614 | fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1615 | if (kGL_GrGLStandard == standard) { |
elemental | a675910 | 2016-11-18 23:11:29 +0100 | [diff] [blame] | 1616 | if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1617 | fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags; |
| 1618 | } |
| 1619 | } else { |
| 1620 | fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags; |
| 1621 | } |
cblume | 790d513 | 2016-02-29 11:13:29 -0800 | [diff] [blame] | 1622 | // 565 is not a sized internal format on desktop GL. So on desktop with |
| 1623 | // 565 we always use an unsized internal format to let the system pick |
| 1624 | // the best sized format to convert the 565 data to. Since TexStorage |
| 1625 | // only allows sized internal formats we disallow it. |
| 1626 | // |
| 1627 | // TODO: As of 4.2, regular GL supports 565. This logic is due for an |
| 1628 | // update. |
| 1629 | if (texStorageSupported && kGL_GrGLStandard != standard) { |
| 1630 | fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1631 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1632 | fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1633 | |
| 1634 | fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; |
| 1635 | fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1636 | fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1637 | GR_GL_RGBA; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1638 | 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] | 1639 | fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1640 | fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1641 | if (kGL_GrGLStandard == standard) { |
| 1642 | if (version >= GR_GL_VER(4, 2)) { |
| 1643 | fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags; |
| 1644 | } |
| 1645 | } else { |
| 1646 | fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags; |
| 1647 | } |
cblume | 790d513 | 2016-02-29 11:13:29 -0800 | [diff] [blame] | 1648 | if (texStorageSupported) { |
| 1649 | fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1650 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1651 | fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1652 | |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 1653 | fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; |
| 1654 | fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1655 | fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 1656 | GR_GL_RGBA; |
| 1657 | fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType = |
| 1658 | GR_GL_UNSIGNED_INT_2_10_10_10_REV; |
| 1659 | fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; |
| 1660 | if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) { |
| 1661 | fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag | |
| 1662 | allRenderFlags; |
| 1663 | } |
| 1664 | if (texStorageSupported) { |
| 1665 | fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1666 | } |
| 1667 | if (texelBufferSupport) { |
| 1668 | fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag; |
| 1669 | } |
| 1670 | fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
| 1671 | |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1672 | bool alpha8IsValidForGL = kGL_GrGLStandard == standard && |
| 1673 | (!fIsCoreProfile || version <= GR_GL_VER(3, 0)); |
| 1674 | |
| 1675 | ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig]; |
| 1676 | alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
| 1677 | alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType; |
| 1678 | if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) { |
| 1679 | alphaInfo.fFlags = ConfigInfo::kTextureable_Flag; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1680 | } |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1681 | alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA; |
| 1682 | alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1683 | alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA; |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1684 | alphaInfo.fSwizzle = GrSwizzle::AAAA(); |
| 1685 | if (fAlpha8IsRenderable && alpha8IsValidForGL) { |
| 1686 | alphaInfo.fFlags |= allRenderFlags; |
| 1687 | } |
| 1688 | |
| 1689 | ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig]; |
| 1690 | redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
| 1691 | redInfo.fFormatType = kNormalizedFixedPoint_FormatType; |
| 1692 | redInfo.fFormats.fBaseInternalFormat = GR_GL_RED; |
| 1693 | redInfo.fFormats.fSizedInternalFormat = GR_GL_R8; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1694 | redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED; |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1695 | redInfo.fSwizzle = GrSwizzle::RRRR(); |
Robert Phillips | 5ab7276 | 2017-06-07 12:04:18 -0400 | [diff] [blame] | 1696 | |
Brian Osman | 48c9919 | 2017-06-02 08:45:06 -0400 | [diff] [blame] | 1697 | // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8) |
| 1698 | if (texStorageSupported && !isCommandBufferES2) { |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1699 | if (!disableR8TexStorageForANGLEGL) { |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1700 | alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1701 | } |
| 1702 | redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1703 | } |
| 1704 | |
Brian Salomon | e609e81 | 2018-01-17 14:00:47 -0500 | [diff] [blame] | 1705 | if (textureRedSupport) { |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1706 | redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags; |
| 1707 | if (texelBufferSupport) { |
| 1708 | redInfo.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag; |
| 1709 | } |
| 1710 | |
| 1711 | fConfigTable[kAlpha_8_GrPixelConfig] = redInfo; |
| 1712 | } else { |
| 1713 | redInfo.fFlags = 0; |
| 1714 | |
| 1715 | fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo; |
cblume | 790d513 | 2016-02-29 11:13:29 -0800 | [diff] [blame] | 1716 | } |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1717 | |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 1718 | ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig]; |
| 1719 | grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
| 1720 | grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType; |
| 1721 | grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE; |
| 1722 | grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1723 | grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE; |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 1724 | grayLumInfo.fSwizzle = GrSwizzle::RGBA(); |
| 1725 | if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) || |
| 1726 | (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) { |
| 1727 | grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag; |
Brian Osman | 986563b | 2017-01-10 14:20:02 -0500 | [diff] [blame] | 1728 | } |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 1729 | |
| 1730 | ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig]; |
| 1731 | grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; |
| 1732 | grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType; |
| 1733 | grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED; |
| 1734 | grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1735 | grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED; |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 1736 | grayRedInfo.fSwizzle = GrSwizzle::RRRA(); |
| 1737 | grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag; |
| 1738 | |
| 1739 | #if 0 // Leaving Gray8 as non-renderable, to keep things simple and match raster. Needs to be |
| 1740 | // updated to support Gray8_as_Lum and Gray8_as_red if this is ever enabled. |
Brian Osman | 986563b | 2017-01-10 14:20:02 -0500 | [diff] [blame] | 1741 | if (this->textureRedSupport() || |
| 1742 | (kDesktop_ARB_MSFBOType == this->msFBOType() && |
| 1743 | ctxInfo.renderer() != kOSMesa_GrGLRenderer)) { |
| 1744 | // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable. |
| 1745 | // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present. |
| 1746 | // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case. |
| 1747 | fConfigTable[kGray_8_GrPixelConfig].fFlags |= allRenderFlags; |
| 1748 | } |
| 1749 | #endif |
Brian Osman | 48c9919 | 2017-06-02 08:45:06 -0400 | [diff] [blame] | 1750 | if (texStorageSupported && !isCommandBufferES2) { |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1751 | if (!disableR8TexStorageForANGLEGL) { |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 1752 | grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1753 | } |
| 1754 | grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1755 | } |
| 1756 | |
Brian Salomon | e609e81 | 2018-01-17 14:00:47 -0500 | [diff] [blame] | 1757 | if (textureRedSupport) { |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 1758 | if (texelBufferSupport) { |
| 1759 | grayRedInfo.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag; |
| 1760 | } |
| 1761 | fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo; |
| 1762 | } else { |
| 1763 | grayRedInfo.fFlags = 0; |
| 1764 | fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo; |
Brian Osman | 986563b | 2017-01-10 14:20:02 -0500 | [diff] [blame] | 1765 | } |
| 1766 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1767 | // Check for [half] floating point texture support |
| 1768 | // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not |
| 1769 | // supported. This is for simplicity, but a more granular approach is possible. Coincidentally, |
| 1770 | // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0. |
| 1771 | bool hasFPTextures = false; |
| 1772 | bool hasHalfFPTextures = false; |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 1773 | bool rgIsTexturable = false; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1774 | // for now we don't support floating point MSAA on ES |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 1775 | uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1776 | |
| 1777 | if (kGL_GrGLStandard == standard) { |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1778 | if (version >= GR_GL_VER(3, 0)) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1779 | hasFPTextures = true; |
| 1780 | hasHalfFPTextures = true; |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 1781 | rgIsTexturable = true; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1782 | } |
| 1783 | } else { |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1784 | if (version >= GR_GL_VER(3, 0)) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1785 | hasFPTextures = true; |
| 1786 | hasHalfFPTextures = true; |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 1787 | rgIsTexturable = true; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1788 | } else { |
| 1789 | if (ctxInfo.hasExtension("GL_OES_texture_float_linear") && |
| 1790 | ctxInfo.hasExtension("GL_OES_texture_float")) { |
| 1791 | hasFPTextures = true; |
| 1792 | } |
| 1793 | if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") && |
| 1794 | ctxInfo.hasExtension("GL_OES_texture_half_float")) { |
| 1795 | hasHalfFPTextures = true; |
| 1796 | } |
| 1797 | } |
| 1798 | } |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1799 | |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 1800 | for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) { |
| 1801 | const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG; |
| 1802 | fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format; |
| 1803 | fConfigTable[fpconfig].fFormats.fSizedInternalFormat = |
| 1804 | kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1805 | fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format; |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 1806 | fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT; |
| 1807 | fConfigTable[fpconfig].fFormatType = kFloat_FormatType; |
| 1808 | if (hasFPTextures) { |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 1809 | fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0; |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 1810 | // For now we only enable rendering to float on desktop, because on ES we'd have to |
| 1811 | // solve many precision issues and no clients actually want this yet. |
| 1812 | if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) || |
| 1813 | ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) { |
| 1814 | fConfigTable[fpconfig].fFlags |= fpRenderFlags; |
| 1815 | } |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1816 | } |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 1817 | if (texStorageSupported) { |
| 1818 | fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1819 | } |
| 1820 | if (texelBufferSupport) { |
| 1821 | fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag; |
| 1822 | } |
| 1823 | fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1824 | } |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1825 | |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1826 | GrGLenum redHalfExternalType; |
Brian Osman | b092cea | 2017-11-17 19:14:55 +0000 | [diff] [blame] | 1827 | if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) { |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1828 | redHalfExternalType = GR_GL_HALF_FLOAT; |
Brian Osman | b092cea | 2017-11-17 19:14:55 +0000 | [diff] [blame] | 1829 | } else { |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1830 | redHalfExternalType = GR_GL_HALF_FLOAT_OES; |
Brian Osman | b092cea | 2017-11-17 19:14:55 +0000 | [diff] [blame] | 1831 | } |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1832 | ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig]; |
| 1833 | redHalf.fFormats.fExternalType = redHalfExternalType; |
| 1834 | redHalf.fFormatType = kFloat_FormatType; |
| 1835 | redHalf.fFormats.fBaseInternalFormat = GR_GL_RED; |
| 1836 | redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1837 | redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED; |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1838 | redHalf.fSwizzle = GrSwizzle::RRRR(); |
Brian Salomon | e609e81 | 2018-01-17 14:00:47 -0500 | [diff] [blame] | 1839 | if (textureRedSupport && hasHalfFPTextures) { |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1840 | redHalf.fFlags = ConfigInfo::kTextureable_Flag; |
| 1841 | |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 1842 | if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) || |
Brian Salomon | e609e81 | 2018-01-17 14:00:47 -0500 | [diff] [blame] | 1843 | (textureRedSupport && ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) { |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1844 | redHalf.fFlags |= fpRenderFlags; |
| 1845 | } |
| 1846 | |
| 1847 | if (texStorageSupported && !isCommandBufferES2) { |
| 1848 | redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1849 | } |
| 1850 | |
| 1851 | if (texelBufferSupport) { |
| 1852 | redHalf.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag; |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 1853 | } |
| 1854 | } |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1855 | fConfigTable[kAlpha_half_GrPixelConfig] = redHalf; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1856 | |
| 1857 | fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; |
| 1858 | fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1859 | fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1860 | GR_GL_RGBA; |
Geoff Lang | 4b05000 | 2017-09-28 15:16:50 -0400 | [diff] [blame] | 1861 | if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) { |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1862 | fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT; |
| 1863 | } else { |
| 1864 | fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES; |
| 1865 | } |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 1866 | fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType; |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1867 | if (hasHalfFPTextures) { |
| 1868 | fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; |
| 1869 | // ES requires 3.2 or EXT_color_buffer_half_float. |
| 1870 | if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) || |
| 1871 | ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) { |
| 1872 | fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags; |
| 1873 | } |
| 1874 | } |
cblume | 790d513 | 2016-02-29 11:13:29 -0800 | [diff] [blame] | 1875 | if (texStorageSupported) { |
| 1876 | fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; |
| 1877 | } |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 1878 | if (texelBufferSupport) { |
| 1879 | fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag; |
| 1880 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1881 | fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 1882 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1883 | // Bulk populate the texture internal/external formats here and then deal with exceptions below. |
| 1884 | |
| 1885 | // ES 2.0 requires that the internal/external formats match. |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1886 | bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() || |
| 1887 | ctxInfo.version() >= GR_GL_VER(3,0)); |
| 1888 | // All ES versions (thus far) require sized internal formats for render buffers. |
| 1889 | // TODO: Always use sized internal format? |
| 1890 | bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard(); |
| 1891 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1892 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1893 | // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the |
| 1894 | // <format> param to glTex[Sub]Image. |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1895 | fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] = |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1896 | fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1897 | fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ? |
| 1898 | fConfigTable[i].fFormats.fSizedInternalFormat : |
| 1899 | fConfigTable[i].fFormats.fBaseInternalFormat; |
| 1900 | fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ? |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1901 | fConfigTable[i].fFormats.fSizedInternalFormat : |
| 1902 | fConfigTable[i].fFormats.fBaseInternalFormat; |
| 1903 | } |
Brian Salomon | 44804c0 | 2018-01-23 16:51:28 -0500 | [diff] [blame] | 1904 | // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the |
| 1905 | // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a |
| 1906 | // sized internal format. This is because there is no valid 8 bit alpha sized internal format |
| 1907 | // in ES. |
| 1908 | if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) { |
| 1909 | SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8); |
| 1910 | SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat == |
| 1911 | GR_GL_ALPHA8); |
Greg Daniel | 8713b88 | 2017-10-26 15:15:47 -0400 | [diff] [blame] | 1912 | fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage = |
| 1913 | fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat; |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 1914 | fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage = |
| 1915 | fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat; |
Greg Daniel | 8713b88 | 2017-10-26 15:15:47 -0400 | [diff] [blame] | 1916 | } |
| 1917 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1918 | // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format> |
| 1919 | // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match. |
| 1920 | // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param. |
| 1921 | // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage. |
| 1922 | if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) { |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1923 | fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] = |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1924 | GR_GL_SRGB_ALPHA; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 1925 | |
| 1926 | // Additionally, because we had to "invent" sBGRA, there is no way to make it work |
| 1927 | // in ES 2.0, because there is no <internalFormat> we can use. So just make that format |
| 1928 | // unsupported. (If we have no sRGB support at all, this will get overwritten below). |
| 1929 | fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1930 | } |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 1931 | // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must |
| 1932 | // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to |
| 1933 | // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x' |
| 1934 | // slot. |
| 1935 | fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] = |
| 1936 | GR_GL_RGB; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1937 | |
| 1938 | // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image |
| 1939 | // as a base format. |
| 1940 | // GL_EXT_texture_format_BGRA8888: |
| 1941 | // This extension GL_BGRA as an unsized internal format. However, it is written against ES |
| 1942 | // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal |
| 1943 | // formats. |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1944 | // GL_APPLE_texture_format_BGRA8888: |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1945 | // ES 2.0: the extension makes BGRA an external format but not an internal format. |
| 1946 | // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for |
| 1947 | // glTexImage (just for glTexStorage). |
Greg Daniel | 0ff79b2 | 2018-02-15 12:33:33 -0500 | [diff] [blame] | 1948 | if (useSizedTexFormats && this->bgraIsInternalFormat()) { |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1949 | fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA; |
| 1950 | } |
| 1951 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1952 | // If we don't have texture swizzle support then the shader generator must insert the |
| 1953 | // swizzle into shader code. |
| 1954 | if (!this->textureSwizzleSupport()) { |
| 1955 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 1956 | shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 1957 | } |
| 1958 | } |
| 1959 | |
bsalomon | 7f9b2e4 | 2016-01-12 13:29:26 -0800 | [diff] [blame] | 1960 | // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to |
| 1961 | // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel |
| 1962 | // gets written to the single component. |
Brian Salomon | e609e81 | 2018-01-17 14:00:47 -0500 | [diff] [blame] | 1963 | if (textureRedSupport) { |
bsalomon | 7f9b2e4 | 2016-01-12 13:29:26 -0800 | [diff] [blame] | 1964 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 1965 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
| 1966 | if (GrPixelConfigIsAlphaOnly(config) && |
| 1967 | fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 1968 | shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA(); |
bsalomon | 7f9b2e4 | 2016-01-12 13:29:26 -0800 | [diff] [blame] | 1969 | } |
| 1970 | } |
| 1971 | } |
| 1972 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1973 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 1974 | if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1975 | // We assume that MSAA rendering is supported only if we support non-MSAA rendering. |
| 1976 | SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags); |
Greg Daniel | 6bd729d | 2017-07-31 09:38:23 -0400 | [diff] [blame] | 1977 | if ((kGL_GrGLStandard == ctxInfo.standard() && |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1978 | (ctxInfo.version() >= GR_GL_VER(4,2) || |
| 1979 | ctxInfo.hasExtension("GL_ARB_internalformat_query"))) || |
Greg Daniel | 6bd729d | 2017-07-31 09:38:23 -0400 | [diff] [blame] | 1980 | (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) { |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1981 | int count; |
| 1982 | GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer; |
| 1983 | GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS, |
| 1984 | 1, &count); |
| 1985 | if (count) { |
| 1986 | int* temp = new int[count]; |
| 1987 | GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count, |
| 1988 | temp); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1989 | // GL has a concept of MSAA rasterization with a single sample but we do not. |
| 1990 | if (count && temp[count - 1] == 1) { |
| 1991 | --count; |
| 1992 | SkASSERT(!count || temp[count -1] > 1); |
| 1993 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1994 | fConfigTable[i].fColorSampleCounts.setCount(count+1); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1995 | // We initialize our supported values with 1 (no msaa) and reverse the order |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1996 | // returned by GL so that the array is ascending. |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1997 | fConfigTable[i].fColorSampleCounts[0] = 1; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1998 | for (int j = 0; j < count; ++j) { |
| 1999 | fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1]; |
| 2000 | } |
| 2001 | delete[] temp; |
| 2002 | } |
| 2003 | } else { |
Brian Salomon | 7f1a074 | 2018-01-29 14:24:19 -0500 | [diff] [blame] | 2004 | // Fake out the table using some semi-standard counts up to the max allowed sample |
| 2005 | // count. |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 2006 | int maxSampleCnt = 1; |
Brian Salomon | 7f1a074 | 2018-01-29 14:24:19 -0500 | [diff] [blame] | 2007 | if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) { |
| 2008 | GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt); |
| 2009 | } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) { |
| 2010 | GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt); |
| 2011 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 2012 | // Chrome has a mock GL implementation that returns 0. |
| 2013 | maxSampleCnt = SkTMax(1, maxSampleCnt); |
Brian Salomon | 7f1a074 | 2018-01-29 14:24:19 -0500 | [diff] [blame] | 2014 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 2015 | static constexpr int kDefaultSamples[] = {1, 2, 4, 8}; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 2016 | int count = SK_ARRAY_COUNT(kDefaultSamples); |
| 2017 | for (; count > 0; --count) { |
Brian Salomon | 7f1a074 | 2018-01-29 14:24:19 -0500 | [diff] [blame] | 2018 | if (kDefaultSamples[count - 1] <= maxSampleCnt) { |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 2019 | break; |
| 2020 | } |
| 2021 | } |
| 2022 | if (count > 0) { |
| 2023 | fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples); |
| 2024 | } |
| 2025 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 2026 | } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) { |
| 2027 | fConfigTable[i].fColorSampleCounts.setCount(1); |
| 2028 | fConfigTable[i].fColorSampleCounts[0] = 1; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 2029 | } |
| 2030 | } |
| 2031 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 2032 | #ifdef SK_DEBUG |
| 2033 | // Make sure we initialized everything. |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 2034 | ConfigInfo defaultEntry; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 2035 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 2036 | // Make sure we didn't set renderable and not blittable or renderable with msaa and not |
| 2037 | // renderable. |
Ben Wagner | f8a131d | 2018-03-13 16:56:43 -0400 | [diff] [blame] | 2038 | SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) && |
| 2039 | !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag))); |
| 2040 | SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) && |
| 2041 | !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag))); |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 2042 | SkASSERT(defaultEntry.fFormats.fBaseInternalFormat != |
| 2043 | fConfigTable[i].fFormats.fBaseInternalFormat); |
| 2044 | SkASSERT(defaultEntry.fFormats.fSizedInternalFormat != |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 2045 | fConfigTable[i].fFormats.fSizedInternalFormat); |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 2046 | for (int j = 0; j < kExternalFormatUsageCnt; ++j) { |
| 2047 | SkASSERT(defaultEntry.fFormats.fExternalFormat[j] != |
| 2048 | fConfigTable[i].fFormats.fExternalFormat[j]); |
| 2049 | } |
| 2050 | SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 2051 | } |
| 2052 | #endif |
| 2053 | } |
| 2054 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2055 | bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 2056 | GrSurfaceOrigin* origin, bool* rectsMustMatch, |
| 2057 | bool* disallowSubrect) const { |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2058 | // By default, we don't require rects to match. |
| 2059 | *rectsMustMatch = false; |
| 2060 | |
| 2061 | // By default, we allow subrects. |
| 2062 | *disallowSubrect = false; |
| 2063 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2064 | // If the src is a texture, we can implement the blit as a draw assuming the config is |
| 2065 | // renderable. |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 2066 | if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) { |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 2067 | *origin = kBottomLeft_GrSurfaceOrigin; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2068 | desc->fFlags = kRenderTarget_GrSurfaceFlag; |
| 2069 | desc->fConfig = src->config(); |
| 2070 | return true; |
| 2071 | } |
| 2072 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2073 | { |
| 2074 | // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were |
| 2075 | // wrapped. In that case the proxy would already be instantiated. |
| 2076 | const GrTexture* srcTexture = src->priv().peekTexture(); |
| 2077 | const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture); |
| 2078 | if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) { |
| 2079 | // Not supported for FBO blit or CopyTexSubImage |
| 2080 | return false; |
| 2081 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are |
| 2085 | // possible and we return false to fallback to creating a render target dst for render-to- |
| 2086 | // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo |
| 2087 | // 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] | 2088 | GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2089 | bool rectsMustMatchForBlitFramebuffer = false; |
| 2090 | bool disallowSubrectForBlitFramebuffer = false; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 2091 | if (src->numColorSamples() > 1 && |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2092 | (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) { |
| 2093 | rectsMustMatchForBlitFramebuffer = true; |
| 2094 | disallowSubrectForBlitFramebuffer = true; |
| 2095 | // Mirroring causes rects to mismatch later, don't allow it. |
| 2096 | originForBlitFramebuffer = src->origin(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 2097 | } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() & |
| 2098 | kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) { |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2099 | rectsMustMatchForBlitFramebuffer = true; |
| 2100 | // Mirroring causes rects to mismatch later, don't allow it. |
| 2101 | originForBlitFramebuffer = src->origin(); |
| 2102 | } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2103 | originForBlitFramebuffer = src->origin(); |
| 2104 | } |
| 2105 | |
| 2106 | // Check for format issues with glCopyTexSubImage2D |
| 2107 | if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) { |
| 2108 | // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit |
| 2109 | // then we set up for that, otherwise fail. |
| 2110 | if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) { |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 2111 | *origin = originForBlitFramebuffer; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2112 | desc->fConfig = kBGRA_8888_GrPixelConfig; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2113 | *rectsMustMatch = rectsMustMatchForBlitFramebuffer; |
| 2114 | *disallowSubrect = disallowSubrectForBlitFramebuffer; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2115 | return true; |
| 2116 | } |
| 2117 | return false; |
| 2118 | } |
| 2119 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2120 | { |
Brian Salomon | 63e7973 | 2017-05-15 21:23:13 -0400 | [diff] [blame] | 2121 | bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() && |
| 2122 | this->usesMSAARenderBuffers(); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2123 | if (srcIsMSAARenderbuffer) { |
| 2124 | // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO |
| 2125 | // blit or fail. |
| 2126 | if (this->canConfigBeFBOColorAttachment(src->config())) { |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 2127 | *origin = originForBlitFramebuffer; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2128 | desc->fConfig = src->config(); |
| 2129 | *rectsMustMatch = rectsMustMatchForBlitFramebuffer; |
| 2130 | *disallowSubrect = disallowSubrectForBlitFramebuffer; |
| 2131 | return true; |
| 2132 | } |
| 2133 | return false; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2134 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | // We'll do a CopyTexSubImage. Make the dst a plain old texture. |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 2138 | *origin = src->origin(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2139 | desc->fConfig = src->config(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2140 | desc->fFlags = kNone_GrSurfaceFlags; |
| 2141 | return true; |
| 2142 | } |
| 2143 | |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 2144 | void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo, |
| 2145 | const GrContextOptions& contextOptions, |
| 2146 | GrShaderCaps* shaderCaps) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2147 | // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand. |
| 2148 | // Thus we are blacklisting this extension for now on Adreno4xx devices. |
| 2149 | if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) { |
| 2150 | fDiscardRenderTargetSupport = false; |
| 2151 | fInvalidateFBType = kNone_InvalidateFBType; |
| 2152 | } |
| 2153 | |
| 2154 | // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between |
| 2155 | // 340.96 and 367.57. |
| 2156 | if (kGL_GrGLStandard == ctxInfo.standard() && |
| 2157 | ctxInfo.driver() == kNVIDIA_GrGLDriver && |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame] | 2158 | ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2159 | fClearTextureSupport = false; |
| 2160 | } |
| 2161 | |
| 2162 | // Calling glClearTexImage crashes on the NexusPlayer. |
| 2163 | if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) { |
| 2164 | fClearTextureSupport = false; |
| 2165 | } |
| 2166 | |
| 2167 | // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations. |
| 2168 | #ifdef SK_BUILD_FOR_MAC |
| 2169 | if (shaderCaps->fGeometryShaderSupport) { |
| 2170 | shaderCaps->fGSInvocationsSupport = false; |
| 2171 | } |
| 2172 | #endif |
| 2173 | |
| 2174 | // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry |
| 2175 | // shaders. @127.0 is the earliest verified driver to not crash. |
| 2176 | if (kQualcomm_GrGLDriver == ctxInfo.driver() && |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame] | 2177 | ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2178 | shaderCaps->fGeometryShaderSupport = false; |
| 2179 | } |
| 2180 | |
| 2181 | #if defined(__has_feature) |
| 2182 | #if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer) |
| 2183 | // See skbug.com/7058 |
| 2184 | fMapBufferType = kNone_MapBufferType; |
| 2185 | fMapBufferFlags = kNone_MapFlags; |
| 2186 | #endif |
| 2187 | #endif |
| 2188 | |
| 2189 | // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where |
| 2190 | // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug |
| 2191 | // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's |
| 2192 | // unclear whether this really affects a wide range of devices. |
| 2193 | if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer && |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame] | 2194 | ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2195 | fMapBufferType = kNone_MapBufferType; |
| 2196 | fMapBufferFlags = kNone_MapFlags; |
| 2197 | } |
| 2198 | |
| 2199 | // TODO: re-enable for ANGLE |
| 2200 | if (kANGLE_GrGLDriver == ctxInfo.driver()) { |
| 2201 | fTransferBufferType = kNone_TransferBufferType; |
| 2202 | } |
| 2203 | |
| 2204 | // Using MIPs on this GPU seems to be a source of trouble. |
| 2205 | if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) { |
| 2206 | fMipMapSupport = false; |
| 2207 | } |
| 2208 | |
| 2209 | if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) { |
| 2210 | // Temporarily disabling clip analytic fragments processors on Nexus player while we work |
| 2211 | // around a driver bug related to gl_FragCoord. |
| 2212 | // https://bugs.chromium.org/p/skia/issues/detail?id=7286 |
| 2213 | fMaxClipAnalyticFPs = 0; |
| 2214 | } |
| 2215 | |
| 2216 | #ifndef SK_BUILD_FOR_IOS |
| 2217 | if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() || |
| 2218 | kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() || |
| 2219 | (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() && |
| 2220 | ctxInfo.driver() != kChromium_GrGLDriver)) { |
| 2221 | fUseDrawToClearColor = true; |
| 2222 | } |
| 2223 | #endif |
| 2224 | |
| 2225 | // A lot of GPUs have trouble with full screen clears (skbug.com/7195) |
| 2226 | if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() || |
| 2227 | kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) { |
| 2228 | fUseDrawToClearColor = true; |
| 2229 | } |
| 2230 | |
| 2231 | #ifdef SK_BUILD_FOR_MAC |
| 2232 | // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform |
| 2233 | // full screen clears |
| 2234 | // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always |
| 2235 | // perform full screen clears. |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame] | 2236 | // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a |
| 2237 | // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well. |
| 2238 | if (kIntel_GrGLVendor == ctxInfo.vendor() && |
| 2239 | ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2240 | fUseDrawToClearColor = true; |
| 2241 | } |
| 2242 | #endif |
| 2243 | |
| 2244 | // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver |
| 2245 | // bugs seems to involve clearing too much and not skipping the clear. |
| 2246 | // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620 |
| 2247 | // but only for D3D11 ANGLE. |
| 2248 | if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) { |
| 2249 | fUseDrawToClearColor = true; |
| 2250 | } |
| 2251 | |
| 2252 | if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) { |
| 2253 | // This is known to be fixed sometime between driver 145.0 and 219.0 |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame] | 2254 | if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2255 | fUseDrawToClearStencilClip = true; |
| 2256 | } |
| 2257 | fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true; |
| 2258 | } |
| 2259 | |
| 2260 | // This was reproduced on the following configurations: |
| 2261 | // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0 |
| 2262 | // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0 |
| 2263 | // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0 |
| 2264 | // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0 |
| 2265 | // and not produced on: |
| 2266 | // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0 |
| 2267 | // The particular lines that get dropped from test images varies across different devices. |
| 2268 | if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() && |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame] | 2269 | ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2270 | fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true; |
| 2271 | } |
| 2272 | |
| 2273 | // Our Chromebook with kPowerVRRogue_GrGLRenderer seems to crash when glDrawArraysInstanced is |
| 2274 | // given 1 << 15 or more instances. |
| 2275 | if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) { |
| 2276 | fMaxInstancesPerDrawArraysWithoutCrashing = 0x7fff; |
| 2277 | } |
| 2278 | |
| 2279 | // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3. |
Chris Dalton | 0090ef6 | 2018-03-28 17:35:00 -0600 | [diff] [blame] | 2280 | if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2281 | fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true; |
| 2282 | fUseDrawInsteadOfAllRenderTargetWrites = true; |
| 2283 | } |
| 2284 | |
| 2285 | if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) { |
| 2286 | fSampleShadingSupport = false; |
| 2287 | } |
| 2288 | |
| 2289 | #ifdef SK_BUILD_FOR_MAC |
| 2290 | static constexpr bool isMAC = true; |
| 2291 | #else |
| 2292 | static constexpr bool isMAC = false; |
| 2293 | #endif |
| 2294 | |
| 2295 | // We support manual mip-map generation (via iterative downsampling draw calls). This fixes |
| 2296 | // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using |
| 2297 | // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally, |
| 2298 | // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary: |
| 2299 | if (fMipMapLevelAndLodControlSupport && |
| 2300 | (contextOptions.fDoManualMipmapping || |
| 2301 | (kIntel_GrGLVendor == ctxInfo.vendor()) || |
| 2302 | (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) || |
| 2303 | (kATI_GrGLVendor == ctxInfo.vendor()))) { |
| 2304 | fDoManualMipmapping = true; |
| 2305 | } |
| 2306 | |
| 2307 | // See http://crbug.com/710443 |
| 2308 | #ifdef SK_BUILD_FOR_MAC |
| 2309 | if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) { |
| 2310 | fClearToBoundaryValuesIsBroken = true; |
| 2311 | } |
| 2312 | #endif |
| 2313 | if (kQualcomm_GrGLVendor == ctxInfo.vendor()) { |
| 2314 | fDrawArraysBaseVertexIsBroken = true; |
| 2315 | } |
| 2316 | |
| 2317 | // The ccpr vertex-shader implementation does not work on this platform. Only allow CCPR with |
| 2318 | // GS. |
| 2319 | |
| 2320 | if (kANGLE_GrGLRenderer == ctxInfo.renderer() && |
| 2321 | GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer()) { |
| 2322 | bool gsSupport = fShaderCaps->geometryShaderSupport(); |
| 2323 | #if GR_TEST_UTILS |
| 2324 | gsSupport &= !contextOptions.fSuppressGeometryShaders; |
| 2325 | #endif |
| 2326 | fBlacklistCoverageCounting = !gsSupport; |
| 2327 | } |
| 2328 | // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the |
| 2329 | // Galaxy S7. |
| 2330 | // TODO: Once this is fixed we can update the check here to look at a driver version number too. |
| 2331 | if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) { |
| 2332 | shaderCaps->fFBFetchSupport = false; |
| 2333 | } |
| 2334 | |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2335 | // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader |
| 2336 | shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor(); |
| 2337 | |
| 2338 | // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any |
| 2339 | // function that may require a gradient calculation inside a conditional block may return |
| 2340 | // undefined results". This appears to be an issue with the 'any' call since even the simple |
| 2341 | // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play |
| 2342 | // from our GrTextureDomain processor. |
| 2343 | shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor(); |
| 2344 | |
| 2345 | // Known issue on at least some Intel platforms: |
| 2346 | // http://code.google.com/p/skia/issues/detail?id=946 |
| 2347 | if (kIntel_GrGLVendor == ctxInfo.vendor()) { |
| 2348 | shaderCaps->fFragCoordConventionsExtensionString = nullptr; |
| 2349 | } |
| 2350 | |
Chris Dalton | 0090ef6 | 2018-03-28 17:35:00 -0600 | [diff] [blame] | 2351 | if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2352 | // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), |
| 2353 | // so we must do the abs first in a separate expression. |
| 2354 | shaderCaps->fCanUseMinAndAbsTogether = false; |
| 2355 | |
| 2356 | // Tegra3 fract() seems to trigger undefined behavior for negative values, so we |
| 2357 | // must avoid this condition. |
| 2358 | shaderCaps->fCanUseFractForNegativeValues = false; |
| 2359 | } |
| 2360 | |
| 2361 | // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int |
| 2362 | // thus must us -1.0 * %s.x to work correctly |
| 2363 | if (kIntel_GrGLVendor == ctxInfo.vendor()) { |
| 2364 | shaderCaps->fMustForceNegatedAtanParamToFloat = true; |
| 2365 | } |
| 2366 | |
| 2367 | // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader |
| 2368 | // when floor and abs are called on the same line. Thus we must execute an Op between them to |
| 2369 | // make sure the compiler doesn't re-inline them even if we break the calls apart. |
| 2370 | if (kIntel_GrGLVendor == ctxInfo.vendor()) { |
| 2371 | shaderCaps->fMustDoOpBetweenFloorAndAbs = true; |
| 2372 | } |
| 2373 | |
| 2374 | // On Adreno devices with framebuffer fetch support, there is a bug where they always return |
| 2375 | // the original dst color when reading the outColor even after being written to. By using a |
| 2376 | // local outColor we can work around this bug. |
| 2377 | if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) { |
| 2378 | shaderCaps->fRequiresLocalOutputColorForFBFetch = true; |
| 2379 | } |
| 2380 | |
| 2381 | // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform |
| 2382 | // color, and that uniform contains an opaque color, and the output of the shader is only based |
| 2383 | // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce |
| 2384 | // that the shader always outputs opaque values. In that case, it appears to remove the shader |
| 2385 | // based blending code it normally injects, turning SrcOver into Src. To fix this, we always |
| 2386 | // insert an extra bit of math on the uniform that confuses the compiler just enough... |
| 2387 | if (kMaliT_GrGLRenderer == ctxInfo.renderer()) { |
| 2388 | shaderCaps->fMustObfuscateUniformColor = true; |
| 2389 | } |
| 2390 | #ifdef SK_BUILD_FOR_WIN |
| 2391 | // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098). |
| 2392 | // |
| 2393 | // Basically, if a shader has a construct like: |
| 2394 | // |
| 2395 | // float x = someCondition ? someValue : 0; |
| 2396 | // float2 result = (0 == x) ? float2(x, x) |
| 2397 | // : float2(2 * x / x, 0); |
| 2398 | // |
| 2399 | // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though |
| 2400 | // we've explicitly guarded the division with a check against zero. This manifests in much |
| 2401 | // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value |
| 2402 | // to the denominator of divisions, even when we've added checks that the denominator isn't 0. |
| 2403 | if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) { |
| 2404 | shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true; |
| 2405 | } |
| 2406 | #endif |
| 2407 | |
| 2408 | // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some |
| 2409 | // (rare) situations. It's sporadic, and mostly on older drivers. It also seems to be the case |
| 2410 | // that the interpolation of vertex shader outputs is quite inaccurate. |
| 2411 | if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) { |
| 2412 | shaderCaps->fCanUseFragCoord = false; |
| 2413 | shaderCaps->fInterpolantsAreInaccurate = true; |
| 2414 | } |
| 2415 | |
Chris Dalton | 0090ef6 | 2018-03-28 17:35:00 -0600 | [diff] [blame] | 2416 | // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware. |
| 2417 | if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) { |
| 2418 | shaderCaps->fCanUseFragCoord = false; |
| 2419 | } |
| 2420 | |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 2421 | // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048. |
| 2422 | // (Are they implemented with fp16?) |
| 2423 | if (kARM_GrGLVendor == ctxInfo.vendor()) { |
| 2424 | shaderCaps->fIncompleteShortIntPrecision = true; |
| 2425 | } |
| 2426 | |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2427 | // Disabling advanced blend on various platforms with major known issues. We also block Chrome |
| 2428 | // for now until its own blacklists can be updated. |
| 2429 | if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() || |
| 2430 | kAdreno5xx_GrGLRenderer == ctxInfo.renderer() || |
| 2431 | kIntel_GrGLDriver == ctxInfo.driver() || |
| 2432 | kChromium_GrGLDriver == ctxInfo.driver()) { |
| 2433 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
| 2434 | shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction; |
| 2435 | } |
| 2436 | |
| 2437 | // Non-coherent advanced blend has an issue on NVIDIA pre 337.00. |
| 2438 | if (kNVIDIA_GrGLDriver == ctxInfo.driver() && |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame] | 2439 | ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) && |
Brian Salomon | 4e69f14 | 2018-01-24 09:28:28 -0500 | [diff] [blame] | 2440 | kAdvanced_BlendEquationSupport == fBlendEquationSupport) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2441 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
| 2442 | shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction; |
| 2443 | } |
| 2444 | |
| 2445 | if (this->advancedBlendEquationSupport()) { |
| 2446 | if (kNVIDIA_GrGLDriver == ctxInfo.driver() && |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame] | 2447 | ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2448 | // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA. |
| 2449 | fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) | |
| 2450 | (1 << kColorBurn_GrBlendEquation); |
| 2451 | } |
| 2452 | if (kARM_GrGLVendor == ctxInfo.vendor()) { |
| 2453 | // Blacklist color-burn on ARM until the fix is released. |
| 2454 | fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation); |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples. |
| 2459 | if (fMultisampleDisableSupport && |
| 2460 | this->shaderCaps()->dualSourceBlendingSupport() && |
| 2461 | this->shaderCaps()->pathRenderingSupport() && |
| 2462 | fUsesMixedSamples && |
| 2463 | #if GR_TEST_UTILS |
| 2464 | (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) && |
| 2465 | #endif |
| 2466 | (kNVIDIA_GrGLDriver == ctxInfo.driver() || |
| 2467 | kChromium_GrGLDriver == ctxInfo.driver())) { |
| 2468 | fDiscardRenderTargetSupport = false; |
| 2469 | fInvalidateFBType = kNone_InvalidateFBType; |
| 2470 | } |
Brian Osman | c585e20 | 2018-04-04 14:08:27 -0400 | [diff] [blame] | 2471 | |
| 2472 | // Various Samsung devices (Note4, S7, ...) don't advertise the image_external_essl3 extension, |
| 2473 | // (only the base image_external extension), but do support it, and require that it be enabled |
| 2474 | // to work with ESSL3. This has been seen on both Mali and Adreno devices. skbug.com/7713 |
| 2475 | if (ctxInfo.hasExtension("GL_OES_EGL_image_external") && |
| 2476 | ctxInfo.glslGeneration() >= k330_GrGLSLGeneration && |
| 2477 | !shaderCaps->fExternalTextureSupport && // i.e. Missing the _essl3 extension |
| 2478 | (kARM_GrGLVendor == ctxInfo.vendor() || kQualcomm_GrGLVendor == ctxInfo.vendor())) { |
| 2479 | shaderCaps->fExternalTextureSupport = true; |
| 2480 | shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3"; |
| 2481 | } |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2482 | } |
| 2483 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 2484 | void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2485 | if (options.fDisableDriverCorrectnessWorkarounds) { |
| 2486 | SkASSERT(!fDoManualMipmapping); |
| 2487 | SkASSERT(!fClearToBoundaryValuesIsBroken); |
| 2488 | SkASSERT(0 == fMaxInstancesPerDrawArraysWithoutCrashing); |
| 2489 | SkASSERT(!fDrawArraysBaseVertexIsBroken); |
| 2490 | SkASSERT(!fUseDrawToClearColor); |
| 2491 | SkASSERT(!fUseDrawToClearStencilClip); |
| 2492 | SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO); |
| 2493 | SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites); |
| 2494 | SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines); |
| 2495 | } |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 2496 | if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) { |
| 2497 | fUseDrawToClearColor = false; |
| 2498 | } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) { |
| 2499 | fUseDrawToClearColor = true; |
| 2500 | } |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 2501 | if (options.fDoManualMipmapping) { |
| 2502 | fDoManualMipmapping = true; |
| 2503 | } |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 2504 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 2505 | |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 2506 | bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const { |
| 2507 | if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) { |
| 2508 | if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) { |
| 2509 | if (tex->hasBaseLevelBeenBoundToFBO()) { |
| 2510 | return false; |
| 2511 | } |
| 2512 | } |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 2513 | } if (auto rt = surface->asRenderTarget()) { |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 2514 | if (fUseDrawInsteadOfAllRenderTargetWrites) { |
| 2515 | return false; |
| 2516 | } |
| 2517 | if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) { |
| 2518 | return false; |
| 2519 | } |
| 2520 | return SkToBool(surface->asTexture()); |
| 2521 | } |
| 2522 | return true; |
| 2523 | } |
| 2524 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 2525 | bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const { |
| 2526 | if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) { |
| 2527 | // We don't support reading pixels directly from EXTERNAL textures as it would require |
| 2528 | // binding the texture to a FBO. |
| 2529 | if (tex->target() == GR_GL_TEXTURE_EXTERNAL) { |
| 2530 | return false; |
| 2531 | } |
| 2532 | } |
| 2533 | return true; |
| 2534 | } |
| 2535 | |
| 2536 | GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config, |
| 2537 | GrColorType dstColorType) const { |
| 2538 | // For now, we mostly report the read back format that is required by the ES spec without |
| 2539 | // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax |
| 2540 | // this as makes sense to increase performance and correctness. |
| 2541 | switch (fConfigTable[config].fFormatType) { |
| 2542 | case kNormalizedFixedPoint_FormatType: |
| 2543 | return GrColorType::kRGBA_8888; |
| 2544 | case kFloat_FormatType: |
| 2545 | // We cheat a little here and allow F16 read back if the src and dst match. |
| 2546 | if (kRGBA_half_GrPixelConfig == config && GrColorType::kRGBA_F16 == dstColorType) { |
| 2547 | return GrColorType::kRGBA_F16; |
| 2548 | } |
| 2549 | if ((kAlpha_half_GrPixelConfig == config || |
| 2550 | kAlpha_half_as_Red_GrPixelConfig == config) && |
| 2551 | GrColorType::kAlpha_F16 == dstColorType) { |
| 2552 | return GrColorType::kAlpha_F16; |
| 2553 | } |
| 2554 | // And similar for full float RG. |
| 2555 | if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) { |
| 2556 | return GrColorType::kRG_F32; |
| 2557 | } |
| 2558 | return GrColorType::kRGBA_F32; |
| 2559 | } |
| 2560 | return GrColorType::kUnknown; |
| 2561 | } |
| 2562 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 2563 | bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const { |
| 2564 | const GrGLFramebufferInfo* fbInfo = backendRT.getGLFramebufferInfo(); |
| 2565 | SkASSERT(fbInfo); |
| 2566 | // Window Rectangles are not supported for FBO 0; |
| 2567 | return fbInfo->fFBOID != 0; |
| 2568 | } |
| 2569 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 2570 | int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const { |
| 2571 | requestedCount = SkTMax(1, requestedCount); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 2572 | int count = fConfigTable[config].fColorSampleCounts.count(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 2573 | if (!count) { |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 2574 | return 0; |
| 2575 | } |
| 2576 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 2577 | if (1 == requestedCount) { |
| 2578 | return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0; |
| 2579 | } |
| 2580 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 2581 | for (int i = 0; i < count; ++i) { |
| 2582 | if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) { |
| 2583 | return fConfigTable[config].fColorSampleCounts[i]; |
| 2584 | } |
| 2585 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 2586 | return 0; |
| 2587 | } |
| 2588 | |
| 2589 | int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const { |
| 2590 | const auto& table = fConfigTable[config].fColorSampleCounts; |
| 2591 | if (!table.count()) { |
| 2592 | return 0; |
| 2593 | } |
| 2594 | return table[table.count() - 1]; |
Brian Salomon | d653cac | 2018-02-01 13:58:00 -0500 | [diff] [blame] | 2595 | } |
| 2596 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2597 | bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config, |
| 2598 | GrGLStandard standard) { |
| 2599 | *config = kUnknown_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2600 | |
| 2601 | switch (ct) { |
| 2602 | case kUnknown_SkColorType: |
| 2603 | return false; |
| 2604 | case kAlpha_8_SkColorType: |
| 2605 | if (GR_GL_ALPHA8 == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2606 | *config = kAlpha_8_as_Alpha_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2607 | } else if (GR_GL_R8 == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2608 | *config = kAlpha_8_as_Red_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2609 | } |
| 2610 | break; |
| 2611 | case kRGB_565_SkColorType: |
| 2612 | if (GR_GL_RGB565 == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2613 | *config = kRGB_565_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2614 | } |
| 2615 | break; |
| 2616 | case kARGB_4444_SkColorType: |
| 2617 | if (GR_GL_RGBA4 == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2618 | *config = kRGBA_4444_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2619 | } |
| 2620 | break; |
| 2621 | case kRGBA_8888_SkColorType: |
| 2622 | if (GR_GL_RGBA8 == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2623 | *config = kRGBA_8888_GrPixelConfig; |
Greg Daniel | 7b219ac | 2017-12-18 14:49:04 -0500 | [diff] [blame] | 2624 | } else if (GR_GL_SRGB8_ALPHA8 == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2625 | *config = kSRGBA_8888_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2626 | } |
| 2627 | break; |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 2628 | case kRGB_888x_SkColorType: |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 2629 | if (GR_GL_RGB8 == format) { |
| 2630 | *config = kRGB_888_GrPixelConfig; |
| 2631 | } |
| 2632 | break; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2633 | case kBGRA_8888_SkColorType: |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2634 | if (GR_GL_RGBA8 == format) { |
| 2635 | if (kGL_GrGLStandard == standard) { |
| 2636 | *config = kBGRA_8888_GrPixelConfig; |
| 2637 | } |
| 2638 | } else if (GR_GL_BGRA8 == format) { |
| 2639 | if (kGLES_GrGLStandard == standard) { |
| 2640 | *config = kBGRA_8888_GrPixelConfig; |
| 2641 | } |
Greg Daniel | 7b219ac | 2017-12-18 14:49:04 -0500 | [diff] [blame] | 2642 | } else if (GR_GL_SRGB8_ALPHA8 == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2643 | *config = kSBGRA_8888_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2644 | } |
| 2645 | break; |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 2646 | case kRGBA_1010102_SkColorType: |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 2647 | if (GR_GL_RGB10_A2 == format) { |
| 2648 | *config = kRGBA_1010102_GrPixelConfig; |
| 2649 | } |
| 2650 | break; |
Brian Salomon | e41e176 | 2018-01-25 14:07:47 -0500 | [diff] [blame] | 2651 | case kRGB_101010x_SkColorType: |
| 2652 | return false; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2653 | case kGray_8_SkColorType: |
| 2654 | if (GR_GL_LUMINANCE8 == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2655 | *config = kGray_8_as_Lum_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2656 | } else if (GR_GL_R8 == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2657 | *config = kGray_8_as_Red_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2658 | } |
| 2659 | break; |
| 2660 | case kRGBA_F16_SkColorType: |
| 2661 | if (GR_GL_RGBA16F == format) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2662 | *config = kRGBA_half_GrPixelConfig; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2663 | } |
| 2664 | break; |
| 2665 | } |
| 2666 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 2667 | return kUnknown_GrPixelConfig != *config; |
| 2668 | } |
| 2669 | |
| 2670 | bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct, |
| 2671 | GrPixelConfig* config) const { |
| 2672 | const GrGLTextureInfo* texInfo = tex.getGLTextureInfo(); |
| 2673 | if (!texInfo) { |
| 2674 | return false; |
| 2675 | } |
| 2676 | return validate_sized_format(texInfo->fFormat, ct, config, fStandard); |
| 2677 | } |
| 2678 | |
| 2679 | bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct, |
| 2680 | GrPixelConfig* config) const { |
| 2681 | const GrGLFramebufferInfo* fbInfo = rt.getGLFramebufferInfo(); |
| 2682 | if (!fbInfo) { |
| 2683 | return false; |
| 2684 | } |
| 2685 | return validate_sized_format(fbInfo->fFormat, ct, config, fStandard); |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 2686 | } |
| 2687 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 2688 | bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct, |
| 2689 | GrPixelConfig* config) const { |
| 2690 | const GrGLenum* glFormat = format.getGLFormat(); |
| 2691 | if (!glFormat) { |
| 2692 | return false; |
| 2693 | } |
| 2694 | return validate_sized_format(*glFormat, ct, config, fStandard); |
| 2695 | } |
| 2696 | |
| 2697 | |