1 2 /* 3 * Copyright 2013 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 #ifndef GrCaps_DEFINED 9 #define GrCaps_DEFINED 10 11 #include "include/core/SkImageInfo.h" 12 #include "include/core/SkRefCnt.h" 13 #include "include/core/SkString.h" 14 #include "include/gpu/GrDriverBugWorkarounds.h" 15 #include "include/private/GrTypesPriv.h" 16 #include "src/core/SkCompressedDataUtils.h" 17 #include "src/gpu/GrBlend.h" 18 #include "src/gpu/GrSamplerState.h" 19 #include "src/gpu/GrShaderCaps.h" 20 #include "src/gpu/GrSurfaceProxy.h" 21 22 class GrBackendFormat; 23 class GrBackendRenderTarget; 24 class GrBackendTexture; 25 struct GrContextOptions; 26 class GrProcessorKeyBuilder; 27 class GrProgramDesc; 28 class GrProgramInfo; 29 class GrRenderTargetProxy; 30 class GrSurface; 31 class SkJSONWriter; 32 33 /** 34 * Represents the capabilities of a GrContext. 35 */ 36 class GrCaps : public SkRefCnt { 37 public: 38 GrCaps(const GrContextOptions&); 39 40 void dumpJSON(SkJSONWriter*) const; 41 shaderCaps()42 const GrShaderCaps* shaderCaps() const { return fShaderCaps.get(); } refShaderCaps()43 sk_sp<const GrShaderCaps> refShaderCaps() const { return fShaderCaps; } 44 npotTextureTileSupport()45 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; } 46 /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g. 47 only for POT textures) */ mipmapSupport()48 bool mipmapSupport() const { return fMipmapSupport; } 49 gpuTracingSupport()50 bool gpuTracingSupport() const { return fGpuTracingSupport; } oversizedStencilSupport()51 bool oversizedStencilSupport() const { return fOversizedStencilSupport; } textureBarrierSupport()52 bool textureBarrierSupport() const { return fTextureBarrierSupport; } sampleLocationsSupport()53 bool sampleLocationsSupport() const { return fSampleLocationsSupport; } multisampleDisableSupport()54 bool multisampleDisableSupport() const { return fMultisampleDisableSupport; } drawInstancedSupport()55 bool drawInstancedSupport() const { return fDrawInstancedSupport; } 56 // Is there hardware support for indirect draws? (Ganesh always supports indirect draws as long 57 // as it can polyfill them with instanced calls, but this cap tells us if they are supported 58 // natively.) nativeDrawIndirectSupport()59 bool nativeDrawIndirectSupport() const { return fNativeDrawIndirectSupport; } useClientSideIndirectBuffers()60 bool useClientSideIndirectBuffers() const { 61 #ifdef SK_DEBUG 62 if (!fNativeDrawIndirectSupport || fNativeDrawIndexedIndirectIsBroken) { 63 // We might implement indirect draws with a polyfill, so the commands need to reside in 64 // CPU memory. 65 SkASSERT(fUseClientSideIndirectBuffers); 66 } 67 #endif 68 return fUseClientSideIndirectBuffers; 69 } mixedSamplesSupport()70 bool mixedSamplesSupport() const { return fMixedSamplesSupport; } conservativeRasterSupport()71 bool conservativeRasterSupport() const { return fConservativeRasterSupport; } wireframeSupport()72 bool wireframeSupport() const { return fWireframeSupport; } 73 // This flag indicates that we never have to resolve MSAA. In practice, it means that we have 74 // an MSAA-render-to-texture extension: Any render target we create internally will use the 75 // extension, and any wrapped render target is the client's responsibility. msaaResolvesAutomatically()76 bool msaaResolvesAutomatically() const { return fMSAAResolvesAutomatically; } halfFloatVertexAttributeSupport()77 bool halfFloatVertexAttributeSupport() const { return fHalfFloatVertexAttributeSupport; } 78 79 // Primitive restart functionality is core in ES 3.0, but using it will cause slowdowns on some 80 // systems. This cap is only set if primitive restart will improve performance. usePrimitiveRestart()81 bool usePrimitiveRestart() const { return fUsePrimitiveRestart; } 82 preferClientSideDynamicBuffers()83 bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; } 84 85 // On tilers, an initial fullscreen clear is an OPTIMIZATION. It allows the hardware to 86 // initialize each tile with a constant value rather than loading each pixel from memory. preferFullscreenClears()87 bool preferFullscreenClears() const { return fPreferFullscreenClears; } 88 89 // Should we discard stencil values after a render pass? (Tilers get better performance if we 90 // always load stencil buffers with a "clear" op, and then discard the content when finished.) discardStencilValuesAfterRenderPass()91 bool discardStencilValuesAfterRenderPass() const { 92 // b/160958008 93 return false; 94 #if 0 95 // This method is actually just a duplicate of preferFullscreenClears(), with a descriptive 96 // name for the sake of readability. 97 return this->preferFullscreenClears(); 98 #endif 99 } 100 101 // D3D does not allow the refs or masks to differ on a two-sided stencil draw. twoSidedStencilRefsAndMasksMustMatch()102 bool twoSidedStencilRefsAndMasksMustMatch() const { 103 return fTwoSidedStencilRefsAndMasksMustMatch; 104 } 105 preferVRAMUseOverFlushes()106 bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; } 107 preferTrianglesOverSampleMask()108 bool preferTrianglesOverSampleMask() const { return fPreferTrianglesOverSampleMask; } 109 avoidStencilBuffers()110 bool avoidStencilBuffers() const { return fAvoidStencilBuffers; } 111 avoidWritePixelsFastPath()112 bool avoidWritePixelsFastPath() const { return fAvoidWritePixelsFastPath; } 113 114 // http://skbug.com/9739 requiresManualFBBarrierAfterTessellatedStencilDraw()115 bool requiresManualFBBarrierAfterTessellatedStencilDraw() const { 116 return fRequiresManualFBBarrierAfterTessellatedStencilDraw; 117 } 118 119 // glDrawElementsIndirect fails GrMeshTest on every Win10 Intel bot. nativeDrawIndexedIndirectIsBroken()120 bool nativeDrawIndexedIndirectIsBroken() const { return fNativeDrawIndexedIndirectIsBroken; } 121 122 /** 123 * Indicates the capabilities of the fixed function blend unit. 124 */ 125 enum BlendEquationSupport { 126 kBasic_BlendEquationSupport, //<! Support to select the operator that 127 // combines src and dst terms. 128 kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific 129 // SVG/PDF blend modes. Requires blend barriers. 130 kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not 131 // require blend barriers, and permits overlap. 132 133 kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport 134 }; 135 blendEquationSupport()136 BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; } 137 advancedBlendEquationSupport()138 bool advancedBlendEquationSupport() const { 139 return fBlendEquationSupport >= kAdvanced_BlendEquationSupport; 140 } 141 advancedCoherentBlendEquationSupport()142 bool advancedCoherentBlendEquationSupport() const { 143 return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport; 144 } 145 isAdvancedBlendEquationDisabled(GrBlendEquation equation)146 bool isAdvancedBlendEquationDisabled(GrBlendEquation equation) const { 147 SkASSERT(GrBlendEquationIsAdvanced(equation)); 148 SkASSERT(this->advancedBlendEquationSupport()); 149 return SkToBool(fAdvBlendEqDisableFlags & (1 << equation)); 150 } 151 152 // On some GPUs it is a performance win to disable blending instead of doing src-over with a src 153 // alpha equal to 1. To disable blending we collapse src-over to src and the backends will 154 // handle the disabling of blending. shouldCollapseSrcOverToSrcWhenAble()155 bool shouldCollapseSrcOverToSrcWhenAble() const { 156 return fShouldCollapseSrcOverToSrcWhenAble; 157 } 158 159 /** 160 * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and 161 * textures allows partial mappings or full mappings. 162 */ 163 enum MapFlags { 164 kNone_MapFlags = 0x0, //<! Cannot map the resource. 165 166 kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of 167 // the other flags to have meaning. 168 kSubset_MapFlag = 0x2, //<! The resource can be partially mapped. 169 kAsyncRead_MapFlag = 0x4, //<! Are maps for reading asynchronous WRT GrOpsRenderPass 170 // submitted to GrGpu. 171 }; 172 mapBufferFlags()173 uint32_t mapBufferFlags() const { return fMapBufferFlags; } 174 175 // Scratch textures not being reused means that those scratch textures 176 // that we upload to (i.e., don't have a render target) will not be 177 // recycled in the texture cache. This is to prevent ghosting by drivers 178 // (in particular for deferred architectures). reuseScratchTextures()179 bool reuseScratchTextures() const { return fReuseScratchTextures; } reuseScratchBuffers()180 bool reuseScratchBuffers() const { return fReuseScratchBuffers; } 181 182 /// maximum number of attribute values per vertex maxVertexAttributes()183 int maxVertexAttributes() const { return fMaxVertexAttributes; } 184 maxRenderTargetSize()185 int maxRenderTargetSize() const { return fMaxRenderTargetSize; } 186 187 /** This is the largest render target size that can be used without incurring extra perfomance 188 cost. It is usually the max RT size, unless larger render targets are known to be slower. */ maxPreferredRenderTargetSize()189 int maxPreferredRenderTargetSize() const { return fMaxPreferredRenderTargetSize; } 190 maxTextureSize()191 int maxTextureSize() const { return fMaxTextureSize; } 192 193 /** This is the maximum tile size to use by GPU devices for rendering sw-backed images/bitmaps. 194 It is usually the max texture size, unless we're overriding it for testing. */ maxTileSize()195 int maxTileSize() const { 196 SkASSERT(fMaxTileSize <= fMaxTextureSize); 197 return fMaxTileSize; 198 } 199 maxWindowRectangles()200 int maxWindowRectangles() const { return fMaxWindowRectangles; } 201 202 // Returns whether mixed samples is supported for the given backend render target. isWindowRectanglesSupportedForRT(const GrBackendRenderTarget & rt)203 bool isWindowRectanglesSupportedForRT(const GrBackendRenderTarget& rt) const { 204 return this->maxWindowRectangles() > 0 && this->onIsWindowRectanglesSupportedForRT(rt); 205 } 206 maxPushConstantsSize()207 uint32_t maxPushConstantsSize() const { return fMaxPushConstantsSize; } 208 209 virtual bool isFormatSRGB(const GrBackendFormat&) const = 0; 210 211 bool isFormatCompressed(const GrBackendFormat& format) const; 212 213 // Can a texture be made with the GrBackendFormat, and then be bound and sampled in a shader. 214 virtual bool isFormatTexturable(const GrBackendFormat&) const = 0; 215 216 // Returns whether a texture of the given format can be copied to a texture of the same format. 217 virtual bool isFormatCopyable(const GrBackendFormat&) const = 0; 218 219 // Returns the maximum supported sample count for a format. 0 means the format is not renderable 220 // 1 means the format is renderable but doesn't support MSAA. 221 virtual int maxRenderTargetSampleCount(const GrBackendFormat&) const = 0; 222 223 // Returns the number of samples to use when performing internal draws to the given config with 224 // MSAA or mixed samples. If 0, Ganesh should not attempt to use internal multisampling. internalMultisampleCount(const GrBackendFormat & format)225 int internalMultisampleCount(const GrBackendFormat& format) const { 226 return std::min(fInternalMultisampleCount, this->maxRenderTargetSampleCount(format)); 227 } 228 229 virtual bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, 230 int sampleCount = 1) const = 0; 231 232 virtual bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const = 0; 233 234 // Find a sample count greater than or equal to the requested count which is supported for a 235 // render target of the given format or 0 if no such sample count is supported. If the requested 236 // sample count is 1 then 1 will be returned if non-MSAA rendering is supported, otherwise 0. 237 // For historical reasons requestedCount==0 is handled identically to requestedCount==1. 238 virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const = 0; 239 240 /** 241 * Backends may have restrictions on what types of surfaces support GrGpu::writePixels(). 242 * If this returns false then the caller should implement a fallback where a temporary texture 243 * is created, pixels are written to it, and then that is copied or drawn into the the surface. 244 */ 245 bool surfaceSupportsWritePixels(const GrSurface*) const; 246 247 /** 248 * Indicates whether surface supports GrGpu::readPixels, must be copied, or cannot be read. 249 */ 250 enum class SurfaceReadPixelsSupport { 251 /** GrGpu::readPixels is supported by the surface. */ 252 kSupported, 253 /** 254 * GrGpu::readPixels is not supported by this surface but this surface can be drawn 255 * or copied to a Ganesh-created GrTextureType::kTexture2D and then that surface will be 256 * readable. 257 */ 258 kCopyToTexture2D, 259 /** 260 * Not supported 261 */ 262 kUnsupported, 263 }; 264 /** 265 * Backends may have restrictions on what types of surfaces support GrGpu::readPixels(). We may 266 * either be able to read directly from the surface, read from a copy of the surface, or not 267 * read at all. 268 */ 269 virtual SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const = 0; 270 271 struct SupportedWrite { 272 GrColorType fColorType; 273 // If the write is occurring using GrGpu::transferPixelsTo then this provides the 274 // minimum alignment of the offset into the transfer buffer. 275 size_t fOffsetAlignmentForTransferBuffer; 276 }; 277 278 /** 279 * Given a dst pixel config and a src color type what color type must the caller coax the 280 * the data into in order to use GrGpu::writePixels(). 281 */ 282 virtual SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, 283 const GrBackendFormat& surfaceFormat, 284 GrColorType srcColorType) const = 0; 285 286 struct SupportedRead { 287 GrColorType fColorType; 288 // If the read is occurring using GrGpu::transferPixelsFrom then this provides the 289 // minimum alignment of the offset into the transfer buffer. 290 size_t fOffsetAlignmentForTransferBuffer; 291 }; 292 293 /** 294 * Given a src surface's color type and its backend format as well as a color type the caller 295 * would like read into, this provides a legal color type that the caller may pass to 296 * GrGpu::readPixels(). The returned color type may differ from the passed dstColorType, in 297 * which case the caller must convert the read pixel data (see GrConvertPixels). When converting 298 * to dstColorType the swizzle in the returned struct should be applied. The caller must check 299 * the returned color type for kUnknown. 300 */ 301 SupportedRead supportedReadPixelsColorType(GrColorType srcColorType, 302 const GrBackendFormat& srcFormat, 303 GrColorType dstColorType) const; 304 305 /** 306 * Do GrGpu::writePixels() and GrGpu::transferPixelsTo() support a src buffer where the row 307 * bytes is not equal to bpp * w? 308 */ writePixelsRowBytesSupport()309 bool writePixelsRowBytesSupport() const { return fWritePixelsRowBytesSupport; } 310 /** 311 * Does GrGpu::readPixels() support a dst buffer where the row bytes is not equal to bpp * w? 312 */ readPixelsRowBytesSupport()313 bool readPixelsRowBytesSupport() const { return fReadPixelsRowBytesSupport; } 314 transferFromSurfaceToBufferSupport()315 bool transferFromSurfaceToBufferSupport() const { return fTransferFromSurfaceToBufferSupport; } transferFromBufferToTextureSupport()316 bool transferFromBufferToTextureSupport() const { return fTransferFromBufferToTextureSupport; } 317 suppressPrints()318 bool suppressPrints() const { return fSuppressPrints; } 319 bufferMapThreshold()320 size_t bufferMapThreshold() const { 321 SkASSERT(fBufferMapThreshold >= 0); 322 return fBufferMapThreshold; 323 } 324 325 /** True in environments that will issue errors if memory uploaded to buffers 326 is not initialized (even if not read by draw calls). */ mustClearUploadedBufferData()327 bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; } 328 329 /** For some environments, there is a performance or safety concern to not 330 initializing textures. For example, with WebGL and Firefox, there is a large 331 performance hit to not doing it. 332 */ shouldInitializeTextures()333 bool shouldInitializeTextures() const { return fShouldInitializeTextures; } 334 335 /** Returns true if the given backend supports importing AHardwareBuffers via the 336 * GrAHardwarebufferImageGenerator. This will only ever be supported on Android devices with API 337 * level >= 26. 338 * */ supportsAHardwareBufferImages()339 bool supportsAHardwareBufferImages() const { return fSupportsAHardwareBufferImages; } 340 wireframeMode()341 bool wireframeMode() const { return fWireframeMode; } 342 343 /** Supports using GrFence. */ fenceSyncSupport()344 bool fenceSyncSupport() const { return fFenceSyncSupport; } 345 346 /** Supports using GrSemaphore. */ semaphoreSupport()347 bool semaphoreSupport() const { return fSemaphoreSupport; } 348 crossContextTextureSupport()349 bool crossContextTextureSupport() const { return fCrossContextTextureSupport; } 350 /** 351 * Returns whether or not we will be able to do a copy given the passed in params 352 */ 353 bool canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, 354 const SkIRect& srcRect, const SkIPoint& dstPoint) const; 355 dynamicStateArrayGeometryProcessorTextureSupport()356 bool dynamicStateArrayGeometryProcessorTextureSupport() const { 357 return fDynamicStateArrayGeometryProcessorTextureSupport; 358 } 359 360 // Not all backends support clearing with a scissor test (e.g. Metal), this will always 361 // return true if performColorClearsAsDraws() returns true. performPartialClearsAsDraws()362 bool performPartialClearsAsDraws() const { 363 return fPerformColorClearsAsDraws || fPerformPartialClearsAsDraws; 364 } 365 366 // Many drivers have issues with color clears. performColorClearsAsDraws()367 bool performColorClearsAsDraws() const { return fPerformColorClearsAsDraws; } 368 avoidLargeIndexBufferDraws()369 bool avoidLargeIndexBufferDraws() const { return fAvoidLargeIndexBufferDraws; } 370 371 /// Adreno 4xx devices experience an issue when there are a large number of stencil clip bit 372 /// clears. The minimal repro steps are not precisely known but drawing a rect with a stencil 373 /// op instead of using glClear seems to resolve the issue. performStencilClearsAsDraws()374 bool performStencilClearsAsDraws() const { return fPerformStencilClearsAsDraws; } 375 376 // Can we use coverage counting shortcuts to render paths? Coverage counting can cause artifacts 377 // along shared edges if care isn't taken to ensure both contours wind in the same direction. allowCoverageCounting()378 bool allowCoverageCounting() const { return fAllowCoverageCounting; } 379 380 // Should we disable the CCPR code due to a faulty driver? driverDisableCCPR()381 bool driverDisableCCPR() const { return fDriverDisableCCPR; } driverDisableMSAACCPR()382 bool driverDisableMSAACCPR() const { return fDriverDisableMSAACCPR; } 383 384 // Returns how to sample the dst values for the passed in GrRenderTargetProxy. 385 GrDstSampleType getDstSampleTypeForProxy(const GrRenderTargetProxy*) const; 386 387 /** 388 * This is used to try to ensure a successful copy a dst in order to perform shader-based 389 * blending. 390 * 391 * fRectsMustMatch will be set to true if the copy operation must ensure that the src and dest 392 * rects are identical. 393 * 394 * fMustCopyWholeSrc will be set to true if copy rect must equal src's bounds. 395 * 396 * Caller will detect cases when copy cannot succeed and try copy-as-draw as a fallback. 397 */ 398 struct DstCopyRestrictions { 399 GrSurfaceProxy::RectsMustMatch fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kNo; 400 bool fMustCopyWholeSrc = false; 401 }; getDstCopyRestrictions(const GrRenderTargetProxy * src,GrColorType ct)402 virtual DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src, 403 GrColorType ct) const { 404 return {}; 405 } 406 407 bool validateSurfaceParams(const SkISize&, const GrBackendFormat&, GrRenderable renderable, 408 int renderTargetSampleCnt, GrMipmapped) const; 409 410 bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat& format) const; 411 412 /** These are used when creating a new texture internally. */ 413 GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const; 414 415 virtual GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const = 0; 416 417 /** 418 * The CLAMP_TO_BORDER wrap mode for texture coordinates was added to desktop GL in 1.3, and 419 * GLES 3.2, but is also available in extensions. Vulkan and Metal always have support. 420 */ clampToBorderSupport()421 bool clampToBorderSupport() const { return fClampToBorderSupport; } 422 423 /** 424 * Returns the GrSwizzle to use when sampling or reading back from a texture with the passed in 425 * GrBackendFormat and GrColorType. 426 */ 427 GrSwizzle getReadSwizzle(const GrBackendFormat& format, GrColorType colorType) const; 428 429 /** 430 * Returns the GrSwizzle to use when writing colors to a surface with the passed in 431 * GrBackendFormat and GrColorType. 432 */ 433 virtual GrSwizzle getWriteSwizzle(const GrBackendFormat&, GrColorType) const = 0; 434 435 virtual uint64_t computeFormatKey(const GrBackendFormat&) const = 0; 436 workarounds()437 const GrDriverBugWorkarounds& workarounds() const { return fDriverBugWorkarounds; } 438 439 /** 440 * Adds fields to the key to represent the sampler that will be created for the passed 441 * in parameters. Currently this extra keying is only needed when building a vulkan pipeline 442 * with immutable samplers. 443 */ addExtraSamplerKey(GrProcessorKeyBuilder *,GrSamplerState,const GrBackendFormat &)444 virtual void addExtraSamplerKey(GrProcessorKeyBuilder*, 445 GrSamplerState, 446 const GrBackendFormat&) const {} 447 448 virtual GrProgramDesc makeDesc(GrRenderTarget*, const GrProgramInfo&) const = 0; 449 450 // This method specifies, for each backend, the extra properties of a RT when Ganesh creates one 451 // internally. For example, for Vulkan, Ganesh always creates RTs that can be used as input 452 // attachments. getExtraSurfaceFlagsForDeferredRT()453 virtual GrInternalSurfaceFlags getExtraSurfaceFlagsForDeferredRT() const { 454 return GrInternalSurfaceFlags::kNone; 455 } 456 457 #if GR_TEST_UTILS 458 struct TestFormatColorTypeCombination { 459 GrColorType fColorType; 460 GrBackendFormat fFormat; 461 }; 462 463 virtual std::vector<TestFormatColorTypeCombination> getTestingCombinations() const = 0; 464 #endif 465 466 protected: 467 // Subclasses must call this at the end of their init method in order to do final processing on 468 // the caps (including overrides requested by the client). 469 // NOTE: this method will only reduce the caps, never expand them. 470 void finishInitialization(const GrContextOptions& options); 471 472 sk_sp<GrShaderCaps> fShaderCaps; 473 474 bool fNPOTTextureTileSupport : 1; 475 bool fMipmapSupport : 1; 476 bool fReuseScratchTextures : 1; 477 bool fReuseScratchBuffers : 1; 478 bool fGpuTracingSupport : 1; 479 bool fOversizedStencilSupport : 1; 480 bool fTextureBarrierSupport : 1; 481 bool fSampleLocationsSupport : 1; 482 bool fMultisampleDisableSupport : 1; 483 bool fDrawInstancedSupport : 1; 484 bool fNativeDrawIndirectSupport : 1; 485 bool fUseClientSideIndirectBuffers : 1; 486 bool fMixedSamplesSupport : 1; 487 bool fConservativeRasterSupport : 1; 488 bool fWireframeSupport : 1; 489 bool fMSAAResolvesAutomatically : 1; 490 bool fUsePrimitiveRestart : 1; 491 bool fPreferClientSideDynamicBuffers : 1; 492 bool fPreferFullscreenClears : 1; 493 bool fTwoSidedStencilRefsAndMasksMustMatch : 1; 494 bool fMustClearUploadedBufferData : 1; 495 bool fShouldInitializeTextures : 1; 496 bool fSupportsAHardwareBufferImages : 1; 497 bool fHalfFloatVertexAttributeSupport : 1; 498 bool fClampToBorderSupport : 1; 499 bool fPerformPartialClearsAsDraws : 1; 500 bool fPerformColorClearsAsDraws : 1; 501 bool fAvoidLargeIndexBufferDraws : 1; 502 bool fPerformStencilClearsAsDraws : 1; 503 bool fAllowCoverageCounting : 1; 504 bool fTransferFromBufferToTextureSupport : 1; 505 bool fTransferFromSurfaceToBufferSupport : 1; 506 bool fWritePixelsRowBytesSupport : 1; 507 bool fReadPixelsRowBytesSupport : 1; 508 bool fShouldCollapseSrcOverToSrcWhenAble : 1; 509 510 // Driver workaround 511 bool fDriverDisableCCPR : 1; 512 bool fDriverDisableMSAACCPR : 1; 513 bool fAvoidStencilBuffers : 1; 514 bool fAvoidWritePixelsFastPath : 1; 515 bool fRequiresManualFBBarrierAfterTessellatedStencilDraw : 1; 516 bool fNativeDrawIndexedIndirectIsBroken : 1; 517 518 // ANGLE performance workaround 519 bool fPreferVRAMUseOverFlushes : 1; 520 521 // On some platforms it's better to make more triangles than to use the sample mask (MSAA only). 522 bool fPreferTrianglesOverSampleMask : 1; 523 524 bool fFenceSyncSupport : 1; 525 bool fSemaphoreSupport : 1; 526 527 // Requires fence sync support in GL. 528 bool fCrossContextTextureSupport : 1; 529 530 // Not (yet) implemented in VK backend. 531 bool fDynamicStateArrayGeometryProcessorTextureSupport : 1; 532 533 BlendEquationSupport fBlendEquationSupport; 534 uint32_t fAdvBlendEqDisableFlags; 535 static_assert(kLast_GrBlendEquation < 32); 536 537 uint32_t fMapBufferFlags; 538 int fBufferMapThreshold; 539 540 int fMaxRenderTargetSize; 541 int fMaxPreferredRenderTargetSize; 542 int fMaxVertexAttributes; 543 int fMaxTextureSize; 544 int fMaxTileSize; 545 int fMaxWindowRectangles; 546 int fInternalMultisampleCount; 547 uint32_t fMaxPushConstantsSize = 0; 548 549 GrDriverBugWorkarounds fDriverBugWorkarounds; 550 551 private: 552 void applyOptionsOverrides(const GrContextOptions& options); 553 onApplyOptionsOverrides(const GrContextOptions &)554 virtual void onApplyOptionsOverrides(const GrContextOptions&) {} onDumpJSON(SkJSONWriter *)555 virtual void onDumpJSON(SkJSONWriter*) const {} 556 virtual bool onSurfaceSupportsWritePixels(const GrSurface*) const = 0; 557 virtual bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, 558 const SkIRect& srcRect, const SkIPoint& dstPoint) const = 0; 559 virtual GrBackendFormat onGetDefaultBackendFormat(GrColorType) const = 0; 560 561 // Backends should implement this if they have any extra requirements for use of window 562 // rectangles for a specific GrBackendRenderTarget outside of basic support. onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget &)563 virtual bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const { 564 return true; 565 } 566 567 virtual bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const = 0; 568 569 virtual SupportedRead onSupportedReadPixelsColorType(GrColorType srcColorType, 570 const GrBackendFormat& srcFormat, 571 GrColorType dstColorType) const = 0; 572 573 virtual GrSwizzle onGetReadSwizzle(const GrBackendFormat&, GrColorType) const = 0; 574 onGetDstSampleTypeForProxy(const GrRenderTargetProxy *)575 virtual GrDstSampleType onGetDstSampleTypeForProxy(const GrRenderTargetProxy*) const { 576 return GrDstSampleType::kAsTextureCopy; 577 } 578 579 bool fSuppressPrints : 1; 580 bool fWireframeMode : 1; 581 582 using INHERITED = SkRefCnt; 583 }; 584 585 #endif 586