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
;
29 * \file unaligned-blit.cpp
31 * Verify the accuracy of blits involving MSAA buffers when the blit
32 * coordinates are not aligned to simple powers of two.
34 * This test operates through the use of a sequence of blits that
35 * might be called a "scrambling blit": a source image (whose size is
36 * not a power of two) is divided up into tiles (whose size is also
37 * not a power of two), and these tiles are blitted one at a time from
38 * the source to the destination buffer, permuting the order of the
39 * tiles in a deterministic way. The scrambling ensures that we test
40 * a wide variety of different offsets and coordinate misalignments.
42 * The test performs the following operations: First an unscrambled
43 * test image is created in a source buffer, which may or may not be
44 * multisampled. Then a scrambling blit is used to copy it to a
45 * destination buffer, which also may or may not be multisampled.
46 * Finally, the destination buffer is blitted to the window system
47 * framebuffer, using the inverse permutation. This should result in
48 * an unscrambled test image.
50 * To verify that the test image is correct, we produce a reference
51 * image by repeating the same operation using ordinary unscrambled
54 const int pattern_size
= 245;
55 const int tile_size
= 49;
56 const int tiles_across
= 5;
57 const int num_tiles
= tiles_across
* tiles_across
;
59 PIGLIT_GL_TEST_CONFIG_BEGIN
61 config
.supports_gl_compat_version
= 10;
63 config
.window_width
= 2*pattern_size
;
64 config
.window_height
= pattern_size
;
65 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DEPTH
| PIGLIT_GL_VISUAL_STENCIL
;
66 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
68 PIGLIT_GL_TEST_CONFIG_END
70 const int permutation
[num_tiles
] = {
71 10, 5, 6, 17, 3, 11, 16, 21, 14, 24, 23, 8, 15, 18, 0, 12, 9,
72 4, 22, 19, 20, 2, 7, 13, 1
75 const int inverse_permutation
[num_tiles
] = {
76 14, 24, 21, 4, 17, 1, 2, 22, 11, 16, 0, 5, 15, 23, 8, 12, 6,
77 3, 13, 19, 20, 7, 18, 10, 9
82 TestPattern
*test_pattern
= NULL
;
83 ManifestProgram
*manifest_program
= NULL
;
84 GLbitfield buffer_to_test
;
87 scrambling_blit(const int *permutation
)
89 for (int i
= 0; i
< num_tiles
; ++i
) {
90 int src_x
= (i
% tiles_across
) * tile_size
;
91 int src_y
= (i
/ tiles_across
) * tile_size
;
92 int dst_x
= (permutation
[i
] % tiles_across
) * tile_size
;
93 int dst_y
= (permutation
[i
] / tiles_across
) * tile_size
;
94 glBlitFramebuffer(src_x
, src_y
,
95 src_x
+ tile_size
, src_y
+ tile_size
,
97 dst_x
+ tile_size
, dst_y
+ tile_size
,
98 buffer_to_test
, GL_NEAREST
);
103 NORETURN
print_usage_and_exit(char *prog_name
)
105 printf("Usage: %s <num_samples> <buffer_type> <blit_type>\n"
106 " where <buffer_type> is one of:\n"
110 " and <blit_type> is one of:\n"
115 piglit_report_result(PIGLIT_FAIL
);
119 piglit_init(int argc
, char **argv
)
125 print_usage_and_exit(argv
[0]);
128 num_samples
= strtol(argv
[1], &endptr
, 0);
129 if (endptr
!= argv
[1] + strlen(argv
[1]))
130 print_usage_and_exit(argv
[0]);
132 piglit_require_gl_version(21);
133 piglit_require_extension("GL_ARB_framebuffer_object");
134 piglit_require_extension("GL_ARB_vertex_array_object");
136 /* Skip the test if num_samples > GL_MAX_SAMPLES */
138 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
139 if (num_samples
> max_samples
)
140 piglit_report_result(PIGLIT_SKIP
);
142 if (strcmp(argv
[2], "color") == 0) {
143 test_pattern
= new Triangles();
144 buffer_to_test
= GL_COLOR_BUFFER_BIT
;
145 } else if (strcmp(argv
[2], "depth") == 0) {
146 test_pattern
= new DepthSunburst();
147 manifest_program
= new ManifestDepth();
148 buffer_to_test
= GL_DEPTH_BUFFER_BIT
;
149 } else if (strcmp(argv
[2], "stencil") == 0) {
150 test_pattern
= new StencilSunburst();
151 manifest_program
= new ManifestStencil();
152 buffer_to_test
= GL_STENCIL_BUFFER_BIT
;
154 print_usage_and_exit(argv
[0]);
157 if (strcmp(argv
[3], "msaa") == 0) {
158 src_samples
= dst_samples
= num_samples
;
159 } else if (strcmp(argv
[3], "upsample") == 0) {
161 dst_samples
= num_samples
;
162 } else if (strcmp(argv
[3], "downsample") == 0) {
163 src_samples
= num_samples
;
166 print_usage_and_exit(argv
[0]);
169 test_pattern
->compile();
170 if (manifest_program
)
171 manifest_program
->compile();
172 src_fbo
.setup(FboConfig(src_samples
, pattern_size
, pattern_size
));
173 dst_fbo
.setup(FboConfig(dst_samples
, pattern_size
, pattern_size
));
181 /* Draw the test pattern in src_fbo. */
182 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, src_fbo
.handle
);
183 src_fbo
.set_viewport();
184 test_pattern
->draw(TestPattern::no_projection
);
186 /* Blit from src_fbo to dst_fbo, scrambling the pattern as we go. */
187 glBindFramebuffer(GL_READ_FRAMEBUFFER
, src_fbo
.handle
);
188 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, dst_fbo
.handle
);
189 scrambling_blit(permutation
);
191 /* Blit from dst_fbo to the left half of the window system
192 * framebuffer, unscrambling as we go.
194 glBindFramebuffer(GL_READ_FRAMEBUFFER
, dst_fbo
.handle
);
195 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
196 scrambling_blit(inverse_permutation
);
198 /* Blit from src_fbo to dst_fbo with no scrambling. */
199 glBindFramebuffer(GL_READ_FRAMEBUFFER
, src_fbo
.handle
);
200 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, dst_fbo
.handle
);
201 glBlitFramebuffer(0, 0, pattern_size
, pattern_size
,
202 0, 0, pattern_size
, pattern_size
,
203 buffer_to_test
, GL_NEAREST
);
205 /* Blit from dst_fbo to the right half of the window system
206 * framebuffer, with no scrambling.
208 glBindFramebuffer(GL_READ_FRAMEBUFFER
, dst_fbo
.handle
);
209 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
210 glBlitFramebuffer(0, 0, pattern_size
, pattern_size
,
211 pattern_size
, 0, pattern_size
*2, pattern_size
,
212 buffer_to_test
, GL_NEAREST
);
214 /* If we were testing depth or stencil, manifest the image so
215 * that we can see it.
217 glViewport(0, 0, piglit_width
, piglit_height
);
218 if (manifest_program
)
219 manifest_program
->run();
221 /* Check that the left and right halves of the screen match. */
222 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
223 pass
= piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width
,
224 piglit_height
) && pass
;
226 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
228 piglit_present_results();
230 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;