2 * Copyright © 2013 Gregory Hainaut <gregory.hainaut@gmail.com>
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"
26 PIGLIT_GL_TEST_CONFIG_BEGIN
28 config
.supports_gl_compat_version
= 20;
29 config
.supports_gl_core_version
= 31;
31 PIGLIT_GL_TEST_CONFIG_END
43 stage2bitfield(GLint stage
)
46 case GL_VERTEX_SHADER
: return GL_VERTEX_SHADER_BIT
;
47 case GL_FRAGMENT_SHADER
: return GL_FRAGMENT_SHADER_BIT
;
48 case GL_GEOMETRY_SHADER
: return GL_GEOMETRY_SHADER_BIT
;
49 case GL_TESS_CONTROL_SHADER
: return GL_TESS_CONTROL_SHADER_BIT
;
50 case GL_TESS_EVALUATION_SHADER
:return GL_TESS_EVALUATION_SHADER_BIT
;
51 case GL_COMPUTE_SHADER
: return GL_COMPUTE_SHADER_BIT
;
53 assert(!"Should not get here.");
59 check_stage(GLint pipe
, GLint expected
, GLint stage
, bool supported
)
62 glGetProgramPipelineiv(pipe
, stage
, ¶m
);
65 pass
= piglit_check_gl_error(GL_INVALID_ENUM
) && pass
;
66 } else if (param
!= expected
) {
67 fprintf(stderr
, "Failed to get program of stage %s.\n",
68 piglit_get_gl_enum_name(stage
));
74 use_stage_and_check(GLint pipe
, GLint program
, GLint stage
, bool supported
)
76 printf("Attach program (%d) to stage (%s). Expected to be "
79 piglit_get_gl_enum_name(stage
),
80 supported
? "yes" : "no");
82 glUseProgramStages(pipe
, stage2bitfield(stage
), program
);
84 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
86 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
89 check_stage(pipe
, program
, stage
, supported
);
93 piglit_init(int argc
, char **argv
)
95 GLint vs
, fs
, gs
, tcs
, tes
;
100 const char *shader_source
[2];
102 static const char vs_source
[] =
103 "#if __VERSION__ > 140\n"
104 "out gl_PerVertex {\n"
105 " vec4 gl_Position;\n"
108 "in vec4 position;\n"
110 "varying vec4 position;\n"
115 " gl_Position = position;\n"
117 static const char fs_source
[] =
118 "#if __VERSION__ >= 420\n"
119 "layout(location = 0) out vec4 color;\n"
121 "#define color gl_FragColor\n"
125 " color = vec4(0.0, 1.0, 0.0, 0.0);\n"
127 static const char gs_source
[] =
128 "in gl_PerVertex {\n"
129 " vec4 gl_Position;\n"
132 "out gl_PerVertex {\n"
133 " vec4 gl_Position;\n"
136 "layout(triangles) in;\n"
137 "layout(triangle_strip, max_vertices = 3) out;\n"
139 " for(int i = 0; i < gl_in.length(); i++) {\n"
140 " gl_Position = gl_in[i].gl_Position;\n"
145 static const char tc_source
[] =
146 "#extension GL_ARB_tessellation_shader: require\n"
147 "in gl_PerVertex {\n"
148 " vec4 gl_Position;\n"
151 "out gl_PerVertex {\n"
152 " vec4 gl_Position;\n"
155 "layout(vertices = 3) out;\n"
158 " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
159 " gl_TessLevelOuter[0] = 1.0;\n"
160 " gl_TessLevelOuter[1] = 1.0;\n"
161 " gl_TessLevelOuter[2] = 1.0;\n"
162 " gl_TessLevelInner[0] = 1.0;\n"
163 " gl_TessLevelInner[1] = 1.0;\n"
165 static const char te_source
[] =
166 "#extension GL_ARB_tessellation_shader: require\n"
167 "in gl_PerVertex {\n"
168 " vec4 gl_Position;\n"
171 "out gl_PerVertex {\n"
172 " vec4 gl_Position;\n"
175 "layout(triangles, equal_spacing) in;\n"
179 " vec4 p0 = gl_in[0].gl_Position;\n"
180 " vec4 p1 = gl_in[1].gl_Position;\n"
181 " vec4 p2 = gl_in[2].gl_Position;\n"
183 " vec3 p = gl_TessCoord.xyz;\n"
185 " gl_Position = p0*p.x + p1*p.y + p2*p.z;\n"
187 const bool has_gs
= piglit_get_gl_version() >= 32;
188 const bool has_tess
= piglit_get_gl_version() >= 40
189 || piglit_is_extension_supported("GL_ARB_tessellation_shader");
191 piglit_require_extension("GL_ARB_separate_shader_objects");
195 if (piglit_get_gl_version() >= 43) {
197 } else if (piglit_get_gl_version() >= 32) {
203 (void)!asprintf(&version
,
205 "#extension GL_ARB_separate_shader_objects: enable\n\n",
208 shader_source
[0] = version
;
210 shader_source
[1] = tc_source
;
211 tcs
= glCreateShaderProgramv(GL_TESS_CONTROL_SHADER
, 2,
213 pass
= piglit_link_check_status(tcs
) && pass
;
215 shader_source
[1] = te_source
;
216 tes
= glCreateShaderProgramv(GL_TESS_EVALUATION_SHADER
, 2,
218 pass
= piglit_link_check_status(tes
) && pass
;
225 shader_source
[1] = gs_source
;
226 gs
= glCreateShaderProgramv(GL_GEOMETRY_SHADER
, 2,
228 pass
= piglit_link_check_status(gs
) && pass
;
233 shader_source
[1] = fs_source
;
234 fs
= glCreateShaderProgramv(GL_FRAGMENT_SHADER
, 2, shader_source
);
235 pass
= piglit_link_check_status(fs
) && pass
;
237 shader_source
[1] = vs_source
;
238 vs
= glCreateShaderProgramv(GL_VERTEX_SHADER
, 2, shader_source
);
239 pass
= piglit_link_check_status(vs
) && pass
;
241 glGenProgramPipelines(1, &pipe
);
242 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
244 glActiveShaderProgram(pipe
, fs
);
245 glGetProgramPipelineiv(pipe
, GL_ACTIVE_PROGRAM
, ¶m
);
247 fprintf(stderr
, "Failed to get Active Program.\n");
250 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
252 use_stage_and_check(pipe
, vs
, GL_VERTEX_SHADER
, true);
253 use_stage_and_check(pipe
, fs
, GL_FRAGMENT_SHADER
, true);
254 use_stage_and_check(pipe
, gs
, GL_GEOMETRY_SHADER
, has_gs
);
255 use_stage_and_check(pipe
, tes
, GL_TESS_EVALUATION_SHADER
, has_tess
);
256 use_stage_and_check(pipe
, tcs
, GL_TESS_CONTROL_SHADER
, has_tess
);
258 glActiveShaderProgram(pipe
, vs
);
259 glGetProgramPipelineiv(pipe
, GL_ACTIVE_PROGRAM
, ¶m
);
261 fprintf(stderr
, "Failed to get Active Program.\n");
264 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
267 glUseProgramStages(pipe
, GL_ALL_SHADER_BITS
, 0);
268 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
270 check_stage(pipe
, 0, GL_VERTEX_SHADER
, true);
271 check_stage(pipe
, 0, GL_FRAGMENT_SHADER
, true);
272 check_stage(pipe
, 0, GL_GEOMETRY_SHADER
, has_gs
);
273 check_stage(pipe
, 0, GL_TESS_EVALUATION_SHADER
, has_tess
);
274 check_stage(pipe
, 0, GL_TESS_CONTROL_SHADER
, has_tess
);
278 piglit_present_results();
279 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);