[Intel-gfx] [PATCH i-g-t 1/2] Prep work for adding NV12 testcase

2017-10-10 Thread Vidya Srinivas
From: chandra konduru 

This patch adds necessary prep work for nv12 testcase:
- updated fb allocation functions to handle NV12 format
- igt helper function to return png image size
- igt helper function to calculate start of uv in a given NV12 buffer
- igt helper function to map buffer for host access
- igt helper function to return plane id based on plane type and num
- populates fb->...[4] parameters for NV12
- igt helper function to convert RGB data to NV12
- updated drm_format to bpp to handle NV12
- updated fast copy blit function to deal NV12 subplanes
- made an update to few tests due to above changes

v1: Reference https://patchwork.freedesktop.org/patch/57590/
initially floated by Chandra Konduru
on Aug 20 2015 based on the IGT
framework available at that time.

v2: Rebased as per the current IGT framework/changes (me)

v3: lib fixes for nv12 rotation
additional helper functions added to cover
multiple plane testing

Signed-off-by: Chandra Konduru 
Signed-off-by: Vidya Srinivas 
Signed-off-by: Mahesh Kumar 
---
 lib/igt_draw.c   |   2 +-
 lib/igt_fb.c | 189 ---
 lib/igt_fb.h |  14 ++-
 lib/igt_kms.c|  50 ++-
 lib/igt_kms.h|   2 +
 lib/intel_batchbuffer.c  |  14 +--
 lib/intel_batchbuffer.h  |   3 +-
 lib/intel_reg.h  |   1 +
 lib/ioctl_wrappers.c |   9 ++
 lib/ioctl_wrappers.h |   1 +
 tests/kms_draw_crc.c |   2 +-
 tests/kms_frontbuffer_tracking.c |   6 +-
 tests/kms_render.c   |   4 +-
 tests/kms_rotation_crc.c |   8 +-
 tests/prime_vgem.c   |   2 +-
 15 files changed, 254 insertions(+), 53 deletions(-)

diff --git a/lib/igt_draw.c b/lib/igt_draw.c
index 76ffb6c..8a7dbea 100644
--- a/lib/igt_draw.c
+++ b/lib/igt_draw.c
@@ -723,7 +723,7 @@ void igt_draw_rect_fb(int fd, drm_intel_bufmgr *bufmgr,
 {
igt_draw_rect(fd, bufmgr, context, fb->gem_handle, fb->size, fb->stride,
  method, rect_x, rect_y, rect_w, rect_h, color,
- igt_drm_format_to_bpp(fb->drm_format));
+ igt_drm_format_to_bpp(fb->drm_format, 0));
 }
 
 /**
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index d4eaed7..71317fd 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -141,6 +141,31 @@ void igt_get_fb_tile_size(int fd, uint64_t tiling, int 
fb_bpp,
}
 }
 
+void igt_fb_calc_uv(struct igt_fb *fb)
+{
+   if (fb->drm_format != DRM_FORMAT_NV12)
+   return;
+
+   switch (fb->tiling) {
+   case LOCAL_DRM_FORMAT_MOD_NONE:
+   fb->uv_y_start = fb->height;
+   break;
+   case LOCAL_I915_FORMAT_MOD_X_TILED:
+   fb->uv_y_start = fb->height;
+   break;
+   case LOCAL_I915_FORMAT_MOD_Y_TILED:
+   case LOCAL_I915_FORMAT_MOD_Yf_TILED:
+   if (fb->height % 64)
+   fb->uv_y_start = (fb->height + 63) & ~63;
+   else
+   fb->uv_y_start = fb->height;
+   break;
+   default:
+   igt_assert(0);
+   }
+   fb->uv_offset = fb->uv_y_start * fb->stride;
+}
+
 /**
  * igt_calc_fb_size:
  * @fd: the DRM file descriptor
@@ -154,7 +179,7 @@ void igt_get_fb_tile_size(int fd, uint64_t tiling, int 
fb_bpp,
  * This function returns valid stride and size values for a framebuffer with 
the
  * specified parameters.
  */
-void igt_calc_fb_size(int fd, int width, int height, int bpp, uint64_t tiling,
+void igt_calc_fb_size(int fd, int width, int height, int bpp, uint32_t format, 
uint64_t tiling,
  unsigned *size_ret, unsigned *stride_ret)
 {
unsigned int tile_width, tile_height, stride, size;
@@ -178,12 +203,16 @@ void igt_calc_fb_size(int fd, int width, int height, int 
bpp, uint64_t tiling,
for (stride = 512; stride < v; stride *= 2)
;
 
-   v = stride * height;
+   /* planar formats height is 1.5x */
+   v = stride * (format == DRM_FORMAT_NV12 ? (height * 3) / 2 : 
height);
for (size = 1024*1024; size < v; size *= 2)
;
} else {
stride = ALIGN(byte_width, tile_width);
-   size = stride * ALIGN(height, tile_height);
+   size = stride * (format == DRM_FORMAT_NV12 ? ALIGN((height * 3) 
/ 2, tile_height) :
+   ALIGN(height, tile_height));
+   if (format == DRM_FORMAT_NV12)
+   size = ALIGN(size, 256 * 1024);
}
 
*stride_ret = stride;
@@ -248,13 +277,13 @@ static int 

[Intel-gfx] [PATCH i-g-t 1/2] Prep work for adding NV12 testcase

2017-07-26 Thread Vidya Srinivas
From: chandra konduru 

This patch adds necessary prep work for nv12 testcase:
- updated fb allocation functions to handle NV12 format
- igt helper function to return png image size
- igt helper function to calculate start of uv in a given NV12 buffer
- igt helper function to map buffer for host access
- populates fb->...[4] parameters for NV12
- igt helper function to convert RGB data to NV12
- updated drm_format to bpp to handle NV12
- updated fast copy blit function to deal NV12 subplanes
- made an update to few tests due to above changes

v1: Reference https://patchwork.freedesktop.org/patch/57590/
Was previously posted by Chandra Konduru
on Aug 20 2015 based on the IGT
framework available at that time.

v2: Rebased as per the current IGT framework/changes (me)

Signed-off-by: Chandra Konduru 
Signed-off-by: Vidya Srinivas 
---
 lib/igt_draw.c   |   2 +-
 lib/igt_fb.c | 189 ---
 lib/igt_fb.h |  12 ++-
 lib/intel_batchbuffer.c  |  14 +--
 lib/intel_batchbuffer.h  |   3 +-
 lib/intel_reg.h  |   1 +
 lib/ioctl_wrappers.c |   9 ++
 lib/ioctl_wrappers.h |   1 +
 tests/kms_frontbuffer_tracking.c |   6 +-
 tests/kms_render.c   |   4 +-
 tests/kms_rotation_crc.c |   8 +-
 tests/prime_vgem.c   |   2 +-
 12 files changed, 202 insertions(+), 49 deletions(-)

diff --git a/lib/igt_draw.c b/lib/igt_draw.c
index db55cd9..512e964 100644
--- a/lib/igt_draw.c
+++ b/lib/igt_draw.c
@@ -652,7 +652,7 @@ void igt_draw_rect_fb(int fd, drm_intel_bufmgr *bufmgr,
 {
igt_draw_rect(fd, bufmgr, context, fb->gem_handle, fb->size, fb->stride,
  method, rect_x, rect_y, rect_w, rect_h, color,
- igt_drm_format_to_bpp(fb->drm_format));
+ igt_drm_format_to_bpp(fb->drm_format, 0));
 }
 
 /**
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 93e21c1..f313289 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -131,6 +131,33 @@ static void igt_get_fb_tile_size(int fd, uint64_t tiling, 
int fb_bpp,
}
 }
 
+void igt_fb_calc_uv(struct igt_fb *fb)
+{
+   if (fb->drm_format != DRM_FORMAT_NV12)
+   return;
+
+   switch (fb->tiling) {
+   case LOCAL_DRM_FORMAT_MOD_NONE:
+   fb->uv_y_start = fb->height;
+   break;
+   case LOCAL_I915_FORMAT_MOD_X_TILED:
+   fb->uv_y_start = fb->height;
+   break;
+   case LOCAL_I915_FORMAT_MOD_Y_TILED:
+   fb->uv_y_start = fb->height;
+   break;
+   case LOCAL_I915_FORMAT_MOD_Yf_TILED:
+   if (fb->height % 64)
+   fb->uv_y_start = (fb->height + 63) & ~63;
+   else
+   fb->uv_y_start = fb->height;
+   break;
+   default:
+   igt_assert(0);
+   }
+   fb->uv_offset = fb->uv_y_start * fb->stride;
+}
+
 /**
  * igt_calc_fb_size:
  * @fd: the DRM file descriptor
@@ -144,7 +171,7 @@ static void igt_get_fb_tile_size(int fd, uint64_t tiling, 
int fb_bpp,
  * This function returns valid stride and size values for a framebuffer with 
the
  * specified parameters.
  */
-void igt_calc_fb_size(int fd, int width, int height, int bpp, uint64_t tiling,
+void igt_calc_fb_size(int fd, int width, int height, int bpp, uint32_t format, 
uint64_t tiling,
  unsigned *size_ret, unsigned *stride_ret)
 {
unsigned int tile_width, tile_height, stride, size;
@@ -168,12 +195,13 @@ void igt_calc_fb_size(int fd, int width, int height, int 
bpp, uint64_t tiling,
for (stride = 512; stride < v; stride *= 2)
;
 
-   v = stride * height;
+   /* planar formats height is 1.5x */
+   v = stride * (format == DRM_FORMAT_NV12 ? (height * 3) / 2 : 
height);
for (size = 1024*1024; size < v; size *= 2)
;
} else {
stride = ALIGN(byte_width, tile_width);
-   size = stride * ALIGN(height, tile_height);
+   size = stride * (format == DRM_FORMAT_NV12 ? (ALIGN(height, 
tile_height) * 3) / 2 : ALIGN(height, tile_height));
}
 
*stride_ret = stride;
@@ -212,13 +240,13 @@ static int create_bo_for_fb(int fd, int width, int 
height, uint32_t format,
unsigned *size_ret, unsigned *stride_ret,
bool *is_dumb)
 {
-   int bpp = igt_drm_format_to_bpp(format);
+   int bpp = igt_drm_format_to_bpp(format, 0);
int bo;
 
-   if (tiling || size || stride) {
+   if (tiling || size || stride || (format == 

[Intel-gfx] [PATCH i-g-t 1/2] Prep work for adding NV12 testcase

2015-08-19 Thread Chandra Konduru
From: chandra konduru chandra.kond...@intel.com

This patch adds necessary prep work for nv12 testcase:
  - updated fb allocation functions to handle NV12 format
  - igt helper function to return png image size
  - igt helper function to calculate start of uv in a given NV12 buffer
  - igt helper function to map buffer for host access
  - populates fb-...[4] parameters for NV12
  - igt helper function to convert RGB data to NV12
  - updated drm_format to bpp to handle NV12
  - updated fast copy blit function to deal NV12 subplanes
  - made an update to kms_render testcase due to above changes

Signed-off-by: chandra konduru chandra.kond...@intel.com
---
 lib/igt_fb.c| 316 +---
 lib/igt_fb.h|   9 +-
 lib/intel_batchbuffer.c |  16 ++-
 lib/intel_batchbuffer.h |   3 +-
 lib/intel_reg.h |   1 +
 lib/ioctl_wrappers.c|  10 +-
 lib/ioctl_wrappers.h|   2 +-
 tests/kms_render.c  |   4 +-
 8 files changed, 334 insertions(+), 27 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 134dbd2..788bb61 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -74,7 +74,7 @@ static struct format_desc_struct {
 
 
 /* helpers to create nice-looking framebuffers */
-static int create_bo_for_fb(int fd, int width, int height, int bpp,
+static int create_bo_for_fb(int fd, int width, int height, int bpp, int bpp2,
uint64_t tiling, unsigned bo_size,
uint32_t *gem_handle_ret,
unsigned *size_ret,
@@ -99,13 +99,17 @@ static int create_bo_for_fb(int fd, int width, int height, 
int bpp,
for (stride = 512; stride  v; stride *= 2)
;
 
-   v = stride * height;
+   /* planar formats height is 1.5x */
+   v = stride * (bpp2 ? (height * 3) / 2 : height);
+
for (size = 1024*1024; size  v; size *= 2)
;
} else {
/* Scan-out has a 64 byte alignment restriction */
stride = (width * (bpp / 8) + 63)  ~63;
-   size = stride * height;
+
+   /* planar formats height is 1.5x */
+   size = stride * (bpp2 ? (height * 3) / 2 : height);
}
 
if (bo_size == 0)
@@ -393,6 +397,75 @@ void igt_paint_image(cairo_t *cr, const char *filename,
 }
 
 /**
+ * igt_get_image_size:
+ * @filename: filename of the png image
+ * @width: width of the image
+ * @height: height of the image
+ *
+ * This function returns @width and @height of the png image in @filename,
+ * which is loaded from the package data directory.
+ */
+void
+igt_get_image_size(const char *filename, int *width, int *height)
+{
+   cairo_surface_t *image;
+   FILE* f;
+
+   f = igt_fopen_data(filename);
+
+   image = cairo_image_surface_create_from_png_stream(stdio_read_func, f);
+   igt_assert(cairo_surface_status(image) == CAIRO_STATUS_SUCCESS);
+
+   *width = cairo_image_surface_get_width(image);
+   *height = cairo_image_surface_get_height(image);
+
+   cairo_surface_destroy(image);
+
+   fclose(f);
+}
+
+
+/**
+ * igt_fb_calc_uv:
+ * @fb: pointer to an #igt_fb structure
+ *
+ * This function calculates UV offset in bytes and UV starting line number
+ * for requested NV12 @fb.
+ */
+void
+igt_fb_calc_uv(struct igt_fb *fb)
+{
+   if (fb-drm_format != DRM_FORMAT_NV12)
+   return;
+
+   switch (fb-tiling) {
+   case LOCAL_DRM_FORMAT_MOD_NONE:
+   fb-uv_y_start = fb-height;
+   break;
+   case LOCAL_I915_FORMAT_MOD_X_TILED:
+   fb-uv_y_start = fb-height;
+   break;
+   case LOCAL_I915_FORMAT_MOD_Y_TILED:
+   fb-uv_y_start = fb-height;
+   break;
+   case LOCAL_I915_FORMAT_MOD_Yf_TILED:
+   /* tile-Yf requires uv to start on a new tile row */
+   if (fb-height % 64)
+   fb-uv_y_start = (fb-height + 63)  ~63;
+   else
+   fb-uv_y_start = fb-height;
+   break;
+   default:
+   igt_assert(0);
+   }
+
+   fb-uv_offset = fb-uv_y_start * fb-stride;
+
+   /* assert that fb has enough lines to hold y and uv sub-planes */
+   igt_assert(fb-size / fb-stride = fb-uv_y_start + fb-height / 2);
+}
+
+/**
  * igt_create_fb_with_bo_size:
  * @fd: open i915 drm file descriptor
  * @width: width of the framebuffer in pixel
@@ -418,24 +491,32 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
   struct igt_fb *fb, unsigned bo_size)
 {
uint32_t fb_id;
-   int bpp;
+   int bpp, bpp2;
 
memset(fb, 0, sizeof(*fb));
 
-   bpp = igt_drm_format_to_bpp(format);
+   bpp = igt_drm_format_to_bpp(format, 0);
+   bpp2 = igt_drm_format_to_bpp(format, 1);
 
-   igt_debug(%s(width=%d, height=%d, format=0x%x [bpp=%d], 
tiling=0x%PRIx64,