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