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