• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2013,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  */
24 
25 #include "igt.h"
26 #include <math.h>
27 
28 
29 IGT_TEST_DESCRIPTION("Test display plane scaling");
30 
31 typedef struct {
32 	uint32_t devid;
33 	int drm_fd;
34 	igt_display_t display;
35 	igt_crc_t ref_crc;
36 
37 	int image_w;
38 	int image_h;
39 
40 	struct igt_fb fb[4];
41 
42 	igt_plane_t *plane1;
43 	igt_plane_t *plane2;
44 	igt_plane_t *plane3;
45 	igt_plane_t *plane4;
46 } data_t;
47 
get_num_scalers(data_t * d,enum pipe pipe)48 static int get_num_scalers(data_t* d, enum pipe pipe)
49 {
50 	if (!is_i915_device(d->drm_fd))
51 		return 1;
52 
53 	igt_require(intel_gen(d->devid) >= 9);
54 
55 	if (intel_gen(d->devid) >= 10)
56 		return 2;
57 	else if (pipe != PIPE_C)
58 		return 2;
59 	else
60 		return 1;
61 }
62 
is_planar_yuv_format(uint32_t pixelformat)63 static bool is_planar_yuv_format(uint32_t pixelformat)
64 {
65 	switch (pixelformat) {
66 	case DRM_FORMAT_NV12:
67 	case DRM_FORMAT_P010:
68 	case DRM_FORMAT_P012:
69 	case DRM_FORMAT_P016:
70 		return true;
71 	default:
72 		return false;
73 	}
74 }
75 
cleanup_fbs(data_t * data)76 static void cleanup_fbs(data_t *data)
77 {
78 	int i;
79 
80 	for (i = 0; i < ARRAY_SIZE(data->fb); i++)
81 		igt_remove_fb(data->drm_fd, &data->fb[i]);
82 }
83 
cleanup_crtc(data_t * data)84 static void cleanup_crtc(data_t *data)
85 {
86 	igt_display_reset(&data->display);
87 
88 	cleanup_fbs(data);
89 }
90 
prepare_crtc(data_t * data,igt_output_t * output,enum pipe pipe,igt_plane_t * plane,drmModeModeInfo * mode)91 static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
92 			igt_plane_t *plane, drmModeModeInfo *mode)
93 {
94 	igt_display_t *display = &data->display;
95 	uint64_t tiling = is_i915_device(data->drm_fd) ?
96 		LOCAL_I915_FORMAT_MOD_X_TILED : LOCAL_DRM_FORMAT_MOD_NONE;
97 
98 	cleanup_crtc(data);
99 
100 	igt_output_set_pipe(output, pipe);
101 
102 	igt_skip_on(!igt_display_has_format_mod(display, DRM_FORMAT_XRGB8888,
103 						tiling));
104 
105 	/* allocate fb for plane 1 */
106 	igt_create_pattern_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
107 			      DRM_FORMAT_XRGB8888,
108 			      tiling,
109 			      &data->fb[0]);
110 
111 	igt_plane_set_fb(plane, &data->fb[0]);
112 
113 	if (plane->type != DRM_PLANE_TYPE_PRIMARY) {
114 		igt_plane_t *primary;
115 		int ret;
116 
117 		/* Do we succeed without enabling the primary plane? */
118 		ret = igt_display_try_commit2(display, COMMIT_ATOMIC);
119 		if (!ret)
120 			return;
121 
122 		/*
123 		 * Fallback: set the primary plane to actually enable the pipe.
124 		 * Some drivers always require the primary plane to be enabled.
125 		 */
126 		primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
127 		igt_plane_set_fb(primary, &data->fb[0]);
128 	}
129 	igt_display_commit2(display, COMMIT_ATOMIC);
130 }
131 
check_scaling_pipe_plane_rot(data_t * d,igt_plane_t * plane,uint32_t pixel_format,uint64_t tiling,enum pipe pipe,igt_output_t * output,igt_rotation_t rot)132 static void check_scaling_pipe_plane_rot(data_t *d, igt_plane_t *plane,
133 					 uint32_t pixel_format,
134 					 uint64_t tiling, enum pipe pipe,
135 					 igt_output_t *output,
136 					 igt_rotation_t rot)
137 {
138 	igt_display_t *display = &d->display;
139 	int width, height;
140 	drmModeModeInfo *mode;
141 
142 	cleanup_crtc(d);
143 
144 	igt_output_set_pipe(output, pipe);
145 	mode = igt_output_get_mode(output);
146 
147 	/* create buffer in the range of  min and max source side limit.*/
148 	width = height = 8;
149 	if (is_i915_device(d->drm_fd) && is_planar_yuv_format(pixel_format))
150 		width = height = 16;
151 	igt_create_color_fb(display->drm_fd, width, height,
152 		       pixel_format, tiling, 0.0, 1.0, 0.0, &d->fb[0]);
153 	igt_plane_set_fb(plane, &d->fb[0]);
154 
155 	/* Check min to full resolution upscaling */
156 	igt_fb_set_position(&d->fb[0], plane, 0, 0);
157 	igt_fb_set_size(&d->fb[0], plane, width, height);
158 	igt_plane_set_position(plane, 0, 0);
159 	igt_plane_set_size(plane, mode->hdisplay, mode->vdisplay);
160 	igt_plane_set_rotation(plane, rot);
161 	igt_display_commit2(display, COMMIT_ATOMIC);
162 
163 	igt_plane_set_fb(plane, NULL);
164 	igt_plane_set_position(plane, 0, 0);
165 }
166 
167 static const igt_rotation_t rotations[] = {
168 	IGT_ROTATION_0,
169 	IGT_ROTATION_90,
170 	IGT_ROTATION_180,
171 	IGT_ROTATION_270,
172 };
173 
can_rotate(data_t * d,unsigned format,uint64_t tiling,igt_rotation_t rot)174 static bool can_rotate(data_t *d, unsigned format, uint64_t tiling,
175 		       igt_rotation_t rot)
176 {
177 
178 	if (!is_i915_device(d->drm_fd))
179 		return true;
180 
181 	switch (format) {
182 	case DRM_FORMAT_RGB565:
183 		if (intel_gen(d->devid) >= 11)
184 			break;
185 		/* fall through */
186 	case DRM_FORMAT_C8:
187 	case DRM_FORMAT_XRGB16161616F:
188 	case DRM_FORMAT_XBGR16161616F:
189 	case DRM_FORMAT_ARGB16161616F:
190 	case DRM_FORMAT_ABGR16161616F:
191 	case DRM_FORMAT_Y210:
192 	case DRM_FORMAT_Y212:
193 	case DRM_FORMAT_Y216:
194 	case DRM_FORMAT_XVYU12_16161616:
195 	case DRM_FORMAT_XVYU16161616:
196 		return false;
197 	default:
198 		break;
199 	}
200 
201 	return true;
202 }
203 
can_scale(data_t * d,unsigned format)204 static bool can_scale(data_t *d, unsigned format)
205 {
206 	if (!is_i915_device(d->drm_fd))
207 		return true;
208 
209 	switch (format) {
210 	case DRM_FORMAT_XRGB16161616F:
211 	case DRM_FORMAT_XBGR16161616F:
212 	case DRM_FORMAT_ARGB16161616F:
213 	case DRM_FORMAT_ABGR16161616F:
214 		if (intel_gen(d->devid) >= 11)
215 			return true;
216 		/* fall through */
217 	case DRM_FORMAT_C8:
218 		return false;
219 	default:
220 		return true;
221 	}
222 }
223 
test_scaler_with_rotation_pipe(data_t * d,enum pipe pipe,igt_output_t * output)224 static void test_scaler_with_rotation_pipe(data_t *d, enum pipe pipe,
225 					   igt_output_t *output)
226 {
227 	igt_display_t *display = &d->display;
228 	igt_plane_t *plane;
229 	uint64_t tiling = is_i915_device(d->drm_fd) ?
230 		LOCAL_I915_FORMAT_MOD_Y_TILED : LOCAL_DRM_FORMAT_MOD_NONE;
231 
232 	igt_output_set_pipe(output, pipe);
233 	for_each_plane_on_pipe(display, pipe, plane) {
234 		if (plane->type == DRM_PLANE_TYPE_CURSOR)
235 			continue;
236 
237 		for (int i = 0; i < ARRAY_SIZE(rotations); i++) {
238 			igt_rotation_t rot = rotations[i];
239 			for (int j = 0; j < plane->drm_plane->count_formats; j++) {
240 				unsigned format = plane->drm_plane->formats[j];
241 
242 				if (igt_fb_supported_format(format) &&
243 				    igt_plane_has_format_mod(plane, format, tiling) &&
244 				    can_rotate(d, format, tiling, rot) &&
245 				    can_scale(d, format))
246 					check_scaling_pipe_plane_rot(d, plane, format,
247 								     tiling, pipe,
248 								     output, rot);
249 			}
250 		}
251 	}
252 }
253 
254 static const uint64_t tilings[] = {
255 	LOCAL_DRM_FORMAT_MOD_NONE,
256 	LOCAL_I915_FORMAT_MOD_X_TILED,
257 	LOCAL_I915_FORMAT_MOD_Y_TILED,
258 	LOCAL_I915_FORMAT_MOD_Yf_TILED
259 };
260 
test_scaler_with_pixel_format_pipe(data_t * d,enum pipe pipe,igt_output_t * output)261 static void test_scaler_with_pixel_format_pipe(data_t *d, enum pipe pipe, igt_output_t *output)
262 {
263 	igt_display_t *display = &d->display;
264 	igt_plane_t *plane;
265 
266 	igt_output_set_pipe(output, pipe);
267 
268 	for_each_plane_on_pipe(display, pipe, plane) {
269 		if (plane->type == DRM_PLANE_TYPE_CURSOR)
270 			continue;
271 
272 		for (int i = 0; i < ARRAY_SIZE(tilings); i++) {
273 			uint64_t tiling = tilings[i];
274 
275 			for (int j = 0; j < plane->drm_plane->count_formats; j++) {
276 				uint32_t format = plane->drm_plane->formats[j];
277 
278 				if (igt_fb_supported_format(format) &&
279 				    igt_plane_has_format_mod(plane, format, tiling) &&
280 				    can_scale(d, format))
281 					check_scaling_pipe_plane_rot(d, plane,
282 								     format, tiling,
283 								     pipe, output, IGT_ROTATION_0);
284 			}
285 		}
286 	}
287 }
288 
289 /* does iterative scaling on plane2 */
iterate_plane_scaling(data_t * d,drmModeModeInfo * mode)290 static void iterate_plane_scaling(data_t *d, drmModeModeInfo *mode)
291 {
292 	igt_display_t *display = &d->display;
293 
294 	if (mode->hdisplay >= d->fb[1].width) {
295 		int w, h;
296 		/* fixed fb */
297 		igt_fb_set_position(&d->fb[1], d->plane2, 0, 0);
298 		igt_fb_set_size(&d->fb[1], d->plane2, d->fb[1].width, d->fb[1].height);
299 		igt_plane_set_position(d->plane2, 0, 0);
300 
301 		/* adjust plane size */
302 		for (w = d->fb[1].width; w <= mode->hdisplay; w+=10) {
303 			h = w * d->fb[1].height / d->fb[1].width;
304 			igt_plane_set_size(d->plane2, w, h);
305 			igt_display_commit2(display, COMMIT_ATOMIC);
306 		}
307 	} else {
308 		int w, h;
309 		/* fixed plane */
310 		igt_plane_set_position(d->plane2, 0, 0);
311 		igt_plane_set_size(d->plane2, mode->hdisplay, mode->vdisplay);
312 		igt_fb_set_position(&d->fb[1], d->plane2, 0, 0);
313 
314 		/* adjust fb size */
315 		for (w = mode->hdisplay; w <= d->fb[1].width; w+=10) {
316 			/* Source coordinates must not be clipped. */
317 			h = min(w * mode->hdisplay / mode->vdisplay, d->fb[1].height);
318 			igt_fb_set_size(&d->fb[1], d->plane2, w, h);
319 			igt_display_commit2(display, COMMIT_ATOMIC);
320 		}
321 	}
322 }
323 
324 static void
test_plane_scaling_on_pipe(data_t * d,enum pipe pipe,igt_output_t * output)325 test_plane_scaling_on_pipe(data_t *d, enum pipe pipe, igt_output_t *output)
326 {
327 	igt_display_t *display = &d->display;
328 	igt_pipe_t *pipe_obj = &display->pipes[pipe];
329 	drmModeModeInfo *mode;
330 	int primary_plane_scaling = 0; /* For now */
331 	uint64_t tiling = is_i915_device(display->drm_fd) ?
332 		LOCAL_I915_FORMAT_MOD_X_TILED : LOCAL_DRM_FORMAT_MOD_NONE;
333 
334 	igt_skip_on(!igt_display_has_format_mod(display, DRM_FORMAT_XRGB8888,
335 						tiling));
336 
337 	mode = igt_output_get_mode(output);
338 
339 	/* Set up display with plane 1 */
340 	d->plane1 = igt_pipe_get_plane_type(pipe_obj, DRM_PLANE_TYPE_PRIMARY);
341 	prepare_crtc(d, output, pipe, d->plane1, mode);
342 
343 	igt_create_color_pattern_fb(display->drm_fd, 600, 600,
344 				    DRM_FORMAT_XRGB8888,
345 				    tiling,
346 				    .5, .5, .5, &d->fb[1]);
347 
348 	igt_create_pattern_fb(d->drm_fd,
349 			      mode->hdisplay, mode->vdisplay,
350 			      DRM_FORMAT_XRGB8888,
351 			      tiling,
352 			      &d->fb[2]);
353 
354 	if (primary_plane_scaling) {
355 		/* Primary plane upscaling */
356 		igt_fb_set_position(&d->fb[0], d->plane1, 100, 100);
357 		igt_fb_set_size(&d->fb[0], d->plane1, 500, 500);
358 		igt_plane_set_position(d->plane1, 0, 0);
359 		igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
360 		igt_display_commit2(display, COMMIT_ATOMIC);
361 
362 		/* Primary plane 1:1 no scaling */
363 		igt_fb_set_position(&d->fb[0], d->plane1, 0, 0);
364 		igt_fb_set_size(&d->fb[0], d->plane1, d->fb[0].width, d->fb[0].height);
365 		igt_plane_set_position(d->plane1, 0, 0);
366 		igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
367 		igt_display_commit2(display, COMMIT_ATOMIC);
368 	}
369 
370 	/* Set up fb[1]->plane2 mapping. */
371 	d->plane2 = igt_pipe_get_plane_type_index(pipe_obj,
372 						  DRM_PLANE_TYPE_OVERLAY, 0);
373 
374 	if (!d->plane2) {
375 		igt_debug("Plane-2 doesnt exist on pipe %s\n", kmstest_pipe_name(pipe));
376 		return;
377 	}
378 
379 	igt_plane_set_fb(d->plane2, &d->fb[1]);
380 
381 	/* 2nd plane windowed */
382 	igt_fb_set_position(&d->fb[1], d->plane2, 100, 100);
383 	igt_fb_set_size(&d->fb[1], d->plane2, d->fb[1].width-200, d->fb[1].height-200);
384 	igt_plane_set_position(d->plane2, 100, 100);
385 	igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200);
386 	igt_display_commit2(display, COMMIT_ATOMIC);
387 
388 	iterate_plane_scaling(d, mode);
389 
390 	/* 2nd plane up scaling */
391 	igt_fb_set_position(&d->fb[1], d->plane2, 100, 100);
392 	igt_fb_set_size(&d->fb[1], d->plane2, 500, 500);
393 	igt_plane_set_position(d->plane2, 10, 10);
394 	igt_plane_set_size(d->plane2, mode->hdisplay-20, mode->vdisplay-20);
395 	igt_display_commit2(display, COMMIT_ATOMIC);
396 
397 	/* 2nd plane downscaling */
398 	igt_fb_set_position(&d->fb[1], d->plane2, 0, 0);
399 	igt_fb_set_size(&d->fb[1], d->plane2, d->fb[1].width, d->fb[1].height);
400 	igt_plane_set_position(d->plane2, 10, 10);
401 
402 	/* Downscale (10/9)x of original image */
403 	igt_plane_set_size(d->plane2, (d->fb[1].width * 10)/9, (d->fb[1].height * 10)/9);
404 	igt_display_commit2(display, COMMIT_ATOMIC);
405 
406 	if (primary_plane_scaling) {
407 		/* Primary plane up scaling */
408 		igt_fb_set_position(&d->fb[0], d->plane1, 100, 100);
409 		igt_fb_set_size(&d->fb[0], d->plane1, 500, 500);
410 		igt_plane_set_position(d->plane1, 0, 0);
411 		igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
412 		igt_display_commit2(display, COMMIT_ATOMIC);
413 	}
414 
415 	/* Set up fb[2]->plane3 mapping. */
416 	d->plane3 = igt_pipe_get_plane_type_index(pipe_obj,
417 						  DRM_PLANE_TYPE_OVERLAY, 1);
418 	if(!d->plane3) {
419 		igt_debug("Plane-3 doesnt exist on pipe %s\n", kmstest_pipe_name(pipe));
420 		return;
421 	}
422 
423 	igt_plane_set_fb(d->plane3, &d->fb[2]);
424 
425 	/* 3rd plane windowed - no scaling */
426 	igt_fb_set_position(&d->fb[2], d->plane3, 100, 100);
427 	igt_fb_set_size(&d->fb[2], d->plane3, d->fb[2].width-300, d->fb[2].height-300);
428 	igt_plane_set_position(d->plane3, 100, 100);
429 	igt_plane_set_size(d->plane3, mode->hdisplay-300, mode->vdisplay-300);
430 	igt_display_commit2(display, COMMIT_ATOMIC);
431 
432 	/* Switch scaler from plane 2 to plane 3 */
433 	igt_fb_set_position(&d->fb[1], d->plane2, 100, 100);
434 	igt_fb_set_size(&d->fb[1], d->plane2, d->fb[1].width-200, d->fb[1].height-200);
435 	igt_plane_set_position(d->plane2, 100, 100);
436 	igt_plane_set_size(d->plane2, d->fb[1].width-200, d->fb[1].height-200);
437 
438 	igt_fb_set_position(&d->fb[2], d->plane3, 100, 100);
439 	igt_fb_set_size(&d->fb[2], d->plane3, d->fb[2].width-400, d->fb[2].height-400);
440 	igt_plane_set_position(d->plane3, 10, 10);
441 	igt_plane_set_size(d->plane3, mode->hdisplay-300, mode->vdisplay-300);
442 	igt_display_commit2(display, COMMIT_ATOMIC);
443 
444 	if (primary_plane_scaling) {
445 		/* Switch scaler from plane 1 to plane 2 */
446 		igt_fb_set_position(&d->fb[0], d->plane1, 0, 0);
447 		igt_fb_set_size(&d->fb[0], d->plane1, d->fb[0].width, d->fb[0].height);
448 		igt_plane_set_position(d->plane1, 0, 0);
449 		igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
450 
451 		igt_fb_set_position(&d->fb[1], d->plane2, 100, 100);
452 		igt_fb_set_size(&d->fb[1], d->plane2, d->fb[1].width-500,d->fb[1].height-500);
453 		igt_plane_set_position(d->plane2, 100, 100);
454 		igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200);
455 		igt_display_commit2(display, COMMIT_ATOMIC);
456 	}
457 }
458 
459 static void
__test_scaler_with_clipping_clamping_scenario(data_t * d,drmModeModeInfo * mode,uint32_t f1,uint32_t f2)460 __test_scaler_with_clipping_clamping_scenario(data_t *d, drmModeModeInfo *mode,
461 					      uint32_t f1, uint32_t f2)
462 {
463 	cleanup_fbs(d);
464 
465 	igt_create_pattern_fb(d->drm_fd,
466 			      mode->hdisplay, mode->vdisplay, f1,
467 			      LOCAL_I915_FORMAT_MOD_X_TILED, &d->fb[1]);
468 
469 	igt_create_pattern_fb(d->drm_fd,
470 			      mode->hdisplay, mode->vdisplay, f2,
471 			      LOCAL_I915_FORMAT_MOD_Y_TILED, &d->fb[2]);
472 
473 	igt_plane_set_fb(d->plane1, &d->fb[1]);
474 	igt_plane_set_fb(d->plane2, &d->fb[2]);
475 
476 	igt_fb_set_position(&d->fb[1], d->plane1, 0, 0);
477 	igt_fb_set_size(&d->fb[1], d->plane1, 300, 300);
478 	igt_plane_set_position(d->plane1, 100, 400);
479 	igt_fb_set_position(&d->fb[2], d->plane2, 0, 0);
480 	igt_fb_set_size(&d->fb[2], d->plane2, 400, 400);
481 	igt_plane_set_position(d->plane2, 100, 100);
482 
483 	/* scaled window size is outside the modeset area.*/
484 	igt_plane_set_size(d->plane1, mode->hdisplay + 200,
485 					    mode->vdisplay + 200);
486 	igt_plane_set_size(d->plane2, mode->hdisplay + 100,
487 					    mode->vdisplay + 100);
488 
489 	/*
490 	 * Can't guarantee that the clipped coordinates are
491 	 * suitably aligned for yuv. So allow the commit to fail.
492 	 */
493 	if (igt_format_is_yuv(d->fb[1].drm_format) ||
494 	    igt_format_is_yuv(d->fb[2].drm_format))
495 		igt_display_try_commit2(&d->display, COMMIT_ATOMIC);
496 	else
497 		igt_display_commit2(&d->display, COMMIT_ATOMIC);
498 }
499 
500 static void
test_scaler_with_clipping_clamping_scenario(data_t * d,enum pipe pipe,igt_output_t * output)501 test_scaler_with_clipping_clamping_scenario(data_t *d, enum pipe pipe, igt_output_t *output)
502 {
503 	igt_pipe_t *pipe_obj = &d->display.pipes[pipe];
504 	drmModeModeInfo *mode;
505 
506 	igt_require(get_num_scalers(d, pipe) >= 2);
507 
508 	mode = igt_output_get_mode(output);
509 	d->plane1 = igt_pipe_get_plane_type(pipe_obj, DRM_PLANE_TYPE_PRIMARY);
510 	d->plane2 = igt_pipe_get_plane_type(pipe_obj, DRM_PLANE_TYPE_OVERLAY);
511 	prepare_crtc(d, output, pipe, d->plane1, mode);
512 
513 	for (int i = 0; i < d->plane1->drm_plane->count_formats; i++) {
514 		unsigned f1 = d->plane1->drm_plane->formats[i];
515 		if (!igt_fb_supported_format(f1) ||
516 		    !can_scale(d, f1))
517 			continue;
518 
519 		for (int j = 0; j < d->plane2->drm_plane->count_formats; j++) {
520 			unsigned f2 = d->plane2->drm_plane->formats[j];
521 
522 			if (!igt_fb_supported_format(f2) ||
523 			    !can_scale(d, f2))
524 				continue;
525 
526 			__test_scaler_with_clipping_clamping_scenario(d, mode, f1, f2);
527 		}
528 	}
529 }
530 
find_connected_pipe(igt_display_t * display,bool second,enum pipe * pipe,igt_output_t ** output)531 static void find_connected_pipe(igt_display_t *display, bool second, enum pipe *pipe, igt_output_t **output)
532 {
533 	enum pipe first = PIPE_NONE;
534 	igt_output_t *first_output = NULL;
535 	bool found = false;
536 
537 	for_each_pipe_with_valid_output(display, *pipe, *output) {
538 		if (first == *pipe || *output == first_output)
539 			continue;
540 
541 		if (second) {
542 			first = *pipe;
543 			first_output = *output;
544 			second = false;
545 			continue;
546 		}
547 
548 		return;
549 	}
550 
551 	if (first_output)
552 		igt_require_f(found, "No second valid output found\n");
553 	else
554 		igt_require_f(found, "No valid outputs found\n");
555 }
556 
test_scaler_with_multi_pipe_plane(data_t * d)557 static void test_scaler_with_multi_pipe_plane(data_t *d)
558 {
559 	igt_display_t *display = &d->display;
560 	igt_output_t *output1, *output2;
561 	drmModeModeInfo *mode1, *mode2;
562 	enum pipe pipe1, pipe2;
563 	uint64_t tiling = is_i915_device(display->drm_fd) ?
564 		LOCAL_I915_FORMAT_MOD_Y_TILED : LOCAL_DRM_FORMAT_MOD_NONE;
565 
566 	cleanup_crtc(d);
567 
568 	find_connected_pipe(display, false, &pipe1, &output1);
569 	find_connected_pipe(display, true, &pipe2, &output2);
570 
571 	igt_skip_on(!output1 || !output2);
572 
573 	igt_output_set_pipe(output1, pipe1);
574 	igt_output_set_pipe(output2, pipe2);
575 
576 	d->plane1 = igt_output_get_plane(output1, 0);
577 	d->plane2 = get_num_scalers(d, pipe1) >= 2 ? igt_output_get_plane(output1, 1) : NULL;
578 	d->plane3 = igt_output_get_plane(output2, 0);
579 	d->plane4 = get_num_scalers(d, pipe2) >= 2 ? igt_output_get_plane(output2, 1) : NULL;
580 
581 	mode1 = igt_output_get_mode(output1);
582 	mode2 = igt_output_get_mode(output2);
583 
584 	igt_skip_on(!igt_display_has_format_mod(display, DRM_FORMAT_XRGB8888,
585 						tiling));
586 
587 	igt_create_pattern_fb(d->drm_fd, 600, 600,
588 			      DRM_FORMAT_XRGB8888,
589 			      tiling, &d->fb[0]);
590 
591 	igt_create_pattern_fb(d->drm_fd, 500, 500,
592 			      DRM_FORMAT_XRGB8888,
593 			      tiling, &d->fb[1]);
594 
595 	igt_create_pattern_fb(d->drm_fd, 700, 700,
596 			      DRM_FORMAT_XRGB8888,
597 			      tiling, &d->fb[2]);
598 
599 	igt_create_pattern_fb(d->drm_fd, 400, 400,
600 			      DRM_FORMAT_XRGB8888,
601 			      tiling, &d->fb[3]);
602 
603 	igt_plane_set_fb(d->plane1, &d->fb[0]);
604 	if (d->plane2)
605 		igt_plane_set_fb(d->plane2, &d->fb[1]);
606 	igt_plane_set_fb(d->plane3, &d->fb[2]);
607 	if (d->plane4)
608 		igt_plane_set_fb(d->plane4, &d->fb[3]);
609 	igt_display_commit2(display, COMMIT_ATOMIC);
610 
611 	/* Upscaling Primary */
612 	igt_plane_set_size(d->plane1, mode1->hdisplay, mode1->vdisplay);
613 	igt_plane_set_size(d->plane3, mode2->hdisplay, mode2->vdisplay);
614 	igt_display_commit2(display, COMMIT_ATOMIC);
615 
616 	/* Upscaling Sprites */
617 	igt_plane_set_size(d->plane2 ?: d->plane1, mode1->hdisplay, mode1->vdisplay);
618 	igt_plane_set_size(d->plane4 ?: d->plane3, mode2->hdisplay, mode2->vdisplay);
619 	igt_display_commit2(display, COMMIT_ATOMIC);
620 }
621 
622 igt_main
623 {
624 	data_t data = {};
625 	enum pipe pipe;
626 
627 	igt_skip_on_simulation();
628 
629 	igt_fixture {
630 		data.drm_fd = drm_open_driver_master(DRIVER_INTEL | DRIVER_AMDGPU);
631 		igt_display_require(&data.display, data.drm_fd);
632 		data.devid = is_i915_device(data.drm_fd) ?
633 			intel_get_drm_devid(data.drm_fd) : 0;
634 		igt_require(data.display.is_atomic);
635 	}
636 
for_each_pipe_static(pipe)637 	for_each_pipe_static(pipe) igt_subtest_group {
638 		igt_output_t *output;
639 
640 		igt_fixture {
641 			igt_display_require_output_on_pipe(&data.display, pipe);
642 
643 			igt_require(get_num_scalers(&data, pipe) > 0);
644 		}
645 
646 		igt_subtest_f("pipe-%s-plane-scaling", kmstest_pipe_name(pipe))
647 			for_each_valid_output_on_pipe(&data.display, pipe, output)
648 				test_plane_scaling_on_pipe(&data, pipe, output);
649 
650 		igt_subtest_f("pipe-%s-scaler-with-pixel-format", kmstest_pipe_name(pipe))
651 			for_each_valid_output_on_pipe(&data.display, pipe, output)
652 				test_scaler_with_pixel_format_pipe(&data, pipe, output);
653 
654 		igt_subtest_f("pipe-%s-scaler-with-rotation", kmstest_pipe_name(pipe))
655 			for_each_valid_output_on_pipe(&data.display, pipe, output)
656 				test_scaler_with_rotation_pipe(&data, pipe, output);
657 
658 		igt_subtest_f("pipe-%s-scaler-with-clipping-clamping", kmstest_pipe_name(pipe))
659 			for_each_valid_output_on_pipe(&data.display, pipe, output)
660 				test_scaler_with_clipping_clamping_scenario(&data, pipe, output);
661 	}
662 
663 	igt_subtest_f("2x-scaler-multi-pipe")
664 		test_scaler_with_multi_pipe_plane(&data);
665 
666 	igt_fixture
667 		igt_display_fini(&data.display);
668 }
669