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