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
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
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"
44 " gl_Position = vec4(piglit_vertex, 0.0, 1.0);\n"
47 static const char fs_source
[] =
50 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
54 target_to_str(GLenum target
)
57 case GL_TIME_ELAPSED_EXT
:
58 return "GL_TIME_ELAPSED_EXT";
59 case GL_TIMESTAMP_EXT
:
60 return "GL_TIMESTAMP_EXT";
66 static enum piglit_result
67 bits_query(GLenum target
)
70 glGetQueryivEXT(target
, GL_QUERY_COUNTER_BITS_EXT
, &bits
);
71 if (!piglit_check_gl_error(GL_NO_ERROR
))
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
);
79 printf("bits query for %s got %d bits\n", target_to_str(target
), bits
);
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
,
121 if (current
!= query
)
122 piglit_report_result(PIGLIT_FAIL
);
124 GLint prog
= piglit_build_simple_program(vs_source
, fs_source
);
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 */
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
);
162 piglit_init(int argc
, char **argv
)
164 piglit_require_extension("GL_EXT_disjoint_timer_query");