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) |
Brian Salomon | 2a51de8 | 2016-11-16 12:06:01 -0500 | [diff] [blame] | 27 | , fBlendSupportAllEquations(layout.fBlendSupportAllEquations) |
| 28 | , fFormat(layout.fFormat) {} |
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, |
Brian Salomon | 2a51de8 | 2016-11-16 12:06:01 -0500 | [diff] [blame] | 31 | bool overrideCoverage, bool blendSupportAllEquations, ASTLayout::Format format) |
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) |
Brian Salomon | 2a51de8 | 2016-11-16 12:06:01 -0500 | [diff] [blame] | 39 | , fBlendSupportAllEquations(blendSupportAllEquations) |
| 40 | , fFormat(format) {} |
| 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) |
| 51 | , fFormat(ASTLayout::Format::kUnspecified) {} |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 52 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame^] | 53 | SkString description() const { |
| 54 | SkString result; |
| 55 | SkString separator; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 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 | } |
Brian Salomon | 2a51de8 | 2016-11-16 12:06:01 -0500 | [diff] [blame] | 88 | if (ASTLayout::Format::kUnspecified != fFormat) { |
| 89 | result += separator + ASTLayout::FormatToStr(fFormat); |
| 90 | separator = ", "; |
| 91 | } |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame^] | 92 | if (result.size() > 0) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 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 && |
Brian Salomon | 2a51de8 | 2016-11-16 12:06:01 -0500 | [diff] [blame] | 106 | fBlendSupportAllEquations == other.fBlendSupportAllEquations && |
| 107 | fFormat == other.fFormat; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | bool operator!=(const Layout& other) const { |
| 111 | return !(*this == other); |
| 112 | } |
| 113 | |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 114 | // everything but builtin is in the GLSL spec; builtin comes from SPIR-V and identifies which |
| 115 | // particular builtin value this object represents. |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 116 | int fLocation; |
| 117 | int fBinding; |
| 118 | int fIndex; |
| 119 | int fSet; |
| 120 | int fBuiltin; |
| 121 | bool fOriginUpperLeft; |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 122 | bool fOverrideCoverage; |
| 123 | bool fBlendSupportAllEquations; |
Brian Salomon | 2a51de8 | 2016-11-16 12:06:01 -0500 | [diff] [blame] | 124 | ASTLayout::Format fFormat; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | } // namespace |
| 128 | |
| 129 | #endif |