ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_separate_shader_objects / rendezvous_by_location.c
blobc9c673a5413da0f013f7d4d586010907aa2fb633
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 /**
25 * \file rendezvous_by_location.c
26 * Simple test for separate shader objects that use rendezvous-by-location.
28 * There are two ways one might expect rendezvous-by-location to fail. One
29 * predicatble failure mode is for variables between two program objects to be
30 * linked in the order they appear in the shader text. Another predicatble
31 * failure mode is for variables between two program objects to be linked by
32 * name.
34 * This test tries both modes using a single fragement shader program. This
35 * program outputs two varibles, a and b, with locations specified. Two
36 * fragment shader programs are created, each having input variables a and b,
37 * with locations specified. In the first case, a and b are listed in the
38 * same order as in the vertex shader, but the locations are reversed (vertex
39 * shader output a has the location of fragment shader input b). In the
40 * second case, a and b are list in the reverse order as in the vertex shader.
41 * However, the assigned locations are the same as in the other fragment
42 * shader.
44 #include "piglit-util-gl.h"
45 #include "sso-common.h"
47 PIGLIT_GL_TEST_CONFIG_BEGIN
49 config.supports_gl_compat_version = 10;
50 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
52 PIGLIT_GL_TEST_CONFIG_END
54 static GLuint pipeline_same_declaration_order;
55 static GLuint pipeline_same_location_order;
57 static const char *vs_code_template =
58 "#version %d\n"
59 "#extension GL_ARB_separate_shader_objects: require\n"
60 "#extension GL_ARB_explicit_attrib_location: require\n"
61 "\n"
62 "layout(location = 0) in vec4 piglit_vertex;\n"
63 "\n"
64 "layout(location = 2) out vec3 a;\n"
65 "layout(location = 3) out vec3 b;\n"
66 "\n"
67 "void main()\n"
68 "{\n"
69 " gl_Position = piglit_vertex;\n"
70 " a = vec3(0, 0, 1);\n"
71 " b = vec3(1, 0, 0);\n"
72 "}\n"
75 static const char *fs_code_same_declaration_order_template =
76 "#version %d\n"
77 "#extension GL_ARB_separate_shader_objects: require\n"
78 "#extension GL_ARB_explicit_attrib_location: enable\n"
79 "\n"
80 "#if __VERSION__ >= 130\n"
81 "layout(location = 0) out vec4 out_color;\n"
82 "#else\n"
83 "#define out_color gl_FragColor\n"
84 "#endif\n"
85 "\n"
86 "layout(location = 3) in vec3 a; /* should get vec3(1, 0, 0) */\n"
87 "layout(location = 2) in vec3 b; /* should get vec3(0, 0, 1) */\n"
88 "\n"
89 "void main()\n"
90 "{\n"
91 " out_color = vec4(cross(b, a), 1);\n"
92 "}\n"
95 static const char *fs_code_same_location_order_template =
96 "#version %d\n"
97 "#extension GL_ARB_separate_shader_objects: require\n"
98 "#extension GL_ARB_explicit_attrib_location: enable\n"
99 "\n"
100 "#if __VERSION__ >= 130\n"
101 "layout(location = 0) out vec4 out_color;\n"
102 "#else\n"
103 "#define out_color gl_FragColor\n"
104 "#endif\n"
105 "\n"
106 "layout(location = 2) in vec3 b; /* should get vec3(0, 0, 1) */\n"
107 "layout(location = 3) in vec3 a; /* should get vec3(1, 0, 0) */\n"
108 "\n"
109 "void main()\n"
110 "{\n"
111 " out_color = vec4(cross(b, a), 1);\n"
112 "}\n"
115 enum piglit_result
116 piglit_display(void)
118 static const float expected[] = {
119 0.0f, 1.0f, 0.0f, 1.0f
121 bool pass;
123 glClearColor(0.1f, 0.1f, 0.1f, 0.1f);
124 glClear(GL_COLOR_BUFFER_BIT);
126 glBindProgramPipeline(pipeline_same_declaration_order);
127 piglit_draw_rect(-1, -1, 1, 2);
129 glBindProgramPipeline(pipeline_same_location_order);
130 piglit_draw_rect(0, -1, 1, 2);
131 pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
132 expected);
134 piglit_present_results();
135 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
138 void piglit_init(int argc, char **argv)
140 unsigned glsl_version;
141 GLuint vs_prog;
142 GLuint fs_prog_same_declaration_order;
143 GLuint fs_prog_same_location_order;
144 char *source;
145 bool pass = true;
147 piglit_require_vertex_shader();
148 piglit_require_fragment_shader();
149 piglit_require_extension("GL_ARB_separate_shader_objects");
150 piglit_require_extension("GL_ARB_explicit_attrib_location");
152 glsl_version = pick_a_glsl_version();
154 (void)!asprintf(&source, vs_code_template, glsl_version);
155 vs_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,
156 (const GLchar *const *) &source);
157 pass = piglit_link_check_status(vs_prog) && pass;
158 free(source);
160 (void)!asprintf(&source, fs_code_same_declaration_order_template, glsl_version);
161 fs_prog_same_declaration_order =
162 glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1,
163 (const GLchar *const *) &source);
164 pass = piglit_link_check_status(fs_prog_same_declaration_order) && pass;
165 free(source);
167 (void)!asprintf(&source, fs_code_same_location_order_template, glsl_version);
168 fs_prog_same_location_order =
169 glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1,
170 (const GLchar *const *) &source);
171 pass = piglit_link_check_status(fs_prog_same_location_order) && pass;
172 free(source);
174 glGenProgramPipelines(1, &pipeline_same_declaration_order);
175 glUseProgramStages(pipeline_same_declaration_order,
176 GL_VERTEX_SHADER_BIT,
177 vs_prog);
178 glUseProgramStages(pipeline_same_declaration_order,
179 GL_FRAGMENT_SHADER_BIT,
180 fs_prog_same_declaration_order);
181 piglit_program_pipeline_check_status(pipeline_same_declaration_order);
183 glGenProgramPipelines(1, &pipeline_same_location_order);
184 glUseProgramStages(pipeline_same_location_order,
185 GL_VERTEX_SHADER_BIT,
186 vs_prog);
187 glUseProgramStages(pipeline_same_location_order,
188 GL_FRAGMENT_SHADER_BIT,
189 fs_prog_same_location_order);
190 piglit_program_pipeline_check_status(pipeline_same_location_order);
192 pass = piglit_check_gl_error(0) && pass;
193 if (!pass)
194 piglit_report_result(PIGLIT_FAIL);