xref: /aosp_15_r20/external/deqp/external/openglcts/modules/gl/gl4cGlSpirvTests.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _GL4CGLSPIRVTESTS_HPP
2 #define _GL4CGLSPIRVTESTS_HPP
3 /*-------------------------------------------------------------------------
4  * OpenGL Conformance Test Suite
5  * -----------------------------
6  *
7  * Copyright (c) 2017 The Khronos Group Inc.
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
24  */ /*-------------------------------------------------------------------*/
25 
26 /**
27  */ /*!
28  * \file  gl4cGlSpirvTests.hpp
29  * \brief Conformance tests for the GL_ARB_gl_spirv functionality.
30  */ /*-------------------------------------------------------------------*/
31 
32 #include "../common/glcSpirvUtils.hpp"
33 #include "glcTestCase.hpp"
34 #include "gluShaderProgram.hpp"
35 #include "glwDefs.hpp"
36 #include "tcuDefs.hpp"
37 #include <map>
38 #include <vector>
39 
40 using namespace glu;
41 using namespace glw;
42 using namespace glc;
43 
44 namespace gl4cts
45 {
46 
47 typedef std::vector<std::string> CapabilitiesVec;
48 
49 /**  Verifies if using SPIR-V modules for each shader stage works as expected. */
50 class SpirvModulesPositiveTest : public deqp::TestCase
51 {
52 public:
53     /* Public methods */
54     SpirvModulesPositiveTest(deqp::Context &context);
55 
56     void init();
57     void deinit();
58 
59     tcu::TestNode::IterateResult iterate();
60 
61 private:
62     /* Private methods */
63 
64     /* Private members */
65     GLuint m_texture;
66     GLuint m_fbo;
67 
68     std::string m_vertex;
69     std::string m_tesselationCtrl;
70     std::string m_tesselationEval;
71     std::string m_geometry;
72     std::string m_fragment;
73 };
74 
75 /**  Verifies if one binary module can be associated with multiple shader objects. */
76 class SpirvShaderBinaryMultipleShaderObjectsTest : public deqp::TestCase
77 {
78 public:
79     /* Public methods */
80     SpirvShaderBinaryMultipleShaderObjectsTest(deqp::Context &context);
81 
82     void init();
83     void deinit();
84 
85     tcu::TestNode::IterateResult iterate();
86 
87 private:
88     /* Private methods */
89 
90     /* Private members */
91     std::string m_spirv;
92 };
93 
94 /**  Verifies if state queries for new features added by ARB_gl_spirv works as expected. */
95 class SpirvModulesStateQueriesTest : public deqp::TestCase
96 {
97 public:
98     /* Public methods */
99     SpirvModulesStateQueriesTest(deqp::Context &context);
100 
101     void init();
102     void deinit();
103 
104     tcu::TestNode::IterateResult iterate();
105 
106 private:
107     /* Private methods */
108 
109     /* Private members */
110     std::string m_vertex;
111 };
112 
113 /**  Verifies if new features added by ARB_gl_spirv generate error messages as expected. */
114 class SpirvModulesErrorVerificationTest : public deqp::TestCase
115 {
116 public:
117     /* Public methods */
118     SpirvModulesErrorVerificationTest(deqp::Context &context);
119 
120     void init();
121     void deinit();
122 
123     tcu::TestNode::IterateResult iterate();
124 
125 private:
126     /* Private methods */
127 
128     /* Private members */
129     std::string m_vertex;
130 
131     GLuint m_glslShaderId;
132     GLuint m_spirvShaderId;
133     GLuint m_programId;
134     GLuint m_textureId;
135 };
136 
137 /**  Verifies if GLSL to Spir-V converter supports Spir-V features. */
138 class SpirvGlslToSpirVEnableTest : public deqp::TestCase
139 {
140 public:
141     /* Public methods */
142     SpirvGlslToSpirVEnableTest(deqp::Context &context);
143 
144     void init();
145     void deinit();
146 
147     tcu::TestNode::IterateResult iterate();
148 
149 private:
150     /* Private methods */
151 
152     /* Private members */
153     std::string m_vertex;
154 };
155 
156 /**  Verifies if GLSL built-in functions are supported by Spir-V. */
157 class SpirvGlslToSpirVBuiltInFunctionsTest : public deqp::TestCase
158 {
159 public:
160     /* Public methods */
161     SpirvGlslToSpirVBuiltInFunctionsTest(deqp::Context &context);
162 
163     void init();
164     void deinit();
165 
166     tcu::TestNode::IterateResult iterate();
167 
168 private:
169     /* Private methods */
170     void initMappings();
171 
172     /* Private members */
173     SpirVMapping m_mappings;
174 
175     std::string m_commonVertex;
176     std::string m_commonTessEval;
177     std::vector<ShaderSource> m_sources;
178 };
179 
180 /**  Verifies if constant specialization feature works as expected. */
181 class SpirvGlslToSpirVSpecializationConstantsTest : public deqp::TestCase
182 {
183 public:
184     /* Public methods */
185     SpirvGlslToSpirVSpecializationConstantsTest(deqp::Context &context);
186 
187     void init();
188     void deinit();
189 
190     tcu::TestNode::IterateResult iterate();
191 
192 private:
193     /* Private methods */
194 
195     /* Private members */
196     GLuint m_texture;
197     GLuint m_fbo;
198 
199     std::string m_vertex;
200     std::string m_fragment;
201 };
202 
203 /**  Verifies if Spir-V built in variable decorations works as expected. */
204 class SpirvValidationBuiltInVariableDecorationsTest : public deqp::TestCase
205 {
206 public:
207     /* Public methods */
208     SpirvValidationBuiltInVariableDecorationsTest(deqp::Context &context);
209 
210     void init();
211     void deinit();
212 
213     tcu::TestNode::IterateResult iterate();
214 
215 private: /* Private structs */
216     struct ValidationOutputStruct
217     {
218         GLubyte x, y, z;
219         GLuint value;
220 
ValidationOutputStructgl4cts::SpirvValidationBuiltInVariableDecorationsTest::ValidationOutputStruct221         ValidationOutputStruct() : x(0), y(0), z(0), value(0)
222         {
223         }
224 
ValidationOutputStructgl4cts::SpirvValidationBuiltInVariableDecorationsTest::ValidationOutputStruct225         ValidationOutputStruct(GLubyte _x, GLubyte _y, GLuint _value) : x(_x), y(_y), z(0), value(_value)
226         {
227         }
228 
ValidationOutputStructgl4cts::SpirvValidationBuiltInVariableDecorationsTest::ValidationOutputStruct229         ValidationOutputStruct(GLubyte _x, GLubyte _y, GLubyte _z, GLuint _value) : x(_x), y(_y), z(_z), value(_value)
230         {
231         }
232     };
233 
234     typedef std::vector<ValidationOutputStruct> ValidationOutputVec;
235 
236     typedef bool (SpirvValidationBuiltInVariableDecorationsTest::*ValidationFuncPtr)(ValidationOutputVec &outputs);
237 
238     struct ValidationStruct
239     {
240         std::vector<ShaderSource> shaders;
241         ValidationOutputVec outputs;
242         ValidationFuncPtr validationFuncPtr;
243 
ValidationStructgl4cts::SpirvValidationBuiltInVariableDecorationsTest::ValidationStruct244         ValidationStruct() : validationFuncPtr(DE_NULL)
245         {
246         }
247 
ValidationStructgl4cts::SpirvValidationBuiltInVariableDecorationsTest::ValidationStruct248         ValidationStruct(ValidationFuncPtr funcPtr) : validationFuncPtr(funcPtr)
249         {
250         }
251     };
252 
253     /* Private methods */
254     bool validComputeFunc(ValidationOutputVec &outputs);
255     bool validPerVertexFragFunc(ValidationOutputVec &outputs);
256     bool validPerVertexPointFunc(ValidationOutputVec &outputs);
257     bool validTesselationGeometryFunc(ValidationOutputVec &outputs);
258     bool validMultiSamplingFunc(ValidationOutputVec &outputs);
259 
260     /* Private members */
261     SpirVMapping m_mappings;
262 
263     std::vector<ValidationStruct> m_validations;
264 
265     std::string m_compute;
266     std::string m_vertex;
267     std::string m_tesselationCtrl;
268     std::string m_tesselationEval;
269     std::string m_geometry;
270     std::string m_fragment;
271 };
272 
273 /**  Verifies if Spir-V capabilities works as expected. */
274 class SpirvValidationCapabilitiesTest : public deqp::TestCase
275 {
276 public:
277     /* Public methods */
278     SpirvValidationCapabilitiesTest(deqp::Context &context);
279 
280     void init();
281     void deinit();
282 
283     tcu::TestNode::IterateResult iterate();
284 
285     int spirVCapabilityCutOff(std::string spirVSrcInput, std::string &spirVSrcOutput, CapabilitiesVec &capabilities,
286                               int &currentCapability);
287 
288 private:
289     typedef std::map<glu::ShaderType, CapabilitiesVec> CapabilitiesMap;
290 
291     struct ShaderStage
292     {
293         std::string name;
294         ShaderSource source;
295         ShaderBinary binary;
296         CapabilitiesVec caps;
297 
ShaderStagegl4cts::SpirvValidationCapabilitiesTest::ShaderStage298         ShaderStage()
299         {
300         }
301 
ShaderStagegl4cts::SpirvValidationCapabilitiesTest::ShaderStage302         ShaderStage(std::string _name) : name(_name)
303         {
304         }
305     };
306 
307     typedef std::vector<ShaderStage> Pipeline;
308 
309     /* Private methods */
310 
311     /* Private members */
312     std::vector<Pipeline> m_pipelines;
313 };
314 
315 /** Test group which encapsulates all sparse buffer conformance tests */
316 class GlSpirvTests : public deqp::TestCaseGroup
317 {
318 public:
319     /* Public methods */
320     GlSpirvTests(deqp::Context &context);
321 
322     void init();
323 
324 private:
325     GlSpirvTests(const GlSpirvTests &other);
326     GlSpirvTests &operator=(const GlSpirvTests &other);
327 };
328 
329 } // namespace gl4cts
330 
331 #endif // _GL4CGLSPIRVTESTS_HPP
332