• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
33 #include "igt.h"
34 #include <stdbool.h>
35 #include <unistd.h>
36 #include <stdlib.h>
37 #include <sys/ioctl.h>
38 #include <stdio.h>
39 #include <string.h>
40 #include <fcntl.h>
41 #include <inttypes.h>
42 #include <errno.h>
43 #include <sys/stat.h>
44 #include <sys/time.h>
45 #include "drm.h"
46 #include "intel_bufmgr.h"
47 
48 IGT_TEST_DESCRIPTION("Basic test for the media_fill() function, a very simple"
49 		     " workload for the Media pipeline.");
50 
51 #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 
59 typedef struct {
60 	int drm_fd;
61 	uint32_t devid;
62 	drm_intel_bufmgr *bufmgr;
63 	uint8_t linear[WIDTH * HEIGHT];
64 } data_t;
65 
scratch_buf_init(data_t * data,struct igt_buf * buf,int width,int height,int stride,uint8_t color)66 static void scratch_buf_init(data_t *data, struct igt_buf *buf,
67 			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 	memset(buf, 0, sizeof(*buf));
79 
80 	buf->bo = bo;
81 	buf->stride = stride;
82 	buf->tiling = I915_TILING_NONE;
83 	buf->size = SIZE;
84 	buf->bpp = 32;
85 }
86 
87 static void
scratch_buf_check(data_t * data,struct igt_buf * buf,int x,int y,uint8_t color)88 scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y,
89 		uint8_t color)
90 {
91 	uint8_t val;
92 
93 	gem_read(data->drm_fd, buf->bo->handle, 0,
94 		data->linear, sizeof(data->linear));
95 	val = data->linear[y * WIDTH + x];
96 	igt_assert_f(val == color,
97 		     "Expected 0x%02x, found 0x%02x at (%d,%d)\n",
98 		     color, val, x, y);
99 }
100 
101 igt_simple_main
102 {
103 	data_t data = {0, };
104 	struct intel_batchbuffer *batch = NULL;
105 	struct igt_buf dst;
106 	igt_fillfunc_t media_fill = NULL;
107 	int i, j;
108 
109 	data.drm_fd = drm_open_driver_render(DRIVER_INTEL);
110 	igt_require_gem(data.drm_fd);
111 
112 	data.devid = intel_get_drm_devid(data.drm_fd);
113 
114 	data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
115 	igt_assert(data.bufmgr);
116 
117 	media_fill = igt_get_media_fillfunc(data.devid);
118 
119 	igt_require_f(media_fill,
120 		"no media-fill function\n");
121 
122 	batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
123 	igt_assert(batch);
124 
125 	scratch_buf_init(&data, &dst, WIDTH, HEIGHT, STRIDE, COLOR_C4);
126 
127 	for (i = 0; i < WIDTH; i++) {
128 		for (j = 0; j < HEIGHT; j++) {
129 			scratch_buf_check(&data, &dst, i, j, COLOR_C4);
130 		}
131 	}
132 
133 	media_fill(batch,
134 		&dst, 0, 0, WIDTH / 2, HEIGHT / 2,
135 		COLOR_4C);
136 
137 	for (i = 0; i < WIDTH; i++) {
138 		for (j = 0; j < HEIGHT; j++) {
139 			if (i < WIDTH / 2 && j < HEIGHT / 2)
140 				scratch_buf_check(&data, &dst, i, j, COLOR_4C);
141 			else
142 				scratch_buf_check(&data, &dst, i, j, COLOR_C4);
143 		}
144 	}
145 }
146