blob: 7359262c9664cdde2dc826b28531c862bdd4b045 [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)
Brian Salomon2a51de82016-11-16 12:06:01 -050027 , fBlendSupportAllEquations(layout.fBlendSupportAllEquations)
28 , fFormat(layout.fFormat) {}
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,
Brian Salomon2a51de82016-11-16 12:06:01 -050031 bool overrideCoverage, bool blendSupportAllEquations, ASTLayout::Format format)
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)
Brian Salomon2a51de82016-11-16 12:06:01 -050039 , 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) {}
ethannicholasb3058bd2016-07-01 08:22:01 -070052
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050053 SkString description() const {
54 SkString result;
55 SkString separator;
ethannicholasb3058bd2016-07-01 08:22:01 -070056 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 }
Brian Salomon2a51de82016-11-16 12:06:01 -050088 if (ASTLayout::Format::kUnspecified != fFormat) {
89 result += separator + ASTLayout::FormatToStr(fFormat);
90 separator = ", ";
91 }
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050092 if (result.size() > 0) {
ethannicholasb3058bd2016-07-01 08:22:01 -070093 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 &&
Brian Salomon2a51de82016-11-16 12:06:01 -0500106 fBlendSupportAllEquations == other.fBlendSupportAllEquations &&
107 fFormat == other.fFormat;
ethannicholasb3058bd2016-07-01 08:22:01 -0700108 }
109
110 bool operator!=(const Layout& other) const {
111 return !(*this == other);
112 }
113
egdaniel988283c2016-11-16 07:29:51 -0800114 // everything but builtin is in the GLSL spec; builtin comes from SPIR-V and identifies which
115 // particular builtin value this object represents.
ethannicholasf789b382016-08-03 12:43:36 -0700116 int fLocation;
117 int fBinding;
118 int fIndex;
119 int fSet;
120 int fBuiltin;
121 bool fOriginUpperLeft;
ethannicholas5961bc92016-10-12 06:39:56 -0700122 bool fOverrideCoverage;
123 bool fBlendSupportAllEquations;
Brian Salomon2a51de82016-11-16 12:06:01 -0500124 ASTLayout::Format fFormat;
ethannicholasb3058bd2016-07-01 08:22:01 -0700125};
126
127} // namespace
128
129#endif