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 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 27 | #include "libANGLE/Constants.h" |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 28 | #include "libANGLE/Debug.h" |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 29 | #include "libANGLE/Error.h" |
| 30 | #include "libANGLE/RefCountObject.h" |
jchen10 | 7a20b97 | 2017-06-13 14:25:26 +0800 | [diff] [blame] | 31 | #include "libANGLE/Uniform.h" |
| 32 | #include "libANGLE/angletypes.h" |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 33 | |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 34 | namespace rx |
| 35 | { |
Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 36 | class GLImplFactory; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 37 | class ProgramImpl; |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 38 | struct TranslatedAttribute; |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 39 | } |
daniel@transgaming.com | e684229 | 2010-04-20 18:52:50 +0000 | [diff] [blame] | 40 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 41 | namespace gl |
| 42 | { |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 43 | struct Caps; |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 44 | class Context; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 45 | class ContextState; |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 46 | class Shader; |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 47 | class ShaderProgramManager; |
Jamie Madill | f4f8db8 | 2017-02-15 09:31:39 -0500 | [diff] [blame] | 48 | class State; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 49 | class InfoLog; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 50 | class Buffer; |
| 51 | class Framebuffer; |
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 | { |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 115 | ensureInitialized(); |
| 116 | StreamHelper helper(mLazyStream.get()); |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 117 | helper << value; |
| 118 | return helper; |
| 119 | } |
| 120 | |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 121 | std::string str() const { return mLazyStream ? mLazyStream->str() : ""; } |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 122 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 123 | private: |
Jamie Madill | 23176ce | 2017-07-31 14:14:33 -0400 | [diff] [blame] | 124 | void ensureInitialized() |
| 125 | { |
| 126 | if (!mLazyStream) |
| 127 | { |
| 128 | mLazyStream.reset(new std::stringstream()); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | std::unique_ptr<std::stringstream> mLazyStream; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 135 | // Struct used for correlating uniforms/elements of uniform arrays to handles |
| 136 | struct VariableLocation |
| 137 | { |
| 138 | VariableLocation(); |
| 139 | VariableLocation(const std::string &name, unsigned int element, unsigned int index); |
| 140 | |
| 141 | std::string name; |
| 142 | unsigned int element; |
| 143 | unsigned int index; |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 144 | |
Jamie Madill | fe8b598 | 2017-09-07 17:00:18 -0400 | [diff] [blame^] | 145 | // If used is false, it means this location is only used to fill an empty space in an array, |
| 146 | // and there is no corresponding uniform variable for this location. It can also mean the |
| 147 | // uniform was optimized out by the implementation. |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 148 | bool used; |
| 149 | |
| 150 | // If this location was bound to an unreferenced uniform. Setting data on this uniform is a |
| 151 | // no-op. |
| 152 | bool ignored; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 153 | }; |
| 154 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 155 | // Information about a variable binding. |
| 156 | // Currently used by CHROMIUM_path_rendering |
| 157 | struct BindingInfo |
| 158 | { |
| 159 | // The type of binding, for example GL_FLOAT_VEC3. |
| 160 | // This can be GL_NONE if the variable is optimized away. |
| 161 | GLenum type; |
| 162 | |
| 163 | // This is the name of the variable in |
| 164 | // the translated shader program. Note that |
| 165 | // this can be empty in the case where the |
| 166 | // variable has been optimized away. |
| 167 | std::string name; |
| 168 | |
| 169 | // True if the binding is valid, otherwise false. |
| 170 | bool valid; |
| 171 | }; |
| 172 | |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 173 | // This small structure encapsulates binding sampler uniforms to active GL textures. |
| 174 | struct SamplerBinding |
| 175 | { |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 176 | SamplerBinding(GLenum textureTypeIn, size_t elementCount, bool unreferenced) |
| 177 | : textureType(textureTypeIn), boundTextureUnits(elementCount, 0), unreferenced(unreferenced) |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 178 | { |
| 179 | } |
| 180 | |
| 181 | // Necessary for retrieving active textures from the GL state. |
| 182 | GLenum textureType; |
| 183 | |
| 184 | // List of all textures bound to this sampler, of type textureType. |
| 185 | std::vector<GLuint> boundTextureUnits; |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 186 | |
| 187 | // A note if this sampler is an unreferenced uniform. |
| 188 | bool unreferenced; |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 189 | }; |
| 190 | |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 191 | // A varying with tranform feedback enabled. If it's an array, either the whole array or one of its |
| 192 | // elements specified by 'arrayIndex' can set to be enabled. |
| 193 | struct TransformFeedbackVarying : public sh::Varying |
| 194 | { |
| 195 | TransformFeedbackVarying(const sh::Varying &varyingIn, GLuint index) |
| 196 | : sh::Varying(varyingIn), arrayIndex(index) |
| 197 | { |
| 198 | } |
| 199 | std::string nameWithArrayIndex() const |
| 200 | { |
| 201 | std::stringstream fullNameStr; |
| 202 | fullNameStr << name; |
| 203 | if (arrayIndex != GL_INVALID_INDEX) |
| 204 | { |
| 205 | fullNameStr << "[" << arrayIndex << "]"; |
| 206 | } |
| 207 | return fullNameStr.str(); |
| 208 | } |
| 209 | GLsizei size() const { return (arrayIndex == GL_INVALID_INDEX ? elementCount() : 1); } |
| 210 | |
| 211 | GLuint arrayIndex; |
| 212 | }; |
| 213 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 214 | struct ImageBinding |
| 215 | { |
Xinghua Cao | 0328b57 | 2017-06-26 15:51:36 +0800 | [diff] [blame] | 216 | ImageBinding(size_t count) : boundImageUnits(count, 0) {} |
| 217 | ImageBinding(GLuint imageUnit, size_t count) |
| 218 | { |
| 219 | for (size_t index = 0; index < count; ++index) |
| 220 | { |
| 221 | boundImageUnits.push_back(imageUnit + static_cast<GLuint>(index)); |
| 222 | } |
| 223 | } |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 224 | |
Xinghua Cao | 0328b57 | 2017-06-26 15:51:36 +0800 | [diff] [blame] | 225 | std::vector<GLuint> boundImageUnits; |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 226 | }; |
| 227 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 228 | class ProgramState final : angle::NonCopyable |
| 229 | { |
| 230 | public: |
| 231 | ProgramState(); |
| 232 | ~ProgramState(); |
| 233 | |
| 234 | const std::string &getLabel(); |
| 235 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 236 | Shader *getAttachedVertexShader() const { return mAttachedVertexShader; } |
| 237 | Shader *getAttachedFragmentShader() const { return mAttachedFragmentShader; } |
| 238 | Shader *getAttachedComputeShader() const { return mAttachedComputeShader; } |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 239 | const std::vector<std::string> &getTransformFeedbackVaryingNames() const |
| 240 | { |
| 241 | return mTransformFeedbackVaryingNames; |
| 242 | } |
| 243 | GLint getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; } |
| 244 | GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const |
| 245 | { |
jchen10 | 7a20b97 | 2017-06-13 14:25:26 +0800 | [diff] [blame] | 246 | ASSERT(uniformBlockIndex < mUniformBlocks.size()); |
| 247 | return mUniformBlocks[uniformBlockIndex].binding; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 248 | } |
| 249 | const UniformBlockBindingMask &getActiveUniformBlockBindingsMask() const |
| 250 | { |
| 251 | return mActiveUniformBlockBindings; |
| 252 | } |
| 253 | const std::vector<sh::Attribute> &getAttributes() const { return mAttributes; } |
| 254 | const AttributesMask &getActiveAttribLocationsMask() const |
| 255 | { |
| 256 | return mActiveAttribLocationsMask; |
| 257 | } |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 258 | DrawBufferMask getActiveOutputVariables() const { return mActiveOutputVariables; } |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 259 | const std::vector<sh::OutputVariable> &getOutputVariables() const { return mOutputVariables; } |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 260 | const std::map<int, VariableLocation> &getOutputLocations() const { return mOutputLocations; } |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 261 | const std::vector<LinkedUniform> &getUniforms() const { return mUniforms; } |
| 262 | const std::vector<VariableLocation> &getUniformLocations() const { return mUniformLocations; } |
| 263 | const std::vector<UniformBlock> &getUniformBlocks() const { return mUniformBlocks; } |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 264 | const std::vector<SamplerBinding> &getSamplerBindings() const { return mSamplerBindings; } |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 265 | const std::vector<ImageBinding> &getImageBindings() const { return mImageBindings; } |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 266 | const sh::WorkGroupSize &getComputeShaderLocalSize() const { return mComputeShaderLocalSize; } |
| 267 | const RangeUI &getSamplerUniformRange() const { return mSamplerUniformRange; } |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 268 | const RangeUI &getImageUniformRange() const { return mImageUniformRange; } |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 269 | const RangeUI &getAtomicCounterUniformRange() const { return mAtomicCounterUniformRange; } |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 270 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 271 | const std::vector<TransformFeedbackVarying> &getLinkedTransformFeedbackVaryings() const |
| 272 | { |
| 273 | return mLinkedTransformFeedbackVaryings; |
| 274 | } |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 275 | const std::vector<AtomicCounterBuffer> &getAtomicCounterBuffers() const |
| 276 | { |
| 277 | return mAtomicCounterBuffers; |
| 278 | } |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 279 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 280 | GLint getUniformLocation(const std::string &name) const; |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 281 | GLuint getUniformIndexFromName(const std::string &name) const; |
| 282 | GLuint getUniformIndexFromLocation(GLint location) const; |
| 283 | Optional<GLuint> getSamplerIndex(GLint location) const; |
| 284 | bool isSamplerUniformIndex(GLuint index) const; |
| 285 | GLuint getSamplerIndexFromUniformIndex(GLuint uniformIndex) const; |
Jamie Madill | 34ca4f5 | 2017-06-13 11:49:39 -0400 | [diff] [blame] | 286 | GLuint getAttributeLocation(const std::string &name) const; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 287 | |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 288 | int getNumViews() const { return mNumViews; } |
| 289 | bool usesMultiview() const { return mNumViews != -1; } |
| 290 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 291 | private: |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 292 | friend class MemoryProgramCache; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 293 | friend class Program; |
| 294 | |
| 295 | std::string mLabel; |
| 296 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 297 | sh::WorkGroupSize mComputeShaderLocalSize; |
| 298 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 299 | Shader *mAttachedFragmentShader; |
| 300 | Shader *mAttachedVertexShader; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 301 | Shader *mAttachedComputeShader; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 302 | |
| 303 | std::vector<std::string> mTransformFeedbackVaryingNames; |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 304 | std::vector<TransformFeedbackVarying> mLinkedTransformFeedbackVaryings; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 305 | GLenum mTransformFeedbackBufferMode; |
| 306 | |
jchen10 | 7a20b97 | 2017-06-13 14:25:26 +0800 | [diff] [blame] | 307 | // For faster iteration on the blocks currently being bound. |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 308 | UniformBlockBindingMask mActiveUniformBlockBindings; |
| 309 | |
| 310 | std::vector<sh::Attribute> mAttributes; |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 311 | angle::BitSet<MAX_VERTEX_ATTRIBS> mActiveAttribLocationsMask; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 312 | |
| 313 | // Uniforms are sorted in order: |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 314 | // 1. Non-opaque uniforms |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 315 | // 2. Sampler uniforms |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 316 | // 3. Image uniforms |
| 317 | // 4. Atomic counter uniforms |
| 318 | // 5. Uniform block uniforms |
| 319 | // This makes opaque uniform validation easier, since we don't need a separate list. |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 320 | std::vector<LinkedUniform> mUniforms; |
| 321 | std::vector<VariableLocation> mUniformLocations; |
| 322 | std::vector<UniformBlock> mUniformBlocks; |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 323 | std::vector<AtomicCounterBuffer> mAtomicCounterBuffers; |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 324 | RangeUI mSamplerUniformRange; |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 325 | RangeUI mImageUniformRange; |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 326 | RangeUI mAtomicCounterUniformRange; |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 327 | |
| 328 | // An array of the samplers that are used by the program |
| 329 | std::vector<gl::SamplerBinding> mSamplerBindings; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 330 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 331 | // An array of the images that are used by the program |
| 332 | std::vector<gl::ImageBinding> mImageBindings; |
| 333 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 334 | std::vector<sh::OutputVariable> mOutputVariables; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 335 | // TODO(jmadill): use unordered/hash map when available |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 336 | std::map<int, VariableLocation> mOutputLocations; |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 337 | DrawBufferMask mActiveOutputVariables; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 338 | |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 339 | // Fragment output variable base types: FLOAT, INT, or UINT. Ordered by location. |
| 340 | std::vector<GLenum> mOutputVariableTypes; |
| 341 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 342 | bool mBinaryRetrieveableHint; |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 343 | bool mSeparable; |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 344 | |
| 345 | // ANGLE_multiview. |
| 346 | int mNumViews; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 347 | }; |
| 348 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 349 | class Program final : angle::NonCopyable, public LabeledObject |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 350 | { |
| 351 | public: |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 352 | Program(rx::GLImplFactory *factory, ShaderProgramManager *manager, GLuint handle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 353 | void onDestroy(const Context *context); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 354 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 355 | GLuint id() const { return mHandle; } |
| 356 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 357 | void setLabel(const std::string &label) override; |
| 358 | const std::string &getLabel() const override; |
| 359 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 360 | rx::ProgramImpl *getImplementation() const { return mProgram; } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 361 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 362 | void attachShader(Shader *shader); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 363 | void detachShader(const Context *context, Shader *shader); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 364 | int getAttachedShadersCount() const; |
| 365 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 366 | const Shader *getAttachedVertexShader() const { return mState.mAttachedVertexShader; } |
| 367 | const Shader *getAttachedFragmentShader() const { return mState.mAttachedFragmentShader; } |
| 368 | const Shader *getAttachedComputeShader() const { return mState.mAttachedComputeShader; } |
| 369 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 370 | void bindAttributeLocation(GLuint index, const char *name); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 371 | void bindUniformLocation(GLuint index, const char *name); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 372 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 373 | // CHROMIUM_path_rendering |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 374 | BindingInfo getFragmentInputBindingInfo(const Context *context, GLint index) const; |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 375 | void bindFragmentInputLocation(GLint index, const char *name); |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 376 | void pathFragmentInputGen(const Context *context, |
| 377 | GLint index, |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 378 | GLenum genMode, |
| 379 | GLint components, |
| 380 | const GLfloat *coeffs); |
| 381 | |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 382 | Error link(const gl::Context *context); |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 383 | bool isLinked() const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 384 | |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 385 | Error loadBinary(const Context *context, |
| 386 | GLenum binaryFormat, |
| 387 | const void *binary, |
| 388 | GLsizei length); |
| 389 | Error saveBinary(const Context *context, |
| 390 | GLenum *binaryFormat, |
| 391 | void *binary, |
| 392 | GLsizei bufSize, |
| 393 | GLsizei *length) const; |
Jamie Madill | ffe00c0 | 2017-06-27 16:26:55 -0400 | [diff] [blame] | 394 | GLint getBinaryLength(const Context *context) const; |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 395 | void setBinaryRetrievableHint(bool retrievable); |
| 396 | bool getBinaryRetrievableHint() const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 397 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 398 | void setSeparable(bool separable); |
| 399 | bool isSeparable() const; |
| 400 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 401 | int getInfoLogLength() const; |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 402 | void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const; |
| 403 | void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders) const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 404 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 405 | GLuint getAttributeLocation(const std::string &name) const; |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 406 | bool isAttribLocationActive(size_t attribLocation) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 407 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 408 | void getActiveAttribute(GLuint index, |
| 409 | GLsizei bufsize, |
| 410 | GLsizei *length, |
| 411 | GLint *size, |
| 412 | GLenum *type, |
| 413 | GLchar *name) const; |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 414 | GLint getActiveAttributeCount() const; |
| 415 | GLint getActiveAttributeMaxLength() const; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 416 | const std::vector<sh::Attribute> &getAttributes() const { return mState.mAttributes; } |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 417 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 418 | GLint getFragDataLocation(const std::string &name) const; |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 419 | size_t getOutputResourceCount() const; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 420 | const std::vector<GLenum> &getOutputVariableTypes() const |
| 421 | { |
| 422 | return mState.mOutputVariableTypes; |
| 423 | } |
Corentin Wallez | db9e5d3 | 2017-06-12 12:05:45 -0700 | [diff] [blame] | 424 | DrawBufferMask getActiveOutputVariables() const { return mState.mActiveOutputVariables; } |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 425 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 426 | void getActiveUniform(GLuint index, |
| 427 | GLsizei bufsize, |
| 428 | GLsizei *length, |
| 429 | GLint *size, |
| 430 | GLenum *type, |
| 431 | GLchar *name) const; |
| 432 | GLint getActiveUniformCount() const; |
| 433 | GLint getActiveUniformMaxLength() const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 434 | GLint getActiveUniformi(GLuint index, GLenum pname) const; |
| 435 | bool isValidUniformLocation(GLint location) const; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 436 | const LinkedUniform &getUniformByLocation(GLint location) const; |
Jamie Madill | ac4e9c3 | 2017-01-13 14:07:12 -0500 | [diff] [blame] | 437 | const VariableLocation &getUniformLocation(GLint location) const; |
| 438 | const std::vector<VariableLocation> &getUniformLocations() const; |
| 439 | const LinkedUniform &getUniformByIndex(GLuint index) const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 440 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 441 | GLint getUniformLocation(const std::string &name) const; |
| 442 | GLuint getUniformIndex(const std::string &name) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 443 | void setUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 444 | void setUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 445 | void setUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 446 | void setUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
| 447 | void setUniform1iv(GLint location, GLsizei count, const GLint *v); |
| 448 | void setUniform2iv(GLint location, GLsizei count, const GLint *v); |
| 449 | void setUniform3iv(GLint location, GLsizei count, const GLint *v); |
| 450 | void setUniform4iv(GLint location, GLsizei count, const GLint *v); |
| 451 | void setUniform1uiv(GLint location, GLsizei count, const GLuint *v); |
| 452 | void setUniform2uiv(GLint location, GLsizei count, const GLuint *v); |
| 453 | void setUniform3uiv(GLint location, GLsizei count, const GLuint *v); |
| 454 | void setUniform4uiv(GLint location, GLsizei count, const GLuint *v); |
| 455 | void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 456 | void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 457 | void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 458 | void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 459 | void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 460 | void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 461 | void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 462 | void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 463 | void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 464 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 465 | void getUniformfv(const Context *context, GLint location, GLfloat *params) const; |
| 466 | void getUniformiv(const Context *context, GLint location, GLint *params) const; |
| 467 | void getUniformuiv(const Context *context, GLint location, GLuint *params) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 468 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 469 | void getActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName) const; |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 470 | GLuint getActiveUniformBlockCount() const; |
| 471 | GLint getActiveUniformBlockMaxLength() const; |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 472 | |
Geoff Lang | e1a2775 | 2015-10-05 13:16:04 -0400 | [diff] [blame] | 473 | GLuint getUniformBlockIndex(const std::string &name) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 474 | |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 475 | void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding); |
| 476 | GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const; |
| 477 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 478 | const UniformBlock &getUniformBlockByIndex(GLuint index) const; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 479 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 480 | void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode); |
| 481 | 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] | 482 | GLsizei getTransformFeedbackVaryingCount() const; |
| 483 | GLsizei getTransformFeedbackVaryingMaxLength() const; |
| 484 | GLenum getTransformFeedbackBufferMode() const; |
| 485 | |
Frank Henigman | fccbac2 | 2017-05-28 17:29:26 -0400 | [diff] [blame] | 486 | static bool linkValidateInterfaceBlockFields(InfoLog &infoLog, |
| 487 | const std::string &uniformName, |
| 488 | const sh::InterfaceBlockField &vertexUniform, |
| 489 | const sh::InterfaceBlockField &fragmentUniform, |
| 490 | bool webglCompatibility); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 491 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 492 | void addRef(); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 493 | void release(const Context *context); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 494 | unsigned int getRefCount() const; |
| 495 | void flagForDeletion(); |
| 496 | bool isFlaggedForDeletion() const; |
| 497 | |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 498 | void validate(const Caps &caps); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 499 | bool validateSamplers(InfoLog *infoLog, const Caps &caps); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 500 | bool isValidated() const; |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 501 | bool samplesFromTexture(const gl::State &state, GLuint textureID) const; |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 502 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 503 | const AttributesMask &getActiveAttribLocationsMask() const |
| 504 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 505 | return mState.mActiveAttribLocationsMask; |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 506 | } |
| 507 | |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 508 | const std::vector<SamplerBinding> &getSamplerBindings() const |
| 509 | { |
| 510 | return mState.mSamplerBindings; |
| 511 | } |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 512 | |
| 513 | const std::vector<ImageBinding> &getImageBindings() const { return mState.mImageBindings; } |
| 514 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 515 | const ProgramState &getState() const { return mState; } |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 516 | |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 517 | static bool linkValidateVariablesBase(InfoLog &infoLog, |
| 518 | const std::string &variableName, |
| 519 | const sh::ShaderVariable &vertexVariable, |
| 520 | const sh::ShaderVariable &fragmentVariable, |
| 521 | bool validatePrecision); |
| 522 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 523 | GLuint getInputResourceIndex(const GLchar *name) const; |
| 524 | GLuint getOutputResourceIndex(const GLchar *name) const; |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 525 | void getInputResourceName(GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name) const; |
| 526 | void getOutputResourceName(GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name) const; |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 527 | const sh::Attribute &getInputResource(GLuint index) const; |
| 528 | const sh::OutputVariable &getOutputResource(GLuint index) const; |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 529 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 530 | class Bindings final : angle::NonCopyable |
| 531 | { |
| 532 | public: |
| 533 | void bindLocation(GLuint index, const std::string &name); |
| 534 | int getBinding(const std::string &name) const; |
| 535 | |
| 536 | typedef std::unordered_map<std::string, GLuint>::const_iterator const_iterator; |
| 537 | const_iterator begin() const; |
| 538 | const_iterator end() const; |
| 539 | |
| 540 | private: |
| 541 | std::unordered_map<std::string, GLuint> mBindings; |
| 542 | }; |
| 543 | |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 544 | const Bindings &getAttributeBindings() const { return mAttributeBindings; } |
| 545 | const Bindings &getUniformLocationBindings() const { return mUniformLocationBindings; } |
| 546 | const Bindings &getFragmentInputBindings() const { return mFragmentInputBindings; } |
| 547 | |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 548 | int getNumViews() const { return mState.getNumViews(); } |
| 549 | bool usesMultiview() const { return mState.usesMultiview(); } |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 550 | |
Olli Etuaho | b78707c | 2017-03-09 15:03:11 +0000 | [diff] [blame] | 551 | private: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 552 | ~Program(); |
| 553 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 554 | struct VaryingRef |
| 555 | { |
| 556 | const sh::Varying *get() const { return vertex ? vertex : fragment; } |
| 557 | |
| 558 | const sh::Varying *vertex = nullptr; |
| 559 | const sh::Varying *fragment = nullptr; |
| 560 | }; |
| 561 | |
| 562 | using MergedVaryings = std::map<std::string, VaryingRef>; |
| 563 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 564 | void unlink(); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 565 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 566 | bool linkAttributes(const Context *context, InfoLog &infoLog); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 567 | bool validateUniformBlocksCount(GLuint maxUniformBlocks, |
| 568 | const std::vector<sh::InterfaceBlock> &block, |
| 569 | const std::string &errorMessage, |
| 570 | InfoLog &infoLog) const; |
| 571 | bool validateVertexAndFragmentInterfaceBlocks( |
| 572 | const std::vector<sh::InterfaceBlock> &vertexInterfaceBlocks, |
| 573 | const std::vector<sh::InterfaceBlock> &fragmentInterfaceBlocks, |
Frank Henigman | fccbac2 | 2017-05-28 17:29:26 -0400 | [diff] [blame] | 574 | InfoLog &infoLog, |
| 575 | bool webglCompatibility) const; |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 576 | bool linkUniformBlocks(const Context *context, InfoLog &infoLog); |
| 577 | bool linkVaryings(const Context *context, InfoLog &infoLog) const; |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 578 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 579 | bool linkUniforms(const Context *context, |
| 580 | InfoLog &infoLog, |
| 581 | const Bindings &uniformLocationBindings); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 582 | void linkSamplerAndImageBindings(); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 583 | bool linkAtomicCounterBuffers(); |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 584 | |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 585 | bool areMatchingInterfaceBlocks(InfoLog &infoLog, |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 586 | const sh::InterfaceBlock &vertexInterfaceBlock, |
Frank Henigman | fccbac2 | 2017-05-28 17:29:26 -0400 | [diff] [blame] | 587 | const sh::InterfaceBlock &fragmentInterfaceBlock, |
| 588 | bool webglCompatibility) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 589 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 590 | static bool linkValidateVaryings(InfoLog &infoLog, |
| 591 | const std::string &varyingName, |
| 592 | const sh::Varying &vertexVarying, |
| 593 | const sh::Varying &fragmentVarying, |
| 594 | int shaderVersion); |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 595 | bool linkValidateBuiltInVaryings(const Context *context, InfoLog &infoLog) const; |
jchen10 | a9042d3 | 2017-03-17 08:50:45 +0800 | [diff] [blame] | 596 | bool linkValidateTransformFeedback(const gl::Context *context, |
| 597 | InfoLog &infoLog, |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 598 | const MergedVaryings &linkedVaryings, |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 599 | const Caps &caps) const; |
Yuly Novikov | caa5cda | 2017-06-15 21:14:03 -0400 | [diff] [blame] | 600 | bool linkValidateGlobalNames(const Context *context, InfoLog &infoLog) const; |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 601 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 602 | void gatherTransformFeedbackVaryings(const MergedVaryings &varyings); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 603 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 604 | MergedVaryings getMergedVaryings(const Context *context) const; |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 605 | std::vector<PackedVarying> getPackedVaryings(const MergedVaryings &mergedVaryings) const; |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 606 | void linkOutputVariables(const Context *context); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 607 | |
Olli Etuaho | 48fed63 | 2017-03-16 12:05:30 +0000 | [diff] [blame] | 608 | void setUniformValuesFromBindingQualifiers(); |
| 609 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 610 | void gatherAtomicCounterBuffers(); |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 611 | void gatherInterfaceBlockInfo(const Context *context); |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 612 | template <typename VarT> |
| 613 | void defineUniformBlockMembers(const std::vector<VarT> &fields, |
| 614 | const std::string &prefix, |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 615 | const std::string &mappedPrefix, |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 616 | int blockIndex); |
| 617 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 618 | void defineUniformBlock(const sh::InterfaceBlock &interfaceBlock, GLenum shaderType); |
| 619 | |
Corentin Wallez | 8b7d814 | 2016-11-15 13:40:37 -0500 | [diff] [blame] | 620 | // Both these function update the cached uniform values and return a modified "count" |
| 621 | // so that the uniform update doesn't overflow the uniform. |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 622 | template <typename T> |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 623 | GLsizei clampUniformCount(const VariableLocation &locationInfo, |
| 624 | GLsizei count, |
| 625 | int vectorSize, |
Jamie Madill | e7d8432 | 2017-01-10 18:21:59 -0500 | [diff] [blame] | 626 | const T *v); |
Jamie Madill | be5e2ec | 2017-08-31 13:28:28 -0400 | [diff] [blame] | 627 | template <size_t cols, size_t rows, typename T> |
| 628 | GLsizei clampMatrixUniformCount(GLint location, GLsizei count, GLboolean transpose, const T *v); |
| 629 | |
| 630 | void updateSamplerUniform(const VariableLocation &locationInfo, |
| 631 | GLsizei clampedCount, |
| 632 | const GLint *v); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 633 | |
| 634 | template <typename DestT> |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 635 | void getUniformInternal(const Context *context, |
| 636 | DestT *dataOut, |
| 637 | GLint location, |
| 638 | GLenum nativeType, |
| 639 | int components) const; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 640 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 641 | ProgramState mState; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 642 | rx::ProgramImpl *mProgram; |
| 643 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 644 | bool mValidated; |
| 645 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 646 | Bindings mAttributeBindings; |
Olli Etuaho | 4a92ceb | 2017-02-19 17:51:24 +0000 | [diff] [blame] | 647 | |
| 648 | // Note that this has nothing to do with binding layout qualifiers that can be set for some |
| 649 | // uniforms in GLES3.1+. It is used to pre-set the location of uniforms. |
| 650 | Bindings mUniformLocationBindings; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 651 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 652 | // CHROMIUM_path_rendering |
| 653 | Bindings mFragmentInputBindings; |
| 654 | |
daniel@transgaming.com | 716056c | 2012-07-24 18:38:59 +0000 | [diff] [blame] | 655 | bool mLinked; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 656 | 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] | 657 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 658 | unsigned int mRefCount; |
| 659 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 660 | ShaderProgramManager *mResourceManager; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 661 | const GLuint mHandle; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 662 | |
| 663 | InfoLog mInfoLog; |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 664 | |
| 665 | // Cache for sampler validation |
| 666 | Optional<bool> mCachedValidateSamplersResult; |
| 667 | std::vector<GLenum> mTextureUnitTypesCache; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 668 | }; |
Jamie Madill | a2c7498 | 2016-12-12 11:20:42 -0500 | [diff] [blame] | 669 | } // namespace gl |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 670 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 671 | #endif // LIBANGLE_PROGRAM_H_ |