blob: 0ca9e9de0eae8c0d661991d024c5f1dd7fef0998 [file] [log] [blame]
Eric Anholtcb5a35f2009-03-30 19:17:12 -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 repeatedly uploading frames of images, by uploading
30 * the data all at once with pwrite, and then blitting it to another buffer.
31 *
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
38 * frame.
39 *
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.
43 *
44 * The current workload we have that does large drm_intel_bo_map()
45 * uploads is texture upload for OpenGL (as it frequently is doing
46 * reformatting as it uploads the user's data, making bo_subdata less
47 * suitable)
48 */
49
50#include <stdlib.h>
51#include <stdio.h>
52#include <string.h>
53#include <assert.h>
54#include <fcntl.h>
55#include <inttypes.h>
56#include <errno.h>
57#include <sys/stat.h>
58#include <sys/time.h>
59#include "drm.h"
60#include "i915_drm.h"
61#include "drmtest.h"
62#include "intel_bufmgr.h"
63#include "intel_batchbuffer.h"
Chris Wilsond4d769a2010-10-26 10:59:18 +010064#include "intel_gpu_tools.h"
Eric Anholtcb5a35f2009-03-30 19:17:12 -070065
66#define OBJECT_WIDTH 1280
67#define OBJECT_HEIGHT 720
68
69static double
70get_time_in_secs(void)
71{
72 struct timeval tv;
73
74 gettimeofday(&tv, NULL);
75
76 return (double)tv.tv_sec + tv.tv_usec / 1000000.0;
77}
78
79static void
80do_render(drm_intel_bufmgr *bufmgr, struct intel_batchbuffer *batch,
81 drm_intel_bo *dst_bo, int width, int height)
82{
83 uint32_t *data;
84 drm_intel_bo *src_bo;
85 int i;
86 static uint32_t seed = 1;
87
88 src_bo = drm_intel_bo_alloc(bufmgr, "src", width * height * 4, 4096);
89
90 drm_intel_bo_map(src_bo, 1);
91
92 data = src_bo->virtual;
93 for (i = 0; i < width * height; i++) {
94 data[i] = seed++;
95 }
96
97 drm_intel_bo_unmap(src_bo);
98
99 /* Render the junk to the dst. */
100 BEGIN_BATCH(8);
101 OUT_BATCH(XY_SRC_COPY_BLT_CMD |
102 XY_SRC_COPY_BLT_WRITE_ALPHA |
103 XY_SRC_COPY_BLT_WRITE_RGB);
104 OUT_BATCH((3 << 24) | /* 32 bits */
105 (0xcc << 16) | /* copy ROP */
106 (width * 4) /* dst pitch */);
107 OUT_BATCH(0); /* dst x1,y1 */
108 OUT_BATCH((height << 16) | width); /* dst x2,y2 */
109 OUT_RELOC(dst_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
110 OUT_BATCH(0); /* src x1,y1 */
111 OUT_BATCH(width * 4); /* src pitch */
112 OUT_RELOC(src_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
113 ADVANCE_BATCH();
114
115 intel_batchbuffer_flush(batch);
116
117 drm_intel_bo_unreference(src_bo);
118}
119
120int main(int argc, char **argv)
121{
122 int fd;
123 int object_size = OBJECT_WIDTH * OBJECT_HEIGHT * 4;
124 double start_time, end_time;
125 drm_intel_bo *dst_bo;
126 drm_intel_bufmgr *bufmgr;
127 struct intel_batchbuffer *batch;
128 int i;
129
130 fd = drm_open_any();
131
132 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
133 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
134
Chris Wilsond4d769a2010-10-26 10:59:18 +0100135 batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
Eric Anholtcb5a35f2009-03-30 19:17:12 -0700136
137 dst_bo = drm_intel_bo_alloc(bufmgr, "dst", object_size, 4096);
138
139 /* Prep loop to get us warmed up. */
140 for (i = 0; i < 60; i++) {
141 do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
142 }
143 drm_intel_bo_wait_rendering(dst_bo);
144
145 /* Do the actual timing. */
146 start_time = get_time_in_secs();
147 for (i = 0; i < 200; i++) {
148 do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
149 }
150 drm_intel_bo_wait_rendering(dst_bo);
151 end_time = get_time_in_secs();
152
153 printf("%d iterations in %.03f secs: %.01f MB/sec\n", i,
154 end_time - start_time,
155 (double)i * OBJECT_WIDTH * OBJECT_HEIGHT * 4 / 1024.0 / 1024.0 /
156 (end_time - start_time));
157
158 intel_batchbuffer_free(batch);
159 drm_intel_bufmgr_destroy(bufmgr);
160
161 close(fd);
162
163 return 0;
164}