2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 * Verify that the implementation ignores multisample fragment
28 * operations when performing clears.
30 * This test checks that the following state variables (from GL 3.0
31 * section 4.1.3 "Multisample Fragment Operations") do not apply when
34 * - GL_SAMPLE_ALPHA_TO_COVERAGE
36 * - GL_SAMPLE_ALPHA_TO_ONE
38 * - GL_SAMPLE_COVERAGE
40 * - GL_SAMPLE_COVERAGE_VALUE
42 * - GL_SAMPLE_COVERAGE_INVERT
44 * The test operates by setting the above state variables in a way
45 * that would reduce the sample coverage (for normal GL draw
46 * operations). Then it performs a glClear() and verifies that all
47 * samples of all pixels were cleared.
49 * The test can be run in 3 modes: color, depth, and stencil.
51 * In depth and stencil modes, extra work is required to verify that
52 * all samples are properly cleared. Since a typical MSAA resolve
53 * retains only one sample from each pixel for the depth and stencil
54 * buffers, we need to convert depth/stencil values into colors, then
55 * blit to the screen and check that the resulting color is correct.
56 * The extra work of converting depth/stencil values into colors is
57 * done using the ManifestDepth and ManifestStencil programs from
58 * piglit-test-pattern.h.
61 #include "piglit-test-pattern.h"
62 #include "piglit-fbo.h"
63 using namespace piglit_util_fbo
;
64 using namespace piglit_util_test_pattern
;
66 PIGLIT_GL_TEST_CONFIG_BEGIN
68 config
.supports_gl_compat_version
= 10;
70 config
.window_width
= 256;
71 config
.window_height
= 256;
72 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
73 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
75 PIGLIT_GL_TEST_CONFIG_END
79 const int pattern_width
= 256; const int pattern_height
= 256;
82 ManifestProgram
*manifest_program
= NULL
;
83 GLbitfield buffer_to_test
;
87 print_usage_and_exit(char *prog_name
)
89 printf("Usage: %s <num_samples> <buffer_type>\n"
90 " where <buffer_type> is one of:\n"
95 piglit_report_result(PIGLIT_FAIL
);
100 piglit_init(int argc
, char **argv
)
103 print_usage_and_exit(argv
[0]);
105 /* 1st arg: num_samples */
107 int num_samples
= strtol(argv
[1], &endptr
, 0);
108 if (endptr
!= argv
[1] + strlen(argv
[1]))
109 print_usage_and_exit(argv
[0]);
111 /* 2nd arg: buffer_type */
112 if (strcmp(argv
[2], "color") == 0) {
113 buffer_to_test
= GL_COLOR_BUFFER_BIT
;
114 } else if (strcmp(argv
[2], "depth") == 0) {
115 buffer_to_test
= GL_DEPTH_BUFFER_BIT
;
116 manifest_program
= new ManifestDepth();
117 } else if (strcmp(argv
[2], "stencil") == 0) {
118 buffer_to_test
= GL_STENCIL_BUFFER_BIT
;
119 manifest_program
= new ManifestStencil();
121 print_usage_and_exit(argv
[0]);
124 piglit_require_gl_version(21);
125 piglit_require_extension("GL_ARB_framebuffer_object");
126 piglit_require_extension("GL_ARB_vertex_array_object");
128 /* Skip the test if num_samples > GL_MAX_SAMPLES */
130 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
131 if (num_samples
> max_samples
)
132 piglit_report_result(PIGLIT_SKIP
);
134 multisampled_fbo
.setup(FboConfig(num_samples
, pattern_width
,
136 if (manifest_program
)
137 manifest_program
->compile();
139 if (!piglit_check_gl_error(GL_NO_ERROR
))
140 piglit_report_result(PIGLIT_FAIL
);
145 test_clear(const float r
, const float g
, const float b
,
146 const float a
, const bool fast_clear_compatible
)
150 /* Clear all buffers of the multisampled fbo to default values
151 * (color={0,0,0,0}, depth=1, stencil=0), with no special
152 * coverage settings set.
154 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, multisampled_fbo
.handle
);
155 multisampled_fbo
.set_viewport();
156 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
|
157 GL_STENCIL_BUFFER_BIT
);
159 /* Set all the clear values to non-default settings. We use
160 * an alpha value other than 1.0 so verify that
161 * GL_SAMPLE_ALPHA_TO_COVERAGE and GL_SAMPLE_ALPHA_TO_ONE
164 glClearColor(r
, g
, b
, a
);
168 /* Enable the mulitsample fragment operations that glClear()
169 * is supposed to ignore.
171 glEnable(GL_SAMPLE_COVERAGE
);
172 glSampleCoverage(0.5, GL_TRUE
);
173 glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE
);
174 glEnable(GL_SAMPLE_ALPHA_TO_ONE
);
176 /* Clear the buffer under test. */
177 glClear(buffer_to_test
);
179 /* Reset the multisample fragment operations and clear values
180 * to their default settings.
182 glClearColor(0.0, 0.0, 0.0, 0.0);
185 glDisable(GL_SAMPLE_COVERAGE
);
186 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE
);
187 glDisable(GL_SAMPLE_ALPHA_TO_ONE
);
189 /* If we are testing the depth or stencil buffer, use
190 * manifest_program to convert depth/stencil values to
193 if (manifest_program
)
194 manifest_program
->run();
196 /* Blit the color values from the multisampled FBO to the
197 * screen, forcing a resolve.
199 glBindFramebuffer(GL_READ_FRAMEBUFFER
, multisampled_fbo
.handle
);
200 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
201 glBlitFramebuffer(0, 0, pattern_width
, pattern_height
,
202 0, 0, pattern_width
, pattern_height
,
203 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
205 /* Figure out what color we expect to be drawn, depending on
206 * which buffer was tested:
208 * - If we tested the color buffer, we should have gotten the
209 * clear color back verbatim.
211 * - If we tested the depth buffer, we should have gotten red,
212 * since the ManifestDepth program converts a depth value of
215 * - If we tested the stencil buffer, we should have gotten
216 * blue, since the ManifestStencil program converts a
217 * stencil value of 1 to blue.
219 const float expected_color
[4] = { r
, g
, b
, a
};
220 static const float expected_depth
[4] = { 1.0, 0.0, 0.0, 1.0 };
221 static const float expected_stencil
[4] = { 0.0, 0.0, 1.0, 1.0 };
222 const float *expected
= NULL
;
223 switch (buffer_to_test
) {
224 case GL_COLOR_BUFFER_BIT
:
225 expected
= expected_color
;
227 case GL_DEPTH_BUFFER_BIT
:
228 expected
= expected_depth
;
230 case GL_STENCIL_BUFFER_BIT
:
231 expected
= expected_stencil
;
234 printf("Unexpected value in buffer_to_test\n");
235 piglit_report_result(PIGLIT_FAIL
);
239 /* Test that the appropriate color was drawn. Since the
240 * resolve operation averaged together all the color samples
241 * corresponding to each pixel, this effectively verifies that
242 * all samples of every pixel were correctly cleared.
244 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
245 pass
= piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
,
248 if (buffer_to_test
== GL_COLOR_BUFFER_BIT
)
249 printf("fast_clear_compatible = %s, result = %s\n",
250 fast_clear_compatible
? "true" : "false",
251 pass
? "pass" : "fail");
253 piglit_present_results();
258 extern "C" enum piglit_result
263 /* Non 'fast clear' path. */
264 pass
= test_clear(1.0, 1.0, 1.0, 0.5, false) && pass
;
266 /* Test with color values compatible with Intel's i965 driver's
267 * 'fast clear' constraints. It varifies the 'fast clear' path
268 * if supported by the implementation.
270 pass
= test_clear(1.0, 1.0, 1.0, 0.0, true) && pass
;
272 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
275 } /* Anonymous namespace */