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