daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // Program.h: Defines the gl::Program class. Implements GL program objects |
| 8 | // and related functionality. [OpenGL ES 2.0.24] section 2.10.3 page 28. |
| 9 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 10 | #ifndef LIBANGLE_PROGRAM_H_ |
| 11 | #define LIBANGLE_PROGRAM_H_ |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 12 | |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 13 | #include <GLES2/gl2.h> |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 14 | #include <GLSLANG/ShaderLang.h> |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 15 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 16 | #include <set> |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 17 | #include <sstream> |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 18 | #include <string> |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 19 | #include <vector> |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 20 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 21 | #include "common/angleutils.h" |
| 22 | #include "common/mathutil.h" |
| 23 | #include "common/Optional.h" |
| 24 | |
| 25 | #include "libANGLE/angletypes.h" |
| 26 | #include "libANGLE/Constants.h" |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 27 | #include "libANGLE/Debug.h" |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 28 | #include "libANGLE/Error.h" |
| 29 | #include "libANGLE/RefCountObject.h" |
| 30 | |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 31 | namespace rx |
| 32 | { |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 33 | class ImplFactory; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 34 | class ProgramImpl; |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 35 | struct TranslatedAttribute; |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 36 | } |
daniel@transgaming.com | e684229 | 2010-04-20 18:52:50 +0000 | [diff] [blame] | 37 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 38 | namespace gl |
| 39 | { |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 40 | struct Caps; |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 41 | struct ContextState; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 42 | class ResourceManager; |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 43 | class Shader; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 44 | class InfoLog; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 45 | class Buffer; |
| 46 | class Framebuffer; |
| 47 | struct UniformBlock; |
| 48 | struct LinkedUniform; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 49 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 50 | extern const char * const g_fakepath; |
| 51 | |
Jamie Madill | f0d10f8 | 2015-03-31 12:56:52 -0400 | [diff] [blame] | 52 | class InfoLog : angle::NonCopyable |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 53 | { |
| 54 | public: |
| 55 | InfoLog(); |
| 56 | ~InfoLog(); |
| 57 | |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 58 | size_t getLength() const; |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 59 | void getLog(GLsizei bufSize, GLsizei *length, char *infoLog) const; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 60 | |
| 61 | void appendSanitized(const char *message); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 62 | void reset(); |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 63 | |
| 64 | // This helper class ensures we append a newline after writing a line. |
| 65 | class StreamHelper : angle::NonCopyable |
| 66 | { |
| 67 | public: |
| 68 | StreamHelper(StreamHelper &&rhs) |
| 69 | : mStream(rhs.mStream) |
| 70 | { |
| 71 | rhs.mStream = nullptr; |
| 72 | } |
| 73 | |
| 74 | StreamHelper &operator=(StreamHelper &&rhs) |
| 75 | { |
| 76 | std::swap(mStream, rhs.mStream); |
| 77 | return *this; |
| 78 | } |
| 79 | |
| 80 | ~StreamHelper() |
| 81 | { |
| 82 | // Write newline when destroyed on the stack |
| 83 | if (mStream) |
| 84 | { |
| 85 | (*mStream) << std::endl; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | template <typename T> |
| 90 | StreamHelper &operator<<(const T &value) |
| 91 | { |
| 92 | (*mStream) << value; |
| 93 | return *this; |
| 94 | } |
| 95 | |
| 96 | private: |
| 97 | friend class InfoLog; |
| 98 | |
| 99 | StreamHelper(std::stringstream *stream) |
| 100 | : mStream(stream) |
| 101 | { |
| 102 | ASSERT(stream); |
| 103 | } |
| 104 | |
| 105 | std::stringstream *mStream; |
| 106 | }; |
| 107 | |
| 108 | template <typename T> |
| 109 | StreamHelper operator<<(const T &value) |
| 110 | { |
| 111 | StreamHelper helper(&mStream); |
| 112 | helper << value; |
| 113 | return helper; |
| 114 | } |
| 115 | |
| 116 | std::string str() const { return mStream.str(); } |
| 117 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 118 | private: |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 119 | std::stringstream mStream; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 122 | // Struct used for correlating uniforms/elements of uniform arrays to handles |
| 123 | struct VariableLocation |
| 124 | { |
| 125 | VariableLocation(); |
| 126 | VariableLocation(const std::string &name, unsigned int element, unsigned int index); |
| 127 | |
| 128 | std::string name; |
| 129 | unsigned int element; |
| 130 | unsigned int index; |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 131 | |
| 132 | // If this is a valid uniform location |
| 133 | bool used; |
| 134 | |
| 135 | // If this location was bound to an unreferenced uniform. Setting data on this uniform is a |
| 136 | // no-op. |
| 137 | bool ignored; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 138 | }; |
| 139 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame^] | 140 | class ProgramState final : angle::NonCopyable |
| 141 | { |
| 142 | public: |
| 143 | ProgramState(); |
| 144 | ~ProgramState(); |
| 145 | |
| 146 | const std::string &getLabel(); |
| 147 | |
| 148 | const Shader *getAttachedVertexShader() const { return mAttachedVertexShader; } |
| 149 | const Shader *getAttachedFragmentShader() const { return mAttachedFragmentShader; } |
| 150 | const std::vector<std::string> &getTransformFeedbackVaryingNames() const |
| 151 | { |
| 152 | return mTransformFeedbackVaryingNames; |
| 153 | } |
| 154 | GLint getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; } |
| 155 | GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const |
| 156 | { |
| 157 | ASSERT(uniformBlockIndex < IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS); |
| 158 | return mUniformBlockBindings[uniformBlockIndex]; |
| 159 | } |
| 160 | const UniformBlockBindingMask &getActiveUniformBlockBindingsMask() const |
| 161 | { |
| 162 | return mActiveUniformBlockBindings; |
| 163 | } |
| 164 | const std::vector<sh::Attribute> &getAttributes() const { return mAttributes; } |
| 165 | const AttributesMask &getActiveAttribLocationsMask() const |
| 166 | { |
| 167 | return mActiveAttribLocationsMask; |
| 168 | } |
| 169 | const std::map<int, VariableLocation> &getOutputVariables() const { return mOutputVariables; } |
| 170 | const std::vector<LinkedUniform> &getUniforms() const { return mUniforms; } |
| 171 | const std::vector<VariableLocation> &getUniformLocations() const { return mUniformLocations; } |
| 172 | const std::vector<UniformBlock> &getUniformBlocks() const { return mUniformBlocks; } |
| 173 | |
| 174 | const LinkedUniform *getUniformByName(const std::string &name) const; |
| 175 | GLint getUniformLocation(const std::string &name) const; |
| 176 | GLuint getUniformIndex(const std::string &name) const; |
| 177 | |
| 178 | private: |
| 179 | friend class Program; |
| 180 | |
| 181 | std::string mLabel; |
| 182 | |
| 183 | Shader *mAttachedFragmentShader; |
| 184 | Shader *mAttachedVertexShader; |
| 185 | |
| 186 | std::vector<std::string> mTransformFeedbackVaryingNames; |
| 187 | std::vector<sh::Varying> mTransformFeedbackVaryingVars; |
| 188 | GLenum mTransformFeedbackBufferMode; |
| 189 | |
| 190 | GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS]; |
| 191 | UniformBlockBindingMask mActiveUniformBlockBindings; |
| 192 | |
| 193 | std::vector<sh::Attribute> mAttributes; |
| 194 | std::bitset<MAX_VERTEX_ATTRIBS> mActiveAttribLocationsMask; |
| 195 | |
| 196 | // Uniforms are sorted in order: |
| 197 | // 1. Non-sampler uniforms |
| 198 | // 2. Sampler uniforms |
| 199 | // 3. Uniform block uniforms |
| 200 | // This makes sampler validation easier, since we don't need a separate list. |
| 201 | std::vector<LinkedUniform> mUniforms; |
| 202 | std::vector<VariableLocation> mUniformLocations; |
| 203 | std::vector<UniformBlock> mUniformBlocks; |
| 204 | |
| 205 | // TODO(jmadill): use unordered/hash map when available |
| 206 | std::map<int, VariableLocation> mOutputVariables; |
| 207 | |
| 208 | bool mBinaryRetrieveableHint; |
| 209 | }; |
| 210 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 211 | class Program final : angle::NonCopyable, public LabeledObject |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 212 | { |
| 213 | public: |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 214 | Program(rx::ImplFactory *factory, ResourceManager *manager, GLuint handle); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 215 | ~Program(); |
| 216 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 217 | GLuint id() const { return mHandle; } |
| 218 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 219 | void setLabel(const std::string &label) override; |
| 220 | const std::string &getLabel() const override; |
| 221 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 222 | rx::ProgramImpl *getImplementation() { return mProgram; } |
| 223 | const rx::ProgramImpl *getImplementation() const { return mProgram; } |
| 224 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 225 | bool attachShader(Shader *shader); |
| 226 | bool detachShader(Shader *shader); |
| 227 | int getAttachedShadersCount() const; |
| 228 | |
| 229 | void bindAttributeLocation(GLuint index, const char *name); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 230 | void bindUniformLocation(GLuint index, const char *name); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 231 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 232 | Error link(const ContextState &data); |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 233 | bool isLinked() const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 234 | |
| 235 | Error loadBinary(GLenum binaryFormat, const void *binary, GLsizei length); |
| 236 | Error saveBinary(GLenum *binaryFormat, void *binary, GLsizei bufSize, GLsizei *length) const; |
| 237 | GLint getBinaryLength() const; |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 238 | void setBinaryRetrievableHint(bool retrievable); |
| 239 | bool getBinaryRetrievableHint() const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 240 | |
| 241 | int getInfoLogLength() const; |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 242 | void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const; |
| 243 | void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders) const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 244 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 245 | GLuint getAttributeLocation(const std::string &name) const; |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 246 | bool isAttribLocationActive(size_t attribLocation) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 247 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 248 | void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 249 | GLint getActiveAttributeCount() const; |
| 250 | GLint getActiveAttributeMaxLength() const; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame^] | 251 | const std::vector<sh::Attribute> &getAttributes() const { return mState.mAttributes; } |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 252 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 253 | GLint getFragDataLocation(const std::string &name) const; |
| 254 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 255 | void getActiveUniform(GLuint index, |
| 256 | GLsizei bufsize, |
| 257 | GLsizei *length, |
| 258 | GLint *size, |
| 259 | GLenum *type, |
| 260 | GLchar *name) const; |
| 261 | GLint getActiveUniformCount() const; |
| 262 | GLint getActiveUniformMaxLength() const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 263 | GLint getActiveUniformi(GLuint index, GLenum pname) const; |
| 264 | bool isValidUniformLocation(GLint location) const; |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 265 | bool isIgnoredUniformLocation(GLint location) const; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 266 | const LinkedUniform &getUniformByLocation(GLint location) const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 267 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 268 | GLint getUniformLocation(const std::string &name) const; |
| 269 | GLuint getUniformIndex(const std::string &name) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 270 | void setUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 271 | void setUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 272 | void setUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 273 | void setUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
| 274 | void setUniform1iv(GLint location, GLsizei count, const GLint *v); |
| 275 | void setUniform2iv(GLint location, GLsizei count, const GLint *v); |
| 276 | void setUniform3iv(GLint location, GLsizei count, const GLint *v); |
| 277 | void setUniform4iv(GLint location, GLsizei count, const GLint *v); |
| 278 | void setUniform1uiv(GLint location, GLsizei count, const GLuint *v); |
| 279 | void setUniform2uiv(GLint location, GLsizei count, const GLuint *v); |
| 280 | void setUniform3uiv(GLint location, GLsizei count, const GLuint *v); |
| 281 | void setUniform4uiv(GLint location, GLsizei count, const GLuint *v); |
| 282 | void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 283 | void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 284 | void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 285 | void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 286 | void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 287 | void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 288 | void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 289 | void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 290 | void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 291 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 292 | void getUniformfv(GLint location, GLfloat *params) const; |
| 293 | void getUniformiv(GLint location, GLint *params) const; |
| 294 | void getUniformuiv(GLint location, GLuint *params) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 295 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 296 | void getActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName) const; |
| 297 | void getActiveUniformBlockiv(GLuint uniformBlockIndex, GLenum pname, GLint *params) const; |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 298 | GLuint getActiveUniformBlockCount() const; |
| 299 | GLint getActiveUniformBlockMaxLength() const; |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 300 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 301 | GLuint getUniformBlockIndex(const std::string &name) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 302 | |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 303 | void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding); |
| 304 | GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const; |
| 305 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 306 | const UniformBlock &getUniformBlockByIndex(GLuint index) const; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 307 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 308 | void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode); |
| 309 | void getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const; |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 310 | GLsizei getTransformFeedbackVaryingCount() const; |
| 311 | GLsizei getTransformFeedbackVaryingMaxLength() const; |
| 312 | GLenum getTransformFeedbackBufferMode() const; |
| 313 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 314 | static bool linkValidateUniforms(InfoLog &infoLog, const std::string &uniformName, const sh::Uniform &vertexUniform, const sh::Uniform &fragmentUniform); |
| 315 | static bool linkValidateInterfaceBlockFields(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform); |
| 316 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 317 | void addRef(); |
| 318 | void release(); |
| 319 | unsigned int getRefCount() const; |
| 320 | void flagForDeletion(); |
| 321 | bool isFlaggedForDeletion() const; |
| 322 | |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 323 | void validate(const Caps &caps); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 324 | bool validateSamplers(InfoLog *infoLog, const Caps &caps); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 325 | bool isValidated() const; |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 326 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 327 | const AttributesMask &getActiveAttribLocationsMask() const |
| 328 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame^] | 329 | return mState.mActiveAttribLocationsMask; |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 330 | } |
| 331 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 332 | private: |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 333 | class Bindings final : angle::NonCopyable |
| 334 | { |
| 335 | public: |
| 336 | void bindLocation(GLuint index, const std::string &name); |
| 337 | int getBinding(const std::string &name) const; |
| 338 | |
| 339 | typedef std::unordered_map<std::string, GLuint>::const_iterator const_iterator; |
| 340 | const_iterator begin() const; |
| 341 | const_iterator end() const; |
| 342 | |
| 343 | private: |
| 344 | std::unordered_map<std::string, GLuint> mBindings; |
| 345 | }; |
| 346 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 347 | void unlink(bool destroy = false); |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 348 | void resetUniformBlockBindings(); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 349 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 350 | bool linkAttributes(const ContextState &data, |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 351 | InfoLog &infoLog, |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 352 | const Bindings &attributeBindings, |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 353 | const Shader *vertexShader); |
Jamie Madill | e473dee | 2015-08-18 14:49:01 -0400 | [diff] [blame] | 354 | bool linkUniformBlocks(InfoLog &infoLog, const Caps &caps); |
Jamie Madill | ada9ecc | 2015-08-17 12:53:37 -0400 | [diff] [blame] | 355 | static bool linkVaryings(InfoLog &infoLog, |
| 356 | const Shader *vertexShader, |
| 357 | const Shader *fragmentShader); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 358 | bool linkUniforms(gl::InfoLog &infoLog, const gl::Caps &caps, const Bindings &uniformBindings); |
| 359 | bool indexUniforms(gl::InfoLog &infoLog, const gl::Caps &caps, const Bindings &uniformBindings); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 360 | bool areMatchingInterfaceBlocks(gl::InfoLog &infoLog, const sh::InterfaceBlock &vertexInterfaceBlock, |
| 361 | const sh::InterfaceBlock &fragmentInterfaceBlock); |
| 362 | |
| 363 | static bool linkValidateVariablesBase(InfoLog &infoLog, |
| 364 | const std::string &variableName, |
| 365 | const sh::ShaderVariable &vertexVariable, |
| 366 | const sh::ShaderVariable &fragmentVariable, |
| 367 | bool validatePrecision); |
| 368 | |
| 369 | static bool linkValidateVaryings(InfoLog &infoLog, const std::string &varyingName, const sh::Varying &vertexVarying, const sh::Varying &fragmentVarying); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 370 | bool linkValidateTransformFeedback(InfoLog &infoLog, |
| 371 | const std::vector<const sh::Varying *> &linkedVaryings, |
| 372 | const Caps &caps) const; |
| 373 | |
| 374 | void gatherTransformFeedbackVaryings(const std::vector<const sh::Varying *> &varyings); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 375 | bool assignUniformBlockRegister(InfoLog &infoLog, UniformBlock *uniformBlock, GLenum shader, unsigned int registerIndex, const Caps &caps); |
| 376 | void defineOutputVariables(Shader *fragmentShader); |
| 377 | |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 378 | std::vector<const sh::Varying *> getMergedVaryings() const; |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 379 | void linkOutputVariables(); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 380 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 381 | bool flattenUniformsAndCheckCaps(const Caps &caps, InfoLog &infoLog); |
| 382 | |
| 383 | struct VectorAndSamplerCount |
| 384 | { |
| 385 | VectorAndSamplerCount() : vectorCount(0), samplerCount(0) {} |
| 386 | VectorAndSamplerCount(const VectorAndSamplerCount &other) = default; |
| 387 | VectorAndSamplerCount &operator=(const VectorAndSamplerCount &other) = default; |
| 388 | |
| 389 | VectorAndSamplerCount &operator+=(const VectorAndSamplerCount &other) |
| 390 | { |
| 391 | vectorCount += other.vectorCount; |
| 392 | samplerCount += other.samplerCount; |
| 393 | return *this; |
| 394 | } |
| 395 | |
| 396 | unsigned int vectorCount; |
| 397 | unsigned int samplerCount; |
| 398 | }; |
| 399 | |
| 400 | VectorAndSamplerCount flattenUniform(const sh::ShaderVariable &uniform, |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 401 | const std::string &fullName, |
| 402 | std::vector<LinkedUniform> *samplerUniforms); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 403 | |
| 404 | void gatherInterfaceBlockInfo(); |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 405 | template <typename VarT> |
| 406 | void defineUniformBlockMembers(const std::vector<VarT> &fields, |
| 407 | const std::string &prefix, |
| 408 | int blockIndex); |
| 409 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 410 | void defineUniformBlock(const sh::InterfaceBlock &interfaceBlock, GLenum shaderType); |
| 411 | |
| 412 | template <typename T> |
| 413 | void setUniformInternal(GLint location, GLsizei count, const T *v); |
| 414 | |
| 415 | template <size_t cols, size_t rows, typename T> |
| 416 | void setMatrixUniformInternal(GLint location, GLsizei count, GLboolean transpose, const T *v); |
| 417 | |
| 418 | template <typename DestT> |
| 419 | void getUniformInternal(GLint location, DestT *dataOut) const; |
| 420 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame^] | 421 | ProgramState mState; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 422 | rx::ProgramImpl *mProgram; |
| 423 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 424 | bool mValidated; |
| 425 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 426 | Bindings mAttributeBindings; |
| 427 | Bindings mUniformBindings; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 428 | |
daniel@transgaming.com | 716056c | 2012-07-24 18:38:59 +0000 | [diff] [blame] | 429 | bool mLinked; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 430 | bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use |
daniel@transgaming.com | 4fa0833 | 2010-05-11 02:29:27 +0000 | [diff] [blame] | 431 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 432 | unsigned int mRefCount; |
| 433 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 434 | ResourceManager *mResourceManager; |
| 435 | const GLuint mHandle; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 436 | |
| 437 | InfoLog mInfoLog; |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 438 | |
| 439 | // Cache for sampler validation |
| 440 | Optional<bool> mCachedValidateSamplersResult; |
| 441 | std::vector<GLenum> mTextureUnitTypesCache; |
| 442 | RangeUI mSamplerUniformRange; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 443 | }; |
| 444 | } |
| 445 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 446 | #endif // LIBANGLE_PROGRAM_H_ |