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