[virglrenderer-devel] [PATCH 2/3] vtest: Add backing store to each resource
Tomeu Vizoso
tomeu.vizoso at collabora.com
Thu Aug 2 09:09:44 UTC 2018
With the main aim of making vtest's usage of virglrenderer more similar
to that of QEMU, this patch sets a backing store to each resource and
reads from or writes to at each transfer operation.
---
vtest/vtest_protocol.h | 6 ++--
vtest/vtest_renderer.c | 62 ++++++++++++++++++++++++++----------------
2 files changed, 42 insertions(+), 26 deletions(-)
diff --git a/vtest/vtest_protocol.h b/vtest/vtest_protocol.h
index f6176437e6e9..1d3e426998d1 100644
--- a/vtest/vtest_protocol.h
+++ b/vtest/vtest_protocol.h
@@ -54,7 +54,7 @@
/* 0 length cmd */
/* resp VCMD_GET_CAPS + caps */
-#define VCMD_RES_CREATE_SIZE 10
+#define VCMD_RES_CREATE_SIZE 11
#define VCMD_RES_CREATE_RES_HANDLE 0
#define VCMD_RES_CREATE_TARGET 1
#define VCMD_RES_CREATE_FORMAT 2
@@ -65,11 +65,12 @@
#define VCMD_RES_CREATE_ARRAY_SIZE 7
#define VCMD_RES_CREATE_LAST_LEVEL 8
#define VCMD_RES_CREATE_NR_SAMPLES 9
+#define VCMD_RES_CREATE_DATA_SIZE 10
#define VCMD_RES_UNREF_SIZE 1
#define VCMD_RES_UNREF_RES_HANDLE 0
-#define VCMD_TRANSFER_HDR_SIZE 11
+#define VCMD_TRANSFER_HDR_SIZE 12
#define VCMD_TRANSFER_RES_HANDLE 0
#define VCMD_TRANSFER_LEVEL 1
#define VCMD_TRANSFER_STRIDE 2
@@ -81,6 +82,7 @@
#define VCMD_TRANSFER_HEIGHT 8
#define VCMD_TRANSFER_DEPTH 9
#define VCMD_TRANSFER_DATA_SIZE 10
+#define VCMD_TRANSFER_OFFSET 11
#define VCMD_BUSY_WAIT_FLAG_WAIT 1
diff --git a/vtest/vtest_renderer.c b/vtest/vtest_renderer.c
index 8f0262a83b20..6607f20c4bb6 100644
--- a/vtest/vtest_renderer.c
+++ b/vtest/vtest_renderer.c
@@ -35,9 +35,11 @@
#include "vtest_protocol.h"
#include "util.h"
#include "util/u_debug.h"
+#include "util/u_memory.h"
static int ctx_id = 1;
static int fence_id = 1;
+static struct iovec iovecs[1024] = {0,};
static int last_fence;
static void vtest_write_fence(UNUSED void *cookie, uint32_t fence_id_in)
@@ -45,9 +47,17 @@ static void vtest_write_fence(UNUSED void *cookie, uint32_t fence_id_in)
last_fence = fence_id_in;
}
+static void vtest_res_destroy(UNUSED void *cookie, uint32_t handle)
+{
+ if (iovecs[handle].iov_base != NULL)
+ free(iovecs[handle].iov_base);
+ iovecs[handle].iov_base = NULL;
+}
+
struct virgl_renderer_callbacks vtest_cbs = {
.version = 1,
.write_fence = vtest_write_fence,
+ .res_destroy = vtest_res_destroy,
};
struct vtest_renderer {
@@ -234,6 +244,7 @@ int vtest_create_resource(void)
{
uint32_t res_create_buf[VCMD_RES_CREATE_SIZE];
struct virgl_renderer_resource_create_args args;
+ struct iovec *iovec;
int ret;
ret = vtest_block_read(renderer.in_fd, &res_create_buf, sizeof(res_create_buf));
@@ -254,8 +265,24 @@ int vtest_create_resource(void)
args.flags = 0;
ret = virgl_renderer_resource_create(&args, NULL, 0);
+ if (ret)
+ return ret;
virgl_renderer_ctx_attach_resource(ctx_id, args.handle);
+
+ iovec = CALLOC_STRUCT(iovec);
+ if (!iovec)
+ return -ENOMEM;
+
+ iovec->iov_len = res_create_buf[VCMD_RES_CREATE_DATA_SIZE];
+ iovec->iov_base = calloc(1, iovec->iov_len);
+ if (!iovec->iov_base)
+ return -ENOMEM;
+
+ virgl_renderer_resource_attach_iov(args.handle, iovec, 1);
+ assert(args.handle < ARRAY_SIZE(iovecs));
+ iovecs[args.handle] = *iovec;
+
return ret;
}
@@ -312,6 +339,7 @@ int vtest_submit_cmd(uint32_t length_dw)
box.h = thdr_buf[VCMD_TRANSFER_HEIGHT]; \
box.d = thdr_buf[VCMD_TRANSFER_DEPTH]; \
data_size = thdr_buf[VCMD_TRANSFER_DATA_SIZE]; \
+ offset = thdr_buf[VCMD_TRANSFER_OFFSET]; \
} while(0)
@@ -323,8 +351,7 @@ int vtest_transfer_get(UNUSED uint32_t length_dw)
uint32_t stride, layer_stride, handle;
struct virgl_box box;
uint32_t data_size;
- void *ptr;
- struct iovec iovec;
+ uint32_t offset;
ret = vtest_block_read(renderer.in_fd, thdr_buf, VCMD_TRANSFER_HDR_SIZE * 4);
if (ret != VCMD_TRANSFER_HDR_SIZE * 4)
@@ -332,25 +359,20 @@ int vtest_transfer_get(UNUSED uint32_t length_dw)
DECODE_TRANSFER;
- ptr = malloc(data_size);
- if (!ptr)
- return -ENOMEM;
-
- iovec.iov_len = data_size;
- iovec.iov_base = ptr;
ret = virgl_renderer_transfer_read_iov(handle,
ctx_id,
level,
stride,
layer_stride,
&box,
- 0,
- &iovec, 1);
+ offset,
+ NULL, 0);
if (ret)
fprintf(stderr," transfer read failed %d\n", ret);
- ret = vtest_block_write(renderer.out_fd, ptr, data_size);
- free(ptr);
+ ret = vtest_block_write(renderer.out_fd,
+ iovecs[handle].iov_base + offset,
+ data_size);
return ret < 0 ? ret : 0;
}
@@ -362,8 +384,7 @@ int vtest_transfer_put(UNUSED uint32_t length_dw)
uint32_t stride, layer_stride, handle;
struct virgl_box box;
uint32_t data_size;
- void *ptr;
- struct iovec iovec;
+ uint32_t offset;
ret = vtest_block_read(renderer.in_fd, thdr_buf, VCMD_TRANSFER_HDR_SIZE * 4);
if (ret != VCMD_TRANSFER_HDR_SIZE * 4)
@@ -371,27 +392,20 @@ int vtest_transfer_put(UNUSED uint32_t length_dw)
DECODE_TRANSFER;
- ptr = malloc(data_size);
- if (!ptr)
- return -ENOMEM;
-
- ret = vtest_block_read(renderer.in_fd, ptr, data_size);
+ ret = vtest_block_read(renderer.in_fd, iovecs[handle].iov_base + offset, data_size);
if (ret < 0)
return ret;
- iovec.iov_len = data_size;
- iovec.iov_base = ptr;
ret = virgl_renderer_transfer_write_iov(handle,
ctx_id,
level,
stride,
layer_stride,
&box,
- 0,
- &iovec, 1);
+ offset,
+ NULL, 0);
if (ret)
fprintf(stderr," transfer write failed %d\n", ret);
- free(ptr);
return 0;
}
--
2.17.1
More information about the virglrenderer-devel
mailing list