blob: f830b0ff09941b5c0972e3c9462096906fe5906a [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
2 * Copyright 2016 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 */
Ethan Nicholas11d53972016-11-28 11:23:23 -05007
ethannicholasb3058bd2016-07-01 08:22:01 -07008#ifndef SKSL_MODIFIERS
9#define SKSL_MODIFIERS
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/sksl/ir/SkSLLayout.h"
ethannicholasb3058bd2016-07-01 08:22:01 -070012
13namespace SkSL {
14
15/**
Ethan Nicholas11d53972016-11-28 11:23:23 -050016 * A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration.
ethannicholasb3058bd2016-07-01 08:22:01 -070017 */
18struct Modifiers {
19 enum Flag {
Ethan Nicholascb670962017-04-20 19:31:52 -040020 kNo_Flag = 0,
21 kConst_Flag = 1 << 0,
22 kIn_Flag = 1 << 1,
23 kOut_Flag = 1 << 2,
Ethan Nicholas858fecc2019-03-07 13:19:18 -050024 kUniform_Flag = 1 << 3,
25 kFlat_Flag = 1 << 4,
26 kNoPerspective_Flag = 1 << 5,
27 kReadOnly_Flag = 1 << 6,
28 kWriteOnly_Flag = 1 << 7,
29 kCoherent_Flag = 1 << 8,
30 kVolatile_Flag = 1 << 9,
31 kRestrict_Flag = 1 << 10,
32 kBuffer_Flag = 1 << 11,
33 kHasSideEffects_Flag = 1 << 12,
34 kPLS_Flag = 1 << 13,
35 kPLSIn_Flag = 1 << 14,
36 kPLSOut_Flag = 1 << 15,
Brian Osman3c358422020-03-23 10:44:12 -040037 kVarying_Flag = 1 << 16,
Ethan Nicholasf3c8f5d2020-08-20 13:09:14 +000038 kInline_Flag = 1 << 17,
ethannicholasb3058bd2016-07-01 08:22:01 -070039 };
40
Ethan Nicholas3605ace2016-11-21 15:59:48 -050041 Modifiers()
42 : fLayout(Layout())
43 , fFlags(0) {}
44
Michael Ludwig9094f2c2018-09-07 13:44:21 -040045 Modifiers(const Layout& layout, int flags)
ethannicholasb3058bd2016-07-01 08:22:01 -070046 : fLayout(layout)
47 , fFlags(flags) {}
48
Ethan Nicholas0df1b042017-03-31 13:56:23 -040049 String description() const {
50 String result = fLayout.description();
ethannicholasb3058bd2016-07-01 08:22:01 -070051 if (fFlags & kUniform_Flag) {
52 result += "uniform ";
53 }
54 if (fFlags & kConst_Flag) {
55 result += "const ";
56 }
ethannicholasf789b382016-08-03 12:43:36 -070057 if (fFlags & kFlat_Flag) {
58 result += "flat ";
59 }
60 if (fFlags & kNoPerspective_Flag) {
61 result += "noperspective ";
62 }
Brian Salomonf9f45122016-11-29 11:59:17 -050063 if (fFlags & kReadOnly_Flag) {
64 result += "readonly ";
65 }
66 if (fFlags & kWriteOnly_Flag) {
67 result += "writeonly ";
68 }
69 if (fFlags & kCoherent_Flag) {
70 result += "coherent ";
71 }
72 if (fFlags & kVolatile_Flag) {
73 result += "volatile ";
74 }
75 if (fFlags & kRestrict_Flag) {
76 result += "restrict ";
77 }
Ethan Nicholas0dd30d92017-05-01 16:57:07 -040078 if (fFlags & kBuffer_Flag) {
79 result += "buffer ";
80 }
Ethan Nicholascb670962017-04-20 19:31:52 -040081 if (fFlags & kHasSideEffects_Flag) {
82 result += "sk_has_side_effects ";
83 }
Ethan Nicholasa7ceb502019-01-11 10:31:48 -050084 if (fFlags & kPLS_Flag) {
85 result += "__pixel_localEXT ";
86 }
87 if (fFlags & kPLSIn_Flag) {
88 result += "__pixel_local_inEXT ";
89 }
90 if (fFlags & kPLSOut_Flag) {
91 result += "__pixel_local_outEXT ";
92 }
Brian Osman3c358422020-03-23 10:44:12 -040093 if (fFlags & kVarying_Flag) {
94 result += "varying ";
95 }
ethannicholasb3058bd2016-07-01 08:22:01 -070096 if ((fFlags & kIn_Flag) && (fFlags & kOut_Flag)) {
97 result += "inout ";
98 } else if (fFlags & kIn_Flag) {
99 result += "in ";
100 } else if (fFlags & kOut_Flag) {
101 result += "out ";
102 }
103
104 return result;
105 }
106
107 bool operator==(const Modifiers& other) const {
108 return fLayout == other.fLayout && fFlags == other.fFlags;
109 }
110
111 bool operator!=(const Modifiers& other) const {
112 return !(*this == other);
113 }
114
ethannicholasf789b382016-08-03 12:43:36 -0700115 Layout fLayout;
116 int fFlags;
ethannicholasb3058bd2016-07-01 08:22:01 -0700117};
118
John Stilesa6841be2020-08-06 14:11:56 -0400119} // namespace SkSL
ethannicholasb3058bd2016-07-01 08:22:01 -0700120
121#endif