summaryrefslogtreecommitdiff
path: root/tests/spec/arb_texture_view/queries.c
blob: b603791a1de024e4bdb376eb282566ca0567ada4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*
 * Copyright © 2013 LunarG, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Author: Jon Ashburn <jon@lunarg.com>
 */

/**
 * Tests GL_ARB_texture_view  queries of new state added by this extension
 *
 */

#include "piglit-util-gl.h"

PIGLIT_GL_TEST_CONFIG_BEGIN

	config.supports_gl_compat_version = 15;
	config.supports_gl_core_version = 31;
	config.supports_gl_es_version = 31;

	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
	config.khr_no_error_support = PIGLIT_NO_ERRORS;

PIGLIT_GL_TEST_CONFIG_END

/**
 * make sure default initial state is correct for textureView
 * In OpenGL Core 4.3 spec see  table 23.15 for default values.
 */
static bool
query_default_state(void)
{
	bool pass = true;
	GLuint tex[2];
	GLint param;

	glGenTextures(2,tex);
	glBindTexture(GL_TEXTURE_CUBE_MAP, tex[0]);
	glTexStorage2D(GL_TEXTURE_CUBE_MAP, 7, GL_R32F, 64, 64);
	glTextureView(tex[1], GL_TEXTURE_CUBE_MAP, tex[0], GL_RG16I, 2, 4, 0, 6);
	glBindTexture(GL_TEXTURE_CUBE_MAP, tex[1]);
	glDeleteTextures(1, &tex[1]);
	/* tex[1] which is bound to GL_TEXTURE_CUBE_MAP is deleted */

	glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_MIN_LEVEL,
							&param);
	if (param != 0) {
		printf("bad default of min_level, expected 0 got %u\n", param);
		pass = false;
	}
	glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_NUM_LEVELS,
							&param);
	if (param != 0) {
		printf("bad default of num_levels, expected 0 got %u\n", param);
		pass = false;
	}
	glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_MIN_LAYER,
							&param);
	if (param != 0) {
		printf("bad default of min_layer, expected 0 got %u\n", param);
		pass = false;
	}
	glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_VIEW_NUM_LAYERS,
							&param);
	if (param != 0) {
		printf("bad default of num_layers, expected 0 got %u\n", param);
		pass = false;
	}
	glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_IMMUTABLE_FORMAT,
							&param);
	if (param != 0) {
		printf("bad default of immutable_format, expected 0 got %u\n",
		       param);
		pass = false;
	}
	glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_IMMUTABLE_LEVELS,
							&param);
	if (param != 0) {
		printf("bad default of immutable_levels, expected 0 got %u\n",
		       param);
		pass = false;
	}
	glDeleteTextures(1, tex);

	return pass;
}

/**
 * This tests min_levels, num_levels, immutable_levels  and imutable_format.
 * note: see params test for more min/num  level query testing
 *
 * In OpenGL Core 4.3 spec see section 8.18:
 *    "The minlevel and minlayer parameters are relative to the view of
 *    origtexture. If numlayers or numlevels extend beyond origtexture, they
 *    are clamped to the maximum extent of the original texture.
 *    If the command is successful, the texture parameters in <texture> are
 *     updated as follows:
 *       - TEXTURE_IMMUTABLE_FORMAT is set to TRUE.
 *
 *       - TEXTURE_IMMUTABLE_LEVELS is set to the value of
 *         TEXTURE_IMMUTABLE_LEVELS from the original texture.
 *
 *       - TEXTURE_VIEW_MIN_LEVEL is set to <minlevel> plus the value of
 *         TEXTURE_VIEW_MIN_LEVEL from the original texture.
 *
 *       - TEXTURE_VIEW_NUM_LEVELS is set to the lesser of numlevels and the
 *         value of TEXTURE_VIEW_NUM_LEVELS for origtexture minus minlevels."
 * In the ARB_texture_view extension registry spec see this for chained views:
 *   "(3) Is it possible to create a texture view using an original texture
 *   which is itself a view? And if so, how are the level/layer values
 *   interpreted?
 *
 *   RESOLVED: It is legal. For example, let's say texture 1 is a 2D_ARRAY
 *   texture with 200 layers. It will have TEXTURE_VIEW_MIN_LAYER=0,
 *   TEXTURE_VIEW_NUM_LAYERS=200. Then we create texture 2 from texture 1 using
 *   <minlayer>=100, <numlayers>=100. It will have TEXTURE_VIEW_MIN_LAYER=100,
 *   TEXTURE_VIEW_NUM_LAYERS=100. Then we create texture 3 from texture 2 using
 *   <minlayer>=50, <numlayers>=50. It will have TEXTURE_VIEW_MIN_LAYER=150,
 *   TEXTURE_VIEW_NUM_LAYERS=50."
 */
static bool
query_levels_test(void)
{
	GLuint tex[2], viewtex, l;
	GLint param;
	bool pass = true;

	glGenTextures(2, tex);

	/* test the view causes immutable_format to be set */
	glBindTexture(GL_TEXTURE_2D, tex[0]);
	glTexStorage2D(GL_TEXTURE_2D, 6, GL_R32F, 16, 32);
	glTextureView(tex[1], GL_TEXTURE_2D, tex[0], GL_RG16F, 0, 1, 0, 1);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	glBindTexture(GL_TEXTURE_2D, tex[1]);
	glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_IMMUTABLE_FORMAT, &param);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	if (param != GL_TRUE) {
		printf("bad query of immutable_format\n");
		pass = false;
	}
	glDeleteTextures(2,tex);

	/**
	 * test min_levels are additive using chained views
	 * test immutable_levels  get set correctly based on origtexture
	 * test num_levels are correct for chained views
	 */
	glGenTextures(2,tex);
	glBindTexture(GL_TEXTURE_CUBE_MAP, tex[0]);
	glTexStorage2D(GL_TEXTURE_CUBE_MAP, 7, GL_R32F, 64, 64);
	glTextureView(tex[1], GL_TEXTURE_CUBE_MAP,tex[0], GL_RG16I, 2, 4, 0, 6);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	glBindTexture(GL_TEXTURE_CUBE_MAP, tex[1]);
	glGetTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_IMMUTABLE_LEVELS,
						&param);
	if (param != 7) {
		printf("bad query of immutable_levels, expected 7 got %u\n",
		       param);
		pass = false;
	}
	for (l = 0; l < 4; l++) {
		glGenTextures(1, &viewtex);
		glTextureView(viewtex, GL_TEXTURE_CUBE_MAP, tex[1], GL_RG16F,
			      l, 4, 0, 6);
		glBindTexture(GL_TEXTURE_CUBE_MAP, viewtex);
		glGetTexParameteriv(GL_TEXTURE_CUBE_MAP,
				    GL_TEXTURE_VIEW_MIN_LEVEL, &param);
		if (param != (2 + l)) {
			glDeleteTextures(1, &viewtex);
			printf("bad query of view_min_level expected %u got %u\n",
			       2+l, param);
			pass = false;
			break;
		}
		glGetTexParameteriv(GL_TEXTURE_CUBE_MAP,
				    GL_TEXTURE_IMMUTABLE_LEVELS, &param);
		if (param != 7) {
			glDeleteTextures(1, &viewtex);
			printf("query of immutable_levels not tracking orig, expected 7 got %u\n",
			       param);
			pass = false;
			break;
		}
		glGetTexParameteriv(GL_TEXTURE_CUBE_MAP,
				    GL_TEXTURE_VIEW_NUM_LEVELS,	&param);
		if (param != (4 - l)) {
			glDeleteTextures(1, &viewtex);
			printf("bad query of view_num_levels expected %u got %u\n",
			       4 - l, param);
			pass = false;
			break;
		}
		glDeleteTextures(1, &viewtex);
	}
	glDeleteTextures(2, tex);

	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	return pass;
}
/**
 *
 */
/**
 * This tests correct queries of min_layers, num_layers.
 * note: see params test for more min/num  layers query testing
 *
 * In OpenGL Core 4.3 spec see section 8.18:
 *    "The minlevel and minlayer parameters are relative to the view of
 *    origtexture. If numlayers or numlevels extend beyond origtexture, they
 *    are clamped to the maximum extent of the original texture.
 *    If the command is successful, the texture parameters in <texture> are
 *     updated as follows:
 *       - TEXTURE_VIEW_MIN_LAYER is set to <minlayer> plus the value of
 *         TEXTURE_VIEW_MIN_LAYER from the original texture.
 *
 *       - TEXTURE_VIEW_NUM_LAYERS is set to the lesser of numlayerss and the
 *         value of TEXTURE_VIEW_NUM_LAYERS for origtexture minus minlayers."
 */

static bool
query_layers_state(void)
{
	bool pass = true;
	GLuint tex[2], viewtex, l;
	GLint param;

	glGenTextures(2, tex);
	glBindTexture(GL_TEXTURE_2D_ARRAY, tex[0]);
	glTexStorage3D(GL_TEXTURE_2D_ARRAY, 7, GL_RG16F, 64, 64, 10);
	glTextureView(tex[1], GL_TEXTURE_2D_ARRAY,tex[0], GL_RG16I, 0, 3, 1, 8);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
	for (l = 0; l < 4; l++) {
		glGenTextures(1, &viewtex);
		glTextureView(viewtex, GL_TEXTURE_2D_ARRAY, tex[1], GL_RG16UI,
			      0, 4, l, 9);
		glBindTexture(GL_TEXTURE_2D_ARRAY, viewtex);

		/* test min_layers are additive using chained views */
		glGetTexParameteriv(GL_TEXTURE_2D_ARRAY,
				    GL_TEXTURE_VIEW_MIN_LAYER, &param);

		if (param != (1 + l)) {
			glDeleteTextures(1, &viewtex);
			printf("bad query of view_min_layer expected %u got %u\n",
			       1+l, param);
			pass = false;
			break;
		}
		/* test num_layers are correct for chained views */
		glGetTexParameteriv(GL_TEXTURE_2D_ARRAY,
				    GL_TEXTURE_VIEW_NUM_LAYERS,	&param);
		if (param != (8 - l)) {
			glDeleteTextures(1, &viewtex);
			printf("bad query of view_num_layers expected %u got %u\n",
			       8 - l, param);
			pass = false;
			break;
		}

		glDeleteTextures(1, &viewtex);
	}
	glDeleteTextures(2, tex);

	return pass;
}

enum piglit_result
piglit_display(void)
{
	return PIGLIT_FAIL;
}

void
piglit_init(int argc, char **argv)
{
	bool pass = true;
#ifdef PIGLIT_USE_OPENGL
	piglit_require_extension("GL_ARB_texture_storage");
	piglit_require_extension("GL_ARB_texture_view");
#else
	piglit_require_extension("GL_OES_texture_view");
#endif

	pass = query_levels_test();
	pass = query_layers_state() && pass;
	pass = query_default_state() && pass;

	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}