test/dri2: Use xcb for more accurate timing of SwapBuffers
To do SwapBuffers correctly requires a Swap/Get buffers combination, and this is easiest using xcb rather than xlib. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
parent
6f6190abcf
commit
2e7ae76038
|
|
@ -205,7 +205,7 @@ if test "x$UDEV" != "xno"; then
|
|||
fi
|
||||
fi
|
||||
|
||||
PKG_CHECK_MODULES(X11, [x11 xrender xrandr xext xfixes cairo cairo-xlib-xrender pixman-1 libpng], [x11="yes"], [x11="no"])
|
||||
PKG_CHECK_MODULES(X11, [x11 x11-xcb xcb-dri2 xrender xrandr xext xfixes cairo cairo-xlib-xrender pixman-1 libpng], [x11="yes"], [x11="no"])
|
||||
AM_CONDITIONAL(HAVE_X11, test "x$x11" = "xyes")
|
||||
|
||||
cpuid="yes"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@
|
|||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/Xfixes.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcbext.h>
|
||||
#include <xcb/dri2.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
|
@ -101,10 +105,29 @@ static uint64_t check_msc(Display *dpy, Window win, uint64_t last_msc)
|
|||
return current_msc;
|
||||
}
|
||||
|
||||
static void swap_buffers(xcb_connection_t *c, Window win,
|
||||
unsigned int *attachments, int nattachments)
|
||||
{
|
||||
unsigned int seq[2];
|
||||
|
||||
seq[0] = xcb_dri2_swap_buffers_unchecked(c, win,
|
||||
0, 0, 0, 0, 0, 0).sequence;
|
||||
|
||||
|
||||
seq[1] = xcb_dri2_get_buffers_unchecked(c, win,
|
||||
nattachments, nattachments,
|
||||
attachments).sequence;
|
||||
|
||||
xcb_flush(c);
|
||||
xcb_discard_reply(c, seq[0]);
|
||||
xcb_discard_reply(c, seq[1]);
|
||||
}
|
||||
|
||||
static void run(Display *dpy, int width, int height,
|
||||
unsigned int *attachments, int nattachments,
|
||||
const char *name)
|
||||
{
|
||||
xcb_connection_t *c = XGetXCBConnection(dpy);
|
||||
Window win;
|
||||
XSetWindowAttributes attr;
|
||||
int count;
|
||||
|
|
@ -132,15 +155,17 @@ static void run(Display *dpy, int width, int height,
|
|||
if (count != nattachments)
|
||||
return;
|
||||
|
||||
swap_buffers(c, win, attachments, nattachments);
|
||||
msc = check_msc(dpy, win, msc);
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (count = 0; count < COUNT; count++)
|
||||
DRI2SwapBuffers(dpy, win, 0, 0, 0);
|
||||
swap_buffers(c, win, attachments, nattachments);
|
||||
msc = check_msc(dpy, win, msc);
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
printf("%d %s (%dx%d) swaps in %fs.\n",
|
||||
count, name, width, height, elapsed(&start, &end));
|
||||
|
||||
swap_buffers(c, win, attachments, nattachments);
|
||||
msc = check_msc(dpy, win, msc);
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (count = 0; count < COUNT; count++)
|
||||
|
|
@ -153,10 +178,11 @@ static void run(Display *dpy, int width, int height,
|
|||
|
||||
DRI2SwapInterval(dpy, win, 0);
|
||||
|
||||
swap_buffers(c, win, attachments, nattachments);
|
||||
msc = check_msc(dpy, win, msc);
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (count = 0; count < COUNT; count++)
|
||||
DRI2SwapBuffers(dpy, win, 0, 0, 0);
|
||||
swap_buffers(c, win, attachments, nattachments);
|
||||
msc = check_msc(dpy, win, msc);
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
printf("%d %s (%dx%d) vblank=0 swaps in %fs.\n",
|
||||
|
|
|
|||
Loading…
Reference in New Issue