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 repeatedly uploading frames of images, by uploading
30 * the data all at once with pwrite, and then blitting it to another buffer.
32 * You might think of this like a movie player, but that wouldn't be entirely
33 * accurate, since the access patterns of the memory would be different
34 * (generally, smaller source image, upscaled, an thus different memory access
35 * pattern in both texel fetch for the stretching and the destination writes).
36 * However, some things like swfdec would be doing something like this since
37 * they compute their data in host memory and upload the full sw rendered
40 * Additionally, those applications should be rendering at the screen refresh
41 * rate, while this test has no limits, and so can get itself into the
42 * working set larger than aperture size performance disaster.
44 * The current workload doing this path is pixmap upload for non-KMS.
61 #include "intel_bufmgr.h"
62 #include "intel_batchbuffer.h"
64 #include "intel_chipset.h"
66 #define OBJECT_WIDTH 1280
67 #define OBJECT_HEIGHT 720
70 get_time_in_secs(void)
74 gettimeofday(&tv, NULL);
76 return (double)tv.tv_sec + tv.tv_usec / 1000000.0;
80 do_render(drm_intel_bufmgr *bufmgr, struct intel_batchbuffer *batch,
81 drm_intel_bo *dst_bo, int width, int height)
83 uint32_t data[width * height];
86 static uint32_t seed = 1;
88 /* Generate some junk. Real workloads would be doing a lot more
89 * work to generate the junk.
91 for (i = 0; i < width * height; i++) {
95 /* Upload the junk. */
96 src_bo = drm_intel_bo_alloc(bufmgr, "src", sizeof(data), 4096);
97 drm_intel_bo_subdata(src_bo, 0, sizeof(data), data);
99 /* Render the junk to the dst. */
100 BLIT_COPY_BATCH_START(batch->devid, 0);
101 OUT_BATCH((3 << 24) | /* 32 bits */
102 (0xcc << 16) | /* copy ROP */
103 (width * 4) /* dst pitch */);
104 OUT_BATCH(0); /* dst x1,y1 */
105 OUT_BATCH((height << 16) | width); /* dst x2,y2 */
106 OUT_RELOC(dst_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
107 OUT_BATCH(0); /* src x1,y1 */
108 OUT_BATCH(width * 4); /* src pitch */
109 OUT_RELOC(src_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
112 intel_batchbuffer_flush(batch);
114 drm_intel_bo_unreference(src_bo);
117 int main(int argc, char **argv)
120 int object_size = OBJECT_WIDTH * OBJECT_HEIGHT * 4;
121 double start_time, end_time;
122 drm_intel_bo *dst_bo;
123 drm_intel_bufmgr *bufmgr;
124 struct intel_batchbuffer *batch;
129 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
130 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
132 batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
134 dst_bo = drm_intel_bo_alloc(bufmgr, "dst", object_size, 4096);
136 /* Prep loop to get us warmed up. */
137 for (i = 0; i < 60; i++) {
138 do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
140 drm_intel_bo_wait_rendering(dst_bo);
142 /* Do the actual timing. */
143 start_time = get_time_in_secs();
144 for (i = 0; i < 200; i++) {
145 do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
147 drm_intel_bo_wait_rendering(dst_bo);
148 end_time = get_time_in_secs();
150 printf("%d iterations in %.03f secs: %.01f MB/sec\n", i,
151 end_time - start_time,
152 (double)i * OBJECT_WIDTH * OBJECT_HEIGHT * 4 / 1024.0 / 1024.0 /
153 (end_time - start_time));
155 intel_batchbuffer_free(batch);
156 drm_intel_bufmgr_destroy(bufmgr);