2 * Copyright © 2011 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 * Daniel Vetter <daniel.vetter@ffwll.ch>
29 * Testcase: Unreferencing of active buffers
31 * Execs buffers and immediately unreferences them, hence the kernel active list
32 * will be the last one to hold a reference on them. Usually libdrm bo caching
33 * prevents that by keeping another reference.
46 #include "intel_bufmgr.h"
47 #include "intel_batchbuffer.h"
48 #include "intel_gpu_tools.h"
50 static drm_intel_bufmgr *bufmgr;
51 struct intel_batchbuffer *batch;
52 static drm_intel_bo *load_bo;
54 int main(int argc, char **argv)
58 igt_skip_on_simulation();
62 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
64 fprintf(stderr, "failed to init libdrm\n");
67 /* don't enable buffer reuse!! */
68 //drm_intel_bufmgr_gem_enable_reuse(bufmgr);
70 batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
73 /* put some load onto the gpu to keep the light buffers active for long
75 for (i = 0; i < 1000; i++) {
76 load_bo = drm_intel_bo_alloc(bufmgr, "target bo", 1024*4096, 4096);
78 fprintf(stderr, "failed to alloc target buffer\n");
83 OUT_BATCH(XY_SRC_COPY_BLT_CMD |
84 XY_SRC_COPY_BLT_WRITE_ALPHA |
85 XY_SRC_COPY_BLT_WRITE_RGB);
86 OUT_BATCH((3 << 24) | /* 32 bits */
87 (0xcc << 16) | /* copy ROP */
89 OUT_BATCH(0); /* dst x1,y1 */
90 OUT_BATCH((1024 << 16) | 512);
91 OUT_RELOC(load_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
92 OUT_BATCH((0 << 16) | 512); /* src x1, y1 */
94 OUT_RELOC(load_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
97 intel_batchbuffer_flush(batch);
99 drm_intel_bo_disable_reuse(load_bo);
100 drm_intel_bo_unreference(load_bo);
103 drm_intel_bufmgr_destroy(bufmgr);