[Piglit] [PATCH v2] arb_texture_view: Add test for 2d layer as 2d

Emil Velikov emil.l.velikov at gmail.com
Thu Oct 15 17:07:56 PDT 2015


Hi Glenn,

On 16 October 2015 at 00:10, Glenn Kennard <glenn.kennard at gmail.com> wrote:
> Test that layers other than 0 from a 2d layer texture
> can be used in a 2d texture view.
>
> Signed-off-by: Glenn Kennard <glenn.kennard at gmail.com>
> ---
>  tests/all.py                                       |   2 +
>  tests/spec/arb_texture_view/CMakeLists.gl.txt      |   1 +
>  .../sampling-2d-array-as-2d-layer.c                | 195 +++++++++++++++++++++
>  3 files changed, 198 insertions(+)
>  create mode 100644 tests/spec/arb_texture_view/sampling-2d-array-as-2d-layer.c
>
> diff --git a/tests/all.py b/tests/all.py
> index 610d89f..738cec2 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -2451,6 +2451,8 @@ with profile.group_manager(
>        'sampling-2d-array-as-cubemap')
>      g(['arb_texture_view-sampling-2d-array-as-cubemap-array'],
>        'sampling-2d-array-as-cubemap-array')
> +    g(['arb_texture_view-sampling-2d-array-as-2d-layer'],
> +      'sampling-2d-array-as-2d-layer')
>
>  with profile.group_manager(
>          PiglitGLTest,
> diff --git a/tests/spec/arb_texture_view/CMakeLists.gl.txt b/tests/spec/arb_texture_view/CMakeLists.gl.txt
> index 197731a..772f8b4 100644
> --- a/tests/spec/arb_texture_view/CMakeLists.gl.txt
> +++ b/tests/spec/arb_texture_view/CMakeLists.gl.txt
> @@ -23,6 +23,7 @@ piglit_add_executable(arb_texture_view-rendering-formats rendering-formats.c)
>  piglit_add_executable(arb_texture_view-rendering-layers rendering_layers.c common.c)
>  piglit_add_executable(arb_texture_view-rendering-levels rendering_levels.c common.c)
>  piglit_add_executable(arb_texture_view-rendering-target rendering_target.c common.c)
> +piglit_add_executable(arb_texture_view-sampling-2d-array-as-2d-layer sampling-2d-array-as-2d-layer.c)
>  piglit_add_executable(arb_texture_view-sampling-2d-array-as-cubemap-array sampling-2d-array-as-cubemap-array.c)
>  piglit_add_executable(arb_texture_view-sampling-2d-array-as-cubemap sampling-2d-array-as-cubemap.c)
>  piglit_add_executable(arb_texture_view-targets targets.c common.c)
> diff --git a/tests/spec/arb_texture_view/sampling-2d-array-as-2d-layer.c b/tests/spec/arb_texture_view/sampling-2d-array-as-2d-layer.c
> new file mode 100644
> index 0000000..65074d2
> --- /dev/null
> +++ b/tests/spec/arb_texture_view/sampling-2d-array-as-2d-layer.c
> @@ -0,0 +1,195 @@
> +/*
> + * Copyright © 2015 Glenn Kennard
> + *
> + * 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: Glenn Kennard <glenn.kennard at gmail.com>
> + */
> +
> +/**
> + * \file sampling-2d-array-as-2d-layer.c
> + * This tests that you can cast from a 2D Array texture to a regular 2D texture
> + * with layer>0 and sample from the latter.
> + */
> +
> +#include "piglit-util-gl.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +       config.supports_gl_compat_version = 30;
> +//     config.supports_gl_core_version = 32;
> +       config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static const float green[] = {0, 1, 0, 1};
> +static const float red[] = {1, 0, 0, 1};
> +
> +typedef struct Params {
> +       int num_layers;
> +       int width;
> +       int height;
> +       const char * const desc;
> +} Params;
> +
Bikeshed: Drop the typedef ?

> +/* test a few size combinations that tend to require particular alignment
> +   requirements by the hardware */
> +static const Params testparams[] = {
> +       { 8, 1, 1, "1x1" },
> +       { 3, 2, 1, "2x1" },
> +       { 3, 8, 1, "8x1" },
> +       { 1, 16, 1, "16x1" },
> +       { 5, 1, 16, "1x16" },
> +       { 9, 32, 32, "32x32" },
> +       { 2, 64, 64, "64x64" },
> +       { 4, 128, 64, "128x64" },
> +       { 3, 35, 67, "35x67" }
> +};
> +
> +static float *makesolidimage(int w, int h, const float color[4])
> +{
> +       float *p = malloc(w * h * 4 * sizeof(GLfloat));
> +       size_t n;
> +       assert(p);
> +       for (n = 0; n < w * h; n++) {
> +               p[n*4 + 0] = color[0];
> +               p[n*4 + 1] = color[1];
> +               p[n*4 + 2] = color[2];
> +               p[n*4 + 3] = color[3];
> +       }
> +       return p;
> +}
> +
> +static bool
> +test_single_layer(const Params* p, int layer)
> +{
> +       int l;
> +       GLuint tex_src, tex_view;
> +       GLboolean pass;
bool pass;

> +       GLfloat *image;
> +
> +       assert(layer < p->num_layers);
> +
> +       glGenTextures(1, &tex_src);
> +       glBindTexture(GL_TEXTURE_2D_ARRAY, tex_src);
> +
> +       glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, p->width, p->height, p->num_layers);
> +
> +       /* load each array layer with red */
> +       image = makesolidimage(p->width, p->height, red);
> +       for (l = 0; l < p->num_layers; l++) {
> +               glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l,
> +                               p->width, p->height, 1, GL_RGBA, GL_FLOAT, image);
> +       }
> +
> +       /* make layer to check red, but green for pixel at (0,0) which should be the only one sampled */
> +       memcpy(image, green, sizeof(green));
> +
> +       glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layer,
> +                       p->width, p->height, 1, GL_RGBA, GL_FLOAT, image);
> +
> +       free(image);
> +
> +       glGenTextures(1, &tex_view);
> +       /* checked layer is supposed to be green */
> +       glTextureView(tex_view, GL_TEXTURE_2D, tex_src, GL_RGBA8,
> +                     0, 1, layer, 1);
> +       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
> +       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
> +       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
> +       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
> +
> +       glBindTexture(GL_TEXTURE_2D, tex_view);
> +
> +       /* draw it! */
> +       piglit_draw_rect(-1, -1, 2, 2);
> +
> +       pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green);
> +       if (!pass) {
> +               printf("layer %d failed\n", layer);
> +       }
> +
> +       glDeleteTextures(1, &tex_view);
> +       glDeleteTextures(1, &tex_src);
> +
> +       return pass;
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +       GLboolean pass = GL_TRUE;
bool pass = true;

> +       size_t n;
> +       int layer;
> +
> +       glViewport(0, 0, piglit_width, piglit_height);
> +       glClearColor(0.0, 0.0, 1.0, 1.0);
> +
> +       for (n = 0; n < ARRAY_SIZE(testparams); n++) {
> +               GLboolean subtest_pass = GL_TRUE;
bool subtest_pass = true;

> +               for (layer = 0; layer < testparams[n].num_layers; layer++) {
> +                       glClear(GL_COLOR_BUFFER_BIT);
> +
> +                       subtest_pass &= test_single_layer(&testparams[n], layer);
subtest_pass = test_foo() && subtest_pass;

> +               }
> +               piglit_report_subtest_result(subtest_pass ? PIGLIT_PASS : PIGLIT_FAIL,
> +                       testparams[n].desc);
> +               pass &= subtest_pass;
pass = subtest_pass && pass;

Without these we might bail on the remaining tests, if one fails.

-Emil


More information about the Piglit mailing list