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