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