blob: d2df9b26a8ff6f1be2e9dff0213154fc99932caa [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,
Ethan Nicholas88d99c62017-08-16 16:41:30 -040081 kInt_GrSLType,
Brian Salomon1d816b92017-08-17 11:07:59 -040082 kUint_GrSLType,
83 kFloat_GrSLType,
84 kVec2f_GrSLType,
85 kVec3f_GrSLType,
86 kVec4f_GrSLType,
87 kVec2i_GrSLType,
88 kVec3i_GrSLType,
89 kVec4i_GrSLType,
90 kMat22f_GrSLType,
91 kMat33f_GrSLType,
92 kMat44f_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070093 kTexture2DSampler_GrSLType,
Brian Salomona8f00022016-11-16 12:55:57 -050094 kITexture2DSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070095 kTextureExternalSampler_GrSLType,
96 kTexture2DRectSampler_GrSLType,
csmartdalton22458032016-11-16 11:28:16 -070097 kBufferSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070098 kTexture2D_GrSLType,
99 kSampler_GrSLType,
Brian Salomonf9f45122016-11-29 11:59:17 -0500100 kImageStorage2D_GrSLType,
101 kIImageStorage2D_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000102};
103
bsalomon17168df2014-12-09 09:00:49 -0800104enum GrShaderType {
105 kVertex_GrShaderType,
106 kGeometry_GrShaderType,
107 kFragment_GrShaderType,
108
109 kLastkFragment_GrShaderType = kFragment_GrShaderType
110};
111static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
112
cdalton5e58cee2016-02-11 12:49:47 -0800113enum GrShaderFlags {
114 kNone_GrShaderFlags = 0,
115 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
116 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
117 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
118};
119GR_MAKE_BITFIELD_OPS(GrShaderFlags);
120
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000121/**
bsalomonc0bd6482014-12-09 10:04:14 -0800122 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -0800123 * vary the internal precision based on the qualifiers. These currently only apply to float types (
124 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -0800125 */
126enum GrSLPrecision {
127 kLow_GrSLPrecision,
128 kMedium_GrSLPrecision,
129 kHigh_GrSLPrecision,
130
Brian Osman33aa2c72017-04-05 09:26:15 -0400131 // Default precision is a special tag that means "whatever the default for the program/type
132 // combination is". In other words, it maps to the empty string in shader code. There are some
133 // scenarios where kDefault is not allowed (as the default precision for a program, or for
134 // varyings, for example).
135 kDefault_GrSLPrecision,
bsalomonc0bd6482014-12-09 10:04:14 -0800136
Brian Osman33aa2c72017-04-05 09:26:15 -0400137 // We only consider the "real" precisions here
138 kLast_GrSLPrecision = kHigh_GrSLPrecision,
bsalomonc0bd6482014-12-09 10:04:14 -0800139};
140
141static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
142
ethannicholas22793252016-01-30 09:59:10 -0800143/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -0800144static inline bool GrSLTypeIsFloatType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500145 switch (type) {
Brian Salomon1d816b92017-08-17 11:07:59 -0400146 case kFloat_GrSLType:
147 case kVec2f_GrSLType:
148 case kVec3f_GrSLType:
149 case kVec4f_GrSLType:
150 case kMat22f_GrSLType:
151 case kMat33f_GrSLType:
152 case kMat44f_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500153 return true;
bsalomon422f56f2014-12-09 10:18:12 -0800154
Brian Salomonfa26e662016-11-14 11:27:00 -0500155 case kVoid_GrSLType:
156 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500157 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500158 case kTextureExternalSampler_GrSLType:
159 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700160 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500161 case kBool_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400162 case kInt_GrSLType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400163 case kUint_GrSLType:
164 case kVec2i_GrSLType:
165 case kVec3i_GrSLType:
166 case kVec4i_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500167 case kTexture2D_GrSLType:
168 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500169 case kImageStorage2D_GrSLType:
170 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500171 return false;
172 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400173 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500174 return false;
bsalomone5286e02016-01-14 09:24:09 -0800175}
176
egdaniel990dbc82016-07-13 14:09:30 -0700177static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500178 switch (type) {
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:
183 return true;
bsalomone5286e02016-01-14 09:24:09 -0800184
Brian Salomonfa26e662016-11-14 11:27:00 -0500185 case kVoid_GrSLType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400186 case kFloat_GrSLType:
187 case kVec2f_GrSLType:
188 case kVec3f_GrSLType:
189 case kVec4f_GrSLType:
190 case kVec2i_GrSLType:
191 case kVec3i_GrSLType:
192 case kVec4i_GrSLType:
193 case kMat22f_GrSLType:
194 case kMat33f_GrSLType:
195 case kMat44f_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400196 case kBufferSampler_GrSLType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400197 case kInt_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500198 case kUint_GrSLType:
199 case kBool_GrSLType:
200 case kTexture2D_GrSLType:
201 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500202 case kImageStorage2D_GrSLType:
203 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500204 return false;
205 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400206 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500207 return false;
egdanielfa896322016-01-13 12:19:30 -0800208}
209
egdaniel990dbc82016-07-13 14:09:30 -0700210static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500211 switch (type) {
212 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500213 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500214 case kTextureExternalSampler_GrSLType:
215 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700216 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500217 return true;
cdalton74b8d322016-04-11 14:47:28 -0700218
Brian Salomonfa26e662016-11-14 11:27:00 -0500219 case kVoid_GrSLType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400220 case kFloat_GrSLType:
221 case kVec2f_GrSLType:
222 case kVec3f_GrSLType:
223 case kVec4f_GrSLType:
224 case kVec2i_GrSLType:
225 case kVec3i_GrSLType:
226 case kVec4i_GrSLType:
227 case kMat22f_GrSLType:
228 case kMat33f_GrSLType:
229 case kMat44f_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500230 case kInt_GrSLType:
231 case kUint_GrSLType:
232 case kBool_GrSLType:
233 case kTexture2D_GrSLType:
234 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500235 case kImageStorage2D_GrSLType:
236 case kIImageStorage2D_GrSLType:
237 return false;
238 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400239 SK_ABORT("Unexpected type");
Brian Salomonf9f45122016-11-29 11:59:17 -0500240 return false;
241}
242
243static inline bool GrSLTypeIsImageStorage(GrSLType type) {
244 switch (type) {
245 case kImageStorage2D_GrSLType:
246 case kIImageStorage2D_GrSLType:
247 return true;
248
249 case kVoid_GrSLType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400250 case kFloat_GrSLType:
251 case kVec2f_GrSLType:
252 case kVec3f_GrSLType:
253 case kVec4f_GrSLType:
254 case kVec2i_GrSLType:
255 case kVec3i_GrSLType:
256 case kVec4i_GrSLType:
257 case kMat22f_GrSLType:
258 case kMat33f_GrSLType:
259 case kMat44f_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500260 case kInt_GrSLType:
261 case kUint_GrSLType:
262 case kBool_GrSLType:
263 case kTexture2D_GrSLType:
264 case kSampler_GrSLType:
265 case kTexture2DSampler_GrSLType:
266 case kITexture2DSampler_GrSLType:
267 case kTextureExternalSampler_GrSLType:
268 case kTexture2DRectSampler_GrSLType:
269 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500270 return false;
271 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400272 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500273 return false;
cdalton74b8d322016-04-11 14:47:28 -0700274}
275
cdalton5f2d8e22016-03-11 13:34:32 -0800276static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500277 switch (type) {
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400278 case kInt_GrSLType:
Ethan Nicholas88d99c62017-08-16 16:41:30 -0400279 case kUint_GrSLType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400280 case kFloat_GrSLType:
281 case kVec2f_GrSLType:
282 case kVec3f_GrSLType:
283 case kVec4f_GrSLType:
284 case kVec2i_GrSLType:
285 case kVec3i_GrSLType:
286 case kVec4i_GrSLType:
287 case kMat22f_GrSLType:
288 case kMat33f_GrSLType:
289 case kMat44f_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500290 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500291 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500292 case kTextureExternalSampler_GrSLType:
293 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700294 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500295 case kTexture2D_GrSLType:
296 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500297 case kImageStorage2D_GrSLType:
298 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500299 return true;
300
301 case kVoid_GrSLType:
302 case kBool_GrSLType:
303 return false;
304 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400305 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500306 return false;
cdalton5f2d8e22016-03-11 13:34:32 -0800307}
308
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000309//////////////////////////////////////////////////////////////////////////////
310
jvanverth@google.com054ae992013-04-01 20:06:51 +0000311/**
312 * Types used to describe format of vertices in arrays.
Brian Salomonc5886032017-07-19 11:48:05 -0400313 */
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000314enum GrVertexAttribType {
315 kFloat_GrVertexAttribType = 0,
316 kVec2f_GrVertexAttribType,
317 kVec3f_GrVertexAttribType,
318 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800319
csmartdaltonb37cb232017-02-08 14:56:27 -0500320 kVec2i_GrVertexAttribType, // vector of 2 32-bit ints
321 kVec3i_GrVertexAttribType, // vector of 3 32-bit ints
322 kVec4i_GrVertexAttribType, // vector of 4 32-bit ints
323
egdaniel37b4d862014-11-03 10:07:07 -0800324 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800325 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000326
Brian Salomonc5886032017-07-19 11:48:05 -0400327 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800328
329 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800330 kUint_GrVertexAttribType,
egdaniel990dbc82016-07-13 14:09:30 -0700331
cdalton793dc262016-02-08 10:11:47 -0800332 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000333};
334static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
335
jvanverth@google.com054ae992013-04-01 20:06:51 +0000336/**
337 * Returns the size of the attrib type in bytes.
338 */
339static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500340 switch (type) {
341 case kFloat_GrVertexAttribType:
342 return sizeof(float);
343 case kVec2f_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400344 return 2 * sizeof(float);
Brian Salomonfa26e662016-11-14 11:27:00 -0500345 case kVec3f_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400346 return 3 * sizeof(float);
Brian Salomonfa26e662016-11-14 11:27:00 -0500347 case kVec4f_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400348 return 4 * sizeof(float);
csmartdaltonb37cb232017-02-08 14:56:27 -0500349 case kVec2i_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400350 return 2 * sizeof(int32_t);
csmartdaltonb37cb232017-02-08 14:56:27 -0500351 case kVec3i_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400352 return 3 * sizeof(int32_t);
csmartdaltonb37cb232017-02-08 14:56:27 -0500353 case kVec4i_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400354 return 4 * sizeof(int32_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500355 case kUByte_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400356 return 1 * sizeof(char);
Brian Salomonfa26e662016-11-14 11:27:00 -0500357 case kVec4ub_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400358 return 4 * sizeof(char);
Brian Salomonfa26e662016-11-14 11:27:00 -0500359 case kVec2us_GrVertexAttribType:
Brian Salomonc5886032017-07-19 11:48:05 -0400360 return 2 * sizeof(int16_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500361 case kInt_GrVertexAttribType:
362 return sizeof(int32_t);
363 case kUint_GrVertexAttribType:
364 return sizeof(uint32_t);
365 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400366 SK_ABORT("Unexpected attribute type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500367 return 0;
jvanverth@google.com054ae992013-04-01 20:06:51 +0000368}
369
370/**
cdalton793dc262016-02-08 10:11:47 -0800371 * Is the attrib type integral?
372 */
373static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500374 switch (type) {
375 case kFloat_GrVertexAttribType:
376 return false;
377 case kVec2f_GrVertexAttribType:
378 return false;
379 case kVec3f_GrVertexAttribType:
380 return false;
381 case kVec4f_GrVertexAttribType:
382 return false;
csmartdaltonb37cb232017-02-08 14:56:27 -0500383 case kVec2i_GrVertexAttribType:
384 return true;
385 case kVec3i_GrVertexAttribType:
386 return true;
387 case kVec4i_GrVertexAttribType:
388 return true;
Brian Salomonfa26e662016-11-14 11:27:00 -0500389 case kUByte_GrVertexAttribType:
390 return false;
391 case kVec4ub_GrVertexAttribType:
392 return false;
393 case kVec2us_GrVertexAttribType:
394 return false;
395 case kInt_GrVertexAttribType:
396 return true;
397 case kUint_GrVertexAttribType:
398 return true;
399 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400400 SK_ABORT("Unexpected attribute type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500401 return false;
cdalton793dc262016-02-08 10:11:47 -0800402}
403
404/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800405 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000406 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800407static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
408 switch (type) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800409 case kUByte_GrVertexAttribType:
410 case kFloat_GrVertexAttribType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400411 return kFloat_GrSLType;
jvanverth7023a002016-02-22 11:25:32 -0800412 case kVec2us_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800413 case kVec2f_GrVertexAttribType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400414 return kVec2f_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800415 case kVec3f_GrVertexAttribType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400416 return kVec3f_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800417 case kVec4ub_GrVertexAttribType:
418 case kVec4f_GrVertexAttribType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400419 return kVec4f_GrSLType;
csmartdaltonb37cb232017-02-08 14:56:27 -0500420 case kVec2i_GrVertexAttribType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400421 return kVec2i_GrSLType;
csmartdaltonb37cb232017-02-08 14:56:27 -0500422 case kVec3i_GrVertexAttribType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400423 return kVec3i_GrSLType;
csmartdaltonb37cb232017-02-08 14:56:27 -0500424 case kVec4i_GrVertexAttribType:
Brian Salomon1d816b92017-08-17 11:07:59 -0400425 return kVec4i_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800426 case kInt_GrVertexAttribType:
427 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800428 case kUint_GrVertexAttribType:
429 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000430 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400431 SK_ABORT("Unsupported type conversion");
Brian Salomonfa26e662016-11-14 11:27:00 -0500432 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800433}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000434
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000435//////////////////////////////////////////////////////////////////////////////
436
Brian Salomonf9f45122016-11-29 11:59:17 -0500437enum class GrImageStorageFormat {
438 kRGBA8,
439 kRGBA8i,
440 kRGBA16f,
441 kRGBA32f,
442};
443
444/**
445 * Describes types of caching and compiler optimizations allowed for certain variable types
446 * (currently only image storages).
447 **/
448enum class GrSLMemoryModel {
449 /** No special restrctions on memory accesses or compiler optimizations */
450 kNone,
451 /** Cache coherent across shader invocations */
452 kCoherent,
453 /**
454 * Disallows compiler from eliding loads or stores that appear redundant in a single
455 * invocation. Implies coherent.
456 */
457 kVolatile
458};
459
460/**
461 * If kYes then the memory backing the varialble is only accessed via the variable. This is
462 * currently only used with image storages.
463 */
464enum class GrSLRestrict {
465 kYes,
466 kNo,
467};
468
469//////////////////////////////////////////////////////////////////////////////
470
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000471/**
Brian Salomonc5886032017-07-19 11:48:05 -0400472 * We have coverage effects that clip rendering to the edge of some geometric primitive.
473 * This enum specifies how that clipping is performed. Not all factories that take a
474 * GrProcessorEdgeType will succeed with all values and it is up to the caller to check for
475 * a NULL return.
476 */
joshualittb0a8a372014-09-23 09:50:21 -0700477enum GrPrimitiveEdgeType {
478 kFillBW_GrProcessorEdgeType,
479 kFillAA_GrProcessorEdgeType,
480 kInverseFillBW_GrProcessorEdgeType,
481 kInverseFillAA_GrProcessorEdgeType,
482 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000483
joshualittb0a8a372014-09-23 09:50:21 -0700484 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000485};
486
joshualittb0a8a372014-09-23 09:50:21 -0700487static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000488
joshualittb0a8a372014-09-23 09:50:21 -0700489static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
490 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000491}
492
joshualittb0a8a372014-09-23 09:50:21 -0700493static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
494 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
495 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000496}
497
joshualittb0a8a372014-09-23 09:50:21 -0700498static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
Brian Salomonc5886032017-07-19 11:48:05 -0400499 return (kFillBW_GrProcessorEdgeType != edgeType &&
500 kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000501}
502
joshualittb0a8a372014-09-23 09:50:21 -0700503static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000504 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700505 case kFillBW_GrProcessorEdgeType:
506 return kInverseFillBW_GrProcessorEdgeType;
507 case kFillAA_GrProcessorEdgeType:
508 return kInverseFillAA_GrProcessorEdgeType;
509 case kInverseFillBW_GrProcessorEdgeType:
510 return kFillBW_GrProcessorEdgeType;
511 case kInverseFillAA_GrProcessorEdgeType:
512 return kFillAA_GrProcessorEdgeType;
513 case kHairlineAA_GrProcessorEdgeType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400514 SK_ABORT("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000515 }
Brian Salomonc5886032017-07-19 11:48:05 -0400516 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000517}
518
bsalomonbcf0a522014-10-08 08:40:09 -0700519/**
520 * Indicates the type of pending IO operations that can be recorded for gpu resources.
521 */
522enum GrIOType {
523 kRead_GrIOType,
524 kWrite_GrIOType,
525 kRW_GrIOType
526};
527
jvanverth17aa0472016-01-05 10:41:27 -0800528/**
Brian Salomonc5886032017-07-19 11:48:05 -0400529 * Indicates the type of data that a GPU buffer will be used for.
530 */
cdalton397536c2016-03-25 12:15:03 -0700531enum GrBufferType {
532 kVertex_GrBufferType,
533 kIndex_GrBufferType,
cdaltone2e71c22016-04-07 18:13:29 -0700534 kTexel_GrBufferType,
535 kDrawIndirect_GrBufferType,
cdalton397536c2016-03-25 12:15:03 -0700536 kXferCpuToGpu_GrBufferType,
537 kXferGpuToCpu_GrBufferType,
538
539 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
540};
cdaltone2e71c22016-04-07 18:13:29 -0700541static const int kGrBufferTypeCount = kLast_GrBufferType + 1;
542
543static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) {
544 SkASSERT(type >= 0 && type < kGrBufferTypeCount);
545 return type <= kIndex_GrBufferType;
546
547 GR_STATIC_ASSERT(0 == kVertex_GrBufferType);
548 GR_STATIC_ASSERT(1 == kIndex_GrBufferType);
549}
cdalton397536c2016-03-25 12:15:03 -0700550
551/**
Brian Salomonc5886032017-07-19 11:48:05 -0400552 * Provides a performance hint regarding the frequency at which a data store will be accessed.
553 */
cdalton397536c2016-03-25 12:15:03 -0700554enum GrAccessPattern {
555 /** Data store will be respecified repeatedly and used many times. */
556 kDynamic_GrAccessPattern,
557 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
558 kStatic_GrAccessPattern,
559 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
560 kStream_GrAccessPattern,
561
562 kLast_GrAccessPattern = kStream_GrAccessPattern
jvanverth17aa0472016-01-05 10:41:27 -0800563};
564
Robert Phillipsc4f0a822017-06-13 08:11:36 -0400565// Flags shared between GrRenderTarget and GrRenderTargetProxy
566enum class GrRenderTargetFlags {
567 kNone = 0,
568
569 // For internal resources:
570 // this is enabled whenever MSAA is enabled and GrCaps reports mixed samples are supported
571 // For wrapped resources:
572 // this is disabled for FBO0
573 // but, otherwise, is enabled whenever MSAA is enabled and GrCaps reports mixed samples
574 // are supported
575 kMixedSampled = 1 << 0,
576
577 // For internal resources:
578 // this is enabled whenever GrCaps reports window rect support
579 // For wrapped resources1
580 // this is disabled for FBO0
581 // but, otherwise, is enabled whenever GrCaps reports window rect support
582 kWindowRectsSupport = 1 << 1
583};
584GR_MAKE_BITFIELD_CLASS_OPS(GrRenderTargetFlags)
jvanverth17aa0472016-01-05 10:41:27 -0800585
joshualitt7d022d62015-05-12 12:03:50 -0700586#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700587// Takes a pointer to a GrCaps, and will suppress prints if required
Brian Salomonc5886032017-07-19 11:48:05 -0400588#define GrCapsDebugf(caps, ...) \
589 if (!(caps)->suppressPrints()) { \
590 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700591 }
592#else
bsalomon682c2692015-05-22 14:01:46 -0700593#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700594#endif
595
kkinnunen2e6055b2016-04-22 01:48:29 -0700596/**
597 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
598 */
599enum class GrBackendObjectOwnership : bool {
600 /** Holder does not destroy the backend object. */
601 kBorrowed = false,
602 /** Holder destroys the backend object. */
603 kOwned = true
604};
605
Brian Salomonaff329b2017-08-11 09:40:37 -0400606template <typename T>
607T* const* unique_ptr_address_as_pointer_address(std::unique_ptr<T> const* up) {
608 static_assert(sizeof(T*) == sizeof(std::unique_ptr<T>), "unique_ptr not expected size.");
609 return reinterpret_cast<T* const*>(up);
bungeman06ca8ec2016-06-09 08:01:03 -0700610}
611
jvanverth84741b32016-09-30 08:39:02 -0700612/*
613 * Object for CPU-GPU synchronization
614 */
Greg Daniel6be35232017-03-01 17:01:09 -0500615typedef uint64_t GrFence;
jvanverth84741b32016-09-30 08:39:02 -0700616
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000617#endif