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