[Piglit] [PATCH] msaa: Verify proper operation of alpha blending.
Anuj Phogat
anuj.phogat at gmail.com
Tue Aug 14 11:53:13 PDT 2012
On Mon, Aug 13, 2012 at 2:54 PM, Paul Berry <stereotype441 at gmail.com> wrote:
> A bug has been discovered in Mesa's implementation of MSAA for
> i965/Gen7 when alpha blending is in use. This test is a minor
> revision of the test case from the bug report.
>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=53077
> ---
> tests/all.tests | 1 +
> .../ext_framebuffer_multisample/CMakeLists.gl.txt | 1 +
> .../ext_framebuffer_multisample/alpha-blending.c | 105 ++++++++++++++++++++
> 3 files changed, 107 insertions(+), 0 deletions(-)
> create mode 100644 tests/spec/ext_framebuffer_multisample/alpha-blending.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index e317d15..9419e73 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -1381,6 +1381,7 @@ ext_framebuffer_multisample['negative-readpixels'] = concurrent_test('ext_frameb
> ext_framebuffer_multisample['renderbufferstorage-samples'] = concurrent_test('ext_framebuffer_multisample-renderbufferstorage-samples')
> ext_framebuffer_multisample['renderbuffer-samples'] = concurrent_test('ext_framebuffer_multisample-renderbuffer-samples')
> ext_framebuffer_multisample['samples'] = concurrent_test('ext_framebuffer_multisample-samples')
> +ext_framebuffer_multisample['alpha-blending'] = PlainExecTest('ext_framebuffer_multisample-alpha-blending -auto')
>
> for num_samples in MSAA_SAMPLE_COUNTS:
> for test_type in ('color', 'srgb', 'stencil_draw', 'stencil_resolve',
> diff --git a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
> index ec5d05f..e486613 100644
> --- a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
> +++ b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
> @@ -10,6 +10,7 @@ link_libraries (
> )
>
> piglit_add_executable (ext_framebuffer_multisample-accuracy common.cpp accuracy.cpp)
> +piglit_add_executable (ext_framebuffer_multisample-alpha-blending alpha-blending.c)
> piglit_add_executable (ext_framebuffer_multisample-alpha-to-one-msaa-disabled common.cpp
> draw-buffers-common.cpp alpha-to-one-msaa-disabled.cpp)
> piglit_add_executable (ext_framebuffer_multisample-alpha-to-one-single-sample-buffer common.cpp
> diff --git a/tests/spec/ext_framebuffer_multisample/alpha-blending.c b/tests/spec/ext_framebuffer_multisample/alpha-blending.c
> new file mode 100644
> index 0000000..013def3
> --- /dev/null
> +++ b/tests/spec/ext_framebuffer_multisample/alpha-blending.c
> @@ -0,0 +1,105 @@
> +/*
> + * 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 alpha-blending.c
> + *
> + * This test checks for Mesa bug 53077 (Output error with msaa when
> + * both of framebuffer and source color's alpha are not 1). The test
> + * operates by drawing a partially transparent non-square rectangle to
> + * a multisampled buffer (using a triangle fan) and then blitting the
> + * result to the screen. If the bug is present, artifacts will appear
> + * along the rectangle diagonal due to alpha blending being performed
> + * incorrectly while drawing the first triangle of the fan.
> + *
> + * See also https://bugs.freedesktop.org/show_bug.cgi?id=53077
> + */
> +
> +#include "piglit-util-gl-common.h"
> +
> +GLuint framebuffer, renderbuffer;
> +#define WIDTH 300
> +#define HEIGHT 350
> +int numSamples;
> +
> +PIGLIT_GL_TEST_MAIN(
> + WIDTH,
> + HEIGHT,
> + GLUT_DOUBLE| GLUT_RGBA | GLUT_ALPHA);
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + glGetIntegerv(GL_MAX_SAMPLES_EXT, &numSamples);
> +
> + glGenFramebuffersEXT(1, &framebuffer);
> + glGenRenderbuffersEXT(1, &renderbuffer);
> + glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer);
> + glBindRenderbufferEXT(GL_RENDERBUFFER, renderbuffer);
> + glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, numSamples, GL_RGBA, WIDTH, HEIGHT);
> + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
> + glEnable (GL_MULTISAMPLE);
> +}
> +
> +enum piglit_result
> +piglit_display()
> +{
> + GLenum src_factor, dst_factor;
> + float expected_color[] = { 0.0, 0.7, 0.0, 0.79 };
> + int x0 = 140;
> + int x1 = 220;
> + int y0 = 55;
> + int y1 = 165;
> + bool pass = true;
> + float vertex_data[][2] = {
> + { ((float) x0)/WIDTH * 2.0 - 1.0, ((float) y0)/HEIGHT * 2.0 - 1.0 },
> + { ((float) x1)/WIDTH * 2.0 - 1.0, ((float) y0)/HEIGHT * 2.0 - 1.0 },
> + { ((float) x1)/WIDTH * 2.0 - 1.0, ((float) y1)/HEIGHT * 2.0 - 1.0 },
> + { ((float) x0)/WIDTH * 2.0 - 1.0, ((float) y1)/HEIGHT * 2.0 - 1.0 },
> + };
> +
> + glBindFramebufferEXT(GL_FRAMEBUFFER,framebuffer);
> +
> + glClearColor(0.0, 0.0, 0.0, 1.0);
> + glClear(GL_COLOR_BUFFER_BIT);
> +
> + glEnable(GL_BLEND);
> + src_factor = GL_SRC_ALPHA;
> + dst_factor = GL_ONE_MINUS_SRC_ALPHA;
> + glBlendFunc (src_factor, dst_factor);
> + glColor4f (0.0, 1.0, 0.0, 0.7);
> + glVertexPointer(2, GL_FLOAT, 0, vertex_data);
> + glEnableClientState(GL_VERTEX_ARRAY);
> + glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
> +
> + glBindFramebufferEXT(GL_READ_FRAMEBUFFER, framebuffer);
> + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
> + glBlitFramebuffer(0, 0, WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);
> + glBindFramebuffer(GL_FRAMEBUFFER, 0);
> +
> + pass = piglit_probe_rect_rgba(x0, y0, x1 - x0, y1 - y0, expected_color)
> + && pass;
> +
> + piglit_present_results();
> +
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> --
> 1.7.7.6
>
Looks good to me.
Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>
More information about the Piglit
mailing list