blob: f3e494acb90cfd2e1d1fd8003dd18ba395357988 [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9#include "GrGLCaps.h"
joshualittb4384b92014-10-21 12:53:15 -070010
egdanielb7e7d572015-11-04 04:23:53 -080011#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000012#include "GrGLContext.h"
bsalomon1aa20292016-01-22 08:16:09 -080013#include "GrGLRenderTarget.h"
jvanverthcba99b82015-06-24 06:59:57 -070014#include "glsl/GrGLSLCaps.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000015#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000016#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000017
bsalomon682c2692015-05-22 14:01:46 -070018GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
19 const GrGLContextInfo& ctxInfo,
20 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080021 fStandard = ctxInfo.standard();
22
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000023 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000024 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000025 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000026 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080027 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028 fMaxFragmentUniformVectors = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fUnpackRowLengthSupport = false;
30 fUnpackFlipYSupport = false;
31 fPackRowLengthSupport = false;
32 fPackFlipYSupport = false;
33 fTextureUsageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000034 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000035 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000036 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070037 fDirectStateAccessSupport = false;
38 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080039 fES2CompatibilitySupport = false;
cdaltond4727922015-11-10 12:49:06 -080040 fMultisampleDisableSupport = false;
cdalton06604b92016-02-05 10:09:51 -080041 fDrawIndirectSupport = false;
42 fMultiDrawIndirectSupport = false;
43 fBaseInstanceSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000044 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070046 fBindFragDataLocationSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080047 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080048 fTextureSwizzleSupport = false;
bsalomon88c7b982015-07-31 11:20:16 -070049 fRGBA8888PixelsOpsAreSlow = false;
50 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080051 fMipMapLevelAndLodControlSupport = false;
ericrkb4ecabd2016-03-11 15:18:20 -080052 fRGBAToBGRAReadbackConversionsAreSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070053
bsalomon083617b2016-02-12 12:10:14 -080054 fBlitFramebufferSupport = kNone_BlitFramebufferSupport;
55
halcanary385fe4d2015-08-26 13:07:48 -070056 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070057
cdalton4cd67132015-06-10 19:23:46 -070058 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000059}
60
cdalton4cd67132015-06-10 19:23:46 -070061void GrGLCaps::init(const GrContextOptions& contextOptions,
62 const GrGLContextInfo& ctxInfo,
63 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000064 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000065 GrGLVersion version = ctxInfo.version();
66
bsalomon@google.combcce8922013-03-25 15:38:39 +000067 /**************************************************************************
68 * Caps specific to GrGLCaps
69 **************************************************************************/
70
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000071 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000072 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
73 &fMaxFragmentUniformVectors);
74 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000075 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000076 GrGLint max;
77 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
78 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000079 if (version >= GR_GL_VER(3, 2)) {
80 GrGLint profileMask;
81 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
82 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
83 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000084 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000085 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000086
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000087 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000088 fUnpackRowLengthSupport = true;
89 fUnpackFlipYSupport = false;
90 fPackRowLengthSupport = true;
91 fPackFlipYSupport = false;
92 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000093 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
94 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000095 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000096 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
97 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098 fPackFlipYSupport =
99 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
100 }
101
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000102 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000103 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
104
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000105 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700106 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
107 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
108 ctxInfo.hasExtension("GL_NV_texture_barrier");
109 } else {
110 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
111 }
112
cdaltoneb79eea2016-02-26 10:39:34 -0800113 if (kGL_GrGLStandard == standard) {
114 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
115 ctxInfo.hasExtension("GL_ARB_texture_multisample");
116 } else {
117 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
118 }
119
halcanary9d524f22016-03-29 09:03:52 -0700120 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
hendrikwa0d5ad72014-12-02 07:30:30 -0800121 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700122 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800123 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000124 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
125 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800126 } else {
127 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
128 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000129 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000130 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000131 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000132 ctxInfo.hasExtension("GL_ARB_imaging");
133
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000134 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
135 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
136 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
137 // limit this decision to specific GPU families rather than basing it on the vendor alone.
138 if (!GR_GL_MUST_USE_VBO &&
cdaltone2e71c22016-04-07 18:13:29 -0700139 !fIsCoreProfile &&
bsalomoned82c4e2014-09-02 07:54:47 -0700140 (kARM_GrGLVendor == ctxInfo.vendor() ||
141 kImagination_GrGLVendor == ctxInfo.vendor() ||
142 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000143 fUseNonVBOVertexAndIndexDynamicData = true;
144 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000145
egdaniel9250d242015-05-18 13:04:26 -0700146 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
147 // Thus we are blacklisting this extension for now on Adreno4xx devices.
148 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
149 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
150 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
151 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000152 fDiscardRenderTargetSupport = true;
153 fInvalidateFBType = kInvalidate_InvalidateFBType;
154 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
155 fDiscardRenderTargetSupport = true;
156 fInvalidateFBType = kDiscard_InvalidateFBType;
157 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000158
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000159 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
160 fFullClearIsFree = true;
161 }
162
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000163 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000164 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800165 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
166 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000167 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000168 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
169 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000170 }
171
cdalton626e1ff2015-06-12 13:56:46 -0700172 if (kGL_GrGLStandard == standard) {
173 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
174 } else {
175 fDirectStateAccessSupport = false;
176 }
177
178 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
179 fDebugSupport = true;
180 } else {
181 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
182 }
183
jvanverth3f801cb2014-12-16 09:49:38 -0800184 if (kGL_GrGLStandard == standard) {
185 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
186 }
187 else {
188 fES2CompatibilitySupport = true;
189 }
190
cdalton0edea2c2015-05-21 08:27:44 -0700191 if (kGL_GrGLStandard == standard) {
192 fMultisampleDisableSupport = true;
193 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700194 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700195 }
196
kkinnunend94708e2015-07-30 22:47:04 -0700197 if (kGL_GrGLStandard == standard) {
198 if (version >= GR_GL_VER(3, 0)) {
199 fBindFragDataLocationSupport = true;
200 }
201 } else {
202 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
203 fBindFragDataLocationSupport = true;
204 }
joshualittc1f56b52015-06-22 12:31:31 -0700205 }
206
bsalomonb8909d32016-01-28 07:09:52 -0800207#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700208 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
bsalomonb8909d32016-01-28 07:09:52 -0800209#else
210 fBindUniformLocationSupport = false;
211#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700212
kkinnunene06ed252016-02-16 23:15:40 -0800213 if (kGL_GrGLStandard == standard) {
214 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
215 // We also require textureSize() support for rectangle 2D samplers which was added in
216 // GLSL 1.40.
217 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
218 fRectangleTextureSupport = true;
219 }
bsalomone179a912016-01-20 06:18:10 -0800220 }
kkinnunene06ed252016-02-16 23:15:40 -0800221 } else {
222 // Command buffer exposes this in GL ES context for Chromium reasons,
223 // but it should not be used. Also, at the time of writing command buffer
224 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800225 }
226
bsalomoncdee0092016-01-08 13:20:12 -0800227 if (kGL_GrGLStandard == standard) {
228 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
229 fTextureSwizzleSupport = true;
230 }
231 } else {
232 if (version >= GR_GL_VER(3,0)) {
233 fTextureSwizzleSupport = true;
234 }
235 }
236
cblume09bd2c02016-03-01 14:08:28 -0800237 if (kGL_GrGLStandard == standard) {
238 fMipMapLevelAndLodControlSupport = true;
239 } else if (kGLES_GrGLStandard == standard) {
240 if (version >= GR_GL_VER(3,0)) {
241 fMipMapLevelAndLodControlSupport = true;
242 }
243 }
244
bsalomon88c7b982015-07-31 11:20:16 -0700245#ifdef SK_BUILD_FOR_WIN
246 // We're assuming that on Windows Chromium we're using ANGLE.
247 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
248 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700249 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700250 fRGBA8888PixelsOpsAreSlow = isANGLE;
251 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
252 // check DX11 ANGLE.
253 fPartialFBOReadIsSlow = isANGLE;
254#endif
255
ericrkb4ecabd2016-03-11 15:18:20 -0800256 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
257 bool isMAC = false;
258#ifdef SK_BUILD_FOR_MAC
259 isMAC = true;
260#endif
261
262 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
263 // vis-versa.
264 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
265
cdalton4cd67132015-06-10 19:23:46 -0700266 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700267 * GrShaderCaps fields
268 **************************************************************************/
269
egdaniel0a482332015-10-26 08:59:10 -0700270 // This must be called after fCoreProfile is set on the GrGLCaps
271 this->initGLSL(ctxInfo);
272 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
273
egdaniel05ded892015-10-26 07:38:05 -0700274 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
275
276 // For now these two are equivalent but we could have dst read in shader via some other method.
277 // Before setting this, initGLSL() must have been called.
278 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
279
280 // Enable supported shader-related caps
281 if (kGL_GrGLStandard == standard) {
282 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
283 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
284 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
285 glslCaps->fShaderDerivativeSupport = true;
286 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
287 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
288 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
cdalton793dc262016-02-08 10:11:47 -0800289 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
290 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700291 }
292 else {
293 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
294
295 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
296 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800297
298 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
299 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700300 }
301
ethannicholas22793252016-01-30 09:59:10 -0800302 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
303 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
halcanary9d524f22016-03-29 09:03:52 -0700304 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
ethannicholas22793252016-01-30 09:59:10 -0800305 &glslCaps->fPixelLocalStorageSize);
306 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
307 }
308 else {
309 glslCaps->fPixelLocalStorageSize = 0;
310 glslCaps->fPLSPathRenderingSupport = false;
311 }
312
cdalton9c3f1432016-03-11 10:07:37 -0800313 // Protect ourselves against tracking huge amounts of texture state.
314 static const uint8_t kMaxSaneSamplers = 32;
315 GrGLint maxSamplers;
316 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
317 glslCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
318 if (glslCaps->fGeometryShaderSupport) {
319 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
320 glslCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
321 }
322 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
323 glslCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
324 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
325 glslCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
326
egdaniel05ded892015-10-26 07:38:05 -0700327 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700328 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000329 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700330
cdalton63f6c1f2015-11-06 07:09:43 -0800331 // We need dual source blending and the ability to disable multisample in order to support mixed
332 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800333 if (fMultisampleDisableSupport &&
334 glslCaps->dualSourceBlendingSupport() &&
335 fShaderCaps->pathRenderingSupport()) {
336 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800337 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800338 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800339 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
340 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800341 fDiscardRenderTargetSupport = false;
342 fInvalidateFBType = kNone_InvalidateFBType;
343 }
344 }
345
egdanieleed519e2016-01-15 11:36:18 -0800346 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700347 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700348 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700349 this->initStencilFormats(ctxInfo);
350
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000351 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000352 // we could also look for GL_ATI_separate_stencil extension or
353 // GL_EXT_stencil_two_side but they use different function signatures
354 // than GL2.0+ (and than each other).
355 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
356 // supported on GL 1.4 and higher or by extension
357 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
358 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
359 } else {
360 // ES 2 has two sided stencil and stencil wrap
361 fTwoSidedStencilSupport = true;
362 fStencilWrapOpsSupport = true;
363 }
364
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000365 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000366 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
367 // extension includes glMapBuffer.
368 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
369 fMapBufferFlags |= kSubset_MapFlag;
370 fMapBufferType = kMapBufferRange_MapBufferType;
371 } else {
372 fMapBufferType = kMapBuffer_MapBufferType;
373 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000374 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000375 // Unextended GLES2 doesn't have any buffer mapping.
376 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800377 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800378 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
379 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800380 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
381 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
382 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000383 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
384 fMapBufferFlags = kCanMap_MapFlag;
385 fMapBufferType = kMapBuffer_MapBufferType;
386 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000387 }
388
jvanverthd7a2c1f2015-12-07 07:36:44 -0800389 if (kGL_GrGLStandard == standard) {
390 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
391 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700392 }
jvanverthd7a2c1f2015-12-07 07:36:44 -0800393 } else {
394 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
395 fTransferBufferType = kPBO_TransferBufferType;
396 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
397 fTransferBufferType = kChromium_TransferBufferType;
398 }
399 }
400
joshualitte5b74c62015-06-01 14:17:47 -0700401 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
402 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700403 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700404 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
405 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
406 // a small subset.
407#if 0
cdalton397536c2016-03-25 12:15:03 -0700408 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700409#else
cdalton397536c2016-03-25 12:15:03 -0700410 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700411#endif
joshualitte5b74c62015-06-01 14:17:47 -0700412 }
413
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000414 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000415 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
416 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
417 fNPOTTextureTileSupport = true;
418 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000419 } else {
420 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000421 // ES3 has no limitations.
422 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
423 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000424 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
425 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
426 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
427 // to alllow arbitrary wrap modes, however.
428 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000429 }
430
bsalomone72bd022015-10-26 07:33:03 -0700431 // Using MIPs on this GPU seems to be a source of trouble.
432 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
433 fMipMapSupport = false;
434 }
435
bsalomon@google.combcce8922013-03-25 15:38:39 +0000436 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
437 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
438 // Our render targets are always created with textures as the color
439 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000440 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000441
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000442 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
443
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000444 // Disable scratch texture reuse on Mali and Adreno devices
445 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
446 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000447
robertphillips1b8e1b52015-06-24 06:54:10 -0700448#if 0
449 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
450 kQualcomm_GrGLVendor != ctxInfo.vendor();
451#endif
452
egdaniel05ded892015-10-26 07:38:05 -0700453 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000454 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800455 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000456 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800457 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000458 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800459 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
460 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
461 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
462 // This is to guard against platforms that may not support as many samples for
463 // glRasterSamples as they do for framebuffers.
464 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
465 }
466 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000467
bsalomon63b21962014-11-05 07:05:34 -0800468 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800469 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800470 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800471 fUseDrawInsteadOfClear = true;
472 }
473
joshualitt83bc2292015-06-18 14:18:02 -0700474 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
475 fUseDrawInsteadOfPartialRenderTargetWrite = true;
476 }
477
bsalomonbabafcc2016-02-16 11:36:47 -0800478 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
479 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
480 fUseDrawInsteadOfPartialRenderTargetWrite = true;
481 fUseDrawInsteadOfAllRenderTargetWrites = true;
482 }
483
robertphillips63926682015-08-20 09:39:02 -0700484#ifdef SK_BUILD_FOR_WIN
485 // On ANGLE deferring flushes can lead to GPU starvation
486 fPreferVRAMUseOverFlushes = !isANGLE;
487#endif
488
bsalomon7dea7b72015-08-19 08:26:51 -0700489 if (kChromium_GrGLDriver == ctxInfo.driver()) {
490 fMustClearUploadedBufferData = true;
491 }
492
bsalomond08ea5f2015-02-20 06:58:13 -0800493 if (kGL_GrGLStandard == standard) {
494 // ARB allows mixed size FBO attachments, EXT does not.
495 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
496 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
497 fOversizedStencilSupport = true;
498 } else {
499 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
500 }
501 } else {
502 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
503 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
504 }
505
joshualitt58001552015-06-26 12:46:36 -0700506 if (kGL_GrGLStandard == standard) {
507 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
508 // instanced arrays, but we could make this more granular if we wanted
509 fSupportsInstancedDraws =
510 version >= GR_GL_VER(3, 2) ||
511 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
512 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
513 } else {
514 fSupportsInstancedDraws =
515 version >= GR_GL_VER(3, 0) ||
516 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
517 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
518 }
519
cdalton06604b92016-02-05 10:09:51 -0800520 if (kGL_GrGLStandard == standard) {
521 // We don't use ARB_draw_indirect because it does not support a base instance.
522 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER.
523 fDrawIndirectSupport =
524 fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3);
525 } else {
526 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
527 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
528 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
529 }
530
jvanverthcba99b82015-06-24 06:59:57 -0700531 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800532
533 if (contextOptions.fUseShaderSwizzling) {
534 fTextureSwizzleSupport = false;
535 }
536
ethannicholas28ef4452016-03-25 09:26:03 -0700537 if (kGL_GrGLStandard == standard) {
538 if (version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading")) {
539 fSampleShadingSupport = true;
540 }
541 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
542 fSampleShadingSupport = true;
543 }
544
bsalomoncdee0092016-01-08 13:20:12 -0800545 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
546 // already been detected.
547 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700548
549 this->applyOptionsOverrides(contextOptions);
550 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000551}
552
egdaniel472d44e2015-10-22 08:20:00 -0700553const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
554 bool isCoreProfile) {
555 switch (generation) {
556 case k110_GrGLSLGeneration:
557 if (kGLES_GrGLStandard == standard) {
558 // ES2s shader language is based on version 1.20 but is version
559 // 1.00 of the ES language.
560 return "#version 100\n";
561 } else {
562 SkASSERT(kGL_GrGLStandard == standard);
563 return "#version 110\n";
564 }
565 case k130_GrGLSLGeneration:
566 SkASSERT(kGL_GrGLStandard == standard);
567 return "#version 130\n";
568 case k140_GrGLSLGeneration:
569 SkASSERT(kGL_GrGLStandard == standard);
570 return "#version 140\n";
571 case k150_GrGLSLGeneration:
572 SkASSERT(kGL_GrGLStandard == standard);
573 if (isCoreProfile) {
574 return "#version 150\n";
575 } else {
576 return "#version 150 compatibility\n";
577 }
578 case k330_GrGLSLGeneration:
579 if (kGLES_GrGLStandard == standard) {
580 return "#version 300 es\n";
581 } else {
582 SkASSERT(kGL_GrGLStandard == standard);
583 if (isCoreProfile) {
584 return "#version 330\n";
585 } else {
586 return "#version 330 compatibility\n";
587 }
588 }
cdalton33ad7012016-02-22 07:55:44 -0800589 case k400_GrGLSLGeneration:
590 SkASSERT(kGL_GrGLStandard == standard);
591 if (isCoreProfile) {
592 return "#version 400\n";
593 } else {
594 return "#version 400 compatibility\n";
595 }
egdaniel472d44e2015-10-22 08:20:00 -0700596 case k310es_GrGLSLGeneration:
597 SkASSERT(kGLES_GrGLStandard == standard);
598 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800599 case k320es_GrGLSLGeneration:
600 SkASSERT(kGLES_GrGLStandard == standard);
601 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700602 }
603 return "<no version>";
604}
605
egdaniel05ded892015-10-26 07:38:05 -0700606void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700607 GrGLStandard standard = ctxInfo.standard();
608 GrGLVersion version = ctxInfo.version();
609
610 /**************************************************************************
611 * Caps specific to GrGLSLCaps
612 **************************************************************************/
613
614 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
615 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700616 if (kGLES_GrGLStandard == standard) {
617 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
618 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
619 glslCaps->fFBFetchSupport = true;
620 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
621 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
622 }
623 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
624 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
625 glslCaps->fFBFetchNeedsCustomOutput = false;
626 glslCaps->fFBFetchSupport = true;
627 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
628 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
629 }
630 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
631 // The arm extension also requires an additional flag which we will set onResetContext
632 glslCaps->fFBFetchNeedsCustomOutput = false;
633 glslCaps->fFBFetchSupport = true;
634 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
635 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
636 }
637 glslCaps->fUsesPrecisionModifiers = true;
638 }
639
640 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
641
cdaltonc08f1962016-02-12 12:14:06 -0800642 if (kGL_GrGLStandard == standard) {
643 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
644 } else {
645 glslCaps->fFlatInterpolationSupport =
646 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
647 }
648
649 if (kGL_GrGLStandard == standard) {
650 glslCaps->fNoPerspectiveInterpolationSupport =
651 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
652 } else {
653 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
654 glslCaps->fNoPerspectiveInterpolationSupport = true;
655 glslCaps->fNoPerspectiveInterpolationExtensionString =
656 "GL_NV_shader_noperspective_interpolation";
657 }
658 }
659
cdalton33ad7012016-02-22 07:55:44 -0800660 if (kGL_GrGLStandard == standard) {
cdalton4a98cdb2016-03-01 12:12:20 -0800661 glslCaps->fMultisampleInterpolationSupport =
662 ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
663 } else {
664 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
665 glslCaps->fMultisampleInterpolationSupport = true;
666 } else if (ctxInfo.hasExtension("GL_OES_shader_multisample_interpolation")) {
667 glslCaps->fMultisampleInterpolationSupport = true;
668 glslCaps->fMultisampleInterpolationExtensionString =
669 "GL_OES_shader_multisample_interpolation";
670 }
671 }
672
673 if (kGL_GrGLStandard == standard) {
cdalton33ad7012016-02-22 07:55:44 -0800674 glslCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
675 } else {
676 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
677 glslCaps->fSampleVariablesSupport = true;
678 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
679 glslCaps->fSampleVariablesSupport = true;
680 glslCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
681 }
682 }
683
684 if (glslCaps->fSampleVariablesSupport) {
685 glslCaps->fSampleMaskOverrideCoverageSupport =
686 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage");
687 }
688
egdaniel472d44e2015-10-22 08:20:00 -0700689 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
690 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
691
692 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
693 // function that may require a gradient calculation inside a conditional block may return
694 // undefined results". This appears to be an issue with the 'any' call since even the simple
695 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
696 // from our GrTextureDomain processor.
697 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
698
egdaniel472d44e2015-10-22 08:20:00 -0700699 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
700 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800701
702 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
703 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
704 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800705
706 // Frag Coords Convention support is not part of ES
707 // Known issue on at least some Intel platforms:
708 // http://code.google.com/p/skia/issues/detail?id=946
709 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
710 kGLES_GrGLStandard != standard &&
711 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
712 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
713 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
714 }
715
716 if (kGLES_GrGLStandard == standard) {
717 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
718 }
719
cdalton9c3f1432016-03-11 10:07:37 -0800720 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
721 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
722 glslCaps->fExternalTextureSupport = true;
723 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
724 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
725 // At least one driver has been found that has this extension without the "GL_" prefix.
726 glslCaps->fExternalTextureSupport = true;
727 }
728 }
729
730 if (glslCaps->fExternalTextureSupport) {
bsalomon7ea33f52015-11-22 14:51:00 -0800731 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
732 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
733 } else {
734 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
735 }
736 }
737
cdaltonc04ce672016-03-11 14:07:38 -0800738 if (kGL_GrGLStandard == standard) {
cdaltonf8a6ce82016-04-11 13:02:05 -0700739 glslCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc04ce672016-03-11 14:07:38 -0800740 } else {
cdaltonf8a6ce82016-04-11 13:02:05 -0700741 glslCaps->fTexelFetchSupport =
742 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
743 }
744
745 if (glslCaps->fTexelFetchSupport) {
746 if (kGL_GrGLStandard == standard) {
747 glslCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(4, 3) &&
748 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
749 } else {
750 if (ctxInfo.version() >= GR_GL_VER(3, 2) &&
751 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
752 glslCaps->fTexelBufferSupport = true;
753 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
754 glslCaps->fTexelBufferSupport = true;
755 glslCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer";
756 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
757 glslCaps->fTexelBufferSupport = true;
758 glslCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer";
759 }
cdaltonc04ce672016-03-11 14:07:38 -0800760 }
761 }
762
egdaniel8dcdedc2015-11-11 06:27:20 -0800763 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
764 // the abs first in a separate expression.
765 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
766 glslCaps->fCanUseMinAndAbsTogether = false;
767 }
768
bsalomon7ea33f52015-11-22 14:51:00 -0800769 // 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 -0800770 // thus must us -1.0 * %s.x to work correctly
771 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
772 glslCaps->fMustForceNegatedAtanParamToFloat = true;
773 }
egdaniel472d44e2015-10-22 08:20:00 -0700774}
775
kkinnunencfe62e32015-07-01 02:58:50 -0700776bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700777 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
778
779 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700780 return false;
781 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700782
kkinnunencfe62e32015-07-01 02:58:50 -0700783 if (kGL_GrGLStandard == ctxInfo.standard()) {
784 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
785 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
786 return false;
787 }
788 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700789 if (!hasChromiumPathRendering &&
790 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700791 return false;
792 }
793 }
794 // We only support v1.3+ of GL_NV_path_rendering which allows us to
795 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
796 // additions are detected by checking the existence of the function.
797 // We also use *Then* functions that not all drivers might have. Check
798 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800799 if (!gli->fFunctions.fStencilThenCoverFillPath ||
800 !gli->fFunctions.fStencilThenCoverStrokePath ||
801 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
802 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
803 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700804 return false;
805 }
806 return true;
807}
bsalomon1aa20292016-01-22 08:16:09 -0800808
809bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800810 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800811 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
812 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800813 // If it's not possible to even have a render target of rtConfig then read pixels is
814 // not supported regardless of readConfig.
815 if (!this->isConfigRenderable(rtConfig, false)) {
816 return false;
817 }
bsalomon7928ef62016-01-05 10:26:39 -0800818
bsalomon76148af2016-01-12 11:13:47 -0800819 GrGLenum readFormat;
820 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800821 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800822 return false;
823 }
824
bsalomon1aa20292016-01-22 08:16:09 -0800825 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800826 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
827 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
828 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
829 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
830 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
831 readFormat != GR_GL_BGRA) {
832 return false;
833 }
834 // There is also a set of allowed types, but all the types we use are in the set:
835 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
836 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
837 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
838 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
839 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
840 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
841 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800842 return true;
piotaixre4b23142014-10-02 10:57:53 -0700843 }
bsalomon7928ef62016-01-05 10:26:39 -0800844
bsalomon76148af2016-01-12 11:13:47 -0800845 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800846
bsalomon1aa20292016-01-22 08:16:09 -0800847 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800848 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
849 return true;
850 }
851 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800852 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800853 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
854 return true;
855 }
856 }
857
bsalomon1aa20292016-01-22 08:16:09 -0800858 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800859 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800860 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800861 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800862 if (!bindRenderTarget()) {
863 return false;
864 }
865 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
866 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800867 rpFormat->fFormat = format;
868 rpFormat->fType = type;
869 }
870
bsalomon1aa20292016-01-22 08:16:09 -0800871 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
872 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700873}
874
robertphillips@google.com6177e692013-02-28 20:16:25 +0000875void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000876
877 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000878 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000879 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
880 // ES3 driver bugs on at least one device with a tiled GPU (N10).
881 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
882 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
883 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
884 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800885 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700886 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000887 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000888 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
889 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
890 // chrome's extension is equivalent to the EXT msaa
891 // and fbo_blit extensions.
892 fMSFBOType = kDesktop_EXT_MSFBOType;
893 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
894 fMSFBOType = kES_Apple_MSFBOType;
895 }
bsalomon083617b2016-02-12 12:10:14 -0800896
897 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
898 // is available.
899 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
900 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
901 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
902 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
903 // limitations.
904 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
905 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000906 } else {
egdanieleed519e2016-01-15 11:36:18 -0800907 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700908 fMSFBOType = kMixedSamples_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800909 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
vbuzinovdded6962015-06-12 08:59:45 -0700910 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000911 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000912 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800913 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000914 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
915 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000916 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800917 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000918 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000919 }
920}
921
cdalton1dd05422015-06-12 09:01:18 -0700922void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
923 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
924
925 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
926 // for now until its own blacklists can be updated.
927 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
928 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700929 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700930 return;
931 }
932
933 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
934 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
935 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
936 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
937 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
938 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
939 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
940 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
941 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
942 return;
943 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
944 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
945 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
946 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
947 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
948 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
949 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
950 // slow on a particular platform.
951 } else {
952 return; // No advanced blend support.
953 }
954
955 SkASSERT(this->advancedBlendEquationSupport());
956
957 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
958 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
959 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
960 (1 << kColorBurn_GrBlendEquation);
961 }
joel.liang9764c402015-07-09 19:46:18 -0700962 if (kARM_GrGLVendor == ctxInfo.vendor()) {
963 // Blacklist color-burn on ARM until the fix is released.
964 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
965 }
cdalton1dd05422015-06-12 09:01:18 -0700966}
967
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000968namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700969const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000970}
971
972void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
973
974 // Build up list of legal stencil formats (though perhaps not supported on
975 // the particular gpu/driver) from most preferred to least.
976
977 // these consts are in order of most preferred to least preferred
978 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
979
980 static const StencilFormat
981 // internal Format stencil bits total bits packed?
982 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
983 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
984 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
985 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000986 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000987 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
988
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000989 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000990 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000991 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000992 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
993 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
994
995 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
996 // require FBO support we can expect these are legal formats and don't
997 // check. These also all support the unsized GL_STENCIL_INDEX.
998 fStencilFormats.push_back() = gS8;
999 fStencilFormats.push_back() = gS16;
1000 if (supportsPackedDS) {
1001 fStencilFormats.push_back() = gD24S8;
1002 }
1003 fStencilFormats.push_back() = gS4;
1004 if (supportsPackedDS) {
1005 fStencilFormats.push_back() = gDS;
1006 }
1007 } else {
1008 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1009 // for other formats.
1010 // ES doesn't support using the unsized format.
1011
1012 fStencilFormats.push_back() = gS8;
1013 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001014 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1015 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001016 fStencilFormats.push_back() = gD24S8;
1017 }
1018 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1019 fStencilFormats.push_back() = gS4;
1020 }
1021 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001022}
1023
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001024SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001025
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001026 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001027
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001028 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001029 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001030 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001031 i,
1032 fStencilFormats[i].fStencilBits,
1033 fStencilFormats[i].fTotalBits);
1034 }
1035
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001036 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001037 "None",
1038 "ARB",
1039 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001040 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001041 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001042 "IMG MS To Texture",
1043 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001044 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001045 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001046 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1047 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1048 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001049 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1050 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1051 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1052 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001053 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001054 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001055
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001056 static const char* kInvalidateFBTypeStr[] = {
1057 "None",
1058 "Discard",
1059 "Invalidate",
1060 };
1061 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1062 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1063 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1064 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001065
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001066 static const char* kMapBufferTypeStr[] = {
1067 "None",
1068 "MapBuffer",
1069 "MapBufferRange",
1070 "Chromium",
1071 };
1072 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1073 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1074 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1075 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1076 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1077
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001078 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001079 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001080 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001081 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001082 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001083 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1084 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1085 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1086 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001087
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001088 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001089 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1090 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001091 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001092 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1093 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001094 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -08001095 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1096 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1097 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001098 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001099 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001100 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1101 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001102 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001103 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001104 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
halcanary9d524f22016-03-29 09:03:52 -07001105 r.appendf("BGRA to RGBA readback conversions are slow: %s\n",
ericrkb4ecabd2016-03-11 15:18:20 -08001106 (fRGBAToBGRAReadbackConversionsAreSlow ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001107
1108 r.append("Configs\n-------\n");
1109 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1110 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001111 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1112 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001113 i,
1114 fConfigTable[i].fFlags,
1115 fConfigTable[i].fFormats.fBaseInternalFormat,
1116 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001117 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1118 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001119 fConfigTable[i].fFormats.fExternalType,
1120 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001121 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001122 }
1123
jvanverthe9c0fc62015-04-29 11:18:05 -07001124 return r;
1125}
1126
jvanverthe9c0fc62015-04-29 11:18:05 -07001127static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1128 switch (p) {
1129 case kLow_GrSLPrecision:
1130 return GR_GL_LOW_FLOAT;
1131 case kMedium_GrSLPrecision:
1132 return GR_GL_MEDIUM_FLOAT;
1133 case kHigh_GrSLPrecision:
1134 return GR_GL_HIGH_FLOAT;
1135 }
1136 SkFAIL("Unknown precision.");
1137 return -1;
1138}
1139
1140static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1141 switch (type) {
1142 case kVertex_GrShaderType:
1143 return GR_GL_VERTEX_SHADER;
1144 case kGeometry_GrShaderType:
1145 return GR_GL_GEOMETRY_SHADER;
1146 case kFragment_GrShaderType:
1147 return GR_GL_FRAGMENT_SHADER;
1148 }
1149 SkFAIL("Unknown shader type.");
1150 return -1;
1151}
1152
jvanverthcba99b82015-06-24 06:59:57 -07001153void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
halcanary9d524f22016-03-29 09:03:52 -07001154 const GrGLInterface* intf,
jvanverthcba99b82015-06-24 06:59:57 -07001155 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001156 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1157 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1158 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1159 if (kGeometry_GrShaderType != s) {
1160 GrShaderType shaderType = static_cast<GrShaderType>(s);
1161 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001162 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001163 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001164 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1165 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1166 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1167 GrGLint range[2];
1168 GrGLint bits;
1169 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1170 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001171 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1172 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1173 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001174 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001175 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001176 }
jvanverthcba99b82015-06-24 06:59:57 -07001177 else if (!glslCaps->fShaderPrecisionVaries) {
halcanary9d524f22016-03-29 09:03:52 -07001178 glslCaps->fShaderPrecisionVaries =
jvanverthcba99b82015-06-24 06:59:57 -07001179 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001180 }
1181 }
1182 }
1183 }
1184 }
1185 }
1186 else {
1187 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001188 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001189 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1190 if (kGeometry_GrShaderType != s) {
1191 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001192 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1193 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1194 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001195 }
1196 }
1197 }
1198 }
1199 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1200 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1201 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1202 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001203 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001204 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
halcanary9d524f22016-03-29 09:03:52 -07001205 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
jvanverthcba99b82015-06-24 06:59:57 -07001206 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001207 }
1208 }
cdaltona6b92ad2016-04-11 12:03:08 -07001209 glslCaps->initSamplerPrecisionTable();
jvanverthe9c0fc62015-04-29 11:18:05 -07001210}
1211
bsalomon41e4384e2016-01-08 09:12:44 -08001212bool GrGLCaps::bgraIsInternalFormat() const {
1213 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1214}
1215
bsalomon76148af2016-01-12 11:13:47 -08001216bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1217 GrGLenum* internalFormat, GrGLenum* externalFormat,
1218 GrGLenum* externalType) const {
1219 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1220 externalFormat, externalType)) {
1221 return false;
1222 }
1223 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1224 return true;
1225}
1226
1227bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1228 GrGLenum* internalFormat) const {
1229 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1230 return false;
1231 }
1232 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1233 return true;
1234}
1235
1236bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1237 GrGLenum* externalFormat, GrGLenum* externalType) const {
1238 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1239 externalFormat, externalType)) {
1240 return false;
1241 }
1242 return true;
1243}
1244
1245bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1246 if (GrPixelConfigIsCompressed(config)) {
1247 return false;
1248 }
1249 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1250 return true;
1251}
1252
1253bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1254 ExternalFormatUsage usage, GrGLenum* externalFormat,
1255 GrGLenum* externalType) const {
1256 SkASSERT(externalFormat && externalType);
1257 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1258 return false;
1259 }
1260
1261 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1262 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1263
1264 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1265 // made to work in many cases using glPixelStore and what not but is not needed currently.
1266 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1267 return false;
1268 }
1269
1270 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1271 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1272
bsalomone9573312016-01-25 14:33:25 -08001273 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1274 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1275 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1276 // texture, not the red component.
1277 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1278 if (this->textureRedSupport()) {
1279 SkASSERT(GR_GL_RED == *externalFormat);
1280 *externalFormat = GR_GL_ALPHA;
1281 }
1282 }
1283
bsalomon76148af2016-01-12 11:13:47 -08001284 return true;
1285}
1286
bsalomoncdee0092016-01-08 13:20:12 -08001287void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1288 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001289 /*
1290 Comments on renderability of configs on various GL versions.
1291 OpenGL < 3.0:
1292 no built in support for render targets.
1293 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1294 format RGB, RGBA and NV float formats we don't use.
1295 This is the following:
1296 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1297 RGB10_A2, RGBA12,RGBA16
1298 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1299 since they aren't required by later standards and the driver can simply return
1300 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1301 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1302 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1303 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1304 This adds a lot of additional renderable sized formats, including ALPHA8.
1305 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1306 16F, 32I, 32UI, and 32F variants).
1307 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1308
1309 For both the above extensions we limit ourselves to those that are also required by
1310 OpenGL 3.0.
1311
1312 OpenGL 3.0:
1313 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1314 but are not required to be supported as renderable textures/renderbuffer.
1315 Required renderable color formats:
1316 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1317 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1318 RGB10_A2.
1319 - R11F_G11F_B10F.
1320 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1321 and RG8UI.
1322 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1323 - ALPHA8
1324
1325 OpenGL 3.1, 3.2, 3.3
1326 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1327 OpengGL 3.3, 4.0, 4.1
1328 Adds RGB10_A2UI.
1329 OpengGL 4.2
1330 Adds
1331 - RGB5_A1, RGBA4
1332 - RGB565
1333 OpenGL 4.4
1334 Does away with the separate list and adds a column to the sized internal color format
1335 table. However, no new formats become required color renderable.
1336
1337 ES 2.0
1338 color renderable: RGBA4, RGB5_A1, RGB565
1339 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1340 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1341 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1342 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1343 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1344 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1345
1346 ES 3.0
1347 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1348 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1349 RGB5_A1.
1350 - RGB8 and RGB565.
1351 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1352 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1353 ES 3.1
1354 Adds RGB10_A2, RGB10_A2UI,
1355 ES 3.2
1356 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1357 */
1358 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1359 if (kNone_MSFBOType != fMSFBOType) {
1360 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1361 }
1362
1363 GrGLStandard standard = ctxInfo.standard();
1364 GrGLVersion version = ctxInfo.version();
1365
cblume790d5132016-02-29 11:13:29 -08001366 bool texStorageSupported = false;
1367 if (kGL_GrGLStandard == standard) {
1368 // The EXT version can apply to either GL or GLES.
1369 texStorageSupported = version >= GR_GL_VER(4,2) ||
1370 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1371 ctxInfo.hasExtension("GL_EXT_texture_storage");
1372 } else {
1373 // Qualcomm Adreno drivers appear to have issues with texture storage.
1374 texStorageSupported = (version >= GR_GL_VER(3,0) &&
1375 kQualcomm_GrGLVendor != ctxInfo.vendor()) &&
1376 ctxInfo.hasExtension("GL_EXT_texture_storage");
1377 }
1378
1379 // TODO: remove after command buffer supports full ES 3.0
1380 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0) &&
1381 kChromium_GrGLDriver == ctxInfo.driver()) {
1382 texStorageSupported = false;
1383 }
1384
cdalton74b8d322016-04-11 14:47:28 -07001385 bool texelBufferSupport = this->shaderCaps()->texelBufferSupport();
1386
bsalomon30447372015-12-21 09:03:05 -08001387 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1388 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001389 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001390 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001391 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001392 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001393
1394 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1395 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001396 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1397 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001398 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001399 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001400 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1401 if (kGL_GrGLStandard == standard) {
1402 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1403 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001404 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001405 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1406 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1407 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1408 }
egdaniel4999df82016-01-07 17:06:04 -08001409 }
cblume790d5132016-02-29 11:13:29 -08001410 if (texStorageSupported) {
1411 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1412 }
cdalton74b8d322016-04-11 14:47:28 -07001413 if (texelBufferSupport) {
1414 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1415 }
bsalomoncdee0092016-01-08 13:20:12 -08001416 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001417
bsalomon76148af2016-01-12 11:13:47 -08001418 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1419 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001420 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001421 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001422 if (kGL_GrGLStandard == standard) {
1423 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1424 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1425 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1426 // Since the internal format is RGBA8, it is also renderable.
1427 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1428 allRenderFlags;
1429 }
1430 } else {
1431 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1432 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1433 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1434 // The APPLE extension doesn't make this renderable.
1435 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1436 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1437 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1438 // Though, that seems to not be the case if the texture storage extension is
1439 // present. The specs don't exactly make that clear.
1440 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1441 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1442 }
1443 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1444 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1445 ConfigInfo::kRenderable_Flag;
1446 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001447 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001448 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1449 ConfigInfo::kRenderableWithMSAA_Flag;
1450 }
1451 }
1452 }
cblume790d5132016-02-29 11:13:29 -08001453 if (texStorageSupported) {
1454 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1455 }
bsalomoncdee0092016-01-08 13:20:12 -08001456 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001457
brianosmana6359362016-03-21 06:55:37 -07001458 // We only enable srgb support if both textures and FBOs support srgb,
brianosman64d094d2016-03-25 06:01:59 -07001459 // *and* we can disable sRGB decode-on-read, to support "legacy" mode,
1460 // *and* we can disable sRGB encode-on-write.
bsalomon41e4384e2016-01-08 09:12:44 -08001461 if (kGL_GrGLStandard == standard) {
1462 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001463 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001464 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1465 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1466 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001467 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001468 }
1469 }
1470 // All the above srgb extensions support toggling srgb writes
bsalomon41e4384e2016-01-08 09:12:44 -08001471 } else {
1472 // See https://bug.skia.org/4148 for PowerVR issue.
brianosmana6359362016-03-21 06:55:37 -07001473 fSRGBSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
bsalomon41e4384e2016-01-08 09:12:44 -08001474 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1475 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1476 // sRGB writing for destinations.
brianosman64d094d2016-03-25 06:01:59 -07001477 fSRGBSupport = fSRGBSupport && ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001478 }
brianosmana6359362016-03-21 06:55:37 -07001479 if (!ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode")) {
1480 // To support "legacy" L32 mode, we require the ability to turn off sRGB decode:
1481 fSRGBSupport = false;
1482 }
bsalomon30447372015-12-21 09:03:05 -08001483 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1484 fConfigTable[kSRGBA_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_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001487 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1488 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001489 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001490 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001491 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001492 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1493 allRenderFlags;
1494 }
cblume790d5132016-02-29 11:13:29 -08001495 if (texStorageSupported) {
1496 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1497 }
bsalomoncdee0092016-01-08 13:20:12 -08001498 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001499
brianosmana6359362016-03-21 06:55:37 -07001500 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1501 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1502 // is in this format, for example).
1503 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1504 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1505 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1506 // external format is GL_BGRA.
1507 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1508 GR_GL_BGRA;
1509 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1510 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1511 if (fSRGBSupport) {
1512 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1513 allRenderFlags;
1514 }
1515 if (texStorageSupported) {
1516 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1517 }
1518 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1519
bsalomon30447372015-12-21 09:03:05 -08001520 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1521 if (this->ES2CompatibilitySupport()) {
1522 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1523 } else {
1524 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1525 }
bsalomon76148af2016-01-12 11:13:47 -08001526 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1527 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001528 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001529 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001530 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1531 if (kGL_GrGLStandard == standard) {
1532 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1533 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1534 }
1535 } else {
1536 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1537 }
cblume790d5132016-02-29 11:13:29 -08001538 // 565 is not a sized internal format on desktop GL. So on desktop with
1539 // 565 we always use an unsized internal format to let the system pick
1540 // the best sized format to convert the 565 data to. Since TexStorage
1541 // only allows sized internal formats we disallow it.
1542 //
1543 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1544 // update.
1545 if (texStorageSupported && kGL_GrGLStandard != standard) {
1546 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1547 }
bsalomoncdee0092016-01-08 13:20:12 -08001548 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001549
1550 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1551 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001552 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1553 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001554 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001555 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001556 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1557 if (kGL_GrGLStandard == standard) {
1558 if (version >= GR_GL_VER(4, 2)) {
1559 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1560 }
1561 } else {
1562 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1563 }
cblume790d5132016-02-29 11:13:29 -08001564 if (texStorageSupported) {
1565 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1566 }
bsalomoncdee0092016-01-08 13:20:12 -08001567 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001568
1569 if (this->textureRedSupport()) {
1570 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1571 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001572 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1573 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001574 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07001575 if (texelBufferSupport) {
1576 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1577 }
bsalomon30447372015-12-21 09:03:05 -08001578 } else {
1579 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1580 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001581 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1582 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001583 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001584 }
1585 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001586 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001587 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1588 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1589 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1590 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1591 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1592 }
cblume790d5132016-02-29 11:13:29 -08001593 if (texStorageSupported) {
1594 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1595 }
bsalomon41e4384e2016-01-08 09:12:44 -08001596
1597 // Check for [half] floating point texture support
1598 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1599 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1600 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1601 bool hasFPTextures = false;
1602 bool hasHalfFPTextures = false;
1603 // for now we don't support floating point MSAA on ES
1604 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1605 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1606
1607 if (kGL_GrGLStandard == standard) {
1608 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1609 hasFPTextures = true;
1610 hasHalfFPTextures = true;
1611 }
1612 } else {
1613 if (version >= GR_GL_VER(3, 1)) {
1614 hasFPTextures = true;
1615 hasHalfFPTextures = true;
1616 } else {
1617 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1618 ctxInfo.hasExtension("GL_OES_texture_float")) {
1619 hasFPTextures = true;
1620 }
1621 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1622 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1623 hasHalfFPTextures = true;
1624 }
1625 }
1626 }
bsalomon30447372015-12-21 09:03:05 -08001627
1628 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1629 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001630 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1631 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001632 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001633 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001634 if (hasFPTextures) {
1635 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1636 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1637 // many precision issues and no clients actually want this yet.
1638 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1639 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1640 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1641 }
1642 }
cblume790d5132016-02-29 11:13:29 -08001643 if (texStorageSupported) {
1644 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1645 }
cdalton74b8d322016-04-11 14:47:28 -07001646 if (texelBufferSupport) {
1647 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1648 }
bsalomoncdee0092016-01-08 13:20:12 -08001649 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001650
1651 if (this->textureRedSupport()) {
1652 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1653 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001654 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1655 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001656 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07001657 if (texelBufferSupport) {
1658 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |=
1659 ConfigInfo::kCanUseWithTexelBuffer_Flag;
1660 }
bsalomon30447372015-12-21 09:03:05 -08001661 } else {
1662 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1663 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001664 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1665 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001666 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001667 }
1668 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1669 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1670 } else {
1671 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1672 }
bsalomon7928ef62016-01-05 10:26:39 -08001673 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001674 if (hasHalfFPTextures) {
1675 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1676 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1677 // GL_RED internal format.
1678 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1679 (this->textureRedSupport() &&
1680 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1681 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1682 }
1683 }
cblume790d5132016-02-29 11:13:29 -08001684 if (texStorageSupported) {
1685 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1686 }
bsalomon30447372015-12-21 09:03:05 -08001687
1688 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1689 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001690 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1691 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001692 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1693 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1694 } else {
1695 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1696 }
bsalomon7928ef62016-01-05 10:26:39 -08001697 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001698 if (hasHalfFPTextures) {
1699 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1700 // ES requires 3.2 or EXT_color_buffer_half_float.
1701 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1702 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1703 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1704 }
1705 }
cblume790d5132016-02-29 11:13:29 -08001706 if (texStorageSupported) {
1707 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1708 }
cdalton74b8d322016-04-11 14:47:28 -07001709 if (texelBufferSupport) {
1710 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1711 }
bsalomoncdee0092016-01-08 13:20:12 -08001712 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001713
1714 // Compressed texture support
1715
1716 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1717 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1718
1719 // TODO: Fix command buffer bindings and remove this.
1720 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001721
1722 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001723 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001724
1725 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1726 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001727 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001728 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001729 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001730 // Disable this for now, while we investigate https://bug.skia.org/4333
1731 if (false) {
1732 // Check for 8-bit palette..
1733 GrGLint numFormats;
1734 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1735 if (numFormats) {
1736 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1737 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1738 for (int i = 0; i < numFormats; ++i) {
1739 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1740 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1741 break;
1742 }
1743 }
1744 }
1745 }
bsalomoncdee0092016-01-08 13:20:12 -08001746 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001747
bsalomon41e4384e2016-01-08 09:12:44 -08001748 // May change the internal format based on extensions.
1749 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1750 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1751 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1752 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1753 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1754 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1755 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1756 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1757 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1758 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1759 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1760 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1761 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1762 GR_GL_COMPRESSED_RED_RGTC1;
1763 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1764 GR_GL_COMPRESSED_RED_RGTC1;
1765 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1766 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1767 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1768 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1769 GR_GL_COMPRESSED_3DC_X;
1770
bsalomon30447372015-12-21 09:03:05 -08001771 }
bsalomon76148af2016-01-12 11:13:47 -08001772 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001773 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001774 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001775 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001776
1777 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1778 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001779 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001780 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001781 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001782 if (kGL_GrGLStandard == standard) {
1783 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1784 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1785 }
1786 } else {
1787 if (version >= GR_GL_VER(3, 0) ||
1788 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1789 // ETC2 is a superset of ETC1, so we can just check for that, too.
1790 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1791 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1792 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1793 }
1794 }
bsalomoncdee0092016-01-08 13:20:12 -08001795 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001796
1797 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1798 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001799 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001800 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001801 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001802 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1803 // decompressing the textures in the driver, and is generally slower.
1804 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1805 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1806 }
bsalomoncdee0092016-01-08 13:20:12 -08001807 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001808
1809 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1810 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1811 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1812 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001813 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1814 0;
bsalomon30447372015-12-21 09:03:05 -08001815 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001816 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001817 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1818 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1819 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1820 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1821 }
bsalomoncdee0092016-01-08 13:20:12 -08001822 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001823
1824 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1825
1826 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001827 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1828 ctxInfo.version() >= GR_GL_VER(3,0));
1829 // All ES versions (thus far) require sized internal formats for render buffers.
1830 // TODO: Always use sized internal format?
1831 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1832
bsalomon30447372015-12-21 09:03:05 -08001833 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001834 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1835 // param to glTex[Sub]Image.
1836 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1837 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1838 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1839 fConfigTable[i].fFormats.fSizedInternalFormat :
1840 fConfigTable[i].fFormats.fBaseInternalFormat;
1841 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001842 fConfigTable[i].fFormats.fSizedInternalFormat :
1843 fConfigTable[i].fFormats.fBaseInternalFormat;
1844 }
1845 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1846 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1847 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1848 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1849 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001850 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001851 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001852
1853 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1854 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1855 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1856 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001857 }
1858
1859 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1860 // as a base format.
1861 // GL_EXT_texture_format_BGRA8888:
1862 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1863 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1864 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001865 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001866 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1867 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1868 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001869 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001870 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1871 }
1872
bsalomoncdee0092016-01-08 13:20:12 -08001873 // If we don't have texture swizzle support then the shader generator must insert the
1874 // swizzle into shader code.
1875 if (!this->textureSwizzleSupport()) {
1876 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1877 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1878 }
1879 }
1880
bsalomon7f9b2e42016-01-12 13:29:26 -08001881 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1882 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1883 // gets written to the single component.
1884 if (this->textureRedSupport()) {
1885 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1886 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1887 if (GrPixelConfigIsAlphaOnly(config) &&
1888 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1889 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1890 }
1891 }
1892 }
1893
bsalomon30447372015-12-21 09:03:05 -08001894#ifdef SK_DEBUG
1895 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001896 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001897 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001898 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1899 fConfigTable[i].fFormats.fBaseInternalFormat);
1900 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001901 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001902 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1903 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1904 fConfigTable[i].fFormats.fExternalFormat[j]);
1905 }
1906 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001907 }
1908#endif
1909}
1910
egdanielb7e7d572015-11-04 04:23:53 -08001911void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}