framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / ext_disjoint_timer_query / simple-query.c
blob17d054ce98902a7c1130e2dc1341e11cb1d97e07
1 /*
2 * Copyright © 2017 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
26 * Tests GL_EXT_disjoint_timer_query extension. Test does not to cover
27 * the whole API as that is tested throughly by existing query tests for
28 * desktop GL. Main objective is to test that timer queries work on OpenGL
29 * ES 2.0 and we can get GL_GPU_DISJOINT_EXT value from the driver.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_es_version = 20;
36 config.window_visual = PIGLIT_GL_VISUAL_RGBA;
37 PIGLIT_GL_TEST_CONFIG_END
39 static const char vs_source[] =
40 "attribute vec2 piglit_vertex;\n"
41 "\n"
42 "void main()\n"
43 "{\n"
44 " gl_Position = vec4(piglit_vertex, 0.0, 1.0);\n"
45 "}\n";
47 static const char fs_source[] =
48 "void main()\n"
49 "{\n"
50 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
51 "}\n";
53 static const char *
54 target_to_str(GLenum target)
56 switch (target) {
57 case GL_TIME_ELAPSED_EXT:
58 return "GL_TIME_ELAPSED_EXT";
59 case GL_TIMESTAMP_EXT:
60 return "GL_TIMESTAMP_EXT";
61 default:
62 return "";
66 static enum piglit_result
67 bits_query(GLenum target)
69 GLint bits;
70 glGetQueryivEXT(target, GL_QUERY_COUNTER_BITS_EXT, &bits);
71 if (!piglit_check_gl_error(GL_NO_ERROR))
72 return PIGLIT_FAIL;
73 /* Spec requires at least 30bits. */
74 if (bits > 0 && bits < 30) {
75 fprintf(stderr, "expected >= 30 bits for %s, got %d\n",
76 target_to_str(target), bits);
77 return PIGLIT_FAIL;
79 printf("bits query for %s got %d bits\n", target_to_str(target), bits);
80 return PIGLIT_PASS;
83 enum piglit_result
84 piglit_display(void)
86 GLuint query;
87 GLint current;
88 GLint64 disjoint;
89 GLuint64 time = 0;
91 if (bits_query(GL_TIME_ELAPSED_EXT) != PIGLIT_PASS)
92 piglit_report_result(PIGLIT_FAIL);
94 if (bits_query(GL_TIMESTAMP_EXT) != PIGLIT_PASS)
95 piglit_report_result(PIGLIT_FAIL);
97 glGenQueriesEXT(1, &query);
99 /* Clear disjoint error state. */
100 glGetInteger64vEXT(GL_GPU_DISJOINT_EXT, &disjoint);
101 if (!piglit_check_gl_error(GL_NO_ERROR))
102 piglit_report_result(PIGLIT_FAIL);
104 glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query);
106 /* "The error INVALID_OPERATION is generated if QueryCounterEXT is
107 * called on a query object that is already in use inside a
108 * BeginQueryEXT/EndQueryEXT."
110 glQueryCounterEXT(query, GL_TIMESTAMP_EXT);
112 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
113 piglit_report_result(PIGLIT_FAIL);
115 if (!glIsQueryEXT(query))
116 piglit_report_result(PIGLIT_FAIL);
118 glGetQueryivEXT(GL_TIME_ELAPSED_EXT, GL_CURRENT_QUERY_EXT,
119 &current);
121 if (current != query)
122 piglit_report_result(PIGLIT_FAIL);
124 GLint prog = piglit_build_simple_program(vs_source, fs_source);
125 glUseProgram(prog);
127 piglit_draw_rect(-1, -1, 2, 2);
129 glDeleteProgram(prog);
131 glEndQueryEXT(GL_TIME_ELAPSED_EXT);
133 glGetQueryObjectui64vEXT(query, GL_QUERY_RESULT_EXT, &time);
135 /* Check if disjoint operation occured. */
136 glGetInteger64vEXT(GL_GPU_DISJOINT_EXT, &disjoint);
137 if (!piglit_check_gl_error(GL_NO_ERROR))
138 piglit_report_result(PIGLIT_FAIL);
140 /* If no disjoint operation, then we should have a
141 * 'sensible value' in time, expecting more than 0.
143 if (disjoint == 0 && time <= 0)
144 piglit_report_result(PIGLIT_FAIL);
146 /* Finally, check that we are able to retrieve GL_TIMESTAMP_EXT */
147 GLint64 now_int64;
148 glGetInteger64v(GL_TIMESTAMP_EXT, &now_int64);
150 if (!piglit_check_gl_error(GL_NO_ERROR))
151 piglit_report_result(PIGLIT_FAIL);
153 glDeleteQueriesEXT(1, &query);
155 if (!piglit_check_gl_error(GL_NO_ERROR))
156 piglit_report_result(PIGLIT_FAIL);
158 return PIGLIT_PASS;
161 void
162 piglit_init(int argc, char **argv)
164 piglit_require_extension("GL_EXT_disjoint_timer_query");