2 * Copyright © 2013 Intel Corporation
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
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
24 #include "piglit-util-gl.h"
25 #include "xfb3_common.h"
28 * @file set_invalid_varyings.c
30 * Tests that varyings for separate attributes cannot be set using keywords
31 * reserved solely for the interleaved use. The spec:
33 * "The error INVALID_OPERATION is generated by TransformFeedbackVaryings
34 * if any pointer in <varyings> identifies the special names "gl_NextBuffer",
35 * "gl_SkipComponents1", "gl_SkipComponents2", "gl_SkipComponents3", or
36 * "gl_SkipComponents4" and <bufferMode> is not INTERLEAVED_ATTRIBS_NV, or if
37 * the number of "gl_NextBuffer" pointers in <varyings> is greater than or
38 * equal to the value of MAX_TRANSFORM_FEEDBACK_BUFFERS."
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config
.supports_gl_compat_version
= 32;
44 config
.supports_gl_core_version
= 32;
45 config
.khr_no_error_support
= PIGLIT_HAS_ERRORS
;
47 PIGLIT_GL_TEST_CONFIG_END
49 static const char gs_simple_text
[] =
51 "layout(points) in;\n"
52 "layout(points, max_vertices = 1) out;\n"
55 " gl_Position = gl_in[0].gl_Position;\n"
60 const char *description
;
61 const char *varyings
[2];
62 } invalid_for_separated
[] = {
64 "gl_NextBuffer should not be accepted in separate mode",
65 { "x1_out", "gl_NextBuffer" }
68 "gl_SkipComponents1 should not be accepted in separate mode",
69 { "gl_SkipComponents1", "x1_out" }
72 "gl_SkipComponents2 should not be accepted in separate mode",
73 { "gl_SkipComponents2", "x1_out" }
76 "gl_SkipComponents3 should not be accepted in separate mode",
77 { "gl_SkipComponents3", "x1_out" }
80 "gl_SkipComponents4 should not be accepted in separate mode",
81 { "gl_SkipComponents4", "x1_out" }
86 try_invalid_separate_mode(GLuint prog
)
90 for (i
= 0; i
< ARRAY_SIZE(invalid_for_separated
); ++i
) {
91 glTransformFeedbackVaryings(prog
,
92 ARRAY_SIZE(invalid_for_separated
[i
].varyings
),
93 invalid_for_separated
[i
].varyings
,
96 if (!piglit_check_gl_error(GL_INVALID_OPERATION
)) {
98 invalid_for_separated
[i
].description
);
107 * Dynamically reserve space and setup an array of 'n + n + 1' string pointers
108 * having the following layout:
110 * [0]: "x_0x00000000"
111 * [1]: "gl_NextBuffer"
112 * [2]: "x_0x00000001"
113 * [3]: "gl_NextBuffer"
117 * For testing the upper bound of sepators (gl_NextBuffer) the varying names
118 * need to be mutually unique as the driver could simply bail out before
119 * encountering 'n' separators simply because the driver did not except already
123 try_max_separators(GLuint prog
, unsigned n
)
125 /* 'n' + 1 varying names and 'n' separators */
126 const unsigned var_n
= 2 * n
+ 1;
130 vars
= (const char **)malloc(var_n
* sizeof(const char *));
132 for (i
= 0; i
<= n
; ++i
) {
133 (void)!asprintf((char **)&vars
[2 * i
+ 0], "x_0x%08x", i
);
136 static const char separator
[] = "gl_NextBuffer";
137 vars
[2 * i
+ 1] = separator
;
141 glTransformFeedbackVaryings(prog
, var_n
, vars
, GL_INTERLEAVED_ATTRIBS
);
143 for (i
= 0; i
<= n
; ++i
)
144 free((char *)vars
[2 * i
+ 0]);
148 return piglit_check_gl_error(GL_INVALID_OPERATION
);
152 piglit_init(int argc
, char **argv
)
158 piglit_require_extension("GL_ARB_transform_feedback3");
160 glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS
,
163 printf("Maximum number of separate attributes is zero\n");
164 piglit_report_result(PIGLIT_FAIL
);
167 prog
= piglit_build_simple_program_multiple_shaders(
168 GL_VERTEX_SHADER
, vs_pass_thru_text
,
169 GL_GEOMETRY_SHADER
, gs_simple_text
, 0);
171 /* Try too many attributes */
172 pass
= try_invalid_separate_mode(prog
) && pass
;
173 pass
= try_max_separators(prog
, max_attrib_n
) && pass
;
175 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
181 /* Should never be reached */