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 | */ |
| 7 | |
| 8 | #ifndef SKSL_LAYOUT |
| 9 | #define SKSL_LAYOUT |
| 10 | |
| 11 | namespace SkSL { |
| 12 | |
| 13 | /** |
| 14 | * Represents a layout block appearing before a variable declaration, as in: |
| 15 | * |
| 16 | * layout (location = 0) int x; |
| 17 | */ |
| 18 | struct Layout { |
| 19 | Layout(const ASTLayout& layout) |
| 20 | : fLocation(layout.fLocation) |
| 21 | , fBinding(layout.fBinding) |
| 22 | , fIndex(layout.fIndex) |
| 23 | , fSet(layout.fSet) |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 24 | , fBuiltin(layout.fBuiltin) |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 25 | , fOriginUpperLeft(layout.fOriginUpperLeft) |
| 26 | , fOverrideCoverage(layout.fOverrideCoverage) |
ethannicholas | fa5f65a | 2016-11-15 12:53:05 -0800 | [diff] [blame] | 27 | , fBlendSupportAllEquations(layout.fBlendSupportAllEquations) |
Stan Iliev | cb115bd | 2016-11-16 15:25:42 +0000 | [diff] [blame^] | 28 | , fPushConstant(layout.fPushConstant) {} |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 29 | |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 30 | Layout(int location, int binding, int index, int set, int builtin, bool originUpperLeft, |
Stan Iliev | cb115bd | 2016-11-16 15:25:42 +0000 | [diff] [blame^] | 31 | bool overrideCoverage, bool blendSupportAllEquations, bool pushconstant) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 32 | : fLocation(location) |
| 33 | , fBinding(binding) |
| 34 | , fIndex(index) |
| 35 | , fSet(set) |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 36 | , fBuiltin(builtin) |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 37 | , fOriginUpperLeft(originUpperLeft) |
| 38 | , fOverrideCoverage(overrideCoverage) |
ethannicholas | fa5f65a | 2016-11-15 12:53:05 -0800 | [diff] [blame] | 39 | , fBlendSupportAllEquations(blendSupportAllEquations) |
Stan Iliev | cb115bd | 2016-11-16 15:25:42 +0000 | [diff] [blame^] | 40 | , fPushConstant(pushconstant) {} |
ethannicholas | fa5f65a | 2016-11-15 12:53:05 -0800 | [diff] [blame] | 41 | |
| 42 | Layout() |
| 43 | : fLocation(-1) |
| 44 | , fBinding(-1) |
| 45 | , fIndex(-1) |
| 46 | , fSet(-1) |
| 47 | , fBuiltin(-1) |
| 48 | , fOriginUpperLeft(false) |
| 49 | , fOverrideCoverage(false) |
| 50 | , fBlendSupportAllEquations(false) |
Stan Iliev | cb115bd | 2016-11-16 15:25:42 +0000 | [diff] [blame^] | 51 | , fPushConstant(false) {} |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 52 | |
| 53 | std::string description() const { |
| 54 | std::string result; |
| 55 | std::string separator; |
| 56 | if (fLocation >= 0) { |
| 57 | result += separator + "location = " + to_string(fLocation); |
| 58 | separator = ", "; |
| 59 | } |
| 60 | if (fBinding >= 0) { |
| 61 | result += separator + "binding = " + to_string(fBinding); |
| 62 | separator = ", "; |
| 63 | } |
| 64 | if (fIndex >= 0) { |
| 65 | result += separator + "index = " + to_string(fIndex); |
| 66 | separator = ", "; |
| 67 | } |
| 68 | if (fSet >= 0) { |
| 69 | result += separator + "set = " + to_string(fSet); |
| 70 | separator = ", "; |
| 71 | } |
| 72 | if (fBuiltin >= 0) { |
| 73 | result += separator + "builtin = " + to_string(fBuiltin); |
| 74 | separator = ", "; |
| 75 | } |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 76 | if (fOriginUpperLeft) { |
| 77 | result += separator + "origin_upper_left"; |
| 78 | separator = ", "; |
| 79 | } |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 80 | if (fOverrideCoverage) { |
| 81 | result += separator + "override_coverage"; |
| 82 | separator = ", "; |
| 83 | } |
| 84 | if (fBlendSupportAllEquations) { |
| 85 | result += separator + "blend_support_all_equations"; |
| 86 | separator = ", "; |
| 87 | } |
ethannicholas | fa5f65a | 2016-11-15 12:53:05 -0800 | [diff] [blame] | 88 | if (fPushConstant) { |
| 89 | result += separator + "push_constant"; |
| 90 | separator = ", "; |
| 91 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 92 | if (result.length() > 0) { |
| 93 | result = "layout (" + result + ")"; |
| 94 | } |
| 95 | return result; |
| 96 | } |
| 97 | |
| 98 | bool operator==(const Layout& other) const { |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 99 | return fLocation == other.fLocation && |
| 100 | fBinding == other.fBinding && |
| 101 | fIndex == other.fIndex && |
| 102 | fSet == other.fSet && |
| 103 | fBuiltin == other.fBuiltin && |
| 104 | fOriginUpperLeft == other.fOriginUpperLeft && |
| 105 | fOverrideCoverage == other.fOverrideCoverage && |
Stan Iliev | cb115bd | 2016-11-16 15:25:42 +0000 | [diff] [blame^] | 106 | fBlendSupportAllEquations == other.fBlendSupportAllEquations; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | bool operator!=(const Layout& other) const { |
| 110 | return !(*this == other); |
| 111 | } |
| 112 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 113 | int fLocation; |
| 114 | int fBinding; |
| 115 | int fIndex; |
| 116 | int fSet; |
| 117 | int fBuiltin; |
ethannicholas | fa5f65a | 2016-11-15 12:53:05 -0800 | [diff] [blame] | 118 | int fOffset; |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 119 | bool fOriginUpperLeft; |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 120 | bool fOverrideCoverage; |
| 121 | bool fBlendSupportAllEquations; |
ethannicholas | fa5f65a | 2016-11-15 12:53:05 -0800 | [diff] [blame] | 122 | bool fPushConstant; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | } // namespace |
| 126 | |
| 127 | #endif |