[Piglit] [PATCH 9/9] Validate that SwapBuffers doesn't re-use an MSC.
Eric Anholt
eric at anholt.net
Thu May 8 11:41:13 PDT 2014
Jamey Sharp <jamey at minilop.net> writes:
> 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.
> 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140508/a02e2680/attachment-0001.sig>
More information about the Piglit
mailing list