[Piglit] [PATCH v2 1/1] viewport-clamp: to test the viewport clamping
Nanley Chery
nanleychery at gmail.com
Fri Feb 22 22:16:00 UTC 2019
On Thu, Feb 21, 2019 at 08:30:59PM +0200, Eleni Maria Stea wrote:
> A test to check the viewport clamping and to reproduce the following bug
> on i965:
>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=108999
>
> v2:
> - Renamed the test to something more relevant (Nanley Chery)
> - Fixed the description (Nanley Chery)
> - Used the piglit_build_simple_program function instead of my own code
> to compile and link the shaders (Nanley Chery)
> ---
> tests/general/CMakeLists.gl.txt | 1 +
> tests/general/viewport-clamp.c | 116 ++++++++++++++++++++++++++++++++
> tests/opengl.py | 1 +
> 3 files changed, 118 insertions(+)
> create mode 100644 tests/general/viewport-clamp.c
>
> diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
> index 83189fc42..a0da78bbe 100644
> --- a/tests/general/CMakeLists.gl.txt
> +++ b/tests/general/CMakeLists.gl.txt
> @@ -132,5 +132,6 @@ piglit_add_executable (clear-accum clear-accum.c)
> piglit_add_executable (vs-point_size-zero vs-point_size-zero.c)
> piglit_add_executable (triangle-guardband-viewport triangle-guardband-viewport.c)
> piglit_add_executable (teximage-scale-bias teximage-scale-bias.c)
> +piglit_add_executable (viewport-clamp viewport-clamp.c)
>
> # vim: ft=cmake:
> diff --git a/tests/general/viewport-clamp.c b/tests/general/viewport-clamp.c
> new file mode 100644
> index 000000000..3ac353bbf
> --- /dev/null
> +++ b/tests/general/viewport-clamp.c
> @@ -0,0 +1,116 @@
> +/*
> + * Copyright © 2019 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.
> + *
> + * Author:
> + * Eleni Maria Stea <estea at igalia.com>
> + */
> +
> +/* The purpose of this test is to validate the viewport clamping
> + * when the Y is flipped (0 on top). It can be used to reproduce this bug:
> + * https://bugs.freedesktop.org/show_bug.cgi?id=108999
> + * and test the fix: https://patchwork.freedesktop.org/series/53830/
> + */
> +
> +#include "piglit-util-gl.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +config.supports_gl_compat_version = 20;
Vertex array objects aren't part of OpenGL until version 3.0.
> +config.window_width = 800;
> +config.window_height = 600;
> +config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
> +config.khr_no_error_support = PIGLIT_NO_ERRORS;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static int piglit_error;
> +static unsigned int vao, vbo;
> +static unsigned int sdrprog;
> +static const float varr[] = { -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 };
> +
> +static const char *vsdr_src =
> + "attribute vec4 vertex;\n"
> + "void main()\n" "{\n" "gl_Position = vertex;\n" "}\n";
> +
> +static const char *fsdr_src =
> + "void main()\n"
> + "{\n" "gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" "}\n";
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + int status;
> +
> + glGenBuffers(1, &vbo);
> + glBindBuffer(GL_ARRAY_BUFFER, vbo);
> + glBufferData(GL_ARRAY_BUFFER, sizeof varr, varr, GL_STATIC_DRAW);
> +
> + glGenVertexArrays(1, &vao);
> + glBindVertexArray(vao);
> + glEnableVertexAttribArray(0);
> + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
> + glBindBuffer(GL_ARRAY_BUFFER, 0);
> + glBindVertexArray(0);
> +
> + sdrprog = piglit_build_simple_program(vsdr_src, fsdr_src);
I just discovered that there's an ""_unlinked() variant of this
function.
-Nanley
> +
> + glBindAttribLocation(sdrprog, 0, "vertex");
> + glLinkProgram(sdrprog);
> +
> + glGetProgramiv(sdrprog, GL_LINK_STATUS, &status);
> + if (!status) {
> + fprintf(stderr, "failed to link program\n");
> + piglit_error = 1;
> + return;
> + }
> +
> + glUseProgram(sdrprog);
> +
> + if (glGetError() != GL_NO_ERROR)
> + piglit_error = 1;
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> + if (piglit_error)
> + return PIGLIT_FAIL;
> +
> + glBindVertexArray(vao);
> +
> + glViewport(2, 602, 262, 296);
> +
> + glDrawArrays(GL_TRIANGLES, 0, 6);
> +
> + glViewport(0, 0, 800, 600);
> +
> + glDrawArrays(GL_TRIANGLES, 0, 6);
> +
> + glBindVertexArray(0);
> +
> + if (glGetError() != GL_NO_ERROR)
> + return PIGLIT_FAIL;
> +
> + piglit_swap_buffers();
> +
> + return PIGLIT_PASS;
> +}
> diff --git a/tests/opengl.py b/tests/opengl.py
> index d6cfa0986..500a874a9 100644
> --- a/tests/opengl.py
> +++ b/tests/opengl.py
> @@ -878,6 +878,7 @@ with profile.test_list.group_manager(
> g(['incomplete-cubemap', 'format'], 'incomplete-cubemap-format')
> g(['gl-2.0-texture-units'])
> g(['gl-2.0-uniform-neg-location'])
> + g(['viewport-clamp'])
>
> with profile.test_list.group_manager(
> PiglitGLTest,
> --
> 2.20.1
>
More information about the Piglit
mailing list