1 #ifndef _GLUSHADERLIBRARY_HPP 2 #define _GLUSHADERLIBRARY_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program OpenGL ES Utilities 5 * ------------------------------------------------ 6 * 7 * Copyright 2015 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 file utilities. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "gluDefs.hpp" 27 #include "gluVarType.hpp" 28 #include "gluShaderProgram.hpp" 29 #include "tcuTestCase.hpp" 30 31 #include <string> 32 #include <vector> 33 34 namespace glu 35 { 36 namespace sl 37 { 38 39 enum CaseType 40 { 41 CASETYPE_COMPLETE = 0, //!< Has all shaders specified separately. 42 CASETYPE_VERTEX_ONLY, //!< "Both" case, vertex shader sub case. 43 CASETYPE_FRAGMENT_ONLY, //!< "Both" case, fragment shader sub case. 44 45 CASETYPE_LAST 46 }; 47 48 enum ExpectResult 49 { 50 EXPECT_PASS = 0, 51 EXPECT_COMPILE_FAIL, 52 EXPECT_LINK_FAIL, 53 EXPECT_COMPILE_LINK_FAIL, 54 EXPECT_VALIDATION_FAIL, 55 EXPECT_BUILD_SUCCESSFUL, 56 57 EXPECT_LAST 58 }; 59 60 enum OutputType 61 { 62 OUTPUT_RESULT = 0, 63 OUTPUT_COLOR, 64 65 OUTPUT_LAST 66 }; 67 68 struct Value 69 { 70 union Element 71 { 72 float float32; 73 int32_t int32; 74 int32_t bool32; 75 }; 76 77 VarType type; 78 std::string name; 79 std::vector<Element> elements; // Scalar values (variable.varType.getScalarSize() * #values). 80 }; 81 82 struct ValueBlock 83 { 84 std::vector<Value> inputs; 85 std::vector<Value> outputs; 86 std::vector<Value> uniforms; 87 }; 88 89 enum CapabilityType 90 { 91 CAPABILITY_LIMIT = 0, 92 CAPABILITY_FLAG, 93 94 CAPABILITY_LAST 95 }; 96 97 enum CapabilityFlag 98 { 99 CAPABILITY_FULL_GLSL_ES_100_SUPPORT, 100 CAPABILITY_ONLY_GLSL_ES_100_SUPPORT, // only ES2, no ES3 capability 101 CAPABILITY_EXACTLY_ONE_DRAW_BUFFER // gl_MaxDrawBuffers is exactly 1 102 }; 103 104 struct RequiredCapability 105 { 106 CapabilityType type; 107 108 union 109 { 110 CapabilityFlag flagName; 111 uint32_t enumName; 112 }; 113 114 int referenceValue; 115 RequiredCapabilityglu::sl::RequiredCapability116 RequiredCapability(CapabilityFlag flagName_) 117 : type(CAPABILITY_FLAG) 118 , flagName(flagName_) 119 , referenceValue(0) // not used 120 { 121 } 122 RequiredCapabilityglu::sl::RequiredCapability123 RequiredCapability(uint32_t enumName_, int referenceValue_) 124 : type(CAPABILITY_LIMIT) 125 , enumName(enumName_) 126 , referenceValue(referenceValue_) 127 { 128 } 129 }; 130 131 struct RequiredExtension 132 { 133 std::vector<std::string> alternatives; // One or more extensions, at least one (but not all) must be supported 134 uint32_t effectiveStages; // Bitfield of shader stages requiring this extension 135 RequiredExtensionglu::sl::RequiredExtension136 RequiredExtension(const std::vector<std::string> &alternatives_, uint32_t effectiveStages_) 137 : alternatives(alternatives_) 138 , effectiveStages(effectiveStages_) 139 { 140 } 141 RequiredExtensionglu::sl::RequiredExtension142 RequiredExtension(const std::string &extension, uint32_t effectiveStages_) : effectiveStages(effectiveStages_) 143 { 144 alternatives.push_back(extension); 145 } 146 RequiredExtensionglu::sl::RequiredExtension147 RequiredExtension(void) : effectiveStages(0u) 148 { 149 } 150 }; 151 152 struct ProgramSpecification 153 { 154 glu::ProgramSources sources; 155 std::vector<RequiredExtension> requiredExtensions; 156 uint32_t activeStages; // Has an effect only if sources.separable == true, must be 0 otherwise 157 ProgramSpecificationglu::sl::ProgramSpecification158 ProgramSpecification(void) : activeStages(0u) 159 { 160 } 161 }; 162 163 struct ShaderCaseSpecification 164 { 165 CaseType caseType; 166 ExpectResult expectResult; 167 OutputType outputType; 168 DataType outputFormat; 169 glu::GLSLVersion targetVersion; 170 171 std::vector<RequiredCapability> requiredCaps; 172 173 ValueBlock values; 174 std::vector<ProgramSpecification> programs; 175 ShaderCaseSpecificationglu::sl::ShaderCaseSpecification176 ShaderCaseSpecification(void) 177 : caseType(CASETYPE_LAST) 178 , expectResult(EXPECT_LAST) 179 , outputType(OUTPUT_RESULT) 180 , outputFormat(TYPE_LAST) 181 , targetVersion(glu::GLSL_VERSION_LAST) 182 { 183 } 184 }; 185 186 bool isValid(const ValueBlock &block); 187 bool isValid(const ShaderCaseSpecification &spec); 188 189 bool isCapabilityRequired(CapabilityFlag capabilityFlag, const ShaderCaseSpecification &spec); 190 191 class ShaderCaseFactory 192 { 193 public: ~ShaderCaseFactory()194 virtual ~ShaderCaseFactory() 195 { 196 } 197 virtual tcu::TestCaseGroup *createGroup(const std::string &name, const std::string &description, 198 const std::vector<tcu::TestNode *> &children) = 0; 199 virtual tcu::TestCase *createCase(const std::string &name, const std::string &description, 200 const ShaderCaseSpecification &spec) = 0; 201 }; 202 203 std::vector<tcu::TestNode *> parseFile(const tcu::Archive &archive, const std::string &filename, 204 ShaderCaseFactory *caseFactory); 205 206 // Specialization utilties 207 208 struct ProgramSpecializationParams 209 { 210 const ShaderCaseSpecification &caseSpec; 211 const std::vector<RequiredExtension> requiredExtensions; // Extensions, must be resolved to single ext per entry 212 const int maxPatchVertices; // Used by tess shaders only 213 ProgramSpecializationParamsglu::sl::ProgramSpecializationParams214 ProgramSpecializationParams(const ShaderCaseSpecification &caseSpec_, 215 const std::vector<RequiredExtension> &requiredExtensions_, int maxPatchVertices_) 216 : caseSpec(caseSpec_) 217 , requiredExtensions(requiredExtensions_) 218 , maxPatchVertices(maxPatchVertices_) 219 { 220 } 221 }; 222 223 void genCompareFunctions(std::ostringstream &stream, const ValueBlock &valueBlock, bool useFloatTypes); 224 std::string injectExtensionRequirements(const std::string &baseCode, const std::vector<RequiredExtension> &extensions, 225 ShaderType shaderType); 226 227 // Other utilities 228 229 void dumpValues(tcu::TestLog &log, const ValueBlock &values, int arrayNdx); 230 231 } // namespace sl 232 } // namespace glu 233 234 #endif // _GLUSHADERLIBRARY_HPP 235