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
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
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
49 piglit_init(int argc
, char **argv
)
53 GLuint vs
, gs
, fs
, prog
;
54 const char *vs_source
=
56 "uniform vs { float v; };\n"
57 "uniform vsgs { float vg; };\n"
58 "uniform vsfs { float vf; };\n"
59 "uniform vsgsfs { float vgf; };\n"
61 " gl_Position = vec4(v + vg + vf + vgf);\n"
64 const char *gs_source
=
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"
73 " for(int i = 0; i < 3; i++) {\n"
74 " gl_Position = vec4(g + vg + gf + vgf);\n"
79 const char *fs_source
=
81 "uniform fs { float f; };\n"
82 "uniform vsfs { float vf; };\n"
83 "uniform gsfs { float gf; };\n"
84 "uniform vsgsfs { float vgf; };\n"
86 " gl_FragColor = vec4(f + vf + gf + vgf);\n"
90 bool use_gs
= piglit_get_gl_version() >= 32;
93 int num_uniforms_used
= 0;
96 header
= "#version 150\n";
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
);
110 (void)!asprintf(&temp_source
, gs_source
, header
);
111 gs
= piglit_compile_shader_text(GL_GEOMETRY_SHADER
, temp_source
);
112 glAttachShader(prog
, gs
);
116 (void)!asprintf(&temp_source
, fs_source
, header
);
117 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, temp_source
);
118 glAttachShader(prog
, fs
);
122 if (!piglit_link_check_status(prog
)) {
123 piglit_report_result(PIGLIT_FAIL
);
127 num_uniforms_used
= 7;
130 num_uniforms_used
= 6;
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
,
144 glGetActiveUniformBlockiv(prog
, i
,
145 GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER
,
148 glGetActiveUniformBlockiv(prog
, i
,
149 GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER
,
153 printf("%10s: %d %d %d", name
, ref_vs
, ref_gs
, ref_fs
);
155 printf("%10s: %d %d", name
, ref_vs
, ref_fs
);
158 if ((strstr(name
, "vs") != 0) != ref_vs
)
161 if ((strstr(name
, "gs") != 0) != ref_gs
)
164 if ((strstr(name
, "fs") != 0) != ref_fs
)
175 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
178 enum piglit_result
piglit_display(void)