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
23 #include "piglit-test-pattern.h"
24 #include "piglit-fbo.h"
25 using namespace piglit_util_fbo
;
26 using namespace piglit_util_test_pattern
;
31 * Verify the accuracy of upsampling from a non-MSAA buffer to an MSAA
34 * This test operates by drawing a test image in the window system
35 * framebuffer (which is non-MSAA), and then blitting it to an MSAA
36 * framebuffer, forcing the implementation to upsample it.
38 * To verify that upsampling has properly replicated each pixel value
39 * in each of its samples, we blit from the MSAA buffer back to the
40 * window system framebuffer. This causes all of the samples for each
41 * pixel to be blended, so if any of the pixels were not upsampled
42 * correctly, we would expect the downsampled image to be different
43 * from the original image.
45 * When testing depth and stencil buffers, we need to modify this
46 * procedure slightly, since downsampling depth and stencil buffers
47 * doesn't cause the pixels to be blended. So, after the first blit,
48 * we execute a "manifest pass" to translate the depth or stencil
49 * image into a color image. This is done independently in both the
50 * MSAA and non-MSAA buffers. Then we downsample the resulting color
53 * Note: this test relies on proper functioning of the MSAA buffer and
54 * the downsample blit. These are already adequately tested by
58 PIGLIT_GL_TEST_CONFIG_BEGIN
60 config
.supports_gl_compat_version
= 10;
62 config
.window_width
= 512;
63 config
.window_height
= 256;
64 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DEPTH
| PIGLIT_GL_VISUAL_STENCIL
;
65 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
67 PIGLIT_GL_TEST_CONFIG_END
69 const int pattern_width
= 256; const int pattern_height
= 256;
72 TestPattern
*test_pattern
= NULL
;
73 ManifestProgram
*manifest_program
= NULL
;
74 GLbitfield buffer_to_test
;
75 GLenum filter_mode
= GL_NEAREST
;
78 print_usage_and_exit(char *prog_name
)
80 printf("Usage: %s <num_samples> <buffer_type>\n"
81 " where <buffer_type> is one of:\n"
85 "Available options:\n"
86 " linear: use GL_LINEAR filter mode\n",
88 piglit_report_result(PIGLIT_FAIL
);
92 piglit_init(int argc
, char **argv
)
96 print_usage_and_exit(argv
[0]);
99 num_samples
= strtol(argv
[1], &endptr
, 0);
100 if (endptr
!= argv
[1] + strlen(argv
[1]))
101 print_usage_and_exit(argv
[0]);
104 piglit_require_gl_version(21);
105 piglit_require_extension("GL_ARB_framebuffer_object");
106 piglit_require_extension("GL_ARB_vertex_array_object");
108 /* Skip the test if num_samples > GL_MAX_SAMPLES */
110 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
111 if (num_samples
> max_samples
)
112 piglit_report_result(PIGLIT_SKIP
);
114 if (strcmp(argv
[2], "color") == 0) {
115 test_pattern
= new Triangles();
116 buffer_to_test
= GL_COLOR_BUFFER_BIT
;
117 } else if (strcmp(argv
[2], "depth") == 0) {
118 test_pattern
= new DepthSunburst();
119 manifest_program
= new ManifestDepth();
120 buffer_to_test
= GL_DEPTH_BUFFER_BIT
;
121 } else if (strcmp(argv
[2], "stencil") == 0) {
122 test_pattern
= new StencilSunburst();
123 manifest_program
= new ManifestStencil();
124 buffer_to_test
= GL_STENCIL_BUFFER_BIT
;
126 print_usage_and_exit(argv
[0]);
129 for (int i
= 3; i
< argc
; i
++) {
130 if (strcmp(argv
[i
], "linear") == 0)
131 filter_mode
= GL_LINEAR
;
133 print_usage_and_exit(argv
[0]);
136 test_pattern
->compile();
137 if (manifest_program
)
138 manifest_program
->compile();
140 multisample_fbo
.setup(FboConfig(num_samples
, pattern_width
,
149 /* Draw the full test pattern on the right half of the piglit
150 * window, as a reference image.
152 * To map the full test pattern to the right half of the
153 * windows, we need a projection matrix that multiplies the X
154 * coordinate by 0.5 and adds 0.5.
162 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
163 glViewport(0, 0, piglit_width
, piglit_height
);
164 test_pattern
->draw(proj
);
166 /* Blit the test pattern to multisample_fbo, forcing the
167 * implementation to upsample it.
169 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
170 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, multisample_fbo
.handle
);
171 glBlitFramebuffer(pattern_width
, 0, pattern_width
*2, pattern_height
,
172 0, 0, pattern_width
, pattern_height
,
173 buffer_to_test
, filter_mode
);
175 if (manifest_program
) {
176 /* Manifest the test pattern in the main framebuffer. */
177 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
178 manifest_program
->run();
180 /* Manifest the test pattern in the multisample
183 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, multisample_fbo
.handle
);
184 multisample_fbo
.set_viewport();
185 manifest_program
->run();
188 /* Blit the manifested test pattern to the left half of the
189 * main framebuffer, forcing the implementation to downsample
192 glBindFramebuffer(GL_READ_FRAMEBUFFER
, multisample_fbo
.handle
);
193 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
194 glBlitFramebuffer(0, 0, pattern_width
, pattern_height
,
195 0, 0, pattern_width
, pattern_height
,
196 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
198 /* Check that the left and right halves of the screen match.
199 * If they don't, then there is either a problem with
200 * upsampling or downsampling. Since downsampling is already
201 * tested by accuracy.cpp, we'll assume that any problem we
202 * see here is due to upsampling.
204 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
205 pass
= piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width
,
206 piglit_height
) && pass
;
208 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
210 piglit_present_results();
212 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;