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