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

Vidya Srinivas vidya.srinivas at intel.com
Tue Oct 10 12:15:14 UTC 2017


From: chandra konduru <chandra.konduru at 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
- 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 <chandra.konduru at intel.com>
Signed-off-by: Vidya Srinivas <vidya.srinivas at intel.com>
Signed-off-by: Mahesh Kumar <mahesh1.kumar at intel.com>
---
 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 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 == DRM_FORMAT_NV12)) {
 		unsigned calculated_size, calculated_stride;
 
-		igt_calc_fb_size(fd, width, height, bpp, tiling,
+		igt_calc_fb_size(fd, width, height, bpp, format, tiling,
 				 &calculated_size, &calculated_stride);
 		if (stride == 0)
 			stride = calculated_stride;
@@ -595,6 +624,22 @@ cairo_surface_t *igt_cairo_image_surface_create_from_png(const char *filename)
 	return image;
 }
 
+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_paint_image:
  * @cr: cairo drawing context
@@ -676,38 +721,111 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 	igt_debug("%s(handle=%d, pitch=%d)\n",
 		  __func__, fb->gem_handle, fb->stride);
 
-	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
-	    tiling != LOCAL_I915_FORMAT_MOD_X_TILED) {
-		do_or_die(__kms_addfb(fd, fb->gem_handle, width, height,
-				      fb->stride, format, tiling,
-				      LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id));
-	} else {
-		uint32_t handles[4];
-		uint32_t pitches[4];
-		uint32_t offsets[4];
-
-		memset(handles, 0, sizeof(handles));
-		memset(pitches, 0, sizeof(pitches));
-		memset(offsets, 0, sizeof(offsets));
-
-		handles[0] = fb->gem_handle;
-		pitches[0] = fb->stride;
-
-		do_or_die(drmModeAddFB2(fd, width, height, format,
-					handles, pitches, offsets,
-					&fb_id, 0));
-	}
-
 	fb->width = width;
 	fb->height = height;
 	fb->tiling = tiling;
 	fb->drm_format = format;
-	fb->fb_id = fb_id;
 	fb->fd = fd;
 
+	igt_fb_calc_uv(fb);
+
+	do_or_die(__kms_addfb(fd, fb->gem_handle, width, height,
+				      fb->stride, format, tiling, fb->uv_offset,
+				      LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id));
+
+	fb->fb_id = fb_id;
+
 	return fb_id;
 }
 
+void igt_fb_gem_mmap(int fd, struct igt_fb *fb)
+{
+	if (!fb->mmap_gtt)
+		fb->mmap_gtt = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
+		PROT_READ | PROT_WRITE);
+	igt_assert(fb->mmap_gtt);
+}
+
+void igt_fb_csc_xrgb_to_nv12(int fd, struct igt_fb *dst_fb, struct igt_fb *src_fb)
+{
+	unsigned char *nv12;
+	unsigned char *xrgb;
+	unsigned char y, v, u;
+	float yf, vf, uf;
+	unsigned char r, g, b;
+	int i, j, xrgb_pos, y_pos, uv_pos, uv_base;
+	unsigned int obj_tiling;
+	struct igt_fb *temp_src_fb, *temp_dst_fb;
+	struct igt_fb fb1, fb2;
+
+	if (src_fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
+		src_fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED) {
+		temp_src_fb = &fb1;
+		temp_dst_fb = &fb2;
+		igt_create_fb(fd, src_fb->width, src_fb->height,
+						src_fb->drm_format, LOCAL_DRM_FORMAT_MOD_NONE, temp_src_fb);
+		igt_create_fb(fd, dst_fb->width, dst_fb->height,
+						dst_fb->drm_format, LOCAL_DRM_FORMAT_MOD_NONE, temp_dst_fb);
+		if (src_fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED)
+			obj_tiling = I915_TILING_Y;
+		else
+			obj_tiling = I915_TILING_Yf;
+
+		igt_blitter_fast_copy__raw(fd, src_fb->gem_handle, src_fb->stride, obj_tiling,
+					0, 0, temp_src_fb->width, temp_src_fb->height, igt_drm_format_to_bpp(temp_src_fb->drm_format, 0),
+					temp_src_fb->gem_handle, temp_src_fb->stride, I915_TILING_NONE, 0, 0);
+	}
+	else {
+		temp_src_fb = src_fb;
+		temp_dst_fb = dst_fb;
+	}
+
+	igt_fb_gem_mmap(fd, temp_src_fb);
+	igt_fb_gem_mmap(fd, temp_dst_fb);
+
+	xrgb = (unsigned char *) temp_src_fb->mmap_gtt;
+	nv12 = (unsigned char *) temp_dst_fb->mmap_gtt;
+	uv_base = temp_dst_fb->stride * temp_dst_fb->height;
+
+	for (i = 0; i < temp_src_fb->height; i++) {
+		xrgb_pos = i * temp_src_fb->stride;
+		y_pos = i * temp_dst_fb->stride;
+		uv_pos = temp_dst_fb->stride * i / 2;
+		for (j = 0; j < temp_src_fb->width; j++) {
+			b = xrgb[xrgb_pos++];
+			g = xrgb[xrgb_pos++];
+			r = xrgb[xrgb_pos++];
+			xrgb_pos++;
+			yf =  (0.257 * r) + (0.504 * g) + (0.098 * b) + 16;
+			uf = -(0.148 * r) - (0.291 * g) + (0.439 * b) + 128;
+			vf =  (0.439 * r) - (0.368 * g) - (0.071 * b) + 128;
+			y = (unsigned char) yf;
+			u = (unsigned char) uf;
+			v = (unsigned char) vf;
+			nv12[y_pos++] = y;
+			if (!(j % 2) && !(i % 2)) {
+				nv12[uv_base + uv_pos++] = u;
+				nv12[uv_base + uv_pos++] = v;
+			}
+		}
+	}
+
+	if (dst_fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
+		dst_fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED) {
+		igt_blitter_fast_copy__raw(fd, temp_dst_fb->gem_handle, temp_dst_fb->stride,
+				I915_TILING_NONE, 0, 0, dst_fb->width, dst_fb->height,
+				igt_drm_format_to_bpp(dst_fb->drm_format, 0), dst_fb->gem_handle,
+				dst_fb->stride, obj_tiling, 0, 0);
+		igt_blitter_fast_copy__raw(fd, temp_dst_fb->gem_handle, temp_dst_fb->stride,
+				I915_TILING_NONE, 0, temp_dst_fb->uv_y_start, dst_fb->width, dst_fb->height,
+				igt_drm_format_to_bpp(dst_fb->drm_format, 1), dst_fb->gem_handle,
+				dst_fb->stride, obj_tiling, 0, dst_fb->uv_y_start);
+
+		igt_remove_fb(fd, temp_src_fb);
+		igt_remove_fb(fd, temp_dst_fb);
+	}
+}
+
 /**
  * igt_create_fb:
  * @fd: open i915 drm file descriptor
@@ -1043,6 +1161,7 @@ static void destroy_cairo_surface__blit(void *arg)
 				   I915_TILING_NONE,
 				   0, 0, /* src_x, src_y */
 				   fb->width, fb->height,
+				   0,
 				   fb->gem_handle,
 				   fb->stride,
 				   obj_tiling,
@@ -1090,6 +1209,7 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 				   obj_tiling,
 				   0, 0, /* src_x, src_y */
 				   fb->width, fb->height,
+				   igt_drm_format_to_bpp(fb->drm_format, 0),
 				   blit->linear.handle,
 				   blit->linear.stride,
 				   I915_TILING_NONE,
@@ -1272,10 +1392,19 @@ uint32_t igt_bpp_depth_to_drm_format(int bpp, int depth)
  * The bits per pixel for the given drm fourcc pixel format code. Fails hard if
  * no match was found.
  */
-uint32_t igt_drm_format_to_bpp(uint32_t drm_format)
+uint32_t igt_drm_format_to_bpp(uint32_t drm_format, int plane)
 {
 	struct format_desc_struct *f;
 
+	if (drm_format == DRM_FORMAT_NV12 && plane == 0)
+		return 8;
+
+	else if(drm_format == DRM_FORMAT_NV12 && plane == 1)
+		return 16;
+
+	if (plane)
+		return 0;
+
 	for_each_format(f)
 		if (f->drm_id == drm_format)
 			return f->bpp;
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 3f54903..998f4b0 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -72,6 +72,9 @@ typedef struct igt_fb {
 	uint64_t tiling;
 	unsigned int size;
 	cairo_surface_t *cairo_surface;
+	void *mmap_gtt;
+	uint32_t uv_y_start;
+	uint32_t uv_offset;
 	unsigned int domain;
 } igt_fb_t;
 
@@ -95,10 +98,13 @@ enum igt_text_align {
 	align_hcenter	= 0x08,
 };
 
+void igt_fb_gem_mmap(int fd, struct igt_fb *fb);
+void igt_fb_csc_xrgb_to_nv12(int fd, struct igt_fb *dst, struct igt_fb *src);
+void igt_fb_calc_uv(struct igt_fb *fb);
+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);
 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
 igt_create_fb_with_bo_size(int fd, int width, int height,
 			   uint32_t format, uint64_t tiling,
@@ -156,9 +162,11 @@ int igt_cairo_printf_line(cairo_t *cr, enum igt_text_align align,
 
 /* helpers to handle drm fourcc codes */
 uint32_t igt_bpp_depth_to_drm_format(int bpp, int depth);
-uint32_t igt_drm_format_to_bpp(uint32_t drm_format);
+uint32_t igt_drm_format_to_bpp(uint32_t drm_format, int plane);
 const char *igt_format_str(uint32_t drm_format);
 void igt_get_all_cairo_formats(const uint32_t **formats, int *format_count);
 
+void igt_get_image_size(const char *filename, int *width, int *height);
+
 #endif /* __IGT_FB_H__ */
 
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 379bd0c..82f583a 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -2015,6 +2015,49 @@ static igt_plane_t *igt_pipe_get_plane(igt_pipe_t *pipe, int plane_idx)
 	return &pipe->planes[plane_idx];
 }
 
+static igt_plane_t *__igt_pipe_get_plane_type_with_id(igt_pipe_t *pipe, int plane_type, int id)
+{
+	int i, plane_idx = -1;
+	int p_id = 0;
+
+	switch(plane_type) {
+	case DRM_PLANE_TYPE_CURSOR:
+		plane_idx = pipe->plane_cursor;
+		break;
+	case DRM_PLANE_TYPE_PRIMARY:
+		plane_idx = pipe->plane_primary;
+		break;
+	case DRM_PLANE_TYPE_OVERLAY:
+		for(i = 0; i < pipe->n_planes; i++) {
+			if (pipe->planes[i].type == DRM_PLANE_TYPE_OVERLAY) {
+				if (p_id == id) {
+			    	plane_idx = i;
+					break;
+				}
+				p_id++;
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	igt_assert_f(plane_idx >= 0 && plane_idx < pipe->n_planes,
+		"Valid pipe->planes idx not found. plane_idx=%d plane_type=%d n_planes=%d\n",
+		plane_idx, plane_type, pipe->n_planes);
+
+	return &pipe->planes[plane_idx];
+}
+
+igt_plane_t *igt_output_get_plane_type_with_id(igt_output_t *output, int plane_type, int id)
+{
+	igt_pipe_t *pipe;
+
+	pipe = igt_output_get_driving_pipe(output);
+	igt_assert(pipe);
+
+	return __igt_pipe_get_plane_type_with_id(pipe, plane_type, id);
+}
 
 igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t *pipe, int plane_type)
 {
@@ -2028,9 +2071,12 @@ igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t *pipe, int plane_type)
 		plane_idx = pipe->plane_primary;
 		break;
 	case DRM_PLANE_TYPE_OVERLAY:
-		for(i = 0; i < pipe->n_planes; i++)
-			if (pipe->planes[i].type == DRM_PLANE_TYPE_OVERLAY)
+		for(i = 0; i < pipe->n_planes; i++) {
+			if (pipe->planes[i].type == DRM_PLANE_TYPE_OVERLAY) {
 			    plane_idx = i;
+				break;
+			}
+		}
 		break;
 	default:
 		break;
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 8dc118c..72343ca 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -395,6 +395,8 @@ void igt_output_set_pipe(igt_output_t *output, enum pipe pipe);
 void igt_output_set_scaling_mode(igt_output_t *output, uint64_t scaling_mode);
 igt_plane_t *igt_output_get_plane(igt_output_t *output, int plane_idx);
 igt_plane_t *igt_output_get_plane_type(igt_output_t *output, int plane_type);
+igt_plane_t *igt_output_get_plane_type_with_id(igt_output_t *output,
+	int plane_type, int id);
 igt_output_t *igt_output_from_connector(igt_display_t *display,
     drmModeConnector *connector);
 igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t *pipe, int plane_type);
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index 5344989..1e11e90 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -519,7 +519,7 @@ static uint32_t fast_copy_dword0(unsigned int src_tiling,
 }
 
 static uint32_t fast_copy_dword1(unsigned int src_tiling,
-				 unsigned int dst_tiling)
+				 unsigned int dst_tiling, uint32_t color_depth)
 {
 	uint32_t dword1 = 0;
 
@@ -528,7 +528,10 @@ static uint32_t fast_copy_dword1(unsigned int src_tiling,
 	if (dst_tiling == I915_TILING_Yf)
 		dword1 |= XY_FAST_COPY_DST_TILING_Yf;
 
-	dword1 |= XY_FAST_COPY_COLOR_DEPTH_32;
+	if (color_depth == 8)
+		dword1 |= XY_FAST_COPY_COLOR_DEPTH_8;
+	else
+		dword1 |= XY_FAST_COPY_COLOR_DEPTH_32;
 
 	return dword1;
 }
@@ -603,6 +606,7 @@ void igt_blitter_fast_copy__raw(int fd,
 
 				/* size */
 				unsigned int width, unsigned int height,
+				uint32_t color_depth,
 
 				/* dst */
 				uint32_t dst_handle,
@@ -621,7 +625,7 @@ void igt_blitter_fast_copy__raw(int fd,
 	src_pitch = fast_copy_pitch(src_stride, src_tiling);
 	dst_pitch = fast_copy_pitch(dst_stride, dst_tiling);
 	dword0 = fast_copy_dword0(src_tiling, dst_tiling);
-	dword1 = fast_copy_dword1(src_tiling, dst_tiling);
+	dword1 = fast_copy_dword1(src_tiling, dst_tiling, color_depth);
 
 #define CHECK_RANGE(x)	((x) >= 0 && (x) < (1 << 15))
 	assert(CHECK_RANGE(src_x) && CHECK_RANGE(src_y) &&
@@ -681,7 +685,7 @@ void igt_blitter_fast_copy__raw(int fd,
  */
 void igt_blitter_fast_copy(struct intel_batchbuffer *batch,
 			   struct igt_buf *src, unsigned src_x, unsigned src_y,
-			   unsigned width, unsigned height,
+			   unsigned width, unsigned height, uint32_t color_depth,
 			   struct igt_buf *dst, unsigned dst_x, unsigned dst_y)
 {
 	uint32_t src_pitch, dst_pitch;
@@ -690,7 +694,7 @@ void igt_blitter_fast_copy(struct intel_batchbuffer *batch,
 	src_pitch = fast_copy_pitch(src->stride, src->tiling);
 	dst_pitch = fast_copy_pitch(dst->stride, src->tiling);
 	dword0 = fast_copy_dword0(src->tiling, dst->tiling);
-	dword1 = fast_copy_dword1(src->tiling, dst->tiling);
+	dword1 = fast_copy_dword1(src->tiling, dst->tiling, color_depth);
 
 #define CHECK_RANGE(x)	((x) >= 0 && (x) < (1 << 15))
 	assert(CHECK_RANGE(src_x) && CHECK_RANGE(src_y) &&
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index 869747d..4bdac0e 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -227,7 +227,7 @@ unsigned igt_buf_height(struct igt_buf *buf);
 
 void igt_blitter_fast_copy(struct intel_batchbuffer *batch,
 			  struct igt_buf *src, unsigned src_x, unsigned src_y,
-			  unsigned width, unsigned height,
+			  unsigned width, unsigned height, uint32_t color_depth,
 			  struct igt_buf *dst, unsigned dst_x, unsigned dst_y);
 
 void igt_blitter_fast_copy__raw(int fd,
@@ -239,6 +239,7 @@ void igt_blitter_fast_copy__raw(int fd,
 
 				/* size */
 				unsigned int width, unsigned int height,
+				uint32_t color_depth,
 
 				/* dst */
 				uint32_t dst_handle,
diff --git a/lib/intel_reg.h b/lib/intel_reg.h
index 3a28c08..c4c6775 100644
--- a/lib/intel_reg.h
+++ b/lib/intel_reg.h
@@ -2530,6 +2530,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 /* dword 1 */
 #define   XY_FAST_COPY_SRC_TILING_Yf			(1 <<  31)
 #define   XY_FAST_COPY_DST_TILING_Yf			(1 <<  30)
+#define   XY_FAST_COPY_COLOR_DEPTH_8            (0  << 24)
 #define   XY_FAST_COPY_COLOR_DEPTH_32			(3  << 24)
 
 #define MI_STORE_DWORD_IMM		((0x20<<23)|2)
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 87511fc..77017bc 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -53,6 +53,7 @@
 #include "intel_io.h"
 #include "igt_debugfs.h"
 #include "config.h"
+#include "igt_fb.h"
 
 #ifdef HAVE_VALGRIND
 #include <valgrind/valgrind.h>
@@ -1829,6 +1830,7 @@ void igt_require_fb_modifiers(int fd)
 
 int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 		uint32_t stride, uint32_t pixel_format, uint64_t modifier,
+		uint32_t uv_offset,
 		uint32_t flags, uint32_t *buf_id)
 {
 	struct local_drm_mode_fb_cmd2 f;
@@ -1846,6 +1848,13 @@ int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 	f.pitches[0] = stride;
 	f.modifier[0] = modifier;
 
+	if (pixel_format == DRM_FORMAT_NV12) {
+		f.handles[1] = handle;
+		f.pitches[1] = stride;
+		f.offsets[1] = uv_offset;
+		f.modifier[1] = modifier;
+	}
+
 	ret = igt_ioctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f);
 
 	*buf_id = f.fb_id;
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index 1663b7f..fdbc146 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -254,6 +254,7 @@ void igt_require_fb_modifiers(int fd);
  */
 int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 		uint32_t stride, uint32_t pixel_format, uint64_t modifier,
+		uint32_t uv_offset,
 		uint32_t flags, uint32_t *buf_id);
 
 /**
diff --git a/tests/kms_draw_crc.c b/tests/kms_draw_crc.c
index 723e7a1..1490f0b 100644
--- a/tests/kms_draw_crc.c
+++ b/tests/kms_draw_crc.c
@@ -163,7 +163,7 @@ static bool format_is_supported(uint32_t format, uint64_t modifier)
 						   format, modifier,
 						   0, NULL, &stride, NULL);
 	ret =  __kms_addfb(drm_fd, gem_handle, 64, 64,
-			   stride, format, modifier,
+			   stride, format, modifier, 0,
 			   LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id);
 	drmModeRmFB(drm_fd, fb_id);
 	gem_close(drm_fd, gem_handle);
diff --git a/tests/kms_frontbuffer_tracking.c b/tests/kms_frontbuffer_tracking.c
index a068c8a..3961e5e 100644
--- a/tests/kms_frontbuffer_tracking.c
+++ b/tests/kms_frontbuffer_tracking.c
@@ -576,13 +576,13 @@ static void create_fb(enum pixel_format pformat, int width, int height,
 	 * the same size regardless of tiling since we want to properly exercise
 	 * the Kernel's specific tiling-checking code paths without accidentally
 	 * hitting size-checking ones first. */
-	bpp = igt_drm_format_to_bpp(format);
+	bpp = igt_drm_format_to_bpp(format, 0);
 	if (plane == PLANE_CUR)
 		tiling_for_size = LOCAL_DRM_FORMAT_MOD_NONE;
 	else
 		tiling_for_size = opt.tiling;
 
-	igt_calc_fb_size(drm.fd, width, height, bpp, tiling_for_size, &size,
+	igt_calc_fb_size(drm.fd, width, height, bpp, format, tiling_for_size, &size,
 			 &stride);
 
 	igt_create_fb_with_bo_size(drm.fd, width, height, format, tiling, fb,
@@ -1208,7 +1208,7 @@ static void start_busy_thread(struct igt_fb *fb)
 	busy_thread.width = fb->width;
 	busy_thread.height = fb->height;
 	busy_thread.color = pick_color(fb, COLOR_PRIM_BG);
-	busy_thread.bpp = igt_drm_format_to_bpp(fb->drm_format);
+	busy_thread.bpp = igt_drm_format_to_bpp(fb->drm_format, 0);
 
 	rc = pthread_create(&busy_thread.thread, NULL, busy_thread_func, NULL);
 	igt_assert_eq(rc, 0);
diff --git a/tests/kms_render.c b/tests/kms_render.c
index d2208e3..b56fff7 100644
--- a/tests/kms_render.c
+++ b/tests/kms_render.c
@@ -78,8 +78,8 @@ static void gpu_blit(struct igt_fb *dst_fb, struct igt_fb *src_fb)
 
 	igt_assert(dst_fb->drm_format == src_fb->drm_format);
 	igt_assert(src_fb->drm_format == DRM_FORMAT_RGB565 ||
-	       igt_drm_format_to_bpp(src_fb->drm_format) != 16);
-	bpp = igt_drm_format_to_bpp(src_fb->drm_format);
+	       igt_drm_format_to_bpp(src_fb->drm_format, 0) != 16);
+	bpp = igt_drm_format_to_bpp(src_fb->drm_format, 0);
 	dst_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "destination",
 					 dst_fb->gem_handle);
 	igt_assert(dst_bo);
diff --git a/tests/kms_rotation_crc.c b/tests/kms_rotation_crc.c
index 5aec8fa..f89ac3e 100644
--- a/tests/kms_rotation_crc.c
+++ b/tests/kms_rotation_crc.c
@@ -428,7 +428,7 @@ static void test_plane_rotation_ytiled_obj(data_t *data,
 	igt_display_t *display = &data->display;
 	uint64_t tiling = LOCAL_I915_FORMAT_MOD_Y_TILED;
 	uint32_t format = DRM_FORMAT_XRGB8888;
-	int bpp = igt_drm_format_to_bpp(format);
+	int bpp = igt_drm_format_to_bpp(format, 0);
 	enum igt_commit_style commit = COMMIT_LEGACY;
 	int fd = data->gfx_fd;
 	igt_plane_t *plane;
@@ -463,7 +463,7 @@ static void test_plane_rotation_ytiled_obj(data_t *data,
 	igt_assert_eq(ret, 0);
 
 	do_or_die(__kms_addfb(fd, gem_handle, w, h, stride,
-		  format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS,
+		  format, tiling, 0, LOCAL_DRM_MODE_FB_MODIFIERS,
 		  &data->fb.fb_id));
 	data->fb.width = w;
 	data->fb.height = h;
@@ -492,7 +492,7 @@ static void test_plane_rotation_exhaust_fences(data_t *data,
 	igt_display_t *display = &data->display;
 	uint64_t tiling = LOCAL_I915_FORMAT_MOD_Y_TILED;
 	uint32_t format = DRM_FORMAT_XRGB8888;
-	int bpp = igt_drm_format_to_bpp(format);
+	int bpp = igt_drm_format_to_bpp(format, 0);
 	enum igt_commit_style commit = COMMIT_LEGACY;
 	int fd = data->gfx_fd;
 	igt_plane_t *plane;
@@ -544,7 +544,7 @@ static void test_plane_rotation_exhaust_fences(data_t *data,
 		}
 
 		ret = (__kms_addfb(fd, gem_handle, w, h, stride,
-		       format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS,
+		       format, tiling, 0, LOCAL_DRM_MODE_FB_MODIFIERS,
 		       &data2[i].fb.fb_id));
 		if (ret) {
 			igt_warn("failed to create framebuffer\n");
diff --git a/tests/prime_vgem.c b/tests/prime_vgem.c
index 0ffaee9..7e86ed8 100644
--- a/tests/prime_vgem.c
+++ b/tests/prime_vgem.c
@@ -723,7 +723,7 @@ static void test_flip(int i915, int vgem, unsigned hang)
 
 		do_or_die(__kms_addfb(i915, handle[i],
 				      bo[i].width, bo[i].height, bo[i].pitch,
-				      DRM_FORMAT_XRGB8888, I915_TILING_NONE,
+				      DRM_FORMAT_XRGB8888, I915_TILING_NONE, 0,
 				      LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id[i]));
 		igt_assert(fb_id[i]);
 	}
-- 
1.9.1



More information about the Intel-gfx mailing list