blob: 75074276005cf3428c7d8f238332e21f2735f629 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// 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 Lang0a73dd82014-11-19 16:18:08 -050010#ifndef LIBANGLE_PROGRAM_H_
11#define LIBANGLE_PROGRAM_H_
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012
Geoff Lang0b7eef72014-06-12 14:10:47 -040013#include <GLES2/gl2.h>
Jamie Madill861ebb32016-11-17 16:40:22 -050014#include <GLSLANG/ShaderVars.h>
Geoff Lang0b7eef72014-06-12 14:10:47 -040015
Jamie Madilla7d12dc2016-12-13 15:08:19 -050016#include <array>
Jamie Madill861ebb32016-11-17 16:40:22 -050017#include <map>
Jamie Madill63805b42015-08-25 13:17:39 -040018#include <set>
Jamie Madill71c3b2c2015-05-07 11:49:20 -040019#include <sstream>
Geoff Lang0b7eef72014-06-12 14:10:47 -040020#include <string>
Jamie Madill63805b42015-08-25 13:17:39 -040021#include <vector>
Geoff Lang0b7eef72014-06-12 14:10:47 -040022
Jamie Madill3d3d2f22015-09-23 16:47:51 -040023#include "common/angleutils.h"
24#include "common/mathutil.h"
25#include "common/Optional.h"
26
27#include "libANGLE/angletypes.h"
28#include "libANGLE/Constants.h"
Geoff Lang70d0f492015-12-10 17:45:46 -050029#include "libANGLE/Debug.h"
Jamie Madill3d3d2f22015-09-23 16:47:51 -040030#include "libANGLE/Error.h"
31#include "libANGLE/RefCountObject.h"
32
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000033namespace rx
34{
Jamie Madill7aea7e02016-05-10 10:39:45 -040035class GLImplFactory;
Geoff Lang7dd2e102014-11-10 15:19:26 -050036class ProgramImpl;
Jamie Madill5c6b7bf2015-08-17 12:53:35 -040037struct TranslatedAttribute;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000038}
daniel@transgaming.come6842292010-04-20 18:52:50 +000039
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000040namespace gl
41{
Brandon Jones43a53e22014-08-28 16:23:22 -070042struct Caps;
Jamie Madilla2c74982016-12-12 11:20:42 -050043class Context;
Jamie Madilldfde6ab2016-06-09 07:07:18 -070044class ContextState;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000045class Shader;
Geoff Lang4ddf5af2016-12-01 14:30:44 -050046class ShaderProgramManager;
Jamie Madillf4f8db82017-02-15 09:31:39 -050047class State;
Geoff Lang7dd2e102014-11-10 15:19:26 -050048class InfoLog;
Geoff Lang7dd2e102014-11-10 15:19:26 -050049class Buffer;
50class Framebuffer;
51struct UniformBlock;
52struct LinkedUniform;
Jamie Madill192745a2016-12-22 15:58:21 -050053struct PackedVarying;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000054
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000055extern const char * const g_fakepath;
56
Jamie Madillf0d10f82015-03-31 12:56:52 -040057class InfoLog : angle::NonCopyable
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000058{
59 public:
60 InfoLog();
61 ~InfoLog();
62
Jamie Madill71c3b2c2015-05-07 11:49:20 -040063 size_t getLength() const;
Geoff Lange1a27752015-10-05 13:16:04 -040064 void getLog(GLsizei bufSize, GLsizei *length, char *infoLog) const;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000065
66 void appendSanitized(const char *message);
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000067 void reset();
Jamie Madillf6113162015-05-07 11:49:21 -040068
69 // This helper class ensures we append a newline after writing a line.
70 class StreamHelper : angle::NonCopyable
71 {
72 public:
73 StreamHelper(StreamHelper &&rhs)
74 : mStream(rhs.mStream)
75 {
76 rhs.mStream = nullptr;
77 }
78
79 StreamHelper &operator=(StreamHelper &&rhs)
80 {
81 std::swap(mStream, rhs.mStream);
82 return *this;
83 }
84
85 ~StreamHelper()
86 {
87 // Write newline when destroyed on the stack
88 if (mStream)
89 {
90 (*mStream) << std::endl;
91 }
92 }
93
94 template <typename T>
95 StreamHelper &operator<<(const T &value)
96 {
97 (*mStream) << value;
98 return *this;
99 }
100
101 private:
102 friend class InfoLog;
103
104 StreamHelper(std::stringstream *stream)
105 : mStream(stream)
106 {
107 ASSERT(stream);
108 }
109
110 std::stringstream *mStream;
111 };
112
113 template <typename T>
114 StreamHelper operator<<(const T &value)
115 {
116 StreamHelper helper(&mStream);
117 helper << value;
118 return helper;
119 }
120
121 std::string str() const { return mStream.str(); }
122
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000123 private:
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400124 std::stringstream mStream;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000125};
126
Geoff Lang7dd2e102014-11-10 15:19:26 -0500127// Struct used for correlating uniforms/elements of uniform arrays to handles
128struct VariableLocation
129{
130 VariableLocation();
131 VariableLocation(const std::string &name, unsigned int element, unsigned int index);
132
133 std::string name;
134 unsigned int element;
135 unsigned int index;
Geoff Langd8605522016-04-13 10:19:12 -0400136
137 // If this is a valid uniform location
138 bool used;
139
140 // If this location was bound to an unreferenced uniform. Setting data on this uniform is a
141 // no-op.
142 bool ignored;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500143};
144
Sami Väisänen46eaa942016-06-29 10:26:37 +0300145// Information about a variable binding.
146// Currently used by CHROMIUM_path_rendering
147struct BindingInfo
148{
149 // The type of binding, for example GL_FLOAT_VEC3.
150 // This can be GL_NONE if the variable is optimized away.
151 GLenum type;
152
153 // This is the name of the variable in
154 // the translated shader program. Note that
155 // this can be empty in the case where the
156 // variable has been optimized away.
157 std::string name;
158
159 // True if the binding is valid, otherwise false.
160 bool valid;
161};
162
Jamie Madille7d84322017-01-10 18:21:59 -0500163// This small structure encapsulates binding sampler uniforms to active GL textures.
164struct SamplerBinding
165{
166 SamplerBinding(GLenum textureTypeIn, size_t elementCount)
167 : textureType(textureTypeIn), boundTextureUnits(elementCount, 0)
168 {
169 }
170
171 // Necessary for retrieving active textures from the GL state.
172 GLenum textureType;
173
174 // List of all textures bound to this sampler, of type textureType.
175 std::vector<GLuint> boundTextureUnits;
176};
177
jchen10a9042d32017-03-17 08:50:45 +0800178// A varying with tranform feedback enabled. If it's an array, either the whole array or one of its
179// elements specified by 'arrayIndex' can set to be enabled.
180struct TransformFeedbackVarying : public sh::Varying
181{
182 TransformFeedbackVarying(const sh::Varying &varyingIn, GLuint index)
183 : sh::Varying(varyingIn), arrayIndex(index)
184 {
185 }
186 std::string nameWithArrayIndex() const
187 {
188 std::stringstream fullNameStr;
189 fullNameStr << name;
190 if (arrayIndex != GL_INVALID_INDEX)
191 {
192 fullNameStr << "[" << arrayIndex << "]";
193 }
194 return fullNameStr.str();
195 }
196 GLsizei size() const { return (arrayIndex == GL_INVALID_INDEX ? elementCount() : 1); }
197
198 GLuint arrayIndex;
199};
200
Jamie Madill48ef11b2016-04-27 15:21:52 -0400201class ProgramState final : angle::NonCopyable
202{
203 public:
204 ProgramState();
205 ~ProgramState();
206
207 const std::string &getLabel();
208
209 const Shader *getAttachedVertexShader() const { return mAttachedVertexShader; }
210 const Shader *getAttachedFragmentShader() const { return mAttachedFragmentShader; }
Martin Radev4c4c8e72016-08-04 12:25:34 +0300211 const Shader *getAttachedComputeShader() const { return mAttachedComputeShader; }
Jamie Madill48ef11b2016-04-27 15:21:52 -0400212 const std::vector<std::string> &getTransformFeedbackVaryingNames() const
213 {
214 return mTransformFeedbackVaryingNames;
215 }
216 GLint getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; }
217 GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const
218 {
219 ASSERT(uniformBlockIndex < IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS);
220 return mUniformBlockBindings[uniformBlockIndex];
221 }
222 const UniformBlockBindingMask &getActiveUniformBlockBindingsMask() const
223 {
224 return mActiveUniformBlockBindings;
225 }
226 const std::vector<sh::Attribute> &getAttributes() const { return mAttributes; }
227 const AttributesMask &getActiveAttribLocationsMask() const
228 {
229 return mActiveAttribLocationsMask;
230 }
Corentin Walleze7557742017-06-01 13:09:57 -0400231 DrawBufferMask getActiveOutputVariables() const { return mActiveOutputVariables; }
jchen1015015f72017-03-16 13:54:21 +0800232 const std::map<int, VariableLocation> &getOutputLocations() const { return mOutputLocations; }
Jamie Madill48ef11b2016-04-27 15:21:52 -0400233 const std::vector<LinkedUniform> &getUniforms() const { return mUniforms; }
234 const std::vector<VariableLocation> &getUniformLocations() const { return mUniformLocations; }
235 const std::vector<UniformBlock> &getUniformBlocks() const { return mUniformBlocks; }
Jamie Madille7d84322017-01-10 18:21:59 -0500236 const std::vector<SamplerBinding> &getSamplerBindings() const { return mSamplerBindings; }
Jamie Madill48ef11b2016-04-27 15:21:52 -0400237
Jamie Madill48ef11b2016-04-27 15:21:52 -0400238 GLint getUniformLocation(const std::string &name) const;
Jamie Madille7d84322017-01-10 18:21:59 -0500239 GLuint getUniformIndexFromName(const std::string &name) const;
240 GLuint getUniformIndexFromLocation(GLint location) const;
241 Optional<GLuint> getSamplerIndex(GLint location) const;
242 bool isSamplerUniformIndex(GLuint index) const;
243 GLuint getSamplerIndexFromUniformIndex(GLuint uniformIndex) const;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400244
245 private:
246 friend class Program;
247
248 std::string mLabel;
249
Martin Radev4c4c8e72016-08-04 12:25:34 +0300250 sh::WorkGroupSize mComputeShaderLocalSize;
251
Jamie Madill48ef11b2016-04-27 15:21:52 -0400252 Shader *mAttachedFragmentShader;
253 Shader *mAttachedVertexShader;
Martin Radev4c4c8e72016-08-04 12:25:34 +0300254 Shader *mAttachedComputeShader;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400255
256 std::vector<std::string> mTransformFeedbackVaryingNames;
jchen10a9042d32017-03-17 08:50:45 +0800257 std::vector<TransformFeedbackVarying> mLinkedTransformFeedbackVaryings;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400258 GLenum mTransformFeedbackBufferMode;
259
Jamie Madilla7d12dc2016-12-13 15:08:19 -0500260 std::array<GLuint, IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS> mUniformBlockBindings;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400261 UniformBlockBindingMask mActiveUniformBlockBindings;
262
263 std::vector<sh::Attribute> mAttributes;
Jamie Madill6de51852017-04-12 09:53:01 -0400264 angle::BitSet<MAX_VERTEX_ATTRIBS> mActiveAttribLocationsMask;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400265
266 // Uniforms are sorted in order:
267 // 1. Non-sampler uniforms
268 // 2. Sampler uniforms
269 // 3. Uniform block uniforms
270 // This makes sampler validation easier, since we don't need a separate list.
271 std::vector<LinkedUniform> mUniforms;
272 std::vector<VariableLocation> mUniformLocations;
273 std::vector<UniformBlock> mUniformBlocks;
Jamie Madille7d84322017-01-10 18:21:59 -0500274 RangeUI mSamplerUniformRange;
275
276 // An array of the samplers that are used by the program
277 std::vector<gl::SamplerBinding> mSamplerBindings;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400278
jchen1015015f72017-03-16 13:54:21 +0800279 std::vector<sh::OutputVariable> mOutputVariables;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400280 // TODO(jmadill): use unordered/hash map when available
jchen1015015f72017-03-16 13:54:21 +0800281 std::map<int, VariableLocation> mOutputLocations;
Corentin Walleze7557742017-06-01 13:09:57 -0400282 DrawBufferMask mActiveOutputVariables;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400283
Geoff Lange0cff192017-05-30 13:04:56 -0400284 // Fragment output variable base types: FLOAT, INT, or UINT. Ordered by location.
285 std::vector<GLenum> mOutputVariableTypes;
286
Jamie Madill48ef11b2016-04-27 15:21:52 -0400287 bool mBinaryRetrieveableHint;
Yunchao He61afff12017-03-14 15:34:03 +0800288 bool mSeparable;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400289};
290
Geoff Lang70d0f492015-12-10 17:45:46 -0500291class Program final : angle::NonCopyable, public LabeledObject
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000292{
293 public:
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500294 Program(rx::GLImplFactory *factory, ShaderProgramManager *manager, GLuint handle);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000295 ~Program();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500296 void destroy(const Context *context);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000297
Geoff Lang7dd2e102014-11-10 15:19:26 -0500298 GLuint id() const { return mHandle; }
299
Geoff Lang70d0f492015-12-10 17:45:46 -0500300 void setLabel(const std::string &label) override;
301 const std::string &getLabel() const override;
302
Geoff Lang47110bf2016-04-20 11:13:22 -0700303 rx::ProgramImpl *getImplementation() const { return mProgram; }
Geoff Lang7dd2e102014-11-10 15:19:26 -0500304
Jamie Madillef300b12016-10-07 15:12:09 -0400305 void attachShader(Shader *shader);
Jamie Madillc1d770e2017-04-13 17:31:24 -0400306 void detachShader(const Context *context, Shader *shader);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000307 int getAttachedShadersCount() const;
308
Jamie Madillef300b12016-10-07 15:12:09 -0400309 const Shader *getAttachedVertexShader() const { return mState.mAttachedVertexShader; }
310 const Shader *getAttachedFragmentShader() const { return mState.mAttachedFragmentShader; }
311 const Shader *getAttachedComputeShader() const { return mState.mAttachedComputeShader; }
312
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000313 void bindAttributeLocation(GLuint index, const char *name);
Geoff Langd8605522016-04-13 10:19:12 -0400314 void bindUniformLocation(GLuint index, const char *name);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000315
Sami Väisänen46eaa942016-06-29 10:26:37 +0300316 // CHROMIUM_path_rendering
317 BindingInfo getFragmentInputBindingInfo(GLint index) const;
318 void bindFragmentInputLocation(GLint index, const char *name);
319 void pathFragmentInputGen(GLint index,
320 GLenum genMode,
321 GLint components,
322 const GLfloat *coeffs);
323
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500324 Error link(const gl::Context *context);
Geoff Lange1a27752015-10-05 13:16:04 -0400325 bool isLinked() const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500326
Jamie Madilla2c74982016-12-12 11:20:42 -0500327 Error loadBinary(const Context *context,
328 GLenum binaryFormat,
329 const void *binary,
330 GLsizei length);
331 Error saveBinary(const Context *context,
332 GLenum *binaryFormat,
333 void *binary,
334 GLsizei bufSize,
335 GLsizei *length) const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500336 GLint getBinaryLength() const;
Geoff Langc5629752015-12-07 16:29:04 -0500337 void setBinaryRetrievableHint(bool retrievable);
338 bool getBinaryRetrievableHint() const;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000339
Yunchao He61afff12017-03-14 15:34:03 +0800340 void setSeparable(bool separable);
341 bool isSeparable() const;
342
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000343 int getInfoLogLength() const;
Geoff Lange1a27752015-10-05 13:16:04 -0400344 void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const;
345 void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders) const;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000346
Geoff Lange1a27752015-10-05 13:16:04 -0400347 GLuint getAttributeLocation(const std::string &name) const;
Jamie Madill63805b42015-08-25 13:17:39 -0400348 bool isAttribLocationActive(size_t attribLocation) const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500349
jchen10fd7c3b52017-03-21 15:36:03 +0800350 void getActiveAttribute(GLuint index,
351 GLsizei bufsize,
352 GLsizei *length,
353 GLint *size,
354 GLenum *type,
355 GLchar *name) const;
Geoff Lange1a27752015-10-05 13:16:04 -0400356 GLint getActiveAttributeCount() const;
357 GLint getActiveAttributeMaxLength() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400358 const std::vector<sh::Attribute> &getAttributes() const { return mState.mAttributes; }
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000359
Geoff Lang7dd2e102014-11-10 15:19:26 -0500360 GLint getFragDataLocation(const std::string &name) const;
jchen10fd7c3b52017-03-21 15:36:03 +0800361 size_t getOutputResourceCount() const;
Geoff Lange0cff192017-05-30 13:04:56 -0400362 const std::vector<GLenum> &getOutputVariableTypes() const
363 {
364 return mState.mOutputVariableTypes;
365 }
Geoff Lang7dd2e102014-11-10 15:19:26 -0500366
Geoff Lange1a27752015-10-05 13:16:04 -0400367 void getActiveUniform(GLuint index,
368 GLsizei bufsize,
369 GLsizei *length,
370 GLint *size,
371 GLenum *type,
372 GLchar *name) const;
373 GLint getActiveUniformCount() const;
374 GLint getActiveUniformMaxLength() const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500375 GLint getActiveUniformi(GLuint index, GLenum pname) const;
376 bool isValidUniformLocation(GLint location) const;
Jamie Madill62d31cb2015-09-11 13:25:51 -0400377 const LinkedUniform &getUniformByLocation(GLint location) const;
Jamie Madillac4e9c32017-01-13 14:07:12 -0500378 const VariableLocation &getUniformLocation(GLint location) const;
379 const std::vector<VariableLocation> &getUniformLocations() const;
380 const LinkedUniform &getUniformByIndex(GLuint index) const;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000381
Jamie Madill62d31cb2015-09-11 13:25:51 -0400382 GLint getUniformLocation(const std::string &name) const;
383 GLuint getUniformIndex(const std::string &name) const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500384 void setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
385 void setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
386 void setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
387 void setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
388 void setUniform1iv(GLint location, GLsizei count, const GLint *v);
389 void setUniform2iv(GLint location, GLsizei count, const GLint *v);
390 void setUniform3iv(GLint location, GLsizei count, const GLint *v);
391 void setUniform4iv(GLint location, GLsizei count, const GLint *v);
392 void setUniform1uiv(GLint location, GLsizei count, const GLuint *v);
393 void setUniform2uiv(GLint location, GLsizei count, const GLuint *v);
394 void setUniform3uiv(GLint location, GLsizei count, const GLuint *v);
395 void setUniform4uiv(GLint location, GLsizei count, const GLuint *v);
396 void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
397 void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
398 void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
399 void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
400 void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
401 void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
402 void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
403 void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
404 void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
405
Geoff Lange1a27752015-10-05 13:16:04 -0400406 void getUniformfv(GLint location, GLfloat *params) const;
407 void getUniformiv(GLint location, GLint *params) const;
408 void getUniformuiv(GLint location, GLuint *params) const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500409
Geoff Lang7dd2e102014-11-10 15:19:26 -0500410 void getActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName) const;
Geoff Lange1a27752015-10-05 13:16:04 -0400411 GLuint getActiveUniformBlockCount() const;
412 GLint getActiveUniformBlockMaxLength() const;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +0000413
Geoff Lange1a27752015-10-05 13:16:04 -0400414 GLuint getUniformBlockIndex(const std::string &name) const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500415
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000416 void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding);
417 GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const;
418
Jamie Madill62d31cb2015-09-11 13:25:51 -0400419 const UniformBlock &getUniformBlockByIndex(GLuint index) const;
Gregoire Payen de La Garanderie68694e92015-03-24 14:03:37 +0000420
Geoff Lang48dcae72014-02-05 16:28:24 -0500421 void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode);
422 void getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const;
Geoff Lang1b6edcb2014-02-03 14:27:56 -0500423 GLsizei getTransformFeedbackVaryingCount() const;
424 GLsizei getTransformFeedbackVaryingMaxLength() const;
425 GLenum getTransformFeedbackBufferMode() const;
426
Geoff Lang7dd2e102014-11-10 15:19:26 -0500427 static bool linkValidateInterfaceBlockFields(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform);
428
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000429 void addRef();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500430 void release(const Context *context);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000431 unsigned int getRefCount() const;
432 void flagForDeletion();
433 bool isFlaggedForDeletion() const;
434
Brandon Jones43a53e22014-08-28 16:23:22 -0700435 void validate(const Caps &caps);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500436 bool validateSamplers(InfoLog *infoLog, const Caps &caps);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000437 bool isValidated() const;
Jamie Madilla4595b82017-01-11 17:36:34 -0500438 bool samplesFromTexture(const gl::State &state, GLuint textureID) const;
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000439
Jamie Madill63805b42015-08-25 13:17:39 -0400440 const AttributesMask &getActiveAttribLocationsMask() const
441 {
Jamie Madill48ef11b2016-04-27 15:21:52 -0400442 return mState.mActiveAttribLocationsMask;
Jamie Madill63805b42015-08-25 13:17:39 -0400443 }
444
Jamie Madille7d84322017-01-10 18:21:59 -0500445 const std::vector<SamplerBinding> &getSamplerBindings() const
446 {
447 return mState.mSamplerBindings;
448 }
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500449 const ProgramState &getState() const { return mState; }
Jamie Madille7d84322017-01-10 18:21:59 -0500450
Olli Etuahob78707c2017-03-09 15:03:11 +0000451 static bool linkValidateVariablesBase(InfoLog &infoLog,
452 const std::string &variableName,
453 const sh::ShaderVariable &vertexVariable,
454 const sh::ShaderVariable &fragmentVariable,
455 bool validatePrecision);
456
jchen1015015f72017-03-16 13:54:21 +0800457 GLuint getInputResourceIndex(const GLchar *name) const;
458 GLuint getOutputResourceIndex(const GLchar *name) const;
jchen10fd7c3b52017-03-21 15:36:03 +0800459 void getInputResourceName(GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name) const;
460 void getOutputResourceName(GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name) const;
jchen1015015f72017-03-16 13:54:21 +0800461
Geoff Langd8605522016-04-13 10:19:12 -0400462 class Bindings final : angle::NonCopyable
463 {
464 public:
465 void bindLocation(GLuint index, const std::string &name);
466 int getBinding(const std::string &name) const;
467
468 typedef std::unordered_map<std::string, GLuint>::const_iterator const_iterator;
469 const_iterator begin() const;
470 const_iterator end() const;
471
472 private:
473 std::unordered_map<std::string, GLuint> mBindings;
474 };
475
Olli Etuahob78707c2017-03-09 15:03:11 +0000476 private:
Jamie Madill192745a2016-12-22 15:58:21 -0500477 struct VaryingRef
478 {
479 const sh::Varying *get() const { return vertex ? vertex : fragment; }
480
481 const sh::Varying *vertex = nullptr;
482 const sh::Varying *fragment = nullptr;
483 };
484
485 using MergedVaryings = std::map<std::string, VaryingRef>;
486
Jamie Madill6c1f6712017-02-14 19:08:04 -0500487 void unlink();
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000488 void resetUniformBlockBindings();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000489
Jamie Madilleb979bf2016-11-15 12:28:46 -0500490 bool linkAttributes(const ContextState &data, InfoLog &infoLog);
Martin Radev4c4c8e72016-08-04 12:25:34 +0300491 bool validateUniformBlocksCount(GLuint maxUniformBlocks,
492 const std::vector<sh::InterfaceBlock> &block,
493 const std::string &errorMessage,
494 InfoLog &infoLog) const;
495 bool validateVertexAndFragmentInterfaceBlocks(
496 const std::vector<sh::InterfaceBlock> &vertexInterfaceBlocks,
497 const std::vector<sh::InterfaceBlock> &fragmentInterfaceBlocks,
498 InfoLog &infoLog) const;
Jamie Madille473dee2015-08-18 14:49:01 -0400499 bool linkUniformBlocks(InfoLog &infoLog, const Caps &caps);
Jamie Madill192745a2016-12-22 15:58:21 -0500500 bool linkVaryings(InfoLog &infoLog) const;
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000501
Olli Etuaho4a92ceb2017-02-19 17:51:24 +0000502 bool linkUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &uniformLocationBindings);
Olli Etuaho48fed632017-03-16 12:05:30 +0000503 void linkSamplerBindings();
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000504
Jamie Madilla2c74982016-12-12 11:20:42 -0500505 bool areMatchingInterfaceBlocks(InfoLog &infoLog,
Martin Radev4c4c8e72016-08-04 12:25:34 +0300506 const sh::InterfaceBlock &vertexInterfaceBlock,
507 const sh::InterfaceBlock &fragmentInterfaceBlock) const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500508
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400509 static bool linkValidateVaryings(InfoLog &infoLog,
510 const std::string &varyingName,
511 const sh::Varying &vertexVarying,
512 const sh::Varying &fragmentVarying,
513 int shaderVersion);
Yuly Novikov817232e2017-02-22 18:36:10 -0500514 bool linkValidateBuiltInVaryings(InfoLog &infoLog) const;
jchen10a9042d32017-03-17 08:50:45 +0800515 bool linkValidateTransformFeedback(const gl::Context *context,
516 InfoLog &infoLog,
Jamie Madill192745a2016-12-22 15:58:21 -0500517 const MergedVaryings &linkedVaryings,
Jamie Madillccdf74b2015-08-18 10:46:12 -0400518 const Caps &caps) const;
519
Jamie Madill192745a2016-12-22 15:58:21 -0500520 void gatherTransformFeedbackVaryings(const MergedVaryings &varyings);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500521
Jamie Madill192745a2016-12-22 15:58:21 -0500522 MergedVaryings getMergedVaryings() const;
523 std::vector<PackedVarying> getPackedVaryings(const MergedVaryings &mergedVaryings) const;
Jamie Madill80a6fc02015-08-21 16:53:16 -0400524 void linkOutputVariables();
Jamie Madillccdf74b2015-08-18 10:46:12 -0400525
Olli Etuaho48fed632017-03-16 12:05:30 +0000526 void setUniformValuesFromBindingQualifiers();
527
Jamie Madill62d31cb2015-09-11 13:25:51 -0400528 void gatherInterfaceBlockInfo();
Jamie Madill4a3c2342015-10-08 12:58:45 -0400529 template <typename VarT>
530 void defineUniformBlockMembers(const std::vector<VarT> &fields,
531 const std::string &prefix,
532 int blockIndex);
533
Jamie Madill62d31cb2015-09-11 13:25:51 -0400534 void defineUniformBlock(const sh::InterfaceBlock &interfaceBlock, GLenum shaderType);
535
Corentin Wallez8b7d8142016-11-15 13:40:37 -0500536 // Both these function update the cached uniform values and return a modified "count"
537 // so that the uniform update doesn't overflow the uniform.
Jamie Madill62d31cb2015-09-11 13:25:51 -0400538 template <typename T>
Corentin Wallez8b7d8142016-11-15 13:40:37 -0500539 GLsizei setUniformInternal(GLint location, GLsizei count, int vectorSize, const T *v);
Jamie Madill62d31cb2015-09-11 13:25:51 -0400540 template <size_t cols, size_t rows, typename T>
Corentin Wallez8b7d8142016-11-15 13:40:37 -0500541 GLsizei setMatrixUniformInternal(GLint location,
542 GLsizei count,
543 GLboolean transpose,
544 const T *v);
Jamie Madille7d84322017-01-10 18:21:59 -0500545 template <typename T>
546 void updateSamplerUniform(const VariableLocation &locationInfo,
547 const uint8_t *destPointer,
548 GLsizei clampedCount,
549 const T *v);
Jamie Madill62d31cb2015-09-11 13:25:51 -0400550
551 template <typename DestT>
552 void getUniformInternal(GLint location, DestT *dataOut) const;
553
Jamie Madill48ef11b2016-04-27 15:21:52 -0400554 ProgramState mState;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500555 rx::ProgramImpl *mProgram;
556
Geoff Lang7dd2e102014-11-10 15:19:26 -0500557 bool mValidated;
558
Geoff Langd8605522016-04-13 10:19:12 -0400559 Bindings mAttributeBindings;
Olli Etuaho4a92ceb2017-02-19 17:51:24 +0000560
561 // Note that this has nothing to do with binding layout qualifiers that can be set for some
562 // uniforms in GLES3.1+. It is used to pre-set the location of uniforms.
563 Bindings mUniformLocationBindings;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000564
Sami Väisänen46eaa942016-06-29 10:26:37 +0300565 // CHROMIUM_path_rendering
566 Bindings mFragmentInputBindings;
567
daniel@transgaming.com716056c2012-07-24 18:38:59 +0000568 bool mLinked;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000569 bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
daniel@transgaming.com4fa08332010-05-11 02:29:27 +0000570
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000571 unsigned int mRefCount;
572
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500573 ShaderProgramManager *mResourceManager;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000574 const GLuint mHandle;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000575
576 InfoLog mInfoLog;
Jamie Madill3d3d2f22015-09-23 16:47:51 -0400577
578 // Cache for sampler validation
579 Optional<bool> mCachedValidateSamplersResult;
580 std::vector<GLenum> mTextureUnitTypesCache;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000581};
Jamie Madilla2c74982016-12-12 11:20:42 -0500582} // namespace gl
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000583
Geoff Lang0a73dd82014-11-19 16:18:08 -0500584#endif // LIBANGLE_PROGRAM_H_