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 <[email protected]>
25 * Xiang, Haihao <[email protected]>
26 */
27
28 /*
29 * This file is a basic test for the gpgpu_fill() function, a very simple
30 * workload for the GPGPU 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 #define WIDTH 64
49 #define HEIGHT 64
50 #define STRIDE (WIDTH)
51 #define SIZE (HEIGHT*STRIDE)
52
53 #define COLOR_C4 0xc4
54 #define COLOR_4C 0x4c
55
56 typedef struct {
57 int drm_fd;
58 uint32_t devid;
59 drm_intel_bufmgr *bufmgr;
60 uint8_t linear[WIDTH * HEIGHT];
61 } data_t;
62
scratch_buf_init(data_t * data,struct igt_buf * buf,int width,int height,int stride,uint8_t color)63 static void scratch_buf_init(data_t *data, struct igt_buf *buf,
64 int width, int height, int stride, uint8_t color)
65 {
66 drm_intel_bo *bo;
67 int i;
68
69 bo = drm_intel_bo_alloc(data->bufmgr, "", SIZE, 4096);
70 for (i = 0; i < width * height; i++)
71 data->linear[i] = color;
72 gem_write(data->drm_fd, bo->handle, 0, data->linear,
73 sizeof(data->linear));
74
75 memset(buf, 0, sizeof(*buf));
76
77 buf->bo = bo;
78 buf->stride = stride;
79 buf->tiling = I915_TILING_NONE;
80 buf->size = SIZE;
81 buf->bpp = 32;
82 }
83
84 static void
scratch_buf_check(data_t * data,struct igt_buf * buf,int x,int y,uint8_t color)85 scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y,
86 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];
93 igt_assert_f(val == color,
94 "Expected 0x%02x, found 0x%02x at (%d,%d)\n",
95 color, val, x, y);
96 }
97
98 igt_simple_main
99 {
100 data_t data = {0, };
101 struct intel_batchbuffer *batch = NULL;
102 struct igt_buf dst;
103 igt_fillfunc_t gpgpu_fill = NULL;
104 int i, j;
105
106 data.drm_fd = drm_open_driver_render(DRIVER_INTEL);
107 data.devid = intel_get_drm_devid(data.drm_fd);
108 igt_require_gem(data.drm_fd);
109
110 data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
111 igt_assert(data.bufmgr);
112
113 gpgpu_fill = igt_get_gpgpu_fillfunc(data.devid);
114
115 igt_require_f(gpgpu_fill,
116 "no gpgpu-fill function\n");
117
118 batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
119 igt_assert(batch);
120
121 scratch_buf_init(&data, &dst, WIDTH, HEIGHT, STRIDE, COLOR_C4);
122
123 for (i = 0; i < WIDTH; i++) {
124 for (j = 0; j < HEIGHT; j++) {
125 scratch_buf_check(&data, &dst, i, j, COLOR_C4);
126 }
127 }
128
129 gpgpu_fill(batch,
130 &dst, 0, 0, WIDTH / 2, HEIGHT / 2,
131 COLOR_4C);
132
133 for (i = 0; i < WIDTH; i++) {
134 for (j = 0; j < HEIGHT; j++) {
135 if (i < WIDTH / 2 && j < HEIGHT / 2)
136 scratch_buf_check(&data, &dst, i, j, COLOR_4C);
137 else
138 scratch_buf_check(&data, &dst, i, j, COLOR_C4);
139 }
140 }
141 }
142