diff options
author | Alexandros Frantzis <alexandros.frantzis@collabora.com> | 2019-05-27 19:32:31 +0300 |
---|---|---|
committer | Gurchetan Singh <gurchetansingh@google.com> | 2019-06-03 19:31:17 -0700 |
commit | 0bb764b6cfd302022eecb79fd09ea6bcb75d4c68 (patch) | |
tree | af68fb4d14141d012490f5f00d56227b7242314a /tests | |
parent | 2af3a83136235f43b9bf32675a9183beb51b763e (diff) |
vrend: Improve iov bound checking for transfers
This commit improves bound checking by more accurately calculating
the expected transfer size. This improvement is achieved in two ways:
1. Using the image level (layer_)stride when the (layer_)stride is 0,
which matches the interpretation we use for performing the actual
read/write.
2. Calculating the transfer size by using the exact end offset in
the image, instead of using multiples of whole image rows.
The increased accuracy increases safety, and also allows us to support
some transfers with explicit strides that were previously rejected (see
added test).
Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_virgl_transfer.c | 34 | ||||
-rw-r--r-- | tests/testvirgl_encode.c | 13 | ||||
-rw-r--r-- | tests/testvirgl_encode.h | 7 |
3 files changed, 53 insertions, 1 deletions
diff --git a/tests/test_virgl_transfer.c b/tests/test_virgl_transfer.c index b1fcf2e..c8bf032 100644 --- a/tests/test_virgl_transfer.c +++ b/tests/test_virgl_transfer.c @@ -932,6 +932,35 @@ START_TEST(virgl_test_copy_transfer_to_staging_with_iov_succeeds) } END_TEST +START_TEST(virgl_test_transfer_near_res_bounds_with_stride_succeeds) +{ + struct virgl_context ctx = {0}; + struct virgl_resource res = {0}; + int res_width = 4; + int res_height = 3; + int res_stride = res_width * 4; + struct pipe_box box = {.x = 2, .y = 1, .z = 0, .width = 2, .height = 2, .depth = 1}; + int ret; + + ret = testvirgl_init_ctx_cmdbuf(&ctx); + ck_assert_int_eq(ret, 0); + + ret = testvirgl_create_backed_simple_2d_res(&res, 1, res_width, res_height); + ck_assert_int_eq(ret, 0); + virgl_renderer_ctx_attach_resource(ctx.ctx_id, res.handle); + + virgl_encoder_transfer_with_stride(&ctx, &res, 0, 0, &box, 6 * 4, VIRGL_TRANSFER_TO_HOST, + res_stride, 0); + + ret = virgl_renderer_submit_cmd(ctx.cbuf->buf, ctx.ctx_id, ctx.cbuf->cdw); + ck_assert_int_eq(ret, 0); + + virgl_renderer_ctx_detach_resource(ctx.ctx_id, res.handle); + testvirgl_destroy_backed_res(&res); + testvirgl_fini_ctx_cmdbuf(&ctx); +} +END_TEST + static Suite *virgl_init_suite(void) { Suite *s; @@ -986,6 +1015,11 @@ static Suite *virgl_init_suite(void) suite_add_tcase(s, tc_core); + tc_core = tcase_create("transfer_command_bounds"); + tcase_add_test(tc_core, virgl_test_transfer_near_res_bounds_with_stride_succeeds); + + suite_add_tcase(s, tc_core); + return s; } diff --git a/tests/testvirgl_encode.c b/tests/testvirgl_encode.c index 5707482..6f7192a 100644 --- a/tests/testvirgl_encode.c +++ b/tests/testvirgl_encode.c @@ -569,10 +569,21 @@ int virgl_encoder_transfer(struct virgl_context *ctx, const struct pipe_box *box, unsigned offset, unsigned direction) { + return virgl_encoder_transfer_with_stride(ctx, res, level, usage, box, + offset, direction, 0, 0); +} + +int virgl_encoder_transfer_with_stride(struct virgl_context *ctx, + struct virgl_resource *res, + unsigned level, unsigned usage, + const struct pipe_box *box, + unsigned offset, unsigned direction, + unsigned stride, unsigned layer_stride) +{ uint32_t command; command = VIRGL_CMD0(VIRGL_CCMD_TRANSFER3D, 0, VIRGL_TRANSFER3D_SIZE); virgl_encoder_write_dword(ctx->cbuf, command); - virgl_encoder_transfer3d_common(ctx, res, level, usage, box, 0, 0); + virgl_encoder_transfer3d_common(ctx, res, level, usage, box, stride, layer_stride); virgl_encoder_write_dword(ctx->cbuf, offset); virgl_encoder_write_dword(ctx->cbuf, direction); return 0; diff --git a/tests/testvirgl_encode.h b/tests/testvirgl_encode.h index a41d4ce..c5bd9c1 100644 --- a/tests/testvirgl_encode.h +++ b/tests/testvirgl_encode.h @@ -149,6 +149,13 @@ int virgl_encoder_transfer(struct virgl_context *ctx, const struct pipe_box *box, unsigned offset, unsigned direction); +int virgl_encoder_transfer_with_stride(struct virgl_context *ctx, + struct virgl_resource *res, + unsigned level, unsigned usage, + const struct pipe_box *box, + unsigned offset, unsigned direction, + unsigned stride, unsigned layer_stride); + int virgl_encoder_copy_transfer(struct virgl_context *ctx, struct virgl_resource *res, unsigned level, unsigned usage, |