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" |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 26 | #include "libANGLE/Version.h" |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 27 | #include "libANGLE/features.h" |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 28 | #include "libANGLE/histogram_macros.h" |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 29 | #include "libANGLE/queryconversions.h" |
| 30 | #include "libANGLE/renderer/GLImplFactory.h" |
| 31 | #include "libANGLE/renderer/ProgramImpl.h" |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 32 | #include "platform/Platform.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 33 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 34 | namespace gl |
| 35 | { |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 36 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 37 | namespace |
| 38 | { |
| 39 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 40 | // This simplified cast function doesn't need to worry about advanced concepts like |
| 41 | // depth range values, or casting to bool. |
| 42 | template <typename DestT, typename SrcT> |
| 43 | DestT UniformStateQueryCast(SrcT value); |
| 44 | |
| 45 | // From-Float-To-Integer Casts |
| 46 | template <> |
| 47 | GLint UniformStateQueryCast(GLfloat value) |
| 48 | { |
| 49 | return clampCast<GLint>(roundf(value)); |
| 50 | } |
| 51 | |
| 52 | template <> |
| 53 | GLuint UniformStateQueryCast(GLfloat value) |
| 54 | { |
| 55 | return clampCast<GLuint>(roundf(value)); |
| 56 | } |
| 57 | |
| 58 | // From-Integer-to-Integer Casts |
| 59 | template <> |
| 60 | GLint UniformStateQueryCast(GLuint value) |
| 61 | { |
| 62 | return clampCast<GLint>(value); |
| 63 | } |
| 64 | |
| 65 | template <> |
| 66 | GLuint UniformStateQueryCast(GLint value) |
| 67 | { |
| 68 | return clampCast<GLuint>(value); |
| 69 | } |
| 70 | |
| 71 | // From-Boolean-to-Anything Casts |
| 72 | template <> |
| 73 | GLfloat UniformStateQueryCast(GLboolean value) |
| 74 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 75 | return (ConvertToBool(value) ? 1.0f : 0.0f); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | template <> |
| 79 | GLint UniformStateQueryCast(GLboolean value) |
| 80 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 81 | return (ConvertToBool(value) ? 1 : 0); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | template <> |
| 85 | GLuint UniformStateQueryCast(GLboolean value) |
| 86 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 87 | return (ConvertToBool(value) ? 1u : 0u); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | // Default to static_cast |
| 91 | template <typename DestT, typename SrcT> |
| 92 | DestT UniformStateQueryCast(SrcT value) |
| 93 | { |
| 94 | return static_cast<DestT>(value); |
| 95 | } |
| 96 | |
| 97 | template <typename SrcT, typename DestT> |
| 98 | void UniformStateQueryCastLoop(DestT *dataOut, const uint8_t *srcPointer, int components) |
| 99 | { |
| 100 | for (int comp = 0; comp < components; ++comp) |
| 101 | { |
| 102 | // We only work with strides of 4 bytes for uniform components. (GLfloat/GLint) |
| 103 | // Don't use SrcT stride directly since GLboolean has a stride of 1 byte. |
| 104 | size_t offset = comp * 4; |
| 105 | const SrcT *typedSrcPointer = reinterpret_cast<const SrcT *>(&srcPointer[offset]); |
| 106 | dataOut[comp] = UniformStateQueryCast<DestT>(*typedSrcPointer); |
| 107 | } |
| 108 | } |
| 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 | |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 209 | std::string GetInterfaceBlockLimitName(ShaderType shaderType, sh::BlockType blockType) |
| 210 | { |
| 211 | std::ostringstream stream; |
| 212 | stream << "GL_MAX_" << GetShaderTypeString(shaderType) << "_"; |
| 213 | |
| 214 | switch (blockType) |
| 215 | { |
| 216 | case sh::BlockType::BLOCK_UNIFORM: |
| 217 | stream << "UNIFORM_BUFFERS"; |
| 218 | break; |
| 219 | case sh::BlockType::BLOCK_BUFFER: |
| 220 | stream << "SHADER_STORAGE_BLOCKS"; |
| 221 | break; |
| 222 | default: |
| 223 | UNREACHABLE(); |
| 224 | return ""; |
| 225 | } |
| 226 | |
| 227 | if (shaderType == ShaderType::Geometry) |
| 228 | { |
| 229 | stream << "_EXT"; |
| 230 | } |
| 231 | |
| 232 | return stream.str(); |
| 233 | } |
| 234 | |
| 235 | const char *GetInterfaceBlockTypeString(sh::BlockType blockType) |
| 236 | { |
| 237 | switch (blockType) |
| 238 | { |
| 239 | case sh::BlockType::BLOCK_UNIFORM: |
| 240 | return "uniform block"; |
| 241 | case sh::BlockType::BLOCK_BUFFER: |
| 242 | return "shader storage block"; |
| 243 | default: |
| 244 | UNREACHABLE(); |
| 245 | return ""; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | void LogInterfaceBlocksExceedLimit(InfoLog &infoLog, |
| 250 | ShaderType shaderType, |
| 251 | sh::BlockType blockType, |
| 252 | GLuint limit) |
| 253 | { |
| 254 | infoLog << GetShaderTypeString(shaderType) << " shader " |
| 255 | << GetInterfaceBlockTypeString(blockType) << " count exceeds " |
| 256 | << GetInterfaceBlockLimitName(shaderType, blockType) << " (" << limit << ")"; |
| 257 | } |
| 258 | |
Jiawei Shao | 427071e | 2018-03-19 09:21:37 +0800 | [diff] [blame] | 259 | bool ValidateInterfaceBlocksCount(GLuint maxInterfaceBlocks, |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 260 | const std::vector<sh::InterfaceBlock> &interfaceBlocks, |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 261 | ShaderType shaderType, |
| 262 | sh::BlockType blockType, |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 263 | GLuint *combinedInterfaceBlocksCount, |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 264 | InfoLog &infoLog) |
| 265 | { |
| 266 | GLuint blockCount = 0; |
| 267 | for (const sh::InterfaceBlock &block : interfaceBlocks) |
| 268 | { |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 269 | if (IsActiveInterfaceBlock(block)) |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 270 | { |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 271 | blockCount += std::max(block.arraySize, 1u); |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 272 | if (blockCount > maxInterfaceBlocks) |
| 273 | { |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 274 | LogInterfaceBlocksExceedLimit(infoLog, shaderType, blockType, maxInterfaceBlocks); |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 275 | return false; |
| 276 | } |
| 277 | } |
| 278 | } |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 279 | |
| 280 | // [OpenGL ES 3.1] Chapter 7.6.2 Page 105: |
| 281 | // If a uniform block is used by multiple shader stages, each such use counts separately |
| 282 | // against this combined limit. |
| 283 | // [OpenGL ES 3.1] Chapter 7.8 Page 111: |
| 284 | // If a shader storage block in a program is referenced by multiple shaders, each such |
| 285 | // reference counts separately against this combined limit. |
| 286 | if (combinedInterfaceBlocksCount) |
| 287 | { |
| 288 | *combinedInterfaceBlocksCount += blockCount; |
| 289 | } |
| 290 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 291 | return true; |
| 292 | } |
| 293 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 294 | GLuint GetInterfaceBlockIndex(const std::vector<InterfaceBlock> &list, const std::string &name) |
| 295 | { |
| 296 | std::vector<unsigned int> subscripts; |
| 297 | std::string baseName = ParseResourceName(name, &subscripts); |
| 298 | |
| 299 | unsigned int numBlocks = static_cast<unsigned int>(list.size()); |
| 300 | for (unsigned int blockIndex = 0; blockIndex < numBlocks; blockIndex++) |
| 301 | { |
| 302 | const auto &block = list[blockIndex]; |
| 303 | if (block.name == baseName) |
| 304 | { |
| 305 | const bool arrayElementZero = |
| 306 | (subscripts.empty() && (!block.isArray || block.arrayElement == 0)); |
| 307 | const bool arrayElementMatches = |
| 308 | (subscripts.size() == 1 && subscripts[0] == block.arrayElement); |
| 309 | if (arrayElementMatches || arrayElementZero) |
| 310 | { |
| 311 | return blockIndex; |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | return GL_INVALID_INDEX; |
| 317 | } |
| 318 | |
| 319 | void GetInterfaceBlockName(const GLuint index, |
| 320 | const std::vector<InterfaceBlock> &list, |
| 321 | GLsizei bufSize, |
| 322 | GLsizei *length, |
| 323 | GLchar *name) |
| 324 | { |
| 325 | ASSERT(index < list.size()); |
| 326 | |
| 327 | const auto &block = list[index]; |
| 328 | |
| 329 | if (bufSize > 0) |
| 330 | { |
| 331 | std::string blockName = block.name; |
| 332 | |
| 333 | if (block.isArray) |
| 334 | { |
| 335 | blockName += ArrayString(block.arrayElement); |
| 336 | } |
| 337 | CopyStringToBuffer(name, blockName, bufSize, length); |
| 338 | } |
| 339 | } |
| 340 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 341 | void InitUniformBlockLinker(const ProgramState &state, UniformBlockLinker *blockLinker) |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 342 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 343 | for (ShaderType shaderType : AllShaderTypes()) |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 344 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 345 | Shader *shader = state.getAttachedShader(shaderType); |
| 346 | if (shader) |
| 347 | { |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 348 | blockLinker->addShaderBlocks(shaderType, &shader->getUniformBlocks()); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 349 | } |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 353 | void InitShaderStorageBlockLinker(const ProgramState &state, ShaderStorageBlockLinker *blockLinker) |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 354 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 355 | for (ShaderType shaderType : AllShaderTypes()) |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 356 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 357 | Shader *shader = state.getAttachedShader(shaderType); |
| 358 | if (shader != nullptr) |
| 359 | { |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 360 | blockLinker->addShaderBlocks(shaderType, &shader->getShaderStorageBlocks()); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 361 | } |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
jchen10 | 8225e73 | 2017-11-14 16:29:03 +0800 | [diff] [blame] | 365 | // Find the matching varying or field by name. |
| 366 | const sh::ShaderVariable *FindVaryingOrField(const ProgramMergedVaryings &varyings, |
| 367 | const std::string &name) |
| 368 | { |
| 369 | const sh::ShaderVariable *var = nullptr; |
| 370 | for (const auto &ref : varyings) |
| 371 | { |
| 372 | const sh::Varying *varying = ref.second.get(); |
| 373 | if (varying->name == name) |
| 374 | { |
| 375 | var = varying; |
| 376 | break; |
| 377 | } |
| 378 | var = FindShaderVarField(*varying, name); |
| 379 | if (var != nullptr) |
| 380 | { |
| 381 | break; |
| 382 | } |
| 383 | } |
| 384 | return var; |
| 385 | } |
| 386 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 387 | void AddParentPrefix(const std::string &parentName, std::string *mismatchedFieldName) |
| 388 | { |
| 389 | ASSERT(mismatchedFieldName); |
| 390 | if (mismatchedFieldName->empty()) |
| 391 | { |
| 392 | *mismatchedFieldName = parentName; |
| 393 | } |
| 394 | else |
| 395 | { |
| 396 | std::ostringstream stream; |
| 397 | stream << parentName << "." << *mismatchedFieldName; |
| 398 | *mismatchedFieldName = stream.str(); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | const char *GetLinkMismatchErrorString(LinkMismatchError linkError) |
| 403 | { |
| 404 | switch (linkError) |
| 405 | { |
| 406 | case LinkMismatchError::TYPE_MISMATCH: |
| 407 | return "Type"; |
| 408 | case LinkMismatchError::ARRAY_SIZE_MISMATCH: |
| 409 | return "Array size"; |
| 410 | case LinkMismatchError::PRECISION_MISMATCH: |
| 411 | return "Precision"; |
| 412 | case LinkMismatchError::STRUCT_NAME_MISMATCH: |
| 413 | return "Structure name"; |
| 414 | case LinkMismatchError::FIELD_NUMBER_MISMATCH: |
| 415 | return "Field number"; |
| 416 | case LinkMismatchError::FIELD_NAME_MISMATCH: |
| 417 | return "Field name"; |
| 418 | |
| 419 | case LinkMismatchError::INTERPOLATION_TYPE_MISMATCH: |
| 420 | return "Interpolation type"; |
| 421 | case LinkMismatchError::INVARIANCE_MISMATCH: |
| 422 | return "Invariance"; |
| 423 | |
| 424 | case LinkMismatchError::BINDING_MISMATCH: |
| 425 | return "Binding layout qualifier"; |
| 426 | case LinkMismatchError::LOCATION_MISMATCH: |
| 427 | return "Location layout qualifier"; |
| 428 | case LinkMismatchError::OFFSET_MISMATCH: |
| 429 | return "Offset layout qualilfier"; |
| 430 | |
| 431 | case LinkMismatchError::LAYOUT_QUALIFIER_MISMATCH: |
| 432 | return "Layout qualifier"; |
| 433 | case LinkMismatchError::MATRIX_PACKING_MISMATCH: |
| 434 | return "Matrix Packing"; |
| 435 | default: |
| 436 | UNREACHABLE(); |
| 437 | return ""; |
| 438 | } |
| 439 | } |
| 440 | |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 441 | LinkMismatchError LinkValidateInterfaceBlockFields(const sh::InterfaceBlockField &blockField1, |
| 442 | const sh::InterfaceBlockField &blockField2, |
| 443 | bool webglCompatibility, |
| 444 | std::string *mismatchedBlockFieldName) |
| 445 | { |
| 446 | if (blockField1.name != blockField2.name) |
| 447 | { |
| 448 | return LinkMismatchError::FIELD_NAME_MISMATCH; |
| 449 | } |
| 450 | |
| 451 | // If webgl, validate precision of UBO fields, otherwise don't. See Khronos bug 10287. |
| 452 | LinkMismatchError linkError = Program::LinkValidateVariablesBase( |
| 453 | blockField1, blockField2, webglCompatibility, true, mismatchedBlockFieldName); |
| 454 | if (linkError != LinkMismatchError::NO_MISMATCH) |
| 455 | { |
| 456 | AddParentPrefix(blockField1.name, mismatchedBlockFieldName); |
| 457 | return linkError; |
| 458 | } |
| 459 | |
| 460 | if (blockField1.isRowMajorLayout != blockField2.isRowMajorLayout) |
| 461 | { |
| 462 | AddParentPrefix(blockField1.name, mismatchedBlockFieldName); |
| 463 | return LinkMismatchError::MATRIX_PACKING_MISMATCH; |
| 464 | } |
| 465 | |
| 466 | return LinkMismatchError::NO_MISMATCH; |
| 467 | } |
| 468 | |
| 469 | LinkMismatchError AreMatchingInterfaceBlocks(const sh::InterfaceBlock &interfaceBlock1, |
| 470 | const sh::InterfaceBlock &interfaceBlock2, |
| 471 | bool webglCompatibility, |
| 472 | std::string *mismatchedBlockFieldName) |
| 473 | { |
| 474 | // validate blocks for the same member types |
| 475 | if (interfaceBlock1.fields.size() != interfaceBlock2.fields.size()) |
| 476 | { |
| 477 | return LinkMismatchError::FIELD_NUMBER_MISMATCH; |
| 478 | } |
| 479 | if (interfaceBlock1.arraySize != interfaceBlock2.arraySize) |
| 480 | { |
| 481 | return LinkMismatchError::ARRAY_SIZE_MISMATCH; |
| 482 | } |
| 483 | if (interfaceBlock1.layout != interfaceBlock2.layout || |
| 484 | interfaceBlock1.binding != interfaceBlock2.binding) |
| 485 | { |
| 486 | return LinkMismatchError::LAYOUT_QUALIFIER_MISMATCH; |
| 487 | } |
| 488 | const unsigned int numBlockMembers = static_cast<unsigned int>(interfaceBlock1.fields.size()); |
| 489 | for (unsigned int blockMemberIndex = 0; blockMemberIndex < numBlockMembers; blockMemberIndex++) |
| 490 | { |
| 491 | const sh::InterfaceBlockField &member1 = interfaceBlock1.fields[blockMemberIndex]; |
| 492 | const sh::InterfaceBlockField &member2 = interfaceBlock2.fields[blockMemberIndex]; |
| 493 | |
| 494 | LinkMismatchError linkError = LinkValidateInterfaceBlockFields( |
| 495 | member1, member2, webglCompatibility, mismatchedBlockFieldName); |
| 496 | if (linkError != LinkMismatchError::NO_MISMATCH) |
| 497 | { |
| 498 | return linkError; |
| 499 | } |
| 500 | } |
| 501 | return LinkMismatchError::NO_MISMATCH; |
| 502 | } |
| 503 | |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 504 | using ShaderInterfaceBlock = std::pair<ShaderType, const sh::InterfaceBlock *>; |
| 505 | using InterfaceBlockMap = std::map<std::string, ShaderInterfaceBlock>; |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 506 | |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 507 | void InitializeInterfaceBlockMap(const std::vector<sh::InterfaceBlock> &interfaceBlocks, |
| 508 | ShaderType shaderType, |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 509 | InterfaceBlockMap *linkedInterfaceBlocks) |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 510 | { |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 511 | ASSERT(linkedInterfaceBlocks); |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 512 | |
| 513 | for (const sh::InterfaceBlock &interfaceBlock : interfaceBlocks) |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 514 | { |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 515 | (*linkedInterfaceBlocks)[interfaceBlock.name] = std::make_pair(shaderType, &interfaceBlock); |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 516 | } |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 517 | } |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 518 | |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 519 | bool ValidateGraphicsInterfaceBlocksPerShader( |
| 520 | const std::vector<sh::InterfaceBlock> &interfaceBlocksToLink, |
| 521 | ShaderType shaderType, |
| 522 | bool webglCompatibility, |
| 523 | InterfaceBlockMap *linkedBlocks, |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 524 | InfoLog &infoLog) |
| 525 | { |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 526 | ASSERT(linkedBlocks); |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 527 | |
| 528 | for (const sh::InterfaceBlock &block : interfaceBlocksToLink) |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 529 | { |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 530 | const auto &entry = linkedBlocks->find(block.name); |
| 531 | if (entry != linkedBlocks->end()) |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 532 | { |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 533 | const sh::InterfaceBlock &linkedBlock = *(entry->second.second); |
| 534 | std::string mismatchedStructFieldName; |
| 535 | LinkMismatchError linkError = AreMatchingInterfaceBlocks( |
| 536 | block, linkedBlock, webglCompatibility, &mismatchedStructFieldName); |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 537 | if (linkError != LinkMismatchError::NO_MISMATCH) |
| 538 | { |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 539 | LogLinkMismatch(infoLog, block.name, GetInterfaceBlockTypeString(block.blockType), |
| 540 | linkError, mismatchedStructFieldName, entry->second.first, |
| 541 | shaderType); |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 542 | return false; |
| 543 | } |
| 544 | } |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 545 | else |
| 546 | { |
| 547 | (*linkedBlocks)[block.name] = std::make_pair(shaderType, &block); |
| 548 | } |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | return true; |
| 552 | } |
| 553 | |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 554 | bool ValidateInterfaceBlocksMatch( |
| 555 | GLuint numShadersHasInterfaceBlocks, |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 556 | const ShaderMap<const std::vector<sh::InterfaceBlock> *> &shaderInterfaceBlocks, |
| 557 | InfoLog &infoLog, |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 558 | bool webglCompatibility) |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 559 | { |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 560 | if (numShadersHasInterfaceBlocks < 2u) |
| 561 | { |
| 562 | return true; |
| 563 | } |
| 564 | |
| 565 | ASSERT(!shaderInterfaceBlocks[ShaderType::Compute]); |
| 566 | |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 567 | // Check that interface blocks defined in the graphics shaders are identical |
| 568 | |
| 569 | InterfaceBlockMap linkedInterfaceBlocks; |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 570 | |
| 571 | bool interfaceBlockMapInitialized = false; |
| 572 | for (ShaderType shaderType : kAllGraphicsShaderTypes) |
| 573 | { |
| 574 | if (!shaderInterfaceBlocks[shaderType]) |
| 575 | { |
| 576 | continue; |
| 577 | } |
| 578 | |
| 579 | if (!interfaceBlockMapInitialized) |
| 580 | { |
| 581 | InitializeInterfaceBlockMap(*shaderInterfaceBlocks[shaderType], shaderType, |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 582 | &linkedInterfaceBlocks); |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 583 | interfaceBlockMapInitialized = true; |
| 584 | } |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 585 | else if (!ValidateGraphicsInterfaceBlocksPerShader(*shaderInterfaceBlocks[shaderType], |
| 586 | shaderType, webglCompatibility, |
| 587 | &linkedInterfaceBlocks, infoLog)) |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 588 | { |
| 589 | return false; |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 593 | return true; |
| 594 | } |
| 595 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 596 | } // anonymous namespace |
| 597 | |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 598 | // Saves the linking context for later use in resolveLink(). |
| 599 | struct Program::LinkingState |
| 600 | { |
| 601 | const Context *context; |
| 602 | std::unique_ptr<ProgramLinkedResources> resources; |
Shahbaz Youssefi | 9137ade | 2018-08-27 14:22:37 -0400 | [diff] [blame] | 603 | egl::BlobCache::Key programHash; |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 604 | std::unique_ptr<rx::LinkEvent> linkEvent; |
| 605 | }; |
| 606 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 607 | const char *const g_fakepath = "C:\\fakepath"; |
| 608 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 609 | // InfoLog implementation. |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 610 | InfoLog::InfoLog() |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 611 | { |
| 612 | } |
| 613 | |
| 614 | InfoLog::~InfoLog() |
| 615 | { |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 618 | size_t InfoLog::getLength() const |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 619 | { |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 620 | if (!mLazyStream) |
| 621 | { |
| 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | const std::string &logString = mLazyStream->str(); |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 626 | return logString.empty() ? 0 : logString.length() + 1; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 629 | void InfoLog::getLog(GLsizei bufSize, GLsizei *length, char *infoLog) const |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 630 | { |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 631 | size_t index = 0; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 632 | |
| 633 | if (bufSize > 0) |
| 634 | { |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 635 | const std::string logString(str()); |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 636 | |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 637 | if (!logString.empty()) |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 638 | { |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 639 | index = std::min(static_cast<size_t>(bufSize) - 1, logString.length()); |
| 640 | memcpy(infoLog, logString.c_str(), index); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | infoLog[index] = '\0'; |
| 644 | } |
| 645 | |
| 646 | if (length) |
| 647 | { |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 648 | *length = static_cast<GLsizei>(index); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
| 652 | // append a santized message to the program info log. |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 653 | // 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] | 654 | // messages, so lets remove all occurrences of this fake file path from the log. |
| 655 | void InfoLog::appendSanitized(const char *message) |
| 656 | { |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 657 | ensureInitialized(); |
| 658 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 659 | std::string msg(message); |
| 660 | |
| 661 | size_t found; |
| 662 | do |
| 663 | { |
| 664 | found = msg.find(g_fakepath); |
| 665 | if (found != std::string::npos) |
| 666 | { |
| 667 | msg.erase(found, strlen(g_fakepath)); |
| 668 | } |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 669 | } while (found != std::string::npos); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 670 | |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 671 | *mLazyStream << message << std::endl; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 672 | } |
| 673 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 674 | void InfoLog::reset() |
| 675 | { |
Jiawei Shao | 02f1523 | 2017-12-27 10:10:28 +0800 | [diff] [blame] | 676 | if (mLazyStream) |
| 677 | { |
| 678 | mLazyStream.reset(nullptr); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | bool InfoLog::empty() const |
| 683 | { |
| 684 | if (!mLazyStream) |
| 685 | { |
| 686 | return true; |
| 687 | } |
| 688 | |
| 689 | return mLazyStream->rdbuf()->in_avail() == 0; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 692 | void LogLinkMismatch(InfoLog &infoLog, |
| 693 | const std::string &variableName, |
| 694 | const char *variableType, |
| 695 | LinkMismatchError linkError, |
| 696 | const std::string &mismatchedStructOrBlockFieldName, |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 697 | ShaderType shaderType1, |
| 698 | ShaderType shaderType2) |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 699 | { |
| 700 | std::ostringstream stream; |
| 701 | stream << GetLinkMismatchErrorString(linkError) << "s of " << variableType << " '" |
| 702 | << variableName; |
| 703 | |
| 704 | if (!mismatchedStructOrBlockFieldName.empty()) |
| 705 | { |
| 706 | stream << "' member '" << variableName << "." << mismatchedStructOrBlockFieldName; |
| 707 | } |
| 708 | |
| 709 | stream << "' differ between " << GetShaderTypeString(shaderType1) << " and " |
| 710 | << GetShaderTypeString(shaderType2) << " shaders."; |
| 711 | |
| 712 | infoLog << stream.str(); |
| 713 | } |
| 714 | |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 715 | bool IsActiveInterfaceBlock(const sh::InterfaceBlock &interfaceBlock) |
| 716 | { |
| 717 | // Only 'packed' blocks are allowed to be considered inactive. |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 718 | return interfaceBlock.active || interfaceBlock.layout != sh::BLOCKLAYOUT_PACKED; |
Jiawei Shao | 1c08cbb | 2018-03-15 15:11:56 +0800 | [diff] [blame] | 719 | } |
| 720 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 721 | // VariableLocation implementation. |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 722 | VariableLocation::VariableLocation() : arrayIndex(0), index(kUnused), ignored(false) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 723 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 724 | } |
| 725 | |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 726 | VariableLocation::VariableLocation(unsigned int arrayIndex, unsigned int index) |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 727 | : arrayIndex(arrayIndex), index(index), ignored(false) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 728 | { |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 729 | ASSERT(arrayIndex != GL_INVALID_INDEX); |
| 730 | } |
| 731 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 732 | // SamplerBindings implementation. |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 733 | SamplerBinding::SamplerBinding(TextureType textureTypeIn, size_t elementCount, bool unreferenced) |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 734 | : textureType(textureTypeIn), boundTextureUnits(elementCount, 0), unreferenced(unreferenced) |
| 735 | { |
| 736 | } |
| 737 | |
| 738 | SamplerBinding::SamplerBinding(const SamplerBinding &other) = default; |
| 739 | |
| 740 | SamplerBinding::~SamplerBinding() = default; |
| 741 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 742 | // ProgramBindings implementation. |
| 743 | ProgramBindings::ProgramBindings() |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 744 | { |
| 745 | } |
| 746 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 747 | ProgramBindings::~ProgramBindings() |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 748 | { |
| 749 | } |
| 750 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 751 | void ProgramBindings::bindLocation(GLuint index, const std::string &name) |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 752 | { |
| 753 | mBindings[name] = index; |
| 754 | } |
| 755 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 756 | int ProgramBindings::getBinding(const std::string &name) const |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 757 | { |
| 758 | auto iter = mBindings.find(name); |
| 759 | return (iter != mBindings.end()) ? iter->second : -1; |
| 760 | } |
| 761 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 762 | ProgramBindings::const_iterator ProgramBindings::begin() const |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 763 | { |
| 764 | return mBindings.begin(); |
| 765 | } |
| 766 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 767 | ProgramBindings::const_iterator ProgramBindings::end() const |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 768 | { |
| 769 | return mBindings.end(); |
| 770 | } |
| 771 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 772 | // ImageBinding implementation. |
Qin Jiajia | 47f6dd0 | 2018-08-10 13:36:32 +0800 | [diff] [blame] | 773 | ImageBinding::ImageBinding(size_t count) : boundImageUnits(count, 0), unreferenced(false) |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 774 | { |
| 775 | } |
Qin Jiajia | 47f6dd0 | 2018-08-10 13:36:32 +0800 | [diff] [blame] | 776 | ImageBinding::ImageBinding(GLuint imageUnit, size_t count, bool unreferenced) |
| 777 | : unreferenced(unreferenced) |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 778 | { |
| 779 | for (size_t index = 0; index < count; ++index) |
| 780 | { |
| 781 | boundImageUnits.push_back(imageUnit + static_cast<GLuint>(index)); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | ImageBinding::ImageBinding(const ImageBinding &other) = default; |
| 786 | |
| 787 | ImageBinding::~ImageBinding() = default; |
| 788 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 789 | // ProgramState implementation. |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 790 | ProgramState::ProgramState() |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 791 | : mLabel(), |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 792 | mAttachedShaders({}), |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 793 | mTransformFeedbackBufferMode(GL_INTERLEAVED_ATTRIBS), |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 794 | mMaxActiveAttribLocation(0), |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 795 | mSamplerUniformRange(0, 0), |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 796 | mImageUniformRange(0, 0), |
| 797 | mAtomicCounterUniformRange(0, 0), |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 798 | mBinaryRetrieveableHint(false), |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 799 | mNumViews(-1), |
| 800 | // [GL_EXT_geometry_shader] Table 20.22 |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 801 | mGeometryShaderInputPrimitiveType(PrimitiveMode::Triangles), |
| 802 | mGeometryShaderOutputPrimitiveType(PrimitiveMode::TriangleStrip), |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 803 | mGeometryShaderInvocations(1), |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 804 | mGeometryShaderMaxVertices(0), |
| 805 | mActiveSamplerRefCounts{} |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 806 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 807 | mComputeShaderLocalSize.fill(1); |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 808 | mActiveSamplerTypes.fill(TextureType::InvalidEnum); |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 809 | } |
| 810 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 811 | ProgramState::~ProgramState() |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 812 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 813 | ASSERT(!hasAttachedShader()); |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 814 | } |
| 815 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 816 | const std::string &ProgramState::getLabel() |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 817 | { |
| 818 | return mLabel; |
| 819 | } |
| 820 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 821 | Shader *ProgramState::getAttachedShader(ShaderType shaderType) const |
| 822 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 823 | ASSERT(shaderType != ShaderType::InvalidEnum); |
| 824 | return mAttachedShaders[shaderType]; |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 825 | } |
| 826 | |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 827 | GLuint ProgramState::getUniformIndexFromName(const std::string &name) const |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 828 | { |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 829 | return GetResourceIndexFromName(mUniforms, name); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 830 | } |
| 831 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 832 | GLuint ProgramState::getBufferVariableIndexFromName(const std::string &name) const |
| 833 | { |
| 834 | return GetResourceIndexFromName(mBufferVariables, name); |
| 835 | } |
| 836 | |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 837 | GLuint ProgramState::getUniformIndexFromLocation(GLint location) const |
| 838 | { |
| 839 | ASSERT(location >= 0 && static_cast<size_t>(location) < mUniformLocations.size()); |
| 840 | return mUniformLocations[location].index; |
| 841 | } |
| 842 | |
| 843 | Optional<GLuint> ProgramState::getSamplerIndex(GLint location) const |
| 844 | { |
| 845 | GLuint index = getUniformIndexFromLocation(location); |
| 846 | if (!isSamplerUniformIndex(index)) |
| 847 | { |
| 848 | return Optional<GLuint>::Invalid(); |
| 849 | } |
| 850 | |
| 851 | return getSamplerIndexFromUniformIndex(index); |
| 852 | } |
| 853 | |
| 854 | bool ProgramState::isSamplerUniformIndex(GLuint index) const |
| 855 | { |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 856 | return mSamplerUniformRange.contains(index); |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | GLuint ProgramState::getSamplerIndexFromUniformIndex(GLuint uniformIndex) const |
| 860 | { |
| 861 | ASSERT(isSamplerUniformIndex(uniformIndex)); |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 862 | return uniformIndex - mSamplerUniformRange.low(); |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 863 | } |
| 864 | |
Qin Jiajia | 47f6dd0 | 2018-08-10 13:36:32 +0800 | [diff] [blame] | 865 | bool ProgramState::isImageUniformIndex(GLuint index) const |
| 866 | { |
| 867 | return mImageUniformRange.contains(index); |
| 868 | } |
| 869 | |
| 870 | GLuint ProgramState::getImageIndexFromUniformIndex(GLuint uniformIndex) const |
| 871 | { |
| 872 | ASSERT(isImageUniformIndex(uniformIndex)); |
| 873 | return uniformIndex - mImageUniformRange.low(); |
| 874 | } |
| 875 | |
Jamie Madill | 34ca4f5 | 2017-06-13 11:49:39 -0400 | [diff] [blame] | 876 | GLuint ProgramState::getAttributeLocation(const std::string &name) const |
| 877 | { |
| 878 | for (const sh::Attribute &attribute : mAttributes) |
| 879 | { |
| 880 | if (attribute.name == name) |
| 881 | { |
| 882 | return attribute.location; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | return static_cast<GLuint>(-1); |
| 887 | } |
| 888 | |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 889 | bool ProgramState::hasAttachedShader() const |
| 890 | { |
| 891 | for (const Shader *shader : mAttachedShaders) |
| 892 | { |
| 893 | if (shader) |
| 894 | { |
| 895 | return true; |
| 896 | } |
| 897 | } |
| 898 | return false; |
| 899 | } |
| 900 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 901 | Program::Program(rx::GLImplFactory *factory, ShaderProgramManager *manager, GLuint handle) |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 902 | : mProgram(factory->createProgram(mState)), |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 903 | mValidated(false), |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 904 | mLinked(false), |
jchen10 | 5055fba | 2018-08-17 09:57:07 +0800 | [diff] [blame] | 905 | mLinkResolved(true), |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 906 | mDeleteStatus(false), |
| 907 | mRefCount(0), |
| 908 | mResourceManager(manager), |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 909 | mHandle(handle) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 910 | { |
| 911 | ASSERT(mProgram); |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 912 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 913 | unlink(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | Program::~Program() |
| 917 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 918 | ASSERT(!mProgram); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 921 | void Program::onDestroy(const Context *context) |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 922 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 923 | ASSERT(mLinkResolved); |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 924 | for (ShaderType shaderType : AllShaderTypes()) |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 925 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 926 | if (mState.mAttachedShaders[shaderType]) |
| 927 | { |
| 928 | mState.mAttachedShaders[shaderType]->release(context); |
| 929 | mState.mAttachedShaders[shaderType] = nullptr; |
| 930 | } |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 931 | } |
| 932 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 933 | // TODO(jmadill): Handle error in the Context. http://anglebug.com/2491 |
Jamie Madill | b7d924a | 2018-03-10 11:16:54 -0500 | [diff] [blame] | 934 | ANGLE_SWALLOW_ERR(mProgram->destroy(context)); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 935 | |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 936 | ASSERT(!mState.hasAttachedShader()); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 937 | SafeDelete(mProgram); |
| 938 | |
| 939 | delete this; |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 940 | } |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 941 | GLuint Program::id() const |
| 942 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 943 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 944 | return mHandle; |
| 945 | } |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 946 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 947 | void Program::setLabel(const std::string &label) |
| 948 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 949 | ASSERT(mLinkResolved); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 950 | mState.mLabel = label; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | const std::string &Program::getLabel() const |
| 954 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 955 | ASSERT(mLinkResolved); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 956 | return mState.mLabel; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 957 | } |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 958 | rx::ProgramImpl *Program::getImplementation() const |
| 959 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 960 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 961 | return mProgram; |
| 962 | } |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 963 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 964 | void Program::attachShader(Shader *shader) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 965 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 966 | ASSERT(mLinkResolved); |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 967 | ShaderType shaderType = shader->getType(); |
| 968 | ASSERT(shaderType != ShaderType::InvalidEnum); |
| 969 | |
| 970 | mState.mAttachedShaders[shaderType] = shader; |
| 971 | mState.mAttachedShaders[shaderType]->addRef(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 974 | void Program::detachShader(const Context *context, Shader *shader) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 975 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 976 | ASSERT(mLinkResolved); |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 977 | ShaderType shaderType = shader->getType(); |
| 978 | ASSERT(shaderType != ShaderType::InvalidEnum); |
| 979 | |
| 980 | ASSERT(mState.mAttachedShaders[shaderType] == shader); |
| 981 | shader->release(context); |
| 982 | mState.mAttachedShaders[shaderType] = nullptr; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 983 | } |
| 984 | |
daniel@transgaming.com | cba5057 | 2010-03-28 19:36:09 +0000 | [diff] [blame] | 985 | int Program::getAttachedShadersCount() const |
| 986 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 987 | ASSERT(mLinkResolved); |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 988 | int numAttachedShaders = 0; |
| 989 | for (const Shader *shader : mState.mAttachedShaders) |
| 990 | { |
| 991 | if (shader) |
| 992 | { |
| 993 | ++numAttachedShaders; |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | return numAttachedShaders; |
daniel@transgaming.com | cba5057 | 2010-03-28 19:36:09 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 1000 | const Shader *Program::getAttachedShader(ShaderType shaderType) const |
| 1001 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1002 | ASSERT(mLinkResolved); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 1003 | return mState.getAttachedShader(shaderType); |
| 1004 | } |
| 1005 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1006 | void Program::bindAttributeLocation(GLuint index, const char *name) |
| 1007 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1008 | ASSERT(mLinkResolved); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 1009 | mAttributeBindings.bindLocation(index, name); |
| 1010 | } |
| 1011 | |
| 1012 | void Program::bindUniformLocation(GLuint index, const char *name) |
| 1013 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1014 | ASSERT(mLinkResolved); |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 1015 | mUniformLocationBindings.bindLocation(index, name); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1018 | void Program::bindFragmentInputLocation(GLint index, const char *name) |
| 1019 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1020 | ASSERT(mLinkResolved); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1021 | mFragmentInputBindings.bindLocation(index, name); |
| 1022 | } |
| 1023 | |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 1024 | void Program::bindFragmentOutputLocation(GLuint index, const char *name) |
| 1025 | { |
| 1026 | mFragmentOutputLocations.bindLocation(index, name); |
| 1027 | } |
| 1028 | |
| 1029 | void Program::bindFragmentOutputIndex(GLuint index, const char *name) |
| 1030 | { |
| 1031 | mFragmentOutputIndexes.bindLocation(index, name); |
| 1032 | } |
| 1033 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1034 | BindingInfo Program::getFragmentInputBindingInfo(GLint index) const |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1035 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1036 | ASSERT(mLinkResolved); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1037 | BindingInfo ret; |
| 1038 | ret.type = GL_NONE; |
| 1039 | ret.valid = false; |
| 1040 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 1041 | Shader *fragmentShader = mState.getAttachedShader(ShaderType::Fragment); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1042 | ASSERT(fragmentShader); |
| 1043 | |
| 1044 | // Find the actual fragment shader varying we're interested in |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1045 | const std::vector<sh::Varying> &inputs = fragmentShader->getInputVaryings(); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1046 | |
| 1047 | for (const auto &binding : mFragmentInputBindings) |
| 1048 | { |
| 1049 | if (binding.second != static_cast<GLuint>(index)) |
| 1050 | continue; |
| 1051 | |
| 1052 | ret.valid = true; |
| 1053 | |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 1054 | size_t nameLengthWithoutArrayIndex; |
| 1055 | unsigned int arrayIndex = ParseArrayIndex(binding.first, &nameLengthWithoutArrayIndex); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1056 | |
| 1057 | for (const auto &in : inputs) |
| 1058 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 1059 | if (in.name.length() == nameLengthWithoutArrayIndex && |
| 1060 | angle::BeginsWith(in.name, binding.first, nameLengthWithoutArrayIndex)) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1061 | { |
| 1062 | if (in.isArray()) |
| 1063 | { |
| 1064 | // The client wants to bind either "name" or "name[0]". |
| 1065 | // GL ES 3.1 spec refers to active array names with language such as: |
| 1066 | // "if the string identifies the base name of an active array, where the |
| 1067 | // string would exactly match the name of the variable if the suffix "[0]" |
| 1068 | // were appended to the string". |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 1069 | if (arrayIndex == GL_INVALID_INDEX) |
| 1070 | arrayIndex = 0; |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1071 | |
Corentin Wallez | 054f7ed | 2016-09-20 17:15:59 -0400 | [diff] [blame] | 1072 | ret.name = in.mappedName + "[" + ToString(arrayIndex) + "]"; |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1073 | } |
| 1074 | else |
| 1075 | { |
| 1076 | ret.name = in.mappedName; |
| 1077 | } |
| 1078 | ret.type = in.type; |
| 1079 | return ret; |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | return ret; |
| 1085 | } |
| 1086 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1087 | void Program::pathFragmentInputGen(GLint index, |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1088 | GLenum genMode, |
| 1089 | GLint components, |
| 1090 | const GLfloat *coeffs) |
| 1091 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1092 | ASSERT(mLinkResolved); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1093 | // If the location is -1 then the command is silently ignored |
| 1094 | if (index == -1) |
| 1095 | return; |
| 1096 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1097 | const auto &binding = getFragmentInputBindingInfo(index); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1098 | |
| 1099 | // If the input doesn't exist then then the command is silently ignored |
| 1100 | // This could happen through optimization for example, the shader translator |
| 1101 | // decides that a variable is not actually being used and optimizes it away. |
| 1102 | if (binding.name.empty()) |
| 1103 | return; |
| 1104 | |
| 1105 | mProgram->setPathFragmentInputGen(binding.name, genMode, components, coeffs); |
| 1106 | } |
| 1107 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1108 | // The attached shaders are checked for linking errors by matching up their variables. |
| 1109 | // Uniform, input and output variables get collected. |
| 1110 | // The code gets compiled into binaries. |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 1111 | Error Program::link(const gl::Context *context) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1112 | { |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 1113 | const auto &data = context->getContextState(); |
| 1114 | |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 1115 | auto *platform = ANGLEPlatformCurrent(); |
| 1116 | double startTime = platform->currentTime(platform); |
| 1117 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1118 | unlink(); |
Jamie Madill | 6bc264a | 2018-03-31 15:36:05 -0400 | [diff] [blame] | 1119 | mInfoLog.reset(); |
| 1120 | |
| 1121 | // Validate we have properly attached shaders before checking the cache. |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1122 | if (!linkValidateShaders(mInfoLog)) |
Jamie Madill | 6bc264a | 2018-03-31 15:36:05 -0400 | [diff] [blame] | 1123 | { |
| 1124 | return NoError(); |
| 1125 | } |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1126 | |
Shahbaz Youssefi | 9137ade | 2018-08-27 14:22:37 -0400 | [diff] [blame] | 1127 | egl::BlobCache::Key programHash = {0}; |
Jamie Madill | 6bc264a | 2018-03-31 15:36:05 -0400 | [diff] [blame] | 1128 | MemoryProgramCache *cache = context->getMemoryProgramCache(); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1129 | |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 1130 | if (cache) |
| 1131 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1132 | angle::Result result = cache->getProgram(context, this, &mState, &programHash); |
| 1133 | mLinked = (result == angle::Result::Continue()); |
| 1134 | ANGLE_TRY(result); |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | if (mLinked) |
| 1138 | { |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 1139 | double delta = platform->currentTime(platform) - startTime; |
| 1140 | int us = static_cast<int>(delta * 1000000.0); |
| 1141 | ANGLE_HISTOGRAM_COUNTS("GPU.ANGLE.ProgramCache.ProgramCacheHitTimeUS", us); |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 1142 | return NoError(); |
| 1143 | } |
| 1144 | |
| 1145 | // Cache load failed, fall through to normal linking. |
| 1146 | unlink(); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 1147 | |
Jamie Madill | 6bc264a | 2018-03-31 15:36:05 -0400 | [diff] [blame] | 1148 | // Re-link shaders after the unlink call. |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1149 | ASSERT(linkValidateShaders(mInfoLog)); |
Yuly Novikov | cfa48d3 | 2016-06-15 22:14:36 -0400 | [diff] [blame] | 1150 | |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1151 | std::unique_ptr<ProgramLinkedResources> resources; |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 1152 | if (mState.mAttachedShaders[ShaderType::Compute]) |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 1153 | { |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1154 | resources.reset( |
| 1155 | new ProgramLinkedResources{{0, PackMode::ANGLE_RELAXED}, |
| 1156 | {&mState.mUniformBlocks, &mState.mUniforms}, |
| 1157 | {&mState.mShaderStorageBlocks, &mState.mBufferVariables}, |
| 1158 | {&mState.mAtomicCounterBuffers}, |
| 1159 | {}}); |
Luc Ferron | e17b5ba | 2018-06-04 14:28:58 -0400 | [diff] [blame] | 1160 | |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 1161 | GLuint combinedImageUniforms = 0u; |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1162 | if (!linkUniforms(context->getCaps(), mInfoLog, mUniformLocationBindings, |
| 1163 | &combinedImageUniforms, &resources->unusedUniforms)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1164 | { |
| 1165 | return NoError(); |
| 1166 | } |
| 1167 | |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 1168 | GLuint combinedShaderStorageBlocks = 0u; |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1169 | if (!linkInterfaceBlocks(context->getCaps(), context->getClientVersion(), |
| 1170 | context->getExtensions().webglCompatibility, mInfoLog, |
| 1171 | &combinedShaderStorageBlocks)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1172 | { |
| 1173 | return NoError(); |
| 1174 | } |
| 1175 | |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 1176 | // [OpenGL ES 3.1] Chapter 8.22 Page 203: |
| 1177 | // A link error will be generated if the sum of the number of active image uniforms used in |
| 1178 | // all shaders, the number of active shader storage blocks, and the number of active |
| 1179 | // fragment shader outputs exceeds the implementation-dependent value of |
| 1180 | // MAX_COMBINED_SHADER_OUTPUT_RESOURCES. |
| 1181 | if (combinedImageUniforms + combinedShaderStorageBlocks > |
| 1182 | context->getCaps().maxCombinedShaderOutputResources) |
| 1183 | { |
| 1184 | mInfoLog |
| 1185 | << "The sum of the number of active image uniforms, active shader storage blocks " |
| 1186 | "and active fragment shader outputs exceeds " |
| 1187 | "MAX_COMBINED_SHADER_OUTPUT_RESOURCES (" |
| 1188 | << context->getCaps().maxCombinedShaderOutputResources << ")"; |
| 1189 | return NoError(); |
| 1190 | } |
| 1191 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1192 | InitUniformBlockLinker(mState, &resources->uniformBlockLinker); |
| 1193 | InitShaderStorageBlockLinker(mState, &resources->shaderStorageBlockLinker); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1194 | } |
| 1195 | else |
| 1196 | { |
Luc Ferron | e17b5ba | 2018-06-04 14:28:58 -0400 | [diff] [blame] | 1197 | // Map the varyings to the register file |
| 1198 | // In WebGL, we use a slightly different handling for packing variables. |
| 1199 | gl::PackMode packMode = PackMode::ANGLE_RELAXED; |
| 1200 | if (data.getLimitations().noFlexibleVaryingPacking) |
| 1201 | { |
| 1202 | // D3D9 pack mode is strictly more strict than WebGL, so takes priority. |
| 1203 | packMode = PackMode::ANGLE_NON_CONFORMANT_D3D9; |
| 1204 | } |
| 1205 | else if (data.getExtensions().webglCompatibility) |
| 1206 | { |
| 1207 | packMode = PackMode::WEBGL_STRICT; |
| 1208 | } |
| 1209 | |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1210 | resources.reset( |
| 1211 | new ProgramLinkedResources{{data.getCaps().maxVaryingVectors, packMode}, |
| 1212 | {&mState.mUniformBlocks, &mState.mUniforms}, |
| 1213 | {&mState.mShaderStorageBlocks, &mState.mBufferVariables}, |
| 1214 | {&mState.mAtomicCounterBuffers}, |
| 1215 | {}}); |
Luc Ferron | e17b5ba | 2018-06-04 14:28:58 -0400 | [diff] [blame] | 1216 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1217 | if (!linkAttributes(context->getCaps(), mInfoLog)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1218 | { |
| 1219 | return NoError(); |
| 1220 | } |
| 1221 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1222 | if (!linkVaryings(mInfoLog)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1223 | { |
| 1224 | return NoError(); |
| 1225 | } |
| 1226 | |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 1227 | GLuint combinedImageUniforms = 0u; |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1228 | if (!linkUniforms(context->getCaps(), mInfoLog, mUniformLocationBindings, |
| 1229 | &combinedImageUniforms, &resources->unusedUniforms)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1230 | { |
| 1231 | return NoError(); |
| 1232 | } |
| 1233 | |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 1234 | GLuint combinedShaderStorageBlocks = 0u; |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1235 | if (!linkInterfaceBlocks(context->getCaps(), context->getClientVersion(), |
| 1236 | context->getExtensions().webglCompatibility, mInfoLog, |
| 1237 | &combinedShaderStorageBlocks)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1238 | { |
| 1239 | return NoError(); |
| 1240 | } |
| 1241 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1242 | if (!linkValidateGlobalNames(mInfoLog)) |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 1243 | { |
| 1244 | return NoError(); |
| 1245 | } |
| 1246 | |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 1247 | if (!linkOutputVariables(context->getCaps(), context->getExtensions(), |
| 1248 | context->getClientVersion(), combinedImageUniforms, |
| 1249 | combinedShaderStorageBlocks)) |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 1250 | { |
| 1251 | return NoError(); |
| 1252 | } |
| 1253 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1254 | const auto &mergedVaryings = getMergedVaryings(); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1255 | |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 1256 | ASSERT(mState.mAttachedShaders[ShaderType::Vertex]); |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1257 | mState.mNumViews = mState.mAttachedShaders[ShaderType::Vertex]->getNumViews(); |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 1258 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1259 | InitUniformBlockLinker(mState, &resources->uniformBlockLinker); |
| 1260 | InitShaderStorageBlockLinker(mState, &resources->shaderStorageBlockLinker); |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 1261 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 1262 | if (!linkValidateTransformFeedback(context->getClientVersion(), mInfoLog, mergedVaryings, |
| 1263 | context->getCaps())) |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 1264 | { |
| 1265 | return NoError(); |
| 1266 | } |
| 1267 | |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1268 | if (!resources->varyingPacking.collectAndPackUserVaryings( |
jchen10 | 85c93c4 | 2017-11-12 15:36:47 +0800 | [diff] [blame] | 1269 | mInfoLog, mergedVaryings, mState.getTransformFeedbackVaryingNames())) |
Olli Etuaho | 39e7812 | 2017-08-29 14:34:22 +0300 | [diff] [blame] | 1270 | { |
| 1271 | return NoError(); |
| 1272 | } |
| 1273 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1274 | gatherTransformFeedbackVaryings(mergedVaryings); |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 1275 | } |
| 1276 | |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1277 | mLinkingState.reset(new LinkingState()); |
| 1278 | mLinkingState->context = context; |
| 1279 | mLinkingState->programHash = programHash; |
| 1280 | mLinkingState->linkEvent = mProgram->link(context, *resources, mInfoLog); |
| 1281 | mLinkingState->resources = std::move(resources); |
jchen10 | 5055fba | 2018-08-17 09:57:07 +0800 | [diff] [blame] | 1282 | mLinkResolved = false; |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1283 | |
| 1284 | return NoError(); |
| 1285 | } |
| 1286 | |
| 1287 | bool Program::isLinking() const |
| 1288 | { |
| 1289 | return (mLinkingState.get() && mLinkingState->linkEvent->isLinking()); |
| 1290 | } |
| 1291 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1292 | void Program::resolveLinkImpl(const Context *context) |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1293 | { |
| 1294 | ASSERT(mLinkingState.get()); |
| 1295 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1296 | angle::Result result = mLinkingState->linkEvent->wait(context); |
| 1297 | |
| 1298 | mLinked = result == angle::Result::Continue(); |
jchen10 | 5055fba | 2018-08-17 09:57:07 +0800 | [diff] [blame] | 1299 | mLinkResolved = true; |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1300 | auto linkingState = std::move(mLinkingState); |
| 1301 | if (!mLinked) |
| 1302 | { |
| 1303 | return; |
| 1304 | } |
| 1305 | |
Jamie Madill | 6db1c2e | 2017-11-08 09:17:40 -0500 | [diff] [blame] | 1306 | initInterfaceBlockBindings(); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 1307 | |
Yunchao He | ece1253 | 2017-11-21 15:50:21 +0800 | [diff] [blame] | 1308 | // According to GLES 3.0/3.1 spec for LinkProgram and UseProgram, |
| 1309 | // Only successfully linked program can replace the executables. |
Yunchao He | 85072e8 | 2017-11-14 15:43:28 +0800 | [diff] [blame] | 1310 | ASSERT(mLinked); |
| 1311 | updateLinkedShaderStages(); |
| 1312 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 1313 | // Mark implementation-specific unreferenced uniforms as ignored. |
Qin Jiajia | 47f6dd0 | 2018-08-10 13:36:32 +0800 | [diff] [blame] | 1314 | mProgram->markUnusedUniformLocations(&mState.mUniformLocations, &mState.mSamplerBindings, |
| 1315 | &mState.mImageBindings); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 1316 | |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 1317 | // Must be called after markUnusedUniformLocations. |
| 1318 | mState.updateActiveSamplers(); |
Qin Jiajia | 47f6dd0 | 2018-08-10 13:36:32 +0800 | [diff] [blame] | 1319 | mState.updateActiveImages(); |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 1320 | |
| 1321 | setUniformValuesFromBindingQualifiers(); |
| 1322 | |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 1323 | // Save to the program cache. |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1324 | auto *cache = linkingState->context->getMemoryProgramCache(); |
| 1325 | if (cache && |
| 1326 | (mState.mLinkedTransformFeedbackVaryings.empty() || |
| 1327 | !linkingState->context->getWorkarounds().disableProgramCachingForTransformFeedback)) |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 1328 | { |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1329 | cache->putProgram(linkingState->programHash, linkingState->context, this); |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 1330 | } |
apatrick@chromium.org | 9a30b09 | 2012-06-06 20:21:55 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
Yunchao He | 85072e8 | 2017-11-14 15:43:28 +0800 | [diff] [blame] | 1333 | void Program::updateLinkedShaderStages() |
| 1334 | { |
Yunchao He | ece1253 | 2017-11-21 15:50:21 +0800 | [diff] [blame] | 1335 | mState.mLinkedShaderStages.reset(); |
| 1336 | |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 1337 | for (const Shader *shader : mState.mAttachedShaders) |
Yunchao He | 85072e8 | 2017-11-14 15:43:28 +0800 | [diff] [blame] | 1338 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 1339 | if (shader) |
| 1340 | { |
| 1341 | mState.mLinkedShaderStages.set(shader->getType()); |
| 1342 | } |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 1343 | } |
Yunchao He | 85072e8 | 2017-11-14 15:43:28 +0800 | [diff] [blame] | 1344 | } |
| 1345 | |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 1346 | void ProgramState::updateTransformFeedbackStrides() |
| 1347 | { |
| 1348 | if (mTransformFeedbackBufferMode == GL_INTERLEAVED_ATTRIBS) |
| 1349 | { |
| 1350 | mTransformFeedbackStrides.resize(1); |
| 1351 | size_t totalSize = 0; |
| 1352 | for (auto &varying : mLinkedTransformFeedbackVaryings) |
| 1353 | { |
| 1354 | totalSize += varying.size() * VariableExternalSize(varying.type); |
| 1355 | } |
| 1356 | mTransformFeedbackStrides[0] = static_cast<GLsizei>(totalSize); |
| 1357 | } |
| 1358 | else |
| 1359 | { |
| 1360 | mTransformFeedbackStrides.resize(mLinkedTransformFeedbackVaryings.size()); |
| 1361 | for (size_t i = 0; i < mLinkedTransformFeedbackVaryings.size(); i++) |
| 1362 | { |
| 1363 | auto &varying = mLinkedTransformFeedbackVaryings[i]; |
| 1364 | mTransformFeedbackStrides[i] = |
| 1365 | static_cast<GLsizei>(varying.size() * VariableExternalSize(varying.type)); |
| 1366 | } |
| 1367 | } |
| 1368 | } |
| 1369 | |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 1370 | void ProgramState::updateActiveSamplers() |
| 1371 | { |
| 1372 | for (SamplerBinding &samplerBinding : mSamplerBindings) |
| 1373 | { |
| 1374 | if (samplerBinding.unreferenced) |
| 1375 | continue; |
| 1376 | |
| 1377 | for (GLint textureUnit : samplerBinding.boundTextureUnits) |
| 1378 | { |
| 1379 | mActiveSamplerRefCounts[textureUnit]++; |
| 1380 | mActiveSamplerTypes[textureUnit] = getSamplerUniformTextureType(textureUnit); |
| 1381 | mActiveSamplersMask.set(textureUnit); |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | |
Qin Jiajia | 47f6dd0 | 2018-08-10 13:36:32 +0800 | [diff] [blame] | 1386 | void ProgramState::updateActiveImages() |
| 1387 | { |
| 1388 | for (ImageBinding &imageBinding : mImageBindings) |
| 1389 | { |
| 1390 | if (imageBinding.unreferenced) |
| 1391 | continue; |
| 1392 | |
| 1393 | for (GLint imageUnit : imageBinding.boundImageUnits) |
| 1394 | { |
| 1395 | mActiveImagesMask.set(imageUnit); |
| 1396 | } |
| 1397 | } |
| 1398 | } |
| 1399 | |
daniel@transgaming.com | aa5e59b | 2011-10-04 18:43:12 +0000 | [diff] [blame] | 1400 | // 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] | 1401 | void Program::unlink() |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1402 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1403 | mState.mAttributes.clear(); |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 1404 | mState.mAttributesTypeMask.reset(); |
| 1405 | mState.mAttributesMask.reset(); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1406 | mState.mActiveAttribLocationsMask.reset(); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 1407 | mState.mMaxActiveAttribLocation = 0; |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 1408 | mState.mLinkedTransformFeedbackVaryings.clear(); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1409 | mState.mUniforms.clear(); |
| 1410 | mState.mUniformLocations.clear(); |
| 1411 | mState.mUniformBlocks.clear(); |
jchen10 | 7a20b97 | 2017-06-13 14:25:26 +0800 | [diff] [blame] | 1412 | mState.mActiveUniformBlockBindings.reset(); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 1413 | mState.mAtomicCounterBuffers.clear(); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1414 | mState.mOutputVariables.clear(); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1415 | mState.mOutputLocations.clear(); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 1416 | mState.mOutputVariableTypes.clear(); |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 1417 | mState.mDrawBufferTypeMask.reset(); |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 1418 | mState.mActiveOutputVariables.reset(); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1419 | mState.mComputeShaderLocalSize.fill(1); |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 1420 | mState.mSamplerBindings.clear(); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 1421 | mState.mImageBindings.clear(); |
Qin Jiajia | 47f6dd0 | 2018-08-10 13:36:32 +0800 | [diff] [blame] | 1422 | mState.mActiveImagesMask.reset(); |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 1423 | mState.mNumViews = -1; |
| 1424 | mState.mGeometryShaderInputPrimitiveType = PrimitiveMode::Triangles; |
| 1425 | mState.mGeometryShaderOutputPrimitiveType = PrimitiveMode::TriangleStrip; |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 1426 | mState.mGeometryShaderInvocations = 1; |
| 1427 | mState.mGeometryShaderMaxVertices = 0; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1428 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1429 | mValidated = false; |
| 1430 | |
daniel@transgaming.com | 716056c | 2012-07-24 18:38:59 +0000 | [diff] [blame] | 1431 | mLinked = false; |
Jamie Madill | 6bc264a | 2018-03-31 15:36:05 -0400 | [diff] [blame] | 1432 | mInfoLog.reset(); |
daniel@transgaming.com | 716056c | 2012-07-24 18:38:59 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 1435 | Error Program::loadBinary(const Context *context, |
| 1436 | GLenum binaryFormat, |
| 1437 | const void *binary, |
| 1438 | GLsizei length) |
apatrick@chromium.org | 3ce8dbc | 2012-06-08 17:52:30 +0000 | [diff] [blame] | 1439 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1440 | ASSERT(mLinkResolved); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1441 | unlink(); |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 1442 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1443 | #if ANGLE_PROGRAM_BINARY_LOAD != ANGLE_ENABLED |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 1444 | return NoError(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1445 | #else |
Geoff Lang | c46cc2f | 2015-10-01 17:16:20 -0400 | [diff] [blame] | 1446 | ASSERT(binaryFormat == GL_PROGRAM_BINARY_ANGLE); |
| 1447 | if (binaryFormat != GL_PROGRAM_BINARY_ANGLE) |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 1448 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 1449 | mInfoLog << "Invalid program binary format."; |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 1450 | return NoError(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1451 | } |
| 1452 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 1453 | const uint8_t *bytes = reinterpret_cast<const uint8_t *>(binary); |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1454 | angle::Result result = |
| 1455 | MemoryProgramCache::Deserialize(context, this, &mState, bytes, length, mInfoLog); |
| 1456 | mLinked = result == angle::Result::Continue(); |
| 1457 | ANGLE_TRY(result); |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 1458 | |
| 1459 | // Currently we require the full shader text to compute the program hash. |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1460 | // We could also store the binary in the internal program cache. |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 1461 | |
Jamie Madill | 70aeda4 | 2018-08-20 12:17:40 -0400 | [diff] [blame] | 1462 | for (size_t uniformBlockIndex = 0; uniformBlockIndex < mState.mUniformBlocks.size(); |
| 1463 | ++uniformBlockIndex) |
| 1464 | { |
| 1465 | mDirtyBits.set(uniformBlockIndex); |
| 1466 | } |
| 1467 | |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 1468 | return NoError(); |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 1469 | #endif // #if ANGLE_PROGRAM_BINARY_LOAD == ANGLE_ENABLED |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1470 | } |
| 1471 | |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 1472 | Error Program::saveBinary(const Context *context, |
| 1473 | GLenum *binaryFormat, |
| 1474 | void *binary, |
| 1475 | GLsizei bufSize, |
| 1476 | GLsizei *length) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1477 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1478 | ASSERT(mLinkResolved); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1479 | if (binaryFormat) |
| 1480 | { |
Geoff Lang | c46cc2f | 2015-10-01 17:16:20 -0400 | [diff] [blame] | 1481 | *binaryFormat = GL_PROGRAM_BINARY_ANGLE; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1482 | } |
| 1483 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 1484 | angle::MemoryBuffer memoryBuf; |
| 1485 | MemoryProgramCache::Serialize(context, this, &memoryBuf); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1486 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 1487 | GLsizei streamLength = static_cast<GLsizei>(memoryBuf.size()); |
| 1488 | const uint8_t *streamState = memoryBuf.data(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1489 | |
| 1490 | if (streamLength > bufSize) |
| 1491 | { |
| 1492 | if (length) |
| 1493 | { |
| 1494 | *length = 0; |
| 1495 | } |
| 1496 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 1497 | // TODO: This should be moved to the validation layer but computing the size of the binary |
| 1498 | // before saving it causes the save to happen twice. It may be possible to write the binary |
| 1499 | // to a separate buffer, validate sizes and then copy it. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1500 | return InternalError(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | if (binary) |
| 1504 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 1505 | char *ptr = reinterpret_cast<char *>(binary); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1506 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1507 | memcpy(ptr, streamState, streamLength); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1508 | ptr += streamLength; |
| 1509 | |
| 1510 | ASSERT(ptr - streamLength == binary); |
| 1511 | } |
| 1512 | |
| 1513 | if (length) |
| 1514 | { |
| 1515 | *length = streamLength; |
| 1516 | } |
| 1517 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 1518 | return NoError(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1519 | } |
| 1520 | |
Jamie Madill | ffe00c0 | 2017-06-27 16:26:55 -0400 | [diff] [blame] | 1521 | GLint Program::getBinaryLength(const Context *context) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1522 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1523 | ASSERT(mLinkResolved); |
Geoff Lang | b26ab82 | 2018-05-29 11:19:00 -0400 | [diff] [blame] | 1524 | if (!mLinked) |
| 1525 | { |
| 1526 | return 0; |
| 1527 | } |
| 1528 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1529 | GLint length; |
Jamie Madill | ffe00c0 | 2017-06-27 16:26:55 -0400 | [diff] [blame] | 1530 | Error error = saveBinary(context, nullptr, nullptr, std::numeric_limits<GLint>::max(), &length); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1531 | if (error.isError()) |
| 1532 | { |
| 1533 | return 0; |
| 1534 | } |
| 1535 | |
| 1536 | return length; |
apatrick@chromium.org | 3ce8dbc | 2012-06-08 17:52:30 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1539 | void Program::setBinaryRetrievableHint(bool retrievable) |
| 1540 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1541 | ASSERT(mLinkResolved); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1542 | // TODO(jmadill) : replace with dirty bits |
| 1543 | mProgram->setBinaryRetrievableHint(retrievable); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1544 | mState.mBinaryRetrieveableHint = retrievable; |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | bool Program::getBinaryRetrievableHint() const |
| 1548 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1549 | ASSERT(mLinkResolved); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1550 | return mState.mBinaryRetrieveableHint; |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1551 | } |
| 1552 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1553 | void Program::setSeparable(bool separable) |
| 1554 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1555 | ASSERT(mLinkResolved); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1556 | // TODO(yunchao) : replace with dirty bits |
| 1557 | if (mState.mSeparable != separable) |
| 1558 | { |
| 1559 | mProgram->setSeparable(separable); |
| 1560 | mState.mSeparable = separable; |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | bool Program::isSeparable() const |
| 1565 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1566 | ASSERT(mLinkResolved); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1567 | return mState.mSeparable; |
| 1568 | } |
| 1569 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1570 | void Program::release(const Context *context) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1571 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1572 | ASSERT(mLinkResolved); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1573 | mRefCount--; |
| 1574 | |
| 1575 | if (mRefCount == 0 && mDeleteStatus) |
| 1576 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1577 | mResourceManager->deleteProgram(context, mHandle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | void Program::addRef() |
| 1582 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1583 | ASSERT(mLinkResolved); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1584 | mRefCount++; |
| 1585 | } |
| 1586 | |
| 1587 | unsigned int Program::getRefCount() const |
| 1588 | { |
| 1589 | return mRefCount; |
| 1590 | } |
| 1591 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1592 | int Program::getInfoLogLength() const |
| 1593 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1594 | ASSERT(mLinkResolved); |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 1595 | return static_cast<int>(mInfoLog.getLength()); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1598 | void Program::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1599 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1600 | ASSERT(mLinkResolved); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 1601 | return mInfoLog.getLog(bufSize, length, infoLog); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1604 | void Program::getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders) const |
daniel@transgaming.com | 6c78521 | 2010-03-30 03:36:17 +0000 | [diff] [blame] | 1605 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1606 | ASSERT(mLinkResolved); |
daniel@transgaming.com | 6c78521 | 2010-03-30 03:36:17 +0000 | [diff] [blame] | 1607 | int total = 0; |
| 1608 | |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 1609 | for (const Shader *shader : mState.mAttachedShaders) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1610 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 1611 | if (shader && (total < maxCount)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 1612 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 1613 | shaders[total] = shader->getHandle(); |
| 1614 | ++total; |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 1615 | } |
| 1616 | } |
| 1617 | |
daniel@transgaming.com | 6c78521 | 2010-03-30 03:36:17 +0000 | [diff] [blame] | 1618 | if (count) |
| 1619 | { |
| 1620 | *count = total; |
| 1621 | } |
| 1622 | } |
| 1623 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1624 | GLuint Program::getAttributeLocation(const std::string &name) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1625 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1626 | ASSERT(mLinkResolved); |
Jamie Madill | 34ca4f5 | 2017-06-13 11:49:39 -0400 | [diff] [blame] | 1627 | return mState.getAttributeLocation(name); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1628 | } |
| 1629 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 1630 | bool Program::isAttribLocationActive(size_t attribLocation) const |
Jamie Madill | 56c6e3c | 2015-04-15 10:18:05 -0400 | [diff] [blame] | 1631 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1632 | ASSERT(mLinkResolved); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1633 | ASSERT(attribLocation < mState.mActiveAttribLocationsMask.size()); |
| 1634 | return mState.mActiveAttribLocationsMask[attribLocation]; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1635 | } |
| 1636 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1637 | void Program::getActiveAttribute(GLuint index, |
| 1638 | GLsizei bufsize, |
| 1639 | GLsizei *length, |
| 1640 | GLint *size, |
| 1641 | GLenum *type, |
| 1642 | GLchar *name) const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1643 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1644 | ASSERT(mLinkResolved); |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1645 | if (!mLinked) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1646 | { |
| 1647 | if (bufsize > 0) |
| 1648 | { |
| 1649 | name[0] = '\0'; |
| 1650 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1651 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1652 | if (length) |
| 1653 | { |
| 1654 | *length = 0; |
| 1655 | } |
| 1656 | |
| 1657 | *type = GL_NONE; |
| 1658 | *size = 1; |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1659 | return; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1660 | } |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1661 | |
jchen10 | 36e120e | 2017-03-14 14:53:58 +0800 | [diff] [blame] | 1662 | ASSERT(index < mState.mAttributes.size()); |
| 1663 | const sh::Attribute &attrib = mState.mAttributes[index]; |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1664 | |
| 1665 | if (bufsize > 0) |
| 1666 | { |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1667 | CopyStringToBuffer(name, attrib.name, bufsize, length); |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | // Always a single 'type' instance |
| 1671 | *size = 1; |
| 1672 | *type = attrib.type; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1675 | GLint Program::getActiveAttributeCount() const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1676 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1677 | ASSERT(mLinkResolved); |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1678 | if (!mLinked) |
Jamie Madill | 2d77318 | 2015-08-18 10:27:28 -0400 | [diff] [blame] | 1679 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1680 | return 0; |
| 1681 | } |
| 1682 | |
jchen10 | 36e120e | 2017-03-14 14:53:58 +0800 | [diff] [blame] | 1683 | return static_cast<GLint>(mState.mAttributes.size()); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1686 | GLint Program::getActiveAttributeMaxLength() const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1687 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1688 | ASSERT(mLinkResolved); |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1689 | if (!mLinked) |
Jamie Madill | 2d77318 | 2015-08-18 10:27:28 -0400 | [diff] [blame] | 1690 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1691 | return 0; |
| 1692 | } |
| 1693 | |
| 1694 | size_t maxLength = 0; |
| 1695 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1696 | for (const sh::Attribute &attrib : mState.mAttributes) |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1697 | { |
jchen10 | 36e120e | 2017-03-14 14:53:58 +0800 | [diff] [blame] | 1698 | maxLength = std::max(attrib.name.length() + 1, maxLength); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1699 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1700 | |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 1701 | return static_cast<GLint>(maxLength); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1702 | } |
| 1703 | |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1704 | const std::vector<sh::Attribute> &Program::getAttributes() const |
| 1705 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1706 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1707 | return mState.mAttributes; |
| 1708 | } |
| 1709 | |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1710 | const std::vector<SamplerBinding> &Program::getSamplerBindings() const |
| 1711 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1712 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1713 | return mState.mSamplerBindings; |
| 1714 | } |
| 1715 | |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1716 | const sh::WorkGroupSize &Program::getComputeShaderLocalSize() const |
| 1717 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1718 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1719 | return mState.mComputeShaderLocalSize; |
| 1720 | } |
| 1721 | |
| 1722 | PrimitiveMode Program::getGeometryShaderInputPrimitiveType() const |
| 1723 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1724 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1725 | return mState.mGeometryShaderInputPrimitiveType; |
| 1726 | } |
| 1727 | PrimitiveMode Program::getGeometryShaderOutputPrimitiveType() const |
| 1728 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1729 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1730 | return mState.mGeometryShaderOutputPrimitiveType; |
| 1731 | } |
| 1732 | GLint Program::getGeometryShaderInvocations() const |
| 1733 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1734 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1735 | return mState.mGeometryShaderInvocations; |
| 1736 | } |
| 1737 | GLint Program::getGeometryShaderMaxVertices() const |
| 1738 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1739 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1740 | return mState.mGeometryShaderMaxVertices; |
| 1741 | } |
| 1742 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1743 | GLuint Program::getInputResourceIndex(const GLchar *name) const |
| 1744 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1745 | ASSERT(mLinkResolved); |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 1746 | return GetResourceIndexFromName(mState.mAttributes, std::string(name)); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | GLuint Program::getOutputResourceIndex(const GLchar *name) const |
| 1750 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1751 | ASSERT(mLinkResolved); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1752 | return GetResourceIndexFromName(mState.mOutputVariables, std::string(name)); |
| 1753 | } |
| 1754 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1755 | size_t Program::getOutputResourceCount() const |
| 1756 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1757 | ASSERT(mLinkResolved); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1758 | return (mLinked ? mState.mOutputVariables.size() : 0); |
| 1759 | } |
| 1760 | |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1761 | const std::vector<GLenum> &Program::getOutputVariableTypes() const |
| 1762 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1763 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1764 | return mState.mOutputVariableTypes; |
| 1765 | } |
| 1766 | DrawBufferMask Program::getActiveOutputVariables() const |
| 1767 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1768 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1769 | return mState.mActiveOutputVariables; |
| 1770 | } |
| 1771 | |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 1772 | template <typename T> |
| 1773 | void Program::getResourceName(GLuint index, |
| 1774 | const std::vector<T> &resources, |
| 1775 | GLsizei bufSize, |
| 1776 | GLsizei *length, |
| 1777 | GLchar *name) const |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1778 | { |
| 1779 | if (length) |
| 1780 | { |
| 1781 | *length = 0; |
| 1782 | } |
| 1783 | |
| 1784 | if (!mLinked) |
| 1785 | { |
| 1786 | if (bufSize > 0) |
| 1787 | { |
| 1788 | name[0] = '\0'; |
| 1789 | } |
| 1790 | return; |
| 1791 | } |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 1792 | ASSERT(index < resources.size()); |
| 1793 | const auto &resource = resources[index]; |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1794 | |
| 1795 | if (bufSize > 0) |
| 1796 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 1797 | CopyStringToBuffer(name, resource.name, bufSize, length); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1798 | } |
| 1799 | } |
| 1800 | |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 1801 | void Program::getInputResourceName(GLuint index, |
| 1802 | GLsizei bufSize, |
| 1803 | GLsizei *length, |
| 1804 | GLchar *name) const |
| 1805 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1806 | ASSERT(mLinkResolved); |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 1807 | getResourceName(index, mState.mAttributes, bufSize, length, name); |
| 1808 | } |
| 1809 | |
| 1810 | void Program::getOutputResourceName(GLuint index, |
| 1811 | GLsizei bufSize, |
| 1812 | GLsizei *length, |
| 1813 | GLchar *name) const |
| 1814 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1815 | ASSERT(mLinkResolved); |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 1816 | getResourceName(index, mState.mOutputVariables, bufSize, length, name); |
| 1817 | } |
| 1818 | |
| 1819 | void Program::getUniformResourceName(GLuint index, |
| 1820 | GLsizei bufSize, |
| 1821 | GLsizei *length, |
| 1822 | GLchar *name) const |
| 1823 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1824 | ASSERT(mLinkResolved); |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 1825 | getResourceName(index, mState.mUniforms, bufSize, length, name); |
| 1826 | } |
| 1827 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 1828 | void Program::getBufferVariableResourceName(GLuint index, |
| 1829 | GLsizei bufSize, |
| 1830 | GLsizei *length, |
| 1831 | GLchar *name) const |
| 1832 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1833 | ASSERT(mLinkResolved); |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 1834 | getResourceName(index, mState.mBufferVariables, bufSize, length, name); |
| 1835 | } |
| 1836 | |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 1837 | const sh::Attribute &Program::getInputResource(GLuint index) const |
| 1838 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1839 | ASSERT(mLinkResolved); |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 1840 | ASSERT(index < mState.mAttributes.size()); |
| 1841 | return mState.mAttributes[index]; |
| 1842 | } |
| 1843 | |
| 1844 | const sh::OutputVariable &Program::getOutputResource(GLuint index) const |
| 1845 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1846 | ASSERT(mLinkResolved); |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 1847 | ASSERT(index < mState.mOutputVariables.size()); |
| 1848 | return mState.mOutputVariables[index]; |
| 1849 | } |
| 1850 | |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1851 | const ProgramBindings &Program::getAttributeBindings() const |
| 1852 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1853 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1854 | return mAttributeBindings; |
| 1855 | } |
| 1856 | const ProgramBindings &Program::getUniformLocationBindings() const |
| 1857 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1858 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1859 | return mUniformLocationBindings; |
| 1860 | } |
| 1861 | const ProgramBindings &Program::getFragmentInputBindings() const |
| 1862 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1863 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1864 | return mFragmentInputBindings; |
| 1865 | } |
| 1866 | |
| 1867 | int Program::getNumViews() const |
| 1868 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1869 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1870 | return mState.getNumViews(); |
| 1871 | } |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1872 | |
| 1873 | ComponentTypeMask Program::getDrawBufferTypeMask() const |
| 1874 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1875 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1876 | return mState.mDrawBufferTypeMask; |
| 1877 | } |
| 1878 | ComponentTypeMask Program::getAttributesTypeMask() const |
| 1879 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1880 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1881 | return mState.mAttributesTypeMask; |
| 1882 | } |
| 1883 | AttributesMask Program::getAttributesMask() const |
| 1884 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1885 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1886 | return mState.mAttributesMask; |
| 1887 | } |
| 1888 | |
| 1889 | const std::vector<GLsizei> &Program::getTransformFeedbackStrides() const |
| 1890 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1891 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 1892 | return mState.mTransformFeedbackStrides; |
| 1893 | } |
| 1894 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1895 | GLint Program::getFragDataLocation(const std::string &name) const |
| 1896 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1897 | ASSERT(mLinkResolved); |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 1898 | GLint primaryLocation = |
| 1899 | GetVariableLocation(mState.mOutputVariables, mState.mOutputLocations, name); |
| 1900 | if (primaryLocation != -1) |
| 1901 | { |
| 1902 | return primaryLocation; |
| 1903 | } |
| 1904 | return GetVariableLocation(mState.mOutputVariables, mState.mSecondaryOutputLocations, name); |
| 1905 | } |
| 1906 | |
| 1907 | GLint Program::getFragDataIndex(const std::string &name) const |
| 1908 | { |
| 1909 | ASSERT(mLinkResolved); |
| 1910 | if (GetVariableLocation(mState.mOutputVariables, mState.mOutputLocations, name) != -1) |
| 1911 | { |
| 1912 | return 0; |
| 1913 | } |
| 1914 | if (GetVariableLocation(mState.mOutputVariables, mState.mSecondaryOutputLocations, name) != -1) |
| 1915 | { |
| 1916 | return 1; |
| 1917 | } |
| 1918 | return -1; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1921 | void Program::getActiveUniform(GLuint index, |
| 1922 | GLsizei bufsize, |
| 1923 | GLsizei *length, |
| 1924 | GLint *size, |
| 1925 | GLenum *type, |
| 1926 | GLchar *name) const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1927 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1928 | ASSERT(mLinkResolved); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1929 | if (mLinked) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1930 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1931 | // index must be smaller than getActiveUniformCount() |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1932 | ASSERT(index < mState.mUniforms.size()); |
| 1933 | const LinkedUniform &uniform = mState.mUniforms[index]; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1934 | |
| 1935 | if (bufsize > 0) |
| 1936 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1937 | std::string string = uniform.name; |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1938 | CopyStringToBuffer(name, string, bufsize, length); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1939 | } |
| 1940 | |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 1941 | *size = clampCast<GLint>(uniform.getBasicTypeElementCount()); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1942 | *type = uniform.type; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1943 | } |
| 1944 | else |
| 1945 | { |
| 1946 | if (bufsize > 0) |
| 1947 | { |
| 1948 | name[0] = '\0'; |
| 1949 | } |
| 1950 | |
| 1951 | if (length) |
| 1952 | { |
| 1953 | *length = 0; |
| 1954 | } |
| 1955 | |
| 1956 | *size = 0; |
| 1957 | *type = GL_NONE; |
| 1958 | } |
| 1959 | } |
| 1960 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1961 | GLint Program::getActiveUniformCount() const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1962 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1963 | ASSERT(mLinkResolved); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1964 | if (mLinked) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1965 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1966 | return static_cast<GLint>(mState.mUniforms.size()); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1967 | } |
| 1968 | else |
| 1969 | { |
| 1970 | return 0; |
| 1971 | } |
| 1972 | } |
| 1973 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 1974 | size_t Program::getActiveBufferVariableCount() const |
| 1975 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1976 | ASSERT(mLinkResolved); |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 1977 | return mLinked ? mState.mBufferVariables.size() : 0; |
| 1978 | } |
| 1979 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 1980 | GLint Program::getActiveUniformMaxLength() const |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1981 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1982 | ASSERT(mLinkResolved); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1983 | size_t maxLength = 0; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1984 | |
| 1985 | if (mLinked) |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1986 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1987 | for (const LinkedUniform &uniform : mState.mUniforms) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1988 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1989 | if (!uniform.name.empty()) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1990 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1991 | size_t length = uniform.name.length() + 1u; |
| 1992 | if (uniform.isArray()) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1993 | { |
| 1994 | length += 3; // Counting in "[0]". |
| 1995 | } |
| 1996 | maxLength = std::max(length, maxLength); |
| 1997 | } |
| 1998 | } |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 1999 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2000 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2001 | return static_cast<GLint>(maxLength); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2002 | } |
| 2003 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2004 | bool Program::isValidUniformLocation(GLint location) const |
| 2005 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2006 | ASSERT(mLinkResolved); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2007 | ASSERT(angle::IsValueInRangeForNumericType<GLint>(mState.mUniformLocations.size())); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2008 | return (location >= 0 && static_cast<size_t>(location) < mState.mUniformLocations.size() && |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 2009 | mState.mUniformLocations[static_cast<size_t>(location)].used()); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2010 | } |
| 2011 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2012 | const LinkedUniform &Program::getUniformByLocation(GLint location) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2013 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2014 | ASSERT(mLinkResolved); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2015 | ASSERT(location >= 0 && static_cast<size_t>(location) < mState.mUniformLocations.size()); |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 2016 | return mState.mUniforms[mState.getUniformIndexFromLocation(location)]; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2017 | } |
| 2018 | |
Jamie Madill | ac4e9c3 | 2017-01-13 14:07:12 -0500 | [diff] [blame] | 2019 | const VariableLocation &Program::getUniformLocation(GLint location) const |
| 2020 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2021 | ASSERT(mLinkResolved); |
Jamie Madill | ac4e9c3 | 2017-01-13 14:07:12 -0500 | [diff] [blame] | 2022 | ASSERT(location >= 0 && static_cast<size_t>(location) < mState.mUniformLocations.size()); |
| 2023 | return mState.mUniformLocations[location]; |
| 2024 | } |
| 2025 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 2026 | const BufferVariable &Program::getBufferVariableByIndex(GLuint index) const |
| 2027 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2028 | ASSERT(mLinkResolved); |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 2029 | ASSERT(index < static_cast<size_t>(mState.mBufferVariables.size())); |
| 2030 | return mState.mBufferVariables[index]; |
| 2031 | } |
| 2032 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2033 | GLint Program::getUniformLocation(const std::string &name) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2034 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2035 | ASSERT(mLinkResolved); |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 2036 | return GetVariableLocation(mState.mUniforms, mState.mUniformLocations, name); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2037 | } |
| 2038 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2039 | GLuint Program::getUniformIndex(const std::string &name) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2040 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2041 | ASSERT(mLinkResolved); |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 2042 | return mState.getUniformIndexFromName(name); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | void Program::setUniform1fv(GLint location, GLsizei count, const GLfloat *v) |
| 2046 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2047 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2048 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2049 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 1, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2050 | mProgram->setUniform1fv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | void Program::setUniform2fv(GLint location, GLsizei count, const GLfloat *v) |
| 2054 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2055 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2056 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2057 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 2, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2058 | mProgram->setUniform2fv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | void Program::setUniform3fv(GLint location, GLsizei count, const GLfloat *v) |
| 2062 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2063 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2064 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2065 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 3, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2066 | mProgram->setUniform3fv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | void Program::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) |
| 2070 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2071 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2072 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2073 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 4, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2074 | mProgram->setUniform4fv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2075 | } |
| 2076 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2077 | Program::SetUniformResult Program::setUniform1iv(GLint location, GLsizei count, const GLint *v) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2078 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2079 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2080 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2081 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 1, v); |
| 2082 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2083 | mProgram->setUniform1iv(location, clampedCount, v); |
| 2084 | |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2085 | if (mState.isSamplerUniformIndex(locationInfo.index)) |
| 2086 | { |
| 2087 | updateSamplerUniform(locationInfo, clampedCount, v); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2088 | return SetUniformResult::SamplerChanged; |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2089 | } |
| 2090 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2091 | return SetUniformResult::NoSamplerChange; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | void Program::setUniform2iv(GLint location, GLsizei count, const GLint *v) |
| 2095 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2096 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2097 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2098 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 2, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2099 | mProgram->setUniform2iv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | void Program::setUniform3iv(GLint location, GLsizei count, const GLint *v) |
| 2103 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2104 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2105 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2106 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 3, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2107 | mProgram->setUniform3iv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | void Program::setUniform4iv(GLint location, GLsizei count, const GLint *v) |
| 2111 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2112 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2113 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2114 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 4, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2115 | mProgram->setUniform4iv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | void Program::setUniform1uiv(GLint location, GLsizei count, const GLuint *v) |
| 2119 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2120 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2121 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2122 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 1, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2123 | mProgram->setUniform1uiv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | void Program::setUniform2uiv(GLint location, GLsizei count, const GLuint *v) |
| 2127 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2128 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2129 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2130 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 2, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2131 | mProgram->setUniform2uiv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | void Program::setUniform3uiv(GLint location, GLsizei count, const GLuint *v) |
| 2135 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2136 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2137 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2138 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 3, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2139 | mProgram->setUniform3uiv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | void Program::setUniform4uiv(GLint location, GLsizei count, const GLuint *v) |
| 2143 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2144 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2145 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 2146 | GLsizei clampedCount = clampUniformCount(locationInfo, count, 4, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2147 | mProgram->setUniform4uiv(location, clampedCount, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2148 | } |
| 2149 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2150 | void Program::setUniformMatrix2fv(GLint location, |
| 2151 | GLsizei count, |
| 2152 | GLboolean transpose, |
| 2153 | const GLfloat *v) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2154 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2155 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2156 | GLsizei clampedCount = clampMatrixUniformCount<2, 2>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2157 | mProgram->setUniformMatrix2fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2158 | } |
| 2159 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2160 | void Program::setUniformMatrix3fv(GLint location, |
| 2161 | GLsizei count, |
| 2162 | GLboolean transpose, |
| 2163 | const GLfloat *v) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2164 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2165 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2166 | GLsizei clampedCount = clampMatrixUniformCount<3, 3>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2167 | mProgram->setUniformMatrix3fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2168 | } |
| 2169 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2170 | void Program::setUniformMatrix4fv(GLint location, |
| 2171 | GLsizei count, |
| 2172 | GLboolean transpose, |
| 2173 | const GLfloat *v) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2174 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2175 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2176 | GLsizei clampedCount = clampMatrixUniformCount<4, 4>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2177 | mProgram->setUniformMatrix4fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2178 | } |
| 2179 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2180 | void Program::setUniformMatrix2x3fv(GLint location, |
| 2181 | GLsizei count, |
| 2182 | GLboolean transpose, |
| 2183 | const GLfloat *v) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2184 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2185 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2186 | GLsizei clampedCount = clampMatrixUniformCount<2, 3>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2187 | mProgram->setUniformMatrix2x3fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2188 | } |
| 2189 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2190 | void Program::setUniformMatrix2x4fv(GLint location, |
| 2191 | GLsizei count, |
| 2192 | GLboolean transpose, |
| 2193 | const GLfloat *v) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2194 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2195 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2196 | GLsizei clampedCount = clampMatrixUniformCount<2, 4>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2197 | mProgram->setUniformMatrix2x4fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2198 | } |
| 2199 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2200 | void Program::setUniformMatrix3x2fv(GLint location, |
| 2201 | GLsizei count, |
| 2202 | GLboolean transpose, |
| 2203 | const GLfloat *v) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2204 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2205 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2206 | GLsizei clampedCount = clampMatrixUniformCount<3, 2>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2207 | mProgram->setUniformMatrix3x2fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2208 | } |
| 2209 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2210 | void Program::setUniformMatrix3x4fv(GLint location, |
| 2211 | GLsizei count, |
| 2212 | GLboolean transpose, |
| 2213 | const GLfloat *v) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2214 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2215 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2216 | GLsizei clampedCount = clampMatrixUniformCount<3, 4>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2217 | mProgram->setUniformMatrix3x4fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2218 | } |
| 2219 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2220 | void Program::setUniformMatrix4x2fv(GLint location, |
| 2221 | GLsizei count, |
| 2222 | GLboolean transpose, |
| 2223 | const GLfloat *v) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2224 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2225 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2226 | GLsizei clampedCount = clampMatrixUniformCount<4, 2>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2227 | mProgram->setUniformMatrix4x2fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2228 | } |
| 2229 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2230 | void Program::setUniformMatrix4x3fv(GLint location, |
| 2231 | GLsizei count, |
| 2232 | GLboolean transpose, |
| 2233 | const GLfloat *v) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2234 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2235 | ASSERT(mLinkResolved); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 2236 | GLsizei clampedCount = clampMatrixUniformCount<4, 3>(location, count, transpose, v); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 2237 | mProgram->setUniformMatrix4x3fv(location, clampedCount, transpose, v); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2238 | } |
| 2239 | |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 2240 | GLuint Program::getSamplerUniformBinding(const VariableLocation &uniformLocation) const |
| 2241 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2242 | ASSERT(mLinkResolved); |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 2243 | GLuint samplerIndex = mState.getSamplerIndexFromUniformIndex(uniformLocation.index); |
| 2244 | const std::vector<GLuint> &boundTextureUnits = |
| 2245 | mState.mSamplerBindings[samplerIndex].boundTextureUnits; |
| 2246 | return boundTextureUnits[uniformLocation.arrayIndex]; |
| 2247 | } |
| 2248 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2249 | void Program::getUniformfv(const Context *context, GLint location, GLfloat *v) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2250 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2251 | ASSERT(mLinkResolved); |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 2252 | const VariableLocation &uniformLocation = mState.getUniformLocations()[location]; |
| 2253 | const LinkedUniform &uniform = mState.getUniforms()[uniformLocation.index]; |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2254 | |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 2255 | if (uniform.isSampler()) |
| 2256 | { |
| 2257 | *v = static_cast<GLfloat>(getSamplerUniformBinding(uniformLocation)); |
| 2258 | return; |
| 2259 | } |
| 2260 | |
| 2261 | const GLenum nativeType = gl::VariableComponentType(uniform.type); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2262 | if (nativeType == GL_FLOAT) |
| 2263 | { |
| 2264 | mProgram->getUniformfv(context, location, v); |
| 2265 | } |
| 2266 | else |
| 2267 | { |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 2268 | getUniformInternal(context, v, location, nativeType, VariableComponentCount(uniform.type)); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2269 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2270 | } |
| 2271 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2272 | void Program::getUniformiv(const Context *context, GLint location, GLint *v) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2273 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2274 | ASSERT(mLinkResolved); |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 2275 | const VariableLocation &uniformLocation = mState.getUniformLocations()[location]; |
| 2276 | const LinkedUniform &uniform = mState.getUniforms()[uniformLocation.index]; |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2277 | |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 2278 | if (uniform.isSampler()) |
| 2279 | { |
| 2280 | *v = static_cast<GLint>(getSamplerUniformBinding(uniformLocation)); |
| 2281 | return; |
| 2282 | } |
| 2283 | |
| 2284 | const GLenum nativeType = gl::VariableComponentType(uniform.type); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2285 | if (nativeType == GL_INT || nativeType == GL_BOOL) |
| 2286 | { |
| 2287 | mProgram->getUniformiv(context, location, v); |
| 2288 | } |
| 2289 | else |
| 2290 | { |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 2291 | getUniformInternal(context, v, location, nativeType, VariableComponentCount(uniform.type)); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2292 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2293 | } |
| 2294 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2295 | void Program::getUniformuiv(const Context *context, GLint location, GLuint *v) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2296 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2297 | ASSERT(mLinkResolved); |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 2298 | const VariableLocation &uniformLocation = mState.getUniformLocations()[location]; |
| 2299 | const LinkedUniform &uniform = mState.getUniforms()[uniformLocation.index]; |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2300 | |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 2301 | if (uniform.isSampler()) |
| 2302 | { |
| 2303 | *v = getSamplerUniformBinding(uniformLocation); |
| 2304 | return; |
| 2305 | } |
| 2306 | |
| 2307 | const GLenum nativeType = VariableComponentType(uniform.type); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2308 | if (nativeType == GL_UNSIGNED_INT) |
| 2309 | { |
| 2310 | mProgram->getUniformuiv(context, location, v); |
| 2311 | } |
| 2312 | else |
| 2313 | { |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 2314 | getUniformInternal(context, v, location, nativeType, VariableComponentCount(uniform.type)); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 2315 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2316 | } |
| 2317 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2318 | void Program::flagForDeletion() |
| 2319 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2320 | ASSERT(mLinkResolved); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2321 | mDeleteStatus = true; |
| 2322 | } |
| 2323 | |
| 2324 | bool Program::isFlaggedForDeletion() const |
| 2325 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2326 | ASSERT(mLinkResolved); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2327 | return mDeleteStatus; |
| 2328 | } |
daniel@transgaming.com | 86a7a13 | 2010-04-29 03:32:32 +0000 | [diff] [blame] | 2329 | |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 2330 | void Program::validate(const Caps &caps) |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 2331 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2332 | ASSERT(mLinkResolved); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 2333 | mInfoLog.reset(); |
| 2334 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2335 | if (mLinked) |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 2336 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2337 | mValidated = ConvertToBool(mProgram->validate(caps, &mInfoLog)); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 2338 | } |
| 2339 | else |
| 2340 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 2341 | mInfoLog << "Program has not been successfully linked."; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 2342 | } |
| 2343 | } |
| 2344 | |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 2345 | bool Program::validateSamplersImpl(InfoLog *infoLog, const Caps &caps) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2346 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2347 | ASSERT(mLinkResolved); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 2348 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2349 | // if any two active samplers in a program are of different types, but refer to the same |
| 2350 | // texture image unit, and this is the current program, then ValidateProgram will fail, and |
| 2351 | // DrawArrays and DrawElements will issue the INVALID_OPERATION error. |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 2352 | for (size_t textureUnit : mState.mActiveSamplersMask) |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2353 | { |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 2354 | if (mState.mActiveSamplerTypes[textureUnit] == TextureType::InvalidEnum) |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2355 | { |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 2356 | if (infoLog) |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2357 | { |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 2358 | (*infoLog) << "Samplers of conflicting types refer to the same texture " |
| 2359 | "image unit (" |
| 2360 | << textureUnit << ")."; |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2361 | } |
| 2362 | |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 2363 | mCachedValidateSamplersResult = false; |
| 2364 | return false; |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2365 | } |
| 2366 | } |
| 2367 | |
| 2368 | mCachedValidateSamplersResult = true; |
| 2369 | return true; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2370 | } |
| 2371 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 2372 | bool Program::isValidated() const |
| 2373 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2374 | ASSERT(mLinkResolved); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2375 | return mValidated; |
| 2376 | } |
| 2377 | |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 2378 | GLuint Program::getActiveAtomicCounterBufferCount() const |
| 2379 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2380 | ASSERT(mLinkResolved); |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 2381 | return static_cast<GLuint>(mState.mAtomicCounterBuffers.size()); |
| 2382 | } |
| 2383 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2384 | GLuint Program::getActiveShaderStorageBlockCount() const |
| 2385 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2386 | ASSERT(mLinkResolved); |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2387 | return static_cast<GLuint>(mState.mShaderStorageBlocks.size()); |
| 2388 | } |
| 2389 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 2390 | void Program::getActiveUniformBlockName(const GLuint blockIndex, |
| 2391 | GLsizei bufSize, |
| 2392 | GLsizei *length, |
| 2393 | GLchar *blockName) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2394 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2395 | ASSERT(mLinkResolved); |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 2396 | GetInterfaceBlockName(blockIndex, mState.mUniformBlocks, bufSize, length, blockName); |
| 2397 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2398 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 2399 | void Program::getActiveShaderStorageBlockName(const GLuint blockIndex, |
| 2400 | GLsizei bufSize, |
| 2401 | GLsizei *length, |
| 2402 | GLchar *blockName) const |
| 2403 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2404 | ASSERT(mLinkResolved); |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 2405 | GetInterfaceBlockName(blockIndex, mState.mShaderStorageBlocks, bufSize, length, blockName); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 2406 | } |
| 2407 | |
Qin Jiajia | 9bf5552 | 2018-01-29 13:56:23 +0800 | [diff] [blame] | 2408 | template <typename T> |
| 2409 | GLint Program::getActiveInterfaceBlockMaxNameLength(const std::vector<T> &resources) const |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 2410 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2411 | int maxLength = 0; |
| 2412 | |
| 2413 | if (mLinked) |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 2414 | { |
Qin Jiajia | 9bf5552 | 2018-01-29 13:56:23 +0800 | [diff] [blame] | 2415 | for (const T &resource : resources) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2416 | { |
Qin Jiajia | 9bf5552 | 2018-01-29 13:56:23 +0800 | [diff] [blame] | 2417 | if (!resource.name.empty()) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2418 | { |
Qin Jiajia | 9bf5552 | 2018-01-29 13:56:23 +0800 | [diff] [blame] | 2419 | int length = static_cast<int>(resource.nameWithArrayIndex().length()); |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 2420 | maxLength = std::max(length + 1, maxLength); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2421 | } |
| 2422 | } |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 2423 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2424 | |
| 2425 | return maxLength; |
| 2426 | } |
| 2427 | |
Qin Jiajia | 9bf5552 | 2018-01-29 13:56:23 +0800 | [diff] [blame] | 2428 | GLint Program::getActiveUniformBlockMaxNameLength() const |
| 2429 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2430 | ASSERT(mLinkResolved); |
Qin Jiajia | 9bf5552 | 2018-01-29 13:56:23 +0800 | [diff] [blame] | 2431 | return getActiveInterfaceBlockMaxNameLength(mState.mUniformBlocks); |
| 2432 | } |
| 2433 | |
| 2434 | GLint Program::getActiveShaderStorageBlockMaxNameLength() const |
| 2435 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2436 | ASSERT(mLinkResolved); |
Qin Jiajia | 9bf5552 | 2018-01-29 13:56:23 +0800 | [diff] [blame] | 2437 | return getActiveInterfaceBlockMaxNameLength(mState.mShaderStorageBlocks); |
| 2438 | } |
| 2439 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 2440 | GLuint Program::getUniformBlockIndex(const std::string &name) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2441 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2442 | ASSERT(mLinkResolved); |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 2443 | return GetInterfaceBlockIndex(mState.mUniformBlocks, name); |
| 2444 | } |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2445 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 2446 | GLuint Program::getShaderStorageBlockIndex(const std::string &name) const |
| 2447 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2448 | ASSERT(mLinkResolved); |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 2449 | return GetInterfaceBlockIndex(mState.mShaderStorageBlocks, name); |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2452 | const InterfaceBlock &Program::getUniformBlockByIndex(GLuint index) const |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2453 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2454 | ASSERT(mLinkResolved); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2455 | ASSERT(index < static_cast<GLuint>(mState.mUniformBlocks.size())); |
| 2456 | return mState.mUniformBlocks[index]; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2457 | } |
| 2458 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 2459 | const InterfaceBlock &Program::getShaderStorageBlockByIndex(GLuint index) const |
| 2460 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2461 | ASSERT(mLinkResolved); |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 2462 | ASSERT(index < static_cast<GLuint>(mState.mShaderStorageBlocks.size())); |
| 2463 | return mState.mShaderStorageBlocks[index]; |
| 2464 | } |
| 2465 | |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 2466 | void Program::bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding) |
| 2467 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2468 | ASSERT(mLinkResolved); |
jchen10 | 7a20b97 | 2017-06-13 14:25:26 +0800 | [diff] [blame] | 2469 | mState.mUniformBlocks[uniformBlockIndex].binding = uniformBlockBinding; |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 2470 | mState.mActiveUniformBlockBindings.set(uniformBlockIndex, uniformBlockBinding != 0); |
Jamie Madill | 70aeda4 | 2018-08-20 12:17:40 -0400 | [diff] [blame] | 2471 | mDirtyBits.set(DIRTY_BIT_UNIFORM_BLOCK_BINDING_0 + uniformBlockIndex); |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | GLuint Program::getUniformBlockBinding(GLuint uniformBlockIndex) const |
| 2475 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2476 | ASSERT(mLinkResolved); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2477 | return mState.getUniformBlockBinding(uniformBlockIndex); |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 2478 | } |
| 2479 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2480 | GLuint Program::getShaderStorageBlockBinding(GLuint shaderStorageBlockIndex) const |
| 2481 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2482 | ASSERT(mLinkResolved); |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2483 | return mState.getShaderStorageBlockBinding(shaderStorageBlockIndex); |
| 2484 | } |
| 2485 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2486 | void Program::setTransformFeedbackVaryings(GLsizei count, |
| 2487 | const GLchar *const *varyings, |
| 2488 | GLenum bufferMode) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2489 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2490 | ASSERT(mLinkResolved); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2491 | mState.mTransformFeedbackVaryingNames.resize(count); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2492 | for (GLsizei i = 0; i < count; i++) |
| 2493 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2494 | mState.mTransformFeedbackVaryingNames[i] = varyings[i]; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2495 | } |
| 2496 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2497 | mState.mTransformFeedbackBufferMode = bufferMode; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2498 | } |
| 2499 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2500 | void Program::getTransformFeedbackVarying(GLuint index, |
| 2501 | GLsizei bufSize, |
| 2502 | GLsizei *length, |
| 2503 | GLsizei *size, |
| 2504 | GLenum *type, |
| 2505 | GLchar *name) const |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2506 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2507 | ASSERT(mLinkResolved); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2508 | if (mLinked) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2509 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2510 | ASSERT(index < mState.mLinkedTransformFeedbackVaryings.size()); |
| 2511 | const auto &var = mState.mLinkedTransformFeedbackVaryings[index]; |
| 2512 | std::string varName = var.nameWithArrayIndex(); |
| 2513 | GLsizei lastNameIdx = std::min(bufSize - 1, static_cast<GLsizei>(varName.length())); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2514 | if (length) |
| 2515 | { |
| 2516 | *length = lastNameIdx; |
| 2517 | } |
| 2518 | if (size) |
| 2519 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2520 | *size = var.size(); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2521 | } |
| 2522 | if (type) |
| 2523 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2524 | *type = var.type; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2525 | } |
| 2526 | if (name) |
| 2527 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2528 | memcpy(name, varName.c_str(), lastNameIdx); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2529 | name[lastNameIdx] = '\0'; |
| 2530 | } |
| 2531 | } |
| 2532 | } |
| 2533 | |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 2534 | GLsizei Program::getTransformFeedbackVaryingCount() const |
| 2535 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2536 | ASSERT(mLinkResolved); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2537 | if (mLinked) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2538 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2539 | return static_cast<GLsizei>(mState.mLinkedTransformFeedbackVaryings.size()); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2540 | } |
| 2541 | else |
| 2542 | { |
| 2543 | return 0; |
| 2544 | } |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | GLsizei Program::getTransformFeedbackVaryingMaxLength() const |
| 2548 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2549 | ASSERT(mLinkResolved); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2550 | if (mLinked) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2551 | { |
| 2552 | GLsizei maxSize = 0; |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2553 | for (const auto &var : mState.mLinkedTransformFeedbackVaryings) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2554 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 2555 | maxSize = |
| 2556 | std::max(maxSize, static_cast<GLsizei>(var.nameWithArrayIndex().length() + 1)); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | return maxSize; |
| 2560 | } |
| 2561 | else |
| 2562 | { |
| 2563 | return 0; |
| 2564 | } |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | GLenum Program::getTransformFeedbackBufferMode() const |
| 2568 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2569 | ASSERT(mLinkResolved); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2570 | return mState.mTransformFeedbackBufferMode; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2571 | } |
| 2572 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2573 | bool Program::linkValidateShaders(InfoLog &infoLog) |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2574 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 2575 | Shader *vertexShader = mState.mAttachedShaders[ShaderType::Vertex]; |
| 2576 | Shader *fragmentShader = mState.mAttachedShaders[ShaderType::Fragment]; |
| 2577 | Shader *computeShader = mState.mAttachedShaders[ShaderType::Compute]; |
| 2578 | Shader *geometryShader = mState.mAttachedShaders[ShaderType::Geometry]; |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2579 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2580 | bool isComputeShaderAttached = (computeShader != nullptr); |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 2581 | bool isGraphicsShaderAttached = |
| 2582 | (vertexShader != nullptr || fragmentShader != nullptr || geometryShader != nullptr); |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2583 | // Check whether we both have a compute and non-compute shaders attached. |
| 2584 | // If there are of both types attached, then linking should fail. |
| 2585 | // OpenGL ES 3.10, 7.3 Program Objects, under LinkProgram |
| 2586 | if (isComputeShaderAttached == true && isGraphicsShaderAttached == true) |
| 2587 | { |
| 2588 | infoLog << "Both compute and graphics shaders are attached to the same program."; |
| 2589 | return false; |
| 2590 | } |
| 2591 | |
| 2592 | if (computeShader) |
| 2593 | { |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2594 | if (!computeShader->isCompiled()) |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2595 | { |
| 2596 | infoLog << "Attached compute shader is not compiled."; |
| 2597 | return false; |
| 2598 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 2599 | ASSERT(computeShader->getType() == ShaderType::Compute); |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2600 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2601 | mState.mComputeShaderLocalSize = computeShader->getWorkGroupSize(); |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2602 | |
| 2603 | // GLSL ES 3.10, 4.4.1.1 Compute Shader Inputs |
| 2604 | // If the work group size is not specified, a link time error should occur. |
| 2605 | if (!mState.mComputeShaderLocalSize.isDeclared()) |
| 2606 | { |
| 2607 | infoLog << "Work group size is not specified."; |
| 2608 | return false; |
| 2609 | } |
| 2610 | } |
| 2611 | else |
| 2612 | { |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2613 | if (!fragmentShader || !fragmentShader->isCompiled()) |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2614 | { |
| 2615 | infoLog << "No compiled fragment shader when at least one graphics shader is attached."; |
| 2616 | return false; |
| 2617 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 2618 | ASSERT(fragmentShader->getType() == ShaderType::Fragment); |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2619 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2620 | if (!vertexShader || !vertexShader->isCompiled()) |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2621 | { |
| 2622 | infoLog << "No compiled vertex shader when at least one graphics shader is attached."; |
| 2623 | return false; |
| 2624 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 2625 | ASSERT(vertexShader->getType() == ShaderType::Vertex); |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2626 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2627 | int vertexShaderVersion = vertexShader->getShaderVersion(); |
| 2628 | if (fragmentShader->getShaderVersion() != vertexShaderVersion) |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2629 | { |
| 2630 | infoLog << "Fragment shader version does not match vertex shader version."; |
| 2631 | return false; |
| 2632 | } |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 2633 | |
| 2634 | if (geometryShader) |
| 2635 | { |
| 2636 | // [GL_EXT_geometry_shader] Chapter 7 |
| 2637 | // Linking can fail for a variety of reasons as specified in the OpenGL ES Shading |
| 2638 | // Language Specification, as well as any of the following reasons: |
| 2639 | // * One or more of the shader objects attached to <program> are not compiled |
| 2640 | // successfully. |
| 2641 | // * The shaders do not use the same shader language version. |
| 2642 | // * <program> contains objects to form a geometry shader, and |
| 2643 | // - <program> is not separable and contains no objects to form a vertex shader; or |
| 2644 | // - the input primitive type, output primitive type, or maximum output vertex count |
| 2645 | // is not specified in the compiled geometry shader object. |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2646 | if (!geometryShader->isCompiled()) |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 2647 | { |
| 2648 | infoLog << "The attached geometry shader isn't compiled."; |
| 2649 | return false; |
| 2650 | } |
| 2651 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2652 | if (geometryShader->getShaderVersion() != vertexShaderVersion) |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 2653 | { |
| 2654 | mInfoLog << "Geometry shader version does not match vertex shader version."; |
| 2655 | return false; |
| 2656 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 2657 | ASSERT(geometryShader->getType() == ShaderType::Geometry); |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 2658 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2659 | Optional<PrimitiveMode> inputPrimitive = |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2660 | geometryShader->getGeometryShaderInputPrimitiveType(); |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 2661 | if (!inputPrimitive.valid()) |
| 2662 | { |
| 2663 | mInfoLog << "Input primitive type is not specified in the geometry shader."; |
| 2664 | return false; |
| 2665 | } |
| 2666 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2667 | Optional<PrimitiveMode> outputPrimitive = |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2668 | geometryShader->getGeometryShaderOutputPrimitiveType(); |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 2669 | if (!outputPrimitive.valid()) |
| 2670 | { |
| 2671 | mInfoLog << "Output primitive type is not specified in the geometry shader."; |
| 2672 | return false; |
| 2673 | } |
| 2674 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2675 | Optional<GLint> maxVertices = geometryShader->getGeometryShaderMaxVertices(); |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 2676 | if (!maxVertices.valid()) |
| 2677 | { |
| 2678 | mInfoLog << "'max_vertices' is not specified in the geometry shader."; |
| 2679 | return false; |
| 2680 | } |
| 2681 | |
| 2682 | mState.mGeometryShaderInputPrimitiveType = inputPrimitive.value(); |
| 2683 | mState.mGeometryShaderOutputPrimitiveType = outputPrimitive.value(); |
| 2684 | mState.mGeometryShaderMaxVertices = maxVertices.value(); |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2685 | mState.mGeometryShaderInvocations = geometryShader->getGeometryShaderInvocations(); |
Jiawei Shao | 4ed05da | 2018-02-02 14:26:15 +0800 | [diff] [blame] | 2686 | } |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | return true; |
| 2690 | } |
| 2691 | |
jchen10 | 910a3da | 2017-11-15 09:40:11 +0800 | [diff] [blame] | 2692 | GLuint Program::getTransformFeedbackVaryingResourceIndex(const GLchar *name) const |
| 2693 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2694 | ASSERT(mLinkResolved); |
jchen10 | 910a3da | 2017-11-15 09:40:11 +0800 | [diff] [blame] | 2695 | for (GLuint tfIndex = 0; tfIndex < mState.mLinkedTransformFeedbackVaryings.size(); ++tfIndex) |
| 2696 | { |
| 2697 | const auto &tf = mState.mLinkedTransformFeedbackVaryings[tfIndex]; |
| 2698 | if (tf.nameWithArrayIndex() == name) |
| 2699 | { |
| 2700 | return tfIndex; |
| 2701 | } |
| 2702 | } |
| 2703 | return GL_INVALID_INDEX; |
| 2704 | } |
| 2705 | |
| 2706 | const TransformFeedbackVarying &Program::getTransformFeedbackVaryingResource(GLuint index) const |
| 2707 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2708 | ASSERT(mLinkResolved); |
jchen10 | 910a3da | 2017-11-15 09:40:11 +0800 | [diff] [blame] | 2709 | ASSERT(index < mState.mLinkedTransformFeedbackVaryings.size()); |
| 2710 | return mState.mLinkedTransformFeedbackVaryings[index]; |
| 2711 | } |
| 2712 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2713 | bool Program::linkVaryings(InfoLog &infoLog) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2714 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 2715 | Shader *previousShader = nullptr; |
| 2716 | for (ShaderType shaderType : kAllGraphicsShaderTypes) |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2717 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 2718 | Shader *currentShader = mState.mAttachedShaders[shaderType]; |
| 2719 | if (!currentShader) |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2720 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 2721 | continue; |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2722 | } |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 2723 | |
| 2724 | if (previousShader) |
| 2725 | { |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2726 | if (!linkValidateShaderInterfaceMatching(previousShader, currentShader, infoLog)) |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 2727 | { |
| 2728 | return false; |
| 2729 | } |
| 2730 | } |
| 2731 | previousShader = currentShader; |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2732 | } |
| 2733 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2734 | if (!linkValidateBuiltInVaryings(infoLog)) |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2735 | { |
| 2736 | return false; |
| 2737 | } |
| 2738 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2739 | if (!linkValidateFragmentInputBindings(infoLog)) |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2740 | { |
| 2741 | return false; |
| 2742 | } |
| 2743 | |
| 2744 | return true; |
| 2745 | } |
| 2746 | |
| 2747 | // [OpenGL ES 3.1] Chapter 7.4.1 "Shader Interface Matchining" Page 91 |
| 2748 | // TODO(jiawei.shao@intel.com): add validation on input/output blocks matching |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2749 | bool Program::linkValidateShaderInterfaceMatching(gl::Shader *generatingShader, |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2750 | gl::Shader *consumingShader, |
| 2751 | gl::InfoLog &infoLog) const |
| 2752 | { |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2753 | ASSERT(generatingShader->getShaderVersion() == consumingShader->getShaderVersion()); |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 2754 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2755 | const std::vector<sh::Varying> &outputVaryings = generatingShader->getOutputVaryings(); |
| 2756 | const std::vector<sh::Varying> &inputVaryings = consumingShader->getInputVaryings(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2757 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 2758 | bool validateGeometryShaderInputs = consumingShader->getType() == ShaderType::Geometry; |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2759 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2760 | for (const sh::Varying &input : inputVaryings) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2761 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2762 | bool matched = false; |
| 2763 | |
| 2764 | // Built-in varyings obey special rules |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2765 | if (input.isBuiltIn()) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2766 | { |
| 2767 | continue; |
| 2768 | } |
| 2769 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2770 | for (const sh::Varying &output : outputVaryings) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2771 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2772 | if (input.name == output.name) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2773 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2774 | ASSERT(!output.isBuiltIn()); |
| 2775 | |
| 2776 | std::string mismatchedStructFieldName; |
| 2777 | LinkMismatchError linkError = |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2778 | LinkValidateVaryings(output, input, generatingShader->getShaderVersion(), |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2779 | validateGeometryShaderInputs, &mismatchedStructFieldName); |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2780 | if (linkError != LinkMismatchError::NO_MISMATCH) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2781 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2782 | LogLinkMismatch(infoLog, input.name, "varying", linkError, |
| 2783 | mismatchedStructFieldName, generatingShader->getType(), |
| 2784 | consumingShader->getType()); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2785 | return false; |
| 2786 | } |
| 2787 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2788 | matched = true; |
| 2789 | break; |
| 2790 | } |
| 2791 | } |
| 2792 | |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 2793 | // We permit unmatched, unreferenced varyings. Note that this specifically depends on |
| 2794 | // whether the input is statically used - a statically used input should fail this test even |
| 2795 | // if it is not active. GLSL ES 3.00.6 section 4.3.10. |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2796 | if (!matched && input.staticUse) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2797 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2798 | infoLog << GetShaderTypeString(consumingShader->getType()) << " varying " << input.name |
| 2799 | << " does not match any " << GetShaderTypeString(generatingShader->getType()) |
| 2800 | << " varying"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2801 | return false; |
| 2802 | } |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2803 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2804 | |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2805 | // TODO(jmadill): verify no unmatched output varyings? |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2806 | |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2807 | return true; |
| 2808 | } |
| 2809 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2810 | bool Program::linkValidateFragmentInputBindings(gl::InfoLog &infoLog) const |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2811 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 2812 | ASSERT(mState.mAttachedShaders[ShaderType::Fragment]); |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2813 | |
| 2814 | std::map<GLuint, std::string> staticFragmentInputLocations; |
| 2815 | |
| 2816 | const std::vector<sh::Varying> &fragmentInputVaryings = |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2817 | mState.mAttachedShaders[ShaderType::Fragment]->getInputVaryings(); |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2818 | for (const sh::Varying &input : fragmentInputVaryings) |
| 2819 | { |
| 2820 | if (input.isBuiltIn() || !input.staticUse) |
| 2821 | { |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2822 | continue; |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 2823 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2824 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2825 | const auto inputBinding = mFragmentInputBindings.getBinding(input.name); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2826 | if (inputBinding == -1) |
| 2827 | continue; |
| 2828 | |
| 2829 | const auto it = staticFragmentInputLocations.find(inputBinding); |
| 2830 | if (it == std::end(staticFragmentInputLocations)) |
| 2831 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2832 | staticFragmentInputLocations.insert(std::make_pair(inputBinding, input.name)); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2833 | } |
| 2834 | else |
| 2835 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 2836 | infoLog << "Binding for fragment input " << input.name << " conflicts with " |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2837 | << it->second; |
| 2838 | return false; |
| 2839 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | return true; |
| 2843 | } |
| 2844 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2845 | bool Program::linkUniforms(const Caps &caps, |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2846 | InfoLog &infoLog, |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 2847 | const ProgramBindings &uniformLocationBindings, |
Luc Ferron | e17b5ba | 2018-06-04 14:28:58 -0400 | [diff] [blame] | 2848 | GLuint *combinedImageUniformsCount, |
| 2849 | std::vector<UnusedUniform> *unusedUniforms) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 2850 | { |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 2851 | UniformLinker linker(mState); |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2852 | if (!linker.link(caps, infoLog, uniformLocationBindings)) |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2853 | { |
| 2854 | return false; |
| 2855 | } |
| 2856 | |
Luc Ferron | e17b5ba | 2018-06-04 14:28:58 -0400 | [diff] [blame] | 2857 | linker.getResults(&mState.mUniforms, unusedUniforms, &mState.mUniformLocations); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2858 | |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 2859 | linkSamplerAndImageBindings(combinedImageUniformsCount); |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2860 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2861 | if (!linkAtomicCounterBuffers()) |
| 2862 | { |
| 2863 | return false; |
| 2864 | } |
| 2865 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2866 | return true; |
| 2867 | } |
| 2868 | |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 2869 | void Program::linkSamplerAndImageBindings(GLuint *combinedImageUniforms) |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2870 | { |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 2871 | ASSERT(combinedImageUniforms); |
| 2872 | |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 2873 | unsigned int high = static_cast<unsigned int>(mState.mUniforms.size()); |
| 2874 | unsigned int low = high; |
| 2875 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2876 | for (auto counterIter = mState.mUniforms.rbegin(); |
| 2877 | counterIter != mState.mUniforms.rend() && counterIter->isAtomicCounter(); ++counterIter) |
| 2878 | { |
| 2879 | --low; |
| 2880 | } |
| 2881 | |
| 2882 | mState.mAtomicCounterUniformRange = RangeUI(low, high); |
| 2883 | |
| 2884 | high = low; |
| 2885 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2886 | for (auto imageIter = mState.mUniforms.rbegin(); |
| 2887 | imageIter != mState.mUniforms.rend() && imageIter->isImage(); ++imageIter) |
| 2888 | { |
| 2889 | --low; |
| 2890 | } |
| 2891 | |
| 2892 | mState.mImageUniformRange = RangeUI(low, high); |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 2893 | *combinedImageUniforms = 0u; |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2894 | // If uniform is a image type, insert it into the mImageBindings array. |
| 2895 | for (unsigned int imageIndex : mState.mImageUniformRange) |
| 2896 | { |
Xinghua Cao | 0328b57 | 2017-06-26 15:51:36 +0800 | [diff] [blame] | 2897 | // ES3.1 (section 7.6.1) and GLSL ES3.1 (section 4.4.5), Uniform*i{v} commands |
| 2898 | // cannot load values into a uniform defined as an image. if declare without a |
| 2899 | // binding qualifier, any uniform image variable (include all elements of |
| 2900 | // unbound image array) shoud be bound to unit zero. |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2901 | auto &imageUniform = mState.mUniforms[imageIndex]; |
| 2902 | if (imageUniform.binding == -1) |
| 2903 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 2904 | mState.mImageBindings.emplace_back( |
| 2905 | ImageBinding(imageUniform.getBasicTypeElementCount())); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2906 | } |
Xinghua Cao | 0328b57 | 2017-06-26 15:51:36 +0800 | [diff] [blame] | 2907 | else |
| 2908 | { |
| 2909 | mState.mImageBindings.emplace_back( |
Qin Jiajia | 47f6dd0 | 2018-08-10 13:36:32 +0800 | [diff] [blame] | 2910 | ImageBinding(imageUniform.binding, imageUniform.getBasicTypeElementCount(), false)); |
Xinghua Cao | 0328b57 | 2017-06-26 15:51:36 +0800 | [diff] [blame] | 2911 | } |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 2912 | |
| 2913 | GLuint arraySize = imageUniform.isArray() ? imageUniform.arraySizes[0] : 1u; |
| 2914 | *combinedImageUniforms += imageUniform.activeShaderCount() * arraySize; |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | high = low; |
| 2918 | |
| 2919 | for (auto samplerIter = mState.mUniforms.rbegin() + mState.mImageUniformRange.length(); |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 2920 | samplerIter != mState.mUniforms.rend() && samplerIter->isSampler(); ++samplerIter) |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2921 | { |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 2922 | --low; |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2923 | } |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 2924 | |
| 2925 | mState.mSamplerUniformRange = RangeUI(low, high); |
| 2926 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2927 | // If uniform is a sampler type, insert it into the mSamplerBindings array. |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 2928 | for (unsigned int samplerIndex : mState.mSamplerUniformRange) |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2929 | { |
| 2930 | const auto &samplerUniform = mState.mUniforms[samplerIndex]; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2931 | TextureType textureType = SamplerTypeToTextureType(samplerUniform.type); |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 2932 | unsigned int elementCount = samplerUniform.getBasicTypeElementCount(); |
| 2933 | mState.mSamplerBindings.emplace_back(textureType, elementCount, false); |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 2934 | } |
| 2935 | } |
| 2936 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2937 | bool Program::linkAtomicCounterBuffers() |
| 2938 | { |
| 2939 | for (unsigned int index : mState.mAtomicCounterUniformRange) |
| 2940 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2941 | auto &uniform = mState.mUniforms[index]; |
Jiajia Qin | 94f1e89 | 2017-11-20 12:14:32 +0800 | [diff] [blame] | 2942 | uniform.blockInfo.offset = uniform.offset; |
| 2943 | uniform.blockInfo.arrayStride = (uniform.isArray() ? 4 : 0); |
| 2944 | uniform.blockInfo.matrixStride = 0; |
| 2945 | uniform.blockInfo.isRowMajorMatrix = false; |
| 2946 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2947 | bool found = false; |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2948 | for (unsigned int bufferIndex = 0; bufferIndex < mState.mAtomicCounterBuffers.size(); |
| 2949 | ++bufferIndex) |
| 2950 | { |
| 2951 | auto &buffer = mState.mAtomicCounterBuffers[bufferIndex]; |
| 2952 | if (buffer.binding == uniform.binding) |
| 2953 | { |
| 2954 | buffer.memberIndexes.push_back(index); |
| 2955 | uniform.bufferIndex = bufferIndex; |
| 2956 | found = true; |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 2957 | buffer.unionReferencesWith(uniform); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2958 | break; |
| 2959 | } |
| 2960 | } |
| 2961 | if (!found) |
| 2962 | { |
| 2963 | AtomicCounterBuffer atomicCounterBuffer; |
| 2964 | atomicCounterBuffer.binding = uniform.binding; |
| 2965 | atomicCounterBuffer.memberIndexes.push_back(index); |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 2966 | atomicCounterBuffer.unionReferencesWith(uniform); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2967 | mState.mAtomicCounterBuffers.push_back(atomicCounterBuffer); |
| 2968 | uniform.bufferIndex = static_cast<int>(mState.mAtomicCounterBuffers.size() - 1); |
| 2969 | } |
| 2970 | } |
| 2971 | // TODO(jie.a.chen@intel.com): Count each atomic counter buffer to validate against |
Jiawei Shao | 0d88ec9 | 2018-02-27 16:25:31 +0800 | [diff] [blame] | 2972 | // gl_Max[Vertex|Fragment|Compute|Geometry|Combined]AtomicCounterBuffers. |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 2973 | |
| 2974 | return true; |
| 2975 | } |
| 2976 | |
Jamie Madill | eb979bf | 2016-11-15 12:28:46 -0500 | [diff] [blame] | 2977 | // Assigns locations to all attributes from the bindings and program locations. |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2978 | bool Program::linkAttributes(const Caps &caps, InfoLog &infoLog) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2979 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 2980 | Shader *vertexShader = mState.getAttachedShader(ShaderType::Vertex); |
Jamie Madill | eb979bf | 2016-11-15 12:28:46 -0500 | [diff] [blame] | 2981 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2982 | int shaderVersion = vertexShader->getShaderVersion(); |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 2983 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2984 | unsigned int usedLocations = 0; |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 2985 | if (shaderVersion >= 300) |
| 2986 | { |
| 2987 | // In GLSL ES 3.00.6, aliasing checks should be done with all declared attributes - see GLSL |
| 2988 | // ES 3.00.6 section 12.46. Inactive attributes will be pruned after aliasing checks. |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2989 | mState.mAttributes = vertexShader->getAllAttributes(); |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 2990 | } |
| 2991 | else |
| 2992 | { |
| 2993 | // In GLSL ES 1.00.17 we only do aliasing checks for active attributes. |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2994 | mState.mAttributes = vertexShader->getActiveAttributes(); |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 2995 | } |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 2996 | GLuint maxAttribs = caps.maxVertexAttributes; |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 2997 | |
| 2998 | // TODO(jmadill): handle aliasing robustly |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 2999 | if (mState.mAttributes.size() > maxAttribs) |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 3000 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 3001 | infoLog << "Too many vertex attributes."; |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 3002 | return false; |
| 3003 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3004 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3005 | std::vector<sh::Attribute *> usedAttribMap(maxAttribs, nullptr); |
Jamie Madill | 4e10722 | 2015-08-24 14:12:17 +0000 | [diff] [blame] | 3006 | |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 3007 | // Assign locations to attributes that have a binding location and check for attribute aliasing. |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 3008 | for (sh::Attribute &attribute : mState.mAttributes) |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 3009 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 3010 | // GLSL ES 3.10 January 2016 section 4.3.4: Vertex shader inputs can't be arrays or |
| 3011 | // structures, so we don't need to worry about adjusting their names or generating entries |
| 3012 | // for each member/element (unlike uniforms for example). |
| 3013 | ASSERT(!attribute.isArray() && !attribute.isStruct()); |
| 3014 | |
Jamie Madill | eb979bf | 2016-11-15 12:28:46 -0500 | [diff] [blame] | 3015 | int bindingLocation = mAttributeBindings.getBinding(attribute.name); |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 3016 | if (attribute.location == -1 && bindingLocation != -1) |
Jamie Madill | 2d77318 | 2015-08-18 10:27:28 -0400 | [diff] [blame] | 3017 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 3018 | attribute.location = bindingLocation; |
| 3019 | } |
| 3020 | |
| 3021 | if (attribute.location != -1) |
| 3022 | { |
| 3023 | // Location is set by glBindAttribLocation or by location layout qualifier |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3024 | const int regs = VariableRegisterCount(attribute.type); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3025 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3026 | if (static_cast<GLuint>(regs + attribute.location) > maxAttribs) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3027 | { |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 3028 | infoLog << "Attribute (" << attribute.name << ") at location " << attribute.location |
| 3029 | << " is too big to fit"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3030 | |
| 3031 | return false; |
| 3032 | } |
| 3033 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3034 | for (int reg = 0; reg < regs; reg++) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3035 | { |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3036 | const int regLocation = attribute.location + reg; |
| 3037 | sh::ShaderVariable *linkedAttribute = usedAttribMap[regLocation]; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3038 | |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 3039 | // In GLSL ES 3.00.6 and in WebGL, attribute aliasing produces a link error. |
| 3040 | // In non-WebGL GLSL ES 1.00.17, attribute aliasing is allowed with some |
| 3041 | // restrictions - see GLSL ES 1.00.17 section 2.10.4, but ANGLE currently has a bug. |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 3042 | if (linkedAttribute) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3043 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 3044 | // TODO(jmadill): fix aliasing on ES2 |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 3045 | // if (shaderVersion >= 300 && !webgl) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3046 | { |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 3047 | infoLog << "Attribute '" << attribute.name << "' aliases attribute '" |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3048 | << linkedAttribute->name << "' at location " << regLocation; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3049 | return false; |
| 3050 | } |
| 3051 | } |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 3052 | else |
| 3053 | { |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3054 | usedAttribMap[regLocation] = &attribute; |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 3055 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3056 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3057 | usedLocations |= 1 << regLocation; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3058 | } |
| 3059 | } |
| 3060 | } |
| 3061 | |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 3062 | // Assign locations to attributes that don't have a binding location. |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 3063 | for (sh::Attribute &attribute : mState.mAttributes) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3064 | { |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 3065 | // Not set by glBindAttribLocation or by location layout qualifier |
| 3066 | if (attribute.location == -1) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3067 | { |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3068 | int regs = VariableRegisterCount(attribute.type); |
| 3069 | int availableIndex = AllocateFirstFreeBits(&usedLocations, regs, maxAttribs); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3070 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3071 | if (availableIndex == -1 || static_cast<GLuint>(availableIndex + regs) > maxAttribs) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3072 | { |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 3073 | infoLog << "Too many attributes (" << attribute.name << ")"; |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 3074 | return false; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3075 | } |
| 3076 | |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 3077 | attribute.location = availableIndex; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3078 | } |
| 3079 | } |
| 3080 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 3081 | ASSERT(mState.mAttributesTypeMask.none()); |
| 3082 | ASSERT(mState.mAttributesMask.none()); |
| 3083 | |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 3084 | // Prune inactive attributes. This step is only needed on shaderVersion >= 300 since on earlier |
| 3085 | // shader versions we're only processing active attributes to begin with. |
| 3086 | if (shaderVersion >= 300) |
| 3087 | { |
| 3088 | for (auto attributeIter = mState.mAttributes.begin(); |
| 3089 | attributeIter != mState.mAttributes.end();) |
| 3090 | { |
| 3091 | if (attributeIter->active) |
| 3092 | { |
| 3093 | ++attributeIter; |
| 3094 | } |
| 3095 | else |
| 3096 | { |
| 3097 | attributeIter = mState.mAttributes.erase(attributeIter); |
| 3098 | } |
| 3099 | } |
| 3100 | } |
| 3101 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 3102 | for (const sh::Attribute &attribute : mState.mAttributes) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3103 | { |
Olli Etuaho | ebd6e2d | 2018-03-23 17:07:55 +0200 | [diff] [blame] | 3104 | ASSERT(attribute.active); |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3105 | ASSERT(attribute.location != -1); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 3106 | unsigned int regs = static_cast<unsigned int>(VariableRegisterCount(attribute.type)); |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 3107 | |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 3108 | for (unsigned int r = 0; r < regs; r++) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3109 | { |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 3110 | unsigned int location = static_cast<unsigned int>(attribute.location) + r; |
| 3111 | mState.mActiveAttribLocationsMask.set(location); |
| 3112 | mState.mMaxActiveAttribLocation = |
| 3113 | std::max(mState.mMaxActiveAttribLocation, location + 1); |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 3114 | |
| 3115 | // gl_VertexID and gl_InstanceID are active attributes but don't have a bound attribute. |
| 3116 | if (!attribute.isBuiltIn()) |
| 3117 | { |
| 3118 | mState.mAttributesTypeMask.setIndex(VariableComponentType(attribute.type), |
| 3119 | location); |
| 3120 | mState.mAttributesMask.set(location); |
| 3121 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3122 | } |
| 3123 | } |
| 3124 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3125 | return true; |
| 3126 | } |
| 3127 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3128 | bool Program::linkInterfaceBlocks(const Caps &caps, |
| 3129 | const Version &version, |
| 3130 | bool webglCompatibility, |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 3131 | InfoLog &infoLog, |
| 3132 | GLuint *combinedShaderStorageBlocksCount) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 3133 | { |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 3134 | ASSERT(combinedShaderStorageBlocksCount); |
| 3135 | |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 3136 | GLuint combinedUniformBlocksCount = 0u; |
| 3137 | GLuint numShadersHasUniformBlocks = 0u; |
| 3138 | ShaderMap<const std::vector<sh::InterfaceBlock> *> allShaderUniformBlocks = {}; |
| 3139 | for (ShaderType shaderType : AllShaderTypes()) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 3140 | { |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 3141 | Shader *shader = mState.mAttachedShaders[shaderType]; |
| 3142 | if (!shader) |
| 3143 | { |
| 3144 | continue; |
| 3145 | } |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 3146 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3147 | const auto &uniformBlocks = shader->getUniformBlocks(); |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 3148 | if (!uniformBlocks.empty()) |
Jiawei Shao | 427071e | 2018-03-19 09:21:37 +0800 | [diff] [blame] | 3149 | { |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 3150 | if (!ValidateInterfaceBlocksCount( |
| 3151 | caps.maxShaderUniformBlocks[shaderType], uniformBlocks, shaderType, |
| 3152 | sh::BlockType::BLOCK_UNIFORM, &combinedUniformBlocksCount, infoLog)) |
| 3153 | { |
| 3154 | return false; |
| 3155 | } |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 3156 | |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 3157 | allShaderUniformBlocks[shaderType] = &uniformBlocks; |
| 3158 | ++numShadersHasUniformBlocks; |
| 3159 | } |
Jiawei Shao | 427071e | 2018-03-19 09:21:37 +0800 | [diff] [blame] | 3160 | } |
| 3161 | |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 3162 | if (combinedUniformBlocksCount > caps.maxCombinedUniformBlocks) |
| 3163 | { |
| 3164 | infoLog << "The sum of the number of active uniform blocks exceeds " |
| 3165 | "MAX_COMBINED_UNIFORM_BLOCKS (" |
| 3166 | << caps.maxCombinedUniformBlocks << ")."; |
| 3167 | return false; |
| 3168 | } |
| 3169 | |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 3170 | if (!ValidateInterfaceBlocksMatch(numShadersHasUniformBlocks, allShaderUniformBlocks, infoLog, |
| 3171 | webglCompatibility)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 3172 | { |
| 3173 | return false; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3174 | } |
Jamie Madill | e473dee | 2015-08-18 14:49:01 -0400 | [diff] [blame] | 3175 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3176 | if (version >= Version(3, 1)) |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 3177 | { |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 3178 | *combinedShaderStorageBlocksCount = 0u; |
| 3179 | GLuint numShadersHasShaderStorageBlocks = 0u; |
| 3180 | ShaderMap<const std::vector<sh::InterfaceBlock> *> allShaderStorageBlocks = {}; |
| 3181 | for (ShaderType shaderType : AllShaderTypes()) |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 3182 | { |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 3183 | Shader *shader = mState.mAttachedShaders[shaderType]; |
| 3184 | if (!shader) |
| 3185 | { |
| 3186 | continue; |
| 3187 | } |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 3188 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3189 | const auto &shaderStorageBlocks = shader->getShaderStorageBlocks(); |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 3190 | if (!shaderStorageBlocks.empty()) |
Jiawei Shao | 427071e | 2018-03-19 09:21:37 +0800 | [diff] [blame] | 3191 | { |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 3192 | if (!ValidateInterfaceBlocksCount( |
| 3193 | caps.maxShaderStorageBlocks[shaderType], shaderStorageBlocks, shaderType, |
| 3194 | sh::BlockType::BLOCK_BUFFER, combinedShaderStorageBlocksCount, infoLog)) |
| 3195 | { |
| 3196 | return false; |
| 3197 | } |
Jiawei Shao | 40786bd | 2018-04-18 13:58:57 +0800 | [diff] [blame] | 3198 | |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 3199 | allShaderStorageBlocks[shaderType] = &shaderStorageBlocks; |
| 3200 | ++numShadersHasShaderStorageBlocks; |
| 3201 | } |
Jiawei Shao | 427071e | 2018-03-19 09:21:37 +0800 | [diff] [blame] | 3202 | } |
| 3203 | |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 3204 | if (*combinedShaderStorageBlocksCount > caps.maxCombinedShaderStorageBlocks) |
Jiawei Shao | bb3255b | 2018-04-27 09:45:18 +0800 | [diff] [blame] | 3205 | { |
| 3206 | infoLog << "The sum of the number of active shader storage blocks exceeds " |
| 3207 | "MAX_COMBINED_SHADER_STORAGE_BLOCKS (" |
| 3208 | << caps.maxCombinedShaderStorageBlocks << ")."; |
| 3209 | return false; |
| 3210 | } |
| 3211 | |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 3212 | if (!ValidateInterfaceBlocksMatch(numShadersHasShaderStorageBlocks, allShaderStorageBlocks, |
| 3213 | infoLog, webglCompatibility)) |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 3214 | { |
| 3215 | return false; |
| 3216 | } |
| 3217 | } |
Jiawei Shao | 54aafe5 | 2018-04-27 14:54:57 +0800 | [diff] [blame] | 3218 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3219 | return true; |
| 3220 | } |
| 3221 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3222 | LinkMismatchError Program::LinkValidateVariablesBase(const sh::ShaderVariable &variable1, |
| 3223 | const sh::ShaderVariable &variable2, |
| 3224 | bool validatePrecision, |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 3225 | bool validateArraySize, |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3226 | std::string *mismatchedStructOrBlockMemberName) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3227 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3228 | if (variable1.type != variable2.type) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3229 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3230 | return LinkMismatchError::TYPE_MISMATCH; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3231 | } |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 3232 | if (validateArraySize && variable1.arraySizes != variable2.arraySizes) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3233 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3234 | return LinkMismatchError::ARRAY_SIZE_MISMATCH; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3235 | } |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3236 | if (validatePrecision && variable1.precision != variable2.precision) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3237 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3238 | return LinkMismatchError::PRECISION_MISMATCH; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3239 | } |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3240 | if (variable1.structName != variable2.structName) |
Geoff Lang | bb1e750 | 2017-06-05 16:40:09 -0400 | [diff] [blame] | 3241 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3242 | return LinkMismatchError::STRUCT_NAME_MISMATCH; |
Geoff Lang | bb1e750 | 2017-06-05 16:40:09 -0400 | [diff] [blame] | 3243 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3244 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3245 | if (variable1.fields.size() != variable2.fields.size()) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3246 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3247 | return LinkMismatchError::FIELD_NUMBER_MISMATCH; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3248 | } |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3249 | const unsigned int numMembers = static_cast<unsigned int>(variable1.fields.size()); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3250 | for (unsigned int memberIndex = 0; memberIndex < numMembers; memberIndex++) |
| 3251 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3252 | const sh::ShaderVariable &member1 = variable1.fields[memberIndex]; |
| 3253 | const sh::ShaderVariable &member2 = variable2.fields[memberIndex]; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3254 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3255 | if (member1.name != member2.name) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3256 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3257 | return LinkMismatchError::FIELD_NAME_MISMATCH; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3258 | } |
| 3259 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3260 | LinkMismatchError linkErrorOnField = LinkValidateVariablesBase( |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 3261 | member1, member2, validatePrecision, true, mismatchedStructOrBlockMemberName); |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3262 | if (linkErrorOnField != LinkMismatchError::NO_MISMATCH) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3263 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3264 | AddParentPrefix(member1.name, mismatchedStructOrBlockMemberName); |
| 3265 | return linkErrorOnField; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3266 | } |
| 3267 | } |
| 3268 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3269 | return LinkMismatchError::NO_MISMATCH; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3270 | } |
| 3271 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3272 | LinkMismatchError Program::LinkValidateVaryings(const sh::Varying &outputVarying, |
| 3273 | const sh::Varying &inputVarying, |
| 3274 | int shaderVersion, |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 3275 | bool validateGeometryShaderInputVarying, |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3276 | std::string *mismatchedStructFieldName) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3277 | { |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 3278 | if (validateGeometryShaderInputVarying) |
| 3279 | { |
| 3280 | // [GL_EXT_geometry_shader] Section 11.1gs.4.3: |
| 3281 | // The OpenGL ES Shading Language doesn't support multi-dimensional arrays as shader inputs |
| 3282 | // or outputs. |
| 3283 | ASSERT(inputVarying.arraySizes.size() == 1u); |
| 3284 | |
| 3285 | // Geometry shader input varyings are not treated as arrays, so a vertex array output |
| 3286 | // varying cannot match a geometry shader input varying. |
| 3287 | // [GL_EXT_geometry_shader] Section 7.4.1: |
| 3288 | // Geometry shader per-vertex input variables and blocks are required to be declared as |
| 3289 | // arrays, with each element representing input or output values for a single vertex of a |
| 3290 | // multi-vertex primitive. For the purposes of interface matching, such variables and blocks |
| 3291 | // are treated as though they were not declared as arrays. |
| 3292 | if (outputVarying.isArray()) |
| 3293 | { |
| 3294 | return LinkMismatchError::ARRAY_SIZE_MISMATCH; |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | // Skip the validation on the array sizes between a vertex output varying and a geometry input |
| 3299 | // varying as it has been done before. |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3300 | LinkMismatchError linkError = |
Jiawei Shao | d063aff | 2018-02-22 10:19:09 +0800 | [diff] [blame] | 3301 | LinkValidateVariablesBase(outputVarying, inputVarying, false, |
| 3302 | !validateGeometryShaderInputVarying, mismatchedStructFieldName); |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3303 | if (linkError != LinkMismatchError::NO_MISMATCH) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3304 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3305 | return linkError; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3306 | } |
| 3307 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3308 | if (!sh::InterpolationTypesMatch(outputVarying.interpolation, inputVarying.interpolation)) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3309 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3310 | return LinkMismatchError::INTERPOLATION_TYPE_MISMATCH; |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 3311 | } |
| 3312 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3313 | if (shaderVersion == 100 && outputVarying.isInvariant != inputVarying.isInvariant) |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 3314 | { |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3315 | return LinkMismatchError::INVARIANCE_MISMATCH; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3316 | } |
| 3317 | |
Jiawei Shao | 881b7bf | 2017-12-25 11:18:37 +0800 | [diff] [blame] | 3318 | return LinkMismatchError::NO_MISMATCH; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3319 | } |
| 3320 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3321 | bool Program::linkValidateBuiltInVaryings(InfoLog &infoLog) const |
Yuly Novikov | 817232e | 2017-02-22 18:36:10 -0500 | [diff] [blame] | 3322 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 3323 | Shader *vertexShader = mState.mAttachedShaders[ShaderType::Vertex]; |
| 3324 | Shader *fragmentShader = mState.mAttachedShaders[ShaderType::Fragment]; |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3325 | const auto &vertexVaryings = vertexShader->getOutputVaryings(); |
| 3326 | const auto &fragmentVaryings = fragmentShader->getInputVaryings(); |
| 3327 | int shaderVersion = vertexShader->getShaderVersion(); |
Yuly Novikov | 817232e | 2017-02-22 18:36:10 -0500 | [diff] [blame] | 3328 | |
| 3329 | if (shaderVersion != 100) |
| 3330 | { |
| 3331 | // Only ESSL 1.0 has restrictions on matching input and output invariance |
| 3332 | return true; |
| 3333 | } |
| 3334 | |
| 3335 | bool glPositionIsInvariant = false; |
| 3336 | bool glPointSizeIsInvariant = false; |
| 3337 | bool glFragCoordIsInvariant = false; |
| 3338 | bool glPointCoordIsInvariant = false; |
| 3339 | |
| 3340 | for (const sh::Varying &varying : vertexVaryings) |
| 3341 | { |
| 3342 | if (!varying.isBuiltIn()) |
| 3343 | { |
| 3344 | continue; |
| 3345 | } |
| 3346 | if (varying.name.compare("gl_Position") == 0) |
| 3347 | { |
| 3348 | glPositionIsInvariant = varying.isInvariant; |
| 3349 | } |
| 3350 | else if (varying.name.compare("gl_PointSize") == 0) |
| 3351 | { |
| 3352 | glPointSizeIsInvariant = varying.isInvariant; |
| 3353 | } |
| 3354 | } |
| 3355 | |
| 3356 | for (const sh::Varying &varying : fragmentVaryings) |
| 3357 | { |
| 3358 | if (!varying.isBuiltIn()) |
| 3359 | { |
| 3360 | continue; |
| 3361 | } |
| 3362 | if (varying.name.compare("gl_FragCoord") == 0) |
| 3363 | { |
| 3364 | glFragCoordIsInvariant = varying.isInvariant; |
| 3365 | } |
| 3366 | else if (varying.name.compare("gl_PointCoord") == 0) |
| 3367 | { |
| 3368 | glPointCoordIsInvariant = varying.isInvariant; |
| 3369 | } |
| 3370 | } |
| 3371 | |
| 3372 | // There is some ambiguity in ESSL 1.00.17 paragraph 4.6.4 interpretation, |
| 3373 | // for example, https://cvs.khronos.org/bugzilla/show_bug.cgi?id=13842. |
| 3374 | // Not requiring invariance to match is supported by: |
| 3375 | // dEQP, WebGL CTS, Nexus 5X GLES |
| 3376 | if (glFragCoordIsInvariant && !glPositionIsInvariant) |
| 3377 | { |
| 3378 | infoLog << "gl_FragCoord can only be declared invariant if and only if gl_Position is " |
| 3379 | "declared invariant."; |
| 3380 | return false; |
| 3381 | } |
| 3382 | if (glPointCoordIsInvariant && !glPointSizeIsInvariant) |
| 3383 | { |
| 3384 | infoLog << "gl_PointCoord can only be declared invariant if and only if gl_PointSize is " |
| 3385 | "declared invariant."; |
| 3386 | return false; |
| 3387 | } |
| 3388 | |
| 3389 | return true; |
| 3390 | } |
| 3391 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3392 | bool Program::linkValidateTransformFeedback(const Version &version, |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 3393 | InfoLog &infoLog, |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 3394 | const ProgramMergedVaryings &varyings, |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3395 | const Caps &caps) const |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3396 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3397 | |
jchen10 | 8225e73 | 2017-11-14 16:29:03 +0800 | [diff] [blame] | 3398 | // Validate the tf names regardless of the actual program varyings. |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3399 | std::set<std::string> uniqueNames; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 3400 | for (const std::string &tfVaryingName : mState.mTransformFeedbackVaryingNames) |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3401 | { |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3402 | if (version < Version(3, 1) && tfVaryingName.find('[') != std::string::npos) |
Jamie Madill | 89bb70e | 2015-08-31 14:18:39 -0400 | [diff] [blame] | 3403 | { |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 3404 | infoLog << "Capture of array elements is undefined and not supported."; |
Jamie Madill | 89bb70e | 2015-08-31 14:18:39 -0400 | [diff] [blame] | 3405 | return false; |
| 3406 | } |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3407 | if (version >= Version(3, 1)) |
jchen10 | 8225e73 | 2017-11-14 16:29:03 +0800 | [diff] [blame] | 3408 | { |
| 3409 | if (IncludeSameArrayElement(uniqueNames, tfVaryingName)) |
| 3410 | { |
| 3411 | infoLog << "Two transform feedback varyings include the same array element (" |
| 3412 | << tfVaryingName << ")."; |
| 3413 | return false; |
| 3414 | } |
| 3415 | } |
| 3416 | else |
| 3417 | { |
| 3418 | if (uniqueNames.count(tfVaryingName) > 0) |
| 3419 | { |
| 3420 | infoLog << "Two transform feedback varyings specify the same output variable (" |
| 3421 | << tfVaryingName << ")."; |
| 3422 | return false; |
| 3423 | } |
| 3424 | } |
| 3425 | uniqueNames.insert(tfVaryingName); |
| 3426 | } |
| 3427 | |
| 3428 | // Validate against program varyings. |
| 3429 | size_t totalComponents = 0; |
| 3430 | for (const std::string &tfVaryingName : mState.mTransformFeedbackVaryingNames) |
| 3431 | { |
| 3432 | std::vector<unsigned int> subscripts; |
| 3433 | std::string baseName = ParseResourceName(tfVaryingName, &subscripts); |
| 3434 | |
| 3435 | const sh::ShaderVariable *var = FindVaryingOrField(varyings, baseName); |
| 3436 | if (var == nullptr) |
jchen10 | 85c93c4 | 2017-11-12 15:36:47 +0800 | [diff] [blame] | 3437 | { |
| 3438 | infoLog << "Transform feedback varying " << tfVaryingName |
| 3439 | << " does not exist in the vertex shader."; |
| 3440 | return false; |
| 3441 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3442 | |
jchen10 | 8225e73 | 2017-11-14 16:29:03 +0800 | [diff] [blame] | 3443 | // Validate the matching variable. |
| 3444 | if (var->isStruct()) |
| 3445 | { |
| 3446 | infoLog << "Struct cannot be captured directly (" << baseName << ")."; |
| 3447 | return false; |
| 3448 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3449 | |
jchen10 | 8225e73 | 2017-11-14 16:29:03 +0800 | [diff] [blame] | 3450 | size_t elementCount = 0; |
| 3451 | size_t componentCount = 0; |
| 3452 | |
| 3453 | if (var->isArray()) |
| 3454 | { |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3455 | if (version < Version(3, 1)) |
jchen10 | 8225e73 | 2017-11-14 16:29:03 +0800 | [diff] [blame] | 3456 | { |
| 3457 | infoLog << "Capture of arrays is undefined and not supported."; |
| 3458 | return false; |
| 3459 | } |
| 3460 | |
| 3461 | // GLSL ES 3.10 section 4.3.6: A vertex output can't be an array of arrays. |
| 3462 | ASSERT(!var->isArrayOfArrays()); |
| 3463 | |
| 3464 | if (!subscripts.empty() && subscripts[0] >= var->getOutermostArraySize()) |
| 3465 | { |
| 3466 | infoLog << "Cannot capture outbound array element '" << tfVaryingName << "'."; |
| 3467 | return false; |
| 3468 | } |
| 3469 | elementCount = (subscripts.empty() ? var->getOutermostArraySize() : 1); |
| 3470 | } |
| 3471 | else |
| 3472 | { |
| 3473 | if (!subscripts.empty()) |
| 3474 | { |
| 3475 | infoLog << "Varying '" << baseName |
| 3476 | << "' is not an array to be captured by element."; |
| 3477 | return false; |
| 3478 | } |
| 3479 | elementCount = 1; |
| 3480 | } |
| 3481 | |
| 3482 | // TODO(jmadill): Investigate implementation limits on D3D11 |
| 3483 | componentCount = VariableComponentCount(var->type) * elementCount; |
| 3484 | if (mState.mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS && |
| 3485 | componentCount > caps.maxTransformFeedbackSeparateComponents) |
| 3486 | { |
| 3487 | infoLog << "Transform feedback varying " << tfVaryingName << " components (" |
| 3488 | << componentCount << ") exceed the maximum separate components (" |
| 3489 | << caps.maxTransformFeedbackSeparateComponents << ")."; |
| 3490 | return false; |
| 3491 | } |
| 3492 | |
| 3493 | totalComponents += componentCount; |
| 3494 | if (mState.mTransformFeedbackBufferMode == GL_INTERLEAVED_ATTRIBS && |
| 3495 | totalComponents > caps.maxTransformFeedbackInterleavedComponents) |
| 3496 | { |
| 3497 | infoLog << "Transform feedback varying total components (" << totalComponents |
| 3498 | << ") exceed the maximum interleaved components (" |
| 3499 | << caps.maxTransformFeedbackInterleavedComponents << ")."; |
| 3500 | return false; |
| 3501 | } |
| 3502 | } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3503 | return true; |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 3504 | } |
| 3505 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3506 | bool Program::linkValidateGlobalNames(InfoLog &infoLog) const |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 3507 | { |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 3508 | const std::vector<sh::Attribute> &attributes = |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3509 | mState.mAttachedShaders[ShaderType::Vertex]->getActiveAttributes(); |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 3510 | |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 3511 | for (const auto &attrib : attributes) |
| 3512 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 3513 | for (ShaderType shaderType : kAllGraphicsShaderTypes) |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 3514 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 3515 | Shader *shader = mState.mAttachedShaders[shaderType]; |
| 3516 | if (!shader) |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 3517 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 3518 | continue; |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 3519 | } |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 3520 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3521 | const std::vector<sh::Uniform> &uniforms = shader->getUniforms(); |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 3522 | for (const auto &uniform : uniforms) |
Jiawei Shao | 0d88ec9 | 2018-02-27 16:25:31 +0800 | [diff] [blame] | 3523 | { |
| 3524 | if (uniform.name == attrib.name) |
| 3525 | { |
| 3526 | infoLog << "Name conflicts between a uniform and an attribute: " << attrib.name; |
| 3527 | return false; |
| 3528 | } |
| 3529 | } |
| 3530 | } |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 3531 | } |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 3532 | |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 3533 | return true; |
| 3534 | } |
| 3535 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 3536 | void Program::gatherTransformFeedbackVaryings(const ProgramMergedVaryings &varyings) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3537 | { |
| 3538 | // 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] | 3539 | mState.mLinkedTransformFeedbackVaryings.clear(); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 3540 | for (const std::string &tfVaryingName : mState.mTransformFeedbackVaryingNames) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3541 | { |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 3542 | std::vector<unsigned int> subscripts; |
| 3543 | std::string baseName = ParseResourceName(tfVaryingName, &subscripts); |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 3544 | size_t subscript = GL_INVALID_INDEX; |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 3545 | if (!subscripts.empty()) |
| 3546 | { |
| 3547 | subscript = subscripts.back(); |
| 3548 | } |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 3549 | for (const auto &ref : varyings) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3550 | { |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 3551 | const sh::Varying *varying = ref.second.get(); |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 3552 | if (baseName == varying->name) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3553 | { |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 3554 | mState.mLinkedTransformFeedbackVaryings.emplace_back( |
| 3555 | *varying, static_cast<GLuint>(subscript)); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3556 | break; |
| 3557 | } |
jchen10 | 8225e73 | 2017-11-14 16:29:03 +0800 | [diff] [blame] | 3558 | else if (varying->isStruct()) |
| 3559 | { |
| 3560 | const auto *field = FindShaderVarField(*varying, tfVaryingName); |
| 3561 | if (field != nullptr) |
| 3562 | { |
| 3563 | mState.mLinkedTransformFeedbackVaryings.emplace_back(*field, *varying); |
| 3564 | break; |
| 3565 | } |
| 3566 | } |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3567 | } |
| 3568 | } |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 3569 | mState.updateTransformFeedbackStrides(); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3570 | } |
| 3571 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3572 | ProgramMergedVaryings Program::getMergedVaryings() const |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3573 | { |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 3574 | ProgramMergedVaryings merged; |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3575 | |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 3576 | for (const sh::Varying &varying : |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3577 | mState.mAttachedShaders[ShaderType::Vertex]->getOutputVaryings()) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3578 | { |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 3579 | merged[varying.name].vertex = &varying; |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3580 | } |
| 3581 | |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 3582 | for (const sh::Varying &varying : |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3583 | mState.mAttachedShaders[ShaderType::Fragment]->getInputVaryings()) |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 3584 | { |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 3585 | merged[varying.name].fragment = &varying; |
| 3586 | } |
| 3587 | |
| 3588 | return merged; |
| 3589 | } |
| 3590 | |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 3591 | bool CompareOutputVariable(const sh::OutputVariable &a, const sh::OutputVariable &b) |
| 3592 | { |
| 3593 | return a.getArraySizeProduct() > b.getArraySizeProduct(); |
| 3594 | } |
| 3595 | |
| 3596 | int Program::getOutputLocationForLink(const sh::OutputVariable &outputVariable) const |
| 3597 | { |
| 3598 | if (outputVariable.location != -1) |
| 3599 | { |
| 3600 | return outputVariable.location; |
| 3601 | } |
| 3602 | int apiLocation = mFragmentOutputLocations.getBinding(outputVariable.name); |
| 3603 | if (apiLocation != -1) |
| 3604 | { |
| 3605 | return apiLocation; |
| 3606 | } |
| 3607 | return -1; |
| 3608 | } |
| 3609 | |
| 3610 | bool Program::isOutputSecondaryForLink(const sh::OutputVariable &outputVariable) const |
| 3611 | { |
| 3612 | if (outputVariable.index != -1) |
| 3613 | { |
| 3614 | ASSERT(outputVariable.index == 0 || outputVariable.index == 1); |
| 3615 | return (outputVariable.index == 1); |
| 3616 | } |
| 3617 | int apiIndex = mFragmentOutputIndexes.getBinding(outputVariable.name); |
| 3618 | if (apiIndex != -1) |
| 3619 | { |
| 3620 | // Index layout qualifier from the shader takes precedence, so the index from the API is |
| 3621 | // checked only if the index was not set in the shader. This is not specified in the EXT |
| 3622 | // spec, but is specified in desktop OpenGL specs. |
| 3623 | return (apiIndex == 1); |
| 3624 | } |
| 3625 | // EXT_blend_func_extended: Outputs get index 0 by default. |
| 3626 | return false; |
| 3627 | } |
| 3628 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3629 | bool Program::linkOutputVariables(const Caps &caps, |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 3630 | const Extensions &extensions, |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3631 | const Version &version, |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 3632 | GLuint combinedImageUniformsCount, |
| 3633 | GLuint combinedShaderStorageBlocksCount) |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 3634 | { |
Jiawei Shao | 016105b | 2018-04-12 16:38:31 +0800 | [diff] [blame] | 3635 | Shader *fragmentShader = mState.mAttachedShaders[ShaderType::Fragment]; |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 3636 | ASSERT(fragmentShader != nullptr); |
| 3637 | |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 3638 | ASSERT(mState.mOutputVariableTypes.empty()); |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 3639 | ASSERT(mState.mActiveOutputVariables.none()); |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 3640 | ASSERT(mState.mDrawBufferTypeMask.none()); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 3641 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3642 | const auto &outputVariables = fragmentShader->getActiveOutputVariables(); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 3643 | // Gather output variable types |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 3644 | for (const auto &outputVariable : outputVariables) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 3645 | { |
| 3646 | if (outputVariable.isBuiltIn() && outputVariable.name != "gl_FragColor" && |
| 3647 | outputVariable.name != "gl_FragData") |
| 3648 | { |
| 3649 | continue; |
| 3650 | } |
| 3651 | |
| 3652 | unsigned int baseLocation = |
| 3653 | (outputVariable.location == -1 ? 0u |
| 3654 | : static_cast<unsigned int>(outputVariable.location)); |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 3655 | |
| 3656 | // GLSL ES 3.10 section 4.3.6: Output variables cannot be arrays of arrays or arrays of |
| 3657 | // structures, so we may use getBasicTypeElementCount(). |
| 3658 | unsigned int elementCount = outputVariable.getBasicTypeElementCount(); |
| 3659 | for (unsigned int elementIndex = 0; elementIndex < elementCount; elementIndex++) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 3660 | { |
| 3661 | const unsigned int location = baseLocation + elementIndex; |
| 3662 | if (location >= mState.mOutputVariableTypes.size()) |
| 3663 | { |
| 3664 | mState.mOutputVariableTypes.resize(location + 1, GL_NONE); |
| 3665 | } |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 3666 | ASSERT(location < mState.mActiveOutputVariables.size()); |
| 3667 | mState.mActiveOutputVariables.set(location); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 3668 | mState.mOutputVariableTypes[location] = VariableComponentType(outputVariable.type); |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 3669 | mState.mDrawBufferTypeMask.setIndex(mState.mOutputVariableTypes[location], location); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 3670 | } |
| 3671 | } |
| 3672 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3673 | if (version >= ES_3_1) |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 3674 | { |
| 3675 | // [OpenGL ES 3.1] Chapter 8.22 Page 203: |
| 3676 | // A link error will be generated if the sum of the number of active image uniforms used in |
| 3677 | // all shaders, the number of active shader storage blocks, and the number of active |
| 3678 | // fragment shader outputs exceeds the implementation-dependent value of |
| 3679 | // MAX_COMBINED_SHADER_OUTPUT_RESOURCES. |
| 3680 | if (combinedImageUniformsCount + combinedShaderStorageBlocksCount + |
| 3681 | mState.mActiveOutputVariables.count() > |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3682 | caps.maxCombinedShaderOutputResources) |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 3683 | { |
| 3684 | mInfoLog |
| 3685 | << "The sum of the number of active image uniforms, active shader storage blocks " |
| 3686 | "and active fragment shader outputs exceeds " |
| 3687 | "MAX_COMBINED_SHADER_OUTPUT_RESOURCES (" |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3688 | << caps.maxCombinedShaderOutputResources << ")"; |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 3689 | return false; |
| 3690 | } |
| 3691 | } |
| 3692 | |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 3693 | // Skip this step for GLES2 shaders. |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3694 | if (fragmentShader->getShaderVersion() == 100) |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 3695 | return true; |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 3696 | |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 3697 | mState.mOutputVariables = outputVariables; |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 3698 | // TODO(jmadill): any caps validation here? |
| 3699 | |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 3700 | for (sh::OutputVariable &outputVariable : mState.mOutputVariables) |
| 3701 | { |
| 3702 | if (outputVariable.isArray()) |
| 3703 | { |
| 3704 | // We're following the GLES 3.1 November 2016 spec section 7.3.1.1 Naming Active |
| 3705 | // Resources and including [0] at the end of array variable names. |
| 3706 | outputVariable.name += "[0]"; |
| 3707 | outputVariable.mappedName += "[0]"; |
| 3708 | } |
| 3709 | } |
| 3710 | |
| 3711 | bool hasSecondaryOutputs = false; |
| 3712 | |
| 3713 | // Reserve locations for output variables whose location is fixed in the shader or through the |
| 3714 | // API. |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 3715 | for (unsigned int outputVariableIndex = 0; outputVariableIndex < mState.mOutputVariables.size(); |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 3716 | outputVariableIndex++) |
| 3717 | { |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 3718 | const sh::OutputVariable &outputVariable = mState.mOutputVariables[outputVariableIndex]; |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 3719 | |
| 3720 | // Don't store outputs for gl_FragDepth, gl_FragColor, etc. |
| 3721 | if (outputVariable.isBuiltIn()) |
| 3722 | continue; |
| 3723 | |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 3724 | int baseLocation = getOutputLocationForLink(outputVariable); |
| 3725 | if (baseLocation == -1) |
| 3726 | { |
| 3727 | // Here we're only reserving locations for variables whose location is fixed. |
| 3728 | continue; |
| 3729 | } |
| 3730 | |
| 3731 | auto *outputLocations = &mState.mOutputLocations; |
| 3732 | if (isOutputSecondaryForLink(outputVariable)) |
| 3733 | { |
| 3734 | outputLocations = &mState.mSecondaryOutputLocations; |
| 3735 | // Note that this check doesn't need to be before checking baseLocation == -1 above. If |
| 3736 | // an output has an index specified it will always also have the location specified. |
| 3737 | hasSecondaryOutputs = true; |
| 3738 | } |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 3739 | |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 3740 | // GLSL ES 3.10 section 4.3.6: Output variables cannot be arrays of arrays or arrays of |
| 3741 | // structures, so we may use getBasicTypeElementCount(). |
| 3742 | unsigned int elementCount = outputVariable.getBasicTypeElementCount(); |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 3743 | unsigned int outputLocationsNeeded = static_cast<unsigned int>(baseLocation) + elementCount; |
| 3744 | if (outputLocationsNeeded > outputLocations->size()) |
| 3745 | { |
| 3746 | outputLocations->resize(outputLocationsNeeded); |
| 3747 | } |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 3748 | for (unsigned int elementIndex = 0; elementIndex < elementCount; elementIndex++) |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 3749 | { |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 3750 | const unsigned int location = static_cast<unsigned int>(baseLocation) + elementIndex; |
| 3751 | ASSERT(location < outputLocations->size()); |
| 3752 | if (outputLocations->at(location).used()) |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 3753 | { |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 3754 | mInfoLog << "Location of variable " << outputVariable.name |
| 3755 | << " conflicts with another variable."; |
| 3756 | return false; |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 3757 | } |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 3758 | if (outputVariable.isArray()) |
| 3759 | { |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 3760 | (*outputLocations)[location] = VariableLocation(elementIndex, outputVariableIndex); |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 3761 | } |
| 3762 | else |
| 3763 | { |
| 3764 | VariableLocation locationInfo; |
| 3765 | locationInfo.index = outputVariableIndex; |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 3766 | (*outputLocations)[location] = locationInfo; |
| 3767 | } |
| 3768 | } |
| 3769 | } |
| 3770 | |
| 3771 | // Here we assign locations for the output variables that don't yet have them. Note that we're |
| 3772 | // not necessarily able to fit the variables optimally, since then we might have to try |
| 3773 | // different arrangements of output arrays. Now we just assign the locations in the order that |
| 3774 | // we got the output variables. The spec isn't clear on what kind of algorithm is required for |
| 3775 | // finding locations for the output variables, so this should be acceptable at least for now. |
| 3776 | GLuint maxLocation = caps.maxDrawBuffers; |
| 3777 | if (hasSecondaryOutputs) |
| 3778 | { |
| 3779 | // EXT_blend_func_extended: Program outputs will be validated against |
| 3780 | // MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT if there's even one output with index one. |
| 3781 | maxLocation = extensions.maxDualSourceDrawBuffers; |
| 3782 | } |
| 3783 | |
| 3784 | for (unsigned int outputVariableIndex = 0; outputVariableIndex < mState.mOutputVariables.size(); |
| 3785 | outputVariableIndex++) |
| 3786 | { |
| 3787 | const sh::OutputVariable &outputVariable = mState.mOutputVariables[outputVariableIndex]; |
| 3788 | |
| 3789 | // Don't store outputs for gl_FragDepth, gl_FragColor, etc. |
| 3790 | if (outputVariable.isBuiltIn()) |
| 3791 | continue; |
| 3792 | |
| 3793 | if (getOutputLocationForLink(outputVariable) != -1) |
| 3794 | { |
| 3795 | continue; |
| 3796 | } |
| 3797 | |
| 3798 | auto *outputLocations = &mState.mOutputLocations; |
| 3799 | if (isOutputSecondaryForLink(outputVariable)) |
| 3800 | { |
| 3801 | outputLocations = &mState.mSecondaryOutputLocations; |
| 3802 | } |
| 3803 | |
| 3804 | int baseLocation = 0; |
| 3805 | unsigned int elementCount = outputVariable.getBasicTypeElementCount(); |
| 3806 | bool elementsFit = false; |
| 3807 | while (!elementsFit) |
| 3808 | { |
| 3809 | // Try baseLocations starting from 0 one at a time and see if the variable fits. |
| 3810 | elementsFit = true; |
| 3811 | if (baseLocation + elementCount > maxLocation) |
| 3812 | { |
| 3813 | // EXT_blend_func_extended: Linking can fail: |
| 3814 | // "if the explicit binding assignments do not leave enough space for the linker to |
| 3815 | // automatically assign a location for a varying out array, which requires multiple |
| 3816 | // contiguous locations." |
| 3817 | mInfoLog << "Could not fit output variable into available locations: " |
| 3818 | << outputVariable.name; |
| 3819 | return false; |
| 3820 | } |
| 3821 | unsigned int outputLocationsNeeded = |
| 3822 | static_cast<unsigned int>(baseLocation) + elementCount; |
| 3823 | if (outputLocationsNeeded > outputLocations->size()) |
| 3824 | { |
| 3825 | outputLocations->resize(outputLocationsNeeded); |
| 3826 | } |
| 3827 | for (unsigned int elementIndex = 0; elementIndex < elementCount; elementIndex++) |
| 3828 | { |
| 3829 | const unsigned int location = |
| 3830 | static_cast<unsigned int>(baseLocation) + elementIndex; |
| 3831 | ASSERT(location < outputLocations->size()); |
| 3832 | if (outputLocations->at(location).used()) |
| 3833 | { |
| 3834 | elementsFit = false; |
| 3835 | break; |
| 3836 | } |
| 3837 | } |
| 3838 | if (elementsFit) |
| 3839 | { |
| 3840 | for (unsigned int elementIndex = 0; elementIndex < elementCount; elementIndex++) |
| 3841 | { |
| 3842 | const unsigned int location = |
| 3843 | static_cast<unsigned int>(baseLocation) + elementIndex; |
| 3844 | if (outputVariable.isArray()) |
| 3845 | { |
| 3846 | (*outputLocations)[location] = |
| 3847 | VariableLocation(elementIndex, outputVariableIndex); |
| 3848 | } |
| 3849 | else |
| 3850 | { |
| 3851 | VariableLocation locationInfo; |
| 3852 | locationInfo.index = outputVariableIndex; |
| 3853 | (*outputLocations)[location] = locationInfo; |
| 3854 | } |
| 3855 | } |
| 3856 | } |
| 3857 | else |
| 3858 | { |
| 3859 | ++baseLocation; |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 3860 | } |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 3861 | } |
| 3862 | } |
Jiawei Shao | 7a8fe15 | 2018-04-28 12:59:58 +0800 | [diff] [blame] | 3863 | |
| 3864 | return true; |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 3865 | } |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3866 | |
Olli Etuaho | 48fed63 | 2017-03-16 12:05:30 +0000 | [diff] [blame] | 3867 | void Program::setUniformValuesFromBindingQualifiers() |
| 3868 | { |
Jamie Madill | 982f6e0 | 2017-06-07 14:33:04 -0400 | [diff] [blame] | 3869 | for (unsigned int samplerIndex : mState.mSamplerUniformRange) |
Olli Etuaho | 48fed63 | 2017-03-16 12:05:30 +0000 | [diff] [blame] | 3870 | { |
| 3871 | const auto &samplerUniform = mState.mUniforms[samplerIndex]; |
| 3872 | if (samplerUniform.binding != -1) |
| 3873 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 3874 | GLint location = getUniformLocation(samplerUniform.name); |
Olli Etuaho | 48fed63 | 2017-03-16 12:05:30 +0000 | [diff] [blame] | 3875 | ASSERT(location != -1); |
| 3876 | std::vector<GLint> boundTextureUnits; |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 3877 | for (unsigned int elementIndex = 0; |
| 3878 | elementIndex < samplerUniform.getBasicTypeElementCount(); ++elementIndex) |
Olli Etuaho | 48fed63 | 2017-03-16 12:05:30 +0000 | [diff] [blame] | 3879 | { |
| 3880 | boundTextureUnits.push_back(samplerUniform.binding + elementIndex); |
| 3881 | } |
| 3882 | setUniform1iv(location, static_cast<GLsizei>(boundTextureUnits.size()), |
| 3883 | boundTextureUnits.data()); |
| 3884 | } |
| 3885 | } |
| 3886 | } |
| 3887 | |
Jamie Madill | 6db1c2e | 2017-11-08 09:17:40 -0500 | [diff] [blame] | 3888 | void Program::initInterfaceBlockBindings() |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3889 | { |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 3890 | // Set initial bindings from shader. |
| 3891 | for (unsigned int blockIndex = 0; blockIndex < mState.mUniformBlocks.size(); blockIndex++) |
| 3892 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 3893 | InterfaceBlock &uniformBlock = mState.mUniformBlocks[blockIndex]; |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 3894 | bindUniformBlock(blockIndex, uniformBlock.binding); |
| 3895 | } |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3896 | } |
| 3897 | |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 3898 | void Program::updateSamplerUniform(const VariableLocation &locationInfo, |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 3899 | GLsizei clampedCount, |
| 3900 | const GLint *v) |
| 3901 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 3902 | ASSERT(mState.isSamplerUniformIndex(locationInfo.index)); |
| 3903 | GLuint samplerIndex = mState.getSamplerIndexFromUniformIndex(locationInfo.index); |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 3904 | SamplerBinding &samplerBinding = mState.mSamplerBindings[samplerIndex]; |
| 3905 | std::vector<GLuint> &boundTextureUnits = samplerBinding.boundTextureUnits; |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 3906 | |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 3907 | if (samplerBinding.unreferenced) |
| 3908 | return; |
| 3909 | |
| 3910 | // Update the sampler uniforms. |
| 3911 | for (GLsizei arrayIndex = 0; arrayIndex < clampedCount; ++arrayIndex) |
| 3912 | { |
| 3913 | GLint oldSamplerIndex = boundTextureUnits[arrayIndex + locationInfo.arrayIndex]; |
| 3914 | GLint newSamplerIndex = v[arrayIndex]; |
| 3915 | |
| 3916 | if (oldSamplerIndex == newSamplerIndex) |
| 3917 | continue; |
| 3918 | |
| 3919 | boundTextureUnits[arrayIndex + locationInfo.arrayIndex] = newSamplerIndex; |
| 3920 | |
| 3921 | // Update the reference counts. |
| 3922 | uint32_t &oldRefCount = mState.mActiveSamplerRefCounts[oldSamplerIndex]; |
| 3923 | uint32_t &newRefCount = mState.mActiveSamplerRefCounts[newSamplerIndex]; |
| 3924 | ASSERT(oldRefCount > 0); |
| 3925 | ASSERT(newRefCount < std::numeric_limits<uint32_t>::max()); |
| 3926 | oldRefCount--; |
| 3927 | newRefCount++; |
| 3928 | |
| 3929 | // Check for binding type change. |
| 3930 | TextureType &newSamplerType = mState.mActiveSamplerTypes[newSamplerIndex]; |
| 3931 | TextureType &oldSamplerType = mState.mActiveSamplerTypes[oldSamplerIndex]; |
| 3932 | |
| 3933 | if (newRefCount == 1) |
| 3934 | { |
| 3935 | newSamplerType = samplerBinding.textureType; |
| 3936 | mState.mActiveSamplersMask.set(newSamplerIndex); |
| 3937 | } |
| 3938 | else if (newSamplerType != samplerBinding.textureType) |
| 3939 | { |
| 3940 | // Conflict detected. Ensure we reset it properly. |
| 3941 | newSamplerType = TextureType::InvalidEnum; |
| 3942 | } |
| 3943 | |
| 3944 | // Unset previously active sampler. |
| 3945 | if (oldRefCount == 0) |
| 3946 | { |
| 3947 | oldSamplerType = TextureType::InvalidEnum; |
| 3948 | mState.mActiveSamplersMask.reset(oldSamplerIndex); |
| 3949 | } |
| 3950 | else if (oldSamplerType == TextureType::InvalidEnum) |
| 3951 | { |
| 3952 | // Previous conflict. Check if this new change fixed the conflict. |
| 3953 | oldSamplerType = mState.getSamplerUniformTextureType(oldSamplerIndex); |
| 3954 | } |
| 3955 | } |
Jamie Madill | d68248b | 2017-09-11 14:34:14 -0400 | [diff] [blame] | 3956 | |
| 3957 | // Invalidate the validation cache. |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 3958 | mCachedValidateSamplersResult.reset(); |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 3959 | } |
| 3960 | |
Jamie Madill | 7e4eff1 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 3961 | TextureType ProgramState::getSamplerUniformTextureType(size_t textureUnitIndex) const |
| 3962 | { |
| 3963 | TextureType foundType = TextureType::InvalidEnum; |
| 3964 | |
| 3965 | for (const SamplerBinding &binding : mSamplerBindings) |
| 3966 | { |
| 3967 | if (binding.unreferenced) |
| 3968 | continue; |
| 3969 | |
| 3970 | // A conflict exists if samplers of different types are sourced by the same texture unit. |
| 3971 | // We need to check all bound textures to detect this error case. |
| 3972 | for (GLuint textureUnit : binding.boundTextureUnits) |
| 3973 | { |
| 3974 | if (textureUnit == textureUnitIndex) |
| 3975 | { |
| 3976 | if (foundType == TextureType::InvalidEnum) |
| 3977 | { |
| 3978 | foundType = binding.textureType; |
| 3979 | } |
| 3980 | else if (foundType != binding.textureType) |
| 3981 | { |
| 3982 | return TextureType::InvalidEnum; |
| 3983 | } |
| 3984 | } |
| 3985 | } |
| 3986 | } |
| 3987 | |
| 3988 | return foundType; |
| 3989 | } |
| 3990 | |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 3991 | template <typename T> |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 3992 | GLsizei Program::clampUniformCount(const VariableLocation &locationInfo, |
| 3993 | GLsizei count, |
| 3994 | int vectorSize, |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 3995 | const T *v) |
| 3996 | { |
Jamie Madill | 134f93d | 2017-08-31 17:11:00 -0400 | [diff] [blame] | 3997 | if (count == 1) |
| 3998 | return 1; |
| 3999 | |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 4000 | const LinkedUniform &linkedUniform = mState.mUniforms[locationInfo.index]; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4001 | |
Corentin Wallez | 15ac534 | 2016-11-03 17:06:39 -0400 | [diff] [blame] | 4002 | // OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array |
| 4003 | // element index used, as reported by GetActiveUniform, will be ignored by the GL." |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 4004 | unsigned int remainingElements = |
| 4005 | linkedUniform.getBasicTypeElementCount() - locationInfo.arrayIndex; |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 4006 | GLsizei maxElementCount = |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 4007 | static_cast<GLsizei>(remainingElements * linkedUniform.getElementComponents()); |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 4008 | |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 4009 | if (count * vectorSize > maxElementCount) |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 4010 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 4011 | return maxElementCount / vectorSize; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4012 | } |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 4013 | |
| 4014 | return count; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4015 | } |
| 4016 | |
| 4017 | template <size_t cols, size_t rows, typename T> |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 4018 | GLsizei Program::clampMatrixUniformCount(GLint location, |
| 4019 | GLsizei count, |
| 4020 | GLboolean transpose, |
| 4021 | const T *v) |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4022 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 4023 | const VariableLocation &locationInfo = mState.mUniformLocations[location]; |
| 4024 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4025 | if (!transpose) |
| 4026 | { |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 4027 | return clampUniformCount(locationInfo, count, cols * rows, v); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4028 | } |
| 4029 | |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 4030 | const LinkedUniform &linkedUniform = mState.mUniforms[locationInfo.index]; |
Corentin Wallez | 15ac534 | 2016-11-03 17:06:39 -0400 | [diff] [blame] | 4031 | |
| 4032 | // OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array |
| 4033 | // element index used, as reported by GetActiveUniform, will be ignored by the GL." |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 4034 | unsigned int remainingElements = |
| 4035 | linkedUniform.getBasicTypeElementCount() - locationInfo.arrayIndex; |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 4036 | return std::min(count, static_cast<GLsizei>(remainingElements)); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4037 | } |
| 4038 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4039 | // Driver differences mean that doing the uniform value cast ourselves gives consistent results. |
| 4040 | // 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] | 4041 | template <typename DestT> |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4042 | void Program::getUniformInternal(const Context *context, |
| 4043 | DestT *dataOut, |
| 4044 | GLint location, |
| 4045 | GLenum nativeType, |
| 4046 | int components) const |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4047 | { |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4048 | switch (nativeType) |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4049 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4050 | case GL_BOOL: |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4051 | { |
| 4052 | GLint tempValue[16] = {0}; |
| 4053 | mProgram->getUniformiv(context, location, tempValue); |
| 4054 | UniformStateQueryCastLoop<GLboolean>( |
| 4055 | dataOut, reinterpret_cast<const uint8_t *>(tempValue), components); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4056 | break; |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4057 | } |
| 4058 | case GL_INT: |
| 4059 | { |
| 4060 | GLint tempValue[16] = {0}; |
| 4061 | mProgram->getUniformiv(context, location, tempValue); |
| 4062 | UniformStateQueryCastLoop<GLint>(dataOut, reinterpret_cast<const uint8_t *>(tempValue), |
| 4063 | components); |
| 4064 | break; |
| 4065 | } |
| 4066 | case GL_UNSIGNED_INT: |
| 4067 | { |
| 4068 | GLuint tempValue[16] = {0}; |
| 4069 | mProgram->getUniformuiv(context, location, tempValue); |
| 4070 | UniformStateQueryCastLoop<GLuint>(dataOut, reinterpret_cast<const uint8_t *>(tempValue), |
| 4071 | components); |
| 4072 | break; |
| 4073 | } |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4074 | case GL_FLOAT: |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4075 | { |
| 4076 | GLfloat tempValue[16] = {0}; |
| 4077 | mProgram->getUniformfv(context, location, tempValue); |
| 4078 | UniformStateQueryCastLoop<GLfloat>( |
| 4079 | dataOut, reinterpret_cast<const uint8_t *>(tempValue), components); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4080 | break; |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4081 | } |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4082 | default: |
| 4083 | UNREACHABLE(); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4084 | break; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 4085 | } |
| 4086 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 4087 | |
| 4088 | bool Program::samplesFromTexture(const gl::State &state, GLuint textureID) const |
| 4089 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4090 | ASSERT(mLinkResolved); |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 4091 | // Must be called after samplers are validated. |
| 4092 | ASSERT(mCachedValidateSamplersResult.valid() && mCachedValidateSamplersResult.value()); |
| 4093 | |
| 4094 | for (const auto &binding : mState.mSamplerBindings) |
| 4095 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4096 | TextureType textureType = binding.textureType; |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 4097 | for (const auto &unit : binding.boundTextureUnits) |
| 4098 | { |
| 4099 | GLenum programTextureID = state.getSamplerTextureId(unit, textureType); |
| 4100 | if (programTextureID == textureID) |
| 4101 | { |
| 4102 | // TODO(jmadill): Check for appropriate overlap. |
| 4103 | return true; |
| 4104 | } |
| 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | return false; |
| 4109 | } |
| 4110 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 4111 | angle::Result Program::syncState(const Context *context) |
Jamie Madill | 70aeda4 | 2018-08-20 12:17:40 -0400 | [diff] [blame] | 4112 | { |
| 4113 | if (mDirtyBits.any()) |
| 4114 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4115 | ASSERT(mLinkResolved); |
Jamie Madill | 70aeda4 | 2018-08-20 12:17:40 -0400 | [diff] [blame] | 4116 | ANGLE_TRY(mProgram->syncState(context, mDirtyBits)); |
| 4117 | mDirtyBits.reset(); |
| 4118 | } |
| 4119 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 4120 | return angle::Result::Continue(); |
Jamie Madill | 70aeda4 | 2018-08-20 12:17:40 -0400 | [diff] [blame] | 4121 | } |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 4122 | } // namespace gl |