blob: 65df09251ac1fd7829ed9a0594b57fd6626f182a [file] [log] [blame]
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001
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 */
bsalomon4b91f762015-05-19 09:29:46 -07008#ifndef GrCaps_DEFINED
9#define GrCaps_DEFINED
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000010
Brian Salomonc5886032017-07-19 11:48:05 -040011#include "../private/GrTypesPriv.h"
cdalton1dd05422015-06-12 09:01:18 -070012#include "GrBlend.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050013#include "GrShaderCaps.h"
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +000014#include "SkRefCnt.h"
15#include "SkString.h"
16
bsalomon682c2692015-05-22 14:01:46 -070017struct GrContextOptions;
Robert Phillipsbf25d432017-04-07 10:08:53 -040018class GrRenderTargetProxy;
Brian Osman71a18892017-08-10 10:23:25 -040019class SkJSONWriter;
jvanverthe9c0fc62015-04-29 11:18:05 -070020
21/**
bsalomon4b91f762015-05-19 09:29:46 -070022 * Represents the capabilities of a GrContext.
jvanverthe9c0fc62015-04-29 11:18:05 -070023 */
bsalomon4b91f762015-05-19 09:29:46 -070024class GrCaps : public SkRefCnt {
jvanverthe9c0fc62015-04-29 11:18:05 -070025public:
bsalomon682c2692015-05-22 14:01:46 -070026 GrCaps(const GrContextOptions&);
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000027
Brian Osman71a18892017-08-10 10:23:25 -040028 void dumpJSON(SkJSONWriter*) const;
29
Brian Salomon94efbf52016-11-29 13:43:05 -050030 const GrShaderCaps* shaderCaps() const { return fShaderCaps.get(); }
jvanverthe9c0fc62015-04-29 11:18:05 -070031
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000032 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
commit-bot@chromium.org47442312013-12-19 16:18:01 +000033 /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
34 only for POT textures) */
35 bool mipMapSupport() const { return fMipMapSupport; }
brianosman64d094d2016-03-25 06:01:59 -070036
37 /**
38 * Skia convention is that a device only has sRGB support if it supports sRGB formats for both
39 * textures and framebuffers. In addition:
40 * Decoding to linear of an sRGB texture can be disabled.
brianosman64d094d2016-03-25 06:01:59 -070041 */
brianosmana6359362016-03-21 06:55:37 -070042 bool srgbSupport() const { return fSRGBSupport; }
brianosman35b784d2016-05-05 11:52:53 -070043 /**
44 * Is there support for enabling/disabling sRGB writes for sRGB-capable color buffers?
45 */
46 bool srgbWriteControl() const { return fSRGBWriteControl; }
Brian Osman57bc3ea2017-07-27 09:58:11 -040047 bool srgbDecodeDisableSupport() const { return fSRGBDecodeDisableSupport; }
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000048 bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000049 bool gpuTracingSupport() const { return fGpuTracingSupport; }
bsalomond08ea5f2015-02-20 06:58:13 -080050 bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
cdaltonfd4167d2015-04-21 11:45:56 -070051 bool textureBarrierSupport() const { return fTextureBarrierSupport; }
cdaltoneb79eea2016-02-26 10:39:34 -080052 bool sampleLocationsSupport() const { return fSampleLocationsSupport; }
csmartdalton2b5f2cb2016-06-10 14:06:32 -070053 bool multisampleDisableSupport() const { return fMultisampleDisableSupport; }
Chris Dalton1d616352017-05-31 12:51:23 -060054 bool instanceAttribSupport() const { return fInstanceAttribSupport; }
egdanieleed519e2016-01-15 11:36:18 -080055 bool usesMixedSamples() const { return fUsesMixedSamples; }
csmartdalton485a1202016-07-13 10:16:32 -070056 bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; }
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +000057
bsalomon63b21962014-11-05 07:05:34 -080058 bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
bsalomonbabafcc2016-02-16 11:36:47 -080059
robertphillips63926682015-08-20 09:39:02 -070060 bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; }
61
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000062 /**
csmartdaltone0d36292016-07-29 08:14:20 -070063 * Indicates the level of support for gr_instanced::* functionality. A higher level includes
64 * all functionality from the levels below it.
65 */
66 enum class InstancedSupport {
67 kNone,
68 kBasic,
69 kMultisampled,
70 kMixedSampled
71 };
72
73 InstancedSupport instancedSupport() const { return fInstancedSupport; }
74
75 bool avoidInstancedDrawsToFPTargets() const { return fAvoidInstancedDrawsToFPTargets; }
76
Eric Karl5c779752017-05-08 12:02:07 -070077 bool avoidStencilBuffers() const { return fAvoidStencilBuffers; }
78
csmartdaltone0d36292016-07-29 08:14:20 -070079 /**
cdalton8917d622015-05-06 13:40:21 -070080 * Indicates the capabilities of the fixed function blend unit.
81 */
82 enum BlendEquationSupport {
83 kBasic_BlendEquationSupport, //<! Support to select the operator that
84 // combines src and dst terms.
85 kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific
86 // SVG/PDF blend modes. Requires blend barriers.
87 kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not
88 // require blend barriers, and permits overlap.
89
90 kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
91 };
92
93 BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
94
95 bool advancedBlendEquationSupport() const {
96 return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
97 }
98
99 bool advancedCoherentBlendEquationSupport() const {
100 return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
101 }
102
cdalton1dd05422015-06-12 09:01:18 -0700103 bool canUseAdvancedBlendEquation(GrBlendEquation equation) const {
104 SkASSERT(GrBlendEquationIsAdvanced(equation));
105 return SkToBool(fAdvBlendEqBlacklist & (1 << equation));
106 }
107
cdalton8917d622015-05-06 13:40:21 -0700108 /**
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000109 * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
110 * textures allows partial mappings or full mappings.
111 */
112 enum MapFlags {
113 kNone_MapFlags = 0x0, //<! Cannot map the resource.
114
115 kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
116 // the other flags to have meaning.k
117 kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
118 };
119
120 uint32_t mapBufferFlags() const { return fMapBufferFlags; }
121
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000122 // Scratch textures not being reused means that those scratch textures
skia.committer@gmail.com7ed98df2013-10-31 07:01:53 +0000123 // that we upload to (i.e., don't have a render target) will not be
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000124 // recycled in the texture cache. This is to prevent ghosting by drivers
125 // (in particular for deferred architectures).
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000126 bool reuseScratchTextures() const { return fReuseScratchTextures; }
robertphillips1b8e1b52015-06-24 06:54:10 -0700127 bool reuseScratchBuffers() const { return fReuseScratchBuffers; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000128
bsalomon7dbd45d2016-03-23 10:40:53 -0700129 /// maximum number of attribute values per vertex
130 int maxVertexAttributes() const { return fMaxVertexAttributes; }
131
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000132 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
133 int maxTextureSize() const { return fMaxTextureSize; }
bsalomon8c07b7a2015-11-02 11:36:52 -0800134 /** This is the maximum tile size to use by GPU devices for rendering sw-backed images/bitmaps.
135 It is usually the max texture size, unless we're overriding it for testing. */
136 int maxTileSize() const { SkASSERT(fMaxTileSize <= fMaxTextureSize); return fMaxTileSize; }
bsalomonc59a1df2015-06-01 07:13:42 -0700137
cdaltonaf8bc7d2016-02-05 09:35:20 -0800138 int maxRasterSamples() const { return fMaxRasterSamples; }
Greg Daniel81e7bf82017-07-19 14:47:42 -0400139
140 // Find a sample count greater than or equal to the requested count which is supported for a
141 // color buffer of the given config. If MSAA is not support for the config we will return 0.
142 virtual int getSampleCount(int requestedCount, GrPixelConfig config) const = 0;
egdanieleed519e2016-01-15 11:36:18 -0800143
csmartdalton9bc11872016-08-09 12:42:47 -0700144 int maxWindowRectangles() const { return fMaxWindowRectangles; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000145
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400146 virtual bool isConfigTexturable(GrPixelConfig) const = 0;
bsalomon41e4384e2016-01-08 09:12:44 -0800147 virtual bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const = 0;
Brian Salomonf9f45122016-11-29 11:59:17 -0500148 virtual bool canConfigBeImageStorage(GrPixelConfig config) const = 0;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000149
robertphillipscaef3452015-11-11 13:18:11 -0800150 bool suppressPrints() const { return fSuppressPrints; }
151
cdalton397536c2016-03-25 12:15:03 -0700152 size_t bufferMapThreshold() const {
153 SkASSERT(fBufferMapThreshold >= 0);
154 return fBufferMapThreshold;
joshualitt7224c862015-05-29 06:46:47 -0700155 }
bsalomon682c2692015-05-22 14:01:46 -0700156
egdaniel51c8d402015-08-06 10:54:13 -0700157 bool fullClearIsFree() const { return fFullClearIsFree; }
158
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400159 /** True in environments that will issue errors if memory uploaded to buffers
bsalomon7dea7b72015-08-19 08:26:51 -0700160 is not initialized (even if not read by draw calls). */
161 bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
162
Jim Van Verthfbdc0802017-05-02 16:15:53 -0400163 bool wireframeMode() const { return fWireframeMode; }
164
ethannicholas28ef4452016-03-25 09:26:03 -0700165 bool sampleShadingSupport() const { return fSampleShadingSupport; }
166
jvanverth84741b32016-09-30 08:39:02 -0700167 bool fenceSyncSupport() const { return fFenceSyncSupport; }
Brian Osman2c2bc112017-02-28 10:02:49 -0500168 bool crossContextTextureSupport() const { return fCrossContextTextureSupport; }
jvanverth84741b32016-09-30 08:39:02 -0700169
Brian Salomon467921e2017-03-06 16:17:12 -0500170 /**
171 * This is can be called before allocating a texture to be a dst for copySurface. This is only
Robert Phillipsbf25d432017-04-07 10:08:53 -0400172 * used for doing dst copies needed in blends, thus the src is always a GrRenderTargetProxy. It
173 * will populate the origin, config, and flags fields of the desc such that copySurface can
Eric Karl74480882017-04-03 14:49:05 -0700174 * efficiently succeed. rectsMustMatch will be set to true if the copy operation must ensure
175 * that the src and dest rects are identical. disallowSubrect will be set to true if copy rect
176 * must equal src's bounds.
Brian Salomon467921e2017-03-06 16:17:12 -0500177 */
Robert Phillipsbf25d432017-04-07 10:08:53 -0400178 virtual bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Eric Karl74480882017-04-03 14:49:05 -0700179 bool* rectsMustMatch, bool* disallowSubrect) const = 0;
Brian Salomon467921e2017-03-06 16:17:12 -0500180
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000181protected:
bsalomon4ee6bd82015-05-27 13:23:23 -0700182 /** Subclasses must call this at the end of their constructors in order to apply caps
183 overrides requested by the client. Note that overrides will only reduce the caps never
184 expand them. */
185 void applyOptionsOverrides(const GrContextOptions& options);
186
bungeman6bd52842016-10-27 09:30:08 -0700187 sk_sp<GrShaderCaps> fShaderCaps;
jvanverthe9c0fc62015-04-29 11:18:05 -0700188
joshualitt83bc2292015-06-18 14:18:02 -0700189 bool fNPOTTextureTileSupport : 1;
190 bool fMipMapSupport : 1;
brianosmana6359362016-03-21 06:55:37 -0700191 bool fSRGBSupport : 1;
brianosman35b784d2016-05-05 11:52:53 -0700192 bool fSRGBWriteControl : 1;
Brian Osman57bc3ea2017-07-27 09:58:11 -0400193 bool fSRGBDecodeDisableSupport : 1;
joshualitt83bc2292015-06-18 14:18:02 -0700194 bool fDiscardRenderTargetSupport : 1;
195 bool fReuseScratchTextures : 1;
robertphillips1b8e1b52015-06-24 06:54:10 -0700196 bool fReuseScratchBuffers : 1;
joshualitt83bc2292015-06-18 14:18:02 -0700197 bool fGpuTracingSupport : 1;
joshualitt83bc2292015-06-18 14:18:02 -0700198 bool fOversizedStencilSupport : 1;
199 bool fTextureBarrierSupport : 1;
cdaltoneb79eea2016-02-26 10:39:34 -0800200 bool fSampleLocationsSupport : 1;
csmartdalton2b5f2cb2016-06-10 14:06:32 -0700201 bool fMultisampleDisableSupport : 1;
Chris Dalton1d616352017-05-31 12:51:23 -0600202 bool fInstanceAttribSupport : 1;
egdanieleed519e2016-01-15 11:36:18 -0800203 bool fUsesMixedSamples : 1;
csmartdalton485a1202016-07-13 10:16:32 -0700204 bool fPreferClientSideDynamicBuffers : 1;
egdaniel51c8d402015-08-06 10:54:13 -0700205 bool fFullClearIsFree : 1;
bsalomon7dea7b72015-08-19 08:26:51 -0700206 bool fMustClearUploadedBufferData : 1;
robertphillips1b8e1b52015-06-24 06:54:10 -0700207
bsalomon63b21962014-11-05 07:05:34 -0800208 // Driver workaround
joshualitt83bc2292015-06-18 14:18:02 -0700209 bool fUseDrawInsteadOfClear : 1;
csmartdaltone0d36292016-07-29 08:14:20 -0700210 bool fAvoidInstancedDrawsToFPTargets : 1;
Eric Karl5c779752017-05-08 12:02:07 -0700211 bool fAvoidStencilBuffers : 1;
bsalomon63b21962014-11-05 07:05:34 -0800212
robertphillips63926682015-08-20 09:39:02 -0700213 // ANGLE workaround
214 bool fPreferVRAMUseOverFlushes : 1;
215
ethannicholas28ef4452016-03-25 09:26:03 -0700216 bool fSampleShadingSupport : 1;
jvanverth84741b32016-09-30 08:39:02 -0700217 // TODO: this may need to be an enum to support different fence types
218 bool fFenceSyncSupport : 1;
ethannicholas28ef4452016-03-25 09:26:03 -0700219
Brian Osman2c2bc112017-02-28 10:02:49 -0500220 // Vulkan doesn't support this (yet) and some drivers have issues, too
221 bool fCrossContextTextureSupport : 1;
222
csmartdaltone0d36292016-07-29 08:14:20 -0700223 InstancedSupport fInstancedSupport;
224
cdalton8917d622015-05-06 13:40:21 -0700225 BlendEquationSupport fBlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -0700226 uint32_t fAdvBlendEqBlacklist;
227 GR_STATIC_ASSERT(kLast_GrBlendEquation < 32);
228
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000229 uint32_t fMapBufferFlags;
cdalton397536c2016-03-25 12:15:03 -0700230 int fBufferMapThreshold;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000231
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000232 int fMaxRenderTargetSize;
bsalomon7dbd45d2016-03-23 10:40:53 -0700233 int fMaxVertexAttributes;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000234 int fMaxTextureSize;
bsalomon8c07b7a2015-11-02 11:36:52 -0800235 int fMaxTileSize;
egdanieleed519e2016-01-15 11:36:18 -0800236 int fMaxColorSampleCount;
237 int fMaxStencilSampleCount;
cdaltonaf8bc7d2016-02-05 09:35:20 -0800238 int fMaxRasterSamples;
csmartdalton9bc11872016-08-09 12:42:47 -0700239 int fMaxWindowRectangles;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000240
egdanielbc127a32014-09-19 12:07:43 -0700241private:
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400242 virtual void onApplyOptionsOverrides(const GrContextOptions&) {}
Brian Osman71a18892017-08-10 10:23:25 -0400243 virtual void onDumpJSON(SkJSONWriter*) const {}
egdanielb7e7d572015-11-04 04:23:53 -0800244
robertphillipscaef3452015-11-11 13:18:11 -0800245 bool fSuppressPrints : 1;
Jim Van Verthfbdc0802017-05-02 16:15:53 -0400246 bool fWireframeMode : 1;
bsalomon682c2692015-05-22 14:01:46 -0700247
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000248 typedef SkRefCnt INHERITED;
249};
250
251#endif