ext_transform_feedback: document missing mode in usage
[piglit.git] / tests / glx / glx-multithread-clearbuffer.c
blob5f5d07c03cef6a7108398867bf845f3468333445
1 /*
2 * Copyright (c) 2017 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /**
25 * Create multiple GLX contexts and concurrently create, clear, and destroy
26 * buffers and flush the context.
28 * This reproduces a deadlock with the radeonsi command submission thread
29 * queue.
32 #include "piglit-util-gl.h"
33 #include "piglit-glx-util.h"
34 #include "pthread.h"
36 static pthread_mutex_t mutex;
37 static bool dispatch_ready = false;
39 static void *
40 thread_func(void *arg)
42 Display *dpy;
43 XVisualInfo *visinfo;
44 Window win;
45 unsigned i;
47 dpy = piglit_get_glx_display();
48 visinfo = piglit_get_glx_visual(dpy);
49 win = piglit_get_glx_window(dpy, visinfo);
51 GLXContext ctx;
53 ctx = piglit_get_glx_context(dpy, visinfo);
54 glXMakeCurrent(dpy, win, ctx);
56 pthread_mutex_lock(&mutex);
57 if (!dispatch_ready) {
58 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
59 dispatch_ready = true;
60 piglit_require_gl_version(30);
61 piglit_require_extension("GL_ARB_clear_buffer_object");
63 pthread_mutex_unlock(&mutex);
65 for (i = 0; i < 1000; ++i) {
66 GLuint buf;
67 glGenBuffers(1, &buf);
68 glBindBuffer(GL_ARRAY_BUFFER, buf);
69 glBufferData(GL_ARRAY_BUFFER, 512, NULL, GL_STATIC_DRAW);
70 glClearBufferSubData(GL_ARRAY_BUFFER, GL_R32UI, 0, 512, GL_RED_INTEGER, GL_UNSIGNED_INT, &buf);
71 glDeleteBuffers(1, &buf);
72 glFlush();
73 piglit_check_gl_error(0);
76 glXDestroyContext(dpy, ctx);
77 return NULL;
80 int
81 main(int argc, char **argv)
83 /* Need at least 16 contexts to congest the thread queue. */
84 pthread_t thread[16];
85 bool pass = true;
87 for (int i = 1; i < argc; i++) {
88 if (!strcmp(argv[i], "-auto"))
89 piglit_automatic = 1;
90 else
91 fprintf(stderr, "Unknown option: %s\n", argv[i]);
94 XInitThreads();
96 pthread_mutex_init(&mutex, NULL);
98 for (int i = 0; i < ARRAY_SIZE(thread); i++)
99 pthread_create(&thread[i], NULL, thread_func, NULL);
101 for (int i = 0; i < ARRAY_SIZE(thread); i++) {
102 if (pthread_join(thread[i], NULL) != 0)
103 pass = false;
106 pthread_mutex_destroy(&mutex);
108 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
109 return 0;