[Piglit] [PATCH 1/2] shaders: add test to check (0 cmp x+y) optimization

Samuel Iglesias Gonsálvez siglesias at igalia.com
Fri Feb 27 05:57:51 PST 2015


This patch is meant to check that a Mesa patch [0] fixes a bug in (0 cmp
x+y) optimization, as it was suggested by Ian [1]. Patch 2/2 checks (x+y
cmp 0) optimization.

My idea is to push these patches into master branch next week in order
to have everything in place before pushing Mesa patch [0]. I am going to
wait some days more before pushing them, just in case someone wants to
review them.

Thanks,

Sam

[0]
http://lists.freedesktop.org/archives/mesa-dev/2015-February/077740.html
[1]
http://lists.freedesktop.org/archives/mesa-dev/2015-February/077767.html


On Wed, 2015-02-25 at 15:03 +0100, Samuel Iglesias Gonsalvez wrote:
> ---
>  tests/all.py                      |   1 +
>  tests/shaders/CMakeLists.gl.txt   |   1 +
>  tests/shaders/glsl-opt-0-cmp-xy.c | 130 ++++++++++++++++++++++++++++++++++++++
>  3 files changed, 132 insertions(+)
>  create mode 100644 tests/shaders/glsl-opt-0-cmp-xy.c
> 
> diff --git a/tests/all.py b/tests/all.py
> index 40f38cf..d07ae35 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -506,6 +506,7 @@ add_concurrent_test(shaders, ['glsl-link-bug30552'])
>  add_concurrent_test(shaders, ['glsl-link-bug38015'])
>  add_concurrent_test(shaders, ['glsl-link-empty-prog-01'])
>  add_concurrent_test(shaders, ['glsl-link-empty-prog-02'])
> +add_concurrent_test(shaders, ['glsl-opt-0-cmp-xy'])
>  shaders['GLSL link single global initializer, 2 shaders'] = \
>      PiglitGLTest(['glsl-link-test',
>                    os.path.join('shaders', 'glsl-link-initializer-01a.vert'),
> diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt
> index 3efc6bf..521282b 100644
> --- a/tests/shaders/CMakeLists.gl.txt
> +++ b/tests/shaders/CMakeLists.gl.txt
> @@ -145,6 +145,7 @@ piglit_add_executable (glsl-routing glsl-routing.c)
>  piglit_add_executable (shader_runner shader_runner.c parser_utils.c)
>  piglit_add_executable (glsl-vs-point-size glsl-vs-point-size.c)
>  piglit_add_executable (glsl-sin glsl-sin.c)
> +piglit_add_executable (glsl-opt-0-cmp-xy glsl-opt-0-cmp-xy.c)
>  IF (UNIX)
>  	target_link_libraries(glsl-sin m)
>  ENDIF (UNIX)
> diff --git a/tests/shaders/glsl-opt-0-cmp-xy.c b/tests/shaders/glsl-opt-0-cmp-xy.c
> new file mode 100644
> index 0000000..65cb555
> --- /dev/null
> +++ b/tests/shaders/glsl-opt-0-cmp-xy.c
> @@ -0,0 +1,130 @@
> +/*
> + * Copyright © 2015 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:
> + *    Samuel Iglesias Gonsalvez <siglesias at igalia.com>
> + *
> + */
> +
> +/** @file glsl-opt-0-cmp-xy.c
> + *
> + * It checks (0 cmp x+y) optimization (if any) works fine.
> + *
> + * Test renders two rectangles: left rect's color is green, right rect's color
> + * is red. Left rectangle's width is one pixel larger than right rectangle's.
> + *
> + */
> +
> +#include "piglit-util-gl.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +        config.supports_gl_compat_version = 10;
> +        config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
> +        config.window_width = 50;
> +        config.window_height = 50;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static char vs_code[] =
> +    "uniform float a;\n"
> +
> +    "void main()\n"
> +    "{\n"
> +    "    gl_Position = ftransform();\n"
> +    "}\n";
> +
> +static char fs_code[] =
> +    "uniform float a;\n"
> +
> +    "void main()\n"
> +    "{\n"
> +    "    if (0.0 >= (a - 1.0))\n"
> +    "        gl_FragColor = vec4(0, 1, 0, 1);\n"
> +    "    else\n"
> +    "        gl_FragColor = vec4(1, 0, 0, 1);\n"
> +    "}\n";
> +
> +static GLuint setup_shaders()
> +{
> +    GLuint vs, fs, prog;
> +
> +    vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_code);
> +    fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_code);
> +    prog = piglit_link_simple_program(vs, fs);
> +
> +    glUseProgram(prog);
> +    return prog;
> +}
> +
> +static GLboolean test()
> +{
> +    GLint prog, location;
> +    GLboolean pass = GL_TRUE;
> +    int i;
> +    float color[4] = {0, 0, 0, 1};
> +
> +    prog = setup_shaders();
> +    location = glGetUniformLocation(prog, "a");
> +
> +    for (i = 0; i < 49; i++) {
> +        glUniform1f(location, (i - 25));
> +        piglit_draw_rect(i, 0, i+1, 50);
> +    }
> +    if (!piglit_check_gl_error(GL_NO_ERROR))
> +        piglit_report_result(PIGLIT_FAIL);
> +
> +    for (i = 0; i < 50; i++) {
> +        float val = i - 25;
> +        if (0.0f >= (val - 1.0)) {
> +            color[1] = 1.0f;
> +            color[0] = color[2] = 0.0f;
> +        } else {
> +            color[0] = 1.0f;
> +            color[1] = color[2] = 0.0f;
> +        }
> +        pass = piglit_probe_pixel_rgb(i, 0, color) && pass;
> +    }
> +
> +    return pass;
> +}
> +
> +enum piglit_result piglit_display(void)
> +{
> +    GLboolean pass;
> +
> +    piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
> +
> +    glClearColor(0.5, 0.5, 0.5, 0.5);
> +    glClear(GL_COLOR_BUFFER_BIT);
> +
> +    pass = test();
> +
> +    piglit_present_results();
> +
> +    return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +void piglit_init(int argc, char **argv)
> +{
> +    piglit_require_gl_version(20);
> +}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20150227/c2f93c08/attachment.sig>


More information about the Piglit mailing list