testdisplay: Round tiled allocations up to pot stride and fence size
authorChris Wilson <chris@chris-wilson.co.uk>
Fri, 4 Nov 2011 13:26:13 +0000 (13:26 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Fri, 4 Nov 2011 13:25:45 +0000 (13:25 +0000)
Be simple and use the strictest requirements from gen2/3 with old
kernels so that this simply works everywhere.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42585

tests/testdisplay.c

index e58461a..3c9741c 100644 (file)
@@ -421,8 +421,23 @@ allocate_surface(int fd, int width, int height, uint32_t depth, uint32_t bpp,
        int size, stride;
 
        if (tiled) {
-               stride = (width * (bpp / 8) + 511) & ~511;
-               size = stride * (height + 7) & ~7;
+               int v;
+
+               /* Round the tiling up to the next power-of-two and the
+                * region up to the next pot fence size so that this works
+                * on all generations.
+                *
+                * This can still fail if the framebuffer is too large to
+                * be tiled. But then that failure is expected.
+                */
+
+               v = width * bpp / 8;
+               for (stride = 512; stride < v; stride *= 2)
+                       ;
+
+               v = stride * height;
+               for (size = 1024*1024; size < v; size *= 2)
+                       ;
        } else {
                /* Scan-out has a 64 byte alignment restriction */
                stride = (width * (bpp / 8) + 63) & ~63;
@@ -456,8 +471,8 @@ allocate_surface(int fd, int width, int height, uint32_t depth, uint32_t bpp,
                set_tiling.tiling_mode = I915_TILING_X;
                set_tiling.stride = stride;
                if (ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling)) {
-                       fprintf(stderr, "set tiling failed: %s\n",
-                               strerror(errno));
+                       fprintf(stderr, "set tiling failed: %s (stride=%d, size=%d)\n",
+                               strerror(errno), stride, size);
                        return NULL;
                }
        }