[i-g-t 24/27] lib/batchbuffer: Add vm_bind support for blit copy
Bhanuprakash Modem
bhanuprakash.modem at intel.com
Mon Jan 23 09:43:32 UTC 2023
Add a support for vm_bind mode in blit copy (both fast & src).
Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem at intel.com>
---
lib/igt_fb.c | 53 ++++++++++++++++++++++------
lib/intel_batchbuffer.c | 76 ++++++++++++++++++++++++++++++++---------
2 files changed, 103 insertions(+), 26 deletions(-)
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index ed462313..e2f3c20e 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -35,6 +35,7 @@
#include "drmtest.h"
#include "i915/gem_create.h"
#include "i915/gem_mman.h"
+#include "i915/gem_vm.h"
#include "igt_aux.h"
#include "igt_color_encoding.h"
#include "igt_fb.h"
@@ -2684,19 +2685,50 @@ static void blitcopy(const struct igt_fb *dst_fb,
const struct igt_fb *src_fb)
{
uint32_t src_tiling, dst_tiling;
- uint32_t ctx = 0;
uint64_t ahnd = 0;
+ const intel_ctx_t *ctx;
+ uint32_t vm_id = 0, ctx_id = 0;
+ intel_ctx_cfg_t *cfg = NULL;
+ intel_ctx_cfg_t ctx_cfg = { };
+ int drm_fd;
igt_assert_eq(dst_fb->fd, src_fb->fd);
igt_assert_eq(dst_fb->num_planes, src_fb->num_planes);
+ drm_fd = dst_fb->fd;
src_tiling = igt_fb_mod_to_tiling(src_fb->modifier);
dst_tiling = igt_fb_mod_to_tiling(dst_fb->modifier);
if (!gem_has_relocations(dst_fb->fd)) {
- igt_require(gem_has_contexts(dst_fb->fd));
- ctx = gem_context_create(dst_fb->fd);
- ahnd = get_reloc_ahnd(dst_fb->fd, ctx);
+ struct drm_i915_gem_context_param param = {
+ .param = I915_CONTEXT_PARAM_RECOVERABLE,
+ .value = 0,
+ };
+
+ igt_require(gem_has_contexts(drm_fd));
+
+ if (gem_has_vm(drm_fd)) {
+ vm_id = gem_vm_create_in_vm_bind_mode(drm_fd);
+ ctx_cfg.engines[0] = (struct i915_engine_class_instance) {
+ .engine_class = I915_ENGINE_CLASS_COPY,
+ };
+ ctx_cfg.num_engines = 1;
+
+ ctx = intel_ctx_create(drm_fd, &ctx_cfg);
+ ctx_id = ctx->id;
+ param.ctx_id = ctx_id;
+
+ gem_context_set_param(drm_fd, ¶m);
+ gem_context_set_vm(drm_fd, ctx_id, vm_id);
+
+ vm_id = gem_context_get_vm(drm_fd, ctx_id);
+ cfg = &ctx_cfg;
+
+ ahnd = get_simple_ahnd(drm_fd, ctx_id);
+ } else {
+ ctx_id = gem_context_create(drm_fd);
+ ahnd = get_reloc_ahnd(drm_fd, ctx_id);
+ }
}
for (int i = 0; i < dst_fb->num_planes; i++) {
@@ -2709,8 +2741,8 @@ static void blitcopy(const struct igt_fb *dst_fb,
* instead.
*/
if (fast_blit_ok(src_fb) && fast_blit_ok(dst_fb)) {
- igt_blitter_fast_copy__raw(dst_fb->fd,
- ahnd, ctx, NULL,
+ igt_blitter_fast_copy__raw(drm_fd,
+ ahnd, ctx_id, cfg,
src_fb->gem_handle,
src_fb->offsets[i],
src_fb->strides[i],
@@ -2727,8 +2759,8 @@ static void blitcopy(const struct igt_fb *dst_fb,
0, 0 /* dst_x, dst_y */,
dst_fb->size);
} else {
- igt_blitter_src_copy(dst_fb->fd,
- ahnd, ctx, NULL,
+ igt_blitter_src_copy(drm_fd,
+ ahnd, ctx_id, cfg,
src_fb->gem_handle,
src_fb->offsets[i],
src_fb->strides[i],
@@ -2747,8 +2779,9 @@ static void blitcopy(const struct igt_fb *dst_fb,
}
}
- if (ctx)
- gem_context_destroy(dst_fb->fd, ctx);
+ intel_ctx_destroy(drm_fd, ctx);
+ if (vm_id)
+ gem_vm_destroy(drm_fd, vm_id);
put_ahnd(ahnd);
}
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index 25ed7316..5fb4dd2e 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -222,24 +222,48 @@ uint32_t intel_bb_find_engine(const intel_ctx_cfg_t *cfg, unsigned int class)
static void exec_blit(int fd,
struct drm_i915_gem_exec_object2 *objs,
- uint32_t count, unsigned int gen,
- uint32_t ctx, const intel_ctx_cfg_t *cfg)
+ uint32_t count, uint32_t ctx,
+ const intel_ctx_cfg_t *cfg, uint32_t vm_id)
{
- struct drm_i915_gem_execbuffer2 exec;
- uint32_t devid = intel_get_drm_devid(fd);
- uint32_t blt_id = HAS_BLT_RING(devid) ? I915_EXEC_BLT : I915_EXEC_DEFAULT;
+ if (gem_has_vm(fd)) {
+ struct drm_i915_gem_execbuffer3 execbuf;
+ struct drm_i915_gem_timeline_fence exec_fence = { };
+ int i;
- if (cfg)
- blt_id = intel_bb_find_engine(cfg, I915_ENGINE_CLASS_COPY);
+ for (i = 0; i < count; i++)
+ i915_vm_bind(fd, vm_id, objs[i].offset, objs[i].handle,
+ 0, objs[i].rsvd2, 0, 0, 0);
+
+ exec_fence.handle = syncobj_create(fd, 0);
+ exec_fence.flags = I915_TIMELINE_FENCE_SIGNAL;
+
+ memset(&execbuf, 0, sizeof(execbuf));
+ execbuf.ctx_id = ctx;
+ execbuf.batch_address = objs[0].offset;
+ execbuf.engine_idx = intel_bb_find_engine(cfg, I915_ENGINE_CLASS_COPY);
+ execbuf.fence_count = 1;
+ execbuf.timeline_fences = to_user_pointer(&exec_fence);
+
+ gem_execbuf3(fd, &execbuf);
- exec = (struct drm_i915_gem_execbuffer2) {
- .buffers_ptr = to_user_pointer(objs),
- .buffer_count = count,
- .flags = blt_id | I915_EXEC_NO_RELOC,
- .rsvd1 = ctx,
- };
+ igt_assert(syncobj_timeline_wait(fd, &exec_fence.handle, NULL, 1,
+ gettime_ns() + (2 * NSEC_PER_SEC),
+ DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT, NULL));
+ syncobj_destroy(fd, exec_fence.handle);
- gem_execbuf(fd, &exec);
+ for (i = 0; i < count; i++)
+ i915_vm_unbind(fd, vm_id, objs[i].offset, objs[i].rsvd2);
+ } else {
+ struct drm_i915_gem_execbuffer2 exec = (struct drm_i915_gem_execbuffer2) {
+ .buffers_ptr = to_user_pointer(objs),
+ .buffer_count = count,
+ .flags = I915_EXEC_NO_RELOC | HAS_BLT_RING(intel_get_drm_devid(fd)) ?
+ I915_EXEC_BLT : I915_EXEC_DEFAULT,
+ .rsvd1 = ctx,
+ };
+
+ gem_execbuf(fd, &exec);
+ }
}
static uint32_t src_copy_dword0(uint32_t src_tiling, uint32_t dst_tiling,
@@ -345,6 +369,10 @@ void igt_blitter_src_copy(int fd,
uint64_t batch_offset, src_offset, dst_offset;
const bool has_64b_reloc = gen >= 8;
int i = 0;
+ uint32_t vm_id = 0;
+
+ if (cfg)
+ vm_id = gem_context_get_vm(fd, ctx);
batch_handle = gem_create(fd, 4096);
if (ahnd) {
@@ -444,13 +472,19 @@ void igt_blitter_src_copy(int fd,
objs[0].flags |= EXEC_OBJECT_NEEDS_FENCE | EXEC_OBJECT_WRITE;
objs[1].flags |= EXEC_OBJECT_NEEDS_FENCE;
+ if (vm_id) {
+ objs[0].rsvd2 = 4096;
+ objs[1].rsvd2 = dst_size;
+ objs[2].rsvd2 = src_size;
+ }
+
if (ahnd) {
objs[0].flags |= EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
objs[1].flags |= EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
objs[2].flags |= EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
}
- exec_blit(fd, objs, 3, gen, ctx, cfg);
+ exec_blit(fd, objs, 3, ctx, cfg, vm_id);
gem_close(fd, batch_handle);
}
@@ -515,6 +549,10 @@ void igt_blitter_fast_copy__raw(int fd,
uint32_t src_pitch, dst_pitch;
uint64_t batch_offset, src_offset, dst_offset;
int i = 0;
+ uint32_t vm_id = 0;
+
+ if (cfg)
+ vm_id = gem_context_get_vm(fd, ctx);
batch_handle = gem_create(fd, 4096);
if (ahnd) {
@@ -566,13 +604,19 @@ void igt_blitter_fast_copy__raw(int fd,
fill_object(&objs[1], src_handle, src_offset, NULL, 0);
fill_object(&objs[2], batch_handle, batch_offset, relocs, !ahnd ? 2 : 0);
+ if (vm_id) {
+ objs[0].rsvd2 = 4096;
+ objs[1].rsvd2 = dst_size;
+ objs[2].rsvd2 = src_size;
+ }
+
if (ahnd) {
objs[0].flags |= EXEC_OBJECT_PINNED;
objs[1].flags |= EXEC_OBJECT_PINNED;
objs[2].flags |= EXEC_OBJECT_PINNED;
}
- exec_blit(fd, objs, 3, intel_gen(intel_get_drm_devid(fd)), ctx, cfg);
+ exec_blit(fd, objs, 3, ctx, cfg, vm_id);
gem_close(fd, batch_handle);
}
--
2.39.0
More information about the Intel-gfx-trybot
mailing list