blob: dfa396758b584741049c46281ee1ebc236789237 [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 */
7
8#ifndef SKSL_LAYOUT
9#define SKSL_LAYOUT
10
11namespace SkSL {
12
13/**
14 * Represents a layout block appearing before a variable declaration, as in:
15 *
16 * layout (location = 0) int x;
17 */
18struct Layout {
19 Layout(const ASTLayout& layout)
20 : fLocation(layout.fLocation)
21 , fBinding(layout.fBinding)
22 , fIndex(layout.fIndex)
23 , fSet(layout.fSet)
ethannicholasf789b382016-08-03 12:43:36 -070024 , fBuiltin(layout.fBuiltin)
ethannicholas5961bc92016-10-12 06:39:56 -070025 , fOriginUpperLeft(layout.fOriginUpperLeft)
26 , fOverrideCoverage(layout.fOverrideCoverage)
ethannicholasfa5f65a2016-11-15 12:53:05 -080027 , fBlendSupportAllEquations(layout.fBlendSupportAllEquations)
Stan Ilievcb115bd2016-11-16 15:25:42 +000028 , fPushConstant(layout.fPushConstant) {}
ethannicholasb3058bd2016-07-01 08:22:01 -070029
ethannicholas5961bc92016-10-12 06:39:56 -070030 Layout(int location, int binding, int index, int set, int builtin, bool originUpperLeft,
Stan Ilievcb115bd2016-11-16 15:25:42 +000031 bool overrideCoverage, bool blendSupportAllEquations, bool pushconstant)
ethannicholasb3058bd2016-07-01 08:22:01 -070032 : fLocation(location)
33 , fBinding(binding)
34 , fIndex(index)
35 , fSet(set)
ethannicholasf789b382016-08-03 12:43:36 -070036 , fBuiltin(builtin)
ethannicholas5961bc92016-10-12 06:39:56 -070037 , fOriginUpperLeft(originUpperLeft)
38 , fOverrideCoverage(overrideCoverage)
ethannicholasfa5f65a2016-11-15 12:53:05 -080039 , fBlendSupportAllEquations(blendSupportAllEquations)
Stan Ilievcb115bd2016-11-16 15:25:42 +000040 , fPushConstant(pushconstant) {}
ethannicholasfa5f65a2016-11-15 12:53:05 -080041
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 Ilievcb115bd2016-11-16 15:25:42 +000051 , fPushConstant(false) {}
ethannicholasb3058bd2016-07-01 08:22:01 -070052
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 }
ethannicholasf789b382016-08-03 12:43:36 -070076 if (fOriginUpperLeft) {
77 result += separator + "origin_upper_left";
78 separator = ", ";
79 }
ethannicholas5961bc92016-10-12 06:39:56 -070080 if (fOverrideCoverage) {
81 result += separator + "override_coverage";
82 separator = ", ";
83 }
84 if (fBlendSupportAllEquations) {
85 result += separator + "blend_support_all_equations";
86 separator = ", ";
87 }
ethannicholasfa5f65a2016-11-15 12:53:05 -080088 if (fPushConstant) {
89 result += separator + "push_constant";
90 separator = ", ";
91 }
ethannicholasb3058bd2016-07-01 08:22:01 -070092 if (result.length() > 0) {
93 result = "layout (" + result + ")";
94 }
95 return result;
96 }
97
98 bool operator==(const Layout& other) const {
ethannicholas5961bc92016-10-12 06:39:56 -070099 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 Ilievcb115bd2016-11-16 15:25:42 +0000106 fBlendSupportAllEquations == other.fBlendSupportAllEquations;
ethannicholasb3058bd2016-07-01 08:22:01 -0700107 }
108
109 bool operator!=(const Layout& other) const {
110 return !(*this == other);
111 }
112
ethannicholasf789b382016-08-03 12:43:36 -0700113 int fLocation;
114 int fBinding;
115 int fIndex;
116 int fSet;
117 int fBuiltin;
ethannicholasfa5f65a2016-11-15 12:53:05 -0800118 int fOffset;
ethannicholasf789b382016-08-03 12:43:36 -0700119 bool fOriginUpperLeft;
ethannicholas5961bc92016-10-12 06:39:56 -0700120 bool fOverrideCoverage;
121 bool fBlendSupportAllEquations;
ethannicholasfa5f65a2016-11-15 12:53:05 -0800122 bool fPushConstant;
ethannicholasb3058bd2016-07-01 08:22:01 -0700123};
124
125} // namespace
126
127#endif