Coverage Report

Created: 2021-08-22 09:07

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