Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2017 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // UniformLinker.cpp: implements link-time checks for default block uniforms, and generates uniform |
| 8 | // locations. Populates data structures related to uniforms so that they can be stored in program |
| 9 | // state. |
| 10 | |
Jamie Madill | 7af0de5 | 2017-11-06 17:09:33 -0500 | [diff] [blame] | 11 | #include "libANGLE/ProgramLinkedResources.h" |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 12 | |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 13 | #include "common/string_utils.h" |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 14 | #include "common/utilities.h" |
| 15 | #include "libANGLE/Caps.h" |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 16 | #include "libANGLE/Context.h" |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 17 | #include "libANGLE/Shader.h" |
Jiawei-Shao | ddb5eb5 | 2017-03-14 13:36:18 +0800 | [diff] [blame] | 18 | #include "libANGLE/features.h" |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 19 | |
| 20 | namespace gl |
| 21 | { |
| 22 | |
| 23 | namespace |
| 24 | { |
| 25 | |
| 26 | LinkedUniform *FindUniform(std::vector<LinkedUniform> &list, const std::string &name) |
| 27 | { |
| 28 | for (LinkedUniform &uniform : list) |
| 29 | { |
| 30 | if (uniform.name == name) |
| 31 | return &uniform; |
| 32 | } |
| 33 | |
| 34 | return nullptr; |
| 35 | } |
| 36 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 37 | int GetUniformLocationBinding(const ProgramBindings &uniformLocationBindings, |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 38 | const sh::Uniform &uniform) |
| 39 | { |
| 40 | int binding = uniformLocationBindings.getBinding(uniform.name); |
| 41 | if (uniform.isArray() && binding == -1) |
| 42 | { |
| 43 | // Bindings for array uniforms can be set either with or without [0] in the end. |
| 44 | ASSERT(angle::EndsWith(uniform.name, "[0]")); |
| 45 | std::string nameWithoutIndex = uniform.name.substr(0u, uniform.name.length() - 3u); |
| 46 | return uniformLocationBindings.getBinding(nameWithoutIndex); |
| 47 | } |
| 48 | return binding; |
| 49 | } |
| 50 | |
| 51 | } // anonymous namespace |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 52 | |
| 53 | UniformLinker::UniformLinker(const ProgramState &state) : mState(state) |
| 54 | { |
| 55 | } |
| 56 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 57 | UniformLinker::~UniformLinker() = default; |
| 58 | |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 59 | void UniformLinker::getResults(std::vector<LinkedUniform> *uniforms, |
| 60 | std::vector<VariableLocation> *uniformLocations) |
| 61 | { |
| 62 | uniforms->swap(mUniforms); |
| 63 | uniformLocations->swap(mUniformLocations); |
| 64 | } |
| 65 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 66 | bool UniformLinker::link(const Context *context, |
| 67 | InfoLog &infoLog, |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 68 | const ProgramBindings &uniformLocationBindings) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 69 | { |
| 70 | if (mState.getAttachedVertexShader() && mState.getAttachedFragmentShader()) |
| 71 | { |
| 72 | ASSERT(mState.getAttachedComputeShader() == nullptr); |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame^] | 73 | if (!validateGraphicsUniforms(context, infoLog)) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 74 | { |
| 75 | return false; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Flatten the uniforms list (nested fields) into a simple list (no nesting). |
| 80 | // Also check the maximum uniform vector and sampler counts. |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 81 | if (!flattenUniformsAndCheckCaps(context, infoLog)) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 82 | { |
| 83 | return false; |
| 84 | } |
| 85 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 86 | if (!checkMaxCombinedAtomicCounters(context->getCaps(), infoLog)) |
| 87 | { |
| 88 | return false; |
| 89 | } |
| 90 | |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 91 | if (!indexUniforms(infoLog, uniformLocationBindings)) |
| 92 | { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | return true; |
| 97 | } |
| 98 | |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame^] | 99 | bool UniformLinker::validateGraphicsUniforms(const Context *context, InfoLog &infoLog) const |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 100 | { |
| 101 | // Check that uniforms defined in the vertex and fragment shaders are identical |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame^] | 102 | std::map<std::string, const sh::Uniform *> linkedUniforms; |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 103 | const std::vector<sh::Uniform> &vertexUniforms = |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 104 | mState.getAttachedVertexShader()->getUniforms(context); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 105 | const std::vector<sh::Uniform> &fragmentUniforms = |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 106 | mState.getAttachedFragmentShader()->getUniforms(context); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 107 | |
| 108 | for (const sh::Uniform &vertexUniform : vertexUniforms) |
| 109 | { |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame^] | 110 | linkedUniforms[vertexUniform.name] = &vertexUniform; |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | for (const sh::Uniform &fragmentUniform : fragmentUniforms) |
| 114 | { |
| 115 | auto entry = linkedUniforms.find(fragmentUniform.name); |
| 116 | if (entry != linkedUniforms.end()) |
| 117 | { |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame^] | 118 | const sh::Uniform &linkedUniform = *(entry->second); |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 119 | const std::string &uniformName = "uniform '" + linkedUniform.name + "'"; |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame^] | 120 | if (!LinkValidateUniforms(infoLog, uniformName, linkedUniform, fragmentUniform)) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 121 | { |
| 122 | return false; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | return true; |
| 127 | } |
| 128 | |
| 129 | // GLSL ES Spec 3.00.3, section 4.3.5. |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame^] | 130 | bool UniformLinker::LinkValidateUniforms(InfoLog &infoLog, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 131 | const std::string &uniformName, |
| 132 | const sh::Uniform &vertexUniform, |
| 133 | const sh::Uniform &fragmentUniform) |
| 134 | { |
| 135 | #if ANGLE_PROGRAM_LINK_VALIDATE_UNIFORM_PRECISION == ANGLE_ENABLED |
| 136 | const bool validatePrecision = true; |
| 137 | #else |
| 138 | const bool validatePrecision = false; |
| 139 | #endif |
| 140 | |
Jiawei Shao | 7361860 | 2017-12-20 15:47:15 +0800 | [diff] [blame^] | 141 | if (!Program::LinkValidateVariablesBase(infoLog, uniformName, vertexUniform, fragmentUniform, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 142 | validatePrecision)) |
| 143 | { |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | // GLSL ES Spec 3.10.4, section 4.4.5. |
| 148 | if (vertexUniform.binding != -1 && fragmentUniform.binding != -1 && |
| 149 | vertexUniform.binding != fragmentUniform.binding) |
| 150 | { |
| 151 | infoLog << "Binding layout qualifiers for " << uniformName |
| 152 | << " differ between vertex and fragment shaders."; |
| 153 | return false; |
| 154 | } |
| 155 | |
| 156 | // GLSL ES Spec 3.10.4, section 9.2.1. |
| 157 | if (vertexUniform.location != -1 && fragmentUniform.location != -1 && |
| 158 | vertexUniform.location != fragmentUniform.location) |
| 159 | { |
| 160 | infoLog << "Location layout qualifiers for " << uniformName |
| 161 | << " differ between vertex and fragment shaders."; |
| 162 | return false; |
| 163 | } |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 164 | if (vertexUniform.offset != fragmentUniform.offset) |
| 165 | { |
| 166 | infoLog << "Offset layout qualifiers for " << uniformName |
| 167 | << " differ between vertex and fragment shaders."; |
| 168 | return false; |
| 169 | } |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 170 | |
| 171 | return true; |
| 172 | } |
| 173 | |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 174 | bool UniformLinker::indexUniforms(InfoLog &infoLog, const ProgramBindings &uniformLocationBindings) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 175 | { |
| 176 | // All the locations where another uniform can't be located. |
| 177 | std::set<GLuint> reservedLocations; |
| 178 | // Locations which have been allocated for an unused uniform. |
| 179 | std::set<GLuint> ignoredLocations; |
| 180 | |
| 181 | int maxUniformLocation = -1; |
| 182 | |
| 183 | // Gather uniform locations that have been set either using the bindUniformLocation API or by |
| 184 | // using a location layout qualifier and check conflicts between them. |
| 185 | if (!gatherUniformLocationsAndCheckConflicts(infoLog, uniformLocationBindings, |
| 186 | &reservedLocations, &ignoredLocations, |
| 187 | &maxUniformLocation)) |
| 188 | { |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | // Conflicts have been checked, now we can prune non-statically used uniforms. Code further down |
| 193 | // the line relies on only having statically used uniforms in mUniforms. |
| 194 | pruneUnusedUniforms(); |
| 195 | |
| 196 | // Gather uniforms that have their location pre-set and uniforms that don't yet have a location. |
| 197 | std::vector<VariableLocation> unlocatedUniforms; |
| 198 | std::map<GLuint, VariableLocation> preLocatedUniforms; |
| 199 | |
| 200 | for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++) |
| 201 | { |
| 202 | const LinkedUniform &uniform = mUniforms[uniformIndex]; |
| 203 | |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 204 | if (uniform.isBuiltIn() || IsAtomicCounterType(uniform.type)) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 205 | { |
| 206 | continue; |
| 207 | } |
| 208 | |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 209 | int preSetLocation = GetUniformLocationBinding(uniformLocationBindings, uniform); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 210 | int shaderLocation = uniform.location; |
| 211 | |
| 212 | if (shaderLocation != -1) |
| 213 | { |
| 214 | preSetLocation = shaderLocation; |
| 215 | } |
| 216 | |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 217 | unsigned int elementCount = uniform.getBasicTypeElementCount(); |
| 218 | for (unsigned int arrayIndex = 0; arrayIndex < elementCount; arrayIndex++) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 219 | { |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 220 | VariableLocation location(arrayIndex, static_cast<unsigned int>(uniformIndex)); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 221 | |
| 222 | if ((arrayIndex == 0 && preSetLocation != -1) || shaderLocation != -1) |
| 223 | { |
| 224 | int elementLocation = preSetLocation + arrayIndex; |
| 225 | preLocatedUniforms[elementLocation] = location; |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | unlocatedUniforms.push_back(location); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // Make enough space for all uniforms, with pre-set locations or not. |
| 235 | mUniformLocations.resize( |
| 236 | std::max(unlocatedUniforms.size() + preLocatedUniforms.size() + ignoredLocations.size(), |
| 237 | static_cast<size_t>(maxUniformLocation + 1))); |
| 238 | |
| 239 | // Assign uniforms with pre-set locations |
| 240 | for (const auto &uniform : preLocatedUniforms) |
| 241 | { |
| 242 | mUniformLocations[uniform.first] = uniform.second; |
| 243 | } |
| 244 | |
| 245 | // Assign ignored uniforms |
| 246 | for (const auto &ignoredLocation : ignoredLocations) |
| 247 | { |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 248 | mUniformLocations[ignoredLocation].markIgnored(); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | // Automatically assign locations for the rest of the uniforms |
| 252 | size_t nextUniformLocation = 0; |
| 253 | for (const auto &unlocatedUniform : unlocatedUniforms) |
| 254 | { |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 255 | while (mUniformLocations[nextUniformLocation].used() || |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 256 | mUniformLocations[nextUniformLocation].ignored) |
| 257 | { |
| 258 | nextUniformLocation++; |
| 259 | } |
| 260 | |
| 261 | ASSERT(nextUniformLocation < mUniformLocations.size()); |
| 262 | mUniformLocations[nextUniformLocation] = unlocatedUniform; |
| 263 | nextUniformLocation++; |
| 264 | } |
| 265 | |
| 266 | return true; |
| 267 | } |
| 268 | |
| 269 | bool UniformLinker::gatherUniformLocationsAndCheckConflicts( |
| 270 | InfoLog &infoLog, |
Jamie Madill | 3c1da04 | 2017-11-27 18:33:40 -0500 | [diff] [blame] | 271 | const ProgramBindings &uniformLocationBindings, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 272 | std::set<GLuint> *reservedLocations, |
| 273 | std::set<GLuint> *ignoredLocations, |
| 274 | int *maxUniformLocation) |
| 275 | { |
| 276 | for (const LinkedUniform &uniform : mUniforms) |
| 277 | { |
| 278 | if (uniform.isBuiltIn()) |
| 279 | { |
| 280 | continue; |
| 281 | } |
| 282 | |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 283 | int apiBoundLocation = GetUniformLocationBinding(uniformLocationBindings, uniform); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 284 | int shaderLocation = uniform.location; |
| 285 | |
| 286 | if (shaderLocation != -1) |
| 287 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 288 | unsigned int elementCount = uniform.getBasicTypeElementCount(); |
| 289 | |
| 290 | for (unsigned int arrayIndex = 0; arrayIndex < elementCount; arrayIndex++) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 291 | { |
| 292 | // GLSL ES 3.10 section 4.4.3 |
| 293 | int elementLocation = shaderLocation + arrayIndex; |
| 294 | *maxUniformLocation = std::max(*maxUniformLocation, elementLocation); |
| 295 | if (reservedLocations->find(elementLocation) != reservedLocations->end()) |
| 296 | { |
| 297 | infoLog << "Multiple uniforms bound to location " << elementLocation << "."; |
| 298 | return false; |
| 299 | } |
| 300 | reservedLocations->insert(elementLocation); |
| 301 | if (!uniform.staticUse) |
| 302 | { |
| 303 | ignoredLocations->insert(elementLocation); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | else if (apiBoundLocation != -1 && uniform.staticUse) |
| 308 | { |
| 309 | // Only the first location is reserved even if the uniform is an array. |
| 310 | *maxUniformLocation = std::max(*maxUniformLocation, apiBoundLocation); |
| 311 | if (reservedLocations->find(apiBoundLocation) != reservedLocations->end()) |
| 312 | { |
| 313 | infoLog << "Multiple uniforms bound to location " << apiBoundLocation << "."; |
| 314 | return false; |
| 315 | } |
| 316 | reservedLocations->insert(apiBoundLocation); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | // Record the uniform locations that were bound using the API for uniforms that were not found |
| 321 | // from the shader. Other uniforms should not be assigned to those locations. |
| 322 | for (const auto &locationBinding : uniformLocationBindings) |
| 323 | { |
| 324 | GLuint location = locationBinding.second; |
| 325 | if (reservedLocations->find(location) == reservedLocations->end()) |
| 326 | { |
| 327 | ignoredLocations->insert(location); |
| 328 | *maxUniformLocation = std::max(*maxUniformLocation, static_cast<int>(location)); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | return true; |
| 333 | } |
| 334 | |
| 335 | void UniformLinker::pruneUnusedUniforms() |
| 336 | { |
| 337 | auto uniformIter = mUniforms.begin(); |
| 338 | while (uniformIter != mUniforms.end()) |
| 339 | { |
| 340 | if (uniformIter->staticUse) |
| 341 | { |
| 342 | ++uniformIter; |
| 343 | } |
| 344 | else |
| 345 | { |
| 346 | uniformIter = mUniforms.erase(uniformIter); |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | bool UniformLinker::flattenUniformsAndCheckCapsForShader( |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 352 | const Context *context, |
| 353 | Shader *shader, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 354 | GLuint maxUniformComponents, |
| 355 | GLuint maxTextureImageUnits, |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 356 | GLuint maxImageUnits, |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 357 | GLuint maxAtomicCounters, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 358 | const std::string &componentsErrorMessage, |
| 359 | const std::string &samplerErrorMessage, |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 360 | const std::string &imageErrorMessage, |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 361 | const std::string &atomicCounterErrorMessage, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 362 | std::vector<LinkedUniform> &samplerUniforms, |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 363 | std::vector<LinkedUniform> &imageUniforms, |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 364 | std::vector<LinkedUniform> &atomicCounterUniforms, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 365 | InfoLog &infoLog) |
| 366 | { |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 367 | ShaderUniformCount shaderUniformCount; |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 368 | for (const sh::Uniform &uniform : shader->getUniforms(context)) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 369 | { |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 370 | shaderUniformCount += flattenUniform(uniform, &samplerUniforms, &imageUniforms, |
| 371 | &atomicCounterUniforms, shader->getType()); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 372 | } |
| 373 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 374 | if (shaderUniformCount.vectorCount > maxUniformComponents) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 375 | { |
| 376 | infoLog << componentsErrorMessage << maxUniformComponents << ")."; |
| 377 | return false; |
| 378 | } |
| 379 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 380 | if (shaderUniformCount.samplerCount > maxTextureImageUnits) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 381 | { |
| 382 | infoLog << samplerErrorMessage << maxTextureImageUnits << ")."; |
| 383 | return false; |
| 384 | } |
| 385 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 386 | if (shaderUniformCount.imageCount > maxImageUnits) |
| 387 | { |
| 388 | infoLog << imageErrorMessage << maxImageUnits << ")."; |
| 389 | return false; |
| 390 | } |
| 391 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 392 | if (shaderUniformCount.atomicCounterCount > maxAtomicCounters) |
| 393 | { |
| 394 | infoLog << atomicCounterErrorMessage << maxAtomicCounters << ")."; |
| 395 | return false; |
| 396 | } |
| 397 | |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 398 | return true; |
| 399 | } |
| 400 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 401 | bool UniformLinker::flattenUniformsAndCheckCaps(const Context *context, InfoLog &infoLog) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 402 | { |
| 403 | std::vector<LinkedUniform> samplerUniforms; |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 404 | std::vector<LinkedUniform> imageUniforms; |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 405 | std::vector<LinkedUniform> atomicCounterUniforms; |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 406 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 407 | const Caps &caps = context->getCaps(); |
| 408 | |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 409 | if (mState.getAttachedComputeShader()) |
| 410 | { |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 411 | Shader *computeShader = mState.getAttachedComputeShader(); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 412 | |
| 413 | // TODO (mradev): check whether we need finer-grained component counting |
| 414 | if (!flattenUniformsAndCheckCapsForShader( |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 415 | context, computeShader, caps.maxComputeUniformComponents / 4, |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 416 | caps.maxComputeTextureImageUnits, caps.maxComputeImageUniforms, |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 417 | caps.maxComputeAtomicCounters, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 418 | "Compute shader active uniforms exceed MAX_COMPUTE_UNIFORM_COMPONENTS (", |
| 419 | "Compute shader sampler count exceeds MAX_COMPUTE_TEXTURE_IMAGE_UNITS (", |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 420 | "Compute shader image count exceeds MAX_COMPUTE_IMAGE_UNIFORMS (", |
| 421 | "Compute shader atomic counter count exceeds MAX_COMPUTE_ATOMIC_COUNTERS (", |
| 422 | samplerUniforms, imageUniforms, atomicCounterUniforms, infoLog)) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 423 | { |
| 424 | return false; |
| 425 | } |
| 426 | } |
| 427 | else |
| 428 | { |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 429 | Shader *vertexShader = mState.getAttachedVertexShader(); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 430 | |
| 431 | if (!flattenUniformsAndCheckCapsForShader( |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 432 | context, vertexShader, caps.maxVertexUniformVectors, |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 433 | caps.maxVertexTextureImageUnits, caps.maxVertexImageUniforms, |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 434 | caps.maxVertexAtomicCounters, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 435 | "Vertex shader active uniforms exceed MAX_VERTEX_UNIFORM_VECTORS (", |
| 436 | "Vertex shader sampler count exceeds MAX_VERTEX_TEXTURE_IMAGE_UNITS (", |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 437 | "Vertex shader image count exceeds MAX_VERTEX_IMAGE_UNIFORMS (", |
| 438 | "Vertex shader atomic counter count exceeds MAX_VERTEX_ATOMIC_COUNTERS (", |
| 439 | samplerUniforms, imageUniforms, atomicCounterUniforms, infoLog)) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 440 | { |
| 441 | return false; |
| 442 | } |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 443 | |
| 444 | Shader *fragmentShader = mState.getAttachedFragmentShader(); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 445 | |
| 446 | if (!flattenUniformsAndCheckCapsForShader( |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 447 | context, fragmentShader, caps.maxFragmentUniformVectors, caps.maxTextureImageUnits, |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 448 | caps.maxFragmentImageUniforms, caps.maxFragmentAtomicCounters, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 449 | "Fragment shader active uniforms exceed MAX_FRAGMENT_UNIFORM_VECTORS (", |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 450 | "Fragment shader sampler count exceeds MAX_TEXTURE_IMAGE_UNITS (", |
| 451 | "Fragment shader image count exceeds MAX_FRAGMENT_IMAGE_UNIFORMS (", |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 452 | "Fragment shader atomic counter count exceeds MAX_FRAGMENT_ATOMIC_COUNTERS (", |
| 453 | samplerUniforms, imageUniforms, atomicCounterUniforms, infoLog)) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 454 | { |
| 455 | return false; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | mUniforms.insert(mUniforms.end(), samplerUniforms.begin(), samplerUniforms.end()); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 460 | mUniforms.insert(mUniforms.end(), imageUniforms.begin(), imageUniforms.end()); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 461 | mUniforms.insert(mUniforms.end(), atomicCounterUniforms.begin(), atomicCounterUniforms.end()); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 462 | return true; |
| 463 | } |
| 464 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 465 | UniformLinker::ShaderUniformCount UniformLinker::flattenUniform( |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 466 | const sh::Uniform &uniform, |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 467 | std::vector<LinkedUniform> *samplerUniforms, |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 468 | std::vector<LinkedUniform> *imageUniforms, |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 469 | std::vector<LinkedUniform> *atomicCounterUniforms, |
| 470 | GLenum shaderType) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 471 | { |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 472 | int location = uniform.location; |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 473 | ShaderUniformCount shaderUniformCount = |
| 474 | flattenUniformImpl(uniform, uniform.name, uniform.mappedName, samplerUniforms, |
| 475 | imageUniforms, atomicCounterUniforms, shaderType, uniform.staticUse, |
| 476 | uniform.binding, uniform.offset, &location); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 477 | if (uniform.staticUse) |
| 478 | { |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 479 | return shaderUniformCount; |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 480 | } |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 481 | return ShaderUniformCount(); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 484 | UniformLinker::ShaderUniformCount UniformLinker::flattenArrayOfStructsUniform( |
| 485 | const sh::ShaderVariable &uniform, |
| 486 | unsigned int arrayNestingIndex, |
| 487 | const std::string &namePrefix, |
| 488 | const std::string &mappedNamePrefix, |
| 489 | std::vector<LinkedUniform> *samplerUniforms, |
| 490 | std::vector<LinkedUniform> *imageUniforms, |
| 491 | std::vector<LinkedUniform> *atomicCounterUniforms, |
| 492 | GLenum shaderType, |
| 493 | bool markStaticUse, |
| 494 | int binding, |
| 495 | int offset, |
| 496 | int *location) |
| 497 | { |
| 498 | // Nested arrays are processed starting from outermost (arrayNestingIndex 0u) and ending at the |
| 499 | // innermost. |
| 500 | ShaderUniformCount shaderUniformCount; |
| 501 | const unsigned int currentArraySize = uniform.getNestedArraySize(arrayNestingIndex); |
| 502 | for (unsigned int arrayElement = 0u; arrayElement < currentArraySize; ++arrayElement) |
| 503 | { |
| 504 | const std::string elementName = namePrefix + ArrayString(arrayElement); |
| 505 | const std::string elementMappedName = mappedNamePrefix + ArrayString(arrayElement); |
| 506 | if (arrayNestingIndex + 1u < uniform.arraySizes.size()) |
| 507 | { |
| 508 | shaderUniformCount += flattenArrayOfStructsUniform( |
| 509 | uniform, arrayNestingIndex + 1u, elementName, elementMappedName, samplerUniforms, |
| 510 | imageUniforms, atomicCounterUniforms, shaderType, markStaticUse, binding, offset, |
| 511 | location); |
| 512 | } |
| 513 | else |
| 514 | { |
| 515 | shaderUniformCount += flattenStructUniform( |
| 516 | uniform.fields, elementName, elementMappedName, samplerUniforms, imageUniforms, |
| 517 | atomicCounterUniforms, shaderType, markStaticUse, binding, offset, location); |
| 518 | } |
| 519 | } |
| 520 | return shaderUniformCount; |
| 521 | } |
| 522 | |
| 523 | UniformLinker::ShaderUniformCount UniformLinker::flattenStructUniform( |
| 524 | const std::vector<sh::ShaderVariable> &fields, |
| 525 | const std::string &namePrefix, |
| 526 | const std::string &mappedNamePrefix, |
| 527 | std::vector<LinkedUniform> *samplerUniforms, |
| 528 | std::vector<LinkedUniform> *imageUniforms, |
| 529 | std::vector<LinkedUniform> *atomicCounterUniforms, |
| 530 | GLenum shaderType, |
| 531 | bool markStaticUse, |
| 532 | int binding, |
| 533 | int offset, |
| 534 | int *location) |
| 535 | { |
| 536 | ShaderUniformCount shaderUniformCount; |
| 537 | for (const sh::ShaderVariable &field : fields) |
| 538 | { |
| 539 | const std::string &fieldName = namePrefix + "." + field.name; |
| 540 | const std::string &fieldMappedName = mappedNamePrefix + "." + field.mappedName; |
| 541 | |
| 542 | shaderUniformCount += |
| 543 | flattenUniformImpl(field, fieldName, fieldMappedName, samplerUniforms, imageUniforms, |
| 544 | atomicCounterUniforms, shaderType, markStaticUse, -1, -1, location); |
| 545 | } |
| 546 | return shaderUniformCount; |
| 547 | } |
| 548 | |
| 549 | UniformLinker::ShaderUniformCount UniformLinker::flattenArrayUniform( |
| 550 | const sh::ShaderVariable &uniform, |
| 551 | const std::string &namePrefix, |
| 552 | const std::string &mappedNamePrefix, |
| 553 | std::vector<LinkedUniform> *samplerUniforms, |
| 554 | std::vector<LinkedUniform> *imageUniforms, |
| 555 | std::vector<LinkedUniform> *atomicCounterUniforms, |
| 556 | GLenum shaderType, |
| 557 | bool markStaticUse, |
| 558 | int binding, |
| 559 | int offset, |
| 560 | int *location) |
| 561 | { |
| 562 | ShaderUniformCount shaderUniformCount; |
| 563 | |
| 564 | ASSERT(uniform.isArray()); |
| 565 | for (unsigned int arrayElement = 0u; arrayElement < uniform.getOutermostArraySize(); |
| 566 | ++arrayElement) |
| 567 | { |
| 568 | sh::ShaderVariable uniformElement = uniform; |
| 569 | uniformElement.indexIntoArray(arrayElement); |
| 570 | const std::string elementName = namePrefix + ArrayString(arrayElement); |
| 571 | const std::string elementMappedName = mappedNamePrefix + ArrayString(arrayElement); |
| 572 | |
| 573 | shaderUniformCount += flattenUniformImpl( |
| 574 | uniformElement, elementName, elementMappedName, samplerUniforms, imageUniforms, |
| 575 | atomicCounterUniforms, shaderType, markStaticUse, binding, offset, location); |
| 576 | } |
| 577 | return shaderUniformCount; |
| 578 | } |
| 579 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 580 | UniformLinker::ShaderUniformCount UniformLinker::flattenUniformImpl( |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 581 | const sh::ShaderVariable &uniform, |
| 582 | const std::string &fullName, |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 583 | const std::string &fullMappedName, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 584 | std::vector<LinkedUniform> *samplerUniforms, |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 585 | std::vector<LinkedUniform> *imageUniforms, |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 586 | std::vector<LinkedUniform> *atomicCounterUniforms, |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 587 | GLenum shaderType, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 588 | bool markStaticUse, |
| 589 | int binding, |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 590 | int offset, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 591 | int *location) |
| 592 | { |
| 593 | ASSERT(location); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 594 | ShaderUniformCount shaderUniformCount; |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 595 | |
| 596 | if (uniform.isStruct()) |
| 597 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 598 | if (uniform.isArray()) |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 599 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 600 | shaderUniformCount += flattenArrayOfStructsUniform( |
| 601 | uniform, 0u, fullName, fullMappedName, samplerUniforms, imageUniforms, |
| 602 | atomicCounterUniforms, shaderType, markStaticUse, binding, offset, location); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 603 | } |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 604 | else |
| 605 | { |
| 606 | shaderUniformCount += flattenStructUniform( |
| 607 | uniform.fields, fullName, fullMappedName, samplerUniforms, imageUniforms, |
| 608 | atomicCounterUniforms, shaderType, markStaticUse, binding, offset, location); |
| 609 | } |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 610 | return shaderUniformCount; |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 611 | } |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 612 | if (uniform.isArrayOfArrays()) |
| 613 | { |
| 614 | // GLES 3.1 November 2016 section 7.3.1 page 77: |
| 615 | // "For an active variable declared as an array of an aggregate data type (structures or |
| 616 | // arrays), a separate entry will be generated for each active array element" |
| 617 | return flattenArrayUniform(uniform, fullName, fullMappedName, samplerUniforms, |
| 618 | imageUniforms, atomicCounterUniforms, shaderType, markStaticUse, |
| 619 | binding, offset, location); |
| 620 | } |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 621 | |
| 622 | // Not a struct |
| 623 | bool isSampler = IsSamplerType(uniform.type); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 624 | bool isImage = IsImageType(uniform.type); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 625 | bool isAtomicCounter = IsAtomicCounterType(uniform.type); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 626 | std::vector<gl::LinkedUniform> *uniformList = &mUniforms; |
| 627 | if (isSampler) |
| 628 | { |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 629 | uniformList = samplerUniforms; |
| 630 | } |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 631 | else if (isImage) |
| 632 | { |
| 633 | uniformList = imageUniforms; |
| 634 | } |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 635 | else if (isAtomicCounter) |
| 636 | { |
| 637 | uniformList = atomicCounterUniforms; |
| 638 | } |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 639 | |
| 640 | std::string fullNameWithArrayIndex(fullName); |
| 641 | std::string fullMappedNameWithArrayIndex(fullMappedName); |
| 642 | |
| 643 | if (uniform.isArray()) |
| 644 | { |
| 645 | // We're following the GLES 3.1 November 2016 spec section 7.3.1.1 Naming Active Resources |
| 646 | // and including [0] at the end of array variable names. |
| 647 | fullNameWithArrayIndex += "[0]"; |
| 648 | fullMappedNameWithArrayIndex += "[0]"; |
| 649 | } |
| 650 | |
| 651 | LinkedUniform *existingUniform = FindUniform(*uniformList, fullNameWithArrayIndex); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 652 | if (existingUniform) |
| 653 | { |
| 654 | if (binding != -1) |
| 655 | { |
| 656 | existingUniform->binding = binding; |
| 657 | } |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 658 | if (offset != -1) |
| 659 | { |
| 660 | existingUniform->offset = offset; |
| 661 | } |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 662 | if (*location != -1) |
| 663 | { |
| 664 | existingUniform->location = *location; |
| 665 | } |
| 666 | if (markStaticUse) |
| 667 | { |
| 668 | existingUniform->staticUse = true; |
jchen10 | 4ef2503 | 2017-11-01 09:36:51 +0800 | [diff] [blame] | 669 | existingUniform->setStaticUse(shaderType, true); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | else |
| 673 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 674 | ASSERT(uniform.arraySizes.size() <= 1u); |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 675 | LinkedUniform linkedUniform(uniform.type, uniform.precision, fullNameWithArrayIndex, |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 676 | uniform.arraySizes, binding, offset, *location, -1, |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 677 | sh::BlockMemberInfo::getDefaultBlockInfo()); |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 678 | linkedUniform.mappedName = fullMappedNameWithArrayIndex; |
| 679 | linkedUniform.staticUse = markStaticUse; |
| 680 | linkedUniform.flattenedOffsetInParentArrays = uniform.flattenedOffsetInParentArrays; |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 681 | if (markStaticUse) |
| 682 | { |
jchen10 | 4ef2503 | 2017-11-01 09:36:51 +0800 | [diff] [blame] | 683 | linkedUniform.setStaticUse(shaderType, true); |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 684 | } |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 685 | |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 686 | uniformList->push_back(linkedUniform); |
| 687 | } |
| 688 | |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 689 | // Struct and array of arrays uniforms get flattened so we can use getBasicTypeElementCount(). |
| 690 | unsigned int elementCount = uniform.getBasicTypeElementCount(); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 691 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 692 | // Samplers and images aren't "real" uniforms, so they don't count towards register usage. |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 693 | // Likewise, don't count "real" uniforms towards opaque count. |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 694 | shaderUniformCount.vectorCount = |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 695 | (IsOpaqueType(uniform.type) ? 0 : (VariableRegisterCount(uniform.type) * elementCount)); |
Jamie Madill | 7af0de5 | 2017-11-06 17:09:33 -0500 | [diff] [blame] | 696 | shaderUniformCount.samplerCount = (isSampler ? elementCount : 0); |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 697 | shaderUniformCount.imageCount = (isImage ? elementCount : 0); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 698 | shaderUniformCount.atomicCounterCount = (isAtomicCounter ? elementCount : 0); |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 699 | |
| 700 | if (*location != -1) |
| 701 | { |
| 702 | *location += elementCount; |
| 703 | } |
| 704 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 705 | return shaderUniformCount; |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 706 | } |
| 707 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 708 | bool UniformLinker::checkMaxCombinedAtomicCounters(const Caps &caps, InfoLog &infoLog) |
| 709 | { |
| 710 | unsigned int atomicCounterCount = 0; |
| 711 | for (const auto &uniform : mUniforms) |
| 712 | { |
| 713 | if (IsAtomicCounterType(uniform.type) && uniform.staticUse) |
| 714 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 715 | atomicCounterCount += uniform.getBasicTypeElementCount(); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 716 | if (atomicCounterCount > caps.maxCombinedAtomicCounters) |
| 717 | { |
| 718 | infoLog << "atomic counter count exceeds MAX_COMBINED_ATOMIC_COUNTERS" |
| 719 | << caps.maxCombinedAtomicCounters << ")."; |
| 720 | return false; |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | return true; |
| 725 | } |
| 726 | |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 727 | // InterfaceBlockLinker implementation. |
| 728 | InterfaceBlockLinker::InterfaceBlockLinker(std::vector<InterfaceBlock> *blocksOut) |
| 729 | : mBlocksOut(blocksOut) |
| 730 | { |
| 731 | } |
| 732 | |
| 733 | InterfaceBlockLinker::~InterfaceBlockLinker() |
| 734 | { |
| 735 | } |
| 736 | |
| 737 | void InterfaceBlockLinker::addShaderBlocks(GLenum shader, |
| 738 | const std::vector<sh::InterfaceBlock> *blocks) |
| 739 | { |
| 740 | mShaderBlocks.push_back(std::make_pair(shader, blocks)); |
| 741 | } |
| 742 | |
| 743 | void InterfaceBlockLinker::linkBlocks(const GetBlockSize &getBlockSize, |
| 744 | const GetBlockMemberInfo &getMemberInfo) const |
| 745 | { |
Jamie Madill | 6db1c2e | 2017-11-08 09:17:40 -0500 | [diff] [blame] | 746 | ASSERT(mBlocksOut->empty()); |
| 747 | |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 748 | std::set<std::string> visitedList; |
| 749 | |
| 750 | for (const auto &shaderBlocks : mShaderBlocks) |
| 751 | { |
| 752 | const GLenum shaderType = shaderBlocks.first; |
| 753 | |
| 754 | for (const auto &block : *shaderBlocks.second) |
| 755 | { |
| 756 | // Only 'packed' blocks are allowed to be considered inactive. |
| 757 | if (!block.staticUse && block.layout == sh::BLOCKLAYOUT_PACKED) |
| 758 | continue; |
| 759 | |
| 760 | if (visitedList.count(block.name) > 0) |
| 761 | { |
| 762 | if (block.staticUse) |
| 763 | { |
| 764 | for (InterfaceBlock &priorBlock : *mBlocksOut) |
| 765 | { |
| 766 | if (block.name == priorBlock.name) |
| 767 | { |
| 768 | priorBlock.setStaticUse(shaderType, true); |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 769 | // TODO(jiajia.qin@intel.com): update the block members static use. |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | else |
| 775 | { |
| 776 | defineInterfaceBlock(getBlockSize, getMemberInfo, block, shaderType); |
| 777 | visitedList.insert(block.name); |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | template <typename VarT> |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 784 | void InterfaceBlockLinker::defineArrayOfStructsBlockMembers(const GetBlockMemberInfo &getMemberInfo, |
| 785 | const VarT &field, |
| 786 | unsigned int arrayNestingIndex, |
| 787 | const std::string &prefix, |
| 788 | const std::string &mappedPrefix, |
| 789 | int blockIndex, |
| 790 | bool singleEntryForTopLevelArray, |
| 791 | int topLevelArraySize) const |
| 792 | { |
| 793 | // Nested arrays are processed starting from outermost (arrayNestingIndex 0u) and ending at the |
| 794 | // innermost. |
| 795 | unsigned int entryGenerationArraySize = field.getNestedArraySize(arrayNestingIndex); |
| 796 | if (singleEntryForTopLevelArray) |
| 797 | { |
| 798 | entryGenerationArraySize = 1; |
| 799 | } |
| 800 | for (unsigned int arrayElement = 0u; arrayElement < entryGenerationArraySize; ++arrayElement) |
| 801 | { |
| 802 | const std::string elementName = prefix + ArrayString(arrayElement); |
| 803 | const std::string elementMappedName = mappedPrefix + ArrayString(arrayElement); |
| 804 | if (arrayNestingIndex + 1u < field.arraySizes.size()) |
| 805 | { |
| 806 | defineArrayOfStructsBlockMembers(getMemberInfo, field, arrayNestingIndex + 1u, |
| 807 | elementName, elementMappedName, blockIndex, false, |
| 808 | topLevelArraySize); |
| 809 | } |
| 810 | else |
| 811 | { |
| 812 | defineBlockMembers(getMemberInfo, field.fields, elementName, elementMappedName, |
| 813 | blockIndex, false, topLevelArraySize); |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | template <typename VarT> |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 819 | void InterfaceBlockLinker::defineBlockMembers(const GetBlockMemberInfo &getMemberInfo, |
| 820 | const std::vector<VarT> &fields, |
| 821 | const std::string &prefix, |
| 822 | const std::string &mappedPrefix, |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 823 | int blockIndex, |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 824 | bool singleEntryForTopLevelArray, |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 825 | int topLevelArraySize) const |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 826 | { |
| 827 | for (const VarT &field : fields) |
| 828 | { |
| 829 | std::string fullName = (prefix.empty() ? field.name : prefix + "." + field.name); |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 830 | std::string fullMappedName = |
| 831 | (mappedPrefix.empty() ? field.mappedName : mappedPrefix + "." + field.mappedName); |
| 832 | |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 833 | defineBlockMember(getMemberInfo, field, fullName, fullMappedName, blockIndex, |
| 834 | singleEntryForTopLevelArray, topLevelArraySize); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | template <typename VarT> |
| 839 | void InterfaceBlockLinker::defineBlockMember(const GetBlockMemberInfo &getMemberInfo, |
| 840 | const VarT &field, |
| 841 | const std::string &fullName, |
| 842 | const std::string &fullMappedName, |
| 843 | int blockIndex, |
| 844 | bool singleEntryForTopLevelArray, |
| 845 | int topLevelArraySize) const |
| 846 | { |
| 847 | int nextArraySize = topLevelArraySize; |
| 848 | if (((field.isArray() && field.isStruct()) || field.isArrayOfArrays()) && |
| 849 | singleEntryForTopLevelArray) |
| 850 | { |
| 851 | // In OpenGL ES 3.10 spec, session 7.3.1.1 'For an active shader storage block |
| 852 | // member declared as an array of an aggregate type, an entry will be generated only |
| 853 | // for the first array element, regardless of its type.' |
| 854 | nextArraySize = field.getOutermostArraySize(); |
| 855 | } |
| 856 | |
| 857 | if (field.isStruct()) |
| 858 | { |
| 859 | if (field.isArray()) |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 860 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 861 | defineArrayOfStructsBlockMembers(getMemberInfo, field, 0u, fullName, fullMappedName, |
| 862 | blockIndex, singleEntryForTopLevelArray, |
| 863 | nextArraySize); |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 864 | } |
| 865 | else |
| 866 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 867 | ASSERT(nextArraySize == topLevelArraySize); |
| 868 | defineBlockMembers(getMemberInfo, field.fields, fullName, fullMappedName, blockIndex, |
| 869 | false, nextArraySize); |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 870 | } |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 871 | return; |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 872 | } |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 873 | if (field.isArrayOfArrays()) |
| 874 | { |
| 875 | unsigned int entryGenerationArraySize = field.getOutermostArraySize(); |
| 876 | if (singleEntryForTopLevelArray) |
| 877 | { |
| 878 | entryGenerationArraySize = 1u; |
| 879 | } |
| 880 | for (unsigned int arrayElement = 0u; arrayElement < entryGenerationArraySize; |
| 881 | ++arrayElement) |
| 882 | { |
| 883 | VarT fieldElement = field; |
| 884 | fieldElement.indexIntoArray(arrayElement); |
| 885 | const std::string elementName = fullName + ArrayString(arrayElement); |
| 886 | const std::string elementMappedName = fullMappedName + ArrayString(arrayElement); |
| 887 | |
| 888 | defineBlockMember(getMemberInfo, fieldElement, elementName, elementMappedName, |
| 889 | blockIndex, false, nextArraySize); |
| 890 | } |
| 891 | return; |
| 892 | } |
| 893 | |
| 894 | // If getBlockMemberInfo returns false, the variable is optimized out. |
| 895 | sh::BlockMemberInfo memberInfo; |
| 896 | if (!getMemberInfo(fullName, fullMappedName, &memberInfo)) |
| 897 | { |
| 898 | return; |
| 899 | } |
| 900 | |
| 901 | std::string fullNameWithArrayIndex = fullName; |
| 902 | std::string fullMappedNameWithArrayIndex = fullMappedName; |
| 903 | |
| 904 | if (field.isArray()) |
| 905 | { |
| 906 | fullNameWithArrayIndex += "[0]"; |
| 907 | fullMappedNameWithArrayIndex += "[0]"; |
| 908 | } |
| 909 | |
| 910 | ASSERT(nextArraySize == topLevelArraySize); |
| 911 | defineBlockMemberImpl(field, fullNameWithArrayIndex, fullMappedNameWithArrayIndex, blockIndex, |
| 912 | memberInfo, nextArraySize); |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | void InterfaceBlockLinker::defineInterfaceBlock(const GetBlockSize &getBlockSize, |
| 916 | const GetBlockMemberInfo &getMemberInfo, |
| 917 | const sh::InterfaceBlock &interfaceBlock, |
| 918 | GLenum shaderType) const |
| 919 | { |
| 920 | size_t blockSize = 0; |
| 921 | std::vector<unsigned int> blockIndexes; |
| 922 | |
| 923 | int blockIndex = static_cast<int>(mBlocksOut->size()); |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 924 | // Track the first and last block member index to determine the range of active block members in |
| 925 | // the block. |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 926 | size_t firstBlockMemberIndex = getCurrentBlockMemberIndex(); |
| 927 | defineBlockMembers(getMemberInfo, interfaceBlock.fields, interfaceBlock.fieldPrefix(), |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 928 | interfaceBlock.fieldMappedPrefix(), blockIndex, |
| 929 | interfaceBlock.blockType == sh::BlockType::BLOCK_BUFFER, 1); |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 930 | size_t lastBlockMemberIndex = getCurrentBlockMemberIndex(); |
| 931 | |
| 932 | for (size_t blockMemberIndex = firstBlockMemberIndex; blockMemberIndex < lastBlockMemberIndex; |
| 933 | ++blockMemberIndex) |
| 934 | { |
| 935 | blockIndexes.push_back(static_cast<unsigned int>(blockMemberIndex)); |
| 936 | } |
| 937 | |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 938 | for (unsigned int arrayElement = 0; arrayElement < interfaceBlock.elementCount(); |
| 939 | ++arrayElement) |
| 940 | { |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 941 | std::string blockArrayName = interfaceBlock.name; |
| 942 | std::string blockMappedArrayName = interfaceBlock.mappedName; |
| 943 | if (interfaceBlock.isArray()) |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 944 | { |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 945 | blockArrayName += ArrayString(arrayElement); |
| 946 | blockMappedArrayName += ArrayString(arrayElement); |
| 947 | } |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 948 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 949 | // Don't define this block at all if it's not active in the implementation. |
| 950 | if (!getBlockSize(blockArrayName, blockMappedArrayName, &blockSize)) |
| 951 | { |
| 952 | continue; |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 953 | } |
| 954 | |
Jiajia Qin | feb2c63 | 2017-12-08 17:59:19 +0800 | [diff] [blame] | 955 | // ESSL 3.10 section 4.4.4 page 58: |
| 956 | // Any uniform or shader storage block declared without a binding qualifier is initially |
| 957 | // assigned to block binding point zero. |
| 958 | int blockBinding = |
| 959 | (interfaceBlock.binding == -1 ? 0 : interfaceBlock.binding + arrayElement); |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 960 | InterfaceBlock block(interfaceBlock.name, interfaceBlock.mappedName, |
Jiajia Qin | feb2c63 | 2017-12-08 17:59:19 +0800 | [diff] [blame] | 961 | interfaceBlock.isArray(), arrayElement, blockBinding); |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 962 | block.memberIndexes = blockIndexes; |
| 963 | block.setStaticUse(shaderType, interfaceBlock.staticUse); |
| 964 | |
| 965 | // Since all block elements in an array share the same active interface blocks, they |
| 966 | // will all be active once any block member is used. So, since interfaceBlock.name[0] |
| 967 | // was active, here we will add every block element in the array. |
| 968 | block.dataSize = static_cast<unsigned int>(blockSize); |
| 969 | mBlocksOut->push_back(block); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | // UniformBlockLinker implementation. |
| 974 | UniformBlockLinker::UniformBlockLinker(std::vector<InterfaceBlock> *blocksOut, |
| 975 | std::vector<LinkedUniform> *uniformsOut) |
| 976 | : InterfaceBlockLinker(blocksOut), mUniformsOut(uniformsOut) |
| 977 | { |
| 978 | } |
| 979 | |
| 980 | UniformBlockLinker::~UniformBlockLinker() |
| 981 | { |
| 982 | } |
| 983 | |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 984 | void UniformBlockLinker::defineBlockMemberImpl(const sh::ShaderVariable &field, |
| 985 | const std::string &fullName, |
| 986 | const std::string &fullMappedName, |
| 987 | int blockIndex, |
| 988 | const sh::BlockMemberInfo &memberInfo, |
| 989 | int /*topLevelArraySize*/) const |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 990 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 991 | LinkedUniform newUniform(field.type, field.precision, fullName, field.arraySizes, -1, -1, -1, |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 992 | blockIndex, memberInfo); |
| 993 | newUniform.mappedName = fullMappedName; |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 994 | // TODO(jiajia.qin@intel.com): update the block memeber static use. |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 995 | |
| 996 | // Since block uniforms have no location, we don't need to store them in the uniform locations |
| 997 | // list. |
| 998 | mUniformsOut->push_back(newUniform); |
| 999 | } |
| 1000 | |
| 1001 | size_t UniformBlockLinker::getCurrentBlockMemberIndex() const |
| 1002 | { |
| 1003 | return mUniformsOut->size(); |
| 1004 | } |
| 1005 | |
| 1006 | // ShaderStorageBlockLinker implementation. |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 1007 | ShaderStorageBlockLinker::ShaderStorageBlockLinker(std::vector<InterfaceBlock> *blocksOut, |
| 1008 | std::vector<BufferVariable> *bufferVariablesOut) |
| 1009 | : InterfaceBlockLinker(blocksOut), mBufferVariablesOut(bufferVariablesOut) |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 1010 | { |
| 1011 | } |
| 1012 | |
| 1013 | ShaderStorageBlockLinker::~ShaderStorageBlockLinker() |
| 1014 | { |
| 1015 | } |
| 1016 | |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 1017 | void ShaderStorageBlockLinker::defineBlockMemberImpl(const sh::ShaderVariable &field, |
| 1018 | const std::string &fullName, |
| 1019 | const std::string &fullMappedName, |
| 1020 | int blockIndex, |
| 1021 | const sh::BlockMemberInfo &memberInfo, |
| 1022 | int topLevelArraySize) const |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 1023 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 1024 | BufferVariable newBufferVariable(field.type, field.precision, fullName, field.arraySizes, |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 1025 | blockIndex, memberInfo); |
| 1026 | newBufferVariable.mappedName = fullMappedName; |
| 1027 | // TODO(jiajia.qin@intel.com): update the block memeber static use. |
| 1028 | |
| 1029 | newBufferVariable.topLevelArraySize = topLevelArraySize; |
| 1030 | |
| 1031 | mBufferVariablesOut->push_back(newBufferVariable); |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | size_t ShaderStorageBlockLinker::getCurrentBlockMemberIndex() const |
| 1035 | { |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 1036 | return mBufferVariablesOut->size(); |
Jamie Madill | 977abce | 2017-11-07 08:03:19 -0500 | [diff] [blame] | 1037 | } |
| 1038 | |
Jiajia Qin | 94f1e89 | 2017-11-20 12:14:32 +0800 | [diff] [blame] | 1039 | // AtomicCounterBufferLinker implementation. |
| 1040 | AtomicCounterBufferLinker::AtomicCounterBufferLinker( |
| 1041 | std::vector<AtomicCounterBuffer> *atomicCounterBuffersOut) |
| 1042 | : mAtomicCounterBuffersOut(atomicCounterBuffersOut) |
| 1043 | { |
| 1044 | } |
| 1045 | |
| 1046 | AtomicCounterBufferLinker::~AtomicCounterBufferLinker() |
| 1047 | { |
| 1048 | } |
| 1049 | |
| 1050 | void AtomicCounterBufferLinker::link(const std::map<int, unsigned int> &sizeMap) const |
| 1051 | { |
| 1052 | for (auto &atomicCounterBuffer : *mAtomicCounterBuffersOut) |
| 1053 | { |
| 1054 | auto bufferSize = sizeMap.find(atomicCounterBuffer.binding); |
| 1055 | ASSERT(bufferSize != sizeMap.end()); |
| 1056 | atomicCounterBuffer.dataSize = bufferSize->second; |
| 1057 | } |
| 1058 | } |
| 1059 | |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 1060 | } // namespace gl |