blob: 16a4ca9747eb6d062252dcf2490c1a7611565322 [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
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +000011#include "GrTypes.h"
bsalomon17168df2014-12-09 09:00:49 -080012#include "GrTypesPriv.h"
cdalton1dd05422015-06-12 09:01:18 -070013#include "GrBlend.h"
bsalomon17168df2014-12-09 09:00:49 -080014#include "GrShaderVar.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050015#include "GrShaderCaps.h"
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +000016#include "SkRefCnt.h"
17#include "SkString.h"
18
bsalomon682c2692015-05-22 14:01:46 -070019struct GrContextOptions;
20
jvanverthe9c0fc62015-04-29 11:18:05 -070021
22/**
bsalomon4b91f762015-05-19 09:29:46 -070023 * Represents the capabilities of a GrContext.
jvanverthe9c0fc62015-04-29 11:18:05 -070024 */
bsalomon4b91f762015-05-19 09:29:46 -070025class GrCaps : public SkRefCnt {
jvanverthe9c0fc62015-04-29 11:18:05 -070026public:
bsalomon682c2692015-05-22 14:01:46 -070027 GrCaps(const GrContextOptions&);
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000028
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +000029 virtual SkString dump() const;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000030
Brian Salomon94efbf52016-11-29 13:43:05 -050031 const GrShaderCaps* shaderCaps() const { return fShaderCaps.get(); }
jvanverthe9c0fc62015-04-29 11:18:05 -070032
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000033 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
commit-bot@chromium.org47442312013-12-19 16:18:01 +000034 /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
35 only for POT textures) */
36 bool mipMapSupport() const { return fMipMapSupport; }
brianosman64d094d2016-03-25 06:01:59 -070037
38 /**
39 * Skia convention is that a device only has sRGB support if it supports sRGB formats for both
40 * textures and framebuffers. In addition:
41 * Decoding to linear of an sRGB texture can be disabled.
brianosman64d094d2016-03-25 06:01:59 -070042 */
brianosmana6359362016-03-21 06:55:37 -070043 bool srgbSupport() const { return fSRGBSupport; }
brianosman35b784d2016-05-05 11:52:53 -070044 /**
45 * Is there support for enabling/disabling sRGB writes for sRGB-capable color buffers?
46 */
47 bool srgbWriteControl() const { return fSRGBWriteControl; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000048 bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; }
49 bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; }
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000050 bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000051 bool gpuTracingSupport() const { return fGpuTracingSupport; }
krajcevski786978162014-07-30 11:25:44 -070052 bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; }
bsalomond08ea5f2015-02-20 06:58:13 -080053 bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
cdaltonfd4167d2015-04-21 11:45:56 -070054 bool textureBarrierSupport() const { return fTextureBarrierSupport; }
cdaltoneb79eea2016-02-26 10:39:34 -080055 bool sampleLocationsSupport() const { return fSampleLocationsSupport; }
csmartdalton2b5f2cb2016-06-10 14:06:32 -070056 bool multisampleDisableSupport() const { return fMultisampleDisableSupport; }
egdanieleed519e2016-01-15 11:36:18 -080057 bool usesMixedSamples() const { return fUsesMixedSamples; }
csmartdalton485a1202016-07-13 10:16:32 -070058 bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; }
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +000059
bsalomon63b21962014-11-05 07:05:34 -080060 bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
joshualitt83bc2292015-06-18 14:18:02 -070061 bool useDrawInsteadOfPartialRenderTargetWrite() const {
62 return fUseDrawInsteadOfPartialRenderTargetWrite;
63 }
bsalomon63b21962014-11-05 07:05:34 -080064
bsalomonbabafcc2016-02-16 11:36:47 -080065 bool useDrawInsteadOfAllRenderTargetWrites() const {
66 return fUseDrawInsteadOfAllRenderTargetWrites;
67 }
68
robertphillips63926682015-08-20 09:39:02 -070069 bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; }
70
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000071 /**
csmartdaltone0d36292016-07-29 08:14:20 -070072 * Indicates the level of support for gr_instanced::* functionality. A higher level includes
73 * all functionality from the levels below it.
74 */
75 enum class InstancedSupport {
76 kNone,
77 kBasic,
78 kMultisampled,
79 kMixedSampled
80 };
81
82 InstancedSupport instancedSupport() const { return fInstancedSupport; }
83
84 bool avoidInstancedDrawsToFPTargets() const { return fAvoidInstancedDrawsToFPTargets; }
85
86 /**
cdalton8917d622015-05-06 13:40:21 -070087 * Indicates the capabilities of the fixed function blend unit.
88 */
89 enum BlendEquationSupport {
90 kBasic_BlendEquationSupport, //<! Support to select the operator that
91 // combines src and dst terms.
92 kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific
93 // SVG/PDF blend modes. Requires blend barriers.
94 kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not
95 // require blend barriers, and permits overlap.
96
97 kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
98 };
99
100 BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
101
102 bool advancedBlendEquationSupport() const {
103 return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
104 }
105
106 bool advancedCoherentBlendEquationSupport() const {
107 return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
108 }
109
cdalton1dd05422015-06-12 09:01:18 -0700110 bool canUseAdvancedBlendEquation(GrBlendEquation equation) const {
111 SkASSERT(GrBlendEquationIsAdvanced(equation));
112 return SkToBool(fAdvBlendEqBlacklist & (1 << equation));
113 }
114
cdalton8917d622015-05-06 13:40:21 -0700115 /**
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000116 * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
117 * textures allows partial mappings or full mappings.
118 */
119 enum MapFlags {
120 kNone_MapFlags = 0x0, //<! Cannot map the resource.
121
122 kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
123 // the other flags to have meaning.k
124 kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
125 };
126
127 uint32_t mapBufferFlags() const { return fMapBufferFlags; }
128
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000129 // Scratch textures not being reused means that those scratch textures
skia.committer@gmail.com7ed98df2013-10-31 07:01:53 +0000130 // that we upload to (i.e., don't have a render target) will not be
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000131 // recycled in the texture cache. This is to prevent ghosting by drivers
132 // (in particular for deferred architectures).
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000133 bool reuseScratchTextures() const { return fReuseScratchTextures; }
robertphillips1b8e1b52015-06-24 06:54:10 -0700134 bool reuseScratchBuffers() const { return fReuseScratchBuffers; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000135
bsalomon7dbd45d2016-03-23 10:40:53 -0700136 /// maximum number of attribute values per vertex
137 int maxVertexAttributes() const { return fMaxVertexAttributes; }
138
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000139 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
140 int maxTextureSize() const { return fMaxTextureSize; }
bsalomon8c07b7a2015-11-02 11:36:52 -0800141 /** This is the maximum tile size to use by GPU devices for rendering sw-backed images/bitmaps.
142 It is usually the max texture size, unless we're overriding it for testing. */
143 int maxTileSize() const { SkASSERT(fMaxTileSize <= fMaxTextureSize); return fMaxTileSize; }
bsalomonc59a1df2015-06-01 07:13:42 -0700144
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000145 // Will be 0 if MSAA is not supported
egdanieleed519e2016-01-15 11:36:18 -0800146 int maxColorSampleCount() const { return fMaxColorSampleCount; }
147 // Will be 0 if MSAA is not supported
148 int maxStencilSampleCount() const { return fMaxStencilSampleCount; }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800149 // Will be 0 if raster multisample is not supported. Raster multisample is a special HW mode
150 // where the rasterizer runs with more samples than are in the target framebuffer.
151 int maxRasterSamples() const { return fMaxRasterSamples; }
egdanieleed519e2016-01-15 11:36:18 -0800152 // We require the sample count to be less than maxColorSampleCount and maxStencilSampleCount.
153 // If we are using mixed samples, we only care about stencil.
154 int maxSampleCount() const {
155 if (this->usesMixedSamples()) {
156 return this->maxStencilSampleCount();
157 } else {
158 return SkTMin(this->maxColorSampleCount(), this->maxStencilSampleCount());
159 }
160 }
161
csmartdalton9bc11872016-08-09 12:42:47 -0700162 int maxWindowRectangles() const { return fMaxWindowRectangles; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000163
bsalomon41e4384e2016-01-08 09:12:44 -0800164 virtual bool isConfigTexturable(GrPixelConfig config) const = 0;
165 virtual bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const = 0;
Brian Salomonf9f45122016-11-29 11:59:17 -0500166 virtual bool canConfigBeImageStorage(GrPixelConfig config) const = 0;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000167
robertphillipscaef3452015-11-11 13:18:11 -0800168 bool suppressPrints() const { return fSuppressPrints; }
169
170 bool immediateFlush() const { return fImmediateFlush; }
bsalomon682c2692015-05-22 14:01:46 -0700171
cdalton397536c2016-03-25 12:15:03 -0700172 size_t bufferMapThreshold() const {
173 SkASSERT(fBufferMapThreshold >= 0);
174 return fBufferMapThreshold;
joshualitt7224c862015-05-29 06:46:47 -0700175 }
bsalomon682c2692015-05-22 14:01:46 -0700176
egdaniel51c8d402015-08-06 10:54:13 -0700177 bool fullClearIsFree() const { return fFullClearIsFree; }
178
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400179 /** True in environments that will issue errors if memory uploaded to buffers
bsalomon7dea7b72015-08-19 08:26:51 -0700180 is not initialized (even if not read by draw calls). */
181 bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
182
ethannicholas28ef4452016-03-25 09:26:03 -0700183 bool sampleShadingSupport() const { return fSampleShadingSupport; }
184
jvanverth84741b32016-09-30 08:39:02 -0700185 bool fenceSyncSupport() const { return fFenceSyncSupport; }
186
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000187protected:
bsalomon4ee6bd82015-05-27 13:23:23 -0700188 /** Subclasses must call this at the end of their constructors in order to apply caps
189 overrides requested by the client. Note that overrides will only reduce the caps never
190 expand them. */
191 void applyOptionsOverrides(const GrContextOptions& options);
192
bungeman6bd52842016-10-27 09:30:08 -0700193 sk_sp<GrShaderCaps> fShaderCaps;
jvanverthe9c0fc62015-04-29 11:18:05 -0700194
joshualitt83bc2292015-06-18 14:18:02 -0700195 bool fNPOTTextureTileSupport : 1;
196 bool fMipMapSupport : 1;
brianosmana6359362016-03-21 06:55:37 -0700197 bool fSRGBSupport : 1;
brianosman35b784d2016-05-05 11:52:53 -0700198 bool fSRGBWriteControl : 1;
joshualitt83bc2292015-06-18 14:18:02 -0700199 bool fTwoSidedStencilSupport : 1;
200 bool fStencilWrapOpsSupport : 1;
201 bool fDiscardRenderTargetSupport : 1;
202 bool fReuseScratchTextures : 1;
robertphillips1b8e1b52015-06-24 06:54:10 -0700203 bool fReuseScratchBuffers : 1;
joshualitt83bc2292015-06-18 14:18:02 -0700204 bool fGpuTracingSupport : 1;
205 bool fCompressedTexSubImageSupport : 1;
206 bool fOversizedStencilSupport : 1;
207 bool fTextureBarrierSupport : 1;
cdaltoneb79eea2016-02-26 10:39:34 -0800208 bool fSampleLocationsSupport : 1;
csmartdalton2b5f2cb2016-06-10 14:06:32 -0700209 bool fMultisampleDisableSupport : 1;
egdanieleed519e2016-01-15 11:36:18 -0800210 bool fUsesMixedSamples : 1;
csmartdalton485a1202016-07-13 10:16:32 -0700211 bool fPreferClientSideDynamicBuffers : 1;
egdaniel51c8d402015-08-06 10:54:13 -0700212 bool fFullClearIsFree : 1;
bsalomon7dea7b72015-08-19 08:26:51 -0700213 bool fMustClearUploadedBufferData : 1;
robertphillips1b8e1b52015-06-24 06:54:10 -0700214
bsalomon63b21962014-11-05 07:05:34 -0800215 // Driver workaround
joshualitt83bc2292015-06-18 14:18:02 -0700216 bool fUseDrawInsteadOfClear : 1;
217 bool fUseDrawInsteadOfPartialRenderTargetWrite : 1;
bsalomonbabafcc2016-02-16 11:36:47 -0800218 bool fUseDrawInsteadOfAllRenderTargetWrites : 1;
csmartdaltone0d36292016-07-29 08:14:20 -0700219 bool fAvoidInstancedDrawsToFPTargets : 1;
bsalomon63b21962014-11-05 07:05:34 -0800220
robertphillips63926682015-08-20 09:39:02 -0700221 // ANGLE workaround
222 bool fPreferVRAMUseOverFlushes : 1;
223
ethannicholas28ef4452016-03-25 09:26:03 -0700224 bool fSampleShadingSupport : 1;
jvanverth84741b32016-09-30 08:39:02 -0700225 // TODO: this may need to be an enum to support different fence types
226 bool fFenceSyncSupport : 1;
ethannicholas28ef4452016-03-25 09:26:03 -0700227
csmartdaltone0d36292016-07-29 08:14:20 -0700228 InstancedSupport fInstancedSupport;
229
cdalton8917d622015-05-06 13:40:21 -0700230 BlendEquationSupport fBlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -0700231 uint32_t fAdvBlendEqBlacklist;
232 GR_STATIC_ASSERT(kLast_GrBlendEquation < 32);
233
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000234 uint32_t fMapBufferFlags;
cdalton397536c2016-03-25 12:15:03 -0700235 int fBufferMapThreshold;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000236
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000237 int fMaxRenderTargetSize;
bsalomon7dbd45d2016-03-23 10:40:53 -0700238 int fMaxVertexAttributes;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000239 int fMaxTextureSize;
bsalomon8c07b7a2015-11-02 11:36:52 -0800240 int fMaxTileSize;
egdanieleed519e2016-01-15 11:36:18 -0800241 int fMaxColorSampleCount;
242 int fMaxStencilSampleCount;
cdaltonaf8bc7d2016-02-05 09:35:20 -0800243 int fMaxRasterSamples;
csmartdalton9bc11872016-08-09 12:42:47 -0700244 int fMaxWindowRectangles;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000245
egdanielbc127a32014-09-19 12:07:43 -0700246private:
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400247 virtual void onApplyOptionsOverrides(const GrContextOptions&) {}
egdanielb7e7d572015-11-04 04:23:53 -0800248
robertphillipscaef3452015-11-11 13:18:11 -0800249 bool fSuppressPrints : 1;
250 bool fImmediateFlush: 1;
bsalomon682c2692015-05-22 14:01:46 -0700251
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000252 typedef SkRefCnt INHERITED;
253};
254
255#endif