blob: 1536f7b229df9236f039cd1196b7224cd93bba81 [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 Salomone225b562017-06-14 13:00:03 -040015class GrCaps;
16
Brian Salomon5e150852017-03-22 14:53:13 -040017// The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might
18// not actually be monotonic, depending on how libstdc++ was built. However, this is only currently
19// used for idle resource purging so it shouldn't cause a correctness problem.
20#if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000)
21using GrStdSteadyClock = std::chrono::monotonic_clock;
22#else
23using GrStdSteadyClock = std::chrono::steady_clock;
24#endif
25
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050026/** This enum indicates the type of antialiasing to be performed. */
Brian Salomonaf9847e2017-03-01 11:28:27 -050027enum class GrAAType : unsigned {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050028 /** No antialiasing */
29 kNone,
30 /** Use fragment shader code to compute a fractional pixel coverage. */
31 kCoverage,
32 /** Use normal MSAA. */
33 kMSAA,
34 /**
35 * Use "mixed samples" MSAA such that the stencil buffer is multisampled but the color buffer is
36 * not.
37 */
38 kMixedSamples
39};
40
Brian Salomon0abc8b42016-12-13 10:22:54 -050041static inline bool GrAATypeIsHW(GrAAType type) {
42 switch (type) {
43 case GrAAType::kNone:
44 return false;
45 case GrAAType::kCoverage:
46 return false;
47 case GrAAType::kMSAA:
48 return true;
49 case GrAAType::kMixedSamples:
50 return true;
51 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040052 SK_ABORT("Unknown AA Type");
Brian Salomon0abc8b42016-12-13 10:22:54 -050053 return false;
54}
55
Brian Salomon7c8460e2017-05-12 11:36:10 -040056/** The type of full scene antialiasing supported by a render target. */
57enum class GrFSAAType {
58 /** No FSAA */
59 kNone,
60 /** Regular MSAA where each attachment has the same sample count. */
61 kUnifiedMSAA,
62 /** One color sample, N stencil samples. */
63 kMixedSamples,
64};
65
66/**
67 * Not all drawing code paths support using mixed samples when available and instead use
68 * coverage-based aa.
69 */
70enum class GrAllowMixedSamples { kNo, kYes };
71
Brian Salomone225b562017-06-14 13:00:03 -040072GrAAType GrChooseAAType(GrAA, GrFSAAType, GrAllowMixedSamples, const GrCaps&);
Brian Salomon7c8460e2017-05-12 11:36:10 -040073
Brian Salomon0abc8b42016-12-13 10:22:54 -050074/**
75 * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars,
76 * but should be applicable to other shader languages.)
77 */
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000078enum GrSLType {
79 kVoid_GrSLType,
Brian Salomonfa26e662016-11-14 11:27:00 -050080 kBool_GrSLType,
Brian Salomonfa26e662016-11-14 11:27:00 -050081 kUint_GrSLType,
Ethan Nicholas88d99c62017-08-16 16:41:30 -040082 kShort_GrSLType,
83 kUShort_GrSLType,
84 kHighFloat_GrSLType,
85 kHighFloat2_GrSLType,
86 kHighFloat3_GrSLType,
87 kHighFloat4_GrSLType,
88 kHighFloat2x2_GrSLType,
89 kHighFloat3x3_GrSLType,
90 kHighFloat4x4_GrSLType,
91 kHalf_GrSLType,
92 kHalf2_GrSLType,
93 kHalf3_GrSLType,
94 kHalf4_GrSLType,
95 kHalf2x2_GrSLType,
96 kHalf3x3_GrSLType,
97 kHalf4x4_GrSLType,
98 kInt_GrSLType,
99 kInt2_GrSLType,
100 kInt3_GrSLType,
101 kInt4_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -0700102 kTexture2DSampler_GrSLType,
Brian Salomona8f00022016-11-16 12:55:57 -0500103 kITexture2DSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -0700104 kTextureExternalSampler_GrSLType,
105 kTexture2DRectSampler_GrSLType,
csmartdalton22458032016-11-16 11:28:16 -0700106 kBufferSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -0700107 kTexture2D_GrSLType,
108 kSampler_GrSLType,
Brian Salomonf9f45122016-11-29 11:59:17 -0500109 kImageStorage2D_GrSLType,
110 kIImageStorage2D_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000111};
112
bsalomon17168df2014-12-09 09:00:49 -0800113enum GrShaderType {
114 kVertex_GrShaderType,
115 kGeometry_GrShaderType,
116 kFragment_GrShaderType,
117
118 kLastkFragment_GrShaderType = kFragment_GrShaderType
119};
120static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
121
cdalton5e58cee2016-02-11 12:49:47 -0800122enum GrShaderFlags {
123 kNone_GrShaderFlags = 0,
124 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
125 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
126 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
127};
128GR_MAKE_BITFIELD_OPS(GrShaderFlags);
129
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000130/**
bsalomonc0bd6482014-12-09 10:04:14 -0800131 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -0800132 * vary the internal precision based on the qualifiers. These currently only apply to float types (
133 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -0800134 */
135enum GrSLPrecision {
136 kLow_GrSLPrecision,
137 kMedium_GrSLPrecision,
138 kHigh_GrSLPrecision,
139
Brian Osman33aa2c72017-04-05 09:26:15 -0400140 // Default precision is a special tag that means "whatever the default for the program/type
141 // combination is". In other words, it maps to the empty string in shader code. There are some
142 // scenarios where kDefault is not allowed (as the default precision for a program, or for
143 // varyings, for example).
144 kDefault_GrSLPrecision,
bsalomonc0bd6482014-12-09 10:04:14 -0800145
Brian Osman33aa2c72017-04-05 09:26:15 -0400146 // We only consider the "real" precisions here
147 kLast_GrSLPrecision = kHigh_GrSLPrecision,
bsalomonc0bd6482014-12-09 10:04:14 -0800148};
149
150static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
151
ethannicholas22793252016-01-30 09:59:10 -0800152/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -0800153static inline bool GrSLTypeIsFloatType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500154 switch (type) {
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400155 case kHighFloat_GrSLType:
156 case kHighFloat2_GrSLType:
157 case kHighFloat3_GrSLType:
158 case kHighFloat4_GrSLType:
159 case kHighFloat2x2_GrSLType:
160 case kHighFloat3x3_GrSLType:
161 case kHighFloat4x4_GrSLType:
162 case kHalf_GrSLType:
163 case kHalf2_GrSLType:
164 case kHalf3_GrSLType:
165 case kHalf4_GrSLType:
166 case kHalf2x2_GrSLType:
167 case kHalf3x3_GrSLType:
168 case kHalf4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500169 return true;
bsalomon422f56f2014-12-09 10:18:12 -0800170
Brian Salomonfa26e662016-11-14 11:27:00 -0500171 case kVoid_GrSLType:
172 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500173 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500174 case kTextureExternalSampler_GrSLType:
175 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700176 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500177 case kBool_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500178 case kUint_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400179 case kShort_GrSLType:
180 case kUShort_GrSLType:
181 case kInt_GrSLType:
182 case kInt2_GrSLType:
183 case kInt3_GrSLType:
184 case kInt4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500185 case kTexture2D_GrSLType:
186 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500187 case kImageStorage2D_GrSLType:
188 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500189 return false;
190 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400191 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500192 return false;
bsalomone5286e02016-01-14 09:24:09 -0800193}
194
egdaniel990dbc82016-07-13 14:09:30 -0700195static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500196 switch (type) {
197 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500198 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500199 case kTextureExternalSampler_GrSLType:
200 case kTexture2DRectSampler_GrSLType:
201 return true;
bsalomone5286e02016-01-14 09:24:09 -0800202
Brian Salomonfa26e662016-11-14 11:27:00 -0500203 case kVoid_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400204 case kHighFloat_GrSLType:
205 case kHighFloat2_GrSLType:
206 case kHighFloat3_GrSLType:
207 case kHighFloat4_GrSLType:
208 case kHighFloat2x2_GrSLType:
209 case kHighFloat3x3_GrSLType:
210 case kHighFloat4x4_GrSLType:
211 case kHalf_GrSLType:
212 case kHalf2_GrSLType:
213 case kHalf3_GrSLType:
214 case kHalf4_GrSLType:
215 case kHalf2x2_GrSLType:
216 case kHalf3x3_GrSLType:
217 case kHalf4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500218 case kInt_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400219 case kInt2_GrSLType:
220 case kInt3_GrSLType:
221 case kInt4_GrSLType:
222 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500223 case kUint_GrSLType:
224 case kBool_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400225 case kShort_GrSLType:
226 case kUShort_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500227 case kTexture2D_GrSLType:
228 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500229 case kImageStorage2D_GrSLType:
230 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500231 return false;
232 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400233 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500234 return false;
egdanielfa896322016-01-13 12:19:30 -0800235}
236
egdaniel990dbc82016-07-13 14:09:30 -0700237static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500238 switch (type) {
239 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500240 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500241 case kTextureExternalSampler_GrSLType:
242 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700243 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500244 return true;
cdalton74b8d322016-04-11 14:47:28 -0700245
Brian Salomonfa26e662016-11-14 11:27:00 -0500246 case kVoid_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400247 case kHighFloat_GrSLType:
248 case kHighFloat2_GrSLType:
249 case kHighFloat3_GrSLType:
250 case kHighFloat4_GrSLType:
251 case kHighFloat2x2_GrSLType:
252 case kHighFloat3x3_GrSLType:
253 case kHighFloat4x4_GrSLType:
254 case kHalf_GrSLType:
255 case kHalf2_GrSLType:
256 case kHalf3_GrSLType:
257 case kHalf4_GrSLType:
258 case kHalf2x2_GrSLType:
259 case kHalf3x3_GrSLType:
260 case kHalf4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500261 case kInt_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400262 case kInt2_GrSLType:
263 case kInt3_GrSLType:
264 case kInt4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500265 case kUint_GrSLType:
266 case kBool_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400267 case kShort_GrSLType:
268 case kUShort_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500269 case kTexture2D_GrSLType:
270 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500271 case kImageStorage2D_GrSLType:
272 case kIImageStorage2D_GrSLType:
273 return false;
274 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400275 SK_ABORT("Unexpected type");
Brian Salomonf9f45122016-11-29 11:59:17 -0500276 return false;
277}
278
279static inline bool GrSLTypeIsImageStorage(GrSLType type) {
280 switch (type) {
281 case kImageStorage2D_GrSLType:
282 case kIImageStorage2D_GrSLType:
283 return true;
284
285 case kVoid_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400286 case kHighFloat_GrSLType:
287 case kHighFloat2_GrSLType:
288 case kHighFloat3_GrSLType:
289 case kHighFloat4_GrSLType:
290 case kHighFloat2x2_GrSLType:
291 case kHighFloat3x3_GrSLType:
292 case kHighFloat4x4_GrSLType:
293 case kHalf_GrSLType:
294 case kHalf2_GrSLType:
295 case kHalf3_GrSLType:
296 case kHalf4_GrSLType:
297 case kHalf2x2_GrSLType:
298 case kHalf3x3_GrSLType:
299 case kHalf4x4_GrSLType:
300 case kInt2_GrSLType:
301 case kInt3_GrSLType:
302 case kInt4_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500303 case kInt_GrSLType:
304 case kUint_GrSLType:
305 case kBool_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400306 case kShort_GrSLType:
307 case kUShort_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500308 case kTexture2D_GrSLType:
309 case kSampler_GrSLType:
310 case kTexture2DSampler_GrSLType:
311 case kITexture2DSampler_GrSLType:
312 case kTextureExternalSampler_GrSLType:
313 case kTexture2DRectSampler_GrSLType:
314 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500315 return false;
316 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400317 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500318 return false;
cdalton74b8d322016-04-11 14:47:28 -0700319}
320
cdalton5f2d8e22016-03-11 13:34:32 -0800321static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500322 switch (type) {
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400323 case kTexture2DSampler_GrSLType:
324 case kITexture2DSampler_GrSLType:
325 case kTextureExternalSampler_GrSLType:
326 case kTexture2DRectSampler_GrSLType:
327 case kBufferSampler_GrSLType:
328 case kTexture2D_GrSLType:
329 case kSampler_GrSLType:
330 case kImageStorage2D_GrSLType:
331 case kIImageStorage2D_GrSLType:
332 return true;
333
334 case kVoid_GrSLType:
335 case kBool_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500336 case kUint_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400337 case kShort_GrSLType:
338 case kUShort_GrSLType:
339 case kHighFloat_GrSLType:
340 case kHighFloat2_GrSLType:
341 case kHighFloat3_GrSLType:
342 case kHighFloat4_GrSLType:
343 case kHighFloat2x2_GrSLType:
344 case kHighFloat3x3_GrSLType:
345 case kHighFloat4x4_GrSLType:
346 case kHalf_GrSLType:
347 case kHalf2_GrSLType:
348 case kHalf3_GrSLType:
349 case kHalf4_GrSLType:
350 case kHalf2x2_GrSLType:
351 case kHalf3x3_GrSLType:
352 case kHalf4x4_GrSLType:
353 case kInt_GrSLType:
354 case kInt2_GrSLType:
355 case kInt3_GrSLType:
356 case kInt4_GrSLType:
357 return false;
358 }
Ben Wagner824e7302017-08-17 09:15:28 -0400359 SK_ABORT("Unexpected type");
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400360 return false;
361}
362
363// temporarily accepting (but ignoring) precision modifiers on the new types; this will be killed
364// in a future CL
365static inline bool GrSLTypeTemporarilyAcceptsPrecision(GrSLType type) {
366 switch (type) {
367 case kUint_GrSLType:
368 case kShort_GrSLType:
369 case kUShort_GrSLType:
370 case kHighFloat_GrSLType:
371 case kHighFloat2_GrSLType:
372 case kHighFloat3_GrSLType:
373 case kHighFloat4_GrSLType:
374 case kHighFloat2x2_GrSLType:
375 case kHighFloat3x3_GrSLType:
376 case kHighFloat4x4_GrSLType:
377 case kHalf_GrSLType:
378 case kHalf2_GrSLType:
379 case kHalf3_GrSLType:
380 case kHalf4_GrSLType:
381 case kHalf2x2_GrSLType:
382 case kHalf3x3_GrSLType:
383 case kHalf4x4_GrSLType:
384 case kInt_GrSLType:
385 case kInt2_GrSLType:
386 case kInt3_GrSLType:
387 case kInt4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500388 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500389 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500390 case kTextureExternalSampler_GrSLType:
391 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700392 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500393 case kTexture2D_GrSLType:
394 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500395 case kImageStorage2D_GrSLType:
396 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500397 return true;
398
399 case kVoid_GrSLType:
400 case kBool_GrSLType:
401 return false;
402 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400403 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500404 return false;
cdalton5f2d8e22016-03-11 13:34:32 -0800405}
406
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000407//////////////////////////////////////////////////////////////////////////////
408
jvanverth@google.com054ae992013-04-01 20:06:51 +0000409/**
410 * Types used to describe format of vertices in arrays.
Brian Salomonc5886032017-07-19 11:48:05 -0400411 */
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000412enum GrVertexAttribType {
413 kFloat_GrVertexAttribType = 0,
414 kVec2f_GrVertexAttribType,
415 kVec3f_GrVertexAttribType,
416 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800417
csmartdaltonb37cb232017-02-08 14:56:27 -0500418 kVec2i_GrVertexAttribType, // vector of 2 32-bit ints
419 kVec3i_GrVertexAttribType, // vector of 3 32-bit ints
420 kVec4i_GrVertexAttribType, // vector of 4 32-bit ints
421
egdaniel37b4d862014-11-03 10:07:07 -0800422 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800423 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000424
Brian Salomonc5886032017-07-19 11:48:05 -0400425 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800426
427 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800428 kUint_GrVertexAttribType,
egdaniel990dbc82016-07-13 14:09:30 -0700429
cdalton793dc262016-02-08 10:11:47 -0800430 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000431};
432static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
433
jvanverth@google.com054ae992013-04-01 20:06:51 +0000434/**
435 * Returns the size of the attrib type in bytes.
436 */
437static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500438 switch (type) {
439 case kFloat_GrVertexAttribType:
440 return sizeof(float);
441 case kVec2f_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400442 return 2 * sizeof(float);
Brian Salomonfa26e662016-11-14 11:27:00 -0500443 case kVec3f_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400444 return 3 * sizeof(float);
Brian Salomonfa26e662016-11-14 11:27:00 -0500445 case kVec4f_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400446 return 4 * sizeof(float);
csmartdaltonb37cb232017-02-08 14:56:27 -0500447 case kVec2i_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400448 return 2 * sizeof(int32_t);
csmartdaltonb37cb232017-02-08 14:56:27 -0500449 case kVec3i_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400450 return 3 * sizeof(int32_t);
csmartdaltonb37cb232017-02-08 14:56:27 -0500451 case kVec4i_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400452 return 4 * sizeof(int32_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500453 case kUByte_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400454 return 1 * sizeof(char);
Brian Salomonfa26e662016-11-14 11:27:00 -0500455 case kVec4ub_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400456 return 4 * sizeof(char);
Brian Salomonfa26e662016-11-14 11:27:00 -0500457 case kVec2us_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400458 return 2 * sizeof(int16_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500459 case kInt_GrVertexAttribType:
460 return sizeof(int32_t);
461 case kUint_GrVertexAttribType:
462 return sizeof(uint32_t);
463 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400464 SK_ABORT("Unexpected attribute type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500465 return 0;
jvanverth@google.com054ae992013-04-01 20:06:51 +0000466}
467
468/**
cdalton793dc262016-02-08 10:11:47 -0800469 * Is the attrib type integral?
470 */
471static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500472 switch (type) {
473 case kFloat_GrVertexAttribType:
474 return false;
475 case kVec2f_GrVertexAttribType:
476 return false;
477 case kVec3f_GrVertexAttribType:
478 return false;
479 case kVec4f_GrVertexAttribType:
480 return false;
csmartdaltonb37cb232017-02-08 14:56:27 -0500481 case kVec2i_GrVertexAttribType:
482 return true;
483 case kVec3i_GrVertexAttribType:
484 return true;
485 case kVec4i_GrVertexAttribType:
486 return true;
Brian Salomonfa26e662016-11-14 11:27:00 -0500487 case kUByte_GrVertexAttribType:
488 return false;
489 case kVec4ub_GrVertexAttribType:
490 return false;
491 case kVec2us_GrVertexAttribType:
492 return false;
493 case kInt_GrVertexAttribType:
494 return true;
495 case kUint_GrVertexAttribType:
496 return true;
497 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400498 SK_ABORT("Unexpected attribute type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500499 return false;
cdalton793dc262016-02-08 10:11:47 -0800500}
501
502/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800503 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000504 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800505static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
506 switch (type) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800507 case kUByte_GrVertexAttribType:
508 case kFloat_GrVertexAttribType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400509 return kHighFloat_GrSLType;
jvanverth7023a002016-02-22 11:25:32 -0800510 case kVec2us_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800511 case kVec2f_GrVertexAttribType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400512 return kHighFloat2_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800513 case kVec3f_GrVertexAttribType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400514 return kHighFloat3_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800515 case kVec4ub_GrVertexAttribType:
516 case kVec4f_GrVertexAttribType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400517 return kHighFloat4_GrSLType;
csmartdaltonb37cb232017-02-08 14:56:27 -0500518 case kVec2i_GrVertexAttribType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400519 return kInt2_GrSLType;
csmartdaltonb37cb232017-02-08 14:56:27 -0500520 case kVec3i_GrVertexAttribType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400521 return kInt3_GrSLType;
csmartdaltonb37cb232017-02-08 14:56:27 -0500522 case kVec4i_GrVertexAttribType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400523 return kInt4_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800524 case kInt_GrVertexAttribType:
525 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800526 case kUint_GrVertexAttribType:
527 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000528 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400529 SK_ABORT("Unsupported type conversion");
Brian Salomonfa26e662016-11-14 11:27:00 -0500530 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800531}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000532
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000533//////////////////////////////////////////////////////////////////////////////
534
Brian Salomonf9f45122016-11-29 11:59:17 -0500535enum class GrImageStorageFormat {
536 kRGBA8,
537 kRGBA8i,
538 kRGBA16f,
539 kRGBA32f,
540};
541
542/**
543 * Describes types of caching and compiler optimizations allowed for certain variable types
544 * (currently only image storages).
545 **/
546enum class GrSLMemoryModel {
547 /** No special restrctions on memory accesses or compiler optimizations */
548 kNone,
549 /** Cache coherent across shader invocations */
550 kCoherent,
551 /**
552 * Disallows compiler from eliding loads or stores that appear redundant in a single
553 * invocation. Implies coherent.
554 */
555 kVolatile
556};
557
558/**
559 * If kYes then the memory backing the varialble is only accessed via the variable. This is
560 * currently only used with image storages.
561 */
562enum class GrSLRestrict {
563 kYes,
564 kNo,
565};
566
567//////////////////////////////////////////////////////////////////////////////
568
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000569/**
Brian Salomonc5886032017-07-19 11:48:05 -0400570 * We have coverage effects that clip rendering to the edge of some geometric primitive.
571 * This enum specifies how that clipping is performed. Not all factories that take a
572 * GrProcessorEdgeType will succeed with all values and it is up to the caller to check for
573 * a NULL return.
574 */
joshualittb0a8a372014-09-23 09:50:21 -0700575enum GrPrimitiveEdgeType {
576 kFillBW_GrProcessorEdgeType,
577 kFillAA_GrProcessorEdgeType,
578 kInverseFillBW_GrProcessorEdgeType,
579 kInverseFillAA_GrProcessorEdgeType,
580 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000581
joshualittb0a8a372014-09-23 09:50:21 -0700582 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000583};
584
joshualittb0a8a372014-09-23 09:50:21 -0700585static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000586
joshualittb0a8a372014-09-23 09:50:21 -0700587static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
588 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000589}
590
joshualittb0a8a372014-09-23 09:50:21 -0700591static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
592 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
593 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000594}
595
joshualittb0a8a372014-09-23 09:50:21 -0700596static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
Brian Salomonc5886032017-07-19 11:48:05 -0400597 return (kFillBW_GrProcessorEdgeType != edgeType &&
598 kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000599}
600
joshualittb0a8a372014-09-23 09:50:21 -0700601static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000602 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700603 case kFillBW_GrProcessorEdgeType:
604 return kInverseFillBW_GrProcessorEdgeType;
605 case kFillAA_GrProcessorEdgeType:
606 return kInverseFillAA_GrProcessorEdgeType;
607 case kInverseFillBW_GrProcessorEdgeType:
608 return kFillBW_GrProcessorEdgeType;
609 case kInverseFillAA_GrProcessorEdgeType:
610 return kFillAA_GrProcessorEdgeType;
611 case kHairlineAA_GrProcessorEdgeType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400612 SK_ABORT("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000613 }
Brian Salomonc5886032017-07-19 11:48:05 -0400614 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000615}
616
bsalomonbcf0a522014-10-08 08:40:09 -0700617/**
618 * Indicates the type of pending IO operations that can be recorded for gpu resources.
619 */
620enum GrIOType {
621 kRead_GrIOType,
622 kWrite_GrIOType,
623 kRW_GrIOType
624};
625
jvanverth17aa0472016-01-05 10:41:27 -0800626/**
Brian Salomonc5886032017-07-19 11:48:05 -0400627 * Indicates the type of data that a GPU buffer will be used for.
628 */
cdalton397536c2016-03-25 12:15:03 -0700629enum GrBufferType {
630 kVertex_GrBufferType,
631 kIndex_GrBufferType,
cdaltone2e71c22016-04-07 18:13:29 -0700632 kTexel_GrBufferType,
633 kDrawIndirect_GrBufferType,
cdalton397536c2016-03-25 12:15:03 -0700634 kXferCpuToGpu_GrBufferType,
635 kXferGpuToCpu_GrBufferType,
636
637 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
638};
cdaltone2e71c22016-04-07 18:13:29 -0700639static const int kGrBufferTypeCount = kLast_GrBufferType + 1;
640
641static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) {
642 SkASSERT(type >= 0 && type < kGrBufferTypeCount);
643 return type <= kIndex_GrBufferType;
644
645 GR_STATIC_ASSERT(0 == kVertex_GrBufferType);
646 GR_STATIC_ASSERT(1 == kIndex_GrBufferType);
647}
cdalton397536c2016-03-25 12:15:03 -0700648
649/**
Brian Salomonc5886032017-07-19 11:48:05 -0400650 * Provides a performance hint regarding the frequency at which a data store will be accessed.
651 */
cdalton397536c2016-03-25 12:15:03 -0700652enum GrAccessPattern {
653 /** Data store will be respecified repeatedly and used many times. */
654 kDynamic_GrAccessPattern,
655 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
656 kStatic_GrAccessPattern,
657 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
658 kStream_GrAccessPattern,
659
660 kLast_GrAccessPattern = kStream_GrAccessPattern
jvanverth17aa0472016-01-05 10:41:27 -0800661};
662
Robert Phillipsc4f0a822017-06-13 08:11:36 -0400663// Flags shared between GrRenderTarget and GrRenderTargetProxy
664enum class GrRenderTargetFlags {
665 kNone = 0,
666
667 // For internal resources:
668 // this is enabled whenever MSAA is enabled and GrCaps reports mixed samples are supported
669 // For wrapped resources:
670 // this is disabled for FBO0
671 // but, otherwise, is enabled whenever MSAA is enabled and GrCaps reports mixed samples
672 // are supported
673 kMixedSampled = 1 << 0,
674
675 // For internal resources:
676 // this is enabled whenever GrCaps reports window rect support
677 // For wrapped resources1
678 // this is disabled for FBO0
679 // but, otherwise, is enabled whenever GrCaps reports window rect support
680 kWindowRectsSupport = 1 << 1
681};
682GR_MAKE_BITFIELD_CLASS_OPS(GrRenderTargetFlags)
jvanverth17aa0472016-01-05 10:41:27 -0800683
joshualitt7d022d62015-05-12 12:03:50 -0700684#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700685// Takes a pointer to a GrCaps, and will suppress prints if required
Brian Salomonc5886032017-07-19 11:48:05 -0400686#define GrCapsDebugf(caps, ...) \
687 if (!(caps)->suppressPrints()) { \
688 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700689 }
690#else
bsalomon682c2692015-05-22 14:01:46 -0700691#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700692#endif
693
kkinnunen2e6055b2016-04-22 01:48:29 -0700694/**
695 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
696 */
697enum class GrBackendObjectOwnership : bool {
698 /** Holder does not destroy the backend object. */
699 kBorrowed = false,
700 /** Holder destroys the backend object. */
701 kOwned = true
702};
703
Brian Salomonaff329b2017-08-11 09:40:37 -0400704template <typename T>
705T* const* unique_ptr_address_as_pointer_address(std::unique_ptr<T> const* up) {
706 static_assert(sizeof(T*) == sizeof(std::unique_ptr<T>), "unique_ptr not expected size.");
707 return reinterpret_cast<T* const*>(up);
bungeman06ca8ec2016-06-09 08:01:03 -0700708}
709
jvanverth84741b32016-09-30 08:39:02 -0700710/*
711 * Object for CPU-GPU synchronization
712 */
Greg Daniel6be35232017-03-01 17:01:09 -0500713typedef uint64_t GrFence;
jvanverth84741b32016-09-30 08:39:02 -0700714
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000715#endif