lib/igt_fb: Let others use igt_get_fb_tile_size
PATCH 1/5 lib/igt_fb: Let others use igt_get_fb_tile_size
This function can be used by igt_draw to get accurate tile dimensions for all tile formats.
--- lib/igt_fb.c | 2 +- lib/igt_fb.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
lib/igt_fb.c +1 -1
@@ -74,7 +74,7 @@ static struct format_desc_struct {#define for_each_format (f) \ for (f = format_desc; f - format_desc < ARRAY_SIZE(format_desc); f++) -static void igt_get_fb_tile_size (int fd,uint64_t tiling,int fb_bpp, +void igt_get_fb_tile_size (int fd,uint64_t tiling,int fb_bpp,unsigned *width_ret,unsigned *height_ret) {switch (tiling) {
lib/igt_fb.h +2 -1
@@ -94,7 +94,8 @@ enum igt_text_align { align_vcenter =0x04 , align_hcenter = 0x08, }; - +void igt_get_fb_tile_size (int fd,uint64_t tiling,int fb_bpp, +unsigned *width_ret,unsigned *height_ret);void igt_calc_fb_size (int fd,int width,int height,int bpp,uint64_t tiling,unsigned *size_ret,unsigned *stride_ret);unsigned int
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/5 lib/igt_fb: Add helper function for tile_to_mod
igt_get_fb_tile_size function takes modifer as an argument This helper function will let users to convert tiling to modifier and use igt_get_fb_tile_size()
--- lib/igt_fb.c | 27 +++++++++++++++++++++++++++ lib/igt_fb.h | 1 + 2 files changed, 28 insertions(+)
lib/igt_fb.c +27 -0
@@ -206,6 +206,33 @@ uint64_t igt_fb_mod_to_tiling(uint64_t modifier) } } +/** +* igt_fb_tiling_to_mod: +* @tiling: DRM framebuffer tiling +* +* This function converts a DRM framebuffer tiling to its corresponding +* modifier constant. +* +* Returns: +* A modifier constant +*/ +uint64_t igt_fb_tiling_to_mod (uint64_t tiling) +{ +switch (tiling) { +case I915_TILING_NONE : +return LOCAL_DRM_FORMAT_MOD_NONE ; +case I915_TILING_X : +return LOCAL_I915_FORMAT_MOD_X_TILED ; +case I915_TILING_Y : +return LOCAL_I915_FORMAT_MOD_Y_TILED ; +case I915_TILING_Yf: +return LOCAL_I915_FORMAT_MOD_Yf_TILED; +default : +igt_assert (0 ); + } +} + +/* helpers to create nice-looking framebuffers */ static int create_bo_for_fb(int fd, int width, int height, uint32_t format, uint64_t tiling, unsigned size, unsigned stride,
lib/igt_fb.h +1 -0
@@ -131,6 +131,7 @@ int igt_create_bo_with_dimensions(int fd, int width, int height, uint32_t format bool *is_dumb);uint64_t igt_fb_mod_to_tiling (uint64_t modifier); +uint64_t igt_fb_tiling_to_mod (uint64_t tiling);/* cairo-based painting */ cairo_t *igt_get_cairo_ctx (int fd,struct igt_fb *fb);
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/5 lib/igt_draw: Add Y-tiling support
In reply to Praveen PaneriThis patch adds Y-tiling support for igt_draw_rect function.
v2:
Use helper function to get tile sizes (Ville)
--- lib/igt_draw.c | 132 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 45 deletions(-)
lib/igt_draw.c +87 -45
@@ -136,32 +136,47 @@ 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) { -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_width, tile_height, 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 ; +igt_get_fb_tile_size (fd, (uint64_t )igt_fb_tiling_to_mod (tiling), bpp, + &tile_width, &tile_height); + 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 +184,49 @@ 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) { -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_width, tile_height, 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 ; +igt_get_fb_tile_size (fd, (uint64_t )igt_fb_tiling_to_mod (tiling), bpp, + &tile_width, &tile_height); 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; - x_tile_n = tile_n % tiles_per_line; - y_tile_n = tile_n / tiles_per_line; +if (tiling ==I915_TILING_X ) { - *x = (x_tile_n * x_tile_size + x_tile_off) / pixel_size; - *y = y_tile_n * y_tile_size + y_tile_off; + 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; + + 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 = (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 +254,16 @@ 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;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);set_pixel (ptr, pos, color, bpp); } }
@@ -259,8 +290,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 +344,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 +377,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;
@@ -361,8 +400,8 @@ 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); +tiled_pos_to_x_y_linear (fd, tiled_pos, buf->stride, swizzle, + buf->bpp, &x, &y, tiling);if (x >= rect->x && x < rect->x + rect->w && y >= rect->y && y < rect->y + rect->h) {
@@ -399,7 +438,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);
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/5 lib/igt_draw: Add Y-tiling support for IGT_DRAW_BLT method
In reply to Praveen PaneriFrom: Akash Goel <[email protected]>
--- lib/igt_draw.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
lib/igt_draw.c +41 -0
@@ -31,6 +31,7 @@#include "igt_core.h" #include "igt_fb.h" #include "ioctl_wrappers.h" +#include "i830_reg.h" /** * SECTION:igt_draw
@@ -487,6 +488,26 @@ static void draw_rect_blt(int fd, struct cmd_data *cmd_data, blt_cmd_tiling = (tiling) ?XY_COLOR_BLT_TILED :0 ; pitch = (tiling) ? buf->stride /4 : buf->stride; +if (tiling ==I915_TILING_Y ) { +/* +* To change the tile register, insert an MI_FLUSH_DW +* followed by an MI_LOAD_REGISTER_IMM +*/ +BEGIN_BATCH (4 ,0 ); +OUT_BATCH (MI_FLUSH_DW |2 ); +OUT_BATCH (0x0 ); +OUT_BATCH (0x0 ); +OUT_BATCH (0x0 ); +ADVANCE_BATCH (); + +BEGIN_BATCH (4 ,0 ); +OUT_BATCH (MI_LOAD_REGISTER_IMM ); +OUT_BATCH (0x22200 );/* BCS_SWCTRL */ +OUT_BATCH (((0x3 <<16 ) |0x3 ));/* enable the Y tiling */ +OUT_BATCH (MI_NOOP ); +ADVANCE_BATCH (); + } +BEGIN_BATCH (6 ,1 );OUT_BATCH (XY_COLOR_BLT_CMD_NOLEN |XY_COLOR_BLT_WRITE_ALPHA |XY_COLOR_BLT_WRITE_RGB | blt_cmd_tiling | blt_cmd_len);
@@ -497,6 +518,26 @@ static void draw_rect_blt(int fd, struct cmd_data *cmd_data,OUT_BATCH (color);ADVANCE_BATCH (); +if (tiling ==I915_TILING_Y ) { +/* +* To change the tile register, insert an MI_FLUSH_DW +* followed by an MI_LOAD_REGISTER_IMM +*/ +BEGIN_BATCH (4 ,0 ); +OUT_BATCH (MI_FLUSH_DW |2 ); +OUT_BATCH (0x0 ); +OUT_BATCH (0x0 ); +OUT_BATCH (0x0 ); +ADVANCE_BATCH (); + +BEGIN_BATCH (4 ,0 ); +OUT_BATCH (MI_LOAD_REGISTER_IMM ); +OUT_BATCH (0x22200 );/* BCS_SWCTRL */ +OUT_BATCH ((0x3 <<16 ));/* Reset back to X-Tiling (default) */ +OUT_BATCH (MI_NOOP ); +ADVANCE_BATCH (); + } +intel_batchbuffer_flush (batch);intel_batchbuffer_free (batch); }
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 5/5 tests/kms_draw_crc: add support for Y tiling
In reply to Praveen PaneriFrom: Paulo Zanoni <[email protected]>
This is the program that's supposed to test lib/igt_draw. We just added Y tiling support for the library, so add the tests now.
--- tests/kms_draw_crc.c | 55 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 15 deletions(-)
tests/kms_draw_crc.c +40 -15
@@ -47,6 +47,13 @@ static const uint32_t formats[N_FORMATS] = { DRM_FORMAT_XRGB2101010, }; +#define N_TILING_METHODS 3 +static const uint64_t tilings[N_TILING_METHODS ] = { +LOCAL_DRM_FORMAT_MOD_NONE , +LOCAL_I915_FORMAT_MOD_X_TILED , +LOCAL_I915_FORMAT_MOD_Y_TILED , +}; +struct base_crc {bool set;igt_crc_t crc;
@@ -151,6 +158,9 @@ static void draw_method_subtest(enum igt_draw_method method, {igt_crc_t crc; +if (tiling ==LOCAL_I915_FORMAT_MOD_Y_TILED ) +igt_require (intel_gen (intel_get_drm_devid (drm_fd)) >=9 ); +/* Use IGT_DRAW_MMAP_GTT on an untiled buffer as the parameter for * comparison. Cache the value so we don't recompute it for every single * subtest. */
@@ -208,6 +218,11 @@ static void fill_fb_subtest(void)get_fill_crc (LOCAL_I915_FORMAT_MOD_X_TILED , &crc);igt_assert_crc_equal (&crc, &base_crc); +if (intel_gen (intel_get_drm_devid (drm_fd)) >=9 ) { +get_fill_crc (LOCAL_I915_FORMAT_MOD_Y_TILED , &crc); +igt_assert_crc_equal (&crc, &base_crc); + } +igt_remove_fb (drm_fd, &fb); }
@@ -265,28 +280,38 @@ static const char *format_str(int format_index) } } +static const char *tiling_str (int tiling_index) +{ +switch (tilings[tiling_index]) { +case LOCAL_DRM_FORMAT_MOD_NONE : +return "untiled" ; +case LOCAL_I915_FORMAT_MOD_X_TILED : +return "xtiled" ; +case LOCAL_I915_FORMAT_MOD_Y_TILED : +return "ytiled" ; +default : +igt_assert (false); + } +} + igt_main {enum igt_draw_method method; -int format_index; +int format_idx, tiling_idx;igt_fixture setup_environment (); -for (format_index =0 ; format_index <N_FORMATS ; format_index++) { -for (method =0 ; method <IGT_DRAW_METHOD_COUNT ; method++) { -igt_subtest_f ("draw-method-%s-%s-untiled" , -format_str (format_index), - igt_draw_get_method_name(method)) -draw_method_subtest (method, format_index, -LOCAL_DRM_FORMAT_MOD_NONE ); -igt_subtest_f ("draw-method-%s-%s-tiled" , -format_str (format_index), - igt_draw_get_method_name(method)) -draw_method_subtest (method, format_index, -LOCAL_I915_FORMAT_MOD_X_TILED ); - } - } +for (format_idx =0 ; format_idx <N_FORMATS ; format_idx++) { +for (method =0 ; method <IGT_DRAW_METHOD_COUNT ; method++) { +for (tiling_idx =0 ; tiling_idx <N_TILING_METHODS ; tiling_idx++) { +igt_subtest_f ("draw-method-%s-%s-%s" , +format_str (format_idx), +igt_draw_get_method_name (method), + tiling_str(tiling_idx)) +draw_method_subtest (method, format_idx, + tilings[tiling_idx]); + } } } igt_subtest("fill-fb")fill_fb_subtest ();
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx