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 Program interface query test case
22 *//*--------------------------------------------------------------------*/
24 #include "es31fProgramInterfaceQueryTestCase.hpp"
25 #include "es31fProgramInterfaceDefinitionUtil.hpp"
26 #include "tcuTestLog.hpp"
27 #include "gluVarTypeUtil.hpp"
28 #include "gluStrUtil.hpp"
29 #include "gluContextInfo.hpp"
30 #include "gluShaderProgram.hpp"
31 #include "glwFunctions.hpp"
32 #include "glwEnums.hpp"
34 #include "deStringUtil.hpp"
35 #include "deSTLUtil.hpp"
46 using ProgramInterfaceDefinition::VariablePathComponent;
47 using ProgramInterfaceDefinition::VariableSearchFilter;
49 static glw::GLenum getProgramDefaultBlockInterfaceFromStorage (glu::Storage storage)
54 case glu::STORAGE_PATCH_IN:
55 return GL_PROGRAM_INPUT;
57 case glu::STORAGE_OUT:
58 case glu::STORAGE_PATCH_OUT:
59 return GL_PROGRAM_OUTPUT;
61 case glu::STORAGE_UNIFORM:
70 static bool isBufferBackedInterfaceBlockStorage (glu::Storage storage)
72 return storage == glu::STORAGE_BUFFER || storage == glu::STORAGE_UNIFORM;
75 const char* getRequiredExtensionForStage (glu::ShaderType stage)
79 case glu::SHADERTYPE_COMPUTE:
80 case glu::SHADERTYPE_VERTEX:
81 case glu::SHADERTYPE_FRAGMENT:
84 case glu::SHADERTYPE_GEOMETRY:
85 return "GL_EXT_geometry_shader";
87 case glu::SHADERTYPE_TESSELLATION_CONTROL:
88 case glu::SHADERTYPE_TESSELLATION_EVALUATION:
89 return "GL_EXT_tessellation_shader";
97 static int getTypeSize (glu::DataType type)
99 if (type == glu::TYPE_FLOAT)
101 else if (type == glu::TYPE_INT || type == glu::TYPE_UINT)
103 else if (type == glu::TYPE_BOOL)
110 static int getVarTypeSize (const glu::VarType& type)
112 if (type.isBasicType())
114 // return in basic machine units
115 return glu::getDataTypeScalarSize(type.getBasicType()) * getTypeSize(glu::getDataTypeScalarType(type.getBasicType()));
117 else if (type.isStructType())
120 for (int ndx = 0; ndx < type.getStructPtr()->getNumMembers(); ++ndx)
121 size += getVarTypeSize(type.getStructPtr()->getMember(ndx).getType());
124 else if (type.isArrayType())
126 // unsized arrays are handled as if they had only one element
127 if (type.getArraySize() == glu::VarType::UNSIZED_ARRAY)
128 return getVarTypeSize(type.getElementType());
130 return type.getArraySize() * getVarTypeSize(type.getElementType());
139 static glu::MatrixOrder getMatrixOrderFromPath (const std::vector<VariablePathComponent>& path)
141 glu::MatrixOrder order = glu::MATRIXORDER_LAST;
144 for (int pathNdx = 0; pathNdx < (int)path.size(); ++pathNdx)
146 glu::MatrixOrder matOrder;
148 if (path[pathNdx].isInterfaceBlock())
149 matOrder = path[pathNdx].getInterfaceBlock()->layout.matrixOrder;
150 else if (path[pathNdx].isDeclaration())
151 matOrder = path[pathNdx].getDeclaration()->layout.matrixOrder;
152 else if (path[pathNdx].isVariableType())
153 matOrder = glu::MATRIXORDER_LAST;
157 return glu::MATRIXORDER_LAST;
160 if (matOrder != glu::MATRIXORDER_LAST)
170 PropValidator (Context& context, ProgramResourcePropFlags validationProp, const char* requiredExtension);
172 virtual std::string getHumanReadablePropertyString (glw::GLint propVal) const;
173 virtual void validate (const ProgramInterfaceDefinition::Program* program, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const = 0;
175 bool isSupported (void) const;
176 bool isSelected (deUint32 caseFlags) const;
179 void setError (const std::string& err) const;
181 tcu::TestContext& m_testCtx;
182 const glu::RenderContext& m_renderContext;
185 const glu::ContextInfo& m_contextInfo;
186 const char* m_extension;
187 const ProgramResourcePropFlags m_validationProp;
190 PropValidator::PropValidator (Context& context, ProgramResourcePropFlags validationProp, const char* requiredExtension)
191 : m_testCtx (context.getTestContext())
192 , m_renderContext (context.getRenderContext())
193 , m_contextInfo (context.getContextInfo())
194 , m_extension (requiredExtension)
195 , m_validationProp (validationProp)
199 std::string PropValidator::getHumanReadablePropertyString (glw::GLint propVal) const
201 return de::toString(propVal);
204 bool PropValidator::isSupported (void) const
206 if(glu::contextSupports(m_renderContext.getType(), glu::ApiType::es(3, 2)))
208 return m_extension == DE_NULL || m_contextInfo.isExtensionSupported(m_extension);
211 bool PropValidator::isSelected (deUint32 caseFlags) const
213 return (caseFlags & (deUint32)m_validationProp) != 0;
216 void PropValidator::setError (const std::string& err) const
218 // don't overwrite earlier errors
219 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
220 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, err.c_str());
223 class SingleVariableValidator : public PropValidator
226 SingleVariableValidator (Context& context, ProgramResourcePropFlags validationProp, glw::GLuint programID, const VariableSearchFilter& filter, const char* requiredExtension);
228 void validate (const ProgramInterfaceDefinition::Program* program, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
229 virtual void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const = 0;
230 virtual void validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
233 const VariableSearchFilter m_filter;
234 const glw::GLuint m_programID;
237 SingleVariableValidator::SingleVariableValidator (Context& context, ProgramResourcePropFlags validationProp, glw::GLuint programID, const VariableSearchFilter& filter, const char* requiredExtension)
238 : PropValidator (context, validationProp, requiredExtension)
240 , m_programID (programID)
244 void SingleVariableValidator::validate (const ProgramInterfaceDefinition::Program* program, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
246 std::vector<VariablePathComponent> path;
248 if (findProgramVariablePathByPathName(path, program, resource, m_filter))
250 const glu::VarType* variable = (path.back().isVariableType()) ? (path.back().getVariableType()) : (DE_NULL);
252 if (!variable || !variable->isBasicType())
254 m_testCtx.getLog() << tcu::TestLog::Message << "Error, resource name \"" << resource << "\" refers to a non-basic type." << tcu::TestLog::EndMessage;
255 setError("resource not basic type");
258 validateSingleVariable(path, resource, propValue, implementationName);
260 // finding matching variable in any shader is sufficient
263 else if (deStringBeginsWith(resource.c_str(), "gl_"))
265 // special case for builtins
266 validateBuiltinVariable(resource, propValue, implementationName);
270 // we are only supplied good names, generated by ourselves
272 throw tcu::InternalError("Resource name consistency error");
275 void SingleVariableValidator::validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
279 DE_UNREF(implementationName);
283 class SingleBlockValidator : public PropValidator
286 SingleBlockValidator (Context& context, ProgramResourcePropFlags validationProp, glw::GLuint programID, const VariableSearchFilter& filter, const char* requiredExtension);
288 void validate (const ProgramInterfaceDefinition::Program* program, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
289 virtual void validateSingleBlock (const glu::InterfaceBlock& block, const std::vector<int>& instanceIndex, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const = 0;
292 const VariableSearchFilter m_filter;
293 const glw::GLuint m_programID;
296 SingleBlockValidator::SingleBlockValidator (Context& context, ProgramResourcePropFlags validationProp, glw::GLuint programID, const VariableSearchFilter& filter, const char* requiredExtension)
297 : PropValidator (context, validationProp, requiredExtension)
299 , m_programID (programID)
303 void SingleBlockValidator::validate (const ProgramInterfaceDefinition::Program* program, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
305 glu::VarTokenizer tokenizer (resource.c_str());
306 const std::string blockName = tokenizer.getIdentifier();
307 std::vector<int> instanceIndex;
312 while (tokenizer.getToken() == glu::VarTokenizer::TOKEN_LEFT_BRACKET)
315 DE_ASSERT(tokenizer.getToken() == glu::VarTokenizer::TOKEN_NUMBER);
317 instanceIndex.push_back(tokenizer.getNumber());
320 DE_ASSERT(tokenizer.getToken() == glu::VarTokenizer::TOKEN_RIGHT_BRACKET);
325 // no trailing garbage
326 DE_ASSERT(tokenizer.getToken() == glu::VarTokenizer::TOKEN_END);
328 for (int shaderNdx = 0; shaderNdx < (int)program->getShaders().size(); ++shaderNdx)
330 const ProgramInterfaceDefinition::Shader* const shader = program->getShaders()[shaderNdx];
331 if (!m_filter.matchesFilter(shader))
334 for (int blockNdx = 0; blockNdx < (int)shader->getDefaultBlock().interfaceBlocks.size(); ++blockNdx)
336 const glu::InterfaceBlock& block = shader->getDefaultBlock().interfaceBlocks[blockNdx];
338 if (m_filter.matchesFilter(block) && block.interfaceName == blockName)
341 DE_ASSERT(instanceIndex.size() == block.dimensions.size());
343 validateSingleBlock(block, instanceIndex, resource, propValue, implementationName);
349 // we are only supplied good names, generated by ourselves
351 throw tcu::InternalError("Resource name consistency error");
354 class TypeValidator : public SingleVariableValidator
357 TypeValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
359 std::string getHumanReadablePropertyString (glw::GLint propVal) const;
360 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
361 void validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
364 TypeValidator::TypeValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
365 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_TYPE, programID, filter, DE_NULL)
369 std::string TypeValidator::getHumanReadablePropertyString (glw::GLint propVal) const
371 return de::toString(glu::getShaderVarTypeStr(propVal));
374 void TypeValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
376 const glu::VarType* variable = path.back().getVariableType();
379 DE_UNREF(implementationName);
381 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying type, expecting " << glu::getDataTypeName(variable->getBasicType()) << tcu::TestLog::EndMessage;
383 if (variable->getBasicType() != glu::getDataTypeFromGLType(propValue))
385 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << glu::getDataTypeName(glu::getDataTypeFromGLType(propValue)) << tcu::TestLog::EndMessage;
386 setError("resource type invalid");
390 void TypeValidator::validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
392 DE_UNREF(implementationName);
400 { "gl_Position", glu::TYPE_FLOAT_VEC4 },
401 { "gl_FragCoord", glu::TYPE_FLOAT_VEC4 },
402 { "gl_PerVertex.gl_Position", glu::TYPE_FLOAT_VEC4 },
403 { "gl_VertexID", glu::TYPE_INT },
404 { "gl_InvocationID", glu::TYPE_INT },
405 { "gl_NumWorkGroups", glu::TYPE_UINT_VEC3 },
406 { "gl_FragDepth", glu::TYPE_FLOAT },
407 { "gl_TessLevelOuter[0]", glu::TYPE_FLOAT },
408 { "gl_TessLevelInner[0]", glu::TYPE_FLOAT },
411 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(builtins); ++ndx)
413 if (resource == builtins[ndx].name)
415 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying type, expecting " << glu::getDataTypeName(builtins[ndx].type) << tcu::TestLog::EndMessage;
417 if (glu::getDataTypeFromGLType(propValue) != builtins[ndx].type)
419 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << glu::getDataTypeName(glu::getDataTypeFromGLType(propValue)) << tcu::TestLog::EndMessage;
420 setError("resource type invalid");
429 class ArraySizeValidator : public SingleVariableValidator
432 ArraySizeValidator (Context& context, glw::GLuint programID, int unsizedArraySize, const VariableSearchFilter& filter);
434 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
435 void validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
438 const int m_unsizedArraySize;
441 ArraySizeValidator::ArraySizeValidator (Context& context, glw::GLuint programID, int unsizedArraySize, const VariableSearchFilter& filter)
442 : SingleVariableValidator (context, PROGRAMRESOURCEPROP_ARRAY_SIZE, programID, filter, DE_NULL)
443 , m_unsizedArraySize (unsizedArraySize)
447 void ArraySizeValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
449 const VariablePathComponent nullComponent;
450 const VariablePathComponent& enclosingcomponent = (path.size() > 1) ? (path[path.size()-2]) : (nullComponent);
452 const bool isArray = enclosingcomponent.isVariableType() && enclosingcomponent.getVariableType()->isArrayType();
453 const bool inUnsizedArray = isArray && (enclosingcomponent.getVariableType()->getArraySize() == glu::VarType::UNSIZED_ARRAY);
454 const int arraySize = (!isArray) ? (1) : (inUnsizedArray) ? (m_unsizedArraySize) : (enclosingcomponent.getVariableType()->getArraySize());
456 DE_ASSERT(arraySize >= 0);
458 DE_UNREF(implementationName);
460 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying array size, expecting " << arraySize << tcu::TestLog::EndMessage;
462 if (arraySize != propValue)
464 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
465 setError("resource array size invalid");
469 void ArraySizeValidator::validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
471 DE_UNREF(implementationName);
479 { "gl_Position", 1 },
480 { "gl_VertexID", 1 },
481 { "gl_FragCoord", 1 },
482 { "gl_PerVertex.gl_Position", 1 },
483 { "gl_InvocationID", 1 },
484 { "gl_NumWorkGroups", 1 },
485 { "gl_FragDepth", 1 },
486 { "gl_TessLevelOuter[0]", 4 },
487 { "gl_TessLevelInner[0]", 2 },
490 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(builtins); ++ndx)
492 if (resource == builtins[ndx].name)
494 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying array size, expecting " << builtins[ndx].arraySize << tcu::TestLog::EndMessage;
496 if (propValue != builtins[ndx].arraySize)
498 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
499 setError("resource array size invalid");
508 class ArrayStrideValidator : public SingleVariableValidator
511 ArrayStrideValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
513 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
516 ArrayStrideValidator::ArrayStrideValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
517 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_ARRAY_STRIDE, programID, filter, DE_NULL)
521 void ArrayStrideValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
523 const VariablePathComponent nullComponent;
524 const VariablePathComponent& component = path.back();
525 const VariablePathComponent& enclosingcomponent = (path.size() > 1) ? (path[path.size()-2]) : (nullComponent);
526 const VariablePathComponent& firstComponent = path.front();
528 const bool isBufferBlock = firstComponent.isInterfaceBlock() && isBufferBackedInterfaceBlockStorage(firstComponent.getInterfaceBlock()->storage);
529 const bool isArray = enclosingcomponent.isVariableType() && enclosingcomponent.getVariableType()->isArrayType();
530 const bool isAtomicCounter = glu::isDataTypeAtomicCounter(component.getVariableType()->getBasicType()); // atomic counters are buffer backed with a stride of 4 basic machine units
533 DE_UNREF(implementationName);
535 // Layout tests will verify layouts of buffer backed arrays properly. Here we just check values are greater or equal to the element size
536 if (isBufferBlock && isArray)
538 const int elementSize = glu::getDataTypeScalarSize(component.getVariableType()->getBasicType()) * getTypeSize(glu::getDataTypeScalarType(component.getVariableType()->getBasicType()));
539 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying array stride, expecting greater or equal to " << elementSize << tcu::TestLog::EndMessage;
541 if (propValue < elementSize)
543 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
544 setError("resource array stride invalid");
549 // Atomics are buffer backed with stride of 4 even though they are not in an interface block
550 const int arrayStride = (isAtomicCounter && isArray) ? (4) : (!isBufferBlock && !isAtomicCounter) ? (-1) : (0);
552 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying array stride, expecting " << arrayStride << tcu::TestLog::EndMessage;
554 if (arrayStride != propValue)
556 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
557 setError("resource array stride invalid");
562 class BlockIndexValidator : public SingleVariableValidator
565 BlockIndexValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
567 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
570 BlockIndexValidator::BlockIndexValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
571 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_BLOCK_INDEX, programID, filter, DE_NULL)
575 void BlockIndexValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
577 const VariablePathComponent& firstComponent = path.front();
580 DE_UNREF(implementationName);
582 if (!firstComponent.isInterfaceBlock())
584 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying block index, expecting -1" << tcu::TestLog::EndMessage;
588 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
589 setError("resource block index invalid");
594 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying block index, expecting a valid block index" << tcu::TestLog::EndMessage;
598 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
599 setError("resource block index invalid");
603 const glw::Functions& gl = m_renderContext.getFunctions();
604 const glw::GLenum interface = (firstComponent.getInterfaceBlock()->storage == glu::STORAGE_UNIFORM) ? (GL_UNIFORM_BLOCK) :
605 (firstComponent.getInterfaceBlock()->storage == glu::STORAGE_BUFFER) ? (GL_SHADER_STORAGE_BLOCK) :
607 glw::GLint written = 0;
608 std::vector<char> nameBuffer (firstComponent.getInterfaceBlock()->interfaceName.size() + 3 * firstComponent.getInterfaceBlock()->dimensions.size() + 2, '\0'); // +3 for appended "[N]", +1 for '\0' and +1 just for safety
610 gl.getProgramResourceName(m_programID, interface, propValue, (int)nameBuffer.size() - 1, &written, &nameBuffer[0]);
611 GLU_EXPECT_NO_ERROR(gl.getError(), "query block name");
612 TCU_CHECK(written < (int)nameBuffer.size());
613 TCU_CHECK(nameBuffer.back() == '\0');
616 const std::string blockName (&nameBuffer[0], written);
617 std::ostringstream expectedName;
619 expectedName << firstComponent.getInterfaceBlock()->interfaceName;
620 for (int dimensionNdx = 0; dimensionNdx < (int)firstComponent.getInterfaceBlock()->dimensions.size(); ++dimensionNdx)
621 expectedName << "[0]";
623 m_testCtx.getLog() << tcu::TestLog::Message << "Block name with index " << propValue << " is \"" << blockName << "\"" << tcu::TestLog::EndMessage;
624 if (blockName != expectedName.str())
626 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, expected " << expectedName.str() << tcu::TestLog::EndMessage;
627 setError("resource block index invalid");
634 class IsRowMajorValidator : public SingleVariableValidator
637 IsRowMajorValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
639 std::string getHumanReadablePropertyString (glw::GLint propVal) const;
640 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
643 IsRowMajorValidator::IsRowMajorValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
644 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_MATRIX_ROW_MAJOR, programID, filter, DE_NULL)
648 std::string IsRowMajorValidator::getHumanReadablePropertyString (glw::GLint propVal) const
650 return de::toString(glu::getBooleanStr(propVal));
653 void IsRowMajorValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
655 const VariablePathComponent& component = path.back();
656 const VariablePathComponent& firstComponent = path.front();
658 const bool isBufferBlock = firstComponent.isInterfaceBlock() && isBufferBackedInterfaceBlockStorage(firstComponent.getInterfaceBlock()->storage);
659 const bool isMatrix = glu::isDataTypeMatrix(component.getVariableType()->getBasicType());
660 const int expected = (isBufferBlock && isMatrix && getMatrixOrderFromPath(path) == glu::MATRIXORDER_ROW_MAJOR) ? (1) : (0);
663 DE_UNREF(implementationName);
665 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying matrix order, expecting IS_ROW_MAJOR = " << expected << tcu::TestLog::EndMessage;
667 if (propValue != expected)
669 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
670 setError("resource matrix order invalid");
674 class MatrixStrideValidator : public SingleVariableValidator
677 MatrixStrideValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
679 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
682 MatrixStrideValidator::MatrixStrideValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
683 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_MATRIX_STRIDE, programID, filter, DE_NULL)
687 void MatrixStrideValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
689 const VariablePathComponent& component = path.back();
690 const VariablePathComponent& firstComponent = path.front();
692 const bool isBufferBlock = firstComponent.isInterfaceBlock() && isBufferBackedInterfaceBlockStorage(firstComponent.getInterfaceBlock()->storage);
693 const bool isMatrix = glu::isDataTypeMatrix(component.getVariableType()->getBasicType());
696 DE_UNREF(implementationName);
698 // Layout tests will verify layouts of buffer backed arrays properly. Here we just check the stride is is greater or equal to the row/column size
699 if (isBufferBlock && isMatrix)
701 const bool columnMajor = getMatrixOrderFromPath(path) != glu::MATRIXORDER_ROW_MAJOR;
702 const int numMajorElements = (columnMajor) ? (glu::getDataTypeMatrixNumRows(component.getVariableType()->getBasicType())) : (glu::getDataTypeMatrixNumColumns(component.getVariableType()->getBasicType()));
703 const int majorSize = numMajorElements * getTypeSize(glu::getDataTypeScalarType(component.getVariableType()->getBasicType()));
705 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying matrix stride, expecting greater or equal to " << majorSize << tcu::TestLog::EndMessage;
707 if (propValue < majorSize)
709 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
710 setError("resource matrix stride invalid");
715 const int matrixStride = (!isBufferBlock && !glu::isDataTypeAtomicCounter(component.getVariableType()->getBasicType())) ? (-1) : (0);
717 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying matrix stride, expecting " << matrixStride << tcu::TestLog::EndMessage;
719 if (matrixStride != propValue)
721 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
722 setError("resource matrix stride invalid");
727 class AtomicCounterBufferIndexVerifier : public SingleVariableValidator
730 AtomicCounterBufferIndexVerifier (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
732 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
735 AtomicCounterBufferIndexVerifier::AtomicCounterBufferIndexVerifier (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
736 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_ATOMIC_COUNTER_BUFFER_INDEX, programID, filter, DE_NULL)
740 void AtomicCounterBufferIndexVerifier::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
743 DE_UNREF(implementationName);
745 if (!glu::isDataTypeAtomicCounter(path.back().getVariableType()->getBasicType()))
747 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying atomic counter buffer index, expecting -1" << tcu::TestLog::EndMessage;
751 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
752 setError("resource atomic counter buffer index invalid");
757 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying atomic counter buffer index, expecting a valid index" << tcu::TestLog::EndMessage;
761 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
762 setError("resource atomic counter buffer index invalid");
766 const glw::Functions& gl = m_renderContext.getFunctions();
767 glw::GLint numActiveResources = 0;
769 gl.getProgramInterfaceiv(m_programID, GL_ATOMIC_COUNTER_BUFFER, GL_ACTIVE_RESOURCES, &numActiveResources);
770 GLU_EXPECT_NO_ERROR(gl.getError(), "getProgramInterfaceiv(..., GL_ATOMIC_COUNTER_BUFFER, GL_ACTIVE_RESOURCES, ...)");
772 if (propValue >= numActiveResources)
774 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << ", GL_ACTIVE_RESOURCES = " << numActiveResources << tcu::TestLog::EndMessage;
775 setError("resource atomic counter buffer index invalid");
781 class LocationValidator : public SingleVariableValidator
784 LocationValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
786 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
787 void validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
790 LocationValidator::LocationValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
791 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_LOCATION, programID, filter, DE_NULL)
795 static int getVariableLocationLength (const glu::VarType& type)
797 if (type.isBasicType())
799 if (glu::isDataTypeMatrix(type.getBasicType()))
800 return glu::getDataTypeMatrixNumColumns(type.getBasicType());
804 else if (type.isStructType())
807 for (int ndx = 0; ndx < type.getStructPtr()->getNumMembers(); ++ndx)
808 size += getVariableLocationLength(type.getStructPtr()->getMember(ndx).getType());
811 else if (type.isArrayType())
812 return type.getArraySize() * getVariableLocationLength(type.getElementType());
820 static int getIOSubVariableLocation (const std::vector<VariablePathComponent>& path, int startNdx, int currentLocation)
822 if (currentLocation == -1)
825 if (path[startNdx].getVariableType()->isBasicType())
826 return currentLocation;
827 else if (path[startNdx].getVariableType()->isArrayType())
828 return getIOSubVariableLocation(path, startNdx+1, currentLocation);
829 else if (path[startNdx].getVariableType()->isStructType())
831 for (int ndx = 0; ndx < path[startNdx].getVariableType()->getStructPtr()->getNumMembers(); ++ndx)
833 if (&path[startNdx].getVariableType()->getStructPtr()->getMember(ndx).getType() == path[startNdx + 1].getVariableType())
834 return getIOSubVariableLocation(path, startNdx + 1, currentLocation);
836 if (currentLocation != -1)
837 currentLocation += getVariableLocationLength(path[startNdx].getVariableType()->getStructPtr()->getMember(ndx).getType());
840 // could not find member, never happens
851 static int getIOBlockVariableLocation (const std::vector<VariablePathComponent>& path)
853 const glu::InterfaceBlock* block = path.front().getInterfaceBlock();
854 int currentLocation = block->layout.location;
856 // Find the block member
857 for (int memberNdx = 0; memberNdx < (int)block->variables.size(); ++memberNdx)
859 if (block->variables[memberNdx].layout.location != -1)
860 currentLocation = block->variables[memberNdx].layout.location;
862 if (&block->variables[memberNdx] == path[1].getDeclaration())
865 // unspecified + unspecified = unspecified
866 if (currentLocation != -1)
867 currentLocation += getVariableLocationLength(block->variables[memberNdx].varType);
870 // Find subtype location in the complex type
871 return getIOSubVariableLocation(path, 2, currentLocation);
874 static int getExplicitLocationFromPath (const std::vector<VariablePathComponent>& path)
876 const glu::VariableDeclaration* varDecl = (path[0].isInterfaceBlock()) ? (path[1].getDeclaration()) : (path[0].getDeclaration());
878 if (path.front().isInterfaceBlock() && path.front().getInterfaceBlock()->storage == glu::STORAGE_UNIFORM)
880 // inside uniform block
883 else if (path.front().isInterfaceBlock() && (path.front().getInterfaceBlock()->storage == glu::STORAGE_IN ||
884 path.front().getInterfaceBlock()->storage == glu::STORAGE_OUT ||
885 path.front().getInterfaceBlock()->storage == glu::STORAGE_PATCH_IN ||
886 path.front().getInterfaceBlock()->storage == glu::STORAGE_PATCH_OUT))
889 return getIOBlockVariableLocation(path);
891 else if (varDecl->storage == glu::STORAGE_UNIFORM)
893 // default block uniform
894 return varDecl->layout.location;
896 else if (varDecl->storage == glu::STORAGE_IN ||
897 varDecl->storage == glu::STORAGE_OUT ||
898 varDecl->storage == glu::STORAGE_PATCH_IN ||
899 varDecl->storage == glu::STORAGE_PATCH_OUT)
901 // default block input/output
902 return getIOSubVariableLocation(path, 1, varDecl->layout.location);
911 void LocationValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
913 const bool isAtomicCounterUniform = glu::isDataTypeAtomicCounter(path.back().getVariableType()->getBasicType());
914 const bool isUniformBlockVariable = path.front().isInterfaceBlock() && path.front().getInterfaceBlock()->storage == glu::STORAGE_UNIFORM;
915 const bool isVertexShader = m_filter.getShaderTypeBits() == (1u << glu::SHADERTYPE_VERTEX);
916 const bool isFragmentShader = m_filter.getShaderTypeBits() == (1u << glu::SHADERTYPE_FRAGMENT);
917 const glu::Storage storage = (path.front().isInterfaceBlock()) ? (path.front().getInterfaceBlock()->storage) : (path.front().getDeclaration()->storage);
918 const bool isInputVariable = (storage == glu::STORAGE_IN || storage == glu::STORAGE_PATCH_IN);
919 const bool isOutputVariable = (storage == glu::STORAGE_OUT || storage == glu::STORAGE_PATCH_OUT);
920 const int explicitLayoutLocation = getExplicitLocationFromPath(path);
923 std::string reasonStr;
927 if (isAtomicCounterUniform)
929 expectLocation = false;
930 reasonStr = "Atomic counter uniforms have effective location of -1";
932 else if (isUniformBlockVariable)
934 expectLocation = false;
935 reasonStr = "Uniform block variables have effective location of -1";
937 else if (isInputVariable && !isVertexShader && explicitLayoutLocation == -1)
939 expectLocation = false;
940 reasonStr = "Inputs (except for vertex shader inputs) not declared with a location layout qualifier have effective location of -1";
942 else if (isOutputVariable && !isFragmentShader && explicitLayoutLocation == -1)
944 expectLocation = false;
945 reasonStr = "Outputs (except for fragment shader outputs) not declared with a location layout qualifier have effective location of -1";
949 expectLocation = true;
954 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying uniform location, expecting -1. (" << reasonStr << ")" << tcu::TestLog::EndMessage;
958 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
959 setError("resource location invalid");
966 if (explicitLayoutLocation == -1)
968 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying location, expecting a valid location" << tcu::TestLog::EndMessage;
969 locationOk = (propValue != -1);
973 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying location, expecting " << explicitLayoutLocation << tcu::TestLog::EndMessage;
974 locationOk = (propValue == explicitLayoutLocation);
979 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
980 setError("resource location invalid");
984 const VariablePathComponent nullComponent;
985 const VariablePathComponent& enclosingcomponent = (path.size() > 1) ? (path[path.size()-2]) : (nullComponent);
986 const bool isArray = enclosingcomponent.isVariableType() && enclosingcomponent.getVariableType()->isArrayType();
988 const glw::Functions& gl = m_renderContext.getFunctions();
989 const glw::GLenum interface = getProgramDefaultBlockInterfaceFromStorage(storage);
991 m_testCtx.getLog() << tcu::TestLog::Message << "Comparing location to the values returned by GetProgramResourceLocation" << tcu::TestLog::EndMessage;
993 // Test all bottom-level array elements
996 const std::string arrayResourceName = (implementationName.size() > 3) ? (implementationName.substr(0, implementationName.size() - 3)) : (""); // chop "[0]"
998 for (int arrayElementNdx = 0; arrayElementNdx < enclosingcomponent.getVariableType()->getArraySize(); ++arrayElementNdx)
1000 const std::string elementResourceName = arrayResourceName + "[" + de::toString(arrayElementNdx) + "]";
1001 const glw::GLint location = gl.getProgramResourceLocation(m_programID, interface, elementResourceName.c_str());
1003 if (location != propValue+arrayElementNdx)
1006 << tcu::TestLog::Message
1007 << "\tError, getProgramResourceLocation (resource=\"" << elementResourceName << "\") returned location " << location
1008 << ", expected " << (propValue+arrayElementNdx)
1009 << tcu::TestLog::EndMessage;
1010 setError("resource location invalid");
1013 m_testCtx.getLog() << tcu::TestLog::Message << "\tLocation of \"" << elementResourceName << "\":\t" << location << tcu::TestLog::EndMessage;
1018 const glw::GLint location = gl.getProgramResourceLocation(m_programID, interface, implementationName.c_str());
1020 if (location != propValue)
1022 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, getProgramResourceLocation returned location " << location << ", expected " << propValue << tcu::TestLog::EndMessage;
1023 setError("resource location invalid");
1031 void LocationValidator::validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1034 DE_UNREF(implementationName);
1036 // built-ins have no location
1038 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying location, expecting -1" << tcu::TestLog::EndMessage;
1040 if (propValue != -1)
1042 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
1043 setError("resource location invalid");
1047 class VariableNameLengthValidator : public SingleVariableValidator
1050 VariableNameLengthValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
1052 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1053 void validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1054 void validateNameLength (const std::string& implementationName, glw::GLint propValue) const;
1057 VariableNameLengthValidator::VariableNameLengthValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
1058 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_NAME_LENGTH, programID, filter, DE_NULL)
1062 void VariableNameLengthValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1066 validateNameLength(implementationName, propValue);
1069 void VariableNameLengthValidator::validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1072 validateNameLength(implementationName, propValue);
1075 void VariableNameLengthValidator::validateNameLength (const std::string& implementationName, glw::GLint propValue) const
1077 const int expected = (int)implementationName.length() + 1; // includes null byte
1078 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying name length, expecting " << expected << " (" << (int)implementationName.length() << " for \"" << implementationName << "\" + 1 byte for terminating null character)" << tcu::TestLog::EndMessage;
1080 if (propValue != expected)
1082 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, invalid name length, got " << propValue << tcu::TestLog::EndMessage;
1083 setError("name length invalid");
1087 class OffsetValidator : public SingleVariableValidator
1090 OffsetValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
1092 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1095 OffsetValidator::OffsetValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
1096 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_OFFSET, programID, filter, DE_NULL)
1100 void OffsetValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1102 const bool isAtomicCounterUniform = glu::isDataTypeAtomicCounter(path.back().getVariableType()->getBasicType());
1103 const bool isBufferBackedBlockStorage = path.front().isInterfaceBlock() && isBufferBackedInterfaceBlockStorage(path.front().getInterfaceBlock()->storage);
1106 DE_UNREF(implementationName);
1108 if (!isAtomicCounterUniform && !isBufferBackedBlockStorage)
1110 // Not buffer backed
1111 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying offset, expecting -1" << tcu::TestLog::EndMessage;
1113 if (propValue != -1)
1115 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, invalid offset, got " << propValue << tcu::TestLog::EndMessage;
1116 setError("offset invalid");
1121 // Expect a valid offset
1122 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying offset, expecting a valid offset" << tcu::TestLog::EndMessage;
1126 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, invalid offset, got " << propValue << tcu::TestLog::EndMessage;
1127 setError("offset invalid");
1132 class VariableReferencedByShaderValidator : public PropValidator
1135 VariableReferencedByShaderValidator (Context& context, glu::ShaderType shaderType, const VariableSearchFilter& searchFilter);
1137 std::string getHumanReadablePropertyString (glw::GLint propVal) const;
1138 void validate (const ProgramInterfaceDefinition::Program* program, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1141 const VariableSearchFilter m_filter;
1142 const glu::ShaderType m_shaderType;
1145 VariableReferencedByShaderValidator::VariableReferencedByShaderValidator (Context& context, glu::ShaderType shaderType, const VariableSearchFilter& searchFilter)
1146 : PropValidator (context, PROGRAMRESOURCEPROP_REFERENCED_BY_SHADER, getRequiredExtensionForStage(shaderType))
1147 , m_filter (VariableSearchFilter::logicalAnd(VariableSearchFilter::createShaderTypeFilter(shaderType), searchFilter))
1148 , m_shaderType (shaderType)
1150 DE_ASSERT(m_shaderType < glu::SHADERTYPE_LAST);
1153 std::string VariableReferencedByShaderValidator::getHumanReadablePropertyString (glw::GLint propVal) const
1155 return de::toString(glu::getBooleanStr(propVal));
1158 void VariableReferencedByShaderValidator::validate (const ProgramInterfaceDefinition::Program* program, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1160 DE_UNREF(implementationName);
1162 std::vector<VariablePathComponent> dummyPath;
1163 const bool referencedByShader = findProgramVariablePathByPathName(dummyPath, program, resource, m_filter);
1166 << tcu::TestLog::Message
1167 << "Verifying referenced by " << glu::getShaderTypeName(m_shaderType) << " shader, expecting "
1168 << ((referencedByShader) ? ("GL_TRUE") : ("GL_FALSE"))
1169 << tcu::TestLog::EndMessage;
1171 if (propValue != ((referencedByShader) ? (1) : (0)))
1173 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, invalid referenced_by_" << glu::getShaderTypeName(m_shaderType) << ", got " << propValue << tcu::TestLog::EndMessage;
1174 setError("referenced_by_" + std::string(glu::getShaderTypeName(m_shaderType)) + " invalid");
1178 class BlockNameLengthValidator : public SingleBlockValidator
1181 BlockNameLengthValidator (Context& context, const glw::GLuint programID, const VariableSearchFilter& filter);
1183 void validateSingleBlock (const glu::InterfaceBlock& block, const std::vector<int>& instanceIndex, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1186 BlockNameLengthValidator::BlockNameLengthValidator (Context& context, const glw::GLuint programID, const VariableSearchFilter& filter)
1187 : SingleBlockValidator(context, PROGRAMRESOURCEPROP_NAME_LENGTH, programID, filter, DE_NULL)
1191 void BlockNameLengthValidator::validateSingleBlock (const glu::InterfaceBlock& block, const std::vector<int>& instanceIndex, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1193 DE_UNREF(instanceIndex);
1197 const int expected = (int)implementationName.length() + 1; // includes null byte
1198 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying name length, expecting " << expected << " (" << (int)implementationName.length() << " for \"" << implementationName << "\" + 1 byte for terminating null character)" << tcu::TestLog::EndMessage;
1200 if (propValue != expected)
1202 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, invalid name length, got " << propValue << tcu::TestLog::EndMessage;
1203 setError("name length invalid");
1207 class BufferBindingValidator : public SingleBlockValidator
1210 BufferBindingValidator (Context& context, const glw::GLuint programID, const VariableSearchFilter& filter);
1212 void validateSingleBlock (const glu::InterfaceBlock& block, const std::vector<int>& instanceIndex, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1215 BufferBindingValidator::BufferBindingValidator (Context& context, const glw::GLuint programID, const VariableSearchFilter& filter)
1216 : SingleBlockValidator(context, PROGRAMRESOURCEPROP_BUFFER_BINDING, programID, filter, DE_NULL)
1220 void BufferBindingValidator::validateSingleBlock (const glu::InterfaceBlock& block, const std::vector<int>& instanceIndex, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1223 DE_UNREF(implementationName);
1225 if (block.layout.binding != -1)
1228 int dimensionSize = 1;
1230 for (int dimensionNdx = (int)(block.dimensions.size()) - 1; dimensionNdx >= 0; --dimensionNdx)
1232 flatIndex += dimensionSize * instanceIndex[dimensionNdx];
1233 dimensionSize *= block.dimensions[dimensionNdx];
1236 const int expected = (block.dimensions.empty()) ? (block.layout.binding) : (block.layout.binding + flatIndex);
1237 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying block binding, expecting " << expected << tcu::TestLog::EndMessage;
1239 if (propValue != expected)
1241 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, invalid buffer binding, got " << propValue << tcu::TestLog::EndMessage;
1242 setError("buffer binding invalid");
1247 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying buffer binding, expecting a valid binding" << tcu::TestLog::EndMessage;
1251 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, invalid buffer binding, got " << propValue << tcu::TestLog::EndMessage;
1252 setError("buffer binding invalid");
1257 class BlockReferencedByShaderValidator : public PropValidator
1260 BlockReferencedByShaderValidator (Context& context, glu::ShaderType shaderType, const VariableSearchFilter& searchFilter);
1262 std::string getHumanReadablePropertyString (glw::GLint propVal) const;
1263 void validate (const ProgramInterfaceDefinition::Program* program, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1266 const VariableSearchFilter m_filter;
1267 const glu::ShaderType m_shaderType;
1270 BlockReferencedByShaderValidator::BlockReferencedByShaderValidator (Context& context, glu::ShaderType shaderType, const VariableSearchFilter& searchFilter)
1271 : PropValidator (context, PROGRAMRESOURCEPROP_REFERENCED_BY_SHADER, getRequiredExtensionForStage(shaderType))
1272 , m_filter (VariableSearchFilter::logicalAnd(VariableSearchFilter::createShaderTypeFilter(shaderType), searchFilter))
1273 , m_shaderType (shaderType)
1275 DE_ASSERT(m_shaderType < glu::SHADERTYPE_LAST);
1278 std::string BlockReferencedByShaderValidator::getHumanReadablePropertyString (glw::GLint propVal) const
1280 return de::toString(glu::getBooleanStr(propVal));
1283 void BlockReferencedByShaderValidator::validate (const ProgramInterfaceDefinition::Program* program, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1285 const std::string blockName = glu::parseVariableName(resource.c_str());
1286 bool referencedByShader = false;
1288 DE_UNREF(implementationName);
1290 for (int shaderNdx = 0; shaderNdx < (int)program->getShaders().size(); ++shaderNdx)
1292 const ProgramInterfaceDefinition::Shader* const shader = program->getShaders()[shaderNdx];
1293 if (!m_filter.matchesFilter(shader))
1296 for (int blockNdx = 0; blockNdx < (int)shader->getDefaultBlock().interfaceBlocks.size(); ++blockNdx)
1298 const glu::InterfaceBlock& block = shader->getDefaultBlock().interfaceBlocks[blockNdx];
1300 if (m_filter.matchesFilter(block) && block.interfaceName == blockName)
1301 referencedByShader = true;
1306 << tcu::TestLog::Message
1307 << "Verifying referenced by " << glu::getShaderTypeName(m_shaderType) << " shader, expecting "
1308 << ((referencedByShader) ? ("GL_TRUE") : ("GL_FALSE"))
1309 << tcu::TestLog::EndMessage;
1311 if (propValue != ((referencedByShader) ? (1) : (0)))
1313 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, invalid referenced_by_" << glu::getShaderTypeName(m_shaderType) << ", got " << propValue << tcu::TestLog::EndMessage;
1314 setError("referenced_by_" + std::string(glu::getShaderTypeName(m_shaderType)) + " invalid");
1318 class TopLevelArraySizeValidator : public SingleVariableValidator
1321 TopLevelArraySizeValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
1323 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1326 TopLevelArraySizeValidator::TopLevelArraySizeValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
1327 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_TOP_LEVEL_ARRAY_SIZE, programID, filter, DE_NULL)
1331 void TopLevelArraySizeValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1336 DE_ASSERT(path.front().isInterfaceBlock() && path.front().getInterfaceBlock()->storage == glu::STORAGE_BUFFER);
1338 DE_UNREF(implementationName);
1340 if (!path[1].getDeclaration()->varType.isArrayType())
1343 reason = "Top-level block member is not an array";
1345 else if (path[1].getDeclaration()->varType.getElementType().isBasicType())
1348 reason = "Top-level block member is not an array of an aggregate type";
1350 else if (path[1].getDeclaration()->varType.getArraySize() == glu::VarType::UNSIZED_ARRAY)
1353 reason = "Top-level block member is an unsized top-level array";
1357 expected = path[1].getDeclaration()->varType.getArraySize();
1358 reason = "Top-level block member is a sized top-level array";
1361 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying top level array size, expecting " << expected << ". (" << reason << ")." << tcu::TestLog::EndMessage;
1363 if (propValue != expected)
1365 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, invalid top level array size, got " << propValue << tcu::TestLog::EndMessage;
1366 setError("top level array size invalid");
1370 class TopLevelArrayStrideValidator : public SingleVariableValidator
1373 TopLevelArrayStrideValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
1375 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1378 TopLevelArrayStrideValidator::TopLevelArrayStrideValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
1379 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_TOP_LEVEL_ARRAY_STRIDE, programID, filter, DE_NULL)
1383 void TopLevelArrayStrideValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1385 DE_ASSERT(path.front().isInterfaceBlock() && path.front().getInterfaceBlock()->storage == glu::STORAGE_BUFFER);
1387 DE_UNREF(implementationName);
1389 if (!path[1].getDeclaration()->varType.isArrayType())
1391 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying top level array stride, expecting 0. (Top-level block member is not an array)." << tcu::TestLog::EndMessage;
1395 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, top level array stride, got " << propValue << tcu::TestLog::EndMessage;
1396 setError("top level array stride invalid");
1399 else if (path[1].getDeclaration()->varType.getElementType().isBasicType())
1401 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying top level array stride, expecting 0. (Top-level block member is not an array of an aggregate type)." << tcu::TestLog::EndMessage;
1405 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, top level array stride, got " << propValue << tcu::TestLog::EndMessage;
1406 setError("top level array stride invalid");
1411 const int minimumStride = getVarTypeSize(path[1].getDeclaration()->varType.getElementType());
1413 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying top level array stride, expecting greater or equal to " << minimumStride << "." << tcu::TestLog::EndMessage;
1415 if (propValue < minimumStride)
1417 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, invalid top level array stride, got " << propValue << tcu::TestLog::EndMessage;
1418 setError("top level array stride invalid");
1423 class TransformFeedbackResourceValidator : public PropValidator
1426 TransformFeedbackResourceValidator (Context& context, ProgramResourcePropFlags validationProp);
1428 void validate (const ProgramInterfaceDefinition::Program* program, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1431 virtual void validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const = 0;
1432 virtual void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const = 0;
1436 TransformFeedbackResourceValidator::TransformFeedbackResourceValidator (Context& context, ProgramResourcePropFlags validationProp)
1437 : PropValidator(context, validationProp, DE_NULL)
1441 void TransformFeedbackResourceValidator::validate (const ProgramInterfaceDefinition::Program* program, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1443 if (deStringBeginsWith(resource.c_str(), "gl_"))
1445 validateBuiltinVariable(resource, propValue, implementationName);
1449 // Check resource name is a xfb output. (sanity check)
1450 #if defined(DE_DEBUG)
1451 bool generatorFound = false;
1453 // Check the resource name is a valid transform feedback resource and find the name generating resource
1454 for (int varyingNdx = 0; varyingNdx < (int)program->getTransformFeedbackVaryings().size(); ++varyingNdx)
1456 const std::string varyingName = program->getTransformFeedbackVaryings()[varyingNdx];
1457 std::vector<VariablePathComponent> path;
1458 std::vector<std::string> resources;
1460 if (!findProgramVariablePathByPathName(path, program, varyingName, VariableSearchFilter::createShaderTypeStorageFilter(getProgramTransformFeedbackStage(program), glu::STORAGE_OUT)))
1462 // program does not contain feedback varying, not valid program
1467 generateVariableTypeResourceNames(resources, varyingName, *path.back().getVariableType(), RESOURCE_NAME_GENERATION_FLAG_TRANSFORM_FEEDBACK_VARIABLE);
1469 if (de::contains(resources.begin(), resources.end(), resource))
1471 generatorFound = true;
1476 // resource name was not found, should never happen
1477 DE_ASSERT(generatorFound);
1478 DE_UNREF(generatorFound);
1483 std::vector<VariablePathComponent> path;
1485 if (!findProgramVariablePathByPathName(path, program, resource, VariableSearchFilter::createShaderTypeStorageFilter(getProgramTransformFeedbackStage(program), glu::STORAGE_OUT)))
1488 validateSingleVariable(path, resource, propValue, implementationName);
1493 class TransformFeedbackArraySizeValidator : public TransformFeedbackResourceValidator
1496 TransformFeedbackArraySizeValidator (Context& context);
1498 void validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1499 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1502 TransformFeedbackArraySizeValidator::TransformFeedbackArraySizeValidator (Context& context)
1503 : TransformFeedbackResourceValidator(context, PROGRAMRESOURCEPROP_ARRAY_SIZE)
1507 void TransformFeedbackArraySizeValidator::validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1509 DE_UNREF(implementationName);
1513 if (resource == "gl_Position")
1518 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying array size, expecting " << arraySize << tcu::TestLog::EndMessage;
1519 if (arraySize != propValue)
1521 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
1522 setError("resource array size invalid");
1526 void TransformFeedbackArraySizeValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1529 DE_UNREF(implementationName);
1531 const int arraySize = (path.back().getVariableType()->isArrayType()) ? (path.back().getVariableType()->getArraySize()) : (1);
1533 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying array size, expecting " << arraySize << tcu::TestLog::EndMessage;
1534 if (arraySize != propValue)
1536 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
1537 setError("resource array size invalid");
1541 class TransformFeedbackNameLengthValidator : public TransformFeedbackResourceValidator
1544 TransformFeedbackNameLengthValidator (Context& context);
1547 void validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1548 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1549 void validateVariable (const std::string& implementationName, glw::GLint propValue) const;
1552 TransformFeedbackNameLengthValidator::TransformFeedbackNameLengthValidator (Context& context)
1553 : TransformFeedbackResourceValidator(context, PROGRAMRESOURCEPROP_NAME_LENGTH)
1557 void TransformFeedbackNameLengthValidator::validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1560 validateVariable(implementationName, propValue);
1563 void TransformFeedbackNameLengthValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1567 validateVariable(implementationName, propValue);
1570 void TransformFeedbackNameLengthValidator::validateVariable (const std::string& implementationName, glw::GLint propValue) const
1572 const int expected = (int)implementationName.length() + 1; // includes null byte
1573 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying name length, expecting " << expected << " (" << (int)implementationName.length() << " for \"" << implementationName << "\" + 1 byte for terminating null character)" << tcu::TestLog::EndMessage;
1575 if (propValue != expected)
1577 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, invalid name length, got " << propValue << tcu::TestLog::EndMessage;
1578 setError("name length invalid");
1582 class TransformFeedbackTypeValidator : public TransformFeedbackResourceValidator
1585 TransformFeedbackTypeValidator (Context& context);
1587 void validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1588 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1591 TransformFeedbackTypeValidator::TransformFeedbackTypeValidator (Context& context)
1592 : TransformFeedbackResourceValidator(context, PROGRAMRESOURCEPROP_TYPE)
1596 void TransformFeedbackTypeValidator::validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1598 DE_UNREF(implementationName);
1600 glu::DataType varType = glu::TYPE_INVALID;
1602 if (resource == "gl_Position")
1603 varType = glu::TYPE_FLOAT_VEC4;
1607 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying type, expecting " << glu::getDataTypeName(varType) << tcu::TestLog::EndMessage;
1608 if (glu::getDataTypeFromGLType(propValue) != varType)
1610 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << glu::getDataTypeName(glu::getDataTypeFromGLType(propValue)) << tcu::TestLog::EndMessage;
1611 setError("resource type invalid");
1616 void TransformFeedbackTypeValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1619 DE_UNREF(implementationName);
1621 // Unlike other interfaces, xfb program interface uses just variable name to refer to arrays of basic types. (Others use "variable[0]")
1622 // Thus we might end up querying a type for an array. In this case, return the type of an array element.
1623 const glu::VarType& variable = *path.back().getVariableType();
1624 const glu::VarType& elementType = (variable.isArrayType()) ? (variable.getElementType()) : (variable);
1626 DE_ASSERT(elementType.isBasicType());
1628 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying type, expecting " << glu::getDataTypeName(elementType.getBasicType()) << tcu::TestLog::EndMessage;
1629 if (elementType.getBasicType() != glu::getDataTypeFromGLType(propValue))
1631 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << glu::getDataTypeName(glu::getDataTypeFromGLType(propValue)) << tcu::TestLog::EndMessage;
1632 setError("resource type invalid");
1636 class PerPatchValidator : public SingleVariableValidator
1639 PerPatchValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter);
1641 std::string getHumanReadablePropertyString (glw::GLint propVal) const;
1642 void validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1643 void validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const;
1646 PerPatchValidator::PerPatchValidator (Context& context, glw::GLuint programID, const VariableSearchFilter& filter)
1647 : SingleVariableValidator(context, PROGRAMRESOURCEPROP_IS_PER_PATCH, programID, filter, "GL_EXT_tessellation_shader")
1651 std::string PerPatchValidator::getHumanReadablePropertyString (glw::GLint propVal) const
1653 return de::toString(glu::getBooleanStr(propVal));
1656 void PerPatchValidator::validateSingleVariable (const std::vector<VariablePathComponent>& path, const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1658 const glu::Storage storage = (path.front().isInterfaceBlock()) ? (path.front().getInterfaceBlock()->storage) : (path.front().getDeclaration()->storage);
1659 const int expected = (storage == glu::STORAGE_PATCH_IN || storage == glu::STORAGE_PATCH_OUT) ? (1) : (0);
1662 DE_UNREF(implementationName);
1664 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying if is per patch, expecting IS_PER_PATCH = " << expected << tcu::TestLog::EndMessage;
1666 if (propValue != expected)
1668 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
1669 setError("resource is per patch invalid");
1673 void PerPatchValidator::validateBuiltinVariable (const std::string& resource, glw::GLint propValue, const std::string& implementationName) const
1675 DE_UNREF(implementationName);
1683 { "gl_Position", 0 },
1684 { "gl_PerVertex.gl_Position", 0 },
1685 { "gl_InvocationID", 0 },
1686 { "gl_TessLevelOuter[0]", 1 },
1687 { "gl_TessLevelInner[0]", 1 },
1690 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(builtins); ++ndx)
1692 if (resource == builtins[ndx].name)
1694 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying if is per patch, expecting IS_PER_PATCH = " << builtins[ndx].isPerPatch << tcu::TestLog::EndMessage;
1696 if (propValue != builtins[ndx].isPerPatch)
1698 m_testCtx.getLog() << tcu::TestLog::Message << "\tError, got " << propValue << tcu::TestLog::EndMessage;
1699 setError("resource is per patch invalid");
1710 ProgramResourceQueryTestTarget::ProgramResourceQueryTestTarget (ProgramInterface interface_, deUint32 propFlags_)
1711 : interface(interface_)
1712 , propFlags(propFlags_)
1716 case PROGRAMINTERFACE_UNIFORM: DE_ASSERT((propFlags & PROGRAMRESOURCEPROP_UNIFORM_INTERFACE_MASK) == propFlags); break;
1717 case PROGRAMINTERFACE_UNIFORM_BLOCK: DE_ASSERT((propFlags & PROGRAMRESOURCEPROP_UNIFORM_BLOCK_INTERFACE_MASK) == propFlags); break;
1718 case PROGRAMINTERFACE_SHADER_STORAGE_BLOCK: DE_ASSERT((propFlags & PROGRAMRESOURCEPROP_SHADER_STORAGE_BLOCK_MASK) == propFlags); break;
1719 case PROGRAMINTERFACE_PROGRAM_INPUT: DE_ASSERT((propFlags & PROGRAMRESOURCEPROP_PROGRAM_INPUT_MASK) == propFlags); break;
1720 case PROGRAMINTERFACE_PROGRAM_OUTPUT: DE_ASSERT((propFlags & PROGRAMRESOURCEPROP_PROGRAM_OUTPUT_MASK) == propFlags); break;
1721 case PROGRAMINTERFACE_BUFFER_VARIABLE: DE_ASSERT((propFlags & PROGRAMRESOURCEPROP_BUFFER_VARIABLE_MASK) == propFlags); break;
1722 case PROGRAMINTERFACE_TRANSFORM_FEEDBACK_VARYING: DE_ASSERT((propFlags & PROGRAMRESOURCEPROP_TRANSFORM_FEEDBACK_VARYING_MASK) == propFlags); break;
1729 ProgramInterfaceQueryTestCase::ProgramInterfaceQueryTestCase (Context& context, const char* name, const char* description, ProgramResourceQueryTestTarget queryTarget)
1730 : TestCase (context, name, description)
1731 , m_queryTarget (queryTarget)
1735 ProgramInterfaceQueryTestCase::~ProgramInterfaceQueryTestCase (void)
1739 ProgramInterface ProgramInterfaceQueryTestCase::getTargetInterface (void) const
1741 return m_queryTarget.interface;
1744 static glw::GLenum getGLInterfaceEnumValue (ProgramInterface interface)
1748 case PROGRAMINTERFACE_UNIFORM: return GL_UNIFORM;
1749 case PROGRAMINTERFACE_UNIFORM_BLOCK: return GL_UNIFORM_BLOCK;
1750 case PROGRAMINTERFACE_ATOMIC_COUNTER_BUFFER: return GL_ATOMIC_COUNTER_BUFFER;
1751 case PROGRAMINTERFACE_PROGRAM_INPUT: return GL_PROGRAM_INPUT;
1752 case PROGRAMINTERFACE_PROGRAM_OUTPUT: return GL_PROGRAM_OUTPUT;
1753 case PROGRAMINTERFACE_TRANSFORM_FEEDBACK_VARYING: return GL_TRANSFORM_FEEDBACK_VARYING;
1754 case PROGRAMINTERFACE_BUFFER_VARIABLE: return GL_BUFFER_VARIABLE;
1755 case PROGRAMINTERFACE_SHADER_STORAGE_BLOCK: return GL_SHADER_STORAGE_BLOCK;
1762 static bool isInterfaceBlockInterfaceName (const ProgramInterfaceDefinition::Program* program, ProgramInterface interface, const std::string& blockInterfaceName)
1764 deUint32 validStorageBits;
1765 deUint32 searchStageBits;
1767 DE_STATIC_ASSERT(glu::STORAGE_LAST < 32);
1768 DE_STATIC_ASSERT(glu::SHADERTYPE_LAST < 32);
1772 case PROGRAMINTERFACE_UNIFORM_BLOCK:
1773 case PROGRAMINTERFACE_SHADER_STORAGE_BLOCK:
1774 case PROGRAMINTERFACE_ATOMIC_COUNTER_BUFFER:
1777 case PROGRAMINTERFACE_PROGRAM_INPUT:
1778 validStorageBits = (1u << glu::STORAGE_IN) | (1u << glu::STORAGE_PATCH_IN);
1779 searchStageBits = (1u << program->getFirstStage());
1782 case PROGRAMINTERFACE_PROGRAM_OUTPUT:
1783 validStorageBits = (1u << glu::STORAGE_OUT) | (1u << glu::STORAGE_PATCH_OUT);
1784 searchStageBits = (1u << program->getLastStage());
1787 case PROGRAMINTERFACE_TRANSFORM_FEEDBACK_VARYING:
1788 validStorageBits = (1u << glu::STORAGE_OUT);
1789 searchStageBits = (1u << getProgramTransformFeedbackStage(program));
1792 case PROGRAMINTERFACE_UNIFORM:
1793 validStorageBits = (1u << glu::STORAGE_UNIFORM);
1794 searchStageBits = 0xFFFFFFFFu;
1797 case PROGRAMINTERFACE_BUFFER_VARIABLE:
1798 validStorageBits = (1u << glu::STORAGE_BUFFER);
1799 searchStageBits = 0xFFFFFFFFu;
1807 for (int shaderNdx = 0; shaderNdx < (int)program->getShaders().size(); ++shaderNdx)
1809 const ProgramInterfaceDefinition::Shader* const shader = program->getShaders()[shaderNdx];
1810 if (((1u << shader->getType()) & searchStageBits) == 0)
1813 for (int blockNdx = 0; blockNdx < (int)shader->getDefaultBlock().interfaceBlocks.size(); ++blockNdx)
1815 const glu::InterfaceBlock& block = shader->getDefaultBlock().interfaceBlocks[blockNdx];
1817 if (((1u << block.storage) & validStorageBits) == 0)
1820 if (block.interfaceName == blockInterfaceName)
1827 static std::string getInterfaceBlockInteraceNameByMember (const ProgramInterfaceDefinition::Program* program, ProgramInterface interface, const std::string& memberName)
1829 deUint32 validStorageBits;
1830 deUint32 searchStageBits;
1832 DE_STATIC_ASSERT(glu::STORAGE_LAST < 32);
1833 DE_STATIC_ASSERT(glu::SHADERTYPE_LAST < 32);
1837 case PROGRAMINTERFACE_UNIFORM_BLOCK:
1838 case PROGRAMINTERFACE_SHADER_STORAGE_BLOCK:
1839 case PROGRAMINTERFACE_ATOMIC_COUNTER_BUFFER:
1842 case PROGRAMINTERFACE_PROGRAM_INPUT:
1843 validStorageBits = (1u << glu::STORAGE_IN) | (1u << glu::STORAGE_PATCH_IN);
1844 searchStageBits = (1u << program->getFirstStage());
1847 case PROGRAMINTERFACE_PROGRAM_OUTPUT:
1848 validStorageBits = (1u << glu::STORAGE_OUT) | (1u << glu::STORAGE_PATCH_OUT);
1849 searchStageBits = (1u << program->getLastStage());
1852 case PROGRAMINTERFACE_TRANSFORM_FEEDBACK_VARYING:
1853 validStorageBits = (1u << glu::STORAGE_OUT);
1854 searchStageBits = (1u << getProgramTransformFeedbackStage(program));
1857 case PROGRAMINTERFACE_UNIFORM:
1858 validStorageBits = (1u << glu::STORAGE_UNIFORM);
1859 searchStageBits = 0xFFFFFFFFu;
1862 case PROGRAMINTERFACE_BUFFER_VARIABLE:
1863 validStorageBits = (1u << glu::STORAGE_BUFFER);
1864 searchStageBits = 0xFFFFFFFFu;
1872 for (int shaderNdx = 0; shaderNdx < (int)program->getShaders().size(); ++shaderNdx)
1874 const ProgramInterfaceDefinition::Shader* const shader = program->getShaders()[shaderNdx];
1875 if (((1u << shader->getType()) & searchStageBits) == 0)
1878 for (int blockNdx = 0; blockNdx < (int)shader->getDefaultBlock().interfaceBlocks.size(); ++blockNdx)
1880 const glu::InterfaceBlock& block = shader->getDefaultBlock().interfaceBlocks[blockNdx];
1882 if (((1u << block.storage) & validStorageBits) == 0)
1885 for (int varNdx = 0; varNdx < (int)block.variables.size(); ++varNdx)
1887 if (block.variables[varNdx].name == memberName)
1888 return block.interfaceName;
1895 static void queryAndValidateProps (tcu::TestContext& testCtx,
1896 const glw::Functions& gl,
1897 glw::GLuint programID,
1898 ProgramInterface interface,
1899 const char* targetResourceName,
1900 const ProgramInterfaceDefinition::Program* programDefinition,
1901 const std::vector<glw::GLenum>& props,
1902 const std::vector<const PropValidator*>& validators)
1904 const glw::GLenum glInterface = getGLInterfaceEnumValue(interface);
1905 std::string implementationResourceName = targetResourceName;
1906 glw::GLuint resourceNdx;
1907 glw::GLint written = -1;
1909 // prefill result buffer with an invalid value. -1 might be valid sometimes, avoid it. Make buffer one larger
1910 // to allow detection of too many return values
1911 std::vector<glw::GLint> propValues (props.size() + 1, -2);
1913 DE_ASSERT(props.size() == validators.size());
1917 resourceNdx = gl.getProgramResourceIndex(programID, glInterface, targetResourceName);
1918 GLU_EXPECT_NO_ERROR(gl.getError(), "get resource index");
1920 if (resourceNdx == GL_INVALID_INDEX)
1924 bool removeTrailingArray; // convert from "target[0]" -> "target"
1925 bool removeTrailingMember; // convert from "target.member" -> "target"
1926 bool removeIOBlock; // convert from "InterfaceName.target" -> "target"
1927 bool addIOBlock; // convert from "target" -> "InterfaceName.target"
1928 bool addIOBlockArray; // convert from "target" -> "InterfaceName[0].target"
1929 } recoveryStrategies[] =
1932 { true, false, false, false, false },
1933 { false, true, false, false, false },
1934 { false, false, true, false, false },
1935 { false, false, false, true, false },
1936 { false, false, false, false, true },
1938 { true, false, true, false, false },
1939 { true, false, false, true, false },
1940 { true, false, false, false, true },
1941 { false, true, true, false, false },
1942 { false, true, false, true, false },
1943 { false, true, false, false, true },
1946 // The resource name generation in the GL implementations is very commonly broken. Try to
1947 // keep the tests producing useful data even in these cases by attempting to recover from
1948 // common naming bugs. Set test result to failure even if recovery succeeded to signal
1949 // incorrect name generation.
1951 testCtx.getLog() << tcu::TestLog::Message << "getProgramResourceIndex returned GL_INVALID_INDEX for \"" << targetResourceName << "\"" << tcu::TestLog::EndMessage;
1952 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "could not find target resource");
1954 for (int strategyNdx = 0; strategyNdx < DE_LENGTH_OF_ARRAY(recoveryStrategies); ++strategyNdx)
1956 const std::string resourceName = std::string(targetResourceName);
1957 const size_t rootNameEnd = resourceName.find_first_of(".[");
1958 const std::string rootName = resourceName.substr(0, rootNameEnd);
1959 std::string simplifiedResourceName;
1961 if (recoveryStrategies[strategyNdx].removeTrailingArray)
1963 if (de::endsWith(resourceName, "[0]"))
1964 simplifiedResourceName = resourceName.substr(0, resourceName.length() - 3);
1969 if (recoveryStrategies[strategyNdx].removeTrailingMember)
1971 const size_t lastMember = resourceName.find_last_of('.');
1972 if (lastMember != std::string::npos)
1973 simplifiedResourceName = resourceName.substr(0, lastMember);
1978 if (recoveryStrategies[strategyNdx].removeIOBlock)
1980 if (deStringBeginsWith(resourceName.c_str(), "gl_PerVertex."))
1982 // builtin interface bock, remove block name
1983 simplifiedResourceName = resourceName.substr(13);
1985 else if (isInterfaceBlockInterfaceName(programDefinition, interface, rootName))
1987 // user-defined inteface block, remove name
1988 const size_t accessorEnd = resourceName.find('.'); // includes potential array accessor
1990 if (accessorEnd != std::string::npos)
1991 simplifiedResourceName = resourceName.substr(0, accessorEnd+1);
1997 // recovery not applicable
2002 if (recoveryStrategies[strategyNdx].addIOBlock || recoveryStrategies[strategyNdx].addIOBlockArray)
2004 const std::string arrayAccessor = (recoveryStrategies[strategyNdx].addIOBlockArray) ? ("[0]") : ("");
2006 if (deStringBeginsWith(resourceName.c_str(), "gl_") && resourceName.find('.') == std::string::npos)
2008 // free builtin variable, add block name
2009 simplifiedResourceName = "gl_PerVertex" + arrayAccessor + "." + resourceName;
2013 const std::string interafaceName = getInterfaceBlockInteraceNameByMember(programDefinition, interface, rootName);
2015 if (!interafaceName.empty())
2017 // free user variable, add block name
2018 simplifiedResourceName = interafaceName + arrayAccessor + "." + resourceName;
2022 // recovery not applicable
2028 if (simplifiedResourceName.empty())
2031 resourceNdx = gl.getProgramResourceIndex(programID, glInterface, simplifiedResourceName.c_str());
2032 GLU_EXPECT_NO_ERROR(gl.getError(), "get resource index");
2034 // recovery succeeded
2035 if (resourceNdx != GL_INVALID_INDEX)
2037 implementationResourceName = simplifiedResourceName;
2038 testCtx.getLog() << tcu::TestLog::Message << "\tResource not found, continuing anyway using index obtained for resource \"" << simplifiedResourceName << "\"" << tcu::TestLog::EndMessage;
2043 if (resourceNdx == GL_INVALID_INDEX)
2047 gl.getProgramResourceiv(programID, glInterface, resourceNdx, (int)props.size(), &props[0], (int)propValues.size(), &written, &propValues[0]);
2048 GLU_EXPECT_NO_ERROR(gl.getError(), "get props");
2050 if (written != (int)props.size())
2052 testCtx.getLog() << tcu::TestLog::Message << "getProgramResourceiv returned unexpected number of values, expected " << (int)props.size() << ", got " << written << tcu::TestLog::EndMessage;
2053 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "getProgramResourceiv returned unexpected number of values");
2057 if (propValues.back() != -2)
2059 testCtx.getLog() << tcu::TestLog::Message << "getProgramResourceiv post write buffer guard value was modified, too many return values" << tcu::TestLog::EndMessage;
2060 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "getProgramResourceiv returned unexpected number of values");
2063 propValues.pop_back();
2064 DE_ASSERT(validators.size() == propValues.size());
2069 tcu::MessageBuilder message(&testCtx.getLog());
2070 message << "For resource index " << resourceNdx << " (\"" << targetResourceName << "\") got following properties:\n";
2072 for (int propNdx = 0; propNdx < (int)propValues.size(); ++propNdx)
2073 message << "\t" << glu::getProgramResourcePropertyName(props[propNdx]) << ":\t" << validators[propNdx]->getHumanReadablePropertyString(propValues[propNdx]) << "\n";
2075 message << tcu::TestLog::EndMessage;
2080 for (int propNdx = 0; propNdx < (int)propValues.size(); ++propNdx)
2081 validators[propNdx]->validate(programDefinition, targetResourceName, propValues[propNdx], implementationResourceName);
2084 const ProgramInterfaceDefinition::Program* ProgramInterfaceQueryTestCase::getAndCheckProgramDefinition (void)
2086 const ProgramInterfaceDefinition::Program* programDefinition = getProgramDefinition();
2087 DE_ASSERT(programDefinition->isValid());
2089 const bool supportsES32 = glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::es(3, 2));
2091 if (programDefinition->hasStage(glu::SHADERTYPE_TESSELLATION_CONTROL) ||
2092 programDefinition->hasStage(glu::SHADERTYPE_TESSELLATION_EVALUATION))
2094 if (!supportsES32 && !m_context.getContextInfo().isExtensionSupported("GL_EXT_tessellation_shader"))
2095 throw tcu::NotSupportedError("Test requires GL_EXT_tessellation_shader extension");
2098 // Testing IS_PER_PATCH as a part of a larger set is ok, since the extension is checked
2099 // before query. However, we don't want IS_PER_PATCH-specific tests to become noop and pass.
2100 if (m_queryTarget.propFlags == PROGRAMRESOURCEPROP_IS_PER_PATCH)
2102 if (!supportsES32 && !m_context.getContextInfo().isExtensionSupported("GL_EXT_tessellation_shader"))
2103 throw tcu::NotSupportedError("Test requires GL_EXT_tessellation_shader extension");
2106 if (programDefinition->hasStage(glu::SHADERTYPE_GEOMETRY))
2108 if (!supportsES32 && !m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
2109 throw tcu::NotSupportedError("Test requires GL_EXT_geometry_shader extension");
2112 if (programContainsIOBlocks(programDefinition))
2114 if (!supportsES32 && !m_context.getContextInfo().isExtensionSupported("GL_EXT_shader_io_blocks"))
2115 throw tcu::NotSupportedError("Test requires GL_EXT_shader_io_blocks extension");
2118 return programDefinition;
2121 int ProgramInterfaceQueryTestCase::getMaxPatchVertices (void)
2123 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2124 glw::GLint maxPatchVertices = 0;
2126 gl.getIntegerv(GL_MAX_PATCH_VERTICES, &maxPatchVertices);
2127 GLU_EXPECT_NO_ERROR(gl.getError(), "getIntegerv(GL_MAX_PATCH_VERTICES)");
2128 return maxPatchVertices;
2131 ProgramInterfaceQueryTestCase::IterateResult ProgramInterfaceQueryTestCase::iterate (void)
2136 const PropValidator* validator;
2139 const ProgramInterfaceDefinition::Program* programDefinition = getAndCheckProgramDefinition();
2140 const std::vector<std::string> targetResources = getQueryTargetResources();
2141 glu::ShaderProgram program (m_context.getRenderContext(), generateProgramInterfaceProgramSources(programDefinition));
2143 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2147 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Program", "Program");
2149 // Feedback varyings
2150 if (!programDefinition->getTransformFeedbackVaryings().empty())
2152 tcu::MessageBuilder builder(&m_testCtx.getLog());
2153 builder << "Transform feedback varyings: {";
2154 for (int ndx = 0; ndx < (int)programDefinition->getTransformFeedbackVaryings().size(); ++ndx)
2158 builder << "\"" << programDefinition->getTransformFeedbackVaryings()[ndx] << "\"";
2160 builder << "}" << tcu::TestLog::EndMessage;
2163 m_testCtx.getLog() << program;
2164 if (!program.isOk())
2166 m_testCtx.getLog() << tcu::TestLog::Message << "Program build failed, checking if program exceeded implementation limits" << tcu::TestLog::EndMessage;
2167 checkProgramResourceUsage(programDefinition, m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
2170 throw tcu::TestError("could not build program");
2174 // Check interface props
2176 switch (m_queryTarget.interface)
2178 case PROGRAMINTERFACE_UNIFORM:
2180 const VariableSearchFilter uniformFilter = VariableSearchFilter::createStorageFilter(glu::STORAGE_UNIFORM);
2182 const TypeValidator typeValidator (m_context, program.getProgram(), uniformFilter);
2183 const ArraySizeValidator arraySizeValidator (m_context, program.getProgram(), -1, uniformFilter);
2184 const ArrayStrideValidator arrayStrideValidator (m_context, program.getProgram(), uniformFilter);
2185 const BlockIndexValidator blockIndexValidator (m_context, program.getProgram(), uniformFilter);
2186 const IsRowMajorValidator isRowMajorValidator (m_context, program.getProgram(), uniformFilter);
2187 const MatrixStrideValidator matrixStrideValidator (m_context, program.getProgram(), uniformFilter);
2188 const AtomicCounterBufferIndexVerifier atomicCounterBufferIndexVerifier (m_context, program.getProgram(), uniformFilter);
2189 const LocationValidator locationValidator (m_context, program.getProgram(), uniformFilter);
2190 const VariableNameLengthValidator nameLengthValidator (m_context, program.getProgram(), uniformFilter);
2191 const OffsetValidator offsetVerifier (m_context, program.getProgram(), uniformFilter);
2192 const VariableReferencedByShaderValidator referencedByVertexVerifier (m_context, glu::SHADERTYPE_VERTEX, uniformFilter);
2193 const VariableReferencedByShaderValidator referencedByFragmentVerifier (m_context, glu::SHADERTYPE_FRAGMENT, uniformFilter);
2194 const VariableReferencedByShaderValidator referencedByComputeVerifier (m_context, glu::SHADERTYPE_COMPUTE, uniformFilter);
2195 const VariableReferencedByShaderValidator referencedByGeometryVerifier (m_context, glu::SHADERTYPE_GEOMETRY, uniformFilter);
2196 const VariableReferencedByShaderValidator referencedByTessControlVerifier (m_context, glu::SHADERTYPE_TESSELLATION_CONTROL, uniformFilter);
2197 const VariableReferencedByShaderValidator referencedByTessEvaluationVerifier (m_context, glu::SHADERTYPE_TESSELLATION_EVALUATION, uniformFilter);
2199 const TestProperty allProperties[] =
2201 { GL_ARRAY_SIZE, &arraySizeValidator },
2202 { GL_ARRAY_STRIDE, &arrayStrideValidator },
2203 { GL_ATOMIC_COUNTER_BUFFER_INDEX, &atomicCounterBufferIndexVerifier },
2204 { GL_BLOCK_INDEX, &blockIndexValidator },
2205 { GL_IS_ROW_MAJOR, &isRowMajorValidator },
2206 { GL_LOCATION, &locationValidator },
2207 { GL_MATRIX_STRIDE, &matrixStrideValidator },
2208 { GL_NAME_LENGTH, &nameLengthValidator },
2209 { GL_OFFSET, &offsetVerifier },
2210 { GL_REFERENCED_BY_VERTEX_SHADER, &referencedByVertexVerifier },
2211 { GL_REFERENCED_BY_FRAGMENT_SHADER, &referencedByFragmentVerifier },
2212 { GL_REFERENCED_BY_COMPUTE_SHADER, &referencedByComputeVerifier },
2213 { GL_REFERENCED_BY_GEOMETRY_SHADER, &referencedByGeometryVerifier },
2214 { GL_REFERENCED_BY_TESS_CONTROL_SHADER, &referencedByTessControlVerifier },
2215 { GL_REFERENCED_BY_TESS_EVALUATION_SHADER, &referencedByTessEvaluationVerifier },
2216 { GL_TYPE, &typeValidator },
2219 for (int targetResourceNdx = 0; targetResourceNdx < (int)targetResources.size(); ++targetResourceNdx)
2221 const tcu::ScopedLogSection section (m_testCtx.getLog(), "UniformResource", "Uniform resource \"" + targetResources[targetResourceNdx] + "\"");
2222 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2223 std::vector<glw::GLenum> props;
2224 std::vector<const PropValidator*> validators;
2226 for (int propNdx = 0; propNdx < DE_LENGTH_OF_ARRAY(allProperties); ++propNdx)
2228 if (allProperties[propNdx].validator->isSelected(m_queryTarget.propFlags) &&
2229 allProperties[propNdx].validator->isSupported())
2231 props.push_back(allProperties[propNdx].prop);
2232 validators.push_back(allProperties[propNdx].validator);
2236 DE_ASSERT(!props.empty());
2238 queryAndValidateProps(m_testCtx, gl, program.getProgram(), m_queryTarget.interface, targetResources[targetResourceNdx].c_str(), programDefinition, props, validators);
2244 case PROGRAMINTERFACE_UNIFORM_BLOCK:
2245 case PROGRAMINTERFACE_SHADER_STORAGE_BLOCK:
2247 const glu::Storage storage = (m_queryTarget.interface == PROGRAMINTERFACE_UNIFORM_BLOCK) ? (glu::STORAGE_UNIFORM) : (glu::STORAGE_BUFFER);
2248 const VariableSearchFilter blockFilter = VariableSearchFilter::createStorageFilter(storage);
2250 const BlockNameLengthValidator nameLengthValidator (m_context, program.getProgram(), blockFilter);
2251 const BlockReferencedByShaderValidator referencedByVertexVerifier (m_context, glu::SHADERTYPE_VERTEX, blockFilter);
2252 const BlockReferencedByShaderValidator referencedByFragmentVerifier (m_context, glu::SHADERTYPE_FRAGMENT, blockFilter);
2253 const BlockReferencedByShaderValidator referencedByComputeVerifier (m_context, glu::SHADERTYPE_COMPUTE, blockFilter);
2254 const BlockReferencedByShaderValidator referencedByGeometryVerifier (m_context, glu::SHADERTYPE_GEOMETRY, blockFilter);
2255 const BlockReferencedByShaderValidator referencedByTessControlVerifier (m_context, glu::SHADERTYPE_TESSELLATION_CONTROL, blockFilter);
2256 const BlockReferencedByShaderValidator referencedByTessEvaluationVerifier (m_context, glu::SHADERTYPE_TESSELLATION_EVALUATION, blockFilter);
2257 const BufferBindingValidator bufferBindingValidator (m_context, program.getProgram(), blockFilter);
2259 const TestProperty allProperties[] =
2261 { GL_NAME_LENGTH, &nameLengthValidator },
2262 { GL_REFERENCED_BY_VERTEX_SHADER, &referencedByVertexVerifier },
2263 { GL_REFERENCED_BY_FRAGMENT_SHADER, &referencedByFragmentVerifier },
2264 { GL_REFERENCED_BY_COMPUTE_SHADER, &referencedByComputeVerifier },
2265 { GL_REFERENCED_BY_GEOMETRY_SHADER, &referencedByGeometryVerifier },
2266 { GL_REFERENCED_BY_TESS_CONTROL_SHADER, &referencedByTessControlVerifier },
2267 { GL_REFERENCED_BY_TESS_EVALUATION_SHADER, &referencedByTessEvaluationVerifier },
2268 { GL_BUFFER_BINDING, &bufferBindingValidator },
2271 for (int targetResourceNdx = 0; targetResourceNdx < (int)targetResources.size(); ++targetResourceNdx)
2273 const tcu::ScopedLogSection section (m_testCtx.getLog(), "BlockResource", "Interface block \"" + targetResources[targetResourceNdx] + "\"");
2274 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2275 std::vector<glw::GLenum> props;
2276 std::vector<const PropValidator*> validators;
2278 for (int propNdx = 0; propNdx < DE_LENGTH_OF_ARRAY(allProperties); ++propNdx)
2280 if (allProperties[propNdx].validator->isSelected(m_queryTarget.propFlags) &&
2281 allProperties[propNdx].validator->isSupported())
2283 props.push_back(allProperties[propNdx].prop);
2284 validators.push_back(allProperties[propNdx].validator);
2288 DE_ASSERT(!props.empty());
2290 queryAndValidateProps(m_testCtx, gl, program.getProgram(), m_queryTarget.interface, targetResources[targetResourceNdx].c_str(), programDefinition, props, validators);
2296 case PROGRAMINTERFACE_PROGRAM_INPUT:
2297 case PROGRAMINTERFACE_PROGRAM_OUTPUT:
2299 const bool isInputCase = (m_queryTarget.interface == PROGRAMINTERFACE_PROGRAM_INPUT);
2300 const glu::Storage varyingStorage = (isInputCase) ? (glu::STORAGE_IN) : (glu::STORAGE_OUT);
2301 const glu::Storage patchStorage = (isInputCase) ? (glu::STORAGE_PATCH_IN) : (glu::STORAGE_PATCH_OUT);
2302 const glu::ShaderType shaderType = (isInputCase) ? (programDefinition->getFirstStage()) : (programDefinition->getLastStage());
2303 const int unsizedArraySize = (isInputCase && shaderType == glu::SHADERTYPE_GEOMETRY) ? (1) // input points
2304 : (isInputCase && shaderType == glu::SHADERTYPE_TESSELLATION_CONTROL) ? (getMaxPatchVertices()) // input batch size
2305 : (!isInputCase && shaderType == glu::SHADERTYPE_TESSELLATION_CONTROL) ? (programDefinition->getTessellationNumOutputPatchVertices()) // output batch size
2306 : (isInputCase && shaderType == glu::SHADERTYPE_TESSELLATION_EVALUATION) ? (getMaxPatchVertices()) // input batch size
2308 const VariableSearchFilter variableFilter = VariableSearchFilter::logicalAnd(VariableSearchFilter::createShaderTypeFilter(shaderType),
2309 VariableSearchFilter::logicalOr(VariableSearchFilter::createStorageFilter(varyingStorage),
2310 VariableSearchFilter::createStorageFilter(patchStorage)));
2312 const TypeValidator typeValidator (m_context, program.getProgram(), variableFilter);
2313 const ArraySizeValidator arraySizeValidator (m_context, program.getProgram(), unsizedArraySize, variableFilter);
2314 const LocationValidator locationValidator (m_context, program.getProgram(), variableFilter);
2315 const VariableNameLengthValidator nameLengthValidator (m_context, program.getProgram(), variableFilter);
2316 const VariableReferencedByShaderValidator referencedByVertexVerifier (m_context, glu::SHADERTYPE_VERTEX, variableFilter);
2317 const VariableReferencedByShaderValidator referencedByFragmentVerifier (m_context, glu::SHADERTYPE_FRAGMENT, variableFilter);
2318 const VariableReferencedByShaderValidator referencedByComputeVerifier (m_context, glu::SHADERTYPE_COMPUTE, variableFilter);
2319 const VariableReferencedByShaderValidator referencedByGeometryVerifier (m_context, glu::SHADERTYPE_GEOMETRY, variableFilter);
2320 const VariableReferencedByShaderValidator referencedByTessControlVerifier (m_context, glu::SHADERTYPE_TESSELLATION_CONTROL, variableFilter);
2321 const VariableReferencedByShaderValidator referencedByTessEvaluationVerifier (m_context, glu::SHADERTYPE_TESSELLATION_EVALUATION, variableFilter);
2322 const PerPatchValidator perPatchValidator (m_context, program.getProgram(), variableFilter);
2324 const TestProperty allProperties[] =
2326 { GL_ARRAY_SIZE, &arraySizeValidator },
2327 { GL_LOCATION, &locationValidator },
2328 { GL_NAME_LENGTH, &nameLengthValidator },
2329 { GL_REFERENCED_BY_VERTEX_SHADER, &referencedByVertexVerifier },
2330 { GL_REFERENCED_BY_FRAGMENT_SHADER, &referencedByFragmentVerifier },
2331 { GL_REFERENCED_BY_COMPUTE_SHADER, &referencedByComputeVerifier },
2332 { GL_REFERENCED_BY_GEOMETRY_SHADER, &referencedByGeometryVerifier },
2333 { GL_REFERENCED_BY_TESS_CONTROL_SHADER, &referencedByTessControlVerifier },
2334 { GL_REFERENCED_BY_TESS_EVALUATION_SHADER, &referencedByTessEvaluationVerifier },
2335 { GL_TYPE, &typeValidator },
2336 { GL_IS_PER_PATCH, &perPatchValidator },
2339 for (int targetResourceNdx = 0; targetResourceNdx < (int)targetResources.size(); ++targetResourceNdx)
2341 const std::string resourceInterfaceName = (m_queryTarget.interface == PROGRAMINTERFACE_PROGRAM_INPUT) ? ("Input") : ("Output");
2342 const tcu::ScopedLogSection section (m_testCtx.getLog(), "BlockResource", resourceInterfaceName + " resource \"" + targetResources[targetResourceNdx] + "\"");
2343 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2344 std::vector<glw::GLenum> props;
2345 std::vector<const PropValidator*> validators;
2347 for (int propNdx = 0; propNdx < DE_LENGTH_OF_ARRAY(allProperties); ++propNdx)
2349 if (allProperties[propNdx].validator->isSelected(m_queryTarget.propFlags) &&
2350 allProperties[propNdx].validator->isSupported())
2352 props.push_back(allProperties[propNdx].prop);
2353 validators.push_back(allProperties[propNdx].validator);
2357 DE_ASSERT(!props.empty());
2359 queryAndValidateProps(m_testCtx, gl, program.getProgram(), m_queryTarget.interface, targetResources[targetResourceNdx].c_str(), programDefinition, props, validators);
2365 case PROGRAMINTERFACE_BUFFER_VARIABLE:
2367 const VariableSearchFilter variableFilter = VariableSearchFilter::createStorageFilter(glu::STORAGE_BUFFER);
2369 const TypeValidator typeValidator (m_context, program.getProgram(), variableFilter);
2370 const ArraySizeValidator arraySizeValidator (m_context, program.getProgram(), 0, variableFilter);
2371 const ArrayStrideValidator arrayStrideValidator (m_context, program.getProgram(), variableFilter);
2372 const BlockIndexValidator blockIndexValidator (m_context, program.getProgram(), variableFilter);
2373 const IsRowMajorValidator isRowMajorValidator (m_context, program.getProgram(), variableFilter);
2374 const MatrixStrideValidator matrixStrideValidator (m_context, program.getProgram(), variableFilter);
2375 const OffsetValidator offsetValidator (m_context, program.getProgram(), variableFilter);
2376 const VariableNameLengthValidator nameLengthValidator (m_context, program.getProgram(), variableFilter);
2377 const VariableReferencedByShaderValidator referencedByVertexVerifier (m_context, glu::SHADERTYPE_VERTEX, variableFilter);
2378 const VariableReferencedByShaderValidator referencedByFragmentVerifier (m_context, glu::SHADERTYPE_FRAGMENT, variableFilter);
2379 const VariableReferencedByShaderValidator referencedByComputeVerifier (m_context, glu::SHADERTYPE_COMPUTE, variableFilter);
2380 const VariableReferencedByShaderValidator referencedByGeometryVerifier (m_context, glu::SHADERTYPE_GEOMETRY, variableFilter);
2381 const VariableReferencedByShaderValidator referencedByTessControlVerifier (m_context, glu::SHADERTYPE_TESSELLATION_CONTROL, variableFilter);
2382 const VariableReferencedByShaderValidator referencedByTessEvaluationVerifier (m_context, glu::SHADERTYPE_TESSELLATION_EVALUATION, variableFilter);
2383 const TopLevelArraySizeValidator topLevelArraySizeValidator (m_context, program.getProgram(), variableFilter);
2384 const TopLevelArrayStrideValidator topLevelArrayStrideValidator (m_context, program.getProgram(), variableFilter);
2386 const TestProperty allProperties[] =
2388 { GL_ARRAY_SIZE, &arraySizeValidator },
2389 { GL_ARRAY_STRIDE, &arrayStrideValidator },
2390 { GL_BLOCK_INDEX, &blockIndexValidator },
2391 { GL_IS_ROW_MAJOR, &isRowMajorValidator },
2392 { GL_MATRIX_STRIDE, &matrixStrideValidator },
2393 { GL_NAME_LENGTH, &nameLengthValidator },
2394 { GL_OFFSET, &offsetValidator },
2395 { GL_REFERENCED_BY_VERTEX_SHADER, &referencedByVertexVerifier },
2396 { GL_REFERENCED_BY_FRAGMENT_SHADER, &referencedByFragmentVerifier },
2397 { GL_REFERENCED_BY_COMPUTE_SHADER, &referencedByComputeVerifier },
2398 { GL_REFERENCED_BY_GEOMETRY_SHADER, &referencedByGeometryVerifier },
2399 { GL_REFERENCED_BY_TESS_CONTROL_SHADER, &referencedByTessControlVerifier },
2400 { GL_REFERENCED_BY_TESS_EVALUATION_SHADER, &referencedByTessEvaluationVerifier },
2401 { GL_TOP_LEVEL_ARRAY_SIZE, &topLevelArraySizeValidator },
2402 { GL_TOP_LEVEL_ARRAY_STRIDE, &topLevelArrayStrideValidator },
2403 { GL_TYPE, &typeValidator },
2406 for (int targetResourceNdx = 0; targetResourceNdx < (int)targetResources.size(); ++targetResourceNdx)
2408 const tcu::ScopedLogSection section (m_testCtx.getLog(), "BufferVariableResource", "Buffer variable \"" + targetResources[targetResourceNdx] + "\"");
2409 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2410 std::vector<glw::GLenum> props;
2411 std::vector<const PropValidator*> validators;
2413 for (int propNdx = 0; propNdx < DE_LENGTH_OF_ARRAY(allProperties); ++propNdx)
2415 if (allProperties[propNdx].validator->isSelected(m_queryTarget.propFlags) &&
2416 allProperties[propNdx].validator->isSupported())
2418 props.push_back(allProperties[propNdx].prop);
2419 validators.push_back(allProperties[propNdx].validator);
2423 DE_ASSERT(!props.empty());
2425 queryAndValidateProps(m_testCtx, gl, program.getProgram(), m_queryTarget.interface, targetResources[targetResourceNdx].c_str(), programDefinition, props, validators);
2431 case PROGRAMINTERFACE_TRANSFORM_FEEDBACK_VARYING:
2433 const TransformFeedbackTypeValidator typeValidator (m_context);
2434 const TransformFeedbackArraySizeValidator arraySizeValidator (m_context);
2435 const TransformFeedbackNameLengthValidator nameLengthValidator (m_context);
2437 const TestProperty allProperties[] =
2439 { GL_ARRAY_SIZE, &arraySizeValidator },
2440 { GL_NAME_LENGTH, &nameLengthValidator },
2441 { GL_TYPE, &typeValidator },
2444 for (int targetResourceNdx = 0; targetResourceNdx < (int)targetResources.size(); ++targetResourceNdx)
2446 const tcu::ScopedLogSection section (m_testCtx.getLog(), "XFBVariableResource", "Transform feedback varying \"" + targetResources[targetResourceNdx] + "\"");
2447 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2448 std::vector<glw::GLenum> props;
2449 std::vector<const PropValidator*> validators;
2451 for (int propNdx = 0; propNdx < DE_LENGTH_OF_ARRAY(allProperties); ++propNdx)
2453 if (allProperties[propNdx].validator->isSelected(m_queryTarget.propFlags) &&
2454 allProperties[propNdx].validator->isSupported())
2456 props.push_back(allProperties[propNdx].prop);
2457 validators.push_back(allProperties[propNdx].validator);
2461 DE_ASSERT(!props.empty());
2463 queryAndValidateProps(m_testCtx, gl, program.getProgram(), m_queryTarget.interface, targetResources[targetResourceNdx].c_str(), programDefinition, props, validators);
2476 static bool checkLimit (glw::GLenum pname, int usage, const glw::Functions& gl, tcu::TestLog& log)
2480 glw::GLint limit = 0;
2481 gl.getIntegerv(pname, &limit);
2482 GLU_EXPECT_NO_ERROR(gl.getError(), "query limits");
2484 log << tcu::TestLog::Message << "\t" << glu::getGettableStateStr(pname) << " = " << limit << ", test requires " << usage << tcu::TestLog::EndMessage;
2488 log << tcu::TestLog::Message << "\t\tLimit exceeded" << tcu::TestLog::EndMessage;
2496 static bool checkShaderResourceUsage (const ProgramInterfaceDefinition::Program* program, const ProgramInterfaceDefinition::Shader* shader, const glw::Functions& gl, tcu::TestLog& log)
2498 const ProgramInterfaceDefinition::ShaderResourceUsage usage = getShaderResourceUsage(program, shader);
2500 switch (shader->getType())
2502 case glu::SHADERTYPE_VERTEX:
2510 { GL_MAX_VERTEX_ATTRIBS, usage.numInputVectors },
2511 { GL_MAX_VERTEX_UNIFORM_COMPONENTS, usage.numDefaultBlockUniformComponents },
2512 { GL_MAX_VERTEX_UNIFORM_VECTORS, usage.numUniformVectors },
2513 { GL_MAX_VERTEX_UNIFORM_BLOCKS, usage.numUniformBlocks },
2514 { GL_MAX_VERTEX_OUTPUT_COMPONENTS, usage.numOutputComponents },
2515 { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, usage.numSamplers },
2516 { GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS, usage.numAtomicCounterBuffers },
2517 { GL_MAX_VERTEX_ATOMIC_COUNTERS, usage.numAtomicCounters },
2518 { GL_MAX_VERTEX_IMAGE_UNIFORMS, usage.numImages },
2519 { GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS, usage.numCombinedUniformComponents },
2520 { GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, usage.numShaderStorageBlocks },
2525 log << tcu::TestLog::Message << "Vertex shader:" << tcu::TestLog::EndMessage;
2526 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(restrictions); ++ndx)
2527 allOk &= checkLimit(restrictions[ndx].pname, restrictions[ndx].usage, gl, log);
2532 case glu::SHADERTYPE_FRAGMENT:
2540 { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, usage.numDefaultBlockUniformComponents },
2541 { GL_MAX_FRAGMENT_UNIFORM_VECTORS, usage.numUniformVectors },
2542 { GL_MAX_FRAGMENT_UNIFORM_BLOCKS, usage.numUniformBlocks },
2543 { GL_MAX_FRAGMENT_INPUT_COMPONENTS, usage.numInputComponents },
2544 { GL_MAX_TEXTURE_IMAGE_UNITS, usage.numSamplers },
2545 { GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS, usage.numAtomicCounterBuffers },
2546 { GL_MAX_FRAGMENT_ATOMIC_COUNTERS, usage.numAtomicCounters },
2547 { GL_MAX_FRAGMENT_IMAGE_UNIFORMS, usage.numImages },
2548 { GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS, usage.numCombinedUniformComponents },
2549 { GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS, usage.numShaderStorageBlocks },
2554 log << tcu::TestLog::Message << "Fragment shader:" << tcu::TestLog::EndMessage;
2555 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(restrictions); ++ndx)
2556 allOk &= checkLimit(restrictions[ndx].pname, restrictions[ndx].usage, gl, log);
2561 case glu::SHADERTYPE_COMPUTE:
2569 { GL_MAX_COMPUTE_UNIFORM_BLOCKS, usage.numUniformBlocks },
2570 { GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS, usage.numSamplers },
2571 { GL_MAX_COMPUTE_UNIFORM_COMPONENTS, usage.numDefaultBlockUniformComponents },
2572 { GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS, usage.numAtomicCounterBuffers },
2573 { GL_MAX_COMPUTE_ATOMIC_COUNTERS, usage.numAtomicCounters },
2574 { GL_MAX_COMPUTE_IMAGE_UNIFORMS, usage.numImages },
2575 { GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS, usage.numCombinedUniformComponents },
2576 { GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS, usage.numShaderStorageBlocks },
2581 log << tcu::TestLog::Message << "Compute shader:" << tcu::TestLog::EndMessage;
2582 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(restrictions); ++ndx)
2583 allOk &= checkLimit(restrictions[ndx].pname, restrictions[ndx].usage, gl, log);
2588 case glu::SHADERTYPE_GEOMETRY:
2590 const int totalOutputComponents = program->getGeometryNumOutputVertices() * usage.numOutputComponents;
2597 { GL_MAX_GEOMETRY_UNIFORM_COMPONENTS, usage.numDefaultBlockUniformComponents },
2598 { GL_MAX_GEOMETRY_UNIFORM_BLOCKS, usage.numUniformBlocks },
2599 { GL_MAX_GEOMETRY_INPUT_COMPONENTS, usage.numInputComponents },
2600 { GL_MAX_GEOMETRY_OUTPUT_COMPONENTS, usage.numOutputComponents },
2601 { GL_MAX_GEOMETRY_OUTPUT_VERTICES, (int)program->getGeometryNumOutputVertices() },
2602 { GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, totalOutputComponents },
2603 { GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, usage.numSamplers },
2604 { GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS, usage.numAtomicCounterBuffers },
2605 { GL_MAX_GEOMETRY_ATOMIC_COUNTERS, usage.numAtomicCounters },
2606 { GL_MAX_GEOMETRY_IMAGE_UNIFORMS, usage.numImages },
2607 { GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, usage.numShaderStorageBlocks },
2612 log << tcu::TestLog::Message << "Geometry shader:" << tcu::TestLog::EndMessage;
2613 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(restrictions); ++ndx)
2614 allOk &= checkLimit(restrictions[ndx].pname, restrictions[ndx].usage, gl, log);
2619 case glu::SHADERTYPE_TESSELLATION_CONTROL:
2621 const int totalOutputComponents = program->getTessellationNumOutputPatchVertices() * usage.numOutputComponents + usage.numPatchOutputComponents;
2628 { GL_MAX_PATCH_VERTICES, (int)program->getTessellationNumOutputPatchVertices() },
2629 { GL_MAX_TESS_PATCH_COMPONENTS, usage.numPatchOutputComponents },
2630 { GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS, usage.numDefaultBlockUniformComponents },
2631 { GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS, usage.numUniformBlocks },
2632 { GL_MAX_TESS_CONTROL_INPUT_COMPONENTS, usage.numInputComponents },
2633 { GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS, usage.numOutputComponents },
2634 { GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS, totalOutputComponents },
2635 { GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS, usage.numSamplers },
2636 { GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS, usage.numAtomicCounterBuffers },
2637 { GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS, usage.numAtomicCounters },
2638 { GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS, usage.numImages },
2639 { GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, usage.numShaderStorageBlocks },
2644 log << tcu::TestLog::Message << "Tessellation control shader:" << tcu::TestLog::EndMessage;
2645 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(restrictions); ++ndx)
2646 allOk &= checkLimit(restrictions[ndx].pname, restrictions[ndx].usage, gl, log);
2651 case glu::SHADERTYPE_TESSELLATION_EVALUATION:
2659 { GL_MAX_PATCH_VERTICES, (int)program->getTessellationNumOutputPatchVertices() },
2660 { GL_MAX_TESS_PATCH_COMPONENTS, usage.numPatchInputComponents },
2661 { GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS, usage.numDefaultBlockUniformComponents },
2662 { GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS, usage.numUniformBlocks },
2663 { GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS, usage.numInputComponents },
2664 { GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS, usage.numOutputComponents },
2665 { GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS, usage.numSamplers },
2666 { GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS, usage.numAtomicCounterBuffers },
2667 { GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS, usage.numAtomicCounters },
2668 { GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS, usage.numImages },
2669 { GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, usage.numShaderStorageBlocks },
2674 log << tcu::TestLog::Message << "Tessellation evaluation shader:" << tcu::TestLog::EndMessage;
2675 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(restrictions); ++ndx)
2676 allOk &= checkLimit(restrictions[ndx].pname, restrictions[ndx].usage, gl, log);
2687 static bool checkProgramCombinedResourceUsage (const ProgramInterfaceDefinition::Program* program, const glw::Functions& gl, tcu::TestLog& log)
2689 const ProgramInterfaceDefinition::ProgramResourceUsage usage = getCombinedProgramResourceUsage(program);
2697 { GL_MAX_UNIFORM_BUFFER_BINDINGS, usage.uniformBufferMaxBinding+1 },
2698 { GL_MAX_UNIFORM_BLOCK_SIZE, usage.uniformBufferMaxSize },
2699 { GL_MAX_COMBINED_UNIFORM_BLOCKS, usage.numUniformBlocks },
2700 { GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS, usage.numCombinedVertexUniformComponents },
2701 { GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS, usage.numCombinedFragmentUniformComponents },
2702 { GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS, usage.numCombinedGeometryUniformComponents },
2703 { GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS, usage.numCombinedTessControlUniformComponents },
2704 { GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS, usage.numCombinedTessEvalUniformComponents },
2705 { GL_MAX_VARYING_COMPONENTS, usage.numVaryingComponents },
2706 { GL_MAX_VARYING_VECTORS, usage.numVaryingVectors },
2707 { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, usage.numCombinedSamplers },
2708 { GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES, usage.numCombinedOutputResources },
2709 { GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS, usage.atomicCounterBufferMaxBinding+1 },
2710 { GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE, usage.atomicCounterBufferMaxSize },
2711 { GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS, usage.numAtomicCounterBuffers },
2712 { GL_MAX_COMBINED_ATOMIC_COUNTERS, usage.numAtomicCounters },
2713 { GL_MAX_IMAGE_UNITS, usage.maxImageBinding+1 },
2714 { GL_MAX_COMBINED_IMAGE_UNIFORMS, usage.numCombinedImages },
2715 { GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, usage.shaderStorageBufferMaxBinding+1 },
2716 { GL_MAX_SHADER_STORAGE_BLOCK_SIZE, usage.shaderStorageBufferMaxSize },
2717 { GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS, usage.numShaderStorageBlocks },
2718 { GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, usage.numXFBInterleavedComponents },
2719 { GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, usage.numXFBSeparateAttribs },
2720 { GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, usage.numXFBSeparateComponents },
2721 { GL_MAX_DRAW_BUFFERS, usage.fragmentOutputMaxBinding+1 },
2726 log << tcu::TestLog::Message << "Program combined:" << tcu::TestLog::EndMessage;
2727 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(restrictions); ++ndx)
2728 allOk &= checkLimit(restrictions[ndx].pname, restrictions[ndx].usage, gl, log);
2733 void checkProgramResourceUsage (const ProgramInterfaceDefinition::Program* program, const glw::Functions& gl, tcu::TestLog& log)
2735 bool limitExceeded = false;
2737 for (int shaderNdx = 0; shaderNdx < (int)program->getShaders().size(); ++shaderNdx)
2738 limitExceeded |= !checkShaderResourceUsage(program, program->getShaders()[shaderNdx], gl, log);
2740 limitExceeded |= !checkProgramCombinedResourceUsage(program, gl, log);
2744 log << tcu::TestLog::Message << "One or more resource limits exceeded" << tcu::TestLog::EndMessage;
2745 throw tcu::NotSupportedError("one or more resource limits exceeded");