[PATCH i-g-t 5/8] lib/intel_batchbuffer: move engine class selection to helper

Juha-Pekka Heikkila
2026-03-20T13:47:05Z

move engine class selection to helper to avoid duplicate code

Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
---
lib/intel_batchbuffer.c | 42 +++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index cfafaecd0..a3fa58b4f 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -2468,6 +2468,26 @@ static void update_offsets(struct intel_bb *ibb,
}
}

+static unsigned short get_engine_class(int fd, uint64_t flags)
+{
+ switch (flags & I915_EXEC_RING_MASK) {
+ case I915_EXEC_DEFAULT:
+ case I915_EXEC_BLT:
+ return DRM_XE_ENGINE_CLASS_COPY;
+ case I915_EXEC_BSD:
+ return DRM_XE_ENGINE_CLASS_VIDEO_DECODE;
+ case I915_EXEC_RENDER:
+ if (xe_has_engine_class(fd, DRM_XE_ENGINE_CLASS_RENDER))
+ return DRM_XE_ENGINE_CLASS_RENDER;
+ else
+ return DRM_XE_ENGINE_CLASS_COMPUTE;
+ case I915_EXEC_VEBOX:
+ return DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE;
+ default:
+ igt_assert_f(false, "Unknown engine: %x", (uint32_t)flags);
+ }
+}
+
#define LINELEN 76

/*
@@ -2510,26 +2530,8 @@ int __xe_bb_exec(struct intel_bb *ibb, uint64_t flags, bool sync)
inst.engine_instance =
(flags & I915_EXEC_BSD_MASK) >> I915_EXEC_BSD_SHIFT;

- switch (flags & I915_EXEC_RING_MASK) {
- case I915_EXEC_DEFAULT:
- case I915_EXEC_BLT:
- inst.engine_class = DRM_XE_ENGINE_CLASS_COPY;
- break;
- case I915_EXEC_BSD:
- inst.engine_class = DRM_XE_ENGINE_CLASS_VIDEO_DECODE;
- break;
- case I915_EXEC_RENDER:
- if (xe_has_engine_class(ibb->fd, DRM_XE_ENGINE_CLASS_RENDER))
- inst.engine_class = DRM_XE_ENGINE_CLASS_RENDER;
- else
- inst.engine_class = DRM_XE_ENGINE_CLASS_COMPUTE;
- break;
- case I915_EXEC_VEBOX:
- inst.engine_class = DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE;
- break;
- default:
- igt_assert_f(false, "Unknown engine: %x", (uint32_t) flags);
- }
+ inst.engine_class = get_engine_class(ibb->fd, flags);
+
igt_debug("Run on %s\n", xe_engine_class_string(inst.engine_class));

if (ibb->engine_id)
--
2.43.0