vtest: defer virgl_renderer_context_create further

The goal is to allow clients to negoticate protocol versions, capsets,
and in the future, parameters and context types before
virgl_renderer_context_create is called.

Specifically, these commands should not trigger
virgl_renderer_context_create

  VCMD_PING_PROTOCOL_VERSION
  VCMD_PROTOCOL_VERSION
  VCMD_GET_CAPS
  VCMD_GET_CAPS2
  VCMD_RESOURCE_BUSY_WAIT when res_id==0 (for legacy reasons)

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Isaac Bosompem <mrisaacb@google.com>
macos/master
Chia-I Wu 4 years ago
parent 3802f56a3b
commit 48b67e83a1
  1. 8
      vtest/vtest_renderer.c
  2. 56
      vtest/vtest_server.c

@ -1072,6 +1072,14 @@ int vtest_resource_busy_wait(UNUSED uint32_t length_dw)
return -1; return -1;
} }
/* clients often send VCMD_PING_PROTOCOL_VERSION followed by
* VCMD_RESOURCE_BUSY_WAIT with handle 0 to figure out if
* VCMD_PING_PROTOCOL_VERSION is supported. We need to make a special case
* for that.
*/
if (!ctx->context_initialized && bw_buf[VCMD_BUSY_WAIT_HANDLE])
return -1;
/* handle = bw_buf[VCMD_BUSY_WAIT_HANDLE]; unused as of now */ /* handle = bw_buf[VCMD_BUSY_WAIT_HANDLE]; unused as of now */
flags = bw_buf[VCMD_BUSY_WAIT_FLAGS]; flags = bw_buf[VCMD_BUSY_WAIT_FLAGS];

@ -580,28 +580,34 @@ static void vtest_server_run(void)
vtest_server_close_socket(); vtest_server_close_socket();
} }
typedef int (*vtest_cmd_fptr_t)(uint32_t); static const struct vtest_command {
int (*dispatch)(uint32_t);
static const vtest_cmd_fptr_t vtest_commands[] = { bool init_context;
NULL /* CMD ids starts at 1 */, } vtest_commands[] = {
vtest_send_caps, /* CMD ids starts at 1 */
vtest_create_resource, [0] = { NULL, false },
vtest_resource_unref, [VCMD_GET_CAPS] = { vtest_send_caps, false },
vtest_transfer_get, [VCMD_RESOURCE_CREATE] = { vtest_create_resource, true },
vtest_transfer_put, [VCMD_RESOURCE_UNREF] = { vtest_resource_unref, true },
vtest_submit_cmd, [VCMD_TRANSFER_GET] = { vtest_transfer_get, true },
vtest_resource_busy_wait, [VCMD_TRANSFER_PUT] = { vtest_transfer_put, true },
NULL, /* VCMD_CREATE_RENDERER is a specific case */ [VCMD_SUBMIT_CMD] = { vtest_submit_cmd, true },
vtest_send_caps2, [VCMD_RESOURCE_BUSY_WAIT] = { vtest_resource_busy_wait, false },
vtest_ping_protocol_version, /* VCMD_CREATE_RENDERER is a special case */
vtest_protocol_version, [VCMD_CREATE_RENDERER] = { NULL, false },
vtest_create_resource2, [VCMD_GET_CAPS2] = { vtest_send_caps2, false },
vtest_transfer_get2, [VCMD_PING_PROTOCOL_VERSION] = { vtest_ping_protocol_version, false },
vtest_transfer_put2, [VCMD_PROTOCOL_VERSION] = { vtest_protocol_version, false },
/* since protocol version 2 */
[VCMD_RESOURCE_CREATE2] = { vtest_create_resource2, true },
[VCMD_TRANSFER_GET2] = { vtest_transfer_get2, true },
[VCMD_TRANSFER_PUT2] = { vtest_transfer_put2, true },
}; };
static int vtest_client_dispatch_commands(struct vtest_client *client) static int vtest_client_dispatch_commands(struct vtest_client *client)
{ {
const struct vtest_command *cmd;
int ret; int ret;
uint32_t header[VTEST_HDR_SIZE]; uint32_t header[VTEST_HDR_SIZE];
@ -632,18 +638,22 @@ static int vtest_client_dispatch_commands(struct vtest_client *client)
return VTEST_CLIENT_ERROR_COMMAND_ID; return VTEST_CLIENT_ERROR_COMMAND_ID;
} }
if (vtest_commands[header[1]] == NULL) { cmd = &vtest_commands[header[1]];
if (cmd->dispatch == NULL) {
return VTEST_CLIENT_ERROR_COMMAND_UNEXPECTED; return VTEST_CLIENT_ERROR_COMMAND_UNEXPECTED;
} }
ret = vtest_lazy_init_context(client->context); /* we should consider per-context dispatch table to get rid of if's */
if (ret) { if (cmd->init_context) {
return VTEST_CLIENT_ERROR_CONTEXT_FAILED; ret = vtest_lazy_init_context(client->context);
if (ret) {
return VTEST_CLIENT_ERROR_CONTEXT_FAILED;
}
} }
vtest_set_current_context(client->context); vtest_set_current_context(client->context);
ret = vtest_commands[header[1]](header[0]); ret = cmd->dispatch(header[0]);
if (ret < 0) { if (ret < 0) {
return VTEST_CLIENT_ERROR_COMMAND_DISPATCH; return VTEST_CLIENT_ERROR_COMMAND_DISPATCH;
} }

Loading…
Cancel
Save