ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_uniform_buffer_object / referenced-by-shader.c
blob1d3723a283c1de27674b51f5b8372532da787efd
1 /*
2 * Copyright © 2012, 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
21 * DEALINGS IN THE SOFTWARE.
24 /** @file referenced-by-shader.c
26 * From the GL_ARB_uniform_buffer_object spec and
27 * Section 2.11.4(Uniform Variables) of OpenGL 3.2 Core:
29 * "If <pname> is UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER,
30 * UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER, or
31 * UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER, then a boolean
32 * value indicating whether the uniform block identified by
33 * <uniformBlockIndex> is referenced by the vertex, geometry, or
34 * fragment programming stage of <program>, respectively, is
35 * returned."
38 #include "piglit-util-gl.h"
40 PIGLIT_GL_TEST_CONFIG_BEGIN
42 config.supports_gl_compat_version = 10;
43 config.supports_gl_core_version = 31;
44 config.khr_no_error_support = PIGLIT_NO_ERRORS;
46 PIGLIT_GL_TEST_CONFIG_END
48 void
49 piglit_init(int argc, char **argv)
51 bool pass = true;
52 unsigned int i;
53 GLuint vs, gs, fs, prog;
54 const char *vs_source =
55 "%s"
56 "uniform vs { float v; };\n"
57 "uniform vsgs { float vg; };\n"
58 "uniform vsfs { float vf; };\n"
59 "uniform vsgsfs { float vgf; };\n"
60 "void main() {\n"
61 " gl_Position = vec4(v + vg + vf + vgf);\n"
62 "}\n";
64 const char *gs_source =
65 "%s"
66 "layout(triangles) in;\n"
67 "layout(triangle_strip, max_vertices=3) out;\n"
68 "uniform gs { float g; };\n"
69 "uniform vsgs { float vg; };\n"
70 "uniform gsfs { float gf; };\n"
71 "uniform vsgsfs { float vgf; };\n"
72 "void main() {\n"
73 " for(int i = 0; i < 3; i++) {\n"
74 " gl_Position = vec4(g + vg + gf + vgf);\n"
75 " EmitVertex();\n"
76 " }\n"
77 "}\n";
79 const char *fs_source =
80 "%s"
81 "uniform fs { float f; };\n"
82 "uniform vsfs { float vf; };\n"
83 "uniform gsfs { float gf; };\n"
84 "uniform vsgsfs { float vgf; };\n"
85 "void main() {\n"
86 " gl_FragColor = vec4(f + vf + gf + vgf);\n"
87 "}\n";
89 char name[10];
90 bool use_gs = piglit_get_gl_version() >= 32;
91 const char *header;
92 char *temp_source;
93 int num_uniforms_used = 0;
95 if (use_gs) {
96 header = "#version 150\n";
97 } else {
98 header = "#extension GL_ARB_uniform_buffer_object : enable\n";
99 piglit_require_extension("GL_ARB_uniform_buffer_object");
102 prog = glCreateProgram();
104 (void)!asprintf(&temp_source, vs_source, header);
105 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, temp_source);
106 glAttachShader(prog, vs);
107 free(temp_source);
109 if (use_gs) {
110 (void)!asprintf(&temp_source, gs_source, header);
111 gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, temp_source);
112 glAttachShader(prog, gs);
113 free(temp_source);
116 (void)!asprintf(&temp_source, fs_source, header);
117 fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, temp_source);
118 glAttachShader(prog, fs);
119 free(temp_source);
121 glLinkProgram(prog);
122 if (!piglit_link_check_status(prog)) {
123 piglit_report_result(PIGLIT_FAIL);
126 if (use_gs) {
127 num_uniforms_used = 7;
128 printf(" v g f\n");
129 } else {
130 num_uniforms_used = 6;
131 printf(" v f\n");
134 for (i = 0; i < num_uniforms_used; i++) {
135 GLint ref_vs = 0, ref_gs = 0, ref_fs = 0;
136 bool block_fail = false;
138 glGetActiveUniformBlockName(prog, i, sizeof(name), NULL, name);
140 glGetActiveUniformBlockiv(prog, i,
141 GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER,
142 &ref_vs);
143 if (use_gs) {
144 glGetActiveUniformBlockiv(prog, i,
145 GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER,
146 &ref_gs);
148 glGetActiveUniformBlockiv(prog, i,
149 GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER,
150 &ref_fs);
152 if (use_gs) {
153 printf("%10s: %d %d %d", name, ref_vs, ref_gs, ref_fs);
154 } else {
155 printf("%10s: %d %d", name, ref_vs, ref_fs);
158 if ((strstr(name, "vs") != 0) != ref_vs)
159 block_fail = true;
160 if (use_gs) {
161 if ((strstr(name, "gs") != 0) != ref_gs)
162 block_fail = true;
164 if ((strstr(name, "fs") != 0) != ref_fs)
165 block_fail = true;
167 if (block_fail) {
168 printf(" FAIL");
169 pass = false;
172 printf("\n");
175 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
178 enum piglit_result piglit_display(void)
180 /* UNREACHED */
181 return PIGLIT_FAIL;