summaryrefslogtreecommitdiff
path: root/tests/i915/kms_flip_scaled_crc.c
blob: d6edb01c2c6d41899c14766b9e316a4aaa914851 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/*
 * Copyright © 2020 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 */

#include "igt.h"

IGT_TEST_DESCRIPTION("Test flipping between scaled/nonscaled framebuffers");

typedef struct {
	int drm_fd;
	igt_display_t display;
	igt_output_t *output;
	enum pipe pipe;
	uint32_t gen;
	struct igt_fb small_fb;
	struct igt_fb big_fb;
	igt_pipe_crc_t *pipe_crc;
	uint32_t attemptmodewidth;
	uint32_t attemptmodeheight;
} data_t;

const struct {
	const char * const name;
	const char * const describe;
	const uint64_t firstmodifier;
	const uint32_t firstformat;
	const uint64_t secondmodifier;
	const uint32_t secondformat;
	const double firstmultiplier;
	const double secondmultiplier;
} flip_scenario_test[] = {
	{
		"flip-32bpp-ytile-to-64bpp-ytile-downscaling",
		"Flip from 32bpp non scaled fb to 64bpp downscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB8888,
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB16161616F,
		1.0,
		2.0,
	},
	{
		"flip-64bpp-ytile-to-32bpp-ytile-downscaling",
		"Flip from 64bpp non scaled fb to 32bpp downscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB16161616F,
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB8888,
		1.0,
		2.0,
	},
	{
		"flip-64bpp-ytile-to-16bpp-ytile-downscaling",
		"Flip from 64bpp non scaled fb to 16bpp downscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB16161616F,
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_RGB565,
		1.0,
		2.0,
	},
	{
		"flip-32bpp-ytileccs-to-64bpp-ytile-downscaling",
		"Flip from 32bpp non scaled fb to 64bpp downscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED_CCS, DRM_FORMAT_XRGB8888,
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB16161616F,
		1.0,
		2.0,
	},
	{
		"flip-32bpp-ytile-to-32bpp-ytilegen12rcccs-downscaling",
		"Flip from 32bpp non scaled fb to 32bpp downscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB8888,
		I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS, DRM_FORMAT_XRGB8888,
		1.0,
		2.0,
	},
	{
		"flip-32bpp-ytile-to-32bpp-ytileccs-downscaling",
		"Flip from 32bpp non scaled fb to 32bpp downscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB8888,
		I915_FORMAT_MOD_Y_TILED_CCS, DRM_FORMAT_XRGB8888,
		1.0,
		2.0,
	},
	{
		"flip-64bpp-ytile-to-32bpp-ytilercccs-downscaling",
		"Flip from 64bpp non scaled fb to 32bpp downscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB16161616F,
		I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS, DRM_FORMAT_XRGB8888,
		1.0,
		2.0,
	},
	{
		"flip-32bpp-ytile-to-64bpp-ytile-upscaling",
		"Flip from 32bpp non scaled fb to 64bpp upscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB8888,
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB16161616F,
		0.5,
		1.0,
	},
	{
		"flip-64bpp-ytile-to-32bpp-ytile-upscaling",
		"Flip from 64bpp non scaled fb to 32bpp upscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB16161616F,
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB8888,
		0.5,
		1.0,
	},
	{
		"flip-64bpp-ytile-to-16bpp-ytile-upscaling",
		"Flip from 64bpp non scaled fb to 16bpp upscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB16161616F,
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_RGB565,
		0.5,
		1.0,
	},
	{
		"flip-32bpp-ytileccs-to-64bpp-ytile-upscaling",
		"Flip from 32bpp non scaled fb to 64bpp upscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED_CCS, DRM_FORMAT_XRGB8888,
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB16161616F,
		0.5,
		1.0,
	},
	{
		"flip-32bpp-ytile-to-32bpp-ytilegen12rcccs-upscaling",
		"Flip from 32bpp non scaled fb to 32bpp upscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB8888,
		I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS, DRM_FORMAT_XRGB8888,
		0.5,
		1.0,
	},
	{
		"flip-32bpp-ytile-to-32bpp-ytileccs-upscaling",
		"Flip from 32bpp non scaled fb to 32bpp upscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB8888,
		I915_FORMAT_MOD_Y_TILED_CCS, DRM_FORMAT_XRGB8888,
		0.5,
		1.0,
	},
	{
		"flip-64bpp-ytile-to-32bpp-ytilercccs-upscaling",
		"Flip from 64bpp non scaled fb to 32bpp upscaled fb to stress CD clock programming",
		I915_FORMAT_MOD_Y_TILED, DRM_FORMAT_XRGB16161616F,
		I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS, DRM_FORMAT_XRGB8888,
		0.5,
		1.0,
	},
};

static void setup_fb(data_t *data, struct igt_fb *newfb, uint32_t width,
		     uint32_t height, uint64_t format, uint64_t modifier)
{
	igt_require(igt_display_has_format_mod(&data->display, format,
					       modifier));

	igt_create_color_fb(data->drm_fd, width, height,
			    format, modifier, 0, 1, 0, newfb);
}

static void free_fbs(data_t *data)
{
	igt_remove_fb(data->drm_fd, &data->small_fb);
	igt_remove_fb(data->drm_fd, &data->big_fb);
}

static void set_lut(data_t *data, enum pipe pipe)
{
	igt_pipe_t *pipe_obj = &data->display.pipes[pipe];
	struct drm_color_lut *lut;
	drmModeCrtc *crtc;
	int i, lut_size;

	crtc = drmModeGetCrtc(data->drm_fd, pipe_obj->crtc_id);
	lut_size = crtc->gamma_size;
	drmModeFreeCrtc(crtc);

	lut = malloc(sizeof(lut[0]) * lut_size);

	/*
	 * The scaler may have lower internal precision than
	 * the rest of the pipe. Limit the output to 8bpc using
	 * the legacy LUT.
	 */
	for (i = 0; i < lut_size; i++) {
		uint16_t v  = (i * 0xffff / (lut_size - 1)) & 0xff00;

		lut[i].red = v;
		lut[i].green = v;
		lut[i].blue = v;
	}

	igt_pipe_obj_replace_prop_blob(pipe_obj, IGT_CRTC_GAMMA_LUT,
				       lut, sizeof(lut[0]) * lut_size);

	free(lut);
}

static void clear_lut(data_t *data, enum pipe pipe)
{
	igt_pipe_t *pipe_obj = &data->display.pipes[pipe];

	igt_pipe_obj_set_prop_value(pipe_obj, IGT_CRTC_GAMMA_LUT, 0);
}

static void test_flip_to_scaled(data_t *data, uint32_t index,
				enum pipe pipe, igt_output_t *output,
				drmModeModeInfoPtr modetoset)
{
	igt_plane_t *primary;
	igt_crc_t small_crc, big_crc;
	struct drm_event_vblank ev;
	int ret;

	igt_display_reset(&data->display);
	igt_display_commit2(&data->display, COMMIT_ATOMIC);

	igt_debug("running on output %s pipe %s\n", output->name,
		  kmstest_pipe_name(pipe));

	if (data->big_fb.fb_id == 0) {
		setup_fb(data, &data->small_fb,
				data->attemptmodewidth * flip_scenario_test[index].firstmultiplier,
				data->attemptmodeheight * flip_scenario_test[index].firstmultiplier,
				flip_scenario_test[index].firstformat,
				flip_scenario_test[index].firstmodifier);

		setup_fb(data, &data->big_fb,
				data->attemptmodewidth * flip_scenario_test[index].secondmultiplier,
				data->attemptmodeheight * flip_scenario_test[index].secondmultiplier,
				flip_scenario_test[index].secondformat,
				flip_scenario_test[index].secondmodifier);

		igt_debug("small fb %dx%d\n", data->small_fb.width,
				data->small_fb.height);
		igt_debug("big fb %dx%d\n", data->big_fb.width,
				data->big_fb.height);
	}

	if (modetoset)
		igt_output_override_mode(output, modetoset);
	/*
	 * Setting a pipe invalidates the modetoset pointer.
	 * So, mode is overriden first and then pipe is set.
	 * Don't change this sequence.
	 */
	igt_output_set_pipe(output, pipe);

	primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
	igt_skip_on_f(!igt_plane_has_format_mod(primary, data->small_fb.drm_format, data->small_fb.modifier) ||
		      !igt_plane_has_format_mod(primary, data->big_fb.drm_format,
		      data->big_fb.modifier), "No requested format/modifier on pipe %s\n", kmstest_pipe_name(pipe));

	set_lut(data, pipe);
	igt_display_commit_atomic(&data->display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);

	if (data->pipe_crc) {
		igt_pipe_crc_stop(data->pipe_crc);
		igt_pipe_crc_free(data->pipe_crc);
	}
	data->pipe_crc = igt_pipe_crc_new(data->drm_fd, pipe,
					  INTEL_PIPE_CRC_SOURCE_AUTO);

	igt_plane_set_position(primary, 0, 0);
	igt_plane_set_fb(primary, &data->small_fb);
	igt_plane_set_size(primary, data->attemptmodewidth,
			   data->attemptmodeheight);
	ret = igt_display_try_commit_atomic(&data->display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);

	igt_skip_on_f(ret == -ERANGE, "Platform scaling limits exceeded, skipping.\n");
	igt_skip_on_f((ret == -EINVAL) && (!modetoset || modetoset->vrefresh > 90), "Valid/default mode too big, cdclk limits exceeded. Check next connector\n");
	igt_assert_eq(ret, 0);

	igt_pipe_crc_start(data->pipe_crc);
	igt_pipe_crc_get_current(data->drm_fd, data->pipe_crc, &small_crc);

	igt_plane_set_fb(primary, &data->big_fb);
	igt_plane_set_size(primary, data->attemptmodewidth,
			   data->attemptmodeheight);
	ret = igt_display_try_commit_atomic(&data->display,
					    DRM_MODE_ATOMIC_ALLOW_MODESET  |
					    DRM_MODE_PAGE_FLIP_EVENT, NULL);

	igt_skip_on_f(ret == -ERANGE, "Platform scaling limits exceeded, skipping.\n");
	igt_skip_on_f((ret == -EINVAL) && (!modetoset || modetoset->vrefresh > 90), "Valid/default mode too big, cdclk limits exceeded. Check next connector\n");
	igt_assert_eq(ret, 0);

	igt_assert(read(data->drm_fd, &ev, sizeof(ev)) == sizeof(ev));

	igt_pipe_crc_get_current(data->drm_fd, data->pipe_crc, &big_crc);
	igt_assert_crc_equal(&small_crc, &big_crc);

	igt_pipe_crc_stop(data->pipe_crc);
	igt_pipe_crc_free(data->pipe_crc);
	data->pipe_crc = NULL;

	clear_lut(data, pipe);

	modetoset = NULL;
	igt_output_set_pipe(output, PIPE_NONE);
	igt_plane_set_fb(primary, NULL);
	igt_display_commit2(&data->display, COMMIT_ATOMIC);
}

static drmModeModeInfoPtr find_mode(data_t *data, igt_output_t *output)
{
	drmModeModeInfoPtr modetoset = NULL;

	for (int i = 0; i < output->config.connector->count_modes; i++) {
		if (output->config.connector->modes[i].hdisplay == data->attemptmodewidth &&
		    output->config.connector->modes[i].vdisplay == data->attemptmodeheight) {
			if (modetoset &&
			    modetoset->vrefresh < output->config.connector->modes[i].vrefresh)
				continue;

			modetoset = &output->config.connector->modes[i];
		}
	}

	return modetoset;
}

igt_main
{
	enum pipe pipe;
	data_t data = {};
	igt_output_t *output;
	drmModeModeInfoPtr modetoset = NULL;

	igt_fixture {
		data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
		data.gen = intel_display_ver(intel_get_drm_devid(data.drm_fd));
		igt_require(data.gen >= 9);
		igt_display_require(&data.display, data.drm_fd);
		igt_require(data.display.is_atomic);
		igt_require_pipe_crc(data.drm_fd);
		kmstest_set_vt_graphics_mode();

		if (data.gen < 11) {
			data.attemptmodewidth = 640;
			data.attemptmodeheight = 480;
		} else {
			data.attemptmodewidth = 1920;
			data.attemptmodeheight = 1080;
		}
	}

	for (int index = 0; index < ARRAY_SIZE(flip_scenario_test); index++) {
		igt_describe(flip_scenario_test[index].describe);
		igt_subtest_with_dynamic(flip_scenario_test[index].name) {
			free_fbs(&data);
			for_each_pipe(&data.display, pipe) {
				bool found = false;
				for_each_valid_output_on_pipe(&data.display, pipe, output) {
					modetoset = find_mode(&data, output);
					if (modetoset) {
						found = true;
						igt_dynamic_f("pipe-%s-valid-mode", kmstest_pipe_name(pipe))
							test_flip_to_scaled(&data, index, pipe, output, modetoset);
						break;
					}
				}
				if (!found) {
					for_each_valid_output_on_pipe(&data.display, pipe, output) {
						igt_dynamic_f("pipe-%s-default-mode", kmstest_pipe_name(pipe))
							test_flip_to_scaled(&data, index, pipe, output, NULL);
					}
				}
				break;
			}
		}
	}

	igt_fixture {
		free_fbs(&data);
		if (data.pipe_crc) {
			igt_pipe_crc_stop(data.pipe_crc);
			igt_pipe_crc_free(data.pipe_crc);
			data.pipe_crc = NULL;
		}
		kmstest_set_vt_text_mode();
		igt_display_fini(&data.display);
	}
}