summaryrefslogtreecommitdiff
path: root/tests/i915/kms_dsc.c
blob: 617323e3aa3c9f5c3e0a7abe1d25a86c5e4df4f6 (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
/*
 * Copyright © 2018 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.
 *
 * Displayport Display Stream Compression test
 * Until the CRC support is added this needs to be invoked with --interactive
 * to manually verify if the test pattern is seen without corruption for each
 * subtest.
 *
 * Authors:
 * Manasi Navare <manasi.d.navare@intel.com>
 *
 */
#include "igt.h"
#include "igt_sysfs.h"
#include <errno.h>
#include <getopt.h>
#include <math.h>
#include <stdint.h>
#include <stdbool.h>
#include <strings.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <time.h>
#include <fcntl.h>
#include <termios.h>

IGT_TEST_DESCRIPTION("Test to validate display stream compression");

#define HDISPLAY_5K	5120
#define DSC_MIN_BPP	8

enum dsc_test_type {
	TEST_BASIC_DSC,
	TEST_DSC_BPP
};

typedef struct {
	int drm_fd;
	uint32_t devid;
	igt_display_t display;
	struct igt_fb fb_test_pattern;
	igt_output_t *output;
	int compression_bpp;
	int n_pipes;
	enum pipe pipe;
} data_t;

bool force_dsc_en_orig;
int force_dsc_restore_fd = -1;

const struct {
	const int format;
	const char format_str[20];
} test_list[] = {
	{DRM_FORMAT_XYUV8888, "XYUV8888"},
	{DRM_FORMAT_XRGB2101010, "XRGB2101010"},
	{DRM_FORMAT_XRGB16161616F, "XRGB16161616F"},
	{DRM_FORMAT_YUYV, "YUYV"},
};

static inline void manual(const char *expected)
{
	igt_debug_interactive_mode_check("all", expected);
}

static void force_dsc_enable(data_t *data)
{
	int ret;

	igt_debug("Forcing DSC enable on %s\n", data->output->name);
	ret = igt_force_dsc_enable(data->drm_fd,
				   data->output->name);
	igt_assert_f(ret > 0, "debugfs_write failed");
}

static void force_dsc_enable_bpp(data_t *data)
{
	int ret;

	igt_debug("Forcing DSC BPP to %d on %s\n",
		  data->compression_bpp, data->output->name);
	ret = igt_force_dsc_enable_bpp(data->drm_fd,
				       data->output->name,
				       data->compression_bpp);
	igt_assert_f(ret > 0, "debugfs_write failed");
}

static void save_force_dsc_en(data_t *data)
{
	force_dsc_en_orig =
		igt_is_force_dsc_enabled(data->drm_fd,
					 data->output->name);
	force_dsc_restore_fd =
		igt_get_dsc_debugfs_fd(data->drm_fd,
				       data->output->name);
	igt_assert(force_dsc_restore_fd >= 0);
}

static void restore_force_dsc_en(void)
{
	if (force_dsc_restore_fd < 0)
		return;

	igt_debug("Restoring DSC enable\n");
	igt_assert(write(force_dsc_restore_fd, force_dsc_en_orig ? "1" : "0", 1) == 1);

	close(force_dsc_restore_fd);
	force_dsc_restore_fd = -1;
}

static void kms_dsc_exit_handler(int sig)
{
	restore_force_dsc_en();
}

static int sort_drm_modes(const void *a, const void *b)
{
	const drmModeModeInfo *mode1 = a, *mode2 = b;

	return (mode1->clock < mode2->clock) - (mode2->clock < mode1->clock);
}

static drmModeModeInfo *get_highres_mode(igt_output_t *output)
{
	drmModeConnector *connector = output->config.connector;
	drmModeModeInfo *highest_mode = NULL;

	qsort(connector->modes,
	      connector->count_modes,
	      sizeof(drmModeModeInfo),
	      sort_drm_modes);

	highest_mode = &connector->modes[0];

	return highest_mode;
}

static bool check_dsc_on_connector(data_t *data)
{
	igt_output_t *output = data->output;

	if (!igt_is_dsc_supported(data->drm_fd, output->name)) {
		igt_debug("DSC not supported on connector %s\n",
			  output->name);
		return false;
	}

	if (!output_is_internal_panel(output) &&
	    !igt_is_fec_supported(data->drm_fd, output->name)) {
		igt_debug("DSC cannot be enabled without FEC on %s\n",
			  output->name);
		return false;
	}

	return true;
}

static bool check_big_joiner_test_constraint(data_t *data,
					     enum dsc_test_type test_type)
{
	igt_output_t *output = data->output;
	drmModeModeInfo *mode = get_highres_mode(output);

	if (test_type == TEST_DSC_BPP &&
	    mode->hdisplay >= HDISPLAY_5K) {
		igt_debug("Bigjoiner does not support force bpp on %s\n",
			   output->name);
		return false;
	}

	return true;
}

static bool check_big_joiner_pipe_constraint(data_t *data)
{
	igt_output_t *output = data->output;
	drmModeModeInfo *mode = get_highres_mode(output);

	if (mode->hdisplay >= HDISPLAY_5K &&
	    data->pipe == (data->n_pipes - 1)) {
		igt_debug("Pipe-%s not supported due to bigjoiner limitation\n",
			   kmstest_pipe_name(data->pipe));
		return false;
	}

	return true;
}

static bool check_dp_gen11_constraint(data_t *data)
{
	igt_output_t *output = data->output;
	uint32_t devid = intel_get_drm_devid(data->drm_fd);
	drmModeConnector *connector = output->config.connector;

	if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) &&
	    (data->pipe == PIPE_A) && IS_GEN11(devid)) {
		igt_debug("DSC not supported on pipe A on external DP in gen11 platforms\n");
		return false;
	}

	return true;
}

static void test_cleanup(data_t *data)
{
	igt_output_t *output = data->output;
	igt_plane_t *primary;

	primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
	igt_plane_set_fb(primary, NULL);

	igt_output_set_pipe(output, PIPE_NONE);
	igt_remove_fb(data->drm_fd, &data->fb_test_pattern);
}

/* re-probe connectors and do a modeset with DSC */
static void update_display(data_t *data, enum dsc_test_type test_type, unsigned int plane_format)
{
	bool enabled;
	igt_plane_t *primary;
	drmModeModeInfo *mode;
	igt_output_t *output = data->output;
	igt_display_t *display = &data->display;

	/* sanitize the state before starting the subtest */
	igt_display_reset(display);
	igt_display_commit(display);

	igt_debug("DSC is supported on %s\n", data->output->name);
	save_force_dsc_en(data);
	force_dsc_enable(data);

	if (test_type == TEST_DSC_BPP) {
		igt_debug("Trying to set BPP to %d\n", data->compression_bpp);
		force_dsc_enable_bpp(data);
	}

	igt_output_set_pipe(output, data->pipe);

	mode = get_highres_mode(output);
	igt_require(mode != NULL);
	igt_output_override_mode(output, mode);

	primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);

	igt_skip_on(!igt_plane_has_format_mod(primary, plane_format,
		    DRM_FORMAT_MOD_LINEAR));

	igt_create_pattern_fb(data->drm_fd,
			      mode->hdisplay,
			      mode->vdisplay,
			      plane_format,
			      DRM_FORMAT_MOD_LINEAR,
			      &data->fb_test_pattern);

	igt_plane_set_fb(primary, &data->fb_test_pattern);
	igt_display_commit(display);

	/* until we have CRC check support, manually check if RGB test
	 * pattern has no corruption.
	 */
	manual("RGB test pattern without corruption");

	enabled = igt_is_dsc_enabled(data->drm_fd, output->name);
	restore_force_dsc_en();
	igt_debug("Reset compression BPP\n");
	data->compression_bpp = 0;
	force_dsc_enable_bpp(data);

	igt_assert_f(enabled,
		     "Default DSC enable failed on connector: %s pipe: %s\n",
		     output->name,
		     kmstest_pipe_name(data->pipe));

	test_cleanup(data);
}

static void test_dsc(data_t *data, enum dsc_test_type test_type, int bpp, unsigned int plane_format)
{
	igt_display_t *display = &data->display;
	igt_output_t *output;
	char name[20];
	enum pipe pipe;

	for_each_pipe_with_valid_output(display, pipe, output) {
		data->compression_bpp = bpp;
		data->output = output;
		data->pipe = pipe;

		if (!check_dsc_on_connector(data))
			continue;

		if (!check_big_joiner_test_constraint(data, test_type))
			continue;

		if (!check_dp_gen11_constraint(data))
			continue;

		if (!check_big_joiner_pipe_constraint(data))
			continue;

		if (test_type == TEST_DSC_BPP)
			snprintf(name, sizeof(name), "-%dbpp", data->compression_bpp);
		else
			snprintf(name, sizeof(name), "-%s", igt_format_str(plane_format));

		igt_dynamic_f("pipe-%s-%s%s",  kmstest_pipe_name(data->pipe), data->output->name, name)
			update_display(data, test_type, plane_format);
	}
}

igt_main
{
	data_t data = {};
	int i;

	igt_fixture {
		data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
		data.devid = intel_get_drm_devid(data.drm_fd);
		kmstest_set_vt_graphics_mode();
		igt_install_exit_handler(kms_dsc_exit_handler);
		igt_display_require(&data.display, data.drm_fd);
		igt_display_require_output(&data.display);
		data.n_pipes = 0;
		for_each_pipe(&data.display, i)
			data.n_pipes++;
	}

	igt_describe("Tests basic display stream compression functionality if supported "
		     "by a connector by forcing DSC on all connectors that support it "
		     "with default parameters");
	igt_subtest_with_dynamic("basic-dsc")
			test_dsc(&data, TEST_BASIC_DSC, 0, DRM_FORMAT_XRGB8888);

	igt_describe("Tests basic display stream compression functionality if supported "
		     "by a connector by forcing DSC on all connectors that support it "
		     "with default parameters and creating fb with diff formats");
	igt_subtest_with_dynamic("dsc-with-formats") {
		for (int k = 0; k < ARRAY_SIZE(test_list); k++)
			test_dsc(&data, TEST_BASIC_DSC, 0, test_list[k].format);
	}

	igt_fixture
		igt_require(intel_display_ver(data.devid) >= 13);

	/*
	 * Output bpp/compressed bpp supported is 8 to 23 (pipe_bpp - 1)
	 * i.e. 8 to 23. So, here we are considering compressed bpp as min(8), mean (8+23/2)
	 * and max(23).
	 */
	igt_describe("Tests basic display stream compression functionality if supported "
		     "by a connector by forcing DSC on all connectors that support it "
		     "with certain BPP as the output BPP for the connector");
	igt_subtest_with_dynamic("dsc-with-bpp") {
		uint32_t bpp_list[] = {
			DSC_MIN_BPP,
			(DSC_MIN_BPP  + (DSC_MIN_BPP * 3) - 1) / 2,
			(DSC_MIN_BPP * 3) - 1
		};

		for (int j = 0; j < ARRAY_SIZE(bpp_list); j++)
			test_dsc(&data, TEST_DSC_BPP, bpp_list[j], DRM_FORMAT_XRGB8888);
	}

	igt_fixture {
		igt_display_fini(&data.display);
		close(data.drm_fd);
	}
}