• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 		deInt32		int32;
74 		deInt32		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 		deUint32			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 (deUint32 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 	deUint32					effectiveStages;	// Bitfield of shader stages requiring this extension
135 
RequiredExtensionglu::sl::RequiredExtension136 	RequiredExtension (const std::vector<std::string>&	alternatives_,
137 					   deUint32							effectiveStages_)
138 		: alternatives		(alternatives_)
139 		, effectiveStages	(effectiveStages_)
140 	{
141 	}
142 
RequiredExtensionglu::sl::RequiredExtension143 		RequiredExtension (const std::string&	extension,
144 						   deUint32				effectiveStages_)
145 		: effectiveStages	(effectiveStages_)
146 	{
147 		alternatives.push_back(extension);
148 	}
149 
RequiredExtensionglu::sl::RequiredExtension150 	RequiredExtension (void)
151 		: effectiveStages	(0u)
152 	{
153 	}
154 };
155 
156 struct ProgramSpecification
157 {
158 	glu::ProgramSources				sources;
159 	std::vector<RequiredExtension>	requiredExtensions;
160 	deUint32						activeStages;	// Has an effect only if sources.separable == true, must be 0 otherwise
161 
ProgramSpecificationglu::sl::ProgramSpecification162 	ProgramSpecification (void)
163 		: activeStages(0u)
164 	{
165 	}
166 };
167 
168 struct ShaderCaseSpecification
169 {
170 	CaseType							caseType;
171 	ExpectResult						expectResult;
172 	OutputType							outputType;
173 	DataType							outputFormat;
174 	glu::GLSLVersion					targetVersion;
175 
176 	std::vector<RequiredCapability>		requiredCaps;
177 
178 	ValueBlock							values;
179 	std::vector<ProgramSpecification>	programs;
180 
ShaderCaseSpecificationglu::sl::ShaderCaseSpecification181 	ShaderCaseSpecification (void)
182 		: caseType				(CASETYPE_LAST)
183 		, expectResult			(EXPECT_LAST)
184 		, outputType			(OUTPUT_RESULT)
185 		, outputFormat			(TYPE_LAST)
186 		, targetVersion			(glu::GLSL_VERSION_LAST)
187 	{
188 	}
189 };
190 
191 bool	isValid		(const ValueBlock& block);
192 bool	isValid		(const ShaderCaseSpecification& spec);
193 
194 bool	isCapabilityRequired(CapabilityFlag capabilityFlag, const ShaderCaseSpecification& spec);
195 
196 class ShaderCaseFactory
197 {
198 public:
199 	virtual tcu::TestCaseGroup*	createGroup	(const std::string& name, const std::string& description, const std::vector<tcu::TestNode*>& children) = 0;
200 	virtual tcu::TestCase*		createCase	(const std::string& name, const std::string& description, const ShaderCaseSpecification& spec) = 0;
201 };
202 
203 std::vector<tcu::TestNode*>		parseFile	(const tcu::Archive& archive, const std::string& filename, ShaderCaseFactory* caseFactory);
204 
205 // Specialization utilties
206 
207 struct ProgramSpecializationParams
208 {
209 	const ShaderCaseSpecification&			caseSpec;
210 	const std::vector<RequiredExtension>	requiredExtensions;	// Extensions, must be resolved to single ext per entry
211 	const int								maxPatchVertices;	// Used by tess shaders only
212 
ProgramSpecializationParamsglu::sl::ProgramSpecializationParams213 	ProgramSpecializationParams (const ShaderCaseSpecification&			caseSpec_,
214 								 const std::vector<RequiredExtension>&	requiredExtensions_,
215 								 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, ShaderType shaderType);
225 
226 // Other utilities
227 
228 void			dumpValues					(tcu::TestLog& log, const ValueBlock& values, int arrayNdx);
229 
230 } // sl
231 } // glu
232 
233 #endif // _GLUSHADERLIBRARY_HPP
234