ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / arb_pipeline_statistics_query / pipeline_stats_geom.c
blob3b165a52cffde753c3c50b845dd67fd3b5c61956
1 /*
2 * Copyright © 2014 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 /** \file pipeline_stats_geom.c
26 * This test verifies that the vertex shader related tokens of
27 * ARB_pipeline_statistics_query() work as expected. OpenGL 4.4 Specification,
28 * Core Profile.
30 * When BeginQuery is called with a target of GEOMETRY_SHADER_INVOCATIONS,
31 * the geometry shader invocations count maintained by the GL is set to zero.
32 * When a geometry shader invocations query is active, the counter is
33 * incremented every time the geometry shader is invoked (see section 11.3).
34 * In case of instanced geometry shaders (see section 11.3.4.2) the geometry
35 * shader invocations count is incremented for each separate instanced
36 * invocation.
38 * When BeginQuery is called with a target of GEOMETRY_SHADER_PRIMITIVES_-
39 * EMITTED_ARB, the geometry shader output primitives count maintained by the
40 * GL is set to zero. When a geometry shader primitives emitted query is
41 * active, the counter is incremented every time the geometry shader emits
42 * a primitive to a vertex stream that is further processed by the GL (see
43 * section 11.3.2). Restarting primitive topology using the shading language
44 * built-in functions EndPrimitive or EndStreamPrimitive does not increment
45 * the geometry shader output primitives count.
47 * (The chicken clause)
48 * The result of geometry shader queries may be implementation dependent due
49 * to reasons described in section 11.1.3.
52 #include "piglit-util-gl.h"
53 #include "pipestat_help.h"
55 PIGLIT_GL_TEST_CONFIG_BEGIN
56 config.supports_gl_core_version = 32;
57 config.supports_gl_compat_version = 32;
58 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
59 PIGLIT_GL_TEST_CONFIG_END
61 const char *vs_src =
62 "#version 150 \n"
63 "in vec4 piglit_vertex; \n"
64 "out vec4 vertex_to_gs; \n"
65 "void main() \n"
66 "{ \n"
67 " vertex_to_gs = piglit_vertex;\n"
68 "} \n";
70 const char *gs_src =
71 "#version 150 \n"
72 "layout(triangles) in; \n"
73 "layout(triangle_strip, max_vertices = 6) out; \n"
74 "in vec4 vertex_to_gs[3]; \n"
75 "void main() \n"
76 "{ \n"
77 " for (int i = 0; i < 6; i++) { \n"
78 " gl_Position = vertex_to_gs[i % 3]; \n"
79 " EmitVertex(); \n"
80 " } \n"
81 "} \n";
84 #ifdef DISPLAY
85 const char *fs_src =
86 "#version 150 \n"
87 "out vec4 color; \n"
88 "void main() \n"
89 "{ \n"
90 " color = vec4(0.0, 1.0, 0.0, 1.0); \n"
91 "} \n";
92 #endif
94 static struct query queries[] = {
96 .query = GL_GEOMETRY_SHADER_INVOCATIONS,
97 .min = NUM_PRIMS,
98 .max = NUM_PRIMS},
100 /* There are going to be NUM_PRIMS invocations, and for each invocation
101 * we're going to write 6 vertices in a tristrip, which is 4 triangles.
102 * So NUM_PRIMS * 4 is what we expect here */
104 .query = GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB,
105 .min = NUM_PRIMS * 4,
106 .max = NUM_PRIMS * 4}
109 enum piglit_result
110 piglit_display(void)
112 enum piglit_result ret = do_query(queries, ARRAY_SIZE(queries));
113 #ifdef DISPLAY
114 piglit_present_results();
115 #endif
116 return ret;
119 void
120 piglit_init(int argc, char *argv[])
122 GLuint vs, gs, prog;
124 do_query_init(queries, ARRAY_SIZE(queries));
126 prog = glCreateProgram();
128 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_src);
129 gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_src);
131 #ifndef DISPLAY
132 glEnable(GL_RASTERIZER_DISCARD);
133 #else
134 glAttachShader(prog,
135 piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_src));
136 #endif
138 glAttachShader(prog, vs);
139 glAttachShader(prog, gs);
140 glLinkProgram(prog);
142 if (!piglit_link_check_status(prog)) {
143 glDeleteProgram(prog);
144 piglit_report_result(PIGLIT_FAIL);
147 glUseProgram(prog);