Debian Codegraph @

src/gpu/ganesh/GrCaps.h

raw ◀ ▶
1 Debian patch touch this file
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/SkCapabilities.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkTypes.h"
14 #include "include/gpu/GpuTypes.h"
15 #include "include/gpu/ganesh/GrDriverBugWorkarounds.h"
16 #include "include/gpu/ganesh/GrTypes.h"
17 #include "include/private/base/SkMacros.h"
18 #include "include/private/base/SkTo.h"
19 #include "include/private/gpu/ganesh/GrTypesPriv.h"
20 #include "src/gpu/Blend.h"
21 #include "src/gpu/Swizzle.h"
22 #include "src/gpu/ganesh/GrSamplerState.h"
23 #include "src/gpu/ganesh/GrShaderCaps.h"
24 #include "src/gpu/ganesh/GrSurfaceProxy.h"
25
26 #include <algorithm>
27 #include <cstddef>
28 #include <cstdint>
29 #include <memory>
30 #include <string>
31 #include <string_view>
32 #include <tuple>
33 #include <vector>
34
35 class GrBackendFormat;
36 class GrBackendRenderTarget;
37 class GrProgramDesc;
38 class GrProgramInfo;
39 class GrRenderTarget;
40 class GrRenderTargetProxy;
41 class GrSurface;
42 class SkJSONWriter;
43 enum class SkTextureCompressionType;
44 struct GrContextOptions;
45 struct SkIRect;
46 struct SkISize;
47
48 namespace skgpu {
49 class KeyBuilder;
50 }
51 namespace GrTest {
52 struct TestFormatColorTypeCombination;
53 }
54
55 /**
56 * Represents the capabilities of a GrContext.
57 */
58 class GrCaps : public SkCapabilities {
59 public:
60 explicit GrCaps(const GrContextOptions&);
61
62 void dumpJSON(SkJSONWriter*) const;
63
64 const GrShaderCaps* shaderCaps() const { return fShaderCaps.get(); }
65
66 #if defined(GPU_TEST_UTILS)
67 std::string_view deviceName() const { return fDeviceName; }
68 #endif
69
70 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
71 /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
72 only for POT textures) */
73 bool mipmapSupport() const { return fMipmapSupport; }
74 /** Is anisotropic filtering supported. */
75 bool anisoSupport() const { return fAnisoSupport; }
76
77 bool gpuTracingSupport() const { return fGpuTracingSupport; }
78 bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
79 bool textureBarrierSupport() const { return fTextureBarrierSupport; }
80 bool sampleLocationsSupport() const { return fSampleLocationsSupport; }
81 bool drawInstancedSupport() const { return fDrawInstancedSupport; }
82 // Is there hardware support for indirect draws? (Ganesh always supports indirect draws as long
83 // as it can polyfill them with instanced calls, but this cap tells us if they are supported
84 // natively.)
85 bool nativeDrawIndirectSupport() const { return fNativeDrawIndirectSupport; }
86 bool useClientSideIndirectBuffers() const {
87 #ifdef SK_DEBUG
88 if (!fNativeDrawIndirectSupport || fNativeDrawIndexedIndirectIsBroken) {
89 // We might implement indirect draws with a polyfill, so the commands need to reside in
90 // CPU memory.
91 SkASSERT(fUseClientSideIndirectBuffers);
92 }
93 #endif
94 return fUseClientSideIndirectBuffers;
95 }
96 bool conservativeRasterSupport() const { return fConservativeRasterSupport; }
97 bool wireframeSupport() const { return fWireframeSupport; }
98 // This flag indicates that we never have to resolve MSAA. In practice, it means that we have
99 // an MSAA-render-to-texture extension: Any render target we create internally will use the
100 // extension, and any wrapped render target is the client's responsibility.
101 bool msaaResolvesAutomatically() const { return fMSAAResolvesAutomatically; }
102 // If true then when doing MSAA draws, we will prefer to discard the msaa attachment on load
103 // and stores. The use of this feature for specific draws depends on the render target having a
104 // resolve attachment, and if we need to load previous data the resolve attachment must be
105 // usable as an input attachment/texture. Otherwise we will just write out and store the msaa
106 // attachment like normal.
107 // This flag is similar to enabling gl render to texture for msaa rendering.
108 bool preferDiscardableMSAAAttachment() const { return fPreferDiscardableMSAAAttachment; }
109 bool halfFloatVertexAttributeSupport() const { return fHalfFloatVertexAttributeSupport; }
110
111 // Primitive restart functionality is core in ES 3.0, but using it will cause slowdowns on some
112 // systems. This cap is only set if primitive restart will improve performance.
113 bool usePrimitiveRestart() const { return fUsePrimitiveRestart; }
114
115 bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; }
116
•117 // The following 3 methods provide information that enables performance optimizations for tiler
118 // GPUs. Full clear operations (followed by discarding the content when finished) are more
119 // performant than load operations on these GPUs as they enable the hardware to initialize each
120 // tile with a constant value as opposed to loading each pixel from memory.
121 bool preferFullscreenClears() const { return fPreferFullscreenClears; }
122 // Should we discard stencil values after a render pass? (Tilers get better performance if we
123 // always load stencil buffers with a "clear" op, and then discard the content when finished.)
124 bool discardStencilValuesAfterRenderPass() const {
125 // b/160958008
126 return false;
127 #if 0
128 // This method is actually just a duplicate of preferFullscreenClears(), with a descriptive
129 // name for the sake of readability.
•130 return fDiscardStencilValuesAfterRenderPass;
131 #endif
132 }
133
•134 // Returns whether clearing an attachment is faster than loading the attachment. This is useful
135 // when you know the values are already cleared so it doesn't matter if we load or clear at the
136 // start of a render pass.
137 bool clearsAreFasterThanLoads() const { return fClearsAreFasterThanLoads; }
138
139 // D3D does not allow the refs or masks to differ on a two-sided stencil draw.
140 bool twoSidedStencilRefsAndMasksMustMatch() const {
141 return fTwoSidedStencilRefsAndMasksMustMatch;
142 }
143
144 bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; }
145
146 bool avoidStencilBuffers() const { return fAvoidStencilBuffers; }
147
148 bool avoidWritePixelsFastPath() const { return fAvoidWritePixelsFastPath; }
149
150 // glDrawElementsIndirect fails GrMeshTest on every Win10 Intel bot.
151 bool nativeDrawIndexedIndirectIsBroken() const { return fNativeDrawIndexedIndirectIsBroken; }
152
153 /**
154 * Indicates the capabilities of the fixed function blend unit.
155 */
156 enum BlendEquationSupport {
157 kBasic_BlendEquationSupport, //<! Support to select the operator that
158 // combines src and dst terms.
159 kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific
160 // SVG/PDF blend modes. Requires blend barriers.
161 kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not
162 // require blend barriers, and permits overlap.
163
164 kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
165 };
166
167 BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
168
169 bool advancedBlendEquationSupport() const {
170 return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
171 }
172
173 bool advancedCoherentBlendEquationSupport() const {
174 return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
175 }
176
177 bool isAdvancedBlendEquationDisabled(skgpu::BlendEquation equation) const {
178 SkASSERT(skgpu::BlendEquationIsAdvanced(equation));
179 SkASSERT(this->advancedBlendEquationSupport());
180 return SkToBool(fAdvBlendEqDisableFlags & (1 << static_cast<int>(equation)));
181 }
182
183 // On some GPUs it is a performance win to disable blending instead of doing src-over with a src
184 // alpha equal to 1. To disable blending we collapse src-over to src and the backends will
185 // handle the disabling of blending.
186 bool shouldCollapseSrcOverToSrcWhenAble() const {
187 return fShouldCollapseSrcOverToSrcWhenAble;
188 }
189
190 // When abandoning the GrDirectContext do we need to sync the GPU before we start abandoning
191 // resources.
192 bool mustSyncGpuDuringAbandon() const {
193 return fMustSyncGpuDuringAbandon;
194 }
195
196 // Shortcut for shaderCaps()->fReducedShaderMode.
197 bool reducedShaderMode() const { return this->shaderCaps()->fReducedShaderMode; }
198
199 /**
200 * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
201 * textures allows partial mappings or full mappings.
202 */
203 enum MapFlags {
204 kNone_MapFlags = 0x0, //<! Cannot map the resource.
205
206 kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
207 // the other flags to have meaning.
208 kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
209 kAsyncRead_MapFlag = 0x4, //<! Are maps for reading asynchronous WRT GrOpsRenderPass
210 // submitted to GrGpu.
211 };
212
213 // This returns the general mapping support for the GPU. However, even if this returns a flag
214 // that says buffers can be mapped, it does NOT mean that every buffer will be mappable. Thus
215 // calls of map should still check to see if a valid pointer was returned from the map call and
216 // handle fallbacks appropriately. If this does return kNone_MapFlags then all calls to map() on
217 // any buffer will fail.
218 uint32_t mapBufferFlags() const { return fMapBufferFlags; }
219
220 // Scratch textures not being reused means that those scratch textures
221 // that we upload to (i.e., don't have a render target) will not be
222 // recycled in the texture cache. This is to prevent ghosting by drivers
223 // (in particular for deferred architectures).
224 bool reuseScratchTextures() const { return fReuseScratchTextures; }
225 bool reuseScratchBuffers() const { return fReuseScratchBuffers; }
226
227 /// maximum number of attribute values per vertex
228 int maxVertexAttributes() const { return fMaxVertexAttributes; }
229
230 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
231
232 /** This is the largest render target size that can be used without incurring extra perfomance
233 cost. It is usually the max RT size, unless larger render targets are known to be slower. */
234 int maxPreferredRenderTargetSize() const { return fMaxPreferredRenderTargetSize; }
235
236 int maxTextureSize() const { return fMaxTextureSize; }
237
238 int maxWindowRectangles() const { return fMaxWindowRectangles; }
239
240 // Returns whether window rectangles are supported for the given backend render target.
241 bool isWindowRectanglesSupportedForRT(const GrBackendRenderTarget& rt) const {
242 return this->maxWindowRectangles() > 0 && this->onIsWindowRectanglesSupportedForRT(rt);
243 }
244
245 uint32_t maxPushConstantsSize() const { return fMaxPushConstantsSize; }
246
247 // Alignment requirement for row bytes in buffer<->texture transfers.
248 size_t transferBufferRowBytesAlignment() const { return fTransferBufferRowBytesAlignment; }
249
250 // Alignment requirement for offsets and size in buffer->buffer transfers.
251 size_t transferFromBufferToBufferAlignment() const {
252 return fTransferFromBufferToBufferAlignment;
253 }
254
255 // Alignment requirement for offset and size passed to in GrGpuBuffer::updateData when the
256 // preserve param is true.
257 size_t bufferUpdateDataPreserveAlignment() const {
258 return fBufferUpdateDataPreserveAlignment;
259 }
260
261 virtual bool isFormatSRGB(const GrBackendFormat&) const = 0;
262
263 bool isFormatCompressed(const GrBackendFormat& format) const;
264
265 // Can a texture be made with the GrBackendFormat and texture type, and then be bound and
266 // sampled in a shader.
267 virtual bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const = 0;
268
269 // Returns whether a texture of the given format can be copied to a texture of the same format.
270 virtual bool isFormatCopyable(const GrBackendFormat&) const = 0;
271
272 // Returns the maximum supported sample count for a format. 0 means the format is not renderable
273 // 1 means the format is renderable but doesn't support MSAA.
274 virtual int maxRenderTargetSampleCount(const GrBackendFormat&) const = 0;
275
276 // Returns the number of samples to use when performing draws to the given config with internal
277 // MSAA. If 0, Ganesh should not attempt to use internal multisampling.
278 int internalMultisampleCount(const GrBackendFormat& format) const {
279 return std::min(fInternalMultisampleCount, this->maxRenderTargetSampleCount(format));
280 }
281
282 virtual bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
283 int sampleCount = 1) const = 0;
284
285 virtual bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const = 0;
286
287 // Find a sample count greater than or equal to the requested count which is supported for a
288 // render target of the given format or 0 if no such sample count is supported. If the requested
289 // sample count is 1 then 1 will be returned if non-MSAA rendering is supported, otherwise 0.
290 // For historical reasons requestedCount==0 is handled identically to requestedCount==1.
291 virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const = 0;
292
293 /**
294 * Backends may have restrictions on what types of surfaces support GrGpu::writePixels().
295 * If this returns false then the caller should implement a fallback where a temporary texture
296 * is created, pixels are written to it, and then that is copied or drawn into the the surface.
297 */
298 bool surfaceSupportsWritePixels(const GrSurface*) const;
299
300 /**
301 * Indicates whether surface supports GrGpu::readPixels, must be copied, or cannot be read.
302 */
303 enum class SurfaceReadPixelsSupport {
304 /** GrGpu::readPixels is supported by the surface. */
305 kSupported,
306 /**
307 * GrGpu::readPixels is not supported by this surface but this surface can be drawn
308 * or copied to a Ganesh-created GrTextureType::kTexture2D and then that surface will be
309 * readable.
310 */
311 kCopyToTexture2D,
312 /**
313 * Not supported
314 */
315 kUnsupported,
316 };
317 /**
318 * Backends may have restrictions on what types of surfaces support GrGpu::readPixels(). We may
319 * either be able to read directly from the surface, read from a copy of the surface, or not
320 * read at all.
321 */
322 virtual SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const = 0;
323
324 struct SupportedWrite {
325 GrColorType fColorType;
326 // If the write is occurring using GrGpu::transferPixelsTo then this provides the
327 // minimum alignment of the offset into the transfer buffer.
328 size_t fOffsetAlignmentForTransferBuffer;
329 };
330
331 /**
332 * Given a dst pixel config and a src color type what color type must the caller coax the
333 * the data into in order to use GrGpu::writePixels().
334 */
335 virtual SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
336 const GrBackendFormat& surfaceFormat,
337 GrColorType srcColorType) const = 0;
338
339 struct SupportedRead {
340 GrColorType fColorType;
341 // If the read is occurring using GrGpu::transferPixelsFrom then this provides the
342 // minimum alignment of the offset into the transfer buffer.
343 size_t fOffsetAlignmentForTransferBuffer;
344 };
345
346 /**
347 * Given a src surface's color type and its backend format as well as a color type the caller
348 * would like read into, this provides a legal color type that the caller may pass to
349 * GrGpu::readPixels(). The returned color type may differ from the passed dstColorType, in
350 * which case the caller must convert the read pixel data (see GrConvertPixels). When converting
351 * to dstColorType the swizzle in the returned struct should be applied. The caller must check
352 * the returned color type for kUnknown.
353 */
354 SupportedRead supportedReadPixelsColorType(GrColorType srcColorType,
355 const GrBackendFormat& srcFormat,
356 GrColorType dstColorType) const;
357
358 /**
359 * Does GrGpu::writePixels() support a src buffer where the row bytes is not equal to bpp * w?
360 */
361 bool writePixelsRowBytesSupport() const { return fWritePixelsRowBytesSupport; }
362
363 /**
364 * Does GrGpu::transferPixelsTo() support a src buffer where the row bytes is not equal to
365 * bpp * w?
366 */
367 bool transferPixelsToRowBytesSupport() const { return fTransferPixelsToRowBytesSupport; }
368
369 /**
370 * Does GrGpu::readPixels() support a dst buffer where the row bytes is not equal to bpp * w?
371 */
372 bool readPixelsRowBytesSupport() const { return fReadPixelsRowBytesSupport; }
373
374 bool transferFromSurfaceToBufferSupport() const { return fTransferFromSurfaceToBufferSupport; }
375 bool transferFromBufferToTextureSupport() const { return fTransferFromBufferToTextureSupport; }
376 bool transferFromBufferToBufferSupport() const { return fTransferFromBufferToBufferSupport; }
377
378 bool suppressPrints() const { return fSuppressPrints; }
379
380 size_t bufferMapThreshold() const {
381 SkASSERT(fBufferMapThreshold >= 0);
382 return static_cast<size_t>(fBufferMapThreshold);
383 }
384
385 /** True in environments that will issue errors if memory uploaded to buffers
386 is not initialized (even if not read by draw calls). */
387 bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
388
389 /** For some environments, there is a performance or safety concern to not
390 initializing textures. For example, with WebGL and Firefox, there is a large
391 performance hit to not doing it.
392 */
393 bool shouldInitializeTextures() const { return fShouldInitializeTextures; }
394
395 /**
396 * When a new GrGpuBuffer is created is it known to contain all zero bytes?
397 */
398 bool buffersAreInitiallyZero() const { return fBuffersAreInitiallyZero; }
399
400 /** Returns true if the given backend supports importing AHardwareBuffers via the
401 * GrAHardwarebufferImageGenerator. This will only ever be supported on Android devices with API
402 * level >= 26.
403 * */
404 bool supportsAHardwareBufferImages() const { return fSupportsAHardwareBufferImages; }
405
406 bool wireframeMode() const { return fWireframeMode; }
407
408 /** Supports using GrSemaphores. */
409 bool semaphoreSupport() const { return fSemaphoreSupport; }
410
411 /** Supports using GrBackendSemaphore as "signal" semaphores or for waiting. See also
412 * GrFlushInfo and GrDirectContext. */
413 bool backendSemaphoreSupport() const { return fBackendSemaphoreSupport; }
414
415 /** Supports async callback for finishedProcs */
416 bool finishedProcAsyncCallbackSupport() const { return fFinishedProcAsyncCallbackSupport; }
417
418 bool crossContextTextureSupport() const { return fCrossContextTextureSupport; }
419 /**
420 * Returns whether or not we will be able to do a copy given the passed in params
421 */
422 bool canCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect,
423 const GrSurfaceProxy* src, const SkIRect& srcRect) const;
424
425 bool dynamicStateArrayGeometryProcessorTextureSupport() const {
426 return fDynamicStateArrayGeometryProcessorTextureSupport;
427 }
428
429 bool supportsProtectedContent() const { return fSupportsProtectedContent; }
430
431 // Not all backends support clearing with a scissor test (e.g. Metal), this will always
432 // return true if performColorClearsAsDraws() returns true.
433 bool performPartialClearsAsDraws() const {
434 return fPerformColorClearsAsDraws || fPerformPartialClearsAsDraws;
435 }
436
437 // Many drivers have issues with color clears.
438 bool performColorClearsAsDraws() const { return fPerformColorClearsAsDraws; }
439
440 bool avoidLargeIndexBufferDraws() const { return fAvoidLargeIndexBufferDraws; }
441
442 /// Adreno 4xx devices experience an issue when there are a large number of stencil clip bit
443 /// clears. The minimal repro steps are not precisely known but drawing a rect with a stencil
444 /// op instead of using glClear seems to resolve the issue.
445 bool performStencilClearsAsDraws() const { return fPerformStencilClearsAsDraws; }
446
447 // Should we disable TessellationPathRenderer due to a faulty driver?
448 bool disableTessellationPathRenderer() const { return fDisableTessellationPathRenderer; }
449
450 // Returns how to sample the dst values for the passed in GrRenderTargetProxy.
451 GrDstSampleFlags getDstSampleFlagsForProxy(const GrRenderTargetProxy*, bool drawUsesMSAA) const;
452
453 /**
454 * This is used to try to ensure a successful copy a dst in order to perform shader-based
455 * blending.
456 *
457 * fRectsMustMatch will be set to true if the copy operation must ensure that the src and dest
458 * rects are identical.
459 *
460 * fMustCopyWholeSrc will be set to true if copy rect must equal src's bounds.
461 *
462 * Caller will detect cases when copy cannot succeed and try copy-as-draw as a fallback.
463 */
464 struct DstCopyRestrictions {
465 GrSurfaceProxy::RectsMustMatch fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kNo;
466 bool fMustCopyWholeSrc = false;
467 };
468 virtual DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src,
469 GrColorType ct) const {
470 return {};
471 }
472
473 bool validateSurfaceParams(const SkISize&,
474 const GrBackendFormat&,
475 GrRenderable renderable,
476 int renderTargetSampleCnt,
477 skgpu::Mipmapped,
478 GrTextureType) const;
479
480 bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat& format) const;
481
482 /** These are used when creating a new texture internally. */
483 GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const;
484
485 virtual GrBackendFormat getBackendFormatFromCompressionType(SkTextureCompressionType) const = 0;
486
487 /**
488 * The CLAMP_TO_BORDER wrap mode for texture coordinates was added to desktop GL in 1.3, and
489 * GLES 3.2, but is also available in extensions. Vulkan and Metal always have support.
490 */
491 bool clampToBorderSupport() const { return fClampToBorderSupport; }
492
493 /**
494 * Returns the skgpu::Swizzle to use when sampling or reading back from a texture with the
495 * passed in GrBackendFormat and GrColorType.
496 */
497 skgpu::Swizzle getReadSwizzle(const GrBackendFormat& format, GrColorType colorType) const;
498
499 /**
500 * Returns the skgpu::Swizzle to use when writing colors to a surface with the passed in
501 * GrBackendFormat and GrColorType.
502 */
503 virtual skgpu::Swizzle getWriteSwizzle(const GrBackendFormat&, GrColorType) const = 0;
504
505 virtual uint64_t computeFormatKey(const GrBackendFormat&) const = 0;
506
507 skgpu::GpuStatsFlags supportedGpuStats() const { return fSupportedGpuStats; }
508
509 const GrDriverBugWorkarounds& workarounds() const { return fDriverBugWorkarounds; }
510
511 /**
512 * Adds fields to the key to represent the sampler that will be created for the passed
513 * in parameters. Currently this extra keying is only needed when building a vulkan pipeline
514 * with immutable samplers.
515 */
516 virtual void addExtraSamplerKey(skgpu::KeyBuilder*,
517 GrSamplerState,
518 const GrBackendFormat&) const {}
519
520 enum class ProgramDescOverrideFlags {
521 kNone = 0,
522 // If using discardable msaa surfaces in vulkan, when we break up a render pass for an
523 // inline upload, we must do a load msaa subpass for the second render pass. However, if the
524 // original render pass did not have this load subpass (e.g. clear or discard load op), then
525 // all the GrProgramInfos for draws that end up in the second render pass will have been
526 // recorded thinking they will be in a render pass with only 1 subpass. Thus we add an
527 // override flag to the makeDesc call to force the actually VkPipeline that gets created to
528 // be created using a render pass with 2 subpasses. We do miss on the pre-compile with this
529 // approach, but inline uploads are very rare and already slow.
530 kVulkanHasResolveLoadSubpass = 0x1,
531 };
532 SK_DECL_BITFIELD_CLASS_OPS_FRIENDS(ProgramDescOverrideFlags);
533
534
535 virtual GrProgramDesc makeDesc(
536 GrRenderTarget*, const GrProgramInfo&,
537 ProgramDescOverrideFlags overrideFlags = ProgramDescOverrideFlags::kNone) const = 0;
538
539 // This method specifies, for each backend, the extra properties of a RT when Ganesh creates one
540 // internally. For example, for Vulkan, Ganesh always creates RTs that can be used as input
541 // attachments.
542 virtual GrInternalSurfaceFlags getExtraSurfaceFlagsForDeferredRT() const {
543 return GrInternalSurfaceFlags::kNone;
544 }
545
546 bool supportsDynamicMSAA(const GrRenderTargetProxy*) const;
547
548 virtual bool dmsaaResolveCanBeUsedAsTextureInSameRenderPass() const { return true; }
549
550 // skbug.com/40042245. Task reordering is disabled for some GPUs on GL due to driver bugs.
551 bool avoidReorderingRenderTasks() const {
552 return fAvoidReorderingRenderTasks;
553 }
554
555 bool avoidDithering() const {
556 return fAvoidDithering;
557 }
558
559 bool disablePerspectiveSDFText() const {
560 return fDisablePerspectiveSDFText;
561 }
562
563 // anglebug.com/7796
564 bool avoidLineDraws() const { return fAvoidLineDraws; }
565
566 /**
567 * Checks whether the passed color type is renderable. If so, the same color type is passed
568 * back along with the default format used for the color type. If not, provides an alternative
569 * (perhaps lower bit depth and/or unorm instead of float) color type that is supported
570 * along with it's default format or kUnknown if there no renderable fallback format.
571 */
572 std::tuple<GrColorType, GrBackendFormat> getFallbackColorTypeAndFormat(GrColorType,
573 int sampleCount) const;
574
575 #if defined(GPU_TEST_UTILS)
576 virtual std::vector<GrTest::TestFormatColorTypeCombination> getTestingCombinations() const = 0;
577 #endif
578
579 protected:
580 // Subclasses must call this at the end of their init method in order to do final processing on
581 // the caps (including overrides requested by the client).
582 // NOTE: this method will only reduce the caps, never expand them.
583 void finishInitialization(const GrContextOptions& options);
584
585 #if defined(GPU_TEST_UTILS)
586 void setDeviceName(const char* n) {
587 fDeviceName = n;
588 }
589 #endif
590
591 virtual bool onSupportsDynamicMSAA(const GrRenderTargetProxy*) const { return false; }
592
593 std::unique_ptr<GrShaderCaps> fShaderCaps;
594
595 bool fNPOTTextureTileSupport : 1;
596 bool fMipmapSupport : 1;
597 bool fAnisoSupport : 1;
598 bool fReuseScratchTextures : 1;
599 bool fReuseScratchBuffers : 1;
600 bool fGpuTracingSupport : 1;
601 bool fOversizedStencilSupport : 1;
602 bool fTextureBarrierSupport : 1;
603 bool fSampleLocationsSupport : 1;
604 bool fDrawInstancedSupport : 1;
605 bool fNativeDrawIndirectSupport : 1;
606 bool fUseClientSideIndirectBuffers : 1;
607 bool fConservativeRasterSupport : 1;
608 bool fWireframeSupport : 1;
609 bool fMSAAResolvesAutomatically : 1;
610 bool fPreferDiscardableMSAAAttachment : 1;
611 bool fUsePrimitiveRestart : 1;
612 bool fPreferClientSideDynamicBuffers : 1;
613 bool fPreferFullscreenClears : 1;
•614 bool fDiscardStencilValuesAfterRenderPass : 1;
615 bool fClearsAreFasterThanLoads : 1;
616 bool fTwoSidedStencilRefsAndMasksMustMatch : 1;
617 bool fMustClearUploadedBufferData : 1;
618 bool fBuffersAreInitiallyZero : 1;
619 bool fShouldInitializeTextures : 1;
620 bool fSupportsAHardwareBufferImages : 1;
621 bool fHalfFloatVertexAttributeSupport : 1;
622 bool fClampToBorderSupport : 1;
623 bool fPerformPartialClearsAsDraws : 1;
624 bool fPerformColorClearsAsDraws : 1;
625 bool fAvoidLargeIndexBufferDraws : 1;
626 bool fPerformStencilClearsAsDraws : 1;
627 bool fTransferFromBufferToTextureSupport : 1;
628 bool fTransferFromSurfaceToBufferSupport : 1;
629 bool fTransferFromBufferToBufferSupport : 1;
630 bool fWritePixelsRowBytesSupport : 1;
631 bool fTransferPixelsToRowBytesSupport : 1;
632 bool fReadPixelsRowBytesSupport : 1;
633 bool fShouldCollapseSrcOverToSrcWhenAble : 1;
634 bool fMustSyncGpuDuringAbandon : 1;
635
636 // Driver workaround
637 bool fDisableTessellationPathRenderer : 1;
638 bool fAvoidStencilBuffers : 1;
639 bool fAvoidWritePixelsFastPath : 1;
640 bool fNativeDrawIndexedIndirectIsBroken : 1;
641 bool fAvoidReorderingRenderTasks : 1;
642 bool fAvoidDithering : 1;
643 bool fDisablePerspectiveSDFText : 1;
644 bool fAvoidLineDraws : 1;
645
646 // ANGLE performance workaround
647 bool fPreferVRAMUseOverFlushes : 1;
648
649 bool fSemaphoreSupport : 1;
650 bool fBackendSemaphoreSupport : 1;
651 bool fFinishedProcAsyncCallbackSupport : 1;
652
653 // Requires fence sync support in GL.
654 bool fCrossContextTextureSupport : 1;
655
656 // Not (yet) implemented in VK backend.
657 bool fDynamicStateArrayGeometryProcessorTextureSupport : 1;
658
659 bool fSupportsProtectedContent : 1;
660
661 BlendEquationSupport fBlendEquationSupport;
662 uint32_t fAdvBlendEqDisableFlags;
663 static_assert(static_cast<int>(skgpu::BlendEquation::kLast) < 32);
664
665 uint32_t fMapBufferFlags;
666 int fBufferMapThreshold;
667
668 int fMaxRenderTargetSize;
669 int fMaxPreferredRenderTargetSize;
670 int fMaxVertexAttributes;
671 int fMaxTextureSize;
672 int fMaxWindowRectangles;
673 int fInternalMultisampleCount;
674 uint32_t fMaxPushConstantsSize = 0;
675 size_t fTransferBufferRowBytesAlignment = 1;
676 size_t fTransferFromBufferToBufferAlignment = 1;
677 size_t fBufferUpdateDataPreserveAlignment = 1;
678
679 skgpu::GpuStatsFlags fSupportedGpuStats = skgpu::GpuStatsFlags::kNone;
680
681 GrDriverBugWorkarounds fDriverBugWorkarounds;
682
683 #if defined(GPU_TEST_UTILS)
684 std::string fDeviceName;
685 #endif
686
687 private:
688 void applyOptionsOverrides(const GrContextOptions& options);
689
690 virtual void onApplyOptionsOverrides(const GrContextOptions&) {}
691 virtual void onDumpJSON(SkJSONWriter*) const {}
692 virtual bool onSurfaceSupportsWritePixels(const GrSurface*) const = 0;
693 virtual bool onCanCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect,
694 const GrSurfaceProxy* src, const SkIRect& srcRect) const = 0;
695 virtual GrBackendFormat onGetDefaultBackendFormat(GrColorType) const = 0;
696
697 // Backends should implement this if they have any extra requirements for use of window
698 // rectangles for a specific GrBackendRenderTarget outside of basic support.
699 virtual bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const {
700 return true;
701 }
702
703 virtual bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const = 0;
704
705 virtual SupportedRead onSupportedReadPixelsColorType(GrColorType srcColorType,
706 const GrBackendFormat& srcFormat,
707 GrColorType dstColorType) const = 0;
708
709 virtual skgpu::Swizzle onGetReadSwizzle(const GrBackendFormat&, GrColorType) const = 0;
710
711 virtual GrDstSampleFlags onGetDstSampleFlagsForProxy(const GrRenderTargetProxy*) const {
712 return GrDstSampleFlags::kNone;
713 }
714
715 bool fSuppressPrints : 1;
716 bool fWireframeMode : 1;
717
718 using INHERITED = SkRefCnt;
719 };
720
721 SK_MAKE_BITFIELD_CLASS_OPS(GrCaps::ProgramDescOverrideFlags)
722
723 #endif