vtest: add vtest_transfer_get_internal

Move the common code of vtest_transfer_{get,get_nop,get2,get2_nop}
to the new function.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
macos/master
Chia-I Wu 4 years ago
parent 5d71e4a32b
commit c8d3e8ff21
  1. 98
      vtest/vtest_renderer.c

@ -755,69 +755,77 @@ static int vtest_transfer_decode_args2(struct vtest_context *ctx,
return 0; return 0;
} }
int vtest_transfer_get(UNUSED uint32_t length_dw) static int vtest_transfer_get_internal(struct vtest_context *ctx,
struct vtest_transfer_args *args,
uint32_t data_size)
{ {
struct vtest_context *ctx = vtest_get_current_context(); struct iovec data_iov;
int ret; int ret = 0;
struct vtest_transfer_args args;
uint32_t data_size;
void *ptr;
struct iovec iovec;
ret = vtest_transfer_decode_args(ctx, &args, &data_size); if (data_size) {
if (ret < 0) { data_iov.iov_len = data_size;
return ret; data_iov.iov_base = malloc(data_size);
} if (!data_iov.iov_base) {
ptr = malloc(data_size);
if (!ptr) {
return -ENOMEM; return -ENOMEM;
} }
}
iovec.iov_len = data_size; if (args) {
iovec.iov_base = ptr; ret = virgl_renderer_transfer_read_iov(args->handle,
ret = virgl_renderer_transfer_read_iov(args.handle,
ctx->ctx_id, ctx->ctx_id,
args.level, args->level,
args.stride, args->stride,
args.layer_stride, args->layer_stride,
&args.box, &args->box,
args.offset, args->offset,
&iovec, 1); data_size ? &data_iov : NULL,
data_size ? 1 : 0);
if (ret) { if (ret) {
fprintf(stderr," transfer read failed %d\n", ret); report_failed_call("virgl_renderer_transfer_read_iov", ret);
}
} else if (data_size) {
memset(data_iov.iov_base, 0, data_iov.iov_len);
} }
ret = vtest_block_write(ctx->out_fd, ptr, data_size); if (data_size) {
ret = vtest_block_write(ctx->out_fd, data_iov.iov_base, data_iov.iov_len);
if (ret > 0)
ret = 0;
free(ptr); free(data_iov.iov_base);
return ret < 0 ? ret : 0; }
return ret;
} }
int vtest_transfer_get_nop(UNUSED uint32_t length_dw) int vtest_transfer_get(UNUSED uint32_t length_dw)
{ {
struct vtest_context *ctx = vtest_get_current_context(); struct vtest_context *ctx = vtest_get_current_context();
int ret; int ret;
struct vtest_transfer_args args; struct vtest_transfer_args args;
uint32_t data_size; uint32_t data_size;
void *ptr;
ret = vtest_transfer_decode_args(ctx, &args, &data_size); ret = vtest_transfer_decode_args(ctx, &args, &data_size);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
ptr = malloc(data_size); return vtest_transfer_get_internal(ctx, &args, data_size);
if (!ptr) { }
return -ENOMEM;
}
memset(ptr, 0, data_size); int vtest_transfer_get_nop(UNUSED uint32_t length_dw)
{
struct vtest_context *ctx = vtest_get_current_context();
int ret;
struct vtest_transfer_args args;
uint32_t data_size;
ret = vtest_block_write(ctx->out_fd, ptr, data_size); ret = vtest_transfer_decode_args(ctx, &args, &data_size);
if (ret < 0) {
return ret;
}
free(ptr); return vtest_transfer_get_internal(ctx, NULL, data_size);
return ret < 0 ? ret : 0;
} }
int vtest_transfer_put(UNUSED uint32_t length_dw) int vtest_transfer_put(UNUSED uint32_t length_dw)
@ -910,19 +918,7 @@ int vtest_transfer_get2(UNUSED uint32_t length_dw)
return report_failure("offset larger then length of backing store", -EFAULT); return report_failure("offset larger then length of backing store", -EFAULT);
} }
ret = virgl_renderer_transfer_read_iov(args.handle, return vtest_transfer_get_internal(ctx, &args, 0);
ctx->ctx_id,
args.level,
args.stride,
args.layer_stride,
&args.box,
args.offset,
NULL, 0);
if (ret) {
return report_failed_call("virgl_renderer_transfer_read_iov", ret);
}
return 0;
} }
int vtest_transfer_get2_nop(UNUSED uint32_t length_dw) int vtest_transfer_get2_nop(UNUSED uint32_t length_dw)
@ -946,7 +942,7 @@ int vtest_transfer_get2_nop(UNUSED uint32_t length_dw)
return report_failure("offset larger then length of backing store", -EFAULT); return report_failure("offset larger then length of backing store", -EFAULT);
} }
return 0; return vtest_transfer_get_internal(ctx, NULL, 0);
} }
int vtest_transfer_put2(UNUSED uint32_t length_dw) int vtest_transfer_put2(UNUSED uint32_t length_dw)

Loading…
Cancel
Save