1 /*
2 * Copyright © 2014 Intel Corporation
3 *
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:
10 *
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.
14 *
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.
22 */
23
24 /** \file pipeline_stats_extra_prims.c
25 *
26 * GL_ARB_pipeline_statistics_query says:
27 *
28 * (23) How do operations like Clear, TexSubImage, etc. affect the results of
29 * the newly introduced queries?
30 *
31 * DISCUSSION: Implementations might require "helper" rendering commands be
32 * issued to implement certain operations like Clear, TexSubImage, etc.
33 *
34 * RESOLVED: They don't. Only application submitted rendering commands
35 * should have an effect on the results of the queries.
36 *
37 * This test tries to provoke extra primitives.
38 */
39
40 #include "piglit-util-gl.h"
41 #include "pipestat_help.h"
42
43 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config.supports_gl_compat_version = 30;
45 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
46 PIGLIT_GL_TEST_CONFIG_END
47
48 static const char *vs_src =
49 "#version 130 \n"
50 " \n"
51 "in vec4 piglit_vertex; \n"
52 "void main() \n"
53 "{ \n"
54 " gl_Position = piglit_vertex;\n"
55 "} \n";
56
57 static const char *fs_src =
58 "#version 110 \n"
59 " \n"
60 "void main() \n"
61 "{ \n"
62 " gl_FragColor = vec4(0, 1, 0, 1); \n"
63 "} \n";
64
65 static struct query queries[] = {
66 {
67 .query = GL_PRIMITIVES_SUBMITTED_ARB,
68 .min = 3 /* Going to emit three lines */
69 },
70 };
71
72 /* Some random line vertices. The values really don't matter. */
73 static const float vertex_data[] = {
74 0.2f, 0.5f, 0.0f, 1.0f, /* Vert 0 */
75 0.8f, 0.5f, 0.0f, 1.0f, /* Vert 1 */
76 };
77
78 static void
draw(void)79 draw(void)
80 {
81 glDrawArrays(GL_LINES, 0, 2);
82
83 /* Perform a partial overwrite of the vertex buffer used by the
84 * previous draw call, to try and provoke a staging blit which may
85 * emit an extra primitive.
86 */
87 glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_data) / 2,
88 vertex_data);
89
90 glDrawArrays(GL_LINES, 0, 2);
91
92 /* Ensure clears aren't counted. */
93 glClear(GL_COLOR_BUFFER_BIT);
94
95 glDrawArrays(GL_LINES, 0, 2);
96
97 #ifdef DISPLAY
98 piglit_present_results();
99 #endif
100 }
101
102 enum piglit_result
piglit_display(void)103 piglit_display(void)
104 {
105 return do_query_func(queries, ARRAY_SIZE(queries), draw);
106 }
107
108 void
piglit_init(int argc,char * argv[])109 piglit_init(int argc, char *argv[])
110 {
111 GLuint prog, array, buf;
112
113 glGenVertexArrays(1, &array);
114 glBindVertexArray(array);
115 glGenBuffers(1, &buf);
116 glBindBuffer(GL_ARRAY_BUFFER, buf);
117
118 prog = piglit_build_simple_program(vs_src, fs_src);
119
120 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data,
121 GL_STREAM_DRAW);
122
123 glVertexAttribPointer(0, /* index */
124 4, /* size */
125 GL_FLOAT, /* type */
126 GL_FALSE, /* normalized */
127 0, /* stride */
128 NULL /* pointer */);
129 glEnableVertexAttribArray(0);
130
131 #ifndef DISPLAY
132 glEnable(GL_RASTERIZER_DISCARD);
133 #endif
134
135 do_query_init(queries, ARRAY_SIZE(queries));
136
137 if (!piglit_link_check_status(prog)) {
138 glDeleteProgram(prog);
139 piglit_report_result(PIGLIT_FAIL);
140 }
141
142 glUseProgram(prog);
143 }
144