[Piglit] [PATCH] Add test for concurrent shader compiler use. v3

Ken Phillis Jr kphillisjr at gmail.com
Wed Apr 24 11:09:53 PDT 2013


I think this is a good start, however it does have a few issues I can see.

1) Two threads may not be enough to truly find the race conditions. I
know that an increasing number of systems have 4 or more processor
cores available and that not all of the cores run at the same speed.
That said, It may be a good idea to have the thread creation be
dynamic and set at runtime. I would suggest having the count be either
equal to the number of cores, or two times the number of cores.
However, this change may make it to where the iteration count needs to
be increased to cope with the additional cpu cores.

2)A major problem is that this test does not have any safe guards in
case features are missing. As the test is currently written, The test
Implicitly requires either of the following requirements be met:
Requirement 1: The following extensions be available and enabled:
GL_ARB_shader_objects, GL_ARB_vertex_shader, and
GL_ARB_fragment_shader
Requirement 2: The system is capable of running OpenGL 2.0 ( and GLSL
1.10 ), OpenGL 2.1 ( and GLSL 1.20), or OpenGL 3.x ( w/ compatibility
profile )

3) While not needing to be tested against in this test, but it would
be a good idea to also have tests against Geometry Shaders, and
Tessellation Shaders. These Have been gaining steam in the LLVM pipe
also so it may be useful to test against these so that race conditions
can be caught early on.

On Wed, Apr 24, 2013 at 9:19 AM, Tom Stellard <tom at stellard.net> wrote:
> On Wed, Apr 24, 2013 at 08:36:50AM +0200, Mathias Fröhlich wrote:
>>
>> Hi all,
>>
>> On Monday, April 22, 2013 09:39:02 Eric Anholt wrote:
>> > We format our comments as:
>> >
>> > +           /* Ok, not nice but should be safe due to all threads working
>> > +            * on the same type of context.
>> > +            */
>>
>> Now v4 is attached with the changed comment.
>> Could somebody apply and push this test please?
>>
>> greetings and thanks
>>
>
> Pushed.  Thanks for the patch!
>
> -Tom
>>
>> --
>> Mathias Fröhlich
>
>> From 5af2967b3f19e27755ffc5d6cb8408ceab959e11 Mon Sep 17 00:00:00 2001
>> Message-Id: <5af2967b3f19e27755ffc5d6cb8408ceab959e11.1366782138.git.Mathias.Froehlich at gmx.net>
>> From: Mathias Froehlich <Mathias.Froehlich at web.de>
>> Date: Wed, 24 Apr 2013 07:37:09 +0200
>> Subject: [PATCH] Add test for concurrent shader compiler use.
>>
>> Add a test that creates two contexts and concurrently
>> compiles shader programs to test race conditions of
>> the shader compiler.
>>
>> v3: (Tom Stellard)
>>   - Report pass at the end of the tests
>>   - Add as a concurrent test
>>
>> v4: (Mathias Froehlich)
>>   - Fix comment style
>>
>> Signed-off-by: Mathias Froehlich <Mathias.Froehlich at web.de>
>> Reviewed-by: Tom Stellard <thomas.stellard at amd.com>
>> Reviewed-by: Eric Anholt <eric at anholt.net>
>> ---
>>  tests/all.tests                            |   1 +
>>  tests/glx/CMakeLists.gl.txt                |   2 +
>>  tests/glx/glx-multithread-shader-compile.c | 118 +++++++++++++++++++++++++++++
>>  3 files changed, 121 insertions(+)
>>  create mode 100644 tests/glx/glx-multithread-shader-compile.c
>>
>> diff --git a/tests/all.tests b/tests/all.tests
>> index b827e12..d6c8f45 100644
>> --- a/tests/all.tests
>> +++ b/tests/all.tests
>> @@ -352,6 +352,7 @@ add_plain_test(glx, 'glx-multithread-makecurrent-1')
>>  add_plain_test(glx, 'glx-multithread-makecurrent-2')
>>  add_plain_test(glx, 'glx-multithread-makecurrent-3')
>>  add_plain_test(glx, 'glx-multithread-makecurrent-4')
>> +add_concurrent_test(glx, 'glx-multithread-shader-compile')
>>  add_plain_test(glx, 'glx-shader-sharing')
>>  add_plain_test(glx, 'glx-swap-exchange')
>>  glx['glx-swap-event_event'] = PlainExecTest(['glx-swap-event', '-auto', '--event'])
>> diff --git a/tests/glx/CMakeLists.gl.txt b/tests/glx/CMakeLists.gl.txt
>> index e75e492..ca85317 100644
>> --- a/tests/glx/CMakeLists.gl.txt
>> +++ b/tests/glx/CMakeLists.gl.txt
>> @@ -41,6 +41,8 @@ IF(PIGLIT_BUILD_GLX_TESTS)
>>       target_link_libraries(glx-multithread-makecurrent-3 pthread)
>>       piglit_add_executable (glx-multithread-makecurrent-4 glx-multithread-makecurrent-4.c)
>>       target_link_libraries(glx-multithread-makecurrent-4 pthread)
>> +     piglit_add_executable (glx-multithread-shader-compile glx-multithread-shader-compile.c)
>> +     target_link_libraries(glx-multithread-shader-compile pthread)
>>       piglit_add_executable (glx-make-current glx-make-current.c)
>>       piglit_add_executable (glx-swap-event glx-swap-event.c)
>>       piglit_add_executable (glx-make-glxdrawable-current glx-make-glxdrawable-current.c)
>> diff --git a/tests/glx/glx-multithread-shader-compile.c b/tests/glx/glx-multithread-shader-compile.c
>> new file mode 100644
>> index 0000000..b04c1b2
>> --- /dev/null
>> +++ b/tests/glx/glx-multithread-shader-compile.c
>> @@ -0,0 +1,118 @@
>> +/*
>> + * Copyright (c) 2012 Mathias Fröhlich
>> + *
>> + * 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-multithread-shader-compile.c
>> + * @author Mathias Fröhlich
>> + *
>> + * Create two GLX contexts and concurrently compile shaders.
>> + * Exercises a race conditon with the r600 llvm compiler.
>> + */
>> +
>> +#include "piglit-util-gl-common.h"
>> +#include "piglit-glx-util.h"
>> +#include "pthread.h"
>> +
>> +static const char *vert_shader_text =
>> +   "void main() \n"
>> +   "{ \n"
>> +   "   gl_Position = ftransform(); \n"
>> +   "   gl_FrontColor = gl_Color; \n"
>> +   "} \n";
>> +
>> +static const char *frag_shader_text =
>> +   "void main() \n"
>> +   "{ \n"
>> +   "   gl_FragColor = vec4(1.0) - gl_Color; \n"
>> +   "} \n";
>> +
>> +static pthread_mutex_t mutex;
>> +
>> +static void *
>> +thread_func(void *arg)
>> +{
>> +     Display *dpy;
>> +     XVisualInfo *visinfo;
>> +     Window win;
>> +     unsigned i;
>> +
>> +     dpy = piglit_get_glx_display();
>> +     visinfo = piglit_get_glx_visual(dpy);
>> +     win = piglit_get_glx_window(dpy, visinfo);
>> +
>> +     for (i = 0; i < 100; ++i) {
>> +             GLXContext ctx;
>> +             GLuint vert_shader, frag_shader;
>> +             GLuint program;
>> +
>> +             ctx = piglit_get_glx_context(dpy, visinfo);
>> +             glXMakeCurrent(dpy, win, ctx);
>> +
>> +             /* Ok, not nice but should be safe due to all threads working
>> +              * on the same type of context.
>> +                 */
>> +             pthread_mutex_lock(&mutex);
>> +             piglit_dispatch_default_init();
>> +             pthread_mutex_unlock(&mutex);
>> +
>> +             vert_shader = piglit_compile_shader_text(GL_VERTEX_SHADER, vert_shader_text);
>> +             piglit_check_gl_error(GL_NO_ERROR);
>> +
>> +             frag_shader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag_shader_text);
>> +             piglit_check_gl_error(GL_NO_ERROR);
>> +
>> +             program = piglit_link_simple_program(vert_shader, frag_shader);
>> +             piglit_check_gl_error(GL_NO_ERROR);
>> +
>> +             glUseProgram(program);
>> +             piglit_check_gl_error(GL_NO_ERROR);
>> +
>> +             glXDestroyContext(dpy, ctx);
>> +     }
>> +
>> +     return NULL;
>> +}
>> +
>> +int
>> +main(int argc, char **argv)
>> +{
>> +     int ret;
>> +     pthread_t thread1, thread2;
>> +
>> +     pthread_mutex_init(&mutex, NULL);
>> +
>> +     /* Now, spawn some threads that compile simple shaders.
>> +      */
>> +     pthread_create(&thread1, NULL, thread_func, NULL);
>> +     pthread_create(&thread2, NULL, thread_func, NULL);
>> +
>> +     ret = pthread_join(thread1, NULL);
>> +     assert(ret == 0);
>> +     ret = pthread_join(thread2, NULL);
>> +     assert(ret == 0);
>> +
>> +     pthread_mutex_destroy(&mutex);
>> +
>> +     piglit_report_result(PIGLIT_PASS);
>> +     return 0;
>> +}
>> --
>> 1.8.1.4
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list