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