[PATCH i-g-t 1/5] lib/intel_blt: Promote blt_bo_copy()
Francois Dugast
francois.dugast at intel.com
Wed Mar 5 09:06:11 UTC 2025
This function abstracts copy with mem blt. Move it to the library so
that it can be also be used elsewhere without code duplication.
Signed-off-by: Francois Dugast <francois.dugast at intel.com>
---
lib/intel_blt.c | 53 +++++++++++++++++++++++++++++++++++++
lib/intel_blt.h | 3 +++
tests/intel/xe_copy_basic.c | 36 +------------------------
3 files changed, 57 insertions(+), 35 deletions(-)
diff --git a/lib/intel_blt.c b/lib/intel_blt.c
index b2fb3151e..84318a557 100644
--- a/lib/intel_blt.c
+++ b/lib/intel_blt.c
@@ -1903,6 +1903,59 @@ int blt_mem_copy(int fd, const intel_ctx_t *ctx,
return ret;
}
+/**
+ * blt_bo_copy:
+ * @fd: drm fd
+ * @src_handle: handle of the source BO
+ * @dst_handle: handle of the destination BO
+ * @ctx: intel_ctx_t context
+ * @size: BO size
+ * @width: width
+ * @height: height
+ * @region: memory region
+ *
+ * Copy BO with mem blit from @src_handle into @dst_handle.
+ */
+void blt_bo_copy(int fd, uint32_t src_handle, uint32_t dst_handle, const intel_ctx_t *ctx,
+ uint32_t size, uint32_t width, uint32_t height, uint32_t region)
+{
+ struct blt_mem_data mem = {};
+ uint64_t bb_size = xe_bb_size(fd, SZ_4K);
+ uint64_t ahnd = intel_allocator_open_full(fd, ctx->vm, 0, 0,
+ INTEL_ALLOCATOR_SIMPLE,
+ ALLOC_STRATEGY_LOW_TO_HIGH, 0);
+ uint8_t src_mocs = intel_get_uc_mocs_index(fd);
+ uint8_t dst_mocs = src_mocs;
+ uint32_t bb;
+ int result;
+
+ bb = xe_bo_create(fd, 0, bb_size, region, 0);
+
+ blt_mem_init(fd, &mem);
+ blt_set_mem_object(&mem.src, src_handle, size, 0, width, height,
+ region, src_mocs, DEFAULT_PAT_INDEX, M_LINEAR,
+ COMPRESSION_DISABLED);
+ blt_set_mem_object(&mem.dst, dst_handle, size, 0, width, height,
+ region, dst_mocs, DEFAULT_PAT_INDEX, M_LINEAR,
+ COMPRESSION_DISABLED);
+ mem.src.ptr = xe_bo_map(fd, src_handle, size);
+ mem.dst.ptr = xe_bo_map(fd, dst_handle, size);
+
+ blt_set_batch(&mem.bb, bb, bb_size, region);
+ igt_assert(mem.src.width == mem.dst.width);
+
+ blt_mem_copy(fd, ctx, NULL, ahnd, &mem);
+ result = memcmp(mem.src.ptr, mem.dst.ptr, mem.src.size);
+
+ intel_allocator_bind(ahnd, 0, 0);
+ munmap(mem.src.ptr, size);
+ munmap(mem.dst.ptr, size);
+ gem_close(fd, bb);
+ put_ahnd(ahnd);
+
+ igt_assert_f(!result, "source and destination differ\n");
+}
+
static void emit_blt_mem_set(int fd, uint64_t ahnd, const struct blt_mem_data *mem,
uint8_t fill_data)
{
diff --git a/lib/intel_blt.h b/lib/intel_blt.h
index 5d6191ac9..4357d70eb 100644
--- a/lib/intel_blt.h
+++ b/lib/intel_blt.h
@@ -271,6 +271,9 @@ int blt_mem_copy(int fd, const intel_ctx_t *ctx,
uint64_t ahnd,
const struct blt_mem_data *mem);
+void blt_bo_copy(int fd, uint32_t src_handle, uint32_t dst_handle, const intel_ctx_t *ctx,
+ uint32_t size, uint32_t width, uint32_t height, uint32_t region);
+
int blt_mem_set(int fd, const intel_ctx_t *ctx,
const struct intel_execution_engine2 *e, uint64_t ahnd,
const struct blt_mem_data *mem, uint8_t fill_data);
diff --git a/tests/intel/xe_copy_basic.c b/tests/intel/xe_copy_basic.c
index a43842e39..458106b0b 100644
--- a/tests/intel/xe_copy_basic.c
+++ b/tests/intel/xe_copy_basic.c
@@ -44,41 +44,7 @@ static void
mem_copy(int fd, uint32_t src_handle, uint32_t dst_handle, const intel_ctx_t *ctx,
uint32_t size, uint32_t width, uint32_t height, uint32_t region)
{
- struct blt_mem_data mem = {};
- uint64_t bb_size = xe_bb_size(fd, SZ_4K);
- uint64_t ahnd = intel_allocator_open_full(fd, ctx->vm, 0, 0,
- INTEL_ALLOCATOR_SIMPLE,
- ALLOC_STRATEGY_LOW_TO_HIGH, 0);
- uint8_t src_mocs = intel_get_uc_mocs_index(fd);
- uint8_t dst_mocs = src_mocs;
- uint32_t bb;
- int result;
-
- bb = xe_bo_create(fd, 0, bb_size, region, 0);
-
- blt_mem_init(fd, &mem);
- blt_set_mem_object(&mem.src, src_handle, size, 0, width, height,
- region, src_mocs, DEFAULT_PAT_INDEX, M_LINEAR,
- COMPRESSION_DISABLED);
- blt_set_mem_object(&mem.dst, dst_handle, size, 0, width, height,
- region, dst_mocs, DEFAULT_PAT_INDEX, M_LINEAR,
- COMPRESSION_DISABLED);
- mem.src.ptr = xe_bo_map(fd, src_handle, size);
- mem.dst.ptr = xe_bo_map(fd, dst_handle, size);
-
- blt_set_batch(&mem.bb, bb, bb_size, region);
- igt_assert(mem.src.width == mem.dst.width);
-
- blt_mem_copy(fd, ctx, NULL, ahnd, &mem);
- result = memcmp(mem.src.ptr, mem.dst.ptr, mem.src.size);
-
- intel_allocator_bind(ahnd, 0, 0);
- munmap(mem.src.ptr, size);
- munmap(mem.dst.ptr, size);
- gem_close(fd, bb);
- put_ahnd(ahnd);
-
- igt_assert_f(!result, "source and destination differ\n");
+ blt_bo_copy(fd, src_handle, dst_handle, ctx, size, width, height, region);
}
/**
--
2.43.0
More information about the igt-dev
mailing list