2 * Copyright © 2009 Intel Corporation
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:
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
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
24 * Eric Anholt <eric@anholt.net>
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.
32 * The vertex buffer uploads
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
55 #include "intel_bufmgr.h"
56 #include "intel_batchbuffer.h"
58 #include "intel_chipset.h"
60 /* Happens to be 128k, the size of the VBOs used by i965's Mesa driver. */
61 #define OBJECT_WIDTH 256
62 #define OBJECT_HEIGHT 128
65 get_time_in_secs(void)
69 gettimeofday(&tv, NULL);
71 return (double)tv.tv_sec + tv.tv_usec / 1000000.0;
75 do_render(drm_intel_bufmgr *bufmgr, struct intel_batchbuffer *batch,
76 drm_intel_bo *dst_bo, int width, int height)
81 static uint32_t seed = 1;
83 src_bo = drm_intel_bo_alloc(bufmgr, "src", width * height * 4, 4096);
85 /* Upload some junk. Real workloads would be doing a lot more
86 * work to generate the junk.
88 for (i = 0; i < width * height;) {
91 /* Choose a size from 1 to 64 dwords to upload.
92 * Normal workloads have a distribution of sizes with a
93 * large tail (something in your scene's going to have a big
94 * pile of vertices, most likely), but I'm trying to get at
95 * the cost of the small uploads here.
97 size = random() % 64 + 1;
98 if (i + size > width * height)
99 size = width * height - i;
101 for (j = 0; j < size; j++)
104 /* Upload the junk. */
105 drm_intel_bo_subdata(src_bo, i * 4, size * 4, data);
110 /* Render the junk to the dst. */
111 BLIT_COPY_BATCH_START(batch->devid, 0);
112 OUT_BATCH((3 << 24) | /* 32 bits */
113 (0xcc << 16) | /* copy ROP */
114 (width * 4) /* dst pitch */);
115 OUT_BATCH(0); /* dst x1,y1 */
116 OUT_BATCH((height << 16) | width); /* dst x2,y2 */
117 OUT_RELOC(dst_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
118 OUT_BATCH(0); /* src x1,y1 */
119 OUT_BATCH(width * 4); /* src pitch */
120 OUT_RELOC(src_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
123 intel_batchbuffer_flush(batch);
125 drm_intel_bo_unreference(src_bo);
128 int main(int argc, char **argv)
131 int object_size = OBJECT_WIDTH * OBJECT_HEIGHT * 4;
132 double start_time, end_time;
133 drm_intel_bo *dst_bo;
134 drm_intel_bufmgr *bufmgr;
135 struct intel_batchbuffer *batch;
140 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
141 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
143 batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
145 dst_bo = drm_intel_bo_alloc(bufmgr, "dst", object_size, 4096);
147 /* Prep loop to get us warmed up. */
148 for (i = 0; i < 20; i++) {
149 do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
151 drm_intel_bo_wait_rendering(dst_bo);
153 /* Do the actual timing. */
154 start_time = get_time_in_secs();
155 for (i = 0; i < 1000; i++) {
156 do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
158 drm_intel_bo_wait_rendering(dst_bo);
159 end_time = get_time_in_secs();
161 printf("%d iterations in %.03f secs: %.01f MB/sec\n", i,
162 end_time - start_time,
163 (double)i * OBJECT_WIDTH * OBJECT_HEIGHT * 4 / 1024.0 / 1024.0 /
164 (end_time - start_time));
166 intel_batchbuffer_free(batch);
167 drm_intel_bufmgr_destroy(bufmgr);