igt/gem_close_race: Fix blit commands for BDW
authorChris Wilson <chris@chris-wilson.co.uk>
Wed, 29 Jan 2014 22:59:57 +0000 (22:59 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Wed, 29 Jan 2014 23:02:50 +0000 (23:02 +0000)
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=73958
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
tests/gem_close_race.c

index 3a2d847..4485db2 100644 (file)
@@ -49,6 +49,7 @@
 
 static char device[80];
 static uint32_t devid;
+static bool has_64bit_relocations;
 
 static void selfcopy(int fd, uint32_t handle, int loops)
 {
@@ -57,32 +58,41 @@ static void selfcopy(int fd, uint32_t handle, int loops)
        struct drm_i915_gem_execbuffer2 execbuf;
        struct drm_i915_gem_pwrite gem_pwrite;
        struct drm_i915_gem_create create;
-       uint32_t buf[10];
+       uint32_t buf[12], *b = buf;
 
        memset(reloc, 0, sizeof(reloc));
        memset(gem_exec, 0, sizeof(gem_exec));
        memset(&execbuf, 0, sizeof(execbuf));
 
-       buf[0] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
-       buf[1] = 0xcc << 16 | 1 << 25 | 1 << 24 | (4*1024);
-       buf[2] = 0;
-       buf[3] = 512 << 16 | 1024;
-       buf[4] = 0;
-       reloc[0].offset = 4 * sizeof(uint32_t);
+       *b = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+       if (has_64bit_relocations)
+               *b += 2;
+       b++;
+       *b++ = 0xcc << 16 | 1 << 25 | 1 << 24 | (4*1024);
+       *b++ = 0;
+       *b++ = 512 << 16 | 1024;
+
+       reloc[0].offset = (b - buf) * sizeof(*b);
        reloc[0].target_handle = handle;
        reloc[0].read_domains = I915_GEM_DOMAIN_RENDER;
        reloc[0].write_domain = I915_GEM_DOMAIN_RENDER;
+       *b++ = 0;
+       if (has_64bit_relocations)
+               *b++ = 0;
+
+       *b++ = 512 << 16;
+       *b++ = 4*1024;
 
-       buf[5] = 512 << 16;
-       buf[6] = 4*1024;
-       buf[7] = 0;
-       reloc[1].offset = 7 * sizeof(uint32_t);
+       reloc[1].offset = (b - buf) * sizeof(*b);
        reloc[1].target_handle = handle;
        reloc[1].read_domains = I915_GEM_DOMAIN_RENDER;
        reloc[1].write_domain = 0;
+       *b++ = 0;
+       if (has_64bit_relocations)
+               *b++ = 0;
 
-       buf[8] = MI_BATCH_BUFFER_END;
-       buf[9] = 0;
+       *b++ = MI_BATCH_BUFFER_END;
+       *b++ = 0;
 
        gem_exec[0].handle = handle;
 
@@ -95,13 +105,13 @@ static void selfcopy(int fd, uint32_t handle, int loops)
 
        execbuf.buffers_ptr = (uintptr_t)gem_exec;
        execbuf.buffer_count = 2;
-       execbuf.batch_len = sizeof(buf);
+       execbuf.batch_len = (b - buf) * sizeof(*b);
        if (HAS_BLT_RING(devid))
                execbuf.flags |= I915_EXEC_BLT;
 
        gem_pwrite.handle = gem_exec[1].handle;
        gem_pwrite.offset = 0;
-       gem_pwrite.size = sizeof(buf);
+       gem_pwrite.size = execbuf.batch_len;
        gem_pwrite.data_ptr = (uintptr_t)buf;
        if (drmIoctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite) == 0) {
                while (loops--)
@@ -218,6 +228,7 @@ igt_main
                int fd = open(device, O_RDWR);
                igt_assert(fd != -1);
                devid = intel_get_drm_devid(fd);
+               has_64bit_relocations = intel_gen(devid) >= 8;
                close(fd);
        }