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