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