blob: 93573eacd618406f658a9d41ca4629fa8d9abc4e [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>
Geoff Lang7dd2e102014-11-10 15:19:26 -050014#include <GLSLANG/ShaderLang.h>
Geoff Lang0b7eef72014-06-12 14:10:47 -040015
Jamie Madill63805b42015-08-25 13:17:39 -040016#include <set>
Jamie Madill71c3b2c2015-05-07 11:49:20 -040017#include <sstream>
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include <string>
Jamie Madill63805b42015-08-25 13:17:39 -040019#include <vector>
Geoff Lang0b7eef72014-06-12 14:10:47 -040020
Jamie Madill3d3d2f22015-09-23 16:47:51 -040021#include "common/angleutils.h"
22#include "common/mathutil.h"
23#include "common/Optional.h"
24
25#include "libANGLE/angletypes.h"
26#include "libANGLE/Constants.h"
Geoff Lang70d0f492015-12-10 17:45:46 -050027#include "libANGLE/Debug.h"
Jamie Madill3d3d2f22015-09-23 16:47:51 -040028#include "libANGLE/Error.h"
29#include "libANGLE/RefCountObject.h"
30
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000031namespace rx
32{
Jamie Madill7aea7e02016-05-10 10:39:45 -040033class GLImplFactory;
Geoff Lang7dd2e102014-11-10 15:19:26 -050034class ProgramImpl;
Jamie Madill5c6b7bf2015-08-17 12:53:35 -040035struct TranslatedAttribute;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000036}
daniel@transgaming.come6842292010-04-20 18:52:50 +000037
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038namespace gl
39{
Brandon Jones43a53e22014-08-28 16:23:22 -070040struct Caps;
Jamie Madilldfde6ab2016-06-09 07:07:18 -070041class ContextState;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000042class ResourceManager;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000043class Shader;
Geoff Lang7dd2e102014-11-10 15:19:26 -050044class InfoLog;
Geoff Lang7dd2e102014-11-10 15:19:26 -050045class Buffer;
46class Framebuffer;
47struct UniformBlock;
48struct LinkedUniform;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000049
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000050extern const char * const g_fakepath;
51
Jamie Madillf0d10f82015-03-31 12:56:52 -040052class InfoLog : angle::NonCopyable
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000053{
54 public:
55 InfoLog();
56 ~InfoLog();
57
Jamie Madill71c3b2c2015-05-07 11:49:20 -040058 size_t getLength() const;
Geoff Lange1a27752015-10-05 13:16:04 -040059 void getLog(GLsizei bufSize, GLsizei *length, char *infoLog) const;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000060
61 void appendSanitized(const char *message);
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000062 void reset();
Jamie Madillf6113162015-05-07 11:49:21 -040063
64 // This helper class ensures we append a newline after writing a line.
65 class StreamHelper : angle::NonCopyable
66 {
67 public:
68 StreamHelper(StreamHelper &&rhs)
69 : mStream(rhs.mStream)
70 {
71 rhs.mStream = nullptr;
72 }
73
74 StreamHelper &operator=(StreamHelper &&rhs)
75 {
76 std::swap(mStream, rhs.mStream);
77 return *this;
78 }
79
80 ~StreamHelper()
81 {
82 // Write newline when destroyed on the stack
83 if (mStream)
84 {
85 (*mStream) << std::endl;
86 }
87 }
88
89 template <typename T>
90 StreamHelper &operator<<(const T &value)
91 {
92 (*mStream) << value;
93 return *this;
94 }
95
96 private:
97 friend class InfoLog;
98
99 StreamHelper(std::stringstream *stream)
100 : mStream(stream)
101 {
102 ASSERT(stream);
103 }
104
105 std::stringstream *mStream;
106 };
107
108 template <typename T>
109 StreamHelper operator<<(const T &value)
110 {
111 StreamHelper helper(&mStream);
112 helper << value;
113 return helper;
114 }
115
116 std::string str() const { return mStream.str(); }
117
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000118 private:
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400119 std::stringstream mStream;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000120};
121
Geoff Lang7dd2e102014-11-10 15:19:26 -0500122// Struct used for correlating uniforms/elements of uniform arrays to handles
123struct VariableLocation
124{
125 VariableLocation();
126 VariableLocation(const std::string &name, unsigned int element, unsigned int index);
127
128 std::string name;
129 unsigned int element;
130 unsigned int index;
Geoff Langd8605522016-04-13 10:19:12 -0400131
132 // If this is a valid uniform location
133 bool used;
134
135 // If this location was bound to an unreferenced uniform. Setting data on this uniform is a
136 // no-op.
137 bool ignored;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500138};
139
Sami Väisänen46eaa942016-06-29 10:26:37 +0300140// Information about a variable binding.
141// Currently used by CHROMIUM_path_rendering
142struct BindingInfo
143{
144 // The type of binding, for example GL_FLOAT_VEC3.
145 // This can be GL_NONE if the variable is optimized away.
146 GLenum type;
147
148 // This is the name of the variable in
149 // the translated shader program. Note that
150 // this can be empty in the case where the
151 // variable has been optimized away.
152 std::string name;
153
154 // True if the binding is valid, otherwise false.
155 bool valid;
156};
157
Jamie Madill48ef11b2016-04-27 15:21:52 -0400158class ProgramState final : angle::NonCopyable
159{
160 public:
161 ProgramState();
162 ~ProgramState();
163
164 const std::string &getLabel();
165
166 const Shader *getAttachedVertexShader() const { return mAttachedVertexShader; }
167 const Shader *getAttachedFragmentShader() const { return mAttachedFragmentShader; }
Martin Radev4c4c8e72016-08-04 12:25:34 +0300168 const Shader *getAttachedComputeShader() const { return mAttachedComputeShader; }
Jamie Madill48ef11b2016-04-27 15:21:52 -0400169 const std::vector<std::string> &getTransformFeedbackVaryingNames() const
170 {
171 return mTransformFeedbackVaryingNames;
172 }
173 GLint getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; }
174 GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const
175 {
176 ASSERT(uniformBlockIndex < IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS);
177 return mUniformBlockBindings[uniformBlockIndex];
178 }
179 const UniformBlockBindingMask &getActiveUniformBlockBindingsMask() const
180 {
181 return mActiveUniformBlockBindings;
182 }
183 const std::vector<sh::Attribute> &getAttributes() const { return mAttributes; }
184 const AttributesMask &getActiveAttribLocationsMask() const
185 {
186 return mActiveAttribLocationsMask;
187 }
188 const std::map<int, VariableLocation> &getOutputVariables() const { return mOutputVariables; }
189 const std::vector<LinkedUniform> &getUniforms() const { return mUniforms; }
190 const std::vector<VariableLocation> &getUniformLocations() const { return mUniformLocations; }
191 const std::vector<UniformBlock> &getUniformBlocks() const { return mUniformBlocks; }
192
193 const LinkedUniform *getUniformByName(const std::string &name) const;
194 GLint getUniformLocation(const std::string &name) const;
195 GLuint getUniformIndex(const std::string &name) const;
196
197 private:
198 friend class Program;
199
200 std::string mLabel;
201
Martin Radev4c4c8e72016-08-04 12:25:34 +0300202 sh::WorkGroupSize mComputeShaderLocalSize;
203
Jamie Madill48ef11b2016-04-27 15:21:52 -0400204 Shader *mAttachedFragmentShader;
205 Shader *mAttachedVertexShader;
Martin Radev4c4c8e72016-08-04 12:25:34 +0300206 Shader *mAttachedComputeShader;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400207
208 std::vector<std::string> mTransformFeedbackVaryingNames;
209 std::vector<sh::Varying> mTransformFeedbackVaryingVars;
210 GLenum mTransformFeedbackBufferMode;
211
212 GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS];
213 UniformBlockBindingMask mActiveUniformBlockBindings;
214
215 std::vector<sh::Attribute> mAttributes;
216 std::bitset<MAX_VERTEX_ATTRIBS> mActiveAttribLocationsMask;
217
218 // Uniforms are sorted in order:
219 // 1. Non-sampler uniforms
220 // 2. Sampler uniforms
221 // 3. Uniform block uniforms
222 // This makes sampler validation easier, since we don't need a separate list.
223 std::vector<LinkedUniform> mUniforms;
224 std::vector<VariableLocation> mUniformLocations;
225 std::vector<UniformBlock> mUniformBlocks;
226
227 // TODO(jmadill): use unordered/hash map when available
228 std::map<int, VariableLocation> mOutputVariables;
229
230 bool mBinaryRetrieveableHint;
231};
232
Geoff Lang70d0f492015-12-10 17:45:46 -0500233class Program final : angle::NonCopyable, public LabeledObject
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000234{
235 public:
Jamie Madill7aea7e02016-05-10 10:39:45 -0400236 Program(rx::GLImplFactory *factory, ResourceManager *manager, GLuint handle);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000237 ~Program();
238
Geoff Lang7dd2e102014-11-10 15:19:26 -0500239 GLuint id() const { return mHandle; }
240
Geoff Lang70d0f492015-12-10 17:45:46 -0500241 void setLabel(const std::string &label) override;
242 const std::string &getLabel() const override;
243
Geoff Lang47110bf2016-04-20 11:13:22 -0700244 rx::ProgramImpl *getImplementation() const { return mProgram; }
Geoff Lang7dd2e102014-11-10 15:19:26 -0500245
Jamie Madillef300b12016-10-07 15:12:09 -0400246 void attachShader(Shader *shader);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000247 bool detachShader(Shader *shader);
248 int getAttachedShadersCount() const;
249
Jamie Madillef300b12016-10-07 15:12:09 -0400250 const Shader *getAttachedVertexShader() const { return mState.mAttachedVertexShader; }
251 const Shader *getAttachedFragmentShader() const { return mState.mAttachedFragmentShader; }
252 const Shader *getAttachedComputeShader() const { return mState.mAttachedComputeShader; }
253
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000254 void bindAttributeLocation(GLuint index, const char *name);
Geoff Langd8605522016-04-13 10:19:12 -0400255 void bindUniformLocation(GLuint index, const char *name);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000256
Sami Väisänen46eaa942016-06-29 10:26:37 +0300257 // CHROMIUM_path_rendering
258 BindingInfo getFragmentInputBindingInfo(GLint index) const;
259 void bindFragmentInputLocation(GLint index, const char *name);
260 void pathFragmentInputGen(GLint index,
261 GLenum genMode,
262 GLint components,
263 const GLfloat *coeffs);
264
Jamie Madill9082b982016-04-27 15:21:51 -0400265 Error link(const ContextState &data);
Geoff Lange1a27752015-10-05 13:16:04 -0400266 bool isLinked() const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500267
268 Error loadBinary(GLenum binaryFormat, const void *binary, GLsizei length);
269 Error saveBinary(GLenum *binaryFormat, void *binary, GLsizei bufSize, GLsizei *length) const;
270 GLint getBinaryLength() const;
Geoff Langc5629752015-12-07 16:29:04 -0500271 void setBinaryRetrievableHint(bool retrievable);
272 bool getBinaryRetrievableHint() const;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000273
274 int getInfoLogLength() const;
Geoff Lange1a27752015-10-05 13:16:04 -0400275 void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const;
276 void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders) const;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000277
Geoff Lange1a27752015-10-05 13:16:04 -0400278 GLuint getAttributeLocation(const std::string &name) const;
Jamie Madill63805b42015-08-25 13:17:39 -0400279 bool isAttribLocationActive(size_t attribLocation) const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500280
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000281 void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
Geoff Lange1a27752015-10-05 13:16:04 -0400282 GLint getActiveAttributeCount() const;
283 GLint getActiveAttributeMaxLength() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400284 const std::vector<sh::Attribute> &getAttributes() const { return mState.mAttributes; }
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000285
Geoff Lang7dd2e102014-11-10 15:19:26 -0500286 GLint getFragDataLocation(const std::string &name) const;
287
Geoff Lange1a27752015-10-05 13:16:04 -0400288 void getActiveUniform(GLuint index,
289 GLsizei bufsize,
290 GLsizei *length,
291 GLint *size,
292 GLenum *type,
293 GLchar *name) const;
294 GLint getActiveUniformCount() const;
295 GLint getActiveUniformMaxLength() const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500296 GLint getActiveUniformi(GLuint index, GLenum pname) const;
297 bool isValidUniformLocation(GLint location) const;
Geoff Langd8605522016-04-13 10:19:12 -0400298 bool isIgnoredUniformLocation(GLint location) const;
Jamie Madill62d31cb2015-09-11 13:25:51 -0400299 const LinkedUniform &getUniformByLocation(GLint location) const;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000300
Jamie Madill62d31cb2015-09-11 13:25:51 -0400301 GLint getUniformLocation(const std::string &name) const;
302 GLuint getUniformIndex(const std::string &name) const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500303 void setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
304 void setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
305 void setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
306 void setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
307 void setUniform1iv(GLint location, GLsizei count, const GLint *v);
308 void setUniform2iv(GLint location, GLsizei count, const GLint *v);
309 void setUniform3iv(GLint location, GLsizei count, const GLint *v);
310 void setUniform4iv(GLint location, GLsizei count, const GLint *v);
311 void setUniform1uiv(GLint location, GLsizei count, const GLuint *v);
312 void setUniform2uiv(GLint location, GLsizei count, const GLuint *v);
313 void setUniform3uiv(GLint location, GLsizei count, const GLuint *v);
314 void setUniform4uiv(GLint location, GLsizei count, const GLuint *v);
315 void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
316 void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
317 void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
318 void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
319 void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
320 void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
321 void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
322 void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
323 void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
324
Geoff Lange1a27752015-10-05 13:16:04 -0400325 void getUniformfv(GLint location, GLfloat *params) const;
326 void getUniformiv(GLint location, GLint *params) const;
327 void getUniformuiv(GLint location, GLuint *params) const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500328
Geoff Lang7dd2e102014-11-10 15:19:26 -0500329 void getActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName) const;
330 void getActiveUniformBlockiv(GLuint uniformBlockIndex, GLenum pname, GLint *params) const;
Geoff Lange1a27752015-10-05 13:16:04 -0400331 GLuint getActiveUniformBlockCount() const;
332 GLint getActiveUniformBlockMaxLength() const;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +0000333
Geoff Lange1a27752015-10-05 13:16:04 -0400334 GLuint getUniformBlockIndex(const std::string &name) const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500335
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000336 void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding);
337 GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const;
338
Jamie Madill62d31cb2015-09-11 13:25:51 -0400339 const UniformBlock &getUniformBlockByIndex(GLuint index) const;
Gregoire Payen de La Garanderie68694e92015-03-24 14:03:37 +0000340
Geoff Lang48dcae72014-02-05 16:28:24 -0500341 void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode);
342 void getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const;
Geoff Lang1b6edcb2014-02-03 14:27:56 -0500343 GLsizei getTransformFeedbackVaryingCount() const;
344 GLsizei getTransformFeedbackVaryingMaxLength() const;
345 GLenum getTransformFeedbackBufferMode() const;
346
Geoff Lang7dd2e102014-11-10 15:19:26 -0500347 static bool linkValidateUniforms(InfoLog &infoLog, const std::string &uniformName, const sh::Uniform &vertexUniform, const sh::Uniform &fragmentUniform);
348 static bool linkValidateInterfaceBlockFields(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform);
349
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000350 void addRef();
351 void release();
352 unsigned int getRefCount() const;
353 void flagForDeletion();
354 bool isFlaggedForDeletion() const;
355
Brandon Jones43a53e22014-08-28 16:23:22 -0700356 void validate(const Caps &caps);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500357 bool validateSamplers(InfoLog *infoLog, const Caps &caps);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000358 bool isValidated() const;
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000359
Jamie Madill63805b42015-08-25 13:17:39 -0400360 const AttributesMask &getActiveAttribLocationsMask() const
361 {
Jamie Madill48ef11b2016-04-27 15:21:52 -0400362 return mState.mActiveAttribLocationsMask;
Jamie Madill63805b42015-08-25 13:17:39 -0400363 }
364
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000365 private:
Geoff Langd8605522016-04-13 10:19:12 -0400366 class Bindings final : angle::NonCopyable
367 {
368 public:
369 void bindLocation(GLuint index, const std::string &name);
370 int getBinding(const std::string &name) const;
371
372 typedef std::unordered_map<std::string, GLuint>::const_iterator const_iterator;
373 const_iterator begin() const;
374 const_iterator end() const;
375
376 private:
377 std::unordered_map<std::string, GLuint> mBindings;
378 };
379
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000380 void unlink(bool destroy = false);
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000381 void resetUniformBlockBindings();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000382
Jamie Madill9082b982016-04-27 15:21:51 -0400383 bool linkAttributes(const ContextState &data,
Jamie Madill3da79b72015-04-27 11:09:17 -0400384 InfoLog &infoLog,
Geoff Langd8605522016-04-13 10:19:12 -0400385 const Bindings &attributeBindings,
Jamie Madill3da79b72015-04-27 11:09:17 -0400386 const Shader *vertexShader);
Martin Radev4c4c8e72016-08-04 12:25:34 +0300387 bool validateUniformBlocksCount(GLuint maxUniformBlocks,
388 const std::vector<sh::InterfaceBlock> &block,
389 const std::string &errorMessage,
390 InfoLog &infoLog) const;
391 bool validateVertexAndFragmentInterfaceBlocks(
392 const std::vector<sh::InterfaceBlock> &vertexInterfaceBlocks,
393 const std::vector<sh::InterfaceBlock> &fragmentInterfaceBlocks,
394 InfoLog &infoLog) const;
Jamie Madille473dee2015-08-18 14:49:01 -0400395 bool linkUniformBlocks(InfoLog &infoLog, const Caps &caps);
Sami Väisänen46eaa942016-06-29 10:26:37 +0300396 bool linkVaryings(InfoLog &infoLog, const Shader *vertexShader, const Shader *fragmentShader) const;
Martin Radev4c4c8e72016-08-04 12:25:34 +0300397 bool validateVertexAndFragmentUniforms(InfoLog &infoLog) const;
Geoff Langd8605522016-04-13 10:19:12 -0400398 bool linkUniforms(gl::InfoLog &infoLog, const gl::Caps &caps, const Bindings &uniformBindings);
399 bool indexUniforms(gl::InfoLog &infoLog, const gl::Caps &caps, const Bindings &uniformBindings);
Martin Radev4c4c8e72016-08-04 12:25:34 +0300400 bool areMatchingInterfaceBlocks(gl::InfoLog &infoLog,
401 const sh::InterfaceBlock &vertexInterfaceBlock,
402 const sh::InterfaceBlock &fragmentInterfaceBlock) const;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500403
404 static bool linkValidateVariablesBase(InfoLog &infoLog,
405 const std::string &variableName,
406 const sh::ShaderVariable &vertexVariable,
407 const sh::ShaderVariable &fragmentVariable,
408 bool validatePrecision);
409
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400410 static bool linkValidateVaryings(InfoLog &infoLog,
411 const std::string &varyingName,
412 const sh::Varying &vertexVarying,
413 const sh::Varying &fragmentVarying,
414 int shaderVersion);
Jamie Madillccdf74b2015-08-18 10:46:12 -0400415 bool linkValidateTransformFeedback(InfoLog &infoLog,
416 const std::vector<const sh::Varying *> &linkedVaryings,
417 const Caps &caps) const;
418
419 void gatherTransformFeedbackVaryings(const std::vector<const sh::Varying *> &varyings);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500420 bool assignUniformBlockRegister(InfoLog &infoLog, UniformBlock *uniformBlock, GLenum shader, unsigned int registerIndex, const Caps &caps);
421 void defineOutputVariables(Shader *fragmentShader);
422
Jamie Madillccdf74b2015-08-18 10:46:12 -0400423 std::vector<const sh::Varying *> getMergedVaryings() const;
Jamie Madill80a6fc02015-08-21 16:53:16 -0400424 void linkOutputVariables();
Jamie Madillccdf74b2015-08-18 10:46:12 -0400425
Martin Radev4c4c8e72016-08-04 12:25:34 +0300426 bool flattenUniformsAndCheckCapsForShader(const gl::Shader &shader,
427 GLuint maxUniformComponents,
428 GLuint maxTextureImageUnits,
429 const std::string &componentsErrorMessage,
430 const std::string &samplerErrorMessage,
431 std::vector<LinkedUniform> &samplerUniforms,
432 InfoLog &infoLog);
Jamie Madill62d31cb2015-09-11 13:25:51 -0400433 bool flattenUniformsAndCheckCaps(const Caps &caps, InfoLog &infoLog);
434
435 struct VectorAndSamplerCount
436 {
437 VectorAndSamplerCount() : vectorCount(0), samplerCount(0) {}
438 VectorAndSamplerCount(const VectorAndSamplerCount &other) = default;
439 VectorAndSamplerCount &operator=(const VectorAndSamplerCount &other) = default;
440
441 VectorAndSamplerCount &operator+=(const VectorAndSamplerCount &other)
442 {
443 vectorCount += other.vectorCount;
444 samplerCount += other.samplerCount;
445 return *this;
446 }
447
448 unsigned int vectorCount;
449 unsigned int samplerCount;
450 };
451
452 VectorAndSamplerCount flattenUniform(const sh::ShaderVariable &uniform,
Jamie Madill3d3d2f22015-09-23 16:47:51 -0400453 const std::string &fullName,
454 std::vector<LinkedUniform> *samplerUniforms);
Jamie Madill62d31cb2015-09-11 13:25:51 -0400455
456 void gatherInterfaceBlockInfo();
Jamie Madill4a3c2342015-10-08 12:58:45 -0400457 template <typename VarT>
458 void defineUniformBlockMembers(const std::vector<VarT> &fields,
459 const std::string &prefix,
460 int blockIndex);
461
Jamie Madill62d31cb2015-09-11 13:25:51 -0400462 void defineUniformBlock(const sh::InterfaceBlock &interfaceBlock, GLenum shaderType);
463
464 template <typename T>
465 void setUniformInternal(GLint location, GLsizei count, const T *v);
466
467 template <size_t cols, size_t rows, typename T>
468 void setMatrixUniformInternal(GLint location, GLsizei count, GLboolean transpose, const T *v);
469
470 template <typename DestT>
471 void getUniformInternal(GLint location, DestT *dataOut) const;
472
Jamie Madill48ef11b2016-04-27 15:21:52 -0400473 ProgramState mState;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500474 rx::ProgramImpl *mProgram;
475
Geoff Lang7dd2e102014-11-10 15:19:26 -0500476 bool mValidated;
477
Geoff Langd8605522016-04-13 10:19:12 -0400478 Bindings mAttributeBindings;
479 Bindings mUniformBindings;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000480
Sami Väisänen46eaa942016-06-29 10:26:37 +0300481 // CHROMIUM_path_rendering
482 Bindings mFragmentInputBindings;
483
daniel@transgaming.com716056c2012-07-24 18:38:59 +0000484 bool mLinked;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000485 bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
daniel@transgaming.com4fa08332010-05-11 02:29:27 +0000486
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000487 unsigned int mRefCount;
488
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000489 ResourceManager *mResourceManager;
490 const GLuint mHandle;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000491
492 InfoLog mInfoLog;
Jamie Madill3d3d2f22015-09-23 16:47:51 -0400493
494 // Cache for sampler validation
495 Optional<bool> mCachedValidateSamplersResult;
496 std::vector<GLenum> mTextureUnitTypesCache;
497 RangeUI mSamplerUniformRange;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000498};
499}
500
Geoff Lang0a73dd82014-11-19 16:18:08 -0500501#endif // LIBANGLE_PROGRAM_H_