[Piglit] [PATCH 1/3] spec/ARB_copy_image: Add a simple ARB_copy_image test

Brian Paul brianp at vmware.com
Mon Jun 30 10:05:27 PDT 2014


On 06/30/2014 10:49 AM, Jason Ekstrand wrote:
>
>
>
> On Sat, Jun 28, 2014 at 6:28 AM, Brian Paul <brianp at vmware.com
> <mailto:brianp at vmware.com>> wrote:
>
>     On 06/27/2014 05:31 PM, Jason Ekstrand wrote:
>
>         This is a simple sanity test for the ARB_copy_image extension.
>           This tests
>         tests the different combinations of textures and renderbuffers
>         for intputs
>         and outputs to glCopyTexSubImage.
>
>         Signed-off-by: Jason Ekstrand <jason.ekstrand at intel.com
>         <mailto:jason.ekstrand at intel.com>>
>         ---
>            tests/all.py                                |   6 +
>            tests/spec/CMakeLists.txt                   |   1 +
>            tests/spec/arb_copy_image/__CMakeLists.gl.txt |  13 ++
>            tests/spec/arb_copy_image/__CMakeLists.txt    |   1 +
>            tests/spec/arb_copy_image/__simple.c          | 226
>         ++++++++++++++++++++++++++++
>            5 files changed, 247 insertions(+)
>            create mode 100644 tests/spec/arb_copy_image/__CMakeLists.gl.txt
>            create mode 100644 tests/spec/arb_copy_image/__CMakeLists.txt
>            create mode 100644 tests/spec/arb_copy_image/__simple.c
>
>         diff --git a/tests/all.py b/tests/all.py
>         index 17d5d9b..9e6196e 100644
>         --- a/tests/all.py
>         +++ b/tests/all.py
>         @@ -3110,6 +3110,12 @@ arb_copy_buffer['overlap'] =
>         concurrent_test('arb_copy___buffer-overlap')
>            arb_copy_buffer['targets'] =
>         concurrent_test('arb_copy___buffer-targets')
>            arb_copy_buffer['subdata-sync'__] =
>         concurrent_test('arb_copy___buffer-subdata-sync')
>
>         +arb_copy_image = {}
>         +spec['ARB_copy_image'] = arb_copy_image
>         +add_concurrent_test(arb_copy___image, 'arb_copy_image-simple
>         --tex-to-tex')
>         +add_concurrent_test(arb_copy___image, 'arb_copy_image-simple
>         --rb-to-tex')
>         +add_concurrent_test(arb_copy___image, 'arb_copy_image-simple
>         --rb-to-rb')
>         +
>            arb_half_float_vertex = {}
>            spec['ARB_half_float_vertex'] = arb_half_float_vertex
>            add_plain_test(arb_half_float___vertex,
>         'draw-vertices-half-float')
>         diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
>         index 489ff0c..73fe908 100644
>         --- a/tests/spec/CMakeLists.txt
>         +++ b/tests/spec/CMakeLists.txt
>         @@ -4,6 +4,7 @@ add_subdirectory (arb_buffer_storage)
>            add_subdirectory (arb_clear_buffer_object)
>            add_subdirectory (arb_clear_texture)
>            add_subdirectory (arb_color_buffer_float)
>         +add_subdirectory (arb_copy_image)
>            add_subdirectory (arb_compute_shader)
>            add_subdirectory (arb_debug_output)
>            add_subdirectory (khr_debug)
>         diff --git a/tests/spec/arb_copy_image/__CMakeLists.gl.txt
>         b/tests/spec/arb_copy_image/__CMakeLists.gl.txt
>         new file mode 100644
>         index 0000000..ac8ddcc
>         --- /dev/null
>         +++ b/tests/spec/arb_copy_image/__CMakeLists.gl.txt
>         @@ -0,0 +1,13 @@
>         +include_directories(
>         +       ${GLEXT_INCLUDE_DIR}
>         +       ${OPENGL_INCLUDE_PATH}
>         +)
>         +
>         +link_libraries (
>         +       piglitutil_${piglit_target___api}
>         +       ${OPENGL_gl_LIBRARY}
>         +)
>         +
>         +piglit_add_executable (arb_copy_image-simple simple.c)
>         +
>         +# vim: ft=cmake:
>         diff --git a/tests/spec/arb_copy_image/__CMakeLists.txt
>         b/tests/spec/arb_copy_image/__CMakeLists.txt
>         new file mode 100644
>         index 0000000..144a306
>         --- /dev/null
>         +++ b/tests/spec/arb_copy_image/__CMakeLists.txt
>         @@ -0,0 +1 @@
>         +piglit_include_target_api()
>         diff --git a/tests/spec/arb_copy_image/__simple.c
>         b/tests/spec/arb_copy_image/__simple.c
>         new file mode 100644
>         index 0000000..f720c26
>         --- /dev/null
>         +++ b/tests/spec/arb_copy_image/__simple.c
>         @@ -0,0 +1,226 @@
>         +/*
>         + * Copyright 2014 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.
>         + */
>         +
>         +/** @file simple.c
>         + *
>         + * A simple test of glCopyImageSubData that copies a square
>         from one
>         + * 2D texture to another and back.  This test exercises texture
>         to texture,
>         + * texture to renderbuffer, renderbuffer to texture, and
>         renderbuffer to
>         + * renderbuffer copies.
>         + */
>         +#include "piglit-util-gl-common.h"
>         +
>         +PIGLIT_GL_TEST_CONFIG_BEGIN
>         +
>         +       config.supports_gl_compat___version = 13;
>         +
>         +       config.window_width = 128;
>         +       config.window_height = 64;
>
>
>     Does the window size really matter?  If not, please omit those lines
>     and use the default.  If the size does matter, please use width >=
>     160 to allow this to work on Windows.  See the comments in
>     tests/util/piglit-framework-__gl.h for more info.
>
> Fixed that, thanks.  In this case 160x160 is just fine.
>
>
>
>         +       config.window_visual = PIGLIT_GL_VISUAL_RGB |
>         PIGLIT_GL_VISUAL_DOUBLE;
>         +
>         +PIGLIT_GL_TEST_CONFIG_END
>         +
>         +static const float green[3] = {0.0, 1.0, 0.0};
>         +static const float red[3] = {1.0, 0.0, 0.0};
>         +static const float blue[3] = {0.0, 0.0, 1.0};
>         +
>         +int renderbuffers = 0;
>         +
>         +void
>         +piglit_init(int argc, char **argv)
>         +{
>         +       int i;
>         +
>         +       piglit_require_extension("GL___ARB_copy_image");
>         +       piglit_require_extension("GL___EXT_framebuffer_object");
>         +
>         +       for (i = 0; i < argc; ++i) {
>         +               if (strcmp(argv[i], "--tex-to-tex") == 0)
>         +                       renderbuffers = 0;
>         +               else if (strcmp(argv[i], "--tex-to-rb") == 0)
>         +                       renderbuffers = 1;
>         +               else if (strcmp(argv[i], "--rb-to-rb") == 0)
>         +                       renderbuffers = 2;
>         +       }
>         +}
>         +
>         +struct image {
>         +       GLuint name, fbo;
>         +       GLenum target;
>         +};
>         +
>         +void
>         +image_init(struct image *image, GLenum target, GLenum
>         internalformat)
>
>
>     All these local functions should be declared static to avoid
>     compiler warnings.
>
>
> done
>
>
>
>         +{
>         +       image->target = target;
>         +
>         +       glGenFramebuffersEXT(1, &image->fbo);
>         +       glBindFramebufferEXT(GL___FRAMEBUFFER_EXT, image->fbo);
>         +
>         +       if (image->target == GL_RENDERBUFFER_EXT) {
>         +               glGenRenderbuffersEXT(1, &image->name);
>         +               glBindRenderbufferEXT(GL___RENDERBUFFER,
>         image->name);
>         +               glRenderbufferStorageEXT(GL___RENDERBUFFER_EXT,
>         +                                        internalformat, 64, 64);
>         +               glFramebufferRenderbufferEXT(__GL_FRAMEBUFFER_EXT,
>         +
>           GL_COLOR_ATTACHMENT0_EXT,
>         +                                            image->target,
>         image->name);
>         +       } else {
>         +               glGenTextures(1, &image->name);
>         +               glBindTexture(image->target, image->name);
>         +               glTexImage2D(image->target, 0, internalformat,
>         +                            64, 64, 0, internalformat, GL_BYTE,
>         NULL);
>         +               glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
>         GL_NEAREST);
>         +               glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
>         GL_NEAREST);
>         +               glFramebufferTexture2DEXT(GL___FRAMEBUFFER_EXT,
>         +                                         GL_COLOR_ATTACHMENT0_EXT,
>         +                                         image->target,
>         image->name, 0);
>         +       }
>         +}
>         +
>         +void
>         +image_destroy(struct image *image)
>         +{
>         +       if (image->target == GL_RENDERBUFFER_EXT)
>         +               glDeleteRenderbuffersEXT(1, &image->name);
>         +       else
>         +               glDeleteTextures(1, &image->name);
>         +
>         +       glDeleteFramebuffers(1, &image->fbo);
>         +}
>         +
>         +void
>         +image_fill(struct image *image, const float *color)
>         +{
>         +       glClearColor(color[0], color[1], color[2], 1.0f);
>         +       glBindFramebufferEXT(GL___FRAMEBUFFER_EXT, image->fbo);
>         +       glClear(GL_COLOR_BUFFER_BIT);
>         +}
>         +
>         +void
>         +image_draw(struct image *image, int x, int y)
>         +{
>         +       if (image->target == GL_RENDERBUFFER_EXT) {
>         +               glBindFramebufferEXT(GL_READ___FRAMEBUFFER_EXT,
>         image->fbo);
>         +               glBlitFramebufferEXT(0, 0, 64, 64, x, y, x + 64,
>         y + 64,
>         +                                    GL_COLOR_BUFFER_BIT,
>         GL_NEAREST);
>         +       } else {
>         +               /* Set up or GL environment for rendering */
>         +               piglit_ortho_projection(__piglit_width,
>         piglit_height, GL_FALSE);
>         +               glEnable(GL_TEXTURE_2D);
>         +               glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
>         GL_REPLACE);
>         +
>         +               glBindTexture(image->target, image->name);
>         +               piglit_draw_rect_tex(x, y, 64, 64, 0, 0, 1, 1);
>         +
>         +               glDisable(GL_TEXTURE_2D);
>         +       }
>         +}
>         +
>         +void
>         +fill_texture(GLuint name, GLenum target, const float *color,
>         +            int width, int height, int depth)
>         +{
>         +       float *image;
>         +       int i, size;
>         +
>         +       size = width * height * depth;
>         +
>         +       image = malloc(sizeof(float) * 3 * size);
>         +       for (i = 0; i < size; i++)
>         +               memcpy(&image[i*3], color, sizeof(float) * 3);
>         +
>         +       glBindTexture(target, name);
>         +       glTexImage2D(target, 0, GL_RGB, width, height,
>         +                    0, GL_RGB, GL_FLOAT, image);
>         +       glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
>         +       glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
>         +
>         +       free(image);
>         +}
>         +
>         +enum piglit_result
>         +piglit_display(void)
>         +{
>         +       bool pass = true;
>         +       struct image images[2];
>         +
>         +       if (renderbuffers >= 1)
>         +               images[0].target = GL_RENDERBUFFER_EXT;
>         +       else
>         +               images[0].target = GL_TEXTURE_2D;
>         +
>         +       if (renderbuffers == 2)
>         +               images[1].target = GL_RENDERBUFFER_EXT;
>         +       else
>         +               images[1].target = GL_TEXTURE_2D;
>         +
>         +       image_init(&images[0], images[0].target, GL_RGB);
>         +       image_init(&images[1], images[1].target, GL_RGB);
>         +
>         +       image_fill(&images[0], green);
>         +       image_fill(&images[1], red);
>         +
>         +       glCopyImageSubData(images[0].__name, images[0].target,
>         0, 0, 0, 0,
>         +                          images[1].name, images[1].target, 0,
>         17, 11, 0,
>         +                          32, 32, 1);
>         +       pass &= piglit_check_gl_error(GL_NO___ERROR);
>         +
>         +       /* We should now have a green square on red */
>         +       glBindFramebufferEXT(GL_READ___FRAMEBUFFER_EXT,
>         images[1].fbo);
>         +       pass &= piglit_probe_rect_rgb(17, 11, 32, 32, green);
>         +       pass &= piglit_probe_rect_rgb(0, 0, 64, 11, red);
>         +       pass &= piglit_probe_rect_rgb(0, 11, 17, 32, red);
>         +       pass &= piglit_probe_rect_rgb(49, 11, 15, 32, red);
>         +       pass &= piglit_probe_rect_rgb(0, 43, 64, 21, red);
>         +
>         +       image_fill(&images[0], blue);
>         +       glBindFramebufferEXT(GL_READ___FRAMEBUFFER_EXT,
>         images[0].fbo);
>         +       pass &= piglit_probe_rect_rgb(0, 0, 64, 64, blue);
>         +
>         +       glCopyImageSubData(images[1].__name, images[1].target,
>         0, 17, 11, 0,
>         +                          images[0].name, images[0].target, 0,
>         0, 32, 0,
>         +                          32, 32, 1);
>         +       pass &= piglit_check_gl_error(GL_NO___ERROR);
>         +
>         +       /* This should be a green square on blue (no red!) */
>         +       glBindFramebufferEXT(GL_READ___FRAMEBUFFER_EXT,
>         images[0].fbo);
>         +       pass &= piglit_probe_rect_rgb(0, 32, 32, 32, green);
>         +       pass &= piglit_probe_rect_rgb(0, 0, 64, 32, blue);
>         +       pass &= piglit_probe_rect_rgb(32, 32, 32, 32, blue);
>
>
>     In some piglit tests we use the pattern:
>
>         pass = test_something() && pass;
>
>     to report multiple failures.  I'm not sure if you want to do that
>     here though.
>
>
> Yes, that should prevent short-circuiting.  That said, I haven't
> observed any short-circuiting of test functions.  Maybe a GCC thing?

&= is a bitwise operators so it won't get short circuited.  So you can 
disregard my comment.

-Brian



More information about the Piglit mailing list