• 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 struct Value
61 {
62 	union Element
63 	{
64 		float		float32;
65 		deInt32		int32;
66 		deInt32		bool32;
67 	};
68 
69 	VarType					type;
70 	std::string				name;
71 	std::vector<Element>	elements;		// Scalar values (variable.varType.getScalarSize() * #values).
72 };
73 
74 struct ValueBlock
75 {
76 	std::vector<Value>		inputs;
77 	std::vector<Value>		outputs;
78 	std::vector<Value>		uniforms;
79 };
80 
81 struct RequiredCapability
82 {
83 	deUint32				enumName;
84 	int						referenceValue;
85 
RequiredCapabilityglu::sl::RequiredCapability86 	RequiredCapability (void)
87 		: enumName			(0u)
88 		, referenceValue	(0)
89 	{
90 	}
91 
RequiredCapabilityglu::sl::RequiredCapability92 	RequiredCapability (deUint32 enumName_, int referenceValue_)
93 		: enumName			(enumName_)
94 		, referenceValue	(referenceValue_)
95 	{
96 	}
97 };
98 
99 struct RequiredExtension
100 {
101 	std::vector<std::string>	alternatives;		// One or more extensions, at least one (but not all) must be supported
102 	deUint32					effectiveStages;	// Bitfield of shader stages requiring this extension
103 
RequiredExtensionglu::sl::RequiredExtension104 	RequiredExtension (const std::vector<std::string>&	alternatives_,
105 					   deUint32							effectiveStages_)
106 		: alternatives		(alternatives_)
107 		, effectiveStages	(effectiveStages_)
108 	{
109 	}
110 
RequiredExtensionglu::sl::RequiredExtension111 		RequiredExtension (const std::string&	extension,
112 						   deUint32				effectiveStages_)
113 		: effectiveStages	(effectiveStages_)
114 	{
115 		alternatives.push_back(extension);
116 	}
117 
RequiredExtensionglu::sl::RequiredExtension118 	RequiredExtension (void)
119 		: effectiveStages	(0u)
120 	{
121 	}
122 };
123 
124 struct ProgramSpecification
125 {
126 	glu::ProgramSources				sources;
127 	std::vector<RequiredExtension>	requiredExtensions;
128 	deUint32						activeStages;	// Has an effect only if sources.separable == true, must be 0 otherwise
129 
ProgramSpecificationglu::sl::ProgramSpecification130 	ProgramSpecification (void)
131 		: activeStages(0u)
132 	{
133 	}
134 };
135 
136 struct ShaderCaseSpecification
137 {
138 	CaseType							caseType;
139 	ExpectResult						expectResult;
140 	glu::GLSLVersion					targetVersion;
141 
142 	// \todo [pyry] Clean this up
143 	std::vector<RequiredCapability>		requiredCaps;
144 	bool								fullGLSLES100Required;
145 
146 	ValueBlock							values;
147 	std::vector<ProgramSpecification>	programs;
148 
ShaderCaseSpecificationglu::sl::ShaderCaseSpecification149 	ShaderCaseSpecification (void)
150 		: caseType				(CASETYPE_LAST)
151 		, expectResult			(EXPECT_LAST)
152 		, targetVersion			(glu::GLSL_VERSION_LAST)
153 		, fullGLSLES100Required	(false)
154 	{
155 	}
156 };
157 
158 bool	isValid		(const ValueBlock& block);
159 bool	isValid		(const ShaderCaseSpecification& spec);
160 
161 class ShaderCaseFactory
162 {
163 public:
164 	virtual tcu::TestCaseGroup*	createGroup	(const std::string& name, const std::string& description, const std::vector<tcu::TestNode*>& children) = 0;
165 	virtual tcu::TestCase*		createCase	(const std::string& name, const std::string& description, const ShaderCaseSpecification& spec) = 0;
166 };
167 
168 std::vector<tcu::TestNode*>		parseFile	(const tcu::Archive& archive, const std::string& filename, ShaderCaseFactory* caseFactory);
169 
170 // Specialization utilties
171 
172 struct ProgramSpecializationParams
173 {
174 	const ShaderCaseSpecification&			caseSpec;
175 	const std::vector<RequiredExtension>	requiredExtensions;	// Extensions, must be resolved to single ext per entry
176 	const int								maxPatchVertices;	// Used by tess shaders only
177 
ProgramSpecializationParamsglu::sl::ProgramSpecializationParams178 	ProgramSpecializationParams (const ShaderCaseSpecification&			caseSpec_,
179 								 const std::vector<RequiredExtension>&	requiredExtensions_,
180 								 int									maxPatchVertices_)
181 		: caseSpec				(caseSpec_)
182 		, requiredExtensions	(requiredExtensions_)
183 		, maxPatchVertices		(maxPatchVertices_)
184 	{
185 	}
186 };
187 
188 void			genCompareFunctions			(std::ostringstream& stream, const ValueBlock& valueBlock, bool useFloatTypes);
189 std::string		injectExtensionRequirements	(const std::string& baseCode, const std::vector<RequiredExtension>& extensions, ShaderType shaderType);
190 
191 // Other utilities
192 
193 void			dumpValues					(tcu::TestLog& log, const ValueBlock& values, int arrayNdx);
194 
195 } // sl
196 } // glu
197 
198 #endif // _GLUSHADERLIBRARY_HPP
199