Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 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 | // ProgramGL.cpp: Implements the class methods for ProgramGL. |
| 8 | |
| 9 | #include "libANGLE/renderer/gl/ProgramGL.h" |
| 10 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 11 | #include "common/angleutils.h" |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 12 | #include "common/bitset_utils.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 13 | #include "common/debug.h" |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 14 | #include "common/string_utils.h" |
Geoff Lang | 5ed74cf | 2015-04-14 13:57:07 -0400 | [diff] [blame] | 15 | #include "common/utilities.h" |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 16 | #include "libANGLE/Context.h" |
| 17 | #include "libANGLE/Uniform.h" |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 18 | #include "libANGLE/renderer/gl/ContextGL.h" |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 19 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
| 20 | #include "libANGLE/renderer/gl/ShaderGL.h" |
| 21 | #include "libANGLE/renderer/gl/StateManagerGL.h" |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 22 | #include "libANGLE/renderer/gl/WorkaroundsGL.h" |
unknown | b4a3af2 | 2015-11-25 15:02:51 -0500 | [diff] [blame] | 23 | #include "platform/Platform.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 24 | |
| 25 | namespace rx |
| 26 | { |
| 27 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 28 | ProgramGL::ProgramGL(const gl::ProgramState &data, |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 29 | const FunctionsGL *functions, |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 30 | const WorkaroundsGL &workarounds, |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 31 | StateManagerGL *stateManager, |
| 32 | bool enablePathRendering) |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 33 | : ProgramImpl(data), |
| 34 | mFunctions(functions), |
| 35 | mWorkarounds(workarounds), |
| 36 | mStateManager(stateManager), |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 37 | mEnablePathRendering(enablePathRendering), |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 38 | mMultiviewBaseViewLayerIndexUniformLocation(-1), |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 39 | mProgramID(0) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 40 | { |
| 41 | ASSERT(mFunctions); |
| 42 | ASSERT(mStateManager); |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 43 | |
| 44 | mProgramID = mFunctions->createProgram(); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 45 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 46 | |
| 47 | ProgramGL::~ProgramGL() |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 48 | { |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 49 | mFunctions->deleteProgram(mProgramID); |
| 50 | mProgramID = 0; |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 51 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 52 | |
Jamie Madill | 9cf9e87 | 2017-06-05 12:59:25 -0400 | [diff] [blame] | 53 | gl::LinkResult ProgramGL::load(const gl::Context *context, |
| 54 | gl::InfoLog &infoLog, |
| 55 | gl::BinaryInputStream *stream) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 56 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 57 | preLink(); |
| 58 | |
| 59 | // Read the binary format, size and blob |
| 60 | GLenum binaryFormat = stream->readInt<GLenum>(); |
| 61 | GLint binaryLength = stream->readInt<GLint>(); |
| 62 | const uint8_t *binary = stream->data() + stream->offset(); |
| 63 | stream->skip(binaryLength); |
| 64 | |
| 65 | // Load the binary |
| 66 | mFunctions->programBinary(mProgramID, binaryFormat, binary, binaryLength); |
| 67 | |
| 68 | // Verify that the program linked |
| 69 | if (!checkLinkStatus(infoLog)) |
| 70 | { |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 71 | return false; |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | postLink(); |
Jamie Madill | 27a6063 | 2017-06-30 15:12:01 -0400 | [diff] [blame] | 75 | reapplyUBOBindingsIfNeeded(context); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 76 | |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 77 | return true; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 78 | } |
| 79 | |
Jamie Madill | 27a6063 | 2017-06-30 15:12:01 -0400 | [diff] [blame] | 80 | void ProgramGL::save(const gl::Context *context, gl::BinaryOutputStream *stream) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 81 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 82 | GLint binaryLength = 0; |
| 83 | mFunctions->getProgramiv(mProgramID, GL_PROGRAM_BINARY_LENGTH, &binaryLength); |
| 84 | |
| 85 | std::vector<uint8_t> binary(binaryLength); |
| 86 | GLenum binaryFormat = GL_NONE; |
| 87 | mFunctions->getProgramBinary(mProgramID, binaryLength, &binaryLength, &binaryFormat, |
| 88 | &binary[0]); |
| 89 | |
| 90 | stream->writeInt(binaryFormat); |
| 91 | stream->writeInt(binaryLength); |
| 92 | stream->writeBytes(&binary[0], binaryLength); |
Jamie Madill | 27a6063 | 2017-06-30 15:12:01 -0400 | [diff] [blame] | 93 | |
| 94 | reapplyUBOBindingsIfNeeded(context); |
| 95 | } |
| 96 | |
| 97 | void ProgramGL::reapplyUBOBindingsIfNeeded(const gl::Context *context) |
| 98 | { |
| 99 | // Re-apply UBO bindings to work around driver bugs. |
| 100 | const WorkaroundsGL &workaroundsGL = GetImplAs<ContextGL>(context)->getWorkaroundsGL(); |
| 101 | if (workaroundsGL.reapplyUBOBindingsAfterUsingBinaryProgram) |
| 102 | { |
| 103 | const auto &blocks = mState.getUniformBlocks(); |
| 104 | for (size_t blockIndex : mState.getActiveUniformBlockBindingsMask()) |
| 105 | { |
| 106 | setUniformBlockBinding(static_cast<GLuint>(blockIndex), blocks[blockIndex].binding); |
| 107 | } |
| 108 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 109 | } |
| 110 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 111 | void ProgramGL::setBinaryRetrievableHint(bool retrievable) |
| 112 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 113 | // glProgramParameteri isn't always available on ES backends. |
| 114 | if (mFunctions->programParameteri) |
| 115 | { |
| 116 | mFunctions->programParameteri(mProgramID, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, |
| 117 | retrievable ? GL_TRUE : GL_FALSE); |
| 118 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 119 | } |
| 120 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 121 | void ProgramGL::setSeparable(bool separable) |
| 122 | { |
| 123 | mFunctions->programParameteri(mProgramID, GL_PROGRAM_SEPARABLE, separable ? GL_TRUE : GL_FALSE); |
| 124 | } |
| 125 | |
Jamie Madill | 9cf9e87 | 2017-06-05 12:59:25 -0400 | [diff] [blame] | 126 | gl::LinkResult ProgramGL::link(const gl::Context *context, |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 127 | const gl::ProgramLinkedResources &resources, |
Jamie Madill | 9cf9e87 | 2017-06-05 12:59:25 -0400 | [diff] [blame] | 128 | gl::InfoLog &infoLog) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 129 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 130 | preLink(); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 131 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 132 | if (mState.getAttachedComputeShader()) |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 133 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 134 | const ShaderGL *computeShaderGL = GetImplAs<ShaderGL>(mState.getAttachedComputeShader()); |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 135 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 136 | mFunctions->attachShader(mProgramID, computeShaderGL->getShaderID()); |
| 137 | |
| 138 | // Link and verify |
| 139 | mFunctions->linkProgram(mProgramID); |
| 140 | |
| 141 | // Detach the shaders |
| 142 | mFunctions->detachShader(mProgramID, computeShaderGL->getShaderID()); |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 143 | } |
| 144 | else |
| 145 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 146 | // Set the transform feedback state |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 147 | std::vector<std::string> transformFeedbackVaryingMappedNames; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 148 | for (const auto &tfVarying : mState.getTransformFeedbackVaryingNames()) |
Geoff Lang | 1528e56 | 2015-08-24 15:10:58 -0400 | [diff] [blame] | 149 | { |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 150 | std::string tfVaryingMappedName = |
| 151 | mState.getAttachedVertexShader()->getTransformFeedbackVaryingMappedName(tfVarying, |
| 152 | context); |
| 153 | transformFeedbackVaryingMappedNames.push_back(tfVaryingMappedName); |
Geoff Lang | 1528e56 | 2015-08-24 15:10:58 -0400 | [diff] [blame] | 154 | } |
| 155 | |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 156 | if (transformFeedbackVaryingMappedNames.empty()) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 157 | { |
| 158 | if (mFunctions->transformFeedbackVaryings) |
| 159 | { |
| 160 | mFunctions->transformFeedbackVaryings(mProgramID, 0, nullptr, |
| 161 | mState.getTransformFeedbackBufferMode()); |
| 162 | } |
| 163 | } |
| 164 | else |
| 165 | { |
| 166 | ASSERT(mFunctions->transformFeedbackVaryings); |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 167 | std::vector<const GLchar *> transformFeedbackVaryings; |
| 168 | for (const auto &varying : transformFeedbackVaryingMappedNames) |
| 169 | { |
| 170 | transformFeedbackVaryings.push_back(varying.c_str()); |
| 171 | } |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 172 | mFunctions->transformFeedbackVaryings( |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 173 | mProgramID, static_cast<GLsizei>(transformFeedbackVaryingMappedNames.size()), |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 174 | &transformFeedbackVaryings[0], mState.getTransformFeedbackBufferMode()); |
| 175 | } |
| 176 | |
| 177 | const ShaderGL *vertexShaderGL = GetImplAs<ShaderGL>(mState.getAttachedVertexShader()); |
| 178 | const ShaderGL *fragmentShaderGL = GetImplAs<ShaderGL>(mState.getAttachedFragmentShader()); |
| 179 | |
| 180 | // Attach the shaders |
| 181 | mFunctions->attachShader(mProgramID, vertexShaderGL->getShaderID()); |
| 182 | mFunctions->attachShader(mProgramID, fragmentShaderGL->getShaderID()); |
| 183 | |
| 184 | // Bind attribute locations to match the GL layer. |
| 185 | for (const sh::Attribute &attribute : mState.getAttributes()) |
| 186 | { |
Corentin Wallez | 6c1cbf5 | 2016-11-23 12:44:35 -0500 | [diff] [blame] | 187 | if (!attribute.staticUse || attribute.isBuiltIn()) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 188 | { |
| 189 | continue; |
| 190 | } |
| 191 | |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 192 | mFunctions->bindAttribLocation(mProgramID, attribute.location, |
| 193 | attribute.mappedName.c_str()); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | // Link and verify |
| 197 | mFunctions->linkProgram(mProgramID); |
| 198 | |
| 199 | // Detach the shaders |
| 200 | mFunctions->detachShader(mProgramID, vertexShaderGL->getShaderID()); |
| 201 | mFunctions->detachShader(mProgramID, fragmentShaderGL->getShaderID()); |
Geoff Lang | 1528e56 | 2015-08-24 15:10:58 -0400 | [diff] [blame] | 202 | } |
| 203 | |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 204 | // Verify the link |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 205 | if (!checkLinkStatus(infoLog)) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 206 | { |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 207 | return false; |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 208 | } |
| 209 | |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 210 | if (mWorkarounds.alwaysCallUseProgramAfterLink) |
| 211 | { |
| 212 | mStateManager->forceUseProgram(mProgramID); |
| 213 | } |
| 214 | |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 215 | postLink(); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 216 | |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 217 | return true; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 218 | } |
| 219 | |
Jamie Madill | 36cfd6a | 2015-08-18 10:46:20 -0400 | [diff] [blame] | 220 | GLboolean ProgramGL::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLog*/) |
| 221 | { |
| 222 | // TODO(jmadill): implement validate |
| 223 | return true; |
| 224 | } |
| 225 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 226 | void ProgramGL::setUniform1fv(GLint location, GLsizei count, const GLfloat *v) |
| 227 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 228 | if (mFunctions->programUniform1fv != nullptr) |
| 229 | { |
| 230 | mFunctions->programUniform1fv(mProgramID, uniLoc(location), count, v); |
| 231 | } |
| 232 | else |
| 233 | { |
| 234 | mStateManager->useProgram(mProgramID); |
| 235 | mFunctions->uniform1fv(uniLoc(location), count, v); |
| 236 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void ProgramGL::setUniform2fv(GLint location, GLsizei count, const GLfloat *v) |
| 240 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 241 | if (mFunctions->programUniform2fv != nullptr) |
| 242 | { |
| 243 | mFunctions->programUniform2fv(mProgramID, uniLoc(location), count, v); |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | mStateManager->useProgram(mProgramID); |
| 248 | mFunctions->uniform2fv(uniLoc(location), count, v); |
| 249 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void ProgramGL::setUniform3fv(GLint location, GLsizei count, const GLfloat *v) |
| 253 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 254 | if (mFunctions->programUniform3fv != nullptr) |
| 255 | { |
| 256 | mFunctions->programUniform3fv(mProgramID, uniLoc(location), count, v); |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | mStateManager->useProgram(mProgramID); |
| 261 | mFunctions->uniform3fv(uniLoc(location), count, v); |
| 262 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | void ProgramGL::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) |
| 266 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 267 | if (mFunctions->programUniform4fv != nullptr) |
| 268 | { |
| 269 | mFunctions->programUniform4fv(mProgramID, uniLoc(location), count, v); |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | mStateManager->useProgram(mProgramID); |
| 274 | mFunctions->uniform4fv(uniLoc(location), count, v); |
| 275 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void ProgramGL::setUniform1iv(GLint location, GLsizei count, const GLint *v) |
| 279 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 280 | if (mFunctions->programUniform1iv != nullptr) |
| 281 | { |
| 282 | mFunctions->programUniform1iv(mProgramID, uniLoc(location), count, v); |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | mStateManager->useProgram(mProgramID); |
| 287 | mFunctions->uniform1iv(uniLoc(location), count, v); |
| 288 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | void ProgramGL::setUniform2iv(GLint location, GLsizei count, const GLint *v) |
| 292 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 293 | if (mFunctions->programUniform2iv != nullptr) |
| 294 | { |
| 295 | mFunctions->programUniform2iv(mProgramID, uniLoc(location), count, v); |
| 296 | } |
| 297 | else |
| 298 | { |
| 299 | mStateManager->useProgram(mProgramID); |
| 300 | mFunctions->uniform2iv(uniLoc(location), count, v); |
| 301 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void ProgramGL::setUniform3iv(GLint location, GLsizei count, const GLint *v) |
| 305 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 306 | if (mFunctions->programUniform3iv != nullptr) |
| 307 | { |
| 308 | mFunctions->programUniform3iv(mProgramID, uniLoc(location), count, v); |
| 309 | } |
| 310 | else |
| 311 | { |
| 312 | mStateManager->useProgram(mProgramID); |
| 313 | mFunctions->uniform3iv(uniLoc(location), count, v); |
| 314 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void ProgramGL::setUniform4iv(GLint location, GLsizei count, const GLint *v) |
| 318 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 319 | if (mFunctions->programUniform4iv != nullptr) |
| 320 | { |
| 321 | mFunctions->programUniform4iv(mProgramID, uniLoc(location), count, v); |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | mStateManager->useProgram(mProgramID); |
| 326 | mFunctions->uniform4iv(uniLoc(location), count, v); |
| 327 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | void ProgramGL::setUniform1uiv(GLint location, GLsizei count, const GLuint *v) |
| 331 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 332 | if (mFunctions->programUniform1uiv != nullptr) |
| 333 | { |
| 334 | mFunctions->programUniform1uiv(mProgramID, uniLoc(location), count, v); |
| 335 | } |
| 336 | else |
| 337 | { |
| 338 | mStateManager->useProgram(mProgramID); |
| 339 | mFunctions->uniform1uiv(uniLoc(location), count, v); |
| 340 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | void ProgramGL::setUniform2uiv(GLint location, GLsizei count, const GLuint *v) |
| 344 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 345 | if (mFunctions->programUniform2uiv != nullptr) |
| 346 | { |
| 347 | mFunctions->programUniform2uiv(mProgramID, uniLoc(location), count, v); |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | mStateManager->useProgram(mProgramID); |
| 352 | mFunctions->uniform2uiv(uniLoc(location), count, v); |
| 353 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | void ProgramGL::setUniform3uiv(GLint location, GLsizei count, const GLuint *v) |
| 357 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 358 | if (mFunctions->programUniform3uiv != nullptr) |
| 359 | { |
| 360 | mFunctions->programUniform3uiv(mProgramID, uniLoc(location), count, v); |
| 361 | } |
| 362 | else |
| 363 | { |
| 364 | mStateManager->useProgram(mProgramID); |
| 365 | mFunctions->uniform3uiv(uniLoc(location), count, v); |
| 366 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void ProgramGL::setUniform4uiv(GLint location, GLsizei count, const GLuint *v) |
| 370 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 371 | if (mFunctions->programUniform4uiv != nullptr) |
| 372 | { |
| 373 | mFunctions->programUniform4uiv(mProgramID, uniLoc(location), count, v); |
| 374 | } |
| 375 | else |
| 376 | { |
| 377 | mStateManager->useProgram(mProgramID); |
| 378 | mFunctions->uniform4uiv(uniLoc(location), count, v); |
| 379 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | void ProgramGL::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 383 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 384 | if (mFunctions->programUniformMatrix2fv != nullptr) |
| 385 | { |
| 386 | mFunctions->programUniformMatrix2fv(mProgramID, uniLoc(location), count, transpose, value); |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | mStateManager->useProgram(mProgramID); |
| 391 | mFunctions->uniformMatrix2fv(uniLoc(location), count, transpose, value); |
| 392 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | void ProgramGL::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 396 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 397 | if (mFunctions->programUniformMatrix3fv != nullptr) |
| 398 | { |
| 399 | mFunctions->programUniformMatrix3fv(mProgramID, uniLoc(location), count, transpose, value); |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | mStateManager->useProgram(mProgramID); |
| 404 | mFunctions->uniformMatrix3fv(uniLoc(location), count, transpose, value); |
| 405 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | void ProgramGL::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 409 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 410 | if (mFunctions->programUniformMatrix4fv != nullptr) |
| 411 | { |
| 412 | mFunctions->programUniformMatrix4fv(mProgramID, uniLoc(location), count, transpose, value); |
| 413 | } |
| 414 | else |
| 415 | { |
| 416 | mStateManager->useProgram(mProgramID); |
| 417 | mFunctions->uniformMatrix4fv(uniLoc(location), count, transpose, value); |
| 418 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void ProgramGL::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 422 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 423 | if (mFunctions->programUniformMatrix2x3fv != nullptr) |
| 424 | { |
| 425 | mFunctions->programUniformMatrix2x3fv(mProgramID, uniLoc(location), count, transpose, |
| 426 | value); |
| 427 | } |
| 428 | else |
| 429 | { |
| 430 | mStateManager->useProgram(mProgramID); |
| 431 | mFunctions->uniformMatrix2x3fv(uniLoc(location), count, transpose, value); |
| 432 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | void ProgramGL::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 436 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 437 | if (mFunctions->programUniformMatrix3x2fv != nullptr) |
| 438 | { |
| 439 | mFunctions->programUniformMatrix3x2fv(mProgramID, uniLoc(location), count, transpose, |
| 440 | value); |
| 441 | } |
| 442 | else |
| 443 | { |
| 444 | mStateManager->useProgram(mProgramID); |
| 445 | mFunctions->uniformMatrix3x2fv(uniLoc(location), count, transpose, value); |
| 446 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | void ProgramGL::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 450 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 451 | if (mFunctions->programUniformMatrix2x4fv != nullptr) |
| 452 | { |
| 453 | mFunctions->programUniformMatrix2x4fv(mProgramID, uniLoc(location), count, transpose, |
| 454 | value); |
| 455 | } |
| 456 | else |
| 457 | { |
| 458 | mStateManager->useProgram(mProgramID); |
| 459 | mFunctions->uniformMatrix2x4fv(uniLoc(location), count, transpose, value); |
| 460 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | void ProgramGL::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 464 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 465 | if (mFunctions->programUniformMatrix4x2fv != nullptr) |
| 466 | { |
| 467 | mFunctions->programUniformMatrix4x2fv(mProgramID, uniLoc(location), count, transpose, |
| 468 | value); |
| 469 | } |
| 470 | else |
| 471 | { |
| 472 | mStateManager->useProgram(mProgramID); |
| 473 | mFunctions->uniformMatrix4x2fv(uniLoc(location), count, transpose, value); |
| 474 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | void ProgramGL::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 478 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 479 | if (mFunctions->programUniformMatrix3x4fv != nullptr) |
| 480 | { |
| 481 | mFunctions->programUniformMatrix3x4fv(mProgramID, uniLoc(location), count, transpose, |
| 482 | value); |
| 483 | } |
| 484 | else |
| 485 | { |
| 486 | mStateManager->useProgram(mProgramID); |
| 487 | mFunctions->uniformMatrix3x4fv(uniLoc(location), count, transpose, value); |
| 488 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | void ProgramGL::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 492 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 493 | if (mFunctions->programUniformMatrix4x3fv != nullptr) |
| 494 | { |
| 495 | mFunctions->programUniformMatrix4x3fv(mProgramID, uniLoc(location), count, transpose, |
| 496 | value); |
| 497 | } |
| 498 | else |
| 499 | { |
| 500 | mStateManager->useProgram(mProgramID); |
| 501 | mFunctions->uniformMatrix4x3fv(uniLoc(location), count, transpose, value); |
| 502 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 503 | } |
| 504 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 505 | void ProgramGL::setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) |
| 506 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 507 | // Lazy init |
| 508 | if (mUniformBlockRealLocationMap.empty()) |
| 509 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 510 | mUniformBlockRealLocationMap.reserve(mState.getUniformBlocks().size()); |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 511 | for (const gl::InterfaceBlock &uniformBlock : mState.getUniformBlocks()) |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 512 | { |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 513 | const std::string &mappedNameWithIndex = uniformBlock.mappedNameWithArrayIndex(); |
| 514 | GLuint blockIndex = |
| 515 | mFunctions->getUniformBlockIndex(mProgramID, mappedNameWithIndex.c_str()); |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 516 | mUniformBlockRealLocationMap.push_back(blockIndex); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | GLuint realBlockIndex = mUniformBlockRealLocationMap[uniformBlockIndex]; |
| 521 | if (realBlockIndex != GL_INVALID_INDEX) |
| 522 | { |
| 523 | mFunctions->uniformBlockBinding(mProgramID, realBlockIndex, uniformBlockBinding); |
| 524 | } |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 525 | } |
| 526 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 527 | GLuint ProgramGL::getProgramID() const |
| 528 | { |
| 529 | return mProgramID; |
| 530 | } |
| 531 | |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 532 | bool ProgramGL::getUniformBlockSize(const std::string & /* blockName */, |
| 533 | const std::string &blockMappedName, |
| 534 | size_t *sizeOut) const |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 535 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 536 | ASSERT(mProgramID != 0u); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 537 | |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 538 | GLuint blockIndex = mFunctions->getUniformBlockIndex(mProgramID, blockMappedName.c_str()); |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 539 | if (blockIndex == GL_INVALID_INDEX) |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 540 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 541 | *sizeOut = 0; |
| 542 | return false; |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 543 | } |
| 544 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 545 | GLint dataSize = 0; |
| 546 | mFunctions->getActiveUniformBlockiv(mProgramID, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, |
| 547 | &dataSize); |
| 548 | *sizeOut = static_cast<size_t>(dataSize); |
| 549 | return true; |
| 550 | } |
| 551 | |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 552 | bool ProgramGL::getUniformBlockMemberInfo(const std::string & /* memberUniformName */, |
| 553 | const std::string &memberUniformMappedName, |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 554 | sh::BlockMemberInfo *memberInfoOut) const |
| 555 | { |
| 556 | GLuint uniformIndex; |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 557 | const GLchar *memberNameGLStr = memberUniformMappedName.c_str(); |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 558 | mFunctions->getUniformIndices(mProgramID, 1, &memberNameGLStr, &uniformIndex); |
| 559 | |
| 560 | if (uniformIndex == GL_INVALID_INDEX) |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 561 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 562 | *memberInfoOut = sh::BlockMemberInfo::getDefaultBlockInfo(); |
| 563 | return false; |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 564 | } |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 565 | |
| 566 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_OFFSET, |
| 567 | &memberInfoOut->offset); |
| 568 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_ARRAY_STRIDE, |
| 569 | &memberInfoOut->arrayStride); |
| 570 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_MATRIX_STRIDE, |
| 571 | &memberInfoOut->matrixStride); |
| 572 | |
| 573 | // TODO(jmadill): possibly determine this at the gl::Program level. |
| 574 | GLint isRowMajorMatrix = 0; |
| 575 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_IS_ROW_MAJOR, |
| 576 | &isRowMajorMatrix); |
| 577 | memberInfoOut->isRowMajorMatrix = isRowMajorMatrix != GL_FALSE; |
| 578 | return true; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 579 | } |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 580 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 581 | void ProgramGL::setPathFragmentInputGen(const std::string &inputName, |
| 582 | GLenum genMode, |
| 583 | GLint components, |
| 584 | const GLfloat *coeffs) |
| 585 | { |
| 586 | ASSERT(mEnablePathRendering); |
| 587 | |
| 588 | for (const auto &input : mPathRenderingFragmentInputs) |
| 589 | { |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 590 | if (input.mappedName == inputName) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 591 | { |
| 592 | mFunctions->programPathFragmentInputGenNV(mProgramID, input.location, genMode, |
| 593 | components, coeffs); |
| 594 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 595 | return; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | } |
| 600 | |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 601 | void ProgramGL::preLink() |
| 602 | { |
| 603 | // Reset the program state |
| 604 | mUniformRealLocationMap.clear(); |
| 605 | mUniformBlockRealLocationMap.clear(); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 606 | mPathRenderingFragmentInputs.clear(); |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 607 | |
| 608 | mMultiviewBaseViewLayerIndexUniformLocation = -1; |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | bool ProgramGL::checkLinkStatus(gl::InfoLog &infoLog) |
| 612 | { |
| 613 | GLint linkStatus = GL_FALSE; |
| 614 | mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus); |
| 615 | if (linkStatus == GL_FALSE) |
| 616 | { |
| 617 | // Linking failed, put the error into the info log |
| 618 | GLint infoLogLength = 0; |
| 619 | mFunctions->getProgramiv(mProgramID, GL_INFO_LOG_LENGTH, &infoLogLength); |
| 620 | |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 621 | // Info log length includes the null terminator, so 1 means that the info log is an empty |
| 622 | // string. |
| 623 | if (infoLogLength > 1) |
| 624 | { |
| 625 | std::vector<char> buf(infoLogLength); |
| 626 | mFunctions->getProgramInfoLog(mProgramID, infoLogLength, nullptr, &buf[0]); |
| 627 | |
| 628 | mFunctions->deleteProgram(mProgramID); |
| 629 | mProgramID = 0; |
| 630 | |
| 631 | infoLog << buf.data(); |
| 632 | |
Yuly Novikov | bcb3f9b | 2017-01-27 22:45:18 -0500 | [diff] [blame] | 633 | WARN() << "Program link failed unexpectedly: " << buf.data(); |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 634 | } |
| 635 | else |
| 636 | { |
Yuly Novikov | bcb3f9b | 2017-01-27 22:45:18 -0500 | [diff] [blame] | 637 | WARN() << "Program link failed unexpectedly with no info log."; |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 638 | } |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 639 | |
| 640 | // TODO, return GL_OUT_OF_MEMORY or just fail the link? This is an unexpected case |
| 641 | return false; |
| 642 | } |
| 643 | |
| 644 | return true; |
| 645 | } |
| 646 | |
| 647 | void ProgramGL::postLink() |
| 648 | { |
| 649 | // Query the uniform information |
| 650 | ASSERT(mUniformRealLocationMap.empty()); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 651 | const auto &uniformLocations = mState.getUniformLocations(); |
| 652 | const auto &uniforms = mState.getUniforms(); |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 653 | mUniformRealLocationMap.resize(uniformLocations.size(), GL_INVALID_INDEX); |
| 654 | for (size_t uniformLocation = 0; uniformLocation < uniformLocations.size(); uniformLocation++) |
| 655 | { |
| 656 | const auto &entry = uniformLocations[uniformLocation]; |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 657 | if (!entry.used()) |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 658 | { |
| 659 | continue; |
| 660 | } |
| 661 | |
Olli Etuaho | c853804 | 2017-09-27 11:20:15 +0300 | [diff] [blame] | 662 | // From the GLES 3.0.5 spec: |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 663 | // "Locations for sequential array indices are not required to be sequential." |
| 664 | const gl::LinkedUniform &uniform = uniforms[entry.index]; |
| 665 | std::stringstream fullNameStr; |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 666 | if (uniform.isArray()) |
| 667 | { |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 668 | ASSERT(angle::EndsWith(uniform.mappedName, "[0]")); |
| 669 | fullNameStr << uniform.mappedName.substr(0, uniform.mappedName.length() - 3); |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame^] | 670 | fullNameStr << "[" << entry.arrayIndex << "]"; |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 671 | } |
| 672 | else |
| 673 | { |
| 674 | fullNameStr << uniform.mappedName; |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 675 | } |
| 676 | const std::string &fullName = fullNameStr.str(); |
| 677 | |
| 678 | GLint realLocation = mFunctions->getUniformLocation(mProgramID, fullName.c_str()); |
| 679 | mUniformRealLocationMap[uniformLocation] = realLocation; |
| 680 | } |
| 681 | |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 682 | if (mState.usesMultiview()) |
| 683 | { |
| 684 | mMultiviewBaseViewLayerIndexUniformLocation = |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 685 | mFunctions->getUniformLocation(mProgramID, "multiviewBaseViewLayerIndex"); |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 686 | ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1); |
| 687 | } |
| 688 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 689 | // Discover CHROMIUM_path_rendering fragment inputs if enabled. |
| 690 | if (!mEnablePathRendering) |
| 691 | return; |
| 692 | |
| 693 | GLint numFragmentInputs = 0; |
| 694 | mFunctions->getProgramInterfaceiv(mProgramID, GL_FRAGMENT_INPUT_NV, GL_ACTIVE_RESOURCES, |
| 695 | &numFragmentInputs); |
| 696 | if (numFragmentInputs <= 0) |
| 697 | return; |
| 698 | |
| 699 | GLint maxNameLength = 0; |
| 700 | mFunctions->getProgramInterfaceiv(mProgramID, GL_FRAGMENT_INPUT_NV, GL_MAX_NAME_LENGTH, |
| 701 | &maxNameLength); |
| 702 | ASSERT(maxNameLength); |
| 703 | |
| 704 | for (GLint i = 0; i < numFragmentInputs; ++i) |
| 705 | { |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 706 | std::string mappedName; |
| 707 | mappedName.resize(maxNameLength); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 708 | |
| 709 | GLsizei nameLen = 0; |
| 710 | mFunctions->getProgramResourceName(mProgramID, GL_FRAGMENT_INPUT_NV, i, maxNameLength, |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 711 | &nameLen, &mappedName[0]); |
| 712 | mappedName.resize(nameLen); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 713 | |
| 714 | // Ignore built-ins |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 715 | if (angle::BeginsWith(mappedName, "gl_")) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 716 | continue; |
| 717 | |
| 718 | const GLenum kQueryProperties[] = {GL_LOCATION, GL_ARRAY_SIZE}; |
| 719 | GLint queryResults[ArraySize(kQueryProperties)]; |
| 720 | GLsizei queryLength = 0; |
| 721 | |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 722 | mFunctions->getProgramResourceiv( |
| 723 | mProgramID, GL_FRAGMENT_INPUT_NV, i, static_cast<GLsizei>(ArraySize(kQueryProperties)), |
| 724 | kQueryProperties, static_cast<GLsizei>(ArraySize(queryResults)), &queryLength, |
| 725 | queryResults); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 726 | |
Olli Etuaho | e319171 | 2016-07-18 16:01:10 +0300 | [diff] [blame] | 727 | ASSERT(queryLength == static_cast<GLsizei>(ArraySize(kQueryProperties))); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 728 | |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 729 | PathRenderingFragmentInput baseElementInput; |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 730 | baseElementInput.mappedName = mappedName; |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 731 | baseElementInput.location = queryResults[0]; |
| 732 | mPathRenderingFragmentInputs.push_back(std::move(baseElementInput)); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 733 | |
| 734 | // If the input is an array it's denoted by [0] suffix on the variable |
| 735 | // name. We'll then create an entry per each array index where index > 0 |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 736 | if (angle::EndsWith(mappedName, "[0]")) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 737 | { |
| 738 | // drop the suffix |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 739 | mappedName.resize(mappedName.size() - 3); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 740 | |
| 741 | const auto arraySize = queryResults[1]; |
| 742 | const auto baseLocation = queryResults[0]; |
| 743 | |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 744 | for (GLint arrayIndex = 1; arrayIndex < arraySize; ++arrayIndex) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 745 | { |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 746 | PathRenderingFragmentInput arrayElementInput; |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 747 | arrayElementInput.mappedName = mappedName + "[" + ToString(arrayIndex) + "]"; |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 748 | arrayElementInput.location = baseLocation + arrayIndex; |
| 749 | mPathRenderingFragmentInputs.push_back(std::move(arrayElementInput)); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | } |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 753 | } |
| 754 | |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 755 | void ProgramGL::enableSideBySideRenderingPath() const |
| 756 | { |
| 757 | ASSERT(mState.usesMultiview()); |
| 758 | ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1); |
| 759 | |
| 760 | ASSERT(mFunctions->programUniform1i != nullptr); |
| 761 | mFunctions->programUniform1i(mProgramID, mMultiviewBaseViewLayerIndexUniformLocation, -1); |
| 762 | } |
| 763 | |
| 764 | void ProgramGL::enableLayeredRenderingPath(int baseViewIndex) const |
| 765 | { |
| 766 | ASSERT(mState.usesMultiview()); |
| 767 | ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1); |
| 768 | |
| 769 | ASSERT(mFunctions->programUniform1i != nullptr); |
| 770 | mFunctions->programUniform1i(mProgramID, mMultiviewBaseViewLayerIndexUniformLocation, |
| 771 | baseViewIndex); |
| 772 | } |
| 773 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 774 | void ProgramGL::getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const |
| 775 | { |
| 776 | mFunctions->getUniformfv(mProgramID, uniLoc(location), params); |
| 777 | } |
| 778 | |
| 779 | void ProgramGL::getUniformiv(const gl::Context *context, GLint location, GLint *params) const |
| 780 | { |
| 781 | mFunctions->getUniformiv(mProgramID, uniLoc(location), params); |
| 782 | } |
| 783 | |
| 784 | void ProgramGL::getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const |
| 785 | { |
| 786 | mFunctions->getUniformuiv(mProgramID, uniLoc(location), params); |
| 787 | } |
| 788 | |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 789 | void ProgramGL::markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations, |
| 790 | std::vector<gl::SamplerBinding> *samplerBindings) |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 791 | { |
| 792 | GLint maxLocation = static_cast<GLint>(uniformLocations->size()); |
| 793 | for (GLint location = 0; location < maxLocation; ++location) |
| 794 | { |
| 795 | if (uniLoc(location) == -1) |
| 796 | { |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 797 | auto &locationRef = (*uniformLocations)[location]; |
| 798 | if (mState.isSamplerUniformIndex(locationRef.index)) |
| 799 | { |
| 800 | GLuint samplerIndex = mState.getSamplerIndexFromUniformIndex(locationRef.index); |
| 801 | (*samplerBindings)[samplerIndex].unreferenced = true; |
| 802 | } |
| 803 | locationRef.markUnused(); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 808 | } // namespace rx |