ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_view / params.c
blobf95dfac99ae6ff76d70fdb11bf98ab27e9d093bf
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 GL_ARB_texture_view and validity of input parameters.
28 * Use both valid and invalid parameters, although mostly invalid
29 * parameters are tested since other tests use valid parameters.
30 * Only the parameters "texture", "origtexture", "minlevel", "numlevels",
31 * "minlayer", "numlayers" are tested for validity as per section 8.18 of
32 * OpenGL 4.3 Core spec.
33 * Tests formats.c and targets.c test the valid and invalid "format" and
34 * "target" input parameters respectively.
38 #include "piglit-util-gl.h"
40 PIGLIT_GL_TEST_CONFIG_BEGIN
42 config.supports_gl_compat_version = 15;
43 config.supports_gl_core_version = 31;
45 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
46 config.khr_no_error_support = PIGLIT_NO_ERRORS;
48 PIGLIT_GL_TEST_CONFIG_END
50 static const char *TestName = "arb_texture_view-params";
52 /**
53 * Test TextureView with various invalid arguments for "texture"
54 * and "origtexture".
55 * Errors as per OpenGL core 4.3 spec section 8.18:
56 * "An INVALID_VALUE error is generated if origtexture is not the
57 * name of a texture."
58 * "An INVALID_OPERATION error is generated if the value of
59 * TEXTURE_IMMUTABLE_FORMAT for origtexture is not TRUE."
60 * "An INVALID_VALUE error is generated if texture is zero."
61 * "An INVALID_OPERATION error is generated if texture is not a valid name
62 * returned by GenTextures, or if texture has already been bound and
63 * given a target."
65 static bool
66 invalid_texture_param(void)
68 bool pass = true;
69 GLuint tex[2];
71 /* invalid original texture param (origtexture) */
72 glGenTextures(2, tex);
73 glBindTexture(GL_TEXTURE_2D, tex[0]);
74 if (!piglit_check_gl_error(GL_NO_ERROR)) {
75 printf("%s Found gl errors prior to testing glTextureView\n",
76 TestName);
77 pass = false;
78 goto err_out;
80 /* origtexture IMMUTABLE_FORMAT == FALSE */
81 glTextureView(tex[1], GL_TEXTURE_2D, tex[0], GL_R8, 0, 1, 0, 1);
82 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
83 glDeleteTextures(1, &tex[1]);
84 glTexStorage2D(GL_TEXTURE_2D,2, GL_RGBA32F, 16, 16);
85 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
87 glGenTextures(1, &tex[1]);
88 /* origtexture is not the name of a texture */
89 glTextureView(tex[1], GL_TEXTURE_2D, 0, GL_RGBA32UI, 0, 1, 0, 1);
90 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
91 glDeleteTextures(1, &tex[1]);
93 /* invalid texture param (value is 0)*/
94 glTextureView(0, GL_TEXTURE_2D, tex[0], GL_RGBA32I, 0, 1, 0 ,1);
95 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
97 glGenTextures(1, &tex[1]);
98 glBindTexture(GL_TEXTURE_2D, tex[1]);
99 glTextureView(tex[1], GL_TEXTURE_2D, tex[0], GL_RGBA32F, 0, 1, 0, 1);
100 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
101 glDeleteTextures(2, tex);
103 /* invalid texture param (value not a valid name from GenTextures)*/
104 glGenTextures(1, tex);
105 glBindTexture(GL_TEXTURE_2D, tex[0]);
106 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RG16F, 16, 16);
107 glTextureView(~tex[0], GL_TEXTURE_2D, tex[0], GL_RGBA8, 0,1,0,1);
108 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
109 glDeleteTextures(1, tex);
111 /* orig texture not immutable */
112 glGenTextures(2, tex);
113 glBindTexture(GL_TEXTURE_2D, tex[0]);
114 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16, 32, 32, 0, GL_RGB,
115 GL_SHORT, NULL);
116 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB16, 16, 16, 0, GL_RGB,
117 GL_SHORT, NULL);
118 glTextureView(tex[1], GL_TEXTURE_2D, tex[0], GL_RGBA32F, 0,1,0,1);
119 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
121 err_out:
122 glDeleteTextures(2, tex);
123 return pass;
127 * Test TextureView with invalid arguments for "minlayer"
128 * and "numlayers".
129 * Errors as per OpenGL core 4.3 spec section 8.18:
130 * "An INVALID_VALUE error is generated if minlevel or minlayer are larger
131 * than the greatest level or layer, respectively, of origtexture."
132 * "An INVALID_VALUE error is generated if target is TEXTURE_1D,
133 * TEXTURE_2D, TEXTURE_3D, TEXTURE_RECTANGLE, or TEXTURE_2D_-
134 * MULTISAMPLE and numlayers does not equal 1."
136 static bool
137 invalid_layer_param(GLenum target)
139 bool pass = true;
140 GLenum tar;
141 GLuint tex[2];
143 /* invalid minlayer param */
144 glGenTextures(2, tex);
145 glBindTexture(target, tex[0]);
146 if (target == GL_TEXTURE_1D_ARRAY) {
147 tar = GL_TEXTURE_1D;
148 glTexStorage2D(target, 7, GL_RGB16I, 64, 4);
149 } else if (target == GL_TEXTURE_2D_ARRAY) {
150 tar = GL_TEXTURE_2D;
151 glTexStorage3D(target, 7, GL_RGB16F, 64, 64, 4);
152 } else {
153 printf("%s: called with invalid target\n", TestName);
154 return false;
156 glTextureView(tex[1], target, tex[0], GL_RGB16UI, 0, 7, 4, 2);
157 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
158 glDeleteTextures(1, &tex[1]);
160 /* invalid numlayer param */
161 glGenTextures(1, &tex[1]);
162 glTextureView(tex[1], tar, tex[0], GL_RGB16I, 1, 5, 0, 4);
163 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
165 glDeleteTextures(2, tex);
166 return pass;
170 * Test TextureView with invalid argument for "minlevel"
171 * Errors as per OpenGL core 4.3 spec section 8.18:
172 * "An INVALID_VALUE error is generated if minlevel or minlayer are larger
173 * than the greatest level or layer, respectively, of origtexture."
175 static bool
176 invalid_level_param(void)
178 bool pass = true;
179 GLuint tex[2];
181 /* invalid minlevel param */
182 glGenTextures(2, tex);
183 glBindTexture(GL_TEXTURE_1D, tex[0]);
184 glTexStorage1D(GL_TEXTURE_1D, 6, GL_RGB16F, 32);
185 glTextureView(tex[1], GL_TEXTURE_1D, tex[0], GL_RGB16UI, 7, 5, 1, 1);
186 if (!piglit_check_gl_error(GL_INVALID_VALUE)) {
187 pass = false;
189 glDeleteTextures(2, tex);
190 return pass;
194 * Test TextureView with "minlevel" range over legal values and
195 * with "numlevels" clamped correctly.
196 * As per OpenGL 4.3 Core spec section 8.18:
197 * "TEXTURE_VIEW_MIN_LEVEL is set to minlevel plus the value of
198 * TEXTURE_VIEW_MIN_LEVEL for origtexture."
200 * "The minlevel and minlayer parameters are relative to the view
201 * of origtexture. If numlayers or numlevels extend beyond origtexture,
202 * they are clamped to the maximum extent of the original texture."
204 static bool
205 levels_clamping(void)
207 GLuint tex[2];
208 GLint level, i;
209 bool pass = true;
210 const GLuint numLevels = 8;
212 glGenTextures(1, tex);
213 glBindTexture(GL_TEXTURE_1D, tex[0]);
214 glTexStorage1D(GL_TEXTURE_1D, numLevels-1, GL_RG16, 64);
215 for (i = 0; i < numLevels - 1; i++) {
216 glGenTextures(1, &tex[1]);
217 glTextureView(tex[1], GL_TEXTURE_1D_ARRAY, tex[0], GL_RG16I,
218 i, numLevels-i, 0, 3);
219 if (!piglit_check_gl_error(GL_NO_ERROR)) {
220 pass = false;
221 break;
223 glBindTexture(GL_TEXTURE_1D_ARRAY, tex[1]);
224 glGetTexParameteriv(GL_TEXTURE_1D_ARRAY,
225 GL_TEXTURE_VIEW_MIN_LEVEL, &level);
226 if (level != i) {
227 printf("failed at min_level=%d, queried view_min_level=%d\n",
228 i, level);
229 pass = false;
230 break;
232 glGetTexParameteriv(GL_TEXTURE_1D_ARRAY,
233 GL_TEXTURE_VIEW_NUM_LEVELS, &level);
234 if (level != (numLevels - 1 -i)) {
235 printf("failed at min_level=%d, queried view_num_level=%d\n",
236 i, level);
237 pass = false;
238 break;
240 glDeleteTextures(1, &tex[1]);
241 glBindTexture(GL_TEXTURE_1D, tex[0]);
244 glDeleteTextures(2, tex);
245 return pass;
249 * Test TextureView with "minlayer" range over legal values and
250 * with "numlayers" clamped correctly.
251 * As per OpenGL 4.3 Core spec section 8.18:
252 * "TEXTURE_VIEW_MIN_LAYER is set to minlayer plus the value of
253 * TEXTURE_VIEW_MIN_LAYER for origtexture."
255 * "The minlevel and minlayer parameters are relative to the view
256 * of origtexture. If numlayers or numlevels extend beyond origtexture,
257 * they are clamped to the maximum extent of the original texture."
259 static bool
260 layers_clamping(void)
262 bool pass = true;
263 GLuint tex[2];
264 GLint layer, i;
266 glGenTextures(1, tex);
267 glBindTexture(GL_TEXTURE_1D_ARRAY, tex[0]);
268 glTexStorage2D(GL_TEXTURE_1D_ARRAY, 5, GL_RGBA16F, 16, 4);
269 for (i = 0; i < 4; i++) {
270 glGenTextures(1, &tex[1]);
271 glTextureView(tex[1], GL_TEXTURE_1D_ARRAY, tex[0], GL_RGBA16I,
272 0, 7, i, 5-i);
273 if (!piglit_check_gl_error(GL_NO_ERROR)) {
274 pass = false;
275 break;
277 glBindTexture(GL_TEXTURE_1D_ARRAY, tex[1]);
278 glGetTexParameteriv(GL_TEXTURE_1D_ARRAY,
279 GL_TEXTURE_VIEW_MIN_LAYER, &layer);
280 if (layer != i) {
281 printf("failed at min_layer=%d, queried view_min_layer=%d\n",
282 i, layer);
283 pass = false;
284 break;
286 glGetTexParameteriv(GL_TEXTURE_1D_ARRAY,
287 GL_TEXTURE_VIEW_NUM_LAYERS, &layer);
288 if (layer != (4-i)) {
289 printf("failed at min_layer=%d, queried view_num_layer=%d\n",
290 i, layer);
291 pass = false;
292 break;
294 glDeleteTextures(1, &tex[1]);
295 glBindTexture(GL_TEXTURE_1D_ARRAY, tex[0]);
298 glDeleteTextures(2, tex);
299 return pass;
303 enum piglit_result
304 piglit_display(void)
306 return PIGLIT_FAIL;
309 #define X(f, desc) \
310 do { \
311 const bool subtest_pass = (f); \
312 piglit_report_subtest_result(subtest_pass \
313 ? PIGLIT_PASS : PIGLIT_FAIL, \
314 (desc)); \
315 pass = pass && subtest_pass; \
316 } while (0)
319 void
320 piglit_init(int argc, char **argv)
322 bool pass = true;
324 piglit_require_extension("GL_ARB_texture_storage");
325 piglit_require_extension("GL_ARB_texture_view");
326 piglit_require_extension("GL_EXT_texture_integer");
327 piglit_require_extension("GL_ARB_texture_float");
328 piglit_require_extension("GL_EXT_texture_array");
330 if (!piglit_khr_no_error) {
331 X(invalid_texture_param(), "Invalid texture or origtexture");
332 X(invalid_layer_param(GL_TEXTURE_1D_ARRAY), "Invalid layer param 1D");
333 X(invalid_layer_param(GL_TEXTURE_2D_ARRAY), "Invalid layer param 2D");
334 X(invalid_level_param(), "Invalid level param");
335 } else {
336 X(levels_clamping(), "Minlevel range and numlevel clamp");
337 X(layers_clamping(), "Minlayer range and numlayer clamp");
340 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
341 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);