From 2af3a83136235f43b9bf32675a9183beb51b763e Mon Sep 17 00:00:00 2001 From: Alexandros Frantzis Date: Mon, 27 May 2019 14:32:57 +0300 Subject: [PATCH] vrend: Ignore transfer layer_stride for targets without layers There is no need to fail such transfers, in the same way we don't fail when we are given a stride for targets without height, especially since both stride and layer_stride have a valid (albeit possibly not very useful) interpretation for all targets types. Signed-off-by: Alexandros Frantzis Reviewed-by: Chia-I Wu --- src/vrend_renderer.c | 9 --------- tests/test_virgl_transfer.c | 36 ++++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 5b716ce..be037a1 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -6437,16 +6437,7 @@ static bool check_iov_bounds(struct vrend_resource *res, valid_layer_stride = util_format_get_2d_size(res->base.format, valid_stride, info->box->height); - - /* layer stride only makes sense for 3d,cube and arrays */ if (info->layer_stride) { - if ((res->base.target != PIPE_TEXTURE_3D && - res->base.target != PIPE_TEXTURE_CUBE && - res->base.target != PIPE_TEXTURE_1D_ARRAY && - res->base.target != PIPE_TEXTURE_2D_ARRAY && - res->base.target != PIPE_TEXTURE_CUBE_ARRAY)) - return false; - /* only validate passed in layer_stride for boxes with depth */ if (info->box->depth > 1) { if (info->layer_stride < valid_layer_stride) diff --git a/tests/test_virgl_transfer.c b/tests/test_virgl_transfer.c index d185ae5..b1fcf2e 100644 --- a/tests/test_virgl_transfer.c +++ b/tests/test_virgl_transfer.c @@ -374,7 +374,7 @@ START_TEST(virgl_test_transfer_1d_bad_iov_offset) } END_TEST -START_TEST(virgl_test_transfer_1d_bad_layer_stride) +START_TEST(virgl_test_transfer_1d_strides_are_ignored) { struct virgl_renderer_resource_create_args res; unsigned char data[50*4]; @@ -382,6 +382,7 @@ START_TEST(virgl_test_transfer_1d_bad_layer_stride) int niovs = 1; int ret; struct virgl_box box = { .w = 50, .h = 1, .d = 1 }; + int bad_stride = box.w - 1; testvirgl_init_simple_1d_resource(&res, 1); res.target = PIPE_TEXTURE_1D; @@ -392,8 +393,12 @@ START_TEST(virgl_test_transfer_1d_bad_layer_stride) virgl_renderer_ctx_attach_resource(1, res.handle); - ret = virgl_renderer_transfer_write_iov(res.handle, 1, 0, 0, 50, &box, 0, &iov, niovs); - ck_assert_int_eq(ret, EINVAL); + ret = virgl_renderer_transfer_write_iov(res.handle, 1, 0, bad_stride, 0, + &box, 0, &iov, niovs); + ck_assert_int_eq(ret, 0); + ret = virgl_renderer_transfer_write_iov(res.handle, 1, 0, 0, bad_stride, + &box, 0, &iov, niovs); + ck_assert_int_eq(ret, 0); virgl_renderer_ctx_detach_resource(1, res.handle); @@ -401,7 +406,7 @@ START_TEST(virgl_test_transfer_1d_bad_layer_stride) } END_TEST -START_TEST(virgl_test_transfer_2d_bad_layer_stride) +START_TEST(virgl_test_transfer_2d_layer_stride_is_ignored) { struct virgl_renderer_resource_create_args res; unsigned char data[50*4]; @@ -409,6 +414,7 @@ START_TEST(virgl_test_transfer_2d_bad_layer_stride) int niovs = 1; int ret; struct virgl_box box = { .w = 50, .h = 1, .d = 1 }; + int bad_stride = box.w - 1; testvirgl_init_simple_2d_resource(&res, 1); @@ -417,8 +423,9 @@ START_TEST(virgl_test_transfer_2d_bad_layer_stride) virgl_renderer_ctx_attach_resource(1, res.handle); - ret = virgl_renderer_transfer_write_iov(res.handle, 1, 0, 0, 50, &box, 0, &iov, niovs); - ck_assert_int_eq(ret, EINVAL); + ret = virgl_renderer_transfer_write_iov(res.handle, 1, 0, 0, bad_stride, + &box, 0, &iov, niovs); + ck_assert_int_eq(ret, 0); virgl_renderer_ctx_detach_resource(1, res.handle); @@ -426,7 +433,7 @@ START_TEST(virgl_test_transfer_2d_bad_layer_stride) } END_TEST -START_TEST(virgl_test_transfer_buffer_bad_layer_stride) +START_TEST(virgl_test_transfer_buffer_strides_are_ignored) { struct virgl_renderer_resource_create_args res; unsigned char data[50*4]; @@ -434,6 +441,7 @@ START_TEST(virgl_test_transfer_buffer_bad_layer_stride) int niovs = 1; int ret; struct virgl_box box = { .w = 50, .h = 1, .d = 1 }; + int bad_stride = box.w - 1; testvirgl_init_simple_buffer(&res, 1); @@ -442,8 +450,12 @@ START_TEST(virgl_test_transfer_buffer_bad_layer_stride) virgl_renderer_ctx_attach_resource(1, res.handle); - ret = virgl_renderer_transfer_write_iov(res.handle, 1, 0, 0, 50, &box, 0, &iov, niovs); - ck_assert_int_eq(ret, EINVAL); + ret = virgl_renderer_transfer_write_iov(res.handle, 1, 0, bad_stride, 0, + &box, 0, &iov, niovs); + ck_assert_int_eq(ret, 0); + ret = virgl_renderer_transfer_write_iov(res.handle, 1, 0, bad_stride, 0, + &box, 0, &iov, niovs); + ck_assert_int_eq(ret, 0); virgl_renderer_ctx_detach_resource(1, res.handle); @@ -944,9 +956,9 @@ static Suite *virgl_init_suite(void) tcase_add_test(tc_core, virgl_test_transfer_1d); tcase_add_test(tc_core, virgl_test_transfer_1d_bad_iov); tcase_add_test(tc_core, virgl_test_transfer_1d_bad_iov_offset); - tcase_add_test(tc_core, virgl_test_transfer_1d_bad_layer_stride); - tcase_add_test(tc_core, virgl_test_transfer_2d_bad_layer_stride); - tcase_add_test(tc_core, virgl_test_transfer_buffer_bad_layer_stride); + tcase_add_test(tc_core, virgl_test_transfer_1d_strides_are_ignored); + tcase_add_test(tc_core, virgl_test_transfer_2d_layer_stride_is_ignored); + tcase_add_test(tc_core, virgl_test_transfer_buffer_strides_are_ignored); tcase_add_test(tc_core, virgl_test_transfer_2d_array_bad_layer_stride); tcase_add_test(tc_core, virgl_test_transfer_2d_bad_level); tcase_add_test(tc_core, virgl_test_transfer_2d_bad_stride);