From: TheoH <[email protected]> The existing tests don't demonstrate a variety of implementation bugs that we've observed in current drivers, so this is our attempt to demonstrate those bugs.
Signed-off-by: Theo Hill <[email protected]> Signed-off-by: Jamey Sharp <[email protected]> --- tests/all.py | 9 + tests/spec/glx_oml_sync_control/CMakeLists.gl.txt | 1 + tests/spec/glx_oml_sync_control/timing.c | 298 ++++++++++++++++++++++ 3 files changed, 308 insertions(+) create mode 100644 tests/spec/glx_oml_sync_control/timing.c diff --git a/tests/all.py b/tests/all.py index ccfa626..d610ce0 100644 --- a/tests/all.py +++ b/tests/all.py @@ -786,6 +786,15 @@ oml_sync_control['swapbuffersmsc-return swap_interval 0'] = PiglitTest(['glx-oml oml_sync_control['swapbuffersmsc-return swap_interval 1'] = PiglitTest(['glx-oml-sync-control-swapbuffersmsc-return', '1']) oml_sync_control['waitformsc'] = PiglitTest(['glx-oml-sync-control-waitformsc']) +oml_sync_control_nonzeros = [ + mode + [kind, period] + for mode in [[], ['-fullscreen'], ['-waitformsc']] + for kind in ['-divisor', '-msc-delta'] + for period in ['1', '2'] +] +for arg in [[], ['-fullscreen']] + oml_sync_control_nonzeros: + oml_sync_control[' '.join(['timing'] + arg)] = PiglitTest(['glx-oml-sync-control-timing'] + arg) + 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 c299848..125e2a5 100644 --- a/tests/spec/glx_oml_sync_control/CMakeLists.gl.txt +++ b/tests/spec/glx_oml_sync_control/CMakeLists.gl.txt @@ -26,6 +26,7 @@ IF(PIGLIT_BUILD_GLX_TESTS) piglit_add_executable (glx-oml-sync-control-swapbuffersmsc-divisor-zero swapbuffersmsc-divisor-zero.c common.c) 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) ENDIF(PIGLIT_BUILD_GLX_TESTS) # vim: ft=cmake: diff --git a/tests/spec/glx_oml_sync_control/timing.c b/tests/spec/glx_oml_sync_control/timing.c new file mode 100644 index 0000000..decb352 --- /dev/null +++ b/tests/spec/glx_oml_sync_control/timing.c @@ -0,0 +1,298 @@ +/* + * 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 timing.c + * Validates that OML Sync Control implementation actually syncs to vertical retrace + */ + +#include "piglit-util-gl-common.h" +#include "piglit-glx-util.h" +#include "common.h" +/* + * TODO: varying MSC deltas enumerated as arguments + * TODO: As a different test, create two drawables and verify they have independent SBC + */ +static bool fullscreen; +static bool use_swapbuffers = true; +static int64_t target_msc_delta; +static int64_t divisor; +static const int64_t msc_remainder = 0; +static const unsigned int loops = 10; + +struct stats { + unsigned int n; + double mean; + double M2; +}; + +static void update_stats(struct stats *stats, double val) { + double delta = val - stats->mean; + stats->n += 1; + stats->mean += delta / stats->n; + stats->M2 += delta * (val - stats->mean); +} + +static double get_stddev(struct stats *stats) { + return sqrt(stats->M2 / (stats->n - 1)); +} + +static enum piglit_result +draw(Display *dpy) +{ + enum piglit_result result = PIGLIT_PASS; + int64_t last_ust = 0xd0, last_msc = 0xd0, last_sbc = 0xd0, last_timestamp = -1; + struct stats msc_wallclock_duration_stats = {}; + struct stats msc_ust_duration_stats = {}; + double expected_msc_wallclock_duration = 0.0; + int32_t rate_num, rate_den; + unsigned int i; + + if (!glXGetSyncValuesOML(dpy, win, &last_ust, &last_msc, &last_sbc)) { + fprintf(stderr, "Initial glXGetSyncValuesOML failed\n"); + return PIGLIT_FAIL; + } + + /* Check that the window is fresh */ + if (last_sbc != 0) { + fprintf(stderr, "Initial SBC for the window should be 0, was %" PRId64 "\n", last_sbc); + } + + if (!glXGetMscRateOML(dpy, win, &rate_num, &rate_den)) { + fprintf(stderr, "glXGetMscRateOML failed, can't test MSC duration\n"); + } else { + expected_msc_wallclock_duration = 1e6 * rate_den / rate_num; + } + + for (i = 0; i < loops; i++) { + int64_t swapped_ust = 0xd0, swapped_msc = 0xd0, swapped_sbc = 0xd0; + int64_t new_ust = 0xd0, new_msc = 0xd0, new_sbc = 0xd0, new_timestamp; + int64_t expected_msc, target_sbc; + int64_t target_msc = 0; + + if (target_msc_delta) { + target_msc = last_msc + target_msc_delta; + } + + if (use_swapbuffers) { + glClearColor(0.0, 1.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + glFlush(); + + target_sbc = glXSwapBuffersMscOML(dpy, win, target_msc, divisor, msc_remainder); + if(target_sbc <= 0) { + fprintf(stderr, "glXSwapBuffersMscOML failed\n"); + return PIGLIT_FAIL; + } + /*ERROR: swapBuffersMsc calculates wrong target SBC (i.e. not current sbc + 1) */ + if(target_sbc != last_sbc + 1) { + fprintf(stderr, "glXSwapBuffersMscOML calculated the wrong target sbc: expected %"PRId64" but got %"PRId64"\n", last_sbc + 1, target_sbc); + result = PIGLIT_FAIL; + } + + if(!glXWaitForSbcOML(dpy, win, target_sbc, &swapped_ust, &swapped_msc, &swapped_sbc)) { + fprintf(stderr, "glXWaitForSbcOML failed\n"); + result = PIGLIT_FAIL; + } + } else { + target_sbc = last_sbc; + + if(!glXWaitForMscOML(dpy, win, target_msc, divisor, msc_remainder, &swapped_ust, &swapped_msc, &swapped_sbc)) { + fprintf(stderr, "glXWaitForSbcOML failed\n"); + result = PIGLIT_FAIL; + } + } + new_timestamp = piglit_get_microseconds(); + + if (!glXGetSyncValuesOML(dpy, win, &new_ust, &new_msc, &new_sbc)) { + fprintf(stderr, "Follow-up glXGetSyncValuesOML failed\n"); + return PIGLIT_FAIL; + } + + /* ERROR: immediately after waitForMsc or waitForSbc, getSyncValues returns different ust/msc/sbc */ + if (swapped_ust != new_ust) { + fprintf(stderr, "glXGetSyncValuesOML returned UST %"PRId64" but Wait returned %"PRId64"\n", new_ust, swapped_ust); + result = PIGLIT_FAIL; + } + + if (swapped_msc != new_msc) { + fprintf(stderr, "glXGetSyncValuesOML returned MSC %"PRId64" but Wait returned %"PRId64"\n", new_msc, swapped_msc); + result = PIGLIT_FAIL; + } + + if (swapped_sbc != new_sbc) { + fprintf(stderr, "glXGetSyncValuesOML returned SBC %"PRId64" but Wait returned %"PRId64"\n", new_sbc, swapped_sbc); + result = PIGLIT_FAIL; + } + + if (new_msc > last_msc) { + int64_t delta_msc = new_msc - last_msc; + update_stats(&msc_ust_duration_stats, (new_ust - last_ust) / delta_msc); + + if (last_timestamp >= 0) { + if (new_timestamp < 0) { + fprintf(stderr, "no monotonic clock available\n"); + } else { + update_stats(&msc_wallclock_duration_stats, (new_timestamp - last_timestamp) / delta_msc); + } + } + } + + /* ERROR: non-monotonicity in ust/msc */ + if (new_ust < last_ust) { + fprintf(stderr, "non-monotonic UST went backward by %"PRId64"\n", last_ust - new_ust); + result = PIGLIT_FAIL; + } + + if (new_msc < last_msc) { + fprintf(stderr, "non-monotonic MSC went backward by %"PRId64"\n", last_msc - new_msc); + result = PIGLIT_FAIL; + } + + /* ERROR: waitForSbc returns on the wrong SBC or waitForMsc changes SBC */ + if (new_sbc != target_sbc) { + fprintf(stderr, "Wait should have returned at SBC %"PRId64" but returned at %"PRId64"\n", target_sbc, new_sbc); + result = PIGLIT_FAIL; + } + + /* ERROR: Wake up MSC too early */ + /* WARNING: MSC is late. Technically being late is allowed by the spec */ + expected_msc = target_msc; + if (divisor) { + /* If there is a divisor, the expected MSC is the next MSC after last_msc such that MSC % divisor == remainder */ + int64_t last_remainder = last_msc % divisor; + expected_msc = last_msc - last_remainder + msc_remainder; + if (expected_msc <= last_msc) + expected_msc += divisor; + } else if (!target_msc) { + expected_msc = last_msc + 1; + } + + if (new_msc < expected_msc) { + fprintf(stderr, "woke up %"PRId64" MSCs early\n", expected_msc - new_msc); + result = PIGLIT_FAIL; + } + + if (new_msc > expected_msc) { + fprintf(stderr, "woke up %"PRId64" MSCs later than expected\n", new_msc - expected_msc); + } + + /* ERROR: if divisor is non-0 and MSC % divisor != remainder */ + if (divisor && new_msc % divisor != msc_remainder) { + fprintf(stderr, "woke up at wrong MSC remainder %"PRId64", not requested remainder %"PRId64"\n", new_msc % divisor, msc_remainder); + result = PIGLIT_FAIL; + } + + last_ust = new_ust; + last_msc = new_msc; + last_sbc = new_sbc; + last_timestamp = new_timestamp; + } + + /* + * WARNING: ust inconsistent with delta msc (ust is only guaranteed to be monotnic) + * ERROR: delta msc/delta wallclock time inconsistent + * - std dev too high (indicates periodicity) + * - mean isn't consistent with getMscRate (indicates correct period) + */ + if (msc_ust_duration_stats.n < 2) { + fprintf(stderr, "Not enough UST timing samples\n"); + } else if (expected_msc_wallclock_duration > 0.0) { + double apparent_ust_rate = msc_ust_duration_stats.mean / expected_msc_wallclock_duration; + if (get_stddev(&msc_ust_duration_stats) / apparent_ust_rate > 100) { + fprintf(stderr, "UST duration per MSC is surprisingly variable (stddev %f USTs), but then it only has to be monotonic\n", get_stddev(&msc_ust_duration_stats)); + } + } + + if (msc_wallclock_duration_stats.n < 2) { + fprintf(stderr, "Not enough wallclock timing samples\n"); + } else if (get_stddev(&msc_wallclock_duration_stats) > 1000) { + fprintf(stderr, "Wallclock time between MSCs has stddev > 1ms (%fus), driver is probably not syncing to vblank\n", + get_stddev(&msc_wallclock_duration_stats)); + result = PIGLIT_FAIL; + } else if (expected_msc_wallclock_duration > 0.0) { + if (fabs(expected_msc_wallclock_duration - msc_wallclock_duration_stats.mean) > 50) { + fprintf(stderr, "Wallclock time between MSCs %fus does not match glXGetMscRateOML %f\n", msc_wallclock_duration_stats.mean, expected_msc_wallclock_duration); + result = PIGLIT_FAIL; + } + } + + return result; +} + +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], "-fullscreen")) { + fullscreen = true; + } else if (!strcmp(argv[j], "-waitformsc")) { + use_swapbuffers = false; + } else if (!strcmp(argv[j], "-divisor")) { + j++; + divisor = parse_num_arg(argc, argv, j); + } else 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); + } + } + + if (divisor && target_msc_delta) { + fprintf(stderr, "this test doesn't support using both -divisor and -msc-delta\n"); + piglit_report_result(PIGLIT_FAIL); + } + + if (!use_swapbuffers && !divisor && !target_msc_delta) { + fprintf(stderr, "when using -waitformsc, this test requires either -divisor or -msc-delta\n"); + piglit_report_result(PIGLIT_FAIL); + } + + piglit_automatic = true; + piglit_oml_sync_control_test_run(fullscreen, draw); + + return 0; +} -- 1.8.5.3 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
