vtest: use server-generated res ids since version 3

VCMD_RESOURCE_CREATE and VCMD_RESOURCE_CREATE2 use and return
server-generated ids since version 3.  The client id must be 0.

This makes the commands work more like linux's
DRM_IOCTL_VIRTGPU_RESOURCE_CREATE.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
macos/master
Chia-I Wu 5 years ago
parent 50e05e95e6
commit 05da5edabb
  1. 7
      vtest/vtest_protocol.h
  2. 30
      vtest/vtest_renderer.c

@ -60,6 +60,7 @@
#define VCMD_PROTOCOL_VERSION 11
/* since protocol version 2 */
#define VCMD_RESOURCE_CREATE2 12
#define VCMD_TRANSFER_GET2 13
#define VCMD_TRANSFER_PUT2 14
@ -72,7 +73,7 @@
#endif /* VIRGL_RENDERER_UNSTABLE_APIS */
#define VCMD_RES_CREATE_SIZE 10
#define VCMD_RES_CREATE_RES_HANDLE 0
#define VCMD_RES_CREATE_RES_HANDLE 0 /* must be 0 since protocol version 3 */
#define VCMD_RES_CREATE_TARGET 1
#define VCMD_RES_CREATE_FORMAT 2
#define VCMD_RES_CREATE_BIND 3
@ -82,9 +83,10 @@
#define VCMD_RES_CREATE_ARRAY_SIZE 7
#define VCMD_RES_CREATE_LAST_LEVEL 8
#define VCMD_RES_CREATE_NR_SAMPLES 9
/* resp res_id since protocol version 3 */
#define VCMD_RES_CREATE2_SIZE 11
#define VCMD_RES_CREATE2_RES_HANDLE 0
#define VCMD_RES_CREATE2_RES_HANDLE 0 /* must be 0 since protocol version 3 */
#define VCMD_RES_CREATE2_TARGET 1
#define VCMD_RES_CREATE2_FORMAT 2
#define VCMD_RES_CREATE2_BIND 3
@ -95,6 +97,7 @@
#define VCMD_RES_CREATE2_LAST_LEVEL 8
#define VCMD_RES_CREATE2_NR_SAMPLES 9
#define VCMD_RES_CREATE2_DATA_SIZE 10
/* resp res_id since protocol version 3, and fd if data_size >0 */
#define VCMD_RES_UNREF_SIZE 1
#define VCMD_RES_UNREF_RES_HANDLE 0

@ -804,15 +804,22 @@ static int vtest_create_resource_setup_shm(struct vtest_resource *res,
}
static int vtest_create_resource_internal(struct vtest_context *ctx,
uint32_t cmd_id,
struct virgl_renderer_resource_create_args *args,
size_t shm_size)
{
struct vtest_resource *res;
int ret;
// Check that the handle doesn't already exist.
if (util_hash_table_get(ctx->resource_table, intptr_to_pointer(args->handle)))
return -EEXIST;
if (ctx->protocol_version >= 3) {
if (args->handle)
return -EINVAL;
} else {
// Check that the handle doesn't already exist.
if (util_hash_table_get(ctx->resource_table, intptr_to_pointer(args->handle))) {
return -EEXIST;
}
}
res = vtest_new_resource(args->handle);
if (!res)
@ -827,6 +834,19 @@ static int vtest_create_resource_internal(struct vtest_context *ctx,
virgl_renderer_ctx_attach_resource(ctx->ctx_id, res->res_id);
if (ctx->protocol_version >= 3) {
uint32_t resp_buf[VTEST_HDR_SIZE + 1] = {
[VTEST_CMD_LEN] = 1,
[VTEST_CMD_ID] = cmd_id,
[VTEST_CMD_DATA_START] = res->res_id,
};
ret = vtest_block_write(ctx->out_fd, resp_buf, sizeof(resp_buf));
if (ret < 0) {
vtest_unref_resource(res);
return ret;
}
}
/* no shm for v1 resources or v2 multi-sample resources */
if (shm_size) {
int fd;
@ -866,7 +886,7 @@ int vtest_create_resource(UNUSED uint32_t length_dw)
return ret;
}
return vtest_create_resource_internal(ctx, &args, 0);
return vtest_create_resource_internal(ctx, VCMD_RESOURCE_CREATE, &args, 0);
}
int vtest_create_resource2(UNUSED uint32_t length_dw)
@ -881,7 +901,7 @@ int vtest_create_resource2(UNUSED uint32_t length_dw)
return ret;
}
return vtest_create_resource_internal(ctx, &args, shm_size);
return vtest_create_resource_internal(ctx, VCMD_RESOURCE_CREATE2, &args, shm_size);
}
int vtest_resource_unref(UNUSED uint32_t length_dw)

Loading…
Cancel
Save