@@ -23,7 +23,9 @@
#include "igt.h"
#include "drmtest.h"
+#include "sw_sync.h"
#include <errno.h>
+#include <pthread.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
@@ -111,6 +113,81 @@ enum transition_type {
TRANSITION_MODESET_DISABLE,
};
+int timeline[IGT_MAX_PLANES];
+pthread_t thread[IGT_MAX_PLANES];
+int seqno[IGT_MAX_PLANES];
+
+static void prepare_fencing(igt_display_t *display, enum pipe pipe)
+{
+ igt_plane_t *plane;
+
+ igt_require_sw_sync();
+
+ for_each_plane_on_pipe(display, pipe, plane)
+ timeline[plane->index] = sw_sync_timeline_create();
+}
+
+static void unprepare_fencing(igt_display_t *display, enum pipe pipe)
+{
+ igt_plane_t *plane;
+
+ for_each_plane_on_pipe(display, pipe, plane)
+ close(timeline[plane->index]);
+}
+
+static void *fence_inc_thread(void *arg)
+{
+ int t = *((int *) arg);
+
+ pthread_detach(pthread_self());
+
+ usleep(5000);
+ sw_sync_timeline_inc(t, 1);
+ return NULL;
+}
+
+static void configure_fencing(igt_display_t *display, enum pipe pipe)
+{
+ igt_plane_t *plane;
+ int i, fd, ret;
+
+ for_each_plane_on_pipe(display, pipe, plane) {
+
+ if (!plane->fb)
+ continue;
+
+ i = plane->index;
+
+ seqno[i]++;
+ fd = sw_sync_fence_create(timeline[i], seqno[i]);
+ igt_plane_set_fence_fd(plane, fd);
+ ret = pthread_create(&thread[i], NULL, fence_inc_thread, &timeline[i]);
+ igt_assert_eq(ret, 0);
+ }
+}
+
+static void clear_fencing(igt_display_t *display, enum pipe pipe)
+{
+ igt_plane_t *plane;
+
+ for_each_plane_on_pipe(display, pipe, plane)
+ igt_plane_set_fence_fd(plane, -1);
+}
+
+static void atomic_commit(igt_display_t *display, enum pipe pipe, unsigned int flags, void *data, bool fencing, int *out_fence)
+{
+ if (fencing) {
+ configure_fencing(display, pipe);
+ igt_pipe_set_out_fence_ptr(&display->pipes[pipe],
+ (int64_t *) out_fence);
+ }
+
+ igt_display_commit_atomic(display, flags, data);
+
+ if (fencing)
+ clear_fencing(display, pipe);
+}
+
/*
* 1. Set primary plane to a known fb.
* 2. Make sure getcrtc returns the correct fb id.
@@ -134,6 +211,9 @@ run_transition_test(igt_display_t *display, enum pipe pipe, igt_output_t *output
unsigned flags = DRM_MODE_PAGE_FLIP_EVENT;
int out_fence, ret;
+ if (fencing)
+ prepare_fencing(display, pipe);
+
if (nonblocking)
flags |= DRM_MODE_ATOMIC_NONBLOCK;
@@ -234,10 +314,8 @@ run_transition_test(igt_display_t *display, enum pipe pipe, igt_output_t *output
wm_setup_plane(display, pipe, i, parms);
- if (fencing)
- igt_pipe_set_out_fence_ptr(&display->pipes[pipe], &out_fence);
+ atomic_commit(display, pipe, flags, (void *)(unsigned long)i, fencing, &out_fence);
- igt_display_commit_atomic(display, flags, (void *)(unsigned long)i);
drmHandleEvent(display->drm_fd, &drm_events);
if (type == TRANSITION_MODESET_DISABLE) {
@@ -262,19 +340,14 @@ run_transition_test(igt_display_t *display, enum pipe pipe, igt_output_t *output
if (type == TRANSITION_MODESET)
igt_output_override_mode(output, &override_mode);
- if (fencing)
- igt_pipe_set_out_fence_ptr(&display->pipes[pipe], &out_fence);
-
- igt_display_commit_atomic(display, flags, (void *)(unsigned long)j);
+ atomic_commit(display, pipe, flags, (void *)(unsigned long)i, fencing, &out_fence);
drmHandleEvent(display->drm_fd, &drm_events);
wm_setup_plane(display, pipe, i, parms);
if (type == TRANSITION_MODESET)
igt_output_override_mode(output, NULL);
- if (fencing)
- igt_pipe_set_out_fence_ptr(&display->pipes[pipe], &out_fence);
-
+ atomic_commit(display, pipe, flags, (void *)(unsigned long)i, fencing, &out_fence);
igt_display_commit_atomic(display, flags, (void *)(unsigned long)i);
drmHandleEvent(display->drm_fd, &drm_events);
}
@@ -282,6 +355,8 @@ run_transition_test(igt_display_t *display, enum pipe pipe, igt_output_t *output
}
cleanup:
+ unprepare_fencing(display, pipe);
+
igt_output_set_pipe(output, PIPE_NONE);
for_each_plane_on_pipe(display, pipe, plane)