Debian Codegraph @

src/gpu/ganesh/gl/GrGLCaps.cpp

raw
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "src/gpu/ganesh/gl/GrGLCaps.h"
9
10 #include "include/core/SkColor.h"
11 #include "include/core/SkRect.h"
12 #include "include/core/SkSize.h"
13 #include "include/core/SkTextureCompressionType.h"
14 #include "include/gpu/GpuTypes.h"
15 #include "include/gpu/ganesh/GrContextOptions.h"
16 #include "include/gpu/ganesh/GrDriverBugWorkarounds.h"
17 #include "include/gpu/ganesh/GrTypes.h"
18 #include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
19 #include "include/gpu/ganesh/gl/GrGLFunctions.h"
20 #include "include/gpu/ganesh/gl/GrGLInterface.h"
21 #include "include/private/base/SkDebug.h"
22 #include "include/private/base/SkMath.h"
23 #include "include/private/base/SkTemplates.h"
24 #include "include/private/base/SkTo.h"
25 #include "src/core/SkCompressedDataUtils.h"
26 #include "src/gpu/Blend.h"
27 #include "src/gpu/GpuTypesPriv.h"
28 #include "src/gpu/ganesh/GrBackendUtils.h"
29 #include "src/gpu/ganesh/GrProgramDesc.h"
30 #include "src/gpu/ganesh/GrRenderTarget.h"
31 #include "src/gpu/ganesh/GrRenderTargetProxy.h"
32 #include "src/gpu/ganesh/GrShaderCaps.h"
33 #include "src/gpu/ganesh/GrSurface.h"
34 #include "src/gpu/ganesh/GrSurfaceProxy.h"
35 #include "src/gpu/ganesh/GrSurfaceProxyPriv.h"
36 #include "src/gpu/ganesh/GrTextureProxy.h"
37 #include "src/gpu/ganesh/TestFormatColorTypeCombination.h"
38 #include "src/gpu/ganesh/gl/GrGLContext.h"
39 #include "src/gpu/ganesh/gl/GrGLDefines.h"
40 #include "src/gpu/ganesh/gl/GrGLRenderTarget.h"
41 #include "src/gpu/ganesh/gl/GrGLTexture.h"
42 #include "src/gpu/ganesh/gl/GrGLUtil.h"
43 #include "src/sksl/SkSLGLSL.h"
44
45 #include <algorithm>
46 #include <cstddef>
47 #include <initializer_list>
48 #include <memory>
49
50 class GrProgramInfo;
51 class SkJSONWriter;
52
53 #if defined(SK_BUILD_FOR_IOS)
54 #include <TargetConditionals.h>
55 #endif
56
57 GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
58 const GrGLContextInfo& ctxInfo,
59 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
60 fStandard = ctxInfo.standard();
61
62 fPackFlipYSupport = false;
63 fTextureUsageSupport = false;
64 fImagingSupport = false;
65 fVertexArrayObjectSupport = false;
66 fDebugSupport = false;
67 fES2CompatibilitySupport = false;
68 fStrictProtectedness = false;
69 fDrawRangeElementsSupport = false;
70 fBaseVertexBaseInstanceSupport = false;
71 fIsCoreProfile = false;
72 fBindFragDataLocationSupport = false;
73 fRectangleTextureSupport = false;
74 fBindUniformLocationSupport = false;
75 fMipmapLevelControlSupport = false;
76 fMipmapLodControlSupport = false;
77 fDoManualMipmapping = false;
78 fClearToBoundaryValuesIsBroken = false;
79 fClearTextureSupport = false;
80 fDrawArraysBaseVertexIsBroken = false;
81 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false;
82 fUseDrawInsteadOfAllRenderTargetWrites = false;
83 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
84 fDontSetBaseOrMaxLevelForExternalTextures = false;
85 fNeverDisableColorWrites = false;
86 fMustSetAnyTexParameterToEnableMipmapping = false;
87 fAllowBGRA8CopyTexSubImage = false;
88 fAllowSRGBCopyTexSubImage = false;
89 fDisallowDynamicMSAA = false;
90 fMustResetBlendFuncBetweenDualSourceAndDisable = false;
91 fBindTexture0WhenChangingTextureFBOMultisampleCount = false;
92 fRebindColorAttachmentAfterCheckFramebufferStatus = false;
93 fBindDefaultFramebufferOnPresent = false;
94 fFlushBeforeWritePixels = false;
95 fDisableScalingCopyAsDraws = false;
96 fPadRG88TransferAlignment = false;
97 fProgramBinarySupport = false;
98 fProgramParameterSupport = false;
99 fSamplerObjectSupport = false;
100 fUseSamplerObjects = false;
101 fTextureSwizzleSupport = false;
102 fTiledRenderingSupport = false;
103 fFenceSyncSupport = false;
104 fFBFetchRequiresEnablePerSample = false;
105 fSRGBWriteControl = false;
106 fSkipErrorChecks = false;
107
108 fShaderCaps = std::make_unique<GrShaderCaps>();
109
110 this->init(contextOptions, ctxInfo, glInterface);
111 }
112
113 static bool angle_backend_is_d3d(GrGLANGLEBackend backend) {
114 return backend == GrGLANGLEBackend::kD3D9 || backend == GrGLANGLEBackend::kD3D11;
115 }
116
117 static bool angle_backend_is_metal(GrGLANGLEBackend backend) {
118 return backend == GrGLANGLEBackend::kMetal;
119 }
120
121 void GrGLCaps::init(const GrContextOptions& contextOptions,
122 const GrGLContextInfo& ctxInfo,
123 const GrGLInterface* gli) {
124 GrGLStandard standard = ctxInfo.standard();
125 // standard can be unused (optimized away) if SK_ASSUME_GL_ES is set
126 sk_ignore_unused_variable(standard);
127 GrGLVersion version = ctxInfo.version();
128
129 #if defined(GPU_TEST_UTILS)
130 const GrGLubyte* deviceName;
131 GR_GL_CALL_RET(gli, deviceName, GetString(GR_GL_RENDERER));
132 this->setDeviceName(reinterpret_cast<const char*>(deviceName));
133 #endif
134
135 if (GR_IS_GR_GL(standard)) {
136 GrGLint max;
137 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
138 fMaxFragmentUniformVectors = max / 4;
139 if (version >= GR_GL_VER(3, 2)) {
140 GrGLint profileMask;
141 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
142 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
143 }
144 } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
145 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
146 &fMaxFragmentUniformVectors);
147 }
148
149 if (fDriverBugWorkarounds.max_fragment_uniform_vectors_32) {
150 fMaxFragmentUniformVectors = std::min(fMaxFragmentUniformVectors, 32);
151 }
152 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
153
154 if (GR_IS_GR_GL(standard)) {
155 fWritePixelsRowBytesSupport = true;
156 fReadPixelsRowBytesSupport = true;
157 fPackFlipYSupport = false;
158 } else if (GR_IS_GR_GL_ES(standard)) {
159 fWritePixelsRowBytesSupport =
160 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_unpack_subimage");
161 fReadPixelsRowBytesSupport =
162 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pack_subimage");
163 fPackFlipYSupport =
164 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
165 } else if (GR_IS_GR_WEBGL(standard)) {
166 // WebGL 2.0 has these
167 fWritePixelsRowBytesSupport = version >= GR_GL_VER(2, 0);
168 fReadPixelsRowBytesSupport = version >= GR_GL_VER(2, 0);
169 }
170 fTransferPixelsToRowBytesSupport = fWritePixelsRowBytesSupport;
171
172 if (fDriverBugWorkarounds.pack_parameters_workaround_with_pack_buffer) {
173 // In some cases drivers handle copying the last row incorrectly
174 // when using GL_PACK_ROW_LENGTH. Chromium handles this by iterating
175 // through every row and conditionally clobbering that value, but
176 // Skia already has a scratch buffer workaround when pack row length
177 // is not supported, so just use that.
178 fReadPixelsRowBytesSupport = false;
179 }
180
181 fTextureUsageSupport = GR_IS_GR_GL_ES(standard) &&
182 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
183
184 if (GR_IS_GR_GL(standard)) {
185 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
186 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
187 ctxInfo.hasExtension("GL_NV_texture_barrier");
188 } else if (GR_IS_GR_GL_ES(standard)) {
189 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
190 } else if (GR_IS_GR_WEBGL(standard)) {
191 fTextureBarrierSupport = false;
192 }
193
194 if (GR_IS_GR_GL(standard)) {
195 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
196 ctxInfo.hasExtension("GL_ARB_texture_multisample");
197 } else if (GR_IS_GR_GL_ES(standard)) {
198 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
199 } else if (GR_IS_GR_WEBGL(standard)) {
200 fSampleLocationsSupport = false;
201 }
202
203 fImagingSupport = GR_IS_GR_GL(standard) &&
204 ctxInfo.hasExtension("GL_ARB_imaging");
205
206 if (((GR_IS_GR_GL(standard) && version >= GR_GL_VER(4,3)) ||
207 (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0)) ||
208 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
209 fInvalidateFBType = kInvalidate_InvalidateFBType;
210 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
211 fInvalidateFBType = kDiscard_InvalidateFBType;
212 }
213
214 // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
215 // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
216 if (GR_IS_GR_GL_ES(standard)) {
217 // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
218 // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
219 if (ctxInfo.vendor() == GrGLVendor::kARM) {
220 fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
221 }
222 }
223
224 if (ctxInfo.vendor() == GrGLVendor::kARM ||
225 ctxInfo.vendor() == GrGLVendor::kImagination ||
226 ctxInfo.vendor() == GrGLVendor::kQualcomm ) {
227 fPreferFullscreenClears = true;
228 }
229
230 if (GR_IS_GR_GL(standard)) {
231 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
232 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
233 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
234 } else if (GR_IS_GR_GL_ES(standard)) {
235 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
236 ctxInfo.hasExtension("GL_OES_vertex_array_object");
237 } else if (GR_IS_GR_WEBGL(standard)) {
238 fVertexArrayObjectSupport = version >= GR_GL_VER(2, 0) ||
239 ctxInfo.hasExtension("GL_OES_vertex_array_object") ||
240 ctxInfo.hasExtension("OES_vertex_array_object");
241 }
242
243 if (GR_IS_GR_GL(standard) && version >= GR_GL_VER(4,3)) {
244 fDebugSupport = true;
245 } else if (GR_IS_GR_GL_ES(standard)) {
246 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
247 } else if (GR_IS_GR_WEBGL(standard)) {
248 fDebugSupport = false;
249 }
250
251 if (GR_IS_GR_GL(standard)) {
252 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
253 }
254 else if (GR_IS_GR_GL_ES(standard)) {
255 fES2CompatibilitySupport = true;
256 } else if (GR_IS_GR_WEBGL(standard)) {
257 fES2CompatibilitySupport = true;
258 }
259
260 if (GR_IS_GR_GL(standard)) {
261 fClientCanDisableMultisample = true;
262 } else if (GR_IS_GR_GL_ES(standard)) {
263 fClientCanDisableMultisample = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
264 } else if (GR_IS_GR_WEBGL(standard)) {
265 fClientCanDisableMultisample = false;
266 }
267
268 if (GR_IS_GR_GL(standard)) {
269 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
270 // instanced arrays, but we could make this more granular if we wanted
271 fDrawInstancedSupport =
272 version >= GR_GL_VER(3, 2) ||
273 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
274 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
275 } else if (GR_IS_GR_GL_ES(standard)) {
276 fDrawInstancedSupport =
277 version >= GR_GL_VER(3, 0) ||
278 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
279 ctxInfo.hasExtension("GL_EXT_instanced_arrays")) ||
280 ctxInfo.hasExtension("GL_ANGLE_instanced_arrays");
281 } else if (GR_IS_GR_WEBGL(standard)) {
282 // WebGL 2.0 has DrawArraysInstanced and drawElementsInstanced
283 fDrawInstancedSupport = version >= GR_GL_VER(2, 0);
284 }
285
286 if (GR_IS_GR_GL(standard)) {
287 if (version >= GR_GL_VER(3, 0)) {
288 fBindFragDataLocationSupport = true;
289 }
290 } else if (GR_IS_GR_GL_ES(standard)) {
291 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
292 fBindFragDataLocationSupport = true;
293 }
294 } else if (GR_IS_GR_WEBGL(standard)) {
295 fBindFragDataLocationSupport = false;
296 }
297
298 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
299
300 if (GR_IS_GR_GL(standard)) {
301 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
302 ctxInfo.hasExtension("GL_ANGLE_texture_rectangle")) {
303 fRectangleTextureSupport = true;
304 }
305 } else if (GR_IS_GR_GL_ES(standard)) {
306 fRectangleTextureSupport = ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
307 ctxInfo.hasExtension("GL_ANGLE_texture_rectangle");
308 } else if (GR_IS_GR_WEBGL(standard)) {
309 fRectangleTextureSupport = false;
310 }
311
312 // GrCaps defaults fClampToBorderSupport to true, so disable when unsupported
313 if (GR_IS_GR_GL(standard)) {
314 // Clamp to border added in 1.3
315 if (version < GR_GL_VER(1, 3) && !ctxInfo.hasExtension("GL_ARB_texture_border_clamp")) {
316 fClampToBorderSupport = false;
317 }
318 } else if (GR_IS_GR_GL_ES(standard)) {
319 // GLES didn't have clamp to border until 3.2, but provides several alternative extensions
320 if (version < GR_GL_VER(3, 2) && !ctxInfo.hasExtension("GL_EXT_texture_border_clamp") &&
321 !ctxInfo.hasExtension("GL_NV_texture_border_clamp") &&
322 !ctxInfo.hasExtension("GL_OES_texture_border_clamp")) {
323 fClampToBorderSupport = false;
324 }
325 } else if (GR_IS_GR_WEBGL(standard)) {
326 // WebGL appears to only have REPEAT, CLAMP_TO_EDGE and MIRRORED_REPEAT
327 fClampToBorderSupport = false;
328 }
329
330 if (GR_IS_GR_GL(standard)) {
331 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
332 fTextureSwizzleSupport = true;
333 }
334 } else if (GR_IS_GR_GL_ES(standard)) {
335 if (version >= GR_GL_VER(3,0)) {
336 fTextureSwizzleSupport = true;
337 }
338 } else if (GR_IS_GR_WEBGL(standard)) {
339 fTextureSwizzleSupport = false;
340 }
341
342 if (GR_IS_GR_GL(standard)) {
343 fMipmapLevelControlSupport = true;
344 fMipmapLodControlSupport = true;
345 } else if (GR_IS_GR_GL_ES(standard)) {
346 if (version >= GR_GL_VER(3,0)) {
347 fMipmapLevelControlSupport = true;
348 fMipmapLodControlSupport = true;
349 }
350 } else if (GR_IS_GR_WEBGL(standard)) {
351 fMipmapLevelControlSupport = false;
352 fMipmapLodControlSupport = false;
353 }
354
355 if ((GR_IS_GR_GL_ES(standard) || GR_IS_GR_GL(standard)) &&
356 ctxInfo.hasExtension("GL_ARB_invalidate_subdata")) {
357 fInvalidateBufferType = InvalidateBufferType::kInvalidate;
358 } else if (!GR_IS_GR_WEBGL(standard) && !ctxInfo.isOverCommandBuffer()) {
359 // Chrome's command buffer will push an array of zeros to a buffer if null is passed to
360 // glBufferData (to avoid letting an application see uninitialized memory). This is
361 // expensive so we avoid it. WebGL spec explicitly disallows null values.
362 fInvalidateBufferType = InvalidateBufferType::kNullData;
363 }
364
365 if (GR_IS_GR_GL(standard)) {
366 fClearTextureSupport = (version >= GR_GL_VER(4,4) ||
367 ctxInfo.hasExtension("GL_ARB_clear_texture"));
368 } else if (GR_IS_GR_GL_ES(standard)) {
369 fClearTextureSupport = ctxInfo.hasExtension("GL_EXT_clear_texture");
370 } else if (GR_IS_GR_WEBGL(standard)) {
371 fClearTextureSupport = false;
372 }
373
374 #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
375 fSupportsAHardwareBufferImages = true;
376 #endif
377
378 if (GR_IS_GR_GL(standard)) {
379 fSRGBWriteControl = version >= GR_GL_VER(3, 0) ||
380 ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
381 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB");
382 } else if (GR_IS_GR_GL_ES(standard)) {
383 // ES through 3.2 requires EXT_srgb_write_control to support toggling
384 // sRGB writing for destinations.
385 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
386 } // No WebGL support
387
388 fSkipErrorChecks = ctxInfo.isOverCommandBuffer();
389 if (GR_IS_GR_WEBGL(standard)) {
390 // Error checks are quite costly in webgl, especially in Chrome.
391 fSkipErrorChecks = true;
392 }
393
394 // When we are abandoning the context we cannot call into GL thus we should skip any sync work.
395 fMustSyncGpuDuringAbandon = false;
396
397 fSupportsProtectedContent = [&]() {
398 if (!ctxInfo.hasExtension("GL_EXT_protected_textures")) {
399 return false;
400 }
401
402 GrGLint contextFlags;
403 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_FLAGS, &contextFlags);
404 return SkToBool(contextFlags & GR_GL_CONTEXT_FLAG_PROTECTED_CONTENT_BIT_EXT);
405 }();
406
407 /**
408 * When Ganesh is backed by ANGLE mapping to Vulkan, the Protectedness handling has to be
409 * more like the Vulkan case (i.e., all internally allocated objects that will be written to
410 * in a Protected Context must be Protected). ANGLE just forwards any work to the
411 * active Vulkan Context. If that Vulkan Context is Protected that would mean, without
412 * using strict Protectedness, writes to unProtected objects would be submitted to a
413 * Protected Queue - which is not allowed in Vulkan.
414 */
415 fStrictProtectedness = fSupportsProtectedContent &&
416 ctxInfo.angleBackend() != GrGLANGLEBackend::kUnknown;
417
418 /**************************************************************************
419 * GrShaderCaps fields
420 **************************************************************************/
421
422 // This must be called after fCoreProfile is set on the GrGLCaps
423 this->initGLSL(ctxInfo, gli);
424 GrShaderCaps* shaderCaps = fShaderCaps.get();
425
426 // Enable supported shader-related caps
427 if (GR_IS_GR_GL(standard)) {
428 shaderCaps->fDualSourceBlendingSupport =
429 (version >= GR_GL_VER(3, 3) ||
430 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
431 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
432
433 shaderCaps->fShaderDerivativeSupport = true;
434 shaderCaps->fExplicitTextureLodSupport =
435 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
436
437 shaderCaps->fIntegerSupport = version >= GR_GL_VER(3, 0) &&
438 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
439
440 shaderCaps->fNonsquareMatrixSupport =
441 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
442 shaderCaps->fInverseHyperbolicSupport =
443 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
444 } else if (GR_IS_GR_GL_ES(standard)) {
445 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
446
447 shaderCaps->fShaderDerivativeSupport =
448 // We use this value for GLSL ES 3.0.
449 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_standard_derivatives");
450 shaderCaps->fExplicitTextureLodSupport =
451 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
452
453 shaderCaps->fIntegerSupport = version >= GR_GL_VER(3, 0) &&
454 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
455 shaderCaps->fNonsquareMatrixSupport =
456 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
457 shaderCaps->fInverseHyperbolicSupport =
458 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
459 } else if (GR_IS_GR_WEBGL(standard)) {
460 shaderCaps->fShaderDerivativeSupport = version >= GR_GL_VER(2, 0) ||
461 ctxInfo.hasExtension("GL_OES_standard_derivatives") ||
462 ctxInfo.hasExtension("OES_standard_derivatives");
463 shaderCaps->fExplicitTextureLodSupport =
464 version >= GR_GL_VER(2, 0) &&
465 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
466 shaderCaps->fIntegerSupport = (version >= GR_GL_VER(2, 0));
467 shaderCaps->fNonsquareMatrixSupport =
468 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
469 shaderCaps->fInverseHyperbolicSupport =
470 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
471 }
472
473 if (ctxInfo.hasExtension("GL_NV_conservative_raster")) {
474 fConservativeRasterSupport = true;
475 }
476
477 if (GR_IS_GR_GL(standard)) {
478 fWireframeSupport = true;
479 }
480
481 if (GR_IS_GR_GL(standard)) {
482 shaderCaps->fRewriteSwitchStatements =
483 ctxInfo.glslGeneration() < SkSL::GLSLGeneration::k130; // introduced in GLSL 1.3
484 } else if (GR_IS_GR_GL_ES(standard)) {
485 shaderCaps->fRewriteSwitchStatements =
486 ctxInfo.glslGeneration() < SkSL::GLSLGeneration::k300es; // introduced in GLSL ES3
487 } else if (GR_IS_GR_WEBGL(standard)) {
488 shaderCaps->fRewriteSwitchStatements = version < GR_GL_VER(2, 0); // introduced in WebGL 2
489 shaderCaps->fCanUseVoidInSequenceExpressions =
490 false; // removed in WebGL 2, use workaround in all versions for safety
491 }
492
493 // Protect ourselves against tracking huge amounts of texture state.
494 static const uint8_t kMaxSaneSamplers = 32;
495 GrGLint maxSamplers;
496 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
497 shaderCaps->fMaxFragmentSamplers = std::min<GrGLint>(kMaxSaneSamplers, maxSamplers);
498
499 // SGX and Mali GPUs have tiled architectures that have trouble with frequently changing VBOs.
500 // We've measured a performance increase using non-VBO vertex data for dynamic content on these
501 // GPUs. Perhaps we should read the renderer string and limit this decision to specific GPU
502 // families rather than basing it on the vendor alone.
503 // Angle can be initialized with client arrays disabled and needs to be queried. The Chrome
504 // command buffer blocks the use of client side buffers (but may emulate VBOs with them). Client
505 // side buffers are not allowed in core profiles.
506 if (GR_IS_GR_GL(standard) || GR_IS_GR_GL_ES(standard)) {
507 GrGLint clientArraysEnabled = GR_GL_TRUE;
508 if (ctxInfo.hasExtension("GL_ANGLE_client_arrays")) {
509 GR_GL_GetIntegerv(gli, GR_GL_CLIENT_ARRAYS_ANGLE, &clientArraysEnabled);
510 }
511
512 if (clientArraysEnabled && !ctxInfo.isOverCommandBuffer() && !fIsCoreProfile &&
513 (ctxInfo.vendor() == GrGLVendor::kARM || ctxInfo.vendor() == GrGLVendor::kImagination ||
514 ctxInfo.vendor() == GrGLVendor::kQualcomm)) {
515 fPreferClientSideDynamicBuffers = true;
516 }
517 } // No client side arrays in WebGL https://www.khronos.org/registry/webgl/specs/1.0/#6.2
518
519 if (!contextOptions.fAvoidStencilBuffers && !fSupportsProtectedContent) {
520 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
521 // We also avoid both for Protected Contexts due to their use of RenderBuffers (which
522 // cannot be correctly created as Protected).
523 this->initFSAASupport(contextOptions, ctxInfo, gli);
524 this->initStencilSupport(ctxInfo);
525 }
526
527 // Setup blit framebuffer
528 if (GR_IS_GR_GL(standard)) {
529 if (version >= GR_GL_VER(3,0) ||
530 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
531 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
532 fBlitFramebufferFlags = 0;
533 }
534 } else if (GR_IS_GR_GL_ES(standard)) {
535 if (version >= GR_GL_VER(3, 0) ||
536 ctxInfo.hasExtension("GL_NV_framebuffer_blit")) {
537 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
538 kNoMSAADst_BlitFramebufferFlag |
539 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
540 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
541 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
542 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
543 // limitations.
544 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
545 kResolveMustBeFull_BlitFrambufferFlag |
546 kNoMSAADst_BlitFramebufferFlag |
547 kNoFormatConversion_BlitFramebufferFlag |
548 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
549 }
550 } // No WebGL 1.0 support for BlitFramebuffer
551
552 this->initBlendEqationSupport(ctxInfo);
553
554 if (GR_IS_GR_GL(standard)) {
555 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
556 // extension includes glMapBuffer.
557 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
558 fMapBufferFlags |= kSubset_MapFlag;
559 fMapBufferType = kMapBufferRange_MapBufferType;
560 } else {
561 fMapBufferType = kMapBuffer_MapBufferType;
562 }
563 } else if (GR_IS_GR_GL_ES(standard)) {
564 // Unextended GLES2 doesn't have any buffer mapping.
565 fMapBufferFlags = kNone_MapFlags;
566 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
567 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
568 fMapBufferType = kChromium_MapBufferType;
569 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
570 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
571 fMapBufferType = kMapBufferRange_MapBufferType;
572 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
573 fMapBufferFlags = kCanMap_MapFlag;
574 fMapBufferType = kMapBuffer_MapBufferType;
575 }
576 } else if (GR_IS_GR_WEBGL(standard)) {
577 // explicitly removed https://www.khronos.org/registry/webgl/specs/2.0/#5.14
578 fMapBufferFlags = kNone_MapFlags;
579 }
580
581 // Buffers have more restrictions in WebGL than GLES. For example,
582 // https://www.khronos.org/registry/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING
583 // We therefore haven't attempted to support mapping or transfers between buffers and surfaces
584 // or between buffers.
585
586 if (GR_IS_GR_GL(standard)) {
587 if (version >= GR_GL_VER(2, 1) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object") ||
588 ctxInfo.hasExtension("GL_EXT_pixel_buffer_object")) {
589 fTransferFromBufferToTextureSupport = true;
590 fTransferFromSurfaceToBufferSupport = true;
591 fTransferBufferType = TransferBufferType::kARB_PBO;
592 }
593 } else if (GR_IS_GR_GL_ES(standard)) {
594 if (version >= GR_GL_VER(3, 0) ||
595 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
596 // GL_EXT_unpack_subimage needed to support subtexture rectangles
597 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
598 fTransferFromBufferToTextureSupport = true;
599 fTransferFromSurfaceToBufferSupport = true;
600 if (version < GR_GL_VER(3, 0)) {
601 fTransferBufferType = TransferBufferType::kNV_PBO;
602 } else {
603 fTransferBufferType = TransferBufferType::kARB_PBO;
604 }
605 // TODO: get transfer buffers working in Chrome
606 // } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
607 // fTransferFromBufferToTextureSupport = false;
608 // fTransferFromSurfaceToBufferSupport = false;
609 // fTransferBufferType = TransferBufferType::kChromium;
610 }
611 }
612
613 if (GR_IS_GR_GL(standard) &&
614 (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_copy_buffer"))) {
615 fTransferFromBufferToBufferSupport = true;
616 } else if (GR_IS_GR_GL_ES(standard) &&
617 (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_copy_buffer"))) {
618 fTransferFromBufferToBufferSupport = true;
619 }
620
621 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
622 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
623 if (fBufferMapThreshold < 0) {
624 #if 0
625 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
626 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
627 // using a small subset.
628 fBufferMapThreshold = ctxInfo.isOverCommandBuffer() ? 0 : SK_MaxS32;
629 #else
630 fBufferMapThreshold = SK_MaxS32;
631 #endif
632 }
633
634 if (GR_IS_GR_GL(standard)) {
635 fNPOTTextureTileSupport = true;
636 fMipmapSupport = true;
637 fAnisoSupport = version >= GR_GL_VER(4,6) ||
638 ctxInfo.hasExtension("GL_ARB_texture_filter_anisotropic") ||
639 ctxInfo.hasExtension("GL_EXT_texture_filter_anisotropic");
640 } else if (GR_IS_GR_GL_ES(standard)) {
641 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
642 // ES3 has no limitations.
643 fNPOTTextureTileSupport = version >= GR_GL_VER(3,0) ||
644 ctxInfo.hasExtension("GL_OES_texture_npot");
645 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
646 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
647 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
648 // to alllow arbitrary wrap modes, however.
649 fMipmapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
650 fAnisoSupport = ctxInfo.hasExtension("GL_EXT_texture_filter_anisotropic");
651 } else if (GR_IS_GR_WEBGL(standard)) {
652 // Texture access works in the WebGL 2.0 API as in the OpenGL ES 3.0 API
653 fNPOTTextureTileSupport = version >= GR_GL_VER(2,0);
654 // All mipmapping and all wrapping modes are supported for non-power-of-
655 // two images [in WebGL 2.0].
656 fMipmapSupport = fNPOTTextureTileSupport;
657 fAnisoSupport = ctxInfo.hasExtension("GL_EXT_texture_filter_anisotropic") ||
658 ctxInfo.hasExtension("EXT_texture_filter_anisotropic");
659 }
660 if (fAnisoSupport) {
661 GR_GL_GetFloatv(gli, GR_GL_MAX_TEXTURE_MAX_ANISOTROPY, &fMaxTextureMaxAnisotropy);
662 }
663
664 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
665
666 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
667 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
668
669 if (ctxInfo.vendor() == GrGLVendor::kARM) {
670 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
671 fMaxPreferredRenderTargetSize = std::min(4096, fMaxPreferredRenderTargetSize);
672 }
673
674 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
675
676 // Disable scratch texture reuse on Mali and Adreno devices
677 fReuseScratchTextures = (ctxInfo.vendor() != GrGLVendor::kARM);
678
679 #if 0
680 fReuseScratchBuffers = ctxInfo.vendor() != GrGLVendor::kARM
681 ctxInfo.vendor() != GrGLVendor::kQualcomm;
682 #endif
683
684 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
685 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
686 }
687
688 #ifdef SK_BUILD_FOR_WIN
689 // We're assuming that on Windows Chromium we're using D3D ANGLE.
690 bool isD3DANGLE = angle_backend_is_d3d(ctxInfo.angleBackend()) ||
691 ctxInfo.isOverCommandBuffer();
692 // On ANGLE deferring flushes can lead to GPU starvation
693 fPreferVRAMUseOverFlushes = !isD3DANGLE;
694 #endif
695
696 if (ctxInfo.isOverCommandBuffer()) {
697 fMustClearUploadedBufferData = true;
698 }
699
700 // In a WASM build on Firefox, we see warnings like
701 // WebGL warning: texSubImage2D: This operation requires zeroing texture data. This is slow.
702 // WebGL warning: texSubImage2D: Texture has not been initialized prior to a partial upload,
703 // forcing the browser to clear it. This may be slow.
704 // Setting the initial clear seems to make those warnings go away and offers a substantial
705 // boost in performance in Firefox. Chrome sees a more modest increase.
706 if (GR_IS_GR_WEBGL(standard)) {
707 fShouldInitializeTextures = true;
708 }
709
710 if (GR_IS_GR_GL(standard)) {
711 // ARB allows mixed size FBO attachments, EXT does not.
712 if (version >= GR_GL_VER(3, 0) ||
713 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
714 fOversizedStencilSupport = true;
715 } else {
716 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
717 }
718 } else if (GR_IS_GR_GL_ES(standard)) {
719 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
720 fOversizedStencilSupport = version >= GR_GL_VER(3, 0);
721 } else if (GR_IS_GR_WEBGL(standard)) {
722 // WebGL 1.0 has some constraints for FBO attachments:
723 // https://www.khronos.org/registry/webgl/specs/1.0/index.html#6.6
724 // These constraints "no longer apply in WebGL 2"
725 fOversizedStencilSupport = version >= GR_GL_VER(2, 0);
726 }
727
728 if (GR_IS_GR_GL(standard)) {
729 fBaseVertexBaseInstanceSupport = version >= GR_GL_VER(4,2) ||
730 ctxInfo.hasExtension("GL_ARB_base_instance");
731 if (fBaseVertexBaseInstanceSupport) {
732 fNativeDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
733 ctxInfo.hasExtension("GL_ARB_draw_indirect");
734 if (version >= GR_GL_VER(4,3) || ctxInfo.hasExtension("GL_ARB_multi_draw_indirect")) {
735 fMultiDrawType = MultiDrawType::kMultiDrawIndirect;
736 }
737 }
738 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
739 } else if (GR_IS_GR_GL_ES(standard)) {
740 fBaseVertexBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
741 // Don't support indirect draws on ES. They don't allow VAO 0.
742 //
743 // "An INVALID_OPERATION error is generated if zero is bound to VERTEX_ARRAY_BINDING,
744 // DRAW_INDIRECT_BUFFER or to any enabled vertex array."
745 //
746 // https://www.khronos.org/registry/OpenGL/specs/es/3.1/es_spec_3.1.pdf
747 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
748 } else if (GR_IS_GR_WEBGL(standard)) {
749 fBaseVertexBaseInstanceSupport = ctxInfo.hasExtension(
750 "WEBGL_draw_instanced_base_vertex_base_instance");
751 if (fBaseVertexBaseInstanceSupport && ctxInfo.hasExtension(
752 "GL_WEBGL_multi_draw_instanced_base_vertex_base_instance")) {
753 fNativeDrawIndirectSupport = true;
754 fMultiDrawType = MultiDrawType::kANGLEOrWebGL;
755 }
756 // The indirect structs need to reside in CPU memory for the WebGL version.
757 fUseClientSideIndirectBuffers = true;
758 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
759 }
760 // We used to disable this as a correctness workaround (http://anglebug.com/4536). Now it is
761 // disabled because of poor performance (skbug.com/40043081).
762 if (ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D11) {
763 fBaseVertexBaseInstanceSupport = false;
764 fNativeDrawIndirectSupport = false;
765 fMultiDrawType = MultiDrawType::kNone;
766 }
767
768 // We do not support GrBackendSemaphore for GL backends because the clients cannot really make
769 // GrGLsync objects ahead of time without talking to the GPU.
770 fBackendSemaphoreSupport = false;
771 // We prefer GL sync objects but also support NV_fence_sync. The former can be
772 // used to implement GrGLsync and GrSemaphore. The latter only implements GrGLsync.
773 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
774 if (GR_IS_GR_WEBGL(standard)) {
775 // Only in WebGL 2.0
776 fSemaphoreSupport = fFenceSyncSupport = version >= GR_GL_VER(2, 0);
777 fFenceType = FenceType::kSyncObject;
778 } else if (GR_IS_GR_GL(standard) &&
779 (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync"))) {
780 fSemaphoreSupport = fFenceSyncSupport = true;
781 fFenceType = FenceType::kSyncObject;
782 } else if (GR_IS_GR_GL_ES(standard) &&
783 (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync"))) {
784 fSemaphoreSupport = fFenceSyncSupport = true;
785 fFenceType = FenceType::kSyncObject;
786 } else if (ctxInfo.hasExtension("GL_NV_fence")) {
787 // This extension can exist in GL and GL ES. We have it last because we prefer the
788 // standard GLsync object implementation which also supports GPU semaphore semantics.
789 fFenceSyncSupport = true;
790 fFenceType = FenceType::kNVFence;
791 }
792 fFinishedProcAsyncCallbackSupport = fFenceSyncSupport;
793
794 if (GR_IS_GR_WEBGL(standard)) {
795 if (version >= GR_GL_VER(2, 0)) {
796 if (ctxInfo.hasExtension("EXT_disjoint_timer_query_webgl2") ||
797 ctxInfo.hasExtension("GL_EXT_disjoint_timer_query_webgl2")) {
798 fTimerQueryType = TimerQueryType::kDisjoint;
799 }
800 } else {
801 if (ctxInfo.hasExtension("EXT_disjoint_timer_query") ||
802 ctxInfo.hasExtension("GL_EXT_disjoint_timer_query")) {
803 fTimerQueryType = TimerQueryType::kDisjoint;
804 }
805 }
806 } else if (GR_IS_GR_GL_ES(standard)) {
807 if (ctxInfo.hasExtension("GL_EXT_disjoint_timer_query")) {
808 fTimerQueryType = TimerQueryType::kDisjoint;
809 }
810 } else if (GR_IS_GR_GL(standard)) {
811 if (version >= GR_GL_VER(3, 3) || ctxInfo.hasExtension("GL_EXT_timer_query") ||
812 ctxInfo.hasExtension("GL_ARB_timer_query")) {
813 fTimerQueryType = TimerQueryType::kRegular;
814 }
815 }
816 if (fTimerQueryType != TimerQueryType::kNone) {
817 fSupportedGpuStats |= skgpu::GpuStatsFlags::kElapsedTime;
818 }
819
820 // Safely moving textures between contexts requires semaphores.
821 fCrossContextTextureSupport = fSemaphoreSupport;
822
823 // Half float vertex attributes requires GL3 or ES3
824 // It can also work with OES_VERTEX_HALF_FLOAT, but that requires a different enum.
825 if (GR_IS_GR_GL(standard)) {
826 fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(3, 0));
827 } else if (GR_IS_GR_GL_ES(standard)) {
828 fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(3, 0));
829 } else if (GR_IS_GR_WEBGL(standard)) {
830 // This appears to be supported in 2.0, looking at the spec.
831 fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(2, 0));
832 }
833
834 fDynamicStateArrayGeometryProcessorTextureSupport = true;
835
836 if (GR_IS_GR_GL(standard)) {
837 fProgramBinarySupport = (version >= GR_GL_VER(4, 1));
838 fProgramParameterSupport = (version >= GR_GL_VER(4, 1));
839 } else if (GR_IS_GR_GL_ES(standard)) {
840 fProgramBinarySupport =
841 (version >= GR_GL_VER(3, 0)) || ctxInfo.hasExtension("GL_OES_get_program_binary");
842 fProgramParameterSupport = (version >= GR_GL_VER(3, 0));
843 } // Explicitly not supported in WebGL 2.0
844 // https://www.khronos.org/registry/webgl/specs/2.0/#5.4
845 if (fProgramBinarySupport) {
846 GrGLint count;
847 GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
848 if (count > 0) {
849 fProgramBinaryFormats.resize_back(count);
850 GR_GL_GetIntegerv(gli, GR_GL_PROGRAM_BINARY_FORMATS,
851 reinterpret_cast<GrGLint*>(fProgramBinaryFormats.data()));
852 } else {
853 fProgramBinarySupport = false;
854 }
855 }
856 if (GR_IS_GR_GL(standard)) {
857 fSamplerObjectSupport =
858 version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_sampler_objects");
859 } else if (GR_IS_GR_GL_ES(standard)) {
860 fSamplerObjectSupport = version >= GR_GL_VER(3,0);
861 } else if (GR_IS_GR_WEBGL(standard)) {
862 fSamplerObjectSupport = version >= GR_GL_VER(2,0);
863 }
864 // We currently use sampler objects whenever they are available.
865 fUseSamplerObjects = fSamplerObjectSupport;
866
867 if (GR_IS_GR_GL_ES(standard)) {
868 fTiledRenderingSupport = ctxInfo.hasExtension("GL_QCOM_tiled_rendering");
869 }
870
871 if (ctxInfo.vendor() == GrGLVendor::kARM) {
872 fShouldCollapseSrcOverToSrcWhenAble = true;
873 }
874
875 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
876 if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue) {
877 // https://b/195281495
878 // The TecnoSpark 3 Pro with a PowerVR GE8300 seems to have a steep dithering performance
879 // cliff in the Android Framework
880 fAvoidDithering = true;
881 }
882 #endif
883
884 FormatWorkarounds formatWorkarounds;
885
886 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
887 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, gli, shaderCaps,
888 &formatWorkarounds);
889 }
890
891 // Requires msaa support, ES compatibility have already been detected.
892 this->initFormatTable(ctxInfo, gli, formatWorkarounds);
893
894 this->finishInitialization(contextOptions);
895
896 // For GL, besides the user-specifiable override, we also want to avoid stencil buffers
897 // in Protected mode (to avoid using RenderBuffers)
898 fAvoidStencilBuffers = contextOptions.fAvoidStencilBuffers || fSupportsProtectedContent;
899
900 // For now these two are equivalent but we could have dst read in shader via some other method.
901 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
902 }
903
904 const char* get_glsl_version_decl_string(GrGLStandard standard, SkSL::GLSLGeneration generation,
905 bool isCoreProfile) {
906 if (GR_IS_GR_GL(standard)) {
907 switch (generation) {
908 case SkSL::GLSLGeneration::k110:
909 return "#version 110\n";
910 case SkSL::GLSLGeneration::k130:
911 return "#version 130\n";
912 case SkSL::GLSLGeneration::k140:
913 return "#version 140\n";
914 case SkSL::GLSLGeneration::k150:
915 if (isCoreProfile) {
916 return "#version 150\n";
917 } else {
918 return "#version 150 compatibility\n";
919 }
920 case SkSL::GLSLGeneration::k330:
921 if (isCoreProfile) {
922 return "#version 330\n";
923 } else {
924 return "#version 330 compatibility\n";
925 }
926 case SkSL::GLSLGeneration::k400:
927 if (isCoreProfile) {
928 return "#version 400\n";
929 } else {
930 return "#version 400 compatibility\n";
931 }
932 case SkSL::GLSLGeneration::k420:
933 if (isCoreProfile) {
934 return "#version 420\n";
935 } else {
936 return "#version 420 compatibility\n";
937 }
938 default:
939 break;
940 }
941 } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
942 switch (generation) {
943 case SkSL::GLSLGeneration::k100es:
944 return "#version 100\n";
945 case SkSL::GLSLGeneration::k300es:
946 return "#version 300 es\n";
947 case SkSL::GLSLGeneration::k310es:
948 return "#version 310 es\n";
949 case SkSL::GLSLGeneration::k320es:
950 return "#version 320 es\n";
951 default:
952 break;
953 }
954 }
955 return "<no version>";
956 }
957
958 bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
959 if (GR_IS_GR_GL(ctxInfo.standard()) &&
960 ctxInfo.version() < GR_GL_VER(4,1) &&
961 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
962 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
963 return true;
964 }
965 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
966 // geometry shaders don't have lower precision than vertex and fragment.
967 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
968 GrGLint range[2];
969 GrGLint bits;
970 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
971 if (range[0] < 127 || range[1] < 127 || bits < 23) {
972 return false;
973 }
974 }
975 return true;
976 }
977
978 void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
979 GrGLStandard standard = ctxInfo.standard();
980 GrGLVersion version = ctxInfo.version();
981
982 /**************************************************************************
983 * Caps specific to GrShaderCaps
984 **************************************************************************/
985
986 GrShaderCaps* shaderCaps = fShaderCaps.get();
987 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
988 if (GR_IS_GR_GL_ES(standard)) {
989 // fFBFetchRequiresEnablePerSample is not a shader cap but is initialized below to keep it
990 // with related FB fetch logic.
991 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
992 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
993 shaderCaps->fFBFetchSupport = true;
994 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
995 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
996 fFBFetchRequiresEnablePerSample = false;
997 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
998 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know.
999 shaderCaps->fFBFetchNeedsCustomOutput = false;
1000 shaderCaps->fFBFetchSupport = true;
1001 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
1002 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
1003 fFBFetchRequiresEnablePerSample = false;
1004 } else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
1005 // The arm extension also requires an additional flag which we will set onResetContext.
1006 shaderCaps->fFBFetchNeedsCustomOutput = false;
1007 shaderCaps->fFBFetchSupport = true;
1008 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
1009 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
1010 fFBFetchRequiresEnablePerSample = true;
1011 }
1012 shaderCaps->fUsesPrecisionModifiers = true;
1013 } else if (GR_IS_GR_GL(standard)) {
1014 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
1015 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
1016 shaderCaps->fFBFetchSupport = true;
1017 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
1018 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
1019 fFBFetchRequiresEnablePerSample = false;
1020 }
1021 } else if (GR_IS_GR_WEBGL(standard)) {
1022 shaderCaps->fUsesPrecisionModifiers = true;
1023 }
1024
1025 if (GR_IS_GR_GL(standard)) {
1026 shaderCaps->fFlatInterpolationSupport =
1027 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
1028 } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
1029 shaderCaps->fFlatInterpolationSupport =
1030 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
1031 } // not sure for WebGL
1032
1033 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
1034 // Avoid on ANGLE too, it inserts a geometry shader into the pipeline to implement flat interp.
1035 // Is this only true on ANGLE's D3D backends or also on the GL backend?
1036 // Flat interpolation is slow with ANGLE's Metal backend and uses memory to rewrite index
1037 // buffers to support GL's provoking vertex semantics.
1038 // Never prefer flat shading on WebGL. GPU detection isn't as robust (e.g.
1039 // WEBGL_debug_renderer_info may not be enabled and strings may be masked), the perf benefits
1040 // are minimal, and potential cost is high (e.g. on ANGLE Metal backend).
1041 shaderCaps->fPreferFlatInterpolation = !GR_IS_GR_WEBGL(standard) &&
1042 shaderCaps->fFlatInterpolationSupport &&
1043 ctxInfo.vendor() != GrGLVendor::kQualcomm &&
1044 !angle_backend_is_d3d(ctxInfo.angleBackend()) &&
1045 !angle_backend_is_metal(ctxInfo.angleBackend());
1046 if (GR_IS_GR_GL(standard)) {
1047 shaderCaps->fNoPerspectiveInterpolationSupport =
1048 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
1049 } else if (GR_IS_GR_GL_ES(standard)) {
1050 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
1051 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es) {
1052 shaderCaps->fNoPerspectiveInterpolationSupport = true;
1053 shaderCaps->fNoPerspectiveInterpolationExtensionString =
1054 "GL_NV_shader_noperspective_interpolation";
1055 }
1056 } // Not sure for WebGL
1057
1058 if (GR_IS_GR_GL(standard)) {
1059 shaderCaps->fSampleMaskSupport = ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k400;
1060 } else if (GR_IS_GR_GL_ES(standard)) {
1061 if (ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k320es) {
1062 shaderCaps->fSampleMaskSupport = true;
1063 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
1064 shaderCaps->fSampleMaskSupport = true;
1065 shaderCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
1066 }
1067 }
1068
1069 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
1070 shaderCaps->fGLSLGeneration,
1071 fIsCoreProfile);
1072
1073 if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
1074 if (SkSL::GLSLGeneration::k100es == shaderCaps->fGLSLGeneration) {
1075 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
1076 }
1077 } // WebGL might have to check for OES_standard_derivatives
1078
1079 if (GR_IS_GR_GL_ES(standard)) {
1080 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
1081 }
1082
1083 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
1084 if (ctxInfo.glslGeneration() == SkSL::GLSLGeneration::k100es) {
1085 shaderCaps->fExternalTextureSupport = true;
1086 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
1087 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
1088 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
1089 // At least one driver has been found that has this extension without the "GL_" prefix.
1090 shaderCaps->fExternalTextureSupport = true;
1091 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
1092 }
1093 }
1094
1095 if (GR_IS_GR_GL(standard)) {
1096 shaderCaps->fVertexIDSupport = true;
1097 } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
1098 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
1099 }
1100
1101 // isinf() exists in GLSL 1.3 and above, but hardware without proper IEEE support is allowed to
1102 // always return false, so it's potentially meaningless. In GLSL 3.3 and GLSL ES3+, isinf() is
1103 // required to actually identify infinite values. (GPUs are not required to _produce_ infinite
1104 // values via operations like `num / 0.0` until GLSL 4.1.)
1105 shaderCaps->fInfinitySupport = (ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k330);
1106
1107 // Using isinf or isnan with ANGLE will disable fast-math (which is a good thing!), but that
1108 // leads to hangs in the Metal shader compiler service for some of our tessellation shaders,
1109 // running on Intel Macs. For now, pretend that we don't have infinity support, even when we're
1110 // targeting ANGLE's ES3 to Metal.
1111 if (ctxInfo.angleBackend() == GrGLANGLEBackend::kMetal &&
1112 ctxInfo.angleVendor() == GrGLVendor::kIntel) {
1113 shaderCaps->fInfinitySupport = false;
1114 }
1115
1116 if (GR_IS_GR_GL(standard)) {
1117 shaderCaps->fNonconstantArrayIndexSupport = true;
1118 } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
1119 shaderCaps->fNonconstantArrayIndexSupport =
1120 (ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es);
1121 }
1122
1123 if (GR_IS_GR_GL(standard)) {
1124 shaderCaps->fBitManipulationSupport =
1125 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k400;
1126 } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
1127 shaderCaps->fBitManipulationSupport =
1128 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k310es;
1129 }
1130
1131 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
1132 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
1133 shaderCaps->fHasLowFragmentPrecision = ctxInfo.renderer() == GrGLRenderer::kMali4xx;
1134
1135 if (GR_IS_GR_GL(standard)) {
1136 shaderCaps->fBuiltinFMASupport =
1137 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k400;
1138 } else if (GR_IS_GR_GL_ES(standard)) {
1139 shaderCaps->fBuiltinFMASupport =
1140 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k320es;
1141 } else if (GR_IS_GR_WEBGL(standard)) {
1142 shaderCaps->fBuiltinFMASupport = false;
1143 }
1144
1145 shaderCaps->fBuiltinDeterminantSupport = ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k150;
1146 }
1147
1148 void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions,
1149 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
1150 if (GR_IS_GR_GL(ctxInfo.standard())) {
1151 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1152 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
1153 fMSFBOType = kStandard_MSFBOType;
1154 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
1155 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
1156 fMSFBOType = kStandard_MSFBOType;
1157 }
1158 } else if (GR_IS_GR_GL_ES(ctxInfo.standard())) {
1159 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
1160 // ES3 driver bugs on at least one device with a tiled GPU (N10).
1161 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
1162 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
1163 fMSAAResolvesAutomatically = true;
1164 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
1165 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
1166 fMSAAResolvesAutomatically = true;
1167 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1168 fMSFBOType = kStandard_MSFBOType;
1169 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
1170 fMSFBOType = kStandard_MSFBOType;
1171 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
1172 fMSFBOType = kStandard_MSFBOType;
1173 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
1174 fMSFBOType = kES_Apple_MSFBOType;
1175 }
1176 } else if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
1177 // No support in WebGL 1, but there is for 2.0
1178 if (ctxInfo.version() >= GR_GL_VER(2,0)) {
1179 fMSFBOType = kStandard_MSFBOType;
1180 } else {
1181 fMSFBOType = kNone_MSFBOType;
1182 }
1183 }
1184 }
1185
1186 void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
1187 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
1188
1189 bool layoutQualifierSupport = false;
1190 if ((GR_IS_GR_GL(fStandard) && shaderCaps->fGLSLGeneration >= SkSL::GLSLGeneration::k140) ||
1191 (GR_IS_GR_GL_ES(fStandard) && shaderCaps->fGLSLGeneration >= SkSL::GLSLGeneration::k300es)){
1192 layoutQualifierSupport = true;
1193 } else if (GR_IS_GR_WEBGL(fStandard)) {
1194 return;
1195 }
1196
1197 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1198 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1199 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
1200 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
1201 layoutQualifierSupport) {
1202 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1203 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
1204 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1205 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1206 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
1207 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
1208 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1209 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
1210 }
1211 }
1212
1213
1214 void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
1215
1216 // Build up list of legal stencil formats (though perhaps not supported on
1217 // the particular gpu/driver) from most preferred to least.
1218
1219 // We push back stencil formats onto the fStencilFormats array in order of most preferred to
1220 // least preferred.
1221
1222 if (GR_IS_GR_GL(ctxInfo.standard())) {
1223 bool supportsPackedDS =
1224 ctxInfo.version() >= GR_GL_VER(3,0) ||
1225 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1226 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1227
1228 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1229 // require FBO support we can expect these are legal formats and don't
1230 // check.
1231 fStencilFormats.push_back() = GrGLFormat::kSTENCIL_INDEX8;
1232 fStencilFormats.push_back() = GrGLFormat::kSTENCIL_INDEX16;
1233 if (supportsPackedDS) {
1234 fStencilFormats.push_back() = GrGLFormat::kDEPTH24_STENCIL8;
1235 }
1236 } else if (GR_IS_GR_GL_ES(ctxInfo.standard())) {
1237 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1238 // for other formats.
1239
1240 fStencilFormats.push_back() = GrGLFormat::kSTENCIL_INDEX8;
1241 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1242 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
1243 fStencilFormats.push_back() = GrGLFormat::kDEPTH24_STENCIL8;
1244 }
1245 } else if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
1246 fStencilFormats.push_back() = GrGLFormat::kSTENCIL_INDEX8;
1247 if (ctxInfo.version() >= GR_GL_VER(2,0)) {
1248 fStencilFormats.push_back() = GrGLFormat::kDEPTH24_STENCIL8;
1249 }
1250 }
1251 }
1252
1253 #ifdef SK_ENABLE_DUMP_GPU
1254 #include "src/utils/SkJSONWriter.h"
1255
1256 static const char* multi_draw_type_name(GrGLCaps::MultiDrawType multiDrawType) {
1257 switch (multiDrawType) {
1258 case GrGLCaps::MultiDrawType::kNone : return "kNone";
1259 case GrGLCaps::MultiDrawType::kMultiDrawIndirect : return "kMultiDrawIndirect";
1260 case GrGLCaps::MultiDrawType::kANGLEOrWebGL : return "kMultiDrawIndirect";
1261 }
1262 SkUNREACHABLE;
1263 }
1264
1265 void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
1266
1267 // We are called by the base class, which has already called beginObject(). We choose to nest
1268 // all of our caps information in a named sub-object.
1269 writer->beginObject("GL caps");
1270
1271 writer->beginArray("Stencil Formats");
1272
1273 for (int i = 0; i < fStencilFormats.size(); ++i) {
1274 writer->beginObject(nullptr, false);
1275 writer->appendS32("stencil bits", GrGLFormatStencilBits(fStencilFormats[i]));
1276 writer->appendS32("total bytes", GrGLFormatBytesPerBlock(fStencilFormats[i]));
1277 writer->endObject();
1278 }
1279
1280 writer->endArray();
1281
1282 auto msfboStr = [&] {
1283 switch (fMSFBOType) {
1284 case kNone_MSFBOType: return "None";
1285 case kStandard_MSFBOType: return "Standard";
1286 case kES_Apple_MSFBOType: return "Apple";
1287 case kES_IMG_MsToTexture_MSFBOType: return "IMG MS To Texture";
1288 case kES_EXT_MsToTexture_MSFBOType: return "EXT MS To Texture";
1289 }
1290 SkUNREACHABLE;
1291 };
1292
1293 auto invalidateFBTypeStr = [&] {
1294 switch (fInvalidateFBType) {
1295 case kNone_InvalidateFBType: return "None";
1296 case kDiscard_InvalidateFBType: return "Discard";
1297 case kInvalidate_InvalidateFBType: return "Invalidate";
1298 }
1299 SkUNREACHABLE;
1300 };
1301
1302 auto invalidateBufferTypeStr = [&] {
1303 switch (fInvalidateBufferType) {
1304 case InvalidateBufferType::kNone: return "None";
1305 case InvalidateBufferType::kNullData: return "Null data hint";
1306 case InvalidateBufferType::kInvalidate: return "Invalidate";
1307 }
1308 SkUNREACHABLE;
1309 };
1310
1311 auto mapBufferTypeStr = [&] {
1312 switch (fMapBufferType) {
1313 case kNone_MapBufferType: return "None";
1314 case kMapBuffer_MapBufferType: return "MapBuffer";
1315 case kMapBufferRange_MapBufferType: return "MapBufferRange";
1316 case kChromium_MapBufferType: return "Chromium";
1317 }
1318 SkUNREACHABLE;
1319 };
1320
1321 writer->appendBool("Core Profile", fIsCoreProfile);
1322 writer->appendCString("MSAA Type", msfboStr());
1323 writer->appendCString("Invalidate FB Type", invalidateFBTypeStr());
1324 writer->appendCString("Invalidate Buffer Type", invalidateBufferTypeStr());
1325 writer->appendCString("Map Buffer Type", mapBufferTypeStr());
1326 writer->appendCString("Multi Draw Type", multi_draw_type_name(fMultiDrawType));
1327 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1328 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
1329
1330 writer->appendBool("Texture Usage support", fTextureUsageSupport);
1331 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1332 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
1333 writer->appendBool("Debug support", fDebugSupport);
1334 writer->appendBool("ES2 compatibility support", fES2CompatibilitySupport);
1335 writer->appendBool("Strict Protectedness", fStrictProtectedness);
1336 writer->appendBool("drawRangeElements support", fDrawRangeElementsSupport);
1337 writer->appendBool("Base (vertex base) instance support", fBaseVertexBaseInstanceSupport);
1338 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1339 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1340 writer->appendBool("Mipmap LOD control support", fMipmapLodControlSupport);
1341 writer->appendBool("Mipmap level control support", fMipmapLevelControlSupport);
1342 writer->appendBool("Clear texture support", fClearTextureSupport);
1343 writer->appendBool("Program binary support", fProgramBinarySupport);
1344 writer->appendBool("Program parameters support", fProgramParameterSupport);
1345 writer->appendBool("Sampler object support", fSamplerObjectSupport);
1346 writer->appendBool("Using sampler objects", fUseSamplerObjects);
1347 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1348 writer->appendBool("Tiled rendering support", fTiledRenderingSupport);
1349 writer->appendBool("Fence sync support", fFenceSyncSupport);
1350 writer->appendBool("FB fetch requires enable per sample", fFBFetchRequiresEnablePerSample);
1351 writer->appendBool("sRGB Write Control", fSRGBWriteControl);
1352
1353 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1354 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1355 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1356 fUseDrawInsteadOfAllRenderTargetWrites);
1357 writer->appendBool("Max instances per draw without crashing (or zero)",
1358 fMaxInstancesPerDrawWithoutCrashing);
1359
1360 writer->beginArray("formats");
1361
1362 for (int i = 0; i < kGrGLColorFormatCount; ++i) {
1363 writer->beginObject(nullptr, false);
1364 writer->appendHexU32("flags", fFormatTable[i].fFlags);
1365 writer->appendHexU32("f_type", (uint32_t)fFormatTable[i].fFormatType);
1366 writer->appendHexU32("c_internal", fFormatTable[i].fCompressedInternalFormat);
1367 writer->appendHexU32("i_for_teximage", fFormatTable[i].fInternalFormatForTexImageOrStorage);
1368 writer->appendHexU32("i_for_renderbuffer", fFormatTable[i].fInternalFormatForRenderbuffer);
1369 writer->appendHexU32("default_ex_format", fFormatTable[i].fDefaultExternalFormat);
1370 writer->appendHexU32("default_ex_type", fFormatTable[i].fDefaultExternalType);
1371 writer->appendHexU32("default_color_type", (uint32_t)fFormatTable[i].fDefaultColorType);
1372
1373 writer->beginArray("surface color types");
1374 for (int j = 0; j < fFormatTable[i].fColorTypeInfoCount; ++j) {
1375 const auto& ctInfo = fFormatTable[i].fColorTypeInfos[j];
1376 writer->beginObject(nullptr, false);
1377 writer->appendHexU32("colorType", (uint32_t)ctInfo.fColorType);
1378 writer->appendHexU32("flags", ctInfo.fFlags);
1379
1380 writer->beginArray("data color types");
1381 for (int k = 0; k < ctInfo.fExternalIOFormatCount; ++k) {
1382 const auto& ioInfo = ctInfo.fExternalIOFormats[k];
1383 writer->beginObject(nullptr, false);
1384 writer->appendHexU32("colorType", (uint32_t)ioInfo.fColorType);
1385 writer->appendHexU32("ex_type", ioInfo.fExternalType);
1386 writer->appendHexU32("ex_teximage", ioInfo.fExternalTexImageFormat);
1387 writer->appendHexU32("ex_read", ioInfo.fExternalReadFormat);
1388 writer->endObject();
1389 }
1390 writer->endArray();
1391 writer->endObject();
1392 }
1393 writer->endArray();
1394 writer->endObject();
1395 }
1396
1397 writer->endArray();
1398 writer->endObject();
1399 }
1400 #else
1401 void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const { }
1402 #endif
1403
1404 void GrGLCaps::getTexImageExternalFormatAndType(GrGLFormat surfaceFormat, GrGLenum* externalFormat,
1405 GrGLenum* externalType) const {
1406 const auto& info = this->getFormatInfo(surfaceFormat);
1407 *externalType = info.fDefaultExternalType;
1408 *externalFormat = info.fDefaultExternalFormat;
1409 }
1410
1411 void GrGLCaps::getTexSubImageDefaultFormatTypeAndColorType(GrGLFormat format,
1412 GrGLenum* externalFormat,
1413 GrGLenum* externalType,
1414 GrColorType* colorType) const {
1415 const auto& info = this->getFormatInfo(format);
1416 *externalType = info.fDefaultExternalType;
1417 *externalFormat = info.fDefaultExternalFormat;
1418 *colorType = info.fDefaultColorType;
1419 }
1420
1421 void GrGLCaps::getTexSubImageExternalFormatAndType(GrGLFormat surfaceFormat,
1422 GrColorType surfaceColorType,
1423 GrColorType memoryColorType,
1424 GrGLenum* externalFormat,
1425 GrGLenum* externalType) const {
1426 this->getExternalFormat(surfaceFormat, surfaceColorType, memoryColorType,
1427 kTexImage_ExternalFormatUsage, externalFormat, externalType);
1428 }
1429
1430 void GrGLCaps::getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType,
1431 GrColorType memoryColorType, GrGLenum* externalFormat,
1432 GrGLenum* externalType) const {
1433 this->getExternalFormat(surfaceFormat, surfaceColorType, memoryColorType,
1434 kReadPixels_ExternalFormatUsage, externalFormat, externalType);
1435 }
1436
1437 void GrGLCaps::getExternalFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType,
1438 GrColorType memoryColorType, ExternalFormatUsage usage,
1439 GrGLenum* externalFormat, GrGLenum* externalType) const {
1440 SkASSERT(externalFormat && externalType);
1441 *externalFormat = this->getFormatInfo(surfaceFormat).externalFormat(
1442 surfaceColorType, memoryColorType, usage);
1443 *externalType = this->getFormatInfo(surfaceFormat).externalType(
1444 surfaceColorType, memoryColorType);
1445 }
1446
1447 void GrGLCaps::setStencilFormatIndexForFormat(GrGLFormat format, int index) {
1448 SkASSERT(!this->hasStencilFormatBeenDeterminedForFormat(format));
1449 this->getFormatInfo(format).fStencilFormatIndex =
1450 index < 0 ? FormatInfo::kUnsupported_StencilFormatIndex : index;
1451 }
1452
1453 void GrGLCaps::setColorTypeFormat(GrColorType colorType, GrGLFormat format) {
1454 int idx = static_cast<int>(colorType);
1455 SkASSERT(fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown);
1456 fColorTypeToFormatTable[idx] = format;
1457 }
1458
1459 void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1460 const FormatWorkarounds& formatWorkarounds) {
1461 GrGLStandard standard = ctxInfo.standard();
1462 // standard can be unused (optimized away) if SK_ASSUME_GL_ES is set
1463 sk_ignore_unused_variable(standard);
1464 GrGLVersion version = ctxInfo.version();
1465
1466 uint32_t nonMSAARenderFlags = FormatInfo::kFBOColorAttachment_Flag;
1467 uint32_t msaaRenderFlags = nonMSAARenderFlags;
1468 if (kNone_MSFBOType != fMSFBOType) {
1469 msaaRenderFlags |= FormatInfo::kFBOColorAttachmentWithMSAA_Flag;
1470 }
1471
1472 bool texStorageSupported = false;
1473 if (GR_IS_GR_GL(standard)) {
1474 // The EXT version can apply to either GL or GLES.
1475 texStorageSupported = version >= GR_GL_VER(4,2) ||
1476 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1477 ctxInfo.hasExtension("GL_EXT_texture_storage");
1478 } else if (GR_IS_GR_GL_ES(standard)) {
1479 texStorageSupported = version >= GR_GL_VER(3,0) ||
1480 ctxInfo.hasExtension("GL_EXT_texture_storage");
1481 } else if (GR_IS_GR_WEBGL(standard)) {
1482 texStorageSupported = version >= GR_GL_VER(2,0);
1483 }
1484 if (fDriverBugWorkarounds.disable_texture_storage) {
1485 texStorageSupported = false;
1486 }
1487
1488 if (formatWorkarounds.fDisableTexStorage) {
1489 texStorageSupported = false;
1490 }
1491
1492 // ES 2.0 requires that the internal/external formats match so we can't use sized internal
1493 // formats for glTexImage until ES 3.0. TODO: Support sized internal formats in WebGL2.
1494 bool texImageSupportsSizedInternalFormat =
1495 (GR_IS_GR_GL(standard) || (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0)));
1496
1497 // for now we don't support floating point MSAA on ES
1498 uint32_t fpRenderFlags = (GR_IS_GR_GL(standard)) ? msaaRenderFlags : nonMSAARenderFlags;
1499
1500 for (int i = 0; i < kGrColorTypeCnt; ++i) {
1501 fColorTypeToFormatTable[i] = GrGLFormat::kUnknown;
1502 }
1503
1504 ///////////////////////////////////////////////////////////////////////////
1505
1506 GrGLenum halfFloatType = GR_GL_HALF_FLOAT;
1507 if ((GR_IS_GR_GL_ES(standard) && version < GR_GL_VER(3, 0)) ||
1508 (GR_IS_GR_WEBGL(standard) && version < GR_GL_VER(2, 0))) {
1509 halfFloatType = GR_GL_HALF_FLOAT_OES;
1510 }
1511
1512 // Format: RGBA8
1513 {
1514 FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA8);
1515 info.fFormatType = FormatType::kNormalizedFixedPoint;
1516 info.fInternalFormatForRenderbuffer = GR_GL_RGBA8;
1517 info.fDefaultExternalFormat = GR_GL_RGBA;
1518 info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
1519 info.fDefaultColorType = GrColorType::kRGBA_8888;
1520 info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
1521 if (GR_IS_GR_GL(standard)) {
1522 info.fFlags |= msaaRenderFlags;
1523 } else if (GR_IS_GR_GL_ES(standard)) {
1524 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1525 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1526 info.fFlags |= msaaRenderFlags;
1527 }
1528 } else if (GR_IS_GR_WEBGL(standard)) {
1529 info.fFlags |= msaaRenderFlags;
1530 }
1531
1532 if (texStorageSupported) {
1533 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
1534 info.fInternalFormatForTexImageOrStorage = GR_GL_RGBA8;
1535 } else {
1536 info.fInternalFormatForTexImageOrStorage =
1537 texImageSupportsSizedInternalFormat ? GR_GL_RGBA8 : GR_GL_RGBA;
1538 }
1539
1540 bool supportsBGRAColorType = GR_IS_GR_GL(standard) &&
1541 (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra"));
1542 info.fColorTypeInfoCount = supportsBGRAColorType ? 3 : 2;
1543 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
1544 int ctIdx = 0;
1545 // Format: RGBA8, Surface: kRGBA_8888
1546 {
1547 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1548 ctInfo.fColorType = GrColorType::kRGBA_8888;
1549 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1550 this->setColorTypeFormat(GrColorType::kRGBA_8888, GrGLFormat::kRGBA8);
1551
1552 // External IO ColorTypes:
1553 ctInfo.fExternalIOFormatCount = 2;
1554 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1555 ctInfo.fExternalIOFormatCount);
1556 int ioIdx = 0;
1557 // Format: RGBA8, Surface: kRGBA_8888, Data: kRGBA_8888
1558 {
1559 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1560 ioFormat.fColorType = GrColorType::kRGBA_8888;
1561 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1562 ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
1563 ioFormat.fExternalReadFormat = GR_GL_RGBA;
1564 }
1565 // Format: RGBA8, Surface: kRGBA_8888, Data: kBGRA_8888
1566 {
1567 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1568 ioFormat.fColorType = GrColorType::kBGRA_8888;
1569 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1570 ioFormat.fExternalTexImageFormat = 0; // TODO: Enable this on non-ES GL
1571 ioFormat.fExternalReadFormat =
1572 formatWorkarounds.fDisallowBGRA8ReadPixels ? 0 : GR_GL_BGRA;
1573 // Not guaranteed by ES/WebGL.
1574 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1575 }
1576 }
1577
1578 // Format: RGBA8, Surface: kBGRA_8888
1579 if (supportsBGRAColorType) {
1580 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1581 ctInfo.fColorType = GrColorType::kBGRA_8888;
1582 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1583 this->setColorTypeFormat(GrColorType::kBGRA_8888, GrGLFormat::kRGBA8);
1584
1585 // External IO ColorTypes:
1586 ctInfo.fExternalIOFormatCount = 2;
1587 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1588 ctInfo.fExternalIOFormatCount);
1589 int ioIdx = 0;
1590 // Format: RGBA8, Surface: kBGRA_8888, Data: kBGRA_8888
1591 {
1592 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1593 ioFormat.fColorType = GrColorType::kBGRA_8888;
1594 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1595 ioFormat.fExternalTexImageFormat = GR_GL_BGRA;
1596 ioFormat.fExternalReadFormat =
1597 formatWorkarounds.fDisallowBGRA8ReadPixels ? 0 : GR_GL_BGRA;
1598 // Not guaranteed by ES/WebGL.
1599 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1600 }
1601
1602 // Format: RGBA8, Surface: kBGRA_8888, Data: kRGBA_8888
1603 {
1604 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1605 ioFormat.fColorType = GrColorType::kRGBA_8888;
1606 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1607 ioFormat.fExternalTexImageFormat = 0;
1608 ioFormat.fExternalReadFormat = GR_GL_RGBA;
1609 }
1610 }
1611
1612 // Format: RGBA8, Surface: kRGB_888x
1613 {
1614 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1615 ctInfo.fColorType = GrColorType::kRGB_888x;
1616 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
1617 ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1();
1618
1619 // External IO ColorTypes:
1620 ctInfo.fExternalIOFormatCount = 1;
1621 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1622 ctInfo.fExternalIOFormatCount);
1623 int ioIdx = 0;
1624 // Format: RGBA8, Surface: kRGB_888x, Data: kRGBA_888x
1625 {
1626 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1627 ioFormat.fColorType = GrColorType::kRGB_888x;
1628 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1629 ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
1630 ioFormat.fExternalReadFormat = GR_GL_RGBA;
1631 }
1632 }
1633 }
1634
1635 // Format: R8
1636 {
1637 FormatInfo& info = this->getFormatInfo(GrGLFormat::kR8);
1638 info.fFormatType = FormatType::kNormalizedFixedPoint;
1639 info.fInternalFormatForRenderbuffer = GR_GL_R8;
1640 info.fDefaultExternalFormat = GR_GL_RED;
1641 info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
1642 info.fDefaultColorType = GrColorType::kR_8;
1643 bool r8Support = false;
1644 if (GR_IS_GR_GL(standard)) {
1645 r8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1646 } else if (GR_IS_GR_GL_ES(standard)) {
1647 r8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1648 } else if (GR_IS_GR_WEBGL(standard)) {
1649 r8Support = ctxInfo.version() >= GR_GL_VER(2, 0);
1650 }
1651 if (formatWorkarounds.fDisallowR8ForPowerVRSGX54x) {
1652 r8Support = false;
1653 }
1654
1655 if (r8Support) {
1656 info.fFlags |= FormatInfo::kTexturable_Flag
1657 | FormatInfo::kTransfers_Flag
1658 | msaaRenderFlags;
1659 }
1660
1661 if (texStorageSupported) {
1662 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
1663 info.fInternalFormatForTexImageOrStorage = GR_GL_R8;
1664 } else {
1665 info.fInternalFormatForTexImageOrStorage =
1666 texImageSupportsSizedInternalFormat ? GR_GL_R8 : GR_GL_RED;
1667 }
1668
1669 if (r8Support) {
1670 info.fColorTypeInfoCount = 3;
1671 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
1672 int ctIdx = 0;
1673 // Format: R8, Surface: kR_8
1674 {
1675 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1676 ctInfo.fColorType = GrColorType::kR_8;
1677 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1678 this->setColorTypeFormat(GrColorType::kR_8, GrGLFormat::kR8);
1679
1680 // External IO ColorTypes:
1681 ctInfo.fExternalIOFormatCount = 2;
1682 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1683 ctInfo.fExternalIOFormatCount);
1684 int ioIdx = 0;
1685 // Format: R8, Surface: kR_8, Data: kR_8
1686 {
1687 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1688 ioFormat.fColorType = GrColorType::kR_8;
1689 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1690 ioFormat.fExternalTexImageFormat = GR_GL_RED;
1691 ioFormat.fExternalReadFormat = GR_GL_RED;
1692 // Not guaranteed by ES/WebGL.
1693 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1694 }
1695
1696 // Format: R8, Surface: kR_8, Data: kR_8xxx
1697 {
1698 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1699 ioFormat.fColorType = GrColorType::kR_8xxx;
1700 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1701 ioFormat.fExternalTexImageFormat = 0;
1702 ioFormat.fExternalReadFormat = GR_GL_RGBA;
1703 }
1704 }
1705
1706 // Format: R8, Surface: kAlpha_8
1707 {
1708 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1709 ctInfo.fColorType = GrColorType::kAlpha_8;
1710 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1711 ctInfo.fReadSwizzle = skgpu::Swizzle("000r");
1712 ctInfo.fWriteSwizzle = skgpu::Swizzle("a000");
1713 this->setColorTypeFormat(GrColorType::kAlpha_8, GrGLFormat::kR8);
1714
1715 // External IO ColorTypes:
1716 ctInfo.fExternalIOFormatCount = 2;
1717 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1718 ctInfo.fExternalIOFormatCount);
1719 int ioIdx = 0;
1720 // Format: R8, Surface: kAlpha_8, Data: kAlpha_8
1721 {
1722 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1723 ioFormat.fColorType = GrColorType::kAlpha_8;
1724 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1725 ioFormat.fExternalTexImageFormat = GR_GL_RED;
1726 ioFormat.fExternalReadFormat = GR_GL_RED;
1727 // Not guaranteed by ES/WebGL.
1728 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1729 }
1730
1731 // Format: R8, Surface: kAlpha_8, Data: kAlpha_8xxx
1732 {
1733 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1734 ioFormat.fColorType = GrColorType::kAlpha_8xxx;
1735 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1736 ioFormat.fExternalTexImageFormat = 0;
1737 ioFormat.fExternalReadFormat = GR_GL_RGBA;
1738 }
1739 }
1740
1741 // Format: R8, Surface: kGray_8
1742 {
1743 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1744 ctInfo.fColorType = GrColorType::kGray_8;
1745 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
1746 ctInfo.fReadSwizzle = skgpu::Swizzle("rrr1");
1747 this->setColorTypeFormat(GrColorType::kGray_8, GrGLFormat::kR8);
1748
1749 // External IO ColorTypes:
1750 ctInfo.fExternalIOFormatCount = 2;
1751 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1752 ctInfo.fExternalIOFormatCount);
1753 int ioIdx = 0;
1754 // Format: R8, Surface: kGray_8, Data: kGray_8
1755 {
1756 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1757 ioFormat.fColorType = GrColorType::kGray_8;
1758 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1759 ioFormat.fExternalTexImageFormat = GR_GL_RED;
1760 ioFormat.fExternalReadFormat = GR_GL_RED;
1761 // Not guaranteed by ES/WebGL.
1762 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1763 }
1764
1765 // Format: R8, Surface: kGray_8, Data: kGray_8xxx
1766 {
1767 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1768 ioFormat.fColorType = GrColorType::kGray_8xxx;
1769 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1770 ioFormat.fExternalTexImageFormat = 0;
1771 ioFormat.fExternalReadFormat = GR_GL_RGBA;
1772 }
1773 }
1774 }
1775 }
1776
1777 // Format: ALPHA8
1778 {
1779 bool alpha8IsValidForGL = GR_IS_GR_GL(standard) &&
1780 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1781 bool alpha8IsValidForGLES = GR_IS_GR_GL_ES(standard);
1782 bool alpha8IsValidForWebGL = GR_IS_GR_WEBGL(standard);
1783
1784 FormatInfo& info = this->getFormatInfo(GrGLFormat::kALPHA8);
1785 info.fFormatType = FormatType::kNormalizedFixedPoint;
1786 // GL_EXT_texture_storage adds GL_ALPHA8 for texture storage. However, ES3 has glTexStorage
1787 // but does not have GL_ALPHA8 (and requires a sized internal format for glTexStorage).
1788 // WebGL never has GL_ALPHA8.
1789 bool alpha8SizedEnumSupported =
1790 alpha8IsValidForGL ||
1791 (alpha8IsValidForGLES && ctxInfo.hasExtension("GL_EXT_texture_storage"));
1792 bool alpha8TexStorageSupported = alpha8SizedEnumSupported && texStorageSupported;
1793
1794 bool alpha8IsRenderable = false;
1795 if (alpha8IsValidForGL) {
1796 // Core profile removes ALPHA8 support.
1797 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
1798 alpha8IsRenderable = ctxInfo.version() >= GR_GL_VER(3, 0) ||
1799 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1800 }
1801 info.fInternalFormatForRenderbuffer = GR_GL_ALPHA8;
1802 info.fDefaultExternalFormat = GR_GL_ALPHA;
1803 info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
1804 info.fDefaultColorType = GrColorType::kAlpha_8;
1805 if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
1806 info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
1807 }
1808 if (alpha8IsRenderable && alpha8IsValidForGL) {
1809 // We will use ALPHA8 to create MSAA renderbuffers.
1810 SkASSERT(alpha8SizedEnumSupported);
1811 info.fFlags |= msaaRenderFlags;
1812 }
1813 if (alpha8TexStorageSupported) {
1814 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
1815 info.fInternalFormatForTexImageOrStorage = GR_GL_ALPHA8;
1816 } else {
1817 // Even if GL_ALPHA8 is added to ES by GL_EXT_texture_storage it doesn't become legal
1818 // for glTexImage2D.
1819 if (!GR_IS_GR_GL_ES(standard) && texImageSupportsSizedInternalFormat &&
1820 alpha8SizedEnumSupported) {
1821 info.fInternalFormatForTexImageOrStorage = GR_GL_ALPHA8;
1822 } else {
1823 info.fInternalFormatForTexImageOrStorage = GR_GL_ALPHA;
1824 }
1825 }
1826
1827 if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
1828 info.fColorTypeInfoCount = 1;
1829 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
1830 int ctIdx = 0;
1831 // Format: ALPHA8, Surface: kAlpha_8
1832 {
1833 if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
1834 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1835 ctInfo.fColorType = GrColorType::kAlpha_8;
1836 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag |
1837 ColorTypeInfo::kRenderable_Flag;
1838 int idx = static_cast<int>(GrColorType::kAlpha_8);
1839 if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
1840 this->setColorTypeFormat(GrColorType::kAlpha_8, GrGLFormat::kALPHA8);
1841 }
1842
1843 // External IO ColorTypes:
1844 ctInfo.fExternalIOFormatCount = 2;
1845 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1846 ctInfo.fExternalIOFormatCount);
1847 int ioIdx = 0;
1848 // Format: ALPHA8, Surface: kAlpha_8, Data: kAlpha_8
1849 {
1850 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1851 ioFormat.fColorType = GrColorType::kAlpha_8;
1852 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1853 ioFormat.fExternalTexImageFormat = GR_GL_ALPHA;
1854 ioFormat.fExternalReadFormat = GR_GL_ALPHA;
1855 // Not guaranteed by ES/WebGL.
1856 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1857 }
1858
1859 // Format: ALPHA8, Surface: kAlpha_8, Data: kRGBA_8888
1860 {
1861 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1862 ioFormat.fColorType = GrColorType::kRGBA_8888;
1863 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1864 ioFormat.fExternalTexImageFormat = 0;
1865 ioFormat.fExternalReadFormat = GR_GL_RGBA;
1866 }
1867 }
1868 }
1869 }
1870 }
1871
1872 // Do we support the lumincance and luminance_alpha formats
1873 bool lum8Supported = false;
1874 bool lum8SizedFormatSupported = false;
1875 if (GR_IS_GR_GL(standard) && !fIsCoreProfile) {
1876 lum8Supported = true;
1877 lum8SizedFormatSupported = true;
1878 } else if (GR_IS_GR_GL_ES(standard)) {
1879 lum8Supported = true;
1880 // Even on ES3 this extension is required to define LUMINANCE8. GL_LUMINANCE8 is not a
1881 // valid internal format for TexImage2D so we need to be using texture storage to use
1882 // it. Even though we check the extension for texture storage here, we also check to see
1883 // if texStorageSupported may have been disabled for a workaround.
1884 lum8SizedFormatSupported =
1885 texStorageSupported && ctxInfo.hasExtension("GL_EXT_texture_storage");
1886 } else if (GR_IS_GR_WEBGL(standard)) {
1887 lum8Supported = true;
1888 }
1889
1890 // Format: LUMINANCE8
1891 {
1892 FormatInfo& info = this->getFormatInfo(GrGLFormat::kLUMINANCE8);
1893 info.fFormatType = FormatType::kNormalizedFixedPoint;
1894 info.fInternalFormatForRenderbuffer = GR_GL_LUMINANCE8;
1895 info.fDefaultExternalFormat = GR_GL_LUMINANCE;
1896 info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
1897 info.fDefaultColorType = GrColorType::kGray_8;
1898
1899 if (lum8Supported) {
1900 info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
1901 }
1902 if (texStorageSupported && lum8SizedFormatSupported) {
1903 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
1904 info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE8;
1905 } else if (texImageSupportsSizedInternalFormat && lum8SizedFormatSupported) {
1906 info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE8;
1907 } else {
1908 info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE;
1909 }
1910 // We are not enabling attaching to an FBO for LUMINANCE8 mostly because of confusion in the
1911 // spec. For GLES it does not seem to ever support LUMINANCE8 being color-renderable. For GL
1912 // versions less than 3.0 it is provided by GL_ARB_framebuffer_object. However, the original
1913 // version of that extension did not add LUMINANCE8, but was added in a later revsion. So
1914 // even the presence of that extension does not guarantee support. GL 3.0 and higher (core
1915 // or compatibility) do not list LUMINANCE8 as color-renderable (which is strange since the
1916 // GL_ARB_framebuffer_object extension was meant to bring 3.0 functionality to lower
1917 // versions).
1918
1919 if (lum8Supported) {
1920 info.fColorTypeInfoCount = 1;
1921 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
1922 int ctIdx = 0;
1923 // Format: LUMINANCE8, Surface: kGray_8
1924 {
1925 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1926 ctInfo.fColorType = GrColorType::kGray_8;
1927 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
1928 int idx = static_cast<int>(GrColorType::kGray_8);
1929 if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
1930 this->setColorTypeFormat(GrColorType::kGray_8, GrGLFormat::kLUMINANCE8);
1931 }
1932
1933 // External IO ColorTypes:
1934 ctInfo.fExternalIOFormatCount = 2;
1935 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1936 ctInfo.fExternalIOFormatCount);
1937 int ioIdx = 0;
1938 // Format: LUMINANCE8, Surface: kGray_8, Data: kGray_8
1939 {
1940 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1941 ioFormat.fColorType = GrColorType::kGray_8;
1942 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1943 ioFormat.fExternalTexImageFormat = GR_GL_LUMINANCE;
1944 ioFormat.fExternalReadFormat = 0;
1945 }
1946
1947 // Format: LUMINANCE8, Surface: kGray_8, Data: kRGBA_8888
1948 {
1949 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1950 ioFormat.fColorType = GrColorType::kRGBA_8888;
1951 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1952 ioFormat.fExternalTexImageFormat = 0;
1953 ioFormat.fExternalReadFormat = GR_GL_RGBA;
1954 }
1955 }
1956 }
1957 }
1958
1959 // Format: LUMINANCE8_ALPHA8
1960 {
1961 FormatInfo& info = this->getFormatInfo(GrGLFormat::kLUMINANCE8_ALPHA8);
1962 info.fFormatType = FormatType::kNormalizedFixedPoint;
1963 info.fInternalFormatForRenderbuffer = GR_GL_LUMINANCE8_ALPHA8;
1964 info.fDefaultExternalFormat = GR_GL_LUMINANCE_ALPHA;
1965 info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
1966 info.fDefaultColorType = GrColorType::kGrayAlpha_88;
1967 if (lum8Supported) {
1968 info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
1969 }
1970 if (texStorageSupported && lum8SizedFormatSupported) {
1971 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
1972 info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE8_ALPHA8;
1973 } else if (texImageSupportsSizedInternalFormat && lum8SizedFormatSupported) {
1974 info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE8_ALPHA8;
1975 } else {
1976 info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE_ALPHA;
1977 }
1978 // See note in LUMINANCE8 section about not attaching to framebuffers.
1979
1980 if (lum8Supported) {
1981 info.fColorTypeInfoCount = 1;
1982 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
1983 int ctIdx = 0;
1984 // Format: LUMINANCE8_ALPHA8, Surface: kGrayAlpha_88
1985 {
1986 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1987 ctInfo.fColorType = GrColorType::kGrayAlpha_88;
1988 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
1989 int idx = static_cast<int>(GrColorType::kGrayAlpha_88);
1990 if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
1991 this->setColorTypeFormat(GrColorType::kGrayAlpha_88,
1992 GrGLFormat::kLUMINANCE8_ALPHA8);
1993 }
1994
1995 // External IO ColorTypes:
1996 ctInfo.fExternalIOFormatCount = 2;
1997 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1998 ctInfo.fExternalIOFormatCount);
1999 int ioIdx = 0;
2000 // Format: LUMINANCE8, Surface: kGrayAlpha_88, Data: kGrayAlpha_88
2001 {
2002 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2003 ioFormat.fColorType = GrColorType::kGrayAlpha_88;
2004 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2005 ioFormat.fExternalTexImageFormat = GR_GL_LUMINANCE_ALPHA;
2006 ioFormat.fExternalReadFormat = 0;
2007 }
2008
2009 // Format: LUMINANCE8, Surface: kGrayAlpha_88, Data: kRGBA_8888
2010 {
2011 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2012 ioFormat.fColorType = GrColorType::kRGBA_8888;
2013 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2014 ioFormat.fExternalTexImageFormat = 0;
2015 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2016 }
2017 }
2018 }
2019 }
2020 // Format: BGRA8
2021 {
2022 FormatInfo& info = this->getFormatInfo(GrGLFormat::kBGRA8);
2023 info.fFormatType = FormatType::kNormalizedFixedPoint;
2024
2025 info.fDefaultExternalFormat = GR_GL_BGRA;
2026 info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
2027 info.fDefaultColorType = GrColorType::kBGRA_8888;
2028
2029 GrGLenum bgraTexImageFormat;
2030 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
2031 // as a base format. Which base format depends on which extension is used.
2032 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
2033 // GL_EXT_texture_format_BGRA8888:
2034 // This extension adds GL_BGRA as an unsized internal format. However, it is
2035 // written against ES 2.0 and therefore doesn't define a GL_BGRA8 as ES 2.0 doesn't
2036 // have sized internal formats. See later where we check for tex storage BGRA8
2037 // support.
2038 bgraTexImageFormat = GR_GL_BGRA;
2039 } else {
2040 // GL_APPLE_texture_format_BGRA8888:
2041 // ES 2.0: the extension makes BGRA an external format but not an internal format.
2042 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format
2043 // for glTexImage (just for glTexStorage).
2044 bgraTexImageFormat = GR_GL_RGBA;
2045 }
2046
2047 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have
2048 // the GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texture_storage and
2049 // GL_EXT_texture_format_BGRA8888.
2050 bool supportsBGRATexStorage = false;
2051
2052 if (GR_IS_GR_GL_ES(standard)) {
2053 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
2054 // The GL_EXT_texture_format_BGRA8888 extension adds BGRA color renderbuffer support
2055 // for ES 2.0. The extension adds BGRA to the supported renerable formats in table
2056 // 4.5. In ES 2.0. All the extensions that add multisample support, all reference
2057 // table 4.5 as the formats that are supported. Thus we can use msaaRenderFlags.
2058 // Additionally, the renderable support was added in a later revision of the
2059 // extension. So it is possible for older drivers to support the extension but only
2060 // an early revision of it without renderable support. We have no way of
2061 // distinguishing between the two and assume renderable.
2062
2063
2064 info.fFlags = FormatInfo::kTexturable_Flag
2065 | FormatInfo::kTransfers_Flag;
2066 // Only enable BGRA msaa if we know we're going through Angle. The spec for
2067 // GL_EXT_texture_format_BGRA8888 was updated in 2016 to add support for GL_BGRA_EXT
2068 // as a sized, renderable format. But we may end up running on old drivers written
2069 // against earlier version of the spec. Also the interactions between all these
2070 // extensions are very suibtle and it wouldn't be hard for a driver to mess them up.
2071 // We are confident that Angle does it as we expect. Our non-angle test bots do seem
2072 // to pass and draw correctly so we could consider enabling this more broadly in the
2073 // future.
2074 // In addition, we also need to disable BGRA MSAA on Mesa. When a client attempts
2075 // to wrap a GPU-backed texture into an SkSurface with MSAA, Ganesh will create
2076 // a MSAA renderbuffer to first render to before resolving to the single-sampled
2077 // texture. Mesa claims to support EXT_texture_format_BGRA8888, and according to
2078 // the spec, this should imply support for both BGRA textures and renderbuffers.
2079 // In practice, however, Mesa only supports BGRA textures and will error on
2080 // glRenderbufferStorage* if the internalformat is BGRA.
2081 if (ctxInfo.angleBackend() != GrGLANGLEBackend::kUnknown &&
2082 ctxInfo.angleDriver() != GrGLDriver::kMesa) {
2083 // Angle incorrectly requires GL_BGRA8_EXT for the interalFormat for both ES2
2084 // and ES3 even though this extension does not define that value. The extension
2085 // only defines GL_BGRA_EXT as an internal format.
2086 info.fInternalFormatForRenderbuffer = GR_GL_BGRA8;
2087 info.fFlags |= msaaRenderFlags;
2088 } else {
2089 // It is not clear what the correct format to use on ES3 is. This extension only
2090 // defines GL_BGRA_EXT. That is definitely the correct thing to use on ES2, but
2091 // its unclear whether that is valid in ES3 or if it wants something like
2092 // GL_BGRA8_EXT (which is only defined in the apple extenstion). For now we set
2093 // everything to use BGRA since its the only explicitly defined value. Until we
2094 // enable MSAA for non-angle this is a moot point.
2095 info.fInternalFormatForRenderbuffer = GR_GL_BGRA;
2096 info.fFlags |= nonMSAARenderFlags;
2097 }
2098 // GL_EXT_texture storage has defined interactions with
2099 // GL_EXT_texture_format_BGRA8888. However, ES3 supports glTexStorage but
2100 // without GL_EXT_texture_storage it does not allow the BGRA8 sized internal format.
2101 if (ctxInfo.hasExtension("GL_EXT_texture_storage") &&
2102 !formatWorkarounds.fDisableBGRATextureStorageForIntelWindowsES) {
2103 supportsBGRATexStorage = true;
2104 }
2105 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
2106 // This APPLE extension introduces complexity on ES2. It leaves the internal format
2107 // as RGBA, but allows BGRA as the external format. From testing, it appears that
2108 // the driver remembers the external format when the texture is created (with
2109 // TexImage). If you then try to upload data in the other swizzle (with
2110 // TexSubImage), it fails. We could work around this, but it adds even more state
2111 // tracking to code that is already too tricky. Instead, we opt not to support BGRA
2112 // on ES2 with this extension. This also side-steps some ambiguous interactions with
2113 // the texture storage extension.
2114 if (version >= GR_GL_VER(3,0)) {
2115 // The APPLE extension doesn't explicitly make this renderable, but
2116 // internally it appears to use RGBA8, which we'll patch up below.
2117 info.fFlags = FormatInfo::kTexturable_Flag
2118 | FormatInfo::kTransfers_Flag
2119 | msaaRenderFlags;
2120 // The GL_APPLE_texture_format_BGRA8888 does not add support for BGRA color
2121 // renderbuffers at all so we use RGBA here.
2122 info.fInternalFormatForRenderbuffer = GR_GL_RGBA8;
2123 supportsBGRATexStorage = true;
2124 }
2125 }
2126 }
2127 if (texStorageSupported && supportsBGRATexStorage) {
2128 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2129 info.fInternalFormatForTexImageOrStorage = GR_GL_BGRA8;
2130 } else {
2131 info.fInternalFormatForTexImageOrStorage = bgraTexImageFormat;
2132 }
2133
2134 if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
2135 info.fColorTypeInfoCount = 2;
2136 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2137 int ctIdx = 0;
2138 // Format: BGRA8, Surface: kBGRA_8888
2139 {
2140 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2141 ctInfo.fColorType = GrColorType::kBGRA_8888;
2142 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2143 this->setColorTypeFormat(GrColorType::kBGRA_8888, GrGLFormat::kBGRA8);
2144
2145 // External IO ColorTypes:
2146 ctInfo.fExternalIOFormatCount = 2;
2147 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2148 ctInfo.fExternalIOFormatCount);
2149 int ioIdx = 0;
2150 // Format: BGRA8, Surface: kBGRA_8888, Data: kBGRA_8888
2151 {
2152 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2153 ioFormat.fColorType = GrColorType::kBGRA_8888;
2154 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2155 ioFormat.fExternalTexImageFormat = GR_GL_BGRA;
2156 ioFormat.fExternalReadFormat = 0;
2157 ioFormat.fExternalReadFormat =
2158 formatWorkarounds.fDisallowBGRA8ReadPixels ? 0 : GR_GL_BGRA;
2159 // Not guaranteed by ES/WebGL.
2160 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2161 }
2162
2163 // Format: BGRA8, Surface: kBGRA_8888, Data: kRGBA_8888
2164 {
2165 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2166 ioFormat.fColorType = GrColorType::kRGBA_8888;
2167 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2168 ioFormat.fExternalTexImageFormat = 0;
2169 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2170 }
2171 }
2172
2173 // Format: BGRA8, Surface: kRGB_888x
2174 {
2175 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2176 ctInfo.fColorType = GrColorType::kRGB_888x;
2177 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
2178 ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1();
2179
2180 // External IO ColorTypes:
2181 ctInfo.fExternalIOFormatCount = 1;
2182 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2183 ctInfo.fExternalIOFormatCount);
2184 int ioIdx = 0;
2185 // Format: BGRA8, Surface: kRGB_888x, Data: kRGBA_888x
2186 {
2187 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2188 ioFormat.fColorType = GrColorType::kRGB_888x;
2189 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2190 ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2191 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2192 }
2193 }
2194 }
2195 }
2196
2197 // Format: RGB565
2198 {
2199 FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB565);
2200 info.fFormatType = FormatType::kNormalizedFixedPoint;
2201 info.fInternalFormatForRenderbuffer = GR_GL_RGB565;
2202 info.fDefaultExternalFormat = GR_GL_RGB;
2203 info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
2204 info.fDefaultColorType = GrColorType::kBGR_565;
2205 if (GR_IS_GR_GL(standard)) {
2206 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
2207 info.fFlags = FormatInfo::kTexturable_Flag
2208 | FormatInfo::kTransfers_Flag
2209 | msaaRenderFlags;
2210 }
2211 } else if (GR_IS_GR_GL_ES(standard)) {
2212 info.fFlags = FormatInfo::kTexturable_Flag
2213 | FormatInfo::kTransfers_Flag
2214 | msaaRenderFlags;
2215 } else if (GR_IS_GR_WEBGL(standard)) {
2216 info.fFlags = FormatInfo::kTexturable_Flag
2217 | FormatInfo::kTransfers_Flag
2218 | msaaRenderFlags;
2219 }
2220 // 565 is not a sized internal format on desktop GL. So on desktop with
2221 // 565 we always use an unsized internal format to let the system pick
2222 // the best sized format to convert the 565 data to. Since TexStorage
2223 // only allows sized internal formats we disallow it.
2224 //
2225 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
2226 // update.
2227 if (texStorageSupported && GR_IS_GR_GL_ES(standard)) {
2228 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2229 info.fInternalFormatForTexImageOrStorage = GR_GL_RGB565;
2230 } else {
2231 info.fInternalFormatForTexImageOrStorage =
2232 texImageSupportsSizedInternalFormat ? GR_GL_RGB565 : GR_GL_RGB;
2233 }
2234
2235 if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) {
2236 info.fColorTypeInfoCount = 1;
2237 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2238 int ctIdx = 0;
2239 // Format: RGB565, Surface: kBGR_565
2240 {
2241 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2242 ctInfo.fColorType = GrColorType::kBGR_565;
2243 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2244 this->setColorTypeFormat(GrColorType::kBGR_565, GrGLFormat::kRGB565);
2245
2246 // External IO ColorTypes:
2247 ctInfo.fExternalIOFormatCount = 2;
2248 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2249 ctInfo.fExternalIOFormatCount);
2250 int ioIdx = 0;
2251 // Format: RGB565, Surface: kBGR_565, Data: kBGR_565
2252 {
2253 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2254 ioFormat.fColorType = GrColorType::kBGR_565;
2255 ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
2256 ioFormat.fExternalTexImageFormat = GR_GL_RGB;
2257 ioFormat.fExternalReadFormat = GR_GL_RGB;
2258 // Not guaranteed by ES/WebGL.
2259 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2260 }
2261
2262 // Format: RGB565, Surface: kBGR_565, Data: kRGBA_8888
2263 {
2264 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2265 ioFormat.fColorType = GrColorType::kRGBA_8888;
2266 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2267 ioFormat.fExternalTexImageFormat = 0;
2268 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2269 }
2270 }
2271 }
2272 }
2273
2274 // Format: RGBA16F
2275 {
2276 FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA16F);
2277 info.fFormatType = FormatType::kFloat;
2278 info.fInternalFormatForRenderbuffer = GR_GL_RGBA16F;
2279 info.fDefaultExternalFormat = GR_GL_RGBA;
2280 info.fDefaultExternalType = halfFloatType;
2281 info.fDefaultColorType = GrColorType::kRGBA_F16;
2282 bool rgba16FTextureSupport = false;
2283 bool rgba16FRenderTargetSupport = false;
2284
2285 if (GR_IS_GR_GL(standard)) {
2286 if (version >= GR_GL_VER(3, 0)) {
2287 rgba16FTextureSupport = true;
2288 rgba16FRenderTargetSupport = true;
2289 } else if (ctxInfo.hasExtension("GL_ARB_texture_float")) {
2290 rgba16FTextureSupport = true;
2291 }
2292 } else if (GR_IS_GR_GL_ES(standard)) {
2293 if (version >= GR_GL_VER(3, 0)) {
2294 rgba16FTextureSupport = true;
2295 rgba16FRenderTargetSupport =
2296 version >= GR_GL_VER(3, 2) ||
2297 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") ||
2298 ctxInfo.hasExtension("GL_EXT_color_buffer_float");
2299 } else if (ctxInfo.hasExtension("GL_OES_texture_half_float") &&
2300 ctxInfo.hasExtension("GL_OES_texture_half_float_linear")) {
2301 rgba16FTextureSupport = true;
2302 rgba16FRenderTargetSupport = ctxInfo.hasExtension("GL_EXT_color_buffer_half_float");
2303 }
2304 } else if (GR_IS_GR_WEBGL(standard)) {
2305 if (version >= GR_GL_VER(2, 0)) {
2306 rgba16FTextureSupport = true;
2307 rgba16FRenderTargetSupport =
2308 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") ||
2309 ctxInfo.hasExtension("EXT_color_buffer_half_float") ||
2310 ctxInfo.hasExtension("GL_EXT_color_buffer_float") ||
2311 ctxInfo.hasExtension("EXT_color_buffer_float");
2312 } else if ((ctxInfo.hasExtension("GL_OES_texture_half_float") ||
2313 ctxInfo.hasExtension("OES_texture_half_float")) &&
2314 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") ||
2315 ctxInfo.hasExtension("OES_texture_half_float_linear"))) {
2316 rgba16FTextureSupport = true;
2317 // We don't check for EXT_color_buffer_float as it's only defined for WebGL 2.
2318 rgba16FRenderTargetSupport =
2319 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") ||
2320 ctxInfo.hasExtension("EXT_color_buffer_half_float");
2321 }
2322 }
2323
2324 if (rgba16FTextureSupport) {
2325 info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2326 if (rgba16FRenderTargetSupport) {
2327 info.fFlags |= fpRenderFlags;
2328 }
2329 }
2330 if (texStorageSupported && !formatWorkarounds.fDisableRGBA16FTexStorageForCrBug1008003) {
2331 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2332 info.fInternalFormatForTexImageOrStorage = GR_GL_RGBA16F;
2333 } else {
2334 info.fInternalFormatForTexImageOrStorage =
2335 texImageSupportsSizedInternalFormat ? GR_GL_RGBA16F : GR_GL_RGBA;
2336 }
2337
2338 if (rgba16FTextureSupport) {
2339 uint32_t flags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2340
2341 info.fColorTypeInfoCount = 3;
2342 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2343 int ctIdx = 0;
2344 // Format: RGBA16F, Surface: kRGBA_F16
2345 {
2346 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2347 ctInfo.fColorType = GrColorType::kRGBA_F16;
2348 ctInfo.fFlags = flags;
2349 this->setColorTypeFormat(GrColorType::kRGBA_F16, GrGLFormat::kRGBA16F);
2350
2351 // External IO ColorTypes:
2352 ctInfo.fExternalIOFormatCount = 2;
2353 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2354 ctInfo.fExternalIOFormatCount);
2355 int ioIdx = 0;
2356 // Format: RGBA16F, Surface: kRGBA_F16, Data: kRGBA_F16
2357 {
2358 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2359 ioFormat.fColorType = GrColorType::kRGBA_F16;
2360 ioFormat.fExternalType = halfFloatType;
2361 ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2362 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2363 // Not guaranteed by ES/WebGL.
2364 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2365 }
2366
2367 // Format: RGBA16F, Surface: kRGBA_F16, Data: kRGBA_F32
2368 {
2369 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2370 ioFormat.fColorType = GrColorType::kRGBA_F32;
2371 ioFormat.fExternalType = GR_GL_FLOAT;
2372 ioFormat.fExternalTexImageFormat = 0;
2373 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2374 }
2375 }
2376
2377 // Format: RGBA16F, Surface: kRGBA_F16_Clamped
2378 {
2379 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2380 ctInfo.fColorType = GrColorType::kRGBA_F16_Clamped;
2381 ctInfo.fFlags = flags;
2382 this->setColorTypeFormat(GrColorType::kRGBA_F16_Clamped, GrGLFormat::kRGBA16F);
2383
2384 // External IO ColorTypes:
2385 ctInfo.fExternalIOFormatCount = 2;
2386 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2387 ctInfo.fExternalIOFormatCount);
2388 int ioIdx = 0;
2389 // Format: RGBA16F, Surface: kRGBA_F16_Clamped, Data: kRGBA_F16_Clamped
2390 {
2391 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2392 ioFormat.fColorType = GrColorType::kRGBA_F16_Clamped;
2393 ioFormat.fExternalType = halfFloatType;
2394 ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2395 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2396 // Not guaranteed by ES/WebGL.
2397 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2398 }
2399
2400 // Format: RGBA16F, Surface: kRGBA_F16_Clamped, Data: kRGBA_F32
2401 {
2402 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2403 ioFormat.fColorType = GrColorType::kRGBA_F32;
2404 ioFormat.fExternalType = GR_GL_FLOAT;
2405 ioFormat.fExternalTexImageFormat = 0;
2406 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2407 }
2408 }
2409 // Format: RGBA16F, Surface: kRGB_F16F16F16x
2410 {
2411 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2412 ctInfo.fColorType = GrColorType::kRGB_F16F16F16x;
2413 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
2414 ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1();
2415 ctInfo.fWriteSwizzle = skgpu::Swizzle::RGB1();
2416 this->setColorTypeFormat(GrColorType::kRGB_F16F16F16x, GrGLFormat::kRGBA16F);
2417
2418 // External IO ColorTypes:
2419 ctInfo.fExternalIOFormatCount = 2;
2420 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2421 ctInfo.fExternalIOFormatCount);
2422 int ioIdx = 0;
2423 // Format: RGBA16F, Surface: kRGB_F16F16F16x, Data: kRGB_F16F16F16x
2424 {
2425 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2426 ioFormat.fColorType = GrColorType::kRGB_F16F16F16x;
2427 ioFormat.fExternalType = halfFloatType;
2428 ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2429 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2430 // Not guaranteed by ES/WebGL.
2431 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2432 }
2433 // Format: RGBA16F, Surface: kRGB_F16F16F16x, Data: kRGBA_F32
2434 {
2435 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2436 ioFormat.fColorType = GrColorType::kRGBA_F32;
2437 ioFormat.fExternalType = GR_GL_FLOAT;
2438 ioFormat.fExternalTexImageFormat = 0;
2439 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2440 }
2441 }
2442 }
2443 }
2444
2445 // Format: R16F
2446 {
2447 FormatInfo& info = this->getFormatInfo(GrGLFormat::kR16F);
2448 info.fFormatType = FormatType::kFloat;
2449 info.fInternalFormatForRenderbuffer = GR_GL_R16F;
2450 info.fDefaultExternalFormat = GR_GL_RED;
2451 info.fDefaultExternalType = halfFloatType;
2452 info.fDefaultColorType = GrColorType::kR_F16;
2453 bool r16FTextureSupport = false;
2454 bool r16FRenderTargetSupport = false;
2455
2456 if (GR_IS_GR_GL(standard)) {
2457 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg")) {
2458 r16FTextureSupport = true;
2459 r16FRenderTargetSupport = true;
2460 }
2461 } else if (GR_IS_GR_GL_ES(standard)) {
2462 // It seems possible that a combination of GL_EXT_texture_rg and
2463 // GL_EXT_color_buffer_half_float might add this format to ES 2.0 but it is not entirely
2464 // clear. The latter mentions interaction but that may only be for renderbuffers as
2465 // neither adds the texture format explicitly.
2466 // GL_OES_texture_format_half_float makes no reference to RED formats.
2467 if (version >= GR_GL_VER(3, 0)) {
2468 r16FTextureSupport = true;
2469 r16FRenderTargetSupport = version >= GR_GL_VER(3, 2) ||
2470 ctxInfo.hasExtension("GL_EXT_color_buffer_float") ||
2471 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float");
2472 }
2473 } else if (GR_IS_GR_WEBGL(standard)) {
2474 if (version >= GR_GL_VER(2, 0)) {
2475 r16FTextureSupport = true;
2476 r16FRenderTargetSupport = ctxInfo.hasExtension("GL_EXT_color_buffer_float") ||
2477 ctxInfo.hasExtension("EXT_color_buffer_float");
2478 }
2479 }
2480
2481 if (r16FTextureSupport) {
2482 info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2483 if (r16FRenderTargetSupport) {
2484 info.fFlags |= fpRenderFlags;
2485 }
2486 }
2487 if (texStorageSupported) {
2488 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2489 info.fInternalFormatForTexImageOrStorage = GR_GL_R16F;
2490 } else {
2491 info.fInternalFormatForTexImageOrStorage =
2492 texImageSupportsSizedInternalFormat ? GR_GL_R16F : GR_GL_RED;
2493 }
2494
2495 if (r16FTextureSupport) {
2496 // Format: R16F, Surface: kAlpha_F16
2497 info.fColorTypeInfoCount = 1;
2498 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2499 int ctIdx = 0;
2500 {
2501 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2502 ctInfo.fColorType = GrColorType::kAlpha_F16;
2503 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2504 ctInfo.fReadSwizzle = skgpu::Swizzle("000r");
2505 ctInfo.fWriteSwizzle = skgpu::Swizzle("a000");
2506 this->setColorTypeFormat(GrColorType::kAlpha_F16, GrGLFormat::kR16F);
2507
2508 // External IO ColorTypes:
2509 ctInfo.fExternalIOFormatCount = 2;
2510 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2511 ctInfo.fExternalIOFormatCount);
2512 int ioIdx = 0;
2513 // Format: R16F, Surface: kAlpha_F16, Data: kAlpha_F16
2514 {
2515 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2516 ioFormat.fColorType = GrColorType::kAlpha_F16;
2517 ioFormat.fExternalType = halfFloatType;
2518 ioFormat.fExternalTexImageFormat = GR_GL_RED;
2519 ioFormat.fExternalReadFormat = GR_GL_RED;
2520 // Not guaranteed by ES/WebGL.
2521 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2522 }
2523
2524 // Format: R16F, Surface: kAlpha_F16, Data: kAlpha_F32xxx
2525 {
2526 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2527 ioFormat.fColorType = GrColorType::kAlpha_F32xxx;
2528 ioFormat.fExternalType = GR_GL_FLOAT;
2529 ioFormat.fExternalTexImageFormat = 0;
2530 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2531 }
2532 }
2533 }
2534 }
2535
2536 // Format: LUMINANCE16F
2537 {
2538 // NOTE: We disallow lum16f on ES devices if linear filtering modes are not
2539 // supported. This is for simplicity, but a more granular approach is possible.
2540 bool lum16FSupported = false;
2541 bool lum16FSizedFormatSupported = false;
2542 GrGLenum lumHalfFloatType = halfFloatType;
2543 if (GR_IS_GR_GL(standard)) {
2544 if (!fIsCoreProfile && ctxInfo.hasExtension("GL_ARB_texture_float")) {
2545 lum16FSupported = true;
2546 lum16FSizedFormatSupported = true;
2547 }
2548 } else if (GR_IS_GR_GL_ES(standard)) {
2549 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
2550 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
2551 lum16FSupported = true;
2552 // Even in ES 3.0+ LUMINANCE and GL_HALF_FLOAT are not listed as a valid
2553 // combination. Thus we must use GL_HALF_FLOAT_OES provided by the extension
2554 // GL_OES_texture_half_float. Note: these two types are not defined to be the same
2555 // value.
2556 lumHalfFloatType = GR_GL_HALF_FLOAT_OES;
2557 // Even on ES3 this extension is required to define LUMINANCE16F.
2558 lum16FSizedFormatSupported = ctxInfo.hasExtension("GL_EXT_texture_storage");
2559 }
2560 } // No WebGL support
2561
2562 if (formatWorkarounds.fDisableLuminance16F) {
2563 lum16FSupported = false;
2564 }
2565
2566 FormatInfo& info = this->getFormatInfo(GrGLFormat::kLUMINANCE16F);
2567 info.fFormatType = FormatType::kFloat;
2568 info.fInternalFormatForRenderbuffer = GR_GL_LUMINANCE16F;
2569 info.fDefaultExternalFormat = GR_GL_LUMINANCE;
2570 info.fDefaultExternalType = lumHalfFloatType;
2571 info.fDefaultColorType = GrColorType::kGray_F16;
2572
2573 if (lum16FSupported) {
2574 info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2575
2576 if (texStorageSupported && lum16FSizedFormatSupported) {
2577 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2578 info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE16F;
2579 } else if (texImageSupportsSizedInternalFormat && lum16FSizedFormatSupported) {
2580 info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE16F;
2581 } else {
2582 info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE;
2583 }
2584
2585 info.fColorTypeInfoCount = 1;
2586 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2587 int ctIdx = 0;
2588 // Format: LUMINANCE16F, Surface: kAlpha_F16
2589 {
2590 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2591 ctInfo.fColorType = GrColorType::kAlpha_F16;
2592 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
2593 ctInfo.fReadSwizzle = skgpu::Swizzle("000r");
2594 ctInfo.fWriteSwizzle = skgpu::Swizzle("aaa0");
2595
2596 int idx = static_cast<int>(GrColorType::kAlpha_F16);
2597 if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
2598 this->setColorTypeFormat(GrColorType::kAlpha_F16, GrGLFormat::kLUMINANCE16F);
2599 }
2600
2601 // External IO ColorTypes:
2602 ctInfo.fExternalIOFormatCount = 2;
2603 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2604 ctInfo.fExternalIOFormatCount);
2605 int ioIdx = 0;
2606 // Format: LUMINANCE16F, Surface: kAlpha_F16, Data: kAlpha_F16
2607 {
2608 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2609 ioFormat.fColorType = GrColorType::kAlpha_F16;
2610 ioFormat.fExternalType = lumHalfFloatType;
2611 ioFormat.fExternalTexImageFormat = GR_GL_LUMINANCE;
2612 ioFormat.fExternalReadFormat = 0;
2613 }
2614
2615 // Format: LUMINANCE16F, Surface: kAlpha_F16, Data: kRGBA_F32
2616 {
2617 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2618 ioFormat.fColorType = GrColorType::kRGBA_F32;
2619 ioFormat.fExternalType = GR_GL_FLOAT;
2620 ioFormat.fExternalTexImageFormat = 0;
2621 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2622 }
2623 }
2624 }
2625 }
2626
2627 // Format: RGBx8
2628 {
2629 FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBX8);
2630 info.fFormatType = FormatType::kNormalizedFixedPoint;
2631 info.fInternalFormatForRenderbuffer = GR_GL_RGBX8;
2632 info.fDefaultExternalFormat = GR_GL_RGB;
2633 info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
2634 info.fDefaultColorType = GrColorType::kRGB_888;
2635
2636 bool supportsSizedRGBX = false;
2637 // The GL_ANGLE_rgbx_internal_format extension only adds the sized GL_RGBX8 type and does
2638 // not have a way to create a texture of that format with texImage using an unsized type. So
2639 // we require that we either have texture storage support or that tex image supports sized
2640 // formats to say that this format is supported.
2641 if (GR_IS_GR_GL_ES(standard) && ctxInfo.hasExtension("GL_ANGLE_rgbx_internal_format") &&
2642 (texStorageSupported || texImageSupportsSizedInternalFormat)) {
2643 supportsSizedRGBX = true;
2644 }
2645
2646 if (supportsSizedRGBX) {
2647 info.fInternalFormatForTexImageOrStorage = GR_GL_RGBX8;
2648 info.fFlags = FormatInfo::kTexturable_Flag |
2649 FormatInfo::kTransfers_Flag |
2650 msaaRenderFlags;
2651 if (texStorageSupported) {
2652 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2653 }
2654 info.fColorTypeInfoCount = 1;
2655 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2656 int ctIdx = 0;
2657 // Format: RGBX8, Surface: kRGB_888x
2658 {
2659 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2660 ctInfo.fColorType = GrColorType::kRGB_888x;
2661 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2662 this->setColorTypeFormat(GrColorType::kRGB_888x, GrGLFormat::kRGBX8);
2663
2664 // External IO ColorTypes:
2665 ctInfo.fExternalIOFormatCount = 2;
2666 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2667 ctInfo.fExternalIOFormatCount);
2668 int ioIdx = 0;
2669 // Format: RGBX8, Surface: kRGB_888x, Data: kRGB_888
2670 {
2671 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2672 ioFormat.fColorType = GrColorType::kRGB_888;
2673 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2674 ioFormat.fExternalTexImageFormat = GR_GL_RGB;
2675 ioFormat.fExternalReadFormat = 0;
2676 }
2677
2678 // Format: RGBX8, Surface: kRGB_888x, Data: kRGB_888x
2679 {
2680 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2681 ioFormat.fColorType = GrColorType::kRGB_888x;
2682 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2683 ioFormat.fExternalTexImageFormat = 0;
2684 ioFormat.fExternalReadFormat = GR_GL_RGBX8;
2685 }
2686 }
2687 }
2688 }
2689
2690 // Format: RGB8
2691 {
2692 FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB8);
2693 info.fFormatType = FormatType::kNormalizedFixedPoint;
2694 info.fInternalFormatForRenderbuffer = GR_GL_RGB8;
2695 info.fDefaultExternalFormat = GR_GL_RGB;
2696 info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
2697 info.fDefaultColorType = GrColorType::kRGB_888;
2698 info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2699 if (GR_IS_GR_GL(standard)) {
2700 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be
2701 // a supported render buffer format. Since we usually use render buffers for MSAA on
2702 // non-ES GL we don't support MSAA for GL_RGB8. On 4.2+ we could check using
2703 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if
2704 // this becomes an issue.
2705 info.fFlags |= nonMSAARenderFlags;
2706 } else if (GR_IS_GR_GL_ES(standard)) {
2707 // 3.0 and the extension support this as a render buffer format.
2708 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
2709 info.fFlags |= msaaRenderFlags;
2710 }
2711 } else if (GR_IS_GR_WEBGL(standard)) {
2712 // WebGL seems to support RBG8
2713 info.fFlags |= msaaRenderFlags;
2714 }
2715 if (texStorageSupported) {
2716 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2717 info.fInternalFormatForTexImageOrStorage = GR_GL_RGB8;
2718 } else {
2719 info.fInternalFormatForTexImageOrStorage =
2720 texImageSupportsSizedInternalFormat ? GR_GL_RGB8 : GR_GL_RGB;
2721 }
2722
2723 info.fColorTypeInfoCount = 1;
2724 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2725 int ctIdx = 0;
2726 // Format: RGB8, Surface: kRGB_888x
2727 {
2728 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2729 ctInfo.fColorType = GrColorType::kRGB_888x;
2730 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2731
2732 int idx = static_cast<int>(GrColorType::kRGB_888x);
2733 if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
2734 this->setColorTypeFormat(GrColorType::kRGB_888x, GrGLFormat::kRGB8);
2735 }
2736
2737 // External IO ColorTypes:
2738 ctInfo.fExternalIOFormatCount = 2;
2739 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2740 ctInfo.fExternalIOFormatCount);
2741 int ioIdx = 0;
2742 // Format: RGB8, Surface: kRGB_888x, Data: kRGB_888
2743 {
2744 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2745 ioFormat.fColorType = GrColorType::kRGB_888;
2746 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2747 ioFormat.fExternalTexImageFormat = GR_GL_RGB;
2748 ioFormat.fExternalReadFormat = 0;
2749 }
2750
2751 // Format: RGB8, Surface: kRGB_888x, Data: kRGBA_8888
2752 {
2753 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2754 ioFormat.fColorType = GrColorType::kRGBA_8888;
2755 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2756 ioFormat.fExternalTexImageFormat = 0;
2757 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2758 }
2759 }
2760 }
2761
2762 // Format: RG8
2763 {
2764 FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG8);
2765 info.fFormatType = FormatType::kNormalizedFixedPoint;
2766 info.fInternalFormatForRenderbuffer = GR_GL_RG8;
2767 info.fDefaultExternalFormat = GR_GL_RG;
2768 info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
2769 info.fDefaultColorType = GrColorType::kRG_88;
2770 bool rg8Support = false;
2771 if (GR_IS_GR_GL(standard)) {
2772 rg8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
2773 } else if (GR_IS_GR_GL_ES(standard)) {
2774 rg8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
2775 } else if (GR_IS_GR_WEBGL(standard)) {
2776 rg8Support = version >= GR_GL_VER(2, 0);
2777 }
2778 if (rg8Support) {
2779 info.fFlags |= FormatInfo::kTexturable_Flag
2780 | FormatInfo::kTransfers_Flag
2781 | msaaRenderFlags;
2782 if (texStorageSupported) {
2783 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2784 info.fInternalFormatForTexImageOrStorage = GR_GL_RG8;
2785 }
2786 }
2787 if (!(info.fFlags & FormatInfo::kUseTexStorage_Flag)) {
2788 info.fInternalFormatForTexImageOrStorage =
2789 texImageSupportsSizedInternalFormat ? GR_GL_RG8 : GR_GL_RG;
2790 }
2791 if (rg8Support) {
2792 info.fColorTypeInfoCount = 1;
2793 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2794 int ctIdx = 0;
2795 // Format: RG8, Surface: kRG_88
2796 {
2797 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2798 ctInfo.fColorType = GrColorType::kRG_88;
2799 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2800 this->setColorTypeFormat(GrColorType::kRG_88, GrGLFormat::kRG8);
2801
2802 // External IO ColorTypes:
2803 ctInfo.fExternalIOFormatCount = 2;
2804 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2805 ctInfo.fExternalIOFormatCount);
2806 int ioIdx = 0;
2807 // Format: RG8, Surface: kRG_88, Data: kRG_88
2808 {
2809 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2810 ioFormat.fColorType = GrColorType::kRG_88;
2811 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2812 ioFormat.fExternalTexImageFormat = GR_GL_RG;
2813 ioFormat.fExternalReadFormat = 0;
2814 if (GR_IS_GR_GL(standard) && !formatWorkarounds.fDisallowDirectRG8ReadPixels) {
2815 ioFormat.fExternalReadFormat = GR_GL_RG;
2816 }
2817 }
2818
2819 // Format: RG8, Surface: kRG_88, Data: kRGBA_8888
2820 {
2821 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2822 ioFormat.fColorType = GrColorType::kRGBA_8888;
2823 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2824 ioFormat.fExternalTexImageFormat = 0;
2825 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2826 }
2827 }
2828 }
2829 }
2830
2831 // Format: RGB10_A2
2832 {
2833 FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB10_A2);
2834 info.fFormatType = FormatType::kNormalizedFixedPoint;
2835 info.fInternalFormatForRenderbuffer = GR_GL_RGB10_A2;
2836 info.fDefaultExternalFormat = GR_GL_RGBA;
2837 info.fDefaultExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
2838 info.fDefaultColorType = GrColorType::kRGBA_1010102;
2839 if (GR_IS_GR_GL(standard) ||
2840 (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3, 0))) {
2841 info.fFlags = FormatInfo::kTexturable_Flag
2842 | FormatInfo::kTransfers_Flag
2843 | msaaRenderFlags;
2844 } else if (GR_IS_GR_GL_ES(standard) &&
2845 ctxInfo.hasExtension("GL_EXT_texture_type_2_10_10_10_REV")) {
2846 info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2847 } // No WebGL support
2848
2849 if (texStorageSupported) {
2850 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2851 info.fInternalFormatForTexImageOrStorage = GR_GL_RGB10_A2;
2852 } else {
2853 info.fInternalFormatForTexImageOrStorage =
2854 texImageSupportsSizedInternalFormat ? GR_GL_RGB10_A2 : GR_GL_RGBA;
2855 }
2856
2857 if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
2858 bool supportsBGRAColorType = GR_IS_GR_GL(standard) &&
2859 (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra"));
2860
2861 info.fColorTypeInfoCount = supportsBGRAColorType ? 3 : 2;
2862 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2863 int ctIdx = 0;
2864 // Format: RGB10_A2, Surface: kRGBA_1010102
2865 {
2866 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2867 ctInfo.fColorType = GrColorType::kRGBA_1010102;
2868 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2869 this->setColorTypeFormat(GrColorType::kRGBA_1010102, GrGLFormat::kRGB10_A2);
2870
2871 // External IO ColorTypes:
2872 ctInfo.fExternalIOFormatCount = 2;
2873 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2874 ctInfo.fExternalIOFormatCount);
2875 int ioIdx = 0;
2876 // Format: RGB10_A2, Surface: kRGBA_1010102, Data: kRGBA_1010102
2877 {
2878 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2879 ioFormat.fColorType = GrColorType::kRGBA_1010102;
2880 ioFormat.fExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
2881 ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2882 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2883 // Not guaranteed by ES/WebGL.
2884 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2885 }
2886
2887 // Format: RGB10_A2, Surface: kRGBA_1010102, Data: kRGBA_8888
2888 {
2889 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2890 ioFormat.fColorType = GrColorType::kRGBA_8888;
2891 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2892 ioFormat.fExternalTexImageFormat = 0;
2893 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2894 }
2895 }
2896 //------------------------------------------------------------------
2897 // Format: RGB10_A2, Surface: kBGRA_1010102
2898 if (supportsBGRAColorType) {
2899 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2900 ctInfo.fColorType = GrColorType::kBGRA_1010102;
2901 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2902 this->setColorTypeFormat(GrColorType::kBGRA_1010102, GrGLFormat::kRGB10_A2);
2903
2904 // External IO ColorTypes:
2905 ctInfo.fExternalIOFormatCount = 2;
2906 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2907 ctInfo.fExternalIOFormatCount);
2908 int ioIdx = 0;
2909 // Format: RGB10_A2, Surface: kBGRA_1010102, Data: kBGRA_1010102
2910 {
2911 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2912 ioFormat.fColorType = GrColorType::kBGRA_1010102;
2913 ioFormat.fExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
2914 ioFormat.fExternalTexImageFormat = GR_GL_BGRA;
2915 ioFormat.fExternalReadFormat =
2916 formatWorkarounds.fDisallowBGRA8ReadPixels ? 0 : GR_GL_BGRA;
2917 // Not guaranteed by ES/WebGL.
2918 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2919 }
2920
2921 // Format: RGB10_A2, Surface: kBGRA_1010102, Data: kRGBA_8888
2922 {
2923 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2924 ioFormat.fColorType = GrColorType::kRGBA_8888;
2925 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2926 ioFormat.fExternalTexImageFormat = 0;
2927 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2928 }
2929 }
2930 // Format: RGB10_A2, Surface: kRGB_101010x
2931 {
2932 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2933 ctInfo.fColorType = GrColorType::kRGB_101010x;
2934 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
2935 ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1();
2936 ctInfo.fWriteSwizzle = skgpu::Swizzle::RGB1();
2937 this->setColorTypeFormat(GrColorType::kRGB_101010x, GrGLFormat::kRGB10_A2);
2938
2939 // External IO ColorTypes:
2940 ctInfo.fExternalIOFormatCount = 2;
2941 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2942 ctInfo.fExternalIOFormatCount);
2943 int ioIdx = 0;
2944 // Format: RGB10_A2, Surface: kRGB_101010x, Data: kRGB_101010x
2945 {
2946 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2947 ioFormat.fColorType = GrColorType::kRGB_101010x;
2948 ioFormat.fExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
2949 ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2950 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2951 // Not guaranteed by ES/WebGL.
2952 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2953 }
2954 // Format: RGB10_A2, Surface: kRGB_101010x, Data: kRGBA_8888
2955 {
2956 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2957 ioFormat.fColorType = GrColorType::kRGBA_8888;
2958 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2959 ioFormat.fExternalTexImageFormat = 0;
2960 ioFormat.fExternalReadFormat = GR_GL_RGBA;
2961 }
2962 }
2963
2964 }
2965 }
2966
2967 // Format: RGBA4
2968 {
2969 FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA4);
2970 info.fFormatType = FormatType::kNormalizedFixedPoint;
2971 info.fInternalFormatForRenderbuffer = GR_GL_RGBA4;
2972 info.fDefaultExternalFormat = GR_GL_RGBA;
2973 info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
2974 info.fDefaultColorType = GrColorType::kABGR_4444;
2975 info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2976 if (GR_IS_GR_GL(standard)) {
2977 if (version >= GR_GL_VER(4, 2)) {
2978 info.fFlags |= msaaRenderFlags;
2979 }
2980 } else if (GR_IS_GR_GL_ES(standard)) {
2981 info.fFlags |= msaaRenderFlags;
2982 } else if (GR_IS_GR_WEBGL(standard)) {
2983 info.fFlags |= msaaRenderFlags;
2984 }
2985 if (texStorageSupported) {
2986 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2987 info.fInternalFormatForTexImageOrStorage = GR_GL_RGBA4;
2988 } else {
2989 info.fInternalFormatForTexImageOrStorage =
2990 texImageSupportsSizedInternalFormat ? GR_GL_RGBA4 : GR_GL_RGBA;
2991 }
2992
2993 info.fColorTypeInfoCount = 1;
2994 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2995 int ctIdx = 0;
2996 // Format: RGBA4, Surface: kABGR_4444
2997 {
2998 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2999 ctInfo.fColorType = GrColorType::kABGR_4444;
3000 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3001 this->setColorTypeFormat(GrColorType::kABGR_4444, GrGLFormat::kRGBA4);
3002
3003 // External IO ColorTypes:
3004 ctInfo.fExternalIOFormatCount = 2;
3005 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3006 ctInfo.fExternalIOFormatCount);
3007 int ioIdx = 0;
3008 // Format: RGBA4, Surface: kABGR_4444, Data: kABGR_4444
3009 {
3010 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3011 ioFormat.fColorType = GrColorType::kABGR_4444;
3012 ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
3013 ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
3014 ioFormat.fExternalReadFormat = GR_GL_RGBA;
3015 // Not guaranteed by ES/WebGL.
3016 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
3017 }
3018
3019 // Format: RGBA4, Surface: kABGR_4444, Data: kRGBA_8888
3020 {
3021 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3022 ioFormat.fColorType = GrColorType::kRGBA_8888;
3023 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
3024 ioFormat.fExternalTexImageFormat = 0;
3025 ioFormat.fExternalReadFormat = GR_GL_RGBA;
3026 }
3027 }
3028 }
3029
3030 // Format: SRGB8_ALPHA8
3031 {
3032 FormatInfo& info = this->getFormatInfo(GrGLFormat::kSRGB8_ALPHA8);
3033 info.fFormatType = FormatType::kNormalizedFixedPoint;
3034 info.fInternalFormatForRenderbuffer = GR_GL_SRGB8_ALPHA8;
3035 info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
3036 info.fDefaultColorType = GrColorType::kRGBA_8888_SRGB;
3037
3038 // We may modify the default external format below.
3039 info.fDefaultExternalFormat = GR_GL_RGBA;
3040 bool srgb8Alpha8TexStorageSupported = texStorageSupported;
3041 bool srgb8Alpha8TextureSupport = false;
3042 bool srgb8Alpha8RenderTargetSupport = false;
3043 if (GR_IS_GR_GL(standard)) {
3044 if (version >= GR_GL_VER(3, 0)) {
3045 srgb8Alpha8TextureSupport = true;
3046 srgb8Alpha8RenderTargetSupport = true;
3047 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
3048 srgb8Alpha8TextureSupport = true;
3049 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
3050 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
3051 srgb8Alpha8RenderTargetSupport = true;
3052 }
3053 }
3054 } else if (GR_IS_GR_GL_ES(standard)) {
3055 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_sRGB")) {
3056 srgb8Alpha8TextureSupport = true;
3057 srgb8Alpha8RenderTargetSupport = true;
3058 }
3059 if (version < GR_GL_VER(3, 0)) {
3060 // ES 2.0 requires that the external format matches the internal format.
3061 info.fDefaultExternalFormat = GR_GL_SRGB_ALPHA;
3062 // There is no defined interaction between GL_EXT_sRGB and GL_EXT_texture_storage.
3063 srgb8Alpha8TexStorageSupported = false;
3064 }
3065 } else if (GR_IS_GR_WEBGL(standard)) {
3066 // sRGB extension should be on most WebGL 1.0 contexts, although sometimes under 2
3067 // names.
3068 if (version >= GR_GL_VER(2, 0) || ctxInfo.hasExtension("GL_EXT_sRGB") ||
3069 ctxInfo.hasExtension("EXT_sRGB")) {
3070 srgb8Alpha8TextureSupport = true;
3071 srgb8Alpha8RenderTargetSupport = true;
3072 }
3073 if (version < GR_GL_VER(2, 0)) {
3074 // WebGL 1.0 requires that the external format matches the internal format.
3075 info.fDefaultExternalFormat = GR_GL_SRGB_ALPHA;
3076 // There is no extension to WebGL 1 that adds glTexStorage.
3077 SkASSERT(!srgb8Alpha8TexStorageSupported);
3078 }
3079 }
3080
3081 if (srgb8Alpha8TextureSupport) {
3082 info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
3083 if (srgb8Alpha8RenderTargetSupport) {
3084 info.fFlags |= formatWorkarounds.fDisableSRGBRenderWithMSAAForMacAMD
3085 ? nonMSAARenderFlags
3086 : msaaRenderFlags;
3087 }
3088 }
3089 if (srgb8Alpha8TexStorageSupported) {
3090 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
3091 info.fInternalFormatForTexImageOrStorage = GR_GL_SRGB8_ALPHA8;
3092 } else {
3093 info.fInternalFormatForTexImageOrStorage =
3094 texImageSupportsSizedInternalFormat ? GR_GL_SRGB8_ALPHA8 : GR_GL_SRGB_ALPHA;
3095 }
3096
3097 if (srgb8Alpha8TextureSupport) {
3098 info.fColorTypeInfoCount = 1;
3099 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
3100 int ctIdx = 0;
3101 // Format: SRGB8_ALPHA8, Surface: kRGBA_8888_SRGB
3102 {
3103 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
3104 ctInfo.fColorType = GrColorType::kRGBA_8888_SRGB;
3105 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3106 this->setColorTypeFormat(GrColorType::kRGBA_8888_SRGB, GrGLFormat::kSRGB8_ALPHA8);
3107
3108 // External IO ColorTypes:
3109 ctInfo.fExternalIOFormatCount = 1;
3110 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3111 ctInfo.fExternalIOFormatCount);
3112 int ioIdx = 0;
3113
3114 // Format: SRGB8_ALPHA8, Surface: kRGBA_8888_SRGB, Data: kRGBA_8888_SRGB
3115 {
3116 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu.
3117 // Thus, the external format is GL_RGBA. See below for note about ES2.0 and
3118 // glTex[Sub]Image.
3119 GrGLenum texImageExternalFormat = GR_GL_RGBA;
3120
3121 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the
3122 // <format> param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and
3123 // <format> params to match. Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the
3124 // <format> param. On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the
3125 // <format> param to glTexImage.
3126 if (GR_IS_GR_GL_ES(standard) && version == GR_GL_VER(2,0)) {
3127 texImageExternalFormat = GR_GL_SRGB_ALPHA;
3128 }
3129 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3130 ioFormat.fColorType = GrColorType::kRGBA_8888_SRGB;
3131 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
3132 ioFormat.fExternalTexImageFormat = texImageExternalFormat;
3133 ioFormat.fExternalReadFormat = GR_GL_RGBA;
3134 }
3135 }
3136 }
3137 }
3138
3139 // Format: COMPRESSED_RGB8_BC1
3140 {
3141 FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_RGB8_BC1);
3142 info.fFormatType = FormatType::kNormalizedFixedPoint;
3143 info.fInternalFormatForTexImageOrStorage = GR_GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
3144 if (GR_IS_GR_GL(standard) || GR_IS_GR_GL_ES(standard)) {
3145 if (ctxInfo.hasExtension("GL_EXT_texture_compression_s3tc")) {
3146 info.fFlags = FormatInfo::kTexturable_Flag;
3147 }
3148 } else if (GR_IS_GR_WEBGL(standard)) {
3149 if (ctxInfo.hasExtension("WEBGL_compressed_texture_s3tc")) {
3150 info.fFlags = FormatInfo::kTexturable_Flag;
3151 }
3152 }
3153
3154 // There are no support GrColorTypes for this format
3155 }
3156
3157 // Format: COMPRESSED_RGBA8_BC1
3158 {
3159 FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_RGBA8_BC1);
3160 info.fFormatType = FormatType::kNormalizedFixedPoint;
3161 info.fInternalFormatForTexImageOrStorage = GR_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
3162 if (GR_IS_GR_GL(standard) || GR_IS_GR_GL_ES(standard)) {
3163 if (ctxInfo.hasExtension("GL_EXT_texture_compression_s3tc")) {
3164 info.fFlags = FormatInfo::kTexturable_Flag;
3165 }
3166 } else if (GR_IS_GR_WEBGL(standard)) {
3167 if (ctxInfo.hasExtension("WEBGL_compressed_texture_s3tc")) {
3168 info.fFlags = FormatInfo::kTexturable_Flag;
3169 }
3170 }
3171
3172 // There are no support GrColorTypes for this format
3173 }
3174
3175 // Format: COMPRESSED_RGB8_ETC2
3176 {
3177 FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_RGB8_ETC2);
3178 info.fFormatType = FormatType::kNormalizedFixedPoint;
3179 info.fInternalFormatForTexImageOrStorage = GR_GL_COMPRESSED_RGB8_ETC2;
3180 if (!formatWorkarounds.fDisallowETC2Compression) {
3181 if (GR_IS_GR_GL(standard)) {
3182 if (version >= GR_GL_VER(4, 3) ||
3183 ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
3184 info.fFlags = FormatInfo::kTexturable_Flag;
3185 }
3186 } else if (GR_IS_GR_GL_ES(standard)) {
3187 if (version >= GR_GL_VER(3, 0) ||
3188 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture")) {
3189 info.fFlags = FormatInfo::kTexturable_Flag;
3190 }
3191 } else if (GR_IS_GR_WEBGL(standard)) {
3192 if (ctxInfo.hasExtension("WEBGL_compressed_texture_etc")) {
3193 info.fFlags = FormatInfo::kTexturable_Flag;
3194 }
3195 }
3196 }
3197
3198 // There are no support GrColorTypes for this format
3199 }
3200
3201 // Format: COMPRESSED_ETC1_RGB8
3202 {
3203 FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_ETC1_RGB8);
3204 info.fFormatType = FormatType::kNormalizedFixedPoint;
3205 info.fInternalFormatForTexImageOrStorage = GR_GL_COMPRESSED_ETC1_RGB8;
3206 if (GR_IS_GR_GL_ES(standard)) {
3207 if (ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture")) {
3208 info.fFlags = FormatInfo::kTexturable_Flag;
3209 }
3210 } else if (GR_IS_GR_WEBGL(standard)) {
3211 if (ctxInfo.hasExtension("WEBGL_compressed_texture_etc1")) {
3212 info.fFlags = FormatInfo::kTexturable_Flag;
3213 }
3214 }
3215 // No GL support
3216
3217 // There are no support GrColorTypes for this format
3218 }
3219
3220 // Format: R16
3221 {
3222 FormatInfo& info = this->getFormatInfo(GrGLFormat::kR16);
3223 info.fFormatType = FormatType::kNormalizedFixedPoint;
3224 info.fInternalFormatForRenderbuffer = GR_GL_R16;
3225 info.fDefaultExternalFormat = GR_GL_RED;
3226 info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
3227 info.fDefaultColorType = GrColorType::kR_16;
3228 bool r16Supported = false;
3229 if (!formatWorkarounds.fDisallowTextureUnorm16) {
3230 if (GR_IS_GR_GL(standard)) {
3231 r16Supported = version >= GR_GL_VER(3, 0) ||
3232 ctxInfo.hasExtension("GL_ARB_texture_rg");
3233 } else if (GR_IS_GR_GL_ES(standard)) {
3234 r16Supported = ctxInfo.hasExtension("GL_EXT_texture_norm16");
3235 } // No WebGL support
3236 }
3237
3238 if (r16Supported) {
3239 info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
3240 if (!formatWorkarounds.fDisallowUnorm16Transfers) {
3241 info.fFlags |= FormatInfo::kTransfers_Flag;
3242 }
3243 }
3244
3245 if (texStorageSupported) {
3246 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
3247 info.fInternalFormatForTexImageOrStorage = GR_GL_R16;
3248 } else {
3249 info.fInternalFormatForTexImageOrStorage =
3250 texImageSupportsSizedInternalFormat ? GR_GL_R16 : GR_GL_RED;
3251 }
3252
3253 if (r16Supported) {
3254 info.fColorTypeInfoCount = 1;
3255 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
3256 int ctIdx = 0;
3257 // Format: R16, Surface: kAlpha_16
3258 {
3259 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
3260 ctInfo.fColorType = GrColorType::kAlpha_16;
3261 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3262 ctInfo.fReadSwizzle = skgpu::Swizzle("000r");
3263 ctInfo.fWriteSwizzle = skgpu::Swizzle("a000");
3264 this->setColorTypeFormat(GrColorType::kAlpha_16, GrGLFormat::kR16);
3265
3266 // External IO ColorTypes:
3267 ctInfo.fExternalIOFormatCount = 2;
3268 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3269 ctInfo.fExternalIOFormatCount);
3270 int ioIdx = 0;
3271 // Format: R16, Surface: kAlpha_16, Data: kAlpha_16
3272 {
3273 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3274 ioFormat.fColorType = GrColorType::kAlpha_16;
3275 ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT;
3276 ioFormat.fExternalTexImageFormat = GR_GL_RED;
3277 ioFormat.fExternalReadFormat = GR_GL_RED;
3278 // Not guaranteed by ES/WebGL.
3279 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
3280 }
3281
3282 // Format: R16, Surface: kAlpha_16, Data: kAlpha_8xxx
3283 {
3284 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3285 ioFormat.fColorType = GrColorType::kAlpha_8xxx;
3286 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
3287 ioFormat.fExternalTexImageFormat = 0;
3288 ioFormat.fExternalReadFormat = GR_GL_RGBA;
3289 }
3290 }
3291 }
3292 }
3293
3294 // Format: RG16
3295 {
3296 FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG16);
3297 info.fFormatType = FormatType::kNormalizedFixedPoint;
3298 info.fInternalFormatForTexImageOrStorage =
3299 texImageSupportsSizedInternalFormat ? GR_GL_RG16 : GR_GL_RG;
3300 info.fInternalFormatForRenderbuffer = GR_GL_RG16;
3301 info.fDefaultExternalFormat = GR_GL_RG;
3302 info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
3303 info.fDefaultColorType = GrColorType::kRG_1616;
3304 bool rg16Supported = false;
3305 if (!formatWorkarounds.fDisallowTextureUnorm16) {
3306 if (GR_IS_GR_GL(standard)) {
3307 rg16Supported = version >= GR_GL_VER(3, 0) ||
3308 ctxInfo.hasExtension("GL_ARB_texture_rg");
3309 } else if (GR_IS_GR_GL_ES(standard)) {
3310 rg16Supported = ctxInfo.hasExtension("GL_EXT_texture_norm16");
3311 } // No WebGL support
3312 }
3313
3314 if (rg16Supported) {
3315 info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
3316 if (!formatWorkarounds.fDisallowUnorm16Transfers) {
3317 info.fFlags |= FormatInfo::kTransfers_Flag;
3318 }
3319 }
3320
3321 if (texStorageSupported) {
3322 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
3323 info.fInternalFormatForTexImageOrStorage = GR_GL_RG16;
3324 } else {
3325 info.fInternalFormatForTexImageOrStorage =
3326 texImageSupportsSizedInternalFormat ? GR_GL_RG16 : GR_GL_RG;
3327 }
3328
3329 if (rg16Supported) {
3330 info.fColorTypeInfoCount = 1;
3331 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
3332 int ctIdx = 0;
3333 // Format: GR_GL_RG16, Surface: kRG_1616
3334 {
3335 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
3336 ctInfo.fColorType = GrColorType::kRG_1616;
3337 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3338 this->setColorTypeFormat(GrColorType::kRG_1616, GrGLFormat::kRG16);
3339
3340 // External IO ColorTypes:
3341 ctInfo.fExternalIOFormatCount = 2;
3342 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3343 ctInfo.fExternalIOFormatCount);
3344 int ioIdx = 0;
3345 // Format: GR_GL_RG16, Surface: kRG_1616, Data: kRG_1616
3346 {
3347 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3348 ioFormat.fColorType = GrColorType::kRG_1616;
3349 ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT;
3350 ioFormat.fExternalTexImageFormat = GR_GL_RG;
3351 ioFormat.fExternalReadFormat = GR_GL_RG;
3352 // Not guaranteed by ES/WebGL.
3353 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
3354 }
3355
3356 // Format: GR_GL_RG16, Surface: kRG_1616, Data: kRGBA_8888
3357 {
3358 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3359 ioFormat.fColorType = GrColorType::kRGBA_8888;
3360 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
3361 ioFormat.fExternalTexImageFormat = 0;
3362 ioFormat.fExternalReadFormat = GR_GL_RGBA;
3363 }
3364 }
3365 }
3366 }
3367
3368 // Format: RGBA16
3369 {
3370 bool rgba16Support = false;
3371 if (!formatWorkarounds.fDisallowTextureUnorm16) {
3372 if (GR_IS_GR_GL(standard)) {
3373 rgba16Support = version >= GR_GL_VER(3, 0);
3374 } else if (GR_IS_GR_GL_ES(standard)) {
3375 rgba16Support = ctxInfo.hasExtension("GL_EXT_texture_norm16");
3376 } // No WebGL support
3377 }
3378
3379 FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA16);
3380 info.fFormatType = FormatType::kNormalizedFixedPoint;
3381
3382 info.fInternalFormatForRenderbuffer = GR_GL_RGBA16;
3383 info.fDefaultExternalFormat = GR_GL_RGBA;
3384 info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
3385 info.fDefaultColorType = GrColorType::kRGBA_16161616;
3386 if (rgba16Support) {
3387 info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
3388 if (!formatWorkarounds.fDisallowUnorm16Transfers) {
3389 info.fFlags |= FormatInfo::kTransfers_Flag;
3390 }
3391 }
3392
3393 if (texStorageSupported) {
3394 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
3395 info.fInternalFormatForTexImageOrStorage = GR_GL_RGBA16;
3396 } else {
3397 info.fInternalFormatForTexImageOrStorage =
3398 texImageSupportsSizedInternalFormat ? GR_GL_RGBA16 : GR_GL_RGBA;
3399 }
3400
3401 if (rgba16Support) {
3402 // Format: GR_GL_RGBA16, Surface: kRGBA_16161616
3403 info.fColorTypeInfoCount = 1;
3404 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
3405 int ctIdx = 0;
3406 {
3407 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
3408 ctInfo.fColorType = GrColorType::kRGBA_16161616;
3409 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3410 this->setColorTypeFormat(GrColorType::kRGBA_16161616, GrGLFormat::kRGBA16);
3411
3412 // External IO ColorTypes:
3413 ctInfo.fExternalIOFormatCount = 2;
3414 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3415 ctInfo.fExternalIOFormatCount);
3416 int ioIdx = 0;
3417 // Format: GR_GL_RGBA16, Surface: kRGBA_16161616, Data: kRGBA_16161616
3418 {
3419 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3420 ioFormat.fColorType = GrColorType::kRGBA_16161616;
3421 ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT;
3422 ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
3423 ioFormat.fExternalReadFormat = GR_GL_RGBA;
3424 // Not guaranteed by ES/WebGL.
3425 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
3426 }
3427
3428 // Format: GR_GL_RGBA16, Surface: kRGBA_16161616, Data: kRGBA_8888
3429 {
3430 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3431 ioFormat.fColorType = GrColorType::kRGBA_8888;
3432 ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
3433 ioFormat.fExternalTexImageFormat = 0;
3434 ioFormat.fExternalReadFormat = GR_GL_RGBA;
3435 }
3436 }
3437 }
3438 }
3439
3440 // Format:RG16F
3441 {
3442 bool rg16FTextureSupport = false;
3443 bool rg16FRenderTargetSupport = false;
3444 if (GR_IS_GR_GL(standard)) {
3445 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
3446 rg16FTextureSupport = true;
3447 rg16FRenderTargetSupport = true;
3448 }
3449 } else if (GR_IS_GR_GL_ES(standard)) {
3450 // It seems possible that a combination of GL_EXT_texture_rg and
3451 // GL_EXT_color_buffer_half_float might add this format to ES 2.0 but it is not entirely
3452 // clear. The latter mentions interaction but that may only be for renderbuffers as
3453 // neither adds the texture format explicitly.
3454 // GL_OES_texture_format_half_float makes no reference to RG formats.
3455 if (version >= GR_GL_VER(3, 0)) {
3456 rg16FTextureSupport = true;
3457 rg16FRenderTargetSupport = version >= GR_GL_VER(3, 2) ||
3458 ctxInfo.hasExtension("GL_EXT_color_buffer_float") ||
3459 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float");
3460 }
3461 } else if (GR_IS_GR_WEBGL(standard)) {
3462 if (version >= GR_GL_VER(2, 0)) {
3463 rg16FTextureSupport = true;
3464 rg16FRenderTargetSupport = ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") ||
3465 ctxInfo.hasExtension("EXT_color_buffer_half_float") ||
3466 ctxInfo.hasExtension("GL_EXT_color_buffer_float") ||
3467 ctxInfo.hasExtension("EXT_color_buffer_float");
3468 }
3469 }
3470
3471 FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG16F);
3472 info.fFormatType = FormatType::kFloat;
3473 info.fInternalFormatForRenderbuffer = GR_GL_RG16F;
3474 info.fDefaultExternalFormat = GR_GL_RG;
3475 info.fDefaultExternalType = halfFloatType;
3476 info.fDefaultColorType = GrColorType::kRG_F16;
3477 if (rg16FTextureSupport) {
3478 info.fFlags |= FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
3479 if (rg16FRenderTargetSupport) {
3480 info.fFlags |= fpRenderFlags;
3481 }
3482 }
3483
3484 if (texStorageSupported) {
3485 info.fFlags |= FormatInfo::kUseTexStorage_Flag;
3486 info.fInternalFormatForTexImageOrStorage = GR_GL_RG16F;
3487 } else {
3488 info.fInternalFormatForTexImageOrStorage =
3489 texImageSupportsSizedInternalFormat ? GR_GL_RG16F : GR_GL_RG;
3490 }
3491
3492 if (rg16FTextureSupport) {
3493 info.fColorTypeInfoCount = 1;
3494 info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
3495 int ctIdx = 0;
3496 // Format: GR_GL_RG16F, Surface: kRG_F16
3497 {
3498 auto& ctInfo = info.fColorTypeInfos[ctIdx++];
3499 ctInfo.fColorType = GrColorType::kRG_F16;
3500 ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3501 this->setColorTypeFormat(GrColorType::kRG_F16, GrGLFormat::kRG16F);
3502
3503 // External IO ColorTypes:
3504 ctInfo.fExternalIOFormatCount = 2;
3505 ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3506 ctInfo.fExternalIOFormatCount);
3507 int ioIdx = 0;
3508 // Format: GR_GL_RG16F, Surface: kRG_F16, Data: kRG_F16
3509 {
3510 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3511 ioFormat.fColorType = GrColorType::kRG_F16;
3512 ioFormat.fExternalType = halfFloatType;
3513 ioFormat.fExternalTexImageFormat = GR_GL_RG;
3514 ioFormat.fExternalReadFormat = GR_GL_RG;
3515 // Not guaranteed by ES/WebGL.
3516 ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
3517 }
3518
3519 // Format: GR_GL_RG16F, Surface: kRG_F16, Data: kRGBA_F32
3520 {
3521 auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3522 ioFormat.fColorType = GrColorType::kRGBA_F32;
3523 ioFormat.fExternalType = GR_GL_FLOAT;
3524 ioFormat.fExternalTexImageFormat = 0;
3525 ioFormat.fExternalReadFormat = GR_GL_RGBA;
3526 }
3527 }
3528 }
3529 }
3530
3531 this->setupSampleCounts(ctxInfo, gli);
3532
3533 #ifdef SK_DEBUG
3534 for (int i = 0; i < kGrGLColorFormatCount; ++i) {
3535 if (GrGLFormat::kUnknown == static_cast<GrGLFormat>(i)) {
3536 continue;
3537 }
3538 const auto& formatInfo = fFormatTable[i];
3539 // Make sure we didn't set fbo attachable with msaa and not fbo attachable.
3540 SkASSERT(!((formatInfo.fFlags & FormatInfo::kFBOColorAttachmentWithMSAA_Flag) &&
3541 !(formatInfo.fFlags & FormatInfo::kFBOColorAttachment_Flag)));
3542
3543 // Make sure we set all the formats' FormatType
3544 SkASSERT(formatInfo.fFormatType != FormatType::kUnknown);
3545
3546 // Make sure if we added a ColorTypeInfo we filled it out
3547 for (int j = 0; j < formatInfo.fColorTypeInfoCount; ++j) {
3548 const auto& ctInfo = formatInfo.fColorTypeInfos[j];
3549 SkASSERT(ctInfo.fColorType != GrColorType::kUnknown);
3550 // Seems silly to add a color type if we don't support any flags on it.
3551 SkASSERT(ctInfo.fFlags);
3552 // Make sure if we added any ExternalIOFormats we filled it out
3553 for (int k = 0; k < ctInfo.fExternalIOFormatCount; ++k) {
3554 const auto& ioInfo = ctInfo.fExternalIOFormats[k];
3555 SkASSERT(ioInfo.fColorType != GrColorType::kUnknown);
3556 }
3557 }
3558 }
3559 #endif
3560 }
3561
3562 void GrGLCaps::setupSampleCounts(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
3563 GrGLStandard standard = ctxInfo.standard();
3564 // standard can be unused (optimized away) if SK_ASSUME_GL_ES is set
3565 sk_ignore_unused_variable(standard);
3566 GrGLVersion version = ctxInfo.version();
3567
3568 int maxSampleCnt = 1;
3569 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
3570 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
3571 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
3572 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
3573 }
3574 // Chrome has a mock GL implementation that returns 0.
3575 maxSampleCnt = std::max(1, maxSampleCnt);
3576
3577 for (int i = 0; i < kGrGLColorFormatCount; ++i) {
3578 if (FormatInfo::kFBOColorAttachmentWithMSAA_Flag & fFormatTable[i].fFlags) {
3579 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
3580 SkASSERT(FormatInfo::kFBOColorAttachment_Flag & fFormatTable[i].fFlags);
3581 SkASSERT(GrGLCaps::kNone_MSFBOType != fMSFBOType);
3582 if ((GR_IS_GR_GL(standard) &&
3583 (version >= GR_GL_VER(4,2) ||
3584 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
3585 (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0))) {
3586 // Implicite resolve may have a lower max samples than the per format MSAA.
3587 const bool multisampleIsImplicit =
3588 GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
3589 GrGLCaps::kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
3590 int count;
3591 GrGLFormat grGLFormat = static_cast<GrGLFormat>(i);
3592 GrGLenum glFormat = this->getRenderbufferInternalFormat(grGLFormat);
3593 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, glFormat,
3594 GR_GL_NUM_SAMPLE_COUNTS, 1, &count);
3595 if (count) {
3596 std::unique_ptr<int[]> temp(new int[count]);
3597 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, glFormat, GR_GL_SAMPLES,
3598 count, temp.get());
3599 // GL has a concept of MSAA rasterization with a single sample but we do not.
3600 if (count && temp[count - 1] == 1) {
3601 --count;
3602 SkASSERT(!count || temp[count -1] > 1);
3603 }
3604 fFormatTable[i].fColorSampleCounts.reserve(count + 1);
3605 // We initialize our supported values with 1 (no msaa) and reverse the order
3606 // returned by GL so that the array is ascending.
3607 fFormatTable[i].fColorSampleCounts.push_back(1);
3608 for (int j = 0; j < count; ++j) {
3609 #if defined(SK_BUILD_FOR_IOS) && TARGET_OS_SIMULATOR
3610 // The iOS simulator is reporting incorrect values for sample counts,
3611 // so force them to be a power of 2.
3612 int sampleCnt = SkPrevPow2(temp[count - j - 1]);
3613 #else
3614 int sampleCnt = temp[count - j - 1];
3615 #endif
3616 if (multisampleIsImplicit && sampleCnt > maxSampleCnt) {
3617 break;
3618 }
3619 fFormatTable[i].fColorSampleCounts.push_back(sampleCnt);
3620 }
3621 }
3622 } else {
3623 // Fake out the table using some semi-standard counts up to the max allowed sample
3624 // count.
3625 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
3626 int count = std::size(kDefaultSamples);
3627 for (; count > 0; --count) {
3628 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
3629 break;
3630 }
3631 }
3632 if (count > 0) {
3633 fFormatTable[i].fColorSampleCounts.append(count, kDefaultSamples);
3634 }
3635 }
3636 } else if (FormatInfo::kFBOColorAttachment_Flag & fFormatTable[i].fFlags) {
3637 fFormatTable[i].fColorSampleCounts.resize(1);
3638 fFormatTable[i].fColorSampleCounts[0] = 1;
3639 }
3640 }
3641 }
3642
3643 bool GrGLCaps::canCopyTexSubImage(GrGLFormat dstFormat, bool dstHasMSAARenderBuffer,
3644 const GrTextureType* dstTypeIfTexture,
3645 GrGLFormat srcFormat, bool srcHasMSAARenderBuffer,
3646 const GrTextureType* srcTypeIfTexture) const {
3647 // When it comes to format types and component sizes the gl spec is fairly complex as
3648 // requirements differ depending on many properties (e.g. if the internalFormat was created with
3649 // a sized format or not). These affect the rules about which format types can be copied to
3650 // which other types. For now we are being more restrictive and requiring that the types must
3651 // match exactly.
3652 if (this->getFormatDefaultExternalType(dstFormat) !=
3653 this->getFormatDefaultExternalType(srcFormat)) {
3654 return false;
3655 }
3656
3657 // Either both the src and dst formats need to be SRGB or both need to not be SRGB
3658 if (GrGLFormatIsSRGB(dstFormat) != GrGLFormatIsSRGB(srcFormat)) {
3659 return false;
3660 }
3661
3662 if (GR_IS_GR_GL_ES(fStandard)) {
3663 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
3664 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it.
3665 // ANGLE, for one, does not allow it. However, we've found it works on some drivers and
3666 // avoids bugs with using glBlitFramebuffer.
3667 if ((dstFormat == GrGLFormat::kBGRA8 || srcFormat == GrGLFormat::kBGRA8) &&
3668 !fAllowBGRA8CopyTexSubImage) {
3669 return false;
3670 }
3671
3672 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
3673 // and SRGB isn't in the spec. There doesn't appear to be any extension that adds it.
3674 // ANGLE, for one, does not allow it. However, we've found it works on some drivers and
3675 // avoids bugs with using glBlitFramebuffer.
3676 if ((GrGLFormatIsSRGB(dstFormat) || GrGLFormatIsSRGB(srcFormat)) &&
3677 !fAllowSRGBCopyTexSubImage) {
3678 return false;
3679 }
3680
3681 // Table 3.9 of the ES2 spec and 3.16 of ES3 spec indicates the supported internal base
3682 // formats with CopyTexSubImage. Each base format can be copied to itself or formats with
3683 // less channels.
3684 uint32_t dstChannels = GrGLFormatChannels(dstFormat);
3685 uint32_t srcChannels = GrGLFormatChannels(srcFormat);
3686 if (!dstChannels || !srcChannels) {
3687 // The formats don't represent color channels (i.e. may be depth stencil)
3688 return false;
3689 }
3690 // The dst channels have to be a subset of the srcChannels, except R, RG, or RGB, channels
3691 // can go to LUM. (See expansion of Table 3.9 in EXT_texture_rg).
3692 if ((dstChannels & srcChannels) != srcChannels) {
3693 if (dstChannels == kGray_SkColorChannelFlag ||
3694 dstChannels == kGrayAlpha_SkColorChannelFlags) {
3695 // The dst can't have gray if the src is alpha-only.
3696 if (srcChannels == kAlpha_SkColorChannelFlag) {
3697 return false;
3698 }
3699 } else {
3700 return false;
3701 }
3702 }
3703 }
3704
3705 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
3706 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
3707 return false;
3708 }
3709
3710 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
3711 // texture.
3712 if (!dstTypeIfTexture) {
3713 return false;
3714 }
3715
3716 // Check that we could wrap the source in an FBO, that the dst is not TEXTURE_EXTERNAL, that no
3717 // mirroring is required
3718 return this->canFormatBeFBOColorAttachment(srcFormat) &&
3719 (!srcTypeIfTexture || *srcTypeIfTexture != GrTextureType::kExternal) &&
3720 *dstTypeIfTexture != GrTextureType::kExternal;
3721 }
3722
3723 bool GrGLCaps::canCopyAsBlit(GrGLFormat dstFormat, int dstSampleCnt,
3724 const GrTextureType* dstTypeIfTexture,
3725 GrGLFormat srcFormat, int srcSampleCnt,
3726 const GrTextureType* srcTypeIfTexture,
3727 const SkRect& srcBounds, bool srcBoundsExact,
3728 const SkIRect& srcRect, const SkIRect& dstRect) const {
3729 auto blitFramebufferFlags = fBlitFramebufferFlags;
3730 if (!this->canFormatBeFBOColorAttachment(dstFormat) ||
3731 !this->canFormatBeFBOColorAttachment(srcFormat)) {
3732 return false;
3733 }
3734
3735 if (dstTypeIfTexture && *dstTypeIfTexture == GrTextureType::kExternal) {
3736 return false;
3737 }
3738 if (srcTypeIfTexture && *srcTypeIfTexture == GrTextureType::kExternal) {
3739 return false;
3740 }
3741
3742 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
3743 return false;
3744 }
3745
3746 if (dstSampleCnt > 1 && dstSampleCnt != srcSampleCnt) {
3747 // Regardless of support-level, all blits require src and dst sample counts to match if
3748 // the dst is MSAA.
3749 return false;
3750 }
3751
3752 if (srcRect.width() != dstRect.width() || srcRect.height() != dstRect.height()) {
3753 // If the blit would scale contents, it's only valid for non-MSAA framebuffers that we
3754 // can write directly to.
3755 if ((GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) ||
3756 this->useDrawInsteadOfAllRenderTargetWrites() || srcSampleCnt > 1) {
3757 return false;
3758 }
3759 }
3760
3761 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
3762 if (srcSampleCnt > 1) {
3763 if (1 == dstSampleCnt) {
3764 return false;
3765 }
3766 if (SkRect::Make(srcRect) != srcBounds || !srcBoundsExact) {
3767 return false;
3768 }
3769 }
3770 }
3771
3772 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
3773 if (dstSampleCnt > 1) {
3774 return false;
3775 }
3776 }
3777
3778 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
3779 if (srcFormat != dstFormat) {
3780 return false;
3781 }
3782 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
3783 if (srcSampleCnt > 1 && srcFormat != dstFormat) {
3784 return false;
3785 }
3786 }
3787
3788 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
3789 if (srcSampleCnt > 1) {
3790 if (dstRect != srcRect) {
3791 return false;
3792 }
3793 }
3794 }
3795 return true;
3796 }
3797
3798 bool GrGLCaps::canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTexturable, bool scalingCopy) const {
3799 return this->isFormatRenderable(dstFormat, 1) &&
3800 srcIsTexturable &&
3801 !(fDisableScalingCopyAsDraws && scalingCopy);
3802 }
3803
3804 static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
3805 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
3806 if (!rt) {
3807 return false;
3808 }
3809 // A RT has a separate MSAA renderbuffer if:
3810 // 1) It's multisampled
3811 // 2) We're using an extension with separate MSAA renderbuffers
3812 // 3) It's not FBO 0, which is special and always auto-resolves
3813 return rt->numSamples() > 1 &&
3814 glCaps.usesMSAARenderBuffers() &&
3815 !rt->glRTFBOIDIs0();
3816 }
3817
3818 bool GrGLCaps::onCanCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect,
3819 const GrSurfaceProxy* src, const SkIRect& srcRect) const {
3820 if (src->isProtected() == GrProtected::kYes && dst->isProtected() != GrProtected::kYes) {
3821 return false;
3822 }
3823
3824 int dstSampleCnt = 0;
3825 int srcSampleCnt = 0;
3826 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
3827 dstSampleCnt = rtProxy->numSamples();
3828 }
3829 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
3830 srcSampleCnt = rtProxy->numSamples();
3831 }
3832 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
3833 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
3834
3835 const GrTextureProxy* dstTex = dst->asTextureProxy();
3836 const GrTextureProxy* srcTex = src->asTextureProxy();
3837
3838 GrTextureType dstTexType;
3839 GrTextureType* dstTexTypePtr = nullptr;
3840 GrTextureType srcTexType;
3841 GrTextureType* srcTexTypePtr = nullptr;
3842 if (dstTex) {
3843 dstTexType = dstTex->textureType();
3844 dstTexTypePtr = &dstTexType;
3845 }
3846 if (srcTex) {
3847 srcTexType = srcTex->textureType();
3848 srcTexTypePtr = &srcTexType;
3849 }
3850
3851 auto dstFormat = GrBackendFormats::AsGLFormat(dst->backendFormat());
3852 auto srcFormat = GrBackendFormats::AsGLFormat(src->backendFormat());
3853 // Only copyAsBlit() and copyAsDraw() can handle scaling between src and dst.
3854 const bool scalingCopy = srcRect.size() != dstRect.size();
3855 if (!scalingCopy &&
3856 this->canCopyTexSubImage(dstFormat, has_msaa_render_buffer(dst, *this), dstTexTypePtr,
3857 srcFormat, has_msaa_render_buffer(src, *this), srcTexTypePtr)) {
3858 return true;
3859 }
3860 return this->canCopyAsBlit(dstFormat, dstSampleCnt, dstTexTypePtr, srcFormat, srcSampleCnt,
3861 srcTexTypePtr, src->getBoundsRect(), src->priv().isExact(), srcRect,
3862 dstRect) ||
3863 this->canCopyAsDraw(dstFormat, SkToBool(srcTex), scalingCopy);
3864 }
3865
3866 GrCaps::DstCopyRestrictions GrGLCaps::getDstCopyRestrictions(const GrRenderTargetProxy* src,
3867 GrColorType colorType) const {
3868 // If the src is a texture, we can implement the blit as a draw assuming the config is
3869 // renderable.
3870 if (src->asTextureProxy() && !this->isFormatAsColorTypeRenderable(colorType,
3871 src->backendFormat())) {
3872 return {};
3873 }
3874
3875 if (const auto* texProxy = src->asTextureProxy()) {
3876 if (texProxy->textureType() == GrTextureType::kExternal) {
3877 // Not supported for FBO blit or CopyTexSubImage. Caller will have to fall back to a
3878 // draw (if the source is also a texture).
3879 return {};
3880 }
3881 }
3882
3883 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
3884 // possible and we return false to fallback to creating a render target dst for render-to-
3885 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
3886 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
3887 DstCopyRestrictions blitFramebufferRestrictions = {};
3888 if (src->numSamples() > 1 &&
3889 (fBlitFramebufferFlags & kResolveMustBeFull_BlitFrambufferFlag)) {
3890 blitFramebufferRestrictions.fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kYes;
3891 blitFramebufferRestrictions.fMustCopyWholeSrc = true;
3892 // Mirroring causes rects to mismatch later, don't allow it.
3893 } else if (src->numSamples() > 1 && (fBlitFramebufferFlags &
3894 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
3895 blitFramebufferRestrictions.fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kYes;
3896 }
3897
3898 auto srcFormat = GrBackendFormats::AsGLFormat(src->backendFormat());
3899 // Check for format issues with glCopyTexSubImage2D
3900 if (srcFormat == GrGLFormat::kBGRA8) {
3901 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
3902 // then we set up for that, otherwise fail.
3903 if (this->canFormatBeFBOColorAttachment(srcFormat)) {
3904 return blitFramebufferRestrictions;
3905 }
3906 // Caller will have to use a draw.
3907 return {};
3908 }
3909
3910 {
3911 bool srcIsMSAARenderbuffer = src->numSamples() > 1 &&
3912 this->usesMSAARenderBuffers();
3913 if (srcIsMSAARenderbuffer) {
3914 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
3915 // blit or fail.
3916 if (this->canFormatBeFBOColorAttachment(srcFormat)) {
3917 return blitFramebufferRestrictions;
3918 }
3919 // Caller will have to use a draw.
3920 return {};
3921 }
3922 }
3923
3924 // We'll do a CopyTexSubImage, no restrictions.
3925 return {};
3926 }
3927
3928 void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
3929 const GrContextOptions& contextOptions,
3930 const GrGLInterface* glInterface,
3931 GrShaderCaps* shaderCaps,
3932 FormatWorkarounds* formatWorkarounds) {
3933 GrGLDriverVersion driverVersion =
3934 ctxInfo.angleBackend() == GrGLANGLEBackend::kUnknown ? ctxInfo.driverVersion()
3935 : ctxInfo.angleDriverVersion();
3936
3937 // A driver bug on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
3938 // Thus we are disabling this extension for now on Adreno4xx devices.
3939 if (ctxInfo.renderer() == GrGLRenderer::kAdreno430 ||
3940 ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other ||
3941 fDriverBugWorkarounds.disable_discard_framebuffer) {
3942 fInvalidateFBType = kNone_InvalidateFBType;
3943 }
3944
3945 if (ctxInfo.renderer() == GrGLRenderer::kIntelCherryView) {
3946 // When running DMSAA_dst_read_with_existing_barrier with DMSAA disabled on linux Intel
3947 // HD405, the test fails when using texture barriers. Oddly the gpu doing the draw which
3948 // uses the barrier correctly. It is the next draw, which does not use or need a barrier,
3949 // that is blending with a dst as if the barrier draw didn't happen. Since this GPU is not
3950 // that important to us and this driver bug could probably manifest itself in the wild, we
3951 // are just disabling texture barrier support for the gpu.
3952 fTextureBarrierSupport = false;
3953 }
3954
3955 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
3956 // 340.96 and 367.57.
3957 if (GR_IS_GR_GL(ctxInfo.standard()) && ctxInfo.driver() == GrGLDriver::kNVIDIA &&
3958 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
3959 fClearTextureSupport = false;
3960 }
3961
3962 // glBlitFramebuffer seems to produce incorrect results on QC, Mali400, and Tegra3 but
3963 // glCopyTexSubImage2D works (even though there is no extension that specifically allows it).
3964 if (ctxInfo.vendor() == GrGLVendor::kQualcomm ||
3965 ctxInfo.renderer() == GrGLRenderer::kMali4xx ||
3966 ctxInfo.renderer() == GrGLRenderer::kTegra_PreK1) {
3967 fAllowBGRA8CopyTexSubImage = true;
3968 }
3969 // glCopyTexSubImage2D works for sRGB with GLES 3.0 and on some GPUs with GLES 2.0
3970 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
3971 ctxInfo.renderer() == GrGLRenderer::kMali4xx ||
3972 ctxInfo.renderer() == GrGLRenderer::kTegra_PreK1) {
3973 fAllowSRGBCopyTexSubImage = true;
3974 }
3975
3976 // Originally, this condition disabled DMSAA on non-Intel (and some Intel) devices running over
3977 // ANGLE D3D11 (http://anglebug.com/6030). ANGLE's D3D11 support for
3978 // EXT_multisample_render_to_texture was incomplete and has been removed
3979 // (http://crbug.com/443111620), which led to some significant performance regressions
3980 // (http://crbug.com/466515405). Since ANGLE had always been advertising that extension, Ganesh
3981 // was disabling DMSAA almost universally. The regression was triggered due to allocating very
3982 // large MSAA attachments. To preserve prior behavior on ANGLE+D3D11, we will keep DMSAA
3983 // disabled (although these techniques are used with Graphite on Dawn+D3D11).
3984 if (/* fMSFBOType == kES_EXT_MsToTexture_MSFBOType && */
3985 ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D11) {
3986 // As GL_EXT_multisampled_render_to_texture supporting issue,
3987 // fall back to default dmsaa path
3988 if ((ctxInfo.vendor() == GrGLVendor::kIntel ||
3989 ctxInfo.angleVendor() == GrGLVendor::kIntel) &&
3990 ctxInfo.renderer() >= GrGLRenderer::kIntelIceLake) {
3991 fMSFBOType = kStandard_MSFBOType;
3992 fMSAAResolvesAutomatically = false;
3993 }
3994 else {
3995 fDisallowDynamicMSAA = true;
3996 }
3997 }
3998
3999 // skbug.com/40043172
4000 if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
4001 fDisallowDynamicMSAA = true;
4002 }
4003
4004 // Below we are aggressive about turning off all mapping/transfer functionality together. This
4005 // could be finer grained if code paths and tests were adjusted to check more specific caps.
4006 // For example it might be possible to support buffer to buffer transfers even if buffer mapping
4007 // or buffer to surface transfers don't work.
4008 #if defined(__has_feature)
4009 #if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
4010 // See skbug.com/40038290
4011 fMapBufferType = kNone_MapBufferType;
4012 fMapBufferFlags = kNone_MapFlags;
4013 fTransferFromBufferToTextureSupport = false;
4014 fTransferFromSurfaceToBufferSupport = false;
4015 fTransferFromBufferToBufferSupport = false;
4016 fTransferBufferType = TransferBufferType::kNone;
4017 #endif
4018 #endif
4019
4020 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
4021 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
4022 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
4023 // unclear whether this really affects a wide range of devices.
4024 if (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx &&
4025 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
4026 fMapBufferType = kNone_MapBufferType;
4027 fMapBufferFlags = kNone_MapFlags;
4028 fTransferFromBufferToTextureSupport = false;
4029 fTransferFromSurfaceToBufferSupport = false;
4030 fTransferFromBufferToBufferSupport = false;
4031 fTransferBufferType = TransferBufferType::kNone;
4032 }
4033
4034 // The TransferPixelsToTexture test fails on ANGLE D3D9 and D3D11 if this is enabled.
4035 // https://anglebug.com/5542
4036 if (angle_backend_is_d3d(ctxInfo.angleBackend())) {
4037 fTransferPixelsToRowBytesSupport = false;
4038 }
4039
4040 // Using MIPs on this GPU seems to be a source of trouble.
4041 if (ctxInfo.renderer() == GrGLRenderer::kPowerVR54x) {
4042 fMipmapSupport = false;
4043 }
4044
4045 #ifdef SK_BUILD_FOR_ANDROID
4046 if (ctxInfo.renderer() == GrGLRenderer::kPowerVR54x) {
4047 // Flutter found glTexSubImage2D for GL_RED is much slower than GL_ALPHA on the
4048 // "MC18 PERSONAL SHOPPER"
4049 formatWorkarounds->fDisallowR8ForPowerVRSGX54x = true;
4050 }
4051 #endif
4052
4053 // Reported on skia-discuss as occurring with these GL strings:
4054 // GL_VERSION: 3.1.0 - Build 9.17.10.4459
4055 // GL_VENDOR: Intel
4056 // GL_RENDERER: Intel(R) HD Graphics 2000
4057 // https://groups.google.com/g/skia-discuss/c/dYV1blEAda0/m/-zuZLXQKAwAJ?utm_medium=email&utm_source=footer
4058 // See also skbug.com/40040603
4059 if (ctxInfo.renderer() == GrGLRenderer::kIntelSandyBridge &&
4060 ctxInfo.driver() == GrGLDriver::kIntel) {
4061 fMapBufferType = kNone_MapBufferType;
4062 fMapBufferFlags = kNone_MapFlags;
4063 // On skia-discuss it was reported that after turning off mapping there was this
4064 // shader compilation error.
4065 // ERROR: 0:18: 'assign' : cannot convert from '3-component vector of float' to 'varying 2-component vector of float'
4066 // for this line:
4067 // vTransformedCoords_5_S0 = mat3x2(umatrix_S1_c0_c1) * vec3(_tmp_2_inPosition, 1.0);
4068 fShaderCaps->fNonsquareMatrixSupport = false;
4069 }
4070
4071 if (ctxInfo.isOverCommandBuffer() && ctxInfo.version() >= GR_GL_VER(3,0)) {
4072 formatWorkarounds->fDisallowTextureUnorm16 = true; // http://crbug.com/1224108
4073 formatWorkarounds->fDisallowETC2Compression = true; // http://crbug.com/1224111
4074 fTransferFromSurfaceToBufferSupport = false; // http://crbug.com/1224138
4075
4076 // http://crbug.com/1224117
4077 fMapBufferFlags = kNone_MapFlags;
4078 fMapBufferType = kNone_MapBufferType;
4079 }
4080
4081 // https://b.corp.google.com/issues/143074513
4082 // https://skbug.com/40042528
4083 if (ctxInfo.renderer() == GrGLRenderer::kAdreno615 ||
4084 ctxInfo.renderer() == GrGLRenderer::kAdreno620) {
4085 fMSFBOType = kNone_MSFBOType;
4086 fMSAAResolvesAutomatically = false;
4087 }
4088
4089 #ifndef SK_BUILD_FOR_IOS
4090 if (ctxInfo.renderer() == GrGLRenderer::kPowerVR54x ||
4091 ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue ||
4092 (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx && !ctxInfo.isOverCommandBuffer())) {
4093 fPerformColorClearsAsDraws = true;
4094 }
4095 #endif
4096
4097 // A lot of GPUs have trouble with full screen clears (skbug.com/40038435)
4098 if (ctxInfo.renderer() == GrGLRenderer::kAMDRadeonHD7xxx ||
4099 ctxInfo.renderer() == GrGLRenderer::kAMDRadeonR9M4xx) {
4100 fPerformColorClearsAsDraws = true;
4101 }
4102
4103 #ifdef SK_BUILD_FOR_MAC
4104 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
4105 // full screen clears
4106 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
4107 // perform full screen clears.
4108 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
4109 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
4110 // crbug.com/1039912 - Crash rate in glClear spiked after OS update, affecting mostly
4111 // Broadwell on 10.13+
4112 if (ctxInfo.vendor() == GrGLVendor::kIntel &&
4113 (ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12) ||
4114 ctxInfo.renderer() == GrGLRenderer::kIntelBroadwell)) {
4115 fPerformColorClearsAsDraws = true;
4116 }
4117 // crbug.com/969609 - NVIDIA on Mac sometimes segfaults during glClear in chrome. It seems
4118 // mostly concentrated in 10.13/14, GT 650Ms, driver 12+. But there are instances of older
4119 // drivers and GTX 775s, so we'll start with a broader workaround.
4120 if (ctxInfo.vendor() == GrGLVendor::kNVIDIA) {
4121 fPerformColorClearsAsDraws = true;
4122 }
4123 #endif
4124
4125 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
4126 // bugs seems to involve clearing too much and not skipping the clear.
4127 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
4128 // but only for D3D11 ANGLE.
4129 if (ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D11) {
4130 fPerformColorClearsAsDraws = true;
4131 }
4132
4133 if (ctxInfo.renderer() == GrGLRenderer::kAdreno430 ||
4134 ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other) {
4135 // This is known to be fixed sometime between driver 145.0 and 219.0
4136 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
4137 fPerformStencilClearsAsDraws = true;
4138 }
4139 // This is known to be fixed sometime between driver 129.0 and 145.0 on Nexus 6P.
4140 // On driver 129 on Android M it fails the unit tests called WritePixelsPendingIO without
4141 // the workaround. It passes on Android N with driver 145 without the workaround.
4142 // skbug.com/40042902
4143 if (ctxInfo.driverVersion() < GR_GL_DRIVER_VER(145, 0, 0)) {
4144 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
4145 }
4146 }
4147
4148 if (fDriverBugWorkarounds.gl_clear_broken) {
4149 fPerformColorClearsAsDraws = true;
4150 fPerformStencilClearsAsDraws = true;
4151 }
4152
4153 if (ctxInfo.vendor() == GrGLVendor::kQualcomm) {
4154 // It appears that all the Adreno GPUs have less than optimal performance when
4155 // drawing w/ large index buffers.
4156 fAvoidLargeIndexBufferDraws = true;
4157 }
4158
4159 if (ctxInfo.renderer() == GrGLRenderer::kMali4xx ||
4160 (ctxInfo.renderer() == GrGLRenderer::kWebGL &&
4161 ctxInfo.webglRenderer() == GrGLRenderer::kMali4xx)) {
4162 // Perspective SDF text runs significantly slower on Mali-4xx hardware
4163 fDisablePerspectiveSDFText = true;
4164 }
4165
4166 // This was reproduced on the following configurations:
4167 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
4168 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
4169 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
4170 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
4171 // and not produced on:
4172 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
4173 // The particular lines that get dropped from test images varies across different devices.
4174 if (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx &&
4175 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
4176 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
4177 }
4178
4179 // TODO: Don't apply this on iOS?
4180 if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue &&
4181 driverVersion < GR_GL_DRIVER_VER(23, 2, 0)) {
4182 // Our Chromebook with GrGLRenderer::kPowerVRRogue crashes on large instanced draws. The
4183 // current minimum number of instances observed to crash is somewhere between 2^14 and 2^15.
4184 // Keep the number of instances below 1000, just to be safe.
4185 fMaxInstancesPerDrawWithoutCrashing = 999;
4186 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
4187 fMaxInstancesPerDrawWithoutCrashing = 0x4000000;
4188 }
4189
4190 #ifndef SK_BUILD_FOR_IOS
4191 if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue) {
4192 // We saw this bug on a TecnoSpark 3 Pro with a PowerVR GE8300.
4193 // GL_VERSION: "OpenGL ES 3.2 build 1.10@51309121"
4194 // Possibly this could be more limited by driver version or HW generation.
4195 // When using samplers, we are seeing a bug where the gpu is sometimes not sampling the
4196 // correct mip level data. A workaround to this issue is that when binding a texture we also
4197 // set some texture state, and it seems like any inividual state works (e.g. min/mag filter,
4198 // base level, max level, etc.). Currently we just set the min filter level every time we
4199 // bind a texture as the workaround.
4200 fMustSetAnyTexParameterToEnableMipmapping = true;
4201 // ColorTypeBackendAllocationTest failed for kAlpha_8 and kGray_8 when using
4202 // GL_UNPACK_ROW_LENGTH. Perhaps this could be a more limited workaround by applying
4203 // only to single channel 8 bit unorm formats but we only have a monolithic query for this
4204 // support at present.
4205 fWritePixelsRowBytesSupport = false;
4206 // TransferPixelsToTextureTest fails for all color types on
4207 // TecnoSpark 3 Pro with a PowerVR GE8300, GL_VERSION: "OpenGL ES 3.2 build 1.10@51309121"
4208 // if GL_UNPACK_ROW_LENGTH is used.
4209 fTransferPixelsToRowBytesSupport = false;
4210 }
4211 #endif
4212
4213 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
4214 if (ctxInfo.renderer() == GrGLRenderer::kTegra_PreK1) {
4215 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
4216 fUseDrawInsteadOfAllRenderTargetWrites = true;
4217 }
4218
4219 #ifdef SK_BUILD_FOR_MAC
4220 static constexpr bool isMAC = true;
4221 #else
4222 static constexpr bool isMAC = false;
4223 #endif
4224
4225 #ifdef SK_BUILD_FOR_ANDROID
4226 // Older versions of Android have problems with setting GL_TEXTURE_BASE_LEVEL or
4227 // GL_TEXTURE_MAX_LEVEL on GL_TEXTURE_EXTERTNAL_OES textures. We just leave them as is and hope
4228 // the client never changes them either.
4229 fDontSetBaseOrMaxLevelForExternalTextures = true;
4230 // PowerVR can crash setting the levels on Android up to Q for any texture?
4231 // https://crbug.com/1123874
4232 if (ctxInfo.vendor() == GrGLVendor::kImagination) {
4233 fMipmapLevelControlSupport = false;
4234 }
4235 #endif
4236
4237 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
4238 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
4239 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
4240 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
4241 if (fMipmapLevelControlSupport &&
4242 !ctxInfo.isOverCommandBuffer() && // http://crbug.com/1224110
4243 (contextOptions.fDoManualMipmapping ||
4244 ctxInfo.vendor() == GrGLVendor::kIntel ||
4245 (ctxInfo.driver() == GrGLDriver::kNVIDIA && isMAC) ||
4246 ctxInfo.vendor() == GrGLVendor::kATI)) {
4247 fDoManualMipmapping = true;
4248 }
4249
4250 // See http://crbug.com/710443
4251 #ifdef SK_BUILD_FOR_MAC
4252 if (ctxInfo.renderer() == GrGLRenderer::kIntelBroadwell) {
4253 fClearToBoundaryValuesIsBroken = true;
4254 }
4255 #endif
4256 if (ctxInfo.vendor() == GrGLVendor::kQualcomm) {
4257 fDrawArraysBaseVertexIsBroken = true;
4258 }
4259
4260 // b/40043081, b/40045491: indirect draws in ANGLE + D3D are very slow
4261 if (ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D9 ||
4262 ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D11) {
4263 fBaseVertexBaseInstanceSupport = false;
4264 fNativeDrawIndirectSupport = false;
4265 fMultiDrawType = MultiDrawType::kNone;
4266 }
4267
4268 // https://b.corp.google.com/issues/188410972
4269 if (ctxInfo.isRunningOverVirgl()) {
4270 fDrawInstancedSupport = false;
4271 }
4272
4273 // http://anglebug.com/4538
4274 if (fBaseVertexBaseInstanceSupport && !fDrawInstancedSupport) {
4275 fBaseVertexBaseInstanceSupport = false;
4276 fNativeDrawIndirectSupport = false;
4277 fMultiDrawType = MultiDrawType::kNone;
4278 }
4279
4280 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
4281 // Galaxy S7.
4282 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
4283 if (ctxInfo.renderer() == GrGLRenderer::kAdreno530 ||
4284 ctxInfo.renderer() == GrGLRenderer::kAdreno5xx_other) {
4285 shaderCaps->fFBFetchSupport = false;
4286 }
4287
4288 if (ctxInfo.renderer() == GrGLRenderer::kTegra_PreK1) {
4289 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
4290 // so we must do the abs first in a separate expression.
4291 shaderCaps->fCanUseMinAndAbsTogether = false;
4292
4293 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
4294 // must avoid this condition.
4295 shaderCaps->fCanUseFractForNegativeValues = false;
4296 }
4297
4298 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
4299 // thus must us -1.0 * %s.x to work correctly
4300 if (ctxInfo.vendor() == GrGLVendor::kIntel) {
4301 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
4302 }
4303
4304 #if defined(SK_BUILD_FOR_MAC)
4305 if (ctxInfo.vendor() == GrGLVendor::kATI) {
4306 // The Radeon GLSL compiler on Mac gets confused by ldexp(..., -x).
4307 // Convert to ldexp(..., x * -1).
4308 // skbug.com/40043167
4309 shaderCaps->fMustForceNegatedLdexpParamToMultiply = true;
4310 }
4311 #endif
4312
4313 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
4314 // when floor and abs are called on the same line. Thus we must execute an Op between them to
4315 // make sure the compiler doesn't re-inline them even if we break the calls apart.
4316 if (ctxInfo.vendor() == GrGLVendor::kIntel) {
4317 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
4318 }
4319
4320 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
4321 // the original dst color when reading the outColor even after being written to. By using a
4322 // local outColor we can work around this bug.
4323 if (shaderCaps->fFBFetchSupport && ctxInfo.vendor() == GrGLVendor::kQualcomm) {
4324 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
4325 }
4326
4327 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
4328 // color, and that uniform contains an opaque color, and the output of the shader is only based
4329 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
4330 // that the shader always outputs opaque values. In that case, it appears to remove the shader
4331 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
4332 // insert an extra bit of math on the uniform that confuses the compiler just enough...
4333 if (ctxInfo.renderer() == GrGLRenderer::kMaliT) {
4334 shaderCaps->fMustObfuscateUniformColor = true;
4335 }
4336
4337 #if defined(SK_BUILD_FOR_ANDROID)
4338 // On the following GPUs, the Perlin noise code needs to aggressively snap to multiples
4339 // of 1/255 to avoid artifacts in the double table lookup:
4340 // Tegra3, PowerVRGE8320 (Wembley), MaliG76, and Adreno308
4341 // Given the range of vendors we're just blanket enabling it on Android for OpenGL.
4342 fShaderCaps->fPerlinNoiseRoundingFix = true;
4343 #endif
4344
4345 // On Mali 400 there is a bug using dFd* in the x direction. So we avoid using it when possible.
4346 if (ctxInfo.renderer() == GrGLRenderer::kMali4xx) {
4347 fShaderCaps->fAvoidDfDxForGradientsWhenPossible = true;
4348 }
4349
4350 #ifdef SK_BUILD_FOR_WIN
4351 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
4352 //
4353 // Basically, if a shader has a construct like:
4354 //
4355 // float x = someCondition ? someValue : 0;
4356 // float2 result = (0 == x) ? float2(x, x)
4357 // : float2(2 * x / x, 0);
4358 //
4359 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
4360 // we've explicitly guarded the division with a check against zero. This manifests in much
4361 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
4362 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
4363 if (angle_backend_is_d3d(ctxInfo.angleBackend()) || ctxInfo.isOverCommandBuffer()) {
4364 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
4365 }
4366 #endif
4367
4368 // The Adreno 5xx and 6xx produce incorrect results when comparing a pair of matrices.
4369 if (ctxInfo.renderer() == GrGLRenderer::kAdreno530 ||
4370 ctxInfo.renderer() == GrGLRenderer::kAdreno5xx_other ||
4371 ctxInfo.renderer() == GrGLRenderer::kAdreno615 ||
4372 ctxInfo.renderer() == GrGLRenderer::kAdreno620 ||
4373 ctxInfo.renderer() == GrGLRenderer::kAdreno630 ||
4374 ctxInfo.renderer() == GrGLRenderer::kAdreno640 ||
4375 ctxInfo.renderer() == GrGLRenderer::kAdreno6xx_other) {
4376 shaderCaps->fRewriteMatrixComparisons = true;
4377 }
4378
4379 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
4380 // (rare) situations. It's sporadic, and mostly on older drivers. Additionally, old Adreno
4381 // compilers (see skbug.com/40035225) crash when accessing .zw of gl_FragCoord, so just bypass
4382 // using gl_FragCoord at all to get around it.
4383 if (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx) {
4384 shaderCaps->fCanUseFragCoord = false;
4385 }
4386
4387 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
4388 if (ctxInfo.renderer() == GrGLRenderer::kTegra_PreK1) {
4389 shaderCaps->fCanUseFragCoord = false;
4390 }
4391
4392 if (fDriverBugWorkarounds.add_and_true_to_loop_condition) {
4393 shaderCaps->fAddAndTrueToLoopCondition = true;
4394 }
4395
4396 if (fDriverBugWorkarounds.unfold_short_circuit_as_ternary_operation) {
4397 shaderCaps->fUnfoldShortCircuitAsTernary = true;
4398 }
4399
4400 if (fDriverBugWorkarounds.emulate_abs_int_function) {
4401 shaderCaps->fEmulateAbsIntFunction = true;
4402 }
4403
4404 if (fDriverBugWorkarounds.rewrite_do_while_loops) {
4405 shaderCaps->fRewriteDoWhileLoops = true;
4406 }
4407
4408 if (fDriverBugWorkarounds.remove_pow_with_constant_exponent) {
4409 shaderCaps->fRemovePowWithConstantExponent = true;
4410 }
4411
4412 if (fDriverBugWorkarounds.disable_dual_source_blending_support) {
4413 shaderCaps->fDualSourceBlendingSupport = false;
4414 }
4415
4416 if (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx ||
4417 ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other) {
4418 shaderCaps->fMustWriteToFragColor = true;
4419 }
4420
4421 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
4422 // command buffer for now until its own denylists can be updated.
4423 if (ctxInfo.renderer() == GrGLRenderer::kAdreno430 ||
4424 ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other ||
4425 ctxInfo.renderer() == GrGLRenderer::kAdreno530 ||
4426 ctxInfo.renderer() == GrGLRenderer::kAdreno5xx_other ||
4427 ctxInfo.driver() == GrGLDriver::kIntel ||
4428 ctxInfo.angleVendor() == GrGLVendor::kIntel ||
4429 ctxInfo.isOverCommandBuffer() ||
4430 ctxInfo.vendor() == GrGLVendor::kARM /* skbug.com/40043001 */) {
4431 fBlendEquationSupport = kBasic_BlendEquationSupport;
4432 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
4433 }
4434
4435 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
4436 if (((ctxInfo.driver() == GrGLDriver::kNVIDIA &&
4437 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0)) ||
4438 (ctxInfo.angleBackend() == GrGLANGLEBackend::kOpenGL &&
4439 ctxInfo.angleDriver() == GrGLDriver::kNVIDIA &&
4440 ctxInfo.angleDriverVersion() < GR_GL_DRIVER_VER(337, 00, 0))) &&
4441 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
4442 fBlendEquationSupport = kBasic_BlendEquationSupport;
4443 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
4444 }
4445
4446 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
4447 fBlendEquationSupport = kBasic_BlendEquationSupport;
4448 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
4449 }
4450
4451 if (this->advancedBlendEquationSupport()) {
4452 if ((ctxInfo.driver() == GrGLDriver::kNVIDIA &&
4453 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) ||
4454 (ctxInfo.angleBackend() == GrGLANGLEBackend::kOpenGL &&
4455 ctxInfo.angleDriver() == GrGLDriver::kNVIDIA &&
4456 ctxInfo.angleDriverVersion() < GR_GL_DRIVER_VER(355, 00, 0))) {
4457 // Disable color-dodge and color-burn on pre-355.00 NVIDIA.
4458 fAdvBlendEqDisableFlags |= (1 << static_cast<int>(skgpu::BlendEquation::kColorDodge)) |
4459 (1 << static_cast<int>(skgpu::BlendEquation::kColorBurn));
4460 }
4461 if (ctxInfo.vendor() == GrGLVendor::kARM) {
4462 // Disable color-burn on ARM until the fix is released.
4463 fAdvBlendEqDisableFlags |= (1 << static_cast<int>(skgpu::BlendEquation::kColorBurn));
4464 }
4465 }
4466
4467 // On Adreno 5xx devices, there is a bug where we first draw using dual source blending. Thus
4468 // the dst blend func references the dst. Then the next draw we disable blending. However, on
4469 // the second draw the driver has a bug where it tries to access the second color output again.
4470 // This is fixed by reseting the blend function to anything that does not reference src2 when we
4471 // disable blending.
4472 if (ctxInfo.renderer() == GrGLRenderer::kAdreno530 ||
4473 ctxInfo.renderer() == GrGLRenderer::kAdreno5xx_other ||
4474 ctxInfo.renderer() == GrGLRenderer::kAdreno620 ||
4475 ctxInfo.renderer() == GrGLRenderer::kAdreno640) {
4476 fMustResetBlendFuncBetweenDualSourceAndDisable = true;
4477 }
4478
4479 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
4480 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
4481 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
4482 // skbug.com/40038974
4483 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
4484 ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k330 &&
4485 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
4486 shaderCaps->fExternalTextureSupport = true;
4487 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
4488 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
4489 }
4490
4491 #ifdef SK_BUILD_FOR_IOS
4492 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
4493 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
4494 // is to just disable the feature.
4495 // https://github.com/flutter/flutter/issues/16718
4496 // https://bugreport.apple.com/web/?problemID=39948888
4497 fWritePixelsRowBytesSupport = false;
4498 // This affects all iOS devices for transfering from a PBO as well (presumably the issue is in
4499 // the GL->Metal layer).
4500 fTransferPixelsToRowBytesSupport = false;
4501 #endif
4502
4503 if (ctxInfo.vendor() == GrGLVendor::kIntel || // IntelIris640 drops draws completely.
4504 ctxInfo.webglVendor() == GrGLVendor::kIntel || // Disable if the webgl vendor is Intel
4505 ctxInfo.renderer() == GrGLRenderer::kMaliT || // Some curves appear flat on GalaxyS6.
4506 ctxInfo.renderer() == GrGLRenderer::kAdreno3xx ||
4507 ctxInfo.renderer() == GrGLRenderer::kAdreno430 ||
4508 ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other || // We get garbage on Adreno405.
4509 ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D9) { // D3D9 conic strokes fail.
4510 fDisableTessellationPathRenderer = true;
4511 }
4512 // We found that on Wembley devices (PowerVR GE8320) that using tessellation path renderer would
4513 // cause lots of rendering errors where it seemed like vertices were in the wrong place. This
4514 // led to lots of GMs drawing nothing (e.g. dashing4) or lots of garbage. The Wembley devices
4515 // were running Android 12 with a driver version of 1.13. We previously had TecnoSpark devices
4516 // with the same GPU running on Android P (driver 1.10) which did not have this issue. We don't
4517 // know when the bug appeared in the driver so for now we disable tessellation path renderer for
4518 // all matching gpus regardless of driver version.
4519 //
4520 // 2022-10-28 Update: Testing via Flutter found this is not a problem on driver version 1.15.
4521 // See https://github.com/flutter/flutter/issues/113596
4522 // GL_VERSION : OpenGL ES 3.1 build 1.15@6133109
4523 // GL_RENDERER: PowerVR Rogue AXE-1-16M
4524 // GL_VENDOR : Imagination Technologies
4525 if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue &&
4526 driverVersion < GR_GL_DRIVER_VER(1, 15, 0)) {
4527 fDisableTessellationPathRenderer = true;
4528 }
4529
4530 // The Wembley device draws the mesh_update GM incorrectly when using transfer buffers. Buffer
4531 // to buffer transfers affect draws earlier in the GL command sequence.
4532 // Android API: 31
4533 // GL_VERSION : OpenGL ES 3.2 build 1.13@5720833
4534 // GL_RENDERER: PowerVR Rogue GE8300
4535 // GL_VENDOR : Imagination Technologies
4536 if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue) {
4537 fTransferFromBufferToBufferSupport = false;
4538 }
4539
4540 // The Wembley device fails shader compilations with no error message when there is a const
4541 // parameter. Given that we've already passed through SkSL compilation and enforced that the
4542 // parameter is never written, it is harmless to strip the const off when writing GLSL.
4543 // Android API: 31
4544 // GL_VERSION : OpenGL ES 3.2 build 1.13@5720833
4545 // GL_RENDERER: PowerVR Rogue GE8300
4546 // GL_VENDOR : Imagination Technologies
4547 if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue &&
4548 driverVersion < GR_GL_DRIVER_VER(1, 15, 0)) {
4549 fShaderCaps->fRemoveConstFromFunctionParameters = true;
4550 }
4551 #ifdef SK_BUILD_FOR_WIN
4552 // glDrawElementsIndirect fails GrMeshTest on every Win10 Intel bot.
4553 if (ctxInfo.driver() == GrGLDriver::kIntel ||
4554 (ctxInfo.angleVendor() == GrGLVendor::kIntel &&
4555 ctxInfo.angleBackend() == GrGLANGLEBackend::kOpenGL)) {
4556 fNativeDrawIndexedIndirectIsBroken = true;
4557 fUseClientSideIndirectBuffers = true;
4558 }
4559 #endif
4560
4561 // PowerVRGX6250 drops every pixel if we modify the sample mask while color writes are disabled.
4562 if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue) {
4563 fNeverDisableColorWrites = true;
4564 shaderCaps->fMustWriteToFragColor = true;
4565 }
4566
4567 // It appears that Qualcomm drivers don't actually support
4568 // GL_NV_shader_noperspective_interpolation in ES 3.00 or 3.10 shaders, only 3.20.
4569 // https://crbug.com/986581
4570 if (ctxInfo.vendor() == GrGLVendor::kQualcomm &&
4571 SkSL::GLSLGeneration::k320es != ctxInfo.glslGeneration()) {
4572 shaderCaps->fNoPerspectiveInterpolationSupport = false;
4573 }
4574
4575 // We disable srgb write control for Adreno4xx devices.
4576 // see: skbug.com/40036502
4577 if (ctxInfo.renderer() == GrGLRenderer::kAdreno430 ||
4578 ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other) {
4579 fSRGBWriteControl = false;
4580 }
4581
4582 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
4583 #if defined(SK_BUILD_FOR_MAC)
4584 if (ctxInfo.vendor() == GrGLVendor::kATI) {
4585 formatWorkarounds->fDisableSRGBRenderWithMSAAForMacAMD = true;
4586 }
4587 #endif
4588
4589 // Command buffer fails glTexSubImage2D with type == GL_HALF_FLOAT_OES if a GL_RGBA16F texture
4590 // is created with glTexStorage2D. See crbug.com/1008003.
4591 formatWorkarounds->fDisableRGBA16FTexStorageForCrBug1008003 =
4592 ctxInfo.isOverCommandBuffer() && ctxInfo.version() < GR_GL_VER(3, 0);
4593
4594 #if defined(SK_BUILD_FOR_WIN)
4595 // On Intel Windows ES contexts it seems that using texture storage with BGRA causes
4596 // problems with cross-context SkImages.
4597 formatWorkarounds->fDisableBGRATextureStorageForIntelWindowsES =
4598 ctxInfo.driver() == GrGLDriver::kIntel && GR_IS_GR_GL_ES(ctxInfo.standard());
4599 #endif
4600
4601 // On the Intel Iris 6100, interacting with LUM16F seems to confuse the driver. After
4602 // writing to/reading from a LUM16F texture reads from/writes to other formats behave
4603 // erratically.
4604 // All Adrenos claim to support LUM16F but don't appear to actually do so.
4605 // The failing devices/gpus were: Nexus5/Adreno330, Nexus5x/Adreno418, Pixel/Adreno530,
4606 // Pixel2XL/Adreno540 and Pixel3/Adreno630
4607 formatWorkarounds->fDisableLuminance16F =
4608 (ctxInfo.renderer() == GrGLRenderer::kIntelBroadwell ||
4609 ctxInfo.vendor() == GrGLVendor::kQualcomm) &&
4610 ctxInfo.angleBackend() == GrGLANGLEBackend::kUnknown;
4611
4612 #ifdef SK_BUILD_FOR_MAC
4613 // On a MacBookPro 11.5 running MacOS 10.13 with a Radeon M370X the TransferPixelsFrom test
4614 // fails when transferring out from a GL_RG8 texture using GL_RG/GL_UNSIGNED_BYTE.
4615 // The same error also occurs in MacOS 10.15 with a Radeon Pro 5300M.
4616 formatWorkarounds->fDisallowDirectRG8ReadPixels =
4617 ctxInfo.renderer() == GrGLRenderer::kAMDRadeonR9M3xx ||
4618 ctxInfo.renderer() == GrGLRenderer::kAMDRadeonPro5xxx ||
4619 ctxInfo.renderer() == GrGLRenderer::kAMDRadeonProVegaxx;
4620 #endif
4621
4622 #ifdef SK_BUILD_FOR_ANDROID
4623 // crbug.com/945506. Telemetry reported a memory usage regression for Android Go Chrome/WebView
4624 // when using glTexStorage2D. This appears to affect OOP-R (so not just over command buffer).
4625 // Update 10/2023, it looks like this may just effect chrome Android GO devices which are
4626 // running on Mali-T720. It does not seem to impact Qualcomm devices. We have no tests to verify
4627 // if newer ARM devices are impacted, so for now we keep this disabled on all ARM by default.
4628 //
4629 // We allow the client to pass in a GrContextOption flag to say they prefer having tex storage
4630 // support regadless of memory usage impacts. This is important for supporting Protected
4631 // textures as they require tex storage support.
4632 if (ctxInfo.vendor() == GrGLVendor::kARM &&
4633 !contextOptions.fAlwaysUseTexStorageWhenAvailable &&
4634 !fSupportsProtectedContent) {
4635 formatWorkarounds->fDisableTexStorage = true;
4636 }
4637 #endif
4638
4639 // https://github.com/flutter/flutter/issues/38700
4640 if (ctxInfo.driver() == GrGLDriver::kAndroidEmulator) {
4641 shaderCaps->fNoDefaultPrecisionForExternalSamplers = true;
4642 }
4643
4644 // skbug.com/40040812: Nexus5 produces rendering artifacts when we use QCOM_tiled_rendering.
4645 if (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx) {
4646 fTiledRenderingSupport = false;
4647 }
4648 // https://github.com/flutter/flutter/issues/47164
4649 // https://github.com/flutter/flutter/issues/47804
4650 if (fTiledRenderingSupport && (!glInterface->fFunctions.fStartTiling ||
4651 !glInterface->fFunctions.fEndTiling)) {
4652 // Some devices expose the QCOM tiled memory extension string but don't actually provide the
4653 // start and end tiling functions (see above flutter bugs). To work around this, the funcs
4654 // are marked optional in the interface generator, but we turn off the tiled rendering cap
4655 // if they aren't provided. This disabling is in driver workarounds so that SKQP will still
4656 // fail on devices that advertise the extension w/o the functions.
4657 fTiledRenderingSupport = false;
4658 }
4659
4660 if (ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D9) {
4661 formatWorkarounds->fDisallowBGRA8ReadPixels = true;
4662 }
4663
4664 // We disable MSAA for older Intel GPUs. Before Gen9, performance was very bad. Even with Gen9,
4665 // we've seen driver crashes in the wild.
4666 // (crbug.com/527565, crbug.com/983926)
4667 if (ctxInfo.vendor() == GrGLVendor::kIntel || ctxInfo.angleVendor() == GrGLVendor::kIntel) {
4668 // Gen11 seems mostly ok, except we avoid drawing lines with MSAA. (anglebug.com/7796)
4669 if (ctxInfo.renderer() >= GrGLRenderer::kIntelIceLake &&
4670 contextOptions.fAllowMSAAOnNewIntel) {
4671 if (fMSFBOType != kNone_MSFBOType) {
4672 fAvoidLineDraws = true;
4673 }
4674 } else {
4675 fMSFBOType = kNone_MSFBOType;
4676 }
4677 }
4678
4679 // ANGLE's D3D9 backend + AMD GPUs are flaky with program binary caching (skbug.com/40041731)
4680 if (ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D9 &&
4681 ctxInfo.angleVendor() == GrGLVendor::kATI) {
4682 fProgramBinarySupport = false;
4683 }
4684
4685 // skbug.com/40042580. Avoid recursion issue in SurfaceContext::writePixels.
4686 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
4687 fReuseScratchTextures = false;
4688 }
4689
4690 // skbug.com/40042245. Don't reorder on these GPUs in GL on old drivers.
4691 if ((ctxInfo.renderer() == GrGLRenderer::kAdreno620 ||
4692 ctxInfo.renderer() == GrGLRenderer::kAdreno640) &&
4693 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(571, 0, 0)) {
4694 fAvoidReorderingRenderTasks = true;
4695 }
4696
4697 // http://crbug.com/1197152
4698 // http://b/187364475
4699 // We could limit this < 1.13 on ChromeOS but we don't really have a good way to detect
4700 // ChromeOS from here.
4701 if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue &&
4702 ctxInfo.driver() == GrGLDriver::kImagination &&
4703 driverVersion < GR_GL_DRIVER_VER(1, 16, 0)) {
4704 fShaderCaps->fShaderDerivativeSupport = false;
4705 }
4706
4707 if (ctxInfo.driver() == GrGLDriver::kFreedreno) {
4708 formatWorkarounds->fDisallowUnorm16Transfers = true;
4709 }
4710
4711 // If we keep rebind the same texture to an FBO's color attachment but changing between MSAA and
4712 // non-MSAA we get corruption in the texture contents. Binding texture 0 and then rebinding the
4713 // original texture avoids this.
4714 // This was found on Nexus 5, Android 6.0.1, build M4B30Z
4715 // GL_VENDOR : "Qualcomm"
4716 // GL_RENDERER: "Adreno (TM) 330"
4717 // GL_VERSION : "OpenGL ES 3.0 [email protected] AU@ (GIT@I96aee987eb)"
4718 //
4719 // We also so alpha blending issues on these GMs skbug_9819, p3_ovals, p3 on Mali-Gxx devices
4720 // The GM issues were observed on a Galaxy S9 running Android 10:
4721 // GL_VERSION : "OpenGL ES 3.2 v1.r19p0-01rel0.###other-sha0123456789ABCDEF0###"
4722 // GL_RENDERER: "Mali-G72"
4723 // GL_VENDOR : "ARM"
4724 // and a P30 running Android 9:
4725 // GL_VERSION : "OpenGL ES 3.2 v1.r16p0-01rel0.4aee637066427cbcd25297324dba15f5"
4726 // GL_RENDERER: "Mali-G76"
4727 // GL_VENDOR : "ARM"
4728 // but *not* a Galaxy S20 running Android 10:
4729 // GL_VERSION : "OpenGL ES 3.2 v1.r20p0-01rel0.###other-sha0123456789ABCDEF0###"
4730 // GL_RENDERER: "Mali-G77"
4731 // GL_VENDOR : "ARM"
4732 // It's unclear if the difference is driver version or Bifrost vs Valhall. The workaround is
4733 // fairly trivial so just applying to all Bifrost and Valhall.
4734 if ((ctxInfo.renderer() == GrGLRenderer::kAdreno3xx &&
4735 ctxInfo.driver() == GrGLDriver::kQualcomm) ||
4736 (ctxInfo.renderer() == GrGLRenderer::kMaliG)) {
4737 fBindTexture0WhenChangingTextureFBOMultisampleCount = true;
4738 }
4739
4740 // skbug.com/40043721
4741 // We found that on the Galaxy S7 the TransferPixelsTo test would fail after adding
4742 // glCheckFramebufferStatus() checks when making new FBOs. Note that the returned status was
4743 // GL_FRAMEBUFFER_COMPLETE. Switching the color binding to ID 0 and back to the original
4744 // afterwards works around the issue.
4745 // GL_VENDOR : "ARM"
4746 // GL_RENDERER: "Mali-T880"
4747 // GL_VERSION : "OpenGL ES 3.2 v1.r22p0-01rel0.f294e54ceb2cb2d81039204fa4b0402e"
4748 //
4749 // This *didn't* reproduce on a Samsung Chromebook Plus device:
4750 // GL_VENDOR : "ARM"
4751 // GL_RENDERER: "Mali-T860"
4752 // GL_VERSION : "OpenGL ES 3.2 v1.r26p0-01rel0.217d2597f6bd19b169343737782e56e3"
4753 if (ctxInfo.renderer() == GrGLRenderer::kMaliT &&
4754 ctxInfo.driver() == GrGLDriver::kARM &&
4755 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(1, 26, 0)) {
4756 fRebindColorAttachmentAfterCheckFramebufferStatus = true;
4757 }
4758
4759 #ifdef SK_BUILD_FOR_MAC
4760 // skbug.com/398631003
4761 if (ctxInfo.vendor() == GrGLVendor::kApple &&
4762 // Even the GL ANGLE backend doesn't have this issue, so the workaround is only necessary
4763 // if we're not rendering with ANGLE.
4764 ctxInfo.angleBackend() == GrGLANGLEBackend::kUnknown) {
4765 fBindDefaultFramebufferOnPresent = true;
4766 }
4767 #endif
4768
4769 // skbug.com/40044367
4770 // We found that the P30 produces a GL error when setting GL_TEXTURE_MAX_ANISOTROPY as a sampler
4771 // parameter but not as a texture parameter. We are disabling anisotropy on drivers that may
4772 // be affected.
4773 //
4774 // FAIL on P30
4775 // GL_VENDOR : ARM
4776 // GL_RENDERER: Mali-G76
4777 // GL_VERSION : OpenGL ES 3.2 v1.r16p0-01rel0.4aee637066427cbcd25297324dba15f5
4778 //
4779 // PASS on Pixel6
4780 // GL_VENDOR : ARM
4781 // GL_RENDERER: Mali-G78
4782 // GL_VERSION : OpenGL ES 3.2 v1.r32p1-00pxl0.b7e5868a59a273f4a9f58d1657ef99de
4783 //
4784 // PASS on Galaxy S30:
4785 // GL_VENDOR : ARM
4786 // GL_RENDERER: Mali-G77
4787 // GL_VERSION : OpenGL ES 3.2 v1.r20p0-01rel0.###other-sha0123456789ABCDEF0###
4788 //
4789 // PASS on Galaxy S9:
4790 // GL_VENDOR : ARM
4791 // GL_RENDERER: Mali-G72
4792 // GL_VENDOR : OpenGL ES 3.2 v1.r19p0-01rel0.###other-sha0123456789ABCDEF0###
4793 if (ctxInfo.renderer() == GrGLRenderer::kMaliG &&
4794 ctxInfo.driver() == GrGLDriver::kARM &&
4795 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(1, 19, 0)) {
4796 fAnisoSupport = false;
4797 }
4798
4799 // b/229626353
4800 // On certain classes of Adreno running WebGL, glTexSubImage2D() occasionally fails to upload
4801 // texels on time for sampling. The solution is to call glFlush() before glTexSubImage2D().
4802 // Seen on:
4803 // * Nexus 5x (Adreno 418)
4804 // * Nexus 6 (Adreno 420)
4805 // * Pixel 3 (Adreno 630)
4806 if (ctxInfo.renderer() == GrGLRenderer::kWebGL &&
4807 (ctxInfo.webglRenderer() == GrGLRenderer::kAdreno4xx_other ||
4808 ctxInfo.webglRenderer() == GrGLRenderer::kAdreno630)) {
4809 fFlushBeforeWritePixels = true;
4810 }
4811 // crbug.com/1395777
4812 // There appears to be a driver bug in GLSL program linking on Mali 400 and 450 devices with
4813 // driver version 2.1.199xx that causes the copy-as-draw programs in GrGLGpu to fail. The crash
4814 // rate increased when scaling copy support was added, so disallow scaling copy-as-draws on
4815 // these devices.
4816 if (ctxInfo.renderer() == GrGLRenderer::kMali4xx &&
4817 ctxInfo.driverVersion() >= GR_GL_DRIVER_VER(2, 1, 19900)) {
4818 fDisableScalingCopyAsDraws = true;
4819 }
4820 // skbug.com/40045272
4821 // Setting the max level is technically unnecessary, but on Intel drivers it makes it
4822 // clear that a rendering feedback loop is not occurring, and avoids hitting a slow path.
4823 // When running on ANGLE, however, this triggers the validator because we can only use
4824 // levels between BASE_LEVEL and MAX_LEVEL for a framebuffer, and we're trying to use
4825 // MAX_LEVEL+1. So instead we set up sync points between each mipmap level render.
4826 if (ctxInfo.vendor() == GrGLVendor::kIntel &&
4827 ctxInfo.angleBackend() == GrGLANGLEBackend::kUnknown) {
4828 fRegenerateMipmapType = RegenerateMipmapType::kBasePlusMaxLevel;
4829 } else if (ctxInfo.angleVendor() == GrGLVendor::kIntel) {
4830 fRegenerateMipmapType = RegenerateMipmapType::kBasePlusSync;
4831 }
4832 #ifdef SK_BUILD_FOR_MAC
4833 // On Apple Silicon, RG88 requires 2-byte alignment for transfer buffer readback
4834 if (ctxInfo.vendor() == GrGLVendor::kApple) {
4835 fPadRG88TransferAlignment = true;
4836 }
4837 #endif
4838 }
4839
4840 void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
4841 if (options.fDisableDriverCorrectnessWorkarounds) {
4842 SkASSERT(!fDoManualMipmapping);
4843 SkASSERT(!fClearToBoundaryValuesIsBroken);
4844 SkASSERT(0 == fMaxInstancesPerDrawWithoutCrashing);
4845 SkASSERT(!fDrawArraysBaseVertexIsBroken);
4846 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
4847 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
4848 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
4849 SkASSERT(!fDontSetBaseOrMaxLevelForExternalTextures);
4850 SkASSERT(!fNeverDisableColorWrites);
4851 }
4852 if (options.fShaderCacheStrategy < GrContextOptions::ShaderCacheStrategy::kBackendBinary) {
4853 fProgramBinarySupport = false;
4854 }
4855
4856 switch (options.fSkipGLErrorChecks) {
4857 case GrContextOptions::Enable::kNo:
4858 fSkipErrorChecks = false;
4859 break;
4860 case GrContextOptions::Enable::kYes:
4861 fSkipErrorChecks = true;
4862 break;
4863 case GrContextOptions::Enable::kDefault:
4864 break;
4865 }
4866 }
4867
4868 bool GrGLCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {
4869 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
4870 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
4871 if (tex->hasBaseLevelBeenBoundToFBO()) {
4872 return false;
4873 }
4874 }
4875 }
4876 if (auto rt = surface->asRenderTarget()) {
4877 if (fUseDrawInsteadOfAllRenderTargetWrites) {
4878 return false;
4879 }
4880 if (rt->numSamples() > 1 && this->usesMSAARenderBuffers()) {
4881 return false;
4882 }
4883 return SkToBool(surface->asTexture());
4884 }
4885 return true;
4886 }
4887
4888 GrCaps::SurfaceReadPixelsSupport GrGLCaps::surfaceSupportsReadPixels(
4889 const GrSurface* surface) const {
4890 if (surface->isProtected()) {
4891 return SurfaceReadPixelsSupport::kUnsupported;
4892 }
4893 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
4894 // We don't support reading pixels directly from EXTERNAL textures as it would require
4895 // binding the texture to a FBO. For now we also disallow reading back directly
4896 // from compressed textures.
4897 if (tex->target() == GR_GL_TEXTURE_EXTERNAL || GrGLFormatIsCompressed(tex->format())) {
4898 return SurfaceReadPixelsSupport::kCopyToTexture2D;
4899 }
4900 } else if (auto rt = static_cast<const GrGLRenderTarget*>(surface->asRenderTarget())) {
4901 // glReadPixels does not allow reading back from a MSAA framebuffer. If the underlying
4902 // GrSurface doesn't have a second FBO to resolve to then we must make a copy.
4903 if (rt->numSamples() > 1 && !rt->asTexture()) {
4904 return SurfaceReadPixelsSupport::kCopyToTexture2D;
4905 }
4906 }
4907 return SurfaceReadPixelsSupport::kSupported;
4908 }
4909
4910 size_t offset_alignment_for_transfer_buffer(GrGLenum externalType) {
4911 // This switch is derived from a table titled "Pixel data type parameter values and the
4912 // corresponding GL data types" in the OpenGL spec (Table 8.2 in OpenGL 4.5).
4913 switch (externalType) {
4914 case GR_GL_UNSIGNED_BYTE: return sizeof(GrGLubyte);
4915 case GR_GL_BYTE: return sizeof(GrGLbyte);
4916 case GR_GL_UNSIGNED_SHORT: return sizeof(GrGLushort);
4917 case GR_GL_SHORT: return sizeof(GrGLshort);
4918 case GR_GL_UNSIGNED_INT: return sizeof(GrGLuint);
4919 case GR_GL_INT: return sizeof(GrGLint);
4920 case GR_GL_HALF_FLOAT: return sizeof(GrGLhalf);
4921 case GR_GL_HALF_FLOAT_OES: return sizeof(GrGLhalf);
4922 case GR_GL_FLOAT: return sizeof(GrGLfloat);
4923 case GR_GL_UNSIGNED_SHORT_5_6_5: return sizeof(GrGLushort);
4924 case GR_GL_UNSIGNED_SHORT_4_4_4_4: return sizeof(GrGLushort);
4925 case GR_GL_UNSIGNED_SHORT_5_5_5_1: return sizeof(GrGLushort);
4926 case GR_GL_UNSIGNED_INT_2_10_10_10_REV: return sizeof(GrGLuint);
4927 #if 0 // GL types we currently don't use. Here for future reference.
4928 case GR_GL_UNSIGNED_BYTE_3_3_2: return sizeof(GrGLubyte);
4929 case GR_GL_UNSIGNED_BYTE_2_3_3_REV: return sizeof(GrGLubyte);
4930 case GR_GL_UNSIGNED_SHORT_5_6_5_REV: return sizeof(GrGLushort);
4931 case GR_GL_UNSIGNED_SHORT_4_4_4_4_REV: return sizeof(GrGLushort);
4932 case GR_GL_UNSIGNED_SHORT_1_5_5_5_REV: return sizeof(GrGLushort);
4933 case GR_GL_UNSIGNED_INT_8_8_8_8: return sizeof(GrGLuint);
4934 case GR_GL_UNSIGNED_INT_8_8_8_8_REV: return sizeof(GrGLuint);
4935 case GR_GL_UNSIGNED_INT_10_10_10_2: return sizeof(GrGLuint);
4936 case GR_GL_UNSIGNED_INT_24_8: return sizeof(GrGLuint);
4937 case GR_GL_UNSIGNED_INT_10F_11F_11F_REV: return sizeof(GrGLuint);
4938 case GR_GL_UNSIGNED_INT_5_9_9_9_REV: return sizeof(GrGLuint);
4939 // This one is not corresponding to a GL data type and the spec just says it is 4.
4940 case GR_GL_FLOAT_32_UNSIGNED_INT_24_8_REV: return 4;
4941 #endif
4942 default: return 0;
4943 }
4944 }
4945
4946 GrCaps::SupportedRead GrGLCaps::onSupportedReadPixelsColorType(
4947 GrColorType srcColorType, const GrBackendFormat& srcBackendFormat,
4948 GrColorType dstColorType) const {
4949
4950 SkTextureCompressionType compression = GrBackendFormatToCompressionType(srcBackendFormat);
4951 if (compression != SkTextureCompressionType::kNone) {
4952 return {SkTextureCompressionTypeIsOpaque(compression) ? GrColorType::kRGB_888x
4953 : GrColorType::kRGBA_8888,
4954 0};
4955 }
4956
4957 // We first try to find a supported read pixels GrColorType that matches the requested
4958 // dstColorType. If that doesn't exists we will use any valid read pixels GrColorType.
4959 GrCaps::SupportedRead fallbackRead = {GrColorType::kUnknown, 0};
4960 const auto& formatInfo = this->getFormatInfo(GrBackendFormats::AsGLFormat(srcBackendFormat));
4961 bool foundSrcCT = false;
4962 for (int i = 0; !foundSrcCT && i < formatInfo.fColorTypeInfoCount; ++i) {
4963 if (formatInfo.fColorTypeInfos[i].fColorType == srcColorType) {
4964 const ColorTypeInfo& ctInfo = formatInfo.fColorTypeInfos[i];
4965 foundSrcCT = true;
4966 for (int j = 0; j < ctInfo.fExternalIOFormatCount; ++j) {
4967 const auto& ioInfo = ctInfo.fExternalIOFormats[j];
4968 if (ioInfo.fExternalReadFormat != 0) {
4969 if (formatInfo.fHaveQueriedImplementationReadSupport ||
4970 !ioInfo.fRequiresImplementationReadQuery) {
4971 GrGLenum transferOffsetAlignment = 0;
4972 if (formatInfo.fFlags & FormatInfo::kTransfers_Flag) {
4973 transferOffsetAlignment =
4974 offset_alignment_for_transfer_buffer(ioInfo.fExternalType);
4975 if (dstColorType == GrColorType::kRG_88 && fPadRG88TransferAlignment) {
4976 transferOffsetAlignment = 2;
4977 }
4978 }
4979 if (ioInfo.fColorType == dstColorType) {
4980 return {dstColorType, transferOffsetAlignment};
4981 }
4982 // Currently we just pick the first supported format that we find as our
4983 // fallback.
4984 if (fallbackRead.fColorType == GrColorType::kUnknown) {
4985 fallbackRead = {ioInfo.fColorType, transferOffsetAlignment};
4986 }
4987 }
4988 }
4989 }
4990 }
4991 }
4992 return fallbackRead;
4993 }
4994
4995 GrCaps::SupportedWrite GrGLCaps::supportedWritePixelsColorType(GrColorType surfaceColorType,
4996 const GrBackendFormat& surfaceFormat,
4997 GrColorType srcColorType) const {
4998 // We first try to find a supported write pixels GrColorType that matches the data's
4999 // srcColorType. If that doesn't exists we will use any supported GrColorType.
5000 GrColorType fallbackCT = GrColorType::kUnknown;
5001 const auto& formatInfo = this->getFormatInfo(GrBackendFormats::AsGLFormat(surfaceFormat));
5002 bool foundSurfaceCT = false;
5003 size_t transferOffsetAlignment = 0;
5004 if (formatInfo.fFlags & FormatInfo::kTransfers_Flag) {
5005 transferOffsetAlignment = 1;
5006 }
5007 for (int i = 0; !foundSurfaceCT && i < formatInfo.fColorTypeInfoCount; ++i) {
5008 if (formatInfo.fColorTypeInfos[i].fColorType == surfaceColorType) {
5009 const ColorTypeInfo& ctInfo = formatInfo.fColorTypeInfos[i];
5010 foundSurfaceCT = true;
5011 for (int j = 0; j < ctInfo.fExternalIOFormatCount; ++j) {
5012 const auto& ioInfo = ctInfo.fExternalIOFormats[j];
5013 if (ioInfo.fExternalTexImageFormat != 0) {
5014 if (ioInfo.fColorType == srcColorType) {
5015 return {srcColorType, transferOffsetAlignment};
5016 }
5017 // Currently we just pick the first supported format that we find as our
5018 // fallback.
5019 if (fallbackCT == GrColorType::kUnknown) {
5020 fallbackCT = ioInfo.fColorType;
5021 }
5022 }
5023 }
5024 }
5025 }
5026 return {fallbackCT, transferOffsetAlignment};
5027 }
5028
5029 bool GrGLCaps::programBinaryFormatIsValid(GrGLenum binaryFormat) const {
5030 return std::find(fProgramBinaryFormats.begin(), fProgramBinaryFormats.end(), binaryFormat) !=
5031 fProgramBinaryFormats.end();
5032 }
5033
5034 bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
5035 GrGLFramebufferInfo fbInfo;
5036 SkAssertResult(GrBackendRenderTargets::GetGLFramebufferInfo(backendRT, &fbInfo));
5037 // Window Rectangles are not supported for FBO 0;
5038 return fbInfo.fFBOID != 0;
5039 }
5040
5041 bool GrGLCaps::isFormatSRGB(const GrBackendFormat& format) const {
5042 return GrBackendFormats::AsGLFormat(format) == GrGLFormat::kSRGB8_ALPHA8;
5043 }
5044
5045 bool GrGLCaps::isFormatTexturable(const GrBackendFormat& format, GrTextureType textureType) const {
5046 if (textureType == GrTextureType::kRectangle && !this->rectangleTextureSupport()) {
5047 return false;
5048 }
5049 return this->isFormatTexturable(GrBackendFormats::AsGLFormat(format));
5050 }
5051
5052 bool GrGLCaps::isFormatTexturable(GrGLFormat format) const {
5053 const FormatInfo& info = this->getFormatInfo(format);
5054 return SkToBool(info.fFlags & FormatInfo::kTexturable_Flag);
5055 }
5056
5057 bool GrGLCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
5058 int sampleCount) const {
5059 if (format.textureType() == GrTextureType::kRectangle && !this->rectangleTextureSupport()) {
5060 return false;
5061 }
5062 if (format.textureType() == GrTextureType::kExternal) {
5063 return false;
5064 }
5065 auto f = GrBackendFormats::AsGLFormat(format);
5066 const FormatInfo& info = this->getFormatInfo(f);
5067 if (!SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kRenderable_Flag)) {
5068 return false;
5069 }
5070
5071 return this->isFormatRenderable(f, sampleCount);
5072 }
5073
5074 bool GrGLCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount) const {
5075 if (format.textureType() == GrTextureType::kRectangle && !this->rectangleTextureSupport()) {
5076 return false;
5077 }
5078 if (format.textureType() == GrTextureType::kExternal) {
5079 return false;
5080 }
5081 return this->isFormatRenderable(GrBackendFormats::AsGLFormat(format), sampleCount);
5082 }
5083
5084 int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrGLFormat format) const {
5085 const FormatInfo& info = this->getFormatInfo(format);
5086
5087 int count = info.fColorSampleCounts.size();
5088 if (!count) {
5089 return 0;
5090 }
5091
5092 requestedCount = std::max(1, requestedCount);
5093 if (1 == requestedCount) {
5094 return info.fColorSampleCounts[0] == 1 ? 1 : 0;
5095 }
5096
5097 for (int sampleCount : info.fColorSampleCounts) {
5098 if (sampleCount >= requestedCount) {
5099 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
5100 sampleCount = std::min(sampleCount, 4);
5101 }
5102 return sampleCount;
5103 }
5104 }
5105 return 0;
5106 }
5107
5108 int GrGLCaps::maxRenderTargetSampleCount(GrGLFormat format) const {
5109 const FormatInfo& info = this->getFormatInfo(format);
5110 const auto& table = info.fColorSampleCounts;
5111 if (table.empty()) {
5112 return 0;
5113 }
5114 int count = table[table.size() - 1];
5115 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
5116 count = std::min(count, 4);
5117 }
5118 return count;
5119 }
5120
5121 bool GrGLCaps::canFormatBeFBOColorAttachment(GrGLFormat format) const {
5122 return SkToBool(this->getFormatInfo(format).fFlags & FormatInfo::kFBOColorAttachment_Flag);
5123 }
5124
5125 bool GrGLCaps::isFormatCopyable(const GrBackendFormat& format) const {
5126 // In GL we have three ways to be able to copy. CopyTexImage, blit, and draw. CopyTexImage
5127 // requires the src to be an FBO attachment, blit requires both src and dst to be FBO
5128 // attachments, and draw requires the dst to be an FBO attachment. Thus to copy from and to
5129 // the same config, we need that config to be bindable to an FBO.
5130 return this->canFormatBeFBOColorAttachment(GrBackendFormats::AsGLFormat(format));
5131 }
5132
5133 bool GrGLCaps::formatSupportsTexStorage(GrGLFormat format) const {
5134 return SkToBool(this->getFormatInfo(format).fFlags & FormatInfo::kUseTexStorage_Flag);
5135 }
5136
5137 bool GrGLCaps::shouldQueryImplementationReadSupport(GrGLFormat format) const {
5138 const auto& formatInfo = const_cast<GrGLCaps*>(this)->getFormatInfo(format);
5139 if (!formatInfo.fHaveQueriedImplementationReadSupport) {
5140 // Check whether we will actually learn anything useful.
5141 bool needQuery = false;
5142 for (int i = 0; i < formatInfo.fColorTypeInfoCount && !needQuery; ++i) {
5143 const auto& surfCTInfo = formatInfo.fColorTypeInfos[i];
5144 for (int j = 0; j < surfCTInfo.fExternalIOFormatCount; ++j) {
5145 if (surfCTInfo.fExternalIOFormats[j].fRequiresImplementationReadQuery) {
5146 needQuery = true;
5147 break;
5148 }
5149 }
5150 }
5151 if (!needQuery) {
5152 // Pretend we already checked it.
5153 const_cast<FormatInfo&>(formatInfo).fHaveQueriedImplementationReadSupport = true;
5154 }
5155 }
5156 return !formatInfo.fHaveQueriedImplementationReadSupport;
5157 }
5158
5159 void GrGLCaps::didQueryImplementationReadSupport(GrGLFormat format,
5160 GrGLenum readFormat,
5161 GrGLenum readType) const {
5162 auto& formatInfo = const_cast<GrGLCaps*>(this)->getFormatInfo(format);
5163 for (int i = 0; i < formatInfo.fColorTypeInfoCount; ++i) {
5164 auto& surfCTInfo = formatInfo.fColorTypeInfos[i];
5165 for (int j = 0; j < surfCTInfo.fExternalIOFormatCount; ++j) {
5166 auto& readCTInfo = surfCTInfo.fExternalIOFormats[j];
5167 if (readCTInfo.fRequiresImplementationReadQuery) {
5168 if (readCTInfo.fExternalReadFormat != readFormat ||
5169 readCTInfo.fExternalType != readType) {
5170 // Don't zero out fExternalType. It's also used for writing data to the texture!
5171 readCTInfo.fExternalReadFormat = 0;
5172 }
5173 }
5174 }
5175 }
5176 formatInfo.fHaveQueriedImplementationReadSupport = true;
5177 }
5178
5179 bool GrGLCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
5180 const GrBackendFormat& format) const {
5181 if (format.textureType() == GrTextureType::kExternal) {
5182 // For lack of a better alternative, assume the external format matches the requested ct.
5183 return true;
5184 }
5185
5186 GrGLFormat glFormat = GrBackendFormats::AsGLFormat(format);
5187 const auto& info = this->getFormatInfo(glFormat);
5188 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
5189 if (info.fColorTypeInfos[i].fColorType == ct) {
5190 return true;
5191 }
5192 }
5193 return false;
5194 }
5195
5196 GrBackendFormat GrGLCaps::onGetDefaultBackendFormat(GrColorType ct) const {
5197 auto format = this->getFormatFromColorType(ct);
5198 if (format == GrGLFormat::kUnknown) {
5199 return {};
5200 }
5201 return GrBackendFormats::MakeGL(GrGLFormatToEnum(format), GR_GL_TEXTURE_2D);
5202 }
5203
5204 GrBackendFormat GrGLCaps::getBackendFormatFromCompressionType(
5205 SkTextureCompressionType compressionType) const {
5206 switch (compressionType) {
5207 case SkTextureCompressionType::kNone:
5208 return {};
5209 case SkTextureCompressionType::kETC2_RGB8_UNORM:
5210 // if ETC2 is available default to that format
5211 if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_RGB8_ETC2)) {
5212 return GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGB8_ETC2, GR_GL_TEXTURE_2D);
5213 }
5214 if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_ETC1_RGB8)) {
5215 return GrBackendFormats::MakeGL(GR_GL_COMPRESSED_ETC1_RGB8, GR_GL_TEXTURE_2D);
5216 }
5217 return {};
5218 case SkTextureCompressionType::kBC1_RGB8_UNORM:
5219 if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_RGB8_BC1)) {
5220 return GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
5221 GR_GL_TEXTURE_2D);
5222 }
5223 return {};
5224 case SkTextureCompressionType::kBC1_RGBA8_UNORM:
5225 if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_RGBA8_BC1)) {
5226 return GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
5227 GR_GL_TEXTURE_2D);
5228 }
5229 return {};
5230 }
5231
5232 SkUNREACHABLE;
5233 }
5234
5235 skgpu::Swizzle GrGLCaps::onGetReadSwizzle(const GrBackendFormat& format,
5236 GrColorType colorType) const {
5237 GrGLFormat glFormat = GrBackendFormats::AsGLFormat(format);
5238 const auto& info = this->getFormatInfo(glFormat);
5239 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
5240 const auto& ctInfo = info.fColorTypeInfos[i];
5241 if (ctInfo.fColorType == colorType) {
5242 return ctInfo.fReadSwizzle;
5243 }
5244 }
5245 SkDEBUGFAILF("Illegal color type (%d) and format (%d) combination.",
5246 (int)colorType, (int)glFormat);
5247 return {};
5248 }
5249
5250 skgpu::Swizzle GrGLCaps::getWriteSwizzle(const GrBackendFormat& format,
5251 GrColorType colorType) const {
5252 const auto& info = this->getFormatInfo(GrBackendFormats::AsGLFormat(format));
5253 for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
5254 const auto& ctInfo = info.fColorTypeInfos[i];
5255 if (ctInfo.fColorType == colorType) {
5256 return ctInfo.fWriteSwizzle;
5257 }
5258 }
5259 SkDEBUGFAILF("Illegal color type (%d) and format (%d) combination.",
5260 (int)colorType,
5261 (int)GrBackendFormats::AsGLFormat(format));
5262 return {};
5263 }
5264
5265 GrDstSampleFlags GrGLCaps::onGetDstSampleFlagsForProxy(const GrRenderTargetProxy* rt) const {
5266 if (rt->asTextureProxy()) {
5267 return GrDstSampleFlags::kRequiresTextureBarrier;
5268 }
5269 return GrDstSampleFlags::kNone;
5270 }
5271
5272 bool GrGLCaps::onSupportsDynamicMSAA(const GrRenderTargetProxy* rtProxy) const {
5273 return !fDisallowDynamicMSAA;
5274 }
5275
5276 uint64_t GrGLCaps::computeFormatKey(const GrBackendFormat& format) const {
5277 auto glFormat = GrBackendFormats::AsGLFormat(format);
5278 return (uint64_t)(glFormat);
5279 }
5280
5281 GrProgramDesc GrGLCaps::makeDesc(GrRenderTarget* /* rt */,
5282 const GrProgramInfo& programInfo,
5283 ProgramDescOverrideFlags overrideFlags) const {
5284 SkASSERT(overrideFlags == ProgramDescOverrideFlags::kNone);
5285 GrProgramDesc desc;
5286 GrProgramDesc::Build(&desc, programInfo, *this);
5287 return desc;
5288 }
5289
5290 #if defined(GPU_TEST_UTILS)
5291 std::vector<GrTest::TestFormatColorTypeCombination> GrGLCaps::getTestingCombinations() const {
5292 std::vector<GrTest::TestFormatColorTypeCombination> combos = {
5293 { GrColorType::kAlpha_8,
5294 GrBackendFormats::MakeGL(GR_GL_ALPHA8, GR_GL_TEXTURE_2D) },
5295 { GrColorType::kAlpha_8,
5296 GrBackendFormats::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D) },
5297 { GrColorType::kBGR_565,
5298 GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_2D) },
5299 { GrColorType::kABGR_4444,
5300 GrBackendFormats::MakeGL(GR_GL_RGBA4, GR_GL_TEXTURE_2D) },
5301 { GrColorType::kRGBA_8888,
5302 GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D) },
5303 { GrColorType::kRGBA_8888_SRGB,
5304 GrBackendFormats::MakeGL(GR_GL_SRGB8_ALPHA8, GR_GL_TEXTURE_2D) },
5305 { GrColorType::kRGB_888x,
5306 GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D) },
5307 { GrColorType::kRGB_888x,
5308 GrBackendFormats::MakeGL(GR_GL_BGRA8, GR_GL_TEXTURE_2D) },
5309 { GrColorType::kRGB_888x,
5310 GrBackendFormats::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_2D) },
5311 { GrColorType::kRGB_888x,
5312 GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGB8_ETC2, GR_GL_TEXTURE_2D) },
5313 { GrColorType::kRGB_888x,
5314 GrBackendFormats::MakeGL(GR_GL_COMPRESSED_ETC1_RGB8, GR_GL_TEXTURE_2D) },
5315 { GrColorType::kRGB_888x,
5316 GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GR_GL_TEXTURE_2D) },
5317 { GrColorType::kRGBA_8888,
5318 GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GR_GL_TEXTURE_2D) },
5319 { GrColorType::kRG_88,
5320 GrBackendFormats::MakeGL(GR_GL_RG8, GR_GL_TEXTURE_2D) },
5321 { GrColorType::kRGBA_1010102,
5322 GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D) },
5323 { GrColorType::kRGB_101010x,
5324 GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D) },
5325 { GrColorType::kGray_8,
5326 GrBackendFormats::MakeGL(GR_GL_LUMINANCE8, GR_GL_TEXTURE_2D) },
5327 { GrColorType::kGray_8,
5328 GrBackendFormats::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D) },
5329 { GrColorType::kGrayAlpha_88,
5330 GrBackendFormats::MakeGL(GR_GL_LUMINANCE8_ALPHA8, GR_GL_TEXTURE_2D) },
5331 { GrColorType::kAlpha_F16,
5332 GrBackendFormats::MakeGL(GR_GL_R16F, GR_GL_TEXTURE_2D) },
5333 { GrColorType::kAlpha_F16,
5334 GrBackendFormats::MakeGL(GR_GL_LUMINANCE16F, GR_GL_TEXTURE_2D) },
5335 { GrColorType::kRGBA_F16,
5336 GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D) },
5337 { GrColorType::kRGBA_F16_Clamped,
5338 GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D) },
5339 { GrColorType::kRGB_F16F16F16x,
5340 GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D) },
5341 { GrColorType::kAlpha_16,
5342 GrBackendFormats::MakeGL(GR_GL_R16, GR_GL_TEXTURE_2D) },
5343 { GrColorType::kRG_1616,
5344 GrBackendFormats::MakeGL(GR_GL_RG16, GR_GL_TEXTURE_2D) },
5345 { GrColorType::kRGBA_16161616,
5346 GrBackendFormats::MakeGL(GR_GL_RGBA16, GR_GL_TEXTURE_2D) },
5347 { GrColorType::kRG_F16,
5348 GrBackendFormats::MakeGL(GR_GL_RG16F, GR_GL_TEXTURE_2D) },
5349 };
5350
5351 if (GR_IS_GR_GL(fStandard)) {
5352 combos.push_back({ GrColorType::kBGRA_8888,
5353 GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D) });
5354 combos.push_back({ GrColorType::kBGRA_1010102,
5355 GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D) });
5356 } else {
5357 SkASSERT(GR_IS_GR_GL_ES(fStandard) || GR_IS_GR_WEBGL(fStandard));
5358
5359 combos.push_back({ GrColorType::kBGRA_8888,
5360 GrBackendFormats::MakeGL(GR_GL_BGRA8, GR_GL_TEXTURE_2D) });
5361 }
5362 if (this->rectangleTextureSupport()) {
5363 size_t count2D = combos.size();
5364 for (size_t i = 0; i < count2D; ++i) {
5365 auto combo2D = combos[i];
5366 GrGLenum formatEnum = GrBackendFormats::AsGLFormatEnum(combo2D.fFormat);
5367 combos.push_back({combo2D.fColorType,
5368 GrBackendFormats::MakeGL(formatEnum, GR_GL_TEXTURE_RECTANGLE)});
5369 }
5370 }
5371 return combos;
5372 }
5373 #endif