From f8000f0986c3efeb1d597598c2a8825f8b862b08 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 1 Jul 2020 16:59:14 -0700 Subject: [PATCH] vtest: add VCMD_CONTEXT_INIT It gives clients access to virgl_renderer_context_create_with_flags. Signed-off-by: Chia-I Wu Reviewed-by: Isaac Bosompem --- vtest/vtest.h | 1 + vtest/vtest_protocol.h | 4 ++++ vtest/vtest_renderer.c | 39 ++++++++++++++++++++++++++++++++++++--- vtest/vtest_server.c | 1 + 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/vtest/vtest.h b/vtest/vtest.h index d05e292..43f030e 100644 --- a/vtest/vtest.h +++ b/vtest/vtest.h @@ -81,6 +81,7 @@ int vtest_protocol_version(uint32_t length_dw); /* since protocol version 3 */ int vtest_get_param(uint32_t length_dw); int vtest_get_capset(uint32_t length_dw); +int vtest_context_init(uint32_t length_dw); void vtest_set_max_length(uint32_t length); diff --git a/vtest/vtest_protocol.h b/vtest/vtest_protocol.h index 07df4be..81e1fbf 100644 --- a/vtest/vtest_protocol.h +++ b/vtest/vtest_protocol.h @@ -68,6 +68,7 @@ /* since protocol version 3 */ #define VCMD_GET_PARAM 15 #define VCMD_GET_CAPSET 16 +#define VCMD_CONTEXT_INIT 17 #endif /* VIRGL_RENDERER_UNSTABLE_APIS */ #define VCMD_RES_CREATE_SIZE 10 @@ -145,6 +146,9 @@ #define VCMD_GET_CAPSET_VERSION 1 /* resp capset validity and contents */ +#define VCMD_CONTEXT_INIT_SIZE 1 +#define VCMD_CONTEXT_INIT_CAPSET_ID 0 + #endif /* VIRGL_RENDERER_UNSTABLE_APIS */ #endif /* VTEST_PROTOCOL */ diff --git a/vtest/vtest_renderer.c b/vtest/vtest_renderer.c index 16c053a..61e81e4 100644 --- a/vtest/vtest_renderer.c +++ b/vtest/vtest_renderer.c @@ -64,6 +64,7 @@ struct vtest_context { char *debug_name; unsigned protocol_version; + unsigned capset_id; bool context_initialized; struct util_hash_table *resource_table; @@ -327,6 +328,7 @@ static struct vtest_context *vtest_new_context(struct vtest_input *input, ctx->debug_name = NULL; /* By default we support version 0 unless VCMD_PROTOCOL_VERSION is sent */ ctx->protocol_version = 0; + ctx->capset_id = 0; ctx->context_initialized = false; return ctx; @@ -390,9 +392,16 @@ int vtest_lazy_init_context(struct vtest_context *ctx) if (ctx->context_initialized) return 0; - ret = virgl_renderer_context_create(ctx->ctx_id, - strlen(ctx->debug_name), - ctx->debug_name); + if (ctx->capset_id) { + ret = virgl_renderer_context_create_with_flags(ctx->ctx_id, + ctx->capset_id, + strlen(ctx->debug_name), + ctx->debug_name); + } else { + ret = virgl_renderer_context_create(ctx->ctx_id, + strlen(ctx->debug_name), + ctx->debug_name); + } ctx->context_initialized = (ret == 0); return ret; @@ -570,6 +579,30 @@ int vtest_get_capset(UNUSED uint32_t length_dw) return ret >= 0 ? 0 : ret; } +int vtest_context_init(UNUSED uint32_t length_dw) +{ + struct vtest_context *ctx = vtest_get_current_context(); + uint32_t context_init_buf[VCMD_CONTEXT_INIT_SIZE]; + uint32_t capset_id; + int ret; + + ret = ctx->input->read(ctx->input, context_init_buf, sizeof(context_init_buf)); + if (ret != sizeof(context_init_buf)) + return -1; + + capset_id = context_init_buf[VCMD_CONTEXT_INIT_CAPSET_ID]; + if (!capset_id) + return -EINVAL; + + if (ctx->context_initialized) { + return ctx->capset_id == capset_id ? 0 : -EINVAL; + } + + ctx->capset_id = capset_id; + + return vtest_lazy_init_context(ctx); +} + int vtest_send_caps2(UNUSED uint32_t length_dw) { struct vtest_context *ctx = vtest_get_current_context(); diff --git a/vtest/vtest_server.c b/vtest/vtest_server.c index 2e5689f..835c359 100644 --- a/vtest/vtest_server.c +++ b/vtest/vtest_server.c @@ -607,6 +607,7 @@ static const struct vtest_command { /* since protocol version 3 */ [VCMD_GET_PARAM] = { vtest_get_param, false }, [VCMD_GET_CAPSET] = { vtest_get_capset, false }, + [VCMD_CONTEXT_INIT] = { vtest_context_init, false }, }; static int vtest_client_dispatch_commands(struct vtest_client *client)