2 * Copyright © 2013 The Piglit project
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
21 * DEALINGS IN THE SOFTWARE.
25 * \file vertices-out.c
27 * Test required errors for wrong GL_GEOMETRY_VERTICES_OUT parameters with
28 * variable number of output components.
30 * The value of GEOMETRY_VERTICES_OUT is limited by the implementation
31 * dependend constants MAX_GEOMETRY_OUTPUT_VERTICES and
32 * MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS.
34 * From the ARB_geometry_shader4 spec (section Errors):
35 * "The error INVALID_VALUE is generated by ProgramParameteriARB if <pname> is
36 * GEOMETRY_VERTICES_OUT_ARB and <value> is negative.
38 * The error INVALID_VALUE is generated by ProgramParameteriARB if <pname> is
39 * GEOMETRY_VERTICES_OUT_ARB and <value> exceeds
40 * MAX_GEOMETRY_OUTPUT_VERTICES_ARB.
42 * The error INVALID_VALUE is generated by ProgramParameteriARB if <pname> is
43 * set to GEOMETRY_VERTICES_OUT_ARB and the product of <value> and the sum of
44 * all components of all active varying variables exceeds
45 * MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB."
47 * And from section Geometry Shader outputs:
48 * "[...]the product of the total number of vertices and the sum of all
49 * components of all active varying variables may not exceed the value of
50 * MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB. LinkProgram will fail if it
51 * determines that the total component limit would be violated."
57 static const char gs_text_var
[] =
58 "uniform int vertex_count;\n"
59 "varying out float var[n];\n"
62 " for (int i = 0; i < vertex_count; i++) {\n"
63 " gl_Position = vec4(0.0);\n"
64 " for (int j = 0; j < n; j++)\n"
65 " var[j] = 1.0 / exp2(float(j + 1));\n"
70 static const char fs_text_var
[] =
71 "varying float var[n];\n"
74 " gl_FragColor = vec4(0.0);\n"
75 " for (int j = 0; j < n; j++)\n"
76 " gl_FragColor += vec4(var[j]);\n"
79 static bool transform_feedback
= false;
80 static int components
= -1;
83 PIGLIT_GL_TEST_CONFIG_BEGIN
84 config
.supports_gl_compat_version
= 20;
85 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
86 PIGLIT_GL_TEST_CONFIG_END
90 test_geometry_vertices_out(const GLuint prog
)
93 int max_geometry_output_vertices
;
94 int max_geometry_total_output_components
;
97 glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES
,
98 &max_geometry_output_vertices
);
99 glGetIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS
,
100 &max_geometry_total_output_components
);
102 printf("Testing negative (-1) vertices out.\n");
103 glProgramParameteri(prog
, GL_GEOMETRY_VERTICES_OUT_ARB
, -1);
104 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
106 /* Setting GEOMETRY_VERTICES_OUT to zero should generate no error but
107 * linking with a geometry shader should fail.
109 printf("Testing zero (0) vertices out.\n");
110 glProgramParameteri(prog
, GL_GEOMETRY_VERTICES_OUT_ARB
, 0);
112 pass
= piglit_check_gl_error(GL_NO_ERROR
) &&
113 !piglit_link_check_status_quiet(prog
) && pass
;
115 printf("Testing too many (%d) vertices out.\n",
116 max_geometry_output_vertices
+ 1);
117 glProgramParameteri(prog
, GL_GEOMETRY_VERTICES_OUT_ARB
,
118 max_geometry_output_vertices
+ 1);
119 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
121 /* If MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS results in an even smaller
122 * limit for GEOMETRY_VERTICES_OUT than GL_MAX_GEOMETRY_OUTPUT_VERTICES
125 * If (GEOMETRY_VERTICES_OUT * (sum of components of all out varyings))
126 * > MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, the spec requires
127 * ProgramParameter to throw an INVALID_VALUE and subsequent linking to
129 * But the number of output components can only be infered from the
130 * geometry shader source (and a geometry shader might not even be
131 * attached to the program object when ProgramParameter is called).
132 * So, ignore any errors generated from ProgramParameter and only check
133 * that linking failed.
135 if ((components
!= 0) &&
136 (max_geometry_total_output_components
/ components
<
137 max_geometry_output_vertices
)) {
138 printf("Testing too many total output components (%d vertices "
139 "=> %d total components).\n",
140 max_geometry_total_output_components
/ components
+ 1,
141 (max_geometry_total_output_components
/ components
+ 1) *
143 glProgramParameteri(prog
, GL_GEOMETRY_VERTICES_OUT_ARB
,
144 max_geometry_total_output_components
/
146 piglit_reset_gl_error();
148 pass
= !piglit_link_check_status_quiet(prog
) && pass
;
151 max_vertices_out
= (components
!= 0) ?
152 MIN2(max_geometry_output_vertices
,
153 max_geometry_total_output_components
/ components
) :
154 max_geometry_output_vertices
;
155 printf("Testing maximal (%d) vertices out.\n", max_vertices_out
);
156 glProgramParameteri(prog
, GL_GEOMETRY_VERTICES_OUT_ARB
,
159 pass
= piglit_check_gl_error(GL_NO_ERROR
) &&
160 piglit_link_check_status(prog
) && pass
;
166 /* Parse command line arguments.
168 * Recognized command line arguments are:
169 * * The optional argument "tf": Use transform feedback.
170 * * An integer indicating the number of per vertex varying components
171 * written by the geometry shader (not counting gl_Position) OR the
172 * argument "max" which indicates to use a number of components of
173 * MAX_GEOMETRY_VARYING_COMPONENTS_ARB or, if transform feedback is used,
174 * the minimum of MAX_GEOMETRY_VARYING_COMPONENTS_ARB and
175 * MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS.
178 parse_cmd_line(int argc
, char **argv
)
180 int i
, max_components
;
182 glGetIntegerv(GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB
, &max_components
);
184 for (i
= 1; i
< argc
; i
++) {
185 if (strcmp(argv
[i
], "tf") == 0) {
186 transform_feedback
= true;
187 } else if (strcmp(argv
[i
], "max") == 0) {
189 } else if(argv
[i
][0] != '-') {
191 long int l
= strtol(argv
[i
], &e
, 10);
197 if (transform_feedback
) {
198 int max_tf_components
;
200 piglit_require_extension("GL_EXT_transform_feedback");
202 glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS
,
204 max_components
= MIN2(max_components
, max_tf_components
);
207 if (components
== -2)
208 components
= max_components
;
210 if ((components
< 0) || components
> max_components
) {
211 fprintf(stderr
, "Please specify number of components "
212 "from 0 to %d (inclusive) on the command line\n",
214 piglit_report_result(PIGLIT_FAIL
);
219 piglit_init(int argc
, char **argv
)
223 const char *gs_string
, *fs_string
;
225 piglit_require_extension("GL_ARB_geometry_shader4");
226 /* NV_geometry_shader4 relaxes some restrictions on valid program
229 piglit_require_not_extension("GL_NV_geometry_shader4");
231 parse_cmd_line(argc
, argv
);
233 /* Prepare shader source strings. */
234 if (components
== 0) {
238 (void)!asprintf((char **)&gs_string
,
239 "#extension GL_ARB_geometry_shader4: enable\n"
240 "const int n = %d;\n%s", components
, gs_text_var
);
241 if (transform_feedback
)
244 (void)!asprintf((char **)&fs_string
,
245 "const int n = %d;\n%s",
246 components
, fs_text_var
);
249 printf("Running Test with %d component(s) per output vertex and "
250 "transform feedback %s.\n",
251 components
, transform_feedback
? "enabled" : "disabled");
253 /* Create shader and run test. */
254 prog
= create_shader(vs_text
, gs_string
, fs_string
);
255 pass
= test_geometry_vertices_out(prog
) && pass
;
256 glDeleteProgram(prog
);
258 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
264 /* Should never be reached */