Line data Source code
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 "GrTypes.h"
12 : #include "GrTypesPriv.h"
13 : #include "GrBlend.h"
14 : #include "GrShaderVar.h"
15 : #include "GrShaderCaps.h"
16 : #include "SkRefCnt.h"
17 : #include "SkString.h"
18 :
19 : struct GrContextOptions;
20 : class GrRenderTargetProxy;
21 :
22 : /**
23 : * Represents the capabilities of a GrContext.
24 : */
25 0 : class GrCaps : public SkRefCnt {
26 : public:
27 : GrCaps(const GrContextOptions&);
28 :
29 : virtual SkString dump() const;
30 :
31 0 : const GrShaderCaps* shaderCaps() const { return fShaderCaps.get(); }
32 :
33 0 : bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
34 : /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
35 : only for POT textures) */
36 0 : bool mipMapSupport() const { return fMipMapSupport; }
37 :
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.
42 : */
43 0 : bool srgbSupport() const { return fSRGBSupport; }
44 : /**
45 : * Is there support for enabling/disabling sRGB writes for sRGB-capable color buffers?
46 : */
47 0 : bool srgbWriteControl() const { return fSRGBWriteControl; }
48 0 : bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; }
49 0 : bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; }
50 0 : bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
51 : bool gpuTracingSupport() const { return fGpuTracingSupport; }
52 : bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; }
53 : bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
54 0 : bool textureBarrierSupport() const { return fTextureBarrierSupport; }
55 0 : bool sampleLocationsSupport() const { return fSampleLocationsSupport; }
56 0 : bool multisampleDisableSupport() const { return fMultisampleDisableSupport; }
57 0 : bool usesMixedSamples() const { return fUsesMixedSamples; }
58 0 : bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; }
59 :
60 0 : bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
61 0 : bool useDrawInsteadOfPartialRenderTargetWrite() const {
62 0 : return fUseDrawInsteadOfPartialRenderTargetWrite;
63 : }
64 :
65 0 : bool useDrawInsteadOfAllRenderTargetWrites() const {
66 0 : return fUseDrawInsteadOfAllRenderTargetWrites;
67 : }
68 :
69 0 : bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; }
70 :
71 : /**
72 : * 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 0 : InstancedSupport instancedSupport() const { return fInstancedSupport; }
83 :
84 0 : bool avoidInstancedDrawsToFPTargets() const { return fAvoidInstancedDrawsToFPTargets; }
85 :
86 : /**
87 : * 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 0 : BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
101 :
102 0 : bool advancedBlendEquationSupport() const {
103 0 : return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
104 : }
105 :
106 0 : bool advancedCoherentBlendEquationSupport() const {
107 0 : return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
108 : }
109 :
110 0 : bool canUseAdvancedBlendEquation(GrBlendEquation equation) const {
111 0 : SkASSERT(GrBlendEquationIsAdvanced(equation));
112 0 : return SkToBool(fAdvBlendEqBlacklist & (1 << equation));
113 : }
114 :
115 : /**
116 : * 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 0 : uint32_t mapBufferFlags() const { return fMapBufferFlags; }
128 :
129 : // Scratch textures not being reused means that those scratch textures
130 : // that we upload to (i.e., don't have a render target) will not be
131 : // recycled in the texture cache. This is to prevent ghosting by drivers
132 : // (in particular for deferred architectures).
133 0 : bool reuseScratchTextures() const { return fReuseScratchTextures; }
134 0 : bool reuseScratchBuffers() const { return fReuseScratchBuffers; }
135 :
136 : /// maximum number of attribute values per vertex
137 0 : int maxVertexAttributes() const { return fMaxVertexAttributes; }
138 :
139 0 : int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
140 0 : int maxTextureSize() const { return fMaxTextureSize; }
141 : /** 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 0 : int maxTileSize() const { SkASSERT(fMaxTileSize <= fMaxTextureSize); return fMaxTileSize; }
144 :
145 : // Will be 0 if MSAA is not supported
146 0 : int maxColorSampleCount() const { return fMaxColorSampleCount; }
147 : // Will be 0 if MSAA is not supported
148 0 : int maxStencilSampleCount() const { return fMaxStencilSampleCount; }
149 : // 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 0 : int maxRasterSamples() const { return fMaxRasterSamples; }
152 : // 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 0 : int maxSampleCount() const {
155 0 : if (this->usesMixedSamples()) {
156 0 : return this->maxStencilSampleCount();
157 : } else {
158 0 : return SkTMin(this->maxColorSampleCount(), this->maxStencilSampleCount());
159 : }
160 : }
161 :
162 0 : int maxWindowRectangles() const { return fMaxWindowRectangles; }
163 :
164 : virtual bool isConfigTexturable(GrPixelConfig config) const = 0;
165 : virtual bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const = 0;
166 : virtual bool canConfigBeImageStorage(GrPixelConfig config) const = 0;
167 :
168 0 : bool suppressPrints() const { return fSuppressPrints; }
169 :
170 : bool immediateFlush() const { return fImmediateFlush; }
171 :
172 0 : size_t bufferMapThreshold() const {
173 0 : SkASSERT(fBufferMapThreshold >= 0);
174 0 : return fBufferMapThreshold;
175 : }
176 :
177 0 : bool fullClearIsFree() const { return fFullClearIsFree; }
178 :
179 : /** True in environments that will issue errors if memory uploaded to buffers
180 : is not initialized (even if not read by draw calls). */
181 0 : bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
182 :
183 0 : bool sampleShadingSupport() const { return fSampleShadingSupport; }
184 :
185 : bool fenceSyncSupport() const { return fFenceSyncSupport; }
186 0 : bool crossContextTextureSupport() const { return fCrossContextTextureSupport; }
187 :
188 : /**
189 : * This is can be called before allocating a texture to be a dst for copySurface. This is only
190 : * used for doing dst copies needed in blends, thus the src is always a GrRenderTargetProxy. It
191 : * will populate the origin, config, and flags fields of the desc such that copySurface can
192 : * efficiently succeed. rectsMustMatch will be set to true if the copy operation must ensure
193 : * that the src and dest rects are identical. disallowSubrect will be set to true if copy rect
194 : * must equal src's bounds.
195 : */
196 : virtual bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
197 : bool* rectsMustMatch, bool* disallowSubrect) const = 0;
198 :
199 : protected:
200 : /** Subclasses must call this at the end of their constructors in order to apply caps
201 : overrides requested by the client. Note that overrides will only reduce the caps never
202 : expand them. */
203 : void applyOptionsOverrides(const GrContextOptions& options);
204 :
205 : sk_sp<GrShaderCaps> fShaderCaps;
206 :
207 : bool fNPOTTextureTileSupport : 1;
208 : bool fMipMapSupport : 1;
209 : bool fSRGBSupport : 1;
210 : bool fSRGBWriteControl : 1;
211 : bool fTwoSidedStencilSupport : 1;
212 : bool fStencilWrapOpsSupport : 1;
213 : bool fDiscardRenderTargetSupport : 1;
214 : bool fReuseScratchTextures : 1;
215 : bool fReuseScratchBuffers : 1;
216 : bool fGpuTracingSupport : 1;
217 : bool fCompressedTexSubImageSupport : 1;
218 : bool fOversizedStencilSupport : 1;
219 : bool fTextureBarrierSupport : 1;
220 : bool fSampleLocationsSupport : 1;
221 : bool fMultisampleDisableSupport : 1;
222 : bool fUsesMixedSamples : 1;
223 : bool fPreferClientSideDynamicBuffers : 1;
224 : bool fFullClearIsFree : 1;
225 : bool fMustClearUploadedBufferData : 1;
226 :
227 : // Driver workaround
228 : bool fUseDrawInsteadOfClear : 1;
229 : bool fUseDrawInsteadOfPartialRenderTargetWrite : 1;
230 : bool fUseDrawInsteadOfAllRenderTargetWrites : 1;
231 : bool fAvoidInstancedDrawsToFPTargets : 1;
232 :
233 : // ANGLE workaround
234 : bool fPreferVRAMUseOverFlushes : 1;
235 :
236 : bool fSampleShadingSupport : 1;
237 : // TODO: this may need to be an enum to support different fence types
238 : bool fFenceSyncSupport : 1;
239 :
240 : // Vulkan doesn't support this (yet) and some drivers have issues, too
241 : bool fCrossContextTextureSupport : 1;
242 :
243 : InstancedSupport fInstancedSupport;
244 :
245 : BlendEquationSupport fBlendEquationSupport;
246 : uint32_t fAdvBlendEqBlacklist;
247 : GR_STATIC_ASSERT(kLast_GrBlendEquation < 32);
248 :
249 : uint32_t fMapBufferFlags;
250 : int fBufferMapThreshold;
251 :
252 : int fMaxRenderTargetSize;
253 : int fMaxVertexAttributes;
254 : int fMaxTextureSize;
255 : int fMaxTileSize;
256 : int fMaxColorSampleCount;
257 : int fMaxStencilSampleCount;
258 : int fMaxRasterSamples;
259 : int fMaxWindowRectangles;
260 :
261 : private:
262 0 : virtual void onApplyOptionsOverrides(const GrContextOptions&) {}
263 :
264 : bool fSuppressPrints : 1;
265 : bool fImmediateFlush: 1;
266 :
267 : typedef SkRefCnt INHERITED;
268 : };
269 :
270 : #endif
|