[Piglit] [PATCH 1/4] implement new texture swizzle test
Ian Romanick
idr at freedesktop.org
Sat Apr 26 15:48:33 PDT 2014
On 04/24/2014 01:54 PM, Brian Paul wrote:
> The original one didn't test the GL_ONE and GL_ZERO terms and was
> pretty compilicated. This tests all swizzle combinations and is
> much simpler.
> ---
> tests/all.py | 1 +
> tests/spec/ext_texture_swizzle/CMakeLists.gl.txt | 1 +
> tests/spec/ext_texture_swizzle/swizzle.c | 173 ++++++++++++++++++++++
> 3 files changed, 175 insertions(+)
> create mode 100644 tests/spec/ext_texture_swizzle/swizzle.c
>
> diff --git a/tests/all.py b/tests/all.py
> index 080b432..0665567 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -2644,6 +2644,7 @@ for stage in ['vs', 'gs', 'fs']:
> ext_texture_swizzle = {}
> spec['EXT_texture_swizzle'] = ext_texture_swizzle
> add_plain_test(ext_texture_swizzle, 'tex-swizzle')
> +add_concurrent_test(ext_texture_swizzle, 'ext_texture_swizzle-swizzle')
> ext_texture_swizzle['depth_texture_mode_and_swizzle'] = concurrent_test('depth_texture_mode_and_swizzle')
>
> ext_texture_compression_latc = {}
> diff --git a/tests/spec/ext_texture_swizzle/CMakeLists.gl.txt b/tests/spec/ext_texture_swizzle/CMakeLists.gl.txt
> index 047a199..70ecb1c 100644
> --- a/tests/spec/ext_texture_swizzle/CMakeLists.gl.txt
> +++ b/tests/spec/ext_texture_swizzle/CMakeLists.gl.txt
> @@ -10,5 +10,6 @@ link_libraries (
> )
>
> piglit_add_executable (depth_texture_mode_and_swizzle depth_texture_mode_and_swizzle.c)
> +piglit_add_executable (ext_texture_swizzle-swizzle swizzle.c)
>
> # vim: ft=cmake:
> diff --git a/tests/spec/ext_texture_swizzle/swizzle.c b/tests/spec/ext_texture_swizzle/swizzle.c
> new file mode 100644
> index 0000000..ead6711
> --- /dev/null
> +++ b/tests/spec/ext_texture_swizzle/swizzle.c
> @@ -0,0 +1,173 @@
> +/*
> + * Copyright © 2014 VMware, Inc.
> + *
> + * 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.
> + */
> +
> +/*
> + * Test GL_EXT_texture_swizzle (including the _ZERO and _ONE terms).
> + * Brian Paul
> + * 24 April 2014
> + */
> +
> +
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> + config.supports_gl_compat_version = 12;
> + config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +
> +#define RED 0.2f
> +#define GREEN 0.4f
> +#define BLUE 0.6f
> +#define ALPHA 0.8f
> +
> +
> +static float
> +get_component_color(GLenum swz)
> +{
> + switch (swz) {
> + case GL_RED:
> + return RED;
> + case GL_GREEN:
> + return GREEN;
> + case GL_BLUE:
> + return BLUE;
> + case GL_ALPHA:
> + return ALPHA;
> + case GL_ZERO:
> + return 0.0f;
> + case GL_ONE:
> + return 1.0f;
> + default:
> + assert(!"Invalid swizzle term");
> + return 0.0;
> + }
> +}
> +
> +
> +static void
> +get_expected_color(GLenum swz_r, GLenum swz_g, GLenum swz_b, GLenum swz_a,
> + float expected[4])
Some funky indentation here.
> +{
> + expected[0] = get_component_color(swz_r);
> + expected[1] = get_component_color(swz_g);
> + expected[2] = get_component_color(swz_b);
> + expected[3] = get_component_color(swz_a);
> +}
> +
> +
> +static bool
> +test_swizzle(GLenum swz_r, GLenum swz_g, GLenum swz_b, GLenum swz_a)
> +{
> + float expected[4];
> + bool p;
> +
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R_EXT, swz_r);
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G_EXT, swz_g);
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B_EXT, swz_b);
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A_EXT, swz_a);
> +
> + if (!piglit_check_gl_error(GL_NO_ERROR))
> + return false;
> +
> + get_expected_color(swz_r, swz_g, swz_b, swz_a, expected);
> +
> + piglit_draw_rect_tex(-1.0, -1.0, 2.0, 2.0,
> + 0.0, 0.0, 1.0, 1.0);
I usually like tests better that draw all of the cases at once. That
makes it easier to see the failures (on the screen), and it makes them
run much faster in simulation. This is how the old tex-swizzle test
worked. I think we could do this with a lot less complexity (versus
tex-swizzle) by doing a 36x36 grid of 2x2 squares. Adding an x and y
parameter to test_swizzle, and the draw+probe becomes:
piglit_draw_rect_tex(x, y, 2, 2, 0.0, 0.0, 1.0, 1.0);
p = piglit_probe_pixel_rgba(x + 1, y + 1, expected);
You'll also need to set the minimum window width and height to 36 * 3.
> + p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected);
> +
> + piglit_present_results();
Move the piglit_present_results to after the loops in piglit_display...
> +
> + return p;
> +}
> +
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> + static const GLenum swizzle_terms[6] = {
> + GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_ZERO, GL_ONE
> + };
> + bool pass = true;
> + int num_failures = 0;
> + int r, g, b, a;
> +
glClearColor(0.5, 0.5, 0.5, 0.5);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
piglit_ortho_projection(piglit_width, piglit_height, false);
y = 0;
> + for (r = 0; r < 6; r++) {
> + for (g = 0; g < 6; g++) {
x = 0;
> + for (b = 0; b < 6; b++) {
> + for (a = 0; a < 6; a++) {
> + bool p = test_swizzle(swizzle_terms[r],
> + swizzle_terms[g],
> + swizzle_terms[b],
> + swizzle_terms[a])
> + && pass;
> + if (!p) {
> + /* give up after 10 failures */
> + num_failures++;
> + if (num_failures >= 10)
> + return PIGLIT_FAIL;
> + }
> + pass = pass && p;
x += 3;
> + }
> + }
y += 3;
> + }
> + }
> +
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +
> +static void
> +setup_texture(void)
> +{
> + GLfloat image[8][8][4];
> + int i, j;
> + GLuint tex;
> +
> + for (i = 0; i < 8; i++) {
> + for (j = 0; j < 8; j++) {
> + image[i][j][0] = RED;
> + image[i][j][1] = GREEN;
> + image[i][j][2] = BLUE;
> + image[i][j][3] = ALPHA;
> + }
> + }
> +
> + glGenTextures(1, &tex);
> + glBindTexture(GL_TEXTURE_2D, tex);
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
> + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_FLOAT, image);
> + glEnable(GL_TEXTURE_2D);
> + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
> +}
> +
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + piglit_require_extension("GL_EXT_texture_swizzle");
> +
> + setup_texture();
> +}
>
More information about the Piglit
mailing list