daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // Program.cpp: Implements the gl::Program class. Implements GL program objects |
| 8 | // and related functionality. [OpenGL ES 2.0.24] section 2.10.3 page 28. |
| 9 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 10 | #include "libANGLE/Program.h" |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 11 | |
Jamie Madill | 9e0478f | 2015-01-13 11:13:54 -0500 | [diff] [blame] | 12 | #include <algorithm> |
| 13 | |
Jamie Madill | 20e005b | 2017-04-07 14:19:22 -0400 | [diff] [blame] | 14 | #include "common/bitset_utils.h" |
Jamie Madill | 9e0478f | 2015-01-13 11:13:54 -0500 | [diff] [blame] | 15 | #include "common/debug.h" |
| 16 | #include "common/platform.h" |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 17 | #include "common/string_utils.h" |
Jamie Madill | 9e0478f | 2015-01-13 11:13:54 -0500 | [diff] [blame] | 18 | #include "common/utilities.h" |
Jamie Madill | 9e0478f | 2015-01-13 11:13:54 -0500 | [diff] [blame] | 19 | #include "compiler/translator/blocklayout.h" |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 20 | #include "libANGLE/Context.h" |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 21 | #include "libANGLE/MemoryProgramCache.h" |
Jamie Madill | 7af0de5 | 2017-11-06 17:09:33 -0500 | [diff] [blame] | 22 | #include "libANGLE/ProgramLinkedResources.h" |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 23 | #include "libANGLE/ResourceManager.h" |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 24 | #include "libANGLE/Uniform.h" |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 25 | #include "libANGLE/VaryingPacking.h" |
| 26 | #include "libANGLE/features.h" |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 27 | #include "libANGLE/histogram_macros.h" |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 28 | #include "libANGLE/queryconversions.h" |
| 29 | #include "libANGLE/renderer/GLImplFactory.h" |
| 30 | #include "libANGLE/renderer/ProgramImpl.h" |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 31 | #include "platform/Platform.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 32 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 33 | namespace gl |
| 34 | { |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 35 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 36 | namespace |
| 37 | { |
| 38 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 39 | // This simplified cast function doesn't need to worry about advanced concepts like |
| 40 | // depth range values, or casting to bool. |
| 41 | template <typename DestT, typename SrcT> |
| 42 | DestT UniformStateQueryCast(SrcT value); |
| 43 | |
| 44 | // From-Float-To-Integer Casts |
| 45 | template <> |
| 46 | GLint UniformStateQueryCast(GLfloat value) |
| 47 | { |
| 48 | return clampCast<GLint>(roundf(value)); |
| 49 | } |
| 50 | |
| 51 | template <> |
| 52 | GLuint UniformStateQueryCast(GLfloat value) |
| 53 | { |
| 54 | return clampCast<GLuint>(roundf(value)); |
| 55 | } |
| 56 | |
| 57 | // From-Integer-to-Integer Casts |
| 58 | template <> |
| 59 | GLint UniformStateQueryCast(GLuint value) |
| 60 | { |
| 61 | return clampCast<GLint>(value); |
| 62 | } |
| 63 | |
| 64 | template <> |
| 65 | GLuint UniformStateQueryCast(GLint value) |
| 66 | { |
| 67 | return clampCast<GLuint>(value); |
| 68 | } |
| 69 | |
| 70 | // From-Boolean-to-Anything Casts |
| 71 | template <> |
| 72 | GLfloat UniformStateQueryCast(GLboolean value) |
| 73 | { |
| 74 | return (value == GL_TRUE ? 1.0f : 0.0f); |
| 75 | } |
| 76 | |
| 77 | template <> |
| 78 | GLint UniformStateQueryCast(GLboolean value) |
| 79 | { |
| 80 | return (value == GL_TRUE ? 1 : 0); |
| 81 | } |
| 82 | |
| 83 | template <> |
| 84 | GLuint UniformStateQueryCast(GLboolean value) |
| 85 | { |
| 86 | return (value == GL_TRUE ? 1u : 0u); |
| 87 | } |
| 88 | |
| 89 | // Default to static_cast |
| 90 | template <typename DestT, typename SrcT> |
| 91 | DestT UniformStateQueryCast(SrcT value) |
| 92 | { |
| 93 | return static_cast<DestT>(value); |
| 94 | } |
| 95 | |
| 96 | template <typename SrcT, typename DestT> |
| 97 | void UniformStateQueryCastLoop(DestT *dataOut, const uint8_t *srcPointer, int components) |
| 98 | { |
| 99 | for (int comp = 0; comp < components; ++comp) |
| 100 | { |
| 101 | // We only work with strides of 4 bytes for uniform components. (GLfloat/GLint) |
| 102 | // Don't use SrcT stride directly since GLboolean has a stride of 1 byte. |
| 103 | size_t offset = comp * 4; |
| 104 | const SrcT *typedSrcPointer = reinterpret_cast<const SrcT *>(&srcPointer[offset]); |
| 105 | dataOut[comp] = UniformStateQueryCast<DestT>(*typedSrcPointer); |
| 106 | } |
| 107 | } |
| 108 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 109 | // true if varying x has a higher priority in packing than y |
| 110 | bool ComparePackedVarying(const PackedVarying &x, const PackedVarying &y) |
| 111 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 112 | // If the PackedVarying 'x' or 'y' to be compared is an array element, this clones an equivalent |
| 113 | // non-array shader variable 'vx' or 'vy' for actual comparison instead. |
| 114 | sh::ShaderVariable vx, vy; |
| 115 | const sh::ShaderVariable *px, *py; |
| 116 | if (x.isArrayElement()) |
| 117 | { |
| 118 | vx = *x.varying; |
| 119 | vx.arraySize = 0; |
| 120 | px = &vx; |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | px = x.varying; |
| 125 | } |
| 126 | |
| 127 | if (y.isArrayElement()) |
| 128 | { |
| 129 | vy = *y.varying; |
| 130 | vy.arraySize = 0; |
| 131 | py = &vy; |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | py = y.varying; |
| 136 | } |
| 137 | |
| 138 | return gl::CompareShaderVar(*px, *py); |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 139 | } |
| 140 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 141 | template <typename VarT> |
| 142 | GLuint GetResourceIndexFromName(const std::vector<VarT> &list, const std::string &name) |
| 143 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 144 | std::string nameAsArrayName = name + "[0]"; |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 145 | for (size_t index = 0; index < list.size(); index++) |
| 146 | { |
| 147 | const VarT &resource = list[index]; |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 148 | if (resource.name == name || (resource.isArray() && resource.name == nameAsArrayName)) |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 149 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 150 | return static_cast<GLuint>(index); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
| 154 | return GL_INVALID_INDEX; |
| 155 | } |
| 156 | |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 157 | template <typename VarT> |
| 158 | GLint GetVariableLocation(const std::vector<VarT> &list, |
| 159 | const std::vector<VariableLocation> &locationList, |
| 160 | const std::string &name) |
| 161 | { |
| 162 | size_t nameLengthWithoutArrayIndex; |
| 163 | unsigned int arrayIndex = ParseArrayIndex(name, &nameLengthWithoutArrayIndex); |
| 164 | |
| 165 | for (size_t location = 0u; location < locationList.size(); ++location) |
| 166 | { |
| 167 | const VariableLocation &variableLocation = locationList[location]; |
| 168 | if (!variableLocation.used()) |
| 169 | { |
| 170 | continue; |
| 171 | } |
| 172 | |
| 173 | const VarT &variable = list[variableLocation.index]; |
| 174 | |
| 175 | if (angle::BeginsWith(variable.name, name)) |
| 176 | { |
| 177 | if (name.length() == variable.name.length()) |
| 178 | { |
| 179 | ASSERT(name == variable.name); |
| 180 | // GLES 3.1 November 2016 page 87. |
| 181 | // The string exactly matches the name of the active variable. |
| 182 | return static_cast<GLint>(location); |
| 183 | } |
| 184 | if (name.length() + 3u == variable.name.length() && variable.isArray()) |
| 185 | { |
| 186 | ASSERT(name + "[0]" == variable.name); |
| 187 | // The string identifies the base name of an active array, where the string would |
| 188 | // exactly match the name of the variable if the suffix "[0]" were appended to the |
| 189 | // string. |
| 190 | return static_cast<GLint>(location); |
| 191 | } |
| 192 | } |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 193 | if (variable.isArray() && variableLocation.arrayIndex == arrayIndex && |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 194 | nameLengthWithoutArrayIndex + 3u == variable.name.length() && |
| 195 | angle::BeginsWith(variable.name, name, nameLengthWithoutArrayIndex)) |
| 196 | { |
| 197 | ASSERT(name.substr(0u, nameLengthWithoutArrayIndex) + "[0]" == variable.name); |
| 198 | // The string identifies an active element of the array, where the string ends with the |
| 199 | // concatenation of the "[" character, an integer (with no "+" sign, extra leading |
| 200 | // zeroes, or whitespace) identifying an array element, and the "]" character, the |
| 201 | // integer is less than the number of active elements of the array variable, and where |
| 202 | // the string would exactly match the enumerated name of the array if the decimal |
| 203 | // integer were replaced with zero. |
| 204 | return static_cast<GLint>(location); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | return -1; |
| 209 | } |
| 210 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 211 | void CopyStringToBuffer(GLchar *buffer, const std::string &string, GLsizei bufSize, GLsizei *length) |
| 212 | { |
| 213 | ASSERT(bufSize > 0); |
| 214 | strncpy(buffer, string.c_str(), bufSize); |
| 215 | buffer[bufSize - 1] = '\0'; |
| 216 | |
| 217 | if (length) |
| 218 | { |
| 219 | *length = static_cast<GLsizei>(strlen(buffer)); |
| 220 | } |
| 221 | } |
| 222 | |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 223 | bool IncludeSameArrayElement(const std::set<std::string> &nameSet, const std::string &name) |
| 224 | { |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 225 | std::vector<unsigned int> subscripts; |
| 226 | std::string baseName = ParseResourceName(name, &subscripts); |
| 227 | for (auto nameInSet : nameSet) |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 228 | { |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 229 | std::vector<unsigned int> arrayIndices; |
| 230 | std::string arrayName = ParseResourceName(nameInSet, &arrayIndices); |
| 231 | if (baseName == arrayName && |
| 232 | (subscripts.empty() || arrayIndices.empty() || subscripts == arrayIndices)) |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 233 | { |
| 234 | return true; |
| 235 | } |
| 236 | } |
| 237 | return false; |
| 238 | } |
| 239 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 240 | bool validateInterfaceBlocksCount(GLuint maxInterfaceBlocks, |
| 241 | const std::vector<sh::InterfaceBlock> &interfaceBlocks, |
| 242 | const std::string &errorMessage, |
| 243 | InfoLog &infoLog) |
| 244 | { |
| 245 | GLuint blockCount = 0; |
| 246 | for (const sh::InterfaceBlock &block : interfaceBlocks) |
| 247 | { |
| 248 | if (block.staticUse || block.layout != sh::BLOCKLAYOUT_PACKED) |
| 249 | { |
| 250 | blockCount += (block.arraySize ? block.arraySize : 1); |
| 251 | if (blockCount > maxInterfaceBlocks) |
| 252 | { |
| 253 | infoLog << errorMessage << maxInterfaceBlocks << ")"; |
| 254 | return false; |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | return true; |
| 259 | } |
| 260 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 261 | GLuint GetInterfaceBlockIndex(const std::vector<InterfaceBlock> &list, const std::string &name) |
| 262 | { |
| 263 | std::vector<unsigned int> subscripts; |
| 264 | std::string baseName = ParseResourceName(name, &subscripts); |
| 265 | |
| 266 | unsigned int numBlocks = static_cast<unsigned int>(list.size()); |
| 267 | for (unsigned int blockIndex = 0; blockIndex < numBlocks; blockIndex++) |
| 268 | { |
| 269 | const auto &block = list[blockIndex]; |
| 270 | if (block.name == baseName) |
| 271 | { |
| 272 | const bool arrayElementZero = |
| 273 | (subscripts.empty() && (!block.isArray || block.arrayElement == 0)); |
| 274 | const bool arrayElementMatches = |
| 275 | (subscripts.size() == 1 && subscripts[0] == block.arrayElement); |
| 276 | if (arrayElementMatches || arrayElementZero) |
| 277 | { |
| 278 | return blockIndex; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | return GL_INVALID_INDEX; |
| 284 | } |
| 285 | |
| 286 | void GetInterfaceBlockName(const GLuint index, |
| 287 | const std::vector<InterfaceBlock> &list, |
| 288 | GLsizei bufSize, |
| 289 | GLsizei *length, |
| 290 | GLchar *name) |
| 291 | { |
| 292 | ASSERT(index < list.size()); |
| 293 | |
| 294 | const auto &block = list[index]; |
| 295 | |
| 296 | if (bufSize > 0) |
| 297 | { |
| 298 | std::string blockName = block.name; |
| 299 | |
| 300 | if (block.isArray) |
| 301 | { |
| 302 | blockName += ArrayString(block.arrayElement); |
| 303 | } |
| 304 | CopyStringToBuffer(name, blockName, bufSize, length); |
| 305 | } |
| 306 | } |
| 307 | |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 308 | void InitUniformBlockLinker(const gl::Context *context, |
| 309 | const ProgramState &state, |
| 310 | UniformBlockLinker *blockLinker) |
| 311 | { |
| 312 | if (state.getAttachedVertexShader()) |
| 313 | { |
| 314 | blockLinker->addShaderBlocks(GL_VERTEX_SHADER, |
| 315 | &state.getAttachedVertexShader()->getUniformBlocks(context)); |
| 316 | } |
| 317 | |
| 318 | if (state.getAttachedFragmentShader()) |
| 319 | { |
| 320 | blockLinker->addShaderBlocks(GL_FRAGMENT_SHADER, |
| 321 | &state.getAttachedFragmentShader()->getUniformBlocks(context)); |
| 322 | } |
| 323 | |
| 324 | if (state.getAttachedComputeShader()) |
| 325 | { |
| 326 | blockLinker->addShaderBlocks(GL_COMPUTE_SHADER, |
| 327 | &state.getAttachedComputeShader()->getUniformBlocks(context)); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | void InitShaderStorageBlockLinker(const gl::Context *context, |
| 332 | const ProgramState &state, |
| 333 | ShaderStorageBlockLinker *blockLinker) |
| 334 | { |
| 335 | if (state.getAttachedVertexShader()) |
| 336 | { |
| 337 | blockLinker->addShaderBlocks( |
| 338 | GL_VERTEX_SHADER, &state.getAttachedVertexShader()->getShaderStorageBlocks(context)); |
| 339 | } |
| 340 | |
| 341 | if (state.getAttachedFragmentShader()) |
| 342 | { |
| 343 | blockLinker->addShaderBlocks( |
| 344 | GL_FRAGMENT_SHADER, |
| 345 | &state.getAttachedFragmentShader()->getShaderStorageBlocks(context)); |
| 346 | } |
| 347 | |
| 348 | if (state.getAttachedComputeShader()) |
| 349 | { |
| 350 | blockLinker->addShaderBlocks( |
| 351 | GL_COMPUTE_SHADER, &state.getAttachedComputeShader()->getShaderStorageBlocks(context)); |
| 352 | } |
| 353 | } |
| 354 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 355 | } // anonymous namespace |
| 356 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 357 | const char *const g_fakepath = "C:\\fakepath"; |
| 358 | |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 359 | InfoLog::InfoLog() |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 360 | { |
| 361 | } |
| 362 | |
| 363 | InfoLog::~InfoLog() |
| 364 | { |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 367 | size_t InfoLog::getLength() const |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 368 | { |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 369 | if (!mLazyStream) |
| 370 | { |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | const std::string &logString = mLazyStream->str(); |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 375 | return logString.empty() ? 0 : logString.length() + 1; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 378 | void InfoLog::getLog(GLsizei bufSize, GLsizei *length, char *infoLog) const |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 379 | { |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 380 | size_t index = 0; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 381 | |
| 382 | if (bufSize > 0) |
| 383 | { |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 384 | const std::string logString(str()); |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 385 | |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 386 | if (!logString.empty()) |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 387 | { |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 388 | index = std::min(static_cast<size_t>(bufSize) - 1, logString.length()); |
| 389 | memcpy(infoLog, logString.c_str(), index); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | infoLog[index] = '\0'; |
| 393 | } |
| 394 | |
| 395 | if (length) |
| 396 | { |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 397 | *length = static_cast<GLsizei>(index); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
| 401 | // append a santized message to the program info log. |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 402 | // The D3D compiler includes a fake file path in some of the warning or error |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 403 | // messages, so lets remove all occurrences of this fake file path from the log. |
| 404 | void InfoLog::appendSanitized(const char *message) |
| 405 | { |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 406 | ensureInitialized(); |
| 407 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 408 | std::string msg(message); |
| 409 | |
| 410 | size_t found; |
| 411 | do |
| 412 | { |
| 413 | found = msg.find(g_fakepath); |
| 414 | if (found != std::string::npos) |
| 415 | { |
| 416 | msg.erase(found, strlen(g_fakepath)); |
| 417 | } |
| 418 | } |
| 419 | while (found != std::string::npos); |
| 420 | |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 421 | *mLazyStream << message << std::endl; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 422 | } |
| 423 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 424 | void InfoLog::reset() |
| 425 | { |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 428 | VariableLocation::VariableLocation() : arrayIndex(0), index(kUnused), ignored(false) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 429 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 430 | } |
| 431 | |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 432 | VariableLocation::VariableLocation(unsigned int arrayIndex, unsigned int index) |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 433 | : arrayIndex(arrayIndex), index(index), ignored(false) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 434 | { |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 435 | ASSERT(arrayIndex != GL_INVALID_INDEX); |
| 436 | } |
| 437 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 438 | void Program::Bindings::bindLocation(GLuint index, const std::string &name) |
| 439 | { |
| 440 | mBindings[name] = index; |
| 441 | } |
| 442 | |
| 443 | int Program::Bindings::getBinding(const std::string &name) const |
| 444 | { |
| 445 | auto iter = mBindings.find(name); |
| 446 | return (iter != mBindings.end()) ? iter->second : -1; |
| 447 | } |
| 448 | |
| 449 | Program::Bindings::const_iterator Program::Bindings::begin() const |
| 450 | { |
| 451 | return mBindings.begin(); |
| 452 | } |
| 453 | |
| 454 | Program::Bindings::const_iterator Program::Bindings::end() const |
| 455 | { |
| 456 | return mBindings.end(); |
| 457 | } |
| 458 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 459 | ProgramState::ProgramState() |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 460 | : mLabel(), |
| 461 | mAttachedFragmentShader(nullptr), |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 462 | mAttachedVertexShader(nullptr), |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 463 | mAttachedComputeShader(nullptr), |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 464 | mTransformFeedbackBufferMode(GL_INTERLEAVED_ATTRIBS), |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 465 | mMaxActiveAttribLocation(0), |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 466 | mSamplerUniformRange(0, 0), |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 467 | mImageUniformRange(0, 0), |
| 468 | mAtomicCounterUniformRange(0, 0), |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 469 | mBinaryRetrieveableHint(false), |
| 470 | mNumViews(-1) |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 471 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 472 | mComputeShaderLocalSize.fill(1); |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 473 | } |
| 474 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 475 | ProgramState::~ProgramState() |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 476 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 477 | ASSERT(!mAttachedVertexShader && !mAttachedFragmentShader && !mAttachedComputeShader); |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 478 | } |
| 479 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 480 | const std::string &ProgramState::getLabel() |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 481 | { |
| 482 | return mLabel; |
| 483 | } |
| 484 | |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 485 | GLuint ProgramState::getUniformIndexFromName(const std::string &name) const |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 486 | { |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 487 | return GetResourceIndexFromName(mUniforms, name); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 488 | } |
| 489 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 490 | GLuint ProgramState::getBufferVariableIndexFromName(const std::string &name) const |
| 491 | { |
| 492 | return GetResourceIndexFromName(mBufferVariables, name); |
| 493 | } |
| 494 | |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 495 | GLuint ProgramState::getUniformIndexFromLocation(GLint location) const |
| 496 | { |
| 497 | ASSERT(location >= 0 && static_cast<size_t>(location) < mUniformLocations.size()); |
| 498 | return mUniformLocations[location].index; |
| 499 | } |
| 500 | |
| 501 | Optional<GLuint> ProgramState::getSamplerIndex(GLint location) const |
| 502 | { |
| 503 | GLuint index = getUniformIndexFromLocation(location); |
| 504 | if (!isSamplerUniformIndex(index)) |
| 505 | { |
| 506 | return Optional<GLuint>::Invalid(); |
| 507 | } |
| 508 | |
| 509 | return getSamplerIndexFromUniformIndex(index); |
| 510 | } |
| 511 | |
| 512 | bool ProgramState::isSamplerUniformIndex(GLuint index) const |
| 513 | { |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 514 | return mSamplerUniformRange.contains(index); |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | GLuint ProgramState::getSamplerIndexFromUniformIndex(GLuint uniformIndex) const |
| 518 | { |
| 519 | ASSERT(isSamplerUniformIndex(uniformIndex)); |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 520 | return uniformIndex - mSamplerUniformRange.low(); |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 521 | } |
| 522 | |
Jamie Madill | 34ca4f5 | 2017-06-13 11:49:39 -0400 | [diff] [blame] | 523 | GLuint ProgramState::getAttributeLocation(const std::string &name) const |
| 524 | { |
| 525 | for (const sh::Attribute &attribute : mAttributes) |
| 526 | { |
| 527 | if (attribute.name == name) |
| 528 | { |
| 529 | return attribute.location; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | return static_cast<GLuint>(-1); |
| 534 | } |
| 535 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 536 | Program::Program(rx::GLImplFactory *factory, ShaderProgramManager *manager, GLuint handle) |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 537 | : mProgram(factory->createProgram(mState)), |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 538 | mValidated(false), |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 539 | mLinked(false), |
| 540 | mDeleteStatus(false), |
| 541 | mRefCount(0), |
| 542 | mResourceManager(manager), |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 543 | mHandle(handle) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 544 | { |
| 545 | ASSERT(mProgram); |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 546 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 547 | unlink(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | Program::~Program() |
| 551 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 552 | ASSERT(!mProgram); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 555 | void Program::onDestroy(const Context *context) |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 556 | { |
| 557 | if (mState.mAttachedVertexShader != nullptr) |
| 558 | { |
| 559 | mState.mAttachedVertexShader->release(context); |
| 560 | mState.mAttachedVertexShader = nullptr; |
| 561 | } |
| 562 | |
| 563 | if (mState.mAttachedFragmentShader != nullptr) |
| 564 | { |
| 565 | mState.mAttachedFragmentShader->release(context); |
| 566 | mState.mAttachedFragmentShader = nullptr; |
| 567 | } |
| 568 | |
| 569 | if (mState.mAttachedComputeShader != nullptr) |
| 570 | { |
| 571 | mState.mAttachedComputeShader->release(context); |
| 572 | mState.mAttachedComputeShader = nullptr; |
| 573 | } |
| 574 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 575 | mProgram->destroy(context); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 576 | |
| 577 | ASSERT(!mState.mAttachedVertexShader && !mState.mAttachedFragmentShader && |
| 578 | !mState.mAttachedComputeShader); |
| 579 | SafeDelete(mProgram); |
| 580 | |
| 581 | delete this; |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 582 | } |
| 583 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 584 | void Program::setLabel(const std::string &label) |
| 585 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 586 | mState.mLabel = label; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | const std::string &Program::getLabel() const |
| 590 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 591 | return mState.mLabel; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 592 | } |
| 593 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 594 | void Program::attachShader(Shader *shader) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 595 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 596 | switch (shader->getType()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 597 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 598 | case GL_VERTEX_SHADER: |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 599 | { |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 600 | ASSERT(!mState.mAttachedVertexShader); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 601 | mState.mAttachedVertexShader = shader; |
| 602 | mState.mAttachedVertexShader->addRef(); |
| 603 | break; |
| 604 | } |
| 605 | case GL_FRAGMENT_SHADER: |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 606 | { |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 607 | ASSERT(!mState.mAttachedFragmentShader); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 608 | mState.mAttachedFragmentShader = shader; |
| 609 | mState.mAttachedFragmentShader->addRef(); |
| 610 | break; |
| 611 | } |
| 612 | case GL_COMPUTE_SHADER: |
| 613 | { |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 614 | ASSERT(!mState.mAttachedComputeShader); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 615 | mState.mAttachedComputeShader = shader; |
| 616 | mState.mAttachedComputeShader->addRef(); |
| 617 | break; |
| 618 | } |
| 619 | default: |
| 620 | UNREACHABLE(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 621 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 624 | void Program::detachShader(const Context *context, Shader *shader) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 625 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 626 | switch (shader->getType()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 627 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 628 | case GL_VERTEX_SHADER: |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 629 | { |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 630 | ASSERT(mState.mAttachedVertexShader == shader); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 631 | shader->release(context); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 632 | mState.mAttachedVertexShader = nullptr; |
| 633 | break; |
| 634 | } |
| 635 | case GL_FRAGMENT_SHADER: |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 636 | { |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 637 | ASSERT(mState.mAttachedFragmentShader == shader); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 638 | shader->release(context); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 639 | mState.mAttachedFragmentShader = nullptr; |
| 640 | break; |
| 641 | } |
| 642 | case GL_COMPUTE_SHADER: |
| 643 | { |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 644 | ASSERT(mState.mAttachedComputeShader == shader); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 645 | shader->release(context); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 646 | mState.mAttachedComputeShader = nullptr; |
| 647 | break; |
| 648 | } |
| 649 | default: |
| 650 | UNREACHABLE(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 651 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 652 | } |
| 653 | |
daniel@transgaming.com | cba5057 | 2010-03-28 19:36:09 +0000 | [diff] [blame] | 654 | int Program::getAttachedShadersCount() const |
| 655 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 656 | return (mState.mAttachedVertexShader ? 1 : 0) + (mState.mAttachedFragmentShader ? 1 : 0) + |
| 657 | (mState.mAttachedComputeShader ? 1 : 0); |
daniel@transgaming.com | cba5057 | 2010-03-28 19:36:09 +0000 | [diff] [blame] | 658 | } |
| 659 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 660 | void Program::bindAttributeLocation(GLuint index, const char *name) |
| 661 | { |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 662 | mAttributeBindings.bindLocation(index, name); |
| 663 | } |
| 664 | |
| 665 | void Program::bindUniformLocation(GLuint index, const char *name) |
| 666 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 667 | mUniformLocationBindings.bindLocation(index, name); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 670 | void Program::bindFragmentInputLocation(GLint index, const char *name) |
| 671 | { |
| 672 | mFragmentInputBindings.bindLocation(index, name); |
| 673 | } |
| 674 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 675 | BindingInfo Program::getFragmentInputBindingInfo(const Context *context, GLint index) const |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 676 | { |
| 677 | BindingInfo ret; |
| 678 | ret.type = GL_NONE; |
| 679 | ret.valid = false; |
| 680 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 681 | Shader *fragmentShader = mState.getAttachedFragmentShader(); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 682 | ASSERT(fragmentShader); |
| 683 | |
| 684 | // Find the actual fragment shader varying we're interested in |
Jiawei Shao | 3d40488 | 2017-10-16 13:30:48 +0800 | [diff] [blame] | 685 | const std::vector<sh::Varying> &inputs = fragmentShader->getInputVaryings(context); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 686 | |
| 687 | for (const auto &binding : mFragmentInputBindings) |
| 688 | { |
| 689 | if (binding.second != static_cast<GLuint>(index)) |
| 690 | continue; |
| 691 | |
| 692 | ret.valid = true; |
| 693 | |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 694 | size_t nameLengthWithoutArrayIndex; |
| 695 | unsigned int arrayIndex = ParseArrayIndex(binding.first, &nameLengthWithoutArrayIndex); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 696 | |
| 697 | for (const auto &in : inputs) |
| 698 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 699 | if (in.name.length() == nameLengthWithoutArrayIndex && |
| 700 | angle::BeginsWith(in.name, binding.first, nameLengthWithoutArrayIndex)) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 701 | { |
| 702 | if (in.isArray()) |
| 703 | { |
| 704 | // The client wants to bind either "name" or "name[0]". |
| 705 | // GL ES 3.1 spec refers to active array names with language such as: |
| 706 | // "if the string identifies the base name of an active array, where the |
| 707 | // string would exactly match the name of the variable if the suffix "[0]" |
| 708 | // were appended to the string". |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 709 | if (arrayIndex == GL_INVALID_INDEX) |
| 710 | arrayIndex = 0; |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 711 | |
Corentin Wallez | 054f7ed | 2016-09-20 17:15:59 -0400 | [diff] [blame] | 712 | ret.name = in.mappedName + "[" + ToString(arrayIndex) + "]"; |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 713 | } |
| 714 | else |
| 715 | { |
| 716 | ret.name = in.mappedName; |
| 717 | } |
| 718 | ret.type = in.type; |
| 719 | return ret; |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | return ret; |
| 725 | } |
| 726 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 727 | void Program::pathFragmentInputGen(const Context *context, |
| 728 | GLint index, |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 729 | GLenum genMode, |
| 730 | GLint components, |
| 731 | const GLfloat *coeffs) |
| 732 | { |
| 733 | // If the location is -1 then the command is silently ignored |
| 734 | if (index == -1) |
| 735 | return; |
| 736 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 737 | const auto &binding = getFragmentInputBindingInfo(context, index); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 738 | |
| 739 | // If the input doesn't exist then then the command is silently ignored |
| 740 | // This could happen through optimization for example, the shader translator |
| 741 | // decides that a variable is not actually being used and optimizes it away. |
| 742 | if (binding.name.empty()) |
| 743 | return; |
| 744 | |
| 745 | mProgram->setPathFragmentInputGen(binding.name, genMode, components, coeffs); |
| 746 | } |
| 747 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 748 | // The attached shaders are checked for linking errors by matching up their variables. |
| 749 | // Uniform, input and output variables get collected. |
| 750 | // The code gets compiled into binaries. |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 751 | Error Program::link(const gl::Context *context) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 752 | { |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 753 | const auto &data = context->getContextState(); |
| 754 | |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 755 | auto *platform = ANGLEPlatformCurrent(); |
| 756 | double startTime = platform->currentTime(platform); |
| 757 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 758 | unlink(); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 759 | |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 760 | ProgramHash programHash; |
| 761 | auto *cache = context->getMemoryProgramCache(); |
| 762 | if (cache) |
| 763 | { |
| 764 | ANGLE_TRY_RESULT(cache->getProgram(context, this, &mState, &programHash), mLinked); |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 765 | ANGLE_HISTOGRAM_BOOLEAN("GPU.ANGLE.ProgramCache.LoadBinarySuccess", mLinked); |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | if (mLinked) |
| 769 | { |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 770 | double delta = platform->currentTime(platform) - startTime; |
| 771 | int us = static_cast<int>(delta * 1000000.0); |
| 772 | ANGLE_HISTOGRAM_COUNTS("GPU.ANGLE.ProgramCache.ProgramCacheHitTimeUS", us); |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 773 | return NoError(); |
| 774 | } |
| 775 | |
| 776 | // Cache load failed, fall through to normal linking. |
| 777 | unlink(); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 778 | mInfoLog.reset(); |
| 779 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 780 | const Caps &caps = data.getCaps(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 781 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 782 | auto vertexShader = mState.mAttachedVertexShader; |
| 783 | auto fragmentShader = mState.mAttachedFragmentShader; |
| 784 | auto computeShader = mState.mAttachedComputeShader; |
| 785 | |
| 786 | bool isComputeShaderAttached = (computeShader != nullptr); |
| 787 | bool nonComputeShadersAttached = (vertexShader != nullptr || fragmentShader != nullptr); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 788 | // Check whether we both have a compute and non-compute shaders attached. |
| 789 | // If there are of both types attached, then linking should fail. |
| 790 | // OpenGL ES 3.10, 7.3 Program Objects, under LinkProgram |
| 791 | if (isComputeShaderAttached == true && nonComputeShadersAttached == true) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 792 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 793 | mInfoLog << "Both a compute and non-compute shaders are attached to the same program."; |
| 794 | return NoError(); |
Yuly Novikov | cfa48d3 | 2016-06-15 22:14:36 -0400 | [diff] [blame] | 795 | } |
| 796 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 797 | if (computeShader) |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 798 | { |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 799 | if (!computeShader->isCompiled(context)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 800 | { |
| 801 | mInfoLog << "Attached compute shader is not compiled."; |
| 802 | return NoError(); |
| 803 | } |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 804 | ASSERT(computeShader->getType() == GL_COMPUTE_SHADER); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 805 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 806 | mState.mComputeShaderLocalSize = computeShader->getWorkGroupSize(context); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 807 | |
| 808 | // GLSL ES 3.10, 4.4.1.1 Compute Shader Inputs |
| 809 | // If the work group size is not specified, a link time error should occur. |
| 810 | if (!mState.mComputeShaderLocalSize.isDeclared()) |
| 811 | { |
| 812 | mInfoLog << "Work group size is not specified."; |
| 813 | return NoError(); |
| 814 | } |
| 815 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 816 | if (!linkUniforms(context, mInfoLog, mUniformLocationBindings)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 817 | { |
| 818 | return NoError(); |
| 819 | } |
| 820 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 821 | if (!linkInterfaceBlocks(context, mInfoLog)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 822 | { |
| 823 | return NoError(); |
| 824 | } |
| 825 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 826 | ProgramLinkedResources resources = { |
| 827 | {0, PackMode::ANGLE_RELAXED}, |
| 828 | {&mState.mUniformBlocks, &mState.mUniforms}, |
| 829 | {&mState.mShaderStorageBlocks, &mState.mBufferVariables}}; |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 830 | |
| 831 | InitUniformBlockLinker(context, mState, &resources.uniformBlockLinker); |
| 832 | InitShaderStorageBlockLinker(context, mState, &resources.shaderStorageBlockLinker); |
| 833 | |
| 834 | ANGLE_TRY_RESULT(mProgram->link(context, resources, mInfoLog), mLinked); |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 835 | if (!mLinked) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 836 | { |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 837 | return NoError(); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | else |
| 841 | { |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 842 | if (!fragmentShader || !fragmentShader->isCompiled(context)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 843 | { |
| 844 | return NoError(); |
| 845 | } |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 846 | ASSERT(fragmentShader->getType() == GL_FRAGMENT_SHADER); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 847 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 848 | if (!vertexShader || !vertexShader->isCompiled(context)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 849 | { |
| 850 | return NoError(); |
| 851 | } |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 852 | ASSERT(vertexShader->getType() == GL_VERTEX_SHADER); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 853 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 854 | if (fragmentShader->getShaderVersion(context) != vertexShader->getShaderVersion(context)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 855 | { |
| 856 | mInfoLog << "Fragment shader version does not match vertex shader version."; |
| 857 | return NoError(); |
| 858 | } |
| 859 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 860 | if (!linkAttributes(context, mInfoLog)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 861 | { |
| 862 | return NoError(); |
| 863 | } |
| 864 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 865 | if (!linkVaryings(context, mInfoLog)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 866 | { |
| 867 | return NoError(); |
| 868 | } |
| 869 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 870 | if (!linkUniforms(context, mInfoLog, mUniformLocationBindings)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 871 | { |
| 872 | return NoError(); |
| 873 | } |
| 874 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 875 | if (!linkInterfaceBlocks(context, mInfoLog)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 876 | { |
| 877 | return NoError(); |
| 878 | } |
| 879 | |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 880 | if (!linkValidateGlobalNames(context, mInfoLog)) |
| 881 | { |
| 882 | return NoError(); |
| 883 | } |
| 884 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 885 | const auto &mergedVaryings = getMergedVaryings(context); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 886 | |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 887 | mState.mNumViews = vertexShader->getNumViews(context); |
| 888 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 889 | linkOutputVariables(context); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 890 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 891 | // Validate we can pack the varyings. |
| 892 | std::vector<PackedVarying> packedVaryings = getPackedVaryings(mergedVaryings); |
| 893 | |
| 894 | // Map the varyings to the register file |
| 895 | // In WebGL, we use a slightly different handling for packing variables. |
| 896 | auto packMode = data.getExtensions().webglCompatibility ? PackMode::WEBGL_STRICT |
| 897 | : PackMode::ANGLE_RELAXED; |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 898 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 899 | ProgramLinkedResources resources = { |
| 900 | {data.getCaps().maxVaryingVectors, packMode}, |
| 901 | {&mState.mUniformBlocks, &mState.mUniforms}, |
| 902 | {&mState.mShaderStorageBlocks, &mState.mBufferVariables}}; |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 903 | |
| 904 | InitUniformBlockLinker(context, mState, &resources.uniformBlockLinker); |
| 905 | InitShaderStorageBlockLinker(context, mState, &resources.shaderStorageBlockLinker); |
| 906 | |
| 907 | if (!resources.varyingPacking.packUserVaryings(mInfoLog, packedVaryings, |
| 908 | mState.getTransformFeedbackVaryingNames())) |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 909 | { |
| 910 | return NoError(); |
| 911 | } |
| 912 | |
Olli Etuaho | 39e7812 | 2017-08-29 14:34:22 +0300 | [diff] [blame] | 913 | if (!linkValidateTransformFeedback(context, mInfoLog, mergedVaryings, caps)) |
| 914 | { |
| 915 | return NoError(); |
| 916 | } |
| 917 | |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 918 | ANGLE_TRY_RESULT(mProgram->link(context, resources, mInfoLog), mLinked); |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 919 | if (!mLinked) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 920 | { |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 921 | return NoError(); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | gatherTransformFeedbackVaryings(mergedVaryings); |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 925 | } |
| 926 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 927 | gatherAtomicCounterBuffers(); |
Jamie Madill | 6db1c2e | 2017-11-08 09:17:40 -0500 | [diff] [blame] | 928 | initInterfaceBlockBindings(); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 929 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 930 | setUniformValuesFromBindingQualifiers(); |
| 931 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 932 | // Mark implementation-specific unreferenced uniforms as ignored. |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 933 | mProgram->markUnusedUniformLocations(&mState.mUniformLocations, &mState.mSamplerBindings); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 934 | |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 935 | // Save to the program cache. |
| 936 | if (cache && (mState.mLinkedTransformFeedbackVaryings.empty() || |
| 937 | !context->getWorkarounds().disableProgramCachingForTransformFeedback)) |
| 938 | { |
| 939 | cache->putProgram(programHash, context, this); |
| 940 | } |
| 941 | |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 942 | double delta = platform->currentTime(platform) - startTime; |
| 943 | int us = static_cast<int>(delta * 1000000.0); |
| 944 | ANGLE_HISTOGRAM_COUNTS("GPU.ANGLE.ProgramCache.ProgramCacheMissTimeUS", us); |
| 945 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 946 | return NoError(); |
apatrick@chromium.org | 9a30b09 | 2012-06-06 20:21:55 +0000 | [diff] [blame] | 947 | } |
| 948 | |
daniel@transgaming.com | aa5e59b | 2011-10-04 18:43:12 +0000 | [diff] [blame] | 949 | // Returns the program object to an unlinked state, before re-linking, or at destruction |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 950 | void Program::unlink() |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 951 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 952 | mState.mAttributes.clear(); |
| 953 | mState.mActiveAttribLocationsMask.reset(); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 954 | mState.mMaxActiveAttribLocation = 0; |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 955 | mState.mLinkedTransformFeedbackVaryings.clear(); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 956 | mState.mUniforms.clear(); |
| 957 | mState.mUniformLocations.clear(); |
| 958 | mState.mUniformBlocks.clear(); |
jchen10 | 7a20b97 | 2017-06-13 14:25:26 +0800 | [diff] [blame] | 959 | mState.mActiveUniformBlockBindings.reset(); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 960 | mState.mAtomicCounterBuffers.clear(); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 961 | mState.mOutputVariables.clear(); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 962 | mState.mOutputLocations.clear(); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 963 | mState.mOutputVariableTypes.clear(); |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 964 | mState.mActiveOutputVariables.reset(); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 965 | mState.mComputeShaderLocalSize.fill(1); |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 966 | mState.mSamplerBindings.clear(); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 967 | mState.mImageBindings.clear(); |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 968 | mState.mNumViews = -1; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 969 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 970 | mValidated = false; |
| 971 | |
daniel@transgaming.com | 716056c | 2012-07-24 18:38:59 +0000 | [diff] [blame] | 972 | mLinked = false; |
| 973 | } |
| 974 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 975 | bool Program::isLinked() const |
daniel@transgaming.com | 716056c | 2012-07-24 18:38:59 +0000 | [diff] [blame] | 976 | { |
| 977 | return mLinked; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 978 | } |
| 979 | |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 980 | Error Program::loadBinary(const Context *context, |
| 981 | GLenum binaryFormat, |
| 982 | const void *binary, |
| 983 | GLsizei length) |
apatrick@chromium.org | 3ce8dbc | 2012-06-08 17:52:30 +0000 | [diff] [blame] | 984 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 985 | unlink(); |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 986 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 987 | #if ANGLE_PROGRAM_BINARY_LOAD != ANGLE_ENABLED |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 988 | return NoError(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 989 | #else |
Geoff Lang | c46cc2f | 2015-10-01 17:16:20 -0400 | [diff] [blame] | 990 | ASSERT(binaryFormat == GL_PROGRAM_BINARY_ANGLE); |
| 991 | if (binaryFormat != GL_PROGRAM_BINARY_ANGLE) |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 992 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 993 | mInfoLog << "Invalid program binary format."; |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 994 | return NoError(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 995 | } |
| 996 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 997 | const uint8_t *bytes = reinterpret_cast<const uint8_t *>(binary); |
| 998 | ANGLE_TRY_RESULT( |
| 999 | MemoryProgramCache::Deserialize(context, this, &mState, bytes, length, mInfoLog), mLinked); |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 1000 | |
| 1001 | // Currently we require the full shader text to compute the program hash. |
| 1002 | // TODO(jmadill): Store the binary in the internal program cache. |
| 1003 | |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 1004 | return NoError(); |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 1005 | #endif // #if ANGLE_PROGRAM_BINARY_LOAD == ANGLE_ENABLED |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1006 | } |
| 1007 | |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 1008 | Error Program::saveBinary(const Context *context, |
| 1009 | GLenum *binaryFormat, |
| 1010 | void *binary, |
| 1011 | GLsizei bufSize, |
| 1012 | GLsizei *length) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1013 | { |
| 1014 | if (binaryFormat) |
| 1015 | { |
Geoff Lang | c46cc2f | 2015-10-01 17:16:20 -0400 | [diff] [blame] | 1016 | *binaryFormat = GL_PROGRAM_BINARY_ANGLE; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1017 | } |
| 1018 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 1019 | angle::MemoryBuffer memoryBuf; |
| 1020 | MemoryProgramCache::Serialize(context, this, &memoryBuf); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1021 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 1022 | GLsizei streamLength = static_cast<GLsizei>(memoryBuf.size()); |
| 1023 | const uint8_t *streamState = memoryBuf.data(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1024 | |
| 1025 | if (streamLength > bufSize) |
| 1026 | { |
| 1027 | if (length) |
| 1028 | { |
| 1029 | *length = 0; |
| 1030 | } |
| 1031 | |
| 1032 | // TODO: This should be moved to the validation layer but computing the size of the binary before saving |
| 1033 | // it causes the save to happen twice. It may be possible to write the binary to a separate buffer, validate |
| 1034 | // sizes and then copy it. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1035 | return InternalError(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | if (binary) |
| 1039 | { |
| 1040 | char *ptr = reinterpret_cast<char*>(binary); |
| 1041 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1042 | memcpy(ptr, streamState, streamLength); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1043 | ptr += streamLength; |
| 1044 | |
| 1045 | ASSERT(ptr - streamLength == binary); |
| 1046 | } |
| 1047 | |
| 1048 | if (length) |
| 1049 | { |
| 1050 | *length = streamLength; |
| 1051 | } |
| 1052 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 1053 | return NoError(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1054 | } |
| 1055 | |
Jamie Madill | ffe00c0 | 2017-06-27 16:26:55 -0400 | [diff] [blame] | 1056 | GLint Program::getBinaryLength(const Context *context) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1057 | { |
| 1058 | GLint length; |
Jamie Madill | ffe00c0 | 2017-06-27 16:26:55 -0400 | [diff] [blame] | 1059 | Error error = saveBinary(context, nullptr, nullptr, std::numeric_limits<GLint>::max(), &length); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1060 | if (error.isError()) |
| 1061 | { |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
| 1065 | return length; |
apatrick@chromium.org | 3ce8dbc | 2012-06-08 17:52:30 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1068 | void Program::setBinaryRetrievableHint(bool retrievable) |
| 1069 | { |
| 1070 | // TODO(jmadill) : replace with dirty bits |
| 1071 | mProgram->setBinaryRetrievableHint(retrievable); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1072 | mState.mBinaryRetrieveableHint = retrievable; |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | bool Program::getBinaryRetrievableHint() const |
| 1076 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1077 | return mState.mBinaryRetrieveableHint; |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1078 | } |
| 1079 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1080 | void Program::setSeparable(bool separable) |
| 1081 | { |
| 1082 | // TODO(yunchao) : replace with dirty bits |
| 1083 | if (mState.mSeparable != separable) |
| 1084 | { |
| 1085 | mProgram->setSeparable(separable); |
| 1086 | mState.mSeparable = separable; |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | bool Program::isSeparable() const |
| 1091 | { |
| 1092 | return mState.mSeparable; |
| 1093 | } |
| 1094 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1095 | void Program::release(const Context *context) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1096 | { |
| 1097 | mRefCount--; |
| 1098 | |
| 1099 | if (mRefCount == 0 && mDeleteStatus) |
| 1100 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1101 | mResourceManager->deleteProgram(context, mHandle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | void Program::addRef() |
| 1106 | { |
| 1107 | mRefCount++; |
| 1108 | } |
| 1109 | |
| 1110 | unsigned int Program::getRefCount() const |
| 1111 | { |
| 1112 | return mRefCount; |
| 1113 | } |
| 1114 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1115 | int Program::getInfoLogLength() const |
| 1116 | { |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 1117 | return static_cast<int>(mInfoLog.getLength()); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1120 | void Program::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1121 | { |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 1122 | return mInfoLog.getLog(bufSize, length, infoLog); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1125 | void Program::getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders) const |
daniel@transgaming.com | 6c78521 | 2010-03-30 03:36:17 +0000 | [diff] [blame] | 1126 | { |
| 1127 | int total = 0; |
| 1128 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1129 | if (mState.mAttachedComputeShader) |
| 1130 | { |
| 1131 | if (total < maxCount) |
| 1132 | { |
| 1133 | shaders[total] = mState.mAttachedComputeShader->getHandle(); |
| 1134 | total++; |
| 1135 | } |
| 1136 | } |
| 1137 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1138 | if (mState.mAttachedVertexShader) |
daniel@transgaming.com | 6c78521 | 2010-03-30 03:36:17 +0000 | [diff] [blame] | 1139 | { |
| 1140 | if (total < maxCount) |
| 1141 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1142 | shaders[total] = mState.mAttachedVertexShader->getHandle(); |
Olli Etuaho | 586bc55 | 2016-03-04 11:46:03 +0200 | [diff] [blame] | 1143 | total++; |
daniel@transgaming.com | 6c78521 | 2010-03-30 03:36:17 +0000 | [diff] [blame] | 1144 | } |
daniel@transgaming.com | 6c78521 | 2010-03-30 03:36:17 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1147 | if (mState.mAttachedFragmentShader) |
daniel@transgaming.com | 6c78521 | 2010-03-30 03:36:17 +0000 | [diff] [blame] | 1148 | { |
| 1149 | if (total < maxCount) |
| 1150 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1151 | shaders[total] = mState.mAttachedFragmentShader->getHandle(); |
Olli Etuaho | 586bc55 | 2016-03-04 11:46:03 +0200 | [diff] [blame] | 1152 | total++; |
daniel@transgaming.com | 6c78521 | 2010-03-30 03:36:17 +0000 | [diff] [blame] | 1153 | } |
daniel@transgaming.com | 6c78521 | 2010-03-30 03:36:17 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | if (count) |
| 1157 | { |
| 1158 | *count = total; |
| 1159 | } |
| 1160 | } |
| 1161 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1162 | GLuint Program::getAttributeLocation(const std::string &name) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1163 | { |
Jamie Madill | 34ca4f5 | 2017-06-13 11:49:39 -0400 | [diff] [blame] | 1164 | return mState.getAttributeLocation(name); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1165 | } |
| 1166 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 1167 | bool Program::isAttribLocationActive(size_t attribLocation) const |
Jamie Madill | 56c6e3c | 2015-04-15 10:18:05 -0400 | [diff] [blame] | 1168 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1169 | ASSERT(attribLocation < mState.mActiveAttribLocationsMask.size()); |
| 1170 | return mState.mActiveAttribLocationsMask[attribLocation]; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1171 | } |
| 1172 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1173 | void Program::getActiveAttribute(GLuint index, |
| 1174 | GLsizei bufsize, |
| 1175 | GLsizei *length, |
| 1176 | GLint *size, |
| 1177 | GLenum *type, |
| 1178 | GLchar *name) const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1179 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1180 | if (!mLinked) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1181 | { |
| 1182 | if (bufsize > 0) |
| 1183 | { |
| 1184 | name[0] = '\0'; |
| 1185 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1186 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1187 | if (length) |
| 1188 | { |
| 1189 | *length = 0; |
| 1190 | } |
| 1191 | |
| 1192 | *type = GL_NONE; |
| 1193 | *size = 1; |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1194 | return; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1195 | } |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1196 | |
jchen10 | 36e120e | 2017-03-14 14:53:58 +0800 | [diff] [blame] | 1197 | ASSERT(index < mState.mAttributes.size()); |
| 1198 | const sh::Attribute &attrib = mState.mAttributes[index]; |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1199 | |
| 1200 | if (bufsize > 0) |
| 1201 | { |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1202 | CopyStringToBuffer(name, attrib.name, bufsize, length); |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | // Always a single 'type' instance |
| 1206 | *size = 1; |
| 1207 | *type = attrib.type; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1210 | GLint Program::getActiveAttributeCount() const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1211 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1212 | if (!mLinked) |
Jamie Madill | 2d77318 | 2015-08-18 10:27:28 -0400 | [diff] [blame] | 1213 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1214 | return 0; |
| 1215 | } |
| 1216 | |
jchen10 | 36e120e | 2017-03-14 14:53:58 +0800 | [diff] [blame] | 1217 | return static_cast<GLint>(mState.mAttributes.size()); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1220 | GLint Program::getActiveAttributeMaxLength() const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1221 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1222 | if (!mLinked) |
Jamie Madill | 2d77318 | 2015-08-18 10:27:28 -0400 | [diff] [blame] | 1223 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1224 | return 0; |
| 1225 | } |
| 1226 | |
| 1227 | size_t maxLength = 0; |
| 1228 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1229 | for (const sh::Attribute &attrib : mState.mAttributes) |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1230 | { |
jchen10 | 36e120e | 2017-03-14 14:53:58 +0800 | [diff] [blame] | 1231 | maxLength = std::max(attrib.name.length() + 1, maxLength); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1232 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1233 | |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1234 | return static_cast<GLint>(maxLength); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1235 | } |
| 1236 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1237 | GLuint Program::getInputResourceIndex(const GLchar *name) const |
| 1238 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 1239 | return GetResourceIndexFromName(mState.mAttributes, std::string(name)); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | GLuint Program::getOutputResourceIndex(const GLchar *name) const |
| 1243 | { |
| 1244 | return GetResourceIndexFromName(mState.mOutputVariables, std::string(name)); |
| 1245 | } |
| 1246 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1247 | size_t Program::getOutputResourceCount() const |
| 1248 | { |
| 1249 | return (mLinked ? mState.mOutputVariables.size() : 0); |
| 1250 | } |
| 1251 | |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 1252 | template <typename T> |
| 1253 | void Program::getResourceName(GLuint index, |
| 1254 | const std::vector<T> &resources, |
| 1255 | GLsizei bufSize, |
| 1256 | GLsizei *length, |
| 1257 | GLchar *name) const |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1258 | { |
| 1259 | if (length) |
| 1260 | { |
| 1261 | *length = 0; |
| 1262 | } |
| 1263 | |
| 1264 | if (!mLinked) |
| 1265 | { |
| 1266 | if (bufSize > 0) |
| 1267 | { |
| 1268 | name[0] = '\0'; |
| 1269 | } |
| 1270 | return; |
| 1271 | } |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 1272 | ASSERT(index < resources.size()); |
| 1273 | const auto &resource = resources[index]; |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1274 | |
| 1275 | if (bufSize > 0) |
| 1276 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 1277 | CopyStringToBuffer(name, resource.name, bufSize, length); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1278 | } |
| 1279 | } |
| 1280 | |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 1281 | void Program::getInputResourceName(GLuint index, |
| 1282 | GLsizei bufSize, |
| 1283 | GLsizei *length, |
| 1284 | GLchar *name) const |
| 1285 | { |
| 1286 | getResourceName(index, mState.mAttributes, bufSize, length, name); |
| 1287 | } |
| 1288 | |
| 1289 | void Program::getOutputResourceName(GLuint index, |
| 1290 | GLsizei bufSize, |
| 1291 | GLsizei *length, |
| 1292 | GLchar *name) const |
| 1293 | { |
| 1294 | getResourceName(index, mState.mOutputVariables, bufSize, length, name); |
| 1295 | } |
| 1296 | |
| 1297 | void Program::getUniformResourceName(GLuint index, |
| 1298 | GLsizei bufSize, |
| 1299 | GLsizei *length, |
| 1300 | GLchar *name) const |
| 1301 | { |
| 1302 | getResourceName(index, mState.mUniforms, bufSize, length, name); |
| 1303 | } |
| 1304 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 1305 | void Program::getBufferVariableResourceName(GLuint index, |
| 1306 | GLsizei bufSize, |
| 1307 | GLsizei *length, |
| 1308 | GLchar *name) const |
| 1309 | { |
| 1310 | getResourceName(index, mState.mBufferVariables, bufSize, length, name); |
| 1311 | } |
| 1312 | |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 1313 | const sh::Attribute &Program::getInputResource(GLuint index) const |
| 1314 | { |
| 1315 | ASSERT(index < mState.mAttributes.size()); |
| 1316 | return mState.mAttributes[index]; |
| 1317 | } |
| 1318 | |
| 1319 | const sh::OutputVariable &Program::getOutputResource(GLuint index) const |
| 1320 | { |
| 1321 | ASSERT(index < mState.mOutputVariables.size()); |
| 1322 | return mState.mOutputVariables[index]; |
| 1323 | } |
| 1324 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1325 | GLint Program::getFragDataLocation(const std::string &name) const |
| 1326 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 1327 | return GetVariableLocation(mState.mOutputVariables, mState.mOutputLocations, name); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1330 | void Program::getActiveUniform(GLuint index, |
| 1331 | GLsizei bufsize, |
| 1332 | GLsizei *length, |
| 1333 | GLint *size, |
| 1334 | GLenum *type, |
| 1335 | GLchar *name) const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1336 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1337 | if (mLinked) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1338 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1339 | // index must be smaller than getActiveUniformCount() |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1340 | ASSERT(index < mState.mUniforms.size()); |
| 1341 | const LinkedUniform &uniform = mState.mUniforms[index]; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1342 | |
| 1343 | if (bufsize > 0) |
| 1344 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1345 | std::string string = uniform.name; |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1346 | CopyStringToBuffer(name, string, bufsize, length); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1347 | } |
| 1348 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1349 | *size = uniform.elementCount(); |
| 1350 | *type = uniform.type; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1351 | } |
| 1352 | else |
| 1353 | { |
| 1354 | if (bufsize > 0) |
| 1355 | { |
| 1356 | name[0] = '\0'; |
| 1357 | } |
| 1358 | |
| 1359 | if (length) |
| 1360 | { |
| 1361 | *length = 0; |
| 1362 | } |
| 1363 | |
| 1364 | *size = 0; |
| 1365 | *type = GL_NONE; |
| 1366 | } |
| 1367 | } |
| 1368 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1369 | GLint Program::getActiveUniformCount() const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1370 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1371 | if (mLinked) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1372 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1373 | return static_cast<GLint>(mState.mUniforms.size()); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1374 | } |
| 1375 | else |
| 1376 | { |
| 1377 | return 0; |
| 1378 | } |
| 1379 | } |
| 1380 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 1381 | size_t Program::getActiveBufferVariableCount() const |
| 1382 | { |
| 1383 | return mLinked ? mState.mBufferVariables.size() : 0; |
| 1384 | } |
| 1385 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1386 | GLint Program::getActiveUniformMaxLength() const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1387 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1388 | size_t maxLength = 0; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1389 | |
| 1390 | if (mLinked) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1391 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1392 | for (const LinkedUniform &uniform : mState.mUniforms) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1393 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1394 | if (!uniform.name.empty()) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1395 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1396 | size_t length = uniform.name.length() + 1u; |
| 1397 | if (uniform.isArray()) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1398 | { |
| 1399 | length += 3; // Counting in "[0]". |
| 1400 | } |
| 1401 | maxLength = std::max(length, maxLength); |
| 1402 | } |
| 1403 | } |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1404 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1405 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1406 | return static_cast<GLint>(maxLength); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1407 | } |
| 1408 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1409 | bool Program::isValidUniformLocation(GLint location) const |
| 1410 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1411 | ASSERT(angle::IsValueInRangeForNumericType<GLint>(mState.mUniformLocations.size())); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1412 | return (location >= 0 && static_cast<size_t>(location) < mState.mUniformLocations.size() && |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 1413 | mState.mUniformLocations[static_cast<size_t>(location)].used()); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 1414 | } |
| 1415 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1416 | const LinkedUniform &Program::getUniformByLocation(GLint location) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1417 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1418 | ASSERT(location >= 0 && static_cast<size_t>(location) < mState.mUniformLocations.size()); |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 1419 | return mState.mUniforms[mState.getUniformIndexFromLocation(location)]; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1420 | } |
| 1421 | |
Jamie Madill | ac4e9c3 | 2017-01-13 14:07:12 -0500 | [diff] [blame] | 1422 | const VariableLocation &Program::getUniformLocation(GLint location) const |
| 1423 | { |
| 1424 | ASSERT(location >= 0 && static_cast<size_t>(location) < mState.mUniformLocations.size()); |
| 1425 | return mState.mUniformLocations[location]; |
| 1426 | } |
| 1427 | |
| 1428 | const std::vector<VariableLocation> &Program::getUniformLocations() const |
| 1429 | { |
| 1430 | return mState.mUniformLocations; |
| 1431 | } |
| 1432 | |
| 1433 | const LinkedUniform &Program::getUniformByIndex(GLuint index) const |
| 1434 | { |
| 1435 | ASSERT(index < static_cast<size_t>(mState.mUniforms.size())); |
| 1436 | return mState.mUniforms[index]; |
| 1437 | } |
| 1438 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 1439 | const BufferVariable &Program::getBufferVariableByIndex(GLuint index) const |
| 1440 | { |
| 1441 | ASSERT(index < static_cast<size_t>(mState.mBufferVariables.size())); |
| 1442 | return mState.mBufferVariables[index]; |
| 1443 | } |
| 1444 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1445 | GLint Program::getUniformLocation(const std::string &name) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1446 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 1447 | return GetVariableLocation(mState.mUniforms, mState.mUniformLocations, name); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1448 | } |
| 1449 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1450 | GLuint Program::getUniformIndex(const std::string &name) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1451 | { |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 1452 | return mState.getUniformIndexFromName(name); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | void Program::setUniform1fv(GLint location, GLsizei count, const GLfloat *v) |
| 1456 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1457 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1458 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 1, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1459 | mProgram->setUniform1fv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | void Program::setUniform2fv(GLint location, GLsizei count, const GLfloat *v) |
| 1463 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1464 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1465 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 2, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1466 | mProgram->setUniform2fv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | void Program::setUniform3fv(GLint location, GLsizei count, const GLfloat *v) |
| 1470 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1471 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1472 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 3, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1473 | mProgram->setUniform3fv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | void Program::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) |
| 1477 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1478 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1479 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 4, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1480 | mProgram->setUniform4fv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1481 | } |
| 1482 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1483 | Program::SetUniformResult Program::setUniform1iv(GLint location, GLsizei count, const GLint *v) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1484 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1485 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1486 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 1, v); |
| 1487 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1488 | mProgram->setUniform1iv(location, clampedCount, v); |
| 1489 | |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1490 | if (mState.isSamplerUniformIndex(locationInfo.index)) |
| 1491 | { |
| 1492 | updateSamplerUniform(locationInfo, clampedCount, v); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1493 | return SetUniformResult::SamplerChanged; |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1494 | } |
| 1495 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1496 | return SetUniformResult::NoSamplerChange; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | void Program::setUniform2iv(GLint location, GLsizei count, const GLint *v) |
| 1500 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1501 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1502 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 2, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1503 | mProgram->setUniform2iv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | void Program::setUniform3iv(GLint location, GLsizei count, const GLint *v) |
| 1507 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1508 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1509 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 3, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1510 | mProgram->setUniform3iv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | void Program::setUniform4iv(GLint location, GLsizei count, const GLint *v) |
| 1514 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1515 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1516 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 4, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1517 | mProgram->setUniform4iv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | void Program::setUniform1uiv(GLint location, GLsizei count, const GLuint *v) |
| 1521 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1522 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1523 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 1, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1524 | mProgram->setUniform1uiv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | void Program::setUniform2uiv(GLint location, GLsizei count, const GLuint *v) |
| 1528 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1529 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1530 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 2, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1531 | mProgram->setUniform2uiv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | void Program::setUniform3uiv(GLint location, GLsizei count, const GLuint *v) |
| 1535 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1536 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1537 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 3, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1538 | mProgram->setUniform3uiv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | void Program::setUniform4uiv(GLint location, GLsizei count, const GLuint *v) |
| 1542 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1543 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 1544 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 4, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1545 | mProgram->setUniform4uiv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | void Program::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) |
| 1549 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1550 | GLsizei clampedCount = clampMatrixUniformCount<2, 2>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1551 | mProgram->setUniformMatrix2fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | void Program::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) |
| 1555 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1556 | GLsizei clampedCount = clampMatrixUniformCount<3, 3>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1557 | mProgram->setUniformMatrix3fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | void Program::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) |
| 1561 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1562 | GLsizei clampedCount = clampMatrixUniformCount<4, 4>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1563 | mProgram->setUniformMatrix4fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | void Program::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) |
| 1567 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1568 | GLsizei clampedCount = clampMatrixUniformCount<2, 3>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1569 | mProgram->setUniformMatrix2x3fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | void Program::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) |
| 1573 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1574 | GLsizei clampedCount = clampMatrixUniformCount<2, 4>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1575 | mProgram->setUniformMatrix2x4fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | void Program::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) |
| 1579 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1580 | GLsizei clampedCount = clampMatrixUniformCount<3, 2>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1581 | mProgram->setUniformMatrix3x2fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | void Program::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) |
| 1585 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1586 | GLsizei clampedCount = clampMatrixUniformCount<3, 4>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1587 | mProgram->setUniformMatrix3x4fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | void Program::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) |
| 1591 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1592 | GLsizei clampedCount = clampMatrixUniformCount<4, 2>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1593 | mProgram->setUniformMatrix4x2fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | void Program::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) |
| 1597 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 1598 | GLsizei clampedCount = clampMatrixUniformCount<4, 3>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 1599 | mProgram->setUniformMatrix4x3fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1600 | } |
| 1601 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 1602 | void Program::getUniformfv(const Context *context, GLint location, GLfloat *v) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1603 | { |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 1604 | const auto &uniformLocation = mState.getUniformLocations()[location]; |
| 1605 | const auto &uniform = mState.getUniforms()[uniformLocation.index]; |
| 1606 | |
| 1607 | GLenum nativeType = gl::VariableComponentType(uniform.type); |
| 1608 | if (nativeType == GL_FLOAT) |
| 1609 | { |
| 1610 | mProgram->getUniformfv(context, location, v); |
| 1611 | } |
| 1612 | else |
| 1613 | { |
| 1614 | getUniformInternal(context, v, location, nativeType, |
| 1615 | gl::VariableComponentCount(uniform.type)); |
| 1616 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1617 | } |
| 1618 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 1619 | void Program::getUniformiv(const Context *context, GLint location, GLint *v) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1620 | { |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 1621 | const auto &uniformLocation = mState.getUniformLocations()[location]; |
| 1622 | const auto &uniform = mState.getUniforms()[uniformLocation.index]; |
| 1623 | |
| 1624 | GLenum nativeType = gl::VariableComponentType(uniform.type); |
| 1625 | if (nativeType == GL_INT || nativeType == GL_BOOL) |
| 1626 | { |
| 1627 | mProgram->getUniformiv(context, location, v); |
| 1628 | } |
| 1629 | else |
| 1630 | { |
| 1631 | getUniformInternal(context, v, location, nativeType, |
| 1632 | gl::VariableComponentCount(uniform.type)); |
| 1633 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1634 | } |
| 1635 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 1636 | void Program::getUniformuiv(const Context *context, GLint location, GLuint *v) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1637 | { |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 1638 | const auto &uniformLocation = mState.getUniformLocations()[location]; |
| 1639 | const auto &uniform = mState.getUniforms()[uniformLocation.index]; |
| 1640 | |
| 1641 | GLenum nativeType = gl::VariableComponentType(uniform.type); |
| 1642 | if (nativeType == GL_UNSIGNED_INT) |
| 1643 | { |
| 1644 | mProgram->getUniformuiv(context, location, v); |
| 1645 | } |
| 1646 | else |
| 1647 | { |
| 1648 | getUniformInternal(context, v, location, nativeType, |
| 1649 | gl::VariableComponentCount(uniform.type)); |
| 1650 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1651 | } |
| 1652 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1653 | void Program::flagForDeletion() |
| 1654 | { |
| 1655 | mDeleteStatus = true; |
| 1656 | } |
| 1657 | |
| 1658 | bool Program::isFlaggedForDeletion() const |
| 1659 | { |
| 1660 | return mDeleteStatus; |
| 1661 | } |
daniel@transgaming.com | 86a7a13 | 2010-04-29 03:32:32 +0000 | [diff] [blame] | 1662 | |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 1663 | void Program::validate(const Caps &caps) |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 1664 | { |
| 1665 | mInfoLog.reset(); |
| 1666 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1667 | if (mLinked) |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 1668 | { |
Jamie Madill | 36cfd6a | 2015-08-18 10:46:20 -0400 | [diff] [blame] | 1669 | mValidated = (mProgram->validate(caps, &mInfoLog) == GL_TRUE); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 1670 | } |
| 1671 | else |
| 1672 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 1673 | mInfoLog << "Program has not been successfully linked."; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 1674 | } |
| 1675 | } |
| 1676 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1677 | bool Program::validateSamplers(InfoLog *infoLog, const Caps &caps) |
| 1678 | { |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1679 | // Skip cache if we're using an infolog, so we get the full error. |
| 1680 | // Also skip the cache if the sample mapping has changed, or if we haven't ever validated. |
| 1681 | if (infoLog == nullptr && mCachedValidateSamplersResult.valid()) |
| 1682 | { |
| 1683 | return mCachedValidateSamplersResult.value(); |
| 1684 | } |
| 1685 | |
| 1686 | if (mTextureUnitTypesCache.empty()) |
| 1687 | { |
| 1688 | mTextureUnitTypesCache.resize(caps.maxCombinedTextureImageUnits, GL_NONE); |
| 1689 | } |
| 1690 | else |
| 1691 | { |
| 1692 | std::fill(mTextureUnitTypesCache.begin(), mTextureUnitTypesCache.end(), GL_NONE); |
| 1693 | } |
| 1694 | |
| 1695 | // if any two active samplers in a program are of different types, but refer to the same |
| 1696 | // texture image unit, and this is the current program, then ValidateProgram will fail, and |
| 1697 | // DrawArrays and DrawElements will issue the INVALID_OPERATION error. |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 1698 | for (const auto &samplerBinding : mState.mSamplerBindings) |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1699 | { |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 1700 | if (samplerBinding.unreferenced) |
| 1701 | continue; |
| 1702 | |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 1703 | GLenum textureType = samplerBinding.textureType; |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1704 | |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 1705 | for (GLuint textureUnit : samplerBinding.boundTextureUnits) |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1706 | { |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1707 | if (textureUnit >= caps.maxCombinedTextureImageUnits) |
| 1708 | { |
| 1709 | if (infoLog) |
| 1710 | { |
| 1711 | (*infoLog) << "Sampler uniform (" << textureUnit |
| 1712 | << ") exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (" |
| 1713 | << caps.maxCombinedTextureImageUnits << ")"; |
| 1714 | } |
| 1715 | |
| 1716 | mCachedValidateSamplersResult = false; |
| 1717 | return false; |
| 1718 | } |
| 1719 | |
| 1720 | if (mTextureUnitTypesCache[textureUnit] != GL_NONE) |
| 1721 | { |
| 1722 | if (textureType != mTextureUnitTypesCache[textureUnit]) |
| 1723 | { |
| 1724 | if (infoLog) |
| 1725 | { |
| 1726 | (*infoLog) << "Samplers of conflicting types refer to the same texture " |
| 1727 | "image unit (" |
| 1728 | << textureUnit << ")."; |
| 1729 | } |
| 1730 | |
| 1731 | mCachedValidateSamplersResult = false; |
| 1732 | return false; |
| 1733 | } |
| 1734 | } |
| 1735 | else |
| 1736 | { |
| 1737 | mTextureUnitTypesCache[textureUnit] = textureType; |
| 1738 | } |
| 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | mCachedValidateSamplersResult = true; |
| 1743 | return true; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1744 | } |
| 1745 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1746 | bool Program::isValidated() const |
| 1747 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1748 | return mValidated; |
| 1749 | } |
| 1750 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1751 | GLuint Program::getActiveUniformBlockCount() const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1752 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1753 | return static_cast<GLuint>(mState.mUniformBlocks.size()); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1754 | } |
| 1755 | |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 1756 | GLuint Program::getActiveAtomicCounterBufferCount() const |
| 1757 | { |
| 1758 | return static_cast<GLuint>(mState.mAtomicCounterBuffers.size()); |
| 1759 | } |
| 1760 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 1761 | GLuint Program::getActiveShaderStorageBlockCount() const |
| 1762 | { |
| 1763 | return static_cast<GLuint>(mState.mShaderStorageBlocks.size()); |
| 1764 | } |
| 1765 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 1766 | void Program::getActiveUniformBlockName(const GLuint blockIndex, |
| 1767 | GLsizei bufSize, |
| 1768 | GLsizei *length, |
| 1769 | GLchar *blockName) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1770 | { |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 1771 | GetInterfaceBlockName(blockIndex, mState.mUniformBlocks, bufSize, length, blockName); |
| 1772 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1773 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 1774 | void Program::getActiveShaderStorageBlockName(const GLuint blockIndex, |
| 1775 | GLsizei bufSize, |
| 1776 | GLsizei *length, |
| 1777 | GLchar *blockName) const |
| 1778 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1779 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 1780 | GetInterfaceBlockName(blockIndex, mState.mShaderStorageBlocks, bufSize, length, blockName); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1781 | } |
| 1782 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1783 | GLint Program::getActiveUniformBlockMaxLength() const |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 1784 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1785 | int maxLength = 0; |
| 1786 | |
| 1787 | if (mLinked) |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 1788 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1789 | unsigned int numUniformBlocks = static_cast<unsigned int>(mState.mUniformBlocks.size()); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1790 | for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < numUniformBlocks; uniformBlockIndex++) |
| 1791 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 1792 | const InterfaceBlock &uniformBlock = mState.mUniformBlocks[uniformBlockIndex]; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1793 | if (!uniformBlock.name.empty()) |
| 1794 | { |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 1795 | int length = static_cast<int>(uniformBlock.nameWithArrayIndex().length()); |
| 1796 | maxLength = std::max(length + 1, maxLength); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1797 | } |
| 1798 | } |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 1799 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1800 | |
| 1801 | return maxLength; |
| 1802 | } |
| 1803 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1804 | GLuint Program::getUniformBlockIndex(const std::string &name) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1805 | { |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 1806 | return GetInterfaceBlockIndex(mState.mUniformBlocks, name); |
| 1807 | } |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1808 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 1809 | GLuint Program::getShaderStorageBlockIndex(const std::string &name) const |
| 1810 | { |
| 1811 | return GetInterfaceBlockIndex(mState.mShaderStorageBlocks, name); |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 1814 | const InterfaceBlock &Program::getUniformBlockByIndex(GLuint index) const |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1815 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1816 | ASSERT(index < static_cast<GLuint>(mState.mUniformBlocks.size())); |
| 1817 | return mState.mUniformBlocks[index]; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1818 | } |
| 1819 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame^] | 1820 | const InterfaceBlock &Program::getShaderStorageBlockByIndex(GLuint index) const |
| 1821 | { |
| 1822 | ASSERT(index < static_cast<GLuint>(mState.mShaderStorageBlocks.size())); |
| 1823 | return mState.mShaderStorageBlocks[index]; |
| 1824 | } |
| 1825 | |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 1826 | void Program::bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding) |
| 1827 | { |
jchen10 | 7a20b97 | 2017-06-13 14:25:26 +0800 | [diff] [blame] | 1828 | mState.mUniformBlocks[uniformBlockIndex].binding = uniformBlockBinding; |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 1829 | mState.mActiveUniformBlockBindings.set(uniformBlockIndex, uniformBlockBinding != 0); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1830 | mProgram->setUniformBlockBinding(uniformBlockIndex, uniformBlockBinding); |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | GLuint Program::getUniformBlockBinding(GLuint uniformBlockIndex) const |
| 1834 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1835 | return mState.getUniformBlockBinding(uniformBlockIndex); |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 1838 | GLuint Program::getShaderStorageBlockBinding(GLuint shaderStorageBlockIndex) const |
| 1839 | { |
| 1840 | return mState.getShaderStorageBlockBinding(shaderStorageBlockIndex); |
| 1841 | } |
| 1842 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1843 | void Program::setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode) |
| 1844 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1845 | mState.mTransformFeedbackVaryingNames.resize(count); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1846 | for (GLsizei i = 0; i < count; i++) |
| 1847 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1848 | mState.mTransformFeedbackVaryingNames[i] = varyings[i]; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1849 | } |
| 1850 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1851 | mState.mTransformFeedbackBufferMode = bufferMode; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | void Program::getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const |
| 1855 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1856 | if (mLinked) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1857 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 1858 | ASSERT(index < mState.mLinkedTransformFeedbackVaryings.size()); |
| 1859 | const auto &var = mState.mLinkedTransformFeedbackVaryings[index]; |
| 1860 | std::string varName = var.nameWithArrayIndex(); |
| 1861 | GLsizei lastNameIdx = std::min(bufSize - 1, static_cast<GLsizei>(varName.length())); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1862 | if (length) |
| 1863 | { |
| 1864 | *length = lastNameIdx; |
| 1865 | } |
| 1866 | if (size) |
| 1867 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 1868 | *size = var.size(); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1869 | } |
| 1870 | if (type) |
| 1871 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 1872 | *type = var.type; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1873 | } |
| 1874 | if (name) |
| 1875 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 1876 | memcpy(name, varName.c_str(), lastNameIdx); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1877 | name[lastNameIdx] = '\0'; |
| 1878 | } |
| 1879 | } |
| 1880 | } |
| 1881 | |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 1882 | GLsizei Program::getTransformFeedbackVaryingCount() const |
| 1883 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1884 | if (mLinked) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1885 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 1886 | return static_cast<GLsizei>(mState.mLinkedTransformFeedbackVaryings.size()); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1887 | } |
| 1888 | else |
| 1889 | { |
| 1890 | return 0; |
| 1891 | } |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 1892 | } |
| 1893 | |
| 1894 | GLsizei Program::getTransformFeedbackVaryingMaxLength() const |
| 1895 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1896 | if (mLinked) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1897 | { |
| 1898 | GLsizei maxSize = 0; |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 1899 | for (const auto &var : mState.mLinkedTransformFeedbackVaryings) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1900 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 1901 | maxSize = |
| 1902 | std::max(maxSize, static_cast<GLsizei>(var.nameWithArrayIndex().length() + 1)); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | return maxSize; |
| 1906 | } |
| 1907 | else |
| 1908 | { |
| 1909 | return 0; |
| 1910 | } |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | GLenum Program::getTransformFeedbackBufferMode() const |
| 1914 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1915 | return mState.mTransformFeedbackBufferMode; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1916 | } |
| 1917 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 1918 | bool Program::linkVaryings(const Context *context, InfoLog &infoLog) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1919 | { |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 1920 | Shader *vertexShader = mState.mAttachedVertexShader; |
| 1921 | Shader *fragmentShader = mState.mAttachedFragmentShader; |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 1922 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 1923 | ASSERT(vertexShader->getShaderVersion(context) == fragmentShader->getShaderVersion(context)); |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 1924 | |
Jiawei Shao | 3d40488 | 2017-10-16 13:30:48 +0800 | [diff] [blame] | 1925 | const std::vector<sh::Varying> &vertexVaryings = vertexShader->getOutputVaryings(context); |
| 1926 | const std::vector<sh::Varying> &fragmentVaryings = fragmentShader->getInputVaryings(context); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1927 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1928 | std::map<GLuint, std::string> staticFragmentInputLocations; |
| 1929 | |
Jamie Madill | 4cff247 | 2015-08-21 16:53:18 -0400 | [diff] [blame] | 1930 | for (const sh::Varying &output : fragmentVaryings) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1931 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1932 | bool matched = false; |
| 1933 | |
| 1934 | // Built-in varyings obey special rules |
Jamie Madill | ada9ecc | 2015-08-17 12:53:37 -0400 | [diff] [blame] | 1935 | if (output.isBuiltIn()) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1936 | { |
| 1937 | continue; |
| 1938 | } |
| 1939 | |
Jamie Madill | 4cff247 | 2015-08-21 16:53:18 -0400 | [diff] [blame] | 1940 | for (const sh::Varying &input : vertexVaryings) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1941 | { |
Jamie Madill | ada9ecc | 2015-08-17 12:53:37 -0400 | [diff] [blame] | 1942 | if (output.name == input.name) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1943 | { |
Jamie Madill | ada9ecc | 2015-08-17 12:53:37 -0400 | [diff] [blame] | 1944 | ASSERT(!input.isBuiltIn()); |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 1945 | if (!linkValidateVaryings(infoLog, output.name, input, output, |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 1946 | vertexShader->getShaderVersion(context))) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1947 | { |
| 1948 | return false; |
| 1949 | } |
| 1950 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1951 | matched = true; |
| 1952 | break; |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | // We permit unmatched, unreferenced varyings |
Jamie Madill | ada9ecc | 2015-08-17 12:53:37 -0400 | [diff] [blame] | 1957 | if (!matched && output.staticUse) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1958 | { |
Jamie Madill | ada9ecc | 2015-08-17 12:53:37 -0400 | [diff] [blame] | 1959 | infoLog << "Fragment varying " << output.name << " does not match any vertex varying"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1960 | return false; |
| 1961 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1962 | |
| 1963 | // Check for aliased path rendering input bindings (if any). |
| 1964 | // If more than one binding refer statically to the same |
| 1965 | // location the link must fail. |
| 1966 | |
| 1967 | if (!output.staticUse) |
| 1968 | continue; |
| 1969 | |
| 1970 | const auto inputBinding = mFragmentInputBindings.getBinding(output.name); |
| 1971 | if (inputBinding == -1) |
| 1972 | continue; |
| 1973 | |
| 1974 | const auto it = staticFragmentInputLocations.find(inputBinding); |
| 1975 | if (it == std::end(staticFragmentInputLocations)) |
| 1976 | { |
| 1977 | staticFragmentInputLocations.insert(std::make_pair(inputBinding, output.name)); |
| 1978 | } |
| 1979 | else |
| 1980 | { |
| 1981 | infoLog << "Binding for fragment input " << output.name << " conflicts with " |
| 1982 | << it->second; |
| 1983 | return false; |
| 1984 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1985 | } |
| 1986 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 1987 | if (!linkValidateBuiltInVaryings(context, infoLog)) |
Yuly Novikov | 817232e | 2017-02-22 18:36:10 -0500 | [diff] [blame] | 1988 | { |
| 1989 | return false; |
| 1990 | } |
| 1991 | |
Jamie Madill | ada9ecc | 2015-08-17 12:53:37 -0400 | [diff] [blame] | 1992 | // TODO(jmadill): verify no unmatched vertex varyings? |
| 1993 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1994 | return true; |
| 1995 | } |
| 1996 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 1997 | bool Program::linkUniforms(const Context *context, |
| 1998 | InfoLog &infoLog, |
Olli Etuaho | 4a92ceb | 2017-02-19 17:51:24 +0000 | [diff] [blame] | 1999 | const Bindings &uniformLocationBindings) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2000 | { |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 2001 | UniformLinker linker(mState); |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2002 | if (!linker.link(context, infoLog, uniformLocationBindings)) |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2003 | { |
| 2004 | return false; |
| 2005 | } |
| 2006 | |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 2007 | linker.getResults(&mState.mUniforms, &mState.mUniformLocations); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2008 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2009 | linkSamplerAndImageBindings(); |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2010 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2011 | if (!linkAtomicCounterBuffers()) |
| 2012 | { |
| 2013 | return false; |
| 2014 | } |
| 2015 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2016 | return true; |
| 2017 | } |
| 2018 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2019 | void Program::linkSamplerAndImageBindings() |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2020 | { |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 2021 | unsigned int high = static_cast<unsigned int>(mState.mUniforms.size()); |
| 2022 | unsigned int low = high; |
| 2023 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2024 | for (auto counterIter = mState.mUniforms.rbegin(); |
| 2025 | counterIter != mState.mUniforms.rend() && counterIter->isAtomicCounter(); ++counterIter) |
| 2026 | { |
| 2027 | --low; |
| 2028 | } |
| 2029 | |
| 2030 | mState.mAtomicCounterUniformRange = RangeUI(low, high); |
| 2031 | |
| 2032 | high = low; |
| 2033 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2034 | for (auto imageIter = mState.mUniforms.rbegin(); |
| 2035 | imageIter != mState.mUniforms.rend() && imageIter->isImage(); ++imageIter) |
| 2036 | { |
| 2037 | --low; |
| 2038 | } |
| 2039 | |
| 2040 | mState.mImageUniformRange = RangeUI(low, high); |
| 2041 | |
| 2042 | // If uniform is a image type, insert it into the mImageBindings array. |
| 2043 | for (unsigned int imageIndex : mState.mImageUniformRange) |
| 2044 | { |
Xinghua Cao | 0328b57 | 2017-06-26 15:51:36 +0800 | [diff] [blame] | 2045 | // ES3.1 (section 7.6.1) and GLSL ES3.1 (section 4.4.5), Uniform*i{v} commands |
| 2046 | // cannot load values into a uniform defined as an image. if declare without a |
| 2047 | // binding qualifier, any uniform image variable (include all elements of |
| 2048 | // unbound image array) shoud be bound to unit zero. |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2049 | auto &imageUniform = mState.mUniforms[imageIndex]; |
| 2050 | if (imageUniform.binding == -1) |
| 2051 | { |
Xinghua Cao | 0328b57 | 2017-06-26 15:51:36 +0800 | [diff] [blame] | 2052 | mState.mImageBindings.emplace_back(ImageBinding(imageUniform.elementCount())); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2053 | } |
Xinghua Cao | 0328b57 | 2017-06-26 15:51:36 +0800 | [diff] [blame] | 2054 | else |
| 2055 | { |
| 2056 | mState.mImageBindings.emplace_back( |
| 2057 | ImageBinding(imageUniform.binding, imageUniform.elementCount())); |
| 2058 | } |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | high = low; |
| 2062 | |
| 2063 | for (auto samplerIter = mState.mUniforms.rbegin() + mState.mImageUniformRange.length(); |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 2064 | samplerIter != mState.mUniforms.rend() && samplerIter->isSampler(); ++samplerIter) |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2065 | { |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 2066 | --low; |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2067 | } |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 2068 | |
| 2069 | mState.mSamplerUniformRange = RangeUI(low, high); |
| 2070 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2071 | // If uniform is a sampler type, insert it into the mSamplerBindings array. |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 2072 | for (unsigned int samplerIndex : mState.mSamplerUniformRange) |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2073 | { |
| 2074 | const auto &samplerUniform = mState.mUniforms[samplerIndex]; |
| 2075 | GLenum textureType = SamplerTypeToTextureType(samplerUniform.type); |
| 2076 | mState.mSamplerBindings.emplace_back( |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2077 | SamplerBinding(textureType, samplerUniform.elementCount(), false)); |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2078 | } |
| 2079 | } |
| 2080 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2081 | bool Program::linkAtomicCounterBuffers() |
| 2082 | { |
| 2083 | for (unsigned int index : mState.mAtomicCounterUniformRange) |
| 2084 | { |
| 2085 | auto &uniform = mState.mUniforms[index]; |
| 2086 | bool found = false; |
| 2087 | for (unsigned int bufferIndex = 0; bufferIndex < mState.mAtomicCounterBuffers.size(); |
| 2088 | ++bufferIndex) |
| 2089 | { |
| 2090 | auto &buffer = mState.mAtomicCounterBuffers[bufferIndex]; |
| 2091 | if (buffer.binding == uniform.binding) |
| 2092 | { |
| 2093 | buffer.memberIndexes.push_back(index); |
| 2094 | uniform.bufferIndex = bufferIndex; |
| 2095 | found = true; |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 2096 | buffer.unionReferencesWith(uniform); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2097 | break; |
| 2098 | } |
| 2099 | } |
| 2100 | if (!found) |
| 2101 | { |
| 2102 | AtomicCounterBuffer atomicCounterBuffer; |
| 2103 | atomicCounterBuffer.binding = uniform.binding; |
| 2104 | atomicCounterBuffer.memberIndexes.push_back(index); |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 2105 | atomicCounterBuffer.unionReferencesWith(uniform); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2106 | mState.mAtomicCounterBuffers.push_back(atomicCounterBuffer); |
| 2107 | uniform.bufferIndex = static_cast<int>(mState.mAtomicCounterBuffers.size() - 1); |
| 2108 | } |
| 2109 | } |
| 2110 | // TODO(jie.a.chen@intel.com): Count each atomic counter buffer to validate against |
| 2111 | // gl_Max[Vertex|Fragment|Compute|Combined]AtomicCounterBuffers. |
| 2112 | |
| 2113 | return true; |
| 2114 | } |
| 2115 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2116 | bool Program::linkValidateInterfaceBlockFields(InfoLog &infoLog, |
| 2117 | const std::string &uniformName, |
| 2118 | const sh::InterfaceBlockField &vertexUniform, |
Frank Henigman | fccbac2 | 2017-05-28 17:29:26 -0400 | [diff] [blame] | 2119 | const sh::InterfaceBlockField &fragmentUniform, |
| 2120 | bool webglCompatibility) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2121 | { |
Frank Henigman | fccbac2 | 2017-05-28 17:29:26 -0400 | [diff] [blame] | 2122 | // If webgl, validate precision of UBO fields, otherwise don't. See Khronos bug 10287. |
| 2123 | if (!linkValidateVariablesBase(infoLog, uniformName, vertexUniform, fragmentUniform, |
| 2124 | webglCompatibility)) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2125 | { |
| 2126 | return false; |
| 2127 | } |
| 2128 | |
| 2129 | if (vertexUniform.isRowMajorLayout != fragmentUniform.isRowMajorLayout) |
| 2130 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2131 | infoLog << "Matrix packings for " << uniformName << " differ between vertex and fragment shaders"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2132 | return false; |
| 2133 | } |
| 2134 | |
| 2135 | return true; |
| 2136 | } |
| 2137 | |
Jamie Madill | eb979bf | 2016-11-15 12:28:46 -0500 | [diff] [blame] | 2138 | // Assigns locations to all attributes from the bindings and program locations. |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2139 | bool Program::linkAttributes(const Context *context, InfoLog &infoLog) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2140 | { |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2141 | const ContextState &data = context->getContextState(); |
| 2142 | auto *vertexShader = mState.getAttachedVertexShader(); |
Jamie Madill | eb979bf | 2016-11-15 12:28:46 -0500 | [diff] [blame] | 2143 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2144 | unsigned int usedLocations = 0; |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2145 | mState.mAttributes = vertexShader->getActiveAttributes(context); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2146 | GLuint maxAttribs = data.getCaps().maxVertexAttributes; |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 2147 | |
| 2148 | // TODO(jmadill): handle aliasing robustly |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2149 | if (mState.mAttributes.size() > maxAttribs) |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 2150 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2151 | infoLog << "Too many vertex attributes."; |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 2152 | return false; |
| 2153 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2154 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2155 | std::vector<sh::Attribute *> usedAttribMap(maxAttribs, nullptr); |
Jamie Madill | 4e10722 | 2015-08-24 14:12:17 +0000 | [diff] [blame] | 2156 | |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2157 | // Link attributes that have a binding location |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2158 | for (sh::Attribute &attribute : mState.mAttributes) |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2159 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 2160 | // GLSL ES 3.10 January 2016 section 4.3.4: Vertex shader inputs can't be arrays or |
| 2161 | // structures, so we don't need to worry about adjusting their names or generating entries |
| 2162 | // for each member/element (unlike uniforms for example). |
| 2163 | ASSERT(!attribute.isArray() && !attribute.isStruct()); |
| 2164 | |
Jamie Madill | eb979bf | 2016-11-15 12:28:46 -0500 | [diff] [blame] | 2165 | int bindingLocation = mAttributeBindings.getBinding(attribute.name); |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2166 | if (attribute.location == -1 && bindingLocation != -1) |
Jamie Madill | 2d77318 | 2015-08-18 10:27:28 -0400 | [diff] [blame] | 2167 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2168 | attribute.location = bindingLocation; |
| 2169 | } |
| 2170 | |
| 2171 | if (attribute.location != -1) |
| 2172 | { |
| 2173 | // Location is set by glBindAttribLocation or by location layout qualifier |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 2174 | const int regs = VariableRegisterCount(attribute.type); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2175 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 2176 | if (static_cast<GLuint>(regs + attribute.location) > maxAttribs) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2177 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2178 | infoLog << "Active attribute (" << attribute.name << ") at location " |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2179 | << attribute.location << " is too big to fit"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2180 | |
| 2181 | return false; |
| 2182 | } |
| 2183 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 2184 | for (int reg = 0; reg < regs; reg++) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2185 | { |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 2186 | const int regLocation = attribute.location + reg; |
| 2187 | sh::ShaderVariable *linkedAttribute = usedAttribMap[regLocation]; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2188 | |
| 2189 | // In GLSL 3.00, attribute aliasing produces a link error |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 2190 | // In GLSL 1.00, attribute aliasing is allowed, but ANGLE currently has a bug |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2191 | if (linkedAttribute) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2192 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2193 | // TODO(jmadill): fix aliasing on ES2 |
| 2194 | // if (mProgram->getShaderVersion() >= 300) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2195 | { |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 2196 | infoLog << "Attribute '" << attribute.name << "' aliases attribute '" |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 2197 | << linkedAttribute->name << "' at location " << regLocation; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2198 | return false; |
| 2199 | } |
| 2200 | } |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2201 | else |
| 2202 | { |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 2203 | usedAttribMap[regLocation] = &attribute; |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2204 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2205 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 2206 | usedLocations |= 1 << regLocation; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2207 | } |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | // Link attributes that don't have a binding location |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2212 | for (sh::Attribute &attribute : mState.mAttributes) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2213 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2214 | // Not set by glBindAttribLocation or by location layout qualifier |
| 2215 | if (attribute.location == -1) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2216 | { |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 2217 | int regs = VariableRegisterCount(attribute.type); |
| 2218 | int availableIndex = AllocateFirstFreeBits(&usedLocations, regs, maxAttribs); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2219 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 2220 | if (availableIndex == -1 || static_cast<GLuint>(availableIndex + regs) > maxAttribs) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2221 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2222 | infoLog << "Too many active attributes (" << attribute.name << ")"; |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2223 | return false; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2224 | } |
| 2225 | |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2226 | attribute.location = availableIndex; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2230 | for (const sh::Attribute &attribute : mState.mAttributes) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2231 | { |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 2232 | ASSERT(attribute.location != -1); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 2233 | unsigned int regs = static_cast<unsigned int>(VariableRegisterCount(attribute.type)); |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 2234 | |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 2235 | for (unsigned int r = 0; r < regs; r++) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2236 | { |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 2237 | unsigned int location = static_cast<unsigned int>(attribute.location) + r; |
| 2238 | mState.mActiveAttribLocationsMask.set(location); |
| 2239 | mState.mMaxActiveAttribLocation = |
| 2240 | std::max(mState.mMaxActiveAttribLocation, location + 1); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2241 | } |
| 2242 | } |
| 2243 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2244 | return true; |
| 2245 | } |
| 2246 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2247 | bool Program::validateVertexAndFragmentInterfaceBlocks( |
| 2248 | const std::vector<sh::InterfaceBlock> &vertexInterfaceBlocks, |
| 2249 | const std::vector<sh::InterfaceBlock> &fragmentInterfaceBlocks, |
Frank Henigman | fccbac2 | 2017-05-28 17:29:26 -0400 | [diff] [blame] | 2250 | InfoLog &infoLog, |
| 2251 | bool webglCompatibility) const |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2252 | { |
| 2253 | // Check that interface blocks defined in the vertex and fragment shaders are identical |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2254 | typedef std::map<std::string, const sh::InterfaceBlock *> InterfaceBlockMap; |
| 2255 | InterfaceBlockMap linkedInterfaceBlocks; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2256 | |
| 2257 | for (const sh::InterfaceBlock &vertexInterfaceBlock : vertexInterfaceBlocks) |
| 2258 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2259 | linkedInterfaceBlocks[vertexInterfaceBlock.name] = &vertexInterfaceBlock; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2260 | } |
| 2261 | |
Jamie Madill | e473dee | 2015-08-18 14:49:01 -0400 | [diff] [blame] | 2262 | for (const sh::InterfaceBlock &fragmentInterfaceBlock : fragmentInterfaceBlocks) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2263 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2264 | auto entry = linkedInterfaceBlocks.find(fragmentInterfaceBlock.name); |
| 2265 | if (entry != linkedInterfaceBlocks.end()) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2266 | { |
| 2267 | const sh::InterfaceBlock &vertexInterfaceBlock = *entry->second; |
Frank Henigman | fccbac2 | 2017-05-28 17:29:26 -0400 | [diff] [blame] | 2268 | if (!areMatchingInterfaceBlocks(infoLog, vertexInterfaceBlock, fragmentInterfaceBlock, |
| 2269 | webglCompatibility)) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2270 | { |
| 2271 | return false; |
| 2272 | } |
| 2273 | } |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2274 | // TODO(jiajia.qin@intel.com): Add |
| 2275 | // MAX_COMBINED_UNIFORM_BLOCKS/MAX_COMBINED_SHADER_STORAGE_BLOCKS validation. |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2276 | } |
| 2277 | return true; |
| 2278 | } |
Jamie Madill | e473dee | 2015-08-18 14:49:01 -0400 | [diff] [blame] | 2279 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2280 | bool Program::linkInterfaceBlocks(const Context *context, InfoLog &infoLog) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2281 | { |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2282 | const auto &caps = context->getCaps(); |
| 2283 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2284 | if (mState.mAttachedComputeShader) |
| 2285 | { |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2286 | Shader &computeShader = *mState.mAttachedComputeShader; |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2287 | const auto &computeUniformBlocks = computeShader.getUniformBlocks(context); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2288 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2289 | if (!validateInterfaceBlocksCount( |
| 2290 | caps.maxComputeUniformBlocks, computeUniformBlocks, |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2291 | "Compute shader uniform block count exceeds GL_MAX_COMPUTE_UNIFORM_BLOCKS (", |
| 2292 | infoLog)) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2293 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2294 | return false; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2295 | } |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2296 | |
| 2297 | const auto &computeShaderStorageBlocks = computeShader.getShaderStorageBlocks(context); |
| 2298 | if (!validateInterfaceBlocksCount(caps.maxComputeShaderStorageBlocks, |
| 2299 | computeShaderStorageBlocks, |
| 2300 | "Compute shader shader storage block count exceeds " |
| 2301 | "GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS (", |
| 2302 | infoLog)) |
| 2303 | { |
| 2304 | return false; |
| 2305 | } |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2306 | return true; |
| 2307 | } |
| 2308 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2309 | Shader &vertexShader = *mState.mAttachedVertexShader; |
| 2310 | Shader &fragmentShader = *mState.mAttachedFragmentShader; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2311 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2312 | const auto &vertexUniformBlocks = vertexShader.getUniformBlocks(context); |
| 2313 | const auto &fragmentUniformBlocks = fragmentShader.getUniformBlocks(context); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2314 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2315 | if (!validateInterfaceBlocksCount( |
| 2316 | caps.maxVertexUniformBlocks, vertexUniformBlocks, |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2317 | "Vertex shader uniform block count exceeds GL_MAX_VERTEX_UNIFORM_BLOCKS (", infoLog)) |
| 2318 | { |
| 2319 | return false; |
| 2320 | } |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2321 | if (!validateInterfaceBlocksCount( |
| 2322 | caps.maxFragmentUniformBlocks, fragmentUniformBlocks, |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2323 | "Fragment shader uniform block count exceeds GL_MAX_FRAGMENT_UNIFORM_BLOCKS (", |
| 2324 | infoLog)) |
| 2325 | { |
| 2326 | |
| 2327 | return false; |
| 2328 | } |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2329 | |
| 2330 | bool webglCompatibility = context->getExtensions().webglCompatibility; |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2331 | if (!validateVertexAndFragmentInterfaceBlocks(vertexUniformBlocks, fragmentUniformBlocks, |
Frank Henigman | fccbac2 | 2017-05-28 17:29:26 -0400 | [diff] [blame] | 2332 | infoLog, webglCompatibility)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2333 | { |
| 2334 | return false; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2335 | } |
Jamie Madill | e473dee | 2015-08-18 14:49:01 -0400 | [diff] [blame] | 2336 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2337 | if (context->getClientVersion() >= Version(3, 1)) |
| 2338 | { |
| 2339 | const auto &vertexShaderStorageBlocks = vertexShader.getShaderStorageBlocks(context); |
| 2340 | const auto &fragmentShaderStorageBlocks = fragmentShader.getShaderStorageBlocks(context); |
| 2341 | |
| 2342 | if (!validateInterfaceBlocksCount(caps.maxVertexShaderStorageBlocks, |
| 2343 | vertexShaderStorageBlocks, |
| 2344 | "Vertex shader shader storage block count exceeds " |
| 2345 | "GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS (", |
| 2346 | infoLog)) |
| 2347 | { |
| 2348 | return false; |
| 2349 | } |
| 2350 | if (!validateInterfaceBlocksCount(caps.maxFragmentShaderStorageBlocks, |
| 2351 | fragmentShaderStorageBlocks, |
| 2352 | "Fragment shader shader storage block count exceeds " |
| 2353 | "GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS (", |
| 2354 | infoLog)) |
| 2355 | { |
| 2356 | |
| 2357 | return false; |
| 2358 | } |
| 2359 | |
| 2360 | if (!validateVertexAndFragmentInterfaceBlocks(vertexShaderStorageBlocks, |
| 2361 | fragmentShaderStorageBlocks, infoLog, |
| 2362 | webglCompatibility)) |
| 2363 | { |
| 2364 | return false; |
| 2365 | } |
| 2366 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2367 | return true; |
| 2368 | } |
| 2369 | |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 2370 | bool Program::areMatchingInterfaceBlocks(InfoLog &infoLog, |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2371 | const sh::InterfaceBlock &vertexInterfaceBlock, |
Frank Henigman | fccbac2 | 2017-05-28 17:29:26 -0400 | [diff] [blame] | 2372 | const sh::InterfaceBlock &fragmentInterfaceBlock, |
| 2373 | bool webglCompatibility) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2374 | { |
| 2375 | const char* blockName = vertexInterfaceBlock.name.c_str(); |
| 2376 | // validate blocks for the same member types |
| 2377 | if (vertexInterfaceBlock.fields.size() != fragmentInterfaceBlock.fields.size()) |
| 2378 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2379 | infoLog << "Types for interface block '" << blockName |
| 2380 | << "' differ between vertex and fragment shaders"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2381 | return false; |
| 2382 | } |
| 2383 | if (vertexInterfaceBlock.arraySize != fragmentInterfaceBlock.arraySize) |
| 2384 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2385 | infoLog << "Array sizes differ for interface block '" << blockName |
| 2386 | << "' between vertex and fragment shaders"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2387 | return false; |
| 2388 | } |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 2389 | if (vertexInterfaceBlock.layout != fragmentInterfaceBlock.layout || |
| 2390 | vertexInterfaceBlock.isRowMajorLayout != fragmentInterfaceBlock.isRowMajorLayout || |
| 2391 | vertexInterfaceBlock.binding != fragmentInterfaceBlock.binding) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2392 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2393 | infoLog << "Layout qualifiers differ for interface block '" << blockName |
| 2394 | << "' between vertex and fragment shaders"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2395 | return false; |
| 2396 | } |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 2397 | const unsigned int numBlockMembers = |
| 2398 | static_cast<unsigned int>(vertexInterfaceBlock.fields.size()); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2399 | for (unsigned int blockMemberIndex = 0; blockMemberIndex < numBlockMembers; blockMemberIndex++) |
| 2400 | { |
| 2401 | const sh::InterfaceBlockField &vertexMember = vertexInterfaceBlock.fields[blockMemberIndex]; |
| 2402 | const sh::InterfaceBlockField &fragmentMember = fragmentInterfaceBlock.fields[blockMemberIndex]; |
| 2403 | if (vertexMember.name != fragmentMember.name) |
| 2404 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2405 | infoLog << "Name mismatch for field " << blockMemberIndex |
| 2406 | << " of interface block '" << blockName |
| 2407 | << "': (in vertex: '" << vertexMember.name |
| 2408 | << "', in fragment: '" << fragmentMember.name << "')"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2409 | return false; |
| 2410 | } |
| 2411 | std::string memberName = "interface block '" + vertexInterfaceBlock.name + "' member '" + vertexMember.name + "'"; |
Frank Henigman | fccbac2 | 2017-05-28 17:29:26 -0400 | [diff] [blame] | 2412 | if (!linkValidateInterfaceBlockFields(infoLog, memberName, vertexMember, fragmentMember, |
| 2413 | webglCompatibility)) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2414 | { |
| 2415 | return false; |
| 2416 | } |
| 2417 | } |
| 2418 | return true; |
| 2419 | } |
| 2420 | |
| 2421 | bool Program::linkValidateVariablesBase(InfoLog &infoLog, const std::string &variableName, const sh::ShaderVariable &vertexVariable, |
| 2422 | const sh::ShaderVariable &fragmentVariable, bool validatePrecision) |
| 2423 | { |
| 2424 | if (vertexVariable.type != fragmentVariable.type) |
| 2425 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2426 | infoLog << "Types for " << variableName << " differ between vertex and fragment shaders"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2427 | return false; |
| 2428 | } |
| 2429 | if (vertexVariable.arraySize != fragmentVariable.arraySize) |
| 2430 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2431 | infoLog << "Array sizes for " << variableName << " differ between vertex and fragment shaders"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2432 | return false; |
| 2433 | } |
| 2434 | if (validatePrecision && vertexVariable.precision != fragmentVariable.precision) |
| 2435 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2436 | infoLog << "Precisions for " << variableName << " differ between vertex and fragment shaders"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2437 | return false; |
| 2438 | } |
Geoff Lang | bb1e750 | 2017-06-05 16:40:09 -0400 | [diff] [blame] | 2439 | if (vertexVariable.structName != fragmentVariable.structName) |
| 2440 | { |
| 2441 | infoLog << "Structure names for " << variableName |
| 2442 | << " differ between vertex and fragment shaders"; |
| 2443 | return false; |
| 2444 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2445 | |
| 2446 | if (vertexVariable.fields.size() != fragmentVariable.fields.size()) |
| 2447 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2448 | infoLog << "Structure lengths for " << variableName << " differ between vertex and fragment shaders"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2449 | return false; |
| 2450 | } |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 2451 | const unsigned int numMembers = static_cast<unsigned int>(vertexVariable.fields.size()); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2452 | for (unsigned int memberIndex = 0; memberIndex < numMembers; memberIndex++) |
| 2453 | { |
| 2454 | const sh::ShaderVariable &vertexMember = vertexVariable.fields[memberIndex]; |
| 2455 | const sh::ShaderVariable &fragmentMember = fragmentVariable.fields[memberIndex]; |
| 2456 | |
| 2457 | if (vertexMember.name != fragmentMember.name) |
| 2458 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2459 | infoLog << "Name mismatch for field '" << memberIndex |
| 2460 | << "' of " << variableName |
| 2461 | << ": (in vertex: '" << vertexMember.name |
| 2462 | << "', in fragment: '" << fragmentMember.name << "')"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2463 | return false; |
| 2464 | } |
| 2465 | |
| 2466 | const std::string memberName = variableName.substr(0, variableName.length() - 1) + "." + |
| 2467 | vertexMember.name + "'"; |
| 2468 | |
| 2469 | if (!linkValidateVariablesBase(infoLog, vertexMember.name, vertexMember, fragmentMember, validatePrecision)) |
| 2470 | { |
| 2471 | return false; |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | return true; |
| 2476 | } |
| 2477 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 2478 | bool Program::linkValidateVaryings(InfoLog &infoLog, |
| 2479 | const std::string &varyingName, |
| 2480 | const sh::Varying &vertexVarying, |
| 2481 | const sh::Varying &fragmentVarying, |
| 2482 | int shaderVersion) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2483 | { |
| 2484 | if (!linkValidateVariablesBase(infoLog, varyingName, vertexVarying, fragmentVarying, false)) |
| 2485 | { |
| 2486 | return false; |
| 2487 | } |
| 2488 | |
Jamie Madill | e9cc469 | 2015-02-19 16:00:13 -0500 | [diff] [blame] | 2489 | if (!sh::InterpolationTypesMatch(vertexVarying.interpolation, fragmentVarying.interpolation)) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2490 | { |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 2491 | infoLog << "Interpolation types for " << varyingName |
| 2492 | << " differ between vertex and fragment shaders."; |
| 2493 | return false; |
| 2494 | } |
| 2495 | |
| 2496 | if (shaderVersion == 100 && vertexVarying.isInvariant != fragmentVarying.isInvariant) |
| 2497 | { |
| 2498 | infoLog << "Invariance for " << varyingName |
| 2499 | << " differs between vertex and fragment shaders."; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2500 | return false; |
| 2501 | } |
| 2502 | |
| 2503 | return true; |
| 2504 | } |
| 2505 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2506 | bool Program::linkValidateBuiltInVaryings(const Context *context, InfoLog &infoLog) const |
Yuly Novikov | 817232e | 2017-02-22 18:36:10 -0500 | [diff] [blame] | 2507 | { |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2508 | Shader *vertexShader = mState.mAttachedVertexShader; |
| 2509 | Shader *fragmentShader = mState.mAttachedFragmentShader; |
Jiawei Shao | 3d40488 | 2017-10-16 13:30:48 +0800 | [diff] [blame] | 2510 | const auto &vertexVaryings = vertexShader->getOutputVaryings(context); |
| 2511 | const auto &fragmentVaryings = fragmentShader->getInputVaryings(context); |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2512 | int shaderVersion = vertexShader->getShaderVersion(context); |
Yuly Novikov | 817232e | 2017-02-22 18:36:10 -0500 | [diff] [blame] | 2513 | |
| 2514 | if (shaderVersion != 100) |
| 2515 | { |
| 2516 | // Only ESSL 1.0 has restrictions on matching input and output invariance |
| 2517 | return true; |
| 2518 | } |
| 2519 | |
| 2520 | bool glPositionIsInvariant = false; |
| 2521 | bool glPointSizeIsInvariant = false; |
| 2522 | bool glFragCoordIsInvariant = false; |
| 2523 | bool glPointCoordIsInvariant = false; |
| 2524 | |
| 2525 | for (const sh::Varying &varying : vertexVaryings) |
| 2526 | { |
| 2527 | if (!varying.isBuiltIn()) |
| 2528 | { |
| 2529 | continue; |
| 2530 | } |
| 2531 | if (varying.name.compare("gl_Position") == 0) |
| 2532 | { |
| 2533 | glPositionIsInvariant = varying.isInvariant; |
| 2534 | } |
| 2535 | else if (varying.name.compare("gl_PointSize") == 0) |
| 2536 | { |
| 2537 | glPointSizeIsInvariant = varying.isInvariant; |
| 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | for (const sh::Varying &varying : fragmentVaryings) |
| 2542 | { |
| 2543 | if (!varying.isBuiltIn()) |
| 2544 | { |
| 2545 | continue; |
| 2546 | } |
| 2547 | if (varying.name.compare("gl_FragCoord") == 0) |
| 2548 | { |
| 2549 | glFragCoordIsInvariant = varying.isInvariant; |
| 2550 | } |
| 2551 | else if (varying.name.compare("gl_PointCoord") == 0) |
| 2552 | { |
| 2553 | glPointCoordIsInvariant = varying.isInvariant; |
| 2554 | } |
| 2555 | } |
| 2556 | |
| 2557 | // There is some ambiguity in ESSL 1.00.17 paragraph 4.6.4 interpretation, |
| 2558 | // for example, https://cvs.khronos.org/bugzilla/show_bug.cgi?id=13842. |
| 2559 | // Not requiring invariance to match is supported by: |
| 2560 | // dEQP, WebGL CTS, Nexus 5X GLES |
| 2561 | if (glFragCoordIsInvariant && !glPositionIsInvariant) |
| 2562 | { |
| 2563 | infoLog << "gl_FragCoord can only be declared invariant if and only if gl_Position is " |
| 2564 | "declared invariant."; |
| 2565 | return false; |
| 2566 | } |
| 2567 | if (glPointCoordIsInvariant && !glPointSizeIsInvariant) |
| 2568 | { |
| 2569 | infoLog << "gl_PointCoord can only be declared invariant if and only if gl_PointSize is " |
| 2570 | "declared invariant."; |
| 2571 | return false; |
| 2572 | } |
| 2573 | |
| 2574 | return true; |
| 2575 | } |
| 2576 | |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2577 | bool Program::linkValidateTransformFeedback(const gl::Context *context, |
| 2578 | InfoLog &infoLog, |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2579 | const Program::MergedVaryings &varyings, |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2580 | const Caps &caps) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2581 | { |
| 2582 | size_t totalComponents = 0; |
| 2583 | |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2584 | std::set<std::string> uniqueNames; |
| 2585 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2586 | for (const std::string &tfVaryingName : mState.mTransformFeedbackVaryingNames) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2587 | { |
| 2588 | bool found = false; |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 2589 | std::vector<unsigned int> subscripts; |
| 2590 | std::string baseName = ParseResourceName(tfVaryingName, &subscripts); |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2591 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2592 | for (const auto &ref : varyings) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2593 | { |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2594 | const sh::Varying *varying = ref.second.get(); |
| 2595 | |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2596 | if (baseName == varying->name) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2597 | { |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2598 | if (uniqueNames.count(tfVaryingName) > 0) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2599 | { |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2600 | infoLog << "Two transform feedback varyings specify the same output variable (" |
| 2601 | << tfVaryingName << ")."; |
| 2602 | return false; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2603 | } |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2604 | if (context->getClientVersion() >= Version(3, 1)) |
| 2605 | { |
| 2606 | if (IncludeSameArrayElement(uniqueNames, tfVaryingName)) |
| 2607 | { |
| 2608 | infoLog |
| 2609 | << "Two transform feedback varyings include the same array element (" |
| 2610 | << tfVaryingName << ")."; |
| 2611 | return false; |
| 2612 | } |
| 2613 | } |
| 2614 | else if (varying->isArray()) |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 2615 | { |
| 2616 | infoLog << "Capture of arrays is undefined and not supported."; |
| 2617 | return false; |
| 2618 | } |
| 2619 | |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2620 | uniqueNames.insert(tfVaryingName); |
| 2621 | |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2622 | // TODO(jmadill): Investigate implementation limits on D3D11 |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2623 | size_t elementCount = |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 2624 | ((varying->isArray() && subscripts.empty()) ? varying->elementCount() : 1); |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2625 | size_t componentCount = VariableComponentCount(varying->type) * elementCount; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2626 | if (mState.mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS && |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2627 | componentCount > caps.maxTransformFeedbackSeparateComponents) |
| 2628 | { |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2629 | infoLog << "Transform feedback varying's " << varying->name << " components (" |
| 2630 | << componentCount << ") exceed the maximum separate components (" |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2631 | << caps.maxTransformFeedbackSeparateComponents << ")."; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2632 | return false; |
| 2633 | } |
| 2634 | |
| 2635 | totalComponents += componentCount; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2636 | found = true; |
| 2637 | break; |
| 2638 | } |
| 2639 | } |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2640 | if (context->getClientVersion() < Version(3, 1) && |
| 2641 | tfVaryingName.find('[') != std::string::npos) |
Jamie Madill | 89bb70e | 2015-08-31 14:18:39 -0400 | [diff] [blame] | 2642 | { |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 2643 | infoLog << "Capture of array elements is undefined and not supported."; |
Jamie Madill | 89bb70e | 2015-08-31 14:18:39 -0400 | [diff] [blame] | 2644 | return false; |
| 2645 | } |
Olli Etuaho | 39e7812 | 2017-08-29 14:34:22 +0300 | [diff] [blame] | 2646 | // All transform feedback varyings are expected to exist since packUserVaryings checks for |
| 2647 | // them. |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2648 | ASSERT(found); |
| 2649 | } |
| 2650 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2651 | if (mState.mTransformFeedbackBufferMode == GL_INTERLEAVED_ATTRIBS && |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2652 | totalComponents > caps.maxTransformFeedbackInterleavedComponents) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2653 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2654 | infoLog << "Transform feedback varying total components (" << totalComponents |
| 2655 | << ") exceed the maximum interleaved components (" |
| 2656 | << caps.maxTransformFeedbackInterleavedComponents << ")."; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2657 | return false; |
| 2658 | } |
| 2659 | |
| 2660 | return true; |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 2661 | } |
| 2662 | |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 2663 | bool Program::linkValidateGlobalNames(const Context *context, InfoLog &infoLog) const |
| 2664 | { |
| 2665 | const std::vector<sh::Uniform> &vertexUniforms = |
| 2666 | mState.mAttachedVertexShader->getUniforms(context); |
| 2667 | const std::vector<sh::Uniform> &fragmentUniforms = |
| 2668 | mState.mAttachedFragmentShader->getUniforms(context); |
| 2669 | const std::vector<sh::Attribute> &attributes = |
| 2670 | mState.mAttachedVertexShader->getActiveAttributes(context); |
| 2671 | for (const auto &attrib : attributes) |
| 2672 | { |
| 2673 | for (const auto &uniform : vertexUniforms) |
| 2674 | { |
| 2675 | if (uniform.name == attrib.name) |
| 2676 | { |
| 2677 | infoLog << "Name conflicts between a uniform and an attribute: " << attrib.name; |
| 2678 | return false; |
| 2679 | } |
| 2680 | } |
| 2681 | for (const auto &uniform : fragmentUniforms) |
| 2682 | { |
| 2683 | if (uniform.name == attrib.name) |
| 2684 | { |
| 2685 | infoLog << "Name conflicts between a uniform and an attribute: " << attrib.name; |
| 2686 | return false; |
| 2687 | } |
| 2688 | } |
| 2689 | } |
| 2690 | return true; |
| 2691 | } |
| 2692 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2693 | void Program::gatherTransformFeedbackVaryings(const Program::MergedVaryings &varyings) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2694 | { |
| 2695 | // Gather the linked varyings that are used for transform feedback, they should all exist. |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2696 | mState.mLinkedTransformFeedbackVaryings.clear(); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2697 | for (const std::string &tfVaryingName : mState.mTransformFeedbackVaryingNames) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2698 | { |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 2699 | std::vector<unsigned int> subscripts; |
| 2700 | std::string baseName = ParseResourceName(tfVaryingName, &subscripts); |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2701 | size_t subscript = GL_INVALID_INDEX; |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 2702 | if (!subscripts.empty()) |
| 2703 | { |
| 2704 | subscript = subscripts.back(); |
| 2705 | } |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2706 | for (const auto &ref : varyings) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2707 | { |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2708 | const sh::Varying *varying = ref.second.get(); |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2709 | if (baseName == varying->name) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2710 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2711 | mState.mLinkedTransformFeedbackVaryings.emplace_back( |
| 2712 | *varying, static_cast<GLuint>(subscript)); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2713 | break; |
| 2714 | } |
| 2715 | } |
| 2716 | } |
| 2717 | } |
| 2718 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2719 | Program::MergedVaryings Program::getMergedVaryings(const Context *context) const |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2720 | { |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2721 | MergedVaryings merged; |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2722 | |
Jiawei Shao | 3d40488 | 2017-10-16 13:30:48 +0800 | [diff] [blame] | 2723 | for (const sh::Varying &varying : mState.mAttachedVertexShader->getOutputVaryings(context)) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2724 | { |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2725 | merged[varying.name].vertex = &varying; |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2726 | } |
| 2727 | |
Jiawei Shao | 3d40488 | 2017-10-16 13:30:48 +0800 | [diff] [blame] | 2728 | for (const sh::Varying &varying : mState.mAttachedFragmentShader->getInputVaryings(context)) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2729 | { |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2730 | merged[varying.name].fragment = &varying; |
| 2731 | } |
| 2732 | |
| 2733 | return merged; |
| 2734 | } |
| 2735 | |
| 2736 | std::vector<PackedVarying> Program::getPackedVaryings( |
| 2737 | const Program::MergedVaryings &mergedVaryings) const |
| 2738 | { |
| 2739 | const std::vector<std::string> &tfVaryings = mState.getTransformFeedbackVaryingNames(); |
| 2740 | std::vector<PackedVarying> packedVaryings; |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2741 | std::set<std::string> uniqueFullNames; |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2742 | |
| 2743 | for (const auto &ref : mergedVaryings) |
| 2744 | { |
| 2745 | const sh::Varying *input = ref.second.vertex; |
| 2746 | const sh::Varying *output = ref.second.fragment; |
| 2747 | |
| 2748 | // Only pack varyings that have a matched input or output, plus special builtins. |
| 2749 | if ((input && output) || (output && output->isBuiltIn())) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2750 | { |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2751 | // Will get the vertex shader interpolation by default. |
| 2752 | auto interpolation = ref.second.get()->interpolation; |
| 2753 | |
Olli Etuaho | 06a06f5 | 2017-07-12 12:22:15 +0300 | [diff] [blame] | 2754 | // Note that we lose the vertex shader static use information here. The data for the |
| 2755 | // variable is taken from the fragment shader. |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2756 | if (output->isStruct()) |
| 2757 | { |
| 2758 | ASSERT(!output->isArray()); |
| 2759 | for (const auto &field : output->fields) |
| 2760 | { |
| 2761 | ASSERT(!field.isStruct() && !field.isArray()); |
| 2762 | packedVaryings.push_back(PackedVarying(field, interpolation, output->name)); |
| 2763 | } |
| 2764 | } |
| 2765 | else |
| 2766 | { |
| 2767 | packedVaryings.push_back(PackedVarying(*output, interpolation)); |
| 2768 | } |
| 2769 | continue; |
| 2770 | } |
| 2771 | |
| 2772 | // Keep Transform FB varyings in the merged list always. |
| 2773 | if (!input) |
| 2774 | { |
| 2775 | continue; |
| 2776 | } |
| 2777 | |
| 2778 | for (const std::string &tfVarying : tfVaryings) |
| 2779 | { |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 2780 | std::vector<unsigned int> subscripts; |
| 2781 | std::string baseName = ParseResourceName(tfVarying, &subscripts); |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2782 | size_t subscript = GL_INVALID_INDEX; |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 2783 | if (!subscripts.empty()) |
| 2784 | { |
| 2785 | subscript = subscripts.back(); |
| 2786 | } |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2787 | if (uniqueFullNames.count(tfVarying) > 0) |
| 2788 | { |
| 2789 | continue; |
| 2790 | } |
| 2791 | if (baseName == input->name) |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2792 | { |
| 2793 | // Transform feedback for varying structs is underspecified. |
| 2794 | // See Khronos bug 9856. |
| 2795 | // TODO(jmadill): Figure out how to be spec-compliant here. |
| 2796 | if (!input->isStruct()) |
| 2797 | { |
| 2798 | packedVaryings.push_back(PackedVarying(*input, input->interpolation)); |
| 2799 | packedVaryings.back().vertexOnly = true; |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2800 | packedVaryings.back().arrayIndex = static_cast<GLuint>(subscript); |
| 2801 | uniqueFullNames.insert(tfVarying); |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2802 | } |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2803 | if (subscript == GL_INVALID_INDEX) |
| 2804 | { |
| 2805 | break; |
| 2806 | } |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2807 | } |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2808 | } |
| 2809 | } |
| 2810 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2811 | std::sort(packedVaryings.begin(), packedVaryings.end(), ComparePackedVarying); |
| 2812 | |
| 2813 | return packedVaryings; |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 2814 | } |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2815 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2816 | void Program::linkOutputVariables(const Context *context) |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2817 | { |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2818 | Shader *fragmentShader = mState.mAttachedFragmentShader; |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2819 | ASSERT(fragmentShader != nullptr); |
| 2820 | |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2821 | ASSERT(mState.mOutputVariableTypes.empty()); |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 2822 | ASSERT(mState.mActiveOutputVariables.none()); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2823 | |
| 2824 | // Gather output variable types |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2825 | for (const auto &outputVariable : fragmentShader->getActiveOutputVariables(context)) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2826 | { |
| 2827 | if (outputVariable.isBuiltIn() && outputVariable.name != "gl_FragColor" && |
| 2828 | outputVariable.name != "gl_FragData") |
| 2829 | { |
| 2830 | continue; |
| 2831 | } |
| 2832 | |
| 2833 | unsigned int baseLocation = |
| 2834 | (outputVariable.location == -1 ? 0u |
| 2835 | : static_cast<unsigned int>(outputVariable.location)); |
| 2836 | for (unsigned int elementIndex = 0; elementIndex < outputVariable.elementCount(); |
| 2837 | elementIndex++) |
| 2838 | { |
| 2839 | const unsigned int location = baseLocation + elementIndex; |
| 2840 | if (location >= mState.mOutputVariableTypes.size()) |
| 2841 | { |
| 2842 | mState.mOutputVariableTypes.resize(location + 1, GL_NONE); |
| 2843 | } |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 2844 | ASSERT(location < mState.mActiveOutputVariables.size()); |
| 2845 | mState.mActiveOutputVariables.set(location); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2846 | mState.mOutputVariableTypes[location] = VariableComponentType(outputVariable.type); |
| 2847 | } |
| 2848 | } |
| 2849 | |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2850 | // Skip this step for GLES2 shaders. |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2851 | if (fragmentShader->getShaderVersion(context) == 100) |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2852 | return; |
| 2853 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2854 | mState.mOutputVariables = fragmentShader->getActiveOutputVariables(context); |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2855 | // TODO(jmadill): any caps validation here? |
| 2856 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 2857 | for (unsigned int outputVariableIndex = 0; outputVariableIndex < mState.mOutputVariables.size(); |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2858 | outputVariableIndex++) |
| 2859 | { |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 2860 | const sh::OutputVariable &outputVariable = mState.mOutputVariables[outputVariableIndex]; |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2861 | |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 2862 | if (outputVariable.isArray()) |
| 2863 | { |
| 2864 | // We're following the GLES 3.1 November 2016 spec section 7.3.1.1 Naming Active |
| 2865 | // Resources and including [0] at the end of array variable names. |
| 2866 | mState.mOutputVariables[outputVariableIndex].name += "[0]"; |
| 2867 | mState.mOutputVariables[outputVariableIndex].mappedName += "[0]"; |
| 2868 | } |
| 2869 | |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2870 | // Don't store outputs for gl_FragDepth, gl_FragColor, etc. |
| 2871 | if (outputVariable.isBuiltIn()) |
| 2872 | continue; |
| 2873 | |
| 2874 | // Since multiple output locations must be specified, use 0 for non-specified locations. |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 2875 | unsigned int baseLocation = |
| 2876 | (outputVariable.location == -1 ? 0u |
| 2877 | : static_cast<unsigned int>(outputVariable.location)); |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2878 | |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2879 | for (unsigned int elementIndex = 0; elementIndex < outputVariable.elementCount(); |
| 2880 | elementIndex++) |
| 2881 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 2882 | const unsigned int location = baseLocation + elementIndex; |
| 2883 | if (location >= mState.mOutputLocations.size()) |
| 2884 | { |
| 2885 | mState.mOutputLocations.resize(location + 1); |
| 2886 | } |
| 2887 | ASSERT(!mState.mOutputLocations.at(location).used()); |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 2888 | if (outputVariable.isArray()) |
| 2889 | { |
| 2890 | mState.mOutputLocations[location] = |
| 2891 | VariableLocation(elementIndex, outputVariableIndex); |
| 2892 | } |
| 2893 | else |
| 2894 | { |
| 2895 | VariableLocation locationInfo; |
| 2896 | locationInfo.index = outputVariableIndex; |
| 2897 | mState.mOutputLocations[location] = locationInfo; |
| 2898 | } |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 2899 | } |
| 2900 | } |
| 2901 | } |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2902 | |
Olli Etuaho | 48fed63 | 2017-03-16 12:05:30 +0000 | [diff] [blame] | 2903 | void Program::setUniformValuesFromBindingQualifiers() |
| 2904 | { |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 2905 | for (unsigned int samplerIndex : mState.mSamplerUniformRange) |
Olli Etuaho | 48fed63 | 2017-03-16 12:05:30 +0000 | [diff] [blame] | 2906 | { |
| 2907 | const auto &samplerUniform = mState.mUniforms[samplerIndex]; |
| 2908 | if (samplerUniform.binding != -1) |
| 2909 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 2910 | GLint location = getUniformLocation(samplerUniform.name); |
Olli Etuaho | 48fed63 | 2017-03-16 12:05:30 +0000 | [diff] [blame] | 2911 | ASSERT(location != -1); |
| 2912 | std::vector<GLint> boundTextureUnits; |
| 2913 | for (unsigned int elementIndex = 0; elementIndex < samplerUniform.elementCount(); |
| 2914 | ++elementIndex) |
| 2915 | { |
| 2916 | boundTextureUnits.push_back(samplerUniform.binding + elementIndex); |
| 2917 | } |
| 2918 | setUniform1iv(location, static_cast<GLsizei>(boundTextureUnits.size()), |
| 2919 | boundTextureUnits.data()); |
| 2920 | } |
| 2921 | } |
| 2922 | } |
| 2923 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2924 | void Program::gatherAtomicCounterBuffers() |
| 2925 | { |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 2926 | for (unsigned int index : mState.mAtomicCounterUniformRange) |
| 2927 | { |
| 2928 | auto &uniform = mState.mUniforms[index]; |
| 2929 | uniform.blockInfo.offset = uniform.offset; |
| 2930 | uniform.blockInfo.arrayStride = (uniform.isArray() ? 4 : 0); |
| 2931 | uniform.blockInfo.matrixStride = 0; |
| 2932 | uniform.blockInfo.isRowMajorMatrix = false; |
| 2933 | } |
| 2934 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2935 | // TODO(jie.a.chen@intel.com): Get the actual BUFFER_DATA_SIZE from backend for each buffer. |
| 2936 | } |
| 2937 | |
Jamie Madill | 6db1c2e | 2017-11-08 09:17:40 -0500 | [diff] [blame] | 2938 | void Program::initInterfaceBlockBindings() |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2939 | { |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 2940 | // Set initial bindings from shader. |
| 2941 | for (unsigned int blockIndex = 0; blockIndex < mState.mUniformBlocks.size(); blockIndex++) |
| 2942 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2943 | InterfaceBlock &uniformBlock = mState.mUniformBlocks[blockIndex]; |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 2944 | bindUniformBlock(blockIndex, uniformBlock.binding); |
| 2945 | } |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2946 | } |
| 2947 | |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 2948 | void Program::updateSamplerUniform(const VariableLocation &locationInfo, |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 2949 | GLsizei clampedCount, |
| 2950 | const GLint *v) |
| 2951 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2952 | ASSERT(mState.isSamplerUniformIndex(locationInfo.index)); |
| 2953 | GLuint samplerIndex = mState.getSamplerIndexFromUniformIndex(locationInfo.index); |
| 2954 | std::vector<GLuint> *boundTextureUnits = |
| 2955 | &mState.mSamplerBindings[samplerIndex].boundTextureUnits; |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 2956 | |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 2957 | std::copy(v, v + clampedCount, boundTextureUnits->begin() + locationInfo.arrayIndex); |
Jamie Madill | d68248b | 2017-09-11 14:34:14 -0400 | [diff] [blame] | 2958 | |
| 2959 | // Invalidate the validation cache. |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2960 | mCachedValidateSamplersResult.reset(); |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | template <typename T> |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2964 | GLsizei Program::clampUniformCount(const VariableLocation &locationInfo, |
| 2965 | GLsizei count, |
| 2966 | int vectorSize, |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 2967 | const T *v) |
| 2968 | { |
Jamie Madill | 134f93d | 2017-08-31 17:11:00 -0400 | [diff] [blame] | 2969 | if (count == 1) |
| 2970 | return 1; |
| 2971 | |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2972 | const LinkedUniform &linkedUniform = mState.mUniforms[locationInfo.index]; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2973 | |
Corentin Wallez | 15ac534 | 2016-11-03 17:06:39 -0400 | [diff] [blame] | 2974 | // OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array |
| 2975 | // element index used, as reported by GetActiveUniform, will be ignored by the GL." |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 2976 | unsigned int remainingElements = linkedUniform.elementCount() - locationInfo.arrayIndex; |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2977 | GLsizei maxElementCount = |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2978 | static_cast<GLsizei>(remainingElements * linkedUniform.getElementComponents()); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2979 | |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2980 | if (count * vectorSize > maxElementCount) |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2981 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2982 | return maxElementCount / vectorSize; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2983 | } |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2984 | |
| 2985 | return count; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | template <size_t cols, size_t rows, typename T> |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2989 | GLsizei Program::clampMatrixUniformCount(GLint location, |
| 2990 | GLsizei count, |
| 2991 | GLboolean transpose, |
| 2992 | const T *v) |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2993 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2994 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2995 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2996 | if (!transpose) |
| 2997 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2998 | return clampUniformCount(locationInfo, count, cols * rows, v); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2999 | } |
| 3000 | |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 3001 | const LinkedUniform &linkedUniform = mState.mUniforms[locationInfo.index]; |
Corentin Wallez | 15ac534 | 2016-11-03 17:06:39 -0400 | [diff] [blame] | 3002 | |
| 3003 | // OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array |
| 3004 | // element index used, as reported by GetActiveUniform, will be ignored by the GL." |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 3005 | unsigned int remainingElements = linkedUniform.elementCount() - locationInfo.arrayIndex; |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 3006 | return std::min(count, static_cast<GLsizei>(remainingElements)); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3007 | } |
| 3008 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 3009 | // Driver differences mean that doing the uniform value cast ourselves gives consistent results. |
| 3010 | // EG: on NVIDIA drivers, it was observed that getUniformi for MAX_INT+1 returned MIN_INT. |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3011 | template <typename DestT> |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 3012 | void Program::getUniformInternal(const Context *context, |
| 3013 | DestT *dataOut, |
| 3014 | GLint location, |
| 3015 | GLenum nativeType, |
| 3016 | int components) const |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3017 | { |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 3018 | switch (nativeType) |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3019 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3020 | case GL_BOOL: |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 3021 | { |
| 3022 | GLint tempValue[16] = {0}; |
| 3023 | mProgram->getUniformiv(context, location, tempValue); |
| 3024 | UniformStateQueryCastLoop<GLboolean>( |
| 3025 | dataOut, reinterpret_cast<const uint8_t *>(tempValue), components); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3026 | break; |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 3027 | } |
| 3028 | case GL_INT: |
| 3029 | { |
| 3030 | GLint tempValue[16] = {0}; |
| 3031 | mProgram->getUniformiv(context, location, tempValue); |
| 3032 | UniformStateQueryCastLoop<GLint>(dataOut, reinterpret_cast<const uint8_t *>(tempValue), |
| 3033 | components); |
| 3034 | break; |
| 3035 | } |
| 3036 | case GL_UNSIGNED_INT: |
| 3037 | { |
| 3038 | GLuint tempValue[16] = {0}; |
| 3039 | mProgram->getUniformuiv(context, location, tempValue); |
| 3040 | UniformStateQueryCastLoop<GLuint>(dataOut, reinterpret_cast<const uint8_t *>(tempValue), |
| 3041 | components); |
| 3042 | break; |
| 3043 | } |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3044 | case GL_FLOAT: |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 3045 | { |
| 3046 | GLfloat tempValue[16] = {0}; |
| 3047 | mProgram->getUniformfv(context, location, tempValue); |
| 3048 | UniformStateQueryCastLoop<GLfloat>( |
| 3049 | dataOut, reinterpret_cast<const uint8_t *>(tempValue), components); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3050 | break; |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 3051 | } |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3052 | default: |
| 3053 | UNREACHABLE(); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 3054 | break; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3055 | } |
| 3056 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 3057 | |
| 3058 | bool Program::samplesFromTexture(const gl::State &state, GLuint textureID) const |
| 3059 | { |
| 3060 | // Must be called after samplers are validated. |
| 3061 | ASSERT(mCachedValidateSamplersResult.valid() && mCachedValidateSamplersResult.value()); |
| 3062 | |
| 3063 | for (const auto &binding : mState.mSamplerBindings) |
| 3064 | { |
| 3065 | GLenum textureType = binding.textureType; |
| 3066 | for (const auto &unit : binding.boundTextureUnits) |
| 3067 | { |
| 3068 | GLenum programTextureID = state.getSamplerTextureId(unit, textureType); |
| 3069 | if (programTextureID == textureID) |
| 3070 | { |
| 3071 | // TODO(jmadill): Check for appropriate overlap. |
| 3072 | return true; |
| 3073 | } |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | return false; |
| 3078 | } |
| 3079 | |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 3080 | } // namespace gl |