glsl: test loop unroll with uint overflow
[piglit.git] / tests / spec / arb_transform_feedback3 / set_invalid_varyings.c
blob80124ed604f86f4d6d2aca7a8100b2f4ef4573bb
1 /*
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
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.
24 #include "piglit-util-gl.h"
25 #include "xfb3_common.h"
27 /**
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[] =
50 "#version 150\n"
51 "layout(points) in;\n"
52 "layout(points, max_vertices = 1) out;\n"
53 "out float x1_out;\n"
54 "void main() {\n"
55 " gl_Position = gl_in[0].gl_Position;\n"
56 " x1_out = 1.0;\n"
57 "}";
59 static const struct {
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" }
85 static bool
86 try_invalid_separate_mode(GLuint prog)
88 unsigned i;
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,
94 GL_SEPARATE_ATTRIBS);
96 if (!piglit_check_gl_error(GL_INVALID_OPERATION)) {
97 printf("fail: %s\n",
98 invalid_for_separated[i].description);
99 return false;
103 return true;
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"
114 * ...
115 * [2n]: "x_0x..n"
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
120 * declared varying.
122 static bool
123 try_max_separators(GLuint prog, unsigned n)
125 /* 'n' + 1 varying names and 'n' separators */
126 const unsigned var_n = 2 * n + 1;
127 const char **vars;
128 unsigned i;
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);
135 if (i < n) {
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]);
146 free(vars);
148 return piglit_check_gl_error(GL_INVALID_OPERATION);
151 void
152 piglit_init(int argc, char **argv)
154 bool pass = true;
155 GLuint prog;
156 GLint max_attrib_n;
158 piglit_require_extension("GL_ARB_transform_feedback3");
160 glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
161 &max_attrib_n);
162 if (!max_attrib_n) {
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);
178 enum piglit_result
179 piglit_display(void)
181 /* Should never be reached */
182 return PIGLIT_FAIL;