[Piglit] [PATCH 9/9] Validate that SwapBuffers doesn't re-use an MSC.

Jamey Sharp jamey at minilop.net
Wed Apr 23 17:27:23 PDT 2014


From: TheoH <Theo0x48 at gmail.com>

This test checks that when swapbuffers is called multiple times without
WaitForSbc that the SBC is not incremented more often than the MSC.

Signed-off-by: Theo Hill <Theo0x48 at gmail.com>
Signed-off-by: Jamey Sharp <jamey at minilop.net>
---
 tests/all.py                                       |   4 +
 tests/spec/glx_oml_sync_control/CMakeLists.gl.txt  |   2 +
 .../spec/glx_oml_sync_control/repeat-swapbuffers.c | 143 +++++++++++++++++++++
 3 files changed, 149 insertions(+)
 create mode 100644 tests/spec/glx_oml_sync_control/repeat-swapbuffers.c

diff --git a/tests/all.py b/tests/all.py
index d610ce0..b87970d 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -795,6 +795,10 @@ oml_sync_control_nonzeros = [
 for arg in [[], ['-fullscreen']] + oml_sync_control_nonzeros:
     oml_sync_control[' '.join(['timing'] + arg)] = PiglitTest(['glx-oml-sync-control-timing'] + arg)
 
+oml_sync_control['repeat-swapbuffers'] = PiglitTest(['glx-oml-sync-control-repeat-swapbuffers'])
+oml_sync_control['repeat-swapbuffers -msc-delta 1'] = PiglitTest(['glx-oml-sync-control-repeat-swapbuffers', '-msc-delta', '1'])
+oml_sync_control['repeat-swapbuffers -msc-delta 5'] = PiglitTest(['glx-oml-sync-control-repeat-swapbuffers', '-msc-delta', '5'])
+
 mesa_query_renderer = {}
 glx['GLX_MESA_query_renderer'] = mesa_query_renderer
 mesa_query_renderer['coverage'] = concurrent_test('glx-query-renderer-coverage')
diff --git a/tests/spec/glx_oml_sync_control/CMakeLists.gl.txt b/tests/spec/glx_oml_sync_control/CMakeLists.gl.txt
index 125e2a5..9b02979 100644
--- a/tests/spec/glx_oml_sync_control/CMakeLists.gl.txt
+++ b/tests/spec/glx_oml_sync_control/CMakeLists.gl.txt
@@ -27,6 +27,8 @@ IF(PIGLIT_BUILD_GLX_TESTS)
 	piglit_add_executable (glx-oml-sync-control-swapbuffersmsc-return swapbuffersmsc-return.c common.c)
 	piglit_add_executable (glx-oml-sync-control-waitformsc waitformsc.c common.c)
 	piglit_add_executable (glx-oml-sync-control-timing timing.c common.c)
+	piglit_add_executable (glx-oml-sync-control-repeat-swapbuffers repeat-swapbuffers.c common.c)
+
 ENDIF(PIGLIT_BUILD_GLX_TESTS)
 
 # vim: ft=cmake:
diff --git a/tests/spec/glx_oml_sync_control/repeat-swapbuffers.c b/tests/spec/glx_oml_sync_control/repeat-swapbuffers.c
new file mode 100644
index 0000000..7339305
--- /dev/null
+++ b/tests/spec/glx_oml_sync_control/repeat-swapbuffers.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright © 2014 The TOVA Company
+ *
+ * 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.
+ */
+
+/**
+ * \file repeat-swapbuffers.c
+ * Verifies that glXSwapBuffersMscOML does not increment SBC more often than MSC
+ */
+
+#include "piglit-util-gl-common.h"
+#include "piglit-glx-util.h"
+#include "common.h"
+
+static int64_t target_msc_delta = 0;
+static const int64_t divisor = 0;
+static const int64_t msc_remainder = 0;
+static const unsigned int loops = 5;
+
+
+struct omlTriple {
+	int64_t ust;
+	int64_t msc;
+	int64_t sbc;
+};
+
+static double max(double a, double b)
+{
+	return a > b ? a : b;
+}
+
+static enum piglit_result
+draw(Display *dpy)
+{
+	struct omlTriple old = {.ust = 0xd0, .msc = 0xd0, .sbc = 0xd0};
+	struct omlTriple new = {.ust = 0xd0, .msc = 0xd0, .sbc = 0xd0};
+	int64_t target_sbc = 0;
+	int i;
+	int32_t rate_num, rate_den;
+	double timeout;
+
+	if (!glXGetMscRateOML(dpy, win, &rate_num, &rate_den)) {
+		timeout = 1.0 / 10; /* Assume MSC rate is at least 10Hz */
+	} else {
+		timeout = (double) rate_den / rate_num;
+	}
+
+	timeout *= loops * max(1, max(target_msc_delta, divisor));
+	piglit_set_timeout(timeout * 2, PIGLIT_FAIL); /* Safety factor 2 */
+
+	if (!glXGetSyncValuesOML(dpy, win, &old.ust, &old.msc, &old.sbc)) {
+		fprintf(stderr, "Initial glXGetSyncValuesOML failed\n");
+		return PIGLIT_FAIL;
+	}
+
+	old.msc -= 1;
+	for (i = 0; i < loops; ++i) {
+		int64_t target_msc = 0;
+		glClearColor(0.0, 1.0, 0.0, 0.0);
+		glClear(GL_COLOR_BUFFER_BIT);
+		glFlush();
+
+		if (target_msc_delta) {
+			target_msc = old.msc + target_msc_delta;
+		}
+
+		target_sbc = glXSwapBuffersMscOML(dpy, win, target_msc, divisor, msc_remainder);
+		if (target_sbc <= 0) {
+			fprintf(stderr, "glXSwapBuffersMscOML failed\n");
+			return PIGLIT_FAIL;
+		}
+		if (!glXGetSyncValuesOML(dpy, win, &new.ust, &new.msc, &new.sbc)) {
+			fprintf(stderr, "glXGetSyncValuesOML failed\n");
+			return PIGLIT_FAIL;
+		}
+
+		if (new.sbc - old.sbc > new.msc - old.msc) {
+			fprintf(stderr, "SBC incremented more than once per msc\n");
+			return PIGLIT_FAIL;
+		}
+		if (new.sbc > old.sbc) {
+			old = new;
+		}
+	}
+	return PIGLIT_PASS;
+}
+
+static unsigned int
+parse_num_arg(int argc, char **argv, int j)
+{
+	char *ptr;
+	unsigned int val;
+
+	if (j >= argc) {
+		fprintf(stderr, "%s requires an argument\n", argv[j - 1]);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	val = strtoul(argv[j], &ptr, 0);
+	if (!val || *ptr != '\0') {
+		fprintf(stderr, "%s requires an argument\n", argv[j - 1]);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	return val;
+}
+
+int
+main(int argc, char **argv)
+{
+	int j;
+	for (j = 1; j < argc; ++j) {
+		if (!strcmp(argv[j], "-msc-delta")) {
+			++j;
+			target_msc_delta = parse_num_arg(argc, argv, j);
+		} else {
+			fprintf(stderr, "unsupported option %s\n", argv[j]);
+			piglit_report_result(PIGLIT_FAIL);
+		}
+	}
+	piglit_automatic = true;
+	piglit_oml_sync_control_test_run(false, draw);
+
+	return 0;
+}
-- 
1.8.5.3



More information about the Piglit mailing list