| /* |
| * 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; |
| 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; |
| #if defined(COBALT) |
| // On some GL implementations, this feature might not be implemented. |
| // In the interest of greater compatibility, this feature is disabled. |
| fDrawArraysBaseVertexIsBroken = true; |
| #else |
| fDrawArraysBaseVertexIsBroken = false; |
| #endif |
| fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false; |
| fUseDrawInsteadOfAllRenderTargetWrites = false; |
| fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false; |
| fDetachStencilFromMSAABuffersBeforeReadPixels = false; |
| fDontSetBaseOrMaxLevelForExternalTextures = false; |
| fNeverDisableColorWrites = false; |
| fProgramBinarySupport = false; |
| fProgramParameterSupport = false; |
| fSamplerObjectSupport = false; |
| fTiledRenderingSupport = false; |
| fFBFetchRequiresEnablePerSample = false; |
| fSRGBWriteControl = 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 |
| |
| bool textureRedSupport = false; |
| if (kGL_GrGLStandard == standard) { |
| textureRedSupport = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg"); |
| } else { |
| textureRedSupport = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg"); |
| } |
| |
| if (textureRedSupport) { |
| // Some devices claim to support GL_RED, but actually do not, so we |
| // verify support by actually attempting to create a GL_RED texture. |
| // As an example, one device was found to claim GLES 3.0 support, but |
| // could not create GL_RED textures. |
| GrGLenum error; |
| GrGLuint texture_id; |
| GR_GL_CALL(gli, GenTextures(1, &texture_id)); |
| GR_GL_CALL(gli, BindTexture(GR_GL_TEXTURE_2D, texture_id)); |
| GR_GL_CALL_NOERRCHECK(gli, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RED, 64, 64, 0, GR_GL_RED, |
| GR_GL_UNSIGNED_BYTE, 0)); |
| GR_GL_CALL_RET(gli, error, GetError()); |
| if (error != GR_GL_NO_ERROR) { |
| // There was an error creating the texture, do not advertise GL_RED |
| // support. |
| textureRedSupport = false; |
| } |
| GR_GL_CALL(gli, BindTexture(GR_GL_TEXTURE_2D, 0)); |
| GR_GL_CALL(gli, DeleteTextures(1, &texture_id)); |
| } |
| |
| 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)) { |
| if (kChromium_GrGLDriver == ctxInfo.driver()) { |
| fRectangleTextureSupport = ctxInfo.hasExtension("GL_ARB_texture_rectangle"); |
| } else { |
| // 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 |
| |
| if (GR_IS_GR_GL(standard)) { |
| fSRGBWriteControl = version >= GR_GL_VER(3, 0) || |
| ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") || |
| ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB"); |
| } else if (GR_IS_GR_GL_ES(standard)) { |
| // ES through 3.2 requires EXT_srgb_write_control to support toggling |
| // sRGB writing for destinations. |
| fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control"); |
| } // No WebGL support |
| |
| /************************************************************************** |
| * 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); |
| |
| #if defined(COBALT) |
| if (ctxInfo.renderer() == kGalliumLLVM_GrGLRenderer) { |
| // The Gallium renderer claims to support a max texture size of 8K. |
| // However, attempting to create 4k x 2k texture fails under this |
| // implementation. Creating a 2k x 2k texture succeeds, so the new limit |
| // is set to 2048. |
| const int kRealMaxTextureSize = 2048; |
| fMaxTextureSize = SkTMin(kRealMaxTextureSize, fMaxTextureSize); |
| fMaxRenderTargetSize = SkTMin(kRealMaxTextureSize, fMaxRenderTargetSize); |
| } |
| #endif |
| |
| // 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 defined(COBALT) |
| // A crash issue was found on the Nexus Player within the PowerVR GLES |
| // driver when uploading new data to reuse scratch textures, so disable |
| // scratch texture reuse on that device. |
| if (kImagination_GrGLVendor == ctxInfo.vendor() && |
| kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) { |
| fReuseScratchTextures = false; |
| } |
| #endif |
| |
| #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); |
| } |
| |
| if (GR_IS_GR_GL_ES(standard)) { |
| fTiledRenderingSupport = ctxInfo.hasExtension("GL_QCOM_tiled_rendering"); |
| } |
| |
| FormatWorkarounds formatWorkarounds; |
| |
| if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { |
| this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps, |
| &formatWorkarounds); |
| } |
| |
| // Requires fTextureSwizzleSupport, msaa support, ES compatibility have |
| // already been detected. |
| this->initFormatTable(ctxInfo, gli, formatWorkarounds); |
| |
| 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; |
| } |
| |
| 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; |
| } 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())) { |
| // 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; |
| fMSAAResolvesAutomatically = true; |
| } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { |
| fMSFBOType = kES_IMG_MsToTexture_MSFBOType; |
| fMSAAResolvesAutomatically = true; |
| } 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 1, but there is for 2.0 |
| if (ctxInfo.version() >= GR_GL_VER(2,0)) { |
| fMSFBOType = kStandard_MSFBOType; |
| } else { |
| fMSFBOType = kNone_MSFBOType; |
| } |
| } |
| |
| // We disable MSAA for all Intel GPUs. Before Gen9, performance was very bad. Even with Gen9, |
| // we've seen driver crashes in the wild. We don't have data on Gen11 yet. |
| // chromium:527565, chromium:983926 |
| if (kIntel_GrGLVendor == ctxInfo.vendor()) { |
| 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("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("Clear texture support", fClearTextureSupport); |
| writer->appendBool("Program binary support", fProgramBinarySupport); |
| writer->appendBool("Program parameters support", fProgramParameterSupport); |
| writer->appendBool("Sampler object support", fSamplerObjectSupport); |
| writer->appendBool("Tiled rendering support", fTiledRenderingSupport); |
| writer->appendBool("FB fetch requires enable per sample", fFBFetchRequiresEnablePerSample); |
| writer->appendBool("sRGB Write Control", fSRGBWriteControl); |
| |
| 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("formats"); |
| |
| for (int i = 0; i < kGrGLFormatCount; ++i) { |
| writer->beginObject(nullptr, false); |
| writer->appendHexU32("flags", fFormatTable[i].fFlags); |
| writer->appendHexU32("f_type", (uint32_t)fFormatTable[i].fFormatType); |
| writer->appendHexU32("c_internal", fFormatTable[i].fCompressedInternalFormat); |
| writer->appendHexU32("i_for_teximage", fFormatTable[i].fInternalFormatForTexImageOrStorage); |
| writer->appendHexU32("i_for_renderbuffer", fFormatTable[i].fInternalFormatForRenderbuffer); |
| writer->appendHexU32("default_ex_format", fFormatTable[i].fDefaultExternalFormat); |
| writer->appendHexU32("default_ex_type", fFormatTable[i].fDefaultExternalType); |
| writer->appendHexU64("bpp", fFormatTable[i].fBytesPerPixel); |
| |
| writer->beginArray("surface color types"); |
| for (int j = 0; j < fFormatTable[i].fColorTypeInfoCount; ++j) { |
| const auto& ctInfo = fFormatTable[i].fColorTypeInfos[j]; |
| writer->beginObject(nullptr, false); |
| writer->appendHexU32("colorType", (uint32_t)ctInfo.fColorType); |
| writer->appendHexU32("flags", ctInfo.fFlags); |
| |
| writer->beginArray("data color types"); |
| for (int k = 0; k < ctInfo.fExternalIOFormatCount; ++k) { |
| const auto& ioInfo = ctInfo.fExternalIOFormats[k]; |
| writer->beginObject(nullptr, false); |
| writer->appendHexU32("colorType", (uint32_t)ioInfo.fColorType); |
| writer->appendHexU32("ex_type", ioInfo.fExternalType); |
| writer->appendHexU32("ex_teximage", ioInfo.fExternalTexImageFormat); |
| writer->appendHexU32("ex_read", ioInfo.fExternalReadFormat); |
| writer->endObject(); |
| } |
| writer->endArray(); |
| writer->endObject(); |
| } |
| writer->endArray(); |
| writer->endObject(); |
| } |
| |
| writer->endArray(); |
| writer->endObject(); |
| } |
| #else |
| void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const { } |
| #endif |
| |
| void GrGLCaps::getTexImageExternalFormatAndType(GrGLFormat surfaceFormat, GrGLenum* externalFormat, |
| GrGLenum* externalType) const { |
| const auto& info = this->getFormatInfo(surfaceFormat); |
| *externalType = info.fDefaultExternalType; |
| *externalFormat = info.fDefaultExternalFormat; |
| } |
| |
| void GrGLCaps::getTexSubImageZeroFormatTypeAndBpp(GrGLFormat format, GrGLenum* externalFormat, |
| GrGLenum* externalType, size_t* bpp) const { |
| const auto& info = this->getFormatInfo(format); |
| *externalType = info.fDefaultExternalType; |
| *externalFormat = info.fDefaultExternalFormat; |
| *bpp = info.fBytesPerPixel; |
| } |
| |
| void GrGLCaps::getTexSubImageExternalFormatAndType(GrGLFormat surfaceFormat, |
| GrColorType surfaceColorType, |
| GrColorType memoryColorType, |
| GrGLenum* externalFormat, |
| GrGLenum* externalType) const { |
| this->getExternalFormat(surfaceFormat, surfaceColorType, memoryColorType, |
| kTexImage_ExternalFormatUsage, externalFormat, externalType); |
| } |
| |
| void GrGLCaps::getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, |
| GrColorType memoryColorType, GrGLenum* externalFormat, |
| GrGLenum* externalType) const { |
| this->getExternalFormat(surfaceFormat, surfaceColorType, memoryColorType, |
| kReadPixels_ExternalFormatUsage, externalFormat, externalType); |
| } |
| |
| void GrGLCaps::getExternalFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, |
| GrColorType memoryColorType, ExternalFormatUsage usage, |
| GrGLenum* externalFormat, GrGLenum* externalType) const { |
| SkASSERT(externalFormat && externalType); |
| *externalFormat = this->getFormatInfo(surfaceFormat).externalFormat( |
| surfaceColorType, memoryColorType, usage); |
| *externalType = this->getFormatInfo(surfaceFormat).externalType( |
| surfaceColorType, memoryColorType); |
| } |
| |
| void GrGLCaps::setStencilFormatIndexForFormat(GrGLFormat format, int index) { |
| SkASSERT(!this->hasStencilFormatBeenDeterminedForFormat(format)); |
| this->getFormatInfo(format).fStencilFormatIndex = |
| index < 0 ? FormatInfo::kUnsupported_StencilFormatIndex : index; |
| } |
| |
| void GrGLCaps::setColorTypeFormat(GrColorType colorType, GrGLFormat format) { |
| int idx = static_cast<int>(colorType); |
| SkASSERT(fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown); |
| fColorTypeToFormatTable[idx] = format; |
| } |
| |
| void GrGLCaps::initFormatTable(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; |
| } |
| |
| // 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))); |
| |
| // for now we don't support floating point MSAA on ES |
| uint32_t fpRenderFlags = (GR_IS_GR_GL(standard)) ? msaaRenderFlags : nonMSAARenderFlags; |
| |
| for (int i = 0; i < kGrColorTypeCnt; ++i) { |
| fColorTypeToFormatTable[i] = GrGLFormat::kUnknown; |
| } |
| |
| /////////////////////////////////////////////////////////////////////////// |
| |
| GrGLenum halfFloatType = GR_GL_HALF_FLOAT; |
| if ((GR_IS_GR_GL_ES(standard) && version < GR_GL_VER(3, 0)) || |
| (GR_IS_GR_WEBGL(standard) && version < GR_GL_VER(2, 0))) { |
| halfFloatType = GR_GL_HALF_FLOAT_OES; |
| } |
| |
| // Format: RGBA8 |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA8); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| info.fInternalFormatForRenderbuffer = GR_GL_RGBA8; |
| info.fDefaultExternalFormat = GR_GL_RGBA; |
| info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; |
| info.fBytesPerPixel = 4; |
| info.fFlags = FormatInfo::kTexturable_Flag; |
| if (GR_IS_GR_GL(standard)) { |
| info.fFlags |= msaaRenderFlags; |
| } else if (GR_IS_GR_GL_ES(standard)) { |
| #if defined(STARBOARD) |
| // Starboard code in GrGLUtil.cpp may override the driver version |
| // from GLES 3.0 to 2.0 if the config specifies that only GLES 2.0 |
| // features should be used. This will confuse the regular |
| // capabilities check. Since all Starboard GLES platforms must |
| // support rendering to RGBA8 buffers, no check is needed here. |
| info.fFlags |= msaaRenderFlags; |
| #else |
| if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || |
| ctxInfo.hasExtension("GL_ARM_rgba8")) { |
| info.fFlags |= msaaRenderFlags; |
| } |
| #endif |
| } else if (GR_IS_GR_WEBGL(standard)) { |
| info.fFlags |= msaaRenderFlags; |
| } |
| |
| if (texStorageSupported) { |
| info.fFlags |= FormatInfo::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_RGBA8; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = |
| texImageSupportsSizedInternalFormat ? GR_GL_RGBA8 : GR_GL_RGBA; |
| } |
| |
| bool supportsBGRAColorType = GR_IS_GR_GL(standard) && |
| (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")); |
| info.fColorTypeInfoCount = supportsBGRAColorType ? 3 : 2; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: RGBA8, Surface: kRGBA_8888 |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kRGBA_8888; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| this->setColorTypeFormat(GrColorType::kRGBA_8888, GrGLFormat::kRGBA8); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 1; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: RGBA8, Surface: kRGBA_8888, Data: kRGBA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = GR_GL_RGBA; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| |
| // Format: RGBA8, Surface: kBGRA_8888 |
| if (supportsBGRAColorType) { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kBGRA_8888; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| this->setColorTypeFormat(GrColorType::kBGRA_8888, GrGLFormat::kRGBA8); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: RGBA8, Surface: kBGRA_8888, Data: kBGRA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kBGRA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = GR_GL_BGRA; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: RGBA8, Surface: kBGRA_8888, Data: kRGBA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| |
| // Format: RGBA8, Surface: kRGB_888x |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kRGB_888x; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| ctInfo.fTextureSwizzle = GrSwizzle::RGB1(); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 1; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: RGBA8, Surface: kRGB_888x, Data: kRGBA_888x |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGB_888x; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = GR_GL_RGBA; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| |
| // Format: R8 |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kR8); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| info.fInternalFormatForRenderbuffer = GR_GL_R8; |
| info.fDefaultExternalFormat = GR_GL_RED; |
| info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; |
| info.fBytesPerPixel = 1; |
| bool r8Support = false; |
| if (GR_IS_GR_GL(standard)) { |
| r8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg"); |
| } else if (GR_IS_GR_GL_ES(standard)) { |
| r8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg"); |
| } else if (GR_IS_GR_WEBGL(standard)) { |
| r8Support = ctxInfo.version() >= GR_GL_VER(2, 0); |
| } |
| // TODO: Disable R8 texture support to force similar rendering paths. |
| // R8 support currently breaks text rendering. |
| #if defined(COBALT) |
| r8Support = false; |
| #endif |
| |
| if (r8Support) { |
| info.fFlags |= FormatInfo::kTexturable_Flag | msaaRenderFlags; |
| } |
| |
| if (texStorageSupported) { |
| info.fFlags |= FormatInfo::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_R8; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = |
| texImageSupportsSizedInternalFormat ? GR_GL_R8 : GR_GL_RED; |
| } |
| |
| if (r8Support) { |
| info.fColorTypeInfoCount = 2; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: R8, Surface: kAlpha_8 |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kAlpha_8; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| ctInfo.fTextureSwizzle = GrSwizzle::RRRR(); |
| ctInfo.fOutputSwizzle = GrSwizzle::AAAA(); |
| this->setColorTypeFormat(GrColorType::kAlpha_8, GrGLFormat::kR8); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: R8, Surface: kAlpha_8, Data: kAlpha_8 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kAlpha_8; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = GR_GL_RED; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: R8, Surface: kAlpha_8, Data: kAlpha_8xxx |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kAlpha_8xxx; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| |
| // Format: R8, Surface: kGray_8 |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kGray_8; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| ctInfo.fTextureSwizzle = GrSwizzle("rrr1"); |
| this->setColorTypeFormat(GrColorType::kGray_8, GrGLFormat::kR8); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: R8, Surface: kGray_8, Data: kGray_8 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kGray_8; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = GR_GL_RED; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: R8, Surface: kGray_8, Data: kGray_8xxx |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kGray_8xxx; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| } |
| |
| // Format: ALPHA8 |
| { |
| bool alpha8IsValidForGL = GR_IS_GR_GL(standard) && |
| (!fIsCoreProfile || version <= GR_GL_VER(3, 0)); |
| bool alpha8IsValidForGLES = GR_IS_GR_GL_ES(standard); |
| bool alpha8IsValidForWebGL = GR_IS_GR_WEBGL(standard); |
| |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kALPHA8); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| // GL_EXT_texture_storage adds GL_ALPHA8 for texture storage. However, ES3 has glTexStorage |
| // but does not have GL_ALPHA8 (and requires a sized internal format for glTexStorage). |
| // WebGL never has GL_ALPHA8. |
| bool alpha8SizedEnumSupported = |
| alpha8IsValidForGL || |
| (alpha8IsValidForGLES && ctxInfo.hasExtension("GL_EXT_texture_storage")); |
| bool alpha8TexStorageSupported = alpha8SizedEnumSupported && texStorageSupported; |
| |
| bool alpha8IsRenderable = false; |
| if (alpha8IsValidForGL) { |
| // Core profile removes ALPHA8 support. |
| // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable. |
| alpha8IsRenderable = ctxInfo.version() >= GR_GL_VER(3, 0) || |
| ctxInfo.hasExtension("GL_ARB_framebuffer_object"); |
| } |
| info.fInternalFormatForRenderbuffer = GR_GL_ALPHA8; |
| info.fDefaultExternalFormat = GR_GL_ALPHA; |
| info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; |
| info.fBytesPerPixel = 1; |
| if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) { |
| info.fFlags = FormatInfo::kTexturable_Flag; |
| } |
| if (alpha8IsRenderable && alpha8IsValidForGL) { |
| // We will use ALPHA8 to create MSAA renderbuffers. |
| SkASSERT(alpha8SizedEnumSupported); |
| info.fFlags |= msaaRenderFlags; |
| } |
| if (alpha8TexStorageSupported) { |
| info.fFlags |= FormatInfo::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_ALPHA8; |
| } else { |
| // Even if GL_ALPHA8 is added to ES by GL_EXT_texture_storage it doesn't become legal |
| // for glTexImage2D. |
| if (!GR_IS_GR_GL_ES(standard) && texImageSupportsSizedInternalFormat && |
| alpha8SizedEnumSupported) { |
| info.fInternalFormatForTexImageOrStorage = GR_GL_ALPHA8; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = GR_GL_ALPHA; |
| } |
| } |
| |
| if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) { |
| info.fColorTypeInfoCount = 1; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: ALPHA8, Surface: kAlpha_8 |
| { |
| if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kAlpha_8; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | |
| ColorTypeInfo::kRenderable_Flag; |
| ctInfo.fTextureSwizzle = GrSwizzle::AAAA(); |
| int idx = static_cast<int>(GrColorType::kAlpha_8); |
| if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) { |
| this->setColorTypeFormat(GrColorType::kAlpha_8, GrGLFormat::kALPHA8); |
| } |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: ALPHA8, Surface: kAlpha_8, Data: kAlpha_8 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kAlpha_8; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = GR_GL_ALPHA; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: ALPHA8, Surface: kAlpha_8, Data: kRGBA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| } |
| } |
| |
| // Format: LUMINANCE8 |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kLUMINANCE8); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| info.fInternalFormatForRenderbuffer = GR_GL_LUMINANCE8; |
| info.fDefaultExternalFormat = GR_GL_LUMINANCE; |
| info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; |
| info.fBytesPerPixel = 1; |
| bool lum8Supported = false; |
| bool lum8SizedFormatSupported = false; |
| if (GR_IS_GR_GL(standard) && !fIsCoreProfile) { |
| lum8Supported = true; |
| lum8SizedFormatSupported = true; |
| } else if (GR_IS_GR_GL_ES(standard)) { |
| lum8Supported = true; |
| // Even on ES3 this extension is required to define LUMINANCE8. |
| lum8SizedFormatSupported = ctxInfo.hasExtension("GL_EXT_texture_storage"); |
| } else if (GR_IS_GR_WEBGL(standard)) { |
| lum8Supported = true; |
| } |
| if (lum8Supported) { |
| info.fFlags = FormatInfo::kTexturable_Flag; |
| } |
| if (texStorageSupported && lum8SizedFormatSupported) { |
| info.fFlags |= FormatInfo::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE8; |
| } else if (texImageSupportsSizedInternalFormat && lum8SizedFormatSupported) { |
| info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE8; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE; |
| } |
| // 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 (lum8Supported) { |
| info.fColorTypeInfoCount = 1; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: LUMINANCE8, Surface: kGray_8 |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kGray_8; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| int idx = static_cast<int>(GrColorType::kGray_8); |
| if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) { |
| this->setColorTypeFormat(GrColorType::kGray_8, GrGLFormat::kLUMINANCE8); |
| } |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: LUMINANCE8, Surface: kGray_8, Data: kGray_8 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kGray_8; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = GR_GL_LUMINANCE; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: LUMINANCE8, Surface: kGray_8, Data: kRGBA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| } |
| |
| // Format: BGRA8 |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kBGRA8); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| |
| // We currently only use the renderbuffer format when allocating msaa renderbuffers, so we |
| // are making decisions here based on that use case. The GL_EXT_texture_format_BGRA8888 |
| // extension adds BGRA color renderbuffer support for ES 2.0, but this does not guarantee |
| // support for MSAA renderbuffers. Additionally, the renderable support was added in a later |
| // revision of the extension. So it is possible for older drivers to support the extension |
| // but only an early revision of it without renderable support. We have no way of |
| // distinguishing between the two. The GL_APPLE_texture_format_BGRA8888 does not add support |
| // for BGRA color renderbuffers at all. Ideally, for both cases we would use RGBA8 for our |
| // format for the MSAA buffer. In the GL_EXT_texture_format_BGRA8888 case we can still |
| // make the resolve BGRA and which will work for glBlitFramebuffer for resolving which just |
| // requires the src and dst be bindable to FBOs. However, we can't do this in the current |
| // world since some devices (e.g. chromium & angle) require the formats in glBlitFramebuffer |
| // to match. We don't have a way to really check this during resolve since we only actually |
| // have one GrPixelConfig and one GrBackendFormat that is shared by the GrGLRenderTarget. |
| // Once we break those up into different surface we can revisit doing this change. |
| if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) { |
| info.fInternalFormatForRenderbuffer = GR_GL_RGBA8; |
| } else { |
| info.fInternalFormatForRenderbuffer = GR_GL_BGRA8; |
| } |
| |
| info.fDefaultExternalFormat = GR_GL_BGRA; |
| info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; |
| info.fBytesPerPixel = 4; |
| |
| GrGLenum bgraTexImageFormat; |
| // 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). |
| bgraTexImageFormat = 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. See later where we check for tex storage BGRA8 |
| // support. |
| bgraTexImageFormat = GR_GL_BGRA; |
| } |
| |
| // 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::kTexturable_Flag | nonMSAARenderFlags; |
| // GL_EXT_texture storage has defined interactions with |
| // GL_EXT_texture_format_BGRA8888. However, ES3 supports glTexStorage but |
| // without GL_EXT_texture_storage it does not allow the BGRA8 sized internal format. |
| 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::kTexturable_Flag | msaaRenderFlags; |
| supportsBGRATexStorage = true; |
| } |
| } |
| } |
| if (texStorageSupported && supportsBGRATexStorage) { |
| info.fFlags |= FormatInfo::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_BGRA8; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = bgraTexImageFormat; |
| } |
| |
| if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) { |
| info.fColorTypeInfoCount = 1; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: BGRA8, Surface: kBGRA_8888 |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kBGRA_8888; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| this->setColorTypeFormat(GrColorType::kBGRA_8888, GrGLFormat::kBGRA8); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: BGRA8, Surface: kBGRA_8888, Data: kBGRA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kBGRA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = GR_GL_BGRA; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: BGRA8, Surface: kBGRA_8888, Data: kRGBA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| } |
| |
| // Format: RGB565 |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB565); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| info.fInternalFormatForRenderbuffer = GR_GL_RGB565; |
| info.fDefaultExternalFormat = GR_GL_RGB; |
| info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_5_6_5; |
| info.fBytesPerPixel = 2; |
| if (GR_IS_GR_GL(standard)) { |
| if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) { |
| info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags; |
| } |
| } else if (GR_IS_GR_GL_ES(standard)) { |
| info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags; |
| } else if (GR_IS_GR_WEBGL(standard)) { |
| info.fFlags = FormatInfo::kTexturable_Flag | 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::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_RGB565; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = |
| texImageSupportsSizedInternalFormat ? GR_GL_RGB565 : GR_GL_RGB; |
| } |
| |
| if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) { |
| info.fColorTypeInfoCount = 1; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: RGB565, Surface: kBGR_565 |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kBGR_565; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| this->setColorTypeFormat(GrColorType::kBGR_565, GrGLFormat::kRGB565); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: RGB565, Surface: kBGR_565, Data: kBGR_565 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kBGR_565; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5; |
| ioFormat.fExternalTexImageFormat = GR_GL_RGB; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: RGB565, Surface: kBGR_565, Data: kRGBA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| } |
| |
| // Format: RGBA16F |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA16F); |
| info.fFormatType = FormatType::kFloat; |
| info.fInternalFormatForRenderbuffer = GR_GL_RGBA16F; |
| info.fDefaultExternalFormat = GR_GL_RGBA; |
| info.fDefaultExternalType = halfFloatType; |
| info.fBytesPerPixel = 8; |
| bool rgba16FTextureSupport = false; |
| bool rgba16FRenderTargetSupport = false; |
| |
| if (GR_IS_GR_GL(standard)) { |
| if (version >= GR_GL_VER(3, 0)) { |
| rgba16FTextureSupport = true; |
| rgba16FRenderTargetSupport = true; |
| } else if (ctxInfo.hasExtension("GL_ARB_texture_float")) { |
| rgba16FTextureSupport = true; |
| } |
| } else if (GR_IS_GR_GL_ES(standard)) { |
| if (version >= GR_GL_VER(3, 0)) { |
| rgba16FTextureSupport = true; |
| rgba16FRenderTargetSupport = |
| version >= GR_GL_VER(3, 2) || |
| ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") || |
| ctxInfo.hasExtension("GL_EXT_color_buffer_float"); |
| } else if (ctxInfo.hasExtension("GL_OES_texture_half_float") && |
| ctxInfo.hasExtension("GL_OES_texture_half_float_linear")) { |
| rgba16FTextureSupport = true; |
| rgba16FRenderTargetSupport = ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"); |
| } |
| } else if (GR_IS_GR_WEBGL(standard)) { |
| if (version >= GR_GL_VER(2, 0)) { |
| rgba16FTextureSupport = true; |
| rgba16FRenderTargetSupport = |
| ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") || |
| ctxInfo.hasExtension("EXT_color_buffer_half_float") || |
| ctxInfo.hasExtension("GL_EXT_color_buffer_float") || |
| ctxInfo.hasExtension("EXT_color_buffer_float"); |
| } else if ((ctxInfo.hasExtension("GL_OES_texture_half_float") || |
| ctxInfo.hasExtension("OES_texture_half_float")) && |
| (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") || |
| ctxInfo.hasExtension("OES_texture_half_float_linear"))) { |
| rgba16FTextureSupport = true; |
| // We don't check for EXT_color_buffer_float as it's only defined for WebGL 2. |
| rgba16FRenderTargetSupport = |
| ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") || |
| ctxInfo.hasExtension("EXT_color_buffer_half_float"); |
| } |
| } |
| |
| if (rgba16FTextureSupport) { |
| info.fFlags = FormatInfo::kTexturable_Flag; |
| if (rgba16FRenderTargetSupport) { |
| info.fFlags |= fpRenderFlags; |
| } |
| } |
| if (texStorageSupported && !formatWorkarounds.fDisableRGBA16FTexStorageForCrBug1008003) { |
| info.fFlags |= FormatInfo::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_RGBA16F; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = |
| texImageSupportsSizedInternalFormat ? GR_GL_RGBA16F : GR_GL_RGBA; |
| } |
| |
| if (rgba16FTextureSupport) { |
| uint32_t flags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| |
| info.fColorTypeInfoCount = 2; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: RGBA16F, Surface: kRGBA_F16 |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kRGBA_F16; |
| ctInfo.fFlags = flags; |
| this->setColorTypeFormat(GrColorType::kRGBA_F16, GrGLFormat::kRGBA16F); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: RGBA16F, Surface: kRGBA_F16, Data: kRGBA_F16 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_F16; |
| ioFormat.fExternalType = halfFloatType; |
| ioFormat.fExternalTexImageFormat = GR_GL_RGBA; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: RGBA16F, Surface: kRGBA_F16, Data: kRGBA_F32 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_F32; |
| ioFormat.fExternalType = GR_GL_FLOAT; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| |
| // Format: RGBA16F, Surface: kRGBA_F16_Clamped |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kRGBA_F16_Clamped; |
| ctInfo.fFlags = flags; |
| this->setColorTypeFormat(GrColorType::kRGBA_F16_Clamped, GrGLFormat::kRGBA16F); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: RGBA16F, Surface: kRGBA_F16_Clamped, Data: kRGBA_F16_Clamped |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_F16_Clamped; |
| ioFormat.fExternalType = halfFloatType; |
| ioFormat.fExternalTexImageFormat = GR_GL_RGBA; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: RGBA16F, Surface: kRGBA_F16_Clamped, Data: kRGBA_F32 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_F32; |
| ioFormat.fExternalType = GR_GL_FLOAT; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| } |
| |
| // Format: R16F |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kR16F); |
| info.fFormatType = FormatType::kFloat; |
| info.fInternalFormatForRenderbuffer = GR_GL_R16F; |
| info.fDefaultExternalFormat = GR_GL_RED; |
| info.fDefaultExternalType = halfFloatType; |
| info.fBytesPerPixel = 2; |
| bool r16FTextureSupport = false; |
| bool r16FRenderTargetSupport = false; |
| |
| if (GR_IS_GR_GL(standard)) { |
| if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg")) { |
| r16FTextureSupport = true; |
| r16FRenderTargetSupport = true; |
| } |
| } else if (GR_IS_GR_GL_ES(standard)) { |
| // It seems possible that a combination of GL_EXT_texture_rg and |
| // GL_EXT_color_buffer_half_float might add this format to ES 2.0 but it is not entirely |
| // clear. The latter mentions interaction but that may only be for renderbuffers as |
| // neither adds the texture format explicitly. |
| // GL_OES_texture_format_half_float makes no reference to RED formats. |
| if (version >= GR_GL_VER(3, 0)) { |
| r16FTextureSupport = true; |
| r16FRenderTargetSupport = version >= GR_GL_VER(3, 2) || |
| ctxInfo.hasExtension("GL_EXT_color_buffer_float") || |
| ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"); |
| } |
| } else if (GR_IS_GR_WEBGL(standard)) { |
| if (version >= GR_GL_VER(2, 0)) { |
| r16FTextureSupport = true; |
| r16FRenderTargetSupport = ctxInfo.hasExtension("GL_EXT_color_buffer_float") || |
| ctxInfo.hasExtension("EXT_color_buffer_float"); |
| } |
| } |
| |
| if (r16FTextureSupport) { |
| info.fFlags = FormatInfo::kTexturable_Flag; |
| if (r16FRenderTargetSupport) { |
| info.fFlags |= fpRenderFlags; |
| } |
| } |
| if (texStorageSupported) { |
| info.fFlags |= FormatInfo::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_R16F; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = |
| texImageSupportsSizedInternalFormat ? GR_GL_R16F : GR_GL_RED; |
| } |
| |
| if (r16FTextureSupport) { |
| // Format: R16F, Surface: kAlpha_F16 |
| info.fColorTypeInfoCount = 1; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kAlpha_F16; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| ctInfo.fTextureSwizzle = GrSwizzle::RRRR(); |
| ctInfo.fOutputSwizzle = GrSwizzle::AAAA(); |
| this->setColorTypeFormat(GrColorType::kAlpha_F16, GrGLFormat::kR16F); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: R16F, Surface: kAlpha_F16, Data: kAlpha_F16 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kAlpha_F16; |
| ioFormat.fExternalType = halfFloatType; |
| ioFormat.fExternalTexImageFormat = GR_GL_RED; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: R16F, Surface: kAlpha_F16, Data: kAlpha_F32xxx |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kAlpha_F32xxx; |
| ioFormat.fExternalType = GR_GL_FLOAT; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| } |
| |
| // Format: LUMINANCE16F |
| { |
| // NOTE: We disallow lum16f on ES devices if linear filtering modes are not |
| // supported. This is for simplicity, but a more granular approach is possible. |
| bool lum16FSupported = false; |
| bool lum16FSizedFormatSupported = false; |
| if (GR_IS_GR_GL(standard)) { |
| if (!fIsCoreProfile && ctxInfo.hasExtension("GL_ARB_texture_float")) { |
| lum16FSupported = true; |
| lum16FSizedFormatSupported = true; |
| } |
| } else if (GR_IS_GR_GL_ES(standard)) { |
| if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") && |
| ctxInfo.hasExtension("GL_OES_texture_half_float")) { |
| lum16FSupported = true; |
| // Even on ES3 this extension is required to define LUMINANCE16F. |
| lum16FSizedFormatSupported = ctxInfo.hasExtension("GL_EXT_texture_storage"); |
| } |
| } // No WebGL support |
| |
| if (formatWorkarounds.fDisableLuminance16F) { |
| lum16FSupported = false; |
| } |
| |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kLUMINANCE16F); |
| info.fFormatType = FormatType::kFloat; |
| info.fInternalFormatForRenderbuffer = GR_GL_LUMINANCE16F; |
| info.fDefaultExternalFormat = GR_GL_LUMINANCE; |
| info.fDefaultExternalType = halfFloatType; |
| info.fBytesPerPixel = 2; |
| |
| if (lum16FSupported) { |
| info.fFlags = FormatInfo::kTexturable_Flag; |
| |
| if (texStorageSupported && lum16FSizedFormatSupported) { |
| info.fFlags |= FormatInfo::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE16F; |
| } else if (texImageSupportsSizedInternalFormat && lum16FSizedFormatSupported) { |
| info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE16F; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE; |
| } |
| |
| info.fColorTypeInfoCount = 1; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: LUMINANCE16F, Surface: kAlpha_F16 |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kAlpha_F16; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag; |
| ctInfo.fTextureSwizzle = GrSwizzle::RRRR(); |
| ctInfo.fOutputSwizzle = GrSwizzle::AAAA(); |
| |
| int idx = static_cast<int>(GrColorType::kAlpha_F16); |
| if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) { |
| this->setColorTypeFormat(GrColorType::kAlpha_F16, GrGLFormat::kLUMINANCE16F); |
| } |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: LUMINANCE16F, Surface: kAlpha_F16, Data: kAlpha_F16 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kAlpha_F16; |
| ioFormat.fExternalType = halfFloatType; |
| ioFormat.fExternalTexImageFormat = GR_GL_LUMINANCE; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: LUMINANCE16F, Surface: kAlpha_F16, Data: kRGBA_F32 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_F32; |
| ioFormat.fExternalType = GR_GL_FLOAT; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| } |
| |
| // Format: RGB8 |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB8); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| info.fInternalFormatForRenderbuffer = GR_GL_RGB8; |
| info.fDefaultExternalFormat = GR_GL_RGB; |
| info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; |
| info.fBytesPerPixel = 4; // We assume the GPU stores this format 4 byte aligned |
| info.fFlags = FormatInfo::kTexturable_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::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_RGB8; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = |
| texImageSupportsSizedInternalFormat ? GR_GL_RGB8 : GR_GL_RGB; |
| } |
| if (formatWorkarounds.fDisableRGB8ForMali400) { |
| info.fFlags = 0; |
| } |
| |
| info.fColorTypeInfoCount = 1; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: RGB8, Surface: kRGB_888x |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kRGB_888x; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| this->setColorTypeFormat(GrColorType::kRGB_888x, GrGLFormat::kRGB8); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: RGB8, Surface: kRGB_888x, Data: kRGB_888x |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGB_888x; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| // This is technically the wrong format to use for this color type since the color |
| // type is 4 bytes but the format is 3. However, we don't currently upload data of |
| // this type so the format is only used when creating an empty texture. If we want |
| // to support uploading data we should add in RGB_888 GrColorType. Additionally, on |
| // the FormatInfo we should have a default format to use when we want to create an |
| // empty texture. |
| ioFormat.fExternalTexImageFormat = GR_GL_RGB; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: RGB8, Surface: kRGB_888x, Data: kRGBA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| |
| // Format: RG8 |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG8); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| info.fInternalFormatForRenderbuffer = GR_GL_RG8; |
| info.fDefaultExternalFormat = GR_GL_RG; |
| info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; |
| info.fBytesPerPixel = 2; |
| bool rg8Support = false; |
| if (GR_IS_GR_GL(standard)) { |
| rg8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg"); |
| } else if (GR_IS_GR_GL_ES(standard)) { |
| rg8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg"); |
| } else if (GR_IS_GR_WEBGL(standard)) { |
| rg8Support = version >= GR_GL_VER(2, 0); |
| } |
| if (rg8Support) { |
| info.fFlags |= FormatInfo::kTexturable_Flag | msaaRenderFlags; |
| if (texStorageSupported) { |
| info.fFlags |= FormatInfo::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_RG8; |
| } |
| } |
| if (!(info.fFlags & FormatInfo::kUseTexStorage_Flag)) { |
| info.fInternalFormatForTexImageOrStorage = |
| texImageSupportsSizedInternalFormat ? GR_GL_RG8 : GR_GL_RG; |
| } |
| if (rg8Support) { |
| info.fColorTypeInfoCount = 1; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: RG8, Surface: kRG_88 |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kRG_88; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| this->setColorTypeFormat(GrColorType::kRG_88, GrGLFormat::kRG8); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: RG8, Surface: kRG_88, Data: kRG_88 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRG_88; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = GR_GL_RG; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: RG8, Surface: kRG_88, Data: kRGBA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| } |
| |
| // Format: RGB10_A2 |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB10_A2); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| info.fInternalFormatForRenderbuffer = GR_GL_RGB10_A2; |
| info.fDefaultExternalFormat = GR_GL_RGBA; |
| info.fDefaultExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV; |
| info.fBytesPerPixel = 4; |
| if (GR_IS_GR_GL(standard) || |
| (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3, 0))) { |
| info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags; |
| } else if (GR_IS_GR_GL_ES(standard) && |
| ctxInfo.hasExtension("GL_EXT_texture_type_2_10_10_10_REV")) { |
| info.fFlags = FormatInfo::kTexturable_Flag; |
| } // No WebGL support |
| if (texStorageSupported) { |
| info.fFlags |= FormatInfo::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_RGB10_A2; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = |
| texImageSupportsSizedInternalFormat ? GR_GL_RGB10_A2 : GR_GL_RGBA; |
| } |
| |
| if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) { |
| info.fColorTypeInfoCount = 1; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: RGB10_A2, Surface: kRGBA_1010102 |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kRGBA_1010102; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| this->setColorTypeFormat(GrColorType::kRGBA_1010102, GrGLFormat::kRGB10_A2); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: RGB10_A2, Surface: kRGBA_1010102, Data: kRGBA_1010102 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_1010102; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV; |
| ioFormat.fExternalTexImageFormat = GR_GL_RGBA; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: RGB10_A2, Surface: kRGBA_1010102, Data: kRGBA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| } |
| |
| // Format: RGBA4 |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA4); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| info.fInternalFormatForRenderbuffer = GR_GL_RGBA4; |
| info.fDefaultExternalFormat = GR_GL_RGBA; |
| info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; |
| info.fBytesPerPixel = 2; |
| info.fFlags = FormatInfo::kTexturable_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::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_RGBA4; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = |
| texImageSupportsSizedInternalFormat ? GR_GL_RGBA4 : GR_GL_RGBA; |
| } |
| |
| info.fColorTypeInfoCount = 1; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: RGBA4, Surface: kABGR_4444 |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kABGR_4444; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| this->setColorTypeFormat(GrColorType::kABGR_4444, GrGLFormat::kRGBA4); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 2; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| // Format: RGBA4, Surface: kABGR_4444, Data: kABGR_4444 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kABGR_4444; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; |
| ioFormat.fExternalTexImageFormat = GR_GL_RGBA; |
| ioFormat.fExternalReadFormat = 0; |
| } |
| |
| // Format: RGBA4, Surface: kABGR_4444, Data: kRGBA_8888 |
| { |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_8888; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = 0; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| |
| // Format: SRGB8_ALPHA8 |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kSRGB8_ALPHA8); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| info.fInternalFormatForRenderbuffer = GR_GL_SRGB8_ALPHA8; |
| info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; |
| info.fBytesPerPixel = 4; |
| |
| // We may modify the default external format below. |
| info.fDefaultExternalFormat = GR_GL_RGBA; |
| bool srgb8Alpha8TexStorageSupported = texStorageSupported; |
| bool srgb8Alpha8TextureSupport = false; |
| bool srgb8Alpha8RenderTargetSupport = false; |
| if (GR_IS_GR_GL(standard)) { |
| if (version >= GR_GL_VER(3, 0)) { |
| srgb8Alpha8TextureSupport = true; |
| srgb8Alpha8RenderTargetSupport = true; |
| } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) { |
| srgb8Alpha8TextureSupport = true; |
| if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") || |
| ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) { |
| srgb8Alpha8RenderTargetSupport = true; |
| } |
| } |
| } else if (GR_IS_GR_GL_ES(standard)) { |
| if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_sRGB")) { |
| srgb8Alpha8TextureSupport = true; |
| srgb8Alpha8RenderTargetSupport = true; |
| } |
| if (version < GR_GL_VER(3, 0)) { |
| // ES 2.0 requires that the external format matches the internal format. |
| info.fDefaultExternalFormat = GR_GL_SRGB_ALPHA; |
| // There is no defined interaction between GL_EXT_sRGB and GL_EXT_texture_storage. |
| srgb8Alpha8TexStorageSupported = false; |
| } |
| } else if (GR_IS_GR_WEBGL(standard)) { |
| // sRGB extension should be on most WebGL 1.0 contexts, although sometimes under 2 |
| // names. |
| if (version >= GR_GL_VER(2, 0) || ctxInfo.hasExtension("GL_EXT_sRGB") || |
| ctxInfo.hasExtension("EXT_sRGB")) { |
| srgb8Alpha8TextureSupport = true; |
| srgb8Alpha8RenderTargetSupport = true; |
| } |
| if (version < GR_GL_VER(2, 0)) { |
| // WebGL 1.0 requires that the external format matches the internal format. |
| info.fDefaultExternalFormat = GR_GL_SRGB_ALPHA; |
| // There is no extension to WebGL 1 that adds glTexStorage. |
| SkASSERT(!srgb8Alpha8TexStorageSupported); |
| } |
| } |
| |
| if (srgb8Alpha8TextureSupport) { |
| info.fFlags = FormatInfo::kTexturable_Flag; |
| if (srgb8Alpha8RenderTargetSupport) { |
| info.fFlags |= formatWorkarounds.fDisableSRGBRenderWithMSAAForMacAMD |
| ? nonMSAARenderFlags |
| : msaaRenderFlags; |
| } |
| } |
| if (srgb8Alpha8TexStorageSupported) { |
| info.fFlags |= FormatInfo::kUseTexStorage_Flag; |
| info.fInternalFormatForTexImageOrStorage = GR_GL_SRGB8_ALPHA8; |
| } else { |
| info.fInternalFormatForTexImageOrStorage = |
| texImageSupportsSizedInternalFormat ? GR_GL_SRGB8_ALPHA8 : GR_GL_SRGB_ALPHA; |
| } |
| |
| if (srgb8Alpha8TextureSupport) { |
| info.fColorTypeInfoCount = 1; |
| info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); |
| int ctIdx = 0; |
| // Format: SRGB8_ALPHA8, Surface: kRGBA_8888_SRGB |
| { |
| auto& ctInfo = info.fColorTypeInfos[ctIdx++]; |
| ctInfo.fColorType = GrColorType::kRGBA_8888_SRGB; |
| ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag; |
| this->setColorTypeFormat(GrColorType::kRGBA_8888_SRGB, GrGLFormat::kSRGB8_ALPHA8); |
| |
| // External IO ColorTypes: |
| ctInfo.fExternalIOFormatCount = 1; |
| ctInfo.fExternalIOFormats.reset( |
| new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]()); |
| int ioIdx = 0; |
| |
| // Format: SRGB8_ALPHA8, Surface: kRGBA_8888_SRGB, Data: kRGBA_8888_SRGB |
| { |
| // 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. |
| GrGLenum texImageExternalFormat = GR_GL_RGBA; |
| |
| // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the |
| // <format> param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and |
| // <format> params to match. Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the |
| // <format> param. On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the |
| // <format> param to glTexImage. |
| if (GR_IS_GR_GL_ES(standard) && version == GR_GL_VER(2,0)) { |
| texImageExternalFormat = GR_GL_SRGB_ALPHA; |
| } |
| auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++]; |
| ioFormat.fColorType = GrColorType::kRGBA_8888_SRGB; |
| ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE; |
| ioFormat.fExternalTexImageFormat = texImageExternalFormat; |
| ioFormat.fExternalReadFormat = GR_GL_RGBA; |
| } |
| } |
| } |
| } |
| |
| // Format: COMPRESSED_RGB8_ETC2 |
| { |
| FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_RGB8_ETC2); |
| info.fFormatType = FormatType::kNormalizedFixedPoint; |
| info.fInternalFormatForTexImageOrStorage = 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::kTexturable_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::kTexturable_Flag; |
| } |
| } // No WebGL support |
| |
| // There are no support GrColorTypes for this format |
| |