ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_clear_buffer_object / formats.c
blob4a053eb2437cfc4373890948e9944cb89a0f1a11
1 /*
2 * Copyright © 2014 Intel Corporation
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.
24 /**
25 * \file formats.c
27 * Test clearing the entire buffer with multiple internal formats. Pass the data
28 * to clear the buffer with in a format so that the GL doesn't have to do any
29 * format conversion.
32 #include "piglit-util-gl.h"
33 #include "common.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 15;
38 config.supports_gl_core_version = 31;
39 config.khr_no_error_support = PIGLIT_NO_ERRORS;
41 PIGLIT_GL_TEST_CONFIG_END
44 static const struct {
45 GLenum internal_format;
46 GLenum format;
47 GLenum type;
49 int size;
50 bool core_profile;
51 const char *ext[3];
52 } formats[] = {
53 /* internal_format format type size core extensions */
54 {GL_ALPHA8, GL_ALPHA, GL_UNSIGNED_BYTE, 1, false, {NULL, NULL, NULL}},
55 {GL_ALPHA16, GL_ALPHA, GL_UNSIGNED_SHORT, 2, false, {NULL, NULL, NULL}},
56 {GL_LUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1, false, {NULL, NULL, NULL}},
57 {GL_LUMINANCE16, GL_LUMINANCE, GL_UNSIGNED_SHORT, 2, false, {NULL, NULL, NULL}},
58 {GL_LUMINANCE8_ALPHA8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 2, false, {NULL, NULL, NULL}},
59 {GL_LUMINANCE16_ALPHA16, GL_LUMINANCE_ALPHA, GL_UNSIGNED_SHORT, 4, false, {NULL, NULL, NULL}},
60 {GL_INTENSITY8, GL_RED, GL_UNSIGNED_BYTE, 1, false, {NULL, NULL, NULL}},
61 {GL_INTENSITY16, GL_RED, GL_UNSIGNED_SHORT, 2, false, {NULL, NULL, NULL}},
62 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, 4, true, {NULL, NULL, NULL}},
63 {GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT, 8, true, {NULL, NULL, NULL}},
64 /* texture_float */
65 {GL_ALPHA32F_ARB, GL_ALPHA, GL_FLOAT, 4, false, {NULL, "GL_ARB_texture_float", NULL}},
66 {GL_LUMINANCE32F_ARB, GL_LUMINANCE, GL_FLOAT, 4, false, {NULL, "GL_ARB_texture_float", NULL}},
67 {GL_LUMINANCE_ALPHA32F_ARB, GL_LUMINANCE_ALPHA, GL_FLOAT, 8, false, {NULL, "GL_ARB_texture_float", NULL}},
68 {GL_INTENSITY32F_ARB, GL_RED, GL_FLOAT, 4, false, {NULL, "GL_ARB_texture_float", NULL}},
69 {GL_RGB32F, GL_RGB, GL_FLOAT, 12, true, {NULL, "GL_ARB_texture_float", "GL_ARB_texture_buffer_object_rgb32"}},
70 {GL_RGBA32F_ARB, GL_RGBA, GL_FLOAT, 16, true, {NULL, "GL_ARB_texture_float", NULL}},
71 /* texture_half_float */
72 {GL_ALPHA16F_ARB, GL_ALPHA, GL_HALF_FLOAT, 2, false, {NULL, "GL_ARB_texture_float", "GL_ARB_half_float_pixel"}},
73 {GL_LUMINANCE16F_ARB, GL_LUMINANCE, GL_HALF_FLOAT, 2, false, {NULL, "GL_ARB_texture_float", "GL_ARB_half_float_pixel"}},
74 {GL_LUMINANCE_ALPHA16F_ARB, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, 4, false, {NULL, "GL_ARB_texture_float", "GL_ARB_half_float_pixel"}},
75 {GL_INTENSITY16F_ARB, GL_RED, GL_HALF_FLOAT, 2, false, {NULL, "GL_ARB_texture_float", "GL_ARB_half_float_pixel"}},
76 {GL_RGBA16F_ARB, GL_RGBA, GL_HALF_FLOAT, 8, true, {NULL, "GL_ARB_texture_float", "GL_ARB_half_float_pixel"}},
77 /* texture_integer */
78 {GL_ALPHA8I_EXT, GL_ALPHA_INTEGER, GL_BYTE, 1, false, {NULL, "GL_EXT_texture_integer", NULL}},
79 {GL_ALPHA16I_EXT, GL_ALPHA_INTEGER, GL_SHORT, 2, false, {NULL, "GL_EXT_texture_integer", NULL}},
80 {GL_ALPHA32I_EXT, GL_ALPHA_INTEGER, GL_INT, 4, false, {NULL, "GL_EXT_texture_integer", NULL}},
81 {GL_ALPHA8UI_EXT, GL_ALPHA_INTEGER, GL_UNSIGNED_BYTE, 1, false, {NULL, "GL_EXT_texture_integer", NULL}},
82 {GL_ALPHA16UI_EXT, GL_ALPHA_INTEGER, GL_UNSIGNED_SHORT, 2, false, {NULL, "GL_EXT_texture_integer", NULL}},
83 {GL_ALPHA32UI_EXT, GL_ALPHA_INTEGER, GL_UNSIGNED_INT, 4, false, {NULL, "GL_EXT_texture_integer", NULL}},
85 {GL_LUMINANCE8I_EXT, GL_LUMINANCE_INTEGER_EXT, GL_BYTE, 1, false, {NULL, "GL_EXT_texture_integer", NULL}},
86 {GL_LUMINANCE16I_EXT, GL_LUMINANCE_INTEGER_EXT, GL_SHORT, 2, false, {NULL, "GL_EXT_texture_integer", NULL}},
87 {GL_LUMINANCE32I_EXT, GL_LUMINANCE_INTEGER_EXT, GL_INT, 4, false, {NULL, "GL_EXT_texture_integer", NULL}},
88 {GL_LUMINANCE8UI_EXT, GL_LUMINANCE_INTEGER_EXT, GL_UNSIGNED_BYTE, 1, false, {NULL, "GL_EXT_texture_integer", NULL}},
89 {GL_LUMINANCE16UI_EXT, GL_LUMINANCE_INTEGER_EXT, GL_UNSIGNED_SHORT, 2, false, {NULL, "GL_EXT_texture_integer", NULL}},
90 {GL_LUMINANCE32UI_EXT, GL_LUMINANCE_INTEGER_EXT, GL_UNSIGNED_INT, 4, false, {NULL, "GL_EXT_texture_integer", NULL}},
92 {GL_LUMINANCE_ALPHA8I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_BYTE, 2, false, {NULL, "GL_EXT_texture_integer", NULL}},
93 {GL_LUMINANCE_ALPHA16I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_SHORT, 4, false, {NULL, "GL_EXT_texture_integer", NULL}},
94 {GL_LUMINANCE_ALPHA32I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_INT, 8, false, {NULL, "GL_EXT_texture_integer", NULL}},
95 {GL_LUMINANCE_ALPHA8UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_UNSIGNED_BYTE, 2, false, {NULL, "GL_EXT_texture_integer", NULL}},
96 {GL_LUMINANCE_ALPHA16UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_UNSIGNED_SHORT, 4, false, {NULL, "GL_EXT_texture_integer", NULL}},
97 {GL_LUMINANCE_ALPHA32UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_UNSIGNED_INT, 8, false, {NULL, "GL_EXT_texture_integer", NULL}},
99 {GL_INTENSITY8I_EXT, GL_RED_INTEGER, GL_BYTE, 1, false, {NULL, "GL_EXT_texture_integer", NULL}},
100 {GL_INTENSITY16I_EXT, GL_RED_INTEGER, GL_SHORT , 2, false, {NULL, "GL_EXT_texture_integer", NULL}},
101 {GL_INTENSITY32I_EXT, GL_RED_INTEGER, GL_INT, 4, false, {NULL, "GL_EXT_texture_integer", NULL}},
102 {GL_INTENSITY8UI_EXT, GL_RED_INTEGER, GL_UNSIGNED_BYTE, 1, false, {NULL, "GL_EXT_texture_integer", NULL}},
103 {GL_INTENSITY16UI_EXT, GL_RED_INTEGER, GL_UNSIGNED_SHORT, 2, false, {NULL, "GL_EXT_texture_integer", NULL}},
104 {GL_INTENSITY32UI_EXT, GL_RED_INTEGER, GL_UNSIGNED_INT, 4, false, {NULL, "GL_EXT_texture_integer", NULL}},
106 {GL_RGB32I, GL_RGB_INTEGER, GL_INT, 12, true, {NULL, "GL_EXT_texture_integer", "GL_ARB_texture_buffer_object_rgb32"}},
107 {GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT, 12, true, {NULL, "GL_EXT_texture_integer", "GL_ARB_texture_buffer_object_rgb32"}},
109 {GL_RGBA8I_EXT, GL_RGBA_INTEGER, GL_BYTE, 4, true, {NULL, "GL_EXT_texture_integer", NULL}},
110 {GL_RGBA16I_EXT, GL_RGBA_INTEGER, GL_SHORT, 8, true, {NULL, "GL_EXT_texture_integer", NULL}},
111 {GL_RGBA32I_EXT, GL_RGBA_INTEGER, GL_INT, 16, true, {NULL, "GL_EXT_texture_integer", NULL}},
112 {GL_RGBA8UI_EXT, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, 4, true, {NULL, "GL_EXT_texture_integer", NULL}},
113 {GL_RGBA16UI_EXT, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, 8, true, {NULL, "GL_EXT_texture_integer", NULL}},
114 {GL_RGBA32UI_EXT, GL_RGBA_INTEGER, GL_UNSIGNED_INT, 16, true, {NULL, "GL_EXT_texture_integer", NULL}},
115 /* texture_rg */
116 {GL_R8, GL_RED, GL_UNSIGNED_BYTE, 1, true, {"GL_ARB_texture_rg", NULL, NULL}},
117 {GL_R16, GL_RED, GL_UNSIGNED_SHORT, 2, true, {"GL_ARB_texture_rg", NULL, NULL}},
118 {GL_R16F, GL_RED, GL_HALF_FLOAT, 2, true, {"GL_ARB_texture_rg", "GL_ARB_texture_float", "GL_ARB_half_float_pixel"}},
119 {GL_R32F, GL_RED, GL_FLOAT, 4, true, {"GL_ARB_texture_rg", "GL_ARB_texture_float", NULL}},
120 {GL_R8I, GL_RED_INTEGER, GL_BYTE, 1, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
121 {GL_R16I, GL_RED_INTEGER, GL_SHORT, 2, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
122 {GL_R32I, GL_RED_INTEGER, GL_INT, 4, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
123 {GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE, 1, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
124 {GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT, 2, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
125 {GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, 4, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
127 {GL_RG8, GL_RG, GL_UNSIGNED_BYTE, 2, true, {"GL_ARB_texture_rg", NULL, NULL}},
128 {GL_RG16, GL_RG, GL_UNSIGNED_SHORT, 4, true, {"GL_ARB_texture_rg", NULL, NULL}},
129 {GL_RG16F, GL_RG, GL_HALF_FLOAT, 4, true, {"GL_ARB_texture_rg", "GL_ARB_texture_float", "GL_ARB_half_float_pixel"}},
130 {GL_RG32F, GL_RG, GL_FLOAT, 8, true, {"GL_ARB_texture_rg", "GL_ARB_texture_float", NULL}},
131 {GL_RG8I, GL_RG_INTEGER, GL_BYTE, 2, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
132 {GL_RG16I, GL_RG_INTEGER, GL_SHORT, 4, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
133 {GL_RG32I, GL_RG_INTEGER, GL_INT, 8, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
134 {GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE, 2, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
135 {GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT, 4, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
136 {GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT, 8, true, {"GL_ARB_texture_rg", "GL_EXT_texture_integer", NULL}},
140 static bool
141 test_format(const int i)
143 static const char *const clear_data = "\x01\x02\x02\x03"
144 "\x04\x05\x06\x07"
145 "\x08\x09\x10\x11"
146 "\x12\x13\x14\x15";
148 static const char *const data_init = "\xff\xff\xff\xff"
149 "\xff\xff\xff\xff"
150 "\x00\x00\x00\x00"
151 "\x00\x00\x00\x00"
152 "\x55\x55\x55\x55"
153 "\x55\x55\x55\x55"
154 "\xaa\xaa\xaa\xaa"
155 "\xaa\xaa\xaa\xaa"
156 "\xff\x00\xff\x00"
157 "\xff\x00\xff\x00"
158 "\x00\xff\x00\xff"
159 "\x00\xff\x00\xff"
160 "\x91\xcc\x45\x36"
161 "\xd3\xe4\xe3\x5b"
162 "\x79\x1e\x21\x39"
163 "\xa8\xfa\x69\x6a";
164 int j;
167 if (piglit_is_core_profile && !formats[i].core_profile)
168 return true;
170 for (j = 0; j < 3; ++j)
171 if (formats[i].ext[j])
172 if (!piglit_is_extension_supported(
173 formats[i].ext[j]))
174 return true;
176 printf("Testing %s... ",
177 piglit_get_gl_enum_name(formats[i].internal_format));
178 fill_array_buffer(64, data_init);
179 glClearBufferData(GL_ARRAY_BUFFER, formats[i].internal_format,
180 formats[i].format, formats[i].type, clear_data);
182 if (!piglit_check_gl_error(GL_NO_ERROR) ||
183 !check_array_buffer_data(formats[i].size, clear_data)) {
184 printf("Failed!\n");
185 return false;
187 printf("Passed.\n");
188 return true;
192 void
193 piglit_init(int argc, char **argv)
195 bool pass = true;
196 int i;
197 const int buffer_size = 3<<20;
198 unsigned int buffer;
200 piglit_require_extension("GL_ARB_clear_buffer_object");
202 glGenBuffers(1, &buffer);
203 glBindBuffer(GL_ARRAY_BUFFER, buffer);
204 glBufferData(GL_ARRAY_BUFFER, buffer_size, NULL, GL_STREAM_READ);
206 for (i = 0; i < ARRAY_SIZE(formats); ++i)
207 pass = test_format(i) && pass;
209 glBindBuffer(GL_ARRAY_BUFFER, 0);
210 glDeleteBuffers(1, &buffer);
212 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
214 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
218 enum piglit_result
219 piglit_display(void)
221 return PIGLIT_PASS;