Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 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 <stdbool.h> |
| 34 | #include <unistd.h> |
Daniel Vetter | aaebbc5 | 2014-03-22 15:35:16 +0100 | [diff] [blame] | 35 | #include <stdlib.h> |
| 36 | #include <sys/ioctl.h> |
| 37 | #include <stdio.h> |
| 38 | #include <string.h> |
Daniel Vetter | aaebbc5 | 2014-03-22 15:35:16 +0100 | [diff] [blame] | 39 | #include <fcntl.h> |
| 40 | #include <inttypes.h> |
| 41 | #include <errno.h> |
| 42 | #include <sys/stat.h> |
| 43 | #include <sys/time.h> |
| 44 | #include <getopt.h> |
| 45 | #include "drm.h" |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 46 | #include "ioctl_wrappers.h" |
Daniel Vetter | aaebbc5 | 2014-03-22 15:35:16 +0100 | [diff] [blame] | 47 | #include "drmtest.h" |
| 48 | #include "intel_bufmgr.h" |
| 49 | #include "intel_batchbuffer.h" |
Daniel Vetter | c03c6ce | 2014-03-22 21:34:29 +0100 | [diff] [blame] | 50 | #include "intel_io.h" |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 51 | #include "intel_chipset.h" |
Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 52 | |
| 53 | #define WIDTH 64 |
| 54 | #define STRIDE (WIDTH) |
| 55 | #define HEIGHT 64 |
| 56 | #define SIZE (HEIGHT*STRIDE) |
| 57 | |
| 58 | #define COLOR_C4 0xc4 |
| 59 | #define COLOR_4C 0x4c |
| 60 | |
| 61 | typedef struct { |
| 62 | int drm_fd; |
| 63 | uint32_t devid; |
| 64 | drm_intel_bufmgr *bufmgr; |
| 65 | uint8_t linear[WIDTH * HEIGHT]; |
| 66 | } data_t; |
| 67 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 68 | static void scratch_buf_init(data_t *data, struct igt_buf *buf, |
Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 69 | int width, int height, int stride, uint8_t color) |
| 70 | { |
| 71 | drm_intel_bo *bo; |
| 72 | int i; |
| 73 | |
| 74 | bo = drm_intel_bo_alloc(data->bufmgr, "", SIZE, 4096); |
| 75 | for (i = 0; i < width * height; i++) |
| 76 | data->linear[i] = color; |
| 77 | gem_write(data->drm_fd, bo->handle, 0, data->linear, |
| 78 | sizeof(data->linear)); |
| 79 | |
| 80 | buf->bo = bo; |
| 81 | buf->stride = stride; |
| 82 | buf->tiling = I915_TILING_NONE; |
| 83 | buf->size = SIZE; |
| 84 | } |
| 85 | |
| 86 | static void |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 87 | scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y, |
Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 88 | uint8_t color) |
| 89 | { |
| 90 | uint8_t val; |
| 91 | |
| 92 | gem_read(data->drm_fd, buf->bo->handle, 0, |
| 93 | data->linear, sizeof(data->linear)); |
| 94 | val = data->linear[y * WIDTH + x]; |
Daniel Vetter | 0b7ce4a | 2014-05-14 09:56:53 +0200 | [diff] [blame^] | 95 | igt_assert_f(val == color, |
| 96 | "Expected 0x%02x, found 0x%02x at (%d,%d)\n", |
| 97 | color, val, x, y); |
Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 98 | } |
| 99 | |
Daniel Vetter | dda85fb | 2013-12-10 10:18:32 +0100 | [diff] [blame] | 100 | igt_simple_main |
Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 101 | { |
| 102 | data_t data = {0, }; |
| 103 | struct intel_batchbuffer *batch = NULL; |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 104 | struct igt_buf dst; |
Daniel Vetter | 53a4d9e | 2014-03-22 15:49:02 +0100 | [diff] [blame] | 105 | igt_media_fillfunc_t media_fill = NULL; |
Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 106 | int i, j; |
| 107 | |
Daniel Vetter | dda85fb | 2013-12-10 10:18:32 +0100 | [diff] [blame] | 108 | data.drm_fd = drm_open_any_render(); |
| 109 | data.devid = intel_get_drm_devid(data.drm_fd); |
Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 110 | |
Daniel Vetter | dda85fb | 2013-12-10 10:18:32 +0100 | [diff] [blame] | 111 | data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096); |
| 112 | igt_assert(data.bufmgr); |
Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 113 | |
Daniel Vetter | 53a4d9e | 2014-03-22 15:49:02 +0100 | [diff] [blame] | 114 | media_fill = igt_get_media_fillfunc(data.devid); |
Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 115 | |
Daniel Vetter | dda85fb | 2013-12-10 10:18:32 +0100 | [diff] [blame] | 116 | igt_require_f(media_fill, |
| 117 | "no media-fill function\n"); |
Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 118 | |
Daniel Vetter | dda85fb | 2013-12-10 10:18:32 +0100 | [diff] [blame] | 119 | batch = intel_batchbuffer_alloc(data.bufmgr, data.devid); |
| 120 | igt_assert(batch); |
Xiang, Haihao | 641267d | 2013-11-29 13:47:31 +0800 | [diff] [blame] | 121 | |
| 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 | } |