[PATCH i-g-t 1/3] lib/gem_submission: Add kernel exec object alignment capability

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Wed Sep 22 18:20:18 UTC 2021


With newer gens passing non-zero alignment will be forbidden.
Add check which detects kernel supports it or not.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Petri Latvala <petri.latvala at intel.com>
Cc: Ashutosh Dixit <ashutosh.dixit at intel.com>
---
 lib/i915/gem_submission.c | 32 ++++++++++++++++++++++++++++++++
 lib/i915/gem_submission.h |  1 +
 2 files changed, 33 insertions(+)

diff --git a/lib/i915/gem_submission.c b/lib/i915/gem_submission.c
index f1af4f97c..459ee21f9 100644
--- a/lib/i915/gem_submission.c
+++ b/lib/i915/gem_submission.c
@@ -472,3 +472,35 @@ bool gem_has_relocations(int i915)
 
 	return has_relocs;
 }
+
+/**
+ * gem_allows_passing_alignment
+ * @fd: opened i915 drm file descriptor
+ *
+ * Check does i915 driver allows passing alignment in exec object to
+ * handle in kernel and adjust object offset accordingly.
+ *
+ * Returns: true if kernel supports setting offset to be aligned, otherwise
+ * false.
+ */
+bool gem_allows_passing_alignment(int fd)
+{
+	struct drm_i915_gem_exec_object2 obj = {
+		.handle = gem_create(fd, 4096),
+	};
+	struct drm_i915_gem_execbuffer2 execbuf = {
+		.buffers_ptr = to_user_pointer(&obj),
+		.buffer_count = 1,
+	};
+	bool ret;
+	const uint32_t bbe = MI_BATCH_BUFFER_END;
+
+	gem_write(fd, obj.handle, 0, &bbe, sizeof(bbe));
+	gem_execbuf(fd, &execbuf);
+
+	obj.alignment = 0x2000;
+	ret = __gem_execbuf(fd, &execbuf) == 0;
+	gem_close(fd, obj.handle);
+
+	return ret;
+}
diff --git a/lib/i915/gem_submission.h b/lib/i915/gem_submission.h
index 9b3e2a4e5..9f1ee8125 100644
--- a/lib/i915/gem_submission.h
+++ b/lib/i915/gem_submission.h
@@ -55,5 +55,6 @@ unsigned int gem_submission_measure(int i915, const intel_ctx_cfg_t *cfg,
 
 void gem_test_all_engines(int fd);
 bool gem_has_relocations(int fd);
+bool gem_allows_passing_alignment(int fd);
 
 #endif /* GEM_SUBMISSION_H */
-- 
2.26.0



More information about the Intel-gfx-trybot mailing list