blob: 599a0e00dace4a10b89e1522caa76548bb55d77f [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9#include "GrGLCaps.h"
joshualittb4384b92014-10-21 12:53:15 -070010
egdanielb7e7d572015-11-04 04:23:53 -080011#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000012#include "GrGLContext.h"
bsalomon1aa20292016-01-22 08:16:09 -080013#include "GrGLRenderTarget.h"
jvanverthcba99b82015-06-24 06:59:57 -070014#include "glsl/GrGLSLCaps.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000015#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000016#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000017
bsalomon682c2692015-05-22 14:01:46 -070018GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
19 const GrGLContextInfo& ctxInfo,
20 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080021 fStandard = ctxInfo.standard();
22
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000023 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000024 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000025 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000026 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080027 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028 fMaxFragmentUniformVectors = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fUnpackRowLengthSupport = false;
30 fUnpackFlipYSupport = false;
31 fPackRowLengthSupport = false;
32 fPackFlipYSupport = false;
33 fTextureUsageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000034 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000035 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000036 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070037 fDirectStateAccessSupport = false;
38 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080039 fES2CompatibilitySupport = false;
cdaltond4727922015-11-10 12:49:06 -080040 fMultisampleDisableSupport = false;
cdalton06604b92016-02-05 10:09:51 -080041 fDrawIndirectSupport = false;
42 fMultiDrawIndirectSupport = false;
43 fBaseInstanceSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000044 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070046 fBindFragDataLocationSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080047 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080048 fTextureSwizzleSupport = false;
bsalomon88c7b982015-07-31 11:20:16 -070049 fRGBA8888PixelsOpsAreSlow = false;
50 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080051 fMipMapLevelAndLodControlSupport = false;
ericrkb4ecabd2016-03-11 15:18:20 -080052 fRGBAToBGRAReadbackConversionsAreSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070053
bsalomon083617b2016-02-12 12:10:14 -080054 fBlitFramebufferSupport = kNone_BlitFramebufferSupport;
55
halcanary385fe4d2015-08-26 13:07:48 -070056 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070057
cdalton4cd67132015-06-10 19:23:46 -070058 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000059}
60
cdalton4cd67132015-06-10 19:23:46 -070061void GrGLCaps::init(const GrContextOptions& contextOptions,
62 const GrGLContextInfo& ctxInfo,
63 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000064 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000065 GrGLVersion version = ctxInfo.version();
66
bsalomon@google.combcce8922013-03-25 15:38:39 +000067 /**************************************************************************
68 * Caps specific to GrGLCaps
69 **************************************************************************/
70
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000071 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000072 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
73 &fMaxFragmentUniformVectors);
74 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000075 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000076 GrGLint max;
77 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
78 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000079 if (version >= GR_GL_VER(3, 2)) {
80 GrGLint profileMask;
81 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
82 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
83 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000084 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000085 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000086
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000087 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000088 fUnpackRowLengthSupport = true;
89 fUnpackFlipYSupport = false;
90 fPackRowLengthSupport = true;
91 fPackFlipYSupport = false;
92 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000093 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
94 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000095 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000096 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
97 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098 fPackFlipYSupport =
99 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
100 }
101
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000102 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000103 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
104
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000105 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700106 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
107 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
108 ctxInfo.hasExtension("GL_NV_texture_barrier");
109 } else {
110 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
111 }
112
cdaltoneb79eea2016-02-26 10:39:34 -0800113 if (kGL_GrGLStandard == standard) {
114 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
115 ctxInfo.hasExtension("GL_ARB_texture_multisample");
116 } else {
117 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
118 }
119
hendrikwa0d5ad72014-12-02 07:30:30 -0800120 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
121 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700122 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800123 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000124 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
125 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800126 } else {
127 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
128 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000129 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000130 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000131 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000132 ctxInfo.hasExtension("GL_ARB_imaging");
133
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000134 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
135 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
136 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
137 // limit this decision to specific GPU families rather than basing it on the vendor alone.
138 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700139 (kARM_GrGLVendor == ctxInfo.vendor() ||
140 kImagination_GrGLVendor == ctxInfo.vendor() ||
141 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000142 fUseNonVBOVertexAndIndexDynamicData = true;
143 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000144
egdaniel9250d242015-05-18 13:04:26 -0700145 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
146 // Thus we are blacklisting this extension for now on Adreno4xx devices.
147 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
148 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
149 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
150 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000151 fDiscardRenderTargetSupport = true;
152 fInvalidateFBType = kInvalidate_InvalidateFBType;
153 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
154 fDiscardRenderTargetSupport = true;
155 fInvalidateFBType = kDiscard_InvalidateFBType;
156 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000157
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000158 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
159 fFullClearIsFree = true;
160 }
161
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000162 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000163 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800164 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
165 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000166 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000167 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
168 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000169 }
170
cdalton626e1ff2015-06-12 13:56:46 -0700171 if (kGL_GrGLStandard == standard) {
172 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
173 } else {
174 fDirectStateAccessSupport = false;
175 }
176
177 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
178 fDebugSupport = true;
179 } else {
180 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
181 }
182
jvanverth3f801cb2014-12-16 09:49:38 -0800183 if (kGL_GrGLStandard == standard) {
184 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
185 }
186 else {
187 fES2CompatibilitySupport = true;
188 }
189
cdalton0edea2c2015-05-21 08:27:44 -0700190 if (kGL_GrGLStandard == standard) {
191 fMultisampleDisableSupport = true;
192 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700193 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700194 }
195
kkinnunend94708e2015-07-30 22:47:04 -0700196 if (kGL_GrGLStandard == standard) {
197 if (version >= GR_GL_VER(3, 0)) {
198 fBindFragDataLocationSupport = true;
199 }
200 } else {
201 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
202 fBindFragDataLocationSupport = true;
203 }
joshualittc1f56b52015-06-22 12:31:31 -0700204 }
205
bsalomonb8909d32016-01-28 07:09:52 -0800206#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700207 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
bsalomonb8909d32016-01-28 07:09:52 -0800208#else
209 fBindUniformLocationSupport = false;
210#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700211
kkinnunene06ed252016-02-16 23:15:40 -0800212 if (kGL_GrGLStandard == standard) {
213 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
214 // We also require textureSize() support for rectangle 2D samplers which was added in
215 // GLSL 1.40.
216 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
217 fRectangleTextureSupport = true;
218 }
bsalomone179a912016-01-20 06:18:10 -0800219 }
kkinnunene06ed252016-02-16 23:15:40 -0800220 } else {
221 // Command buffer exposes this in GL ES context for Chromium reasons,
222 // but it should not be used. Also, at the time of writing command buffer
223 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800224 }
225
bsalomoncdee0092016-01-08 13:20:12 -0800226 if (kGL_GrGLStandard == standard) {
227 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
228 fTextureSwizzleSupport = true;
229 }
230 } else {
231 if (version >= GR_GL_VER(3,0)) {
232 fTextureSwizzleSupport = true;
233 }
234 }
235
cblume09bd2c02016-03-01 14:08:28 -0800236 if (kGL_GrGLStandard == standard) {
237 fMipMapLevelAndLodControlSupport = true;
238 } else if (kGLES_GrGLStandard == standard) {
239 if (version >= GR_GL_VER(3,0)) {
240 fMipMapLevelAndLodControlSupport = true;
241 }
242 }
243
bsalomon88c7b982015-07-31 11:20:16 -0700244#ifdef SK_BUILD_FOR_WIN
245 // We're assuming that on Windows Chromium we're using ANGLE.
246 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
247 kChromium_GrGLDriver == ctxInfo.driver();
248 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
249 fRGBA8888PixelsOpsAreSlow = isANGLE;
250 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
251 // check DX11 ANGLE.
252 fPartialFBOReadIsSlow = isANGLE;
253#endif
254
ericrkb4ecabd2016-03-11 15:18:20 -0800255 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
256 bool isMAC = false;
257#ifdef SK_BUILD_FOR_MAC
258 isMAC = true;
259#endif
260
261 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
262 // vis-versa.
263 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
264
cdalton4cd67132015-06-10 19:23:46 -0700265 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700266 * GrShaderCaps fields
267 **************************************************************************/
268
egdaniel0a482332015-10-26 08:59:10 -0700269 // This must be called after fCoreProfile is set on the GrGLCaps
270 this->initGLSL(ctxInfo);
271 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
272
egdaniel05ded892015-10-26 07:38:05 -0700273 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
274
275 // For now these two are equivalent but we could have dst read in shader via some other method.
276 // Before setting this, initGLSL() must have been called.
277 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
278
279 // Enable supported shader-related caps
280 if (kGL_GrGLStandard == standard) {
281 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
282 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
283 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
284 glslCaps->fShaderDerivativeSupport = true;
285 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
286 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
287 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
cdalton793dc262016-02-08 10:11:47 -0800288 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
289 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700290 }
291 else {
292 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
293
294 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
295 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800296
297 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
298 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700299 }
300
ethannicholas22793252016-01-30 09:59:10 -0800301 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
302 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
303 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
304 &glslCaps->fPixelLocalStorageSize);
305 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
306 }
307 else {
308 glslCaps->fPixelLocalStorageSize = 0;
309 glslCaps->fPLSPathRenderingSupport = false;
310 }
311
cdalton9c3f1432016-03-11 10:07:37 -0800312 // Protect ourselves against tracking huge amounts of texture state.
313 static const uint8_t kMaxSaneSamplers = 32;
314 GrGLint maxSamplers;
315 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
316 glslCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
317 if (glslCaps->fGeometryShaderSupport) {
318 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
319 glslCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
320 }
321 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
322 glslCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
323 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
324 glslCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
325
egdaniel05ded892015-10-26 07:38:05 -0700326 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700327 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000328 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700329
cdalton63f6c1f2015-11-06 07:09:43 -0800330 // We need dual source blending and the ability to disable multisample in order to support mixed
331 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800332 if (fMultisampleDisableSupport &&
333 glslCaps->dualSourceBlendingSupport() &&
334 fShaderCaps->pathRenderingSupport()) {
335 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800336 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800337 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800338 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
339 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800340 fDiscardRenderTargetSupport = false;
341 fInvalidateFBType = kNone_InvalidateFBType;
342 }
343 }
344
egdanieleed519e2016-01-15 11:36:18 -0800345 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700346 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700347 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700348 this->initStencilFormats(ctxInfo);
349
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000350 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000351 // we could also look for GL_ATI_separate_stencil extension or
352 // GL_EXT_stencil_two_side but they use different function signatures
353 // than GL2.0+ (and than each other).
354 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
355 // supported on GL 1.4 and higher or by extension
356 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
357 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
358 } else {
359 // ES 2 has two sided stencil and stencil wrap
360 fTwoSidedStencilSupport = true;
361 fStencilWrapOpsSupport = true;
362 }
363
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000364 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000365 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
366 // extension includes glMapBuffer.
367 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
368 fMapBufferFlags |= kSubset_MapFlag;
369 fMapBufferType = kMapBufferRange_MapBufferType;
370 } else {
371 fMapBufferType = kMapBuffer_MapBufferType;
372 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000373 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000374 // Unextended GLES2 doesn't have any buffer mapping.
375 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800376 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800377 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
378 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800379 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
380 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
381 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000382 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
383 fMapBufferFlags = kCanMap_MapFlag;
384 fMapBufferType = kMapBuffer_MapBufferType;
385 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000386 }
387
jvanverthd7a2c1f2015-12-07 07:36:44 -0800388 if (kGL_GrGLStandard == standard) {
389 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
390 fTransferBufferType = kPBO_TransferBufferType;
391 }
392 } else {
393 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
394 fTransferBufferType = kPBO_TransferBufferType;
395 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
396 fTransferBufferType = kChromium_TransferBufferType;
397 }
398 }
399
joshualitte5b74c62015-06-01 14:17:47 -0700400 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
401 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
robertphillipsf8c3ba42016-03-25 04:55:58 -0700402 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700403 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
404 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
405 // a small subset.
406#if 0
robertphillipsf8c3ba42016-03-25 04:55:58 -0700407 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700408#else
robertphillipsf8c3ba42016-03-25 04:55:58 -0700409 fGeometryBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700410#endif
joshualitte5b74c62015-06-01 14:17:47 -0700411 }
412
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000413 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000414 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
415 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
416 fNPOTTextureTileSupport = true;
417 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000418 } else {
419 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000420 // ES3 has no limitations.
421 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
422 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000423 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
424 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
425 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
426 // to alllow arbitrary wrap modes, however.
427 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000428 }
429
bsalomone72bd022015-10-26 07:33:03 -0700430 // Using MIPs on this GPU seems to be a source of trouble.
431 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
432 fMipMapSupport = false;
433 }
434
bsalomon@google.combcce8922013-03-25 15:38:39 +0000435 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
436 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
437 // Our render targets are always created with textures as the color
438 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000439 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000440
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000441 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
442
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000443 // Disable scratch texture reuse on Mali and Adreno devices
444 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
445 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000446
robertphillips1b8e1b52015-06-24 06:54:10 -0700447#if 0
448 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
449 kQualcomm_GrGLVendor != ctxInfo.vendor();
450#endif
451
egdaniel05ded892015-10-26 07:38:05 -0700452 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000453 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800454 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000455 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800456 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000457 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800458 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
459 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
460 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
461 // This is to guard against platforms that may not support as many samples for
462 // glRasterSamples as they do for framebuffers.
463 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
464 }
465 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000466
bsalomon63b21962014-11-05 07:05:34 -0800467 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800468 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800469 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800470 fUseDrawInsteadOfClear = true;
471 }
472
joshualitt83bc2292015-06-18 14:18:02 -0700473 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
474 fUseDrawInsteadOfPartialRenderTargetWrite = true;
475 }
476
bsalomonbabafcc2016-02-16 11:36:47 -0800477 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
478 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
479 fUseDrawInsteadOfPartialRenderTargetWrite = true;
480 fUseDrawInsteadOfAllRenderTargetWrites = true;
481 }
482
robertphillips63926682015-08-20 09:39:02 -0700483#ifdef SK_BUILD_FOR_WIN
484 // On ANGLE deferring flushes can lead to GPU starvation
485 fPreferVRAMUseOverFlushes = !isANGLE;
486#endif
487
bsalomon7dea7b72015-08-19 08:26:51 -0700488 if (kChromium_GrGLDriver == ctxInfo.driver()) {
489 fMustClearUploadedBufferData = true;
490 }
491
bsalomond08ea5f2015-02-20 06:58:13 -0800492 if (kGL_GrGLStandard == standard) {
493 // ARB allows mixed size FBO attachments, EXT does not.
494 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
495 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
496 fOversizedStencilSupport = true;
497 } else {
498 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
499 }
500 } else {
501 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
502 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
503 }
504
joshualitt58001552015-06-26 12:46:36 -0700505 if (kGL_GrGLStandard == standard) {
506 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
507 // instanced arrays, but we could make this more granular if we wanted
508 fSupportsInstancedDraws =
509 version >= GR_GL_VER(3, 2) ||
510 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
511 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
512 } else {
513 fSupportsInstancedDraws =
514 version >= GR_GL_VER(3, 0) ||
515 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
516 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
517 }
518
cdalton06604b92016-02-05 10:09:51 -0800519 if (kGL_GrGLStandard == standard) {
520 // We don't use ARB_draw_indirect because it does not support a base instance.
521 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER.
522 fDrawIndirectSupport =
523 fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3);
524 } else {
525 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
526 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
527 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
528 }
529
jvanverthcba99b82015-06-24 06:59:57 -0700530 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800531
532 if (contextOptions.fUseShaderSwizzling) {
533 fTextureSwizzleSupport = false;
534 }
535
ethannicholas28ef4452016-03-25 09:26:03 -0700536 if (kGL_GrGLStandard == standard) {
537 if (version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading")) {
538 fSampleShadingSupport = true;
539 }
540 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
541 fSampleShadingSupport = true;
542 }
543
bsalomoncdee0092016-01-08 13:20:12 -0800544 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
545 // already been detected.
546 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700547
548 this->applyOptionsOverrides(contextOptions);
549 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000550}
551
egdaniel472d44e2015-10-22 08:20:00 -0700552const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
553 bool isCoreProfile) {
554 switch (generation) {
555 case k110_GrGLSLGeneration:
556 if (kGLES_GrGLStandard == standard) {
557 // ES2s shader language is based on version 1.20 but is version
558 // 1.00 of the ES language.
559 return "#version 100\n";
560 } else {
561 SkASSERT(kGL_GrGLStandard == standard);
562 return "#version 110\n";
563 }
564 case k130_GrGLSLGeneration:
565 SkASSERT(kGL_GrGLStandard == standard);
566 return "#version 130\n";
567 case k140_GrGLSLGeneration:
568 SkASSERT(kGL_GrGLStandard == standard);
569 return "#version 140\n";
570 case k150_GrGLSLGeneration:
571 SkASSERT(kGL_GrGLStandard == standard);
572 if (isCoreProfile) {
573 return "#version 150\n";
574 } else {
575 return "#version 150 compatibility\n";
576 }
577 case k330_GrGLSLGeneration:
578 if (kGLES_GrGLStandard == standard) {
579 return "#version 300 es\n";
580 } else {
581 SkASSERT(kGL_GrGLStandard == standard);
582 if (isCoreProfile) {
583 return "#version 330\n";
584 } else {
585 return "#version 330 compatibility\n";
586 }
587 }
cdalton33ad7012016-02-22 07:55:44 -0800588 case k400_GrGLSLGeneration:
589 SkASSERT(kGL_GrGLStandard == standard);
590 if (isCoreProfile) {
591 return "#version 400\n";
592 } else {
593 return "#version 400 compatibility\n";
594 }
egdaniel472d44e2015-10-22 08:20:00 -0700595 case k310es_GrGLSLGeneration:
596 SkASSERT(kGLES_GrGLStandard == standard);
597 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800598 case k320es_GrGLSLGeneration:
599 SkASSERT(kGLES_GrGLStandard == standard);
600 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700601 }
602 return "<no version>";
603}
604
egdaniel05ded892015-10-26 07:38:05 -0700605void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700606 GrGLStandard standard = ctxInfo.standard();
607 GrGLVersion version = ctxInfo.version();
608
609 /**************************************************************************
610 * Caps specific to GrGLSLCaps
611 **************************************************************************/
612
613 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
614 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700615 if (kGLES_GrGLStandard == standard) {
616 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
617 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
618 glslCaps->fFBFetchSupport = true;
619 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
620 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
621 }
622 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
623 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
624 glslCaps->fFBFetchNeedsCustomOutput = false;
625 glslCaps->fFBFetchSupport = true;
626 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
627 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
628 }
629 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
630 // The arm extension also requires an additional flag which we will set onResetContext
631 glslCaps->fFBFetchNeedsCustomOutput = false;
632 glslCaps->fFBFetchSupport = true;
633 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
634 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
635 }
636 glslCaps->fUsesPrecisionModifiers = true;
637 }
638
639 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
640
cdaltonc08f1962016-02-12 12:14:06 -0800641 if (kGL_GrGLStandard == standard) {
642 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
643 } else {
644 glslCaps->fFlatInterpolationSupport =
645 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
646 }
647
648 if (kGL_GrGLStandard == standard) {
649 glslCaps->fNoPerspectiveInterpolationSupport =
650 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
651 } else {
652 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
653 glslCaps->fNoPerspectiveInterpolationSupport = true;
654 glslCaps->fNoPerspectiveInterpolationExtensionString =
655 "GL_NV_shader_noperspective_interpolation";
656 }
657 }
658
cdalton33ad7012016-02-22 07:55:44 -0800659 if (kGL_GrGLStandard == standard) {
cdalton4a98cdb2016-03-01 12:12:20 -0800660 glslCaps->fMultisampleInterpolationSupport =
661 ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
662 } else {
663 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
664 glslCaps->fMultisampleInterpolationSupport = true;
665 } else if (ctxInfo.hasExtension("GL_OES_shader_multisample_interpolation")) {
666 glslCaps->fMultisampleInterpolationSupport = true;
667 glslCaps->fMultisampleInterpolationExtensionString =
668 "GL_OES_shader_multisample_interpolation";
669 }
670 }
671
672 if (kGL_GrGLStandard == standard) {
cdalton33ad7012016-02-22 07:55:44 -0800673 glslCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
674 } else {
675 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
676 glslCaps->fSampleVariablesSupport = true;
677 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
678 glslCaps->fSampleVariablesSupport = true;
679 glslCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
680 }
681 }
682
683 if (glslCaps->fSampleVariablesSupport) {
684 glslCaps->fSampleMaskOverrideCoverageSupport =
685 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage");
686 }
687
egdaniel472d44e2015-10-22 08:20:00 -0700688 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
689 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
690
691 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
692 // function that may require a gradient calculation inside a conditional block may return
693 // undefined results". This appears to be an issue with the 'any' call since even the simple
694 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
695 // from our GrTextureDomain processor.
696 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
697
egdaniel472d44e2015-10-22 08:20:00 -0700698 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
699 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800700
701 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
702 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
703 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800704
705 // Frag Coords Convention support is not part of ES
706 // Known issue on at least some Intel platforms:
707 // http://code.google.com/p/skia/issues/detail?id=946
708 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
709 kGLES_GrGLStandard != standard &&
710 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
711 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
712 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
713 }
714
715 if (kGLES_GrGLStandard == standard) {
716 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
717 }
718
cdalton9c3f1432016-03-11 10:07:37 -0800719 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
720 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
721 glslCaps->fExternalTextureSupport = true;
722 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
723 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
724 // At least one driver has been found that has this extension without the "GL_" prefix.
725 glslCaps->fExternalTextureSupport = true;
726 }
727 }
728
729 if (glslCaps->fExternalTextureSupport) {
bsalomon7ea33f52015-11-22 14:51:00 -0800730 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
731 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
732 } else {
733 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
734 }
735 }
736
cdaltonc04ce672016-03-11 14:07:38 -0800737 if (kGL_GrGLStandard == standard) {
738 glslCaps->fBufferTextureSupport = ctxInfo.version() > GR_GL_VER(3, 1) &&
739 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
740 } else {
741 if (ctxInfo.version() > GR_GL_VER(3, 2) &&
742 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
743 glslCaps->fBufferTextureSupport = true;
744 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
745 glslCaps->fBufferTextureSupport = true;
746 glslCaps->fBufferTextureExtensionString = "GL_OES_texture_buffer";
747 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
748 glslCaps->fBufferTextureSupport = true;
749 glslCaps->fBufferTextureExtensionString = "GL_EXT_texture_buffer";
750 }
751 }
752
egdaniel8dcdedc2015-11-11 06:27:20 -0800753 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
754 // the abs first in a separate expression.
755 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
756 glslCaps->fCanUseMinAndAbsTogether = false;
757 }
758
bsalomon7ea33f52015-11-22 14:51:00 -0800759 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
egdaniel8dcdedc2015-11-11 06:27:20 -0800760 // thus must us -1.0 * %s.x to work correctly
761 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
762 glslCaps->fMustForceNegatedAtanParamToFloat = true;
763 }
egdaniel472d44e2015-10-22 08:20:00 -0700764}
765
kkinnunencfe62e32015-07-01 02:58:50 -0700766bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700767 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
768
769 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700770 return false;
771 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700772
kkinnunencfe62e32015-07-01 02:58:50 -0700773 if (kGL_GrGLStandard == ctxInfo.standard()) {
774 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
775 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
776 return false;
777 }
778 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700779 if (!hasChromiumPathRendering &&
780 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700781 return false;
782 }
783 }
784 // We only support v1.3+ of GL_NV_path_rendering which allows us to
785 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
786 // additions are detected by checking the existence of the function.
787 // We also use *Then* functions that not all drivers might have. Check
788 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800789 if (!gli->fFunctions.fStencilThenCoverFillPath ||
790 !gli->fFunctions.fStencilThenCoverStrokePath ||
791 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
792 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
793 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700794 return false;
795 }
796 return true;
797}
bsalomon1aa20292016-01-22 08:16:09 -0800798
799bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800800 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800801 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
802 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800803 // If it's not possible to even have a render target of rtConfig then read pixels is
804 // not supported regardless of readConfig.
805 if (!this->isConfigRenderable(rtConfig, false)) {
806 return false;
807 }
bsalomon7928ef62016-01-05 10:26:39 -0800808
bsalomon76148af2016-01-12 11:13:47 -0800809 GrGLenum readFormat;
810 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800811 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800812 return false;
813 }
814
bsalomon1aa20292016-01-22 08:16:09 -0800815 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800816 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
817 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
818 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
819 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
820 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
821 readFormat != GR_GL_BGRA) {
822 return false;
823 }
824 // There is also a set of allowed types, but all the types we use are in the set:
825 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
826 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
827 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
828 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
829 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
830 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
831 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800832 return true;
piotaixre4b23142014-10-02 10:57:53 -0700833 }
bsalomon7928ef62016-01-05 10:26:39 -0800834
bsalomon76148af2016-01-12 11:13:47 -0800835 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800836
bsalomon1aa20292016-01-22 08:16:09 -0800837 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800838 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
839 return true;
840 }
841 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800842 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800843 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
844 return true;
845 }
846 }
847
bsalomon1aa20292016-01-22 08:16:09 -0800848 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800849 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800850 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800851 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800852 if (!bindRenderTarget()) {
853 return false;
854 }
855 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
856 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800857 rpFormat->fFormat = format;
858 rpFormat->fType = type;
859 }
860
bsalomon1aa20292016-01-22 08:16:09 -0800861 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
862 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700863}
864
robertphillips@google.com6177e692013-02-28 20:16:25 +0000865void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000866
867 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000868 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000869 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
870 // ES3 driver bugs on at least one device with a tiled GPU (N10).
871 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
872 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
873 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
874 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800875 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700876 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000877 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000878 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
879 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
880 // chrome's extension is equivalent to the EXT msaa
881 // and fbo_blit extensions.
882 fMSFBOType = kDesktop_EXT_MSFBOType;
883 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
884 fMSFBOType = kES_Apple_MSFBOType;
885 }
bsalomon083617b2016-02-12 12:10:14 -0800886
887 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
888 // is available.
889 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
890 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
891 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
892 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
893 // limitations.
894 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
895 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000896 } else {
egdanieleed519e2016-01-15 11:36:18 -0800897 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700898 fMSFBOType = kMixedSamples_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800899 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
vbuzinovdded6962015-06-12 08:59:45 -0700900 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000901 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000902 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800903 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000904 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
905 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000906 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800907 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000908 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000909 }
910}
911
cdalton1dd05422015-06-12 09:01:18 -0700912void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
913 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
914
915 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
916 // for now until its own blacklists can be updated.
917 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
918 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700919 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700920 return;
921 }
922
923 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
924 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
925 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
926 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
927 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
928 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
929 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
930 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
931 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
932 return;
933 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
934 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
935 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
936 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
937 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
938 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
939 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
940 // slow on a particular platform.
941 } else {
942 return; // No advanced blend support.
943 }
944
945 SkASSERT(this->advancedBlendEquationSupport());
946
947 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
948 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
949 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
950 (1 << kColorBurn_GrBlendEquation);
951 }
joel.liang9764c402015-07-09 19:46:18 -0700952 if (kARM_GrGLVendor == ctxInfo.vendor()) {
953 // Blacklist color-burn on ARM until the fix is released.
954 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
955 }
cdalton1dd05422015-06-12 09:01:18 -0700956}
957
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000958namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700959const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000960}
961
962void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
963
964 // Build up list of legal stencil formats (though perhaps not supported on
965 // the particular gpu/driver) from most preferred to least.
966
967 // these consts are in order of most preferred to least preferred
968 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
969
970 static const StencilFormat
971 // internal Format stencil bits total bits packed?
972 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
973 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
974 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
975 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000976 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000977 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
978
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000979 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000980 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000981 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000982 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
983 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
984
985 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
986 // require FBO support we can expect these are legal formats and don't
987 // check. These also all support the unsized GL_STENCIL_INDEX.
988 fStencilFormats.push_back() = gS8;
989 fStencilFormats.push_back() = gS16;
990 if (supportsPackedDS) {
991 fStencilFormats.push_back() = gD24S8;
992 }
993 fStencilFormats.push_back() = gS4;
994 if (supportsPackedDS) {
995 fStencilFormats.push_back() = gDS;
996 }
997 } else {
998 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
999 // for other formats.
1000 // ES doesn't support using the unsized format.
1001
1002 fStencilFormats.push_back() = gS8;
1003 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001004 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1005 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001006 fStencilFormats.push_back() = gD24S8;
1007 }
1008 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1009 fStencilFormats.push_back() = gS4;
1010 }
1011 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001012}
1013
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001014SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001015
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001016 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001017
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001018 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001019 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001020 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001021 i,
1022 fStencilFormats[i].fStencilBits,
1023 fStencilFormats[i].fTotalBits);
1024 }
1025
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001026 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001027 "None",
1028 "ARB",
1029 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001030 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001031 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001032 "IMG MS To Texture",
1033 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001034 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001035 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001036 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1037 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1038 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001039 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1040 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1041 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1042 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001043 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001044 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001045
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001046 static const char* kInvalidateFBTypeStr[] = {
1047 "None",
1048 "Discard",
1049 "Invalidate",
1050 };
1051 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1052 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1053 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1054 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001055
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001056 static const char* kMapBufferTypeStr[] = {
1057 "None",
1058 "MapBuffer",
1059 "MapBufferRange",
1060 "Chromium",
1061 };
1062 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1063 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1064 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1065 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1066 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1067
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001068 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001069 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001070 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001071 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001072 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001073 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1074 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1075 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1076 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001077
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001078 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001079 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1080 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001081 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001082 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1083 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001084 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -08001085 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1086 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1087 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001088 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001089 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001090 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1091 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001092 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001093 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001094 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
ericrkb4ecabd2016-03-11 15:18:20 -08001095 r.appendf("BGRA to RGBA readback conversions are slow: %s\n",
1096 (fRGBAToBGRAReadbackConversionsAreSlow ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001097
1098 r.append("Configs\n-------\n");
1099 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1100 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001101 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1102 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001103 i,
1104 fConfigTable[i].fFlags,
1105 fConfigTable[i].fFormats.fBaseInternalFormat,
1106 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001107 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1108 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001109 fConfigTable[i].fFormats.fExternalType,
1110 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001111 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001112 }
1113
jvanverthe9c0fc62015-04-29 11:18:05 -07001114 return r;
1115}
1116
jvanverthe9c0fc62015-04-29 11:18:05 -07001117static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1118 switch (p) {
1119 case kLow_GrSLPrecision:
1120 return GR_GL_LOW_FLOAT;
1121 case kMedium_GrSLPrecision:
1122 return GR_GL_MEDIUM_FLOAT;
1123 case kHigh_GrSLPrecision:
1124 return GR_GL_HIGH_FLOAT;
1125 }
1126 SkFAIL("Unknown precision.");
1127 return -1;
1128}
1129
1130static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1131 switch (type) {
1132 case kVertex_GrShaderType:
1133 return GR_GL_VERTEX_SHADER;
1134 case kGeometry_GrShaderType:
1135 return GR_GL_GEOMETRY_SHADER;
1136 case kFragment_GrShaderType:
1137 return GR_GL_FRAGMENT_SHADER;
1138 }
1139 SkFAIL("Unknown shader type.");
1140 return -1;
1141}
1142
jvanverthcba99b82015-06-24 06:59:57 -07001143void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1144 const GrGLInterface* intf,
1145 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001146 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1147 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1148 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1149 if (kGeometry_GrShaderType != s) {
1150 GrShaderType shaderType = static_cast<GrShaderType>(s);
1151 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001152 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001153 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001154 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1155 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1156 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1157 GrGLint range[2];
1158 GrGLint bits;
1159 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1160 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001161 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1162 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1163 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001164 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001165 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001166 }
jvanverthcba99b82015-06-24 06:59:57 -07001167 else if (!glslCaps->fShaderPrecisionVaries) {
1168 glslCaps->fShaderPrecisionVaries =
1169 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001170 }
1171 }
1172 }
1173 }
1174 }
1175 }
1176 else {
1177 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001178 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001179 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1180 if (kGeometry_GrShaderType != s) {
1181 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001182 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1183 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1184 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001185 }
1186 }
1187 }
1188 }
1189 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1190 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1191 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1192 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001193 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001194 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001195 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1196 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001197 }
1198 }
1199}
1200
bsalomon41e4384e2016-01-08 09:12:44 -08001201bool GrGLCaps::bgraIsInternalFormat() const {
1202 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1203}
1204
bsalomon76148af2016-01-12 11:13:47 -08001205bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1206 GrGLenum* internalFormat, GrGLenum* externalFormat,
1207 GrGLenum* externalType) const {
1208 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1209 externalFormat, externalType)) {
1210 return false;
1211 }
1212 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1213 return true;
1214}
1215
1216bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1217 GrGLenum* internalFormat) const {
1218 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1219 return false;
1220 }
1221 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1222 return true;
1223}
1224
1225bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1226 GrGLenum* externalFormat, GrGLenum* externalType) const {
1227 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1228 externalFormat, externalType)) {
1229 return false;
1230 }
1231 return true;
1232}
1233
1234bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1235 if (GrPixelConfigIsCompressed(config)) {
1236 return false;
1237 }
1238 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1239 return true;
1240}
1241
1242bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1243 ExternalFormatUsage usage, GrGLenum* externalFormat,
1244 GrGLenum* externalType) const {
1245 SkASSERT(externalFormat && externalType);
1246 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1247 return false;
1248 }
1249
1250 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1251 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1252
1253 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1254 // made to work in many cases using glPixelStore and what not but is not needed currently.
1255 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1256 return false;
1257 }
1258
1259 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1260 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1261
bsalomone9573312016-01-25 14:33:25 -08001262 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1263 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1264 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1265 // texture, not the red component.
1266 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1267 if (this->textureRedSupport()) {
1268 SkASSERT(GR_GL_RED == *externalFormat);
1269 *externalFormat = GR_GL_ALPHA;
1270 }
1271 }
1272
bsalomon76148af2016-01-12 11:13:47 -08001273 return true;
1274}
1275
bsalomoncdee0092016-01-08 13:20:12 -08001276void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1277 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001278 /*
1279 Comments on renderability of configs on various GL versions.
1280 OpenGL < 3.0:
1281 no built in support for render targets.
1282 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1283 format RGB, RGBA and NV float formats we don't use.
1284 This is the following:
1285 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1286 RGB10_A2, RGBA12,RGBA16
1287 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1288 since they aren't required by later standards and the driver can simply return
1289 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1290 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1291 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1292 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1293 This adds a lot of additional renderable sized formats, including ALPHA8.
1294 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1295 16F, 32I, 32UI, and 32F variants).
1296 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1297
1298 For both the above extensions we limit ourselves to those that are also required by
1299 OpenGL 3.0.
1300
1301 OpenGL 3.0:
1302 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1303 but are not required to be supported as renderable textures/renderbuffer.
1304 Required renderable color formats:
1305 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1306 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1307 RGB10_A2.
1308 - R11F_G11F_B10F.
1309 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1310 and RG8UI.
1311 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1312 - ALPHA8
1313
1314 OpenGL 3.1, 3.2, 3.3
1315 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1316 OpengGL 3.3, 4.0, 4.1
1317 Adds RGB10_A2UI.
1318 OpengGL 4.2
1319 Adds
1320 - RGB5_A1, RGBA4
1321 - RGB565
1322 OpenGL 4.4
1323 Does away with the separate list and adds a column to the sized internal color format
1324 table. However, no new formats become required color renderable.
1325
1326 ES 2.0
1327 color renderable: RGBA4, RGB5_A1, RGB565
1328 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1329 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1330 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1331 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1332 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1333 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1334
1335 ES 3.0
1336 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1337 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1338 RGB5_A1.
1339 - RGB8 and RGB565.
1340 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1341 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1342 ES 3.1
1343 Adds RGB10_A2, RGB10_A2UI,
1344 ES 3.2
1345 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1346 */
1347 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1348 if (kNone_MSFBOType != fMSFBOType) {
1349 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1350 }
1351
1352 GrGLStandard standard = ctxInfo.standard();
1353 GrGLVersion version = ctxInfo.version();
1354
cblume790d5132016-02-29 11:13:29 -08001355 bool texStorageSupported = false;
1356 if (kGL_GrGLStandard == standard) {
1357 // The EXT version can apply to either GL or GLES.
1358 texStorageSupported = version >= GR_GL_VER(4,2) ||
1359 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1360 ctxInfo.hasExtension("GL_EXT_texture_storage");
1361 } else {
1362 // Qualcomm Adreno drivers appear to have issues with texture storage.
1363 texStorageSupported = (version >= GR_GL_VER(3,0) &&
1364 kQualcomm_GrGLVendor != ctxInfo.vendor()) &&
1365 ctxInfo.hasExtension("GL_EXT_texture_storage");
1366 }
1367
1368 // TODO: remove after command buffer supports full ES 3.0
1369 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0) &&
1370 kChromium_GrGLDriver == ctxInfo.driver()) {
1371 texStorageSupported = false;
1372 }
1373
bsalomon30447372015-12-21 09:03:05 -08001374 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1375 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001376 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001377 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001378 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001379 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001380
1381 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1382 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001383 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1384 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001385 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001386 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001387 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1388 if (kGL_GrGLStandard == standard) {
1389 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1390 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001391 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001392 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1393 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1394 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1395 }
egdaniel4999df82016-01-07 17:06:04 -08001396 }
cblume790d5132016-02-29 11:13:29 -08001397 if (texStorageSupported) {
1398 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1399 }
bsalomoncdee0092016-01-08 13:20:12 -08001400 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001401
bsalomon76148af2016-01-12 11:13:47 -08001402 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1403 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001404 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001405 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001406 if (kGL_GrGLStandard == standard) {
1407 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1408 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1409 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1410 // Since the internal format is RGBA8, it is also renderable.
1411 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1412 allRenderFlags;
1413 }
1414 } else {
1415 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1416 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1417 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1418 // The APPLE extension doesn't make this renderable.
1419 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1420 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1421 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1422 // Though, that seems to not be the case if the texture storage extension is
1423 // present. The specs don't exactly make that clear.
1424 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1425 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1426 }
1427 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1428 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1429 ConfigInfo::kRenderable_Flag;
1430 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001431 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001432 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1433 ConfigInfo::kRenderableWithMSAA_Flag;
1434 }
1435 }
1436 }
cblume790d5132016-02-29 11:13:29 -08001437 if (texStorageSupported) {
1438 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1439 }
bsalomoncdee0092016-01-08 13:20:12 -08001440 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001441
brianosmana6359362016-03-21 06:55:37 -07001442 // We only enable srgb support if both textures and FBOs support srgb,
brianosman64d094d2016-03-25 06:01:59 -07001443 // *and* we can disable sRGB decode-on-read, to support "legacy" mode,
1444 // *and* we can disable sRGB encode-on-write.
bsalomon41e4384e2016-01-08 09:12:44 -08001445 if (kGL_GrGLStandard == standard) {
1446 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001447 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001448 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1449 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1450 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001451 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001452 }
1453 }
1454 // All the above srgb extensions support toggling srgb writes
bsalomon41e4384e2016-01-08 09:12:44 -08001455 } else {
1456 // See https://bug.skia.org/4148 for PowerVR issue.
brianosmana6359362016-03-21 06:55:37 -07001457 fSRGBSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
bsalomon41e4384e2016-01-08 09:12:44 -08001458 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1459 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1460 // sRGB writing for destinations.
brianosman64d094d2016-03-25 06:01:59 -07001461 fSRGBSupport = fSRGBSupport && ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001462 }
brianosmana6359362016-03-21 06:55:37 -07001463 if (!ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode")) {
1464 // To support "legacy" L32 mode, we require the ability to turn off sRGB decode:
1465 fSRGBSupport = false;
1466 }
bsalomon30447372015-12-21 09:03:05 -08001467 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1468 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1469 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1470 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001471 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1472 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001473 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001474 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001475 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001476 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1477 allRenderFlags;
1478 }
cblume790d5132016-02-29 11:13:29 -08001479 if (texStorageSupported) {
1480 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1481 }
bsalomoncdee0092016-01-08 13:20:12 -08001482 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001483
brianosmana6359362016-03-21 06:55:37 -07001484 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1485 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1486 // is in this format, for example).
1487 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1488 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1489 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1490 // external format is GL_BGRA.
1491 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1492 GR_GL_BGRA;
1493 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1494 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1495 if (fSRGBSupport) {
1496 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1497 allRenderFlags;
1498 }
1499 if (texStorageSupported) {
1500 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1501 }
1502 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1503
bsalomon30447372015-12-21 09:03:05 -08001504 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1505 if (this->ES2CompatibilitySupport()) {
1506 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1507 } else {
1508 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1509 }
bsalomon76148af2016-01-12 11:13:47 -08001510 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1511 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001512 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001513 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001514 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1515 if (kGL_GrGLStandard == standard) {
1516 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1517 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1518 }
1519 } else {
1520 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1521 }
cblume790d5132016-02-29 11:13:29 -08001522 // 565 is not a sized internal format on desktop GL. So on desktop with
1523 // 565 we always use an unsized internal format to let the system pick
1524 // the best sized format to convert the 565 data to. Since TexStorage
1525 // only allows sized internal formats we disallow it.
1526 //
1527 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1528 // update.
1529 if (texStorageSupported && kGL_GrGLStandard != standard) {
1530 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1531 }
bsalomoncdee0092016-01-08 13:20:12 -08001532 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001533
1534 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1535 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001536 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1537 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001538 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001539 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001540 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1541 if (kGL_GrGLStandard == standard) {
1542 if (version >= GR_GL_VER(4, 2)) {
1543 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1544 }
1545 } else {
1546 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1547 }
cblume790d5132016-02-29 11:13:29 -08001548 if (texStorageSupported) {
1549 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1550 }
bsalomoncdee0092016-01-08 13:20:12 -08001551 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001552
1553 if (this->textureRedSupport()) {
1554 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1555 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001556 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1557 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001558 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001559 } else {
1560 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1561 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001562 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1563 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001564 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001565 }
1566 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001567 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001568 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1569 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1570 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1571 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1572 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1573 }
cblume790d5132016-02-29 11:13:29 -08001574 if (texStorageSupported) {
1575 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1576 }
bsalomon41e4384e2016-01-08 09:12:44 -08001577
1578 // Check for [half] floating point texture support
1579 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1580 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1581 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1582 bool hasFPTextures = false;
1583 bool hasHalfFPTextures = false;
1584 // for now we don't support floating point MSAA on ES
1585 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1586 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1587
1588 if (kGL_GrGLStandard == standard) {
1589 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1590 hasFPTextures = true;
1591 hasHalfFPTextures = true;
1592 }
1593 } else {
1594 if (version >= GR_GL_VER(3, 1)) {
1595 hasFPTextures = true;
1596 hasHalfFPTextures = true;
1597 } else {
1598 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1599 ctxInfo.hasExtension("GL_OES_texture_float")) {
1600 hasFPTextures = true;
1601 }
1602 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1603 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1604 hasHalfFPTextures = true;
1605 }
1606 }
1607 }
bsalomon30447372015-12-21 09:03:05 -08001608
1609 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1610 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001611 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1612 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001613 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001614 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001615 if (hasFPTextures) {
1616 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1617 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1618 // many precision issues and no clients actually want this yet.
1619 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1620 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1621 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1622 }
1623 }
cblume790d5132016-02-29 11:13:29 -08001624 if (texStorageSupported) {
1625 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1626 }
bsalomoncdee0092016-01-08 13:20:12 -08001627 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001628
1629 if (this->textureRedSupport()) {
1630 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1631 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001632 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1633 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001634 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001635 } else {
1636 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1637 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001638 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1639 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001640 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001641 }
1642 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1643 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1644 } else {
1645 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1646 }
bsalomon7928ef62016-01-05 10:26:39 -08001647 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001648 if (hasHalfFPTextures) {
1649 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1650 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1651 // GL_RED internal format.
1652 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1653 (this->textureRedSupport() &&
1654 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1655 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1656 }
1657 }
cblume790d5132016-02-29 11:13:29 -08001658 if (texStorageSupported) {
1659 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1660 }
bsalomon30447372015-12-21 09:03:05 -08001661
1662 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1663 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001664 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1665 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001666 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1667 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1668 } else {
1669 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1670 }
bsalomon7928ef62016-01-05 10:26:39 -08001671 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001672 if (hasHalfFPTextures) {
1673 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1674 // ES requires 3.2 or EXT_color_buffer_half_float.
1675 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1676 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1677 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1678 }
1679 }
cblume790d5132016-02-29 11:13:29 -08001680 if (texStorageSupported) {
1681 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1682 }
bsalomoncdee0092016-01-08 13:20:12 -08001683 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001684
1685 // Compressed texture support
1686
1687 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1688 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1689
1690 // TODO: Fix command buffer bindings and remove this.
1691 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001692
1693 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001694 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001695
1696 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1697 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001698 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001699 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001700 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001701 // Disable this for now, while we investigate https://bug.skia.org/4333
1702 if (false) {
1703 // Check for 8-bit palette..
1704 GrGLint numFormats;
1705 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1706 if (numFormats) {
1707 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1708 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1709 for (int i = 0; i < numFormats; ++i) {
1710 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1711 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1712 break;
1713 }
1714 }
1715 }
1716 }
bsalomoncdee0092016-01-08 13:20:12 -08001717 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001718
bsalomon41e4384e2016-01-08 09:12:44 -08001719 // May change the internal format based on extensions.
1720 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1721 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1722 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1723 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1724 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1725 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1726 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1727 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1728 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1729 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1730 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1731 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1732 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1733 GR_GL_COMPRESSED_RED_RGTC1;
1734 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1735 GR_GL_COMPRESSED_RED_RGTC1;
1736 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1737 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1738 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1739 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1740 GR_GL_COMPRESSED_3DC_X;
1741
bsalomon30447372015-12-21 09:03:05 -08001742 }
bsalomon76148af2016-01-12 11:13:47 -08001743 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001744 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001745 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001746 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001747
1748 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1749 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001750 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001751 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001752 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001753 if (kGL_GrGLStandard == standard) {
1754 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1755 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1756 }
1757 } else {
1758 if (version >= GR_GL_VER(3, 0) ||
1759 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1760 // ETC2 is a superset of ETC1, so we can just check for that, too.
1761 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1762 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1763 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1764 }
1765 }
bsalomoncdee0092016-01-08 13:20:12 -08001766 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001767
1768 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1769 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001770 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001771 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001772 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001773 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1774 // decompressing the textures in the driver, and is generally slower.
1775 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1776 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1777 }
bsalomoncdee0092016-01-08 13:20:12 -08001778 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001779
1780 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1781 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1782 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1783 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001784 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1785 0;
bsalomon30447372015-12-21 09:03:05 -08001786 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001787 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001788 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1789 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1790 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1791 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1792 }
bsalomoncdee0092016-01-08 13:20:12 -08001793 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001794
1795 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1796
1797 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001798 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1799 ctxInfo.version() >= GR_GL_VER(3,0));
1800 // All ES versions (thus far) require sized internal formats for render buffers.
1801 // TODO: Always use sized internal format?
1802 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1803
bsalomon30447372015-12-21 09:03:05 -08001804 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001805 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1806 // param to glTex[Sub]Image.
1807 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1808 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1809 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1810 fConfigTable[i].fFormats.fSizedInternalFormat :
1811 fConfigTable[i].fFormats.fBaseInternalFormat;
1812 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001813 fConfigTable[i].fFormats.fSizedInternalFormat :
1814 fConfigTable[i].fFormats.fBaseInternalFormat;
1815 }
1816 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1817 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1818 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1819 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1820 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001821 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001822 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001823
1824 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1825 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1826 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1827 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001828 }
1829
1830 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1831 // as a base format.
1832 // GL_EXT_texture_format_BGRA8888:
1833 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1834 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1835 // formats.
1836 // GL_APPLE_texture_format_BGRA8888:
1837 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1838 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1839 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001840 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001841 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1842 }
1843
bsalomoncdee0092016-01-08 13:20:12 -08001844 // If we don't have texture swizzle support then the shader generator must insert the
1845 // swizzle into shader code.
1846 if (!this->textureSwizzleSupport()) {
1847 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1848 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1849 }
1850 }
1851
bsalomon7f9b2e42016-01-12 13:29:26 -08001852 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1853 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1854 // gets written to the single component.
1855 if (this->textureRedSupport()) {
1856 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1857 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1858 if (GrPixelConfigIsAlphaOnly(config) &&
1859 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1860 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1861 }
1862 }
1863 }
1864
bsalomon30447372015-12-21 09:03:05 -08001865#ifdef SK_DEBUG
1866 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001867 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001868 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001869 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1870 fConfigTable[i].fFormats.fBaseInternalFormat);
1871 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001872 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001873 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1874 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1875 fConfigTable[i].fFormats.fExternalFormat[j]);
1876 }
1877 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001878 }
1879#endif
1880}
1881
egdanielb7e7d572015-11-04 04:23:53 -08001882void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}