Verify that glXCreateContextAttribsARB accepts the
GLX_CONTEXT_RELEASE_BEHAVIOR_ARB attribute, that the value of
GL_CONTEXT_RELEASE_BEHAVIOR in the created context reflects the value
of the attribute, and that queued rendering commands are not lost
when switching contexts.
---

The test doesn't try to verify that the context isn't flushed when
it is made non-current since I can't think of a good way to do that.

 tests/all.py                          |   1 +
 tests/glx/CMakeLists.gl.txt           |   1 +
 tests/glx/glx-context-flush-control.c | 158 ++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+)
 create mode 100644 tests/glx/glx-context-flush-control.c

diff --git a/tests/all.py b/tests/all.py
index 9597d11..312b077 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -540,6 +540,7 @@ add_plain_test(glx, 'glx-swap-pixmap-bad')
 add_plain_test(glx, 'glx-swap-singlebuffer')
 add_plain_test(glx, 'glx-make-current')
 add_plain_test(glx, 'glx-make-glxdrawable-current')
+add_concurrent_test(glx, 'glx-context-flush-control')
 add_plain_test(glx, 'glx-buffer-age')
 glx['glx-buffer-age vblank_mode=0'] = plain_test('glx-buffer-age')
 glx['glx-buffer-age vblank_mode=0'].env['vblank_mode'] = '0'
diff --git a/tests/glx/CMakeLists.gl.txt b/tests/glx/CMakeLists.gl.txt
index eeb1d7a..f66a0cc 100644
--- a/tests/glx/CMakeLists.gl.txt
+++ b/tests/glx/CMakeLists.gl.txt
@@ -32,6 +32,7 @@ IF(PIGLIT_BUILD_GLX_TESTS)
        piglit_add_executable (glx-dont-care-mask glx-dont-care-mask.c)
        piglit_add_executable (glx-multi-context-ib-1 glx-multi-context-ib-1.c)
        piglit_add_executable (glx-multithread glx-multithread.c)
+       piglit_add_executable (glx-context-flush-control 
glx-context-flush-control.c)
        target_link_libraries(glx-multithread pthread)
        piglit_add_executable (glx-multithread-texture 
glx-multithread-texture.c)
        target_link_libraries(glx-multithread-texture pthread)
diff --git a/tests/glx/glx-context-flush-control.c 
b/tests/glx/glx-context-flush-control.c
new file mode 100644
index 0000000..aaf47d7
--- /dev/null
+++ b/tests/glx/glx-context-flush-control.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright ?? 2014 Fredrik H??glund
+ *
+ * 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 glx-context-flush-control.c
+ *
+ * Verify that glXCreateContextAttribsARB accepts the
+ * GLX_CONTEXT_RELEASE_BEHAVIOR_ARB attribute, that the value of
+ * GL_CONTEXT_RELEASE_BEHAVIOR in the created context reflects the value
+ * of the attribute, and that queued rendering commands are not lost
+ * when switching contexts.
+ */
+
+#include "piglit-util-gl.h"
+#include "piglit-glx-util.h"
+
+int piglit_width = 100;
+int piglit_height = 100;
+
+#ifndef GLX_ARB_context_flush_control
+#define GLX_CONTEXT_RELEASE_BEHAVIOR_ARB       0x2097
+#define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB  0
+#define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098
+#endif
+
+#ifndef GL_VERSION_4_5
+#define GL_CONTEXT_RELEASE_BEHAVIOR       0x82FB
+#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82FC
+#endif
+
+static PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribs = NULL;
+
+static bool
+check_value_(GLenum param, GLenum expected, int line)
+{
+       GLint value;
+       glGetIntegerv(param, &value);
+
+       if (value != expected) {
+               fprintf(stderr, "%s was %s, expected %s (%s:%d)\n",
+                       piglit_get_gl_enum_name(param),
+                       piglit_get_gl_enum_name(value),
+                       piglit_get_gl_enum_name(expected),
+                       __FILE__, line);
+               return false;
+       }
+
+       return true;
+}
+
+#define check_value(param, expected) \
+       check_value_(param, expected, __LINE__)
+
+int
+main(int argc, char **argv)
+{
+       const int ctx_attribs_noflush[] = {
+               GLX_CONTEXT_MAJOR_VERSION_ARB, 1,
+               GLX_CONTEXT_MINOR_VERSION_ARB, 2,
+               GLX_CONTEXT_RELEASE_BEHAVIOR_ARB, 
GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB,
+               0
+       };
+       const int ctx_attribs_flush[] = {
+               GLX_CONTEXT_MAJOR_VERSION_ARB, 1,
+               GLX_CONTEXT_MINOR_VERSION_ARB, 2,
+               GLX_CONTEXT_RELEASE_BEHAVIOR_ARB, 
GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB,
+               0
+       };
+       const float green[] = { 0.0, 1.0, 0.0, 1.0 };
+       const float blue[] = { 0.0, 0.0, 1.0, 1.0 };
+       const int half_width = piglit_width * .5;
+       const int half_height = piglit_height * .5;
+       bool pass = true;
+       Display *dpy;
+       GLXContext ctx1, ctx2;
+       GLXFBConfig config;
+       XVisualInfo *xvi;
+       Window win1, win2;
+
+       dpy = piglit_get_glx_display();
+
+       piglit_require_glx_extension(dpy, "GLX_ARB_get_proc_address");
+       piglit_require_glx_extension(dpy, "GLX_ARB_create_context");
+       piglit_require_glx_extension(dpy, "GLX_ARB_context_flush_control");
+
+       CreateContextAttribs = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
+               glXGetProcAddressARB((GLubyte *) "glXCreateContextAttribsARB");
+
+       /* Create and map two identical windows */
+       xvi = piglit_get_glx_visual(dpy);
+       config = piglit_glx_get_fbconfig_for_visinfo(dpy, xvi);
+
+       win1 = piglit_get_glx_window(dpy, xvi);
+       win2 = piglit_get_glx_window(dpy, xvi);
+
+       /* Create two contexts - one with GLX_CONTEXT_RELEASE_BEHAVIOR_NONE,
+          and the other with GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH */
+       ctx1 = CreateContextAttribs(dpy, config, 0, True, ctx_attribs_noflush);
+       ctx2 = CreateContextAttribs(dpy, config, 0, True, ctx_attribs_flush);
+
+       /* Make the first context current on win1 */
+       glXMakeCurrent(dpy, win1, ctx1);
+
+       piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
+       piglit_require_extension("GL_KHR_context_flush_control");
+
+       /* Verify that the release behavior is set to none */
+       pass = check_value(GL_CONTEXT_RELEASE_BEHAVIOR, GL_NONE) && pass;
+
+       /* Clear the back buffer to green, but don't flush or swap buffers */
+       glClearColor(0.0, 1.0, 0.0, 1.0);
+       glClear(GL_COLOR_BUFFER_BIT);
+
+       /* Make the second context current on win2 */
+       glXMakeCurrent(dpy, win2, ctx2);
+
+       /* Verify that the release behavior is set to flush */
+       pass = check_value(GL_CONTEXT_RELEASE_BEHAVIOR,
+                          GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH) && pass;
+
+       /* Clear the back buffer to blue and swap buffers */
+       glClearColor(0.0, 0.0, 1.0, 1.0);
+       glClear(GL_COLOR_BUFFER_BIT);
+       glXSwapBuffers(dpy, win2);
+
+       pass = piglit_probe_pixel_rgba(half_width, half_height, blue) && pass;
+
+       /* Make the first context current again */
+       glXMakeCurrent(dpy, win1, ctx1);
+
+       /* Swap buffers (this flushes the context)
+          and verify that the back buffer was cleared */
+       glXSwapBuffers(dpy, win1);
+
+       pass = piglit_probe_pixel_rgba(half_width, half_height, green) && pass;
+
+       piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+       return 0;
+}
-- 
1.8.5.3

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to