[i-g-t 21/27] lib/igt_draw: Add support for VM bind mode
Bhanuprakash Modem
bhanuprakash.modem at intel.com
Mon Jan 23 09:43:29 UTC 2023
Add support to create a @cfg configuration (when working with custom
engines layout) to work in vm_bind mode.
This patch will also moves the ctx creation logic to lib, instead of
creating at test level.
Credits-to: Niranjana Vishwanathapura <niranjana.vishwanathapura at intel.com>
Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem at intel.com>
---
lib/igt_draw.c | 59 ++++++++++++++++++++++++++++++++++++++++----------
lib/igt_draw.h | 6 ++---
2 files changed, 50 insertions(+), 15 deletions(-)
diff --git a/lib/igt_draw.c b/lib/igt_draw.c
index 975d65cd..e8437fb3 100644
--- a/lib/igt_draw.c
+++ b/lib/igt_draw.c
@@ -36,6 +36,8 @@
#include "i830_reg.h"
#include "i915/gem_create.h"
#include "i915/gem_mman.h"
+#include "i915/gem_vm.h"
+#include "i915/i915_vm_bind.h"
#ifndef PAGE_ALIGN
#ifndef PAGE_SIZE
@@ -65,6 +67,7 @@
struct cmd_data {
struct buf_ops *bops;
uint32_t ctx;
+ intel_ctx_cfg_t *cfg;
};
struct buf_data {
@@ -780,7 +783,10 @@ static void draw_rect_render(int fd, struct cmd_data *cmd_data,
src = create_buf(fd, cmd_data->bops, &tmp, I915_TILING_NONE);
dst = create_buf(fd, cmd_data->bops, buf, tiling);
- ibb = intel_bb_create_with_context(fd, cmd_data->ctx, NULL, PAGE_SIZE);
+ if (cmd_data->cfg)
+ ibb = intel_bb_create_for_vm_bind_mode(fd, cmd_data->ctx, cmd_data->cfg, PAGE_SIZE);
+ else
+ ibb = intel_bb_create_with_context(fd, cmd_data->ctx, NULL, PAGE_SIZE);
rendercopy(ibb, src, 0, 0, rect->w, rect->h, dst, rect->x, rect->y);
@@ -794,7 +800,6 @@ static void draw_rect_render(int fd, struct cmd_data *cmd_data,
* igt_draw_rect:
* @fd: the DRM file descriptor
* @bops: buf ops, only required for IGT_DRAW_BLT and IGT_DRAW_RENDER
- * @ctx: the context, can be 0 if you don't want to think about it
* @buf_handle: the handle of the buffer where you're going to draw to
* @buf_size: the size of the buffer
* @buf_stride: the stride of the buffer
@@ -810,18 +815,18 @@ static void draw_rect_render(int fd, struct cmd_data *cmd_data,
* This function draws a colored rectangle on the destination buffer, allowing
* you to specify the method used to draw the rectangle.
*/
-void igt_draw_rect(int fd, struct buf_ops *bops, uint32_t ctx,
+void igt_draw_rect(int fd, struct buf_ops *bops,
uint32_t buf_handle, uint32_t buf_size, uint32_t buf_stride,
uint32_t tiling, enum igt_draw_method method,
int rect_x, int rect_y, int rect_w, int rect_h,
uint32_t color, int bpp)
{
uint32_t buf_tiling, swizzle;
-
- struct cmd_data cmd_data = {
- .bops = bops,
- .ctx = ctx,
- };
+ const intel_ctx_t *ctx = NULL;
+ uint32_t vm_id, ctx_id = 0;
+ intel_ctx_cfg_t *cfg = NULL;
+ intel_ctx_cfg_t ctx_cfg = { };
+ struct cmd_data cmd_data = { };
struct buf_data buf = {
.handle = buf_handle,
.size = buf_size,
@@ -835,6 +840,32 @@ void igt_draw_rect(int fd, struct buf_ops *bops, uint32_t ctx,
.h = rect_h,
};
+ if (gem_has_vm(fd) &&
+ (method == IGT_DRAW_RENDER || method == IGT_DRAW_BLT)) {
+ struct drm_i915_gem_context_param param = {
+ .param = I915_CONTEXT_PARAM_RECOVERABLE,
+ .value = 0,
+ };
+
+ vm_id = gem_vm_create_in_vm_bind_mode(fd);
+ ctx_cfg.engines[0] = (struct i915_engine_class_instance) {
+ .engine_class = (method == IGT_DRAW_RENDER) ?
+ I915_ENGINE_CLASS_RENDER : I915_ENGINE_CLASS_COPY
+ };
+ ctx_cfg.num_engines = 1;
+ ctx = intel_ctx_create(fd, &ctx_cfg);
+ ctx_id = ctx->id;
+ param.ctx_id = ctx_id;
+ gem_context_set_param(fd, ¶m);
+ gem_context_set_vm(fd, ctx_id, vm_id);
+ vm_id = gem_context_get_vm(fd, ctx_id);
+ cfg = &ctx_cfg;
+ }
+
+ cmd_data.bops = bops;
+ cmd_data.ctx = ctx_id;
+ cmd_data.cfg = cfg;
+
swizzle = I915_BIT_6_SWIZZLE_NONE;
if (tiling != I915_TILING_NONE && gem_available_fences(fd)) {
gem_get_tiling(fd, buf_handle, &buf_tiling, &swizzle);
@@ -864,6 +895,10 @@ void igt_draw_rect(int fd, struct buf_ops *bops, uint32_t ctx,
igt_assert(false);
break;
}
+
+ intel_ctx_destroy(fd, ctx);
+ if (vm_id)
+ gem_vm_destroy(fd, vm_id);
}
/**
@@ -883,11 +918,11 @@ void igt_draw_rect(int fd, struct buf_ops *bops, uint32_t ctx,
* of manually providing its details. See igt_draw_rect.
*/
void igt_draw_rect_fb(int fd, struct buf_ops *bops,
- uint32_t ctx, struct igt_fb *fb,
- enum igt_draw_method method, int rect_x, int rect_y,
+ struct igt_fb *fb, enum igt_draw_method method,
+ int rect_x, int rect_y,
int rect_w, int rect_h, uint32_t color)
{
- igt_draw_rect(fd, bops, ctx, fb->gem_handle, fb->size, fb->strides[0],
+ igt_draw_rect(fd, bops, fb->gem_handle, fb->size, fb->strides[0],
igt_fb_mod_to_tiling(fb->modifier), method,
rect_x, rect_y, rect_w, rect_h, color,
igt_drm_format_to_bpp(fb->drm_format));
@@ -903,7 +938,7 @@ void igt_draw_rect_fb(int fd, struct buf_ops *bops,
*/
void igt_draw_fill_fb(int fd, struct igt_fb *fb, uint32_t color)
{
- igt_draw_rect_fb(fd, NULL, 0, fb,
+ igt_draw_rect_fb(fd, NULL, fb,
gem_has_mappable_ggtt(fd) ? IGT_DRAW_MMAP_GTT :
IGT_DRAW_MMAP_WC,
0, 0, fb->width, fb->height, color);
diff --git a/lib/igt_draw.h b/lib/igt_draw.h
index 2d18ef6c..6b60afe9 100644
--- a/lib/igt_draw.h
+++ b/lib/igt_draw.h
@@ -50,15 +50,15 @@ enum igt_draw_method {
const char *igt_draw_get_method_name(enum igt_draw_method method);
-void igt_draw_rect(int fd, struct buf_ops *bops, uint32_t ctx,
+void igt_draw_rect(int fd, struct buf_ops *bops,
uint32_t buf_handle, uint32_t buf_size, uint32_t buf_stride,
uint32_t tiling, enum igt_draw_method method,
int rect_x, int rect_y, int rect_w, int rect_h,
uint32_t color, int bpp);
void igt_draw_rect_fb(int fd, struct buf_ops *bops,
- uint32_t ctx, struct igt_fb *fb,
- enum igt_draw_method method, int rect_x, int rect_y,
+ struct igt_fb *fb, enum igt_draw_method method,
+ int rect_x, int rect_y,
int rect_w, int rect_h, uint32_t color);
void igt_draw_fill_fb(int fd, struct igt_fb *fb, uint32_t color);
--
2.39.0
More information about the Intel-gfx-trybot
mailing list