[i-g-t v3 08/13] lib/intel_batchbuffer: No relocations in blitter fast copy
Bhanuprakash Modem
bhanuprakash.modem at intel.com
Wed Jun 30 11:44:53 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/igt_fb.c | 24 ++++++++++++++++---
lib/intel_batchbuffer.c | 51 +++++++++++++++++++++++++++++------------
lib/intel_batchbuffer.h | 6 ++---
3 files changed, 60 insertions(+), 21 deletions(-)
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 71b8985529..389325c923 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -2404,6 +2404,9 @@ 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;
+ uint64_t dst_offset, src_offset;
igt_assert_eq(dst_fb->fd, src_fb->fd);
igt_assert_eq(dst_fb->num_planes, src_fb->num_planes);
@@ -2411,6 +2414,15 @@ static void blitcopy(const struct igt_fb *dst_fb,
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);
+ }
+
+ dst_offset = get_offset(ahnd, dst_fb->gem_handle, dst_fb->size, 0);
+ src_offset = get_offset(ahnd, src_fb->gem_handle, src_fb->size, 0);
+
for (int i = 0; i < dst_fb->num_planes; i++) {
igt_assert_eq(dst_fb->plane_bpp[i], src_fb->plane_bpp[i]);
igt_assert_eq(dst_fb->plane_width[i], src_fb->plane_width[i]);
@@ -2421,9 +2433,9 @@ 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,
+ igt_blitter_fast_copy__raw(dst_fb->fd, ahnd, ctx,
src_fb->gem_handle,
- src_fb->offsets[i],
+ src_offset + src_fb->offsets[i],
src_fb->strides[i],
src_tiling,
0, 0, /* src_x, src_y */
@@ -2431,7 +2443,7 @@ 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],
+ dst_offset + dst_fb->offsets[i],
dst_fb->strides[i],
dst_tiling,
0, 0 /* dst_x, dst_y */);
@@ -2452,6 +2464,12 @@ static void blitcopy(const struct igt_fb *dst_fb,
0, 0 /* dst_x, dst_y */);
}
}
+ put_offset(ahnd, dst_fb->gem_handle);
+ put_offset(ahnd, src_fb->gem_handle);
+ put_ahnd(ahnd);
+
+ if (ctx)
+ gem_context_destroy(dst_fb->fd, ctx);
}
static void free_linear_mapping(struct fb_blit_upload *blit)
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index cc976a6243..4472e76864 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);
}
@@ -901,8 +906,10 @@ void igt_blitter_src_copy(int fd,
/**
* igt_blitter_fast_copy__raw:
* @fd: file descriptor of the i915 driver
+ * @ahnd: handle to an allocator
+ * @ctx: context
* @src_handle: GEM handle of the source buffer
- * @src_delta: offset into the source GEM bo, in bytes
+ * @src_offset: offset into the source GEM bo
* @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 +918,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: offset into the destination GEM bo
* @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 +926,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, uint32_t ctx,
/* 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 +942,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)
@@ -947,6 +954,7 @@ void igt_blitter_fast_copy__raw(int fd,
uint32_t dword0, dword1;
uint32_t src_pitch, dst_pitch;
int i = 0;
+ uint64_t batch_offset;
src_pitch = fast_copy_pitch(src_stride, src_tiling);
dst_pitch = fast_copy_pitch(dst_stride, dst_tiling);
@@ -964,31 +972,44 @@ 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);
+ 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,
+ 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 (ahnd) {
+ 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;
+
+ fill_object(&objs[2], batch_handle, NULL, 0);
+ objs[2].offset = batch_offset;
+ } else {
+ fill_object(&objs[2], batch_handle, relocs, 2);
+ }
+ exec_blit(fd, objs, 3, intel_gen(intel_get_drm_devid(fd)), ctx);
gem_close(fd, batch_handle);
+ put_offset(ahnd, batch_handle);
}
/**
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index 6f148713b7..3ddd460612 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, uint32_t ctx,
/* 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