blob: cfa5bbc972da17d98b77b1de24ff10ec51c1434f [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
Robert Phillips6b47c7d2017-08-29 07:24:09 -040026/** This enum is used to specify the load operation to be used when an
27 * opList/GrGpuCommandBuffer begins execution.
28 */
29enum class GrLoadOp {
30 kLoad,
31 kClear,
32 kDiscard,
33};
34
35/** This enum is used to specify the store operation to be used when an
36 * opList/GrGpuCommandBuffer ends execution.
37 */
38enum class GrStoreOp {
39 kStore,
40 kDiscard,
41};
42
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050043/** This enum indicates the type of antialiasing to be performed. */
Brian Salomonaf9847e2017-03-01 11:28:27 -050044enum class GrAAType : unsigned {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050045 /** No antialiasing */
46 kNone,
47 /** Use fragment shader code to compute a fractional pixel coverage. */
48 kCoverage,
49 /** Use normal MSAA. */
50 kMSAA,
51 /**
52 * Use "mixed samples" MSAA such that the stencil buffer is multisampled but the color buffer is
53 * not.
54 */
55 kMixedSamples
56};
57
Brian Salomon0abc8b42016-12-13 10:22:54 -050058static inline bool GrAATypeIsHW(GrAAType type) {
59 switch (type) {
60 case GrAAType::kNone:
61 return false;
62 case GrAAType::kCoverage:
63 return false;
64 case GrAAType::kMSAA:
65 return true;
66 case GrAAType::kMixedSamples:
67 return true;
68 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040069 SK_ABORT("Unknown AA Type");
Brian Salomon0abc8b42016-12-13 10:22:54 -050070 return false;
71}
72
Brian Salomon7c8460e2017-05-12 11:36:10 -040073/** The type of full scene antialiasing supported by a render target. */
74enum class GrFSAAType {
75 /** No FSAA */
76 kNone,
77 /** Regular MSAA where each attachment has the same sample count. */
78 kUnifiedMSAA,
79 /** One color sample, N stencil samples. */
80 kMixedSamples,
81};
82
83/**
84 * Not all drawing code paths support using mixed samples when available and instead use
85 * coverage-based aa.
86 */
87enum class GrAllowMixedSamples { kNo, kYes };
88
Brian Salomone225b562017-06-14 13:00:03 -040089GrAAType GrChooseAAType(GrAA, GrFSAAType, GrAllowMixedSamples, const GrCaps&);
Brian Salomon7c8460e2017-05-12 11:36:10 -040090
Brian Salomon0abc8b42016-12-13 10:22:54 -050091/**
92 * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars,
93 * but should be applicable to other shader languages.)
94 */
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000095enum GrSLType {
96 kVoid_GrSLType,
Brian Salomonfa26e662016-11-14 11:27:00 -050097 kBool_GrSLType,
Ethan Nicholasf7b88202017-09-18 14:10:39 -040098 kShort_GrSLType,
99 kUShort_GrSLType,
100 kHighFloat_GrSLType,
101 kHighFloat2_GrSLType,
102 kHighFloat3_GrSLType,
103 kHighFloat4_GrSLType,
104 kHighFloat2x2_GrSLType,
105 kHighFloat3x3_GrSLType,
106 kHighFloat4x4_GrSLType,
107 kHalf_GrSLType,
108 kHalf2_GrSLType,
109 kHalf3_GrSLType,
110 kHalf4_GrSLType,
111 kHalf2x2_GrSLType,
112 kHalf3x3_GrSLType,
113 kHalf4x4_GrSLType,
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400114 kInt_GrSLType,
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400115 kInt2_GrSLType,
116 kInt3_GrSLType,
117 kInt4_GrSLType,
Brian Salomon1d816b92017-08-17 11:07:59 -0400118 kUint_GrSLType,
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400119 kUint2_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -0700120 kTexture2DSampler_GrSLType,
Brian Salomona8f00022016-11-16 12:55:57 -0500121 kITexture2DSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -0700122 kTextureExternalSampler_GrSLType,
123 kTexture2DRectSampler_GrSLType,
csmartdalton22458032016-11-16 11:28:16 -0700124 kBufferSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -0700125 kTexture2D_GrSLType,
126 kSampler_GrSLType,
Brian Salomonf9f45122016-11-29 11:59:17 -0500127 kImageStorage2D_GrSLType,
128 kIImageStorage2D_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000129};
130
bsalomon17168df2014-12-09 09:00:49 -0800131enum GrShaderType {
132 kVertex_GrShaderType,
133 kGeometry_GrShaderType,
134 kFragment_GrShaderType,
135
136 kLastkFragment_GrShaderType = kFragment_GrShaderType
137};
138static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
139
cdalton5e58cee2016-02-11 12:49:47 -0800140enum GrShaderFlags {
141 kNone_GrShaderFlags = 0,
142 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
143 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
144 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
145};
146GR_MAKE_BITFIELD_OPS(GrShaderFlags);
147
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000148/**
bsalomonc0bd6482014-12-09 10:04:14 -0800149 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -0800150 * vary the internal precision based on the qualifiers. These currently only apply to float types (
151 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -0800152 */
153enum GrSLPrecision {
154 kLow_GrSLPrecision,
155 kMedium_GrSLPrecision,
156 kHigh_GrSLPrecision,
157
Brian Osman33aa2c72017-04-05 09:26:15 -0400158 // Default precision is a special tag that means "whatever the default for the program/type
159 // combination is". In other words, it maps to the empty string in shader code. There are some
160 // scenarios where kDefault is not allowed (as the default precision for a program, or for
161 // varyings, for example).
162 kDefault_GrSLPrecision,
bsalomonc0bd6482014-12-09 10:04:14 -0800163
Brian Osman33aa2c72017-04-05 09:26:15 -0400164 // We only consider the "real" precisions here
165 kLast_GrSLPrecision = kHigh_GrSLPrecision,
bsalomonc0bd6482014-12-09 10:04:14 -0800166};
167
168static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
169
ethannicholas22793252016-01-30 09:59:10 -0800170/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -0800171static inline bool GrSLTypeIsFloatType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500172 switch (type) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400173 case kHighFloat_GrSLType:
174 case kHighFloat2_GrSLType:
175 case kHighFloat3_GrSLType:
176 case kHighFloat4_GrSLType:
177 case kHighFloat2x2_GrSLType:
178 case kHighFloat3x3_GrSLType:
179 case kHighFloat4x4_GrSLType:
180 case kHalf_GrSLType:
181 case kHalf2_GrSLType:
182 case kHalf3_GrSLType:
183 case kHalf4_GrSLType:
184 case kHalf2x2_GrSLType:
185 case kHalf3x3_GrSLType:
186 case kHalf4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500187 return true;
bsalomon422f56f2014-12-09 10:18:12 -0800188
Brian Salomonfa26e662016-11-14 11:27:00 -0500189 case kVoid_GrSLType:
190 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500191 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500192 case kTextureExternalSampler_GrSLType:
193 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700194 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500195 case kBool_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400196 case kShort_GrSLType:
197 case kUShort_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400198 case kInt_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400199 case kInt2_GrSLType:
200 case kInt3_GrSLType:
201 case kInt4_GrSLType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400202 case kUint_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400203 case kUint2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500204 case kTexture2D_GrSLType:
205 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500206 case kImageStorage2D_GrSLType:
207 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500208 return false;
209 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400210 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500211 return false;
bsalomone5286e02016-01-14 09:24:09 -0800212}
213
egdaniel990dbc82016-07-13 14:09:30 -0700214static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500215 switch (type) {
216 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500217 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500218 case kTextureExternalSampler_GrSLType:
219 case kTexture2DRectSampler_GrSLType:
220 return true;
bsalomone5286e02016-01-14 09:24:09 -0800221
Brian Salomonfa26e662016-11-14 11:27:00 -0500222 case kVoid_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400223 case kHighFloat_GrSLType:
224 case kHighFloat2_GrSLType:
225 case kHighFloat3_GrSLType:
226 case kHighFloat4_GrSLType:
227 case kHighFloat2x2_GrSLType:
228 case kHighFloat3x3_GrSLType:
229 case kHighFloat4x4_GrSLType:
230 case kHalf_GrSLType:
231 case kHalf2_GrSLType:
232 case kHalf3_GrSLType:
233 case kHalf4_GrSLType:
234 case kHalf2x2_GrSLType:
235 case kHalf3x3_GrSLType:
236 case kHalf4x4_GrSLType:
Ethan Nicholas27185a92017-09-18 02:41:08 +0000237 case kInt_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400238 case kInt2_GrSLType:
239 case kInt3_GrSLType:
240 case kInt4_GrSLType:
Ethan Nicholas27185a92017-09-18 02:41:08 +0000241 case kUint_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400242 case kUint2_GrSLType:
243 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500244 case kBool_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400245 case kShort_GrSLType:
246 case kUShort_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500247 case kTexture2D_GrSLType:
248 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500249 case kImageStorage2D_GrSLType:
250 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500251 return false;
252 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400253 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500254 return false;
egdanielfa896322016-01-13 12:19:30 -0800255}
256
egdaniel990dbc82016-07-13 14:09:30 -0700257static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500258 switch (type) {
259 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500260 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500261 case kTextureExternalSampler_GrSLType:
262 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700263 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500264 return true;
cdalton74b8d322016-04-11 14:47:28 -0700265
Brian Salomonfa26e662016-11-14 11:27:00 -0500266 case kVoid_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400267 case kHighFloat_GrSLType:
268 case kHighFloat2_GrSLType:
269 case kHighFloat3_GrSLType:
270 case kHighFloat4_GrSLType:
271 case kHighFloat2x2_GrSLType:
272 case kHighFloat3x3_GrSLType:
273 case kHighFloat4x4_GrSLType:
274 case kHalf_GrSLType:
275 case kHalf2_GrSLType:
276 case kHalf3_GrSLType:
277 case kHalf4_GrSLType:
278 case kHalf2x2_GrSLType:
279 case kHalf3x3_GrSLType:
280 case kHalf4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500281 case kInt_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400282 case kInt2_GrSLType:
283 case kInt3_GrSLType:
284 case kInt4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500285 case kUint_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400286 case kUint2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500287 case kBool_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400288 case kShort_GrSLType:
289 case kUShort_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500290 case kTexture2D_GrSLType:
291 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500292 case kImageStorage2D_GrSLType:
293 case kIImageStorage2D_GrSLType:
294 return false;
295 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400296 SK_ABORT("Unexpected type");
Brian Salomonf9f45122016-11-29 11:59:17 -0500297 return false;
298}
299
300static inline bool GrSLTypeIsImageStorage(GrSLType type) {
301 switch (type) {
302 case kImageStorage2D_GrSLType:
303 case kIImageStorage2D_GrSLType:
304 return true;
305
306 case kVoid_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400307 case kHighFloat_GrSLType:
308 case kHighFloat2_GrSLType:
309 case kHighFloat3_GrSLType:
310 case kHighFloat4_GrSLType:
311 case kHighFloat2x2_GrSLType:
312 case kHighFloat3x3_GrSLType:
313 case kHighFloat4x4_GrSLType:
314 case kHalf_GrSLType:
315 case kHalf2_GrSLType:
316 case kHalf3_GrSLType:
317 case kHalf4_GrSLType:
318 case kHalf2x2_GrSLType:
319 case kHalf3x3_GrSLType:
320 case kHalf4x4_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500321 case kInt_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400322 case kInt2_GrSLType:
323 case kInt3_GrSLType:
324 case kInt4_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500325 case kUint_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400326 case kUint2_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500327 case kBool_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400328 case kShort_GrSLType:
329 case kUShort_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500330 case kTexture2D_GrSLType:
331 case kSampler_GrSLType:
332 case kTexture2DSampler_GrSLType:
333 case kITexture2DSampler_GrSLType:
334 case kTextureExternalSampler_GrSLType:
335 case kTexture2DRectSampler_GrSLType:
336 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500337 return false;
338 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400339 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500340 return false;
cdalton74b8d322016-04-11 14:47:28 -0700341}
342
cdalton5f2d8e22016-03-11 13:34:32 -0800343static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500344 switch (type) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400345 case kTexture2DSampler_GrSLType:
346 case kITexture2DSampler_GrSLType:
347 case kTextureExternalSampler_GrSLType:
348 case kTexture2DRectSampler_GrSLType:
349 case kBufferSampler_GrSLType:
350 case kTexture2D_GrSLType:
351 case kSampler_GrSLType:
352 case kImageStorage2D_GrSLType:
353 case kIImageStorage2D_GrSLType:
354 return true;
355
356 case kVoid_GrSLType:
357 case kBool_GrSLType:
358 case kShort_GrSLType:
359 case kUShort_GrSLType:
360 case kHighFloat_GrSLType:
361 case kHighFloat2_GrSLType:
362 case kHighFloat3_GrSLType:
363 case kHighFloat4_GrSLType:
364 case kHighFloat2x2_GrSLType:
365 case kHighFloat3x3_GrSLType:
366 case kHighFloat4x4_GrSLType:
367 case kHalf_GrSLType:
368 case kHalf2_GrSLType:
369 case kHalf3_GrSLType:
370 case kHalf4_GrSLType:
371 case kHalf2x2_GrSLType:
372 case kHalf3x3_GrSLType:
373 case kHalf4x4_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400374 case kInt_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400375 case kInt2_GrSLType:
376 case kInt3_GrSLType:
377 case kInt4_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400378 case kUint_GrSLType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400379 case kUint2_GrSLType:
380 return false;
381 }
382 SK_ABORT("Unexpected type");
383 return false;
384}
385
386// temporarily accepting (but ignoring) precision modifiers on the new types; this will be killed
387// in a future CL
388static inline bool GrSLTypeTemporarilyAcceptsPrecision(GrSLType type) {
389 switch (type) {
390 case kShort_GrSLType:
391 case kUShort_GrSLType:
392 case kHighFloat_GrSLType:
393 case kHighFloat2_GrSLType:
394 case kHighFloat3_GrSLType:
395 case kHighFloat4_GrSLType:
396 case kHighFloat2x2_GrSLType:
397 case kHighFloat3x3_GrSLType:
398 case kHighFloat4x4_GrSLType:
399 case kHalf_GrSLType:
400 case kHalf2_GrSLType:
401 case kHalf3_GrSLType:
402 case kHalf4_GrSLType:
403 case kHalf2x2_GrSLType:
404 case kHalf3x3_GrSLType:
405 case kHalf4x4_GrSLType:
406 case kInt_GrSLType:
407 case kInt2_GrSLType:
408 case kInt3_GrSLType:
409 case kInt4_GrSLType:
410 case kUint_GrSLType:
411 case kUint2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500412 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500413 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500414 case kTextureExternalSampler_GrSLType:
415 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700416 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500417 case kTexture2D_GrSLType:
418 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500419 case kImageStorage2D_GrSLType:
420 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500421 return true;
422
423 case kVoid_GrSLType:
424 case kBool_GrSLType:
425 return false;
426 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400427 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500428 return false;
cdalton5f2d8e22016-03-11 13:34:32 -0800429}
430
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000431//////////////////////////////////////////////////////////////////////////////
432
jvanverth@google.com054ae992013-04-01 20:06:51 +0000433/**
434 * Types used to describe format of vertices in arrays.
Brian Salomonc5886032017-07-19 11:48:05 -0400435 */
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000436enum GrVertexAttribType {
437 kFloat_GrVertexAttribType = 0,
438 kVec2f_GrVertexAttribType,
439 kVec3f_GrVertexAttribType,
440 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800441
csmartdaltonb37cb232017-02-08 14:56:27 -0500442 kVec2i_GrVertexAttribType, // vector of 2 32-bit ints
443 kVec3i_GrVertexAttribType, // vector of 3 32-bit ints
444 kVec4i_GrVertexAttribType, // vector of 4 32-bit ints
445
egdaniel37b4d862014-11-03 10:07:07 -0800446 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800447 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000448
Robert Phillips8296e752017-08-25 08:45:21 -0400449 kVec2us_norm_GrVertexAttribType, // vector of 2 shorts. 0 -> 0.0f, 65535 -> 1.0f.
450 kVec2us_uint_GrVertexAttribType, // vector of 2 shorts. 0 -> 0, 65535 -> 65535.
ethannicholas22793252016-01-30 09:59:10 -0800451
452 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800453 kUint_GrVertexAttribType,
egdaniel990dbc82016-07-13 14:09:30 -0700454
cdalton793dc262016-02-08 10:11:47 -0800455 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000456};
457static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
458
jvanverth@google.com054ae992013-04-01 20:06:51 +0000459/**
460 * Returns the size of the attrib type in bytes.
461 */
462static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500463 switch (type) {
464 case kFloat_GrVertexAttribType:
465 return sizeof(float);
466 case kVec2f_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400467 return 2 * sizeof(float);
Brian Salomonfa26e662016-11-14 11:27:00 -0500468 case kVec3f_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400469 return 3 * sizeof(float);
Brian Salomonfa26e662016-11-14 11:27:00 -0500470 case kVec4f_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400471 return 4 * sizeof(float);
csmartdaltonb37cb232017-02-08 14:56:27 -0500472 case kVec2i_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400473 return 2 * sizeof(int32_t);
csmartdaltonb37cb232017-02-08 14:56:27 -0500474 case kVec3i_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400475 return 3 * sizeof(int32_t);
csmartdaltonb37cb232017-02-08 14:56:27 -0500476 case kVec4i_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400477 return 4 * sizeof(int32_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500478 case kUByte_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400479 return 1 * sizeof(char);
Brian Salomonfa26e662016-11-14 11:27:00 -0500480 case kVec4ub_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400481 return 4 * sizeof(char);
Robert Phillips8296e752017-08-25 08:45:21 -0400482 case kVec2us_norm_GrVertexAttribType: // fall through
483 case kVec2us_uint_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400484 return 2 * sizeof(int16_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500485 case kInt_GrVertexAttribType:
486 return sizeof(int32_t);
487 case kUint_GrVertexAttribType:
488 return sizeof(uint32_t);
489 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400490 SK_ABORT("Unexpected attribute type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500491 return 0;
jvanverth@google.com054ae992013-04-01 20:06:51 +0000492}
493
494/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800495 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000496 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800497static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
498 switch (type) {
Robert Phillips8296e752017-08-25 08:45:21 -0400499 case kVec2us_norm_GrVertexAttribType: // fall through
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400500 return kHighFloat2_GrSLType;
Robert Phillips8296e752017-08-25 08:45:21 -0400501 case kVec2us_uint_GrVertexAttribType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400502 return kUint2_GrSLType;
Robert Phillips8296e752017-08-25 08:45:21 -0400503 case kUByte_GrVertexAttribType: // fall through
joshualitt2dd1ae02014-12-03 06:24:10 -0800504 case kFloat_GrVertexAttribType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400505 return kHighFloat_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800506 case kVec2f_GrVertexAttribType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400507 return kHighFloat2_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800508 case kVec3f_GrVertexAttribType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400509 return kHighFloat3_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800510 case kVec4ub_GrVertexAttribType:
511 case kVec4f_GrVertexAttribType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400512 return kHighFloat4_GrSLType;
csmartdaltonb37cb232017-02-08 14:56:27 -0500513 case kVec2i_GrVertexAttribType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400514 return kInt2_GrSLType;
csmartdaltonb37cb232017-02-08 14:56:27 -0500515 case kVec3i_GrVertexAttribType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400516 return kInt3_GrSLType;
csmartdaltonb37cb232017-02-08 14:56:27 -0500517 case kVec4i_GrVertexAttribType:
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400518 return kInt4_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800519 case kInt_GrVertexAttribType:
520 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800521 case kUint_GrVertexAttribType:
522 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000523 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400524 SK_ABORT("Unsupported type conversion");
Brian Salomonfa26e662016-11-14 11:27:00 -0500525 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800526}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000527
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000528//////////////////////////////////////////////////////////////////////////////
529
Brian Salomonf9f45122016-11-29 11:59:17 -0500530enum class GrImageStorageFormat {
531 kRGBA8,
532 kRGBA8i,
533 kRGBA16f,
534 kRGBA32f,
535};
536
537/**
538 * Describes types of caching and compiler optimizations allowed for certain variable types
539 * (currently only image storages).
540 **/
541enum class GrSLMemoryModel {
542 /** No special restrctions on memory accesses or compiler optimizations */
543 kNone,
544 /** Cache coherent across shader invocations */
545 kCoherent,
546 /**
547 * Disallows compiler from eliding loads or stores that appear redundant in a single
548 * invocation. Implies coherent.
549 */
550 kVolatile
551};
552
553/**
554 * If kYes then the memory backing the varialble is only accessed via the variable. This is
555 * currently only used with image storages.
556 */
557enum class GrSLRestrict {
558 kYes,
559 kNo,
560};
561
562//////////////////////////////////////////////////////////////////////////////
563
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000564/**
Brian Salomonc5886032017-07-19 11:48:05 -0400565 * We have coverage effects that clip rendering to the edge of some geometric primitive.
566 * This enum specifies how that clipping is performed. Not all factories that take a
567 * GrProcessorEdgeType will succeed with all values and it is up to the caller to check for
568 * a NULL return.
569 */
joshualittb0a8a372014-09-23 09:50:21 -0700570enum GrPrimitiveEdgeType {
571 kFillBW_GrProcessorEdgeType,
572 kFillAA_GrProcessorEdgeType,
573 kInverseFillBW_GrProcessorEdgeType,
574 kInverseFillAA_GrProcessorEdgeType,
575 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000576
joshualittb0a8a372014-09-23 09:50:21 -0700577 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000578};
579
joshualittb0a8a372014-09-23 09:50:21 -0700580static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000581
joshualittb0a8a372014-09-23 09:50:21 -0700582static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
583 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000584}
585
joshualittb0a8a372014-09-23 09:50:21 -0700586static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
587 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
588 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000589}
590
joshualittb0a8a372014-09-23 09:50:21 -0700591static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
Brian Salomonc5886032017-07-19 11:48:05 -0400592 return (kFillBW_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 GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000597 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700598 case kFillBW_GrProcessorEdgeType:
599 return kInverseFillBW_GrProcessorEdgeType;
600 case kFillAA_GrProcessorEdgeType:
601 return kInverseFillAA_GrProcessorEdgeType;
602 case kInverseFillBW_GrProcessorEdgeType:
603 return kFillBW_GrProcessorEdgeType;
604 case kInverseFillAA_GrProcessorEdgeType:
605 return kFillAA_GrProcessorEdgeType;
606 case kHairlineAA_GrProcessorEdgeType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400607 SK_ABORT("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000608 }
Brian Salomonc5886032017-07-19 11:48:05 -0400609 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000610}
611
bsalomonbcf0a522014-10-08 08:40:09 -0700612/**
613 * Indicates the type of pending IO operations that can be recorded for gpu resources.
614 */
615enum GrIOType {
616 kRead_GrIOType,
617 kWrite_GrIOType,
618 kRW_GrIOType
619};
620
jvanverth17aa0472016-01-05 10:41:27 -0800621/**
Brian Salomonc5886032017-07-19 11:48:05 -0400622 * Indicates the type of data that a GPU buffer will be used for.
623 */
cdalton397536c2016-03-25 12:15:03 -0700624enum GrBufferType {
625 kVertex_GrBufferType,
626 kIndex_GrBufferType,
cdaltone2e71c22016-04-07 18:13:29 -0700627 kTexel_GrBufferType,
628 kDrawIndirect_GrBufferType,
cdalton397536c2016-03-25 12:15:03 -0700629 kXferCpuToGpu_GrBufferType,
630 kXferGpuToCpu_GrBufferType,
631
632 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
633};
cdaltone2e71c22016-04-07 18:13:29 -0700634static const int kGrBufferTypeCount = kLast_GrBufferType + 1;
635
636static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) {
637 SkASSERT(type >= 0 && type < kGrBufferTypeCount);
638 return type <= kIndex_GrBufferType;
639
640 GR_STATIC_ASSERT(0 == kVertex_GrBufferType);
641 GR_STATIC_ASSERT(1 == kIndex_GrBufferType);
642}
cdalton397536c2016-03-25 12:15:03 -0700643
644/**
Brian Salomonc5886032017-07-19 11:48:05 -0400645 * Provides a performance hint regarding the frequency at which a data store will be accessed.
646 */
cdalton397536c2016-03-25 12:15:03 -0700647enum GrAccessPattern {
648 /** Data store will be respecified repeatedly and used many times. */
649 kDynamic_GrAccessPattern,
650 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
651 kStatic_GrAccessPattern,
652 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
653 kStream_GrAccessPattern,
654
655 kLast_GrAccessPattern = kStream_GrAccessPattern
jvanverth17aa0472016-01-05 10:41:27 -0800656};
657
Robert Phillipsc4f0a822017-06-13 08:11:36 -0400658// Flags shared between GrRenderTarget and GrRenderTargetProxy
659enum class GrRenderTargetFlags {
660 kNone = 0,
661
662 // For internal resources:
663 // this is enabled whenever MSAA is enabled and GrCaps reports mixed samples are supported
664 // For wrapped resources:
665 // this is disabled for FBO0
666 // but, otherwise, is enabled whenever MSAA is enabled and GrCaps reports mixed samples
667 // are supported
668 kMixedSampled = 1 << 0,
669
670 // For internal resources:
671 // this is enabled whenever GrCaps reports window rect support
672 // For wrapped resources1
673 // this is disabled for FBO0
674 // but, otherwise, is enabled whenever GrCaps reports window rect support
675 kWindowRectsSupport = 1 << 1
676};
677GR_MAKE_BITFIELD_CLASS_OPS(GrRenderTargetFlags)
jvanverth17aa0472016-01-05 10:41:27 -0800678
joshualitt7d022d62015-05-12 12:03:50 -0700679#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700680// Takes a pointer to a GrCaps, and will suppress prints if required
Brian Salomonc5886032017-07-19 11:48:05 -0400681#define GrCapsDebugf(caps, ...) \
682 if (!(caps)->suppressPrints()) { \
683 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700684 }
685#else
bsalomon682c2692015-05-22 14:01:46 -0700686#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700687#endif
688
kkinnunen2e6055b2016-04-22 01:48:29 -0700689/**
690 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
691 */
692enum class GrBackendObjectOwnership : bool {
693 /** Holder does not destroy the backend object. */
694 kBorrowed = false,
695 /** Holder destroys the backend object. */
696 kOwned = true
697};
698
Brian Salomonaff329b2017-08-11 09:40:37 -0400699template <typename T>
700T* const* unique_ptr_address_as_pointer_address(std::unique_ptr<T> const* up) {
701 static_assert(sizeof(T*) == sizeof(std::unique_ptr<T>), "unique_ptr not expected size.");
702 return reinterpret_cast<T* const*>(up);
bungeman06ca8ec2016-06-09 08:01:03 -0700703}
704
jvanverth84741b32016-09-30 08:39:02 -0700705/*
706 * Object for CPU-GPU synchronization
707 */
Greg Daniel6be35232017-03-01 17:01:09 -0500708typedef uint64_t GrFence;
jvanverth84741b32016-09-30 08:39:02 -0700709
Brian Osman195c05b2017-08-30 15:14:04 -0400710/**
711 * Used to include or exclude specific GPU path renderers for testing purposes.
712 */
713enum class GpuPathRenderers {
714 kNone = 0, // Always use sofware masks and/or GrDefaultPathRenderer.
715 kDashLine = 1 << 0,
716 kStencilAndCover = 1 << 1,
717 kMSAA = 1 << 2,
718 kAAConvex = 1 << 3,
719 kAALinearizing = 1 << 4,
720 kSmall = 1 << 5,
721 kCoverageCounting = 1 << 6,
722 kTessellating = 1 << 7,
723
724 kAll = (kTessellating | (kTessellating - 1)),
725
726 // Temporarily disabling CCPR by default until it has had a time to soak.
727 kDefault = kAll & ~kCoverageCounting,
728};
729
730GR_MAKE_BITFIELD_CLASS_OPS(GpuPathRenderers)
731
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000732#endif