From patchwork Thu Apr 11 08:08:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v2,1/2] lib/igt_draw: Add support for writing onto already mmapped buffer From: Vandita Kulkarni X-Patchwork-Id: 588836 Message-Id: <20240411080846.3098-2-vandita.kulkarni@intel.com> To: intel-gfx-trybot@lists.freedesktop.org Cc: Vandita Kulkarni Date: Thu, 11 Apr 2024 13:38:45 +0530 Provide another draw method, for supporting drawing onto already mmapped buffer. Signed-off-by: Vandita Kulkarni --- lib/igt_draw.c | 37 ++++++++++++++++++++++++-- lib/igt_draw.h | 11 +++++++- tests/intel/kms_frontbuffer_tracking.c | 2 +- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/lib/igt_draw.c b/lib/igt_draw.c index 2c01d7b02..e458238f0 100644 --- a/lib/igt_draw.c +++ b/lib/igt_draw.c @@ -75,6 +75,7 @@ struct buf_data { uint32_t handle; uint32_t size; uint32_t stride; + void *buf_ptr; int width; int height; int bpp; @@ -110,6 +111,8 @@ const char *igt_draw_get_method_name(enum igt_draw_method method) return "blt"; case IGT_DRAW_RENDER: return "render"; + case IGT_DRAW_MMAP_PTR: + return "mmap-ptr"; default: igt_assert(false); } @@ -541,6 +544,27 @@ static void draw_rect_mmap_wc(int fd, struct buf_data *buf, struct rect *rect, igt_assert(gem_munmap(ptr, buf->size) == 0); } +static void draw_rect_mmap_ptr(int fd, struct buf_data *buf, struct rect *rect, + uint32_t tiling, uint32_t swizzle, uint32_t color) +{ + igt_assert(buf->buf_ptr != NULL); + + switch (tiling) { + case I915_TILING_NONE: + draw_rect_ptr_linear(buf->buf_ptr, buf->stride, rect, color, buf->bpp); + break; + case I915_TILING_X: + case I915_TILING_Y: + case I915_TILING_4: + draw_rect_ptr_tiled(buf->buf_ptr, buf->stride, tiling, swizzle, rect, + color, buf->bpp); + break; + default: + igt_assert(false); + break; + } +} + static void draw_rect_pwrite_untiled(int fd, struct buf_data *buf, struct rect *rect, uint32_t color) { @@ -839,6 +863,8 @@ static void draw_rect_render(int fd, struct cmd_data *cmd_data, * @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 + * @buf_ptr: Pointer to already mmapped buffer, to be used with IGT_DRAW_MMAP_PTR, + otherwise can be left NULL. * @buf_width: the width of the buffer * @buf_height: the height of the buffer * @tiling: the tiling of the buffer @@ -855,7 +881,7 @@ static void draw_rect_render(int fd, struct cmd_data *cmd_data, */ void igt_draw_rect(int fd, struct buf_ops *bops, uint32_t ctx, uint32_t buf_handle, uint32_t buf_size, uint32_t buf_stride, - int buf_width, int buf_height, + void *buf_ptr, int buf_width, int buf_height, 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) @@ -870,6 +896,7 @@ void igt_draw_rect(int fd, struct buf_ops *bops, uint32_t ctx, .handle = buf_handle, .size = buf_size, .stride = buf_stride, + .buf_ptr = buf_ptr, .width = buf_width, .height = buf_height, .bpp = bpp, @@ -907,6 +934,9 @@ void igt_draw_rect(int fd, struct buf_ops *bops, uint32_t ctx, case IGT_DRAW_RENDER: draw_rect_render(fd, &cmd_data, &buf, &rect, tiling, color); break; + case IGT_DRAW_MMAP_PTR: + draw_rect_mmap_ptr(fd, &buf, &rect, tiling, swizzle, color); + break; default: igt_assert(false); break; @@ -935,7 +965,7 @@ void igt_draw_rect_fb(int fd, struct buf_ops *bops, int rect_w, int rect_h, uint32_t color) { igt_draw_rect(fd, bops, ctx, fb->gem_handle, fb->size, fb->strides[0], - fb->width, fb->height, + fb->driver_priv, fb->width, fb->height, 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)); @@ -971,5 +1001,8 @@ bool igt_draw_supports_method(int fd, enum igt_draw_method method) if (method == IGT_DRAW_RENDER) return !!igt_get_render_copyfunc(intel_get_drm_devid(fd)); + if (method == IGT_DRAW_MMAP_PTR) + return (is_i915_device(fd) && gem_has_mappable_ggtt(fd)) || is_xe_device(fd); + return true; } diff --git a/lib/igt_draw.h b/lib/igt_draw.h index 1dec95e86..e6cce7295 100644 --- a/lib/igt_draw.h +++ b/lib/igt_draw.h @@ -36,6 +36,7 @@ * @IGT_DRAW_PWRITE: draw using the pwrite ioctl. * @IGT_DRAW_BLT: draw using the BLT ring. * @IGT_DRAW_RENDER: draw using the render ring. + * @IGT_DRAW_MMAP_PTR: draw onto already mmapped buffer. * @IGT_DRAW_METHOD_COUNT: useful for iterating through everything. */ enum igt_draw_method { @@ -46,6 +47,14 @@ enum igt_draw_method { IGT_DRAW_BLT, IGT_DRAW_RENDER, IGT_DRAW_METHOD_COUNT, + /* + * FIXME: This enum is placed after IGT_DRAW_METHOD_COUNT in order + * to avoid it being used by other tests which test all the DRAW methods + * Once we add support for this draw method in all those tests keep it + * outside the total count. Some examples are kms_draw_crc, kms_frontbuffer_tracking + * Similarly add support in igt_draw_get_method_name and igt_draw_supports_method + */ + IGT_DRAW_MMAP_PTR, }; const char *igt_draw_get_method_name(enum igt_draw_method method); @@ -54,7 +63,7 @@ bool igt_draw_supports_method(int fd, enum igt_draw_method method); void igt_draw_rect(int fd, struct buf_ops *bops, uint32_t ctx, uint32_t buf_handle, uint32_t buf_size, uint32_t buf_stride, - int buf_width, int buf_height, + void *buf_ptr, int buf_width, int buf_height, 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); diff --git a/tests/intel/kms_frontbuffer_tracking.c b/tests/intel/kms_frontbuffer_tracking.c index e45d17dd6..32cc50712 100644 --- a/tests/intel/kms_frontbuffer_tracking.c +++ b/tests/intel/kms_frontbuffer_tracking.c @@ -2262,7 +2262,7 @@ static void *busy_thread_func(void *data) { while (!busy_thread.stop) igt_draw_rect(drm.fd, drm.bops, 0, busy_thread.handle, - busy_thread.size, busy_thread.stride, + busy_thread.size, busy_thread.stride, NULL, busy_thread.width, busy_thread.height, busy_thread.tiling, IGT_DRAW_BLT, 0, 0, busy_thread.width, busy_thread.height, From patchwork Thu Apr 11 08:08:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [v2,2/2] tests/kms_async_flips: Reuse the already mmapped buffer From: Vandita Kulkarni X-Patchwork-Id: 588837 Message-Id: <20240411080846.3098-3-vandita.kulkarni@intel.com> To: intel-gfx-trybot@lists.freedesktop.org Cc: Vandita Kulkarni , =?UTF-8?q?Zbigniew=20Kempczy=C5=84ski?= Date: Thu, 11 Apr 2024 13:38:46 +0530 In crc test case where we are trying to update the fb dont mmap it agian. On some platforms it was found that updating a newly mmapped buffer takes longer time. Signed-off-by: Vandita Kulkarni Reviewed-by: Zbigniew KempczyƄski --- tests/kms_async_flips.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/kms_async_flips.c b/tests/kms_async_flips.c index 2895168f7..05f1f72cf 100644 --- a/tests/kms_async_flips.c +++ b/tests/kms_async_flips.c @@ -221,12 +221,19 @@ static void test_init_fbs(data_t *data) prev_modifier = data->modifier; if (data->bufs[0].fb_id) { - for (i = 0; i < NUM_FBS; i++) + for (i = 0; i < NUM_FBS; i++) { + if (is_intel_device(data->drm_fd)) + igt_fb_unmap_buffer(&data->bufs[i], data->bufs[i].driver_priv); igt_remove_fb(data->drm_fd, &data->bufs[i]); + } } - for (i = 0; i < NUM_FBS; i++) + for (i = 0; i < NUM_FBS; i++) { make_fb(data, &data->bufs[i], width, height, i); + if (is_intel_device(data->drm_fd)) + data->bufs[i].driver_priv = igt_fb_map_buffer(data->drm_fd, + &data->bufs[i]); + } } igt_plane_set_fb(data->plane, &data->bufs[0]); @@ -538,8 +545,7 @@ static void paint_fb(data_t *data, struct igt_fb *fb, { if (is_intel_device(data->drm_fd)) { igt_draw_rect_fb(data->drm_fd, data->bops, 0, fb, - igt_draw_supports_method(data->drm_fd, IGT_DRAW_MMAP_GTT) ? - IGT_DRAW_MMAP_GTT : IGT_DRAW_MMAP_WC, + IGT_DRAW_MMAP_PTR, 0, 0, width, height, color); } else { cairo_t *cr; @@ -730,8 +736,11 @@ igt_main } igt_fixture { - for (i = 0; i < NUM_FBS; i++) + for (i = 0; i < NUM_FBS; i++) { + if (is_intel_device(data.drm_fd)) + igt_fb_unmap_buffer(&data.bufs[i], data.bufs[i].driver_priv); igt_remove_fb(data.drm_fd, &data.bufs[i]); + } if (is_intel_device(data.drm_fd)) buf_ops_destroy(data.bops);