From patchwork Tue Jul 18 17:22:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Praveen Paneri X-Patchwork-Id: 9849169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C8425600CC for ; Tue, 18 Jul 2017 17:13:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8150285C6 for ; Tue, 18 Jul 2017 17:13:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D10F285D1; Tue, 18 Jul 2017 17:13:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 20C5A285C6 for ; Tue, 18 Jul 2017 17:13:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9BB8A6E391; Tue, 18 Jul 2017 17:13:35 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id AEC536E38C for ; Tue, 18 Jul 2017 17:13:30 +0000 (UTC) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP; 18 Jul 2017 10:13:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,378,1496127600"; d="scan'208";a="880154454" Received: from intel-desktop.iind.intel.com ([10.223.26.163]) by FMSMGA003.fm.intel.com with ESMTP; 18 Jul 2017 10:13:29 -0700 From: Praveen Paneri To: intel-gfx@lists.freedesktop.org Date: Tue, 18 Jul 2017 22:52:58 +0530 Message-Id: <1500398580-15846-4-git-send-email-praveen.paneri@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500398580-15846-1-git-send-email-praveen.paneri@intel.com> References: <1500398580-15846-1-git-send-email-praveen.paneri@intel.com> Cc: paulo.r.zanoni@intel.com, Praveen Paneri Subject: [Intel-gfx] [PATCH i-g-t v3 3/5] lib/igt_draw: add support for Y tiling X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Paulo Zanoni From: Paulo Zanoni Most of the patch is to change the tile/untile functions so they can work with Y-major tiling. v2: (Praveen) No skipping on BLT for Y-tile now as we have a fix for that. Reviewed-by: Praveen Paneri Signed-off-by: Paulo Zanoni Signed-off-by: Praveen Paneri --- lib/igt_draw.c | 171 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 121 insertions(+), 50 deletions(-) diff --git a/lib/igt_draw.c b/lib/igt_draw.c index db55cd9..76ffb6c 100644 --- a/lib/igt_draw.c +++ b/lib/igt_draw.c @@ -135,71 +135,118 @@ static int swizzle_addr(int addr, int swizzle) return addr; } -/* It's all in "pixel coordinates", so make sure you multiply/divide by the bpp - * if you need to. */ -static int linear_x_y_to_tiled_pos(int x, int y, uint32_t stride, int swizzle, - int bpp) +static int tile(int x, int y, uint32_t x_tile_size, uint32_t y_tile_size, + uint32_t line_size, bool xmajor) { - int x_tile_size, y_tile_size; - int x_tile_n, y_tile_n, x_tile_off, y_tile_off; - int line_size, tile_size; - int tile_n, tile_off; - int tiled_pos, tiles_per_line; - int pixel_size = bpp / 8; + int tile_size, tiles_per_line, x_tile_n, y_tile_n, tile_off, pos; + int tile_n, x_tile_off, y_tile_off; - line_size = stride; - x_tile_size = 512; - y_tile_size = 8; - tile_size = x_tile_size * y_tile_size; tiles_per_line = line_size / x_tile_size; + tile_size = x_tile_size * y_tile_size; + x_tile_n = x / x_tile_size; y_tile_n = y / y_tile_size; - y_tile_off = y % y_tile_size; + tile_n = y_tile_n * tiles_per_line + x_tile_n; - x_tile_n = (x * pixel_size) / x_tile_size; - x_tile_off = (x * pixel_size) % x_tile_size; + x_tile_off = x % x_tile_size; + y_tile_off = y % y_tile_size; - tile_n = y_tile_n * tiles_per_line + x_tile_n; - tile_off = y_tile_off * x_tile_size + x_tile_off; - tiled_pos = tile_n * tile_size + tile_off; + if (xmajor) + tile_off = y_tile_off * x_tile_size + x_tile_off; + else + tile_off = x_tile_off * y_tile_size + y_tile_off; - tiled_pos = swizzle_addr(tiled_pos, swizzle); + pos = tile_n * tile_size + tile_off; - return tiled_pos / pixel_size; + return pos; } -/* It's all in "pixel coordinates", so make sure you multiply/divide by the bpp - * if you need to. */ -static void tiled_pos_to_x_y_linear(int tiled_pos, uint32_t stride, - int swizzle, int bpp, int *x, int *y) +static void untile(int tiled_pos, int x_tile_size, int y_tile_size, + uint32_t line_size, bool xmajor, int *x, int *y) { - int tile_n, tile_off, tiles_per_line, line_size; + int tile_n, tile_off, tiles_per_line; int x_tile_off, y_tile_off; int x_tile_n, y_tile_n; - int x_tile_size, y_tile_size, tile_size; - int pixel_size = bpp / 8; - - tiled_pos = swizzle_addr(tiled_pos, swizzle); + int tile_size; - line_size = stride; - x_tile_size = 512; - y_tile_size = 8; tile_size = x_tile_size * y_tile_size; tiles_per_line = line_size / x_tile_size; tile_n = tiled_pos / tile_size; tile_off = tiled_pos % tile_size; - y_tile_off = tile_off / x_tile_size; - x_tile_off = tile_off % x_tile_size; + if (xmajor) { + y_tile_off = tile_off / x_tile_size; + x_tile_off = tile_off % x_tile_size; + } else { + y_tile_off = tile_off % y_tile_size; + x_tile_off = tile_off / y_tile_size; + } x_tile_n = tile_n % tiles_per_line; y_tile_n = tile_n / tiles_per_line; - *x = (x_tile_n * x_tile_size + x_tile_off) / pixel_size; + *x = (x_tile_n * x_tile_size + x_tile_off); *y = y_tile_n * y_tile_size + y_tile_off; } +static int linear_x_y_to_xtiled_pos(int x, int y, uint32_t stride, int swizzle, + int bpp) +{ + int pos; + int pixel_size = bpp / 8; + + x *= pixel_size; + pos = tile(x, y, 512, 8, stride, true); + pos = swizzle_addr(pos, swizzle); + return pos / pixel_size; +} + +static int linear_x_y_to_ytiled_pos(int x, int y, uint32_t stride, int swizzle, + int bpp) +{ + int ow_tile_n, pos; + int ow_size = 16; + int pixel_size = bpp / 8; + + /* We have an Y tiling of OWords, so use the tile() function to get the + * OW number, then adjust to the fact that the OW may have more than one + * pixel. */ + x *= pixel_size; + ow_tile_n = tile(x / ow_size, y, 128 / ow_size, 32, + stride / ow_size, false); + pos = ow_tile_n * ow_size + (x % ow_size); + pos = swizzle_addr(pos, swizzle); + return pos / pixel_size; +} + +static void xtiled_pos_to_x_y_linear(int tiled_pos, uint32_t stride, + int swizzle, int bpp, int *x, int *y) +{ + int pixel_size = bpp / 8; + + tiled_pos = swizzle_addr(tiled_pos, swizzle); + + untile(tiled_pos, 512, 8, stride, true, x, y); + *x /= pixel_size; +} + +static void ytiled_pos_to_x_y_linear(int tiled_pos, uint32_t stride, + int swizzle, int bpp, int *x, int *y) +{ + int ow_tile_n; + int ow_size = 16; + int pixel_size = bpp / 8; + + tiled_pos = swizzle_addr(tiled_pos, swizzle); + + ow_tile_n = tiled_pos / ow_size; + untile(ow_tile_n, 128 / ow_size, 32, stride / ow_size, false, x, y); + *x *= ow_size; + *x += tiled_pos % ow_size; + *x /= pixel_size; +} + static void set_pixel(void *_ptr, int index, uint32_t color, int bpp) { if (bpp == 16) { @@ -254,15 +301,26 @@ static void draw_rect_ptr_linear(void *ptr, uint32_t stride, } } -static void draw_rect_ptr_tiled(void *ptr, uint32_t stride, int swizzle, - struct rect *rect, uint32_t color, int bpp) +static void draw_rect_ptr_tiled(void *ptr, uint32_t stride, uint32_t tiling, + int swizzle, struct rect *rect, uint32_t color, + int bpp) { int x, y, pos; for (y = rect->y; y < rect->y + rect->h; y++) { for (x = rect->x; x < rect->x + rect->w; x++) { - pos = linear_x_y_to_tiled_pos(x, y, stride, swizzle, - bpp); + switch (tiling) { + case I915_TILING_X: + pos = linear_x_y_to_xtiled_pos(x, y, stride, + swizzle, bpp); + break; + case I915_TILING_Y: + pos = linear_x_y_to_ytiled_pos(x, y, stride, + swizzle, bpp); + break; + default: + igt_assert(false); + } set_pixel(ptr, pos, color, bpp); } } @@ -289,8 +347,9 @@ static void draw_rect_mmap_cpu(int fd, struct buf_data *buf, struct rect *rect, draw_rect_ptr_linear(ptr, buf->stride, rect, color, buf->bpp); break; case I915_TILING_X: - draw_rect_ptr_tiled(ptr, buf->stride, swizzle, rect, color, - buf->bpp); + case I915_TILING_Y: + draw_rect_ptr_tiled(ptr, buf->stride, tiling, swizzle, rect, + color, buf->bpp); break; default: igt_assert(false); @@ -339,8 +398,9 @@ static void draw_rect_mmap_wc(int fd, struct buf_data *buf, struct rect *rect, draw_rect_ptr_linear(ptr, buf->stride, rect, color, buf->bpp); break; case I915_TILING_X: - draw_rect_ptr_tiled(ptr, buf->stride, swizzle, rect, color, - buf->bpp); + case I915_TILING_Y: + draw_rect_ptr_tiled(ptr, buf->stride, tiling, swizzle, rect, + color, buf->bpp); break; default: igt_assert(false); @@ -367,8 +427,8 @@ static void draw_rect_pwrite_untiled(int fd, struct buf_data *buf, } static void draw_rect_pwrite_tiled(int fd, struct buf_data *buf, - struct rect *rect, uint32_t color, - uint32_t swizzle) + uint32_t tiling, struct rect *rect, + uint32_t color, uint32_t swizzle) { int i; int tiled_pos, x, y, pixel_size; @@ -391,8 +451,18 @@ static void draw_rect_pwrite_tiled(int fd, struct buf_data *buf, set_pixel(tmp, i, color, buf->bpp); for (tiled_pos = 0; tiled_pos < buf->size; tiled_pos += pixel_size) { - tiled_pos_to_x_y_linear(tiled_pos, buf->stride, swizzle, - buf->bpp, &x, &y); + switch (tiling) { + case I915_TILING_X: + xtiled_pos_to_x_y_linear(tiled_pos, buf->stride, + swizzle, buf->bpp, &x, &y); + break; + case I915_TILING_Y: + ytiled_pos_to_x_y_linear(tiled_pos, buf->stride, + swizzle, buf->bpp, &x, &y); + break; + default: + igt_assert(false); + } if (x >= rect->x && x < rect->x + rect->w && y >= rect->y && y < rect->y + rect->h) { @@ -429,7 +499,8 @@ static void draw_rect_pwrite(int fd, struct buf_data *buf, draw_rect_pwrite_untiled(fd, buf, rect, color); break; case I915_TILING_X: - draw_rect_pwrite_tiled(fd, buf, rect, color, swizzle); + case I915_TILING_Y: + draw_rect_pwrite_tiled(fd, buf, tiling, rect, color, swizzle); break; default: igt_assert(false);