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