Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2009 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 | * Eric Anholt <eric@anholt.net> |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * Roughly simulates Mesa's current vertex buffer behavior: do a series of |
| 30 | * small pwrites on a moderately-sized buffer, then render using it. |
| 31 | * |
| 32 | * The vertex buffer uploads |
| 33 | * |
| 34 | * You might think of this like a movie player, but that wouldn't be entirely |
| 35 | * accurate, since the access patterns of the memory would be different |
| 36 | * (generally, smaller source image, upscaled, an thus different memory access |
| 37 | * pattern in both texel fetch for the stretching and the destination writes). |
| 38 | * However, some things like swfdec would be doing something like this since |
| 39 | * they compute their data in host memory and upload the full sw rendered |
| 40 | * frame. |
| 41 | */ |
| 42 | |
| 43 | #include <stdlib.h> |
| 44 | #include <stdio.h> |
| 45 | #include <string.h> |
| 46 | #include <assert.h> |
| 47 | #include <fcntl.h> |
| 48 | #include <inttypes.h> |
| 49 | #include <errno.h> |
| 50 | #include <sys/stat.h> |
| 51 | #include <sys/time.h> |
| 52 | #include "drm.h" |
| 53 | #include "i915_drm.h" |
| 54 | #include "drmtest.h" |
| 55 | #include "intel_bufmgr.h" |
| 56 | #include "intel_batchbuffer.h" |
Chris Wilson | d4d769a | 2010-10-26 10:59:18 +0100 | [diff] [blame] | 57 | #include "intel_gpu_tools.h" |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 58 | |
| 59 | /* Happens to be 128k, the size of the VBOs used by i965's Mesa driver. */ |
| 60 | #define OBJECT_WIDTH 256 |
| 61 | #define OBJECT_HEIGHT 128 |
| 62 | |
| 63 | static double |
| 64 | get_time_in_secs(void) |
| 65 | { |
| 66 | struct timeval tv; |
| 67 | |
| 68 | gettimeofday(&tv, NULL); |
| 69 | |
| 70 | return (double)tv.tv_sec + tv.tv_usec / 1000000.0; |
| 71 | } |
| 72 | |
| 73 | static void |
| 74 | do_render(drm_intel_bufmgr *bufmgr, struct intel_batchbuffer *batch, |
| 75 | drm_intel_bo *dst_bo, int width, int height) |
| 76 | { |
| 77 | uint32_t data[64]; |
| 78 | drm_intel_bo *src_bo; |
| 79 | int i; |
Eric Anholt | 7889abd | 2009-03-30 19:09:00 -0700 | [diff] [blame] | 80 | static uint32_t seed = 1; |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 81 | |
| 82 | src_bo = drm_intel_bo_alloc(bufmgr, "src", width * height * 4, 4096); |
| 83 | |
| 84 | /* Upload some junk. Real workloads would be doing a lot more |
| 85 | * work to generate the junk. |
| 86 | */ |
| 87 | for (i = 0; i < width * height;) { |
| 88 | int size, j; |
| 89 | |
| 90 | /* Choose a size from 1 to 64 dwords to upload. |
| 91 | * Normal workloads have a distribution of sizes with a |
| 92 | * large tail (something in your scene's going to have a big |
| 93 | * pile of vertices, most likely), but I'm trying to get at |
| 94 | * the cost of the small uploads here. |
| 95 | */ |
| 96 | size = random() % 64 + 1; |
| 97 | if (i + size > width * height) |
| 98 | size = width * height - i; |
| 99 | |
| 100 | for (j = 0; j < size; j++) |
Eric Anholt | 7889abd | 2009-03-30 19:09:00 -0700 | [diff] [blame] | 101 | data[j] = seed++; |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 102 | |
| 103 | /* Upload the junk. */ |
| 104 | drm_intel_bo_subdata(src_bo, i * 4, size * 4, data); |
| 105 | |
| 106 | i += size; |
| 107 | } |
| 108 | |
| 109 | /* Render the junk to the dst. */ |
| 110 | BEGIN_BATCH(8); |
| 111 | OUT_BATCH(XY_SRC_COPY_BLT_CMD | |
| 112 | XY_SRC_COPY_BLT_WRITE_ALPHA | |
| 113 | XY_SRC_COPY_BLT_WRITE_RGB); |
| 114 | OUT_BATCH((3 << 24) | /* 32 bits */ |
| 115 | (0xcc << 16) | /* copy ROP */ |
| 116 | (width * 4) /* dst pitch */); |
| 117 | OUT_BATCH(0); /* dst x1,y1 */ |
| 118 | OUT_BATCH((height << 16) | width); /* dst x2,y2 */ |
| 119 | OUT_RELOC(dst_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0); |
| 120 | OUT_BATCH(0); /* src x1,y1 */ |
| 121 | OUT_BATCH(width * 4); /* src pitch */ |
| 122 | OUT_RELOC(src_bo, I915_GEM_DOMAIN_RENDER, 0, 0); |
| 123 | ADVANCE_BATCH(); |
| 124 | |
| 125 | intel_batchbuffer_flush(batch); |
| 126 | |
| 127 | drm_intel_bo_unreference(src_bo); |
| 128 | } |
| 129 | |
| 130 | int main(int argc, char **argv) |
| 131 | { |
| 132 | int fd; |
| 133 | int object_size = OBJECT_WIDTH * OBJECT_HEIGHT * 4; |
| 134 | double start_time, end_time; |
| 135 | drm_intel_bo *dst_bo; |
| 136 | drm_intel_bufmgr *bufmgr; |
| 137 | struct intel_batchbuffer *batch; |
| 138 | int i; |
| 139 | |
| 140 | fd = drm_open_any(); |
| 141 | |
| 142 | bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
| 143 | drm_intel_bufmgr_gem_enable_reuse(bufmgr); |
| 144 | |
Chris Wilson | d4d769a | 2010-10-26 10:59:18 +0100 | [diff] [blame] | 145 | batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd)); |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 146 | |
| 147 | dst_bo = drm_intel_bo_alloc(bufmgr, "dst", object_size, 4096); |
| 148 | |
| 149 | /* Prep loop to get us warmed up. */ |
| 150 | for (i = 0; i < 20; i++) { |
| 151 | do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT); |
| 152 | } |
| 153 | drm_intel_bo_wait_rendering(dst_bo); |
| 154 | |
| 155 | /* Do the actual timing. */ |
| 156 | start_time = get_time_in_secs(); |
| 157 | for (i = 0; i < 1000; i++) { |
| 158 | do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT); |
| 159 | } |
| 160 | drm_intel_bo_wait_rendering(dst_bo); |
| 161 | end_time = get_time_in_secs(); |
| 162 | |
| 163 | printf("%d iterations in %.03f secs: %.01f MB/sec\n", i, |
| 164 | end_time - start_time, |
Eric Anholt | 7889abd | 2009-03-30 19:09:00 -0700 | [diff] [blame] | 165 | (double)i * OBJECT_WIDTH * OBJECT_HEIGHT * 4 / 1024.0 / 1024.0 / |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 166 | (end_time - start_time)); |
| 167 | |
| 168 | intel_batchbuffer_free(batch); |
| 169 | drm_intel_bufmgr_destroy(bufmgr); |
| 170 | |
| 171 | close(fd); |
| 172 | |
| 173 | return 0; |
| 174 | } |