blob: 12bbae3d0620e36f17c7734300ff7764fa2a37ec [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 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.
Eric Anholtcb5a35f2009-03-30 19:17:12 -070043 *
44 * The current workload doing this path is pixmap upload for non-KMS.
Eric Anholt8c641832009-03-26 17:15:11 -070045 */
46
Derek Morton1b492e32015-10-01 16:09:02 +010047#include "igt.h"
Eric Anholt8c641832009-03-26 17:15:11 -070048#include <stdlib.h>
49#include <stdio.h>
50#include <string.h>
51#include <assert.h>
52#include <fcntl.h>
53#include <inttypes.h>
54#include <errno.h>
55#include <sys/stat.h>
56#include <sys/time.h>
Daniel Vetter254f19b2014-03-22 21:29:01 +010057
58#include <drm.h>
59#include <i915_drm.h>
60
Eric Anholt8c641832009-03-26 17:15:11 -070061#define OBJECT_WIDTH 1280
62#define OBJECT_HEIGHT 720
63
64static double
65get_time_in_secs(void)
66{
67 struct timeval tv;
68
69 gettimeofday(&tv, NULL);
70
71 return (double)tv.tv_sec + tv.tv_usec / 1000000.0;
72}
73
74static void
75do_render(drm_intel_bufmgr *bufmgr, struct intel_batchbuffer *batch,
76 drm_intel_bo *dst_bo, int width, int height)
77{
78 uint32_t data[width * height];
79 drm_intel_bo *src_bo;
80 int i;
Eric Anholt7889abd2009-03-30 19:09:00 -070081 static uint32_t seed = 1;
Eric Anholt8c641832009-03-26 17:15:11 -070082
83 /* Generate some junk. Real workloads would be doing a lot more
84 * work to generate the junk.
85 */
86 for (i = 0; i < width * height; i++) {
Eric Anholt7889abd2009-03-30 19:09:00 -070087 data[i] = seed++;
Eric Anholt8c641832009-03-26 17:15:11 -070088 }
89
90 /* Upload the junk. */
91 src_bo = drm_intel_bo_alloc(bufmgr, "src", sizeof(data), 4096);
92 drm_intel_bo_subdata(src_bo, 0, sizeof(data), data);
93
94 /* Render the junk to the dst. */
Chris Wilson10552b52014-08-30 11:44:51 +010095 BLIT_COPY_BATCH_START(0);
Eric Anholt8c641832009-03-26 17:15:11 -070096 OUT_BATCH((3 << 24) | /* 32 bits */
97 (0xcc << 16) | /* copy ROP */
98 (width * 4) /* dst pitch */);
99 OUT_BATCH(0); /* dst x1,y1 */
100 OUT_BATCH((height << 16) | width); /* dst x2,y2 */
101 OUT_RELOC(dst_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
102 OUT_BATCH(0); /* src x1,y1 */
103 OUT_BATCH(width * 4); /* src pitch */
104 OUT_RELOC(src_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
105 ADVANCE_BATCH();
106
107 intel_batchbuffer_flush(batch);
108
109 drm_intel_bo_unreference(src_bo);
110}
111
112int main(int argc, char **argv)
113{
114 int fd;
115 int object_size = OBJECT_WIDTH * OBJECT_HEIGHT * 4;
116 double start_time, end_time;
117 drm_intel_bo *dst_bo;
118 drm_intel_bufmgr *bufmgr;
119 struct intel_batchbuffer *batch;
120 int i;
121
Micah Fedkec81d2932015-07-22 21:54:02 +0000122 fd = drm_open_driver(DRIVER_INTEL);
Eric Anholt8c641832009-03-26 17:15:11 -0700123
124 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
125 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
126
Chris Wilsond4d769a2010-10-26 10:59:18 +0100127 batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
Eric Anholt8c641832009-03-26 17:15:11 -0700128
129 dst_bo = drm_intel_bo_alloc(bufmgr, "dst", object_size, 4096);
130
131 /* Prep loop to get us warmed up. */
132 for (i = 0; i < 60; i++) {
133 do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
134 }
135 drm_intel_bo_wait_rendering(dst_bo);
136
137 /* Do the actual timing. */
138 start_time = get_time_in_secs();
139 for (i = 0; i < 200; i++) {
140 do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
141 }
142 drm_intel_bo_wait_rendering(dst_bo);
143 end_time = get_time_in_secs();
144
145 printf("%d iterations in %.03f secs: %.01f MB/sec\n", i,
146 end_time - start_time,
Eric Anholt7889abd2009-03-30 19:09:00 -0700147 (double)i * OBJECT_WIDTH * OBJECT_HEIGHT * 4 / 1024.0 / 1024.0 /
Eric Anholt8c641832009-03-26 17:15:11 -0700148 (end_time - start_time));
149
150 intel_batchbuffer_free(batch);
151 drm_intel_bufmgr_destroy(bufmgr);
152
153 close(fd);
154
155 return 0;
156}