vtest: add vtest_transfer_decode_args

Replace DECODE_TRANSFER macro by the new helper.

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 0f5cb454e1
commit e1ccc59b5b
  1. 142
      vtest/vtest_renderer.c

@ -687,46 +687,62 @@ int vtest_submit_cmd(uint32_t length_dw)
return ret ? -1 : 0; return ret ? -1 : 0;
} }
#define DECODE_TRANSFER \ struct vtest_transfer_args {
do { \ uint32_t handle;
handle = thdr_buf[VCMD_TRANSFER_RES_HANDLE]; \ uint32_t level;
level = thdr_buf[VCMD_TRANSFER_LEVEL]; \ uint32_t stride;
stride = thdr_buf[VCMD_TRANSFER_STRIDE]; \ uint32_t layer_stride;
layer_stride = thdr_buf[VCMD_TRANSFER_LAYER_STRIDE]; \ struct virgl_box box;
box.x = thdr_buf[VCMD_TRANSFER_X]; \ uint32_t offset;
box.y = thdr_buf[VCMD_TRANSFER_Y]; \ };
box.z = thdr_buf[VCMD_TRANSFER_Z]; \
box.w = thdr_buf[VCMD_TRANSFER_WIDTH]; \ static int vtest_transfer_decode_args(struct vtest_context *ctx,
box.h = thdr_buf[VCMD_TRANSFER_HEIGHT]; \ struct vtest_transfer_args *args,
box.d = thdr_buf[VCMD_TRANSFER_DEPTH]; \ uint32_t *data_size)
data_size = thdr_buf[VCMD_TRANSFER_DATA_SIZE]; \ {
} while(0) uint32_t thdr_buf[VCMD_TRANSFER_HDR_SIZE];
int ret;
ret = ctx->input->read(ctx->input, thdr_buf, sizeof(thdr_buf));
if (ret != sizeof(thdr_buf)) {
return -1;
}
args->handle = thdr_buf[VCMD_TRANSFER_RES_HANDLE];
args->level = thdr_buf[VCMD_TRANSFER_LEVEL];
args->stride = thdr_buf[VCMD_TRANSFER_STRIDE];
args->layer_stride = thdr_buf[VCMD_TRANSFER_LAYER_STRIDE];
args->box.x = thdr_buf[VCMD_TRANSFER_X];
args->box.y = thdr_buf[VCMD_TRANSFER_Y];
args->box.z = thdr_buf[VCMD_TRANSFER_Z];
args->box.w = thdr_buf[VCMD_TRANSFER_WIDTH];
args->box.h = thdr_buf[VCMD_TRANSFER_HEIGHT];
args->box.d = thdr_buf[VCMD_TRANSFER_DEPTH];
args->offset = 0;
*data_size = thdr_buf[VCMD_TRANSFER_DATA_SIZE];
if (*data_size > renderer.max_length) {
return -ENOMEM;
}
return 0;
}
int vtest_transfer_get(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();
uint32_t thdr_buf[VCMD_TRANSFER_HDR_SIZE];
int ret; int ret;
int level; struct vtest_transfer_args args;
uint32_t stride, layer_stride, handle;
struct virgl_box box;
uint32_t data_size; uint32_t data_size;
void *ptr; void *ptr;
struct iovec iovec; struct iovec iovec;
ret = ctx->input->read(ctx->input, thdr_buf, ret = vtest_transfer_decode_args(ctx, &args, &data_size);
VCMD_TRANSFER_HDR_SIZE * 4); if (ret < 0) {
if (ret != VCMD_TRANSFER_HDR_SIZE * 4) {
return ret; return ret;
} }
DECODE_TRANSFER;
if (data_size > renderer.max_length) {
return -ENOMEM;
}
ptr = malloc(data_size); ptr = malloc(data_size);
if (!ptr) { if (!ptr) {
return -ENOMEM; return -ENOMEM;
@ -734,13 +750,13 @@ int vtest_transfer_get(UNUSED uint32_t length_dw)
iovec.iov_len = data_size; iovec.iov_len = data_size;
iovec.iov_base = ptr; iovec.iov_base = ptr;
ret = virgl_renderer_transfer_read_iov(handle, ret = virgl_renderer_transfer_read_iov(args.handle,
ctx->ctx_id, ctx->ctx_id,
level, args.level,
stride, args.stride,
layer_stride, args.layer_stride,
&box, &args.box,
0, args.offset,
&iovec, 1); &iovec, 1);
if (ret) { if (ret) {
fprintf(stderr," transfer read failed %d\n", ret); fprintf(stderr," transfer read failed %d\n", ret);
@ -755,26 +771,16 @@ int vtest_transfer_get(UNUSED uint32_t length_dw)
int vtest_transfer_get_nop(UNUSED uint32_t length_dw) int vtest_transfer_get_nop(UNUSED uint32_t length_dw)
{ {
struct vtest_context *ctx = vtest_get_current_context(); struct vtest_context *ctx = vtest_get_current_context();
uint32_t thdr_buf[VCMD_TRANSFER_HDR_SIZE];
int ret; int ret;
UNUSED int level; struct vtest_transfer_args args;
UNUSED uint32_t stride, layer_stride, handle;
UNUSED struct virgl_box box;
uint32_t data_size; uint32_t data_size;
void *ptr; void *ptr;
ret = ctx->input->read(ctx->input, thdr_buf, ret = vtest_transfer_decode_args(ctx, &args, &data_size);
VCMD_TRANSFER_HDR_SIZE * 4); if (ret < 0) {
if (ret != VCMD_TRANSFER_HDR_SIZE * 4) {
return ret; return ret;
} }
DECODE_TRANSFER;
if (data_size > renderer.max_length) {
return -ENOMEM;
}
ptr = malloc(data_size); ptr = malloc(data_size);
if (!ptr) { if (!ptr) {
return -ENOMEM; return -ENOMEM;
@ -791,27 +797,17 @@ int vtest_transfer_get_nop(UNUSED uint32_t length_dw)
int vtest_transfer_put(UNUSED uint32_t length_dw) int vtest_transfer_put(UNUSED uint32_t length_dw)
{ {
struct vtest_context *ctx = vtest_get_current_context(); struct vtest_context *ctx = vtest_get_current_context();
uint32_t thdr_buf[VCMD_TRANSFER_HDR_SIZE];
int ret; int ret;
int level; struct vtest_transfer_args args;
uint32_t stride, layer_stride, handle;
struct virgl_box box;
uint32_t data_size; uint32_t data_size;
void *ptr; void *ptr;
struct iovec iovec; struct iovec iovec;
ret = ctx->input->read(ctx->input, thdr_buf, ret = vtest_transfer_decode_args(ctx, &args, &data_size);
VCMD_TRANSFER_HDR_SIZE * 4); if (ret < 0) {
if (ret != VCMD_TRANSFER_HDR_SIZE * 4) {
return ret; return ret;
} }
DECODE_TRANSFER;
if (data_size > renderer.max_length) {
return -ENOMEM;
}
ptr = malloc(data_size); ptr = malloc(data_size);
if (!ptr) { if (!ptr) {
return -ENOMEM; return -ENOMEM;
@ -824,13 +820,13 @@ int vtest_transfer_put(UNUSED uint32_t length_dw)
iovec.iov_len = data_size; iovec.iov_len = data_size;
iovec.iov_base = ptr; iovec.iov_base = ptr;
ret = virgl_renderer_transfer_write_iov(handle, ret = virgl_renderer_transfer_write_iov(args.handle,
ctx->ctx_id, ctx->ctx_id,
level, args.level,
stride, args.stride,
layer_stride, args.layer_stride,
&box, &args.box,
0, args.offset,
&iovec, 1); &iovec, 1);
if (ret) { if (ret) {
fprintf(stderr," transfer write failed %d\n", ret); fprintf(stderr," transfer write failed %d\n", ret);
@ -843,26 +839,16 @@ int vtest_transfer_put(UNUSED uint32_t length_dw)
int vtest_transfer_put_nop(UNUSED uint32_t length_dw) int vtest_transfer_put_nop(UNUSED uint32_t length_dw)
{ {
struct vtest_context *ctx = vtest_get_current_context(); struct vtest_context *ctx = vtest_get_current_context();
uint32_t thdr_buf[VCMD_TRANSFER_HDR_SIZE];
int ret; int ret;
UNUSED int level; struct vtest_transfer_args args;
UNUSED uint32_t stride, layer_stride, handle;
UNUSED struct virgl_box box;
uint32_t data_size; uint32_t data_size;
void *ptr; void *ptr;
ret = ctx->input->read(ctx->input, thdr_buf, ret = vtest_transfer_decode_args(ctx, &args, &data_size);
VCMD_TRANSFER_HDR_SIZE * 4); if (ret < 0) {
if (ret != VCMD_TRANSFER_HDR_SIZE * 4) {
return ret; return ret;
} }
DECODE_TRANSFER;
if (data_size > renderer.max_length) {
return -ENOMEM;
}
ptr = malloc(data_size); ptr = malloc(data_size);
if (!ptr) { if (!ptr) {
return -ENOMEM; return -ENOMEM;

Loading…
Cancel
Save