blob: 42da3d448151d3bf4664aabb2e329e238e0d8c04 [file] [log] [blame]
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrTypesPriv_DEFINED
9#define GrTypesPriv_DEFINED
10
Brian Salomon5e150852017-03-22 14:53:13 -040011#include <chrono>
jvanverth@google.com054ae992013-04-01 20:06:51 +000012#include "GrTypes.h"
bungeman06ca8ec2016-06-09 08:01:03 -070013#include "SkRefCnt.h"
bsalomon@google.com31ec7982013-03-27 18:14:57 +000014
Brian Salomon5e150852017-03-22 14:53:13 -040015// The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might
16// not actually be monotonic, depending on how libstdc++ was built. However, this is only currently
17// used for idle resource purging so it shouldn't cause a correctness problem.
18#if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000)
19using GrStdSteadyClock = std::chrono::monotonic_clock;
20#else
21using GrStdSteadyClock = std::chrono::steady_clock;
22#endif
23
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050024/** This enum indicates the type of antialiasing to be performed. */
Brian Salomonaf9847e2017-03-01 11:28:27 -050025enum class GrAAType : unsigned {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050026 /** No antialiasing */
27 kNone,
28 /** Use fragment shader code to compute a fractional pixel coverage. */
29 kCoverage,
30 /** Use normal MSAA. */
31 kMSAA,
32 /**
33 * Use "mixed samples" MSAA such that the stencil buffer is multisampled but the color buffer is
34 * not.
35 */
36 kMixedSamples
37};
38
Brian Salomon0abc8b42016-12-13 10:22:54 -050039static inline bool GrAATypeIsHW(GrAAType type) {
40 switch (type) {
41 case GrAAType::kNone:
42 return false;
43 case GrAAType::kCoverage:
44 return false;
45 case GrAAType::kMSAA:
46 return true;
47 case GrAAType::kMixedSamples:
48 return true;
49 }
50 SkFAIL("Unknown AA Type");
51 return false;
52}
53
Brian Salomon7c8460e2017-05-12 11:36:10 -040054/** The type of full scene antialiasing supported by a render target. */
55enum class GrFSAAType {
56 /** No FSAA */
57 kNone,
58 /** Regular MSAA where each attachment has the same sample count. */
59 kUnifiedMSAA,
60 /** One color sample, N stencil samples. */
61 kMixedSamples,
62};
63
64/**
65 * Not all drawing code paths support using mixed samples when available and instead use
66 * coverage-based aa.
67 */
68enum class GrAllowMixedSamples { kNo, kYes };
69
70static inline GrAAType GrChooseAAType(GrAA aa, GrFSAAType fsaaType,
71 GrAllowMixedSamples allowMixedSamples) {
72 if (GrAA::kNo == aa) {
73 return GrAAType::kNone;
74 }
75 switch (fsaaType) {
76 case GrFSAAType::kNone:
77 return GrAAType::kCoverage;
78 case GrFSAAType::kUnifiedMSAA:
79 return GrAAType::kMSAA;
80 case GrFSAAType::kMixedSamples:
81 return GrAllowMixedSamples::kYes == allowMixedSamples ? GrAAType::kMixedSamples
82 : GrAAType::kCoverage;
83 }
84 SkFAIL("Unexpected fsaa type");
85 return GrAAType::kNone;
86}
87
Brian Salomon0abc8b42016-12-13 10:22:54 -050088/**
89 * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars,
90 * but should be applicable to other shader languages.)
91 */
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000092enum GrSLType {
93 kVoid_GrSLType,
Brian Salomonfa26e662016-11-14 11:27:00 -050094 kBool_GrSLType,
95 kInt_GrSLType,
96 kUint_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000097 kFloat_GrSLType,
98 kVec2f_GrSLType,
99 kVec3f_GrSLType,
100 kVec4f_GrSLType,
csmartdaltonb37cb232017-02-08 14:56:27 -0500101 kVec2i_GrSLType,
102 kVec3i_GrSLType,
103 kVec4i_GrSLType,
cdalton8d988b32016-03-07 15:39:09 -0800104 kMat22f_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000105 kMat33f_GrSLType,
106 kMat44f_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -0700107 kTexture2DSampler_GrSLType,
Brian Salomona8f00022016-11-16 12:55:57 -0500108 kITexture2DSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -0700109 kTextureExternalSampler_GrSLType,
110 kTexture2DRectSampler_GrSLType,
csmartdalton22458032016-11-16 11:28:16 -0700111 kBufferSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -0700112 kTexture2D_GrSLType,
113 kSampler_GrSLType,
Brian Salomonf9f45122016-11-29 11:59:17 -0500114 kImageStorage2D_GrSLType,
115 kIImageStorage2D_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000116};
117
bsalomon17168df2014-12-09 09:00:49 -0800118enum GrShaderType {
119 kVertex_GrShaderType,
120 kGeometry_GrShaderType,
121 kFragment_GrShaderType,
122
123 kLastkFragment_GrShaderType = kFragment_GrShaderType
124};
125static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
126
cdalton5e58cee2016-02-11 12:49:47 -0800127enum GrShaderFlags {
128 kNone_GrShaderFlags = 0,
129 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
130 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
131 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
132};
133GR_MAKE_BITFIELD_OPS(GrShaderFlags);
134
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000135/**
bsalomonc0bd6482014-12-09 10:04:14 -0800136 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -0800137 * vary the internal precision based on the qualifiers. These currently only apply to float types (
138 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -0800139 */
140enum GrSLPrecision {
141 kLow_GrSLPrecision,
142 kMedium_GrSLPrecision,
143 kHigh_GrSLPrecision,
144
Brian Osman33aa2c72017-04-05 09:26:15 -0400145 // Default precision is a special tag that means "whatever the default for the program/type
146 // combination is". In other words, it maps to the empty string in shader code. There are some
147 // scenarios where kDefault is not allowed (as the default precision for a program, or for
148 // varyings, for example).
149 kDefault_GrSLPrecision,
bsalomonc0bd6482014-12-09 10:04:14 -0800150
Brian Osman33aa2c72017-04-05 09:26:15 -0400151 // We only consider the "real" precisions here
152 kLast_GrSLPrecision = kHigh_GrSLPrecision,
bsalomonc0bd6482014-12-09 10:04:14 -0800153};
154
155static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
156
ethannicholas22793252016-01-30 09:59:10 -0800157/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -0800158static inline bool GrSLTypeIsFloatType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500159 switch (type) {
160 case kFloat_GrSLType:
161 case kVec2f_GrSLType:
162 case kVec3f_GrSLType:
163 case kVec4f_GrSLType:
164 case kMat22f_GrSLType:
165 case kMat33f_GrSLType:
166 case kMat44f_GrSLType:
167 return true;
bsalomon422f56f2014-12-09 10:18:12 -0800168
Brian Salomonfa26e662016-11-14 11:27:00 -0500169 case kVoid_GrSLType:
170 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500171 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500172 case kTextureExternalSampler_GrSLType:
173 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700174 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500175 case kBool_GrSLType:
176 case kInt_GrSLType:
177 case kUint_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500178 case kVec2i_GrSLType:
179 case kVec3i_GrSLType:
180 case kVec4i_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500181 case kTexture2D_GrSLType:
182 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500183 case kImageStorage2D_GrSLType:
184 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500185 return false;
186 }
187 SkFAIL("Unexpected type");
188 return false;
bsalomone5286e02016-01-14 09:24:09 -0800189}
190
egdaniel990dbc82016-07-13 14:09:30 -0700191static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500192 switch (type) {
193 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500194 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500195 case kTextureExternalSampler_GrSLType:
196 case kTexture2DRectSampler_GrSLType:
197 return true;
bsalomone5286e02016-01-14 09:24:09 -0800198
Brian Salomonfa26e662016-11-14 11:27:00 -0500199 case kVoid_GrSLType:
200 case kFloat_GrSLType:
201 case kVec2f_GrSLType:
202 case kVec3f_GrSLType:
203 case kVec4f_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500204 case kVec2i_GrSLType:
205 case kVec3i_GrSLType:
206 case kVec4i_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500207 case kMat22f_GrSLType:
208 case kMat33f_GrSLType:
209 case kMat44f_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700210 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500211 case kInt_GrSLType:
212 case kUint_GrSLType:
213 case kBool_GrSLType:
214 case kTexture2D_GrSLType:
215 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500216 case kImageStorage2D_GrSLType:
217 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500218 return false;
219 }
220 SkFAIL("Unexpected type");
221 return false;
egdanielfa896322016-01-13 12:19:30 -0800222}
223
egdaniel990dbc82016-07-13 14:09:30 -0700224static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500225 switch (type) {
226 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500227 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500228 case kTextureExternalSampler_GrSLType:
229 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700230 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500231 return true;
cdalton74b8d322016-04-11 14:47:28 -0700232
Brian Salomonfa26e662016-11-14 11:27:00 -0500233 case kVoid_GrSLType:
234 case kFloat_GrSLType:
235 case kVec2f_GrSLType:
236 case kVec3f_GrSLType:
237 case kVec4f_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500238 case kVec2i_GrSLType:
239 case kVec3i_GrSLType:
240 case kVec4i_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500241 case kMat22f_GrSLType:
242 case kMat33f_GrSLType:
243 case kMat44f_GrSLType:
244 case kInt_GrSLType:
245 case kUint_GrSLType:
246 case kBool_GrSLType:
247 case kTexture2D_GrSLType:
248 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500249 case kImageStorage2D_GrSLType:
250 case kIImageStorage2D_GrSLType:
251 return false;
252 }
253 SkFAIL("Unexpected type");
254 return false;
255}
256
257static inline bool GrSLTypeIsImageStorage(GrSLType type) {
258 switch (type) {
259 case kImageStorage2D_GrSLType:
260 case kIImageStorage2D_GrSLType:
261 return true;
262
263 case kVoid_GrSLType:
264 case kFloat_GrSLType:
265 case kVec2f_GrSLType:
266 case kVec3f_GrSLType:
267 case kVec4f_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500268 case kVec2i_GrSLType:
269 case kVec3i_GrSLType:
270 case kVec4i_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500271 case kMat22f_GrSLType:
272 case kMat33f_GrSLType:
273 case kMat44f_GrSLType:
274 case kInt_GrSLType:
275 case kUint_GrSLType:
276 case kBool_GrSLType:
277 case kTexture2D_GrSLType:
278 case kSampler_GrSLType:
279 case kTexture2DSampler_GrSLType:
280 case kITexture2DSampler_GrSLType:
281 case kTextureExternalSampler_GrSLType:
282 case kTexture2DRectSampler_GrSLType:
283 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500284 return false;
285 }
286 SkFAIL("Unexpected type");
287 return false;
cdalton74b8d322016-04-11 14:47:28 -0700288}
289
cdalton5f2d8e22016-03-11 13:34:32 -0800290static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500291 switch (type) {
292 case kInt_GrSLType:
293 case kUint_GrSLType:
294 case kFloat_GrSLType:
295 case kVec2f_GrSLType:
296 case kVec3f_GrSLType:
297 case kVec4f_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500298 case kVec2i_GrSLType:
299 case kVec3i_GrSLType:
300 case kVec4i_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500301 case kMat22f_GrSLType:
302 case kMat33f_GrSLType:
303 case kMat44f_GrSLType:
304 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500305 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500306 case kTextureExternalSampler_GrSLType:
307 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700308 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500309 case kTexture2D_GrSLType:
310 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500311 case kImageStorage2D_GrSLType:
312 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500313 return true;
314
315 case kVoid_GrSLType:
316 case kBool_GrSLType:
317 return false;
318 }
319 SkFAIL("Unexpected type");
320 return false;
cdalton5f2d8e22016-03-11 13:34:32 -0800321}
322
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000323//////////////////////////////////////////////////////////////////////////////
324
jvanverth@google.com054ae992013-04-01 20:06:51 +0000325/**
326 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000327 */
328enum GrVertexAttribType {
329 kFloat_GrVertexAttribType = 0,
330 kVec2f_GrVertexAttribType,
331 kVec3f_GrVertexAttribType,
332 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800333
csmartdaltonb37cb232017-02-08 14:56:27 -0500334 kVec2i_GrVertexAttribType, // vector of 2 32-bit ints
335 kVec3i_GrVertexAttribType, // vector of 3 32-bit ints
336 kVec4i_GrVertexAttribType, // vector of 4 32-bit ints
337
egdaniel37b4d862014-11-03 10:07:07 -0800338 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800339 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000340
jvanverth7023a002016-02-22 11:25:32 -0800341 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800342
343 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800344 kUint_GrVertexAttribType,
egdaniel990dbc82016-07-13 14:09:30 -0700345
cdalton793dc262016-02-08 10:11:47 -0800346 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000347};
348static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
349
jvanverth@google.com054ae992013-04-01 20:06:51 +0000350
351/**
352 * Returns the size of the attrib type in bytes.
353 */
354static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500355 switch (type) {
356 case kFloat_GrVertexAttribType:
357 return sizeof(float);
358 case kVec2f_GrVertexAttribType:
359 return 2*sizeof(float);
360 case kVec3f_GrVertexAttribType:
361 return 3*sizeof(float);
362 case kVec4f_GrVertexAttribType:
363 return 4*sizeof(float);
csmartdaltonb37cb232017-02-08 14:56:27 -0500364 case kVec2i_GrVertexAttribType:
365 return 2*sizeof(int32_t);
366 case kVec3i_GrVertexAttribType:
367 return 3*sizeof(int32_t);
368 case kVec4i_GrVertexAttribType:
369 return 4*sizeof(int32_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500370 case kUByte_GrVertexAttribType:
371 return 1*sizeof(char);
372 case kVec4ub_GrVertexAttribType:
373 return 4*sizeof(char);
374 case kVec2us_GrVertexAttribType:
375 return 2*sizeof(int16_t);
376 case kInt_GrVertexAttribType:
377 return sizeof(int32_t);
378 case kUint_GrVertexAttribType:
379 return sizeof(uint32_t);
380 }
381 SkFAIL("Unexpected attribute type");
382 return 0;
jvanverth@google.com054ae992013-04-01 20:06:51 +0000383}
384
385/**
cdalton793dc262016-02-08 10:11:47 -0800386 * Is the attrib type integral?
387 */
388static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500389 switch (type) {
390 case kFloat_GrVertexAttribType:
391 return false;
392 case kVec2f_GrVertexAttribType:
393 return false;
394 case kVec3f_GrVertexAttribType:
395 return false;
396 case kVec4f_GrVertexAttribType:
397 return false;
csmartdaltonb37cb232017-02-08 14:56:27 -0500398 case kVec2i_GrVertexAttribType:
399 return true;
400 case kVec3i_GrVertexAttribType:
401 return true;
402 case kVec4i_GrVertexAttribType:
403 return true;
Brian Salomonfa26e662016-11-14 11:27:00 -0500404 case kUByte_GrVertexAttribType:
405 return false;
406 case kVec4ub_GrVertexAttribType:
407 return false;
408 case kVec2us_GrVertexAttribType:
409 return false;
410 case kInt_GrVertexAttribType:
411 return true;
412 case kUint_GrVertexAttribType:
413 return true;
414 }
415 SkFAIL("Unexpected attribute type");
416 return false;
cdalton793dc262016-02-08 10:11:47 -0800417}
418
419/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800420 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000421 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800422static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
423 switch (type) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800424 case kUByte_GrVertexAttribType:
425 case kFloat_GrVertexAttribType:
426 return kFloat_GrSLType;
jvanverth7023a002016-02-22 11:25:32 -0800427 case kVec2us_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800428 case kVec2f_GrVertexAttribType:
429 return kVec2f_GrSLType;
430 case kVec3f_GrVertexAttribType:
431 return kVec3f_GrSLType;
432 case kVec4ub_GrVertexAttribType:
433 case kVec4f_GrVertexAttribType:
434 return kVec4f_GrSLType;
csmartdaltonb37cb232017-02-08 14:56:27 -0500435 case kVec2i_GrVertexAttribType:
436 return kVec2i_GrSLType;
437 case kVec3i_GrVertexAttribType:
438 return kVec3i_GrSLType;
439 case kVec4i_GrVertexAttribType:
440 return kVec4i_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800441 case kInt_GrVertexAttribType:
442 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800443 case kUint_GrVertexAttribType:
444 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000445 }
Brian Salomonfa26e662016-11-14 11:27:00 -0500446 SkFAIL("Unsupported type conversion");
447 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800448}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000449
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000450//////////////////////////////////////////////////////////////////////////////
451
Brian Salomonf9f45122016-11-29 11:59:17 -0500452enum class GrImageStorageFormat {
453 kRGBA8,
454 kRGBA8i,
455 kRGBA16f,
456 kRGBA32f,
457};
458
459/**
460 * Describes types of caching and compiler optimizations allowed for certain variable types
461 * (currently only image storages).
462 **/
463enum class GrSLMemoryModel {
464 /** No special restrctions on memory accesses or compiler optimizations */
465 kNone,
466 /** Cache coherent across shader invocations */
467 kCoherent,
468 /**
469 * Disallows compiler from eliding loads or stores that appear redundant in a single
470 * invocation. Implies coherent.
471 */
472 kVolatile
473};
474
475/**
476 * If kYes then the memory backing the varialble is only accessed via the variable. This is
477 * currently only used with image storages.
478 */
479enum class GrSLRestrict {
480 kYes,
481 kNo,
482};
483
484//////////////////////////////////////////////////////////////////////////////
485
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000486/**
487* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000488* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700489* GrProcessorEdgeType will succeed with all values and it is up to the caller to check for
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000490* a NULL return.
491*/
joshualittb0a8a372014-09-23 09:50:21 -0700492enum GrPrimitiveEdgeType {
493 kFillBW_GrProcessorEdgeType,
494 kFillAA_GrProcessorEdgeType,
495 kInverseFillBW_GrProcessorEdgeType,
496 kInverseFillAA_GrProcessorEdgeType,
497 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000498
joshualittb0a8a372014-09-23 09:50:21 -0700499 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000500};
501
joshualittb0a8a372014-09-23 09:50:21 -0700502static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000503
joshualittb0a8a372014-09-23 09:50:21 -0700504static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
505 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000506}
507
joshualittb0a8a372014-09-23 09:50:21 -0700508static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
509 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
510 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000511}
512
joshualittb0a8a372014-09-23 09:50:21 -0700513static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
514 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000515}
516
joshualittb0a8a372014-09-23 09:50:21 -0700517static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000518 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700519 case kFillBW_GrProcessorEdgeType:
520 return kInverseFillBW_GrProcessorEdgeType;
521 case kFillAA_GrProcessorEdgeType:
522 return kInverseFillAA_GrProcessorEdgeType;
523 case kInverseFillBW_GrProcessorEdgeType:
524 return kFillBW_GrProcessorEdgeType;
525 case kInverseFillAA_GrProcessorEdgeType:
526 return kFillAA_GrProcessorEdgeType;
527 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000528 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000529 }
joshualittb0a8a372014-09-23 09:50:21 -0700530 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000531}
532
bsalomonbcf0a522014-10-08 08:40:09 -0700533/**
534 * Indicates the type of pending IO operations that can be recorded for gpu resources.
535 */
536enum GrIOType {
537 kRead_GrIOType,
538 kWrite_GrIOType,
539 kRW_GrIOType
540};
541
jvanverth17aa0472016-01-05 10:41:27 -0800542/**
cdalton397536c2016-03-25 12:15:03 -0700543* Indicates the type of data that a GPU buffer will be used for.
544*/
545enum GrBufferType {
546 kVertex_GrBufferType,
547 kIndex_GrBufferType,
cdaltone2e71c22016-04-07 18:13:29 -0700548 kTexel_GrBufferType,
549 kDrawIndirect_GrBufferType,
cdalton397536c2016-03-25 12:15:03 -0700550 kXferCpuToGpu_GrBufferType,
551 kXferGpuToCpu_GrBufferType,
552
553 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
554};
cdaltone2e71c22016-04-07 18:13:29 -0700555static const int kGrBufferTypeCount = kLast_GrBufferType + 1;
556
557static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) {
558 SkASSERT(type >= 0 && type < kGrBufferTypeCount);
559 return type <= kIndex_GrBufferType;
560
561 GR_STATIC_ASSERT(0 == kVertex_GrBufferType);
562 GR_STATIC_ASSERT(1 == kIndex_GrBufferType);
563}
cdalton397536c2016-03-25 12:15:03 -0700564
565/**
566* Provides a performance hint regarding the frequency at which a data store will be accessed.
567*/
568enum GrAccessPattern {
569 /** Data store will be respecified repeatedly and used many times. */
570 kDynamic_GrAccessPattern,
571 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
572 kStatic_GrAccessPattern,
573 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
574 kStream_GrAccessPattern,
575
576 kLast_GrAccessPattern = kStream_GrAccessPattern
jvanverth17aa0472016-01-05 10:41:27 -0800577};
578
579
joshualitt7d022d62015-05-12 12:03:50 -0700580#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700581// Takes a pointer to a GrCaps, and will suppress prints if required
582#define GrCapsDebugf(caps, ...) \
Brian Salomoneb628292017-02-15 14:12:26 -0500583 if (!(caps)->suppressPrints()) { \
bsalomon682c2692015-05-22 14:01:46 -0700584 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700585 }
586#else
bsalomon682c2692015-05-22 14:01:46 -0700587#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700588#endif
589
kkinnunen2e6055b2016-04-22 01:48:29 -0700590/**
591 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
592 */
593enum class GrBackendObjectOwnership : bool {
594 /** Holder does not destroy the backend object. */
595 kBorrowed = false,
596 /** Holder destroys the backend object. */
597 kOwned = true
598};
599
bungeman06ca8ec2016-06-09 08:01:03 -0700600template <typename T> T * const * sk_sp_address_as_pointer_address(sk_sp<T> const * sp) {
601 static_assert(sizeof(T*) == sizeof(sk_sp<T>), "sk_sp not expected size.");
602 return reinterpret_cast<T * const *>(sp);
603}
604
jvanverth84741b32016-09-30 08:39:02 -0700605/*
606 * Object for CPU-GPU synchronization
607 */
Greg Daniel6be35232017-03-01 17:01:09 -0500608typedef uint64_t GrFence;
jvanverth84741b32016-09-30 08:39:02 -0700609
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000610#endif