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