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 | { |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 144 | const ShaderVariable *fieldVar = nullptr; |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 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, |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 159 | bool matchPrecision, |
| 160 | bool matchName) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 161 | { |
| 162 | if (type != other.type) |
| 163 | return false; |
| 164 | if (matchPrecision && precision != other.precision) |
| 165 | return false; |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 166 | if (matchName && name != other.name) |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 167 | return false; |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 168 | ASSERT(!matchName || mappedName == other.mappedName); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 169 | if (arraySize != other.arraySize) |
| 170 | return false; |
| 171 | if (fields.size() != other.fields.size()) |
| 172 | return false; |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 173 | |
| 174 | // [OpenGL ES 3.1 SPEC Chapter 7.4.1] |
| 175 | // Variables declared as structures are considered to match in type if and only if structure |
| 176 | // members match in name, type, qualification, and declaration order. |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 177 | for (size_t ii = 0; ii < fields.size(); ++ii) |
| 178 | { |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 179 | if (!fields[ii].isSameVariableAtLinkTime(other.fields[ii], matchPrecision, true)) |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 180 | { |
| 181 | return false; |
| 182 | } |
| 183 | } |
| 184 | if (structName != other.structName) |
| 185 | return false; |
| 186 | return true; |
| 187 | } |
| 188 | |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 189 | Uniform::Uniform() : binding(-1), offset(-1) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 190 | { |
| 191 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 192 | |
| 193 | Uniform::~Uniform() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 194 | { |
| 195 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 196 | |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 197 | Uniform::Uniform(const Uniform &other) |
| 198 | : VariableWithLocation(other), binding(other.binding), offset(other.offset) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 199 | { |
| 200 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 201 | |
| 202 | Uniform &Uniform::operator=(const Uniform &other) |
| 203 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 204 | VariableWithLocation::operator=(other); |
Olli Etuaho | 547cbd4 | 2017-02-27 11:54:00 +0200 | [diff] [blame] | 205 | binding = other.binding; |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 206 | offset = other.offset; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 207 | return *this; |
| 208 | } |
| 209 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 210 | bool Uniform::operator==(const Uniform &other) const |
| 211 | { |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 212 | return VariableWithLocation::operator==(other) && binding == other.binding && |
| 213 | offset == other.offset; |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | bool Uniform::isSameUniformAtLinkTime(const Uniform &other) const |
| 217 | { |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 218 | // Enforce a consistent match. |
| 219 | // https://cvs.khronos.org/bugzilla/show_bug.cgi?id=16261 |
| 220 | if (binding != -1 && other.binding != -1 && binding != other.binding) |
Olli Etuaho | 547cbd4 | 2017-02-27 11:54:00 +0200 | [diff] [blame] | 221 | { |
| 222 | return false; |
| 223 | } |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 224 | if (location != -1 && other.location != -1 && location != other.location) |
| 225 | { |
| 226 | return false; |
| 227 | } |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 228 | if (offset != other.offset) |
| 229 | { |
| 230 | return false; |
| 231 | } |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 232 | return VariableWithLocation::isSameVariableAtLinkTime(other, true, true); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 235 | VariableWithLocation::VariableWithLocation() : location(-1) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 236 | { |
| 237 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 238 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 239 | VariableWithLocation::~VariableWithLocation() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 240 | { |
| 241 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 242 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 243 | VariableWithLocation::VariableWithLocation(const VariableWithLocation &other) |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 244 | : ShaderVariable(other), location(other.location) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 245 | { |
| 246 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 247 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 248 | VariableWithLocation &VariableWithLocation::operator=(const VariableWithLocation &other) |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 249 | { |
| 250 | ShaderVariable::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 251 | location = other.location; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 252 | return *this; |
| 253 | } |
| 254 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 255 | bool VariableWithLocation::operator==(const VariableWithLocation &other) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 256 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 257 | return (ShaderVariable::operator==(other) && location == other.location); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 260 | Attribute::Attribute() |
| 261 | { |
| 262 | } |
| 263 | |
| 264 | Attribute::~Attribute() |
| 265 | { |
| 266 | } |
| 267 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 268 | Attribute::Attribute(const Attribute &other) : VariableWithLocation(other) |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 269 | { |
| 270 | } |
| 271 | |
| 272 | Attribute &Attribute::operator=(const Attribute &other) |
| 273 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 274 | VariableWithLocation::operator=(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 275 | return *this; |
| 276 | } |
| 277 | |
| 278 | bool Attribute::operator==(const Attribute &other) const |
| 279 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 280 | return VariableWithLocation::operator==(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | OutputVariable::OutputVariable() |
| 284 | { |
| 285 | } |
| 286 | |
| 287 | OutputVariable::~OutputVariable() |
| 288 | { |
| 289 | } |
| 290 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 291 | OutputVariable::OutputVariable(const OutputVariable &other) : VariableWithLocation(other) |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 292 | { |
| 293 | } |
| 294 | |
| 295 | OutputVariable &OutputVariable::operator=(const OutputVariable &other) |
| 296 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 297 | VariableWithLocation::operator=(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 298 | return *this; |
| 299 | } |
| 300 | |
| 301 | bool OutputVariable::operator==(const OutputVariable &other) const |
| 302 | { |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 303 | return VariableWithLocation::operator==(other); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 304 | } |
| 305 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 306 | InterfaceBlockField::InterfaceBlockField() : isRowMajorLayout(false) |
| 307 | { |
| 308 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 309 | |
| 310 | InterfaceBlockField::~InterfaceBlockField() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 311 | { |
| 312 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 313 | |
| 314 | InterfaceBlockField::InterfaceBlockField(const InterfaceBlockField &other) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 315 | : ShaderVariable(other), isRowMajorLayout(other.isRowMajorLayout) |
| 316 | { |
| 317 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 318 | |
| 319 | InterfaceBlockField &InterfaceBlockField::operator=(const InterfaceBlockField &other) |
| 320 | { |
| 321 | ShaderVariable::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 322 | isRowMajorLayout = other.isRowMajorLayout; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 323 | return *this; |
| 324 | } |
| 325 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 326 | bool InterfaceBlockField::operator==(const InterfaceBlockField &other) const |
| 327 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 328 | return (ShaderVariable::operator==(other) && isRowMajorLayout == other.isRowMajorLayout); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | bool InterfaceBlockField::isSameInterfaceBlockFieldAtLinkTime( |
| 332 | const InterfaceBlockField &other) const |
| 333 | { |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 334 | return (ShaderVariable::isSameVariableAtLinkTime(other, true, true) && |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 335 | isRowMajorLayout == other.isRowMajorLayout); |
| 336 | } |
| 337 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 338 | Varying::Varying() : interpolation(INTERPOLATION_SMOOTH), isInvariant(false) |
| 339 | { |
| 340 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 341 | |
| 342 | Varying::~Varying() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 343 | { |
| 344 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 345 | |
| 346 | Varying::Varying(const Varying &other) |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 347 | : VariableWithLocation(other), |
| 348 | interpolation(other.interpolation), |
| 349 | isInvariant(other.isInvariant) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 350 | { |
| 351 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 352 | |
| 353 | Varying &Varying::operator=(const Varying &other) |
| 354 | { |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 355 | VariableWithLocation::operator=(other); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 356 | interpolation = other.interpolation; |
| 357 | isInvariant = other.isInvariant; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 358 | return *this; |
| 359 | } |
| 360 | |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 361 | bool Varying::operator==(const Varying &other) const |
| 362 | { |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 363 | return (VariableWithLocation::operator==(other) && interpolation == other.interpolation && |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 364 | isInvariant == other.isInvariant); |
| 365 | } |
| 366 | |
Jamie Madill | 9e64edc | 2015-05-07 14:08:06 +0000 | [diff] [blame] | 367 | bool Varying::isSameVaryingAtLinkTime(const Varying &other) const |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 368 | { |
Olli Etuaho | 37ad474 | 2015-04-27 13:18:50 +0300 | [diff] [blame] | 369 | return isSameVaryingAtLinkTime(other, 100); |
| 370 | } |
| 371 | |
| 372 | bool Varying::isSameVaryingAtLinkTime(const Varying &other, int shaderVersion) const |
| 373 | { |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 374 | return (ShaderVariable::isSameVariableAtLinkTime(other, false, false) && |
Corentin Wallez | 8495498 | 2016-07-12 15:42:18 -0400 | [diff] [blame] | 375 | InterpolationTypesMatch(interpolation, other.interpolation) && |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame^] | 376 | (shaderVersion >= 300 || isInvariant == other.isInvariant) && |
| 377 | (location == other.location) && |
| 378 | (name == other.name || (shaderVersion >= 310 && location >= 0))); |
Zhenyao Mo | ed13636 | 2014-10-03 13:23:01 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 381 | InterfaceBlock::InterfaceBlock() |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 382 | : arraySize(0), |
| 383 | layout(BLOCKLAYOUT_PACKED), |
| 384 | isRowMajorLayout(false), |
| 385 | binding(-1), |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 386 | staticUse(false), |
| 387 | blockType(BlockType::BLOCK_UNIFORM) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 388 | { |
| 389 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 390 | |
| 391 | InterfaceBlock::~InterfaceBlock() |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 392 | { |
| 393 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 394 | |
| 395 | InterfaceBlock::InterfaceBlock(const InterfaceBlock &other) |
| 396 | : name(other.name), |
| 397 | mappedName(other.mappedName), |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 398 | instanceName(other.instanceName), |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 399 | arraySize(other.arraySize), |
| 400 | layout(other.layout), |
| 401 | isRowMajorLayout(other.isRowMajorLayout), |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 402 | binding(other.binding), |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 403 | staticUse(other.staticUse), |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 404 | blockType(other.blockType), |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 405 | fields(other.fields) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 406 | { |
| 407 | } |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 408 | |
| 409 | InterfaceBlock &InterfaceBlock::operator=(const InterfaceBlock &other) |
| 410 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 411 | name = other.name; |
| 412 | mappedName = other.mappedName; |
| 413 | instanceName = other.instanceName; |
| 414 | arraySize = other.arraySize; |
| 415 | layout = other.layout; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 416 | isRowMajorLayout = other.isRowMajorLayout; |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 417 | binding = other.binding; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 418 | staticUse = other.staticUse; |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 419 | blockType = other.blockType; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 420 | fields = other.fields; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 421 | return *this; |
| 422 | } |
| 423 | |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 424 | std::string InterfaceBlock::fieldPrefix() const |
| 425 | { |
| 426 | return instanceName.empty() ? "" : name; |
Jamie Madill | 6a72979 | 2014-07-18 10:33:14 -0400 | [diff] [blame] | 427 | } |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 428 | |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 429 | std::string InterfaceBlock::fieldMappedPrefix() const |
| 430 | { |
| 431 | return instanceName.empty() ? "" : mappedName; |
| 432 | } |
| 433 | |
Corentin Wallez | 8495498 | 2016-07-12 15:42:18 -0400 | [diff] [blame] | 434 | bool InterfaceBlock::isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other) const |
| 435 | { |
| 436 | if (name != other.name || mappedName != other.mappedName || arraySize != other.arraySize || |
| 437 | layout != other.layout || isRowMajorLayout != other.isRowMajorLayout || |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 438 | binding != other.binding || blockType != other.blockType || |
| 439 | fields.size() != other.fields.size()) |
Corentin Wallez | 8495498 | 2016-07-12 15:42:18 -0400 | [diff] [blame] | 440 | { |
| 441 | return false; |
| 442 | } |
| 443 | |
| 444 | for (size_t fieldIndex = 0; fieldIndex < fields.size(); ++fieldIndex) |
| 445 | { |
| 446 | if (!fields[fieldIndex].isSameInterfaceBlockFieldAtLinkTime(other.fields[fieldIndex])) |
| 447 | { |
| 448 | return false; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | return true; |
| 453 | } |
| 454 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 455 | void WorkGroupSize::fill(int fillValue) |
| 456 | { |
| 457 | localSizeQualifiers[0] = fillValue; |
| 458 | localSizeQualifiers[1] = fillValue; |
| 459 | localSizeQualifiers[2] = fillValue; |
| 460 | } |
| 461 | |
| 462 | void WorkGroupSize::setLocalSize(int localSizeX, int localSizeY, int localSizeZ) |
| 463 | { |
| 464 | localSizeQualifiers[0] = localSizeX; |
| 465 | localSizeQualifiers[1] = localSizeY; |
| 466 | localSizeQualifiers[2] = localSizeZ; |
| 467 | } |
| 468 | |
| 469 | // check that if one of them is less than 1, then all of them are. |
| 470 | // Or if one is positive, then all of them are positive. |
| 471 | bool WorkGroupSize::isLocalSizeValid() const |
| 472 | { |
| 473 | return ( |
| 474 | (localSizeQualifiers[0] < 1 && localSizeQualifiers[1] < 1 && localSizeQualifiers[2] < 1) || |
| 475 | (localSizeQualifiers[0] > 0 && localSizeQualifiers[1] > 0 && localSizeQualifiers[2] > 0)); |
| 476 | } |
| 477 | |
| 478 | bool WorkGroupSize::isAnyValueSet() const |
| 479 | { |
| 480 | return localSizeQualifiers[0] > 0 || localSizeQualifiers[1] > 0 || localSizeQualifiers[2] > 0; |
| 481 | } |
| 482 | |
| 483 | bool WorkGroupSize::isDeclared() const |
| 484 | { |
| 485 | bool localSizeDeclared = localSizeQualifiers[0] > 0; |
| 486 | ASSERT(isLocalSizeValid()); |
| 487 | return localSizeDeclared; |
| 488 | } |
| 489 | |
| 490 | bool WorkGroupSize::isWorkGroupSizeMatching(const WorkGroupSize &right) const |
| 491 | { |
| 492 | for (size_t i = 0u; i < size(); ++i) |
| 493 | { |
| 494 | bool result = (localSizeQualifiers[i] == right.localSizeQualifiers[i] || |
| 495 | (localSizeQualifiers[i] == 1 && right.localSizeQualifiers[i] == -1) || |
| 496 | (localSizeQualifiers[i] == -1 && right.localSizeQualifiers[i] == 1)); |
| 497 | if (!result) |
| 498 | { |
| 499 | return false; |
| 500 | } |
| 501 | } |
| 502 | return true; |
| 503 | } |
| 504 | |
| 505 | int &WorkGroupSize::operator[](size_t index) |
| 506 | { |
| 507 | ASSERT(index < size()); |
| 508 | return localSizeQualifiers[index]; |
| 509 | } |
| 510 | |
| 511 | int WorkGroupSize::operator[](size_t index) const |
| 512 | { |
| 513 | ASSERT(index < size()); |
| 514 | return localSizeQualifiers[index]; |
| 515 | } |
| 516 | |
| 517 | size_t WorkGroupSize::size() const |
| 518 | { |
| 519 | return 3u; |
| 520 | } |
| 521 | |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 522 | } // namespace sh |