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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
/*
* Copyright © 2011 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-errors.c
*
* Test that the implementation flags various
* transform-feedback-related error conditions.
*
* This test covers all of the error conditions as specified in the
* "Errors" section of the EXT_transform_feedback spec, with the
* following exceptions:
*
* - Errors related to BeginQuery and EndQuery.
*
* - Error due to mismatch of transform feedback mode and drawing mode
* (e.g. drawing GL_LINES when transform feedback is expecting
* GL_TRIANGLES).
*
* - Errors due to exceeding MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTIBS in
* a call to TransformFeedbackVaryings, GetTransformFeedbackVarying,
* or
* Get{Integer,Boolean}Indexedv(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING).
*
* In addition, there are a few tests which verify that errors do not
* occur during normal operation ("interleaved_ok_*", "separate_ok_*",
* and "link_other_active"). These tests help to verify that the
* implementation is not overly aggressive in flagging errors.
*/
#include "piglit-util-gl-common.h"
PIGLIT_GL_TEST_CONFIG_BEGIN
config.supports_gl_compat_version = 10;
config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
PIGLIT_GL_TEST_CONFIG_END
#define XFB_BUFFER_SIZE 12
#define NUM_BUFFERS 2
enum test_mode {
NORMAL,
NO_VARYINGS,
UNBOUND_BUFFER,
SKIP_USE_PROGRAM,
BEGIN_ACTIVE,
USEPROG_ACTIVE,
LINK_CURRENT_ACTIVE,
LINK_OTHER_ACTIVE,
BIND_ACTIVE,
END_INACTIVE,
BIND_MAX,
BIND_BAD_SIZE,
BIND_BAD_OFFSET,
NOT_A_PROGRAM,
USEPROGSTAGE_ACTIVE,
USEPROGSTAGE_NOACTIVE,
BIND_PIPELINE
};
enum bind_mode {
BASE,
RANGE,
OFFSET,
};
static const char *vstext =
"varying vec4 foo;\n"
"varying vec4 bar;\n"
"\n"
"void main()\n"
"{\n"
" foo = vec4(1.0);\n"
" bar = vec4(1.0);\n"
" gl_Position = vec4(1.0);\n"
"}\n";
static const char *vstext_sep_template =
"#version %d\n"
"#extension GL_ARB_separate_shader_objects : enable\n"
"#if __VERSION__ > 140\n"
"/* At least some versions of AMD's closed-source driver\n"
" * contain a bug that requires redeclaration of gl_PerVertex\n"
" * interface block in core profile shaders.\n"
" */\n"
"out gl_PerVertex {\n"
" vec4 gl_Position;\n"
"};\n"
"#endif\n"
"varying vec4 foo;\n"
"varying vec4 bar;\n"
"\n"
"void main()\n"
"{\n"
" foo = vec4(1.0);\n"
" bar = vec4(1.0);\n"
" gl_Position = vec4(1.0);\n"
"}\n";
static const char *varyings[] = { "foo", "bar" };
static struct test_desc
{
const char *name;
enum test_mode mode;
int param;
enum bind_mode bind_mode;
GLenum buffer_mode;
int num_buffers;
GLboolean skip_use_program;
} tests[] = {
/* name mode param num_buffers
* bind_mode
* buffer_mode
*/
{ "interleaved_ok_base", NORMAL, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "interleaved_ok_range", NORMAL, 0, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "interleaved_ok_offset", NORMAL, 0, OFFSET, GL_INTERLEAVED_ATTRIBS, 1 },
{ "interleaved_unbound", UNBOUND_BUFFER, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "interleaved_no_varyings", NO_VARYINGS, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "separate_ok_1", NORMAL, 0, BASE, GL_SEPARATE_ATTRIBS, 1 },
{ "separate_unbound_0_1", UNBOUND_BUFFER, 0, BASE, GL_SEPARATE_ATTRIBS, 1 },
{ "separate_ok_2", NORMAL, 0, BASE, GL_SEPARATE_ATTRIBS, 2 },
{ "separate_unbound_0_2", UNBOUND_BUFFER, 0, BASE, GL_SEPARATE_ATTRIBS, 2 },
{ "separate_unbound_1_2", UNBOUND_BUFFER, 1, BASE, GL_SEPARATE_ATTRIBS, 2 },
{ "separate_no_varyings", NO_VARYINGS, 0, BASE, GL_SEPARATE_ATTRIBS, 1 },
{ "no_prog_active", SKIP_USE_PROGRAM, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "begin_active", BEGIN_ACTIVE, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "useprog_active", USEPROG_ACTIVE, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "link_current_active", LINK_CURRENT_ACTIVE, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "link_other_active", LINK_OTHER_ACTIVE, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_base_active", BIND_ACTIVE, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_active", BIND_ACTIVE, 0, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_offset_active", BIND_ACTIVE, 0, OFFSET, GL_INTERLEAVED_ATTRIBS, 1 },
{ "end_inactive", END_INACTIVE, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_base_max", BIND_MAX, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_max", BIND_MAX, 0, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_offset_max", BIND_MAX, 0, OFFSET, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_size_m4", BIND_BAD_SIZE, -4, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_size_0", BIND_BAD_SIZE, 0, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_size_1", BIND_BAD_SIZE, 1, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_size_2", BIND_BAD_SIZE, 2, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_size_3", BIND_BAD_SIZE, 3, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_size_5", BIND_BAD_SIZE, 5, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_offset_1", BIND_BAD_OFFSET, 1, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_offset_2", BIND_BAD_OFFSET, 2, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_offset_3", BIND_BAD_OFFSET, 3, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_range_offset_5", BIND_BAD_OFFSET, 5, RANGE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_offset_offset_1", BIND_BAD_OFFSET, 1, OFFSET, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_offset_offset_2", BIND_BAD_OFFSET, 2, OFFSET, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_offset_offset_3", BIND_BAD_OFFSET, 3, OFFSET, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_offset_offset_5", BIND_BAD_OFFSET, 5, OFFSET, GL_INTERLEAVED_ATTRIBS, 1 },
{ "not_a_program", NOT_A_PROGRAM, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "useprogstage_noactive", USEPROGSTAGE_NOACTIVE,0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "useprogstage_active", USEPROGSTAGE_ACTIVE, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
{ "bind_pipeline", BIND_PIPELINE, 0, BASE, GL_INTERLEAVED_ATTRIBS, 1 },
};
static void
do_bind(const struct test_desc *test, GLuint buf, int i)
{
int size = test->mode == BIND_BAD_SIZE
? test->param : sizeof(float[XFB_BUFFER_SIZE]);
int offset = test->mode == BIND_BAD_OFFSET
? test->param : 0;
switch (test->bind_mode) {
case BASE:
printf("BindBufferBase(buffer %i)\n", i);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, i, buf);
break;
case RANGE:
printf("BindBufferRange(buffer %i, offset=%i, size=%i)\n", i,
offset, size);
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i, buf,
offset, size);
break;
case OFFSET:
printf("BindBufferOffsetEXT(buffer %i, offset=%i)\n", i,
offset);
glBindBufferOffsetEXT(GL_TRANSFORM_FEEDBACK_BUFFER, i, buf,
offset);
break;
}
}
static GLboolean
do_test(const struct test_desc *test)
{
GLuint vs;
GLuint progs[2];
GLuint pipes[2];
GLuint bufs[NUM_BUFFERS];
float initial_xfb_buffer_contents[XFB_BUFFER_SIZE];
GLboolean pass = GL_TRUE;
int i;
int num_varyings = test->mode == NO_VARYINGS ? 0 : test->num_buffers;
GLint max_separate_attribs;
char* vstext_sep;
if (test->mode == USEPROGSTAGE_ACTIVE
|| test->mode == USEPROGSTAGE_NOACTIVE
|| test->mode == BIND_PIPELINE) {
piglit_require_extension("GL_ARB_separate_shader_objects");
if (piglit_get_gl_version() >= 32)
asprintf(&vstext_sep, vstext_sep_template, 150);
else
asprintf(&vstext_sep, vstext_sep_template, 110);
}
glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
&max_separate_attribs);
printf("MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTIBS=%i\n",
max_separate_attribs);
printf("Compile vertex shader\n");
vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);
if (test->mode == USEPROGSTAGE_ACTIVE
|| test->mode == USEPROGSTAGE_NOACTIVE
|| test->mode == BIND_PIPELINE) {
/* Note, we can't use glCreateShaderProgramv because the setup
* of transform feedback must be done before linking
*/
vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext_sep);
progs[0] = glCreateProgram();
glProgramParameteri(progs[0], GL_PROGRAM_SEPARABLE, GL_TRUE);
glAttachShader(progs[0], vs);
} else if (test->mode == NOT_A_PROGRAM) {
printf("Create a program and then delete it\n");
progs[0] = glCreateProgram();
glDeleteProgram(progs[0]);
} else {
progs[0] = glCreateProgram();
glAttachShader(progs[0], vs);
}
pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
printf("Setup transform feedback for %i varyings in %s mode\n",
num_varyings,
test->buffer_mode == GL_INTERLEAVED_ATTRIBS
? "interleaved" : "separate");
glTransformFeedbackVaryings(progs[0], num_varyings,
varyings, test->buffer_mode);
if (test->mode == NOT_A_PROGRAM) {
pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
return pass;
}
printf("Link program\n");
glLinkProgram(progs[0]);
pass = piglit_link_check_status(progs[0]) && pass;
if (test->mode == USEPROGSTAGE_ACTIVE
|| test->mode == USEPROGSTAGE_NOACTIVE
|| test->mode == BIND_PIPELINE) {
printf("Create 2nd program for the pipeline\n");
progs[1] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,
(const char **) &vstext_sep);
pass = piglit_link_check_status(progs[1]) && pass;
}
if (test->mode == USEPROG_ACTIVE || test->mode == LINK_OTHER_ACTIVE) {
printf("Prepare 2nd program\n");
progs[1] = glCreateProgram();
glAttachShader(progs[1], vs);
}
if (test->mode == USEPROG_ACTIVE) {
printf("Link 2nd program\n");
glLinkProgram(progs[1]);
pass = piglit_link_check_status(progs[1]) && pass;
}
if (test->mode == USEPROGSTAGE_ACTIVE
|| test->mode == USEPROGSTAGE_NOACTIVE
|| test->mode == BIND_PIPELINE) {
printf("Use pipeline\n");
glGenProgramPipelines(2, pipes);
glUseProgramStages(pipes[0], GL_VERTEX_SHADER_BIT, progs[0]);
glUseProgramStages(pipes[1], GL_VERTEX_SHADER_BIT, progs[1]);
glBindProgramPipeline(pipes[0]);
} else if (test->mode == SKIP_USE_PROGRAM) {
printf("Don't use program\n");
} else {
printf("Use program\n");
glUseProgram(progs[0]);
}
printf("Prepare %i buffers\n", test->num_buffers);
glGenBuffers(test->num_buffers, bufs);
memset(initial_xfb_buffer_contents, 0,
sizeof(initial_xfb_buffer_contents));
for (i = 0; i < test->num_buffers; ++i) {
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, bufs[i]);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER,
sizeof(initial_xfb_buffer_contents),
initial_xfb_buffer_contents, GL_STREAM_READ);
}
switch (test->mode) {
case BIND_MAX:
do_bind(test, bufs[0], max_separate_attribs);
pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
return pass;
case BIND_BAD_SIZE:
case BIND_BAD_OFFSET:
do_bind(test, bufs[0], 0);
pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
return pass;
default:
break;
}
for (i = 0; i < test->num_buffers; ++i) {
if (test->mode == UNBOUND_BUFFER && i == test->param) {
printf("Don't bind buffer %i\n", i);
} else {
do_bind(test, bufs[i], i);
}
}
pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
if (test->mode == END_INACTIVE) {
printf("EndTransformFeedback\n");
glEndTransformFeedback();
pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
return pass;
}
printf("BeginTransformFeedback\n");
glBeginTransformFeedback(GL_POINTS);
switch (test->mode) {
case UNBOUND_BUFFER:
case NO_VARYINGS:
case SKIP_USE_PROGRAM:
pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
break;
default:
pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
break;
}
switch (test->mode) {
case BEGIN_ACTIVE:
printf("BeginTransformFeedback\n");
glBeginTransformFeedback(GL_POINTS);
pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
break;
case USEPROG_ACTIVE:
printf("Use new program\n");
glUseProgram(progs[1]);
pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
break;
case LINK_CURRENT_ACTIVE:
printf("Link current program\n");
glLinkProgram(progs[0]);
pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
break;
case LINK_OTHER_ACTIVE:
printf("Link 2nd program\n");
glLinkProgram(progs[1]);
pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
break;
case BIND_ACTIVE:
do_bind(test, bufs[0], 0);
pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
break;
case USEPROGSTAGE_ACTIVE:
printf("Use new program stage\n");
glUseProgramStages(pipes[0], GL_VERTEX_SHADER_BIT, progs[1]);
pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
break;
case USEPROGSTAGE_NOACTIVE:
printf("Use new program stage\n");
glUseProgramStages(pipes[1], GL_VERTEX_SHADER_BIT, progs[1]);
pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
break;
case BIND_PIPELINE:
printf("Bind a new pipeline\n");
glBindProgramPipeline(pipes[1]);
pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
break;
default:
break;
}
return pass;
}
void
print_usage_and_exit(const char *prog_name)
{
int i;
printf("Usage: %s <test_name>\n"
" where <test_name> is one of:\n", prog_name);
for (i = 0; i < ARRAY_SIZE(tests); ++i)
printf(" %s\n", tests[i].name);
exit(0);
}
const struct test_desc *
find_matching_test(const char *prog_name, const char *test_name)
{
int i;
for (i = 0; i < ARRAY_SIZE(tests); ++i) {
if (strcmp(tests[i].name, test_name) == 0)
return &tests[i];
}
print_usage_and_exit(prog_name);
return NULL; /* won't actually be reached */
}
void
piglit_init(int argc, char **argv)
{
const struct test_desc *test;
/* Parse params. */
if (argc != 2)
print_usage_and_exit(argv[0]);
test = find_matching_test(argv[0], argv[1]);
piglit_require_GLSL();
piglit_require_transform_feedback();
if (test->bind_mode == OFFSET) {
/* BindBufferOffset only exists in the EXT specification */
piglit_require_extension("GL_EXT_transform_feedback");
}
piglit_report_result(do_test(test) ? PIGLIT_PASS : PIGLIT_FAIL);
}
enum piglit_result
piglit_display(void)
{
/* Should never be reached */
return PIGLIT_FAIL;
}
|