2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrTypesPriv_DEFINED
9 #define GrTypesPriv_DEFINED
15 // 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)
19 using GrStdSteadyClock = std::chrono::monotonic_clock;
21 using GrStdSteadyClock = std::chrono::steady_clock;
24 /** This enum indicates the type of antialiasing to be performed. */
25 enum class GrAAType : unsigned {
26 /** No antialiasing */
28 /** Use fragment shader code to compute a fractional pixel coverage. */
30 /** Use normal MSAA. */
33 * Use "mixed samples" MSAA such that the stencil buffer is multisampled but the color buffer is
39 static inline bool GrAATypeIsHW(GrAAType type) {
43 case GrAAType::kCoverage:
47 case GrAAType::kMixedSamples:
50 SkFAIL("Unknown AA Type");
55 * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars,
56 * but should be applicable to other shader languages.)
73 kTexture2DSampler_GrSLType,
74 kITexture2DSampler_GrSLType,
75 kTextureExternalSampler_GrSLType,
76 kTexture2DRectSampler_GrSLType,
77 kBufferSampler_GrSLType,
80 kImageStorage2D_GrSLType,
81 kIImageStorage2D_GrSLType,
86 kGeometry_GrShaderType,
87 kFragment_GrShaderType,
89 kLastkFragment_GrShaderType = kFragment_GrShaderType
91 static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
94 kNone_GrShaderFlags = 0,
95 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
96 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
97 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
99 GR_MAKE_BITFIELD_OPS(GrShaderFlags);
101 enum class GrDrawFace {
110 * Precisions of shader language variables. Not all shading languages support precisions or actually
111 * vary the internal precision based on the qualifiers. These currently only apply to float types (
112 * including float vectors and matrices).
116 kMedium_GrSLPrecision,
119 // Default precision is medium. This is because on OpenGL ES 2 highp support is not
120 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
121 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
123 kLast_GrSLPrecision = kHigh_GrSLPrecision
126 static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
128 /** Is the shading language type float (including vectors/matrices)? */
129 static inline bool GrSLTypeIsFloatType(GrSLType type) {
131 case kFloat_GrSLType:
132 case kVec2f_GrSLType:
133 case kVec3f_GrSLType:
134 case kVec4f_GrSLType:
135 case kMat22f_GrSLType:
136 case kMat33f_GrSLType:
137 case kMat44f_GrSLType:
141 case kTexture2DSampler_GrSLType:
142 case kITexture2DSampler_GrSLType:
143 case kTextureExternalSampler_GrSLType:
144 case kTexture2DRectSampler_GrSLType:
145 case kBufferSampler_GrSLType:
149 case kVec2i_GrSLType:
150 case kVec3i_GrSLType:
151 case kVec4i_GrSLType:
152 case kTexture2D_GrSLType:
153 case kSampler_GrSLType:
154 case kImageStorage2D_GrSLType:
155 case kIImageStorage2D_GrSLType:
158 SkFAIL("Unexpected type");
162 static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
164 case kTexture2DSampler_GrSLType:
165 case kITexture2DSampler_GrSLType:
166 case kTextureExternalSampler_GrSLType:
167 case kTexture2DRectSampler_GrSLType:
171 case kFloat_GrSLType:
172 case kVec2f_GrSLType:
173 case kVec3f_GrSLType:
174 case kVec4f_GrSLType:
175 case kVec2i_GrSLType:
176 case kVec3i_GrSLType:
177 case kVec4i_GrSLType:
178 case kMat22f_GrSLType:
179 case kMat33f_GrSLType:
180 case kMat44f_GrSLType:
181 case kBufferSampler_GrSLType:
185 case kTexture2D_GrSLType:
186 case kSampler_GrSLType:
187 case kImageStorage2D_GrSLType:
188 case kIImageStorage2D_GrSLType:
191 SkFAIL("Unexpected type");
195 static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
197 case kTexture2DSampler_GrSLType:
198 case kITexture2DSampler_GrSLType:
199 case kTextureExternalSampler_GrSLType:
200 case kTexture2DRectSampler_GrSLType:
201 case kBufferSampler_GrSLType:
205 case kFloat_GrSLType:
206 case kVec2f_GrSLType:
207 case kVec3f_GrSLType:
208 case kVec4f_GrSLType:
209 case kVec2i_GrSLType:
210 case kVec3i_GrSLType:
211 case kVec4i_GrSLType:
212 case kMat22f_GrSLType:
213 case kMat33f_GrSLType:
214 case kMat44f_GrSLType:
218 case kTexture2D_GrSLType:
219 case kSampler_GrSLType:
220 case kImageStorage2D_GrSLType:
221 case kIImageStorage2D_GrSLType:
224 SkFAIL("Unexpected type");
228 static inline bool GrSLTypeIsImageStorage(GrSLType type) {
230 case kImageStorage2D_GrSLType:
231 case kIImageStorage2D_GrSLType:
235 case kFloat_GrSLType:
236 case kVec2f_GrSLType:
237 case kVec3f_GrSLType:
238 case kVec4f_GrSLType:
239 case kVec2i_GrSLType:
240 case kVec3i_GrSLType:
241 case kVec4i_GrSLType:
242 case kMat22f_GrSLType:
243 case kMat33f_GrSLType:
244 case kMat44f_GrSLType:
248 case kTexture2D_GrSLType:
249 case kSampler_GrSLType:
250 case kTexture2DSampler_GrSLType:
251 case kITexture2DSampler_GrSLType:
252 case kTextureExternalSampler_GrSLType:
253 case kTexture2DRectSampler_GrSLType:
254 case kBufferSampler_GrSLType:
257 SkFAIL("Unexpected type");
261 static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
265 case kFloat_GrSLType:
266 case kVec2f_GrSLType:
267 case kVec3f_GrSLType:
268 case kVec4f_GrSLType:
269 case kVec2i_GrSLType:
270 case kVec3i_GrSLType:
271 case kVec4i_GrSLType:
272 case kMat22f_GrSLType:
273 case kMat33f_GrSLType:
274 case kMat44f_GrSLType:
275 case kTexture2DSampler_GrSLType:
276 case kITexture2DSampler_GrSLType:
277 case kTextureExternalSampler_GrSLType:
278 case kTexture2DRectSampler_GrSLType:
279 case kBufferSampler_GrSLType:
280 case kTexture2D_GrSLType:
281 case kSampler_GrSLType:
282 case kImageStorage2D_GrSLType:
283 case kIImageStorage2D_GrSLType:
290 SkFAIL("Unexpected type");
294 //////////////////////////////////////////////////////////////////////////////
297 * Types used to describe format of vertices in arrays.
299 enum GrVertexAttribType {
300 kFloat_GrVertexAttribType = 0,
301 kVec2f_GrVertexAttribType,
302 kVec3f_GrVertexAttribType,
303 kVec4f_GrVertexAttribType,
305 kVec2i_GrVertexAttribType, // vector of 2 32-bit ints
306 kVec3i_GrVertexAttribType, // vector of 3 32-bit ints
307 kVec4i_GrVertexAttribType, // vector of 4 32-bit ints
309 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
310 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
312 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
314 kInt_GrVertexAttribType,
315 kUint_GrVertexAttribType,
317 kLast_GrVertexAttribType = kUint_GrVertexAttribType
319 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
323 * Returns the size of the attrib type in bytes.
325 static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
327 case kFloat_GrVertexAttribType:
328 return sizeof(float);
329 case kVec2f_GrVertexAttribType:
330 return 2*sizeof(float);
331 case kVec3f_GrVertexAttribType:
332 return 3*sizeof(float);
333 case kVec4f_GrVertexAttribType:
334 return 4*sizeof(float);
335 case kVec2i_GrVertexAttribType:
336 return 2*sizeof(int32_t);
337 case kVec3i_GrVertexAttribType:
338 return 3*sizeof(int32_t);
339 case kVec4i_GrVertexAttribType:
340 return 4*sizeof(int32_t);
341 case kUByte_GrVertexAttribType:
342 return 1*sizeof(char);
343 case kVec4ub_GrVertexAttribType:
344 return 4*sizeof(char);
345 case kVec2us_GrVertexAttribType:
346 return 2*sizeof(int16_t);
347 case kInt_GrVertexAttribType:
348 return sizeof(int32_t);
349 case kUint_GrVertexAttribType:
350 return sizeof(uint32_t);
352 SkFAIL("Unexpected attribute type");
357 * Is the attrib type integral?
359 static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
361 case kFloat_GrVertexAttribType:
363 case kVec2f_GrVertexAttribType:
365 case kVec3f_GrVertexAttribType:
367 case kVec4f_GrVertexAttribType:
369 case kVec2i_GrVertexAttribType:
371 case kVec3i_GrVertexAttribType:
373 case kVec4i_GrVertexAttribType:
375 case kUByte_GrVertexAttribType:
377 case kVec4ub_GrVertexAttribType:
379 case kVec2us_GrVertexAttribType:
381 case kInt_GrVertexAttribType:
383 case kUint_GrVertexAttribType:
386 SkFAIL("Unexpected attribute type");
391 * converts a GrVertexAttribType to a GrSLType
393 static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
395 case kUByte_GrVertexAttribType:
396 case kFloat_GrVertexAttribType:
397 return kFloat_GrSLType;
398 case kVec2us_GrVertexAttribType:
399 case kVec2f_GrVertexAttribType:
400 return kVec2f_GrSLType;
401 case kVec3f_GrVertexAttribType:
402 return kVec3f_GrSLType;
403 case kVec4ub_GrVertexAttribType:
404 case kVec4f_GrVertexAttribType:
405 return kVec4f_GrSLType;
406 case kVec2i_GrVertexAttribType:
407 return kVec2i_GrSLType;
408 case kVec3i_GrVertexAttribType:
409 return kVec3i_GrSLType;
410 case kVec4i_GrVertexAttribType:
411 return kVec4i_GrSLType;
412 case kInt_GrVertexAttribType:
413 return kInt_GrSLType;
414 case kUint_GrVertexAttribType:
415 return kUint_GrSLType;
417 SkFAIL("Unsupported type conversion");
418 return kVoid_GrSLType;
421 //////////////////////////////////////////////////////////////////////////////
423 enum class GrImageStorageFormat {
431 * Describes types of caching and compiler optimizations allowed for certain variable types
432 * (currently only image storages).
434 enum class GrSLMemoryModel {
435 /** No special restrctions on memory accesses or compiler optimizations */
437 /** Cache coherent across shader invocations */
440 * Disallows compiler from eliding loads or stores that appear redundant in a single
441 * invocation. Implies coherent.
447 * If kYes then the memory backing the varialble is only accessed via the variable. This is
448 * currently only used with image storages.
450 enum class GrSLRestrict {
455 //////////////////////////////////////////////////////////////////////////////
458 * We have coverage effects that clip rendering to the edge of some geometric primitive.
459 * This enum specifies how that clipping is performed. Not all factories that take a
460 * GrProcessorEdgeType will succeed with all values and it is up to the caller to check for
463 enum GrPrimitiveEdgeType {
464 kFillBW_GrProcessorEdgeType,
465 kFillAA_GrProcessorEdgeType,
466 kInverseFillBW_GrProcessorEdgeType,
467 kInverseFillAA_GrProcessorEdgeType,
468 kHairlineAA_GrProcessorEdgeType,
470 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
473 static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
475 static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
476 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
479 static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
480 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
481 kInverseFillBW_GrProcessorEdgeType == edgeType);
484 static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
485 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
488 static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
490 case kFillBW_GrProcessorEdgeType:
491 return kInverseFillBW_GrProcessorEdgeType;
492 case kFillAA_GrProcessorEdgeType:
493 return kInverseFillAA_GrProcessorEdgeType;
494 case kInverseFillBW_GrProcessorEdgeType:
495 return kFillBW_GrProcessorEdgeType;
496 case kInverseFillAA_GrProcessorEdgeType:
497 return kFillAA_GrProcessorEdgeType;
498 case kHairlineAA_GrProcessorEdgeType:
499 SkFAIL("Hairline fill isn't invertible.");
501 return kFillAA_GrProcessorEdgeType; // suppress warning.
505 * Indicates the type of pending IO operations that can be recorded for gpu resources.
514 * Indicates the type of data that a GPU buffer will be used for.
517 kVertex_GrBufferType,
520 kDrawIndirect_GrBufferType,
521 kXferCpuToGpu_GrBufferType,
522 kXferGpuToCpu_GrBufferType,
524 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
526 static const int kGrBufferTypeCount = kLast_GrBufferType + 1;
528 static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) {
529 SkASSERT(type >= 0 && type < kGrBufferTypeCount);
530 return type <= kIndex_GrBufferType;
532 GR_STATIC_ASSERT(0 == kVertex_GrBufferType);
533 GR_STATIC_ASSERT(1 == kIndex_GrBufferType);
537 * Provides a performance hint regarding the frequency at which a data store will be accessed.
539 enum GrAccessPattern {
540 /** Data store will be respecified repeatedly and used many times. */
541 kDynamic_GrAccessPattern,
542 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
543 kStatic_GrAccessPattern,
544 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
545 kStream_GrAccessPattern,
547 kLast_GrAccessPattern = kStream_GrAccessPattern
552 // Takes a pointer to a GrCaps, and will suppress prints if required
553 #define GrCapsDebugf(caps, ...) \
554 if (!(caps)->suppressPrints()) { \
555 SkDebugf(__VA_ARGS__); \
558 #define GrCapsDebugf(caps, ...)
562 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
564 enum class GrBackendObjectOwnership : bool {
565 /** Holder does not destroy the backend object. */
567 /** Holder destroys the backend object. */
571 template <typename T> T * const * sk_sp_address_as_pointer_address(sk_sp<T> const * sp) {
572 static_assert(sizeof(T*) == sizeof(sk_sp<T>), "sk_sp not expected size.");
573 return reinterpret_cast<T * const *>(sp);
577 * Object for CPU-GPU synchronization
579 typedef uint64_t GrFence;