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
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
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
32 #include "piglit-util-gl.h"
33 #include "piglit-glx-util.h"
36 static pthread_mutex_t mutex
;
37 static bool dispatch_ready
= false;
40 thread_func(void *arg
)
47 dpy
= piglit_get_glx_display();
48 visinfo
= piglit_get_glx_visual(dpy
);
49 win
= piglit_get_glx_window(dpy
, visinfo
);
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
) {
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
);
73 piglit_check_gl_error(0);
76 glXDestroyContext(dpy
, ctx
);
81 main(int argc
, char **argv
)
83 /* Need at least 16 contexts to congest the thread queue. */
89 pthread_mutex_init(&mutex
, NULL
);
91 for (int i
= 0; i
< ARRAY_SIZE(thread
); i
++)
92 pthread_create(&thread
[i
], NULL
, thread_func
, NULL
);
94 for (int i
= 0; i
< ARRAY_SIZE(thread
); i
++) {
95 if (pthread_join(thread
[i
], NULL
) != 0)
99 pthread_mutex_destroy(&mutex
);
101 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);