ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_view / formats.c
blob56415db52fd0d798398aa2e5adc72c58637339d7
1 /*
2 * Copyright © 2013 LunarG, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
23 * Author: Jon Ashburn <jon@lunarg.com>
26 /**
27 * \file
28 * This (arb_texture_view-formats) tests valid and invalid new TextureView
29 * formats based on the original textures format.
31 * Section 8.18 (Texture Views) of OpenGL 4.3 Core says:
32 * "The two textures’ internal formats must be compatible according to
33 * table 8.21 if the internal format exists in that table. The internal
34 * formats must be identical if not in that table."
38 #include "piglit-util-gl.h"
39 #include "common.h"
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config.supports_gl_compat_version = 15;
44 config.supports_gl_core_version = 31;
45 config.supports_gl_es_version = 31;
47 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
48 config.khr_no_error_support = PIGLIT_NO_ERRORS;
50 PIGLIT_GL_TEST_CONFIG_END
52 static const char *TestName = "arb_texture_view-formats";
54 #define MAX_ILLEGAL_FORMATS 17
55 #define VIEW_CLASS_NOT_IN_TABLE 0xfffffff
57 /**
58 * Iterate through array of texture formats and check if call to TextureView
59 * causes the gl error "err"
61 static bool
62 check_format_array(const GLenum err, const unsigned int numFormats,
63 const GLenum *formatArray, const GLenum target,
64 const GLuint tex, const GLuint levels, const
65 GLuint layers)
67 unsigned int i;
68 bool pass = true;
70 for (i = 0; i < numFormats; i++) {
71 GLenum format;
72 GLuint newTex;
73 format = formatArray[i];
74 if (format == 0)
75 continue;
76 glGenTextures(1, &newTex);
77 glTextureView(newTex, target, tex, format, 0, levels, 0,
78 layers);
79 glDeleteTextures(1, &newTex);
80 if (!piglit_check_gl_error(err)) {
81 printf("failing texView format=%s\n",
82 piglit_get_gl_enum_name(format));
83 pass = false;
84 break;
87 return pass;
90 /**
91 * Do error-check tests for texture formats
93 static bool
94 test_format_errors(GLenum format_class)
96 const GLint width = 16, height = 16;
97 const GLsizei levels = 5, layers = 6;
98 GLenum target = GL_TEXTURE_CUBE_MAP;
99 GLuint tex;
100 bool pass = true;
101 GLenum legalFormats[MAX_ILLEGAL_FORMATS];
102 unsigned int numFormats;
103 GLenum illegalFormats[] = {
104 /* skip compressed sized formats */
105 /* 128 bit */
106 GL_RGBA32F,
107 GL_RGBA32UI,
108 GL_RGBA32I,
109 /* 96 bit */
110 GL_RGB32F,
111 GL_RGB32UI,
112 GL_RGB32I,
113 /* 64 bit */
114 GL_RGBA16F,
115 GL_RG32F,
116 GL_RGBA16UI,
117 GL_RG32UI,
118 GL_RGBA16I,
119 GL_RG32I,
120 /* 48 bit */
121 GL_RGB16F,
122 GL_RGB16UI,
123 GL_RGB16I,
124 /* 32 bits */
125 GL_RG16F,
126 GL_R11F_G11F_B10F,
127 GL_R32F,
128 GL_RGB10_A2UI,
129 GL_RGBA8UI,
130 GL_RG16UI,
131 GL_R32UI,
132 GL_RGBA8I,
133 GL_RG16I,
134 GL_R32I,
135 GL_RGB10_A2,
136 GL_RGBA8,
137 GL_RGBA8_SNORM,
138 GL_SRGB8_ALPHA8,
139 GL_RGB9_E5,
140 /* 24 bits */
141 GL_RGB8,
142 GL_RGB8_SNORM,
143 GL_SRGB8,
144 GL_RGB8UI,
145 GL_RGB8I,
146 /* 16 bits */
147 GL_R16F,
148 GL_RG8UI,
149 GL_R16UI,
150 GL_RG8I,
151 GL_R16I,
152 GL_RG8,
153 GL_RG8_SNORM,
154 /* 8 bits */
155 GL_R8UI,
156 GL_R8I,
157 GL_R8,
158 GL_R8_SNORM,
159 /* a sampling of unsized formats */
160 GL_ALPHA,
161 GL_LUMINANCE,
162 GL_LUMINANCE_ALPHA,
163 GL_INTENSITY,
164 GL_RGB,
165 GL_RGBA,
166 GL_DEPTH_COMPONENT,
167 GL_COMPRESSED_ALPHA,
168 GL_COMPRESSED_LUMINANCE_ALPHA,
169 GL_COMPRESSED_LUMINANCE,
170 GL_COMPRESSED_INTENSITY,
171 GL_COMPRESSED_RGB,
172 GL_COMPRESSED_RGBA,
173 GL_COMPRESSED_RGBA,
174 GL_COMPRESSED_SRGB,
175 GL_COMPRESSED_SRGB_ALPHA,
176 GL_COMPRESSED_SLUMINANCE,
177 GL_COMPRESSED_SLUMINANCE_ALPHA,
178 /* format that is legal for TexStorage but not in table */
179 GL_RGBA4,
180 /* 16-bit norm formats */
181 GL_RGBA16,
182 GL_RGBA16_SNORM,
183 GL_RGB16,
184 GL_RGB16_SNORM,
185 GL_RG16,
186 GL_RG16_SNORM,
187 GL_R16,
188 GL_R16_SNORM,
190 int totalFormats = ARRAY_SIZE(illegalFormats);
192 if (piglit_is_gles() &&
193 !piglit_is_extension_supported("GL_EXT_texture_norm16"))
194 totalFormats -= 8;
196 glGenTextures(1, &tex); /* orig tex */
197 glBindTexture(target, tex);
199 switch (format_class) {
200 case GL_VIEW_CLASS_128_BITS:
201 glTexStorage2D(target, levels, GL_RGBA32F, width, height);
202 numFormats = update_valid_arrays(legalFormats, illegalFormats,
203 totalFormats,
204 GL_RGBA32F, GL_RGBA32UI, GL_RGBA32I, 0);
205 break;
206 case GL_VIEW_CLASS_96_BITS:
207 glTexStorage2D(target, levels, GL_RGB32F, width, height);
208 numFormats = update_valid_arrays(legalFormats, illegalFormats,
209 totalFormats,
210 GL_RGB32F, GL_RGB32UI, GL_RGB32I, 0);
211 break;
212 case GL_VIEW_CLASS_64_BITS:
213 glTexStorage2D(target, levels, GL_RGBA16F, width, height);
214 numFormats = update_valid_arrays(legalFormats, illegalFormats,
215 totalFormats,
216 GL_RGBA16F, GL_RG32F, GL_RGBA16UI,
217 GL_RG32UI, GL_RGBA16I, GL_RG32I, 0);
218 if (!piglit_is_gles() ||
219 piglit_is_extension_supported("GL_EXT_texture_norm16")) {
220 numFormats +=
221 update_valid_arrays(&legalFormats[numFormats],
222 illegalFormats,
223 totalFormats,
224 GL_RGBA16, GL_RGBA16_SNORM, 0);
226 break;
227 case GL_VIEW_CLASS_48_BITS:
228 glTexStorage2D(target, levels, GL_RGB16F, width, height);
229 numFormats = update_valid_arrays(legalFormats, illegalFormats,
230 totalFormats,
231 GL_RGB16F, GL_RGB16UI, GL_RGB16I, 0);
232 if (!piglit_is_gles() ||
233 piglit_is_extension_supported("GL_EXT_texture_norm16")) {
234 numFormats +=
235 update_valid_arrays(&legalFormats[numFormats],
236 illegalFormats,
237 totalFormats,
238 GL_RGB16, GL_RGB16_SNORM, 0);
240 break;
241 case GL_VIEW_CLASS_32_BITS:
242 glTexStorage2D(target, levels, GL_RG16F, width, height);
243 numFormats = update_valid_arrays(legalFormats, illegalFormats,
244 totalFormats,
245 GL_RG16F, GL_R11F_G11F_B10F, GL_R32F,
246 GL_RGB10_A2UI, GL_RGBA8UI, GL_RG16UI,
247 GL_R32UI, GL_RGBA8I, GL_RG16I,
248 GL_R32I, GL_RGB10_A2, GL_RGBA8,
249 GL_RGBA8_SNORM,
250 GL_SRGB8_ALPHA8, GL_RGB9_E5, 0);
251 if (!piglit_is_gles() ||
252 piglit_is_extension_supported("GL_EXT_texture_norm16")) {
253 numFormats +=
254 update_valid_arrays(&legalFormats[numFormats],
255 illegalFormats,
256 totalFormats,
257 GL_RG16, GL_RG16_SNORM, 0);
259 break;
260 case GL_VIEW_CLASS_24_BITS:
261 glTexStorage2D(target, levels, GL_RGB8, width, height);
262 numFormats = update_valid_arrays(legalFormats, illegalFormats,
263 totalFormats,
264 GL_RGB8, GL_RGB8_SNORM, GL_SRGB8,
265 GL_RGB8UI, GL_RGB8I, 0);
266 break;
267 case GL_VIEW_CLASS_16_BITS:
268 glTexStorage2D(target, levels, GL_R16F, width, height);
269 numFormats = update_valid_arrays(legalFormats, illegalFormats,
270 totalFormats,
271 GL_R16F, GL_RG8UI, GL_R16UI, GL_RG8I,
272 GL_R16I, GL_RG8, GL_RG8_SNORM, 0);
273 if (!piglit_is_gles() ||
274 piglit_is_extension_supported("GL_EXT_texture_norm16")) {
275 numFormats +=
276 update_valid_arrays(&legalFormats[numFormats],
277 illegalFormats,
278 totalFormats,
279 GL_R16, GL_R16_SNORM, 0);
281 break;
282 case GL_VIEW_CLASS_8_BITS:
283 glTexStorage2D(target, levels, GL_R8I, width, height);
284 numFormats = update_valid_arrays(legalFormats, illegalFormats,
285 totalFormats,
286 GL_R8UI, GL_R8I, GL_R8, GL_R8_SNORM, 0);
287 break;
288 case VIEW_CLASS_NOT_IN_TABLE:
289 glTexStorage2D(target, levels, GL_RGBA4, width, height);
290 numFormats = update_valid_arrays(legalFormats, illegalFormats,
291 totalFormats,
292 GL_RGBA4, 0);
293 break;
294 default:
295 assert(!"Invalid format_class\n");
296 numFormats = 0;
299 if (!piglit_check_gl_error(GL_NO_ERROR)) {
300 printf("%s Found gl errors prior to testing glTextureView\n",
301 TestName);
302 pass = false;
303 goto err_out;
306 /* ensure TextureView of legal formats gives no gl error */
307 pass = check_format_array(GL_NO_ERROR, numFormats, legalFormats,
308 target, tex, levels, layers) && pass;
310 if (!piglit_khr_no_error) {
311 /* ensure TextureView of illegal formats returns an error */
312 pass = check_format_array(GL_INVALID_OPERATION,
313 totalFormats, illegalFormats,
314 target, tex, levels, layers) && pass;
317 err_out:
318 glDeleteTextures(1, &tex);
320 return pass;
324 enum piglit_result
325 piglit_display(void)
327 return PIGLIT_FAIL;
330 #define X(f, desc) \
331 do { \
332 const bool subtest_pass = (f); \
333 piglit_report_subtest_result(subtest_pass \
334 ? PIGLIT_PASS : PIGLIT_FAIL, \
335 (desc)); \
336 pass = pass && subtest_pass; \
337 } while (0)
339 void
340 piglit_init(int argc, char **argv)
342 bool pass = true;
344 #ifdef PIGLIT_USE_OPENGL
345 piglit_require_extension("GL_ARB_texture_storage");
346 piglit_require_extension("GL_ARB_texture_view");
347 piglit_require_extension("GL_EXT_texture_integer");
348 piglit_require_extension("GL_ARB_texture_float");
349 if (piglit_get_gl_version() < 31)
350 piglit_require_extension("GL_ARB_texture_cube_map");
351 #else
352 piglit_require_extension("GL_OES_texture_view");
353 #endif
355 X(test_format_errors(GL_VIEW_CLASS_128_BITS), "Format 128 bits validity");
356 X(test_format_errors(GL_VIEW_CLASS_96_BITS), "Format 96 bits validity");
357 X(test_format_errors(GL_VIEW_CLASS_64_BITS), "Format 64 bits validity");
358 X(test_format_errors(GL_VIEW_CLASS_48_BITS), "Format 48 bits validity");
359 X(test_format_errors(GL_VIEW_CLASS_32_BITS), "Format 32 bits validity");
360 X(test_format_errors(GL_VIEW_CLASS_24_BITS), "Format 24 bits validity");
361 X(test_format_errors(GL_VIEW_CLASS_16_BITS), "Format 16 bits validity");
362 X(test_format_errors(GL_VIEW_CLASS_8_BITS), "Format 8 bits validity");
363 X(test_format_errors(VIEW_CLASS_NOT_IN_TABLE), "Format misc validity");
364 #undef X
365 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
366 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);