2 * Copyright © 2014 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
25 * \file layout-mismatch.c
27 * Link multiple shader objects with layout qualifiers and check that linking
28 * fails or succeeds if the qualifiers mismatch or match, respectively.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 32;
36 config
.supports_gl_core_version
= 32;
37 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
39 PIGLIT_GL_TEST_CONFIG_END
42 static const char *const vs_source
=
44 "void main() { gl_Position = vec4(0.0); }\n";
46 static const char *const tcs_source_main
=
48 "#extension GL_ARB_tessellation_shader: require\n"
49 "layout(vertices = 3) out;\n"
51 " gl_TessLevelOuter = float[4](1.0, 1.0, 1.0, 1.0);\n"
52 " gl_TessLevelInner = float[2](1.0, 1.0);\n"
55 static const char *const tcs_source_main_no_v
=
57 "#extension GL_ARB_tessellation_shader: require\n"
59 " gl_TessLevelOuter = float[4](1.0, 1.0, 1.0, 1.0);\n"
60 " gl_TessLevelInner = float[2](1.0, 1.0);\n"
63 static const char *const tes_source_main
=
65 "#extension GL_ARB_tessellation_shader: require\n"
66 "layout(triangles) in;\n"
67 "void main() { gl_Position = vec4(0.0); }\n";
69 static const char *const tes_source_main_no_pm
=
71 "#extension GL_ARB_tessellation_shader: require\n"
72 "void main() { gl_Position = vec4(0.0); }\n";
74 static const char *const fs_source
=
76 "void main() { gl_FragColor = vec4(0.0); }\n";
79 static const char *const tcs_source_template
=
81 "#extension GL_ARB_tessellation_shader: require\n"
82 "layout(vertices = %d) out;\n"
83 "int foo%d(void) { return 1; }\n";
85 static const char *const tes_source_template
=
87 "#extension GL_ARB_tessellation_shader: require\n"
89 "int foo%d(void) { return 1; }\n";
92 static const char *const prim_mode
[] = {
93 "triangles", "quads", "isolines"
95 static const char *const spacing
[] = {
96 "triangles, equal_spacing",
97 "triangles, fractional_even_spacing",
98 "triangles, fractional_odd_spacing"
100 static const char *const vertex_order
[] = {
101 "triangles, cw", "triangles, ccw"
104 static char *tes_source1
, *tes_source2
;
105 static char *tcs_source1
, *tcs_source2
;
108 test_tcs_layout(const int i
, const int j
)
113 sprintf(tcs_source1
, tcs_source_template
, i
, 1);
114 sprintf(tcs_source2
, tcs_source_template
, j
, 2);
116 prog
= piglit_build_simple_program_unlinked_multiple_shaders(
117 GL_VERTEX_SHADER
, vs_source
,
118 GL_TESS_CONTROL_SHADER
, tcs_source_main_no_v
,
119 GL_TESS_CONTROL_SHADER
, tcs_source1
,
120 GL_TESS_CONTROL_SHADER
, tcs_source2
,
121 GL_TESS_EVALUATION_SHADER
, tes_source_main
,
122 GL_FRAGMENT_SHADER
, fs_source
,
125 link_status
= piglit_link_check_status_quiet(prog
);
126 glDeleteProgram(prog
);
128 if (link_status
&& (i
!= j
)) {
129 fprintf(stderr
, "Program with different vertices "
130 "specifications linked successfully\n");
133 if (!link_status
&& (i
== j
)) {
134 fprintf(stderr
, "Program with identical vertices "
135 "specifications failed to link\n");
144 test_tes_layout(const char *const layout1
, const char *const layout2
,
145 const char *const layout_name
)
150 sprintf(tes_source1
, tes_source_template
, layout1
, 1);
151 sprintf(tes_source2
, tes_source_template
, layout2
, 2);
153 prog
= piglit_build_simple_program_unlinked_multiple_shaders(
154 GL_VERTEX_SHADER
, vs_source
,
155 GL_TESS_CONTROL_SHADER
, tcs_source_main
,
156 GL_TESS_EVALUATION_SHADER
, tes_source_main_no_pm
,
157 GL_TESS_EVALUATION_SHADER
, tes_source1
,
158 GL_TESS_EVALUATION_SHADER
, tes_source2
,
159 GL_FRAGMENT_SHADER
, fs_source
,
162 link_status
= piglit_link_check_status_quiet(prog
);
163 glDeleteProgram(prog
);
165 if (link_status
&& (layout1
!= layout2
)) {
166 fprintf(stderr
, "Program with different %s "
167 "specifications linked successfully\n", layout_name
);
170 if (!link_status
&& (layout1
== layout2
)) {
171 fprintf(stderr
, "Program with identical %s "
172 "specifications failed to link\n", layout_name
);
181 piglit_init(int argc
, char **argv
)
186 piglit_require_extension("GL_ARB_tessellation_shader");
188 /* From the ARB_tessellation_shader spec (Section 2.14.2):
190 * "Linking will fail if the program object contains objects to form
191 * a tessellation control shader (see section 2.X.1), and
195 * * the output patch vertex count is specified differently in
197 * tessellation control shader objects."
199 tcs_source1
= malloc(strlen(tcs_source_template
) + 8);
200 tcs_source2
= malloc(strlen(tcs_source_template
) + 8);
202 for(i
= 1; i
< 32; i
*= 4) {
203 for(j
= 1; j
< 32; j
*= 4) {
204 pass
= test_tcs_layout(i
, j
) && pass
;
211 /* From the ARB_tessellation_shader spec (Section 2.14.2):
213 * "Linking will fail if the program object contains objects to form
214 * a tessellation evaluation shader (see section 2.X.3), and
218 * * the tessellation primitive mode, spacing, vertex order, or
219 * point mode is specified differently in multiple tessellation
220 * evaluation shader objects."
222 tes_source1
= malloc(strlen(tes_source_template
) + 64);
223 tes_source2
= malloc(strlen(tes_source_template
) + 64);
225 for(i
= 0; i
< ARRAY_SIZE(prim_mode
); ++i
) {
226 for(j
= 0; j
< ARRAY_SIZE(prim_mode
); ++j
) {
227 pass
= test_tes_layout(prim_mode
[i
], prim_mode
[j
],
228 "primitive mode") && pass
;
232 for(i
= 0; i
< ARRAY_SIZE(spacing
); ++i
) {
233 for(j
= 0; j
< ARRAY_SIZE(spacing
); ++j
) {
234 pass
= test_tes_layout(spacing
[i
], spacing
[j
],
235 "vertex spacing") && pass
;
239 for(i
= 0; i
< ARRAY_SIZE(vertex_order
); ++i
) {
240 for(j
= 0; j
< ARRAY_SIZE(vertex_order
); ++j
) {
241 pass
= test_tes_layout(vertex_order
[i
],
243 "vertex order") && pass
;
250 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
252 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);