blob: 828637d02755c6f294c9f1ab40bf66783ebebe53 [file] [log] [blame]
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/gpu/GrContextOptions.h"
#include "src/core/SkTSearch.h"
#include "src/core/SkTSort.h"
#include "src/gpu/GrRenderTargetProxyPriv.h"
#include "src/gpu/GrShaderCaps.h"
#include "src/gpu/GrSurfaceProxyPriv.h"
#include "src/gpu/GrTextureProxyPriv.h"
#include "src/gpu/SkGr.h"
#include "src/gpu/gl/GrGLCaps.h"
#include "src/gpu/gl/GrGLContext.h"
#include "src/gpu/gl/GrGLRenderTarget.h"
#include "src/gpu/gl/GrGLTexture.h"
#include "src/utils/SkJSONWriter.h"
GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
const GrGLContextInfo& ctxInfo,
const GrGLInterface* glInterface) : INHERITED(contextOptions) {
fStandard = ctxInfo.standard();
fStencilFormats.reset();
fMSFBOType = kNone_MSFBOType;
fInvalidateFBType = kNone_InvalidateFBType;
fMapBufferType = kNone_MapBufferType;
fTransferBufferType = kNone_TransferBufferType;
fMaxFragmentUniformVectors = 0;
fPackFlipYSupport = false;
fTextureUsageSupport = false;
fAlpha8IsRenderable = false;
fImagingSupport = false;
fVertexArrayObjectSupport = false;
fDebugSupport = false;
fES2CompatibilitySupport = false;
fDrawIndirectSupport = false;
fMultiDrawIndirectSupport = false;
fBaseInstanceSupport = false;
fIsCoreProfile = false;
fBindFragDataLocationSupport = false;
fRectangleTextureSupport = false;
fRGBA8888PixelsOpsAreSlow = false;
fPartialFBOReadIsSlow = false;
fMipMapLevelAndLodControlSupport = false;
fRGBAToBGRAReadbackConversionsAreSlow = false;
fUseBufferDataNullHint = false;
fDoManualMipmapping = false;
fClearToBoundaryValuesIsBroken = false;
fClearTextureSupport = false;
fDrawArraysBaseVertexIsBroken = false;
fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false;
fUseDrawInsteadOfAllRenderTargetWrites = false;
fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
fDetachStencilFromMSAABuffersBeforeReadPixels = false;
fDontSetBaseOrMaxLevelForExternalTextures = false;
fProgramBinarySupport = false;
fProgramParameterSupport = false;
fSamplerObjectSupport = false;
fFBFetchRequiresEnablePerSample = false;
fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
fMaxInstancesPerDrawWithoutCrashing = 0;
fShaderCaps.reset(new GrShaderCaps(contextOptions));
this->init(contextOptions, ctxInfo, glInterface);
}
void GrGLCaps::init(const GrContextOptions& contextOptions,
const GrGLContextInfo& ctxInfo,
const GrGLInterface* gli) {
GrGLStandard standard = ctxInfo.standard();
// standard can be unused (optimzed away) if SK_ASSUME_GL_ES is set
sk_ignore_unused_variable(standard);
GrGLVersion version = ctxInfo.version();
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 = SkMin32(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);
}
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");
} // no WebGL support
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);
} // no WebGL support
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 (kARM_GrGLVendor == ctxInfo.vendor()) {
fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
}
}
if (kARM_GrGLVendor == ctxInfo.vendor() ||
kImagination_GrGLVendor == ctxInfo.vendor() ||
kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
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");
} // no WebGL support
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)) {
fMultisampleDisableSupport = true;
} else if (GR_IS_GR_GL_ES(standard)) {
fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
} // no WebGL support
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
fInstanceAttribSupport =
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)) {
fInstanceAttribSupport =
version >= GR_GL_VER(3, 0) ||
(ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
} else if (GR_IS_GR_WEBGL(standard)) {
// WebGL 2.0 has DrawArraysInstanced and drawElementsInstanced
fInstanceAttribSupport = 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;
}
} // no WebGL support
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)) {
// ANGLE will advertise the extension in ES2 contexts but actually using the texture in
// a shader requires ES3 shading language.
fRectangleTextureSupport = ctxInfo.hasExtension("GL_ANGLE_texture_rectangle") &&
ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
} // no WebGL support
// 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")) {
this->fShaderCaps->fTextureSwizzleAppliedInShader = false;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3,0)) {
this->fShaderCaps->fTextureSwizzleAppliedInShader = false;
}
} // no WebGL support
if (GR_IS_GR_GL(standard)) {
fMipMapLevelAndLodControlSupport = true;
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3,0)) {
fMipMapLevelAndLodControlSupport = true;
}
} // no WebGL support
#ifdef SK_BUILD_FOR_WIN
// We're assuming that on Windows Chromium we're using ANGLE.
bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
kChromium_GrGLDriver == ctxInfo.driver();
// Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
fRGBA8888PixelsOpsAreSlow = isANGLE;
// On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
// check DX11 ANGLE.
fPartialFBOReadIsSlow = isANGLE;
#endif
bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
bool isMAC = false;
#ifdef SK_BUILD_FOR_MAC
isMAC = true;
#endif
// Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
// vis-versa.
fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
// Chrome's command buffer will zero out a buffer if null is passed to glBufferData to
// avoid letting an application see uninitialized memory.
if (GR_IS_GR_GL(standard) || GR_IS_GR_GL_ES(standard)) {
fUseBufferDataNullHint = kChromium_GrGLDriver != ctxInfo.driver();
} else if (GR_IS_GR_WEBGL(standard)) {
// WebGL spec explicitly disallows null values.
fUseBufferDataNullHint = false;
}
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");
} // no WebGL support
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
fSupportsAHardwareBufferImages = true;
#endif
// We only enable srgb support if both textures and FBOs support srgb.
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3,0)) {
fSRGBSupport = true;
} else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
fSRGBSupport = true;
}
}
// All the above srgb extensions support toggling srgb writes
if (fSRGBSupport) {
fSRGBWriteControl = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
fSRGBSupport = version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
// ES through 3.1 requires EXT_srgb_write_control to support toggling
// sRGB writing for destinations.
fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
} else if (GR_IS_GR_WEBGL(standard)) {
// sRGB extension should be on most WebGL 1.0 contexts, although
// sometimes under 2 names.
fSRGBSupport = version >= GR_GL_VER(2,0) || ctxInfo.hasExtension("GL_EXT_sRGB") ||
ctxInfo.hasExtension("EXT_sRGB");
}
// This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
// all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
// and sBGRA is basically impossible to support on any version of ES (with our current code).
// In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
// of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
// we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
// affects Windows.
if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig &&
(GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard))) {
fSRGBSupport = false;
}
/**************************************************************************
* GrShaderCaps fields
**************************************************************************/
// This must be called after fCoreProfile is set on the GrGLCaps
this->initGLSL(ctxInfo, gli);
GrShaderCaps* shaderCaps = fShaderCaps.get();
shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
// 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() >= k130_GrGLSLGeneration;
shaderCaps->fShaderDerivativeSupport = true;
// we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
shaderCaps->fGeometryShaderSupport = version >= GR_GL_VER(3, 2) &&
ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
if (shaderCaps->fGeometryShaderSupport) {
if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
shaderCaps->fGSInvocationsSupport = true;
} else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
shaderCaps->fGSInvocationsSupport = true;
shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
}
}
shaderCaps->fIntegerSupport = version >= GR_GL_VER(3, 0) &&
ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard)) {
shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
shaderCaps->fShaderDerivativeSupport = version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_OES_standard_derivatives");
// Mali and early Adreno both have support for geometry shaders, but they appear to be
// implemented in software. In practice with ccpr, they are slower than the backup impl that
// only uses vertex shaders.
if (kARM_GrGLVendor != ctxInfo.vendor() &&
kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
kAdreno4xx_other_GrGLRenderer != ctxInfo.renderer()) {
if (version >= GR_GL_VER(3,2)) {
shaderCaps->fGeometryShaderSupport = true;
} else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
shaderCaps->fGeometryShaderSupport = true;
shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
}
shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
}
shaderCaps->fIntegerSupport = version >= GR_GL_VER(3, 0) &&
ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
} else if (GR_IS_GR_WEBGL(standard)) {
shaderCaps->fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives") ||
ctxInfo.hasExtension("OES_standard_derivatives");
}
// 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 = SkTMin<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.
// 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)) {
if (ctxInfo.driver() != kChromium_GrGLDriver && !fIsCoreProfile &&
(ctxInfo.vendor() == kARM_GrGLVendor || ctxInfo.vendor() == kImagination_GrGLVendor ||
ctxInfo.vendor() == kQualcomm_GrGLVendor)) {
fPreferClientSideDynamicBuffers = true;
}
} // No client side arrays in WebGL https://www.khronos.org/registry/webgl/specs/1.0/#6.2
if (!contextOptions.fAvoidStencilBuffers) {
// To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
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)) {
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_MapBufferType;
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_MapBufferType;
}
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")) {
fTransferBufferSupport = true;
fTransferBufferType = kPBO_TransferBufferType;
}
} 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"))) {
fTransferBufferSupport = true;
fTransferBufferType = kPBO_TransferBufferType;
// TODO: get transfer buffers working in Chrome
// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
// fTransferBufferSupport = true;
// fTransferBufferType = kChromium_TransferBufferType;
}
} // no WebGL support
// 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 = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
#else
fBufferMapThreshold = SK_MaxS32;
#endif
}
if (GR_IS_GR_GL(standard)) {
fNPOTTextureTileSupport = true;
fMipMapSupport = true;
} 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");
} 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;
}
GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
}
GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
// Our render targets are always created with textures as the color
// attachment, hence this min:
fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
if (kARM_GrGLVendor == ctxInfo.vendor()) {
// On Mali G71, RT's above 4k have been observed to incur a performance cost.
fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
}
fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
// Disable scratch texture reuse on Mali and Adreno devices
fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
#if 0
fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
kQualcomm_GrGLVendor != ctxInfo.vendor();
#endif
if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
}
#ifdef SK_BUILD_FOR_WIN
// On ANGLE deferring flushes can lead to GPU starvation
fPreferVRAMUseOverFlushes = !isANGLE;
#endif
if (kARM_GrGLVendor == ctxInfo.vendor()) {
// ARM seems to do better with larger quantities of fine triangles, as opposed to using the
// sample mask. (At least in our current round rect op.)
fPreferTrianglesOverSampleMask = true;
}
if (kChromium_GrGLDriver == ctxInfo.driver()) {
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)) {
fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
ctxInfo.hasExtension("GL_ARB_draw_indirect");
fBaseInstanceSupport = version >= GR_GL_VER(4,2);
fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
(fDrawIndirectSupport &&
!fBaseInstanceSupport && // The ARB extension has no base inst.
ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
} else if (GR_IS_GR_GL_ES(standard)) {
fDrawIndirectSupport = version >= GR_GL_VER(3,1);
fMultiDrawIndirectSupport = fDrawIndirectSupport &&
ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
fBaseInstanceSupport = fDrawIndirectSupport &&
ctxInfo.hasExtension("GL_EXT_base_instance");
fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
} else if (GR_IS_GR_WEBGL(standard)) {
// WebGL lacks indirect support, but drawRange was added in WebGL 2.0
fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
}
// TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
if (GR_IS_GR_GL(standard)) {
fFenceSyncSupport = (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync"));
} else if (GR_IS_GR_GL_ES(standard)) {
fFenceSyncSupport = (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync"));
} else if (GR_IS_GR_WEBGL(standard)) {
// Only in WebGL 2.0
fFenceSyncSupport = version >= GR_GL_VER(2, 0);
}
// The same objects (GL sync objects) are used to implement GPU/CPU fence syncs and GPU/GPU
// semaphores.
fSemaphoreSupport = fFenceSyncSupport;
// 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);
fProgramBinarySupport = count > 0;
}
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);
}
FormatWorkarounds formatWorkarounds;
if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps,
&formatWorkarounds);
}
// Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
// already been detected.
this->initFormatTable(contextOptions, ctxInfo, gli, formatWorkarounds);
this->initConfigTable(contextOptions, ctxInfo, gli);
this->applyOptionsOverrides(contextOptions);
shaderCaps->applyOptionsOverrides(contextOptions);
// For now these two are equivalent but we could have dst read in shader via some other method.
shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
}
const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
bool isCoreProfile) {
if (GR_IS_GR_GL(standard)) {
switch (generation) {
case k110_GrGLSLGeneration:
return "#version 110\n";
case k130_GrGLSLGeneration:
return "#version 130\n";
case k140_GrGLSLGeneration:
return "#version 140\n";
case k150_GrGLSLGeneration:
if (isCoreProfile) {
return "#version 150\n";
} else {
return "#version 150 compatibility\n";
}
case k330_GrGLSLGeneration:
if (isCoreProfile) {
return "#version 330\n";
} else {
return "#version 330 compatibility\n";
}
case k400_GrGLSLGeneration:
if (isCoreProfile) {
return "#version 400\n";
} else {
return "#version 400 compatibility\n";
}
case k420_GrGLSLGeneration:
if (isCoreProfile) {
return "#version 420\n";
} else {
return "#version 420 compatibility\n";
}
default:
break;
}
} else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
switch (generation) {
case k110_GrGLSLGeneration:
// ES2s shader language is based on version 1.20 but is version
// 1.00 of the ES language.
return "#version 100\n";
case k330_GrGLSLGeneration:
return "#version 300 es\n";
case k310es_GrGLSLGeneration:
return "#version 310 es\n";
case k320es_GrGLSLGeneration:
return "#version 320 es\n";
default:
break;
}
}
return "<no version>";
}
bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
if (GR_IS_GR_GL(ctxInfo.standard()) &&
ctxInfo.version() < GR_GL_VER(4,1) &&
!ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
// We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
return true;
}
// glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
// geometry shaders don't have lower precision than vertex and fragment.
for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
GrGLint range[2];
GrGLint bits;
GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
if (range[0] < 127 || range[1] < 127 || bits < 23) {
return false;
}
}
return true;
}
void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
GrGLStandard standard = ctxInfo.standard();
GrGLVersion version = ctxInfo.version();
/**************************************************************************
* Caps specific to GrShaderCaps
**************************************************************************/
GrShaderCaps* shaderCaps = fShaderCaps.get();
shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
if (GR_IS_GR_GL_ES(standard)) {
// fFBFetchRequiresEnablePerSample is not a shader cap but is initialized below to keep it
// with related FB fetch logic.
if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
shaderCaps->fFBFetchSupport = true;
shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
fFBFetchRequiresEnablePerSample = false;
} else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
// Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know.
shaderCaps->fFBFetchNeedsCustomOutput = false;
shaderCaps->fFBFetchSupport = true;
shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
fFBFetchRequiresEnablePerSample = false;
} else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
// The arm extension also requires an additional flag which we will set onResetContext.
shaderCaps->fFBFetchNeedsCustomOutput = false;
shaderCaps->fFBFetchSupport = true;
shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
fFBFetchRequiresEnablePerSample = true;
}
shaderCaps->fUsesPrecisionModifiers = true;
} else if (GR_IS_GR_WEBGL(standard)) {
shaderCaps->fUsesPrecisionModifiers = true;
}
if (GR_IS_GR_GL(standard)) {
shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
shaderCaps->fFlatInterpolationSupport =
ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
} // not sure for WebGL
// Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530). ANGLE
// Avoid on ANGLE too, it inserts a geometry shader into the pipeline to implement flat interp.
shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
kQualcomm_GrGLVendor != ctxInfo.vendor() &&
kANGLE_GrGLDriver != ctxInfo.driver();
if (GR_IS_GR_GL(standard)) {
shaderCaps->fNoPerspectiveInterpolationSupport =
ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
shaderCaps->fNoPerspectiveInterpolationSupport = true;
shaderCaps->fNoPerspectiveInterpolationExtensionString =
"GL_NV_shader_noperspective_interpolation";
}
} // Not sure for WebGL
if (GR_IS_GR_GL(standard)) {
shaderCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
shaderCaps->fSampleVariablesSupport = true;
} else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
shaderCaps->fSampleVariablesSupport = true;
shaderCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
}
}
shaderCaps->fSampleVariablesStencilSupport = shaderCaps->fSampleVariablesSupport;
if (kQualcomm_GrGLVendor == ctxInfo.vendor() || kATI_GrGLVendor == ctxInfo.vendor()) {
// FIXME: The sample mask round rect op draws nothing on several Adreno and Radeon bots.
// Other ops that use sample mask while rendering to stencil seem to work fine. Temporarily
// disable sample mask on color buffers while we investigate.
// http://skbug.com/8921
shaderCaps->fSampleVariablesSupport = false;
}
shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
shaderCaps->fGLSLGeneration,
fIsCoreProfile);
if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
if (k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
}
} // WebGL might have to check for OES_standard_derivatives
// Frag Coords Convention support is not part of ES
if (GR_IS_GR_GL(standard) &&
(ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
}
if (GR_IS_GR_GL_ES(standard)) {
shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
}
if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
shaderCaps->fExternalTextureSupport = true;
shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
} else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
// At least one driver has been found that has this extension without the "GL_" prefix.
shaderCaps->fExternalTextureSupport = true;
shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
}
}
if (GR_IS_GR_GL(standard)) {
shaderCaps->fVertexIDSupport = true;
} else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
// Desktop GLSL 3.30 == ES GLSL 3.00.
shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
}
if (GR_IS_GR_GL(standard)) {
shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
}
shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
shaderCaps->fHasLowFragmentPrecision = kMali4xx_GrGLRenderer == ctxInfo.renderer();
if (GR_IS_GR_GL(standard)) {
shaderCaps->fBuiltinFMASupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard)) {
shaderCaps->fBuiltinFMASupport = ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration;
}
}
bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
return false;
}
if (GR_IS_GR_GL(ctxInfo.standard())) {
if (ctxInfo.version() < GR_GL_VER(4, 3) &&
!ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
return false;
}
} else if (GR_IS_GR_GL_ES(ctxInfo.standard())) {
if (!hasChromiumPathRendering &&
ctxInfo.version() < GR_GL_VER(3, 1)) {
return false;
}
} else if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
// No WebGL support
return false;
}
// We only support v1.3+ of GL_NV_path_rendering which allows us to
// set individual fragment inputs with ProgramPathFragmentInputGen. The API
// additions are detected by checking the existence of the function.
// We also use *Then* functions that not all drivers might have. Check
// them for consistency.
if (!gli->fFunctions.fStencilThenCoverFillPath ||
!gli->fFunctions.fStencilThenCoverStrokePath ||
!gli->fFunctions.fStencilThenCoverFillPathInstanced ||
!gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
!gli->fFunctions.fProgramPathFragmentInputGen) {
return false;
}
return true;
}
bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
GrPixelConfig readConfig,
std::function<void (GrGLenum, GrGLint*)> getIntegerv,
std::function<bool ()> bindRenderTarget,
std::function<void ()> unbindRenderTarget) const {
// If it's not possible to even have a color attachment of surfaceConfig then read pixels is
// not supported regardless of readConfig.
if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
return false;
}
GrGLenum readFormat;
GrGLenum readType;
if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
return false;
}
if (GR_IS_GR_GL(fStandard)) {
// Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
// the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
// GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
// GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
// The manual does not seem to fully match the spec as the spec allows integer formats
// when the bound color buffer is an integer buffer. It doesn't specify which integer
// formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
readFormat != GR_GL_RGBA_INTEGER) {
return false;
}
// There is also a set of allowed types, but all the types we use are in the set:
// GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
// GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
// GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
// GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
// GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
// GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
// GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
return true;
}
// See Section 16.1.2 in the ES 3.2 specification.
switch (fConfigTable[surfaceConfig].fFormatType) {
case kNormalizedFixedPoint_FormatType:
if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
return true;
}
break;
case kFloat_FormatType:
if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
return true;
}
break;
}
if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
ReadPixelsFormat* rpFormat =
const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
GrGLint format = 0, type = 0;
if (!bindRenderTarget()) {
return false;
}
getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
rpFormat->fFormat = format;
rpFormat->fType = type;
unbindRenderTarget();
}
return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
}
void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
const GrGLInterface* gli) {
// We need dual source blending and the ability to disable multisample in order to support mixed
// samples in every corner case.
if (fMultisampleDisableSupport && this->shaderCaps()->dualSourceBlendingSupport()) {
fMixedSamplesSupport = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
}
if (GR_IS_GR_GL(ctxInfo.standard())) {
if (ctxInfo.version() >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
fMSFBOType = kStandard_MSFBOType;
if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
// Core profile removes ALPHA8 support.
// OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
// However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
// present.
fAlpha8IsRenderable = true;
}
} else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
fMSFBOType = kStandard_MSFBOType;
}
} else if (GR_IS_GR_GL_ES(ctxInfo.standard())) {
if (ctxInfo.version() >= GR_GL_VER(3,0) &&
ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
// The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
// it is part of the spec. Thus alpha8 will not be renderable for those devices.
fAlpha8IsRenderable = true;
}
// We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
// ES3 driver bugs on at least one device with a tiled GPU (N10).
if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
} else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
} else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
fMSFBOType = kStandard_MSFBOType;
} else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
fMSFBOType = kStandard_MSFBOType;
} else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
fMSFBOType = kStandard_MSFBOType;
} else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
fMSFBOType = kES_Apple_MSFBOType;
}
} else if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
// No support in WebGL
fMSFBOType = kNone_MSFBOType;
}
// We disable MSAA for older (pre-Gen9) Intel GPUs for performance reasons.
// ApolloLake is the first Gen9 chipset.
if (kIntel_GrGLVendor == ctxInfo.vendor() &&
(ctxInfo.renderer() < kIntelApolloLake_GrGLRenderer ||
ctxInfo.renderer() == kOther_GrGLRenderer)) {
fMSFBOType = kNone_MSFBOType;
}
}
void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
bool layoutQualifierSupport = false;
if ((GR_IS_GR_GL(fStandard) && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
(GR_IS_GR_GL_ES(fStandard) && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
layoutQualifierSupport = true;
} else if (GR_IS_GR_WEBGL(fStandard)) {
return;
}
if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
} else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
layoutQualifierSupport) {
fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
} else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
fBlendEquationSupport = kAdvanced_BlendEquationSupport;
shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
} else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
fBlendEquationSupport = kAdvanced_BlendEquationSupport;
shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
// TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
// slow on a particular platform.
}
}
namespace {
const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
}
void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
// Build up list of legal stencil formats (though perhaps not supported on
// the particular gpu/driver) from most preferred to least.
// these consts are in order of most preferred to least preferred
// we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
static const StencilFormat
// internal Format stencil bits total bits packed?
gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
// gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
if (GR_IS_GR_GL(ctxInfo.standard())) {
bool supportsPackedDS =
ctxInfo.version() >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
ctxInfo.hasExtension("GL_ARB_framebuffer_object");
// S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
// require FBO support we can expect these are legal formats and don't
// check. These also all support the unsized GL_STENCIL_INDEX.
fStencilFormats.push_back() = gS8;
fStencilFormats.push_back() = gS16;
if (supportsPackedDS) {
fStencilFormats.push_back() = gD24S8;
}
fStencilFormats.push_back() = gS4;
if (supportsPackedDS) {
fStencilFormats.push_back() = gDS;
}
} else if (GR_IS_GR_GL_ES(ctxInfo.standard())) {
// ES2 has STENCIL_INDEX8 without extensions but requires extensions
// for other formats.
// ES doesn't support using the unsized format.
fStencilFormats.push_back() = gS8;
//fStencilFormats.push_back() = gS16;
if (ctxInfo.version() >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
fStencilFormats.push_back() = gD24S8;
}
if (ctxInfo.hasExtension("GL_OES_stencil4")) {
fStencilFormats.push_back() = gS4;
}
} else if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
fStencilFormats.push_back() = gS8;
if (ctxInfo.version() >= GR_GL_VER(2,0)) {
fStencilFormats.push_back() = gD24S8;
}
}
}
#ifdef SK_ENABLE_DUMP_GPU
void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
// We are called by the base class, which has already called beginObject(). We choose to nest
// all of our caps information in a named sub-object.
writer->beginObject("GL caps");
writer->beginArray("Stencil Formats");
for (int i = 0; i < fStencilFormats.count(); ++i) {
writer->beginObject(nullptr, false);
writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
writer->endObject();
}
writer->endArray();
static const char* kMSFBOExtStr[] = {
"None",
"Standard",
"Apple",
"IMG MS To Texture",
"EXT MS To Texture",
};
GR_STATIC_ASSERT(0 == kNone_MSFBOType);
GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
static const char* kInvalidateFBTypeStr[] = {
"None",
"Discard",
"Invalidate",
};
GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
static const char* kMapBufferTypeStr[] = {
"None",
"MapBuffer",
"MapBufferRange",
"Chromium",
};
GR_STATIC_ASSERT(0 == kNone_MapBufferType);
GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
writer->appendBool("Core Profile", fIsCoreProfile);
writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
writer->appendBool("Texture Usage support", fTextureUsageSupport);
writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
writer->appendBool("GL_ARB_imaging support", fImagingSupport);
writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
writer->appendBool("Debug support", fDebugSupport);
writer->appendBool("Draw indirect support", fDrawIndirectSupport);
writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
writer->appendBool("Base instance support", fBaseInstanceSupport);
writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
writer->appendBool("BGRA to RGBA readback conversions are slow",
fRGBAToBGRAReadbackConversionsAreSlow);
writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
fUseDrawInsteadOfAllRenderTargetWrites);
writer->appendBool("Max instances per draw without crashing (or zero)",
fMaxInstancesPerDrawWithoutCrashing);
writer->beginArray("configs");
for (int i = 0; i < kGrPixelConfigCnt; ++i) {
writer->beginObject(nullptr, false);
writer->appendHexU32("flags", fConfigTable[i].fFlags);
writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
writer->appendHexU32("e_format_read_pixels",
fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
writer->appendHexU32(
"e_format_teximage",
fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
writer->appendHexU32("i_for_renderbuffer",
fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
writer->endObject();
}
writer->endArray();
writer->endObject();
}
#else
void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const { }
#endif
bool GrGLCaps::bgraIsInternalFormat() const {
return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
}
bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
GrGLenum* internalFormat, GrGLenum* externalFormat,
GrGLenum* externalType) const {
if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
externalFormat, externalType)) {
return false;
}
*internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
return true;
}
bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
GrGLenum* internalFormat) const {
if (!GrPixelConfigIsCompressed(surfaceConfig)) {
return false;
}
*internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
return true;
}
bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
GrGLenum* externalFormat, GrGLenum* externalType) const {
if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
externalFormat, externalType)) {
return false;
}
return true;
}
void GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
SkASSERT(!GrPixelConfigIsCompressed(config));
*internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
}
void GrGLCaps::getSizedInternalFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
*internalFormat = fConfigTable[config].fFormats.fSizedInternalFormat;
}
bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
ExternalFormatUsage usage, GrGLenum* externalFormat,
GrGLenum* externalType) const {
SkASSERT(externalFormat && externalType);
if (GrPixelConfigIsCompressed(memoryConfig)) {
return false;
}
bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
*externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
*externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
// When GL_RED is supported as a texture format, our alpha-only textures are stored using
// GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
// surface is not alpha-only and we want alpha to really mean the alpha component of the
// texture, not the red component.
if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
if (GR_GL_RED == *externalFormat) {
*externalFormat = GR_GL_ALPHA;
}
}
return true;
}
void GrGLCaps::setStencilFormatIndexForFormat(GrGLSizedInternalFormat format, int index) {
SkASSERT(!this->hasStencilFormatBeenDeterminedForFormat(format));
this->getFormatInfo(format).fStencilFormatIndex =
index < 0 ? FormatInfo::kUnsupported_StencilFormatIndex : index;
}
void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
const FormatWorkarounds& formatWorkarounds) {
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();
uint32_t nonMSAARenderFlags = FormatInfo::kFBOColorAttachment_Flag;
uint32_t msaaRenderFlags = nonMSAARenderFlags;
if (kNone_MSFBOType != fMSFBOType) {
msaaRenderFlags |= FormatInfo::kFBOColorAttachmentWithMSAA_Flag;
}
bool texStorageSupported = false;
if (GR_IS_GR_GL(standard)) {
// The EXT version can apply to either GL or GLES.
texStorageSupported = version >= GR_GL_VER(4,2) ||
ctxInfo.hasExtension("GL_ARB_texture_storage") ||
ctxInfo.hasExtension("GL_EXT_texture_storage");
} else if (GR_IS_GR_GL_ES(standard)) {
texStorageSupported = version >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_EXT_texture_storage");
} else if (GR_IS_GR_WEBGL(standard)) {
texStorageSupported = version >= GR_GL_VER(2,0);
}
if (fDriverBugWorkarounds.disable_texture_storage) {
texStorageSupported = false;
}
#ifdef SK_BUILD_FOR_ANDROID
// crbug.com/945506. Telemetry reported a memory usage regression for Android Go Chrome/WebView
// when using glTexStorage2D. This appears to affect OOP-R (so not just over command buffer).
texStorageSupported = false;
#endif
// ES 2.0 requires that the internal/external formats match so we can't use sized internal
// formats for glTexImage until ES 3.0. TODO: Support sized internal formats in WebGL2.
bool texImageSupportsSizedInternalFormat =
(GR_IS_GR_GL(standard) || (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0)));
// This is set when we know we have both texture and render support for:
// R 8/16/16F
// RG 8/16/16F
// The floating point formats above also depend on additional general floating put support on
// the device which we query later on.
bool textureRedSupport = false;
if (!formatWorkarounds.fDisableTextureRedForMesa) {
if (GR_IS_GR_GL(standard)) {
textureRedSupport =
version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
} else if (GR_IS_GR_GL_ES(standard)) {
textureRedSupport =
version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
}
} // No WebGL support
// Check for [half] floating point texture support
// NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
// supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
// [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
bool hasFP16Textures = false;
enum class HalfFPRenderTargetSupport { kNone, kRGBAOnly, kAll };
HalfFPRenderTargetSupport halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kNone;
// for now we don't support floating point MSAA on ES
uint32_t fpRenderFlags = (GR_IS_GR_GL(standard)) ? msaaRenderFlags : nonMSAARenderFlags;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 0)) {
hasFP16Textures = true;
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0)) {
hasFP16Textures = true;
} else if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
ctxInfo.hasExtension("GL_OES_texture_float")) {
hasFP16Textures = true;
} else if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
ctxInfo.hasExtension("GL_OES_texture_half_float")) {
hasFP16Textures = true;
}
if (version >= GR_GL_VER(3, 2)) {
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
} else if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
} else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
// This extension only enables half float support rendering for RGBA.
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kRGBAOnly;
}
} else if (GR_IS_GR_WEBGL(standard)) {
if ((ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
ctxInfo.hasExtension("GL_OES_texture_float")) ||
(ctxInfo.hasExtension("OES_texture_float_linear") &&
ctxInfo.hasExtension("OES_texture_float"))) {
hasFP16Textures = true;
} else if ((ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
ctxInfo.hasExtension("GL_OES_texture_half_float")) ||
(ctxInfo.hasExtension("OES_texture_half_float_linear") &&
ctxInfo.hasExtension("OES_texture_half_float"))) {
hasFP16Textures = true;
}
if (ctxInfo.hasExtension("GL_WEBGL_color_buffer_float") ||
ctxInfo.hasExtension("WEBGL_color_buffer_float")) {
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
} else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") ||
ctxInfo.hasExtension("EXT_color_buffer_half_float")) {
// This extension only enables half float support rendering for RGBA.
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kRGBAOnly;
}
}
// For desktop:
// GL 3.0 requires support for R16 & RG16
// GL_ARB_texture_rg adds R16 & RG16 support for OpenGL 1.1 and above
// For ES:
// GL_EXT_texture_norm16 adds support for both texturing and rendering
// There is also the GL_NV_image_formats extension - for further investigation
bool r16AndRG1616Supported = false;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg")) {
r16AndRG1616Supported = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_EXT_texture_norm16")) {
r16AndRG1616Supported = true;
}
} // No WebGL support
///////////////////////////////////////////////////////////////////////////
GrGLenum halfFloatType = GR_GL_HALF_FLOAT;
if (GR_IS_GR_GL_ES(standard) && version < GR_GL_VER(3, 0)) {
halfFloatType = GR_GL_HALF_FLOAT_OES;
}
// RGBA8
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kRGBA8);
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA8 : GR_GL_RGBA;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
info.fFlags = FormatInfo::kTextureable_Flag;
if (GR_IS_GR_GL(standard)) {
info.fFlags |= msaaRenderFlags;
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
ctxInfo.hasExtension("GL_ARM_rgba8")) {
info.fFlags |= msaaRenderFlags;
}
} else if (GR_IS_GR_WEBGL(standard)) {
info.fFlags |= msaaRenderFlags;
}
if (texStorageSupported) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
// kRGBA_8888
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_8888, flags);
}
// kBGRA_8888
{
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kBGRA_8888, flags);
}
}
}
// kRGB_888x
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGB_888x, flags);
}
}
// R8
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kR8);
info.fBaseInternalFormat = GR_GL_RED;
info.fSizedInternalFormat = GR_GL_R8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_R8 : GR_GL_RED;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (textureRedSupport) {
info.fFlags |= FormatInfo::kTextureable_Flag | msaaRenderFlags;
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (textureRedSupport) {
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
// kAlpha_8
{
info.fColorTypeInfos.emplace_back(GrColorType::kAlpha_8, flags);
}
// kGray_8
{
info.fColorTypeInfos.emplace_back(GrColorType::kGray_8, flags);
}
}
}
// ALPHA8
{
bool alpha8IsValidForGL = GR_IS_GR_GL(standard) &&
(!fIsCoreProfile || version <= GR_GL_VER(3, 0));
bool alpha8IsValidForGLES = GR_IS_GR_GL_ES(standard) && version < GR_GL_VER(3, 0);
bool alpha8IsValidForWebGL = GR_IS_GR_WEBGL(standard);
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kALPHA8);
info.fBaseInternalFormat = GR_GL_ALPHA;
info.fSizedInternalFormat = GR_GL_ALPHA8;
if (GR_IS_GR_GL_ES(standard) || !texImageSupportsSizedInternalFormat) {
// ES does not have sized internal format GL_ALPHA8.
info.fInternalFormatForTexImage = GR_GL_ALPHA;
} else {
info.fInternalFormatForTexImage = GR_GL_ALPHA8;
}
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
info.fFlags = FormatInfo::kTextureable_Flag;
}
if (fAlpha8IsRenderable && alpha8IsValidForGL) {
info.fFlags |= msaaRenderFlags;
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2 &&
!formatWorkarounds.fDisableNonRedSingleChannelTexStorageForANGLEGL) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
// kAlpha_8
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
info.fColorTypeInfos.emplace_back(GrColorType::kAlpha_8, flags);
}
}
}
}
// LUMINANCE8
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kLUMINANCE8);
info.fBaseInternalFormat = GR_GL_LUMINANCE;
info.fSizedInternalFormat = GR_GL_LUMINANCE8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_LUMINANCE8 : GR_GL_LUMINANCE;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
bool supportsLum = (GR_IS_GR_GL(standard) && version <= GR_GL_VER(3, 0)) ||
(GR_IS_GR_GL_ES(standard) && version < GR_GL_VER(3, 0)) ||
(GR_IS_GR_WEBGL(standard));
if (supportsLum) {
info.fFlags = FormatInfo::kTextureable_Flag;
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2 &&
!formatWorkarounds.fDisableNonRedSingleChannelTexStorageForANGLEGL) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
// We are not enabling attaching to an FBO for LUMINANCE8 mostly because of confusion in the
// spec. For GLES it does not seem to ever support LUMINANCE8 being color-renderable. For GL
// versions less than 3.0 it is provided by GL_ARB_framebuffer_object. However, the original
// version of that extension did not add LUMINANCE8, but was added in a later revsion. So
// even the presence of that extension does not guarantee support. GL 3.0 and higher (core
// or compatibility) do not list LUMINANCE8 as color-renderable (which is strange since the
// GL_ARB_framebuffer_object extension was meant to bring 3.0 functionality to lower
// versions).
if (supportsLum) {
// kGray_8
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kGray_8, flags);
}
}
}
// BGRA8
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kBGRA8);
info.fBaseInternalFormat = GR_GL_BGRA;
info.fSizedInternalFormat = GR_GL_BGRA8;
// If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
// as a base format. Which base format depends on which extension is used.
if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
// GL_APPLE_texture_format_BGRA8888:
// ES 2.0: the extension makes BGRA an external format but not an internal format.
// ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format
// for glTexImage (just for glTexStorage).
info.fInternalFormatForTexImage = GR_GL_RGBA;
} else {
// GL_EXT_texture_format_BGRA8888:
// This extension adds GL_BGRA as an unsized internal format. However, it is
// written against ES 2.0 and therefore doesn't define a GL_BGRA8 as ES 2.0 doesn't
// have sized internal formats.
info.fInternalFormatForTexImage = GR_GL_BGRA;
}
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
// TexStorage requires using a sized internal format and BGRA8 is only supported if we have
// the GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texture_storage and
// GL_EXT_texture_format_BGRA8888.
bool supportsBGRATexStorage = false;
if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
info.fFlags = FormatInfo::kTextureable_Flag | nonMSAARenderFlags;
// GL_EXT_texture storage has defined interactions with
// GL_EXT_texture_format_BGRA8888.
if (ctxInfo.hasExtension("GL_EXT_texture_storage") &&
!formatWorkarounds.fDisableBGRATextureStorageForIntelWindowsES) {
supportsBGRATexStorage = true;
}
} else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
// This APPLE extension introduces complexity on ES2. It leaves the internal format
// as RGBA, but allows BGRA as the external format. From testing, it appears that
// the driver remembers the external format when the texture is created (with
// TexImage). If you then try to upload data in the other swizzle (with
// TexSubImage), it fails. We could work around this, but it adds even more state
// tracking to code that is already too tricky. Instead, we opt not to support BGRA
// on ES2 with this extension. This also side-steps some ambiguous interactions with
// the texture storage extension.
if (version >= GR_GL_VER(3,0)) {
// The APPLE extension doesn't explicitly make this renderable, but
// internally it appears to use RGBA8, which we'll patch up below.
info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags;
supportsBGRATexStorage = true;
}
}
}
if (texStorageSupported && supportsBGRATexStorage) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (SkToBool(info.fFlags &FormatInfo::kTextureable_Flag)) {
// kBGRA_8888
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kBGRA_8888, flags);
}
}
}
// RGB565
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kRGB565);
info.fBaseInternalFormat = GR_GL_RGB;
info.fSizedInternalFormat = GR_GL_RGB565;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGB565 : GR_GL_RGB;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
info.fFlags = FormatInfo::kTextureable_Flag;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
info.fFlags |= msaaRenderFlags;
}
} else if (GR_IS_GR_GL_ES(standard)) {
info.fFlags |= msaaRenderFlags;
} else if (GR_IS_GR_WEBGL(standard)) {
info.fFlags |= msaaRenderFlags;
}
// 565 is not a sized internal format on desktop GL. So on desktop with
// 565 we always use an unsized internal format to let the system pick
// the best sized format to convert the 565 data to. Since TexStorage
// only allows sized internal formats we disallow it.
//
// TODO: As of 4.2, regular GL supports 565. This logic is due for an
// update.
if (texStorageSupported && GR_IS_GR_GL_ES(standard)) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
// kBGR_565
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kBGR_565, flags);
}
}
// RGBA16F
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kRGBA16F);
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA16F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA16F : GR_GL_RGBA;
info.fDefaultExternalType = halfFloatType;
if (hasFP16Textures) {
info.fFlags = FormatInfo::kTextureable_Flag;
// ES requires 3.2 or EXT_color_buffer_half_float.
if (halfFPRenderTargetSupport != HalfFPRenderTargetSupport::kNone) {
info.fFlags |= fpRenderFlags;
}
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (hasFP16Textures) {
// kRGBA_F16
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_F16, flags);
}
// kRGBA_F16_Clamped
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_F16_Clamped, flags);
}
}
}
// R16F
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kR16F);
info.fBaseInternalFormat = GR_GL_RED;
info.fSizedInternalFormat = GR_GL_R16F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_R16F : GR_GL_RED;
info.fDefaultExternalType = halfFloatType;
if (textureRedSupport && hasFP16Textures) {
info.fFlags = FormatInfo::kTextureable_Flag;
if (halfFPRenderTargetSupport == HalfFPRenderTargetSupport::kAll) {
info.fFlags |= fpRenderFlags;
}
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (textureRedSupport && hasFP16Textures) {
// kAlpha_F16
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kAlpha_F16, flags);
}
}
}
// RGB8
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kRGB8);
info.fBaseInternalFormat = GR_GL_RGB;
info.fSizedInternalFormat = GR_GL_RGB8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGB8 : GR_GL_RGB;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
info.fFlags = FormatInfo::kTextureable_Flag;
if (GR_IS_GR_GL(standard)) {
// Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be
// a supported render buffer format. Since we usually use render buffers for MSAA on
// non-ES GL we don't support MSAA for GL_RGB8. On 4.2+ we could check using
// glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if
// this becomes an issue.
// This also would probably work in mixed-samples mode where there is no MSAA color
// buffer but we don't support that just for simplicity's sake.
info.fFlags |= nonMSAARenderFlags;
} else if (GR_IS_GR_GL_ES(standard)) {
// 3.0 and the extension support this as a render buffer format.
if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
info.fFlags |= msaaRenderFlags;
}
} else if (GR_IS_GR_WEBGL(standard)) {
// WebGL seems to support RBG8
info.fFlags |= msaaRenderFlags;
}
if (texStorageSupported) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (formatWorkarounds.fDisableRGB8ForMali400) {
info.fFlags = 0;
}
// kRGB_888x
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGB_888x, flags);
}
}
// RG8
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kRG8);
info.fBaseInternalFormat = GR_GL_RG;
info.fSizedInternalFormat = GR_GL_RG8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RG8 : GR_GL_RG;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (textureRedSupport) {
info.fFlags |= FormatInfo::kTextureable_Flag | msaaRenderFlags;
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
}
if (textureRedSupport) {
// kRG_88
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRG_88, flags);
}
}
}
// RGB10_A2
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kRGB10_A2);
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGB10_A2;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGB10_A2 : GR_GL_RGBA;
info.fDefaultExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
if (GR_IS_GR_GL(standard) ||
(GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3, 0))) {
info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags;
} else if (GR_IS_GR_GL_ES(standard) &&
ctxInfo.hasExtension("GL_EXT_texture_type_2_10_10_10_REV")) {
info.fFlags = FormatInfo::kTextureable_Flag;
} // No WebGL support
if (texStorageSupported) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (SkToBool(info.fFlags &FormatInfo::kTextureable_Flag)) {
// kRGBA_1010102
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_1010102, flags);
}
}
}
// RGBA4
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kRGBA4);
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA4;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA4 : GR_GL_RGBA;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
info.fFlags = FormatInfo::kTextureable_Flag;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(4, 2)) {
info.fFlags |= msaaRenderFlags;
}
} else if (GR_IS_GR_GL_ES(standard)) {
info.fFlags |= msaaRenderFlags;
} else if (GR_IS_GR_WEBGL(standard)) {
info.fFlags |= msaaRenderFlags;
}
if (texStorageSupported) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
// kABGR_4444
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kABGR_4444, flags);
}
}
// RGBA32F
{
// FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kRGBA32F);
// We don't allow texturing or rendering to this format
}
// SRGB8_ALPHA8
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kSRGB8_ALPHA8);
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_SRGB8_ALPHA8 : GR_GL_RGBA;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (fSRGBSupport) {
uint32_t srgbRenderFlags =
formatWorkarounds.fDisableSRGBRenderWithMSAAForMacAMD ? nonMSAARenderFlags
: msaaRenderFlags;
info.fFlags = FormatInfo::kTextureable_Flag | srgbRenderFlags;
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (fSRGBSupport) {
// kRGBA_8888_SRGB
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_8888_SRGB, flags);
}
}
}
// COMPRESSED_RGB8_ETC2
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kCOMPRESSED_RGB8_ETC2);
info.fBaseInternalFormat = GR_GL_RGB;
info.fCompressedInternalFormat = GR_GL_COMPRESSED_RGB8_ETC2;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
info.fFlags = FormatInfo::kTextureable_Flag;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture")) {
info.fFlags = FormatInfo::kTextureable_Flag;
}
} // No WebGL support
// There are no support GrColorTypes for this format
}
// COMPRESSED_ETC1_RGB8
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kCOMPRESSED_ETC1_RGB8);
info.fBaseInternalFormat = GR_GL_RGB;
info.fCompressedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture")) {
info.fFlags = FormatInfo::kTextureable_Flag;
}
} // No GL or WebGL support
// There are no support GrColorTypes for this format
}
// GR_GL_R16
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kR16);
info.fBaseInternalFormat = GR_GL_RED;
info.fSizedInternalFormat = GR_GL_R16;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_R16 : GR_GL_RED;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
if (r16AndRG1616Supported) {
info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags;
}
if (r16AndRG1616Supported) {
// kR_16
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kR_16, flags);
}
}
}
// GR_GL_RG16
{
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kRG16);
info.fBaseInternalFormat = GR_GL_RG;
info.fSizedInternalFormat = GR_GL_RG16;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RG16 : GR_GL_RG;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
if (r16AndRG1616Supported) {
info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags;
}
if (r16AndRG1616Supported) {
// kRG_1616
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRG_1616, flags);
}
}
}
// GR_GL_RGBA16
{
// For desktop:
// GL 3.0 requires both texture and render support for RGBA16
// For ES:
// GL_EXT_texture_norm16 adds support for both texturing and rendering
// There is also the GL_NV_image_formats extension - for further investigation
//
// This is basically the same as R16F and RG16F except the GL_ARB_texture_rg extension
// doesn't add this format
bool rgba16161616Supported = false;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 0)) {
rgba16161616Supported = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_EXT_texture_norm16")) {
rgba16161616Supported = true;
}
} // No WebGL support
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kRGBA16);
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA16;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA16 : GR_GL_RGBA;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
if (rgba16161616Supported) {
info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags;
}
if (rgba16161616Supported) {
// kRGBA_16161616
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_16161616, flags);
}
}
}
// GR_GL_RG16F
{
bool rg16fTexturesSupported = false;
bool rg16fRenderingSupported = false;
// For desktop:
// 3.0 requires both texture and render support
// GL_ARB_texture_rg adds both texture and render support
// For ES:
// 3.2 requires RG16F as both renderable and texturable
// 3.0 only requires RG16F as texture-only
// GL_EXT_color_buffer_float adds texture and render support
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg")) {
rg16fTexturesSupported = true;
rg16fRenderingSupported = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
rg16fTexturesSupported = true;
rg16fRenderingSupported = true;
} else if (version >= GR_GL_VER(3, 0)) {
rg16fTexturesSupported = true; // texture only
}
}
FormatInfo& info = this->getFormatInfo(GrGLSizedInternalFormat::kRG16F);
info.fBaseInternalFormat = GR_GL_RG;
info.fSizedInternalFormat = GR_GL_RG16F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RG16F : GR_GL_RG;
info.fDefaultExternalType = halfFloatType;
if (rg16fTexturesSupported) {
info.fFlags |= FormatInfo::kTextureable_Flag;
}
if (rg16fRenderingSupported) {
info.fFlags |= fpRenderFlags;
}
SkASSERT(rg16fTexturesSupported || !rg16fRenderingSupported);
if (rg16fTexturesSupported) {
// kRG_F16
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRG_F16, flags);
}
}
}
}
void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
/*
Comments on renderability of configs on various GL versions.
OpenGL < 3.0:
no built in support for render targets.
GL_EXT_framebuffer_object adds possible support for any sized format with base internal
format RGB, RGBA and NV float formats we don't use.
This is the following:
R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
RGB10_A2, RGBA12,RGBA16
Though, it is hard to believe the more obscure formats such as RGBA12 would work
since they aren't required by later standards and the driver can simply return
FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
any sized internal format with a base internal format of ALPHA, LUMINANCE,
LUMINANCE_ALPHA, INTENSITY, RED, and RG.
This adds a lot of additional renderable sized formats, including ALPHA8.
The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
16F, 32I, 32UI, and 32F variants).
Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
For both the above extensions we limit ourselves to those that are also required by
OpenGL 3.0.
OpenGL 3.0:
Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
but are not required to be supported as renderable textures/renderbuffer.
Required renderable color formats:
- RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
RGB10_A2.
- R11F_G11F_B10F.
- RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
and RG8UI.
- R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
- ALPHA8
OpenGL 3.1, 3.2, 3.3
Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
OpengGL 3.3, 4.0, 4.1
Adds RGB10_A2UI.
OpengGL 4.2
Adds
- RGB5_A1, RGBA4
- RGB565
OpenGL 4.4
Does away with the separate list and adds a column to the sized internal color format
table. However, no new formats become required color renderable.
ES 2.0
color renderable: RGBA4, RGB5_A1, RGB565
GL_EXT_texture_rg adds support for R8, RG8 as a color render target
GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
ES 3.0
- RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
RGB5_A1.
- RGB8 and RGB565.
- RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
- R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
ES 3.1
Adds RGB10_A2, RGB10_A2UI,
ES 3.2
Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
*/
GrGLStandard standard = ctxInfo.standard();
// standard can be unused (optimzed away) if SK_ASSUME_GL_ES is set
sk_ignore_unused_variable(standard);
GrGLVersion version = ctxInfo.version();
// Correctness workarounds.
bool disableTextureRedForMesa = false;
bool disableSRGBRenderWithMSAAForMacAMD = false;
bool disableRGB8ForMali400 = false;
if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
// ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
// and GL_RG on FBO textures.
disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
// MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
#if defined(SK_BUILD_FOR_MAC)
disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
#endif
// Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
}
uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag;
uint32_t allRenderFlags = nonMSAARenderFlags;
if (kNone_MSFBOType != fMSFBOType) {
allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
}
bool textureRedSupport = false;
if (!disableTextureRedForMesa) {
if (GR_IS_GR_GL(standard)) {
textureRedSupport =
version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
} else if (GR_IS_GR_GL_ES(standard)) {
textureRedSupport =
version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
}
} // No WebGL support
fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RGBA;
fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
if (GR_IS_GR_GL(standard)) {
// We require some form of FBO support and all GLs with FBO support can render to RGBA8
fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
ctxInfo.hasExtension("GL_ARM_rgba8")) {
fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
}
} else if (GR_IS_GR_WEBGL(standard)) {
// WebGL seems to support RBGA8
fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
}
fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
// Our external RGB data always has a byte where alpha would be. When calling read pixels we
// want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
// read back unaligned 24bit RGB color values.
fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
if (GR_IS_GR_GL(standard)) {
// Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
// supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
// we don't support MSAA for GL_RGB8. On 4.2+ we could check using
// glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
// becomes an issue.
// This also would probably work in mixed-samples mode where there is no MSAA color buffer
// but we don't support that just for simplicity's sake.
fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
} else if (GR_IS_GR_GL_ES(standard)) {
// 3.0 and the extension support this as a render buffer format.
if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
}
} else if (GR_IS_GR_WEBGL(standard)) {
// WebGL seems to support RBG8
fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
}
if (disableRGB8ForMali400) {
fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
}
fConfigTable[kRGB_888X_GrPixelConfig] = fConfigTable[kRGBA_8888_GrPixelConfig];
// Currently we don't allow RGB_888X to be renderable because we don't have a way to handle
// blends that reference the dst alpha when the values in the dst alpha channel are
// uninitialized.
fConfigTable[kRGB_888X_GrPixelConfig].fFlags = 0;
fConfigTable[kRG_88_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RG;
fConfigTable[kRG_88_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RG8;
fConfigTable[kRG_88_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RG;
fConfigTable[kRG_88_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
fConfigTable[kRG_88_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
if (textureRedSupport) {
fConfigTable[kRG_88_GrPixelConfig].fFlags = allRenderFlags;
} else {
fConfigTable[kRG_88_GrPixelConfig].fFlags = 0;
}
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_BGRA;
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
if (GR_IS_GR_GL(standard)) {
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
// Since the internal format is RGBA8, it is also renderable.
fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = allRenderFlags;
}
} else if (GR_IS_GR_GL_ES(standard)) {
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = nonMSAARenderFlags;
if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
this->usesMSAARenderBuffers()) {
fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
ConfigInfo::kRenderableWithMSAA_Flag;
}
} else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
// This APPLE extension introduces complexity on ES2. It leaves the internal format
// as RGBA, but allows BGRA as the external format. From testing, it appears that the
// driver remembers the external format when the texture is created (with TexImage).
// If you then try to upload data in the other swizzle (with TexSubImage), it fails.
// We could work around this, but it adds even more state tracking to code that is
// already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
// This also side-steps some ambiguous interactions with the texture storage extension.
if (version >= GR_GL_VER(3,0)) {
// The APPLE extension doesn't explicitly make this renderable, but
// internally it appears to use RGBA8, which we'll patch up below.
fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = allRenderFlags;
}
}
} else if (GR_IS_GR_WEBGL(standard)) {
// Guess based on ES 2.0 support
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
}
uint32_t srgbRenderFlags = allRenderFlags;
if (disableSRGBRenderWithMSAAForMacAMD) {
srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
}
fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
// GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
// external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RGBA;
fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
if (fSRGBSupport) {
fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = srgbRenderFlags;
}
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
if (this->ES2CompatibilitySupport()) {
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
} else {
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
}
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RGB;
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
}
} else if (GR_IS_GR_GL_ES(standard)) {
fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
} else if (GR_IS_GR_WEBGL(standard)) {
fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
}
fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RGBA;
fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(4, 2)) {
fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
}
} else if (GR_IS_GR_GL_ES(standard)) {
fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
} else if (GR_IS_GR_WEBGL(standard)) {
fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
}
fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RGBA;
fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
GR_GL_UNSIGNED_INT_2_10_10_10_REV;
fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
if (GR_IS_GR_GL(standard) ||
(GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3, 0))) {
fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = allRenderFlags;
} // No WebGL support
bool alpha8IsValidForGL = GR_IS_GR_GL(standard) &&
(!fIsCoreProfile || version <= GR_GL_VER(3, 0));
ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
alphaInfo.fRGBAReadSwizzle = GrSwizzle("000a");
if (fAlpha8IsRenderable && alpha8IsValidForGL) {
alphaInfo.fFlags |= allRenderFlags;
}
ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
redInfo.fRGBAReadSwizzle = GrSwizzle("000r");
if (textureRedSupport) <