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 | |
| 37 | ShaderVariable::ShaderVariable(GLenum typeIn, unsigned int arraySizeIn) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 38 | : type(typeIn), precision(0), arraySize(arraySizeIn), staticUse(false) |
| 39 | { |
| 40 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 41 | |
| 42 | ShaderVariable::~ShaderVariable() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 43 | { |
| 44 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 45 | |
| 46 | ShaderVariable::ShaderVariable(const ShaderVariable &other) |
| 47 | : type(other.type), |
| 48 | precision(other.precision), |
| 49 | name(other.name), |
| 50 | mappedName(other.mappedName), |
| 51 | arraySize(other.arraySize), |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 52 | staticUse(other.staticUse), |
| 53 | fields(other.fields), |
| 54 | structName(other.structName) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 55 | { |
| 56 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 57 | |
| 58 | ShaderVariable &ShaderVariable::operator=(const ShaderVariable &other) |
| 59 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 60 | type = other.type; |
| 61 | precision = other.precision; |
| 62 | name = other.name; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 63 | mappedName = other.mappedName; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 64 | arraySize = other.arraySize; |
| 65 | staticUse = other.staticUse; |
| 66 | fields = other.fields; |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 67 | structName = other.structName; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 68 | return *this; |
| 69 | } |
| 70 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 71 | bool ShaderVariable::operator==(const ShaderVariable &other) const |
| 72 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 73 | if (type != other.type || precision != other.precision || name != other.name || |
| 74 | mappedName != other.mappedName || arraySize != other.arraySize || |
| 75 | staticUse != other.staticUse || fields.size() != other.fields.size() || |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 76 | structName != other.structName) |
| 77 | { |
| 78 | return false; |
| 79 | } |
| 80 | for (size_t ii = 0; ii < fields.size(); ++ii) |
| 81 | { |
| 82 | if (fields[ii] != other.fields[ii]) |
| 83 | return false; |
| 84 | } |
| 85 | return true; |
| 86 | } |
| 87 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 88 | bool ShaderVariable::findInfoByMappedName(const std::string &mappedFullName, |
| 89 | const ShaderVariable **leafVar, |
| 90 | std::string *originalFullName) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 91 | { |
| 92 | ASSERT(leafVar && originalFullName); |
| 93 | // There are three cases: |
| 94 | // 1) the top variable is of struct type; |
| 95 | // 2) the top variable is an array; |
| 96 | // 3) otherwise. |
| 97 | size_t pos = mappedFullName.find_first_of(".["); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 98 | |
| 99 | if (pos == std::string::npos) |
| 100 | { |
| 101 | // Case 3. |
| 102 | if (mappedFullName != this->mappedName) |
| 103 | return false; |
| 104 | *originalFullName = this->name; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 105 | *leafVar = this; |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 106 | return true; |
| 107 | } |
| 108 | else |
| 109 | { |
| 110 | std::string topName = mappedFullName.substr(0, pos); |
| 111 | if (topName != this->mappedName) |
| 112 | return false; |
| 113 | std::string originalName = this->name; |
| 114 | std::string remaining; |
| 115 | if (mappedFullName[pos] == '[') |
| 116 | { |
| 117 | // Case 2. |
| 118 | size_t closePos = mappedFullName.find_first_of(']'); |
| 119 | if (closePos < pos || closePos == std::string::npos) |
| 120 | return false; |
| 121 | // Append '[index]'. |
| 122 | originalName += mappedFullName.substr(pos, closePos - pos + 1); |
| 123 | if (closePos + 1 == mappedFullName.size()) |
| 124 | { |
| 125 | *originalFullName = originalName; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 126 | *leafVar = this; |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 127 | return true; |
| 128 | } |
| 129 | else |
| 130 | { |
| 131 | // In the form of 'a[0].b', so after ']', '.' is expected. |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 132 | if (mappedFullName[closePos + 1] != '.') |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 133 | return false; |
| 134 | remaining = mappedFullName.substr(closePos + 2); // Skip "]." |
| 135 | } |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | // Case 1. |
| 140 | remaining = mappedFullName.substr(pos + 1); // Skip "." |
| 141 | } |
| 142 | for (size_t ii = 0; ii < this->fields.size(); ++ii) |
| 143 | { |
| 144 | const ShaderVariable *fieldVar = NULL; |
| 145 | std::string originalFieldName; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 146 | bool found = fields[ii].findInfoByMappedName(remaining, &fieldVar, &originalFieldName); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 147 | if (found) |
| 148 | { |
| 149 | *originalFullName = originalName + "." + originalFieldName; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 150 | *leafVar = fieldVar; |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 151 | return true; |
| 152 | } |
| 153 | } |
| 154 | return false; |
| 155 | } |
| 156 | } |
| 157 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 158 | bool ShaderVariable::isSameVariableAtLinkTime(const ShaderVariable &other, |
| 159 | bool matchPrecision) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 160 | { |
| 161 | if (type != other.type) |
| 162 | return false; |
| 163 | if (matchPrecision && precision != other.precision) |
| 164 | return false; |
| 165 | if (name != other.name) |
| 166 | return false; |
| 167 | ASSERT(mappedName == other.mappedName); |
| 168 | if (arraySize != other.arraySize) |
| 169 | return false; |
| 170 | if (fields.size() != other.fields.size()) |
| 171 | return false; |
| 172 | for (size_t ii = 0; ii < fields.size(); ++ii) |
| 173 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 174 | if (!fields[ii].isSameVariableAtLinkTime(other.fields[ii], matchPrecision)) |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 175 | { |
| 176 | return false; |
| 177 | } |
| 178 | } |
| 179 | if (structName != other.structName) |
| 180 | return false; |
| 181 | return true; |
| 182 | } |
| 183 | |
Olli Etuaho | 547cbd4 | 2017-02-27 11:54:00 +0200 | [diff] [blame] | 184 | Uniform::Uniform() : binding(-1) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 185 | { |
| 186 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 187 | |
| 188 | Uniform::~Uniform() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 189 | { |
| 190 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 191 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 192 | Uniform::Uniform(const Uniform &other) : VariableWithLocation(other), binding(other.binding) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 193 | { |
| 194 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 195 | |
| 196 | Uniform &Uniform::operator=(const Uniform &other) |
| 197 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 198 | VariableWithLocation::operator=(other); |
Olli Etuaho | 547cbd4 | 2017-02-27 11:54:00 +0200 | [diff] [blame] | 199 | binding = other.binding; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 200 | return *this; |
| 201 | } |
| 202 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 203 | bool Uniform::operator==(const Uniform &other) const |
| 204 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 205 | return VariableWithLocation::operator==(other) && binding == other.binding; |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | bool Uniform::isSameUniformAtLinkTime(const Uniform &other) const |
| 209 | { |
Olli Etuaho | 547cbd4 | 2017-02-27 11:54:00 +0200 | [diff] [blame] | 210 | if (binding != -1 && other.binding != -1 && binding != other.binding) |
| 211 | { |
| 212 | return false; |
| 213 | } |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 214 | if (location != -1 && other.location != -1 && location != other.location) |
| 215 | { |
| 216 | return false; |
| 217 | } |
| 218 | return VariableWithLocation::isSameVariableAtLinkTime(other, true); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 221 | VariableWithLocation::VariableWithLocation() : location(-1) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 222 | { |
| 223 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 224 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 225 | VariableWithLocation::~VariableWithLocation() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 226 | { |
| 227 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 228 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 229 | VariableWithLocation::VariableWithLocation(const VariableWithLocation &other) |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 230 | : ShaderVariable(other), location(other.location) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 231 | { |
| 232 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 233 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 234 | VariableWithLocation &VariableWithLocation::operator=(const VariableWithLocation &other) |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 235 | { |
| 236 | ShaderVariable::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 237 | location = other.location; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 238 | return *this; |
| 239 | } |
| 240 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 241 | bool VariableWithLocation::operator==(const VariableWithLocation &other) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 242 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 243 | return (ShaderVariable::operator==(other) && location == other.location); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 246 | Attribute::Attribute() |
| 247 | { |
| 248 | } |
| 249 | |
| 250 | Attribute::~Attribute() |
| 251 | { |
| 252 | } |
| 253 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 254 | Attribute::Attribute(const Attribute &other) : VariableWithLocation(other) |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 255 | { |
| 256 | } |
| 257 | |
| 258 | Attribute &Attribute::operator=(const Attribute &other) |
| 259 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 260 | VariableWithLocation::operator=(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 261 | return *this; |
| 262 | } |
| 263 | |
| 264 | bool Attribute::operator==(const Attribute &other) const |
| 265 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 266 | return VariableWithLocation::operator==(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | OutputVariable::OutputVariable() |
| 270 | { |
| 271 | } |
| 272 | |
| 273 | OutputVariable::~OutputVariable() |
| 274 | { |
| 275 | } |
| 276 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 277 | OutputVariable::OutputVariable(const OutputVariable &other) : VariableWithLocation(other) |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 278 | { |
| 279 | } |
| 280 | |
| 281 | OutputVariable &OutputVariable::operator=(const OutputVariable &other) |
| 282 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 283 | VariableWithLocation::operator=(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 284 | return *this; |
| 285 | } |
| 286 | |
| 287 | bool OutputVariable::operator==(const OutputVariable &other) const |
| 288 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame^] | 289 | return VariableWithLocation::operator==(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 290 | } |
| 291 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 292 | InterfaceBlockField::InterfaceBlockField() : isRowMajorLayout(false) |
| 293 | { |
| 294 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 295 | |
| 296 | InterfaceBlockField::~InterfaceBlockField() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 297 | { |
| 298 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 299 | |
| 300 | InterfaceBlockField::InterfaceBlockField(const InterfaceBlockField &other) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 301 | : ShaderVariable(other), isRowMajorLayout(other.isRowMajorLayout) |
| 302 | { |
| 303 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 304 | |
| 305 | InterfaceBlockField &InterfaceBlockField::operator=(const InterfaceBlockField &other) |
| 306 | { |
| 307 | ShaderVariable::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 308 | isRowMajorLayout = other.isRowMajorLayout; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 309 | return *this; |
| 310 | } |
| 311 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 312 | bool InterfaceBlockField::operator==(const InterfaceBlockField &other) const |
| 313 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 314 | return (ShaderVariable::operator==(other) && isRowMajorLayout == other.isRowMajorLayout); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | bool InterfaceBlockField::isSameInterfaceBlockFieldAtLinkTime( |
| 318 | const InterfaceBlockField &other) const |
| 319 | { |
| 320 | return (ShaderVariable::isSameVariableAtLinkTime(other, true) && |
| 321 | isRowMajorLayout == other.isRowMajorLayout); |
| 322 | } |
| 323 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 324 | Varying::Varying() : interpolation(INTERPOLATION_SMOOTH), isInvariant(false) |
| 325 | { |
| 326 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 327 | |
| 328 | Varying::~Varying() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 329 | { |
| 330 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 331 | |
| 332 | Varying::Varying(const Varying &other) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 333 | : ShaderVariable(other), interpolation(other.interpolation), isInvariant(other.isInvariant) |
| 334 | { |
| 335 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 336 | |
| 337 | Varying &Varying::operator=(const Varying &other) |
| 338 | { |
| 339 | ShaderVariable::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 340 | interpolation = other.interpolation; |
| 341 | isInvariant = other.isInvariant; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 342 | return *this; |
| 343 | } |
| 344 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 345 | bool Varying::operator==(const Varying &other) const |
| 346 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 347 | return (ShaderVariable::operator==(other) && interpolation == other.interpolation && |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 348 | isInvariant == other.isInvariant); |
| 349 | } |
| 350 | |
Jamie Madill | 9e64edc | 2015-05-07 14:08:06 +0000 | [diff] [blame] | 351 | bool Varying::isSameVaryingAtLinkTime(const Varying &other) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 352 | { |
Olli Etuaho | 37ad474 | 2015-04-27 13:18:50 +0300 | [diff] [blame] | 353 | return isSameVaryingAtLinkTime(other, 100); |
| 354 | } |
| 355 | |
| 356 | bool Varying::isSameVaryingAtLinkTime(const Varying &other, int shaderVersion) const |
| 357 | { |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 358 | return (ShaderVariable::isSameVariableAtLinkTime(other, false) && |
Corentin Wallez | 8495498 | 2016-07-12 15:42:18 -0400 | [diff] [blame] | 359 | InterpolationTypesMatch(interpolation, other.interpolation) && |
Olli Etuaho | 37ad474 | 2015-04-27 13:18:50 +0300 | [diff] [blame] | 360 | (shaderVersion >= 300 || isInvariant == other.isInvariant)); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 363 | InterfaceBlock::InterfaceBlock() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 364 | : arraySize(0), layout(BLOCKLAYOUT_PACKED), isRowMajorLayout(false), staticUse(false) |
| 365 | { |
| 366 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 367 | |
| 368 | InterfaceBlock::~InterfaceBlock() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 369 | { |
| 370 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 371 | |
| 372 | InterfaceBlock::InterfaceBlock(const InterfaceBlock &other) |
| 373 | : name(other.name), |
| 374 | mappedName(other.mappedName), |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 375 | instanceName(other.instanceName), |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 376 | arraySize(other.arraySize), |
| 377 | layout(other.layout), |
| 378 | isRowMajorLayout(other.isRowMajorLayout), |
| 379 | staticUse(other.staticUse), |
| 380 | fields(other.fields) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 381 | { |
| 382 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 383 | |
| 384 | InterfaceBlock &InterfaceBlock::operator=(const InterfaceBlock &other) |
| 385 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 386 | name = other.name; |
| 387 | mappedName = other.mappedName; |
| 388 | instanceName = other.instanceName; |
| 389 | arraySize = other.arraySize; |
| 390 | layout = other.layout; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 391 | isRowMajorLayout = other.isRowMajorLayout; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 392 | staticUse = other.staticUse; |
| 393 | fields = other.fields; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 394 | return *this; |
| 395 | } |
| 396 | |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 397 | std::string InterfaceBlock::fieldPrefix() const |
| 398 | { |
| 399 | return instanceName.empty() ? "" : name; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 400 | } |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 401 | |
Corentin Wallez | 8495498 | 2016-07-12 15:42:18 -0400 | [diff] [blame] | 402 | bool InterfaceBlock::isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other) const |
| 403 | { |
| 404 | if (name != other.name || mappedName != other.mappedName || arraySize != other.arraySize || |
| 405 | layout != other.layout || isRowMajorLayout != other.isRowMajorLayout || |
| 406 | fields.size() != other.fields.size()) |
| 407 | { |
| 408 | return false; |
| 409 | } |
| 410 | |
| 411 | for (size_t fieldIndex = 0; fieldIndex < fields.size(); ++fieldIndex) |
| 412 | { |
| 413 | if (!fields[fieldIndex].isSameInterfaceBlockFieldAtLinkTime(other.fields[fieldIndex])) |
| 414 | { |
| 415 | return false; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | return true; |
| 420 | } |
| 421 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 422 | void WorkGroupSize::fill(int fillValue) |
| 423 | { |
| 424 | localSizeQualifiers[0] = fillValue; |
| 425 | localSizeQualifiers[1] = fillValue; |
| 426 | localSizeQualifiers[2] = fillValue; |
| 427 | } |
| 428 | |
| 429 | void WorkGroupSize::setLocalSize(int localSizeX, int localSizeY, int localSizeZ) |
| 430 | { |
| 431 | localSizeQualifiers[0] = localSizeX; |
| 432 | localSizeQualifiers[1] = localSizeY; |
| 433 | localSizeQualifiers[2] = localSizeZ; |
| 434 | } |
| 435 | |
| 436 | // check that if one of them is less than 1, then all of them are. |
| 437 | // Or if one is positive, then all of them are positive. |
| 438 | bool WorkGroupSize::isLocalSizeValid() const |
| 439 | { |
| 440 | return ( |
| 441 | (localSizeQualifiers[0] < 1 && localSizeQualifiers[1] < 1 && localSizeQualifiers[2] < 1) || |
| 442 | (localSizeQualifiers[0] > 0 && localSizeQualifiers[1] > 0 && localSizeQualifiers[2] > 0)); |
| 443 | } |
| 444 | |
| 445 | bool WorkGroupSize::isAnyValueSet() const |
| 446 | { |
| 447 | return localSizeQualifiers[0] > 0 || localSizeQualifiers[1] > 0 || localSizeQualifiers[2] > 0; |
| 448 | } |
| 449 | |
| 450 | bool WorkGroupSize::isDeclared() const |
| 451 | { |
| 452 | bool localSizeDeclared = localSizeQualifiers[0] > 0; |
| 453 | ASSERT(isLocalSizeValid()); |
| 454 | return localSizeDeclared; |
| 455 | } |
| 456 | |
| 457 | bool WorkGroupSize::isWorkGroupSizeMatching(const WorkGroupSize &right) const |
| 458 | { |
| 459 | for (size_t i = 0u; i < size(); ++i) |
| 460 | { |
| 461 | bool result = (localSizeQualifiers[i] == right.localSizeQualifiers[i] || |
| 462 | (localSizeQualifiers[i] == 1 && right.localSizeQualifiers[i] == -1) || |
| 463 | (localSizeQualifiers[i] == -1 && right.localSizeQualifiers[i] == 1)); |
| 464 | if (!result) |
| 465 | { |
| 466 | return false; |
| 467 | } |
| 468 | } |
| 469 | return true; |
| 470 | } |
| 471 | |
| 472 | int &WorkGroupSize::operator[](size_t index) |
| 473 | { |
| 474 | ASSERT(index < size()); |
| 475 | return localSizeQualifiers[index]; |
| 476 | } |
| 477 | |
| 478 | int WorkGroupSize::operator[](size_t index) const |
| 479 | { |
| 480 | ASSERT(index < size()); |
| 481 | return localSizeQualifiers[index]; |
| 482 | } |
| 483 | |
| 484 | size_t WorkGroupSize::size() const |
| 485 | { |
| 486 | return 3u; |
| 487 | } |
| 488 | |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 489 | } // namespace sh |