1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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.
21 * \brief Uniform block tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es31fUniformBlockTests.hpp"
25 #include "glsUniformBlockCase.hpp"
26 #include "glsRandomUniformBlockCase.hpp"
27 #include "tcuCommandLine.hpp"
28 #include "deRandom.hpp"
29 #include "deStringUtil.hpp"
43 using gls::UniformBlockCase;
44 using gls::RandomUniformBlockCase;
45 using namespace gls::ub;
47 void createRandomCaseGroup (tcu::TestCaseGroup* parentGroup, Context& context, const char* groupName, const char* description, UniformBlockCase::BufferMode bufferMode, deUint32 features, int numCases, deUint32 baseSeed)
49 tcu::TestCaseGroup* group = new tcu::TestCaseGroup(context.getTestContext(), groupName, description);
50 parentGroup->addChild(group);
52 baseSeed += (deUint32)context.getTestContext().getCommandLine().getBaseSeed();
54 for (int ndx = 0; ndx < numCases; ndx++)
55 group->addChild(new RandomUniformBlockCase(context.getTestContext(), context.getRenderContext(), glu::GLSL_VERSION_310_ES,
56 de::toString(ndx).c_str(), "", bufferMode, features, (deUint32)ndx+baseSeed));
59 class BlockBasicTypeCase : public UniformBlockCase
62 BlockBasicTypeCase (Context& context, const char* name, const char* description, const VarType& type, deUint32 layoutFlags, int numInstances)
63 : UniformBlockCase(context.getTestContext(), context.getRenderContext(), name, description, glu::GLSL_VERSION_310_ES, BUFFERMODE_PER_BLOCK)
65 UniformBlock& block = m_interface.allocBlock("Block");
66 block.addUniform(Uniform("var", type, 0));
67 block.setFlags(layoutFlags);
71 block.setArraySize(numInstances);
72 block.setInstanceName("block");
77 static void createBlockBasicTypeCases (tcu::TestCaseGroup* group, Context& context, const char* name, const VarType& type, deUint32 layoutFlags, int numInstances = 0)
79 group->addChild(new BlockBasicTypeCase(context, (string(name) + "_vertex").c_str(), "", type, layoutFlags|DECLARE_VERTEX, numInstances));
80 group->addChild(new BlockBasicTypeCase(context, (string(name) + "_fragment").c_str(), "", type, layoutFlags|DECLARE_FRAGMENT, numInstances));
82 if (!(layoutFlags & LAYOUT_PACKED))
83 group->addChild(new BlockBasicTypeCase(context, (string(name) + "_both").c_str(), "", type, layoutFlags|DECLARE_VERTEX|DECLARE_FRAGMENT, numInstances));
86 class Block2LevelStructArrayCase : public UniformBlockCase
89 Block2LevelStructArrayCase (Context& context, const char* name, const char* description, deUint32 layoutFlags, BufferMode bufferMode, int numInstances)
90 : UniformBlockCase (context.getTestContext(), context.getRenderContext(), name, description, glu::GLSL_VERSION_310_ES, bufferMode)
91 , m_layoutFlags (layoutFlags)
92 , m_numInstances (numInstances)
98 StructType& typeS = m_interface.allocStruct("S");
99 typeS.addMember("a", VarType(glu::TYPE_UINT_VEC3, PRECISION_HIGH), UNUSED_BOTH);
100 typeS.addMember("b", VarType(VarType(glu::TYPE_FLOAT_MAT2, PRECISION_MEDIUM), 4));
101 typeS.addMember("c", VarType(glu::TYPE_UINT, PRECISION_LOW));
103 UniformBlock& block = m_interface.allocBlock("Block");
104 block.addUniform(Uniform("u", VarType(glu::TYPE_INT, PRECISION_MEDIUM)));
105 block.addUniform(Uniform("s", VarType(VarType(VarType(&typeS), 3), 2)));
106 block.addUniform(Uniform("v", VarType(glu::TYPE_FLOAT_VEC2, PRECISION_MEDIUM)));
107 block.setFlags(m_layoutFlags);
109 if (m_numInstances > 0)
111 block.setInstanceName("block");
112 block.setArraySize(m_numInstances);
117 deUint32 m_layoutFlags;
123 UniformBlockTests::UniformBlockTests (Context& context)
124 : TestCaseGroup(context, "ubo", "Uniform Block tests")
128 UniformBlockTests::~UniformBlockTests (void)
132 void UniformBlockTests::init (void)
134 static const glu::DataType basicTypes[] =
137 glu::TYPE_FLOAT_VEC2,
138 glu::TYPE_FLOAT_VEC3,
139 glu::TYPE_FLOAT_VEC4,
152 glu::TYPE_FLOAT_MAT2,
153 glu::TYPE_FLOAT_MAT3,
154 glu::TYPE_FLOAT_MAT4,
155 glu::TYPE_FLOAT_MAT2X3,
156 glu::TYPE_FLOAT_MAT2X4,
157 glu::TYPE_FLOAT_MAT3X2,
158 glu::TYPE_FLOAT_MAT3X4,
159 glu::TYPE_FLOAT_MAT4X2,
160 glu::TYPE_FLOAT_MAT4X3
169 { "shared", LAYOUT_SHARED },
170 { "packed", LAYOUT_PACKED },
171 { "std140", LAYOUT_STD140 }
180 { "row_major", LAYOUT_ROW_MAJOR },
181 { "column_major", LAYOUT_COLUMN_MAJOR }
187 UniformBlockCase::BufferMode mode;
190 { "per_block_buffer", UniformBlockCase::BUFFERMODE_PER_BLOCK },
191 { "single_buffer", UniformBlockCase::BUFFERMODE_SINGLE }
196 tcu::TestCaseGroup* nestedArrayGroup = new tcu::TestCaseGroup(m_testCtx, "2_level_array", "2-level basic array variable in single buffer");
197 addChild(nestedArrayGroup);
199 for (int layoutFlagNdx = 0; layoutFlagNdx < DE_LENGTH_OF_ARRAY(layoutFlags); layoutFlagNdx++)
201 tcu::TestCaseGroup* layoutGroup = new tcu::TestCaseGroup(m_testCtx, layoutFlags[layoutFlagNdx].name, "");
202 nestedArrayGroup->addChild(layoutGroup);
204 for (int basicTypeNdx = 0; basicTypeNdx < DE_LENGTH_OF_ARRAY(basicTypes); basicTypeNdx++)
206 const glu::DataType type = basicTypes[basicTypeNdx];
207 const char* typeName = glu::getDataTypeName(type);
208 const int childSize = 4;
209 const int parentSize = 3;
210 const VarType childType (VarType(type, glu::isDataTypeBoolOrBVec(type) ? 0 : PRECISION_HIGH), childSize);
211 const VarType parentType (childType, parentSize);
213 createBlockBasicTypeCases(layoutGroup, m_context, typeName, parentType, layoutFlags[layoutFlagNdx].flags);
215 if (glu::isDataTypeMatrix(type))
217 for (int matFlagNdx = 0; matFlagNdx < DE_LENGTH_OF_ARRAY(matrixFlags); matFlagNdx++)
218 createBlockBasicTypeCases(layoutGroup, m_context, (string(matrixFlags[matFlagNdx].name) + "_" + typeName).c_str(),
219 parentType, layoutFlags[layoutFlagNdx].flags|matrixFlags[matFlagNdx].flags);
227 tcu::TestCaseGroup* nestedArrayGroup = new tcu::TestCaseGroup(m_testCtx, "3_level_array", "3-level basic array variable in single buffer");
228 addChild(nestedArrayGroup);
230 for (int layoutFlagNdx = 0; layoutFlagNdx < DE_LENGTH_OF_ARRAY(layoutFlags); layoutFlagNdx++)
232 tcu::TestCaseGroup* layoutGroup = new tcu::TestCaseGroup(m_testCtx, layoutFlags[layoutFlagNdx].name, "");
233 nestedArrayGroup->addChild(layoutGroup);
235 for (int basicTypeNdx = 0; basicTypeNdx < DE_LENGTH_OF_ARRAY(basicTypes); basicTypeNdx++)
237 const glu::DataType type = basicTypes[basicTypeNdx];
238 const char* typeName = glu::getDataTypeName(type);
239 const int childSize0 = 2;
240 const int childSize1 = 4;
241 const int parentSize = 3;
242 const VarType childType0 (VarType(type, glu::isDataTypeBoolOrBVec(type) ? 0 : PRECISION_HIGH), childSize0);
243 const VarType childType1 (childType0, childSize1);
244 const VarType parentType (childType1, parentSize);
246 createBlockBasicTypeCases(layoutGroup, m_context, typeName, parentType, layoutFlags[layoutFlagNdx].flags);
248 if (glu::isDataTypeMatrix(type))
250 for (int matFlagNdx = 0; matFlagNdx < DE_LENGTH_OF_ARRAY(matrixFlags); matFlagNdx++)
251 createBlockBasicTypeCases(layoutGroup, m_context, (string(matrixFlags[matFlagNdx].name) + "_" + typeName).c_str(),
252 parentType, layoutFlags[layoutFlagNdx].flags|matrixFlags[matFlagNdx].flags);
258 // ubo.2_level_struct_array
260 tcu::TestCaseGroup* structArrayArrayGroup = new tcu::TestCaseGroup(m_testCtx, "2_level_struct_array", "Struct array in one uniform block");
261 addChild(structArrayArrayGroup);
263 for (int modeNdx = 0; modeNdx < DE_LENGTH_OF_ARRAY(bufferModes); modeNdx++)
265 tcu::TestCaseGroup* modeGroup = new tcu::TestCaseGroup(m_testCtx, bufferModes[modeNdx].name, "");
266 structArrayArrayGroup->addChild(modeGroup);
268 for (int layoutFlagNdx = 0; layoutFlagNdx < DE_LENGTH_OF_ARRAY(layoutFlags); layoutFlagNdx++)
270 for (int isArray = 0; isArray < 2; isArray++)
272 std::string baseName = layoutFlags[layoutFlagNdx].name;
273 deUint32 baseFlags = layoutFlags[layoutFlagNdx].flags;
275 if (bufferModes[modeNdx].mode == UniformBlockCase::BUFFERMODE_SINGLE && isArray == 0)
276 continue; // Doesn't make sense to add this variant.
279 baseName += "_instance_array";
281 modeGroup->addChild(new Block2LevelStructArrayCase(m_context, (baseName + "_vertex").c_str(), "", baseFlags|DECLARE_VERTEX, bufferModes[modeNdx].mode, isArray ? 3 : 0));
282 modeGroup->addChild(new Block2LevelStructArrayCase(m_context, (baseName + "_fragment").c_str(), "", baseFlags|DECLARE_FRAGMENT, bufferModes[modeNdx].mode, isArray ? 3 : 0));
284 if (!(baseFlags & LAYOUT_PACKED))
285 modeGroup->addChild(new Block2LevelStructArrayCase(m_context, (baseName + "_both").c_str(), "", baseFlags|DECLARE_VERTEX|DECLARE_FRAGMENT, bufferModes[modeNdx].mode, isArray ? 3 : 0));
293 const deUint32 allShaders = FEATURE_VERTEX_BLOCKS|FEATURE_FRAGMENT_BLOCKS|FEATURE_SHARED_BLOCKS;
294 const deUint32 allLayouts = FEATURE_PACKED_LAYOUT|FEATURE_SHARED_LAYOUT|FEATURE_STD140_LAYOUT;
295 const deUint32 allBasicTypes = FEATURE_VECTORS|FEATURE_MATRICES;
296 const deUint32 unused = FEATURE_UNUSED_MEMBERS|FEATURE_UNUSED_UNIFORMS;
297 const deUint32 matFlags = FEATURE_MATRIX_LAYOUT;
298 const deUint32 basicTypeArrays = allShaders|allLayouts|unused|allBasicTypes|matFlags|FEATURE_ARRAYS|FEATURE_ARRAYS_OF_ARRAYS;
299 const deUint32 allFeatures = ~0u;
301 tcu::TestCaseGroup* randomGroup = new tcu::TestCaseGroup(m_testCtx, "random", "Random Uniform Block cases");
302 addChild(randomGroup);
304 createRandomCaseGroup(randomGroup, m_context, "basic_type_arrays", "Arrays, per-block buffers", UniformBlockCase::BUFFERMODE_PER_BLOCK, basicTypeArrays, 25, 1150);
305 createRandomCaseGroup(randomGroup, m_context, "all_per_block_buffers", "All random features, per-block buffers", UniformBlockCase::BUFFERMODE_PER_BLOCK, allFeatures, 50, 11200);
306 createRandomCaseGroup(randomGroup, m_context, "all_shared_buffer", "All random features, shared buffer", UniformBlockCase::BUFFERMODE_SINGLE, allFeatures, 50, 11250);