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 | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 33 | class GLImplFactory; |
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 | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 41 | class 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 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame^] | 140 | // Information about a variable binding. |
| 141 | // Currently used by CHROMIUM_path_rendering |
| 142 | struct BindingInfo |
| 143 | { |
| 144 | // The type of binding, for example GL_FLOAT_VEC3. |
| 145 | // This can be GL_NONE if the variable is optimized away. |
| 146 | GLenum type; |
| 147 | |
| 148 | // This is the name of the variable in |
| 149 | // the translated shader program. Note that |
| 150 | // this can be empty in the case where the |
| 151 | // variable has been optimized away. |
| 152 | std::string name; |
| 153 | |
| 154 | // True if the binding is valid, otherwise false. |
| 155 | bool valid; |
| 156 | }; |
| 157 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 158 | class ProgramState final : angle::NonCopyable |
| 159 | { |
| 160 | public: |
| 161 | ProgramState(); |
| 162 | ~ProgramState(); |
| 163 | |
| 164 | const std::string &getLabel(); |
| 165 | |
| 166 | const Shader *getAttachedVertexShader() const { return mAttachedVertexShader; } |
| 167 | const Shader *getAttachedFragmentShader() const { return mAttachedFragmentShader; } |
| 168 | const std::vector<std::string> &getTransformFeedbackVaryingNames() const |
| 169 | { |
| 170 | return mTransformFeedbackVaryingNames; |
| 171 | } |
| 172 | GLint getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; } |
| 173 | GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const |
| 174 | { |
| 175 | ASSERT(uniformBlockIndex < IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS); |
| 176 | return mUniformBlockBindings[uniformBlockIndex]; |
| 177 | } |
| 178 | const UniformBlockBindingMask &getActiveUniformBlockBindingsMask() const |
| 179 | { |
| 180 | return mActiveUniformBlockBindings; |
| 181 | } |
| 182 | const std::vector<sh::Attribute> &getAttributes() const { return mAttributes; } |
| 183 | const AttributesMask &getActiveAttribLocationsMask() const |
| 184 | { |
| 185 | return mActiveAttribLocationsMask; |
| 186 | } |
| 187 | const std::map<int, VariableLocation> &getOutputVariables() const { return mOutputVariables; } |
| 188 | const std::vector<LinkedUniform> &getUniforms() const { return mUniforms; } |
| 189 | const std::vector<VariableLocation> &getUniformLocations() const { return mUniformLocations; } |
| 190 | const std::vector<UniformBlock> &getUniformBlocks() const { return mUniformBlocks; } |
| 191 | |
| 192 | const LinkedUniform *getUniformByName(const std::string &name) const; |
| 193 | GLint getUniformLocation(const std::string &name) const; |
| 194 | GLuint getUniformIndex(const std::string &name) const; |
| 195 | |
| 196 | private: |
| 197 | friend class Program; |
| 198 | |
| 199 | std::string mLabel; |
| 200 | |
| 201 | Shader *mAttachedFragmentShader; |
| 202 | Shader *mAttachedVertexShader; |
| 203 | |
| 204 | std::vector<std::string> mTransformFeedbackVaryingNames; |
| 205 | std::vector<sh::Varying> mTransformFeedbackVaryingVars; |
| 206 | GLenum mTransformFeedbackBufferMode; |
| 207 | |
| 208 | GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS]; |
| 209 | UniformBlockBindingMask mActiveUniformBlockBindings; |
| 210 | |
| 211 | std::vector<sh::Attribute> mAttributes; |
| 212 | std::bitset<MAX_VERTEX_ATTRIBS> mActiveAttribLocationsMask; |
| 213 | |
| 214 | // Uniforms are sorted in order: |
| 215 | // 1. Non-sampler uniforms |
| 216 | // 2. Sampler uniforms |
| 217 | // 3. Uniform block uniforms |
| 218 | // This makes sampler validation easier, since we don't need a separate list. |
| 219 | std::vector<LinkedUniform> mUniforms; |
| 220 | std::vector<VariableLocation> mUniformLocations; |
| 221 | std::vector<UniformBlock> mUniformBlocks; |
| 222 | |
| 223 | // TODO(jmadill): use unordered/hash map when available |
| 224 | std::map<int, VariableLocation> mOutputVariables; |
| 225 | |
| 226 | bool mBinaryRetrieveableHint; |
| 227 | }; |
| 228 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 229 | class Program final : angle::NonCopyable, public LabeledObject |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 230 | { |
| 231 | public: |
Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 232 | Program(rx::GLImplFactory *factory, ResourceManager *manager, GLuint handle); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 233 | ~Program(); |
| 234 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 235 | GLuint id() const { return mHandle; } |
| 236 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 237 | void setLabel(const std::string &label) override; |
| 238 | const std::string &getLabel() const override; |
| 239 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 240 | rx::ProgramImpl *getImplementation() { return mProgram; } |
| 241 | const rx::ProgramImpl *getImplementation() const { return mProgram; } |
| 242 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 243 | bool attachShader(Shader *shader); |
| 244 | bool detachShader(Shader *shader); |
| 245 | int getAttachedShadersCount() const; |
| 246 | |
| 247 | void bindAttributeLocation(GLuint index, const char *name); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 248 | void bindUniformLocation(GLuint index, const char *name); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 249 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame^] | 250 | // CHROMIUM_path_rendering |
| 251 | BindingInfo getFragmentInputBindingInfo(GLint index) const; |
| 252 | void bindFragmentInputLocation(GLint index, const char *name); |
| 253 | void pathFragmentInputGen(GLint index, |
| 254 | GLenum genMode, |
| 255 | GLint components, |
| 256 | const GLfloat *coeffs); |
| 257 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 258 | Error link(const ContextState &data); |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 259 | bool isLinked() const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 260 | |
| 261 | Error loadBinary(GLenum binaryFormat, const void *binary, GLsizei length); |
| 262 | Error saveBinary(GLenum *binaryFormat, void *binary, GLsizei bufSize, GLsizei *length) const; |
| 263 | GLint getBinaryLength() const; |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 264 | void setBinaryRetrievableHint(bool retrievable); |
| 265 | bool getBinaryRetrievableHint() const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 266 | |
| 267 | int getInfoLogLength() const; |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 268 | void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const; |
| 269 | void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders) const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 270 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 271 | GLuint getAttributeLocation(const std::string &name) const; |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 272 | bool isAttribLocationActive(size_t attribLocation) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 273 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 274 | 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] | 275 | GLint getActiveAttributeCount() const; |
| 276 | GLint getActiveAttributeMaxLength() const; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 277 | const std::vector<sh::Attribute> &getAttributes() const { return mState.mAttributes; } |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 278 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 279 | GLint getFragDataLocation(const std::string &name) const; |
| 280 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 281 | void getActiveUniform(GLuint index, |
| 282 | GLsizei bufsize, |
| 283 | GLsizei *length, |
| 284 | GLint *size, |
| 285 | GLenum *type, |
| 286 | GLchar *name) const; |
| 287 | GLint getActiveUniformCount() const; |
| 288 | GLint getActiveUniformMaxLength() const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 289 | GLint getActiveUniformi(GLuint index, GLenum pname) const; |
| 290 | bool isValidUniformLocation(GLint location) const; |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 291 | bool isIgnoredUniformLocation(GLint location) const; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 292 | const LinkedUniform &getUniformByLocation(GLint location) const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 293 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 294 | GLint getUniformLocation(const std::string &name) const; |
| 295 | GLuint getUniformIndex(const std::string &name) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 296 | void setUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 297 | void setUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 298 | void setUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 299 | void setUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
| 300 | void setUniform1iv(GLint location, GLsizei count, const GLint *v); |
| 301 | void setUniform2iv(GLint location, GLsizei count, const GLint *v); |
| 302 | void setUniform3iv(GLint location, GLsizei count, const GLint *v); |
| 303 | void setUniform4iv(GLint location, GLsizei count, const GLint *v); |
| 304 | void setUniform1uiv(GLint location, GLsizei count, const GLuint *v); |
| 305 | void setUniform2uiv(GLint location, GLsizei count, const GLuint *v); |
| 306 | void setUniform3uiv(GLint location, GLsizei count, const GLuint *v); |
| 307 | void setUniform4uiv(GLint location, GLsizei count, const GLuint *v); |
| 308 | void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 309 | void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 310 | void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 311 | void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 312 | void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 313 | void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 314 | void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 315 | void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 316 | void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 317 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 318 | void getUniformfv(GLint location, GLfloat *params) const; |
| 319 | void getUniformiv(GLint location, GLint *params) const; |
| 320 | void getUniformuiv(GLint location, GLuint *params) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 321 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 322 | void getActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName) const; |
| 323 | void getActiveUniformBlockiv(GLuint uniformBlockIndex, GLenum pname, GLint *params) const; |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 324 | GLuint getActiveUniformBlockCount() const; |
| 325 | GLint getActiveUniformBlockMaxLength() const; |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 326 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 327 | GLuint getUniformBlockIndex(const std::string &name) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 328 | |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 329 | void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding); |
| 330 | GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const; |
| 331 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 332 | const UniformBlock &getUniformBlockByIndex(GLuint index) const; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 333 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 334 | void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode); |
| 335 | 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] | 336 | GLsizei getTransformFeedbackVaryingCount() const; |
| 337 | GLsizei getTransformFeedbackVaryingMaxLength() const; |
| 338 | GLenum getTransformFeedbackBufferMode() const; |
| 339 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 340 | static bool linkValidateUniforms(InfoLog &infoLog, const std::string &uniformName, const sh::Uniform &vertexUniform, const sh::Uniform &fragmentUniform); |
| 341 | static bool linkValidateInterfaceBlockFields(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform); |
| 342 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 343 | void addRef(); |
| 344 | void release(); |
| 345 | unsigned int getRefCount() const; |
| 346 | void flagForDeletion(); |
| 347 | bool isFlaggedForDeletion() const; |
| 348 | |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 349 | void validate(const Caps &caps); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 350 | bool validateSamplers(InfoLog *infoLog, const Caps &caps); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 351 | bool isValidated() const; |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 352 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 353 | const AttributesMask &getActiveAttribLocationsMask() const |
| 354 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 355 | return mState.mActiveAttribLocationsMask; |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 356 | } |
| 357 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 358 | private: |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 359 | class Bindings final : angle::NonCopyable |
| 360 | { |
| 361 | public: |
| 362 | void bindLocation(GLuint index, const std::string &name); |
| 363 | int getBinding(const std::string &name) const; |
| 364 | |
| 365 | typedef std::unordered_map<std::string, GLuint>::const_iterator const_iterator; |
| 366 | const_iterator begin() const; |
| 367 | const_iterator end() const; |
| 368 | |
| 369 | private: |
| 370 | std::unordered_map<std::string, GLuint> mBindings; |
| 371 | }; |
| 372 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 373 | void unlink(bool destroy = false); |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 374 | void resetUniformBlockBindings(); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 375 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 376 | bool linkAttributes(const ContextState &data, |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 377 | InfoLog &infoLog, |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 378 | const Bindings &attributeBindings, |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 379 | const Shader *vertexShader); |
Jamie Madill | e473dee | 2015-08-18 14:49:01 -0400 | [diff] [blame] | 380 | bool linkUniformBlocks(InfoLog &infoLog, const Caps &caps); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame^] | 381 | bool linkVaryings(InfoLog &infoLog, const Shader *vertexShader, const Shader *fragmentShader) const; |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 382 | bool linkUniforms(gl::InfoLog &infoLog, const gl::Caps &caps, const Bindings &uniformBindings); |
| 383 | bool indexUniforms(gl::InfoLog &infoLog, const gl::Caps &caps, const Bindings &uniformBindings); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 384 | bool areMatchingInterfaceBlocks(gl::InfoLog &infoLog, const sh::InterfaceBlock &vertexInterfaceBlock, |
| 385 | const sh::InterfaceBlock &fragmentInterfaceBlock); |
| 386 | |
| 387 | static bool linkValidateVariablesBase(InfoLog &infoLog, |
| 388 | const std::string &variableName, |
| 389 | const sh::ShaderVariable &vertexVariable, |
| 390 | const sh::ShaderVariable &fragmentVariable, |
| 391 | bool validatePrecision); |
| 392 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 393 | static bool linkValidateVaryings(InfoLog &infoLog, |
| 394 | const std::string &varyingName, |
| 395 | const sh::Varying &vertexVarying, |
| 396 | const sh::Varying &fragmentVarying, |
| 397 | int shaderVersion); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 398 | bool linkValidateTransformFeedback(InfoLog &infoLog, |
| 399 | const std::vector<const sh::Varying *> &linkedVaryings, |
| 400 | const Caps &caps) const; |
| 401 | |
| 402 | void gatherTransformFeedbackVaryings(const std::vector<const sh::Varying *> &varyings); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 403 | bool assignUniformBlockRegister(InfoLog &infoLog, UniformBlock *uniformBlock, GLenum shader, unsigned int registerIndex, const Caps &caps); |
| 404 | void defineOutputVariables(Shader *fragmentShader); |
| 405 | |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 406 | std::vector<const sh::Varying *> getMergedVaryings() const; |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 407 | void linkOutputVariables(); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 408 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 409 | bool flattenUniformsAndCheckCaps(const Caps &caps, InfoLog &infoLog); |
| 410 | |
| 411 | struct VectorAndSamplerCount |
| 412 | { |
| 413 | VectorAndSamplerCount() : vectorCount(0), samplerCount(0) {} |
| 414 | VectorAndSamplerCount(const VectorAndSamplerCount &other) = default; |
| 415 | VectorAndSamplerCount &operator=(const VectorAndSamplerCount &other) = default; |
| 416 | |
| 417 | VectorAndSamplerCount &operator+=(const VectorAndSamplerCount &other) |
| 418 | { |
| 419 | vectorCount += other.vectorCount; |
| 420 | samplerCount += other.samplerCount; |
| 421 | return *this; |
| 422 | } |
| 423 | |
| 424 | unsigned int vectorCount; |
| 425 | unsigned int samplerCount; |
| 426 | }; |
| 427 | |
| 428 | VectorAndSamplerCount flattenUniform(const sh::ShaderVariable &uniform, |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 429 | const std::string &fullName, |
| 430 | std::vector<LinkedUniform> *samplerUniforms); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 431 | |
| 432 | void gatherInterfaceBlockInfo(); |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 433 | template <typename VarT> |
| 434 | void defineUniformBlockMembers(const std::vector<VarT> &fields, |
| 435 | const std::string &prefix, |
| 436 | int blockIndex); |
| 437 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 438 | void defineUniformBlock(const sh::InterfaceBlock &interfaceBlock, GLenum shaderType); |
| 439 | |
| 440 | template <typename T> |
| 441 | void setUniformInternal(GLint location, GLsizei count, const T *v); |
| 442 | |
| 443 | template <size_t cols, size_t rows, typename T> |
| 444 | void setMatrixUniformInternal(GLint location, GLsizei count, GLboolean transpose, const T *v); |
| 445 | |
| 446 | template <typename DestT> |
| 447 | void getUniformInternal(GLint location, DestT *dataOut) const; |
| 448 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 449 | ProgramState mState; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 450 | rx::ProgramImpl *mProgram; |
| 451 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 452 | bool mValidated; |
| 453 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 454 | Bindings mAttributeBindings; |
| 455 | Bindings mUniformBindings; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 456 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame^] | 457 | // CHROMIUM_path_rendering |
| 458 | Bindings mFragmentInputBindings; |
| 459 | |
daniel@transgaming.com | 716056c | 2012-07-24 18:38:59 +0000 | [diff] [blame] | 460 | bool mLinked; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 461 | 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] | 462 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 463 | unsigned int mRefCount; |
| 464 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 465 | ResourceManager *mResourceManager; |
| 466 | const GLuint mHandle; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 467 | |
| 468 | InfoLog mInfoLog; |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 469 | |
| 470 | // Cache for sampler validation |
| 471 | Optional<bool> mCachedValidateSamplersResult; |
| 472 | std::vector<GLenum> mTextureUnitTypesCache; |
| 473 | RangeUI mSamplerUniformRange; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 474 | }; |
| 475 | } |
| 476 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 477 | #endif // LIBANGLE_PROGRAM_H_ |