ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1 | /* |
| 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 Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 7 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 8 | #ifndef SKSL_MODIFIERS |
| 9 | #define SKSL_MODIFIERS |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/sksl/ir/SkSLLayout.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 12 | |
| 13 | namespace SkSL { |
| 14 | |
| 15 | /** |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 16 | * A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration. |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 17 | */ |
| 18 | struct Modifiers { |
| 19 | enum Flag { |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 20 | kNo_Flag = 0, |
| 21 | kConst_Flag = 1 << 0, |
| 22 | kIn_Flag = 1 << 1, |
| 23 | kOut_Flag = 1 << 2, |
Ethan Nicholas | 858fecc | 2019-03-07 13:19:18 -0500 | [diff] [blame] | 24 | 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 Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 37 | kVarying_Flag = 1 << 16, |
Ethan Nicholas | f3c8f5d | 2020-08-20 13:09:14 +0000 | [diff] [blame] | 38 | kInline_Flag = 1 << 17, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
Ethan Nicholas | 3605ace | 2016-11-21 15:59:48 -0500 | [diff] [blame] | 41 | Modifiers() |
| 42 | : fLayout(Layout()) |
| 43 | , fFlags(0) {} |
| 44 | |
Michael Ludwig | 9094f2c | 2018-09-07 13:44:21 -0400 | [diff] [blame] | 45 | Modifiers(const Layout& layout, int flags) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 46 | : fLayout(layout) |
| 47 | , fFlags(flags) {} |
| 48 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 49 | String description() const { |
| 50 | String result = fLayout.description(); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 51 | if (fFlags & kUniform_Flag) { |
| 52 | result += "uniform "; |
| 53 | } |
| 54 | if (fFlags & kConst_Flag) { |
| 55 | result += "const "; |
| 56 | } |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 57 | if (fFlags & kFlat_Flag) { |
| 58 | result += "flat "; |
| 59 | } |
| 60 | if (fFlags & kNoPerspective_Flag) { |
| 61 | result += "noperspective "; |
| 62 | } |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 63 | 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 Nicholas | 0dd30d9 | 2017-05-01 16:57:07 -0400 | [diff] [blame] | 78 | if (fFlags & kBuffer_Flag) { |
| 79 | result += "buffer "; |
| 80 | } |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 81 | if (fFlags & kHasSideEffects_Flag) { |
| 82 | result += "sk_has_side_effects "; |
| 83 | } |
Ethan Nicholas | a7ceb50 | 2019-01-11 10:31:48 -0500 | [diff] [blame] | 84 | 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 Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 93 | if (fFlags & kVarying_Flag) { |
| 94 | result += "varying "; |
| 95 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 96 | 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 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 115 | Layout fLayout; |
| 116 | int fFlags; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 119 | } // namespace SkSL |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 120 | |
| 121 | #endif |