[Piglit] [PATCH] msaa: Test that multisampled blits can flip the image in the X or Y direction.

Anuj Phogat anuj.phogat at gmail.com
Thu Sep 6 18:24:33 PDT 2012


On Wed, Sep 5, 2012 at 5:25 PM, Paul Berry <stereotype441 at gmail.com> wrote:
> ---
>  tests/all.tests                                    |    9 +
>  .../ext_framebuffer_multisample/CMakeLists.gl.txt  |    1 +
>  .../ext_framebuffer_multisample/blit-flipped.cpp   |  183 ++++++++++++++++++++
>  3 files changed, 193 insertions(+), 0 deletions(-)
>  create mode 100644 tests/spec/ext_framebuffer_multisample/blit-flipped.cpp
>
> diff --git a/tests/all.tests b/tests/all.tests
> index 85f2691..6f9982b 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -1551,6 +1551,15 @@ for num_samples in MSAA_SAMPLE_COUNTS:
>                  ext_framebuffer_multisample[test_name] = PlainExecTest(
>                          executable)
>
> +for num_samples in MSAA_SAMPLE_COUNTS:
> +        for flip_direction in ('x', 'y'):
> +                test_name = ' '.join(['blit-flipped', str(num_samples),
> +                                      flip_direction])
> +                executable = 'ext_framebuffer_multisample-{0} -auto'.format(
> +                        test_name)
> +                ext_framebuffer_multisample[test_name] = PlainExecTest(
> +                        executable)
> +
>  # Note: the interpolation tests also check for sensible behaviour with
>  # non-multisampled framebuffers, so go ahead and test them with
>  # num_samples==0 as well.
> diff --git a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
> index fabe229..1542b92 100644
> --- a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
> +++ b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
> @@ -22,6 +22,7 @@ piglit_add_executable (ext_framebuffer_multisample-alpha-to-one-msaa-disabled co
>  piglit_add_executable (ext_framebuffer_multisample-alpha-to-one-single-sample-buffer common.cpp
>                        draw-buffers-common.cpp alpha-to-one-single-sample-buffer.cpp)
>  piglit_add_executable (ext_framebuffer_multisample-bitmap common.cpp bitmap.cpp)
> +piglit_add_executable (ext_framebuffer_multisample-blit-flipped common.cpp blit-flipped.cpp)
>  piglit_add_executable (ext_framebuffer_multisample-blit-mismatched-samples common.cpp blit-mismatched-samples.cpp)
>  piglit_add_executable (ext_framebuffer_multisample-blit-mismatched-sizes common.cpp blit-mismatched-sizes.cpp)
>  piglit_add_executable (ext_framebuffer_multisample-blit-mismatched-formats common.cpp blit-mismatched-formats.cpp)
> diff --git a/tests/spec/ext_framebuffer_multisample/blit-flipped.cpp b/tests/spec/ext_framebuffer_multisample/blit-flipped.cpp
> new file mode 100644
> index 0000000..4d1250e
> --- /dev/null
> +++ b/tests/spec/ext_framebuffer_multisample/blit-flipped.cpp
> @@ -0,0 +1,183 @@
> +/*
> + * Copyright © 2012 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 blit-flipped.cpp
> + *
> + * From the GL 4.3 spec, section 18.3.1 "Blitting Pixel Rectangles":
> + *
> + *     If SAMPLE_BUFFERS for either the read framebuffer or draw
> + *     framebuffer is greater than zero, no copy is performed and an
> + *     INVALID_OPERATION error is generated if the dimensions of the
> + *     source and destination rectangles provided to BlitFramebuffer
> + *     are not identical, or if the formats of the read and draw
> + *     framebuffers are not identical.
> + *
> + * It is not clear from the spec whether "dimensions" should mean both
> + * sign and magnitude, or just magnitude.  However, Y flips are likely
> + * to be commonplace in OpenGL applications that have been ported from
> + * DirectX applications, as a result of the fact that DirectX and
> + * OpenGL differ in their orientation of the Y axis.  Furthermore, at
> + * least one commercial driver (nVidia) permits Y flips, and L4D2
> + * relies on them being permitted.  So it seems prudent to assume that
> + * "dimensions" means just magnitude, not sign.
> + *
> + * This test verifies that a blit from a multisampled buffer to a
> + * single-sampled buffer is permitted to flip either in the X or Y
> + * direction, and that the resulting image is the same as what would
> + * be obtained by doing a non-flipped blit to a single-sampled buffer,
> + * and then a second blit that performs a flip.
> + */
> +
> +#include "common.h"
> +
> +const int pattern_width = 256; const int pattern_height = 256;
> +
> +PIGLIT_GL_TEST_MAIN(pattern_width * 2,
> +                   pattern_height,
> +                   GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);
> +
> +static Fbo multisampled_fbo, singlesampled_fbo;
> +static TestPattern *test_pattern;
> +static GLint srcX0, srcY0, srcX1, srcY1;
> +
> +static void
> +print_usage_and_exit(char *prog_name)
> +{
> +       printf("Usage: %s <num_samples> <flip_direction>\n"
> +              "  where <flip_direction> is either x or y\n",
> +              prog_name);
> +       piglit_report_result(PIGLIT_FAIL);
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +       if (argc != 3)
> +               print_usage_and_exit(argv[0]);
> +
> +       /* 1st arg: num_samples */
> +       char *endptr = NULL;
> +       int num_samples = strtol(argv[1], &endptr, 0);
> +       if (endptr != argv[1] + strlen(argv[1]))
> +               print_usage_and_exit(argv[0]);
> +
> +       /* 2nd arg: flip_direction */
> +       if (strcmp(argv[2], "x") == 0) {
> +               srcX0 = pattern_width;
> +               srcX1 = 0;
> +               srcY0 = 0;
> +               srcY1 = pattern_height;
> +       } else if (strcmp(argv[2], "y") == 0) {
> +               srcX0 = 0;
> +               srcX1 = pattern_width;
> +               srcY0 = pattern_height;
> +               srcY1 = 0;
> +       } else {
> +               print_usage_and_exit(argv[0]);
> +       }
> +
> +       piglit_require_gl_version(30);
> +
> +       /* Skip the test if num_samples > GL_MAX_SAMPLES */
> +       GLint max_samples;
> +       glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
> +       if (num_samples > max_samples)
> +               piglit_report_result(PIGLIT_SKIP);
> +
> +       singlesampled_fbo.setup(FboConfig(0,
> +                                         pattern_width,
> +                                         pattern_height));
> +
> +       multisampled_fbo.setup(FboConfig(num_samples,
> +                                        pattern_width,
> +                                        pattern_height));
> +
> +       test_pattern = new Triangles();
> +       test_pattern->compile();
> +
> +       if (!piglit_check_gl_error(GL_NO_ERROR)) {
> +               piglit_report_result(PIGLIT_FAIL);
> +       }
> +}
> +
> +enum piglit_result
> +piglit_display()
> +{
> +       bool pass = true;
> +
> +       /* Draw the test pattern into the multisampled buffer. */
> +       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, multisampled_fbo.handle);
> +       multisampled_fbo.set_viewport();
> +       test_pattern->draw(TestPattern::no_projection);
> +
> +       /* Blit it to a single-sampled buffer, flipping the
> +        * appropriate coordinate.  This will only work if the
> +        * implementation allows multisampled blits to be flipped.
> +        */
> +       glBindFramebuffer(GL_READ_FRAMEBUFFER, multisampled_fbo.handle);
> +       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, singlesampled_fbo.handle);
> +       glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1,
> +                         0, 0, pattern_width, pattern_height,
> +                         GL_COLOR_BUFFER_BIT, GL_NEAREST);
> +       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
> +
> +       /* Blit the resulting image to the screen, performing no
> +        * additional flip.  This is the test image.
> +        */
> +       glBindFramebuffer(GL_READ_FRAMEBUFFER, singlesampled_fbo.handle);
> +       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
> +       glBlitFramebuffer(0, 0, pattern_width, pattern_height,
> +                         0, 0, pattern_width, pattern_height,
> +                         GL_COLOR_BUFFER_BIT, GL_NEAREST);
> +
> +       /* Blit the test pattern into the single-sampled buffer with
> +        * no flip.  This should always work.
> +        */
> +       glBindFramebuffer(GL_READ_FRAMEBUFFER, multisampled_fbo.handle);
> +       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, singlesampled_fbo.handle);
> +       glBlitFramebuffer(0, 0, pattern_width, pattern_height,
> +                         0, 0, pattern_width, pattern_height,
> +                         GL_COLOR_BUFFER_BIT, GL_NEAREST);
> +
> +       /* Blit the resulting image to the screen, flipping the
> +        * appropriate coordinate, to produce the reference image.
> +        * This should always work (since it is blitting from
> +        * single-sampled to single-sampled).
> +        */
> +       glBindFramebuffer(GL_READ_FRAMEBUFFER, singlesampled_fbo.handle);
> +       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
> +       glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1,
> +                         pattern_width, 0, 2*pattern_width, pattern_height,
> +                         GL_COLOR_BUFFER_BIT, GL_NEAREST);
> +
> +       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
> +
> +       /* Compare the test and reference images. */
> +       glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
> +       pass = piglit_probe_rect_halves_equal_rgba(0, 0, 2*pattern_width,
> +                                                  pattern_height) && pass;
> +
> +       piglit_present_results();
> +
> +       return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> --
> 1.7.7.6
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit

Test passes after applying relevant mesa patch.
Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>


More information about the Piglit mailing list