blob: dfcde60d45fbf9039ba84d02c0cbe4b749ca3a4a [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9#include "GrGLCaps.h"
joshualittb4384b92014-10-21 12:53:15 -070010
egdanielb7e7d572015-11-04 04:23:53 -080011#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000012#include "GrGLContext.h"
bsalomon1aa20292016-01-22 08:16:09 -080013#include "GrGLRenderTarget.h"
jvanverthcba99b82015-06-24 06:59:57 -070014#include "glsl/GrGLSLCaps.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000015#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000016#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000017
bsalomon682c2692015-05-22 14:01:46 -070018GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
19 const GrGLContextInfo& ctxInfo,
20 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080021 fStandard = ctxInfo.standard();
22
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000023 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000024 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000025 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000026 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080027 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000029 fMaxVertexAttributes = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030 fUnpackRowLengthSupport = false;
31 fUnpackFlipYSupport = false;
32 fPackRowLengthSupport = false;
33 fPackFlipYSupport = false;
34 fTextureUsageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000035 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000036 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000037 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070038 fDirectStateAccessSupport = false;
39 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080040 fES2CompatibilitySupport = false;
cdaltond4727922015-11-10 12:49:06 -080041 fMultisampleDisableSupport = false;
cdalton06604b92016-02-05 10:09:51 -080042 fDrawIndirectSupport = false;
43 fMultiDrawIndirectSupport = false;
44 fBaseInstanceSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000045 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000046 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070047 fBindFragDataLocationSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080048 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080049 fTextureSwizzleSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070050 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070051 fRGBA8888PixelsOpsAreSlow = false;
52 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080053 fMipMapLevelAndLodControlSupport = false;
piotaixre4b23142014-10-02 10:57:53 -070054
bsalomon083617b2016-02-12 12:10:14 -080055 fBlitFramebufferSupport = kNone_BlitFramebufferSupport;
56
halcanary385fe4d2015-08-26 13:07:48 -070057 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070058
cdalton4cd67132015-06-10 19:23:46 -070059 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060}
61
cdalton4cd67132015-06-10 19:23:46 -070062void GrGLCaps::init(const GrContextOptions& contextOptions,
63 const GrGLContextInfo& ctxInfo,
64 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000065 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000066 GrGLVersion version = ctxInfo.version();
67
bsalomon@google.combcce8922013-03-25 15:38:39 +000068 /**************************************************************************
69 * Caps specific to GrGLCaps
70 **************************************************************************/
71
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000072 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000073 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
74 &fMaxFragmentUniformVectors);
75 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000076 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000077 GrGLint max;
78 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
79 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000080 if (version >= GR_GL_VER(3, 2)) {
81 GrGLint profileMask;
82 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
83 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
84 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000085 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000086 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000087
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000088 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089 fUnpackRowLengthSupport = true;
90 fUnpackFlipYSupport = false;
91 fPackRowLengthSupport = true;
92 fPackFlipYSupport = false;
93 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000094 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
95 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000096 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000097 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
98 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000099 fPackFlipYSupport =
100 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
101 }
102
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000103 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000104 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
105
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000106 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700107 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
108 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
109 ctxInfo.hasExtension("GL_NV_texture_barrier");
110 } else {
111 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
112 }
113
cdaltoneb79eea2016-02-26 10:39:34 -0800114 if (kGL_GrGLStandard == standard) {
115 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
116 ctxInfo.hasExtension("GL_ARB_texture_multisample");
117 } else {
118 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
119 }
120
hendrikwa0d5ad72014-12-02 07:30:30 -0800121 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
122 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700123 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800124 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000125 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
126 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800127 } else {
128 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
129 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000130 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000131 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000132 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000133 ctxInfo.hasExtension("GL_ARB_imaging");
134
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000135 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
136 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
137 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
138 // limit this decision to specific GPU families rather than basing it on the vendor alone.
139 if (!GR_GL_MUST_USE_VBO &&
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();
249 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
250 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
cdalton4cd67132015-06-10 19:23:46 -0700256 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700257 * GrShaderCaps fields
258 **************************************************************************/
259
egdaniel0a482332015-10-26 08:59:10 -0700260 // This must be called after fCoreProfile is set on the GrGLCaps
261 this->initGLSL(ctxInfo);
262 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
263
egdaniel05ded892015-10-26 07:38:05 -0700264 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
265
266 // For now these two are equivalent but we could have dst read in shader via some other method.
267 // Before setting this, initGLSL() must have been called.
268 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
269
270 // Enable supported shader-related caps
271 if (kGL_GrGLStandard == standard) {
272 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
273 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
274 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
275 glslCaps->fShaderDerivativeSupport = true;
276 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
277 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
278 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
cdalton793dc262016-02-08 10:11:47 -0800279 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
280 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700281 }
282 else {
283 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
284
285 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
286 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800287
288 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
289 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700290 }
291
ethannicholas22793252016-01-30 09:59:10 -0800292 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
293 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
294 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
295 &glslCaps->fPixelLocalStorageSize);
296 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
297 }
298 else {
299 glslCaps->fPixelLocalStorageSize = 0;
300 glslCaps->fPLSPathRenderingSupport = false;
301 }
302
cdalton9c3f1432016-03-11 10:07:37 -0800303 // Protect ourselves against tracking huge amounts of texture state.
304 static const uint8_t kMaxSaneSamplers = 32;
305 GrGLint maxSamplers;
306 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
307 glslCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
308 if (glslCaps->fGeometryShaderSupport) {
309 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
310 glslCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
311 }
312 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
313 glslCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
314 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
315 glslCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
316
egdaniel05ded892015-10-26 07:38:05 -0700317 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700318 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000319 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700320
cdalton63f6c1f2015-11-06 07:09:43 -0800321 // We need dual source blending and the ability to disable multisample in order to support mixed
322 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800323 if (fMultisampleDisableSupport &&
324 glslCaps->dualSourceBlendingSupport() &&
325 fShaderCaps->pathRenderingSupport()) {
326 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800327 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800328 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800329 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
330 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800331 fDiscardRenderTargetSupport = false;
332 fInvalidateFBType = kNone_InvalidateFBType;
333 }
334 }
335
egdanieleed519e2016-01-15 11:36:18 -0800336 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700337 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700338 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700339 this->initStencilFormats(ctxInfo);
340
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000341 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000342 // we could also look for GL_ATI_separate_stencil extension or
343 // GL_EXT_stencil_two_side but they use different function signatures
344 // than GL2.0+ (and than each other).
345 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
346 // supported on GL 1.4 and higher or by extension
347 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
348 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
349 } else {
350 // ES 2 has two sided stencil and stencil wrap
351 fTwoSidedStencilSupport = true;
352 fStencilWrapOpsSupport = true;
353 }
354
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000355 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000356 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
357 // extension includes glMapBuffer.
358 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
359 fMapBufferFlags |= kSubset_MapFlag;
360 fMapBufferType = kMapBufferRange_MapBufferType;
361 } else {
362 fMapBufferType = kMapBuffer_MapBufferType;
363 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000364 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000365 // Unextended GLES2 doesn't have any buffer mapping.
366 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800367 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800368 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
369 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800370 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
371 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
372 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000373 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
374 fMapBufferFlags = kCanMap_MapFlag;
375 fMapBufferType = kMapBuffer_MapBufferType;
376 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000377 }
378
jvanverthd7a2c1f2015-12-07 07:36:44 -0800379 if (kGL_GrGLStandard == standard) {
380 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
381 fTransferBufferType = kPBO_TransferBufferType;
382 }
383 } else {
384 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
385 fTransferBufferType = kPBO_TransferBufferType;
386 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
387 fTransferBufferType = kChromium_TransferBufferType;
388 }
389 }
390
joshualitte5b74c62015-06-01 14:17:47 -0700391 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
392 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
393 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700394 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
395 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
396 // a small subset.
397#if 0
cdalton1acea862015-06-02 13:05:52 -0700398 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700399#else
400 fGeometryBufferMapThreshold = SK_MaxS32;
401#endif
joshualitte5b74c62015-06-01 14:17:47 -0700402 }
403
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000404 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000405 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
406 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
407 fNPOTTextureTileSupport = true;
408 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000409 } else {
410 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000411 // ES3 has no limitations.
412 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
413 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000414 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
415 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
416 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
417 // to alllow arbitrary wrap modes, however.
418 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000419 }
420
bsalomone72bd022015-10-26 07:33:03 -0700421 // Using MIPs on this GPU seems to be a source of trouble.
422 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
423 fMipMapSupport = false;
424 }
425
bsalomon@google.combcce8922013-03-25 15:38:39 +0000426 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
427 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
428 // Our render targets are always created with textures as the color
429 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000430 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000431
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000432 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
433
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000434 // Disable scratch texture reuse on Mali and Adreno devices
435 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
436 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000437
robertphillips1b8e1b52015-06-24 06:54:10 -0700438#if 0
439 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
440 kQualcomm_GrGLVendor != ctxInfo.vendor();
441#endif
442
egdaniel05ded892015-10-26 07:38:05 -0700443 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000444 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800445 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000446 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800447 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000448 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800449 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
450 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
451 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
452 // This is to guard against platforms that may not support as many samples for
453 // glRasterSamples as they do for framebuffers.
454 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
455 }
456 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000457
bsalomon63b21962014-11-05 07:05:34 -0800458 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800459 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800460 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800461 fUseDrawInsteadOfClear = true;
462 }
463
joshualitt83bc2292015-06-18 14:18:02 -0700464 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
465 fUseDrawInsteadOfPartialRenderTargetWrite = true;
466 }
467
bsalomonbabafcc2016-02-16 11:36:47 -0800468 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
469 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
470 fUseDrawInsteadOfPartialRenderTargetWrite = true;
471 fUseDrawInsteadOfAllRenderTargetWrites = true;
472 }
473
robertphillips63926682015-08-20 09:39:02 -0700474#ifdef SK_BUILD_FOR_WIN
475 // On ANGLE deferring flushes can lead to GPU starvation
476 fPreferVRAMUseOverFlushes = !isANGLE;
477#endif
478
bsalomon7dea7b72015-08-19 08:26:51 -0700479 if (kChromium_GrGLDriver == ctxInfo.driver()) {
480 fMustClearUploadedBufferData = true;
481 }
482
bsalomond08ea5f2015-02-20 06:58:13 -0800483 if (kGL_GrGLStandard == standard) {
484 // ARB allows mixed size FBO attachments, EXT does not.
485 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
486 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
487 fOversizedStencilSupport = true;
488 } else {
489 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
490 }
491 } else {
492 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
493 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
494 }
495
joshualitt58001552015-06-26 12:46:36 -0700496 if (kGL_GrGLStandard == standard) {
497 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
498 // instanced arrays, but we could make this more granular if we wanted
499 fSupportsInstancedDraws =
500 version >= GR_GL_VER(3, 2) ||
501 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
502 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
503 } else {
504 fSupportsInstancedDraws =
505 version >= GR_GL_VER(3, 0) ||
506 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
507 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
508 }
509
cdalton06604b92016-02-05 10:09:51 -0800510 if (kGL_GrGLStandard == standard) {
511 // We don't use ARB_draw_indirect because it does not support a base instance.
512 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER.
513 fDrawIndirectSupport =
514 fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3);
515 } else {
516 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
517 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
518 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
519 }
520
jvanverthcba99b82015-06-24 06:59:57 -0700521 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800522
523 if (contextOptions.fUseShaderSwizzling) {
524 fTextureSwizzleSupport = false;
525 }
526
527 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
528 // already been detected.
529 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700530
531 this->applyOptionsOverrides(contextOptions);
532 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000533}
534
egdaniel472d44e2015-10-22 08:20:00 -0700535const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
536 bool isCoreProfile) {
537 switch (generation) {
538 case k110_GrGLSLGeneration:
539 if (kGLES_GrGLStandard == standard) {
540 // ES2s shader language is based on version 1.20 but is version
541 // 1.00 of the ES language.
542 return "#version 100\n";
543 } else {
544 SkASSERT(kGL_GrGLStandard == standard);
545 return "#version 110\n";
546 }
547 case k130_GrGLSLGeneration:
548 SkASSERT(kGL_GrGLStandard == standard);
549 return "#version 130\n";
550 case k140_GrGLSLGeneration:
551 SkASSERT(kGL_GrGLStandard == standard);
552 return "#version 140\n";
553 case k150_GrGLSLGeneration:
554 SkASSERT(kGL_GrGLStandard == standard);
555 if (isCoreProfile) {
556 return "#version 150\n";
557 } else {
558 return "#version 150 compatibility\n";
559 }
560 case k330_GrGLSLGeneration:
561 if (kGLES_GrGLStandard == standard) {
562 return "#version 300 es\n";
563 } else {
564 SkASSERT(kGL_GrGLStandard == standard);
565 if (isCoreProfile) {
566 return "#version 330\n";
567 } else {
568 return "#version 330 compatibility\n";
569 }
570 }
cdalton33ad7012016-02-22 07:55:44 -0800571 case k400_GrGLSLGeneration:
572 SkASSERT(kGL_GrGLStandard == standard);
573 if (isCoreProfile) {
574 return "#version 400\n";
575 } else {
576 return "#version 400 compatibility\n";
577 }
egdaniel472d44e2015-10-22 08:20:00 -0700578 case k310es_GrGLSLGeneration:
579 SkASSERT(kGLES_GrGLStandard == standard);
580 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800581 case k320es_GrGLSLGeneration:
582 SkASSERT(kGLES_GrGLStandard == standard);
583 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700584 }
585 return "<no version>";
586}
587
egdaniel05ded892015-10-26 07:38:05 -0700588void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700589 GrGLStandard standard = ctxInfo.standard();
590 GrGLVersion version = ctxInfo.version();
591
592 /**************************************************************************
593 * Caps specific to GrGLSLCaps
594 **************************************************************************/
595
596 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
597 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700598 if (kGLES_GrGLStandard == standard) {
599 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
600 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
601 glslCaps->fFBFetchSupport = true;
602 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
603 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
604 }
605 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
606 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
607 glslCaps->fFBFetchNeedsCustomOutput = false;
608 glslCaps->fFBFetchSupport = true;
609 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
610 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
611 }
612 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
613 // The arm extension also requires an additional flag which we will set onResetContext
614 glslCaps->fFBFetchNeedsCustomOutput = false;
615 glslCaps->fFBFetchSupport = true;
616 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
617 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
618 }
619 glslCaps->fUsesPrecisionModifiers = true;
620 }
621
622 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
623
cdaltonc08f1962016-02-12 12:14:06 -0800624 if (kGL_GrGLStandard == standard) {
625 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
626 } else {
627 glslCaps->fFlatInterpolationSupport =
628 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
629 }
630
631 if (kGL_GrGLStandard == standard) {
632 glslCaps->fNoPerspectiveInterpolationSupport =
633 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
634 } else {
635 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
636 glslCaps->fNoPerspectiveInterpolationSupport = true;
637 glslCaps->fNoPerspectiveInterpolationExtensionString =
638 "GL_NV_shader_noperspective_interpolation";
639 }
640 }
641
cdalton33ad7012016-02-22 07:55:44 -0800642 if (kGL_GrGLStandard == standard) {
cdalton4a98cdb2016-03-01 12:12:20 -0800643 glslCaps->fMultisampleInterpolationSupport =
644 ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
645 } else {
646 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
647 glslCaps->fMultisampleInterpolationSupport = true;
648 } else if (ctxInfo.hasExtension("GL_OES_shader_multisample_interpolation")) {
649 glslCaps->fMultisampleInterpolationSupport = true;
650 glslCaps->fMultisampleInterpolationExtensionString =
651 "GL_OES_shader_multisample_interpolation";
652 }
653 }
654
655 if (kGL_GrGLStandard == standard) {
cdalton33ad7012016-02-22 07:55:44 -0800656 glslCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
657 } else {
658 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
659 glslCaps->fSampleVariablesSupport = true;
660 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
661 glslCaps->fSampleVariablesSupport = true;
662 glslCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
663 }
664 }
665
666 if (glslCaps->fSampleVariablesSupport) {
667 glslCaps->fSampleMaskOverrideCoverageSupport =
668 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage");
669 }
670
egdaniel472d44e2015-10-22 08:20:00 -0700671 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
672 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
673
674 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
675 // function that may require a gradient calculation inside a conditional block may return
676 // undefined results". This appears to be an issue with the 'any' call since even the simple
677 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
678 // from our GrTextureDomain processor.
679 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
680
egdaniel472d44e2015-10-22 08:20:00 -0700681 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
682 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800683
684 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
685 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
686 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800687
688 // Frag Coords Convention support is not part of ES
689 // Known issue on at least some Intel platforms:
690 // http://code.google.com/p/skia/issues/detail?id=946
691 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
692 kGLES_GrGLStandard != standard &&
693 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
694 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
695 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
696 }
697
698 if (kGLES_GrGLStandard == standard) {
699 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
700 }
701
cdalton9c3f1432016-03-11 10:07:37 -0800702 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
703 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
704 glslCaps->fExternalTextureSupport = true;
705 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
706 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
707 // At least one driver has been found that has this extension without the "GL_" prefix.
708 glslCaps->fExternalTextureSupport = true;
709 }
710 }
711
712 if (glslCaps->fExternalTextureSupport) {
bsalomon7ea33f52015-11-22 14:51:00 -0800713 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
714 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
715 } else {
716 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
717 }
718 }
719
cdaltonc04ce672016-03-11 14:07:38 -0800720 if (kGL_GrGLStandard == standard) {
721 glslCaps->fBufferTextureSupport = ctxInfo.version() > GR_GL_VER(3, 1) &&
722 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
723 } else {
724 if (ctxInfo.version() > GR_GL_VER(3, 2) &&
725 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
726 glslCaps->fBufferTextureSupport = true;
727 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
728 glslCaps->fBufferTextureSupport = true;
729 glslCaps->fBufferTextureExtensionString = "GL_OES_texture_buffer";
730 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
731 glslCaps->fBufferTextureSupport = true;
732 glslCaps->fBufferTextureExtensionString = "GL_EXT_texture_buffer";
733 }
734 }
735
egdaniel8dcdedc2015-11-11 06:27:20 -0800736 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
737 // the abs first in a separate expression.
738 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
739 glslCaps->fCanUseMinAndAbsTogether = false;
740 }
741
bsalomon7ea33f52015-11-22 14:51:00 -0800742 // 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 -0800743 // thus must us -1.0 * %s.x to work correctly
744 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
745 glslCaps->fMustForceNegatedAtanParamToFloat = true;
746 }
egdaniel472d44e2015-10-22 08:20:00 -0700747}
748
kkinnunencfe62e32015-07-01 02:58:50 -0700749bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700750 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
751
752 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700753 return false;
754 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700755
kkinnunencfe62e32015-07-01 02:58:50 -0700756 if (kGL_GrGLStandard == ctxInfo.standard()) {
757 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
758 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
759 return false;
760 }
761 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700762 if (!hasChromiumPathRendering &&
763 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700764 return false;
765 }
766 }
767 // We only support v1.3+ of GL_NV_path_rendering which allows us to
768 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
769 // additions are detected by checking the existence of the function.
770 // We also use *Then* functions that not all drivers might have. Check
771 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800772 if (!gli->fFunctions.fStencilThenCoverFillPath ||
773 !gli->fFunctions.fStencilThenCoverStrokePath ||
774 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
775 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
776 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700777 return false;
778 }
779 return true;
780}
bsalomon1aa20292016-01-22 08:16:09 -0800781
782bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800783 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800784 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
785 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800786 // If it's not possible to even have a render target of rtConfig then read pixels is
787 // not supported regardless of readConfig.
788 if (!this->isConfigRenderable(rtConfig, false)) {
789 return false;
790 }
bsalomon7928ef62016-01-05 10:26:39 -0800791
bsalomon76148af2016-01-12 11:13:47 -0800792 GrGLenum readFormat;
793 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800794 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800795 return false;
796 }
797
bsalomon1aa20292016-01-22 08:16:09 -0800798 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800799 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
800 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
801 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
802 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
803 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
804 readFormat != GR_GL_BGRA) {
805 return false;
806 }
807 // There is also a set of allowed types, but all the types we use are in the set:
808 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
809 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
810 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
811 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
812 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
813 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
814 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800815 return true;
piotaixre4b23142014-10-02 10:57:53 -0700816 }
bsalomon7928ef62016-01-05 10:26:39 -0800817
bsalomon76148af2016-01-12 11:13:47 -0800818 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800819
bsalomon1aa20292016-01-22 08:16:09 -0800820 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800821 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
822 return true;
823 }
824 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800825 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800826 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
827 return true;
828 }
829 }
830
bsalomon1aa20292016-01-22 08:16:09 -0800831 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800832 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800833 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800834 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800835 if (!bindRenderTarget()) {
836 return false;
837 }
838 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
839 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800840 rpFormat->fFormat = format;
841 rpFormat->fType = type;
842 }
843
bsalomon1aa20292016-01-22 08:16:09 -0800844 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
845 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700846}
847
robertphillips@google.com6177e692013-02-28 20:16:25 +0000848void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000849
850 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000851 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000852 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
853 // ES3 driver bugs on at least one device with a tiled GPU (N10).
854 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
855 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
856 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
857 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800858 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700859 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000860 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000861 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
862 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
863 // chrome's extension is equivalent to the EXT msaa
864 // and fbo_blit extensions.
865 fMSFBOType = kDesktop_EXT_MSFBOType;
866 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
867 fMSFBOType = kES_Apple_MSFBOType;
868 }
bsalomon083617b2016-02-12 12:10:14 -0800869
870 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
871 // is available.
872 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
873 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
874 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
875 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
876 // limitations.
877 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
878 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000879 } else {
egdanieleed519e2016-01-15 11:36:18 -0800880 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700881 fMSFBOType = kMixedSamples_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800882 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
vbuzinovdded6962015-06-12 08:59:45 -0700883 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000884 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000885 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800886 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000887 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
888 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000889 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800890 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000891 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000892 }
893}
894
cdalton1dd05422015-06-12 09:01:18 -0700895void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
896 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
897
898 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
899 // for now until its own blacklists can be updated.
900 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
901 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700902 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700903 return;
904 }
905
906 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
907 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
908 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
909 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
910 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
911 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
912 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
913 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
914 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
915 return;
916 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
917 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
918 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
919 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
920 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
921 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
922 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
923 // slow on a particular platform.
924 } else {
925 return; // No advanced blend support.
926 }
927
928 SkASSERT(this->advancedBlendEquationSupport());
929
930 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
931 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
932 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
933 (1 << kColorBurn_GrBlendEquation);
934 }
joel.liang9764c402015-07-09 19:46:18 -0700935 if (kARM_GrGLVendor == ctxInfo.vendor()) {
936 // Blacklist color-burn on ARM until the fix is released.
937 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
938 }
cdalton1dd05422015-06-12 09:01:18 -0700939}
940
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000941namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700942const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000943}
944
945void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
946
947 // Build up list of legal stencil formats (though perhaps not supported on
948 // the particular gpu/driver) from most preferred to least.
949
950 // these consts are in order of most preferred to least preferred
951 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
952
953 static const StencilFormat
954 // internal Format stencil bits total bits packed?
955 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
956 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
957 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
958 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000959 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000960 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
961
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000962 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000963 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000964 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000965 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
966 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
967
968 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
969 // require FBO support we can expect these are legal formats and don't
970 // check. These also all support the unsized GL_STENCIL_INDEX.
971 fStencilFormats.push_back() = gS8;
972 fStencilFormats.push_back() = gS16;
973 if (supportsPackedDS) {
974 fStencilFormats.push_back() = gD24S8;
975 }
976 fStencilFormats.push_back() = gS4;
977 if (supportsPackedDS) {
978 fStencilFormats.push_back() = gDS;
979 }
980 } else {
981 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
982 // for other formats.
983 // ES doesn't support using the unsized format.
984
985 fStencilFormats.push_back() = gS8;
986 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000987 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
988 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000989 fStencilFormats.push_back() = gD24S8;
990 }
991 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
992 fStencilFormats.push_back() = gS4;
993 }
994 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000995}
996
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000997SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000998
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000999 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001000
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001001 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001002 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001003 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001004 i,
1005 fStencilFormats[i].fStencilBits,
1006 fStencilFormats[i].fTotalBits);
1007 }
1008
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001009 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001010 "None",
1011 "ARB",
1012 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001013 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001014 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001015 "IMG MS To Texture",
1016 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001017 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001018 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001019 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1020 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1021 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001022 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1023 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1024 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1025 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001026 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001027 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001028
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001029 static const char* kInvalidateFBTypeStr[] = {
1030 "None",
1031 "Discard",
1032 "Invalidate",
1033 };
1034 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1035 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1036 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1037 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001038
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001039 static const char* kMapBufferTypeStr[] = {
1040 "None",
1041 "MapBuffer",
1042 "MapBufferRange",
1043 "Chromium",
1044 };
1045 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1046 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1047 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1048 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1049 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1050
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001051 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001052 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001053 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001054 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001055 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001056 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001057 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1058 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1059 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1060 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001061
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001062 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001063 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1064 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001065 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001066 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1067 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001068 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -08001069 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1070 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1071 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001072 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001073 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001074 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001075 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1076 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001077 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001078 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001079 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001080
1081 r.append("Configs\n-------\n");
1082 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1083 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001084 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1085 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001086 i,
1087 fConfigTable[i].fFlags,
1088 fConfigTable[i].fFormats.fBaseInternalFormat,
1089 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001090 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1091 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001092 fConfigTable[i].fFormats.fExternalType,
1093 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001094 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001095 }
1096
jvanverthe9c0fc62015-04-29 11:18:05 -07001097 return r;
1098}
1099
jvanverthe9c0fc62015-04-29 11:18:05 -07001100static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1101 switch (p) {
1102 case kLow_GrSLPrecision:
1103 return GR_GL_LOW_FLOAT;
1104 case kMedium_GrSLPrecision:
1105 return GR_GL_MEDIUM_FLOAT;
1106 case kHigh_GrSLPrecision:
1107 return GR_GL_HIGH_FLOAT;
1108 }
1109 SkFAIL("Unknown precision.");
1110 return -1;
1111}
1112
1113static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1114 switch (type) {
1115 case kVertex_GrShaderType:
1116 return GR_GL_VERTEX_SHADER;
1117 case kGeometry_GrShaderType:
1118 return GR_GL_GEOMETRY_SHADER;
1119 case kFragment_GrShaderType:
1120 return GR_GL_FRAGMENT_SHADER;
1121 }
1122 SkFAIL("Unknown shader type.");
1123 return -1;
1124}
1125
jvanverthcba99b82015-06-24 06:59:57 -07001126void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1127 const GrGLInterface* intf,
1128 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001129 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1130 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1131 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1132 if (kGeometry_GrShaderType != s) {
1133 GrShaderType shaderType = static_cast<GrShaderType>(s);
1134 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001135 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001136 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001137 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1138 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1139 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1140 GrGLint range[2];
1141 GrGLint bits;
1142 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1143 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001144 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1145 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1146 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001147 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001148 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001149 }
jvanverthcba99b82015-06-24 06:59:57 -07001150 else if (!glslCaps->fShaderPrecisionVaries) {
1151 glslCaps->fShaderPrecisionVaries =
1152 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001153 }
1154 }
1155 }
1156 }
1157 }
1158 }
1159 else {
1160 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001161 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001162 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1163 if (kGeometry_GrShaderType != s) {
1164 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001165 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1166 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1167 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001168 }
1169 }
1170 }
1171 }
1172 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1173 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1174 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1175 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001176 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001177 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001178 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1179 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001180 }
1181 }
1182}
1183
bsalomon41e4384e2016-01-08 09:12:44 -08001184bool GrGLCaps::bgraIsInternalFormat() const {
1185 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1186}
1187
bsalomon76148af2016-01-12 11:13:47 -08001188bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1189 GrGLenum* internalFormat, GrGLenum* externalFormat,
1190 GrGLenum* externalType) const {
1191 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1192 externalFormat, externalType)) {
1193 return false;
1194 }
1195 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1196 return true;
1197}
1198
1199bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1200 GrGLenum* internalFormat) const {
1201 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1202 return false;
1203 }
1204 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1205 return true;
1206}
1207
1208bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1209 GrGLenum* externalFormat, GrGLenum* externalType) const {
1210 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1211 externalFormat, externalType)) {
1212 return false;
1213 }
1214 return true;
1215}
1216
1217bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1218 if (GrPixelConfigIsCompressed(config)) {
1219 return false;
1220 }
1221 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1222 return true;
1223}
1224
1225bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1226 ExternalFormatUsage usage, GrGLenum* externalFormat,
1227 GrGLenum* externalType) const {
1228 SkASSERT(externalFormat && externalType);
1229 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1230 return false;
1231 }
1232
1233 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1234 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1235
1236 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1237 // made to work in many cases using glPixelStore and what not but is not needed currently.
1238 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1239 return false;
1240 }
1241
1242 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1243 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1244
bsalomone9573312016-01-25 14:33:25 -08001245 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1246 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1247 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1248 // texture, not the red component.
1249 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1250 if (this->textureRedSupport()) {
1251 SkASSERT(GR_GL_RED == *externalFormat);
1252 *externalFormat = GR_GL_ALPHA;
1253 }
1254 }
1255
bsalomon76148af2016-01-12 11:13:47 -08001256 return true;
1257}
1258
bsalomoncdee0092016-01-08 13:20:12 -08001259void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1260 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001261 /*
1262 Comments on renderability of configs on various GL versions.
1263 OpenGL < 3.0:
1264 no built in support for render targets.
1265 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1266 format RGB, RGBA and NV float formats we don't use.
1267 This is the following:
1268 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1269 RGB10_A2, RGBA12,RGBA16
1270 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1271 since they aren't required by later standards and the driver can simply return
1272 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1273 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1274 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1275 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1276 This adds a lot of additional renderable sized formats, including ALPHA8.
1277 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1278 16F, 32I, 32UI, and 32F variants).
1279 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1280
1281 For both the above extensions we limit ourselves to those that are also required by
1282 OpenGL 3.0.
1283
1284 OpenGL 3.0:
1285 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1286 but are not required to be supported as renderable textures/renderbuffer.
1287 Required renderable color formats:
1288 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1289 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1290 RGB10_A2.
1291 - R11F_G11F_B10F.
1292 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1293 and RG8UI.
1294 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1295 - ALPHA8
1296
1297 OpenGL 3.1, 3.2, 3.3
1298 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1299 OpengGL 3.3, 4.0, 4.1
1300 Adds RGB10_A2UI.
1301 OpengGL 4.2
1302 Adds
1303 - RGB5_A1, RGBA4
1304 - RGB565
1305 OpenGL 4.4
1306 Does away with the separate list and adds a column to the sized internal color format
1307 table. However, no new formats become required color renderable.
1308
1309 ES 2.0
1310 color renderable: RGBA4, RGB5_A1, RGB565
1311 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1312 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1313 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1314 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1315 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1316 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1317
1318 ES 3.0
1319 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1320 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1321 RGB5_A1.
1322 - RGB8 and RGB565.
1323 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1324 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1325 ES 3.1
1326 Adds RGB10_A2, RGB10_A2UI,
1327 ES 3.2
1328 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1329 */
1330 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1331 if (kNone_MSFBOType != fMSFBOType) {
1332 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1333 }
1334
1335 GrGLStandard standard = ctxInfo.standard();
1336 GrGLVersion version = ctxInfo.version();
1337
cblume790d5132016-02-29 11:13:29 -08001338 bool texStorageSupported = false;
1339 if (kGL_GrGLStandard == standard) {
1340 // The EXT version can apply to either GL or GLES.
1341 texStorageSupported = version >= GR_GL_VER(4,2) ||
1342 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1343 ctxInfo.hasExtension("GL_EXT_texture_storage");
1344 } else {
1345 // Qualcomm Adreno drivers appear to have issues with texture storage.
1346 texStorageSupported = (version >= GR_GL_VER(3,0) &&
1347 kQualcomm_GrGLVendor != ctxInfo.vendor()) &&
1348 ctxInfo.hasExtension("GL_EXT_texture_storage");
1349 }
1350
1351 // TODO: remove after command buffer supports full ES 3.0
1352 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0) &&
1353 kChromium_GrGLDriver == ctxInfo.driver()) {
1354 texStorageSupported = false;
1355 }
1356
bsalomon30447372015-12-21 09:03:05 -08001357 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1358 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001359 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001360 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001361 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001362 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001363
1364 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1365 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001366 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1367 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001368 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001369 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001370 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1371 if (kGL_GrGLStandard == standard) {
1372 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1373 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001374 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001375 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1376 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1377 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1378 }
egdaniel4999df82016-01-07 17:06:04 -08001379 }
cblume790d5132016-02-29 11:13:29 -08001380 if (texStorageSupported) {
1381 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1382 }
bsalomoncdee0092016-01-08 13:20:12 -08001383 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001384
bsalomon76148af2016-01-12 11:13:47 -08001385 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1386 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001387 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001388 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001389 if (kGL_GrGLStandard == standard) {
1390 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1391 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1392 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1393 // Since the internal format is RGBA8, it is also renderable.
1394 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1395 allRenderFlags;
1396 }
1397 } else {
1398 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1399 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1400 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1401 // The APPLE extension doesn't make this renderable.
1402 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1403 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1404 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1405 // Though, that seems to not be the case if the texture storage extension is
1406 // present. The specs don't exactly make that clear.
1407 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1408 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1409 }
1410 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1411 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1412 ConfigInfo::kRenderable_Flag;
1413 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001414 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001415 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1416 ConfigInfo::kRenderableWithMSAA_Flag;
1417 }
1418 }
1419 }
cblume790d5132016-02-29 11:13:29 -08001420 if (texStorageSupported) {
1421 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1422 }
bsalomoncdee0092016-01-08 13:20:12 -08001423 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001424
bsalomon41e4384e2016-01-08 09:12:44 -08001425 // We only enable srgb support if both textures and FBOs support srgb.
1426 bool srgbSupport = false;
1427 if (kGL_GrGLStandard == standard) {
1428 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1429 srgbSupport = true;
1430 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1431 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1432 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1433 srgbSupport = true;
1434 }
1435 }
1436 // All the above srgb extensions support toggling srgb writes
1437 fSRGBWriteControl = srgbSupport;
1438 } else {
1439 // See https://bug.skia.org/4148 for PowerVR issue.
1440 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
1441 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1442 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1443 // sRGB writing for destinations.
1444 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1445 }
bsalomon30447372015-12-21 09:03:05 -08001446 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1447 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1448 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1449 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001450 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1451 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001452 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001453 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001454 if (srgbSupport) {
1455 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1456 allRenderFlags;
1457 }
cblume790d5132016-02-29 11:13:29 -08001458 if (texStorageSupported) {
1459 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1460 }
bsalomoncdee0092016-01-08 13:20:12 -08001461 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001462
1463 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1464 if (this->ES2CompatibilitySupport()) {
1465 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1466 } else {
1467 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1468 }
bsalomon76148af2016-01-12 11:13:47 -08001469 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1470 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001471 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001472 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001473 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1474 if (kGL_GrGLStandard == standard) {
1475 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1476 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1477 }
1478 } else {
1479 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1480 }
cblume790d5132016-02-29 11:13:29 -08001481 // 565 is not a sized internal format on desktop GL. So on desktop with
1482 // 565 we always use an unsized internal format to let the system pick
1483 // the best sized format to convert the 565 data to. Since TexStorage
1484 // only allows sized internal formats we disallow it.
1485 //
1486 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1487 // update.
1488 if (texStorageSupported && kGL_GrGLStandard != standard) {
1489 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1490 }
bsalomoncdee0092016-01-08 13:20:12 -08001491 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001492
1493 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1494 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001495 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1496 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001497 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001498 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001499 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1500 if (kGL_GrGLStandard == standard) {
1501 if (version >= GR_GL_VER(4, 2)) {
1502 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1503 }
1504 } else {
1505 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1506 }
cblume790d5132016-02-29 11:13:29 -08001507 if (texStorageSupported) {
1508 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1509 }
bsalomoncdee0092016-01-08 13:20:12 -08001510 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001511
1512 if (this->textureRedSupport()) {
1513 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1514 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001515 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1516 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001517 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001518 } else {
1519 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1520 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001521 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1522 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001523 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001524 }
1525 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001526 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001527 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1528 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1529 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1530 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1531 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1532 }
cblume790d5132016-02-29 11:13:29 -08001533 if (texStorageSupported) {
1534 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1535 }
bsalomon41e4384e2016-01-08 09:12:44 -08001536
1537 // Check for [half] floating point texture support
1538 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1539 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1540 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1541 bool hasFPTextures = false;
1542 bool hasHalfFPTextures = false;
1543 // for now we don't support floating point MSAA on ES
1544 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1545 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1546
1547 if (kGL_GrGLStandard == standard) {
1548 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1549 hasFPTextures = true;
1550 hasHalfFPTextures = true;
1551 }
1552 } else {
1553 if (version >= GR_GL_VER(3, 1)) {
1554 hasFPTextures = true;
1555 hasHalfFPTextures = true;
1556 } else {
1557 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1558 ctxInfo.hasExtension("GL_OES_texture_float")) {
1559 hasFPTextures = true;
1560 }
1561 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1562 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1563 hasHalfFPTextures = true;
1564 }
1565 }
1566 }
bsalomon30447372015-12-21 09:03:05 -08001567
1568 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1569 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001570 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1571 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001572 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001573 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001574 if (hasFPTextures) {
1575 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1576 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1577 // many precision issues and no clients actually want this yet.
1578 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1579 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1580 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1581 }
1582 }
cblume790d5132016-02-29 11:13:29 -08001583 if (texStorageSupported) {
1584 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1585 }
bsalomoncdee0092016-01-08 13:20:12 -08001586 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001587
1588 if (this->textureRedSupport()) {
1589 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1590 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001591 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1592 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001593 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001594 } else {
1595 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1596 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001597 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1598 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001599 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001600 }
1601 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1602 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1603 } else {
1604 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1605 }
bsalomon7928ef62016-01-05 10:26:39 -08001606 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001607 if (hasHalfFPTextures) {
1608 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1609 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1610 // GL_RED internal format.
1611 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1612 (this->textureRedSupport() &&
1613 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1614 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1615 }
1616 }
cblume790d5132016-02-29 11:13:29 -08001617 if (texStorageSupported) {
1618 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1619 }
bsalomon30447372015-12-21 09:03:05 -08001620
1621 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1622 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001623 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1624 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001625 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1626 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1627 } else {
1628 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1629 }
bsalomon7928ef62016-01-05 10:26:39 -08001630 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001631 if (hasHalfFPTextures) {
1632 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1633 // ES requires 3.2 or EXT_color_buffer_half_float.
1634 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1635 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1636 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1637 }
1638 }
cblume790d5132016-02-29 11:13:29 -08001639 if (texStorageSupported) {
1640 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1641 }
bsalomoncdee0092016-01-08 13:20:12 -08001642 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001643
1644 // Compressed texture support
1645
1646 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1647 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1648
1649 // TODO: Fix command buffer bindings and remove this.
1650 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001651
1652 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001653 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001654
1655 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1656 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001657 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001658 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001659 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001660 // Disable this for now, while we investigate https://bug.skia.org/4333
1661 if (false) {
1662 // Check for 8-bit palette..
1663 GrGLint numFormats;
1664 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1665 if (numFormats) {
1666 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1667 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1668 for (int i = 0; i < numFormats; ++i) {
1669 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1670 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1671 break;
1672 }
1673 }
1674 }
1675 }
bsalomoncdee0092016-01-08 13:20:12 -08001676 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001677
bsalomon41e4384e2016-01-08 09:12:44 -08001678 // May change the internal format based on extensions.
1679 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1680 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1681 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1682 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1683 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1684 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1685 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1686 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1687 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1688 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1689 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1690 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1691 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1692 GR_GL_COMPRESSED_RED_RGTC1;
1693 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1694 GR_GL_COMPRESSED_RED_RGTC1;
1695 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1696 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1697 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1698 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1699 GR_GL_COMPRESSED_3DC_X;
1700
bsalomon30447372015-12-21 09:03:05 -08001701 }
bsalomon76148af2016-01-12 11:13:47 -08001702 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001703 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001704 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001705 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001706
1707 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1708 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001709 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001710 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001711 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001712 if (kGL_GrGLStandard == standard) {
1713 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1714 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1715 }
1716 } else {
1717 if (version >= GR_GL_VER(3, 0) ||
1718 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1719 // ETC2 is a superset of ETC1, so we can just check for that, too.
1720 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1721 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1722 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1723 }
1724 }
bsalomoncdee0092016-01-08 13:20:12 -08001725 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001726
1727 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1728 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001729 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001730 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001731 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001732 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1733 // decompressing the textures in the driver, and is generally slower.
1734 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1735 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1736 }
bsalomoncdee0092016-01-08 13:20:12 -08001737 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001738
1739 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1740 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1741 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1742 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001743 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1744 0;
bsalomon30447372015-12-21 09:03:05 -08001745 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001746 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001747 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1748 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1749 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1750 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1751 }
bsalomoncdee0092016-01-08 13:20:12 -08001752 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001753
1754 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1755
1756 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001757 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1758 ctxInfo.version() >= GR_GL_VER(3,0));
1759 // All ES versions (thus far) require sized internal formats for render buffers.
1760 // TODO: Always use sized internal format?
1761 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1762
bsalomon30447372015-12-21 09:03:05 -08001763 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001764 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1765 // param to glTex[Sub]Image.
1766 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1767 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1768 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1769 fConfigTable[i].fFormats.fSizedInternalFormat :
1770 fConfigTable[i].fFormats.fBaseInternalFormat;
1771 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001772 fConfigTable[i].fFormats.fSizedInternalFormat :
1773 fConfigTable[i].fFormats.fBaseInternalFormat;
1774 }
1775 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1776 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1777 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1778 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1779 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001780 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001781 GR_GL_SRGB_ALPHA;
1782 }
1783
1784 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1785 // as a base format.
1786 // GL_EXT_texture_format_BGRA8888:
1787 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1788 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1789 // formats.
1790 // GL_APPLE_texture_format_BGRA8888:
1791 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1792 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1793 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001794 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001795 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1796 }
1797
bsalomoncdee0092016-01-08 13:20:12 -08001798 // If we don't have texture swizzle support then the shader generator must insert the
1799 // swizzle into shader code.
1800 if (!this->textureSwizzleSupport()) {
1801 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1802 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1803 }
1804 }
1805
bsalomon7f9b2e42016-01-12 13:29:26 -08001806 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1807 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1808 // gets written to the single component.
1809 if (this->textureRedSupport()) {
1810 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1811 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1812 if (GrPixelConfigIsAlphaOnly(config) &&
1813 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1814 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1815 }
1816 }
1817 }
1818
bsalomon30447372015-12-21 09:03:05 -08001819#ifdef SK_DEBUG
1820 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001821 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001822 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001823 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1824 fConfigTable[i].fFormats.fBaseInternalFormat);
1825 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001826 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001827 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1828 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1829 fConfigTable[i].fFormats.fExternalFormat[j]);
1830 }
1831 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001832 }
1833#endif
1834}
1835
egdanielb7e7d572015-11-04 04:23:53 -08001836void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}