From daf7fe69f7bd0caa955d30b43fc35b7ce0069b6b Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Tue, 15 Sep 2009 23:23:09 -0700 Subject: DRI2: add OML_sync_control support Add OML_sync_control support, along with a simple program for testing it. This means adding support for the DRI2GetMSC, DRI2WaitMSC and DRI2WaitSBC requests. Signed-off-by: Jesse Barnes --- progs/xdemos/.gitignore | 1 + progs/xdemos/Makefile | 1 + progs/xdemos/msctest.c | 202 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 progs/xdemos/msctest.c (limited to 'progs') diff --git a/progs/xdemos/.gitignore b/progs/xdemos/.gitignore index 1b9b3a87c0..5ae0f5a062 100644 --- a/progs/xdemos/.gitignore +++ b/progs/xdemos/.gitignore @@ -26,3 +26,4 @@ xdemo xfont xrotfontdemo yuvrect_client +msctest diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile index 77f667978c..f866a32865 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -29,6 +29,7 @@ PROGS = \ glxsnoop \ glxswapcontrol \ manywin \ + msctest \ multictx \ offset \ overlay \ diff --git a/progs/xdemos/msctest.c b/progs/xdemos/msctest.c new file mode 100644 index 0000000000..001ecf04d6 --- /dev/null +++ b/progs/xdemos/msctest.c @@ -0,0 +1,202 @@ +/* + * Copyright © 2009 Intel Corporation + * + * 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. + * + * Authors: + * Jesse Barnes + * + */ + +/** @file msctest.c + * Simple test for MSC functionality. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void (*get_sync_values)(Display *dpy, Window winGL, int64_t *ust, int64_t *msc, int64_t *sbc); +void (*wait_sync)(Display *dpy, Window winGL, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc); + +static int GLXExtensionSupported(Display *dpy, const char *extension) +{ + const char *extensionsString, *client_extensions, *pos; + + extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy)); + client_extensions = glXGetClientString(dpy, GLX_EXTENSIONS); + + pos = strstr(extensionsString, extension); + + if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') && + (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0')) + return 1; + + pos = strstr(client_extensions, extension); + + if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') && + (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0')) + return 1; + + return 0; +} + +extern char *optarg; +extern int optind, opterr, optopt; +static char optstr[] = "v"; + +static void usage(char *name) +{ + printf("usage: %s\n", name); + exit(-1); +} + +int main(int argc, char *argv[]) +{ + Display *disp; + XVisualInfo *pvi; + XSetWindowAttributes swa; + int attrib[14]; + Window winGL; + GLXContext context; + int dummy; + Atom wmDelete; + int verbose = 0, width = 200, height = 200; + int c, i = 1; + int64_t ust, msc, sbc; + + opterr = 0; + while ((c = getopt(argc, argv, optstr)) != -1) { + switch (c) { + case 'v': + verbose = 1; + break; + default: + usage(argv[0]); + break; + } + } + + disp = XOpenDisplay(NULL); + if (!disp) { + fprintf(stderr, "failed to open display\n"); + return -1; + } + + if (!glXQueryExtension(disp, &dummy, &dummy)) { + fprintf(stderr, "glXQueryExtension failed\n"); + return -1; + } + + if (!GLXExtensionSupported(disp, "GLX_OML_sync_control")) { + fprintf(stderr, "GLX_OML_sync_control not supported, exiting\n"); + return -1; + } + + attrib[0] = GLX_RGBA; + attrib[1] = 1; + attrib[2] = GLX_RED_SIZE; + attrib[3] = 1; + attrib[4] = GLX_GREEN_SIZE; + attrib[5] = 1; + attrib[6] = GLX_BLUE_SIZE; + attrib[7] = 1; + attrib[8] = GLX_DOUBLEBUFFER; + attrib[9] = 1; + attrib[10] = None; + + pvi = glXChooseVisual(disp, DefaultScreen(disp), attrib); + if (!pvi) { + fprintf(stderr, "failed to choose visual, exiting\n"); + return -1; + } + + context = glXCreateContext(disp, pvi, None, GL_TRUE); + if (!context) { + fprintf(stderr, "failed to create glx context\n"); + return -1; + } + + pvi->screen = DefaultScreen(disp); + + swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen), + pvi->visual, AllocNone); + swa.border_pixel = 0; + swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | + StructureNotifyMask; + winGL = XCreateWindow(disp, RootWindow(disp, pvi->screen), + 0, 0, + width, height, + 0, pvi->depth, InputOutput, pvi->visual, + CWBorderPixel | CWColormap | CWEventMask, &swa); + if (!winGL) { + fprintf(stderr, "window creation failed\n"); + return -1; + } + wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True); + XSetWMProtocols(disp, winGL, &wmDelete, 1); + + XSetStandardProperties(disp, winGL, "msc test", "msc text", + None, NULL, 0, NULL); + + XMapRaised(disp, winGL); + + glXMakeCurrent(disp, winGL, context); + + get_sync_values = glXGetProcAddress((unsigned char *)"glXGetSyncValuesOML"); + wait_sync = glXGetProcAddress((unsigned char *)"glXWaitForMscOML"); + + if (!get_sync_values || !wait_sync) { + fprintf(stderr, "failed to get sync values function\n"); + return -1; + } + + while (i++) { + get_sync_values(disp, winGL, &ust, &msc, &sbc); + fprintf(stderr, "ust: %llu, msc: %llu, sbc: %llu\n", ust, msc, + sbc); + + /* Alternate colors to make tearing obvious */ + if (i & 1) + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + else + glClearColor(1.0f, 0.0f, 0.0f, 0.0f); + glClear(GL_COLOR_BUFFER_BIT); + glXSwapBuffers(disp, winGL); + wait_sync(disp, winGL, 0, 60, 0, &ust, &msc, &sbc); + fprintf(stderr, + "wait returned ust: %llu, msc: %llu, sbc: %llu\n", + ust, msc, sbc); + sleep(1); + } + + XDestroyWindow(disp, winGL); + glXDestroyContext(disp, context); + XCloseDisplay(disp); + + return 0; +} -- cgit v1.2.3 From f35f666f81221aea0b2eda533573bcbd07d10d65 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Mon, 2 Nov 2009 11:20:08 -0800 Subject: xdemos/glsync: Add swap interval support to glsync test --- progs/xdemos/glsync.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'progs') diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c index da87306cf2..e813c8770d 100644 --- a/progs/xdemos/glsync.c +++ b/progs/xdemos/glsync.c @@ -59,6 +59,7 @@ void (*video_sync_get)(); void (*video_sync)(); +void (*swap_interval)(); static int GLXExtensionSupported(Display *dpy, const char *extension) { @@ -84,7 +85,7 @@ static int GLXExtensionSupported(Display *dpy, const char *extension) extern char *optarg; extern int optind, opterr, optopt; -static char optstr[] = "w:h:s:v"; +static char optstr[] = "w:h:s:vi:"; enum sync_type { none = 0, @@ -100,6 +101,7 @@ static void usage(char *name) printf("\t\tn: none\n"); printf("\t\ts: SGI video sync extension\n"); printf("\t\tb: buffer swap\n"); + printf("\t-i\n"); printf("\t-v: verbose (print count)\n"); exit(-1); } @@ -117,7 +119,7 @@ int main(int argc, char *argv[]) Atom wmDelete; enum sync_type waitforsync = none; int width = 500, height = 500, verbose = 0, - countonly = 0; + countonly = 0, interval = 1; int c, i = 1; opterr = 0; @@ -148,6 +150,9 @@ int main(int argc, char *argv[]) case 'v': verbose = 1; break; + case 'i': + interval = atoi(optarg); + break; default: usage(argv[0]); break; @@ -227,11 +232,15 @@ int main(int argc, char *argv[]) video_sync_get = glXGetProcAddress((unsigned char *)"glXGetVideoSyncSGI"); video_sync = glXGetProcAddress((unsigned char *)"glXWaitVideoSyncSGI"); - if (!video_sync_get || !video_sync) { + swap_interval = glXGetProcAddress((unsigned char *)"glXSwapIntervalSGI"); + + if (!video_sync_get || !video_sync || !swap_interval) { fprintf(stderr, "failed to get sync functions\n"); return -1; } + swap_interval(interval); + fprintf(stderr, "set swap interval to %d\n", interval); video_sync_get(&count); count++; while (i++) { @@ -256,6 +265,11 @@ int main(int argc, char *argv[]) continue; } + if (verbose) { + video_sync_get(&count); + fprintf(stderr, "current count: %d\n", count); + } + /* Alternate colors to make tearing obvious */ if (i & 1) glClearColor(1.0f, 1.0f, 1.0f, 1.0f); -- cgit v1.2.3 From f860aac0d8caff6623792c9da272af269e631ed9 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Tue, 3 Nov 2009 10:48:17 -0800 Subject: xdemos/glsync: Make glsync test draw a rectangle Doing simple buffer clears isn't enough to actually allocate render buffers, we need to do real drawing. --- progs/xdemos/glsync.c | 83 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 34 deletions(-) (limited to 'progs') diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c index e813c8770d..0608f75534 100644 --- a/progs/xdemos/glsync.c +++ b/progs/xdemos/glsync.c @@ -111,7 +111,6 @@ int main(int argc, char *argv[]) Display *disp; XVisualInfo *pvi; XSetWindowAttributes swa; - int attrib[14]; GLint last_val = -1, count = 0; Window winGL; GLXContext context; @@ -121,6 +120,19 @@ int main(int argc, char *argv[]) int width = 500, height = 500, verbose = 0, countonly = 0, interval = 1; int c, i = 1; + int attribs[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + None }; + int db_attribs[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + None }; + XSizeHints sizehints; opterr = 0; while ((c = getopt(argc, argv, optstr)) != -1) { @@ -175,34 +187,17 @@ int main(int argc, char *argv[]) return -1; } - attrib[0] = GLX_RGBA; - attrib[1] = 1; - attrib[2] = GLX_RED_SIZE; - attrib[3] = 1; - attrib[4] = GLX_GREEN_SIZE; - attrib[5] = 1; - attrib[6] = GLX_BLUE_SIZE; - attrib[7] = 1; - if (waitforsync != buffer_swap) - attrib[8] = None; - else { - attrib[8] = GLX_DOUBLEBUFFER; - attrib[9] = 1; - attrib[10] = None; + if (waitforsync != buffer_swap) { + pvi = glXChooseVisual(disp, DefaultScreen(disp), attribs); + } else { + pvi = glXChooseVisual(disp, DefaultScreen(disp), db_attribs); } - pvi = glXChooseVisual(disp, DefaultScreen(disp), attrib); if (!pvi) { fprintf(stderr, "failed to choose visual, exiting\n"); return -1; } - context = glXCreateContext(disp, pvi, None, GL_TRUE); - if (!context) { - fprintf(stderr, "failed to create glx context\n"); - return -1; - } - pvi->screen = DefaultScreen(disp); swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen), @@ -222,11 +217,23 @@ int main(int argc, char *argv[]) wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True); XSetWMProtocols(disp, winGL, &wmDelete, 1); + sizehints.x = 0; + sizehints.y = 0; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + + XSetNormalHints(disp, winGL, &sizehints); XSetStandardProperties(disp, winGL, "glsync test", "glsync text", - None, NULL, 0, NULL); + None, NULL, 0, &sizehints); - XMapRaised(disp, winGL); + context = glXCreateContext(disp, pvi, NULL, GL_TRUE); + if (!context) { + fprintf(stderr, "failed to create glx context\n"); + return -1; + } + XMapWindow(disp, winGL); glXMakeCurrent(disp, winGL, context); video_sync_get = glXGetProcAddress((unsigned char *)"glXGetVideoSyncSGI"); @@ -239,11 +246,26 @@ int main(int argc, char *argv[]) return -1; } - swap_interval(interval); - fprintf(stderr, "set swap interval to %d\n", interval); + if (waitforsync == buffer_swap) { + swap_interval(interval); + fprintf(stderr, "set swap interval to %d\n", interval); + } video_sync_get(&count); count++; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); while (i++) { + /* Alternate colors to make tearing obvious */ + if (i & 1) { + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + glColor3f(1.0f, 1.0f, 1.0f); + } else { + glClearColor(1.0f, 0.0f, 0.0f, 0.0f); + glColor3f(1.0f, 0.0f, 0.0f); + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glRectf(0, 0, width, height); + /* Wait for vsync */ if (waitforsync == sgi_video_sync) { if (verbose) @@ -254,6 +276,7 @@ int main(int argc, char *argv[]) if (count == last_val) fprintf(stderr, "error: count didn't change: %d\n", count); last_val = count; + glFlush(); } else if (waitforsync == buffer_swap) { glXSwapBuffers(disp, winGL); } @@ -269,14 +292,6 @@ int main(int argc, char *argv[]) video_sync_get(&count); fprintf(stderr, "current count: %d\n", count); } - - /* Alternate colors to make tearing obvious */ - if (i & 1) - glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - else - glClearColor(1.0f, 0.0f, 0.0f, 0.0f); - glClear(GL_COLOR_BUFFER_BIT); - glFlush(); } XDestroyWindow(disp, winGL); -- cgit v1.2.3 From 0269dc19b57b61d46b09fe2636ce430baa9383c3 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Mon, 4 Jan 2010 13:13:57 -0500 Subject: xdemos/glsync: check glXMakeCurrent return value Since this program is used for testing, catching this case can be helpful. --- progs/xdemos/glsync.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c index 0608f75534..6108d991d0 100644 --- a/progs/xdemos/glsync.c +++ b/progs/xdemos/glsync.c @@ -120,6 +120,7 @@ int main(int argc, char *argv[]) int width = 500, height = 500, verbose = 0, countonly = 0, interval = 1; int c, i = 1; + int ret; int attribs[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, @@ -234,7 +235,10 @@ int main(int argc, char *argv[]) } XMapWindow(disp, winGL); - glXMakeCurrent(disp, winGL, context); + ret = glXMakeCurrent(disp, winGL, context); + if (ret) { + fprintf(stderr, "failed to make context current: %d\n", ret); + } video_sync_get = glXGetProcAddress((unsigned char *)"glXGetVideoSyncSGI"); video_sync = glXGetProcAddress((unsigned char *)"glXWaitVideoSyncSGI"); -- cgit v1.2.3 From c642f3941ba2ab68135037e1fcb1c29dcb820de7 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Mon, 4 Jan 2010 16:26:17 -0500 Subject: xdemos/glsync: handle no sync method better Print out count, finish rendering, etc. Makes the -sn option more useful. --- progs/xdemos/glsync.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'progs') diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c index 6108d991d0..4dc4937703 100644 --- a/progs/xdemos/glsync.c +++ b/progs/xdemos/glsync.c @@ -117,8 +117,7 @@ int main(int argc, char *argv[]) int dummy; Atom wmDelete; enum sync_type waitforsync = none; - int width = 500, height = 500, verbose = 0, - countonly = 0, interval = 1; + int width = 500, height = 500, verbose = 0, interval = 1; int c, i = 1; int ret; int attribs[] = { GLX_RGBA, @@ -283,13 +282,10 @@ int main(int argc, char *argv[]) glFlush(); } else if (waitforsync == buffer_swap) { glXSwapBuffers(disp, winGL); - } - - if (countonly) { - video_sync(2, 1, &count); - fprintf(stderr, "current count: %d\n", count); + } else { + video_sync_get(&count); sleep(1); - continue; + glFinish(); } if (verbose) { -- cgit v1.2.3