in src/gpu/ganesh/gl/GrGLCaps.cpp [121:910]
void GrGLCaps::init(const GrContextOptions& contextOptions,
const GrGLContextInfo& ctxInfo,
const GrGLInterface* gli) {
GrGLStandard standard = ctxInfo.standard();
// standard can be unused (optimized away) if SK_ASSUME_GL_ES is set
sk_ignore_unused_variable(standard);
GrGLVersion version = ctxInfo.version();
#if defined(GPU_TEST_UTILS)
const GrGLubyte* deviceName;
GR_GL_CALL_RET(gli, deviceName, GetString(GR_GL_RENDERER));
this->setDeviceName(reinterpret_cast<const char*>(deviceName));
#endif
if (GR_IS_GR_GL(standard)) {
GrGLint max;
GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
fMaxFragmentUniformVectors = max / 4;
if (version >= GR_GL_VER(3, 2)) {
GrGLint profileMask;
GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
}
} else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
&fMaxFragmentUniformVectors);
}
if (fDriverBugWorkarounds.max_fragment_uniform_vectors_32) {
fMaxFragmentUniformVectors = std::min(fMaxFragmentUniformVectors, 32);
}
GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
if (GR_IS_GR_GL(standard)) {
fWritePixelsRowBytesSupport = true;
fReadPixelsRowBytesSupport = true;
fPackFlipYSupport = false;
} else if (GR_IS_GR_GL_ES(standard)) {
fWritePixelsRowBytesSupport =
version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_unpack_subimage");
fReadPixelsRowBytesSupport =
version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pack_subimage");
fPackFlipYSupport =
ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
} else if (GR_IS_GR_WEBGL(standard)) {
// WebGL 2.0 has these
fWritePixelsRowBytesSupport = version >= GR_GL_VER(2, 0);
fReadPixelsRowBytesSupport = version >= GR_GL_VER(2, 0);
}
fTransferPixelsToRowBytesSupport = fWritePixelsRowBytesSupport;
if (fDriverBugWorkarounds.pack_parameters_workaround_with_pack_buffer) {
// In some cases drivers handle copying the last row incorrectly
// when using GL_PACK_ROW_LENGTH. Chromium handles this by iterating
// through every row and conditionally clobbering that value, but
// Skia already has a scratch buffer workaround when pack row length
// is not supported, so just use that.
fReadPixelsRowBytesSupport = false;
}
fTextureUsageSupport = GR_IS_GR_GL_ES(standard) &&
ctxInfo.hasExtension("GL_ANGLE_texture_usage");
if (GR_IS_GR_GL(standard)) {
fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
ctxInfo.hasExtension("GL_NV_texture_barrier");
} else if (GR_IS_GR_GL_ES(standard)) {
fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
} else if (GR_IS_GR_WEBGL(standard)) {
fTextureBarrierSupport = false;
}
if (GR_IS_GR_GL(standard)) {
fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
ctxInfo.hasExtension("GL_ARB_texture_multisample");
} else if (GR_IS_GR_GL_ES(standard)) {
fSampleLocationsSupport = version >= GR_GL_VER(3,1);
} else if (GR_IS_GR_WEBGL(standard)) {
fSampleLocationsSupport = false;
}
fImagingSupport = GR_IS_GR_GL(standard) &&
ctxInfo.hasExtension("GL_ARB_imaging");
if (((GR_IS_GR_GL(standard) && version >= GR_GL_VER(4,3)) ||
(GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0)) ||
ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
fInvalidateFBType = kInvalidate_InvalidateFBType;
} else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
fInvalidateFBType = kDiscard_InvalidateFBType;
}
// For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
// GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
if (GR_IS_GR_GL_ES(standard)) {
// Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
// FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
if (ctxInfo.vendor() == GrGLVendor::kARM) {
fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
}
}
if (ctxInfo.vendor() == GrGLVendor::kARM ||
ctxInfo.vendor() == GrGLVendor::kImagination ||
ctxInfo.vendor() == GrGLVendor::kQualcomm ) {
fPreferFullscreenClears = true;
}
if (GR_IS_GR_GL(standard)) {
fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
} else if (GR_IS_GR_GL_ES(standard)) {
fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_OES_vertex_array_object");
} else if (GR_IS_GR_WEBGL(standard)) {
fVertexArrayObjectSupport = version >= GR_GL_VER(2, 0) ||
ctxInfo.hasExtension("GL_OES_vertex_array_object") ||
ctxInfo.hasExtension("OES_vertex_array_object");
}
if (GR_IS_GR_GL(standard) && version >= GR_GL_VER(4,3)) {
fDebugSupport = true;
} else if (GR_IS_GR_GL_ES(standard)) {
fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
} else if (GR_IS_GR_WEBGL(standard)) {
fDebugSupport = false;
}
if (GR_IS_GR_GL(standard)) {
fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
}
else if (GR_IS_GR_GL_ES(standard)) {
fES2CompatibilitySupport = true;
} else if (GR_IS_GR_WEBGL(standard)) {
fES2CompatibilitySupport = true;
}
if (GR_IS_GR_GL(standard)) {
fClientCanDisableMultisample = true;
} else if (GR_IS_GR_GL_ES(standard)) {
fClientCanDisableMultisample = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
} else if (GR_IS_GR_WEBGL(standard)) {
fClientCanDisableMultisample = false;
}
if (GR_IS_GR_GL(standard)) {
// 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
// instanced arrays, but we could make this more granular if we wanted
fDrawInstancedSupport =
version >= GR_GL_VER(3, 2) ||
(ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
} else if (GR_IS_GR_GL_ES(standard)) {
fDrawInstancedSupport =
version >= GR_GL_VER(3, 0) ||
(ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
ctxInfo.hasExtension("GL_EXT_instanced_arrays")) ||
ctxInfo.hasExtension("GL_ANGLE_instanced_arrays");
} else if (GR_IS_GR_WEBGL(standard)) {
// WebGL 2.0 has DrawArraysInstanced and drawElementsInstanced
fDrawInstancedSupport = version >= GR_GL_VER(2, 0);
}
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 0)) {
fBindFragDataLocationSupport = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
fBindFragDataLocationSupport = true;
}
} else if (GR_IS_GR_WEBGL(standard)) {
fBindFragDataLocationSupport = false;
}
fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
ctxInfo.hasExtension("GL_ANGLE_texture_rectangle")) {
fRectangleTextureSupport = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
fRectangleTextureSupport = ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
ctxInfo.hasExtension("GL_ANGLE_texture_rectangle");
} else if (GR_IS_GR_WEBGL(standard)) {
fRectangleTextureSupport = false;
}
// GrCaps defaults fClampToBorderSupport to true, so disable when unsupported
if (GR_IS_GR_GL(standard)) {
// Clamp to border added in 1.3
if (version < GR_GL_VER(1, 3) && !ctxInfo.hasExtension("GL_ARB_texture_border_clamp")) {
fClampToBorderSupport = false;
}
} else if (GR_IS_GR_GL_ES(standard)) {
// GLES didn't have clamp to border until 3.2, but provides several alternative extensions
if (version < GR_GL_VER(3, 2) && !ctxInfo.hasExtension("GL_EXT_texture_border_clamp") &&
!ctxInfo.hasExtension("GL_NV_texture_border_clamp") &&
!ctxInfo.hasExtension("GL_OES_texture_border_clamp")) {
fClampToBorderSupport = false;
}
} else if (GR_IS_GR_WEBGL(standard)) {
// WebGL appears to only have REPEAT, CLAMP_TO_EDGE and MIRRORED_REPEAT
fClampToBorderSupport = false;
}
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
fTextureSwizzleSupport = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3,0)) {
fTextureSwizzleSupport = true;
}
} else if (GR_IS_GR_WEBGL(standard)) {
fTextureSwizzleSupport = false;
}
if (GR_IS_GR_GL(standard)) {
fMipmapLevelControlSupport = true;
fMipmapLodControlSupport = true;
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3,0)) {
fMipmapLevelControlSupport = true;
fMipmapLodControlSupport = true;
}
} else if (GR_IS_GR_WEBGL(standard)) {
fMipmapLevelControlSupport = false;
fMipmapLodControlSupport = false;
}
if ((GR_IS_GR_GL_ES(standard) || GR_IS_GR_GL(standard)) &&
ctxInfo.hasExtension("GL_ARB_invalidate_subdata")) {
fInvalidateBufferType = InvalidateBufferType::kInvalidate;
} else if (!GR_IS_GR_WEBGL(standard) && !ctxInfo.isOverCommandBuffer()) {
// Chrome's command buffer will push an array of zeros to a buffer if null is passed to
// glBufferData (to avoid letting an application see uninitialized memory). This is
// expensive so we avoid it. WebGL spec explicitly disallows null values.
fInvalidateBufferType = InvalidateBufferType::kNullData;
}
if (GR_IS_GR_GL(standard)) {
fClearTextureSupport = (version >= GR_GL_VER(4,4) ||
ctxInfo.hasExtension("GL_ARB_clear_texture"));
} else if (GR_IS_GR_GL_ES(standard)) {
fClearTextureSupport = ctxInfo.hasExtension("GL_EXT_clear_texture");
} else if (GR_IS_GR_WEBGL(standard)) {
fClearTextureSupport = false;
}
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
fSupportsAHardwareBufferImages = true;
#endif
if (GR_IS_GR_GL(standard)) {
fSRGBWriteControl = version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB");
} else if (GR_IS_GR_GL_ES(standard)) {
// ES through 3.2 requires EXT_srgb_write_control to support toggling
// sRGB writing for destinations.
fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
} // No WebGL support
fSkipErrorChecks = ctxInfo.isOverCommandBuffer();
if (GR_IS_GR_WEBGL(standard)) {
// Error checks are quite costly in webgl, especially in Chrome.
fSkipErrorChecks = true;
}
// When we are abandoning the context we cannot call into GL thus we should skip any sync work.
fMustSyncGpuDuringAbandon = false;
fSupportsProtectedContent = [&]() {
if (!ctxInfo.hasExtension("GL_EXT_protected_textures")) {
return false;
}
GrGLint contextFlags;
GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_FLAGS, &contextFlags);
return SkToBool(contextFlags & GR_GL_CONTEXT_FLAG_PROTECTED_CONTENT_BIT_EXT);
}();
/**
* When Ganesh is backed by ANGLE mapping to Vulkan, the Protectedness handling has to be
* more like the Vulkan case (i.e., all internally allocated objects that will be written to
* in a Protected Context must be Protected). ANGLE just forwards any work to the
* active Vulkan Context. If that Vulkan Context is Protected that would mean, without
* using strict Protectedness, writes to unProtected objects would be submitted to a
* Protected Queue - which is not allowed in Vulkan.
*/
fStrictProtectedness = fSupportsProtectedContent &&
ctxInfo.angleBackend() != GrGLANGLEBackend::kUnknown;
/**************************************************************************
* GrShaderCaps fields
**************************************************************************/
// This must be called after fCoreProfile is set on the GrGLCaps
this->initGLSL(ctxInfo, gli);
GrShaderCaps* shaderCaps = fShaderCaps.get();
// Enable supported shader-related caps
if (GR_IS_GR_GL(standard)) {
shaderCaps->fDualSourceBlendingSupport =
(version >= GR_GL_VER(3, 3) ||
ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
shaderCaps->fShaderDerivativeSupport = true;
shaderCaps->fExplicitTextureLodSupport =
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
shaderCaps->fIntegerSupport = version >= GR_GL_VER(3, 0) &&
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
shaderCaps->fNonsquareMatrixSupport =
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
shaderCaps->fInverseHyperbolicSupport =
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
} else if (GR_IS_GR_GL_ES(standard)) {
shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
shaderCaps->fShaderDerivativeSupport =
// We use this value for GLSL ES 3.0.
version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_standard_derivatives");
shaderCaps->fExplicitTextureLodSupport =
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
shaderCaps->fIntegerSupport = version >= GR_GL_VER(3, 0) &&
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
shaderCaps->fNonsquareMatrixSupport =
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
shaderCaps->fInverseHyperbolicSupport =
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
} else if (GR_IS_GR_WEBGL(standard)) {
shaderCaps->fShaderDerivativeSupport = version >= GR_GL_VER(2, 0) ||
ctxInfo.hasExtension("GL_OES_standard_derivatives") ||
ctxInfo.hasExtension("OES_standard_derivatives");
shaderCaps->fExplicitTextureLodSupport =
version >= GR_GL_VER(2, 0) &&
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
shaderCaps->fIntegerSupport = (version >= GR_GL_VER(2, 0));
shaderCaps->fNonsquareMatrixSupport =
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
shaderCaps->fInverseHyperbolicSupport =
ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
}
if (ctxInfo.hasExtension("GL_NV_conservative_raster")) {
fConservativeRasterSupport = true;
}
if (GR_IS_GR_GL(standard)) {
fWireframeSupport = true;
}
if (GR_IS_GR_GL(standard)) {
shaderCaps->fRewriteSwitchStatements =
ctxInfo.glslGeneration() < SkSL::GLSLGeneration::k130; // introduced in GLSL 1.3
} else if (GR_IS_GR_GL_ES(standard)) {
shaderCaps->fRewriteSwitchStatements =
ctxInfo.glslGeneration() < SkSL::GLSLGeneration::k300es; // introduced in GLSL ES3
} else if (GR_IS_GR_WEBGL(standard)) {
shaderCaps->fRewriteSwitchStatements = version < GR_GL_VER(2, 0); // introduced in WebGL 2
shaderCaps->fCanUseVoidInSequenceExpressions =
false; // removed in WebGL 2, use workaround in all versions for safety
}
// Protect ourselves against tracking huge amounts of texture state.
static const uint8_t kMaxSaneSamplers = 32;
GrGLint maxSamplers;
GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
shaderCaps->fMaxFragmentSamplers = std::min<GrGLint>(kMaxSaneSamplers, maxSamplers);
// SGX and Mali GPUs have tiled architectures that have trouble with frequently changing VBOs.
// We've measured a performance increase using non-VBO vertex data for dynamic content on these
// GPUs. Perhaps we should read the renderer string and limit this decision to specific GPU
// families rather than basing it on the vendor alone.
// Angle can be initialized with client arrays disabled and needs to be queried. The Chrome
// command buffer blocks the use of client side buffers (but may emulate VBOs with them). Client
// side buffers are not allowed in core profiles.
if (GR_IS_GR_GL(standard) || GR_IS_GR_GL_ES(standard)) {
GrGLint clientArraysEnabled = GR_GL_TRUE;
if (ctxInfo.hasExtension("GL_ANGLE_client_arrays")) {
GR_GL_GetIntegerv(gli, GR_GL_CLIENT_ARRAYS_ANGLE, &clientArraysEnabled);
}
if (clientArraysEnabled && !ctxInfo.isOverCommandBuffer() && !fIsCoreProfile &&
(ctxInfo.vendor() == GrGLVendor::kARM || ctxInfo.vendor() == GrGLVendor::kImagination ||
ctxInfo.vendor() == GrGLVendor::kQualcomm)) {
fPreferClientSideDynamicBuffers = true;
}
} // No client side arrays in WebGL https://www.khronos.org/registry/webgl/specs/1.0/#6.2
if (!contextOptions.fAvoidStencilBuffers && !fSupportsProtectedContent) {
// To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
// We also avoid both for Protected Contexts due to their use of RenderBuffers (which
// cannot be correctly created as Protected).
this->initFSAASupport(contextOptions, ctxInfo, gli);
this->initStencilSupport(ctxInfo);
}
// Setup blit framebuffer
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
fBlitFramebufferFlags = 0;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_NV_framebuffer_blit")) {
fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
kNoMSAADst_BlitFramebufferFlag |
kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
} else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
// The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
// limitations.
fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
kResolveMustBeFull_BlitFrambufferFlag |
kNoMSAADst_BlitFramebufferFlag |
kNoFormatConversion_BlitFramebufferFlag |
kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
}
} // No WebGL 1.0 support for BlitFramebuffer
this->initBlendEqationSupport(ctxInfo);
if (GR_IS_GR_GL(standard)) {
fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
// extension includes glMapBuffer.
if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
fMapBufferFlags |= kSubset_MapFlag;
fMapBufferType = kMapBufferRange_MapBufferType;
} else {
fMapBufferType = kMapBuffer_MapBufferType;
}
} else if (GR_IS_GR_GL_ES(standard)) {
// Unextended GLES2 doesn't have any buffer mapping.
fMapBufferFlags = kNone_MapFlags;
if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
fMapBufferType = kChromium_MapBufferType;
} else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
fMapBufferType = kMapBufferRange_MapBufferType;
} else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
fMapBufferFlags = kCanMap_MapFlag;
fMapBufferType = kMapBuffer_MapBufferType;
}
} else if (GR_IS_GR_WEBGL(standard)) {
// explicitly removed https://www.khronos.org/registry/webgl/specs/2.0/#5.14
fMapBufferFlags = kNone_MapFlags;
}
// Buffers have more restrictions in WebGL than GLES. For example,
// https://www.khronos.org/registry/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING
// We therefore haven't attempted to support mapping or transfers between buffers and surfaces
// or between buffers.
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(2, 1) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object") ||
ctxInfo.hasExtension("GL_EXT_pixel_buffer_object")) {
fTransferFromBufferToTextureSupport = true;
fTransferFromSurfaceToBufferSupport = true;
fTransferBufferType = TransferBufferType::kARB_PBO;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0) ||
(ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
// GL_EXT_unpack_subimage needed to support subtexture rectangles
ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
fTransferFromBufferToTextureSupport = true;
fTransferFromSurfaceToBufferSupport = true;
if (version < GR_GL_VER(3, 0)) {
fTransferBufferType = TransferBufferType::kNV_PBO;
} else {
fTransferBufferType = TransferBufferType::kARB_PBO;
}
// TODO: get transfer buffers working in Chrome
// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
// fTransferFromBufferToTextureSupport = false;
// fTransferFromSurfaceToBufferSupport = false;
// fTransferBufferType = TransferBufferType::kChromium;
}
}
if (GR_IS_GR_GL(standard) &&
(version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_copy_buffer"))) {
fTransferFromBufferToBufferSupport = true;
} else if (GR_IS_GR_GL_ES(standard) &&
(version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_copy_buffer"))) {
fTransferFromBufferToBufferSupport = true;
}
// On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
// threshold to the maximum unless the client gives us a hint that map memory is cheap.
if (fBufferMapThreshold < 0) {
#if 0
// We think mapping on Chromium will be cheaper once we know ahead of time how much space
// we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
// using a small subset.
fBufferMapThreshold = ctxInfo.isOverCommandBuffer() ? 0 : SK_MaxS32;
#else
fBufferMapThreshold = SK_MaxS32;
#endif
}
if (GR_IS_GR_GL(standard)) {
fNPOTTextureTileSupport = true;
fMipmapSupport = true;
fAnisoSupport = version >= GR_GL_VER(4,6) ||
ctxInfo.hasExtension("GL_ARB_texture_filter_anisotropic") ||
ctxInfo.hasExtension("GL_EXT_texture_filter_anisotropic");
} else if (GR_IS_GR_GL_ES(standard)) {
// Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
// ES3 has no limitations.
fNPOTTextureTileSupport = version >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_OES_texture_npot");
// ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
// support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
// does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
// to alllow arbitrary wrap modes, however.
fMipmapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
fAnisoSupport = ctxInfo.hasExtension("GL_EXT_texture_filter_anisotropic");
} else if (GR_IS_GR_WEBGL(standard)) {
// Texture access works in the WebGL 2.0 API as in the OpenGL ES 3.0 API
fNPOTTextureTileSupport = version >= GR_GL_VER(2,0);
// All mipmapping and all wrapping modes are supported for non-power-of-
// two images [in WebGL 2.0].
fMipmapSupport = fNPOTTextureTileSupport;
fAnisoSupport = ctxInfo.hasExtension("GL_EXT_texture_filter_anisotropic") ||
ctxInfo.hasExtension("EXT_texture_filter_anisotropic");
}
if (fAnisoSupport) {
GR_GL_GetFloatv(gli, GR_GL_MAX_TEXTURE_MAX_ANISOTROPY, &fMaxTextureMaxAnisotropy);
}
GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
if (ctxInfo.vendor() == GrGLVendor::kARM) {
// On Mali G71, RT's above 4k have been observed to incur a performance cost.
fMaxPreferredRenderTargetSize = std::min(4096, fMaxPreferredRenderTargetSize);
}
fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
// Disable scratch texture reuse on Mali and Adreno devices
fReuseScratchTextures = (ctxInfo.vendor() != GrGLVendor::kARM);
#if 0
fReuseScratchBuffers = ctxInfo.vendor() != GrGLVendor::kARM
ctxInfo.vendor() != GrGLVendor::kQualcomm;
#endif
if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
}
#ifdef SK_BUILD_FOR_WIN
// We're assuming that on Windows Chromium we're using D3D ANGLE.
bool isD3DANGLE = angle_backend_is_d3d(ctxInfo.angleBackend()) ||
ctxInfo.isOverCommandBuffer();
// On ANGLE deferring flushes can lead to GPU starvation
fPreferVRAMUseOverFlushes = !isD3DANGLE;
#endif
if (ctxInfo.isOverCommandBuffer()) {
fMustClearUploadedBufferData = true;
}
// In a WASM build on Firefox, we see warnings like
// WebGL warning: texSubImage2D: This operation requires zeroing texture data. This is slow.
// WebGL warning: texSubImage2D: Texture has not been initialized prior to a partial upload,
// forcing the browser to clear it. This may be slow.
// Setting the initial clear seems to make those warnings go away and offers a substantial
// boost in performance in Firefox. Chrome sees a more modest increase.
if (GR_IS_GR_WEBGL(standard)) {
fShouldInitializeTextures = true;
}
if (GR_IS_GR_GL(standard)) {
// ARB allows mixed size FBO attachments, EXT does not.
if (version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
fOversizedStencilSupport = true;
} else {
SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
}
} else if (GR_IS_GR_GL_ES(standard)) {
// ES 3.0 supports mixed size FBO attachments, 2.0 does not.
fOversizedStencilSupport = version >= GR_GL_VER(3, 0);
} else if (GR_IS_GR_WEBGL(standard)) {
// WebGL 1.0 has some constraints for FBO attachments:
// https://www.khronos.org/registry/webgl/specs/1.0/index.html#6.6
// These constraints "no longer apply in WebGL 2"
fOversizedStencilSupport = version >= GR_GL_VER(2, 0);
}
if (GR_IS_GR_GL(standard)) {
fBaseVertexBaseInstanceSupport = version >= GR_GL_VER(4,2) ||
ctxInfo.hasExtension("GL_ARB_base_instance");
if (fBaseVertexBaseInstanceSupport) {
fNativeDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
ctxInfo.hasExtension("GL_ARB_draw_indirect");
if (version >= GR_GL_VER(4,3) || ctxInfo.hasExtension("GL_ARB_multi_draw_indirect")) {
fMultiDrawType = MultiDrawType::kMultiDrawIndirect;
}
}
fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
} else if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_ANGLE_base_vertex_base_instance")) {
fBaseVertexBaseInstanceSupport = true;
fNativeDrawIndirectSupport = true;
fMultiDrawType = MultiDrawType::kANGLEOrWebGL;
// The indirect structs need to reside in CPU memory for the ANGLE version.
fUseClientSideIndirectBuffers = true;
} else {
fBaseVertexBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
// Don't support indirect draws on ES. They don't allow VAO 0.
//
// "An INVALID_OPERATION error is generated if zero is bound to VERTEX_ARRAY_BINDING,
// DRAW_INDIRECT_BUFFER or to any enabled vertex array."
//
// https://www.khronos.org/registry/OpenGL/specs/es/3.1/es_spec_3.1.pdf
}
fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
} else if (GR_IS_GR_WEBGL(standard)) {
fBaseVertexBaseInstanceSupport = ctxInfo.hasExtension(
"WEBGL_draw_instanced_base_vertex_base_instance");
if (fBaseVertexBaseInstanceSupport && ctxInfo.hasExtension(
"GL_WEBGL_multi_draw_instanced_base_vertex_base_instance")) {
fNativeDrawIndirectSupport = true;
fMultiDrawType = MultiDrawType::kANGLEOrWebGL;
}
// The indirect structs need to reside in CPU memory for the WebGL version.
fUseClientSideIndirectBuffers = true;
fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
}
// We used to disable this as a correctness workaround (http://anglebug.com/4536). Now it is
// disabled because of poor performance (http://skbug.com/11998).
if (ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D11) {
fBaseVertexBaseInstanceSupport = false;
fNativeDrawIndirectSupport = false;
fMultiDrawType = MultiDrawType::kNone;
}
// We do not support GrBackendSemaphore for GL backends because the clients cannot really make
// GrGLsync objects ahead of time without talking to the GPU.
fBackendSemaphoreSupport = false;
// We prefer GL sync objects but also support NV_fence_sync. The former can be
// used to implement GrGLsync and GrSemaphore. The latter only implements GrGLsync.
// TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
if (GR_IS_GR_WEBGL(standard)) {
// Only in WebGL 2.0
fSemaphoreSupport = fFenceSyncSupport = version >= GR_GL_VER(2, 0);
fFenceType = FenceType::kSyncObject;
} else if (GR_IS_GR_GL(standard) &&
(version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync"))) {
fSemaphoreSupport = fFenceSyncSupport = true;
fFenceType = FenceType::kSyncObject;
} else if (GR_IS_GR_GL_ES(standard) &&
(version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync"))) {
fSemaphoreSupport = fFenceSyncSupport = true;
fFenceType = FenceType::kSyncObject;
} else if (ctxInfo.hasExtension("GL_NV_fence")) {
// This extension can exist in GL and GL ES. We have it last because we prefer the
// standard GLsync object implementation which also supports GPU semaphore semantics.
fFenceSyncSupport = true;
fFenceType = FenceType::kNVFence;
}
fFinishedProcAsyncCallbackSupport = fFenceSyncSupport;
if (GR_IS_GR_WEBGL(standard)) {
if (version >= GR_GL_VER(2, 0)) {
if (ctxInfo.hasExtension("EXT_disjoint_timer_query_webgl2") ||
ctxInfo.hasExtension("GL_EXT_disjoint_timer_query_webgl2")) {
fTimerQueryType = TimerQueryType::kDisjoint;
}
} else {
if (ctxInfo.hasExtension("EXT_disjoint_timer_query") ||
ctxInfo.hasExtension("GL_EXT_disjoint_timer_query")) {
fTimerQueryType = TimerQueryType::kDisjoint;
}
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_EXT_disjoint_timer_query")) {
fTimerQueryType = TimerQueryType::kDisjoint;
}
} else if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 3) || ctxInfo.hasExtension("GL_EXT_timer_query") ||
ctxInfo.hasExtension("GL_ARB_timer_query")) {
fTimerQueryType = TimerQueryType::kRegular;
}
}
if (fTimerQueryType != TimerQueryType::kNone) {
fSupportedGpuStats |= skgpu::GpuStatsFlags::kElapsedTime;
}
// Safely moving textures between contexts requires semaphores.
fCrossContextTextureSupport = fSemaphoreSupport;
// Half float vertex attributes requires GL3 or ES3
// It can also work with OES_VERTEX_HALF_FLOAT, but that requires a different enum.
if (GR_IS_GR_GL(standard)) {
fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(3, 0));
} else if (GR_IS_GR_GL_ES(standard)) {
fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(3, 0));
} else if (GR_IS_GR_WEBGL(standard)) {
// This appears to be supported in 2.0, looking at the spec.
fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(2, 0));
}
fDynamicStateArrayGeometryProcessorTextureSupport = true;
if (GR_IS_GR_GL(standard)) {
fProgramBinarySupport = (version >= GR_GL_VER(4, 1));
fProgramParameterSupport = (version >= GR_GL_VER(4, 1));
} else if (GR_IS_GR_GL_ES(standard)) {
fProgramBinarySupport =
(version >= GR_GL_VER(3, 0)) || ctxInfo.hasExtension("GL_OES_get_program_binary");
fProgramParameterSupport = (version >= GR_GL_VER(3, 0));
} // Explicitly not supported in WebGL 2.0
// https://www.khronos.org/registry/webgl/specs/2.0/#5.4
if (fProgramBinarySupport) {
GrGLint count;
GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
if (count > 0) {
fProgramBinaryFormats.resize_back(count);
GR_GL_GetIntegerv(gli, GR_GL_PROGRAM_BINARY_FORMATS,
reinterpret_cast<GrGLint*>(fProgramBinaryFormats.data()));
} else {
fProgramBinarySupport = false;
}
}
if (GR_IS_GR_GL(standard)) {
fSamplerObjectSupport =
version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_sampler_objects");
} else if (GR_IS_GR_GL_ES(standard)) {
fSamplerObjectSupport = version >= GR_GL_VER(3,0);
} else if (GR_IS_GR_WEBGL(standard)) {
fSamplerObjectSupport = version >= GR_GL_VER(2,0);
}
// We currently use sampler objects whenever they are available.
fUseSamplerObjects = fSamplerObjectSupport;
if (GR_IS_GR_GL_ES(standard)) {
fTiledRenderingSupport = ctxInfo.hasExtension("GL_QCOM_tiled_rendering");
}
if (ctxInfo.vendor() == GrGLVendor::kARM) {
fShouldCollapseSrcOverToSrcWhenAble = true;
}
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue) {
// https://b/195281495
// The TecnoSpark 3 Pro with a PowerVR GE8300 seems to have a steep dithering performance
// cliff in the Android Framework
fAvoidDithering = true;
}
#endif
FormatWorkarounds formatWorkarounds;
if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, gli, shaderCaps,
&formatWorkarounds);
}
// Requires msaa support, ES compatibility have already been detected.
this->initFormatTable(ctxInfo, gli, formatWorkarounds);
this->finishInitialization(contextOptions);
// For GL, besides the user-specifiable override, we also want to avoid stencil buffers
// in Protected mode (to avoid using RenderBuffers)
fAvoidStencilBuffers = contextOptions.fAvoidStencilBuffers || fSupportsProtectedContent;
// For now these two are equivalent but we could have dst read in shader via some other method.
shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
}