1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
5 * Copyright (c) 2014-2016 The Khronos Group Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 */ /*-------------------------------------------------------------------*/
24 #include "glwEnums.hpp"
26 #include "gluContextInfo.hpp"
27 #include "tcuRenderTarget.hpp"
28 #include "tcuVectorUtil.hpp"
32 #include "es31cExplicitUniformLocationTest.hpp"
43 Logger() : null_log_(0)
47 Logger(const Logger& rhs)
49 null_log_ = rhs.null_log_;
52 str_ << rhs.str_.str();
58 s_tcuLog->writeMessage(str_.str().c_str());
59 if (!str_.str().empty())
61 s_tcuLog->writeMessage(NL);
66 Logger& operator<<(const T& t)
75 static tcu::TestLog* Get()
80 static void setOutput(tcu::TestLog& log)
86 void operator=(const Logger&);
88 std::ostringstream str_;
89 static tcu::TestLog* s_tcuLog;
91 tcu::TestLog* Logger::s_tcuLog = NULL;
100 FSH_OR_CSH, //"one shader"
106 DefOccurence(DefOccurenceEnum _occurence) : occurence(_occurence)
110 bool occurs(GLenum shader) const
112 if (occurence == NONE_SH)
116 if (occurence == ALL_SH)
120 if (occurence == FSH_OR_CSH)
122 return shader == GL_FRAGMENT_SHADER || shader == GL_COMPUTE_SHADER;
124 if (occurence == VSH)
126 return shader == GL_VERTEX_SHADER;
128 if (occurence == ALL_BUT_FSH)
130 return shader != GL_FRAGMENT_SHADER;
132 if (occurence == ALL_BUT_VSH)
134 return shader != GL_VERTEX_SHADER;
141 class LocationSpecifier
148 class LayoutSpecifierBase
158 LayoutSpecifierBase(int _val, NumSys _numSys, DefOccurence _occurence)
159 : val(_val), numSys(_numSys), occurence(_occurence)
163 bool isImplicit(const std::vector<GLenum> stages) const
165 bool implicit = true;
166 for (size_t i = 0; i < stages.size(); i++)
168 implicit &= !occurence.occurs(stages[i]);
176 DefOccurence occurence;
180 class LayoutSpecifier : public LayoutSpecifierBase
183 LayoutSpecifier(int _val, NumSys _numSys, DefOccurence _occurence) : LayoutSpecifierBase(_val, _numSys, _occurence)
187 static LayoutSpecifier<T> C(int _val, NumSys _sys = Dec)
189 return LayoutSpecifier<T>(_val, _sys, DefOccurence::ALL_SH);
192 static LayoutSpecifier<T> C(int _val, DefOccurence _occurence)
194 return LayoutSpecifier<T>(_val, Dec, _occurence);
197 static LayoutSpecifier<T> Implicit()
199 return LayoutSpecifier<T>(1999999, Dec, DefOccurence::NONE_SH);
202 void streamDefinition(std::ostringstream& str, GLenum shader) const;
205 typedef LayoutSpecifier<LocationSpecifier> Loc;
206 typedef LayoutSpecifier<IndexSpecifier> Index;
209 void LayoutSpecifier<LocationSpecifier>::streamDefinition(std::ostringstream& str, GLenum shader) const
211 if (val < 0 || !occurence.occurs(shader))
216 str << "layout(location = ";
217 if (numSys == Loc::Oct)
219 str << std::oct << "0";
221 else if (numSys == Loc::Hex)
223 str << std::hex << "0x";
225 str << val << std::dec << ") ";
229 void LayoutSpecifier<IndexSpecifier>::streamDefinition(std::ostringstream& str, GLenum shader) const
231 if (val < 0 || !occurence.occurs(shader))
236 str << "layout(index = ";
237 if (numSys == Loc::Oct)
239 str << std::oct << "0";
241 else if (numSys == Loc::Hex)
243 str << std::hex << "0x";
245 str << val << std::dec << ") ";
248 class UniformStructCounter
251 UniformStructCounter() : counter(0)
260 UniformStructCounter(const UniformStructCounter&);
267 UniformType(GLenum _enumType, int _arraySize = 0)
268 : enumType(_enumType), arraySize(_arraySize), isArray(_arraySize > 0), signedType(true)
274 arraySizesSegmented.push_back(arraySize);
277 UniformType(GLenum _enumType, const std::vector<int>& _arraySizesSegmented)
278 : enumType(_enumType), arraySizesSegmented(_arraySizesSegmented), isArray(true), signedType(true)
281 for (size_t i = 0; i < arraySizesSegmented.size(); i++)
283 assert(arraySizesSegmented[i] > 0);
284 arraySize *= arraySizesSegmented[i];
288 UniformType(UniformStructCounter& structCounter, std::vector<UniformType> _childTypes, int _arraySize = 0)
289 : enumType(0), arraySize(_arraySize), childTypes(_childTypes), isArray(_arraySize > 0), signedType(true)
292 std::ostringstream _str;
293 _str << "S" << structCounter.getNextCount();
294 strType = _str.str();
299 arraySizesSegmented.push_back(arraySize);
302 inline const std::string& str() const
307 inline const std::string& refStr() const
312 bool isStruct() const
314 return (baseType == 0);
317 bool isSigned() const
322 const char* abs() const
329 case GL_UNSIGNED_INT:
339 std::pair<int, int> getSize() const
344 GLenum getBaseType() const
349 void streamArrayStr(std::ostringstream& _str, int arrayElem = -1) const
357 for (size_t segment = 0; segment < arraySizesSegmented.size(); segment++)
359 _str << "[" << arraySizesSegmented[segment] << "]";
364 int tailSize = arraySize;
365 for (size_t segment = 0; segment < arraySizesSegmented.size(); segment++)
367 tailSize /= arraySizesSegmented[segment];
368 _str << "[" << arrayElem / tailSize << "]";
369 arrayElem %= tailSize;
376 //arrays-of-arrays size
377 std::vector<int> arraySizesSegmented;
379 //premultiplied array size
382 //child types for nested (struct) types;
383 std::vector<UniformType> childTypes;
389 size = std::pair<int, int>(1, 1);
395 strType = "sampler2D";
396 baseType = GL_SAMPLER;
399 refStrType = strType = "float";
403 refStrType = strType = "int";
406 case GL_UNSIGNED_INT:
407 refStrType = strType = "uint";
408 baseType = GL_UNSIGNED_INT;
412 refStrType = strType = "vec2";
417 refStrType = strType = "vec3";
422 refStrType = strType = "vec4";
430 size.first = size.second = 2;
436 size.first = size.second = 3;
442 size.first = size.second = 4;
444 case GL_FLOAT_MAT2x3:
451 case GL_FLOAT_MAT4x3:
458 case GL_FLOAT_MAT2x4:
465 case GL_FLOAT_MAT3x4:
472 case GL_FLOAT_MAT3x2:
479 case GL_FLOAT_MAT4x2:
487 refStrType = strType = "ivec2";
492 refStrType = strType = "ivec3";
497 refStrType = strType = "ivec4";
506 std::string strType, refStrType;
507 std::pair<int, int> size;
513 class UniformValueGenerator
516 UniformValueGenerator() : fValue(0.0f), iValue(0)
521 if (fValue > 99999.0f)
525 return (fValue += 1.0f);
529 return (iValue += 1);
533 UniformValueGenerator(const UniformValueGenerator&);
541 void streamValue(std::ostringstream& str, int arrayElement = 0, int column = 0) const
543 int arrayElementSize = type.getSize().first * type.getSize().second;
545 str << type.refStr() << "(";
547 if (type.getBaseType() == GL_SAMPLER)
549 for (size_t elem = 0; elem < 4; elem++)
553 str << fValues[arrayElement * 4 + elem];
559 for (int elem = 0; fValues.size() && elem < type.getSize().first; elem++)
563 str << fValues[arrayElement * arrayElementSize + column * type.getSize().first + elem] << ".0";
565 for (int elem = 0; iValues.size() && elem < type.getSize().first; elem++)
569 str << iValues[arrayElement * arrayElementSize + elem];
571 for (int elem = 0; uValues.size() && elem < type.getSize().first; elem++)
575 str << uValues[arrayElement * arrayElementSize + elem] << "u";
580 const void* getPtr(int arrayElement) const
582 int arrayElementSize = type.getSize().first * type.getSize().second;
583 if (type.getBaseType() == GL_INT || type.getBaseType() == GL_SAMPLER)
585 return &iValues[arrayElement * arrayElementSize];
587 else if (type.getBaseType() == GL_UNSIGNED_INT)
589 return &uValues[arrayElement * arrayElementSize];
591 else if (type.getBaseType() == GL_FLOAT)
593 return &fValues[arrayElement * arrayElementSize];
599 UniformValue(const UniformType& _type, UniformValueGenerator& generator) : type(_type)
601 const int sizeRow = type.getSize().first;
602 const int sizeColumn = type.getSize().second;
609 if (type.getBaseType() == GL_INT)
611 assert(sizeColumn == 1);
612 iValues.resize(sizeRow * type.arraySize);
613 for (size_t elem = 0; elem < iValues.size(); elem++)
615 iValues[elem] = generator.genI();
618 else if (type.getBaseType() == GL_UNSIGNED_INT)
620 assert(sizeColumn == 1);
621 uValues.resize(sizeRow * type.arraySize);
622 for (size_t elem = 0; elem < uValues.size(); elem++)
624 uValues[elem] = static_cast<GLuint>(generator.genI());
627 else if (type.getBaseType() == GL_FLOAT)
629 fValues.resize(sizeColumn * sizeRow * type.arraySize);
630 for (size_t elem = 0; elem < fValues.size(); elem++)
632 fValues[elem] = generator.genF();
635 else if (type.getBaseType() == GL_SAMPLER)
638 fValues.resize(4 * type.arraySize);
639 for (size_t elem = 0; elem < fValues.size(); elem++)
641 fValues[elem] = float(elem) / float(fValues.size());
644 iValues.resize(type.arraySize);
645 for (size_t elem = 0; elem < iValues.size(); elem++)
647 iValues[elem] = generator.genI() % 16;
656 std::vector<GLfloat> fValues;
657 std::vector<GLint> iValues;
658 std::vector<GLint> uValues;
667 Uniform(UniformValueGenerator& generator, UniformType _type, Loc _location,
668 DefOccurence _declOccurence = DefOccurence::ALL_SH, DefOccurence _usageOccurence = DefOccurence::ALL_SH)
670 , location(_location)
671 , declOccurence(_declOccurence)
672 , usageOccurence(_usageOccurence)
673 , value(_type, generator)
678 int currentLocation = location.val;
679 for (int arrayElem = 0; arrayElem < type.arraySize; arrayElem++)
681 for (size_t child = 0; child < type.childTypes.size(); child++)
683 Loc childLocation = Loc::Implicit();
684 if (currentLocation > 0)
686 childLocation = Loc::C(currentLocation);
688 childUniforms.push_back(
689 Uniform(generator, type.childTypes[child], childLocation, declOccurence, usageOccurence));
690 currentLocation += type.childTypes[child].arraySize;
696 void setName(const std::string& parentName, const std::string& _name)
700 std::ostringstream __name;
701 __name << parentName << _name;
706 for (size_t i = 0; i < childUniforms.size(); i++)
708 std::ostringstream childName;
709 childName << "m" << (i % (childUniforms.size() / type.arraySize));
710 std::ostringstream childParentName;
711 childParentName << name;
712 type.streamArrayStr(childParentName, (int)(i / type.arraySize));
713 childParentName << ".";
714 childUniforms[i].setName(childParentName.str(), childName.str());
718 const std::string& getName() const
723 void streamDefinition(std::ostringstream& str) const
725 str << type.str() << " " << shortName;
726 type.streamArrayStr(str);
731 DefOccurence declOccurence, usageOccurence;
734 std::vector<Uniform> childUniforms;
735 std::string name, shortName;
738 class SubroutineFunction
741 SubroutineFunction(UniformValueGenerator& generator, Index _index = Index::Implicit())
742 : index(_index), embeddedRetVal(GL_FLOAT_VEC4, generator)
745 const UniformValue& getRetVal() const
747 return embeddedRetVal;
750 inline const std::string& getName() const
755 void setName(int _name)
757 std::ostringstream __name;
758 __name << "sf" << _name;
765 UniformValue embeddedRetVal;
769 class SubroutineFunctionSet
772 SubroutineFunctionSet(UniformValueGenerator& generator, size_t count = 0) : fn(count, SubroutineFunction(generator))
776 void push_back(const SubroutineFunction& _fn)
781 inline const std::string& getTypeName() const
786 void setTypeName(int _name)
788 std::ostringstream __name;
789 __name << "st" << _name;
790 typeName = __name.str();
793 std::vector<SubroutineFunction> fn;
794 std::string typeName;
797 class SubroutineUniform
800 SubroutineUniform(UniformValueGenerator& generator, SubroutineFunctionSet& _functions, Loc _location,
801 int _arraySize = 0, DefOccurence _defOccurence = DefOccurence::ALL_SH, bool _used = true)
802 : functions(_functions)
803 , location(_location)
804 , arraySize(_arraySize)
805 , defOccurence(_defOccurence)
807 , embeddedUIntUniform(GL_UNSIGNED_INT, generator)
810 assert(arraySize >= 0);
822 arraySizesSegmented.push_back(arraySize);
824 embeddedUIntUniform = UniformValue(UniformType(GL_UNSIGNED_INT, arraySize), generator);
825 for (int i = 0; i < arraySize; i++)
827 embeddedUIntUniform.uValues[i] = static_cast<GLint>(embeddedUIntUniform.uValues[i] % functions.fn.size());
831 SubroutineUniform(UniformValueGenerator& generator, SubroutineFunctionSet& _functions, Loc _location,
832 std::vector<int> _arraySizesSegmented, DefOccurence _defOccurence = DefOccurence::ALL_SH,
834 : functions(_functions)
835 , location(_location)
836 , defOccurence(_defOccurence)
838 , arraySizesSegmented(_arraySizesSegmented)
840 , embeddedUIntUniform(GL_UNSIGNED_INT, generator)
844 for (size_t i = 0; i < arraySizesSegmented.size(); i++)
846 assert(arraySizesSegmented[i] > 0);
847 arraySize *= arraySizesSegmented[i];
850 embeddedUIntUniform = UniformValue(UniformType(GL_UNSIGNED_INT, arraySize), generator);
851 for (int i = 0; i < arraySize; i++)
853 embeddedUIntUniform.uValues[i] = static_cast<GLint>(embeddedUIntUniform.uValues[i] % functions.fn.size());
856 void setName(const std::string& _name)
861 const std::string& getName() const
866 void streamArrayStr(std::ostringstream& str, int arrayElem = -1) const
874 for (size_t segment = 0; segment < arraySizesSegmented.size(); segment++)
876 str << "[" << arraySizesSegmented[segment] << "]";
881 int tailSize = arraySize;
882 for (size_t segment = 0; segment < arraySizesSegmented.size(); segment++)
884 tailSize /= arraySizesSegmented[segment];
885 str << "[" << arrayElem / tailSize << "]";
886 arrayElem %= tailSize;
891 const SubroutineFunction& getSelectedFunction(int arrayElem) const
893 assert(arrayElem < arraySize);
894 return functions.fn[embeddedUIntUniform.uValues[arrayElem]];
897 SubroutineFunctionSet functions;
900 DefOccurence defOccurence;
904 std::vector<int> arraySizesSegmented;
906 UniformValue embeddedUIntUniform;
917 ShaderKey(GLenum _stage, const std::string& _input, const std::string& _output)
918 : stage(_stage), input(_input), output(_output)
922 std::string input, output;
924 bool operator<(const ShaderKey& rhs) const
926 if (stage == rhs.stage)
928 if (input == rhs.input)
930 return (output < rhs.output);
932 return input < rhs.input;
934 return stage < rhs.stage;
938 class CompiledProgram
942 std::vector<GLenum> stages;
945 class ShaderSourceFactory
948 static void streamUniformDefinitions(const std::vector<Uniform>& uniforms, GLenum shader, std::ostringstream& ret)
950 for (size_t i = 0; i < uniforms.size(); i++)
952 if (uniforms[i].declOccurence.occurs(shader))
954 if (uniforms[i].type.isStruct())
956 ret << "struct " << uniforms[i].type.str() << " {" << std::endl;
957 for (size_t child = 0; child < uniforms[i].childUniforms.size() / uniforms[i].type.arraySize;
961 uniforms[i].childUniforms[child].streamDefinition(ret);
962 ret << ";" << std::endl;
964 ret << "};" << std::endl;
966 uniforms[i].location.streamDefinition(ret, shader);
968 uniforms[i].streamDefinition(ret);
969 ret << ";" << std::endl;
974 static void streamSubroutineDefinitions(const std::vector<SubroutineUniform>& subroutineUniforms, GLenum shader,
975 std::ostringstream& ret)
977 if (subroutineUniforms.size())
979 //add a "zero" uniform;
980 ret << "uniform float zero;" << std::endl;
983 for (size_t i = 0; i < subroutineUniforms.size(); i++)
985 if (subroutineUniforms[i].defOccurence.occurs(shader))
988 //subroutine vec4 st0(float param);
989 ret << "subroutine vec4 " << subroutineUniforms[i].functions.getTypeName() << "(float param);"
992 for (size_t fn = 0; fn < subroutineUniforms[i].functions.fn.size(); fn++)
994 //layout(index = X) subroutine(st0) vec4 sf0(float param) { .... };
995 subroutineUniforms[i].functions.fn[fn].index.streamDefinition(ret, shader);
996 ret << "subroutine(" << subroutineUniforms[i].functions.getTypeName() << ") vec4 "
997 << subroutineUniforms[i].functions.fn[fn].getName() << "(float param) { return zero + ";
998 subroutineUniforms[i].functions.fn[fn].getRetVal().streamValue(ret);
999 ret << "; }" << std::endl;
1002 //layout(location = X) subroutine uniform stX uX[...];
1003 subroutineUniforms[i].location.streamDefinition(ret, shader);
1004 ret << "subroutine uniform " << subroutineUniforms[i].functions.getTypeName() << " "
1005 << subroutineUniforms[i].getName();
1006 subroutineUniforms[i].streamArrayStr(ret);
1007 ret << ";" << std::endl;
1012 static void streamUniformValidator(std::ostringstream& ret, const Uniform& uniform, GLenum shader,
1013 const char* outTemporary)
1015 if (uniform.declOccurence.occurs(shader) && uniform.usageOccurence.occurs(shader))
1017 if (uniform.type.isStruct())
1019 for (size_t child = 0; child < uniform.childUniforms.size(); child++)
1021 streamUniformValidator(ret, uniform.childUniforms[child], shader, outTemporary);
1026 for (int arrayElement = 0; arrayElement < uniform.type.arraySize; arrayElement++)
1028 for (int column = 0; column < uniform.type.getSize().second; column++)
1030 std::string columnIndex;
1031 if (uniform.type.getSize().second > 1)
1033 std::ostringstream str;
1034 str << "[" << column << "]";
1035 columnIndex = str.str();
1037 std::string absoluteF;
1038 if (uniform.type.isSigned())
1043 if (uniform.type.getBaseType() == GL_SAMPLER)
1045 ret << NL " if (any(greaterThan(" << absoluteF << "(texture(" << uniform.getName();
1046 uniform.type.streamArrayStr(ret, arrayElement);
1047 ret << columnIndex << ", vec2(0.5)) - ";
1048 uniform.value.streamValue(ret, arrayElement, column);
1049 ret << " ), " << uniform.type.refStr() << "(" << uniform.type.abs() << ")))) {";
1051 else if (uniform.type.getSize().first > 1)
1053 ret << NL " if (any(greaterThan(" << absoluteF << "(" << uniform.getName();
1054 uniform.type.streamArrayStr(ret, arrayElement);
1055 ret << columnIndex << " - ";
1056 uniform.value.streamValue(ret, arrayElement, column);
1057 ret << "), " << uniform.type.refStr() << "(" << uniform.type.abs() << ")))) {";
1061 ret << NL " if (" << absoluteF << "(" << uniform.getName();
1062 uniform.type.streamArrayStr(ret, arrayElement);
1064 uniform.value.streamValue(ret, arrayElement);
1065 ret << ") >" << uniform.type.refStr() << "(" << uniform.type.abs() << ")) {";
1067 ret << NL " " << outTemporary << " = vec4 (1.0, 0.0, 0.0, 1.0);";
1075 static void streamUniformValidators(std::ostringstream& ret, const std::vector<Uniform>& uniforms, GLenum shader,
1076 const char* outTemporary)
1078 for (size_t i = 0; i < uniforms.size(); i++)
1080 streamUniformValidator(ret, uniforms[i], shader, outTemporary);
1084 static void streamSubroutineValidator(std::ostringstream& ret, const SubroutineUniform& subroutineUniform,
1085 GLenum shader, const char* outTemporary)
1087 if (subroutineUniform.defOccurence.occurs(shader) && subroutineUniform.used)
1089 for (int arrayElem = 0; arrayElem < subroutineUniform.arraySize; arrayElem++)
1091 ret << NL " if (any(greaterThan(abs(" << subroutineUniform.getName();
1092 subroutineUniform.streamArrayStr(ret, arrayElem);
1094 subroutineUniform.getSelectedFunction(arrayElem).getRetVal().streamValue(ret);
1095 ret << "), vec4(0.1)))) {";
1096 ret << NL " " << outTemporary << " = vec4 (1.0, 0.0, 0.0, 1.0);";
1102 static void streamSubroutineValidators(std::ostringstream& ret,
1103 const std::vector<SubroutineUniform>& subroutineUniforms, GLenum shader,
1104 const char* outTemporary)
1106 for (size_t i = 0; i < subroutineUniforms.size(); i++)
1108 streamSubroutineValidator(ret, subroutineUniforms[i], shader, outTemporary);
1112 static void streamShaderHeader(std::ostringstream& str, const glu::ContextType type)
1114 if (glu::isContextTypeES(type))
1116 str << "#version 310 es" NL "precision highp float;" NL "precision highp int;";
1120 str << "#version 430 core" NL;
1124 static std::string generateFragmentShader(const ShaderKey& key, const std::vector<Uniform>& uniforms,
1125 const std::vector<SubroutineUniform>& subroutineUniforms,
1126 const std::string& additionalDef, const glu::ContextType type)
1129 std::ostringstream ret;
1130 streamShaderHeader(ret, type);
1132 streamUniformDefinitions(uniforms, GL_FRAGMENT_SHADER, ret);
1134 streamSubroutineDefinitions(subroutineUniforms, GL_FRAGMENT_SHADER, ret);
1135 ret << NL << additionalDef << NL "in vec4 " << key.input << ";" << NL "out vec4 out_FragColor;"
1136 << NL "void main() {" << NL " vec4 validationResult = " << key.input << ";" << NL;
1137 streamUniformValidators(ret, uniforms, GL_FRAGMENT_SHADER, "validationResult");
1139 streamSubroutineValidators(ret, subroutineUniforms, GL_FRAGMENT_SHADER, "validationResult");
1140 ret << NL " out_FragColor = validationResult;" << NL "}";
1145 static std::string generateVertexShader(const ShaderKey& key, const std::vector<Uniform>& uniforms,
1146 const std::vector<SubroutineUniform>& subroutineUniforms,
1147 const std::string& additionalDef, const glu::ContextType type)
1150 std::ostringstream ret;
1151 streamShaderHeader(ret, type);
1153 streamUniformDefinitions(uniforms, GL_VERTEX_SHADER, ret);
1155 streamSubroutineDefinitions(subroutineUniforms, GL_VERTEX_SHADER, ret);
1156 ret << NL << additionalDef << NL "in vec4 in_Position;" << NL "out vec4 " << key.output << ";"
1157 << NL "void main() {" << NL " vec4 validationResult = vec4(0.0, 1.0, 0.0, 1.0);" << NL;
1158 streamUniformValidators(ret, uniforms, GL_VERTEX_SHADER, "validationResult");
1160 streamSubroutineValidators(ret, subroutineUniforms, GL_VERTEX_SHADER, "validationResult");
1161 ret << NL " " << key.output << " = validationResult;" << NL " gl_Position = in_Position;" << NL "}";
1165 static std::string generateComputeShader(const ShaderKey&, const std::vector<Uniform>& uniforms,
1166 const std::vector<SubroutineUniform>& subroutineUniforms,
1167 const std::string& additionalDef, const glu::ContextType type)
1170 std::ostringstream ret;
1171 streamShaderHeader(ret, type);
1172 ret << NL "layout (local_size_x = 1, local_size_y = 1) in;"
1173 << NL "layout (std430, binding = 1) buffer ResultBuffer {" << NL " vec4 cs_ValidationResult;" << NL "};"
1175 streamUniformDefinitions(uniforms, GL_COMPUTE_SHADER, ret);
1177 streamSubroutineDefinitions(subroutineUniforms, GL_COMPUTE_SHADER, ret);
1178 ret << NL << additionalDef << NL "void main() {" << NL " vec4 validationResult = vec4(0.0, 1.0, 0.0, 1.0);"
1180 streamUniformValidators(ret, uniforms, GL_COMPUTE_SHADER, "validationResult");
1182 streamSubroutineValidators(ret, subroutineUniforms, GL_COMPUTE_SHADER, "validationResult");
1183 ret << NL " cs_ValidationResult = validationResult;" << NL "}";
1188 static std::string generateShader(const ShaderKey& key, const std::vector<Uniform>& uniforms,
1189 const std::vector<SubroutineUniform>& subroutineUniforms,
1190 const std::string& additionalDef, const glu::ContextType type)
1195 case GL_VERTEX_SHADER:
1196 return generateVertexShader(key, uniforms, subroutineUniforms, additionalDef, type);
1197 case GL_FRAGMENT_SHADER:
1198 return generateFragmentShader(key, uniforms, subroutineUniforms, additionalDef, type);
1200 case GL_COMPUTE_SHADER:
1201 return generateComputeShader(key, uniforms, subroutineUniforms, additionalDef, type);
1210 class ExplicitUniformLocationCaseBase : public glcts::SubcaseBase
1212 virtual std::string Title()
1216 virtual std::string Purpose()
1220 virtual std::string Method()
1224 virtual std::string PassCriteria()
1229 int getWindowWidth()
1231 return m_context.getRenderContext().getRenderTarget().getWidth();
1234 int getWindowHeight()
1236 return m_context.getRenderContext().getRenderTarget().getHeight();
1239 std::map<ShaderKey, GLuint> CreateShaders(const std::vector<std::vector<ShaderKey> >& programConfigs,
1240 const std::vector<Uniform>& uniforms,
1241 const std::vector<SubroutineUniform>& subroutineUniforms,
1242 const std::string& additionalDef)
1244 std::map<ShaderKey, GLuint> ret;
1247 for (size_t config = 0; config < programConfigs.size(); config++)
1249 for (size_t target = 0; target < programConfigs[config].size(); target++)
1252 if (ret.find(programConfigs[config][target]) == ret.end())
1254 GLuint shader = glCreateShader(programConfigs[config][target].stage);
1256 std::string source = ShaderSourceFactory::generateShader(programConfigs[config][target], uniforms,
1257 subroutineUniforms, additionalDef,
1258 m_context.getRenderContext().getType());
1259 const char* cSource[] = { source.c_str() };
1260 glShaderSource(shader, 1, cSource, NULL);
1261 ret[programConfigs[config][target]] = shader;
1267 for (std::map<ShaderKey, GLuint>::iterator i = ret.begin(); i != ret.end(); i++)
1269 glCompileShader(i->second);
1275 long CreatePrograms(std::vector<CompiledProgram>& programs, const std::vector<Uniform>& uniforms,
1276 const std::vector<SubroutineUniform>& subroutineUniforms, const std::string& additionalDef,
1277 bool negativeCompile, bool negativeLink)
1280 long ret = NO_ERROR;
1282 std::vector<std::vector<ShaderKey> > programConfigs;
1284 std::vector<ShaderKey> vsh_fsh(2);
1285 vsh_fsh[0] = ShaderKey(GL_VERTEX_SHADER, "", "vs_ValidationResult");
1286 vsh_fsh[1] = ShaderKey(GL_FRAGMENT_SHADER, "vs_ValidationResult", "");
1287 programConfigs.push_back(vsh_fsh);
1290 std::vector<ShaderKey> csh(1);
1291 csh[0] = ShaderKey(GL_COMPUTE_SHADER, "", "");
1292 programConfigs.push_back(csh);
1295 std::map<ShaderKey, GLuint> shaders =
1296 CreateShaders(programConfigs, uniforms, subroutineUniforms, additionalDef);
1298 //query compilation results
1299 for (std::map<ShaderKey, GLuint>::iterator it = shaders.begin(); it != shaders.end(); it++)
1302 glGetShaderiv(it->second, GL_COMPILE_STATUS, &status);
1303 GLchar infoLog[1000], source[4000];
1304 glGetShaderSource(it->second, 4000, NULL, source);
1305 glGetShaderInfoLog(it->second, 1000, NULL, infoLog);
1306 Logger::Get()->writeKernelSource(source);
1307 Logger::Get()->writeCompileInfo("shader", "", status == GL_TRUE, infoLog);
1311 if (!negativeCompile)
1313 if (status != GL_TRUE)
1315 Logger() << "Shader compilation failed";
1323 Logger() << "Negative compilation case failed: shader shoult not compile, but "
1324 "GL_COMPILE_STATUS != 0";
1331 if (negativeCompile)
1335 for (std::map<ShaderKey, GLuint>::iterator it = shaders.begin(); it != shaders.end(); it++)
1337 glDeleteShader(it->second);
1343 //assemble programs and link
1344 for (size_t config = 0; config < programConfigs.size(); config++)
1346 CompiledProgram program;
1347 program.name = glCreateProgram();
1349 for (size_t target = 0; target < programConfigs[config].size(); target++)
1352 GLuint shader = shaders.find(programConfigs[config][target])->second;
1354 glAttachShader(program.name, shader);
1356 program.stages.push_back(programConfigs[config][target].stage);
1358 programs.push_back(program);
1359 glLinkProgram(programs[config].name);
1361 for (size_t config = 0; config < programConfigs.size(); config++)
1363 glLinkProgram(programs[config].name);
1367 for (std::map<ShaderKey, GLuint>::iterator it = shaders.begin(); it != shaders.end(); it++)
1369 glDeleteShader(it->second);
1372 //query link status:
1373 for (size_t config = 0; config < programConfigs.size(); config++)
1377 glGetProgramiv(programs[config].name, GL_LINK_STATUS, &status);
1378 GLchar infoLog[1000];
1379 glGetProgramInfoLog(programs[config].name, 1000, NULL, infoLog);
1380 Logger::Get()->writeCompileInfo("program", "", status == GL_TRUE, infoLog);
1384 if (status != GL_TRUE)
1386 Logger() << "Shader link failed";
1394 Logger() << "Negative link case failed: program should not link, but GL_LINK_STATUS != 0";
1402 long DeletePrograms(std::vector<CompiledProgram>& programs)
1404 for (size_t i = 0; i < programs.size(); i++)
1406 glDeleteProgram(programs[i].name);
1412 void setUniform(const Uniform& uniform, const CompiledProgram& program)
1416 for (size_t i = 0; i < program.stages.size(); i++)
1418 used |= uniform.declOccurence.occurs(program.stages[i]) && uniform.usageOccurence.occurs(program.stages[i]);
1423 if (uniform.type.isStruct())
1425 for (size_t j = 0; j < uniform.childUniforms.size(); j++)
1427 setUniform(uniform.childUniforms[j], program);
1433 if (uniform.location.isImplicit(program.stages))
1435 std::ostringstream name;
1436 name << uniform.getName();
1437 uniform.type.streamArrayStr(name, 0);
1438 loc = glGetUniformLocation(program.name, name.str().c_str());
1442 loc = uniform.location.val;
1445 for (int arrayElem = 0; arrayElem < uniform.type.arraySize; arrayElem++)
1447 switch (uniform.type.enumType)
1450 glUniform1f(loc, *(GLfloat*)uniform.value.getPtr(arrayElem));
1453 glUniform2fv(loc, 1, (GLfloat*)uniform.value.getPtr(arrayElem));
1456 glUniform3fv(loc, 1, (GLfloat*)uniform.value.getPtr(arrayElem));
1459 glUniform4fv(loc, 1, (GLfloat*)uniform.value.getPtr(arrayElem));
1462 glUniformMatrix2fv(loc, 1, GL_FALSE, (GLfloat*)uniform.value.getPtr(arrayElem));
1465 glUniformMatrix3fv(loc, 1, GL_FALSE, (GLfloat*)uniform.value.getPtr(arrayElem));
1468 glUniformMatrix4fv(loc, 1, GL_FALSE, (GLfloat*)uniform.value.getPtr(arrayElem));
1470 case GL_FLOAT_MAT2x3:
1471 glUniformMatrix2x3fv(loc, 1, GL_FALSE, (GLfloat*)uniform.value.getPtr(arrayElem));
1473 case GL_FLOAT_MAT4x3:
1474 glUniformMatrix4x3fv(loc, 1, GL_FALSE, (GLfloat*)uniform.value.getPtr(arrayElem));
1476 case GL_FLOAT_MAT2x4:
1477 glUniformMatrix2x4fv(loc, 1, GL_FALSE, (GLfloat*)uniform.value.getPtr(arrayElem));
1479 case GL_FLOAT_MAT3x4:
1480 glUniformMatrix3x4fv(loc, 1, GL_FALSE, (GLfloat*)uniform.value.getPtr(arrayElem));
1482 case GL_FLOAT_MAT3x2:
1483 glUniformMatrix3x2fv(loc, 1, GL_FALSE, (GLfloat*)uniform.value.getPtr(arrayElem));
1485 case GL_FLOAT_MAT4x2:
1486 glUniformMatrix4x2fv(loc, 1, GL_FALSE, (GLfloat*)uniform.value.getPtr(arrayElem));
1490 glUniform1i(loc, *(GLint*)uniform.value.getPtr(arrayElem));
1493 glUniform2iv(loc, 1, (GLint*)uniform.value.getPtr(arrayElem));
1496 glUniform3iv(loc, 1, (GLint*)uniform.value.getPtr(arrayElem));
1499 glUniform4iv(loc, 1, (GLint*)uniform.value.getPtr(arrayElem));
1501 case GL_UNSIGNED_INT:
1502 glUniform1ui(loc, *(GLuint*)uniform.value.getPtr(arrayElem));
1512 void setSubroutineUniform(const SubroutineUniform& subroutineUniform, const CompiledProgram& program, GLenum stage,
1513 std::vector<glw::GLuint>& indicesOut)
1515 bool used = subroutineUniform.defOccurence.occurs(stage) && subroutineUniform.used;
1519 for (int arrayElem = 0; arrayElem < subroutineUniform.arraySize; arrayElem++)
1522 if (subroutineUniform.location.isImplicit(program.stages))
1524 std::ostringstream name;
1525 name << subroutineUniform.getName();
1526 subroutineUniform.streamArrayStr(name, arrayElem);
1527 loc = glGetSubroutineUniformLocation(program.name, stage, name.str().c_str());
1531 loc = subroutineUniform.location.val + arrayElem;
1536 const SubroutineFunction& selectedFunction = subroutineUniform.getSelectedFunction(arrayElem);
1539 if (selectedFunction.index.isImplicit(std::vector<GLenum>(1, stage)))
1541 index = glGetSubroutineIndex(program.name, stage, selectedFunction.getName().c_str());
1545 index = selectedFunction.index.val;
1548 if (loc < (int)indicesOut.size())
1550 indicesOut[loc] = index;
1565 long runExecuteProgram(const CompiledProgram& program, const std::vector<Uniform>& uniforms,
1566 const std::vector<SubroutineUniform>& subroutineUniforms)
1568 long ret = NO_ERROR;
1570 glUseProgram(program.name);
1572 for (size_t i = 0; i < uniforms.size(); i++)
1574 setUniform(uniforms[i], program);
1577 for (size_t stage = 0; stage < program.stages.size() && subroutineUniforms.size(); stage++)
1580 glw::GLint numactive;
1581 glGetProgramStageiv(program.name, program.stages[stage], GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS,
1585 std::vector<glw::GLuint> indices(numactive, 0);
1587 for (size_t i = 0; i < subroutineUniforms.size(); i++)
1589 setSubroutineUniform(subroutineUniforms[i], program, program.stages[stage], indices);
1591 glUniformSubroutinesuiv(program.stages[stage], numactive, &indices[0]);
1595 if (program.stages[0] != GL_COMPUTE_SHADER)
1597 glClear(GL_COLOR_BUFFER_BIT);
1598 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1600 std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4);
1602 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
1603 for (size_t i = 0; i < pixels.size(); i += 4)
1605 if (pixels[i] != 0 || pixels[i + 1] != 255 || pixels[i + 2] != 0)
1608 Logger() << "Program " << program.name << ": Wrong color. Expected green, got (" << (int)pixels[i]
1609 << ", " << (int)pixels[i + 1] << ", " << (int)pixels[i + 2] << ", " << (int)pixels[i + 3]
1614 Logger().Get()->writeImage("rendered image", "", QP_IMAGE_COMPRESSION_MODE_BEST, QP_IMAGE_FORMAT_RGBA8888,
1615 getWindowWidth(), getWindowHeight(), 0, &pixels[0]);
1620 glGenBuffers(1, &buffer);
1621 glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);
1622 glBufferData(GL_SHADER_STORAGE_BUFFER, 4 * sizeof(GLfloat), NULL, GL_DYNAMIC_READ);
1623 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffer);
1625 glDispatchCompute(1, 1, 1);
1626 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
1628 GLfloat* color = reinterpret_cast<GLfloat*>(
1629 glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, 4 * sizeof(GLfloat), GL_MAP_READ_BIT));
1631 if (color[0] != 0 || color[1] != 1.0 || color[2] != 0)
1634 Logger() << "Program " << program.name << ": Wrong color. Expected green, got (" << (int)color[0]
1635 << ", " << (int)color[1] << ", " << (int)color[2] << ", " << (int)color[3] << ").";
1638 glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
1640 glDeleteBuffers(1, &buffer);
1646 long runQueryUniform(const CompiledProgram& program, const Uniform& uniform, std::set<GLuint>& usedLocations,
1649 long ret = NO_ERROR;
1652 glGetUniformLocation(program, name);
1653 Query passes if returned value is unique in current program, matches
1654 explicit location (if passed in GLSL code) and is less than value of
1655 GL_MAX_UNIFORM_LOCATIONS.
1657 glGetProgramResourceLocation(program, GL_UNIFIORM, name);
1658 Query passes if returned value matches value returned from
1659 glGetUniformLocation().
1662 if (uniform.type.isStruct())
1664 for (size_t i = 0; i < uniform.childUniforms.size(); i++)
1666 ret |= runQueryUniform(program, uniform.childUniforms[i], usedLocations, max);
1671 for (int arrayElem = 0; arrayElem < uniform.type.arraySize; arrayElem++)
1674 /* Location that is taken by this uniform (even if not used).*/
1675 GLint reservedLocation = -1;
1676 if (!uniform.location.isImplicit(program.stages))
1678 reservedLocation = uniform.location.val + arrayElem;
1681 //optimization: for continuous arrays run queries at the beging and end only.
1682 bool runQueries = uniform.location.isImplicit(program.stages) ||
1683 (arrayElem < 1000 || arrayElem > uniform.type.arraySize - 1000);
1687 std::ostringstream name;
1688 name << uniform.getName();
1689 uniform.type.streamArrayStr(name, arrayElem);
1690 GLint returned = glGetUniformLocation(program.name, name.str().c_str());
1692 GLint returnedPIQ = glGetProgramResourceLocation(program.name, GL_UNIFORM, name.str().c_str());
1694 if (returned != returnedPIQ)
1698 << "Locations of uniform \"" << name.str()
1699 << "\" returned by glGetUniformLocation and differ glGetProgramResourceLocation differ: "
1700 << returned << " != " << returnedPIQ << ".";
1704 for (size_t i = 0; i < program.stages.size(); i++)
1706 used |= uniform.declOccurence.occurs(program.stages[i]) &&
1707 uniform.usageOccurence.occurs(program.stages[i]);
1710 if (!uniform.location.isImplicit(program.stages))
1712 //Validate uniform location against explicit value
1713 GLint expected = reservedLocation;
1714 if (!(expected == returned || (!used && returned == -1)))
1717 Logger() << "Unexpected uniform \"" << name.str() << "\" location: expected " << expected
1718 << ", got " << returned << ".";
1723 //Check if location > 0 if used;
1729 Logger() << "Unexpected uniform \"" << name.str()
1730 << "\" location: expected positive value, got " << returned << ".";
1734 reservedLocation = returned;
1741 //check if location is less than max
1743 if (returned >= max)
1746 Logger() << "Uniform \"" << name.str() << "\" returned location (" << returned
1747 << ") is greater than implementation dependent limit (" << max << ").";
1752 //usedLocations is always checked (even if queries were not run.
1753 if (reservedLocation >= 0)
1755 //check if location is unique
1756 if (usedLocations.find(reservedLocation) != usedLocations.end())
1759 Logger() << "Uniform location (" << reservedLocation << ") is not unique.";
1761 usedLocations.insert(reservedLocation);
1768 long runQueryUniformSubroutine(const CompiledProgram& program, GLenum stage,
1769 const SubroutineUniform& subroutineUniform, std::set<GLuint>& usedLocations,
1772 long ret = NO_ERROR;
1774 glGetSubroutineUniformLocation(program, shaderType, name)
1775 Query passes if returned value is unique in current program stage,
1776 matches explicit location (if passed in GLSL code) and is less than
1777 value of GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS.
1779 glGetProgramResourceLocation(program, GL_(VERTEX|FRAGMENT|COMPUTE|...
1780 ..._SUBROUTINE_UNIFORM, name)
1781 Query passes if returned value matches value returned from
1782 glGetUniformLocation().
1785 for (int arrayElem = 0; arrayElem < subroutineUniform.arraySize; arrayElem++)
1787 std::ostringstream name;
1788 name << subroutineUniform.getName();
1790 subroutineUniform.streamArrayStr(name, arrayElem);
1792 GLint returned = glGetSubroutineUniformLocation(program.name, stage, name.str().c_str());
1794 glw::GLenum piqStage = 0;
1797 case GL_VERTEX_SHADER:
1798 piqStage = GL_VERTEX_SUBROUTINE_UNIFORM;
1800 case GL_FRAGMENT_SHADER:
1801 piqStage = GL_FRAGMENT_SUBROUTINE_UNIFORM;
1803 case GL_COMPUTE_SHADER:
1804 piqStage = GL_COMPUTE_SUBROUTINE_UNIFORM;
1810 GLint returnedPIQ = glGetProgramResourceLocation(program.name, piqStage, name.str().c_str());
1812 if (returned != returnedPIQ)
1815 Logger() << "Locations of subrutine uniform \"" << name.str()
1816 << "\" returned by glGetUniformLocation and differ glGetProgramResourceLocation differ: "
1817 << returned << " != " << returnedPIQ << ".";
1820 bool used = subroutineUniform.defOccurence.occurs(stage) && subroutineUniform.used;
1822 GLint reservedLocation = -1;
1824 if (!subroutineUniform.location.isImplicit(std::vector<glw::GLenum>(1, stage)))
1826 //Validate uniform location against explicit value
1827 GLint expected = subroutineUniform.location.val + arrayElem;
1828 if (!(expected == returned || (!used && returned == -1)))
1831 Logger() << "Unexpected subroutine uniform \"" << name.str() << "\" location: expected " << expected
1832 << ", got " << returned << ".";
1835 reservedLocation = expected;
1839 //Check if location > 0 if used;
1845 Logger() << "Unexpected subroutine uniform \"" << name.str()
1846 << "\" location: expected positive value, got " << returned << ".";
1850 reservedLocation = returned;
1855 if (reservedLocation >= 0)
1857 //check if location is unique
1858 if (usedLocations.find(reservedLocation) != usedLocations.end())
1861 Logger() << "Subroutine uniform \"" << name.str() << "\" location (" << reservedLocation
1862 << ") is not unique.";
1864 usedLocations.insert(reservedLocation);
1869 //check if location is less than max
1871 if (returned >= max)
1874 Logger() << "Subroutine uniform \"" << name.str() << "\" returned location (" << returned
1875 << ") is greater than implementation dependent limit (" << max << ").";
1882 long runQueryUniformSubroutineFunction(const CompiledProgram& program, GLenum stage,
1883 const SubroutineFunction& subroutineFunction, std::set<GLuint>& usedIndices,
1884 GLint max, bool used)
1886 long ret = NO_ERROR;
1888 glGetSubroutineIndex(program, shaderType, name)
1889 Query passes if returned value is unique in current program stage,
1890 matches explicit index (if passed in GLSL code) and is less than value
1891 of GL_MAX_SUBROUTINES.
1893 glGetProgramResourceIndex(program, GL_(VERTEX|FRAGMENT|COMPUTE|...
1894 ..._SUBROUTINE, name)
1895 Query passes if returned value matches value returned from
1896 glGetSubroutineIndex().
1899 std::string name = subroutineFunction.getName();
1901 GLint returned = glGetSubroutineIndex(program.name, stage, name.c_str());
1903 glw::GLenum piqStage = 0;
1906 case GL_VERTEX_SHADER:
1907 piqStage = GL_VERTEX_SUBROUTINE;
1909 case GL_FRAGMENT_SHADER:
1910 piqStage = GL_FRAGMENT_SUBROUTINE;
1912 case GL_COMPUTE_SHADER:
1913 piqStage = GL_COMPUTE_SUBROUTINE;
1919 GLint returnedPIQ = glGetProgramResourceIndex(program.name, piqStage, name.c_str());
1921 if (returned != returnedPIQ)
1924 Logger() << "Indices of subroutine function \"" << name
1925 << "\" returned by glGetSubroutineIndex and differ glGetProgramResourceIndex differ: " << returned
1926 << " != " << returnedPIQ << ".";
1929 GLint reservedIndex = -1;
1931 if (!subroutineFunction.index.isImplicit(std::vector<glw::GLenum>(1, stage)))
1933 //Validate uniform location against explicit value
1934 GLint expected = subroutineFunction.index.val;
1935 if (!(expected == returned || (!used && returned == -1)))
1938 Logger() << "Unexpected subroutine function \"" << name << "\" index: expected " << expected << ", got "
1942 reservedIndex = expected;
1946 //Check if location > 0 if used;
1952 Logger() << "Unexpected subroutine function \"" << name << "\" index: expected positive value, got "
1957 reservedIndex = returned;
1962 if (reservedIndex >= 0)
1964 //check if location is unique
1965 if (usedIndices.find(reservedIndex) != usedIndices.end())
1968 Logger() << "Subroutine function \"" << name << "\" index (" << reservedIndex << ") is not unique.";
1970 usedIndices.insert(reservedIndex);
1975 //check if location is less than max
1977 if (returned >= max)
1980 Logger() << "Subroutine function \"" << name << "\" returned index (" << returned
1981 << ") is greater than implementation dependent limit (" << max << ").";
1988 long runQueryProgram(const CompiledProgram& program, const std::vector<Uniform>& uniforms,
1989 const std::vector<SubroutineUniform>& subroutineUniforms)
1991 long ret = NO_ERROR;
1994 std::set<GLuint> usedLocations;
1997 glGetIntegerv(GL_MAX_UNIFORM_LOCATIONS, &max);
1999 for (size_t i = 0; i < uniforms.size(); i++)
2001 ret |= runQueryUniform(program, uniforms[i], usedLocations, max);
2005 if (subroutineUniforms.size())
2007 GLint maxLocation, maxIndex;
2008 glGetIntegerv(GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS, &maxLocation);
2009 glGetIntegerv(GL_MAX_SUBROUTINES, &maxIndex);
2011 for (size_t stage = 0; stage < program.stages.size(); stage++)
2013 std::set<GLuint> usedLocations;
2014 std::set<GLuint> usedIndices;
2015 for (size_t i = 0; i < subroutineUniforms.size(); i++)
2017 ret |= runQueryUniformSubroutine(program, program.stages[stage], subroutineUniforms[i],
2018 usedLocations, maxLocation);
2019 for (size_t fn = 0; fn < subroutineUniforms[i].functions.fn.size(); fn++)
2021 ret |= runQueryUniformSubroutineFunction(
2022 program, program.stages[stage], subroutineUniforms[i].functions.fn[fn], usedIndices,
2024 subroutineUniforms[i].defOccurence.occurs(program.stages[stage]) &&
2025 subroutineUniforms[i].used);
2035 UniformValueGenerator uniformValueGenerator;
2036 UniformStructCounter uniformStructCounter;
2038 long doRun(std::vector<SubroutineUniform>& subroutineUniforms)
2040 assert(subroutineUniforms.size());
2041 std::vector<Uniform> noUniforms;
2042 return doRun(noUniforms, subroutineUniforms);
2045 long doRun(std::vector<Uniform>& uniforms)
2047 assert(uniforms.size());
2048 std::vector<SubroutineUniform> noSubroutineUniforms;
2049 return doRun(uniforms, noSubroutineUniforms);
2052 long doRunNegativeCompile(const std::string additionalDef)
2054 std::vector<Uniform> noUniforms;
2055 std::vector<SubroutineUniform> noSubroutineUniforms;
2056 return doRun(noUniforms, noSubroutineUniforms, additionalDef, true);
2059 long doRunNegativeLink(std::vector<Uniform>& uniforms)
2061 std::vector<SubroutineUniform> noSubroutineUniforms;
2062 return doRun(uniforms, noSubroutineUniforms, "", false, true);
2065 long doRunNegativeLink(std::vector<SubroutineUniform>& subroutineUniforms)
2067 std::vector<Uniform> noUniforms;
2068 return doRun(noUniforms, subroutineUniforms, "", false, true);
2071 long doRun(std::vector<Uniform>& uniforms, std::vector<SubroutineUniform>& subroutineUniforms,
2072 std::string additionalDef = "", bool negativeCompile = false, bool negativeLink = false)
2074 long ret = NO_ERROR;
2075 std::string parentUniformName = "";
2076 for (size_t i = 0; i < uniforms.size(); i++)
2078 std::ostringstream name;
2080 uniforms[i].setName(parentUniformName, name.str());
2082 int subroutineTypeCounter = 0;
2083 int subroutineFunctionCounter = 0;
2084 for (size_t i = 0; i < subroutineUniforms.size(); i++)
2086 std::ostringstream name;
2087 name << "u" << i + uniforms.size();
2088 subroutineUniforms[i].setName(name.str());
2089 if (!subroutineUniforms[i].functions.getTypeName().size())
2091 subroutineUniforms[i].functions.setTypeName(subroutineTypeCounter++);
2092 for (size_t fn = 0; fn < subroutineUniforms[i].functions.fn.size(); fn++)
2094 subroutineUniforms[i].functions.fn[fn].setName(subroutineFunctionCounter++);
2099 GLfloat coords[] = {
2100 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
2104 glGenBuffers(1, &vbo);
2105 glBindBuffer(GL_ARRAY_BUFFER, vbo);
2106 glBufferData(GL_ARRAY_BUFFER, sizeof(coords), coords, GL_STATIC_DRAW);
2108 glGenVertexArrays(1, &vao);
2109 glBindVertexArray(vao);
2110 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL);
2111 glEnableVertexAttribArray(0);
2113 std::vector<CompiledProgram> programs;
2114 ret |= CreatePrograms(programs, uniforms, subroutineUniforms, additionalDef, negativeCompile, negativeLink);
2116 for (size_t i = 0; i < programs.size() && ret == NO_ERROR && !negativeCompile && !negativeLink; i++)
2118 ret |= runExecuteProgram(programs[i], uniforms, subroutineUniforms);
2119 ret |= runQueryProgram(programs[i], uniforms, subroutineUniforms);
2124 DeletePrograms(programs);
2126 glDeleteBuffers(1, &vbo);
2127 glDeleteVertexArrays(1, &vao);
2133 class UniformLoc : public ExplicitUniformLocationCaseBase
2137 //layout (location = 2) uniform vec4 u0;
2138 std::vector<Uniform> uniforms;
2139 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(2), DefOccurence::FSH_OR_CSH));
2140 return doRun(uniforms);
2144 class UniformLocNonDec : public ExplicitUniformLocationCaseBase
2148 //layout (location = 0x0a) uniform vec4 u0;
2149 //layout (location = 010) uniform vec4 u1;
2150 std::vector<Uniform> uniforms;
2152 Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(0x0a, Loc::Hex), DefOccurence::FSH_OR_CSH));
2154 Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(010, Loc::Oct), DefOccurence::FSH_OR_CSH));
2155 return doRun(uniforms);
2159 class UniformLocMultipleStages : public ExplicitUniformLocationCaseBase
2163 //layout (location = 2) uniform vec4 u0;
2164 std::vector<Uniform> uniforms;
2165 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(2)));
2166 return doRun(uniforms);
2170 class UniformLocMultipleUniforms : public ExplicitUniformLocationCaseBase
2174 //layout (location = 2) uniform vec4 u0;
2175 //layout (location = 3) uniform vec4 u1;
2176 //layout (location = 5) uniform vec4 u2;
2177 std::vector<Uniform> uniforms;
2178 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(2)));
2179 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(3)));
2180 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(5)));
2181 return doRun(uniforms);
2185 class UniformLocTypesMix : public ExplicitUniformLocationCaseBase
2189 //layout (location = 2) uniform float u0;
2190 //layout (location = 3) uniform vec3 u1;
2191 //layout (location = 0) uniform uint u2;
2192 //layout (location = 1) uniform ivec3 u3;
2193 //layout (location = 4) uniform mat2 u4;
2194 //layout (location = 7) uniform mat2 u5;
2195 //layout (location = 5) uniform mat2 u6;
2196 //layout (location = 6) uniform mat3 u7;
2197 std::vector<Uniform> uniforms;
2198 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::C(2)));
2199 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC3, Loc::C(3)));
2200 uniforms.push_back(Uniform(uniformValueGenerator, GL_UNSIGNED_INT, Loc::C(0)));
2201 uniforms.push_back(Uniform(uniformValueGenerator, GL_INT_VEC3, Loc::C(1)));
2202 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_MAT2, Loc::C(4)));
2203 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_MAT2, Loc::C(7)));
2204 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_MAT2, Loc::C(5)));
2205 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_MAT3, Loc::C(6)));
2206 return doRun(uniforms);
2210 class UniformLocTypesMat : public ExplicitUniformLocationCaseBase
2214 std::vector<Uniform> uniforms;
2215 //layout (location = 1) uniform mat2x3 u0;
2216 //layout (location = 2) uniform mat3x2 u1;
2217 //layout (location = 0) uniform mat2 u2;
2218 //layout (location = 3) uniform imat3x4 u3;
2219 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_MAT2x3, Loc::C(1)));
2220 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_MAT3x2, Loc::C(2)));
2221 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_MAT2, Loc::C(0)));
2222 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_MAT4x3, Loc::C(3)));
2223 return doRun(uniforms);
2227 class UniformLocTypesSamplers : public ExplicitUniformLocationCaseBase
2231 //layout (location = 1) uniform sampler2D s0[3];
2232 //layout (location = 13) uniform sampler2D s1;
2233 std::vector<Uniform> uniforms;
2234 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_SAMPLER_2D, 3), Loc::C(1)));
2235 uniforms.push_back(Uniform(uniformValueGenerator, GL_SAMPLER_2D, Loc::C(13)));
2237 std::vector<GLuint> texUnits;
2238 std::vector<std::vector<GLubyte> > colors;
2240 for (size_t i = 0; i < uniforms.size(); i++)
2242 for (int elem = 0; elem < uniforms[i].type.arraySize; elem++)
2244 texUnits.push_back(uniforms[i].value.iValues[elem]);
2246 std::vector<GLubyte> color(4);
2247 color[0] = static_cast<GLubyte>(255. * uniforms[i].value.fValues[4 * elem + 0] + 0.5);
2248 color[1] = static_cast<GLubyte>(255. * uniforms[i].value.fValues[4 * elem + 1] + 0.5);
2249 color[2] = static_cast<GLubyte>(255. * uniforms[i].value.fValues[4 * elem + 2] + 0.5);
2250 color[3] = static_cast<GLubyte>(255. * uniforms[i].value.fValues[4 * elem + 3] + 0.5);
2251 colors.push_back(color);
2255 std::vector<GLuint> textures(texUnits.size());
2256 glGenTextures((GLsizei)(textures.size()), &textures[0]);
2258 for (size_t i = 0; i < textures.size(); i++)
2260 glActiveTexture(GL_TEXTURE0 + texUnits[i]);
2261 glBindTexture(GL_TEXTURE_2D, textures[i]);
2262 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2263 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &colors[i][0]);
2264 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2267 glActiveTexture(GL_TEXTURE0);
2268 long ret = doRun(uniforms);
2269 glDeleteTextures((GLsizei)(textures.size()), &textures[0]);
2274 class UniformLocTypesStructs : public ExplicitUniformLocationCaseBase
2280 * This test case uses following uniform declarations:
2287 * layout (location = 1) uniform S s0[3];
2288 * layout (location = 13) uniform S s1;
2291 std::vector<UniformType> members;
2292 members.push_back(GL_FLOAT_VEC4);
2293 members.push_back(UniformType(GL_FLOAT, 2));
2294 members.push_back(GL_FLOAT_MAT2);
2295 std::vector<Uniform> uniforms;
2296 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(uniformStructCounter, members, 3), Loc::C(1)));
2297 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(uniformStructCounter, members), Loc::C(13)));
2298 return doRun(uniforms);
2302 class UniformLocArraysNonSpaced : public ExplicitUniformLocationCaseBase
2306 //layout (location = 2) uniform float[3] u0;
2307 //layout (location = 5) uniform vec3[2] u1;
2308 //layout (location = 7) uniform int[3] u2;
2309 //layout (location = 10) uniform ivec4 u3;
2310 std::vector<Uniform> uniforms;
2311 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT, 3), Loc::C(2)));
2312 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT_VEC3, 2), Loc::C(5)));
2313 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_INT, 3), Loc::C(7)));
2314 uniforms.push_back(Uniform(uniformValueGenerator, GL_INT_VEC4, Loc::C(10)));
2315 return doRun(uniforms);
2319 class UniformLocArraySpaced : public ExplicitUniformLocationCaseBase
2323 //layout (location = 2) uniform float u0;
2324 //layout (location = 5) uniform vec3[2] u1;
2325 //layout (location = 8) uniform int[3] u2;
2326 //layout (location = 12) uniform ivec4[1] u3;
2327 std::vector<Uniform> uniforms;
2328 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::C(2)));
2329 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT_VEC3, 2), Loc::C(5)));
2330 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_INT, 3), Loc::C(8)));
2331 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_INT_VEC4, 1), Loc::C(12)));
2332 return doRun(uniforms);
2336 class UniformLocArrayofArrays : public ExplicitUniformLocationCaseBase
2340 //layout (location = 2) uniform float[2][3] u0;
2341 //layout (location = 8) uniform vec3[2][2] u1;
2342 //layout (location = 12) uniform float u2;
2343 std::vector<Uniform> uniforms;
2345 std::vector<int> arraySizesSegmented(2);
2346 arraySizesSegmented[0] = 2;
2347 arraySizesSegmented[1] = 3;
2348 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT, arraySizesSegmented), Loc::C(2)));
2351 std::vector<int> arraySizesSegmented(2);
2352 arraySizesSegmented[0] = arraySizesSegmented[1] = 2;
2354 Uniform(uniformValueGenerator, UniformType(GL_FLOAT_VEC3, arraySizesSegmented), Loc::C(8)));
2356 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::C(12)));
2357 return doRun(uniforms);
2361 class UniformLocMixWithImplicit : public ExplicitUniformLocationCaseBase
2365 //layout (location = 0) uniform float u0;
2366 //layout (location = 2) uniform vec3 u1;
2367 //layout (location = 3) uniform int u2;
2372 std::vector<Uniform> uniforms;
2373 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::C(0, DefOccurence::FSH_OR_CSH)));
2374 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC3, Loc::C(2, DefOccurence::FSH_OR_CSH)));
2375 uniforms.push_back(Uniform(uniformValueGenerator, GL_INT, Loc::C(3, DefOccurence::FSH_OR_CSH)));
2376 return doRun(uniforms);
2380 class UniformLocMixWithImplicit2 : public ExplicitUniformLocationCaseBase
2384 //uniform float[3] u0;
2385 //layout (location = 3) uniform vec3[2] u1;
2386 //uniform int[3] u2;
2387 //layout (location = 8) uniform ivec4 u3;
2388 std::vector<Uniform> uniforms;
2389 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT, 3), Loc::Implicit()));
2390 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT_VEC3, 2), Loc::C(3)));
2391 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_INT, 3), Loc::Implicit()));
2392 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_INT_VEC4, 2), Loc::C(8)));
2393 return doRun(uniforms);
2397 class UniformLocMixWithImplicit3 : public ExplicitUniformLocationCaseBase
2401 //layout (location = 0) uniform float u0; //unused
2402 //layout (location = 2) uniform vec3 u1; //unused
2403 //layout (location = 3) uniform int u2; //unused
2408 std::vector<Uniform> uniforms;
2410 Uniform(uniformValueGenerator, GL_FLOAT, Loc::C(0), DefOccurence::ALL_SH, DefOccurence::NONE_SH));
2412 Uniform(uniformValueGenerator, GL_FLOAT_VEC3, Loc::C(2), DefOccurence::ALL_SH, DefOccurence::NONE_SH));
2414 Uniform(uniformValueGenerator, GL_INT, Loc::C(3), DefOccurence::ALL_SH, DefOccurence::NONE_SH));
2415 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::Implicit()));
2416 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC3, Loc::Implicit()));
2417 uniforms.push_back(Uniform(uniformValueGenerator, GL_INT, Loc::Implicit()));
2418 return doRun(uniforms);
2422 class UniformLocMixWithImplicitMax : public ExplicitUniformLocationCaseBase
2426 long ret = NO_ERROR;
2429 glGetIntegerv(GL_MAX_UNIFORM_LOCATIONS, &max);
2431 const int implicitCount = 1;
2433 int tests[3] = { 0, 3, max - implicitCount };
2435 for (int test = 0; test < 3; test++)
2437 std::vector<Uniform> uniforms;
2439 //for performance reasons fill-up all avaliable locations with an unused arrays.
2440 if (tests[test] > 0)
2443 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT, tests[test]), Loc::C(0),
2444 DefOccurence::ALL_SH, DefOccurence::NONE_SH));
2445 assert(uniforms[uniforms.size() - 1].location.val + uniforms[uniforms.size() - 1].type.arraySize ==
2449 if (tests[test] < max - implicitCount)
2453 Uniform(uniformValueGenerator, UniformType(GL_FLOAT, max - implicitCount - tests[test]),
2454 Loc::C(tests[test] + implicitCount), DefOccurence::ALL_SH, DefOccurence::NONE_SH));
2455 assert(uniforms[uniforms.size() - 1].location.val + uniforms[uniforms.size() - 1].type.arraySize ==
2459 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::Implicit()));
2460 ret |= doRun(uniforms);
2466 class UniformLocMixWithImplicitMaxArray : public ExplicitUniformLocationCaseBase
2470 long ret = NO_ERROR;
2473 glGetIntegerv(GL_MAX_UNIFORM_LOCATIONS, &max);
2475 const int implicitCount = 3;
2477 int tests[3] = { 0, 3, max - 4 };
2479 for (int test = 0; test < 3; test++)
2481 std::vector<Uniform> uniforms;
2483 //for performance reasons fill-up all avaliable locations with an unused arrays.
2484 if (tests[test] > 0)
2487 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT, tests[test]), Loc::C(0),
2488 DefOccurence::ALL_SH, DefOccurence::NONE_SH));
2489 assert(uniforms[uniforms.size() - 1].location.val + uniforms[uniforms.size() - 1].type.arraySize ==
2493 if (tests[test] < max - implicitCount)
2497 Uniform(uniformValueGenerator, UniformType(GL_FLOAT, max - implicitCount - tests[test]),
2498 Loc::C(tests[test] + implicitCount), DefOccurence::ALL_SH, DefOccurence::NONE_SH));
2499 assert(uniforms[uniforms.size() - 1].location.val + uniforms[uniforms.size() - 1].type.arraySize ==
2502 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT, implicitCount), Loc::Implicit()));
2503 ret |= doRun(uniforms);
2509 class UniformLocImplicitInSomeStages : public ExplicitUniformLocationCaseBase
2513 //One shader: uniform float u0;
2514 //Another shader: layout (location = 3) uniform float u0;
2515 std::vector<Uniform> uniforms;
2516 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::C(3, DefOccurence::FSH_OR_CSH)));
2517 return doRun(uniforms);
2521 class UniformLocImplicitInSomeStages2 : public ExplicitUniformLocationCaseBase
2525 //One shader: uniform float u0;
2526 //Another shader: layout (location = 3) uniform float u0; //not used!
2527 std::vector<Uniform> uniforms;
2529 //location only in fsh, declaration in all shaders, usage in all shaders but fsh.
2530 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::C(3, DefOccurence::FSH_OR_CSH),
2531 DefOccurence::ALL_SH, DefOccurence::ALL_BUT_FSH));
2532 return doRun(uniforms);
2536 class UniformLocImplicitInSomeStages3 : public ExplicitUniformLocationCaseBase
2540 std::vector<Uniform> uniforms;
2542 //location only in fsh, declaration in all shaders, usage in all shaders but fsh.
2543 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::C(3, DefOccurence::FSH_OR_CSH),
2544 DefOccurence::ALL_SH, DefOccurence::ALL_BUT_FSH));
2546 //location in all but fsh, declaration in all shaders, usage in fsh.
2547 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::C(2, DefOccurence::ALL_BUT_FSH),
2548 DefOccurence::ALL_SH, DefOccurence::FSH_OR_CSH));
2550 //location only in fsh, declaration in all shaders, usage in all shaders but fsh.
2551 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT, 3), Loc::C(7, DefOccurence::FSH_OR_CSH),
2552 DefOccurence::ALL_SH, DefOccurence::ALL_BUT_FSH));
2554 //location in all but fsh, declaration in all shaders, usage in fsh.
2555 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT, 3),
2556 Loc::C(4, DefOccurence::ALL_BUT_FSH), DefOccurence::ALL_SH,
2557 DefOccurence::FSH_OR_CSH));
2559 //location only in vsh, declaration in all shaders, usage in all shaders but vsh.
2560 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::C(0, DefOccurence::VSH), DefOccurence::ALL_SH,
2561 DefOccurence::ALL_BUT_VSH));
2563 //location only in vsh, declaration in all shaders, usage in all shaders but vsh.
2564 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::C(1, DefOccurence::ALL_BUT_FSH),
2565 DefOccurence::ALL_SH, DefOccurence::ALL_BUT_VSH));
2567 return doRun(uniforms);
2571 class UniformLocNegativeCompileNonNumberLiteral : public ExplicitUniformLocationCaseBase
2575 std::string def = "layout (location = x) uniform float u0;";
2576 return doRunNegativeCompile(def);
2580 class UniformLocNegativeCompileNonConstLoc : public ExplicitUniformLocationCaseBase
2584 std::string def = NL "const int i = 1;" NL "layout (location = i) uniform float u0;";
2585 return doRunNegativeCompile(def);
2589 class UniformLocNegativeLinkLocationReused1 : public ExplicitUniformLocationCaseBase
2593 //layout (location = 2) uniform float u0;
2594 //layout (location = 2) uniform float u1;
2595 std::vector<Uniform> uniforms;
2596 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(2), DefOccurence::FSH_OR_CSH));
2597 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(2), DefOccurence::FSH_OR_CSH));
2598 return doRunNegativeLink(uniforms);
2602 class UniformLocNegativeLinkLocationReused2 : public ExplicitUniformLocationCaseBase
2606 ///layout (location = 2) uniform float u0;
2607 //layout (location = 2) uniform float u1;
2608 std::vector<Uniform> uniforms;
2609 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(2), DefOccurence::FSH_OR_CSH));
2610 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(2), DefOccurence::ALL_BUT_FSH));
2611 return doRunNegativeLink(uniforms);
2615 class UniformLocNegativeLinkMaxLocation : public ExplicitUniformLocationCaseBase
2619 //layout (location = X) uniform float u0;
2620 //Where X is substituted with value of GL_MAX_UNIFORM_LOCATIONS.
2623 glGetIntegerv(GL_MAX_UNIFORM_LOCATIONS, &max);
2625 std::vector<Uniform> uniforms;
2626 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT_VEC4, Loc::C(max), DefOccurence::FSH_OR_CSH));
2628 return doRunNegativeLink(uniforms);
2632 class UniformLocNegativeLinkMaxMaxNumOfLocation : public ExplicitUniformLocationCaseBase
2638 glGetIntegerv(GL_MAX_UNIFORM_LOCATIONS, &max);
2639 std::vector<Uniform> uniforms;
2640 uniforms.push_back(Uniform(uniformValueGenerator, UniformType(GL_FLOAT, max), Loc::C(0),
2641 DefOccurence::FSH_OR_CSH, DefOccurence::NONE_SH));
2642 uniforms.push_back(Uniform(uniformValueGenerator, GL_FLOAT, Loc::Implicit(), DefOccurence::ALL_BUT_FSH));
2643 return doRunNegativeLink(uniforms);
2647 class SubRoutineLoc : public ExplicitUniformLocationCaseBase
2653 //subroutine vec4 st0(float param);
2654 //subroutine(st0) vec4 sf0(float param) { .... };
2655 //subroutine(st0) vec4 sf1(float param) { .... };
2656 SubroutineFunctionSet functions_st0(uniformValueGenerator, 2);
2658 std::vector<SubroutineUniform> subroutineUniforms;
2660 //layout(location = 2) subroutine uniform st0 u0;
2661 subroutineUniforms.push_back(
2662 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(2), 0, DefOccurence::FSH_OR_CSH));
2663 return doRun(subroutineUniforms);
2667 class SubRoutineLocNonDecimal : public ExplicitUniformLocationCaseBase
2672 //subroutine vec4 st0(float param);
2673 //subroutine(st0) vec4 sf0(float param) { .... };
2674 //subroutine(st0) vec4 sf1(float param) { .... };
2675 SubroutineFunctionSet functions_st0(uniformValueGenerator, 2);
2677 std::vector<SubroutineUniform> subroutineUniforms;
2679 //layout(location = 0x0a) subroutine uniform st0 u0;
2680 subroutineUniforms.push_back(SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(0x0a, Loc::Hex), 0,
2681 DefOccurence::FSH_OR_CSH));
2682 //layout(location = 010 ) subroutine uniform st0 u1;
2683 subroutineUniforms.push_back(SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(010, Loc::Oct), 0,
2684 DefOccurence::FSH_OR_CSH));
2685 return doRun(subroutineUniforms);
2689 class SubRoutineLocAllStages : public ExplicitUniformLocationCaseBase
2693 //subroutine vec4 st0(float param);
2694 //subroutine(st0) vec4 sf0(float param) { .... };
2695 //subroutine(st0) vec4 sf1(float param) { .... };
2696 SubroutineFunctionSet functions_st0(uniformValueGenerator, 2);
2698 std::vector<SubroutineUniform> subroutineUniforms;
2700 //layout(location = 2) subroutine uniform st0 u0;
2701 subroutineUniforms.push_back(SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(2)));
2702 return doRun(subroutineUniforms);
2706 class SubRoutineLocArrays : public ExplicitUniformLocationCaseBase
2711 //subroutine vec4 st0(float param);
2712 //subroutine(st0) vec4 sf0(float param) { .... };
2713 //subroutine(st0) vec4 sf1(float param) { .... };
2714 SubroutineFunctionSet functions_st0(uniformValueGenerator, 2);
2716 std::vector<SubroutineUniform> subroutineUniforms;
2718 //layout(location = 1) subroutine uniform st0 u0[2];
2719 subroutineUniforms.push_back(SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(1), 2));
2720 return doRun(subroutineUniforms);
2724 class SubRoutineLocArraysMix : public ExplicitUniformLocationCaseBase
2728 //subroutine vec4 st0(float param);
2729 //subroutine(st0) vec4 sf0(float param) { .... };
2730 //subroutine(st0) vec4 sf1(float param) { .... };
2731 SubroutineFunctionSet functions_st0(uniformValueGenerator, 2);
2733 //subroutine vec4 st1(float param);
2734 //subroutine(st1) vec4 sf2(float param) { .... };
2735 //subroutine(st1) vec4 sf3(float param) { .... };
2736 SubroutineFunctionSet functions_st1(uniformValueGenerator, 2);
2738 std::vector<SubroutineUniform> subroutineUniforms;
2740 //layout(location = 1) subroutine uniform st0 u0[2];
2741 subroutineUniforms.push_back(SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(1), 2));
2743 ////layout(location = 3) subroutine uniform st0 u1[2][3];
2744 std::vector<int> arraySizesSegmented(2);
2745 arraySizesSegmented[0] = 2;
2746 arraySizesSegmented[1] = 3;
2747 subroutineUniforms.push_back(
2748 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(3), arraySizesSegmented));
2750 //layout(location = 9) subroutine uniform st1 u2;
2751 subroutineUniforms.push_back(SubroutineUniform(uniformValueGenerator, functions_st1, Loc::C(9)));
2753 return doRun(subroutineUniforms);
2757 class SubRoutineLocMixWithImplicit : public ExplicitUniformLocationCaseBase
2761 //subroutine vec4 st0(float param);
2762 //subroutine(st0) vec4 sf0(float param) { .... };
2763 //subroutine(st0) vec4 sf1(float param) { .... };
2764 SubroutineFunctionSet functions_st0(uniformValueGenerator, 2);
2766 std::vector<SubroutineUniform> subroutineUniforms;
2767 //subroutine uniform st0 u0;
2768 subroutineUniforms.push_back(SubroutineUniform(uniformValueGenerator, functions_st0, Loc::Implicit()));
2769 //layout(location = 1 ) subroutine uniform st0 u1;
2770 subroutineUniforms.push_back(SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(0)));
2771 //layout(location = 0 ) subroutine uniform st0 u2;
2772 subroutineUniforms.push_back(SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(1)));
2774 return doRun(subroutineUniforms);
2778 class SubRoutineLocCompilationNonNumberLiteral : public ExplicitUniformLocationCaseBase
2784 NL "subroutine vec4 st0(float param);" NL "subroutine(st0) vec4 sf0(float param) { return param; }" NL
2785 "layout(location = x ) subroutine uniform st0 u0;";
2787 return doRunNegativeCompile(def);
2791 class SubRoutineLocCompilationNonConstLoc : public ExplicitUniformLocationCaseBase
2795 std::string def = NL "const int i = 1;" NL "subroutine vec4 st0(float param);" NL
2796 "subroutine(st0) vec4 sf0(float param) { return param; }" NL
2797 "layout(location = i ) subroutine uniform st0 u0;";
2798 return doRunNegativeCompile(def);
2802 class SubRoutineLocLinkLocationReused1 : public ExplicitUniformLocationCaseBase
2806 //layout(location = 1) subroutine uniform st0 u0;
2807 //layout(location = 1) subroutine uniform st0 u0;
2808 SubroutineFunctionSet functions_st0(uniformValueGenerator, 2);
2809 std::vector<SubroutineUniform> subroutineUniforms;
2810 subroutineUniforms.push_back(
2811 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(2), 0, DefOccurence::FSH_OR_CSH));
2812 subroutineUniforms.push_back(
2813 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(2), 0, DefOccurence::FSH_OR_CSH));
2814 return doRunNegativeLink(subroutineUniforms);
2818 class SubRoutineLocLinkLocationMaxLocation : public ExplicitUniformLocationCaseBase
2822 //layout(location = N) subroutine uniform st0 u0;
2823 //Where X is substituted with value of GL_MAX_UNIFORM_LOCATIONS.
2826 glGetIntegerv(GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS, &max);
2827 SubroutineFunctionSet functions_st0(uniformValueGenerator, 2);
2828 std::vector<SubroutineUniform> subroutineUniforms;
2829 subroutineUniforms.push_back(
2830 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(max), 0, DefOccurence::FSH_OR_CSH));
2831 return doRunNegativeLink(subroutineUniforms);
2835 class SubRoutineLocLinkMaxNumOfLocations : public ExplicitUniformLocationCaseBase
2841 glGetIntegerv(GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS, &max);
2842 SubroutineFunctionSet functions_st0(uniformValueGenerator, 2);
2843 std::vector<SubroutineUniform> subroutineUniforms;
2844 subroutineUniforms.push_back(
2845 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(0), max, DefOccurence::FSH_OR_CSH, false));
2846 subroutineUniforms.push_back(
2847 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::Implicit(), 0, DefOccurence::FSH_OR_CSH));
2848 return doRunNegativeLink(subroutineUniforms);
2852 class SubroutineIndex : public ExplicitUniformLocationCaseBase
2858 //subroutine vec4 st0(float param);
2859 SubroutineFunctionSet functions_st0(uniformValueGenerator);
2860 //layout(index = 1) subroutine(st0) vec4 sf0(float param) { .... };
2861 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(1)));
2862 //layout(index = 2) subroutine(st0) vec4 sf1(float param) { .... };
2863 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(2)));
2865 std::vector<SubroutineUniform> subroutineUniforms;
2867 //subroutine uniform st0 u0;
2868 subroutineUniforms.push_back(
2869 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::Implicit(), 0, DefOccurence::FSH_OR_CSH));
2870 return doRun(subroutineUniforms);
2874 class SubroutineIndexNonDecimal : public ExplicitUniformLocationCaseBase
2880 //subroutine vec4 st0(float param);
2881 SubroutineFunctionSet functions_st0(uniformValueGenerator);
2882 //layout(index = 0x0a) subroutine(st0) vec4 sf0(float param) { .... };
2883 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(0x0a, Index::Hex)));
2884 //layout(index = 010 ) subroutine(st0) vec4 sf1(float param) { .... };
2885 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(010, Index::Oct)));
2887 std::vector<SubroutineUniform> subroutineUniforms;
2889 //subroutine uniform st0 u0;
2890 subroutineUniforms.push_back(
2891 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::Implicit(), 0, DefOccurence::FSH_OR_CSH));
2893 return doRun(subroutineUniforms);
2897 class SubroutineIndexLoc : public ExplicitUniformLocationCaseBase
2904 //subroutine vec4 st0(float param);
2905 SubroutineFunctionSet functions_st0(uniformValueGenerator);
2906 //layout(index = 1) subroutine(st0) vec4 sf0(float param) { .... };
2907 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(1)));
2908 //layout(index = 2) subroutine(st0) vec4 sf1(float param) { .... };
2909 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(2)));
2911 std::vector<SubroutineUniform> subroutineUniforms;
2913 //layout(location = 3) subroutine uniform st0 u0;
2914 subroutineUniforms.push_back(
2915 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(3), 0, DefOccurence::FSH_OR_CSH));
2916 return doRun(subroutineUniforms);
2920 class SubroutineIndexNonCont : public ExplicitUniformLocationCaseBase
2926 //subroutine vec4 st0(float param);
2927 SubroutineFunctionSet functions_st0(uniformValueGenerator);
2928 //layout(index = 0) subroutine(st0) vec4 sf0(float param) { .... };
2929 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(0)));
2930 //layout(index = 2) subroutine(st0) vec4 sf1(float param) { .... };
2931 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(2)));
2933 std::vector<SubroutineUniform> subroutineUniforms;
2935 //layout(location = 2) subroutine uniform st0 u0;
2936 subroutineUniforms.push_back(
2937 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(2), 0, DefOccurence::FSH_OR_CSH));
2938 return doRun(subroutineUniforms);
2942 class SubroutineIndexMultUniforms : public ExplicitUniformLocationCaseBase
2949 //subroutine vec4 st0(float param);
2950 SubroutineFunctionSet functions_st0(uniformValueGenerator);
2951 //layout(index = 1) subroutine(st0) vec4 sf0(float param) { .... };
2952 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(1)));
2953 //layout(index = 3) subroutine(st0) vec4 sf1(float param) { .... };
2954 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(3)));
2956 //subroutine vec4 st1(float param);
2957 SubroutineFunctionSet functions_st1(uniformValueGenerator);
2958 //layout(index = 2) subroutine(st1) vec4 sf2(float param) { .... };
2959 functions_st1.push_back(SubroutineFunction(uniformValueGenerator, Index::C(2)));
2960 //layout(index = 0) subroutine(st1) vec4 sf3(float param) { .... };
2961 functions_st1.push_back(SubroutineFunction(uniformValueGenerator, Index::C(0)));
2963 std::vector<SubroutineUniform> subroutineUniforms;
2964 //layout(location = 1) subroutine uniform st0 u0;
2965 subroutineUniforms.push_back(
2966 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(1), 0, DefOccurence::FSH_OR_CSH));
2967 //layout(location = 9) subroutine uniform st1 u1;
2968 subroutineUniforms.push_back(
2969 SubroutineUniform(uniformValueGenerator, functions_st1, Loc::C(9), 0, DefOccurence::FSH_OR_CSH));
2971 return doRun(subroutineUniforms);
2975 class SubroutineIndexAllstages : public ExplicitUniformLocationCaseBase
2980 //subroutine vec4 st0(float param);
2981 SubroutineFunctionSet functions_st0(uniformValueGenerator);
2982 //layout(index = 1) subroutine(st0) vec4 sf0(float param) { .... };
2983 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(1)));
2984 //layout(index = 2) subroutine(st0) vec4 sf1(float param) { .... };
2985 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(2)));
2987 std::vector<SubroutineUniform> subroutineUniforms;
2989 //subroutine uniform st0 u0;
2990 subroutineUniforms.push_back(
2991 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::Implicit(), 0, DefOccurence::ALL_SH));
2992 return doRun(subroutineUniforms);
2996 class SubroutineIndexMixImplicit : public ExplicitUniformLocationCaseBase
3001 //subroutine vec4 st0(float param);
3002 SubroutineFunctionSet functions_st0(uniformValueGenerator);
3003 //subroutine(st0) vec4 sf0(float param) { .... };
3004 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::Implicit()));
3005 //layout(index = 1) subroutine(st0) vec4 sf1(float param) { .... };
3006 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(1)));
3007 //layout(index = 0) subroutine(st0) vec4 sf1(float param) { .... };
3008 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(0)));
3010 std::vector<SubroutineUniform> subroutineUniforms;
3012 //layout(location = 2) subroutine uniform st0 u0;
3013 subroutineUniforms.push_back(
3014 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::C(2), 0, DefOccurence::FSH_OR_CSH));
3015 return doRun(subroutineUniforms);
3019 class SubroutineIndexNegativeCompilationNonNumberLiteral : public ExplicitUniformLocationCaseBase
3023 std::string def = NL "subroutine vec4 st0(float param);" NL
3024 "layout(index = x) subroutine(st0) vec4 sf1(float param) { return param; };";
3025 return doRunNegativeCompile(def);
3029 class SubroutineIndexNegativeCompilationNonConstIndex : public ExplicitUniformLocationCaseBase
3034 NL "const int i = 1;" NL "layout(index = i) subroutine(st0) vec4 sf1(float param) { return param; };";
3035 return doRunNegativeCompile(def);
3039 class SubroutineIndexNegativeLinkIndexReused : public ExplicitUniformLocationCaseBase
3043 //subroutine vec4 st0(float param);
3044 SubroutineFunctionSet functions_st0(uniformValueGenerator);
3045 //layout(index = 2) subroutine(st0) vec4 sf0(float param) { .... };
3046 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(2)));
3047 //layout(index = 2) subroutine(st0) vec4 sf1(float param) { .... };
3048 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(2)));
3050 std::vector<SubroutineUniform> subroutineUniforms;
3052 //subroutine uniform st0 u0;
3053 subroutineUniforms.push_back(
3054 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::Implicit(), 0, DefOccurence::FSH_OR_CSH));
3055 return doRunNegativeLink(subroutineUniforms);
3059 class SubroutineIndexNegativeLinkMaxIndex : public ExplicitUniformLocationCaseBase
3065 glGetIntegerv(GL_MAX_SUBROUTINES, &max);
3067 //subroutine vec4 st0(float param);
3068 SubroutineFunctionSet functions_st0(uniformValueGenerator);
3069 //layout(index = N) subroutine(st0) vec4 sf0(float param) { .... };
3070 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(max)));
3072 std::vector<SubroutineUniform> subroutineUniforms;
3074 //subroutine uniform st0 u0;
3075 subroutineUniforms.push_back(
3076 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::Implicit(), 0, DefOccurence::FSH_OR_CSH));
3077 return doRunNegativeLink(subroutineUniforms);
3081 class SubroutineIndexNegativeLinkMaxNumOfIndices : public ExplicitUniformLocationCaseBase
3085 //subroutine vec4 st0(float param);
3086 SubroutineFunctionSet functions_st0(uniformValueGenerator);
3089 glGetIntegerv(GL_MAX_SUBROUTINES, &max);
3091 for (int i = 0; i < max; i++)
3093 //layout(index = N) subroutine(st0) vec4 sf0(float param) { .... };
3094 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::C(i)));
3096 functions_st0.push_back(SubroutineFunction(uniformValueGenerator, Index::Implicit()));
3098 std::vector<SubroutineUniform> subroutineUniforms;
3100 //subroutine uniform st0 u0;
3101 subroutineUniforms.push_back(
3102 SubroutineUniform(uniformValueGenerator, functions_st0, Loc::Implicit(), 0, DefOccurence::FSH_OR_CSH));
3103 return doRunNegativeLink(subroutineUniforms);
3108 ExplicitUniformLocationGLTests::ExplicitUniformLocationGLTests(glcts::Context& context)
3109 : TestCaseGroup(context, "explicit_uniform_location", "")
3113 ExplicitUniformLocationGLTests::~ExplicitUniformLocationGLTests(void)
3117 void ExplicitUniformLocationGLTests::init()
3119 using namespace glcts;
3121 Logger::setOutput(m_context.getTestContext().getLog());
3122 addChild(new TestSubcase(m_context, "uniform-loc", TestSubcase::Create<UniformLoc>));
3123 addChild(new TestSubcase(m_context, "uniform-loc-nondecimal", TestSubcase::Create<UniformLocNonDec>));
3124 addChild(new TestSubcase(m_context, "uniform-loc-all-stages", TestSubcase::Create<UniformLocMultipleStages>));
3126 new TestSubcase(m_context, "uniform-loc-multiple-uniforms", TestSubcase::Create<UniformLocMultipleUniforms>));
3127 addChild(new TestSubcase(m_context, "uniform-loc-types-mix", TestSubcase::Create<UniformLocTypesMix>));
3128 addChild(new TestSubcase(m_context, "uniform-loc-types-mat", TestSubcase::Create<UniformLocTypesMat>));
3129 addChild(new TestSubcase(m_context, "uniform-loc-types-structs", TestSubcase::Create<UniformLocTypesStructs>));
3130 addChild(new TestSubcase(m_context, "uniform-loc-types-samplers", TestSubcase::Create<UniformLocTypesSamplers>));
3132 new TestSubcase(m_context, "uniform-loc-arrays-nonspaced", TestSubcase::Create<UniformLocArraysNonSpaced>));
3133 addChild(new TestSubcase(m_context, "uniform-loc-arrays-spaced", TestSubcase::Create<UniformLocArraySpaced>));
3135 addChild(new TestSubcase(m_context, "uniform-loc-arrays-of-arrays", TestSubcase::Create<UniformLocArrayofArrays>));
3138 new TestSubcase(m_context, "uniform-loc-mix-with-implicit", TestSubcase::Create<UniformLocMixWithImplicit>));
3140 new TestSubcase(m_context, "uniform-loc-mix-with-implicit2", TestSubcase::Create<UniformLocMixWithImplicit2>));
3142 new TestSubcase(m_context, "uniform-loc-mix-with-implicit3", TestSubcase::Create<UniformLocMixWithImplicit3>));
3143 addChild(new TestSubcase(m_context, "uniform-loc-mix-with-implicit-max",
3144 TestSubcase::Create<UniformLocMixWithImplicitMax>));
3145 addChild(new TestSubcase(m_context, "uniform-loc-mix-with-implicit-max-array",
3146 TestSubcase::Create<UniformLocMixWithImplicitMaxArray>));
3148 addChild(new TestSubcase(m_context, "uniform-loc-implicit-in-some-stages",
3149 TestSubcase::Create<UniformLocImplicitInSomeStages>));
3150 addChild(new TestSubcase(m_context, "uniform-loc-implicit-in-some-stages2",
3151 TestSubcase::Create<UniformLocImplicitInSomeStages2>));
3152 addChild(new TestSubcase(m_context, "uniform-loc-implicit-in-some-stages3",
3153 TestSubcase::Create<UniformLocImplicitInSomeStages3>));
3155 addChild(new TestSubcase(m_context, "uniform-loc-negative-compile-non-number-literal",
3156 TestSubcase::Create<UniformLocNegativeCompileNonNumberLiteral>));
3157 addChild(new TestSubcase(m_context, "uniform-loc-negative-compile-nonconst-loc",
3158 TestSubcase::Create<UniformLocNegativeCompileNonConstLoc>));
3159 addChild(new TestSubcase(m_context, "uniform-loc-negative-link-location-reused1",
3160 TestSubcase::Create<UniformLocNegativeLinkLocationReused1>));
3161 addChild(new TestSubcase(m_context, "uniform-loc-negative-link-location-reused2",
3162 TestSubcase::Create<UniformLocNegativeLinkLocationReused2>));
3163 addChild(new TestSubcase(m_context, "uniform-loc-negative-link-max-location",
3164 TestSubcase::Create<UniformLocNegativeLinkMaxLocation>));
3165 addChild(new TestSubcase(m_context, "uniform-loc-negative-link-max-num-of-locations",
3166 TestSubcase::Create<UniformLocNegativeLinkMaxMaxNumOfLocation>));
3168 addChild(new TestSubcase(m_context, "subroutine-loc", TestSubcase::Create<SubRoutineLoc>));
3169 addChild(new TestSubcase(m_context, "subroutine-loc-nondecimal", TestSubcase::Create<SubRoutineLocNonDecimal>));
3170 addChild(new TestSubcase(m_context, "subroutine-loc-all-stages", TestSubcase::Create<SubRoutineLocAllStages>));
3171 addChild(new TestSubcase(m_context, "subroutine-loc-arrays", TestSubcase::Create<SubRoutineLocArrays>));
3172 addChild(new TestSubcase(m_context, "subroutine-loc-arrays-mix", TestSubcase::Create<SubRoutineLocArraysMix>));
3173 addChild(new TestSubcase(m_context, "subroutine-loc-mix-with-implicit",
3174 TestSubcase::Create<SubRoutineLocMixWithImplicit>));
3175 addChild(new TestSubcase(m_context, "subroutine-loc-negative-compilation-non-number-literal",
3176 TestSubcase::Create<SubRoutineLocCompilationNonNumberLiteral>));
3177 addChild(new TestSubcase(m_context, "subroutine-loc-negative-compilation-nonconst-loc",
3178 TestSubcase::Create<SubRoutineLocCompilationNonConstLoc>));
3179 addChild(new TestSubcase(m_context, "subroutine-loc-negative-link-location-reused1",
3180 TestSubcase::Create<SubRoutineLocLinkLocationReused1>));
3181 addChild(new TestSubcase(m_context, "subroutine-loc-negative-link-location-max-location",
3182 TestSubcase::Create<SubRoutineLocLinkLocationMaxLocation>));
3183 addChild(new TestSubcase(m_context, "subroutine-loc-negative-link-max-num-of-locations",
3184 TestSubcase::Create<SubRoutineLocLinkMaxNumOfLocations>));
3185 addChild(new TestSubcase(m_context, "subroutine-index", TestSubcase::Create<SubroutineIndex>));
3186 addChild(new TestSubcase(m_context, "subroutine-index-nondecimal", TestSubcase::Create<SubroutineIndexNonDecimal>));
3187 addChild(new TestSubcase(m_context, "subroutine-index-loc", TestSubcase::Create<SubroutineIndexLoc>));
3189 new TestSubcase(m_context, "subroutine-index-non-continuous", TestSubcase::Create<SubroutineIndexNonCont>));
3190 addChild(new TestSubcase(m_context, "subroutine-index-multiple-uniforms",
3191 TestSubcase::Create<SubroutineIndexMultUniforms>));
3192 addChild(new TestSubcase(m_context, "subroutine-index-all-stages", TestSubcase::Create<SubroutineIndexAllstages>));
3194 new TestSubcase(m_context, "subroutine-index-mix-implicit", TestSubcase::Create<SubroutineIndexMixImplicit>));
3195 addChild(new TestSubcase(m_context, "subroutine-index-negative-compilation-non-number-literal",
3196 TestSubcase::Create<SubroutineIndexNegativeCompilationNonNumberLiteral>));
3197 addChild(new TestSubcase(m_context, "subroutine-index-negative-compilation-nonconst-index",
3198 TestSubcase::Create<SubroutineIndexNegativeCompilationNonConstIndex>));
3199 addChild(new TestSubcase(m_context, "subroutine-index-negative-link-index-reused",
3200 TestSubcase::Create<SubroutineIndexNegativeLinkIndexReused>));
3201 addChild(new TestSubcase(m_context, "subroutine-index-negative-link-location-maxindex",
3202 TestSubcase::Create<SubroutineIndexNegativeLinkMaxIndex>));
3203 addChild(new TestSubcase(m_context, "subroutine-index-negative-link-max-num-of-indices",
3204 TestSubcase::Create<SubroutineIndexNegativeLinkMaxNumOfIndices>));
3207 ExplicitUniformLocationES31Tests::ExplicitUniformLocationES31Tests(glcts::Context& context)
3208 : TestCaseGroup(context, "explicit_uniform_location", "")
3212 ExplicitUniformLocationES31Tests::~ExplicitUniformLocationES31Tests(void)
3216 void ExplicitUniformLocationES31Tests::init()
3218 using namespace glcts;
3219 Logger::setOutput(m_context.getTestContext().getLog());
3220 addChild(new TestSubcase(m_context, "uniform-loc", TestSubcase::Create<UniformLoc>));
3221 addChild(new TestSubcase(m_context, "uniform-loc-nondecimal", TestSubcase::Create<UniformLocNonDec>));
3222 addChild(new TestSubcase(m_context, "uniform-loc-all-stages", TestSubcase::Create<UniformLocMultipleStages>));
3224 new TestSubcase(m_context, "uniform-loc-multiple-uniforms", TestSubcase::Create<UniformLocMultipleUniforms>));
3225 addChild(new TestSubcase(m_context, "uniform-loc-types-mix", TestSubcase::Create<UniformLocTypesMix>));
3226 addChild(new TestSubcase(m_context, "uniform-loc-types-mat", TestSubcase::Create<UniformLocTypesMat>));
3227 addChild(new TestSubcase(m_context, "uniform-loc-types-structs", TestSubcase::Create<UniformLocTypesStructs>));
3228 addChild(new TestSubcase(m_context, "uniform-loc-types-samplers", TestSubcase::Create<UniformLocTypesSamplers>));
3230 new TestSubcase(m_context, "uniform-loc-arrays-nonspaced", TestSubcase::Create<UniformLocArraysNonSpaced>));
3231 addChild(new TestSubcase(m_context, "uniform-loc-arrays-spaced", TestSubcase::Create<UniformLocArraySpaced>));
3232 addChild(new TestSubcase(m_context, "uniform-loc-arrays-of-arrays", TestSubcase::Create<UniformLocArrayofArrays>));
3234 new TestSubcase(m_context, "uniform-loc-mix-with-implicit", TestSubcase::Create<UniformLocMixWithImplicit>));
3236 new TestSubcase(m_context, "uniform-loc-mix-with-implicit2", TestSubcase::Create<UniformLocMixWithImplicit2>));
3238 new TestSubcase(m_context, "uniform-loc-mix-with-implicit3", TestSubcase::Create<UniformLocMixWithImplicit3>));
3239 addChild(new TestSubcase(m_context, "uniform-loc-mix-with-implicit-max",
3240 TestSubcase::Create<UniformLocMixWithImplicitMax>));
3241 addChild(new TestSubcase(m_context, "uniform-loc-mix-with-implicit-max-array",
3242 TestSubcase::Create<UniformLocMixWithImplicitMaxArray>));
3243 addChild(new TestSubcase(m_context, "uniform-loc-implicit-in-some-stages",
3244 TestSubcase::Create<UniformLocImplicitInSomeStages>));
3245 addChild(new TestSubcase(m_context, "uniform-loc-implicit-in-some-stages2",
3246 TestSubcase::Create<UniformLocImplicitInSomeStages2>));
3247 addChild(new TestSubcase(m_context, "uniform-loc-implicit-in-some-stages3",
3248 TestSubcase::Create<UniformLocImplicitInSomeStages3>));
3249 addChild(new TestSubcase(m_context, "uniform-loc-negative-compile-non-number-literal",
3250 TestSubcase::Create<UniformLocNegativeCompileNonNumberLiteral>));
3251 addChild(new TestSubcase(m_context, "uniform-loc-negative-compile-nonconst-loc",
3252 TestSubcase::Create<UniformLocNegativeCompileNonConstLoc>));
3253 addChild(new TestSubcase(m_context, "uniform-loc-negative-link-location-reused1",
3254 TestSubcase::Create<UniformLocNegativeLinkLocationReused1>));
3255 addChild(new TestSubcase(m_context, "uniform-loc-negative-link-location-reused2",
3256 TestSubcase::Create<UniformLocNegativeLinkLocationReused2>));
3257 addChild(new TestSubcase(m_context, "uniform-loc-negative-link-max-location",
3258 TestSubcase::Create<UniformLocNegativeLinkMaxLocation>));
3259 addChild(new TestSubcase(m_context, "uniform-loc-negative-link-max-num-of-locations",
3260 TestSubcase::Create<UniformLocNegativeLinkMaxMaxNumOfLocation>));