1 #ifndef _GLSSHADERLIBRARYCASE_HPP
2 #define _GLSSHADERLIBRARYCASE_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL (ES) Module
5 * -----------------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Shader test case.
24 *//*--------------------------------------------------------------------*/
26 #include "gluDefs.hpp"
27 #include "gluShaderUtil.hpp"
28 #include "gluRenderContext.hpp"
29 #include "gluShaderProgram.hpp"
30 #include "tcuTestCase.hpp"
31 #include "tcuSurface.hpp"
45 class ShaderCase : public tcu::TestCase
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.
62 EXPECT_COMPILE_LINK_FAIL,
63 EXPECT_VALIDATION_FAIL,
64 EXPECT_BUILD_SUCCESSFUL,
80 /* \todo [2010-03-31 petri] Replace with another vector to allow a) arrays, b) compact representation */
88 StorageType storageType;
89 std::string valueName;
90 glu::DataType dataType;
91 int arrayLength; // Number of elements in array (currently always 1).
92 std::vector<Element> elements; // Scalar values (length dataType.scalarSize * arrayLength).
99 int arrayLength; // Combined array length of each value (lengths must be same, or one).
100 std::vector<Value> values;
103 class CaseRequirement
108 REQUIREMENTTYPE_EXTENSION = 0,
109 REQUIREMENTTYPE_IMPLEMENTATION_LIMIT,
110 REQUIREMENTTYPE_FULL_GLSL_ES_100_SPEC, //!< Full support (as opposed to limited as specified for GLES 2.0 (See GLSL Appendix A)) cannot be queried
115 CaseRequirement (void);
117 static CaseRequirement createAnyExtensionRequirement (const std::vector<std::string>& requirements, deUint32 effectiveShaderStageFlags);
118 static CaseRequirement createLimitRequirement (deUint32 enumName, int ref);
119 static CaseRequirement createFullGLSLES100SpecificationRequirement (void);
120 void checkRequirements (glu::RenderContext& renderCtx, const glu::ContextInfo& contextInfo);
122 RequirementType getType (void) const { return m_type; };
123 std::string getSupportedExtension (void) const { DE_ASSERT(m_type == REQUIREMENTTYPE_EXTENSION); DE_ASSERT(m_supportedExtensionNdx >= 0); return m_extensions[m_supportedExtensionNdx]; }
124 deUint32 getAffectedExtensionStageFlags (void) const { DE_ASSERT(m_type == REQUIREMENTTYPE_EXTENSION); return m_effectiveShaderStageFlags; }
127 RequirementType m_type;
129 // REQUIREMENTTYPE_EXTENSION:
130 std::vector<std::string> m_extensions;
131 int m_supportedExtensionNdx;
132 deUint32 m_effectiveShaderStageFlags;
134 // REQUIREMENTTYPE_IMPLEMENTATION_LIMIT:
136 int m_referenceValue;
139 struct ShaderCaseSpecification
141 ShaderCaseSpecification (void);
143 static ShaderCaseSpecification generateSharedSourceVertexCase (ExpectResult expectResult_, glu::GLSLVersion targetVersion_, const std::vector<ValueBlock>& values, const std::string& sharedSource);
144 static ShaderCaseSpecification generateSharedSourceFragmentCase (ExpectResult expectResult_, glu::GLSLVersion targetVersion_, const std::vector<ValueBlock>& values, const std::string& sharedSource);
146 ExpectResult expectResult;
147 glu::GLSLVersion targetVersion;
149 std::vector<CaseRequirement> requirements;
150 std::vector<ValueBlock> valueBlocks;
151 std::vector<std::string> vertexSources;
152 std::vector<std::string> fragmentSources;
153 std::vector<std::string> tessCtrlSources;
154 std::vector<std::string> tessEvalSources;
155 std::vector<std::string> geometrySources;
158 struct PipelineProgram
160 deUint32 activeStageBits;
161 std::vector<CaseRequirement> requirements;
162 std::vector<std::string> vertexSources;
163 std::vector<std::string> fragmentSources;
164 std::vector<std::string> tessCtrlSources;
165 std::vector<std::string> tessEvalSources;
166 std::vector<std::string> geometrySources;
169 struct PipelineCaseSpecification
171 ExpectResult expectResult;
172 glu::GLSLVersion targetVersion;
174 std::vector<ValueBlock> valueBlocks;
175 std::vector<PipelineProgram> programs;
179 ShaderCase (tcu::TestContext& testCtx,
180 glu::RenderContext& renderCtx,
181 const glu::ContextInfo& contextInfo,
182 const char* caseName,
183 const char* description,
184 const ShaderCaseSpecification& specification);
185 ShaderCase (tcu::TestContext& testCtx,
186 glu::RenderContext& renderCtx,
187 const glu::ContextInfo& contextInfo,
188 const char* caseName,
189 const char* description,
190 const PipelineCaseSpecification& specification);
191 virtual ~ShaderCase (void);
196 IterateResult iterate (void);
198 ShaderCase (const ShaderCase&); // not allowed!
199 ShaderCase& operator= (const ShaderCase&); // not allowed!
201 std::string genVertexShader (const ValueBlock& valueBlock) const;
202 std::string genFragmentShader (const ValueBlock& valueBlock) const;
203 std::string specializeVertexShader (const char* src, const ValueBlock& valueBlock) const;
204 std::string specializeFragmentShader (const char* src, const ValueBlock& valueBlock) const;
205 void specializeVertexShaders (glu::ProgramSources& dst, const std::vector<std::string>& sources, const ValueBlock& valueBlock, const std::vector<ShaderCase::CaseRequirement>& requirements) const;
206 void specializeFragmentShaders (glu::ProgramSources& dst, const std::vector<std::string>& sources, const ValueBlock& valueBlock, const std::vector<ShaderCase::CaseRequirement>& requirements) const;
207 void specializeGeometryShaders (glu::ProgramSources& dst, const std::vector<std::string>& sources, const ValueBlock& valueBlock, const std::vector<ShaderCase::CaseRequirement>& requirements) const;
208 void specializeTessControlShaders (glu::ProgramSources& dst, const std::vector<std::string>& sources, const ValueBlock& valueBlock, const std::vector<ShaderCase::CaseRequirement>& requirements) const;
209 void specializeTessEvalShaders (glu::ProgramSources& dst, const std::vector<std::string>& sources, const ValueBlock& valueBlock, const std::vector<ShaderCase::CaseRequirement>& requirements) const;
210 bool isTessellationPresent (void) const;
211 bool anyProgramRequiresFullGLSLES100Specification (void) const;
213 void dumpValues (const ValueBlock& valueBlock, int arrayNdx);
215 bool checkPixels (tcu::Surface& surface, int minX, int maxX, int minY, int maxY);
219 glu::ProgramSources programSources;
220 PipelineProgram spec;
224 glu::RenderContext& m_renderCtx;
225 const glu::ContextInfo& m_contextInfo;
226 const CaseType m_caseType;
227 const ExpectResult m_expectResult;
228 const glu::GLSLVersion m_targetVersion;
229 const bool m_separatePrograms;
230 std::vector<ValueBlock> m_valueBlocks;
231 std::vector<ProgramObject> m_programs;
238 #endif // _GLSSHADERLIBRARYCASE_HPP