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 01/30] lib/intel_bufops: add mapping on cpu / device
Date: Mon, 10 Aug 2020 11:46:41 +0200	[thread overview]
Message-ID: <20200810094710.28930-2-zbigniew.kempczynski@intel.com> (raw)
In-Reply-To: <20200810094710.28930-1-zbigniew.kempczynski@intel.com>

Simplify mapping intel_buf. To be extended with ref counting.
Add intel_buf dump function for easy dump buffer to the file.
Fixing returned type of bo size function.

Idempotency selftest is now skipped for default buf_ops creation
to avoid time consuming comparison of HW and SW tiled buffers
(this can be the problem for forked tests). Additional function
buf_ops_create_with_selftest() was added to allow perform
verification step where it is required.

Changing alignment from 4->2 (required for 16bpp render).

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

diff --git a/lib/intel_bufops.c b/lib/intel_bufops.c
index 2a48fb0c..09433bed 100644
--- a/lib/intel_bufops.c
+++ b/lib/intel_bufops.c
@@ -704,7 +704,7 @@ static void __intel_buf_init(struct buf_ops *bops,
 	igt_assert(buf);
 	igt_assert(width > 0 && height > 0);
 	igt_assert(bpp == 8 || bpp == 16 || bpp == 32);
-	igt_assert(alignment % 4 == 0);
+	igt_assert(alignment % 2 == 0);
 
 	memset(buf, 0, sizeof(*buf));
 
@@ -757,7 +757,7 @@ static void __intel_buf_init(struct buf_ops *bops,
 
 			buf->surface[0].stride = ALIGN(width * (bpp / 8), tile_width);
 		} else {
-			buf->surface[0].stride = ALIGN(width * (bpp / 8), alignment ?: 4);
+			buf->surface[0].stride = ALIGN(width * (bpp / 8), alignment ?: 2);
 		}
 
 		buf->surface[0].size = buf->surface[0].stride * height;
@@ -870,6 +870,52 @@ void intel_buf_destroy(struct intel_buf *buf)
 	free(buf);
 }
 
+void *intel_buf_cpu_map(struct intel_buf *buf, bool write)
+{
+	int i915 = buf_ops_get_fd(buf->bops);
+
+	igt_assert(buf->ptr == NULL); /* already mapped */
+
+	buf->cpu_write = write;
+	buf->ptr = gem_mmap__cpu_coherent(i915, buf->handle, 0,
+					  buf->surface[0].size,
+					  write ? PROT_WRITE : PROT_READ);
+
+	gem_set_domain(i915, buf->handle,
+		       I915_GEM_DOMAIN_CPU,
+		       write ? I915_GEM_DOMAIN_CPU : 0);
+
+	return buf->ptr;
+}
+
+void *intel_buf_device_map(struct intel_buf *buf, bool write)
+{
+	int i915 = buf_ops_get_fd(buf->bops);
+
+	igt_assert(buf->ptr == NULL); /* already mapped */
+
+	buf->ptr = gem_mmap__device_coherent(i915, buf->handle, 0,
+					     buf->surface[0].size,
+					     write ? PROT_WRITE : PROT_READ);
+
+	gem_set_domain(i915, buf->handle,
+		       I915_GEM_DOMAIN_WC,
+		       write ? I915_GEM_DOMAIN_WC : 0);
+
+	return buf->ptr;
+}
+
+void intel_buf_unmap(struct intel_buf *buf)
+{
+	igt_assert(buf->ptr);
+
+	if (buf->cpu_write)
+		gem_sw_finish(buf_ops_get_fd(buf->bops), buf->handle);
+
+	munmap(buf->ptr, buf->surface[0].size);
+	buf->ptr = NULL;
+}
+
 void intel_buf_print(const struct intel_buf *buf)
 {
 	igt_info("[name: %s]\n", buf->name);
@@ -888,6 +934,21 @@ void intel_buf_print(const struct intel_buf *buf)
 		 from_user_pointer(buf->addr.offset), buf->addr.ctx);
 }
 
+void intel_buf_dump(const struct intel_buf *buf, const char *filename)
+{
+	int i915 = buf_ops_get_fd(buf->bops);
+	uint64_t size = intel_buf_bo_size(buf);
+	FILE *out;
+	void *ptr;
+
+	ptr = gem_mmap__device_coherent(i915, buf->handle, 0, size, PROT_READ);
+	out = fopen(filename, "wb");
+	igt_assert(out);
+	fwrite(ptr, size, 1, out);
+	fclose(out);
+	munmap(ptr, size);
+}
+
 const char *intel_buf_set_name(struct intel_buf *buf, const char *name)
 {
 	return strncpy(buf->name, name, INTEL_BUF_NAME_MAXSIZE);
@@ -1066,7 +1127,7 @@ static void idempotency_selftest(struct buf_ops *bops, uint32_t tiling)
 	buf_ops_set_software_tiling(bops, tiling, false);
 }
 
-int intel_buf_bo_size(const struct intel_buf *buf)
+uint32_t intel_buf_bo_size(const struct intel_buf *buf)
 {
 	int offset = CCS_OFFSET(buf) ?: buf->surface[0].size;
 	int ccs_size =
@@ -1075,16 +1136,7 @@ int intel_buf_bo_size(const struct intel_buf *buf)
 	return offset + ccs_size;
 }
 
-/**
- * buf_ops_create
- * @fd: device filedescriptor
- *
- * Create buf_ops structure depending on fd-device capabilities.
- *
- * Returns: opaque pointer to buf_ops.
- *
- */
-struct buf_ops *buf_ops_create(int fd)
+static struct buf_ops *__buf_ops_create(int fd, bool check_idempotency)
 {
 	struct buf_ops *bops = calloc(1, sizeof(*bops));
 	uint32_t devid;
@@ -1161,12 +1213,44 @@ struct buf_ops *buf_ops_create(int fd)
 		bops->ys_to_linear = NULL;
 	}
 
-	idempotency_selftest(bops, I915_TILING_X);
-	idempotency_selftest(bops, I915_TILING_Y);
+	if (check_idempotency) {
+		idempotency_selftest(bops, I915_TILING_X);
+		idempotency_selftest(bops, I915_TILING_Y);
+	}
 
 	return bops;
 }
 
+/**
+ * buf_ops_create
+ * @fd: device filedescriptor
+ *
+ * Create buf_ops structure depending on fd-device capabilities.
+ *
+ * Returns: opaque pointer to buf_ops.
+ *
+ */
+struct buf_ops *buf_ops_create(int fd)
+{
+	return __buf_ops_create(fd, false);
+}
+
+/**
+ * buf_ops_create_with_selftest
+ * @fd: device filedescriptor
+ *
+ * Create buf_ops structure depending on fd-device capabilities.
+ * Runs with idempotency selftest to verify software tiling gives same
+ * result like hardware tiling (gens with mappable gtt).
+ *
+ * Returns: opaque pointer to buf_ops.
+ *
+ */
+struct buf_ops *buf_ops_create_with_selftest(int fd)
+{
+	return __buf_ops_create(fd, true);
+}
+
 /**
  * buf_ops_destroy
  * @bops: pointer to buf_ops
diff --git a/lib/intel_bufops.h b/lib/intel_bufops.h
index f4f3751e..75b5f5f6 100644
--- a/lib/intel_bufops.h
+++ b/lib/intel_bufops.h
@@ -16,6 +16,9 @@ struct intel_buf {
 	uint32_t bpp;
 	uint32_t compression;
 	uint32_t swizzle_mode;
+	uint32_t yuv_semiplanar_bpp;
+	bool format_is_yuv;
+	bool format_is_yuv_semiplanar;
 	struct {
 		uint32_t offset;
 		uint32_t stride;
@@ -33,6 +36,10 @@ struct intel_buf {
 		uint32_t ctx;
 	} addr;
 
+	/* CPU mapping */
+	uint32_t *ptr;
+	bool cpu_write;
+
 	/* For debugging purposes */
 	char name[INTEL_BUF_NAME_MAXSIZE + 1];
 };
@@ -80,9 +87,10 @@ intel_buf_ccs_height(int gen, const struct intel_buf *buf)
 	return DIV_ROUND_UP(intel_buf_height(buf), 512) * 32;
 }
 
-int intel_buf_bo_size(const struct intel_buf *buf);
+uint32_t intel_buf_bo_size(const struct intel_buf *buf);
 
 struct buf_ops *buf_ops_create(int fd);
+struct buf_ops *buf_ops_create_with_selftest(int fd);
 void buf_ops_destroy(struct buf_ops *bops);
 int buf_ops_get_fd(struct buf_ops *bops);
 
@@ -116,7 +124,12 @@ struct intel_buf *intel_buf_create(struct buf_ops *bops,
 				   uint32_t req_tiling, uint32_t compression);
 void intel_buf_destroy(struct intel_buf *buf);
 
+void *intel_buf_cpu_map(struct intel_buf *buf, bool write);
+void *intel_buf_device_map(struct intel_buf *buf, bool write);
+void intel_buf_unmap(struct intel_buf *buf);
+
 void intel_buf_print(const struct intel_buf *buf);
+void intel_buf_dump(const struct intel_buf *buf, const char *filename);
 const char *intel_buf_set_name(struct intel_buf *buf, const char *name);
 
 void intel_buf_write_to_png(struct intel_buf *buf, const char *filename);
-- 
2.26.0

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

  reply	other threads:[~2020-08-10  9:47 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 ` Zbigniew Kempczyński [this message]
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 ` [igt-dev] [PATCH i-g-t v27 13/30] lib/igt_draw: remove libdrm dependency Zbigniew Kempczyński
2020-08-10  9:46 ` [igt-dev] [PATCH i-g-t v27 14/30] lib/igt_fb: Removal of " 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-2-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.