1 #ifndef _ESEXTCTESTCASEBASE_HPP
2 #define _ESEXTCTESTCASEBASE_HPP
3 /*-------------------------------------------------------------------------
4 * OpenGL Conformance Test Suite
5 * -----------------------------
6 *
7 * Copyright (c) 2014-2016 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 #include "glcContext.hpp"
27 #include "gluShaderUtil.hpp"
28 #include "tcuDefs.hpp"
29 #include "tcuTestCase.hpp"
30
31 #include "glcExtTokens.hpp"
32 #include "glwDefs.hpp"
33 #include "glwFunctions.hpp"
34 #include <map>
35 #include <math.h>
36 #include <string.h>
37
38 /* String definitions */
39 #define GEOMETRY_SHADER_EXTENSION_NOT_SUPPORTED "Geometry shader functionality not supported, skipping"
40 #define GEOMETRY_SHADER_POINT_SIZE_NOT_SUPPORTED "Geometry shader point size functionality not supported, skipping"
41 #define GPU_SHADER5_EXTENSION_NOT_SUPPORTED "GPU shader5 functionality not supported, skipping"
42 #define TESSELLATION_SHADER_EXTENSION_NOT_SUPPORTED "Tessellation shader functionality not supported, skipping"
43 #define TEXTURE_BORDER_CLAMP_NOT_SUPPORTED "Texture border clamp functionality not supported, skipping"
44 #define TEXTURE_CUBE_MAP_ARRAY_EXTENSION_NOT_SUPPORTED "Texture cube map array functionality not supported, skipping"
45 #define SHADER_IMAGE_ATOMIC_EXTENSION_NOT_SUPPORTED "Shader image atomic functionality not supported, skipping"
46 #define TEXTURE_BUFFER_EXTENSION_NOT_SUPPORTED "Texture buffer functionality not supported, skipping"
47 #define DRAW_BUFFERS_INDEXED_NOT_SUPPORTED "Draw buffers indexed functionality not supported, skipping"
48 #define VIEWPORT_ARRAY_NOT_SUPPORTED "Viewport array functionality not supported, skipping"
49 #define DISJOINT_TIMER_QUERY_NOT_SUPPORTED "Disjoint timer query functionality not supported, skipping"
50 #define FRAGMENT_SHADING_RATE_NOT_SUPPORTED "Fragment shading rate functionality not supported, skipping"
51 #define FRAGMENT_SHADING_RATE_PRIMITIVE_NOT_SUPPORTED \
52 "Fragment shading rate primitive functionality not supported, skipping"
53 #define FRAGMENT_SHADING_RATE_ATTACHMENT_NOT_SUPPORTED \
54 "Fragment shading rate attachment functionality not supported, skipping"
55 #define MULTIVIEW_OVR_NOT_SUPPORTED "multiview ovr functionality not supported, skipping"
56
57 namespace glcts
58 {
59 /* Define allowed storage types */
60 enum STORAGE_TYPE
61 {
62 ST_MUTABLE, /* Mutable Storage */
63 ST_IMMUTABLE /* Immutable Storage */
64 };
65
66 /* Extension names */
67 enum ExtensionName
68 {
69 EXTENSIONNAME_SHADER_IMAGE_ATOMIC,
70 EXTENSIONNAME_SHADER_IO_BLOCKS,
71 EXTENSIONNAME_GEOMETRY_SHADER,
72 EXTENSIONNAME_GEOMETRY_POINT_SIZE,
73 EXTENSIONNAME_TESSELLATION_SHADER,
74 EXTENSIONNAME_TESSELLATION_POINT_SIZE,
75 EXTENSIONNAME_TEXTURE_BUFFER,
76 EXTENSIONNAME_TEXTURE_CUBE_MAP_ARRAY,
77 EXTENSIONNAME_GPU_SHADER5,
78 EXTENSIONNAME_VIEWPORT_ARRAY,
79 };
80
81 /* Extension type */
82 enum ExtensionType
83 {
84 EXTENSIONTYPE_NONE, /* Not an extension (part of this version of OpenGL or OpenGL ES) */
85 EXTENSIONTYPE_EXT, /* EXT multivendor extension */
86 EXTENSIONTYPE_OES /* OES Khronos extension */
87 };
88
89 enum ExtensionBehavior
90 {
91 EXTENSIONBEHAVIOR_DISABLE, /* disable */
92 EXTENSIONBEHAVIOR_WARN, /* warn */
93 EXTENSIONBEHAVIOR_ENABLE, /* enable */
94 EXTENSIONBEHAVIOR_REQUIRE /* require */
95 };
96
97 using deqp::Context;
98
99 struct ExtParameters
100 {
101 glu::GLSLVersion glslVersion;
102 ExtensionType extType;
103
ExtParametersglcts::ExtParameters104 ExtParameters(glu::GLSLVersion _glslVersion, ExtensionType _extType) : glslVersion(_glslVersion), extType(_extType)
105 {
106 }
107 };
108
109 /**
110 * Base class for tests implementations.
111 */
112 class TestCaseBase : public tcu::TestCase
113 {
114 public:
115 /* Public methods */
116
117 /* Destructor */
~TestCaseBase(void)118 virtual ~TestCaseBase(void)
119 {
120 }
121
122 static const float m_epsilon_float;
123
124 protected:
125 enum LOG_TYPE
126 {
127 LT_SHADER_OBJECT, /* Shader object */
128 LT_PROGRAM_OBJECT, /* Program object */
129 LT_PIPELINE_OBJECT /* Program pipeline object */
130 };
131 /* Protected type definitions */
132
133 /* Protected methods */
134
135 /* Constructor */
136 TestCaseBase(Context& context, const ExtParameters& extParam, const char* name, const char* description);
137
138 /* Methods that a derived test case should reimplement */
139 virtual void deinit(void);
140 virtual void init(void);
141 virtual IterateResult iterate(void);
142
143 /* Initializes extension function pointers */
144 void initExtensions();
145
146 /* Initializes GLSL specialization map */
147 void initGLSLSpecializationMap();
148
149 /* Function that generates an extension directive */
150 std::string getGLSLExtDirective(ExtensionType type, ExtensionName name, ExtensionBehavior behavior);
151
152 /* Sets the seed for the random generator */
153 void randomSeed(const glw::GLuint seed);
154
155 /* Returns random unsigned integer from the range [0,max) */
156 glw::GLuint randomFormula(const glw::GLuint max);
157
158 /* Helper method for verification of pixel color */
159 bool comparePixel(const unsigned char* buffer, unsigned int x, unsigned int y, unsigned int width,
160 unsigned int height, unsigned int pixel_size, unsigned char expected_red = 0,
161 unsigned char expected_green = 0, unsigned char expected_blue = 0,
162 unsigned char expected_alpha = 0) const;
163
164 /* Helper method for checking if an extension is supported*/
165 bool isExtensionSupported(const std::string& extName) const;
166
167 /* Program creation and validation helper methods */
168 std::string specializeShader(const unsigned int parts, const char* const* code) const;
169 void shaderSourceSpecialized(glw::GLuint shader_id, glw::GLsizei shader_count,
170 const glw::GLchar* const* shader_string);
171
172 bool buildProgram(glw::GLuint po_id, glw::GLuint sh1_shader_id, unsigned int n_sh1_body_parts,
173 const char* const* sh1_body_parts, bool* out_has_compilation_failed = NULL);
174
175 bool buildProgram(glw::GLuint po_id, glw::GLuint sh1_shader_id, unsigned int n_sh1_body_parts,
176 const char* const* sh1_body_parts, glw::GLuint sh2_shader_id, unsigned int n_sh2_body_parts,
177 const char* const* sh2_body_parts, bool* out_has_compilation_failed = NULL);
178
179 bool buildProgram(glw::GLuint po_id, glw::GLuint sh1_shader_id, unsigned int n_sh1_body_parts,
180 const char* const* sh1_body_parts, glw::GLuint sh2_shader_id, unsigned int n_sh2_body_parts,
181 const char* const* sh2_body_parts, glw::GLuint sh3_shader_id, unsigned int n_sh3_body_parts,
182 const char* const* sh3_body_parts, bool* out_has_compilation_failed = NULL);
183
184 bool buildProgram(glw::GLuint po_id, glw::GLuint sh1_shader_id, unsigned int n_sh1_body_parts,
185 const char* const* sh1_body_parts, glw::GLuint sh2_shader_id, unsigned int n_sh2_body_parts,
186 const char* const* sh2_body_parts, glw::GLuint sh3_shader_id, unsigned int n_sh3_body_parts,
187 const char* const* sh3_body_parts, glw::GLuint sh4_shader_id, unsigned int n_sh4_body_parts,
188 const char* const* sh4_body_parts, bool* out_has_compilation_failed = NULL);
189
190 bool buildProgram(glw::GLuint po_id, glw::GLuint sh1_shader_id, unsigned int n_sh1_body_parts,
191 const char* const* sh1_body_parts, glw::GLuint sh2_shader_id, unsigned int n_sh2_body_parts,
192 const char* const* sh2_body_parts, glw::GLuint sh3_shader_id, unsigned int n_sh3_body_parts,
193 const char* const* sh3_body_parts, glw::GLuint sh4_shader_id, unsigned int n_sh4_body_parts,
194 const char* const* sh4_body_parts, glw::GLuint sh5_shader_id, unsigned int n_sh5_body_parts,
195 const char* const* sh5_body_parts, bool* out_has_compilation_failed = NULL);
196
197 bool doesProgramBuild(unsigned int n_fs_body_parts, const char* const* fs_body_parts, unsigned int n_gs_body_parts,
198 const char* const* gs_body_parts, unsigned int n_vs_body_parts,
199 const char* const* vs_body_parts);
200
201 std::string getShaderSource(glw::GLuint shader_id);
202 std::string getCompilationInfoLog(glw::GLuint shader_id);
203 std::string getLinkingInfoLog(glw::GLuint po_id);
204 std::string getPipelineInfoLog(glw::GLuint ppo_id);
205
206 /* Helper method for setting up a fraembuffer with texture as color attachment */
207 bool setupFramebufferWithTextureAsAttachment(glw::GLuint framebuffer_object_id, glw::GLuint color_texture_id,
208 glw::GLenum texture_format, glw::GLuint width,
209 glw::GLuint height) const;
210
211 void checkFramebufferStatus(glw::GLenum framebuffer) const;
212
213 /* Protected variables */
214 Context& m_context;
215 glu::GLSLVersion m_glslVersion;
216 ExtensionType m_extType;
217 std::map<std::string, std::string> m_specializationMap;
218
219 bool m_is_framebuffer_no_attachments_supported;
220 bool m_is_geometry_shader_extension_supported;
221 bool m_is_geometry_shader_point_size_supported;
222 bool m_is_gpu_shader5_supported;
223 bool m_is_program_interface_query_supported;
224 bool m_is_shader_image_load_store_supported;
225 bool m_is_shader_image_atomic_supported;
226 bool m_is_texture_storage_multisample_supported;
227 bool m_is_texture_storage_multisample_2d_array_supported;
228 bool m_is_tessellation_shader_supported;
229 bool m_is_tessellation_shader_point_size_supported;
230 bool m_is_texture_cube_map_array_supported;
231 bool m_is_texture_border_clamp_supported;
232 bool m_is_texture_buffer_supported;
233 bool m_is_viewport_array_supported;
234 bool m_is_fragment_shading_rate_supported;
235 bool m_is_fragment_shading_rate_primitive_supported;
236 bool m_is_fragment_shading_rate_attachment_supported;
237 bool m_is_multiview_ovr_supported;
238
239 /* Predefined shader strings */
240 static const char* m_boilerplate_vs_code;
241
242 /* GL tokens that are diferent for functionalities
243 * enabled by extensions and for functionalities that
244 * are present in the core. */
245 deqp::GLExtTokens m_glExtTokens;
246
247 private:
248 /* Private functions */
249 bool buildProgramVA(glw::GLuint po_id, bool* out_has_compilation_failed, unsigned int sh_stages, ...);
250 std::string getInfoLog(LOG_TYPE log_type, glw::GLuint id);
251
252 /* Private variables */
253 glw::GLuint seed_value;
254
255 friend class TessellationShaderUtils;
256 };
257
258 /* Test Case Group that tracks GLSL version and extension type */
259 class TestCaseGroupBase : public tcu::TestCaseGroup
260 {
261 public:
262 TestCaseGroupBase(Context& context, const ExtParameters& extParam, const char* name, const char* description);
263
~TestCaseGroupBase(void)264 virtual ~TestCaseGroupBase(void)
265 {
266 }
267
getContext(void)268 Context& getContext(void)
269 {
270 return m_context;
271 }
272
273 protected:
274 Context& m_context;
275 ExtParameters m_extParams;
276 };
277
TestCaseGroupBase(Context & context,const ExtParameters & extParams,const char * name,const char * description)278 inline TestCaseGroupBase::TestCaseGroupBase(Context& context, const ExtParameters& extParams, const char* name,
279 const char* description)
280 : tcu::TestCaseGroup(context.getTestContext(), name, description), m_context(context), m_extParams(extParams)
281 {
282 }
283
284 } // namespace glcts
285
286 #endif // _ESEXTCTESTCASEBASE_HPP
287