[PATCH i-g-t 07/22] lib/kms: Support no relocations
Bhanuprakash Modem
bhanuprakash.modem at intel.com
Fri Jun 25 12:54:01 UTC 2021
Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem at intel.com>
---
lib/igt_fb.c | 48 ++++++++++++++++++++++++++++++++++--
lib/igt_fb.h | 2 ++
lib/intel_batchbuffer.c | 54 ++++++++++++++++++++++++++++++-----------
lib/intel_batchbuffer.h | 6 ++---
4 files changed, 91 insertions(+), 19 deletions(-)
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 71b8985529..4ecd60aec1 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -1076,6 +1076,10 @@ static int create_bo_for_fb(struct igt_fb *fb, bool prefer_sysmem)
int err;
fb->gem_handle = gem_create(fd, fb->size);
+ fb->alloc_offset = get_offset(fb->ahnd,
+ fb->gem_handle,
+ fb->size, 0);
+
err = __gem_set_tiling(fd, fb->gem_handle,
igt_fb_mod_to_tiling(fb->modifier),
fb->strides[0]);
@@ -1878,6 +1882,9 @@ unsigned int igt_create_color_fb(int fd, int width, int height,
igt_paint_color(cr, 0, 0, width, height, r, g, b);
igt_put_cairo_ctx(cr);
+ if (is_i915_device(fd))
+ put_offset(fb->ahnd, fb->gem_handle);
+
return fb_id;
}
@@ -1915,6 +1922,9 @@ unsigned int igt_create_pattern_fb(int fd, int width, int height,
igt_paint_test_pattern(cr, width, height);
igt_put_cairo_ctx(cr);
+ if (is_i915_device(fd))
+ put_offset(fb->ahnd, fb->gem_handle);
+
return fb_id;
}
@@ -1958,6 +1968,9 @@ unsigned int igt_create_color_pattern_fb(int fd, int width, int height,
igt_paint_test_pattern(cr, width, height);
igt_put_cairo_ctx(cr);
+ if (is_i915_device(fd))
+ put_offset(fb->ahnd, fb->gem_handle);
+
return fb_id;
}
@@ -2001,6 +2014,9 @@ unsigned int igt_create_image_fb(int fd, int width, int height,
igt_paint_image(cr, filename, 0, 0, width, height);
igt_put_cairo_ctx(cr);
+ if (is_i915_device(fd))
+ put_offset(fb->ahnd, fb->gem_handle);
+
return fb_id;
}
@@ -2404,6 +2420,25 @@ static void blitcopy(const struct igt_fb *dst_fb,
const struct igt_fb *src_fb)
{
uint32_t src_tiling, dst_tiling;
+ bool no_relocs = false;
+
+ /* Allocator handle must be same for both the objects. */
+ igt_assert_eq_u64(dst_fb->ahnd, src_fb->ahnd);
+ if (dst_fb->ahnd) {
+ /*
+ * Check the objects identified by the @gem_handle and @size
+ * is allocated at the @alloc_offset.
+ */
+ no_relocs = intel_allocator_is_allocated(dst_fb->ahnd,
+ dst_fb->gem_handle,
+ dst_fb->size,
+ dst_fb->alloc_offset) &&
+ intel_allocator_is_allocated(src_fb->ahnd,
+ src_fb->gem_handle,
+ src_fb->size,
+ src_fb->alloc_offset);
+ igt_assert(no_relocs);
+ }
igt_assert_eq(dst_fb->fd, src_fb->fd);
igt_assert_eq(dst_fb->num_planes, src_fb->num_planes);
@@ -2422,8 +2457,11 @@ static void blitcopy(const struct igt_fb *dst_fb,
*/
if (fast_blit_ok(src_fb) && fast_blit_ok(dst_fb)) {
igt_blitter_fast_copy__raw(dst_fb->fd,
+ dst_fb->ahnd,
src_fb->gem_handle,
- src_fb->offsets[i],
+ no_relocs ?
+ src_fb->alloc_offset :
+ src_fb->offsets[i],
src_fb->strides[i],
src_tiling,
0, 0, /* src_x, src_y */
@@ -2431,7 +2469,9 @@ static void blitcopy(const struct igt_fb *dst_fb,
dst_fb->plane_height[i],
dst_fb->plane_bpp[i],
dst_fb->gem_handle,
- dst_fb->offsets[i],
+ no_relocs ?
+ dst_fb->alloc_offset :
+ dst_fb->offsets[i],
dst_fb->strides[i],
dst_tiling,
0, 0 /* dst_x, dst_y */);
@@ -2486,6 +2526,8 @@ static void free_linear_mapping(struct fb_blit_upload *blit)
blitcopy(fb, &linear->fb);
gem_sync(fd, linear->fb.gem_handle);
+
+ put_offset(fb->ahnd, linear->fb.gem_handle);
gem_close(fd, linear->fb.gem_handle);
}
@@ -2527,6 +2569,7 @@ static void setup_linear_mapping(struct fb_blit_upload *blit)
fb->drm_format, LOCAL_DRM_FORMAT_MOD_NONE,
fb->color_encoding, fb->color_range);
+ linear->fb.ahnd = fb->ahnd;
create_bo_for_fb(&linear->fb, true);
igt_assert(linear->fb.gem_handle > 0);
@@ -3844,6 +3887,7 @@ void igt_remove_fb(int fd, struct igt_fb *fb)
else
gem_close(fd, fb->gem_handle);
fb->fb_id = 0;
+ fb->ahnd = 0;
}
/**
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 2c2b8265b5..490f604eb5 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -95,6 +95,8 @@ typedef struct igt_fb {
unsigned int plane_bpp[4];
unsigned int plane_width[4];
unsigned int plane_height[4];
+ uint64_t ahnd;
+ uint64_t alloc_offset;
void *driver_priv;
} igt_fb_t;
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index cc976a6243..6854ab1e83 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, bool no_relocs)
{
struct drm_i915_gem_execbuffer2 exec = {
.buffers_ptr = to_user_pointer(objs),
@@ -711,6 +711,9 @@ static void exec_blit(int fd,
.flags = gen >= 6 ? I915_EXEC_BLT : 0,
};
+ if (no_relocs)
+ exec.flags |= I915_EXEC_NO_RELOC;
+
gem_execbuf(fd, &exec);
}
@@ -893,7 +896,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);
}
@@ -901,8 +904,9 @@ void igt_blitter_src_copy(int fd,
/**
* igt_blitter_fast_copy__raw:
* @fd: file descriptor of the i915 driver
+ * @ahnd: handle to an allocator
* @src_handle: GEM handle of the source buffer
- * @src_delta: offset into the source GEM bo, in bytes
+ * @src_offset: address of src object (or) offset into the src GEM bo, in bytes
* @src_stride: Stride (in bytes) of the source buffer
* @src_tiling: Tiling mode of the source buffer
* @src_x: X coordinate of the source region to copy
@@ -911,7 +915,7 @@ void igt_blitter_src_copy(int fd,
* @height: Height of the region to copy
* @bpp: source and destination bits per pixel
* @dst_handle: GEM handle of the destination buffer
- * @dst_delta: offset into the destination GEM bo, in bytes
+ * @dst_offset: address of dst object (or) offset into the dst GEM bo, in bytes
* @dst_stride: Stride (in bytes) of the destination buffer
* @dst_tiling: Tiling mode of the destination buffer
* @dst_x: X coordinate of destination
@@ -919,10 +923,10 @@ void igt_blitter_src_copy(int fd,
*
* Like igt_blitter_fast_copy(), but talking to the kernel directly.
*/
-void igt_blitter_fast_copy__raw(int fd,
+void igt_blitter_fast_copy__raw(int fd, uint64_t ahnd,
/* src */
uint32_t src_handle,
- unsigned int src_delta,
+ uint64_t src_offset,
unsigned int src_stride,
unsigned int src_tiling,
unsigned int src_x, unsigned src_y,
@@ -935,7 +939,7 @@ void igt_blitter_fast_copy__raw(int fd,
/* dst */
uint32_t dst_handle,
- unsigned dst_delta,
+ uint64_t dst_offset,
unsigned int dst_stride,
unsigned int dst_tiling,
unsigned int dst_x, unsigned dst_y)
@@ -944,9 +948,11 @@ void igt_blitter_fast_copy__raw(int fd,
struct drm_i915_gem_exec_object2 objs[3];
struct drm_i915_gem_relocation_entry relocs[2];
uint32_t batch_handle;
+ uint64_t alloc_offset;
uint32_t dword0, dword1;
uint32_t src_pitch, dst_pitch;
int i = 0;
+ bool no_relocs = !gem_has_relocations(fd) && ahnd;
src_pitch = fast_copy_pitch(src_stride, src_tiling);
dst_pitch = fast_copy_pitch(dst_stride, dst_tiling);
@@ -964,30 +970,50 @@ 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++] = dst_offset; /* dst address lower bits */
+ batch[i++] = dst_offset >> 32; /* 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++] = src_offset; /* src address lower bits */
+ batch[i++] = src_offset >> 32; /* 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);
+ alloc_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,
+ fill_relocation(&relocs[0], dst_handle, dst_offset, 4,
I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);
- fill_relocation(&relocs[1], src_handle, src_delta, 8, I915_GEM_DOMAIN_RENDER, 0);
+ fill_relocation(&relocs[1], src_handle, src_offset, 8,
+ I915_GEM_DOMAIN_RENDER, 0);
fill_object(&objs[0], dst_handle, NULL, 0);
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 = alloc_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)), no_relocs);
+ put_offset(ahnd, batch_handle);
gem_close(fd, batch_handle);
}
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index 6f148713b7..cfda9e73de 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -299,10 +299,10 @@ void igt_blitter_fast_copy(struct intel_batchbuffer *batch,
const struct igt_buf *dst, unsigned dst_delta,
unsigned dst_x, unsigned dst_y);
-void igt_blitter_fast_copy__raw(int fd,
+void igt_blitter_fast_copy__raw(int fd, uint64_t ahnd,
/* src */
uint32_t src_handle,
- unsigned int src_delta,
+ uint64_t src_offset,
unsigned int src_stride,
unsigned int src_tiling,
unsigned int src_x, unsigned src_y,
@@ -315,7 +315,7 @@ void igt_blitter_fast_copy__raw(int fd,
/* dst */
uint32_t dst_handle,
- unsigned int dst_delta,
+ uint64_t dst_offset,
unsigned int dst_stride,
unsigned int dst_tiling,
unsigned int dst_x, unsigned dst_y);
--
2.20.1
More information about the Intel-gfx-trybot
mailing list