Skip to contentSkip to conversation

Remove libdrm in rendercopy

PATCH Superseded Zbigniew Kempczyński 2 participants 18 messages Jul 30, 2020

Subsystems (2)

v17 of 34 Superseded Latest is v34 →

lore
Share & tools
lore
#0 lore raw

v17 cover Remove libdrm in rendercopy

Try to check how much will be broken when we migrate to no-libdrm rendercopy.

I still have some doubts in gem_stress, gem_concurrent_blit so depending on the result we'll decide to spread the change to smaller series (with introducing _v2 suffix) or will we be able to do that in single step.

v2: fix invalid offset in bind (gen4)
fix bufops selftest is not executed from default
v3: fix address to be in canonical form
v4: limit 48/47 bit gtt to 46 to avoid using bo with addresses
with 47-bit set
change set-domain to intel_bb_sync in perf.c
v5: dump surface in zlib/base64
v6: back to 1024 px in render test (got hang in gen4 after
change to 512 px)
v7: add dumping bb to base64
add set_domain(wc)
add render-.*-reloc tests
v8: change alignment constraints for tiled buffers on gen4
v9: problem is for gen3 (Grantsdale), not gen4
adding few temporary tests to check stride alignment
v10: change alignment to power of two for gen3
v11: move bb offset to end position for reuse (gen4 and gen6)
in tests which keeps buffer reference (gem_read_read_speed)
v12: add missing set_domain (gtt) in gem_render_tiled_blits
removing hax
v13: change required alignment from 4->2 for non tiled surfaces
enforce sync in tiled_blits for hope gen3 hw will succeed with flush
v14: try pread instead of gtt mapping for Grantsdale
v15: dump surfaces on gen3
v16: change bufops tiling detection logic
v17: add debug stuff for gen3 (y tiling still doesn't work)

Dominik Grzegorzek (2):
lib/igt_fb: Removal of libdrm dependency tests/gem|kms: remove libdrm dependency (batch 1)

Zbigniew Kempczyński (14):
lib/intel_bufops: add mapping on cpu / device lib/intel_bufops: change in hw/sw tiling detection lib/intel_batchbuffer: add new functions to support rendercopy lib/intel_batchbuffer: dump bb to base64 tests/gem_caching|partial: adopt to batch flush function cleanup lib/rendercopy: remove libdrm dependency tests/api_intel_bb: add render tests lib/intel_batchbuffer: use canonical addresses for 48bit ppgtt lib/igt_draw: remove libdrm dependency
tests/gem|kms: remove libdrm dependency (batch 2) tools/intel_residency: adopt intel_residency to use bufops tests/perf: remove libdrm dependency for rendercopy tests/gem_render_tiled_blits: dump gen3 surfaces
tiled_blits: debug stuff for gen3

 lib/Makefile.sources                  |    2 -
 lib/igt_draw.c                        |  154 ++--
 lib/igt_draw.h                        |    8 +-
 lib/igt_fb.c                          |   96 ++-
 lib/intel_aux_pgtable.c               |  325 ++++---
 lib/intel_aux_pgtable.h               |   29 +-
 lib/intel_batchbuffer.c               |  391 +++++++--
 lib/intel_batchbuffer.h               |   85 +-
 lib/intel_bufops.c                    |  160 +++-
 lib/intel_bufops.h                    |   15 +-
 lib/meson.build                       |    1 -
 lib/rendercopy.h                      |  102 +--
 lib/rendercopy_bufmgr.c               |  171 ----
 lib/rendercopy_bufmgr.h               |   28 -
 lib/rendercopy_gen4.c                 |  571 ++++++------
 lib/rendercopy_gen6.c                 |  593 +++++++------
 lib/rendercopy_gen7.c                 |  612 ++++++-------
 lib/rendercopy_gen8.c                 | 1030 ++++++++++------------
 lib/rendercopy_gen9.c                 | 1145 +++++++++++--------------
 lib/rendercopy_i830.c                 |  278 +++---
 lib/rendercopy_i915.c                 |  286 +++---
 lib/veboxcopy.h                       |    8 +-
 lib/veboxcopy_gen12.c                 |  117 ++-
 tests/i915/api_intel_bb.c             |  300 ++++++-
 tests/i915/gem_caching.c              |    5 -
 tests/i915/gem_concurrent_all.c       |  434 +++++-----
 tests/i915/gem_partial_pwrite_pread.c |    3 -
 tests/i915/gem_ppgtt.c                |  183 ++--
 tests/i915/gem_read_read_speed.c      |  161 ++--
 tests/i915/gem_render_copy.c          |  313 +++----
 tests/i915/gem_render_copy_redux.c    |   67 +-
 tests/i915/gem_render_linear_blits.c  |   90 +-
 tests/i915/gem_render_tiled_blits.c   |  168 +++-
 tests/i915/gem_stress.c               |  244 +++---
 tests/i915/perf.c                     |  655 ++++++--------
 tests/kms_big_fb.c                    |   54 +-
 tests/kms_cursor_crc.c                |   63 +-
 tests/kms_draw_crc.c                  |   20 +-
 tests/kms_frontbuffer_tracking.c      |   20 +-
 tests/kms_psr.c                       |  134 +--
 tools/intel_residency.c               |   10 +-
 41 files changed, 4646 insertions(+), 4485 deletions(-)
 delete mode 100644 lib/rendercopy_bufmgr.c
 delete mode 100644 lib/rendercopy_bufmgr.h
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#1 lore raw

PATCH v17 1/16 lib/intel_bufops: add mapping on cpu / device

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).

Cc Dominik Grzegorzek <[email protected]>
Cc Chris Wilson <[email protected]>
---
 lib/intel_bufops.c | 114 +++++++++++++++++++++++++++++++++++++++------
 lib/intel_bufops.h |  15 +++++-
 2 files changed, 113 insertions(+), 16 deletions(-)
lib/intel_bufops.c +99 -15
index 2a48fb0c..09433bed 100644
@@ -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
lib/intel_bufops.h +14 -1
index f4f3751e..75b5f5f6 100644
@@ -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);
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#2 lore raw

PATCH v17 2/16 lib/intel_bufops: change in hw/sw tiling detection

In reply to Zbigniew Kempczyński

Not all swizzling can be handled by the software (bit17) so detect it properly during bufops creation time and disable if necessary.

Cc Dominik Grzegorzek <[email protected]>
Cc Chris Wilson <[email protected]>
---
 lib/intel_bufops.c | 41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)
lib/intel_bufops.c +33 -8
index 09433bed..7309d308 100644
@@ -157,7 +157,7 @@ static int __gem_get_tiling(int fd, struct drm_i915_gem_get_tiling *arg)
 }
 
 static bool __get_tiling(int fd, uint32_t handle, uint32_t *tiling,
-			 uint32_t *swizzle)
+			 uint32_t *swizzle, uint32_t *phys_swizzle)
 {
 	struct drm_i915_gem_get_tiling get_tiling = { .handle = handle };
 
@@ -166,12 +166,13 @@ static bool __get_tiling(int fd, uint32_t handle, uint32_t *tiling,
 
 	*tiling = get_tiling.tiling_mode;
 	*swizzle = get_tiling.swizzle_mode;
+	*phys_swizzle = get_tiling.phys_swizzle_mode;
 	igt_debug("buf tiling: %s, swizzle: %x, phys_swizzle: %x\n",
 		  tiling_str(get_tiling.tiling_mode),
 		  get_tiling.swizzle_mode,
 		  get_tiling.phys_swizzle_mode);
 
-	return get_tiling.phys_swizzle_mode == get_tiling.swizzle_mode;
+	return true;
 }
 
 static int __set_tiling(int fd, uint32_t handle, uint32_t tiling,
@@ -1029,10 +1030,11 @@ struct buf_ops buf_ops_arr[] = {
 	},
 };
 
-static bool probe_hw_tiling(struct buf_ops *bops, uint32_t tiling)
+static bool probe_hw_tiling(struct buf_ops *bops, uint32_t tiling,
+			    bool *swizzling_supported)
 {
 	uint64_t size = 256 * 256;
-	uint32_t handle, buf_tiling, buf_swizzle;
+	uint32_t handle, buf_tiling, buf_swizzle, phys_swizzle;
 	uint32_t stride;
 	int ret;
 	bool is_set = false;
@@ -1051,12 +1053,15 @@ static bool probe_hw_tiling(struct buf_ops *bops, uint32_t tiling)
 	if (ret)
 		goto end;
 
-	is_set = __get_tiling(bops->fd, handle, &buf_tiling, &buf_swizzle);
+	is_set = __get_tiling(bops->fd, handle, &buf_tiling, &buf_swizzle,
+			      &phys_swizzle);
 	if (is_set) {
 		if (tiling == I915_TILING_X)
 			bops->swizzle_x = buf_swizzle;
 		else if (tiling == I915_TILING_Y)
 			bops->swizzle_y = buf_swizzle;
+
+		*swizzling_supported = buf_swizzle == phys_swizzle;
 	}
 end:
 	gem_close(bops->fd, handle);
@@ -1172,14 +1177,21 @@ static struct buf_ops *__buf_ops_create(int fd, bool check_idempotency)
 	 *
 	 * Ok, you have been warned.
 	 */
-	if (bops->intel_gen == 2) {
+	if (bops->intel_gen == 2 ) {
 		igt_warn("Gen2 detected. HW (de)tiling support only.");
 		return bops;
 	}
 
 	/* Let's probe X and Y hw tiling support */
 	if (is_hw_tiling_supported(bops, I915_TILING_X)) {
-		bool supported = probe_hw_tiling(bops, I915_TILING_X);
+		bool swizzling_supported;
+		bool supported = probe_hw_tiling(bops, I915_TILING_X,
+						 &swizzling_supported);
+
+		if (!swizzling_supported) {
+			igt_debug("Swizzling for X is not supported\n");
+			bops->supported_tiles &= ~TILE_X;
+		}
 
 		igt_debug("X fence support: %s\n", bool_str(supported));
 		if (!supported) {
@@ -1190,7 +1202,14 @@ static struct buf_ops *__buf_ops_create(int fd, bool check_idempotency)
 	}
 
 	if (is_hw_tiling_supported(bops, I915_TILING_Y)) {
-		bool supported = probe_hw_tiling(bops, I915_TILING_Y);
+		bool swizzling_supported;
+		bool supported = probe_hw_tiling(bops, I915_TILING_Y,
+						 &swizzling_supported);
+
+		if (!swizzling_supported) {
+			igt_debug("Swizzling for Y is not supported\n");
+			bops->supported_tiles &= ~TILE_Y;
+		}
 
 		igt_debug("Y fence support: %s\n", bool_str(supported));
 		if (!supported) {
@@ -1307,6 +1326,9 @@ bool buf_ops_set_software_tiling(struct buf_ops *bops,
 	switch (tiling) {
 	case I915_TILING_X:
 		if (use_software_tiling) {
+			bool supported = buf_ops_has_tiling_support(bops, tiling);
+			igt_assert_f(supported, "Cannot switch to X software tiling\n");
+
 			igt_debug("-> change X to SW\n");
 			bops->linear_to_x = copy_linear_to_x;
 			bops->x_to_linear = copy_x_to_linear;
@@ -1324,6 +1346,9 @@ bool buf_ops_set_software_tiling(struct buf_ops *bops,
 
 	case I915_TILING_Y:
 		if (use_software_tiling) {
+			bool supported = buf_ops_has_tiling_support(bops, tiling);
+			igt_assert_f(supported, "Cannot switch to Y software tiling\n");
+
 			igt_debug("-> change Y to SW\n");
 			bops->linear_to_y = copy_linear_to_y;
 			bops->y_to_linear = copy_y_to_linear;
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#3 lore raw

PATCH v17 3/16 lib/intel_batchbuffer: add new functions to support rendercopy

In reply to Zbigniew Kempczyński

To cover rendercopy in dependent tests we need to add the following:

1. relocation in any handle
Previously batchbuffer was the main target of relocations. As AUX table require relocations too add support for that in intel_bb.

2. set/get default alignment
Add default alignment for objects added to intel_bb (AUX tables use different alignment for different objects).

3. add intel_buf to intel_bb
Save proposed address to intel_buf

4. add set flag function

5. unification of intel_bb_flush.*() functions.

6. fixing indentation

7. change alignment constraints on gen3

Cc Dominik Grzegorzek <[email protected]>
Cc Chris Wilson <[email protected]>
---
 lib/intel_batchbuffer.c | 313 ++++++++++++++++++++++++++++++++++------
 lib/intel_batchbuffer.h |  41 +++++-
 2 files changed, 307 insertions(+), 47 deletions(-)
lib/intel_batchbuffer.c +268 -45
index 99c2e148..e3282fcf 100644
@@ -37,6 +37,7 @@
 #include "drmtest.h"
 #include "intel_batchbuffer.h"
 #include "intel_bufmgr.h"
+#include "intel_bufops.h"
 #include "intel_chipset.h"
 #include "intel_reg.h"
 #include "veboxcopy.h"
@@ -1214,6 +1215,7 @@ static inline uint64_t __intel_bb_propose_offset(struct intel_bb *ibb)
 	offset = hars_petruska_f54_1_random64(&ibb->prng);
 	offset += 256 << 10; /* Keep the low 256k clear, for negative deltas */
 	offset &= ibb->gtt_size - 1;
+	offset &= ~(ibb->alignment - 1);
 
 	return offset;
 }
@@ -1232,7 +1234,6 @@ __intel_bb_create(int i915, uint32_t size, bool do_relocs)
 {
 	struct intel_bb *ibb = calloc(1, sizeof(*ibb));
 	uint64_t gtt_size;
-	uint64_t bb_address;
 
 	igt_assert(ibb);
 
@@ -1242,6 +1243,7 @@ __intel_bb_create(int i915, uint32_t size, bool do_relocs)
 	ibb->enforce_relocs = do_relocs;
 	ibb->handle = gem_create(i915, size);
 	ibb->size = size;
+	ibb->alignment = 4096;
 	ibb->batch = calloc(1, size);
 	igt_assert(ibb->batch);
 	ibb->ptr = ibb->batch;
@@ -1253,11 +1255,12 @@ __intel_bb_create(int i915, uint32_t size, bool do_relocs)
 		gtt_size /= 2;
 	if ((gtt_size - 1) >> 32)
 		ibb->supports_48b_address = true;
+
 	ibb->gtt_size = gtt_size;
 
 	__reallocate_objects(ibb);
-	bb_address = __intel_bb_propose_offset(ibb);
-	intel_bb_add_object(ibb, ibb->handle, bb_address, false);
+	ibb->batch_offset = __intel_bb_propose_offset(ibb);
+	intel_bb_add_object(ibb, ibb->handle, ibb->batch_offset, false);
 
 	ibb->refcount = 1;
 
@@ -1364,8 +1367,6 @@ void intel_bb_destroy(struct intel_bb *ibb)
 */
 void intel_bb_reset(struct intel_bb *ibb, bool purge_objects_cache)
 {
-	uint64_t bb_address;
-
 	if (purge_objects_cache && ibb->refcount > 1)
 		igt_warn("Cannot purge objects cache on bb, refcount > 1!");
 
@@ -1383,8 +1384,8 @@ void intel_bb_reset(struct intel_bb *ibb, bool purge_objects_cache)
 	gem_close(ibb->i915, ibb->handle);
 	ibb->handle = gem_create(ibb->i915, ibb->size);
 
-	bb_address = __intel_bb_propose_offset(ibb);
-	intel_bb_add_object(ibb, ibb->handle, bb_address, false);
+	ibb->batch_offset = __intel_bb_propose_offset(ibb);
+	intel_bb_add_object(ibb, ibb->handle, ibb->batch_offset, false);
 	ibb->ptr = ibb->batch;
 	memset(ibb->batch, 0, ibb->size);
 }
@@ -1499,6 +1500,7 @@ intel_bb_add_object(struct intel_bb *ibb, uint32_t handle,
 	object = &ibb->objects[i];
 	object->handle = handle;
 	object->offset = offset;
+	object->alignment = ibb->alignment;
 
 	found = tsearch((void *) object, &ibb->root, __compare_objects);
 
@@ -1519,7 +1521,48 @@ intel_bb_add_object(struct intel_bb *ibb, uint32_t handle,
 	return object;
 }
 
-static bool intel_bb_object_set_fence(struct intel_bb *ibb, uint32_t handle)
+struct drm_i915_gem_exec_object2 *
+intel_bb_add_intel_buf(struct intel_bb *ibb, struct intel_buf *buf, bool write)
+{
+	struct drm_i915_gem_exec_object2 *obj;
+
+	obj = intel_bb_add_object(ibb, buf->handle, buf->addr.offset, write);
+
+	/* For compressed surfaces ensure address is aligned to 64KB */
+	if (ibb->gen >= 12 && buf->compression) {
+		obj->offset &= ~(0x10000 - 1);
+		obj->alignment = 0x10000;
+	}
+
+	/* For gen3 ensure tiled buffers are aligned to power of two size */
+	if (ibb->gen == 3 && buf->tiling) {
+		uint64_t alignment = 1024 * 1024;
+
+		while (alignment < buf->surface[0].size)
+			alignment <<= 1;
+		obj->offset &= ~(alignment - 1);
+		obj->alignment = alignment;
+	}
+
+	/* Update address in intel_buf buffer */
+	buf->addr.offset = obj->offset;
+
+	return obj;
+}
+
+struct drm_i915_gem_exec_object2 *
+intel_bb_find_object(struct intel_bb *ibb, uint32_t handle)
+{
+	struct drm_i915_gem_exec_object2 object = { .handle = handle };
+	struct drm_i915_gem_exec_object2 **found;
+
+	found = tfind((void *) &object, &ibb->root, __compare_objects);
+
+	return *found;
+}
+
+bool
+intel_bb_object_set_flag(struct intel_bb *ibb, uint32_t handle, uint64_t flag)
 {
 	struct drm_i915_gem_exec_object2 object = { .handle = handle };
 	struct drm_i915_gem_exec_object2 **found;
@@ -1531,7 +1574,7 @@ static bool intel_bb_object_set_fence(struct intel_bb *ibb, uint32_t handle)
 		return false;
 	}
 
-	(*found)->flags |= EXEC_OBJECT_NEEDS_FENCE;
+	(*found)->flags |= flag;
 
 	return true;
 }
@@ -1539,7 +1582,8 @@ static bool intel_bb_object_set_fence(struct intel_bb *ibb, uint32_t handle)
 /*
  * intel_bb_add_reloc:
  * @ibb: pointer to intel_bb
- * @handle: object handle which address will be taken to patch the bb
+ * @to_handle: object handle in which do relocation
+ * @handle: object handle which address will be taken to patch the @to_handle
  * @read_domains: gem domain bits for the relocation
  * @write_domain: gem domain bit for the relocation
  * @delta: delta value to add to @buffer's gpu address
@@ -1554,6 +1598,7 @@ static bool intel_bb_object_set_fence(struct intel_bb *ibb, uint32_t handle)
  * exists but doesn't mark it as a render target.
  */
 static uint64_t intel_bb_add_reloc(struct intel_bb *ibb,
+				   uint32_t to_handle,
 				   uint32_t handle,
 				   uint32_t read_domains,
 				   uint32_t write_domain,
@@ -1562,20 +1607,32 @@ static uint64_t intel_bb_add_reloc(struct intel_bb *ibb,
 				   uint64_t presumed_offset)
 {
 	struct drm_i915_gem_relocation_entry *relocs;
-	struct drm_i915_gem_exec_object2 *object;
+	struct drm_i915_gem_exec_object2 *object, *to_object;
 	uint32_t i;
 
 	object = intel_bb_add_object(ibb, handle, presumed_offset, false);
 
-	relocs = ibb->relocs;
-	if (ibb->num_relocs == ibb->allocated_relocs) {
-		ibb->allocated_relocs += 4096 / sizeof(*relocs);
-		relocs = realloc(relocs, sizeof(*relocs) * ibb->allocated_relocs);
+	/* For ibb we have relocs allocated in chunks */
+	if (to_handle == ibb->handle) {
+		relocs = ibb->relocs;
+		if (ibb->num_relocs == ibb->allocated_relocs) {
+			ibb->allocated_relocs += 4096 / sizeof(*relocs);
+			relocs = realloc(relocs, sizeof(*relocs) * ibb->allocated_relocs);
+			igt_assert(relocs);
+			ibb->relocs = relocs;
+		}
+		i = ibb->num_relocs++;
+	} else {
+		to_object = intel_bb_find_object(ibb, to_handle);
+		igt_assert_f(to_object, "object has to be added to ibb first!\n");
+
+		i = to_object->relocation_count++;
+		relocs = from_user_pointer(to_object->relocs_ptr);
+		relocs = realloc(relocs, sizeof(*relocs) * to_object->relocation_count);
+		to_object->relocs_ptr = to_user_pointer(relocs);
 		igt_assert(relocs);
-		ibb->relocs = relocs;
 	}
 
-	i = ibb->num_relocs++;
 	memset(&relocs[i], 0, sizeof(*relocs));
 	relocs[i].target_handle = handle;
 	relocs[i].read_domains = read_domains;
@@ -1587,17 +1644,42 @@ static uint64_t intel_bb_add_reloc(struct intel_bb *ibb,
 	else
 		relocs[i].presumed_offset = object->offset;
 
-	igt_debug("add reloc: handle: %u, r/w: 0x%x/0x%x, "
+	igt_debug("add reloc: to_handle: %u, handle: %u, r/w: 0x%x/0x%x, "
 		  "delta: 0x%" PRIx64 ", "
 		  "offset: 0x%" PRIx64 ", "
 		  "poffset: %p\n",
-		  handle, read_domains, write_domain,
+		  to_handle, handle, read_domains, write_domain,
 		  delta, offset,
 		  from_user_pointer(relocs[i].presumed_offset));
 
 	return object->offset;
 }
 
+static uint64_t __intel_bb_emit_reloc(struct intel_bb *ibb,
+				      uint32_t to_handle,
+				      uint32_t to_offset,
+				      uint32_t handle,
+				      uint32_t read_domains,
+				      uint32_t write_domain,
+				      uint64_t delta,
+				      uint64_t presumed_offset)
+{
+	uint64_t address;
+
+	igt_assert(ibb);
+
+	address = intel_bb_add_reloc(ibb, to_handle, handle,
+				     read_domains, write_domain,
+				     delta, to_offset,
+				     presumed_offset);
+
+	intel_bb_out(ibb, delta + address);
+	if (ibb->gen >= 8)
+		intel_bb_out(ibb, address >> 32);
+
+	return address;
+}
+
 /**
  * intel_bb_emit_reloc:
  * @ibb: pointer to intel_bb
@@ -1626,19 +1708,11 @@ uint64_t intel_bb_emit_reloc(struct intel_bb *ibb,
 			     uint64_t delta,
 			     uint64_t presumed_offset)
 {
-	uint64_t address;
-
 	igt_assert(ibb);
 
-	address = intel_bb_add_reloc(ibb, handle, read_domains, write_domain,
-				     delta, intel_bb_offset(ibb),
-				     presumed_offset);
-
-	intel_bb_out(ibb, delta + address);
-	if (ibb->gen >= 8)
-		intel_bb_out(ibb, address >> 32);
-
-	return address;
+	return __intel_bb_emit_reloc(ibb, ibb->handle, intel_bb_offset(ibb),
+				     handle, read_domains, write_domain,
+				     delta, presumed_offset);
 }
 
 uint64_t intel_bb_emit_reloc_fenced(struct intel_bb *ibb,
@@ -1653,7 +1727,7 @@ uint64_t intel_bb_emit_reloc_fenced(struct intel_bb *ibb,
 	address = intel_bb_emit_reloc(ibb, handle, read_domains, write_domain,
 				      delta, presumed_offset);
 
-	intel_bb_object_set_fence(ibb, handle);
+	intel_bb_object_set_flag(ibb, handle, EXEC_OBJECT_NEEDS_FENCE);
 
 	return address;
 }
@@ -1686,7 +1760,8 @@ uint64_t intel_bb_offset_reloc(struct intel_bb *ibb,
 {
 	igt_assert(ibb);
 
-	return intel_bb_add_reloc(ibb, handle, read_domains, write_domain,
+	return intel_bb_add_reloc(ibb, ibb->handle, handle,
+				  read_domains, write_domain,
 				  0, offset, presumed_offset);
 }
 
@@ -1700,7 +1775,24 @@ uint64_t intel_bb_offset_reloc_with_delta(struct intel_bb *ibb,
 {
 	igt_assert(ibb);
 
-	return intel_bb_add_reloc(ibb, handle, read_domains, write_domain,
+	return intel_bb_add_reloc(ibb, ibb->handle, handle,
+				  read_domains, write_domain,
+				  delta, offset, presumed_offset);
+}
+
+uint64_t intel_bb_offset_reloc_to_object(struct intel_bb *ibb,
+					 uint32_t to_handle,
+					 uint32_t handle,
+					 uint32_t read_domains,
+					 uint32_t write_domain,
+					 uint32_t delta,
+					 uint32_t offset,
+					 uint64_t presumed_offset)
+{
+	igt_assert(ibb);
+
+	return intel_bb_add_reloc(ibb, to_handle, handle,
+				  read_domains, write_domain,
 				  delta, offset, presumed_offset);
 }
 
@@ -1955,16 +2047,38 @@ uint32_t intel_bb_emit_bbe(struct intel_bb *ibb)
 }
 
 /*
- * intel_bb_flush_with_context_ring:
+ * intel_bb_emit_flush_common:
  * @ibb: batchbuffer
- * @ctx: context id
- * @ring: ring
  *
- * Submits the batch for execution on the @ring engine with the supplied
- * hardware context @ctx.
+ * Emits instructions which completes batch buffer.
+ *
+ * Returns: offset in batch buffer where there's end of instructions.
  */
-static void intel_bb_flush_with_context_ring(struct intel_bb *ibb,
-					     uint32_t ctx, uint32_t ring)
+uint32_t intel_bb_emit_flush_common(struct intel_bb *ibb)
+{
+	if (intel_bb_offset(ibb) == 0)
+		return 0;
+
+	if (ibb->gen == 5) {
+		/*
+		 * emit gen5 w/a without batch space checks - we reserve that
+		 * already.
+		 */
+		intel_bb_out(ibb, CMD_POLY_STIPPLE_OFFSET << 16);
+		intel_bb_out(ibb, 0);
+	}
+
+	/* Round batchbuffer usage to 2 DWORDs. */
+	if ((intel_bb_offset(ibb) & 4) == 0)
+		intel_bb_out(ibb, 0);
+
+	intel_bb_emit_bbe(ibb);
+
+	return intel_bb_offset(ibb);
+}
+
+static void intel_bb_exec_with_context_ring(struct intel_bb *ibb,
+					    uint32_t ctx, uint32_t ring)
 {
 	intel_bb_exec_with_context(ibb, intel_bb_offset(ibb), ctx,
 				   ring | I915_EXEC_NO_RELOC,
@@ -1972,23 +2086,109 @@ static void intel_bb_flush_with_context_ring(struct intel_bb *ibb,
 	intel_bb_reset(ibb, false);
 }
 
-void intel_bb_flush_render(struct intel_bb *ibb)
+/*
+ * intel_bb_flush:
+ * @ibb: batchbuffer
+ * @ctx: context
+ * @ring: ring
+ *
+ * If batch is not empty emit batch buffer end, execute on specified
+ * context, ring then reset the batch.
+ */
+void intel_bb_flush(struct intel_bb *ibb, uint32_t ctx, uint32_t ring)
+{
+	if (intel_bb_emit_flush_common(ibb) == 0)
+		return;
+
+	intel_bb_exec_with_context_ring(ibb, ctx, ring);
+}
+
+static void __intel_bb_flush_render_with_context(struct intel_bb *ibb,
+						 uint32_t ctx)
 {
 	uint32_t ring = I915_EXEC_RENDER;
 
-	intel_bb_flush_with_context_ring(ibb, ibb->ctx, ring);
+	if (intel_bb_emit_flush_common(ibb) == 0)
+		return;
+
+	intel_bb_exec_with_context_ring(ibb, ctx, ring);
 }
 
-void intel_bb_flush_blit(struct intel_bb *ibb)
+/*
+ * intel_bb_flush_render:
+ * @ibb: batchbuffer
+ *
+ * If batch is not empty emit batch buffer end, execute on render ring
+ * and reset the batch.
+ * Context used to execute is previous batch context.
+ */
+void intel_bb_flush_render(struct intel_bb *ibb)
+{
+	__intel_bb_flush_render_with_context(ibb, ibb->ctx);
+}
+
+/*
+ * intel_bb_flush_render_with_context:
+ * @ibb: batchbuffer
+ * @ctx: context
+ *
+ * If batch is not empty emit batch buffer end, execute on render ring with @ctx
+ * and reset the batch.
+ */
+void intel_bb_flush_render_with_context(struct intel_bb *ibb, uint32_t ctx)
+{
+	__intel_bb_flush_render_with_context(ibb, ctx);
+}
+
+static void __intel_bb_flush_blit_with_context(struct intel_bb *ibb,
+					       uint32_t ctx)
 {
 	uint32_t ring = I915_EXEC_DEFAULT;
 
+	if (intel_bb_emit_flush_common(ibb) == 0)
+		return;
+
 	if (HAS_BLT_RING(ibb->devid))
 		ring = I915_EXEC_BLT;
 
-	intel_bb_flush_with_context_ring(ibb, ibb->ctx, ring);
+	intel_bb_exec_with_context_ring(ibb, ctx, ring);
 }
 
+/*
+ * intel_bb_flush_blit:
+ * @ibb: batchbuffer
+ *
+ * If batch is not empty emit batch buffer end, execute on default/blit ring
+ * (depends on gen) and reset the batch.
+ * Context used to execute is previous batch context.
+ */
+void intel_bb_flush_blit(struct intel_bb *ibb)
+{
+	__intel_bb_flush_blit_with_context(ibb, ibb->ctx);
+}
+
+/*
+ * intel_bb_flush_blit_with_context:
+ * @ibb: batchbuffer
+ * @ctx: context
+ *
+ * If batch is not empty emit batch buffer end, execute on default/blit ring
+ * (depends on gen) with @ctx and reset the batch.
+ */
+void intel_bb_flush_blit_with_context(struct intel_bb *ibb, uint32_t ctx)
+{
+	__intel_bb_flush_blit_with_context(ibb, ctx);
+}
+
+/*
+ * intel_bb_copy_data:
+ * @ibb: batchbuffer
+ * @data: pointer of data which should be copied into batch
+ * @bytes: number of bytes to copy, must be dword multiplied
+ * @align: alignment in the batch
+ *
+ * Function copies @bytes of data pointed by @data into batch buffer.
+ */
 uint32_t intel_bb_copy_data(struct intel_bb *ibb,
 			    const void *data, unsigned int bytes,
 			    uint32_t align)
@@ -2008,6 +2208,14 @@ uint32_t intel_bb_copy_data(struct intel_bb *ibb,
 	return offset;
 }
 
+/*
+ * intel_bb_blit_start:
+ * @ibb: batchbuffer
+ * @flags: flags to blit command
+ *
+ * Function emits XY_SRC_COPY_BLT instruction with size appropriate size
+ * which depend on gen.
+ */
 void intel_bb_blit_start(struct intel_bb *ibb, uint32_t flags)
 {
 	intel_bb_out(ibb, XY_SRC_COPY_BLT_CMD |
@@ -2017,6 +2225,22 @@ void intel_bb_blit_start(struct intel_bb *ibb, uint32_t flags)
 		     (6 + 2 * (ibb->gen >= 8)));
 }
 
+/*
+ * intel_bb_emit_blt_copy:
+ * @ibb: batchbuffer
+ * @src: source buffer (intel_buf)
+ * @src_x1: source x1 position
+ * @src_y1: source y1 position
+ * @src_pitch: source pitch
+ * @dst: destination buffer (intel_buf)
+ * @dst_x1: destination x1 position
+ * @dst_y1: destination y1 position
+ * @dst_pitch: destination pitch
+ * @width: width of data to copy
+ * @height: height of data to copy
+ *
+ * Function emits complete blit command.
+ */
 void intel_bb_emit_blt_copy(struct intel_bb *ibb,
 			    struct intel_buf *src,
 			    int src_x1, int src_y1, int src_pitch,
@@ -2123,7 +2347,6 @@ void intel_bb_blt_copy(struct intel_bb *ibb,
 	intel_bb_emit_blt_copy(ibb, src, src_x1, src_y1, src_pitch,
 			       dst, dst_x1, dst_y1, dst_pitch,
 			       width, height, bpp);
-	intel_bb_emit_bbe(ibb);
 	intel_bb_flush_blit(ibb);
 }
 
lib/intel_batchbuffer.h +39 -2

79 lines not on this page · raw message

Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#4 lore raw

PATCH v17 4/16 lib/intel_batchbuffer: dump bb to base64

In reply to Zbigniew Kempczyński

Code for dumping bb to log as base64 which can be used when something wrong happened.

Cc Dominik Grzegorzek <[email protected]>
Cc Chris Wilson <[email protected]>
---
 lib/intel_batchbuffer.c | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/intel_batchbuffer.h |  2 ++
 2 files changed, 43 insertions(+)
lib/intel_batchbuffer.c +41 -0
index e3282fcf..87638bb2 100644
@@ -52,6 +52,7 @@
 #include "igt_rand.h"
 #include "i830_reg.h"
 #include "huc_copy.h"
+#include <glib.h>
 
 #include <i915_drm.h>
 
@@ -1468,6 +1469,18 @@ void intel_bb_set_debug(struct intel_bb *ibb, bool debug)
 	ibb->debug = debug;
 }
 
+/**
+ * intel_bb_set_dump_base64:
+ * @ibb: pointer to intel_bb
+ * @dump: true / false
+ *
+ * Do bb dump as base64 string before execbuf call.
+ */
+void intel_bb_set_dump_base64(struct intel_bb *ibb, bool dump)
+{
+	ibb->dump_base64 = dump;
+}
+
 static int __compare_objects(const void *p1, const void *p2)
 {
 	const struct drm_i915_gem_exec_object2 *o1 = p1, *o2 = p2;
@@ -1852,6 +1865,31 @@ static void intel_bb_dump_execbuf(struct intel_bb *ibb,
 	}
 }
 
+#define LINELEN 76
+static void intel_bb_dump_base64(struct intel_bb *ibb)
+{
+	int outsize;
+	gchar *str, *pos;
+
+	igt_info("--- bb ---\n");
+	pos = str = g_base64_encode((const guchar *) ibb->batch, ibb->size);
+	outsize = strlen(str);
+
+	while (pos) {
+		char line[LINELEN + 1];
+		int to_copy = min(LINELEN, outsize);
+
+		memcpy(line, pos, to_copy);
+		line[to_copy] = 0;
+		igt_info("%s\n", line);
+		pos += LINELEN;
+		outsize -= to_copy;
+		if (outsize == 0)
+			break;
+	}
+	free(str);
+}
+
 static void print_node(const void *node, VISIT which, int depth)
 {
 	const struct drm_i915_gem_exec_object2 *object =
@@ -1907,6 +1945,9 @@ int __intel_bb_exec(struct intel_bb *ibb, uint32_t end_offset,
 		execbuf.flags &= ~I915_EXEC_NO_RELOC;
 	execbuf.rsvd2 = 0;
 
+	if (ibb->dump_base64)
+		intel_bb_dump_base64(ibb);
+
 	ret = __gem_execbuf_wr(ibb->i915, &execbuf);
 	if (ret) {
 		intel_bb_dump_execbuf(ibb, &execbuf);
lib/intel_batchbuffer.h +2 -0
index cc8c84b6..bfb144b7 100644
@@ -433,6 +433,7 @@ struct intel_bb {
 	int i915;
 	int gen;
 	bool debug;
+	bool dump_base64;
 	bool enforce_relocs;
 	uint32_t devid;
 	uint32_t handle;
@@ -486,6 +487,7 @@ int intel_bb_sync(struct intel_bb *ibb);
 void intel_bb_print(struct intel_bb *ibb);
 void intel_bb_dump(struct intel_bb *ibb, const char *filename);
 void intel_bb_set_debug(struct intel_bb *ibb, bool debug);
+void intel_bb_set_dump_base64(struct intel_bb *ibb, bool dump);
 
 static inline uint64_t
 intel_bb_set_default_object_alignment(struct intel_bb *ibb, uint64_t alignment)
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#5 lore raw

PATCH v17 5/16 tests/gem_caching|partial: adopt to batch flush function cleanup

In reply to Zbigniew Kempczyński

intel_bb API has been cleaned so flush generates also BBE and executes the batch. Remove redundant code to use flush properly.

---
 tests/i915/gem_caching.c              | 5 -----
 tests/i915/gem_partial_pwrite_pread.c | 3 ---
 2 files changed, 8 deletions(-)
tests/i915/gem_caching.c +0 -5
index 1d8989db..23e42132 100644
@@ -99,11 +99,6 @@ copy_bo(struct intel_bb *ibb, struct intel_buf *src, struct intel_buf *dst)
 	intel_bb_emit_reloc_fenced(ibb, src->handle,
 				   I915_GEM_DOMAIN_RENDER,
 				   0, 0, 0x0);
-
-	 /* Mark the end of the buffer. */
-	intel_bb_out(ibb, MI_BATCH_BUFFER_END);
-	intel_bb_ptr_align(ibb, 8);
-
 	intel_bb_flush_blit(ibb);
 	intel_bb_sync(ibb);
 }
tests/i915/gem_partial_pwrite_pread.c +0 -3
index b4bae9b6..b1028472 100644
@@ -101,9 +101,6 @@ static void copy_bo(struct intel_buf *src, struct intel_buf *dst)
 				   I915_GEM_DOMAIN_RENDER,
 				   0, 0, 0x0);
 
-	intel_bb_out(ibb, MI_BATCH_BUFFER_END);
-	intel_bb_ptr_align(ibb, 8);
-
 	intel_bb_flush_blit(ibb);
 	intel_bb_sync(ibb);
 }
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#6 lore raw

PATCH v17 6/16 lib/rendercopy: remove libdrm dependency

In reply to Zbigniew Kempczyński

Use intel_bb as main batch implementation to remove libdrm dependency. Rewrite all pipelines to use intel_bb and update render|vebox_copy function prototypes.

Cc Dominik Grzegorzek <[email protected]>
Cc Chris Wilson <[email protected]>
---
 lib/intel_aux_pgtable.c |  325 +++++------
 lib/intel_aux_pgtable.h |   29 +-
 lib/intel_batchbuffer.h |   42 +-
 lib/rendercopy.h        |  102 ++--
 lib/rendercopy_gen4.c   |  571 ++++++++++---------
 lib/rendercopy_gen6.c   |  593 ++++++++++----------
 lib/rendercopy_gen7.c   |  612 ++++++++++-----------
 lib/rendercopy_gen8.c   | 1030 +++++++++++++++--------------------
 lib/rendercopy_gen9.c   | 1145 +++++++++++++++++----------------------
 lib/rendercopy_i830.c   |  278 +++++-----
 lib/rendercopy_i915.c   |  281 +++++-----
 lib/veboxcopy.h         |    8 +-
 lib/veboxcopy_gen12.c   |  117 ++--
 13 files changed, 2429 insertions(+), 2704 deletions(-)
lib/intel_aux_pgtable.c +144 -181
index db5055c8..b43a366b 100644
@@ -4,7 +4,7 @@
 #include "drmtest.h"
 #include "intel_aux_pgtable.h"
 #include "intel_batchbuffer.h"
-#include "intel_bufmgr.h"
+#include "intel_bufops.h"
 #include "ioctl_wrappers.h"
 
 #include "i915/gem_mman.h"
@@ -31,8 +31,6 @@
 
 #define GFX_ADDRESS_BITS	48
 
-#define max(a, b)		((a) > (b) ? (a) : (b))
-
 #define AUX_FORMAT_YCRCB	0x03
 #define AUX_FORMAT_P010		0x07
 #define AUX_FORMAT_P016		0x08
@@ -58,10 +56,12 @@ struct pgtable {
 	struct pgtable_level_info *level_info;
 	int size;
 	int max_align;
-	drm_intel_bo *bo;
+	struct intel_bb *ibb;
+	struct intel_buf *buf;
+	void *ptr;
 };
 
-static uint64_t last_buf_surface_end(const struct igt_buf *buf)
+static uint64_t last_buf_surface_end(struct intel_buf *buf)
 {
 	uint64_t end_offset = 0;
 	int num_surfaces = buf->format_is_yuv_semiplanar ? 2 : 1;
@@ -79,7 +79,7 @@ static uint64_t last_buf_surface_end(const struct igt_buf *buf)
 }
 
 static int
-pgt_table_count(int address_bits, const struct igt_buf **bufs, int buf_count)
+pgt_table_count(int address_bits, struct intel_buf **bufs, int buf_count)
 {
 	uint64_t end;
 	int count;
@@ -88,19 +88,19 @@ pgt_table_count(int address_bits, const struct igt_buf **bufs, int buf_count)
 	count = 0;
 	end = 0;
 	for (i = 0; i < buf_count; i++) {
-		const struct igt_buf *buf = bufs[i];
+		struct intel_buf *buf = bufs[i];
 		uint64_t start;
 
 		/* We require bufs to be sorted. */
 		igt_assert(i == 0 ||
-			   buf->bo->offset64 >= bufs[i - 1]->bo->offset64 +
-						bufs[i - 1]->bo->size);
+			   buf->addr.offset >= bufs[i - 1]->addr.offset +
+					       intel_buf_bo_size(bufs[i - 1]));
 
-		start = ALIGN_DOWN(buf->bo->offset64, 1UL << address_bits);
+		start = ALIGN_DOWN(buf->addr.offset, 1UL << address_bits);
 		/* Avoid double counting for overlapping aligned bufs. */
 		start = max(start, end);
 
-		end = ALIGN(buf->bo->offset64 + last_buf_surface_end(buf),
+		end = ALIGN(buf->addr.offset + last_buf_surface_end(buf),
 			    1UL << address_bits);
 		igt_assert(end >= start);
 
@@ -111,7 +111,7 @@ pgt_table_count(int address_bits, const struct igt_buf **bufs, int buf_count)
 }
 
 static void
-pgt_calc_size(struct pgtable *pgt, const struct igt_buf **bufs, int buf_count)
+pgt_calc_size(struct pgtable *pgt, struct intel_buf **bufs, int buf_count)
 {
 	int level;
 
@@ -171,28 +171,33 @@ pgt_get_child_table(struct pgtable *pgt, uint64_t parent_table,
 	uint64_t *child_entry_ptr;
 	uint64_t child_table;
 
-	parent_table_ptr = pgt->bo->virtual + parent_table;
+	parent_table_ptr = pgt->ptr + parent_table;
 	child_entry_idx = pgt_entry_index(pgt, level, address);
 	child_entry_ptr = &parent_table_ptr[child_entry_idx];
 
 	if (!*child_entry_ptr) {
 		uint64_t pte;
+		uint32_t offset;
 
 		child_table = pgt_alloc_table(pgt, level - 1);
-		igt_assert(!((child_table + pgt->bo->offset64) &
+		igt_assert(!((child_table + pgt->buf->addr.offset) &
 			     ~ptr_mask(pgt, level)));
 
 		pte = child_table | flags;
-		*child_entry_ptr = pgt->bo->offset64 + pte;
+		*child_entry_ptr = pgt->buf->addr.offset + pte;
 
 		igt_assert(pte <= INT32_MAX);
-		drm_intel_bo_emit_reloc(pgt->bo,
-					parent_table +
-						child_entry_idx * sizeof(uint64_t),
-					pgt->bo, pte, 0, 0);
+
+		offset = parent_table + child_entry_idx * sizeof(uint64_t);
+		intel_bb_offset_reloc_to_object(pgt->ibb,
+						pgt->buf->handle,
+						pgt->buf->handle,
+						0, 0,
+						pte, offset,
+						pgt->buf->addr.offset);
 	} else {
 		child_table = (*child_entry_ptr & ptr_mask(pgt, level)) -
-			      pgt->bo->offset64;
+			      pgt->buf->addr.offset;
 	}
 
 	return child_table;
@@ -205,7 +210,7 @@ pgt_set_l1_entry(struct pgtable *pgt, uint64_t l1_table,
 	uint64_t *l1_table_ptr;
 	uint64_t *l1_entry_ptr;
 
-	l1_table_ptr = pgt->bo->virtual + l1_table;
+	l1_table_ptr = pgt->ptr + l1_table;
 	l1_entry_ptr = &l1_table_ptr[pgt_entry_index(pgt, 0, address)];
 
 	igt_assert(!(ptr & ~ptr_mask(pgt, 0)));
@@ -234,7 +239,7 @@ static int bpp_to_depth_val(int bpp)
 	}
 }
 
-static uint64_t pgt_get_l1_flags(const struct igt_buf *buf, int surface_idx)
+static uint64_t pgt_get_l1_flags(const struct intel_buf *buf, int surface_idx)
 {
 	/*
 	 * The offset of .tile_mode isn't specifed by bspec, it's what Mesa
@@ -337,15 +342,15 @@ static uint64_t pgt_get_lx_flags(void)
 
 static void
 pgt_populate_entries_for_buf(struct pgtable *pgt,
-			       const struct igt_buf *buf,
-			       uint64_t top_table,
-			       int surface_idx)
+			     struct intel_buf *buf,
+			     uint64_t top_table,
+			     int surface_idx)
 {
-	uint64_t surface_addr = buf->bo->offset64 +
+	uint64_t surface_addr = buf->addr.offset +
 				buf->surface[surface_idx].offset;
 	uint64_t surface_end = surface_addr +
 			       buf->surface[surface_idx].size;
-	uint64_t aux_addr = buf->bo->offset64 + buf->ccs[surface_idx].offset;
+	uint64_t aux_addr = buf->addr.offset + buf->ccs[surface_idx].offset;
 	uint64_t l1_flags = pgt_get_l1_flags(buf, surface_idx);
 	uint64_t lx_flags = pgt_get_lx_flags();
 
@@ -367,19 +372,24 @@ pgt_populate_entries_for_buf(struct pgtable *pgt,
 	}
 }
 
+static void pgt_map(int i915, struct pgtable *pgt)
+{
+	pgt->ptr = gem_mmap__device_coherent(i915, pgt->buf->handle, 0,
+					     pgt->size, PROT_READ | PROT_WRITE);
+}
+
+static void pgt_unmap(struct pgtable *pgt)
+{
+	munmap(pgt->ptr, pgt->size);
+}
+
 static void pgt_populate_entries(struct pgtable *pgt,
-				 const struct igt_buf **bufs,
-				 int buf_count,
-				 drm_intel_bo *pgt_bo)
+				 struct intel_buf **bufs,
+				 int buf_count)
 {
 	uint64_t top_table;
 	int i;
 
-	pgt->bo = pgt_bo;
-
-	igt_assert(pgt_bo->size >= pgt->size);
-	memset(pgt_bo->virtual, 0, pgt->size);
-
 	top_table = pgt_alloc_table(pgt, pgt->levels - 1);
 	/* Top level table must be at offset 0. */
 	igt_assert(top_table == 0);
@@ -395,7 +405,7 @@ static void pgt_populate_entries(struct pgtable *pgt,
 
 static struct pgtable *
 pgt_create(const struct pgtable_level_desc *level_descs, int levels,
-	   const struct igt_buf **bufs, int buf_count)
+	   struct intel_buf **bufs, int buf_count)
 {
 	struct pgtable *pgt;
 	int level;
@@ -427,10 +437,11 @@ static void pgt_destroy(struct pgtable *pgt)
 	free(pgt);
 }
 
-drm_intel_bo *
-intel_aux_pgtable_create(drm_intel_bufmgr *bufmgr,
-		       const struct igt_buf **bufs, int buf_count)
+struct intel_buf *
+intel_aux_pgtable_create(struct intel_bb *ibb,
+			 struct intel_buf **bufs, int buf_count)
 {
+	struct drm_i915_gem_exec_object2 *obj;
 	static const struct pgtable_level_desc level_desc[] = {
 		{
 			.idx_shift = 16,
@@ -452,99 +463,43 @@ intel_aux_pgtable_create(drm_intel_bufmgr *bufmgr,
 		},
 	};
 	struct pgtable *pgt;
-	drm_intel_bo *pgt_bo;
-
-	pgt = pgt_create(level_desc, ARRAY_SIZE(level_desc), bufs, buf_count);
+	struct buf_ops *bops;
+	struct intel_buf *buf;
+	uint64_t prev_alignment;
 
-	pgt_bo = drm_intel_bo_alloc_for_render(bufmgr, "aux pgt",
-					       pgt->size, pgt->max_align);
-	igt_assert(pgt_bo);
-
-	igt_assert(drm_intel_bo_map(pgt_bo, true) == 0);
-	pgt_populate_entries(pgt, bufs, buf_count, pgt_bo);
-	igt_assert(drm_intel_bo_unmap(pgt_bo) == 0);
+	igt_assert(buf_count);
+	bops = bufs[0]->bops;
 
+	pgt = pgt_create(level_desc, ARRAY_SIZE(level_desc), bufs, buf_count);
+	pgt->ibb = ibb;
+	pgt->buf = intel_buf_create(bops, pgt->size, 1, 8, 0, I915_TILING_NONE,
+				    I915_COMPRESSION_NONE);
+
+	/* We need to use pgt->max_align for aux table */
+	prev_alignment = intel_bb_set_default_object_alignment(ibb,
+							       pgt->max_align);
+	obj = intel_bb_add_intel_buf(ibb, pgt->buf, false);
+	intel_bb_set_default_object_alignment(ibb, prev_alignment);
+	obj->alignment = pgt->max_align;
+
+	pgt_map(ibb->i915, pgt);
+	pgt_populate_entries(pgt, bufs, buf_count);
+	pgt_unmap(pgt);
+
+	buf = pgt->buf;
 	pgt_destroy(pgt);
 
-	return pgt_bo;
-}
-
-static void
-aux_pgtable_find_max_free_range(const struct igt_buf **bufs, int buf_count,
-				uint64_t *range_start, uint64_t *range_size)
-{
-	/*
-	 * Keep the first page reserved, so we can differentiate pinned
-	 * objects based on a non-NULL offset.
-	 */
-	uint64_t start = 0x1000;
-	/* For now alloc only from the first 4GB address space. */
-	const uint64_t end = 1ULL << 32;
-	uint64_t max_range_start = 0;
-	uint64_t max_range_size = 0;
-	int i;
-
-	for (i = 0; i < buf_count; i++) {
-		if (bufs[i]->bo->offset64 >= end)
-			break;
-
-		if (bufs[i]->bo->offset64 - start > max_range_size) {
-			max_range_start = start;
-			max_range_size = bufs[i]->bo->offset64 - start;
-		}
-		start = bufs[i]->bo->offset64 + bufs[i]->bo->size;
-	}
-
-	if (start < end && end - start > max_range_size) {
-		max_range_start = start;
-		max_range_size = end - start;
-	}
-
-	*range_start = max_range_start;
-	*range_size = max_range_size;
-}
-
-static uint64_t
-aux_pgtable_find_free_range(const struct igt_buf **bufs, int buf_count,
-			    uint32_t size)
-{
-	uint64_t range_start;
-	uint64_t range_size;
-	/* A compressed surface must be 64kB aligned. */
-	const uint32_t align = 0x10000;
-	int pad;
-
-	aux_pgtable_find_max_free_range(bufs, buf_count,
-					&range_start, &range_size);
-
-	pad = ALIGN(range_start, align) - range_start;
-	range_start += pad;
-	range_size -= pad;
-	igt_assert(range_size >= size);
-
-	return range_start +
-	       ALIGN_DOWN(rand() % ((range_size - size) + 1), align);
+	return buf;
 }
 
 static void
-aux_pgtable_reserve_range(const struct igt_buf **bufs, int buf_count,
-			  const struct igt_buf *new_buf)
+aux_pgtable_reserve_buf_slot(struct intel_buf **bufs, int buf_count,
+			     struct intel_buf *new_buf)
 {
 	int i;
 
-	if (igt_buf_compressed(new_buf)) {
-		uint64_t pin_offset = new_buf->bo->offset64;
-
-		if (!pin_offset)
-			pin_offset = aux_pgtable_find_free_range(bufs,
-								 buf_count,
-								 new_buf->bo->size);
-		drm_intel_bo_set_softpin_offset(new_buf->bo, pin_offset);
-		igt_assert(new_buf->bo->offset64 == pin_offset);
-	}
-
 	for (i = 0; i < buf_count; i++)
-		if (bufs[i]->bo->offset64 > new_buf->bo->offset64)
+		if (bufs[i]->addr.offset > new_buf->addr.offset)
 			break;
 
 	memmove(&bufs[i + 1], &bufs[i], sizeof(bufs[0]) * (buf_count - i));
@@ -554,107 +509,115 @@ aux_pgtable_reserve_range(const struct igt_buf **bufs, int buf_count,
 
 void
 gen12_aux_pgtable_init(struct aux_pgtable_info *info,
-		       drm_intel_bufmgr *bufmgr,
-		       const struct igt_buf *src_buf,
-		       const struct igt_buf *dst_buf)
+		       struct intel_bb *ibb,
+		       struct intel_buf *src_buf,
+		       struct intel_buf *dst_buf)
 {
-	const struct igt_buf *bufs[2];
-	const struct igt_buf *reserved_bufs[2];
+	struct intel_buf *bufs[2];
+	struct intel_buf *reserved_bufs[2];
 	int reserved_buf_count;
 	int i;
 
-	if (!igt_buf_compressed(src_buf) && !igt_buf_compressed(dst_buf))
+	igt_assert_f(ibb->enforce_relocs == false,
+		     "We support aux pgtables for non-forced relocs yet!");
+
+	if (!intel_buf_compressed(src_buf) && !intel_buf_compressed(dst_buf))
 		return;
 
 	bufs[0] = src_buf;
 	bufs[1] = dst_buf;
 
 	/*
-	 * Ideally we'd need an IGT-wide GFX address space allocator, which
-	 * would consider all allocations and thus avoid evictions. For now use
-	 * a simpler scheme here, which only considers the buffers involved in
-	 * the blit, which should at least minimize the chance for evictions
-	 * in the case of subsequent blits:
-	 *   1. If they were already bound (bo->offset64 != 0), use this
-	 *      address.
-	 *   2. Pick a range randomly from the 4GB address space, that is not
-	 *      already occupied by a bound object, or an object we pinned.
+	 * Surface index in pgt table depend on its address so:
+	 *   1. if handle was previously executed in batch use that address
+	 *   2. add object to batch, this will generate random address
+	 *
+	 * Randomizing addresses can lead to overlapping, but we don't have
+	 * global address space generator in IGT. Currently assumption is
+	 * randomizing address is spread over 48-bit address space equally
+	 * so risk with overlapping is minimal. Of course it is growing
+	 * with number of objects (+its sizes) involved in blit.
+	 * To avoid relocation EXEC_OBJECT_PINNED flag is set for compressed
+	 * surfaces.
 	 */
+
+	intel_bb_add_intel_buf(ibb, src_buf, false);
+	if (intel_buf_compressed(src_buf))
+		intel_bb_object_set_flag(ibb, src_buf->handle, EXEC_OBJECT_PINNED);
+
+	intel_bb_add_intel_buf(ibb, dst_buf, true);
+	if (intel_buf_compressed(dst_buf))
+		intel_bb_object_set_flag(ibb, dst_buf->handle, EXEC_OBJECT_PINNED);
+
 	reserved_buf_count = 0;
 	/* First reserve space for any bufs that are bound already. */
-	for (i = 0; i < ARRAY_SIZE(bufs); i++)
-		if (bufs[i]->bo->offset64)
-			aux_pgtable_reserve_range(reserved_bufs,
-						  reserved_buf_count++,
-						  bufs[i]);
-
-	/* Next, reserve space for unbound bufs with an AUX surface. */
-	for (i = 0; i < ARRAY_SIZE(bufs); i++)
-		if (!bufs[i]->bo->offset64 && igt_buf_compressed(bufs[i]))
-			aux_pgtable_reserve_range(reserved_bufs,
-						  reserved_buf_count++,
-						  bufs[i]);
+	for (i = 0; i < ARRAY_SIZE(bufs); i++) {
+		igt_assert(bufs[i]->addr.offset != INTEL_BUF_INVALID_ADDRESS);
+		aux_pgtable_reserve_buf_slot(reserved_bufs,
+					     reserved_buf_count++,
+					     bufs[i]);
+	}
 
 	/* Create AUX pgtable entries only for bufs with an AUX surface */
 	info->buf_count = 0;
 	for (i = 0; i < reserved_buf_count; i++) {
-		if (!igt_buf_compressed(reserved_bufs[i]))
+		if (!intel_buf_compressed(reserved_bufs[i]))
 			continue;
 
 		info->bufs[info->buf_count] = reserved_bufs[i];
 		info->buf_pin_offsets[info->buf_count] =
-			reserved_bufs[i]->bo->offset64;
+			reserved_bufs[i]->addr.offset;
+
 		info->buf_count++;
 	}
 
-	info->pgtable_bo = intel_aux_pgtable_create(bufmgr,
-						    info->bufs,
-						    info->buf_count);
-	igt_assert(info->pgtable_bo);
+	info->pgtable_buf = intel_aux_pgtable_create(ibb,
+						     info->bufs,
+						     info->buf_count);
+
+	igt_assert(info->pgtable_buf);
 }
 
 void
-gen12_aux_pgtable_cleanup(struct aux_pgtable_info *info)
+gen12_aux_pgtable_cleanup(struct intel_bb *ibb, struct aux_pgtable_info *info)
 {
 	int i;
 
 	/* Check that the pinned bufs kept their offset after the exec. */
-	for (i = 0; i < info->buf_count; i++)
-		igt_assert_eq_u64(info->bufs[i]->bo->offset64,
-				  info->buf_pin_offsets[i]);
+	for (i = 0; i < info->buf_count; i++) {
+		uint64_t addr;
+
+		addr = intel_bb_get_object_offset(ibb, info->bufs[i]->handle);
+		igt_assert_eq_u64(addr, info->buf_pin_offsets[i]);
+	}
 
-	drm_intel_bo_unreference(info->pgtable_bo);
+	if (info->pgtable_buf)
+		intel_buf_destroy(info->pgtable_buf);
 }
 
 uint32_t
-gen12_create_aux_pgtable_state(struct intel_batchbuffer *batch,
-			       drm_intel_bo *aux_pgtable_bo)
+gen12_create_aux_pgtable_state(struct intel_bb *ibb,
+			       struct intel_buf *aux_pgtable_buf)
 {
 	uint64_t *pgtable_ptr;
 	uint32_t pgtable_ptr_offset;
-	int ret;
 
-	if (!aux_pgtable_bo)
+	if (!aux_pgtable_buf)
 		return 0;
 
-	pgtable_ptr = intel_batchbuffer_subdata_alloc(batch,
-						      sizeof(*pgtable_ptr),
-						      sizeof(*pgtable_ptr));
-	pgtable_ptr_offset = intel_batchbuffer_subdata_offset(batch,
-							      pgtable_ptr);
+	pgtable_ptr = intel_bb_ptr(ibb);
+	pgtable_ptr_offset = intel_bb_offset(ibb);
 
-	*pgtable_ptr = aux_pgtable_bo->offset64;
-	ret = drm_intel_bo_emit_reloc(batch->bo, pgtable_ptr_offset,
-				      aux_pgtable_bo, 0,
-				      0, 0);
-	assert(ret == 0);
+	*pgtable_ptr = intel_bb_offset_reloc(ibb, aux_pgtable_buf->handle,
+					     0, 0,
+					     pgtable_ptr_offset, -1);
+	intel_bb_ptr_add(ibb, sizeof(*pgtable_ptr));
 
 	return pgtable_ptr_offset;
 }
 
 void
-gen12_emit_aux_pgtable_state(struct intel_batchbuffer *batch, uint32_t state,
-			     bool render)
+gen12_emit_aux_pgtable_state(struct intel_bb *ibb, uint32_t state, bool render)
 {
 	uint32_t table_base_reg = render ? GEN12_GFX_AUX_TABLE_BASE_ADDR :
 					   GEN12_VEBOX_AUX_TABLE_BASE_ADDR;
@@ -662,11 +625,11 @@ gen12_emit_aux_pgtable_state(struct intel_batchbuffer *batch, uint32_t state,
 	if (!state)
 		return;
 
-	OUT_BATCH(MI_LOAD_REGISTER_MEM_GEN8 | MI_MMIO_REMAP_ENABLE_GEN12);
-	OUT_BATCH(table_base_reg);
-	OUT_RELOC(batch->bo, 0, 0, state);
+	intel_bb_out(ibb, MI_LOAD_REGISTER_MEM_GEN8 | MI_MMIO_REMAP_ENABLE_GEN12);
+	intel_bb_out(ibb, table_base_reg);
+	intel_bb_emit_reloc(ibb, ibb->handle, 0, 0, state, ibb->batch_offset);
 
-	OUT_BATCH(MI_LOAD_REGISTER_MEM_GEN8 | MI_MMIO_REMAP_ENABLE_GEN12);
-	OUT_BATCH(table_base_reg + 4);
-	OUT_RELOC(batch->bo, 0, 0, state + 4);
+	intel_bb_out(ibb, MI_LOAD_REGISTER_MEM_GEN8 | MI_MMIO_REMAP_ENABLE_GEN12);
+	intel_bb_out(ibb, table_base_reg + 4);
+	intel_bb_emit_reloc(ibb, ibb->handle, 0, 0, state + 4, ibb->batch_offset);
 }
lib/intel_aux_pgtable.h +13 -16
index ac82b7d2..e9976e52 100644
@@ -1,36 +1,33 @@
 #ifndef __INTEL_AUX_PGTABLE_H__
 #define __INTEL_AUX_PGTABLE_H__
 
-#include "intel_bufmgr.h"
-
-struct igt_buf;
-struct intel_batchbuffer;
+#include "intel_bufops.h"
 
 struct aux_pgtable_info {
 	int buf_count;
-	const struct igt_buf *bufs[2];
+	struct intel_buf *bufs[2];
 	uint64_t buf_pin_offsets[2];
-	drm_intel_bo *pgtable_bo;
+	struct intel_buf *pgtable_buf;
 };
 
-drm_intel_bo *
-intel_aux_pgtable_create(drm_intel_bufmgr *bufmgr,
-			 const struct igt_buf **bufs, int buf_count);
+struct intel_buf *
+intel_aux_pgtable_create(struct intel_bb *ibb,
+			 struct intel_buf **bufs, int buf_count);
 
 void
 gen12_aux_pgtable_init(struct aux_pgtable_info *info,
-		       drm_intel_bufmgr *bufmgr,
-		       const struct igt_buf *src_buf,
-		       const struct igt_buf *dst_buf);
+		       struct intel_bb *ibb,
+		       struct intel_buf *src_buf,
+		       struct intel_buf *dst_buf);
 
 void
-gen12_aux_pgtable_cleanup(struct aux_pgtable_info *info);
+gen12_aux_pgtable_cleanup(struct intel_bb *ibb, struct aux_pgtable_info *info);
 
 uint32_t
-gen12_create_aux_pgtable_state(struct intel_batchbuffer *batch,
-			       drm_intel_bo *aux_pgtable_bo);
+gen12_create_aux_pgtable_state(struct intel_bb *batch,
+			       struct intel_buf *aux_pgtable_buf);
 void
-gen12_emit_aux_pgtable_state(struct intel_batchbuffer *batch, uint32_t state,
+gen12_emit_aux_pgtable_state(struct intel_bb *batch, uint32_t state,
 			     bool render);
 
 #endif
lib/intel_batchbuffer.h +23 -19

79 lines not on this page · raw message

lib/rendercopy.h +51 -51

121 lines not on this page · raw message

lib/rendercopy_gen4.c +280 -291

841 lines not on this page · raw message

lib/rendercopy_gen6.c +296 -297

799 lines not on this page · raw message

lib/rendercopy_gen7.c +309 -303

599 lines not on this page · raw message

lib/rendercopy_gen8.c +451 -579

1,030 lines not on this page · raw message

lib/rendercopy_gen9.c +512 -633

1,145 lines not on this page · raw message

lib/rendercopy_i830.c +143 -135

278 lines not on this page · raw message

lib/rendercopy_i915.c +145 -136

281 lines not on this page · raw message

lib/veboxcopy.h +4 -4
index 949d83bf..925b8f52 100644

Lines of this file are not shown. View the raw message.

lib/veboxcopy_gen12.c +58 -59

117 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

Part of the diff is not shown here. View the raw message.

#7 lore raw

PATCH v17 7/16 tests/api_intel_bb: add render tests

In reply to Zbigniew Kempczyński

Check render / render-ccs tests works fine on all supported gens.

Cc Dominik Grzegorzek <[email protected]>
Cc Chris Wilson <[email protected]>
---
 tests/i915/api_intel_bb.c | 256 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 255 insertions(+), 1 deletion(-)
tests/i915/api_intel_bb.c +255 -1
index 6967fc5d..723c0315 100644
@@ -32,6 +32,8 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+#include <glib.h>
+#include <zlib.h>
 #include "intel_bufops.h"
 
 #define PAGE_SIZE 4096
@@ -58,6 +60,7 @@ enum obj_cache_ops {
 static bool debug_bb = false;
 static bool write_png = false;
 static bool buf_info = false;
+static bool print_base64 = false;
 
 static void *alloc_aligned(uint64_t size)
 {
@@ -454,6 +457,54 @@ static int compare_bufs(struct intel_buf *buf1, struct intel_buf *buf2,
 	return ret;
 }
 
+#define LINELEN 76
+static int dump_base64(const char *name, struct intel_buf *buf)
+{
+	void *ptr;
+	int fd, ret;
+	uLongf outsize = buf->surface[0].size * 3 / 2;
+	Bytef *destbuf = malloc(outsize);
+	gchar *str, *pos;
+
+	fd = buf_ops_get_fd(buf->bops);
+
+	ptr = gem_mmap__device_coherent(fd, buf->handle, 0,
+					buf->surface[0].size, PROT_READ);
+
+	ret = compress2(destbuf, &outsize, ptr, buf->surface[0].size,
+			Z_BEST_COMPRESSION);
+	if (ret != Z_OK) {
+		igt_warn("error compressing, ret: %d\n", ret);
+	} else {
+		igt_info("compressed %u -> %lu\n",
+			 buf->surface[0].size, outsize);
+
+		igt_info("--- %s ---\n", name);
+		pos = str = g_base64_encode(destbuf, outsize);
+		outsize = strlen(str);
+		while (pos) {
+			char line[LINELEN + 1];
+			int to_copy = min(LINELEN, outsize);
+
+			memcpy(line, pos, to_copy);
+			line[to_copy] = 0;
+			igt_info("%s\n", line);
+			pos += LINELEN;
+			outsize -= to_copy;
+
+			if (outsize == 0)
+				break;
+		}
+		free(str);
+	}
+
+	munmap(ptr, buf->surface[0].size);
+	free(destbuf);
+
+	return ret;
+}
+
+
 static int __do_intel_bb_blit(struct buf_ops *bops, uint32_t tiling)
 {
 	struct intel_bb *ibb;
@@ -632,6 +683,180 @@ static void full_batch(struct buf_ops *bops)
 	intel_bb_destroy(ibb);
 }
 
+static int render(struct buf_ops *bops, uint32_t tiling, bool do_reloc,
+		  uint32_t width, uint32_t height)
+{
+	struct intel_bb *ibb;
+	struct intel_buf src, dst, final;
+	int i915 = buf_ops_get_fd(bops);
+	uint32_t fails = 0;
+	char name[128];
+	uint32_t devid = intel_get_drm_devid(i915);
+	igt_render_copyfunc_t render_copy = NULL;
+
+	igt_debug("%s() gen: %d\n", __func__, intel_gen(devid));
+
+	/* Don't use relocations on gen12+ */
+	igt_require((do_reloc && intel_gen(devid) < 12) ||
+		    !do_reloc);
+
+	if (do_reloc)
+		ibb = intel_bb_create_with_relocs(i915, PAGE_SIZE);
+	else
+		ibb = intel_bb_create(i915, PAGE_SIZE);
+
+	if (debug_bb)
+		intel_bb_set_debug(ibb, true);
+
+	if (print_base64)
+		intel_bb_set_dump_base64(ibb, true);
+
+	scratch_buf_init(bops, &src, width, height, I915_TILING_NONE,
+			 I915_COMPRESSION_NONE);
+	scratch_buf_init(bops, &dst, width, height, tiling,
+			 I915_COMPRESSION_NONE);
+	scratch_buf_init(bops, &final, width, height, I915_TILING_NONE,
+			 I915_COMPRESSION_NONE);
+
+	scratch_buf_draw_pattern(bops, &src,
+				 0, 0, width, height,
+				 0, 0, width, height, 0);
+
+	render_copy = igt_get_render_copyfunc(devid);
+	igt_assert(render_copy);
+
+	render_copy(ibb, 0,
+		    &src,
+		    0, 0, width, height,
+		    &dst,
+		    0, 0);
+
+	render_copy(ibb, 0,
+		    &dst,
+		    0, 0, width, height,
+		    &final,
+		    0, 0);
+
+	intel_bb_sync(ibb);
+	intel_bb_destroy(ibb);
+
+	if (write_png) {
+		snprintf(name, sizeof(name) - 1,
+			 "render_dst_tiling_%d.png", tiling);
+		intel_buf_write_to_png(&src, "render_src_tiling_none.png");
+		intel_buf_write_to_png(&dst, name);
+		intel_buf_write_to_png(&final, "render_final_tiling_none.png");
+	}
+
+	/* We'll fail on src <-> final compare so just warn */
+	if (tiling == I915_TILING_NONE) {
+		if (compare_bufs(&src, &dst, false) > 0)
+			igt_warn("%s: none->none failed!\n", __func__);
+	} else {
+		if (compare_bufs(&src, &dst, false) == 0)
+			igt_warn("%s: none->tiled failed!\n", __func__);
+	}
+
+	fails = compare_bufs(&src, &final, true);
+
+	if (fails && print_base64) {
+		dump_base64("src", &src);
+		dump_base64("dst", &dst);
+		dump_base64("final", &final);
+	}
+
+	intel_buf_close(bops, &src);
+	intel_buf_close(bops, &dst);
+	intel_buf_close(bops, &final);
+
+	igt_assert_f(fails == 0, "%s: (tiling: %d) fails: %d\n",
+		     __func__, tiling, fails);
+
+	return fails;
+}
+
+static uint32_t count_compressed(int gen, struct intel_buf *buf)
+{
+	int ccs_size = intel_buf_ccs_width(gen, buf) * intel_buf_ccs_height(gen, buf);
+	uint8_t *ptr = intel_buf_device_map(buf, false);
+	uint32_t compressed = 0;
+	int i;
+
+	for (i = 0; i < ccs_size; i++)
+		if (ptr[buf->ccs[0].offset + i])
+			compressed++;
+
+	intel_buf_unmap(buf);
+
+	return compressed;
+}
+
+#define IMGSIZE (512 * 512 * 4)
+#define CCSIMGSIZE (IMGSIZE + 4096)
+static void render_ccs(struct buf_ops *bops)
+{
+	struct intel_bb *ibb;
+	const int width = 1024;
+	const int height = 1024;
+	struct intel_buf src, dst, final;
+	int i915 = buf_ops_get_fd(bops);
+	uint32_t fails = 0;
+	uint32_t compressed = 0;
+	uint32_t devid = intel_get_drm_devid(i915);
+	igt_render_copyfunc_t render_copy = NULL;
+
+	ibb = intel_bb_create(i915, PAGE_SIZE);
+	if (debug_bb)
+		intel_bb_set_debug(ibb, true);
+
+	scratch_buf_init(bops, &src, width, height, I915_TILING_NONE,
+			 I915_COMPRESSION_NONE);
+	scratch_buf_init(bops, &dst, width, height, I915_TILING_Y,
+			 I915_COMPRESSION_RENDER);
+	scratch_buf_init(bops, &final, width, height, I915_TILING_NONE,
+			 I915_COMPRESSION_NONE);
+
+	render_copy = igt_get_render_copyfunc(devid);
+	igt_assert(render_copy);
+
+	scratch_buf_draw_pattern(bops, &src,
+				 0, 0, width, height,
+				 0, 0, width, height, 0);
+
+	render_copy(ibb, 0,
+		    &src,
+		    0, 0, width, height,
+		    &dst,
+		    0, 0);
+
+	render_copy(ibb, 0,
+		    &dst,
+		    0, 0, width, height,
+		    &final,
+		    0, 0);
+
+	intel_bb_sync(ibb);
+	intel_bb_destroy(ibb);
+
+	fails = compare_bufs(&src, &final, true);
+	compressed = count_compressed(ibb->gen, &dst);
+
+	igt_debug("fails: %u, compressed: %u\n", fails, compressed);
+
+	if (write_png) {
+		intel_buf_write_to_png(&src, "render-ccs-src.png");
+		intel_buf_write_to_png(&dst, "render-ccs-dst.png");
+		intel_buf_write_aux_to_png(&dst, "render-ccs-dst-aux.png");
+		intel_buf_write_to_png(&final, "render-ccs-final.png");
+	}
+
+	intel_buf_close(bops, &src);
+	intel_buf_close(bops, &dst);
+	intel_buf_close(bops, &final);
+
+	igt_assert_f(fails == 0, "render-ccs fails: %d\n", fails);
+}
+
 static int opt_handler(int opt, int opt_index, void *data)
 {
 	switch (opt) {
@@ -644,6 +869,9 @@ static int opt_handler(int opt, int opt_index, void *data)
 	case 'i':
 		buf_info = true;
 		break;
+	case 'b':
+		print_base64 = true;
+		break;
 	default:
 		return IGT_OPT_HANDLER_ERROR;
 	}
@@ -655,12 +883,14 @@ const char *help_str =
 	"  -d\tDebug bb\n"
 	"  -p\tWrite surfaces to png\n"
 	"  -i\tPrint buffer info\n"
+	"  -b\tDump to base64 (bb and images)\n"
 	;
 
-igt_main_args("dpi", NULL, help_str, opt_handler, NULL)
+igt_main_args("dpib", NULL, help_str, opt_handler, NULL)
 {
 	int i915;
 	struct buf_ops *bops;
+	uint32_t width;
 
 	igt_fixture {
 		i915 = drm_open_driver(DRIVER_INTEL);
@@ -702,6 +932,30 @@ igt_main_args("dpi", NULL, help_str, opt_handler, NULL)
 	igt_subtest("full-batch")
 		full_batch(bops);
 
+	for (width = 512; width <= 1024; width += 512) {
+		igt_subtest_f("render-none-%u", width) {
+			render(bops, I915_TILING_NONE, false, width, width);
+		}
+		igt_subtest_f("render-x-%u", width) {
+			render(bops, I915_TILING_X, false, width, width);
+		}
+		igt_subtest_f("render-y-%u", width) {
+			render(bops, I915_TILING_Y, false, width, width);
+		}
+		igt_subtest_f("render-none-reloc-%u", width) {
+			render(bops, I915_TILING_NONE, true, width, width);
+		}
+		igt_subtest_f("render-x-reloc-%u", width) {
+			render(bops, I915_TILING_X, true, width, width);
+		}
+		igt_subtest_f("render-y-reloc-%u", width) {
+			render(bops, I915_TILING_Y, true, width, width);
+		}
+	}
+
+	igt_subtest("render-ccs")
+		render_ccs(bops);
+
 	igt_fixture {
 		buf_ops_destroy(bops);
 		close(i915);
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#8 lore raw

PATCH v17 8/16 lib/intel_batchbuffer: use canonical addresses for 48bit ppgtt

In reply to Zbigniew Kempczyński

For all EXEC_OBJECT_PINNED objects we need to be sure address passed must be in canonical form.

Until IGT allocator will be written just limit 48 and 47 bit gtt tables to 46 bit only. We don't want to play with canonical addresses with 47-bit set to 1 (and then 63:48).

Cc Dominik Grzegorzek <[email protected]>
Cc Chris Wilson <[email protected]>
---
 lib/intel_batchbuffer.c   | 37 +++++++++++++++++++++++++++-----
 tests/i915/api_intel_bb.c | 44 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 5 deletions(-)
lib/intel_batchbuffer.c +32 -5
index 87638bb2..cd5278b0 100644
@@ -1205,6 +1205,20 @@ static void __reallocate_objects(struct intel_bb *ibb)
 	}
 }
 
+/*
+ * gen8_canonical_addr
+ * Used to convert any address into canonical form, i.e. [63:48] == [47].
+ * Based on kernel's sign_extend64 implementation.
+ * @address - a virtual address
+ */
+#define GEN8_HIGH_ADDRESS_BIT 47
+static uint64_t gen8_canonical_addr(uint64_t address)
+{
+	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
+
+	return (__s64)(address << shift) >> shift;
+}
+
 static inline uint64_t __intel_bb_propose_offset(struct intel_bb *ibb)
 {
 	uint64_t offset;
@@ -1217,6 +1231,7 @@ static inline uint64_t __intel_bb_propose_offset(struct intel_bb *ibb)
 	offset += 256 << 10; /* Keep the low 256k clear, for negative deltas */
 	offset &= ibb->gtt_size - 1;
 	offset &= ~(ibb->alignment - 1);
+	offset = gen8_canonical_addr(offset);
 
 	return offset;
 }
@@ -1254,9 +1269,21 @@ __intel_bb_create(int i915, uint32_t size, bool do_relocs)
 	gtt_size = gem_aperture_size(i915);
 	if (!gem_uses_full_ppgtt(i915))
 		gtt_size /= 2;
-	if ((gtt_size - 1) >> 32)
+	if ((gtt_size - 1) >> 32) {
 		ibb->supports_48b_address = true;
 
+		/*
+		 * Until we develop IGT address allocator we workaround
+		 * playing with canonical addresses with 47-bit set to 1
+		 * just by limiting gtt size to 46-bit when gtt is 47 or 48
+		 * bit size. Current interface doesn't pass bo size, so
+		 * limiting to 46 bit make us sure we won't enter to
+		 * addresses with 47-bit set (we use 32-bit size now so
+		 * still we fit 47-bit address space).
+		 */
+		if (gtt_size & (3ull << 47))
+			gtt_size = (1ull << 46);
+	}
 	ibb->gtt_size = gtt_size;
 
 	__reallocate_objects(ibb);
@@ -1512,7 +1539,11 @@ intel_bb_add_object(struct intel_bb *ibb, uint32_t handle,
 	i = ibb->num_objects;
 	object = &ibb->objects[i];
 	object->handle = handle;
+
+	/* Limit current offset to gtt size */
 	object->offset = offset;
+	if (offset != INTEL_BUF_INVALID_ADDRESS)
+		object->offset = gen8_canonical_addr(offset & (ibb->gtt_size - 1));
 	object->alignment = ibb->alignment;
 
 	found = tsearch((void *) object, &ibb->root, __compare_objects);
@@ -1832,8 +1863,6 @@ static void intel_bb_dump_execbuf(struct intel_bb *ibb,
 			    from_user_pointer(execbuf->buffers_ptr))[i];
 		relocs = from_user_pointer(objects->relocs_ptr);
 		address = objects->offset;
-		if (address != INTEL_BUF_INVALID_ADDRESS)
-			address = address & (ibb->gtt_size - 1);
 		igt_info(" [%d] handle: %u, reloc_count: %d, reloc_ptr: %p, "
 			 "align: 0x%llx, offset: 0x%" PRIx64 ", flags: 0x%llx, "
 			 "rsvd1: 0x%llx, rsvd2: 0x%llx\n",
@@ -1848,8 +1877,6 @@ static void intel_bb_dump_execbuf(struct intel_bb *ibb,
 			for (j = 0; j < objects->relocation_count; j++) {
 				reloc = &relocs[j];
 				address = reloc->presumed_offset;
-				if (address != INTEL_BUF_INVALID_ADDRESS)
-					address = address & (ibb->gtt_size - 1);
 				igt_info("\t [%d] target handle: %u, "
 					 "offset: 0x%llx, delta: 0x%x, "
 					 "presumed_offset: 0x%" PRIx64 ", "
tests/i915/api_intel_bb.c +44 -0

56 lines not on this page · raw message

Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#9 lore raw

PATCH v17 9/16 lib/igt_draw: remove libdrm dependency

In reply to Zbigniew Kempczyński

Change rendercopy to use intel_bb to remove libdrm dependency.

---
 lib/igt_draw.c | 154 ++++++++++++++++++++++++-------------------------
 lib/igt_draw.h |   8 +--
 2 files changed, 78 insertions(+), 84 deletions(-)
lib/igt_draw.c +74 -80
index f2340127..c2b6eb3e 100644
@@ -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,39 @@ 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);
 
 	switch (buf->bpp) {
 	case 8:
@@ -544,34 +557,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 +596,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 +629,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 +638,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 +688,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 +701,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 +722,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);
lib/igt_draw.h +4 -4
index ec146754..2d18ef6c 100644
@@ -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);
 
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#10 lore raw

PATCH v17 10/16 lib/igt_fb: Removal of libdrm dependency

In reply to Zbigniew Kempczyński

From: Dominik Grzegorzek <[email protected]>

Adopt to intel_bb/intel_buf for libdrm removal.

Cc Zbigniew Kempczyński <[email protected]>
Cc Chris Wilson <[email protected]>
---
 lib/igt_fb.c | 96 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 54 insertions(+), 42 deletions(-)
lib/igt_fb.c +54 -42
index 3864b7a1..748c9c5a 100644
@@ -45,6 +45,7 @@
 #include "intel_batchbuffer.h"
 #include "intel_chipset.h"
 #include "i915/gem_mman.h"
+#include "intel_bufops.h"
 
 /**
  * SECTION:igt_fb
@@ -1973,8 +1974,8 @@ struct fb_blit_upload {
 	int fd;
 	struct igt_fb *fb;
 	struct fb_blit_linear linear;
-	drm_intel_bufmgr *bufmgr;
-	struct intel_batchbuffer *batch;
+	struct buf_ops *bops;
+	struct intel_bb *ibb;
 };
 
 static bool fast_blit_ok(const struct igt_fb *fb)
@@ -2044,14 +2045,14 @@ static bool use_blitter(const struct igt_fb *fb)
 	       !gem_has_mappable_ggtt(fb->fd);
 }
 
-static void init_buf_ccs(struct igt_buf *buf, int ccs_idx,
+static void init_buf_ccs(struct intel_buf *buf, int ccs_idx,
 			 uint32_t offset, uint32_t stride)
 {
 	buf->ccs[ccs_idx].offset = offset;
 	buf->ccs[ccs_idx].stride = stride;
 }
 
-static void init_buf_surface(struct igt_buf *buf, int surface_idx,
+static void init_buf_surface(struct intel_buf *buf, int surface_idx,
 			     uint32_t offset, uint32_t stride, uint32_t size)
 {
 	buf->surface[surface_idx].offset = offset;
@@ -2075,26 +2076,17 @@ static int yuv_semiplanar_bpp(uint32_t drm_format)
 	}
 }
 
-static void init_buf(struct fb_blit_upload *blit,
-		     struct igt_buf *buf,
-		     const struct igt_fb *fb,
-		     const char *name)
+static struct intel_buf *create_buf(struct fb_blit_upload *blit,
+				   const struct igt_fb *fb,
+				   const char *name)
 {
+	struct intel_buf *buf;
+	uint32_t bo_name, handle, compression;
 	int num_surfaces;
 	int i;
 
 	igt_assert_eq(fb->offsets[0], 0);
 
-	buf->bo = gem_handle_to_libdrm_bo(blit->bufmgr, blit->fd,
-					  name, fb->gem_handle);
-	buf->tiling = igt_fb_mod_to_tiling(fb->modifier);
-	buf->bpp = fb->plane_bpp[0];
-	buf->format_is_yuv = igt_format_is_yuv(fb->drm_format);
-	buf->format_is_yuv_semiplanar =
-		igt_format_is_yuv_semiplanar(fb->drm_format);
-	if (buf->format_is_yuv_semiplanar)
-		buf->yuv_semiplanar_bpp = yuv_semiplanar_bpp(fb->drm_format);
-
 	if (is_ccs_modifier(fb->modifier)) {
 		igt_assert_eq(fb->strides[0] & 127, 0);
 
@@ -2104,17 +2096,36 @@ static void init_buf(struct fb_blit_upload *blit,
 			igt_assert_eq(fb->strides[1] & 127, 0);
 
 		if (is_gen12_mc_ccs_modifier(fb->modifier))
-			buf->compression = I915_COMPRESSION_MEDIA;
+			compression = I915_COMPRESSION_MEDIA;
 		else
-			buf->compression = I915_COMPRESSION_RENDER;
+			compression = I915_COMPRESSION_RENDER;
+	} else {
+		num_surfaces = fb->num_planes;
+		compression = I915_COMPRESSION_NONE;
+	}
 
+	bo_name = gem_flink(blit->fd, fb->gem_handle);
+	handle = gem_open(blit->fd, bo_name);
+	buf = calloc(1, sizeof(*buf));
+	igt_assert(buf);
+	intel_buf_init_using_handle(blit->bops, handle, buf, fb->width,
+				    fb->height, fb->plane_bpp[0], 0,
+				    igt_fb_mod_to_tiling(fb->modifier),
+				    compression);
+	intel_buf_set_name(buf, name);
+
+	buf->format_is_yuv = igt_format_is_yuv(fb->drm_format);
+	buf->format_is_yuv_semiplanar =
+		igt_format_is_yuv_semiplanar(fb->drm_format);
+	if (buf->format_is_yuv_semiplanar)
+		buf->yuv_semiplanar_bpp = yuv_semiplanar_bpp(fb->drm_format);
+
+	if (is_ccs_modifier(fb->modifier)) {
 		num_surfaces = fb->num_planes / 2;
 		for (i = 0; i < num_surfaces; i++)
 			init_buf_ccs(buf, i,
 				     fb->offsets[num_surfaces + i],
 				     fb->strides[num_surfaces + i]);
-	} else {
-		num_surfaces = fb->num_planes;
 	}
 
 	igt_assert(fb->offsets[0] == 0);
@@ -2130,11 +2141,13 @@ static void init_buf(struct fb_blit_upload *blit,
 
 	if (fb->modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC)
 		buf->cc.offset = fb->offsets[2];
+
+	return buf;
 }
 
-static void fini_buf(struct igt_buf *buf)
+static void fini_buf(struct intel_buf *buf)
 {
-	drm_intel_bo_unreference(buf->bo);
+	intel_buf_destroy(buf);
 }
 
 static bool use_vebox_copy(const struct igt_fb *src_fb,
@@ -2164,7 +2177,7 @@ static void copy_with_engine(struct fb_blit_upload *blit,
 			     const struct igt_fb *dst_fb,
 			     const struct igt_fb *src_fb)
 {
-	struct igt_buf src = {}, dst = {};
+	struct intel_buf *src, *dst;
 	igt_render_copyfunc_t render_copy = NULL;
 	igt_vebox_copyfunc_t vebox_copy = NULL;
 
@@ -2178,23 +2191,23 @@ static void copy_with_engine(struct fb_blit_upload *blit,
 	igt_assert_eq(dst_fb->offsets[0], 0);
 	igt_assert_eq(src_fb->offsets[0], 0);
 
-	init_buf(blit, &src, src_fb, "cairo enginecopy src");
-	init_buf(blit, &dst, dst_fb, "cairo enginecopy dst");
+	src = create_buf(blit, src_fb, "cairo enginecopy src");
+	dst = create_buf(blit, dst_fb, "cairo enginecopy dst");
 
 	if (vebox_copy)
-		vebox_copy(blit->batch, &src,
+		vebox_copy(blit->ibb, src,
 			   dst_fb->plane_width[0], dst_fb->plane_height[0],
-			   &dst);
+			   dst);
 	else
-		render_copy(blit->batch, NULL,
-			    &src,
+		render_copy(blit->ibb, 0,
+			    src,
 			    0, 0,
 			    dst_fb->plane_width[0], dst_fb->plane_height[0],
-			    &dst,
+			    dst,
 			    0, 0);
 
-	fini_buf(&dst);
-	fini_buf(&src);
+	fini_buf(dst);
+	fini_buf(src);
 }
 
 static void blitcopy(const struct igt_fb *dst_fb,
@@ -2268,7 +2281,7 @@ static void free_linear_mapping(struct fb_blit_upload *blit)
 		gem_set_domain(fd, linear->fb.gem_handle,
 			I915_GEM_DOMAIN_GTT, 0);
 
-		if (blit->batch)
+		if (blit->ibb)
 			copy_with_engine(blit, fb, &linear->fb);
 		else
 			blitcopy(fb, &linear->fb);
@@ -2277,9 +2290,9 @@ static void free_linear_mapping(struct fb_blit_upload *blit)
 		gem_close(fd, linear->fb.gem_handle);
 	}
 
-	if (blit->batch) {
-		intel_batchbuffer_free(blit->batch);
-		drm_intel_bufmgr_destroy(blit->bufmgr);
+	if (blit->ibb) {
+		intel_bb_destroy(blit->ibb);
+		buf_ops_destroy(blit->bops);
 	}
 }
 
@@ -2301,9 +2314,8 @@ static void setup_linear_mapping(struct fb_blit_upload *blit)
 	struct fb_blit_linear *linear = &blit->linear;
 
 	if (!igt_vc4_is_tiled(fb->modifier) && use_enginecopy(fb)) {
-		blit->bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
-		blit->batch = intel_batchbuffer_alloc(blit->bufmgr,
-						      intel_get_drm_devid(fd));
+		blit->bops = buf_ops_create(fd);
+		blit->ibb = intel_bb_create(fd, 4096);
 	}
 
 	/*
@@ -2335,7 +2347,7 @@ static void setup_linear_mapping(struct fb_blit_upload *blit)
 		gem_set_domain(fd, linear->fb.gem_handle,
 				I915_GEM_DOMAIN_GTT, 0);
 
-		if (blit->batch)
+		if (blit->ibb)
 			copy_with_engine(blit, &linear->fb, fb);
 		else
 			blitcopy(&linear->fb, fb);
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#11 lore raw

PATCH v17 11/16 tests/gem|kms: remove libdrm dependency (batch 1)

In reply to Zbigniew Kempczyński

From: Dominik Grzegorzek <[email protected]>

Use intel_bb / intel_buf to remove libdrm dependency.

Tests changed:
- gem_concurrent_all
- gem_ppgtt
- kms_draw_crc
- kms_frontbuffer_tracking
- kms_psr

Cc Zbigniew Kempczyński <[email protected]>
Cc Chris Wilson <[email protected]>
---
 tests/i915/gem_concurrent_all.c  | 434 ++++++++++++++++---------------
 tests/i915/gem_ppgtt.c           | 183 ++++++-------
 tests/kms_draw_crc.c             |  20 +-
 tests/kms_frontbuffer_tracking.c |  20 +-
 tests/kms_psr.c                  | 134 +++++-----
 5 files changed, 392 insertions(+), 399 deletions(-)
tests/i915/gem_concurrent_all.c +218 -216
index 80278c75..7f1763aa 100644
@@ -51,7 +51,6 @@
 #include "i915/gem.h"
 #include "igt.h"
 #include "igt_vgem.h"
-#include "intel_bufmgr.h"
 
 IGT_TEST_DESCRIPTION("Test of pread/pwrite/mmap behavior when writing to active"
 		     " buffers.");
@@ -64,7 +63,9 @@ int pass;
 struct create {
 	const char *name;
 	void (*require)(const struct create *, unsigned);
-	drm_intel_bo *(*create)(drm_intel_bufmgr *, uint64_t size);
+	struct intel_buf *(*create)(struct buf_ops *bops, uint32_t width,
+				    uint32_t height, uint32_t tiling,
+				    uint64_t size);
 };
 
 struct size {
@@ -77,10 +78,10 @@ struct buffers {
 	const struct create *create;
 	const struct access_mode *mode;
 	const struct size *size;
-	drm_intel_bufmgr *bufmgr;
-	struct intel_batchbuffer *batch;
-	drm_intel_bo **src, **dst;
-	drm_intel_bo *snoop, *spare;
+	struct buf_ops *bops;
+	struct intel_bb *ibb;
+	struct intel_buf **src, **dst;
+	struct intel_buf *snoop, *spare;
 	uint32_t *tmp;
 	int width, height, npixels, page_size;
 	int count, num_buffers;
@@ -88,29 +89,32 @@ struct buffers {
 
 #define MIN_BUFFERS 3
 
-static void blt_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src);
+static void blt_copy_bo(struct buffers *b, struct intel_buf *dst,
+			struct intel_buf *src);
 
 static void
-nop_release_bo(drm_intel_bo *bo)
+nop_release_bo(struct intel_buf *buf)
 {
-	drm_intel_bo_unreference(bo);
+	if (buf->ptr)
+		intel_buf_unmap(buf);
+	intel_buf_destroy(buf);
 }
 
 static void
-prw_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+prw_set_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
 	for (int i = 0; i < b->npixels; i++)
 		b->tmp[i] = val;
-	drm_intel_bo_subdata(bo, 0, 4*b->npixels, b->tmp);
+	gem_write(fd, buf->handle, 0, b->tmp, 4*b->npixels);
 }
 
 static void
-prw_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+prw_cmp_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
 	uint32_t *vaddr;
 
 	vaddr = b->tmp;
-	do_or_die(drm_intel_bo_get_subdata(bo, 0, 4*b->npixels, vaddr));
+	gem_read(fd, buf->handle, 0, vaddr, 4*b->npixels);
 	for (int i = 0; i < b->npixels; i++)
 		igt_assert_eq_u32(vaddr[i], val);
 }
@@ -118,31 +122,33 @@ prw_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
 #define pixel(y, width) ((y)*(width) + (((y) + pass)%(width)))
 
 static void
-partial_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+partial_set_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
 	for (int y = 0; y < b->height; y++)
-		do_or_die(drm_intel_bo_subdata(bo, 4*pixel(y, b->width), 4, &val));
+		gem_write(fd, buf->handle, 4*pixel(y, b->width), &val, 4);
 }
 
 static void
-partial_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+partial_cmp_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
 	for (int y = 0; y < b->height; y++) {
-		uint32_t buf;
-		do_or_die(drm_intel_bo_get_subdata(bo, 4*pixel(y, b->width), 4, &buf));
-		igt_assert_eq_u32(buf, val);
+		uint32_t tmp;
+
+		gem_read(fd, buf->handle, 4*pixel(y, b->width), &tmp, 4);
+		igt_assert_eq_u32(tmp, val);
 	}
 }
 
-static drm_intel_bo *
-create_normal_bo(drm_intel_bufmgr *bufmgr, uint64_t size)
+static struct intel_buf *
+create_normal_bo(struct buf_ops *bops, uint32_t width,
+		 uint32_t height, uint32_t tiling, uint64_t size)
 {
-	drm_intel_bo *bo;
+	struct intel_buf *buf;
+	int bpp = size/height/width * 8;
 
-	bo = drm_intel_bo_alloc(bufmgr, "bo", size, 0);
-	igt_assert(bo);
+	buf = intel_buf_create(bops, width, height, bpp, 0, tiling, 0);
 
-	return bo;
+	return buf;
 }
 
 static void can_create_normal(const struct create *create, unsigned count)
@@ -150,19 +156,26 @@ static void can_create_normal(const struct create *create, unsigned count)
 }
 
 #if HAVE_CREATE_PRIVATE
-static drm_intel_bo *
-create_private_bo(drm_intel_bufmgr *bufmgr, uint64_t size)
+static struct intel_buf *
+create_private_bo(buf_ops *bops, uint32_t width, uint32_t height,
+		  uint32_t tiling, uint64_t size)
 {
-	drm_intel_bo *bo;
-	uint32_t handle;
+	struct intel_buf *buf;
+	uint32_t handle, buf_handle, name;
+	int bpp = size/height/width * 8;
 
 	/* XXX gem_create_with_flags(fd, size, I915_CREATE_PRIVATE); */
 
 	handle = gem_create(fd, size);
-	bo = gem_handle_to_libdrm_bo(bufmgr, fd, "stolen", handle);
+	name = gem_flink(fd, handle);
+	buf_handle = gem_open(fd, name);
+
+	buf = calloc(1, sizeof(*buf));
+	intel_buf_init_using_handle(bops, buf_handle, buf, width, height,
+				    bpp, 0, tiling, 0);
 	gem_close(fd, handle);
 
-	return bo;
+	return buf;
 }
 
 static void can_create_private(const struct create *create, unsigned count)
@@ -172,19 +185,26 @@ static void can_create_private(const struct create *create, unsigned count)
 #endif
 
 #if HAVE_CREATE_STOLEN
-static drm_intel_bo *
-create_stolen_bo(drm_intel_bufmgr *bufmgr, uint64_t size)
+static struct intel_buf *
+create_stolen_bo(buf_ops *bops, uint32_t width, uint32_t height,
+		 uint32_t tiling, uint64_t size)
 {
-	drm_intel_bo *bo;
-	uint32_t handle;
+	struct intel_buf *buf;
+	uint32_t handle, buf_handle, name;
+	int bpp = size/height/width * 8;
 
-	/* XXX gem_create_with_flags(fd, size, I915_CREATE_STOLEN); */
+	/* XXX gem_create_with_flags(fd, size, I915_CREATE_PRIVATE); */
 
 	handle = gem_create(fd, size);
-	bo = gem_handle_to_libdrm_bo(bufmgr, fd, "stolen", handle);
+	name = gem_flink(fd, handle);
+	buf_handle = gem_open(fd, name);
+
+	buf = calloc(1, sizeof(*buf));
+	intel_buf_init_using_handle(bops, buf_handle, buf, width, height,
+				    bpp, 0, tiling, 0);
 	gem_close(fd, handle);
 
-	return bo;
+	return buf;
 }
 
 static void can_create_stolen(const struct create *create, unsigned count)
@@ -201,10 +221,17 @@ static void create_cpu_require(const struct create *create, unsigned count)
 #endif
 }
 
-static drm_intel_bo *
+static struct intel_buf *
+create_bo(const struct buffers *b, uint32_t tiling)
+{
+	return b->create->create(b->bops, b->width, b->height,
+				 tiling, 4*b->npixels);
+}
+
+static struct intel_buf *
 unmapped_create_bo(const struct buffers *b)
 {
-	return b->create->create(b->bufmgr, 4*b->npixels);
+	return create_bo(b, I915_TILING_NONE);
 }
 
 static void create_snoop_require(const struct create *create, unsigned count)
@@ -213,16 +240,15 @@ static void create_snoop_require(const struct create *create, unsigned count)
 	igt_require(!gem_has_llc(fd));
 }
 
-static drm_intel_bo *
+static struct intel_buf *
 snoop_create_bo(const struct buffers *b)
 {
-	drm_intel_bo *bo;
+	struct intel_buf *buf;
 
-	bo = unmapped_create_bo(b);
-	gem_set_caching(fd, bo->handle, I915_CACHING_CACHED);
-	drm_intel_bo_disable_reuse(bo);
+	buf = unmapped_create_bo(b);
+	gem_set_caching(fd, buf->handle, I915_CACHING_CACHED);
 
-	return bo;
+	return buf;
 }
 
 static void create_userptr_require(const struct create *create, unsigned count)
@@ -251,11 +277,11 @@ static void create_userptr_require(const struct create *create, unsigned count)
 	igt_require(has_userptr);
 }
 
-static drm_intel_bo *
+static struct intel_buf *
 userptr_create_bo(const struct buffers *b)
 {
 	struct drm_i915_gem_userptr userptr;
-	drm_intel_bo *bo;
+	struct intel_buf *buf;
 	void *ptr;
 
 	memset(&userptr, 0, sizeof(userptr));
@@ -266,54 +292,48 @@ userptr_create_bo(const struct buffers *b)
 	igt_assert(ptr != (void *)-1);
 	userptr.user_ptr = to_user_pointer(ptr);
 
-#if 0
 	do_or_die(drmIoctl(fd, DRM_IOCTL_I915_GEM_USERPTR, &userptr));
-	bo = gem_handle_to_libdrm_bo(b->bufmgr, fd, "userptr", userptr.handle);
-	gem_close(fd, userptr.handle);
-#else
-	bo = drm_intel_bo_alloc_userptr(b->bufmgr, "name",
-					ptr, I915_TILING_NONE, 0,
-					userptr.user_size, 0);
-	igt_assert(bo);
-#endif
-	bo->virtual = from_user_pointer(userptr.user_ptr);
+	buf = calloc(1, sizeof(*buf));
+	intel_buf_init_using_handle(b->bops, userptr.handle, buf, b->width,
+				    b->height, 32, 0, I915_TILING_NONE, 0);
+
+	buf->ptr = (void *) from_user_pointer(userptr.user_ptr);
 
-	return bo;
+	return buf;
 }
 
 static void
-userptr_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+userptr_set_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
 	int size = b->npixels;
-	uint32_t *vaddr = bo->virtual;
+	uint32_t *vaddr = buf->ptr;
 
-	gem_set_domain(fd, bo->handle,
+	gem_set_domain(fd, buf->handle,
 		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
 	while (size--)
 		*vaddr++ = val;
 }
 
 static void
-userptr_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+userptr_cmp_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
 	int size =  b->npixels;
-	uint32_t *vaddr = bo->virtual;
+	uint32_t *vaddr = buf->ptr;
 
-	gem_set_domain(fd, bo->handle,
+	gem_set_domain(fd, buf->handle,
 		       I915_GEM_DOMAIN_CPU, 0);
 	while (size--)
 		igt_assert_eq_u32(*vaddr++, val);
 }
 
 static void
-userptr_release_bo(drm_intel_bo *bo)
+userptr_release_bo(struct intel_buf *buf)
 {
-	igt_assert(bo->virtual);
+	igt_assert(buf->ptr);
 
-	munmap(bo->virtual, bo->size);
-	bo->virtual = NULL;
+	munmap(buf->ptr, buf->surface[0].size);
 
-	drm_intel_bo_unreference(bo);
+	intel_buf_destroy(buf);
 }
 
 static void create_dmabuf_require(const struct create *create, unsigned count)
@@ -349,13 +369,14 @@ struct dmabuf {
 	void *map;
 };
 
-static drm_intel_bo *
+static struct intel_buf *
 dmabuf_create_bo(const struct buffers *b)
 {
 	struct drm_prime_handle args;
-	drm_intel_bo *bo;
+	static struct intel_buf *buf;
 	struct dmabuf *dmabuf;
 	int size;
+	uint32_t handle;
 
 	size = b->page_size;
 
@@ -366,9 +387,12 @@ dmabuf_create_bo(const struct buffers *b)
 
 	do_ioctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args);
 	gem_close(fd, args.handle);
+	igt_assert(args.fd != -1);
 
-	bo = drm_intel_bo_gem_create_from_prime(b->bufmgr, args.fd, size);
-	igt_assert(bo);
+	handle = prime_fd_to_handle(buf_ops_get_fd(b->bops), args.fd);
+	buf = calloc(1, sizeof(*buf));
+	intel_buf_init_using_handle(b->bops, handle, buf, b->width,
+				    b->height, 32, 0, I915_TILING_NONE, 0);
 
 	dmabuf = malloc(sizeof(*dmabuf));
 	igt_assert(dmabuf);
@@ -379,15 +403,15 @@ dmabuf_create_bo(const struct buffers *b)
 			   dmabuf->fd, 0);
 	igt_assert(dmabuf->map != (void *)-1);
 
-	bo->virtual = dmabuf;
+	buf->ptr = (void *) dmabuf;
 
-	return bo;
+	return buf;
 }
 
 static void
-dmabuf_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+dmabuf_set_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
-	struct dmabuf *dmabuf = bo->virtual;
+	struct dmabuf *dmabuf = (void *) buf->ptr;
 	uint32_t *v = dmabuf->map;
 	int y;
 
@@ -398,9 +422,9 @@ dmabuf_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
 }
 
 static void
-dmabuf_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+dmabuf_cmp_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
-	struct dmabuf *dmabuf = bo->virtual;
+	struct dmabuf *dmabuf = (void *) buf->ptr;
 	uint32_t *v = dmabuf->map;
 	int y;
 
@@ -411,17 +435,16 @@ dmabuf_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
 }
 
 static void
-dmabuf_release_bo(drm_intel_bo *bo)
+dmabuf_release_bo(struct intel_buf *buf)
 {
-	struct dmabuf *dmabuf = bo->virtual;
+	struct dmabuf *dmabuf = (void *) buf->ptr;
 	igt_assert(dmabuf);
 
-	munmap(dmabuf->map, bo->size);
+	munmap(dmabuf->map, buf->surface[0].size);
 	close(dmabuf->fd);
 	free(dmabuf);
 
-	bo->virtual = NULL;
-	drm_intel_bo_unreference(bo);
+	intel_buf_destroy(buf);
 }
 
 static bool has_prime_export(int _fd)
@@ -446,13 +469,14 @@ static void create_gtt_require(const struct create *create, unsigned count)
 	gem_require_mappable_ggtt(fd);
 }
 
-static drm_intel_bo *
+static struct intel_buf *
 vgem_create_bo(const struct buffers *b)
 {
 	struct drm_prime_handle args;
-	drm_intel_bo *bo;
+	struct intel_buf *buf;
 	struct vgem_bo vgem;
 	struct dmabuf *dmabuf;
+	uint32_t handle;
 
 	igt_assert(vgem_drv != -1);
 
@@ -470,8 +494,11 @@ vgem_create_bo(const struct buffers *b)
 	gem_close(vgem_drv, args.handle);
 	igt_assert(args.fd != -1);
 
-	bo = drm_intel_bo_gem_create_from_prime(b->bufmgr, args.fd, vgem.size);
-	igt_assert(bo);
+	handle = prime_fd_to_handle(buf_ops_get_fd(b->bops), args.fd);
+	buf = calloc(1, sizeof(*buf));
+	intel_buf_init_using_handle(b->bops, handle, buf,
+				    vgem.width, vgem.height, vgem.bpp,
+				    0, I915_TILING_NONE, 0);
 
 	dmabuf = malloc(sizeof(*dmabuf));
 	igt_assert(dmabuf);
@@ -482,64 +509,58 @@ vgem_create_bo(const struct buffers *b)
 			   dmabuf->fd, 0);
 	igt_assert(dmabuf->map != (void *)-1);
 
-	bo->virtual = dmabuf;
+	buf->ptr = (void *) dmabuf;
 
-	return bo;
+	return buf;
 }
 
 static void
-gtt_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+gtt_set_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
-	uint32_t *vaddr = bo->virtual;
+	uint32_t *vaddr = buf->ptr;
+
+	gem_set_domain(fd, buf->handle,
+		       I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
 
-	drm_intel_gem_bo_start_gtt_access(bo, true);
 	for (int y = 0; y < b->height; y++)
 		vaddr[pixel(y, b->width)] = val;
 }
 
 static void
-gtt_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+gtt_cmp_bo(struct buffers *b, struct  intel_buf *buf, uint32_t val)
 {
-	uint32_t *vaddr = bo->virtual;
+	uint32_t *vaddr = buf->ptr;
 
 	/* GTT access is slow. So we just compare a few points */
-	drm_intel_gem_bo_start_gtt_access(bo, false);
+	gem_set_domain(fd, buf->handle,
+		       I915_GEM_DOMAIN_GTT, 0);
+
 	for (int y = 0; y < b->height; y++)
 		igt_assert_eq_u32(vaddr[pixel(y, b->width)], val);
 }
 
-static drm_intel_bo *
-map_bo(drm_intel_bo *bo)
+static struct intel_buf *
+map_bo(struct intel_buf *buf)
 {
 	/* gtt map doesn't have a write parameter, so just keep the mapping
 	 * around (to avoid the set_domain with the gtt write domain set) and
 	 * manually tell the kernel when we start access the gtt. */
-	do_or_die(drm_intel_gem_bo_map_gtt(bo));
-
-	return bo;
-}
-
-static drm_intel_bo *
-tile_bo(drm_intel_bo *bo, int width)
-{
-	uint32_t tiling = I915_TILING_X;
-	uint32_t stride = width * 4;
-
-	do_or_die(drm_intel_bo_set_tiling(bo, &tiling, stride));
+	buf->ptr = gem_mmap__gtt(buf_ops_get_fd(buf->bops), buf->handle,
+				 buf->surface[0].size, PROT_READ | PROT_WRITE);
 
-	return bo;
+	return buf;
 }
 
-static drm_intel_bo *
+static struct intel_buf *
 gtt_create_bo(const struct buffers *b)
 {
 	return map_bo(unmapped_create_bo(b));
 }
 
-static drm_intel_bo *
+static struct intel_buf *
 gttX_create_bo(const struct buffers *b)
 {
-	return tile_bo(gtt_create_bo(b), b->width);
+	return map_bo(create_bo(b, I915_TILING_X));
 }
 
 static void bit17_require(void)
@@ -574,85 +595,83 @@ wc_create_require(const struct create *create, unsigned count)
 	wc_require();
 }
 
-static drm_intel_bo *
+static struct intel_buf *
 wc_create_bo(const struct buffers *b)
 {
-	drm_intel_bo *bo;
+	static struct intel_buf *buf;
 
-	bo = unmapped_create_bo(b);
-	bo->virtual = gem_mmap__wc(fd, bo->handle, 0, bo->size, PROT_READ | PROT_WRITE);
-	return bo;
+	buf = unmapped_create_bo(b);
+	buf->ptr = gem_mmap__wc(fd, buf->handle, 0, buf->surface[0].size,
+				PROT_READ | PROT_WRITE);
+	return buf;
 }
 
 static void
-wc_release_bo(drm_intel_bo *bo)
+wc_release_bo(struct intel_buf *buf)
 {
-	igt_assert(bo->virtual);
+	igt_assert(buf->ptr);
 
-	munmap(bo->virtual, bo->size);
-	bo->virtual = NULL;
+	munmap(buf->ptr, buf->surface[0].size);
+	buf->ptr = 0;
 
-	nop_release_bo(bo);
+	nop_release_bo(buf);
 }
 
-static drm_intel_bo *
+static struct intel_buf *
 gpu_create_bo(const struct buffers *b)
 {
 	return unmapped_create_bo(b);
 }
 
-static drm_intel_bo *
+static struct intel_buf *
 gpuX_create_bo(const struct buffers *b)
 {
-	return tile_bo(gpu_create_bo(b), b->width);
+	return create_bo(b, I915_TILING_X);
 }
 
 static void
-cpu_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+cpu_set_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
 	int size = b->npixels;
 	uint32_t *vaddr;
 
-	do_or_die(drm_intel_bo_map(bo, true));
-	vaddr = bo->virtual;
+	intel_buf_cpu_map(buf, true);
+	vaddr = buf->ptr;
 	while (size--)
 		*vaddr++ = val;
-	drm_intel_bo_unmap(bo);
+	intel_buf_unmap(buf);
 }
 
 static void
-cpu_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+cpu_cmp_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
 	int size = b->npixels;
 	uint32_t *vaddr;
 
-	do_or_die(drm_intel_bo_map(bo, false));
-	vaddr = bo->virtual;
+	intel_buf_cpu_map(buf, false);
+	vaddr = buf->ptr;
 	while (size--)
 		igt_assert_eq_u32(*vaddr++, val);
-	drm_intel_bo_unmap(bo);
+	intel_buf_unmap(buf);
 }
 
 static void
-gpu_set_bo(struct buffers *buffers, drm_intel_bo *bo, uint32_t val)
+gpu_set_bo(struct buffers *buffers, struct intel_buf *buf, uint32_t val)
 {
 	struct drm_i915_gem_relocation_entry reloc[1];
 	struct drm_i915_gem_exec_object2 gem_exec[2];
 	struct drm_i915_gem_execbuffer2 execbuf;
-	uint32_t buf[10], *b;
-	uint32_t tiling, swizzle;
-
-	drm_intel_bo_get_tiling(bo, &tiling, &swizzle);
+	uint32_t tmp[10], *b;
 
 	memset(reloc, 0, sizeof(reloc));
 	memset(gem_exec, 0, sizeof(gem_exec));
 	memset(&execbuf, 0, sizeof(execbuf));
 
-	b = buf;
+	b = tmp;
 	*b++ = XY_COLOR_BLT_CMD_NOLEN |
 		((gen >= 8) ? 5 : 4) |
 		COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB;
-	if (gen >= 4 && tiling) {
+	if (gen >= 4 && buf->tiling) {
 		b[-1] |= XY_COLOR_BLT_TILED;
 		*b = buffers->width;
 	} else
@@ -660,8 +679,8 @@ gpu_set_bo(struct buffers *buffers, drm_intel_bo *bo, uint32_t val)
 	*b++ |= 0xf0 << 16 | 1 << 25 | 1 << 24;
 	*b++ = 0;
 	*b++ = buffers->height << 16 | buffers->width;
-	reloc[0].offset = (b - buf) * sizeof(uint32_t);
-	reloc[0].target_handle = bo->handle;
+	reloc[0].offset = (b - tmp) * sizeof(uint32_t);
+	reloc[0].target_handle = buf->handle;
 	reloc[0].read_domains = I915_GEM_DOMAIN_RENDER;
 	reloc[0].write_domain = I915_GEM_DOMAIN_RENDER;
 	*b++ = 0;
@@ -669,10 +688,10 @@ gpu_set_bo(struct buffers *buffers, drm_intel_bo *bo, uint32_t val)
 		*b++ = 0;
 	*b++ = val;
 	*b++ = MI_BATCH_BUFFER_END;
-	if ((b - buf) & 1)
+	if ((b - tmp) & 1)
 		*b++ = 0;
 
-	gem_exec[0].handle = bo->handle;
+	gem_exec[0].handle = buf->handle;
 	gem_exec[0].flags = EXEC_OBJECT_NEEDS_FENCE;
 
 	gem_exec[1].handle = gem_create(fd, 4096);
@@ -681,30 +700,30 @@ gpu_set_bo(struct buffers *buffers, drm_intel_bo *bo, uint32_t val)
 
 	execbuf.buffers_ptr = to_user_pointer(gem_exec);
 	execbuf.buffer_count = 2;
-	execbuf.batch_len = (b - buf) * sizeof(buf[0]);
+	execbuf.batch_len = (b - tmp) * sizeof(tmp[0]);
 	if (gen >= 6)
 		execbuf.flags = I915_EXEC_BLT;
 
-	gem_write(fd, gem_exec[1].handle, 0, buf, execbuf.batch_len);
+	gem_write(fd, gem_exec[1].handle, 0, tmp, execbuf.batch_len);
 	gem_execbuf(fd, &execbuf);
 
 	gem_close(fd, gem_exec[1].handle);
 }
 
 static void
-gpu_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val)
+gpu_cmp_bo(struct buffers *b, struct intel_buf *buf, uint32_t val)
 {
-	blt_copy_bo(b, b->snoop, bo);
+	blt_copy_bo(b, b->snoop, buf);
 	cpu_cmp_bo(b, b->snoop, val);
 }
 
 struct access_mode {
 	const char *name;
 	void (*require)(const struct create *, unsigned);
-	drm_intel_bo *(*create_bo)(const struct buffers *b);
-	void (*set_bo)(struct buffers *b, drm_intel_bo *bo, uint32_t val);
-	void (*cmp_bo)(struct buffers *b, drm_intel_bo *bo, uint32_t val);
-	void (*release_bo)(drm_intel_bo *bo);
+	struct intel_buf *(*create_bo)(const struct buffers *b);
+	void (*set_bo)(struct buffers *b, struct intel_buf *buf, uint32_t val);
+	void (*cmp_bo)(struct buffers *b, struct intel_buf *buf, uint32_t val);
+	void (*release_bo)(struct intel_buf *buf);
 };
 igt_render_copyfunc_t rendercopy;
 
@@ -745,7 +764,7 @@ static void buffers_init(struct buffers *b,
 			 const struct access_mode *mode,
 			 const struct size *size,
 			 int num_buffers,
-			 int _fd, int enable_reuse)
+			 int _fd)
 {
 	memset(b, 0, sizeof(*b));
 	b->name = name;
@@ -763,17 +782,13 @@ static void buffers_init(struct buffers *b,
 	b->tmp = malloc(b->page_size);
 	igt_assert(b->tmp);
 
-	b->bufmgr = drm_intel_bufmgr_gem_init(_fd, 4096);
-	igt_assert(b->bufmgr);
+	b->bops = buf_ops_create(_fd);
 
-	b->src = malloc(2*sizeof(drm_intel_bo *)*num_buffers);
+	b->src = malloc(2*sizeof(struct intel_buf *)*num_buffers);
 	igt_assert(b->src);
 	b->dst = b->src + num_buffers;
 
-	if (enable_reuse)
-		drm_intel_bufmgr_gem_enable_reuse(b->bufmgr);
-	b->batch = intel_batchbuffer_alloc(b->bufmgr, devid);
-	igt_assert(b->batch);
+	b->ibb = intel_bb_create(_fd, 4096);
 }
 
 static void buffers_destroy(struct buffers *b)
@@ -809,7 +824,7 @@ static void buffers_destroy(struct buffers *b)
 static void buffers_create(struct buffers *b)
 {
 	int count = b->num_buffers;
-	igt_assert(b->bufmgr);
+	igt_assert(b->bops);
 
 	buffers_destroy(b);
 	igt_assert(b->count == 0);
@@ -823,20 +838,15 @@ static void buffers_create(struct buffers *b)
 	b->snoop = snoop_create_bo(b);
 }
 
-static void buffers_reset(struct buffers *b, bool enable_reuse)
+static void buffers_reset(struct buffers *b)
 {
-	b->bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
-	igt_assert(b->bufmgr);
-
-	if (enable_reuse)
-		drm_intel_bufmgr_gem_enable_reuse(b->bufmgr);
-	b->batch = intel_batchbuffer_alloc(b->bufmgr, devid);
-	igt_assert(b->batch);
+	b->bops = buf_ops_create(fd);
+	b->ibb = intel_bb_create(fd, 4096);
 }
 
 static void buffers_fini(struct buffers *b)
 {
-	if (b->bufmgr == NULL)
+	if (b->bops == NULL)
 		return;
 
 	buffers_destroy(b);
@@ -844,58 +854,47 @@ static void buffers_fini(struct buffers *b)
 	free(b->tmp);
 	free(b->src);
 
-	intel_batchbuffer_free(b->batch);
-	drm_intel_bufmgr_destroy(b->bufmgr);
+	intel_bb_destroy(b->ibb);
+	buf_ops_destroy(b->bops);
 
 	memset(b, 0, sizeof(*b));
 }
 
-typedef void (*do_copy)(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src);
+typedef void (*do_copy)(struct buffers *b, struct intel_buf *dst,
+			struct intel_buf *src);
 typedef igt_hang_t (*do_hang)(void);
 
-static void render_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src)
+static void render_copy_bo(struct buffers *b, struct intel_buf *dst,
+			   struct intel_buf *src)
 {
-	struct igt_buf d = {
-		.bo = dst,
-		.num_tiles = b->npixels * 4,
-		.surface[0] = {
-			.size = b->npixels * 4, .stride = b->width * 4,
-		},
-		.bpp = 32,
-	}, s = {
-		.bo = src,
-		.num_tiles = b->npixels * 4,
-		.surface[0] = {
-			.size = b->npixels * 4, .stride = b->width * 4,
-		},
-		.bpp = 32,
-	};
-	uint32_t swizzle;
-
-	drm_intel_bo_get_tiling(dst, &d.tiling, &swizzle);
-	drm_intel_bo_get_tiling(src, &s.tiling, &swizzle);
-
-	rendercopy(b->batch, NULL,
-		   &s, 0, 0,
+	rendercopy(b->ibb, 0,
+		   src, 0, 0,
 		   b->width, b->height,
-		   &d, 0, 0);
+		   dst, 0, 0);
+	intel_bb_sync(b->ibb);
+	intel_bb_reset(b->ibb, true);
 }
 
-static void blt_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src)
+static void blt_copy_bo(struct buffers *b, struct intel_buf *dst,
+			struct intel_buf *src)
 {
-	intel_blt_copy(b->batch,
+	intel_bb_blt_copy(b->ibb,
 		       src, 0, 0, 4*b->width,
 		       dst, 0, 0, 4*b->width,
 		       b->width, b->height, 32);
+	intel_bb_sync(b->ibb);
+	intel_bb_reset(b->ibb, true);
 }
 
-static void cpu_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src)
+static void cpu_copy_bo(struct buffers *b, struct intel_buf *dst,
+			struct intel_buf *src)
 {
 	const int size = b->page_size;
 	void *d, *s;
 
 	gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_CPU, 0);
-	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
+	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_CPU,
+		       I915_GEM_DOMAIN_CPU);
 	s = gem_mmap__cpu(fd, src->handle, 0, size, PROT_READ);
 	d = gem_mmap__cpu(fd, dst->handle, 0, size, PROT_WRITE);
 
@@ -905,13 +904,15 @@ static void cpu_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src)
 	munmap(s, size);
 }
 
-static void gtt_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src)
+static void gtt_copy_bo(struct buffers *b, struct intel_buf *dst,
+			struct intel_buf *src)
 {
 	const int size = b->page_size;
 	void *d, *s;
 
 	gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_GTT, 0);
-	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
+	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT,
+		       I915_GEM_DOMAIN_GTT);
 
 	s = gem_mmap__gtt(fd, src->handle, size, PROT_READ);
 	d = gem_mmap__gtt(fd, dst->handle, size, PROT_WRITE);
@@ -922,13 +923,15 @@ static void gtt_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src)
 	munmap(s, size);
 }
 
-static void wc_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src)
+static void wc_copy_bo(struct buffers *b, struct intel_buf *dst,
+		       struct intel_buf *src)
 {
 	const int size = b->page_size;
 	void *d, *s;
 
 	gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_WC, 0);
-	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_WC, I915_GEM_DOMAIN_WC);
+	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_WC,
+		       I915_GEM_DOMAIN_WC);
 
 	s = gem_mmap__wc(fd, src->handle, 0, size, PROT_READ);
 	d = gem_mmap__wc(fd, dst->handle, 0, size, PROT_WRITE);
@@ -1335,7 +1338,7 @@ static void run_child(struct buffers *buffers,
 		      do_hang do_hang_func)
 
 {
-	/* We inherit the buffers from the parent, but the bufmgr/batch
+	/* We inherit the buffers from the parent, but the bops/intel_bb
 	 * needs to be local as the cache of reusable itself will be COWed,
 	 * leading to the child closing an object without the parent knowing.
 	 */
@@ -1353,10 +1356,10 @@ static void __run_forked(struct buffers *buffers,
 			 do_hang do_hang_func)
 
 {
-	/* purge the libdrm caches before cloing the process */
+	/* purge the caches before cloing the process */
 	buffers_destroy(buffers);
-	intel_batchbuffer_free(buffers->batch);
-	drm_intel_bufmgr_destroy(buffers->bufmgr);
+	intel_bb_destroy(buffers->ibb);
+	buf_ops_destroy(buffers->bops);
 
 	igt_fork(child, num_children) {
 		int num_buffers;
@@ -1369,7 +1372,7 @@ static void __run_forked(struct buffers *buffers,
 		if (num_buffers < buffers->num_buffers)
 			buffers->num_buffers = num_buffers;
 
-		buffers_reset(buffers, true);
+		buffers_reset(buffers);
 		buffers_create(buffers);
 
 		igt_while_interruptible(interrupt) {
@@ -1382,7 +1385,7 @@ static void __run_forked(struct buffers *buffers,
 	igt_waitchildren();
 	igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0);
 
-	buffers_reset(buffers, true);
+	buffers_reset(buffers);
 }
 
 static void run_forked(struct buffers *buffers,
@@ -1459,8 +1462,7 @@ run_mode(const char *prefix,
 
 	igt_fixture
 		buffers_init(&buffers, prefix, create, mode,
-			     size, num_buffers,
-			     fd, run_wrap_func != run_child);
+			     size, num_buffers, fd);
 
 	for (h = hangs; h->suffix; h++) {
 		if (!all && *h->suffix)
tests/i915/gem_ppgtt.c +82 -101

295 lines not on this page · raw message

tests/kms_draw_crc.c +9 -11
index 70b9b05f..ffd655b0 100644
@@ -38,7 +38,7 @@ struct modeset_params {
 int drm_fd;
 drmModeResPtr drm_res;
 drmModeConnectorPtr drm_connectors[MAX_CONNECTORS];
-drm_intel_bufmgr *bufmgr;
+struct buf_ops *bops;
 igt_pipe_crc_t *pipe_crc;
 
 #define N_FORMATS 3
@@ -126,23 +126,23 @@ static void get_method_crc(enum igt_draw_method method, uint32_t drm_format,
 
 	igt_create_fb(drm_fd, ms.mode->hdisplay, ms.mode->vdisplay,
 		      drm_format, tiling, &fb);
-	igt_draw_rect_fb(drm_fd, bufmgr, NULL, &fb, method,
+	igt_draw_rect_fb(drm_fd, bops, 0, &fb, method,
 			 0, 0, fb.width, fb.height,
 			 get_color(drm_format, 0, 0, 1));
 
-	igt_draw_rect_fb(drm_fd, bufmgr, NULL, &fb, method,
+	igt_draw_rect_fb(drm_fd, bops, 0, &fb, method,
 			 fb.width / 4, fb.height / 4,
 			 fb.width / 2, fb.height / 2,
 			 get_color(drm_format, 0, 1, 0));
-	igt_draw_rect_fb(drm_fd, bufmgr, NULL, &fb, method,
+	igt_draw_rect_fb(drm_fd, bops, 0, &fb, method,
 			 fb.width / 8, fb.height / 8,
 			 fb.width / 4, fb.height / 4,
 			 get_color(drm_format, 1, 0, 0));
-	igt_draw_rect_fb(drm_fd, bufmgr, NULL, &fb, method,
+	igt_draw_rect_fb(drm_fd, bops, 0, &fb, method,
 			 fb.width / 2, fb.height / 2,
 			 fb.width / 3, fb.height / 3,
 			 get_color(drm_format, 1, 0, 1));
-	igt_draw_rect_fb(drm_fd, bufmgr, NULL, &fb, method, 1, 1, 15, 15,
+	igt_draw_rect_fb(drm_fd, bops, 0, &fb, method, 1, 1, 15, 15,
 			 get_color(drm_format, 0, 1, 1));
 
 	rc = drmModeSetCrtc(drm_fd, ms.crtc_id, fb.fb_id, 0, 0,
@@ -228,7 +228,7 @@ static void fill_fb_subtest(void)
 	igt_create_fb(drm_fd, ms.mode->hdisplay, ms.mode->vdisplay,
 		      DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE, &fb);
 
-	igt_draw_rect_fb(drm_fd, bufmgr, NULL, &fb,
+	igt_draw_rect_fb(drm_fd, bops, 0, &fb,
 			 gem_has_mappable_ggtt(drm_fd) ? IGT_DRAW_MMAP_GTT :
 							 IGT_DRAW_MMAP_WC,
 			 0, 0, fb.width, fb.height, 0xFF);
@@ -270,9 +270,7 @@ static void setup_environment(void)
 
 	kmstest_set_vt_graphics_mode();
 
-	bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
-	igt_assert(bufmgr);
-	drm_intel_bufmgr_gem_enable_reuse(bufmgr);
+	bops = buf_ops_create(drm_fd);
 
 	find_modeset_params();
 	pipe_crc = igt_pipe_crc_new(drm_fd, kmstest_get_crtc_idx(drm_res, ms.crtc_id),
@@ -285,7 +283,7 @@ static void teardown_environment(void)
 
 	igt_pipe_crc_free(pipe_crc);
 
-	drm_intel_bufmgr_destroy(bufmgr);
+	buf_ops_destroy(bops);
 
 	for (i = 0; i < drm_res->count_connectors; i++)
 		drmModeFreeConnector(drm_connectors[i]);
tests/kms_frontbuffer_tracking.c +9 -11
index 780fecfe..14f522d8 100644
@@ -166,7 +166,7 @@ struct {
 	int debugfs;
 	igt_display_t display;
 
-	drm_intel_bufmgr *bufmgr;
+	struct buf_ops *bops;
 } drm;
 
 struct {
@@ -1091,7 +1091,7 @@ static void draw_rect(struct draw_pattern_info *pattern, struct fb_region *fb,
 {
 	struct rect rect = pattern->get_rect(fb, r);
 
-	igt_draw_rect_fb(drm.fd, drm.bufmgr, NULL, fb->fb, method,
+	igt_draw_rect_fb(drm.fd, drm.bops, 0, fb->fb, method,
 			 fb->x + rect.x, fb->y + rect.y,
 			 rect.w, rect.h, rect.color);
 
@@ -1117,7 +1117,7 @@ static void fill_fb_region(struct fb_region *region, enum color ecolor)
 {
 	uint32_t color = pick_color(region->fb, ecolor);
 
-	igt_draw_rect_fb(drm.fd, drm.bufmgr, NULL, region->fb, IGT_DRAW_BLT,
+	igt_draw_rect_fb(drm.fd, drm.bops, 0, region->fb, IGT_DRAW_BLT,
 			 region->x, region->y, region->w, region->h,
 			 color);
 }
@@ -1141,7 +1141,7 @@ static bool disable_features(const struct test_mode *t)
 static void *busy_thread_func(void *data)
 {
 	while (!busy_thread.stop)
-		igt_draw_rect(drm.fd, drm.bufmgr, NULL, busy_thread.handle,
+		igt_draw_rect(drm.fd, drm.bops, 0, busy_thread.handle,
 			      busy_thread.size, busy_thread.stride,
 			      busy_thread.tiling, IGT_DRAW_BLT, 0, 0,
 			      busy_thread.width, busy_thread.height,
@@ -1288,14 +1288,12 @@ static void setup_drm(void)
 	kmstest_set_vt_graphics_mode();
 	igt_display_require(&drm.display, drm.fd);
 
-	drm.bufmgr = drm_intel_bufmgr_gem_init(drm.fd, 4096);
-	igt_assert(drm.bufmgr);
-	drm_intel_bufmgr_gem_enable_reuse(drm.bufmgr);
+	drm.bops = buf_ops_create(drm.fd);
 }
 
 static void teardown_drm(void)
 {
-	drm_intel_bufmgr_destroy(drm.bufmgr);
+	buf_ops_destroy(drm.bops);
 	igt_display_fini(&drm.display);
 	close(drm.fd);
 }
@@ -2622,14 +2620,14 @@ static void scaledprimary_subtest(const struct test_mode *t)
 		  t->tiling, t->plane, &new_fb);
 	fill_fb(&new_fb, COLOR_BLUE);
 
-	igt_draw_rect_fb(drm.fd, drm.bufmgr, NULL, &new_fb, t->method,
+	igt_draw_rect_fb(drm.fd, drm.bops, 0, &new_fb, t->method,
 			 reg->x, reg->y, reg->w / 2, reg->h / 2,
 			 pick_color(&new_fb, COLOR_GREEN));
-	igt_draw_rect_fb(drm.fd, drm.bufmgr, NULL, &new_fb, t->method,
+	igt_draw_rect_fb(drm.fd, drm.bops, 0, &new_fb, t->method,
 			 reg->x + reg->w / 2, reg->y + reg->h / 2,
 			 reg->w / 2, reg->h / 2,
 			 pick_color(&new_fb, COLOR_RED));
-	igt_draw_rect_fb(drm.fd, drm.bufmgr, NULL, &new_fb, t->method,
+	igt_draw_rect_fb(drm.fd, drm.bops, 0, &new_fb, t->method,
 			 reg->x + reg->w / 2, reg->y + reg->h / 2,
 			 reg->w / 4, reg->h / 4,
 			 pick_color(&new_fb, COLOR_MAGENTA));
tests/kms_psr.c +74 -60

197 lines not on this page · raw message

Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#12 lore raw

PATCH v17 12/16 tests/gem|kms: remove libdrm dependency (batch 2)

In reply to Zbigniew Kempczyński

Use intel_bb / intel_buf to remove libdrm dependency.

Tests changed:
- gem_read_read_speed
- gem_render_copy
- gem_render_copy_redux
- gem_render_linear_blits
- gem_render_tiled_blits
- gem_stress
- kms_big_fb
- kms_cursor_crc

Remove transitional rendercopy_bufmgr, we don't need it anymore.

Cc Dominik Grzegorzek <[email protected]>
Cc Chris Wilson <[email protected]>
---
 lib/Makefile.sources                 |   2 -
 lib/meson.build                      |   1 -
 lib/rendercopy_bufmgr.c              | 171 ---------------
 lib/rendercopy_bufmgr.h              |  28 ---
 tests/i915/gem_read_read_speed.c     | 161 +++++++-------
 tests/i915/gem_render_copy.c         | 313 +++++++++++----------------
 tests/i915/gem_render_copy_redux.c   |  67 +++---
 tests/i915/gem_render_linear_blits.c |  90 +++-----
 tests/i915/gem_render_tiled_blits.c  |  93 ++++----
 tests/i915/gem_stress.c              | 244 +++++++++++----------
 tests/kms_big_fb.c                   |  54 +++--
 tests/kms_cursor_crc.c               |  63 +++---
 12 files changed, 506 insertions(+), 781 deletions(-)
 delete mode 100644 lib/rendercopy_bufmgr.c
 delete mode 100644 lib/rendercopy_bufmgr.h
lib/Makefile.sources +0 -2
index 464f5be2..67b38645 100644
@@ -107,8 +107,6 @@ lib_source_list =	 	\
 	gen7_render.h		\
 	gen8_render.h		\
 	gen9_render.h		\
-	rendercopy_bufmgr.c	\
-	rendercopy_bufmgr.h	\
 	rendercopy_gen4.c	\
 	rendercopy_gen6.c	\
 	rendercopy_gen7.c	\
lib/meson.build +0 -1
index 341696e5..f1f5f7ca 100644
@@ -45,7 +45,6 @@ lib_sources = [
 	'gpu_cmds.c',
 	'rendercopy_i915.c',
 	'rendercopy_i830.c',
-	'rendercopy_bufmgr.c',
 	'rendercopy_gen4.c',
 	'rendercopy_gen6.c',
 	'rendercopy_gen7.c',
lib/rendercopy_bufmgr.c deleted +0 -171

171 lines not on this page · raw message

lib/rendercopy_bufmgr.h deleted +0 -28
deleted file mode 100644
index f4e5118c..00000000
@@ -1,28 +0,0 @@
-#ifndef __RENDERCOPY_BUFMGR_H__
-#define __RENDERCOPY_BUFMGR_H__
-
-#include <stdint.h>
-#include "intel_bufops.h"
-#include "intel_batchbuffer.h"
-
-struct rendercopy_bufmgr;
-
-struct rendercopy_bufmgr *rendercopy_bufmgr_create(int fd,
-						   drm_intel_bufmgr *bufmgr);
-void rendercopy_bufmgr_destroy(struct rendercopy_bufmgr *bmgr);
-
-bool rendercopy_bufmgr_set_software_tiling(struct rendercopy_bufmgr *bmgr,
-					   uint32_t tiling,
-					   bool use_software_tiling);
-
-void igt_buf_to_linear(struct rendercopy_bufmgr *bmgr, struct igt_buf *buf,
-		       uint32_t *linear);
-
-void linear_to_igt_buf(struct rendercopy_bufmgr *bmgr, struct igt_buf *buf,
-		       uint32_t *linear);
-
-void igt_buf_init(struct rendercopy_bufmgr *bmgr, struct igt_buf *buf,
-		  int width, int height, int bpp,
-		  uint32_t tiling, uint32_t compression);
-
-#endif
tests/i915/gem_read_read_speed.c +82 -79

244 lines not on this page · raw message

tests/i915/gem_render_copy.c +123 -190

583 lines not on this page · raw message

tests/i915/gem_render_copy_redux.c +29 -38

154 lines not on this page · raw message

tests/i915/gem_render_linear_blits.c +32 -58

160 lines not on this page · raw message

tests/i915/gem_render_tiled_blits.c +47 -46

188 lines not on this page · raw message

tests/i915/gem_stress.c +129 -115

500 lines not on this page · raw message

tests/kms_big_fb.c +32 -22

103 lines not on this page · raw message

tests/kms_cursor_crc.c +32 -31

116 lines not on this page · raw message

Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#13 lore raw

PATCH v17 13/16 tools/intel_residency: adopt intel_residency to use bufops

In reply to Zbigniew Kempczyński

IGT draw functions remove libdrm dependency so migrate to new API.

Cc Dominik Grzegorzek <[email protected]>
Cc Chris Wilson <[email protected]>
---
 tools/intel_residency.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
tools/intel_residency.c +4 -6
index bfab40da..736fca0d 100644
@@ -82,7 +82,7 @@ struct {
 	int fd;
 	drmModeResPtr res;
 	drmModeConnectorPtr connectors[MAX_CONNECTORS];
-	drm_intel_bufmgr *bufmgr;
+	struct buf_ops *bops;
 } drm;
 
 struct {
@@ -191,16 +191,14 @@ static void setup_drm(void)
 		drm.connectors[i] = drmModeGetConnector(drm.fd,
 						drm.res->connectors[i]);
 
-	drm.bufmgr = drm_intel_bufmgr_gem_init(drm.fd, 4096);
-	igt_assert(drm.bufmgr);
-	drm_intel_bufmgr_gem_enable_reuse(drm.bufmgr);
+	drm.bops = buf_ops_create(drm.fd);
 }
 
 static void teardown_drm(void)
 {
 	int i;
 
-	drm_intel_bufmgr_destroy(drm.bufmgr);
+	buf_ops_destroy(drm.bops);
 
 	for (i = 0; i < drm.res->count_connectors; i++)
 		drmModeFreeConnector(drm.connectors[i]);
@@ -238,7 +236,7 @@ static void draw_rect(struct igt_fb *fb, enum igt_draw_method method,
 		igt_assert(false);
 	}
 
-	igt_draw_rect_fb(drm.fd, drm.bufmgr, NULL, fb, method, clip.x1, clip.y1,
+	igt_draw_rect_fb(drm.fd, drm.bops, 0, fb, method, clip.x1, clip.y1,
 			 clip.x2 - clip.x1, clip.y2 - clip.y1, color);
 
 	if (method == IGT_DRAW_MMAP_WC) {
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#14 lore raw

PATCH v17 14/16 tests/perf: remove libdrm dependency for rendercopy

In reply to Zbigniew Kempczyński

Rendercopy now uses no-drm version so all users has to migrate to new interface.

Cc Lionel Landwerlin <[email protected]>
Cc Dominik Grzegorzek <[email protected]>
Cc Chris Wilson <[email protected]>
---
 tests/i915/perf.c | 655 +++++++++++++++++++---------------------------
 1 file changed, 273 insertions(+), 382 deletions(-)
tests/i915/perf.c +273 -382
index 92edc9f1..401fe72f 100644
@@ -497,64 +497,42 @@ oa_report_get_ctx_id(uint32_t *report)
 }
 
 static void
-scratch_buf_memset(drm_intel_bo *bo, int width, int height, uint32_t color)
+scratch_buf_memset(struct intel_buf *buf, int width, int height, uint32_t color)
 {
-	int ret;
-
-	ret = drm_intel_bo_map(bo, true /* writable */);
-	igt_assert_eq(ret, 0);
+	intel_buf_cpu_map(buf, true);
 
 	for (int i = 0; i < width * height; i++)
-		((uint32_t *)bo->virtual)[i] = color;
+		buf->ptr[i] = color;
 
-	drm_intel_bo_unmap(bo);
+	intel_buf_unmap(buf);
 }
 
 static void
-scratch_buf_init(drm_intel_bufmgr *bufmgr,
-		 struct igt_buf *buf,
+scratch_buf_init(struct buf_ops *bops,
+		 struct intel_buf *buf,
 		 int width, int height,
 		 uint32_t color)
 {
-	size_t stride = width * 4;
-	size_t size = stride * height;
-	drm_intel_bo *bo = drm_intel_bo_alloc(bufmgr, "", size, 4096);
-
-	scratch_buf_memset(bo, width, height, color);
-
-	memset(buf, 0, sizeof(*buf));
-
-	buf->bo = bo;
-	buf->surface[0].stride = stride;
-	buf->tiling = I915_TILING_NONE;
-	buf->surface[0].size = size;
-	buf->bpp = 32;
+	intel_buf_init(bops, buf, width, height, 32, 0,
+		       I915_TILING_NONE, I915_COMPRESSION_NONE);
+	scratch_buf_memset(buf, width, height, color);
 }
 
 static void
-emit_report_perf_count(struct intel_batchbuffer *batch,
-		       drm_intel_bo *dst_bo,
+emit_report_perf_count(struct intel_bb *ibb,
+		       struct intel_buf *dst,
 		       int dst_offset,
 		       uint32_t report_id)
 {
-	if (IS_HASWELL(devid)) {
-		BEGIN_BATCH(3, 1);
-		OUT_BATCH(GEN6_MI_REPORT_PERF_COUNT);
-		OUT_RELOC(dst_bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
-			  dst_offset);
-		OUT_BATCH(report_id);
-		ADVANCE_BATCH();
-	} else {
-		/* XXX: NB: n dwords arg is actually magic since it internally
-		 * automatically accounts for larger addresses on gen >= 8...
-		 */
-		BEGIN_BATCH(3, 1);
-		OUT_BATCH(GEN8_MI_REPORT_PERF_COUNT);
-		OUT_RELOC(dst_bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
-			  dst_offset);
-		OUT_BATCH(report_id);
-		ADVANCE_BATCH();
-	}
+	if (IS_HASWELL(devid))
+		intel_bb_out(ibb, GEN6_MI_REPORT_PERF_COUNT);
+	else
+		intel_bb_out(ibb, GEN8_MI_REPORT_PERF_COUNT);
+
+	intel_bb_emit_reloc(ibb, dst->handle,
+			    I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
+			    dst_offset, dst->addr.offset);
+	intel_bb_out(ibb, report_id);
 }
 
 static void
@@ -1495,14 +1473,13 @@ enum load {
 
 static struct load_helper {
 	int devid;
-	drm_intel_bufmgr *bufmgr;
-	drm_intel_context *context;
+	struct buf_ops *bops;
 	uint32_t context_id;
-	struct intel_batchbuffer *batch;
+	struct intel_bb *ibb;
 	enum load load;
 	bool exit;
 	struct igt_helper_process igt_proc;
-	struct igt_buf src, dst;
+	struct intel_buf src, dst;
 } lh = { 0, };
 
 static void load_helper_signal_handler(int sig)
@@ -1542,21 +1519,12 @@ static void load_helper_run(enum load load)
 		signal(SIGUSR2, load_helper_signal_handler);
 
 		while (!lh.exit) {
-			int ret;
-
-			render_copy(lh.batch,
-				    lh.context,
+			render_copy(lh.ibb,
+				    lh.context_id,
 				    &lh.src, 0, 0, 1920, 1080,
 				    &lh.dst, 0, 0);
 
-			intel_batchbuffer_flush_with_context(lh.batch,
-							     lh.context);
-
-			ret = drm_intel_gem_context_get_id(lh.context,
-							   &lh.context_id);
-			igt_assert_eq(ret, 0);
-
-			drm_intel_bo_wait_rendering(lh.dst.bo);
+			intel_bb_sync(lh.ibb);
 
 			/* Lower the load by pausing after every submitted
 			 * write. */
@@ -1574,52 +1542,36 @@ static void load_helper_stop(void)
 
 static void load_helper_init(void)
 {
-	int ret;
-
 	lh.devid = intel_get_drm_devid(drm_fd);
 
 	/* MI_STORE_DATA can only use GTT address on gen4+/g33 and needs
 	 * snoopable mem on pre-gen6. Hence load-helper only works on gen6+, but
 	 * that's also all we care about for the rps testcase*/
 	igt_assert(intel_gen(lh.devid) >= 6);
-	lh.bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
-	igt_assert(lh.bufmgr);
-
-	drm_intel_bufmgr_gem_enable_reuse(lh.bufmgr);
 
-	lh.context = drm_intel_gem_context_create(lh.bufmgr);
-	igt_assert(lh.context);
+	lh.bops = buf_ops_create(drm_fd);
 
-	lh.context_id = 0xffffffff;
-	ret = drm_intel_gem_context_get_id(lh.context, &lh.context_id);
-	igt_assert_eq(ret, 0);
+	lh.context_id = gem_context_create(drm_fd);
 	igt_assert_neq(lh.context_id, 0xffffffff);
 
-	lh.batch = intel_batchbuffer_alloc(lh.bufmgr, lh.devid);
-	igt_assert(lh.batch);
+	lh.ibb = intel_bb_create(drm_fd, BATCH_SZ);
 
-	scratch_buf_init(lh.bufmgr, &lh.dst, 1920, 1080, 0);
-	scratch_buf_init(lh.bufmgr, &lh.src, 1920, 1080, 0);
+	scratch_buf_init(lh.bops, &lh.dst, 1920, 1080, 0);
+	scratch_buf_init(lh.bops, &lh.src, 1920, 1080, 0);
 }
 
 static void load_helper_fini(void)
 {
+	int i915 = buf_ops_get_fd(lh.bops);
+
 	if (lh.igt_proc.running)
 		load_helper_stop();
 
-	if (lh.src.bo)
-		drm_intel_bo_unreference(lh.src.bo);
-	if (lh.dst.bo)
-		drm_intel_bo_unreference(lh.dst.bo);
-
-	if (lh.batch)
-		intel_batchbuffer_free(lh.batch);
-
-	if (lh.context)
-		drm_intel_gem_context_destroy(lh.context);
-
-	if (lh.bufmgr)
-		drm_intel_bufmgr_destroy(lh.bufmgr);
+	intel_buf_close(lh.bops, &lh.src);
+	intel_buf_close(lh.bops, &lh.dst);
+	intel_bb_destroy(lh.ibb);
+	gem_context_destroy(i915, lh.context_id);
+	buf_ops_destroy(lh.bops);
 }
 
 static bool expected_report_timing_delta(uint32_t delta, uint32_t expected_delta)
@@ -1888,20 +1840,11 @@ test_per_context_mode_unprivileged(void)
 	write_u64_file("/proc/sys/dev/i915/perf_stream_paranoid", 1);
 
 	igt_fork(child, 1) {
-		drm_intel_context *context;
-		drm_intel_bufmgr *bufmgr;
 		uint32_t ctx_id = 0xffffffff; /* invalid id */
-		int ret;
 
 		igt_drop_root();
 
-		bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
-		context = drm_intel_gem_context_create(bufmgr);
-
-		igt_assert(context);
-
-		ret = drm_intel_gem_context_get_id(context, &ctx_id);
-		igt_assert_eq(ret, 0);
+		ctx_id = gem_context_create(drm_fd);
 		igt_assert_neq(ctx_id, 0xffffffff);
 
 		properties[1] = ctx_id;
@@ -1909,8 +1852,7 @@ test_per_context_mode_unprivileged(void)
 		stream_fd = __perf_open(drm_fd, &param, false);
 		__perf_close(stream_fd);
 
-		drm_intel_gem_context_destroy(context);
-		drm_intel_bufmgr_destroy(bufmgr);
+		gem_context_destroy(drm_fd, ctx_id);
 	}
 
 	igt_waitchildren();
@@ -2936,55 +2878,44 @@ gen12_test_mi_rpc(void)
 		.num_properties = ARRAY_SIZE(properties) / 2,
 		.properties_ptr = to_user_pointer(properties),
 	};
-	drm_intel_bo *bo;
-	drm_intel_bufmgr *bufmgr;
-	drm_intel_context *context;
-	struct intel_batchbuffer *batch;
+	struct buf_ops *bops;
+	struct intel_bb *ibb;
+	struct intel_buf *buf;
 #define INVALID_CTX_ID 0xffffffff
 	uint32_t ctx_id = INVALID_CTX_ID;
 	uint32_t *report32;
-	int ret;
 	size_t format_size_32;
 	struct oa_format format = get_oa_format(test_set->perf_oa_format);
 
 	/* Ensure perf_stream_paranoid is set to 1 by default */
 	write_u64_file("/proc/sys/dev/i915/perf_stream_paranoid", 1);
 
-	bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
-	igt_assert(bufmgr);
-
-	drm_intel_bufmgr_gem_enable_reuse(bufmgr);
-
-	context = drm_intel_gem_context_create(bufmgr);
-	igt_assert(context);
-
-	ret = drm_intel_gem_context_get_id(context, &ctx_id);
-	igt_assert_eq(ret, 0);
+	bops = buf_ops_create(drm_fd);
+	ctx_id = gem_context_create(drm_fd);
 	igt_assert_neq(ctx_id, INVALID_CTX_ID);
 	properties[1] = ctx_id;
 
-	batch = intel_batchbuffer_alloc(bufmgr, devid);
-	bo = drm_intel_bo_alloc(bufmgr, "mi_rpc dest bo", 4096, 64);
+	ibb = intel_bb_create(drm_fd, BATCH_SZ);
+	buf = intel_buf_create(bops, 4096, 1, 8, 64,
+			       I915_TILING_NONE, I915_COMPRESSION_NONE);
 
-	ret = drm_intel_bo_map(bo, true);
-	igt_assert_eq(ret, 0);
-	memset(bo->virtual, 0x80, 4096);
-	drm_intel_bo_unmap(bo);
+	intel_buf_cpu_map(buf, true);
+	memset(buf->ptr, 0x80, 4096);
+	intel_buf_unmap(buf);
 
 	stream_fd = __perf_open(drm_fd, &param, false);
 
 #define REPORT_ID 0xdeadbeef
 #define REPORT_OFFSET 0
-	emit_report_perf_count(batch,
-			       bo,
+	emit_report_perf_count(ibb,
+			       buf,
 			       REPORT_OFFSET,
 			       REPORT_ID);
-	intel_batchbuffer_flush_with_context(batch, context);
-
-	ret = drm_intel_bo_map(bo, false);
-	igt_assert_eq(ret, 0);
+	intel_bb_flush_render_with_context(ibb, ctx_id);
+	intel_bb_sync(ibb);
 
-	report32 = bo->virtual;
+	intel_buf_cpu_map(buf, false);
+	report32 = buf->ptr;
 	format_size_32 = format.size >> 2;
 	dump_report(report32, format_size_32, "mi-rpc");
 
@@ -3006,11 +2937,11 @@ gen12_test_mi_rpc(void)
 	igt_assert_neq(report32[format.b_off >> 2], 0x80808080);
 	igt_assert_eq(report32[format_size_32], 0x80808080);
 
-	drm_intel_bo_unmap(bo);
-	drm_intel_bo_unreference(bo);
-	intel_batchbuffer_free(batch);
-	drm_intel_gem_context_destroy(context);
-	drm_intel_bufmgr_destroy(bufmgr);
+	intel_buf_unmap(buf);
+	intel_buf_destroy(buf);
+	intel_bb_destroy(ibb);
+	gem_context_destroy(drm_fd, ctx_id);
+	buf_ops_destroy(bops);
 	__perf_close(stream_fd);
 }
 
@@ -3034,41 +2965,33 @@ test_mi_rpc(void)
 		.num_properties = sizeof(properties) / 16,
 		.properties_ptr = to_user_pointer(properties),
 	};
-	drm_intel_bufmgr *bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
-	drm_intel_context *context;
-	struct intel_batchbuffer *batch;
-	drm_intel_bo *bo;
-	uint32_t *report32;
-	int ret;
+	struct buf_ops *bops = buf_ops_create(drm_fd);
+	struct intel_bb *ibb;
+	struct intel_buf *buf;
+	uint32_t *report32, ctx_id;
 
 	stream_fd = __perf_open(drm_fd, &param, false);
 
-	drm_intel_bufmgr_gem_enable_reuse(bufmgr);
-
-	context = drm_intel_gem_context_create(bufmgr);
-	igt_assert(context);
+	ctx_id = gem_context_create(drm_fd);
 
-	batch = intel_batchbuffer_alloc(bufmgr, devid);
+	ibb = intel_bb_create(drm_fd, BATCH_SZ);
+	buf = intel_buf_create(bops, 4096, 1, 8, 64,
+			       I915_TILING_NONE, I915_COMPRESSION_NONE);
 
-	bo = drm_intel_bo_alloc(bufmgr, "mi_rpc dest bo", 4096, 64);
-
-	ret = drm_intel_bo_map(bo, true);
-	igt_assert_eq(ret, 0);
+	intel_buf_cpu_map(buf, true);
+	memset(buf->ptr, 0x80, 4096);
+	intel_buf_unmap(buf);
 
-	memset(bo->virtual, 0x80, 4096);
-	drm_intel_bo_unmap(bo);
-
-	emit_report_perf_count(batch,
-			       bo, /* dst */
+	emit_report_perf_count(ibb,
+			       buf, /* dst */
 			       0, /* dst offset in bytes */
 			       0xdeadbeef); /* report ID */
 
-	intel_batchbuffer_flush_with_context(batch, context);
-
-	ret = drm_intel_bo_map(bo, false /* write enable */);
-	igt_assert_eq(ret, 0);
+	intel_bb_flush_render_with_context(ibb, ctx_id);
+	intel_bb_sync(ibb);
 
-	report32 = bo->virtual;
+	intel_buf_cpu_map(buf, false);
+	report32 = buf->ptr;
 	dump_report(report32, 64, "mi-rpc");
 	igt_assert_eq(report32[0], 0xdeadbeef); /* report ID */
 	igt_assert_neq(report32[1], 0); /* timestamp */
@@ -3076,17 +2999,17 @@ test_mi_rpc(void)
 	igt_assert_neq(report32[63], 0x80808080); /* end of report */
 	igt_assert_eq(report32[64], 0x80808080); /* after 256 byte report */
 
-	drm_intel_bo_unmap(bo);
-	drm_intel_bo_unreference(bo);
-	intel_batchbuffer_free(batch);
-	drm_intel_gem_context_destroy(context);
-	drm_intel_bufmgr_destroy(bufmgr);
+	intel_buf_unmap(buf);
+	intel_buf_destroy(buf);
+	intel_bb_destroy(ibb);
+	gem_context_destroy(drm_fd, ctx_id);
+	buf_ops_destroy(bops);
 	__perf_close(stream_fd);
 }
 
 static void
-emit_stall_timestamp_and_rpc(struct intel_batchbuffer *batch,
-			     drm_intel_bo *dst,
+emit_stall_timestamp_and_rpc(struct intel_bb *ibb,
+			     struct intel_buf *dst,
 			     int timestamp_offset,
 			     int report_dst_offset,
 			     uint32_t report_id)
@@ -3095,27 +3018,19 @@ emit_stall_timestamp_and_rpc(struct intel_batchbuffer *batch,
 				   PIPE_CONTROL_RENDER_TARGET_FLUSH |
 				   PIPE_CONTROL_WRITE_TIMESTAMP);
 
-	if (intel_gen(devid) >= 8) {
-		BEGIN_BATCH(5, 1);
-		OUT_BATCH(GFX_OP_PIPE_CONTROL | (6 - 2));
-		OUT_BATCH(pipe_ctl_flags);
-		OUT_RELOC(dst, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
-			  timestamp_offset);
-		OUT_BATCH(0); /* imm lower */
-		OUT_BATCH(0); /* imm upper */
-		ADVANCE_BATCH();
-	} else {
-		BEGIN_BATCH(5, 1);
-		OUT_BATCH(GFX_OP_PIPE_CONTROL | (5 - 2));
-		OUT_BATCH(pipe_ctl_flags);
-		OUT_RELOC(dst, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
-			  timestamp_offset);
-		OUT_BATCH(0); /* imm lower */
-		OUT_BATCH(0); /* imm upper */
-		ADVANCE_BATCH();
-	}
+	if (intel_gen(devid) >= 8)
+		intel_bb_out(ibb, GFX_OP_PIPE_CONTROL | (6 - 2));
+	else
+		intel_bb_out(ibb, GFX_OP_PIPE_CONTROL | (5 - 2));
 
-	emit_report_perf_count(batch, dst, report_dst_offset, report_id);
+	intel_bb_out(ibb, pipe_ctl_flags);
+	intel_bb_emit_reloc(ibb, dst->handle,
+			    I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
+			    timestamp_offset, dst->addr.offset);
+	intel_bb_out(ibb, 0); /* imm lower */
+	intel_bb_out(ibb, 0); /* imm upper */
+
+	emit_report_perf_count(ibb, dst, report_dst_offset, report_id);
 }
 
 /* Tests the INTEL_performance_query use case where an unprivileged process
@@ -3156,11 +3071,10 @@ hsw_test_single_ctx_counters(void)
 	write_u64_file("/proc/sys/dev/i915/perf_stream_paranoid", 1);
 
 	igt_fork(child, 1) {
-		drm_intel_bufmgr *bufmgr;
-		drm_intel_context *context0, *context1;
-		struct intel_batchbuffer *batch;
-		struct igt_buf src[3], dst[3];
-		drm_intel_bo *bo;
+		struct buf_ops *bops;
+		struct intel_buf src[3], dst[3], *dst_buf;
+		struct intel_bb *ibb0, *ibb1;
+		uint32_t context0_id, context1_id;
 		uint32_t *report0_32, *report1_32;
 		uint64_t timestamp0_64, timestamp1_64;
 		uint32_t delta_ts64, delta_oa32;
@@ -3169,26 +3083,24 @@ hsw_test_single_ctx_counters(void)
 		int n_samples_written;
 		int width = 800;
 		int height = 600;
-		uint32_t ctx_id = 0xffffffff; /* invalid id */
-		int ret;
 
 		igt_drop_root();
 
-		bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
-		drm_intel_bufmgr_gem_enable_reuse(bufmgr);
+		bops = buf_ops_create(drm_fd);
 
 		for (int i = 0; i < ARRAY_SIZE(src); i++) {
-			scratch_buf_init(bufmgr, &src[i], width, height, 0xff0000ff);
-			scratch_buf_init(bufmgr, &dst[i], width, height, 0x00ff00ff);
+			scratch_buf_init(bops, &src[i], width, height, 0xff0000ff);
+			scratch_buf_init(bops, &dst[i], width, height, 0x00ff00ff);
 		}
 
-		batch = intel_batchbuffer_alloc(bufmgr, devid);
-
-		context0 = drm_intel_gem_context_create(bufmgr);
-		igt_assert(context0);
-
-		context1 = drm_intel_gem_context_create(bufmgr);
-		igt_assert(context1);
+		/*
+		 * We currently cache addresses for buffers within
+		 * intel_bb, so use separate batches for different contexts
+		 */
+		ibb0 = intel_bb_create(drm_fd, BATCH_SZ);
+		ibb1 = intel_bb_create(drm_fd, BATCH_SZ);
+		context0_id = gem_context_create(drm_fd);
+		context1_id = gem_context_create(drm_fd);
 
 		igt_debug("submitting warm up render_copy\n");
 
@@ -3212,34 +3124,32 @@ hsw_test_single_ctx_counters(void)
 		 * up pinning the context since there won't ever be a pinning
 		 * hook callback.
 		 */
-		render_copy(batch,
-			    context0,
+		render_copy(ibb0,
+			    context0_id,
 			    &src[0], 0, 0, width, height,
 			    &dst[0], 0, 0);
 
-		ret = drm_intel_gem_context_get_id(context0, &ctx_id);
-		igt_assert_eq(ret, 0);
-		igt_assert_neq(ctx_id, 0xffffffff);
-		properties[1] = ctx_id;
+		properties[1] = context0_id;
 
-		intel_batchbuffer_flush_with_context(batch, context0);
+		intel_bb_flush_render_with_context(ibb0, context0_id);
+		intel_bb_sync(ibb0);
 
-		scratch_buf_memset(src[0].bo, width, height, 0xff0000ff);
-		scratch_buf_memset(dst[0].bo, width, height, 0x00ff00ff);
+		scratch_buf_memset(&src[0], width, height, 0xff0000ff);
+		scratch_buf_memset(&dst[0], width, height, 0x00ff00ff);
 
 		igt_debug("opening i915-perf stream\n");
 		stream_fd = __perf_open(drm_fd, &param, false);
 
-		bo = drm_intel_bo_alloc(bufmgr, "mi_rpc dest bo", 4096, 64);
+		dst_buf = intel_buf_create(bops, 4096, 1, 8, 64,
+					   I915_TILING_NONE,
+					   I915_COMPRESSION_NONE);
 
-		ret = drm_intel_bo_map(bo, true /* write enable */);
-		igt_assert_eq(ret, 0);
+		intel_buf_cpu_map(dst_buf, true /* write enable */);
+		memset(dst_buf->ptr, 0x80, 4096);
+		intel_buf_unmap(dst_buf);
 
-		memset(bo->virtual, 0x80, 4096);
-		drm_intel_bo_unmap(bo);
-
-		emit_stall_timestamp_and_rpc(batch,
-					     bo,
+		emit_stall_timestamp_and_rpc(ibb0,
+					     dst_buf,
 					     512 /* timestamp offset */,
 					     0, /* report dst offset */
 					     0xdeadbeef); /* report id */
@@ -3249,45 +3159,45 @@ hsw_test_single_ctx_counters(void)
 		 * that the PIPE_CONTROL + MI_RPC commands will be in a
 		 * separate batch from the copy.
 		 */
-		intel_batchbuffer_flush_with_context(batch, context0);
+		intel_bb_flush_render_with_context(ibb0, context0_id);
 
-		render_copy(batch,
-			    context0,
+		render_copy(ibb0,
+			    context0_id,
 			    &src[0], 0, 0, width, height,
 			    &dst[0], 0, 0);
 
 		/* Another redundant flush to clarify batch bo is free to reuse */
-		intel_batchbuffer_flush_with_context(batch, context0);
+		intel_bb_flush_render_with_context(ibb0, context0_id);
 
 		/* submit two copies on the other context to avoid a false
 		 * positive in case the driver somehow ended up filtering for
 		 * context1
 		 */
-		render_copy(batch,
-			    context1,
+		render_copy(ibb1,
+			    context1_id,
 			    &src[1], 0, 0, width, height,
 			    &dst[1], 0, 0);
 
-		render_copy(batch,
-			    context1,
+		render_copy(ibb1,
+			    context1_id,
 			    &src[2], 0, 0, width, height,
 			    &dst[2], 0, 0);
 
 		/* And another */
-		intel_batchbuffer_flush_with_context(batch, context1);
+		intel_bb_flush_render_with_context(ibb1, context1_id);
 
-		emit_stall_timestamp_and_rpc(batch,
-					     bo,
+		emit_stall_timestamp_and_rpc(ibb0,
+					     dst_buf,
 					     520 /* timestamp offset */,
 					     256, /* report dst offset */
 					     0xbeefbeef); /* report id */
 
-		intel_batchbuffer_flush_with_context(batch, context0);
+		intel_bb_flush_render_with_context(ibb0, context0_id);
+		intel_bb_sync(ibb0);
 
-		ret = drm_intel_bo_map(bo, false /* write enable */);
-		igt_assert_eq(ret, 0);
+		intel_buf_cpu_map(dst_buf, false /* write enable */);
 
-		report0_32 = bo->virtual;
+		report0_32 = dst_buf->ptr;
 		igt_assert_eq(report0_32[0], 0xdeadbeef); /* report ID */
 		igt_assert_neq(report0_32[1], 0); /* timestamp */
 
@@ -3307,8 +3217,8 @@ hsw_test_single_ctx_counters(void)
 		igt_debug("timestamp32 0 = %u\n", report0_32[1]);
 		igt_debug("timestamp32 1 = %u\n", report1_32[1]);
 
-		timestamp0_64 = *(uint64_t *)(((uint8_t *)bo->virtual) + 512);
-		timestamp1_64 = *(uint64_t *)(((uint8_t *)bo->virtual) + 520);
+		timestamp0_64 = *(uint64_t *)(((uint8_t *)dst_buf->ptr) + 512);
+		timestamp1_64 = *(uint64_t *)(((uint8_t *)dst_buf->ptr) + 520);
 
 		igt_debug("timestamp64 0 = %"PRIu64"\n", timestamp0_64);
 		igt_debug("timestamp64 1 = %"PRIu64"\n", timestamp1_64);
@@ -3336,16 +3246,17 @@ hsw_test_single_ctx_counters(void)
 		igt_assert(delta_delta <= 320);
 
 		for (int i = 0; i < ARRAY_SIZE(src); i++) {
-			drm_intel_bo_unreference(src[i].bo);
-			drm_intel_bo_unreference(dst[i].bo);
+			intel_buf_close(bops, &src[i]);
+			intel_buf_close(bops, &dst[i]);
 		}
 
-		drm_intel_bo_unmap(bo);
-		drm_intel_bo_unreference(bo);
-		intel_batchbuffer_free(batch);
-		drm_intel_gem_context_destroy(context0);
-		drm_intel_gem_context_destroy(context1);
-		drm_intel_bufmgr_destroy(bufmgr);
+		intel_buf_unmap(dst_buf);
+		intel_buf_destroy(dst_buf);
+		intel_bb_destroy(ibb0);
+		intel_bb_destroy(ibb1);
+		gem_context_destroy(drm_fd, context0_id);
+		gem_context_destroy(drm_fd, context1_id);
+		buf_ops_destroy(bops);
 		__perf_close(stream_fd);
 	}
 
@@ -3406,11 +3317,10 @@ gen8_test_single_ctx_render_target_writes_a_counter(void)
 
 		igt_fork_helper(&child) {
 			struct drm_i915_perf_record_header *header;
-			drm_intel_bufmgr *bufmgr;
-			drm_intel_context *context0, *context1;
-			struct intel_batchbuffer *batch;
-			struct igt_buf src[3], dst[3];
-			drm_intel_bo *bo;
+			struct buf_ops *bops;
+			struct intel_bb *ibb0, *ibb1;
+			struct intel_buf src[3], dst[3], *dst_buf;
+			uint32_t context0_id, context1_id;
 			uint32_t *report0_32, *report1_32;
 			uint32_t *prev, *lprev = NULL;
 			uint64_t timestamp0_64, timestamp1_64;
@@ -3428,21 +3338,17 @@ gen8_test_single_ctx_render_target_writes_a_counter(void)
 				.format = test_set->perf_oa_format
 			};
 
-			bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
-			drm_intel_bufmgr_gem_enable_reuse(bufmgr);
+			bops = buf_ops_create(drm_fd);
 
 			for (int i = 0; i < ARRAY_SIZE(src); i++) {
-				scratch_buf_init(bufmgr, &src[i], width, height, 0xff0000ff);
-				scratch_buf_init(bufmgr, &dst[i], width, height, 0x00ff00ff);
+				scratch_buf_init(bops, &src[i], width, height, 0xff0000ff);
+				scratch_buf_init(bops, &dst[i], width, height, 0x00ff00ff);
 			}
 
-			batch = intel_batchbuffer_alloc(bufmgr, devid);
-
-			context0 = drm_intel_gem_context_create(bufmgr);
-			igt_assert(context0);
-
-			context1 = drm_intel_gem_context_create(bufmgr);
-			igt_assert(context1);
+			ibb0 = intel_bb_create(drm_fd, BATCH_SZ);
+			ibb1 = intel_bb_create(drm_fd, BATCH_SZ);
+			context0_id = gem_context_create(drm_fd);
+			context1_id = gem_context_create(drm_fd);
 
 			igt_debug("submitting warm up render_copy\n");
 
@@ -3466,32 +3372,30 @@ gen8_test_single_ctx_render_target_writes_a_counter(void)
 			 * up pinning the context since there won't ever be a pinning
 			 * hook callback.
 			 */
-			render_copy(batch,
-				    context0,
+			render_copy(ibb0,
+				    context0_id,
 				    &src[0], 0, 0, width, height,
 				    &dst[0], 0, 0);
+			intel_bb_sync(ibb0);
 
-			ret = drm_intel_gem_context_get_id(context0, &ctx_id);
-			igt_assert_eq(ret, 0);
-			igt_assert_neq(ctx_id, 0xffffffff);
-			properties[1] = ctx_id;
+			properties[1] = context0_id;
 
-			scratch_buf_memset(src[0].bo, width, height, 0xff0000ff);
-			scratch_buf_memset(dst[0].bo, width, height, 0x00ff00ff);
+			scratch_buf_memset(&src[0], width, height, 0xff0000ff);
+			scratch_buf_memset(&dst[0], width, height, 0x00ff00ff);
 
 			igt_debug("opening i915-perf stream\n");
 			stream_fd = __perf_open(drm_fd, &param, false);
 
-			bo = drm_intel_bo_alloc(bufmgr, "mi_rpc dest bo", 4096, 64);
-
-			ret = drm_intel_bo_map(bo, true /* write enable */);
-			igt_assert_eq(ret, 0);
+			dst_buf = intel_buf_create(bops, 4096, 1, 8, 64,
+						   I915_TILING_NONE,
+						   I915_COMPRESSION_NONE);
 
-			memset(bo->virtual, 0x80, 4096);
-			drm_intel_bo_unmap(bo);
+			intel_buf_cpu_map(dst_buf, true /* write enable */);
+			memset(dst_buf->ptr, 0x80, 4096);
+			intel_buf_unmap(dst_buf);
 
-			emit_stall_timestamp_and_rpc(batch,
-						     bo,
+			emit_stall_timestamp_and_rpc(ibb0,
+						     dst_buf,
 						     512 /* timestamp offset */,
 						     0, /* report dst offset */
 						     0xdeadbeef); /* report id */
@@ -3501,49 +3405,46 @@ gen8_test_single_ctx_render_target_writes_a_counter(void)
 			 * that the PIPE_CONTROL + MI_RPC commands will be in a
 			 * separate batch from the copy.
 			 */
-			intel_batchbuffer_flush_with_context(batch, context0);
+			intel_bb_flush_render_with_context(ibb0, context0_id);
 
-			render_copy(batch,
-				    context0,
+			render_copy(ibb0,
+				    context0_id,
 				    &src[0], 0, 0, width, height,
 				    &dst[0], 0, 0);
 
 			/* Another redundant flush to clarify batch bo is free to reuse */
-			intel_batchbuffer_flush_with_context(batch, context0);
+			intel_bb_flush_render_with_context(ibb0, context0_id);
 
 			/* submit two copies on the other context to avoid a false
 			 * positive in case the driver somehow ended up filtering for
 			 * context1
 			 */
-			render_copy(batch,
-				    context1,
+			render_copy(ibb1,
+				    context1_id,
 				    &src[1], 0, 0, width, height,
 				    &dst[1], 0, 0);
 
-			ret = drm_intel_gem_context_get_id(context1, &ctx1_id);
-			igt_assert_eq(ret, 0);
-			igt_assert_neq(ctx1_id, 0xffffffff);
-
-			render_copy(batch,
-				    context1,
+			render_copy(ibb1,
+				    context1_id,
 				    &src[2], 0, 0, width, height,
 				    &dst[2], 0, 0);
 
 			/* And another */
-			intel_batchbuffer_flush_with_context(batch, context1);
+			intel_bb_flush_render_with_context(ibb1, context1_id);
 
-			emit_stall_timestamp_and_rpc(batch,
-						     bo,
+			emit_stall_timestamp_and_rpc(ibb1,
+						     dst_buf,
 						     520 /* timestamp offset */,
 						     256, /* report dst offset */
 						     0xbeefbeef); /* report id */
 
-			intel_batchbuffer_flush_with_context(batch, context1);
+			intel_bb_flush_render_with_context(ibb1, context1_id);
+			intel_bb_sync(ibb1);
+			intel_bb_sync(ibb0);
 
-			ret = drm_intel_bo_map(bo, false /* write enable */);
-			igt_assert_eq(ret, 0);
+			intel_buf_cpu_map(dst_buf, false /* write enable */);
 
-			report0_32 = bo->virtual;
+			report0_32 = dst_buf->ptr;
 			igt_assert_eq(report0_32[0], 0xdeadbeef); /* report ID */
 			igt_assert_neq(report0_32[1], 0); /* timestamp */
 			prev = report0_32;
@@ -3555,6 +3456,7 @@ gen8_test_single_ctx_render_target_writes_a_counter(void)
 			igt_assert_eq(report1_32[0], 0xbeefbeef); /* report ID */
 			igt_assert_neq(report1_32[1], 0); /* timestamp */
 			ctx1_id = report1_32[2];
+			igt_debug("CTX1 ID: %u\n", ctx1_id);
 			dump_report(report1_32, 64, "report1_32");
 
 			memset(accumulator.deltas, 0, sizeof(accumulator.deltas));
@@ -3569,8 +3471,8 @@ gen8_test_single_ctx_render_target_writes_a_counter(void)
 			igt_debug("ctx_id 0 = %u\n", report0_32[2]);
 			igt_debug("ctx_id 1 = %u\n", report1_32[2]);
 
-			timestamp0_64 = *(uint64_t *)(((uint8_t *)bo->virtual) + 512);
-			timestamp1_64 = *(uint64_t *)(((uint8_t *)bo->virtual) + 520);
+			timestamp0_64 = *(uint64_t *)(((uint8_t *)dst_buf->ptr) + 512);
+			timestamp1_64 = *(uint64_t *)(((uint8_t *)dst_buf->ptr) + 520);
 
 			igt_debug("ts_timestamp64 0 = %"PRIu64"\n", timestamp0_64);
 			igt_debug("ts_timestamp64 1 = %"PRIu64"\n", timestamp1_64);
@@ -3758,27 +3660,26 @@ gen8_test_single_ctx_render_target_writes_a_counter(void)
 				  width, height);
 			accumulator_print(&accumulator, "filtered");
 
-			ret = drm_intel_bo_map(src[0].bo, false /* write enable */);
-			igt_assert_eq(ret, 0);
-			ret = drm_intel_bo_map(dst[0].bo, false /* write enable */);
-			igt_assert_eq(ret, 0);
+			intel_buf_cpu_map(&src[0], false /* write enable */);
+			intel_buf_cpu_map(&dst[0], false /* write enable */);
 
-			ret = memcmp(src[0].bo->virtual, dst[0].bo->virtual, 4 * width * height);
-			drm_intel_bo_unmap(src[0].bo);
-			drm_intel_bo_unmap(dst[0].bo);
+			ret = memcmp(src[0].ptr, dst[0].ptr, 4 * width * height);
+			intel_buf_unmap(&src[0]);
+			intel_buf_unmap(&dst[0]);
 
 again:
 			for (int i = 0; i < ARRAY_SIZE(src); i++) {
-				drm_intel_bo_unreference(src[i].bo);
-				drm_intel_bo_unreference(dst[i].bo);
+				intel_buf_close(bops, &src[i]);
+				intel_buf_close(bops, &dst[i]);
 			}
 
-			drm_intel_bo_unmap(bo);
-			drm_intel_bo_unreference(bo);
-			intel_batchbuffer_free(batch);
-			drm_intel_gem_context_destroy(context0);
-			drm_intel_gem_context_destroy(context1);
-			drm_intel_bufmgr_destroy(bufmgr);
+			intel_buf_unmap(dst_buf);
+			intel_buf_destroy(dst_buf);
+			intel_bb_destroy(ibb0);
+			intel_bb_destroy(ibb1);
+			gem_context_destroy(drm_fd, context0_id);
+			gem_context_destroy(drm_fd, context1_id);
+			buf_ops_destroy(bops);
 			__perf_close(stream_fd);
 			gem_quiescent_gpu(drm_fd);
 
@@ -3825,11 +3726,10 @@ static void gen12_single_ctx_helper(void)
 		.num_properties = ARRAY_SIZE(properties) / 2,
 		.properties_ptr = to_user_pointer(properties),
 	};
-	drm_intel_bufmgr *bufmgr;
-	drm_intel_context *context0, *context1;
-	struct intel_batchbuffer *batch;
-	struct igt_buf src[3], dst[3];
-	drm_intel_bo *bo;
+	struct buf_ops *bops;
+	struct intel_bb *ibb0, *ibb1;
+	struct intel_buf src[3], dst[3], *dst_buf;
+	uint32_t context0_id, context1_id;
 	uint32_t *report0_32, *report1_32, *report2_32, *report3_32;
 	uint64_t timestamp0_64, timestamp1_64;
 	uint32_t delta_ts64, delta_oa32;
@@ -3845,21 +3745,17 @@ static void gen12_single_ctx_helper(void)
 		.format = test_set->perf_oa_format
 	};
 
-	bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
-	drm_intel_bufmgr_gem_enable_reuse(bufmgr);
+	bops = buf_ops_create(drm_fd);
 
 	for (int i = 0; i < ARRAY_SIZE(src); i++) {
-		scratch_buf_init(bufmgr, &src[i], width, height, 0xff0000ff);
-		scratch_buf_init(bufmgr, &dst[i], width, height, 0x00ff00ff);
+		scratch_buf_init(bops, &src[i], width, height, 0xff0000ff);
+		scratch_buf_init(bops, &dst[i], width, height, 0x00ff00ff);
 	}
 
-	batch = intel_batchbuffer_alloc(bufmgr, devid);
-
-	context0 = drm_intel_gem_context_create(bufmgr);
-	igt_assert(context0);
-
-	context1 = drm_intel_gem_context_create(bufmgr);
-	igt_assert(context1);
+	ibb0 = intel_bb_create(drm_fd, BATCH_SZ);
+	ibb1 = intel_bb_create(drm_fd, BATCH_SZ);
+	context0_id = gem_context_create(drm_fd);
+	context1_id = gem_context_create(drm_fd);
 
 	igt_debug("submitting warm up render_copy\n");
 
@@ -3883,44 +3779,42 @@ static void gen12_single_ctx_helper(void)
 	 * up pinning the context since there won't ever be a pinning
 	 * hook callback.
 	 */
-	render_copy(batch, context0,
+	render_copy(ibb0, context0_id,
 		    &src[0], 0, 0, width, height,
 		    &dst[0], 0, 0);
 
 	/* Initialize the context parameter to the perf open ioctl here */
-	ret = drm_intel_gem_context_get_id(context0, &ctx0_id);
-	igt_assert_eq(ret, 0);
-	igt_assert_neq(ctx0_id, 0xffffffff);
-	properties[1] = ctx0_id;
+	properties[1] = context0_id;
 
 	igt_debug("opening i915-perf stream\n");
 	stream_fd = __perf_open(drm_fd, &param, false);
 
-	bo = drm_intel_bo_alloc(bufmgr, "mi_rpc dest bo", 4096, 64);
+	dst_buf = intel_buf_create(bops, 4096, 1, 8, 64,
+				   I915_TILING_NONE,
+				   I915_COMPRESSION_NONE);
 
 	/* Set write domain to cpu briefly to fill the buffer with 80s */
-	ret = drm_intel_bo_map(bo, true);
-	igt_assert_eq(ret, 0);
-	memset(bo->virtual, 0x80, 2048);
-	memset(bo->virtual + 2048, 0, 2048);
-	drm_intel_bo_unmap(bo);
+	intel_buf_cpu_map(dst_buf, true /* write enable */);
+	memset(dst_buf->ptr, 0x80, 2048);
+	memset((uint8_t *) dst_buf->ptr + 2048, 0, 2048);
+	intel_buf_unmap(dst_buf);
 
 	/* Submit an mi-rpc to context0 before measurable work */
 #define BO_TIMESTAMP_OFFSET0 1024
 #define BO_REPORT_OFFSET0 0
 #define BO_REPORT_ID0 0xdeadbeef
-	emit_stall_timestamp_and_rpc(batch,
-				     bo,
+	emit_stall_timestamp_and_rpc(ibb0,
+				     dst_buf,
 				     BO_TIMESTAMP_OFFSET0,
 				     BO_REPORT_OFFSET0,
 				     BO_REPORT_ID0);
-	intel_batchbuffer_flush_with_context(batch, context0);
+	intel_bb_flush_render_with_context(ibb0, context0_id);
 
 	/* This is the work/context that is measured for counter increments */
-	render_copy(batch, context0,
+	render_copy(ibb0, context0_id,
 		    &src[0], 0, 0, width, height,
 		    &dst[0], 0, 0);
-	intel_batchbuffer_flush_with_context(batch, context0);
+	intel_bb_flush_render_with_context(ibb0, context0_id);
 
 	/* Submit an mi-rpc to context1 before work
 	 *
@@ -3931,54 +3825,51 @@ static void gen12_single_ctx_helper(void)
 #define BO_TIMESTAMP_OFFSET2 1040
 #define BO_REPORT_OFFSET2 512
 #define BO_REPORT_ID2 0x00c0ffee
-	emit_stall_timestamp_and_rpc(batch,
-				     bo,
+	emit_stall_timestamp_and_rpc(ibb1,
+				     dst_buf,
 				     BO_TIMESTAMP_OFFSET2,
 				     BO_REPORT_OFFSET2,
 				     BO_REPORT_ID2);
-	intel_batchbuffer_flush_with_context(batch, context1);
+	intel_bb_flush_render_with_context(ibb1, context1_id);
 
 	/* Submit two copies on the other context to avoid a false
 	 * positive in case the driver somehow ended up filtering for
 	 * context1
 	 */
-	render_copy(batch, context1,
+	render_copy(ibb1, context1_id,
 		    &src[1], 0, 0, width, height,
 		    &dst[1], 0, 0);
-	ret = drm_intel_gem_context_get_id(context1, &ctx1_id);
-	igt_assert_eq(ret, 0);
-	igt_assert_neq(ctx1_id, 0xffffffff);
 
-	render_copy(batch, context1,
+	render_copy(ibb1, context1_id,
 		    &src[2], 0, 0, width, height,
 		    &dst[2], 0, 0);
-	intel_batchbuffer_flush_with_context(batch, context1);
+	intel_bb_flush_render_with_context(ibb1, context1_id);
 
 	/* Submit an mi-rpc to context1 after all work */
 #define BO_TIMESTAMP_OFFSET3 1048
 #define BO_REPORT_OFFSET3 768
 #define BO_REPORT_ID3 0x01c0ffee
-	emit_stall_timestamp_and_rpc(batch,
-				     bo,
+	emit_stall_timestamp_and_rpc(ibb1,
+				     dst_buf,
 				     BO_TIMESTAMP_OFFSET3,
 				     BO_REPORT_OFFSET3,
 				     BO_REPORT_ID3);
-	intel_batchbuffer_flush_with_context(batch, context1);
+	intel_bb_flush_render_with_context(ibb1, context1_id);
 
 	/* Submit an mi-rpc to context0 after all measurable work */
 #define BO_TIMESTAMP_OFFSET1 1032
 #define BO_REPORT_OFFSET1 256
 #define BO_REPORT_ID1 0xbeefbeef
-	emit_stall_timestamp_and_rpc(batch,
-				     bo,
+	emit_stall_timestamp_and_rpc(ibb0,
+				     dst_buf,
 				     BO_TIMESTAMP_OFFSET1,
 				     BO_REPORT_OFFSET1,
 				     BO_REPORT_ID1);
-	intel_batchbuffer_flush_with_context(batch, context0);
+	intel_bb_flush_render_with_context(ibb0, context0_id);
+	intel_bb_sync(ibb0);
+	intel_bb_sync(ibb1);
 
-	/* Set write domain to none */
-	ret = drm_intel_bo_map(bo, false);
-	igt_assert_eq(ret, 0);
+	intel_buf_cpu_map(dst_buf, false);
 
 	/* Sanity check reports
 	 * reportX_32[0]: report id passed with mi-rpc
@@ -3990,7 +3881,7 @@ static void gen12_single_ctx_helper(void)
 	 * report2_32: start of other work
 	 * report3_32: end of other work
 	 */
-	report0_32 = bo->virtual;
+	report0_32 = dst_buf->ptr;
 	igt_assert_eq(report0_32[0], 0xdeadbeef);
 	igt_assert_neq(report0_32[1], 0);
 	ctx0_id = report0_32[2];
@@ -4001,6 +3892,7 @@ static void gen12_single_ctx_helper(void)
 	igt_assert_eq(report1_32[0], 0xbeefbeef);
 	igt_assert_neq(report1_32[1], 0);
 	ctx1_id = report1_32[2];
+	igt_debug("CTX ID1: %u\n", ctx1_id);
 	dump_report(report1_32, 64, "report1_32");
 
 	/* Verify that counters in context1 are all zeroes */
@@ -4009,7 +3901,7 @@ static void gen12_single_ctx_helper(void)
 	igt_assert_neq(report2_32[1], 0);
 	dump_report(report2_32, 64, "report2_32");
 	igt_assert_eq(0, memcmp(&report2_32[4],
-				bo->virtual + 2048,
+				(uint8_t *) dst_buf->ptr + 2048,
 				240));
 
 	report3_32 = report0_32 + 192;
@@ -4017,7 +3909,7 @@ static void gen12_single_ctx_helper(void)
 	igt_assert_neq(report3_32[1], 0);
 	dump_report(report3_32, 64, "report3_32");
 	igt_assert_eq(0, memcmp(&report3_32[4],
-				bo->virtual + 2048,
+				(uint8_t *) dst_buf->ptr + 2048,
 				240));
 
 	/* Accumulate deltas for counters - A0, A21 and A26 */
@@ -4037,8 +3929,8 @@ static void gen12_single_ctx_helper(void)
 	 * the OA report timestamps should be almost identical but
 	 * allow a 500 nanoseconds margin.
 	 */
-	timestamp0_64 = *(uint64_t *)(((uint8_t *)bo->virtual) + BO_TIMESTAMP_OFFSET0);
-	timestamp1_64 = *(uint64_t *)(((uint8_t *)bo->virtual) + BO_TIMESTAMP_OFFSET1);
+	timestamp0_64 = *(uint64_t *)(((uint8_t *)dst_buf->ptr) + BO_TIMESTAMP_OFFSET0);
+	timestamp1_64 = *(uint64_t *)(((uint8_t *)dst_buf->ptr) + BO_TIMESTAMP_OFFSET1);
 
 	igt_debug("ts_timestamp64 0 = %"PRIu64"\n", timestamp0_64);
 	igt_debug("ts_timestamp64 1 = %"PRIu64"\n", timestamp1_64);
@@ -4073,20 +3965,18 @@ static void gen12_single_ctx_helper(void)
 	/* Verify that the work actually happened by comparing the src
 	 * and dst buffers
 	 */
-	ret = drm_intel_bo_map(src[0].bo, false);
-	igt_assert_eq(ret, 0);
-	ret = drm_intel_bo_map(dst[0].bo, false);
-	igt_assert_eq(ret, 0);
+	intel_buf_cpu_map(&src[0], false);
+	intel_buf_cpu_map(&dst[0], false);
+
+	ret = memcmp(src[0].ptr, dst[0].ptr, 4 * width * height);
+	intel_buf_unmap(&src[0]);
+	intel_buf_unmap(&dst[0]);
 
-	ret = memcmp(src[0].bo->virtual, dst[0].bo->virtual, 4 * width * height);
 	if (ret != 0) {
 		accumulator_print(&accumulator, "total");
 		exit(EAGAIN);
 	}
 
-	drm_intel_bo_unmap(src[0].bo);
-	drm_intel_bo_unmap(dst[0].bo);
-
 	/* Check that this test passed. The test measures the number of 2x2
 	 * samples written to the render target using the counter A26. For
 	 * OAR, this counter will only have increments relevant to this specific
@@ -4096,16 +3986,17 @@ static void gen12_single_ctx_helper(void)
 
 	/* Clean up */
 	for (int i = 0; i < ARRAY_SIZE(src); i++) {
-		drm_intel_bo_unreference(src[i].bo);
-		drm_intel_bo_unreference(dst[i].bo);
+		intel_buf_close(bops, &src[i]);
+		intel_buf_close(bops, &dst[i]);
 	}
 
-	drm_intel_bo_unmap(bo);
-	drm_intel_bo_unreference(bo);
-	intel_batchbuffer_free(batch);
-	drm_intel_gem_context_destroy(context0);
-	drm_intel_gem_context_destroy(context1);
-	drm_intel_bufmgr_destroy(bufmgr);
+	intel_buf_unmap(dst_buf);
+	intel_buf_destroy(dst_buf);
+	intel_bb_destroy(ibb0);
+	intel_bb_destroy(ibb1);
+	gem_context_destroy(drm_fd, context0_id);
+	gem_context_destroy(drm_fd, context1_id);
+	buf_ops_destroy(bops);
 	__perf_close(stream_fd);
 }
 
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#15 lore raw

PATCH v17 15/16 tests/gem_render_tiled_blits: dump gen3 surfaces

In reply to Zbigniew Kempczyński

Experimental to find out what makes reading via gtt incoherent.

---
 tests/i915/gem_render_tiled_blits.c | 79 ++++++++++++++++++++++++++---
 1 file changed, 73 insertions(+), 6 deletions(-)
tests/i915/gem_render_tiled_blits.c +73 -6
index 0d83a43e..dbf4a336 100644
@@ -43,6 +43,8 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/mman.h>
+#include <glib.h>
+#include <zlib.h>
 
 #include <drm.h>
 
@@ -59,20 +61,76 @@ static struct intel_buf linear;
 static uint32_t data[WIDTH*HEIGHT];
 static int snoop;
 
+#define DUMPGEN 3
+#define LINELEN 76
+static int dump_base64(const char *name, void *ptr, uint32_t size)
+{
+	int ret;
+	uLongf outsize = size * 3 / 2;
+	Bytef *destbuf = malloc(outsize);
+	gchar *str, *pos;
+
+	ret = compress2(destbuf, &outsize, ptr, size, Z_BEST_COMPRESSION);
+	if (ret != Z_OK) {
+		igt_warn("error compressing, ret: %d\n", ret);
+	} else {
+		igt_info("compressed %u -> %lu\n", size, outsize);
+
+		igt_info("--- %s ---\n", name);
+		pos = str = g_base64_encode(destbuf, outsize);
+		outsize = strlen(str);
+		while (pos) {
+			char line[LINELEN + 1];
+			int to_copy = min(LINELEN, outsize);
+
+			memcpy(line, pos, to_copy);
+			line[to_copy] = 0;
+			igt_info("%s\n", line);
+			pos += LINELEN;
+			outsize -= to_copy;
+
+			if (outsize == 0)
+				break;
+		}
+		free(str);
+	}
+
+	free(destbuf);
+
+	return ret;
+}
+
 static void
-check_buf(struct intel_bb *ibb, struct intel_buf *buf, uint32_t val)
+check_buf(struct intel_bb *ibb, struct intel_buf *buf, uint32_t val, bool dump)
 {
 	int i915 = buf_ops_get_fd(linear.bops);
 	uint32_t *ptr;
+	char name[32];
 	int i;
 
 	render_copy(ibb, 0, buf, 0, 0, WIDTH, HEIGHT, &linear, 0, 0);
 	intel_bb_sync(ibb);
 
 	if (snoop) {
+		if (ibb->gen == DUMPGEN && dump) {
+			ptr = gem_mmap__device_coherent(ibb->i915, buf->handle, 0,
+							buf->surface[0].size, PROT_READ);
+			gem_set_domain(i915, buf->handle, I915_GEM_DOMAIN_WC, 0);
+			snprintf(name, sizeof(name) - 1, "wc-tiling-%d",
+				 buf->tiling);
+			dump_base64(name, ptr, buf->surface[0].size);
+			munmap(ptr, linear.surface[0].size);
+		}
+
 		ptr = gem_mmap__cpu_coherent(i915, linear.handle, 0,
 					     linear.surface[0].size, PROT_READ);
 		gem_set_domain(i915, linear.handle, I915_GEM_DOMAIN_CPU, 0);
+
+		if (ibb->gen == DUMPGEN && dump) {
+			snprintf(name, sizeof(name) - 1, "linear-tiling-%d",
+				 buf->tiling);
+			dump_base64(name, ptr, buf->surface[0].size);
+		}
 	} else {
 		gem_read(i915, linear.handle, 0, data, sizeof(data));
 		ptr = data;
@@ -97,6 +155,7 @@ static void run_test (int fd, int count)
 	uint32_t start = 0;
 	int i, j;
 	uint32_t devid;
+	char name[32];
 
 	devid = intel_get_drm_devid(fd);
 
@@ -123,12 +182,14 @@ static void run_test (int fd, int count)
 	start_val = malloc(sizeof(*start_val)*count);
 
 	for (i = 0; i < count; i++) {
-		uint32_t tiling = I915_TILING_X + (random() & 1);
+		uint32_t tiling = I915_TILING_X + (i & 1);
 		uint32_t *ptr;
 
 		intel_buf_init(bops, &bufs[i], WIDTH, HEIGHT, 32, 0,
 			       tiling, I915_COMPRESSION_NONE);
 		start_val[i] = start;
+		igt_debug("buf init: [w: %u, h: %u, tiling: %u, start val: %u]\n",
+			  WIDTH, HEIGHT, tiling, start);
 
 		ptr = gem_mmap__gtt(fd, bufs[i].handle,
 				    bufs[i].surface[0].size, PROT_WRITE);
@@ -137,12 +198,18 @@ static void run_test (int fd, int count)
 		for (j = 0; j < WIDTH*HEIGHT; j++)
 			ptr[j] = start++;
 
+		if (ibb->gen == DUMPGEN && count == 2) {
+			snprintf(name, sizeof(name) - 1, "gtt-%d-tiling-%d",
+				 i, bufs[i].tiling);
+			dump_base64(name, ptr, bufs[i].surface[0].size);
+		}
+
 		munmap(ptr, bufs[i].surface[0].size);
 	}
 
 	igt_info("Verifying initialisation...\n");
 	for (i = 0; i < count; i++)
-		check_buf(ibb, &bufs[i], start_val[i]);
+		check_buf(ibb, &bufs[i], start_val[i], true);
 
 	igt_info("Cyclic blits, forward...\n");
 	for (i = 0; i < count * 4; i++) {
@@ -156,7 +223,7 @@ static void run_test (int fd, int count)
 	intel_bb_sync(ibb);
 
 	for (i = 0; i < count; i++)
-		check_buf(ibb, &bufs[i], start_val[i]);
+		check_buf(ibb, &bufs[i], start_val[i], false);
 
 	igt_info("Cyclic blits, backward...\n");
 	for (i = 0; i < count * 4; i++) {
@@ -169,7 +236,7 @@ static void run_test (int fd, int count)
 	}
 	intel_bb_sync(ibb);
 	for (i = 0; i < count; i++)
-		check_buf(ibb, &bufs[i], start_val[i]);
+		check_buf(ibb, &bufs[i], start_val[i], false);
 
 	igt_info("Random blits...\n");
 	for (i = 0; i < count * 4; i++) {
@@ -186,7 +253,7 @@ static void run_test (int fd, int count)
 	intel_bb_sync(ibb);
 
 	for (i = 0; i < count; i++)
-		check_buf(ibb, &bufs[i], start_val[i]);
+		check_buf(ibb, &bufs[i], start_val[i], false);
 
 	/* release resources */
 	intel_buf_close(bops, &linear);
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#16 lore raw

PATCH v17 16/16 tiled_blits: debug stuff for gen3

In reply to Zbigniew Kempczyński
---
 lib/intel_bufops.c                  | 5 ++++-
 lib/rendercopy_i915.c               | 5 +++++
 tests/i915/gem_render_tiled_blits.c | 8 +++++++-
 3 files changed, 16 insertions(+), 2 deletions(-)
lib/intel_bufops.c +4 -1
index 7309d308..fd43f025 100644
@@ -210,11 +210,14 @@ static void set_hw_tiled(struct buf_ops *bops, struct intel_buf *buf)
 {
 	uint32_t ret_tiling, ret_swizzle;
 
+	igt_info("set_hw_tiled: tiling: %d\n", buf->tiling);
 	if (buf->tiling != I915_TILING_X && buf->tiling != I915_TILING_Y)
 		return;
 
-	if (!buf_ops_has_hw_fence(bops, buf->tiling))
+	if (!buf_ops_has_hw_fence(bops, buf->tiling)) {
+		igt_info("has_hw_fence = false\n");
 		return;
+	}
 
 	igt_assert_eq(__set_tiling(bops->fd,
 				   buf->handle, buf->tiling,
lib/rendercopy_i915.c +5 -0
index b16d4f12..776a254b 100644
@@ -32,6 +32,11 @@ void gen3_render_copyfunc(struct intel_bb *ibb,
 	intel_bb_add_intel_buf(ibb, dst, true);
 	intel_bb_add_intel_buf(ibb, src, false);
 
+	intel_buf_set_name(dst, "dst");
+	intel_buf_print(dst);
+	intel_buf_set_name(src, "src");
+	intel_buf_print(src);
+
 	/* invariant state */
 	{
 		intel_bb_out(ibb, _3DSTATE_AA_CMD |
tests/i915/gem_render_tiled_blits.c +7 -1
index dbf4a336..2c78282e 100644
@@ -171,6 +171,11 @@ static void run_test (int fd, int count)
 	bops = buf_ops_create(fd);
 	ibb = intel_bb_create(fd, 4096);
 
+	if (ibb->gen == DUMPGEN) {
+		intel_bb_set_debug(ibb, true);
+		intel_bb_set_dump_base64(ibb, true);
+	}
+
 	intel_buf_init(bops, &linear, WIDTH, HEIGHT, 32, 0,
 		       I915_TILING_NONE, I915_COMPRESSION_NONE);
 	if (snoop) {
@@ -188,7 +193,7 @@ static void run_test (int fd, int count)
 		intel_buf_init(bops, &bufs[i], WIDTH, HEIGHT, 32, 0,
 			       tiling, I915_COMPRESSION_NONE);
 		start_val[i] = start;
-		igt_debug("buf init: [w: %u, h: %u, tiling: %u, start val: %u]\n",
+		igt_info("buf init: [w: %u, h: %u, tiling: %u, start val: %u]\n",
 			  WIDTH, HEIGHT, tiling, start);
 
 		ptr = gem_mmap__gtt(fd, bufs[i].handle,
@@ -274,6 +279,7 @@ igt_main
 		fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
 		igt_require(gem_available_fences(fd) > 0);
+		igt_log_level = IGT_LOG_DEBUG;
 	}
 
 	igt_subtest("basic") {
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#17 lore raw

[igt-dev] ✗ Fi.CI.BAT: failure for Remove libdrm in rendercopy (rev16)

In reply to Zbigniew Kempczyński
== Series Details ==

== Series Details ==

Series: Remove libdrm in rendercopy (rev16)
URL : https://patchwork.freedesktop.org/series/79823/
State : failure

== Summary ==

CI Bug Log - changes from IGT_5752 -> IGTPW_4827
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with IGTPW_4827 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in IGTPW_4827, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/index.html

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in IGTPW_4827:

### IGT changes ###

#### Possible regressions ####

* igt@gem_render_tiled_blits@basic:
- fi-gdg-551: [PASS][1] -> [FAIL][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-gdg-551/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-gdg-551/igt@[email protected]

Known issues
------------

Here are the changes found in IGTPW_4827 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_module_load@reload:
- fi-byt-j1900: [PASS][3] -> [DMESG-WARN][4] ([i915#1982])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-byt-j1900/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-byt-j1900/igt@[email protected]
- fi-bsw-kefka: [PASS][5] -> [DMESG-WARN][6] ([i915#1982]) +1 similar issue
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-bsw-kefka/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-bsw-kefka/igt@[email protected]

* igt@kms_busy@basic@flip:
- fi-kbl-x1275: [PASS][7] -> [DMESG-WARN][8] ([i915#62] / [i915#92] / [i915#95])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-kbl-x1275/igt@kms_busy@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-kbl-x1275/igt@kms_busy@[email protected]

#### Possible fixes ####

* igt@gem_exec_suspend@basic-s3:
- fi-tgl-u2: [FAIL][9] ([i915#1888]) -> [PASS][10] +1 similar issue
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-tgl-u2/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-tgl-u2/igt@[email protected]

* igt@i915_module_load@reload:
- fi-apl-guc: [DMESG-WARN][11] ([i915#1635] / [i915#1982]) -> [PASS][12]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-apl-guc/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-apl-guc/igt@[email protected]
- fi-bsw-n3050: [DMESG-WARN][13] ([i915#1982]) -> [PASS][14]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-bsw-n3050/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-bsw-n3050/igt@[email protected]

* igt@i915_pm_rpm@basic-pci-d3-state:
- fi-byt-j1900: [DMESG-WARN][15] ([i915#1982]) -> [PASS][16]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-byt-j1900/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-byt-j1900/igt@[email protected]
- fi-bsw-kefka: [DMESG-WARN][17] ([i915#1982]) -> [PASS][18]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-bsw-kefka/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-bsw-kefka/igt@[email protected]

* igt@i915_pm_rpm@module-reload:
- {fi-kbl-7560u}: [WARN][19] -> [PASS][20]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-kbl-7560u/igt@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-kbl-7560u/igt@[email protected]

* igt@kms_setmode@basic-clone-single-crtc:
- {fi-kbl-7560u}: [WARN][21] ([i915#2100]) -> [PASS][22]
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-kbl-7560u/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-kbl-7560u/igt@[email protected]

#### Warnings ####

* igt@gem_exec_suspend@basic-s0:
- fi-kbl-x1275: [DMESG-WARN][23] ([i915#62] / [i915#92] / [i915#95]) -> [DMESG-WARN][24] ([i915#1982] / [i915#62] / [i915#92] / [i915#95])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-kbl-x1275/igt@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-kbl-x1275/igt@[email protected]

* igt@kms_cursor_legacy@basic-flip-after-cursor-legacy:
- fi-kbl-x1275: [DMESG-WARN][25] ([i915#62] / [i915#92] / [i915#95]) -> [DMESG-WARN][26] ([i915#62] / [i915#92]) +2 similar issues
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-kbl-x1275/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-kbl-x1275/igt@[email protected]

* igt@kms_force_connector_basic@force-edid:
- fi-kbl-x1275: [DMESG-WARN][27] ([i915#62] / [i915#92]) -> [DMESG-WARN][28] ([i915#62] / [i915#92] / [i915#95]) +1 similar issue
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5752/fi-kbl-x1275/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/fi-kbl-x1275/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[i915#1635]: https://gitlab.freedesktop.org/drm/intel/issues/1635
[i915#1888]: https://gitlab.freedesktop.org/drm/intel/issues/1888
[i915#1982]: https://gitlab.freedesktop.org/drm/intel/issues/1982
[i915#2100]: https://gitlab.freedesktop.org/drm/intel/issues/2100
[i915#62]: https://gitlab.freedesktop.org/drm/intel/issues/62
[i915#92]: https://gitlab.freedesktop.org/drm/intel/issues/92
[i915#95]: https://gitlab.freedesktop.org/drm/intel/issues/95

Participating hosts (43 -> 36)
------------------------------

Missing (7): fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-byt-clapper fi-bdw-samus

Build changes
-------------

* CI: CI-20190529 -> None
* IGT: IGT_5752 -> IGTPW_4827

CI-20190529: 20190529
CI_DRM_8815: 521846d50ed323d4dcb0ffafa63e34528b0a4996 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_4827: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/index.html
IGT_5752: 3ecf9d88803a686354394ea60164551646235273 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Testlist changes ==

+igt@api_intel_bb@check-canonical
+igt@api_intel_bb@render-ccs
+igt@api_intel_bb@render-none-512
+igt@api_intel_bb@render-none-1024
+igt@api_intel_bb@render-none-reloc-512
+igt@api_intel_bb@render-none-reloc-1024
+igt@api_intel_bb@render-x-512
+igt@api_intel_bb@render-x-1024
+igt@api_intel_bb@render-x-reloc-512
+igt@api_intel_bb@render-x-reloc-1024
+igt@api_intel_bb@render-y-512
+igt@api_intel_bb@render-y-1024
+igt@api_intel_bb@render-y-reloc-512
+igt@api_intel_bb@render-y-reloc-1024
-igt@gem_read_read_speed@read-read-1x1
-igt@gem_read_read_speed@read-write-1x1
-igt@gem_read_read_speed@write-read-1x1
-igt@gem_read_read_speed@write-write-1x1

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4827/index.html

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev