Optimize swapchain OOM tests am: 1614827a71 am: 2cfe132119 am: 00ab17bd23 am: c9b7dae...
[platform/upstream/VK-GL-CTS.git] / external / openglcts / modules / common / glcShaderLibraryCase.hpp
1 #ifndef _GLCSHADERLIBRARYCASE_HPP
2 #define _GLCSHADERLIBRARYCASE_HPP
3 /*-------------------------------------------------------------------------
4  * OpenGL Conformance Test Suite
5  * -----------------------------
6  *
7  * Copyright (c) 2016 Google Inc.
8  * Copyright (c) 2016 The Khronos Group Inc.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */ /*!
23  * \file
24  * \brief Shader test case.
25  */ /*-------------------------------------------------------------------*/
26
27 #include "glcTestCase.hpp"
28 #include "gluDefs.hpp"
29 #include "gluRenderContext.hpp"
30 #include "gluShaderUtil.hpp"
31 #include "tcuSurface.hpp"
32
33 #include <string>
34 #include <vector>
35
36 namespace deqp
37 {
38 namespace sl
39 {
40
41 // ShaderCase node.
42
43 class ShaderCase : public tcu::TestCase
44 {
45 public:
46         enum CaseType
47         {
48                 CASETYPE_COMPLETE = 0,  //!< Has both shaders.
49                 CASETYPE_VERTEX_ONLY,   //!< Has only vertex shader.
50                 CASETYPE_FRAGMENT_ONLY, //!< Has only fragment shader.
51
52                 CASETYPE_LAST
53         };
54
55         enum ExpectResult
56         {
57                 EXPECT_PASS = 0,
58                 EXPECT_COMPILE_FAIL,
59                 EXPECT_LINK_FAIL,
60
61                 EXPECT_LAST
62         };
63
64         struct Value
65         {
66                 enum StorageType
67                 {
68                         STORAGE_UNIFORM,
69                         STORAGE_INPUT,
70                         STORAGE_OUTPUT,
71
72                         STORAGE_LAST
73                 };
74
75                 /* \todo [2010-03-31 petri] Replace with another vector to allow a) arrays, b) compact representation */
76                 union Element {
77                         float   float32;
78                         deInt32 int32;
79                         deInt32 bool32;
80                 };
81
82                 StorageType                      storageType;
83                 std::string                      valueName;
84                 glu::DataType            dataType;
85                 int                                      arrayLength; // Number of elements in array (currently always 1).
86                 std::vector<Element> elements;  // Scalar values (length dataType.scalarSize * arrayLength).
87         };
88
89         struct ValueBlock
90         {
91                 int                                arrayLength; // Combined array length of each value (lengths must be same, or one).
92                 std::vector<Value> values;
93                 ValueBlock(void)
94                 {
95                         arrayLength = 0;
96                         values.empty();
97                 }
98         };
99
100         // Methods.
101         ShaderCase(tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* caseName, const char* description,
102                            ExpectResult expectResult, const std::vector<ValueBlock>& valueBlocks, glu::GLSLVersion targetVersion,
103                            const char* vertexSource, const char* fragmentSource);
104
105         virtual ~ShaderCase(void);
106
107         CaseType getCaseType(void) const
108         {
109                 return m_caseType;
110         }
111         const std::vector<ValueBlock>& getValueBlocks(void) const
112         {
113                 return m_valueBlocks;
114         }
115         const char* getVertexSource(void) const
116         {
117                 return m_vertexSource.c_str();
118         }
119         const char* getFragmentSource(void) const
120         {
121                 return m_fragmentSource.c_str();
122         }
123
124         bool              execute(void);
125         IterateResult iterate(void);
126
127 private:
128         ShaderCase(const ShaderCase&);                    // not allowed!
129         ShaderCase& operator=(const ShaderCase&); // not allowed!
130
131         std::string genVertexShader(const ValueBlock& valueBlock);
132         std::string genFragmentShader(const ValueBlock& valueBlock);
133         std::string specializeVertexShader(const char* src, const ValueBlock& valueBlock);
134         std::string specializeFragmentShader(const char* src, const ValueBlock& valueBlock);
135
136         void specializeShaders(const char* vertexSource, const char* fragmentSource, std::string& outVertexSource,
137                                                    std::string& outFragmentSource, const ValueBlock& valueBlock);
138
139         void dumpValues(const ValueBlock& valueBlock, int arrayNdx);
140
141         bool checkPixels(tcu::Surface& surface, int minX, int maxX, int minY, int maxY);
142
143         // Member variables.
144         glu::RenderContext&             m_renderCtx;
145         CaseType                                m_caseType;
146         ExpectResult                    m_expectResult;
147         std::vector<ValueBlock> m_valueBlocks;
148         glu::GLSLVersion                m_targetVersion;
149         std::string                             m_vertexSource;
150         std::string                             m_fragmentSource;
151 };
152
153 } // sl
154 } // deqp
155
156 #endif // _GLCSHADERLIBRARYCASE_HPP