1 #ifndef _GLSSHADERLIBRARYCASE_HPP 2 #define _GLSSHADERLIBRARYCASE_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program OpenGL (ES) Module 5 * ----------------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Shader test case. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "gluDefs.hpp" 27 #include "gluShaderUtil.hpp" 28 #include "gluRenderContext.hpp" 29 #include "gluShaderProgram.hpp" 30 #include "tcuTestCase.hpp" 31 #include "tcuSurface.hpp" 32 33 #include <string> 34 #include <vector> 35 36 namespace deqp 37 { 38 namespace gls 39 { 40 namespace sl 41 { 42 43 // ShaderCase node. 44 45 class ShaderCase : public tcu::TestCase 46 { 47 public: 48 enum CaseType 49 { 50 CASETYPE_COMPLETE = 0, //!< Has all shaders specified separately. 51 CASETYPE_VERTEX_ONLY, //!< "Both" case, vertex shader sub case. 52 CASETYPE_FRAGMENT_ONLY, //!< "Both" case, fragment shader sub case. 53 54 CASETYPE_LAST 55 }; 56 57 enum ExpectResult 58 { 59 EXPECT_PASS = 0, 60 EXPECT_COMPILE_FAIL, 61 EXPECT_LINK_FAIL, 62 EXPECT_COMPILE_LINK_FAIL, 63 EXPECT_VALIDATION_FAIL, 64 65 EXPECT_LAST 66 }; 67 68 struct Value 69 { 70 enum StorageType 71 { 72 STORAGE_UNIFORM, 73 STORAGE_INPUT, 74 STORAGE_OUTPUT, 75 76 STORAGE_LAST 77 }; 78 79 /* \todo [2010-03-31 petri] Replace with another vector to allow a) arrays, b) compact representation */ 80 union Element 81 { 82 float float32; 83 deInt32 int32; 84 deInt32 bool32; 85 }; 86 87 StorageType storageType; 88 std::string valueName; 89 glu::DataType dataType; 90 int arrayLength; // Number of elements in array (currently always 1). 91 std::vector<Element> elements; // Scalar values (length dataType.scalarSize * arrayLength). 92 }; 93 94 struct ValueBlock 95 { 96 ValueBlock (void); 97 98 int arrayLength; // Combined array length of each value (lengths must be same, or one). 99 std::vector<Value> values; 100 }; 101 102 class CaseRequirement 103 { 104 public: 105 enum RequirementType 106 { 107 REQUIREMENTTYPE_EXTENSION = 0, 108 REQUIREMENTTYPE_IMPLEMENTATION_LIMIT, 109 110 REQUIREMENTTYPE_LAST 111 }; 112 113 CaseRequirement (void); 114 115 static CaseRequirement createAnyExtensionRequirement (const std::vector<std::string>& requirements, deUint32 effectiveShaderStageFlags); 116 static CaseRequirement createLimitRequirement (deUint32 enumName, int ref); 117 void checkRequirements (glu::RenderContext& renderCtx, const glu::ContextInfo& contextInfo); 118 getType(void) const119 RequirementType getType (void) const { return m_type; }; getSupportedExtension(void) const120 std::string getSupportedExtension (void) const { DE_ASSERT(m_type == REQUIREMENTTYPE_EXTENSION); DE_ASSERT(m_supportedExtensionNdx >= 0); return m_extensions[m_supportedExtensionNdx]; } getAffectedExtensionStageFlags(void) const121 deUint32 getAffectedExtensionStageFlags (void) const { DE_ASSERT(m_type == REQUIREMENTTYPE_EXTENSION); return m_effectiveShaderStageFlags; } 122 123 private: 124 RequirementType m_type; 125 126 // REQUIREMENTTYPE_EXTENSION: 127 std::vector<std::string> m_extensions; 128 int m_supportedExtensionNdx; 129 deUint32 m_effectiveShaderStageFlags; 130 131 // REQUIREMENTTYPE_IMPLEMENTATION_LIMIT: 132 deUint32 m_enumName; 133 int m_referenceValue; 134 }; 135 136 struct ShaderCaseSpecification 137 { 138 ShaderCaseSpecification (void); 139 140 static ShaderCaseSpecification generateSharedSourceVertexCase (ExpectResult expectResult_, glu::GLSLVersion targetVersion_, const std::vector<ValueBlock>& values, const std::string& sharedSource); 141 static ShaderCaseSpecification generateSharedSourceFragmentCase (ExpectResult expectResult_, glu::GLSLVersion targetVersion_, const std::vector<ValueBlock>& values, const std::string& sharedSource); 142 143 ExpectResult expectResult; 144 glu::GLSLVersion targetVersion; 145 CaseType caseType; 146 std::vector<CaseRequirement> requirements; 147 std::vector<ValueBlock> valueBlocks; 148 std::vector<std::string> vertexSources; 149 std::vector<std::string> fragmentSources; 150 std::vector<std::string> tessCtrlSources; 151 std::vector<std::string> tessEvalSources; 152 std::vector<std::string> geometrySources; 153 }; 154 155 struct PipelineProgram 156 { 157 deUint32 activeStageBits; 158 std::vector<CaseRequirement> requirements; 159 std::vector<std::string> vertexSources; 160 std::vector<std::string> fragmentSources; 161 std::vector<std::string> tessCtrlSources; 162 std::vector<std::string> tessEvalSources; 163 std::vector<std::string> geometrySources; 164 }; 165 166 struct PipelineCaseSpecification 167 { 168 ExpectResult expectResult; 169 glu::GLSLVersion targetVersion; 170 CaseType caseType; 171 std::vector<ValueBlock> valueBlocks; 172 std::vector<PipelineProgram> programs; 173 }; 174 175 // Methods. 176 ShaderCase (tcu::TestContext& testCtx, 177 glu::RenderContext& renderCtx, 178 const glu::ContextInfo& contextInfo, 179 const char* caseName, 180 const char* description, 181 const ShaderCaseSpecification& specification); 182 ShaderCase (tcu::TestContext& testCtx, 183 glu::RenderContext& renderCtx, 184 const glu::ContextInfo& contextInfo, 185 const char* caseName, 186 const char* description, 187 const PipelineCaseSpecification& specification); 188 virtual ~ShaderCase (void); 189 190 private: 191 void init (void); 192 bool execute (void); 193 IterateResult iterate (void); 194 195 ShaderCase (const ShaderCase&); // not allowed! 196 ShaderCase& operator= (const ShaderCase&); // not allowed! 197 198 std::string genVertexShader (const ValueBlock& valueBlock) const; 199 std::string genFragmentShader (const ValueBlock& valueBlock) const; 200 std::string specializeVertexShader (const char* src, const ValueBlock& valueBlock) const; 201 std::string specializeFragmentShader (const char* src, const ValueBlock& valueBlock) const; 202 void specializeVertexShaders (glu::ProgramSources& dst, const std::vector<std::string>& sources, const ValueBlock& valueBlock, const std::vector<ShaderCase::CaseRequirement>& requirements) const; 203 void specializeFragmentShaders (glu::ProgramSources& dst, const std::vector<std::string>& sources, const ValueBlock& valueBlock, const std::vector<ShaderCase::CaseRequirement>& requirements) const; 204 void specializeGeometryShaders (glu::ProgramSources& dst, const std::vector<std::string>& sources, const ValueBlock& valueBlock, const std::vector<ShaderCase::CaseRequirement>& requirements) const; 205 void specializeTessControlShaders (glu::ProgramSources& dst, const std::vector<std::string>& sources, const ValueBlock& valueBlock, const std::vector<ShaderCase::CaseRequirement>& requirements) const; 206 void specializeTessEvalShaders (glu::ProgramSources& dst, const std::vector<std::string>& sources, const ValueBlock& valueBlock, const std::vector<ShaderCase::CaseRequirement>& requirements) const; 207 bool isTessellationPresent (void) const; 208 209 void dumpValues (const ValueBlock& valueBlock, int arrayNdx); 210 211 bool checkPixels (tcu::Surface& surface, int minX, int maxX, int minY, int maxY); 212 213 struct ProgramObject 214 { 215 glu::ProgramSources programSources; 216 PipelineProgram spec; 217 }; 218 219 // Member variables. 220 glu::RenderContext& m_renderCtx; 221 const glu::ContextInfo& m_contextInfo; 222 const CaseType m_caseType; 223 const ExpectResult m_expectResult; 224 const glu::GLSLVersion m_targetVersion; 225 const bool m_separatePrograms; 226 std::vector<ValueBlock> m_valueBlocks; 227 std::vector<ProgramObject> m_programs; 228 }; 229 230 } // sl 231 } // gls 232 } // deqp 233 234 #endif // _GLSSHADERLIBRARYCASE_HPP 235