blob: 7e3346eb74122f2595b3ebd560730c69b0355d11 [file] [log] [blame]
Eric Anholt8c641832009-03-26 17:15:11 -07001/*
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
Derek Morton1b492e32015-10-01 16:09:02 +010043#include "igt.h"
Eric Anholt8c641832009-03-26 17:15:11 -070044#include <stdlib.h>
45#include <stdio.h>
46#include <string.h>
47#include <assert.h>
48#include <fcntl.h>
49#include <inttypes.h>
50#include <errno.h>
51#include <sys/stat.h>
52#include <sys/time.h>
Eric Anholt8c641832009-03-26 17:15:11 -070053
54/* Happens to be 128k, the size of the VBOs used by i965's Mesa driver. */
55#define OBJECT_WIDTH 256
56#define OBJECT_HEIGHT 128
57
58static double
59get_time_in_secs(void)
60{
61 struct timeval tv;
62
63 gettimeofday(&tv, NULL);
64
65 return (double)tv.tv_sec + tv.tv_usec / 1000000.0;
66}
67
68static void
69do_render(drm_intel_bufmgr *bufmgr, struct intel_batchbuffer *batch,
70 drm_intel_bo *dst_bo, int width, int height)
71{
72 uint32_t data[64];
73 drm_intel_bo *src_bo;
74 int i;
Eric Anholt7889abd2009-03-30 19:09:00 -070075 static uint32_t seed = 1;
Eric Anholt8c641832009-03-26 17:15:11 -070076
77 src_bo = drm_intel_bo_alloc(bufmgr, "src", width * height * 4, 4096);
78
79 /* Upload some junk. Real workloads would be doing a lot more
80 * work to generate the junk.
81 */
82 for (i = 0; i < width * height;) {
83 int size, j;
84
85 /* Choose a size from 1 to 64 dwords to upload.
86 * Normal workloads have a distribution of sizes with a
87 * large tail (something in your scene's going to have a big
88 * pile of vertices, most likely), but I'm trying to get at
89 * the cost of the small uploads here.
90 */
91 size = random() % 64 + 1;
92 if (i + size > width * height)
93 size = width * height - i;
94
95 for (j = 0; j < size; j++)
Eric Anholt7889abd2009-03-30 19:09:00 -070096 data[j] = seed++;
Eric Anholt8c641832009-03-26 17:15:11 -070097
98 /* Upload the junk. */
99 drm_intel_bo_subdata(src_bo, i * 4, size * 4, data);
100
101 i += size;
102 }
103
104 /* Render the junk to the dst. */
Chris Wilson10552b52014-08-30 11:44:51 +0100105 BLIT_COPY_BATCH_START(0);
Eric Anholt8c641832009-03-26 17:15:11 -0700106 OUT_BATCH((3 << 24) | /* 32 bits */
107 (0xcc << 16) | /* copy ROP */
108 (width * 4) /* dst pitch */);
109 OUT_BATCH(0); /* dst x1,y1 */
110 OUT_BATCH((height << 16) | width); /* dst x2,y2 */
111 OUT_RELOC(dst_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
112 OUT_BATCH(0); /* src x1,y1 */
113 OUT_BATCH(width * 4); /* src pitch */
114 OUT_RELOC(src_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
115 ADVANCE_BATCH();
116
117 intel_batchbuffer_flush(batch);
118
119 drm_intel_bo_unreference(src_bo);
120}
121
122int main(int argc, char **argv)
123{
124 int fd;
125 int object_size = OBJECT_WIDTH * OBJECT_HEIGHT * 4;
126 double start_time, end_time;
127 drm_intel_bo *dst_bo;
128 drm_intel_bufmgr *bufmgr;
129 struct intel_batchbuffer *batch;
130 int i;
131
Micah Fedkec81d2932015-07-22 21:54:02 +0000132 fd = drm_open_driver(DRIVER_INTEL);
Eric Anholt8c641832009-03-26 17:15:11 -0700133
134 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
135 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
136
Chris Wilsond4d769a2010-10-26 10:59:18 +0100137 batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
Eric Anholt8c641832009-03-26 17:15:11 -0700138
139 dst_bo = drm_intel_bo_alloc(bufmgr, "dst", object_size, 4096);
140
141 /* Prep loop to get us warmed up. */
142 for (i = 0; i < 20; i++) {
143 do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
144 }
145 drm_intel_bo_wait_rendering(dst_bo);
146
147 /* Do the actual timing. */
148 start_time = get_time_in_secs();
149 for (i = 0; i < 1000; i++) {
150 do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
151 }
152 drm_intel_bo_wait_rendering(dst_bo);
153 end_time = get_time_in_secs();
154
155 printf("%d iterations in %.03f secs: %.01f MB/sec\n", i,
156 end_time - start_time,
Eric Anholt7889abd2009-03-30 19:09:00 -0700157 (double)i * OBJECT_WIDTH * OBJECT_HEIGHT * 4 / 1024.0 / 1024.0 /
Eric Anholt8c641832009-03-26 17:15:11 -0700158 (end_time - start_time));
159
160 intel_batchbuffer_free(batch);
161 drm_intel_bufmgr_destroy(bufmgr);
162
163 close(fd);
164
165 return 0;
166}