vtest: add a bit more code

macos/master
Dave Airlie 10 years ago
parent 0b27e44304
commit 437c841b7e
  1. 3
      vtest/vtest.h
  2. 62
      vtest/vtest_protocol.h
  3. 55
      vtest/vtest_renderer.c
  4. 20
      vtest/vtest_server.c

@ -4,5 +4,8 @@
int vtest_create_renderer(int fd); int vtest_create_renderer(int fd);
int vtest_send_caps(void); int vtest_send_caps(void);
int vtest_create_resource(void);
int vtest_resource_unref(void);
#endif #endif

@ -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

@ -1,7 +1,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "virglrenderer.h" #include "virglrenderer.h"
#include "vtest_protocol.h"
static int ctx_id = 1;
struct virgl_renderer_callbacks vtest_cbs = { struct virgl_renderer_callbacks vtest_cbs = {
.version = 1, .version = 1,
// .write_fence = vtest_write_fence, // .write_fence = vtest_write_fence,
@ -15,8 +19,14 @@ struct vtest_renderer renderer;
int vtest_create_renderer(int fd) int vtest_create_renderer(int fd)
{ {
const char *vtestname = "vtestname";
int ret;
renderer.remote_fd = fd; renderer.remote_fd = fd;
virgl_renderer_init(&renderer, VIRGL_RENDERER_USE_EGL, &vtest_cbs); 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) int vtest_send_caps(void)
@ -38,3 +48,48 @@ int vtest_send_caps(void)
write(renderer.remote_fd, caps_buf, max_size); write(renderer.remote_fd, caps_buf, max_size);
return 0; 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;
}

@ -6,6 +6,8 @@
#include <sys/un.h> #include <sys/un.h>
#include "vtest.h" #include "vtest.h"
#include "vtest_protocol.h"
static int vtest_open_socket(const char *path) static int vtest_open_socket(const char *path)
{ {
struct sockaddr_un un; struct sockaddr_un un;
@ -77,7 +79,7 @@ int wait_for_socket_read(int sock)
int main(void) int main(void)
{ {
int sock, new_fd, ret; int sock, new_fd, ret;
uint32_t header[2]; uint32_t header[VTEST_HDR_SIZE];
sock = vtest_open_socket("/tmp/.virgl_test"); sock = vtest_open_socket("/tmp/.virgl_test");
new_fd = wait_for_socket_accept(sock); new_fd = wait_for_socket_accept(sock);
@ -88,13 +90,23 @@ again:
goto err; goto err;
vtest_create_renderer(new_fd); vtest_create_renderer(new_fd);
ret = read(new_fd, &header, 2 * sizeof(uint32_t)); ret = read(new_fd, &header, sizeof(header));
if (ret == 8) { 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(); vtest_send_caps();
break;
case VCMD_RESOURCE_CREATE:
vtest_create_resource();
break;
case VCMD_RESOURCE_UNREF:
vtest_resource_unref();
break;
default:
break;
} }
goto again; goto again;
} }

Loading…
Cancel
Save