From patchwork Fri Jun 9 10:18:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Praveen Paneri X-Patchwork-Id: 9777883 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 8C4C660393 for ; Fri, 9 Jun 2017 10:09:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CB4C28396 for ; Fri, 9 Jun 2017 10:09:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7143B28548; Fri, 9 Jun 2017 10:09:33 +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 D59C728396 for ; Fri, 9 Jun 2017 10:09:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ECB1B6E59A; Fri, 9 Jun 2017 10:09:29 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5E6156E57A for ; Fri, 9 Jun 2017 10:09:28 +0000 (UTC) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jun 2017 03:09:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,317,1493708400"; d="scan'208";a="111127761" Received: from intel-desktop.iind.intel.com ([10.223.26.163]) by orsmga005.jf.intel.com with ESMTP; 09 Jun 2017 03:09:26 -0700 From: Praveen Paneri To: intel-gfx@lists.freedesktop.org Date: Fri, 9 Jun 2017 15:48:19 +0530 Message-Id: <1497003499-14841-1-git-send-email-praveen.paneri@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493390254-5232-4-git-send-email-praveen.paneri@intel.com> References: <1493390254-5232-4-git-send-email-praveen.paneri@intel.com> Cc: paulo.r.zanoni@intel.com, Praveen Paneri Subject: [Intel-gfx] [PATCH] lib/igt_draw: Add Y-tiling support 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 This patch adds Y-tiling support for igt_draw_rect function. v2: Use helper function to get tile sizes (Ville) v3: Moved igt_get_fb_tile_size() out of the for loop for better performance (Paulo) Signed-off-by: Praveen Paneri --- lib/igt_draw.c | 139 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 94 insertions(+), 45 deletions(-) diff --git a/lib/igt_draw.c b/lib/igt_draw.c index 29aec85..2138bf7 100644 --- a/lib/igt_draw.c +++ b/lib/igt_draw.c @@ -136,32 +136,45 @@ static int swizzle_addr(int addr, int swizzle) /* 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 linear_x_y_to_tiled_pos(int fd, int x, int y, uint32_t stride, int swizzle, + int bpp, int tiling, uint32_t tile_width, + uint32_t tile_height) { - 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; + uint32_t tile_size; + int tile_x, tile_y; /* Co-ordinates of the tile holding the pixel */ + int tile_x_off, tile_y_off; /* pixel position inside the tile */ int tile_n, tile_off; - int tiled_pos, tiles_per_line; + int line_size, tiles_per_line; + int tiled_pos; int pixel_size = bpp / 8; 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 = tile_width * tile_height; + tiles_per_line = line_size / tile_width; - y_tile_n = y / y_tile_size; - y_tile_off = y % y_tile_size; + tile_y = y / tile_height; + tile_y_off = y % tile_height; - x_tile_n = (x * pixel_size) / x_tile_size; - x_tile_off = (x * pixel_size) % x_tile_size; + tile_x = (x * pixel_size) / tile_width; + tile_x_off = (x * pixel_size) % tile_width; - 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; + tile_n = tile_y * tiles_per_line + tile_x; + + if (tiling == I915_TILING_X ) { + tile_off = tile_y_off * tile_width + tile_x_off; + } else { /* (tiling == I915_TILING_Y ) */ + int x_oword_n, x_oword_off; + int oword_size = 16; + + /* computation inside the tile */ + x_oword_n = tile_x_off / oword_size; + x_oword_off = tile_x_off % oword_size; + tile_off = x_oword_n * tile_height * oword_size + + tile_y_off * oword_size + + x_oword_off; + } + tiled_pos = tile_n * tile_size + tile_off; tiled_pos = swizzle_addr(tiled_pos, swizzle); return tiled_pos / pixel_size; @@ -169,34 +182,48 @@ static int linear_x_y_to_tiled_pos(int x, int y, uint32_t stride, int swizzle, /* 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 tiled_pos_to_x_y_linear(int fd, int tiled_pos, uint32_t stride, + int swizzle, int bpp, int *x, int *y, + int tiling, uint32_t tile_width, + uint32_t tile_height) { - int tile_n, tile_off, tiles_per_line, line_size; - int x_tile_off, y_tile_off; - int x_tile_n, y_tile_n; - int x_tile_size, y_tile_size, tile_size; + uint32_t tile_size; + int tile_x, tile_y; /* Co-ordinates of the tile holding the pixel */ + int tile_x_off, tile_y_off; /* pixel position inside the tile */ + int tile_n, tile_off; + int line_size, tiles_per_line; int pixel_size = bpp / 8; tiled_pos = swizzle_addr(tiled_pos, swizzle); 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 = tile_width * tile_height; + tiles_per_line = line_size / tile_width; 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; + tile_x = tile_n % tiles_per_line; + tile_y = tile_n / tiles_per_line; + + if (tiling == I915_TILING_X ) { + + tile_y_off = tile_off / tile_width; + tile_x_off = tile_off % tile_width; + } else { + int x_oword_n, x_oword_off; + int oword_size = 16; + + x_oword_n = tile_off / (oword_size * tile_height); + x_oword_off = tile_off % oword_size; - x_tile_n = tile_n % tiles_per_line; - y_tile_n = tile_n / tiles_per_line; + tile_x_off = x_oword_n * oword_size + x_oword_off; + tile_y_off = (tile_off - x_oword_n * oword_size * tile_height) + / oword_size; + } - *x = (x_tile_n * x_tile_size + x_tile_off) / pixel_size; - *y = y_tile_n * y_tile_size + y_tile_off; + *x = (tile_x * tile_width + tile_x_off) / pixel_size; + *y = tile_y * tile_height + tile_y_off; } static void set_pixel(void *_ptr, int index, uint32_t color, int bpp) @@ -224,15 +251,21 @@ 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(int fd, void *ptr, uint32_t stride, int swizzle, + struct rect *rect, uint32_t color, int bpp, + int tiling) { int x, y, pos; + uint32_t tile_width, tile_height; + + igt_get_fb_tile_size(fd, (uint64_t)igt_fb_tiling_to_mod(tiling), bpp, + &tile_width, &tile_height); 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); + pos = linear_x_y_to_tiled_pos(fd, x, y, stride, swizzle, + bpp, tiling, tile_width, + tile_height); set_pixel(ptr, pos, color, bpp); } } @@ -259,8 +292,12 @@ 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); + draw_rect_ptr_tiled(fd, ptr, buf->stride, swizzle, rect, color, + buf->bpp, tiling); + break; + case I915_TILING_Y: + draw_rect_ptr_tiled(fd, ptr, buf->stride, swizzle, rect, color, + buf->bpp, tiling); break; default: igt_assert(false); @@ -309,8 +346,12 @@ 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); + draw_rect_ptr_tiled(fd, ptr, buf->stride, swizzle, rect, color, + buf->bpp, tiling); + break; + case I915_TILING_Y: + draw_rect_ptr_tiled(fd, ptr, buf->stride, swizzle, rect, color, + buf->bpp, tiling); break; default: igt_assert(false); @@ -338,7 +379,7 @@ 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 swizzle, int tiling) { int i; int tiled_pos, x, y, pixel_size; @@ -347,6 +388,7 @@ static void draw_rect_pwrite_tiled(int fd, struct buf_data *buf, bool flush_tmp = false; int tmp_start_pos = 0; int pixels_written = 0; + uint32_t tile_width, tile_height; /* We didn't implement suport for the older tiling methods yet. */ igt_require(intel_gen(intel_get_drm_devid(fd)) >= 5); @@ -360,9 +402,13 @@ static void draw_rect_pwrite_tiled(int fd, struct buf_data *buf, for (i = 0; i < tmp_size; i++) set_pixel(tmp, i, color, buf->bpp); + igt_get_fb_tile_size(fd, (uint64_t)igt_fb_tiling_to_mod(tiling), + buf->bpp, &tile_width, &tile_height); + 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); + tiled_pos_to_x_y_linear(fd, tiled_pos, buf->stride, swizzle, + buf->bpp, &x, &y, tiling, tile_width, + tile_height); if (x >= rect->x && x < rect->x + rect->w && y >= rect->y && y < rect->y + rect->h) { @@ -399,7 +445,10 @@ 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); + draw_rect_pwrite_tiled(fd, buf, rect, color, swizzle, tiling); + break; + case I915_TILING_Y: + draw_rect_pwrite_tiled(fd, buf, rect, color, swizzle, tiling); break; default: igt_assert(false);