[Piglit] [PATCH 2/2] timestamp-get: test glGet(GL_TIMESTAMP)

Marek Olšák maraeo at gmail.com
Tue Jun 26 18:10:59 PDT 2012


---
 tests/all.tests                              |    1 +
 tests/spec/CMakeLists.txt                    |    1 +
 tests/spec/arb_timer_query/CMakeLists.gl.txt |   14 +++
 tests/spec/arb_timer_query/CMakeLists.txt    |    1 +
 tests/spec/arb_timer_query/timestamp-get.c   |  143 ++++++++++++++++++++++++++
 5 files changed, 160 insertions(+)
 create mode 100644 tests/spec/arb_timer_query/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_timer_query/CMakeLists.txt
 create mode 100644 tests/spec/arb_timer_query/timestamp-get.c

diff --git a/tests/all.tests b/tests/all.tests
index a4a899f..a44a6ca 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1605,6 +1605,7 @@ ext_timer_query['time-elapsed'] = concurrent_test('ext_timer_query-time-elapsed'
 arb_timer_query = Group()
 spec['ARB_timer_query'] = arb_timer_query
 arb_timer_query['query GL_TIMESTAMP'] = concurrent_test('ext_timer_query-time-elapsed timestamp')
+arb_timer_query['timestamp-get'] = concurrent_test('arb_timer_query-timestamp-get')
 
 ext_transform_feedback = Group()
 spec['EXT_transform_feedback'] = ext_transform_feedback
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 317548a..09ea171 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -19,6 +19,7 @@ add_subdirectory (arb_texture_buffer_object)
 add_subdirectory (arb_texture_compression)
 add_subdirectory (arb_texture_float)
 add_subdirectory (arb_texture_storage)
+add_subdirectory (arb_timer_query)
 add_subdirectory (arb_transform_feedback2)
 add_subdirectory (ati_envmap_bumpmap)
 add_subdirectory (ext_fog_coord)
diff --git a/tests/spec/arb_timer_query/CMakeLists.gl.txt b/tests/spec/arb_timer_query/CMakeLists.gl.txt
new file mode 100644
index 0000000..afabed7
--- /dev/null
+++ b/tests/spec/arb_timer_query/CMakeLists.gl.txt
@@ -0,0 +1,14 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+	piglitutil
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+)
+
+IF (UNIX)
+   piglit_add_executable (arb_timer_query-timestamp-get timestamp-get.c)
+ENDIF (UNIX)
diff --git a/tests/spec/arb_timer_query/CMakeLists.txt b/tests/spec/arb_timer_query/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_timer_query/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_timer_query/timestamp-get.c b/tests/spec/arb_timer_query/timestamp-get.c
new file mode 100644
index 0000000..3e5a074
--- /dev/null
+++ b/tests/spec/arb_timer_query/timestamp-get.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright © 2012 Marek Olšák <maraeo at gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "piglit-util.h"
+#include <unistd.h>
+#include <sys/time.h>
+
+/**
+ * @file timestamp-get.c
+ *
+ * Test that GL_TIMESTAMP obtained via glGet and glQuery returns roughly
+ * the same value.
+ */
+
+PIGLIT_GL_TEST_MAIN(
+    128 /*window_width*/,
+    128 /*window_height*/,
+    GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA)
+
+static GLint64
+get_gpu_time_via_query(GLuint q)
+{
+	GLint64 time;
+
+	glQueryCounter(q, GL_TIMESTAMP);
+	glGetQueryObjecti64v(q, GL_QUERY_RESULT, &time);
+	return time;
+}
+
+static GLint64
+get_gpu_time_via_get(GLuint q)
+{
+	GLint64 time;
+
+	glGetInteger64v(GL_TIMESTAMP, &time);
+	return time;
+}
+
+static GLint64
+get_cpu_time()
+{
+	struct timeval tv;
+
+	gettimeofday(&tv, 0);
+	return (GLint64)tv.tv_sec * 1000000000 + (GLint64)tv.tv_usec * 1000;
+}
+
+static void
+validate_times(GLint64 t1, GLint64 t2, GLint64 tolerance)
+{
+	if (t1 > t2) {
+		printf("old time = %llu us\n", t1 / 1000);
+		printf("new time = %llu us\n", t2 / 1000);
+		puts("old time > new time");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	/* the tolerance of 1 milisecond seems to be sufficient */
+	if (t2 - t1 > tolerance) {
+		printf("time 1 = %llu us\n", t1 / 1000);
+		printf("time 2 = %llu us\n", t2 / 1000);
+		puts("too big difference");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLint64 t1, t2;
+	GLint64 query_overhead, get_overhead, tolerance;
+	GLuint q;
+
+	glGenQueries(1, &q);
+
+	/* this creates the query in the driver */
+	get_gpu_time_via_query(q);
+
+	/* compute a reasonable tolerance based on driver overhead */
+	t1 = get_cpu_time();
+	get_gpu_time_via_query(q);
+	query_overhead = get_cpu_time() - t1;
+
+	t1 = get_cpu_time();
+	get_gpu_time_via_get(q);
+	get_overhead = get_cpu_time() - t1;
+
+	printf("glGet overhead: %llu us\n", get_overhead / 1000);
+	printf("glQuery overhead: %llu us\n", query_overhead / 1000);
+
+	/* minimum tolerance is 3 ms */
+	tolerance = query_overhead + get_overhead + 3000000;
+
+	/* do testing */
+	puts("Test: first glQuery, then glGet");
+	t1 = get_gpu_time_via_query(q);
+	t2 = get_gpu_time_via_get(q);
+	validate_times(t1, t2, tolerance);
+
+	usleep(10000);
+
+	puts("Test: first glGet, then glQuery");
+	t1 = get_gpu_time_via_get(q);
+	t2 = get_gpu_time_via_query(q);
+	validate_times(t1, t2, tolerance);
+
+	glDeleteQueries(1, &q);
+
+	return PIGLIT_PASS;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_automatic = true;
+
+	if (piglit_get_gl_version() < 20) {
+		printf("Requires OpenGL 2.0\n");
+		piglit_report_result(PIGLIT_SKIP);
+	}
+
+	piglit_require_extension("GL_ARB_timer_query");
+}
-- 
1.7.9.5



More information about the Piglit mailing list