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/GrSwizzle.h" 19 #include "src/gpu/gl/GrGLStencilAttachment.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 typedef GrGLStencilAttachment::Format StencilFormat; 33 34 /** 35 * The type of MSAA for FBOs supported. Different extensions have different 36 * semantics of how / when a resolve is performed. 37 */ 38 enum MSFBOType { 39 /** 40 * no support for MSAA FBOs 41 */ 42 kNone_MSFBOType = 0, 43 /** 44 * OpenGL 3.0+, OpenGL ES 3.0+, GL_ARB_framebuffer_object, 45 * GL_CHROMIUM_framebuffer_multisample, GL_ANGLE_framebuffer_multisample, 46 * or GL_EXT_framebuffer_multisample 47 */ 48 kStandard_MSFBOType, 49 /** 50 * GL_APPLE_framebuffer_multisample ES extension 51 */ 52 kES_Apple_MSFBOType, 53 /** 54 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers. 55 * Instead the texture is multisampled when bound to the FBO and then resolved automatically 56 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call 57 * GR_GL_MAX_SAMPLES_IMG). 58 */ 59 kES_IMG_MsToTexture_MSFBOType, 60 /** 61 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard 62 * GL_MAX_SAMPLES value. 63 */ 64 kES_EXT_MsToTexture_MSFBOType, 65 66 kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType 67 }; 68 69 enum BlitFramebufferFlags { 70 kNoSupport_BlitFramebufferFlag = 1 << 0, 71 kNoScalingOrMirroring_BlitFramebufferFlag = 1 << 1, 72 kResolveMustBeFull_BlitFrambufferFlag = 1 << 2, 73 kNoMSAADst_BlitFramebufferFlag = 1 << 3, 74 kNoFormatConversion_BlitFramebufferFlag = 1 << 4, 75 kNoFormatConversionForMSAASrc_BlitFramebufferFlag = 1 << 5, 76 kRectsMustMatchForMSAASrc_BlitFramebufferFlag = 1 << 6, 77 }; 78 79 enum InvalidateFBType { 80 kNone_InvalidateFBType, 81 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer() 82 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer() 83 84 kLast_InvalidateFBType = kInvalidate_InvalidateFBType 85 }; 86 87 enum MapBufferType { 88 kNone_MapBufferType, 89 kMapBuffer_MapBufferType, // glMapBuffer() 90 kMapBufferRange_MapBufferType, // glMapBufferRange() 91 kChromium_MapBufferType, // GL_CHROMIUM_map_sub 92 93 kLast_MapBufferType = kChromium_MapBufferType, 94 }; 95 96 enum TransferBufferType { 97 kNone_TransferBufferType, 98 kPBO_TransferBufferType, // ARB_pixel_buffer_object 99 kChromium_TransferBufferType, // CHROMIUM_pixel_transfer_buffer_object 100 101 kLast_TransferBufferType = kChromium_TransferBufferType, 102 }; 103 104 /** 105 * Initializes the GrGLCaps to the set of features supported in the current 106 * OpenGL context accessible via ctxInfo. 107 */ 108 GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo, 109 const GrGLInterface* glInterface); 110 111 bool isFormatSRGB(const GrBackendFormat&) const override; 112 bool isFormatCompressed(const GrBackendFormat&, 113 SkImage::CompressionType* compressionType = nullptr) const override; 114 115 bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const override; 116 bool isFormatTexturable(const GrBackendFormat&) const override; 117 bool isFormatTexturable(GrGLFormat) const; 118 119 bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, 120 int sampleCount = 1) const override; 121 bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override; isFormatRenderable(GrGLFormat format,int sampleCount)122 bool isFormatRenderable(GrGLFormat format, int sampleCount) const { 123 return sampleCount <= this->maxRenderTargetSampleCount(format); 124 } 125 getRenderTargetSampleCount(int requestedCount,const GrBackendFormat & format)126 int getRenderTargetSampleCount(int requestedCount, 127 const GrBackendFormat& format) const override { 128 return this->getRenderTargetSampleCount(requestedCount, format.asGLFormat()); 129 } 130 int getRenderTargetSampleCount(int requestedCount, GrGLFormat) const; 131 maxRenderTargetSampleCount(const GrBackendFormat & format)132 int maxRenderTargetSampleCount(const GrBackendFormat& format) const override { 133 return this->maxRenderTargetSampleCount(format.asGLFormat()); 134 } 135 int maxRenderTargetSampleCount(GrGLFormat) const; 136 137 size_t bytesPerPixel(GrGLFormat) const; 138 size_t bytesPerPixel(const GrBackendFormat&) const override; 139 140 bool isFormatCopyable(const GrBackendFormat&) const override; 141 142 bool canFormatBeFBOColorAttachment(GrGLFormat) const; 143 getFormatFromColorType(GrColorType colorType)144 GrGLFormat getFormatFromColorType(GrColorType colorType) const { 145 int idx = static_cast<int>(colorType); 146 return fColorTypeToFormatTable[idx]; 147 } 148 149 /** 150 * Gets the internal format to use with glTexImage...() and glTexStorage...(). May be sized or 151 * base depending upon the GL. Not applicable to compressed textures. 152 */ getTexImageOrStorageInternalFormat(GrGLFormat format)153 GrGLenum getTexImageOrStorageInternalFormat(GrGLFormat format) const { 154 return this->getFormatInfo(format).fInternalFormatForTexImageOrStorage; 155 } 156 157 /** 158 * Gets the external format and type to pass to glTexImage2D with nullptr to create an 159 * uninitialized texture. See getTexImageOrStorageInternalFormat() for the internal format. 160 */ 161 void getTexImageExternalFormatAndType(GrGLFormat surfaceFormat, GrGLenum* externalFormat, 162 GrGLenum* externalType) const; 163 164 /** 165 * Given a src data color type and a color type interpretation for a texture of a given format 166 * this provides the external GL format and type to use with glTexSubImage2d. The color types 167 * should originate from supportedWritePixelsColorType(). 168 */ 169 void getTexSubImageExternalFormatAndType(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 170 GrColorType memoryColorType, GrGLenum* externalFormat, 171 GrGLenum* externalType) const; 172 173 /** 174 * Gets the external format, type, and bytes per pixel to use when uploading zeros via 175 * glTexSubImage...() to clear the texture at creation. 176 */ 177 void getTexSubImageZeroFormatTypeAndBpp(GrGLFormat format, GrGLenum* externalFormat, 178 GrGLenum* externalType, size_t* bpp) const; 179 180 void getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 181 GrColorType memoryColorType, GrGLenum* externalFormat, 182 GrGLenum* externalType) const; 183 184 /** 185 * Gets an array of legal stencil formats. These formats are not guaranteed 186 * to be supported by the driver but are legal GLenum names given the GL 187 * version and extensions supported. 188 */ stencilFormats()189 const SkTArray<StencilFormat, true>& stencilFormats() const { 190 return fStencilFormats; 191 } 192 193 bool formatSupportsTexStorage(GrGLFormat) const; 194 195 /** 196 * Gets the internal format to use with glRenderbufferStorageMultisample...(). May be sized or 197 * base depending upon the GL. Not applicable to compressed textures. 198 */ getRenderbufferInternalFormat(GrGLFormat format)199 GrGLenum getRenderbufferInternalFormat(GrGLFormat format) const { 200 return this->getFormatInfo(format).fInternalFormatForRenderbuffer; 201 } 202 203 /** 204 * Gets the default external type to use with glTex[Sub]Image... when the data pointer is null. 205 */ getFormatDefaultExternalType(GrGLFormat format)206 GrGLenum getFormatDefaultExternalType(GrGLFormat format) const { 207 return this->getFormatInfo(format).fDefaultExternalType; 208 } 209 210 /** 211 * Has a stencil format index been found for the format (or we've found that no format works). 212 */ hasStencilFormatBeenDeterminedForFormat(GrGLFormat format)213 bool hasStencilFormatBeenDeterminedForFormat(GrGLFormat format) const { 214 return this->getFormatInfo(format).fStencilFormatIndex != FormatInfo::kUnknown_StencilIndex; 215 } 216 217 /** 218 * Gets the stencil format index for the format. This assumes 219 * hasStencilFormatBeenDeterminedForFormat has already been checked. Returns a value < 0 if 220 * no stencil format is supported with the format. Otherwise, returned index refers to the array 221 * returned by stencilFormats(). 222 */ getStencilFormatIndexForFormat(GrGLFormat format)223 int getStencilFormatIndexForFormat(GrGLFormat format) const { 224 SkASSERT(this->hasStencilFormatBeenDeterminedForFormat(format)); 225 return this->getFormatInfo(format).fStencilFormatIndex; 226 } 227 228 /** 229 * If index is >= 0 this records an index into stencilFormats() as the best stencil format for 230 * the format. If < 0 it records that the format has no supported stencil format index. 231 */ 232 void setStencilFormatIndexForFormat(GrGLFormat, int index); 233 234 /** 235 * Reports the type of MSAA FBO support. 236 */ msFBOType()237 MSFBOType msFBOType() const { return fMSFBOType; } 238 239 /** 240 * Does the preferred MSAA FBO extension have MSAA renderbuffers? 241 */ usesMSAARenderBuffers()242 bool usesMSAARenderBuffers() const { 243 return kNone_MSFBOType != fMSFBOType && 244 kES_IMG_MsToTexture_MSFBOType != fMSFBOType && 245 kES_EXT_MsToTexture_MSFBOType != fMSFBOType; 246 } 247 248 /** 249 * What functionality is supported by glBlitFramebuffer. 250 */ blitFramebufferSupportFlags()251 uint32_t blitFramebufferSupportFlags() const { return fBlitFramebufferFlags; } 252 253 /** 254 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and 255 * then implicitly resolved when read. 256 */ usesImplicitMSAAResolve()257 bool usesImplicitMSAAResolve() const { 258 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType || 259 kES_EXT_MsToTexture_MSFBOType == fMSFBOType; 260 } 261 invalidateFBType()262 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; } 263 264 /// What type of buffer mapping is supported? mapBufferType()265 MapBufferType mapBufferType() const { return fMapBufferType; } 266 267 /// What type of transfer buffer is supported? transferBufferType()268 TransferBufferType transferBufferType() const { return fTransferBufferType; } 269 270 /// The maximum number of fragment uniform vectors (GLES has min. 16). maxFragmentUniformVectors()271 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; } 272 273 /// Is there support for GL_PACK_REVERSE_ROW_ORDER packFlipYSupport()274 bool packFlipYSupport() const { return fPackFlipYSupport; } 275 276 /// Is there support for texture parameter GL_TEXTURE_USAGE textureUsageSupport()277 bool textureUsageSupport() const { return fTextureUsageSupport; } 278 279 /// Is GL_ARB_IMAGING supported imagingSupport()280 bool imagingSupport() const { return fImagingSupport; } 281 282 /// Is there support for Vertex Array Objects? vertexArrayObjectSupport()283 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; } 284 285 /// Is there support for GL_KHR_debug? debugSupport()286 bool debugSupport() const { return fDebugSupport; } 287 288 /// Is there support for ES2 compatability? ES2CompatibilitySupport()289 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; } 290 291 /// Is there support for glDraw*Instanced? drawInstancedSupport()292 bool drawInstancedSupport() const { return fDrawInstancedSupport; } 293 294 /// Is there support for glDraw*Indirect? Note that the baseInstance fields of indirect draw 295 /// commands cannot be used unless we have base instance support. drawIndirectSupport()296 bool drawIndirectSupport() const { return fDrawIndirectSupport; } 297 298 /// Is there support for glMultiDraw*Indirect? Note that the baseInstance fields of indirect 299 /// draw commands cannot be used unless we have base instance support. multiDrawIndirectSupport()300 bool multiDrawIndirectSupport() const { return fMultiDrawIndirectSupport; } 301 302 /// Is there support for glDrawRangeElements? drawRangeElementsSupport()303 bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; } 304 305 /// Are the baseInstance fields supported in indirect draw commands? baseInstanceSupport()306 bool baseInstanceSupport() const { return fBaseInstanceSupport; } 307 308 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content. useNonVBOVertexAndIndexDynamicData()309 bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; } 310 311 SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override; 312 313 SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, 314 const GrBackendFormat& surfaceFormat, 315 GrColorType srcColorType) const override; 316 isCoreProfile()317 bool isCoreProfile() const { return fIsCoreProfile; } 318 bindFragDataLocationSupport()319 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; } 320 bindUniformLocationSupport()321 bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; } 322 323 /// Are textures with GL_TEXTURE_RECTANGLE type supported. rectangleTextureSupport()324 bool rectangleTextureSupport() const { return fRectangleTextureSupport; } 325 mipMapLevelAndLodControlSupport()326 bool mipMapLevelAndLodControlSupport() const { return fMipMapLevelAndLodControlSupport; } 327 doManualMipmapping()328 bool doManualMipmapping() const { return fDoManualMipmapping; } 329 330 void onDumpJSON(SkJSONWriter*) const override; 331 rgba8888PixelsOpsAreSlow()332 bool rgba8888PixelsOpsAreSlow() const { return fRGBA8888PixelsOpsAreSlow; } partialFBOReadIsSlow()333 bool partialFBOReadIsSlow() const { return fPartialFBOReadIsSlow; } rgbaToBgraReadbackConversionsAreSlow()334 bool rgbaToBgraReadbackConversionsAreSlow() const { 335 return fRGBAToBGRAReadbackConversionsAreSlow; 336 } 337 useBufferDataNullHint()338 bool useBufferDataNullHint() const { return fUseBufferDataNullHint; } 339 340 // Certain Intel GPUs on Mac fail to clear if the glClearColor is made up of only 1s and 0s. clearToBoundaryValuesIsBroken()341 bool clearToBoundaryValuesIsBroken() const { return fClearToBoundaryValuesIsBroken; } 342 343 /// glClearTex(Sub)Image support clearTextureSupport()344 bool clearTextureSupport() const { return fClearTextureSupport; } 345 346 // Adreno/MSAA drops a draw on the imagefiltersbase GM if the base vertex param to 347 // glDrawArrays is nonzero. 348 // https://bugs.chromium.org/p/skia/issues/detail?id=6650 drawArraysBaseVertexIsBroken()349 bool drawArraysBaseVertexIsBroken() const { return fDrawArraysBaseVertexIsBroken; } 350 351 // If true then we must use an intermediate surface to perform partial updates to unorm textures 352 // that have ever been bound to a FBO. disallowTexSubImageForUnormConfigTexturesEverBoundToFBO()353 bool disallowTexSubImageForUnormConfigTexturesEverBoundToFBO() const { 354 return fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO; 355 } 356 357 // Use an intermediate surface to write pixels (full or partial overwrite) to into a texture 358 // that is bound to an FBO. useDrawInsteadOfAllRenderTargetWrites()359 bool useDrawInsteadOfAllRenderTargetWrites() const { 360 return fUseDrawInsteadOfAllRenderTargetWrites; 361 } 362 363 // At least some Adreno 3xx drivers draw lines incorrectly after drawing non-lines. Toggling 364 // face culling on and off seems to resolve this. requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines()365 bool requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() const { 366 return fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines; 367 } 368 369 // Some Adreno drivers refuse to ReadPixels from an MSAA buffer that has stencil attached. detachStencilFromMSAABuffersBeforeReadPixels()370 bool detachStencilFromMSAABuffersBeforeReadPixels() const { 371 return fDetachStencilFromMSAABuffersBeforeReadPixels; 372 } 373 374 // Older Android versions seem to have an issue with setting GL_TEXTURE_BASE_LEVEL or 375 // GL_TEXTURE_MAX_LEVEL for GL_TEXTURE_EXTERNAL_OES textures. dontSetBaseOrMaxLevelForExternalTextures()376 bool dontSetBaseOrMaxLevelForExternalTextures() const { 377 return fDontSetBaseOrMaxLevelForExternalTextures; 378 } 379 380 // PowerVRGX6250 drops every pixel if we modify the sample mask while color writes are disabled. neverDisableColorWrites()381 bool neverDisableColorWrites() const { return fNeverDisableColorWrites; } 382 383 // Returns the observed maximum number of instances the driver can handle in a single draw call 384 // without crashing, or 'pendingInstanceCount' if this workaround is not necessary. 385 // NOTE: the return value may be larger than pendingInstanceCount. maxInstancesPerDrawWithoutCrashing(int pendingInstanceCount)386 int maxInstancesPerDrawWithoutCrashing(int pendingInstanceCount) const { 387 return (fMaxInstancesPerDrawWithoutCrashing) 388 ? fMaxInstancesPerDrawWithoutCrashing : pendingInstanceCount; 389 } 390 391 bool canCopyTexSubImage(GrGLFormat dstFormat, bool dstHasMSAARenderBuffer, 392 const GrTextureType* dstTypeIfTexture, 393 GrGLFormat srcFormat, bool srcHasMSAARenderBuffer, 394 const GrTextureType* srcTypeIfTexture) const; 395 bool canCopyAsBlit(GrGLFormat dstFormat, int dstSampleCnt, 396 const GrTextureType* dstTypeIfTexture, 397 GrGLFormat srcFormat, int srcSampleCnt, 398 const GrTextureType* srcTypeIfTexture, 399 const SkRect& srcBounds, bool srcBoundsExact, 400 const SkIRect& srcRect, const SkIPoint& dstPoint) const; 401 bool canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTexturable) const; 402 403 DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src, 404 GrColorType) const override; 405 programBinarySupport()406 bool programBinarySupport() const { return fProgramBinarySupport; } programParameterSupport()407 bool programParameterSupport() const { return fProgramParameterSupport; } 408 samplerObjectSupport()409 bool samplerObjectSupport() const { return fSamplerObjectSupport; } 410 tiledRenderingSupport()411 bool tiledRenderingSupport() const { return fTiledRenderingSupport; } 412 fbFetchRequiresEnablePerSample()413 bool fbFetchRequiresEnablePerSample() const { return fFBFetchRequiresEnablePerSample; } 414 415 /* Is there support for enabling/disabling sRGB writes for sRGB-capable color buffers? */ srgbWriteControl()416 bool srgbWriteControl() const { return fSRGBWriteControl; } 417 418 GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&, 419 bool isAlphaChannel) const override; 420 421 GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override; 422 423 GrSwizzle getTextureSwizzle(const GrBackendFormat&, GrColorType) const override; 424 GrSwizzle getOutputSwizzle(const GrBackendFormat&, GrColorType) const override; 425 426 #if GR_TEST_UTILS standard()427 GrGLStandard standard() const { return fStandard; } 428 429 std::vector<TestFormatColorTypeCombination> getTestingCombinations() const override; 430 #endif 431 432 private: 433 enum ExternalFormatUsage { 434 kTexImage_ExternalFormatUsage, 435 kReadPixels_ExternalFormatUsage, 436 }; 437 void getExternalFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 438 GrColorType memoryColorType, ExternalFormatUsage usage, 439 GrGLenum* externalFormat, GrGLenum* externalType) const; 440 441 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*); 442 void initGLSL(const GrGLContextInfo&, const GrGLInterface*); 443 bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*); 444 445 struct FormatWorkarounds { 446 bool fDisableSRGBRenderWithMSAAForMacAMD = false; 447 bool fDisableRGBA16FTexStorageForCrBug1008003 = false; 448 bool fDisableBGRATextureStorageForIntelWindowsES = false; 449 bool fDisableRGB8ForMali400 = false; 450 bool fDisableLuminance16F = false; 451 bool fDontDisableTexStorageOnAndroid = false; 452 }; 453 454 void applyDriverCorrectnessWorkarounds(const GrGLContextInfo&, const GrContextOptions&, 455 GrShaderCaps*, FormatWorkarounds*); 456 457 void onApplyOptionsOverrides(const GrContextOptions& options) override; 458 459 bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const override; 460 461 void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&, 462 const GrGLInterface*); 463 void initBlendEqationSupport(const GrGLContextInfo&); 464 void initStencilSupport(const GrGLContextInfo&); 465 // This must be called after initFSAASupport(). 466 void initFormatTable(const GrGLContextInfo&, const GrGLInterface*, const FormatWorkarounds&); 467 void setupSampleCounts(const GrGLContextInfo&, const GrGLInterface*); 468 bool onSurfaceSupportsWritePixels(const GrSurface*) const override; 469 bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, 470 const SkIRect& srcRect, const SkIPoint& dstPoint) const override; 471 GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override; 472 GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat&, GrColorType) const override; 473 bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override; 474 475 SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&, 476 GrColorType) const override; 477 478 GrGLStandard fStandard; 479 480 SkTArray<StencilFormat, true> fStencilFormats; 481 482 int fMaxFragmentUniformVectors; 483 484 MSFBOType fMSFBOType; 485 InvalidateFBType fInvalidateFBType; 486 MapBufferType fMapBufferType; 487 TransferBufferType fTransferBufferType; 488 489 bool fPackFlipYSupport : 1; 490 bool fTextureUsageSupport : 1; 491 bool fImagingSupport : 1; 492 bool fVertexArrayObjectSupport : 1; 493 bool fDebugSupport : 1; 494 bool fES2CompatibilitySupport : 1; 495 bool fDrawInstancedSupport : 1; 496 bool fDrawIndirectSupport : 1; 497 bool fDrawRangeElementsSupport : 1; 498 bool fMultiDrawIndirectSupport : 1; 499 bool fBaseInstanceSupport : 1; 500 bool fUseNonVBOVertexAndIndexDynamicData : 1; 501 bool fIsCoreProfile : 1; 502 bool fBindFragDataLocationSupport : 1; 503 bool fRGBA8888PixelsOpsAreSlow : 1; 504 bool fPartialFBOReadIsSlow : 1; 505 bool fBindUniformLocationSupport : 1; 506 bool fRectangleTextureSupport : 1; 507 bool fMipMapLevelAndLodControlSupport : 1; 508 bool fRGBAToBGRAReadbackConversionsAreSlow : 1; 509 bool fUseBufferDataNullHint : 1; 510 bool fClearTextureSupport : 1; 511 bool fProgramBinarySupport : 1; 512 bool fProgramParameterSupport : 1; 513 bool fSamplerObjectSupport : 1; 514 bool fTiledRenderingSupport : 1; 515 bool fFBFetchRequiresEnablePerSample : 1; 516 bool fSRGBWriteControl : 1; 517 518 // Driver workarounds 519 bool fDoManualMipmapping : 1; 520 bool fClearToBoundaryValuesIsBroken : 1; 521 bool fDrawArraysBaseVertexIsBroken : 1; 522 bool fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO : 1; 523 bool fUseDrawInsteadOfAllRenderTargetWrites : 1; 524 bool fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines : 1; 525 bool fDetachStencilFromMSAABuffersBeforeReadPixels : 1; 526 bool fDontSetBaseOrMaxLevelForExternalTextures : 1; 527 bool fNeverDisableColorWrites : 1; 528 int fMaxInstancesPerDrawWithoutCrashing; 529 530 uint32_t fBlitFramebufferFlags; 531 532 struct ReadPixelsFormat { ReadPixelsFormatReadPixelsFormat533 ReadPixelsFormat() : fFormat(0), fType(0) {} 534 GrGLenum fFormat; 535 GrGLenum fType; 536 }; 537 538 /** Number type of the components (with out considering number of bits.) */ 539 enum class FormatType { 540 kUnknown, 541 kNormalizedFixedPoint, 542 kFloat, 543 }; 544 545 // ColorTypeInfo for a specific format 546 struct ColorTypeInfo { 547 GrColorType fColorType = GrColorType::kUnknown; 548 enum { 549 kUploadData_Flag = 0x1, 550 // Does Ganesh itself support rendering to this colorType & format pair. Renderability 551 // still additionally depends on if the format can be an FBO color attachment. 552 kRenderable_Flag = 0x2, 553 }; 554 uint32_t fFlags = 0; 555 556 GrSwizzle fTextureSwizzle; 557 GrSwizzle fOutputSwizzle; 558 559 struct ExternalIOFormats { 560 GrColorType fColorType = GrColorType::kUnknown; 561 562 /** The external format and type are to be used when uploading/downloading data using 563 data of fColorType and uploading to a texture of a given GrGLFormat and its 564 intended GrColorType. The fExternalTexImageFormat is the format to use for TexImage 565 calls. The fExternalReadFormat is used when calling ReadPixels. If either is zero 566 that signals that either TexImage or ReadPixels is not supported for the combination 567 of format and color types. */ 568 GrGLenum fExternalType = 0; 569 GrGLenum fExternalTexImageFormat = 0; 570 GrGLenum fExternalReadFormat = 0; 571 }; 572 externalFormatColorTypeInfo573 GrGLenum externalFormat(GrColorType externalColorType, ExternalFormatUsage usage) const { 574 for (int i = 0; i < fExternalIOFormatCount; ++i) { 575 if (fExternalIOFormats[i].fColorType == externalColorType) { 576 if (usage == kTexImage_ExternalFormatUsage) { 577 return fExternalIOFormats[i].fExternalTexImageFormat; 578 } else { 579 SkASSERT(usage == kReadPixels_ExternalFormatUsage); 580 return fExternalIOFormats[i].fExternalReadFormat; 581 } 582 } 583 } 584 return 0; 585 } 586 externalTypeColorTypeInfo587 GrGLenum externalType(GrColorType externalColorType) const { 588 for (int i = 0; i < fExternalIOFormatCount; ++i) { 589 if (fExternalIOFormats[i].fColorType == externalColorType) { 590 return fExternalIOFormats[i].fExternalType; 591 } 592 } 593 return 0; 594 } 595 596 std::unique_ptr<ExternalIOFormats[]> fExternalIOFormats; 597 int fExternalIOFormatCount = 0; 598 }; 599 600 struct FormatInfo { colorTypeFlagsFormatInfo601 uint32_t colorTypeFlags(GrColorType colorType) const { 602 for (int i = 0; i < fColorTypeInfoCount; ++i) { 603 if (fColorTypeInfos[i].fColorType == colorType) { 604 return fColorTypeInfos[i].fFlags; 605 } 606 } 607 return 0; 608 } 609 externalFormatFormatInfo610 GrGLenum externalFormat(GrColorType surfaceColorType, GrColorType externalColorType, 611 ExternalFormatUsage usage) const { 612 for (int i = 0; i < fColorTypeInfoCount; ++i) { 613 if (fColorTypeInfos[i].fColorType == surfaceColorType) { 614 return fColorTypeInfos[i].externalFormat(externalColorType, usage); 615 } 616 } 617 return 0; 618 } 619 externalTypeFormatInfo620 GrGLenum externalType(GrColorType surfaceColorType, GrColorType externalColorType) const { 621 for (int i = 0; i < fColorTypeInfoCount; ++i) { 622 if (fColorTypeInfos[i].fColorType == surfaceColorType) { 623 return fColorTypeInfos[i].externalType(externalColorType); 624 } 625 } 626 return 0; 627 } 628 629 enum { 630 kTexturable_Flag = 0x1, 631 /** kFBOColorAttachment means that even if the format cannot be a GrRenderTarget, we can 632 still attach it to a FBO for blitting or reading pixels. */ 633 kFBOColorAttachment_Flag = 0x2, 634 kFBOColorAttachmentWithMSAA_Flag = 0x4, 635 kUseTexStorage_Flag = 0x8, 636 }; 637 uint32_t fFlags = 0; 638 639 FormatType fFormatType = FormatType::kUnknown; 640 641 // Not defined for uncompressed formats. Passed to glCompressedTexImage... 642 GrGLenum fCompressedInternalFormat = 0; 643 644 // Value to uses as the "internalformat" argument to glTexImage or glTexStorage. It is 645 // initialized in coordination with the presence/absence of the kUseTexStorage flag. In 646 // other words, it is only guaranteed to be compatible with glTexImage if the flag is not 647 // set and or with glTexStorage if the flag is set. 648 GrGLenum fInternalFormatForTexImageOrStorage = 0; 649 650 // Value to uses as the "internalformat" argument to glRenderbufferStorageMultisample... 651 GrGLenum fInternalFormatForRenderbuffer = 0; 652 653 // Default values to use along with fInternalFormatForTexImageOrStorage for function 654 // glTexImage2D when not input providing data (passing nullptr). Not defined for compressed 655 // formats. Also used to upload zeros to initially clear a texture. 656 GrGLenum fDefaultExternalFormat = 0; 657 GrGLenum fDefaultExternalType = 0; 658 659 // This value is only valid for regular formats. Compressed formats will be 0. 660 GrGLenum fBytesPerPixel = 0; 661 662 enum { 663 // This indicates that a stencil format has not yet been determined for the config. 664 kUnknown_StencilIndex = -1, 665 // This indicates that there is no supported stencil format for the config. 666 kUnsupported_StencilFormatIndex = -2 667 }; 668 669 // Index fStencilFormats. 670 int fStencilFormatIndex = kUnknown_StencilIndex; 671 672 SkTDArray<int> fColorSampleCounts; 673 674 std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos; 675 int fColorTypeInfoCount = 0; 676 }; 677 678 FormatInfo fFormatTable[kGrGLFormatCount]; 679 getFormatInfo(GrGLFormat format)680 FormatInfo& getFormatInfo(GrGLFormat format) { return fFormatTable[static_cast<int>(format)]; } getFormatInfo(GrGLFormat format)681 const FormatInfo& getFormatInfo(GrGLFormat format) const { 682 return fFormatTable[static_cast<int>(format)]; 683 } 684 685 GrGLFormat fColorTypeToFormatTable[kGrColorTypeCnt]; 686 void setColorTypeFormat(GrColorType, GrGLFormat); 687 688 typedef GrCaps INHERITED; 689 }; 690 691 #endif 692