blob: e3564e8b5d0edc0d2a8de724aeb05de16aa026b0 [file] [log] [blame]
Xiang, Haihao641267d2013-11-29 13:47:31 +08001/*
2 * Copyright © 2013 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 * Damien Lespiau <damien.lespiau@intel.com>
25 * Xiang, Haihao <haihao.xiang@intel.com>
26 */
27
28/*
29 * This file is a basic test for the media_fill() function, a very simple
30 * workload for the Media pipeline.
31 */
32
Thomas Wood804e11f2015-08-17 17:57:43 +010033#include "igt.h"
Xiang, Haihao641267d2013-11-29 13:47:31 +080034#include <stdbool.h>
35#include <unistd.h>
Daniel Vetteraaebbc52014-03-22 15:35:16 +010036#include <stdlib.h>
37#include <sys/ioctl.h>
38#include <stdio.h>
39#include <string.h>
Daniel Vetteraaebbc52014-03-22 15:35:16 +010040#include <fcntl.h>
41#include <inttypes.h>
42#include <errno.h>
43#include <sys/stat.h>
44#include <sys/time.h>
Daniel Vetteraaebbc52014-03-22 15:35:16 +010045#include "drm.h"
Daniel Vetteraaebbc52014-03-22 15:35:16 +010046#include "intel_bufmgr.h"
Xiang, Haihao641267d2013-11-29 13:47:31 +080047
Thomas Woodb2ac2642014-11-28 11:02:44 +000048IGT_TEST_DESCRIPTION("Basic test for the media_fill() function, a very simple"
49 " workload for the Media pipeline.");
50
Xiang, Haihao641267d2013-11-29 13:47:31 +080051#define WIDTH 64
52#define STRIDE (WIDTH)
53#define HEIGHT 64
54#define SIZE (HEIGHT*STRIDE)
55
56#define COLOR_C4 0xc4
57#define COLOR_4C 0x4c
58
59typedef struct {
60 int drm_fd;
61 uint32_t devid;
62 drm_intel_bufmgr *bufmgr;
63 uint8_t linear[WIDTH * HEIGHT];
64} data_t;
65
Daniel Vetter83a4c7d2014-03-22 15:44:48 +010066static void scratch_buf_init(data_t *data, struct igt_buf *buf,
Xiang, Haihao641267d2013-11-29 13:47:31 +080067 int width, int height, int stride, uint8_t color)
68{
69 drm_intel_bo *bo;
70 int i;
71
72 bo = drm_intel_bo_alloc(data->bufmgr, "", SIZE, 4096);
73 for (i = 0; i < width * height; i++)
74 data->linear[i] = color;
75 gem_write(data->drm_fd, bo->handle, 0, data->linear,
76 sizeof(data->linear));
77
78 buf->bo = bo;
79 buf->stride = stride;
80 buf->tiling = I915_TILING_NONE;
81 buf->size = SIZE;
82}
83
84static void
Daniel Vetter83a4c7d2014-03-22 15:44:48 +010085scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y,
Xiang, Haihao641267d2013-11-29 13:47:31 +080086 uint8_t color)
87{
88 uint8_t val;
89
90 gem_read(data->drm_fd, buf->bo->handle, 0,
91 data->linear, sizeof(data->linear));
92 val = data->linear[y * WIDTH + x];
Daniel Vetter0b7ce4a2014-05-14 09:56:53 +020093 igt_assert_f(val == color,
94 "Expected 0x%02x, found 0x%02x at (%d,%d)\n",
95 color, val, x, y);
Xiang, Haihao641267d2013-11-29 13:47:31 +080096}
97
Daniel Vetterdda85fb2013-12-10 10:18:32 +010098igt_simple_main
Xiang, Haihao641267d2013-11-29 13:47:31 +080099{
100 data_t data = {0, };
101 struct intel_batchbuffer *batch = NULL;
Daniel Vetter83a4c7d2014-03-22 15:44:48 +0100102 struct igt_buf dst;
Zhenyu Wang106f0bf2014-12-03 18:56:39 +0800103 igt_fillfunc_t media_fill = NULL;
Xiang, Haihao641267d2013-11-29 13:47:31 +0800104 int i, j;
105
Micah Fedkec81d2932015-07-22 21:54:02 +0000106 data.drm_fd = drm_open_driver_render(DRIVER_INTEL);
Chris Wilson56741ce2017-04-03 19:18:54 +0100107 igt_require_gem(data.drm_fd);
Chris Wilson537e0b82017-04-03 12:02:17 +0100108
Daniel Vetterdda85fb2013-12-10 10:18:32 +0100109 data.devid = intel_get_drm_devid(data.drm_fd);
Xiang, Haihao641267d2013-11-29 13:47:31 +0800110
Daniel Vetterdda85fb2013-12-10 10:18:32 +0100111 data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
112 igt_assert(data.bufmgr);
Xiang, Haihao641267d2013-11-29 13:47:31 +0800113
Daniel Vetter53a4d9e2014-03-22 15:49:02 +0100114 media_fill = igt_get_media_fillfunc(data.devid);
Xiang, Haihao641267d2013-11-29 13:47:31 +0800115
Daniel Vetterdda85fb2013-12-10 10:18:32 +0100116 igt_require_f(media_fill,
117 "no media-fill function\n");
Xiang, Haihao641267d2013-11-29 13:47:31 +0800118
Daniel Vetterdda85fb2013-12-10 10:18:32 +0100119 batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
120 igt_assert(batch);
Xiang, Haihao641267d2013-11-29 13:47:31 +0800121
122 scratch_buf_init(&data, &dst, WIDTH, HEIGHT, STRIDE, COLOR_C4);
123
124 for (i = 0; i < WIDTH; i++) {
125 for (j = 0; j < HEIGHT; j++) {
126 scratch_buf_check(&data, &dst, i, j, COLOR_C4);
127 }
128 }
129
130 media_fill(batch,
131 &dst, 0, 0, WIDTH / 2, HEIGHT / 2,
132 COLOR_4C);
133
134 for (i = 0; i < WIDTH; i++) {
135 for (j = 0; j < HEIGHT; j++) {
136 if (i < WIDTH / 2 && j < HEIGHT / 2)
137 scratch_buf_check(&data, &dst, i, j, COLOR_4C);
138 else
139 scratch_buf_check(&data, &dst, i, j, COLOR_C4);
140 }
141 }
142}