ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_separate_shader_objects / GetProgramPipelineiv.c
blob8f83be2c121261a8f8211b74fe237c57f06fbf5c
1 /*
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
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"
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
33 static bool pass;
35 enum piglit_result
36 piglit_display(void)
38 /* UNREACHED */
39 return PIGLIT_FAIL;
42 static GLbitfield
43 stage2bitfield(GLint stage)
45 switch (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;
52 default:
53 assert(!"Should not get here.");
54 return 0;
58 static void
59 check_stage(GLint pipe, GLint expected, GLint stage, bool supported)
61 GLint param = 0;
62 glGetProgramPipelineiv(pipe, stage, &param);
64 if (!supported) {
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));
69 pass = false;
73 static void
74 use_stage_and_check(GLint pipe, GLint program, GLint stage, bool supported)
76 printf("Attach program (%d) to stage (%s). Expected to be "
77 "supported: %s\n",
78 program,
79 piglit_get_gl_enum_name(stage),
80 supported ? "yes" : "no");
82 glUseProgramStages(pipe, stage2bitfield(stage), program);
83 if (!supported) {
84 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
85 } else {
86 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
89 check_stage(pipe, program, stage, supported);
92 void
93 piglit_init(int argc, char **argv)
95 GLint vs, fs, gs, tcs, tes;
96 GLint ver;
97 GLuint pipe = 0;
98 GLint param = 0;
99 char *version = NULL;
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"
106 "};\n"
107 "\n"
108 "in vec4 position;\n"
109 "#else\n"
110 "varying vec4 position;\n"
111 "#endif\n"
112 "\n"
113 "void main()\n"
114 "{\n"
115 " gl_Position = position;\n"
116 "}\n";
117 static const char fs_source[] =
118 "#if __VERSION__ >= 420\n"
119 "layout(location = 0) out vec4 color;\n"
120 "#else\n"
121 "#define color gl_FragColor\n"
122 "#endif\n"
123 "void main()\n"
124 "{\n"
125 " color = vec4(0.0, 1.0, 0.0, 0.0);\n"
126 "}\n";
127 static const char gs_source[] =
128 "in gl_PerVertex {\n"
129 " vec4 gl_Position;\n"
130 "} gl_in[];\n"
131 "\n"
132 "out gl_PerVertex {\n"
133 " vec4 gl_Position;\n"
134 "};\n"
135 "\n"
136 "layout(triangles) in;\n"
137 "layout(triangle_strip, max_vertices = 3) out;\n"
138 "void main() {\n"
139 " for(int i = 0; i < gl_in.length(); i++) {\n"
140 " gl_Position = gl_in[i].gl_Position;\n"
141 " EmitVertex();\n"
142 " }\n"
143 " EndPrimitive();\n"
144 "}\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"
149 "} gl_in[];\n"
150 "\n"
151 "out gl_PerVertex {\n"
152 " vec4 gl_Position;\n"
153 "} gl_out[];\n"
154 "\n"
155 "layout(vertices = 3) out;\n"
156 "void main()\n"
157 "{\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"
164 "}\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"
169 "} gl_in[];\n"
170 "\n"
171 "out gl_PerVertex {\n"
172 " vec4 gl_Position;\n"
173 "};\n"
174 "\n"
175 "layout(triangles, equal_spacing) in;\n"
176 "\n"
177 "void main()\n"
178 "{\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"
182 "\n"
183 " vec3 p = gl_TessCoord.xyz;\n"
184 "\n"
185 " gl_Position = p0*p.x + p1*p.y + p2*p.z;\n"
186 "}\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");
193 pass = true;
195 if (piglit_get_gl_version() >= 43) {
196 ver = 430;
197 } else if (piglit_get_gl_version() >= 32) {
198 ver = 150;
199 } else {
200 ver = 110;
203 (void)!asprintf(&version,
204 "#version %d\n"
205 "#extension GL_ARB_separate_shader_objects: enable\n\n",
206 ver);
208 shader_source[0] = version;
209 if (has_tess) {
210 shader_source[1] = tc_source;
211 tcs = glCreateShaderProgramv(GL_TESS_CONTROL_SHADER, 2,
212 shader_source);
213 pass = piglit_link_check_status(tcs) && pass;
215 shader_source[1] = te_source;
216 tes = glCreateShaderProgramv(GL_TESS_EVALUATION_SHADER, 2,
217 shader_source);
218 pass = piglit_link_check_status(tes) && pass;
219 } else {
220 tcs = 0;
221 tes = 0;
224 if (has_gs) {
225 shader_source[1] = gs_source;
226 gs = glCreateShaderProgramv(GL_GEOMETRY_SHADER, 2,
227 shader_source);
228 pass = piglit_link_check_status(gs) && pass;
229 } else {
230 gs = 0;
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, &param);
246 if (param != fs) {
247 fprintf(stderr, "Failed to get Active Program.\n");
248 pass = false;
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, &param);
260 if (param != vs) {
261 fprintf(stderr, "Failed to get Active Program.\n");
262 pass = false;
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);
276 free(version);
278 piglit_present_results();
279 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);