ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_view / queries.c
blob026d97ece412e47012e06d559d3ab68636a51d6f
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 queries of new state added by this extension
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_compat_version = 15;
36 config.supports_gl_core_version = 31;
37 config.supports_gl_es_version = 31;
39 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
40 config.khr_no_error_support = PIGLIT_NO_ERRORS;
42 PIGLIT_GL_TEST_CONFIG_END
44 /**
45 * make sure default intial state is correct for textureView
46 * In OpenGL Core 4.3 spec see table 23.15 for default values.
48 static bool
49 query_default_state(void)
51 bool pass = true;
52 GLuint tex[2];
53 GLint param;
55 glGenTextures(2,tex);
56 glBindTexture(GL_TEXTURE_CUBE_MAP, tex[0]);
57 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 7, GL_R32F, 64, 64);
58 glTextureView(tex[1], GL_TEXTURE_CUBE_MAP, tex[0], GL_RG16I, 2, 4, 0, 6);
59 glBindTexture(GL_TEXTURE_CUBE_MAP, tex[1]);
60 glDeleteTextures(1, &tex[1]);
61 /* tex[1] which is bound to GL_TEXTURE_CUBE_MAP is deleted */
63 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_MIN_LEVEL,
64 &param);
65 if (param != 0) {
66 printf("bad default of min_level, expected 0 got %u\n", param);
67 pass = false;
69 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_NUM_LEVELS,
70 &param);
71 if (param != 0) {
72 printf("bad default of num_levels, expected 0 got %u\n", param);
73 pass = false;
75 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_MIN_LAYER,
76 &param);
77 if (param != 0) {
78 printf("bad default of min_layer, expected 0 got %u\n", param);
79 pass = false;
81 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_NUM_LAYERS,
82 &param);
83 if (param != 0) {
84 printf("bad default of num_layers, expected 0 got %u\n", param);
85 pass = false;
87 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_IMMUTABLE_FORMAT,
88 &param);
89 if (param != 0) {
90 printf("bad default of immutable_format, expected 0 got %u\n",
91 param);
92 pass = false;
94 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_IMMUTABLE_LEVELS,
95 &param);
96 if (param != 0) {
97 printf("bad default of immutable_levels, expected 0 got %u\n",
98 param);
99 pass = false;
101 glDeleteTextures(1, tex);
103 return pass;
107 * This tests min_levels, num_levels, immutable_levels and imutable_format.
108 * note: see params test for more min/num level query testing
110 * In OpenGL Core 4.3 spec see section 8.18:
111 * "The minlevel and minlayer parameters are relative to the view of
112 * origtexture. If numlayers or numlevels extend beyond origtexture, they
113 * are clamped to the maximum extent of the original texture.
114 * If the command is successful, the texture parameters in <texture> are
115 * updated as follows:
116 * - TEXTURE_IMMUTABLE_FORMAT is set to TRUE.
118 * - TEXTURE_IMMUTABLE_LEVELS is set to the value of
119 * TEXTURE_IMMUTABLE_LEVELS from the original texture.
121 * - TEXTURE_VIEW_MIN_LEVEL is set to <minlevel> plus the value of
122 * TEXTURE_VIEW_MIN_LEVEL from the original texture.
124 * - TEXTURE_VIEW_NUM_LEVELS is set to the lesser of numlevels and the
125 * value of TEXTURE_VIEW_NUM_LEVELS for origtexture minus minlevels."
126 * In the ARB_texture_view extension registry spec see this for chained views:
127 * "(3) Is it possible to create a texture view using an original texture
128 * which is itself a view? And if so, how are the level/layer values
129 * interpreted?
131 * RESOLVED: It is legal. For example, let's say texture 1 is a 2D_ARRAY
132 * texture with 200 layers. It will have TEXTURE_VIEW_MIN_LAYER=0,
133 * TEXTURE_VIEW_NUM_LAYERS=200. Then we create texture 2 from texture 1 using
134 * <minlayer>=100, <numlayers>=100. It will have TEXTURE_VIEW_MIN_LAYER=100,
135 * TEXTURE_VIEW_NUM_LAYERS=100. Then we create texture 3 from texture 2 using
136 * <minlayer>=50, <numlayers>=50. It will have TEXTURE_VIEW_MIN_LAYER=150,
137 * TEXTURE_VIEW_NUM_LAYERS=50."
139 static bool
140 query_levels_test(void)
142 GLuint tex[2], viewtex, l;
143 GLint param;
144 bool pass = true;
146 glGenTextures(2, tex);
148 /* test the view causes immutable_format to be set */
149 glBindTexture(GL_TEXTURE_2D, tex[0]);
150 glTexStorage2D(GL_TEXTURE_2D, 6, GL_R32F, 16, 32);
151 glTextureView(tex[1], GL_TEXTURE_2D, tex[0], GL_RG16F, 0, 1, 0, 1);
152 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
154 glBindTexture(GL_TEXTURE_2D, tex[1]);
155 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_IMMUTABLE_FORMAT, &param);
156 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
158 if (param != GL_TRUE) {
159 printf("bad query of immutable_format\n");
160 pass = false;
162 glDeleteTextures(2,tex);
165 * test min_levels are additive using chained views
166 * test immutable_levels get set correctly based on origtexture
167 * test num_levels are correct for chained views
169 glGenTextures(2,tex);
170 glBindTexture(GL_TEXTURE_CUBE_MAP, tex[0]);
171 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 7, GL_R32F, 64, 64);
172 glTextureView(tex[1], GL_TEXTURE_CUBE_MAP,tex[0], GL_RG16I, 2, 4, 0, 6);
173 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
175 glBindTexture(GL_TEXTURE_CUBE_MAP, tex[1]);
176 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_IMMUTABLE_LEVELS,
177 &param);
178 if (param != 7) {
179 printf("bad query of immutable_levels, expected 7 got %u\n",
180 param);
181 pass = false;
183 for (l = 0; l < 4; l++) {
184 glGenTextures(1, &viewtex);
185 glTextureView(viewtex, GL_TEXTURE_CUBE_MAP, tex[1], GL_RG16F,
186 l, 4, 0, 6);
187 glBindTexture(GL_TEXTURE_CUBE_MAP, viewtex);
188 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP,
189 GL_TEXTURE_VIEW_MIN_LEVEL, &param);
190 if (param != (2 + l)) {
191 glDeleteTextures(1, &viewtex);
192 printf("bad query of view_min_level expected %u got %u\n",
193 2+l, param);
194 pass = false;
195 break;
197 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP,
198 GL_TEXTURE_IMMUTABLE_LEVELS, &param);
199 if (param != 7) {
200 glDeleteTextures(1, &viewtex);
201 printf("query of immutable_levels not tracking orig, expected 7 got %u\n",
202 param);
203 pass = false;
204 break;
206 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP,
207 GL_TEXTURE_VIEW_NUM_LEVELS, &param);
208 if (param != (4 - l)) {
209 glDeleteTextures(1, &viewtex);
210 printf("bad query of view_num_levels expected %u got %u\n",
211 4 - l, param);
212 pass = false;
213 break;
215 glDeleteTextures(1, &viewtex);
217 glDeleteTextures(2, tex);
219 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
221 return pass;
227 * This tests correct queries of min_layers, num_layers.
228 * note: see params test for more min/num layers query testing
230 * In OpenGL Core 4.3 spec see section 8.18:
231 * "The minlevel and minlayer parameters are relative to the view of
232 * origtexture. If numlayers or numlevels extend beyond origtexture, they
233 * are clamped to the maximum extent of the original texture.
234 * If the command is successful, the texture parameters in <texture> are
235 * updated as follows:
236 * - TEXTURE_VIEW_MIN_LAYER is set to <minlayer> plus the value of
237 * TEXTURE_VIEW_MIN_LAYER from the original texture.
239 * - TEXTURE_VIEW_NUM_LAYERS is set to the lesser of numlayerss and the
240 * value of TEXTURE_VIEW_NUM_LAYERS for origtexture minus minlayers."
243 static bool
244 query_layers_state(void)
246 bool pass = true;
247 GLuint tex[2], viewtex, l;
248 GLint param;
250 glGenTextures(2, tex);
251 glBindTexture(GL_TEXTURE_2D_ARRAY, tex[0]);
252 glTexStorage3D(GL_TEXTURE_2D_ARRAY, 7, GL_RG16F, 64, 64, 10);
253 glTextureView(tex[1], GL_TEXTURE_2D_ARRAY,tex[0], GL_RG16I, 0, 3, 1, 8);
254 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
255 for (l = 0; l < 4; l++) {
256 glGenTextures(1, &viewtex);
257 glTextureView(viewtex, GL_TEXTURE_2D_ARRAY, tex[1], GL_RG16UI,
258 0, 4, l, 9);
259 glBindTexture(GL_TEXTURE_2D_ARRAY, viewtex);
261 /* test min_layers are additive using chained views */
262 glGetTexParameteriv(GL_TEXTURE_2D_ARRAY,
263 GL_TEXTURE_VIEW_MIN_LAYER, &param);
265 if (param != (1 + l)) {
266 glDeleteTextures(1, &viewtex);
267 printf("bad query of view_min_layer expected %u got %u\n",
268 1+l, param);
269 pass = false;
270 break;
272 /* test num_layers are correct for chained views */
273 glGetTexParameteriv(GL_TEXTURE_2D_ARRAY,
274 GL_TEXTURE_VIEW_NUM_LAYERS, &param);
275 if (param != (8 - l)) {
276 glDeleteTextures(1, &viewtex);
277 printf("bad query of view_num_layers expected %u got %u\n",
278 8 - l, param);
279 pass = false;
280 break;
283 glDeleteTextures(1, &viewtex);
285 glDeleteTextures(2, tex);
287 return pass;
290 enum piglit_result
291 piglit_display(void)
293 return PIGLIT_FAIL;
296 void
297 piglit_init(int argc, char **argv)
299 bool pass = true;
300 #ifdef PIGLIT_USE_OPENGL
301 piglit_require_extension("GL_ARB_texture_storage");
302 piglit_require_extension("GL_ARB_texture_view");
303 #else
304 piglit_require_extension("GL_OES_texture_view");
305 #endif
307 pass = query_levels_test();
308 pass = query_layers_state() && pass;
309 pass = query_default_state() && pass;
311 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
312 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);