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 | |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 184 | Uniform::Uniform() |
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 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 192 | Uniform::Uniform(const Uniform &other) : ShaderVariable(other) |
| 193 | { |
| 194 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 195 | |
| 196 | Uniform &Uniform::operator=(const Uniform &other) |
| 197 | { |
| 198 | ShaderVariable::operator=(other); |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 199 | return *this; |
| 200 | } |
| 201 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 202 | bool Uniform::operator==(const Uniform &other) const |
| 203 | { |
| 204 | return ShaderVariable::operator==(other); |
| 205 | } |
| 206 | |
| 207 | bool Uniform::isSameUniformAtLinkTime(const Uniform &other) const |
| 208 | { |
| 209 | return ShaderVariable::isSameVariableAtLinkTime(other, true); |
| 210 | } |
| 211 | |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 212 | InterfaceVariable::InterfaceVariable() : location(-1) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 213 | { |
| 214 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 215 | |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 216 | InterfaceVariable::~InterfaceVariable() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 217 | { |
| 218 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 219 | |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 220 | InterfaceVariable::InterfaceVariable(const InterfaceVariable &other) |
| 221 | : ShaderVariable(other), location(other.location) |
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 | |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 225 | InterfaceVariable &InterfaceVariable::operator=(const InterfaceVariable &other) |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 226 | { |
| 227 | ShaderVariable::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 228 | location = other.location; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 229 | return *this; |
| 230 | } |
| 231 | |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 232 | bool InterfaceVariable::operator==(const InterfaceVariable &other) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 233 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 234 | return (ShaderVariable::operator==(other) && location == other.location); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 237 | Attribute::Attribute() |
| 238 | { |
| 239 | } |
| 240 | |
| 241 | Attribute::~Attribute() |
| 242 | { |
| 243 | } |
| 244 | |
| 245 | Attribute::Attribute(const Attribute &other) : InterfaceVariable(other) |
| 246 | { |
| 247 | } |
| 248 | |
| 249 | Attribute &Attribute::operator=(const Attribute &other) |
| 250 | { |
| 251 | InterfaceVariable::operator=(other); |
| 252 | return *this; |
| 253 | } |
| 254 | |
| 255 | bool Attribute::operator==(const Attribute &other) const |
| 256 | { |
| 257 | return InterfaceVariable::operator==(other); |
| 258 | } |
| 259 | |
| 260 | OutputVariable::OutputVariable() |
| 261 | { |
| 262 | } |
| 263 | |
| 264 | OutputVariable::~OutputVariable() |
| 265 | { |
| 266 | } |
| 267 | |
| 268 | OutputVariable::OutputVariable(const OutputVariable &other) : InterfaceVariable(other) |
| 269 | { |
| 270 | } |
| 271 | |
| 272 | OutputVariable &OutputVariable::operator=(const OutputVariable &other) |
| 273 | { |
| 274 | InterfaceVariable::operator=(other); |
| 275 | return *this; |
| 276 | } |
| 277 | |
| 278 | bool OutputVariable::operator==(const OutputVariable &other) const |
| 279 | { |
| 280 | return InterfaceVariable::operator==(other); |
| 281 | } |
| 282 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 283 | InterfaceBlockField::InterfaceBlockField() : isRowMajorLayout(false) |
| 284 | { |
| 285 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 286 | |
| 287 | InterfaceBlockField::~InterfaceBlockField() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 288 | { |
| 289 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 290 | |
| 291 | InterfaceBlockField::InterfaceBlockField(const InterfaceBlockField &other) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 292 | : ShaderVariable(other), isRowMajorLayout(other.isRowMajorLayout) |
| 293 | { |
| 294 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 295 | |
| 296 | InterfaceBlockField &InterfaceBlockField::operator=(const InterfaceBlockField &other) |
| 297 | { |
| 298 | ShaderVariable::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 299 | isRowMajorLayout = other.isRowMajorLayout; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 300 | return *this; |
| 301 | } |
| 302 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 303 | bool InterfaceBlockField::operator==(const InterfaceBlockField &other) const |
| 304 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 305 | return (ShaderVariable::operator==(other) && isRowMajorLayout == other.isRowMajorLayout); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | bool InterfaceBlockField::isSameInterfaceBlockFieldAtLinkTime( |
| 309 | const InterfaceBlockField &other) const |
| 310 | { |
| 311 | return (ShaderVariable::isSameVariableAtLinkTime(other, true) && |
| 312 | isRowMajorLayout == other.isRowMajorLayout); |
| 313 | } |
| 314 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 315 | Varying::Varying() : interpolation(INTERPOLATION_SMOOTH), isInvariant(false) |
| 316 | { |
| 317 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 318 | |
| 319 | Varying::~Varying() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 320 | { |
| 321 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 322 | |
| 323 | Varying::Varying(const Varying &other) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 324 | : ShaderVariable(other), interpolation(other.interpolation), isInvariant(other.isInvariant) |
| 325 | { |
| 326 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 327 | |
| 328 | Varying &Varying::operator=(const Varying &other) |
| 329 | { |
| 330 | ShaderVariable::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 331 | interpolation = other.interpolation; |
| 332 | isInvariant = other.isInvariant; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 333 | return *this; |
| 334 | } |
| 335 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 336 | bool Varying::operator==(const Varying &other) const |
| 337 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 338 | return (ShaderVariable::operator==(other) && interpolation == other.interpolation && |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 339 | isInvariant == other.isInvariant); |
| 340 | } |
| 341 | |
Jamie Madill | 9e64edc | 2015-05-07 14:08:06 +0000 | [diff] [blame] | 342 | bool Varying::isSameVaryingAtLinkTime(const Varying &other) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 343 | { |
Olli Etuaho | 37ad474 | 2015-04-27 13:18:50 +0300 | [diff] [blame] | 344 | return isSameVaryingAtLinkTime(other, 100); |
| 345 | } |
| 346 | |
| 347 | bool Varying::isSameVaryingAtLinkTime(const Varying &other, int shaderVersion) const |
| 348 | { |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 349 | return (ShaderVariable::isSameVariableAtLinkTime(other, false) && |
Corentin Wallez | 8495498 | 2016-07-12 15:42:18 -0400 | [diff] [blame] | 350 | InterpolationTypesMatch(interpolation, other.interpolation) && |
Olli Etuaho | 37ad474 | 2015-04-27 13:18:50 +0300 | [diff] [blame] | 351 | (shaderVersion >= 300 || isInvariant == other.isInvariant)); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 354 | InterfaceBlock::InterfaceBlock() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 355 | : arraySize(0), layout(BLOCKLAYOUT_PACKED), isRowMajorLayout(false), staticUse(false) |
| 356 | { |
| 357 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 358 | |
| 359 | InterfaceBlock::~InterfaceBlock() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 360 | { |
| 361 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 362 | |
| 363 | InterfaceBlock::InterfaceBlock(const InterfaceBlock &other) |
| 364 | : name(other.name), |
| 365 | mappedName(other.mappedName), |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 366 | instanceName(other.instanceName), |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 367 | arraySize(other.arraySize), |
| 368 | layout(other.layout), |
| 369 | isRowMajorLayout(other.isRowMajorLayout), |
| 370 | staticUse(other.staticUse), |
| 371 | fields(other.fields) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 372 | { |
| 373 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 374 | |
| 375 | InterfaceBlock &InterfaceBlock::operator=(const InterfaceBlock &other) |
| 376 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 377 | name = other.name; |
| 378 | mappedName = other.mappedName; |
| 379 | instanceName = other.instanceName; |
| 380 | arraySize = other.arraySize; |
| 381 | layout = other.layout; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 382 | isRowMajorLayout = other.isRowMajorLayout; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame^] | 383 | staticUse = other.staticUse; |
| 384 | fields = other.fields; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 385 | return *this; |
| 386 | } |
| 387 | |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 388 | std::string InterfaceBlock::fieldPrefix() const |
| 389 | { |
| 390 | return instanceName.empty() ? "" : name; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 391 | } |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 392 | |
Corentin Wallez | 8495498 | 2016-07-12 15:42:18 -0400 | [diff] [blame] | 393 | bool InterfaceBlock::isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other) const |
| 394 | { |
| 395 | if (name != other.name || mappedName != other.mappedName || arraySize != other.arraySize || |
| 396 | layout != other.layout || isRowMajorLayout != other.isRowMajorLayout || |
| 397 | fields.size() != other.fields.size()) |
| 398 | { |
| 399 | return false; |
| 400 | } |
| 401 | |
| 402 | for (size_t fieldIndex = 0; fieldIndex < fields.size(); ++fieldIndex) |
| 403 | { |
| 404 | if (!fields[fieldIndex].isSameInterfaceBlockFieldAtLinkTime(other.fields[fieldIndex])) |
| 405 | { |
| 406 | return false; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | return true; |
| 411 | } |
| 412 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 413 | void WorkGroupSize::fill(int fillValue) |
| 414 | { |
| 415 | localSizeQualifiers[0] = fillValue; |
| 416 | localSizeQualifiers[1] = fillValue; |
| 417 | localSizeQualifiers[2] = fillValue; |
| 418 | } |
| 419 | |
| 420 | void WorkGroupSize::setLocalSize(int localSizeX, int localSizeY, int localSizeZ) |
| 421 | { |
| 422 | localSizeQualifiers[0] = localSizeX; |
| 423 | localSizeQualifiers[1] = localSizeY; |
| 424 | localSizeQualifiers[2] = localSizeZ; |
| 425 | } |
| 426 | |
| 427 | // check that if one of them is less than 1, then all of them are. |
| 428 | // Or if one is positive, then all of them are positive. |
| 429 | bool WorkGroupSize::isLocalSizeValid() const |
| 430 | { |
| 431 | return ( |
| 432 | (localSizeQualifiers[0] < 1 && localSizeQualifiers[1] < 1 && localSizeQualifiers[2] < 1) || |
| 433 | (localSizeQualifiers[0] > 0 && localSizeQualifiers[1] > 0 && localSizeQualifiers[2] > 0)); |
| 434 | } |
| 435 | |
| 436 | bool WorkGroupSize::isAnyValueSet() const |
| 437 | { |
| 438 | return localSizeQualifiers[0] > 0 || localSizeQualifiers[1] > 0 || localSizeQualifiers[2] > 0; |
| 439 | } |
| 440 | |
| 441 | bool WorkGroupSize::isDeclared() const |
| 442 | { |
| 443 | bool localSizeDeclared = localSizeQualifiers[0] > 0; |
| 444 | ASSERT(isLocalSizeValid()); |
| 445 | return localSizeDeclared; |
| 446 | } |
| 447 | |
| 448 | bool WorkGroupSize::isWorkGroupSizeMatching(const WorkGroupSize &right) const |
| 449 | { |
| 450 | for (size_t i = 0u; i < size(); ++i) |
| 451 | { |
| 452 | bool result = (localSizeQualifiers[i] == right.localSizeQualifiers[i] || |
| 453 | (localSizeQualifiers[i] == 1 && right.localSizeQualifiers[i] == -1) || |
| 454 | (localSizeQualifiers[i] == -1 && right.localSizeQualifiers[i] == 1)); |
| 455 | if (!result) |
| 456 | { |
| 457 | return false; |
| 458 | } |
| 459 | } |
| 460 | return true; |
| 461 | } |
| 462 | |
| 463 | int &WorkGroupSize::operator[](size_t index) |
| 464 | { |
| 465 | ASSERT(index < size()); |
| 466 | return localSizeQualifiers[index]; |
| 467 | } |
| 468 | |
| 469 | int WorkGroupSize::operator[](size_t index) const |
| 470 | { |
| 471 | ASSERT(index < size()); |
| 472 | return localSizeQualifiers[index]; |
| 473 | } |
| 474 | |
| 475 | size_t WorkGroupSize::size() const |
| 476 | { |
| 477 | return 3u; |
| 478 | } |
| 479 | |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 480 | } // namespace sh |