blob: d91e62d962428f1699c9974e6bf0ed8cf26bfa50 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Geoff Lang48dcae72014-02-05 16:28:24 -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.cpp: Implements 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 Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Program.h"
Jamie Madill437d2662014-12-05 14:23:35 -050011
Jamie Madill9e0478f2015-01-13 11:13:54 -050012#include <algorithm>
13
Jamie Madill80a6fc02015-08-21 16:53:16 -040014#include "common/BitSetIterator.h"
Jamie Madill9e0478f2015-01-13 11:13:54 -050015#include "common/debug.h"
16#include "common/platform.h"
17#include "common/utilities.h"
18#include "common/version.h"
19#include "compiler/translator/blocklayout.h"
Geoff Lang7dd2e102014-11-10 15:19:26 -050020#include "libANGLE/Data.h"
Jamie Madill437d2662014-12-05 14:23:35 -050021#include "libANGLE/ResourceManager.h"
Geoff Lang7dd2e102014-11-10 15:19:26 -050022#include "libANGLE/features.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050023#include "libANGLE/renderer/Renderer.h"
Geoff Lang7dd2e102014-11-10 15:19:26 -050024#include "libANGLE/renderer/ProgramImpl.h"
Jamie Madill10750cb2015-09-04 14:23:52 -040025#include "libANGLE/queryconversions.h"
Geoff Lang7dd2e102014-11-10 15:19:26 -050026
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000027namespace gl
28{
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000029const char * const g_fakepath = "C:\\fakepath";
30
Geoff Lang7dd2e102014-11-10 15:19:26 -050031namespace
32{
33
34unsigned int ParseAndStripArrayIndex(std::string* name)
35{
36 unsigned int subscript = GL_INVALID_INDEX;
37
38 // Strip any trailing array operator and retrieve the subscript
39 size_t open = name->find_last_of('[');
40 size_t close = name->find_last_of(']');
41 if (open != std::string::npos && close == name->length() - 1)
42 {
43 subscript = atoi(name->substr(open + 1).c_str());
44 name->erase(open);
45 }
46
47 return subscript;
48}
49
Jamie Madill10750cb2015-09-04 14:23:52 -040050void WriteShaderVar(BinaryOutputStream *stream, const sh::ShaderVariable &var)
51{
52 stream->writeInt(var.type);
53 stream->writeInt(var.precision);
54 stream->writeString(var.name);
55 stream->writeString(var.mappedName);
56 stream->writeInt(var.arraySize);
57 stream->writeInt(var.staticUse);
58 stream->writeString(var.structName);
59 ASSERT(var.fields.empty());
Geoff Lang7dd2e102014-11-10 15:19:26 -050060}
61
Jamie Madill10750cb2015-09-04 14:23:52 -040062void LoadShaderVar(BinaryInputStream *stream, sh::ShaderVariable *var)
63{
64 var->type = stream->readInt<GLenum>();
65 var->precision = stream->readInt<GLenum>();
66 var->name = stream->readString();
67 var->mappedName = stream->readString();
68 var->arraySize = stream->readInt<unsigned int>();
69 var->staticUse = stream->readBool();
70 var->structName = stream->readString();
71}
72
73template <typename VarT>
74void DefineUniformBlockMembers(const std::vector<VarT> &fields,
75 const std::string &prefix,
76 int blockIndex,
77 std::vector<LinkedUniform> *uniformsOut)
78{
79 for (const VarT &field : fields)
80 {
81 const std::string &fieldName = (prefix.empty() ? field.name : prefix + "." + field.name);
82
83 if (field.isStruct())
84 {
85 for (unsigned int arrayElement = 0; arrayElement < field.elementCount(); arrayElement++)
86 {
87 const std::string uniformElementName =
88 fieldName + (field.isArray() ? ArrayString(arrayElement) : "");
89 DefineUniformBlockMembers(field.fields, uniformElementName, blockIndex,
90 uniformsOut);
91 }
92 }
93 else
94 {
95 // TODO(jmadill): record row-majorness?
96 // Block layout is recorded in the Impl.
97 LinkedUniform newUniform(field.type, field.precision, fieldName, field.arraySize,
98 blockIndex, sh::BlockMemberInfo::getDefaultBlockInfo());
99
100 // Since block uniforms have no location, we don't need to store them in the uniform
101 // locations list.
102 uniformsOut->push_back(newUniform);
103 }
104 }
105}
106
107// This simplified cast function doesn't need to worry about advanced concepts like
108// depth range values, or casting to bool.
109template <typename DestT, typename SrcT>
110DestT UniformStateQueryCast(SrcT value);
111
112// From-Float-To-Integer Casts
113template <>
114GLint UniformStateQueryCast(GLfloat value)
115{
116 return clampCast<GLint>(roundf(value));
117}
118
119template <>
120GLuint UniformStateQueryCast(GLfloat value)
121{
122 return clampCast<GLuint>(roundf(value));
123}
124
125// From-Integer-to-Integer Casts
126template <>
127GLint UniformStateQueryCast(GLuint value)
128{
129 return clampCast<GLint>(value);
130}
131
132template <>
133GLuint UniformStateQueryCast(GLint value)
134{
135 return clampCast<GLuint>(value);
136}
137
138// From-Boolean-to-Anything Casts
139template <>
140GLfloat UniformStateQueryCast(GLboolean value)
141{
142 return (value == GL_TRUE ? 1.0f : 0.0f);
143}
144
145template <>
146GLint UniformStateQueryCast(GLboolean value)
147{
148 return (value == GL_TRUE ? 1 : 0);
149}
150
151template <>
152GLuint UniformStateQueryCast(GLboolean value)
153{
154 return (value == GL_TRUE ? 1u : 0u);
155}
156
157// Default to static_cast
158template <typename DestT, typename SrcT>
159DestT UniformStateQueryCast(SrcT value)
160{
161 return static_cast<DestT>(value);
162}
163
164template <typename SrcT, typename DestT>
165void UniformStateQueryCastLoop(DestT *dataOut, const uint8_t *srcPointer, int components)
166{
167 const SrcT *typedSrcPointer = reinterpret_cast<const SrcT *>(srcPointer);
168
169 for (int comp = 0; comp < components; ++comp)
170 {
171 dataOut[comp] = UniformStateQueryCast<DestT>(typedSrcPointer[comp]);
172 }
173}
174
175} // anonymous namespace
176
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000177AttributeBindings::AttributeBindings()
178{
179}
180
181AttributeBindings::~AttributeBindings()
182{
apatrick@chromium.org9a30b092012-06-06 20:21:55 +0000183}
184
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400185InfoLog::InfoLog()
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000186{
187}
188
189InfoLog::~InfoLog()
190{
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000191}
192
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400193size_t InfoLog::getLength() const
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000194{
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400195 const std::string &logString = mStream.str();
196 return logString.empty() ? 0 : logString.length() + 1;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000197}
198
199void InfoLog::getLog(GLsizei bufSize, GLsizei *length, char *infoLog)
200{
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400201 size_t index = 0;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000202
203 if (bufSize > 0)
204 {
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400205 const std::string str(mStream.str());
206
207 if (!str.empty())
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000208 {
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400209 index = std::min(static_cast<size_t>(bufSize) - 1, str.length());
210 memcpy(infoLog, str.c_str(), index);
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000211 }
212
213 infoLog[index] = '\0';
214 }
215
216 if (length)
217 {
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400218 *length = static_cast<GLsizei>(index);
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000219 }
220}
221
222// append a santized message to the program info log.
223// The D3D compiler includes a fake file path in some of the warning or error
224// messages, so lets remove all occurrences of this fake file path from the log.
225void InfoLog::appendSanitized(const char *message)
226{
227 std::string msg(message);
228
229 size_t found;
230 do
231 {
232 found = msg.find(g_fakepath);
233 if (found != std::string::npos)
234 {
235 msg.erase(found, strlen(g_fakepath));
236 }
237 }
238 while (found != std::string::npos);
239
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400240 mStream << message << std::endl;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000241}
242
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000243void InfoLog::reset()
244{
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000245}
246
Geoff Lang7dd2e102014-11-10 15:19:26 -0500247VariableLocation::VariableLocation()
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400248 : name(),
249 element(0),
250 index(0)
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000251{
Geoff Lang7dd2e102014-11-10 15:19:26 -0500252}
253
254VariableLocation::VariableLocation(const std::string &name, unsigned int element, unsigned int index)
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400255 : name(name),
256 element(element),
257 index(index)
Geoff Lang7dd2e102014-11-10 15:19:26 -0500258{
259}
260
261LinkedVarying::LinkedVarying()
262{
263}
264
265LinkedVarying::LinkedVarying(const std::string &name, GLenum type, GLsizei size, const std::string &semanticName,
266 unsigned int semanticIndex, unsigned int semanticIndexCount)
267 : name(name), type(type), size(size), semanticName(semanticName), semanticIndex(semanticIndex), semanticIndexCount(semanticIndexCount)
268{
269}
270
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400271Program::Data::Data()
272 : mAttachedFragmentShader(nullptr),
273 mAttachedVertexShader(nullptr),
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400274 mTransformFeedbackBufferMode(GL_NONE)
275{
276}
277
278Program::Data::~Data()
279{
280 if (mAttachedVertexShader != nullptr)
281 {
282 mAttachedVertexShader->release();
283 }
284
285 if (mAttachedFragmentShader != nullptr)
286 {
287 mAttachedFragmentShader->release();
288 }
289}
290
Jamie Madill10750cb2015-09-04 14:23:52 -0400291const LinkedUniform *Program::Data::getUniformByName(const std::string &name) const
292{
293 for (const LinkedUniform &linkedUniform : mUniforms)
294 {
295 if (linkedUniform.name == name)
296 {
297 return &linkedUniform;
298 }
299 }
300
301 return nullptr;
302}
303
304GLint Program::Data::getUniformLocation(const std::string &name) const
305{
306 size_t subscript = GL_INVALID_INDEX;
307 std::string baseName = gl::ParseUniformName(name, &subscript);
308
309 for (size_t location = 0; location < mUniformLocations.size(); ++location)
310 {
311 const VariableLocation &uniformLocation = mUniformLocations[location];
312 const LinkedUniform &uniform = mUniforms[uniformLocation.index];
313
314 if (uniform.name == baseName)
315 {
316 if ((uniform.isArray() && uniformLocation.element == subscript) ||
317 (subscript == GL_INVALID_INDEX))
318 {
319 return static_cast<GLint>(location);
320 }
321 }
322 }
323
324 return -1;
325}
326
327GLuint Program::Data::getUniformIndex(const std::string &name) const
328{
329 size_t subscript = GL_INVALID_INDEX;
330 std::string baseName = gl::ParseUniformName(name, &subscript);
331
332 // The app is not allowed to specify array indices other than 0 for arrays of basic types
333 if (subscript != 0 && subscript != GL_INVALID_INDEX)
334 {
335 return GL_INVALID_INDEX;
336 }
337
338 for (size_t index = 0; index < mUniforms.size(); index++)
339 {
340 const LinkedUniform &uniform = mUniforms[index];
341 if (uniform.name == baseName)
342 {
343 if (uniform.isArray() || subscript == GL_INVALID_INDEX)
344 {
345 return static_cast<GLuint>(index);
346 }
347 }
348 }
349
350 return GL_INVALID_INDEX;
351}
352
353template <typename T>
354void Program::Data::updateUniformData(GLint location, GLsizei count, const T *v)
355{
356 const VariableLocation &locationInfo = mUniformLocations[location];
357 LinkedUniform *linkedUniform = &mUniforms[locationInfo.index];
358 uint8_t *destPointer = linkedUniform->getDataPtrToElement(locationInfo.element);
359 memcpy(destPointer, v, sizeof(T) * count);
360}
361
362template <size_t cols, size_t rows, typename T>
363void Program::Data::updateMatrixUniformData(GLint location,
364 GLsizei count,
365 GLboolean transpose,
366 const T *v)
367{
368 if (!transpose)
369 {
370 updateUniformData(location, count * cols * rows, v);
371 return;
372 }
373
374 // Perform a transposing copy.
375 const VariableLocation &locationInfo = mUniformLocations[location];
376 LinkedUniform *linkedUniform = &mUniforms[locationInfo.index];
377 T *destPtr = reinterpret_cast<T *>(linkedUniform->getDataPtrToElement(locationInfo.element));
378 for (size_t row = 0; row < rows; ++row)
379 {
380 for (size_t col = 0; col < cols; ++col)
381 {
382 destPtr[col * rows + row] = v[row * cols + col];
383 }
384 }
385}
386
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400387Program::Program(rx::ImplFactory *factory, ResourceManager *manager, GLuint handle)
388 : mProgram(factory->createProgram(mData)),
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400389 mValidated(false),
Geoff Lang7dd2e102014-11-10 15:19:26 -0500390 mLinked(false),
391 mDeleteStatus(false),
392 mRefCount(0),
393 mResourceManager(manager),
394 mHandle(handle)
395{
396 ASSERT(mProgram);
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000397
398 resetUniformBlockBindings();
Geoff Lang7dd2e102014-11-10 15:19:26 -0500399 unlink();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000400}
401
402Program::~Program()
403{
404 unlink(true);
daniel@transgaming.com71cd8682010-04-29 03:35:25 +0000405
Geoff Lang7dd2e102014-11-10 15:19:26 -0500406 SafeDelete(mProgram);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000407}
408
409bool Program::attachShader(Shader *shader)
410{
411 if (shader->getType() == GL_VERTEX_SHADER)
412 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400413 if (mData.mAttachedVertexShader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000414 {
415 return false;
416 }
417
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400418 mData.mAttachedVertexShader = shader;
419 mData.mAttachedVertexShader->addRef();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000420 }
421 else if (shader->getType() == GL_FRAGMENT_SHADER)
422 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400423 if (mData.mAttachedFragmentShader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000424 {
425 return false;
426 }
427
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400428 mData.mAttachedFragmentShader = shader;
429 mData.mAttachedFragmentShader->addRef();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000430 }
431 else UNREACHABLE();
432
433 return true;
434}
435
436bool Program::detachShader(Shader *shader)
437{
438 if (shader->getType() == GL_VERTEX_SHADER)
439 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400440 if (mData.mAttachedVertexShader != shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000441 {
442 return false;
443 }
444
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400445 shader->release();
446 mData.mAttachedVertexShader = nullptr;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000447 }
448 else if (shader->getType() == GL_FRAGMENT_SHADER)
449 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400450 if (mData.mAttachedFragmentShader != shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000451 {
452 return false;
453 }
454
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400455 shader->release();
456 mData.mAttachedFragmentShader = nullptr;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000457 }
458 else UNREACHABLE();
459
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000460 return true;
461}
462
daniel@transgaming.comcba50572010-03-28 19:36:09 +0000463int Program::getAttachedShadersCount() const
464{
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400465 return (mData.mAttachedVertexShader ? 1 : 0) + (mData.mAttachedFragmentShader ? 1 : 0);
daniel@transgaming.comcba50572010-03-28 19:36:09 +0000466}
467
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000468void AttributeBindings::bindAttributeLocation(GLuint index, const char *name)
469{
470 if (index < MAX_VERTEX_ATTRIBS)
471 {
472 for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
473 {
474 mAttributeBinding[i].erase(name);
475 }
476
477 mAttributeBinding[index].insert(name);
478 }
apatrick@chromium.org9a30b092012-06-06 20:21:55 +0000479}
480
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000481void Program::bindAttributeLocation(GLuint index, const char *name)
482{
apatrick@chromium.org9a30b092012-06-06 20:21:55 +0000483 mAttributeBindings.bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000484}
485
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000486// Links the HLSL code of the vertex and pixel shader by matching up their varyings,
487// compiling them into binaries, determining the attribute mappings, and collecting
488// a list of uniforms
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400489Error Program::link(const gl::Data &data)
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000490{
491 unlink(false);
492
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000493 mInfoLog.reset();
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000494 resetUniformBlockBindings();
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000495
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400496 if (!mData.mAttachedFragmentShader || !mData.mAttachedFragmentShader->isCompiled())
Geoff Lang7dd2e102014-11-10 15:19:26 -0500497 {
498 return Error(GL_NO_ERROR);
499 }
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400500 ASSERT(mData.mAttachedFragmentShader->getType() == GL_FRAGMENT_SHADER);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500501
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400502 if (!mData.mAttachedVertexShader || !mData.mAttachedVertexShader->isCompiled())
Geoff Lang7dd2e102014-11-10 15:19:26 -0500503 {
504 return Error(GL_NO_ERROR);
505 }
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400506 ASSERT(mData.mAttachedVertexShader->getType() == GL_VERTEX_SHADER);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500507
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400508 if (!linkAttributes(data, mInfoLog, mAttributeBindings, mData.mAttachedVertexShader))
Jamie Madill437d2662014-12-05 14:23:35 -0500509 {
510 return Error(GL_NO_ERROR);
511 }
512
Jamie Madillada9ecc2015-08-17 12:53:37 -0400513 if (!linkVaryings(mInfoLog, mData.mAttachedVertexShader, mData.mAttachedFragmentShader))
514 {
515 return Error(GL_NO_ERROR);
516 }
517
Jamie Madillea918db2015-08-18 14:48:59 -0400518 if (!linkUniforms(mInfoLog, *data.caps))
519 {
520 return Error(GL_NO_ERROR);
521 }
522
Jamie Madille473dee2015-08-18 14:49:01 -0400523 if (!linkUniformBlocks(mInfoLog, *data.caps))
524 {
525 return Error(GL_NO_ERROR);
526 }
527
Jamie Madillccdf74b2015-08-18 10:46:12 -0400528 const auto &mergedVaryings = getMergedVaryings();
529
530 if (!linkValidateTransformFeedback(mInfoLog, mergedVaryings, *data.caps))
531 {
532 return Error(GL_NO_ERROR);
533 }
534
Jamie Madill80a6fc02015-08-21 16:53:16 -0400535 linkOutputVariables();
536
Jamie Madillf5f4ad22015-09-02 18:32:38 +0000537 rx::LinkResult result = mProgram->link(data, mInfoLog);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500538 if (result.error.isError() || !result.linkSuccess)
539 {
Geoff Lang7dd2e102014-11-10 15:19:26 -0500540 return result.error;
541 }
542
Jamie Madillccdf74b2015-08-18 10:46:12 -0400543 gatherTransformFeedbackVaryings(mergedVaryings);
Jamie Madill10750cb2015-09-04 14:23:52 -0400544 mProgram->gatherUniformBlockInfo(&mData.mUniformBlocks, &mData.mUniforms);
Jamie Madillccdf74b2015-08-18 10:46:12 -0400545
Geoff Lang7dd2e102014-11-10 15:19:26 -0500546 mLinked = true;
Geoff Langb543aff2014-09-30 14:52:54 -0400547 return gl::Error(GL_NO_ERROR);
apatrick@chromium.org9a30b092012-06-06 20:21:55 +0000548}
549
apatrick@chromium.org9a30b092012-06-06 20:21:55 +0000550int AttributeBindings::getAttributeBinding(const std::string &name) const
daniel@transgaming.comb4ff1f82010-04-22 13:35:18 +0000551{
552 for (int location = 0; location < MAX_VERTEX_ATTRIBS; location++)
553 {
554 if (mAttributeBinding[location].find(name) != mAttributeBinding[location].end())
555 {
556 return location;
557 }
558 }
559
560 return -1;
561}
562
daniel@transgaming.comaa5e59b2011-10-04 18:43:12 +0000563// Returns the program object to an unlinked state, before re-linking, or at destruction
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000564void Program::unlink(bool destroy)
565{
566 if (destroy) // Object being destructed
567 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400568 if (mData.mAttachedFragmentShader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000569 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400570 mData.mAttachedFragmentShader->release();
571 mData.mAttachedFragmentShader = nullptr;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000572 }
573
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400574 if (mData.mAttachedVertexShader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000575 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400576 mData.mAttachedVertexShader->release();
577 mData.mAttachedVertexShader = nullptr;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000578 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000579 }
580
Jamie Madillc349ec02015-08-21 16:53:12 -0400581 mData.mAttributes.clear();
Jamie Madill63805b42015-08-25 13:17:39 -0400582 mData.mActiveAttribLocationsMask.reset();
Jamie Madillccdf74b2015-08-18 10:46:12 -0400583 mData.mTransformFeedbackVaryingVars.clear();
Jamie Madill10750cb2015-09-04 14:23:52 -0400584 mData.mUniforms.clear();
585 mData.mUniformLocations.clear();
586 mData.mUniformBlocks.clear();
Jamie Madill80a6fc02015-08-21 16:53:16 -0400587 mData.mOutputVariables.clear();
Geoff Lang7dd2e102014-11-10 15:19:26 -0500588
Geoff Lang7dd2e102014-11-10 15:19:26 -0500589 mValidated = false;
590
daniel@transgaming.com716056c2012-07-24 18:38:59 +0000591 mLinked = false;
592}
593
594bool Program::isLinked()
595{
596 return mLinked;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000597}
598
Geoff Lang7dd2e102014-11-10 15:19:26 -0500599Error Program::loadBinary(GLenum binaryFormat, const void *binary, GLsizei length)
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +0000600{
601 unlink(false);
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000602
Geoff Lang7dd2e102014-11-10 15:19:26 -0500603#if ANGLE_PROGRAM_BINARY_LOAD != ANGLE_ENABLED
604 return Error(GL_NO_ERROR);
605#else
606 ASSERT(binaryFormat == mProgram->getBinaryFormat());
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000607
Geoff Lang7dd2e102014-11-10 15:19:26 -0500608 BinaryInputStream stream(binary, length);
609
610 GLenum format = stream.readInt<GLenum>();
611 if (format != mProgram->getBinaryFormat())
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000612 {
Jamie Madillf6113162015-05-07 11:49:21 -0400613 mInfoLog << "Invalid program binary format.";
Geoff Lang7dd2e102014-11-10 15:19:26 -0500614 return Error(GL_NO_ERROR);
615 }
616
617 int majorVersion = stream.readInt<int>();
618 int minorVersion = stream.readInt<int>();
619 if (majorVersion != ANGLE_MAJOR_VERSION || minorVersion != ANGLE_MINOR_VERSION)
620 {
Jamie Madillf6113162015-05-07 11:49:21 -0400621 mInfoLog << "Invalid program binary version.";
Geoff Lang7dd2e102014-11-10 15:19:26 -0500622 return Error(GL_NO_ERROR);
623 }
624
625 unsigned char commitString[ANGLE_COMMIT_HASH_SIZE];
626 stream.readBytes(commitString, ANGLE_COMMIT_HASH_SIZE);
627 if (memcmp(commitString, ANGLE_COMMIT_HASH, sizeof(unsigned char) * ANGLE_COMMIT_HASH_SIZE) != 0)
628 {
Jamie Madillf6113162015-05-07 11:49:21 -0400629 mInfoLog << "Invalid program binary version.";
Geoff Lang7dd2e102014-11-10 15:19:26 -0500630 return Error(GL_NO_ERROR);
631 }
632
Jamie Madill63805b42015-08-25 13:17:39 -0400633 static_assert(MAX_VERTEX_ATTRIBS <= sizeof(unsigned long) * 8,
634 "Too many vertex attribs for mask");
635 mData.mActiveAttribLocationsMask = stream.readInt<unsigned long>();
Geoff Lang7dd2e102014-11-10 15:19:26 -0500636
Jamie Madill3da79b72015-04-27 11:09:17 -0400637 unsigned int attribCount = stream.readInt<unsigned int>();
Jamie Madillc349ec02015-08-21 16:53:12 -0400638 ASSERT(mData.mAttributes.empty());
Jamie Madill3da79b72015-04-27 11:09:17 -0400639 for (unsigned int attribIndex = 0; attribIndex < attribCount; ++attribIndex)
640 {
Jamie Madillc349ec02015-08-21 16:53:12 -0400641 sh::Attribute attrib;
Jamie Madill10750cb2015-09-04 14:23:52 -0400642 LoadShaderVar(&stream, &attrib);
643 attrib.location = stream.readInt<int>();
Jamie Madillc349ec02015-08-21 16:53:12 -0400644 mData.mAttributes.push_back(attrib);
Jamie Madill3da79b72015-04-27 11:09:17 -0400645 }
646
Jamie Madill10750cb2015-09-04 14:23:52 -0400647 unsigned int uniformCount = stream.readInt<unsigned int>();
648 ASSERT(mData.mUniforms.empty());
649 for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; ++uniformIndex)
650 {
651 LinkedUniform uniform;
652 LoadShaderVar(&stream, &uniform);
653
654 uniform.blockIndex = stream.readInt<int>();
655 uniform.blockInfo.offset = stream.readInt<int>();
656 uniform.blockInfo.arrayStride = stream.readInt<int>();
657 uniform.blockInfo.matrixStride = stream.readInt<int>();
658 uniform.blockInfo.isRowMajorMatrix = stream.readBool();
659
660 mData.mUniforms.push_back(uniform);
661 }
662
663 const unsigned int uniformIndexCount = stream.readInt<unsigned int>();
664 ASSERT(mData.mUniformLocations.empty());
665 for (unsigned int uniformIndexIndex = 0; uniformIndexIndex < uniformIndexCount;
666 uniformIndexIndex++)
667 {
668 VariableLocation variable;
669 stream.readString(&variable.name);
670 stream.readInt(&variable.element);
671 stream.readInt(&variable.index);
672
673 mData.mUniformLocations.push_back(variable);
674 }
675
676 unsigned int uniformBlockCount = stream.readInt<unsigned int>();
677 ASSERT(mData.mUniformBlocks.empty());
678 for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < uniformBlockCount;
679 ++uniformBlockIndex)
680 {
681 UniformBlock uniformBlock;
682 stream.readString(&uniformBlock.name);
683 stream.readBool(&uniformBlock.isArray);
684 stream.readInt(&uniformBlock.arrayElement);
685 stream.readInt(&uniformBlock.dataSize);
686 stream.readBool(&uniformBlock.vertexStaticUse);
687 stream.readBool(&uniformBlock.fragmentStaticUse);
688
689 unsigned int numMembers = stream.readInt<unsigned int>();
690 for (unsigned int blockMemberIndex = 0; blockMemberIndex < numMembers; blockMemberIndex++)
691 {
692 uniformBlock.memberUniformIndexes.push_back(stream.readInt<unsigned int>());
693 }
694
695 // TODO(jmadill): Make D3D-only
696 stream.readInt(&uniformBlock.psRegisterIndex);
697 stream.readInt(&uniformBlock.vsRegisterIndex);
698
699 mData.mUniformBlocks.push_back(uniformBlock);
700 }
701
Jamie Madillada9ecc2015-08-17 12:53:37 -0400702 stream.readInt(&mData.mTransformFeedbackBufferMode);
703
Jamie Madill80a6fc02015-08-21 16:53:16 -0400704 unsigned int outputVarCount = stream.readInt<unsigned int>();
705 for (unsigned int outputIndex = 0; outputIndex < outputVarCount; ++outputIndex)
706 {
707 int locationIndex = stream.readInt<int>();
708 VariableLocation locationData;
709 locationData.element = stream.readInt<unsigned int>();
710 locationData.index = stream.readInt<unsigned int>();
711 locationData.name = stream.readString();
712 mData.mOutputVariables[locationIndex] = locationData;
713 }
714
Geoff Lang7dd2e102014-11-10 15:19:26 -0500715 rx::LinkResult result = mProgram->load(mInfoLog, &stream);
716 if (result.error.isError() || !result.linkSuccess)
717 {
Geoff Langb543aff2014-09-30 14:52:54 -0400718 return result.error;
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000719 }
daniel@transgaming.com4c962bf2012-07-24 18:37:02 +0000720
Geoff Lang7dd2e102014-11-10 15:19:26 -0500721 mLinked = true;
Geoff Langb543aff2014-09-30 14:52:54 -0400722 return Error(GL_NO_ERROR);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500723#endif // #if ANGLE_PROGRAM_BINARY_LOAD == ANGLE_ENABLED
724}
725
726Error Program::saveBinary(GLenum *binaryFormat, void *binary, GLsizei bufSize, GLsizei *length) const
727{
728 if (binaryFormat)
729 {
730 *binaryFormat = mProgram->getBinaryFormat();
731 }
732
733 BinaryOutputStream stream;
734
735 stream.writeInt(mProgram->getBinaryFormat());
736 stream.writeInt(ANGLE_MAJOR_VERSION);
737 stream.writeInt(ANGLE_MINOR_VERSION);
738 stream.writeBytes(reinterpret_cast<const unsigned char*>(ANGLE_COMMIT_HASH), ANGLE_COMMIT_HASH_SIZE);
739
Jamie Madill63805b42015-08-25 13:17:39 -0400740 stream.writeInt(mData.mActiveAttribLocationsMask.to_ulong());
Geoff Lang7dd2e102014-11-10 15:19:26 -0500741
Jamie Madillc349ec02015-08-21 16:53:12 -0400742 stream.writeInt(mData.mAttributes.size());
743 for (const sh::Attribute &attrib : mData.mAttributes)
Jamie Madill3da79b72015-04-27 11:09:17 -0400744 {
Jamie Madill10750cb2015-09-04 14:23:52 -0400745 WriteShaderVar(&stream, attrib);
Jamie Madill3da79b72015-04-27 11:09:17 -0400746 stream.writeInt(attrib.location);
Jamie Madill10750cb2015-09-04 14:23:52 -0400747 }
748
749 stream.writeInt(mData.mUniforms.size());
750 for (const gl::LinkedUniform &uniform : mData.mUniforms)
751 {
752 WriteShaderVar(&stream, uniform);
753
754 // FIXME: referenced
755
756 stream.writeInt(uniform.blockIndex);
757 stream.writeInt(uniform.blockInfo.offset);
758 stream.writeInt(uniform.blockInfo.arrayStride);
759 stream.writeInt(uniform.blockInfo.matrixStride);
760 stream.writeInt(uniform.blockInfo.isRowMajorMatrix);
761 }
762
763 stream.writeInt(mData.mUniformLocations.size());
764 for (const auto &variable : mData.mUniformLocations)
765 {
766 stream.writeString(variable.name);
767 stream.writeInt(variable.element);
768 stream.writeInt(variable.index);
769 }
770
771 stream.writeInt(mData.mUniformBlocks.size());
772 for (const UniformBlock &uniformBlock : mData.mUniformBlocks)
773 {
774 stream.writeString(uniformBlock.name);
775 stream.writeInt(uniformBlock.isArray);
776 stream.writeInt(uniformBlock.arrayElement);
777 stream.writeInt(uniformBlock.dataSize);
778
779 stream.writeInt(uniformBlock.vertexStaticUse);
780 stream.writeInt(uniformBlock.fragmentStaticUse);
781
782 stream.writeInt(uniformBlock.memberUniformIndexes.size());
783 for (unsigned int memberUniformIndex : uniformBlock.memberUniformIndexes)
784 {
785 stream.writeInt(memberUniformIndex);
786 }
787
788 // TODO(jmadill): make D3D-only
789 stream.writeInt(uniformBlock.psRegisterIndex);
790 stream.writeInt(uniformBlock.vsRegisterIndex);
Jamie Madill3da79b72015-04-27 11:09:17 -0400791 }
792
Jamie Madillada9ecc2015-08-17 12:53:37 -0400793 stream.writeInt(mData.mTransformFeedbackBufferMode);
794
Jamie Madill80a6fc02015-08-21 16:53:16 -0400795 stream.writeInt(mData.mOutputVariables.size());
796 for (const auto &outputPair : mData.mOutputVariables)
797 {
798 stream.writeInt(outputPair.first);
799 stream.writeInt(outputPair.second.element);
800 stream.writeInt(outputPair.second.index);
801 stream.writeString(outputPair.second.name);
802 }
803
Geoff Lang7dd2e102014-11-10 15:19:26 -0500804 gl::Error error = mProgram->save(&stream);
805 if (error.isError())
806 {
807 return error;
808 }
809
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700810 GLsizei streamLength = static_cast<GLsizei>(stream.length());
Geoff Lang7dd2e102014-11-10 15:19:26 -0500811 const void *streamData = stream.data();
812
813 if (streamLength > bufSize)
814 {
815 if (length)
816 {
817 *length = 0;
818 }
819
820 // TODO: This should be moved to the validation layer but computing the size of the binary before saving
821 // it causes the save to happen twice. It may be possible to write the binary to a separate buffer, validate
822 // sizes and then copy it.
823 return Error(GL_INVALID_OPERATION);
824 }
825
826 if (binary)
827 {
828 char *ptr = reinterpret_cast<char*>(binary);
829
830 memcpy(ptr, streamData, streamLength);
831 ptr += streamLength;
832
833 ASSERT(ptr - streamLength == binary);
834 }
835
836 if (length)
837 {
838 *length = streamLength;
839 }
840
841 return Error(GL_NO_ERROR);
842}
843
844GLint Program::getBinaryLength() const
845{
846 GLint length;
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400847 Error error = saveBinary(nullptr, nullptr, std::numeric_limits<GLint>::max(), &length);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500848 if (error.isError())
849 {
850 return 0;
851 }
852
853 return length;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +0000854}
855
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000856void Program::release()
857{
858 mRefCount--;
859
860 if (mRefCount == 0 && mDeleteStatus)
861 {
862 mResourceManager->deleteProgram(mHandle);
863 }
864}
865
866void Program::addRef()
867{
868 mRefCount++;
869}
870
871unsigned int Program::getRefCount() const
872{
873 return mRefCount;
874}
875
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000876int Program::getInfoLogLength() const
877{
Jamie Madill71c3b2c2015-05-07 11:49:20 -0400878 return static_cast<int>(mInfoLog.getLength());
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000879}
880
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000881void Program::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog)
882{
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000883 return mInfoLog.getLog(bufSize, length, infoLog);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000884}
885
daniel@transgaming.com6c785212010-03-30 03:36:17 +0000886void Program::getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders)
887{
888 int total = 0;
889
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400890 if (mData.mAttachedVertexShader)
daniel@transgaming.com6c785212010-03-30 03:36:17 +0000891 {
892 if (total < maxCount)
893 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400894 shaders[total] = mData.mAttachedVertexShader->getHandle();
daniel@transgaming.com6c785212010-03-30 03:36:17 +0000895 }
896
897 total++;
898 }
899
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400900 if (mData.mAttachedFragmentShader)
daniel@transgaming.com6c785212010-03-30 03:36:17 +0000901 {
902 if (total < maxCount)
903 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -0400904 shaders[total] = mData.mAttachedFragmentShader->getHandle();
daniel@transgaming.com6c785212010-03-30 03:36:17 +0000905 }
906
907 total++;
908 }
909
910 if (count)
911 {
912 *count = total;
913 }
914}
915
Geoff Lang7dd2e102014-11-10 15:19:26 -0500916GLuint Program::getAttributeLocation(const std::string &name)
917{
Jamie Madillc349ec02015-08-21 16:53:12 -0400918 for (const sh::Attribute &attribute : mData.mAttributes)
Geoff Lang7dd2e102014-11-10 15:19:26 -0500919 {
Jamie Madillc349ec02015-08-21 16:53:12 -0400920 if (attribute.name == name && attribute.staticUse)
Geoff Lang7dd2e102014-11-10 15:19:26 -0500921 {
Jamie Madillc349ec02015-08-21 16:53:12 -0400922 return attribute.location;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500923 }
924 }
925
Austin Kinrossb8af7232015-03-16 22:33:25 -0700926 return static_cast<GLuint>(-1);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500927}
928
Jamie Madill63805b42015-08-25 13:17:39 -0400929bool Program::isAttribLocationActive(size_t attribLocation) const
Jamie Madill56c6e3c2015-04-15 10:18:05 -0400930{
Olli Etuaho401d9fe2015-08-26 10:19:59 +0300931 ASSERT(attribLocation < mData.mActiveAttribLocationsMask.size());
Jamie Madill63805b42015-08-25 13:17:39 -0400932 return mData.mActiveAttribLocationsMask[attribLocation];
Geoff Lang7dd2e102014-11-10 15:19:26 -0500933}
934
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000935void Program::getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
936{
Jamie Madillc349ec02015-08-21 16:53:12 -0400937 if (!mLinked)
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000938 {
939 if (bufsize > 0)
940 {
941 name[0] = '\0';
942 }
Geoff Lang7dd2e102014-11-10 15:19:26 -0500943
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000944 if (length)
945 {
946 *length = 0;
947 }
948
949 *type = GL_NONE;
950 *size = 1;
Jamie Madillc349ec02015-08-21 16:53:12 -0400951 return;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000952 }
Jamie Madillc349ec02015-08-21 16:53:12 -0400953
954 size_t attributeIndex = 0;
955
956 for (const sh::Attribute &attribute : mData.mAttributes)
957 {
958 // Skip over inactive attributes
959 if (attribute.staticUse)
960 {
961 if (static_cast<size_t>(index) == attributeIndex)
962 {
963 break;
964 }
965 attributeIndex++;
966 }
967 }
968
969 ASSERT(index == attributeIndex && attributeIndex < mData.mAttributes.size());
970 const sh::Attribute &attrib = mData.mAttributes[attributeIndex];
971
972 if (bufsize > 0)
973 {
974 const char *string = attrib.name.c_str();
975
976 strncpy(name, string, bufsize);
977 name[bufsize - 1] = '\0';
978
979 if (length)
980 {
981 *length = static_cast<GLsizei>(strlen(name));
982 }
983 }
984
985 // Always a single 'type' instance
986 *size = 1;
987 *type = attrib.type;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000988}
989
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000990GLint Program::getActiveAttributeCount()
991{
Jamie Madillc349ec02015-08-21 16:53:12 -0400992 if (!mLinked)
Jamie Madill2d773182015-08-18 10:27:28 -0400993 {
Jamie Madillc349ec02015-08-21 16:53:12 -0400994 return 0;
995 }
996
997 GLint count = 0;
998
999 for (const sh::Attribute &attrib : mData.mAttributes)
1000 {
1001 count += (attrib.staticUse ? 1 : 0);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001002 }
Geoff Lang7dd2e102014-11-10 15:19:26 -05001003
1004 return count;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001005}
1006
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001007GLint Program::getActiveAttributeMaxLength()
1008{
Jamie Madillc349ec02015-08-21 16:53:12 -04001009 if (!mLinked)
Jamie Madill2d773182015-08-18 10:27:28 -04001010 {
Jamie Madillc349ec02015-08-21 16:53:12 -04001011 return 0;
1012 }
1013
1014 size_t maxLength = 0;
1015
1016 for (const sh::Attribute &attrib : mData.mAttributes)
1017 {
1018 if (attrib.staticUse)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001019 {
Jamie Madillc349ec02015-08-21 16:53:12 -04001020 maxLength = std::max(attrib.name.length() + 1, maxLength);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001021 }
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001022 }
Geoff Lang7dd2e102014-11-10 15:19:26 -05001023
Jamie Madillc349ec02015-08-21 16:53:12 -04001024 return static_cast<GLint>(maxLength);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001025}
1026
Geoff Lang7dd2e102014-11-10 15:19:26 -05001027GLint Program::getFragDataLocation(const std::string &name) const
1028{
1029 std::string baseName(name);
1030 unsigned int arrayIndex = ParseAndStripArrayIndex(&baseName);
Jamie Madill80a6fc02015-08-21 16:53:16 -04001031 for (auto outputPair : mData.mOutputVariables)
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001032 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -04001033 const VariableLocation &outputVariable = outputPair.second;
Geoff Lang7dd2e102014-11-10 15:19:26 -05001034 if (outputVariable.name == baseName && (arrayIndex == GL_INVALID_INDEX || arrayIndex == outputVariable.element))
1035 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -04001036 return static_cast<GLint>(outputPair.first);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001037 }
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001038 }
Geoff Lang7dd2e102014-11-10 15:19:26 -05001039 return -1;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001040}
1041
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001042void Program::getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
1043{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001044 if (mLinked)
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001045 {
Jamie Madill10750cb2015-09-04 14:23:52 -04001046 // index must be smaller than getActiveUniformCount()
1047 ASSERT(index < mData.mUniforms.size());
1048 const LinkedUniform &uniform = mData.mUniforms[index];
Geoff Lang7dd2e102014-11-10 15:19:26 -05001049
1050 if (bufsize > 0)
1051 {
Jamie Madill10750cb2015-09-04 14:23:52 -04001052 std::string string = uniform.name;
1053 if (uniform.isArray())
Geoff Lang7dd2e102014-11-10 15:19:26 -05001054 {
1055 string += "[0]";
1056 }
1057
1058 strncpy(name, string.c_str(), bufsize);
1059 name[bufsize - 1] = '\0';
1060
1061 if (length)
1062 {
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001063 *length = static_cast<GLsizei>(strlen(name));
Geoff Lang7dd2e102014-11-10 15:19:26 -05001064 }
1065 }
1066
Jamie Madill10750cb2015-09-04 14:23:52 -04001067 *size = uniform.elementCount();
1068 *type = uniform.type;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001069 }
1070 else
1071 {
1072 if (bufsize > 0)
1073 {
1074 name[0] = '\0';
1075 }
1076
1077 if (length)
1078 {
1079 *length = 0;
1080 }
1081
1082 *size = 0;
1083 *type = GL_NONE;
1084 }
1085}
1086
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001087GLint Program::getActiveUniformCount()
1088{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001089 if (mLinked)
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001090 {
Jamie Madill10750cb2015-09-04 14:23:52 -04001091 return static_cast<GLint>(mData.mUniforms.size());
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001092 }
1093 else
1094 {
1095 return 0;
1096 }
1097}
1098
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001099GLint Program::getActiveUniformMaxLength()
1100{
Jamie Madill10750cb2015-09-04 14:23:52 -04001101 size_t maxLength = 0;
Geoff Lang7dd2e102014-11-10 15:19:26 -05001102
1103 if (mLinked)
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001104 {
Jamie Madill10750cb2015-09-04 14:23:52 -04001105 for (const LinkedUniform &uniform : mData.mUniforms)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001106 {
Jamie Madill10750cb2015-09-04 14:23:52 -04001107 if (!uniform.name.empty())
Geoff Lang7dd2e102014-11-10 15:19:26 -05001108 {
Jamie Madill10750cb2015-09-04 14:23:52 -04001109 size_t length = uniform.name.length() + 1u;
1110 if (uniform.isArray())
Geoff Lang7dd2e102014-11-10 15:19:26 -05001111 {
1112 length += 3; // Counting in "[0]".
1113 }
1114 maxLength = std::max(length, maxLength);
1115 }
1116 }
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001117 }
Geoff Lang7dd2e102014-11-10 15:19:26 -05001118
Jamie Madill10750cb2015-09-04 14:23:52 -04001119 return static_cast<GLint>(maxLength);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001120}
1121
1122GLint Program::getActiveUniformi(GLuint index, GLenum pname) const
1123{
Jamie Madill10750cb2015-09-04 14:23:52 -04001124 ASSERT(static_cast<size_t>(index) < mData.mUniforms.size());
1125 const gl::LinkedUniform &uniform = mData.mUniforms[index];
Geoff Lang7dd2e102014-11-10 15:19:26 -05001126 switch (pname)
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001127 {
Geoff Lang7dd2e102014-11-10 15:19:26 -05001128 case GL_UNIFORM_TYPE: return static_cast<GLint>(uniform.type);
1129 case GL_UNIFORM_SIZE: return static_cast<GLint>(uniform.elementCount());
1130 case GL_UNIFORM_NAME_LENGTH: return static_cast<GLint>(uniform.name.size() + 1 + (uniform.isArray() ? 3 : 0));
1131 case GL_UNIFORM_BLOCK_INDEX: return uniform.blockIndex;
1132 case GL_UNIFORM_OFFSET: return uniform.blockInfo.offset;
1133 case GL_UNIFORM_ARRAY_STRIDE: return uniform.blockInfo.arrayStride;
1134 case GL_UNIFORM_MATRIX_STRIDE: return uniform.blockInfo.matrixStride;
1135 case GL_UNIFORM_IS_ROW_MAJOR: return static_cast<GLint>(uniform.blockInfo.isRowMajorMatrix);
1136 default:
1137 UNREACHABLE();
1138 break;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001139 }
Geoff Lang7dd2e102014-11-10 15:19:26 -05001140 return 0;
1141}
1142
1143bool Program::isValidUniformLocation(GLint location) const
1144{
Jamie Madill10750cb2015-09-04 14:23:52 -04001145 ASSERT(rx::IsIntegerCastSafe<GLint>(mData.mUniformLocations.size()));
1146 return (location >= 0 && static_cast<size_t>(location) < mData.mUniformLocations.size());
Geoff Lang7dd2e102014-11-10 15:19:26 -05001147}
1148
Jamie Madill10750cb2015-09-04 14:23:52 -04001149const LinkedUniform &Program::getUniformByLocation(GLint location) const
Geoff Lang7dd2e102014-11-10 15:19:26 -05001150{
Jamie Madill10750cb2015-09-04 14:23:52 -04001151 ASSERT(location >= 0 && static_cast<size_t>(location) < mData.mUniformLocations.size());
1152 return mData.mUniforms[mData.mUniformLocations[location].index];
Geoff Lang7dd2e102014-11-10 15:19:26 -05001153}
1154
Jamie Madill10750cb2015-09-04 14:23:52 -04001155GLint Program::getUniformLocation(const std::string &name) const
Geoff Lang7dd2e102014-11-10 15:19:26 -05001156{
Jamie Madill10750cb2015-09-04 14:23:52 -04001157 return mData.getUniformLocation(name);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001158}
1159
Jamie Madill10750cb2015-09-04 14:23:52 -04001160GLuint Program::getUniformIndex(const std::string &name) const
Geoff Lang7dd2e102014-11-10 15:19:26 -05001161{
Jamie Madill10750cb2015-09-04 14:23:52 -04001162 return mData.getUniformIndex(name);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001163}
1164
1165void Program::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
1166{
Jamie Madill10750cb2015-09-04 14:23:52 -04001167 mData.updateUniformData(location, count * 1, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001168 mProgram->setUniform1fv(location, count, v);
1169}
1170
1171void Program::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
1172{
Jamie Madill10750cb2015-09-04 14:23:52 -04001173 mData.updateUniformData(location, count * 2, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001174 mProgram->setUniform2fv(location, count, v);
1175}
1176
1177void Program::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
1178{
Jamie Madill10750cb2015-09-04 14:23:52 -04001179 mData.updateUniformData(location, count * 3, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001180 mProgram->setUniform3fv(location, count, v);
1181}
1182
1183void Program::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
1184{
Jamie Madill10750cb2015-09-04 14:23:52 -04001185 mData.updateUniformData(location, count * 4, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001186 mProgram->setUniform4fv(location, count, v);
1187}
1188
1189void Program::setUniform1iv(GLint location, GLsizei count, const GLint *v)
1190{
Jamie Madill10750cb2015-09-04 14:23:52 -04001191 mData.updateUniformData(location, count * 1, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001192 mProgram->setUniform1iv(location, count, v);
1193}
1194
1195void Program::setUniform2iv(GLint location, GLsizei count, const GLint *v)
1196{
Jamie Madill10750cb2015-09-04 14:23:52 -04001197 mData.updateUniformData(location, count * 2, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001198 mProgram->setUniform2iv(location, count, v);
1199}
1200
1201void Program::setUniform3iv(GLint location, GLsizei count, const GLint *v)
1202{
Jamie Madill10750cb2015-09-04 14:23:52 -04001203 mData.updateUniformData(location, count * 3, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001204 mProgram->setUniform3iv(location, count, v);
1205}
1206
1207void Program::setUniform4iv(GLint location, GLsizei count, const GLint *v)
1208{
Jamie Madill10750cb2015-09-04 14:23:52 -04001209 mData.updateUniformData(location, count * 4, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001210 mProgram->setUniform4iv(location, count, v);
1211}
1212
1213void Program::setUniform1uiv(GLint location, GLsizei count, const GLuint *v)
1214{
Jamie Madill10750cb2015-09-04 14:23:52 -04001215 mData.updateUniformData(location, count * 1, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001216 mProgram->setUniform1uiv(location, count, v);
1217}
1218
1219void Program::setUniform2uiv(GLint location, GLsizei count, const GLuint *v)
1220{
Jamie Madill10750cb2015-09-04 14:23:52 -04001221 mData.updateUniformData(location, count * 2, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001222 mProgram->setUniform2uiv(location, count, v);
1223}
1224
1225void Program::setUniform3uiv(GLint location, GLsizei count, const GLuint *v)
1226{
Jamie Madill10750cb2015-09-04 14:23:52 -04001227 mData.updateUniformData(location, count * 3, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001228 mProgram->setUniform3uiv(location, count, v);
1229}
1230
1231void Program::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
1232{
Jamie Madill10750cb2015-09-04 14:23:52 -04001233 mData.updateUniformData(location, count * 4, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001234 mProgram->setUniform4uiv(location, count, v);
1235}
1236
1237void Program::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v)
1238{
Jamie Madill10750cb2015-09-04 14:23:52 -04001239 mData.updateMatrixUniformData<2, 2>(location, count, transpose, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001240 mProgram->setUniformMatrix2fv(location, count, transpose, v);
1241}
1242
1243void Program::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v)
1244{
Jamie Madill10750cb2015-09-04 14:23:52 -04001245 mData.updateMatrixUniformData<3, 3>(location, count, transpose, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001246 mProgram->setUniformMatrix3fv(location, count, transpose, v);
1247}
1248
1249void Program::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v)
1250{
Jamie Madill10750cb2015-09-04 14:23:52 -04001251 mData.updateMatrixUniformData<4, 4>(location, count, transpose, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001252 mProgram->setUniformMatrix4fv(location, count, transpose, v);
1253}
1254
1255void Program::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v)
1256{
Jamie Madill10750cb2015-09-04 14:23:52 -04001257 mData.updateMatrixUniformData<2, 3>(location, count, transpose, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001258 mProgram->setUniformMatrix2x3fv(location, count, transpose, v);
1259}
1260
1261void Program::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v)
1262{
Jamie Madill10750cb2015-09-04 14:23:52 -04001263 mData.updateMatrixUniformData<2, 4>(location, count, transpose, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001264 mProgram->setUniformMatrix2x4fv(location, count, transpose, v);
1265}
1266
1267void Program::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v)
1268{
Jamie Madill10750cb2015-09-04 14:23:52 -04001269 mData.updateMatrixUniformData<3, 2>(location, count, transpose, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001270 mProgram->setUniformMatrix3x2fv(location, count, transpose, v);
1271}
1272
1273void Program::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v)
1274{
Jamie Madill10750cb2015-09-04 14:23:52 -04001275 mData.updateMatrixUniformData<3, 4>(location, count, transpose, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001276 mProgram->setUniformMatrix3x4fv(location, count, transpose, v);
1277}
1278
1279void Program::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v)
1280{
Jamie Madill10750cb2015-09-04 14:23:52 -04001281 mData.updateMatrixUniformData<4, 2>(location, count, transpose, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001282 mProgram->setUniformMatrix4x2fv(location, count, transpose, v);
1283}
1284
1285void Program::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v)
1286{
Jamie Madill10750cb2015-09-04 14:23:52 -04001287 mData.updateMatrixUniformData<4, 3>(location, count, transpose, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001288 mProgram->setUniformMatrix4x3fv(location, count, transpose, v);
1289}
1290
1291void Program::getUniformfv(GLint location, GLfloat *v)
1292{
Jamie Madill10750cb2015-09-04 14:23:52 -04001293 getUniformInternal(location, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001294}
1295
1296void Program::getUniformiv(GLint location, GLint *v)
1297{
Jamie Madill10750cb2015-09-04 14:23:52 -04001298 getUniformInternal(location, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001299}
1300
1301void Program::getUniformuiv(GLint location, GLuint *v)
1302{
Jamie Madill10750cb2015-09-04 14:23:52 -04001303 getUniformInternal(location, v);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001304}
1305
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001306void Program::flagForDeletion()
1307{
1308 mDeleteStatus = true;
1309}
1310
1311bool Program::isFlaggedForDeletion() const
1312{
1313 return mDeleteStatus;
1314}
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00001315
Brandon Jones43a53e22014-08-28 16:23:22 -07001316void Program::validate(const Caps &caps)
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00001317{
1318 mInfoLog.reset();
1319
Geoff Lang7dd2e102014-11-10 15:19:26 -05001320 if (mLinked)
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00001321 {
Jamie Madill36cfd6a2015-08-18 10:46:20 -04001322 mValidated = (mProgram->validate(caps, &mInfoLog) == GL_TRUE);
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00001323 }
1324 else
1325 {
Jamie Madillf6113162015-05-07 11:49:21 -04001326 mInfoLog << "Program has not been successfully linked.";
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00001327 }
1328}
1329
Geoff Lang7dd2e102014-11-10 15:19:26 -05001330bool Program::validateSamplers(InfoLog *infoLog, const Caps &caps)
1331{
1332 return mProgram->validateSamplers(infoLog, caps);
1333}
1334
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001335bool Program::isValidated() const
1336{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001337 return mValidated;
1338}
1339
Geoff Lang7dd2e102014-11-10 15:19:26 -05001340GLuint Program::getActiveUniformBlockCount()
1341{
Jamie Madill10750cb2015-09-04 14:23:52 -04001342 return static_cast<GLuint>(mData.mUniformBlocks.size());
Geoff Lang7dd2e102014-11-10 15:19:26 -05001343}
1344
1345void Program::getActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName) const
1346{
Jamie Madill10750cb2015-09-04 14:23:52 -04001347 ASSERT(uniformBlockIndex <
1348 mData.mUniformBlocks.size()); // index must be smaller than getActiveUniformBlockCount()
Geoff Lang7dd2e102014-11-10 15:19:26 -05001349
Jamie Madill10750cb2015-09-04 14:23:52 -04001350 const UniformBlock &uniformBlock = mData.mUniformBlocks[uniformBlockIndex];
Geoff Lang7dd2e102014-11-10 15:19:26 -05001351
1352 if (bufSize > 0)
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001353 {
Geoff Lang7dd2e102014-11-10 15:19:26 -05001354 std::string string = uniformBlock.name;
1355
Jamie Madill10750cb2015-09-04 14:23:52 -04001356 if (uniformBlock.isArray)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001357 {
Jamie Madill10750cb2015-09-04 14:23:52 -04001358 string += ArrayString(uniformBlock.arrayElement);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001359 }
1360
1361 strncpy(uniformBlockName, string.c_str(), bufSize);
1362 uniformBlockName[bufSize - 1] = '\0';
1363
1364 if (length)
1365 {
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001366 *length = static_cast<GLsizei>(strlen(uniformBlockName));
Geoff Lang7dd2e102014-11-10 15:19:26 -05001367 }
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00001368 }
1369}
1370
Geoff Lang7dd2e102014-11-10 15:19:26 -05001371void Program::getActiveUniformBlockiv(GLuint uniformBlockIndex, GLenum pname, GLint *params) const
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00001372{
Jamie Madill10750cb2015-09-04 14:23:52 -04001373 ASSERT(uniformBlockIndex <
1374 mData.mUniformBlocks.size()); // index must be smaller than getActiveUniformBlockCount()
Geoff Lang7dd2e102014-11-10 15:19:26 -05001375
Jamie Madill10750cb2015-09-04 14:23:52 -04001376 const UniformBlock &uniformBlock = mData.mUniformBlocks[uniformBlockIndex];
Geoff Lang7dd2e102014-11-10 15:19:26 -05001377
1378 switch (pname)
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00001379 {
Geoff Lang7dd2e102014-11-10 15:19:26 -05001380 case GL_UNIFORM_BLOCK_DATA_SIZE:
1381 *params = static_cast<GLint>(uniformBlock.dataSize);
1382 break;
1383 case GL_UNIFORM_BLOCK_NAME_LENGTH:
Jamie Madill10750cb2015-09-04 14:23:52 -04001384 *params =
1385 static_cast<GLint>(uniformBlock.name.size() + 1 + (uniformBlock.isArray ? 3 : 0));
Geoff Lang7dd2e102014-11-10 15:19:26 -05001386 break;
1387 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
1388 *params = static_cast<GLint>(uniformBlock.memberUniformIndexes.size());
1389 break;
1390 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
1391 {
1392 for (unsigned int blockMemberIndex = 0; blockMemberIndex < uniformBlock.memberUniformIndexes.size(); blockMemberIndex++)
1393 {
1394 params[blockMemberIndex] = static_cast<GLint>(uniformBlock.memberUniformIndexes[blockMemberIndex]);
1395 }
1396 }
1397 break;
1398 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
Jamie Madill10750cb2015-09-04 14:23:52 -04001399 *params = static_cast<GLint>(uniformBlock.vertexStaticUse);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001400 break;
1401 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
Jamie Madill10750cb2015-09-04 14:23:52 -04001402 *params = static_cast<GLint>(uniformBlock.fragmentStaticUse);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001403 break;
1404 default: UNREACHABLE();
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00001405 }
1406}
1407
1408GLint Program::getActiveUniformBlockMaxLength()
1409{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001410 int maxLength = 0;
1411
1412 if (mLinked)
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00001413 {
Jamie Madill10750cb2015-09-04 14:23:52 -04001414 unsigned int numUniformBlocks = static_cast<unsigned int>(mData.mUniformBlocks.size());
Geoff Lang7dd2e102014-11-10 15:19:26 -05001415 for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < numUniformBlocks; uniformBlockIndex++)
1416 {
Jamie Madill10750cb2015-09-04 14:23:52 -04001417 const UniformBlock &uniformBlock = mData.mUniformBlocks[uniformBlockIndex];
Geoff Lang7dd2e102014-11-10 15:19:26 -05001418 if (!uniformBlock.name.empty())
1419 {
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001420 const int length = static_cast<int>(uniformBlock.name.length()) + 1;
Geoff Lang7dd2e102014-11-10 15:19:26 -05001421
1422 // Counting in "[0]".
Jamie Madill10750cb2015-09-04 14:23:52 -04001423 const int arrayLength = (uniformBlock.isArray ? 3 : 0);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001424
1425 maxLength = std::max(length + arrayLength, maxLength);
1426 }
1427 }
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00001428 }
Geoff Lang7dd2e102014-11-10 15:19:26 -05001429
1430 return maxLength;
1431}
1432
1433GLuint Program::getUniformBlockIndex(const std::string &name)
1434{
Jamie Madill10750cb2015-09-04 14:23:52 -04001435 size_t subscript = GL_INVALID_INDEX;
1436 std::string baseName = gl::ParseUniformName(name, &subscript);
1437
1438 unsigned int numUniformBlocks = static_cast<unsigned int>(mData.mUniformBlocks.size());
1439 for (unsigned int blockIndex = 0; blockIndex < numUniformBlocks; blockIndex++)
1440 {
1441 const gl::UniformBlock &uniformBlock = mData.mUniformBlocks[blockIndex];
1442 if (uniformBlock.name == baseName)
1443 {
1444 const bool arrayElementZero =
1445 (subscript == GL_INVALID_INDEX &&
1446 (!uniformBlock.isArray || uniformBlock.arrayElement == 0));
1447 if (subscript == uniformBlock.arrayElement || arrayElementZero)
1448 {
1449 return blockIndex;
1450 }
1451 }
1452 }
1453
1454 return GL_INVALID_INDEX;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00001455}
1456
Jamie Madill10750cb2015-09-04 14:23:52 -04001457const UniformBlock &Program::getUniformBlockByIndex(GLuint index) const
Gregoire Payen de La Garanderie68694e92015-03-24 14:03:37 +00001458{
Jamie Madill10750cb2015-09-04 14:23:52 -04001459 ASSERT(index < static_cast<GLuint>(mData.mUniformBlocks.size()));
1460 return mData.mUniformBlocks[index];
Gregoire Payen de La Garanderie68694e92015-03-24 14:03:37 +00001461}
1462
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00001463void Program::bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding)
1464{
Jamie Madilld1fe1642015-08-21 16:26:04 -04001465 mData.mUniformBlockBindings[uniformBlockIndex] = uniformBlockBinding;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00001466}
1467
1468GLuint Program::getUniformBlockBinding(GLuint uniformBlockIndex) const
1469{
Jamie Madilld1fe1642015-08-21 16:26:04 -04001470 return mData.getUniformBlockBinding(uniformBlockIndex);
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00001471}
1472
1473void Program::resetUniformBlockBindings()
1474{
1475 for (unsigned int blockId = 0; blockId < IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS; blockId++)
1476 {
Jamie Madilld1fe1642015-08-21 16:26:04 -04001477 mData.mUniformBlockBindings[blockId] = 0;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00001478 }
1479}
1480
Geoff Lang48dcae72014-02-05 16:28:24 -05001481void Program::setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode)
1482{
Jamie Madillccdf74b2015-08-18 10:46:12 -04001483 mData.mTransformFeedbackVaryingNames.resize(count);
Geoff Lang48dcae72014-02-05 16:28:24 -05001484 for (GLsizei i = 0; i < count; i++)
1485 {
Jamie Madillccdf74b2015-08-18 10:46:12 -04001486 mData.mTransformFeedbackVaryingNames[i] = varyings[i];
Geoff Lang48dcae72014-02-05 16:28:24 -05001487 }
1488
Jamie Madill5c6b7bf2015-08-17 12:53:35 -04001489 mData.mTransformFeedbackBufferMode = bufferMode;
Geoff Lang48dcae72014-02-05 16:28:24 -05001490}
1491
1492void Program::getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const
1493{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001494 if (mLinked)
Geoff Lang48dcae72014-02-05 16:28:24 -05001495 {
Jamie Madillccdf74b2015-08-18 10:46:12 -04001496 ASSERT(index < mData.mTransformFeedbackVaryingVars.size());
1497 const sh::Varying &varying = mData.mTransformFeedbackVaryingVars[index];
Geoff Lang48dcae72014-02-05 16:28:24 -05001498 GLsizei lastNameIdx = std::min(bufSize - 1, static_cast<GLsizei>(varying.name.length()));
1499 if (length)
1500 {
1501 *length = lastNameIdx;
1502 }
1503 if (size)
1504 {
Jamie Madillccdf74b2015-08-18 10:46:12 -04001505 *size = varying.elementCount();
Geoff Lang48dcae72014-02-05 16:28:24 -05001506 }
1507 if (type)
1508 {
1509 *type = varying.type;
1510 }
1511 if (name)
1512 {
1513 memcpy(name, varying.name.c_str(), lastNameIdx);
1514 name[lastNameIdx] = '\0';
1515 }
1516 }
1517}
1518
Geoff Lang1b6edcb2014-02-03 14:27:56 -05001519GLsizei Program::getTransformFeedbackVaryingCount() const
1520{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001521 if (mLinked)
Geoff Lang48dcae72014-02-05 16:28:24 -05001522 {
Jamie Madillccdf74b2015-08-18 10:46:12 -04001523 return static_cast<GLsizei>(mData.mTransformFeedbackVaryingVars.size());
Geoff Lang48dcae72014-02-05 16:28:24 -05001524 }
1525 else
1526 {
1527 return 0;
1528 }
Geoff Lang1b6edcb2014-02-03 14:27:56 -05001529}
1530
1531GLsizei Program::getTransformFeedbackVaryingMaxLength() const
1532{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001533 if (mLinked)
Geoff Lang48dcae72014-02-05 16:28:24 -05001534 {
1535 GLsizei maxSize = 0;
Jamie Madillccdf74b2015-08-18 10:46:12 -04001536 for (const sh::Varying &varying : mData.mTransformFeedbackVaryingVars)
Geoff Lang48dcae72014-02-05 16:28:24 -05001537 {
Geoff Lang48dcae72014-02-05 16:28:24 -05001538 maxSize = std::max(maxSize, static_cast<GLsizei>(varying.name.length() + 1));
1539 }
1540
1541 return maxSize;
1542 }
1543 else
1544 {
1545 return 0;
1546 }
Geoff Lang1b6edcb2014-02-03 14:27:56 -05001547}
1548
1549GLenum Program::getTransformFeedbackBufferMode() const
1550{
Jamie Madill5c6b7bf2015-08-17 12:53:35 -04001551 return mData.mTransformFeedbackBufferMode;
Geoff Lang7dd2e102014-11-10 15:19:26 -05001552}
1553
Jamie Madillada9ecc2015-08-17 12:53:37 -04001554// static
1555bool Program::linkVaryings(InfoLog &infoLog,
1556 const Shader *vertexShader,
1557 const Shader *fragmentShader)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001558{
Jamie Madill4cff2472015-08-21 16:53:18 -04001559 const std::vector<sh::Varying> &vertexVaryings = vertexShader->getVaryings();
1560 const std::vector<sh::Varying> &fragmentVaryings = fragmentShader->getVaryings();
Geoff Lang7dd2e102014-11-10 15:19:26 -05001561
Jamie Madill4cff2472015-08-21 16:53:18 -04001562 for (const sh::Varying &output : fragmentVaryings)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001563 {
Geoff Lang7dd2e102014-11-10 15:19:26 -05001564 bool matched = false;
1565
1566 // Built-in varyings obey special rules
Jamie Madillada9ecc2015-08-17 12:53:37 -04001567 if (output.isBuiltIn())
Geoff Lang7dd2e102014-11-10 15:19:26 -05001568 {
1569 continue;
1570 }
1571
Jamie Madill4cff2472015-08-21 16:53:18 -04001572 for (const sh::Varying &input : vertexVaryings)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001573 {
Jamie Madillada9ecc2015-08-17 12:53:37 -04001574 if (output.name == input.name)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001575 {
Jamie Madillada9ecc2015-08-17 12:53:37 -04001576 ASSERT(!input.isBuiltIn());
1577 if (!linkValidateVaryings(infoLog, output.name, input, output))
Geoff Lang7dd2e102014-11-10 15:19:26 -05001578 {
1579 return false;
1580 }
1581
Geoff Lang7dd2e102014-11-10 15:19:26 -05001582 matched = true;
1583 break;
1584 }
1585 }
1586
1587 // We permit unmatched, unreferenced varyings
Jamie Madillada9ecc2015-08-17 12:53:37 -04001588 if (!matched && output.staticUse)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001589 {
Jamie Madillada9ecc2015-08-17 12:53:37 -04001590 infoLog << "Fragment varying " << output.name << " does not match any vertex varying";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001591 return false;
1592 }
1593 }
1594
Jamie Madillada9ecc2015-08-17 12:53:37 -04001595 // TODO(jmadill): verify no unmatched vertex varyings?
1596
Geoff Lang7dd2e102014-11-10 15:19:26 -05001597 return true;
1598}
1599
Jamie Madill10750cb2015-09-04 14:23:52 -04001600bool Program::linkUniforms(gl::InfoLog &infoLog, const gl::Caps &caps)
Jamie Madillea918db2015-08-18 14:48:59 -04001601{
1602 const std::vector<sh::Uniform> &vertexUniforms = mData.mAttachedVertexShader->getUniforms();
1603 const std::vector<sh::Uniform> &fragmentUniforms = mData.mAttachedFragmentShader->getUniforms();
1604
1605 // Check that uniforms defined in the vertex and fragment shaders are identical
Jamie Madill10750cb2015-09-04 14:23:52 -04001606 std::map<std::string, LinkedUniform> linkedUniforms;
Jamie Madillea918db2015-08-18 14:48:59 -04001607
1608 for (const sh::Uniform &vertexUniform : vertexUniforms)
1609 {
Jamie Madill10750cb2015-09-04 14:23:52 -04001610 linkedUniforms[vertexUniform.name] = LinkedUniform(vertexUniform);
Jamie Madillea918db2015-08-18 14:48:59 -04001611 }
1612
1613 for (const sh::Uniform &fragmentUniform : fragmentUniforms)
1614 {
1615 auto entry = linkedUniforms.find(fragmentUniform.name);
1616 if (entry != linkedUniforms.end())
1617 {
Jamie Madill10750cb2015-09-04 14:23:52 -04001618 LinkedUniform *vertexUniform = &entry->second;
1619 const std::string &uniformName = "uniform '" + vertexUniform->name + "'";
1620 if (!linkValidateUniforms(infoLog, uniformName, *vertexUniform, fragmentUniform))
Jamie Madillea918db2015-08-18 14:48:59 -04001621 {
1622 return false;
1623 }
1624 }
1625 }
1626
Jamie Madill10750cb2015-09-04 14:23:52 -04001627 // Flatten the uniforms list (nested fields) into a simple list (no nesting).
1628 // Also check the maximum uniform vector and sampler counts.
1629 if (!flattenUniformsAndCheckCaps(caps, infoLog))
1630 {
1631 return false;
1632 }
1633
1634 indexUniforms();
1635
Jamie Madillea918db2015-08-18 14:48:59 -04001636 return true;
1637}
1638
Jamie Madill10750cb2015-09-04 14:23:52 -04001639void Program::indexUniforms()
1640{
1641 for (size_t uniformIndex = 0; uniformIndex < mData.mUniforms.size(); uniformIndex++)
1642 {
1643 const gl::LinkedUniform &uniform = mData.mUniforms[uniformIndex];
1644
1645 for (unsigned int arrayIndex = 0; arrayIndex < uniform.elementCount(); arrayIndex++)
1646 {
1647 if (!uniform.isBuiltIn())
1648 {
1649 // Assign in-order uniform locations
1650 mData.mUniformLocations.push_back(gl::VariableLocation(
1651 uniform.name, arrayIndex, static_cast<unsigned int>(uniformIndex)));
1652 }
1653 }
1654 }
1655}
1656
Geoff Lang7dd2e102014-11-10 15:19:26 -05001657bool Program::linkValidateInterfaceBlockFields(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform)
1658{
1659 if (!linkValidateVariablesBase(infoLog, uniformName, vertexUniform, fragmentUniform, true))
1660 {
1661 return false;
1662 }
1663
1664 if (vertexUniform.isRowMajorLayout != fragmentUniform.isRowMajorLayout)
1665 {
Jamie Madillf6113162015-05-07 11:49:21 -04001666 infoLog << "Matrix packings for " << uniformName << " differ between vertex and fragment shaders";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001667 return false;
1668 }
1669
1670 return true;
1671}
1672
1673// Determines the mapping between GL attributes and Direct3D 9 vertex stream usage indices
Jamie Madill5c6b7bf2015-08-17 12:53:35 -04001674bool Program::linkAttributes(const gl::Data &data,
Jamie Madill3da79b72015-04-27 11:09:17 -04001675 InfoLog &infoLog,
1676 const AttributeBindings &attributeBindings,
1677 const Shader *vertexShader)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001678{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001679 unsigned int usedLocations = 0;
Jamie Madillc349ec02015-08-21 16:53:12 -04001680 mData.mAttributes = vertexShader->getActiveAttributes();
Jamie Madill3da79b72015-04-27 11:09:17 -04001681 GLuint maxAttribs = data.caps->maxVertexAttributes;
1682
1683 // TODO(jmadill): handle aliasing robustly
Jamie Madillc349ec02015-08-21 16:53:12 -04001684 if (mData.mAttributes.size() > maxAttribs)
Jamie Madill3da79b72015-04-27 11:09:17 -04001685 {
Jamie Madillf6113162015-05-07 11:49:21 -04001686 infoLog << "Too many vertex attributes.";
Jamie Madill3da79b72015-04-27 11:09:17 -04001687 return false;
1688 }
Geoff Lang7dd2e102014-11-10 15:19:26 -05001689
Jamie Madillc349ec02015-08-21 16:53:12 -04001690 std::vector<sh::Attribute *> usedAttribMap(data.caps->maxVertexAttributes, nullptr);
Jamie Madill4e107222015-08-24 14:12:17 +00001691
Jamie Madillc349ec02015-08-21 16:53:12 -04001692 // Link attributes that have a binding location
1693 for (sh::Attribute &attribute : mData.mAttributes)
1694 {
1695 // TODO(jmadill): do staticUse filtering step here, or not at all
Geoff Lang7dd2e102014-11-10 15:19:26 -05001696 ASSERT(attribute.staticUse);
1697
Jamie Madillc349ec02015-08-21 16:53:12 -04001698 int bindingLocation = attributeBindings.getAttributeBinding(attribute.name);
1699 if (attribute.location == -1 && bindingLocation != -1)
Jamie Madill2d773182015-08-18 10:27:28 -04001700 {
Jamie Madillc349ec02015-08-21 16:53:12 -04001701 attribute.location = bindingLocation;
1702 }
1703
1704 if (attribute.location != -1)
1705 {
1706 // Location is set by glBindAttribLocation or by location layout qualifier
Jamie Madill63805b42015-08-25 13:17:39 -04001707 const int regs = VariableRegisterCount(attribute.type);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001708
Jamie Madill63805b42015-08-25 13:17:39 -04001709 if (static_cast<GLuint>(regs + attribute.location) > maxAttribs)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001710 {
Jamie Madillf6113162015-05-07 11:49:21 -04001711 infoLog << "Active attribute (" << attribute.name << ") at location "
Jamie Madillc349ec02015-08-21 16:53:12 -04001712 << attribute.location << " is too big to fit";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001713
1714 return false;
1715 }
1716
Jamie Madill63805b42015-08-25 13:17:39 -04001717 for (int reg = 0; reg < regs; reg++)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001718 {
Jamie Madill63805b42015-08-25 13:17:39 -04001719 const int regLocation = attribute.location + reg;
1720 sh::ShaderVariable *linkedAttribute = usedAttribMap[regLocation];
Geoff Lang7dd2e102014-11-10 15:19:26 -05001721
1722 // In GLSL 3.00, attribute aliasing produces a link error
Jamie Madill3da79b72015-04-27 11:09:17 -04001723 // In GLSL 1.00, attribute aliasing is allowed, but ANGLE currently has a bug
Jamie Madillc349ec02015-08-21 16:53:12 -04001724 if (linkedAttribute)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001725 {
Jamie Madillc349ec02015-08-21 16:53:12 -04001726 // TODO(jmadill): fix aliasing on ES2
1727 // if (mProgram->getShaderVersion() >= 300)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001728 {
Jamie Madill5c6b7bf2015-08-17 12:53:35 -04001729 infoLog << "Attribute '" << attribute.name << "' aliases attribute '"
Jamie Madill63805b42015-08-25 13:17:39 -04001730 << linkedAttribute->name << "' at location " << regLocation;
Geoff Lang7dd2e102014-11-10 15:19:26 -05001731 return false;
1732 }
1733 }
Jamie Madillc349ec02015-08-21 16:53:12 -04001734 else
1735 {
Jamie Madill63805b42015-08-25 13:17:39 -04001736 usedAttribMap[regLocation] = &attribute;
Jamie Madillc349ec02015-08-21 16:53:12 -04001737 }
Geoff Lang7dd2e102014-11-10 15:19:26 -05001738
Jamie Madill63805b42015-08-25 13:17:39 -04001739 usedLocations |= 1 << regLocation;
Geoff Lang7dd2e102014-11-10 15:19:26 -05001740 }
1741 }
1742 }
1743
1744 // Link attributes that don't have a binding location
Jamie Madillc349ec02015-08-21 16:53:12 -04001745 for (sh::Attribute &attribute : mData.mAttributes)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001746 {
Geoff Lang7dd2e102014-11-10 15:19:26 -05001747 ASSERT(attribute.staticUse);
1748
Jamie Madillc349ec02015-08-21 16:53:12 -04001749 // Not set by glBindAttribLocation or by location layout qualifier
1750 if (attribute.location == -1)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001751 {
Jamie Madill63805b42015-08-25 13:17:39 -04001752 int regs = VariableRegisterCount(attribute.type);
1753 int availableIndex = AllocateFirstFreeBits(&usedLocations, regs, maxAttribs);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001754
Jamie Madill63805b42015-08-25 13:17:39 -04001755 if (availableIndex == -1 || static_cast<GLuint>(availableIndex + regs) > maxAttribs)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001756 {
Jamie Madillf6113162015-05-07 11:49:21 -04001757 infoLog << "Too many active attributes (" << attribute.name << ")";
Jamie Madillc349ec02015-08-21 16:53:12 -04001758 return false;
Geoff Lang7dd2e102014-11-10 15:19:26 -05001759 }
1760
Jamie Madillc349ec02015-08-21 16:53:12 -04001761 attribute.location = availableIndex;
Geoff Lang7dd2e102014-11-10 15:19:26 -05001762 }
1763 }
1764
Jamie Madillc349ec02015-08-21 16:53:12 -04001765 for (const sh::Attribute &attribute : mData.mAttributes)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001766 {
Jamie Madillc349ec02015-08-21 16:53:12 -04001767 ASSERT(attribute.staticUse);
Jamie Madill63805b42015-08-25 13:17:39 -04001768 ASSERT(attribute.location != -1);
1769 int regs = VariableRegisterCount(attribute.type);
Jamie Madillc349ec02015-08-21 16:53:12 -04001770
Jamie Madill63805b42015-08-25 13:17:39 -04001771 for (int r = 0; r < regs; r++)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001772 {
Jamie Madill63805b42015-08-25 13:17:39 -04001773 mData.mActiveAttribLocationsMask.set(attribute.location + r);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001774 }
1775 }
1776
Geoff Lang7dd2e102014-11-10 15:19:26 -05001777 return true;
1778}
1779
Jamie Madille473dee2015-08-18 14:49:01 -04001780bool Program::linkUniformBlocks(InfoLog &infoLog, const Caps &caps)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001781{
Jamie Madille473dee2015-08-18 14:49:01 -04001782 const Shader &vertexShader = *mData.mAttachedVertexShader;
1783 const Shader &fragmentShader = *mData.mAttachedFragmentShader;
1784
Geoff Lang7dd2e102014-11-10 15:19:26 -05001785 const std::vector<sh::InterfaceBlock> &vertexInterfaceBlocks = vertexShader.getInterfaceBlocks();
1786 const std::vector<sh::InterfaceBlock> &fragmentInterfaceBlocks = fragmentShader.getInterfaceBlocks();
Jamie Madille473dee2015-08-18 14:49:01 -04001787
Geoff Lang7dd2e102014-11-10 15:19:26 -05001788 // Check that interface blocks defined in the vertex and fragment shaders are identical
1789 typedef std::map<std::string, const sh::InterfaceBlock*> UniformBlockMap;
1790 UniformBlockMap linkedUniformBlocks;
Jamie Madille473dee2015-08-18 14:49:01 -04001791
1792 GLuint vertexBlockCount = 0;
1793 for (const sh::InterfaceBlock &vertexInterfaceBlock : vertexInterfaceBlocks)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001794 {
Geoff Lang7dd2e102014-11-10 15:19:26 -05001795 linkedUniformBlocks[vertexInterfaceBlock.name] = &vertexInterfaceBlock;
Jamie Madille473dee2015-08-18 14:49:01 -04001796
1797 // Note: shared and std140 layouts are always considered active
1798 if (vertexInterfaceBlock.staticUse || vertexInterfaceBlock.layout != sh::BLOCKLAYOUT_PACKED)
1799 {
1800 if (++vertexBlockCount > caps.maxVertexUniformBlocks)
1801 {
1802 infoLog << "Vertex shader uniform block count exceed GL_MAX_VERTEX_UNIFORM_BLOCKS ("
1803 << caps.maxVertexUniformBlocks << ")";
1804 return false;
1805 }
1806 }
Geoff Lang7dd2e102014-11-10 15:19:26 -05001807 }
Jamie Madille473dee2015-08-18 14:49:01 -04001808
1809 GLuint fragmentBlockCount = 0;
1810 for (const sh::InterfaceBlock &fragmentInterfaceBlock : fragmentInterfaceBlocks)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001811 {
Jamie Madille473dee2015-08-18 14:49:01 -04001812 auto entry = linkedUniformBlocks.find(fragmentInterfaceBlock.name);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001813 if (entry != linkedUniformBlocks.end())
1814 {
1815 const sh::InterfaceBlock &vertexInterfaceBlock = *entry->second;
1816 if (!areMatchingInterfaceBlocks(infoLog, vertexInterfaceBlock, fragmentInterfaceBlock))
1817 {
1818 return false;
1819 }
1820 }
Jamie Madille473dee2015-08-18 14:49:01 -04001821
Geoff Lang7dd2e102014-11-10 15:19:26 -05001822 // Note: shared and std140 layouts are always considered active
Jamie Madille473dee2015-08-18 14:49:01 -04001823 if (fragmentInterfaceBlock.staticUse ||
1824 fragmentInterfaceBlock.layout != sh::BLOCKLAYOUT_PACKED)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001825 {
Jamie Madille473dee2015-08-18 14:49:01 -04001826 if (++fragmentBlockCount > caps.maxFragmentUniformBlocks)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001827 {
Jamie Madille473dee2015-08-18 14:49:01 -04001828 infoLog
1829 << "Fragment shader uniform block count exceed GL_MAX_FRAGMENT_UNIFORM_BLOCKS ("
1830 << caps.maxFragmentUniformBlocks << ")";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001831 return false;
1832 }
1833 }
1834 }
Jamie Madille473dee2015-08-18 14:49:01 -04001835
Jamie Madill10750cb2015-09-04 14:23:52 -04001836 gatherInterfaceBlockInfo();
1837
Geoff Lang7dd2e102014-11-10 15:19:26 -05001838 return true;
1839}
1840
1841bool Program::areMatchingInterfaceBlocks(gl::InfoLog &infoLog, const sh::InterfaceBlock &vertexInterfaceBlock,
1842 const sh::InterfaceBlock &fragmentInterfaceBlock)
1843{
1844 const char* blockName = vertexInterfaceBlock.name.c_str();
1845 // validate blocks for the same member types
1846 if (vertexInterfaceBlock.fields.size() != fragmentInterfaceBlock.fields.size())
1847 {
Jamie Madillf6113162015-05-07 11:49:21 -04001848 infoLog << "Types for interface block '" << blockName
1849 << "' differ between vertex and fragment shaders";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001850 return false;
1851 }
1852 if (vertexInterfaceBlock.arraySize != fragmentInterfaceBlock.arraySize)
1853 {
Jamie Madillf6113162015-05-07 11:49:21 -04001854 infoLog << "Array sizes differ for interface block '" << blockName
1855 << "' between vertex and fragment shaders";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001856 return false;
1857 }
1858 if (vertexInterfaceBlock.layout != fragmentInterfaceBlock.layout || vertexInterfaceBlock.isRowMajorLayout != fragmentInterfaceBlock.isRowMajorLayout)
1859 {
Jamie Madillf6113162015-05-07 11:49:21 -04001860 infoLog << "Layout qualifiers differ for interface block '" << blockName
1861 << "' between vertex and fragment shaders";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001862 return false;
1863 }
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001864 const unsigned int numBlockMembers =
1865 static_cast<unsigned int>(vertexInterfaceBlock.fields.size());
Geoff Lang7dd2e102014-11-10 15:19:26 -05001866 for (unsigned int blockMemberIndex = 0; blockMemberIndex < numBlockMembers; blockMemberIndex++)
1867 {
1868 const sh::InterfaceBlockField &vertexMember = vertexInterfaceBlock.fields[blockMemberIndex];
1869 const sh::InterfaceBlockField &fragmentMember = fragmentInterfaceBlock.fields[blockMemberIndex];
1870 if (vertexMember.name != fragmentMember.name)
1871 {
Jamie Madillf6113162015-05-07 11:49:21 -04001872 infoLog << "Name mismatch for field " << blockMemberIndex
1873 << " of interface block '" << blockName
1874 << "': (in vertex: '" << vertexMember.name
1875 << "', in fragment: '" << fragmentMember.name << "')";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001876 return false;
1877 }
1878 std::string memberName = "interface block '" + vertexInterfaceBlock.name + "' member '" + vertexMember.name + "'";
1879 if (!linkValidateInterfaceBlockFields(infoLog, memberName, vertexMember, fragmentMember))
1880 {
1881 return false;
1882 }
1883 }
1884 return true;
1885}
1886
1887bool Program::linkValidateVariablesBase(InfoLog &infoLog, const std::string &variableName, const sh::ShaderVariable &vertexVariable,
1888 const sh::ShaderVariable &fragmentVariable, bool validatePrecision)
1889{
1890 if (vertexVariable.type != fragmentVariable.type)
1891 {
Jamie Madillf6113162015-05-07 11:49:21 -04001892 infoLog << "Types for " << variableName << " differ between vertex and fragment shaders";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001893 return false;
1894 }
1895 if (vertexVariable.arraySize != fragmentVariable.arraySize)
1896 {
Jamie Madillf6113162015-05-07 11:49:21 -04001897 infoLog << "Array sizes for " << variableName << " differ between vertex and fragment shaders";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001898 return false;
1899 }
1900 if (validatePrecision && vertexVariable.precision != fragmentVariable.precision)
1901 {
Jamie Madillf6113162015-05-07 11:49:21 -04001902 infoLog << "Precisions for " << variableName << " differ between vertex and fragment shaders";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001903 return false;
1904 }
1905
1906 if (vertexVariable.fields.size() != fragmentVariable.fields.size())
1907 {
Jamie Madillf6113162015-05-07 11:49:21 -04001908 infoLog << "Structure lengths for " << variableName << " differ between vertex and fragment shaders";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001909 return false;
1910 }
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001911 const unsigned int numMembers = static_cast<unsigned int>(vertexVariable.fields.size());
Geoff Lang7dd2e102014-11-10 15:19:26 -05001912 for (unsigned int memberIndex = 0; memberIndex < numMembers; memberIndex++)
1913 {
1914 const sh::ShaderVariable &vertexMember = vertexVariable.fields[memberIndex];
1915 const sh::ShaderVariable &fragmentMember = fragmentVariable.fields[memberIndex];
1916
1917 if (vertexMember.name != fragmentMember.name)
1918 {
Jamie Madillf6113162015-05-07 11:49:21 -04001919 infoLog << "Name mismatch for field '" << memberIndex
1920 << "' of " << variableName
1921 << ": (in vertex: '" << vertexMember.name
1922 << "', in fragment: '" << fragmentMember.name << "')";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001923 return false;
1924 }
1925
1926 const std::string memberName = variableName.substr(0, variableName.length() - 1) + "." +
1927 vertexMember.name + "'";
1928
1929 if (!linkValidateVariablesBase(infoLog, vertexMember.name, vertexMember, fragmentMember, validatePrecision))
1930 {
1931 return false;
1932 }
1933 }
1934
1935 return true;
1936}
1937
1938bool Program::linkValidateUniforms(InfoLog &infoLog, const std::string &uniformName, const sh::Uniform &vertexUniform, const sh::Uniform &fragmentUniform)
1939{
Cooper Partin1acf4382015-06-12 12:38:57 -07001940#if ANGLE_PROGRAM_LINK_VALIDATE_UNIFORM_PRECISION == ANGLE_ENABLED
1941 const bool validatePrecision = true;
1942#else
1943 const bool validatePrecision = false;
1944#endif
1945
1946 if (!linkValidateVariablesBase(infoLog, uniformName, vertexUniform, fragmentUniform, validatePrecision))
Geoff Lang7dd2e102014-11-10 15:19:26 -05001947 {
1948 return false;
1949 }
1950
1951 return true;
1952}
1953
1954bool Program::linkValidateVaryings(InfoLog &infoLog, const std::string &varyingName, const sh::Varying &vertexVarying, const sh::Varying &fragmentVarying)
1955{
1956 if (!linkValidateVariablesBase(infoLog, varyingName, vertexVarying, fragmentVarying, false))
1957 {
1958 return false;
1959 }
1960
Jamie Madille9cc4692015-02-19 16:00:13 -05001961 if (!sh::InterpolationTypesMatch(vertexVarying.interpolation, fragmentVarying.interpolation))
Geoff Lang7dd2e102014-11-10 15:19:26 -05001962 {
Jamie Madillf6113162015-05-07 11:49:21 -04001963 infoLog << "Interpolation types for " << varyingName << " differ between vertex and fragment shaders";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001964 return false;
1965 }
1966
1967 return true;
1968}
1969
Jamie Madillccdf74b2015-08-18 10:46:12 -04001970bool Program::linkValidateTransformFeedback(InfoLog &infoLog,
1971 const std::vector<const sh::Varying *> &varyings,
1972 const Caps &caps) const
Geoff Lang7dd2e102014-11-10 15:19:26 -05001973{
1974 size_t totalComponents = 0;
1975
Jamie Madillccdf74b2015-08-18 10:46:12 -04001976 std::set<std::string> uniqueNames;
1977
1978 for (const std::string &tfVaryingName : mData.mTransformFeedbackVaryingNames)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001979 {
1980 bool found = false;
Jamie Madillccdf74b2015-08-18 10:46:12 -04001981 for (const sh::Varying *varying : varyings)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001982 {
Jamie Madillccdf74b2015-08-18 10:46:12 -04001983 if (tfVaryingName == varying->name)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001984 {
Jamie Madillccdf74b2015-08-18 10:46:12 -04001985 if (uniqueNames.count(tfVaryingName) > 0)
Geoff Lang7dd2e102014-11-10 15:19:26 -05001986 {
Jamie Madillccdf74b2015-08-18 10:46:12 -04001987 infoLog << "Two transform feedback varyings specify the same output variable ("
1988 << tfVaryingName << ").";
1989 return false;
Geoff Lang7dd2e102014-11-10 15:19:26 -05001990 }
Jamie Madillccdf74b2015-08-18 10:46:12 -04001991 uniqueNames.insert(tfVaryingName);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001992
Jamie Madillccdf74b2015-08-18 10:46:12 -04001993 // TODO(jmadill): Investigate implementation limits on D3D11
1994 size_t componentCount = gl::VariableComponentCount(varying->type);
Jamie Madillada9ecc2015-08-17 12:53:37 -04001995 if (mData.mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS &&
Geoff Lang7dd2e102014-11-10 15:19:26 -05001996 componentCount > caps.maxTransformFeedbackSeparateComponents)
1997 {
Jamie Madillccdf74b2015-08-18 10:46:12 -04001998 infoLog << "Transform feedback varying's " << varying->name << " components ("
1999 << componentCount << ") exceed the maximum separate components ("
Jamie Madillf6113162015-05-07 11:49:21 -04002000 << caps.maxTransformFeedbackSeparateComponents << ").";
Geoff Lang7dd2e102014-11-10 15:19:26 -05002001 return false;
2002 }
2003
2004 totalComponents += componentCount;
Geoff Lang7dd2e102014-11-10 15:19:26 -05002005 found = true;
2006 break;
2007 }
2008 }
2009
Jamie Madill89bb70e2015-08-31 14:18:39 -04002010 // TODO(jmadill): investigate if we can support capturing array elements.
2011 if (tfVaryingName.find('[') != std::string::npos)
2012 {
2013 infoLog << "Capture of array elements not currently supported.";
2014 return false;
2015 }
2016
Geoff Lang7dd2e102014-11-10 15:19:26 -05002017 // All transform feedback varyings are expected to exist since packVaryings checks for them.
2018 ASSERT(found);
Corentin Wallez54c34e02015-07-02 15:06:55 -04002019 UNUSED_ASSERTION_VARIABLE(found);
Geoff Lang7dd2e102014-11-10 15:19:26 -05002020 }
2021
Jamie Madillada9ecc2015-08-17 12:53:37 -04002022 if (mData.mTransformFeedbackBufferMode == GL_INTERLEAVED_ATTRIBS &&
Jamie Madillf6113162015-05-07 11:49:21 -04002023 totalComponents > caps.maxTransformFeedbackInterleavedComponents)
Geoff Lang7dd2e102014-11-10 15:19:26 -05002024 {
Jamie Madillf6113162015-05-07 11:49:21 -04002025 infoLog << "Transform feedback varying total components (" << totalComponents
2026 << ") exceed the maximum interleaved components ("
2027 << caps.maxTransformFeedbackInterleavedComponents << ").";
Geoff Lang7dd2e102014-11-10 15:19:26 -05002028 return false;
2029 }
2030
2031 return true;
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002032}
2033
Jamie Madillccdf74b2015-08-18 10:46:12 -04002034void Program::gatherTransformFeedbackVaryings(const std::vector<const sh::Varying *> &varyings)
2035{
2036 // Gather the linked varyings that are used for transform feedback, they should all exist.
2037 mData.mTransformFeedbackVaryingVars.clear();
2038 for (const std::string &tfVaryingName : mData.mTransformFeedbackVaryingNames)
2039 {
2040 for (const sh::Varying *varying : varyings)
2041 {
2042 if (tfVaryingName == varying->name)
2043 {
2044 mData.mTransformFeedbackVaryingVars.push_back(*varying);
2045 break;
2046 }
2047 }
2048 }
2049}
2050
2051std::vector<const sh::Varying *> Program::getMergedVaryings() const
2052{
2053 std::set<std::string> uniqueNames;
2054 std::vector<const sh::Varying *> varyings;
2055
2056 for (const sh::Varying &varying : mData.mAttachedVertexShader->getVaryings())
2057 {
2058 if (uniqueNames.count(varying.name) == 0)
2059 {
2060 uniqueNames.insert(varying.name);
2061 varyings.push_back(&varying);
2062 }
2063 }
2064
2065 for (const sh::Varying &varying : mData.mAttachedFragmentShader->getVaryings())
2066 {
2067 if (uniqueNames.count(varying.name) == 0)
2068 {
2069 uniqueNames.insert(varying.name);
2070 varyings.push_back(&varying);
2071 }
2072 }
2073
2074 return varyings;
2075}
Jamie Madill80a6fc02015-08-21 16:53:16 -04002076
2077void Program::linkOutputVariables()
2078{
2079 const Shader *fragmentShader = mData.mAttachedFragmentShader;
2080 ASSERT(fragmentShader != nullptr);
2081
2082 // Skip this step for GLES2 shaders.
2083 if (fragmentShader->getShaderVersion() == 100)
2084 return;
2085
Jamie Madilla0a9e122015-09-02 15:54:30 -04002086 const auto &shaderOutputVars = fragmentShader->getActiveOutputVariables();
Jamie Madill80a6fc02015-08-21 16:53:16 -04002087
2088 // TODO(jmadill): any caps validation here?
2089
2090 for (unsigned int outputVariableIndex = 0; outputVariableIndex < shaderOutputVars.size();
2091 outputVariableIndex++)
2092 {
Jamie Madilla0a9e122015-09-02 15:54:30 -04002093 const sh::OutputVariable &outputVariable = shaderOutputVars[outputVariableIndex];
Jamie Madill80a6fc02015-08-21 16:53:16 -04002094
2095 // Don't store outputs for gl_FragDepth, gl_FragColor, etc.
2096 if (outputVariable.isBuiltIn())
2097 continue;
2098
2099 // Since multiple output locations must be specified, use 0 for non-specified locations.
2100 int baseLocation = (outputVariable.location == -1 ? 0 : outputVariable.location);
2101
2102 ASSERT(outputVariable.staticUse);
2103
2104 for (unsigned int elementIndex = 0; elementIndex < outputVariable.elementCount();
2105 elementIndex++)
2106 {
2107 const int location = baseLocation + elementIndex;
2108 ASSERT(mData.mOutputVariables.count(location) == 0);
2109 unsigned int element = outputVariable.isArray() ? elementIndex : GL_INVALID_INDEX;
2110 mData.mOutputVariables[location] =
2111 VariableLocation(outputVariable.name, element, outputVariableIndex);
2112 }
2113 }
2114}
Jamie Madill10750cb2015-09-04 14:23:52 -04002115
2116bool Program::flattenUniformsAndCheckCaps(const Caps &caps, InfoLog &infoLog)
2117{
2118 const gl::Shader *vertexShader = mData.getAttachedVertexShader();
2119 VectorAndSamplerCount vsCounts;
2120
2121 for (const sh::Uniform &uniform : vertexShader->getUniforms())
2122 {
2123 if (uniform.staticUse)
2124 {
2125 vsCounts += flattenUniform(uniform, uniform.name);
2126 }
2127 }
2128
2129 if (vsCounts.vectorCount > caps.maxVertexUniformVectors)
2130 {
2131 infoLog << "Vertex shader active uniforms exceed MAX_VERTEX_UNIFORM_VECTORS ("
2132 << caps.maxVertexUniformVectors << ").";
2133 return false;
2134 }
2135
2136 if (vsCounts.samplerCount > caps.maxVertexTextureImageUnits)
2137 {
2138 infoLog << "Vertex shader sampler count exceeds MAX_VERTEX_TEXTURE_IMAGE_UNITS ("
2139 << caps.maxVertexTextureImageUnits << ").";
2140 return false;
2141 }
2142
2143 const gl::Shader *fragmentShader = mData.getAttachedFragmentShader();
2144 VectorAndSamplerCount fsCounts;
2145
2146 for (const sh::Uniform &uniform : fragmentShader->getUniforms())
2147 {
2148 if (uniform.staticUse)
2149 {
2150 fsCounts += flattenUniform(uniform, uniform.name);
2151 }
2152 }
2153
2154 if (fsCounts.vectorCount > caps.maxFragmentUniformVectors)
2155 {
2156 infoLog << "Fragment shader active uniforms exceed MAX_FRAGMENT_UNIFORM_VECTORS ("
2157 << caps.maxFragmentUniformVectors << ").";
2158 return false;
2159 }
2160
2161 if (fsCounts.samplerCount > caps.maxTextureImageUnits)
2162 {
2163 infoLog << "Fragment shader sampler count exceeds MAX_TEXTURE_IMAGE_UNITS ("
2164 << caps.maxTextureImageUnits << ").";
2165 return false;
2166 }
2167
2168 return true;
2169}
2170
2171Program::VectorAndSamplerCount Program::flattenUniform(const sh::ShaderVariable &uniform,
2172 const std::string &fullName)
2173{
2174 VectorAndSamplerCount vectorAndSamplerCount;
2175
2176 if (uniform.isStruct())
2177 {
2178 for (unsigned int elementIndex = 0; elementIndex < uniform.elementCount(); elementIndex++)
2179 {
2180 const std::string &elementString = (uniform.isArray() ? ArrayString(elementIndex) : "");
2181
2182 for (size_t fieldIndex = 0; fieldIndex < uniform.fields.size(); fieldIndex++)
2183 {
2184 const sh::ShaderVariable &field = uniform.fields[fieldIndex];
2185 const std::string &fieldFullName = (fullName + elementString + "." + field.name);
2186
2187 vectorAndSamplerCount += flattenUniform(field, fieldFullName);
2188 }
2189 }
2190
2191 return vectorAndSamplerCount;
2192 }
2193
2194 // Not a struct
2195 if (mData.getUniformByName(fullName) == nullptr)
2196 {
2197 gl::LinkedUniform linkedUniform(uniform.type, uniform.precision, fullName,
2198 uniform.arraySize, -1,
2199 sh::BlockMemberInfo::getDefaultBlockInfo());
2200 linkedUniform.staticUse = true;
2201 mData.mUniforms.push_back(linkedUniform);
2202 }
2203
2204 vectorAndSamplerCount.vectorCount =
2205 (VariableRegisterCount(uniform.type) * uniform.elementCount());
2206 vectorAndSamplerCount.samplerCount = (IsSamplerType(uniform.type) ? uniform.elementCount() : 0);
2207
2208 return vectorAndSamplerCount;
2209}
2210
2211void Program::gatherInterfaceBlockInfo()
2212{
2213 std::set<std::string> visitedList;
2214
2215 const gl::Shader *vertexShader = mData.getAttachedVertexShader();
2216
2217 ASSERT(mData.mUniformBlocks.empty());
2218 for (const sh::InterfaceBlock &vertexBlock : vertexShader->getInterfaceBlocks())
2219 {
2220 // Only 'packed' blocks are allowed to be considered inacive.
2221 if (!vertexBlock.staticUse && vertexBlock.layout == sh::BLOCKLAYOUT_PACKED)
2222 continue;
2223
2224 if (visitedList.count(vertexBlock.name) > 0)
2225 continue;
2226
2227 defineUniformBlock(vertexBlock, GL_VERTEX_SHADER);
2228 visitedList.insert(vertexBlock.name);
2229 }
2230
2231 const gl::Shader *fragmentShader = mData.getAttachedFragmentShader();
2232
2233 for (const sh::InterfaceBlock &fragmentBlock : fragmentShader->getInterfaceBlocks())
2234 {
2235 // Only 'packed' blocks are allowed to be considered inacive.
2236 if (!fragmentBlock.staticUse && fragmentBlock.layout == sh::BLOCKLAYOUT_PACKED)
2237 continue;
2238
2239 if (visitedList.count(fragmentBlock.name) > 0)
2240 {
2241 for (gl::UniformBlock &block : mData.mUniformBlocks)
2242 {
2243 if (block.name == fragmentBlock.name)
2244 {
2245 block.fragmentStaticUse = fragmentBlock.staticUse;
2246 }
2247 }
2248
2249 continue;
2250 }
2251
2252 defineUniformBlock(fragmentBlock, GL_FRAGMENT_SHADER);
2253 visitedList.insert(fragmentBlock.name);
2254 }
2255}
2256
2257void Program::defineUniformBlock(const sh::InterfaceBlock &interfaceBlock, GLenum shaderType)
2258{
2259 std::string baseName;
2260 if (!interfaceBlock.instanceName.empty() && interfaceBlock.arraySize == 0)
2261 {
2262 baseName = interfaceBlock.instanceName;
2263 }
2264
2265 int blockIndex = static_cast<int>(mData.mUniformBlocks.size());
2266 size_t firstBlockUniformIndex = mData.mUniforms.size();
2267 DefineUniformBlockMembers(interfaceBlock.fields, baseName, blockIndex, &mData.mUniforms);
2268 size_t lastBlockUniformIndex = mData.mUniforms.size();
2269
2270 std::vector<unsigned int> blockUniformIndexes;
2271 for (size_t blockUniformIndex = firstBlockUniformIndex;
2272 blockUniformIndex < lastBlockUniformIndex; ++blockUniformIndex)
2273 {
2274 blockUniformIndexes.push_back(static_cast<unsigned int>(blockUniformIndex));
2275 }
2276
2277 if (interfaceBlock.arraySize > 0)
2278 {
2279 for (unsigned int arrayElement = 0; arrayElement < interfaceBlock.arraySize; ++arrayElement)
2280 {
2281 UniformBlock block(interfaceBlock.name, true, arrayElement);
2282 block.memberUniformIndexes = blockUniformIndexes;
2283
2284 if (shaderType == GL_VERTEX_SHADER)
2285 {
2286 block.vertexStaticUse = interfaceBlock.staticUse;
2287 }
2288 else
2289 {
2290 ASSERT(shaderType == GL_FRAGMENT_SHADER);
2291 block.fragmentStaticUse = interfaceBlock.staticUse;
2292 }
2293
2294 mData.mUniformBlocks.push_back(block);
2295 }
2296 }
2297 else
2298 {
2299 UniformBlock block(interfaceBlock.name, false, 0);
2300 block.memberUniformIndexes = blockUniformIndexes;
2301
2302 if (shaderType == GL_VERTEX_SHADER)
2303 {
2304 block.vertexStaticUse = interfaceBlock.staticUse;
2305 }
2306 else
2307 {
2308 ASSERT(shaderType == GL_FRAGMENT_SHADER);
2309 block.fragmentStaticUse = interfaceBlock.staticUse;
2310 }
2311
2312 mData.mUniformBlocks.push_back(block);
2313 }
2314}
2315
2316template <typename DestT>
2317void Program::getUniformInternal(GLint location, DestT *dataOut) const
2318{
2319 const VariableLocation &locationInfo = mData.mUniformLocations[location];
2320 const LinkedUniform &uniform = mData.mUniforms[locationInfo.index];
2321
2322 const uint8_t *srcPointer = uniform.getDataPtrToElement(locationInfo.element);
2323
2324 GLenum componentType = VariableComponentType(uniform.type);
2325 if (componentType == GLTypeToGLenum<DestT>::value)
2326 {
2327 memcpy(dataOut, srcPointer, uniform.getElementSize());
2328 return;
2329 }
2330
2331 int components = VariableComponentCount(uniform.type);
2332
2333 switch (componentType)
2334 {
2335 case GL_INT:
2336 UniformStateQueryCastLoop<GLint>(dataOut, srcPointer, components);
2337 break;
2338 case GL_UNSIGNED_INT:
2339 UniformStateQueryCastLoop<GLuint>(dataOut, srcPointer, components);
2340 break;
2341 case GL_BOOL:
2342 UniformStateQueryCastLoop<GLboolean>(dataOut, srcPointer, components);
2343 break;
2344 case GL_FLOAT:
2345 UniformStateQueryCastLoop<GLfloat>(dataOut, srcPointer, components);
2346 break;
2347 default:
2348 UNREACHABLE();
2349 }
2350}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002351}