From 4c7c94ad98ac94a1f8fffbf2ffd79fc3bfcef647 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 4 Nov 2011 13:26:13 +0000 Subject: [PATCH] testdisplay: Round tiled allocations up to pot stride and fence size 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 | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/testdisplay.c b/tests/testdisplay.c index e58461af..3c9741c7 100644 --- a/tests/testdisplay.c +++ b/tests/testdisplay.c @@ -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; } }