summaryrefslogtreecommitdiff
path: root/vtest
diff options
context:
space:
mode:
authorDave Airlie <airlied@gmail.com>2015-03-13 17:32:08 +1000
committerDave Airlie <airlied@gmail.com>2015-03-13 17:32:08 +1000
commit437c841b7ef5aaa1df34d016d0172bb0e5effed7 (patch)
tree164e8f40a2b46e2d306fa90361c847a6e61de487 /vtest
parent0b27e44304cd3bee8f0a0fedb4f970872dfa584f (diff)
vtest: add a bit more code
Diffstat (limited to 'vtest')
-rw-r--r--vtest/vtest.h3
-rw-r--r--vtest/vtest_protocol.h62
-rw-r--r--vtest/vtest_renderer.c55
-rw-r--r--vtest/vtest_server.c20
4 files changed, 136 insertions, 4 deletions
diff --git a/vtest/vtest.h b/vtest/vtest.h
index 2453ca3..d599a05 100644
--- a/vtest/vtest.h
+++ b/vtest/vtest.h
@@ -4,5 +4,8 @@
int vtest_create_renderer(int fd);
int vtest_send_caps(void);
+
+int vtest_create_resource(void);
+int vtest_resource_unref(void);
#endif
diff --git a/vtest/vtest_protocol.h b/vtest/vtest_protocol.h
new file mode 100644
index 0000000..f06896f
--- /dev/null
+++ b/vtest/vtest_protocol.h
@@ -0,0 +1,62 @@
+
+#ifndef VTEST_PROTOCOL
+#define VTEST_PROTOCOL
+
+#define VTEST_DEFAULT_SOCKET_NAME "/tmp/.virgl_test"
+
+/* 32-bit length field */
+/* 32-bit cmd field */
+#define VTEST_HDR_SIZE 2
+#define VTEST_CMD_LEN 0 /* length of data */
+#define VTEST_CMD_ID 1
+#define VTEST_CMD_DATA_START 2
+
+/* vtest cmds */
+#define VCMD_GET_CAPS 1
+
+#define VCMD_RESOURCE_CREATE 2
+#define VCMD_RESOURCE_UNREF 3
+
+#define VCMD_TRANSFER_GET 4
+#define VCMD_TRANSFER_PUT 5
+
+#define VCMD_SUBMIT_CMD 6
+
+/* get caps */
+/* 0 length cmd */
+/* resp VCMD_GET_CAPS + caps */
+
+/* context create */
+#define VCMD_CONTEXT_CREATE_CTX_ID 0
+/* context destroy */
+#define VCMD_CONTEXT_DESTROY_CTX_ID 0
+
+#define VCMD_RES_CREATE_SIZE 10
+#define VCMD_RES_CREATE_RES_HANDLE 0
+#define VCMD_RES_CREATE_TARGET 1
+#define VCMD_RES_CREATE_FORMAT 2
+#define VCMD_RES_CREATE_BIND 3
+#define VCMD_RES_CREATE_WIDTH 4
+#define VCMD_RES_CREATE_HEIGHT 5
+#define VCMD_RES_CREATE_DEPTH 6
+#define VCMD_RES_CREATE_ARRAY_SIZE 7
+#define VCMD_RES_CREATE_LAST_LEVEL 8
+#define VCMD_RES_CREATE_NR_SAMPLES 9
+
+#define VCMD_RES_UNREF_SIZE 1
+#define VCMD_RES_UNREF_RES_HANDLE 0
+
+#define VCMD_TRANSFER_RES_HANDLE 0
+#define VCMD_TRANSFER_LEVEL 1
+#define VCMD_TRANSFER_STRIDE 2
+#define VCMD_TRANSFER_LAYER_STRIDE 3
+#define VCMD_TRANSFER_X 4
+#define VCMD_TRANSFER_Y 5
+#define VCMD_TRANSFER_Z 6
+#define VCMD_TRANSFER_WIDTH 7
+#define VCMD_TRANSFER_HEIGHT 8
+#define VCMD_TRANSFER_DEPTH 9
+#define VCMD_TRANSFER_OFFSET 10
+#define VCMD_TRANSFER_DATA 11
+
+#endif
diff --git a/vtest/vtest_renderer.c b/vtest/vtest_renderer.c
index 75b6506..dbbe20a 100644
--- a/vtest/vtest_renderer.c
+++ b/vtest/vtest_renderer.c
@@ -1,7 +1,11 @@
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include "virglrenderer.h"
+#include "vtest_protocol.h"
+
+static int ctx_id = 1;
struct virgl_renderer_callbacks vtest_cbs = {
.version = 1,
// .write_fence = vtest_write_fence,
@@ -15,8 +19,14 @@ struct vtest_renderer renderer;
int vtest_create_renderer(int fd)
{
+ const char *vtestname = "vtestname";
+ int ret;
+
renderer.remote_fd = fd;
virgl_renderer_init(&renderer, VIRGL_RENDERER_USE_EGL, &vtest_cbs);
+
+ ret = virgl_renderer_context_create(ctx_id, strlen(vtestname), vtestname);
+ return ret;
}
int vtest_send_caps(void)
@@ -38,3 +48,48 @@ int vtest_send_caps(void)
write(renderer.remote_fd, caps_buf, max_size);
return 0;
}
+
+int vtest_create_resource(void)
+{
+ uint32_t res_create_buf[VCMD_RES_CREATE_SIZE];
+ struct virgl_renderer_resource_create_args args;
+ int ret;
+
+ ret = read(renderer.remote_fd, &res_create_buf, sizeof(res_create_buf));
+ if (ret != sizeof(res_create_buf))
+ return -1;
+
+ args.handle = res_create_buf[VCMD_RES_CREATE_RES_HANDLE];
+ args.target = res_create_buf[VCMD_RES_CREATE_TARGET];
+ args.format = res_create_buf[VCMD_RES_CREATE_FORMAT];
+ args.bind = res_create_buf[VCMD_RES_CREATE_BIND];
+
+ args.width = res_create_buf[VCMD_RES_CREATE_WIDTH];
+ args.height = res_create_buf[VCMD_RES_CREATE_HEIGHT];
+ args.depth = res_create_buf[VCMD_RES_CREATE_DEPTH];
+ args.array_size = res_create_buf[VCMD_RES_CREATE_ARRAY_SIZE];
+ args.last_level = res_create_buf[VCMD_RES_CREATE_LAST_LEVEL];
+ args.nr_samples = res_create_buf[VCMD_RES_CREATE_NR_SAMPLES];
+ args.flags = 0;
+
+ ret = virgl_renderer_resource_create(&args, NULL, 0);
+
+ virgl_renderer_ctx_attach_resource(ctx_id, args.handle);
+ return ret;
+}
+
+int vtest_resource_unref(void)
+{
+ uint32_t res_unref_buf[VCMD_RES_UNREF_SIZE];
+ int ret;
+ uint32_t handle;
+
+ ret = read(renderer.remote_fd, &res_unref_buf, sizeof(res_unref_buf));
+ if (ret != sizeof(res_unref_buf))
+ return -1;
+
+ handle = res_unref_buf[VCMD_RES_UNREF_RES_HANDLE];
+ virgl_renderer_ctx_attach_resource(ctx_id, handle);
+ virgl_renderer_resource_unref(handle);
+ return 0;
+}
diff --git a/vtest/vtest_server.c b/vtest/vtest_server.c
index 1b6ea4d..a702139 100644
--- a/vtest/vtest_server.c
+++ b/vtest/vtest_server.c
@@ -6,6 +6,8 @@
#include <sys/un.h>
#include "vtest.h"
+#include "vtest_protocol.h"
+
static int vtest_open_socket(const char *path)
{
struct sockaddr_un un;
@@ -77,7 +79,7 @@ int wait_for_socket_read(int sock)
int main(void)
{
int sock, new_fd, ret;
- uint32_t header[2];
+ uint32_t header[VTEST_HDR_SIZE];
sock = vtest_open_socket("/tmp/.virgl_test");
new_fd = wait_for_socket_accept(sock);
@@ -88,13 +90,23 @@ again:
goto err;
vtest_create_renderer(new_fd);
- ret = read(new_fd, &header, 2 * sizeof(uint32_t));
+ ret = read(new_fd, &header, sizeof(header));
if (ret == 8) {
- fprintf(stderr, "got %d %d\n", header[0], header[1]);
+ fprintf(stderr, "got length: %d cmd: %d\n", header[0], header[1]);
- if (header[1] == 1) {
+ switch (header[1]) {
+ case VCMD_GET_CAPS:
vtest_send_caps();
+ break;
+ case VCMD_RESOURCE_CREATE:
+ vtest_create_resource();
+ break;
+ case VCMD_RESOURCE_UNREF:
+ vtest_resource_unref();
+ break;
+ default:
+ break;
}
goto again;
}