virgl: Link shader program

Add a new command associated to glLinkProgram. With this we should be
able to compile and link shaders when requested by the user, thus
avoiding that to happen in the middle of a frame.

Together with the command we pass an array of shader handles attached to
the program, where each position of the array corresponds to a pipe
shader type.

Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13674>
This commit is contained in:
Antonio Caggiano 2021-11-04 14:51:19 +01:00 committed by Marge Bot
parent 0de0440b7c
commit 902c5bf468
4 changed files with 36 additions and 0 deletions

View File

@ -1535,6 +1535,15 @@ static void virgl_send_tweaks(struct virgl_context *vctx, struct virgl_screen *r
rs->tweak_gles_tf3_value);
}
static void virgl_link_shader(struct pipe_context *ctx, void **handles)
{
struct virgl_context *vctx = virgl_context(ctx);
uint32_t shader_handles[PIPE_SHADER_TYPES];
for (uint32_t i = 0; i < PIPE_SHADER_TYPES; ++i)
shader_handles[i] = (uintptr_t)handles[i];
virgl_encode_link_shader(vctx, shader_handles);
}
struct pipe_context *virgl_context_create(struct pipe_screen *pscreen,
void *priv,
unsigned flags)
@ -1633,6 +1642,9 @@ struct pipe_context *virgl_context_create(struct pipe_screen *pscreen,
vctx->base.memory_barrier = virgl_memory_barrier;
vctx->base.emit_string_marker = virgl_emit_string_marker;
if (rs->caps.caps.v2.host_feature_check_version >= 7)
vctx->base.link_shader = virgl_link_shader;
virgl_init_context_resource_functions(&vctx->base);
virgl_init_query_functions(vctx);
virgl_init_so_functions(vctx);

View File

@ -1281,6 +1281,18 @@ int virgl_encoder_destroy_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id
return 0;
}
int virgl_encode_link_shader(struct virgl_context *ctx, uint32_t *handles)
{
virgl_encoder_write_cmd_dword(ctx, VIRGL_CMD0(VIRGL_CCMD_LINK_SHADER, 0, VIRGL_LINK_SHADER_SIZE));
virgl_encoder_write_dword(ctx->cbuf, handles[PIPE_SHADER_VERTEX]);
virgl_encoder_write_dword(ctx->cbuf, handles[PIPE_SHADER_FRAGMENT]);
virgl_encoder_write_dword(ctx->cbuf, handles[PIPE_SHADER_GEOMETRY]);
virgl_encoder_write_dword(ctx->cbuf, handles[PIPE_SHADER_TESS_CTRL]);
virgl_encoder_write_dword(ctx->cbuf, handles[PIPE_SHADER_TESS_EVAL]);
virgl_encoder_write_dword(ctx->cbuf, handles[PIPE_SHADER_COMPUTE]);
return 0;
}
int virgl_encode_bind_shader(struct virgl_context *ctx,
uint32_t handle, uint32_t type)
{

View File

@ -264,6 +264,8 @@ int virgl_encoder_set_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
int virgl_encoder_create_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
int virgl_encoder_destroy_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
int virgl_encode_link_shader(struct virgl_context *ctx, uint32_t *handles);
int virgl_encode_bind_shader(struct virgl_context *ctx,
uint32_t handle, uint32_t type);

View File

@ -116,6 +116,7 @@ enum virgl_context_cmd {
VIRGL_CCMD_PIPE_RESOURCE_SET_TYPE,
VIRGL_CCMD_GET_MEMORY_INFO,
VIRGL_CCMD_EMIT_STRING_MARKER,
VIRGL_CCMD_LINK_SHADER,
VIRGL_MAX_COMMANDS
};
@ -673,4 +674,13 @@ enum vrend_tweak_type {
#define VIRGL_SEND_STRING_MARKER_STRING_SIZE 1
#define VIRGL_SEND_STRING_MARKER_OFFSET 2
/* link shader program */
#define VIRGL_LINK_SHADER_SIZE 6
#define VIRGL_LINK_SHADER_VERTEX_HANDLE 1
#define VIRGL_LINK_SHADER_FRAGMENT_HANDLE 2
#define VIRGL_LINK_SHADER_GEOMETRY_HANDLE 3
#define VIRGL_LINK_SHADER_TESS_CTRL_HANDLE 4
#define VIRGL_LINK_SHADER_TESS_EVAL_HANDLE 5
#define VIRGL_LINK_SHADER_COMPUTE_HANDLE 6
#endif