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