blob: 4ecab9cc01574acf99bd64e9134f7b6e838acd48 [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
jvanverth@google.com054ae992013-04-01 20:06:51 +000011#include "GrTypes.h"
bungeman06ca8ec2016-06-09 08:01:03 -070012#include "SkRefCnt.h"
bsalomon@google.com31ec7982013-03-27 18:14:57 +000013
bsalomoncdee0092016-01-08 13:20:12 -080014 /**
15 * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars,
16 * but should be applicable to other shader languages.)
17 */
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000018enum GrSLType {
19 kVoid_GrSLType,
Brian Salomonfa26e662016-11-14 11:27:00 -050020 kBool_GrSLType,
21 kInt_GrSLType,
22 kUint_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000023 kFloat_GrSLType,
24 kVec2f_GrSLType,
25 kVec3f_GrSLType,
26 kVec4f_GrSLType,
cdalton8d988b32016-03-07 15:39:09 -080027 kMat22f_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000028 kMat33f_GrSLType,
29 kMat44f_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070030 kTexture2DSampler_GrSLType,
Brian Salomona8f00022016-11-16 12:55:57 -050031 kITexture2DSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070032 kTextureExternalSampler_GrSLType,
33 kTexture2DRectSampler_GrSLType,
csmartdalton22458032016-11-16 11:28:16 -070034 kBufferSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070035 kTexture2D_GrSLType,
36 kSampler_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000037};
38
bsalomon17168df2014-12-09 09:00:49 -080039enum GrShaderType {
40 kVertex_GrShaderType,
41 kGeometry_GrShaderType,
42 kFragment_GrShaderType,
43
44 kLastkFragment_GrShaderType = kFragment_GrShaderType
45};
46static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
47
cdalton5e58cee2016-02-11 12:49:47 -080048enum GrShaderFlags {
49 kNone_GrShaderFlags = 0,
50 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
51 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
52 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
53};
54GR_MAKE_BITFIELD_OPS(GrShaderFlags);
55
robertphillips5fa7f302016-07-21 09:21:04 -070056enum class GrDrawFace {
57 kInvalid = -1,
58
59 kBoth,
60 kCCW,
61 kCW,
62};
63
bsalomon@google.com31ec7982013-03-27 18:14:57 +000064/**
bsalomonc0bd6482014-12-09 10:04:14 -080065 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -080066 * vary the internal precision based on the qualifiers. These currently only apply to float types (
67 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -080068 */
69enum GrSLPrecision {
70 kLow_GrSLPrecision,
71 kMedium_GrSLPrecision,
72 kHigh_GrSLPrecision,
73
74 // Default precision is medium. This is because on OpenGL ES 2 highp support is not
75 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
76 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
77
78 kLast_GrSLPrecision = kHigh_GrSLPrecision
79};
80
81static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
82
ethannicholas22793252016-01-30 09:59:10 -080083/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -080084static inline bool GrSLTypeIsFloatType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -050085 switch (type) {
86 case kFloat_GrSLType:
87 case kVec2f_GrSLType:
88 case kVec3f_GrSLType:
89 case kVec4f_GrSLType:
90 case kMat22f_GrSLType:
91 case kMat33f_GrSLType:
92 case kMat44f_GrSLType:
93 return true;
bsalomon422f56f2014-12-09 10:18:12 -080094
Brian Salomonfa26e662016-11-14 11:27:00 -050095 case kVoid_GrSLType:
96 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -050097 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050098 case kTextureExternalSampler_GrSLType:
99 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700100 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500101 case kBool_GrSLType:
102 case kInt_GrSLType:
103 case kUint_GrSLType:
104 case kTexture2D_GrSLType:
105 case kSampler_GrSLType:
106 return false;
107 }
108 SkFAIL("Unexpected type");
109 return false;
bsalomone5286e02016-01-14 09:24:09 -0800110}
111
egdaniel990dbc82016-07-13 14:09:30 -0700112static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500113 switch (type) {
114 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500115 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500116 case kTextureExternalSampler_GrSLType:
117 case kTexture2DRectSampler_GrSLType:
118 return true;
bsalomone5286e02016-01-14 09:24:09 -0800119
Brian Salomonfa26e662016-11-14 11:27:00 -0500120 case kVoid_GrSLType:
121 case kFloat_GrSLType:
122 case kVec2f_GrSLType:
123 case kVec3f_GrSLType:
124 case kVec4f_GrSLType:
125 case kMat22f_GrSLType:
126 case kMat33f_GrSLType:
127 case kMat44f_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700128 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500129 case kInt_GrSLType:
130 case kUint_GrSLType:
131 case kBool_GrSLType:
132 case kTexture2D_GrSLType:
133 case kSampler_GrSLType:
134 return false;
135 }
136 SkFAIL("Unexpected type");
137 return false;
egdanielfa896322016-01-13 12:19:30 -0800138}
139
egdaniel990dbc82016-07-13 14:09:30 -0700140static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500141 switch (type) {
142 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500143 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500144 case kTextureExternalSampler_GrSLType:
145 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700146 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500147 return true;
cdalton74b8d322016-04-11 14:47:28 -0700148
Brian Salomonfa26e662016-11-14 11:27:00 -0500149 case kVoid_GrSLType:
150 case kFloat_GrSLType:
151 case kVec2f_GrSLType:
152 case kVec3f_GrSLType:
153 case kVec4f_GrSLType:
154 case kMat22f_GrSLType:
155 case kMat33f_GrSLType:
156 case kMat44f_GrSLType:
157 case kInt_GrSLType:
158 case kUint_GrSLType:
159 case kBool_GrSLType:
160 case kTexture2D_GrSLType:
161 case kSampler_GrSLType:
162 return false;
163 }
164 SkFAIL("Unexpected type");
165 return false;
cdalton74b8d322016-04-11 14:47:28 -0700166}
167
cdalton5f2d8e22016-03-11 13:34:32 -0800168static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500169 switch (type) {
170 case kInt_GrSLType:
171 case kUint_GrSLType:
172 case kFloat_GrSLType:
173 case kVec2f_GrSLType:
174 case kVec3f_GrSLType:
175 case kVec4f_GrSLType:
176 case kMat22f_GrSLType:
177 case kMat33f_GrSLType:
178 case kMat44f_GrSLType:
179 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500180 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500181 case kTextureExternalSampler_GrSLType:
182 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700183 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500184 case kTexture2D_GrSLType:
185 case kSampler_GrSLType:
186 return true;
187
188 case kVoid_GrSLType:
189 case kBool_GrSLType:
190 return false;
191 }
192 SkFAIL("Unexpected type");
193 return false;
cdalton5f2d8e22016-03-11 13:34:32 -0800194}
195
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000196//////////////////////////////////////////////////////////////////////////////
197
jvanverth@google.com054ae992013-04-01 20:06:51 +0000198/**
199 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000200 */
201enum GrVertexAttribType {
202 kFloat_GrVertexAttribType = 0,
203 kVec2f_GrVertexAttribType,
204 kVec3f_GrVertexAttribType,
205 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800206
207 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800208 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000209
jvanverth7023a002016-02-22 11:25:32 -0800210 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800211
212 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800213 kUint_GrVertexAttribType,
egdaniel990dbc82016-07-13 14:09:30 -0700214
cdalton793dc262016-02-08 10:11:47 -0800215 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000216};
217static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
218
jvanverth@google.com054ae992013-04-01 20:06:51 +0000219
220/**
221 * Returns the size of the attrib type in bytes.
222 */
223static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500224 switch (type) {
225 case kFloat_GrVertexAttribType:
226 return sizeof(float);
227 case kVec2f_GrVertexAttribType:
228 return 2*sizeof(float);
229 case kVec3f_GrVertexAttribType:
230 return 3*sizeof(float);
231 case kVec4f_GrVertexAttribType:
232 return 4*sizeof(float);
233 case kUByte_GrVertexAttribType:
234 return 1*sizeof(char);
235 case kVec4ub_GrVertexAttribType:
236 return 4*sizeof(char);
237 case kVec2us_GrVertexAttribType:
238 return 2*sizeof(int16_t);
239 case kInt_GrVertexAttribType:
240 return sizeof(int32_t);
241 case kUint_GrVertexAttribType:
242 return sizeof(uint32_t);
243 }
244 SkFAIL("Unexpected attribute type");
245 return 0;
jvanverth@google.com054ae992013-04-01 20:06:51 +0000246}
247
248/**
cdalton793dc262016-02-08 10:11:47 -0800249 * Is the attrib type integral?
250 */
251static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500252 switch (type) {
253 case kFloat_GrVertexAttribType:
254 return false;
255 case kVec2f_GrVertexAttribType:
256 return false;
257 case kVec3f_GrVertexAttribType:
258 return false;
259 case kVec4f_GrVertexAttribType:
260 return false;
261 case kUByte_GrVertexAttribType:
262 return false;
263 case kVec4ub_GrVertexAttribType:
264 return false;
265 case kVec2us_GrVertexAttribType:
266 return false;
267 case kInt_GrVertexAttribType:
268 return true;
269 case kUint_GrVertexAttribType:
270 return true;
271 }
272 SkFAIL("Unexpected attribute type");
273 return false;
cdalton793dc262016-02-08 10:11:47 -0800274}
275
276/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800277 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000278 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800279static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
280 switch (type) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800281 case kUByte_GrVertexAttribType:
282 case kFloat_GrVertexAttribType:
283 return kFloat_GrSLType;
jvanverth7023a002016-02-22 11:25:32 -0800284 case kVec2us_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800285 case kVec2f_GrVertexAttribType:
286 return kVec2f_GrSLType;
287 case kVec3f_GrVertexAttribType:
288 return kVec3f_GrSLType;
289 case kVec4ub_GrVertexAttribType:
290 case kVec4f_GrVertexAttribType:
291 return kVec4f_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800292 case kInt_GrVertexAttribType:
293 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800294 case kUint_GrVertexAttribType:
295 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000296 }
Brian Salomonfa26e662016-11-14 11:27:00 -0500297 SkFAIL("Unsupported type conversion");
298 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800299}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000300
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000301//////////////////////////////////////////////////////////////////////////////
302
303/**
304* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000305* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700306* 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 +0000307* a NULL return.
308*/
joshualittb0a8a372014-09-23 09:50:21 -0700309enum GrPrimitiveEdgeType {
310 kFillBW_GrProcessorEdgeType,
311 kFillAA_GrProcessorEdgeType,
312 kInverseFillBW_GrProcessorEdgeType,
313 kInverseFillAA_GrProcessorEdgeType,
314 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000315
joshualittb0a8a372014-09-23 09:50:21 -0700316 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000317};
318
joshualittb0a8a372014-09-23 09:50:21 -0700319static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000320
joshualittb0a8a372014-09-23 09:50:21 -0700321static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
322 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000323}
324
joshualittb0a8a372014-09-23 09:50:21 -0700325static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
326 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
327 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000328}
329
joshualittb0a8a372014-09-23 09:50:21 -0700330static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
331 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000332}
333
joshualittb0a8a372014-09-23 09:50:21 -0700334static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000335 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700336 case kFillBW_GrProcessorEdgeType:
337 return kInverseFillBW_GrProcessorEdgeType;
338 case kFillAA_GrProcessorEdgeType:
339 return kInverseFillAA_GrProcessorEdgeType;
340 case kInverseFillBW_GrProcessorEdgeType:
341 return kFillBW_GrProcessorEdgeType;
342 case kInverseFillAA_GrProcessorEdgeType:
343 return kFillAA_GrProcessorEdgeType;
344 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000345 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000346 }
joshualittb0a8a372014-09-23 09:50:21 -0700347 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000348}
349
bsalomonbcf0a522014-10-08 08:40:09 -0700350/**
351 * Indicates the type of pending IO operations that can be recorded for gpu resources.
352 */
353enum GrIOType {
354 kRead_GrIOType,
355 kWrite_GrIOType,
356 kRW_GrIOType
357};
358
jvanverth17aa0472016-01-05 10:41:27 -0800359/**
cdalton397536c2016-03-25 12:15:03 -0700360* Indicates the type of data that a GPU buffer will be used for.
361*/
362enum GrBufferType {
363 kVertex_GrBufferType,
364 kIndex_GrBufferType,
cdaltone2e71c22016-04-07 18:13:29 -0700365 kTexel_GrBufferType,
366 kDrawIndirect_GrBufferType,
cdalton397536c2016-03-25 12:15:03 -0700367 kXferCpuToGpu_GrBufferType,
368 kXferGpuToCpu_GrBufferType,
369
370 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
371};
cdaltone2e71c22016-04-07 18:13:29 -0700372static const int kGrBufferTypeCount = kLast_GrBufferType + 1;
373
374static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) {
375 SkASSERT(type >= 0 && type < kGrBufferTypeCount);
376 return type <= kIndex_GrBufferType;
377
378 GR_STATIC_ASSERT(0 == kVertex_GrBufferType);
379 GR_STATIC_ASSERT(1 == kIndex_GrBufferType);
380}
cdalton397536c2016-03-25 12:15:03 -0700381
382/**
383* Provides a performance hint regarding the frequency at which a data store will be accessed.
384*/
385enum GrAccessPattern {
386 /** Data store will be respecified repeatedly and used many times. */
387 kDynamic_GrAccessPattern,
388 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
389 kStatic_GrAccessPattern,
390 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
391 kStream_GrAccessPattern,
392
393 kLast_GrAccessPattern = kStream_GrAccessPattern
jvanverth17aa0472016-01-05 10:41:27 -0800394};
395
396
joshualitt7d022d62015-05-12 12:03:50 -0700397#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700398// Takes a pointer to a GrCaps, and will suppress prints if required
399#define GrCapsDebugf(caps, ...) \
400 if (!caps->suppressPrints()) { \
401 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700402 }
403#else
bsalomon682c2692015-05-22 14:01:46 -0700404#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700405#endif
406
kkinnunen2e6055b2016-04-22 01:48:29 -0700407/**
408 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
409 */
410enum class GrBackendObjectOwnership : bool {
411 /** Holder does not destroy the backend object. */
412 kBorrowed = false,
413 /** Holder destroys the backend object. */
414 kOwned = true
415};
416
bungeman06ca8ec2016-06-09 08:01:03 -0700417template <typename T> T * const * sk_sp_address_as_pointer_address(sk_sp<T> const * sp) {
418 static_assert(sizeof(T*) == sizeof(sk_sp<T>), "sk_sp not expected size.");
419 return reinterpret_cast<T * const *>(sp);
420}
421
jvanverth84741b32016-09-30 08:39:02 -0700422/*
423 * Object for CPU-GPU synchronization
424 */
425typedef intptr_t GrFence;
426
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000427#endif