blob: af31480ba74d80db4716ccffaf3aad370f9d4c0a [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.com60da4172012-06-01 19:25:00 +000029 fMaxVertexAttributes = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030 fUnpackRowLengthSupport = false;
31 fUnpackFlipYSupport = false;
32 fPackRowLengthSupport = false;
33 fPackFlipYSupport = false;
34 fTextureUsageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000035 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000036 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000037 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070038 fDirectStateAccessSupport = false;
39 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080040 fES2CompatibilitySupport = false;
cdaltond4727922015-11-10 12:49:06 -080041 fMultisampleDisableSupport = false;
cdalton06604b92016-02-05 10:09:51 -080042 fDrawIndirectSupport = false;
43 fMultiDrawIndirectSupport = false;
44 fBaseInstanceSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000045 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000046 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070047 fBindFragDataLocationSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080048 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080049 fTextureSwizzleSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070050 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070051 fRGBA8888PixelsOpsAreSlow = false;
52 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080053 fMipMapLevelAndLodControlSupport = false;
ericrkb4ecabd2016-03-11 15:18:20 -080054 fRGBAToBGRAReadbackConversionsAreSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070055
bsalomon083617b2016-02-12 12:10:14 -080056 fBlitFramebufferSupport = kNone_BlitFramebufferSupport;
57
halcanary385fe4d2015-08-26 13:07:48 -070058 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070059
cdalton4cd67132015-06-10 19:23:46 -070060 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000061}
62
cdalton4cd67132015-06-10 19:23:46 -070063void GrGLCaps::init(const GrContextOptions& contextOptions,
64 const GrGLContextInfo& ctxInfo,
65 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000066 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000067 GrGLVersion version = ctxInfo.version();
68
bsalomon@google.combcce8922013-03-25 15:38:39 +000069 /**************************************************************************
70 * Caps specific to GrGLCaps
71 **************************************************************************/
72
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000073 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000074 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
75 &fMaxFragmentUniformVectors);
76 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000077 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000078 GrGLint max;
79 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
80 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000081 if (version >= GR_GL_VER(3, 2)) {
82 GrGLint profileMask;
83 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
84 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
85 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000086 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000087 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000088
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000089 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000090 fUnpackRowLengthSupport = true;
91 fUnpackFlipYSupport = false;
92 fPackRowLengthSupport = true;
93 fPackFlipYSupport = false;
94 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000095 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
96 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000097 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000098 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
99 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000100 fPackFlipYSupport =
101 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
102 }
103
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000104 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000105 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
106
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000107 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700108 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
109 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
110 ctxInfo.hasExtension("GL_NV_texture_barrier");
111 } else {
112 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
113 }
114
cdaltoneb79eea2016-02-26 10:39:34 -0800115 if (kGL_GrGLStandard == standard) {
116 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
117 ctxInfo.hasExtension("GL_ARB_texture_multisample");
118 } else {
119 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
120 }
121
hendrikwa0d5ad72014-12-02 07:30:30 -0800122 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
123 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700124 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800125 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000126 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
127 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800128 } else {
129 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
130 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000131 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000132 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000133 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000134 ctxInfo.hasExtension("GL_ARB_imaging");
135
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000136 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
137 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
138 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
139 // limit this decision to specific GPU families rather than basing it on the vendor alone.
140 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700141 (kARM_GrGLVendor == ctxInfo.vendor() ||
142 kImagination_GrGLVendor == ctxInfo.vendor() ||
143 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000144 fUseNonVBOVertexAndIndexDynamicData = true;
145 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000146
egdaniel9250d242015-05-18 13:04:26 -0700147 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
148 // Thus we are blacklisting this extension for now on Adreno4xx devices.
149 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
150 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
151 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
152 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000153 fDiscardRenderTargetSupport = true;
154 fInvalidateFBType = kInvalidate_InvalidateFBType;
155 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
156 fDiscardRenderTargetSupport = true;
157 fInvalidateFBType = kDiscard_InvalidateFBType;
158 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000159
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000160 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
161 fFullClearIsFree = true;
162 }
163
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000164 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000165 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800166 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
167 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000168 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000169 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
170 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000171 }
172
cdalton626e1ff2015-06-12 13:56:46 -0700173 if (kGL_GrGLStandard == standard) {
174 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
175 } else {
176 fDirectStateAccessSupport = false;
177 }
178
179 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
180 fDebugSupport = true;
181 } else {
182 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
183 }
184
jvanverth3f801cb2014-12-16 09:49:38 -0800185 if (kGL_GrGLStandard == standard) {
186 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
187 }
188 else {
189 fES2CompatibilitySupport = true;
190 }
191
cdalton0edea2c2015-05-21 08:27:44 -0700192 if (kGL_GrGLStandard == standard) {
193 fMultisampleDisableSupport = true;
194 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700195 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700196 }
197
kkinnunend94708e2015-07-30 22:47:04 -0700198 if (kGL_GrGLStandard == standard) {
199 if (version >= GR_GL_VER(3, 0)) {
200 fBindFragDataLocationSupport = true;
201 }
202 } else {
203 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
204 fBindFragDataLocationSupport = true;
205 }
joshualittc1f56b52015-06-22 12:31:31 -0700206 }
207
bsalomonb8909d32016-01-28 07:09:52 -0800208#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700209 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
bsalomonb8909d32016-01-28 07:09:52 -0800210#else
211 fBindUniformLocationSupport = false;
212#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700213
kkinnunene06ed252016-02-16 23:15:40 -0800214 if (kGL_GrGLStandard == standard) {
215 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
216 // We also require textureSize() support for rectangle 2D samplers which was added in
217 // GLSL 1.40.
218 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
219 fRectangleTextureSupport = true;
220 }
bsalomone179a912016-01-20 06:18:10 -0800221 }
kkinnunene06ed252016-02-16 23:15:40 -0800222 } else {
223 // Command buffer exposes this in GL ES context for Chromium reasons,
224 // but it should not be used. Also, at the time of writing command buffer
225 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800226 }
227
bsalomoncdee0092016-01-08 13:20:12 -0800228 if (kGL_GrGLStandard == standard) {
229 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
230 fTextureSwizzleSupport = true;
231 }
232 } else {
233 if (version >= GR_GL_VER(3,0)) {
234 fTextureSwizzleSupport = true;
235 }
236 }
237
cblume09bd2c02016-03-01 14:08:28 -0800238 if (kGL_GrGLStandard == standard) {
239 fMipMapLevelAndLodControlSupport = true;
240 } else if (kGLES_GrGLStandard == standard) {
241 if (version >= GR_GL_VER(3,0)) {
242 fMipMapLevelAndLodControlSupport = true;
243 }
244 }
245
bsalomon88c7b982015-07-31 11:20:16 -0700246#ifdef SK_BUILD_FOR_WIN
247 // We're assuming that on Windows Chromium we're using ANGLE.
248 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
249 kChromium_GrGLDriver == ctxInfo.driver();
250 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
251 fRGBA8888PixelsOpsAreSlow = isANGLE;
252 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
253 // check DX11 ANGLE.
254 fPartialFBOReadIsSlow = isANGLE;
255#endif
256
ericrkb4ecabd2016-03-11 15:18:20 -0800257 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
258 bool isMAC = false;
259#ifdef SK_BUILD_FOR_MAC
260 isMAC = true;
261#endif
262
263 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
264 // vis-versa.
265 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
266
cdalton4cd67132015-06-10 19:23:46 -0700267 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700268 * GrShaderCaps fields
269 **************************************************************************/
270
egdaniel0a482332015-10-26 08:59:10 -0700271 // This must be called after fCoreProfile is set on the GrGLCaps
272 this->initGLSL(ctxInfo);
273 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
274
egdaniel05ded892015-10-26 07:38:05 -0700275 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
276
277 // For now these two are equivalent but we could have dst read in shader via some other method.
278 // Before setting this, initGLSL() must have been called.
279 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
280
281 // Enable supported shader-related caps
282 if (kGL_GrGLStandard == standard) {
283 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
284 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
285 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
286 glslCaps->fShaderDerivativeSupport = true;
287 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
288 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
289 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
cdalton793dc262016-02-08 10:11:47 -0800290 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
291 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700292 }
293 else {
294 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
295
296 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
297 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800298
299 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
300 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700301 }
302
ethannicholas22793252016-01-30 09:59:10 -0800303 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
304 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
305 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
306 &glslCaps->fPixelLocalStorageSize);
307 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
308 }
309 else {
310 glslCaps->fPixelLocalStorageSize = 0;
311 glslCaps->fPLSPathRenderingSupport = false;
312 }
313
cdalton9c3f1432016-03-11 10:07:37 -0800314 // Protect ourselves against tracking huge amounts of texture state.
315 static const uint8_t kMaxSaneSamplers = 32;
316 GrGLint maxSamplers;
317 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
318 glslCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
319 if (glslCaps->fGeometryShaderSupport) {
320 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
321 glslCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
322 }
323 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
324 glslCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
325 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
326 glslCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
327
egdaniel05ded892015-10-26 07:38:05 -0700328 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700329 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000330 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700331
cdalton63f6c1f2015-11-06 07:09:43 -0800332 // We need dual source blending and the ability to disable multisample in order to support mixed
333 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800334 if (fMultisampleDisableSupport &&
335 glslCaps->dualSourceBlendingSupport() &&
336 fShaderCaps->pathRenderingSupport()) {
337 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800338 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800339 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800340 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
341 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800342 fDiscardRenderTargetSupport = false;
343 fInvalidateFBType = kNone_InvalidateFBType;
344 }
345 }
346
egdanieleed519e2016-01-15 11:36:18 -0800347 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700348 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700349 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700350 this->initStencilFormats(ctxInfo);
351
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000352 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000353 // we could also look for GL_ATI_separate_stencil extension or
354 // GL_EXT_stencil_two_side but they use different function signatures
355 // than GL2.0+ (and than each other).
356 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
357 // supported on GL 1.4 and higher or by extension
358 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
359 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
360 } else {
361 // ES 2 has two sided stencil and stencil wrap
362 fTwoSidedStencilSupport = true;
363 fStencilWrapOpsSupport = true;
364 }
365
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000366 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000367 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
368 // extension includes glMapBuffer.
369 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
370 fMapBufferFlags |= kSubset_MapFlag;
371 fMapBufferType = kMapBufferRange_MapBufferType;
372 } else {
373 fMapBufferType = kMapBuffer_MapBufferType;
374 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000375 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000376 // Unextended GLES2 doesn't have any buffer mapping.
377 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800378 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800379 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
380 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800381 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
382 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
383 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000384 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
385 fMapBufferFlags = kCanMap_MapFlag;
386 fMapBufferType = kMapBuffer_MapBufferType;
387 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000388 }
389
jvanverthd7a2c1f2015-12-07 07:36:44 -0800390 if (kGL_GrGLStandard == standard) {
391 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
392 fTransferBufferType = kPBO_TransferBufferType;
393 }
394 } else {
395 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
396 fTransferBufferType = kPBO_TransferBufferType;
397 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
398 fTransferBufferType = kChromium_TransferBufferType;
399 }
400 }
401
joshualitte5b74c62015-06-01 14:17:47 -0700402 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
403 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
404 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700405 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
406 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
407 // a small subset.
408#if 0
cdalton1acea862015-06-02 13:05:52 -0700409 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700410#else
411 fGeometryBufferMapThreshold = SK_MaxS32;
412#endif
joshualitte5b74c62015-06-01 14:17:47 -0700413 }
414
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000415 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000416 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
417 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
418 fNPOTTextureTileSupport = true;
419 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000420 } else {
421 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000422 // ES3 has no limitations.
423 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
424 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000425 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
426 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
427 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
428 // to alllow arbitrary wrap modes, however.
429 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000430 }
431
bsalomone72bd022015-10-26 07:33:03 -0700432 // Using MIPs on this GPU seems to be a source of trouble.
433 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
434 fMipMapSupport = false;
435 }
436
bsalomon@google.combcce8922013-03-25 15:38:39 +0000437 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
438 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
439 // Our render targets are always created with textures as the color
440 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000441 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000442
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000443 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
444
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000445 // Disable scratch texture reuse on Mali and Adreno devices
446 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
447 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000448
robertphillips1b8e1b52015-06-24 06:54:10 -0700449#if 0
450 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
451 kQualcomm_GrGLVendor != ctxInfo.vendor();
452#endif
453
egdaniel05ded892015-10-26 07:38:05 -0700454 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000455 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800456 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000457 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800458 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000459 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800460 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
461 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
462 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
463 // This is to guard against platforms that may not support as many samples for
464 // glRasterSamples as they do for framebuffers.
465 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
466 }
467 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000468
bsalomon63b21962014-11-05 07:05:34 -0800469 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800470 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800471 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800472 fUseDrawInsteadOfClear = true;
473 }
474
joshualitt83bc2292015-06-18 14:18:02 -0700475 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
476 fUseDrawInsteadOfPartialRenderTargetWrite = true;
477 }
478
bsalomonbabafcc2016-02-16 11:36:47 -0800479 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
480 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
481 fUseDrawInsteadOfPartialRenderTargetWrite = true;
482 fUseDrawInsteadOfAllRenderTargetWrites = true;
483 }
484
robertphillips63926682015-08-20 09:39:02 -0700485#ifdef SK_BUILD_FOR_WIN
486 // On ANGLE deferring flushes can lead to GPU starvation
487 fPreferVRAMUseOverFlushes = !isANGLE;
488#endif
489
bsalomon7dea7b72015-08-19 08:26:51 -0700490 if (kChromium_GrGLDriver == ctxInfo.driver()) {
491 fMustClearUploadedBufferData = true;
492 }
493
bsalomond08ea5f2015-02-20 06:58:13 -0800494 if (kGL_GrGLStandard == standard) {
495 // ARB allows mixed size FBO attachments, EXT does not.
496 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
497 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
498 fOversizedStencilSupport = true;
499 } else {
500 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
501 }
502 } else {
503 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
504 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
505 }
506
joshualitt58001552015-06-26 12:46:36 -0700507 if (kGL_GrGLStandard == standard) {
508 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
509 // instanced arrays, but we could make this more granular if we wanted
510 fSupportsInstancedDraws =
511 version >= GR_GL_VER(3, 2) ||
512 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
513 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
514 } else {
515 fSupportsInstancedDraws =
516 version >= GR_GL_VER(3, 0) ||
517 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
518 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
519 }
520
cdalton06604b92016-02-05 10:09:51 -0800521 if (kGL_GrGLStandard == standard) {
522 // We don't use ARB_draw_indirect because it does not support a base instance.
523 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER.
524 fDrawIndirectSupport =
525 fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3);
526 } else {
527 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
528 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
529 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
530 }
531
jvanverthcba99b82015-06-24 06:59:57 -0700532 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800533
534 if (contextOptions.fUseShaderSwizzling) {
535 fTextureSwizzleSupport = false;
536 }
537
538 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
539 // already been detected.
540 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700541
542 this->applyOptionsOverrides(contextOptions);
543 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000544}
545
egdaniel472d44e2015-10-22 08:20:00 -0700546const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
547 bool isCoreProfile) {
548 switch (generation) {
549 case k110_GrGLSLGeneration:
550 if (kGLES_GrGLStandard == standard) {
551 // ES2s shader language is based on version 1.20 but is version
552 // 1.00 of the ES language.
553 return "#version 100\n";
554 } else {
555 SkASSERT(kGL_GrGLStandard == standard);
556 return "#version 110\n";
557 }
558 case k130_GrGLSLGeneration:
559 SkASSERT(kGL_GrGLStandard == standard);
560 return "#version 130\n";
561 case k140_GrGLSLGeneration:
562 SkASSERT(kGL_GrGLStandard == standard);
563 return "#version 140\n";
564 case k150_GrGLSLGeneration:
565 SkASSERT(kGL_GrGLStandard == standard);
566 if (isCoreProfile) {
567 return "#version 150\n";
568 } else {
569 return "#version 150 compatibility\n";
570 }
571 case k330_GrGLSLGeneration:
572 if (kGLES_GrGLStandard == standard) {
573 return "#version 300 es\n";
574 } else {
575 SkASSERT(kGL_GrGLStandard == standard);
576 if (isCoreProfile) {
577 return "#version 330\n";
578 } else {
579 return "#version 330 compatibility\n";
580 }
581 }
cdalton33ad7012016-02-22 07:55:44 -0800582 case k400_GrGLSLGeneration:
583 SkASSERT(kGL_GrGLStandard == standard);
584 if (isCoreProfile) {
585 return "#version 400\n";
586 } else {
587 return "#version 400 compatibility\n";
588 }
egdaniel472d44e2015-10-22 08:20:00 -0700589 case k310es_GrGLSLGeneration:
590 SkASSERT(kGLES_GrGLStandard == standard);
591 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800592 case k320es_GrGLSLGeneration:
593 SkASSERT(kGLES_GrGLStandard == standard);
594 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700595 }
596 return "<no version>";
597}
598
egdaniel05ded892015-10-26 07:38:05 -0700599void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700600 GrGLStandard standard = ctxInfo.standard();
601 GrGLVersion version = ctxInfo.version();
602
603 /**************************************************************************
604 * Caps specific to GrGLSLCaps
605 **************************************************************************/
606
607 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
608 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700609 if (kGLES_GrGLStandard == standard) {
610 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
611 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
612 glslCaps->fFBFetchSupport = true;
613 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
614 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
615 }
616 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
617 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
618 glslCaps->fFBFetchNeedsCustomOutput = false;
619 glslCaps->fFBFetchSupport = true;
620 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
621 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
622 }
623 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
624 // The arm extension also requires an additional flag which we will set onResetContext
625 glslCaps->fFBFetchNeedsCustomOutput = false;
626 glslCaps->fFBFetchSupport = true;
627 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
628 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
629 }
630 glslCaps->fUsesPrecisionModifiers = true;
631 }
632
633 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
634
cdaltonc08f1962016-02-12 12:14:06 -0800635 if (kGL_GrGLStandard == standard) {
636 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
637 } else {
638 glslCaps->fFlatInterpolationSupport =
639 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
640 }
641
642 if (kGL_GrGLStandard == standard) {
643 glslCaps->fNoPerspectiveInterpolationSupport =
644 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
645 } else {
646 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
647 glslCaps->fNoPerspectiveInterpolationSupport = true;
648 glslCaps->fNoPerspectiveInterpolationExtensionString =
649 "GL_NV_shader_noperspective_interpolation";
650 }
651 }
652
cdalton33ad7012016-02-22 07:55:44 -0800653 if (kGL_GrGLStandard == standard) {
cdalton4a98cdb2016-03-01 12:12:20 -0800654 glslCaps->fMultisampleInterpolationSupport =
655 ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
656 } else {
657 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
658 glslCaps->fMultisampleInterpolationSupport = true;
659 } else if (ctxInfo.hasExtension("GL_OES_shader_multisample_interpolation")) {
660 glslCaps->fMultisampleInterpolationSupport = true;
661 glslCaps->fMultisampleInterpolationExtensionString =
662 "GL_OES_shader_multisample_interpolation";
663 }
664 }
665
666 if (kGL_GrGLStandard == standard) {
cdalton33ad7012016-02-22 07:55:44 -0800667 glslCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
668 } else {
669 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
670 glslCaps->fSampleVariablesSupport = true;
671 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
672 glslCaps->fSampleVariablesSupport = true;
673 glslCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
674 }
675 }
676
677 if (glslCaps->fSampleVariablesSupport) {
678 glslCaps->fSampleMaskOverrideCoverageSupport =
679 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage");
680 }
681
egdaniel472d44e2015-10-22 08:20:00 -0700682 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
683 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
684
685 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
686 // function that may require a gradient calculation inside a conditional block may return
687 // undefined results". This appears to be an issue with the 'any' call since even the simple
688 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
689 // from our GrTextureDomain processor.
690 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
691
egdaniel472d44e2015-10-22 08:20:00 -0700692 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
693 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800694
695 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
696 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
697 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800698
699 // Frag Coords Convention support is not part of ES
700 // Known issue on at least some Intel platforms:
701 // http://code.google.com/p/skia/issues/detail?id=946
702 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
703 kGLES_GrGLStandard != standard &&
704 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
705 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
706 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
707 }
708
709 if (kGLES_GrGLStandard == standard) {
710 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
711 }
712
cdalton9c3f1432016-03-11 10:07:37 -0800713 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
714 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
715 glslCaps->fExternalTextureSupport = true;
716 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
717 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
718 // At least one driver has been found that has this extension without the "GL_" prefix.
719 glslCaps->fExternalTextureSupport = true;
720 }
721 }
722
723 if (glslCaps->fExternalTextureSupport) {
bsalomon7ea33f52015-11-22 14:51:00 -0800724 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
725 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
726 } else {
727 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
728 }
729 }
730
cdaltonc04ce672016-03-11 14:07:38 -0800731 if (kGL_GrGLStandard == standard) {
732 glslCaps->fBufferTextureSupport = ctxInfo.version() > GR_GL_VER(3, 1) &&
733 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
734 } else {
735 if (ctxInfo.version() > GR_GL_VER(3, 2) &&
736 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
737 glslCaps->fBufferTextureSupport = true;
738 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
739 glslCaps->fBufferTextureSupport = true;
740 glslCaps->fBufferTextureExtensionString = "GL_OES_texture_buffer";
741 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
742 glslCaps->fBufferTextureSupport = true;
743 glslCaps->fBufferTextureExtensionString = "GL_EXT_texture_buffer";
744 }
745 }
746
egdaniel8dcdedc2015-11-11 06:27:20 -0800747 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
748 // the abs first in a separate expression.
749 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
750 glslCaps->fCanUseMinAndAbsTogether = false;
751 }
752
bsalomon7ea33f52015-11-22 14:51:00 -0800753 // 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 -0800754 // thus must us -1.0 * %s.x to work correctly
755 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
756 glslCaps->fMustForceNegatedAtanParamToFloat = true;
757 }
egdaniel472d44e2015-10-22 08:20:00 -0700758}
759
kkinnunencfe62e32015-07-01 02:58:50 -0700760bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700761 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
762
763 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700764 return false;
765 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700766
kkinnunencfe62e32015-07-01 02:58:50 -0700767 if (kGL_GrGLStandard == ctxInfo.standard()) {
768 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
769 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
770 return false;
771 }
772 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700773 if (!hasChromiumPathRendering &&
774 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700775 return false;
776 }
777 }
778 // We only support v1.3+ of GL_NV_path_rendering which allows us to
779 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
780 // additions are detected by checking the existence of the function.
781 // We also use *Then* functions that not all drivers might have. Check
782 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800783 if (!gli->fFunctions.fStencilThenCoverFillPath ||
784 !gli->fFunctions.fStencilThenCoverStrokePath ||
785 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
786 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
787 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700788 return false;
789 }
790 return true;
791}
bsalomon1aa20292016-01-22 08:16:09 -0800792
793bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800794 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800795 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
796 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800797 // If it's not possible to even have a render target of rtConfig then read pixels is
798 // not supported regardless of readConfig.
799 if (!this->isConfigRenderable(rtConfig, false)) {
800 return false;
801 }
bsalomon7928ef62016-01-05 10:26:39 -0800802
bsalomon76148af2016-01-12 11:13:47 -0800803 GrGLenum readFormat;
804 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800805 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800806 return false;
807 }
808
bsalomon1aa20292016-01-22 08:16:09 -0800809 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800810 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
811 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
812 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
813 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
814 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
815 readFormat != GR_GL_BGRA) {
816 return false;
817 }
818 // There is also a set of allowed types, but all the types we use are in the set:
819 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
820 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
821 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
822 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
823 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
824 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
825 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800826 return true;
piotaixre4b23142014-10-02 10:57:53 -0700827 }
bsalomon7928ef62016-01-05 10:26:39 -0800828
bsalomon76148af2016-01-12 11:13:47 -0800829 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800830
bsalomon1aa20292016-01-22 08:16:09 -0800831 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800832 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
833 return true;
834 }
835 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800836 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800837 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
838 return true;
839 }
840 }
841
bsalomon1aa20292016-01-22 08:16:09 -0800842 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800843 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800844 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800845 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800846 if (!bindRenderTarget()) {
847 return false;
848 }
849 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
850 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800851 rpFormat->fFormat = format;
852 rpFormat->fType = type;
853 }
854
bsalomon1aa20292016-01-22 08:16:09 -0800855 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
856 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700857}
858
robertphillips@google.com6177e692013-02-28 20:16:25 +0000859void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000860
861 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000862 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000863 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
864 // ES3 driver bugs on at least one device with a tiled GPU (N10).
865 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
866 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
867 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
868 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800869 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700870 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000871 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000872 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
873 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
874 // chrome's extension is equivalent to the EXT msaa
875 // and fbo_blit extensions.
876 fMSFBOType = kDesktop_EXT_MSFBOType;
877 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
878 fMSFBOType = kES_Apple_MSFBOType;
879 }
bsalomon083617b2016-02-12 12:10:14 -0800880
881 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
882 // is available.
883 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
884 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
885 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
886 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
887 // limitations.
888 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
889 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000890 } else {
egdanieleed519e2016-01-15 11:36:18 -0800891 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700892 fMSFBOType = kMixedSamples_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800893 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
vbuzinovdded6962015-06-12 08:59:45 -0700894 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000895 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000896 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800897 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000898 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
899 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000900 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800901 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000902 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000903 }
904}
905
cdalton1dd05422015-06-12 09:01:18 -0700906void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
907 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
908
909 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
910 // for now until its own blacklists can be updated.
911 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
912 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700913 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700914 return;
915 }
916
917 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
918 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
919 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
920 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
921 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
922 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
923 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
924 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
925 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
926 return;
927 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
928 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
929 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
930 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
931 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
932 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
933 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
934 // slow on a particular platform.
935 } else {
936 return; // No advanced blend support.
937 }
938
939 SkASSERT(this->advancedBlendEquationSupport());
940
941 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
942 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
943 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
944 (1 << kColorBurn_GrBlendEquation);
945 }
joel.liang9764c402015-07-09 19:46:18 -0700946 if (kARM_GrGLVendor == ctxInfo.vendor()) {
947 // Blacklist color-burn on ARM until the fix is released.
948 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
949 }
cdalton1dd05422015-06-12 09:01:18 -0700950}
951
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000952namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700953const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000954}
955
956void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
957
958 // Build up list of legal stencil formats (though perhaps not supported on
959 // the particular gpu/driver) from most preferred to least.
960
961 // these consts are in order of most preferred to least preferred
962 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
963
964 static const StencilFormat
965 // internal Format stencil bits total bits packed?
966 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
967 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
968 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
969 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000970 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000971 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
972
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000973 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000974 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000975 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000976 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
977 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
978
979 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
980 // require FBO support we can expect these are legal formats and don't
981 // check. These also all support the unsized GL_STENCIL_INDEX.
982 fStencilFormats.push_back() = gS8;
983 fStencilFormats.push_back() = gS16;
984 if (supportsPackedDS) {
985 fStencilFormats.push_back() = gD24S8;
986 }
987 fStencilFormats.push_back() = gS4;
988 if (supportsPackedDS) {
989 fStencilFormats.push_back() = gDS;
990 }
991 } else {
992 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
993 // for other formats.
994 // ES doesn't support using the unsized format.
995
996 fStencilFormats.push_back() = gS8;
997 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000998 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
999 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001000 fStencilFormats.push_back() = gD24S8;
1001 }
1002 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1003 fStencilFormats.push_back() = gS4;
1004 }
1005 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001006}
1007
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001008SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001009
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001010 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001011
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001012 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001013 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001014 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001015 i,
1016 fStencilFormats[i].fStencilBits,
1017 fStencilFormats[i].fTotalBits);
1018 }
1019
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001020 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001021 "None",
1022 "ARB",
1023 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001024 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001025 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001026 "IMG MS To Texture",
1027 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001028 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001029 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001030 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1031 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1032 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001033 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1034 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1035 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1036 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001037 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001038 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001039
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001040 static const char* kInvalidateFBTypeStr[] = {
1041 "None",
1042 "Discard",
1043 "Invalidate",
1044 };
1045 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1046 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1047 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1048 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001049
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001050 static const char* kMapBufferTypeStr[] = {
1051 "None",
1052 "MapBuffer",
1053 "MapBufferRange",
1054 "Chromium",
1055 };
1056 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1057 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1058 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1059 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1060 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1061
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001062 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001063 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001064 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001065 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001066 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001067 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001068 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1069 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1070 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1071 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001072
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001073 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001074 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1075 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001076 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001077 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1078 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001079 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -08001080 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1081 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1082 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001083 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001084 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001085 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001086 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1087 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001088 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001089 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001090 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
ericrkb4ecabd2016-03-11 15:18:20 -08001091 r.appendf("BGRA to RGBA readback conversions are slow: %s\n",
1092 (fRGBAToBGRAReadbackConversionsAreSlow ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001093
1094 r.append("Configs\n-------\n");
1095 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1096 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001097 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1098 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001099 i,
1100 fConfigTable[i].fFlags,
1101 fConfigTable[i].fFormats.fBaseInternalFormat,
1102 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001103 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1104 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001105 fConfigTable[i].fFormats.fExternalType,
1106 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001107 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001108 }
1109
jvanverthe9c0fc62015-04-29 11:18:05 -07001110 return r;
1111}
1112
jvanverthe9c0fc62015-04-29 11:18:05 -07001113static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1114 switch (p) {
1115 case kLow_GrSLPrecision:
1116 return GR_GL_LOW_FLOAT;
1117 case kMedium_GrSLPrecision:
1118 return GR_GL_MEDIUM_FLOAT;
1119 case kHigh_GrSLPrecision:
1120 return GR_GL_HIGH_FLOAT;
1121 }
1122 SkFAIL("Unknown precision.");
1123 return -1;
1124}
1125
1126static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1127 switch (type) {
1128 case kVertex_GrShaderType:
1129 return GR_GL_VERTEX_SHADER;
1130 case kGeometry_GrShaderType:
1131 return GR_GL_GEOMETRY_SHADER;
1132 case kFragment_GrShaderType:
1133 return GR_GL_FRAGMENT_SHADER;
1134 }
1135 SkFAIL("Unknown shader type.");
1136 return -1;
1137}
1138
jvanverthcba99b82015-06-24 06:59:57 -07001139void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1140 const GrGLInterface* intf,
1141 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001142 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1143 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1144 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1145 if (kGeometry_GrShaderType != s) {
1146 GrShaderType shaderType = static_cast<GrShaderType>(s);
1147 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001148 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001149 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001150 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1151 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1152 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1153 GrGLint range[2];
1154 GrGLint bits;
1155 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1156 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001157 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1158 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1159 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001160 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001161 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001162 }
jvanverthcba99b82015-06-24 06:59:57 -07001163 else if (!glslCaps->fShaderPrecisionVaries) {
1164 glslCaps->fShaderPrecisionVaries =
1165 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001166 }
1167 }
1168 }
1169 }
1170 }
1171 }
1172 else {
1173 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001174 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001175 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1176 if (kGeometry_GrShaderType != s) {
1177 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001178 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1179 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1180 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001181 }
1182 }
1183 }
1184 }
1185 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1186 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1187 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1188 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001189 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001190 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001191 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1192 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001193 }
1194 }
1195}
1196
bsalomon41e4384e2016-01-08 09:12:44 -08001197bool GrGLCaps::bgraIsInternalFormat() const {
1198 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1199}
1200
bsalomon76148af2016-01-12 11:13:47 -08001201bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1202 GrGLenum* internalFormat, GrGLenum* externalFormat,
1203 GrGLenum* externalType) const {
1204 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1205 externalFormat, externalType)) {
1206 return false;
1207 }
1208 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1209 return true;
1210}
1211
1212bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1213 GrGLenum* internalFormat) const {
1214 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1215 return false;
1216 }
1217 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1218 return true;
1219}
1220
1221bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1222 GrGLenum* externalFormat, GrGLenum* externalType) const {
1223 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1224 externalFormat, externalType)) {
1225 return false;
1226 }
1227 return true;
1228}
1229
1230bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1231 if (GrPixelConfigIsCompressed(config)) {
1232 return false;
1233 }
1234 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1235 return true;
1236}
1237
1238bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1239 ExternalFormatUsage usage, GrGLenum* externalFormat,
1240 GrGLenum* externalType) const {
1241 SkASSERT(externalFormat && externalType);
1242 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1243 return false;
1244 }
1245
1246 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1247 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1248
1249 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1250 // made to work in many cases using glPixelStore and what not but is not needed currently.
1251 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1252 return false;
1253 }
1254
1255 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1256 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1257
bsalomone9573312016-01-25 14:33:25 -08001258 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1259 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1260 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1261 // texture, not the red component.
1262 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1263 if (this->textureRedSupport()) {
1264 SkASSERT(GR_GL_RED == *externalFormat);
1265 *externalFormat = GR_GL_ALPHA;
1266 }
1267 }
1268
bsalomon76148af2016-01-12 11:13:47 -08001269 return true;
1270}
1271
bsalomoncdee0092016-01-08 13:20:12 -08001272void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1273 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001274 /*
1275 Comments on renderability of configs on various GL versions.
1276 OpenGL < 3.0:
1277 no built in support for render targets.
1278 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1279 format RGB, RGBA and NV float formats we don't use.
1280 This is the following:
1281 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1282 RGB10_A2, RGBA12,RGBA16
1283 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1284 since they aren't required by later standards and the driver can simply return
1285 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1286 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1287 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1288 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1289 This adds a lot of additional renderable sized formats, including ALPHA8.
1290 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1291 16F, 32I, 32UI, and 32F variants).
1292 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1293
1294 For both the above extensions we limit ourselves to those that are also required by
1295 OpenGL 3.0.
1296
1297 OpenGL 3.0:
1298 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1299 but are not required to be supported as renderable textures/renderbuffer.
1300 Required renderable color formats:
1301 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1302 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1303 RGB10_A2.
1304 - R11F_G11F_B10F.
1305 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1306 and RG8UI.
1307 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1308 - ALPHA8
1309
1310 OpenGL 3.1, 3.2, 3.3
1311 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1312 OpengGL 3.3, 4.0, 4.1
1313 Adds RGB10_A2UI.
1314 OpengGL 4.2
1315 Adds
1316 - RGB5_A1, RGBA4
1317 - RGB565
1318 OpenGL 4.4
1319 Does away with the separate list and adds a column to the sized internal color format
1320 table. However, no new formats become required color renderable.
1321
1322 ES 2.0
1323 color renderable: RGBA4, RGB5_A1, RGB565
1324 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1325 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1326 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1327 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1328 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1329 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1330
1331 ES 3.0
1332 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1333 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1334 RGB5_A1.
1335 - RGB8 and RGB565.
1336 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1337 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1338 ES 3.1
1339 Adds RGB10_A2, RGB10_A2UI,
1340 ES 3.2
1341 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1342 */
1343 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1344 if (kNone_MSFBOType != fMSFBOType) {
1345 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1346 }
1347
1348 GrGLStandard standard = ctxInfo.standard();
1349 GrGLVersion version = ctxInfo.version();
1350
cblume790d5132016-02-29 11:13:29 -08001351 bool texStorageSupported = false;
1352 if (kGL_GrGLStandard == standard) {
1353 // The EXT version can apply to either GL or GLES.
1354 texStorageSupported = version >= GR_GL_VER(4,2) ||
1355 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1356 ctxInfo.hasExtension("GL_EXT_texture_storage");
1357 } else {
1358 // Qualcomm Adreno drivers appear to have issues with texture storage.
1359 texStorageSupported = (version >= GR_GL_VER(3,0) &&
1360 kQualcomm_GrGLVendor != ctxInfo.vendor()) &&
1361 ctxInfo.hasExtension("GL_EXT_texture_storage");
1362 }
1363
1364 // TODO: remove after command buffer supports full ES 3.0
1365 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0) &&
1366 kChromium_GrGLDriver == ctxInfo.driver()) {
1367 texStorageSupported = false;
1368 }
1369
bsalomon30447372015-12-21 09:03:05 -08001370 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1371 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001372 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001373 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001374 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001375 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001376
1377 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1378 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001379 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1380 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001381 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001382 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001383 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1384 if (kGL_GrGLStandard == standard) {
1385 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1386 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001387 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001388 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1389 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1390 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1391 }
egdaniel4999df82016-01-07 17:06:04 -08001392 }
cblume790d5132016-02-29 11:13:29 -08001393 if (texStorageSupported) {
1394 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1395 }
bsalomoncdee0092016-01-08 13:20:12 -08001396 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001397
bsalomon76148af2016-01-12 11:13:47 -08001398 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1399 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001400 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001401 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001402 if (kGL_GrGLStandard == standard) {
1403 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1404 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1405 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1406 // Since the internal format is RGBA8, it is also renderable.
1407 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1408 allRenderFlags;
1409 }
1410 } else {
1411 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1412 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1413 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1414 // The APPLE extension doesn't make this renderable.
1415 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1416 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1417 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1418 // Though, that seems to not be the case if the texture storage extension is
1419 // present. The specs don't exactly make that clear.
1420 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1421 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1422 }
1423 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1424 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1425 ConfigInfo::kRenderable_Flag;
1426 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001427 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001428 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1429 ConfigInfo::kRenderableWithMSAA_Flag;
1430 }
1431 }
1432 }
cblume790d5132016-02-29 11:13:29 -08001433 if (texStorageSupported) {
1434 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1435 }
bsalomoncdee0092016-01-08 13:20:12 -08001436 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001437
brianosmana6359362016-03-21 06:55:37 -07001438 // We only enable srgb support if both textures and FBOs support srgb,
1439 // *and* we can disable sRGB decode-on-read, to support "legacy" mode.
bsalomon41e4384e2016-01-08 09:12:44 -08001440 if (kGL_GrGLStandard == standard) {
1441 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001442 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001443 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1444 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1445 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001446 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001447 }
1448 }
1449 // All the above srgb extensions support toggling srgb writes
brianosmana6359362016-03-21 06:55:37 -07001450 fSRGBWriteControl = fSRGBSupport;
bsalomon41e4384e2016-01-08 09:12:44 -08001451 } else {
1452 // See https://bug.skia.org/4148 for PowerVR issue.
brianosmana6359362016-03-21 06:55:37 -07001453 fSRGBSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
bsalomon41e4384e2016-01-08 09:12:44 -08001454 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1455 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1456 // sRGB writing for destinations.
1457 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1458 }
brianosmana6359362016-03-21 06:55:37 -07001459 if (!ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode")) {
1460 // To support "legacy" L32 mode, we require the ability to turn off sRGB decode:
1461 fSRGBSupport = false;
1462 }
bsalomon30447372015-12-21 09:03:05 -08001463 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1464 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1465 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1466 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001467 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1468 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001469 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001470 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001471 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001472 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1473 allRenderFlags;
1474 }
cblume790d5132016-02-29 11:13:29 -08001475 if (texStorageSupported) {
1476 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1477 }
bsalomoncdee0092016-01-08 13:20:12 -08001478 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001479
brianosmana6359362016-03-21 06:55:37 -07001480 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1481 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1482 // is in this format, for example).
1483 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1484 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1485 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1486 // external format is GL_BGRA.
1487 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1488 GR_GL_BGRA;
1489 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1490 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1491 if (fSRGBSupport) {
1492 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1493 allRenderFlags;
1494 }
1495 if (texStorageSupported) {
1496 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1497 }
1498 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1499
bsalomon30447372015-12-21 09:03:05 -08001500 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1501 if (this->ES2CompatibilitySupport()) {
1502 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1503 } else {
1504 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1505 }
bsalomon76148af2016-01-12 11:13:47 -08001506 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1507 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001508 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001509 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001510 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1511 if (kGL_GrGLStandard == standard) {
1512 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1513 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1514 }
1515 } else {
1516 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1517 }
cblume790d5132016-02-29 11:13:29 -08001518 // 565 is not a sized internal format on desktop GL. So on desktop with
1519 // 565 we always use an unsized internal format to let the system pick
1520 // the best sized format to convert the 565 data to. Since TexStorage
1521 // only allows sized internal formats we disallow it.
1522 //
1523 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1524 // update.
1525 if (texStorageSupported && kGL_GrGLStandard != standard) {
1526 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1527 }
bsalomoncdee0092016-01-08 13:20:12 -08001528 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001529
1530 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1531 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001532 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1533 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001534 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001535 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001536 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1537 if (kGL_GrGLStandard == standard) {
1538 if (version >= GR_GL_VER(4, 2)) {
1539 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1540 }
1541 } else {
1542 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1543 }
cblume790d5132016-02-29 11:13:29 -08001544 if (texStorageSupported) {
1545 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1546 }
bsalomoncdee0092016-01-08 13:20:12 -08001547 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001548
1549 if (this->textureRedSupport()) {
1550 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1551 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001552 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1553 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001554 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001555 } else {
1556 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1557 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001558 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1559 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001560 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001561 }
1562 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001563 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001564 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1565 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1566 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1567 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1568 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1569 }
cblume790d5132016-02-29 11:13:29 -08001570 if (texStorageSupported) {
1571 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1572 }
bsalomon41e4384e2016-01-08 09:12:44 -08001573
1574 // Check for [half] floating point texture support
1575 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1576 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1577 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1578 bool hasFPTextures = false;
1579 bool hasHalfFPTextures = false;
1580 // for now we don't support floating point MSAA on ES
1581 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1582 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1583
1584 if (kGL_GrGLStandard == standard) {
1585 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1586 hasFPTextures = true;
1587 hasHalfFPTextures = true;
1588 }
1589 } else {
1590 if (version >= GR_GL_VER(3, 1)) {
1591 hasFPTextures = true;
1592 hasHalfFPTextures = true;
1593 } else {
1594 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1595 ctxInfo.hasExtension("GL_OES_texture_float")) {
1596 hasFPTextures = true;
1597 }
1598 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1599 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1600 hasHalfFPTextures = true;
1601 }
1602 }
1603 }
bsalomon30447372015-12-21 09:03:05 -08001604
1605 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1606 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001607 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1608 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001609 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001610 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001611 if (hasFPTextures) {
1612 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1613 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1614 // many precision issues and no clients actually want this yet.
1615 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1616 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1617 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1618 }
1619 }
cblume790d5132016-02-29 11:13:29 -08001620 if (texStorageSupported) {
1621 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1622 }
bsalomoncdee0092016-01-08 13:20:12 -08001623 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001624
1625 if (this->textureRedSupport()) {
1626 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1627 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001628 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1629 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001630 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001631 } else {
1632 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1633 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001634 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1635 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001636 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001637 }
1638 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1639 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1640 } else {
1641 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1642 }
bsalomon7928ef62016-01-05 10:26:39 -08001643 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001644 if (hasHalfFPTextures) {
1645 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1646 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1647 // GL_RED internal format.
1648 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1649 (this->textureRedSupport() &&
1650 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1651 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1652 }
1653 }
cblume790d5132016-02-29 11:13:29 -08001654 if (texStorageSupported) {
1655 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1656 }
bsalomon30447372015-12-21 09:03:05 -08001657
1658 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1659 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001660 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1661 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001662 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1663 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1664 } else {
1665 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1666 }
bsalomon7928ef62016-01-05 10:26:39 -08001667 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001668 if (hasHalfFPTextures) {
1669 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1670 // ES requires 3.2 or EXT_color_buffer_half_float.
1671 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1672 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1673 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1674 }
1675 }
cblume790d5132016-02-29 11:13:29 -08001676 if (texStorageSupported) {
1677 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1678 }
bsalomoncdee0092016-01-08 13:20:12 -08001679 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001680
1681 // Compressed texture support
1682
1683 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1684 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1685
1686 // TODO: Fix command buffer bindings and remove this.
1687 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001688
1689 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001690 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001691
1692 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1693 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001694 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001695 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001696 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001697 // Disable this for now, while we investigate https://bug.skia.org/4333
1698 if (false) {
1699 // Check for 8-bit palette..
1700 GrGLint numFormats;
1701 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1702 if (numFormats) {
1703 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1704 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1705 for (int i = 0; i < numFormats; ++i) {
1706 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1707 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1708 break;
1709 }
1710 }
1711 }
1712 }
bsalomoncdee0092016-01-08 13:20:12 -08001713 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001714
bsalomon41e4384e2016-01-08 09:12:44 -08001715 // May change the internal format based on extensions.
1716 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1717 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1718 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1719 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1720 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1721 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1722 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1723 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1724 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1725 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1726 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1727 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1728 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1729 GR_GL_COMPRESSED_RED_RGTC1;
1730 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1731 GR_GL_COMPRESSED_RED_RGTC1;
1732 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1733 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1734 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1735 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1736 GR_GL_COMPRESSED_3DC_X;
1737
bsalomon30447372015-12-21 09:03:05 -08001738 }
bsalomon76148af2016-01-12 11:13:47 -08001739 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001740 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001741 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001742 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001743
1744 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1745 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001746 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001747 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001748 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001749 if (kGL_GrGLStandard == standard) {
1750 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1751 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1752 }
1753 } else {
1754 if (version >= GR_GL_VER(3, 0) ||
1755 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1756 // ETC2 is a superset of ETC1, so we can just check for that, too.
1757 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1758 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1759 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1760 }
1761 }
bsalomoncdee0092016-01-08 13:20:12 -08001762 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001763
1764 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1765 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001766 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001767 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001768 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001769 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1770 // decompressing the textures in the driver, and is generally slower.
1771 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1772 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1773 }
bsalomoncdee0092016-01-08 13:20:12 -08001774 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001775
1776 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1777 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1778 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1779 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001780 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1781 0;
bsalomon30447372015-12-21 09:03:05 -08001782 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001783 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001784 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1785 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1786 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1787 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1788 }
bsalomoncdee0092016-01-08 13:20:12 -08001789 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001790
1791 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1792
1793 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001794 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1795 ctxInfo.version() >= GR_GL_VER(3,0));
1796 // All ES versions (thus far) require sized internal formats for render buffers.
1797 // TODO: Always use sized internal format?
1798 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1799
bsalomon30447372015-12-21 09:03:05 -08001800 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001801 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1802 // param to glTex[Sub]Image.
1803 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1804 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1805 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1806 fConfigTable[i].fFormats.fSizedInternalFormat :
1807 fConfigTable[i].fFormats.fBaseInternalFormat;
1808 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001809 fConfigTable[i].fFormats.fSizedInternalFormat :
1810 fConfigTable[i].fFormats.fBaseInternalFormat;
1811 }
1812 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1813 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1814 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1815 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1816 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001817 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001818 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001819
1820 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1821 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1822 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1823 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001824 }
1825
1826 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1827 // as a base format.
1828 // GL_EXT_texture_format_BGRA8888:
1829 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1830 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1831 // formats.
1832 // GL_APPLE_texture_format_BGRA8888:
1833 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1834 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1835 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001836 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001837 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1838 }
1839
bsalomoncdee0092016-01-08 13:20:12 -08001840 // If we don't have texture swizzle support then the shader generator must insert the
1841 // swizzle into shader code.
1842 if (!this->textureSwizzleSupport()) {
1843 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1844 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1845 }
1846 }
1847
bsalomon7f9b2e42016-01-12 13:29:26 -08001848 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1849 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1850 // gets written to the single component.
1851 if (this->textureRedSupport()) {
1852 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1853 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1854 if (GrPixelConfigIsAlphaOnly(config) &&
1855 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1856 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1857 }
1858 }
1859 }
1860
bsalomon30447372015-12-21 09:03:05 -08001861#ifdef SK_DEBUG
1862 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001863 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001864 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001865 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1866 fConfigTable[i].fFormats.fBaseInternalFormat);
1867 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001868 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001869 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1870 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1871 fConfigTable[i].fFormats.fExternalFormat[j]);
1872 }
1873 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001874 }
1875#endif
1876}
1877
egdanielb7e7d572015-11-04 04:23:53 -08001878void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}