[i-g-t v2 07/12] lib/intel_batchbuffer: No relocations in blitter fast copy

Bhanuprakash Modem bhanuprakash.modem at intel.com
Mon Jun 28 12:44:27 UTC 2021


For newer gens kernel will reject relocations by returning -EINVAL
so we should just provide an offset (returned from allocator)
and skip adding relocation entries.

Cc: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem at intel.com>
---
 lib/intel_batchbuffer.c | 57 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 50 insertions(+), 7 deletions(-)

diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index cc976a6243..f3ace27997 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -703,7 +703,7 @@ fill_object(struct drm_i915_gem_exec_object2 *obj, uint32_t gem_handle,
 
 static void exec_blit(int fd,
 		      struct drm_i915_gem_exec_object2 *objs, uint32_t count,
-		      unsigned int gen)
+		      unsigned int gen, uint32_t ctx)
 {
 	struct drm_i915_gem_execbuffer2 exec = {
 		.buffers_ptr = to_user_pointer(objs),
@@ -711,6 +711,11 @@ static void exec_blit(int fd,
 		.flags = gen >= 6 ? I915_EXEC_BLT : 0,
 	};
 
+	if (ctx) {
+		exec.rsvd1 = ctx;
+		exec.flags |= I915_EXEC_NO_RELOC;
+	}
+
 	gem_execbuf(fd, &exec);
 }
 
@@ -893,7 +898,7 @@ void igt_blitter_src_copy(int fd,
 	objs[0].flags |= EXEC_OBJECT_NEEDS_FENCE;
 	objs[1].flags |= EXEC_OBJECT_NEEDS_FENCE;
 
-	exec_blit(fd, objs, 3, gen);
+	exec_blit(fd, objs, 3, gen, 0);
 
 	gem_close(fd, batch_handle);
 }
@@ -947,6 +952,19 @@ void igt_blitter_fast_copy__raw(int fd,
 	uint32_t dword0, dword1;
 	uint32_t src_pitch, dst_pitch;
 	int i = 0;
+	bool no_relocs = !gem_has_relocations(fd);
+	uint32_t ctx = 0;
+	uint64_t ahnd = 0;
+	uint64_t dst_offset, src_offset, batch_offset;
+
+	if (no_relocs) {
+		igt_require(gem_has_contexts(fd));
+		ctx = gem_context_create(fd);
+		ahnd = get_reloc_ahnd(fd, ctx);
+	}
+
+	dst_offset = get_offset(ahnd, dst_handle, (width * height * bpp / 8), 0);
+	src_offset = get_offset(ahnd, src_handle, (width * height * bpp / 8), 0);
 
 	src_pitch = fast_copy_pitch(src_stride, src_tiling);
 	dst_pitch = fast_copy_pitch(dst_stride, dst_tiling);
@@ -964,18 +982,19 @@ void igt_blitter_fast_copy__raw(int fd,
 	batch[i++] = dword1 | dst_pitch;
 	batch[i++] = (dst_y << 16) | dst_x; /* dst x1,y1 */
 	batch[i++] = ((dst_y + height) << 16) | (dst_x + width); /* dst x2,y2 */
-	batch[i++] = dst_delta; /* dst address lower bits */
-	batch[i++] = 0;	/* dst address upper bits */
+	batch[i++] = no_relocs ? dst_offset : dst_delta; /* dst address lower bits */
+	batch[i++] = no_relocs ? (dst_offset >> 32) : 0; /* dst address upper bits */
 	batch[i++] = (src_y << 16) | src_x; /* src x1,y1 */
 	batch[i++] = src_pitch;
-	batch[i++] = src_delta; /* src address lower bits */
-	batch[i++] = 0;	/* src address upper bits */
+	batch[i++] = no_relocs ? src_offset : src_delta; /* src address lower bits */
+	batch[i++] = no_relocs ? (src_offset >> 32) : 0; /* src address upper bits */
 	batch[i++] = MI_BATCH_BUFFER_END;
 	batch[i++] = MI_NOOP;
 
 	igt_assert(i == ARRAY_SIZE(batch));
 
 	batch_handle = gem_create(fd, 4096);
+	batch_offset = get_offset(ahnd, batch_handle, 4096, 0);
 	gem_write(fd, batch_handle, 0, batch, sizeof(batch));
 
 	fill_relocation(&relocs[0], dst_handle, dst_delta, 4,
@@ -986,9 +1005,33 @@ void igt_blitter_fast_copy__raw(int fd,
 	fill_object(&objs[1], src_handle, NULL, 0);
 	fill_object(&objs[2], batch_handle, relocs, 2);
 
-	exec_blit(fd, objs, 3, intel_gen(intel_get_drm_devid(fd)));
+	if (no_relocs) {
+		objs[0].flags |= EXEC_OBJECT_PINNED | EXEC_OBJECT_WRITE;
+		objs[1].flags |= EXEC_OBJECT_PINNED;
+		objs[2].flags |= EXEC_OBJECT_PINNED;
+		objs[0].offset = dst_offset;
+		objs[1].offset = src_offset;
+		objs[2].offset = batch_offset;
+		objs[2].relocation_count = 0;
+		objs[2].relocs_ptr = to_user_pointer(NULL);
+
+		relocs[0].delta = 0;
+		relocs[1].delta = 0;
+		relocs[0].presumed_offset = dst_offset;
+		relocs[1].presumed_offset = src_offset;
+		relocs[0].write_domain = 0;
+	}
+	exec_blit(fd, objs, 3, intel_gen(intel_get_drm_devid(fd)), ctx);
 
 	gem_close(fd, batch_handle);
+
+	put_offset(ahnd, dst_handle);
+	put_offset(ahnd, src_handle);
+	put_offset(ahnd, batch_handle);
+	put_ahnd(ahnd);
+
+	if (ctx)
+		gem_context_destroy(fd, ctx);
 }
 
 /**
-- 
2.20.1



More information about the Intel-gfx-trybot mailing list