blob: beeb111be12ecc87bcbc162eb8ffaaa70349798e [file] [log] [blame]
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +03001/*
2 * Copyright © 2014 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
25 */
26
Thomas Wood804e11f2015-08-17 17:57:43 +010027#include "igt.h"
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +030028#include <errno.h>
29#include <stdbool.h>
30#include <stdio.h>
31#include <string.h>
32
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +010033IGT_TEST_DESCRIPTION("Test page flips and tiling scenarios");
Thomas Woodb2ac2642014-11-28 11:02:44 +000034
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +030035typedef struct {
36 int drm_fd;
37 igt_display_t display;
Tvrtko Ursulinb1177832015-03-03 14:11:06 +000038 int gen;
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +030039} data_t;
40
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +010041static igt_pipe_crc_t *_pipe_crc;
42
Chris Wilson83884e92017-03-21 17:16:03 +000043static igt_pipe_crc_t *pipe_crc_new(data_t *data, int pipe)
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +030044{
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +010045 if (_pipe_crc) {
46 igt_pipe_crc_free(_pipe_crc);
47 _pipe_crc = NULL;
48 }
49
Chris Wilson83884e92017-03-21 17:16:03 +000050 _pipe_crc = igt_pipe_crc_new(data->drm_fd, pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +010051 igt_assert(_pipe_crc);
52
53 return _pipe_crc;
54}
55
56static void pipe_crc_free(void)
57{
58 if (_pipe_crc) {
59 igt_pipe_crc_free(_pipe_crc);
60 _pipe_crc = NULL;
61 }
62}
63
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +010064static void
Maarten Lankhorst5af520a2016-07-05 12:53:05 +020065test_flip_tiling(data_t *data, enum pipe pipe, igt_output_t *output, uint64_t tiling[2])
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +010066{
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +030067 drmModeModeInfo *mode;
68 igt_plane_t *primary;
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +010069 struct igt_fb fb[2];
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +030070 igt_pipe_crc_t *pipe_crc;
71 igt_crc_t reference_crc, crc;
Maarten Lankhorst5af520a2016-07-05 12:53:05 +020072 int fb_id, ret, width;
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +030073
Chris Wilson83884e92017-03-21 17:16:03 +000074 pipe_crc = pipe_crc_new(data, pipe);
Chris Wilsonbe6bb4c2014-09-07 15:52:10 +010075 igt_output_set_pipe(output, pipe);
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +030076
77 mode = igt_output_get_mode(output);
78 primary = igt_output_get_plane(output, 0);
79
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +010080 width = mode->hdisplay;
81
82 if (tiling[0] != tiling[1] &&
83 (tiling[0] != LOCAL_DRM_FORMAT_MOD_NONE ||
84 tiling[1] != LOCAL_DRM_FORMAT_MOD_NONE)) {
85 /*
86 * Since a page flip to a buffer with different stride
87 * doesn't work, choose width so that the stride of both
88 * buffers is the same.
89 */
90 width = 512;
91 while (width < mode->hdisplay)
92 width *= 2;
93 }
94
Ville Syrjälä5b113d32015-12-17 01:39:31 +020095 fb_id = igt_create_pattern_fb(data->drm_fd, width, mode->vdisplay,
96 DRM_FORMAT_XRGB8888, tiling[0],
97 &fb[0]);
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +010098 igt_assert(fb_id);
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +030099
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100100 /* Second fb has different background so CRC does not match. */
Ville Syrjälä5b113d32015-12-17 01:39:31 +0200101 fb_id = igt_create_color_pattern_fb(data->drm_fd, width, mode->vdisplay,
102 DRM_FORMAT_XRGB8888, tiling[1],
103 0.5, 0.5, 0.5, &fb[1]);
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100104 igt_assert(fb_id);
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300105
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100106 /* Set the crtc and generate a reference CRC. */
107 igt_plane_set_fb(primary, &fb[1]);
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300108 igt_display_commit(&data->display);
109 igt_pipe_crc_collect_crc(pipe_crc, &reference_crc);
110
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100111 /* Commit the first fb. */
112 igt_plane_set_fb(primary, &fb[0]);
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300113 igt_display_commit(&data->display);
114
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100115 /* Flip to the second fb. */
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300116 ret = drmModePageFlip(data->drm_fd, output->config.crtc->crtc_id,
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100117 fb[1].fb_id, DRM_MODE_PAGE_FLIP_EVENT, NULL);
118 /*
119 * Page flip should work but some transitions may be temporarily
120 * on some kernels.
121 */
122 igt_require(ret == 0);
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300123
Mika Kahola4d092022018-05-23 14:47:37 +0300124 kmstest_wait_for_pageflip(data->drm_fd);
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300125
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100126 /* Get a crc and compare with the reference. */
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300127 igt_pipe_crc_collect_crc(pipe_crc, &crc);
Daniel Vettere588f6d2015-02-27 20:37:29 +0100128 igt_assert_crc_equal(&reference_crc, &crc);
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300129
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100130 /* Clean up. */
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300131 igt_plane_set_fb(primary, NULL);
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100132 pipe_crc_free();
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300133 igt_output_set_pipe(output, PIPE_ANY);
134 igt_display_commit(&data->display);
135
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100136 igt_remove_fb(data->drm_fd, &fb[0]);
137 igt_remove_fb(data->drm_fd, &fb[1]);
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300138}
139
140static data_t data;
Daniel Vetter4fbd49b2014-04-11 16:16:31 +0200141igt_output_t *output;
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300142
143igt_main
144{
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300145 igt_skip_on_simulation();
146
147 igt_fixture {
Micah Fedkec81d2932015-07-22 21:54:02 +0000148 data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
Tvrtko Ursulinb1177832015-03-03 14:11:06 +0000149 data.gen = intel_gen(intel_get_drm_devid(data.drm_fd));
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300150
Daniel Vetter33f08842014-08-12 11:23:09 +0200151 kmstest_set_vt_graphics_mode();
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300152
Chris Wilson83884e92017-03-21 17:16:03 +0000153 igt_require_pipe_crc(data.drm_fd);
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300154 igt_display_init(&data.display, data.drm_fd);
155 }
156
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100157 /*
158 * Test that a page flip from a tiled buffer to a linear one works
159 * correctly. First, it sets the crtc with the linear buffer and
160 * generates a reference crc for the pipe. Then, the crtc is set with
161 * the tiled one and page flip to the linear one issued. A new crc is
162 * generated and compared to the reference one.
163 */
164
Daniel Vetter4fbd49b2014-04-11 16:16:31 +0200165 igt_subtest_f("flip-changes-tiling") {
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100166 uint64_t tiling[2] = { LOCAL_I915_FORMAT_MOD_X_TILED,
167 LOCAL_DRM_FORMAT_MOD_NONE };
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200168 enum pipe pipe;
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100169
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200170 for_each_pipe_with_valid_output(&data.display, pipe, output)
171 test_flip_tiling(&data, pipe, output, tiling);
Tvrtko Ursulinb1177832015-03-03 14:11:06 +0000172 }
173
174 igt_subtest_f("flip-changes-tiling-Y") {
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100175 uint64_t tiling[2] = { LOCAL_I915_FORMAT_MOD_Y_TILED,
176 LOCAL_DRM_FORMAT_MOD_NONE };
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200177 enum pipe pipe;
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100178
Tvrtko Ursulinb1177832015-03-03 14:11:06 +0000179 igt_require_fb_modifiers(data.drm_fd);
180 igt_require(data.gen >= 9);
181
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200182 for_each_pipe_with_valid_output(&data.display, pipe, output)
183 test_flip_tiling(&data, pipe, output, tiling);
Tvrtko Ursulinb1177832015-03-03 14:11:06 +0000184 }
185
186 igt_subtest_f("flip-changes-tiling-Yf") {
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100187 uint64_t tiling[2] = { LOCAL_I915_FORMAT_MOD_Yf_TILED,
188 LOCAL_DRM_FORMAT_MOD_NONE };
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200189 enum pipe pipe;
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100190
Tvrtko Ursulinb1177832015-03-03 14:11:06 +0000191 igt_require_fb_modifiers(data.drm_fd);
192 igt_require(data.gen >= 9);
193
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200194 for_each_pipe_with_valid_output(&data.display, pipe, output)
195 test_flip_tiling(&data, pipe, output, tiling);
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100196 }
197
198 /*
199 * Test that a page flip from a tiled buffer to another tiled one works
200 * correctly. First, it sets the crtc with the tiled buffer and
201 * generates a reference crc for the pipe. Then a page flip to second
202 * tiled buffer is issued. A new crc is generated and compared to the
203 * reference one.
204 */
205
206 igt_subtest_f("flip-X-tiled") {
207 uint64_t tiling[2] = { LOCAL_I915_FORMAT_MOD_X_TILED,
208 LOCAL_I915_FORMAT_MOD_X_TILED };
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200209 enum pipe pipe;
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100210
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200211 for_each_pipe_with_valid_output(&data.display, pipe, output)
212 test_flip_tiling(&data, pipe, output, tiling);
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100213 }
214
215 igt_subtest_f("flip-Y-tiled") {
216 uint64_t tiling[2] = { LOCAL_I915_FORMAT_MOD_Y_TILED,
217 LOCAL_I915_FORMAT_MOD_Y_TILED };
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200218 enum pipe pipe;
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100219
220 igt_require_fb_modifiers(data.drm_fd);
221 igt_require(data.gen >= 9);
222
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200223 for_each_pipe_with_valid_output(&data.display, pipe, output)
224 test_flip_tiling(&data, pipe, output, tiling);
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100225 }
226
227 igt_subtest_f("flip-Yf-tiled") {
228 uint64_t tiling[2] = { LOCAL_I915_FORMAT_MOD_Yf_TILED,
229 LOCAL_I915_FORMAT_MOD_Yf_TILED };
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200230 enum pipe pipe;
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100231
232 igt_require_fb_modifiers(data.drm_fd);
233 igt_require(data.gen >= 9);
234
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200235 for_each_pipe_with_valid_output(&data.display, pipe, output)
236 test_flip_tiling(&data, pipe, output, tiling);
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100237 }
238
239 /*
240 * Test that a page flip from a linear buffer to a tiled one works
241 * correctly. First, it sets the crtc with the linear buffer and
242 * generates a reference crc for the pipe. Then a page flip to a tiled
243 * buffer is issued. A new crc is generated and compared to the
244 * reference one.
245 */
246
247 igt_subtest_f("flip-to-X-tiled") {
248 uint64_t tiling[2] = { LOCAL_DRM_FORMAT_MOD_NONE,
249 LOCAL_I915_FORMAT_MOD_X_TILED };
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200250 enum pipe pipe;
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100251
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200252 for_each_pipe_with_valid_output(&data.display, pipe, output)
253 test_flip_tiling(&data, pipe, output, tiling);
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100254 }
255
256 igt_subtest_f("flip-to-Y-tiled") {
257 uint64_t tiling[2] = { LOCAL_DRM_FORMAT_MOD_NONE,
258 LOCAL_I915_FORMAT_MOD_Y_TILED };
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200259 enum pipe pipe;
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100260
261 igt_require_fb_modifiers(data.drm_fd);
262 igt_require(data.gen >= 9);
263
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200264 for_each_pipe_with_valid_output(&data.display, pipe, output)
265 test_flip_tiling(&data, pipe, output, tiling);
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100266 }
267
268 igt_subtest_f("flip-to-Yf-tiled") {
269 uint64_t tiling[2] = { LOCAL_DRM_FORMAT_MOD_NONE,
270 LOCAL_I915_FORMAT_MOD_Yf_TILED };
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200271 enum pipe pipe;
Tvrtko Ursulin8a5736b2015-05-12 11:06:34 +0100272
273 igt_require_fb_modifiers(data.drm_fd);
274 igt_require(data.gen >= 9);
275
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200276 for_each_pipe_with_valid_output(&data.display, pipe, output)
277 test_flip_tiling(&data, pipe, output, tiling);
Daniel Vetter4fbd49b2014-04-11 16:16:31 +0200278 }
Ander Conselvan de Oliveiraddf8cc12014-04-02 15:31:38 +0300279
280 igt_fixture {
281 igt_display_fini(&data.display);
282 }
283}