File: api.c

package info (click to toggle)
piglit 0~git20200212-f4710c51b-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 106,972 kB
  • sloc: ansic: 263,763; xml: 48,941; python: 29,918; lisp: 19,789; cpp: 12,142; sh: 22; makefile: 20; pascal: 5
file content (290 lines) | stat: -rw-r--r-- 7,526 bytes parent folder | download | duplicates (4)
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
/*
 * Copyright © 2012 Intel Corporation
 *
 * 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.
 */

/**
 * \file api.c
 *
 * Test miscellaneous other entrypoints for GL_ARB_occlusion_query2.
 */

#include "piglit-util-gl.h"

PIGLIT_GL_TEST_CONFIG_BEGIN

	config.supports_gl_compat_version = 10;
	config.window_visual = (PIGLIT_GL_VISUAL_RGB |
				PIGLIT_GL_VISUAL_DOUBLE |
				PIGLIT_GL_VISUAL_DEPTH);
	config.khr_no_error_support = PIGLIT_NO_ERRORS;

PIGLIT_GL_TEST_CONFIG_END

static bool
test_error_begin_while_other_active(void)
{
	GLuint oq[2];
	bool pass = true;

	/* GL_ARB_occlusion_query2 specifies INVALID_OPERATION for
	 * starting either query type with the other one active.
	 */
	glGenQueries(2, oq);

	glBeginQuery(GL_SAMPLES_PASSED, oq[0]);
	if (!piglit_check_gl_error(0))
		pass = false;
	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[1]);
	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
		pass = false;
	glEndQuery(GL_ANY_SAMPLES_PASSED);
	glEndQuery(GL_SAMPLES_PASSED);
	piglit_reset_gl_error();

	glDeleteQueries(2, oq);

	glGenQueries(2, oq);

	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[0]);
	if (!piglit_check_gl_error(0))
		pass = false;
	glBeginQuery(GL_SAMPLES_PASSED, oq[1]);
	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
		pass = false;
	glEndQuery(GL_SAMPLES_PASSED);
	glEndQuery(GL_ANY_SAMPLES_PASSED);
	piglit_reset_gl_error();

	glDeleteQueries(2, oq);

	return pass;
}

static bool
test_counter_bits(void)
{
	GLint result = -1;

	/* From the GL_ARB_occlusion_query2 spec:
	 *
	 *   "Modify the paragraph beginning with "For occlusion
	 *   queries (SAMPLES_PASSED)..."
	 *
	 *       For occlusion queries
	 *    |  (SAMPLES_PASSED and ANY_SAMPLES_PASSED), the number of bits
	 *    |  depends on the target.  For a target of ANY_SAMPLES_PASSED, if
	 *    |  the number of bits is non-zero,  the minimum number of bits
	 *    |  is 1.  For a target of SAMPLES_PASSED,
	 *       if the number of bits is non-zero, ..."
	 *
	 * So, the number of bits has to be either a zero or >= 1.
	 */
	glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, &result);
	if (result < 0) {
		fprintf(stderr, "GL_QUERY_COUNTER_BITS returned %d\n", result);
		return false;
	}
	return true;
}

static bool
test_error_begin_wrong_target(void)
{
	bool pass = true;
	GLuint oq;

	glGenQueries(1, &oq);

	glBeginQuery(GL_SAMPLES_PASSED, oq);
	if (!piglit_check_gl_error(0))
		pass = false;
	glEndQuery(GL_SAMPLES_PASSED);

	/* From the OpenGL 3.3 spec, section "2.14. ASYNCHRONOUS QUERIES", page 94:
	 *
	 *    "[...] if id is the name of an existing query object whose type does not
	 *     match target, [...] the error INVALID_OPERATION is generated."
	 *
	 * Similar wording exists in the OpenGL ES 3.0.0 spec, section "2.13.
	 * ASYNCHRONOUS QUERIES", page 82.
	 */
	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq);
	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
		pass = false;
	glEndQuery(GL_ANY_SAMPLES_PASSED);
	piglit_reset_gl_error();

	glDeleteQueries(1, &oq);

	return pass;
}

static bool
test_error_end_wrong_target(void)
{
	bool pass = true;
	GLuint oq;

	glGenQueries(1, &oq);

	/* From the GL_ARB_occlusion_query2 spec:
	 *
	 *     "If EndQueryARB is called while no query with the same
	 *      target is in progress, an INVALID_OPERATION error is
	 *      generated."
	 */
	glBeginQuery(GL_SAMPLES_PASSED, oq);
	if (!piglit_check_gl_error(0))
		pass = false;
	glEndQuery(GL_ANY_SAMPLES_PASSED);
	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
		pass = false;
	glEndQuery(GL_SAMPLES_PASSED);
	piglit_reset_gl_error();

	glDeleteQueries(1, &oq);

	glGenQueries(1, &oq);

	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq);
	if (!piglit_check_gl_error(0))
		pass = false;
	glEndQuery(GL_SAMPLES_PASSED);
	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
		pass = false;
	glEndQuery(GL_ANY_SAMPLES_PASSED);
	piglit_reset_gl_error();

	glDeleteQueries(1, &oq);

	return pass;
}

static bool
test_current_query(void)
{
	bool pass = true;
	GLint result = -1;
	GLuint oq;

	glGenQueries(1, &oq);

	/* Test that GL_CURRENT_QUERY returns our target and not the
	 * other one. First, check that we're inactive after the
	 * previous sequence of query code.
	 */
	result = -1;
	glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
	if (result != 0) {
		fprintf(stderr,
			"GL_CURRENT_QUERY(GL_ANY_SAMPLES_PASSED) returned %d "
			"while inactive\n",
			result);
		pass = false;
	}
	result = -1;
	glGetQueryiv(GL_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
	if (result != 0) {
		fprintf(stderr,
			"GL_CURRENT_QUERY(GL_SAMPLES_PASSED) returned %d "
			"while inactive\n",
			result);
		pass = false;
	}

	/* Test the result for GL_ANY_SAMPLES_PASSED active */
	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq);
	result = -1;
	glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
	if (result != oq) {
		fprintf(stderr,
			"GL_CURRENT_QUERY(GL_ANY_SAMPLES_PASSED) returned %d "
			"while GL_ANY_SAMPLES_PASSED active\n",
			result);
		pass = false;
	}
	result = -1;
	glGetQueryiv(GL_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
	if (result != 0) {
		fprintf(stderr,
			"GL_CURRENT_QUERY(GL_SAMPLES_PASSED) returned %d while "
			"GL_ANY_SAMPLES_PASSED active\n",
			result);
		pass = false;
	}
	glEndQuery(GL_ANY_SAMPLES_PASSED);
	glDeleteQueries(1, &oq);

	glGenQueries(1, &oq);

	/* Test the result for GL_SAMPLES_PASSED active */
	glBeginQuery(GL_SAMPLES_PASSED, oq);
	result = -1;
	glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
	if (result != 0) {
		fprintf(stderr,
			"GL_CURRENT_QUERY(GL_ANY_SAMPLES_PASSED) returned %d "
			"while GL_SAMPLES_PASSED active\n",
			result);
		pass = false;
	}
	result = -1;
	glGetQueryiv(GL_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
	if (result != oq) {
		fprintf(stderr,
			"GL_CURRENT_QUERY(GL_SAMPLES_PASSED) returned %d "
			"while GL_SAMPLES_PASSED active\n",
			result);
		pass = false;
	}
	glEndQuery(GL_SAMPLES_PASSED);

	glDeleteQueries(1, &oq);

	return pass;
}

enum piglit_result
piglit_display(void)
{
	bool pass = true;

	pass = test_counter_bits() && pass;
	pass = test_current_query() && pass;

	if (!piglit_khr_no_error) {
		pass = test_error_begin_wrong_target() && pass;
		pass = test_error_end_wrong_target() && pass;
		pass = test_error_begin_while_other_active() && pass;
	}

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);

	/* UNREACHED */
	return PIGLIT_FAIL;
}

void
piglit_init(int argc, char **argv)
{
	piglit_require_extension("GL_ARB_occlusion_query2");
}