ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_view / lifetime_format.c
blob62a685589e7c722917d758b136db40cf908e6d43
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 * Tests texture views with data format changes. 1D textures only.
28 * Uses multiple simultaneous views with different lifetimes and
29 * check results via glGetTexImage().
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;
40 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
41 config.khr_no_error_support = PIGLIT_NO_ERRORS;
43 PIGLIT_GL_TEST_CONFIG_END
45 /* Texture formats. The format_list variable has these fields: */
46 struct format_desc {
47 GLenum internalfmt;
48 GLenum storagefmt;
49 GLenum imagefmt;
50 GLenum imagetype;
51 GLenum getfmt;
52 GLenum gettype;
53 int red, green, blue, alpha;
56 static const struct format_desc format_list[] = {
57 {GL_RGBA8UI, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE,
58 GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, 8, 8, 8, 8},
59 {GL_RGBA8I, GL_RGBA8I, GL_RGBA, GL_UNSIGNED_BYTE,
60 GL_RGBA_INTEGER, GL_BYTE, 8, 8, 8, 8},
61 {GL_RGB16F, GL_RGB16F, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB,
62 GL_HALF_FLOAT, 16, 16, 16, 0},
63 {GL_RGB16I, GL_RGB16, GL_RGB, GL_UNSIGNED_BYTE,
64 GL_RGB_INTEGER, GL_SHORT, 16, 16, 16, 0},
65 {GL_R16UI, GL_R16, GL_RED, GL_UNSIGNED_BYTE,
66 GL_RED_INTEGER, GL_UNSIGNED_SHORT, 16, 0, 0, 0},
67 {GL_R16F, GL_R16, GL_RED, GL_UNSIGNED_BYTE,
68 GL_RED, GL_HALF_FLOAT, 16, 0, 0, 0},
69 {GL_RGBA16UI, GL_RGBA16, GL_RGBA, GL_UNSIGNED_BYTE,
70 GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, 16, 16, 16, 16},
71 {GL_RGBA16F, GL_RGBA16, GL_RGBA, GL_UNSIGNED_BYTE,
72 GL_RGBA, GL_HALF_FLOAT, 16, 16, 16, 16},
76 static bool
77 buffers_equal(const unsigned char * buf0, const unsigned char *buf1, GLint w)
79 int i;
80 for (i = 0; i < w; i++) {
81 if (buf0[i] != buf1[i]) {
82 printf("mismatched texels at index (%d)\n", i);
83 printf(" Buffer0: %u\n", buf0[i]);
84 printf(" Buffer1: %u\n", buf1[i]);
85 return true;
89 return false;
92 static bool
93 test_format_lifetime(const struct format_desc desc0,
94 const struct format_desc desc1)
96 GLuint tex, viewTex[3];
97 GLint width = 32, w, levels = 6;
98 GLint l;
99 int bytes;
100 unsigned char *buffer0, *buffer1;
101 bool pass = true;
103 glGenTextures(1, &tex);
104 glBindTexture(GL_TEXTURE_1D, tex);
105 glTexStorage1D(GL_TEXTURE_1D, levels, desc0.storagefmt, width);
106 glGenTextures(3, viewTex);
107 glTextureView(viewTex[0], GL_TEXTURE_1D, tex, desc0.internalfmt, 0,
108 levels, 0, 1);
109 glTextureView(viewTex[1], GL_TEXTURE_1D, viewTex[0],
110 desc1.internalfmt, 0, levels, 0, 1);
112 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
114 /* load each mipmap with a different color texture */
115 w = width;
116 bytes = (desc0.red + desc0.green + desc0.blue + desc0.alpha) / 8;
117 for (l = 0; l < levels; l++) {
118 GLubyte *buf = create_solid_image(width, 1, 1, bytes, l);
120 if (buf != NULL) {
121 glTexSubImage1D(GL_TEXTURE_1D, l, 0, w, desc0.imagefmt,
122 desc0.imagetype, buf);
123 free(buf);
124 } else {
125 piglit_report_result(PIGLIT_FAIL);
126 assert(!"create_solid_image() failed\n");
129 if (w > 1)
130 w /= 2;
133 #if 0 /* debug */
134 printf("fmt0=%s, fmt1=%s, strgfmt0=%s, gettype0=%s\n",
135 piglit_get_gl_enum_name(desc0.internalfmt),
136 piglit_get_gl_enum_name(desc1.internalfmt),
137 piglit_get_gl_enum_name(desc0.storagefmt),
138 piglit_get_gl_enum_name(desc0.gettype));
139 printf("bytes=%d, width=%d, viewTex[0]=%d, [1]=%d, [2]=%d\n",bytes,
140 width, viewTex[0], viewTex[1], viewTex[2]);
141 #endif
143 glDeleteTextures(1, &tex);
145 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
147 /* compare view0 all level texels bytes to view1 texels bytes */
148 buffer0 = malloc(width * bytes);
149 buffer1 = malloc(width * bytes);
150 w = width;
151 for (l = 0; l < levels; l++) {
152 glBindTexture(GL_TEXTURE_1D, viewTex[0]);
153 glGetTexImage(GL_TEXTURE_1D, l, desc0.getfmt, desc0.gettype,
154 buffer0);
156 glBindTexture(GL_TEXTURE_1D, viewTex[1]);
157 glGetTexImage(GL_TEXTURE_1D, l, desc1.getfmt, desc1.gettype,
158 buffer1);
159 if (buffers_equal(buffer0, buffer1, w)) {
160 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
161 printf("level %d texel mismatch view0 and view1, width=%d\n",
162 l, w);
163 printf("internal format0 %s, internal format1 %s\n",
164 piglit_get_gl_enum_name(desc0.internalfmt),
165 piglit_get_gl_enum_name(desc1.internalfmt));
166 pass = false;
169 if (w > 1)
170 w /= 2;
173 /* compare view1 base level texels to view2 after view0 and view1
174 deleted */
175 glBindTexture(GL_TEXTURE_1D, viewTex[1]);
176 glGetTexImage(GL_TEXTURE_1D, 0, desc1.getfmt, desc1.gettype, buffer1);
178 glTextureView(viewTex[2], GL_TEXTURE_1D, viewTex[0],
179 desc0.internalfmt, 0, 1, 0, 1);
180 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
181 glDeleteTextures(2, viewTex);
182 glBindTexture(GL_TEXTURE_1D, viewTex[2]);
183 glGetTexImage(GL_TEXTURE_1D, 0, desc0.getfmt, desc0.gettype, buffer0);
185 if (buffers_equal(buffer0, buffer1, width)) {
186 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
187 printf("Mismatched texels view1 and view2\n");
188 printf("internal format0 %s, internal format1 %s\n",
189 piglit_get_gl_enum_name(desc0.internalfmt),
190 piglit_get_gl_enum_name(desc1.internalfmt));
191 pass = false;
194 free(buffer0);
195 free(buffer1);
196 glDeleteTextures(1, &viewTex[2]);
198 return pass;
201 enum piglit_result
202 piglit_display(void)
204 return PIGLIT_FAIL;
207 #define X(f, desc) \
208 do { \
209 const bool subtest_pass = (f); \
210 piglit_report_subtest_result(subtest_pass \
211 ? PIGLIT_PASS : PIGLIT_FAIL, \
212 (desc)); \
213 pass = pass && subtest_pass; \
214 } while (0)
216 void
217 piglit_init(int argc, char **argv)
219 bool pass = true;
221 piglit_require_extension("GL_ARB_texture_storage");
222 piglit_require_extension("GL_ARB_texture_view");
224 X(test_format_lifetime(format_list[4], format_list[5]),
225 "view compare 16 bit formats");
226 X(test_format_lifetime(format_list[0], format_list[1]),
227 "view compare 32 bit formats");
228 X(test_format_lifetime(format_list[2], format_list[3]),
229 "view compare 48 bit formats");
230 X(test_format_lifetime(format_list[6], format_list[7]),
231 "view compare 64 bit formats");
232 #undef X
233 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
234 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);