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>
40 #include "intel_bufmgr.h"
41 #include "intel_batchbuffer.h"
42 #include "intel_gpu_tools.h"
45 * Testcase: pwrite/pread consistency when touching partial cachelines
47 * Some fancy new pwrite/pread optimizations clflush in-line while
48 * reading/writing. Check whether all required clflushes happen.
50 * Unfortunately really old mesa used unaligned pread/pwrite for s/w fallback
51 * rendering, so we need to check whether this works on tiled buffers, too.
55 static drm_intel_bufmgr *bufmgr;
56 struct intel_batchbuffer *batch;
58 drm_intel_bo *scratch_bo;
59 drm_intel_bo *staging_bo;
60 drm_intel_bo *tiled_staging_bo;
61 unsigned long scratch_pitch;
62 #define BO_SIZE (32*4096)
64 uint64_t mappable_gtt_limit;
68 copy_bo(drm_intel_bo *src, int src_tiled,
69 drm_intel_bo *dst, int dst_tiled)
71 unsigned long dst_pitch = scratch_pitch;
72 unsigned long src_pitch = scratch_pitch;
73 uint32_t cmd_bits = 0;
75 /* dst is tiled ... */
76 if (intel_gen(devid) >= 4 && dst_tiled) {
78 cmd_bits |= XY_SRC_COPY_BLT_DST_TILED;
81 if (intel_gen(devid) >= 4 && dst_tiled) {
83 cmd_bits |= XY_SRC_COPY_BLT_SRC_TILED;
87 OUT_BATCH(XY_SRC_COPY_BLT_CMD |
88 XY_SRC_COPY_BLT_WRITE_ALPHA |
89 XY_SRC_COPY_BLT_WRITE_RGB |
91 OUT_BATCH((3 << 24) | /* 32 bits */
92 (0xcc << 16) | /* copy ROP */
94 OUT_BATCH(0 << 16 | 0);
95 OUT_BATCH(BO_SIZE/scratch_pitch << 16 | 1024);
96 OUT_RELOC_FENCED(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
97 OUT_BATCH(0 << 16 | 0);
99 OUT_RELOC_FENCED(src, I915_GEM_DOMAIN_RENDER, 0, 0);
102 intel_batchbuffer_flush(batch);
106 blt_bo_fill(drm_intel_bo *tmp_bo, drm_intel_bo *bo, int val)
111 drm_intel_gem_bo_map_gtt(tmp_bo);
112 gtt_ptr = tmp_bo->virtual;
114 for (i = 0; i < BO_SIZE; i++)
117 drm_intel_gem_bo_unmap_gtt(tmp_bo);
119 if (bo->offset < mappable_gtt_limit &&
120 (IS_G33(devid) || intel_gen(devid) >= 4))
121 drmtest_trash_aperture();
123 copy_bo(tmp_bo, 0, bo, 1);
126 #define MAX_BLT_SIZE 128
128 int main(int argc, char **argv)
131 uint8_t tmp[BO_SIZE];
132 uint8_t compare_tmp[BO_SIZE];
133 uint32_t tiling_mode = I915_TILING_X;
139 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
140 //drm_intel_bufmgr_gem_enable_reuse(bufmgr);
141 devid = intel_get_drm_devid(fd);
142 batch = intel_batchbuffer_alloc(bufmgr, devid);
144 /* overallocate the buffers we're actually using because */
145 scratch_bo = drm_intel_bo_alloc_tiled(bufmgr, "scratch bo", 1024,
147 &tiling_mode, &scratch_pitch, 0);
148 assert(tiling_mode == I915_TILING_X);
149 assert(scratch_pitch == 4096);
150 staging_bo = drm_intel_bo_alloc(bufmgr, "staging bo", BO_SIZE, 4096);
151 tiled_staging_bo = drm_intel_bo_alloc_tiled(bufmgr, "scratch bo", 1024,
156 drmtest_init_aperture_trashers(bufmgr);
157 mappable_gtt_limit = gem_mappable_aperture_size();
159 printf("checking partial reads\n");
160 for (i = 0; i < ROUNDS; i++) {
164 blt_bo_fill(staging_bo, scratch_bo, i);
166 start = random() % BO_SIZE;
167 len = random() % (BO_SIZE-start) + 1;
169 drm_intel_bo_get_subdata(scratch_bo, start, len, tmp);
170 for (j = 0; j < len; j++) {
172 printf("mismatch at %i, got: %i, expected: %i\n",
173 start + j, tmp[j], val);
178 drmtest_progress("partial reads test: ", i, ROUNDS);
181 printf("checking partial writes\n");
182 for (i = 0; i < ROUNDS; i++) {
186 blt_bo_fill(staging_bo, scratch_bo, i);
188 start = random() % BO_SIZE;
189 len = random() % (BO_SIZE-start) + 1;
191 memset(tmp, i + 63, BO_SIZE);
193 drm_intel_bo_subdata(scratch_bo, start, len, tmp);
195 copy_bo(scratch_bo, 1, tiled_staging_bo, 1);
196 drm_intel_bo_get_subdata(tiled_staging_bo, 0, BO_SIZE,
199 for (j = 0; j < start; j++) {
200 if (compare_tmp[j] != val) {
201 printf("amismatch at %i, got: %i, expected: %i\n",
206 for (; j < start + len; j++) {
207 if (compare_tmp[j] != tmp[0]) {
208 printf("bmismatch at %i, got: %i, expected: %i\n",
213 for (; j < BO_SIZE; j++) {
214 if (compare_tmp[j] != val) {
215 printf("cmismatch at %i, got: %i, expected: %i\n",
220 drm_intel_gem_bo_unmap_gtt(staging_bo);
222 drmtest_progress("partial writes test: ", i, ROUNDS);
225 printf("checking partial writes after partial reads\n");
226 for (i = 0; i < ROUNDS; i++) {
230 blt_bo_fill(staging_bo, scratch_bo, i);
233 start = random() % BO_SIZE;
234 len = random() % (BO_SIZE-start) + 1;
236 drm_intel_bo_get_subdata(scratch_bo, start, len, tmp);
237 for (j = 0; j < len; j++) {
239 printf("mismatch in read at %i, got: %i, expected: %i\n",
240 start + j, tmp[j], val);
245 /* Change contents through gtt to make the pread cachelines
247 val = (i + 17) % 256;
248 blt_bo_fill(staging_bo, scratch_bo, val);
251 start = random() % BO_SIZE;
252 len = random() % (BO_SIZE-start) + 1;
254 memset(tmp, i + 63, BO_SIZE);
256 drm_intel_bo_subdata(scratch_bo, start, len, tmp);
258 copy_bo(scratch_bo, 1, tiled_staging_bo, 1);
259 drm_intel_bo_get_subdata(tiled_staging_bo, 0, BO_SIZE,
262 for (j = 0; j < start; j++) {
263 if (compare_tmp[j] != val) {
264 printf("mismatch at %i, got: %i, expected: %i\n",
269 for (; j < start + len; j++) {
270 if (compare_tmp[j] != tmp[0]) {
271 printf("mismatch at %i, got: %i, expected: %i\n",
276 for (; j < BO_SIZE; j++) {
277 if (compare_tmp[j] != val) {
278 printf("mismatch at %i, got: %i, expected: %i\n",
283 drm_intel_gem_bo_unmap_gtt(staging_bo);
285 drmtest_progress("partial read/writes test: ", i, ROUNDS);
288 drmtest_cleanup_aperture_trashers();
289 drm_intel_bufmgr_destroy(bufmgr);