GetDevices: Also allow `\.` to be part of the host name
[platform/upstream/VK-GL-CTS.git] / modules / glshared / glsShaderLibraryCase.hpp
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                 EXPECT_BUILD_SUCCESSFUL,
65
66                 EXPECT_LAST
67         };
68
69         struct Value
70         {
71                 enum StorageType
72                 {
73                         STORAGE_UNIFORM,
74                         STORAGE_INPUT,
75                         STORAGE_OUTPUT,
76
77                         STORAGE_LAST
78                 };
79
80                 /* \todo [2010-03-31 petri] Replace with another vector to allow a) arrays, b) compact representation */
81                 union Element
82                 {
83                         float           float32;
84                         deInt32         int32;
85                         deInt32         bool32;
86                 };
87
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).
93         };
94
95         struct ValueBlock
96         {
97                                                         ValueBlock (void);
98
99                 int                                     arrayLength;            // Combined array length of each value (lengths must be same, or one).
100                 std::vector<Value>      values;
101         };
102
103         class CaseRequirement
104         {
105         public:
106                 enum RequirementType
107                 {
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
111
112                         REQUIREMENTTYPE_LAST
113                 };
114
115                                                                         CaseRequirement                                                         (void);
116
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);
121
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; }
125
126         private:
127                 RequirementType                         m_type;
128
129                 // REQUIREMENTTYPE_EXTENSION:
130                 std::vector<std::string>        m_extensions;
131                 int                                                     m_supportedExtensionNdx;
132                 deUint32                                        m_effectiveShaderStageFlags;
133
134                 // REQUIREMENTTYPE_IMPLEMENTATION_LIMIT:
135                 deUint32                                        m_enumName;
136                 int                                                     m_referenceValue;
137         };
138
139         struct ShaderCaseSpecification
140         {
141                                                                                 ShaderCaseSpecification                         (void);
142
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);
145
146                 ExpectResult                                    expectResult;
147                 glu::GLSLVersion                                targetVersion;
148                 CaseType                                                caseType;
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;
156         };
157
158         struct PipelineProgram
159         {
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;
167         };
168
169         struct PipelineCaseSpecification
170         {
171                 ExpectResult                                    expectResult;
172                 glu::GLSLVersion                                targetVersion;
173                 CaseType                                                caseType;
174                 std::vector<ValueBlock>                 valueBlocks;
175                 std::vector<PipelineProgram>    programs;
176         };
177
178         // Methods.
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);
192
193 private:
194         void                                                    init                                                                                    (void);
195         bool                                                    execute                                                                                 (void);
196         IterateResult                                   iterate                                                                                 (void);
197
198                                                                         ShaderCase                                                                              (const ShaderCase&);            // not allowed!
199         ShaderCase&                                             operator=                                                                               (const ShaderCase&);            // not allowed!
200
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;
212
213         void                                                    dumpValues                                                                              (const ValueBlock& valueBlock, int arrayNdx);
214
215         bool                                                    checkPixels                                                                             (tcu::Surface& surface, int minX, int maxX, int minY, int maxY);
216
217         struct ProgramObject
218         {
219                 glu::ProgramSources             programSources;
220                 PipelineProgram                 spec;
221         };
222
223         // Member variables.
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;
232 };
233
234 } // sl
235 } // gls
236 } // deqp
237
238 #endif // _GLSSHADERLIBRARYCASE_HPP