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