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

Submitted by Jamey Sharp on April 24, 2014, 12:27 a.m.

Details

Message ID 1398299243-7543-10-git-send-email-jamey@minilop.net
State New
Headers show

Not browsing as part of any series.

Commit Message

Jamey Sharp April 24, 2014, 12:27 a.m.
From: TheoH <Theo0x48@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@gmail.com>
Signed-off-by: Jamey Sharp <jamey@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

Patch hide | download patch | download mbox

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;
+}

Comments

Jamey Sharp <jamey@minilop.net> writes:

> From: TheoH <Theo0x48@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.

> 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;
> +}

piglit-util.h has a MAX2 macro for you.

> +
> +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 */

This seems pretty restrictive.  I would not be surprised by a test going
to sleep for just 30ms on a busy system.  You just want to make sure
that it doesn't get stuck forever, so I'd drop the math and say "5
seconds" or something.

> +	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();

We don't explicitly put glFlush() in tests unless required.  (this is
also feedback for the previous patch).

> +
> +		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;
> +		}

Huh.  Is glXGetSyncValuesOML supposed to return a new.sbc >= target_sbc
after a glXSwapBuffersMscOML?  I hadn't considered that before.  It's
not clear to me from the spec that it would wait for the swap to have
completed.  However, given that we'll stall on old swaps eventually in
the driver (frame throttling), you'll sometimes get a new sbc/msc/ust.

Your test appears to be ready for sbc not changing, so it looks like
you're prepared for either interpretation, whether the implementation
stalls at glXGSVOML or not.

> +
> +		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;
> +}

The test logic I've read in 7/9 and 9/9 looks good.  I'm hoping to hear
back about framework timeout support (to see whether we want the
per-test timeout stuff or not), and once you do the trivial style-ish
changes, I can send some reviewed-bys.