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 9 #ifndef GrGLCaps_DEFINED 10 #define GrGLCaps_DEFINED 11 12 #include <functional> 13 #include "include/private/GrGLTypesPriv.h" 14 #include "include/private/SkChecksum.h" 15 #include "include/private/SkTArray.h" 16 #include "include/private/SkTHash.h" 17 #include "src/gpu/GrCaps.h" 18 #include "src/gpu/Swizzle.h" 19 #include "src/gpu/gl/GrGLAttachment.h" 20 #include "src/gpu/gl/GrGLUtil.h" 21 22 class GrGLContextInfo; 23 class GrGLRenderTarget; 24 25 /** 26 * Stores some capabilities of a GL context. Most are determined by the GL 27 * version and the extensions string. It also tracks formats that have passed 28 * the FBO completeness test. 29 */ 30 class GrGLCaps : public GrCaps { 31 public: 32 /** 33 * The type of MSAA for FBOs supported. Different extensions have different 34 * semantics of how / when a resolve is performed. 35 */ 36 enum MSFBOType { 37 /** 38 * no support for MSAA FBOs 39 */ 40 kNone_MSFBOType = 0, 41 /** 42 * OpenGL 3.0+, OpenGL ES 3.0+, GL_ARB_framebuffer_object, 43 * GL_CHROMIUM_framebuffer_multisample, GL_ANGLE_framebuffer_multisample, 44 * or GL_EXT_framebuffer_multisample 45 */ 46 kStandard_MSFBOType, 47 /** 48 * GL_APPLE_framebuffer_multisample ES extension 49 */ 50 kES_Apple_MSFBOType, 51 /** 52 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers. 53 * Instead the texture is multisampled when bound to the FBO and then resolved automatically 54 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call 55 * GR_GL_MAX_SAMPLES_IMG). 56 */ 57 kES_IMG_MsToTexture_MSFBOType, 58 /** 59 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard 60 * GL_MAX_SAMPLES value. 61 */ 62 kES_EXT_MsToTexture_MSFBOType, 63 64 kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType 65 }; 66 67 enum BlitFramebufferFlags { 68 kNoSupport_BlitFramebufferFlag = 1 << 0, 69 kNoScalingOrMirroring_BlitFramebufferFlag = 1 << 1, 70 kResolveMustBeFull_BlitFrambufferFlag = 1 << 2, 71 kNoMSAADst_BlitFramebufferFlag = 1 << 3, 72 kNoFormatConversion_BlitFramebufferFlag = 1 << 4, 73 kNoFormatConversionForMSAASrc_BlitFramebufferFlag = 1 << 5, 74 kRectsMustMatchForMSAASrc_BlitFramebufferFlag = 1 << 6, 75 }; 76 77 enum InvalidateFBType { 78 kNone_InvalidateFBType, 79 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer() 80 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer() 81 82 kLast_InvalidateFBType = kInvalidate_InvalidateFBType 83 }; 84 85 enum MapBufferType { 86 kNone_MapBufferType, 87 kMapBuffer_MapBufferType, // glMapBuffer() 88 kMapBufferRange_MapBufferType, // glMapBufferRange() 89 kChromium_MapBufferType, // GL_CHROMIUM_map_sub 90 91 kLast_MapBufferType = kChromium_MapBufferType, 92 }; 93 94 enum class TransferBufferType { 95 kNone, 96 kNV_PBO, // NV_pixel_buffer_object 97 kARB_PBO, // ARB_pixel_buffer_object 98 kChromium, // CHROMIUM_pixel_transfer_buffer_object 99 }; 100 101 enum class FenceType { 102 kNone, 103 kSyncObject, 104 kNVFence 105 }; 106 107 enum class MultiDrawType { 108 kNone, 109 kMultiDrawIndirect, // ARB_multi_draw_indirect, EXT_multi_draw_indirect, or GL 4.3 core. 110 kANGLEOrWebGL // ANGLE_base_vertex_base_instance or 111 // WEBGL_draw_instanced_base_vertex_base_instance 112 }; 113 114 /** 115 * Initializes the GrGLCaps to the set of features supported in the current 116 * OpenGL context accessible via ctxInfo. 117 */ 118 GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo, 119 const GrGLInterface* glInterface); 120 121 bool isFormatSRGB(const GrBackendFormat&) const override; 122 123 bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const override; 124 bool isFormatTexturable(GrGLFormat) const; 125 126 bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, 127 int sampleCount = 1) const override; 128 bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override; isFormatRenderable(GrGLFormat format,int sampleCount)129 bool isFormatRenderable(GrGLFormat format, int sampleCount) const { 130 return sampleCount <= this->maxRenderTargetSampleCount(format); 131 } 132 getRenderTargetSampleCount(int requestedCount,const GrBackendFormat & format)133 int getRenderTargetSampleCount(int requestedCount, 134 const GrBackendFormat& format) const override { 135 return this->getRenderTargetSampleCount(requestedCount, format.asGLFormat()); 136 } 137 int getRenderTargetSampleCount(int requestedCount, GrGLFormat) const; 138 maxRenderTargetSampleCount(const GrBackendFormat & format)139 int maxRenderTargetSampleCount(const GrBackendFormat& format) const override { 140 return this->maxRenderTargetSampleCount(format.asGLFormat()); 141 } 142 int maxRenderTargetSampleCount(GrGLFormat) const; 143 144 bool isFormatCopyable(const GrBackendFormat&) const override; 145 146 bool canFormatBeFBOColorAttachment(GrGLFormat) const; 147 getFormatFromColorType(GrColorType colorType)148 GrGLFormat getFormatFromColorType(GrColorType colorType) const { 149 int idx = static_cast<int>(colorType); 150 return fColorTypeToFormatTable[idx]; 151 } 152 153 /** 154 * Gets the internal format to use with glTexImage...() and glTexStorage...(). May be sized or 155 * base depending upon the GL. Not applicable to compressed textures. 156 */ getTexImageOrStorageInternalFormat(GrGLFormat format)157 GrGLenum getTexImageOrStorageInternalFormat(GrGLFormat format) const { 158 return this->getFormatInfo(format).fInternalFormatForTexImageOrStorage; 159 } 160 161 /** 162 * Gets the external format and type to pass to glTexImage2D with nullptr to create an 163 * uninitialized texture. See getTexImageOrStorageInternalFormat() for the internal format. 164 */ 165 void getTexImageExternalFormatAndType(GrGLFormat surfaceFormat, GrGLenum* externalFormat, 166 GrGLenum* externalType) const; 167 168 /** 169 * Given a src data color type and a color type interpretation for a texture of a given format 170 * this provides the external GL format and type to use with glTexSubImage2d. The color types 171 * should originate from supportedWritePixelsColorType(). 172 */ 173 void getTexSubImageExternalFormatAndType(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 174 GrColorType memoryColorType, GrGLenum* externalFormat, 175 GrGLenum* externalType) const; 176 177 /** 178 * Gets the external format, type, and bytes per pixel to use when uploading solid color data 179 * via glTexSubImage...() to clear the texture at creation. 180 */ 181 void getTexSubImageDefaultFormatTypeAndColorType(GrGLFormat format, 182 GrGLenum* externalFormat, 183 GrGLenum* externalType, 184 GrColorType* colorType) const; 185 186 void getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 187 GrColorType memoryColorType, GrGLenum* externalFormat, 188 GrGLenum* externalType) const; 189 190 /** 191 * Gets an array of legal stencil formats. These formats are not guaranteed 192 * to be supported by the driver but are legal GLenum names given the GL 193 * version and extensions supported. 194 */ stencilFormats()195 const SkTArray<GrGLFormat, true>& stencilFormats() const { 196 return fStencilFormats; 197 } 198 199 bool formatSupportsTexStorage(GrGLFormat) const; 200 201 /** 202 * Would it be useful to check GL_IMPLEMENTATION_READ_FORMAT and _TYPE for this format to 203 * detect more efficient glReadPixels arguments? 204 */ 205 bool shouldQueryImplementationReadSupport(GrGLFormat format) const; 206 207 /** 208 * Let caps know the result of GL_IMPLEMENTATION_READ_FORMAT and _TYPE query for a format 209 * to update supported glReadPixels arguments. 210 */ 211 void didQueryImplementationReadSupport(GrGLFormat format, 212 GrGLenum readFormat, 213 GrGLenum readType) const; 214 215 /** 216 * Gets the internal format to use with glRenderbufferStorageMultisample...(). May be sized or 217 * base depending upon the GL. Not applicable to compressed textures. 218 */ getRenderbufferInternalFormat(GrGLFormat format)219 GrGLenum getRenderbufferInternalFormat(GrGLFormat format) const { 220 return this->getFormatInfo(format).fInternalFormatForRenderbuffer; 221 } 222 223 /** 224 * Gets the default external type to use with glTex[Sub]Image... when the data pointer is null. 225 */ getFormatDefaultExternalType(GrGLFormat format)226 GrGLenum getFormatDefaultExternalType(GrGLFormat format) const { 227 return this->getFormatInfo(format).fDefaultExternalType; 228 } 229 230 /** 231 * Has a stencil format index been found for the format (or we've found that no format works). 232 */ hasStencilFormatBeenDeterminedForFormat(GrGLFormat format)233 bool hasStencilFormatBeenDeterminedForFormat(GrGLFormat format) const { 234 return this->getFormatInfo(format).fStencilFormatIndex != FormatInfo::kUnknown_StencilIndex; 235 } 236 237 /** 238 * Gets the stencil format index for the format. This assumes 239 * hasStencilFormatBeenDeterminedForFormat has already been checked. Returns a value < 0 if 240 * no stencil format is supported with the format. Otherwise, returned index refers to the array 241 * returned by stencilFormats(). 242 */ getStencilFormatIndexForFormat(GrGLFormat format)243 int getStencilFormatIndexForFormat(GrGLFormat format) const { 244 SkASSERT(this->hasStencilFormatBeenDeterminedForFormat(format)); 245 return this->getFormatInfo(format).fStencilFormatIndex; 246 } 247 248 /** 249 * If index is >= 0 this records an index into stencilFormats() as the best stencil format for 250 * the format. If < 0 it records that the format has no supported stencil format index. 251 */ 252 void setStencilFormatIndexForFormat(GrGLFormat, int index); 253 254 /** 255 * Reports the type of MSAA FBO support. 256 */ msFBOType()257 MSFBOType msFBOType() const { return fMSFBOType; } 258 259 /** 260 * Does the preferred MSAA FBO extension have MSAA renderbuffers? 261 */ usesMSAARenderBuffers()262 bool usesMSAARenderBuffers() const { 263 return kNone_MSFBOType != fMSFBOType && 264 kES_IMG_MsToTexture_MSFBOType != fMSFBOType && 265 kES_EXT_MsToTexture_MSFBOType != fMSFBOType; 266 } 267 268 /** 269 * Is it unsupported to only resolve a sub-rectangle of a framebuffer? 270 */ framebufferResolvesMustBeFullSize()271 bool framebufferResolvesMustBeFullSize() const { 272 SkASSERT(fMSFBOType != kNone_MSFBOType); 273 return fMSFBOType == kES_Apple_MSFBOType || 274 (fBlitFramebufferFlags & kResolveMustBeFull_BlitFrambufferFlag); 275 } 276 277 /** 278 * Can we resolve a single-sample framebuffer into an MSAA framebuffer? 279 */ canResolveSingleToMSAA()280 bool canResolveSingleToMSAA() const { 281 SkASSERT(fMSFBOType != kNone_MSFBOType); 282 return fMSFBOType != kES_Apple_MSFBOType && 283 !(fBlitFramebufferFlags & GrGLCaps::kNoMSAADst_BlitFramebufferFlag); 284 } 285 286 /** 287 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and 288 * then implicitly resolved when read. 289 */ usesImplicitMSAAResolve()290 bool usesImplicitMSAAResolve() const { 291 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType || 292 kES_EXT_MsToTexture_MSFBOType == fMSFBOType; 293 } 294 invalidateFBType()295 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; } 296 297 /// What type of buffer mapping is supported? mapBufferType()298 MapBufferType mapBufferType() const { return fMapBufferType; } 299 300 /// What type of transfer buffer is supported? transferBufferType()301 TransferBufferType transferBufferType() const { return fTransferBufferType; } 302 303 /// How are GrFences implemented? fenceType()304 FenceType fenceType() const { return fFenceType; } 305 306 /// How are multi draws implemented (if at all)? multiDrawType()307 MultiDrawType multiDrawType() const { return fMultiDrawType; } 308 309 /// The maximum number of fragment uniform vectors (GLES has min. 16). maxFragmentUniformVectors()310 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; } 311 312 /// Is there support for GL_PACK_REVERSE_ROW_ORDER packFlipYSupport()313 bool packFlipYSupport() const { return fPackFlipYSupport; } 314 315 /// Is there support for texture parameter GL_TEXTURE_USAGE textureUsageSupport()316 bool textureUsageSupport() const { return fTextureUsageSupport; } 317 318 /// Is GL_ARB_IMAGING supported imagingSupport()319 bool imagingSupport() const { return fImagingSupport; } 320 321 /// Is there support for Vertex Array Objects? vertexArrayObjectSupport()322 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; } 323 324 /// Is there support for GL_KHR_debug? debugSupport()325 bool debugSupport() const { return fDebugSupport; } 326 327 /// Is there support for ES2 compatability? ES2CompatibilitySupport()328 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; } 329 330 /// Is there support for glDrawRangeElements? drawRangeElementsSupport()331 bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; } 332 333 /// Are the glDraw*Base(VertexBase)Instance methods, and baseInstance fields in indirect draw 334 //commands supported? baseVertexBaseInstanceSupport()335 bool baseVertexBaseInstanceSupport() const { return fBaseVertexBaseInstanceSupport; } 336 337 SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override; 338 339 SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, 340 const GrBackendFormat& surfaceFormat, 341 GrColorType srcColorType) const override; 342 isCoreProfile()343 bool isCoreProfile() const { return fIsCoreProfile; } 344 bindFragDataLocationSupport()345 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; } 346 bindUniformLocationSupport()347 bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; } 348 349 /// Are textures with GL_TEXTURE_RECTANGLE type supported. rectangleTextureSupport()350 bool rectangleTextureSupport() const { return fRectangleTextureSupport; } 351 352 /// Can set the BASE and MAX mip map level. mipmapLevelControlSupport()353 bool mipmapLevelControlSupport() const { return fMipmapLevelControlSupport; } 354 355 /// Can set the MIN/MAX LOD value. mipmapLodControlSupport()356 bool mipmapLodControlSupport() const { return fMipmapLodControlSupport; } 357 doManualMipmapping()358 bool doManualMipmapping() const { return fDoManualMipmapping; } 359 360 void onDumpJSON(SkJSONWriter*) const override; 361 useBufferDataNullHint()362 bool useBufferDataNullHint() const { return fUseBufferDataNullHint; } 363 364 // Certain Intel GPUs on Mac fail to clear if the glClearColor is made up of only 1s and 0s. clearToBoundaryValuesIsBroken()365 bool clearToBoundaryValuesIsBroken() const { return fClearToBoundaryValuesIsBroken; } 366 367 /// glClearTex(Sub)Image support clearTextureSupport()368 bool clearTextureSupport() const { return fClearTextureSupport; } 369 370 // Adreno/MSAA drops a draw on the imagefiltersbase GM if the base vertex param to 371 // glDrawArrays is nonzero. 372 // https://bugs.chromium.org/p/skia/issues/detail?id=6650 drawArraysBaseVertexIsBroken()373 bool drawArraysBaseVertexIsBroken() const { return fDrawArraysBaseVertexIsBroken; } 374 375 // If true then we must use an intermediate surface to perform partial updates to unorm textures 376 // that have ever been bound to a FBO. disallowTexSubImageForUnormConfigTexturesEverBoundToFBO()377 bool disallowTexSubImageForUnormConfigTexturesEverBoundToFBO() const { 378 return fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO; 379 } 380 381 // Use an intermediate surface to write pixels (full or partial overwrite) to into a texture 382 // that is bound to an FBO. useDrawInsteadOfAllRenderTargetWrites()383 bool useDrawInsteadOfAllRenderTargetWrites() const { 384 return fUseDrawInsteadOfAllRenderTargetWrites; 385 } 386 387 // At least some Adreno 3xx drivers draw lines incorrectly after drawing non-lines. Toggling 388 // face culling on and off seems to resolve this. requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines()389 bool requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() const { 390 return fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines; 391 } 392 393 // Older Android versions seem to have an issue with setting GL_TEXTURE_BASE_LEVEL or 394 // GL_TEXTURE_MAX_LEVEL for GL_TEXTURE_EXTERNAL_OES textures. dontSetBaseOrMaxLevelForExternalTextures()395 bool dontSetBaseOrMaxLevelForExternalTextures() const { 396 return fDontSetBaseOrMaxLevelForExternalTextures; 397 } 398 399 // PowerVRGX6250 drops every pixel if we modify the sample mask while color writes are disabled. neverDisableColorWrites()400 bool neverDisableColorWrites() const { return fNeverDisableColorWrites; } 401 402 // Texture parameters must be used to enable MIP mapping even when a sampler object is used. mustSetAnyTexParameterToEnableMipmapping()403 bool mustSetAnyTexParameterToEnableMipmapping() const { 404 return fMustSetAnyTexParameterToEnableMipmapping; 405 } 406 407 // Whether we must reset the blend function to not reference src2 when disabling blending after 408 // previously referencing src2. mustResetBlendFuncBetweenDualSourceAndDisable()409 bool mustResetBlendFuncBetweenDualSourceAndDisable() const { 410 return fMustResetBlendFuncBetweenDualSourceAndDisable; 411 } 412 413 // Before changing the sample count of a texture bound to an FBO with 414 // glFramebufferTexture2DMultisample() temporarily bind texture 0 to avoid corruption int the 415 // texture contents. bindTexture0WhenChangingTextureFBOMultisampleCount()416 bool bindTexture0WhenChangingTextureFBOMultisampleCount() const { 417 return fBindTexture0WhenChangingTextureFBOMultisampleCount; 418 } 419 420 // After using glCheckFramebufferStatus() bind 0 to the color attachment and then rebind the 421 // original color attachment. rebindColorAttachmentAfterCheckFramebufferStatus()422 bool rebindColorAttachmentAfterCheckFramebufferStatus() const { 423 return fRebindColorAttachmentAfterCheckFramebufferStatus; 424 } 425 426 // Returns the observed maximum number of instances the driver can handle in a single draw call 427 // without crashing, or 'pendingInstanceCount' if this workaround is not necessary. 428 // NOTE: the return value may be larger than pendingInstanceCount. maxInstancesPerDrawWithoutCrashing(int pendingInstanceCount)429 int maxInstancesPerDrawWithoutCrashing(int pendingInstanceCount) const { 430 return (fMaxInstancesPerDrawWithoutCrashing) 431 ? fMaxInstancesPerDrawWithoutCrashing : pendingInstanceCount; 432 } 433 434 bool canCopyTexSubImage(GrGLFormat dstFormat, bool dstHasMSAARenderBuffer, 435 const GrTextureType* dstTypeIfTexture, 436 GrGLFormat srcFormat, bool srcHasMSAARenderBuffer, 437 const GrTextureType* srcTypeIfTexture) const; 438 bool canCopyAsBlit(GrGLFormat dstFormat, int dstSampleCnt, 439 const GrTextureType* dstTypeIfTexture, 440 GrGLFormat srcFormat, int srcSampleCnt, 441 const GrTextureType* srcTypeIfTexture, 442 const SkRect& srcBounds, bool srcBoundsExact, 443 const SkIRect& srcRect, const SkIPoint& dstPoint) const; 444 bool canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTexturable) const; 445 446 DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src, 447 GrColorType) const override; 448 programBinarySupport()449 bool programBinarySupport() const { return fProgramBinarySupport; } programParameterSupport()450 bool programParameterSupport() const { return fProgramParameterSupport; } 451 bool programBinaryFormatIsValid(GrGLenum binaryFormat) const; 452 453 /** Are sampler objects available in this GL? */ samplerObjectSupport()454 bool samplerObjectSupport() const { return fSamplerObjectSupport; } 455 456 /** 457 * Are we using sampler objects in favor of texture parameters? (This will only be true if 458 * samplerObjectSupport()). 459 */ useSamplerObjects()460 bool useSamplerObjects() const { return fUseSamplerObjects; } 461 textureSwizzleSupport()462 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; } 463 tiledRenderingSupport()464 bool tiledRenderingSupport() const { return fTiledRenderingSupport; } 465 fbFetchRequiresEnablePerSample()466 bool fbFetchRequiresEnablePerSample() const { return fFBFetchRequiresEnablePerSample; } 467 468 /* Is there support for enabling/disabling sRGB writes for sRGB-capable color buffers? */ srgbWriteControl()469 bool srgbWriteControl() const { return fSRGBWriteControl; } 470 471 /** Skip checks for GL errors, shader compilation success, program link success. */ skipErrorChecks()472 bool skipErrorChecks() const { return fSkipErrorChecks; } 473 supportsProtected()474 bool supportsProtected() const { return fSupportsProtected; } 475 clientCanDisableMultisample()476 bool clientCanDisableMultisample() const { return fClientCanDisableMultisample; } 477 478 GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override; 479 480 skgpu::Swizzle getWriteSwizzle(const GrBackendFormat&, GrColorType) const override; 481 482 uint64_t computeFormatKey(const GrBackendFormat&) const override; 483 484 GrProgramDesc makeDesc(GrRenderTarget*, 485 const GrProgramInfo&, 486 ProgramDescOverrideFlags) const override; 487 488 #if GR_TEST_UTILS standard()489 GrGLStandard standard() const { return fStandard; } 490 491 std::vector<TestFormatColorTypeCombination> getTestingCombinations() const override; 492 #endif 493 494 private: 495 enum ExternalFormatUsage { 496 kTexImage_ExternalFormatUsage, 497 kReadPixels_ExternalFormatUsage, 498 }; 499 void getExternalFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 500 GrColorType memoryColorType, ExternalFormatUsage usage, 501 GrGLenum* externalFormat, GrGLenum* externalType) const; 502 503 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*); 504 void initGLSL(const GrGLContextInfo&, const GrGLInterface*); 505 506 struct FormatWorkarounds { 507 bool fDisableSRGBRenderWithMSAAForMacAMD = false; 508 bool fDisableRGBA16FTexStorageForCrBug1008003 = false; 509 bool fDisableBGRATextureStorageForIntelWindowsES = false; 510 bool fDisableLuminance16F = false; 511 bool fDontDisableTexStorageOnAndroid = false; 512 bool fDisallowDirectRG8ReadPixels = false; 513 bool fDisallowBGRA8ReadPixels = false; 514 bool fDisallowR8ForPowerVRSGX54x = false; 515 bool fDisallowUnorm16Transfers = false; 516 bool fDisallowTextureUnorm16 = false; 517 bool fDisallowETC2Compression = false; 518 }; 519 520 void applyDriverCorrectnessWorkarounds(const GrGLContextInfo&, const GrContextOptions&, 521 const GrGLInterface*, 522 GrShaderCaps*, FormatWorkarounds*); 523 524 void onApplyOptionsOverrides(const GrContextOptions& options) override; 525 526 bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const override; 527 528 void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&, 529 const GrGLInterface*); 530 void initBlendEqationSupport(const GrGLContextInfo&); 531 void initStencilSupport(const GrGLContextInfo&); 532 // This must be called after initFSAASupport(). 533 void initFormatTable(const GrGLContextInfo&, const GrGLInterface*, const FormatWorkarounds&); 534 void setupSampleCounts(const GrGLContextInfo&, const GrGLInterface*); 535 bool onSurfaceSupportsWritePixels(const GrSurface*) const override; 536 bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, 537 const SkIRect& srcRect, const SkIPoint& dstPoint) const override; 538 GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override; 539 bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override; 540 541 SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&, 542 GrColorType) const override; 543 544 skgpu::Swizzle onGetReadSwizzle(const GrBackendFormat&, GrColorType) const override; 545 546 GrDstSampleFlags onGetDstSampleFlagsForProxy(const GrRenderTargetProxy*) const override; 547 548 bool onSupportsDynamicMSAA(const GrRenderTargetProxy*) const override; 549 550 GrGLStandard fStandard = kNone_GrGLStandard; 551 552 SkTArray<GrGLFormat, true> fStencilFormats; 553 SkTArray<GrGLenum, true> fProgramBinaryFormats; 554 555 int fMaxFragmentUniformVectors = 0; 556 557 MSFBOType fMSFBOType = kNone_MSFBOType; 558 InvalidateFBType fInvalidateFBType = kNone_InvalidateFBType; 559 MapBufferType fMapBufferType = kNone_MapBufferType; 560 TransferBufferType fTransferBufferType = TransferBufferType::kNone; 561 FenceType fFenceType = FenceType::kNone; 562 MultiDrawType fMultiDrawType = MultiDrawType::kNone; 563 564 bool fPackFlipYSupport : 1; 565 bool fTextureUsageSupport : 1; 566 bool fImagingSupport : 1; 567 bool fVertexArrayObjectSupport : 1; 568 bool fDebugSupport : 1; 569 bool fES2CompatibilitySupport : 1; 570 bool fDrawRangeElementsSupport : 1; 571 bool fBaseVertexBaseInstanceSupport : 1; 572 bool fIsCoreProfile : 1; 573 bool fBindFragDataLocationSupport : 1; 574 bool fBindUniformLocationSupport : 1; 575 bool fRectangleTextureSupport : 1; 576 bool fMipmapLevelControlSupport : 1; 577 bool fMipmapLodControlSupport : 1; 578 bool fUseBufferDataNullHint : 1; 579 bool fClearTextureSupport : 1; 580 bool fProgramBinarySupport : 1; 581 bool fProgramParameterSupport : 1; 582 bool fSamplerObjectSupport : 1; 583 bool fUseSamplerObjects : 1; 584 bool fTextureSwizzleSupport : 1; 585 bool fTiledRenderingSupport : 1; 586 bool fFBFetchRequiresEnablePerSample : 1; 587 bool fSRGBWriteControl : 1; 588 bool fSkipErrorChecks : 1; 589 bool fClientCanDisableMultisample : 1; 590 bool fSupportsProtected : 1; 591 592 // Driver workarounds 593 bool fDoManualMipmapping : 1; 594 bool fClearToBoundaryValuesIsBroken : 1; 595 bool fDrawArraysBaseVertexIsBroken : 1; 596 bool fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO : 1; 597 bool fUseDrawInsteadOfAllRenderTargetWrites : 1; 598 bool fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines : 1; 599 bool fDontSetBaseOrMaxLevelForExternalTextures : 1; 600 bool fNeverDisableColorWrites : 1; 601 bool fMustSetAnyTexParameterToEnableMipmapping : 1; 602 bool fAllowBGRA8CopyTexSubImage : 1; 603 bool fDisallowDynamicMSAA : 1; 604 bool fMustResetBlendFuncBetweenDualSourceAndDisable : 1; 605 bool fBindTexture0WhenChangingTextureFBOMultisampleCount : 1; 606 bool fRebindColorAttachmentAfterCheckFramebufferStatus : 1; 607 int fMaxInstancesPerDrawWithoutCrashing = 0; 608 609 uint32_t fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag; 610 611 struct ReadPixelsFormat { ReadPixelsFormatReadPixelsFormat612 ReadPixelsFormat() : fFormat(0), fType(0) {} 613 GrGLenum fFormat; 614 GrGLenum fType; 615 }; 616 617 /** Number type of the components (with out considering number of bits.) */ 618 enum class FormatType { 619 kUnknown, 620 kNormalizedFixedPoint, 621 kFloat, 622 }; 623 624 // ColorTypeInfo for a specific format 625 struct ColorTypeInfo { 626 GrColorType fColorType = GrColorType::kUnknown; 627 enum { 628 kUploadData_Flag = 0x1, 629 // Does Ganesh itself support rendering to this colorType & format pair. Renderability 630 // still additionally depends on if the format can be an FBO color attachment. 631 kRenderable_Flag = 0x2, 632 }; 633 uint32_t fFlags = 0; 634 635 skgpu::Swizzle fReadSwizzle; 636 skgpu::Swizzle fWriteSwizzle; 637 638 struct ExternalIOFormats { 639 GrColorType fColorType = GrColorType::kUnknown; 640 641 /** The external format and type are to be used when uploading/downloading data using 642 data of fColorType and uploading to a texture of a given GrGLFormat and its 643 intended GrColorType. The fExternalTexImageFormat is the format to use for TexImage 644 calls. The fExternalReadFormat is used when calling ReadPixels. If either is zero 645 that signals that either TexImage or ReadPixels is not supported for the combination 646 of format and color types. */ 647 GrGLenum fExternalType = 0; 648 GrGLenum fExternalTexImageFormat = 0; 649 GrGLenum fExternalReadFormat = 0; 650 /** 651 * Must check whether GL_IMPLEMENTATION_COLOR_READ_FORMAT and _TYPE match 652 * fExternalReadFormat and fExternalType before using with glReadPixels. 653 */ 654 bool fRequiresImplementationReadQuery = false; 655 }; 656 externalFormatColorTypeInfo657 GrGLenum externalFormat(GrColorType externalColorType, ExternalFormatUsage usage, 658 bool haveQueriedImplementationReadFormat) const { 659 for (int i = 0; i < fExternalIOFormatCount; ++i) { 660 if (fExternalIOFormats[i].fColorType == externalColorType) { 661 if (usage == kTexImage_ExternalFormatUsage) { 662 return fExternalIOFormats[i].fExternalTexImageFormat; 663 } else { 664 SkASSERT(usage == kReadPixels_ExternalFormatUsage); 665 if (!haveQueriedImplementationReadFormat && 666 fExternalIOFormats[i].fRequiresImplementationReadQuery) { 667 return 0; 668 } 669 return fExternalIOFormats[i].fExternalReadFormat; 670 } 671 } 672 } 673 return 0; 674 } 675 externalTypeColorTypeInfo676 GrGLenum externalType(GrColorType externalColorType) const { 677 for (int i = 0; i < fExternalIOFormatCount; ++i) { 678 if (fExternalIOFormats[i].fColorType == externalColorType) { 679 return fExternalIOFormats[i].fExternalType; 680 } 681 } 682 return 0; 683 } 684 685 std::unique_ptr<ExternalIOFormats[]> fExternalIOFormats; 686 int fExternalIOFormatCount = 0; 687 }; 688 689 struct FormatInfo { colorTypeFlagsFormatInfo690 uint32_t colorTypeFlags(GrColorType colorType) const { 691 for (int i = 0; i < fColorTypeInfoCount; ++i) { 692 if (fColorTypeInfos[i].fColorType == colorType) { 693 return fColorTypeInfos[i].fFlags; 694 } 695 } 696 return 0; 697 } 698 externalFormatFormatInfo699 GrGLenum externalFormat(GrColorType surfaceColorType, GrColorType externalColorType, 700 ExternalFormatUsage usage) const { 701 for (int i = 0; i < fColorTypeInfoCount; ++i) { 702 if (fColorTypeInfos[i].fColorType == surfaceColorType) { 703 return fColorTypeInfos[i].externalFormat(externalColorType, usage, 704 fHaveQueriedImplementationReadSupport); 705 } 706 } 707 return 0; 708 } 709 externalTypeFormatInfo710 GrGLenum externalType(GrColorType surfaceColorType, GrColorType externalColorType) const { 711 for (int i = 0; i < fColorTypeInfoCount; ++i) { 712 if (fColorTypeInfos[i].fColorType == surfaceColorType) { 713 return fColorTypeInfos[i].externalType(externalColorType); 714 } 715 } 716 return 0; 717 } 718 719 enum { 720 kTexturable_Flag = 0x01, 721 /** kFBOColorAttachment means that even if the format cannot be a GrRenderTarget, we can 722 still attach it to a FBO for blitting or reading pixels. */ 723 kFBOColorAttachment_Flag = 0x02, 724 kFBOColorAttachmentWithMSAA_Flag = 0x04, 725 kUseTexStorage_Flag = 0x08, 726 /** 727 * Are pixel buffer objects supported in/out of this format? Ignored if PBOs are not 728 * supported at all. 729 */ 730 kTransfers_Flag = 0x10, 731 }; 732 uint32_t fFlags = 0; 733 734 FormatType fFormatType = FormatType::kUnknown; 735 736 // Not defined for uncompressed formats. Passed to glCompressedTexImage... 737 GrGLenum fCompressedInternalFormat = 0; 738 739 // Value to uses as the "internalformat" argument to glTexImage or glTexStorage. It is 740 // initialized in coordination with the presence/absence of the kUseTexStorage flag. In 741 // other words, it is only guaranteed to be compatible with glTexImage if the flag is not 742 // set and or with glTexStorage if the flag is set. 743 GrGLenum fInternalFormatForTexImageOrStorage = 0; 744 745 // Value to uses as the "internalformat" argument to glRenderbufferStorageMultisample... 746 GrGLenum fInternalFormatForRenderbuffer = 0; 747 748 // Default values to use along with fInternalFormatForTexImageOrStorage for function 749 // glTexImage2D when not input providing data (passing nullptr) or when clearing it by 750 // uploading a block of solid color data. Not defined for compressed formats. 751 GrGLenum fDefaultExternalFormat = 0; 752 GrGLenum fDefaultExternalType = 0; 753 // When the above two values are used to initialize a texture by uploading cleared data to 754 // it the data should be of this color type. 755 GrColorType fDefaultColorType = GrColorType::kUnknown; 756 757 bool fHaveQueriedImplementationReadSupport = false; 758 759 enum { 760 // This indicates that a stencil format has not yet been determined for the config. 761 kUnknown_StencilIndex = -1, 762 // This indicates that there is no supported stencil format for the config. 763 kUnsupported_StencilFormatIndex = -2 764 }; 765 766 // Index fStencilFormats. 767 int fStencilFormatIndex = kUnknown_StencilIndex; 768 769 SkTDArray<int> fColorSampleCounts; 770 771 std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos; 772 int fColorTypeInfoCount = 0; 773 }; 774 775 FormatInfo fFormatTable[kGrGLColorFormatCount]; 776 getFormatInfo(GrGLFormat format)777 FormatInfo& getFormatInfo(GrGLFormat format) { return fFormatTable[static_cast<int>(format)]; } getFormatInfo(GrGLFormat format)778 const FormatInfo& getFormatInfo(GrGLFormat format) const { 779 return fFormatTable[static_cast<int>(format)]; 780 } 781 782 GrGLFormat fColorTypeToFormatTable[kGrColorTypeCnt]; 783 void setColorTypeFormat(GrColorType, GrGLFormat); 784 785 using INHERITED = GrCaps; 786 }; 787 788 #endif 789