All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Subject: [igt-dev] [PATCH i-g-t v27 13/30] lib/igt_draw: remove libdrm dependency
Date: Mon, 10 Aug 2020 11:46:53 +0200	[thread overview]
Message-ID: <20200810094710.28930-14-zbigniew.kempczynski@intel.com> (raw)
In-Reply-To: <20200810094710.28930-1-zbigniew.kempczynski@intel.com>

Change rendercopy to use intel_bb to remove libdrm dependency.

Signed-off-by: Dominik Grzegorzek <dominik.grzegorzek@intel.com>
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/igt_draw.c | 155 ++++++++++++++++++++++++-------------------------
 lib/igt_draw.h |   8 +--
 2 files changed, 79 insertions(+), 84 deletions(-)

diff --git a/lib/igt_draw.c b/lib/igt_draw.c
index f2340127..462738ef 100644
--- a/lib/igt_draw.c
+++ b/lib/igt_draw.c
@@ -27,6 +27,7 @@
 #include "igt_draw.h"
 
 #include "drmtest.h"
+#include "intel_bufops.h"
 #include "intel_batchbuffer.h"
 #include "intel_chipset.h"
 #include "igt_core.h"
@@ -61,8 +62,8 @@
 /* Some internal data structures to avoid having to pass tons of parameters
  * around everything. */
 struct cmd_data {
-	drm_intel_bufmgr *bufmgr;
-	drm_intel_context *context;
+	struct buf_ops *bops;
+	uint32_t ctx;
 };
 
 struct buf_data {
@@ -264,8 +265,7 @@ static void set_pixel(void *_ptr, int index, uint32_t color, int bpp)
 	}
 }
 
-static void switch_blt_tiling(struct intel_batchbuffer *batch, uint32_t tiling,
-			      bool on)
+static void switch_blt_tiling(struct intel_bb *ibb, uint32_t tiling, bool on)
 {
 	uint32_t bcs_swctrl;
 
@@ -273,26 +273,22 @@ static void switch_blt_tiling(struct intel_batchbuffer *batch, uint32_t tiling,
 	if (tiling != I915_TILING_Y)
 		return;
 
-	igt_require(batch->gen >= 6);
+	igt_require(ibb->gen >= 6);
 
 	bcs_swctrl = (0x3 << 16) | (on ? 0x3 : 0x0);
 
 	/* 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(bcs_swctrl);
-	OUT_BATCH(MI_NOOP);
-	ADVANCE_BATCH();
+	intel_bb_out(ibb, MI_FLUSH_DW | 2);
+	intel_bb_out(ibb, 0x0);
+	intel_bb_out(ibb, 0x0);
+	intel_bb_out(ibb, 0x0);
+
+	intel_bb_out(ibb, MI_LOAD_REGISTER_IMM);
+	intel_bb_out(ibb, 0x22200); /* BCS_SWCTRL */
+	intel_bb_out(ibb, bcs_swctrl);
+	intel_bb_out(ibb, MI_NOOP);
 }
 
 static void draw_rect_ptr_linear(void *ptr, uint32_t stride,
@@ -509,22 +505,40 @@ static void draw_rect_pwrite(int fd, struct buf_data *buf,
 	}
 }
 
+static struct intel_buf *create_buf(int fd, struct buf_ops *bops,
+				    struct buf_data *from, uint32_t tiling)
+{
+	struct intel_buf *buf = calloc(sizeof(*buf), 1);
+	uint32_t handle, name, width, height;
+
+	igt_assert(buf);
+
+	width = from->stride / (from->bpp / 8);
+	height = from->size / from->stride;
+
+	name = gem_flink(fd, from->handle);
+	handle = gem_open(fd, name);
+	intel_buf_init_using_handle(bops, handle, buf,
+				    width, height, from->bpp, 0,
+				    tiling, 0);
+
+	return buf;
+}
+
 static void draw_rect_blt(int fd, struct cmd_data *cmd_data,
 			  struct buf_data *buf, struct rect *rect,
 			  uint32_t tiling, uint32_t color)
 {
-	drm_intel_bo *dst;
-	struct intel_batchbuffer *batch;
+	struct intel_bb *ibb;
+	struct intel_buf *dst;
 	int blt_cmd_len, blt_cmd_tiling, blt_cmd_depth;
 	uint32_t devid = intel_get_drm_devid(fd);
 	int gen = intel_gen(devid);
 	int pitch;
 
-	dst = gem_handle_to_libdrm_bo(cmd_data->bufmgr, fd, "", buf->handle);
-	igt_assert(dst);
-
-	batch = intel_batchbuffer_alloc(cmd_data->bufmgr, devid);
-	igt_assert(batch);
+	dst = create_buf(fd, cmd_data->bops, buf, tiling);
+	ibb = intel_bb_create(fd, PAGE_SIZE);
+	intel_bb_add_intel_buf(ibb, dst, true);
 
 	switch (buf->bpp) {
 	case 8:
@@ -544,34 +558,32 @@ static void draw_rect_blt(int fd, struct cmd_data *cmd_data,
 	blt_cmd_tiling = (tiling) ? XY_COLOR_BLT_TILED : 0;
 	pitch = (gen >= 4 && tiling) ? buf->stride / 4 : buf->stride;
 
-	switch_blt_tiling(batch, tiling, true);
+	switch_blt_tiling(ibb, tiling, true);
 
-	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);
-	OUT_BATCH(blt_cmd_depth | (0xF0 << 16) | pitch);
-	OUT_BATCH((rect->y << 16) | rect->x);
-	OUT_BATCH(((rect->y + rect->h) << 16) | (rect->x + rect->w));
-	OUT_RELOC_FENCED(dst, 0, I915_GEM_DOMAIN_RENDER, 0);
-	OUT_BATCH(color);
-	ADVANCE_BATCH();
+	intel_bb_out(ibb, XY_COLOR_BLT_CMD_NOLEN | XY_COLOR_BLT_WRITE_ALPHA |
+		     XY_COLOR_BLT_WRITE_RGB | blt_cmd_tiling | blt_cmd_len);
+	intel_bb_out(ibb, blt_cmd_depth | (0xF0 << 16) | pitch);
+	intel_bb_out(ibb, (rect->y << 16) | rect->x);
+	intel_bb_out(ibb, ((rect->y + rect->h) << 16) | (rect->x + rect->w));
+	intel_bb_emit_reloc_fenced(ibb, dst->handle, 0, I915_GEM_DOMAIN_RENDER,
+				   0, dst->addr.offset);
+	intel_bb_out(ibb, color);
 
-	switch_blt_tiling(batch, tiling, false);
+	switch_blt_tiling(ibb, tiling, false);
 
-	intel_batchbuffer_flush(batch);
-	intel_batchbuffer_free(batch);
-	drm_intel_bo_unreference(dst);
+	intel_bb_flush_blit(ibb);
+	intel_bb_destroy(ibb);
+	intel_buf_destroy(dst);
 }
 
 static void draw_rect_render(int fd, struct cmd_data *cmd_data,
 			     struct buf_data *buf, struct rect *rect,
 			     uint32_t tiling, uint32_t color)
 {
-	drm_intel_bo *src, *dst;
+	struct intel_buf *src, *dst;
 	uint32_t devid = intel_get_drm_devid(fd);
 	igt_render_copyfunc_t rendercopy = igt_get_render_copyfunc(devid);
-	struct igt_buf src_buf = {}, dst_buf = {};
-	struct intel_batchbuffer *batch;
+	struct intel_bb *ibb;
 	struct buf_data tmp;
 	int pixel_size = buf->bpp / 8;
 
@@ -585,40 +597,24 @@ static void draw_rect_render(int fd, struct cmd_data *cmd_data,
 	draw_rect_mmap_cpu(fd, &tmp, &(struct rect){0, 0, rect->w, rect->h},
 			   I915_TILING_NONE, I915_BIT_6_SWIZZLE_NONE, color);
 
-	src = gem_handle_to_libdrm_bo(cmd_data->bufmgr, fd, "", tmp.handle);
-	igt_assert(src);
-	dst = gem_handle_to_libdrm_bo(cmd_data->bufmgr, fd, "", buf->handle);
-	igt_assert(dst);
-
-	src_buf.bo = src;
-	src_buf.surface[0].stride = tmp.stride;
-	src_buf.tiling = I915_TILING_NONE;
-	src_buf.surface[0].size = tmp.size;
-	src_buf.bpp = tmp.bpp;
-	dst_buf.bo = dst;
-	dst_buf.surface[0].stride = buf->stride;
-	dst_buf.tiling = tiling;
-	dst_buf.surface[0].size = buf->size;
-	dst_buf.bpp = buf->bpp;
-
-	batch = intel_batchbuffer_alloc(cmd_data->bufmgr, devid);
-	igt_assert(batch);
-
-	rendercopy(batch, cmd_data->context, &src_buf, 0, 0, rect->w,
-		   rect->h, &dst_buf, rect->x, rect->y);
-
-	intel_batchbuffer_free(batch);
-	drm_intel_bo_unreference(src);
-	drm_intel_bo_unreference(dst);
+	src = create_buf(fd, cmd_data->bops, &tmp, I915_TILING_NONE);
+	dst = create_buf(fd, cmd_data->bops, buf, tiling);
+	ibb = intel_bb_create(fd, PAGE_SIZE);
+
+	rendercopy(ibb, cmd_data->ctx, src, 0, 0, rect->w,
+		   rect->h, dst, rect->x, rect->y);
+
+	intel_bb_destroy(ibb);
+	intel_buf_destroy(src);
+	intel_buf_destroy(dst);
 	gem_close(fd, tmp.handle);
 }
 
 /**
  * igt_draw_rect:
  * @fd: the DRM file descriptor
- * @bufmgr: the libdrm bufmgr, only required for IGT_DRAW_BLT and
- *          IGT_DRAW_RENDER
- * @context: the context, can be NULL if you don't want to think about it
+ * @bops: buf ops, only required for IGT_DRAW_BLT and IGT_DRAW_RENDER
+ * @ctx: the context, can be 0 if you don't want to think about it
  * @buf_handle: the handle of the buffer where you're going to draw to
  * @buf_size: the size of the buffer
  * @buf_stride: the stride of the buffer
@@ -634,7 +630,7 @@ static void draw_rect_render(int fd, struct cmd_data *cmd_data,
  * This function draws a colored rectangle on the destination buffer, allowing
  * you to specify the method used to draw the rectangle.
  */
-void igt_draw_rect(int fd, drm_intel_bufmgr *bufmgr, drm_intel_context *context,
+void igt_draw_rect(int fd, struct buf_ops *bops, uint32_t ctx,
 		   uint32_t buf_handle, uint32_t buf_size, uint32_t buf_stride,
 		   uint32_t tiling, enum igt_draw_method method,
 		   int rect_x, int rect_y, int rect_w, int rect_h,
@@ -643,8 +639,8 @@ void igt_draw_rect(int fd, drm_intel_bufmgr *bufmgr, drm_intel_context *context,
 	uint32_t buf_tiling, swizzle;
 
 	struct cmd_data cmd_data = {
-		.bufmgr = bufmgr,
-		.context = context,
+		.bops = bops,
+		.ctx = ctx,
 	};
 	struct buf_data buf = {
 		.handle = buf_handle,
@@ -693,9 +689,8 @@ void igt_draw_rect(int fd, drm_intel_bufmgr *bufmgr, drm_intel_context *context,
 /**
  * igt_draw_rect_fb:
  * @fd: the DRM file descriptor
- * @bufmgr: the libdrm bufmgr, only required for IGT_DRAW_BLT and
- *          IGT_DRAW_RENDER
- * @context: the context, can be NULL if you don't want to think about it
+ * @bops: buf ops, only required for IGT_DRAW_BLT and IGT_DRAW_RENDER
+ * @ctx: context, can be 0 if you don't want to think about it
  * @fb: framebuffer
  * @method: method you're going to use to write to the buffer
  * @rect_x: horizontal position on the buffer where your rectangle starts
@@ -707,12 +702,12 @@ void igt_draw_rect(int fd, drm_intel_bufmgr *bufmgr, drm_intel_context *context,
  * This is exactly the same as igt_draw_rect, but you can pass an igt_fb instead
  * of manually providing its details. See igt_draw_rect.
  */
-void igt_draw_rect_fb(int fd, drm_intel_bufmgr *bufmgr,
-		      drm_intel_context *context, struct igt_fb *fb,
+void igt_draw_rect_fb(int fd, struct buf_ops *bops,
+		      uint32_t ctx, struct igt_fb *fb,
 		      enum igt_draw_method method, int rect_x, int rect_y,
 		      int rect_w, int rect_h, uint32_t color)
 {
-	igt_draw_rect(fd, bufmgr, context, fb->gem_handle, fb->size, fb->strides[0],
+	igt_draw_rect(fd, bops, ctx, fb->gem_handle, fb->size, fb->strides[0],
 		      igt_fb_mod_to_tiling(fb->modifier), method,
 		      rect_x, rect_y, rect_w, rect_h, color,
 		      igt_drm_format_to_bpp(fb->drm_format));
@@ -728,7 +723,7 @@ void igt_draw_rect_fb(int fd, drm_intel_bufmgr *bufmgr,
  */
 void igt_draw_fill_fb(int fd, struct igt_fb *fb, uint32_t color)
 {
-	igt_draw_rect_fb(fd, NULL, NULL, fb,
+	igt_draw_rect_fb(fd, NULL, 0, fb,
 			 gem_has_mappable_ggtt(fd) ? IGT_DRAW_MMAP_GTT :
 						     IGT_DRAW_MMAP_WC,
 			 0, 0, fb->width, fb->height, color);
diff --git a/lib/igt_draw.h b/lib/igt_draw.h
index ec146754..2d18ef6c 100644
--- a/lib/igt_draw.h
+++ b/lib/igt_draw.h
@@ -25,7 +25,7 @@
 #ifndef __IGT_DRAW_H__
 #define __IGT_DRAW_H__
 
-#include <intel_bufmgr.h>
+#include <intel_bufops.h>
 #include "igt_fb.h"
 
 /**
@@ -50,14 +50,14 @@ enum igt_draw_method {
 
 const char *igt_draw_get_method_name(enum igt_draw_method method);
 
-void igt_draw_rect(int fd, drm_intel_bufmgr *bufmgr, drm_intel_context *context,
+void igt_draw_rect(int fd, struct buf_ops *bops, uint32_t ctx,
 		   uint32_t buf_handle, uint32_t buf_size, uint32_t buf_stride,
 		   uint32_t tiling, enum igt_draw_method method,
 		   int rect_x, int rect_y, int rect_w, int rect_h,
 		   uint32_t color, int bpp);
 
-void igt_draw_rect_fb(int fd, drm_intel_bufmgr *bufmgr,
-		      drm_intel_context *context, struct igt_fb *fb,
+void igt_draw_rect_fb(int fd, struct buf_ops *bops,
+		      uint32_t ctx, struct igt_fb *fb,
 		      enum igt_draw_method method, int rect_x, int rect_y,
 		      int rect_w, int rect_h, uint32_t color);
 
-- 
2.26.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2020-08-10  9:48 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-10  9:46 [igt-dev] [PATCH i-g-t v27 00/30] Remove libdrm in rendercopy Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 01/30] lib/intel_bufops: add mapping on cpu / device Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 02/30] lib/intel_bufops: change in hw/sw tiling detection Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 03/30] lib/intel_bufops: change stride requirements for Grantsdale Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 04/30] lib/intel_bufops: add support for 64bit bpp Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 05/30] lib/intel_bufops: extract getting the stride Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 06/30] lib/intel_batchbuffer: add new functions to support rendercopy Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 07/30] lib/intel_batchbuffer: dump bb to base64 Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 08/30] lib/intel_batchbuffer: use canonical addresses for 48bit ppgtt Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 09/30] tests/api_intel_bb: test flags are cleared on bb reset Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 10/30] tests/gem_caching|partial: adopt to batch flush function cleanup Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 11/30] lib/rendercopy: remove libdrm dependency Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 12/30] tests/api_intel_bb: add render tests Zbigniew Kempczyński
2020-08-10  9:46 ` Zbigniew Kempczyński [this message]
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 14/30] lib/igt_fb: Removal of libdrm dependency Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 15/30] tests/kms_psr: remove " Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 16/30] tests/kms_fronbuffer_tracking: " Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 17/30] tests/kms_draw_crc: " Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 18/30] tests/gem_ppgtt: " Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 19/30] tests/gem_concurrent_all: " Zbigniew Kempczyński
2020-08-10  9:47 ` [igt-dev] [PATCH i-g-t v27 20/30] tests/kms_cursor_crc: " Zbigniew Kempczyński
2020-08-10  9:47 ` [igt-dev] [PATCH i-g-t v27 21/30] tests/kms_big_fb: " Zbigniew Kempczyński
2020-08-10  9:47 ` [igt-dev] [PATCH i-g-t v27 22/30] tests/gem_stress: " Zbigniew Kempczyński
2020-08-10  9:47 ` [igt-dev] [PATCH i-g-t v27 23/30] tests/gem_render_copy: " Zbigniew Kempczyński
2020-08-10  9:47 ` [igt-dev] [PATCH i-g-t v27 24/30] tests/gem_render_copy_redux: " Zbigniew Kempczyński
2020-08-10  9:47 ` [igt-dev] [PATCH i-g-t v27 25/30] tests/gem_render_linear_blits: " Zbigniew Kempczyński
2020-08-10  9:47 ` [igt-dev] [PATCH i-g-t v27 26/30] tests/gem_render_tiled_blits: " Zbigniew Kempczyński
2020-08-10  9:47 ` [igt-dev] [PATCH i-g-t v27 27/30] tests/gem_read_read_speed: " Zbigniew Kempczyński
2020-08-10  9:47 ` [igt-dev] [PATCH i-g-t v27 28/30] lib/rendercopy_bufmgr: remove rendercopy_bufmgr Zbigniew Kempczyński
2020-08-10  9:47 ` [igt-dev] [PATCH i-g-t v27 29/30] tools/intel_residency: adopt intel_residency to use bufops Zbigniew Kempczyński
2020-08-10  9:47 ` [igt-dev] [PATCH i-g-t v27 30/30] tests/perf: remove libdrm dependency for rendercopy Zbigniew Kempczyński
2020-08-10 10:17 ` [igt-dev] ✓ Fi.CI.BAT: success for Remove libdrm in rendercopy (rev26) Patchwork
2020-08-10 13:14 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200810094710.28930-14-zbigniew.kempczynski@intel.com \
    --to=zbigniew.kempczynski@intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.