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