Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
Jamie Madill | a2ad4e8 | 2014-07-17 14:16:32 -0400 | [diff] [blame] | 6 | // ShaderVars.cpp: |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 7 | // Methods for GL variable types (varyings, uniforms, etc) |
| 8 | // |
| 9 | |
Jamie Madill | e294bb8 | 2014-07-17 14:16:26 -0400 | [diff] [blame] | 10 | #include <GLSLANG/ShaderLang.h> |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 11 | |
Olli Etuaho | d57e0db | 2015-04-24 15:05:08 +0300 | [diff] [blame] | 12 | #include "common/debug.h" |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 13 | |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 14 | namespace sh |
| 15 | { |
| 16 | |
Jamie Madill | e9cc469 | 2015-02-19 16:00:13 -0500 | [diff] [blame] | 17 | namespace |
| 18 | { |
| 19 | |
| 20 | InterpolationType GetNonAuxiliaryInterpolationType(InterpolationType interpolation) |
| 21 | { |
| 22 | return (interpolation == INTERPOLATION_CENTROID ? INTERPOLATION_SMOOTH : interpolation); |
| 23 | } |
Jamie Madill | e9cc469 | 2015-02-19 16:00:13 -0500 | [diff] [blame] | 24 | } |
| 25 | // The ES 3.0 spec is not clear on this point, but the ES 3.1 spec, and discussion |
| 26 | // on Khronos.org, clarifies that a smooth/flat mismatch produces a link error, |
| 27 | // but auxiliary qualifier mismatch (centroid) does not. |
| 28 | bool InterpolationTypesMatch(InterpolationType a, InterpolationType b) |
| 29 | { |
| 30 | return (GetNonAuxiliaryInterpolationType(a) == GetNonAuxiliaryInterpolationType(b)); |
| 31 | } |
| 32 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 33 | ShaderVariable::ShaderVariable() : type(0), precision(0), arraySize(0), staticUse(false) |
| 34 | { |
| 35 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 36 | |
Olli Etuaho | e7c2857 | 2017-10-23 16:29:33 +0300 | [diff] [blame^] | 37 | ShaderVariable::ShaderVariable(GLenum typeIn) |
| 38 | : type(typeIn), precision(0), arraySize(0), staticUse(false) |
| 39 | { |
| 40 | } |
| 41 | |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 42 | ShaderVariable::ShaderVariable(GLenum typeIn, unsigned int arraySizeIn) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 43 | : type(typeIn), precision(0), arraySize(arraySizeIn), staticUse(false) |
| 44 | { |
Olli Etuaho | e7c2857 | 2017-10-23 16:29:33 +0300 | [diff] [blame^] | 45 | ASSERT(arraySizeIn != 0); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 46 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 47 | |
| 48 | ShaderVariable::~ShaderVariable() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 49 | { |
| 50 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 51 | |
| 52 | ShaderVariable::ShaderVariable(const ShaderVariable &other) |
| 53 | : type(other.type), |
| 54 | precision(other.precision), |
| 55 | name(other.name), |
| 56 | mappedName(other.mappedName), |
| 57 | arraySize(other.arraySize), |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 58 | staticUse(other.staticUse), |
| 59 | fields(other.fields), |
| 60 | structName(other.structName) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 61 | { |
| 62 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 63 | |
| 64 | ShaderVariable &ShaderVariable::operator=(const ShaderVariable &other) |
| 65 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 66 | type = other.type; |
| 67 | precision = other.precision; |
| 68 | name = other.name; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 69 | mappedName = other.mappedName; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 70 | arraySize = other.arraySize; |
| 71 | staticUse = other.staticUse; |
| 72 | fields = other.fields; |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 73 | structName = other.structName; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 74 | return *this; |
| 75 | } |
| 76 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 77 | bool ShaderVariable::operator==(const ShaderVariable &other) const |
| 78 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 79 | if (type != other.type || precision != other.precision || name != other.name || |
| 80 | mappedName != other.mappedName || arraySize != other.arraySize || |
| 81 | staticUse != other.staticUse || fields.size() != other.fields.size() || |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 82 | structName != other.structName) |
| 83 | { |
| 84 | return false; |
| 85 | } |
| 86 | for (size_t ii = 0; ii < fields.size(); ++ii) |
| 87 | { |
| 88 | if (fields[ii] != other.fields[ii]) |
| 89 | return false; |
| 90 | } |
| 91 | return true; |
| 92 | } |
| 93 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 94 | bool ShaderVariable::findInfoByMappedName(const std::string &mappedFullName, |
| 95 | const ShaderVariable **leafVar, |
| 96 | std::string *originalFullName) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 97 | { |
| 98 | ASSERT(leafVar && originalFullName); |
| 99 | // There are three cases: |
| 100 | // 1) the top variable is of struct type; |
| 101 | // 2) the top variable is an array; |
| 102 | // 3) otherwise. |
| 103 | size_t pos = mappedFullName.find_first_of(".["); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 104 | |
| 105 | if (pos == std::string::npos) |
| 106 | { |
| 107 | // Case 3. |
| 108 | if (mappedFullName != this->mappedName) |
| 109 | return false; |
| 110 | *originalFullName = this->name; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 111 | *leafVar = this; |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 112 | return true; |
| 113 | } |
| 114 | else |
| 115 | { |
| 116 | std::string topName = mappedFullName.substr(0, pos); |
| 117 | if (topName != this->mappedName) |
| 118 | return false; |
| 119 | std::string originalName = this->name; |
| 120 | std::string remaining; |
| 121 | if (mappedFullName[pos] == '[') |
| 122 | { |
| 123 | // Case 2. |
| 124 | size_t closePos = mappedFullName.find_first_of(']'); |
| 125 | if (closePos < pos || closePos == std::string::npos) |
| 126 | return false; |
| 127 | // Append '[index]'. |
| 128 | originalName += mappedFullName.substr(pos, closePos - pos + 1); |
| 129 | if (closePos + 1 == mappedFullName.size()) |
| 130 | { |
| 131 | *originalFullName = originalName; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 132 | *leafVar = this; |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 133 | return true; |
| 134 | } |
| 135 | else |
| 136 | { |
| 137 | // In the form of 'a[0].b', so after ']', '.' is expected. |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 138 | if (mappedFullName[closePos + 1] != '.') |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 139 | return false; |
| 140 | remaining = mappedFullName.substr(closePos + 2); // Skip "]." |
| 141 | } |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | // Case 1. |
| 146 | remaining = mappedFullName.substr(pos + 1); // Skip "." |
| 147 | } |
| 148 | for (size_t ii = 0; ii < this->fields.size(); ++ii) |
| 149 | { |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 150 | const ShaderVariable *fieldVar = nullptr; |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 151 | std::string originalFieldName; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 152 | bool found = fields[ii].findInfoByMappedName(remaining, &fieldVar, &originalFieldName); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 153 | if (found) |
| 154 | { |
| 155 | *originalFullName = originalName + "." + originalFieldName; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 156 | *leafVar = fieldVar; |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 157 | return true; |
| 158 | } |
| 159 | } |
| 160 | return false; |
| 161 | } |
| 162 | } |
| 163 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 164 | bool ShaderVariable::isSameVariableAtLinkTime(const ShaderVariable &other, |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 165 | bool matchPrecision, |
| 166 | bool matchName) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 167 | { |
| 168 | if (type != other.type) |
| 169 | return false; |
| 170 | if (matchPrecision && precision != other.precision) |
| 171 | return false; |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 172 | if (matchName && name != other.name) |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 173 | return false; |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 174 | ASSERT(!matchName || mappedName == other.mappedName); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 175 | if (arraySize != other.arraySize) |
| 176 | return false; |
| 177 | if (fields.size() != other.fields.size()) |
| 178 | return false; |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 179 | |
| 180 | // [OpenGL ES 3.1 SPEC Chapter 7.4.1] |
| 181 | // Variables declared as structures are considered to match in type if and only if structure |
| 182 | // members match in name, type, qualification, and declaration order. |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 183 | for (size_t ii = 0; ii < fields.size(); ++ii) |
| 184 | { |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 185 | if (!fields[ii].isSameVariableAtLinkTime(other.fields[ii], matchPrecision, true)) |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 186 | { |
| 187 | return false; |
| 188 | } |
| 189 | } |
| 190 | if (structName != other.structName) |
| 191 | return false; |
| 192 | return true; |
| 193 | } |
| 194 | |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 195 | Uniform::Uniform() : binding(-1), offset(-1) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 196 | { |
| 197 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 198 | |
| 199 | Uniform::~Uniform() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 200 | { |
| 201 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 202 | |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 203 | Uniform::Uniform(const Uniform &other) |
| 204 | : VariableWithLocation(other), binding(other.binding), offset(other.offset) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 205 | { |
| 206 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 207 | |
| 208 | Uniform &Uniform::operator=(const Uniform &other) |
| 209 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 210 | VariableWithLocation::operator=(other); |
Olli Etuaho | 547cbd4 | 2017-02-27 11:54:00 +0200 | [diff] [blame] | 211 | binding = other.binding; |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 212 | offset = other.offset; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 213 | return *this; |
| 214 | } |
| 215 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 216 | bool Uniform::operator==(const Uniform &other) const |
| 217 | { |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 218 | return VariableWithLocation::operator==(other) && binding == other.binding && |
| 219 | offset == other.offset; |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | bool Uniform::isSameUniformAtLinkTime(const Uniform &other) const |
| 223 | { |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 224 | // Enforce a consistent match. |
| 225 | // https://cvs.khronos.org/bugzilla/show_bug.cgi?id=16261 |
| 226 | if (binding != -1 && other.binding != -1 && binding != other.binding) |
Olli Etuaho | 547cbd4 | 2017-02-27 11:54:00 +0200 | [diff] [blame] | 227 | { |
| 228 | return false; |
| 229 | } |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 230 | if (location != -1 && other.location != -1 && location != other.location) |
| 231 | { |
| 232 | return false; |
| 233 | } |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 234 | if (offset != other.offset) |
| 235 | { |
| 236 | return false; |
| 237 | } |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 238 | return VariableWithLocation::isSameVariableAtLinkTime(other, true, true); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 241 | VariableWithLocation::VariableWithLocation() : location(-1) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 242 | { |
| 243 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 244 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 245 | VariableWithLocation::~VariableWithLocation() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 246 | { |
| 247 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 248 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 249 | VariableWithLocation::VariableWithLocation(const VariableWithLocation &other) |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 250 | : ShaderVariable(other), location(other.location) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 251 | { |
| 252 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 253 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 254 | VariableWithLocation &VariableWithLocation::operator=(const VariableWithLocation &other) |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 255 | { |
| 256 | ShaderVariable::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 257 | location = other.location; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 258 | return *this; |
| 259 | } |
| 260 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 261 | bool VariableWithLocation::operator==(const VariableWithLocation &other) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 262 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 263 | return (ShaderVariable::operator==(other) && location == other.location); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 266 | Attribute::Attribute() |
| 267 | { |
| 268 | } |
| 269 | |
| 270 | Attribute::~Attribute() |
| 271 | { |
| 272 | } |
| 273 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 274 | Attribute::Attribute(const Attribute &other) : VariableWithLocation(other) |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 275 | { |
| 276 | } |
| 277 | |
| 278 | Attribute &Attribute::operator=(const Attribute &other) |
| 279 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 280 | VariableWithLocation::operator=(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 281 | return *this; |
| 282 | } |
| 283 | |
| 284 | bool Attribute::operator==(const Attribute &other) const |
| 285 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 286 | return VariableWithLocation::operator==(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | OutputVariable::OutputVariable() |
| 290 | { |
| 291 | } |
| 292 | |
| 293 | OutputVariable::~OutputVariable() |
| 294 | { |
| 295 | } |
| 296 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 297 | OutputVariable::OutputVariable(const OutputVariable &other) : VariableWithLocation(other) |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 298 | { |
| 299 | } |
| 300 | |
| 301 | OutputVariable &OutputVariable::operator=(const OutputVariable &other) |
| 302 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 303 | VariableWithLocation::operator=(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 304 | return *this; |
| 305 | } |
| 306 | |
| 307 | bool OutputVariable::operator==(const OutputVariable &other) const |
| 308 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 309 | return VariableWithLocation::operator==(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 312 | InterfaceBlockField::InterfaceBlockField() : isRowMajorLayout(false) |
| 313 | { |
| 314 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 315 | |
| 316 | InterfaceBlockField::~InterfaceBlockField() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 317 | { |
| 318 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 319 | |
| 320 | InterfaceBlockField::InterfaceBlockField(const InterfaceBlockField &other) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 321 | : ShaderVariable(other), isRowMajorLayout(other.isRowMajorLayout) |
| 322 | { |
| 323 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 324 | |
| 325 | InterfaceBlockField &InterfaceBlockField::operator=(const InterfaceBlockField &other) |
| 326 | { |
| 327 | ShaderVariable::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 328 | isRowMajorLayout = other.isRowMajorLayout; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 329 | return *this; |
| 330 | } |
| 331 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 332 | bool InterfaceBlockField::operator==(const InterfaceBlockField &other) const |
| 333 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 334 | return (ShaderVariable::operator==(other) && isRowMajorLayout == other.isRowMajorLayout); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | bool InterfaceBlockField::isSameInterfaceBlockFieldAtLinkTime( |
| 338 | const InterfaceBlockField &other) const |
| 339 | { |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 340 | return (ShaderVariable::isSameVariableAtLinkTime(other, true, true) && |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 341 | isRowMajorLayout == other.isRowMajorLayout); |
| 342 | } |
| 343 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 344 | Varying::Varying() : interpolation(INTERPOLATION_SMOOTH), isInvariant(false) |
| 345 | { |
| 346 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 347 | |
| 348 | Varying::~Varying() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 349 | { |
| 350 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 351 | |
| 352 | Varying::Varying(const Varying &other) |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 353 | : VariableWithLocation(other), |
| 354 | interpolation(other.interpolation), |
| 355 | isInvariant(other.isInvariant) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 356 | { |
| 357 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 358 | |
| 359 | Varying &Varying::operator=(const Varying &other) |
| 360 | { |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 361 | VariableWithLocation::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 362 | interpolation = other.interpolation; |
| 363 | isInvariant = other.isInvariant; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 364 | return *this; |
| 365 | } |
| 366 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 367 | bool Varying::operator==(const Varying &other) const |
| 368 | { |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 369 | return (VariableWithLocation::operator==(other) && interpolation == other.interpolation && |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 370 | isInvariant == other.isInvariant); |
| 371 | } |
| 372 | |
Jamie Madill | 9e64edc | 2015-05-07 14:08:06 +0000 | [diff] [blame] | 373 | bool Varying::isSameVaryingAtLinkTime(const Varying &other) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 374 | { |
Olli Etuaho | 37ad474 | 2015-04-27 13:18:50 +0300 | [diff] [blame] | 375 | return isSameVaryingAtLinkTime(other, 100); |
| 376 | } |
| 377 | |
| 378 | bool Varying::isSameVaryingAtLinkTime(const Varying &other, int shaderVersion) const |
| 379 | { |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 380 | return (ShaderVariable::isSameVariableAtLinkTime(other, false, false) && |
Corentin Wallez | 8495498 | 2016-07-12 15:42:18 -0400 | [diff] [blame] | 381 | InterpolationTypesMatch(interpolation, other.interpolation) && |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 382 | (shaderVersion >= 300 || isInvariant == other.isInvariant) && |
| 383 | (location == other.location) && |
| 384 | (name == other.name || (shaderVersion >= 310 && location >= 0))); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 387 | InterfaceBlock::InterfaceBlock() |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 388 | : arraySize(0), |
| 389 | layout(BLOCKLAYOUT_PACKED), |
| 390 | isRowMajorLayout(false), |
| 391 | binding(-1), |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 392 | staticUse(false), |
| 393 | blockType(BlockType::BLOCK_UNIFORM) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 394 | { |
| 395 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 396 | |
| 397 | InterfaceBlock::~InterfaceBlock() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 398 | { |
| 399 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 400 | |
| 401 | InterfaceBlock::InterfaceBlock(const InterfaceBlock &other) |
| 402 | : name(other.name), |
| 403 | mappedName(other.mappedName), |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 404 | instanceName(other.instanceName), |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 405 | arraySize(other.arraySize), |
| 406 | layout(other.layout), |
| 407 | isRowMajorLayout(other.isRowMajorLayout), |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 408 | binding(other.binding), |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 409 | staticUse(other.staticUse), |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 410 | blockType(other.blockType), |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 411 | fields(other.fields) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 412 | { |
| 413 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 414 | |
| 415 | InterfaceBlock &InterfaceBlock::operator=(const InterfaceBlock &other) |
| 416 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 417 | name = other.name; |
| 418 | mappedName = other.mappedName; |
| 419 | instanceName = other.instanceName; |
| 420 | arraySize = other.arraySize; |
| 421 | layout = other.layout; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 422 | isRowMajorLayout = other.isRowMajorLayout; |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 423 | binding = other.binding; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 424 | staticUse = other.staticUse; |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 425 | blockType = other.blockType; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 426 | fields = other.fields; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 427 | return *this; |
| 428 | } |
| 429 | |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 430 | std::string InterfaceBlock::fieldPrefix() const |
| 431 | { |
| 432 | return instanceName.empty() ? "" : name; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 433 | } |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 434 | |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 435 | std::string InterfaceBlock::fieldMappedPrefix() const |
| 436 | { |
| 437 | return instanceName.empty() ? "" : mappedName; |
| 438 | } |
| 439 | |
Corentin Wallez | 8495498 | 2016-07-12 15:42:18 -0400 | [diff] [blame] | 440 | bool InterfaceBlock::isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other) const |
| 441 | { |
| 442 | if (name != other.name || mappedName != other.mappedName || arraySize != other.arraySize || |
| 443 | layout != other.layout || isRowMajorLayout != other.isRowMajorLayout || |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 444 | binding != other.binding || blockType != other.blockType || |
| 445 | fields.size() != other.fields.size()) |
Corentin Wallez | 8495498 | 2016-07-12 15:42:18 -0400 | [diff] [blame] | 446 | { |
| 447 | return false; |
| 448 | } |
| 449 | |
| 450 | for (size_t fieldIndex = 0; fieldIndex < fields.size(); ++fieldIndex) |
| 451 | { |
| 452 | if (!fields[fieldIndex].isSameInterfaceBlockFieldAtLinkTime(other.fields[fieldIndex])) |
| 453 | { |
| 454 | return false; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | return true; |
| 459 | } |
| 460 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 461 | void WorkGroupSize::fill(int fillValue) |
| 462 | { |
| 463 | localSizeQualifiers[0] = fillValue; |
| 464 | localSizeQualifiers[1] = fillValue; |
| 465 | localSizeQualifiers[2] = fillValue; |
| 466 | } |
| 467 | |
| 468 | void WorkGroupSize::setLocalSize(int localSizeX, int localSizeY, int localSizeZ) |
| 469 | { |
| 470 | localSizeQualifiers[0] = localSizeX; |
| 471 | localSizeQualifiers[1] = localSizeY; |
| 472 | localSizeQualifiers[2] = localSizeZ; |
| 473 | } |
| 474 | |
| 475 | // check that if one of them is less than 1, then all of them are. |
| 476 | // Or if one is positive, then all of them are positive. |
| 477 | bool WorkGroupSize::isLocalSizeValid() const |
| 478 | { |
| 479 | return ( |
| 480 | (localSizeQualifiers[0] < 1 && localSizeQualifiers[1] < 1 && localSizeQualifiers[2] < 1) || |
| 481 | (localSizeQualifiers[0] > 0 && localSizeQualifiers[1] > 0 && localSizeQualifiers[2] > 0)); |
| 482 | } |
| 483 | |
| 484 | bool WorkGroupSize::isAnyValueSet() const |
| 485 | { |
| 486 | return localSizeQualifiers[0] > 0 || localSizeQualifiers[1] > 0 || localSizeQualifiers[2] > 0; |
| 487 | } |
| 488 | |
| 489 | bool WorkGroupSize::isDeclared() const |
| 490 | { |
| 491 | bool localSizeDeclared = localSizeQualifiers[0] > 0; |
| 492 | ASSERT(isLocalSizeValid()); |
| 493 | return localSizeDeclared; |
| 494 | } |
| 495 | |
| 496 | bool WorkGroupSize::isWorkGroupSizeMatching(const WorkGroupSize &right) const |
| 497 | { |
| 498 | for (size_t i = 0u; i < size(); ++i) |
| 499 | { |
| 500 | bool result = (localSizeQualifiers[i] == right.localSizeQualifiers[i] || |
| 501 | (localSizeQualifiers[i] == 1 && right.localSizeQualifiers[i] == -1) || |
| 502 | (localSizeQualifiers[i] == -1 && right.localSizeQualifiers[i] == 1)); |
| 503 | if (!result) |
| 504 | { |
| 505 | return false; |
| 506 | } |
| 507 | } |
| 508 | return true; |
| 509 | } |
| 510 | |
| 511 | int &WorkGroupSize::operator[](size_t index) |
| 512 | { |
| 513 | ASSERT(index < size()); |
| 514 | return localSizeQualifiers[index]; |
| 515 | } |
| 516 | |
| 517 | int WorkGroupSize::operator[](size_t index) const |
| 518 | { |
| 519 | ASSERT(index < size()); |
| 520 | return localSizeQualifiers[index]; |
| 521 | } |
| 522 | |
| 523 | size_t WorkGroupSize::size() const |
| 524 | { |
| 525 | return 3u; |
| 526 | } |
| 527 | |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 528 | } // namespace sh |